Skip to content

Commit

Permalink
viewer#1131 gltf model upload UI WIP #4
Browse files Browse the repository at this point in the history
Hooked selection to tree view
  • Loading branch information
akleshchev committed Jul 3, 2024
1 parent 32f3107 commit 9a38ece
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 9 deletions.
108 changes: 99 additions & 9 deletions indra/newview/llfloatergltfasseteditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ LLFloaterGLTFAssetEditor::LLFloaterGLTFAssetEditor(const LLSD& key)

LLFloaterGLTFAssetEditor::~LLFloaterGLTFAssetEditor()
{
gIdleCallbacks.deleteFunction(idle, this);

if (mScroller)
{
removeChild(mScroller);
Expand Down Expand Up @@ -120,7 +118,7 @@ void LLFloaterGLTFAssetEditor::initFolderRoot()
// Insert that scroller into the panel widgets hierarchy
mItemListPanel->addChild(mScroller);

// Create the root model and view for all conversation sessions
// Create the root model
LLGLTFFolderItem* base_item = new LLGLTFFolderItem(mGLTFViewModel);

LLFolderView::Params p(LLUICtrlFactory::getDefaultParams<LLFolderView>());
Expand All @@ -144,15 +142,33 @@ void LLFloaterGLTFAssetEditor::initFolderRoot()
mFolderRoot->setOpen(true);
mFolderRoot->setSelectCallback([this](const std::deque<LLFolderViewItem*>& items, bool user_action) { onFolderSelectionChanged(items, user_action); });
mScroller->setVisible(true);

gIdleCallbacks.addFunction(idle, this);
}

void LLFloaterGLTFAssetEditor::onOpen(const LLSD& key)
{
gIdleCallbacks.addFunction(idle, this);
loadFromSelection();
}

void LLFloaterGLTFAssetEditor::onClose(bool app_quitting)
{
gIdleCallbacks.deleteFunction(idle, this);
mAsset = nullptr;
mObject = nullptr;

}

void LLFloaterGLTFAssetEditor::clearRoot()
{
LLFolderViewFolder::folders_t::iterator folders_it = mFolderRoot->getFoldersBegin();
while (folders_it != mFolderRoot->getFoldersEnd())
{
(*folders_it)->destroyView();
folders_it = mFolderRoot->getFoldersBegin();
}
mNodeToItemMap.clear();
}

void LLFloaterGLTFAssetEditor::idle(void* user_data)
{
LLFloaterGLTFAssetEditor* floater = (LLFloaterGLTFAssetEditor*)user_data;
Expand Down Expand Up @@ -216,6 +232,8 @@ void LLFloaterGLTFAssetEditor::loadFromNode(S32 node_id, LLFolderViewFolder* par
view->setVisible(true);
view->setOpen(true);

mNodeToItemMap[node_id] = view;

for (S32& node_id : node.mChildren)
{
loadFromNode(node_id, view);
Expand Down Expand Up @@ -246,23 +264,32 @@ void LLFloaterGLTFAssetEditor::loadFromNode(S32 node_id, LLFolderViewFolder* par

void LLFloaterGLTFAssetEditor::loadFromSelection()
{
if (!mFolderRoot || LLSelectMgr::getInstance()->getSelection()->getObjectCount() != 1)
clearRoot();

if (LLSelectMgr::getInstance()->getSelection()->getObjectCount() != 1)
{
mAsset = nullptr;
mObject = nullptr;
return;
}

LLSelectNode* node = LLSelectMgr::getInstance()->getSelection()->getFirstNode(NULL);
LLViewerObject* objectp = node->getObject();
if (!objectp)
{
mAsset = nullptr;
mObject = nullptr;
return;
}

mAsset = objectp->mGLTFAsset;
if (!mAsset)
if (!objectp->mGLTFAsset)
{
mAsset = nullptr;
mObject = nullptr;
return;
}
mAsset = objectp->mGLTFAsset;
mObject = objectp;

if (node->mName.empty())
{
Expand All @@ -289,7 +316,6 @@ void LLFloaterGLTFAssetEditor::loadFromSelection()

LLGLTFFolderItem* listener = new LLGLTFFolderItem(i, name, LLGLTFFolderItem::TYPE_SCENE, mGLTFViewModel);


LLFolderViewFolder::Params p;
p.name = name;
p.root = mFolderRoot;
Expand All @@ -316,6 +342,50 @@ void LLFloaterGLTFAssetEditor::loadFromSelection()
mFolderRoot->update();
}

void LLFloaterGLTFAssetEditor::dirty()
{
if (!mObject || !mAsset || !mFolderRoot)
{
closeFloater();
return;
}

if (LLSelectMgr::getInstance()->getSelection()->getObjectCount() > 1)
{
closeFloater();
return;
}

LLSelectNode* node = LLSelectMgr::getInstance()->getSelection()->getFirstNode(NULL);
if (!node)
{
// not yet updated?
// Todo: Subscribe to deletion in some way
return;
}

LLViewerObject* objectp = node->getObject();
if (mObject != objectp || !objectp->mGLTFAsset)
{
closeFloater();
return;
}

if (mAsset != objectp->mGLTFAsset)
{
loadFromSelection();
return;
}

auto found = mNodeToItemMap.find(node->mSelectedGLTFNode);
if (found != mNodeToItemMap.end())
{
LLFolderViewItem* itemp = found->second;
itemp->arrangeAndSet(true, false);
loadNodeTransforms(node->mSelectedGLTFNode);
}
}

void LLFloaterGLTFAssetEditor::onFolderSelectionChanged(const std::deque<LLFolderViewItem*>& items, bool user_action)
{
if (items.empty())
Expand All @@ -329,10 +399,30 @@ void LLFloaterGLTFAssetEditor::onFolderSelectionChanged(const std::deque<LLFolde

switch (vmi->getType())
{
case LLGLTFFolderItem::TYPE_SCENE:
{
setTransformsEnabled(false);
LLSelectMgr::getInstance()->selectObjectOnly(mObject, SELECT_ALL_TES, -1, -1);
break;
}
case LLGLTFFolderItem::TYPE_NODE:
{
setTransformsEnabled(true);
loadNodeTransforms(vmi->getItemId());
LLSelectMgr::getInstance()->selectObjectOnly(mObject, SELECT_ALL_TES, vmi->getItemId(), 0);
break;
}
case LLGLTFFolderItem::TYPE_MESH:
case LLGLTFFolderItem::TYPE_SKIN:
{
if (item->getParent()) // should be a node
{
LLFolderViewFolder* parent = item->getParentFolder();
LLGLTFFolderItem* parent_vmi = static_cast<LLGLTFFolderItem*>(parent->getViewModelItem());
LLSelectMgr::getInstance()->selectObjectOnly(mObject, SELECT_ALL_TES, parent_vmi->getItemId(), 0);
}

setTransformsEnabled(false);
break;
}
default:
Expand Down
8 changes: 8 additions & 0 deletions indra/newview/llfloatergltfasseteditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ namespace LL

class LLSpinCtrl;
class LLMenuButton;
class LLViewerObject;

class LLFloaterGLTFAssetEditor : public LLFloater
{
Expand All @@ -51,6 +52,7 @@ class LLFloaterGLTFAssetEditor : public LLFloater

bool postBuild() override;
void onOpen(const LLSD& key) override;
void onClose(bool app_quitting) override;
void initFolderRoot();

LLGLTFViewModel& getRootViewModel() { return mGLTFViewModel; }
Expand All @@ -60,6 +62,8 @@ class LLFloaterGLTFAssetEditor : public LLFloater
void loadFromNode(S32 node, LLFolderViewFolder* parent);
void loadFromSelection();

void dirty();

protected:
void onFolderSelectionChanged(const std::deque<LLFolderViewItem*>& items, bool user_action);
void onCommitTransform();
Expand All @@ -69,8 +73,11 @@ class LLFloaterGLTFAssetEditor : public LLFloater
void setTransformsEnabled(bool val);
void loadNodeTransforms(S32 id);

void clearRoot();

private:

LLPointer<LLViewerObject> mObject;
std::shared_ptr<LL::GLTF::Asset> mAsset;

// Folder view related
Expand All @@ -79,6 +86,7 @@ class LLFloaterGLTFAssetEditor : public LLFloater
LLPanel* mItemListPanel = nullptr;
LLFolderView* mFolderRoot = nullptr;
LLScrollContainer* mScroller = nullptr;
std::map<S32, LLFolderViewItem*> mNodeToItemMap;

// Transforms panel
LLVector3 mLastEulerDegrees;
Expand Down
12 changes: 12 additions & 0 deletions indra/newview/llselectmgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
#include "llattachmentsmgr.h"
#include "llviewerwindow.h"
#include "lldrawable.h"
#include "llfloatergltfasseteditor.h"
#include "llfloaterinspect.h"
#include "llfloaterreporter.h"
#include "llfloaterreg.h"
Expand Down Expand Up @@ -467,6 +468,11 @@ LLObjectSelectionHandle LLSelectMgr::selectObjectOnly(LLViewerObject* object, S3
if (object->isSelected() ) {
// make sure point at position is updated
updatePointAt();
LLSelectNode* nodep = mSelectedObjects->findNode(object);
if (nodep)
{
nodep->selectGLTFNode(gltf_node, gltf_primitive, true);
}
gEditMenuHandler = this;
return NULL;
}
Expand Down Expand Up @@ -7187,6 +7193,12 @@ void dialog_refresh_all()
{
panel_task_info->dirty();
}

LLFloaterGLTFAssetEditor * gltf_editor = LLFloaterReg::getTypedInstance<LLFloaterGLTFAssetEditor>("gltf_asset_editor");
if (gltf_editor)
{
gltf_editor->dirty();
}
}

S32 get_family_count(LLViewerObject *parent)
Expand Down

0 comments on commit 9a38ece

Please sign in to comment.