From 279ec534dd999420544b672cf84841b86d1306ae Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev Date: Mon, 1 Jul 2024 17:10:13 +0300 Subject: viewer#1131 gltf model upload UI WIP #3 --- indra/newview/llfloatergltfasseteditor.cpp | 269 +++++++++++++++++++- indra/newview/llfloatergltfasseteditor.h | 38 ++- indra/newview/llgltffolderitem.h | 2 +- .../default/xui/en/floater_gltf_asset_editor.xml | 271 ++++++++++++++++++++- 4 files changed, 566 insertions(+), 14 deletions(-) (limited to 'indra') diff --git a/indra/newview/llfloatergltfasseteditor.cpp b/indra/newview/llfloatergltfasseteditor.cpp index 62546c6ed9..ec9ccc1324 100644 --- a/indra/newview/llfloatergltfasseteditor.cpp +++ b/indra/newview/llfloatergltfasseteditor.cpp @@ -31,7 +31,9 @@ #include "gltf/asset.h" #include "llcallbacklist.h" +#include "llmenubutton.h" #include "llselectmgr.h" +#include "llspinctrl.h" #include "llviewerobject.h" const LLColor4U DEFAULT_WHITE(255, 255, 255); @@ -43,16 +45,69 @@ LLFloaterGLTFAssetEditor::LLFloaterGLTFAssetEditor(const LLSD& key) , mUIColor(LLUIColorTable::instance().getColor("MenuItemEnabledColor", DEFAULT_WHITE)) { setTitle("GLTF Asset Editor (WIP)"); + + mCommitCallbackRegistrar.add("PanelObject.menuDoToSelected", [this](LLUICtrl* ctrl, const LLSD& data) { onMenuDoToSelected(data); }); + mEnableCallbackRegistrar.add("PanelObject.menuEnable", [this](LLUICtrl* ctrl, const LLSD& data) { return onMenuEnableItem(data); }); } LLFloaterGLTFAssetEditor::~LLFloaterGLTFAssetEditor() { gIdleCallbacks.deleteFunction(idle, this); + + if (mScroller) + { + removeChild(mScroller); + delete mScroller; + mScroller = NULL; + } } bool LLFloaterGLTFAssetEditor::postBuild() { - mItemListPanel = getChild("item_list_panel"); + // Position + mMenuClipboardPos = getChild("clipboard_pos_btn"); + mCtrlPosX = getChild("Pos X", true); + mCtrlPosX->setCommitCallback([this](LLUICtrl* ctrl, const LLSD& param) { onCommitTransform(); }); + mCtrlPosY = getChild("Pos Y", true); + mCtrlPosY->setCommitCallback([this](LLUICtrl* ctrl, const LLSD& param) { onCommitTransform(); }); + mCtrlPosZ = getChild("Pos Z", true); + mCtrlPosZ->setCommitCallback([this](LLUICtrl* ctrl, const LLSD& param) { onCommitTransform(); }); + + // Scale + mMenuClipboardScale = getChild("clipboard_size_btn"); + mCtrlScaleX = getChild("Scale X", true); + mCtrlScaleX->setCommitCallback([this](LLUICtrl* ctrl, const LLSD& param) { onCommitTransform(); }); + mCtrlScaleY = getChild("Scale Y", true); + mCtrlScaleY->setCommitCallback([this](LLUICtrl* ctrl, const LLSD& param) { onCommitTransform(); }); + mCtrlScaleZ = getChild("Scale Z", true); + mCtrlScaleZ->setCommitCallback([this](LLUICtrl* ctrl, const LLSD& param) { onCommitTransform(); }); + + // Rotation + mMenuClipboardRot = getChild("clipboard_rot_btn"); + mCtrlRotX = getChild("Rot X", true); + mCtrlRotX->setCommitCallback([this](LLUICtrl* ctrl, const LLSD& param) { onCommitTransform(); }); + mCtrlRotY = getChild("Rot Y", true); + mCtrlRotY->setCommitCallback([this](LLUICtrl* ctrl, const LLSD& param) { onCommitTransform(); }); + mCtrlRotZ = getChild("Rot Z", true); + mCtrlPosZ->setCommitCallback([this](LLUICtrl* ctrl, const LLSD& param) { onCommitTransform(); }); + setTransformsEnabled(false); + // todo: do multiple panels based on selected element. + mTransformsPanel = getChild("transform_panel", true); + mTransformsPanel->setVisible(false); + + mItemListPanel = getChild("item_list_panel", true); + initFolderRoot(); + + return true; +} + +void LLFloaterGLTFAssetEditor::initFolderRoot() +{ + if (mScroller || mFolderRoot) + { + LL_ERRS() << "Folder root already initialized" << LL_ENDL; + return; + } LLRect scroller_view_rect = mItemListPanel->getRect(); scroller_view_rect.translate(-scroller_view_rect.mLeft, -scroller_view_rect.mBottom); @@ -87,11 +142,10 @@ bool LLFloaterGLTFAssetEditor::postBuild() mFolderRoot->setScrollContainer(mScroller); mFolderRoot->setFollowsAll(); mFolderRoot->setOpen(true); + mFolderRoot->setSelectCallback([this](const std::deque& items, bool user_action) { onFolderSelectionChanged(items, user_action); }); mScroller->setVisible(true); gIdleCallbacks.addFunction(idle, this); - - return true; } void LLFloaterGLTFAssetEditor::onOpen(const LLSD& key) @@ -252,3 +306,212 @@ void LLFloaterGLTFAssetEditor::loadFromSelection() mFolderRoot->update(); } +void LLFloaterGLTFAssetEditor::onFolderSelectionChanged(const std::deque& items, bool user_action) +{ + if (items.empty()) + { + setTransformsEnabled(false); + return; + } + + LLFolderViewItem* item = items.front(); + LLGLTFFolderItem* vmi = static_cast(item->getViewModelItem()); + + switch (vmi->getType()) + { + case LLGLTFFolderItem::TYPE_NODE: + { + setTransformsEnabled(true); + loadNodeTransforms(vmi->getItemId()); + break; + } + default: + { + setTransformsEnabled(false); + break; + } + } +} + +void LLFloaterGLTFAssetEditor::setTransformsEnabled(bool val) +{ + mMenuClipboardPos->setEnabled(val); + mCtrlPosX->setEnabled(val); + mCtrlPosY->setEnabled(val); + mCtrlPosZ->setEnabled(val); + mMenuClipboardScale->setEnabled(val); + mCtrlScaleX->setEnabled(val); + mCtrlScaleY->setEnabled(val); + mCtrlScaleZ->setEnabled(val); + mMenuClipboardRot->setEnabled(val); + mCtrlRotX->setEnabled(val); + mCtrlRotY->setEnabled(val); + mCtrlRotZ->setEnabled(val); +} + +void LLFloaterGLTFAssetEditor::loadNodeTransforms(S32 node_id) +{ + if (node_id < 0 || node_id >= mAsset->mNodes.size()) + { + LL_ERRS() << "Node id out of range: " << node_id << LL_ENDL; + return; + } + + LL::GLTF::Node& node = mAsset->mNodes[node_id]; + + mCtrlPosX->set(node.mTranslation[0]); + mCtrlPosY->set(node.mTranslation[1]); + mCtrlPosZ->set(node.mTranslation[2]); + + mCtrlScaleX->set(node.mScale[0]); + mCtrlScaleY->set(node.mScale[1]); + mCtrlScaleZ->set(node.mScale[2]); + + LLQuaternion object_rot = LLQuaternion(node.mRotation[0], node.mRotation[1], node.mRotation[2], node.mRotation[3]); + object_rot.getEulerAngles(&(mLastEulerDegrees.mV[VX]), &(mLastEulerDegrees.mV[VY]), &(mLastEulerDegrees.mV[VZ])); + mLastEulerDegrees *= RAD_TO_DEG; + mLastEulerDegrees.mV[VX] = fmod(ll_round(mLastEulerDegrees.mV[VX], OBJECT_ROTATION_PRECISION) + 360.f, 360.f); + mLastEulerDegrees.mV[VY] = fmod(ll_round(mLastEulerDegrees.mV[VY], OBJECT_ROTATION_PRECISION) + 360.f, 360.f); + mLastEulerDegrees.mV[VZ] = fmod(ll_round(mLastEulerDegrees.mV[VZ], OBJECT_ROTATION_PRECISION) + 360.f, 360.f); + + mCtrlRotX->set(mLastEulerDegrees.mV[VX]); + mCtrlRotY->set(mLastEulerDegrees.mV[VY]); + mCtrlRotZ->set(mLastEulerDegrees.mV[VZ]); +} + +void LLFloaterGLTFAssetEditor::onCommitTransform() +{ + if (!mFolderRoot) + { + LL_ERRS() << "Folder root not initialized" << LL_ENDL; + return; + } + + LLFolderViewItem* item = mFolderRoot->getCurSelectedItem(); + if (!item) + { + LL_ERRS() << "Nothing selected" << LL_ENDL; + return; + } + + LLGLTFFolderItem* vmi = static_cast(item->getViewModelItem()); + + if (!vmi || vmi->getType() != LLGLTFFolderItem::TYPE_NODE) + { + LL_ERRS() << "Only nodes implemented" << LL_ENDL; + return; + } + S32 node_id = vmi->getItemId(); + LL::GLTF::Node& node = mAsset->mNodes[node_id]; + + LL::GLTF::vec3 tr(mCtrlPosX->get(), mCtrlPosY->get(), mCtrlPosZ->get()); + node.setTranslation(tr); + + LL::GLTF::vec3 scale(mCtrlScaleX->get(), mCtrlScaleY->get(), mCtrlScaleZ->get()); + node.setScale(scale); + + LLVector3 new_rot(mCtrlRotX->get(), mCtrlRotY->get(), mCtrlRotZ->get()); + new_rot.mV[VX] = ll_round(new_rot.mV[VX], OBJECT_ROTATION_PRECISION); + new_rot.mV[VY] = ll_round(new_rot.mV[VY], OBJECT_ROTATION_PRECISION); + new_rot.mV[VZ] = ll_round(new_rot.mV[VZ], OBJECT_ROTATION_PRECISION); + + // Note: must compare before conversion to radians, some value can go 'around' 360 + LLVector3 delta = new_rot - mLastEulerDegrees; + + if (delta.magVec() >= 0.0005f) + { + mLastEulerDegrees = new_rot; + new_rot *= DEG_TO_RAD; + + LLQuaternion rotation; + rotation.setQuat(new_rot.mV[VX], new_rot.mV[VY], new_rot.mV[VZ]); + LL::GLTF::quat q; + q[0] = rotation.mQ[VX]; + q[1] = rotation.mQ[VY]; + q[2] = rotation.mQ[VZ]; + q[3] = rotation.mQ[VW]; + + node.setRotation(q); + } + + mAsset->updateTransforms(); +} + +void LLFloaterGLTFAssetEditor::onMenuDoToSelected(const LLSD& userdata) +{ + std::string command = userdata.asString(); + + if (command == "psr_paste") + { + // todo: implement + // onPastePos(); + // onPasteSize(); + // onPasteRot(); + } + else if (command == "pos_paste") + { + // todo: implement + } + else if (command == "size_paste") + { + // todo: implement + } + else if (command == "rot_paste") + { + // todo: implement + } + else if (command == "psr_copy") + { + // onCopyPos(); + // onCopySize(); + // onCopyRot(); + } + else if (command == "pos_copy") + { + // todo: implement + } + else if (command == "size_copy") + { + // todo: implement + } + else if (command == "rot_copy") + { + // todo: implement + } +} + +bool LLFloaterGLTFAssetEditor::onMenuEnableItem(const LLSD& userdata) +{ + if (!mFolderRoot) + { + return false; + } + + LLFolderViewItem* item = mFolderRoot->getCurSelectedItem(); + if (!item) + { + return false; + } + + LLGLTFFolderItem* vmi = static_cast(item->getViewModelItem()); + + if (!vmi || vmi->getType() != LLGLTFFolderItem::TYPE_NODE) + { + return false; + } + + std::string command = userdata.asString(); + if (command == "pos_paste" || command == "size_paste" || command == "rot_paste") + { + // todo: implement + return true; + } + if (command == "psr_copy") + { + // todo: implement + return true; + } + + return false; +} + diff --git a/indra/newview/llfloatergltfasseteditor.h b/indra/newview/llfloatergltfasseteditor.h index 49c5aa4ae7..8164928824 100644 --- a/indra/newview/llfloatergltfasseteditor.h +++ b/indra/newview/llfloatergltfasseteditor.h @@ -40,6 +40,9 @@ namespace LL } } +class LLSpinCtrl; +class LLMenuButton; + class LLFloaterGLTFAssetEditor : public LLFloater { public: @@ -48,6 +51,7 @@ public: bool postBuild() override; void onOpen(const LLSD& key) override; + void initFolderRoot(); LLGLTFViewModel& getRootViewModel() { return mGLTFViewModel; } @@ -56,14 +60,42 @@ public: void loadFromNode(S32 node, LLFolderViewFolder* parent); void loadFromSelection(); +protected: + void onFolderSelectionChanged(const std::deque& items, bool user_action); + void onCommitTransform(); + void onMenuDoToSelected(const LLSD& userdata); + bool onMenuEnableItem(const LLSD& userdata); + + void setTransformsEnabled(bool val); + void loadNodeTransforms(S32 id); + private: - LLGLTFViewModel mGLTFViewModel; - LLUIColor mUIColor; + std::shared_ptr mAsset; + + // Folder view related + LLUIColor mUIColor; + LLGLTFViewModel mGLTFViewModel; LLPanel* mItemListPanel = nullptr; LLFolderView* mFolderRoot = nullptr; LLScrollContainer* mScroller = nullptr; - std::shared_ptr mAsset; + + // Transforms panel + LLVector3 mLastEulerDegrees; + + LLPanel* mTransformsPanel = nullptr; + LLMenuButton* mMenuClipboardPos = nullptr; + LLSpinCtrl* mCtrlPosX = nullptr; + LLSpinCtrl* mCtrlPosY = nullptr; + LLSpinCtrl* mCtrlPosZ = nullptr; + LLMenuButton* mMenuClipboardScale = nullptr; + LLSpinCtrl* mCtrlScaleX = nullptr; + LLSpinCtrl* mCtrlScaleY = nullptr; + LLSpinCtrl* mCtrlScaleZ = nullptr; + LLMenuButton* mMenuClipboardRot = nullptr; + LLSpinCtrl* mCtrlRotX = nullptr; + LLSpinCtrl* mCtrlRotY = nullptr; + LLSpinCtrl* mCtrlRotZ = nullptr; }; #endif LL_LLFLOATERGLTFASSETEDITOR_H diff --git a/indra/newview/llgltffolderitem.h b/indra/newview/llgltffolderitem.h index be6e264368..83c6449f96 100644 --- a/indra/newview/llgltffolderitem.h +++ b/indra/newview/llgltffolderitem.h @@ -112,7 +112,7 @@ public: bool filter(LLFolderViewFilter& filter) override; EType getType() const { return mItemType; } - S32 getId() const { return mItemId; } + S32 getItemId() const { return mItemId; } private: LLUIImagePtr pIcon; diff --git a/indra/newview/skins/default/xui/en/floater_gltf_asset_editor.xml b/indra/newview/skins/default/xui/en/floater_gltf_asset_editor.xml index 4dc0dffcfd..82e0e325fb 100644 --- a/indra/newview/skins/default/xui/en/floater_gltf_asset_editor.xml +++ b/indra/newview/skins/default/xui/en/floater_gltf_asset_editor.xml @@ -3,9 +3,9 @@ legacy_header_height="18" can_resize="true" default_tab_group="1" - height="400" + height="530" width="256" - min_height="200" + min_height="400" min_width="200" layout="topleft" name="gltf asset editor" @@ -14,13 +14,270 @@ - + right="-1" + border_size="0"> + + + + + + + + + Position (m) + + + + + + + Size (m) + + + + + + + Rotation (°) + + + + + + + + + -- cgit v1.2.3