diff options
| author | RunitaiLinden <davep@lindenlab.com> | 2023-08-29 16:42:55 -0500 | 
|---|---|---|
| committer | RunitaiLinden <davep@lindenlab.com> | 2023-08-29 16:42:55 -0500 | 
| commit | 455bbcf742691b709353aa3c3e35a76d0ff38ee4 (patch) | |
| tree | fa806a884bde35d117c40a3d1348b52833dcd020 /indra/llprimitive | |
| parent | a3a811606088f1b40d9e098ddff8b38a2420b8e9 (diff) | |
SL-20229 Add GenericStreamingMessage and use it to receive GLTF material overrides
Diffstat (limited to 'indra/llprimitive')
| -rw-r--r-- | indra/llprimitive/llgltfmaterial.cpp | 172 | ||||
| -rw-r--r-- | indra/llprimitive/llgltfmaterial.h | 9 | 
2 files changed, 181 insertions, 0 deletions
| diff --git a/indra/llprimitive/llgltfmaterial.cpp b/indra/llprimitive/llgltfmaterial.cpp index c16803d39d..8475e7231a 100644 --- a/indra/llprimitive/llgltfmaterial.cpp +++ b/indra/llprimitive/llgltfmaterial.cpp @@ -27,6 +27,7 @@  #include "linden_common.h"  #include "llgltfmaterial.h" +#include "llsdserialize.h"  // NOTE -- this should be the one and only place tiny_gltf.h is included  #include "tinygltf/tiny_gltf.h" @@ -693,6 +694,177 @@ void LLGLTFMaterial::applyOverride(const LLGLTFMaterial& override_mat)      }  } +void LLGLTFMaterial::getOverrideLLSD(const LLGLTFMaterial& override_mat, LLSD& data) +{ +    LL_PROFILE_ZONE_SCOPED; +    llassert(data.isUndefined()); + +    // make every effort to shave bytes here + +    for (int i = 0; i < GLTF_TEXTURE_INFO_COUNT; ++i) +    { +        LLUUID& texture_id = mTextureId[i]; +        const LLUUID& override_texture_id = override_mat.mTextureId[i]; +        if (override_texture_id.notNull() && override_texture_id != texture_id) +        { +            data["tex"][i] = LLSD::UUID(override_texture_id); +        } + +    } + +    if (override_mat.mBaseColor != getDefaultBaseColor()) +    { +        data["bc"] = override_mat.mBaseColor.getValue(); +    } + +    if (override_mat.mEmissiveColor != getDefaultEmissiveColor()) +    { +        data["ec"] = override_mat.mEmissiveColor.getValue(); +    } + +    if (override_mat.mMetallicFactor != getDefaultMetallicFactor()) +    { +        data["mf"] = override_mat.mMetallicFactor; +    } + +    if (override_mat.mRoughnessFactor != getDefaultRoughnessFactor()) +    { +        data["rf"] = override_mat.mRoughnessFactor; +    } + +    if (override_mat.mAlphaMode != getDefaultAlphaMode() || override_mat.mOverrideAlphaMode) +    { +        data["am"] = override_mat.mAlphaMode; +    } + +    if (override_mat.mAlphaCutoff != getDefaultAlphaCutoff()) +    { +        data["ac"] = override_mat.mAlphaCutoff; +    } + +    if (override_mat.mDoubleSided != getDefaultDoubleSided() || override_mat.mOverrideDoubleSided) +    { +        data["ds"] = override_mat.mDoubleSided; +    } + +    for (int i = 0; i < GLTF_TEXTURE_INFO_COUNT; ++i) +    { +        if (override_mat.mTextureTransform[i].mOffset != getDefaultTextureOffset()) +        { +            data["ti"][i]["o"] = override_mat.mTextureTransform[i].mOffset.getValue(); +        } + +        if (override_mat.mTextureTransform[i].mScale != getDefaultTextureScale()) +        { +            data["ti"][i]["s"] = override_mat.mTextureTransform[i].mScale.getValue(); +        } + +        if (override_mat.mTextureTransform[i].mRotation != getDefaultTextureRotation()) +        { +            data["ti"][i]["r"] = override_mat.mTextureTransform[i].mRotation; +        } +    } + +#if 0 +    { +        std::ostringstream ostr; +        LLSDSerialize::serialize(data, ostr, LLSDSerialize::LLSD_NOTATION); +        std::string param_str(ostr.str()); +        LL_INFOS() << param_str << LL_ENDL; +        LL_INFOS() << "Notation size: " << param_str.size() << LL_ENDL; +    } + +    { +        std::ostringstream ostr; +        LLSDSerialize::serialize(data, ostr, LLSDSerialize::LLSD_BINARY); +        std::string param_str(ostr.str()); +        LL_INFOS() << "Binary size: " << param_str.size() << LL_ENDL; +    } +#endif +} + + +void LLGLTFMaterial::applyOverrideLLSD(const LLSD& data) +{ +    const LLSD& tex = data["tex"]; + +    if (tex.isArray()) +    { +        for (int i = 0; i < tex.size(); ++i) +        { +            mTextureId[i] = tex[i].asUUID(); +        } +    } + +    const LLSD& bc = data["bc"]; +    if (bc.isDefined()) +    { +        mBaseColor.setValue(bc); +    } + +    const LLSD& ec = data["ec"]; +    if (ec.isDefined()) +    { +        mEmissiveColor.setValue(ec); +    } + +    const LLSD& mf = data["mf"]; +    if (mf.isReal()) +    { +        mMetallicFactor = mf.asReal(); +    } + +    const LLSD& rf = data["rf"]; +    if (rf.isReal()) +    { +        mRoughnessFactor = rf.asReal(); +    } + +    const LLSD& am = data["am"]; +    if (am.isInteger()) +    { +        mAlphaMode = (AlphaMode) am.asInteger(); +    } + +    const LLSD& ac = data["ac"]; +    if (ac.isReal()) +    { +        mAlphaCutoff = ac.asReal(); +    } + +    const LLSD& ds = data["ds"]; +    if (data.isBoolean()) +    { +        mDoubleSided = ds.asBoolean(); +        mOverrideDoubleSided = true; +    } + +    const LLSD& ti = data["ti"]; +    if (ti.isArray()) +    { +        for (int i = 0; i < GLTF_TEXTURE_INFO_COUNT; ++i) +        { +            const LLSD& o = ti[i]["o"]; +            if (o.isDefined()) +            { +                mTextureTransform[i].mOffset.setValue(o); +            } + +            const LLSD& s = ti[i]["s"]; +            if (s.isDefined()) +            { +                mTextureTransform[i].mScale.setValue(s); +            } + +            const LLSD& r = ti[i]["r"]; +            if (r.isReal()) +            { +                mTextureTransform[i].mRotation = r.asReal(); +            } +        } +    } +} +  LLUUID LLGLTFMaterial::getHash() const  {      LL_PROFILE_ZONE_SCOPED_CATEGORY_TEXTURE; diff --git a/indra/llprimitive/llgltfmaterial.h b/indra/llprimitive/llgltfmaterial.h index ad7784f6d1..ca27507707 100644 --- a/indra/llprimitive/llgltfmaterial.h +++ b/indra/llprimitive/llgltfmaterial.h @@ -176,6 +176,7 @@ public:      // get the contents of this LLGLTFMaterial as a json string      std::string asJSON(bool prettyprint = false) const; +      // initialize from given tinygltf::Model      // model - the model to reference      // mat_index - index of material in model's material array @@ -185,6 +186,14 @@ public:      void writeToModel(tinygltf::Model& model, S32 mat_index) const;      void applyOverride(const LLGLTFMaterial& override_mat); +     +    // apply the given LLSD override data +    void applyOverrideLLSD(const LLSD& data); + +    // Get the given override on this LLGLTFMaterial as LLSD +    // override_mat -- the override source data +    // data -- output LLSD object (should be passed in empty) +    void getOverrideLLSD(const LLGLTFMaterial& override_mat, LLSD& data);      // For base materials only (i.e. assets). Clears transforms to      // default since they're not supported in assets yet. | 
