Add skinning auto-detection in nifosg loader

pull/638/head
scrawl 10 years ago
parent 60ede8dede
commit 46cbec9a4a

@ -117,7 +117,7 @@ int main(int argc, char** argv)
osg::Group* newNode = new osg::Group;
NifOsg::Loader loader;
loader.resourceManager = &resourceMgr;
newNode->addChild(loader.loadAsSkeleton(nif));
newNode->addChild(loader.load(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));
mBaseNode->addChild(loader.loadAsSkeleton(file));
mBaseNode->addChild(loader.load(file));
//mObject->setVisibilityFlags (Element_Reference);

@ -12,6 +12,7 @@ NIFFile::NIFFile(Files::IStreamPtr stream, const std::string &name)
: ver(0)
, filename(name)
, mStream(stream)
, mUseSkinning(false)
{
parse();
}
@ -208,4 +209,14 @@ void NIFFile::parse()
records[i]->post(this);
}
void NIFFile::setUseSkinning(bool skinning)
{
mUseSkinning = skinning;
}
bool NIFFile::getUseSkinning() const
{
return mUseSkinning;
}
}

@ -32,6 +32,8 @@ class NIFFile
/// Root list. This is a select portion of the pointers from records
std::vector<Record*> roots;
bool mUseSkinning;
/// Parse the file
void parse();
@ -83,6 +85,12 @@ public:
/// Number of roots
size_t numRoots() const { return roots.size(); }
/// Set whether there is skinning contained in this NIF file.
/// @note This is just a hint for users of the NIF file and has no effect on the loading procedure.
void setUseSkinning(bool skinning);
bool getUseSkinning() const;
/// Get the name of the file
std::string getFilename(){ return filename; }
};

@ -166,6 +166,8 @@ struct NiTriShape : Node
Node::post(nif);
data.post(nif);
skin.post(nif);
if (!skin.empty())
nif->setUseSkinning(true);
}
};

@ -297,7 +297,7 @@ namespace
void apply(osg::Node &node)
{
std::map<std::string, const Nif::NiKeyframeController*>::const_iterator found = mMap.find(node.getName());
if (found != mMap.end())
if (node.asTransform() && found != mMap.end())
{
const Nif::NiKeyframeController* keyframectrl = found->second;
@ -439,6 +439,9 @@ namespace NifOsg
osg::ref_ptr<osg::Node> load(Nif::NIFFilePtr nif, TextKeyMap* textKeys)
{
if (nif->getUseSkinning())
return loadAsSkeleton(nif, textKeys);
if (nif->numRoots() < 1)
nif->fail("Found no root nodes");

@ -24,13 +24,11 @@ namespace NifOsg
class Loader
{
public:
// TODO: add auto-detection for skinning. We will still need a "force skeleton" parameter
// though, when assembling from several files, i.e. equipment parts
/// Create a scene graph for the given NIF. Assumes no skinning is used.
/// 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.
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.
/// Create a scene graph for the given NIF. Always creates a skeleton so that rigs can be attached on the created scene.
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.

Loading…
Cancel
Save