|
|
@@ -372,6 +372,8 @@ typedef struct cgltf_texture
|
|
|
char* name;
|
|
|
cgltf_image* image;
|
|
|
cgltf_sampler* sampler;
|
|
|
+ cgltf_bool has_basisu;
|
|
|
+ cgltf_image* basisu_image;
|
|
|
cgltf_extras extras;
|
|
|
cgltf_size extensions_count;
|
|
|
cgltf_extension* extensions;
|
|
|
@@ -3885,7 +3887,62 @@ static int cgltf_parse_json_texture(cgltf_options* options, jsmntok_t const* tok
|
|
|
}
|
|
|
else if (cgltf_json_strcmp(tokens + i, json_chunk, "extensions") == 0)
|
|
|
{
|
|
|
- i = cgltf_parse_json_unprocessed_extensions(options, tokens, i, json_chunk, &out_texture->extensions_count, &out_texture->extensions);
|
|
|
+ ++i;
|
|
|
+
|
|
|
+ CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_OBJECT);
|
|
|
+ if (out_texture->extensions)
|
|
|
+ {
|
|
|
+ return CGLTF_ERROR_JSON;
|
|
|
+ }
|
|
|
+
|
|
|
+ int extensions_size = tokens[i].size;
|
|
|
+ ++i;
|
|
|
+ out_texture->extensions = (cgltf_extension*)cgltf_calloc(options, sizeof(cgltf_extension), extensions_size);
|
|
|
+ out_texture->extensions_count = 0;
|
|
|
+
|
|
|
+ if (!out_texture->extensions)
|
|
|
+ {
|
|
|
+ return CGLTF_ERROR_NOMEM;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (int k = 0; k < extensions_size; ++k)
|
|
|
+ {
|
|
|
+ CGLTF_CHECK_KEY(tokens[i]);
|
|
|
+
|
|
|
+ if (cgltf_json_strcmp(tokens + i, json_chunk, "KHR_texture_basisu") == 0)
|
|
|
+ {
|
|
|
+ out_texture->has_basisu = 1;
|
|
|
+ ++i;
|
|
|
+ CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_OBJECT);
|
|
|
+ int num_properties = tokens[i].size;
|
|
|
+ ++i;
|
|
|
+
|
|
|
+ for (int t = 0; t < num_properties; ++t)
|
|
|
+ {
|
|
|
+ CGLTF_CHECK_KEY(tokens[i]);
|
|
|
+
|
|
|
+ if (cgltf_json_strcmp(tokens + i, json_chunk, "source") == 0)
|
|
|
+ {
|
|
|
+ ++i;
|
|
|
+ out_texture->basisu_image = CGLTF_PTRINDEX(cgltf_image, cgltf_json_to_int(tokens + i, json_chunk));
|
|
|
+ ++i;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ i = cgltf_skip_json(tokens, i + 1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ i = cgltf_parse_json_unprocessed_extension(options, tokens, i, json_chunk, &(out_texture->extensions[out_texture->extensions_count++]));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (i < 0)
|
|
|
+ {
|
|
|
+ return i;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
@@ -5851,6 +5908,7 @@ static int cgltf_fixup_pointers(cgltf_data* data)
|
|
|
for (cgltf_size i = 0; i < data->textures_count; ++i)
|
|
|
{
|
|
|
CGLTF_PTRFIXUP(data->textures[i].image, data->images, data->images_count);
|
|
|
+ CGLTF_PTRFIXUP(data->textures[i].basisu_image, data->images, data->images_count);
|
|
|
CGLTF_PTRFIXUP(data->textures[i].sampler, data->samplers, data->samplers_count);
|
|
|
}
|
|
|
|