Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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