Skip to content

Commit

Permalink
Fix support for EXT_mesh_gpu_instancing
Browse files Browse the repository at this point in the history
bufferView is not a valid attribute; it looks like the code was probably
copied from Draco where this attribute is valid.

Also we were missing skip_json for both this extension and Draco; this
can be necessary to skip extras data.
  • Loading branch information
zeux committed May 16, 2023
1 parent 9f77acc commit d36646f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
12 changes: 6 additions & 6 deletions cgltf.h
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,6 @@ typedef struct cgltf_draco_mesh_compression {
} cgltf_draco_mesh_compression;

typedef struct cgltf_mesh_gpu_instancing {
cgltf_buffer_view* buffer_view;
cgltf_attribute* attributes;
cgltf_size attributes_count;
} cgltf_mesh_gpu_instancing;
Expand Down Expand Up @@ -2864,6 +2863,10 @@ static int cgltf_parse_json_draco_mesh_compression(cgltf_options* options, jsmnt
out_draco_mesh_compression->buffer_view = CGLTF_PTRINDEX(cgltf_buffer_view, cgltf_json_to_int(tokens + i, json_chunk));
++i;
}
else
{
i = cgltf_skip_json(tokens, i+1);
}

if (i < 0)
{
Expand All @@ -2889,11 +2892,9 @@ static int cgltf_parse_json_mesh_gpu_instancing(cgltf_options* options, jsmntok_
{
i = cgltf_parse_json_attribute_list(options, tokens, i + 1, json_chunk, &out_mesh_gpu_instancing->attributes, &out_mesh_gpu_instancing->attributes_count);
}
else if (cgltf_json_strcmp(tokens + i, json_chunk, "bufferView") == 0)
else
{
++i;
out_mesh_gpu_instancing->buffer_view = CGLTF_PTRINDEX(cgltf_buffer_view, cgltf_json_to_int(tokens + i, json_chunk));
++i;
i = cgltf_skip_json(tokens, i+1);
}

if (i < 0)
Expand Down Expand Up @@ -6411,7 +6412,6 @@ static int cgltf_fixup_pointers(cgltf_data* data)

if (data->nodes[i].has_mesh_gpu_instancing)
{
CGLTF_PTRFIXUP_REQ(data->nodes[i].mesh_gpu_instancing.buffer_view, data->buffer_views, data->buffer_views_count);
for (cgltf_size m = 0; m < data->nodes[i].mesh_gpu_instancing.attributes_count; ++m)
{
CGLTF_PTRFIXUP_REQ(data->nodes[i].mesh_gpu_instancing.attributes[m].data, data->accessors, data->accessors_count);
Expand Down
1 change: 0 additions & 1 deletion cgltf_write.h
Original file line number Diff line number Diff line change
Expand Up @@ -977,7 +977,6 @@ static void cgltf_write_node(cgltf_write_context* context, const cgltf_node* nod

cgltf_write_line(context, "\"EXT_mesh_gpu_instancing\": {");
{
CGLTF_WRITE_IDXPROP("bufferView", node->mesh_gpu_instancing.buffer_view, context->data->buffer_views);
cgltf_write_line(context, "\"attributes\": {");
{
for (cgltf_size i = 0; i < node->mesh_gpu_instancing.attributes_count; ++i)
Expand Down

0 comments on commit d36646f

Please sign in to comment.