mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-22 00:53:52 +00:00
Return text keys from NIFs when creating entities
This commit is contained in:
parent
44975854e5
commit
36be1536d9
6 changed files with 37 additions and 19 deletions
|
@ -26,7 +26,7 @@ CreatureAnimation::CreatureAnimation(const MWWorld::Ptr& ptr, OEngine::Render::O
|
||||||
{
|
{
|
||||||
std::string mesh = "meshes\\" + ref->base->model;
|
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++)
|
for(size_t i = 0;i < mEntityList.mEntities.size();i++)
|
||||||
{
|
{
|
||||||
Ogre::Entity *ent = mEntityList.mEntities[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");
|
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++)
|
for(size_t i = 0;i < mEntityList.mEntities.size();i++)
|
||||||
{
|
{
|
||||||
Ogre::Entity *base = mEntityList.mEntities[i];
|
Ogre::Entity *base = mEntityList.mEntities[i];
|
||||||
|
|
|
@ -93,7 +93,7 @@ void Objects::insertMesh (const MWWorld::Ptr& ptr, const std::string& mesh)
|
||||||
assert(insert);
|
assert(insert);
|
||||||
|
|
||||||
Ogre::AxisAlignedBox bounds = Ogre::AxisAlignedBox::BOX_NULL;
|
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++)
|
for(size_t i = 0;i < entities.mEntities.size();i++)
|
||||||
{
|
{
|
||||||
const Ogre::AxisAlignedBox &tmp = entities.mEntities[i]->getBoundingBox();
|
const Ogre::AxisAlignedBox &tmp = entities.mEntities[i]->getBoundingBox();
|
||||||
|
|
|
@ -327,7 +327,7 @@ void SkyManager::create()
|
||||||
|
|
||||||
// Stars
|
// Stars
|
||||||
mAtmosphereNight = mRootNode->createChildSceneNode();
|
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++)
|
for(size_t i = 0, matidx = 0;i < entities.mEntities.size();i++)
|
||||||
{
|
{
|
||||||
Entity* night1_ent = entities.mEntities[i];
|
Entity* night1_ent = entities.mEntities[i];
|
||||||
|
@ -352,7 +352,7 @@ void SkyManager::create()
|
||||||
|
|
||||||
// Atmosphere (day)
|
// Atmosphere (day)
|
||||||
mAtmosphereDay = mRootNode->createChildSceneNode();
|
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++)
|
for(size_t i = 0;i < entities.mEntities.size();i++)
|
||||||
{
|
{
|
||||||
Entity* atmosphere_ent = entities.mEntities[i];
|
Entity* atmosphere_ent = entities.mEntities[i];
|
||||||
|
@ -366,7 +366,7 @@ void SkyManager::create()
|
||||||
|
|
||||||
// Clouds
|
// Clouds
|
||||||
SceneNode* clouds_node = mRootNode->createChildSceneNode();
|
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++)
|
for(size_t i = 0;i < entities.mEntities.size();i++)
|
||||||
{
|
{
|
||||||
Entity* clouds_ent = entities.mEntities[i];
|
Entity* clouds_ent = entities.mEntities[i];
|
||||||
|
|
|
@ -342,8 +342,23 @@ void loadResource(Ogre::Resource *resource)
|
||||||
anim->optimise();
|
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)
|
if(node->boneTrafo != NULL)
|
||||||
{
|
{
|
||||||
Ogre::SkeletonManager &skelMgr = Ogre::SkeletonManager::getSingleton();
|
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);
|
skel = skelMgr.create(name, group, true, loader);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!textkeys || textkeys->size() > 0)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Nif::NiNode *ninode = dynamic_cast<Nif::NiNode*>(node);
|
const Nif::NiNode *ninode = dynamic_cast<const Nif::NiNode*>(node);
|
||||||
if(ninode)
|
if(ninode)
|
||||||
{
|
{
|
||||||
Nif::NodeList &children = ninode->children;
|
const Nif::NodeList &children = ninode->children;
|
||||||
for(size_t i = 0;i < children.length();i++)
|
for(size_t i = 0;i < children.length();i++)
|
||||||
{
|
{
|
||||||
if(!children[i].empty())
|
if(!children[i].empty())
|
||||||
{
|
{
|
||||||
if(createSkeleton(name, group, children[i].getPtr()))
|
if(createSkeleton(name, group, textkeys, children[i].getPtr()))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -965,7 +981,7 @@ public:
|
||||||
NIFMeshLoader::LoaderMap NIFMeshLoader::sLoaders;
|
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;
|
MeshPairList meshes;
|
||||||
|
|
||||||
|
@ -992,7 +1008,7 @@ MeshPairList NIFLoader::load(std::string name, std::string skelName, const std::
|
||||||
}
|
}
|
||||||
|
|
||||||
NIFSkeletonLoader skelldr;
|
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()));
|
NIFMeshLoader meshldr(name, group, (hasSkel ? skelName : std::string()));
|
||||||
meshldr.createMeshes(node, meshes);
|
meshldr.createMeshes(node, meshes);
|
||||||
|
@ -1000,11 +1016,11 @@ MeshPairList NIFLoader::load(std::string name, std::string skelName, const std::
|
||||||
return meshes;
|
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;
|
EntityList entitylist;
|
||||||
|
|
||||||
MeshPairList meshes = load(name, name, group);
|
MeshPairList meshes = load(name, name, textkeys, group);
|
||||||
if(meshes.size() == 0)
|
if(meshes.size() == 0)
|
||||||
return entitylist;
|
return entitylist;
|
||||||
|
|
||||||
|
@ -1053,7 +1069,7 @@ EntityList NIFLoader::createEntities(Ogre::Entity *parent, const std::string &bo
|
||||||
{
|
{
|
||||||
EntityList entitylist;
|
EntityList entitylist;
|
||||||
|
|
||||||
MeshPairList meshes = load(name, parent->getMesh()->getSkeletonName(), group);
|
MeshPairList meshes = load(name, parent->getMesh()->getSkeletonName(), NULL, group);
|
||||||
if(meshes.size() == 0)
|
if(meshes.size() == 0)
|
||||||
return entitylist;
|
return entitylist;
|
||||||
|
|
||||||
|
|
|
@ -58,7 +58,8 @@ namespace Nif
|
||||||
namespace NifOgre
|
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 {
|
struct EntityList {
|
||||||
std::vector<Ogre::Entity*> mEntities;
|
std::vector<Ogre::Entity*> mEntities;
|
||||||
Ogre::Entity *mSkelBase;
|
Ogre::Entity *mSkelBase;
|
||||||
|
@ -67,11 +68,11 @@ struct EntityList {
|
||||||
{ }
|
{ }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/** This holds a list of meshes along with the names of their parent nodes
|
/** This holds a list of meshes along with the names of their parent nodes
|
||||||
*/
|
*/
|
||||||
typedef std::vector< std::pair<Ogre::MeshPtr,std::string> > MeshPairList;
|
typedef std::vector< std::pair<Ogre::MeshPtr,std::string> > MeshPairList;
|
||||||
|
|
||||||
|
|
||||||
/** Manual resource loader for NIF meshes. This is the main class
|
/** Manual resource loader for NIF meshes. This is the main class
|
||||||
responsible for translating the internal NIF mesh structure into
|
responsible for translating the internal NIF mesh structure into
|
||||||
something Ogre can use.
|
something Ogre can use.
|
||||||
|
@ -86,7 +87,7 @@ typedef std::vector< std::pair<Ogre::MeshPtr,std::string> > MeshPairList;
|
||||||
*/
|
*/
|
||||||
class NIFLoader
|
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:
|
public:
|
||||||
static EntityList createEntities(Ogre::Entity *parent, const std::string &bonename,
|
static EntityList createEntities(Ogre::Entity *parent, const std::string &bonename,
|
||||||
|
@ -95,6 +96,7 @@ public:
|
||||||
const std::string &group="General");
|
const std::string &group="General");
|
||||||
|
|
||||||
static EntityList createEntities(Ogre::SceneNode *parent,
|
static EntityList createEntities(Ogre::SceneNode *parent,
|
||||||
|
TextKeyMap *textkeys,
|
||||||
const std::string &name,
|
const std::string &name,
|
||||||
const std::string &group="General");
|
const std::string &group="General");
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue