summaryrefslogtreecommitdiff
path: root/indra/newview/llmaterialeditor.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'indra/newview/llmaterialeditor.cpp')
-rw-r--r--indra/newview/llmaterialeditor.cpp182
1 files changed, 169 insertions, 13 deletions
diff --git a/indra/newview/llmaterialeditor.cpp b/indra/newview/llmaterialeditor.cpp
index 27b5d508e0..735b4af689 100644
--- a/indra/newview/llmaterialeditor.cpp
+++ b/indra/newview/llmaterialeditor.cpp
@@ -935,13 +935,33 @@ bool LLMaterialEditor::saveIfNeeded()
tid.generate(); // timestamp-based randomization + uniquification
LLAssetID new_asset_id = tid.makeAssetID(gAgent.getSecureSessionID());
std::string res_desc = buildMaterialDescription();
- U32 next_owner_perm = LLFloaterPerms::getNextOwnerPerms("Uploads");
+ U32 next_owner_perm = LLFloaterPerms::getNextOwnerPerms("Materials");
LLUUID parent = gInventory.findUserDefinedCategoryUUIDForType(LLFolderType::FT_MATERIAL);
const U8 subtype = NO_INV_SUBTYPE; // TODO maybe use AT_SETTINGS and LLSettingsType::ST_MATERIAL ?
create_inventory_item(gAgent.getID(), gAgent.getSessionID(), parent, tid, mMaterialName, res_desc,
LLAssetType::AT_MATERIAL, LLInventoryType::IT_MATERIAL, subtype, next_owner_perm,
- new LLBoostFuncInventoryCallback([output = buffer](LLUUID const& inv_item_id) {
+ new LLBoostFuncInventoryCallback([output = buffer](LLUUID const& inv_item_id)
+ {
+ LLViewerInventoryItem* item = gInventory.getItem(inv_item_id);
+ if (item)
+ {
+ // create_inventory_item doesn't allow presetting some permissions, fix it now
+ LLPermissions perm = item->getPermissions();
+ if (perm.getMaskEveryone() != LLFloaterPerms::getEveryonePerms("Materials")
+ || perm.getMaskGroup() != LLFloaterPerms::getGroupPerms("Materials"))
+ {
+ perm.setMaskEveryone(LLFloaterPerms::getEveryonePerms("Materials"));
+ perm.setMaskGroup(LLFloaterPerms::getGroupPerms("Materials"));
+
+ item->setPermissions(perm);
+
+ item->updateServer(FALSE);
+ gInventory.updateItem(item);
+ gInventory.notifyObservers();
+ }
+ }
+
// from reference in LLSettingsVOBase::createInventoryItem()/updateInventoryItem()
LLResourceUploadInfo::ptr_t uploadInfo =
std::make_shared<LLBufferedAssetUploadInfo>(
@@ -966,7 +986,7 @@ bool LLMaterialEditor::saveIfNeeded()
}
LLViewerAssetUpload::EnqueueInventoryUpload(agent_url, uploadInfo);
}
- })
+ })
);
// We do not update floater with uploaded asset yet, so just close it.
@@ -1379,6 +1399,16 @@ void LLMaterialEditor::loadMaterialFromFile(const std::string& filename, S32 ind
}
}
+void LLMaterialEditor::loadLiveMaterial(LLGLTFMaterial * material, bool make_copy)
+{
+ if (!material)
+ {
+ return;
+ }
+ LLMaterialEditor* me = (LLMaterialEditor*)LLFloaterReg::getInstance("material_editor");
+ me->loadMaterial(material, make_copy);
+}
+
void LLMaterialEditor::loadMaterial(const tinygltf::Model &model_in, const std::string &filename_lc, S32 index)
{
if (model_in.materials.size() <= index)
@@ -1483,6 +1513,61 @@ void LLMaterialEditor::loadMaterial(const tinygltf::Model &model_in, const std::
applyToSelection();
}
+void LLMaterialEditor::loadMaterial(LLGLTFMaterial * material, bool make_copy)
+{
+ setBaseColorId(material->mBaseColorId);
+ setMetallicRoughnessId(material->mMetallicRoughnessId);
+ setEmissiveId(material->mEmissiveId);
+ setNormalId(material->mNormalId);
+
+ setAlphaMode(material->getAlphaMode());
+ setAlphaCutoff(material->mAlphaCutoff);
+
+ setBaseColor(material->mBaseColor);
+ setEmissiveColor(material->mEmissiveColor);
+
+ setMetalnessFactor(material->mMetallicFactor);
+ setRoughnessFactor(material->mRoughnessFactor);
+
+ setDoubleSided(material->mDoubleSided);
+
+ if (make_copy)
+ {
+ setTitle(LLTrans::getString("New Material"));
+ }
+ else
+ {
+ setTitle(getString("material_override_title"));
+ // TODO: Save whole selection
+
+ LLObjectSelectionHandle selection = LLSelectMgr::getInstance()->getSelection();
+ LLViewerObject* object = selection->getFirstNode()->getObject();
+ if (object)
+ {
+ const S32 num_tes = llmin((S32)object->getNumTEs(), (S32)object->getNumFaces()); // avatars have TEs but no faces
+ for (S32 face = 0; face < num_tes; ++face)
+ {
+ LLTextureEntry *te = object->getTE(face);
+ if (te->isSelected())
+ {
+ // TEMP
+ setOverrideTarget(object->getLocalID(), face);
+ break;
+ }
+ }
+ }
+ }
+
+ // Todo: At the moment it always makes a 'copy'
+ // Will need a way to expand existing material
+ // once overrides are done
+
+ setHasUnsavedChanges(make_copy);
+
+ openFloater();
+ setFocus(TRUE);
+}
+
bool LLMaterialEditor::setFromGltfModel(const tinygltf::Model& model, S32 index, bool set_textures)
{
if (model.materials.size() > index)
@@ -1788,10 +1873,10 @@ void LLMaterialEditor::importMaterial()
true);
}
-class LLRemderMaterialFunctor : public LLSelectedTEFunctor
+class LLRenderMaterialFunctor : public LLSelectedTEFunctor
{
public:
- LLRemderMaterialFunctor(const LLUUID &id)
+ LLRenderMaterialFunctor(const LLUUID &id)
: mMatId(id)
{
}
@@ -1810,16 +1895,59 @@ private:
LLUUID mMatId;
};
+class LLRenderMaterialOverrideFunctor : public LLSelectedTEFunctor
+{
+public:
+ LLRenderMaterialOverrideFunctor(LLMaterialEditor * me, std::string const & url)
+ : mEditor(me), mCapUrl(url)
+ {
+
+ }
+
+ bool apply(LLViewerObject* objectp, S32 te) override
+ {
+ if (objectp && objectp->permModify() && objectp->getVolume())
+ {
+ //LLVOVolume* vobjp = (LLVOVolume*)objectp;
+ S32 local_id = objectp->getLocalID();
+
+ LLSD overrides = llsd::map(
+ "local_id", local_id,
+ "side", te,
+ "overrides", LLSD::emptyMap()
+ );
+ LLCoros::instance().launch("modifyMaterialCoro", std::bind(&LLMaterialEditor::modifyMaterialCoro, mEditor, mCapUrl, overrides));
+ }
+ return true;
+ }
+
+private:
+ LLMaterialEditor * mEditor;
+ std::string mCapUrl;
+};
+
void LLMaterialEditor::applyToSelection()
{
- // Placehodler. Will be removed once override systems gets finished.
- LLPointer<LLGLTFMaterial> mat = new LLGLTFMaterial();
- getGLTFMaterial(mat);
- const LLUUID placeholder("984e183e-7811-4b05-a502-d79c6f978a98");
- gGLTFMaterialList.addMaterial(placeholder, mat);
- LLRemderMaterialFunctor mat_func(placeholder);
- LLObjectSelectionHandle selected_objects = LLSelectMgr::getInstance()->getSelection();
- selected_objects->applyToTEs(&mat_func);
+ std::string url = gAgent.getRegionCapability("ModifyMaterialParams");
+ if (!url.empty())
+ {
+ LLObjectSelectionHandle selected_objects = LLSelectMgr::getInstance()->getSelection();
+ LLRenderMaterialOverrideFunctor override_func(this, url);
+ selected_objects->applyToTEs(&override_func);
+ }
+ else
+ {
+ LL_WARNS() << "not connected to materials capable region, missing ModifyMaterialParams cap" << LL_ENDL;
+
+ // Fallback local preview. Will be removed once override systems is finished and new cap is deployed everywhere.
+ LLPointer<LLGLTFMaterial> mat = new LLGLTFMaterial();
+ getGLTFMaterial(mat);
+ static const LLUUID placeholder("984e183e-7811-4b05-a502-d79c6f978a98");
+ gGLTFMaterialList.addMaterial(placeholder, mat);
+ LLRenderMaterialFunctor mat_func(placeholder);
+ LLObjectSelectionHandle selected_objects = LLSelectMgr::getInstance()->getSelection();
+ selected_objects->applyToTEs(&mat_func);
+ }
}
void LLMaterialEditor::getGLTFMaterial(LLGLTFMaterial* mat)
@@ -2212,3 +2340,31 @@ void LLMaterialEditor::loadDefaults()
model_in.materials.resize(1);
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;
+ }
+}