|
|
@@ -76,7 +76,8 @@ cgltf_size cgltf_write(const cgltf_options* options, char* buffer, cgltf_size si
|
|
|
#define CGLTF_EXTENSION_FLAG_DRACO_MESH_COMPRESSION (1 << 4)
|
|
|
#define CGLTF_EXTENSION_FLAG_MATERIALS_CLEARCOAT (1 << 5)
|
|
|
#define CGLTF_EXTENSION_FLAG_MATERIALS_IOR (1 << 6)
|
|
|
-#define CGLTF_EXTENSION_FLAG_MATERIALS_TRANSMISSION (1 << 7)
|
|
|
+#define CGLTF_EXTENSION_FLAG_MATERIALS_SPECULAR (1 << 7)
|
|
|
+#define CGLTF_EXTENSION_FLAG_MATERIALS_TRANSMISSION (1 << 8)
|
|
|
|
|
|
typedef struct {
|
|
|
char* buffer;
|
|
|
@@ -514,6 +515,11 @@ static void cgltf_write_material(cgltf_write_context* context, const cgltf_mater
|
|
|
context->extension_flags |= CGLTF_EXTENSION_FLAG_MATERIALS_IOR;
|
|
|
}
|
|
|
|
|
|
+ if (material->has_specular)
|
|
|
+ {
|
|
|
+ context->extension_flags |= CGLTF_EXTENSION_FLAG_MATERIALS_SPECULAR;
|
|
|
+ }
|
|
|
+
|
|
|
if (material->has_pbr_metallic_roughness)
|
|
|
{
|
|
|
const cgltf_pbr_metallic_roughness* params = &material->pbr_metallic_roughness;
|
|
|
@@ -530,7 +536,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_transmission)
|
|
|
+ if (material->unlit || material->has_pbr_specular_glossiness || material->has_clearcoat || material->has_ior || material->has_specular || material->has_transmission)
|
|
|
{
|
|
|
cgltf_write_line(context, "\"extensions\": {");
|
|
|
if (material->has_clearcoat)
|
|
|
@@ -551,6 +557,18 @@ static void cgltf_write_material(cgltf_write_context* context, const cgltf_mater
|
|
|
cgltf_write_floatprop(context, "ior", params->ior, 1.5f);
|
|
|
cgltf_write_line(context, "}");
|
|
|
}
|
|
|
+ if (material->has_specular)
|
|
|
+ {
|
|
|
+ const cgltf_specular* params = &material->specular;
|
|
|
+ cgltf_write_line(context, "\"KHR_materials_specular\": {");
|
|
|
+ CGLTF_WRITE_TEXTURE_INFO("specularTexture", params->specular_texture);
|
|
|
+ cgltf_write_floatprop(context, "specularFactor", params->specular_factor, 1.0f);
|
|
|
+ if (cgltf_check_floatarray(params->specular_color_factor, 3, 1.0f))
|
|
|
+ {
|
|
|
+ cgltf_write_floatarrayprop(context, "specularColorFactor", params->specular_color_factor, 3);
|
|
|
+ }
|
|
|
+ cgltf_write_line(context, "}");
|
|
|
+ }
|
|
|
if (material->has_transmission)
|
|
|
{
|
|
|
const cgltf_transmission* params = &material->transmission;
|
|
|
@@ -930,6 +948,9 @@ static void cgltf_write_extensions(cgltf_write_context* context, uint32_t extens
|
|
|
if (extension_flags & CGLTF_EXTENSION_FLAG_MATERIALS_IOR) {
|
|
|
cgltf_write_stritem(context, "KHR_materials_ior");
|
|
|
}
|
|
|
+ if (extension_flags & CGLTF_EXTENSION_FLAG_MATERIALS_SPECULAR) {
|
|
|
+ cgltf_write_stritem(context, "KHR_materials_specular");
|
|
|
+ }
|
|
|
if (extension_flags & CGLTF_EXTENSION_FLAG_MATERIALS_TRANSMISSION) {
|
|
|
cgltf_write_stritem(context, "KHR_materials_transmission");
|
|
|
}
|