From 148c041a43788d0d3faf1d7c5bc1bce8fe8d81e8 Mon Sep 17 00:00:00 2001 From: scrawl Date: Wed, 22 Apr 2015 19:16:49 +0200 Subject: [PATCH] Nif loader cleanup - forcing a skeleton is no longer needed --- components/nifosg/nifloader.cpp | 45 ++++++++------------------------- components/nifosg/nifloader.hpp | 6 +---- 2 files changed, 11 insertions(+), 40 deletions(-) diff --git a/components/nifosg/nifloader.cpp b/components/nifosg/nifloader.cpp index f7f6af0ae..63a3ee887 100644 --- a/components/nifosg/nifloader.cpp +++ b/components/nifosg/nifloader.cpp @@ -459,9 +459,6 @@ namespace NifOsg static osg::ref_ptr load(Nif::NIFFilePtr nif, Resource::TextureManager* textureManager) { - if (nif->getUseSkinning()) - return loadAsSkeleton(nif, textureManager); - if (nif->numRoots() < 1) nif->fail("Found no root nodes"); @@ -473,35 +470,19 @@ namespace NifOsg osg::ref_ptr textkeys (new TextKeyMapHolder); - osg::ref_ptr created = handleNode(nifNode, NULL, textureManager, false, std::map(), 0, 0, false, &textkeys->mTextKeys); + osg::ref_ptr created = handleNode(nifNode, NULL, textureManager, std::map(), 0, 0, false, &textkeys->mTextKeys); + if (nif->getUseSkinning()) + { + osg::ref_ptr skel = new SceneUtil::Skeleton; + skel->addChild(created); + created = skel; + } created->getOrCreateUserDataContainer()->addUserObject(textkeys); return created; } - static osg::ref_ptr loadAsSkeleton(Nif::NIFFilePtr nif, Resource::TextureManager* textureManager) - { - if (nif->numRoots() < 1) - nif->fail("Found no root nodes"); - - const Nif::Record* r = nif->getRoot(0); - assert(r != NULL); - - const Nif::Node* nifNode = dynamic_cast(r); - if (nifNode == NULL) - nif->fail("First root was not a node, but a " + r->recName); - - osg::ref_ptr textkeys (new TextKeyMapHolder); - - osg::ref_ptr skel = new SceneUtil::Skeleton; - handleNode(nifNode, skel, textureManager, true, std::map(), 0, 0, false, &textkeys->mTextKeys); - - skel->getOrCreateUserDataContainer()->addUserObject(textkeys); - - return skel; - } - static void applyNodeProperties(const Nif::Node *nifNode, osg::Node *applyTo, SceneUtil::CompositeStateSetUpdater* composite, Resource::TextureManager* textureManager, std::map& boundTextures, int animflags) { const Nif::PropertyList& props = nifNode->props; @@ -521,7 +502,7 @@ namespace NifOsg toSetup->mFunction = boost::shared_ptr(new ControllerFunction(ctrl)); } - static osg::ref_ptr handleNode(const Nif::Node* nifNode, osg::Group* parentNode, Resource::TextureManager* textureManager, bool createSkeleton, + static osg::ref_ptr handleNode(const Nif::Node* nifNode, osg::Group* parentNode, Resource::TextureManager* textureManager, std::map boundTextures, int animflags, int particleflags, bool skipMeshes, TextKeyMap* textKeys, osg::Node* rootNode=NULL) { osg::ref_ptr transformNode = new osg::MatrixTransform(toMatrix(nifNode->trafo)); @@ -604,7 +585,7 @@ namespace NifOsg if (nifNode->recType == Nif::RC_NiTriShape && !skipMeshes) { const Nif::NiTriShape* triShape = static_cast(nifNode); - if (!createSkeleton || triShape->skin.empty()) + if (triShape->skin.empty()) handleTriShape(triShape, transformNode, boundTextures, animflags); else handleSkinnedTriShape(triShape, transformNode, boundTextures, animflags); @@ -630,8 +611,7 @@ namespace NifOsg { if(!children[i].empty()) { - handleNode(children[i].getPtr(), transformNode, textureManager, - createSkeleton, boundTextures, animflags, particleflags, skipMeshes, textKeys, rootNode); + handleNode(children[i].getPtr(), transformNode, textureManager, boundTextures, animflags, particleflags, skipMeshes, textKeys, rootNode); } } } @@ -1451,11 +1431,6 @@ namespace NifOsg return LoaderImpl::load(file, textureManager); } - osg::ref_ptr Loader::loadAsSkeleton(Nif::NIFFilePtr file, Resource::TextureManager* textureManager) - { - return LoaderImpl::loadAsSkeleton(file, textureManager); - } - void Loader::loadKf(Nif::NIFFilePtr kf, KeyframeHolder& target) { LoaderImpl::loadKf(kf, target); diff --git a/components/nifosg/nifloader.hpp b/components/nifosg/nifloader.hpp index d1437ff2a..678b8cc64 100644 --- a/components/nifosg/nifloader.hpp +++ b/components/nifosg/nifloader.hpp @@ -53,13 +53,9 @@ namespace NifOsg class Loader { public: - /// Create a scene graph for the given NIF. Auto-detects when skinning is used and calls loadAsSkeleton instead. - /// @param node The parent of the new root node for the created scene graph. + /// Create a scene graph for the given NIF. Auto-detects when skinning is used and wraps the graph in a Skeleton if so. static osg::ref_ptr load(Nif::NIFFilePtr file, Resource::TextureManager* textureManager); - /// Create a scene graph for the given NIF. Always creates a skeleton so that rigs can be attached on the created scene. - static osg::ref_ptr loadAsSkeleton(Nif::NIFFilePtr file, Resource::TextureManager* textureManager); - /// Load keyframe controllers from the given kf file. static void loadKf(Nif::NIFFilePtr kf, KeyframeHolder& target);