Skip to content

Commit

Permalink
Added support for anisotropyDirection
Browse files Browse the repository at this point in the history
  • Loading branch information
abwood committed Feb 26, 2023
1 parent 2c68881 commit ba0d506
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
7 changes: 6 additions & 1 deletion cgltf.h
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,7 @@ typedef struct cgltf_iridescence
typedef struct cgltf_anisotropy
{
cgltf_float anisotropy_factor;
cgltf_float anisotropy_direction[2];
cgltf_texture_view anisotropy_texture;
} cgltf_anisotropy;

Expand Down Expand Up @@ -4043,6 +4044,7 @@ static int cgltf_parse_json_anisotropy(cgltf_options* options, jsmntok_t const*

// Default
out_anisotropy->anisotropy_factor = 0.f;
cgltf_fill_float_array(out_anisotropy->anisotropy_direction, 2, 1.0f);

for (int j = 0; j < size; ++j)
{
Expand All @@ -4051,10 +4053,13 @@ static int cgltf_parse_json_anisotropy(cgltf_options* options, jsmntok_t const*
if (cgltf_json_strcmp(tokens + i, json_chunk, "anisotropyFactor") == 0)
{
++i;
out_anisotropy->anisotropy_factor = 0.f;
out_anisotropy->anisotropy_factor = cgltf_json_to_float(tokens + i, json_chunk);
++i;
}
else if (cgltf_json_strcmp(tokens + i, json_chunk, "anisotropyDirection") == 0)
{
i = cgltf_parse_json_float_array(tokens, i + 1, json_chunk, out_anisotropy->anisotropy_direction, 2);
}
else if (cgltf_json_strcmp(tokens + i, json_chunk, "anisotropyTexture") == 0)
{
i = cgltf_parse_json_texture_view(options, tokens, i + 1, json_chunk, &out_anisotropy->anisotropy_texture);
Expand Down
4 changes: 4 additions & 0 deletions cgltf_write.h
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,10 @@ static void cgltf_write_material(cgltf_write_context* context, const cgltf_mater
cgltf_write_line(context, "\"KHR_materials_anisotropy\": {");
const cgltf_anisotropy* params = &material->anisotropy;
cgltf_write_floatprop(context, "anisotropyFactor", params->anisotropy_factor, 0.f);
if (!params->anisotropy_texture->texture)
{
cgltf_write_floatarrayprop(context, "anisotropyDirection", params->anisotropy_direction, 2);
}
CGLTF_WRITE_TEXTURE_INFO("anisotropyTexture", params->anisotropy_texture);
cgltf_write_line(context, "}");
}
Expand Down

0 comments on commit ba0d506

Please sign in to comment.