summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrad Kittenbrink <brad@lindenlab.com>2022-10-17 15:47:15 -0700
committerBrad Kittenbrink <brad@lindenlab.com>2022-10-17 15:48:49 -0700
commit44687a78625d6ed21a82356b07e9927f8d45f629 (patch)
tree8e741701d285b432bb2cd2fff97f28942c06e532
parent53e5216b2092b98d6973c2b27c5c75713ec99e73 (diff)
WIP for SL-17697 live editing now computes diffs of changed material properties in tinygltf schema json
-rw-r--r--indra/llprimitive/llgltfmaterial.cpp94
-rw-r--r--indra/llprimitive/llgltfmaterial.h2
2 files changed, 96 insertions, 0 deletions
diff --git a/indra/llprimitive/llgltfmaterial.cpp b/indra/llprimitive/llgltfmaterial.cpp
index 369a1786a3..951b768678 100644
--- a/indra/llprimitive/llgltfmaterial.cpp
+++ b/indra/llprimitive/llgltfmaterial.cpp
@@ -197,3 +197,97 @@ void LLGLTFMaterial::writeToModel(tinygltf::Model& model, S32 mat_index) const
material_out.doubleSided = mDoubleSided;
}
+void LLGLTFMaterial::writeOverridesToModel(tinygltf::Model & model, S32 mat_index, LLGLTFMaterial const * base_material) const
+{
+ if (model.materials.size() < mat_index+1)
+ {
+ model.materials.resize(mat_index + 1);
+ }
+
+ tinygltf::Material& material_out = model.materials[mat_index];
+
+ // TODO - fix handling of resetting to null/default values
+
+ // set base color texture
+ if (mBaseColorId.notNull() && mBaseColorId != base_material->mBaseColorId)
+ {
+ U32 idx = model.images.size();
+ model.images.resize(idx + 1);
+ model.textures.resize(idx + 1);
+
+ material_out.pbrMetallicRoughness.baseColorTexture.index = idx;
+ model.textures[idx].source = idx;
+ model.images[idx].uri = mBaseColorId.asString();
+ }
+
+ // set normal texture
+ if (mNormalId.notNull() && mNormalId != base_material->mNormalId)
+ {
+ U32 idx = model.images.size();
+ model.images.resize(idx + 1);
+ model.textures.resize(idx + 1);
+
+ material_out.normalTexture.index = idx;
+ model.textures[idx].source = idx;
+ model.images[idx].uri = mNormalId.asString();
+ }
+
+ // set metallic-roughness texture
+ if (mMetallicRoughnessId.notNull() && mMetallicRoughnessId != base_material->mMetallicRoughnessId)
+ {
+ U32 idx = model.images.size();
+ model.images.resize(idx + 1);
+ model.textures.resize(idx + 1);
+
+ material_out.pbrMetallicRoughness.metallicRoughnessTexture.index = idx;
+ model.textures[idx].source = idx;
+ model.images[idx].uri = mMetallicRoughnessId.asString();
+ }
+
+ // set emissive texture
+ if (mEmissiveId.notNull() && mEmissiveId != base_material->mEmissiveId)
+ {
+ U32 idx = model.images.size();
+ model.images.resize(idx + 1);
+ model.textures.resize(idx + 1);
+
+ material_out.emissiveTexture.index = idx;
+ model.textures[idx].source = idx;
+ model.images[idx].uri = mEmissiveId.asString();
+ }
+
+ if(mAlphaMode != base_material->mAlphaMode)
+ {
+ material_out.alphaMode = getAlphaMode();
+ }
+
+ if(mAlphaCutoff != base_material->mAlphaCutoff)
+ {
+ material_out.alphaCutoff = mAlphaCutoff;
+ }
+
+ if(mBaseColor != base_material->mBaseColor)
+ {
+ mBaseColor.write(material_out.pbrMetallicRoughness.baseColorFactor);
+ }
+
+ if(mEmissiveColor != base_material->mEmissiveColor)
+ {
+ mEmissiveColor.write(material_out.emissiveFactor);
+ }
+
+ if(mMetallicFactor != base_material->mMetallicFactor)
+ {
+ material_out.pbrMetallicRoughness.metallicFactor = mMetallicFactor;
+ }
+
+ if(mRoughnessFactor != base_material->mRoughnessFactor)
+ {
+ material_out.pbrMetallicRoughness.roughnessFactor = mRoughnessFactor;
+ }
+
+ if(mDoubleSided != base_material->mDoubleSided)
+ {
+ material_out.doubleSided = mDoubleSided;
+ }
+}
diff --git a/indra/llprimitive/llgltfmaterial.h b/indra/llprimitive/llgltfmaterial.h
index 8efcc9d753..e8d1d67f1b 100644
--- a/indra/llprimitive/llgltfmaterial.h
+++ b/indra/llprimitive/llgltfmaterial.h
@@ -123,5 +123,7 @@ public:
// write to given tinygltf::Model
void writeToModel(tinygltf::Model& model, S32 mat_index) const;
+ // calculate the fields in this material that differ from a base material and write them out to a given tinygltf::Model
+ void writeOverridesToModel(tinygltf::Model & model, S32 mat_index, LLGLTFMaterial const * base_material) const;
};