mirror of
https://github.com/bkaradzic/bgfx.git
synced 2026-02-17 20:52:36 +01:00
Updated cgltf.
This commit is contained in:
78
3rdparty/cgltf/cgltf.h
vendored
78
3rdparty/cgltf/cgltf.h
vendored
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
24
3rdparty/cgltf/cgltf_write.h
vendored
24
3rdparty/cgltf/cgltf_write.h
vendored
@@ -88,6 +88,7 @@ cgltf_size cgltf_write(const cgltf_options* options, char* buffer, cgltf_size si
|
||||
#define CGLTF_EXTENSION_FLAG_MATERIALS_ANISOTROPY (1 << 16)
|
||||
#define CGLTF_EXTENSION_FLAG_MATERIALS_DISPERSION (1 << 17)
|
||||
#define CGLTF_EXTENSION_FLAG_TEXTURE_WEBP (1 << 18)
|
||||
#define CGLTF_EXTENSION_FLAG_MATERIALS_DIFFUSE_TRANSMISSION (1 << 19)
|
||||
|
||||
typedef struct {
|
||||
char* buffer;
|
||||
@@ -656,6 +657,11 @@ static void cgltf_write_material(cgltf_write_context* context, const cgltf_mater
|
||||
context->extension_flags |= CGLTF_EXTENSION_FLAG_MATERIALS_IRIDESCENCE;
|
||||
}
|
||||
|
||||
if (material->has_diffuse_transmission)
|
||||
{
|
||||
context->extension_flags |= CGLTF_EXTENSION_FLAG_MATERIALS_DIFFUSE_TRANSMISSION;
|
||||
}
|
||||
|
||||
if (material->has_anisotropy)
|
||||
{
|
||||
context->extension_flags |= CGLTF_EXTENSION_FLAG_MATERIALS_ANISOTROPY;
|
||||
@@ -681,7 +687,7 @@ static void cgltf_write_material(cgltf_write_context* context, const cgltf_mater
|
||||
cgltf_write_line(context, "}");
|
||||
}
|
||||
|
||||
if (material->unlit || material->has_pbr_specular_glossiness || material->has_clearcoat || material->has_ior || material->has_specular || material->has_transmission || material->has_sheen || material->has_volume || material->has_emissive_strength || material->has_iridescence || material->has_anisotropy || material->has_dispersion)
|
||||
if (material->unlit || material->has_pbr_specular_glossiness || material->has_clearcoat || material->has_ior || material->has_specular || material->has_transmission || material->has_sheen || material->has_volume || material->has_emissive_strength || material->has_iridescence || material->has_anisotropy || material->has_dispersion || material->has_diffuse_transmission)
|
||||
{
|
||||
cgltf_write_line(context, "\"extensions\": {");
|
||||
if (material->has_clearcoat)
|
||||
@@ -792,6 +798,19 @@ static void cgltf_write_material(cgltf_write_context* context, const cgltf_mater
|
||||
CGLTF_WRITE_TEXTURE_INFO("iridescenceThicknessTexture", params->iridescence_thickness_texture);
|
||||
cgltf_write_line(context, "}");
|
||||
}
|
||||
if (material->has_diffuse_transmission)
|
||||
{
|
||||
const cgltf_diffuse_transmission* params = &material->diffuse_transmission;
|
||||
cgltf_write_line(context, "\"KHR_materials_diffuse_transmission\": {");
|
||||
CGLTF_WRITE_TEXTURE_INFO("diffuseTransmissionTexture", params->diffuse_transmission_texture);
|
||||
cgltf_write_floatprop(context, "diffuseTransmissionFactor", params->diffuse_transmission_factor, 0.f);
|
||||
if (cgltf_check_floatarray(params->diffuse_transmission_color_factor, 3, 1.f))
|
||||
{
|
||||
cgltf_write_floatarrayprop(context, "diffuseTransmissionColorFactor", params->diffuse_transmission_color_factor, 3);
|
||||
}
|
||||
CGLTF_WRITE_TEXTURE_INFO("diffuseTransmissionColorTexture", params->diffuse_transmission_color_texture);
|
||||
cgltf_write_line(context, "}");
|
||||
}
|
||||
if (material->has_anisotropy)
|
||||
{
|
||||
cgltf_write_line(context, "\"KHR_materials_anisotropy\": {");
|
||||
@@ -1298,6 +1317,9 @@ static void cgltf_write_extensions(cgltf_write_context* context, uint32_t extens
|
||||
if (extension_flags & CGLTF_EXTENSION_FLAG_MATERIALS_IRIDESCENCE) {
|
||||
cgltf_write_stritem(context, "KHR_materials_iridescence");
|
||||
}
|
||||
if (extension_flags & CGLTF_EXTENSION_FLAG_MATERIALS_DIFFUSE_TRANSMISSION) {
|
||||
cgltf_write_stritem(context, "KHR_materials_diffuse_transmission");
|
||||
}
|
||||
if (extension_flags & CGLTF_EXTENSION_FLAG_MATERIALS_ANISOTROPY) {
|
||||
cgltf_write_stritem(context, "KHR_materials_anisotropy");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user