diff --git a/apps/nifosgtest/test.cpp b/apps/nifosgtest/test.cpp index c21f423bf..0da95d13d 100644 --- a/apps/nifosgtest/test.cpp +++ b/apps/nifosgtest/test.cpp @@ -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); diff --git a/apps/opencs/view/render/object.cpp b/apps/opencs/view/render/object.cpp index f21e8dd4d..f48fcc440 100644 --- a/apps/opencs/view/render/object.cpp +++ b/apps/opencs/view/render/object.cpp @@ -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); diff --git a/components/nifosg/nifloader.cpp b/components/nifosg/nifloader.cpp index c00b4abe1..60e94c67a 100644 --- a/components/nifosg/nifloader.cpp +++ b/components/nifosg/nifloader.cpp @@ -403,7 +403,7 @@ namespace NifOsg rootNode->accept(visitor); } - osg::Node* load(Nif::NIFFilePtr nif, osg::Group *parentNode, TextKeyMap* textKeys) + osg::ref_ptr 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(), 0, 0, false, textKeys); + osg::Node* created = handleNode(nifNode, false, std::map(), 0, 0, false, textKeys); return created; } - osg::Node* loadAsSkeleton(Nif::NIFFilePtr nif, osg::Group *parentNode, TextKeyMap* textKeys) + osg::ref_ptr 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 skel = new osgAnimation::Skeleton; - parentNode->addChild(skel); - - handleNode(nifNode, skel, true, std::map(), 0, 0, false, textKeys); + skel->addChild(handleNode(nifNode, true, std::map(), 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 handleNode(const Nif::Node* nifNode, bool createSkeleton, std::map boundTextures, int animflags, int particleflags, bool skipMeshes, TextKeyMap* textKeys, osg::Node* rootNode=NULL) { osg::ref_ptr 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 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 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) diff --git a/components/nifosg/nifloader.hpp b/components/nifosg/nifloader.hpp index 7ccbbfd2c..d38b88f97 100644 --- a/components/nifosg/nifloader.hpp +++ b/components/nifosg/nifloader.hpp @@ -7,16 +7,15 @@ #include +#include + namespace osg { - class Group; class Node; } namespace NifOsg { - class Controller; - typedef std::multimap 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 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 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