Create mesh entities for objects when loading the NIF

actorid
Chris Robinson 13 years ago
parent c6cc82a51a
commit 3dedac5cb1

@ -93,13 +93,10 @@ void Objects::insertMesh (const MWWorld::Ptr& ptr, const std::string& mesh)
assert(insert);
Ogre::AxisAlignedBox bounds = Ogre::AxisAlignedBox::BOX_NULL;
NifOgre::MeshPairList meshes = NifOgre::NIFLoader::load(mesh);
std::vector<Ogre::Entity*> entities(meshes.size());
for(size_t i = 0;i < meshes.size();i++)
NifOgre::EntityList entities = NifOgre::NIFLoader::createEntities(insert, mesh);
for(size_t i = 0;i < entities.mEntities.size();i++)
{
entities[i] = mRenderer.getScene()->createEntity(meshes[i].first->getName());
const Ogre::AxisAlignedBox &tmp = entities[i]->getBoundingBox();
const Ogre::AxisAlignedBox &tmp = entities.mEntities[i]->getBoundingBox();
bounds.merge(Ogre::AxisAlignedBox(insert->_getDerivedPosition() + tmp.getMinimum(),
insert->_getDerivedPosition() + tmp.getMaximum())
);
@ -119,9 +116,9 @@ void Objects::insertMesh (const MWWorld::Ptr& ptr, const std::string& mesh)
mBounds[ptr.getCell()].merge(bounds);
bool transparent = false;
for(size_t i = 0;i < entities.size();i++)
for(size_t i = 0;i < entities.mEntities.size();i++)
{
Ogre::Entity *ent = entities[i];
Ogre::Entity *ent = entities.mEntities[i];
for (unsigned int i=0; i<ent->getNumSubEntities(); ++i)
{
Ogre::MaterialPtr mat = ent->getSubEntity(i)->getMaterial();
@ -143,10 +140,9 @@ void Objects::insertMesh (const MWWorld::Ptr& ptr, const std::string& mesh)
if(!mIsStatic || !Settings::Manager::getBool("use static geometry", "Objects") || transparent)
{
for(size_t i = 0;i < entities.size();i++)
for(size_t i = 0;i < entities.mEntities.size();i++)
{
Ogre::Entity *ent = entities[i];
insert->attachObject(ent);
Ogre::Entity *ent = entities.mEntities[i];
ent->setRenderingDistance(small ? Settings::Manager::getInt("small object distance", "Viewing distance") : 0);
ent->setVisibilityFlags(mIsStatic ? (small ? RV_StaticsSmall : RV_Statics) : RV_Misc);
@ -197,9 +193,10 @@ void Objects::insertMesh (const MWWorld::Ptr& ptr, const std::string& mesh)
sg->setRenderQueueGroup(transparent ? RQG_Alpha : RQG_Main);
for(size_t i = 0;i < entities.size();i++)
for(size_t i = 0;i < entities.mEntities.size();i++)
{
Ogre::Entity *ent = entities[i];
Ogre::Entity *ent = entities.mEntities[i];
insert->detachObject(ent);
sg->addEntity(ent,insert->_getDerivedPosition(),insert->_getDerivedOrientation(),insert->_getDerivedScale());
mRenderer.getScene()->destroyEntity(ent);

@ -32,6 +32,7 @@
#include <OgreTechnique.h>
#include <OgreSubMesh.h>
#include <OgreRoot.h>
#include <OgreEntity.h>
#include <components/settings/settings.hpp>
#include <components/nifoverrides/nifoverrides.hpp>
@ -871,6 +872,44 @@ MeshPairList NIFLoader::load(const std::string &name, Ogre::SkeletonPtr *skel, c
return meshes;
}
EntityList NIFLoader::createEntities(Ogre::SceneNode *parent, const std::string &name, const std::string &group)
{
EntityList entitylist;
MeshPairList meshes = load(name, NULL, group);
if(meshes.size() == 0)
return entitylist;
Ogre::SceneManager *sceneMgr = parent->getCreator();
for(size_t i = 0;i < meshes.size();i++)
{
entitylist.mEntities.push_back(sceneMgr->createEntity(meshes[i].first->getName()));
Ogre::Entity *entity = entitylist.mEntities.back();
if(!entitylist.mSkelBase && entity->hasSkeleton())
entitylist.mSkelBase = entity;
}
if(entitylist.mSkelBase)
{
parent->attachObject(entitylist.mSkelBase);
for(size_t i = 0;i < entitylist.mEntities.size();i++)
{
Ogre::Entity *entity = entitylist.mEntities[i];
if(entity != entitylist.mSkelBase && entity->hasSkeleton())
entity->shareSkeletonInstanceWith(entitylist.mSkelBase);
else if(entity != entitylist.mSkelBase)
entitylist.mSkelBase->attachObjectToBone(meshes[i].second, entity);
}
}
else
{
for(size_t i = 0;i < entitylist.mEntities.size();i++)
parent->attachObject(entitylist.mEntities[i]);
}
return entitylist;
}
/* More code currently not in use, from the old D source. This was
used in the first attempt at loading NIF meshes, where each submesh

@ -58,6 +58,14 @@ namespace Nif
namespace NifOgre
{
struct EntityList {
std::vector<Ogre::Entity*> mEntities;
Ogre::Entity *mSkelBase;
EntityList() : mSkelBase(0)
{ }
};
/** This holds a list of meshes along with the names of their parent nodes
*/
typedef std::vector< std::pair<Ogre::MeshPtr,std::string> > MeshPairList;
@ -81,6 +89,10 @@ public:
static MeshPairList load(const std::string &name,
Ogre::SkeletonPtr *skel=NULL,
const std::string &group="General");
static EntityList createEntities(Ogre::SceneNode *parent,
const std::string &name,
const std::string &group="General");
};
}

Loading…
Cancel
Save