Skip to content

Commit

Permalink
viewer#1131 gltf model upload UI WIP #2
Browse files Browse the repository at this point in the history
  • Loading branch information
akleshchev committed Jul 1, 2024
1 parent c7bd452 commit e75595a
Show file tree
Hide file tree
Showing 9 changed files with 461 additions and 153 deletions.
6 changes: 4 additions & 2 deletions indra/newview/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,8 @@ set(viewer_SOURCE_FILES
llgesturemgr.cpp
llgiveinventory.cpp
llglsandbox.cpp
llgltffolderviews.cpp
llgltffolderitem.cpp
llgltffoldermodel.cpp
llgltfmateriallist.cpp
llgltfmaterialpreviewmgr.cpp
llgroupactions.cpp
Expand Down Expand Up @@ -978,7 +979,8 @@ set(viewer_HEADER_FILES
llgesturelistener.h
llgesturemgr.h
llgiveinventory.h
llgltffolderviews.h
llgltffolderitem.h
llgltffoldermodel.h
llgltfmateriallist.h
llgltfmaterialpreviewmgr.h
llgroupactions.h
Expand Down
251 changes: 197 additions & 54 deletions indra/newview/llfloatergltfasseteditor.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @file llfloatergltfasseteditor.cpp
* @author Brad Payne
* @brief LLFloaterFontTest class implementation
* @author Andrii Kleshchev
* @brief LLFloaterGltfAssetEditor class implementation
*
* $LicenseInfo:firstyear=2008&license=viewerlgpl$
* Second Life Viewer Source Code
Expand Down Expand Up @@ -29,72 +29,48 @@

#include "llfloatergltfasseteditor.h"

#include "llfolderviewitem.h"
#include "llgltffolderviews.h"
#include "gltf/asset.h"
#include "llcallbacklist.h"
#include "llselectmgr.h"
#include "llviewerobject.h"

bool LLGLTFSort::operator()(const LLGLTFItem* const& a, const LLGLTFItem* const& b) const
{
// Comparison operator: returns "true" is a comes before b, "false" otherwise
S32 compare = LLStringUtil::compareDict(a->getName(), b->getName());
return (compare < 0);
}

/// LLGLTFViewModel

LLGLTFViewModel::LLGLTFViewModel()
: base_t(new LLGLTFSort(), new LLGLTFFilter())
{}

void LLGLTFViewModel::sort(LLFolderViewFolder* folder)
{
base_t::sort(folder);
}
const LLColor4U DEFAULT_WHITE(255, 255, 255);

/// LLGLTFNode
// LLUICtrlFactory::create<LLGLTFNode>(params);
class LLGLTFNode : public LLFolderViewItem
{
public:
struct Params : public LLInitParam::Block<Params, LLFolderViewItem::Params>
{
Params();
};
~LLGLTFNode();
protected:
LLGLTFNode(const Params& p);
};

LLGLTFNode::LLGLTFNode(const LLGLTFNode::Params& p)
: LLFolderViewItem(p)
{
}

LLGLTFNode::~LLGLTFNode()
{
}
/// LLFloaterGLTFAssetEditor

LLFloaterGltfAssetEditor::LLFloaterGltfAssetEditor(const LLSD& key)
LLFloaterGLTFAssetEditor::LLFloaterGLTFAssetEditor(const LLSD& key)
: LLFloater(key)
, mUIColor(LLUIColorTable::instance().getColor("MenuItemEnabledColor", DEFAULT_WHITE))
{
setTitle("GLTF Asset Editor (WIP)");
}

/// LLFloaterGltfAssetEditor

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

bool LLFloaterGltfAssetEditor::postBuild()
bool LLFloaterGLTFAssetEditor::postBuild()
{
mItemListPanel = getChild<LLPanel>("item_list_panel");

LLRect scroller_view_rect = mItemListPanel->getRect();
scroller_view_rect.translate(-scroller_view_rect.mLeft, -scroller_view_rect.mBottom);
LLScrollContainer::Params scroller_params(LLUICtrlFactory::getDefaultParams<LLFolderViewScrollContainer>());
scroller_params.rect(scroller_view_rect);
scroller_params.name("folder_scroller");
mScroller = LLUICtrlFactory::create<LLFolderViewScrollContainer>(scroller_params);
mScroller->setFollowsAll();

// Insert that scroller into the panel widgets hierarchy
mItemListPanel->addChild(mScroller);

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

LLFolderView::Params p(LLUICtrlFactory::getDefaultParams<LLFolderView>());
p.name = getName();
p.title = getLabel();
p.name = "Root";
p.title = "Root";
p.rect = LLRect(0, 0, getRect().getWidth(), 0);
p.parent_panel = mItemListPanel;
p.tool_tip = p.name;
Expand All @@ -103,9 +79,176 @@ bool LLFloaterGltfAssetEditor::postBuild()
p.root = NULL;
p.use_ellipses = true;
p.options_menu = "menu_gltf.xml"; // *TODO : create this or fix to be optional
mConversationsRoot = LLUICtrlFactory::create<LLFolderView>(p);
mConversationsRoot->setCallbackRegistrar(&mCommitCallbackRegistrar);
mConversationsRoot->setEnableRegistrar(&mEnableCallbackRegistrar);
mFolderRoot = LLUICtrlFactory::create<LLFolderView>(p);
mFolderRoot->setCallbackRegistrar(&mCommitCallbackRegistrar);
mFolderRoot->setEnableRegistrar(&mEnableCallbackRegistrar);
// Attach root to the scroller
mScroller->addChild(mFolderRoot);
mFolderRoot->setScrollContainer(mScroller);
mFolderRoot->setFollowsAll();
mFolderRoot->setOpen(true);
mScroller->setVisible(true);

gIdleCallbacks.addFunction(idle, this);

return true;
}

void LLFloaterGLTFAssetEditor::onOpen(const LLSD& key)
{
loadFromSelection();
}

void LLFloaterGLTFAssetEditor::idle(void* user_data)
{
LLFloaterGLTFAssetEditor* floater = (LLFloaterGLTFAssetEditor*)user_data;

if (floater->mFolderRoot)
{
floater->mFolderRoot->update();
}
}

void LLFloaterGLTFAssetEditor::loadItem(S32 id, const std::string& name, LLGLTFFolderItem::EType type, LLFolderViewFolder* parent)
{
LLGLTFFolderItem* listener = new LLGLTFFolderItem(id, name, type, mGLTFViewModel);

LLFolderViewItem::Params params;
params.name(name);
params.creation_date(0);
params.root(mFolderRoot);
params.listener(listener);
params.rect(LLRect());
params.tool_tip = params.name;
params.font_color = mUIColor;
params.font_highlight_color = mUIColor;
LLFolderViewItem* view = LLUICtrlFactory::create<LLFolderViewItem>(params);

view->addToFolder(parent);
view->setVisible(true);
}

void LLFloaterGLTFAssetEditor::loadFromNode(S32 node_id, LLFolderViewFolder* parent)
{
if (mAsset->mNodes.size() <= node_id)
{
return;
}

LL::GLTF::Node& node = mAsset->mNodes[node_id];

std::string name = node.mName;
if (node.mName.empty())
{
name = getString("node_tittle");
}
else
{
name = node.mName;
}

LLGLTFFolderItem* listener = new LLGLTFFolderItem(node_id, name, LLGLTFFolderItem::TYPE_NODE, mGLTFViewModel);

LLFolderViewFolder::Params p;
p.root = mFolderRoot;
p.listener = listener;
p.name = name;
p.tool_tip = name;
p.font_color = mUIColor;
p.font_highlight_color = mUIColor;
LLFolderViewFolder* view = LLUICtrlFactory::create<LLFolderViewFolder>(p);

view->addToFolder(parent);
view->setVisible(true);
view->setOpen(true);

for (S32& node_id : node.mChildren)
{
loadFromNode(node_id, view);
}

if (node.mMesh != LL::GLTF::INVALID_INDEX && mAsset->mMeshes.size() > node.mMesh)
{
std::string name = mAsset->mMeshes[node.mMesh].mName;
if (name.empty())
{
name = getString("mesh_tittle");
}
loadItem(node.mMesh, name, LLGLTFFolderItem::TYPE_MESH, view);
}

if (node.mSkin != LL::GLTF::INVALID_INDEX && mAsset->mSkins.size() > node.mSkin)
{
std::string name = mAsset->mSkins[node.mSkin].mName;
if (name.empty())
{
name = getString("skin_tittle");
}
loadItem(node.mSkin, name, LLGLTFFolderItem::TYPE_SKIN, view);
}

view->setChildrenInited(true);
}

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

LLViewerObject* objectp = LLSelectMgr::getInstance()->getSelection()->getFirstObject();
if (!objectp)
{
return;
}

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

LLUIColor item_color = LLUIColorTable::instance().getColor("MenuItemEnabledColor", DEFAULT_WHITE);
for (S32 i = 0; i < mAsset->mScenes.size(); i++)
{
LL::GLTF::Scene& scene = mAsset->mScenes[i];
std::string name = scene.mName;
if (scene.mName.empty())
{
name = getString("scene_tittle");
}
else
{
name = scene.mName;
}

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


LLFolderViewFolder::Params p;
p.name = name;
p.root = mFolderRoot;
p.listener = listener;
p.tool_tip = name;
p.font_color = mUIColor;
p.font_highlight_color = mUIColor;
LLFolderViewFolder* view = LLUICtrlFactory::create<LLFolderViewFolder>(p);

view->addToFolder(mFolderRoot);
view->setVisible(true);
view->setOpen(true);

for (S32& node_id : scene.mNodes)
{
loadFromNode(node_id, view);
}
view->setChildrenInited(true);
}

mGLTFViewModel.requestSortAll();
mFolderRoot->setChildrenInited(true);
mFolderRoot->arrangeAll();
mFolderRoot->update();
}

Loading

0 comments on commit e75595a

Please sign in to comment.