Skip to content

Commit

Permalink
distinct normal/occlusion texture info when writing
Browse files Browse the repository at this point in the history
  • Loading branch information
wsw0108 committed Sep 22, 2022
1 parent 9f19de1 commit 19f7ec4
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions cgltf_write.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,17 @@ typedef struct {
context->needs_comma = 1; }

#define CGLTF_WRITE_TEXTURE_INFO(label, info) if (info.texture) { \
cgltf_write_line(context, "\"" label "\": {"); \
CGLTF_WRITE_IDXPROP("index", info.texture, context->data->textures); \
cgltf_write_intprop(context, "texCoord", info.texcoord, 0); \
if (info.has_transform) { \
context->extension_flags |= CGLTF_EXTENSION_FLAG_TEXTURE_TRANSFORM; \
cgltf_write_texture_transform(context, &info.transform); \
} \
cgltf_write_extras(context, &info.extras); \
cgltf_write_line(context, "}"); }

#define CGLTF_WRITE_NORMAL_TEXTURE_INFO(label, info) if (info.texture) { \
cgltf_write_line(context, "\"" label "\": {"); \
CGLTF_WRITE_IDXPROP("index", info.texture, context->data->textures); \
cgltf_write_intprop(context, "texCoord", info.texcoord, 0); \
Expand All @@ -156,6 +167,18 @@ typedef struct {
cgltf_write_extras(context, &info.extras); \
cgltf_write_line(context, "}"); }

#define CGLTF_WRITE_OCCLUSION_TEXTURE_INFO(label, info) if (info.texture) { \
cgltf_write_line(context, "\"" label "\": {"); \
CGLTF_WRITE_IDXPROP("index", info.texture, context->data->textures); \
cgltf_write_intprop(context, "texCoord", info.texcoord, 0); \
cgltf_write_floatprop(context, "strength", info.scale, 1.0f); \
if (info.has_transform) { \
context->extension_flags |= CGLTF_EXTENSION_FLAG_TEXTURE_TRANSFORM; \
cgltf_write_texture_transform(context, &info.transform); \
} \
cgltf_write_extras(context, &info.extras); \
cgltf_write_line(context, "}"); }

#ifndef CGLTF_CONSTS
static const cgltf_size GlbHeaderSize = 12;
static const cgltf_size GlbChunkHeaderSize = 8;
Expand Down Expand Up @@ -642,7 +665,7 @@ static void cgltf_write_material(cgltf_write_context* context, const cgltf_mater
cgltf_write_line(context, "\"KHR_materials_clearcoat\": {");
CGLTF_WRITE_TEXTURE_INFO("clearcoatTexture", params->clearcoat_texture);
CGLTF_WRITE_TEXTURE_INFO("clearcoatRoughnessTexture", params->clearcoat_roughness_texture);
CGLTF_WRITE_TEXTURE_INFO("clearcoatNormalTexture", params->clearcoat_normal_texture);
CGLTF_WRITE_NORMAL_TEXTURE_INFO("clearcoatNormalTexture", params->clearcoat_normal_texture);
cgltf_write_floatprop(context, "clearcoatFactor", params->clearcoat_factor, 0.0f);
cgltf_write_floatprop(context, "clearcoatRoughnessFactor", params->clearcoat_roughness_factor, 0.0f);
cgltf_write_line(context, "}");
Expand Down Expand Up @@ -747,8 +770,8 @@ static void cgltf_write_material(cgltf_write_context* context, const cgltf_mater
cgltf_write_line(context, "}");
}

CGLTF_WRITE_TEXTURE_INFO("normalTexture", material->normal_texture);
CGLTF_WRITE_TEXTURE_INFO("occlusionTexture", material->occlusion_texture);
CGLTF_WRITE_NORMAL_TEXTURE_INFO("normalTexture", material->normal_texture);
CGLTF_WRITE_OCCLUSION_TEXTURE_INFO("occlusionTexture", material->occlusion_texture);
CGLTF_WRITE_TEXTURE_INFO("emissiveTexture", material->emissive_texture);
if (cgltf_check_floatarray(material->emissive_factor, 3, 0.0f))
{
Expand Down

0 comments on commit 19f7ec4

Please sign in to comment.