"""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('