From e72e336e2464295bb389c276b3de4334f12f22af Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 5 Jan 2011 01:38:35 -0800 Subject: [PATCH 1/8] 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 c277832ab8..a64db189b5 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 2/8] Brainstorming --- apps/openmw/engine.cpp | 132 +++++++++---------------- 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, 76 insertions(+), 121 deletions(-) diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 9e14c119b1..d0f09c2148 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(); + + if (handle.empty()) + return; + + MWWorld::Ptr ptr = mEnvironment.mWorld->getPtrViaHandle (handle); + + if (ptr.isEmpty()) + return; + + MWScript::InterpreterContext interpreterContext (mEnvironment, + &ptr.getRefData().getLocals(), ptr); + + boost::shared_ptr action = + MWWorld::Class::get (ptr).activate (ptr, mEnvironment.mWorld->getPlayerPos().getPlayer(), + mEnvironment); + + interpreterContext.activate (ptr, action); + + std::string script = MWWorld::Class::get (ptr).getScript (ptr); + + if (!script.empty()) { - std::string handle = mEnvironment.mWorld->getFacedHandle(); - - if (handle.empty()) - return; - - MWWorld::Ptr ptr = mEnvironment.mWorld->getPtrViaHandle (handle); - - if (ptr.isEmpty()) - return; - - MWScript::InterpreterContext interpreterContext (mEnvironment, - &ptr.getRefData().getLocals(), ptr); - - boost::shared_ptr action = - MWWorld::Class::get (ptr).activate (ptr, mEnvironment.mWorld->getPlayerPos().getPlayer(), - mEnvironment); - - interpreterContext.activate (ptr, action); - - std::string script = MWWorld::Class::get (ptr).getScript (ptr); - - if (!script.empty()) - { - mIgnoreLocalPtr = ptr; - mScriptManager->run (script, interpreterContext); - } - - if (!interpreterContext.hasActivationBeenHandled()) - { - interpreterContext.executeActivation(); - } + mIgnoreLocalPtr = ptr; + mScriptManager->run (script, interpreterContext); } - catch (const std::exception& e) + + if (!interpreterContext.hasActivationBeenHandled()) { - std::cerr << "Activation failed: " << e.what() << std::endl; + interpreterContext.executeActivation(); } } - -void OMW::Engine::setCompileAll (bool all) -{ - mCompileAll = all; -} diff --git a/apps/openmw/mwgui/layouts.cpp b/apps/openmw/mwgui/layouts.cpp index 501b234d1f..e03805e65a 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 9eb6092ced..6caba62386 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 fc205d387e..7d4731b821 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 b2a6b50fdf..8f88c0fdb9 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 3/8] Reintroducing animation --- components/nif/data.hpp | 238 +++++++++++++++++++++++-- components/nifogre/ogre_nif_loader.cpp | 165 +++++++++++++++++ components/nifogre/ogre_nif_loader.hpp | 4 + 3 files changed, 388 insertions(+), 19 deletions(-) diff --git a/components/nif/data.hpp b/components/nif/data.hpp index 6fc2c4b820..bc23c45abe 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(); + ttype = 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 + //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(); + stype = 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); + + 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 a33fde55ad..3d63a9f989 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 6ab22aa2fa..a619d3a3b2 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 4/8] 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 78ddffbe8c..a6cdd2838e 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 43860dff38..a55bb3d0e2 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 3d63a9f989..a1254ed7f8 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 5/8] 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 8cde67671b..5316c8267e 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 272bfeeab4..727c9d3172 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 fe54af84ac..aa712dede5 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 93491f263e..87659a2135 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 dbacaacf95..d3ec9b4422 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 7c4b2aaf11..f77d3358d4 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 6/8] 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 244c63e511..6725497c15 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 bb5578f6dc..2b5bbbc4dd 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 d3ec9b4422..09cce2f6d3 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 4691eb5468..643845e250 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 bde6d9c3b3..91fd2fe987 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 bd0304e409..3f9ddad84c 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 7/8] 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 6725497c15..5c51ab5134 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 2b5bbbc4dd..6fab8841ad 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 643845e250..552084c419 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 8/8] 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 5c51ab5134..a899a5aea5 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 6fab8841ad..c6d0922537 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 552084c419..93bde48e3f 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); }