From e72e336e2464295bb389c276b3de4334f12f22af Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 5 Jan 2011 01:38:35 -0800 Subject: [PATCH 01/20] testing --- apps/openmw/mwclass/npc.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index c277832ab..a64db189b 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -53,9 +53,6 @@ namespace MWClass MWRender::Rendering rendering (cellRender, ref->ref); - - //TODO: define consts for each bodypart e.g. chest, foot, wrist... and put the parts in the - // right place const ESM::BodyPart *bodyPart = environment.mWorld->getStore().bodyParts.search (bodyRaceID + "chest"); @@ -241,7 +238,6 @@ namespace MWClass cellRender.scaleMesh(Ogre::Vector3(1, -1, 1), upperright, uppernumbers); } - //neck will reset chest counter if(neck) { cellRender.insertMesh ("meshes\\" + neck->model, Ogre::Vector3( 0, 0, 120), axis, Ogre::Radian(3.14), npcName + "neck", neckandup, neckNumbers); @@ -250,8 +246,9 @@ namespace MWClass cellRender.insertMesh (headModel, Ogre::Vector3( 0, 0, 5), axis, Ogre::Radian(0), npcName + "head", neckandup, neckNumbers); neckandup[neckNumbers++] = npcName + "head"; cellRender.insertMesh (hairModel, Ogre::Vector3( 0, -1, 0), axis, Ogre::Radian(0), npcName + "hair", neckandup, neckNumbers); + cellRender.insertMesh("meshes\\base_anim.nif"); ref->mData.setHandle (rendering.end (ref->mData.isEnabled())); - + // } void Npc::enable (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const From ca9beb610d33124b4db0333889716fb4790906a9 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 5 Jan 2011 01:59:57 -0800 Subject: [PATCH 02/20] Brainstorming --- apps/openmw/engine.cpp | 118 +++++++++---------------- apps/openmw/mwgui/layouts.cpp | 2 +- apps/openmw/mwgui/review.cpp | 2 +- components/nifogre/ogre_nif_loader.cpp | 58 ++++++------ components/nifogre/ogre_nif_loader.hpp | 3 +- 5 files changed, 69 insertions(+), 114 deletions(-) diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 9e14c119b..d0f09c214 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -42,6 +42,8 @@ #include "mwgui/class.hpp" + + //using namespace ESM; void OMW::Engine::executeLocalScripts() @@ -75,8 +77,8 @@ bool OMW::Engine::frameStarted(const Ogre::FrameEvent& evt) std::string effect; - - + + MWWorld::Ptr::CellStore *current = mEnvironment.mWorld->getPlayerPos().getPlayer().getCell(); //If the region has changed if(!(current->cell->data.flags & current->cell->Interior) && timer.elapsed() >= 10){ @@ -86,7 +88,7 @@ bool OMW::Engine::frameStarted(const Ogre::FrameEvent& evt) total = 0; test = (ESM::Region) *(mEnvironment.mWorld->getStore().regions.find(current->cell->region)); } - + if(test.soundList.size() > 0) { std::vector::iterator soundIter = test.soundList.begin(); @@ -118,14 +120,14 @@ bool OMW::Engine::frameStarted(const Ogre::FrameEvent& evt) //play sound std::cout << "Sound: " << go.name <<" Chance:" << chance << "\n"; mEnvironment.mSoundManager->playSound(effect, 20.0, 1.0); - + break; } pos += chance; } } - + //mEnvironment.mSoundManager->playSound(effect, 1.0, 1.0); //printf("REGION: %s\n", test.name); @@ -194,7 +196,6 @@ OMW::Engine::Engine() , mVerboseScripts (false) , mNewGame (false) , mUseSound (true) - , mCompileAll (false) , mScriptManager (0) , mScriptContext (0) , mGuiManager (0) @@ -297,7 +298,7 @@ void OMW::Engine::go() test.name = ""; total = 0; - + std::cout << "Data directory: " << mDataDir << "\n"; @@ -307,6 +308,16 @@ void OMW::Engine::go() addResourcesDirectory (mDataDir / "Meshes"); addResourcesDirectory (mDataDir / "Textures"); + //boost::filesystem::copy_file("meshes\\b\\B_N_Argonian_F_Skins.nif",mDataDir / "b2\\B_N_Argonian_F_Skins.nif",boost::filesystem::copy_option::overwrite_if_exists); + /*CFileOperation fo; // create object + + fo.SetOverwriteMode(false); // reset OverwriteMode flag (optional) + + if (!fo.Copy("c:\\source", "c:\\dest")) // do Copy + { + fo.ShowError(); // if copy fails show error message + }*/ + // This has to be added BEFORE MyGUI is initialized, as it needs // to find core.xml here. @@ -327,7 +338,6 @@ void OMW::Engine::go() MyGUI::FactoryManager::getInstance().registerFactory("Widget"); MyGUI::FactoryManager::getInstance().registerFactory("Widget"); MyGUI::FactoryManager::getInstance().registerFactory("Widget"); - MyGUI::FactoryManager::getInstance().registerFactory("Widget"); // Create window manager - this manages all the MW-specific GUI windows MWScript::registerExtensions (mExtensions); @@ -361,20 +371,9 @@ void OMW::Engine::go() // load cell ESM::Position pos; + pos.pos[0] = pos.pos[1] = pos.pos[2] = 0; pos.rot[0] = pos.rot[1] = pos.rot[2] = 0; - pos.pos[2] = 0; - - if (const ESM::Cell *exterior = mEnvironment.mWorld->getExterior (mCellName)) - { - mEnvironment.mWorld->indexToPosition (exterior->data.gridX, exterior->data.gridY, - pos.pos[0], pos.pos[1], true); - mEnvironment.mWorld->changeToExteriorCell (pos); - } - else - { - pos.pos[0] = pos.pos[1] = 0; - mEnvironment.mWorld->changeCell (mCellName, pos); - } + mEnvironment.mWorld->changeCell (mCellName, pos); // Sets up the input system MWInput::MWInputManager input(mOgre, mEnvironment.mWorld->getPlayerPos(), @@ -390,29 +389,6 @@ void OMW::Engine::go() // Play some good 'ol tunes mEnvironment.mSoundManager->startRandomTitle(); - // scripts - if (mCompileAll) - { - typedef ESMS::ScriptListT::MapType Container; - - Container scripts = mEnvironment.mWorld->getStore().scripts.list; - - int count = 0; - int success = 0; - - for (Container::const_iterator iter (scripts.begin()); iter!=scripts.end(); ++iter, ++count) - if (mScriptManager->compile (iter->first)) - ++success; - - if (count) - std::cout - << "compiled " << success << " of " << count << " scripts (" - << 100*static_cast (success)/count - << "%)" - << std::endl; - - } - // Start the main rendering loop mOgre.start(); @@ -421,49 +397,35 @@ void OMW::Engine::go() void OMW::Engine::activate() { - // TODO: This is only a workaround. The input dispatcher should catch any exceptions thrown inside - // the input handling functions. Looks like this will require an OpenEngine modification. - try - { - std::string handle = mEnvironment.mWorld->getFacedHandle(); + std::string handle = mEnvironment.mWorld->getFacedHandle(); - if (handle.empty()) - return; + if (handle.empty()) + return; - MWWorld::Ptr ptr = mEnvironment.mWorld->getPtrViaHandle (handle); + MWWorld::Ptr ptr = mEnvironment.mWorld->getPtrViaHandle (handle); - if (ptr.isEmpty()) - return; + if (ptr.isEmpty()) + return; - MWScript::InterpreterContext interpreterContext (mEnvironment, - &ptr.getRefData().getLocals(), ptr); + MWScript::InterpreterContext interpreterContext (mEnvironment, + &ptr.getRefData().getLocals(), ptr); - boost::shared_ptr action = - MWWorld::Class::get (ptr).activate (ptr, mEnvironment.mWorld->getPlayerPos().getPlayer(), - mEnvironment); + boost::shared_ptr action = + MWWorld::Class::get (ptr).activate (ptr, mEnvironment.mWorld->getPlayerPos().getPlayer(), + mEnvironment); - interpreterContext.activate (ptr, action); + interpreterContext.activate (ptr, action); - std::string script = MWWorld::Class::get (ptr).getScript (ptr); + std::string script = MWWorld::Class::get (ptr).getScript (ptr); - if (!script.empty()) - { - mIgnoreLocalPtr = ptr; - mScriptManager->run (script, interpreterContext); - } - - if (!interpreterContext.hasActivationBeenHandled()) - { - interpreterContext.executeActivation(); - } - } - catch (const std::exception& e) + if (!script.empty()) { - std::cerr << "Activation failed: " << e.what() << std::endl; + mIgnoreLocalPtr = ptr; + mScriptManager->run (script, interpreterContext); } -} -void OMW::Engine::setCompileAll (bool all) -{ - mCompileAll = all; + if (!interpreterContext.hasActivationBeenHandled()) + { + interpreterContext.executeActivation(); + } } diff --git a/apps/openmw/mwgui/layouts.cpp b/apps/openmw/mwgui/layouts.cpp index 501b234d1..e03805e65 100644 --- a/apps/openmw/mwgui/layouts.cpp +++ b/apps/openmw/mwgui/layouts.cpp @@ -55,7 +55,7 @@ StatsWindow::StatsWindow (MWWorld::Environment& environment) for (int i = 0; i < ESM::Skill::Length; ++i) { skillValues.insert(std::pair >(i, MWMechanics::Stat())); - skillWidgetMap.insert(std::pair(i, nullptr)); + skillWidgetMap.insert(std::pair(i, (MyGUI::StaticTextPtr) nullptr)); } MyGUI::WindowPtr t = static_cast(mMainWidget); diff --git a/apps/openmw/mwgui/review.cpp b/apps/openmw/mwgui/review.cpp index 9eb6092ce..6caba6238 100644 --- a/apps/openmw/mwgui/review.cpp +++ b/apps/openmw/mwgui/review.cpp @@ -80,7 +80,7 @@ ReviewDialog::ReviewDialog(MWWorld::Environment& environment) for (int i = 0; i < ESM::Skill::Length; ++i) { skillValues.insert(std::pair >(i, MWMechanics::Stat())); - skillWidgetMap.insert(std::pair(i, nullptr)); + skillWidgetMap.insert(std::pair(i, (MyGUI::StaticTextPtr)nullptr)); } static_cast(mMainWidget)->eventWindowChangeCoord = MyGUI::newDelegate(this, &ReviewDialog::onWindowResize); diff --git a/components/nifogre/ogre_nif_loader.cpp b/components/nifogre/ogre_nif_loader.cpp index fc205d387..7d4731b82 100644 --- a/components/nifogre/ogre_nif_loader.cpp +++ b/components/nifogre/ogre_nif_loader.cpp @@ -728,8 +728,6 @@ void NIFLoader::handleNode(Nif::Node *node, int flags, const Transformation *trafo, BoundsFinder &bounds, Bone *parentBone) { stack++; - //if( MWClass::isChest) - // cout << "u:" << node << "\n"; // Accumulate the flags from all the child nodes. This works for all // the flags we currently use, at least. flags |= node->flags; @@ -740,6 +738,10 @@ void NIFLoader::handleNode(Nif::Node *node, int flags, { // Get the next extra data in the list e = e->extra.getPtr(); + if(anim){ + cout << "RECNAME:" << e->recName.toString() << "RECTYPE:" << e->recType << "\n"; + cout << "THE:" << e; + } assert(e != NULL); if (e->recType == RC_NiStringExtraData) @@ -761,9 +763,21 @@ void NIFLoader::handleNode(Nif::Node *node, int flags, Bone *bone = 0; + //Contains the actual rotation, scale, and translation coordinate data + if(node->recType == RC_NiKeyframeData && anim) + { + + } + //Indicates the node that the data applies to + if(node->recType == RC_NiKeyframeController && anim) + { + + } + // create skeleton or add bones if (node->recType == RC_NiNode) { + //TODO: Store this variable, then read the KeyFrames //FIXME: "Bip01" isn't every time the root bone if (node->name == "Bip01" || node->name == "Root Bone") //root node, create a skeleton { @@ -779,6 +793,8 @@ void NIFLoader::handleNode(Nif::Node *node, int flags, if (!skel.isNull()) //if there is a skeleton { std::string name = node->name.toString(); + if (anim) + std::cout << "BONE:" << name << "\n"; //if (isBeast && isChest) // std::cout << "NAME: " << name << "\n"; // Quick-n-dirty workaround for the fact that several @@ -928,6 +944,13 @@ void NIFLoader::loadResource(Resource *resource) const std::string test22 ="meshes\\b\\B_N_Breton_M_Skins.nif"; const std::string test23 ="meshes\\b\\B_N_High Elf_F_Skins.nif"; const std::string test24 ="meshes\\b\\B_N_High Elf_M_Skins.nif"; + const std::string animfile = "meshes\\base_anim.nif"; + if (name == animfile){ + std::cout << "We have animation\n"; + anim = true; + } + else + anim = false; //std::cout <<"LEN1:" << test.length() << "TEST: " << test << "\n"; @@ -1087,47 +1110,16 @@ MeshPtr NIFLoader::load(const std::string &name, // Check if the resource already exists ResourcePtr ptr = m->getByName(name, group); MeshPtr resize; - - const std::string beast1 ="meshes\\b\\B_N_Khajiit_F_Skins.nif"; - const std::string beast2 ="meshes\\b\\B_N_Khajiit_M_Skins.nif"; - const std::string beast3 ="meshes\\b\\B_N_Argonian_F_Skins.nif"; - const std::string beast4 ="meshes\\b\\B_N_Argonian_M_Skins.nif"; - - const std::string beasttail1 ="tail\\b\\B_N_Khajiit_F_Skins.nif"; - const std::string beasttail2 ="tail\\b\\B_N_Khajiit_M_Skins.nif"; - const std::string beasttail3 ="tail\\b\\B_N_Argonian_F_Skins.nif"; - const std::string beasttail4 ="tail\\b\\B_N_Argonian_M_Skins.nif"; if (!ptr.isNull()){ - //if(pieces > 1) - //cout << "It exists\n"; resize = MeshPtr(ptr); - //resize->load(); - //resize->reload(); } else // Nope, create a new one. { resize = MeshManager::getSingleton().createManual(name, group, NIFLoader::getSingletonPtr()); - //cout <<"EXISTING" << name << "\n"; - - //if(pieces > 1) - //cout << "Creating it\n"; - - - //resize->load(); - //resize->reload(); - //return 0; ResourcePtr ptr = m->getByName(name, group); resize = MeshPtr(ptr); - - //NIFLoader::getSingletonPtr()-> - /*ResourcePtr ptr = m->getByName(name, group); - if (!ptr.isNull()){ - if(pieces > 1) - cout << "It exists\n"; - resize = MeshPtr(ptr);*/ - //return resize; } return resize; } diff --git a/components/nifogre/ogre_nif_loader.hpp b/components/nifogre/ogre_nif_loader.hpp index b2a6b50fd..8f88c0fdb 100644 --- a/components/nifogre/ogre_nif_loader.hpp +++ b/components/nifogre/ogre_nif_loader.hpp @@ -82,7 +82,7 @@ class NIFLoader : Ogre::ManualResourceLoader Ogre::Quaternion convertRotation(const Nif::Matrix& rot); private: - NIFLoader() : resourceGroup("General") { skincounter = 0; resourceName = "";} + NIFLoader() : resourceGroup("General") { skincounter = 0; resourceName = ""; anim = false;} NIFLoader(NIFLoader& n) {} void warn(std::string msg); @@ -128,6 +128,7 @@ class NIFLoader : Ogre::ManualResourceLoader bool isBeast; bool isHands; bool isFeet; + bool anim; int counter; int numbers; int stack; From d035441876e9678093f89e4f46bcfa820333549b Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Mon, 11 Apr 2011 20:56:06 -0400 Subject: [PATCH 03/20] Reintroducing animation --- components/nif/data.hpp | 242 ++++++++++++++++++++++--- components/nifogre/ogre_nif_loader.cpp | 165 +++++++++++++++++ components/nifogre/ogre_nif_loader.hpp | 4 + 3 files changed, 390 insertions(+), 21 deletions(-) diff --git a/components/nif/data.hpp b/components/nif/data.hpp index 6fc2c4b82..bc23c45ab 100644 --- a/components/nif/data.hpp +++ b/components/nif/data.hpp @@ -25,6 +25,8 @@ #define _NIF_DATA_H_ #include "controlled.hpp" +#include +#include namespace Nif { @@ -433,20 +435,91 @@ public: class NiKeyframeData : public Record { + + //Rotations + std::vector quats; + std::vector tbc; + std::vector rottime; + int rtype; + + //Translations + std::vector translist1; + std::vector translist2; + std::vector translist3; + std::vector transtbc; + std::vector transtime; + int ttype; + + //Scalings + + std::vector scalefactor; + std::vector scaletime; + std::vector forwards; + std::vector backwards; + std::vector tbcscale; + int stype; + public: + void read(NIFFile *nif) { // Rotations first int count = nif->getInt(); + //std::vector quat(count); + //std::vector rottime(count); + std::cout << "r"; if(count) { - int type = nif->getInt(); - if(type == 1) - nif->skip(count*4*5); // time + quaternion - else if(type == 3) - nif->skip(count*4*8); // rot1 + tension+bias+continuity - else if(type == 4) + //TYPE1 LINEAR_KEY + //TYPE2 QUADRATIC_KEY + //TYPE3 TBC_KEY + //TYPE4 XYZ_ROTATION_KEY + //TYPE5 UNKNOWN_KEY + rtype = nif->getInt(); + //std::cout << "Count: " << count << "Type: " << type << "\n"; + + if(rtype == 1) + { + //We need to actually read in these values instead of skipping them + //nif->skip(count*4*5); // time + quaternion + for (int i = 0; i < count; i++) { + float time = nif->getFloat(); + float w = nif->getFloat(); + float x = nif->getFloat(); + float y = nif->getFloat(); + float z = nif->getFloat(); + Ogre::Quaternion quat = Ogre::Quaternion(Ogre::Real(w), Ogre::Real(x), Ogre::Real(y), Ogre::Real(z)); + quats.push_back(quat); + rottime.push_back(time); + //if(time == 0.0 || time > 355.5) + // std::cout <<"Time:" << time << "W:" << w <<"X:" << x << "Y:" << y << "Z:" << z << "\n"; + } + } + else if(rtype == 3) + { //Example - node 116 in base_anim.nif + for (int i = 0; i < count; i++) { + float time = nif->getFloat(); + float w = nif->getFloat(); + float x = nif->getFloat(); + float y = nif->getFloat(); + float z = nif->getFloat(); + + float tbcx = nif->getFloat(); + float tbcy = nif->getFloat(); + float tbcz = nif->getFloat(); + Ogre::Quaternion quat = Ogre::Quaternion(Ogre::Real(w), Ogre::Real(x), Ogre::Real(y), Ogre::Real(z)); + Ogre::Vector3 vec = Ogre::Vector3(tbcx, tbcy, tbcz); + quats.push_back(quat); + rottime.push_back(time); + tbc.push_back(vec); + //if(time == 0.0 || time > 355.5) + // std::cout <<"Time:" << time << "W:" << w <<"X:" << x << "Y:" << y << "Z:" << z << "\n"; + } + + //nif->skip(count*4*8); // rot1 + tension+bias+continuity + } + else if(rtype == 4) { for(int j=0;jfail("Unknown rotation type in NiKeyframeData"); } + //first = false; // Then translation count = nif->getInt(); + if(count) { - int type = nif->getInt(); - - if(type == 1) nif->getFloatLen(count*4); // time + translation - else if(type == 2) - nif->getFloatLen(count*10); // trans1 + forward + backward - else if(type == 3) - nif->getFloatLen(count*7); // trans1 + tension,bias,continuity + ttype = nif->getInt(); + + //std::cout << "TransCount:" << count << " Type: " << type << "\n"; + if(ttype == 1) { + for (int i = 0; i < count; i++) { + float time = nif->getFloat(); + float x = nif->getFloat(); + float y = nif->getFloat(); + float z = nif->getFloat(); + Ogre::Vector3 trans = Ogre::Vector3(x, y, z); + translist1.push_back(trans); + transtime.push_back(time); + } + //nif->getFloatLen(count*4); // time + translation + } + else if(ttype == 2) + { //Example - node 116 in base_anim.nif + for (int i = 0; i < count; i++) { + float time = nif->getFloat(); + float x = nif->getFloat(); + float y = nif->getFloat(); + float z = nif->getFloat(); + float x2 = nif->getFloat(); + float y2 = nif->getFloat(); + float z2 = nif->getFloat(); + float x3 = nif->getFloat(); + float y3 = nif->getFloat(); + float z3 = nif->getFloat(); + Ogre::Vector3 trans = Ogre::Vector3(x, y, z); + Ogre::Vector3 trans2 = Ogre::Vector3(x2, y2, z2); + Ogre::Vector3 trans3 = Ogre::Vector3(x3, y3, z3); + transtime.push_back(time); + translist1.push_back(trans); + translist2.push_back(trans2); + translist3.push_back(trans3); + } + + //nif->getFloatLen(count*10); // trans1 + forward + backward + } + else if(ttype == 3){ + for (int i = 0; i < count; i++) { + float time = nif->getFloat(); + float x = nif->getFloat(); + float y = nif->getFloat(); + float z = nif->getFloat(); + float t = nif->getFloat(); + float b = nif->getFloat(); + float c = nif->getFloat(); + Ogre::Vector3 trans = Ogre::Vector3(x, y, z); + Ogre::Vector3 tbc = Ogre::Vector3(t, b, c); + translist1.push_back(trans); + transtbc.push_back(tbc); + transtime.push_back(time); + } + //nif->getFloatLen(count*7); // trans1 + tension,bias,continuity + } else nif->fail("Unknown translation type"); } @@ -484,17 +608,93 @@ public: count = nif->getInt(); if(count) { - int type = nif->getInt(); - - int size = 0; - if(type == 1) size = 2; // time+scale - else if(type == 2) size = 4; // 1 + forward + backward (floats) - else if(type == 3) size = 5; // 1 + tbc - else nif->fail("Unknown scaling type"); - nif->getFloatLen(count*size); + stype = nif->getInt(); + + + for(int i = 0; i < count; i++){ + + + //int size = 0; + if(stype >= 1 && stype < 4) + { + float time = nif->getFloat(); + float scale = nif->getFloat(); + scaletime.push_back(time); + scalefactor.push_back(scale); + //size = 2; // time+scale + } + else nif->fail("Unknown scaling type"); + if(stype == 2){ + //size = 4; // 1 + forward + backward (floats) + float forward = nif->getFloat(); + float backward = nif->getFloat(); + forwards.push_back(forward); + backwards.push_back(backward); + } + else if(stype == 3){ + float tbcx = nif->getFloat(); + float tbcy = nif->getFloat(); + float tbcz = nif->getFloat(); + Ogre::Vector3 vec = Ogre::Vector3(tbcx, tbcy, tbcz); + tbcscale.push_back(vec); + + //size = 5; // 1 + tbc + } + + } } + else + stype = 0; } + int getRtype(){ + return rtype; + } + int getStype(){ + return stype; + } + int getTtype(){ + return ttype; + } + std::vector getQuat(){ + return quats; + } + std::vector getrTbc(){ + return tbc; + } + std::vector getrTime(){ + return rottime; + } + + std::vector getTranslist1(){ + return translist1; + } + std::vector getTranslist2(){ + return translist2; + } + std::vector getTranslist3(){ + return translist3; + } + std::vector gettTime(){ + return transtime; + } + std::vector getScalefactor(){ + return scalefactor; + } + std::vector getForwards(){ + return forwards; + } + std::vector getBackwards(){ + return backwards; + } + std::vector getScaleTbc(){ + return tbcscale; + } + + std::vector getsTime(){ + return scaletime; + } }; + } // Namespace #endif diff --git a/components/nifogre/ogre_nif_loader.cpp b/components/nifogre/ogre_nif_loader.cpp index a33fde55a..3d63a9f98 100644 --- a/components/nifogre/ogre_nif_loader.cpp +++ b/components/nifogre/ogre_nif_loader.cpp @@ -1068,6 +1068,11 @@ void NIFLoader::loadResource(Resource *resource) // Handle the node handleNode(node, 0, NULL, bounds, 0); + + short handle = 0; + //skel->setBlendMode(Ogre::SkeletonAnimationBlendMode::ANIMBLEND_CUMULATIVE); + bool first = true; + // set the bounding value. if (bounds.isValid()) { @@ -1075,6 +1080,166 @@ void NIFLoader::loadResource(Resource *resource) bounds.maxX(), bounds.maxY(), bounds.maxZ())); mesh->_setBoundingSphereRadius(bounds.getRadius()); } + 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) + { + Nif::NiKeyframeDataPtr data = f->data; + std::cout << "Controller's Rtype:" << data->getRtype() << "Stype: " << data->getStype() << "Ttype:" << data->getTtype() << "\n"; + + if(first){ + + float end = f->timeStop; + //std::cout <<"Creating WholeThing" << end << "\n"; + + //TRANSLATION + if(!mSkel.isNull()){ + std::cout <<"Creating WholeThing" << end << "\n"; + animcore = mSkel->createAnimation("WholeThing", end); + //animcore->setInterpolationMode(Ogre::Animation::IM_SPLINE); + //animcore->setRotationInterpolationMode(Ogre::Animation::RIM_SPHERICAL); + //animcore2->setRotationInterpolationMode(Ogre::Animation::RIM_LINEAR); + + //ROTATION + animcore2 = mSkel->createAnimation("WholeThing2", end); + //animcore2->setInterpolationMode(Ogre::Animation::IM_SPLINE); + //animcore2->setRotationInterpolationMode(Ogre::Animation::RIM_SPHERICAL); + } + std::cout <<"AFTER"; + first = false; + } + if(animcore && animcore2){ + Nif::Named *node = dynamic_cast ( f->target.getPtr()); + std::cout << "The target rec: " << node->name.toString() << "\n"; + Ogre::NodeAnimationTrack* mTrack = animcore->createNodeTrack(handle, mSkel->getBone(node->name.toString())); + Ogre::NodeAnimationTrack* mTrack2 = animcore2->createNodeTrack(handle++, mSkel->getBone(node->name.toString())); + /* if (node->recType == RC_NiNode) + { + NodeList &list = ((NiNode*)node)->children; + int n = list.length(); + + for (int i = n; i<=n; i++) + { + if(skel->hasBone((list[i]).name.toString())) + mTrack3 = animcore2->createNodeTrack(handle++, skel->getBone((list[i]).name.toString())); + + } + }*/ + + std::vector quats = data->getQuat(); + std::vector::iterator quatIter = quats.begin(); + std::vector rtime = data->getrTime(); + std::vector::iterator rtimeiter = rtime.begin(); + + std::vector ttime = data->gettTime(); + std::vector::iterator ttimeiter = ttime.begin(); + std::vector translist1 = data->getTranslist1(); + std::vector::iterator transiter = translist1.begin(); + std::vector translist2 = data->getTranslist2(); + std::vector::iterator transiter2 = translist2.begin(); + std::vector translist3 = data->getTranslist3(); + std::vector::iterator transiter3 = translist3.begin(); + + + float tleft = 0; + float rleft = 0.0; + float ttotal = 0.0; + float rtotal = 0; + Ogre::TransformKeyFrame* mKey; + Ogre::TransformKeyFrame* mKey2; + float tused = 0.0; + float rused = 0.0; + Ogre::Quaternion lastquat; + Ogre::Vector3 lasttrans; + bool rend = false; + bool tend = false; + Ogre::Quaternion test;// = (skel->getBone(node->name.toString()))->getOrientation(); + for (int j = 0 ; j < ttime.size(); j++) + { + if(data->getTtype() >= 1 && data->getTtype() <= 5) + { + + Ogre::TransformKeyFrame* mKey = mTrack->createNodeKeyFrame(*ttimeiter); + Ogre::Vector3 standard = *transiter; + if(data->getTtype() == 2) + standard = *transiter * *transiter2 * *transiter3; + + mKey->setTranslate(standard);/* + if(mTrack3) + { + Ogre::TransformKeyFrame* mKey3 = mTrack->createNodeKeyFrame(*ttimeiter); + mKey3->setTranslate(standard); + }*/ + //mKey->setRotation(Quaternion::ZERO); + //mKey->setScale(Ogre::Vector3(1,1,1)); + transiter++; //START + transiter2++; + transiter3++; + ttimeiter++; + } + } + for (int j = 0 ; j < rtime.size(); j++) + { + if(data->getRtype() >= 1 && data->getRtype() <= 5) + { + Ogre::TransformKeyFrame* mKey2 = mTrack2->createNodeKeyFrame(*rtimeiter); + test = *quatIter; + + mKey2->setRotation(test); + //mKey2->setTranslate(Ogre::Vector3(0,0,0)); + //mKey2->setScale(Ogre::Vector3(1,1,1)); + quatIter++; + rtimeiter++; + } + } + } + + + + + /* + //mTrack = animcore->createNodeTrack(handle++, skel->getBone(node->name.toString())); + + std::vector stime = data->getsTime(); + std::vector::iterator stimeiter = stime.begin(); + + std::vector sfactor = data->getScalefactor(); + std::vector::iterator sfactoriter = sfactor.begin(); + for (int i = 0 ; i < stime.size(); i++) + { + if(data->getStype() >= 1 && data->getStype() <= 5) + { + Ogre::TransformKeyFrame* mKey = mTrack->createNodeKeyFrame(*stimeiter); + mKey->setScale(Ogre::Vector3(*sfactoriter, *sfactoriter, *sfactoriter)); + + sfactoriter++; + stimeiter++; + } + } + */ + + + } + /* + else if (n != NULL) + { + std::cout << "handle" << handle << "\n"; + //handle++; + }*/ + } + + + + // set skeleton + if (!mSkel.isNull()) + { + mesh->_notifySkeleton(mSkel); + } // set skeleton // if (!skel.isNull()) diff --git a/components/nifogre/ogre_nif_loader.hpp b/components/nifogre/ogre_nif_loader.hpp index 6ab22aa2f..a619d3a3b 100644 --- a/components/nifogre/ogre_nif_loader.hpp +++ b/components/nifogre/ogre_nif_loader.hpp @@ -131,6 +131,10 @@ class NIFLoader : Ogre::ManualResourceLoader int counter; int numbers; int stack; + bool anim; + int handle2; + Ogre::Animation* animcore; + Ogre::Animation* animcore2; // pointer to the ogre mesh which is currently build From 2ac1cc8aee28cf6d8975c36a49648e0a7e149676 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Wed, 13 Apr 2011 20:16:46 -0400 Subject: [PATCH 04/20] Trying to animate creatures --- apps/openmw/engine.cpp | 48 ++++++++++++++++++++++++++ components/esm_store/cell_store.hpp | 3 ++ components/nifogre/ogre_nif_loader.cpp | 13 +++---- 3 files changed, 55 insertions(+), 9 deletions(-) diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 78ddffbe8..a6cdd2838 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -7,6 +7,7 @@ #include #include +#include #include "components/esm/records.hpp" #include @@ -90,6 +91,53 @@ bool OMW::Engine::frameStarted(const Ogre::FrameEvent& evt) std::string effect; MWWorld::Ptr::CellStore *current = mEnvironment.mWorld->getPlayer().getPlayer().getCell(); + /* + ESMS::CellRefList::List creatureData = (current->creatures).list; + ESMS::CellRefList::List::iterator creaturedataiter = creatureData.begin(); + + for(int i = 0; i < creatureData.size(); i++) + { + //std::cout << "Testing" << i < "\n"; + ESMS::LiveCellRef item = *creaturedataiter; + Ogre::Entity* creaturemodel = item.model; + + if(evt.timeSinceLastFrame == 0) + creaturemodel->getSkeleton()->setBindingPose(); + creaturemodel->getSkeleton()->setBlendMode(Ogre::SkeletonAnimationBlendMode::ANIMBLEND_AVERAGE); //ANIMBLEND_AVERAGE + Ogre::AnimationState *mAnimationState = creaturemodel->getAnimationState("WholeThing"); + mAnimationState->setWeight(.5); + mAnimationState->setLoop(true); + //npcmodel->getSkeleton()-> + + mAnimationState->setEnabled(true); + + + + + Ogre::AnimationState *mAnimationState2 = creaturemodel->getAnimationState("WholeThing2"); + mAnimationState2->setLoop(true); + mAnimationState2->setWeight(.5); + mAnimationState2->setEnabled(true); + + mAnimationState2->createBlendMask(creaturemodel->getSkeleton()->getNumBones(),1); + mAnimationState->createBlendMask(creaturemodel->getSkeleton()->getNumBones(),1); + for(int j = 2; j < creaturemodel->getSkeleton()->getNumBones(); j++) + { + mAnimationState->setBlendMaskEntry(j,1); + mAnimationState2->setBlendMaskEntry(j,1); + } + // set skeleton + std::cout << "TimePosition:" << mAnimationState->getTimePosition() << "\n"; + + mAnimationState->addTime(evt.timeSinceLastFrame); + mAnimationState2->addTime(evt.timeSinceLastFrame); + //npcmodel->_updateAnimation(); + //mAnimationState2->setEnabled(true); + creaturedataiter++; + }*/ + + + //If the region has changed if(!(current->cell->data.flags & current->cell->Interior) && timer.elapsed() >= 10){ timer.restart(); diff --git a/components/esm_store/cell_store.hpp b/components/esm_store/cell_store.hpp index 43860dff3..a55bb3d0e 100644 --- a/components/esm_store/cell_store.hpp +++ b/components/esm_store/cell_store.hpp @@ -14,6 +14,7 @@ #include "components/esm/records.hpp" #include "components/esm/loadcell.hpp" #include +#include #include #include @@ -29,6 +30,8 @@ namespace ESMS // The object that this instance is based on. const X* base; + Ogre::Entity *model; + /* Information about this instance, such as 3D location and rotation and individual type-dependent data. */ diff --git a/components/nifogre/ogre_nif_loader.cpp b/components/nifogre/ogre_nif_loader.cpp index 3d63a9f98..a1254ed7f 100644 --- a/components/nifogre/ogre_nif_loader.cpp +++ b/components/nifogre/ogre_nif_loader.cpp @@ -1225,20 +1225,15 @@ void NIFLoader::loadResource(Resource *resource) } - /* - else if (n != NULL) - { - std::cout << "handle" << handle << "\n"; - //handle++; - }*/ + + //std::cout <"BE\n"; } - - // set skeleton - if (!mSkel.isNull()) + if (!mSkel.isNull() && mesh->isLoaded()) { mesh->_notifySkeleton(mSkel); + std::cout << "Skeleton notified\n"; } // set skeleton From 92509d3b70dd4f686caf8d9d9d449f86b258b125 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Wed, 13 Apr 2011 20:35:44 -0400 Subject: [PATCH 05/20] Trying to animate creatures --- apps/openmw/mwclass/creature.cpp | 2 +- apps/openmw/mwrender/cellimp.hpp | 2 ++ apps/openmw/mwrender/exterior.cpp | 15 +++++++++++++++ apps/openmw/mwrender/exterior.hpp | 2 ++ apps/openmw/mwrender/interior.cpp | 17 +++++++++++++++++ apps/openmw/mwrender/interior.hpp | 2 ++ 6 files changed, 39 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwclass/creature.cpp b/apps/openmw/mwclass/creature.cpp index 8cde67671..5316c8267 100644 --- a/apps/openmw/mwclass/creature.cpp +++ b/apps/openmw/mwclass/creature.cpp @@ -34,7 +34,7 @@ namespace MWClass if (!model.empty()) { MWRender::Rendering rendering (cellRender, ref->ref); - cellRender.insertMesh ("meshes\\" + model); + cellRender.insertMesh("meshes\\" + model); cellRender.insertActorPhysics(); ref->mData.setHandle (rendering.end (ref->mData.isEnabled())); } diff --git a/apps/openmw/mwrender/cellimp.hpp b/apps/openmw/mwrender/cellimp.hpp index 272bfeeab..727c9d317 100644 --- a/apps/openmw/mwrender/cellimp.hpp +++ b/apps/openmw/mwrender/cellimp.hpp @@ -7,6 +7,7 @@ #include "../mwworld/refdata.hpp" #include +#include namespace Ogre { @@ -42,6 +43,7 @@ namespace MWRender virtual void insertMesh(const std::string &mesh, Ogre::Vector3 vec, Ogre::Vector3 axis, Ogre::Radian angle, std::string sceneNodeName, std::string sceneParent[], int elements, bool translateFirst) = 0; virtual void insertMesh(const std::string &mesh, Ogre::Vector3 vec, Ogre::Vector3 axis, Ogre::Radian angle, std::string sceneNodeName, std::string sceneParent[], int elements) = 0; virtual void insertMesh(const std::string &mesh) = 0; + //virtual Ogre::Entity* insertAndDeliverMesh(const std::string &mesh) = 0; virtual void scaleMesh(Ogre::Vector3 axis, std::string sceneNodeName[], int elements) = 0; diff --git a/apps/openmw/mwrender/exterior.cpp b/apps/openmw/mwrender/exterior.cpp index fe54af84a..aa712dede 100644 --- a/apps/openmw/mwrender/exterior.cpp +++ b/apps/openmw/mwrender/exterior.cpp @@ -273,6 +273,21 @@ std::string ExteriorCellRender::insertEnd (bool enable) return handle; } +/* +Ogre::Entity* ExteriorCellRender::insertAndDeliverMesh(const std::string &mesh) +{ + assert (insert); + + NIFLoader::load(mesh); + Entity *ent = mScene.getMgr()->createEntity(mesh); + ent->setDisplaySkeleton(true); + + + mInsert->attachObject(ent); + return ent; + +}*/ + // configure lighting according to cell void ExteriorCellRender::configureAmbient() diff --git a/apps/openmw/mwrender/exterior.hpp b/apps/openmw/mwrender/exterior.hpp index 93491f263..87659a213 100644 --- a/apps/openmw/mwrender/exterior.hpp +++ b/apps/openmw/mwrender/exterior.hpp @@ -6,6 +6,7 @@ #include "OgreColourValue.h" #include +#include namespace Ogre { @@ -70,6 +71,7 @@ namespace MWRender virtual void insertMesh(const std::string &mesh, Ogre::Vector3 vec, Ogre::Vector3 axis, Ogre::Radian angle, std::string sceneNodeName, std::string sceneParent[], int elements, bool translateFirst); virtual void insertMesh(const std::string &mesh); + //virtual Ogre::Entity* insertAndDeliverMesh(const std::string &mesh); virtual void rotateMesh(Ogre::Vector3 axis, Ogre::Radian angle, std::string sceneNodeName[], int elements); virtual void scaleMesh(Ogre::Vector3 axis, std::string sceneNodeName[], int elements); diff --git a/apps/openmw/mwrender/interior.cpp b/apps/openmw/mwrender/interior.cpp index dbacaacf9..d3ec9b442 100644 --- a/apps/openmw/mwrender/interior.cpp +++ b/apps/openmw/mwrender/interior.cpp @@ -180,6 +180,23 @@ void InteriorCellRender::insertMesh(const std::string &mesh, Ogre::Vector3 vec, } } +/* +Ogre::Entity* InteriorCellRender::insertAndDeliverMesh(const std::string &mesh) +{ + + assert (insert); + + NIFLoader::load(mesh); + Entity *ent = scene.getMgr()->createEntity(mesh); + ent->setDisplaySkeleton(true); + + + insert->attachObject(ent); + return ent; + +}*/ + + void InteriorCellRender::insertMesh(const std::string &mesh) { assert (insert); diff --git a/apps/openmw/mwrender/interior.hpp b/apps/openmw/mwrender/interior.hpp index 7c4b2aaf1..f77d3358d 100644 --- a/apps/openmw/mwrender/interior.hpp +++ b/apps/openmw/mwrender/interior.hpp @@ -6,6 +6,7 @@ #include "OgreColourValue.h" #include +#include namespace Ogre { @@ -67,6 +68,7 @@ namespace MWRender virtual void rotateMesh(Ogre::Vector3 axis, Ogre::Radian angle, std::string sceneNodeName[], int elements); virtual void scaleMesh(Ogre::Vector3 axis, std::string sceneNodeName[], int elements); /// insert a mesh related to the most recent insertBegin call. + //virtual Ogre::Entity* insertAndDeliverMesh(const std::string &mesh); virtual void insertMesh(const std::string &mesh); virtual void insertMesh(const std::string &mesh, Ogre::Vector3 vec, Ogre::Vector3 axis, Ogre::Radian angle, std::string sceneNodeName, std::string sceneParent[], int elements); virtual void insertMesh(const std::string &mesh, Ogre::Vector3 vec, Ogre::Vector3 axis, Ogre::Radian angle, std::string sceneNodeName, std::string sceneParent[], int elements, bool translateFirst); From 51b74c2f053b87fedadf71136648e63831a73382 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Mon, 23 May 2011 19:01:36 -0400 Subject: [PATCH 06/20] starting --- apps/openmw/engine.cpp | 1 + apps/openmw/mwclass/npc.cpp | 2 ++ apps/openmw/mwrender/interior.cpp | 6 ++++-- components/bsa/bsa_archive.cpp | 6 ++++++ components/bsa/bsa_archive.hpp | 1 + components/files/multidircollection.hpp | 6 ++++-- 6 files changed, 18 insertions(+), 4 deletions(-) diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 244c63e51..6725497c1 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -296,6 +296,7 @@ void OMW::Engine::loadBSA() std::cout << "Adding " << iter->second.string() << std::endl; addBSA (iter->second.string()); } + } // add resources directory diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index bb5578f6d..2b5bbbc4d 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -118,6 +118,8 @@ namespace MWClass Ogre::Vector3 pos2 = Ogre::Vector3( 0, .5, 75); if (groin){ + cellRender.insertMesh("bald_MJ_hat.NIF"); //w/W_6th_Hammer.NIF + //bald_MJ_hat.NIF cellRender.insertMesh("meshes\\" + groin->model, pos2, axis, kOgrePi, npcName + "groin", addresses, numbers); addresses2[numbers] = npcName + "groin"; addresses[numbers++] = npcName + "groin"; diff --git a/apps/openmw/mwrender/interior.cpp b/apps/openmw/mwrender/interior.cpp index d3ec9b442..09cce2f6d 100644 --- a/apps/openmw/mwrender/interior.cpp +++ b/apps/openmw/mwrender/interior.cpp @@ -200,8 +200,10 @@ Ogre::Entity* InteriorCellRender::insertAndDeliverMesh(const std::string &mesh) void InteriorCellRender::insertMesh(const std::string &mesh) { assert (insert); - - NIFLoader::load(mesh); + //if(mesh == "\\Meshes\\bald_MJ_hat.NIF") + // NIFLoader::load(mesh, ""); + //else + NIFLoader::load(mesh); MovableObject *ent = scene.getMgr()->createEntity(mesh); insert->attachObject(ent); diff --git a/components/bsa/bsa_archive.cpp b/components/bsa/bsa_archive.cpp index 4691eb546..643845e25 100644 --- a/components/bsa/bsa_archive.cpp +++ b/components/bsa/bsa_archive.cpp @@ -145,6 +145,7 @@ public: void destroyInstance( Archive* arch) { delete arch; } }; + static bool init = false; static void insertBSAFactory() { @@ -163,3 +164,8 @@ void addBSA(const std::string& name, const std::string& group) ResourceGroupManager::getSingleton(). addResourceLocation(name, "BSA", group); } +void addDir(const std::string& name, const std::string& group) +{ + ResourceGroupManager::getSingleton(). + addResourceLocation(name, "FileSystem", group); +} diff --git a/components/bsa/bsa_archive.hpp b/components/bsa/bsa_archive.hpp index bde6d9c3b..91fd2fe98 100644 --- a/components/bsa/bsa_archive.hpp +++ b/components/bsa/bsa_archive.hpp @@ -29,5 +29,6 @@ /// Add the given BSA file as an input archive in the Ogre resource /// system. void addBSA(const std::string& file, const std::string& group="General"); +void addDir(const std::string& file, const std::string& group="General"); #endif diff --git a/components/files/multidircollection.hpp b/components/files/multidircollection.hpp index bd0304e40..3f9ddad84 100644 --- a/components/files/multidircollection.hpp +++ b/components/files/multidircollection.hpp @@ -4,6 +4,7 @@ #include #include #include +#include #include @@ -21,11 +22,12 @@ namespace Files return left Date: Fri, 3 Jun 2011 20:28:47 -0400 Subject: [PATCH 07/20] Introducing Dir Archive --- apps/openmw/engine.cpp | 24 ++++++++------- apps/openmw/mwclass/npc.cpp | 2 +- components/bsa/bsa_archive.cpp | 54 +++++++++++++++++++++++++++++++++- 3 files changed, 68 insertions(+), 12 deletions(-) diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 6725497c1..5c51ab513 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -111,16 +111,16 @@ bool OMW::Engine::frameRenderingQueued (const Ogre::FrameEvent& evt) mAnimationState->setLoop(true); //npcmodel->getSkeleton()-> - mAnimationState->setEnabled(true); - + mAnimationState->setEnabled(true); + + + - - Ogre::AnimationState *mAnimationState2 = creaturemodel->getAnimationState("WholeThing2"); mAnimationState2->setLoop(true); mAnimationState2->setWeight(.5); - mAnimationState2->setEnabled(true); - + mAnimationState2->setEnabled(true); + mAnimationState2->createBlendMask(creaturemodel->getSkeleton()->getNumBones(),1); mAnimationState->createBlendMask(creaturemodel->getSkeleton()->getNumBones(),1); for(int j = 2; j < creaturemodel->getSkeleton()->getNumBones(); j++) @@ -130,11 +130,11 @@ bool OMW::Engine::frameRenderingQueued (const Ogre::FrameEvent& evt) } // set skeleton std::cout << "TimePosition:" << mAnimationState->getTimePosition() << "\n"; - + mAnimationState->addTime(evt.timeSinceLastFrame); mAnimationState2->addTime(evt.timeSinceLastFrame); //npcmodel->_updateAnimation(); - //mAnimationState2->setEnabled(true); + //mAnimationState2->setEnabled(true); creaturedataiter++; }*/ @@ -297,6 +297,10 @@ void OMW::Engine::loadBSA() addBSA (iter->second.string()); } + std::string m = mDataDir.string(); + std::cout << "Data dir" << m << "\n"; + addDir(m); + } // add resources directory @@ -394,8 +398,8 @@ void OMW::Engine::go() mOgre.configure(!isFile(ogreCfg.c_str()), cfgUserDir, plugCfg, false); - addResourcesDirectory (mDataDir / "Meshes"); - addResourcesDirectory (mDataDir / "Textures"); + //addResourcesDirectory (mDataDir / "Meshes"); + //addResourcesDirectory (mDataDir / "Textures"); // This has to be added BEFORE MyGUI is initialized, as it needs // to find core.xml here. diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index 2b5bbbc4d..6fab8841a 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -118,7 +118,7 @@ namespace MWClass Ogre::Vector3 pos2 = Ogre::Vector3( 0, .5, 75); if (groin){ - cellRender.insertMesh("bald_MJ_hat.NIF"); //w/W_6th_Hammer.NIF + //cellRender.insertMesh("Meshes/bald_MJ_hat.NIF"); //w/W_6th_Hammer.NIF //bald_MJ_hat.NIF cellRender.insertMesh("meshes\\" + groin->model, pos2, axis, kOgrePi, npcName + "groin", addresses, numbers); addresses2[numbers] = npcName + "groin"; diff --git a/components/bsa/bsa_archive.cpp b/components/bsa/bsa_archive.cpp index 643845e25..552084c41 100644 --- a/components/bsa/bsa_archive.cpp +++ b/components/bsa/bsa_archive.cpp @@ -23,6 +23,7 @@ #include "bsa_archive.hpp" +#include #include #include #include @@ -33,6 +34,29 @@ using namespace Ogre; using namespace Mangle::Stream; /// An OGRE Archive wrapping a BSAFile archive +class DirArchive: public Ogre::FileSystemArchive +{ + //FileSystemArchive* arc; + public: + + DirArchive(const String& name) + : FileSystemArchive(name, "Dir") + { mType = "Dir";} + + bool isCaseSensitive() const { return false; } + + // The archive is loaded in the constructor, and never unloaded. + void load() {} + void unload() {} + + DataStreamPtr open(const String& filename, bool readonly = true) const + { + std::string copy = filename; + return FileSystemArchive::open(copy, readonly); + } + +}; + class BSAArchive : public Archive { BSAFile arc; @@ -145,8 +169,26 @@ public: void destroyInstance( Archive* arch) { delete arch; } }; +class DirArchiveFactory : public FileSystemArchiveFactory +{ +public: + const String& getType() const + { + static String name = "Dir"; + return name; + } + + Archive *createInstance( const String& name ) + { + return new DirArchive(name); + } + + void destroyInstance( Archive* arch) { delete arch; } +}; + static bool init = false; +static bool init2 = false; static void insertBSAFactory() { if(!init) @@ -156,6 +198,15 @@ static void insertBSAFactory() } } +static void insertDirFactory() +{ + if(!init2) + { + ArchiveManager::getSingleton().addArchiveFactory( new DirArchiveFactory ); + init = true; + } +} + // The function below is the only publicly exposed part of this file void addBSA(const std::string& name, const std::string& group) @@ -166,6 +217,7 @@ void addBSA(const std::string& name, const std::string& group) } void addDir(const std::string& name, const std::string& group) { + insertDirFactory(); ResourceGroupManager::getSingleton(). - addResourceLocation(name, "FileSystem", group); + addResourceLocation(name, "Dir", group); } From 2aaa0f4578976fb09c05a2cfa1a70a777ad33806 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Sat, 4 Jun 2011 01:29:57 -0400 Subject: [PATCH 08/20] Backslash working in linux --- apps/openmw/engine.cpp | 2 ++ apps/openmw/mwclass/npc.cpp | 2 +- components/bsa/bsa_archive.cpp | 24 ++++++++++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 5c51ab513..a899a5aea 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -300,6 +300,8 @@ void OMW::Engine::loadBSA() std::string m = mDataDir.string(); std::cout << "Data dir" << m << "\n"; addDir(m); + //std::string s = "f\n"; + //std::cout <<"S: " << s.size() << "\n"; } diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index 6fab8841a..c6d092253 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -118,7 +118,7 @@ namespace MWClass Ogre::Vector3 pos2 = Ogre::Vector3( 0, .5, 75); if (groin){ - //cellRender.insertMesh("Meshes/bald_MJ_hat.NIF"); //w/W_6th_Hammer.NIF + cellRender.insertMesh("Meshes\\bald_MJ_hat.NIF"); //w/W_6th_Hammer.NIF //bald_MJ_hat.NIF cellRender.insertMesh("meshes\\" + groin->model, pos2, axis, kOgrePi, npcName + "groin", addresses, numbers); addresses2[numbers] = npcName + "groin"; diff --git a/components/bsa/bsa_archive.cpp b/components/bsa/bsa_archive.cpp index 552084c41..93bde48e3 100644 --- a/components/bsa/bsa_archive.cpp +++ b/components/bsa/bsa_archive.cpp @@ -49,9 +49,33 @@ class DirArchive: public Ogre::FileSystemArchive void load() {} void unload() {} + bool exists(const String& filename) { + std::string copy = filename; + if(OGRE_PLATFORM != OGRE_PLATFORM_WIN32) + { + + for (int i = 0; i < filename.size(); i++) + { + if(copy.at(i) == '\\' ){ + copy.replace(i, 1, "/"); + } + } + } + return FileSystemArchive::exists(copy); + } + DataStreamPtr open(const String& filename, bool readonly = true) const { std::string copy = filename; + if(OGRE_PLATFORM != OGRE_PLATFORM_WIN32){ + //std::cout << "In Open\n"; + for (int i = 0; i < filename.size(); i++) + { + if(copy.at(i) == '\\' ){ + copy.replace(i, 1, "/"); + } + } + } return FileSystemArchive::open(copy, readonly); } From f2a0fa8af2f08e21fe7abf988660ededa8d6524e Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Sun, 5 Jun 2011 23:46:18 -0400 Subject: [PATCH 09/20] Adding files to directory map --- apps/openmw/mwclass/npc.cpp | 2 +- components/bsa/bsa_archive.cpp | 58 ++++++++++++++++++++++++++++++++-- components/bsa/bsa_archive.hpp | 1 + 3 files changed, 57 insertions(+), 4 deletions(-) diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index c6d092253..6a186b92e 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -118,7 +118,7 @@ namespace MWClass Ogre::Vector3 pos2 = Ogre::Vector3( 0, .5, 75); if (groin){ - cellRender.insertMesh("Meshes\\bald_MJ_hat.NIF"); //w/W_6th_Hammer.NIF + cellRender.insertMesh("Meshes\\joker\\bald_MJ_hat.nif"); //w/W_6th_Hammer.NIF //bald_MJ_hat.NIF cellRender.insertMesh("meshes\\" + groin->model, pos2, axis, kOgrePi, npcName + "groin", addresses, numbers); addresses2[numbers] = npcName + "groin"; diff --git a/components/bsa/bsa_archive.cpp b/components/bsa/bsa_archive.cpp index 93bde48e3..5b5ff6511 100644 --- a/components/bsa/bsa_archive.cpp +++ b/components/bsa/bsa_archive.cpp @@ -36,12 +36,42 @@ using namespace Mangle::Stream; /// An OGRE Archive wrapping a BSAFile archive class DirArchive: public Ogre::FileSystemArchive { - //FileSystemArchive* arc; + + boost::filesystem::path currentdir; + std::map > m; + public: DirArchive(const String& name) : FileSystemArchive(name, "Dir") - { mType = "Dir";} + { mType = "Dir"; + currentdir = name; + + populateMap(currentdir); + + } + void populateMap(boost::filesystem::path d){ + //need to cut off first + boost::filesystem::directory_iterator dir_iter(d), dir_end; + std::vector filesind; + boost::filesystem::path f; + for(;dir_iter != dir_end; dir_iter++) + { + if(boost::filesystem::is_directory(*dir_iter)) + populateMap(*dir_iter); + else + { + + f = *dir_iter; + std::string s = f.string(); + filesind.push_back(s); + //std::cout << "File: " << s << "\n"; + } + } + m[d.string()] = filesind; + std::cout << "Directory: " << d.string() << filesind.size() << "\n"; + + } bool isCaseSensitive() const { return false; } @@ -50,6 +80,11 @@ class DirArchive: public Ogre::FileSystemArchive void unload() {} bool exists(const String& filename) { + //String s = filename; + //FileSystemArchive::findFiles(s, true, false, filenames.getPointer(), f.getPointer()); + // std::cout << "Filenames" << filenames.useCount() << "\n"; + + std::string copy = filename; if(OGRE_PLATFORM != OGRE_PLATFORM_WIN32) { @@ -61,6 +96,23 @@ class DirArchive: public Ogre::FileSystemArchive } } } + boost::filesystem::path p = copy; + + int last = copy.size() - 1; + int i = last; + + for (;last >= 0; i--) + { + if(copy.at(i) == '/' || copy.at(i) == '\\') + break; + } + std::string folder; + + folder = copy.substr(0, i); + + boost::filesystem::path folderpath = folder; + std::cout << "\nFull:" << p.string() << "\n"<< "Part:" << folderpath.string(); + return FileSystemArchive::exists(copy); } @@ -227,7 +279,7 @@ static void insertDirFactory() if(!init2) { ArchiveManager::getSingleton().addArchiveFactory( new DirArchiveFactory ); - init = true; + init2 = true; } } diff --git a/components/bsa/bsa_archive.hpp b/components/bsa/bsa_archive.hpp index 91fd2fe98..405856e8c 100644 --- a/components/bsa/bsa_archive.hpp +++ b/components/bsa/bsa_archive.hpp @@ -22,6 +22,7 @@ */ #include +#include #ifndef _BSA_ARCHIVE_H_ #define _BSA_ARCHIVE_H_ From 45453fd7a95276c69479484f8a74d2d4541b1538 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Mon, 6 Jun 2011 20:11:23 -0400 Subject: [PATCH 10/20] Case insensitive external loader working --- apps/openmw/mwclass/npc.cpp | 2 +- components/bsa/bsa_archive.cpp | 101 +++++++++++++++++++++++++++++---- components/bsa/bsa_archive.hpp | 2 + 3 files changed, 93 insertions(+), 12 deletions(-) diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index 6a186b92e..8eaa9d614 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -118,7 +118,7 @@ namespace MWClass Ogre::Vector3 pos2 = Ogre::Vector3( 0, .5, 75); if (groin){ - cellRender.insertMesh("Meshes\\joker\\bald_MJ_hat.nif"); //w/W_6th_Hammer.NIF + cellRender.insertMesh("MeSHes\\1\\red_MJ_hat_org.NIF"); //w/W_6th_Hammer.NIF //bald_MJ_hat.NIF cellRender.insertMesh("meshes\\" + groin->model, pos2, axis, kOgrePi, npcName + "groin", addresses, numbers); addresses2[numbers] = npcName + "groin"; diff --git a/components/bsa/bsa_archive.cpp b/components/bsa/bsa_archive.cpp index 5b5ff6511..13858d405 100644 --- a/components/bsa/bsa_archive.cpp +++ b/components/bsa/bsa_archive.cpp @@ -33,12 +33,21 @@ using namespace Ogre; using namespace Mangle::Stream; +struct ciLessBoost : std::binary_function +{ + bool operator() (const std::string & s1, const std::string & s2) const { + //case insensitive version of is_less + return lexicographical_compare(s1, s2, boost::algorithm::is_iless()); + } +}; + /// An OGRE Archive wrapping a BSAFile archive class DirArchive: public Ogre::FileSystemArchive { boost::filesystem::path currentdir; - std::map > m; + std::map, ciLessBoost> m; + int cutoff; public: @@ -46,6 +55,9 @@ class DirArchive: public Ogre::FileSystemArchive : FileSystemArchive(name, "Dir") { mType = "Dir"; currentdir = name; + std::string s = name; + cutoff = s.size() + 1; + //std::cout << "Cut off:" << cutoff; populateMap(currentdir); @@ -64,12 +76,26 @@ class DirArchive: public Ogre::FileSystemArchive f = *dir_iter; std::string s = f.string(); - filesind.push_back(s); - //std::cout << "File: " << s << "\n"; + + std::string small; + if(cutoff < s.size()) + small = s.substr(cutoff, s.size() - cutoff); + else + small = s.substr(cutoff - 1, s.size() - cutoff); + + filesind.push_back(small); + //std::cout << "File: " << small << "f\n"; } } - m[d.string()] = filesind; - std::cout << "Directory: " << d.string() << filesind.size() << "\n"; + std::string small; + std::string original = d.string(); + if(cutoff < original.size()) + small = original.substr(cutoff, original.size() - cutoff); + else + small = original.substr(cutoff - 1, original.size() - cutoff); + boost::filesystem::path smallp = small; + m[smallp.string()] = filesind; + //std::cout << "Directory: " << smallp.string() << " " << filesind.size() << "\n"; } @@ -80,6 +106,7 @@ class DirArchive: public Ogre::FileSystemArchive void unload() {} bool exists(const String& filename) { + //std::cout << "exists\n"; //String s = filename; //FileSystemArchive::findFiles(s, true, false, filenames.getPointer(), f.getPointer()); // std::cout << "Filenames" << filenames.useCount() << "\n"; @@ -106,21 +133,40 @@ class DirArchive: public Ogre::FileSystemArchive if(copy.at(i) == '/' || copy.at(i) == '\\') break; } - std::string folder; - folder = copy.substr(0, i); + std::string file = copy.substr(i + 1, copy.size() - i); //filename with no slash + std::string folder = copy.substr(0, i); //folder with no slash + std::transform(file.begin(), file.end(), file.begin(), tolower); boost::filesystem::path folderpath = folder; - std::cout << "\nFull:" << p.string() << "\n"<< "Part:" << folderpath.string(); + std::vector current = m[folderpath.string()]; + + for(std::vector::iterator iter = current.begin(); iter != current.end(); iter++) + { + std::string loopfile = iter->substr(i + 1, copy.size() - i); //filename with no slash + std::transform(loopfile.begin(), loopfile.end(), loopfile.begin(), tolower); + if(file.compare(loopfile) == 0){ + std::cout << "Loopfile:" << loopfile << "\n"; + return FileSystemArchive::exists(*iter); + } + } + + //std::cout << "Filename:" << file << "\n"; + //std::cout << "Full:" << p.string() << "\n"; + //std::cout << "Current:" << folder << "size: " << current.size() << "\n"; + //std::cout << "\nFull:" << p.string() << "\n"<< "Part:" << folderpath.string(); return FileSystemArchive::exists(copy); } DataStreamPtr open(const String& filename, bool readonly = true) const { - std::string copy = filename; - if(OGRE_PLATFORM != OGRE_PLATFORM_WIN32){ - //std::cout << "In Open\n"; + std::map, ciLessBoost> mlocal = m; + //std::cout << "Open\n"; + std::string copy = filename; + if(OGRE_PLATFORM != OGRE_PLATFORM_WIN32) + { + for (int i = 0; i < filename.size(); i++) { if(copy.at(i) == '\\' ){ @@ -128,6 +174,39 @@ class DirArchive: public Ogre::FileSystemArchive } } } + boost::filesystem::path p = copy; + + int last = copy.size() - 1; + int i = last; + + for (;last >= 0; i--) + { + if(copy.at(i) == '/' || copy.at(i) == '\\') + break; + } + + std::string file = copy.substr(i + 1, copy.size() - i); //filename with no slash + std::string folder = copy.substr(0, i); //folder with no slash + + std::transform(file.begin(), file.end(), file.begin(), tolower); + boost::filesystem::path folderpath = folder; + std::vector current = mlocal[folderpath.string()]; + + for(std::vector::iterator iter = current.begin(); iter != current.end(); iter++) + { + std::string loopfile = iter->substr(i + 1, copy.size() - i); //filename with no slash + std::transform(loopfile.begin(), loopfile.end(), loopfile.begin(), tolower); + if(file.compare(loopfile) == 0){ + std::cout << "Loopfile:" << loopfile << "\n"; + return FileSystemArchive::open(*iter, readonly); + } + } + + //std::cout << "Filename:" << file << "\n"; + //std::cout << "Full:" << p.string() << "\n"; + //std::cout << "Current:" << folder << "size: " << current.size() << "\n"; + //std::cout << "\nFull:" << p.string() << "\n"<< "Part:" << folderpath.string(); + return FileSystemArchive::open(copy, readonly); } diff --git a/components/bsa/bsa_archive.hpp b/components/bsa/bsa_archive.hpp index 405856e8c..a72f638e3 100644 --- a/components/bsa/bsa_archive.hpp +++ b/components/bsa/bsa_archive.hpp @@ -23,6 +23,8 @@ #include #include +#include +#include #ifndef _BSA_ARCHIVE_H_ #define _BSA_ARCHIVE_H_ From 4d31ca2c865f84883692077951b539bec7ecc99f Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Tue, 7 Jun 2011 17:17:25 -0400 Subject: [PATCH 11/20] Leading slashes now work, efficiency changes --- apps/openmw/mwclass/npc.cpp | 2 +- components/bsa/bsa_archive.cpp | 80 ++++++++++++++++++++++++---------- 2 files changed, 57 insertions(+), 25 deletions(-) diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index 8eaa9d614..285da5c5a 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -118,7 +118,7 @@ namespace MWClass Ogre::Vector3 pos2 = Ogre::Vector3( 0, .5, 75); if (groin){ - cellRender.insertMesh("MeSHes\\1\\red_MJ_hat_org.NIF"); //w/W_6th_Hammer.NIF + cellRender.insertMesh("MeSHes\\1\\red_MJ_hat_org.NIf"); //w/W_6th_Hammer.NIF //bald_MJ_hat.NIF cellRender.insertMesh("meshes\\" + groin->model, pos2, axis, kOgrePi, npcName + "groin", addresses, numbers); addresses2[numbers] = npcName + "groin"; diff --git a/components/bsa/bsa_archive.cpp b/components/bsa/bsa_archive.cpp index 13858d405..ba7be5bfd 100644 --- a/components/bsa/bsa_archive.cpp +++ b/components/bsa/bsa_archive.cpp @@ -49,6 +49,18 @@ class DirArchive: public Ogre::FileSystemArchive std::map, ciLessBoost> m; int cutoff; + bool comparePortion(std::string file1, std::string file2, int start, int size) const + { + for(int i = start; i < start+size; i++) + { + char one = file1.at(i); + char two = file2.at(i); + if(tolower(one) != tolower(two) ) + return false; + } + return true; + } + public: DirArchive(const String& name) @@ -93,8 +105,8 @@ class DirArchive: public Ogre::FileSystemArchive small = original.substr(cutoff, original.size() - cutoff); else small = original.substr(cutoff - 1, original.size() - cutoff); - boost::filesystem::path smallp = small; - m[smallp.string()] = filesind; + //boost::filesystem::path smallp = small; + m[small] = filesind; //std::cout << "Directory: " << smallp.string() << " " << filesind.size() << "\n"; } @@ -113,6 +125,7 @@ class DirArchive: public Ogre::FileSystemArchive std::string copy = filename; + if(OGRE_PLATFORM != OGRE_PLATFORM_WIN32) { @@ -123,7 +136,17 @@ class DirArchive: public Ogre::FileSystemArchive } } } - boost::filesystem::path p = copy; + + if(copy.at(0) == '\\' || copy.at(0) == '/') + { + //std::cout << "Before:" << copy.size() << "\n"; + copy.erase(0, 1); + //std::cout << "The copy" << copy << "\n"; + //std::cout << "After:" << copy.size(); + } + + + //boost::filesystem::path p = copy; int last = copy.size() - 1; int i = last; @@ -134,19 +157,20 @@ class DirArchive: public Ogre::FileSystemArchive break; } - std::string file = copy.substr(i + 1, copy.size() - i); //filename with no slash + //std::string file = copy.substr(i + 1, copy.size() - i); //filename with no slash std::string folder = copy.substr(0, i); //folder with no slash - std::transform(file.begin(), file.end(), file.begin(), tolower); - boost::filesystem::path folderpath = folder; - std::vector current = m[folderpath.string()]; + //std::transform(file.begin(), file.end(), file.begin(), tolower); + //boost::filesystem::path folderpath = folder; + std::vector current = m[folder]; for(std::vector::iterator iter = current.begin(); iter != current.end(); iter++) { - std::string loopfile = iter->substr(i + 1, copy.size() - i); //filename with no slash - std::transform(loopfile.begin(), loopfile.end(), loopfile.begin(), tolower); - if(file.compare(loopfile) == 0){ - std::cout << "Loopfile:" << loopfile << "\n"; + //std::string loopfile = iter->substr(i + 1, copy.size() - i); //filename with no slash + //std::transform(loopfile.begin(), loopfile.end(), loopfile.begin(), tolower); + //std::string now = *iter; + if(comparePortion(*iter, copy, i + 1, copy.size() - i -1) == true){ + //std::cout << "Loopfile:" << copy << "\n"; return FileSystemArchive::exists(*iter); } } @@ -156,7 +180,7 @@ class DirArchive: public Ogre::FileSystemArchive //std::cout << "Current:" << folder << "size: " << current.size() << "\n"; //std::cout << "\nFull:" << p.string() << "\n"<< "Part:" << folderpath.string(); - return FileSystemArchive::exists(copy); + return false;//FileSystemArchive::exists(copy); } DataStreamPtr open(const String& filename, bool readonly = true) const @@ -164,6 +188,7 @@ class DirArchive: public Ogre::FileSystemArchive std::map, ciLessBoost> mlocal = m; //std::cout << "Open\n"; std::string copy = filename; + if(OGRE_PLATFORM != OGRE_PLATFORM_WIN32) { @@ -174,7 +199,15 @@ class DirArchive: public Ogre::FileSystemArchive } } } - boost::filesystem::path p = copy; + + if(copy.at(0) == '\\' || copy.at(0) == '/') + { + //std::cout << "Before:" << copy.size() << "\n"; + copy.erase(0, 1); + //std::cout << "The copy" << copy << "\n"; + //std::cout << "After:" << copy.size(); + } + //boost::filesystem::path p = copy; int last = copy.size() - 1; int i = last; @@ -185,19 +218,18 @@ class DirArchive: public Ogre::FileSystemArchive break; } - std::string file = copy.substr(i + 1, copy.size() - i); //filename with no slash - std::string folder = copy.substr(0, i); //folder with no slash + std::string folder = copy.substr(0, i); //folder with no slash //folder with no slash - std::transform(file.begin(), file.end(), file.begin(), tolower); - boost::filesystem::path folderpath = folder; - std::vector current = mlocal[folderpath.string()]; + //std::transform(file.begin(), file.end(), file.begin(), tolower); + //boost::filesystem::path folderpath = folder; + std::vector current = mlocal[folder]; for(std::vector::iterator iter = current.begin(); iter != current.end(); iter++) { - std::string loopfile = iter->substr(i + 1, copy.size() - i); //filename with no slash - std::transform(loopfile.begin(), loopfile.end(), loopfile.begin(), tolower); - if(file.compare(loopfile) == 0){ - std::cout << "Loopfile:" << loopfile << "\n"; + //std::string loopfile = iter->substr(i + 1, copy.size() - i); //filename with no slash + //std::transform(loopfile.begin(), loopfile.end(), loopfile.begin(), tolower); + if(comparePortion(*iter, copy, i + 1, copy.size() - i -1) == true){ + //std::cout << "Loopfile:" << copy << "\n"; return FileSystemArchive::open(*iter, readonly); } } @@ -206,8 +238,8 @@ class DirArchive: public Ogre::FileSystemArchive //std::cout << "Full:" << p.string() << "\n"; //std::cout << "Current:" << folder << "size: " << current.size() << "\n"; //std::cout << "\nFull:" << p.string() << "\n"<< "Part:" << folderpath.string(); - - return FileSystemArchive::open(copy, readonly); + DataStreamPtr p; + return p;//FileSystemArchive::open(copy, readonly); } }; From d59856af5c98d993e56a5c1dbb75b9f08cd177d4 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Wed, 8 Jun 2011 00:52:25 +0200 Subject: [PATCH 12/20] minor performance improvement --- components/bsa/bsa_archive.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/bsa/bsa_archive.cpp b/components/bsa/bsa_archive.cpp index ba7be5bfd..68c47a0ed 100644 --- a/components/bsa/bsa_archive.cpp +++ b/components/bsa/bsa_archive.cpp @@ -162,7 +162,7 @@ class DirArchive: public Ogre::FileSystemArchive //std::transform(file.begin(), file.end(), file.begin(), tolower); //boost::filesystem::path folderpath = folder; - std::vector current = m[folder]; + std::vector& current = m[folder]; for(std::vector::iterator iter = current.begin(); iter != current.end(); iter++) { From a719a6b46824d2d5e91c15a79ab1bf42b3b23194 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Tue, 7 Jun 2011 18:57:24 -0400 Subject: [PATCH 13/20] Getting rid of animation code in nif loader --- components/nifogre/ogre_nif_loader.cpp | 207 ++++--------------------- 1 file changed, 31 insertions(+), 176 deletions(-) diff --git a/components/nifogre/ogre_nif_loader.cpp b/components/nifogre/ogre_nif_loader.cpp index a1254ed7f..8219a224c 100644 --- a/components/nifogre/ogre_nif_loader.cpp +++ b/components/nifogre/ogre_nif_loader.cpp @@ -81,11 +81,11 @@ Vector3 NIFLoader::convertVector3(const Nif::Vector& vec) Quaternion NIFLoader::convertRotation(const Nif::Matrix& rot) { Real matrix[3][3]; - + for (int i=0; i<3; i++) for (int j=0; j<3; j++) matrix[i][j] = rot.v[i].array[j]; - + return Quaternion(Matrix3(matrix)); } @@ -265,7 +265,7 @@ void NIFLoader::createMaterial(const String &name, } else pass->setDepthWriteEnabled(true); */ - + // Add transparency if NiAlphaProperty was present if (alphaFlags != -1) @@ -346,16 +346,16 @@ void NIFLoader::createOgreSubMesh(NiTriShape *shape, const String &material, std sub->vertexData = new VertexData(); sub->vertexData->vertexCount = numVerts; sub->useSharedVertices = false; - + VertexDeclaration *decl = sub->vertexData->vertexDeclaration; decl->addElement(nextBuf, 0, VET_FLOAT3, VES_POSITION); - + HardwareVertexBufferSharedPtr vbuf = HardwareBufferManager::getSingleton().createVertexBuffer( VertexElement::getTypeSize(VET_FLOAT3), numVerts, HardwareBuffer::HBU_STATIC_WRITE_ONLY); vbuf->writeData(0, vbuf->getSizeInBytes(), data->vertices.ptr, true); - + VertexBufferBinding* bind = sub->vertexData->vertexBufferBinding; bind->setBinding(nextBuf++, vbuf); @@ -673,7 +673,7 @@ void NIFLoader::handleNiTriShape(NiTriShape *shape, int flags, BoundsFinder &bou if (verIndex < data->normals.length) { Vector3 absNormalsPos = vecRot * Vector3(ptrNormals + verIndex *3); - + for (int j=0; j<3; j++) (ptrNormals + verIndex*3)[j] = absNormalsPos[j]; } @@ -833,7 +833,7 @@ void NIFLoader::handleNode(Nif::Node *node, int flags, } for (; itrafo, bounds, bone); } @@ -848,7 +848,7 @@ void NIFLoader::handleNode(Nif::Node *node, int flags, Tri Chest */ if((isChest && stack < 10 ) || (isHands && counter < 3) || !(isChest || isHands)){ //(isBeast && isChest && stack < 10 && counter == skincounter ) - + std::string name = node->name.toString(); //if (isChest) //std::cout << "NAME: " << name << "\n"; @@ -875,15 +875,15 @@ void NIFLoader::handleNode(Nif::Node *node, int flags, //if(isBeast && isChest) //cout << "Handling Shape, Stack " << stack <<"\n"; - - + + counter++; } /*if(isHands){ //cout << "Handling Shape, Stack " << stack <<"\n"; counter++; }*/ - + } stack--; @@ -904,7 +904,7 @@ void NIFLoader::loadResource(Resource *resource) //std::cout <<"NAME:" << name; //if(name.length() >= 20) // {std::string split = name.substr(name.length() - 20, 20); - //if(name == + //if(name == //std::cout <<"NAME:" << name << "LEN: " << name.length() << "\n"; const std::string test ="meshes\\b\\B_N_Dark Elf_M_Skins.NIF"; const std::string test2 ="meshes\\b\\B_N_Dark Elf_M_Skins.nif"; @@ -932,15 +932,15 @@ void NIFLoader::loadResource(Resource *resource) const std::string test24 ="meshes\\b\\B_N_High Elf_M_Skins.nif"; //std::cout <<"LEN1:" << test.length() << "TEST: " << test << "\n"; - - + + if(name.compare(test) == 0 || name.compare(test2) == 0 || name.compare(test3) == 0 || name.compare(test4) == 0 || name.compare(test5) == 0 || name.compare(test6) == 0 || name.compare(test7) == 0 || name.compare(test8) == 0 || name.compare(test9) == 0 || name.compare(test10) == 0 || name.compare(test11) == 0 || name.compare(test12) == 0 || name.compare(test13) == 0 || name.compare(test14) == 0 || name.compare(test15) == 0 || name.compare(test16) == 0 || name.compare(test17) == 0 || name.compare(test18) == 0 || name.compare(test19) == 0 || name.compare(test20) == 0 || name.compare(test21) == 0 || name.compare(test22) == 0 || name.compare(test23) == 0 || name.compare(test24) == 0 - + ){ //std::cout << "Welcome Chest\n"; isChest = true; @@ -1009,7 +1009,7 @@ void NIFLoader::loadResource(Resource *resource) std::cout << "\n\n\nWelcome FRedguard Chest\n\n\n"; isChest = true; }*/ - + //if(split== "Skins.NIF") // std::cout << "\nSPECIAL PROPS\n"; resourceName = ""; @@ -1072,7 +1072,7 @@ void NIFLoader::loadResource(Resource *resource) short handle = 0; //skel->setBlendMode(Ogre::SkeletonAnimationBlendMode::ANIMBLEND_CUMULATIVE); bool first = true; - + // set the bounding value. if (bounds.isValid()) { @@ -1080,155 +1080,10 @@ void NIFLoader::loadResource(Resource *resource) bounds.maxX(), bounds.maxY(), bounds.maxZ())); mesh->_setBoundingSphereRadius(bounds.getRadius()); } - 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) - { - Nif::NiKeyframeDataPtr data = f->data; - std::cout << "Controller's Rtype:" << data->getRtype() << "Stype: " << data->getStype() << "Ttype:" << data->getTtype() << "\n"; - - if(first){ - - float end = f->timeStop; - //std::cout <<"Creating WholeThing" << end << "\n"; - - //TRANSLATION - if(!mSkel.isNull()){ - std::cout <<"Creating WholeThing" << end << "\n"; - animcore = mSkel->createAnimation("WholeThing", end); - //animcore->setInterpolationMode(Ogre::Animation::IM_SPLINE); - //animcore->setRotationInterpolationMode(Ogre::Animation::RIM_SPHERICAL); - //animcore2->setRotationInterpolationMode(Ogre::Animation::RIM_LINEAR); - - //ROTATION - animcore2 = mSkel->createAnimation("WholeThing2", end); - //animcore2->setInterpolationMode(Ogre::Animation::IM_SPLINE); - //animcore2->setRotationInterpolationMode(Ogre::Animation::RIM_SPHERICAL); - } - std::cout <<"AFTER"; - first = false; - } - if(animcore && animcore2){ - Nif::Named *node = dynamic_cast ( f->target.getPtr()); - std::cout << "The target rec: " << node->name.toString() << "\n"; - Ogre::NodeAnimationTrack* mTrack = animcore->createNodeTrack(handle, mSkel->getBone(node->name.toString())); - Ogre::NodeAnimationTrack* mTrack2 = animcore2->createNodeTrack(handle++, mSkel->getBone(node->name.toString())); - /* if (node->recType == RC_NiNode) - { - NodeList &list = ((NiNode*)node)->children; - int n = list.length(); - - for (int i = n; i<=n; i++) - { - if(skel->hasBone((list[i]).name.toString())) - mTrack3 = animcore2->createNodeTrack(handle++, skel->getBone((list[i]).name.toString())); - - } - }*/ - - std::vector quats = data->getQuat(); - std::vector::iterator quatIter = quats.begin(); - std::vector rtime = data->getrTime(); - std::vector::iterator rtimeiter = rtime.begin(); - - std::vector ttime = data->gettTime(); - std::vector::iterator ttimeiter = ttime.begin(); - std::vector translist1 = data->getTranslist1(); - std::vector::iterator transiter = translist1.begin(); - std::vector translist2 = data->getTranslist2(); - std::vector::iterator transiter2 = translist2.begin(); - std::vector translist3 = data->getTranslist3(); - std::vector::iterator transiter3 = translist3.begin(); - - - float tleft = 0; - float rleft = 0.0; - float ttotal = 0.0; - float rtotal = 0; - Ogre::TransformKeyFrame* mKey; - Ogre::TransformKeyFrame* mKey2; - float tused = 0.0; - float rused = 0.0; - Ogre::Quaternion lastquat; - Ogre::Vector3 lasttrans; - bool rend = false; - bool tend = false; - Ogre::Quaternion test;// = (skel->getBone(node->name.toString()))->getOrientation(); - for (int j = 0 ; j < ttime.size(); j++) - { - if(data->getTtype() >= 1 && data->getTtype() <= 5) - { - - Ogre::TransformKeyFrame* mKey = mTrack->createNodeKeyFrame(*ttimeiter); - Ogre::Vector3 standard = *transiter; - if(data->getTtype() == 2) - standard = *transiter * *transiter2 * *transiter3; - - mKey->setTranslate(standard);/* - if(mTrack3) - { - Ogre::TransformKeyFrame* mKey3 = mTrack->createNodeKeyFrame(*ttimeiter); - mKey3->setTranslate(standard); - }*/ - //mKey->setRotation(Quaternion::ZERO); - //mKey->setScale(Ogre::Vector3(1,1,1)); - transiter++; //START - transiter2++; - transiter3++; - ttimeiter++; - } - } - for (int j = 0 ; j < rtime.size(); j++) - { - if(data->getRtype() >= 1 && data->getRtype() <= 5) - { - Ogre::TransformKeyFrame* mKey2 = mTrack2->createNodeKeyFrame(*rtimeiter); - test = *quatIter; - - mKey2->setRotation(test); - //mKey2->setTranslate(Ogre::Vector3(0,0,0)); - //mKey2->setScale(Ogre::Vector3(1,1,1)); - quatIter++; - rtimeiter++; - } - } - } - - - - - /* - //mTrack = animcore->createNodeTrack(handle++, skel->getBone(node->name.toString())); - - std::vector stime = data->getsTime(); - std::vector::iterator stimeiter = stime.begin(); - - std::vector sfactor = data->getScalefactor(); - std::vector::iterator sfactoriter = sfactor.begin(); - for (int i = 0 ; i < stime.size(); i++) - { - if(data->getStype() >= 1 && data->getStype() <= 5) - { - Ogre::TransformKeyFrame* mKey = mTrack->createNodeKeyFrame(*stimeiter); - mKey->setScale(Ogre::Vector3(*sfactoriter, *sfactoriter, *sfactoriter)); - - sfactoriter++; - stimeiter++; - } - } - */ - - - } - - //std::cout <"BE\n"; - } - + + + + // set skeleton if (!mSkel.isNull() && mesh->isLoaded()) { @@ -1241,14 +1096,14 @@ void NIFLoader::loadResource(Resource *resource) // mesh->setSkeletonName(getSkeletonName()); } -MeshPtr NIFLoader::load(const std::string &name, +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); MeshPtr resize; - + const std::string beast1 ="meshes\\b\\B_N_Khajiit_F_Skins.nif"; const std::string beast2 ="meshes\\b\\B_N_Khajiit_M_Skins.nif"; const std::string beast3 ="meshes\\b\\B_N_Argonian_F_Skins.nif"; @@ -1259,8 +1114,8 @@ MeshPtr NIFLoader::load(const std::string &name, const std::string beasttail3 ="tail\\b\\B_N_Argonian_F_Skins.nif"; const std::string beasttail4 ="tail\\b\\B_N_Argonian_M_Skins.nif"; - if (!ptr.isNull()){ - + if (!ptr.isNull()){ + //if(pieces > 1) //cout << "It exists\n"; resize = MeshPtr(ptr); @@ -1271,17 +1126,17 @@ MeshPtr NIFLoader::load(const std::string &name, { resize = MeshManager::getSingleton().createManual(name, group, NIFLoader::getSingletonPtr()); //cout <<"EXISTING" << name << "\n"; - + //if(pieces > 1) //cout << "Creating it\n"; - - + + //resize->load(); //resize->reload(); //return 0; ResourcePtr ptr = m->getByName(name, group); resize = MeshPtr(ptr); - + //NIFLoader::getSingletonPtr()-> /*ResourcePtr ptr = m->getByName(name, group); if (!ptr.isNull()){ @@ -1292,7 +1147,7 @@ MeshPtr NIFLoader::load(const std::string &name, } return resize; } - + /* 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 From 3a9007849d033610343ba3e3d05636e43a2169ba Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Wed, 8 Jun 2011 00:35:30 -0400 Subject: [PATCH 14/20] Windows fix --- apps/openmw/mwclass/npc.cpp | 2 +- components/bsa/bsa_archive.cpp | 12 +++++------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index 285da5c5a..5afc26480 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -118,7 +118,7 @@ namespace MWClass Ogre::Vector3 pos2 = Ogre::Vector3( 0, .5, 75); if (groin){ - cellRender.insertMesh("MeSHes\\1\\red_MJ_hat_org.NIf"); //w/W_6th_Hammer.NIF + cellRender.insertMesh("Meshes\\2\\red_MJ_hat_org.nif"); //w/W_6th_Hammer.NIF //bald_MJ_hat.NIF cellRender.insertMesh("meshes\\" + groin->model, pos2, axis, kOgrePi, npcName + "groin", addresses, numbers); addresses2[numbers] = npcName + "groin"; diff --git a/components/bsa/bsa_archive.cpp b/components/bsa/bsa_archive.cpp index ba7be5bfd..99848649a 100644 --- a/components/bsa/bsa_archive.cpp +++ b/components/bsa/bsa_archive.cpp @@ -107,7 +107,7 @@ class DirArchive: public Ogre::FileSystemArchive small = original.substr(cutoff - 1, original.size() - cutoff); //boost::filesystem::path smallp = small; m[small] = filesind; - //std::cout << "Directory: " << smallp.string() << " " << filesind.size() << "\n"; + //std::cout << "Directory: " << small << " " << filesind.size() << "\n"; } @@ -126,8 +126,7 @@ class DirArchive: public Ogre::FileSystemArchive std::string copy = filename; - if(OGRE_PLATFORM != OGRE_PLATFORM_WIN32) - { + for (int i = 0; i < filename.size(); i++) { @@ -135,7 +134,7 @@ class DirArchive: public Ogre::FileSystemArchive copy.replace(i, 1, "/"); } } - } + if(copy.at(0) == '\\' || copy.at(0) == '/') { @@ -189,8 +188,7 @@ class DirArchive: public Ogre::FileSystemArchive //std::cout << "Open\n"; std::string copy = filename; - if(OGRE_PLATFORM != OGRE_PLATFORM_WIN32) - { + for (int i = 0; i < filename.size(); i++) { @@ -198,7 +196,7 @@ class DirArchive: public Ogre::FileSystemArchive copy.replace(i, 1, "/"); } } - } + if(copy.at(0) == '\\' || copy.at(0) == '/') { From 65cc0e83179ae71a9c32291ebf4495972133729c Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Wed, 8 Jun 2011 17:15:13 -0400 Subject: [PATCH 15/20] trying strict --- apps/openmw/engine.cpp | 49 +--------------------------------- apps/openmw/mwclass/npc.cpp | 2 +- components/bsa/bsa_archive.cpp | 31 ++++++++++++++++----- components/bsa/bsa_archive.hpp | 2 +- 4 files changed, 27 insertions(+), 57 deletions(-) diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index a899a5aea..a160e0993 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -93,51 +93,6 @@ bool OMW::Engine::frameRenderingQueued (const Ogre::FrameEvent& evt) std::string effect; MWWorld::Ptr::CellStore *current = mEnvironment.mWorld->getPlayer().getPlayer().getCell(); - /* - ESMS::CellRefList::List creatureData = (current->creatures).list; - ESMS::CellRefList::List::iterator creaturedataiter = creatureData.begin(); - - for(int i = 0; i < creatureData.size(); i++) - { - //std::cout << "Testing" << i < "\n"; - ESMS::LiveCellRef item = *creaturedataiter; - Ogre::Entity* creaturemodel = item.model; - - if(evt.timeSinceLastFrame == 0) - creaturemodel->getSkeleton()->setBindingPose(); - creaturemodel->getSkeleton()->setBlendMode(Ogre::SkeletonAnimationBlendMode::ANIMBLEND_AVERAGE); //ANIMBLEND_AVERAGE - Ogre::AnimationState *mAnimationState = creaturemodel->getAnimationState("WholeThing"); - mAnimationState->setWeight(.5); - mAnimationState->setLoop(true); - //npcmodel->getSkeleton()-> - - mAnimationState->setEnabled(true); - - - - - Ogre::AnimationState *mAnimationState2 = creaturemodel->getAnimationState("WholeThing2"); - mAnimationState2->setLoop(true); - mAnimationState2->setWeight(.5); - mAnimationState2->setEnabled(true); - - mAnimationState2->createBlendMask(creaturemodel->getSkeleton()->getNumBones(),1); - mAnimationState->createBlendMask(creaturemodel->getSkeleton()->getNumBones(),1); - for(int j = 2; j < creaturemodel->getSkeleton()->getNumBones(); j++) - { - mAnimationState->setBlendMaskEntry(j,1); - mAnimationState2->setBlendMaskEntry(j,1); - } - // set skeleton - std::cout << "TimePosition:" << mAnimationState->getTimePosition() << "\n"; - - mAnimationState->addTime(evt.timeSinceLastFrame); - mAnimationState2->addTime(evt.timeSinceLastFrame); - //npcmodel->_updateAnimation(); - //mAnimationState2->setEnabled(true); - creaturedataiter++; - }*/ - //If the region has changed @@ -299,9 +254,7 @@ void OMW::Engine::loadBSA() std::string m = mDataDir.string(); std::cout << "Data dir" << m << "\n"; - addDir(m); - //std::string s = "f\n"; - //std::cout <<"S: " << s.size() << "\n"; + addDir(m, mFSStrict); } diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index 5afc26480..88d3ee136 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -118,7 +118,7 @@ namespace MWClass Ogre::Vector3 pos2 = Ogre::Vector3( 0, .5, 75); if (groin){ - cellRender.insertMesh("Meshes\\2\\red_MJ_hat_org.nif"); //w/W_6th_Hammer.NIF + cellRender.insertMesh("meshes\\2\\red_MJ_hat_ORg.nif"); //w/W_6th_Hammer.NIF //bald_MJ_hat.NIF cellRender.insertMesh("meshes\\" + groin->model, pos2, axis, kOgrePi, npcName + "groin", addresses, numbers); addresses2[numbers] = npcName + "groin"; diff --git a/components/bsa/bsa_archive.cpp b/components/bsa/bsa_archive.cpp index 99848649a..8e3da70e0 100644 --- a/components/bsa/bsa_archive.cpp +++ b/components/bsa/bsa_archive.cpp @@ -41,6 +41,8 @@ struct ciLessBoost : std::binary_function } }; +static bool fsstrict = false; + /// An OGRE Archive wrapping a BSAFile archive class DirArchive: public Ogre::FileSystemArchive { @@ -70,8 +72,8 @@ class DirArchive: public Ogre::FileSystemArchive std::string s = name; cutoff = s.size() + 1; //std::cout << "Cut off:" << cutoff; - - populateMap(currentdir); + if(fsstrict == false) + populateMap(currentdir); } void populateMap(boost::filesystem::path d){ @@ -111,7 +113,7 @@ class DirArchive: public Ogre::FileSystemArchive } - bool isCaseSensitive() const { return false; } + bool isCaseSensitive() const { return fsstrict; } // The archive is loaded in the constructor, and never unloaded. void load() {} @@ -134,7 +136,13 @@ class DirArchive: public Ogre::FileSystemArchive copy.replace(i, 1, "/"); } } + if(fsstrict == true) + { + std::cout << "fsstrict " << copy << "\n"; + return FileSystemArchive::exists(copy); + } + std::cout << "afterstrict\n"; if(copy.at(0) == '\\' || copy.at(0) == '/') { @@ -144,8 +152,7 @@ class DirArchive: public Ogre::FileSystemArchive //std::cout << "After:" << copy.size(); } - - //boost::filesystem::path p = copy; + int last = copy.size() - 1; int i = last; @@ -196,7 +203,11 @@ class DirArchive: public Ogre::FileSystemArchive copy.replace(i, 1, "/"); } } - + if(fsstrict == true){ + std::cout << "fsstrict " << copy << "\n"; + return FileSystemArchive::open(copy, readonly); + } + std::cout << "afterstrict\n"; if(copy.at(0) == '\\' || copy.at(0) == '/') { @@ -205,6 +216,9 @@ class DirArchive: public Ogre::FileSystemArchive //std::cout << "The copy" << copy << "\n"; //std::cout << "After:" << copy.size(); } + + + //boost::filesystem::path p = copy; int last = copy.size() - 1; @@ -374,6 +388,7 @@ public: static bool init = false; static bool init2 = false; + static void insertBSAFactory() { if(!init) @@ -400,9 +415,11 @@ void addBSA(const std::string& name, const std::string& group) ResourceGroupManager::getSingleton(). addResourceLocation(name, "BSA", group); } -void addDir(const std::string& name, const std::string& group) +void addDir(const std::string& name, const bool& fs, const std::string& group) { + fsstrict = fs; insertDirFactory(); + ResourceGroupManager::getSingleton(). addResourceLocation(name, "Dir", group); } diff --git a/components/bsa/bsa_archive.hpp b/components/bsa/bsa_archive.hpp index a72f638e3..bf7e7ee51 100644 --- a/components/bsa/bsa_archive.hpp +++ b/components/bsa/bsa_archive.hpp @@ -32,6 +32,6 @@ /// Add the given BSA file as an input archive in the Ogre resource /// system. void addBSA(const std::string& file, const std::string& group="General"); -void addDir(const std::string& file, const std::string& group="General"); +void addDir(const std::string& file, const bool& fs, const std::string& group="General"); #endif From 93f41e25a44fea0fe2ae2f9e6a2e7bf19a0c19ff Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Wed, 8 Jun 2011 17:29:28 -0400 Subject: [PATCH 16/20] fs-strict --- apps/openmw/mwclass/npc.cpp | 2 +- components/bsa/bsa_archive.cpp | 35 ++++++++++++++++------------------ 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index 88d3ee136..5afc26480 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -118,7 +118,7 @@ namespace MWClass Ogre::Vector3 pos2 = Ogre::Vector3( 0, .5, 75); if (groin){ - cellRender.insertMesh("meshes\\2\\red_MJ_hat_ORg.nif"); //w/W_6th_Hammer.NIF + cellRender.insertMesh("Meshes\\2\\red_MJ_hat_org.nif"); //w/W_6th_Hammer.NIF //bald_MJ_hat.NIF cellRender.insertMesh("meshes\\" + groin->model, pos2, axis, kOgrePi, npcName + "groin", addresses, numbers); addresses2[numbers] = npcName + "groin"; diff --git a/components/bsa/bsa_archive.cpp b/components/bsa/bsa_archive.cpp index 8e3da70e0..09662474f 100644 --- a/components/bsa/bsa_archive.cpp +++ b/components/bsa/bsa_archive.cpp @@ -49,7 +49,7 @@ class DirArchive: public Ogre::FileSystemArchive boost::filesystem::path currentdir; std::map, ciLessBoost> m; - int cutoff; + unsigned int cutoff; bool comparePortion(std::string file1, std::string file2, int start, int size) const { @@ -128,21 +128,15 @@ class DirArchive: public Ogre::FileSystemArchive std::string copy = filename; - - for (int i = 0; i < filename.size(); i++) + + for (unsigned int i = 0; i < filename.size(); i++) { if(copy.at(i) == '\\' ){ copy.replace(i, 1, "/"); } } - if(fsstrict == true) - { - std::cout << "fsstrict " << copy << "\n"; - return FileSystemArchive::exists(copy); - } - std::cout << "afterstrict\n"; if(copy.at(0) == '\\' || copy.at(0) == '/') { @@ -151,8 +145,13 @@ class DirArchive: public Ogre::FileSystemArchive //std::cout << "The copy" << copy << "\n"; //std::cout << "After:" << copy.size(); } + if(fsstrict == true) + { + //std::cout << "fsstrict " << copy << "\n"; + return FileSystemArchive::exists(copy); + + } - int last = copy.size() - 1; int i = last; @@ -195,19 +194,15 @@ class DirArchive: public Ogre::FileSystemArchive //std::cout << "Open\n"; std::string copy = filename; - - for (int i = 0; i < filename.size(); i++) + + for (unsigned int i = 0; i < filename.size(); i++) { if(copy.at(i) == '\\' ){ copy.replace(i, 1, "/"); } } - if(fsstrict == true){ - std::cout << "fsstrict " << copy << "\n"; - return FileSystemArchive::open(copy, readonly); - } - std::cout << "afterstrict\n"; + if(copy.at(0) == '\\' || copy.at(0) == '/') { @@ -217,7 +212,9 @@ class DirArchive: public Ogre::FileSystemArchive //std::cout << "After:" << copy.size(); } - + if(fsstrict == true){ + return FileSystemArchive::open(copy, readonly); + } //boost::filesystem::path p = copy; @@ -419,7 +416,7 @@ void addDir(const std::string& name, const bool& fs, const std::string& group) { fsstrict = fs; insertDirFactory(); - + ResourceGroupManager::getSingleton(). addResourceLocation(name, "Dir", group); } From 9eefee7168ca3a6fe6b5b75e4e39918309a39f6a Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Sat, 11 Jun 2011 20:01:21 -0400 Subject: [PATCH 17/20] Say strict --- apps/openmw/engine.cpp | 2 +- apps/openmw/mwsound/soundmanager.cpp | 35 ++++++++++++++++++++---- apps/openmw/mwsound/soundmanager.hpp | 7 +++-- components/file_finder/file_finder.hpp | 7 +++-- components/file_finder/filename_less.hpp | 35 ++++++++++++++++++++++++ 5 files changed, 74 insertions(+), 12 deletions(-) diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index a160e0993..97596301c 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -392,7 +392,7 @@ void OMW::Engine::go() mOgre.getCamera(), mEnvironment.mWorld->getStore(), (mDataDir), - mUseSound); + mUseSound, mFSStrict); // Create script system mScriptContext = new MWScript::CompilerContext (MWScript::CompilerContext::Type_Full, diff --git a/apps/openmw/mwsound/soundmanager.cpp b/apps/openmw/mwsound/soundmanager.cpp index 564ebe941..72e62421f 100644 --- a/apps/openmw/mwsound/soundmanager.cpp +++ b/apps/openmw/mwsound/soundmanager.cpp @@ -63,7 +63,7 @@ namespace MWSound */ OEManagerPtr mgr; SoundPtr music; - + /* This class calls update() on the sound manager each frame using and Ogre::FrameListener */ @@ -84,20 +84,22 @@ namespace MWSound // finding. It takes DOS paths (any case, \\ slashes or / slashes) // relative to the sound dir, and translates them into full paths // of existing files in the filesystem, if they exist. + bool FSstrict; FileFinder::FileFinder files; + FileFinder::FileFinderStrict strict; SoundImpl(Ogre::Root *root, Ogre::Camera *camera, const ESMS::ESMStore &str, - const std::string &soundDir) + const std::string &soundDir, bool fsstrict) : mgr(new OEManager(SoundFactoryPtr(new SOUND_FACTORY))) , updater(mgr) , cameraTracker(mgr) , store(str) - , files(soundDir) + , files(soundDir), strict(soundDir) { + FSstrict = fsstrict; cout << "Sound output: " << SOUND_OUT << endl; cout << "Sound decoder: " << SOUND_IN << endl; - // Attach the camera to the camera tracker cameraTracker.followCamera(camera); @@ -124,15 +126,23 @@ namespace MWSound bool hasFile(const std::string &str) { + if(FSstrict == false){ if(files.has(str)) return true; // Not found? Try with .mp3 + return files.has(toMp3(str)); + } + else{ + if(strict.has(str)) return true; + // Not found? Try with .mp3 return files.has(toMp3(str)); } + } // Convert a Morrowind sound path (eg. Fx\funny.wav) to full path // with proper slash conversion (eg. datadir/Sound/Fx/funny.wav) std::string convertPath(const std::string &str) { + if(FSstrict == false){ // Search and return if(files.has(str)) return files.lookup(str); @@ -141,6 +151,18 @@ namespace MWSound std::string mp3 = toMp3(str); if(files.has(mp3)) return files.lookup(mp3); + } + + else + { + if(files.has(str)) + return files.lookup(str); + + // Try mp3 if the wav wasn't found + std::string mp3 = toMp3(str); + if(files.has(mp3)) + return files.lookup(mp3); + } // Give up return ""; @@ -307,12 +329,13 @@ namespace MWSound SoundManager::SoundManager(Ogre::Root *root, Ogre::Camera *camera, const ESMS::ESMStore &store, boost::filesystem::path dataDir, - bool useSound) + bool useSound, bool fsstrict) : mData(NULL) { + fsStrict = fsstrict; MP3Lookup(dataDir / "Music/Explore/"); if(useSound) - mData = new SoundImpl(root, camera, store, (dataDir / "Sound").string()); + mData = new SoundImpl(root, camera, store, (dataDir / "Sound").string(), fsstrict); } SoundManager::~SoundManager() diff --git a/apps/openmw/mwsound/soundmanager.hpp b/apps/openmw/mwsound/soundmanager.hpp index 8c48986db..b76e71e39 100644 --- a/apps/openmw/mwsound/soundmanager.hpp +++ b/apps/openmw/mwsound/soundmanager.hpp @@ -30,13 +30,16 @@ namespace MWSound SoundImpl *mData; std::vector files; + bool fsStrict; - public: + + SoundManager(Ogre::Root*, Ogre::Camera*, const ESMS::ESMStore &store, - boost::filesystem::path dataDir, bool useSound); + boost::filesystem::path dataDir, bool useSound, bool fsstrict); ~SoundManager(); + void startRandomTitle(); void MP3Lookup(boost::filesystem::path dir); //struct SoundImpl; diff --git a/components/file_finder/file_finder.hpp b/components/file_finder/file_finder.hpp index cfa07dce9..358563afa 100644 --- a/components/file_finder/file_finder.hpp +++ b/components/file_finder/file_finder.hpp @@ -22,7 +22,7 @@ class FileFinderT { std::string file = pth.string(); std::string key = file.substr(cut); - owner->table[key] = file; + owner->table[key] = file; } }; @@ -50,17 +50,18 @@ public: bool has(const std::string& file) const { - return table.find(file) != table.end(); + return table.find(file) != table.end(); } // Find the full path from a relative path. const std::string &lookup(const std::string& file) const { - return table.find(file)->second; + return table.find(file)->second; } }; // The default is to use path_less for equality checks typedef FileFinderT FileFinder; +typedef FileFinderT FileFinderStrict; } #endif diff --git a/components/file_finder/filename_less.hpp b/components/file_finder/filename_less.hpp index 9f251b1c8..bc3186ce9 100644 --- a/components/file_finder/filename_less.hpp +++ b/components/file_finder/filename_less.hpp @@ -44,6 +44,41 @@ struct path_less return compareString(a.c_str(), b.c_str()) < 0; } }; + +struct path_slash +{ + int compareChar(char a, char b) const + { + if(a>b) return 1; + else if(a Date: Sun, 12 Jun 2011 16:36:18 -0400 Subject: [PATCH 18/20] streammusic strict --- apps/openmw/mwsound/soundmanager.cpp | 119 ++++++++++++++++++--------- apps/openmw/mwsound/soundmanager.hpp | 9 +- 2 files changed, 85 insertions(+), 43 deletions(-) diff --git a/apps/openmw/mwsound/soundmanager.cpp b/apps/openmw/mwsound/soundmanager.cpp index 72e62421f..abff70664 100644 --- a/apps/openmw/mwsound/soundmanager.cpp +++ b/apps/openmw/mwsound/soundmanager.cpp @@ -87,15 +87,18 @@ namespace MWSound bool FSstrict; FileFinder::FileFinder files; FileFinder::FileFinderStrict strict; + FileFinder::FileFinder musicpath; + FileFinder::FileFinderStrict musicpathStrict; SoundImpl(Ogre::Root *root, Ogre::Camera *camera, const ESMS::ESMStore &str, - const std::string &soundDir, bool fsstrict) + const std::string &soundDir, const std::string &musicDir, bool fsstrict) : mgr(new OEManager(SoundFactoryPtr(new SOUND_FACTORY))) , updater(mgr) , cameraTracker(mgr) , store(str) , files(soundDir), strict(soundDir) + ,musicpath(musicDir), musicpathStrict(musicDir) { FSstrict = fsstrict; cout << "Sound output: " << SOUND_OUT << endl; @@ -113,6 +116,8 @@ namespace MWSound cameraTracker.unfollowCamera(); } + + static std::string toMp3(std::string str) { std::string::size_type i = str.rfind('.'); @@ -124,44 +129,70 @@ namespace MWSound return str; } - bool hasFile(const std::string &str) + bool hasFile(const std::string &str, bool music = false) { if(FSstrict == false){ - if(files.has(str)) return true; - // Not found? Try with .mp3 - return files.has(toMp3(str)); + if(music){ + if(musicpath.has(str)) return true; + // Not found? Try with .mp3 + return musicpath.has(toMp3(str)); + } + else + { + if(files.has(str)) return true; + return files.has(toMp3(str)); + } + } + else + { + if(music){ + if(musicpathStrict.has(str)) return true; + // Not found? Try with .mp3 + return musicpathStrict.has(toMp3(str)); + } + else + { + if(strict.has(str)) return true; + return strict.has(toMp3(str)); + } + } - else{ - if(strict.has(str)) return true; - // Not found? Try with .mp3 - return files.has(toMp3(str)); - } } // Convert a Morrowind sound path (eg. Fx\funny.wav) to full path // with proper slash conversion (eg. datadir/Sound/Fx/funny.wav) - std::string convertPath(const std::string &str) + std::string convertPath(const std::string &str, bool music = false) { if(FSstrict == false){ // Search and return - if(files.has(str)) - return files.lookup(str); + if(music && musicpath.has(str)) + return musicpath.lookup(str); + else if(files.has(str)) + return files.lookup(str); + // Try mp3 if the wav wasn't found std::string mp3 = toMp3(str); - if(files.has(mp3)) - return files.lookup(mp3); + if(music && musicpath.has(mp3)) + return musicpath.lookup(mp3); + else if(files.has(mp3)) + return files.lookup(mp3); } else { - if(files.has(str)) - return files.lookup(str); + if(music && musicpathStrict.has(str)) + return musicpathStrict.lookup(str); + else if(strict.has(str)) + return strict.lookup(str); + - // Try mp3 if the wav wasn't found - std::string mp3 = toMp3(str); - if(files.has(mp3)) - return files.lookup(mp3); + // Try mp3 if the wav wasn't found + std::string mp3 = toMp3(str); + if(music && musicpathStrict.has(mp3)) + return musicpathStrict.lookup(mp3); + else if(strict.has(str)) + return strict.lookup(mp3); } // Give up @@ -326,6 +357,22 @@ namespace MWSound } }; + void SoundManager::streamMusicFull (const std::string& filename) + { + if(!mData) return; + + // Play the sound and tell it to stream, if possible. TODO: + // Store the reference, the jukebox will need to check status, + // control volume etc. + if (mData->music) + mData->music->stop(); + mData->music = mData->mgr->load(filename); + mData->music->setStreaming(true); + mData->music->setVolume(0.4); + mData->music->play(); + + } + SoundManager::SoundManager(Ogre::Root *root, Ogre::Camera *camera, const ESMS::ESMStore &store, boost::filesystem::path dataDir, @@ -335,7 +382,7 @@ namespace MWSound fsStrict = fsstrict; MP3Lookup(dataDir / "Music/Explore/"); if(useSound) - mData = new SoundImpl(root, camera, store, (dataDir / "Sound").string(), fsstrict); + mData = new SoundImpl(root, camera, store, (dataDir / "Sound").string(), (dataDir / "Music").string(), fsstrict); } SoundManager::~SoundManager() @@ -344,6 +391,15 @@ namespace MWSound delete mData; } + void SoundManager::streamMusic(const std::string& filename){ + if(mData->hasFile(filename, true)) + { + std::string fullpath = mData->convertPath(filename, true); + streamMusicFull(fullpath); + } + } + + void SoundManager::MP3Lookup(boost::filesystem::path dir) { boost::filesystem::directory_iterator dir_iter(dir), dir_end; @@ -376,7 +432,7 @@ namespace MWSound try { std::cout << "Playing " << music << "\n"; - streamMusic(music); + streamMusicFull(music); } catch(std::exception &e) { @@ -420,22 +476,7 @@ namespace MWSound return !mData->isPlaying(ptr, "_say_sound"); } - void SoundManager::streamMusic (const std::string& filename) - { - if(!mData) return; - - // Play the sound and tell it to stream, if possible. TODO: - // Store the reference, the jukebox will need to check status, - // control volume etc. - if (mData->music) - mData->music->stop(); - mData->music = mData->mgr->load(filename); - mData->music->setStreaming(true); - mData->music->setVolume(0.4); - mData->music->play(); - - } - + void SoundManager::playSound (const std::string& soundId, float volume, float pitch) { if(!mData) return; diff --git a/apps/openmw/mwsound/soundmanager.hpp b/apps/openmw/mwsound/soundmanager.hpp index b76e71e39..70e6babf9 100644 --- a/apps/openmw/mwsound/soundmanager.hpp +++ b/apps/openmw/mwsound/soundmanager.hpp @@ -31,6 +31,9 @@ namespace MWSound SoundImpl *mData; std::vector files; bool fsStrict; + void streamMusicFull (const std::string& filename); + ///< Play a soundifle + /// \param filename name of a sound file in "Music/" in the data directory. public: @@ -39,7 +42,7 @@ namespace MWSound boost::filesystem::path dataDir, bool useSound, bool fsstrict); ~SoundManager(); - + void streamMusic(const std::string& filename); void startRandomTitle(); void MP3Lookup(boost::filesystem::path dir); //struct SoundImpl; @@ -54,9 +57,7 @@ namespace MWSound bool sayDone (MWWorld::Ptr reference) const; ///< Is actor not speaking? - void streamMusic (const std::string& filename); - ///< Play a soundifle - /// \param filename name of a sound file in "Music/" in the data directory. + void playSound (const std::string& soundId, float volume, float pitch); ///< Play a sound, independently of 3D-position From 56affd018ab8d2f0f50ed37ecb91961b11147c01 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Wed, 15 Jun 2011 13:09:47 -0400 Subject: [PATCH 19/20] Some cleanup --- apps/openmw/mwclass/npc.cpp | 15 ++------- apps/openmw/mwsound/soundmanager.hpp | 4 ++- components/bsa/bsa_archive.cpp | 50 +++------------------------- 3 files changed, 10 insertions(+), 59 deletions(-) diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index 5afc26480..9ef5e6f40 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -95,8 +95,7 @@ namespace MWClass upperright[uppernumbers++] = npcName + "chest"; neckandup[neckNumbers++] = npcName + "chest"; } - //std::cout << "GETTING NPC PART"; - //Orgre::SceneNode test = cellRender.getNpcPart(); + const ESM::BodyPart *upperleg = environment.mWorld->getStore().bodyParts.search (bodyRaceID + "upper leg"); const ESM::BodyPart *groin = environment.mWorld->getStore().bodyParts.search (bodyRaceID + "groin"); @@ -113,23 +112,18 @@ namespace MWClass const ESM::BodyPart *hands = environment.mWorld->getStore().bodyParts.search (bodyRaceID + "hands.1st"); - //std::cout << "RACE" << bodyRaceID << "\n"; - Ogre::Vector3 pos2 = Ogre::Vector3( 0, .5, 75); if (groin){ - cellRender.insertMesh("Meshes\\2\\red_MJ_hat_org.nif"); //w/W_6th_Hammer.NIF - //bald_MJ_hat.NIF cellRender.insertMesh("meshes\\" + groin->model, pos2, axis, kOgrePi, npcName + "groin", addresses, numbers); addresses2[numbers] = npcName + "groin"; addresses[numbers++] = npcName + "groin"; } if (tail) { cellRender.insertMesh("tail\\" + tail->model, Ogre::Vector3(0 , 0, -76), axis, kOgrePi, npcName + "tail", addresses, numbers, "tail"); - //std::cout << "TAIL\n"; } - //addresses[1] = npcName + "groin"; + if(upperleg){ cellRender.insertMesh ("meshes\\" + upperleg->model, Ogre::Vector3( 6, 0, -16), axis, kOgrePi, npcName + "upper leg", addresses, numbers); //-18 cellRender.insertMesh ("meshes\\" + upperleg->model, Ogre::Vector3( -6, 0, -16), axis, Ogre::Radian(0), npcName + "upper leg2", addresses2, numbers); @@ -220,9 +214,6 @@ namespace MWClass if(hand) { - //std::cout << "WE FOUND A HAND\n"; - //-50, 0, -120 - //std::cout << "WE FOUND HANDS\n"; std::string pass; if(hand->model.compare("b\\B_N_Dark Elf_F_Hands.1st.NIF")==0 && bodyRaceID.compare("b_n_dark elf_m_") == 0) pass = "b\\B_N_Dark Elf_M_Hands.1st.NIF"; @@ -232,7 +223,6 @@ namespace MWClass cellRender.insertMesh("meshes\\" + pass, Ogre::Vector3(42, 1, -110), Ogre::Vector3(0, 0,0), kOgrePi, npcName + "hand2", upperright, uppernumbers, false); //0, 100, -100 0,0,120 upperleft[uppernumbers] = npcName + "hand"; upperright[uppernumbers++] = npcName + "hand2"; - //cellRender.rotateMesh(Ogre::Vector3(0, 0,0), kOgrePi, upperleft, uppernumbers); cellRender.scaleMesh(Ogre::Vector3(1, -1, 1), upperleft, uppernumbers); cellRender.scaleMesh(Ogre::Vector3(1, -1, 1), upperright, uppernumbers); } @@ -246,7 +236,6 @@ namespace MWClass else pass =hands->model; //-50, 0, -120 cellRender.insertMesh("meshes\\" + pass, Ogre::Vector3(42, 1,-110), Ogre::Vector3(0, 0, 0), kOgrePi, npcName + "hand", upperleft, uppernumbers, false); //0, 100, -100 42, 0, -110 - //cellRender.insertMesh("meshes\\" + hands->model, Ogre::Vector3(42, 0,110), Ogre::Vector3(1, 0, 0), kOgrePi, npcName + "hand", upperleft, uppernumbers, false); //0, 100, -100 42, 0, -110 cellRender.insertMesh("meshes\\" + pass, Ogre::Vector3(42, 1, -110), Ogre::Vector3(0, 0, 0), kOgrePi, npcName + "hand2", upperright, uppernumbers, false); //0, 100, -100 0,0,120 upperleft[uppernumbers] = npcName + "hand"; upperright[uppernumbers++] = npcName + "hand2"; diff --git a/apps/openmw/mwsound/soundmanager.hpp b/apps/openmw/mwsound/soundmanager.hpp index 70e6babf9..ec33f57a2 100644 --- a/apps/openmw/mwsound/soundmanager.hpp +++ b/apps/openmw/mwsound/soundmanager.hpp @@ -33,7 +33,7 @@ namespace MWSound bool fsStrict; void streamMusicFull (const std::string& filename); ///< Play a soundifle - /// \param filename name of a sound file in "Music/" in the data directory. + /// \param absolute filename public: @@ -43,6 +43,8 @@ namespace MWSound ~SoundManager(); void streamMusic(const std::string& filename); + ///< Play a soundifle + /// \param filename name of a sound file in "Music/" in the data directory. void startRandomTitle(); void MP3Lookup(boost::filesystem::path dir); //struct SoundImpl; diff --git a/components/bsa/bsa_archive.cpp b/components/bsa/bsa_archive.cpp index 09662474f..4b3fbf6c0 100644 --- a/components/bsa/bsa_archive.cpp +++ b/components/bsa/bsa_archive.cpp @@ -67,11 +67,11 @@ class DirArchive: public Ogre::FileSystemArchive DirArchive(const String& name) : FileSystemArchive(name, "Dir") - { mType = "Dir"; + { + mType = "Dir"; currentdir = name; std::string s = name; cutoff = s.size() + 1; - //std::cout << "Cut off:" << cutoff; if(fsstrict == false) populateMap(currentdir); @@ -98,7 +98,6 @@ class DirArchive: public Ogre::FileSystemArchive small = s.substr(cutoff - 1, s.size() - cutoff); filesind.push_back(small); - //std::cout << "File: " << small << "f\n"; } } std::string small; @@ -107,9 +106,7 @@ class DirArchive: public Ogre::FileSystemArchive small = original.substr(cutoff, original.size() - cutoff); else small = original.substr(cutoff - 1, original.size() - cutoff); - //boost::filesystem::path smallp = small; m[small] = filesind; - //std::cout << "Directory: " << small << " " << filesind.size() << "\n"; } @@ -120,12 +117,6 @@ class DirArchive: public Ogre::FileSystemArchive void unload() {} bool exists(const String& filename) { - //std::cout << "exists\n"; - //String s = filename; - //FileSystemArchive::findFiles(s, true, false, filenames.getPointer(), f.getPointer()); - // std::cout << "Filenames" << filenames.useCount() << "\n"; - - std::string copy = filename; @@ -140,10 +131,7 @@ class DirArchive: public Ogre::FileSystemArchive if(copy.at(0) == '\\' || copy.at(0) == '/') { - //std::cout << "Before:" << copy.size() << "\n"; copy.erase(0, 1); - //std::cout << "The copy" << copy << "\n"; - //std::cout << "After:" << copy.size(); } if(fsstrict == true) { @@ -162,36 +150,23 @@ class DirArchive: public Ogre::FileSystemArchive break; } - //std::string file = copy.substr(i + 1, copy.size() - i); //filename with no slash std::string folder = copy.substr(0, i); //folder with no slash - - //std::transform(file.begin(), file.end(), file.begin(), tolower); - //boost::filesystem::path folderpath = folder; std::vector current = m[folder]; for(std::vector::iterator iter = current.begin(); iter != current.end(); iter++) { - //std::string loopfile = iter->substr(i + 1, copy.size() - i); //filename with no slash - //std::transform(loopfile.begin(), loopfile.end(), loopfile.begin(), tolower); - //std::string now = *iter; if(comparePortion(*iter, copy, i + 1, copy.size() - i -1) == true){ - //std::cout << "Loopfile:" << copy << "\n"; return FileSystemArchive::exists(*iter); } } - //std::cout << "Filename:" << file << "\n"; - //std::cout << "Full:" << p.string() << "\n"; - //std::cout << "Current:" << folder << "size: " << current.size() << "\n"; - //std::cout << "\nFull:" << p.string() << "\n"<< "Part:" << folderpath.string(); - return false;//FileSystemArchive::exists(copy); + return false; } DataStreamPtr open(const String& filename, bool readonly = true) const { std::map, ciLessBoost> mlocal = m; - //std::cout << "Open\n"; std::string copy = filename; @@ -206,17 +181,13 @@ class DirArchive: public Ogre::FileSystemArchive if(copy.at(0) == '\\' || copy.at(0) == '/') { - //std::cout << "Before:" << copy.size() << "\n"; copy.erase(0, 1); - //std::cout << "The copy" << copy << "\n"; - //std::cout << "After:" << copy.size(); } if(fsstrict == true){ return FileSystemArchive::open(copy, readonly); } - //boost::filesystem::path p = copy; int last = copy.size() - 1; int i = last; @@ -227,28 +198,17 @@ class DirArchive: public Ogre::FileSystemArchive break; } - std::string folder = copy.substr(0, i); //folder with no slash //folder with no slash - - //std::transform(file.begin(), file.end(), file.begin(), tolower); - //boost::filesystem::path folderpath = folder; + std::string folder = copy.substr(0, i); //folder with no slash std::vector current = mlocal[folder]; for(std::vector::iterator iter = current.begin(); iter != current.end(); iter++) { - //std::string loopfile = iter->substr(i + 1, copy.size() - i); //filename with no slash - //std::transform(loopfile.begin(), loopfile.end(), loopfile.begin(), tolower); if(comparePortion(*iter, copy, i + 1, copy.size() - i -1) == true){ - //std::cout << "Loopfile:" << copy << "\n"; return FileSystemArchive::open(*iter, readonly); } } - - //std::cout << "Filename:" << file << "\n"; - //std::cout << "Full:" << p.string() << "\n"; - //std::cout << "Current:" << folder << "size: " << current.size() << "\n"; - //std::cout << "\nFull:" << p.string() << "\n"<< "Part:" << folderpath.string(); DataStreamPtr p; - return p;//FileSystemArchive::open(copy, readonly); + return p; } }; From 0f2df4e2b8c0fcce0dc88405df970ccf272d0601 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Wed, 15 Jun 2011 22:33:31 +0200 Subject: [PATCH 20/20] more cleanup --- apps/openmw/engine.cpp | 3 - apps/openmw/mwclass/creature.cpp | 2 +- apps/openmw/mwrender/cellimp.hpp | 2 - apps/openmw/mwrender/exterior.cpp | 15 -- apps/openmw/mwrender/exterior.hpp | 2 +- apps/openmw/mwrender/interior.cpp | 29 +-- apps/openmw/mwrender/interior.hpp | 2 - apps/openmw/mwsound/soundmanager.cpp | 158 ++++++------ apps/openmw/mwsound/soundmanager.hpp | 19 +- components/bsa/bsa_archive.cpp | 33 ++- components/esm_store/cell_store.hpp | 3 - components/file_finder/file_finder.hpp | 10 +- components/files/multidircollection.hpp | 2 +- components/nif/data.hpp | 324 +++++------------------- components/nifogre/ogre_nif_loader.cpp | 15 -- components/nifogre/ogre_nif_loader.hpp | 12 +- 16 files changed, 187 insertions(+), 444 deletions(-) diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 97596301c..483a74eef 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -353,9 +353,6 @@ void OMW::Engine::go() mOgre.configure(!isFile(ogreCfg.c_str()), cfgUserDir, plugCfg, false); - //addResourcesDirectory (mDataDir / "Meshes"); - //addResourcesDirectory (mDataDir / "Textures"); - // This has to be added BEFORE MyGUI is initialized, as it needs // to find core.xml here. addResourcesDirectory(mResDir / "mygui"); diff --git a/apps/openmw/mwclass/creature.cpp b/apps/openmw/mwclass/creature.cpp index 5316c8267..0bd133f21 100644 --- a/apps/openmw/mwclass/creature.cpp +++ b/apps/openmw/mwclass/creature.cpp @@ -34,7 +34,7 @@ namespace MWClass if (!model.empty()) { MWRender::Rendering rendering (cellRender, ref->ref); - cellRender.insertMesh("meshes\\" + model); + cellRender.insertMesh("meshes\\" + model); cellRender.insertActorPhysics(); ref->mData.setHandle (rendering.end (ref->mData.isEnabled())); } diff --git a/apps/openmw/mwrender/cellimp.hpp b/apps/openmw/mwrender/cellimp.hpp index 727c9d317..272bfeeab 100644 --- a/apps/openmw/mwrender/cellimp.hpp +++ b/apps/openmw/mwrender/cellimp.hpp @@ -7,7 +7,6 @@ #include "../mwworld/refdata.hpp" #include -#include namespace Ogre { @@ -43,7 +42,6 @@ namespace MWRender virtual void insertMesh(const std::string &mesh, Ogre::Vector3 vec, Ogre::Vector3 axis, Ogre::Radian angle, std::string sceneNodeName, std::string sceneParent[], int elements, bool translateFirst) = 0; virtual void insertMesh(const std::string &mesh, Ogre::Vector3 vec, Ogre::Vector3 axis, Ogre::Radian angle, std::string sceneNodeName, std::string sceneParent[], int elements) = 0; virtual void insertMesh(const std::string &mesh) = 0; - //virtual Ogre::Entity* insertAndDeliverMesh(const std::string &mesh) = 0; virtual void scaleMesh(Ogre::Vector3 axis, std::string sceneNodeName[], int elements) = 0; diff --git a/apps/openmw/mwrender/exterior.cpp b/apps/openmw/mwrender/exterior.cpp index aa712dede..fe54af84a 100644 --- a/apps/openmw/mwrender/exterior.cpp +++ b/apps/openmw/mwrender/exterior.cpp @@ -273,21 +273,6 @@ std::string ExteriorCellRender::insertEnd (bool enable) return handle; } -/* -Ogre::Entity* ExteriorCellRender::insertAndDeliverMesh(const std::string &mesh) -{ - assert (insert); - - NIFLoader::load(mesh); - Entity *ent = mScene.getMgr()->createEntity(mesh); - ent->setDisplaySkeleton(true); - - - mInsert->attachObject(ent); - return ent; - -}*/ - // configure lighting according to cell void ExteriorCellRender::configureAmbient() diff --git a/apps/openmw/mwrender/exterior.hpp b/apps/openmw/mwrender/exterior.hpp index 87659a213..8458e4dd8 100644 --- a/apps/openmw/mwrender/exterior.hpp +++ b/apps/openmw/mwrender/exterior.hpp @@ -71,7 +71,7 @@ namespace MWRender virtual void insertMesh(const std::string &mesh, Ogre::Vector3 vec, Ogre::Vector3 axis, Ogre::Radian angle, std::string sceneNodeName, std::string sceneParent[], int elements, bool translateFirst); virtual void insertMesh(const std::string &mesh); - //virtual Ogre::Entity* insertAndDeliverMesh(const std::string &mesh); + virtual void rotateMesh(Ogre::Vector3 axis, Ogre::Radian angle, std::string sceneNodeName[], int elements); virtual void scaleMesh(Ogre::Vector3 axis, std::string sceneNodeName[], int elements); diff --git a/apps/openmw/mwrender/interior.cpp b/apps/openmw/mwrender/interior.cpp index 09cce2f6d..201eaf542 100644 --- a/apps/openmw/mwrender/interior.cpp +++ b/apps/openmw/mwrender/interior.cpp @@ -180,32 +180,13 @@ void InteriorCellRender::insertMesh(const std::string &mesh, Ogre::Vector3 vec, } } -/* -Ogre::Entity* InteriorCellRender::insertAndDeliverMesh(const std::string &mesh) -{ - - assert (insert); - - NIFLoader::load(mesh); - Entity *ent = scene.getMgr()->createEntity(mesh); - ent->setDisplaySkeleton(true); - - - insert->attachObject(ent); - return ent; - -}*/ - - void InteriorCellRender::insertMesh(const std::string &mesh) { - assert (insert); - //if(mesh == "\\Meshes\\bald_MJ_hat.NIF") - // NIFLoader::load(mesh, ""); - //else - NIFLoader::load(mesh); - MovableObject *ent = scene.getMgr()->createEntity(mesh); - insert->attachObject(ent); + assert (insert); + + NIFLoader::load(mesh); + MovableObject *ent = scene.getMgr()->createEntity(mesh); + insert->attachObject(ent); if (mInsertMesh.empty()) mInsertMesh = mesh; diff --git a/apps/openmw/mwrender/interior.hpp b/apps/openmw/mwrender/interior.hpp index f77d3358d..7c4b2aaf1 100644 --- a/apps/openmw/mwrender/interior.hpp +++ b/apps/openmw/mwrender/interior.hpp @@ -6,7 +6,6 @@ #include "OgreColourValue.h" #include -#include namespace Ogre { @@ -68,7 +67,6 @@ namespace MWRender virtual void rotateMesh(Ogre::Vector3 axis, Ogre::Radian angle, std::string sceneNodeName[], int elements); virtual void scaleMesh(Ogre::Vector3 axis, std::string sceneNodeName[], int elements); /// insert a mesh related to the most recent insertBegin call. - //virtual Ogre::Entity* insertAndDeliverMesh(const std::string &mesh); virtual void insertMesh(const std::string &mesh); virtual void insertMesh(const std::string &mesh, Ogre::Vector3 vec, Ogre::Vector3 axis, Ogre::Radian angle, std::string sceneNodeName, std::string sceneParent[], int elements); virtual void insertMesh(const std::string &mesh, Ogre::Vector3 vec, Ogre::Vector3 axis, Ogre::Radian angle, std::string sceneNodeName, std::string sceneParent[], int elements, bool translateFirst); diff --git a/apps/openmw/mwsound/soundmanager.cpp b/apps/openmw/mwsound/soundmanager.cpp index abff70664..970118a13 100644 --- a/apps/openmw/mwsound/soundmanager.cpp +++ b/apps/openmw/mwsound/soundmanager.cpp @@ -63,7 +63,7 @@ namespace MWSound */ OEManagerPtr mgr; SoundPtr music; - + /* This class calls update() on the sound manager each frame using and Ogre::FrameListener */ @@ -84,11 +84,11 @@ namespace MWSound // finding. It takes DOS paths (any case, \\ slashes or / slashes) // relative to the sound dir, and translates them into full paths // of existing files in the filesystem, if they exist. - bool FSstrict; + bool FSstrict; FileFinder::FileFinder files; - FileFinder::FileFinderStrict strict; - FileFinder::FileFinder musicpath; - FileFinder::FileFinderStrict musicpathStrict; + FileFinder::FileFinderStrict strict; + FileFinder::FileFinder musicpath; + FileFinder::FileFinderStrict musicpathStrict; SoundImpl(Ogre::Root *root, Ogre::Camera *camera, const ESMS::ESMStore &str, @@ -98,9 +98,9 @@ namespace MWSound , cameraTracker(mgr) , store(str) , files(soundDir), strict(soundDir) - ,musicpath(musicDir), musicpathStrict(musicDir) + ,musicpath(musicDir), musicpathStrict(musicDir) { - FSstrict = fsstrict; + FSstrict = fsstrict; cout << "Sound output: " << SOUND_OUT << endl; cout << "Sound decoder: " << SOUND_IN << endl; // Attach the camera to the camera tracker @@ -131,72 +131,74 @@ namespace MWSound bool hasFile(const std::string &str, bool music = false) { - if(FSstrict == false){ - if(music){ - if(musicpath.has(str)) return true; - // Not found? Try with .mp3 - return musicpath.has(toMp3(str)); - } - else - { - if(files.has(str)) return true; - return files.has(toMp3(str)); - } - } - else - { - if(music){ - if(musicpathStrict.has(str)) return true; - // Not found? Try with .mp3 - return musicpathStrict.has(toMp3(str)); - } - else - { - if(strict.has(str)) return true; - return strict.has(toMp3(str)); - } - - } - } + if(FSstrict == false) + { + if(music) + { + if(musicpath.has(str)) return true; + + // Not found? Try with .mp3 + return musicpath.has(toMp3(str)); + } + else + { + if(files.has(str)) return true; + return files.has(toMp3(str)); + } + } + else + { + if(music) + { + if(musicpathStrict.has(str)) return true; + + // Not found? Try with .mp3 + return musicpathStrict.has(toMp3(str)); + } + else + { + if(strict.has(str)) return true; + return strict.has(toMp3(str)); + } + } + } // Convert a Morrowind sound path (eg. Fx\funny.wav) to full path // with proper slash conversion (eg. datadir/Sound/Fx/funny.wav) std::string convertPath(const std::string &str, bool music = false) { - if(FSstrict == false){ - // Search and return - if(music && musicpath.has(str)) - return musicpath.lookup(str); - else if(files.has(str)) - return files.lookup(str); - - - // Try mp3 if the wav wasn't found - std::string mp3 = toMp3(str); - if(music && musicpath.has(mp3)) - return musicpath.lookup(mp3); - else if(files.has(mp3)) - return files.lookup(mp3); - } - - else - { - if(music && musicpathStrict.has(str)) - return musicpathStrict.lookup(str); - else if(strict.has(str)) - return strict.lookup(str); - - - // Try mp3 if the wav wasn't found - std::string mp3 = toMp3(str); - if(music && musicpathStrict.has(mp3)) - return musicpathStrict.lookup(mp3); - else if(strict.has(str)) - return strict.lookup(mp3); - } - - // Give up - return ""; + if(FSstrict == false) + { + // Search and return + if(music && musicpath.has(str)) + return musicpath.lookup(str); + else if(files.has(str)) + return files.lookup(str); + + // Try mp3 if the wav wasn't found + std::string mp3 = toMp3(str); + if(music && musicpath.has(mp3)) + return musicpath.lookup(mp3); + else if(files.has(mp3)) + return files.lookup(mp3); + } + else + { + if(music && musicpathStrict.has(str)) + return musicpathStrict.lookup(str); + else if(strict.has(str)) + return strict.lookup(str); + + // Try mp3 if the wav wasn't found + std::string mp3 = toMp3(str); + if(music && musicpathStrict.has(mp3)) + return musicpathStrict.lookup(mp3); + else if(strict.has(str)) + return strict.lookup(mp3); + } + + // Give up + return ""; } // Convert a soundId to file name, and modify the volume @@ -377,9 +379,8 @@ namespace MWSound const ESMS::ESMStore &store, boost::filesystem::path dataDir, bool useSound, bool fsstrict) - : mData(NULL) + : mData(NULL), fsStrict (fsstrict) { - fsStrict = fsstrict; MP3Lookup(dataDir / "Music/Explore/"); if(useSound) mData = new SoundImpl(root, camera, store, (dataDir / "Sound").string(), (dataDir / "Music").string(), fsstrict); @@ -391,13 +392,14 @@ namespace MWSound delete mData; } - void SoundManager::streamMusic(const std::string& filename){ - if(mData->hasFile(filename, true)) - { - std::string fullpath = mData->convertPath(filename, true); - streamMusicFull(fullpath); - } - } + void SoundManager::streamMusic(const std::string& filename) + { + if(mData->hasFile(filename, true)) + { + std::string fullpath = mData->convertPath(filename, true); + streamMusicFull(fullpath); + } + } void SoundManager::MP3Lookup(boost::filesystem::path dir) @@ -476,7 +478,7 @@ namespace MWSound return !mData->isPlaying(ptr, "_say_sound"); } - + void SoundManager::playSound (const std::string& soundId, float volume, float pitch) { if(!mData) return; diff --git a/apps/openmw/mwsound/soundmanager.hpp b/apps/openmw/mwsound/soundmanager.hpp index ec33f57a2..ab9559176 100644 --- a/apps/openmw/mwsound/soundmanager.hpp +++ b/apps/openmw/mwsound/soundmanager.hpp @@ -27,27 +27,28 @@ namespace MWSound // Hide implementation details - engine.cpp is compiling // enough as it is. struct SoundImpl; - + SoundImpl *mData; std::vector files; - bool fsStrict; - void streamMusicFull (const std::string& filename); + bool fsStrict; + + void streamMusicFull (const std::string& filename); ///< Play a soundifle /// \param absolute filename - + public: - SoundManager(Ogre::Root*, Ogre::Camera*, const ESMS::ESMStore &store, boost::filesystem::path dataDir, bool useSound, bool fsstrict); ~SoundManager(); - void streamMusic(const std::string& filename); - ///< Play a soundifle + void streamMusic(const std::string& filename); + ///< Play a soundifle /// \param filename name of a sound file in "Music/" in the data directory. + void startRandomTitle(); void MP3Lookup(boost::filesystem::path dir); - //struct SoundImpl; + bool isMusicPlaying(); SoundImpl getMData(); @@ -59,7 +60,7 @@ namespace MWSound bool sayDone (MWWorld::Ptr reference) const; ///< Is actor not speaking? - + void playSound (const std::string& soundId, float volume, float pitch); ///< Play a sound, independently of 3D-position diff --git a/components/bsa/bsa_archive.cpp b/components/bsa/bsa_archive.cpp index f1cf21710..f29b8b237 100644 --- a/components/bsa/bsa_archive.cpp +++ b/components/bsa/bsa_archive.cpp @@ -66,14 +66,13 @@ class DirArchive: public Ogre::FileSystemArchive public: DirArchive(const String& name) - : FileSystemArchive(name, "Dir") - { - mType = "Dir"; - currentdir = name; - std::string s = name; - cutoff = s.size() + 1; - if(fsstrict == false) - populateMap(currentdir); + : FileSystemArchive(name, "Dir"), currentdir (name) + { + mType = "Dir"; + std::string s = name; + cutoff = s.size() + 1; + if(fsstrict == false) + populateMap(currentdir); } void populateMap(boost::filesystem::path d){ @@ -134,11 +133,10 @@ class DirArchive: public Ogre::FileSystemArchive copy.erase(0, 1); } if(fsstrict == true) - { - //std::cout << "fsstrict " << copy << "\n"; - return FileSystemArchive::exists(copy); - - } + { + //std::cout << "fsstrict " << copy << "\n"; + return FileSystemArchive::exists(copy); + } int last = copy.size() - 1; @@ -185,9 +183,10 @@ class DirArchive: public Ogre::FileSystemArchive copy.erase(0, 1); } - if(fsstrict == true){ - return FileSystemArchive::open(copy, readonly); - } + if(fsstrict == true) + { + return FileSystemArchive::open(copy, readonly); + } int last = copy.size() - 1; @@ -199,7 +198,7 @@ class DirArchive: public Ogre::FileSystemArchive break; } - std::string folder = copy.substr(0, i); //folder with no slash + std::string folder = copy.substr(0, i); //folder with no slash std::vector current = mlocal[folder]; for(std::vector::iterator iter = current.begin(); iter != current.end(); iter++) diff --git a/components/esm_store/cell_store.hpp b/components/esm_store/cell_store.hpp index a55bb3d0e..43860dff3 100644 --- a/components/esm_store/cell_store.hpp +++ b/components/esm_store/cell_store.hpp @@ -14,7 +14,6 @@ #include "components/esm/records.hpp" #include "components/esm/loadcell.hpp" #include -#include #include #include @@ -30,8 +29,6 @@ namespace ESMS // The object that this instance is based on. const X* base; - Ogre::Entity *model; - /* Information about this instance, such as 3D location and rotation and individual type-dependent data. */ diff --git a/components/file_finder/file_finder.hpp b/components/file_finder/file_finder.hpp index 358563afa..0e1e07226 100644 --- a/components/file_finder/file_finder.hpp +++ b/components/file_finder/file_finder.hpp @@ -20,9 +20,9 @@ class FileFinderT void add(const boost::filesystem::path &pth) { - std::string file = pth.string(); - std::string key = file.substr(cut); - owner->table[key] = file; + std::string file = pth.string(); + std::string key = file.substr(cut); + owner->table[key] = file; } }; @@ -50,13 +50,13 @@ public: bool has(const std::string& file) const { - return table.find(file) != table.end(); + return table.find(file) != table.end(); } // Find the full path from a relative path. const std::string &lookup(const std::string& file) const { - return table.find(file)->second; + return table.find(file)->second; } }; diff --git a/components/files/multidircollection.hpp b/components/files/multidircollection.hpp index a4345fb82..898700c06 100644 --- a/components/files/multidircollection.hpp +++ b/components/files/multidircollection.hpp @@ -23,7 +23,7 @@ namespace Files return left -#include namespace Nif { @@ -435,266 +434,71 @@ public: class NiKeyframeData : public Record { - - //Rotations - std::vector quats; - std::vector tbc; - std::vector rottime; - int rtype; - - //Translations - std::vector translist1; - std::vector translist2; - std::vector translist3; - std::vector transtbc; - std::vector transtime; - int ttype; - - //Scalings - - std::vector scalefactor; - std::vector scaletime; - std::vector forwards; - std::vector backwards; - std::vector tbcscale; - int stype; - -public: - - void read(NIFFile *nif) - { - // Rotations first - int count = nif->getInt(); - //std::vector quat(count); - //std::vector rottime(count); - std::cout << "r"; - if(count) - { - - //TYPE1 LINEAR_KEY - //TYPE2 QUADRATIC_KEY - //TYPE3 TBC_KEY - //TYPE4 XYZ_ROTATION_KEY - //TYPE5 UNKNOWN_KEY - rtype = nif->getInt(); - //std::cout << "Count: " << count << "Type: " << type << "\n"; - - if(rtype == 1) - { - //We need to actually read in these values instead of skipping them - //nif->skip(count*4*5); // time + quaternion - for (int i = 0; i < count; i++) { - float time = nif->getFloat(); - float w = nif->getFloat(); - float x = nif->getFloat(); - float y = nif->getFloat(); - float z = nif->getFloat(); - Ogre::Quaternion quat = Ogre::Quaternion(Ogre::Real(w), Ogre::Real(x), Ogre::Real(y), Ogre::Real(z)); - quats.push_back(quat); - rottime.push_back(time); - //if(time == 0.0 || time > 355.5) - // std::cout <<"Time:" << time << "W:" << w <<"X:" << x << "Y:" << y << "Z:" << z << "\n"; - } - } - else if(rtype == 3) - { //Example - node 116 in base_anim.nif - for (int i = 0; i < count; i++) { - float time = nif->getFloat(); - float w = nif->getFloat(); - float x = nif->getFloat(); - float y = nif->getFloat(); - float z = nif->getFloat(); - - float tbcx = nif->getFloat(); - float tbcy = nif->getFloat(); - float tbcz = nif->getFloat(); - Ogre::Quaternion quat = Ogre::Quaternion(Ogre::Real(w), Ogre::Real(x), Ogre::Real(y), Ogre::Real(z)); - Ogre::Vector3 vec = Ogre::Vector3(tbcx, tbcy, tbcz); - quats.push_back(quat); - rottime.push_back(time); - tbc.push_back(vec); - //if(time == 0.0 || time > 355.5) - // std::cout <<"Time:" << time << "W:" << w <<"X:" << x << "Y:" << y << "Z:" << z << "\n"; - } - - //nif->skip(count*4*8); // rot1 + tension+bias+continuity - } - else if(rtype == 4) - { - for(int j=0;jgetFloat(); // time - for(int i=0; i<3; i++) - { - int cnt = nif->getInt(); - int type = nif->getInt(); - if(type == 1) - nif->skip(cnt*4*2); // time + unknown - else if(type == 2) - nif->skip(cnt*4*4); // time + unknown vector - else nif->fail("Unknown sub-rotation type"); - } - } - } - else nif->fail("Unknown rotation type in NiKeyframeData"); - } - //first = false; - - // Then translation - count = nif->getInt(); - - if(count) - { - ttype = nif->getInt(); - - //std::cout << "TransCount:" << count << " Type: " << type << "\n"; - if(ttype == 1) { - for (int i = 0; i < count; i++) { - float time = nif->getFloat(); - float x = nif->getFloat(); - float y = nif->getFloat(); - float z = nif->getFloat(); - Ogre::Vector3 trans = Ogre::Vector3(x, y, z); - translist1.push_back(trans); - transtime.push_back(time); - } - //nif->getFloatLen(count*4); // time + translation - } - else if(ttype == 2) - { //Example - node 116 in base_anim.nif - for (int i = 0; i < count; i++) { - float time = nif->getFloat(); - float x = nif->getFloat(); - float y = nif->getFloat(); - float z = nif->getFloat(); - float x2 = nif->getFloat(); - float y2 = nif->getFloat(); - float z2 = nif->getFloat(); - float x3 = nif->getFloat(); - float y3 = nif->getFloat(); - float z3 = nif->getFloat(); - Ogre::Vector3 trans = Ogre::Vector3(x, y, z); - Ogre::Vector3 trans2 = Ogre::Vector3(x2, y2, z2); - Ogre::Vector3 trans3 = Ogre::Vector3(x3, y3, z3); - transtime.push_back(time); - translist1.push_back(trans); - translist2.push_back(trans2); - translist3.push_back(trans3); - } - - //nif->getFloatLen(count*10); // trans1 + forward + backward - } - else if(ttype == 3){ - for (int i = 0; i < count; i++) { - float time = nif->getFloat(); - float x = nif->getFloat(); - float y = nif->getFloat(); - float z = nif->getFloat(); - float t = nif->getFloat(); - float b = nif->getFloat(); - float c = nif->getFloat(); - Ogre::Vector3 trans = Ogre::Vector3(x, y, z); - Ogre::Vector3 tbc = Ogre::Vector3(t, b, c); - translist1.push_back(trans); - transtbc.push_back(tbc); - transtime.push_back(time); - } - //nif->getFloatLen(count*7); // trans1 + tension,bias,continuity - } - else nif->fail("Unknown translation type"); - } - - // Finally, scalings - count = nif->getInt(); - if(count) - { - stype = nif->getInt(); - - - for(int i = 0; i < count; i++){ - - - //int size = 0; - if(stype >= 1 && stype < 4) - { - float time = nif->getFloat(); - float scale = nif->getFloat(); - scaletime.push_back(time); - scalefactor.push_back(scale); - //size = 2; // time+scale - } - else nif->fail("Unknown scaling type"); - if(stype == 2){ - //size = 4; // 1 + forward + backward (floats) - float forward = nif->getFloat(); - float backward = nif->getFloat(); - forwards.push_back(forward); - backwards.push_back(backward); - } - else if(stype == 3){ - float tbcx = nif->getFloat(); - float tbcy = nif->getFloat(); - float tbcz = nif->getFloat(); - Ogre::Vector3 vec = Ogre::Vector3(tbcx, tbcy, tbcz); - tbcscale.push_back(vec); - - //size = 5; // 1 + tbc - } - - } - } - else - stype = 0; - } - int getRtype(){ - return rtype; - } - int getStype(){ - return stype; - } - int getTtype(){ - return ttype; - } - std::vector getQuat(){ - return quats; - } - std::vector getrTbc(){ - return tbc; - } - std::vector getrTime(){ - return rottime; - } - - std::vector getTranslist1(){ - return translist1; - } - std::vector getTranslist2(){ - return translist2; - } - std::vector getTranslist3(){ - return translist3; - } - std::vector gettTime(){ - return transtime; - } - std::vector getScalefactor(){ - return scalefactor; - } - std::vector getForwards(){ - return forwards; - } - std::vector getBackwards(){ - return backwards; - } - std::vector getScaleTbc(){ - return tbcscale; - } - - std::vector getsTime(){ - return scaletime; - } + public: + + void read(NIFFile *nif) + { + // Rotations first + int count = nif->getInt(); + if(count) + { + int type = nif->getInt(); + + if(type == 1) + nif->skip(count*4*5); // time + quaternion + else if(type == 3) + nif->skip(count*4*8); // rot1 + tension+bias+continuity + else if(type == 4) + { + for(int j=0;jgetFloat(); // time + for(int i=0; i<3; i++) + { + int cnt = nif->getInt(); + int type = nif->getInt(); + if(type == 1) + nif->skip(cnt*4*2); // time + unknown + else if(type == 2) + nif->skip(cnt*4*4); // time + unknown vector + else nif->fail("Unknown sub-rotation type"); + } + } + } + else nif->fail("Unknown rotation type in NiKeyframeData"); + } + + // Then translation + count = nif->getInt(); + + if(count) + { + int type = nif->getInt(); + + if(type == 1) + nif->getFloatLen(count*4); // time + translation + else if(type == 2) + nif->getFloatLen(count*10); // trans1 + forward + backward + else if(type == 3) + nif->getFloatLen(count*7); // trans1 + tension,bias,continuity + else nif->fail("Unknown translation type"); + } + + // Finally, scalings + count = nif->getInt(); + if(count) + { + int type = nif->getInt(); + + int size = 0; + if(type == 1) size = 2; // time+scale + else if(type == 2) size = 4; // 1 + forward + backward (floats) + else if(type == 3) size = 5; // 1 + tbc + else nif->fail("Unknown scaling type"); + nif->getFloatLen(count*size); + } + } }; - } // Namespace #endif diff --git a/components/nifogre/ogre_nif_loader.cpp b/components/nifogre/ogre_nif_loader.cpp index 8219a224c..bdd9417a6 100644 --- a/components/nifogre/ogre_nif_loader.cpp +++ b/components/nifogre/ogre_nif_loader.cpp @@ -1068,11 +1068,6 @@ void NIFLoader::loadResource(Resource *resource) // Handle the node handleNode(node, 0, NULL, bounds, 0); - - short handle = 0; - //skel->setBlendMode(Ogre::SkeletonAnimationBlendMode::ANIMBLEND_CUMULATIVE); - bool first = true; - // set the bounding value. if (bounds.isValid()) { @@ -1081,16 +1076,6 @@ void NIFLoader::loadResource(Resource *resource) mesh->_setBoundingSphereRadius(bounds.getRadius()); } - - - - // set skeleton - if (!mSkel.isNull() && mesh->isLoaded()) - { - mesh->_notifySkeleton(mSkel); - std::cout << "Skeleton notified\n"; - } - // set skeleton // if (!skel.isNull()) // mesh->setSkeletonName(getSkeletonName()); diff --git a/components/nifogre/ogre_nif_loader.hpp b/components/nifogre/ogre_nif_loader.hpp index a619d3a3b..736d1ab1e 100644 --- a/components/nifogre/ogre_nif_loader.hpp +++ b/components/nifogre/ogre_nif_loader.hpp @@ -73,11 +73,11 @@ class NIFLoader : Ogre::ManualResourceLoader virtual void loadResource(Ogre::Resource *resource); - static Ogre::MeshPtr load(const std::string &name, + static Ogre::MeshPtr load(const std::string &name, const std::string &group="General"); - + Ogre::Vector3 convertVector3(const Nif::Vector& vec); Ogre::Quaternion convertRotation(const Nif::Matrix& rot); @@ -113,7 +113,7 @@ class NIFLoader : Ogre::ManualResourceLoader { return resourceName + ".skel"; } - + // This is the interface to the Ogre resource system. It allows us to // load NIFs from BSAs, in the file system and in any other place we // tell Ogre to look (eg. in zip or rar files.) It's also used to @@ -131,11 +131,7 @@ class NIFLoader : Ogre::ManualResourceLoader int counter; int numbers; int stack; - bool anim; - int handle2; - Ogre::Animation* animcore; - Ogre::Animation* animcore2; - + // pointer to the ogre mesh which is currently build Ogre::Mesh *mesh;