Unique Identifiers for Creatures and NPC Free Parts

actorid
Jason Hooks 13 years ago
parent 93a4060346
commit 6d10c76b06

@ -1,6 +1,6 @@
#include "actors.hpp" #include "actors.hpp"
#include <OgreSceneNode.h> #include <OgreSceneNode.h>
#include <components/nifogre/ogre_nif_loader.hpp>

@ -1,9 +1,30 @@
#include "animation.hpp" #include "animation.hpp"
namespace MWRender{ namespace MWRender{
std::map<std::string, int> Animation::mUniqueIDs;
Animation::~Animation(){ Animation::~Animation(){
base = 0; base = 0;
} }
std::string Animation::getUniqueID(std::string mesh){
int counter;
if(mUniqueIDs.find(mesh) == mUniqueIDs.end()){
counter = mUniqueIDs[mesh] = 0;
}
else
counter = mUniqueIDs[mesh]++;
std::stringstream out;
if(counter > 99 && counter < 1000)
out << "0";
else if(counter > 9)
out << "00";
else
out << "000";
out << counter;
return out.str();
}
void Animation::handleShapes(std::vector<Nif::NiTriShapeCopy>* allshapes, Ogre::Entity* creaturemodel, Ogre::SkeletonInstance *skel){ void Animation::handleShapes(std::vector<Nif::NiTriShapeCopy>* allshapes, Ogre::Entity* creaturemodel, Ogre::SkeletonInstance *skel){
shapeNumber = 0; shapeNumber = 0;
std::vector<Nif::NiTriShapeCopy>::iterator allshapesiter; std::vector<Nif::NiTriShapeCopy>::iterator allshapesiter;

@ -7,13 +7,17 @@
#include "../mwworld/actiontalk.hpp" #include "../mwworld/actiontalk.hpp"
#include "../mwworld/environment.hpp" #include "../mwworld/environment.hpp"
#include <components/nif/node.hpp> #include <components/nif/node.hpp>
#include <map>
namespace MWRender{ namespace MWRender{
class Animation{ class Animation{
protected: protected:
OEngine::Render::OgreRenderer &mRend; OEngine::Render::OgreRenderer &mRend;
MWWorld::Environment& mEnvironment; MWWorld::Environment& mEnvironment;
static std::map<std::string, int> mUniqueIDs;
float time; float time;
float startTime; float startTime;
@ -36,9 +40,12 @@ class Animation{
std::map<std::string,float> textmappings; std::map<std::string,float> textmappings;
Ogre::Entity* base; Ogre::Entity* base;
void handleShapes(std::vector<Nif::NiTriShapeCopy>* allshapes, Ogre::Entity* creaturemodel, Ogre::SkeletonInstance *skel); void handleShapes(std::vector<Nif::NiTriShapeCopy>* allshapes, Ogre::Entity* creaturemodel, Ogre::SkeletonInstance *skel);
bool timeIndex( float time, std::vector<float> times, int & i, int & j, float & x );
std::string getUniqueID(std::string mesh);
public: public:
Animation(MWWorld::Environment& _env, OEngine::Render::OgreRenderer& _rend): mRend(_rend), mEnvironment(_env){}; Animation(MWWorld::Environment& _env, OEngine::Render::OgreRenderer& _rend): mRend(_rend), mEnvironment(_env){};
bool timeIndex( float time, std::vector<float> times, int & i, int & j, float & x );
~Animation(); ~Animation();
}; };

@ -18,11 +18,12 @@ CreatureAnimation::CreatureAnimation(const MWWorld::Ptr& ptr, MWWorld::Environme
assert (ref->base != NULL); assert (ref->base != NULL);
if(!ref->base->model.empty()){ if(!ref->base->model.empty()){
const std::string &mesh = "meshes\\" + ref->base->model; const std::string &mesh = "meshes\\" + ref->base->model;
std::string meshNumbered = mesh + getUniqueID(mesh) + ">|";
NifOgre::NIFLoader::load(meshNumbered);
base = mRend.getScene()->createEntity(meshNumbered);
std::string meshZero = mesh + "0000>|";
NifOgre::NIFLoader::load(mesh); if(transformations = (NIFLoader::getSingletonPtr())->getAnim(meshZero)){
base = mRend.getScene()->createEntity(mesh);
if(transformations = (NIFLoader::getSingletonPtr())->getAnim(mesh)){
for(int init = 0; init < transformations->size(); init++){ for(int init = 0; init < transformations->size(); init++){
rindexI.push_back(0); rindexI.push_back(0);

@ -173,23 +173,25 @@ NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, MWWorld::Environment& _env,O
insertBoundedPart("meshes\\" + hair->model, "Head"); insertBoundedPart("meshes\\" + hair->model, "Head");
if (chest){ if (chest){
insertFreePart("meshes\\" + chest->model + "|\"", insert); insertFreePart("meshes\\" + chest->model, ">\"", insert);
} }
if (handr){ if (handr){
insertFreePart("meshes\\" + handr->model + "|?", insert); insertFreePart("meshes\\" + handr->model , ">?", insert);
} }
if (handl){ if (handl){
insertFreePart("meshes\\" + handl->model + "|>", insert); insertFreePart("meshes\\" + handl->model, ">>", insert);
} }
if(tail){ if(tail){
insertFreePart("meshes\\" + tail->model + "|*", insert); insertFreePart("meshes\\" + tail->model, ">*", insert);
} }
if(feet){ if(feet){
insertFreePart("meshes\\" + feet->model + "|<", insert); std::string num = getUniqueID(feet->model);
insertFreePart("meshes\\" + feet->model + "|:", insert); insertFreePart("meshes\\" + feet->model,"><", insert);
insertFreePart("meshes\\" + feet->model,">:", insert);
} }
} }
@ -200,12 +202,14 @@ Ogre::Entity* NpcAnimation::insertBoundedPart(const std::string &mesh, std::stri
base->attachObjectToBone(bonename, ent); base->attachObjectToBone(bonename, ent);
return ent; return ent;
} }
void NpcAnimation::insertFreePart(const std::string &mesh, Ogre::SceneNode* insert){ void NpcAnimation::insertFreePart(const std::string &mesh, const std::string suffix, Ogre::SceneNode* insert){
NIFLoader::load(mesh); std::string meshNumbered = mesh + getUniqueID(mesh + suffix) + suffix;
Entity* ent = mRend.getScene()->createEntity(mesh); NIFLoader::load(meshNumbered);
Entity* ent = mRend.getScene()->createEntity(meshNumbered);
insert->attachObject(ent); insert->attachObject(ent);
entityparts.push_back(ent); entityparts.push_back(ent);
std::vector<Nif::NiTriShapeCopy>* shapes = ((NIFLoader::getSingletonPtr())->getShapes(mesh)); std::vector<Nif::NiTriShapeCopy>* shapes = ((NIFLoader::getSingletonPtr())->getShapes(mesh + "0000" + suffix));
if(shapes){ if(shapes){
shapeparts.push_back(shapes); shapeparts.push_back(shapes);
handleShapes(shapes, ent, skel); handleShapes(shapes, ent, skel);

@ -22,7 +22,7 @@ class NpcAnimation: public Animation{
NpcAnimation(const MWWorld::Ptr& ptr, MWWorld::Environment& _env, OEngine::Render::OgreRenderer& _rend); NpcAnimation(const MWWorld::Ptr& ptr, MWWorld::Environment& _env, OEngine::Render::OgreRenderer& _rend);
~NpcAnimation(); ~NpcAnimation();
Ogre::Entity* insertBoundedPart(const std::string &mesh, std::string bonename); Ogre::Entity* insertBoundedPart(const std::string &mesh, std::string bonename);
void insertFreePart(const std::string &mesh, Ogre::SceneNode* insert); void insertFreePart(const std::string &mesh, const std::string suffix, Ogre::SceneNode* insert);
}; };
} }
#endif #endif

@ -1150,7 +1150,7 @@ void NIFLoader::loadResource(Resource *resource)
else if(suffix == '>') else if(suffix == '>')
{ {
baddin = true; baddin = true;
bNiTri = false; bNiTri = true;
std::string sub = name.substr(name.length() - 6, 4); std::string sub = name.substr(name.length() - 6, 4);
if(sub.compare("0000") != 0) if(sub.compare("0000") != 0)

@ -44,8 +44,7 @@
#include <vector> #include <vector>
#include <list> #include <list>
// For warning messages // For warning messages
#include <iostream> #include <iostream>5
// float infinity // float infinity
#include <limits> #include <limits>
using namespace boost::algorithm; using namespace boost::algorithm;

Loading…
Cancel
Save