summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--indra/llprimitive/llgltfmaterial.cpp43
-rw-r--r--indra/llprimitive/llgltfmaterial.h44
-rw-r--r--indra/llprimitive/lltextureentry.h2
-rw-r--r--indra/newview/lllocalgltfmaterials.cpp79
-rw-r--r--indra/newview/lllocalgltfmaterials.h7
5 files changed, 125 insertions, 50 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;
diff --git a/indra/llprimitive/lltextureentry.h b/indra/llprimitive/lltextureentry.h
index 2c932a10df..8dc3434a01 100644
--- a/indra/llprimitive/lltextureentry.h
+++ b/indra/llprimitive/lltextureentry.h
@@ -204,7 +204,7 @@ public:
// GLTF render material
// nuanced behavior here -- if there is no render material, fall back to getGLTFMaterial, but ONLY for the getter, not the setter
- LLGLTFMaterial* getGLTFRenderMaterial() const { return mGLTFRenderMaterial.notNull() ? mGLTFRenderMaterial : getGLTFMaterial(); }
+ LLGLTFMaterial* getGLTFRenderMaterial() const { return mGLTFRenderMaterial.notNull() ? mGLTFRenderMaterial.get() : getGLTFMaterial(); }
S32 setGLTFRenderMaterial(LLGLTFMaterial* mat);
public:
diff --git a/indra/newview/lllocalgltfmaterials.cpp b/indra/newview/lllocalgltfmaterials.cpp
index f292844313..f194226fa5 100644
--- a/indra/newview/lllocalgltfmaterials.cpp
+++ b/indra/newview/lllocalgltfmaterials.cpp
@@ -152,18 +152,7 @@ bool LLLocalGLTFMaterial::updateSelf()
if (mLastModified.asString() != new_last_modified.asString())
{
- LLPointer<LLFetchedGLTFMaterial> raw_material;
- if (mWorldID.notNull())
- {
- // update existing material
- // will create a new one if material doesn't exist yet
- raw_material = (LLFetchedGLTFMaterial*)gGLTFMaterialList.getMaterial(mWorldID);
- }
- else
- {
- raw_material = new LLFetchedGLTFMaterial();
- }
- if (loadMaterial(raw_material, mMaterialIndex))
+ if (loadMaterial())
{
// decode is successful, we can safely proceed.
if (mWorldID.isNull())
@@ -172,8 +161,10 @@ bool LLLocalGLTFMaterial::updateSelf()
}
mLastModified = new_last_modified;
- // will replace material if it already exists
- gGLTFMaterialList.addMaterial(mWorldID, raw_material);
+ // addMaterial will replace material witha a new
+ // pointer if value already exists but we are
+ // reusing existing pointer, so it should add only.
+ gGLTFMaterialList.addMaterial(mWorldID, mGLTFMaterial);
mUpdateRetries = LL_LOCAL_UPDATE_RETRIES;
updated = true;
@@ -223,10 +214,21 @@ bool LLLocalGLTFMaterial::updateSelf()
return updated;
}
-bool LLLocalGLTFMaterial::loadMaterial(LLPointer<LLGLTFMaterial> mat, S32 index)
+bool LLLocalGLTFMaterial::loadMaterial()
{
bool decode_successful = false;
+ if (mWorldID.notNull())
+ {
+ // We should already have it, but update mGLTFMaterial just in case
+ // will create a new one if material doesn't exist yet
+ mGLTFMaterial = (LLFetchedGLTFMaterial*)gGLTFMaterialList.getMaterial(mWorldID);
+ }
+ else
+ {
+ mGLTFMaterial = new LLFetchedGLTFMaterial();
+ }
+
switch (mExtension)
{
case ET_MATERIAL_GLTF:
@@ -261,19 +263,19 @@ bool LLLocalGLTFMaterial::loadMaterial(LLPointer<LLGLTFMaterial> mat, S32 index)
break;
}
- if (model_in.materials.size() <= index)
+ if (model_in.materials.size() <= mMaterialIndex)
{
// materials are missing
- LL_WARNS() << "Cannot load Material, Material " << index << " is missing, " << mFilename << LL_ENDL;
+ LL_WARNS() << "Cannot load Material, Material " << mMaterialIndex << " is missing, " << mFilename << LL_ENDL;
decode_successful = false;
break;
}
// sets everything, but textures will have inaccurate ids
- mat->setFromModel(model_in, index);
+ mGLTFMaterial->setFromModel(model_in, mMaterialIndex);
std::string folder = gDirUtilp->getDirName(filename_lc);
- tinygltf::Material material_in = model_in.materials[index];
+ tinygltf::Material material_in = model_in.materials[mMaterialIndex];
if (!material_in.name.empty())
{
@@ -302,19 +304,50 @@ bool LLLocalGLTFMaterial::loadMaterial(LLPointer<LLGLTFMaterial> mat, S32 index)
if (mBaseColorFetched)
{
- mat->mBaseColorId= mBaseColorFetched->getID();
+ mBaseColorFetched->addTextureStats(64.f * 64.f, TRUE);
+ mGLTFMaterial->mBaseColorId = mBaseColorFetched->getID();
+ mGLTFMaterial->mBaseColorTexture = mBaseColorFetched;
+ }
+ else
+ {
+ mGLTFMaterial->mBaseColorId = LLUUID::null;
+ mGLTFMaterial->mBaseColorTexture = nullptr;
}
+
if (mNormalFetched)
{
- mat->mNormalId = mNormalFetched->getID();
+ mNormalFetched->addTextureStats(64.f * 64.f, TRUE);
+ mGLTFMaterial->mNormalId = mNormalFetched->getID();
+ mGLTFMaterial->mNormalTexture = mBaseColorFetched;
}
+ else
+ {
+ mGLTFMaterial->mNormalId = LLUUID::null;
+ mGLTFMaterial->mNormalTexture = nullptr;
+ }
+
if (mMRFetched)
{
- mat->mMetallicRoughnessId = mMRFetched->getID();
+ mMRFetched->addTextureStats(64.f * 64.f, TRUE);
+ mGLTFMaterial->mMetallicRoughnessId = mMRFetched->getID();
+ mGLTFMaterial->mMetallicRoughnessTexture = mBaseColorFetched;
}
+ else
+ {
+ mGLTFMaterial->mMetallicRoughnessId = LLUUID::null;
+ mGLTFMaterial->mMetallicRoughnessTexture = nullptr;
+ }
+
if (mEmissiveFetched)
{
- mat->mEmissiveId = mEmissiveFetched->getID();
+ mEmissiveFetched->addTextureStats(64.f * 64.f, TRUE);
+ mGLTFMaterial->mEmissiveId = mEmissiveFetched->getID();
+ mGLTFMaterial->mEmissiveTexture = mBaseColorFetched;
+ }
+ else
+ {
+ mGLTFMaterial->mEmissiveId = LLUUID::null;
+ mGLTFMaterial->mEmissiveTexture = nullptr;
}
break;
diff --git a/indra/newview/lllocalgltfmaterials.h b/indra/newview/lllocalgltfmaterials.h
index f762dcc2ce..097f2ea30a 100644
--- a/indra/newview/lllocalgltfmaterials.h
+++ b/indra/newview/lllocalgltfmaterials.h
@@ -34,6 +34,7 @@ class LLScrollListCtrl;
class LLGLTFMaterial;
class LLViewerObject;
class LLViewerFetchedTexture;
+class LLFetchedGLTFMaterial;
class LLLocalGLTFMaterial
{
@@ -53,7 +54,7 @@ public:
bool updateSelf();
private:
- bool loadMaterial(LLPointer<LLGLTFMaterial> raw, S32 index);
+ bool loadMaterial();
private: /* private enums */
enum ELinkStatus
@@ -80,7 +81,9 @@ private: /* members */
S32 mUpdateRetries;
S32 mMaterialIndex; // Single file can have more than one
- // material needs to maintain textures
+ // Maintain textures and material pointers to
+ // make sure they won't be deleted in any way
+ LLPointer<LLFetchedGLTFMaterial> mGLTFMaterial;
LLPointer<LLViewerFetchedTexture> mBaseColorFetched;
LLPointer<LLViewerFetchedTexture> mNormalFetched;
LLPointer<LLViewerFetchedTexture> mMRFetched;