Skip to content

Commit 8805c18

Browse files
committed
gltfpack: Warn if input glTF file contains experimental versions
... or legacy versions (e.g. version 0 for index codec). glTF specification of EXT_meshopt_compression explicitly only supports vertex 0 / index 1.
1 parent ed72a2e commit 8805c18

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

gltf/parsegltf.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,8 @@ static bool freeUnusedBuffers(cgltf_data* data)
518518

519519
static cgltf_result decompressMeshopt(cgltf_data* data)
520520
{
521+
bool warned = false;
522+
521523
for (size_t i = 0; i < data->buffer_views_count; ++i)
522524
{
523525
if (!data->buffer_views[i].has_meshopt_compression)
@@ -536,18 +538,22 @@ static cgltf_result decompressMeshopt(cgltf_data* data)
536538
data->buffer_views[i].data = result;
537539

538540
int rc = -1;
541+
bool warn = false;
539542

540543
switch (mc->mode)
541544
{
542545
case cgltf_meshopt_compression_mode_attributes:
546+
warn = meshopt_decodeVertexVersion(source, mc->size) != 0;
543547
rc = meshopt_decodeVertexBuffer(result, mc->count, mc->stride, source, mc->size);
544548
break;
545549

546550
case cgltf_meshopt_compression_mode_triangles:
551+
warn = meshopt_decodeIndexVersion(source, mc->size) != 1;
547552
rc = meshopt_decodeIndexBuffer(result, mc->count, mc->stride, source, mc->size);
548553
break;
549554

550555
case cgltf_meshopt_compression_mode_indices:
556+
warn = meshopt_decodeIndexVersion(source, mc->size) != 1;
551557
rc = meshopt_decodeIndexSequence(result, mc->count, mc->stride, source, mc->size);
552558
break;
553559

@@ -558,6 +564,12 @@ static cgltf_result decompressMeshopt(cgltf_data* data)
558564
if (rc != 0)
559565
return cgltf_result_io_error;
560566

567+
if (warn && !warned)
568+
{
569+
fprintf(stderr, "Warning: EXT_meshopt_compression data uses versions outside of the glTF specification (vertex 0 / index 1 expected)\n");
570+
warned = true;
571+
}
572+
561573
switch (mc->filter)
562574
{
563575
case cgltf_meshopt_compression_filter_octahedral:

0 commit comments

Comments
 (0)