forked from teamnwah/openmw-tes3coop
Create meshes from the NiTriShapes in the NIF.
This doesn't actually load them yet. It's also very slow for certain NIFs.
This commit is contained in:
parent
9caa264074
commit
6a447c88fb
2 changed files with 68 additions and 13 deletions
|
@ -132,13 +132,13 @@ NIFLoader::LoaderMap NIFLoader::sLoaders;
|
||||||
|
|
||||||
void NIFLoader::warn(const std::string &msg)
|
void NIFLoader::warn(const std::string &msg)
|
||||||
{
|
{
|
||||||
std::cerr << "NIFLoader: Warn:" << msg << "\n";
|
std::cerr << "NIFLoader: Warn: " << msg << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NIFLoader::fail(const std::string &msg)
|
void NIFLoader::fail(const std::string &msg)
|
||||||
{
|
{
|
||||||
std::cerr << "NIFLoader: Fail: "<< msg << std::endl;
|
std::cerr << "NIFLoader: Fail: "<< msg << std::endl;
|
||||||
assert(1);
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -325,24 +325,74 @@ void NIFLoader::loadResource(Ogre::Resource *resource)
|
||||||
warn("Found no records in NIF for "+resource->getName());
|
warn("Found no records in NIF for "+resource->getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
MeshPairList NIFLoader::load(const std::string &name, Ogre::SkeletonPtr *skel, const std::string &group)
|
void NIFLoader::createMeshes(const std::string &name, const std::string &group, Nif::Node *node, MeshPairList &meshes, int flags)
|
||||||
|
{
|
||||||
|
flags |= node->flags;
|
||||||
|
|
||||||
|
// TODO: Check for extra data
|
||||||
|
|
||||||
|
if(node->recType == Nif::RC_NiTriShape)
|
||||||
{
|
{
|
||||||
Ogre::MeshManager &meshMgr = Ogre::MeshManager::getSingleton();
|
Ogre::MeshManager &meshMgr = Ogre::MeshManager::getSingleton();
|
||||||
MeshPairList ret;
|
std::string fullname = name+"@"+node->name;
|
||||||
|
|
||||||
|
Ogre::MeshPtr mesh = meshMgr.getByName(fullname);
|
||||||
|
if(mesh.isNull())
|
||||||
|
{
|
||||||
|
NIFLoader *loader = &sLoaders[fullname];
|
||||||
|
loader->mName = name;
|
||||||
|
loader->mShapeName = node->name;
|
||||||
|
|
||||||
|
mesh = meshMgr.createManual(fullname, group, loader);
|
||||||
|
}
|
||||||
|
|
||||||
|
meshes.push_back(std::make_pair(mesh, (node->parent ? node->parent->name : std::string())));
|
||||||
|
}
|
||||||
|
else if(node->recType != Nif::RC_NiNode && node->recType != Nif::RC_RootCollisionNode &&
|
||||||
|
node->recType != Nif::RC_NiRotatingParticles)
|
||||||
|
warn("Unhandled mesh node type: "+node->recName);
|
||||||
|
|
||||||
|
Nif::NiNode *ninode = dynamic_cast<Nif::NiNode*>(node);
|
||||||
|
if(ninode)
|
||||||
|
{
|
||||||
|
Nif::NodeList &children = ninode->children;
|
||||||
|
for(size_t i = 0;i < children.length();i++)
|
||||||
|
{
|
||||||
|
if(!children[i].empty())
|
||||||
|
createMeshes(name, group, children[i].getPtr(), meshes, flags);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MeshPairList NIFLoader::load(const std::string &name, Ogre::SkeletonPtr *skel, const std::string &group)
|
||||||
|
{
|
||||||
|
MeshPairList meshes;
|
||||||
|
|
||||||
if(skel != NULL)
|
if(skel != NULL)
|
||||||
skel->setNull();
|
skel->setNull();
|
||||||
|
|
||||||
// Check if the resource already exists
|
Nif::NIFFile nif(name);
|
||||||
Ogre::MeshPtr themesh = meshMgr.getByName(name, group);
|
if (nif.numRecords() < 1)
|
||||||
if(themesh.isNull())
|
|
||||||
{
|
{
|
||||||
NIFLoader *loader = &sLoaders[name];
|
nif.warn("Found no records in NIF.");
|
||||||
themesh = meshMgr.createManual(name, group, loader);
|
return meshes;
|
||||||
}
|
}
|
||||||
ret.push_back(std::make_pair(themesh, std::string()));
|
|
||||||
|
|
||||||
return ret;
|
// The first record is assumed to be the root node
|
||||||
|
Nif::Record *r = nif.getRecord(0);
|
||||||
|
assert(r != NULL);
|
||||||
|
|
||||||
|
Nif::Node *node = dynamic_cast<Nif::Node*>(r);
|
||||||
|
if(node == NULL)
|
||||||
|
{
|
||||||
|
nif.warn("First record in file was not a node, but a "+
|
||||||
|
r->recName+". Skipping file.");
|
||||||
|
return meshes;
|
||||||
|
}
|
||||||
|
|
||||||
|
createMeshes(name, group, node, meshes);
|
||||||
|
|
||||||
|
return meshes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -96,8 +96,13 @@ public:
|
||||||
const std::string &group="General");
|
const std::string &group="General");
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void warn(const std::string &msg);
|
std::string mName;
|
||||||
void fail(const std::string &msg);
|
std::string mShapeName;
|
||||||
|
|
||||||
|
static void warn(const std::string &msg);
|
||||||
|
static void fail(const std::string &msg);
|
||||||
|
|
||||||
|
static void createMeshes(const std::string &name, const std::string &group, Nif::Node *node, MeshPairList &meshes, int flags=0);
|
||||||
|
|
||||||
typedef std::map<std::string,NIFLoader,ciLessBoost> LoaderMap;
|
typedef std::map<std::string,NIFLoader,ciLessBoost> LoaderMap;
|
||||||
static LoaderMap sLoaders;
|
static LoaderMap sLoaders;
|
||||||
|
|
Loading…
Reference in a new issue