From fd76c195c83d4af7469cc41f59c3fdcb02716012 Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Fri, 11 Nov 2022 15:53:45 -0800 Subject: SL-18632: Implement editing GLTF material texture transforms in build floater --- indra/newview/llpanelface.cpp | 245 +++++++++++++++++---- indra/newview/llpanelface.h | 10 +- .../skins/default/xui/en/panel_tools_texture.xml | 22 +- 3 files changed, 223 insertions(+), 54 deletions(-) diff --git a/indra/newview/llpanelface.cpp b/indra/newview/llpanelface.cpp index 9d720b1523..f43a5d7dbe 100644 --- a/indra/newview/llpanelface.cpp +++ b/indra/newview/llpanelface.cpp @@ -114,6 +114,73 @@ const S32 PBRTYPE_NORMAL = 2; // PBR Normal const S32 PBRTYPE_METALLIC_ROUGHNESS = 3; // PBR Metallic const S32 PBRTYPE_EMISSIVE = 4; // PBR Emissive +LLGLTFMaterial::TextureInfo texture_info_from_pbrtype(S32 pbr_type) +{ + switch (pbr_type) + { + case PBRTYPE_BASE_COLOR: + return LLGLTFMaterial::GLTF_TEXTURE_INFO_BASE_COLOR; + break; + case PBRTYPE_NORMAL: + return LLGLTFMaterial::GLTF_TEXTURE_INFO_NORMAL; + break; + case PBRTYPE_METALLIC_ROUGHNESS: + return LLGLTFMaterial::GLTF_TEXTURE_INFO_METALLIC_ROUGHNESS; + break; + case PBRTYPE_EMISSIVE: + return LLGLTFMaterial::GLTF_TEXTURE_INFO_EMISSIVE; + break; + default: + return LLGLTFMaterial::GLTF_TEXTURE_INFO_COUNT; + break; + } +} + +void updateSelectedGLTFMaterials(std::function func) +{ + struct LLSelectedTEGLTFMaterialFunctor : public LLSelectedTEFunctor + { + LLSelectedTEGLTFMaterialFunctor(std::function func) : mFunc(func) {} + virtual ~LLSelectedTEGLTFMaterialFunctor() {}; + bool apply(LLViewerObject* object, S32 face) override + { + LLGLTFMaterial new_override; + const LLTextureEntry* tep = object->getTE(face); + if (tep->getGLTFMaterialOverride()) + { + new_override = *tep->getGLTFMaterialOverride(); + } + mFunc(&new_override); + LLGLTFMaterialList::queueModify(object->getID(), face, &new_override); + + return true; + } + + std::function mFunc; + } select_func(func); + LLSelectMgr::getInstance()->getSelection()->applyToTEs(&select_func); +} + +template +void readSelectedGLTFMaterial(std::function func, T& value, bool& identical, bool has_tolerance, T tolerance) +{ + struct LLSelectedTEGetGLTFMaterialFunctor : public LLSelectedTEGetFunctor + { + LLSelectedTEGetGLTFMaterialFunctor(std::function func) : mFunc(func) {} + virtual ~LLSelectedTEGetGLTFMaterialFunctor() {}; + T get(LLViewerObject* object, S32 face) override + { + const LLTextureEntry* tep = object->getTE(face); + const LLGLTFMaterial* render_material = tep->getGLTFRenderMaterial(); + + return mFunc(render_material); + } + + std::function mFunc; + } select_func(func); + identical = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue(&select_func, value, has_tolerance, tolerance); +} + BOOST_STATIC_ASSERT(MATTYPE_DIFFUSE == LLRender::DIFFUSE_MAP && MATTYPE_NORMAL == LLRender::NORMAL_MAP && MATTYPE_SPECULAR == LLRender::SPECULAR_MAP); // @@ -201,11 +268,11 @@ BOOL LLPanelFace::postBuild() childSetCommitCallback("add_media", &LLPanelFace::onClickBtnAddMedia, this); childSetCommitCallback("delete_media", &LLPanelFace::onClickBtnDeleteMedia, this); - childSetCommitCallback("gltfTextureScaleU", &LLPanelFace::onCommitGLTFTextureScaleU, this); - childSetCommitCallback("gltfTextureScaleV", &LLPanelFace::onCommitGLTFTextureScaleV, this); - childSetCommitCallback("gltfRotation", &LLPanelFace::onCommitGLTFRotation, this); - childSetCommitCallback("gltfTextureTranslationU", &LLPanelFace::onCommitGLTFTextureTranslationU, this); - childSetCommitCallback("gltfTextureTranslationV", &LLPanelFace::onCommitGLTFTextureTranslationV, this); + childSetCommitCallback("gltfTextureScaleU", boost::bind(&LLPanelFace::onCommitGLTFTextureScaleU, this, _1), nullptr); + childSetCommitCallback("gltfTextureScaleV", boost::bind(&LLPanelFace::onCommitGLTFTextureScaleV, this, _1), nullptr); + childSetCommitCallback("gltfTextureRotation", boost::bind(&LLPanelFace::onCommitGLTFRotation, this, _1), nullptr); + childSetCommitCallback("gltfTextureOffsetU", boost::bind(&LLPanelFace::onCommitGLTFTextureOffsetU, this, _1), nullptr); + childSetCommitCallback("gltfTextureOffsetV", boost::bind(&LLPanelFace::onCommitGLTFTextureOffsetV, this, _1), nullptr); childSetAction("button align",&LLPanelFace::onClickAutoFix,this); childSetAction("button align textures", &LLPanelFace::onAlignTexture, this); @@ -1722,6 +1789,70 @@ void LLPanelFace::updateUIGLTF(LLViewerObject* objectp, bool& has_pbr_material, getChildView("pbr_from_inventory")->setEnabled(editable); getChildView("edit_selected_pbr")->setEnabled(editable && has_pbr_material); getChildView("save_selected_pbr")->setEnabled(objectp->permCopy() && has_pbr_material); + + const bool show_pbr = mComboMatMedia->getCurrentIndex() == MATMEDIA_PBR && mComboMatMedia->getEnabled(); + if (show_pbr) + { + + const U32 pbr_type = findChild("radio_pbr_type")->getSelectedIndex(); + const LLGLTFMaterial::TextureInfo texture_info = texture_info_from_pbrtype(pbr_type); + const bool show_texture_info = texture_info != LLGLTFMaterial::GLTF_TEXTURE_INFO_COUNT; + + LLUICtrl* gltfCtrlTextureScaleU = getChild("gltfTextureScaleU"); + LLUICtrl* gltfCtrlTextureScaleV = getChild("gltfTextureScaleV"); + LLUICtrl* gltfCtrlTextureRotation = getChild("gltfTextureRotation"); + LLUICtrl* gltfCtrlTextureOffsetU = getChild("gltfTextureOffsetU"); + LLUICtrl* gltfCtrlTextureOffsetV = getChild("gltfTextureOffsetV"); + + gltfCtrlTextureScaleU->setEnabled(show_texture_info); + gltfCtrlTextureScaleV->setEnabled(show_texture_info); + gltfCtrlTextureRotation->setEnabled(show_texture_info); + gltfCtrlTextureOffsetU->setEnabled(show_texture_info); + gltfCtrlTextureOffsetV->setEnabled(show_texture_info); + + if (show_texture_info) + { + LLGLTFMaterial::TextureTransform transform; + bool scale_u_same = true; + bool scale_v_same = true; + bool rotation_same = true; + bool offset_u_same = true; + bool offset_v_same = true; + + readSelectedGLTFMaterial([&](const LLGLTFMaterial* mat) + { + return mat->mTextureTransform[texture_info].mScale[VX]; + }, transform.mScale[VX], scale_u_same, true, 1e-3f); + readSelectedGLTFMaterial([&](const LLGLTFMaterial* mat) + { + return mat->mTextureTransform[texture_info].mScale[VY]; + }, transform.mScale[VY], scale_v_same, true, 1e-3f); + readSelectedGLTFMaterial([&](const LLGLTFMaterial* mat) + { + return mat->mTextureTransform[texture_info].mRotation; + }, transform.mRotation, rotation_same, true, 1e-3f); + readSelectedGLTFMaterial([&](const LLGLTFMaterial* mat) + { + return mat->mTextureTransform[texture_info].mOffset[VX]; + }, transform.mOffset[VX], offset_u_same, true, 1e-3f); + readSelectedGLTFMaterial([&](const LLGLTFMaterial* mat) + { + return mat->mTextureTransform[texture_info].mOffset[VY]; + }, transform.mOffset[VY], offset_v_same, true, 1e-3f); + + gltfCtrlTextureScaleU->setValue(transform.mScale[VX]); + gltfCtrlTextureScaleV->setValue(transform.mScale[VY]); + gltfCtrlTextureRotation->setValue(transform.mRotation * RAD_TO_DEG); + gltfCtrlTextureOffsetU->setValue(transform.mOffset[VX]); + gltfCtrlTextureOffsetV->setValue(transform.mOffset[VY]); + + gltfCtrlTextureScaleU->setTentative(!scale_u_same); + gltfCtrlTextureScaleV->setTentative(!scale_v_same); + gltfCtrlTextureRotation->setTentative(!rotation_same); + gltfCtrlTextureOffsetU->setTentative(!offset_u_same); + gltfCtrlTextureOffsetV->setTentative(!offset_v_same); + } + } } void LLPanelFace::updateVisibilityGLTF() @@ -1748,8 +1879,8 @@ void LLPanelFace::updateVisibilityGLTF() getChildView("gltfTextureScaleU")->setVisible(show_pbr_transform); getChildView("gltfTextureScaleV")->setVisible(show_pbr_transform); getChildView("gltfTextureRotation")->setVisible(show_pbr_transform); - getChildView("gltfTextureTranslationU")->setVisible(show_pbr_transform); - getChildView("gltfTextureTranslationV")->setVisible(show_pbr_transform); + getChildView("gltfTextureOffsetU")->setVisible(show_pbr_transform); + getChildView("gltfTextureOffsetV")->setVisible(show_pbr_transform); } void LLPanelFace::updateCopyTexButton() @@ -2597,11 +2728,15 @@ void LLPanelFace::updateVisibility() bool show_texture = (show_media || (show_material && (material_type == MATTYPE_DIFFUSE) && mComboMatMedia->getEnabled())); bool show_bumpiness = show_material && (material_type == MATTYPE_NORMAL) && mComboMatMedia->getEnabled(); bool show_shininess = show_material && (material_type == MATTYPE_SPECULAR) && mComboMatMedia->getEnabled(); + const bool show_pbr = mComboMatMedia->getCurrentIndex() == MATMEDIA_PBR && mComboMatMedia->getEnabled(); + const U32 pbr_type = findChild("radio_pbr_type")->getSelectedIndex(); + const LLGLTFMaterial::TextureInfo texture_info = texture_info_from_pbrtype(pbr_type); + const bool show_texture_info = show_pbr && texture_info != LLGLTFMaterial::GLTF_TEXTURE_INFO_COUNT; radio_mat_type->setVisible(show_material); // Shared material controls - getChildView("checkbox_sync_settings")->setVisible(show_material || show_media); + getChildView("checkbox_sync_settings")->setVisible(show_material || show_media || show_texture_info); getChildView("tex gen")->setVisible(show_material || show_media); getChildView("combobox texgen")->setVisible(show_material || show_media); getChildView("button align textures")->setVisible(show_material || show_media); @@ -4538,54 +4673,78 @@ void LLPanelFace::onCommitPlanarAlign(LLUICtrl* ctrl, void* userdata) self->sendTextureInfo(); } -// static -void LLPanelFace::onCommitGLTFTextureScaleU(LLUICtrl* ctrl, void* userdata) +void updateGLTFTextureTransform(float value, U32 pbr_type, std::function edit) { -#if 0 - LLPanelFace* self = (LLPanelFace*)userdata; - LL_WARNS() << ctrl->getValue().asReal() << LL_ENDL; // TODO: Remove - // TODO -#endif + U32 texture_info_start; + U32 texture_info_end; + if (gSavedSettings.getBOOL("SyncMaterialSettings")) + { + texture_info_start = 0; + texture_info_end = LLGLTFMaterial::GLTF_TEXTURE_INFO_COUNT; + } + else + { + texture_info_start = texture_info_from_pbrtype(pbr_type); + texture_info_end = texture_info_start + 1; + } + updateSelectedGLTFMaterials([&](LLGLTFMaterial* new_override) + { + for (U32 ti = texture_info_start; ti < texture_info_end; ++ti) + { + LLGLTFMaterial::TextureTransform& new_transform = new_override->mTextureTransform[(LLGLTFMaterial::TextureInfo)ti]; + edit(&new_transform); + } + }); } -// static -void LLPanelFace::onCommitGLTFTextureScaleV(LLUICtrl* ctrl, void* userdata) +void LLPanelFace::onCommitGLTFTextureScaleU(LLUICtrl* ctrl) { -#if 0 - LLPanelFace* self = (LLPanelFace*)userdata; - LL_WARNS() << ctrl->getValue().asReal() << LL_ENDL; // TODO: Remove - // TODO -#endif + const float value = ctrl->getValue().asReal(); + const U32 pbr_type = findChild("radio_pbr_type")->getSelectedIndex(); + updateGLTFTextureTransform(value, pbr_type, [&](LLGLTFMaterial::TextureTransform* new_transform) + { + new_transform->mScale.mV[VX] = value; + }); } -// static -void LLPanelFace::onCommitGLTFRotation(LLUICtrl* ctrl, void* userdata) +void LLPanelFace::onCommitGLTFTextureScaleV(LLUICtrl* ctrl) +{ + const float value = ctrl->getValue().asReal(); + const U32 pbr_type = findChild("radio_pbr_type")->getSelectedIndex(); + updateGLTFTextureTransform(value, pbr_type, [&](LLGLTFMaterial::TextureTransform* new_transform) + { + new_transform->mScale.mV[VY] = value; + }); +} + +void LLPanelFace::onCommitGLTFRotation(LLUICtrl* ctrl) { -#if 0 - LLPanelFace* self = (LLPanelFace*)userdata; - LL_WARNS() << ctrl->getValue().asReal() << LL_ENDL; // TODO: Remove - // TODO -#endif + const float value = ctrl->getValue().asReal() * DEG_TO_RAD; + const U32 pbr_type = findChild("radio_pbr_type")->getSelectedIndex(); + updateGLTFTextureTransform(value, pbr_type, [&](LLGLTFMaterial::TextureTransform* new_transform) + { + new_transform->mRotation = value; + }); } -// static -void LLPanelFace::onCommitGLTFTextureTranslationU(LLUICtrl* ctrl, void* userdata) +void LLPanelFace::onCommitGLTFTextureOffsetU(LLUICtrl* ctrl) { -#if 0 - LLPanelFace* self = (LLPanelFace*)userdata; - LL_WARNS() << ctrl->getValue().asReal() << LL_ENDL; // TODO: Remove - // TODO -#endif + const float value = ctrl->getValue().asReal(); + const U32 pbr_type = findChild("radio_pbr_type")->getSelectedIndex(); + updateGLTFTextureTransform(value, pbr_type, [&](LLGLTFMaterial::TextureTransform* new_transform) + { + new_transform->mOffset.mV[VX] = value; + }); } -// static -void LLPanelFace::onCommitGLTFTextureTranslationV(LLUICtrl* ctrl, void* userdata) +void LLPanelFace::onCommitGLTFTextureOffsetV(LLUICtrl* ctrl) { -#if 0 - LLPanelFace* self = (LLPanelFace*)userdata; - LL_WARNS() << ctrl->getValue().asReal() << LL_ENDL; // TODO: Remove - // TODO -#endif + const float value = ctrl->getValue().asReal(); + const U32 pbr_type = findChild("radio_pbr_type")->getSelectedIndex(); + updateGLTFTextureTransform(value, pbr_type, [&](LLGLTFMaterial::TextureTransform* new_transform) + { + new_transform->mOffset.mV[VY] = value; + }); } void LLPanelFace::onTextureSelectionChanged(LLInventoryItem* itemp) diff --git a/indra/newview/llpanelface.h b/indra/newview/llpanelface.h index 0d8a86069d..69744689b5 100644 --- a/indra/newview/llpanelface.h +++ b/indra/newview/llpanelface.h @@ -229,11 +229,11 @@ protected: static void onCommitGlow( LLUICtrl* ctrl, void *userdata); static void onCommitPlanarAlign( LLUICtrl* ctrl, void* userdata); static void onCommitRepeatsPerMeter( LLUICtrl* ctrl, void* userinfo); - static void onCommitGLTFTextureScaleU(LLUICtrl* ctrl, void* userinfo); - static void onCommitGLTFTextureScaleV(LLUICtrl* ctrl, void* userinfo); - static void onCommitGLTFRotation(LLUICtrl* ctrl, void* userinfo); - static void onCommitGLTFTextureTranslationU(LLUICtrl* ctrl, void* userinfo); - static void onCommitGLTFTextureTranslationV(LLUICtrl* ctrl, void* userinfo); + void onCommitGLTFTextureScaleU(LLUICtrl* ctrl); + void onCommitGLTFTextureScaleV(LLUICtrl* ctrl); + void onCommitGLTFRotation(LLUICtrl* ctrl); + void onCommitGLTFTextureOffsetU(LLUICtrl* ctrl); + void onCommitGLTFTextureOffsetV(LLUICtrl* ctrl); static void onClickAutoFix(void*); static void onAlignTexture(void*); static void onClickBtnLoadInvPBR(void* userdata); diff --git a/indra/newview/skins/default/xui/en/panel_tools_texture.xml b/indra/newview/skins/default/xui/en/panel_tools_texture.xml index 91cd28d80a..06e2a6e98e 100644 --- a/indra/newview/skins/default/xui/en/panel_tools_texture.xml +++ b/indra/newview/skins/default/xui/en/panel_tools_texture.xml @@ -896,10 +896,12 @@ follows="left|top" height="19" initial_value="1" - label="ScaleU" + label="Scale u" label_width="205" layout="topleft" left="10" + min_val="-100" + max_val="100" name="gltfTextureScaleU" top_delta="-115" width="265" /> @@ -907,10 +909,12 @@ follows="left|top" height="19" initial_value="1" - label="ScaleV" + label="Scale v" label_width="205" layout="topleft" left="10" + min_val="-100" + max_val="100" name="gltfTextureScaleV" width="265" /> Date: Wed, 16 Nov 2022 12:04:16 -0800 Subject: SL-18632: Un-hide planar align options when editing GLTF textures in build floater --- indra/newview/llpanelface.cpp | 10 ++++++---- indra/newview/skins/default/xui/en/panel_tools_texture.xml | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/indra/newview/llpanelface.cpp b/indra/newview/llpanelface.cpp index f43a5d7dbe..d620704019 100644 --- a/indra/newview/llpanelface.cpp +++ b/indra/newview/llpanelface.cpp @@ -1003,6 +1003,8 @@ void LLPanelFace::updateUI(bool force_set_values /*false*/) radio_pbr_type->selectNthItem(PBRTYPE_RENDER_MATERIAL_ID); } radio_pbr_type->setEnabled(editable); + const bool pbr_selected = mComboMatMedia->getCurrentIndex() == MATMEDIA_PBR; + const bool texture_info_selected = pbr_selected && radio_pbr_type->getSelectedIndex() != PBRTYPE_RENDER_MATERIAL_ID; getChildView("checkbox_sync_settings")->setEnabled(editable); childSetValue("checkbox_sync_settings", gSavedSettings.getBOOL("SyncMaterialSettings")); @@ -1251,9 +1253,9 @@ void LLPanelFace::updateUI(bool force_set_values /*false*/) LLCheckBoxCtrl* cb_planar_align = getChild("checkbox planar align"); align_planar = (cb_planar_align && cb_planar_align->get()); - bool enabled = (editable && isIdenticalPlanarTexgen()); + bool enabled = (editable && isIdenticalPlanarTexgen() && (!pbr_selected || texture_info_selected)); childSetValue("checkbox planar align", align_planar && enabled); - childSetVisible("checkbox planar align", enabled); + childSetVisible("checkbox planar align", enabled); childSetEnabled("checkbox planar align", enabled); childSetEnabled("button align textures", enabled && LLSelectMgr::getInstance()->getSelection()->getObjectCount() > 1); @@ -2737,8 +2739,8 @@ void LLPanelFace::updateVisibility() // Shared material controls getChildView("checkbox_sync_settings")->setVisible(show_material || show_media || show_texture_info); - getChildView("tex gen")->setVisible(show_material || show_media); - getChildView("combobox texgen")->setVisible(show_material || show_media); + getChildView("tex gen")->setVisible(show_material || show_media || show_texture_info); + getChildView("combobox texgen")->setVisible(show_material || show_media || show_texture_info); getChildView("button align textures")->setVisible(show_material || show_media); // Media controls diff --git a/indra/newview/skins/default/xui/en/panel_tools_texture.xml b/indra/newview/skins/default/xui/en/panel_tools_texture.xml index 06e2a6e98e..ba5a20dd22 100644 --- a/indra/newview/skins/default/xui/en/panel_tools_texture.xml +++ b/indra/newview/skins/default/xui/en/panel_tools_texture.xml @@ -963,7 +963,7 @@ left="7" name="checkbox planar align" tool_tip="Align textures on all selected faces with the last selected face. Requires Planar texture mapping." - top_delta="16" + top_delta="43" width="260" />