Return text keys from NIFs when creating entities

actorid
Chris Robinson 13 years ago
parent 44975854e5
commit 36be1536d9

@ -26,7 +26,7 @@ CreatureAnimation::CreatureAnimation(const MWWorld::Ptr& ptr, OEngine::Render::O
{
std::string mesh = "meshes\\" + ref->base->model;
mEntityList = NifOgre::NIFLoader::createEntities(mInsert, mesh);
mEntityList = NifOgre::NIFLoader::createEntities(mInsert, NULL, mesh);
for(size_t i = 0;i < mEntityList.mEntities.size();i++)
{
Ogre::Entity *ent = mEntityList.mEntities[i];

@ -89,7 +89,7 @@ NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, OEngine::Render::OgreRendere
std::string smodel = (!isBeast ? "meshes\\base_anim.nif" : "meshes\\base_animkna.nif");
mEntityList = NifOgre::NIFLoader::createEntities(mInsert, smodel);
mEntityList = NifOgre::NIFLoader::createEntities(mInsert, NULL, smodel);
for(size_t i = 0;i < mEntityList.mEntities.size();i++)
{
Ogre::Entity *base = mEntityList.mEntities[i];

@ -93,7 +93,7 @@ void Objects::insertMesh (const MWWorld::Ptr& ptr, const std::string& mesh)
assert(insert);
Ogre::AxisAlignedBox bounds = Ogre::AxisAlignedBox::BOX_NULL;
NifOgre::EntityList entities = NifOgre::NIFLoader::createEntities(insert, mesh);
NifOgre::EntityList entities = NifOgre::NIFLoader::createEntities(insert, NULL, mesh);
for(size_t i = 0;i < entities.mEntities.size();i++)
{
const Ogre::AxisAlignedBox &tmp = entities.mEntities[i]->getBoundingBox();

@ -327,7 +327,7 @@ void SkyManager::create()
// Stars
mAtmosphereNight = mRootNode->createChildSceneNode();
NifOgre::EntityList entities = NifOgre::NIFLoader::createEntities(mAtmosphereNight, "meshes\\sky_night_01.nif");
NifOgre::EntityList entities = NifOgre::NIFLoader::createEntities(mAtmosphereNight, NULL, "meshes\\sky_night_01.nif");
for(size_t i = 0, matidx = 0;i < entities.mEntities.size();i++)
{
Entity* night1_ent = entities.mEntities[i];
@ -352,7 +352,7 @@ void SkyManager::create()
// Atmosphere (day)
mAtmosphereDay = mRootNode->createChildSceneNode();
entities = NifOgre::NIFLoader::createEntities(mAtmosphereDay, "meshes\\sky_atmosphere.nif");
entities = NifOgre::NIFLoader::createEntities(mAtmosphereDay, NULL, "meshes\\sky_atmosphere.nif");
for(size_t i = 0;i < entities.mEntities.size();i++)
{
Entity* atmosphere_ent = entities.mEntities[i];
@ -366,7 +366,7 @@ void SkyManager::create()
// Clouds
SceneNode* clouds_node = mRootNode->createChildSceneNode();
entities = NifOgre::NIFLoader::createEntities(clouds_node, "meshes\\sky_clouds_01.nif");
entities = NifOgre::NIFLoader::createEntities(clouds_node, NULL, "meshes\\sky_clouds_01.nif");
for(size_t i = 0;i < entities.mEntities.size();i++)
{
Entity* clouds_ent = entities.mEntities[i];

@ -342,8 +342,23 @@ void loadResource(Ogre::Resource *resource)
anim->optimise();
}
bool createSkeleton(const std::string &name, const std::string &group, Nif::Node *node)
bool createSkeleton(const std::string &name, const std::string &group, TextKeyMap *textkeys, const Nif::Node *node)
{
if(textkeys)
{
Nif::ExtraPtr e = node->extra;
while(!e.empty())
{
if(e->recType == Nif::RC_NiTextKeyExtraData)
{
const Nif::NiTextKeyExtraData *tk = static_cast<const Nif::NiTextKeyExtraData*>(e.getPtr());
for(size_t i = 0;i < tk->list.size();i++)
(*textkeys)[tk->list[i].time] = tk->list[i].text;
}
e = e->extra;
}
}
if(node->boneTrafo != NULL)
{
Ogre::SkeletonManager &skelMgr = Ogre::SkeletonManager::getSingleton();
@ -355,18 +370,19 @@ bool createSkeleton(const std::string &name, const std::string &group, Nif::Node
skel = skelMgr.create(name, group, true, loader);
}
return true;
if(!textkeys || textkeys->size() > 0)
return true;
}
Nif::NiNode *ninode = dynamic_cast<Nif::NiNode*>(node);
const Nif::NiNode *ninode = dynamic_cast<const Nif::NiNode*>(node);
if(ninode)
{
Nif::NodeList &children = ninode->children;
const Nif::NodeList &children = ninode->children;
for(size_t i = 0;i < children.length();i++)
{
if(!children[i].empty())
{
if(createSkeleton(name, group, children[i].getPtr()))
if(createSkeleton(name, group, textkeys, children[i].getPtr()))
return true;
}
}
@ -965,7 +981,7 @@ public:
NIFMeshLoader::LoaderMap NIFMeshLoader::sLoaders;
MeshPairList NIFLoader::load(std::string name, std::string skelName, const std::string &group)
MeshPairList NIFLoader::load(std::string name, std::string skelName, TextKeyMap *textkeys, const std::string &group)
{
MeshPairList meshes;
@ -992,7 +1008,7 @@ MeshPairList NIFLoader::load(std::string name, std::string skelName, const std::
}
NIFSkeletonLoader skelldr;
bool hasSkel = skelldr.createSkeleton(skelName, group, node);
bool hasSkel = skelldr.createSkeleton(skelName, group, textkeys, node);
NIFMeshLoader meshldr(name, group, (hasSkel ? skelName : std::string()));
meshldr.createMeshes(node, meshes);
@ -1000,11 +1016,11 @@ MeshPairList NIFLoader::load(std::string name, std::string skelName, const std::
return meshes;
}
EntityList NIFLoader::createEntities(Ogre::SceneNode *parent, const std::string &name, const std::string &group)
EntityList NIFLoader::createEntities(Ogre::SceneNode *parent, TextKeyMap *textkeys, const std::string &name, const std::string &group)
{
EntityList entitylist;
MeshPairList meshes = load(name, name, group);
MeshPairList meshes = load(name, name, textkeys, group);
if(meshes.size() == 0)
return entitylist;
@ -1053,7 +1069,7 @@ EntityList NIFLoader::createEntities(Ogre::Entity *parent, const std::string &bo
{
EntityList entitylist;
MeshPairList meshes = load(name, parent->getMesh()->getSkeletonName(), group);
MeshPairList meshes = load(name, parent->getMesh()->getSkeletonName(), NULL, group);
if(meshes.size() == 0)
return entitylist;

@ -58,7 +58,8 @@ namespace Nif
namespace NifOgre
{
// FIXME: This should not be in NifOgre, it works agnostic of what model format is used
// FIXME: These should not be in NifOgre, it works agnostic of what model format is used
typedef std::map<float,std::string> TextKeyMap;
struct EntityList {
std::vector<Ogre::Entity*> mEntities;
Ogre::Entity *mSkelBase;
@ -67,11 +68,11 @@ struct EntityList {
{ }
};
/** This holds a list of meshes along with the names of their parent nodes
*/
typedef std::vector< std::pair<Ogre::MeshPtr,std::string> > MeshPairList;
/** Manual resource loader for NIF meshes. This is the main class
responsible for translating the internal NIF mesh structure into
something Ogre can use.
@ -86,7 +87,7 @@ typedef std::vector< std::pair<Ogre::MeshPtr,std::string> > MeshPairList;
*/
class NIFLoader
{
static MeshPairList load(std::string name, std::string skelName, const std::string &group);
static MeshPairList load(std::string name, std::string skelName, TextKeyMap *textkeys, const std::string &group);
public:
static EntityList createEntities(Ogre::Entity *parent, const std::string &bonename,
@ -95,6 +96,7 @@ public:
const std::string &group="General");
static EntityList createEntities(Ogre::SceneNode *parent,
TextKeyMap *textkeys,
const std::string &name,
const std::string &group="General");
};

Loading…
Cancel
Save