diff options
author | Dave Parks <davep@lindenlab.com> | 2022-11-02 12:14:56 -0500 |
---|---|---|
committer | Dave Parks <davep@lindenlab.com> | 2022-11-02 12:14:56 -0500 |
commit | c3f94ab9a1da2c0c5304ff624b54fad6a43506ae (patch) | |
tree | 49e631ff416a4d309be3a4e041538d189a530c1c /indra | |
parent | 0ea5b38b8dd83bc584c1ce652753f7c689b96136 (diff) |
SL-18520 Use GLTF material.extras to pass flags for enabling overriding alpha mode and double sided to default
Diffstat (limited to 'indra')
-rw-r--r-- | indra/llprimitive/llgltfmaterial.cpp | 73 | ||||
-rw-r--r-- | indra/llprimitive/llgltfmaterial.h | 8 | ||||
-rw-r--r-- | indra/newview/llmaterialeditor.cpp | 8 |
3 files changed, 59 insertions, 30 deletions
diff --git a/indra/llprimitive/llgltfmaterial.cpp b/indra/llprimitive/llgltfmaterial.cpp index 4b1f89f99f..172cbdb7ce 100644 --- a/indra/llprimitive/llgltfmaterial.cpp +++ b/indra/llprimitive/llgltfmaterial.cpp @@ -65,6 +65,9 @@ LLGLTFMaterial& LLGLTFMaterial::operator=(const LLGLTFMaterial& rhs) mTextureTransform = rhs.mTextureTransform; + mOverrideDoubleSided = rhs.mOverrideDoubleSided; + mOverrideAlphaMode = rhs.mOverrideDoubleSided; + return *this; } @@ -129,6 +132,22 @@ void LLGLTFMaterial::setFromModel(const tinygltf::Model& model, S32 mat_index) mRoughnessFactor = llclamp((F32)material_in.pbrMetallicRoughness.roughnessFactor, 0.f, 1.f); mDoubleSided = material_in.doubleSided; + + if (material_in.extras.IsObject()) + { + tinygltf::Value::Object extras = material_in.extras.Get<tinygltf::Value::Object>(); + auto& alpha_mode = extras.find("override_alpha_mode"); + if (alpha_mode != extras.end()) + { + mOverrideAlphaMode = alpha_mode->second.Get<bool>(); + } + + auto& double_sided = extras.find("override_double_sided"); + if (double_sided != extras.end()) + { + mOverrideDoubleSided = double_sided->second.Get<bool>(); + } + } } LLVector2 vec2_from_json(const tinygltf::Value::Object& object, const char* key, const LLVector2& default_value) @@ -256,6 +275,27 @@ void LLGLTFMaterial::writeToModel(tinygltf::Model& model, S32 mat_index) const material_out.doubleSided = mDoubleSided; + + // generate "extras" string + tinygltf::Value::Object extras; + bool write_extras = false; + if (mOverrideAlphaMode && mAlphaMode == getDefaultAlphaMode()) + { + extras["override_alpha_mode"] = tinygltf::Value(mOverrideAlphaMode); + write_extras = true; + } + + if (mOverrideDoubleSided && mDoubleSided == getDefaultDoubleSided()) + { + extras["override_double_sided"] = tinygltf::Value(mOverrideDoubleSided); + write_extras = true; + } + + if (write_extras) + { + material_out.extras = tinygltf::Value(extras); + } + model.asset.version = "2.0"; } @@ -425,7 +465,7 @@ void LLGLTFMaterial::setAlphaMode(S32 mode, bool for_override) mAlphaMode = (AlphaMode) llclamp(mode, (S32) ALPHA_MODE_OPAQUE, (S32) ALPHA_MODE_MASK); if (for_override) { - // TODO: what do? + mOverrideAlphaMode = true; } } @@ -436,7 +476,7 @@ void LLGLTFMaterial::setDoubleSided(bool double_sided, bool for_override) mDoubleSided = double_sided; if (for_override) { - // TODO: what do? + mOverrideDoubleSided = true; } } @@ -460,26 +500,6 @@ void LLGLTFMaterial::setTextureRotation(TextureInfo texture_info, float rotation // Make a static default material for accessors const LLGLTFMaterial LLGLTFMaterial::sDefault; -LLUUID LLGLTFMaterial::getDefaultBaseColorId() -{ - return sDefault.mBaseColorId; -} - -LLUUID LLGLTFMaterial::getDefaultNormalId() -{ - return sDefault.mNormalId; -} - -LLUUID LLGLTFMaterial::getDefaultEmissiveId() -{ - return sDefault.mEmissiveId; -} - -LLUUID LLGLTFMaterial::getDefaultMetallicRoughnessId() -{ - return sDefault.mMetallicRoughnessId; -} - F32 LLGLTFMaterial::getDefaultAlphaCutoff() { return sDefault.mAlphaCutoff; @@ -535,7 +555,10 @@ void LLGLTFMaterial::applyOverrideUUID(LLUUID& dst_id, const LLUUID& override_id { if (override_id != GLTF_OVERRIDE_NULL_UUID) { - dst_id = override_id; + if (override_id != LLUUID::null) + { + dst_id = override_id; + } } else { @@ -572,7 +595,7 @@ void LLGLTFMaterial::applyOverride(const LLGLTFMaterial& override_mat) mRoughnessFactor = override_mat.mRoughnessFactor; } - if (override_mat.mAlphaMode != getDefaultAlphaMode()) + if (override_mat.mAlphaMode != getDefaultAlphaMode() || override_mat.mOverrideAlphaMode) { mAlphaMode = override_mat.mAlphaMode; } @@ -581,7 +604,7 @@ void LLGLTFMaterial::applyOverride(const LLGLTFMaterial& override_mat) mAlphaCutoff = override_mat.mAlphaCutoff; } - if (override_mat.mDoubleSided != getDefaultDoubleSided()) + if (override_mat.mDoubleSided != getDefaultDoubleSided() || override_mat.mOverrideDoubleSided) { mDoubleSided = override_mat.mDoubleSided; } diff --git a/indra/llprimitive/llgltfmaterial.h b/indra/llprimitive/llgltfmaterial.h index a385539cc5..9489837de7 100644 --- a/indra/llprimitive/llgltfmaterial.h +++ b/indra/llprimitive/llgltfmaterial.h @@ -83,6 +83,10 @@ public: bool mDoubleSided = false; AlphaMode mAlphaMode = ALPHA_MODE_OPAQUE; + // override specific flags for state that can't use off-by-epsilon or UUID hack + bool mOverrideDoubleSided = false; + bool mOverrideAlphaMode = false; + // get a UUID based on a hash of this LLGLTFMaterial LLUUID getHash() const { @@ -131,10 +135,6 @@ public: void setTextureRotation(TextureInfo texture_info, float rotation); // Default value accessors - static LLUUID getDefaultBaseColorId(); - static LLUUID getDefaultNormalId(); - static LLUUID getDefaultEmissiveId(); - static LLUUID getDefaultMetallicRoughnessId(); static F32 getDefaultAlphaCutoff(); static S32 getDefaultAlphaMode(); static F32 getDefaultMetallicFactor(); diff --git a/indra/newview/llmaterialeditor.cpp b/indra/newview/llmaterialeditor.cpp index 0ae8dcbcf7..004d61a2ec 100644 --- a/indra/newview/llmaterialeditor.cpp +++ b/indra/newview/llmaterialeditor.cpp @@ -2312,7 +2312,13 @@ public: std::string overrides_json = material->asJSON(); - +#if 1 + // debug + std::string err, warn; + LLGLTFMaterial debug; + debug.fromJSON(overrides_json, warn, err); +#endif + LLSD overrides = llsd::map( "object_id", objectp->getID(), "side", te, |