Move parent node attachment out of nifloader

c++11
scrawl 10 years ago
parent ff9e2b03a0
commit 36ad40827b

@ -114,7 +114,7 @@ int main(int argc, char** argv)
osg::Group* newNode = new osg::Group;
NifOsg::Loader loader;
loader.resourceManager = &resourceMgr;
loader.loadAsSkeleton(nif, newNode);
newNode->addChild(loader.loadAsSkeleton(nif));
osg::PositionAttitudeTransform* trans = new osg::PositionAttitudeTransform;
root->addChild(trans);

@ -60,7 +60,7 @@ void CSVRender::Object::update()
Nif::NIFFilePtr file(new Nif::NIFFile(mVFS->get(path), path));
loader.loadAsSkeleton(file, mBaseNode);
mBaseNode->addChild(loader.loadAsSkeleton(file));
//mObject->setVisibilityFlags (Element_Reference);

@ -403,7 +403,7 @@ namespace NifOsg
rootNode->accept(visitor);
}
osg::Node* load(Nif::NIFFilePtr nif, osg::Group *parentNode, TextKeyMap* textKeys)
osg::ref_ptr<osg::Node> load(Nif::NIFFilePtr nif, TextKeyMap* textKeys)
{
if (nif->numRoots() < 1)
nif->fail("Found no root nodes");
@ -414,11 +414,11 @@ namespace NifOsg
if (nifNode == NULL)
nif->fail("First root was not a node, but a " + r->recName);
osg::Node* created = handleNode(nifNode, parentNode, false, std::map<int, int>(), 0, 0, false, textKeys);
osg::Node* created = handleNode(nifNode, false, std::map<int, int>(), 0, 0, false, textKeys);
return created;
}
osg::Node* loadAsSkeleton(Nif::NIFFilePtr nif, osg::Group *parentNode, TextKeyMap* textKeys)
osg::ref_ptr<osg::Node> loadAsSkeleton(Nif::NIFFilePtr nif, TextKeyMap* textKeys)
{
if (nif->numRoots() < 1)
nif->fail("Found no root nodes");
@ -431,9 +431,7 @@ namespace NifOsg
nif->fail("First root was not a node, but a " + r->recName);
osg::ref_ptr<osgAnimation::Skeleton> skel = new osgAnimation::Skeleton;
parentNode->addChild(skel);
handleNode(nifNode, skel, true, std::map<int, int>(), 0, 0, false, textKeys);
skel->addChild(handleNode(nifNode, true, std::map<int, int>(), 0, 0, false, textKeys));
return skel;
}
@ -458,7 +456,7 @@ namespace NifOsg
}
osg::Node* handleNode(const Nif::Node* nifNode, osg::Group* parentNode, bool createSkeleton,
osg::ref_ptr<osg::Node> handleNode(const Nif::Node* nifNode, bool createSkeleton,
std::map<int, int> boundTextures, int animflags, int particleflags, bool skipMeshes, TextKeyMap* textKeys, osg::Node* rootNode=NULL)
{
osg::ref_ptr<osg::MatrixTransform> transformNode;
@ -484,9 +482,6 @@ namespace NifOsg
// Ignoring name for non-bone nodes for now. We might need it later in isolated cases, e.g. AttachLight.
// Insert bones at position 0 to prevent update order problems (see comment in osg Skeleton.cpp)
parentNode->insertChild(0, transformNode);
// UserData used for a variety of features:
// - finding the correct emitter node for a particle system
// - establishing connections to the animated collision shapes, which are handled in a separate loader
@ -567,7 +562,11 @@ namespace NifOsg
for(size_t i = 0;i < children.length();++i)
{
if(!children[i].empty())
handleNode(children[i].getPtr(), transformNode, createSkeleton, boundTextures, animflags, particleflags, skipMeshes, textKeys, rootNode);
{
// Insert bones at position 0 to prevent update order problems (see comment in osg Skeleton.cpp)
transformNode->insertChild(0,
handleNode(children[i].getPtr(), createSkeleton, boundTextures, animflags, particleflags, skipMeshes, textKeys, rootNode));
}
}
}
@ -1328,16 +1327,16 @@ namespace NifOsg
};
osg::Node* Loader::load(Nif::NIFFilePtr file, osg::Group *parentNode, TextKeyMap *textKeys)
osg::ref_ptr<osg::Node> Loader::load(Nif::NIFFilePtr file, TextKeyMap *textKeys)
{
LoaderImpl loader(resourceManager, sShowMarkers);
return loader.load(file, parentNode, textKeys);
return loader.load(file, textKeys);
}
osg::Node* Loader::loadAsSkeleton(Nif::NIFFilePtr file, osg::Group *parentNode, TextKeyMap *textKeys)
osg::ref_ptr<osg::Node> Loader::loadAsSkeleton(Nif::NIFFilePtr file, TextKeyMap *textKeys)
{
LoaderImpl loader(resourceManager, sShowMarkers);
return loader.loadAsSkeleton(file, parentNode, textKeys);
return loader.loadAsSkeleton(file, textKeys);
}
void Loader::loadKf(Nif::NIFFilePtr kf, osg::Node *rootNode, int sourceIndex, TextKeyMap &textKeys)

@ -7,16 +7,15 @@
#include <components/vfs/manager.hpp>
#include <osg/ref_ptr>
namespace osg
{
class Group;
class Node;
}
namespace NifOsg
{
class Controller;
typedef std::multimap<float,std::string> TextKeyMap;
/// The main class responsible for loading NIF files into an OSG-Scenegraph.
@ -27,10 +26,10 @@ namespace NifOsg
// though, when assembling from several files, i.e. equipment parts
/// Create a scene graph for the given NIF. Assumes no skinning is used.
/// @param node The parent of the new root node for the created scene graph.
osg::Node* load(Nif::NIFFilePtr file, osg::Group* parentNode, TextKeyMap* textKeys = NULL);
osg::ref_ptr<osg::Node> load(Nif::NIFFilePtr file, TextKeyMap* textKeys = NULL);
/// Create a scene graph for the given NIF. Assumes skinning will be used.
osg::Node* loadAsSkeleton(Nif::NIFFilePtr file, osg::Group* parentNode, TextKeyMap* textKeys = NULL);
osg::ref_ptr<osg::Node> loadAsSkeleton(Nif::NIFFilePtr file, TextKeyMap* textKeys = NULL);
/// Load keyframe controllers from the given kf file onto the given scene graph.
/// @param sourceIndex The source index for this animation source, used for identifying

Loading…
Cancel
Save