diff options
Diffstat (limited to 'indra')
-rw-r--r-- | indra/llprimitive/lltextureentry.cpp | 21 | ||||
-rw-r--r-- | indra/llprimitive/lltextureentry.h | 2 | ||||
-rw-r--r-- | indra/newview/app_settings/shaders/class1/interface/radianceGenF.glsl | 2 | ||||
-rw-r--r-- | indra/newview/app_settings/shaders/class1/interface/reflectionmipF.glsl | 2 | ||||
-rw-r--r-- | indra/newview/llgltfmateriallist.cpp | 116 | ||||
-rw-r--r-- | indra/newview/llgltfmateriallist.h | 7 | ||||
-rw-r--r-- | indra/newview/llmaterialeditor.cpp | 37 | ||||
-rw-r--r-- | indra/newview/llmaterialeditor.h | 2 | ||||
-rw-r--r-- | indra/newview/llselectmgr.cpp | 47 | ||||
-rw-r--r-- | indra/newview/llviewerobject.cpp | 136 | ||||
-rw-r--r-- | indra/newview/llviewerobject.h | 7 |
11 files changed, 202 insertions, 177 deletions
diff --git a/indra/llprimitive/lltextureentry.cpp b/indra/llprimitive/lltextureentry.cpp index d810c6ed25..2803afde60 100644 --- a/indra/llprimitive/lltextureentry.cpp +++ b/indra/llprimitive/lltextureentry.cpp @@ -512,13 +512,28 @@ S32 LLTextureEntry::setBumpShiny(U8 bump_shiny) void LLTextureEntry::setGLTFMaterial(LLGLTFMaterial* material) { - mGLTFMaterial = material; - if (mGLTFMaterial == nullptr) + if (material != getGLTFMaterial()) { - setGLTFRenderMaterial(nullptr); + // assert on precondtion: + // whether or not mGLTFMaterial is null, any existing override should have been nulled out + // before calling setGLTFMaterial + // NOTE: if you're hitting this assert, try to make sure calling code is using LLViewerObject::setRenderMaterialID + llassert(getGLTFMaterialOverride() == nullptr); + + mGLTFMaterial = material; + if (mGLTFMaterial == nullptr) + { + setGLTFRenderMaterial(nullptr); + } } } +void LLTextureEntry::setGLTFMaterialOverride(LLGLTFMaterial* mat) +{ + llassert(mat == nullptr || getGLTFMaterial() != nullptr); // if override is not null, base material must not be null + mGLTFMaterialOverrides = mat; +} + LLGLTFMaterial* LLTextureEntry::getGLTFRenderMaterial() const { if (mGLTFRenderMaterial.notNull()) diff --git a/indra/llprimitive/lltextureentry.h b/indra/llprimitive/lltextureentry.h index e37bc9a3b6..d94e14bd73 100644 --- a/indra/llprimitive/lltextureentry.h +++ b/indra/llprimitive/lltextureentry.h @@ -200,7 +200,7 @@ public: // GLTF override LLGLTFMaterial* getGLTFMaterialOverride() const { return mGLTFMaterialOverrides; } - void setGLTFMaterialOverride(LLGLTFMaterial* mat) { mGLTFMaterialOverrides = mat; } + void setGLTFMaterialOverride(LLGLTFMaterial* mat); // GLTF render material // nuanced behavior here -- if there is no render material, fall back to getGLTFMaterial, but ONLY for the getter, not the setter diff --git a/indra/newview/app_settings/shaders/class1/interface/radianceGenF.glsl b/indra/newview/app_settings/shaders/class1/interface/radianceGenF.glsl index 32f157e9d2..839e10ce5e 100644 --- a/indra/newview/app_settings/shaders/class1/interface/radianceGenF.glsl +++ b/indra/newview/app_settings/shaders/class1/interface/radianceGenF.glsl @@ -124,7 +124,7 @@ vec4 prefilterEnvMap(vec3 R) vec3 V = R; vec4 color = vec4(0.0); float totalWeight = 0.0; - float envMapDim = 256.0; + float envMapDim = 128.0; int numSamples = 4; float numMips = 6.0; diff --git a/indra/newview/app_settings/shaders/class1/interface/reflectionmipF.glsl b/indra/newview/app_settings/shaders/class1/interface/reflectionmipF.glsl index 9dd97a80b2..f0d579f85e 100644 --- a/indra/newview/app_settings/shaders/class1/interface/reflectionmipF.glsl +++ b/indra/newview/app_settings/shaders/class1/interface/reflectionmipF.glsl @@ -90,7 +90,7 @@ void main() // convert linear depth to distance vec3 v; - v.xy = depth_tc / 512.0 * 2.0 - 1.0; + v.xy = depth_tc / 256.0 * 2.0 - 1.0; v.z = 1.0; v = normalize(v); dist /= v.z; diff --git a/indra/newview/llgltfmateriallist.cpp b/indra/newview/llgltfmateriallist.cpp index 05ed7a2019..8210efae96 100644 --- a/indra/newview/llgltfmateriallist.cpp +++ b/indra/newview/llgltfmateriallist.cpp @@ -36,13 +36,15 @@ #include "llviewercontrol.h" #include "llviewergenericmessage.h" #include "llviewerobjectlist.h" - +#include "llcorehttputil.h" #include "tinygltf/tiny_gltf.h" #include <strstream> #include "json/reader.h" #include "json/value.h" +#include <unordered_set> + LLGLTFMaterialList gGLTFMaterialList; namespace @@ -77,27 +79,80 @@ namespace LLUUID object_id = message["object_id"].asUUID(); - LLViewerObject * obj = gObjectList.findObject(object_id); - S32 side = message["side"].asInteger(); - std::string gltf_json = message["gltf_json"].asString(); - - std::string warn_msg, error_msg; - LLPointer<LLGLTFMaterial> override_data = new LLGLTFMaterial(); - bool success = override_data->fromJSON(gltf_json, warn_msg, error_msg); + LLViewerObject * obj = gObjectList.findObject(object_id); // NOTE: null object here does NOT mean nothing to do, parse message and queue results for later + bool clear_all = true; - if (!success) + if (message.has("sides") && message.has("gltf_json")) { - LL_WARNS() << "failed to parse GLTF override data. errors: " << error_msg << " | warnings: " << warn_msg << LL_ENDL; + LLSD& sides = message["sides"]; + LLSD& gltf_json = message["gltf_json"]; + + if (sides.isArray() && gltf_json.isArray() && + sides.size() != 0 && + sides.size() == gltf_json.size()) + { + clear_all = false; + + // message should be interpreted thusly: + /// sides is a list of face indices + // gltf_json is a list of corresponding json + // any side not represented in "sides" has no override + + // parse json + std::unordered_set<S32> side_set; + + for (int i = 0; i < sides.size(); ++i) + { + LLPointer<LLGLTFMaterial> override_data = new LLGLTFMaterial(); + + std::string gltf_json = message["gltf_json"][i].asString(); + + std::string warn_msg, error_msg; + + bool success = override_data->fromJSON(gltf_json, warn_msg, error_msg); + + if (!success) + { + LL_WARNS() << "failed to parse GLTF override data. errors: " << error_msg << " | warnings: " << warn_msg << LL_ENDL; + } + else + { + S32 side = sides[i].asInteger(); + // flag this side to not be nulled out later + side_set.insert(sides); + + if (!obj || !obj->setTEGLTFMaterialOverride(side, override_data)) + { + // object not ready to receive override data, queue for later + gGLTFMaterialList.queueOverrideUpdate(object_id, side, override_data); + } + } + } + + if (obj && side_set.size() != obj->getNumTEs()) + { // object exists and at least one texture entry needs to have its override data nulled out + for (int i = 0; i < obj->getNumTEs(); ++i) + { + if (side_set.find(i) == side_set.end()) + { + obj->setTEGLTFMaterialOverride(i, nullptr); + } + } + } + } + else + { + LL_WARNS() << "Malformed GLTF override message data: " << message << LL_ENDL; + } } - else - { - if (!obj || !obj->setTEGLTFMaterialOverride(side, override_data)) + + if (clear_all && obj) + { // override list was empty or an error occurred, null out all overrides for this object + for (int i = 0; i < obj->getNumTEs(); ++i) { - // object not ready to receive override data, queue for later - gGLTFMaterialList.queueOverrideUpdate(object_id, side, override_data); + obj->setTEGLTFMaterialOverride(i, nullptr); } } - return true; } }; @@ -296,3 +351,32 @@ void LLGLTFMaterialList::registerCallbacks() { gGenericDispatcher.addHandler("GLTFMaterialOverride", &handle_gltf_override_message); } + +// static +void LLGLTFMaterialList::modifyMaterialCoro(std::string cap_url, LLSD overrides) +{ + LLCore::HttpRequest::policy_t httpPolicy(LLCore::HttpRequest::DEFAULT_POLICY_ID); + LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t + httpAdapter(new LLCoreHttpUtil::HttpCoroutineAdapter("modifyMaterialCoro", httpPolicy)); + LLCore::HttpRequest::ptr_t httpRequest(new LLCore::HttpRequest); + LLCore::HttpOptions::ptr_t httpOpts(new LLCore::HttpOptions); + LLCore::HttpHeaders::ptr_t httpHeaders; + + httpOpts->setFollowRedirects(true); + + LL_DEBUGS() << "Applying override via ModifyMaterialParams cap: " << overrides << LL_ENDL; + + LLSD result = httpAdapter->postAndSuspend(httpRequest, cap_url, overrides, httpOpts, httpHeaders); + + LLSD httpResults = result[LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS]; + LLCore::HttpStatus status = LLCoreHttpUtil::HttpCoroutineAdapter::getStatusFromLLSD(httpResults); + + if (!status) + { + LL_WARNS() << "Failed to modify material." << LL_ENDL; + } + else if (!result["success"].asBoolean()) + { + LL_WARNS() << "Failed to modify material: " << result["message"] << LL_ENDL; + } +} diff --git a/indra/newview/llgltfmateriallist.h b/indra/newview/llgltfmateriallist.h index ee32dc8825..f770f6ecc8 100644 --- a/indra/newview/llgltfmateriallist.h +++ b/indra/newview/llgltfmateriallist.h @@ -49,6 +49,13 @@ public: static void registerCallbacks(); + // apply given override data via given cap url + // cap_url -- should be gAgent.getRegionCapability("ModifyMaterialParams") + // overrides -- LLSD map in the format + // "object_id": LLUUID - object to be modified + // "side": integer - index of face to be modified + // "gltf_json" : string - GLTF compliant json of override data (optional, if omitted any existing override data will be cleared) + static void modifyMaterialCoro(std::string cap_url, LLSD overrides); // save an override update for later (for example, if an override arrived for an unknown object) void queueOverrideUpdate(const LLUUID& id, S32 side, LLGLTFMaterial* override_data); diff --git a/indra/newview/llmaterialeditor.cpp b/indra/newview/llmaterialeditor.cpp index a6d2729dfa..7cd9b9198f 100644 --- a/indra/newview/llmaterialeditor.cpp +++ b/indra/newview/llmaterialeditor.cpp @@ -2039,11 +2039,16 @@ public: // Selection can cover multiple objects, and live editor is // supposed to overwrite changed values only LLTextureEntry* tep = objectp->getTE(te); - LLPointer<LLGLTFMaterial> material = tep->getGLTFMaterial(); + LLPointer<LLGLTFMaterial> material = tep->getGLTFRenderMaterial(); + if (material.isNull()) { material = new LLGLTFMaterial(); } + else + { + material = new LLGLTFMaterial(*material); + } // Override object's values with values from editor where appropriate if (mEditor->getUnsavedChangesFlags() & MATERIAL_BASE_COLOR_DIRTY) @@ -2101,12 +2106,13 @@ public: std::string overrides_json = material->asJSON(); + LLSD overrides = llsd::map( "object_id", objectp->getID(), "side", te, "gltf_json", overrides_json ); - LLCoros::instance().launch("modifyMaterialCoro", std::bind(&LLMaterialEditor::modifyMaterialCoro, mEditor, mCapUrl, overrides)); + LLCoros::instance().launch("modifyMaterialCoro", std::bind(&LLGLTFMaterialList::modifyMaterialCoro, mCapUrl, overrides)); } return true; } @@ -2587,30 +2593,3 @@ void LLMaterialEditor::loadDefaults() setFromGltfModel(model_in, 0, true); } -void LLMaterialEditor::modifyMaterialCoro(std::string cap_url, LLSD overrides) -{ - LLCore::HttpRequest::policy_t httpPolicy(LLCore::HttpRequest::DEFAULT_POLICY_ID); - LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t - httpAdapter(new LLCoreHttpUtil::HttpCoroutineAdapter("modifyMaterialCoro", httpPolicy)); - LLCore::HttpRequest::ptr_t httpRequest(new LLCore::HttpRequest); - LLCore::HttpOptions::ptr_t httpOpts(new LLCore::HttpOptions); - LLCore::HttpHeaders::ptr_t httpHeaders; - - httpOpts->setFollowRedirects(true); - - LL_DEBUGS() << "Applying override via ModifyMaterialParams cap: " << overrides << LL_ENDL; - - LLSD result = httpAdapter->postAndSuspend(httpRequest, cap_url, overrides, httpOpts, httpHeaders); - - LLSD httpResults = result[LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS]; - LLCore::HttpStatus status = LLCoreHttpUtil::HttpCoroutineAdapter::getStatusFromLLSD(httpResults); - - if (!status) - { - LL_WARNS() << "Failed to modify material." << LL_ENDL; - } - else if (!result["success"].asBoolean()) - { - LL_WARNS() << "Failed to modify material: " << result["message"] << LL_ENDL; - } -} diff --git a/indra/newview/llmaterialeditor.h b/indra/newview/llmaterialeditor.h index 040dbe99da..091f51234f 100644 --- a/indra/newview/llmaterialeditor.h +++ b/indra/newview/llmaterialeditor.h @@ -221,8 +221,6 @@ public: // initialize the UI from a default GLTF material void loadDefaults(); - void modifyMaterialCoro(std::string cap_url, LLSD overrides); - U32 getUnsavedChangesFlags() { return mUnsavedChanges; } private: diff --git a/indra/newview/llselectmgr.cpp b/indra/newview/llselectmgr.cpp index 2475900d0e..e4a67d7982 100644 --- a/indra/newview/llselectmgr.cpp +++ b/indra/newview/llselectmgr.cpp @@ -1948,52 +1948,7 @@ void LLSelectMgr::selectionSetGLTFMaterial(const LLUUID& mat_id) objectp->setParameterEntryInUse(LLNetworkData::PARAMS_RENDER_MATERIAL, TRUE, false /*prevent an update*/); } - if (te != -1) - { - LLTextureEntry* tep = objectp->getTE(te); - if (asset_id.notNull()) - { - tep->setGLTFMaterial(gGLTFMaterialList.getMaterial(asset_id)); - } - else - { - tep->setGLTFMaterial(nullptr); - } - - objectp->faceMappingChanged(); - gPipeline.markTextured(objectp->mDrawable); - - LLRenderMaterialParams* param_block = (LLRenderMaterialParams*)objectp->getParameterEntry(LLNetworkData::PARAMS_RENDER_MATERIAL); - if (param_block) - { - param_block->setMaterial(te, asset_id); - } - } - else // Shouldn't happen? - { - S32 num_faces = objectp->getNumTEs(); - for (S32 face = 0; face < num_faces; face++) - { - LLTextureEntry* tep = objectp->getTE(face); - if (asset_id.notNull()) - { - tep->setGLTFMaterial(gGLTFMaterialList.getMaterial(asset_id)); - } - else - { - tep->setGLTFMaterial(nullptr); - } - - objectp->faceMappingChanged(); - gPipeline.markTextured(objectp->mDrawable); - - LLRenderMaterialParams* param_block = (LLRenderMaterialParams*)objectp->getParameterEntry(LLNetworkData::PARAMS_RENDER_MATERIAL); - if (param_block) - { - param_block->setMaterial(face, asset_id); - } - } - } + objectp->setRenderMaterialID(te, asset_id); return true; } diff --git a/indra/newview/llviewerobject.cpp b/indra/newview/llviewerobject.cpp index ac76ad7272..cbdf3964e5 100644 --- a/indra/newview/llviewerobject.cpp +++ b/indra/newview/llviewerobject.cpp @@ -7113,26 +7113,55 @@ const LLUUID& LLViewerObject::getRenderMaterialID(U8 te) const return LLUUID::null; } -void LLViewerObject::setRenderMaterialID(U8 te, const LLUUID& id, bool update_server) +void LLViewerObject::setRenderMaterialID(S32 te_in, const LLUUID& id, bool update_server) { - if (id.notNull()) + S32 start_idx = 0; + S32 end_idx = getNumTEs(); + + if (te_in != -1) { - getTE(te)->setGLTFMaterial(gGLTFMaterialList.getMaterial(id)); + start_idx = te_in; + end_idx = start_idx + 1; + } + + start_idx = llmax(start_idx, 0); + end_idx = llmin(end_idx, (S32) getNumTEs()); + + for (S32 te = start_idx; te < end_idx; ++te) + { + if (update_server) + { + // clear out any existing override data and render material + getTE(te)->setGLTFMaterialOverride(nullptr); + getTE(te)->setGLTFRenderMaterial(nullptr); + + LLCoros::instance().launch("modifyMaterialCoro", + std::bind(&LLGLTFMaterialList::modifyMaterialCoro, + gAgent.getRegionCapability("ModifyMaterialParams"), + llsd::map( + "object_id", getID(), + "side", te))); + } - if (!hasRenderMaterialParams()) + if (id.notNull()) { - // make sure param section exists - // but do not update server to avoid race conditions - ExtraParameter* param = getExtraParameterEntryCreate(LLNetworkData::PARAMS_RENDER_MATERIAL); - if (param) + getTE(te)->setGLTFMaterial(gGLTFMaterialList.getMaterial(id)); + + if (!hasRenderMaterialParams()) { - param->in_use = true; + // make sure param section exists + // but do not update server to avoid race conditions + ExtraParameter* param = getExtraParameterEntryCreate(LLNetworkData::PARAMS_RENDER_MATERIAL); + if (param) + { + param->in_use = true; + } } } - } - else - { - getTE(te)->setGLTFMaterial(nullptr); + else + { + getTE(te)->setGLTFMaterial(nullptr); + } } faceMappingChanged(); @@ -7141,82 +7170,35 @@ void LLViewerObject::setRenderMaterialID(U8 te, const LLUUID& id, bool update_se LLRenderMaterialParams* param_block = (LLRenderMaterialParams*)getParameterEntry(LLNetworkData::PARAMS_RENDER_MATERIAL); if (param_block) { - param_block->setMaterial(te, id); + for (S32 te = start_idx; te < end_idx; ++te) + { + param_block->setMaterial(te, id); - if (param_block->isEmpty()) - { // might be empty if id is null - if (hasRenderMaterialParams()) - { - if (update_server) + if (param_block->isEmpty()) + { // might be empty if id is null + if (hasRenderMaterialParams()) { - setParameterEntryInUse(LLNetworkData::PARAMS_RENDER_MATERIAL, FALSE, true); - } - else - { - ExtraParameter* param = getExtraParameterEntryCreate(LLNetworkData::PARAMS_RENDER_MATERIAL); - if (param) + if (update_server) + { + setParameterEntryInUse(LLNetworkData::PARAMS_RENDER_MATERIAL, FALSE, true); + } + else { - param->in_use = false; + ExtraParameter* param = getExtraParameterEntryCreate(LLNetworkData::PARAMS_RENDER_MATERIAL); + if (param) + { + param->in_use = false; + } } } } } - else if (update_server) - { - parameterChanged(LLNetworkData::PARAMS_RENDER_MATERIAL, true); - } } } void LLViewerObject::setRenderMaterialIDs(const LLUUID& id) { - if (id.notNull()) - { - if (!hasRenderMaterialParams()) - { - // make sure param section exists - // but do not update server to avoid race conditions - ExtraParameter* param = getExtraParameterEntryCreate(LLNetworkData::PARAMS_RENDER_MATERIAL); - if (param) - { - param->in_use = true; - } - } - } - - LLRenderMaterialParams* param_block = nullptr; - if (hasRenderMaterialParams()) - { - param_block = (LLRenderMaterialParams*)getParameterEntry(LLNetworkData::PARAMS_RENDER_MATERIAL); - } - - LLGLTFMaterial* material = id.isNull() ? nullptr : gGLTFMaterialList.getMaterial(id); - const S32 num_tes = llmin((S32)getNumTEs(), (S32)getNumFaces()); - - for (S32 te = 0; te < num_tes; te++) - { - getTE(te)->setGLTFMaterial(material); - - if (param_block) - { - param_block->setMaterial(te, id); - } - } - - faceMappingChanged(); - gPipeline.markTextured(mDrawable); - - if (param_block) - { - if (param_block->isEmpty()) - { - setHasRenderMaterialParams(false); - } - else - { - parameterChanged(LLNetworkData::PARAMS_RENDER_MATERIAL, true); - } - } + setRenderMaterialID(-1, id); } void LLViewerObject::setRenderMaterialIDs(const LLRenderMaterialParams* material_params, bool local_origin) diff --git a/indra/newview/llviewerobject.h b/indra/newview/llviewerobject.h index 31e82545ec..d871382256 100644 --- a/indra/newview/llviewerobject.h +++ b/indra/newview/llviewerobject.h @@ -184,7 +184,12 @@ public: void setHasRenderMaterialParams(bool has_params); const LLUUID& getRenderMaterialID(U8 te) const; - void setRenderMaterialID(U8 te, const LLUUID& id, bool update_server = true); + + // set the RenderMaterialID for the given TextureEntry + // te - TextureEntry index to set, or -1 for all TEs + // id - asset id of material asset + // update_server - if true, will send updates to server + void setRenderMaterialID(S32 te, const LLUUID& id, bool update_server = true); void setRenderMaterialIDs(const LLUUID& id); virtual BOOL isHUDAttachment() const { return FALSE; } |