|
|
@@ -1,7 +1,7 @@
|
|
|
/**
|
|
|
* cgltf_write - a single-file glTF 2.0 writer written in C99.
|
|
|
*
|
|
|
- * Version: 1.6
|
|
|
+ * Version: 1.7
|
|
|
*
|
|
|
* Website: https://github.com/jkuhlmann/cgltf
|
|
|
*
|
|
|
@@ -75,6 +75,7 @@ cgltf_size cgltf_write(const cgltf_options* options, char* buffer, cgltf_size si
|
|
|
#define CGLTF_EXTENSION_FLAG_LIGHTS_PUNCTUAL (1 << 3)
|
|
|
#define CGLTF_EXTENSION_FLAG_DRACO_MESH_COMPRESSION (1 << 4)
|
|
|
#define CGLTF_EXTENSION_FLAG_MATERIALS_CLEARCOAT (1 << 5)
|
|
|
+#define CGLTF_EXTENSION_FLAG_MATERIALS_TRANSMISSION (1 << 6)
|
|
|
|
|
|
typedef struct {
|
|
|
char* buffer;
|
|
|
@@ -502,6 +503,11 @@ static void cgltf_write_material(cgltf_write_context* context, const cgltf_mater
|
|
|
context->extension_flags |= CGLTF_EXTENSION_FLAG_MATERIALS_CLEARCOAT;
|
|
|
}
|
|
|
|
|
|
+ if (material->has_transmission)
|
|
|
+ {
|
|
|
+ context->extension_flags |= CGLTF_EXTENSION_FLAG_MATERIALS_TRANSMISSION;
|
|
|
+ }
|
|
|
+
|
|
|
if (material->has_pbr_metallic_roughness)
|
|
|
{
|
|
|
const cgltf_pbr_metallic_roughness* params = &material->pbr_metallic_roughness;
|
|
|
@@ -518,7 +524,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)
|
|
|
+ if (material->unlit || material->has_pbr_specular_glossiness || material->has_clearcoat || material->has_transmission)
|
|
|
{
|
|
|
cgltf_write_line(context, "\"extensions\": {");
|
|
|
if (material->has_clearcoat)
|
|
|
@@ -532,6 +538,14 @@ static void cgltf_write_material(cgltf_write_context* context, const cgltf_mater
|
|
|
cgltf_write_floatprop(context, "clearcoatRoughnessFactor", params->clearcoat_roughness_factor, 0.0f);
|
|
|
cgltf_write_line(context, "}");
|
|
|
}
|
|
|
+ if (material->has_transmission)
|
|
|
+ {
|
|
|
+ const cgltf_transmission* params = &material->transmission;
|
|
|
+ cgltf_write_line(context, "\"KHR_materials_transmission\": {");
|
|
|
+ CGLTF_WRITE_TEXTURE_INFO("transmissionTexture", params->transmission_texture);
|
|
|
+ cgltf_write_floatprop(context, "transmissionFactor", params->transmission_factor, 0.0f);
|
|
|
+ cgltf_write_line(context, "}");
|
|
|
+ }
|
|
|
if (material->has_pbr_specular_glossiness)
|
|
|
{
|
|
|
const cgltf_pbr_specular_glossiness* params = &material->pbr_specular_glossiness;
|
|
|
@@ -900,6 +914,9 @@ static void cgltf_write_extensions(cgltf_write_context* context, uint32_t extens
|
|
|
if (extension_flags & CGLTF_EXTENSION_FLAG_MATERIALS_CLEARCOAT) {
|
|
|
cgltf_write_stritem(context, "KHR_materials_clearcoat");
|
|
|
}
|
|
|
+ if (extension_flags & CGLTF_EXTENSION_FLAG_MATERIALS_TRANSMISSION) {
|
|
|
+ cgltf_write_stritem(context, "KHR_materials_transmission");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
cgltf_size cgltf_write(const cgltf_options* options, char* buffer, cgltf_size size, const cgltf_data* data)
|
|
|
@@ -1084,6 +1101,8 @@ cgltf_size cgltf_write(const cgltf_options* options, char* buffer, cgltf_size si
|
|
|
cgltf_write_line(context, "]");
|
|
|
}
|
|
|
|
|
|
+ cgltf_write_extras(context, &data->extras);
|
|
|
+
|
|
|
CGLTF_SPRINTF("\n}\n");
|
|
|
|
|
|
// snprintf does not include the null terminator in its return value, so be sure to include it
|