How to use the pygltflib.UNSIGNED_SHORT function in pygltflib

To help you get started, we’ve selected a few pygltflib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github prideout / svg3d / test_gltf.py View on Github external
def create_meshes_from_glb(filename, scale, style, mesh_index=0):
    glb = pygltflib.GLTF2().load(filename)
    meshes = []
    for prim in glb.meshes[mesh_index].primitives:

        # Indices
        accessor = glb.accessors[prim.indices]
        assert accessor.type == "SCALAR"
        assert not accessor.sparse
        assert accessor.componentType == pygltflib.UNSIGNED_SHORT
        nindices = accessor.count
        bv = glb.bufferViews[accessor.bufferView]
        data = glb._glb_data[bv.byteOffset : bv.byteOffset + bv.byteLength]
        triangles = np.frombuffer(data, dtype=np.uint16)
        triangles = np.reshape(triangles, (-1, 3))
        assert nindices == len(triangles) * 3

        # Vertices
        accessor = glb.accessors[prim.attributes.POSITION]
        assert accessor.type == "VEC3"
        assert not accessor.sparse
        assert accessor.componentType == pygltflib.FLOAT
        nvertices = accessor.count
        bv = glb.bufferViews[accessor.bufferView]
        data = glb._glb_data[bv.byteOffset : bv.byteOffset + bv.byteLength]
        vertices = np.frombuffer(data, dtype=np.float32)

pygltflib

Python library for reading, writing and managing 3D objects in the Khronos Group gltf and gltf2 formats.

MIT
Latest version published 1 month ago

Package Health Score

61 / 100
Full package analysis

Similar packages