Skip to content

Commit 142948b

Browse files
committed
gltfpack: Ignore primitives without position data during parse
Many algorithms during gltfpack processing need positions; we currently have early outs for all of them, but this is a bit fragile. Because position-less meshes should be skipped per specification anyway, we discard primitives like that early.
1 parent bc4d35f commit 142948b

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

gltf/parsegltf.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,14 @@ static void parseMeshesGltf(cgltf_data* data, std::vector<Mesh>& meshes, std::ve
181181
continue;
182182
}
183183

184+
const cgltf_accessor* positions = cgltf_find_accessor(&primitive, cgltf_attribute_type_position, 0);
185+
186+
if (!positions)
187+
{
188+
fprintf(stderr, "Warning: ignoring primitive %d of mesh %d because it has no position data\n", int(pi), int(mi));
189+
continue;
190+
}
191+
184192
meshes.push_back(Mesh());
185193
Mesh& result = meshes.back();
186194

@@ -191,7 +199,7 @@ static void parseMeshesGltf(cgltf_data* data, std::vector<Mesh>& meshes, std::ve
191199

192200
result.streams.reserve(primitive.attributes_count);
193201

194-
size_t vertex_count = primitive.attributes_count ? primitive.attributes[0].data->count : 0;
202+
size_t vertex_count = positions->count;
195203

196204
if (primitive.indices)
197205
{

0 commit comments

Comments
 (0)