Skip to content

Commit

Permalink
Create loadMainScene method and modify getFirstSceneNode.
Browse files Browse the repository at this point in the history
  • Loading branch information
xissburg committed Jul 5, 2019
1 parent a06af65 commit 3e54a7f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 19 deletions.
15 changes: 15 additions & 0 deletions Samples/LoadMesh/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,21 @@ int main()
{
auto adapter = gltf->loadFromFileSystem("../Media/damagedHelmet/damagedHelmet.gltf");
objectNode = adapter.getFirstSceneNode(smgr);

// On a scene with multiple root objects `loadMainScene` can be used to load all objects.
/*
auto root = smgr->getRootSceneNode();
adapter.loadMainScene(root, smgr);
auto childIt = root->getChildIterator();
while(childIt.hasMoreElements())
{
auto child = childIt.getNext();
if(child->getName() == "UnityGlTF_root")
{
objectNode = static_cast<Ogre::SceneNode*>(child);
break;
}
}*/
}
catch(std::exception& e)
{
Expand Down
2 changes: 2 additions & 0 deletions include/Ogre_glTF.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ namespace Ogre_glTF
///Return the number of datablock stored
size_t getDatablockCount();

void loadMainScene(Ogre::SceneNode* parentNode, Ogre::SceneManager* smgr) const;

///Construct an item for this object
/// \param smgr pointer to the scene manager where we are creating the item
Ogre::SceneNode* getFirstSceneNode(Ogre::SceneManager* smgr) const;
Expand Down
37 changes: 18 additions & 19 deletions src/Ogre_glTF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,29 +57,28 @@ loaderAdapter::loaderAdapter() : pimpl { std::make_unique<impl>() } { OgreLog("C

loaderAdapter::~loaderAdapter() { OgreLog("Destructed adapter object..."); }

Ogre::SceneNode* loaderAdapter::getFirstSceneNode(Ogre::SceneManager* smgr) const
void loaderAdapter::loadMainScene(Ogre::SceneNode* parentNode, Ogre::SceneManager* smgr) const
{
if(isOk())
{
pimpl->textureImp.loadTextures();
if(!isOk())
return;

// Find a node which is not a child of another node
std::vector<int> allChildren;
for(const auto& node : pimpl->model.nodes)
{
allChildren.insert(allChildren.end(), node.children.begin(), node.children.end());
}
// Find a node index that is not preset in the allChildren array and build
// the hierarchy from there.
for(size_t i = 0; i < pimpl->model.nodes.size(); ++i)
{
if(std::find(allChildren.begin(), allChildren.end(), i) == allChildren.end()) {
return getSceneNode(i, smgr->getRootSceneNode(), smgr);
}
}
pimpl->textureImp.loadTextures();
auto sceneIdx = pimpl->model.defaultScene >= 0 ? pimpl->model.defaultScene : 0;
const auto& scene = pimpl->model.scenes[sceneIdx];

for(auto nodeIdx : scene.nodes)
{
getSceneNode(nodeIdx, parentNode, smgr);
}
}

return nullptr;
Ogre::SceneNode* loaderAdapter::getFirstSceneNode(Ogre::SceneManager* smgr) const
{
if(!isOk())
return nullptr;

pimpl->textureImp.loadTextures();
return getSceneNode(pimpl->model.scenes[0].nodes[0], smgr->getRootSceneNode(), smgr);
}

Ogre::SceneNode* loaderAdapter::getSceneNode(size_t index, Ogre::SceneNode* parentSceneNode, Ogre::SceneManager* smgr) const
Expand Down

0 comments on commit 3e54a7f

Please sign in to comment.