Datasets:
Formats:
csv
Languages:
English
Size:
< 1K
Tags:
robotics
embodied-ai
human-demonstration
egocentric-video
bimanual-manipulation
tactile-sensing
License:
Download player/mano_display.py from alinarus/MultimodalData: direct link, hf CLI and curl.
- Browser
- Download file 3.2 kB
-
https://huggingface.co/datasets/alinarus/MultimodalData/resolve/main/player/mano_display.py
- Command line
-
hf download hf://datasets/alinarus/MultimodalData/player/mano_display.py
-
curl -L -o mano_display.py https://huggingface.co/datasets/alinarus/MultimodalData/resolve/main/player/mano_display.py
3.2 kB
| """Decode portable_preview's SKQ1 posed hand cache, without changing its source.""" | |
| import gzip | |
| import json | |
| from pathlib import Path | |
| import numpy as np | |
| def vertex_normals(vertices, faces): | |
| """Area-weighted smooth normals, matching THREE.BufferGeometry.computeVertexNormals.""" | |
| triangles = vertices[faces] | |
| face_normals = np.cross(triangles[:, 1] - triangles[:, 0], triangles[:, 2] - triangles[:, 0]) | |
| normals = np.zeros_like(vertices) | |
| for corner in range(3): | |
| np.add.at(normals, faces[:, corner], face_normals) | |
| lengths = np.linalg.norm(normals, axis=1, keepdims=True) | |
| return normals / np.maximum(lengths, 1e-20) | |
| class Reader: | |
| def __init__(self, path): | |
| self.data = gzip.decompress(Path(path).read_bytes()) | |
| self.offset = 0 | |
| def array(self, dtype, count): | |
| result = np.frombuffer(self.data, dtype=dtype, count=count, offset=self.offset) | |
| self.offset += result.nbytes | |
| return result | |
| def uint(self): | |
| return int(self.array('<u4', 1)[0]) | |
| def done(self): | |
| assert self.offset == len(self.data), (self.offset, len(self.data)) | |
| def load(cache, count): | |
| cache = Path(cache) | |
| meta = json.loads((cache / 'index.json').read_text()) | |
| assert meta['format'] == 'SKQ1' and meta['frames'] == count | |
| reader = Reader(cache / 'topology.bin.gz') | |
| assert reader.uint() == 827607891 | |
| topology = {} | |
| for side in ('left', 'right'): | |
| vertices, triangles = reader.uint(), reader.uint() | |
| faces = reader.array('<u4', triangles * 3).copy().reshape(-1, 3) | |
| assert faces.max() < vertices | |
| topology[side] = (vertices, faces) | |
| reader.done() | |
| frames = [] | |
| for segment in range(meta['segments']): | |
| reader = Reader(cache / f'segment-{segment:04d}.bin.gz') | |
| assert reader.uint() == 827411283 | |
| n = reader.uint() | |
| batch = [dict(left=None, right=None) for _ in range(n)] | |
| for side in ('left', 'right'): | |
| vertices, faces = topology[side] | |
| assert reader.uint() == vertices | |
| base = reader.array('<f4', 3).astype(np.float64) | |
| scale = reader.array('<f4', 3).astype(np.float64) | |
| valid = [] | |
| for frame in batch: | |
| flags = reader.uint() | |
| if flags: | |
| wrist = reader.array('<f4', 3).copy() | |
| transform = reader.array('<f4', 16).copy().reshape(4, 4) | |
| record = dict(wrist=wrist, transform=transform if flags & 2 else None, faces=faces) | |
| frame[side] = record | |
| valid.append(record) | |
| size = len(valid) * vertices * 3 | |
| low = reader.array('u1', size).astype(np.uint16) | |
| high = reader.array('u1', size).astype(np.uint16) | |
| delta = (low + (high << 8)).reshape(len(valid), vertices, 3) | |
| values = np.cumsum(delta, axis=0, dtype=np.uint32).astype(np.uint16) | |
| positions = (base + values * scale).astype(np.float32) | |
| for record, points in zip(valid, positions): | |
| record['vertices'] = points | |
| reader.done() | |
| frames.extend(batch) | |
| assert len(frames) == count | |
| return frames | |