Skip to content

Commit

Permalink
Updated cgltf_write to handle KHR_texture_basisu.
Browse files Browse the repository at this point in the history
  • Loading branch information
abwood committed Apr 30, 2021
1 parent bc29f89 commit b7b143c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cgltf.h
Original file line number Diff line number Diff line change
Expand Up @@ -3927,6 +3927,10 @@ static int cgltf_parse_json_texture(cgltf_options* options, jsmntok_t const* tok
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
Expand Down
19 changes: 19 additions & 0 deletions cgltf_write.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ cgltf_size cgltf_write(const cgltf_options* options, char* buffer, cgltf_size si
#define CGLTF_EXTENSION_FLAG_MATERIALS_SHEEN (1 << 9)
#define CGLTF_EXTENSION_FLAG_MATERIALS_VARIANTS (1 << 10)
#define CGLTF_EXTENSION_FLAG_MATERIALS_VOLUME (1 << 11)
#define CGLTF_EXTENSION_FLAG_TEXTURE_BASISU (1 << 12)

typedef struct {
char* buffer;
Expand Down Expand Up @@ -707,6 +708,18 @@ static void cgltf_write_texture(cgltf_write_context* context, const cgltf_textur
cgltf_write_strprop(context, "name", texture->name);
CGLTF_WRITE_IDXPROP("source", texture->image, context->data->images);
CGLTF_WRITE_IDXPROP("sampler", texture->sampler, context->data->samplers);

if (texture->has_basisu)
{
cgltf_write_line(context, "\"extensions\": {");
{
context->extension_flags |= CGLTF_EXTENSION_FLAG_TEXTURE_BASISU;
cgltf_write_line(context, "\"KHR_texture_basisu\": {");
CGLTF_WRITE_IDXPROP("source", texture->basisu_image, context->data->images);
cgltf_write_line(context, "}");
}
cgltf_write_line(context, "}");
}
cgltf_write_extras(context, &texture->extras);
cgltf_write_line(context, "}");
}
Expand Down Expand Up @@ -1059,6 +1072,12 @@ static void cgltf_write_extensions(cgltf_write_context* context, uint32_t extens
if (extension_flags & CGLTF_EXTENSION_FLAG_MATERIALS_VARIANTS) {
cgltf_write_stritem(context, "KHR_materials_variants");
}
if (extension_flags & CGLTF_EXTENSION_FLAG_MATERIALS_VOLUME) {
cgltf_write_stritem(context, "KHR_materials_volume");
}
if (extension_flags & CGLTF_EXTENSION_FLAG_TEXTURE_BASISU) {
cgltf_write_stritem(context, "KHR_texture_basisu");
}
}

cgltf_size cgltf_write(const cgltf_options* options, char* buffer, cgltf_size size, const cgltf_data* data)
Expand Down

0 comments on commit b7b143c

Please sign in to comment.