|
|
@@ -500,6 +500,14 @@ typedef struct cgltf_iridescence
|
|
|
cgltf_texture_view iridescence_thickness_texture;
|
|
|
} cgltf_iridescence;
|
|
|
|
|
|
+typedef struct cgltf_diffuse_transmission
|
|
|
+{
|
|
|
+ cgltf_texture_view diffuse_transmission_texture;
|
|
|
+ cgltf_float diffuse_transmission_factor;
|
|
|
+ cgltf_float diffuse_transmission_color_factor[3];
|
|
|
+ cgltf_texture_view diffuse_transmission_color_texture;
|
|
|
+} cgltf_diffuse_transmission;
|
|
|
+
|
|
|
typedef struct cgltf_anisotropy
|
|
|
{
|
|
|
cgltf_float anisotropy_strength;
|
|
|
@@ -525,6 +533,7 @@ typedef struct cgltf_material
|
|
|
cgltf_bool has_sheen;
|
|
|
cgltf_bool has_emissive_strength;
|
|
|
cgltf_bool has_iridescence;
|
|
|
+ cgltf_bool has_diffuse_transmission;
|
|
|
cgltf_bool has_anisotropy;
|
|
|
cgltf_bool has_dispersion;
|
|
|
cgltf_pbr_metallic_roughness pbr_metallic_roughness;
|
|
|
@@ -537,6 +546,7 @@ typedef struct cgltf_material
|
|
|
cgltf_volume volume;
|
|
|
cgltf_emissive_strength emissive_strength;
|
|
|
cgltf_iridescence iridescence;
|
|
|
+ cgltf_diffuse_transmission diffuse_transmission;
|
|
|
cgltf_anisotropy anisotropy;
|
|
|
cgltf_dispersion dispersion;
|
|
|
cgltf_texture_view normal_texture;
|
|
|
@@ -844,6 +854,8 @@ void cgltf_node_transform_world(const cgltf_node* node, cgltf_float* out_matrix)
|
|
|
|
|
|
const uint8_t* cgltf_buffer_view_data(const cgltf_buffer_view* view);
|
|
|
|
|
|
+const cgltf_accessor* cgltf_find_accessor(const cgltf_primitive* prim, cgltf_attribute_type type, cgltf_int index);
|
|
|
+
|
|
|
cgltf_bool cgltf_accessor_read_float(const cgltf_accessor* accessor, cgltf_size index, cgltf_float* out, cgltf_size element_size);
|
|
|
cgltf_bool cgltf_accessor_read_uint(const cgltf_accessor* accessor, cgltf_size index, cgltf_uint* out, cgltf_size element_size);
|
|
|
cgltf_size cgltf_accessor_read_index(const cgltf_accessor* accessor, cgltf_size index);
|
|
|
@@ -2312,6 +2324,18 @@ const uint8_t* cgltf_buffer_view_data(const cgltf_buffer_view* view)
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+const cgltf_accessor* cgltf_find_accessor(const cgltf_primitive* prim, cgltf_attribute_type type, cgltf_int index)
|
|
|
+{
|
|
|
+ for (cgltf_size i = 0; i < prim->attributes_count; ++i)
|
|
|
+ {
|
|
|
+ const cgltf_attribute* attr = &prim->attributes[i];
|
|
|
+ if (attr->type == type && attr->index == index)
|
|
|
+ return attr->data;
|
|
|
+ }
|
|
|
+
|
|
|
+ return NULL;
|
|
|
+}
|
|
|
+
|
|
|
cgltf_bool cgltf_accessor_read_float(const cgltf_accessor* accessor, cgltf_size index, cgltf_float* out, cgltf_size element_size)
|
|
|
{
|
|
|
if (accessor->is_sparse)
|
|
|
@@ -4278,6 +4302,52 @@ static int cgltf_parse_json_iridescence(cgltf_options* options, jsmntok_t const*
|
|
|
return i;
|
|
|
}
|
|
|
|
|
|
+static int cgltf_parse_json_diffuse_transmission(cgltf_options* options, jsmntok_t const* tokens, int i, const uint8_t* json_chunk, cgltf_diffuse_transmission* out_diff_transmission)
|
|
|
+{
|
|
|
+ CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_OBJECT);
|
|
|
+ int size = tokens[i].size;
|
|
|
+ ++i;
|
|
|
+
|
|
|
+ // Defaults
|
|
|
+ cgltf_fill_float_array(out_diff_transmission->diffuse_transmission_color_factor, 3, 1.0f);
|
|
|
+ out_diff_transmission->diffuse_transmission_factor = 0.f;
|
|
|
+
|
|
|
+ for (int j = 0; j < size; ++j)
|
|
|
+ {
|
|
|
+ CGLTF_CHECK_KEY(tokens[i]);
|
|
|
+
|
|
|
+ if (cgltf_json_strcmp(tokens + i, json_chunk, "diffuseTransmissionFactor") == 0)
|
|
|
+ {
|
|
|
+ ++i;
|
|
|
+ out_diff_transmission->diffuse_transmission_factor = cgltf_json_to_float(tokens + i, json_chunk);
|
|
|
+ ++i;
|
|
|
+ }
|
|
|
+ else if (cgltf_json_strcmp(tokens + i, json_chunk, "diffuseTransmissionTexture") == 0)
|
|
|
+ {
|
|
|
+ i = cgltf_parse_json_texture_view(options, tokens, i + 1, json_chunk, &out_diff_transmission->diffuse_transmission_texture);
|
|
|
+ }
|
|
|
+ else if (cgltf_json_strcmp(tokens + i, json_chunk, "diffuseTransmissionColorFactor") == 0)
|
|
|
+ {
|
|
|
+ i = cgltf_parse_json_float_array(tokens, i + 1, json_chunk, out_diff_transmission->diffuse_transmission_color_factor, 3);
|
|
|
+ }
|
|
|
+ else if (cgltf_json_strcmp(tokens + i, json_chunk, "diffuseTransmissionColorTexture") == 0)
|
|
|
+ {
|
|
|
+ i = cgltf_parse_json_texture_view(options, tokens, i + 1, json_chunk, &out_diff_transmission->diffuse_transmission_color_texture);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ i = cgltf_skip_json(tokens, i + 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (i < 0)
|
|
|
+ {
|
|
|
+ return i;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return i;
|
|
|
+}
|
|
|
+
|
|
|
static int cgltf_parse_json_anisotropy(cgltf_options* options, jsmntok_t const* tokens, int i, const uint8_t* json_chunk, cgltf_anisotropy* out_anisotropy)
|
|
|
{
|
|
|
CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_OBJECT);
|
|
|
@@ -4766,6 +4836,11 @@ static int cgltf_parse_json_material(cgltf_options* options, jsmntok_t const* to
|
|
|
out_material->has_iridescence = 1;
|
|
|
i = cgltf_parse_json_iridescence(options, tokens, i + 1, json_chunk, &out_material->iridescence);
|
|
|
}
|
|
|
+ else if (cgltf_json_strcmp(tokens + i, json_chunk, "KHR_materials_diffuse_transmission") == 0)
|
|
|
+ {
|
|
|
+ out_material->has_diffuse_transmission = 1;
|
|
|
+ i = cgltf_parse_json_diffuse_transmission(options, tokens, i + 1, json_chunk, &out_material->diffuse_transmission);
|
|
|
+ }
|
|
|
else if (cgltf_json_strcmp(tokens + i, json_chunk, "KHR_materials_anisotropy") == 0)
|
|
|
{
|
|
|
out_material->has_anisotropy = 1;
|
|
|
@@ -6629,6 +6704,9 @@ static int cgltf_fixup_pointers(cgltf_data* data)
|
|
|
CGLTF_PTRFIXUP(data->materials[i].iridescence.iridescence_texture.texture, data->textures, data->textures_count);
|
|
|
CGLTF_PTRFIXUP(data->materials[i].iridescence.iridescence_thickness_texture.texture, data->textures, data->textures_count);
|
|
|
|
|
|
+ CGLTF_PTRFIXUP(data->materials[i].diffuse_transmission.diffuse_transmission_texture.texture, data->textures, data->textures_count);
|
|
|
+ CGLTF_PTRFIXUP(data->materials[i].diffuse_transmission.diffuse_transmission_color_texture.texture, data->textures, data->textures_count);
|
|
|
+
|
|
|
CGLTF_PTRFIXUP(data->materials[i].anisotropy.anisotropy_texture.texture, data->textures, data->textures_count);
|
|
|
}
|
|
|
|