Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added models/Mesh_PrimitiveMode_04.bin
Binary file not shown.
71 changes: 71 additions & 0 deletions models/Mesh_PrimitiveMode_04.gltf
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
{
"accessors": [
{
"bufferView": 0,
"componentType": 5126,
"count": 4,
"type": "VEC3",
"max": [
0.5,
0.5,
0.0
],
"min": [
-0.5,
-0.5,
0.0
],
"name": "Positions Accessor"
}
],
"asset": {
"generator": "glTF Asset Generator",
"version": "2.0"
},
"buffers": [
{
"uri": "Mesh_PrimitiveMode_04.bin",
"byteLength": 48
}
],
"bufferViews": [
{
"buffer": 0,
"byteLength": 48,
"name": "Positions"
}
],
"materials": [
{
"pbrMetallicRoughness": {
"metallicFactor": 0.0
}
}
],
"meshes": [
{
"primitives": [
{
"attributes": {
"POSITION": 0
},
"material": 0,
"mode": 5
}
]
}
],
"nodes": [
{
"mesh": 0
}
],
"scene": 0,
"scenes": [
{
"nodes": [
0
]
}
]
}
Binary file added models/no_indices_3storybuilding.glb
Binary file not shown.
6 changes: 6 additions & 0 deletions tests/test_gltf.py
Original file line number Diff line number Diff line change
Expand Up @@ -1058,6 +1058,12 @@ def test_unitize_normals_null_values(self):
# Check that the normals are still null
assert g.np.allclose(reimported_mesh.vertex_normals[0], [0, 0, 0])

def test_no_indices(self):
# test mesh with no indices (faces should be generated correctly)
mesh = g.get_mesh("no_indices_3storybuilding.glb")
assert len(mesh.triangles) == 72
mesh = g.get_mesh("Mesh_PrimitiveMode_04.gltf")
assert len(mesh.triangles) == 1

if __name__ == "__main__":
g.trimesh.util.attach_to_log()
Expand Down
3 changes: 2 additions & 1 deletion trimesh/exchange/gltf.py
Original file line number Diff line number Diff line change
Expand Up @@ -1517,8 +1517,9 @@ def _read_buffers(
else:
# indices are apparently optional and we are supposed to
# do the same thing as webGL drawArrays?
faces_len = int(3 * round(len(kwargs["vertices"]) / 3.))
kwargs["faces"] = np.arange(
len(kwargs["vertices"]) * 3, dtype=np.int64
faces_len, dtype=np.int64
).reshape((-1, 3))

if "NORMAL" in attr:
Expand Down