diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index acb0a5a351..2b98a3d604 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -38,18 +38,17 @@ namespace MWClass void Npc::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const { - + ESMS::LiveCellRef *ref = ptr.get(); - const std::string &model = ref->base->model; assert (ref->base != NULL); std::string headID = ref->base->head; std::string bodyRaceID = headID.substr(0, headID.find_last_of("head_") - 4); bool beast = bodyRaceID == "b_n_khajiit_m_" || bodyRaceID == "b_n_khajiit_f_" || bodyRaceID == "b_n_argonian_m_" || bodyRaceID == "b_n_argonian_f_"; - + std::string smodel = "meshes\\base_anim.nif"; if(beast) smodel = "meshes\\base_animkna.nif"; diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index 3bd160e6da..5a9731d2d1 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -18,7 +18,7 @@ namespace MWRender{ mUniqueIDs[copy] = mUniqueIDs[copy] + 1; counter = mUniqueIDs[copy]; } - + std::stringstream out; if(counter > 99 && counter < 1000) out << "0"; @@ -38,7 +38,7 @@ namespace MWRender{ time = startTime; } else if(textmappings){ - + std::string startName = groupname + ": loop start"; std::string stopName = groupname + ": loop stop"; @@ -49,7 +49,7 @@ namespace MWRender{ stopName = groupname + ": loop stop"; for(std::map::iterator iter = textmappings->begin(); iter != textmappings->end(); iter++){ - + std::string current = iter->first.substr(0, startName.size()); std::transform(current.begin(), current.end(), current.begin(), ::tolower); std::string current2 = iter->first.substr(0, stopName.size()); @@ -71,9 +71,9 @@ namespace MWRender{ if(!first){ startName = groupname + ": start"; stopName = groupname + ": stop"; - + for(std::map::iterator iter = textmappings->begin(); iter != textmappings->end(); iter++){ - + std::string current = iter->first.substr(0, startName.size()); std::transform(current.begin(), current.end(), current.begin(), ::tolower); std::string current2 = iter->first.substr(0, stopName.size()); @@ -92,9 +92,9 @@ namespace MWRender{ } } } - + } - + } void Animation::stopScript(){ animate = 0; @@ -103,24 +103,21 @@ namespace MWRender{ void Animation::handleShapes(std::vector* allshapes, Ogre::Entity* creaturemodel, Ogre::SkeletonInstance *skel){ bool useHandles = skel == creaturemodel->getSkeleton(); shapeNumber = 0; - + std::vector::iterator allshapesiter; for(allshapesiter = allshapes->begin(); allshapesiter != allshapes->end(); allshapesiter++) - + { //std::map vecPosRot; - + Nif::NiTriShapeCopy& copy = *allshapesiter; std::vector* allvertices = ©.vertices; - std::vector* allnormals = ©.normals; - - //std::set vertices; //std::set normals; //std::vector boneinfovector = copy.boneinfo; - std::map>* verticesToChange = ©.vertsToWeights; - + std::map >* verticesToChange = ©.vertsToWeights; + //std::cout << "Name " << copy.sname << "\n"; Ogre::HardwareVertexBufferSharedPtr vbuf = creaturemodel->getMesh()->getSubMesh(copy.sname)->vertexData->vertexBufferBinding->getBuffer(0); Ogre::Real* pReal = static_cast(vbuf->lock(Ogre::HardwareBuffer::HBL_NORMAL)); @@ -135,7 +132,7 @@ namespace MWRender{ if(copy.vertices.size() == initialVertices.size()) { //Create if it doesn't already exist - if(shapeIndexI.size() == shapeNumber) + if(shapeIndexI.size() == static_cast (shapeNumber)) { std::vector vec; shapeIndexI.push_back(vec); @@ -165,10 +162,10 @@ namespace MWRender{ } - + } - + allvertices = &initialVertices; } shapeNumber++; @@ -177,8 +174,8 @@ namespace MWRender{ if(verticesToChange->size() > 0){ - - for(std::map>::iterator iter = verticesToChange->begin(); + + for(std::map >::iterator iter = verticesToChange->begin(); iter != verticesToChange->end(); iter++) { std::vector inds = iter->second; @@ -192,15 +189,15 @@ namespace MWRender{ } else bonePtr = skel->getBone(boneinfocopy->bonename); - + Ogre::Vector3 vecPos = bonePtr->_getDerivedPosition() + bonePtr->_getDerivedOrientation() * boneinfocopy->trafo.trans; Ogre::Quaternion vecRot = bonePtr->_getDerivedOrientation() * boneinfocopy->trafo.rotation; - - + + /*if(vecPosRot.find(boneinfocopy->bonehandle) == vecPosRot.end()){ vecPos = bonePtr->_getDerivedPosition() + bonePtr->_getDerivedOrientation() * boneinfocopy->trafo.trans; vecRot = bonePtr->_getDerivedOrientation() * boneinfocopy->trafo.rotation; - + if(useHandles){ PosAndRot both; both.vecPos = vecPos; @@ -215,9 +212,9 @@ namespace MWRender{ }*/ Ogre::Vector3 absVertPos = (vecPos + vecRot * currentVertex) * inds[0].weight; - - for(int i = 1; i < inds.size(); i++){ + + for(std::size_t i = 1; i < inds.size(); i++){ boneinfocopy = &(allshapesiter->boneinfo[inds[i].boneinfocopyindex]); if(useHandles) bonePtr = skel->getBone(boneinfocopy->bonehandle); @@ -229,7 +226,7 @@ namespace MWRender{ /*if(vecPosRot.find(boneinfocopy->bonehandle) == vecPosRot.end()){ vecPos = bonePtr->_getDerivedPosition() + bonePtr->_getDerivedOrientation() * boneinfocopy->trafo.trans; vecRot = bonePtr->_getDerivedOrientation() * boneinfocopy->trafo.rotation; - + if(useHandles){ PosAndRot both; both.vecPos = vecPos; @@ -243,24 +240,25 @@ namespace MWRender{ vecRot = both.vecRot; }*/ - + absVertPos += (vecPos + vecRot * currentVertex) * inds[i].weight; - + } Ogre::Real* addr = (pReal + 3 * verIndex); *addr = absVertPos.x; *(addr+1) = absVertPos.y; *(addr+2) = absVertPos.z; } - - /*for (unsigned int i = 0; i < boneinfovector.size(); i++) + +#if 0 + for (unsigned int i = 0; i < boneinfovector.size(); i++) { Nif::NiSkinData::BoneInfoCopy boneinfo = boneinfovector[i]; if(skel->hasBone(boneinfo.bonename)){ Ogre::Bone *bonePtr = skel->getBone(boneinfo.bonename); Ogre::Vector3 vecPos = bonePtr->_getDerivedPosition() + bonePtr->_getDerivedOrientation() * boneinfo.trafo.trans; Ogre::Quaternion vecRot = bonePtr->_getDerivedOrientation() * boneinfo.trafo.rotation; - + for (unsigned int j=0; j < boneinfo.weights.size(); j++) { unsigned int verIndex = boneinfo.weights[j].vertex; @@ -273,12 +271,12 @@ namespace MWRender{ *addr = absVertPos.x; *(addr+1) = absVertPos.y; *(addr+2) = absVertPos.z; - + } - else + else { - + Ogre::Vector3 absVertPos = vecPos + vecRot * allvertices[verIndex]; absVertPos = absVertPos * boneinfo.weights[j].weight; Ogre::Vector3 old = Ogre::Vector3(pReal + 3 * verIndex); @@ -287,12 +285,12 @@ namespace MWRender{ *addr = absVertPos.x; *(addr+1) = absVertPos.y; *(addr+2) = absVertPos.z; - + //std::cout << "Vertex" << verIndex << "Weight: " << boneinfo.weights[i].weight << "was seen twice\n"; } - - /*if(normals.find(verIndex) == normals.end()) + + if(normals.find(verIndex) == normals.end()) { Ogre::Vector3 absNormalsPos = vecRot * allnormals[verIndex]; absNormalsPos = absNormalsPos * boneinfo.weights[j].weight; @@ -314,16 +312,16 @@ namespace MWRender{ *(addr+1) = absNormalsPos.y; *(addr+2) = absNormalsPos.z; - }*/ - + } +#endif //} //} - - + + //} //Comment out - + ; - } + } else { //Ogre::Bone *bonePtr = creaturemodel->getSkeleton()->getBone(copy.bonename); @@ -337,9 +335,9 @@ namespace MWRender{ float scale; if(skel->hasBone(*boneSequenceIter)){ Ogre::Bone *bonePtr = skel->getBone(*boneSequenceIter); - - - + + + transmult = bonePtr->getPosition(); rotmult = bonePtr->getOrientation(); @@ -368,13 +366,13 @@ namespace MWRender{ rotmult = shaperot; scale = shapescale; } - - - + + + // Computes C = B + AxC*scale // final_vector = old_vector + old_rotation*new_vector*old_scale/ - + for(unsigned int i = 0; i < allvertices->size(); i++){ Ogre::Vector3 current = transmult + rotmult * (*allvertices)[i]; Ogre::Real* addr = pReal + i * 3; @@ -414,10 +412,10 @@ namespace MWRender{ x = 0.0; return true; } - + if ( i < 0 || i >= count ) i = 0; - + float tI = times[i]; if ( time > tI ) { @@ -457,11 +455,11 @@ namespace MWRender{ void Animation::handleAnimationTransforms(){ Ogre::SkeletonInstance* skel = base->getSkeleton(); - + Ogre::Bone* b = skel->getRootBone(); b->setOrientation(Ogre::Real(.3),Ogre::Real(.3),Ogre::Real(.3), Ogre::Real(.3)); //This is a trick - + skel->_updateTransforms(); //skel->_notifyManualBonesDirty(); @@ -474,7 +472,7 @@ namespace MWRender{ Ogre::Bone* b = skel->getRootBone(); b->setOrientation(Ogre::Real(.3),Ogre::Real(.3),Ogre::Real(.3), Ogre::Real(.3));//This is a trick - + skel->_updateTransforms(); // skel->_notifyManualBonesDirty(); @@ -492,17 +490,17 @@ namespace MWRender{ slot++; //iter++; continue; - + } float x; float x2; - + std::vector quats = iter->getQuat(); std::vector ttime = iter->gettTime(); std::vector::iterator ttimeiter = ttime.begin(); - + std::vector rtime = iter->getrTime(); int rindexJ = 0; timeIndex(time, rtime, rindexI[slot], rindexJ, x2); @@ -516,15 +514,15 @@ namespace MWRender{ //std::cout << "X: " << x << " X2: " << x2 << "\n"; Ogre::Vector3 t; Ogre::Quaternion r; - + bool bTrans = translist1.size() > 0; if(bTrans){ Ogre::Vector3 v1 = translist1[tindexI[slot]]; Ogre::Vector3 v2 = translist1[tindexJ]; t = (v1 + (v2 - v1) * x); - + } - + bool bQuats = quats.size() > 0; if(bQuats){ r = Ogre::Quaternion::Slerp(x2, quats[rindexI[slot]], quats[rindexJ], true); @@ -538,15 +536,15 @@ namespace MWRender{ if(bQuats) bone->setOrientation(r); - - + + skel->_updateTransforms(); //skel->_notifyManualBonesDirty(); base->getAllAnimationStates()->_notifyDirty(); //base->_updateAnimation(); base->_notifyMoved(); - } - for(int i = 0; i < entityparts.size(); i++){ + } + for(std::size_t i = 0; i < entityparts.size(); i++){ skel = entityparts[i]->getSkeleton(); if(skel->hasBone(iter->getBonename())){ Ogre::Bone* bone = skel->getBone(iter->getBonename()); @@ -554,17 +552,17 @@ namespace MWRender{ bone->setPosition(t); if(bQuats) bone->setOrientation(r); - + skel->_updateTransforms(); //skel->_notifyManualBonesDirty(); entityparts[i]->getAllAnimationStates()->_notifyDirty(); // entityparts[i]->_updateAnimation(); entityparts[i]->_notifyMoved(); - } + } } slot++; } } } -} \ No newline at end of file +} diff --git a/apps/openmw/mwrender/creatureanimation.cpp b/apps/openmw/mwrender/creatureanimation.cpp index c2b95186b8..3cb40f2f1a 100644 --- a/apps/openmw/mwrender/creatureanimation.cpp +++ b/apps/openmw/mwrender/creatureanimation.cpp @@ -14,7 +14,7 @@ CreatureAnimation::CreatureAnimation(const MWWorld::Ptr& ptr, MWWorld::Environme ESMS::LiveCellRef *ref = ptr.get(); - assert (ref->base != NULL); + assert (ref->base != NULL); if(!ref->base->model.empty()){ const std::string &mesh = "meshes\\" + ref->base->model; std::string meshNumbered = mesh + getUniqueID(mesh) + ">|"; @@ -22,9 +22,9 @@ CreatureAnimation::CreatureAnimation(const MWWorld::Ptr& ptr, MWWorld::Environme base = mRend.getScene()->createEntity(meshNumbered); std::string meshZero = mesh + "0000>|"; - if(transformations = (NIFLoader::getSingletonPtr())->getAnim(meshZero)){ + if((transformations = (NIFLoader::getSingletonPtr())->getAnim(meshZero))){ - for(int init = 0; init < transformations->size(); init++){ + for(std::size_t init = 0; init < transformations->size(); init++){ rindexI.push_back(0); tindexI.push_back(0); } @@ -53,10 +53,10 @@ void CreatureAnimation::runAnimation(float timepassed){ else time = startTime + (time - stopTime); } - + handleAnimationTransforms(); handleShapes(shapes, base, base->getSkeleton()); } } -} \ No newline at end of file +} diff --git a/apps/openmw/mwrender/npcanimation.cpp b/apps/openmw/mwrender/npcanimation.cpp index 0ff679507c..ef5c105590 100644 --- a/apps/openmw/mwrender/npcanimation.cpp +++ b/apps/openmw/mwrender/npcanimation.cpp @@ -13,7 +13,7 @@ NpcAnimation::~NpcAnimation(){ NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, MWWorld::Environment& _env,OEngine::Render::OgreRenderer& _rend): Animation(_env,_rend){ ESMS::LiveCellRef *ref = ptr.get(); - + //Part selection on last character of the file string // " Tri Chest // * Tri Tail @@ -35,10 +35,10 @@ NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, MWWorld::Environment& _env,O std::string hairID = ref->base->hair; std::string headID = ref->base->head; std::string npcName = ref->base->name; - //ESMStore::Races r = + //ESMStore::Races r = const ESM::Race* race = mEnvironment.mWorld->getStore().races.find(ref->base->race); - - + + std::string bodyRaceID = headID.substr(0, headID.find_last_of("head_") - 4); char secondtolast = bodyRaceID.at(bodyRaceID.length() - 2); bool female = tolower(secondtolast) == 'f'; @@ -51,7 +51,7 @@ NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, MWWorld::Environment& _env,O std::cout << " Sex: Male" << " Height: " << race->data.height.male << "\n"; }*/ - + std::string smodel = "meshes\\base_anim.nif"; if(beast) @@ -61,25 +61,25 @@ NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, MWWorld::Environment& _env,O assert(insert); NifOgre::NIFLoader::load(smodel); - + base = mRend.getScene()->createEntity(smodel); - base->setSkipAnimationStateUpdate(true); //Magical line of code, this makes the bones + base->setSkipAnimationStateUpdate(true); //Magical line of code, this makes the bones //stay in the same place when we skipanim, or open a gui window - - if(transformations = (NIFLoader::getSingletonPtr())->getAnim(smodel)){ + + if((transformations = (NIFLoader::getSingletonPtr())->getAnim(smodel))){ for(unsigned int init = 0; init < transformations->size(); init++){ rindexI.push_back(0); tindexI.push_back(0); } - + stopTime = transformations->begin()->getStopTime(); startTime = transformations->begin()->getStartTime(); } textmappings = NIFLoader::getSingletonPtr()->getTextIndices(smodel); insert->attachObject(base); - + if(female) insert->scale(race->data.height.female, race->data.height.female, race->data.height.female); else @@ -108,18 +108,18 @@ NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, MWWorld::Environment& _env,O forearml = mEnvironment.mWorld->getStore().bodyParts.search ("b_n_argonian_m_forearm"); //We need two if(!handl) handl = mEnvironment.mWorld->getStore().bodyParts.search (bodyRaceID + "hands"); - //const ESM::BodyPart* claviclel = environment.mWorld->getStore().bodyParts.search (bodyRaceID + "clavicle"); + //const ESM::BodyPart* claviclel = environment.mWorld->getStore().bodyParts.search (bodyRaceID + "clavicle"); //const ESM::BodyPart* clavicler = claviclel; const ESM::BodyPart* handr = handl; const ESM::BodyPart* forearmr = forearml; const ESM::BodyPart* wristr = wristl; const ESM::BodyPart* armr = arml; - + if(upperleg){ insertBoundedPart("meshes\\" + upperleg->model + "*|", "Left Upper Leg"); insertBoundedPart("meshes\\" + upperleg->model, "Right Upper Leg"); - + } if(foot){ if(bodyRaceID.compare("b_n_khajiit_m_") == 0) @@ -139,10 +139,10 @@ NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, MWWorld::Environment& _env,O { insertBoundedPart("meshes\\" + knee->model + "*|", "Left Knee"); //e insertBoundedPart("meshes\\" + knee->model, "Right Knee"); //e - + } if(ankle){ - + insertBoundedPart("meshes\\" + ankle->model + "*|", "Left Ankle"); //Ogre::Quaternion(Ogre::Radian(3.14 / 4), Ogre::Vector3(1, 0, 0)),blank); //1,0,0, blank); insertBoundedPart("meshes\\" + ankle->model, "Right Ankle"); } @@ -167,17 +167,17 @@ NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, MWWorld::Environment& _env,O if(wristl) insertBoundedPart("meshes\\" + wristl->model + "*|", "Left Wrist"); - - - - + + + + /*if(claviclel) insertBoundedPart("meshes\\" + claviclel->model + "*|", "Left Clavicle", base); if(clavicler) insertBoundedPart("meshes\\" + clavicler->model , "Right Clavicle", base);*/ - - + + if(neck) { insertBoundedPart("meshes\\" + neck->model, "Neck"); @@ -186,19 +186,19 @@ NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, MWWorld::Environment& _env,O insertBoundedPart("meshes\\" + head->model, "Head"); if(hair) insertBoundedPart("meshes\\" + hair->model, "Head"); - + if (chest){ insertFreePart("meshes\\" + chest->model, ">\"", insert); - - + + } if (handr){ insertFreePart("meshes\\" + handr->model , ">?", insert); - + } if (handl){ insertFreePart("meshes\\" + handl->model, ">>", insert); - + } if(tail){ insertFreePart("meshes\\" + tail->model, ">*", insert); @@ -215,16 +215,16 @@ NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, MWWorld::Environment& _env,O Ogre::Entity* NpcAnimation::insertBoundedPart(const std::string &mesh, std::string bonename){ NIFLoader::load(mesh); Entity* ent = mRend.getScene()->createEntity(mesh); - - base->attachObjectToBone(bonename, ent); + + base->attachObjectToBone(bonename, ent); return ent; } void NpcAnimation::insertFreePart(const std::string &mesh, const std::string suffix, Ogre::SceneNode* insert){ - std::string meshNumbered = mesh + getUniqueID(mesh + suffix) + suffix; + std::string meshNumbered = mesh + getUniqueID(mesh + suffix) + suffix; NIFLoader::load(meshNumbered); - + Ogre::Entity* ent = mRend.getScene()->createEntity(meshNumbered); - + /*MaterialPtr material = ent->getSubEntity(0)->getMaterial(); material->removeAllTechniques(); @@ -234,7 +234,7 @@ void NpcAnimation::insertFreePart(const std::string &mesh, const std::string suf pass2->setVertexProgram("Ogre/HardwareSkinningTwoWeights"); pass2->setColourWriteEnabled(false); //tech->setSchemeName("blahblah");*/ - + insert->attachObject(ent); entityparts.push_back(ent); @@ -244,7 +244,7 @@ void NpcAnimation::insertFreePart(const std::string &mesh, const std::string suf handleShapes(shapes, ent, base->getSkeleton()); } - + } @@ -256,10 +256,10 @@ void NpcAnimation::runAnimation(float timepassed){ //3. Handle the shapes dependent on animation transforms if(animate > 0){ time += timepassed; - + if(time > stopTime){ animate--; - + if(animate == 0) time = stopTime; else @@ -270,21 +270,21 @@ void NpcAnimation::runAnimation(float timepassed){ Ogre::Vector3 current = insert->_getWorldAABB().getCenter(); //This is the attempt at npc physics - //mEnvironment.mWorld->setObjectPhysicsPosition(insert->getName(), current); + //mEnvironment.mWorld->setObjectPhysicsPosition(insert->getName(), current); + - /*if(base->hasSkeleton()) { - + Ogre::Quaternion boneQuat = rotate; Ogre::Vector3 boneTrans = trans; mEnvironment.mWorld->setObjectPhysicsPosition(insert->getName(), boneTrans + insert->getPosition()); //mEnvironment.mWorld->setObjectPhysicsRotation(insert->getName(), boneQuat * insert->getOrientation()); - + }*/ - - + + std::vector*>::iterator shapepartsiter = shapeparts.begin(); std::vector::iterator entitypartsiter = entityparts.begin(); while(shapepartsiter != shapeparts.end()) @@ -292,12 +292,12 @@ void NpcAnimation::runAnimation(float timepassed){ std::vector* shapes = *shapepartsiter; Ogre::Entity* theentity = *entitypartsiter; /* - Pass* pass = theentity->getSubEntity(0)->getMaterial()->getBestTechnique()->getPass(0); + Pass* pass = theentity->getSubEntity(0)->getMaterial()->getBestTechnique()->getPass(0); if (pass->hasVertexProgram() && pass->getVertexProgram()->isSkeletalAnimationIncluded()) std::cout << "It's hardware\n"; else std::cout << "It's software\n";*/ - + handleShapes(shapes, theentity, theentity->getSkeleton()); shapepartsiter++; entitypartsiter++; @@ -305,4 +305,4 @@ void NpcAnimation::runAnimation(float timepassed){ } } -} \ No newline at end of file +} diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index fff1412631..6215c1913f 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -22,7 +22,7 @@ namespace MWRender { RenderingManager::RenderingManager (OEngine::Render::OgreRenderer& _rend, const boost::filesystem::path& resDir, OEngine::Physic::PhysicEngine* engine, MWWorld::Environment& environment) -:mRendering(_rend), mObjects(mRendering), mDebugging(engine), mActors(mRendering, environment) +:mRendering(_rend), mObjects(mRendering), mActors(mRendering, environment), mDebugging(engine) { mRendering.createScene("PlayerCam", 55, 5); mSkyManager = MWRender::SkyManager::create(mRendering.getWindow(), mRendering.getCamera(), resDir); diff --git a/components/nif/node.hpp b/components/nif/node.hpp index bbceb866e0..0800427466 100644 --- a/components/nif/node.hpp +++ b/components/nif/node.hpp @@ -103,7 +103,7 @@ struct NiTriShapeCopy std::vector vertices; std::vector normals; std::vector boneinfo; - std::map> vertsToWeights; + std::map > vertsToWeights; Nif::NiMorphData morph; }; @@ -158,13 +158,13 @@ struct NiTriShape : Node { float *current = (float*) (ptr + i * 3); copy.vertices.push_back(Ogre::Vector3(*current, *(current + 1), *(current + 2))); - + if(ptrNormals){ float *currentNormals = (float*) (ptrNormals + i * 3); - copy.normals.push_back(Ogre::Vector3(*currentNormals, *(currentNormals + 1), *(currentNormals + 2))); + copy.normals.push_back(Ogre::Vector3(*currentNormals, *(currentNormals + 1), *(currentNormals + 2))); } } - + return copy; } diff --git a/components/nifogre/ogre_nif_loader.cpp b/components/nifogre/ogre_nif_loader.cpp index 92a5713a3a..c62f59ea3d 100644 --- a/components/nifogre/ogre_nif_loader.cpp +++ b/components/nifogre/ogre_nif_loader.cpp @@ -222,7 +222,7 @@ void NIFLoader::createMaterial(const String &name, //Hardware Skinning code, textures may be the wrong color if enabled /*if(!mSkel.isNull()){ material->removeAllTechniques(); - + Ogre::Technique* tech = material->createTechnique(); //tech->setSchemeName("blahblah"); Pass* pass = tech->createPass(); @@ -234,8 +234,8 @@ void NIFLoader::createMaterial(const String &name, // will automatically be loaded when needed. If not (such as for // internal NIF textures that we might support later), we should // already have inserted a manual loader for the texture. - - + + if (!texName.empty()) { Pass *pass = material->getTechnique(0)->getPass(0); @@ -295,8 +295,8 @@ void NIFLoader::createMaterial(const String &name, material->setSpecular(specular.array[0], specular.array[1], specular.array[2], alpha); material->setSelfIllumination(emissive.array[0], emissive.array[1], emissive.array[2]); material->setShininess(glossiness); - - + + } // Takes a name and adds a unique part to it. This is just used to @@ -359,7 +359,7 @@ void NIFLoader::createOgreSubMesh(NiTriShape *shape, const String &material, std HardwareBufferManager::getSingleton().createVertexBuffer( VertexElement::getTypeSize(VET_FLOAT3), numVerts, HardwareBuffer::HBU_STATIC_WRITE_ONLY, false); - + if(flip) { float *datamod = new float[data->vertices.length]; @@ -381,7 +381,7 @@ void NIFLoader::createOgreSubMesh(NiTriShape *shape, const String &material, std { vbuf->writeData(0, vbuf->getSizeInBytes(), data->vertices.ptr, false); } - + VertexBufferBinding* bind = sub->vertexData->vertexBufferBinding; bind->setBinding(nextBuf++, vbuf); @@ -392,7 +392,7 @@ void NIFLoader::createOgreSubMesh(NiTriShape *shape, const String &material, std vbuf = HardwareBufferManager::getSingleton().createVertexBuffer( VertexElement::getTypeSize(VET_FLOAT3), numVerts, HardwareBuffer::HBU_STATIC_WRITE_ONLY, false); - + if(flip) { Quaternion rotation = mTransform.extractQuaternion(); @@ -456,10 +456,10 @@ void NIFLoader::createOgreSubMesh(NiTriShape *shape, const String &material, std if(flip) { float *datamod = new float[data->uvlist.length]; - + for(unsigned int i = 0; i < data->uvlist.length; i+=2){ float x = *(data->uvlist.ptr + i); - + float y = *(data->uvlist.ptr + i + 1); datamod[i] =x; @@ -474,10 +474,10 @@ void NIFLoader::createOgreSubMesh(NiTriShape *shape, const String &material, std // Triangle faces - The total number of triangle points int numFaces = data->triangles.length; - + if (numFaces) { - + sub->indexData->indexCount = numFaces; sub->indexData->indexStart = 0; HardwareIndexBufferSharedPtr ibuf = HardwareBufferManager::getSingleton(). @@ -508,14 +508,14 @@ void NIFLoader::createOgreSubMesh(NiTriShape *shape, const String &material, std index += 3; } - + ibuf->writeData(0, ibuf->getSizeInBytes(), datamod, false); } else ibuf->writeData(0, ibuf->getSizeInBytes(), data->triangles.ptr, false); sub->indexData->indexBuffer = ibuf; - + } @@ -753,9 +753,9 @@ void NIFLoader::handleNiTriShape(NiTriShape *shape, int flags, BoundsFinder &bou //use niskindata for the position of vertices. if (!shape->skin.empty()) { - - - + + + // vector that stores if the position of a vertex is absolute std::vector vertexPosAbsolut(numVerts,false); std::vector vertexPosOriginal(numVerts, Ogre::Vector3::ZERO); @@ -791,7 +791,7 @@ void NIFLoader::handleNiTriShape(NiTriShape *shape, int flags, BoundsFinder &bou bonePtr = mSkel->getBone(shape->skin->bones[boneIndex].name.toString()); // final_vector = old_vector + old_rotation*new_vector*old_scale - + Nif::NiSkinData::BoneInfoCopy boneinfocopy; boneinfocopy.trafo.rotation = convertRotation(it->trafo->rotation); @@ -841,7 +841,7 @@ void NIFLoader::handleNiTriShape(NiTriShape *shape, int flags, BoundsFinder &bou Vector3 absNormalsPos = vecRot * Vector3(ptrNormals + verIndex *3); absNormalsPos = absNormalsPos * (it->weights.ptr + i)->weight; vertexNormalOriginal[verIndex] = Vector3(ptrNormals + verIndex *3); - + for (int j=0; j<3; j++) (ptrNormals + verIndex*3)[j] = absNormalsPos[j]; } @@ -868,7 +868,7 @@ void NIFLoader::handleNiTriShape(NiTriShape *shape, int flags, BoundsFinder &bou absNormalsPos = absNormalsPos * (it->weights.ptr + i)->weight; Vector3 oldNormal = Vector3(ptrNormals + verIndex *3); absNormalsPos = absNormalsPos + oldNormal; - + for (int j=0; j<3; j++) (ptrNormals + verIndex*3)[j] = absNormalsPos[j]; } @@ -879,19 +879,19 @@ void NIFLoader::handleNiTriShape(NiTriShape *shape, int flags, BoundsFinder &bou vba.boneIndex = bonePtr->getHandle(); vba.vertexIndex = verIndex; vba.weight = (it->weights.ptr + i)->weight; - + vertexBoneAssignments.push_back(vba); } - + boneIndex++; } - + } else { - + copy.boneSequence = boneSequence; // Rotate, scale and translate all the vertices, const Matrix &rot = shape->trafo->rotation; @@ -902,7 +902,7 @@ void NIFLoader::handleNiTriShape(NiTriShape *shape, int flags, BoundsFinder &bou copy.trafo.rotation = convertRotation(original.rotation); copy.trafo.scale = original.scale; //We don't use velocity for anything yet, so it does not need to be saved - + // Computes C = B + AxC*scale for (int i=0; inormals.length) { @@ -955,7 +955,7 @@ void NIFLoader::calculateTransform() // Calculate transform Matrix4 transform = Matrix4::IDENTITY; transform = Matrix4::getScale(vector) * transform; - + // Check whether we have to flip vertex winding. // We do have to, if we changed our right hand base. // We can test it by using the cross product from X and Y and see, if it is a non-negative @@ -963,7 +963,7 @@ void NIFLoader::calculateTransform() // but the test is cheap either way. Matrix3 m3; transform.extract3x3Matrix(m3); - + if (m3.GetColumn(0).crossProduct(m3.GetColumn(1)).dotProduct(m3.GetColumn(2)) < 0) { mFlipVertexWinding = true; @@ -1003,39 +1003,38 @@ void NIFLoader::handleNode(Nif::Node *node, int flags, } if (e->recType == RC_NiTextKeyExtraData){ - Nif::NiTextKeyExtraData* extra = dynamic_cast (e); - - std::ofstream file; + Nif::NiTextKeyExtraData* extra = dynamic_cast (e); + + std::ofstream file; if(mOutputAnimFiles){ - std::string cut = ""; - for(unsigned int i = 0; i < name.length(); i++) - { - if(!(name.at(i) == '\\' || name.at(i) == '/' || name.at(i) == '>' || name.at(i) == '<' || name.at(i) == '?' || name.at(i) == '*' || name.at(i) == '|' || name.at(i) == ':' || name.at(i) == '"')) - { - cut += name.at(i); - } - } - - std::cout << "Outputting " << cut << "\n"; - - file.open((verbosePath + "/Indices" + cut + ".txt").c_str()); + std::string cut = ""; + for(unsigned int i = 0; i < name.length(); i++) + { + if(!(name.at(i) == '\\' || name.at(i) == '/' || name.at(i) == '>' || name.at(i) == '<' || name.at(i) == '?' || name.at(i) == '*' || name.at(i) == '|' || name.at(i) == ':' || name.at(i) == '"')) + { + cut += name.at(i); + } + } + + std::cout << "Outputting " << cut << "\n"; + + file.open((verbosePath + "/Indices" + cut + ".txt").c_str()); } - - for(std::vector::iterator textiter = extra->list.begin(); textiter != extra->list.end(); textiter++) - { - - std::string text = textiter->text.toString(); - - replace(text.begin(), text.end(), '\n', '/'); - text.erase(std::remove(text.begin(), text.end(), '\r'), text.end()); - int i = 0; + for(std::vector::iterator textiter = extra->list.begin(); textiter != extra->list.end(); textiter++) + { + std::string text = textiter->text.toString(); + + replace(text.begin(), text.end(), '\n', '/'); + + text.erase(std::remove(text.begin(), text.end(), '\r'), text.end()); + std::size_t i = 0; while(i < text.length()){ while(i < text.length() && text.at(i) == '/' ){ i++; } - int first = i; + std::size_t first = i; int length = 0; while(i < text.length() && text.at(i) != '/' ){ i++; @@ -1045,15 +1044,15 @@ void NIFLoader::handleNode(Nif::Node *node, int flags, //length = text.length() - first; std::string sub = text.substr(first, length); - if(mOutputAnimFiles) + if(mOutputAnimFiles) file << "Time: " << textiter->time << "|" << sub << "\n"; - - textmappings[sub] = textiter->time; + + textmappings[sub] = textiter->time; } } - } - file.close(); - } + } + file.close(); + } } Bone *bone = 0; @@ -1064,7 +1063,7 @@ void NIFLoader::handleNode(Nif::Node *node, int flags, //FIXME: "Bip01" isn't every time the root bone if (node->name == "Bip01" || node->name == "Root Bone") //root node, create a skeleton { - + mSkel = SkeletonManager::getSingleton().create(getSkeletonName(), resourceGroup, true); } @@ -1072,7 +1071,7 @@ void NIFLoader::handleNode(Nif::Node *node, int flags, { std::string name = node->name.toString(); boneSequence.push_back(name); - + // Quick-n-dirty workaround for the fact that several // bones may have the same name. if(!mSkel->hasBone(name)) @@ -1125,7 +1124,7 @@ void NIFLoader::handleNode(Nif::Node *node, int flags, else if (node->recType == RC_NiTriShape && bNiTri) { std::string nodename = node->name.toString(); - + if (triname == "") { handleNiTriShape(dynamic_cast(node), flags, bounds, original, boneSequence); @@ -1172,12 +1171,12 @@ void NIFLoader::loadResource(Resource *resource) baddin = true; bNiTri = true; std::string sub = name.substr(name.length() - 6, 4); - + if(sub.compare("0000") != 0) addAnim = false; - + } - + switch(name.at(name.length() - 1)) { case '"': @@ -1253,33 +1252,30 @@ void NIFLoader::loadResource(Resource *resource) // Handle the node std::vector boneSequence; - - + + handleNode(node, 0, NULL, bounds, 0, boneSequence); if(addAnim) { for(int i = 0; i < nif.numRecords(); i++) - { - Nif::NiKeyframeController *f = dynamic_cast(nif.getRecord(i)); - - Nif::Node *n = dynamic_cast(nif.getRecord(i)); - if(f != NULL) - { - hasAnim = true; - Nif::Node *o = dynamic_cast(f->target.getPtr()); - Nif::NiKeyframeDataPtr data = f->data; - - if (f->timeStart == 10000000000000000) - continue; - data->setBonename(o->name.toString()); - data->setStartTime(f->timeStart); - data->setStopTime(f->timeStop); - - allanim.push_back(data.get()); - - - } + { + Nif::NiKeyframeController *f = dynamic_cast(nif.getRecord(i)); + + if(f != NULL) + { + hasAnim = true; + Nif::Node *o = dynamic_cast(f->target.getPtr()); + Nif::NiKeyframeDataPtr data = f->data; + + if (f->timeStart == 10000000000000000) + continue; + data->setBonename(o->name.toString()); + data->setStartTime(f->timeStart); + data->setStopTime(f->timeStop); + + allanim.push_back(data.get()); + } } } // set the bounding value. @@ -1290,18 +1286,18 @@ void NIFLoader::loadResource(Resource *resource) mesh->_setBoundingSphereRadius(bounds.getRadius()); } if(hasAnim && addAnim){ - allanimmap[name] = allanim; - alltextmappings[name] = textmappings; - } - if(!mSkel.isNull() && shapes.size() > 0 && addAnim) - { - allshapesmap[name] = shapes; - - } - + allanimmap[name] = allanim; + alltextmappings[name] = textmappings; + } + if(!mSkel.isNull() && shapes.size() > 0 && addAnim) + { + allshapesmap[name] = shapes; + + } + if(flip){ - mesh->_setBounds(mBoundingBox, false); - } + mesh->_setBounds(mBoundingBox, false); + } if (!mSkel.isNull()) { @@ -1310,7 +1306,7 @@ void NIFLoader::loadResource(Resource *resource) } void NIFLoader::addInMesh(Ogre::Mesh* input){ - addin.push_back(input); + addin.push_back(input); } @@ -1318,7 +1314,7 @@ void NIFLoader::addInMesh(Ogre::Mesh* input){ MeshPtr NIFLoader::load(const std::string &name, const std::string &group) { - + MeshManager *m = MeshManager::getSingletonPtr(); // Check if the resource already exists ResourcePtr ptr = m->getByName(name, group); @@ -1335,26 +1331,26 @@ MeshPtr NIFLoader::load(const std::string &name, /* This function shares much of the same code handleShapes() in MWRender::Animation -This function also creates new position and normal buffers for submeshes. +This function also creates new position and normal buffers for submeshes. This function points to existing texture and IndexData buffers */ std::vector* NIFLoader::getAnim(std::string lowername){ - - std::map,ciLessBoost>::iterator iter = allanimmap.find(lowername); + + std::map,ciLessBoost>::iterator iter = allanimmap.find(lowername); std::vector* pass = 0; - if(iter != allanimmap.end()) - pass = &(iter->second); - return pass; - + if(iter != allanimmap.end()) + pass = &(iter->second); + return pass; + } std::vector* NIFLoader::getShapes(std::string lowername){ - - std::map,ciLessBoost>::iterator iter = allshapesmap.find(lowername); + + std::map,ciLessBoost>::iterator iter = allshapesmap.find(lowername); std::vector* pass = 0; - if(iter != allshapesmap.end()) - pass = &(iter->second); - return pass; + if(iter != allshapesmap.end()) + pass = &(iter->second); + return pass; } std::map* NIFLoader::getTextIndices(std::string lowername){ diff --git a/components/nifogre/ogre_nif_loader.hpp b/components/nifogre/ogre_nif_loader.hpp index fd16208227..62239bb4c9 100644 --- a/components/nifogre/ogre_nif_loader.hpp +++ b/components/nifogre/ogre_nif_loader.hpp @@ -79,7 +79,7 @@ namespace Mangle namespace NifOgre { - + /** Manual resource loader for NIF meshes. This is the main class responsible for translating the internal NIF mesh structure into @@ -109,7 +109,7 @@ class NIFLoader : Ogre::ManualResourceLoader const std::string &group="General"); //void insertMeshInsideBase(Ogre::Mesh* mesh); std::vector* getAnim(std::string name); - std::vector* getShapes(std::string name); + std::vector* getShapes(std::string name); std::map* getTextIndices(std::string name); void addInMesh(Ogre::Mesh* input); @@ -121,12 +121,12 @@ class NIFLoader : Ogre::ManualResourceLoader void setVerbosePath(std::string path); private: - NIFLoader() : mNormaliseNormals(false), resourceGroup("General"), resourceName(""), flip(false), + NIFLoader() : resourceName(""), resourceGroup("General"), flip(false), mNormaliseNormals(false), mFlipVertexWinding(false), mOutputAnimFiles(false) {} NIFLoader(NIFLoader& n) {} void calculateTransform(); - + void warn(std::string msg); void fail(std::string msg); @@ -167,7 +167,7 @@ class NIFLoader : Ogre::ManualResourceLoader std::string verbosePath; std::string resourceName; std::string resourceGroup; - Ogre::Matrix4 mTransform; + Ogre::Matrix4 mTransform; Ogre::AxisAlignedBox mBoundingBox; bool flip; bool mNormaliseNormals; @@ -184,14 +184,14 @@ class NIFLoader : Ogre::ManualResourceLoader std::string name; std::string triname; std::vector allanim; - std::map textmappings; - std::map,ciLessBoost> alltextmappings; - std::map,ciLessBoost> allanimmap; - std::map,ciLessBoost> allshapesmap; + std::map textmappings; + std::map,ciLessBoost> alltextmappings; + std::map,ciLessBoost> allanimmap; + std::map,ciLessBoost> allshapesmap; std::vector addin; std::vector mAnim; - std::vector mS; - + std::vector mS; + }; }