diff options
-rw-r--r-- | indra/llprimitive/llgltfmaterial.cpp | 43 | ||||
-rw-r--r-- | indra/llprimitive/llgltfmaterial.h | 44 |
2 files changed, 63 insertions, 24 deletions
diff --git a/indra/llprimitive/llgltfmaterial.cpp b/indra/llprimitive/llgltfmaterial.cpp index b9ef2de61a..8f08a8b2cf 100644 --- a/indra/llprimitive/llgltfmaterial.cpp +++ b/indra/llprimitive/llgltfmaterial.cpp @@ -37,7 +37,7 @@ LLGLTFMaterial::LLGLTFMaterial(const LLGLTFMaterial& rhs) LLGLTFMaterial& LLGLTFMaterial::operator=(const LLGLTFMaterial& rhs) { - //have to do a manual operator= because of LLRefCount + //have to do a manual operator= because of LLRefCount mBaseColorId = rhs.mBaseColorId; mNormalId = rhs.mNormalId; mMetallicRoughnessId = rhs.mMetallicRoughnessId; @@ -53,10 +53,7 @@ LLGLTFMaterial& LLGLTFMaterial::operator=(const LLGLTFMaterial& rhs) mDoubleSided = rhs.mDoubleSided; mAlphaMode = rhs.mAlphaMode; - for (S32 i = 0; i < 3; ++i) - { - mTextureTransform[i] = rhs.mTextureTransform[i]; - } + mTextureTransform = rhs.mTextureTransform; return *this; } @@ -285,16 +282,31 @@ void LLGLTFMaterial::setRoughnessFactor(F32 roughness) void LLGLTFMaterial::setAlphaMode(S32 mode) { - mAlphaMode = (AlphaMode)llclamp(mode, (S32)ALPHA_MODE_OPAQUE, (S32)ALPHA_MODE_MASK); + mAlphaMode = (AlphaMode) llclamp(mode, (S32) ALPHA_MODE_OPAQUE, (S32) ALPHA_MODE_MASK); } void LLGLTFMaterial::setDoubleSided(bool double_sided) { - // sure, no clamping will ever be needed for a bool, but include the + // sure, no clamping will ever be needed for a bool, but include the // setter for consistency with the clamping API mDoubleSided = double_sided; } +void LLGLTFMaterial::setTextureOffset(TextureInfo texture_info, const LLVector2& offset) +{ + mTextureTransform[texture_info].mOffset = offset; +} + +void LLGLTFMaterial::setTextureScale(TextureInfo texture_info, const LLVector2& scale) +{ + mTextureTransform[texture_info].mScale = scale; +} + +void LLGLTFMaterial::setTextureRotation(TextureInfo texture_info, float rotation) +{ + mTextureTransform[texture_info].mRotation = rotation; +} + // Default value accessors LLUUID LLGLTFMaterial::getDefaultBaseColorId() @@ -324,7 +336,7 @@ F32 LLGLTFMaterial::getDefaultAlphaCutoff() S32 LLGLTFMaterial::getDefaultAlphaMode() { - return (S32)ALPHA_MODE_OPAQUE; + return (S32) ALPHA_MODE_OPAQUE; } F32 LLGLTFMaterial::getDefaultMetallicFactor() @@ -352,6 +364,21 @@ bool LLGLTFMaterial::getDefaultDoubleSided() return false; } +LLVector2 LLGLTFMaterial::getDefaultTextureOffset() +{ + return LLVector2(0.f, 0.f); +} + +LLVector2 LLGLTFMaterial::getDefaultTextureScale() +{ + return LLVector2(1.f, 1.f); +} + +F32 LLGLTFMaterial::getDefaultTextureRotation() +{ + return 0.f; +} + void LLGLTFMaterial::writeOverridesToModel(tinygltf::Model& model, S32 mat_index, LLGLTFMaterial const* base_material) const { if (model.materials.size() < mat_index + 1) diff --git a/indra/llprimitive/llgltfmaterial.h b/indra/llprimitive/llgltfmaterial.h index 32695d92f4..ea7e402805 100644 --- a/indra/llprimitive/llgltfmaterial.h +++ b/indra/llprimitive/llgltfmaterial.h @@ -79,13 +79,30 @@ public: bool mDoubleSided = false; AlphaMode mAlphaMode = ALPHA_MODE_OPAQUE; - enum TextureTransformIdx : U32 + // get a UUID based on a hash of this LLGLTFMaterial + LLUUID getHash() const + { + LL_PROFILE_ZONE_SCOPED_CATEGORY_TEXTURE; + LLMD5 md5; + md5.update((unsigned char*)this, sizeof(this)); + md5.finalize(); + LLUUID id; + md5.raw_digest(id.mData); + // *TODO: Hash the overrides + return id; + } + + enum TextureInfo : U32 { - TEXTURE_TRANSFORM_DIFFUSE_EMISSIVE, - TEXTURE_TRANSFORM_NORMAL, - TEXTURE_TRANSFORM_METALLIC_ROUGHNESS + GLTF_TEXTURE_INFO_BASE_COLOR, + GLTF_TEXTURE_INFO_NORMAL, + GLTF_TEXTURE_INFO_METALLIC_ROUGHNESS, + GLTF_TEXTURE_INFO_EMISSIVE, + + GLTF_TEXTURE_INFO_COUNT }; - TextureTransform mTextureTransform[3]; + + std::array<TextureTransform, GLTF_TEXTURE_INFO_COUNT> mTextureTransform; //setters for various members (will clamp to acceptable ranges) @@ -101,6 +118,9 @@ public: void setRoughnessFactor(F32 roughness); void setAlphaMode(S32 mode); void setDoubleSided(bool double_sided); + void setTextureOffset(TextureInfo texture_info, const LLVector2& offset); + void setTextureScale(TextureInfo texture_info, const LLVector2& scale); + void setTextureRotation(TextureInfo texture_info, float rotation); // Default value accessors static LLUUID getDefaultBaseColorId(); @@ -114,6 +134,9 @@ public: static LLColor4 getDefaultBaseColor(); static LLColor3 getDefaultEmissiveColor(); static bool getDefaultDoubleSided(); + static LLVector2 getDefaultTextureOffset(); + static LLVector2 getDefaultTextureScale(); + static F32 getDefaultTextureRotation(); // set mAlphaMode from string. // Anything otherthan "MASK" or "BLEND" sets mAlphaMode to ALPHA_MODE_OPAQUE @@ -161,17 +184,6 @@ public: // write to given tinygltf::Model void writeToModel(tinygltf::Model& model, S32 mat_index) const; - // get a UUID based on a hash of this LLGLTFMaterial - LLUUID getHash() const - { - LLMD5 md5; - md5.update((unsigned char*)this, sizeof(this)); - md5.finalize(); - LLUUID id; - md5.raw_digest(id.mData); - return id; - } - // 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; |