SL-18008 Updated Save and Edit PBR buttons

meow-7.2.2
Andrey Kleshchev 2022-10-18 20:12:38 +03:00
parent f20c47a596
commit 7be33594ea
4 changed files with 74 additions and 127 deletions

View File

@ -65,6 +65,8 @@ const std::string MATERIAL_NORMAL_DEFAULT_NAME = "Normal";
const std::string MATERIAL_METALLIC_DEFAULT_NAME = "Metallic Roughness";
const std::string MATERIAL_EMISSIVE_DEFAULT_NAME = "Emissive";
const LLUUID LIVE_MATERIAL_EDITOR_KEY("6cf97162-8b68-49eb-b627-79886c9fd17d");
LLFloaterComboOptions::LLFloaterComboOptions()
: LLFloater(LLSD())
{
@ -1399,14 +1401,24 @@ void LLMaterialEditor::loadMaterialFromFile(const std::string& filename, S32 ind
}
}
void LLMaterialEditor::loadLiveMaterial(LLGLTFMaterial * material, bool make_copy)
void LLMaterialEditor::loadLiveMaterial(LLUUID &asset_id)
{
LLMaterialEditor* me = (LLMaterialEditor*)LLFloaterReg::getInstance("material_editor", LLSD(LIVE_MATERIAL_EDITOR_KEY));
me->setTitle(me->getString("material_override_title"));
me->setAssetId(asset_id);
me->setFromGLTFMaterial(gGLTFMaterialList.getMaterial(asset_id));
me->openFloater();
me->setFocus(TRUE);
}
void LLMaterialEditor::loadFromGLTFMaterial(LLUUID &asset_id)
{
if (!material)
{
return;
}
LLMaterialEditor* me = (LLMaterialEditor*)LLFloaterReg::getInstance("material_editor");
me->loadMaterial(material, make_copy);
me->setTitle(LLTrans::getString("New Material"));
me->setHasUnsavedChanges(true);
me->setFromGLTFMaterial(gGLTFMaterialList.getMaterial(asset_id));
me->openFloater();
me->setFocus(TRUE);
}
void LLMaterialEditor::loadMaterial(const tinygltf::Model &model_in, const std::string &filename_lc, S32 index)
@ -1513,43 +1525,6 @@ 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: 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)
@ -1863,7 +1838,7 @@ public:
{
}
virtual bool apply(LLViewerObject* objectp, S32 te)
bool apply(LLViewerObject* objectp, S32 te) override
{
if (objectp && objectp->permModify() && objectp->getVolume())
{
@ -1938,6 +1913,15 @@ private:
void LLMaterialEditor::applyToSelection()
{
if (!mKey.isUUID() || mKey.asUUID() != LIVE_MATERIAL_EDITOR_KEY)
{
// Only apply if working with 'live' materials
// Might need a better way to distinguish 'live' mode.
// But only one live edit is supposed to work at a time
// as a pair to tools floater.
return;
}
std::string url = gAgent.getRegionCapability("ModifyMaterialParams");
if (!url.empty())
{

View File

@ -98,13 +98,14 @@ public:
void getGLTFMaterial(LLGLTFMaterial* mat);
void setFromGLTFMaterial(LLGLTFMaterial* mat);
void loadAsset() override;
// @index if -1 and file contains more than one material,
// will promt to select specific one
static void loadMaterialFromFile(const std::string& filename, S32 index = -1);
static void loadLiveMaterial(LLGLTFMaterial * material, bool make_copy);
static void LLMaterialEditor::loadLiveMaterial(LLUUID &asset_id);
static void LLMaterialEditor::loadFromGLTFMaterial(LLUUID &asset_id);
static void onLoadComplete(const LLUUID& asset_uuid, LLAssetType::EType type, void* user_data, S32 status, LLExtStat ext_status);
@ -220,10 +221,9 @@ public:
void modifyMaterialCoro(std::string cap_url, LLSD overrides);
private:
void setFromGLTFMaterial(LLGLTFMaterial* mat);
void loadMaterial(const tinygltf::Model &model, const std::string &filename_lc, S32 index);
// if make_copy is set, will make a copy for saving,
// otherwise will edit existing material
void loadMaterial(LLGLTFMaterial * material, bool make_copy);
friend class LLMaterialFilePicker;

View File

@ -4580,24 +4580,15 @@ void LLPanelFace::onPbrSelectionChanged(LLInventoryItem* itemp)
}
}
void LLPanelFace::onPbrStartEditing() {
LL_DEBUGS() << "begin live editing material" << LL_ENDL;
void LLPanelFace::onPbrStartEditing()
{
bool identical;
LLUUID material_id;
LLSelectedTE::getPbrMaterialId(material_id, identical);
LLMaterialEditor *editor =
dynamic_cast<LLMaterialEditor *>(LLFloaterReg::showInstance("material_editor", LLSD(LLUUID::null), TAKE_FOCUS_YES));
if (editor)
{
bool identical;
LLUUID material_id;
LLSelectedTE::getPbrMaterialId(material_id, identical);
LL_DEBUGS() << "loading material live editor with asset " << material_id << LL_ENDL;
LL_DEBUGS() << "loading material live editor with asset " << material_id << LL_ENDL;
LLPointer<LLGLTFMaterial> material = gGLTFMaterialList.getMaterial(material_id);
editor->setTitle(editor->getString("material_override_title"));
editor->setAssetId(material_id);
editor->setFromGLTFMaterial(material);
}
LLMaterialEditor::loadLiveMaterial(material_id);
}
bool LLPanelFace::isIdenticalPlanarTexgen()

View File

@ -2782,47 +2782,36 @@ void handle_object_open()
LLFloaterReg::showInstance("openobject");
}
struct LLSelectedTEGetmatIdAndPermissions : public LLSelectedTEGetFunctor<LLUUID>
{
LLSelectedTEGetmatIdAndPermissions() : mCanCopy(true), mCanModify(true), mCanTransfer(true) {}
LLUUID get(LLViewerObject* object, S32 te_index)
{
mCanCopy &= (bool)object->permCopy();
mCanTransfer &= (bool)object->permTransfer();
mCanModify &= (bool)object->permModify();
// return true if all ids are identical
return object->getRenderMaterialID(te_index);
}
bool mCanCopy;
bool mCanModify;
bool mCanTransfer;
};
bool enable_object_edit_gltf_material()
{
struct LLSelectedTEGetmatId : public LLSelectedTEGetFunctor<LLUUID>
{
LLSelectedTEGetmatId() : mCanModify(true) {}
LLUUID get(LLViewerObject* object, S32 te_index)
{
mCanModify &= (bool)object->permModify();
// Todo: probabnly should compare material
// pointers instead
return object->getRenderMaterialID(te_index);
}
bool mCanModify;
} func;
LLSelectedTEGetmatIdAndPermissions func;
LLUUID mat_id;
bool identical = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue(&func, mat_id);
LL_INFOS() << " Placeholder " << identical << " " << mat_id << LL_ENDL;
// Todo: this is a placeholder for overrides,
// it will have to make sure all selection is identical
LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue(&func, mat_id);
return func.mCanModify;
}
bool enable_object_save_gltf_material()
{
struct LLSelectedTEGetmatId : public LLSelectedTEGetFunctor<LLUUID>
{
LLSelectedTEGetmatId() : mCanCopy(true) {}
LLUUID get(LLViewerObject* object, S32 te_index)
{
mCanCopy &= (bool)object->permCopy();
// permTransfer probably should be passed to editor instead
mCanCopy &= (bool)object->permTransfer();
return object->getRenderMaterialID(te_index);
}
bool mCanCopy;
} func;
LLSelectedTEGetmatIdAndPermissions func;
LLUUID mat_id;
bool identical = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue(&func, mat_id);
LL_INFOS() << " Placeholder " << identical << " " << mat_id << LL_ENDL;
// Todo: this is a placeholder for overrides,
// it will have to make sure all selection is identical
LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue(&func, mat_id);
return func.mCanCopy;
}
@ -2942,37 +2931,20 @@ void handle_object_edit()
void load_life_gltf_material(bool copy)
{
LLObjectSelectionHandle selection = LLSelectMgr::getInstance()->getSelection();
// All materials are supposed to be identical, so pcik any node
LLViewerObject* object = selection->getFirstNode()->getObject();
if (!object)
{
return;
}
// This functionality is a plcaholder for overrides
// so id doesn't load object by id, but instead gets material directly
LLGLTFMaterial * mat = NULL;
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())
{
mat = te->getGLTFMaterial();
break;
}
}
if (mat == NULL)
{
return;
}
update_camera();
LLMaterialEditor::loadLiveMaterial(mat, copy);
LLSelectedTEGetmatIdAndPermissions func;
LLUUID mat_id;
LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue(&func, mat_id);
if (copy)
{
LLMaterialEditor::loadFromGLTFMaterial(mat_id);
}
else
{
LLMaterialEditor::loadLiveMaterial(mat_id);
}
LLViewerJoystick::getInstance()->moveObjects(true);
LLViewerJoystick::getInstance()->setNeedsReset(true);