[错误]: .glb 中的非统一节点比例会使导入的顶点法线偏离表面
POSITIONS = np.array([[1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0]], dtype=np.float32)
def unit_face_normal(verts): normal = np.cross(verts[1] - verts[0], verts[2] - verts[0]) return normal / np.linalg.norm(normal)
def write_glb(path, node_scale): normals = np.tile(unit_face_normal(POSITIONS), (3, 1)).astype(np.float32) blob = b"" buffer_views = [] for data in (POSITIONS.tobytes(), normals.tobytes()): buffer_views.append(pygltflib.BufferView(buffer=0, byteOffset=len(blob), byteLength=len(data))) blob += data gltf = pygltflib.GLTF2( scene=0, scenes=[pygltflib.Scene(nodes=[0])], nodes=[pygltflib.Node(mesh=0, scale=list(node_scale))], meshes=[ pygltflib.Mesh( primitives=[pygltflib.Primitive(attributes=pygltflib.Attributes(POSITION=0, NORMAL=1), mode=4)] ) ], accessors=[ pygltflib.Accessor( bufferView=0, componentType=pygltflib.FLOAT, count=3, …
内容来源: Genesis-Embodied-AI/genesis-world