From 9126bb27b65b49a2dc6d63887789c16e85e49a2e Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Tue, 18 Oct 2011 19:50:19 -0400 Subject: [PATCH 001/104] empty functions --- apps/openmw/mwrender/rendering_manager.cpp | 33 ++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/apps/openmw/mwrender/rendering_manager.cpp b/apps/openmw/mwrender/rendering_manager.cpp index e7ef93858..f7a55aa5e 100644 --- a/apps/openmw/mwrender/rendering_manager.cpp +++ b/apps/openmw/mwrender/rendering_manager.cpp @@ -2,6 +2,8 @@ namespace MWRender { + + RenderingManager::RenderingManager (SkyManager *skyManager) : mSkyManager(skyManager) { @@ -13,6 +15,37 @@ RenderingManager::~RenderingManager () delete mSkyManager; } +void RenderingManager::removeCell (MWWorld::Ptr::CellStore *store){ + +} +void RenderingManager::addObject (const MWWorld::Ptr& ptr, MWWorld::Ptr::CellStore *store){ + +} +void RenderingManager::removeObject (const MWWorld::Ptr& ptr, MWWorld::Ptr::CellStore *store){ + +} +void RenderingManager::moveObject (const MWWorld::Ptr& ptr, const Ogre::Vector3& position){ + +} +void RenderingManager::scaleObject (const MWWorld::Ptr& ptr, const Ogre::Vector3& scale){ + +} +void RenderingManager::rotateObject (const MWWorld::Ptr& ptr, const::Ogre::Quaternion& orientation){ + +} +void RenderingManager::moveObjectToCell (const MWWorld::Ptr& ptr, const Ogre::Vector3& position, MWWorld::Ptr::CellStore *store){ + +} +void RenderingManager::setPhysicsDebugRendering (bool){ + +} +bool RenderingManager::getPhysicsDebugRendering() const{ + return true; +} +void RenderingManager::update (float duration){ + + + void RenderingManager::skyEnable () { mSkyManager->enable(); From 0992f1e9036b381e2e49b04323040e5262033a15 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Tue, 18 Oct 2011 21:02:42 -0400 Subject: [PATCH 002/104] Applying Gus's Windows fix --- apps/openmw/mwrender/rendering_manager.cpp | 1 + components/files/path.hpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwrender/rendering_manager.cpp b/apps/openmw/mwrender/rendering_manager.cpp index f7a55aa5e..e648a6451 100644 --- a/apps/openmw/mwrender/rendering_manager.cpp +++ b/apps/openmw/mwrender/rendering_manager.cpp @@ -45,6 +45,7 @@ bool RenderingManager::getPhysicsDebugRendering() const{ void RenderingManager::update (float duration){ +} void RenderingManager::skyEnable () { diff --git a/components/files/path.hpp b/components/files/path.hpp index 0788cefb1..23c702bbb 100644 --- a/components/files/path.hpp +++ b/components/files/path.hpp @@ -30,7 +30,7 @@ #include namespace Files { typedef LinuxPath TargetPathType; } -#elif defined(__WIN32) || defined(__WINDOWS__) +#elif defined(__WIN32) || defined(__WINDOWS__) || defined (_WINDOWS) #include namespace Files { typedef WindowsPath TargetPathType; } From c52ae6825f1a4d033aceaa79c275c0770ff1a946 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Tue, 18 Oct 2011 21:04:31 -0400 Subject: [PATCH 003/104] Applying Gus's Windows fix2 --- components/files/windowspath.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/components/files/windowspath.cpp b/components/files/windowspath.cpp index f42f149c1..0b913d8ea 100644 --- a/components/files/windowspath.cpp +++ b/components/files/windowspath.cpp @@ -5,7 +5,10 @@ #include #include -#include +#include + +#include +#pragma comment(lib, "Shlwapi.lib") namespace Files { From d0f922ec5d3419880f090fe77c42be7ad310a92c Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Thu, 20 Oct 2011 13:55:56 -0400 Subject: [PATCH 004/104] Moved SkyManager creation --- apps/openmw/mwrender/rendering_manager.cpp | 5 ++--- apps/openmw/mwrender/rendering_manager.hpp | 3 ++- apps/openmw/mwworld/world.cpp | 4 +--- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/apps/openmw/mwrender/rendering_manager.cpp b/apps/openmw/mwrender/rendering_manager.cpp index e648a6451..afa63fc3e 100644 --- a/apps/openmw/mwrender/rendering_manager.cpp +++ b/apps/openmw/mwrender/rendering_manager.cpp @@ -4,10 +4,9 @@ namespace MWRender { -RenderingManager::RenderingManager (SkyManager *skyManager) : - mSkyManager(skyManager) +RenderingManager::RenderingManager (Ogre::RenderWindow* window, Ogre::Camera* cam, const boost::filesystem2::path& resDir) { - + mSkyManager = MWRender::SkyManager::create(window, cam, resDir); } RenderingManager::~RenderingManager () diff --git a/apps/openmw/mwrender/rendering_manager.hpp b/apps/openmw/mwrender/rendering_manager.hpp index d456716d3..ac14ee389 100644 --- a/apps/openmw/mwrender/rendering_manager.hpp +++ b/apps/openmw/mwrender/rendering_manager.hpp @@ -7,13 +7,14 @@ #include "../mwworld/ptr.hpp" #include #include +#include namespace MWRender { class RenderingManager { public: - RenderingManager(SkyManager *skyManager); + RenderingManager(Ogre::RenderWindow* window, Ogre::Camera* cam, const boost::filesystem2::path& resDir); ~RenderingManager(); void removeCell (MWWorld::Ptr::CellStore *store); // TODO do we want this? diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index 78827f150..cee73a433 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -207,9 +207,7 @@ namespace MWWorld mPhysEngine = physEng; mWorldScene = new Scene(environment, this, mScene, mPhysics); - mRenderingManager = new MWRender::RenderingManager( - MWRender::SkyManager::create(renderer.getWindow(), mScene.getCamera(), resDir) - ); + mRenderingManager = new MWRender::RenderingManager(renderer.getWindow(), mScene.getCamera(), resDir); } World::~World() From 3315de8b4a5aced23163c2af7183fe3ba2f07229 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Thu, 20 Oct 2011 15:02:19 -0400 Subject: [PATCH 005/104] Naming convention change --- apps/openmw/CMakeLists.txt | 4 +- apps/openmw/mwrender/renderingmanager.cpp | 85 +++++++++++++++++++++++ apps/openmw/mwrender/renderingmanager.hpp | 52 ++++++++++++++ apps/openmw/mwworld/world.hpp | 2 +- 4 files changed, 140 insertions(+), 3 deletions(-) create mode 100644 apps/openmw/mwrender/renderingmanager.cpp create mode 100644 apps/openmw/mwrender/renderingmanager.hpp diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index 54abb948a..9510273af 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -16,7 +16,7 @@ set(GAME_HEADER source_group(game FILES ${GAME} ${GAME_HEADER}) set(GAMEREND - mwrender/rendering_manager.cpp + mwrender/renderingmanager.cpp mwrender/mwscene.cpp mwrender/cellimp.cpp mwrender/interior.cpp @@ -25,7 +25,7 @@ set(GAMEREND mwrender/player.cpp ) set(GAMEREND_HEADER - mwrender/rendering_manager.hpp + mwrender/renderingmanager.hpp mwrender/cell.hpp mwrender/cellimp.hpp mwrender/mwscene.hpp diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp new file mode 100644 index 000000000..f083d206d --- /dev/null +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -0,0 +1,85 @@ +#include "renderingmanager.hpp" + +namespace MWRender { + + + +RenderingManager::RenderingManager (Ogre::RenderWindow* window, Ogre::Camera* cam, const boost::filesystem2::path& resDir) +{ + mSkyManager = MWRender::SkyManager::create(window, cam, resDir); +} + +RenderingManager::~RenderingManager () +{ + delete mSkyManager; +} + +void RenderingManager::removeCell (MWWorld::Ptr::CellStore *store){ + +} +void RenderingManager::addObject (const MWWorld::Ptr& ptr, MWWorld::Ptr::CellStore *store){ + +} +void RenderingManager::removeObject (const MWWorld::Ptr& ptr, MWWorld::Ptr::CellStore *store){ + +} +void RenderingManager::moveObject (const MWWorld::Ptr& ptr, const Ogre::Vector3& position){ + +} +void RenderingManager::scaleObject (const MWWorld::Ptr& ptr, const Ogre::Vector3& scale){ + +} +void RenderingManager::rotateObject (const MWWorld::Ptr& ptr, const::Ogre::Quaternion& orientation){ + +} +void RenderingManager::moveObjectToCell (const MWWorld::Ptr& ptr, const Ogre::Vector3& position, MWWorld::Ptr::CellStore *store){ + +} +void RenderingManager::setPhysicsDebugRendering (bool){ + +} +bool RenderingManager::getPhysicsDebugRendering() const{ + return true; +} +void RenderingManager::update (float duration){ + + +} + +void RenderingManager::skyEnable () +{ + mSkyManager->enable(); +} + +void RenderingManager::skyDisable () +{ + mSkyManager->disable(); +} + +void RenderingManager::skySetHour (double hour) +{ + mSkyManager->setHour(hour); +} + + +void RenderingManager::skySetDate (int day, int month) +{ + mSkyManager->setDate(day, month); +} + +int RenderingManager::skyGetMasserPhase() const +{ + return mSkyManager->getMasserPhase(); +} + +int RenderingManager::skyGetSecundaPhase() const +{ + return mSkyManager->getSecundaPhase(); +} + +void RenderingManager::skySetMoonColour (bool red) +{ + mSkyManager->setMoonColour(red); +} + +} diff --git a/apps/openmw/mwrender/renderingmanager.hpp b/apps/openmw/mwrender/renderingmanager.hpp new file mode 100644 index 000000000..ac14ee389 --- /dev/null +++ b/apps/openmw/mwrender/renderingmanager.hpp @@ -0,0 +1,52 @@ +#ifndef _GAME_RENDERING_MANAGER_H +#define _GAME_RENDERING_MANAGER_H + + +#include "sky.hpp" + +#include "../mwworld/ptr.hpp" +#include +#include +#include + +namespace MWRender +{ + +class RenderingManager { + public: + RenderingManager(Ogre::RenderWindow* window, Ogre::Camera* cam, const boost::filesystem2::path& resDir); + ~RenderingManager(); + + void removeCell (MWWorld::Ptr::CellStore *store); // TODO do we want this? + + void addObject (const MWWorld::Ptr& ptr, MWWorld::Ptr::CellStore *store); + void removeObject (const MWWorld::Ptr& ptr, MWWorld::Ptr::CellStore *store); + + void moveObject (const MWWorld::Ptr& ptr, const Ogre::Vector3& position); + void scaleObject (const MWWorld::Ptr& ptr, const Ogre::Vector3& scale); + void rotateObject (const MWWorld::Ptr& ptr, const::Ogre::Quaternion& orientation); + void moveObjectToCell (const MWWorld::Ptr& ptr, const Ogre::Vector3& position, MWWorld::Ptr::CellStore *store); + + void setPhysicsDebugRendering (bool); + bool getPhysicsDebugRendering() const; + + void update (float duration); + + void skyEnable (); + void skyDisable (); + void skySetHour (double hour); + void skySetDate (int day, int month); + int skyGetMasserPhase() const; + int skyGetSecundaPhase() const; + void skySetMoonColour (bool red); + + private: + + SkyManager* mSkyManager; + + +}; + +} + +#endif diff --git a/apps/openmw/mwworld/world.hpp b/apps/openmw/mwworld/world.hpp index 978f14c8e..e661ef362 100644 --- a/apps/openmw/mwworld/world.hpp +++ b/apps/openmw/mwworld/world.hpp @@ -9,7 +9,7 @@ #include #include "../mwrender/mwscene.hpp" -#include "../mwrender/rendering_manager.hpp" +#include "../mwrender/renderingmanager.hpp" #include "refdata.hpp" #include "ptr.hpp" From fcf404d27b435d20bcf0867454e00011ead87375 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Thu, 20 Oct 2011 18:15:30 -0400 Subject: [PATCH 006/104] GetFacedHandle in Physics. RenderingManager constructor code added --- apps/openmw/mwrender/renderingmanager.cpp | 56 ++++++++++++++++++++++- apps/openmw/mwrender/renderingmanager.hpp | 42 +++++++++++++++-- apps/openmw/mwworld/physicssystem.cpp | 17 +++++++ apps/openmw/mwworld/physicssystem.hpp | 1 + apps/openmw/mwworld/world.cpp | 3 +- 5 files changed, 113 insertions(+), 6 deletions(-) diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index f083d206d..095323dea 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -1,12 +1,64 @@ #include "renderingmanager.hpp" +#include + +#include "OgreRoot.h" +#include "OgreRenderWindow.h" +#include "OgreSceneManager.h" +#include "OgreViewport.h" +#include "OgreCamera.h" +#include "OgreTextureManager.h" + +#include "../mwworld/world.hpp" // these includes can be removed once the static-hack is gone +#include "../mwworld/ptr.hpp" +#include + +#include "player.hpp" + +using namespace MWRender; +using namespace Ogre; + namespace MWRender { -RenderingManager::RenderingManager (Ogre::RenderWindow* window, Ogre::Camera* cam, const boost::filesystem2::path& resDir) +RenderingManager::RenderingManager (OEngine::Render::OgreRenderer& _rend, const boost::filesystem2::path& resDir) :rend(_rend) { - mSkyManager = MWRender::SkyManager::create(window, cam, resDir); + camera = rend.getCamera(); + mSkyManager = MWRender::SkyManager::create(rend.getWindow(), camera, resDir); + + + rend.createScene("PlayerCam", 55, 5); + + // Set default mipmap level (NB some APIs ignore this) + TextureManager::getSingleton().setDefaultNumMipmaps(5); + + // Load resources + ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); + + // Turn the entire scene (represented by the 'root' node) -90 + // degrees around the x axis. This makes Z go upwards, and Y go into + // the screen (when x is to the right.) This is the orientation that + // Morrowind uses, and it automagically makes everything work as it + // should. + + SceneNode *rt = rend.getScene()->getRootSceneNode(); + mwRoot = rt->createChildSceneNode(); + mwRoot->pitch(Degree(-90)); + + //used to obtain ingame information of ogre objects (which are faced or selected) + mRaySceneQuery = rend.getScene()->createRayQuery(Ray()); + + Ogre::SceneNode *playerNode = mwRoot->createChildSceneNode ("player"); + playerNode->pitch(Degree(90)); + Ogre::SceneNode *cameraYawNode = playerNode->createChildSceneNode(); + Ogre::SceneNode *cameraPitchNode = cameraYawNode->createChildSceneNode(); + cameraPitchNode->attachObject(camera); + + + mPlayer = new MWRender::Player (camera, playerNode->getName()); + + } RenderingManager::~RenderingManager () diff --git a/apps/openmw/mwrender/renderingmanager.hpp b/apps/openmw/mwrender/renderingmanager.hpp index ac14ee389..ec03e970a 100644 --- a/apps/openmw/mwrender/renderingmanager.hpp +++ b/apps/openmw/mwrender/renderingmanager.hpp @@ -4,17 +4,53 @@ #include "sky.hpp" -#include "../mwworld/ptr.hpp" +#include #include #include + +#include +#include + +#include "../mwworld/ptr.hpp" + #include -namespace MWRender +namespace Ogre { + class Camera; + class Viewport; + class SceneManager; + class SceneNode; + class RaySceneQuery; + class Quaternion; + class Vector3; +} +namespace MWWorld +{ + class World; +} + +namespace MWRender +{ + class Player; class RenderingManager { + + OEngine::Render::OgreRenderer &rend; + Ogre::Camera* camera; + + /// Root node for all objects added to the scene. This is rotated so + /// that the OGRE coordinate system matches that used internally in + /// Morrowind. + Ogre::SceneNode *mwRoot; + Ogre::RaySceneQuery *mRaySceneQuery; + + OEngine::Physic::PhysicEngine* eng; + + MWRender::Player *mPlayer; + public: - RenderingManager(Ogre::RenderWindow* window, Ogre::Camera* cam, const boost::filesystem2::path& resDir); + RenderingManager(OEngine::Render::OgreRenderer& _rend, const boost::filesystem2::path& resDir); ~RenderingManager(); void removeCell (MWWorld::Ptr::CellStore *store); // TODO do we want this? diff --git a/apps/openmw/mwworld/physicssystem.cpp b/apps/openmw/mwworld/physicssystem.cpp index fa617a9c7..b06fa1a48 100644 --- a/apps/openmw/mwworld/physicssystem.cpp +++ b/apps/openmw/mwworld/physicssystem.cpp @@ -10,6 +10,7 @@ #include "OgreTextureManager.h" +using namespace Ogre; namespace MWWorld { @@ -23,6 +24,22 @@ namespace MWWorld { } + std::pair PhysicsSystem::getFacedHandle (MWWorld::World& world) + { + std::string handle = ""; + + //get a ray pointing to the center of the viewport + Ray centerRay = mRender.getCamera()->getCameraToViewportRay( + mRender.getViewport()->getWidth()/2, + mRender.getViewport()->getHeight()/2); + //let's avoid the capsule shape of the player. + centerRay.setOrigin(centerRay.getOrigin() + 20*centerRay.getDirection()); + btVector3 from(centerRay.getOrigin().x,-centerRay.getOrigin().z,centerRay.getOrigin().y); + btVector3 to(centerRay.getPoint(500).x,-centerRay.getPoint(500).z,centerRay.getPoint(500).y); + + return mEngine->rayTest(from,to); + } + std::vector< std::pair > PhysicsSystem::doPhysics (float duration, const std::vector >& actors) diff --git a/apps/openmw/mwworld/physicssystem.hpp b/apps/openmw/mwworld/physicssystem.hpp index 7f7bfdcbb..17640c074 100644 --- a/apps/openmw/mwworld/physicssystem.hpp +++ b/apps/openmw/mwworld/physicssystem.hpp @@ -32,6 +32,7 @@ namespace MWWorld void scaleObject (const std::string& handle, float scale); bool toggleCollisionMode(); + std::pair getFacedHandle (MWWorld::World& world); private: OEngine::Render::OgreRenderer &mRender; diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index cee73a433..4174e6457 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -207,7 +207,8 @@ namespace MWWorld mPhysEngine = physEng; mWorldScene = new Scene(environment, this, mScene, mPhysics); - mRenderingManager = new MWRender::RenderingManager(renderer.getWindow(), mScene.getCamera(), resDir); + mRenderingManager = new MWRender::RenderingManager(renderer, + resDir); } World::~World() From 47593f3641fbbd8ffef4d595a5f4502f71356a6a Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Thu, 20 Oct 2011 19:35:49 -0400 Subject: [PATCH 007/104] Removing old files --- apps/openmw/mwrender/rendering_manager.cpp | 85 ---------------------- apps/openmw/mwrender/rendering_manager.hpp | 52 ------------- 2 files changed, 137 deletions(-) delete mode 100644 apps/openmw/mwrender/rendering_manager.cpp delete mode 100644 apps/openmw/mwrender/rendering_manager.hpp diff --git a/apps/openmw/mwrender/rendering_manager.cpp b/apps/openmw/mwrender/rendering_manager.cpp deleted file mode 100644 index afa63fc3e..000000000 --- a/apps/openmw/mwrender/rendering_manager.cpp +++ /dev/null @@ -1,85 +0,0 @@ -#include "rendering_manager.hpp" - -namespace MWRender { - - - -RenderingManager::RenderingManager (Ogre::RenderWindow* window, Ogre::Camera* cam, const boost::filesystem2::path& resDir) -{ - mSkyManager = MWRender::SkyManager::create(window, cam, resDir); -} - -RenderingManager::~RenderingManager () -{ - delete mSkyManager; -} - -void RenderingManager::removeCell (MWWorld::Ptr::CellStore *store){ - -} -void RenderingManager::addObject (const MWWorld::Ptr& ptr, MWWorld::Ptr::CellStore *store){ - -} -void RenderingManager::removeObject (const MWWorld::Ptr& ptr, MWWorld::Ptr::CellStore *store){ - -} -void RenderingManager::moveObject (const MWWorld::Ptr& ptr, const Ogre::Vector3& position){ - -} -void RenderingManager::scaleObject (const MWWorld::Ptr& ptr, const Ogre::Vector3& scale){ - -} -void RenderingManager::rotateObject (const MWWorld::Ptr& ptr, const::Ogre::Quaternion& orientation){ - -} -void RenderingManager::moveObjectToCell (const MWWorld::Ptr& ptr, const Ogre::Vector3& position, MWWorld::Ptr::CellStore *store){ - -} -void RenderingManager::setPhysicsDebugRendering (bool){ - -} -bool RenderingManager::getPhysicsDebugRendering() const{ - return true; -} -void RenderingManager::update (float duration){ - - -} - -void RenderingManager::skyEnable () -{ - mSkyManager->enable(); -} - -void RenderingManager::skyDisable () -{ - mSkyManager->disable(); -} - -void RenderingManager::skySetHour (double hour) -{ - mSkyManager->setHour(hour); -} - - -void RenderingManager::skySetDate (int day, int month) -{ - mSkyManager->setDate(day, month); -} - -int RenderingManager::skyGetMasserPhase() const -{ - return mSkyManager->getMasserPhase(); -} - -int RenderingManager::skyGetSecundaPhase() const -{ - return mSkyManager->getSecundaPhase(); -} - -void RenderingManager::skySetMoonColour (bool red) -{ - mSkyManager->setMoonColour(red); -} - -} diff --git a/apps/openmw/mwrender/rendering_manager.hpp b/apps/openmw/mwrender/rendering_manager.hpp deleted file mode 100644 index ac14ee389..000000000 --- a/apps/openmw/mwrender/rendering_manager.hpp +++ /dev/null @@ -1,52 +0,0 @@ -#ifndef _GAME_RENDERING_MANAGER_H -#define _GAME_RENDERING_MANAGER_H - - -#include "sky.hpp" - -#include "../mwworld/ptr.hpp" -#include -#include -#include - -namespace MWRender -{ - -class RenderingManager { - public: - RenderingManager(Ogre::RenderWindow* window, Ogre::Camera* cam, const boost::filesystem2::path& resDir); - ~RenderingManager(); - - void removeCell (MWWorld::Ptr::CellStore *store); // TODO do we want this? - - void addObject (const MWWorld::Ptr& ptr, MWWorld::Ptr::CellStore *store); - void removeObject (const MWWorld::Ptr& ptr, MWWorld::Ptr::CellStore *store); - - void moveObject (const MWWorld::Ptr& ptr, const Ogre::Vector3& position); - void scaleObject (const MWWorld::Ptr& ptr, const Ogre::Vector3& scale); - void rotateObject (const MWWorld::Ptr& ptr, const::Ogre::Quaternion& orientation); - void moveObjectToCell (const MWWorld::Ptr& ptr, const Ogre::Vector3& position, MWWorld::Ptr::CellStore *store); - - void setPhysicsDebugRendering (bool); - bool getPhysicsDebugRendering() const; - - void update (float duration); - - void skyEnable (); - void skyDisable (); - void skySetHour (double hour); - void skySetDate (int day, int month); - int skyGetMasserPhase() const; - int skyGetSecundaPhase() const; - void skySetMoonColour (bool red); - - private: - - SkyManager* mSkyManager; - - -}; - -} - -#endif From 30ba9b74daf60afd7d781423e6c9cef23f9ddab3 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Sat, 22 Oct 2011 00:15:15 -0400 Subject: [PATCH 008/104] Simple Debugging class --- apps/openmw/mwrender/mwscene.cpp | 18 ++++++++++++++++++ apps/openmw/mwrender/mwscene.hpp | 9 +++++++++ apps/openmw/mwrender/renderingmanager.hpp | 2 ++ 3 files changed, 29 insertions(+) diff --git a/apps/openmw/mwrender/mwscene.cpp b/apps/openmw/mwrender/mwscene.cpp index 900b4d249..cabed7bee 100644 --- a/apps/openmw/mwrender/mwscene.cpp +++ b/apps/openmw/mwrender/mwscene.cpp @@ -18,6 +18,24 @@ using namespace MWRender; using namespace Ogre; +Debugging::Debugging(OEngine::Physic::PhysicEngine* engine){ + eng = engine; +} + +bool Debugging::toggleRenderMode (int mode){ + switch (mode) + { + case MWWorld::World::Render_CollisionDebug: + + // TODO use a proper function instead of accessing the member variable + // directly. + eng->setDebugRenderingMode (!eng->isDebugCreated); + return eng->isDebugCreated; + } + + return false; +} + MWScene::MWScene(OEngine::Render::OgreRenderer &_rend , OEngine::Physic::PhysicEngine* physEng) : rend(_rend) { diff --git a/apps/openmw/mwrender/mwscene.hpp b/apps/openmw/mwrender/mwscene.hpp index 918679035..d68fb6ad5 100644 --- a/apps/openmw/mwrender/mwscene.hpp +++ b/apps/openmw/mwrender/mwscene.hpp @@ -28,6 +28,15 @@ namespace MWRender { class Player; + class Debugging{ + OEngine::Physic::PhysicEngine* eng; + + + public: + Debugging(OEngine::Physic::PhysicEngine* engine); + bool toggleRenderMode (int mode); + }; + /// \brief 3D-scene (rendering and physics) class MWScene diff --git a/apps/openmw/mwrender/renderingmanager.hpp b/apps/openmw/mwrender/renderingmanager.hpp index ec03e970a..8c76f8f26 100644 --- a/apps/openmw/mwrender/renderingmanager.hpp +++ b/apps/openmw/mwrender/renderingmanager.hpp @@ -34,6 +34,8 @@ namespace MWWorld namespace MWRender { class Player; + + class RenderingManager { OEngine::Render::OgreRenderer &rend; From 6efc61b9dfc131a2863bb8c6fd3f88c8965df62d Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Mon, 24 Oct 2011 13:42:36 -0400 Subject: [PATCH 009/104] Removal of MWScene; Object listing fixed --- apps/openmw/engine.cpp | 11 +++- apps/openmw/mwrender/exterior.cpp | 43 +++++++------- apps/openmw/mwrender/exterior.hpp | 6 +- apps/openmw/mwrender/interior.cpp | 33 ++++++----- apps/openmw/mwrender/interior.hpp | 8 +-- apps/openmw/mwrender/mwscene.cpp | 71 +---------------------- apps/openmw/mwrender/mwscene.hpp | 40 ------------- apps/openmw/mwrender/renderingmanager.cpp | 20 ++++--- apps/openmw/mwrender/renderingmanager.hpp | 8 ++- apps/openmw/mwworld/scene.cpp | 8 +-- apps/openmw/mwworld/scene.hpp | 6 +- apps/openmw/mwworld/world.cpp | 37 ++++++------ apps/openmw/mwworld/world.hpp | 4 +- 13 files changed, 100 insertions(+), 195 deletions(-) diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 4e58e8a4c..90b476df7 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -68,20 +68,25 @@ void OMW::Engine::executeLocalScripts() void OMW::Engine::updateFocusReport (float duration) { + if ((mFocusTDiff += duration)>0.25) { mFocusTDiff = 0; std::string name; - + std::string handle = mEnvironment.mWorld->getFacedHandle(); if (!handle.empty()) { MWWorld::Ptr ptr = mEnvironment.mWorld->getPtrViaHandle (handle); - if (!ptr.isEmpty()) + if (!ptr.isEmpty()){ name = MWWorld::Class::get (ptr).getName (ptr); + if (!name.empty()) + std::cout << "Object: " << name << std::endl; + + } } if (name!=mFocusName) @@ -284,6 +289,8 @@ void OMW::Engine::setReportFocus (bool report) void OMW::Engine::go() { + mFocusTDiff = 0; + mReportFocus = true; assert (!mEnvironment.mWorld); assert (!mCellName.empty()); assert (!mMaster.empty()); diff --git a/apps/openmw/mwrender/exterior.cpp b/apps/openmw/mwrender/exterior.cpp index 9dd82c68f..9cc8fd564 100644 --- a/apps/openmw/mwrender/exterior.cpp +++ b/apps/openmw/mwrender/exterior.cpp @@ -1,4 +1,5 @@ #include "exterior.hpp" +#include "renderingmanager.hpp" #include #include @@ -34,11 +35,11 @@ bool ExteriorCellRender::lightOutQuadInLin = false; int ExteriorCellRender::uniqueID = 0; ExteriorCellRender::ExteriorCellRender(ESMS::CellStore &_cell, MWWorld::Environment& environment, - MWScene &_scene, MWWorld::PhysicsSystem *physics) - : mCell(_cell), mEnvironment (environment), mScene(_scene), mPhysics(physics), mBase(NULL), mInsert(NULL), mAmbientMode (0) + RenderingManager &_rendering, MWWorld::PhysicsSystem *physics) + : mCell(_cell), mEnvironment (environment), mRendering(_rendering), mPhysics(physics), mBase(NULL), mInsert(NULL), mAmbientMode (0) { uniqueID = uniqueID +1; - sg = mScene.getMgr()->createStaticGeometry( "sg" + Ogre::StringConverter::toString(uniqueID)); + sg = mRendering.getMgr()->createStaticGeometry( "sg" + Ogre::StringConverter::toString(uniqueID)); } @@ -126,7 +127,7 @@ void ExteriorCellRender::insertMesh(const std::string &mesh, Ogre::Vector3 vec, mNpcPart = parent->createChildSceneNode(sceneNodeName); MeshPtr good2 = NifOgre::NIFLoader::load(mesh); - MovableObject *ent = mScene.getMgr()->createEntity(mesh); + MovableObject *ent = mRendering.getMgr()->createEntity(mesh); if(translateFirst){ @@ -214,7 +215,7 @@ void ExteriorCellRender::insertMesh(const std::string &mesh) assert (mInsert); NifOgre::NIFLoader::load(mesh); - Entity *ent = mScene.getMgr()->createEntity(mesh); + Entity *ent = mRendering.getMgr()->createEntity(mesh); if(!isStatic) { @@ -224,7 +225,7 @@ void ExteriorCellRender::insertMesh(const std::string &mesh) { sg->addEntity(ent,mInsert->_getDerivedPosition(),mInsert->_getDerivedOrientation(),mInsert->_getDerivedScale()); sg->setRegionDimensions(Ogre::Vector3(100000,10000,100000)); - mScene.getMgr()->destroyEntity(ent); + mRendering.getMgr()->destroyEntity(ent); } if (mInsertMesh.empty()) mInsertMesh = mesh; @@ -249,7 +250,7 @@ void ExteriorCellRender::insertLight(float r, float g, float b, float radius) { assert (mInsert); - Ogre::Light *light = mScene.getMgr()->createLight(); + Ogre::Light *light = mRendering.getMgr()->createLight(); light->setDiffuseColour (r, g, b); float cval=0.0f, lval=0.0f, qval=0.0f; @@ -305,7 +306,7 @@ void ExteriorCellRender::configureAmbient() // Create a "sun" that shines light downwards. It doesn't look // completely right, but leave it for now. - Ogre::Light *light = mScene.getMgr()->createLight(); + Ogre::Light *light = mRendering.getMgr()->createLight(); Ogre::ColourValue colour; colour.setAsABGR (mCell.cell->ambi.sunlight); light->setDiffuseColour (colour); @@ -322,9 +323,9 @@ void ExteriorCellRender::configureFog() float high = 4500 + 9000 * (1-mCell.cell->ambi.fogDensity); float low = 200; - mScene.getMgr()->setFog (FOG_LINEAR, color, 0, low, high); - mScene.getCamera()->setFarClipDistance (high + 10); - mScene.getViewport()->setBackgroundColour (color); + mRendering.getMgr()->setFog (FOG_LINEAR, color, 0, low, high); + mRendering.getCamera()->setFarClipDistance (high + 10); + mRendering.getViewport()->setBackgroundColour (color); } void ExteriorCellRender::setAmbientMode() @@ -333,17 +334,17 @@ void ExteriorCellRender::setAmbientMode() { case 0: - mScene.getMgr()->setAmbientLight(mAmbientColor); + mRendering.getMgr()->setAmbientLight(mAmbientColor); break; case 1: - mScene.getMgr()->setAmbientLight(0.7f*mAmbientColor + 0.3f*ColourValue(1,1,1)); + mRendering.getMgr()->setAmbientLight(0.7f*mAmbientColor + 0.3f*ColourValue(1,1,1)); break; case 2: - mScene.getMgr()->setAmbientLight(ColourValue(1,1,1)); + mRendering.getMgr()->setAmbientLight(ColourValue(1,1,1)); break; } } @@ -351,7 +352,7 @@ void ExteriorCellRender::setAmbientMode() void ExteriorCellRender::show() { // FIXME: this one may be the bug - mBase = mScene.getRoot()->createChildSceneNode(); + mBase = mRendering.getRoot()->createChildSceneNode(); configureAmbient(); configureFog(); @@ -400,14 +401,14 @@ void ExteriorCellRender::destroy() { destroyAllAttachedMovableObjects(mBase); mBase->removeAndDestroyAllChildren(); - mScene.getMgr()->destroySceneNode(mBase); + mRendering.getMgr()->destroySceneNode(mBase); } mBase = 0; if (sg) { - mScene.getMgr()->destroyStaticGeometry (sg); + mRendering.getMgr()->destroyStaticGeometry (sg); sg = 0; } } @@ -434,21 +435,21 @@ void ExteriorCellRender::toggleLight() void ExteriorCellRender::enable (const std::string& handle) { if (!handle.empty()) - mScene.getMgr()->getSceneNode (handle)->setVisible (true); + mRendering.getMgr()->getSceneNode (handle)->setVisible (true); } void ExteriorCellRender::disable (const std::string& handle) { if (!handle.empty()) - mScene.getMgr()->getSceneNode (handle)->setVisible (false); + mRendering.getMgr()->getSceneNode (handle)->setVisible (false); } void ExteriorCellRender::deleteObject (const std::string& handle) { if (!handle.empty()) { - Ogre::SceneNode *node = mScene.getMgr()->getSceneNode (handle); + Ogre::SceneNode *node = mRendering.getMgr()->getSceneNode (handle); node->removeAndDestroyAllChildren(); - mScene.getMgr()->destroySceneNode (node); + mRendering.getMgr()->destroySceneNode (node); } } diff --git a/apps/openmw/mwrender/exterior.hpp b/apps/openmw/mwrender/exterior.hpp index d8f6b9b96..17973db46 100644 --- a/apps/openmw/mwrender/exterior.hpp +++ b/apps/openmw/mwrender/exterior.hpp @@ -21,7 +21,7 @@ namespace MWWorld namespace MWRender { - class MWScene; + class RenderingManager; /** This class is responsible for inserting meshes and other @@ -49,7 +49,7 @@ namespace MWRender ESMS::CellStore &mCell; MWWorld::Environment &mEnvironment; - MWScene &mScene; + RenderingManager &mRendering; MWWorld::PhysicsSystem *mPhysics; /// The scene node that contains all objects belonging to this @@ -103,7 +103,7 @@ namespace MWRender public: ExteriorCellRender(ESMS::CellStore &_cell, MWWorld::Environment& environment, - MWScene &_scene, MWWorld::PhysicsSystem *physics); + RenderingManager &_rendering, MWWorld::PhysicsSystem *physics); virtual ~ExteriorCellRender() { destroy(); } diff --git a/apps/openmw/mwrender/interior.cpp b/apps/openmw/mwrender/interior.cpp index bfde4b04e..13149eb55 100644 --- a/apps/openmw/mwrender/interior.cpp +++ b/apps/openmw/mwrender/interior.cpp @@ -1,4 +1,5 @@ #include "interior.hpp" +#include "renderingmanager.hpp" #include #include @@ -108,7 +109,7 @@ void InteriorCellRender::insertMesh(const std::string &mesh, Ogre::Vector3 vec, MeshPtr good2 = NifOgre::NIFLoader::load(mesh); - MovableObject *ent = scene.getMgr()->createEntity(mesh); + MovableObject *ent = mRendering.getMgr()->createEntity(mesh); //ent->extr // MovableObject *ent2 = scene.getMgr()->createEntity(bounds @@ -185,7 +186,7 @@ void InteriorCellRender::insertMesh(const std::string &mesh) assert (insert); NifOgre::NIFLoader::load(mesh); - MovableObject *ent = scene.getMgr()->createEntity(mesh); + MovableObject *ent = mRendering.getMgr()->createEntity(mesh); insert->attachObject(ent); if (mInsertMesh.empty()) @@ -211,7 +212,7 @@ void InteriorCellRender::insertLight(float r, float g, float b, float radius) { assert (insert); - Ogre::Light *light = scene.getMgr()->createLight(); + Ogre::Light *light = mRendering.getMgr()->createLight(); light->setDiffuseColour (r, g, b); float cval=0.0f, lval=0.0f, qval=0.0f; @@ -267,7 +268,7 @@ void InteriorCellRender::configureAmbient() // Create a "sun" that shines light downwards. It doesn't look // completely right, but leave it for now. - Ogre::Light *light = scene.getMgr()->createLight(); + Ogre::Light *light = mRendering.getMgr()->createLight(); Ogre::ColourValue colour; colour.setAsABGR (cell.cell->ambi.sunlight); light->setDiffuseColour (colour); @@ -284,9 +285,9 @@ void InteriorCellRender::configureFog() float high = 4500 + 9000 * (1-cell.cell->ambi.fogDensity); float low = 200; - scene.getMgr()->setFog (FOG_LINEAR, color, 0, low, high); - scene.getCamera()->setFarClipDistance (high + 10); - scene.getViewport()->setBackgroundColour (color); + mRendering.getMgr()->setFog (FOG_LINEAR, color, 0, low, high); + mRendering.getCamera()->setFarClipDistance (high + 10); + mRendering.getViewport()->setBackgroundColour (color); } void InteriorCellRender::setAmbientMode() @@ -295,24 +296,24 @@ void InteriorCellRender::setAmbientMode() { case 0: - scene.getMgr()->setAmbientLight(ambientColor); + mRendering.getMgr()->setAmbientLight(ambientColor); break; case 1: - scene.getMgr()->setAmbientLight(0.7f*ambientColor + 0.3f*ColourValue(1,1,1)); + mRendering.getMgr()->setAmbientLight(0.7f*ambientColor + 0.3f*ColourValue(1,1,1)); break; case 2: - scene.getMgr()->setAmbientLight(ColourValue(1,1,1)); + mRendering.getMgr()->setAmbientLight(ColourValue(1,1,1)); break; } } void InteriorCellRender::show() { - base = scene.getRoot()->createChildSceneNode(); + base = mRendering.getRoot()->createChildSceneNode(); configureAmbient(); configureFog(); @@ -331,7 +332,7 @@ void InteriorCellRender::destroy() if(base) { base->removeAndDestroyAllChildren(); - scene.getMgr()->destroySceneNode(base); + mRendering.getMgr()->destroySceneNode(base); } base = NULL; @@ -359,22 +360,22 @@ void InteriorCellRender::toggleLight() void InteriorCellRender::enable (const std::string& handle) { if (!handle.empty()) - scene.getMgr()->getSceneNode (handle)->setVisible (true); + mRendering.getMgr()->getSceneNode (handle)->setVisible (true); } void InteriorCellRender::disable (const std::string& handle) { if (!handle.empty()) - scene.getMgr()->getSceneNode (handle)->setVisible (false); + mRendering.getMgr()->getSceneNode (handle)->setVisible (false); } void InteriorCellRender::deleteObject (const std::string& handle) { if (!handle.empty()) { - Ogre::SceneNode *node = scene.getMgr()->getSceneNode (handle); + Ogre::SceneNode *node = mRendering.getMgr()->getSceneNode (handle); node->removeAndDestroyAllChildren(); - scene.getMgr()->destroySceneNode (node); + mRendering.getMgr()->destroySceneNode (node); } } diff --git a/apps/openmw/mwrender/interior.hpp b/apps/openmw/mwrender/interior.hpp index 16fca0898..9329d5b79 100644 --- a/apps/openmw/mwrender/interior.hpp +++ b/apps/openmw/mwrender/interior.hpp @@ -20,7 +20,7 @@ namespace MWWorld namespace MWRender { - class MWScene; + class RenderingManager; /** This class is responsible for inserting meshes and other @@ -48,7 +48,7 @@ namespace MWRender ESMS::CellStore &cell; MWWorld::Environment &mEnvironment; - MWScene &scene; + MWRender::RenderingManager &mRendering; MWWorld::PhysicsSystem *mPhysics; /// The scene node that contains all objects belonging to this @@ -95,8 +95,8 @@ namespace MWRender public: InteriorCellRender(ESMS::CellStore &_cell, MWWorld::Environment& environment, - MWScene &_scene, MWWorld::PhysicsSystem *physics) - : cell(_cell), mEnvironment (environment), scene(_scene), base(NULL), insert(NULL), ambientMode (0) + RenderingManager &_rendering, MWWorld::PhysicsSystem *physics) + : cell(_cell), mEnvironment (environment), mRendering(_rendering), base(NULL), insert(NULL), ambientMode (0) { mPhysics = physics; } diff --git a/apps/openmw/mwrender/mwscene.cpp b/apps/openmw/mwrender/mwscene.cpp index cabed7bee..0201c8208 100644 --- a/apps/openmw/mwrender/mwscene.cpp +++ b/apps/openmw/mwrender/mwscene.cpp @@ -22,6 +22,7 @@ Debugging::Debugging(OEngine::Physic::PhysicEngine* engine){ eng = engine; } + bool Debugging::toggleRenderMode (int mode){ switch (mode) { @@ -35,73 +36,3 @@ bool Debugging::toggleRenderMode (int mode){ return false; } - -MWScene::MWScene(OEngine::Render::OgreRenderer &_rend , OEngine::Physic::PhysicEngine* physEng) - : rend(_rend) -{ - eng = physEng; - rend.createScene("PlayerCam", 55, 5); - - // Set default mipmap level (NB some APIs ignore this) - TextureManager::getSingleton().setDefaultNumMipmaps(5); - - // Load resources - ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); - - // Turn the entire scene (represented by the 'root' node) -90 - // degrees around the x axis. This makes Z go upwards, and Y go into - // the screen (when x is to the right.) This is the orientation that - // Morrowind uses, and it automagically makes everything work as it - // should. - SceneNode *rt = rend.getScene()->getRootSceneNode(); - mwRoot = rt->createChildSceneNode(); - mwRoot->pitch(Degree(-90)); - - //used to obtain ingame information of ogre objects (which are faced or selected) - mRaySceneQuery = rend.getScene()->createRayQuery(Ray()); - - Ogre::SceneNode *playerNode = mwRoot->createChildSceneNode ("player"); - playerNode->pitch(Degree(90)); - Ogre::SceneNode *cameraYawNode = playerNode->createChildSceneNode(); - Ogre::SceneNode *cameraPitchNode = cameraYawNode->createChildSceneNode(); - cameraPitchNode->attachObject(getCamera()); - - - mPlayer = new MWRender::Player (getCamera(), playerNode->getName()); -} - -MWScene::~MWScene() -{ - delete mPlayer; -} - -std::pair MWScene::getFacedHandle (MWWorld::World& world) -{ - std::string handle = ""; - - //get a ray pointing to the center of the viewport - Ray centerRay = getCamera()->getCameraToViewportRay( - getViewport()->getWidth()/2, - getViewport()->getHeight()/2); - //let's avoid the capsule shape of the player. - centerRay.setOrigin(centerRay.getOrigin() + 20*centerRay.getDirection()); - btVector3 from(centerRay.getOrigin().x,-centerRay.getOrigin().z,centerRay.getOrigin().y); - btVector3 to(centerRay.getPoint(500).x,-centerRay.getPoint(500).z,centerRay.getPoint(500).y); - - return eng->rayTest(from,to); -} - -bool MWScene::toggleRenderMode (int mode) -{ - switch (mode) - { - case MWWorld::World::Render_CollisionDebug: - - // TODO use a proper function instead of accessing the member variable - // directly. - eng->setDebugRenderingMode (!eng->isDebugCreated); - return eng->isDebugCreated; - } - - return false; -} diff --git a/apps/openmw/mwrender/mwscene.hpp b/apps/openmw/mwrender/mwscene.hpp index d68fb6ad5..b48cfaee2 100644 --- a/apps/openmw/mwrender/mwscene.hpp +++ b/apps/openmw/mwrender/mwscene.hpp @@ -37,47 +37,7 @@ namespace MWRender bool toggleRenderMode (int mode); }; - /// \brief 3D-scene (rendering and physics) - class MWScene - { - OEngine::Render::OgreRenderer &rend; - - /// Root node for all objects added to the scene. This is rotated so - /// that the OGRE coordinate system matches that used internally in - /// Morrowind. - Ogre::SceneNode *mwRoot; - Ogre::RaySceneQuery *mRaySceneQuery; - - OEngine::Physic::PhysicEngine* eng; - - MWRender::Player *mPlayer; - - public: - - MWScene (OEngine::Render::OgreRenderer &_rend , OEngine::Physic::PhysicEngine* physEng); - - ~MWScene(); - - Ogre::Camera *getCamera() { return rend.getCamera(); } - Ogre::SceneNode *getRoot() { return mwRoot; } - Ogre::SceneManager *getMgr() { return rend.getScene(); } - Ogre::Viewport *getViewport() { return rend.getViewport(); } - Ogre::RaySceneQuery *getRaySceneQuery() { return mRaySceneQuery; } - MWRender::Player *getPlayer() { return mPlayer; } - - /// Gets the handle of the object the player is looking at - /// pair - /// name is empty and distance = -1 if there is no object which - /// can be faced - std::pair getFacedHandle (MWWorld::World& world); - - /// Toggle render mode - /// \todo Using an int instead of a enum here to avoid cyclic includes. Will be fixed - /// when the mw*-refactoring is done. - /// \return Resulting mode - bool toggleRenderMode (int mode); - }; } #endif diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index 095323dea..df4eab336 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -22,13 +22,14 @@ namespace MWRender { -RenderingManager::RenderingManager (OEngine::Render::OgreRenderer& _rend, const boost::filesystem2::path& resDir) :rend(_rend) +RenderingManager::RenderingManager (OEngine::Render::OgreRenderer& _rend, const boost::filesystem::path& resDir) :rend(_rend) { - camera = rend.getCamera(); - mSkyManager = MWRender::SkyManager::create(rend.getWindow(), camera, resDir); - + + + //std::cout << "ONE"; rend.createScene("PlayerCam", 55, 5); + mSkyManager = MWRender::SkyManager::create(rend.getWindow(), getCamera(), resDir); // Set default mipmap level (NB some APIs ignore this) TextureManager::getSingleton().setDefaultNumMipmaps(5); @@ -41,7 +42,7 @@ RenderingManager::RenderingManager (OEngine::Render::OgreRenderer& _rend, const // the screen (when x is to the right.) This is the orientation that // Morrowind uses, and it automagically makes everything work as it // should. - + //std::cout << "TWO"; SceneNode *rt = rend.getScene()->getRootSceneNode(); mwRoot = rt->createChildSceneNode(); mwRoot->pitch(Degree(-90)); @@ -53,16 +54,17 @@ RenderingManager::RenderingManager (OEngine::Render::OgreRenderer& _rend, const playerNode->pitch(Degree(90)); Ogre::SceneNode *cameraYawNode = playerNode->createChildSceneNode(); Ogre::SceneNode *cameraPitchNode = cameraYawNode->createChildSceneNode(); - cameraPitchNode->attachObject(camera); - - - mPlayer = new MWRender::Player (camera, playerNode->getName()); + cameraPitchNode->attachObject(getCamera()); + std::cout <<"TWOF\n"; + mPlayer = new MWRender::Player (getCamera(), playerNode->getName()); + //std::cout << "Three"; } RenderingManager::~RenderingManager () { + delete mPlayer; delete mSkyManager; } diff --git a/apps/openmw/mwrender/renderingmanager.hpp b/apps/openmw/mwrender/renderingmanager.hpp index 8c76f8f26..f7b5f80eb 100644 --- a/apps/openmw/mwrender/renderingmanager.hpp +++ b/apps/openmw/mwrender/renderingmanager.hpp @@ -52,7 +52,7 @@ class RenderingManager { MWRender::Player *mPlayer; public: - RenderingManager(OEngine::Render::OgreRenderer& _rend, const boost::filesystem2::path& resDir); + RenderingManager(OEngine::Render::OgreRenderer& _rend, const boost::filesystem::path& resDir); ~RenderingManager(); void removeCell (MWWorld::Ptr::CellStore *store); // TODO do we want this? @@ -77,7 +77,11 @@ class RenderingManager { int skyGetMasserPhase() const; int skyGetSecundaPhase() const; void skySetMoonColour (bool red); - + Ogre::SceneManager *getMgr() { return rend.getScene(); } + Ogre::Camera *getCamera() { return rend.getCamera(); } + Ogre::Viewport *getViewport() { return rend.getViewport(); } + Ogre::SceneNode *getRoot() { return mwRoot; } + MWRender::Player *getPlayer() { return mPlayer; } private: SkyManager* mSkyManager; diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index da9bff6b2..a0fe0e610 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -137,7 +137,7 @@ namespace MWWorld { Ptr::CellStore *cell = mWorld->getExterior(x, y); - loadCell (cell, new MWRender::ExteriorCellRender (*cell, mEnvironment, mScene, mPhysics)); + loadCell (cell, new MWRender::ExteriorCellRender (*cell, mEnvironment, mRendering, mPhysics)); } } @@ -168,8 +168,8 @@ namespace MWWorld mCellChanged = true; } - Scene::Scene (Environment& environment, World *world, MWRender::MWScene& scene, PhysicsSystem *physics) - : mScene (scene), mCurrentCell (0), + Scene::Scene (Environment& environment, World *world, MWRender::RenderingManager& rm, PhysicsSystem *physics) + : mRendering(rm), mCurrentCell (0), mCellChanged (false), mEnvironment (environment), mWorld(world), mPhysics(physics) { } @@ -205,7 +205,7 @@ namespace MWWorld std::cout << "cellName:" << cellName << std::endl; Ptr::CellStore *cell = mWorld->getInterior(cellName); - loadCell (cell, new MWRender::InteriorCellRender (*cell, mEnvironment, mScene, mPhysics)); + loadCell (cell, new MWRender::InteriorCellRender (*cell, mEnvironment, mRendering, mPhysics)); // adjust player mCurrentCell = cell; diff --git a/apps/openmw/mwworld/scene.hpp b/apps/openmw/mwworld/scene.hpp index 9e43a98a5..8612c707b 100644 --- a/apps/openmw/mwworld/scene.hpp +++ b/apps/openmw/mwworld/scene.hpp @@ -14,7 +14,7 @@ #include "refdata.hpp" #include "ptr.hpp" #include "globals.hpp" - +#include "../mwrender/renderingmanager.hpp" #include namespace Ogre @@ -57,7 +57,7 @@ namespace MWWorld private: - MWRender::MWScene& mScene; + MWRender::RenderingManager mRendering; Ptr::CellStore *mCurrentCell; // the cell, the player is in CellRenderCollection mActiveCells; bool mCellChanged; @@ -69,7 +69,7 @@ namespace MWWorld bool adjustPlayerPos = true); public: - Scene (Environment& environment, World *world, MWRender::MWScene& scene, PhysicsSystem *physics); + Scene (Environment& environment, World *world, MWRender::RenderingManager& rm, PhysicsSystem *physics); ~Scene(); diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index 4174e6457..fbc702b0a 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -176,8 +176,8 @@ namespace MWWorld const Files::Collections& fileCollections, const std::string& master, const boost::filesystem::path& resDir, bool newGame, Environment& environment, const std::string& encoding) - : mScene (renderer,physEng), mPlayer (0), mLocalScripts (mStore), mGlobalVariables (0), - mSky (false), mEnvironment (environment), mNextDynamicRecord (0), mCells (mStore, mEsm, *this) + : mRendering (renderer,resDir), mPlayer (0), mLocalScripts (mStore), mGlobalVariables (0), + mSky (false), mEnvironment (environment), mNextDynamicRecord (0), mCells (mStore, mEsm, *this), mDebugging(physEng) { mPhysEngine = physEng; @@ -192,7 +192,7 @@ namespace MWWorld mEsm.open (masterPath.string()); mStore.load (mEsm); - mPlayer = new MWWorld::Player (mScene.getPlayer(), mStore.npcs.find ("player"), *this); + mPlayer = new MWWorld::Player (mRendering.getPlayer(), mStore.npcs.find ("player"), *this); mPhysics->addActor (mPlayer->getPlayer().getRefData().getHandle(), "", Ogre::Vector3 (0, 0, 0)); // global variables @@ -206,9 +206,8 @@ namespace MWWorld mPhysEngine = physEng; - mWorldScene = new Scene(environment, this, mScene, mPhysics); - mRenderingManager = new MWRender::RenderingManager(renderer, - resDir); + mWorldScene = new Scene(environment, this, mRendering, mPhysics); + } World::~World() @@ -397,7 +396,7 @@ namespace MWWorld mGlobalVariables->setFloat ("gamehour", hour); - mRenderingManager->skySetHour (hour); + mRendering.skySetHour (hour); if (days>0) setDay (days + mGlobalVariables->getInt ("day")); @@ -432,7 +431,7 @@ namespace MWWorld mGlobalVariables->setInt ("day", day); mGlobalVariables->setInt ("month", month); - mRenderingManager->skySetDate (day, month); + mRendering.skySetDate (day, month); } void World::setMonth (int month) @@ -453,7 +452,7 @@ namespace MWWorld if (years>0) mGlobalVariables->setInt ("year", years+mGlobalVariables->getInt ("year")); - mRenderingManager->skySetDate (mGlobalVariables->getInt ("day"), month); + mRendering.skySetDate (mGlobalVariables->getInt ("day"), month); } bool World::toggleSky() @@ -461,34 +460,34 @@ namespace MWWorld if (mSky) { mSky = false; - mRenderingManager->skyDisable(); + mRendering.skyDisable(); return false; } else { mSky = true; // TODO check for extorior or interior with sky. - mRenderingManager->skySetHour (mGlobalVariables->getFloat ("gamehour")); - mRenderingManager->skySetDate (mGlobalVariables->getInt ("day"), + mRendering.skySetHour (mGlobalVariables->getFloat ("gamehour")); + mRendering.skySetDate (mGlobalVariables->getInt ("day"), mGlobalVariables->getInt ("month")); - mRenderingManager->skyEnable(); + mRendering.skyEnable(); return true; } } int World::getMasserPhase() const { - return mRenderingManager->skyGetMasserPhase(); + return mRendering.skyGetMasserPhase(); } int World::getSecundaPhase() const { - return mRenderingManager->skyGetSecundaPhase(); + return mRendering.skyGetSecundaPhase(); } void World::setMoonColour (bool red) { - mRenderingManager->skySetMoonColour (red); + mRendering.skySetMoonColour (red); } float World::getTimeScaleFactor() const @@ -513,7 +512,7 @@ namespace MWWorld std::string World::getFacedHandle() { - std::pair result = mScene.getFacedHandle (*this); + std::pair result = mPhysics->getFacedHandle (*this); if (result.first.empty() || result.second>getStore().gameSettings.find ("iMaxActivateDist")->i) @@ -577,7 +576,7 @@ namespace MWWorld // \todo cell change for non-player ref // \todo this should go into the new scene class and eventually into the objects/actors classes. - mScene.getMgr()->getSceneNode (ptr.getRefData().getHandle())-> + mRendering.getMgr()->getSceneNode (ptr.getRefData().getHandle())-> setPosition (Ogre::Vector3 (x, y, z)); } @@ -652,7 +651,7 @@ namespace MWWorld bool World::toggleRenderMode (RenderMode mode) { - return mScene.toggleRenderMode (mode); + return mDebugging.toggleRenderMode (mode); } std::pair World::createRecord (const ESM::Potion& record) diff --git a/apps/openmw/mwworld/world.hpp b/apps/openmw/mwworld/world.hpp index e661ef362..5d196278a 100644 --- a/apps/openmw/mwworld/world.hpp +++ b/apps/openmw/mwworld/world.hpp @@ -65,7 +65,8 @@ namespace MWWorld private: - MWRender::MWScene mScene; + MWRender::RenderingManager mRendering; + MWRender::Debugging mDebugging; MWWorld::Scene *mWorldScene; MWWorld::Player *mPlayer; ESM::ESMReader mEsm; @@ -75,7 +76,6 @@ namespace MWWorld MWWorld::PhysicsSystem *mPhysics; bool mSky; Environment& mEnvironment; - MWRender::RenderingManager *mRenderingManager; int mNextDynamicRecord; Cells mCells; From 0c8aa7fae33c94b4d166693c96e2b8ea9116901a Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Mon, 24 Oct 2011 13:55:10 -0400 Subject: [PATCH 010/104] Removing Object: --- apps/openmw/engine.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 90b476df7..03ec4a479 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -83,8 +83,6 @@ void OMW::Engine::updateFocusReport (float duration) if (!ptr.isEmpty()){ name = MWWorld::Class::get (ptr).getName (ptr); - if (!name.empty()) - std::cout << "Object: " << name << std::endl; } } From 965ff245977009ad3f2906ed16ed8be75249f48f Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Mon, 24 Oct 2011 13:57:12 -0400 Subject: [PATCH 011/104] Removing Object: --- apps/openmw/engine.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 03ec4a479..e8c324e9a 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -288,7 +288,6 @@ void OMW::Engine::setReportFocus (bool report) void OMW::Engine::go() { mFocusTDiff = 0; - mReportFocus = true; assert (!mEnvironment.mWorld); assert (!mCellName.empty()); assert (!mMaster.empty()); From d4f63443e643975b59d2dcbe6f35bc08739815b0 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Mon, 24 Oct 2011 22:11:36 -0400 Subject: [PATCH 012/104] Hiding the rendering manager; crash eliminated --- apps/openmw/mwrender/exterior.cpp | 44 ++++++++++++----------- apps/openmw/mwrender/exterior.hpp | 5 +-- apps/openmw/mwrender/interior.cpp | 32 ++++++++--------- apps/openmw/mwrender/interior.hpp | 8 +++-- apps/openmw/mwrender/renderingmanager.cpp | 7 ++-- apps/openmw/mwrender/renderingmanager.hpp | 3 +- apps/openmw/mwworld/scene.cpp | 10 +++--- apps/openmw/mwworld/scene.hpp | 5 +-- apps/openmw/mwworld/world.cpp | 8 +++-- 9 files changed, 66 insertions(+), 56 deletions(-) diff --git a/apps/openmw/mwrender/exterior.cpp b/apps/openmw/mwrender/exterior.cpp index 9cc8fd564..358e19a7c 100644 --- a/apps/openmw/mwrender/exterior.cpp +++ b/apps/openmw/mwrender/exterior.cpp @@ -35,11 +35,13 @@ bool ExteriorCellRender::lightOutQuadInLin = false; int ExteriorCellRender::uniqueID = 0; ExteriorCellRender::ExteriorCellRender(ESMS::CellStore &_cell, MWWorld::Environment& environment, - RenderingManager &_rendering, MWWorld::PhysicsSystem *physics) - : mCell(_cell), mEnvironment (environment), mRendering(_rendering), mPhysics(physics), mBase(NULL), mInsert(NULL), mAmbientMode (0) + OEngine::Render::OgreRenderer& renderer, Ogre::SceneNode *mwRoot,MWWorld::PhysicsSystem *physics) + : mCell(_cell), mEnvironment (environment), mRenderer(renderer), mPhysics(physics), mBase(NULL), mInsert(NULL), mAmbientMode (0) { + mMwRoot = mwRoot; uniqueID = uniqueID +1; - sg = mRendering.getMgr()->createStaticGeometry( "sg" + Ogre::StringConverter::toString(uniqueID)); + sg = mRenderer.getScene()->createStaticGeometry( "sg" + Ogre::StringConverter::toString(uniqueID)); + } @@ -127,7 +129,7 @@ void ExteriorCellRender::insertMesh(const std::string &mesh, Ogre::Vector3 vec, mNpcPart = parent->createChildSceneNode(sceneNodeName); MeshPtr good2 = NifOgre::NIFLoader::load(mesh); - MovableObject *ent = mRendering.getMgr()->createEntity(mesh); + MovableObject *ent = mRenderer.getScene()->createEntity(mesh); if(translateFirst){ @@ -215,7 +217,7 @@ void ExteriorCellRender::insertMesh(const std::string &mesh) assert (mInsert); NifOgre::NIFLoader::load(mesh); - Entity *ent = mRendering.getMgr()->createEntity(mesh); + Entity *ent = mRenderer.getScene()->createEntity(mesh); if(!isStatic) { @@ -225,7 +227,7 @@ void ExteriorCellRender::insertMesh(const std::string &mesh) { sg->addEntity(ent,mInsert->_getDerivedPosition(),mInsert->_getDerivedOrientation(),mInsert->_getDerivedScale()); sg->setRegionDimensions(Ogre::Vector3(100000,10000,100000)); - mRendering.getMgr()->destroyEntity(ent); + mRenderer.getScene()->destroyEntity(ent); } if (mInsertMesh.empty()) mInsertMesh = mesh; @@ -250,7 +252,7 @@ void ExteriorCellRender::insertLight(float r, float g, float b, float radius) { assert (mInsert); - Ogre::Light *light = mRendering.getMgr()->createLight(); + Ogre::Light *light = mRenderer.getScene()->createLight(); light->setDiffuseColour (r, g, b); float cval=0.0f, lval=0.0f, qval=0.0f; @@ -306,7 +308,7 @@ void ExteriorCellRender::configureAmbient() // Create a "sun" that shines light downwards. It doesn't look // completely right, but leave it for now. - Ogre::Light *light = mRendering.getMgr()->createLight(); + Ogre::Light *light = mRenderer.getScene()->createLight(); Ogre::ColourValue colour; colour.setAsABGR (mCell.cell->ambi.sunlight); light->setDiffuseColour (colour); @@ -323,9 +325,9 @@ void ExteriorCellRender::configureFog() float high = 4500 + 9000 * (1-mCell.cell->ambi.fogDensity); float low = 200; - mRendering.getMgr()->setFog (FOG_LINEAR, color, 0, low, high); - mRendering.getCamera()->setFarClipDistance (high + 10); - mRendering.getViewport()->setBackgroundColour (color); + mRenderer.getScene()->setFog (FOG_LINEAR, color, 0, low, high); + mRenderer.getCamera()->setFarClipDistance (high + 10); + mRenderer.getViewport()->setBackgroundColour (color); } void ExteriorCellRender::setAmbientMode() @@ -334,17 +336,17 @@ void ExteriorCellRender::setAmbientMode() { case 0: - mRendering.getMgr()->setAmbientLight(mAmbientColor); + mRenderer.getScene()->setAmbientLight(mAmbientColor); break; case 1: - mRendering.getMgr()->setAmbientLight(0.7f*mAmbientColor + 0.3f*ColourValue(1,1,1)); + mRenderer.getScene()->setAmbientLight(0.7f*mAmbientColor + 0.3f*ColourValue(1,1,1)); break; case 2: - mRendering.getMgr()->setAmbientLight(ColourValue(1,1,1)); + mRenderer.getScene()->setAmbientLight(ColourValue(1,1,1)); break; } } @@ -352,7 +354,7 @@ void ExteriorCellRender::setAmbientMode() void ExteriorCellRender::show() { // FIXME: this one may be the bug - mBase = mRendering.getRoot()->createChildSceneNode(); + mBase = mMwRoot->createChildSceneNode(); configureAmbient(); configureFog(); @@ -401,14 +403,14 @@ void ExteriorCellRender::destroy() { destroyAllAttachedMovableObjects(mBase); mBase->removeAndDestroyAllChildren(); - mRendering.getMgr()->destroySceneNode(mBase); + mRenderer.getScene()->destroySceneNode(mBase); } mBase = 0; if (sg) { - mRendering.getMgr()->destroyStaticGeometry (sg); + mRenderer.getScene()->destroyStaticGeometry (sg); sg = 0; } } @@ -435,21 +437,21 @@ void ExteriorCellRender::toggleLight() void ExteriorCellRender::enable (const std::string& handle) { if (!handle.empty()) - mRendering.getMgr()->getSceneNode (handle)->setVisible (true); + mRenderer.getScene()->getSceneNode (handle)->setVisible (true); } void ExteriorCellRender::disable (const std::string& handle) { if (!handle.empty()) - mRendering.getMgr()->getSceneNode (handle)->setVisible (false); + mRenderer.getScene()->getSceneNode (handle)->setVisible (false); } void ExteriorCellRender::deleteObject (const std::string& handle) { if (!handle.empty()) { - Ogre::SceneNode *node = mRendering.getMgr()->getSceneNode (handle); + Ogre::SceneNode *node = mRenderer.getScene()->getSceneNode (handle); node->removeAndDestroyAllChildren(); - mRendering.getMgr()->destroySceneNode (node); + mRenderer.getScene()->destroySceneNode (node); } } diff --git a/apps/openmw/mwrender/exterior.hpp b/apps/openmw/mwrender/exterior.hpp index 17973db46..c73625128 100644 --- a/apps/openmw/mwrender/exterior.hpp +++ b/apps/openmw/mwrender/exterior.hpp @@ -49,7 +49,8 @@ namespace MWRender ESMS::CellStore &mCell; MWWorld::Environment &mEnvironment; - RenderingManager &mRendering; + OEngine::Render::OgreRenderer& mRenderer; + Ogre::SceneNode *mMwRoot; MWWorld::PhysicsSystem *mPhysics; /// The scene node that contains all objects belonging to this @@ -103,7 +104,7 @@ namespace MWRender public: ExteriorCellRender(ESMS::CellStore &_cell, MWWorld::Environment& environment, - RenderingManager &_rendering, MWWorld::PhysicsSystem *physics); + OEngine::Render::OgreRenderer& renderer, Ogre::SceneNode *mwRoot, MWWorld::PhysicsSystem *physics); virtual ~ExteriorCellRender() { destroy(); } diff --git a/apps/openmw/mwrender/interior.cpp b/apps/openmw/mwrender/interior.cpp index 13149eb55..cbbab484a 100644 --- a/apps/openmw/mwrender/interior.cpp +++ b/apps/openmw/mwrender/interior.cpp @@ -109,7 +109,7 @@ void InteriorCellRender::insertMesh(const std::string &mesh, Ogre::Vector3 vec, MeshPtr good2 = NifOgre::NIFLoader::load(mesh); - MovableObject *ent = mRendering.getMgr()->createEntity(mesh); + MovableObject *ent = mRenderer.getScene()->createEntity(mesh); //ent->extr // MovableObject *ent2 = scene.getMgr()->createEntity(bounds @@ -186,7 +186,7 @@ void InteriorCellRender::insertMesh(const std::string &mesh) assert (insert); NifOgre::NIFLoader::load(mesh); - MovableObject *ent = mRendering.getMgr()->createEntity(mesh); + MovableObject *ent = mRenderer.getScene()->createEntity(mesh); insert->attachObject(ent); if (mInsertMesh.empty()) @@ -212,7 +212,7 @@ void InteriorCellRender::insertLight(float r, float g, float b, float radius) { assert (insert); - Ogre::Light *light = mRendering.getMgr()->createLight(); + Ogre::Light *light = mRenderer.getScene()->createLight(); light->setDiffuseColour (r, g, b); float cval=0.0f, lval=0.0f, qval=0.0f; @@ -268,7 +268,7 @@ void InteriorCellRender::configureAmbient() // Create a "sun" that shines light downwards. It doesn't look // completely right, but leave it for now. - Ogre::Light *light = mRendering.getMgr()->createLight(); + Ogre::Light *light = mRenderer.getScene()->createLight(); Ogre::ColourValue colour; colour.setAsABGR (cell.cell->ambi.sunlight); light->setDiffuseColour (colour); @@ -285,9 +285,9 @@ void InteriorCellRender::configureFog() float high = 4500 + 9000 * (1-cell.cell->ambi.fogDensity); float low = 200; - mRendering.getMgr()->setFog (FOG_LINEAR, color, 0, low, high); - mRendering.getCamera()->setFarClipDistance (high + 10); - mRendering.getViewport()->setBackgroundColour (color); + mRenderer.getScene()->setFog (FOG_LINEAR, color, 0, low, high); + mRenderer.getCamera()->setFarClipDistance (high + 10); + mRenderer.getViewport()->setBackgroundColour (color); } void InteriorCellRender::setAmbientMode() @@ -296,24 +296,24 @@ void InteriorCellRender::setAmbientMode() { case 0: - mRendering.getMgr()->setAmbientLight(ambientColor); + mRenderer.getScene()->setAmbientLight(ambientColor); break; case 1: - mRendering.getMgr()->setAmbientLight(0.7f*ambientColor + 0.3f*ColourValue(1,1,1)); + mRenderer.getScene()->setAmbientLight(0.7f*ambientColor + 0.3f*ColourValue(1,1,1)); break; case 2: - mRendering.getMgr()->setAmbientLight(ColourValue(1,1,1)); + mRenderer.getScene()->setAmbientLight(ColourValue(1,1,1)); break; } } void InteriorCellRender::show() { - base = mRendering.getRoot()->createChildSceneNode(); + base = mMwRoot->createChildSceneNode(); configureAmbient(); configureFog(); @@ -332,7 +332,7 @@ void InteriorCellRender::destroy() if(base) { base->removeAndDestroyAllChildren(); - mRendering.getMgr()->destroySceneNode(base); + mRenderer.getScene()->destroySceneNode(base); } base = NULL; @@ -360,22 +360,22 @@ void InteriorCellRender::toggleLight() void InteriorCellRender::enable (const std::string& handle) { if (!handle.empty()) - mRendering.getMgr()->getSceneNode (handle)->setVisible (true); + mRenderer.getScene()->getSceneNode (handle)->setVisible (true); } void InteriorCellRender::disable (const std::string& handle) { if (!handle.empty()) - mRendering.getMgr()->getSceneNode (handle)->setVisible (false); + mRenderer.getScene()->getSceneNode (handle)->setVisible (false); } void InteriorCellRender::deleteObject (const std::string& handle) { if (!handle.empty()) { - Ogre::SceneNode *node = mRendering.getMgr()->getSceneNode (handle); + Ogre::SceneNode *node = mRenderer.getScene()->getSceneNode (handle); node->removeAndDestroyAllChildren(); - mRendering.getMgr()->destroySceneNode (node); + mRenderer.getScene()->destroySceneNode (node); } } diff --git a/apps/openmw/mwrender/interior.hpp b/apps/openmw/mwrender/interior.hpp index 9329d5b79..237d689c4 100644 --- a/apps/openmw/mwrender/interior.hpp +++ b/apps/openmw/mwrender/interior.hpp @@ -48,7 +48,8 @@ namespace MWRender ESMS::CellStore &cell; MWWorld::Environment &mEnvironment; - MWRender::RenderingManager &mRendering; + OEngine::Render::OgreRenderer& mRenderer; + Ogre::SceneNode *mMwRoot; MWWorld::PhysicsSystem *mPhysics; /// The scene node that contains all objects belonging to this @@ -95,9 +96,10 @@ namespace MWRender public: InteriorCellRender(ESMS::CellStore &_cell, MWWorld::Environment& environment, - RenderingManager &_rendering, MWWorld::PhysicsSystem *physics) - : cell(_cell), mEnvironment (environment), mRendering(_rendering), base(NULL), insert(NULL), ambientMode (0) + OEngine::Render::OgreRenderer& renderer, Ogre::SceneNode *mwRoot, MWWorld::PhysicsSystem *physics) + : cell(_cell), mEnvironment (environment), mRenderer(renderer), base(NULL), insert(NULL), ambientMode (0) { + mMwRoot = mwRoot; mPhysics = physics; } diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index df4eab336..46cf89edc 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -29,7 +29,7 @@ RenderingManager::RenderingManager (OEngine::Render::OgreRenderer& _rend, const //std::cout << "ONE"; rend.createScene("PlayerCam", 55, 5); - mSkyManager = MWRender::SkyManager::create(rend.getWindow(), getCamera(), resDir); + mSkyManager = MWRender::SkyManager::create(rend.getWindow(), rend.getCamera(), resDir); // Set default mipmap level (NB some APIs ignore this) TextureManager::getSingleton().setDefaultNumMipmaps(5); @@ -54,10 +54,9 @@ RenderingManager::RenderingManager (OEngine::Render::OgreRenderer& _rend, const playerNode->pitch(Degree(90)); Ogre::SceneNode *cameraYawNode = playerNode->createChildSceneNode(); Ogre::SceneNode *cameraPitchNode = cameraYawNode->createChildSceneNode(); - cameraPitchNode->attachObject(getCamera()); - std::cout <<"TWOF\n"; + cameraPitchNode->attachObject(rend.getCamera()); - mPlayer = new MWRender::Player (getCamera(), playerNode->getName()); + mPlayer = new MWRender::Player (rend.getCamera(), playerNode->getName()); //std::cout << "Three"; } diff --git a/apps/openmw/mwrender/renderingmanager.hpp b/apps/openmw/mwrender/renderingmanager.hpp index f7b5f80eb..dcac7625d 100644 --- a/apps/openmw/mwrender/renderingmanager.hpp +++ b/apps/openmw/mwrender/renderingmanager.hpp @@ -77,9 +77,8 @@ class RenderingManager { int skyGetMasserPhase() const; int skyGetSecundaPhase() const; void skySetMoonColour (bool red); + OEngine::Render::OgreRenderer& getOgreRenderer(){return rend;} Ogre::SceneManager *getMgr() { return rend.getScene(); } - Ogre::Camera *getCamera() { return rend.getCamera(); } - Ogre::Viewport *getViewport() { return rend.getViewport(); } Ogre::SceneNode *getRoot() { return mwRoot; } MWRender::Player *getPlayer() { return mPlayer; } private: diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index a0fe0e610..4f425ac65 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -137,7 +137,7 @@ namespace MWWorld { Ptr::CellStore *cell = mWorld->getExterior(x, y); - loadCell (cell, new MWRender::ExteriorCellRender (*cell, mEnvironment, mRendering, mPhysics)); + loadCell (cell, new MWRender::ExteriorCellRender (*cell, mEnvironment, mRenderer, mMwRoot, mPhysics)); } } @@ -168,10 +168,12 @@ namespace MWWorld mCellChanged = true; } - Scene::Scene (Environment& environment, World *world, MWRender::RenderingManager& rm, PhysicsSystem *physics) - : mRendering(rm), mCurrentCell (0), + //We need the ogre renderer and a scene node. + Scene::Scene (Environment& environment, World *world, OEngine::Render::OgreRenderer& renderer, Ogre::SceneNode *mwRoot, PhysicsSystem *physics) + : mRenderer(renderer), mCurrentCell (0), mCellChanged (false), mEnvironment (environment), mWorld(world), mPhysics(physics) { + mMwRoot = mwRoot; } Scene::~Scene() @@ -205,7 +207,7 @@ namespace MWWorld std::cout << "cellName:" << cellName << std::endl; Ptr::CellStore *cell = mWorld->getInterior(cellName); - loadCell (cell, new MWRender::InteriorCellRender (*cell, mEnvironment, mRendering, mPhysics)); + loadCell (cell, new MWRender::InteriorCellRender (*cell, mEnvironment, mRenderer, mMwRoot, mPhysics)); // adjust player mCurrentCell = cell; diff --git a/apps/openmw/mwworld/scene.hpp b/apps/openmw/mwworld/scene.hpp index 8612c707b..68b65adfa 100644 --- a/apps/openmw/mwworld/scene.hpp +++ b/apps/openmw/mwworld/scene.hpp @@ -57,7 +57,8 @@ namespace MWWorld private: - MWRender::RenderingManager mRendering; + OEngine::Render::OgreRenderer& mRenderer; + Ogre::SceneNode *mMwRoot; Ptr::CellStore *mCurrentCell; // the cell, the player is in CellRenderCollection mActiveCells; bool mCellChanged; @@ -69,7 +70,7 @@ namespace MWWorld bool adjustPlayerPos = true); public: - Scene (Environment& environment, World *world, MWRender::RenderingManager& rm, PhysicsSystem *physics); + Scene (Environment& environment, World *world, OEngine::Render::OgreRenderer& renderer, Ogre::SceneNode *mwRoot, PhysicsSystem *physics); ~Scene(); diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index fbc702b0a..1949b6731 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -179,6 +179,7 @@ namespace MWWorld : mRendering (renderer,resDir), mPlayer (0), mLocalScripts (mStore), mGlobalVariables (0), mSky (false), mEnvironment (environment), mNextDynamicRecord (0), mCells (mStore, mEsm, *this), mDebugging(physEng) { + std::cout << "Creating myworld\n"; mPhysEngine = physEng; mPhysics = new PhysicsSystem(renderer, physEng); @@ -206,7 +207,8 @@ namespace MWWorld mPhysEngine = physEng; - mWorldScene = new Scene(environment, this, mRendering, mPhysics); + mWorldScene = new Scene(environment, this, mRendering.getOgreRenderer(), mRendering.getRoot(), mPhysics); + std::cout << "After mworldscene\n"; } @@ -214,8 +216,10 @@ namespace MWWorld { delete mWorldScene; delete mGlobalVariables; - delete mPlayer; + delete mPhysics; + + delete mPlayer; } const ESM::Cell *World::getExterior (const std::string& cellName) const From c3a492bf7463dd38e4a2240902b5b6fdd5f6d6e4 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Tue, 25 Oct 2011 14:06:44 -0400 Subject: [PATCH 013/104] Debugging file renamed --- apps/openmw/CMakeLists.txt | 4 ++-- apps/openmw/mwrender/{mwscene.cpp => debugging.cpp} | 2 +- apps/openmw/mwrender/{mwscene.hpp => debugging.hpp} | 0 apps/openmw/mwrender/exterior.cpp | 2 -- apps/openmw/mwrender/interior.cpp | 1 - apps/openmw/mwworld/scene.hpp | 1 - apps/openmw/mwworld/world.cpp | 1 - apps/openmw/mwworld/world.hpp | 2 +- 8 files changed, 4 insertions(+), 9 deletions(-) rename apps/openmw/mwrender/{mwscene.cpp => debugging.cpp} (97%) rename apps/openmw/mwrender/{mwscene.hpp => debugging.hpp} (100%) diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index 9510273af..86e0adc8d 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -17,7 +17,7 @@ source_group(game FILES ${GAME} ${GAME_HEADER}) set(GAMEREND mwrender/renderingmanager.cpp - mwrender/mwscene.cpp + mwrender/debugging.cpp mwrender/cellimp.cpp mwrender/interior.cpp mwrender/exterior.cpp @@ -28,7 +28,7 @@ set(GAMEREND_HEADER mwrender/renderingmanager.hpp mwrender/cell.hpp mwrender/cellimp.hpp - mwrender/mwscene.hpp + mwrender/debugging.hpp mwrender/interior.hpp mwrender/exterior.hpp mwrender/sky.hpp diff --git a/apps/openmw/mwrender/mwscene.cpp b/apps/openmw/mwrender/debugging.cpp similarity index 97% rename from apps/openmw/mwrender/mwscene.cpp rename to apps/openmw/mwrender/debugging.cpp index 0201c8208..60b299acd 100644 --- a/apps/openmw/mwrender/mwscene.cpp +++ b/apps/openmw/mwrender/debugging.cpp @@ -1,4 +1,4 @@ -#include "mwscene.hpp" +#include "debugging.hpp" #include diff --git a/apps/openmw/mwrender/mwscene.hpp b/apps/openmw/mwrender/debugging.hpp similarity index 100% rename from apps/openmw/mwrender/mwscene.hpp rename to apps/openmw/mwrender/debugging.hpp diff --git a/apps/openmw/mwrender/exterior.cpp b/apps/openmw/mwrender/exterior.cpp index 358e19a7c..1118156ba 100644 --- a/apps/openmw/mwrender/exterior.cpp +++ b/apps/openmw/mwrender/exterior.cpp @@ -8,9 +8,7 @@ #include #include -#include "mwscene.hpp" #include -#include "mwscene.hpp" #include using namespace MWRender; diff --git a/apps/openmw/mwrender/interior.cpp b/apps/openmw/mwrender/interior.cpp index cbbab484a..aa13f2292 100644 --- a/apps/openmw/mwrender/interior.cpp +++ b/apps/openmw/mwrender/interior.cpp @@ -9,7 +9,6 @@ #include #include -#include "mwscene.hpp" #include #include diff --git a/apps/openmw/mwworld/scene.hpp b/apps/openmw/mwworld/scene.hpp index 68b65adfa..6af86a071 100644 --- a/apps/openmw/mwworld/scene.hpp +++ b/apps/openmw/mwworld/scene.hpp @@ -8,7 +8,6 @@ #include -#include "../mwrender/mwscene.hpp" #include "physicssystem.hpp" #include "refdata.hpp" diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index 1949b6731..dfacffc5b 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -208,7 +208,6 @@ namespace MWWorld mPhysEngine = physEng; mWorldScene = new Scene(environment, this, mRendering.getOgreRenderer(), mRendering.getRoot(), mPhysics); - std::cout << "After mworldscene\n"; } diff --git a/apps/openmw/mwworld/world.hpp b/apps/openmw/mwworld/world.hpp index 5d196278a..b1ce69b3d 100644 --- a/apps/openmw/mwworld/world.hpp +++ b/apps/openmw/mwworld/world.hpp @@ -8,7 +8,7 @@ #include -#include "../mwrender/mwscene.hpp" +#include "../mwrender/debugging.hpp" #include "../mwrender/renderingmanager.hpp" #include "refdata.hpp" From 33ecd8b66cb7b5a313b2c8ca5b3905cc2c4c442f Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Sat, 29 Oct 2011 09:50:11 +0200 Subject: [PATCH 014/104] fixed collision toggling bug --- apps/openmw/mwworld/physicssystem.cpp | 41 +++++++++++++++------------ 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/apps/openmw/mwworld/physicssystem.cpp b/apps/openmw/mwworld/physicssystem.cpp index b06fa1a48..067c42151 100644 --- a/apps/openmw/mwworld/physicssystem.cpp +++ b/apps/openmw/mwworld/physicssystem.cpp @@ -1,3 +1,5 @@ +#include + #include "physicssystem.hpp" #include "../mwworld/ptr.hpp" #include "../mwworld/world.hpp" // FIXME @@ -154,28 +156,31 @@ namespace MWWorld { for(std::map::iterator it = mEngine->PhysicActorMap.begin(); it != mEngine->PhysicActorMap.end();it++) { - OEngine::Physic::PhysicActor* act = it->second; - bool cmode = act->getCollisionMode(); - if(cmode) - { - act->enableCollisions(false); - act->setGravity(0.); - act->setVerticalVelocity(0); - mFreeFly = true; - return false; - } - else + if (it->first=="player") { - mFreeFly = false; - act->enableCollisions(true); - act->setGravity(4.); - act->setVerticalVelocity(0); - return true; + OEngine::Physic::PhysicActor* act = it->second; + + bool cmode = act->getCollisionMode(); + if(cmode) + { + act->enableCollisions(false); + act->setGravity(0.); + act->setVerticalVelocity(0); + mFreeFly = true; + return false; + } + else + { + mFreeFly = false; + act->enableCollisions(true); + act->setGravity(4.); + act->setVerticalVelocity(0); + return true; + } } } - return false; // This should never happen, but it shall not bother us now, since - // this part of the code needs a rewrite anyway. + throw std::logic_error ("can't find player"); } } From 583e7221efb0733f6d92f6aa0244cc2d0e9a55cb Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Sat, 29 Oct 2011 09:55:22 +0200 Subject: [PATCH 015/104] silenced a warning and removed some tabs --- apps/openmw/mwworld/world.cpp | 14 +++++++------- apps/openmw/mwworld/world.hpp | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index dfacffc5b..fafea5e12 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -176,10 +176,10 @@ namespace MWWorld const Files::Collections& fileCollections, const std::string& master, const boost::filesystem::path& resDir, bool newGame, Environment& environment, const std::string& encoding) - : mRendering (renderer,resDir), mPlayer (0), mLocalScripts (mStore), mGlobalVariables (0), - mSky (false), mEnvironment (environment), mNextDynamicRecord (0), mCells (mStore, mEsm, *this), mDebugging(physEng) + : mRendering (renderer,resDir), mDebugging(physEng), mPlayer (0), mLocalScripts (mStore), mGlobalVariables (0), + mSky (false), mEnvironment (environment), mNextDynamicRecord (0), mCells (mStore, mEsm, *this) { - std::cout << "Creating myworld\n"; + std::cout << "Creating myworld\n"; mPhysEngine = physEng; mPhysics = new PhysicsSystem(renderer, physEng); @@ -208,17 +208,17 @@ namespace MWWorld mPhysEngine = physEng; mWorldScene = new Scene(environment, this, mRendering.getOgreRenderer(), mRendering.getRoot(), mPhysics); - + } World::~World() { delete mWorldScene; delete mGlobalVariables; - + delete mPhysics; - - delete mPlayer; + + delete mPlayer; } const ESM::Cell *World::getExterior (const std::string& cellName) const diff --git a/apps/openmw/mwworld/world.hpp b/apps/openmw/mwworld/world.hpp index b1ce69b3d..b00b8dead 100644 --- a/apps/openmw/mwworld/world.hpp +++ b/apps/openmw/mwworld/world.hpp @@ -66,7 +66,7 @@ namespace MWWorld private: MWRender::RenderingManager mRendering; - MWRender::Debugging mDebugging; + MWRender::Debugging mDebugging; MWWorld::Scene *mWorldScene; MWWorld::Player *mPlayer; ESM::ESMReader mEsm; From db734876235cdef88d8168b903c6476e78e0e12a Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Sat, 29 Oct 2011 18:52:57 -0400 Subject: [PATCH 016/104] Physics fix and cmake changes --- apps/openmw/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index 4723ff1d7..54495063b 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -16,7 +16,7 @@ set(GAME_HEADER source_group(game FILES ${GAME} ${GAME_HEADER}) add_openmw_dir (mwrender - rendering_manager mwscene cellimp interior exterior sky player + renderingmanager debugging cellimp interior exterior sky player ) add_openmw_dir (mwinput From 1083db5582d89e80be34940228a09bb97f970f2f Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Sun, 30 Oct 2011 00:25:29 -0400 Subject: [PATCH 017/104] Hiding debugging --- apps/openmw/mwrender/renderingmanager.cpp | 5 ++++- apps/openmw/mwrender/renderingmanager.hpp | 5 ++++- apps/openmw/mwworld/world.cpp | 4 ++-- apps/openmw/mwworld/world.hpp | 2 +- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index 46cf89edc..89429d061 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -22,7 +22,7 @@ namespace MWRender { -RenderingManager::RenderingManager (OEngine::Render::OgreRenderer& _rend, const boost::filesystem::path& resDir) :rend(_rend) +RenderingManager::RenderingManager (OEngine::Render::OgreRenderer& _rend, const boost::filesystem::path& resDir, OEngine::Physic::PhysicEngine* engine) :rend(_rend), mDebugging(engine) { @@ -134,5 +134,8 @@ void RenderingManager::skySetMoonColour (bool red) { mSkyManager->setMoonColour(red); } +bool RenderingManager::toggleRenderMode(int mode){ + return mDebugging.toggleRenderMode(mode); +} } diff --git a/apps/openmw/mwrender/renderingmanager.hpp b/apps/openmw/mwrender/renderingmanager.hpp index dcac7625d..917be1b22 100644 --- a/apps/openmw/mwrender/renderingmanager.hpp +++ b/apps/openmw/mwrender/renderingmanager.hpp @@ -3,6 +3,7 @@ #include "sky.hpp" +#include "debugging.hpp" #include #include @@ -50,10 +51,12 @@ class RenderingManager { OEngine::Physic::PhysicEngine* eng; MWRender::Player *mPlayer; + MWRender::Debugging mDebugging; public: - RenderingManager(OEngine::Render::OgreRenderer& _rend, const boost::filesystem::path& resDir); + RenderingManager(OEngine::Render::OgreRenderer& _rend, const boost::filesystem::path& resDir, OEngine::Physic::PhysicEngine* engine); ~RenderingManager(); + bool toggleRenderMode(int mode); void removeCell (MWWorld::Ptr::CellStore *store); // TODO do we want this? diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index fafea5e12..2aadaae11 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -176,7 +176,7 @@ namespace MWWorld const Files::Collections& fileCollections, const std::string& master, const boost::filesystem::path& resDir, bool newGame, Environment& environment, const std::string& encoding) - : mRendering (renderer,resDir), mDebugging(physEng), mPlayer (0), mLocalScripts (mStore), mGlobalVariables (0), + : mRendering (renderer,resDir, physEng),mPlayer (0), mLocalScripts (mStore), mGlobalVariables (0), mSky (false), mEnvironment (environment), mNextDynamicRecord (0), mCells (mStore, mEsm, *this) { std::cout << "Creating myworld\n"; @@ -654,7 +654,7 @@ namespace MWWorld bool World::toggleRenderMode (RenderMode mode) { - return mDebugging.toggleRenderMode (mode); + return mRendering.toggleRenderMode (mode); } std::pair World::createRecord (const ESM::Potion& record) diff --git a/apps/openmw/mwworld/world.hpp b/apps/openmw/mwworld/world.hpp index b00b8dead..ca1759e00 100644 --- a/apps/openmw/mwworld/world.hpp +++ b/apps/openmw/mwworld/world.hpp @@ -66,7 +66,7 @@ namespace MWWorld private: MWRender::RenderingManager mRendering; - MWRender::Debugging mDebugging; + MWWorld::Scene *mWorldScene; MWWorld::Player *mPlayer; ESM::ESMReader mEsm; From e1558e8e14cb22bcda807bf4ff8fee81b067e885 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Sun, 30 Oct 2011 16:59:40 -0400 Subject: [PATCH 018/104] Changing refdata --- apps/openmw/mwworld/refdata.hpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/apps/openmw/mwworld/refdata.hpp b/apps/openmw/mwworld/refdata.hpp index a9613248e..af52ab2b0 100644 --- a/apps/openmw/mwworld/refdata.hpp +++ b/apps/openmw/mwworld/refdata.hpp @@ -22,7 +22,9 @@ namespace MWWorld { class RefData { - std::string mHandle; + Ogre::SceneNode* mHandle; + + std::string baseNode; MWScript::Locals mLocals; // if we find the overhead of heaving a locals // object in the refdata of refs without a script, @@ -43,12 +45,18 @@ namespace MWWorld public: - RefData() : mHasLocals (false), mEnabled (true), mCount (1) {} + RefData() : mHasLocals (false), mEnabled (true), mCount (1){ mHandle = 0;} - std::string getHandle() + Ogre::SceneNode* getHandle() { return mHandle; } + std::string getBaseNode(){ + return baseNode; + } + void setBaseNode(const std::string& node){ + baseNode = node; + } int getCount() const { @@ -64,10 +72,6 @@ namespace MWWorld } } - void setHandle (const std::string& handle) - { - mHandle = handle; - } void setCount (int count) { From 15fae749ae2fa3eec8543aeb7539f90fa37b99cb Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Sun, 30 Oct 2011 17:31:49 -0400 Subject: [PATCH 019/104] Changing refdata2 --- apps/openmw/mwworld/refdata.hpp | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/apps/openmw/mwworld/refdata.hpp b/apps/openmw/mwworld/refdata.hpp index af52ab2b0..e64e3bf30 100644 --- a/apps/openmw/mwworld/refdata.hpp +++ b/apps/openmw/mwworld/refdata.hpp @@ -12,6 +12,7 @@ #include "../mwmechanics/movement.hpp" #include "containerstore.hpp" +#include namespace ESM { @@ -22,9 +23,8 @@ namespace MWWorld { class RefData { - Ogre::SceneNode* mHandle; + Ogre::SceneNode* mBaseNode; - std::string baseNode; MWScript::Locals mLocals; // if we find the overhead of heaving a locals // object in the refdata of refs without a script, @@ -45,18 +45,15 @@ namespace MWWorld public: - RefData() : mHasLocals (false), mEnabled (true), mCount (1){ mHandle = 0;} + RefData() : mHasLocals (false), mEnabled (true), mCount (1) {mBaseNode = 0;} - Ogre::SceneNode* getHandle() + std::string getHandle() { - return mHandle; + return mBaseNode->getName(); + } + void setSceneNode(Ogre::SceneNode* base){ + mBaseNode = base; } - std::string getBaseNode(){ - return baseNode; - } - void setBaseNode(const std::string& node){ - baseNode = node; - } int getCount() const { From 86d3cec1aa4c485746a2ab1f6b45731237e034f3 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Sun, 30 Oct 2011 22:38:15 -0400 Subject: [PATCH 020/104] Changing refdata3 --- apps/openmw/mwworld/refdata.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwworld/refdata.hpp b/apps/openmw/mwworld/refdata.hpp index e64e3bf30..0abca5ac0 100644 --- a/apps/openmw/mwworld/refdata.hpp +++ b/apps/openmw/mwworld/refdata.hpp @@ -45,13 +45,13 @@ namespace MWWorld public: - RefData() : mHasLocals (false), mEnabled (true), mCount (1) {mBaseNode = 0;} + RefData() : mHasLocals (false), mEnabled (true), mCount (1),mBaseNode(0) {} std::string getHandle() { return mBaseNode->getName(); } - void setSceneNode(Ogre::SceneNode* base){ + void setBaseNode(Ogre::SceneNode* base){ mBaseNode = base; } From 3761271c59dcbb59400c1463e9c084f71c56e7c7 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Mon, 31 Oct 2011 00:04:06 -0400 Subject: [PATCH 021/104] Empty creature, objects, npc --- apps/openmw/mwrender/cellimp.hpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/apps/openmw/mwrender/cellimp.hpp b/apps/openmw/mwrender/cellimp.hpp index 664fed64f..9c600a508 100644 --- a/apps/openmw/mwrender/cellimp.hpp +++ b/apps/openmw/mwrender/cellimp.hpp @@ -28,6 +28,15 @@ namespace MWRender /// Base class for cell render, that implements inserting references into a cell in a /// cell type- and render-engine-independent way. + class NPC{ + + }; + class Creature{ + + }; + class Obj{ + + }; class CellRenderImp { public: From f1bc5b0ab62d1b909ee84522451c01e87d843598 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Mon, 31 Oct 2011 23:59:16 -0400 Subject: [PATCH 022/104] Objects started, RenderingInterface --- apps/openmw/CMakeLists.txt | 2 +- apps/openmw/mwrender/cellimp.hpp | 9 --------- apps/openmw/mwrender/creatures.cpp | 2 ++ apps/openmw/mwrender/creatures.hpp | 5 +++++ apps/openmw/mwrender/npcs.cpp | 2 ++ apps/openmw/mwrender/npcs.hpp | 5 +++++ apps/openmw/mwrender/objects.cpp | 16 +++++++++++++++ apps/openmw/mwrender/objects.hpp | 18 +++++++++++++++++ apps/openmw/mwrender/renderingmanager.cpp | 15 ++++++++++++++ apps/openmw/mwrender/renderingmanager.hpp | 24 +++++++++++++++++++---- 10 files changed, 84 insertions(+), 14 deletions(-) create mode 100644 apps/openmw/mwrender/creatures.cpp create mode 100644 apps/openmw/mwrender/creatures.hpp create mode 100644 apps/openmw/mwrender/npcs.cpp create mode 100644 apps/openmw/mwrender/npcs.hpp create mode 100644 apps/openmw/mwrender/objects.cpp create mode 100644 apps/openmw/mwrender/objects.hpp diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index 54495063b..4d3dace03 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -16,7 +16,7 @@ set(GAME_HEADER source_group(game FILES ${GAME} ${GAME_HEADER}) add_openmw_dir (mwrender - renderingmanager debugging cellimp interior exterior sky player + renderingmanager debugging cellimp interior exterior sky player npcs creatures objects ) add_openmw_dir (mwinput diff --git a/apps/openmw/mwrender/cellimp.hpp b/apps/openmw/mwrender/cellimp.hpp index 9c600a508..664fed64f 100644 --- a/apps/openmw/mwrender/cellimp.hpp +++ b/apps/openmw/mwrender/cellimp.hpp @@ -28,15 +28,6 @@ namespace MWRender /// Base class for cell render, that implements inserting references into a cell in a /// cell type- and render-engine-independent way. - class NPC{ - - }; - class Creature{ - - }; - class Obj{ - - }; class CellRenderImp { public: diff --git a/apps/openmw/mwrender/creatures.cpp b/apps/openmw/mwrender/creatures.cpp new file mode 100644 index 000000000..998951249 --- /dev/null +++ b/apps/openmw/mwrender/creatures.cpp @@ -0,0 +1,2 @@ +#include "creatures.hpp" +using namespace MWRender; \ No newline at end of file diff --git a/apps/openmw/mwrender/creatures.hpp b/apps/openmw/mwrender/creatures.hpp new file mode 100644 index 000000000..e884d5de4 --- /dev/null +++ b/apps/openmw/mwrender/creatures.hpp @@ -0,0 +1,5 @@ +namespace MWRender{ +class Creatures{ + +}; +} \ No newline at end of file diff --git a/apps/openmw/mwrender/npcs.cpp b/apps/openmw/mwrender/npcs.cpp new file mode 100644 index 000000000..7012ccb18 --- /dev/null +++ b/apps/openmw/mwrender/npcs.cpp @@ -0,0 +1,2 @@ +#include "npcs.hpp" +using namespace MWRender; diff --git a/apps/openmw/mwrender/npcs.hpp b/apps/openmw/mwrender/npcs.hpp new file mode 100644 index 000000000..861be6fc9 --- /dev/null +++ b/apps/openmw/mwrender/npcs.hpp @@ -0,0 +1,5 @@ +namespace MWRender{ +class Npcs{ + +}; +} diff --git a/apps/openmw/mwrender/objects.cpp b/apps/openmw/mwrender/objects.cpp new file mode 100644 index 000000000..9f91eb791 --- /dev/null +++ b/apps/openmw/mwrender/objects.cpp @@ -0,0 +1,16 @@ +#include "objects.hpp" + +using namespace MWRender; + +void Objects::insertBegin (ESM::CellRef &ref, bool static_){ + +} +void Objects::insertMesh(const std::string &mesh){ + +} +void Objects::insertLight(float r, float g, float b, float radius){ + +} +void Objects::insertObjectPhysics(){ + +} \ No newline at end of file diff --git a/apps/openmw/mwrender/objects.hpp b/apps/openmw/mwrender/objects.hpp new file mode 100644 index 000000000..8a8b1ceae --- /dev/null +++ b/apps/openmw/mwrender/objects.hpp @@ -0,0 +1,18 @@ +#include "components/esm_store/cell_store.hpp" + +#include "../mwworld/refdata.hpp" + +namespace MWRender{ +class Objects{ +public: + Objects(){} + ~Objects(){} + void insertBegin (ESM::CellRef &ref, bool static_ = false); + void insertMesh(const std::string &mesh); + + /// insert a light related to the most recent insertBegin call. + void insertLight(float r, float g, float b, float radius); + void insertObjectPhysics(); + +}; +} \ No newline at end of file diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index 89429d061..d3d17b86b 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -15,6 +15,7 @@ #include "player.hpp" + using namespace MWRender; using namespace Ogre; @@ -67,6 +68,20 @@ RenderingManager::~RenderingManager () delete mSkyManager; } +MWRender::Npcs& RenderingManager::getNPCs(){ + return npcs; +} +MWRender::Objects& RenderingManager::getObjects(){ + return objects; +} +MWRender::Creatures& RenderingManager::getCreatures(){ + return creatures; +} +MWRender::Player* RenderingManager::getPlayer(){ + return mPlayer; +} + + void RenderingManager::removeCell (MWWorld::Ptr::CellStore *store){ } diff --git a/apps/openmw/mwrender/renderingmanager.hpp b/apps/openmw/mwrender/renderingmanager.hpp index 917be1b22..0e7fc87a9 100644 --- a/apps/openmw/mwrender/renderingmanager.hpp +++ b/apps/openmw/mwrender/renderingmanager.hpp @@ -15,6 +15,9 @@ #include "../mwworld/ptr.hpp" #include +#include "objects.hpp" +#include "npcs.hpp" +#include "creatures.hpp" namespace Ogre { @@ -34,13 +37,22 @@ namespace MWWorld namespace MWRender { - class Player; - + class Player; + class RenderingInterface{ + public: + virtual MWRender::Npcs& getNPCs(); + virtual MWRender::Creatures& getCreatures(); + virtual MWRender::Objects& getObjects(); + virtual MWRender::Player* getPlayer(); + }; -class RenderingManager { +class RenderingManager: private RenderingInterface { OEngine::Render::OgreRenderer &rend; Ogre::Camera* camera; + MWRender::Npcs npcs; + MWRender::Creatures creatures; + MWRender::Objects objects; /// Root node for all objects added to the scene. This is rotated so /// that the OGRE coordinate system matches that used internally in @@ -56,6 +68,10 @@ class RenderingManager { public: RenderingManager(OEngine::Render::OgreRenderer& _rend, const boost::filesystem::path& resDir, OEngine::Physic::PhysicEngine* engine); ~RenderingManager(); + virtual MWRender::Npcs& getNPCs(); + virtual MWRender::Creatures& getCreatures(); + virtual MWRender::Objects& getObjects(); + virtual MWRender::Player* getPlayer(); bool toggleRenderMode(int mode); void removeCell (MWWorld::Ptr::CellStore *store); // TODO do we want this? @@ -83,7 +99,7 @@ class RenderingManager { OEngine::Render::OgreRenderer& getOgreRenderer(){return rend;} Ogre::SceneManager *getMgr() { return rend.getScene(); } Ogre::SceneNode *getRoot() { return mwRoot; } - MWRender::Player *getPlayer() { return mPlayer; } + private: SkyManager* mSkyManager; From 3d43a4cd33fcac91c7109ab27c90f7d1b95c69fe Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Tue, 1 Nov 2011 13:46:57 -0400 Subject: [PATCH 023/104] Made recommended changes --- apps/openmw/mwrender/objects.cpp | 9 +++------ apps/openmw/mwrender/objects.hpp | 14 ++++++++------ apps/openmw/mwrender/renderingmanager.cpp | 4 ++-- apps/openmw/mwrender/renderingmanager.hpp | 4 ++-- 4 files changed, 15 insertions(+), 16 deletions(-) diff --git a/apps/openmw/mwrender/objects.cpp b/apps/openmw/mwrender/objects.cpp index 9f91eb791..3ad011b93 100644 --- a/apps/openmw/mwrender/objects.cpp +++ b/apps/openmw/mwrender/objects.cpp @@ -2,15 +2,12 @@ using namespace MWRender; -void Objects::insertBegin (ESM::CellRef &ref, bool static_){ +void Objects::insertBegin (const MWWorld::Ptr& ptr, bool enabled, bool static_){ } -void Objects::insertMesh(const std::string &mesh){ +void Objects::insertMesh (const MWWorld::Ptr& ptr, const std::string& mesh){ } -void Objects::insertLight(float r, float g, float b, float radius){ +void Objects::insertLight (const MWWorld::Ptr& ptr, float r, float g, float b, float radius){ } -void Objects::insertObjectPhysics(){ - -} \ No newline at end of file diff --git a/apps/openmw/mwrender/objects.hpp b/apps/openmw/mwrender/objects.hpp index 8a8b1ceae..75752284d 100644 --- a/apps/openmw/mwrender/objects.hpp +++ b/apps/openmw/mwrender/objects.hpp @@ -1,18 +1,20 @@ #include "components/esm_store/cell_store.hpp" #include "../mwworld/refdata.hpp" +#include "../mwworld/ptr.hpp" namespace MWRender{ class Objects{ +private: + OEngine::Render::OgreRenderer &rend; public: - Objects(){} + Objects(OEngine::Render::OgreRenderer& _rend): rend(_rend){} ~Objects(){} - void insertBegin (ESM::CellRef &ref, bool static_ = false); - void insertMesh(const std::string &mesh); + void insertBegin (const MWWorld::Ptr& ptr, bool enabled, bool static_); + void insertMesh (const MWWorld::Ptr& ptr, const std::string& mesh); + void insertLight (const MWWorld::Ptr& ptr, float r, float g, float b, float radius); /// insert a light related to the most recent insertBegin call. - void insertLight(float r, float g, float b, float radius); - void insertObjectPhysics(); - + }; } \ No newline at end of file diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index d3d17b86b..61fe9bf17 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -77,8 +77,8 @@ MWRender::Objects& RenderingManager::getObjects(){ MWRender::Creatures& RenderingManager::getCreatures(){ return creatures; } -MWRender::Player* RenderingManager::getPlayer(){ - return mPlayer; +MWRender::Player& RenderingManager::getPlayer(){ + return (*mPlayer); } diff --git a/apps/openmw/mwrender/renderingmanager.hpp b/apps/openmw/mwrender/renderingmanager.hpp index 0e7fc87a9..9f751959d 100644 --- a/apps/openmw/mwrender/renderingmanager.hpp +++ b/apps/openmw/mwrender/renderingmanager.hpp @@ -43,7 +43,7 @@ namespace MWRender virtual MWRender::Npcs& getNPCs(); virtual MWRender::Creatures& getCreatures(); virtual MWRender::Objects& getObjects(); - virtual MWRender::Player* getPlayer(); + virtual MWRender::Player& getPlayer(); }; class RenderingManager: private RenderingInterface { @@ -71,7 +71,7 @@ class RenderingManager: private RenderingInterface { virtual MWRender::Npcs& getNPCs(); virtual MWRender::Creatures& getCreatures(); virtual MWRender::Objects& getObjects(); - virtual MWRender::Player* getPlayer(); + virtual MWRender::Player& getPlayer(); bool toggleRenderMode(int mode); void removeCell (MWWorld::Ptr::CellStore *store); // TODO do we want this? From 5822221ae1a60016cab961cfd4649cd793eb5c4b Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Tue, 1 Nov 2011 13:47:36 -0400 Subject: [PATCH 024/104] Made recommended changes --- apps/openmw/mwworld/world.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index 2aadaae11..821179d38 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -9,6 +9,7 @@ #include "../mwrender/sky.hpp" #include "../mwrender/interior.hpp" #include "../mwrender/exterior.hpp" +#include "../mwrender/player.hpp" #include "../mwmechanics/mechanicsmanager.hpp" @@ -193,7 +194,8 @@ namespace MWWorld mEsm.open (masterPath.string()); mStore.load (mEsm); - mPlayer = new MWWorld::Player (mRendering.getPlayer(), mStore.npcs.find ("player"), *this); + MWRender::Player* play = &(mRendering.getPlayer()); + mPlayer = new MWWorld::Player (play, mStore.npcs.find ("player"), *this); mPhysics->addActor (mPlayer->getPlayer().getRefData().getHandle(), "", Ogre::Vector3 (0, 0, 0)); // global variables From c2181d209144de326e7b6b48138ebc85aa0d292f Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Wed, 2 Nov 2011 00:13:33 -0400 Subject: [PATCH 025/104] Dealing with scenenodes --- apps/openmw/mwrender/creatures.hpp | 2 ++ apps/openmw/mwrender/npcs.hpp | 1 + apps/openmw/mwrender/objects.cpp | 7 +++++ apps/openmw/mwrender/objects.hpp | 6 ++++- apps/openmw/mwrender/renderingmanager.cpp | 5 ++-- apps/openmw/mwrender/renderingmanager.hpp | 33 ++++++++++++----------- 6 files changed, 35 insertions(+), 19 deletions(-) diff --git a/apps/openmw/mwrender/creatures.hpp b/apps/openmw/mwrender/creatures.hpp index e884d5de4..17946f050 100644 --- a/apps/openmw/mwrender/creatures.hpp +++ b/apps/openmw/mwrender/creatures.hpp @@ -1,3 +1,5 @@ +#include + namespace MWRender{ class Creatures{ diff --git a/apps/openmw/mwrender/npcs.hpp b/apps/openmw/mwrender/npcs.hpp index 861be6fc9..c9701f195 100644 --- a/apps/openmw/mwrender/npcs.hpp +++ b/apps/openmw/mwrender/npcs.hpp @@ -1,3 +1,4 @@ +#include namespace MWRender{ class Npcs{ diff --git a/apps/openmw/mwrender/objects.cpp b/apps/openmw/mwrender/objects.cpp index 3ad011b93..ed32a8786 100644 --- a/apps/openmw/mwrender/objects.cpp +++ b/apps/openmw/mwrender/objects.cpp @@ -1,9 +1,15 @@ #include "objects.hpp" +#include using namespace MWRender; void Objects::insertBegin (const MWWorld::Ptr& ptr, bool enabled, bool static_){ + ptr.getRefData().setBaseNode(mBase); + assert (!mInsert); + isStatic = static_; + // Create and place scene node for this object + mInsert = mBase->createChildSceneNode(); } void Objects::insertMesh (const MWWorld::Ptr& ptr, const std::string& mesh){ @@ -11,3 +17,4 @@ void Objects::insertMesh (const MWWorld::Ptr& ptr, const std::string& mesh){ void Objects::insertLight (const MWWorld::Ptr& ptr, float r, float g, float b, float radius){ } + diff --git a/apps/openmw/mwrender/objects.hpp b/apps/openmw/mwrender/objects.hpp index 75752284d..e382fb05b 100644 --- a/apps/openmw/mwrender/objects.hpp +++ b/apps/openmw/mwrender/objects.hpp @@ -2,13 +2,17 @@ #include "../mwworld/refdata.hpp" #include "../mwworld/ptr.hpp" +#include namespace MWRender{ class Objects{ private: OEngine::Render::OgreRenderer &rend; + Ogre::SceneNode *mBase; + Ogre::SceneNode *mInsert; + bool isStatic; public: - Objects(OEngine::Render::OgreRenderer& _rend): rend(_rend){} + Objects(OEngine::Render::OgreRenderer& _rend): rend(_rend){mBase = rend.getScene()->getRootSceneNode(); } ~Objects(){} void insertBegin (const MWWorld::Ptr& ptr, bool enabled, bool static_); void insertMesh (const MWWorld::Ptr& ptr, const std::string& mesh); diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index 61fe9bf17..952388fd4 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -1,4 +1,5 @@ #include "renderingmanager.hpp" +#include "objects.hpp" #include @@ -23,7 +24,7 @@ namespace MWRender { -RenderingManager::RenderingManager (OEngine::Render::OgreRenderer& _rend, const boost::filesystem::path& resDir, OEngine::Physic::PhysicEngine* engine) :rend(_rend), mDebugging(engine) +RenderingManager::RenderingManager (OEngine::Render::OgreRenderer& _rend, const boost::filesystem::path& resDir, OEngine::Physic::PhysicEngine* engine) :rend(_rend), mDebugging(engine), objects(rend) { @@ -58,8 +59,8 @@ RenderingManager::RenderingManager (OEngine::Render::OgreRenderer& _rend, const cameraPitchNode->attachObject(rend.getCamera()); mPlayer = new MWRender::Player (rend.getCamera(), playerNode->getName()); + //std::cout << "Three"; - } RenderingManager::~RenderingManager () diff --git a/apps/openmw/mwrender/renderingmanager.hpp b/apps/openmw/mwrender/renderingmanager.hpp index 9f751959d..e8989d740 100644 --- a/apps/openmw/mwrender/renderingmanager.hpp +++ b/apps/openmw/mwrender/renderingmanager.hpp @@ -48,22 +48,7 @@ namespace MWRender class RenderingManager: private RenderingInterface { - OEngine::Render::OgreRenderer &rend; - Ogre::Camera* camera; - MWRender::Npcs npcs; - MWRender::Creatures creatures; - MWRender::Objects objects; - - /// Root node for all objects added to the scene. This is rotated so - /// that the OGRE coordinate system matches that used internally in - /// Morrowind. - Ogre::SceneNode *mwRoot; - Ogre::RaySceneQuery *mRaySceneQuery; - - OEngine::Physic::PhysicEngine* eng; - - MWRender::Player *mPlayer; - MWRender::Debugging mDebugging; + public: RenderingManager(OEngine::Render::OgreRenderer& _rend, const boost::filesystem::path& resDir, OEngine::Physic::PhysicEngine* engine); @@ -103,6 +88,22 @@ class RenderingManager: private RenderingInterface { private: SkyManager* mSkyManager; + OEngine::Render::OgreRenderer &rend; + Ogre::Camera* camera; + MWRender::Npcs npcs; + MWRender::Creatures creatures; + MWRender::Objects objects; + + /// Root node for all objects added to the scene. This is rotated so + /// that the OGRE coordinate system matches that used internally in + /// Morrowind. + Ogre::SceneNode *mwRoot; + Ogre::RaySceneQuery *mRaySceneQuery; + + OEngine::Physic::PhysicEngine* eng; + + MWRender::Player *mPlayer; + MWRender::Debugging mDebugging; }; From d49a02abe5324b98e3da30405d395f2ae9a64841 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Wed, 2 Nov 2011 22:41:48 -0400 Subject: [PATCH 026/104] new insertBegin() --- apps/openmw/mwrender/objects.cpp | 21 +++++++++++++++++---- apps/openmw/mwrender/objects.hpp | 5 ++--- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/apps/openmw/mwrender/objects.cpp b/apps/openmw/mwrender/objects.cpp index ed32a8786..25308962d 100644 --- a/apps/openmw/mwrender/objects.cpp +++ b/apps/openmw/mwrender/objects.cpp @@ -4,12 +4,25 @@ using namespace MWRender; void Objects::insertBegin (const MWWorld::Ptr& ptr, bool enabled, bool static_){ - ptr.getRefData().setBaseNode(mBase); - assert (!mInsert); + Ogre::SceneNode* root = rend.getScene()->getRootSceneNode(); + Ogre::SceneNode* cellnode; + if(cellSceneNodes.find(ptr.getCell()) == cellSceneNodes.end()) + { + //Create the scenenode and put it in the map + cellnode = root->createChildSceneNode(); + cellSceneNodes[ptr.getCell()] = cellnode; + assert(!cellnode->getChildIterator()->begin()); //Is this right? + } + else + { + cellnode = (cellSceneNodes.find(ptr.getCell()))->second; + } + Ogre::SceneNode* insert = cellnode->createChildSceneNode(); + + ptr.getRefData().setBaseNode(insert); isStatic = static_; - // Create and place scene node for this object - mInsert = mBase->createChildSceneNode(); + } void Objects::insertMesh (const MWWorld::Ptr& ptr, const std::string& mesh){ diff --git a/apps/openmw/mwrender/objects.hpp b/apps/openmw/mwrender/objects.hpp index e382fb05b..53a3745ed 100644 --- a/apps/openmw/mwrender/objects.hpp +++ b/apps/openmw/mwrender/objects.hpp @@ -8,11 +8,10 @@ namespace MWRender{ class Objects{ private: OEngine::Render::OgreRenderer &rend; - Ogre::SceneNode *mBase; - Ogre::SceneNode *mInsert; + std::map cellSceneNodes; bool isStatic; public: - Objects(OEngine::Render::OgreRenderer& _rend): rend(_rend){mBase = rend.getScene()->getRootSceneNode(); } + Objects(OEngine::Render::OgreRenderer& _rend): rend(_rend){} ~Objects(){} void insertBegin (const MWWorld::Ptr& ptr, bool enabled, bool static_); void insertMesh (const MWWorld::Ptr& ptr, const std::string& mesh); From 9ac627c93113b5bda1587813f5365db1be8a19fa Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Wed, 2 Nov 2011 22:45:58 -0400 Subject: [PATCH 027/104] Commenting out assert --- apps/openmw/mwrender/objects.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/openmw/mwrender/objects.cpp b/apps/openmw/mwrender/objects.cpp index 25308962d..97e086429 100644 --- a/apps/openmw/mwrender/objects.cpp +++ b/apps/openmw/mwrender/objects.cpp @@ -11,7 +11,7 @@ void Objects::insertBegin (const MWWorld::Ptr& ptr, bool enabled, bool static_){ //Create the scenenode and put it in the map cellnode = root->createChildSceneNode(); cellSceneNodes[ptr.getCell()] = cellnode; - assert(!cellnode->getChildIterator()->begin()); //Is this right? + //assert(!cellnode->getChildIterator()->begin()); //Is this right? } else { From edf85b26f9f12298d0ce32f30a0e4addfd44b968 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Thu, 3 Nov 2011 19:40:37 -0400 Subject: [PATCH 028/104] Insert Mesh, Insert Light, insertBegin improved --- apps/openmw/mwrender/objects.cpp | 95 ++++++++++++++++++++++++++++++-- apps/openmw/mwrender/objects.hpp | 25 ++++++++- 2 files changed, 111 insertions(+), 9 deletions(-) diff --git a/apps/openmw/mwrender/objects.cpp b/apps/openmw/mwrender/objects.cpp index 97e086429..963d03e12 100644 --- a/apps/openmw/mwrender/objects.cpp +++ b/apps/openmw/mwrender/objects.cpp @@ -1,33 +1,116 @@ #include "objects.hpp" #include +#include using namespace MWRender; +using namespace Ogre; + +bool Objects::lightConst = false; +float Objects::lightConstValue = 0.0f; + +bool Objects::lightLinear = true; +int Objects::lightLinearMethod = 1; +float Objects::lightLinearValue = 3; +float Objects::lightLinearRadiusMult = 1; + +bool Objects::lightQuadratic = false; +int Objects::lightQuadraticMethod = 2; +float Objects::lightQuadraticValue = 16; +float Objects::lightQuadraticRadiusMult = 1; + +bool Objects::lightOutQuadInLin = false; + +int Objects::uniqueID = 0; void Objects::insertBegin (const MWWorld::Ptr& ptr, bool enabled, bool static_){ - Ogre::SceneNode* root = rend.getScene()->getRootSceneNode(); + Ogre::SceneNode* root = mRend.getScene()->getRootSceneNode(); Ogre::SceneNode* cellnode; - if(cellSceneNodes.find(ptr.getCell()) == cellSceneNodes.end()) + if(mCellSceneNodes.find(ptr.getCell()) == mCellSceneNodes.end()) { //Create the scenenode and put it in the map cellnode = root->createChildSceneNode(); - cellSceneNodes[ptr.getCell()] = cellnode; - //assert(!cellnode->getChildIterator()->begin()); //Is this right? + mCellSceneNodes[ptr.getCell()] = cellnode; } else { - cellnode = (cellSceneNodes.find(ptr.getCell()))->second; + cellnode = (mCellSceneNodes.find(ptr.getCell()))->second; } Ogre::SceneNode* insert = cellnode->createChildSceneNode(); - + const float *f = ptr.getCellRef().pos.pos; + insert->setPosition(f[0], f[1], f[2]); + insert->setScale(ptr.getCellRef().scale, ptr.getCellRef().scale, ptr.getCellRef().scale); + + // Convert MW rotation to a quaternion: + f = ptr.getCellRef().pos.rot; + + // Rotate around X axis + Quaternion xr(Radian(-f[0]), Vector3::UNIT_X); + + // Rotate around Y axis + Quaternion yr(Radian(-f[1]), Vector3::UNIT_Y); + + // Rotate around Z axis + Quaternion zr(Radian(-f[2]), Vector3::UNIT_Z); + + // Rotates first around z, then y, then x + insert->setOrientation(xr*yr*zr); + if (!enabled) + insert->setVisible (false); ptr.getRefData().setBaseNode(insert); isStatic = static_; } void Objects::insertMesh (const MWWorld::Ptr& ptr, const std::string& mesh){ + Ogre::SceneNode* insert = mRend.getScene()->getSceneNode(ptr.getRefData().getHandle()); + assert(insert); + + NifOgre::NIFLoader::load(mesh); + Entity *ent = mRend.getScene()->createEntity(mesh); + + if(!isStatic) + { + insert->attachObject(ent); + } + else + { + sg->addEntity(ent,insert->_getDerivedPosition(),insert->_getDerivedOrientation(),insert->_getDerivedScale()); + sg->setRegionDimensions(Ogre::Vector3(100000,10000,100000)); + mRend.getScene()->destroyEntity(ent); + } } void Objects::insertLight (const MWWorld::Ptr& ptr, float r, float g, float b, float radius){ + Ogre::SceneNode* insert = mRend.getScene()->getSceneNode(ptr.getRefData().getHandle()); + assert(insert); + Ogre::Light *light = mRend.getScene()->createLight(); + light->setDiffuseColour (r, g, b); + + float cval=0.0f, lval=0.0f, qval=0.0f; + + if(lightConst) + cval = lightConstValue; + if(!lightOutQuadInLin) + { + if(lightLinear) + radius *= lightLinearRadiusMult; + if(lightQuadratic) + radius *= lightQuadraticRadiusMult; + + if(lightLinear) + lval = lightLinearValue / pow(radius, lightLinearMethod); + if(lightQuadratic) + qval = lightQuadraticValue / pow(radius, lightQuadraticMethod); + } + else + { + // FIXME: + // Do quadratic or linear, depending if we're in an exterior or interior + // cell, respectively. Ignore lightLinear and lightQuadratic. + } + + light->setAttenuation(10*radius, cval, lval, qval); + insert->attachObject(light); } diff --git a/apps/openmw/mwrender/objects.hpp b/apps/openmw/mwrender/objects.hpp index 53a3745ed..1b1722365 100644 --- a/apps/openmw/mwrender/objects.hpp +++ b/apps/openmw/mwrender/objects.hpp @@ -7,11 +7,30 @@ namespace MWRender{ class Objects{ private: - OEngine::Render::OgreRenderer &rend; - std::map cellSceneNodes; + OEngine::Render::OgreRenderer &mRend; + std::map mCellSceneNodes; bool isStatic; + Ogre::StaticGeometry *sg; + static int uniqueID; + static bool lightConst; + static float lightConstValue; + + static bool lightLinear; + static int lightLinearMethod; + static float lightLinearValue; + static float lightLinearRadiusMult; + + static bool lightQuadratic; + static int lightQuadraticMethod; + static float lightQuadraticValue; + static float lightQuadraticRadiusMult; + + static bool lightOutQuadInLin; public: - Objects(OEngine::Render::OgreRenderer& _rend): rend(_rend){} + Objects(OEngine::Render::OgreRenderer& _rend): mRend(_rend){ + uniqueID = uniqueID +1; + sg = mRend.getScene()->createStaticGeometry( "sg" + Ogre::StringConverter::toString(uniqueID)); + } ~Objects(){} void insertBegin (const MWWorld::Ptr& ptr, bool enabled, bool static_); void insertMesh (const MWWorld::Ptr& ptr, const std::string& mesh); From e04100606358f065fc455b883cc253d0f73984af Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Thu, 3 Nov 2011 23:47:15 -0400 Subject: [PATCH 029/104] Adding light and fog functions --- apps/openmw/mwrender/renderingmanager.cpp | 67 +++++++++++++++++++++++ apps/openmw/mwrender/renderingmanager.hpp | 12 +++- 2 files changed, 78 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index 952388fd4..b07251f53 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -154,4 +154,71 @@ bool RenderingManager::toggleRenderMode(int mode){ return mDebugging.toggleRenderMode(mode); } +void RenderingManager::configureFog(ESMS::CellStore &mCell) +{ + Ogre::ColourValue color; + color.setAsABGR (mCell.cell->ambi.fog); + + float high = 4500 + 9000 * (1-mCell.cell->ambi.fogDensity); + float low = 200; + + rend.getScene()->setFog (FOG_LINEAR, color, 0, low, high); + rend.getCamera()->setFarClipDistance (high + 10); + rend.getViewport()->setBackgroundColour (color); +} + +void RenderingManager::setAmbientMode() +{ + switch (mAmbientMode) + { + case 0: + + rend.getScene()->setAmbientLight(mAmbientColor); + break; + + case 1: + + rend.getScene()->setAmbientLight(0.7f*mAmbientColor + 0.3f*ColourValue(1,1,1)); + break; + + case 2: + + rend.getScene()->setAmbientLight(ColourValue(1,1,1)); + break; + } +} + +void RenderingManager::configureAmbient(ESMS::CellStore &mCell) +{ + mAmbientColor.setAsABGR (mCell.cell->ambi.ambient); + setAmbientMode(); + + // Create a "sun" that shines light downwards. It doesn't look + // completely right, but leave it for now. + Ogre::Light *light = rend.getScene()->createLight(); + Ogre::ColourValue colour; + colour.setAsABGR (mCell.cell->ambi.sunlight); + light->setDiffuseColour (colour); + light->setType(Ogre::Light::LT_DIRECTIONAL); + light->setDirection(0,-1,0); +} +// Switch through lighting modes. + +void RenderingManager::toggleLight() +{ + if (mAmbientMode==2) + mAmbientMode = 0; + else + ++mAmbientMode; + + switch (mAmbientMode) + { + case 0: std::cout << "Setting lights to normal\n"; break; + case 1: std::cout << "Turning the lights up\n"; break; + case 2: std::cout << "Turning the lights to full\n"; break; + } + + setAmbientMode(); +} + } diff --git a/apps/openmw/mwrender/renderingmanager.hpp b/apps/openmw/mwrender/renderingmanager.hpp index e8989d740..0d2375feb 100644 --- a/apps/openmw/mwrender/renderingmanager.hpp +++ b/apps/openmw/mwrender/renderingmanager.hpp @@ -57,6 +57,8 @@ class RenderingManager: private RenderingInterface { virtual MWRender::Creatures& getCreatures(); virtual MWRender::Objects& getObjects(); virtual MWRender::Player& getPlayer(); + + void toggleLight(); bool toggleRenderMode(int mode); void removeCell (MWWorld::Ptr::CellStore *store); // TODO do we want this? @@ -86,7 +88,10 @@ class RenderingManager: private RenderingInterface { Ogre::SceneNode *getRoot() { return mwRoot; } private: - + void configureAmbient(ESMS::CellStore &mCell); + /// configure fog according to cell + void configureFog(ESMS::CellStore &mCell); + void setAmbientMode(); SkyManager* mSkyManager; OEngine::Render::OgreRenderer &rend; Ogre::Camera* camera; @@ -94,6 +99,11 @@ class RenderingManager: private RenderingInterface { MWRender::Creatures creatures; MWRender::Objects objects; + // 0 normal, 1 more bright, 2 max + int mAmbientMode; + + Ogre::ColourValue mAmbientColor; + /// Root node for all objects added to the scene. This is rotated so /// that the OGRE coordinate system matches that used internally in /// Morrowind. From 6c80e75deb1d3e480d351f2991bedfc59aef5407 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Fri, 4 Nov 2011 21:48:52 -0400 Subject: [PATCH 030/104] More Objects functionality --- apps/openmw/mwrender/objects.cpp | 48 +++++++++++++++++++++++++++++++- apps/openmw/mwrender/objects.hpp | 6 ++-- 2 files changed, 50 insertions(+), 4 deletions(-) diff --git a/apps/openmw/mwrender/objects.cpp b/apps/openmw/mwrender/objects.cpp index 963d03e12..1f2ee1978 100644 --- a/apps/openmw/mwrender/objects.cpp +++ b/apps/openmw/mwrender/objects.cpp @@ -33,8 +33,11 @@ void Objects::insertBegin (const MWWorld::Ptr& ptr, bool enabled, bool static_){ } else { - cellnode = (mCellSceneNodes.find(ptr.getCell()))->second; + cellnode = mCellSceneNodes[ptr.getCell()]; } + + + Ogre::SceneNode* insert = cellnode->createChildSceneNode(); const float *f = ptr.getCellRef().pos.pos; insert->setPosition(f[0], f[1], f[2]); @@ -74,8 +77,23 @@ void Objects::insertMesh (const MWWorld::Ptr& ptr, const std::string& mesh){ } else { + Ogre::StaticGeometry* sg; + if(mSG.find(ptr.getCell()) == mSG.end()) + { + uniqueID = uniqueID +1; + sg = mRend.getScene()->createStaticGeometry( "sg" + Ogre::StringConverter::toString(uniqueID)); + //Create the scenenode and put it in the map + mSG[ptr.getCell()] = sg; + } + else + { + sg = mSG[ptr.getCell()]; + } + sg->addEntity(ent,insert->_getDerivedPosition(),insert->_getDerivedOrientation(),insert->_getDerivedScale()); sg->setRegionDimensions(Ogre::Vector3(100000,10000,100000)); + + sg->build(); //Is this the right place for building? mRend.getScene()->destroyEntity(ent); } @@ -114,3 +132,31 @@ void Objects::insertLight (const MWWorld::Ptr& ptr, float r, float g, float b, f insert->attachObject(light); } +void Objects::deleteObject (const std::string& handle) +{ + if (!handle.empty()) + { + Ogre::SceneNode *node = mRend.getScene()->getSceneNode (handle); + node->removeAndDestroyAllChildren(); + mRend.getScene()->destroySceneNode (node); + } +} + +void Objects::removeCell(const MWWorld::Ptr& ptr){ + if(mCellSceneNodes.find(ptr.getCell()) != mCellSceneNodes.end()) + { + Ogre::SceneNode* base = mCellSceneNodes[ptr.getCell()]; + base->removeAndDestroyAllChildren(); + mRend.getScene()->destroySceneNode(base); + base = 0; + } + + + if(mSG.find(ptr.getCell()) != mSG.end()) + { + Ogre::StaticGeometry* sg = mSG[ptr.getCell()]; + mRend.getScene()->destroyStaticGeometry (sg); + sg = 0; + } +} + diff --git a/apps/openmw/mwrender/objects.hpp b/apps/openmw/mwrender/objects.hpp index 1b1722365..6bd1d31c6 100644 --- a/apps/openmw/mwrender/objects.hpp +++ b/apps/openmw/mwrender/objects.hpp @@ -9,8 +9,8 @@ class Objects{ private: OEngine::Render::OgreRenderer &mRend; std::map mCellSceneNodes; + std::map mSG; bool isStatic; - Ogre::StaticGeometry *sg; static int uniqueID; static bool lightConst; static float lightConstValue; @@ -28,13 +28,13 @@ private: static bool lightOutQuadInLin; public: Objects(OEngine::Render::OgreRenderer& _rend): mRend(_rend){ - uniqueID = uniqueID +1; - sg = mRend.getScene()->createStaticGeometry( "sg" + Ogre::StringConverter::toString(uniqueID)); } ~Objects(){} void insertBegin (const MWWorld::Ptr& ptr, bool enabled, bool static_); void insertMesh (const MWWorld::Ptr& ptr, const std::string& mesh); void insertLight (const MWWorld::Ptr& ptr, float r, float g, float b, float radius); + void deleteObject (const std::string& handle); + void removeCell(const MWWorld::Ptr& ptr); /// insert a light related to the most recent insertBegin call. From 8edcd4d15baea16bf7434416bdb51d902b00c8cc Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Fri, 4 Nov 2011 21:57:39 -0400 Subject: [PATCH 031/104] removing tabs --- apps/openmw/mwrender/objects.cpp | 130 +++++++++++++++---------------- apps/openmw/mwrender/objects.hpp | 17 ++-- 2 files changed, 73 insertions(+), 74 deletions(-) diff --git a/apps/openmw/mwrender/objects.cpp b/apps/openmw/mwrender/objects.cpp index 1f2ee1978..429dae71d 100644 --- a/apps/openmw/mwrender/objects.cpp +++ b/apps/openmw/mwrender/objects.cpp @@ -23,91 +23,91 @@ bool Objects::lightOutQuadInLin = false; int Objects::uniqueID = 0; void Objects::insertBegin (const MWWorld::Ptr& ptr, bool enabled, bool static_){ - Ogre::SceneNode* root = mRend.getScene()->getRootSceneNode(); - Ogre::SceneNode* cellnode; - if(mCellSceneNodes.find(ptr.getCell()) == mCellSceneNodes.end()) - { + Ogre::SceneNode* root = mRend.getScene()->getRootSceneNode(); + Ogre::SceneNode* cellnode; + if(mCellSceneNodes.find(ptr.getCell()) == mCellSceneNodes.end()) + { //Create the scenenode and put it in the map cellnode = root->createChildSceneNode(); - mCellSceneNodes[ptr.getCell()] = cellnode; + mCellSceneNodes[ptr.getCell()] = cellnode; } else - { - cellnode = mCellSceneNodes[ptr.getCell()]; - } + { + cellnode = mCellSceneNodes[ptr.getCell()]; + } - Ogre::SceneNode* insert = cellnode->createChildSceneNode(); - const float *f = ptr.getCellRef().pos.pos; - insert->setPosition(f[0], f[1], f[2]); - insert->setScale(ptr.getCellRef().scale, ptr.getCellRef().scale, ptr.getCellRef().scale); + Ogre::SceneNode* insert = cellnode->createChildSceneNode(); + const float *f = ptr.getCellRef().pos.pos; + insert->setPosition(f[0], f[1], f[2]); + insert->setScale(ptr.getCellRef().scale, ptr.getCellRef().scale, ptr.getCellRef().scale); - // Convert MW rotation to a quaternion: - f = ptr.getCellRef().pos.rot; + // Convert MW rotation to a quaternion: + f = ptr.getCellRef().pos.rot; - // Rotate around X axis - Quaternion xr(Radian(-f[0]), Vector3::UNIT_X); + // Rotate around X axis + Quaternion xr(Radian(-f[0]), Vector3::UNIT_X); - // Rotate around Y axis - Quaternion yr(Radian(-f[1]), Vector3::UNIT_Y); + // Rotate around Y axis + Quaternion yr(Radian(-f[1]), Vector3::UNIT_Y); - // Rotate around Z axis - Quaternion zr(Radian(-f[2]), Vector3::UNIT_Z); + // Rotate around Z axis + Quaternion zr(Radian(-f[2]), Vector3::UNIT_Z); - // Rotates first around z, then y, then x - insert->setOrientation(xr*yr*zr); - if (!enabled) - insert->setVisible (false); + // Rotates first around z, then y, then x + insert->setOrientation(xr*yr*zr); + if (!enabled) + insert->setVisible (false); ptr.getRefData().setBaseNode(insert); - isStatic = static_; + isStatic = static_; } void Objects::insertMesh (const MWWorld::Ptr& ptr, const std::string& mesh){ - Ogre::SceneNode* insert = mRend.getScene()->getSceneNode(ptr.getRefData().getHandle()); - assert(insert); + Ogre::SceneNode* insert = mRend.getScene()->getSceneNode(ptr.getRefData().getHandle()); + assert(insert); - NifOgre::NIFLoader::load(mesh); - Entity *ent = mRend.getScene()->createEntity(mesh); + NifOgre::NIFLoader::load(mesh); + Entity *ent = mRend.getScene()->createEntity(mesh); - if(!isStatic) - { - insert->attachObject(ent); - } - else - { - Ogre::StaticGeometry* sg; - if(mSG.find(ptr.getCell()) == mSG.end()) - { - uniqueID = uniqueID +1; - sg = mRend.getScene()->createStaticGeometry( "sg" + Ogre::StringConverter::toString(uniqueID)); - //Create the scenenode and put it in the map - mSG[ptr.getCell()] = sg; - } - else - { - sg = mSG[ptr.getCell()]; - } - - sg->addEntity(ent,insert->_getDerivedPosition(),insert->_getDerivedOrientation(),insert->_getDerivedScale()); - sg->setRegionDimensions(Ogre::Vector3(100000,10000,100000)); - - sg->build(); //Is this the right place for building? - mRend.getScene()->destroyEntity(ent); - } + if(!isStatic) + { + insert->attachObject(ent); + } + else + { + Ogre::StaticGeometry* sg; + if(mSG.find(ptr.getCell()) == mSG.end()) + { + uniqueID = uniqueID +1; + sg = mRend.getScene()->createStaticGeometry( "sg" + Ogre::StringConverter::toString(uniqueID)); + //Create the scenenode and put it in the map + mSG[ptr.getCell()] = sg; + } + else + { + sg = mSG[ptr.getCell()]; + } + + sg->addEntity(ent,insert->_getDerivedPosition(),insert->_getDerivedOrientation(),insert->_getDerivedScale()); + sg->setRegionDimensions(Ogre::Vector3(100000,10000,100000)); + + sg->build(); //Is this the right place for building? + mRend.getScene()->destroyEntity(ent); + } } void Objects::insertLight (const MWWorld::Ptr& ptr, float r, float g, float b, float radius){ - Ogre::SceneNode* insert = mRend.getScene()->getSceneNode(ptr.getRefData().getHandle()); - assert(insert); - Ogre::Light *light = mRend.getScene()->createLight(); - light->setDiffuseColour (r, g, b); + Ogre::SceneNode* insert = mRend.getScene()->getSceneNode(ptr.getRefData().getHandle()); + assert(insert); + Ogre::Light *light = mRend.getScene()->createLight(); + light->setDiffuseColour (r, g, b); - float cval=0.0f, lval=0.0f, qval=0.0f; + float cval=0.0f, lval=0.0f, qval=0.0f; - if(lightConst) - cval = lightConstValue; + if(lightConst) + cval = lightConstValue; if(!lightOutQuadInLin) { if(lightLinear) @@ -145,10 +145,10 @@ void Objects::deleteObject (const std::string& handle) void Objects::removeCell(const MWWorld::Ptr& ptr){ if(mCellSceneNodes.find(ptr.getCell()) != mCellSceneNodes.end()) { - Ogre::SceneNode* base = mCellSceneNodes[ptr.getCell()]; - base->removeAndDestroyAllChildren(); - mRend.getScene()->destroySceneNode(base); - base = 0; + Ogre::SceneNode* base = mCellSceneNodes[ptr.getCell()]; + base->removeAndDestroyAllChildren(); + mRend.getScene()->destroySceneNode(base); + base = 0; } diff --git a/apps/openmw/mwrender/objects.hpp b/apps/openmw/mwrender/objects.hpp index 6bd1d31c6..da21300b7 100644 --- a/apps/openmw/mwrender/objects.hpp +++ b/apps/openmw/mwrender/objects.hpp @@ -10,9 +10,9 @@ private: OEngine::Render::OgreRenderer &mRend; std::map mCellSceneNodes; std::map mSG; - bool isStatic; - static int uniqueID; - static bool lightConst; + bool isStatic; + static int uniqueID; + static bool lightConst; static float lightConstValue; static bool lightLinear; @@ -27,14 +27,13 @@ private: static bool lightOutQuadInLin; public: - Objects(OEngine::Render::OgreRenderer& _rend): mRend(_rend){ - } + Objects(OEngine::Render::OgreRenderer& _rend): mRend(_rend){} ~Objects(){} - void insertBegin (const MWWorld::Ptr& ptr, bool enabled, bool static_); + void insertBegin (const MWWorld::Ptr& ptr, bool enabled, bool static_); void insertMesh (const MWWorld::Ptr& ptr, const std::string& mesh); - void insertLight (const MWWorld::Ptr& ptr, float r, float g, float b, float radius); - void deleteObject (const std::string& handle); - void removeCell(const MWWorld::Ptr& ptr); + void insertLight (const MWWorld::Ptr& ptr, float r, float g, float b, float radius); + void deleteObject (const std::string& handle); + void removeCell(const MWWorld::Ptr& ptr); /// insert a light related to the most recent insertBegin call. From c11b3a57c1fef17f31ea14c0decedf0050647926 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Sat, 5 Nov 2011 14:57:33 -0400 Subject: [PATCH 032/104] Made buildStaticGeometry function --- apps/openmw/mwrender/objects.cpp | 9 ++++++++- apps/openmw/mwrender/objects.hpp | 2 ++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwrender/objects.cpp b/apps/openmw/mwrender/objects.cpp index 429dae71d..0632255be 100644 --- a/apps/openmw/mwrender/objects.cpp +++ b/apps/openmw/mwrender/objects.cpp @@ -93,7 +93,7 @@ void Objects::insertMesh (const MWWorld::Ptr& ptr, const std::string& mesh){ sg->addEntity(ent,insert->_getDerivedPosition(),insert->_getDerivedOrientation(),insert->_getDerivedScale()); sg->setRegionDimensions(Ogre::Vector3(100000,10000,100000)); - sg->build(); //Is this the right place for building? + mRend.getScene()->destroyEntity(ent); } @@ -159,4 +159,11 @@ void Objects::removeCell(const MWWorld::Ptr& ptr){ sg = 0; } } +void Objects::buildStaticGeometry(const MWWorld::Ptr& ptr){ + if(mSG.find(ptr.getCell()) != mSG.end()) + { + Ogre::StaticGeometry* sg = mSG[ptr.getCell()]; + sg->build(); + } +} diff --git a/apps/openmw/mwrender/objects.hpp b/apps/openmw/mwrender/objects.hpp index da21300b7..ebb52906a 100644 --- a/apps/openmw/mwrender/objects.hpp +++ b/apps/openmw/mwrender/objects.hpp @@ -34,6 +34,8 @@ public: void insertLight (const MWWorld::Ptr& ptr, float r, float g, float b, float radius); void deleteObject (const std::string& handle); void removeCell(const MWWorld::Ptr& ptr); + void buildStaticGeometry(const MWWorld::Ptr& ptr); + /// insert a light related to the most recent insertBegin call. From 469086747e5cfbec8247986fb5ba29319ef8918a Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Mon, 7 Nov 2011 23:35:39 -0500 Subject: [PATCH 033/104] Compile error fix;RenderingInterface separated; buildStaticGeometry argument changed --- apps/openmw/CMakeLists.txt | 2 +- apps/openmw/mwrender/objects.cpp | 9 +++++---- apps/openmw/mwrender/objects.hpp | 4 ++-- apps/openmw/mwrender/renderinginterface.hpp | 12 ++++++++++++ apps/openmw/mwrender/renderingmanager.cpp | 1 - apps/openmw/mwrender/renderingmanager.hpp | 14 ++++---------- 6 files changed, 24 insertions(+), 18 deletions(-) create mode 100644 apps/openmw/mwrender/renderinginterface.hpp diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index 4d3dace03..c41c089c6 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -16,7 +16,7 @@ set(GAME_HEADER source_group(game FILES ${GAME} ${GAME_HEADER}) add_openmw_dir (mwrender - renderingmanager debugging cellimp interior exterior sky player npcs creatures objects + renderingmanager debugging cellimp interior exterior sky player npcs creatures objects renderinginterface ) add_openmw_dir (mwinput diff --git a/apps/openmw/mwrender/objects.cpp b/apps/openmw/mwrender/objects.cpp index 0632255be..b9147d75d 100644 --- a/apps/openmw/mwrender/objects.cpp +++ b/apps/openmw/mwrender/objects.cpp @@ -2,8 +2,9 @@ #include #include -using namespace MWRender; using namespace Ogre; +using namespace MWRender; + bool Objects::lightConst = false; float Objects::lightConstValue = 0.0f; @@ -159,10 +160,10 @@ void Objects::removeCell(const MWWorld::Ptr& ptr){ sg = 0; } } -void Objects::buildStaticGeometry(const MWWorld::Ptr& ptr){ - if(mSG.find(ptr.getCell()) != mSG.end()) +void Objects::buildStaticGeometry(ESMS::CellStore& cell){ + if(mSG.find(&cell) != mSG.end()) { - Ogre::StaticGeometry* sg = mSG[ptr.getCell()]; + Ogre::StaticGeometry* sg = mSG[&cell]; sg->build(); } } diff --git a/apps/openmw/mwrender/objects.hpp b/apps/openmw/mwrender/objects.hpp index ebb52906a..e830d0993 100644 --- a/apps/openmw/mwrender/objects.hpp +++ b/apps/openmw/mwrender/objects.hpp @@ -5,8 +5,8 @@ #include namespace MWRender{ + class Objects{ -private: OEngine::Render::OgreRenderer &mRend; std::map mCellSceneNodes; std::map mSG; @@ -34,7 +34,7 @@ public: void insertLight (const MWWorld::Ptr& ptr, float r, float g, float b, float radius); void deleteObject (const std::string& handle); void removeCell(const MWWorld::Ptr& ptr); - void buildStaticGeometry(const MWWorld::Ptr& ptr); + void buildStaticGeometry(ESMS::CellStore &cell); /// insert a light related to the most recent insertBegin call. diff --git a/apps/openmw/mwrender/renderinginterface.hpp b/apps/openmw/mwrender/renderinginterface.hpp new file mode 100644 index 000000000..28f3b61fc --- /dev/null +++ b/apps/openmw/mwrender/renderinginterface.hpp @@ -0,0 +1,12 @@ +#include "objects.hpp" +#include "npcs.hpp" +#include "creatures.hpp" +namespace MWRender{ +class RenderingInterface{ + public: + virtual MWRender::Npcs& getNPCs() = 0; + virtual MWRender::Creatures& getCreatures() = 0; + virtual MWRender::Objects& getObjects() = 0; + virtual MWRender::Player& getPlayer() = 0; + }; +} \ No newline at end of file diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index b07251f53..c21ce8a43 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -1,5 +1,4 @@ #include "renderingmanager.hpp" -#include "objects.hpp" #include diff --git a/apps/openmw/mwrender/renderingmanager.hpp b/apps/openmw/mwrender/renderingmanager.hpp index 0d2375feb..16e8e5af4 100644 --- a/apps/openmw/mwrender/renderingmanager.hpp +++ b/apps/openmw/mwrender/renderingmanager.hpp @@ -4,6 +4,7 @@ #include "sky.hpp" #include "debugging.hpp" +#include "renderinginterface.hpp" #include #include @@ -15,9 +16,8 @@ #include "../mwworld/ptr.hpp" #include -#include "objects.hpp" -#include "npcs.hpp" -#include "creatures.hpp" + + namespace Ogre { @@ -38,13 +38,7 @@ namespace MWWorld namespace MWRender { class Player; - class RenderingInterface{ - public: - virtual MWRender::Npcs& getNPCs(); - virtual MWRender::Creatures& getCreatures(); - virtual MWRender::Objects& getObjects(); - virtual MWRender::Player& getPlayer(); - }; + class RenderingManager: private RenderingInterface { From a7652bcb0c9fe7991282bf2824b1d8e9345220d7 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Wed, 9 Nov 2011 13:53:29 -0500 Subject: [PATCH 034/104] Yacoby's changes on Objects --- apps/openmw/mwrender/objects.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/openmw/mwrender/objects.cpp b/apps/openmw/mwrender/objects.cpp index b9147d75d..57e6c6501 100644 --- a/apps/openmw/mwrender/objects.cpp +++ b/apps/openmw/mwrender/objects.cpp @@ -40,7 +40,7 @@ void Objects::insertBegin (const MWWorld::Ptr& ptr, bool enabled, bool static_){ Ogre::SceneNode* insert = cellnode->createChildSceneNode(); - const float *f = ptr.getCellRef().pos.pos; + const float *f = ptr.getRefData().getPosition().pos; insert->setPosition(f[0], f[1], f[2]); insert->setScale(ptr.getCellRef().scale, ptr.getCellRef().scale, ptr.getCellRef().scale); From 1faa07b2794a076daacca441e0341c0c5a3a101f Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Wed, 9 Nov 2011 15:47:06 -0500 Subject: [PATCH 035/104] insertObjectRendering proposed --- apps/openmw/mwclass/lockpick.cpp | 11 ++++------- apps/openmw/mwclass/lockpick.hpp | 3 +-- apps/openmw/mwworld/class.cpp | 3 +-- apps/openmw/mwworld/class.hpp | 6 ++++-- apps/openmw/mwworld/world.cpp | 1 - 5 files changed, 10 insertions(+), 14 deletions(-) diff --git a/apps/openmw/mwclass/lockpick.cpp b/apps/openmw/mwclass/lockpick.cpp index 3a94fce26..1296a4144 100644 --- a/apps/openmw/mwclass/lockpick.cpp +++ b/apps/openmw/mwclass/lockpick.cpp @@ -9,25 +9,22 @@ #include "../mwworld/actiontake.hpp" #include "../mwrender/cellimp.hpp" - +#include "../mwrender/renderinginterface.hpp" #include "containerutil.hpp" namespace MWClass { - void Lockpick::insertObj (const MWWorld::Ptr& ptr, MWRender::CellRenderImp& cellRender, - MWWorld::Environment& environment) const + void Lockpick::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const { ESMS::LiveCellRef *ref = ptr.get(); assert (ref->base != NULL); const std::string &model = ref->base->model; + MWRender::Objects objects = renderingInterface.getObjects(); if (!model.empty()) { - MWRender::Rendering rendering (cellRender, ref->ref, ref->mData); - cellRender.insertMesh ("meshes\\" + model); - cellRender.insertObjectPhysics(); - ref->mData.setHandle (rendering.end (ref->mData.isEnabled())); + objects.insertMesh(ptr, "meshes\\" + model); } } diff --git a/apps/openmw/mwclass/lockpick.hpp b/apps/openmw/mwclass/lockpick.hpp index bb9866b8c..9b02dce7f 100644 --- a/apps/openmw/mwclass/lockpick.hpp +++ b/apps/openmw/mwclass/lockpick.hpp @@ -9,8 +9,7 @@ namespace MWClass { public: - virtual void insertObj (const MWWorld::Ptr& ptr, MWRender::CellRenderImp& cellRender, - MWWorld::Environment& environment) const; + virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const; ///< Add reference into a cell for rendering virtual std::string getName (const MWWorld::Ptr& ptr) const; diff --git a/apps/openmw/mwworld/class.cpp b/apps/openmw/mwworld/class.cpp index 670cf90b2..396d92cac 100644 --- a/apps/openmw/mwworld/class.cpp +++ b/apps/openmw/mwworld/class.cpp @@ -21,8 +21,7 @@ namespace MWWorld throw std::runtime_error ("class does not support ID retrieval"); } - void Class::insertObj (const Ptr& ptr, MWRender::CellRenderImp& cellRender, - MWWorld::Environment& environment) const + void Class::insertObjectRendering (const Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const { } diff --git a/apps/openmw/mwworld/class.hpp b/apps/openmw/mwworld/class.hpp index 8ad9ba58f..470235bb0 100644 --- a/apps/openmw/mwworld/class.hpp +++ b/apps/openmw/mwworld/class.hpp @@ -9,6 +9,7 @@ #include "action.hpp" #include "containerstore.hpp" #include "refdata.hpp" +#include "../mwrender/renderinginterface.hpp" namespace Ogre { @@ -59,8 +60,9 @@ namespace MWWorld ///< Return ID of \a ptr or throw an exception, if class does not support ID retrieval /// (default implementation: throw an exception) - virtual void insertObj (const Ptr& ptr, MWRender::CellRenderImp& cellRender, - MWWorld::Environment& environment) const; + + + virtual void insertObjectRendering (const Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const; ///< Add reference into a cell for rendering (default implementation: don't render anything). virtual void enable (const Ptr& ptr, MWWorld::Environment& environment) const; diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index fbe388427..a4e909ffc 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -180,7 +180,6 @@ namespace MWWorld : mRendering (renderer,resDir, physEng),mPlayer (0), mLocalScripts (mStore), mGlobalVariables (0), mSky (false), mEnvironment (environment), mNextDynamicRecord (0), mCells (mStore, mEsm, *this) { - std::cout << "Creating myworld\n"; mPhysEngine = physEng; mPhysics = new PhysicsSystem(renderer, physEng); From 042bceb54771260e81c532fa6ca90869b08d9cdc Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Wed, 9 Nov 2011 18:06:55 -0500 Subject: [PATCH 036/104] Changes to insertObjectRendering; Proposed insertObject --- apps/openmw/mwclass/lockpick.cpp | 18 +++++++++++++++++- apps/openmw/mwclass/lockpick.hpp | 2 ++ apps/openmw/mwworld/class.cpp | 3 +++ apps/openmw/mwworld/class.hpp | 2 ++ apps/openmw/mwworld/physicssystem.cpp | 11 +++++++++++ apps/openmw/mwworld/physicssystem.hpp | 4 ++++ 6 files changed, 39 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwclass/lockpick.cpp b/apps/openmw/mwclass/lockpick.cpp index 1296a4144..e8e9799a2 100644 --- a/apps/openmw/mwclass/lockpick.cpp +++ b/apps/openmw/mwclass/lockpick.cpp @@ -21,13 +21,29 @@ namespace MWClass assert (ref->base != NULL); const std::string &model = ref->base->model; - MWRender::Objects objects = renderingInterface.getObjects(); + if (!model.empty()) { + MWRender::Objects objects = renderingInterface.getObjects(); + objects.insertBegin(ptr, true, false); objects.insertMesh(ptr, "meshes\\" + model); } } + void Lockpick::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + assert (ref->base != NULL); + std::string handle = ptr.getRefData().getHandle(); + if(!handle.empty()){ + physics.insertObjectPhysics(handle); + } + + } + + std::string Lockpick::getName (const MWWorld::Ptr& ptr) const { ESMS::LiveCellRef *ref = diff --git a/apps/openmw/mwclass/lockpick.hpp b/apps/openmw/mwclass/lockpick.hpp index 9b02dce7f..979a3b5ac 100644 --- a/apps/openmw/mwclass/lockpick.hpp +++ b/apps/openmw/mwclass/lockpick.hpp @@ -12,6 +12,8 @@ namespace MWClass virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const; ///< Add reference into a cell for rendering + virtual void insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics) const; + virtual std::string getName (const MWWorld::Ptr& ptr) const; ///< \return name (the one that is to be presented to the user; not the internal one); /// can return an empty string. diff --git a/apps/openmw/mwworld/class.cpp b/apps/openmw/mwworld/class.cpp index 396d92cac..a80405e13 100644 --- a/apps/openmw/mwworld/class.cpp +++ b/apps/openmw/mwworld/class.cpp @@ -24,6 +24,9 @@ namespace MWWorld void Class::insertObjectRendering (const Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const { + } + void Class::insertObject(const Ptr& ptr, MWWorld::PhysicsSystem& physics) const{ + } void Class::enable (const Ptr& ptr, MWWorld::Environment& environment) const diff --git a/apps/openmw/mwworld/class.hpp b/apps/openmw/mwworld/class.hpp index 470235bb0..1a2a4f776 100644 --- a/apps/openmw/mwworld/class.hpp +++ b/apps/openmw/mwworld/class.hpp @@ -10,6 +10,7 @@ #include "containerstore.hpp" #include "refdata.hpp" #include "../mwrender/renderinginterface.hpp" +#include "physicssystem.hpp" namespace Ogre { @@ -63,6 +64,7 @@ namespace MWWorld virtual void insertObjectRendering (const Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const; + virtual void insertObject(const Ptr& ptr, MWWorld::PhysicsSystem& physics) const; ///< Add reference into a cell for rendering (default implementation: don't render anything). virtual void enable (const Ptr& ptr, MWWorld::Environment& environment) const; diff --git a/apps/openmw/mwworld/physicssystem.cpp b/apps/openmw/mwworld/physicssystem.cpp index 067c42151..8ef0ca968 100644 --- a/apps/openmw/mwworld/physicssystem.cpp +++ b/apps/openmw/mwworld/physicssystem.cpp @@ -183,4 +183,15 @@ namespace MWWorld throw std::logic_error ("can't find player"); } + void PhysicsSystem::insertObjectPhysics(const std::string& handle){ + Ogre::SceneNode* node = mRender.getScene()->getSceneNode(handle); + addObject (handle, handle, node->getOrientation(), + node->getScale().x, node->getPosition()); + } + + void PhysicsSystem::insertActorPhysics(const std::string& handle){ + Ogre::SceneNode* node = mRender.getScene()->getSceneNode(handle); + addActor (handle, handle, node->getPosition()); + } + } diff --git a/apps/openmw/mwworld/physicssystem.hpp b/apps/openmw/mwworld/physicssystem.hpp index 17640c074..72f834f6e 100644 --- a/apps/openmw/mwworld/physicssystem.hpp +++ b/apps/openmw/mwworld/physicssystem.hpp @@ -34,6 +34,10 @@ namespace MWWorld bool toggleCollisionMode(); std::pair getFacedHandle (MWWorld::World& world); + void insertObjectPhysics(const std::string& handle); + + void insertActorPhysics(const std::string& handle); + private: OEngine::Render::OgreRenderer &mRender; OEngine::Physic::PhysicEngine* mEngine; From f4e7bd6dfdb5a0280359310b3bc5979ba7433cd8 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Fri, 11 Nov 2011 00:20:53 -0500 Subject: [PATCH 037/104] Made some recommended changes --- apps/openmw/mwclass/creature.cpp | 2 +- apps/openmw/mwclass/lockpick.cpp | 7 +++---- apps/openmw/mwclass/lockpick.hpp | 2 +- apps/openmw/mwrender/renderingmanager.cpp | 4 ++-- apps/openmw/mwrender/renderingmanager.hpp | 6 ++++-- apps/openmw/mwworld/class.cpp | 2 +- apps/openmw/mwworld/class.hpp | 2 +- apps/openmw/mwworld/physicssystem.cpp | 12 ++++++------ apps/openmw/mwworld/physicssystem.hpp | 4 ++-- apps/openmw/mwworld/refdata.hpp | 3 +++ 10 files changed, 24 insertions(+), 20 deletions(-) diff --git a/apps/openmw/mwclass/creature.cpp b/apps/openmw/mwclass/creature.cpp index 2e223c918..f78e400d2 100644 --- a/apps/openmw/mwclass/creature.cpp +++ b/apps/openmw/mwclass/creature.cpp @@ -36,7 +36,7 @@ namespace MWClass MWRender::Rendering rendering (cellRender, ref->ref, ref->mData); cellRender.insertMesh("meshes\\" + model); cellRender.insertActorPhysics(); - ref->mData.setHandle (rendering.end (ref->mData.isEnabled())); + } } diff --git a/apps/openmw/mwclass/lockpick.cpp b/apps/openmw/mwclass/lockpick.cpp index e8e9799a2..32f2311b3 100644 --- a/apps/openmw/mwclass/lockpick.cpp +++ b/apps/openmw/mwclass/lockpick.cpp @@ -30,15 +30,14 @@ namespace MWClass } } - void Lockpick::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics) const + void Lockpick::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const { ESMS::LiveCellRef *ref = ptr.get(); assert (ref->base != NULL); - std::string handle = ptr.getRefData().getHandle(); - if(!handle.empty()){ - physics.insertObjectPhysics(handle); + if(ptr.getRefData().getBaseNode()){ + physics.insertObjectPhysics(ptr); } } diff --git a/apps/openmw/mwclass/lockpick.hpp b/apps/openmw/mwclass/lockpick.hpp index 979a3b5ac..074a07c93 100644 --- a/apps/openmw/mwclass/lockpick.hpp +++ b/apps/openmw/mwclass/lockpick.hpp @@ -12,7 +12,7 @@ namespace MWClass virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const; ///< Add reference into a cell for rendering - virtual void insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics) const; + virtual void insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const; virtual std::string getName (const MWWorld::Ptr& ptr) const; ///< \return name (the one that is to be presented to the user; not the internal one); diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index c21ce8a43..39c1bca7a 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -85,10 +85,10 @@ MWRender::Player& RenderingManager::getPlayer(){ void RenderingManager::removeCell (MWWorld::Ptr::CellStore *store){ } -void RenderingManager::addObject (const MWWorld::Ptr& ptr, MWWorld::Ptr::CellStore *store){ +void RenderingManager::addObject (const MWWorld::Ptr& ptr){ } -void RenderingManager::removeObject (const MWWorld::Ptr& ptr, MWWorld::Ptr::CellStore *store){ +void RenderingManager::removeObject (const MWWorld::Ptr& ptr){ } void RenderingManager::moveObject (const MWWorld::Ptr& ptr, const Ogre::Vector3& position){ diff --git a/apps/openmw/mwrender/renderingmanager.hpp b/apps/openmw/mwrender/renderingmanager.hpp index 16e8e5af4..0508fa54d 100644 --- a/apps/openmw/mwrender/renderingmanager.hpp +++ b/apps/openmw/mwrender/renderingmanager.hpp @@ -57,12 +57,14 @@ class RenderingManager: private RenderingInterface { void removeCell (MWWorld::Ptr::CellStore *store); // TODO do we want this? - void addObject (const MWWorld::Ptr& ptr, MWWorld::Ptr::CellStore *store); - void removeObject (const MWWorld::Ptr& ptr, MWWorld::Ptr::CellStore *store); + void addObject (const MWWorld::Ptr& ptr); + void removeObject (const MWWorld::Ptr& ptr); void moveObject (const MWWorld::Ptr& ptr, const Ogre::Vector3& position); void scaleObject (const MWWorld::Ptr& ptr, const Ogre::Vector3& scale); void rotateObject (const MWWorld::Ptr& ptr, const::Ogre::Quaternion& orientation); + + /// \param store Cell the object was in previously (\a ptr has already been updated to the new cell). void moveObjectToCell (const MWWorld::Ptr& ptr, const Ogre::Vector3& position, MWWorld::Ptr::CellStore *store); void setPhysicsDebugRendering (bool); diff --git a/apps/openmw/mwworld/class.cpp b/apps/openmw/mwworld/class.cpp index a80405e13..b4f93576a 100644 --- a/apps/openmw/mwworld/class.cpp +++ b/apps/openmw/mwworld/class.cpp @@ -25,7 +25,7 @@ namespace MWWorld { } - void Class::insertObject(const Ptr& ptr, MWWorld::PhysicsSystem& physics) const{ + void Class::insertObject(const Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const{ } diff --git a/apps/openmw/mwworld/class.hpp b/apps/openmw/mwworld/class.hpp index 1a2a4f776..706b11aaa 100644 --- a/apps/openmw/mwworld/class.hpp +++ b/apps/openmw/mwworld/class.hpp @@ -64,7 +64,7 @@ namespace MWWorld virtual void insertObjectRendering (const Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const; - virtual void insertObject(const Ptr& ptr, MWWorld::PhysicsSystem& physics) const; + virtual void insertObject(const Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const; ///< Add reference into a cell for rendering (default implementation: don't render anything). virtual void enable (const Ptr& ptr, MWWorld::Environment& environment) const; diff --git a/apps/openmw/mwworld/physicssystem.cpp b/apps/openmw/mwworld/physicssystem.cpp index 8ef0ca968..6ba4805aa 100644 --- a/apps/openmw/mwworld/physicssystem.cpp +++ b/apps/openmw/mwworld/physicssystem.cpp @@ -183,15 +183,15 @@ namespace MWWorld throw std::logic_error ("can't find player"); } - void PhysicsSystem::insertObjectPhysics(const std::string& handle){ - Ogre::SceneNode* node = mRender.getScene()->getSceneNode(handle); - addObject (handle, handle, node->getOrientation(), + void PhysicsSystem::insertObjectPhysics(const MWWorld::Ptr& ptr){ + Ogre::SceneNode* node = ptr.getRefData().getBaseNode(); + addObject (node->getName(), node->getName(), node->getOrientation(), node->getScale().x, node->getPosition()); } - void PhysicsSystem::insertActorPhysics(const std::string& handle){ - Ogre::SceneNode* node = mRender.getScene()->getSceneNode(handle); - addActor (handle, handle, node->getPosition()); + void PhysicsSystem::insertActorPhysics(const MWWorld::Ptr& ptr){ + Ogre::SceneNode* node = ptr.getRefData().getBaseNode(); + addActor (node->getName(), node->getName(), node->getPosition()); } } diff --git a/apps/openmw/mwworld/physicssystem.hpp b/apps/openmw/mwworld/physicssystem.hpp index 72f834f6e..8fbcd0521 100644 --- a/apps/openmw/mwworld/physicssystem.hpp +++ b/apps/openmw/mwworld/physicssystem.hpp @@ -34,9 +34,9 @@ namespace MWWorld bool toggleCollisionMode(); std::pair getFacedHandle (MWWorld::World& world); - void insertObjectPhysics(const std::string& handle); + void insertObjectPhysics(const MWWorld::Ptr& ptr); - void insertActorPhysics(const std::string& handle); + void insertActorPhysics(const MWWorld::Ptr& ptr); private: OEngine::Render::OgreRenderer &mRender; diff --git a/apps/openmw/mwworld/refdata.hpp b/apps/openmw/mwworld/refdata.hpp index 062c5942e..6cef9da19 100644 --- a/apps/openmw/mwworld/refdata.hpp +++ b/apps/openmw/mwworld/refdata.hpp @@ -55,6 +55,9 @@ namespace MWWorld { return mBaseNode->getName(); } + Ogre::SceneNode* getBaseNode(){ + return mBaseNode; + } void setBaseNode(Ogre::SceneNode* base){ mBaseNode = base; } From 62d8d1add22a70b2e8e8adb69e63e98b66a1dd89 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Fri, 11 Nov 2011 14:37:42 -0500 Subject: [PATCH 038/104] more recommended changes --- apps/openmw/mwclass/lockpick.cpp | 6 ++++-- apps/openmw/mwrender/objects.cpp | 2 +- apps/openmw/mwworld/physicssystem.hpp | 1 + 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/apps/openmw/mwclass/lockpick.cpp b/apps/openmw/mwclass/lockpick.cpp index 32f2311b3..c80e5ab7c 100644 --- a/apps/openmw/mwclass/lockpick.cpp +++ b/apps/openmw/mwclass/lockpick.cpp @@ -25,7 +25,7 @@ namespace MWClass if (!model.empty()) { MWRender::Objects objects = renderingInterface.getObjects(); - objects.insertBegin(ptr, true, false); + objects.insertBegin(ptr, ptr.getRefData().isEnabled(), false); objects.insertMesh(ptr, "meshes\\" + model); } } @@ -35,8 +35,10 @@ namespace MWClass ESMS::LiveCellRef *ref = ptr.get(); + + const std::string &model = ref->base->model; assert (ref->base != NULL); - if(ptr.getRefData().getBaseNode()){ + if(!model.empty()){ physics.insertObjectPhysics(ptr); } diff --git a/apps/openmw/mwrender/objects.cpp b/apps/openmw/mwrender/objects.cpp index 57e6c6501..8a4216799 100644 --- a/apps/openmw/mwrender/objects.cpp +++ b/apps/openmw/mwrender/objects.cpp @@ -66,7 +66,7 @@ void Objects::insertBegin (const MWWorld::Ptr& ptr, bool enabled, bool static_){ } void Objects::insertMesh (const MWWorld::Ptr& ptr, const std::string& mesh){ - Ogre::SceneNode* insert = mRend.getScene()->getSceneNode(ptr.getRefData().getHandle()); + Ogre::SceneNode* insert = ptr.getRefData().getBaseNode(); assert(insert); NifOgre::NIFLoader::load(mesh); diff --git a/apps/openmw/mwworld/physicssystem.hpp b/apps/openmw/mwworld/physicssystem.hpp index 8fbcd0521..789c81c45 100644 --- a/apps/openmw/mwworld/physicssystem.hpp +++ b/apps/openmw/mwworld/physicssystem.hpp @@ -4,6 +4,7 @@ #include #include #include +#include "ptr.hpp" namespace MWWorld { From c7dadec8401a54d22580acaebfe60b2944c9cd6c Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Fri, 11 Nov 2011 23:01:12 -0500 Subject: [PATCH 039/104] Updating the rest of mwclass --- apps/openmw/mwclass/activator.cpp | 25 +++- apps/openmw/mwclass/activator.hpp | 5 +- apps/openmw/mwclass/apparatus.cpp | 25 +++- apps/openmw/mwclass/apparatus.hpp | 5 +- apps/openmw/mwclass/armor.cpp | 24 ++- apps/openmw/mwclass/armor.hpp | 5 +- apps/openmw/mwclass/book.cpp | 25 +++- apps/openmw/mwclass/book.hpp | 5 +- apps/openmw/mwclass/clothing.cpp | 25 +++- apps/openmw/mwclass/clothing.hpp | 5 +- apps/openmw/mwclass/container.cpp | 25 +++- apps/openmw/mwclass/container.hpp | 5 +- apps/openmw/mwclass/creature.cpp | 25 +++- apps/openmw/mwclass/creature.hpp | 5 +- apps/openmw/mwclass/door.cpp | 27 +++- apps/openmw/mwclass/door.hpp | 5 +- apps/openmw/mwclass/ingredient.cpp | 26 +++- apps/openmw/mwclass/ingredient.hpp | 5 +- apps/openmw/mwclass/light.cpp | 33 +++-- apps/openmw/mwclass/light.hpp | 5 +- apps/openmw/mwclass/misc.cpp | 25 +++- apps/openmw/mwclass/misc.hpp | 5 +- apps/openmw/mwclass/npc.cpp | 227 ++--------------------------- apps/openmw/mwclass/npc.hpp | 5 +- apps/openmw/mwclass/potion.cpp | 25 +++- apps/openmw/mwclass/potion.hpp | 5 +- apps/openmw/mwclass/probe.cpp | 21 ++- apps/openmw/mwclass/probe.hpp | 5 +- apps/openmw/mwclass/repair.cpp | 25 +++- apps/openmw/mwclass/repair.hpp | 5 +- apps/openmw/mwclass/static.cpp | 25 +++- apps/openmw/mwclass/static.hpp | 5 +- apps/openmw/mwclass/weapon.cpp | 25 +++- apps/openmw/mwclass/weapon.hpp | 5 +- 34 files changed, 368 insertions(+), 350 deletions(-) diff --git a/apps/openmw/mwclass/activator.cpp b/apps/openmw/mwclass/activator.cpp index 4d4b7aeaa..cd34997d2 100644 --- a/apps/openmw/mwclass/activator.cpp +++ b/apps/openmw/mwclass/activator.cpp @@ -11,23 +11,36 @@ namespace MWClass { - void Activator::insertObj (const MWWorld::Ptr& ptr, MWRender::CellRenderImp& cellRender, - MWWorld::Environment& environment) const + void Activator::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const { ESMS::LiveCellRef *ref = ptr.get(); assert (ref->base != NULL); const std::string &model = ref->base->model; + if (!model.empty()) { - MWRender::Rendering rendering (cellRender, ref->ref, ref->mData); - cellRender.insertMesh ("meshes\\" + model); - cellRender.insertObjectPhysics(); - ref->mData.setHandle (rendering.end (ref->mData.isEnabled())); + MWRender::Objects objects = renderingInterface.getObjects(); + objects.insertBegin(ptr, ptr.getRefData().isEnabled(), false); + objects.insertMesh(ptr, "meshes\\" + model); } } + void Activator::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + + const std::string &model = ref->base->model; + assert (ref->base != NULL); + if(!model.empty()){ + physics.insertObjectPhysics(ptr); + } + + } + std::string Activator::getName (const MWWorld::Ptr& ptr) const { ESMS::LiveCellRef *ref = diff --git a/apps/openmw/mwclass/activator.hpp b/apps/openmw/mwclass/activator.hpp index 3b48796ac..08be8a5ff 100644 --- a/apps/openmw/mwclass/activator.hpp +++ b/apps/openmw/mwclass/activator.hpp @@ -9,10 +9,11 @@ namespace MWClass { public: - virtual void insertObj (const MWWorld::Ptr& ptr, MWRender::CellRenderImp& cellRender, - MWWorld::Environment& environment) const; + virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const; ///< Add reference into a cell for rendering + virtual void insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const; + virtual std::string getName (const MWWorld::Ptr& ptr) const; ///< \return name (the one that is to be presented to the user; not the internal one); /// can return an empty string. diff --git a/apps/openmw/mwclass/apparatus.cpp b/apps/openmw/mwclass/apparatus.cpp index ddf96d1be..6f23614e2 100644 --- a/apps/openmw/mwclass/apparatus.cpp +++ b/apps/openmw/mwclass/apparatus.cpp @@ -14,23 +14,36 @@ namespace MWClass { - void Apparatus::insertObj (const MWWorld::Ptr& ptr, MWRender::CellRenderImp& cellRender, - MWWorld::Environment& environment) const + void Apparatus::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const { ESMS::LiveCellRef *ref = ptr.get(); assert (ref->base != NULL); const std::string &model = ref->base->model; + if (!model.empty()) { - MWRender::Rendering rendering (cellRender, ref->ref, ref->mData); - cellRender.insertMesh ("meshes\\" + model); - cellRender.insertObjectPhysics(); - ref->mData.setHandle (rendering.end (ref->mData.isEnabled())); + MWRender::Objects objects = renderingInterface.getObjects(); + objects.insertBegin(ptr, ptr.getRefData().isEnabled(), false); + objects.insertMesh(ptr, "meshes\\" + model); } } + void Apparatus::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + + const std::string &model = ref->base->model; + assert (ref->base != NULL); + if(!model.empty()){ + physics.insertObjectPhysics(ptr); + } + + } + std::string Apparatus::getName (const MWWorld::Ptr& ptr) const { ESMS::LiveCellRef *ref = diff --git a/apps/openmw/mwclass/apparatus.hpp b/apps/openmw/mwclass/apparatus.hpp index c2e6e25e1..9a5a9b955 100644 --- a/apps/openmw/mwclass/apparatus.hpp +++ b/apps/openmw/mwclass/apparatus.hpp @@ -9,10 +9,11 @@ namespace MWClass { public: - virtual void insertObj (const MWWorld::Ptr& ptr, MWRender::CellRenderImp& cellRender, - MWWorld::Environment& environment) const; + virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const; ///< Add reference into a cell for rendering + virtual void insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const; + virtual std::string getName (const MWWorld::Ptr& ptr) const; ///< \return name (the one that is to be presented to the user; not the internal one); /// can return an empty string. diff --git a/apps/openmw/mwclass/armor.cpp b/apps/openmw/mwclass/armor.cpp index 9452fea16..f409bb9b0 100644 --- a/apps/openmw/mwclass/armor.cpp +++ b/apps/openmw/mwclass/armor.cpp @@ -14,23 +14,35 @@ namespace MWClass { - void Armor::insertObj (const MWWorld::Ptr& ptr, MWRender::CellRenderImp& cellRender, - MWWorld::Environment& environment) const + void Armor::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const { ESMS::LiveCellRef *ref = ptr.get(); assert (ref->base != NULL); const std::string &model = ref->base->model; + if (!model.empty()) { - MWRender::Rendering rendering (cellRender, ref->ref, ref->mData); - cellRender.insertMesh ("meshes\\" + model); - cellRender.insertObjectPhysics(); - ref->mData.setHandle (rendering.end (ref->mData.isEnabled())); + MWRender::Objects objects = renderingInterface.getObjects(); + objects.insertBegin(ptr, ptr.getRefData().isEnabled(), false); + objects.insertMesh(ptr, "meshes\\" + model); } } + void Armor::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + const std::string &model = ref->base->model; + assert (ref->base != NULL); + if(!model.empty()){ + physics.insertObjectPhysics(ptr); + } + + } + std::string Armor::getName (const MWWorld::Ptr& ptr) const { ESMS::LiveCellRef *ref = diff --git a/apps/openmw/mwclass/armor.hpp b/apps/openmw/mwclass/armor.hpp index 040342a69..123713a38 100644 --- a/apps/openmw/mwclass/armor.hpp +++ b/apps/openmw/mwclass/armor.hpp @@ -9,10 +9,11 @@ namespace MWClass { public: - virtual void insertObj (const MWWorld::Ptr& ptr, MWRender::CellRenderImp& cellRender, - MWWorld::Environment& environment) const; + virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const; ///< Add reference into a cell for rendering + virtual void insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const; + virtual std::string getName (const MWWorld::Ptr& ptr) const; ///< \return name (the one that is to be presented to the user; not the internal one); /// can return an empty string. diff --git a/apps/openmw/mwclass/book.cpp b/apps/openmw/mwclass/book.cpp index c2d3c4aa8..f9c20b8e8 100644 --- a/apps/openmw/mwclass/book.cpp +++ b/apps/openmw/mwclass/book.cpp @@ -14,23 +14,36 @@ namespace MWClass { - void Book::insertObj (const MWWorld::Ptr& ptr, MWRender::CellRenderImp& cellRender, - MWWorld::Environment& environment) const + void Book::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const { ESMS::LiveCellRef *ref = ptr.get(); assert (ref->base != NULL); const std::string &model = ref->base->model; + if (!model.empty()) { - MWRender::Rendering rendering (cellRender, ref->ref, ref->mData); - cellRender.insertMesh ("meshes\\" + model); - cellRender.insertObjectPhysics(); - ref->mData.setHandle (rendering.end (ref->mData.isEnabled())); + MWRender::Objects objects = renderingInterface.getObjects(); + objects.insertBegin(ptr, ptr.getRefData().isEnabled(), false); + objects.insertMesh(ptr, "meshes\\" + model); } } + void Book::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + + const std::string &model = ref->base->model; + assert (ref->base != NULL); + if(!model.empty()){ + physics.insertObjectPhysics(ptr); + } + + } + std::string Book::getName (const MWWorld::Ptr& ptr) const { ESMS::LiveCellRef *ref = diff --git a/apps/openmw/mwclass/book.hpp b/apps/openmw/mwclass/book.hpp index 70d1bca3b..6e38ea0d3 100644 --- a/apps/openmw/mwclass/book.hpp +++ b/apps/openmw/mwclass/book.hpp @@ -9,10 +9,11 @@ namespace MWClass { public: - virtual void insertObj (const MWWorld::Ptr& ptr, MWRender::CellRenderImp& cellRender, - MWWorld::Environment& environment) const; + virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const; ///< Add reference into a cell for rendering + virtual void insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const; + virtual std::string getName (const MWWorld::Ptr& ptr) const; ///< \return name (the one that is to be presented to the user; not the internal one); /// can return an empty string. diff --git a/apps/openmw/mwclass/clothing.cpp b/apps/openmw/mwclass/clothing.cpp index 7c69573ed..0dc2b4615 100644 --- a/apps/openmw/mwclass/clothing.cpp +++ b/apps/openmw/mwclass/clothing.cpp @@ -14,23 +14,36 @@ namespace MWClass { - void Clothing::insertObj (const MWWorld::Ptr& ptr, MWRender::CellRenderImp& cellRender, - MWWorld::Environment& environment) const + void Clothing::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const { ESMS::LiveCellRef *ref = ptr.get(); assert (ref->base != NULL); const std::string &model = ref->base->model; + if (!model.empty()) { - MWRender::Rendering rendering (cellRender, ref->ref, ref->mData); - cellRender.insertMesh ("meshes\\" + model); - cellRender.insertObjectPhysics(); - ref->mData.setHandle (rendering.end (ref->mData.isEnabled())); + MWRender::Objects objects = renderingInterface.getObjects(); + objects.insertBegin(ptr, ptr.getRefData().isEnabled(), false); + objects.insertMesh(ptr, "meshes\\" + model); } } + void Clothing::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + + const std::string &model = ref->base->model; + assert (ref->base != NULL); + if(!model.empty()){ + physics.insertObjectPhysics(ptr); + } + + } + std::string Clothing::getName (const MWWorld::Ptr& ptr) const { ESMS::LiveCellRef *ref = diff --git a/apps/openmw/mwclass/clothing.hpp b/apps/openmw/mwclass/clothing.hpp index fb88e25df..353f7f606 100644 --- a/apps/openmw/mwclass/clothing.hpp +++ b/apps/openmw/mwclass/clothing.hpp @@ -9,10 +9,11 @@ namespace MWClass { public: - virtual void insertObj (const MWWorld::Ptr& ptr, MWRender::CellRenderImp& cellRender, - MWWorld::Environment& environment) const; + virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const; ///< Add reference into a cell for rendering + virtual void insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const; + virtual std::string getName (const MWWorld::Ptr& ptr) const; ///< \return name (the one that is to be presented to the user; not the internal one); /// can return an empty string. diff --git a/apps/openmw/mwclass/container.cpp b/apps/openmw/mwclass/container.cpp index ad2ab8d65..e24177d6c 100644 --- a/apps/openmw/mwclass/container.cpp +++ b/apps/openmw/mwclass/container.cpp @@ -11,23 +11,36 @@ namespace MWClass { - void Container::insertObj (const MWWorld::Ptr& ptr, MWRender::CellRenderImp& cellRender, - MWWorld::Environment& environment) const + void Container::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const { ESMS::LiveCellRef *ref = ptr.get(); assert (ref->base != NULL); const std::string &model = ref->base->model; + if (!model.empty()) { - MWRender::Rendering rendering (cellRender, ref->ref, ref->mData); - cellRender.insertMesh ("meshes\\" + model); - cellRender.insertObjectPhysics(); - ref->mData.setHandle (rendering.end (ref->mData.isEnabled())); + MWRender::Objects objects = renderingInterface.getObjects(); + objects.insertBegin(ptr, ptr.getRefData().isEnabled(), false); + objects.insertMesh(ptr, "meshes\\" + model); } } + void Container::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + + const std::string &model = ref->base->model; + assert (ref->base != NULL); + if(!model.empty()){ + physics.insertObjectPhysics(ptr); + } + + } + std::string Container::getName (const MWWorld::Ptr& ptr) const { ESMS::LiveCellRef *ref = diff --git a/apps/openmw/mwclass/container.hpp b/apps/openmw/mwclass/container.hpp index de54a9e68..9d65927f8 100644 --- a/apps/openmw/mwclass/container.hpp +++ b/apps/openmw/mwclass/container.hpp @@ -9,10 +9,11 @@ namespace MWClass { public: - virtual void insertObj (const MWWorld::Ptr& ptr, MWRender::CellRenderImp& cellRender, - MWWorld::Environment& environment) const; + virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const; ///< Add reference into a cell for rendering + virtual void insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const; + virtual std::string getName (const MWWorld::Ptr& ptr) const; ///< \return name (the one that is to be presented to the user; not the internal one); /// can return an empty string. diff --git a/apps/openmw/mwclass/creature.cpp b/apps/openmw/mwclass/creature.cpp index f78e400d2..2eca30539 100644 --- a/apps/openmw/mwclass/creature.cpp +++ b/apps/openmw/mwclass/creature.cpp @@ -23,23 +23,36 @@ namespace MWClass return ref->base->mId; } - void Creature::insertObj (const MWWorld::Ptr& ptr, MWRender::CellRenderImp& cellRender, - MWWorld::Environment& environment) const + void Creature::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const { ESMS::LiveCellRef *ref = ptr.get(); assert (ref->base != NULL); const std::string &model = ref->base->model; + if (!model.empty()) { - MWRender::Rendering rendering (cellRender, ref->ref, ref->mData); - cellRender.insertMesh("meshes\\" + model); - cellRender.insertActorPhysics(); - + MWRender::Objects objects = renderingInterface.getObjects(); + objects.insertBegin(ptr, ptr.getRefData().isEnabled(), false); + objects.insertMesh(ptr, "meshes\\" + model); } } + void Creature::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + + const std::string &model = ref->base->model; + assert (ref->base != NULL); + if(!model.empty()){ + physics.insertActorPhysics(ptr); + } + + } + void Creature::enable (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const { environment.mMechanicsManager->addActor (ptr); diff --git a/apps/openmw/mwclass/creature.hpp b/apps/openmw/mwclass/creature.hpp index 9f6708f40..e1657b2c7 100644 --- a/apps/openmw/mwclass/creature.hpp +++ b/apps/openmw/mwclass/creature.hpp @@ -12,10 +12,11 @@ namespace MWClass virtual std::string getId (const MWWorld::Ptr& ptr) const; ///< Return ID of \a ptr - virtual void insertObj (const MWWorld::Ptr& ptr, MWRender::CellRenderImp& cellRender, - MWWorld::Environment& environment) const; + virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const; ///< Add reference into a cell for rendering + virtual void insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const; + virtual void enable (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const; ///< Enable reference; only does the non-rendering part diff --git a/apps/openmw/mwclass/door.cpp b/apps/openmw/mwclass/door.cpp index e32e3ef4e..9e2b17b2e 100644 --- a/apps/openmw/mwclass/door.cpp +++ b/apps/openmw/mwclass/door.cpp @@ -18,23 +18,36 @@ namespace MWClass { - void Door::insertObj (const MWWorld::Ptr& ptr, MWRender::CellRenderImp& cellRender, - MWWorld::Environment& environment) const + void Door::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const { - ESMS::LiveCellRef *ref = + ESMS::LiveCellRef *ref = ptr.get(); assert (ref->base != NULL); const std::string &model = ref->base->model; + if (!model.empty()) { - MWRender::Rendering rendering (cellRender, ref->ref, ref->mData); - cellRender.insertMesh ("meshes\\" + model); - cellRender.insertObjectPhysics(); - ref->mData.setHandle (rendering.end (ref->mData.isEnabled())); + MWRender::Objects objects = renderingInterface.getObjects(); + objects.insertBegin(ptr, ptr.getRefData().isEnabled(), false); + objects.insertMesh(ptr, "meshes\\" + model); } } + void Door::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + + const std::string &model = ref->base->model; + assert (ref->base != NULL); + if(!model.empty()){ + physics.insertObjectPhysics(ptr); + } + + } + std::string Door::getName (const MWWorld::Ptr& ptr) const { ESMS::LiveCellRef *ref = diff --git a/apps/openmw/mwclass/door.hpp b/apps/openmw/mwclass/door.hpp index aecb117d3..aecb4224c 100644 --- a/apps/openmw/mwclass/door.hpp +++ b/apps/openmw/mwclass/door.hpp @@ -9,10 +9,11 @@ namespace MWClass { public: - virtual void insertObj (const MWWorld::Ptr& ptr, MWRender::CellRenderImp& cellRender, - MWWorld::Environment& environment) const; + virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const; ///< Add reference into a cell for rendering + virtual void insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const; + virtual std::string getName (const MWWorld::Ptr& ptr) const; ///< \return name (the one that is to be presented to the user; not the internal one); /// can return an empty string. diff --git a/apps/openmw/mwclass/ingredient.cpp b/apps/openmw/mwclass/ingredient.cpp index e2c9b072f..1ef695b44 100644 --- a/apps/openmw/mwclass/ingredient.cpp +++ b/apps/openmw/mwclass/ingredient.cpp @@ -14,23 +14,37 @@ namespace MWClass { - void Ingredient::insertObj (const MWWorld::Ptr& ptr, MWRender::CellRenderImp& cellRender, - MWWorld::Environment& environment) const + void Ingredient::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const { ESMS::LiveCellRef *ref = ptr.get(); assert (ref->base != NULL); const std::string &model = ref->base->model; + if (!model.empty()) { - MWRender::Rendering rendering (cellRender, ref->ref, ref->mData); - cellRender.insertMesh ("meshes\\" + model); - cellRender.insertObjectPhysics(); - ref->mData.setHandle (rendering.end (ref->mData.isEnabled())); + MWRender::Objects objects = renderingInterface.getObjects(); + objects.insertBegin(ptr, ptr.getRefData().isEnabled(), false); + objects.insertMesh(ptr, "meshes\\" + model); } } + void Ingredient::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + + + const std::string &model = ref->base->model; + assert (ref->base != NULL); + if(!model.empty()){ + physics.insertObjectPhysics(ptr); + } + + } + std::string Ingredient::getName (const MWWorld::Ptr& ptr) const { ESMS::LiveCellRef *ref = diff --git a/apps/openmw/mwclass/ingredient.hpp b/apps/openmw/mwclass/ingredient.hpp index 8b781ba2f..6c7409665 100644 --- a/apps/openmw/mwclass/ingredient.hpp +++ b/apps/openmw/mwclass/ingredient.hpp @@ -9,10 +9,11 @@ namespace MWClass { public: - virtual void insertObj (const MWWorld::Ptr& ptr, MWRender::CellRenderImp& cellRender, - MWWorld::Environment& environment) const; + virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const; ///< Add reference into a cell for rendering + virtual void insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const; + virtual std::string getName (const MWWorld::Ptr& ptr) const; ///< \return name (the one that is to be presented to the user; not the internal one); /// can return an empty string. diff --git a/apps/openmw/mwclass/light.cpp b/apps/openmw/mwclass/light.cpp index f32378002..8e7f32a6c 100644 --- a/apps/openmw/mwclass/light.cpp +++ b/apps/openmw/mwclass/light.cpp @@ -18,31 +18,40 @@ namespace MWClass { - void Light::insertObj (const MWWorld::Ptr& ptr, MWRender::CellRenderImp& cellRender, - MWWorld::Environment& environment) const + void Light::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const { ESMS::LiveCellRef *ref = ptr.get(); assert (ref->base != NULL); const std::string &model = ref->base->model; + if (!model.empty()) { - MWRender::Rendering rendering (cellRender, ref->ref, ref->mData); - - cellRender.insertMesh ("meshes\\" + model); - cellRender.insertObjectPhysics(); - - // Extract the color and convert to floating point + MWRender::Objects objects = renderingInterface.getObjects(); + objects.insertBegin(ptr, ptr.getRefData().isEnabled(), false); + objects.insertMesh(ptr, "meshes\\" + model); const int color = ref->base->data.color; - const float r = ((color >> 0) & 0xFF) / 255.0f; - const float g = ((color >> 8) & 0xFF) / 255.0f; + const float r = ((color >> 0) & 0xFF) / 255.0f; + const float g = ((color >> 8) & 0xFF) / 255.0f; const float b = ((color >> 16) & 0xFF) / 255.0f; const float radius = float (ref->base->data.radius); - cellRender.insertLight (r, g, b, radius); + objects.insertLight (r, g, b, radius); + } + } + + void Light::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + - ref->mData.setHandle (rendering.end (ref->mData.isEnabled())); + const std::string &model = ref->base->model; + assert (ref->base != NULL); + if(!model.empty()){ + physics.insertObjectPhysics(ptr); } + } void Light::enable (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const diff --git a/apps/openmw/mwclass/light.hpp b/apps/openmw/mwclass/light.hpp index 5a1a15b1d..7df82ae5d 100644 --- a/apps/openmw/mwclass/light.hpp +++ b/apps/openmw/mwclass/light.hpp @@ -9,10 +9,11 @@ namespace MWClass { public: - virtual void insertObj (const MWWorld::Ptr& ptr, MWRender::CellRenderImp& cellRender, - MWWorld::Environment& environment) const; + virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const; ///< Add reference into a cell for rendering + virtual void insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const; + virtual void enable (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const; ///< Enable reference; only does the non-rendering part /// \attention This is not the same as the script instruction with the same name. References diff --git a/apps/openmw/mwclass/misc.cpp b/apps/openmw/mwclass/misc.cpp index 84560d009..d331fd35b 100644 --- a/apps/openmw/mwclass/misc.cpp +++ b/apps/openmw/mwclass/misc.cpp @@ -14,23 +14,36 @@ namespace MWClass { - void Miscellaneous::insertObj (const MWWorld::Ptr& ptr, MWRender::CellRenderImp& cellRender, - MWWorld::Environment& environment) const + void Miscellaneous::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const { ESMS::LiveCellRef *ref = ptr.get(); assert (ref->base != NULL); const std::string &model = ref->base->model; + if (!model.empty()) { - MWRender::Rendering rendering (cellRender, ref->ref, ref->mData); - cellRender.insertMesh ("meshes\\" + model); - cellRender.insertObjectPhysics(); - ref->mData.setHandle (rendering.end (ref->mData.isEnabled())); + MWRender::Objects objects = renderingInterface.getObjects(); + objects.insertBegin(ptr, ptr.getRefData().isEnabled(), false); + objects.insertMesh(ptr, "meshes\\" + model); } } + void Miscellaneous::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + + const std::string &model = ref->base->model; + assert (ref->base != NULL); + if(!model.empty()){ + physics.insertObjectPhysics(ptr); + } + + } + std::string Miscellaneous::getName (const MWWorld::Ptr& ptr) const { ESMS::LiveCellRef *ref = diff --git a/apps/openmw/mwclass/misc.hpp b/apps/openmw/mwclass/misc.hpp index 81262cbee..cb1858315 100644 --- a/apps/openmw/mwclass/misc.hpp +++ b/apps/openmw/mwclass/misc.hpp @@ -9,10 +9,11 @@ namespace MWClass { public: - virtual void insertObj (const MWWorld::Ptr& ptr, MWRender::CellRenderImp& cellRender, - MWWorld::Environment& environment) const; + virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const; ///< Add reference into a cell for rendering + virtual void insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const; + virtual std::string getName (const MWWorld::Ptr& ptr) const; ///< \return name (the one that is to be presented to the user; not the internal one); /// can return an empty string. diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index 83161ebeb..ccca0f688 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -32,229 +32,34 @@ namespace MWClass return ref->base->mId; } - void Npc::insertObj (const MWWorld::Ptr& ptr, MWRender::CellRenderImp& cellRender, - MWWorld::Environment& environment) const + void Npc::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const { - //Ogre::SceneNode *chest; ESMS::LiveCellRef *ref = ptr.get(); - //Store scenenodes by npc's name + bodypart [0] , npc's name + bodypart [1] - //Ex. Fargothchest , Fargothneck - assert (ref->base != NULL); - - std::string hairID = ref->base->hair; - std::string headID = ref->base->head; - - // very ugly workaround to stop OGRE from chocking on non-unique scene node handles - static int uniqueId = 0; - - std::ostringstream stream; - stream << "npc$" << uniqueId++; - - std::string npcName = stream.str(); // ref->base->name; - //std::cout << "NPC: " << npcName << "\n"; - - //get the part of the bodypart id which describes the race and the gender - std::string bodyRaceID = headID.substr(0, headID.find_last_of("head_") - 4); - std::string headModel = "meshes\\" + - environment.mWorld->getStore().bodyParts.find(headID)->model; - - std::string hairModel = "meshes\\" + - environment.mWorld->getStore().bodyParts.find(hairID)->model; - - MWRender::Rendering rendering (cellRender, ref->ref, ref->mData); - - - //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"); - - //bodyPart->model-> - Ogre::Vector3 pos = Ogre::Vector3( 20, 20, 20); - Ogre::Vector3 axis = Ogre::Vector3( 0, 0, 1); - Ogre::Radian angle = Ogre::Radian(0); - - std::string addresses[6] = {"", "", "", "","", ""}; - std::string addresses2[6] = {"", "", "", "", "", ""}; - std::string upperleft[5] = {"", "", "", "", ""}; - std::string upperright[5] = {"", "", "", "", ""}; - std::string neckandup[5] = {"", "", "","",""}; - int numbers = 0; - int uppernumbers = 0; - int neckNumbers = 0; - - if (bodyPart){ - - cellRender.insertMesh("meshes\\" + bodyPart->model, pos, axis, angle, npcName + "chest", addresses, numbers, true); //2 0 - addresses2[numbers] = npcName + "chest"; - addresses[numbers++] = npcName + "chest"; - upperleft[uppernumbers] = npcName + "chest"; - upperright[uppernumbers++] = npcName + "chest"; - neckandup[neckNumbers++] = npcName + "chest"; - } - - - const ESM::BodyPart *upperleg = environment.mWorld->getStore().bodyParts.search (bodyRaceID + "upper leg"); - const ESM::BodyPart *groin = environment.mWorld->getStore().bodyParts.search (bodyRaceID + "groin"); - const ESM::BodyPart *arm = environment.mWorld->getStore().bodyParts.search (bodyRaceID + "upper arm"); - const ESM::BodyPart *neck = environment.mWorld->getStore().bodyParts.search (bodyRaceID + "neck"); - const ESM::BodyPart *knee = environment.mWorld->getStore().bodyParts.search (bodyRaceID + "knee"); - const ESM::BodyPart *ankle = environment.mWorld->getStore().bodyParts.search (bodyRaceID + "ankle"); - const ESM::BodyPart *foot = environment.mWorld->getStore().bodyParts.search (bodyRaceID + "foot"); - const ESM::BodyPart *feet = environment.mWorld->getStore().bodyParts.search (bodyRaceID + "feet"); - const ESM::BodyPart *tail = environment.mWorld->getStore().bodyParts.search (bodyRaceID + "tail"); - const ESM::BodyPart *wrist = environment.mWorld->getStore().bodyParts.search (bodyRaceID + "wrist"); - const ESM::BodyPart *forearm = environment.mWorld->getStore().bodyParts.search (bodyRaceID + "forearm"); - const ESM::BodyPart *hand = environment.mWorld->getStore().bodyParts.search (bodyRaceID + "hand.1st"); - const ESM::BodyPart *hands = environment.mWorld->getStore().bodyParts.search (bodyRaceID + "hands.1st"); - - - Ogre::Vector3 pos2 = Ogre::Vector3( 0, .5, 75); - - if (groin){ - 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"); - } - - - 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); - addresses2[numbers] = npcName + "upper leg2"; - addresses[numbers++] = npcName + "upper leg"; - cellRender.scaleMesh(Ogre::Vector3(1, -1, 1), addresses, numbers); - } - if(knee) - { - cellRender.insertMesh ("meshes\\" + knee->model, Ogre::Vector3( 0, -1, -23), axis, Ogre::Radian(0), npcName + "knee", addresses, numbers); - //cellRender.rotateMesh(Ogre::Vector3(0, 1, 0), Ogre::Radian (1), npcName + "upper arm"); - cellRender.insertMesh ("meshes\\" + knee->model, Ogre::Vector3( 0, -1, -23), axis, Ogre::Radian(0), npcName + "knee2", addresses2, numbers); - - addresses2[numbers] = npcName + "knee2"; - addresses[numbers++] = npcName + "knee"; - } - if(ankle){ - - cellRender.insertMesh ("meshes\\" + ankle->model, Ogre::Vector3( 0, 0, -20), axis, Ogre::Radian(0), npcName + "ankle", addresses, numbers); //-1 - cellRender.insertMesh ("meshes\\" + ankle->model, Ogre::Vector3( 0,0, -20), axis, Ogre::Radian(0), npcName + "ankle2", addresses2, numbers); //-1 - - addresses2[numbers] = npcName + "ankle2"; - addresses[numbers++] = npcName + "ankle"; - } - if(foot){ - if(bodyRaceID.compare("b_n_khajiit_m_") == 0) - { - feet = foot; - } - else - { - cellRender.insertMesh ("meshes\\" + foot->model, Ogre::Vector3( 0, -4, -15), axis, Ogre::Radian(0), npcName + "foot", addresses, numbers); - - cellRender.insertMesh ("meshes\\" + foot->model, Ogre::Vector3( 0, -4, -15), axis, Ogre::Radian(0), npcName + "foot2", addresses2, numbers); - addresses2[numbers] = npcName + "foot2"; - addresses[numbers++] = npcName + "foot"; - } - //cellRender.scaleMesh(Ogre::Vector3(1, -1, 1), addresses, numbers); - } - if(feet){ - - cellRender.insertMesh ("foot\\" + feet->model, Ogre::Vector3( 7, 4, -16), axis, kOgrePi, npcName + "foot", addresses, numbers); //9, 0, -14 - - cellRender.insertMesh ("foot\\" + feet->model, Ogre::Vector3( 7, 4, -16), axis, kOgrePi, npcName + "foot2", addresses2, numbers); - addresses2[numbers] = npcName + "foot2"; - addresses[numbers++] = npcName + "foot"; - //cellRender.scaleMesh(Ogre::Vector3(1, -1, 1), addresses, numbers); - } - - - if (arm){ - //010 - cellRender.insertMesh("meshes\\" + arm->model, Ogre::Vector3(-12.5, 0, 104), Ogre::Vector3(0, 1, 0), -kOgrePiOverTwo, npcName + "upper arm", upperleft, uppernumbers); //1, 0,.75 - //cellRender.rotateMesh(Ogre::Vector3(1, 0, 0), Ogre::Radian (.45), upperarmpath, 2); //-.5, 0, -.75 - cellRender.insertMesh("meshes\\" + arm->model, Ogre::Vector3(12.5, 0, 105), Ogre::Vector3(-.5, 0, -.75), kOgrePi, npcName + "upper arm2", upperright, uppernumbers); - upperleft[uppernumbers] = npcName + "upper arm"; - upperright[uppernumbers++] = npcName + "upper arm2"; - cellRender.scaleMesh(Ogre::Vector3(1, -1, 1), upperleft, uppernumbers); //1 -1 1 - cellRender.rotateMesh(Ogre::Vector3(0, .1, 0), kOgrePiOverTwo, upperleft, uppernumbers); - } - - if (forearm) + const std::string &model = ref->base->model; + + if (!model.empty()) { - //addresses[1] = npcName + "upper arm"; - cellRender.insertMesh("meshes\\" + forearm->model, Ogre::Vector3(-12.5, 0, 0), Ogre::Vector3(0, 0, 0), kOgrePi, npcName + "forearm", upperleft, uppernumbers); - cellRender.insertMesh("meshes\\" + forearm->model, Ogre::Vector3(-12.5, 0, 0), Ogre::Vector3(0, 0, 0), kOgrePi, npcName + "forearm2", upperright, uppernumbers); - upperleft[uppernumbers] = npcName + "forearm"; - upperright[uppernumbers++] = npcName + "forearm2"; - } - //else - // std::cout << npcName << "has no forearm"; - if (wrist) - { - if(upperleft[uppernumbers - 1].compare(npcName + "upper arm") == 0) - { - cellRender.insertMesh("meshes\\b\\B_N_Argonian_M_Forearm.nif", Ogre::Vector3(-12.5, 0, 0), Ogre::Vector3(0, 0, 0), kOgrePi, npcName + "forearm", upperleft, uppernumbers); - cellRender.insertMesh("meshes\\b\\B_N_Argonian_M_Forearm.nif", Ogre::Vector3(-12.5, 0, 0), Ogre::Vector3(0, 0, 0), kOgrePi, npcName + "forearm2", upperright, uppernumbers); - upperleft[uppernumbers] = npcName + "forearm"; - upperright[uppernumbers++] = npcName + "forearm2"; - - } - cellRender.insertMesh("meshes\\" + wrist->model, Ogre::Vector3(-9.5, 0, 0), Ogre::Vector3(0, 0, 0), kOgrePi, npcName + "wrist", upperleft, uppernumbers); - cellRender.insertMesh("meshes\\" + wrist->model, Ogre::Vector3(-9.5, 0, 0), Ogre::Vector3(0, 0, 0), kOgrePi, npcName + "wrist2", upperright, uppernumbers); - upperleft[uppernumbers] = npcName + "wrist"; - upperright[uppernumbers++] = npcName + "wrist2"; + MWRender::Objects objects = renderingInterface.getObjects(); + objects.insertBegin(ptr, ptr.getRefData().isEnabled(), false); + objects.insertMesh(ptr, "meshes\\" + model); } + } + void Npc::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const + { + ESMS::LiveCellRef *ref = + ptr.get(); - if(hand) - { - 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"; - else - pass = hand->model; - cellRender.insertMesh("meshes\\" + pass, Ogre::Vector3(42, 1, -110), Ogre::Vector3(0, 0, 0), kOgrePi, npcName + "hand", upperleft, uppernumbers,false); //0, 100, -100 0,0,120 - 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.scaleMesh(Ogre::Vector3(1, -1, 1), upperleft, uppernumbers); - cellRender.scaleMesh(Ogre::Vector3(1, -1, 1), upperright, uppernumbers); - } - if(hands) - { - std::string pass; - if(hands->model.compare("b\\B_N_Redguard_F_Hands.1st.nif")==0 && bodyRaceID.compare("b_n_redguard_m_") == 0) - pass = "b\\B_N_Redguard_M_Hands.1st.nif"; - else if(hands->model.compare("b\\B_N_Imperial_M_Hands.1st.nif") == 0 && bodyRaceID.compare("b_n_nord_m_") == 0) - pass = "b\\B_N_Nord_M_Hands.1st.nif"; - 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\\" + 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.scaleMesh(Ogre::Vector3(1, -1, 1), upperleft, uppernumbers); - 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, kOgrePi, npcName + "neck", neckandup, neckNumbers); - neckandup[neckNumbers++] = npcName + "neck"; + const std::string &model = ref->base->model; + assert (ref->base != NULL); + if(!model.empty()){ + physics.insertActorPhysics(ptr); } - 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.insertActorPhysics(); - ref->mData.setHandle (rendering.end (ref->mData.isEnabled())); } void Npc::enable (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const diff --git a/apps/openmw/mwclass/npc.hpp b/apps/openmw/mwclass/npc.hpp index 9f29878da..095f0de41 100644 --- a/apps/openmw/mwclass/npc.hpp +++ b/apps/openmw/mwclass/npc.hpp @@ -12,10 +12,11 @@ namespace MWClass virtual std::string getId (const MWWorld::Ptr& ptr) const; ///< Return ID of \a ptr - virtual void insertObj (const MWWorld::Ptr& ptr, MWRender::CellRenderImp& cellRender, - MWWorld::Environment& environment) const; + virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const; ///< Add reference into a cell for rendering + virtual void insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const; + virtual void enable (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const; ///< Enable reference; only does the non-rendering part diff --git a/apps/openmw/mwclass/potion.cpp b/apps/openmw/mwclass/potion.cpp index 7cd6db223..2eb1bbfa4 100644 --- a/apps/openmw/mwclass/potion.cpp +++ b/apps/openmw/mwclass/potion.cpp @@ -14,23 +14,36 @@ namespace MWClass { - void Potion::insertObj (const MWWorld::Ptr& ptr, MWRender::CellRenderImp& cellRender, - MWWorld::Environment& environment) const + void Potion::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const { ESMS::LiveCellRef *ref = ptr.get(); assert (ref->base != NULL); const std::string &model = ref->base->model; + if (!model.empty()) { - MWRender::Rendering rendering (cellRender, ref->ref, ref->mData); - cellRender.insertMesh ("meshes\\" + model); - cellRender.insertObjectPhysics(); - ref->mData.setHandle (rendering.end (ref->mData.isEnabled())); + MWRender::Objects objects = renderingInterface.getObjects(); + objects.insertBegin(ptr, ptr.getRefData().isEnabled(), false); + objects.insertMesh(ptr, "meshes\\" + model); } } + void Potion::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + + const std::string &model = ref->base->model; + assert (ref->base != NULL); + if(!model.empty()){ + physics.insertObjectPhysics(ptr); + } + + } + std::string Potion::getName (const MWWorld::Ptr& ptr) const { ESMS::LiveCellRef *ref = diff --git a/apps/openmw/mwclass/potion.hpp b/apps/openmw/mwclass/potion.hpp index 9bf3b34a8..e1a54db3c 100644 --- a/apps/openmw/mwclass/potion.hpp +++ b/apps/openmw/mwclass/potion.hpp @@ -9,10 +9,11 @@ namespace MWClass { public: - virtual void insertObj (const MWWorld::Ptr& ptr, MWRender::CellRenderImp& cellRender, - MWWorld::Environment& environment) const; + virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const; ///< Add reference into a cell for rendering + virtual void insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const; + virtual std::string getName (const MWWorld::Ptr& ptr) const; ///< \return name (the one that is to be presented to the user; not the internal one); /// can return an empty string. diff --git a/apps/openmw/mwclass/probe.cpp b/apps/openmw/mwclass/probe.cpp index b92f5ff26..59d836446 100644 --- a/apps/openmw/mwclass/probe.cpp +++ b/apps/openmw/mwclass/probe.cpp @@ -14,29 +14,34 @@ namespace MWClass { - void Probe::insertObj (const MWWorld::Ptr& ptr, MWRender::CellRenderImp& cellRender, - MWWorld::Environment& environment) const + void Probe::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const { ESMS::LiveCellRef *ref = ptr.get(); assert (ref->base != NULL); const std::string &model = ref->base->model; + if (!model.empty()) { - MWRender::Rendering rendering (cellRender, ref->ref, ref->mData); - cellRender.insertMesh ("meshes\\" + model); - cellRender.insertObjectPhysics(); - ref->mData.setHandle (rendering.end (ref->mData.isEnabled())); + MWRender::Objects objects = renderingInterface.getObjects(); + objects.insertBegin(ptr, ptr.getRefData().isEnabled(), false); + objects.insertMesh(ptr, "meshes\\" + model); } } - std::string Probe::getName (const MWWorld::Ptr& ptr) const + void Probe::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const { ESMS::LiveCellRef *ref = ptr.get(); - return ref->base->name; + + const std::string &model = ref->base->model; + assert (ref->base != NULL); + if(!model.empty()){ + physics.insertObjectPhysics(ptr); + } + } boost::shared_ptr Probe::activate (const MWWorld::Ptr& ptr, diff --git a/apps/openmw/mwclass/probe.hpp b/apps/openmw/mwclass/probe.hpp index 11399d2f6..287dd0475 100644 --- a/apps/openmw/mwclass/probe.hpp +++ b/apps/openmw/mwclass/probe.hpp @@ -9,10 +9,11 @@ namespace MWClass { public: - virtual void insertObj (const MWWorld::Ptr& ptr, MWRender::CellRenderImp& cellRender, - MWWorld::Environment& environment) const; + virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const; ///< Add reference into a cell for rendering + virtual void insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const; + virtual std::string getName (const MWWorld::Ptr& ptr) const; ///< \return name (the one that is to be presented to the user; not the internal one); /// can return an empty string. diff --git a/apps/openmw/mwclass/repair.cpp b/apps/openmw/mwclass/repair.cpp index d52f04e53..320e3827e 100644 --- a/apps/openmw/mwclass/repair.cpp +++ b/apps/openmw/mwclass/repair.cpp @@ -14,23 +14,36 @@ namespace MWClass { - void Repair::insertObj (const MWWorld::Ptr& ptr, MWRender::CellRenderImp& cellRender, - MWWorld::Environment& environment) const + void Repair::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const { ESMS::LiveCellRef *ref = ptr.get(); assert (ref->base != NULL); const std::string &model = ref->base->model; + if (!model.empty()) { - MWRender::Rendering rendering (cellRender, ref->ref, ref->mData); - cellRender.insertMesh ("meshes\\" + model); - cellRender.insertObjectPhysics(); - ref->mData.setHandle (rendering.end (ref->mData.isEnabled())); + MWRender::Objects objects = renderingInterface.getObjects(); + objects.insertBegin(ptr, ptr.getRefData().isEnabled(), false); + objects.insertMesh(ptr, "meshes\\" + model); } } + void Repair::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + + const std::string &model = ref->base->model; + assert (ref->base != NULL); + if(!model.empty()){ + physics.insertObjectPhysics(ptr); + } + + } + std::string Repair::getName (const MWWorld::Ptr& ptr) const { ESMS::LiveCellRef *ref = diff --git a/apps/openmw/mwclass/repair.hpp b/apps/openmw/mwclass/repair.hpp index 3da591e01..174197d9a 100644 --- a/apps/openmw/mwclass/repair.hpp +++ b/apps/openmw/mwclass/repair.hpp @@ -9,10 +9,11 @@ namespace MWClass { public: - virtual void insertObj (const MWWorld::Ptr& ptr, MWRender::CellRenderImp& cellRender, - MWWorld::Environment& environment) const; + virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const; ///< Add reference into a cell for rendering + virtual void insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const; + virtual std::string getName (const MWWorld::Ptr& ptr) const; ///< \return name (the one that is to be presented to the user; not the internal one); /// can return an empty string. diff --git a/apps/openmw/mwclass/static.cpp b/apps/openmw/mwclass/static.cpp index 5691f92ba..372606ace 100644 --- a/apps/openmw/mwclass/static.cpp +++ b/apps/openmw/mwclass/static.cpp @@ -9,23 +9,36 @@ namespace MWClass { - void Static::insertObj (const MWWorld::Ptr& ptr, MWRender::CellRenderImp& cellRender, - MWWorld::Environment& environment) const + void Static::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const { ESMS::LiveCellRef *ref = ptr.get(); assert (ref->base != NULL); const std::string &model = ref->base->model; + if (!model.empty()) { - MWRender::Rendering rendering (cellRender, ref->ref, ref->mData, true); - cellRender.insertMesh ("meshes\\" + model); - cellRender.insertObjectPhysics(); - ref->mData.setHandle (rendering.end (ref->mData.isEnabled())); + MWRender::Objects objects = renderingInterface.getObjects(); + objects.insertBegin(ptr, ptr.getRefData().isEnabled(), false); + objects.insertMesh(ptr, "meshes\\" + model); } } + void Static::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + + const std::string &model = ref->base->model; + assert (ref->base != NULL); + if(!model.empty()){ + physics.insertObjectPhysics(ptr); + } + + } + std::string Static::getName (const MWWorld::Ptr& ptr) const { return ""; diff --git a/apps/openmw/mwclass/static.hpp b/apps/openmw/mwclass/static.hpp index abbf6cd5f..a4b1d8c54 100644 --- a/apps/openmw/mwclass/static.hpp +++ b/apps/openmw/mwclass/static.hpp @@ -9,10 +9,11 @@ namespace MWClass { public: - virtual void insertObj (const MWWorld::Ptr& ptr, MWRender::CellRenderImp& cellRender, - MWWorld::Environment& environment) const; + virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const; ///< Add reference into a cell for rendering + virtual void insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const; + virtual std::string getName (const MWWorld::Ptr& ptr) const; ///< \return name (the one that is to be presented to the user; not the internal one); /// can return an empty string. diff --git a/apps/openmw/mwclass/weapon.cpp b/apps/openmw/mwclass/weapon.cpp index 5dcc94fc8..dd52ed495 100644 --- a/apps/openmw/mwclass/weapon.cpp +++ b/apps/openmw/mwclass/weapon.cpp @@ -14,23 +14,36 @@ namespace MWClass { - void Weapon::insertObj (const MWWorld::Ptr& ptr, MWRender::CellRenderImp& cellRender, - MWWorld::Environment& environment) const + void Weapon::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const { ESMS::LiveCellRef *ref = ptr.get(); assert (ref->base != NULL); const std::string &model = ref->base->model; + if (!model.empty()) { - MWRender::Rendering rendering (cellRender, ref->ref, ref->mData); - cellRender.insertMesh ("meshes\\" + model); - cellRender.insertObjectPhysics(); - ref->mData.setHandle (rendering.end (ref->mData.isEnabled())); + MWRender::Objects objects = renderingInterface.getObjects(); + objects.insertBegin(ptr, ptr.getRefData().isEnabled(), false); + objects.insertMesh(ptr, "meshes\\" + model); } } + void Weapon::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + + const std::string &model = ref->base->model; + assert (ref->base != NULL); + if(!model.empty()){ + physics.insertObjectPhysics(ptr); + } + + } + std::string Weapon::getName (const MWWorld::Ptr& ptr) const { ESMS::LiveCellRef *ref = diff --git a/apps/openmw/mwclass/weapon.hpp b/apps/openmw/mwclass/weapon.hpp index d9c7653dd..84c633ab3 100644 --- a/apps/openmw/mwclass/weapon.hpp +++ b/apps/openmw/mwclass/weapon.hpp @@ -9,10 +9,11 @@ namespace MWClass { public: - virtual void insertObj (const MWWorld::Ptr& ptr, MWRender::CellRenderImp& cellRender, - MWWorld::Environment& environment) const; + virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const; ///< Add reference into a cell for rendering + virtual void insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const; + virtual std::string getName (const MWWorld::Ptr& ptr) const; ///< \return name (the one that is to be presented to the user; not the internal one); /// can return an empty string. From 0b3bb2719f30b0575b37f14108f3515933dddaca Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Sat, 12 Nov 2011 00:19:22 -0500 Subject: [PATCH 040/104] Fixing some errors --- apps/openmw/mwclass/light.cpp | 2 +- apps/openmw/mwclass/lockpick.cpp | 1 - apps/openmw/mwrender/renderinginterface.hpp | 2 ++ apps/openmw/mwrender/renderingmanager.cpp | 1 - apps/openmw/mwrender/renderingmanager.hpp | 7 ++++++- apps/openmw/mwworld/class.hpp | 5 ++++- 6 files changed, 13 insertions(+), 5 deletions(-) diff --git a/apps/openmw/mwclass/light.cpp b/apps/openmw/mwclass/light.cpp index 8e7f32a6c..3fb455914 100644 --- a/apps/openmw/mwclass/light.cpp +++ b/apps/openmw/mwclass/light.cpp @@ -36,7 +36,7 @@ namespace MWClass const float g = ((color >> 8) & 0xFF) / 255.0f; const float b = ((color >> 16) & 0xFF) / 255.0f; const float radius = float (ref->base->data.radius); - objects.insertLight (r, g, b, radius); + objects.insertLight (ptr, r, g, b, radius); } } diff --git a/apps/openmw/mwclass/lockpick.cpp b/apps/openmw/mwclass/lockpick.cpp index c80e5ab7c..8e782bb0f 100644 --- a/apps/openmw/mwclass/lockpick.cpp +++ b/apps/openmw/mwclass/lockpick.cpp @@ -9,7 +9,6 @@ #include "../mwworld/actiontake.hpp" #include "../mwrender/cellimp.hpp" -#include "../mwrender/renderinginterface.hpp" #include "containerutil.hpp" namespace MWClass diff --git a/apps/openmw/mwrender/renderinginterface.hpp b/apps/openmw/mwrender/renderinginterface.hpp index 28f3b61fc..fed1fd3ec 100644 --- a/apps/openmw/mwrender/renderinginterface.hpp +++ b/apps/openmw/mwrender/renderinginterface.hpp @@ -1,6 +1,8 @@ #include "objects.hpp" #include "npcs.hpp" #include "creatures.hpp" +#include "player.hpp" +#define RENDERING_INTERFACE 1 namespace MWRender{ class RenderingInterface{ public: diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index 39c1bca7a..9242fac67 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -13,7 +13,6 @@ #include "../mwworld/ptr.hpp" #include -#include "player.hpp" using namespace MWRender; diff --git a/apps/openmw/mwrender/renderingmanager.hpp b/apps/openmw/mwrender/renderingmanager.hpp index 0508fa54d..f3bc7005d 100644 --- a/apps/openmw/mwrender/renderingmanager.hpp +++ b/apps/openmw/mwrender/renderingmanager.hpp @@ -4,7 +4,9 @@ #include "sky.hpp" #include "debugging.hpp" -#include "renderinginterface.hpp" +//Commented out for now, possibly do an ifdef if necessary, cla + + #include #include @@ -17,6 +19,9 @@ #include +#ifndef RENDERING_INTERFACE +#include "renderinginterface.hpp" +#endif namespace Ogre diff --git a/apps/openmw/mwworld/class.hpp b/apps/openmw/mwworld/class.hpp index 706b11aaa..44de4888f 100644 --- a/apps/openmw/mwworld/class.hpp +++ b/apps/openmw/mwworld/class.hpp @@ -9,8 +9,11 @@ #include "action.hpp" #include "containerstore.hpp" #include "refdata.hpp" -#include "../mwrender/renderinginterface.hpp" + #include "physicssystem.hpp" +#ifndef RENDERING_INTERFACE +#include "../mwrender/renderinginterface.hpp" +#endif namespace Ogre { From bc58ef28cdc6e135515349d90f9096c310cbdbe2 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Sat, 12 Nov 2011 15:58:22 -0500 Subject: [PATCH 041/104] Made corrections --- apps/openmw/mwclass/activator.cpp | 1 + apps/openmw/mwclass/apparatus.hpp | 1 + apps/openmw/mwclass/armor.hpp | 1 + apps/openmw/mwclass/book.hpp | 1 + apps/openmw/mwclass/clothing.hpp | 1 + apps/openmw/mwclass/container.hpp | 1 + apps/openmw/mwclass/creature.cpp | 6 +++--- apps/openmw/mwclass/creature.hpp | 1 + apps/openmw/mwclass/door.cpp | 1 + apps/openmw/mwclass/door.hpp | 1 + apps/openmw/mwclass/ingredient.hpp | 1 + apps/openmw/mwclass/itemlevlist.hpp | 5 +++++ apps/openmw/mwclass/light.hpp | 1 + apps/openmw/mwclass/lockpick.hpp | 1 + apps/openmw/mwclass/misc.hpp | 1 + apps/openmw/mwclass/npc.cpp | 7 ++++--- apps/openmw/mwclass/npc.hpp | 1 + apps/openmw/mwclass/potion.hpp | 1 + apps/openmw/mwclass/probe.hpp | 1 + apps/openmw/mwclass/repair.hpp | 1 + apps/openmw/mwclass/static.hpp | 1 + apps/openmw/mwclass/weapon.hpp | 1 + apps/openmw/mwrender/creatures.hpp | 5 ++++- apps/openmw/mwrender/npcs.hpp | 3 +++ apps/openmw/mwrender/objects.hpp | 6 +++++- apps/openmw/mwrender/renderinginterface.hpp | 15 +++++++++------ apps/openmw/mwrender/renderingmanager.cpp | 2 +- apps/openmw/mwrender/renderingmanager.hpp | 13 +++++++------ apps/openmw/mwworld/class.hpp | 5 +---- 29 files changed, 61 insertions(+), 25 deletions(-) diff --git a/apps/openmw/mwclass/activator.cpp b/apps/openmw/mwclass/activator.cpp index cd34997d2..fcad0d333 100644 --- a/apps/openmw/mwclass/activator.cpp +++ b/apps/openmw/mwclass/activator.cpp @@ -1,5 +1,6 @@ #include "activator.hpp" +#include "../mwrender/objects.hpp" #include diff --git a/apps/openmw/mwclass/apparatus.hpp b/apps/openmw/mwclass/apparatus.hpp index 9a5a9b955..4c8a2c0e2 100644 --- a/apps/openmw/mwclass/apparatus.hpp +++ b/apps/openmw/mwclass/apparatus.hpp @@ -2,6 +2,7 @@ #define GAME_MWCLASS_APPARATUS_H #include "../mwworld/class.hpp" +#include "../mwrender/objects.hpp" namespace MWClass { diff --git a/apps/openmw/mwclass/armor.hpp b/apps/openmw/mwclass/armor.hpp index 123713a38..c5f9812b7 100644 --- a/apps/openmw/mwclass/armor.hpp +++ b/apps/openmw/mwclass/armor.hpp @@ -2,6 +2,7 @@ #define GAME_MWCLASS_ARMOR_H #include "../mwworld/class.hpp" +#include "../mwrender/objects.hpp" namespace MWClass { diff --git a/apps/openmw/mwclass/book.hpp b/apps/openmw/mwclass/book.hpp index 6e38ea0d3..f0e38cceb 100644 --- a/apps/openmw/mwclass/book.hpp +++ b/apps/openmw/mwclass/book.hpp @@ -2,6 +2,7 @@ #define GAME_MWCLASS_BOOK_H #include "../mwworld/class.hpp" +#include "../mwrender/objects.hpp" namespace MWClass { diff --git a/apps/openmw/mwclass/clothing.hpp b/apps/openmw/mwclass/clothing.hpp index 353f7f606..76c2c4a3e 100644 --- a/apps/openmw/mwclass/clothing.hpp +++ b/apps/openmw/mwclass/clothing.hpp @@ -2,6 +2,7 @@ #define GAME_MWCLASS_CLOTHING_H #include "../mwworld/class.hpp" +#include "../mwrender/objects.hpp" namespace MWClass { diff --git a/apps/openmw/mwclass/container.hpp b/apps/openmw/mwclass/container.hpp index 9d65927f8..01763870a 100644 --- a/apps/openmw/mwclass/container.hpp +++ b/apps/openmw/mwclass/container.hpp @@ -2,6 +2,7 @@ #define GAME_MWCLASS_CONTAINER_H #include "../mwworld/class.hpp" +#include "../mwrender/objects.hpp" namespace MWClass { diff --git a/apps/openmw/mwclass/creature.cpp b/apps/openmw/mwclass/creature.cpp index 2eca30539..12978c0dc 100644 --- a/apps/openmw/mwclass/creature.cpp +++ b/apps/openmw/mwclass/creature.cpp @@ -33,9 +33,9 @@ namespace MWClass if (!model.empty()) { - MWRender::Objects objects = renderingInterface.getObjects(); - objects.insertBegin(ptr, ptr.getRefData().isEnabled(), false); - objects.insertMesh(ptr, "meshes\\" + model); + MWRender::Creatures creatures = renderingInterface.getCreatures(); + //creatures.insertBegin(ptr, ptr.getRefData().isEnabled(), false); + //creatures.insertMesh(ptr, "meshes\\" + model); } } diff --git a/apps/openmw/mwclass/creature.hpp b/apps/openmw/mwclass/creature.hpp index e1657b2c7..f74cdf991 100644 --- a/apps/openmw/mwclass/creature.hpp +++ b/apps/openmw/mwclass/creature.hpp @@ -2,6 +2,7 @@ #define GAME_MWCLASS_CREATURE_H #include "../mwworld/class.hpp" +#include "../mwrender/creatures.hpp" namespace MWClass { diff --git a/apps/openmw/mwclass/door.cpp b/apps/openmw/mwclass/door.cpp index 9e2b17b2e..5073afb12 100644 --- a/apps/openmw/mwclass/door.cpp +++ b/apps/openmw/mwclass/door.cpp @@ -13,6 +13,7 @@ #include "../mwworld/world.hpp" #include "../mwrender/cellimp.hpp" +#include "../mwrender/objects.hpp" #include diff --git a/apps/openmw/mwclass/door.hpp b/apps/openmw/mwclass/door.hpp index aecb4224c..c230cf357 100644 --- a/apps/openmw/mwclass/door.hpp +++ b/apps/openmw/mwclass/door.hpp @@ -2,6 +2,7 @@ #define GAME_MWCLASS_DOOR_H #include "../mwworld/class.hpp" +#include "../mwrender/objects.hpp" namespace MWClass { diff --git a/apps/openmw/mwclass/ingredient.hpp b/apps/openmw/mwclass/ingredient.hpp index 6c7409665..47bd1a9e5 100644 --- a/apps/openmw/mwclass/ingredient.hpp +++ b/apps/openmw/mwclass/ingredient.hpp @@ -2,6 +2,7 @@ #define GAME_MWCLASS_INGREDIENT_H #include "../mwworld/class.hpp" +#include "../mwrender/objects.hpp" namespace MWClass { diff --git a/apps/openmw/mwclass/itemlevlist.hpp b/apps/openmw/mwclass/itemlevlist.hpp index 0b71b072c..c7d630aee 100644 --- a/apps/openmw/mwclass/itemlevlist.hpp +++ b/apps/openmw/mwclass/itemlevlist.hpp @@ -9,6 +9,11 @@ namespace MWClass { public: + virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const; + ///< Add reference into a cell for rendering + + virtual void insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const; + virtual std::string getName (const MWWorld::Ptr& ptr) const; ///< \return name (the one that is to be presented to the user; not the internal one); /// can return an empty string. diff --git a/apps/openmw/mwclass/light.hpp b/apps/openmw/mwclass/light.hpp index 7df82ae5d..34421ff51 100644 --- a/apps/openmw/mwclass/light.hpp +++ b/apps/openmw/mwclass/light.hpp @@ -2,6 +2,7 @@ #define GAME_MWCLASS_LIGHT_H #include "../mwworld/class.hpp" +#include "../mwrender/objects.hpp" namespace MWClass { diff --git a/apps/openmw/mwclass/lockpick.hpp b/apps/openmw/mwclass/lockpick.hpp index 074a07c93..c5f1539b4 100644 --- a/apps/openmw/mwclass/lockpick.hpp +++ b/apps/openmw/mwclass/lockpick.hpp @@ -2,6 +2,7 @@ #define GAME_MWCLASS_LOCKPICK_H #include "../mwworld/class.hpp" +#include "../mwrender/objects.hpp" namespace MWClass { diff --git a/apps/openmw/mwclass/misc.hpp b/apps/openmw/mwclass/misc.hpp index cb1858315..36ee2c1b2 100644 --- a/apps/openmw/mwclass/misc.hpp +++ b/apps/openmw/mwclass/misc.hpp @@ -2,6 +2,7 @@ #define GAME_MWCLASS_MISC_H #include "../mwworld/class.hpp" +#include "../mwrender/objects.hpp" namespace MWClass { diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index ccca0f688..6ecdc6e4e 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -15,6 +15,7 @@ #include "../mwmechanics/mechanicsmanager.hpp" #include +#include "../mwrender/objects.hpp" namespace { @@ -42,9 +43,9 @@ namespace MWClass if (!model.empty()) { - MWRender::Objects objects = renderingInterface.getObjects(); - objects.insertBegin(ptr, ptr.getRefData().isEnabled(), false); - objects.insertMesh(ptr, "meshes\\" + model); + MWRender::Npcs npcs = renderingInterface.getNPCs(); + //npcs.insertBegin(ptr, ptr.getRefData().isEnabled(), false); + //npcs.insertMesh(ptr, "meshes\\" + model); } } diff --git a/apps/openmw/mwclass/npc.hpp b/apps/openmw/mwclass/npc.hpp index 095f0de41..271d66392 100644 --- a/apps/openmw/mwclass/npc.hpp +++ b/apps/openmw/mwclass/npc.hpp @@ -2,6 +2,7 @@ #define GAME_MWCLASS_NPC_H #include "../mwworld/class.hpp" +#include "../mwrender/npcs.hpp" namespace MWClass { diff --git a/apps/openmw/mwclass/potion.hpp b/apps/openmw/mwclass/potion.hpp index e1a54db3c..85678121f 100644 --- a/apps/openmw/mwclass/potion.hpp +++ b/apps/openmw/mwclass/potion.hpp @@ -2,6 +2,7 @@ #define GAME_MWCLASS_POTION_H #include "../mwworld/class.hpp" +#include "../mwrender/objects.hpp" namespace MWClass { diff --git a/apps/openmw/mwclass/probe.hpp b/apps/openmw/mwclass/probe.hpp index 287dd0475..d3495bb48 100644 --- a/apps/openmw/mwclass/probe.hpp +++ b/apps/openmw/mwclass/probe.hpp @@ -2,6 +2,7 @@ #define GAME_MWCLASS_PROBE_H #include "../mwworld/class.hpp" +#include "../mwrender/objects.hpp" namespace MWClass { diff --git a/apps/openmw/mwclass/repair.hpp b/apps/openmw/mwclass/repair.hpp index 174197d9a..1e0ea5178 100644 --- a/apps/openmw/mwclass/repair.hpp +++ b/apps/openmw/mwclass/repair.hpp @@ -2,6 +2,7 @@ #define GAME_MWCLASS_REPAIR_H #include "../mwworld/class.hpp" +#include "../mwrender/objects.hpp" namespace MWClass { diff --git a/apps/openmw/mwclass/static.hpp b/apps/openmw/mwclass/static.hpp index a4b1d8c54..be3fdb180 100644 --- a/apps/openmw/mwclass/static.hpp +++ b/apps/openmw/mwclass/static.hpp @@ -2,6 +2,7 @@ #define GAME_MWCLASS_STATIC_H #include "../mwworld/class.hpp" +#include "../mwrender/objects.hpp" namespace MWClass { diff --git a/apps/openmw/mwclass/weapon.hpp b/apps/openmw/mwclass/weapon.hpp index 84c633ab3..79bc4d4de 100644 --- a/apps/openmw/mwclass/weapon.hpp +++ b/apps/openmw/mwclass/weapon.hpp @@ -2,6 +2,7 @@ #define GAME_MWCLASS_WEAPON_H #include "../mwworld/class.hpp" +#include "../mwrender/objects.hpp" namespace MWClass { diff --git a/apps/openmw/mwrender/creatures.hpp b/apps/openmw/mwrender/creatures.hpp index 17946f050..9aabb175b 100644 --- a/apps/openmw/mwrender/creatures.hpp +++ b/apps/openmw/mwrender/creatures.hpp @@ -1,7 +1,10 @@ +#ifndef _GAME_RENDER_CREATURES_H +#define _GAME_RENDER_CREATURES_H #include namespace MWRender{ class Creatures{ }; -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/apps/openmw/mwrender/npcs.hpp b/apps/openmw/mwrender/npcs.hpp index c9701f195..88ee5ca30 100644 --- a/apps/openmw/mwrender/npcs.hpp +++ b/apps/openmw/mwrender/npcs.hpp @@ -1,6 +1,9 @@ +#ifndef _GAME_RENDER_NPCS_H +#define _GAME_RENDER_NPCS_H #include namespace MWRender{ class Npcs{ }; } +#endif diff --git a/apps/openmw/mwrender/objects.hpp b/apps/openmw/mwrender/objects.hpp index e830d0993..0dd7fdd4c 100644 --- a/apps/openmw/mwrender/objects.hpp +++ b/apps/openmw/mwrender/objects.hpp @@ -1,3 +1,6 @@ +#ifndef _GAME_RENDER_OBJECTS_H +#define _GAME_RENDER_OBJECTS_H + #include "components/esm_store/cell_store.hpp" #include "../mwworld/refdata.hpp" @@ -40,4 +43,5 @@ public: /// insert a light related to the most recent insertBegin call. }; -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/apps/openmw/mwrender/renderinginterface.hpp b/apps/openmw/mwrender/renderinginterface.hpp index fed1fd3ec..ebd4af2bd 100644 --- a/apps/openmw/mwrender/renderinginterface.hpp +++ b/apps/openmw/mwrender/renderinginterface.hpp @@ -1,14 +1,17 @@ -#include "objects.hpp" -#include "npcs.hpp" -#include "creatures.hpp" -#include "player.hpp" -#define RENDERING_INTERFACE 1 +#ifndef _GAME_RENDERING_INTERFACE_H +#define _GAME_RENDERING_INTERFACE_H namespace MWRender{ + class Npcs; + class Creatures; + class Objects; + class Player; class RenderingInterface{ public: virtual MWRender::Npcs& getNPCs() = 0; virtual MWRender::Creatures& getCreatures() = 0; virtual MWRender::Objects& getObjects() = 0; virtual MWRender::Player& getPlayer() = 0; + virtual ~RenderingInterface(){}; }; -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index 9242fac67..a413b0372 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -12,7 +12,7 @@ #include "../mwworld/world.hpp" // these includes can be removed once the static-hack is gone #include "../mwworld/ptr.hpp" #include - +#include "renderinginterface.hpp" using namespace MWRender; diff --git a/apps/openmw/mwrender/renderingmanager.hpp b/apps/openmw/mwrender/renderingmanager.hpp index f3bc7005d..9e1f86372 100644 --- a/apps/openmw/mwrender/renderingmanager.hpp +++ b/apps/openmw/mwrender/renderingmanager.hpp @@ -19,10 +19,11 @@ #include -#ifndef RENDERING_INTERFACE #include "renderinginterface.hpp" -#endif - +#include "npcs.hpp" +#include "creatures.hpp" +#include "objects.hpp" +#include "player.hpp" namespace Ogre { @@ -42,7 +43,7 @@ namespace MWWorld namespace MWRender { - class Player; + class RenderingManager: private RenderingInterface { @@ -51,7 +52,7 @@ class RenderingManager: private RenderingInterface { public: RenderingManager(OEngine::Render::OgreRenderer& _rend, const boost::filesystem::path& resDir, OEngine::Physic::PhysicEngine* engine); - ~RenderingManager(); + virtual ~RenderingManager(); virtual MWRender::Npcs& getNPCs(); virtual MWRender::Creatures& getCreatures(); virtual MWRender::Objects& getObjects(); @@ -96,7 +97,7 @@ class RenderingManager: private RenderingInterface { SkyManager* mSkyManager; OEngine::Render::OgreRenderer &rend; Ogre::Camera* camera; - MWRender::Npcs npcs; + MWRender::Npcs npcs; MWRender::Creatures creatures; MWRender::Objects objects; diff --git a/apps/openmw/mwworld/class.hpp b/apps/openmw/mwworld/class.hpp index 44de4888f..706b11aaa 100644 --- a/apps/openmw/mwworld/class.hpp +++ b/apps/openmw/mwworld/class.hpp @@ -9,11 +9,8 @@ #include "action.hpp" #include "containerstore.hpp" #include "refdata.hpp" - -#include "physicssystem.hpp" -#ifndef RENDERING_INTERFACE #include "../mwrender/renderinginterface.hpp" -#endif +#include "physicssystem.hpp" namespace Ogre { From db57f0a1a5752914cd252a021e838a27bddb7bc1 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Sun, 13 Nov 2011 18:19:29 -0500 Subject: [PATCH 042/104] more corrections --- apps/openmw/mwclass/itemlevlist.hpp | 5 ----- apps/openmw/mwclass/npc.cpp | 1 - apps/openmw/mwrender/renderingmanager.cpp | 1 - 3 files changed, 7 deletions(-) diff --git a/apps/openmw/mwclass/itemlevlist.hpp b/apps/openmw/mwclass/itemlevlist.hpp index c7d630aee..0b71b072c 100644 --- a/apps/openmw/mwclass/itemlevlist.hpp +++ b/apps/openmw/mwclass/itemlevlist.hpp @@ -9,11 +9,6 @@ namespace MWClass { public: - virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const; - ///< Add reference into a cell for rendering - - virtual void insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const; - virtual std::string getName (const MWWorld::Ptr& ptr) const; ///< \return name (the one that is to be presented to the user; not the internal one); /// can return an empty string. diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index 6ecdc6e4e..a3171f5b5 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -15,7 +15,6 @@ #include "../mwmechanics/mechanicsmanager.hpp" #include -#include "../mwrender/objects.hpp" namespace { diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index a413b0372..2a502279d 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -12,7 +12,6 @@ #include "../mwworld/world.hpp" // these includes can be removed once the static-hack is gone #include "../mwworld/ptr.hpp" #include -#include "renderinginterface.hpp" using namespace MWRender; From dd466940595043100cff3c7d3f536664af970eff Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Sun, 13 Nov 2011 23:14:18 -0500 Subject: [PATCH 043/104] Changing a lot of things in scene and world --- apps/openmw/mwworld/backup/scene.cpp | 275 +++++++++++++++++++++++++++ apps/openmw/mwworld/backup/scene.hpp | 106 +++++++++++ apps/openmw/mwworld/scene.cpp | 60 +++--- apps/openmw/mwworld/scene.hpp | 11 +- apps/openmw/mwworld/world.cpp | 89 +++++---- apps/openmw/mwworld/world.hpp | 2 +- 6 files changed, 474 insertions(+), 69 deletions(-) create mode 100644 apps/openmw/mwworld/backup/scene.cpp create mode 100644 apps/openmw/mwworld/backup/scene.hpp diff --git a/apps/openmw/mwworld/backup/scene.cpp b/apps/openmw/mwworld/backup/scene.cpp new file mode 100644 index 000000000..93b4a80f4 --- /dev/null +++ b/apps/openmw/mwworld/backup/scene.cpp @@ -0,0 +1,275 @@ +#include "scene.hpp" +#include "world.hpp" + +#include "../mwrender/interior.hpp" +#include "../mwrender/exterior.hpp" + +#include "../mwmechanics/mechanicsmanager.hpp" + +#include "../mwsound/soundmanager.hpp" + +#include "ptr.hpp" +#include "environment.hpp" +#include "player.hpp" +#include "class.hpp" + +#include "cellfunctors.hpp" + +namespace { + +template +void insertCellRefList (T& cellRefList, ESMS::CellStore &cell) +{ + if (!cellRefList.list.empty()) + { + //const MWWorld::Class& class_ = MWWorld::Class::get (MWWorld::Ptr (&*cellRefList.list.begin(), &cell)); + + for (typename T::List::iterator it = cellRefList.list.begin(); + it != cellRefList.list.end(); it++) + { + if (it->mData.getCount() || it->mData.isEnabled()) + { + MWWorld::Ptr ptr (&*it, &cell); + /* TODO: call + * RenderingManager.insertObject + * class_.insertObjectPhysic + * class_.insertObjectMechanics + */ + } + } + } +} + +} + + +namespace MWWorld +{ + + void Scene::unloadCell (CellRenderCollection::iterator iter) + { + ListHandles functor; + iter->first->forEach(functor); + + { // silence annoying g++ warning + for (std::vector::const_iterator iter (functor.mHandles.begin()); + iter!=functor.mHandles.end(); ++iter) + mPhysics->removeObject (*iter); + } + + mWorld->getLocalScripts().clearCell (iter->first); + + mEnvironment.mMechanicsManager->dropActors (iter->first); + mEnvironment.mSoundManager->stopSound (iter->first); + delete iter->second; + mActiveCells.erase (iter); + } + + void Scene::loadCell (Ptr::CellStore *cell, MWRender::CellRender *render) + { + // register local scripts + mWorld->getLocalScripts().addCell (cell); + + // This connects the cell data with the rendering scene. + std::pair result = + mActiveCells.insert (std::make_pair (cell, render)); + + if (result.second) + { + // Load the cell and insert it into the renderer + result.first->second->show(); + } + } + + void Scene::playerCellChange (Ptr::CellStore *cell, const ESM::Position& position, + bool adjustPlayerPos) + { + if (adjustPlayerPos) + mWorld->getPlayer().setPos (position.pos[0], position.pos[1], position.pos[2]); + + mWorld->getPlayer().setCell (cell); + // TODO orientation + mEnvironment.mMechanicsManager->addActor (mWorld->getPlayer().getPlayer()); + mEnvironment.mMechanicsManager->watchActor (mWorld->getPlayer().getPlayer()); + } + + void Scene::changeCell (int X, int Y, const ESM::Position& position, bool adjustPlayerPos) + { + // remove active + mEnvironment.mMechanicsManager->removeActor (mWorld->getPlayer().getPlayer()); + + CellRenderCollection::iterator active = mActiveCells.begin(); + + while (active!=mActiveCells.end()) + { + if (!(active->first->cell->data.flags & ESM::Cell::Interior)) + { + if (std::abs (X-active->first->cell->data.gridX)<=1 && + std::abs (Y-active->first->cell->data.gridY)<=1) + { + // keep cells within the new 3x3 grid + ++active; + continue; + } + } + + unloadCell (active++); + } + + // Load cells + for (int x=X-1; x<=X+1; ++x) + for (int y=Y-1; y<=Y+1; ++y) + { + CellRenderCollection::iterator iter = mActiveCells.begin(); + + while (iter!=mActiveCells.end()) + { + assert (!(iter->first->cell->data.flags & ESM::Cell::Interior)); + + if (x==iter->first->cell->data.gridX && + y==iter->first->cell->data.gridY) + break; + + ++iter; + } + + if (iter==mActiveCells.end()) + { + Ptr::CellStore *cell = mWorld->getExterior(x, y); + + loadCell (cell, new MWRender::ExteriorCellRender (*cell, mEnvironment, mRendering.getOgreRenderer(), mMwRoot, mPhysics)); + } + } + + // find current cell + CellRenderCollection::iterator iter = mActiveCells.begin(); + + while (iter!=mActiveCells.end()) + { + assert (!(iter->first->cell->data.flags & ESM::Cell::Interior)); + + if (X==iter->first->cell->data.gridX && + Y==iter->first->cell->data.gridY) + break; + + ++iter; + } + + assert (iter!=mActiveCells.end()); + + mCurrentCell = iter->first; + + // adjust player + playerCellChange (mWorld->getExterior(X, Y), position, adjustPlayerPos); + + // Sky system + mWorld->adjustSky(); + + mCellChanged = true; + } + + //We need the ogre renderer and a scene node. + Scene::Scene (Environment& environment, World *world, MWRender::RenderingManager& rendering, Ogre::SceneNode *mwRoot, PhysicsSystem *physics) + : mRendering(rendering), mCurrentCell (0), + mCellChanged (false), mEnvironment (environment), mWorld(world), mPhysics(physics) + { + mMwRoot = mwRoot; + } + + Scene::~Scene() + { + for (CellRenderCollection::iterator iter (mActiveCells.begin()); + iter!=mActiveCells.end(); ++iter) + delete iter->second; + } + + bool Scene::hasCellChanged() const + { + return mCellChanged; + } + + const Scene::CellRenderCollection& Scene::getActiveCells() const + { + return mActiveCells; + } + + void Scene::changeToInteriorCell (const std::string& cellName, const ESM::Position& position) + { + // remove active + CellRenderCollection::iterator active = mActiveCells.begin(); + + while (active!=mActiveCells.end()) + { + unloadCell (active++); + } + + // Load cell. + std::cout << "cellName:" << cellName << std::endl; + Ptr::CellStore *cell = mWorld->getInterior(cellName); + + loadCell (cell, new MWRender::InteriorCellRender (*cell, mEnvironment, mRendering.getOgreRenderer(), mMwRoot, mPhysics)); + + // adjust player + mCurrentCell = cell; + playerCellChange (cell, position); + + // Sky system + mWorld->adjustSky(); + + mCellChanged = true; + //currentRegion->name = ""; + } + + void Scene::changeToExteriorCell (const ESM::Position& position) + { + int x = 0; + int y = 0; + + mWorld->positionToIndex (position.pos[0], position.pos[1], x, y); + + changeCell (x, y, position, true); + } + + Ptr::CellStore* Scene::getCurrentCell () + { + return mCurrentCell; + } + + void Scene::markCellAsUnchanged() + { + mCellChanged = false; + } + +/*#include +#include +#include + +#include "../mwworld/class.hpp" +#include "../mwworld/ptr.hpp"*/ + +void Scene::insertCell(ESMS::CellStore &cell) +{ + // Loop through all references in the cell + insertCellRefList (cell.activators, cell); + insertCellRefList (cell.potions, cell); + insertCellRefList (cell.appas, cell); + insertCellRefList (cell.armors, cell); + insertCellRefList (cell.books, cell); + insertCellRefList (cell.clothes, cell); + insertCellRefList (cell.containers, cell); + insertCellRefList (cell.creatures, cell); + insertCellRefList (cell.doors, cell); + insertCellRefList (cell.ingreds, cell); + insertCellRefList (cell.creatureLists, cell); + insertCellRefList (cell.itemLists, cell); + insertCellRefList (cell.lights, cell); + insertCellRefList (cell.lockpicks, cell); + insertCellRefList (cell.miscItems, cell); + insertCellRefList (cell.npcs, cell); + insertCellRefList (cell.probes, cell); + insertCellRefList (cell.repairs, cell); + insertCellRefList (cell.statics, cell); + insertCellRefList (cell.weapons, cell); +} + +} diff --git a/apps/openmw/mwworld/backup/scene.hpp b/apps/openmw/mwworld/backup/scene.hpp new file mode 100644 index 000000000..e170f0153 --- /dev/null +++ b/apps/openmw/mwworld/backup/scene.hpp @@ -0,0 +1,106 @@ +#ifndef GAME_MWWORLD_SCENE_H +#define GAME_MWWORLD_SCENE_H + +#include +#include + +#include + +#include + +#include "physicssystem.hpp" + +#include "refdata.hpp" +#include "ptr.hpp" +#include "globals.hpp" +#include "../mwrender/renderingmanager.hpp" +#include + +namespace Ogre +{ + class Vector3; +} + +namespace ESM +{ + struct Position; +} + +namespace Files +{ + class Collections; +} + +namespace Render +{ + class OgreRenderer; +} + +namespace MWRender +{ + class SkyManager; + class CellRender; +} + +namespace MWWorld +{ + class Environment; + class Player; + + class Scene + { + + public: + + typedef std::map CellRenderCollection; + + private: + + //OEngine::Render::OgreRenderer& mRenderer; + Ogre::SceneNode *mMwRoot; + Ptr::CellStore *mCurrentCell; // the cell, the player is in + CellRenderCollection mActiveCells; + bool mCellChanged; + Environment& mEnvironment; + World *mWorld; + PhysicsSystem *mPhysics; + MWRender::RenderingManager& mRendering; + + void playerCellChange (Ptr::CellStore *cell, const ESM::Position& position, + bool adjustPlayerPos = true); + public: + + Scene (Environment& environment, World *world, MWRender::RenderingManager& rendering, Ogre::SceneNode *mwRoot, PhysicsSystem *physics); + + ~Scene(); + + void unloadCell (CellRenderCollection::iterator iter); + + void loadCell (Ptr::CellStore *cell, MWRender::CellRender *render); + + void changeCell (int X, int Y, const ESM::Position& position, bool adjustPlayerPos); + ///< Move from exterior to interior or from interior cell to a different + /// interior cell. + + Ptr::CellStore* getCurrentCell (); + + const CellRenderCollection& getActiveCells () const; + + bool hasCellChanged() const; + ///< Has the player moved to a different cell, since the last frame? + + void changeToInteriorCell (const std::string& cellName, const ESM::Position& position); + ///< Move to interior cell. + + void changeToExteriorCell (const ESM::Position& position); + ///< Move to exterior cell. + + void markCellAsUnchanged(); + +// std::string getFacedHandle(); + + void insertCell(ESMS::CellStore &cell); + }; +} + +#endif diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index 4f425ac65..56750eef0 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -49,7 +49,9 @@ namespace MWWorld void Scene::unloadCell (CellRenderCollection::iterator iter) { ListHandles functor; - iter->first->forEach(functor); + Ptr::CellStore* cellstore = *iter; + + cellstore->forEach(functor); { // silence annoying g++ warning for (std::vector::const_iterator iter (functor.mHandles.begin()); @@ -57,28 +59,24 @@ namespace MWWorld mPhysics->removeObject (*iter); } - mWorld->getLocalScripts().clearCell (iter->first); + mWorld->getLocalScripts().clearCell (cellstore); - mEnvironment.mMechanicsManager->dropActors (iter->first); - mEnvironment.mSoundManager->stopSound (iter->first); - delete iter->second; + mEnvironment.mMechanicsManager->dropActors (cellstore); + mEnvironment.mSoundManager->stopSound (cellstore); + //delete iter->second; mActiveCells.erase (iter); } - void Scene::loadCell (Ptr::CellStore *cell, MWRender::CellRender *render) + void Scene::loadCell (Ptr::CellStore *cell) { // register local scripts mWorld->getLocalScripts().addCell (cell); // This connects the cell data with the rendering scene. - std::pair result = - mActiveCells.insert (std::make_pair (cell, render)); - - if (result.second) - { - // Load the cell and insert it into the renderer - result.first->second->show(); - } + mActiveCells.push_back(cell); + + mRendering.getObjects().buildStaticGeometry(*cell); + } void Scene::playerCellChange (Ptr::CellStore *cell, const ESM::Position& position, @@ -99,16 +97,18 @@ namespace MWWorld mEnvironment.mMechanicsManager->removeActor (mWorld->getPlayer().getPlayer()); CellRenderCollection::iterator active = mActiveCells.begin(); - + Ptr::CellStore* cellstore = *active; + while (active!=mActiveCells.end()) { - if (!(active->first->cell->data.flags & ESM::Cell::Interior)) + if (!(cellstore->cell->data.flags & ESM::Cell::Interior)) { - if (std::abs (X-active->first->cell->data.gridX)<=1 && - std::abs (Y-active->first->cell->data.gridY)<=1) + if (std::abs (X-cellstore->cell->data.gridX)<=1 && + std::abs (Y-cellstore->cell->data.gridY)<=1) { // keep cells within the new 3x3 grid ++active; + cellstore = *active; continue; } } @@ -121,13 +121,14 @@ namespace MWWorld for (int y=Y-1; y<=Y+1; ++y) { CellRenderCollection::iterator iter = mActiveCells.begin(); + Ptr::CellStore* cellstore = *iter; while (iter!=mActiveCells.end()) { assert (!(iter->first->cell->data.flags & ESM::Cell::Interior)); - if (x==iter->first->cell->data.gridX && - y==iter->first->cell->data.gridY) + if (x==cellstore->cell->data.gridX && + y==cellstore->cell->data.gridY) break; ++iter; @@ -137,19 +138,20 @@ namespace MWWorld { Ptr::CellStore *cell = mWorld->getExterior(x, y); - loadCell (cell, new MWRender::ExteriorCellRender (*cell, mEnvironment, mRenderer, mMwRoot, mPhysics)); + loadCell (cell); } } // find current cell CellRenderCollection::iterator iter = mActiveCells.begin(); + cellstore = *active; while (iter!=mActiveCells.end()) { assert (!(iter->first->cell->data.flags & ESM::Cell::Interior)); - if (X==iter->first->cell->data.gridX && - Y==iter->first->cell->data.gridY) + if (X==cellstore->cell->data.gridX && + Y==cellstore->cell->data.gridY) break; ++iter; @@ -157,7 +159,7 @@ namespace MWWorld assert (iter!=mActiveCells.end()); - mCurrentCell = iter->first; + mCurrentCell = cellstore; // adjust player playerCellChange (mWorld->getExterior(X, Y), position, adjustPlayerPos); @@ -169,8 +171,8 @@ namespace MWWorld } //We need the ogre renderer and a scene node. - Scene::Scene (Environment& environment, World *world, OEngine::Render::OgreRenderer& renderer, Ogre::SceneNode *mwRoot, PhysicsSystem *physics) - : mRenderer(renderer), mCurrentCell (0), + Scene::Scene (Environment& environment, World *world, MWRender::RenderingManager& rendering, Ogre::SceneNode *mwRoot, PhysicsSystem *physics) + : mRendering(rendering), mCurrentCell (0), mCellChanged (false), mEnvironment (environment), mWorld(world), mPhysics(physics) { mMwRoot = mwRoot; @@ -178,9 +180,9 @@ namespace MWWorld Scene::~Scene() { - for (CellRenderCollection::iterator iter (mActiveCells.begin()); + /*for (CellRenderCollection::iterator iter (mActiveCells.begin()); iter!=mActiveCells.end(); ++iter) - delete iter->second; + delete iter->second;*/ } bool Scene::hasCellChanged() const @@ -207,7 +209,7 @@ namespace MWWorld std::cout << "cellName:" << cellName << std::endl; Ptr::CellStore *cell = mWorld->getInterior(cellName); - loadCell (cell, new MWRender::InteriorCellRender (*cell, mEnvironment, mRenderer, mMwRoot, mPhysics)); + loadCell (cell); // adjust player mCurrentCell = cell; diff --git a/apps/openmw/mwworld/scene.hpp b/apps/openmw/mwworld/scene.hpp index 6af86a071..f95c13370 100644 --- a/apps/openmw/mwworld/scene.hpp +++ b/apps/openmw/mwworld/scene.hpp @@ -52,30 +52,31 @@ namespace MWWorld public: - typedef std::map CellRenderCollection; + typedef std::list CellRenderCollection; private: - OEngine::Render::OgreRenderer& mRenderer; + //OEngine::Render::OgreRenderer& mRenderer; Ogre::SceneNode *mMwRoot; - Ptr::CellStore *mCurrentCell; // the cell, the player is in + Ptr::CellStore* mCurrentCell; // the cell, the player is in CellRenderCollection mActiveCells; bool mCellChanged; Environment& mEnvironment; World *mWorld; PhysicsSystem *mPhysics; + MWRender::RenderingManager& mRendering; void playerCellChange (Ptr::CellStore *cell, const ESM::Position& position, bool adjustPlayerPos = true); public: - Scene (Environment& environment, World *world, OEngine::Render::OgreRenderer& renderer, Ogre::SceneNode *mwRoot, PhysicsSystem *physics); + Scene (Environment& environment, World *world, MWRender::RenderingManager& rendering, Ogre::SceneNode *mwRoot, PhysicsSystem *physics); ~Scene(); void unloadCell (CellRenderCollection::iterator iter); - void loadCell (Ptr::CellStore *cell, MWRender::CellRender *render); + void loadCell (Ptr::CellStore *cell); void changeCell (int X, int Y, const ESM::Position& position, bool adjustPlayerPos); ///< Move from exterior to interior or from interior cell to a different diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index a4e909ffc..12a6d26fd 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -130,17 +130,20 @@ namespace MWWorld return Ptr(); } + /* MWRender::CellRender *World::searchRender (Ptr::CellStore *store) { - Scene::CellRenderCollection::const_iterator iter = mWorldScene->getActiveCells().find (store); - - if (iter!=mWorldScene->getActiveCells().end()) - { - return iter->second; - } + for (Scene::CellRenderCollection::const_iterator iter (mWorldScene->getActiveCells().begin()); + iter!=mWorldScene->getActiveCells().end(); ++iter) + { + Ptr::CellStore* cellstore = *iter; + if(store == cellstore){ + //return iter->second; + } + } return 0; - } + }*/ int World::getDaysPerMonth (int month) const { @@ -208,7 +211,7 @@ namespace MWWorld mPhysEngine = physEng; - mWorldScene = new Scene(environment, this, mRendering.getOgreRenderer(), mRendering.getRoot(), mPhysics); + mWorldScene = new Scene(environment, this, mRendering, mRendering.getRoot(), mPhysics); } @@ -308,7 +311,8 @@ namespace MWWorld for (Scene::CellRenderCollection::const_iterator iter (mWorldScene->getActiveCells().begin()); iter!=mWorldScene->getActiveCells().end(); ++iter) { - Ptr ptr = mCells.getPtr (name, *iter->first); + Ptr::CellStore* cellstore = *iter; + Ptr ptr = mCells.getPtr (name, *cellstore); if (!ptr.isEmpty()) return ptr; @@ -333,7 +337,8 @@ namespace MWWorld for (Scene::CellRenderCollection::const_iterator iter (mWorldScene->getActiveCells().begin()); iter!=mWorldScene->getActiveCells().end(); ++iter) { - Ptr ptr = getPtrViaHandle (handle, *iter->first); + Ptr::CellStore* cellstore = *iter; + Ptr ptr = getPtrViaHandle (handle, *cellstore); if (!ptr.isEmpty()) return ptr; @@ -348,13 +353,20 @@ namespace MWWorld { reference.getRefData().enable(); - if (MWRender::CellRender *render = searchRender (reference.getCell())) - { - render->enable (reference.getRefData().getHandle()); + + //render->enable (reference.getRefData().getHandle()); + for (Scene::CellRenderCollection::const_iterator iter (mWorldScene->getActiveCells().begin()); + iter!=mWorldScene->getActiveCells().end(); ++iter) + { + Ptr::CellStore* cellstore = *iter; + if(reference.getCell() == cellstore){ + Class::get (reference).enable (reference, mEnvironment); + break; + } + } - if (mWorldScene->getActiveCells().find (reference.getCell())!=mWorldScene->getActiveCells().end()) - Class::get (reference).enable (reference, mEnvironment); - } + + } } @@ -364,16 +376,20 @@ namespace MWWorld { reference.getRefData().disable(); - if (MWRender::CellRender *render = searchRender (reference.getCell())) - { - render->disable (reference.getRefData().getHandle()); - - if (mWorldScene->getActiveCells().find (reference.getCell())!=mWorldScene->getActiveCells().end()) + + //render->disable (reference.getRefData().getHandle()); + for (Scene::CellRenderCollection::const_iterator iter (mWorldScene->getActiveCells().begin()); + iter!=mWorldScene->getActiveCells().end(); ++iter) { - Class::get (reference).disable (reference, mEnvironment); - mEnvironment.mSoundManager->stopSound3D (reference); + Ptr::CellStore* cellstore = *iter; + if(reference.getCell() == cellstore){ + Class::get (reference).disable (reference, mEnvironment); + mEnvironment.mSoundManager->stopSound3D (reference); + break; + } } - } + + } } @@ -531,21 +547,26 @@ namespace MWWorld { ptr.getRefData().setCount (0); - if (MWRender::CellRender *render = searchRender (ptr.getCell())) - { - if (mWorldScene->getActiveCells().find (ptr.getCell())!=mWorldScene->getActiveCells().end()) + + for (Scene::CellRenderCollection::const_iterator iter (mWorldScene->getActiveCells().begin()); + iter!=mWorldScene->getActiveCells().end(); ++iter) { - Class::get (ptr).disable (ptr, mEnvironment); - mEnvironment.mSoundManager->stopSound3D (ptr); + Ptr::CellStore* cellstore = *iter; + if(ptr.getCell() == cellstore){ + Class::get (ptr).disable (ptr, mEnvironment); + mEnvironment.mSoundManager->stopSound3D (ptr); - mPhysics->removeObject (ptr.getRefData().getHandle()); + mPhysics->removeObject (ptr.getRefData().getHandle()); - mLocalScripts.remove (ptr); + mLocalScripts.remove (ptr); + break; + } } + - render->deleteObject (ptr.getRefData().getHandle()); - ptr.getRefData().setHandle (""); - } + //Should this go here or inside the for loop? + mRendering.getObjects().deleteObject (ptr.getRefData().getHandle()); + ptr.getRefData().setBaseNode(0); } } diff --git a/apps/openmw/mwworld/world.hpp b/apps/openmw/mwworld/world.hpp index ca1759e00..4a26fd11a 100644 --- a/apps/openmw/mwworld/world.hpp +++ b/apps/openmw/mwworld/world.hpp @@ -88,7 +88,7 @@ namespace MWWorld Ptr getPtrViaHandle (const std::string& handle, Ptr::CellStore& cellStore); - MWRender::CellRender *searchRender (Ptr::CellStore *store); + //MWRender::CellRender *searchRender (Ptr::CellStore *store); int getDaysPerMonth (int month) const; From bc06d13d309c40dda73f1fe524472169ff38c237 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Sun, 13 Nov 2011 23:17:56 -0500 Subject: [PATCH 044/104] Removing backups --- apps/openmw/mwworld/backup/scene.cpp | 275 --------------------------- apps/openmw/mwworld/backup/scene.hpp | 106 ----------- 2 files changed, 381 deletions(-) delete mode 100644 apps/openmw/mwworld/backup/scene.cpp delete mode 100644 apps/openmw/mwworld/backup/scene.hpp diff --git a/apps/openmw/mwworld/backup/scene.cpp b/apps/openmw/mwworld/backup/scene.cpp deleted file mode 100644 index 93b4a80f4..000000000 --- a/apps/openmw/mwworld/backup/scene.cpp +++ /dev/null @@ -1,275 +0,0 @@ -#include "scene.hpp" -#include "world.hpp" - -#include "../mwrender/interior.hpp" -#include "../mwrender/exterior.hpp" - -#include "../mwmechanics/mechanicsmanager.hpp" - -#include "../mwsound/soundmanager.hpp" - -#include "ptr.hpp" -#include "environment.hpp" -#include "player.hpp" -#include "class.hpp" - -#include "cellfunctors.hpp" - -namespace { - -template -void insertCellRefList (T& cellRefList, ESMS::CellStore &cell) -{ - if (!cellRefList.list.empty()) - { - //const MWWorld::Class& class_ = MWWorld::Class::get (MWWorld::Ptr (&*cellRefList.list.begin(), &cell)); - - for (typename T::List::iterator it = cellRefList.list.begin(); - it != cellRefList.list.end(); it++) - { - if (it->mData.getCount() || it->mData.isEnabled()) - { - MWWorld::Ptr ptr (&*it, &cell); - /* TODO: call - * RenderingManager.insertObject - * class_.insertObjectPhysic - * class_.insertObjectMechanics - */ - } - } - } -} - -} - - -namespace MWWorld -{ - - void Scene::unloadCell (CellRenderCollection::iterator iter) - { - ListHandles functor; - iter->first->forEach(functor); - - { // silence annoying g++ warning - for (std::vector::const_iterator iter (functor.mHandles.begin()); - iter!=functor.mHandles.end(); ++iter) - mPhysics->removeObject (*iter); - } - - mWorld->getLocalScripts().clearCell (iter->first); - - mEnvironment.mMechanicsManager->dropActors (iter->first); - mEnvironment.mSoundManager->stopSound (iter->first); - delete iter->second; - mActiveCells.erase (iter); - } - - void Scene::loadCell (Ptr::CellStore *cell, MWRender::CellRender *render) - { - // register local scripts - mWorld->getLocalScripts().addCell (cell); - - // This connects the cell data with the rendering scene. - std::pair result = - mActiveCells.insert (std::make_pair (cell, render)); - - if (result.second) - { - // Load the cell and insert it into the renderer - result.first->second->show(); - } - } - - void Scene::playerCellChange (Ptr::CellStore *cell, const ESM::Position& position, - bool adjustPlayerPos) - { - if (adjustPlayerPos) - mWorld->getPlayer().setPos (position.pos[0], position.pos[1], position.pos[2]); - - mWorld->getPlayer().setCell (cell); - // TODO orientation - mEnvironment.mMechanicsManager->addActor (mWorld->getPlayer().getPlayer()); - mEnvironment.mMechanicsManager->watchActor (mWorld->getPlayer().getPlayer()); - } - - void Scene::changeCell (int X, int Y, const ESM::Position& position, bool adjustPlayerPos) - { - // remove active - mEnvironment.mMechanicsManager->removeActor (mWorld->getPlayer().getPlayer()); - - CellRenderCollection::iterator active = mActiveCells.begin(); - - while (active!=mActiveCells.end()) - { - if (!(active->first->cell->data.flags & ESM::Cell::Interior)) - { - if (std::abs (X-active->first->cell->data.gridX)<=1 && - std::abs (Y-active->first->cell->data.gridY)<=1) - { - // keep cells within the new 3x3 grid - ++active; - continue; - } - } - - unloadCell (active++); - } - - // Load cells - for (int x=X-1; x<=X+1; ++x) - for (int y=Y-1; y<=Y+1; ++y) - { - CellRenderCollection::iterator iter = mActiveCells.begin(); - - while (iter!=mActiveCells.end()) - { - assert (!(iter->first->cell->data.flags & ESM::Cell::Interior)); - - if (x==iter->first->cell->data.gridX && - y==iter->first->cell->data.gridY) - break; - - ++iter; - } - - if (iter==mActiveCells.end()) - { - Ptr::CellStore *cell = mWorld->getExterior(x, y); - - loadCell (cell, new MWRender::ExteriorCellRender (*cell, mEnvironment, mRendering.getOgreRenderer(), mMwRoot, mPhysics)); - } - } - - // find current cell - CellRenderCollection::iterator iter = mActiveCells.begin(); - - while (iter!=mActiveCells.end()) - { - assert (!(iter->first->cell->data.flags & ESM::Cell::Interior)); - - if (X==iter->first->cell->data.gridX && - Y==iter->first->cell->data.gridY) - break; - - ++iter; - } - - assert (iter!=mActiveCells.end()); - - mCurrentCell = iter->first; - - // adjust player - playerCellChange (mWorld->getExterior(X, Y), position, adjustPlayerPos); - - // Sky system - mWorld->adjustSky(); - - mCellChanged = true; - } - - //We need the ogre renderer and a scene node. - Scene::Scene (Environment& environment, World *world, MWRender::RenderingManager& rendering, Ogre::SceneNode *mwRoot, PhysicsSystem *physics) - : mRendering(rendering), mCurrentCell (0), - mCellChanged (false), mEnvironment (environment), mWorld(world), mPhysics(physics) - { - mMwRoot = mwRoot; - } - - Scene::~Scene() - { - for (CellRenderCollection::iterator iter (mActiveCells.begin()); - iter!=mActiveCells.end(); ++iter) - delete iter->second; - } - - bool Scene::hasCellChanged() const - { - return mCellChanged; - } - - const Scene::CellRenderCollection& Scene::getActiveCells() const - { - return mActiveCells; - } - - void Scene::changeToInteriorCell (const std::string& cellName, const ESM::Position& position) - { - // remove active - CellRenderCollection::iterator active = mActiveCells.begin(); - - while (active!=mActiveCells.end()) - { - unloadCell (active++); - } - - // Load cell. - std::cout << "cellName:" << cellName << std::endl; - Ptr::CellStore *cell = mWorld->getInterior(cellName); - - loadCell (cell, new MWRender::InteriorCellRender (*cell, mEnvironment, mRendering.getOgreRenderer(), mMwRoot, mPhysics)); - - // adjust player - mCurrentCell = cell; - playerCellChange (cell, position); - - // Sky system - mWorld->adjustSky(); - - mCellChanged = true; - //currentRegion->name = ""; - } - - void Scene::changeToExteriorCell (const ESM::Position& position) - { - int x = 0; - int y = 0; - - mWorld->positionToIndex (position.pos[0], position.pos[1], x, y); - - changeCell (x, y, position, true); - } - - Ptr::CellStore* Scene::getCurrentCell () - { - return mCurrentCell; - } - - void Scene::markCellAsUnchanged() - { - mCellChanged = false; - } - -/*#include -#include -#include - -#include "../mwworld/class.hpp" -#include "../mwworld/ptr.hpp"*/ - -void Scene::insertCell(ESMS::CellStore &cell) -{ - // Loop through all references in the cell - insertCellRefList (cell.activators, cell); - insertCellRefList (cell.potions, cell); - insertCellRefList (cell.appas, cell); - insertCellRefList (cell.armors, cell); - insertCellRefList (cell.books, cell); - insertCellRefList (cell.clothes, cell); - insertCellRefList (cell.containers, cell); - insertCellRefList (cell.creatures, cell); - insertCellRefList (cell.doors, cell); - insertCellRefList (cell.ingreds, cell); - insertCellRefList (cell.creatureLists, cell); - insertCellRefList (cell.itemLists, cell); - insertCellRefList (cell.lights, cell); - insertCellRefList (cell.lockpicks, cell); - insertCellRefList (cell.miscItems, cell); - insertCellRefList (cell.npcs, cell); - insertCellRefList (cell.probes, cell); - insertCellRefList (cell.repairs, cell); - insertCellRefList (cell.statics, cell); - insertCellRefList (cell.weapons, cell); -} - -} diff --git a/apps/openmw/mwworld/backup/scene.hpp b/apps/openmw/mwworld/backup/scene.hpp deleted file mode 100644 index e170f0153..000000000 --- a/apps/openmw/mwworld/backup/scene.hpp +++ /dev/null @@ -1,106 +0,0 @@ -#ifndef GAME_MWWORLD_SCENE_H -#define GAME_MWWORLD_SCENE_H - -#include -#include - -#include - -#include - -#include "physicssystem.hpp" - -#include "refdata.hpp" -#include "ptr.hpp" -#include "globals.hpp" -#include "../mwrender/renderingmanager.hpp" -#include - -namespace Ogre -{ - class Vector3; -} - -namespace ESM -{ - struct Position; -} - -namespace Files -{ - class Collections; -} - -namespace Render -{ - class OgreRenderer; -} - -namespace MWRender -{ - class SkyManager; - class CellRender; -} - -namespace MWWorld -{ - class Environment; - class Player; - - class Scene - { - - public: - - typedef std::map CellRenderCollection; - - private: - - //OEngine::Render::OgreRenderer& mRenderer; - Ogre::SceneNode *mMwRoot; - Ptr::CellStore *mCurrentCell; // the cell, the player is in - CellRenderCollection mActiveCells; - bool mCellChanged; - Environment& mEnvironment; - World *mWorld; - PhysicsSystem *mPhysics; - MWRender::RenderingManager& mRendering; - - void playerCellChange (Ptr::CellStore *cell, const ESM::Position& position, - bool adjustPlayerPos = true); - public: - - Scene (Environment& environment, World *world, MWRender::RenderingManager& rendering, Ogre::SceneNode *mwRoot, PhysicsSystem *physics); - - ~Scene(); - - void unloadCell (CellRenderCollection::iterator iter); - - void loadCell (Ptr::CellStore *cell, MWRender::CellRender *render); - - void changeCell (int X, int Y, const ESM::Position& position, bool adjustPlayerPos); - ///< Move from exterior to interior or from interior cell to a different - /// interior cell. - - Ptr::CellStore* getCurrentCell (); - - const CellRenderCollection& getActiveCells () const; - - bool hasCellChanged() const; - ///< Has the player moved to a different cell, since the last frame? - - void changeToInteriorCell (const std::string& cellName, const ESM::Position& position); - ///< Move to interior cell. - - void changeToExteriorCell (const ESM::Position& position); - ///< Move to exterior cell. - - void markCellAsUnchanged(); - -// std::string getFacedHandle(); - - void insertCell(ESMS::CellStore &cell); - }; -} - -#endif From 58f103a75c604b7b4a6154b16d1b7309c39d1ff4 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Tue, 15 Nov 2011 23:31:18 -0500 Subject: [PATCH 045/104] Adding new insertCellRefList;Collection switched to a set --- apps/openmw/mwworld/scene.cpp | 88 +++++++++++++++++++++++++++++------ apps/openmw/mwworld/scene.hpp | 14 ++++-- apps/openmw/mwworld/world.cpp | 57 +++++------------------ apps/openmw/mwworld/world.hpp | 7 +-- 4 files changed, 98 insertions(+), 68 deletions(-) diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index 56750eef0..1dbe1f821 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -17,6 +17,8 @@ namespace { + + template void insertCellRefList (T& cellRefList, ESMS::CellStore &cell) { @@ -37,6 +39,38 @@ void insertCellRefList (T& cellRefList, ESMS::CellStore &cell) */ } } + } +} +template +void insertCellRefList(MWRender::RenderingManager& rendering, MWWorld::Environment& environment, + T& cellRefList, ESMS::CellStore &cell, MWWorld::PhysicsSystem& physics) +{ + if (!cellRefList.list.empty()) + { + const MWWorld::Class& class_ = + MWWorld::Class::get (MWWorld::Ptr (&*cellRefList.list.begin(), &cell)); + + for (typename T::List::iterator it = cellRefList.list.begin(); + it != cellRefList.list.end(); it++) + { + if (it->mData.getCount() || it->mData.isEnabled()) + { + MWWorld::Ptr ptr (&*it, &cell); + + try + { + + class_.insertObjectRendering(ptr, rendering); + class_.insertObject(ptr, physics, environment); + class_.enable (ptr, environment); + } + catch (const std::exception& e) + { + std::string error ("error during rendering: "); + std::cerr << error + e.what() << std::endl; + } + } + } } } @@ -46,11 +80,11 @@ void insertCellRefList (T& cellRefList, ESMS::CellStore &cell) namespace MWWorld { - void Scene::unloadCell (CellRenderCollection::iterator iter) + void Scene::unloadCell (CellStoreCollection::iterator iter) { ListHandles functor; Ptr::CellStore* cellstore = *iter; - + cellstore->forEach(functor); { // silence annoying g++ warning @@ -73,9 +107,10 @@ namespace MWWorld mWorld->getLocalScripts().addCell (cell); // This connects the cell data with the rendering scene. - mActiveCells.push_back(cell); + mActiveCells.insert(cell); mRendering.getObjects().buildStaticGeometry(*cell); + insertCell(*cell, mEnvironment); } @@ -96,7 +131,7 @@ namespace MWWorld // remove active mEnvironment.mMechanicsManager->removeActor (mWorld->getPlayer().getPlayer()); - CellRenderCollection::iterator active = mActiveCells.begin(); + CellStoreCollection::iterator active = mActiveCells.begin(); Ptr::CellStore* cellstore = *active; while (active!=mActiveCells.end()) @@ -120,12 +155,12 @@ namespace MWWorld for (int x=X-1; x<=X+1; ++x) for (int y=Y-1; y<=Y+1; ++y) { - CellRenderCollection::iterator iter = mActiveCells.begin(); + CellStoreCollection::iterator iter = mActiveCells.begin(); Ptr::CellStore* cellstore = *iter; while (iter!=mActiveCells.end()) { - assert (!(iter->first->cell->data.flags & ESM::Cell::Interior)); + assert (!(cellstore->cell->data.flags & ESM::Cell::Interior)); if (x==cellstore->cell->data.gridX && y==cellstore->cell->data.gridY) @@ -143,7 +178,7 @@ namespace MWWorld } // find current cell - CellRenderCollection::iterator iter = mActiveCells.begin(); + CellStoreCollection::iterator iter = mActiveCells.begin(); cellstore = *active; while (iter!=mActiveCells.end()) @@ -171,18 +206,14 @@ namespace MWWorld } //We need the ogre renderer and a scene node. - Scene::Scene (Environment& environment, World *world, MWRender::RenderingManager& rendering, Ogre::SceneNode *mwRoot, PhysicsSystem *physics) + Scene::Scene (Environment& environment, World *world, MWRender::RenderingManager& rendering, PhysicsSystem *physics) : mRendering(rendering), mCurrentCell (0), mCellChanged (false), mEnvironment (environment), mWorld(world), mPhysics(physics) { - mMwRoot = mwRoot; } Scene::~Scene() { - /*for (CellRenderCollection::iterator iter (mActiveCells.begin()); - iter!=mActiveCells.end(); ++iter) - delete iter->second;*/ } bool Scene::hasCellChanged() const @@ -190,7 +221,7 @@ namespace MWWorld return mCellChanged; } - const Scene::CellRenderCollection& Scene::getActiveCells() const + const Scene::CellStoreCollection& Scene::getActiveCells() const { return mActiveCells; } @@ -198,7 +229,7 @@ namespace MWWorld void Scene::changeToInteriorCell (const std::string& cellName, const ESM::Position& position) { // remove active - CellRenderCollection::iterator active = mActiveCells.begin(); + CellStoreCollection::iterator active = mActiveCells.begin(); while (active!=mActiveCells.end()) { @@ -271,7 +302,34 @@ void Scene::insertCell(ESMS::CellStore &cell) insertCellRefList (cell.probes, cell); insertCellRefList (cell.repairs, cell); insertCellRefList (cell.statics, cell); - insertCellRefList (cell.weapons, cell); + insertCellRefList(cell.weapons, cell); +} + +void Scene::insertCell(ESMS::CellStore &cell, + MWWorld::Environment& environment) +{ + // Loop through all references in the cell + insertCellRefList(mRendering, environment, cell.activators, cell, *mPhysics); + insertCellRefList(mRendering, environment, cell.potions, cell, *mPhysics); + insertCellRefList(mRendering, environment, cell.appas, cell, *mPhysics); + insertCellRefList(mRendering, environment, cell.armors, cell, *mPhysics); + insertCellRefList(mRendering, environment, cell.books, cell, *mPhysics); + insertCellRefList(mRendering, environment, cell.clothes, cell, *mPhysics); + insertCellRefList(mRendering, environment, cell.containers, cell, *mPhysics); + insertCellRefList(mRendering, environment, cell.creatures, cell, *mPhysics); + insertCellRefList(mRendering, environment, cell.doors, cell, *mPhysics); + insertCellRefList(mRendering, environment, cell.ingreds, cell, *mPhysics); + insertCellRefList(mRendering, environment, cell.creatureLists, cell, *mPhysics); + insertCellRefList(mRendering, environment, cell.itemLists, cell, *mPhysics); + insertCellRefList(mRendering, environment, cell.lights, cell, *mPhysics); + insertCellRefList(mRendering, environment, cell.lockpicks, cell, *mPhysics); + insertCellRefList(mRendering, environment, cell.miscItems, cell, *mPhysics); + insertCellRefList(mRendering, environment, cell.npcs, cell, *mPhysics); + insertCellRefList(mRendering, environment, cell.probes, cell, *mPhysics); + insertCellRefList(mRendering, environment, cell.repairs, cell, *mPhysics); + insertCellRefList(mRendering, environment, cell.statics, cell, *mPhysics); + insertCellRefList(mRendering, environment, cell.weapons, cell, *mPhysics); } + } diff --git a/apps/openmw/mwworld/scene.hpp b/apps/openmw/mwworld/scene.hpp index f95c13370..c5183b58c 100644 --- a/apps/openmw/mwworld/scene.hpp +++ b/apps/openmw/mwworld/scene.hpp @@ -14,6 +14,7 @@ #include "ptr.hpp" #include "globals.hpp" #include "../mwrender/renderingmanager.hpp" +#include "../mwrender/renderinginterface.hpp" #include namespace Ogre @@ -52,14 +53,14 @@ namespace MWWorld public: - typedef std::list CellRenderCollection; + typedef std::set CellStoreCollection; private: //OEngine::Render::OgreRenderer& mRenderer; Ogre::SceneNode *mMwRoot; Ptr::CellStore* mCurrentCell; // the cell, the player is in - CellRenderCollection mActiveCells; + CellStoreCollection mActiveCells; bool mCellChanged; Environment& mEnvironment; World *mWorld; @@ -68,13 +69,15 @@ namespace MWWorld void playerCellChange (Ptr::CellStore *cell, const ESM::Position& position, bool adjustPlayerPos = true); + + public: - Scene (Environment& environment, World *world, MWRender::RenderingManager& rendering, Ogre::SceneNode *mwRoot, PhysicsSystem *physics); + Scene (Environment& environment, World *world, MWRender::RenderingManager& rendering, PhysicsSystem *physics); ~Scene(); - void unloadCell (CellRenderCollection::iterator iter); + void unloadCell (CellStoreCollection::iterator iter); void loadCell (Ptr::CellStore *cell); @@ -84,7 +87,7 @@ namespace MWWorld Ptr::CellStore* getCurrentCell (); - const CellRenderCollection& getActiveCells () const; + const CellStoreCollection& getActiveCells () const; bool hasCellChanged() const; ///< Has the player moved to a different cell, since the last frame? @@ -100,6 +103,7 @@ namespace MWWorld // std::string getFacedHandle(); void insertCell(ESMS::CellStore &cell); + void insertCell(ESMS::CellStore &cell, MWWorld::Environment& environment); }; } diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index 12a6d26fd..3993468c0 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -130,20 +130,6 @@ namespace MWWorld return Ptr(); } - /* - MWRender::CellRender *World::searchRender (Ptr::CellStore *store) - { - for (Scene::CellRenderCollection::const_iterator iter (mWorldScene->getActiveCells().begin()); - iter!=mWorldScene->getActiveCells().end(); ++iter) - { - Ptr::CellStore* cellstore = *iter; - if(store == cellstore){ - //return iter->second; - } - } - - return 0; - }*/ int World::getDaysPerMonth (int month) const { @@ -211,7 +197,7 @@ namespace MWWorld mPhysEngine = physEng; - mWorldScene = new Scene(environment, this, mRendering, mRendering.getRoot(), mPhysics); + mWorldScene = new Scene(environment, this, mRendering, mPhysics); } @@ -308,7 +294,7 @@ namespace MWWorld } // active cells - for (Scene::CellRenderCollection::const_iterator iter (mWorldScene->getActiveCells().begin()); + for (Scene::CellStoreCollection::const_iterator iter (mWorldScene->getActiveCells().begin()); iter!=mWorldScene->getActiveCells().end(); ++iter) { Ptr::CellStore* cellstore = *iter; @@ -334,7 +320,7 @@ namespace MWWorld if (mPlayer->getPlayer().getRefData().getHandle()==handle) return mPlayer->getPlayer(); - for (Scene::CellRenderCollection::const_iterator iter (mWorldScene->getActiveCells().begin()); + for (Scene::CellStoreCollection::const_iterator iter (mWorldScene->getActiveCells().begin()); iter!=mWorldScene->getActiveCells().end(); ++iter) { Ptr::CellStore* cellstore = *iter; @@ -355,17 +341,9 @@ namespace MWWorld //render->enable (reference.getRefData().getHandle()); - for (Scene::CellRenderCollection::const_iterator iter (mWorldScene->getActiveCells().begin()); - iter!=mWorldScene->getActiveCells().end(); ++iter) - { - Ptr::CellStore* cellstore = *iter; - if(reference.getCell() == cellstore){ - Class::get (reference).enable (reference, mEnvironment); - break; - } - } - - + if(mWorldScene->getActiveCells().find (reference.getCell()) != mWorldScene->getActiveCells().end()) + Class::get (reference).enable (reference, mEnvironment); + } } @@ -378,16 +356,10 @@ namespace MWWorld //render->disable (reference.getRefData().getHandle()); - for (Scene::CellRenderCollection::const_iterator iter (mWorldScene->getActiveCells().begin()); - iter!=mWorldScene->getActiveCells().end(); ++iter) - { - Ptr::CellStore* cellstore = *iter; - if(reference.getCell() == cellstore){ - Class::get (reference).disable (reference, mEnvironment); - mEnvironment.mSoundManager->stopSound3D (reference); - break; - } - } + if(mWorldScene->getActiveCells().find (reference.getCell())!=mWorldScene->getActiveCells().end()){ + Class::get (reference).disable (reference, mEnvironment); + mEnvironment.mSoundManager->stopSound3D (reference); + } } @@ -548,19 +520,14 @@ namespace MWWorld ptr.getRefData().setCount (0); - for (Scene::CellRenderCollection::const_iterator iter (mWorldScene->getActiveCells().begin()); - iter!=mWorldScene->getActiveCells().end(); ++iter) - { - Ptr::CellStore* cellstore = *iter; - if(ptr.getCell() == cellstore){ + if (mWorldScene->getActiveCells().find (ptr.getCell())!=mWorldScene->getActiveCells().end()){ Class::get (ptr).disable (ptr, mEnvironment); mEnvironment.mSoundManager->stopSound3D (ptr); mPhysics->removeObject (ptr.getRefData().getHandle()); + mRendering.removeObject(ptr); mLocalScripts.remove (ptr); - break; - } } diff --git a/apps/openmw/mwworld/world.hpp b/apps/openmw/mwworld/world.hpp index 4a26fd11a..ea775453a 100644 --- a/apps/openmw/mwworld/world.hpp +++ b/apps/openmw/mwworld/world.hpp @@ -88,7 +88,6 @@ namespace MWWorld Ptr getPtrViaHandle (const std::string& handle, Ptr::CellStore& cellStore); - //MWRender::CellRender *searchRender (Ptr::CellStore *store); int getDaysPerMonth (int month) const; @@ -133,9 +132,11 @@ namespace MWWorld Ptr getPtrViaHandle (const std::string& handle); ///< Return a pointer to a liveCellRef with the given Ogre handle. - + + /// \todo enable reference in the OGRE scene void enable (Ptr reference); - + + /// \todo 5disable reference in the OGRE scene void disable (Ptr reference); void advanceTime (double hours); From 9b94074472c5236eff0a2fdfcffe7e62748f7937 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Wed, 16 Nov 2011 16:22:13 -0500 Subject: [PATCH 046/104] addObject --- apps/openmw/mwrender/renderingmanager.cpp | 4 +++- apps/openmw/mwrender/renderingmanager.hpp | 2 +- apps/openmw/mwworld/scene.cpp | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index 2a502279d..1a4aee3c7 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -84,7 +84,9 @@ void RenderingManager::removeCell (MWWorld::Ptr::CellStore *store){ } void RenderingManager::addObject (const MWWorld::Ptr& ptr){ - + const MWWorld::Class& class_ = + MWWorld::Class::get (ptr); + class_.insertObjectRendering(ptr, *this); } void RenderingManager::removeObject (const MWWorld::Ptr& ptr){ diff --git a/apps/openmw/mwrender/renderingmanager.hpp b/apps/openmw/mwrender/renderingmanager.hpp index 9e1f86372..4e51442bd 100644 --- a/apps/openmw/mwrender/renderingmanager.hpp +++ b/apps/openmw/mwrender/renderingmanager.hpp @@ -6,7 +6,7 @@ #include "debugging.hpp" //Commented out for now, possibly do an ifdef if necessary, cla - +#include "../mwworld/class.hpp" #include #include diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index 1dbe1f821..d07f9eb16 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -60,7 +60,7 @@ void insertCellRefList(MWRender::RenderingManager& rendering, MWWorld::Environme try { - class_.insertObjectRendering(ptr, rendering); + rendering.addObject(ptr); class_.insertObject(ptr, physics, environment); class_.enable (ptr, environment); } From a0947cd432a5fd64ed3d949fb8c089a2c370491f Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Wed, 16 Nov 2011 21:15:49 -0500 Subject: [PATCH 047/104] Player handle changed;Interior removed;Exterior removed;Cellimp removed; Probe fixed --- apps/openmw/CMakeLists.txt | 2 +- apps/openmw/mwclass/probe.cpp | 11 +- apps/openmw/mwclass/probe.hpp | 2 +- apps/openmw/mwclass/static.cpp | 1 - apps/openmw/mwrender/cellimp.cpp | 67 ---- apps/openmw/mwrender/cellimp.hpp | 95 ----- apps/openmw/mwrender/exterior.cpp | 455 ---------------------- apps/openmw/mwrender/exterior.hpp | 139 ------- apps/openmw/mwrender/interior.cpp | 409 ------------------- apps/openmw/mwrender/interior.hpp | 133 ------- apps/openmw/mwrender/player.cpp | 4 +- apps/openmw/mwrender/player.hpp | 8 +- apps/openmw/mwrender/renderingmanager.cpp | 2 +- apps/openmw/mwworld/player.cpp | 3 +- apps/openmw/mwworld/scene.cpp | 2 - apps/openmw/mwworld/world.cpp | 2 - 16 files changed, 21 insertions(+), 1314 deletions(-) delete mode 100644 apps/openmw/mwrender/cellimp.cpp delete mode 100644 apps/openmw/mwrender/cellimp.hpp delete mode 100644 apps/openmw/mwrender/exterior.cpp delete mode 100644 apps/openmw/mwrender/exterior.hpp delete mode 100644 apps/openmw/mwrender/interior.cpp delete mode 100644 apps/openmw/mwrender/interior.hpp diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index 3608cbf14..e17a2cb25 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -16,7 +16,7 @@ set(GAME_HEADER source_group(game FILES ${GAME} ${GAME_HEADER}) add_openmw_dir (mwrender - renderingmanager debugging cellimp interior exterior sky player npcs creatures objects renderinginterface + renderingmanager debugging sky player npcs creatures objects renderinginterface ) add_openmw_dir (mwinput diff --git a/apps/openmw/mwclass/probe.cpp b/apps/openmw/mwclass/probe.cpp index 59d836446..72bdd292c 100644 --- a/apps/openmw/mwclass/probe.cpp +++ b/apps/openmw/mwclass/probe.cpp @@ -8,9 +8,8 @@ #include "../mwworld/ptr.hpp" #include "../mwworld/actiontake.hpp" -#include "../mwrender/cellimp.hpp" - #include "containerutil.hpp" +#include "../mwrender/objects.hpp" namespace MWClass { @@ -44,6 +43,14 @@ namespace MWClass } + + std::string Probe::getName (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->name; + } boost::shared_ptr Probe::activate (const MWWorld::Ptr& ptr, const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const { diff --git a/apps/openmw/mwclass/probe.hpp b/apps/openmw/mwclass/probe.hpp index d3495bb48..d7b9df738 100644 --- a/apps/openmw/mwclass/probe.hpp +++ b/apps/openmw/mwclass/probe.hpp @@ -2,7 +2,7 @@ #define GAME_MWCLASS_PROBE_H #include "../mwworld/class.hpp" -#include "../mwrender/objects.hpp" + namespace MWClass { diff --git a/apps/openmw/mwclass/static.cpp b/apps/openmw/mwclass/static.cpp index 372606ace..cdbd3bfe9 100644 --- a/apps/openmw/mwclass/static.cpp +++ b/apps/openmw/mwclass/static.cpp @@ -5,7 +5,6 @@ #include "../mwworld/ptr.hpp" -#include "../mwrender/cellimp.hpp" namespace MWClass { diff --git a/apps/openmw/mwrender/cellimp.cpp b/apps/openmw/mwrender/cellimp.cpp deleted file mode 100644 index 887941f05..000000000 --- a/apps/openmw/mwrender/cellimp.cpp +++ /dev/null @@ -1,67 +0,0 @@ -#include "cellimp.hpp" - -#include -#include -#include - -#include "../mwworld/class.hpp" -#include "../mwworld/ptr.hpp" - -using namespace MWRender; - -template -void insertCellRefList (CellRenderImp& cellRender, MWWorld::Environment& environment, - T& cellRefList, ESMS::CellStore &cell) -{ - if (!cellRefList.list.empty()) - { - const MWWorld::Class& class_ = - MWWorld::Class::get (MWWorld::Ptr (&*cellRefList.list.begin(), &cell)); - - for (typename T::List::iterator it = cellRefList.list.begin(); - it != cellRefList.list.end(); it++) - { - if (it->mData.getCount() || it->mData.isEnabled()) - { - MWWorld::Ptr ptr (&*it, &cell); - - try - { - class_.insertObj (ptr, cellRender, environment); - class_.enable (ptr, environment); - } - catch (const std::exception& e) - { - std::string error ("error during rendering: "); - std::cerr << error + e.what() << std::endl; - } - } - } - } -} - -void CellRenderImp::insertCell(ESMS::CellStore &cell, - MWWorld::Environment& environment) -{ - // Loop through all references in the cell - insertCellRefList (*this, environment, cell.activators, cell); - insertCellRefList (*this, environment, cell.potions, cell); - insertCellRefList (*this, environment, cell.appas, cell); - insertCellRefList (*this, environment, cell.armors, cell); - insertCellRefList (*this, environment, cell.books, cell); - insertCellRefList (*this, environment, cell.clothes, cell); - insertCellRefList (*this, environment, cell.containers, cell); - insertCellRefList (*this, environment, cell.creatures, cell); - insertCellRefList (*this, environment, cell.doors, cell); - insertCellRefList (*this, environment, cell.ingreds, cell); - insertCellRefList (*this, environment, cell.creatureLists, cell); - insertCellRefList (*this, environment, cell.itemLists, cell); - insertCellRefList (*this, environment, cell.lights, cell); - insertCellRefList (*this, environment, cell.lockpicks, cell); - insertCellRefList (*this, environment, cell.miscItems, cell); - insertCellRefList (*this, environment, cell.npcs, cell); - insertCellRefList (*this, environment, cell.probes, cell); - insertCellRefList (*this, environment, cell.repairs, cell); - insertCellRefList (*this, environment, cell.statics, cell); - insertCellRefList (*this, environment, cell.weapons, cell); -} diff --git a/apps/openmw/mwrender/cellimp.hpp b/apps/openmw/mwrender/cellimp.hpp deleted file mode 100644 index c497b1d19..000000000 --- a/apps/openmw/mwrender/cellimp.hpp +++ /dev/null @@ -1,95 +0,0 @@ -#ifndef _GAME_RENDER_CELLIMP_H -#define _GAME_RENDER_CELLIMP_H - -#include - -#include "components/esm_store/cell_store.hpp" - -#include "../mwworld/refdata.hpp" -#include - -namespace Ogre -{ - class SceneNode; - class Vector3; -} - -namespace ESM -{ - class CellRef; -} - -namespace MWWorld -{ - class Environment; -} -namespace MWRender -{ - /// Base class for cell render, that implements inserting references into a cell in a - /// cell type- and render-engine-independent way. - - class CellRenderImp - { - public: - CellRenderImp() {} - virtual ~CellRenderImp() {} - - /// start inserting a new reference. - virtual void insertBegin (ESM::CellRef& ref, MWWorld::RefData& refData, bool static_ = false) = 0; - - virtual void rotateMesh(Ogre::Vector3 axis, Ogre::Radian angle, std::string sceneNodeName[], int elements) = 0; - /// insert a mesh related to the most recent insertBegin call. - 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 void scaleMesh(Ogre::Vector3 axis, std::string sceneNodeName[], int elements) = 0; - - virtual void insertObjectPhysics() = 0; - - virtual void insertActorPhysics() = 0; - - /// insert a light related to the most recent insertBegin call. - virtual void insertLight(float r, float g, float b, float radius) = 0; - - /// finish inserting a new reference and return a handle to it. - virtual std::string insertEnd (bool Enable) = 0; - - void insertCell(ESMS::CellStore &cell, MWWorld::Environment& environment); - - }; - - /// Exception-safe rendering - class Rendering - { - CellRenderImp& mCellRender; - bool mEnd; - - // not implemented - Rendering (const Rendering&); - Rendering& operator= (const Rendering&); - - public: - - Rendering (CellRenderImp& cellRender, ESM::CellRef& ref, MWWorld::RefData& refData, bool static_ = false) - : mCellRender (cellRender), mEnd (false) - { - mCellRender.insertBegin (ref, refData, static_); - } - - ~Rendering() - { - if (!mEnd) - mCellRender.insertEnd (false); - } - - std::string end (bool enable) - { - assert (!mEnd); - mEnd = true; - return mCellRender.insertEnd (enable); - } - }; -} - -#endif diff --git a/apps/openmw/mwrender/exterior.cpp b/apps/openmw/mwrender/exterior.cpp deleted file mode 100644 index d1eabe36e..000000000 --- a/apps/openmw/mwrender/exterior.cpp +++ /dev/null @@ -1,455 +0,0 @@ -#include "exterior.hpp" -#include "renderingmanager.hpp" - -#include -#include -#include -#include -#include - -#include -#include -#include - -using namespace MWRender; -using namespace Ogre; -using namespace ESMS; - -bool ExteriorCellRender::lightConst = false; -float ExteriorCellRender::lightConstValue = 0.0f; - -bool ExteriorCellRender::lightLinear = true; -int ExteriorCellRender::lightLinearMethod = 1; -float ExteriorCellRender::lightLinearValue = 3; -float ExteriorCellRender::lightLinearRadiusMult = 1; - -bool ExteriorCellRender::lightQuadratic = false; -int ExteriorCellRender::lightQuadraticMethod = 2; -float ExteriorCellRender::lightQuadraticValue = 16; -float ExteriorCellRender::lightQuadraticRadiusMult = 1; - -bool ExteriorCellRender::lightOutQuadInLin = false; - -int ExteriorCellRender::uniqueID = 0; - -ExteriorCellRender::ExteriorCellRender(ESMS::CellStore &_cell, MWWorld::Environment& environment, - OEngine::Render::OgreRenderer& renderer, Ogre::SceneNode *mwRoot,MWWorld::PhysicsSystem *physics) - : mCell(_cell), mEnvironment (environment), mRenderer(renderer), mPhysics(physics), mBase(NULL), mInsert(NULL), mAmbientMode (0) -{ - mMwRoot = mwRoot; - uniqueID = uniqueID +1; - sg = mRenderer.getScene()->createStaticGeometry( "sg" + Ogre::StringConverter::toString(uniqueID)); - -} - - - -void ExteriorCellRender::insertBegin (ESM::CellRef &ref, MWWorld::RefData& refData, bool static_) -{ - assert (!mInsert); - - isStatic = static_; - - // Create and place scene node for this object - mInsert = mBase->createChildSceneNode(); - - const float *f = ref.pos.pos; - mInsert->setPosition(f[0], f[1], f[2]); - mInsert->setScale(ref.scale, ref.scale, ref.scale); - - // Convert MW rotation to a quaternion: - f = ref.pos.rot; - - // Rotate around X axis - Quaternion xr(Radian(-f[0]), Vector3::UNIT_X); - - // Rotate around Y axis - Quaternion yr(Radian(-f[1]), Vector3::UNIT_Y); - - // Rotate around Z axis - Quaternion zr(Radian(-f[2]), Vector3::UNIT_Z); - - // Rotates first around z, then y, then x - mInsert->setOrientation(xr*yr*zr); - - mInsertMesh.clear(); -} - - -void ExteriorCellRender::rotateMesh(Ogre::Vector3 axis, Ogre::Radian angle, std::string sceneNodeName[], int elements) -{ - assert(mInsert); - Ogre::SceneNode *parent = mInsert; - //std::cout << "ELEMENTS:" << elements; - for (int i = 0; i < elements; i++){ - if(sceneNodeName[i] != "" && parent->getChild(sceneNodeName[i])) - parent = dynamic_cast (parent->getChild(sceneNodeName[i])); - } - parent->rotate(axis, angle); -} -/* -void ExteriorCellRender::insertMesh(const std::string &mesh, Ogre::Vector3 vec, Ogre::Vector3 axis, Ogre::Radian angle, std::string sceneNodeName, std::string sceneParent[], int elements){ - assert (mInsert); - //mInsert-> - Ogre::SceneNode *parent = mInsert; - for (int i = 0; i < elements; i++){ - if(sceneParent[i] != "" && parent->getChild(sceneParent[i])) - parent = dynamic_cast (parent->getChild(sceneParent[i])); - } - - mNpcPart = parent->createChildSceneNode(sceneNodeName); - NIFLoader::load(mesh); - MovableObject *ent = mScene.getMgr()->createEntity(mesh); - - mNpcPart->translate(vec); - mNpcPart->rotate(axis, angle); - // mNpcPart->translate(vec); - //mNpcPart->rotate(axis, angle); - mNpcPart->attachObject(ent); - //mNpcPart-> - -} -*/ -void ExteriorCellRender::insertMesh(const std::string &mesh, Ogre::Vector3 vec, Ogre::Vector3 axis, Ogre::Radian angle, std::string sceneNodeName, std::string sceneParent[], int elements) -{ - insertMesh(mesh, vec, axis, angle, sceneNodeName, sceneParent, elements, true); -} -void ExteriorCellRender::insertMesh(const std::string &mesh, Ogre::Vector3 vec, Ogre::Vector3 axis, Ogre::Radian angle, std::string sceneNodeName, std::string sceneParent[], int elements, bool translateFirst){ - - assert (mInsert); - //mInsert-> - Ogre::SceneNode *parent = mInsert; - for (int i = 0; i < elements; i++){ - if(sceneParent[i] != "" && parent->getChild(sceneParent[i])) - parent = dynamic_cast (parent->getChild(sceneParent[i])); - } - - mNpcPart = parent->createChildSceneNode(sceneNodeName); - MeshPtr good2 = NifOgre::NIFLoader::load(mesh); - - MovableObject *ent = mRenderer.getScene()->createEntity(mesh); - - - if(translateFirst){ - mNpcPart->translate(vec); - mNpcPart->rotate(axis, angle); - } - else{ - - mNpcPart->rotate(axis, angle); - mNpcPart->translate(vec); - } - mNpcPart->attachObject(ent); - - Ogre::MeshManager *m = MeshManager::getSingletonPtr(); - 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"; - - const std::string beastfoot1 ="foot\\b\\B_N_Khajiit_F_Skins.nif"; - const std::string beastfoot2 ="foot\\b\\B_N_Khajiit_M_Skins.nif"; - const std::string beastfoot3 ="foot\\b\\B_N_Argonian_F_Skins.nif"; - const std::string beastfoot4 ="foot\\b\\B_N_Argonian_M_Skins.nif"; - if(mesh.compare(beast1) == 0 && m->getByName(beasttail1).isNull()) - { - //std::cout << "CLONINGKHAJIITF\n"; - good2->reload(); - MeshPtr tail = good2->clone(beasttail1); - good2->reload(); - MeshPtr foot = good2->clone(beastfoot1); - good2->reload(); - } - else if(mesh.compare(beast2) == 0 && m->getByName(beasttail2).isNull()) - { - //std::cout << "CLONINGKHAJIITM\n"; - good2->reload(); - MeshPtr tail = good2->clone(beasttail2); - good2->reload(); - MeshPtr foot = good2->clone(beastfoot2); - good2->reload(); - } - else if(mesh.compare(beast3) == 0 && m->getByName(beasttail3).isNull()) - { - //std::cout << "CLONINGARGONIANF\n"; - good2->reload(); - MeshPtr tail = good2->clone(beasttail3); - good2->reload(); - MeshPtr foot = good2->clone(beastfoot3); - good2->reload(); - } - else if(mesh.compare(beast4) == 0 && m->getByName(beasttail4).isNull()) - { - //std::cout << "CLONINGARGONIANM\n"; - good2->reload(); - MeshPtr tail = good2->clone(beasttail4); - good2->reload(); - MeshPtr foot = good2->clone(beastfoot4); - good2->reload(); - } -} -// insert a mesh related to the most recent insertBegin call. - -void ExteriorCellRender::scaleMesh(Ogre::Vector3 axis, std::string sceneNodeName[], int elements) -{ - assert(mInsert); - Ogre::SceneNode *parent = mInsert; - //std::cout << "ELEMENTS:" << elements; - for (int i = 0; i < elements; i++){ - if(sceneNodeName[i] != "" && parent->getChild(sceneNodeName[i])) - parent = dynamic_cast (parent->getChild(sceneNodeName[i])); - } - parent->scale(axis); -} - -// insert a mesh related to the most recent insertBegin call. - - -void ExteriorCellRender::insertMesh(const std::string &mesh) -{ - assert (mInsert); - - NifOgre::NIFLoader::load(mesh); - Entity *ent = mRenderer.getScene()->createEntity(mesh); - - if(!isStatic) - { - mInsert->attachObject(ent); - } - else - { - sg->addEntity(ent,mInsert->_getDerivedPosition(),mInsert->_getDerivedOrientation(),mInsert->_getDerivedScale()); - sg->setRegionDimensions(Ogre::Vector3(100000,10000,100000)); - mRenderer.getScene()->destroyEntity(ent); - } - if (mInsertMesh.empty()) - mInsertMesh = mesh; -} - -void ExteriorCellRender::insertObjectPhysics() -{ - if (!mInsertMesh.empty()) - { - mPhysics->addObject (mInsert->getName(), mInsertMesh, mInsert->getOrientation(), - mInsert->getScale().x, mInsert->getPosition()); - } -} - -void ExteriorCellRender::insertActorPhysics() -{ - mPhysics->addActor (mInsert->getName(), mInsertMesh, mInsert->getPosition()); -} - -// insert a light related to the most recent insertBegin call. -void ExteriorCellRender::insertLight(float r, float g, float b, float radius) -{ - assert (mInsert); - - Ogre::Light *light = mRenderer.getScene()->createLight(); - light->setDiffuseColour (r, g, b); - - float cval=0.0f, lval=0.0f, qval=0.0f; - - if(lightConst) - cval = lightConstValue; - if(!lightOutQuadInLin) - { - if(lightLinear) - radius *= lightLinearRadiusMult; - if(lightQuadratic) - radius *= lightQuadraticRadiusMult; - - if(lightLinear) - lval = lightLinearValue / pow(radius, lightLinearMethod); - if(lightQuadratic) - qval = lightQuadraticValue / pow(radius, lightQuadraticMethod); - } - else - { - // FIXME: - // Do quadratic or linear, depending if we're in an exterior or interior - // cell, respectively. Ignore lightLinear and lightQuadratic. - } - - light->setAttenuation(10*radius, cval, lval, qval); - - mInsert->attachObject(light); -} - -// finish inserting a new reference and return a handle to it. - -std::string ExteriorCellRender::insertEnd (bool enable) -{ - assert (mInsert); - - std::string handle = mInsert->getName(); - - if (!enable) - mInsert->setVisible (false); - - mInsert = 0; - - return handle; -} - -// configure lighting according to cell - -void ExteriorCellRender::configureAmbient() -{ - mAmbientColor.setAsABGR (mCell.cell->ambi.ambient); - setAmbientMode(); - - // Create a "sun" that shines light downwards. It doesn't look - // completely right, but leave it for now. - Ogre::Light *light = mRenderer.getScene()->createLight(); - Ogre::ColourValue colour; - colour.setAsABGR (mCell.cell->ambi.sunlight); - light->setDiffuseColour (colour); - light->setType(Ogre::Light::LT_DIRECTIONAL); - light->setDirection(0,-1,0); -} - -// configure fog according to cell -void ExteriorCellRender::configureFog() -{ - Ogre::ColourValue color; - color.setAsABGR (mCell.cell->ambi.fog); - - float high = 4500 + 9000 * (1-mCell.cell->ambi.fogDensity); - float low = 200; - - mRenderer.getScene()->setFog (FOG_LINEAR, color, 0, low, high); - mRenderer.getCamera()->setFarClipDistance (high + 10); - mRenderer.getViewport()->setBackgroundColour (color); -} - -void ExteriorCellRender::setAmbientMode() -{ - switch (mAmbientMode) - { - case 0: - - mRenderer.getScene()->setAmbientLight(mAmbientColor); - break; - - case 1: - - mRenderer.getScene()->setAmbientLight(0.7f*mAmbientColor + 0.3f*ColourValue(1,1,1)); - break; - - case 2: - - mRenderer.getScene()->setAmbientLight(ColourValue(1,1,1)); - break; - } -} - -void ExteriorCellRender::show() -{ - // FIXME: this one may be the bug - mBase = mMwRoot->createChildSceneNode(); - - configureAmbient(); - configureFog(); - - insertCell(mCell, mEnvironment); - - sg->build(); -} - -void ExteriorCellRender::hide() -{ - if(mBase) - mBase->setVisible(false); -} - -void ExteriorCellRender::destroyAllAttachedMovableObjects(Ogre::SceneNode* i_pSceneNode) -{ - if ( !i_pSceneNode ) - { - assert( false ); - return; - } - - // Destroy all the attached objects - SceneNode::ObjectIterator itObject = i_pSceneNode->getAttachedObjectIterator(); - - while ( itObject.hasMoreElements() ) - { - MovableObject* pObject = static_cast(itObject.getNext()); - i_pSceneNode->getCreator()->destroyMovableObject( pObject ); - } - - // Recurse to child SceneNodes - SceneNode::ChildNodeIterator itChild = i_pSceneNode->getChildIterator(); - - while ( itChild.hasMoreElements() ) - { - SceneNode* pChildNode = static_cast(itChild.getNext()); - destroyAllAttachedMovableObjects( pChildNode ); - } -} - -void ExteriorCellRender::destroy() -{ - if(mBase) - { - destroyAllAttachedMovableObjects(mBase); - mBase->removeAndDestroyAllChildren(); - mRenderer.getScene()->destroySceneNode(mBase); - } - - mBase = 0; - - if (sg) - { - mRenderer.getScene()->destroyStaticGeometry (sg); - sg = 0; - } -} - -// Switch through lighting modes. - -void ExteriorCellRender::toggleLight() -{ - if (mAmbientMode==2) - mAmbientMode = 0; - else - ++mAmbientMode; - - switch (mAmbientMode) - { - case 0: std::cout << "Setting lights to normal\n"; break; - case 1: std::cout << "Turning the lights up\n"; break; - case 2: std::cout << "Turning the lights to full\n"; break; - } - - setAmbientMode(); -} - -void ExteriorCellRender::enable (const std::string& handle) -{ - if (!handle.empty()) - mRenderer.getScene()->getSceneNode (handle)->setVisible (true); -} - -void ExteriorCellRender::disable (const std::string& handle) -{ - if (!handle.empty()) - mRenderer.getScene()->getSceneNode (handle)->setVisible (false); -} - -void ExteriorCellRender::deleteObject (const std::string& handle) -{ - if (!handle.empty()) - { - Ogre::SceneNode *node = mRenderer.getScene()->getSceneNode (handle); - node->removeAndDestroyAllChildren(); - mRenderer.getScene()->destroySceneNode (node); - } -} diff --git a/apps/openmw/mwrender/exterior.hpp b/apps/openmw/mwrender/exterior.hpp deleted file mode 100644 index a0b86165a..000000000 --- a/apps/openmw/mwrender/exterior.hpp +++ /dev/null @@ -1,139 +0,0 @@ -#ifndef _GAME_RENDER_EXTERIOR_H -#define _GAME_RENDER_EXTERIOR_H - -#include "cell.hpp" -#include "cellimp.hpp" -#include "../mwworld/physicssystem.hpp" - -#include "OgreColourValue.h" -#include -#include - -namespace Ogre -{ - class SceneNode; -} - -namespace MWWorld -{ - class Environment; -} - -namespace MWRender -{ - class RenderingManager; - - /** - This class is responsible for inserting meshes and other - rendering objects from the given cell into the given rendering - scene. - */ - - class ExteriorCellRender : public CellRender, private CellRenderImp - { - - static bool lightConst; - static float lightConstValue; - - static bool lightLinear; - static int lightLinearMethod; - static float lightLinearValue; - static float lightLinearRadiusMult; - - static bool lightQuadratic; - static int lightQuadraticMethod; - static float lightQuadraticValue; - static float lightQuadraticRadiusMult; - - static bool lightOutQuadInLin; - - ESMS::CellStore &mCell; - MWWorld::Environment &mEnvironment; - OEngine::Render::OgreRenderer& mRenderer; - Ogre::SceneNode *mMwRoot; - MWWorld::PhysicsSystem *mPhysics; - - /// The scene node that contains all objects belonging to this - /// cell. - Ogre::SceneNode *mBase; - - Ogre::SceneNode *mInsert; - std::string mInsertMesh; - Ogre::SceneNode *mNpcPart; - - //the static geometry - Ogre::StaticGeometry *sg; - bool isStatic; - - // 0 normal, 1 more bright, 2 max - int mAmbientMode; - - Ogre::ColourValue mAmbientColor; - - /// start inserting a new reference. - virtual void insertBegin (ESM::CellRef &ref, MWWorld::RefData& refData, bool static_ = false); - - /// insert a mesh related to the most recent insertBegin call. - 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); - - virtual void insertMesh(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); - - virtual void insertObjectPhysics(); - - virtual void insertActorPhysics(); - - /// insert a light related to the most recent insertBegin call. - virtual void insertLight(float r, float g, float b, float radius); - - /// finish inserting a new reference and return a handle to it. - virtual std::string insertEnd (bool Enable); - - /// configure lighting according to cell - void configureAmbient(); - - /// configure fog according to cell - void configureFog(); - - void setAmbientMode(); - - - public: - - ExteriorCellRender(ESMS::CellStore &_cell, MWWorld::Environment& environment, - OEngine::Render::OgreRenderer& renderer, Ogre::SceneNode *mwRoot, MWWorld::PhysicsSystem *physics); - - virtual ~ExteriorCellRender() { destroy(); } - - /// Make the cell visible. Load the cell if necessary. - virtual void show(); - - /// Remove the cell from rendering, but don't remove it from - /// memory. - virtual void hide(); - - /// Destroy all rendering objects connected with this cell. - virtual void destroy(); // comment by Zini: shouldn't this go into the destructor? - - /// Switch through lighting modes. - void toggleLight(); - - /// Make the reference with the given handle visible. - virtual void enable (const std::string& handle); - - /// Make the reference with the given handle invisible. - virtual void disable (const std::string& handle); - - /// Remove the reference with the given handle permanently from the scene. - virtual void deleteObject (const std::string& handle); - - void destroyAllAttachedMovableObjects(Ogre::SceneNode* i_pSceneNode); - - static int uniqueID; - }; -} - -#endif diff --git a/apps/openmw/mwrender/interior.cpp b/apps/openmw/mwrender/interior.cpp deleted file mode 100644 index c6bddc2f0..000000000 --- a/apps/openmw/mwrender/interior.cpp +++ /dev/null @@ -1,409 +0,0 @@ -#include "interior.hpp" -#include "renderingmanager.hpp" - -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include - -using namespace MWRender; -using namespace Ogre; -using namespace ESMS; - -bool InteriorCellRender::lightConst = false; -float InteriorCellRender::lightConstValue = 0.0f; - -bool InteriorCellRender::lightLinear = true; -int InteriorCellRender::lightLinearMethod = 1; -float InteriorCellRender::lightLinearValue = 3; -float InteriorCellRender::lightLinearRadiusMult = 1; - -bool InteriorCellRender::lightQuadratic = false; -int InteriorCellRender::lightQuadraticMethod = 2; -float InteriorCellRender::lightQuadraticValue = 16; -float InteriorCellRender::lightQuadraticRadiusMult = 1; - -bool InteriorCellRender::lightOutQuadInLin = false; - -// start inserting a new reference. - -void InteriorCellRender::insertBegin (ESM::CellRef &ref, MWWorld::RefData& refData, bool static_) -{ - assert (!insert); - - // Create and place scene node for this object - insert = base->createChildSceneNode(); - - const float *f = refData.getPosition().pos; - insert->setPosition(f[0], f[1], f[2]); - insert->setScale(ref.scale, ref.scale, ref.scale); - - // Convert MW rotation to a quaternion: - f = ref.pos.rot; - - // Rotate around X axis - Quaternion xr(Radian(-f[0]), Vector3::UNIT_X); - - // Rotate around Y axis - Quaternion yr(Radian(-f[1]), Vector3::UNIT_Y); - - // Rotate around Z axis - Quaternion zr(Radian(-f[2]), Vector3::UNIT_Z); - - // Rotates first around z, then y, then x - insert->setOrientation(xr*yr*zr); - - mInsertMesh.clear(); -} - -// insert a mesh related to the most recent insertBegin call. -void InteriorCellRender::rotateMesh(Ogre::Vector3 axis, Ogre::Radian angle, std::string sceneNodeName[], int elements) -{ - assert(insert); - Ogre::SceneNode *parent = insert; - //std::cout << "ELEMENTS:" << elements; - for (int i = 0; i < elements; i++){ - if(sceneNodeName[i] != "" && parent->getChild(sceneNodeName[i])) - parent = dynamic_cast (parent->getChild(sceneNodeName[i])); - } - parent->rotate(axis, angle); -} -// insert a mesh related to the most recent insertBegin call. - -void InteriorCellRender::scaleMesh(Ogre::Vector3 axis, std::string sceneNodeName[], int elements) -{ - assert(insert); - Ogre::SceneNode *parent = insert; - //std::cout << "ELEMENTS:" << elements; - for (int i = 0; i < elements; i++){ - if(sceneNodeName[i] != "" && parent->getChild(sceneNodeName[i])) - parent = dynamic_cast (parent->getChild(sceneNodeName[i])); - } - parent->scale(axis); -} -void InteriorCellRender::insertMesh(const std::string &mesh, Ogre::Vector3 vec, Ogre::Vector3 axis, Ogre::Radian angle, std::string sceneNodeName, std::string sceneParent[], int elements) -{ - insertMesh(mesh, vec, axis, angle, sceneNodeName, sceneParent, elements, true); -} -void InteriorCellRender::insertMesh(const std::string &mesh, Ogre::Vector3 vec, Ogre::Vector3 axis, Ogre::Radian angle, std::string sceneNodeName, std::string sceneParent[], int elements, bool translateFirst){ - - assert (insert); - //insert-> - Ogre::SceneNode *parent = insert; - for (int i = 0; i < elements; i++){ - if(sceneParent[i] != "" && parent->getChild(sceneParent[i])) - parent = dynamic_cast (parent->getChild(sceneParent[i])); - } - - npcPart = parent->createChildSceneNode(sceneNodeName); - //npcPart->showBoundingBox(true); - - MeshPtr good2 = NifOgre::NIFLoader::load(mesh); - - MovableObject *ent = mRenderer.getScene()->createEntity(mesh); - //ent->extr - - // MovableObject *ent2 = scene.getMgr()->createEntity(bounds - // ); - //ent-> - //std::cout << mesh << bounds << "\n"; - - if(translateFirst){ - npcPart->translate(vec); - npcPart->rotate(axis, angle); - } - else{ - - npcPart->rotate(axis, angle); - npcPart->translate(vec); - } - - npcPart->attachObject(ent); - Ogre::MeshManager *m = MeshManager::getSingletonPtr(); - 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"; - - const std::string beastfoot1 ="foot\\b\\B_N_Khajiit_F_Skins.nif"; - const std::string beastfoot2 ="foot\\b\\B_N_Khajiit_M_Skins.nif"; - const std::string beastfoot3 ="foot\\b\\B_N_Argonian_F_Skins.nif"; - const std::string beastfoot4 ="foot\\b\\B_N_Argonian_M_Skins.nif"; - if(mesh.compare(beast1) == 0 && m->getByName(beasttail1).isNull()) - { - //std::cout << "CLONINGKHAJIITF\n"; - good2->reload(); - MeshPtr tail = good2->clone(beasttail1); - good2->reload(); - MeshPtr foot = good2->clone(beastfoot1); - good2->reload(); - } - else if(mesh.compare(beast2) == 0 && m->getByName(beasttail2).isNull()) - { - //std::cout << "CLONINGKHAJIITM\n"; - good2->reload(); - MeshPtr tail = good2->clone(beasttail2); - good2->reload(); - MeshPtr foot = good2->clone(beastfoot2); - good2->reload(); - } - else if(mesh.compare(beast3) == 0 && m->getByName(beasttail3).isNull()) - { - //std::cout << "CLONINGARGONIANF\n"; - good2->reload(); - MeshPtr tail = good2->clone(beasttail3); - good2->reload(); - MeshPtr foot = good2->clone(beastfoot3); - good2->reload(); - } - else if(mesh.compare(beast4) == 0 && m->getByName(beasttail4).isNull()) - { - //std::cout << "CLONINGARGONIANM\n"; - good2->reload(); - MeshPtr tail = good2->clone(beasttail4); - good2->reload(); - MeshPtr foot = good2->clone(beastfoot4); - good2->reload(); - } -} - -void InteriorCellRender::insertMesh(const std::string &mesh) -{ - assert (insert); - - NifOgre::NIFLoader::load(mesh); - MovableObject *ent = mRenderer.getScene()->createEntity(mesh); - insert->attachObject(ent); - - if (mInsertMesh.empty()) - mInsertMesh = mesh; -} - -void InteriorCellRender::insertObjectPhysics() -{ - if (!mInsertMesh.empty()) - { - mPhysics->addObject (insert->getName(), mInsertMesh, insert->getOrientation(), - insert->getScale().x, insert->getPosition()); - } -} - -void InteriorCellRender::insertActorPhysics() -{ - mPhysics->addActor (insert->getName(), mInsertMesh, insert->getPosition()); -} - -// insert a light related to the most recent insertBegin call. -void InteriorCellRender::insertLight(float r, float g, float b, float radius) -{ - assert (insert); - - Ogre::Light *light = mRenderer.getScene()->createLight(); - light->setDiffuseColour (r, g, b); - - float cval=0.0f, lval=0.0f, qval=0.0f; - - if(lightConst) - cval = lightConstValue; - if(!lightOutQuadInLin) - { - if(lightLinear) - radius *= lightLinearRadiusMult; - if(lightQuadratic) - radius *= lightQuadraticRadiusMult; - - if(lightLinear) - lval = lightLinearValue / pow(radius, lightLinearMethod); - if(lightQuadratic) - qval = lightQuadraticValue / pow(radius, lightQuadraticMethod); - } - else - { - // FIXME: - // Do quadratic or linear, depending if we're in an exterior or interior - // cell, respectively. Ignore lightLinear and lightQuadratic. - } - - light->setAttenuation(10*radius, cval, lval, qval); - - insert->attachObject(light); -} - -// finish inserting a new reference and return a handle to it. - -std::string InteriorCellRender::insertEnd (bool enable) -{ - assert (insert); - - std::string handle = insert->getName(); - - if (!enable) - insert->setVisible (false); - - insert = 0; - - return handle; -} - -// configure lighting according to cell - -void InteriorCellRender::configureAmbient() -{ - ambientColor.setAsABGR (cell.cell->ambi.ambient); - setAmbientMode(); - - // Create a "sun" that shines light downwards. It doesn't look - // completely right, but leave it for now. - Ogre::Light *light = mRenderer.getScene()->createLight(); - Ogre::ColourValue colour; - colour.setAsABGR (cell.cell->ambi.sunlight); - light->setDiffuseColour (colour); - light->setType(Ogre::Light::LT_DIRECTIONAL); - light->setDirection(0,-1,0); -} - -// configure fog according to cell -void InteriorCellRender::configureFog() -{ - Ogre::ColourValue color; - color.setAsABGR (cell.cell->ambi.fog); - - float high = 4500 + 9000 * (1-cell.cell->ambi.fogDensity); - float low = 200; - - mRenderer.getScene()->setFog (FOG_LINEAR, color, 0, low, high); - mRenderer.getCamera()->setFarClipDistance (high + 10); - mRenderer.getViewport()->setBackgroundColour (color); -} - -void InteriorCellRender::setAmbientMode() -{ - switch (ambientMode) - { - case 0: - - mRenderer.getScene()->setAmbientLight(ambientColor); - break; - - case 1: - - mRenderer.getScene()->setAmbientLight(0.7f*ambientColor + 0.3f*ColourValue(1,1,1)); - break; - - case 2: - - mRenderer.getScene()->setAmbientLight(ColourValue(1,1,1)); - break; - } -} - -void InteriorCellRender::show() -{ - base = mMwRoot->createChildSceneNode(); - - configureAmbient(); - configureFog(); - - insertCell(cell, mEnvironment); -} - -void InteriorCellRender::hide() -{ - if(base) - base->setVisible(false); -} - -void InteriorCellRender::destroy() -{ - if(base) - { - base->removeAndDestroyAllChildren(); - mRenderer.getScene()->destroySceneNode(base); - } - - base = NULL; -} - -// Switch through lighting modes. - -void InteriorCellRender::toggleLight() -{ - if (ambientMode==2) - ambientMode = 0; - else - ++ambientMode; - - switch (ambientMode) - { - case 0: std::cout << "Setting lights to normal\n"; break; - case 1: std::cout << "Turning the lights up\n"; break; - case 2: std::cout << "Turning the lights to full\n"; break; - } - - setAmbientMode(); -} - -void InteriorCellRender::enable (const std::string& handle) -{ - if (!handle.empty()) - mRenderer.getScene()->getSceneNode (handle)->setVisible (true); -} - -void InteriorCellRender::disable (const std::string& handle) -{ - if (!handle.empty()) - mRenderer.getScene()->getSceneNode (handle)->setVisible (false); -} - -void InteriorCellRender::deleteObject (const std::string& handle) -{ - if (!handle.empty()) - { - Ogre::SceneNode *node = mRenderer.getScene()->getSceneNode (handle); - node->removeAndDestroyAllChildren(); - mRenderer.getScene()->destroySceneNode (node); - } -} - -// Magic function from the internets. Might need this later. -/* -void Scene::DestroyAllAttachedMovableObjects( SceneNode* i_pSceneNode ) -{ - if ( !i_pSceneNode ) - { - ASSERT( false ); - return; - } - - // Destroy all the attached objects - SceneNode::ObjectIterator itObject = i_pSceneNode->getAttachedObjectIterator(); - - while ( itObject.hasMoreElements() ) - { - MovableObject* pObject = static_cast(itObject.getNext()); - i_pSceneNode->getCreator()->destroyMovableObject( pObject ); - } - - // Recurse to child SceneNodes - SceneNode::ChildNodeIterator itChild = i_pSceneNode->getChildIterator(); - - while ( itChild.hasMoreElements() ) - { - SceneNode* pChildNode = static_cast(itChild.getNext()); - DestroyAllAttachedMovableObjects( pChildNode ); - } -} -*/ diff --git a/apps/openmw/mwrender/interior.hpp b/apps/openmw/mwrender/interior.hpp deleted file mode 100644 index cc94e608f..000000000 --- a/apps/openmw/mwrender/interior.hpp +++ /dev/null @@ -1,133 +0,0 @@ -#ifndef _GAME_RENDER_INTERIOR_H -#define _GAME_RENDER_INTERIOR_H - -#include "cell.hpp" -#include "cellimp.hpp" -#include "../mwworld/physicssystem.hpp" - -#include "OgreColourValue.h" -#include - -namespace Ogre -{ - class SceneNode; -} - -namespace MWWorld -{ - class Environment; -} - -namespace MWRender -{ - class RenderingManager; - - /** - This class is responsible for inserting meshes and other - rendering objects from the given cell into the given rendering - scene. - */ - - class InteriorCellRender : public CellRender, private CellRenderImp - { - //static bool isChest; - static bool lightConst; - static float lightConstValue; - - static bool lightLinear; - static int lightLinearMethod; - static float lightLinearValue; - static float lightLinearRadiusMult; - - static bool lightQuadratic; - static int lightQuadraticMethod; - static float lightQuadraticValue; - static float lightQuadraticRadiusMult; - - static bool lightOutQuadInLin; - - ESMS::CellStore &cell; - MWWorld::Environment &mEnvironment; - OEngine::Render::OgreRenderer& mRenderer; - Ogre::SceneNode *mMwRoot; - MWWorld::PhysicsSystem *mPhysics; - - /// The scene node that contains all objects belonging to this - /// cell. - Ogre::SceneNode *base; - - Ogre::SceneNode *insert; - std::string mInsertMesh; - Ogre::SceneNode *npcPart; - - // 0 normal, 1 more bright, 2 max - int ambientMode; - - Ogre::ColourValue ambientColor; - - /// start inserting a new reference. - virtual void insertBegin (ESM::CellRef &ref, MWWorld::RefData& refData, bool static_ = false); - 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 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); - - virtual void insertObjectPhysics(); - - virtual void insertActorPhysics(); - - /// insert a light related to the most recent insertBegin call. - virtual void insertLight(float r, float g, float b, float radius); - - /// finish inserting a new reference and return a handle to it. - virtual std::string insertEnd (bool Enable); - - /// configure lighting according to cell - void configureAmbient(); - - /// configure fog according to cell - void configureFog(); - - void setAmbientMode(); - - - public: - - InteriorCellRender(ESMS::CellStore &_cell, MWWorld::Environment& environment, - OEngine::Render::OgreRenderer& renderer, Ogre::SceneNode *mwRoot, MWWorld::PhysicsSystem *physics) - : cell(_cell), mEnvironment (environment), mRenderer(renderer), base(NULL), insert(NULL), ambientMode (0) - { - mMwRoot = mwRoot; - mPhysics = physics; - } - - virtual ~InteriorCellRender() { destroy(); } - - /// Make the cell visible. Load the cell if necessary. - //virtual void scaleMesh(Ogre::Vector3 axis, std::string sceneNodeName[], int elements); - virtual void show(); - - /// Remove the cell from rendering, but don't remove it from - /// memory. - virtual void hide(); - - /// Destroy all rendering objects connected with this cell. - virtual void destroy(); // comment by Zini: shouldn't this go into the destructor? - - /// Switch through lighting modes. - void toggleLight(); - - /// Make the reference with the given handle visible. - virtual void enable (const std::string& handle); - - /// Make the reference with the given handle invisible. - virtual void disable (const std::string& handle); - - /// Remove the reference with the given handle permanently from the scene. - virtual void deleteObject (const std::string& handle); - }; -} - -#endif diff --git a/apps/openmw/mwrender/player.cpp b/apps/openmw/mwrender/player.cpp index 7dcaeee09..7ed921218 100644 --- a/apps/openmw/mwrender/player.cpp +++ b/apps/openmw/mwrender/player.cpp @@ -3,7 +3,7 @@ namespace MWRender { - Player::Player (Ogre::Camera *camera, const std::string& handle) - : mCamera (camera), mHandle (handle) + Player::Player (Ogre::Camera *camera, Ogre::SceneNode* node) + : mCamera (camera), mNode (node) {} } diff --git a/apps/openmw/mwrender/player.hpp b/apps/openmw/mwrender/player.hpp index f2d819116..4306b8a95 100644 --- a/apps/openmw/mwrender/player.hpp +++ b/apps/openmw/mwrender/player.hpp @@ -2,6 +2,7 @@ #define GAME_MWRENDER_PLAYER_H #include +#include namespace Ogre { @@ -14,15 +15,16 @@ namespace MWRender class Player { Ogre::Camera *mCamera; - std::string mHandle; + Ogre::SceneNode* mNode; public: - Player (Ogre::Camera *camera, const std::string& handle); + Player (Ogre::Camera *camera, Ogre::SceneNode* mNode); Ogre::Camera *getCamera() { return mCamera; } - std::string getHandle() const { return mHandle; } + std::string getHandle() const { return mNode->getName(); } + Ogre::SceneNode* getNode() {return mNode;} }; } diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index 1a4aee3c7..17403d659 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -55,7 +55,7 @@ RenderingManager::RenderingManager (OEngine::Render::OgreRenderer& _rend, const Ogre::SceneNode *cameraPitchNode = cameraYawNode->createChildSceneNode(); cameraPitchNode->attachObject(rend.getCamera()); - mPlayer = new MWRender::Player (rend.getCamera(), playerNode->getName()); + mPlayer = new MWRender::Player (rend.getCamera(), playerNode); //std::cout << "Three"; } diff --git a/apps/openmw/mwworld/player.cpp b/apps/openmw/mwworld/player.cpp index db950b00e..cc93f68c2 100644 --- a/apps/openmw/mwworld/player.cpp +++ b/apps/openmw/mwworld/player.cpp @@ -22,7 +22,8 @@ namespace MWWorld playerPos[0] = playerPos[1] = playerPos[2] = 0; std::cout << renderer->getHandle(); - mPlayer.mData.setHandle (renderer->getHandle()); + + mPlayer.mData.setBaseNode(renderer->getNode()); /// \todo Do not make a copy of classes defined in esm/p records. mClass = new ESM::Class (*world.getStore().classes.find (player->cls)); } diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index d07f9eb16..4721a30dc 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -1,8 +1,6 @@ #include "scene.hpp" #include "world.hpp" -#include "../mwrender/interior.hpp" -#include "../mwrender/exterior.hpp" #include "../mwmechanics/mechanicsmanager.hpp" diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index 3993468c0..4ab46f008 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -7,8 +7,6 @@ #include #include "../mwrender/sky.hpp" -#include "../mwrender/interior.hpp" -#include "../mwrender/exterior.hpp" #include "../mwrender/player.hpp" #include "../mwmechanics/mechanicsmanager.hpp" From 4dc59dfbdd660bb4938ab6b874eb05a7ab534efe Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Thu, 17 Nov 2011 17:10:27 -0500 Subject: [PATCH 048/104] Scenenode flip --- apps/openmw/mwclass/activator.cpp | 1 - apps/openmw/mwclass/apparatus.cpp | 1 - apps/openmw/mwclass/armor.cpp | 1 - apps/openmw/mwclass/book.cpp | 1 - apps/openmw/mwclass/clothing.cpp | 1 - apps/openmw/mwclass/container.cpp | 2 -- apps/openmw/mwclass/creature.cpp | 7 ++++--- apps/openmw/mwclass/door.cpp | 1 - apps/openmw/mwclass/ingredient.cpp | 1 - apps/openmw/mwclass/light.cpp | 2 -- apps/openmw/mwclass/lockpick.cpp | 1 - apps/openmw/mwclass/misc.cpp | 2 -- apps/openmw/mwclass/npc.cpp | 9 +++++---- apps/openmw/mwclass/potion.cpp | 1 - apps/openmw/mwclass/repair.cpp | 2 -- apps/openmw/mwclass/weapon.cpp | 1 - apps/openmw/mwrender/objects.cpp | 5 ++++- apps/openmw/mwrender/objects.hpp | 2 ++ apps/openmw/mwrender/renderingmanager.cpp | 3 +++ 19 files changed, 18 insertions(+), 26 deletions(-) diff --git a/apps/openmw/mwclass/activator.cpp b/apps/openmw/mwclass/activator.cpp index fcad0d333..0cb640877 100644 --- a/apps/openmw/mwclass/activator.cpp +++ b/apps/openmw/mwclass/activator.cpp @@ -8,7 +8,6 @@ #include "../mwworld/ptr.hpp" -#include "../mwrender/cellimp.hpp" namespace MWClass { diff --git a/apps/openmw/mwclass/apparatus.cpp b/apps/openmw/mwclass/apparatus.cpp index 6f23614e2..74305bead 100644 --- a/apps/openmw/mwclass/apparatus.cpp +++ b/apps/openmw/mwclass/apparatus.cpp @@ -8,7 +8,6 @@ #include "../mwworld/ptr.hpp" #include "../mwworld/actiontake.hpp" -#include "../mwrender/cellimp.hpp" #include "containerutil.hpp" diff --git a/apps/openmw/mwclass/armor.cpp b/apps/openmw/mwclass/armor.cpp index f409bb9b0..457a988ef 100644 --- a/apps/openmw/mwclass/armor.cpp +++ b/apps/openmw/mwclass/armor.cpp @@ -8,7 +8,6 @@ #include "../mwworld/ptr.hpp" #include "../mwworld/actiontake.hpp" -#include "../mwrender/cellimp.hpp" #include "containerutil.hpp" diff --git a/apps/openmw/mwclass/book.cpp b/apps/openmw/mwclass/book.cpp index f9c20b8e8..8b2c32dd2 100644 --- a/apps/openmw/mwclass/book.cpp +++ b/apps/openmw/mwclass/book.cpp @@ -8,7 +8,6 @@ #include "../mwworld/ptr.hpp" #include "../mwworld/actiontake.hpp" -#include "../mwrender/cellimp.hpp" #include "containerutil.hpp" diff --git a/apps/openmw/mwclass/clothing.cpp b/apps/openmw/mwclass/clothing.cpp index 0dc2b4615..ac1b3e139 100644 --- a/apps/openmw/mwclass/clothing.cpp +++ b/apps/openmw/mwclass/clothing.cpp @@ -8,7 +8,6 @@ #include "../mwworld/ptr.hpp" #include "../mwworld/actiontake.hpp" -#include "../mwrender/cellimp.hpp" #include "containerutil.hpp" diff --git a/apps/openmw/mwclass/container.cpp b/apps/openmw/mwclass/container.cpp index e24177d6c..6fc6f8482 100644 --- a/apps/openmw/mwclass/container.cpp +++ b/apps/openmw/mwclass/container.cpp @@ -7,8 +7,6 @@ #include "../mwworld/ptr.hpp" -#include "../mwrender/cellimp.hpp" - namespace MWClass { void Container::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const diff --git a/apps/openmw/mwclass/creature.cpp b/apps/openmw/mwclass/creature.cpp index 12978c0dc..39cf94654 100644 --- a/apps/openmw/mwclass/creature.cpp +++ b/apps/openmw/mwclass/creature.cpp @@ -9,7 +9,6 @@ #include "../mwworld/actiontalk.hpp" #include "../mwworld/environment.hpp" -#include "../mwrender/cellimp.hpp" #include "../mwmechanics/mechanicsmanager.hpp" @@ -25,6 +24,7 @@ namespace MWClass void Creature::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const { + /* ESMS::LiveCellRef *ref = ptr.get(); @@ -36,11 +36,12 @@ namespace MWClass MWRender::Creatures creatures = renderingInterface.getCreatures(); //creatures.insertBegin(ptr, ptr.getRefData().isEnabled(), false); //creatures.insertMesh(ptr, "meshes\\" + model); - } + }*/ } void Creature::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const { + /* ESMS::LiveCellRef *ref = ptr.get(); @@ -49,7 +50,7 @@ namespace MWClass assert (ref->base != NULL); if(!model.empty()){ physics.insertActorPhysics(ptr); - } + }*/ } diff --git a/apps/openmw/mwclass/door.cpp b/apps/openmw/mwclass/door.cpp index 5073afb12..ccd1515b4 100644 --- a/apps/openmw/mwclass/door.cpp +++ b/apps/openmw/mwclass/door.cpp @@ -12,7 +12,6 @@ #include "../mwworld/environment.hpp" #include "../mwworld/world.hpp" -#include "../mwrender/cellimp.hpp" #include "../mwrender/objects.hpp" #include diff --git a/apps/openmw/mwclass/ingredient.cpp b/apps/openmw/mwclass/ingredient.cpp index 1ef695b44..42ae56fce 100644 --- a/apps/openmw/mwclass/ingredient.cpp +++ b/apps/openmw/mwclass/ingredient.cpp @@ -8,7 +8,6 @@ #include "../mwworld/ptr.hpp" #include "../mwworld/actiontake.hpp" -#include "../mwrender/cellimp.hpp" #include "containerutil.hpp" diff --git a/apps/openmw/mwclass/light.cpp b/apps/openmw/mwclass/light.cpp index 3fb455914..e846e56f8 100644 --- a/apps/openmw/mwclass/light.cpp +++ b/apps/openmw/mwclass/light.cpp @@ -10,8 +10,6 @@ #include "../mwworld/nullaction.hpp" #include "../mwworld/environment.hpp" -#include "../mwrender/cellimp.hpp" - #include "../mwsound/soundmanager.hpp" #include "containerutil.hpp" diff --git a/apps/openmw/mwclass/lockpick.cpp b/apps/openmw/mwclass/lockpick.cpp index 8e782bb0f..f74536dfc 100644 --- a/apps/openmw/mwclass/lockpick.cpp +++ b/apps/openmw/mwclass/lockpick.cpp @@ -8,7 +8,6 @@ #include "../mwworld/ptr.hpp" #include "../mwworld/actiontake.hpp" -#include "../mwrender/cellimp.hpp" #include "containerutil.hpp" namespace MWClass diff --git a/apps/openmw/mwclass/misc.cpp b/apps/openmw/mwclass/misc.cpp index d331fd35b..97bbcce2e 100644 --- a/apps/openmw/mwclass/misc.cpp +++ b/apps/openmw/mwclass/misc.cpp @@ -8,8 +8,6 @@ #include "../mwworld/ptr.hpp" #include "../mwworld/actiontake.hpp" -#include "../mwrender/cellimp.hpp" - #include "containerutil.hpp" namespace MWClass diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index a3171f5b5..47d62f96b 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -11,8 +11,6 @@ #include "../mwworld/environment.hpp" #include "../mwworld/world.hpp" -#include "../mwrender/cellimp.hpp" - #include "../mwmechanics/mechanicsmanager.hpp" #include @@ -34,6 +32,7 @@ namespace MWClass void Npc::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const { + /* ESMS::LiveCellRef *ref = ptr.get(); @@ -45,11 +44,13 @@ namespace MWClass MWRender::Npcs npcs = renderingInterface.getNPCs(); //npcs.insertBegin(ptr, ptr.getRefData().isEnabled(), false); //npcs.insertMesh(ptr, "meshes\\" + model); - } + }*/ } void Npc::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const { + + /* ESMS::LiveCellRef *ref = ptr.get(); @@ -58,7 +59,7 @@ namespace MWClass assert (ref->base != NULL); if(!model.empty()){ physics.insertActorPhysics(ptr); - } + }*/ } diff --git a/apps/openmw/mwclass/potion.cpp b/apps/openmw/mwclass/potion.cpp index 2eb1bbfa4..bf14c3cc8 100644 --- a/apps/openmw/mwclass/potion.cpp +++ b/apps/openmw/mwclass/potion.cpp @@ -8,7 +8,6 @@ #include "../mwworld/ptr.hpp" #include "../mwworld/actiontake.hpp" -#include "../mwrender/cellimp.hpp" #include "containerutil.hpp" diff --git a/apps/openmw/mwclass/repair.cpp b/apps/openmw/mwclass/repair.cpp index 320e3827e..28e65fa10 100644 --- a/apps/openmw/mwclass/repair.cpp +++ b/apps/openmw/mwclass/repair.cpp @@ -8,8 +8,6 @@ #include "../mwworld/ptr.hpp" #include "../mwworld/actiontake.hpp" -#include "../mwrender/cellimp.hpp" - #include "containerutil.hpp" namespace MWClass diff --git a/apps/openmw/mwclass/weapon.cpp b/apps/openmw/mwclass/weapon.cpp index dd52ed495..b13480600 100644 --- a/apps/openmw/mwclass/weapon.cpp +++ b/apps/openmw/mwclass/weapon.cpp @@ -8,7 +8,6 @@ #include "../mwworld/ptr.hpp" #include "../mwworld/actiontake.hpp" -#include "../mwrender/cellimp.hpp" #include "containerutil.hpp" diff --git a/apps/openmw/mwrender/objects.cpp b/apps/openmw/mwrender/objects.cpp index 8a4216799..2e5a07b60 100644 --- a/apps/openmw/mwrender/objects.cpp +++ b/apps/openmw/mwrender/objects.cpp @@ -23,8 +23,11 @@ bool Objects::lightOutQuadInLin = false; int Objects::uniqueID = 0; +void Objects::setMwRoot(Ogre::SceneNode* root){ + mwRoot = root; +} void Objects::insertBegin (const MWWorld::Ptr& ptr, bool enabled, bool static_){ - Ogre::SceneNode* root = mRend.getScene()->getRootSceneNode(); + Ogre::SceneNode* root = mwRoot; Ogre::SceneNode* cellnode; if(mCellSceneNodes.find(ptr.getCell()) == mCellSceneNodes.end()) { diff --git a/apps/openmw/mwrender/objects.hpp b/apps/openmw/mwrender/objects.hpp index 0dd7fdd4c..9c5f796a1 100644 --- a/apps/openmw/mwrender/objects.hpp +++ b/apps/openmw/mwrender/objects.hpp @@ -13,6 +13,7 @@ class Objects{ OEngine::Render::OgreRenderer &mRend; std::map mCellSceneNodes; std::map mSG; + Ogre::SceneNode* mwRoot; bool isStatic; static int uniqueID; static bool lightConst; @@ -38,6 +39,7 @@ public: void deleteObject (const std::string& handle); void removeCell(const MWWorld::Ptr& ptr); void buildStaticGeometry(ESMS::CellStore &cell); + void setMwRoot(Ogre::SceneNode* root); /// insert a light related to the most recent insertBegin call. diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index 17403d659..9fb9dd98c 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -45,6 +45,7 @@ RenderingManager::RenderingManager (OEngine::Render::OgreRenderer& _rend, const SceneNode *rt = rend.getScene()->getRootSceneNode(); mwRoot = rt->createChildSceneNode(); mwRoot->pitch(Degree(-90)); + objects.setMwRoot(mwRoot); //used to obtain ingame information of ogre objects (which are faced or selected) mRaySceneQuery = rend.getScene()->createRayQuery(Ray()); @@ -220,4 +221,6 @@ void RenderingManager::toggleLight() setAmbientMode(); } + + } From b3e104469989b1d8b2ced5ae35f0c21b342a8bf6 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Thu, 17 Nov 2011 18:08:48 -0500 Subject: [PATCH 049/104] Exterior cells --- apps/openmw/mwworld/scene.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index 4721a30dc..fcf8603d3 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -134,6 +134,7 @@ namespace MWWorld while (active!=mActiveCells.end()) { + cellstore = *active; if (!(cellstore->cell->data.flags & ESM::Cell::Interior)) { if (std::abs (X-cellstore->cell->data.gridX)<=1 && @@ -141,7 +142,6 @@ namespace MWWorld { // keep cells within the new 3x3 grid ++active; - cellstore = *active; continue; } } @@ -154,10 +154,11 @@ namespace MWWorld for (int y=Y-1; y<=Y+1; ++y) { CellStoreCollection::iterator iter = mActiveCells.begin(); - Ptr::CellStore* cellstore = *iter; + while (iter!=mActiveCells.end()) { + cellstore = *iter; assert (!(cellstore->cell->data.flags & ESM::Cell::Interior)); if (x==cellstore->cell->data.gridX && @@ -177,10 +178,11 @@ namespace MWWorld // find current cell CellStoreCollection::iterator iter = mActiveCells.begin(); - cellstore = *active; + while (iter!=mActiveCells.end()) { + cellstore = *iter; assert (!(iter->first->cell->data.flags & ESM::Cell::Interior)); if (X==cellstore->cell->data.gridX && From 15fcdc8b724d2fcbc71bf03fe2450fde93d2e940 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Thu, 17 Nov 2011 19:38:52 -0500 Subject: [PATCH 050/104] Physics working --- apps/openmw/mwclass/activator.cpp | 2 +- apps/openmw/mwclass/apparatus.cpp | 2 +- apps/openmw/mwclass/armor.cpp | 2 +- apps/openmw/mwclass/book.cpp | 2 +- apps/openmw/mwclass/clothing.cpp | 2 +- apps/openmw/mwclass/container.cpp | 2 +- apps/openmw/mwclass/creature.cpp | 2 +- apps/openmw/mwclass/door.cpp | 2 +- apps/openmw/mwclass/ingredient.cpp | 2 +- apps/openmw/mwclass/light.cpp | 2 +- apps/openmw/mwclass/lockpick.cpp | 2 +- apps/openmw/mwclass/misc.cpp | 2 +- apps/openmw/mwclass/npc.cpp | 2 +- apps/openmw/mwclass/potion.cpp | 2 +- apps/openmw/mwclass/probe.cpp | 2 +- apps/openmw/mwclass/repair.cpp | 2 +- apps/openmw/mwclass/static.cpp | 2 +- apps/openmw/mwclass/weapon.cpp | 2 +- apps/openmw/mwworld/physicssystem.cpp | 8 ++++---- apps/openmw/mwworld/physicssystem.hpp | 4 ++-- apps/openmw/mwworld/scene.cpp | 11 ++++++++--- 21 files changed, 32 insertions(+), 27 deletions(-) diff --git a/apps/openmw/mwclass/activator.cpp b/apps/openmw/mwclass/activator.cpp index 0cb640877..fcec0cccc 100644 --- a/apps/openmw/mwclass/activator.cpp +++ b/apps/openmw/mwclass/activator.cpp @@ -36,7 +36,7 @@ namespace MWClass const std::string &model = ref->base->model; assert (ref->base != NULL); if(!model.empty()){ - physics.insertObjectPhysics(ptr); + physics.insertObjectPhysics(ptr, "meshes\\" + model); } } diff --git a/apps/openmw/mwclass/apparatus.cpp b/apps/openmw/mwclass/apparatus.cpp index 74305bead..48ac64137 100644 --- a/apps/openmw/mwclass/apparatus.cpp +++ b/apps/openmw/mwclass/apparatus.cpp @@ -38,7 +38,7 @@ namespace MWClass const std::string &model = ref->base->model; assert (ref->base != NULL); if(!model.empty()){ - physics.insertObjectPhysics(ptr); + physics.insertObjectPhysics(ptr, "meshes\\" + model); } } diff --git a/apps/openmw/mwclass/armor.cpp b/apps/openmw/mwclass/armor.cpp index 457a988ef..477f9659d 100644 --- a/apps/openmw/mwclass/armor.cpp +++ b/apps/openmw/mwclass/armor.cpp @@ -37,7 +37,7 @@ namespace MWClass const std::string &model = ref->base->model; assert (ref->base != NULL); if(!model.empty()){ - physics.insertObjectPhysics(ptr); + physics.insertObjectPhysics(ptr, "meshes\\" + model); } } diff --git a/apps/openmw/mwclass/book.cpp b/apps/openmw/mwclass/book.cpp index 8b2c32dd2..8e9e2f75c 100644 --- a/apps/openmw/mwclass/book.cpp +++ b/apps/openmw/mwclass/book.cpp @@ -38,7 +38,7 @@ namespace MWClass const std::string &model = ref->base->model; assert (ref->base != NULL); if(!model.empty()){ - physics.insertObjectPhysics(ptr); + physics.insertObjectPhysics(ptr, "meshes\\" + model); } } diff --git a/apps/openmw/mwclass/clothing.cpp b/apps/openmw/mwclass/clothing.cpp index ac1b3e139..293e4a200 100644 --- a/apps/openmw/mwclass/clothing.cpp +++ b/apps/openmw/mwclass/clothing.cpp @@ -38,7 +38,7 @@ namespace MWClass const std::string &model = ref->base->model; assert (ref->base != NULL); if(!model.empty()){ - physics.insertObjectPhysics(ptr); + physics.insertObjectPhysics(ptr, "meshes\\" + model); } } diff --git a/apps/openmw/mwclass/container.cpp b/apps/openmw/mwclass/container.cpp index 6fc6f8482..359cb10bf 100644 --- a/apps/openmw/mwclass/container.cpp +++ b/apps/openmw/mwclass/container.cpp @@ -34,7 +34,7 @@ namespace MWClass const std::string &model = ref->base->model; assert (ref->base != NULL); if(!model.empty()){ - physics.insertObjectPhysics(ptr); + physics.insertObjectPhysics(ptr, "meshes\\" + model); } } diff --git a/apps/openmw/mwclass/creature.cpp b/apps/openmw/mwclass/creature.cpp index 39cf94654..416378674 100644 --- a/apps/openmw/mwclass/creature.cpp +++ b/apps/openmw/mwclass/creature.cpp @@ -49,7 +49,7 @@ namespace MWClass const std::string &model = ref->base->model; assert (ref->base != NULL); if(!model.empty()){ - physics.insertActorPhysics(ptr); + physics.insertActorPhysics(ptr, "meshes\\" + model); }*/ } diff --git a/apps/openmw/mwclass/door.cpp b/apps/openmw/mwclass/door.cpp index ccd1515b4..04dd7149d 100644 --- a/apps/openmw/mwclass/door.cpp +++ b/apps/openmw/mwclass/door.cpp @@ -43,7 +43,7 @@ namespace MWClass const std::string &model = ref->base->model; assert (ref->base != NULL); if(!model.empty()){ - physics.insertObjectPhysics(ptr); + physics.insertObjectPhysics(ptr, "meshes\\" + model); } } diff --git a/apps/openmw/mwclass/ingredient.cpp b/apps/openmw/mwclass/ingredient.cpp index 42ae56fce..008c50aa4 100644 --- a/apps/openmw/mwclass/ingredient.cpp +++ b/apps/openmw/mwclass/ingredient.cpp @@ -39,7 +39,7 @@ namespace MWClass const std::string &model = ref->base->model; assert (ref->base != NULL); if(!model.empty()){ - physics.insertObjectPhysics(ptr); + physics.insertObjectPhysics(ptr, "meshes\\" + model); } } diff --git a/apps/openmw/mwclass/light.cpp b/apps/openmw/mwclass/light.cpp index e846e56f8..25fd2dfc3 100644 --- a/apps/openmw/mwclass/light.cpp +++ b/apps/openmw/mwclass/light.cpp @@ -47,7 +47,7 @@ namespace MWClass const std::string &model = ref->base->model; assert (ref->base != NULL); if(!model.empty()){ - physics.insertObjectPhysics(ptr); + physics.insertObjectPhysics(ptr, "meshes\\" + model); } } diff --git a/apps/openmw/mwclass/lockpick.cpp b/apps/openmw/mwclass/lockpick.cpp index f74536dfc..567ba5eed 100644 --- a/apps/openmw/mwclass/lockpick.cpp +++ b/apps/openmw/mwclass/lockpick.cpp @@ -37,7 +37,7 @@ namespace MWClass const std::string &model = ref->base->model; assert (ref->base != NULL); if(!model.empty()){ - physics.insertObjectPhysics(ptr); + physics.insertObjectPhysics(ptr, "meshes\\" + model); } } diff --git a/apps/openmw/mwclass/misc.cpp b/apps/openmw/mwclass/misc.cpp index 97bbcce2e..163d66959 100644 --- a/apps/openmw/mwclass/misc.cpp +++ b/apps/openmw/mwclass/misc.cpp @@ -37,7 +37,7 @@ namespace MWClass const std::string &model = ref->base->model; assert (ref->base != NULL); if(!model.empty()){ - physics.insertObjectPhysics(ptr); + physics.insertObjectPhysics(ptr, "meshes\\" + model); } } diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index 47d62f96b..bc7fc93f8 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -58,7 +58,7 @@ namespace MWClass const std::string &model = ref->base->model; assert (ref->base != NULL); if(!model.empty()){ - physics.insertActorPhysics(ptr); + physics.insertActorPhysics(ptr, "meshes\\" + model); }*/ } diff --git a/apps/openmw/mwclass/potion.cpp b/apps/openmw/mwclass/potion.cpp index bf14c3cc8..50b454fc2 100644 --- a/apps/openmw/mwclass/potion.cpp +++ b/apps/openmw/mwclass/potion.cpp @@ -38,7 +38,7 @@ namespace MWClass const std::string &model = ref->base->model; assert (ref->base != NULL); if(!model.empty()){ - physics.insertObjectPhysics(ptr); + physics.insertObjectPhysics(ptr, "meshes\\" + model); } } diff --git a/apps/openmw/mwclass/probe.cpp b/apps/openmw/mwclass/probe.cpp index 72bdd292c..b626e823d 100644 --- a/apps/openmw/mwclass/probe.cpp +++ b/apps/openmw/mwclass/probe.cpp @@ -38,7 +38,7 @@ namespace MWClass const std::string &model = ref->base->model; assert (ref->base != NULL); if(!model.empty()){ - physics.insertObjectPhysics(ptr); + physics.insertObjectPhysics(ptr, "meshes\\" + model); } } diff --git a/apps/openmw/mwclass/repair.cpp b/apps/openmw/mwclass/repair.cpp index 28e65fa10..b8220516b 100644 --- a/apps/openmw/mwclass/repair.cpp +++ b/apps/openmw/mwclass/repair.cpp @@ -37,7 +37,7 @@ namespace MWClass const std::string &model = ref->base->model; assert (ref->base != NULL); if(!model.empty()){ - physics.insertObjectPhysics(ptr); + physics.insertObjectPhysics(ptr, "meshes\\" + model); } } diff --git a/apps/openmw/mwclass/static.cpp b/apps/openmw/mwclass/static.cpp index cdbd3bfe9..573a64519 100644 --- a/apps/openmw/mwclass/static.cpp +++ b/apps/openmw/mwclass/static.cpp @@ -33,7 +33,7 @@ namespace MWClass const std::string &model = ref->base->model; assert (ref->base != NULL); if(!model.empty()){ - physics.insertObjectPhysics(ptr); + physics.insertObjectPhysics(ptr, "meshes\\" + model); } } diff --git a/apps/openmw/mwclass/weapon.cpp b/apps/openmw/mwclass/weapon.cpp index b13480600..bd31a8896 100644 --- a/apps/openmw/mwclass/weapon.cpp +++ b/apps/openmw/mwclass/weapon.cpp @@ -38,7 +38,7 @@ namespace MWClass const std::string &model = ref->base->model; assert (ref->base != NULL); if(!model.empty()){ - physics.insertObjectPhysics(ptr); + physics.insertObjectPhysics(ptr, "meshes\\" + model); } } diff --git a/apps/openmw/mwworld/physicssystem.cpp b/apps/openmw/mwworld/physicssystem.cpp index 6ba4805aa..eb5c3c91c 100644 --- a/apps/openmw/mwworld/physicssystem.cpp +++ b/apps/openmw/mwworld/physicssystem.cpp @@ -183,15 +183,15 @@ namespace MWWorld throw std::logic_error ("can't find player"); } - void PhysicsSystem::insertObjectPhysics(const MWWorld::Ptr& ptr){ + void PhysicsSystem::insertObjectPhysics(const MWWorld::Ptr& ptr, const std::string model){ Ogre::SceneNode* node = ptr.getRefData().getBaseNode(); - addObject (node->getName(), node->getName(), node->getOrientation(), + addObject (node->getName(), model, node->getOrientation(), node->getScale().x, node->getPosition()); } - void PhysicsSystem::insertActorPhysics(const MWWorld::Ptr& ptr){ + void PhysicsSystem::insertActorPhysics(const MWWorld::Ptr& ptr, const std::string model){ Ogre::SceneNode* node = ptr.getRefData().getBaseNode(); - addActor (node->getName(), node->getName(), node->getPosition()); + addActor (node->getName(), model, node->getPosition()); } } diff --git a/apps/openmw/mwworld/physicssystem.hpp b/apps/openmw/mwworld/physicssystem.hpp index 789c81c45..a447d7bc1 100644 --- a/apps/openmw/mwworld/physicssystem.hpp +++ b/apps/openmw/mwworld/physicssystem.hpp @@ -35,9 +35,9 @@ namespace MWWorld bool toggleCollisionMode(); std::pair getFacedHandle (MWWorld::World& world); - void insertObjectPhysics(const MWWorld::Ptr& ptr); + void insertObjectPhysics(const MWWorld::Ptr& ptr, std::string model); - void insertActorPhysics(const MWWorld::Ptr& ptr); + void insertActorPhysics(const MWWorld::Ptr&, std::string model); private: OEngine::Render::OgreRenderer &mRender; diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index fcf8603d3..f264afde8 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -57,7 +57,6 @@ void insertCellRefList(MWRender::RenderingManager& rendering, MWWorld::Environme try { - rendering.addObject(ptr); class_.insertObject(ptr, physics, environment); class_.enable (ptr, environment); @@ -101,14 +100,17 @@ namespace MWWorld void Scene::loadCell (Ptr::CellStore *cell) { + std::cout << "Start load\n"; // register local scripts mWorld->getLocalScripts().addCell (cell); // This connects the cell data with the rendering scene. mActiveCells.insert(cell); - - mRendering.getObjects().buildStaticGeometry(*cell); + std::cout << "Before static\n"; + insertCell(*cell, mEnvironment); + mRendering.getObjects().buildStaticGeometry(*cell); + std::cout << "Done loading cell\n"; } @@ -228,6 +230,7 @@ namespace MWWorld void Scene::changeToInteriorCell (const std::string& cellName, const ESM::Position& position) { + std::cout << "Changing to interior\n"; // remove active CellStoreCollection::iterator active = mActiveCells.begin(); @@ -309,7 +312,9 @@ void Scene::insertCell(ESMS::CellStore &cell, MWWorld::Environment& environment) { // Loop through all references in the cell + std::cout << "Reflist1\n"; insertCellRefList(mRendering, environment, cell.activators, cell, *mPhysics); + std::cout << "Reflist2\n"; insertCellRefList(mRendering, environment, cell.potions, cell, *mPhysics); insertCellRefList(mRendering, environment, cell.appas, cell, *mPhysics); insertCellRefList(mRendering, environment, cell.armors, cell, *mPhysics); From 7319f7a8c6b4b8f8b59de46d90dfdc26372a3bb2 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Sat, 19 Nov 2011 01:01:19 -0500 Subject: [PATCH 051/104] Many bugs fixed related to changing cells --- apps/openmw/mwclass/activator.cpp | 2 +- apps/openmw/mwclass/apparatus.cpp | 2 +- apps/openmw/mwclass/armor.cpp | 2 +- apps/openmw/mwclass/book.cpp | 2 +- apps/openmw/mwclass/clothing.cpp | 2 +- apps/openmw/mwclass/container.cpp | 2 +- apps/openmw/mwclass/creature.cpp | 2 +- apps/openmw/mwclass/door.cpp | 2 +- apps/openmw/mwclass/ingredient.cpp | 2 +- apps/openmw/mwclass/light.cpp | 2 +- apps/openmw/mwclass/lockpick.cpp | 2 +- apps/openmw/mwclass/misc.cpp | 2 +- apps/openmw/mwclass/npc.cpp | 2 +- apps/openmw/mwclass/potion.cpp | 2 +- apps/openmw/mwclass/probe.cpp | 2 +- apps/openmw/mwclass/repair.cpp | 2 +- apps/openmw/mwclass/static.cpp | 2 +- apps/openmw/mwclass/weapon.cpp | 2 +- apps/openmw/mwrender/objects.cpp | 14 +++---- apps/openmw/mwrender/objects.hpp | 2 +- apps/openmw/mwrender/renderingmanager.cpp | 2 +- apps/openmw/mwrender/renderingmanager.hpp | 7 ++-- apps/openmw/mwworld/cellfunctors.hpp | 6 +-- apps/openmw/mwworld/scene.cpp | 50 +++++++++++++---------- components/esm_store/cell_store.hpp | 2 +- 25 files changed, 63 insertions(+), 56 deletions(-) diff --git a/apps/openmw/mwclass/activator.cpp b/apps/openmw/mwclass/activator.cpp index fcec0cccc..6749a2bfd 100644 --- a/apps/openmw/mwclass/activator.cpp +++ b/apps/openmw/mwclass/activator.cpp @@ -21,7 +21,7 @@ namespace MWClass if (!model.empty()) { - MWRender::Objects objects = renderingInterface.getObjects(); + MWRender::Objects& objects = renderingInterface.getObjects(); objects.insertBegin(ptr, ptr.getRefData().isEnabled(), false); objects.insertMesh(ptr, "meshes\\" + model); } diff --git a/apps/openmw/mwclass/apparatus.cpp b/apps/openmw/mwclass/apparatus.cpp index 48ac64137..30b308e70 100644 --- a/apps/openmw/mwclass/apparatus.cpp +++ b/apps/openmw/mwclass/apparatus.cpp @@ -23,7 +23,7 @@ namespace MWClass if (!model.empty()) { - MWRender::Objects objects = renderingInterface.getObjects(); + MWRender::Objects& objects = renderingInterface.getObjects(); objects.insertBegin(ptr, ptr.getRefData().isEnabled(), false); objects.insertMesh(ptr, "meshes\\" + model); } diff --git a/apps/openmw/mwclass/armor.cpp b/apps/openmw/mwclass/armor.cpp index 477f9659d..a8a431acf 100644 --- a/apps/openmw/mwclass/armor.cpp +++ b/apps/openmw/mwclass/armor.cpp @@ -23,7 +23,7 @@ namespace MWClass if (!model.empty()) { - MWRender::Objects objects = renderingInterface.getObjects(); + MWRender::Objects& objects = renderingInterface.getObjects(); objects.insertBegin(ptr, ptr.getRefData().isEnabled(), false); objects.insertMesh(ptr, "meshes\\" + model); } diff --git a/apps/openmw/mwclass/book.cpp b/apps/openmw/mwclass/book.cpp index 8e9e2f75c..011fd2c32 100644 --- a/apps/openmw/mwclass/book.cpp +++ b/apps/openmw/mwclass/book.cpp @@ -23,7 +23,7 @@ namespace MWClass if (!model.empty()) { - MWRender::Objects objects = renderingInterface.getObjects(); + MWRender::Objects& objects = renderingInterface.getObjects(); objects.insertBegin(ptr, ptr.getRefData().isEnabled(), false); objects.insertMesh(ptr, "meshes\\" + model); } diff --git a/apps/openmw/mwclass/clothing.cpp b/apps/openmw/mwclass/clothing.cpp index 293e4a200..0214c72ad 100644 --- a/apps/openmw/mwclass/clothing.cpp +++ b/apps/openmw/mwclass/clothing.cpp @@ -23,7 +23,7 @@ namespace MWClass if (!model.empty()) { - MWRender::Objects objects = renderingInterface.getObjects(); + MWRender::Objects& objects = renderingInterface.getObjects(); objects.insertBegin(ptr, ptr.getRefData().isEnabled(), false); objects.insertMesh(ptr, "meshes\\" + model); } diff --git a/apps/openmw/mwclass/container.cpp b/apps/openmw/mwclass/container.cpp index 359cb10bf..4157ce17a 100644 --- a/apps/openmw/mwclass/container.cpp +++ b/apps/openmw/mwclass/container.cpp @@ -19,7 +19,7 @@ namespace MWClass if (!model.empty()) { - MWRender::Objects objects = renderingInterface.getObjects(); + MWRender::Objects& objects = renderingInterface.getObjects(); objects.insertBegin(ptr, ptr.getRefData().isEnabled(), false); objects.insertMesh(ptr, "meshes\\" + model); } diff --git a/apps/openmw/mwclass/creature.cpp b/apps/openmw/mwclass/creature.cpp index 416378674..852701cce 100644 --- a/apps/openmw/mwclass/creature.cpp +++ b/apps/openmw/mwclass/creature.cpp @@ -33,7 +33,7 @@ namespace MWClass if (!model.empty()) { - MWRender::Creatures creatures = renderingInterface.getCreatures(); + MWRender::Creatures& creatures = renderingInterface.getCreatures(); //creatures.insertBegin(ptr, ptr.getRefData().isEnabled(), false); //creatures.insertMesh(ptr, "meshes\\" + model); }*/ diff --git a/apps/openmw/mwclass/door.cpp b/apps/openmw/mwclass/door.cpp index 04dd7149d..26436a012 100644 --- a/apps/openmw/mwclass/door.cpp +++ b/apps/openmw/mwclass/door.cpp @@ -28,7 +28,7 @@ namespace MWClass if (!model.empty()) { - MWRender::Objects objects = renderingInterface.getObjects(); + MWRender::Objects& objects = renderingInterface.getObjects(); objects.insertBegin(ptr, ptr.getRefData().isEnabled(), false); objects.insertMesh(ptr, "meshes\\" + model); } diff --git a/apps/openmw/mwclass/ingredient.cpp b/apps/openmw/mwclass/ingredient.cpp index 008c50aa4..5e55010eb 100644 --- a/apps/openmw/mwclass/ingredient.cpp +++ b/apps/openmw/mwclass/ingredient.cpp @@ -23,7 +23,7 @@ namespace MWClass if (!model.empty()) { - MWRender::Objects objects = renderingInterface.getObjects(); + MWRender::Objects& objects = renderingInterface.getObjects(); objects.insertBegin(ptr, ptr.getRefData().isEnabled(), false); objects.insertMesh(ptr, "meshes\\" + model); } diff --git a/apps/openmw/mwclass/light.cpp b/apps/openmw/mwclass/light.cpp index 25fd2dfc3..3890899b0 100644 --- a/apps/openmw/mwclass/light.cpp +++ b/apps/openmw/mwclass/light.cpp @@ -26,7 +26,7 @@ namespace MWClass if (!model.empty()) { - MWRender::Objects objects = renderingInterface.getObjects(); + MWRender::Objects& objects = renderingInterface.getObjects(); objects.insertBegin(ptr, ptr.getRefData().isEnabled(), false); objects.insertMesh(ptr, "meshes\\" + model); const int color = ref->base->data.color; diff --git a/apps/openmw/mwclass/lockpick.cpp b/apps/openmw/mwclass/lockpick.cpp index 567ba5eed..636a8f0be 100644 --- a/apps/openmw/mwclass/lockpick.cpp +++ b/apps/openmw/mwclass/lockpick.cpp @@ -22,7 +22,7 @@ namespace MWClass if (!model.empty()) { - MWRender::Objects objects = renderingInterface.getObjects(); + MWRender::Objects& objects = renderingInterface.getObjects(); objects.insertBegin(ptr, ptr.getRefData().isEnabled(), false); objects.insertMesh(ptr, "meshes\\" + model); } diff --git a/apps/openmw/mwclass/misc.cpp b/apps/openmw/mwclass/misc.cpp index 163d66959..a2642d8d5 100644 --- a/apps/openmw/mwclass/misc.cpp +++ b/apps/openmw/mwclass/misc.cpp @@ -22,7 +22,7 @@ namespace MWClass if (!model.empty()) { - MWRender::Objects objects = renderingInterface.getObjects(); + MWRender::Objects& objects = renderingInterface.getObjects(); objects.insertBegin(ptr, ptr.getRefData().isEnabled(), false); objects.insertMesh(ptr, "meshes\\" + model); } diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index bc7fc93f8..cce23407f 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -41,7 +41,7 @@ namespace MWClass if (!model.empty()) { - MWRender::Npcs npcs = renderingInterface.getNPCs(); + MWRender::Npcs& npcs = renderingInterface.getNPCs(); //npcs.insertBegin(ptr, ptr.getRefData().isEnabled(), false); //npcs.insertMesh(ptr, "meshes\\" + model); }*/ diff --git a/apps/openmw/mwclass/potion.cpp b/apps/openmw/mwclass/potion.cpp index 50b454fc2..86d1e2a98 100644 --- a/apps/openmw/mwclass/potion.cpp +++ b/apps/openmw/mwclass/potion.cpp @@ -23,7 +23,7 @@ namespace MWClass if (!model.empty()) { - MWRender::Objects objects = renderingInterface.getObjects(); + MWRender::Objects& objects = renderingInterface.getObjects(); objects.insertBegin(ptr, ptr.getRefData().isEnabled(), false); objects.insertMesh(ptr, "meshes\\" + model); } diff --git a/apps/openmw/mwclass/probe.cpp b/apps/openmw/mwclass/probe.cpp index b626e823d..a09a39e66 100644 --- a/apps/openmw/mwclass/probe.cpp +++ b/apps/openmw/mwclass/probe.cpp @@ -23,7 +23,7 @@ namespace MWClass if (!model.empty()) { - MWRender::Objects objects = renderingInterface.getObjects(); + MWRender::Objects& objects = renderingInterface.getObjects(); objects.insertBegin(ptr, ptr.getRefData().isEnabled(), false); objects.insertMesh(ptr, "meshes\\" + model); } diff --git a/apps/openmw/mwclass/repair.cpp b/apps/openmw/mwclass/repair.cpp index b8220516b..f8755b2eb 100644 --- a/apps/openmw/mwclass/repair.cpp +++ b/apps/openmw/mwclass/repair.cpp @@ -22,7 +22,7 @@ namespace MWClass if (!model.empty()) { - MWRender::Objects objects = renderingInterface.getObjects(); + MWRender::Objects& objects = renderingInterface.getObjects(); objects.insertBegin(ptr, ptr.getRefData().isEnabled(), false); objects.insertMesh(ptr, "meshes\\" + model); } diff --git a/apps/openmw/mwclass/static.cpp b/apps/openmw/mwclass/static.cpp index 573a64519..946da311d 100644 --- a/apps/openmw/mwclass/static.cpp +++ b/apps/openmw/mwclass/static.cpp @@ -18,7 +18,7 @@ namespace MWClass if (!model.empty()) { - MWRender::Objects objects = renderingInterface.getObjects(); + MWRender::Objects& objects = renderingInterface.getObjects(); objects.insertBegin(ptr, ptr.getRefData().isEnabled(), false); objects.insertMesh(ptr, "meshes\\" + model); } diff --git a/apps/openmw/mwclass/weapon.cpp b/apps/openmw/mwclass/weapon.cpp index bd31a8896..1fbd21f7c 100644 --- a/apps/openmw/mwclass/weapon.cpp +++ b/apps/openmw/mwclass/weapon.cpp @@ -23,7 +23,7 @@ namespace MWClass if (!model.empty()) { - MWRender::Objects objects = renderingInterface.getObjects(); + MWRender::Objects& objects = renderingInterface.getObjects(); objects.insertBegin(ptr, ptr.getRefData().isEnabled(), false); objects.insertMesh(ptr, "meshes\\" + model); } diff --git a/apps/openmw/mwrender/objects.cpp b/apps/openmw/mwrender/objects.cpp index 2e5a07b60..e49e448ae 100644 --- a/apps/openmw/mwrender/objects.cpp +++ b/apps/openmw/mwrender/objects.cpp @@ -40,8 +40,6 @@ void Objects::insertBegin (const MWWorld::Ptr& ptr, bool enabled, bool static_){ cellnode = mCellSceneNodes[ptr.getCell()]; } - - Ogre::SceneNode* insert = cellnode->createChildSceneNode(); const float *f = ptr.getRefData().getPosition().pos; insert->setPosition(f[0], f[1], f[2]); @@ -100,6 +98,7 @@ void Objects::insertMesh (const MWWorld::Ptr& ptr, const std::string& mesh){ mRend.getScene()->destroyEntity(ent); } + } void Objects::insertLight (const MWWorld::Ptr& ptr, float r, float g, float b, float radius){ @@ -146,19 +145,19 @@ void Objects::deleteObject (const std::string& handle) } } -void Objects::removeCell(const MWWorld::Ptr& ptr){ - if(mCellSceneNodes.find(ptr.getCell()) != mCellSceneNodes.end()) +void Objects::removeCell(MWWorld::Ptr::CellStore* store){ + if(mCellSceneNodes.find(store) != mCellSceneNodes.end()) { - Ogre::SceneNode* base = mCellSceneNodes[ptr.getCell()]; + Ogre::SceneNode* base = mCellSceneNodes[store]; base->removeAndDestroyAllChildren(); mRend.getScene()->destroySceneNode(base); base = 0; } - if(mSG.find(ptr.getCell()) != mSG.end()) + if(mSG.find(store) != mSG.end()) { - Ogre::StaticGeometry* sg = mSG[ptr.getCell()]; + Ogre::StaticGeometry* sg = mSG[store]; mRend.getScene()->destroyStaticGeometry (sg); sg = 0; } @@ -171,3 +170,4 @@ void Objects::buildStaticGeometry(ESMS::CellStore& cell){ } } + diff --git a/apps/openmw/mwrender/objects.hpp b/apps/openmw/mwrender/objects.hpp index 9c5f796a1..e7fb716b8 100644 --- a/apps/openmw/mwrender/objects.hpp +++ b/apps/openmw/mwrender/objects.hpp @@ -37,7 +37,7 @@ public: void insertMesh (const MWWorld::Ptr& ptr, const std::string& mesh); void insertLight (const MWWorld::Ptr& ptr, float r, float g, float b, float radius); void deleteObject (const std::string& handle); - void removeCell(const MWWorld::Ptr& ptr); + void removeCell(MWWorld::Ptr::CellStore* store); void buildStaticGeometry(ESMS::CellStore &cell); void setMwRoot(Ogre::SceneNode* root); diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index 9fb9dd98c..fffa6f3d6 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -82,7 +82,7 @@ MWRender::Player& RenderingManager::getPlayer(){ void RenderingManager::removeCell (MWWorld::Ptr::CellStore *store){ - + objects.removeCell(store); } void RenderingManager::addObject (const MWWorld::Ptr& ptr){ const MWWorld::Class& class_ = diff --git a/apps/openmw/mwrender/renderingmanager.hpp b/apps/openmw/mwrender/renderingmanager.hpp index 4e51442bd..e4dc5deb4 100644 --- a/apps/openmw/mwrender/renderingmanager.hpp +++ b/apps/openmw/mwrender/renderingmanager.hpp @@ -88,11 +88,12 @@ class RenderingManager: private RenderingInterface { OEngine::Render::OgreRenderer& getOgreRenderer(){return rend;} Ogre::SceneManager *getMgr() { return rend.getScene(); } Ogre::SceneNode *getRoot() { return mwRoot; } - - private: - void configureAmbient(ESMS::CellStore &mCell); + void configureAmbient(ESMS::CellStore &mCell); /// configure fog according to cell void configureFog(ESMS::CellStore &mCell); + + private: + void setAmbientMode(); SkyManager* mSkyManager; OEngine::Render::OgreRenderer &rend; diff --git a/apps/openmw/mwworld/cellfunctors.hpp b/apps/openmw/mwworld/cellfunctors.hpp index 5ff801f01..8bba898ce 100644 --- a/apps/openmw/mwworld/cellfunctors.hpp +++ b/apps/openmw/mwworld/cellfunctors.hpp @@ -16,12 +16,12 @@ namespace MWWorld /// List all (Ogre-)handles. struct ListHandles { - std::vector mHandles; + std::vector mHandles; bool operator() (ESM::CellRef& ref, RefData& data) { - std::string handle = data.getHandle(); - if (!handle.empty()) + Ogre::SceneNode* handle = data.getBaseNode(); + if (handle) mHandles.push_back (handle); return true; } diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index f264afde8..c9d477833 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -79,38 +79,46 @@ namespace MWWorld void Scene::unloadCell (CellStoreCollection::iterator iter) { + ListHandles functor; - Ptr::CellStore* cellstore = *iter; - - cellstore->forEach(functor); - - { // silence annoying g++ warning - for (std::vector::const_iterator iter (functor.mHandles.begin()); - iter!=functor.mHandles.end(); ++iter) - mPhysics->removeObject (*iter); - } + + MWWorld::Ptr::CellStore* active = *iter; + mRendering.removeCell(active); + + active->forEach(functor); - mWorld->getLocalScripts().clearCell (cellstore); + { - mEnvironment.mMechanicsManager->dropActors (cellstore); - mEnvironment.mSoundManager->stopSound (cellstore); - //delete iter->second; + + // silence annoying g++ warning + for (std::vector::const_iterator iter (functor.mHandles.begin()); + iter!=functor.mHandles.end(); ++iter){ + Ogre::SceneNode* node = *iter; + mPhysics->removeObject (node->getName()); + } + } + mWorld->getLocalScripts().clearCell (active); + mEnvironment.mMechanicsManager->dropActors (active); + mEnvironment.mSoundManager->stopSound (active); mActiveCells.erase (iter); } void Scene::loadCell (Ptr::CellStore *cell) { - std::cout << "Start load\n"; // register local scripts mWorld->getLocalScripts().addCell (cell); - // This connects the cell data with the rendering scene. + + + std::pair result = mActiveCells.insert(cell); - std::cout << "Before static\n"; + if(result.second){ + insertCell(*cell, mEnvironment); + mRendering.getObjects().buildStaticGeometry(*cell); + mRendering.configureAmbient(*cell); + + } - insertCell(*cell, mEnvironment); - mRendering.getObjects().buildStaticGeometry(*cell); - std::cout << "Done loading cell\n"; } @@ -233,7 +241,7 @@ namespace MWWorld std::cout << "Changing to interior\n"; // remove active CellStoreCollection::iterator active = mActiveCells.begin(); - + std::cout << "Size: " << mActiveCells.size() << "\n"; while (active!=mActiveCells.end()) { unloadCell (active++); @@ -312,9 +320,7 @@ void Scene::insertCell(ESMS::CellStore &cell, MWWorld::Environment& environment) { // Loop through all references in the cell - std::cout << "Reflist1\n"; insertCellRefList(mRendering, environment, cell.activators, cell, *mPhysics); - std::cout << "Reflist2\n"; insertCellRefList(mRendering, environment, cell.potions, cell, *mPhysics); insertCellRefList(mRendering, environment, cell.appas, cell, *mPhysics); insertCellRefList(mRendering, environment, cell.armors, cell, *mPhysics); diff --git a/components/esm_store/cell_store.hpp b/components/esm_store/cell_store.hpp index 12f644417..d064312f1 100644 --- a/components/esm_store/cell_store.hpp +++ b/components/esm_store/cell_store.hpp @@ -187,7 +187,7 @@ namespace ESMS ++iter) if (!functor (iter->ref, iter->mData)) return false; - + return true; } From d8367f4968420d956f666d9ff70e96266b9bf204 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Sat, 19 Nov 2011 17:45:05 -0500 Subject: [PATCH 052/104] Activation fix --- apps/openmw/engine.cpp | 4 ---- apps/openmw/mwworld/world.cpp | 22 ++-------------------- 2 files changed, 2 insertions(+), 24 deletions(-) diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index daa9b508e..acff9c8be 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -417,15 +417,11 @@ void OMW::Engine::activate() 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); diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index 4ab46f008..93cf19aef 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -53,12 +53,13 @@ namespace for (iterator iter (refList.list.begin()); iter!=refList.list.end(); ++iter) { + if(iter->mData.getBaseNode()){ if (iter->mData.getHandle()==handle) { return &*iter; } + } } - return 0; } } @@ -70,61 +71,43 @@ namespace MWWorld if (ESMS::LiveCellRef *ref = searchViaHandle (handle, cell.activators)) return Ptr (ref, &cell); - if (ESMS::LiveCellRef *ref = searchViaHandle (handle, cell.potions)) return Ptr (ref, &cell); - if (ESMS::LiveCellRef *ref = searchViaHandle (handle, cell.appas)) return Ptr (ref, &cell); - if (ESMS::LiveCellRef *ref = searchViaHandle (handle, cell.armors)) return Ptr (ref, &cell); - if (ESMS::LiveCellRef *ref = searchViaHandle (handle, cell.books)) return Ptr (ref, &cell); - if (ESMS::LiveCellRef *ref = searchViaHandle (handle, cell.clothes)) return Ptr (ref, &cell); - if (ESMS::LiveCellRef *ref = searchViaHandle (handle, cell.containers)) return Ptr (ref, &cell); - if (ESMS::LiveCellRef *ref = searchViaHandle (handle, cell.creatures)) return Ptr (ref, &cell); - if (ESMS::LiveCellRef *ref = searchViaHandle (handle, cell.doors)) return Ptr (ref, &cell); - if (ESMS::LiveCellRef *ref = searchViaHandle (handle, cell.ingreds)) return Ptr (ref, &cell); - if (ESMS::LiveCellRef *ref = searchViaHandle (handle, cell.lights)) return Ptr (ref, &cell); - if (ESMS::LiveCellRef *ref = searchViaHandle (handle, cell.lockpicks)) return Ptr (ref, &cell); - if (ESMS::LiveCellRef *ref = searchViaHandle (handle, cell.miscItems)) return Ptr (ref, &cell); - if (ESMS::LiveCellRef *ref = searchViaHandle (handle, cell.npcs)) return Ptr (ref, &cell); - if (ESMS::LiveCellRef *ref = searchViaHandle (handle, cell.probes)) return Ptr (ref, &cell); - if (ESMS::LiveCellRef *ref = searchViaHandle (handle, cell.repairs)) return Ptr (ref, &cell); - if (ESMS::LiveCellRef *ref = searchViaHandle (handle, cell.statics)) return Ptr (ref, &cell); - if (ESMS::LiveCellRef *ref = searchViaHandle (handle, cell.weapons)) return Ptr (ref, &cell); - return Ptr(); } @@ -317,7 +300,6 @@ namespace MWWorld { if (mPlayer->getPlayer().getRefData().getHandle()==handle) return mPlayer->getPlayer(); - for (Scene::CellStoreCollection::const_iterator iter (mWorldScene->getActiveCells().begin()); iter!=mWorldScene->getActiveCells().end(); ++iter) { From 7385948056da7eb6f87cda4c9b3a946c50094c08 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Sat, 19 Nov 2011 20:22:56 -0500 Subject: [PATCH 053/104] Yet another crash fix --- apps/openmw/mwrender/objects.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/apps/openmw/mwrender/objects.cpp b/apps/openmw/mwrender/objects.cpp index e49e448ae..ade1127af 100644 --- a/apps/openmw/mwrender/objects.cpp +++ b/apps/openmw/mwrender/objects.cpp @@ -150,6 +150,7 @@ void Objects::removeCell(MWWorld::Ptr::CellStore* store){ { Ogre::SceneNode* base = mCellSceneNodes[store]; base->removeAndDestroyAllChildren(); + mCellSceneNodes.erase(store); mRend.getScene()->destroySceneNode(base); base = 0; } @@ -158,6 +159,7 @@ void Objects::removeCell(MWWorld::Ptr::CellStore* store){ if(mSG.find(store) != mSG.end()) { Ogre::StaticGeometry* sg = mSG[store]; + mSG.erase(store); mRend.getScene()->destroyStaticGeometry (sg); sg = 0; } From 0f4adc39b3483a15c3576af128bc9b56a8caf32a Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Mon, 21 Nov 2011 14:08:44 +0100 Subject: [PATCH 054/104] added animation-related script instructions --- apps/openmw/CMakeLists.txt | 1 + apps/openmw/mwrender/renderingmanager.cpp | 9 ++ apps/openmw/mwrender/renderingmanager.hpp | 12 ++ apps/openmw/mwscript/animationextensions.cpp | 127 +++++++++++++++++++ apps/openmw/mwscript/animationextensions.hpp | 24 ++++ apps/openmw/mwscript/docs/vmformat.txt | 10 +- apps/openmw/mwscript/extensions.cpp | 3 + apps/openmw/mwworld/world.cpp | 11 ++ apps/openmw/mwworld/world.hpp | 18 ++- 9 files changed, 210 insertions(+), 5 deletions(-) create mode 100644 apps/openmw/mwscript/animationextensions.cpp create mode 100644 apps/openmw/mwscript/animationextensions.hpp diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index e17a2cb25..b3bd51e20 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -36,6 +36,7 @@ add_openmw_dir (mwscript locals scriptmanager compilercontext interpretercontext cellextensions miscextensions guiextensions soundextensions skyextensions statsextensions containerextensions aiextensions controlextensions extensions globalscripts ref dialogueextensions + animationextensions ) add_openmw_dir (mwsound diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index 06339cdd4..2a198b5f4 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -225,6 +225,15 @@ void RenderingManager::toggleLight() setAmbientMode(); } +void RenderingManager::playAnimationGroup (const MWWorld::Ptr& ptr, const std::string& groupName, + int mode, int number) +{ +std::cout<<"play animation " << groupName << ", " << mode << ", " << number << std::endl; +} +void RenderingManager::skipAnimation (const MWWorld::Ptr& ptr) +{ +std::cout<<"skip animation"< &mCell); + void playAnimationGroup (const MWWorld::Ptr& ptr, const std::string& groupName, int mode, + int number = 1); + ///< Run animation for a MW-reference. Calls to this function for references that are currently not + /// in the rendered scene should be ignored. + /// + /// \param mode: 0 normal, 1 immediate start, 2 immediate loop + /// \param number How offen the animation should be run + + void skipAnimation (const MWWorld::Ptr& ptr); + ///< Skip the animation for the given MW-reference for one frame. Calls to this function for + /// references that are currently not in the rendered scene should be ignored. + private: void setAmbientMode(); diff --git a/apps/openmw/mwscript/animationextensions.cpp b/apps/openmw/mwscript/animationextensions.cpp new file mode 100644 index 000000000..184be83db --- /dev/null +++ b/apps/openmw/mwscript/animationextensions.cpp @@ -0,0 +1,127 @@ + +#include "animationextensions.hpp" + +#include + +#include + +#include +#include +#include + +#include "../mwworld/world.hpp" + +#include "interpretercontext.hpp" +#include "ref.hpp" + +namespace MWScript +{ + namespace Animation + { + template + class OpSkipAnim : public Interpreter::Opcode0 + { + public: + + virtual void execute (Interpreter::Runtime& runtime) + { + MWWorld::Ptr ptr = R()(runtime); + + InterpreterContext& context = + static_cast (runtime.getContext()); + + context.getWorld().skipAnimation (ptr); + } + }; + + template + class OpPlayAnim : public Interpreter::Opcode1 + { + public: + + virtual void execute (Interpreter::Runtime& runtime, unsigned int arg0) + { + MWWorld::Ptr ptr = R()(runtime); + + InterpreterContext& context = + static_cast (runtime.getContext()); + + std::string group = runtime.getStringLiteral (runtime[0].mInteger); + runtime.pop(); + + Interpreter::Type_Integer mode = 0; + + if (arg0==1) + { + mode = runtime[0].mInteger; + runtime.pop(); + + if (mode<0 || mode>2) + throw std::runtime_error ("animation mode out of range"); + } + + context.getWorld().playAnimationGroup (ptr, group, mode, 1); + } + }; + + template + class OpLoopAnim : public Interpreter::Opcode1 + { + public: + + virtual void execute (Interpreter::Runtime& runtime, unsigned int arg0) + { + MWWorld::Ptr ptr = R()(runtime); + + InterpreterContext& context = + static_cast (runtime.getContext()); + + std::string group = runtime.getStringLiteral (runtime[0].mInteger); + runtime.pop(); + + Interpreter::Type_Integer loops = runtime[0].mInteger; + runtime.pop(); + + if (loops<0) + throw std::runtime_error ("number of animation loops must be non-negative"); + + Interpreter::Type_Integer mode = 0; + + if (arg0==1) + { + mode = runtime[0].mInteger; + runtime.pop(); + + if (mode<0 || mode>2) + throw std::runtime_error ("animation mode out of range"); + } + + context.getWorld().playAnimationGroup (ptr, group, mode, loops); + } + }; + + const int opcodeSkipAnim = 0x2000138; + const int opcodeSkipAnimExplicit = 0x2000139; + const int opcodePlayAnim = 0x20006; + const int opcodePlayAnimExplicit = 0x20007; + const int opcodeLoopAnim = 0x20008; + const int opcodeLoopAnimExplicit = 0x20009; + + void registerExtensions (Compiler::Extensions& extensions) + { + extensions.registerInstruction ("skipanim", "", opcodeSkipAnim, opcodeSkipAnimExplicit); + extensions.registerInstruction ("playgroup", "c/l", opcodePlayAnim, opcodePlayAnimExplicit); + extensions.registerInstruction ("loopgroup", "cl/l", opcodeLoopAnim, opcodeLoopAnimExplicit); + } + + void installOpcodes (Interpreter::Interpreter& interpreter) + { + interpreter.installSegment5 (opcodeSkipAnim, new OpSkipAnim); + interpreter.installSegment5 (opcodeSkipAnimExplicit, new OpSkipAnim); + interpreter.installSegment3 (opcodePlayAnim, new OpPlayAnim); + interpreter.installSegment3 (opcodePlayAnimExplicit, new OpPlayAnim); + interpreter.installSegment3 (opcodeLoopAnim, new OpLoopAnim); + interpreter.installSegment3 (opcodeLoopAnimExplicit, new OpLoopAnim); + } + } +} diff --git a/apps/openmw/mwscript/animationextensions.hpp b/apps/openmw/mwscript/animationextensions.hpp new file mode 100644 index 000000000..ff619ab73 --- /dev/null +++ b/apps/openmw/mwscript/animationextensions.hpp @@ -0,0 +1,24 @@ +#ifndef GAME_SCRIPT_ANIMATIONEXTENSIONS_H +#define GAME_SCRIPT_ANIMATIONEXTENSIONS_H + +namespace Compiler +{ + class Extensions; +} + +namespace Interpreter +{ + class Interpreter; +} + +namespace MWScript +{ + namespace Animation + { + void registerExtensions (Compiler::Extensions& extensions); + + void installOpcodes (Interpreter::Interpreter& interpreter); + } +} + +#endif diff --git a/apps/openmw/mwscript/docs/vmformat.txt b/apps/openmw/mwscript/docs/vmformat.txt index 33ce38cdd..183605328 100644 --- a/apps/openmw/mwscript/docs/vmformat.txt +++ b/apps/openmw/mwscript/docs/vmformat.txt @@ -19,7 +19,11 @@ op 0x20002: AiEscort op 0x20003: AiEscort, explicit reference op 0x20004: Lock op 0x20005: Lock, explicit reference -opcodes 0x20006-0x3ffff unused +op 0x20006: PlayAnim +op 0x20007: PlayAnim, explicit reference +op 0x20008: LoopAnim +op 0x20009: LoopAnim, explicit reference +opcodes 0x2000a-0x3ffff unused Segment 4: (not implemented yet) @@ -109,4 +113,6 @@ op 0x2000134: SetJournalIndex op 0x2000135: GetJournalIndex op 0x2000136: GetPCCell op 0x2000137: GetButtonPressed -opcodes 0x2000138-0x3ffffff unused +op 0x2000138: SkipAnim +op 0x2000139: SkipAnim, expplicit reference +opcodes 0x200013a-0x3ffffff unused diff --git a/apps/openmw/mwscript/extensions.cpp b/apps/openmw/mwscript/extensions.cpp index 86161d2b1..197494146 100644 --- a/apps/openmw/mwscript/extensions.cpp +++ b/apps/openmw/mwscript/extensions.cpp @@ -14,6 +14,7 @@ #include "aiextensions.hpp" #include "controlextensions.hpp" #include "dialogueextensions.hpp" +#include "animationextensions.hpp" namespace MWScript { @@ -29,6 +30,7 @@ namespace MWScript Ai::registerExtensions (extensions); Control::registerExtensions (extensions); Dialogue::registerExtensions (extensions); + Animation::registerExtensions (extensions); } void installOpcodes (Interpreter::Interpreter& interpreter) @@ -44,5 +46,6 @@ namespace MWScript Ai::installOpcodes (interpreter); Control::installOpcodes (interpreter); Dialogue::installOpcodes (interpreter); + Animation::installOpcodes (interpreter); } } diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index 45f333d9b..126bdaf38 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -673,4 +673,15 @@ namespace MWWorld return cell; } } + + void World::playAnimationGroup (const MWWorld::Ptr& ptr, const std::string& groupName, int mode, + int number) + { + mRendering.playAnimationGroup (ptr, groupName, mode, number); + } + + void World::skipAnimation (const MWWorld::Ptr& ptr) + { + mRendering.skipAnimation (ptr); + } } diff --git a/apps/openmw/mwworld/world.hpp b/apps/openmw/mwworld/world.hpp index ea775453a..2c7b43280 100644 --- a/apps/openmw/mwworld/world.hpp +++ b/apps/openmw/mwworld/world.hpp @@ -66,7 +66,7 @@ namespace MWWorld private: MWRender::RenderingManager mRendering; - + MWWorld::Scene *mWorldScene; MWWorld::Player *mPlayer; ESM::ESMReader mEsm; @@ -132,10 +132,10 @@ namespace MWWorld Ptr getPtrViaHandle (const std::string& handle); ///< Return a pointer to a liveCellRef with the given Ogre handle. - + /// \todo enable reference in the OGRE scene void enable (Ptr reference); - + /// \todo 5disable reference in the OGRE scene void disable (Ptr reference); @@ -206,6 +206,18 @@ namespace MWWorld const ESM::Cell *createRecord (const ESM::Cell& record); ///< Create a new recrod (of type cell) in the ESM store. /// \return ID, pointer to created record + + void playAnimationGroup (const MWWorld::Ptr& ptr, const std::string& groupName, int mode, + int number = 1); + ///< Run animation for a MW-reference. Calls to this function for references that are + /// currently not in the rendered scene should be ignored. + /// + /// \param mode: 0 normal, 1 immediate start, 2 immediate loop + /// \param number How offen the animation should be run + + void skipAnimation (const MWWorld::Ptr& ptr); + ///< Skip the animation for the given MW-reference for one frame. Calls to this function for + /// references that are currently not in the rendered scene should be ignored. }; } From 0d3338f8673c5c36c10762ac856bd3d15593dea4 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Tue, 22 Nov 2011 02:39:28 -0500 Subject: [PATCH 055/104] Some naming changes --- apps/openmw/mwrender/objects.cpp | 4 +- apps/openmw/mwrender/objects.hpp | 2 +- apps/openmw/mwrender/renderingmanager.cpp | 50 +++++++++++------------ apps/openmw/mwrender/renderingmanager.hpp | 13 +++--- 4 files changed, 34 insertions(+), 35 deletions(-) diff --git a/apps/openmw/mwrender/objects.cpp b/apps/openmw/mwrender/objects.cpp index 757d86f3b..1e3b4dda0 100644 --- a/apps/openmw/mwrender/objects.cpp +++ b/apps/openmw/mwrender/objects.cpp @@ -24,10 +24,10 @@ bool Objects::lightOutQuadInLin = false; int Objects::uniqueID = 0; void Objects::setMwRoot(Ogre::SceneNode* root){ - mwRoot = root; + mMwRoot = root; } void Objects::insertBegin (const MWWorld::Ptr& ptr, bool enabled, bool static_){ - Ogre::SceneNode* root = mwRoot; + Ogre::SceneNode* root = mMwRoot; Ogre::SceneNode* cellnode; if(mCellSceneNodes.find(ptr.getCell()) == mCellSceneNodes.end()) { diff --git a/apps/openmw/mwrender/objects.hpp b/apps/openmw/mwrender/objects.hpp index 6f36e4849..6cd465fdd 100644 --- a/apps/openmw/mwrender/objects.hpp +++ b/apps/openmw/mwrender/objects.hpp @@ -13,7 +13,7 @@ class Objects{ OEngine::Render::OgreRenderer &mRend; std::map mCellSceneNodes; std::map mSG; - Ogre::SceneNode* mwRoot; + Ogre::SceneNode* mMwRoot; bool isStatic; static int uniqueID; static bool lightConst; diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index 2a198b5f4..878a76b3d 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -22,10 +22,10 @@ namespace MWRender { RenderingManager::RenderingManager (OEngine::Render::OgreRenderer& _rend, const boost::filesystem::path& resDir, OEngine::Physic::PhysicEngine* engine) -:rend(_rend), objects(rend), mDebugging(engine) +:mRendering(_rend), mObjects(mRendering), mDebugging(engine) { - rend.createScene("PlayerCam", 55, 5); - mSkyManager = MWRender::SkyManager::create(rend.getWindow(), rend.getCamera(), resDir); + mRendering.createScene("PlayerCam", 55, 5); + mSkyManager = MWRender::SkyManager::create(mRendering.getWindow(), mRendering.getCamera(), resDir); // Set default mipmap level (NB some APIs ignore this) TextureManager::getSingleton().setDefaultNumMipmaps(5); @@ -38,21 +38,21 @@ RenderingManager::RenderingManager (OEngine::Render::OgreRenderer& _rend, const // the screen (when x is to the right.) This is the orientation that // Morrowind uses, and it automagically makes everything work as it // should. - SceneNode *rt = rend.getScene()->getRootSceneNode(); - mwRoot = rt->createChildSceneNode(); - mwRoot->pitch(Degree(-90)); - objects.setMwRoot(mwRoot); + SceneNode *rt = mRendering.getScene()->getRootSceneNode(); + mMwRoot = rt->createChildSceneNode(); + mMwRoot->pitch(Degree(-90)); + mObjects.setMwRoot(mMwRoot); //used to obtain ingame information of ogre objects (which are faced or selected) - mRaySceneQuery = rend.getScene()->createRayQuery(Ray()); + mRaySceneQuery = mRendering.getScene()->createRayQuery(Ray()); - Ogre::SceneNode *playerNode = mwRoot->createChildSceneNode ("player"); + Ogre::SceneNode *playerNode = mMwRoot->createChildSceneNode ("player"); playerNode->pitch(Degree(90)); Ogre::SceneNode *cameraYawNode = playerNode->createChildSceneNode(); Ogre::SceneNode *cameraPitchNode = cameraYawNode->createChildSceneNode(); - cameraPitchNode->attachObject(rend.getCamera()); + cameraPitchNode->attachObject(mRendering.getCamera()); - mPlayer = new MWRender::Player (rend.getCamera(), playerNode); + mPlayer = new MWRender::Player (mRendering.getCamera(), playerNode); } RenderingManager::~RenderingManager () @@ -62,25 +62,25 @@ RenderingManager::~RenderingManager () } MWRender::Npcs& RenderingManager::getNPCs(){ - return npcs; + return mNpcs; } MWRender::Objects& RenderingManager::getObjects(){ - return objects; + return mObjects; } MWRender::Creatures& RenderingManager::getCreatures(){ - return creatures; + return mCreatures; } MWRender::Player& RenderingManager::getPlayer(){ return (*mPlayer); } void RenderingManager::removeCell (MWWorld::Ptr::CellStore *store){ - objects.removeCell(store); + mObjects.removeCell(store); } void RenderingManager::cellAdded (MWWorld::Ptr::CellStore *store) { - objects.buildStaticGeometry (*store); + mObjects.buildStaticGeometry (*store); } void RenderingManager::addObject (const MWWorld::Ptr& ptr){ @@ -91,7 +91,7 @@ void RenderingManager::addObject (const MWWorld::Ptr& ptr){ } void RenderingManager::removeObject (const MWWorld::Ptr& ptr) { - if (!objects.deleteObject (ptr)) + if (!mObjects.deleteObject (ptr)) { /// \todo delete non-object MW-references } @@ -100,7 +100,7 @@ void RenderingManager::removeObject (const MWWorld::Ptr& ptr) void RenderingManager::moveObject (const MWWorld::Ptr& ptr, const Ogre::Vector3& position) { /// \todo move this to the rendering-subsystems - rend.getScene()->getSceneNode (ptr.getRefData().getHandle())-> + mRendering.getScene()->getSceneNode (ptr.getRefData().getHandle())-> setPosition (position); } @@ -166,9 +166,9 @@ void RenderingManager::configureFog(ESMS::CellStore &mCell) float high = 4500 + 9000 * (1-mCell.cell->ambi.fogDensity); float low = 200; - rend.getScene()->setFog (FOG_LINEAR, color, 0, low, high); - rend.getCamera()->setFarClipDistance (high + 10); - rend.getViewport()->setBackgroundColour (color); + mRendering.getScene()->setFog (FOG_LINEAR, color, 0, low, high); + mRendering.getCamera()->setFarClipDistance (high + 10); + mRendering.getViewport()->setBackgroundColour (color); } void RenderingManager::setAmbientMode() @@ -177,17 +177,17 @@ void RenderingManager::setAmbientMode() { case 0: - rend.getScene()->setAmbientLight(mAmbientColor); + mRendering.getScene()->setAmbientLight(mAmbientColor); break; case 1: - rend.getScene()->setAmbientLight(0.7f*mAmbientColor + 0.3f*ColourValue(1,1,1)); + mRendering.getScene()->setAmbientLight(0.7f*mAmbientColor + 0.3f*ColourValue(1,1,1)); break; case 2: - rend.getScene()->setAmbientLight(ColourValue(1,1,1)); + mRendering.getScene()->setAmbientLight(ColourValue(1,1,1)); break; } } @@ -199,7 +199,7 @@ void RenderingManager::configureAmbient(ESMS::CellStore &mCell // Create a "sun" that shines light downwards. It doesn't look // completely right, but leave it for now. - Ogre::Light *light = rend.getScene()->createLight(); + Ogre::Light *light = mRendering.getScene()->createLight(); Ogre::ColourValue colour; colour.setAsABGR (mCell.cell->ambi.sunlight); light->setDiffuseColour (colour); diff --git a/apps/openmw/mwrender/renderingmanager.hpp b/apps/openmw/mwrender/renderingmanager.hpp index ac4e62e44..f212b4289 100644 --- a/apps/openmw/mwrender/renderingmanager.hpp +++ b/apps/openmw/mwrender/renderingmanager.hpp @@ -109,11 +109,10 @@ class RenderingManager: private RenderingInterface { void setAmbientMode(); SkyManager* mSkyManager; - OEngine::Render::OgreRenderer &rend; - Ogre::Camera* camera; - MWRender::Npcs npcs; - MWRender::Creatures creatures; - MWRender::Objects objects; + OEngine::Render::OgreRenderer &mRendering; + MWRender::Npcs mNpcs; + MWRender::Creatures mCreatures; + MWRender::Objects mObjects; // 0 normal, 1 more bright, 2 max int mAmbientMode; @@ -123,10 +122,10 @@ class RenderingManager: private RenderingInterface { /// Root node for all objects added to the scene. This is rotated so /// that the OGRE coordinate system matches that used internally in /// Morrowind. - Ogre::SceneNode *mwRoot; + Ogre::SceneNode *mMwRoot; Ogre::RaySceneQuery *mRaySceneQuery; - OEngine::Physic::PhysicEngine* eng; + OEngine::Physic::PhysicEngine* mPhysicsEngine; MWRender::Player *mPlayer; MWRender::Debugging mDebugging; From 828a3904a54facd538a7e0caaee0b5a74b3ac297 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Wed, 23 Nov 2011 02:17:21 -0500 Subject: [PATCH 056/104] BSAArchive done and some change to NIFLoader --- components/bsa/bsa_archive.cpp | 25 +- components/nifogre/ogre_nif_loader.cpp | 419 +++++++++++-------------- components/nifogre/ogre_nif_loader.hpp | 18 +- 3 files changed, 214 insertions(+), 248 deletions(-) diff --git a/components/bsa/bsa_archive.cpp b/components/bsa/bsa_archive.cpp index 2178be318..72d15944d 100644 --- a/components/bsa/bsa_archive.cpp +++ b/components/bsa/bsa_archive.cpp @@ -240,15 +240,36 @@ public: // should not have been declared const in the first place. BSAFile *narc = (BSAFile*)&arc; + String passed = filename; + if(filename.at(filename.length() - 1) == '*' || filename.at(filename.length() - 1) == '?' || filename.at(filename.length() - 1) == '<' + || filename.at(filename.length() - 1) == '"' || filename.at(filename.length() - 1) == '>' || filename.at(filename.length() - 1) == ':' + || filename.at(filename.length() - 1) == '|') + { + passed = filename.substr(0, filename.length() - 2); + } + if(filename.at(filename.length() - 2) == '>') + passed = filename.substr(0, filename.length() - 6); // Open the file - StreamPtr strm = narc->getFile(filename.c_str()); + StreamPtr strm = narc->getFile(passed.c_str()); // Wrap it into an Ogre::DataStream. return DataStreamPtr(new Mangle2OgreStream(strm)); } // Check if the file exists. - bool exists(const String& filename) { return arc.exists(filename.c_str()); } + bool exists(const String& filename) { + String passed = filename; + if(filename.at(filename.length() - 1) == '*' || filename.at(filename.length() - 1) == '?' || filename.at(filename.length() - 1) == '<' + || filename.at(filename.length() - 1) == '"' || filename.at(filename.length() - 1) == '>' || filename.at(filename.length() - 1) == ':' + || filename.at(filename.length() - 1) == '|') + { + passed = filename.substr(0, filename.length() - 2); + } + if(filename.at(filename.length() - 2) == '>') + passed = filename.substr(0, filename.length() - 6); + +return arc.exists(passed.c_str()); +} time_t getModifiedTime(const String&) { return 0; } // This is never called as far as I can see. diff --git a/components/nifogre/ogre_nif_loader.cpp b/components/nifogre/ogre_nif_loader.cpp index 668fdcceb..9f98c98d8 100644 --- a/components/nifogre/ogre_nif_loader.cpp +++ b/components/nifogre/ogre_nif_loader.cpp @@ -356,19 +356,77 @@ void NIFLoader::createOgreSubMesh(NiTriShape *shape, const String &material, std HardwareBufferManager::getSingleton().createVertexBuffer( VertexElement::getTypeSize(VET_FLOAT3), numVerts, HardwareBuffer::HBU_STATIC_WRITE_ONLY); + + if(flip) + { + float *datamod = new float[data->vertices.length]; + //std::cout << "Shape" << shape->name.toString() << "\n"; + //std::cout << "MTransform" << mTransform << "\n"; + for(int i = 0; i < numVerts; i++) + { + int index = i * 3; + const float *pos = data->vertices.ptr + index; + Ogre::Vector3 original = Ogre::Vector3(*pos ,*(pos+1), *(pos+2)); + //std::cout << "Original: " << original; + //rstd::cout << "vectorfirst" << original << "\n"; + original = mTransform * original; + mBoundingBox.merge(original); + //std::cout <<" New: " << original << "\n"; + datamod[index] = original.x; + datamod[index+1] = original.y; + datamod[index+2] = original.z; + //std::cout << "vector " << original << "\n"; + //std::cout << "datamod: " << datamod[index+1] << "datamod2: " << *(pos+1) << "\n"; + } + vbuf->writeData(0, vbuf->getSizeInBytes(), datamod, false); + } + else + { + //std::cout << "X " << data->vertices.ptr[0] << "Y " << data->vertices.ptr[1] << "Z " << data->vertices.ptr[2] << "NIFLOADER" << "\n"; + vbuf->writeData(0, vbuf->getSizeInBytes(), data->vertices.ptr, false); + } + vbuf->writeData(0, vbuf->getSizeInBytes(), data->vertices.ptr, true); VertexBufferBinding* bind = sub->vertexData->vertexBufferBinding; bind->setBinding(nextBuf++, vbuf); - // Vertex normals + // Vertex normals if (data->normals.length) { decl->addElement(nextBuf, 0, VET_FLOAT3, VES_NORMAL); vbuf = HardwareBufferManager::getSingleton().createVertexBuffer( VertexElement::getTypeSize(VET_FLOAT3), - numVerts, HardwareBuffer::HBU_STATIC_WRITE_ONLY); - vbuf->writeData(0, vbuf->getSizeInBytes(), data->normals.ptr, true); + numVerts, HardwareBuffer::HBU_DYNAMIC,true); + + if(flip) + { + Quaternion rotation = mTransform.extractQuaternion(); + rotation.normalise(); + + float *datamod = new float[data->normals.length]; + for(int i = 0; i < numVerts; i++) + { + int index = i * 3; + const float *pos = data->normals.ptr + index; + Ogre::Vector3 original = Ogre::Vector3(*pos ,*(pos+1), *(pos+2)); + original = rotation * original; + if (mNormaliseNormals) + { + original.normalise(); + } + + + datamod[index] = original.x; + datamod[index+1] = original.y; + datamod[index+2] = original.z; + } + vbuf->writeData(0, vbuf->getSizeInBytes(), datamod, false); + } + else + { + vbuf->writeData(0, vbuf->getSizeInBytes(), data->normals.ptr, false); + } bind->setBinding(nextBuf++, vbuf); } @@ -393,30 +451,80 @@ void NIFLoader::createOgreSubMesh(NiTriShape *shape, const String &material, std bind->setBinding(nextBuf++, vbuf); } - // Texture UV coordinates - if (data->uvlist.length) + if (data->uvlist.length) { + + + decl->addElement(nextBuf, 0, VET_FLOAT2, VES_TEXTURE_COORDINATES); vbuf = HardwareBufferManager::getSingleton().createVertexBuffer( VertexElement::getTypeSize(VET_FLOAT2), - numVerts, HardwareBuffer::HBU_STATIC_WRITE_ONLY); - - vbuf->writeData(0, vbuf->getSizeInBytes(), data->uvlist.ptr, true); + numVerts, HardwareBuffer::HBU_STATIC_WRITE_ONLY,false); + + if(flip) + { + float *datamod = new float[data->uvlist.length]; + + for(int i = 0; i < data->uvlist.length; i+=2){ + float x = *(data->uvlist.ptr + i); + + float y = *(data->uvlist.ptr + i + 1); + + datamod[i] =x; + datamod[i + 1] =y; + } + vbuf->writeData(0, vbuf->getSizeInBytes(), datamod, false); + } + else + vbuf->writeData(0, vbuf->getSizeInBytes(), data->uvlist.ptr, false); bind->setBinding(nextBuf++, vbuf); } - // Triangle faces + // Triangle faces - The total number of triangle points int numFaces = data->triangles.length; + if (numFaces) { + + sub->indexData->indexCount = numFaces; + sub->indexData->indexStart = 0; HardwareIndexBufferSharedPtr ibuf = HardwareBufferManager::getSingleton(). createIndexBuffer(HardwareIndexBuffer::IT_16BIT, numFaces, - HardwareBuffer::HBU_STATIC_WRITE_ONLY); - ibuf->writeData(0, ibuf->getSizeInBytes(), data->triangles.ptr, true); + HardwareBuffer::HBU_STATIC_WRITE_ONLY, true); + + if(flip && mFlipVertexWinding && sub->indexData->indexCount % 3 == 0){ + sub->indexData->indexBuffer = ibuf; + + uint16 *datamod = new uint16[numFaces]; + int index = 0; + for (size_t i = 0; i < sub->indexData->indexCount; i+=3) + { + + const short *pos = data->triangles.ptr + index; + uint16 i0 = (uint16) *(pos+0); + uint16 i1 = (uint16) *(pos+1); + uint16 i2 = (uint16) *(pos+2); + + //std::cout << "i0: " << i0 << "i1: " << i1 << "i2: " << i2 << "\n"; + + + datamod[index] = i2; + datamod[index+1] = i1; + datamod[index+2] = i0; + + index += 3; + } + + ibuf->writeData(0, ibuf->getSizeInBytes(), datamod, false); + + } + else + ibuf->writeData(0, ibuf->getSizeInBytes(), data->triangles.ptr, false); sub->indexData->indexBuffer = ibuf; - sub->indexData->indexCount = numFaces; - sub->indexData->indexStart = 0; + + + } // Set material if one was given @@ -747,10 +855,30 @@ void NIFLoader::handleNiTriShape(NiTriShape *shape, int flags, BoundsFinder &bou } } +void NIFLoader::calculateTransform() +{ + // Calculate transform + Matrix4 transform = Matrix4::IDENTITY; + transform = Matrix4::getScale(vector) * transform; + // Check whether we have to flip vertex winding. + // We do have to, if we changed our right hand base. + // We can test it by using the cross product from X and Y and see, if it is a non-negative + // projection on Z. Actually it should be exactly Z, as we don't do non-uniform scaling yet, + // but the test is cheap either way. + Matrix3 m3; + transform.extract3x3Matrix(m3); + + if (m3.GetColumn(0).crossProduct(m3.GetColumn(1)).dotProduct(m3.GetColumn(2)) < 0) + { + mFlipVertexWinding = true; + } + + mTransform = transform; + +} 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 @@ -846,13 +974,7 @@ void NIFLoader::handleNode(Nif::Node *node, int flags, { NodeList &list = ((NiNode*)node)->children; int n = list.length(); - int i = 0; - if(isHands){ - //cout << "NumberOfNs: " << n << "Stack:" << stack << "\n"; - //if(stack == 3) - //n=0; - } - for (; irecType == RC_NiTriShape) { - // For shapes - /*For Beast Skins, Shape Bone Names - Tri Left Foot - Tri Right Foot - Tri Tail - 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"; - - if(isChest && isBeast && skincounter == 0 && name.compare("Tri Chest") == 0){ - //std::cout <<"BEASTCHEST1\n"; - handleNiTriShape(dynamic_cast(node), flags, bounds); - skincounter++; - } - else if(isChest && isBeast && skincounter == 1 && name.compare("Tri Tail") == 0){ - //std::cout <<"BEASTCHEST2\n"; - handleNiTriShape(dynamic_cast(node), flags, bounds); - skincounter++; - } - else if(isChest && isBeast && skincounter == 2 && name.compare("Tri Left Foot") == 0){ - //std::cout <<"BEASTCHEST3\n"; - handleNiTriShape(dynamic_cast(node), flags, bounds); - skincounter=1000; - } - else if (!isChest || !isBeast) - { - handleNiTriShape(dynamic_cast(node), flags, bounds); - } - //if(isBeast && isChest) - //cout << "Handling Shape, Stack " << stack <<"\n"; - - - - counter++; - } - /*if(isHands){ - //cout << "Handling Shape, Stack " << stack <<"\n"; - counter++; - }*/ - + handleNiTriShape(dynamic_cast(node), flags, bounds); } - - stack--; } void NIFLoader::loadResource(Resource *resource) { - if(skincounter == 1000) - skincounter = 0; - stack = 0; - counter = 0; - std::string name = resource->getName(); - if(resourceName.compare(name) != 0) - { - skincounter = 0; - resourceName = name; - } - //std::cout <<"NAME:" << name; - //if(name.length() >= 20) - // {std::string split = name.substr(name.length() - 20, 20); - //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"; - const std::string test3 ="meshes\\b\\B_N_Redguard_F_Skins.NIF"; - const std::string test4 ="meshes\\b\\B_N_Redguard_F_Skins.nif"; - const std::string test5 ="meshes\\b\\B_N_Dark Elf_F_Skins.nif"; - const std::string test6 ="meshes\\b\\B_N_Redguard_M_Skins.nif"; - const std::string test7 ="meshes\\b\\B_N_Wood Elf_F_Skins.nif"; - const std::string test8 ="meshes\\b\\B_N_Wood Elf_M_Skins.nif"; - const std::string test9 ="meshes\\b\\B_N_Imperial_F_Skins.nif"; - const std::string test10 ="meshes\\b\\B_N_Imperial_M_Skins.nif"; - const std::string test11 ="meshes\\b\\B_N_Khajiit_F_Skins.nif"; - const std::string test12 ="meshes\\b\\B_N_Khajiit_M_Skins.nif"; - const std::string test13 ="meshes\\b\\B_N_Argonian_F_Skins.nif"; - const std::string test14 ="meshes\\b\\B_N_Argonian_M_Skins.nif"; - const std::string test15 ="meshes\\b\\B_N_Nord_F_Skins.nif"; - const std::string test16 ="meshes\\b\\B_N_Nord_M_Skins.nif"; - const std::string test17 ="meshes\\b\\B_N_Imperial_F_Skins.nif"; - const std::string test18 ="meshes\\b\\B_N_Imperial_M_Skins.nif"; - const std::string test19 ="meshes\\b\\B_N_Orc_F_Skins.nif"; - const std::string test20 ="meshes\\b\\B_N_Orc_M_Skins.nif"; - const std::string test21 ="meshes\\b\\B_N_Breton_F_Skins.nif"; - 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"; - - //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; - if(name.compare(test11) == 0 || name.compare(test12) == 0 || name.compare(test13) == 0 || name.compare(test14) == 0) - { - isBeast = true; - //std::cout << "Welcome Beast\n"; - } - else - isBeast = false; - } - else - isChest = false; - const std::string hands ="meshes\\b\\B_N_Dark Elf_M_Hands.1st.NIF"; - const std::string hands2 ="meshes\\b\\B_N_Dark Elf_F_Hands.1st.NIF"; - const std::string hands3 ="meshes\\b\\B_N_Redguard_M_Hands.1st.nif"; - const std::string hands4 ="meshes\\b\\B_N_Redguard_F_Hands.1st.nif"; - const std::string hands5 ="meshes\\b\\b_n_argonian_m_hands.1st.nif"; - const std::string hands6 ="meshes\\b\\b_n_argonian_f_hands.1st.nif"; - const std::string hands7 ="meshes\\b\\B_N_Breton_M_Hand.1st.NIF"; - const std::string hands8 ="meshes\\b\\B_N_Breton_F_Hands.1st.nif"; - const std::string hands9 ="meshes\\b\\B_N_High Elf_M_Hands.1st.nif"; - const std::string hands10 ="meshes\\b\\B_N_High Elf_F_Hands.1st.nif"; - const std::string hands11 ="meshes\\b\\B_N_Nord_M_Hands.1st.nif"; - const std::string hands12 ="meshes\\b\\B_N_Nord_F_Hands.1st.nif"; - const std::string hands13 ="meshes\\b\\b_n_khajiit_m_hands.1st.nif"; - const std::string hands14 ="meshes\\b\\b_n_khajiit_f_hands.1st.nif"; - const std::string hands15 ="meshes\\b\\B_N_Orc_M_Hands.1st.nif"; - const std::string hands16 ="meshes\\b\\B_N_Orc_F_Hands.1st.nif"; - const std::string hands17 ="meshes\\b\\B_N_Wood Elf_M_Hands.1st.nif"; - const std::string hands18 ="meshes\\b\\B_N_Wood Elf_F_Hands.1st.nif"; - const std::string hands19 ="meshes\\b\\B_N_Imperial_M_Hands.1st.nif"; - const std::string hands20 ="meshes\\b\\B_N_Imperial_F_Hands.1st.nif"; - if(name.compare(hands) == 0 || name.compare(hands2) == 0 || name.compare(hands3) == 0 || name.compare(hands4) == 0 || - name.compare(hands5) == 0 || name.compare(hands6) == 0 || name.compare(hands7) == 0 || name.compare(hands8) == 0 || - name.compare(hands9) == 0 || name.compare(hands10) == 0 || name.compare(hands11) == 0 || name.compare(hands12) == 0 || - name.compare(hands13) == 0 || name.compare(hands14) == 0 || name.compare(hands15) == 0 || name.compare(hands16) == 0 || - name.compare(hands17) == 0 || name.compare(hands18) == 0 || name.compare(hands19) == 0 || name.compare(hands20) == 0) - { - //std::cout << "Welcome Hands1st\n"; - isHands = true; - isChest = false; - } - else - isHands = false; - - - /* - else if(name.compare(test3) == 0 || name.compare(test4) == 0) - { - std::cout << "\n\n\nWelcome FRedguard Chest\n\n\n"; - isChest = true; - } - else if(name.compare(test5) == 0 || name.compare(test6) == 0) - { - std::cout << "\n\n\nWelcome FRedguard Chest\n\n\n"; - isChest = true; - } - else if(name.compare(test7) == 0 || name.compare(test8) == 0) - { - std::cout << "\n\n\nWelcome FRedguard Chest\n\n\n"; - isChest = true; - } - else if(name.compare(test9) == 0 || name.compare(test10) == 0) - { - std::cout << "\n\n\nWelcome FRedguard Chest\n\n\n"; - isChest = true; - }*/ - - //if(split== "Skins.NIF") - // std::cout << "\nSPECIAL PROPS\n"; - resourceName = ""; - // Check if the resource already exists - //MeshPtr ptr = m->load(name, "custom"); - //cout << "THISNAME: " << ptr->getName() << "\n"; - //cout << "RESOURCE:"<< resource->getName(); + mBoundingBox.setNull(); mesh = 0; mSkel.setNull(); - + flip = false; + std::string name = resource->getName(); + char suffix = name.at(name.length() - 2); + + if(suffix == '*') + { + vector = Ogre::Vector3(-1,1,1); + flip = true; + } + else if(suffix == '?'){ + vector = Ogre::Vector3(1,-1,1); + flip = true; + } + else if(suffix == '<'){ + vector = Ogre::Vector3(1,1,-1); + flip = true; + } + else if(suffix == '>') + { + + //bNiTri = false; + //baddin = true; + std::string sub = name.substr(name.length() - 6, 4); + //if(sub.compare("0000") != 0) + // addAnim = false; + + } + if(flip) + { + //std::cout << "Flipping"; + calculateTransform(); + } // Set up the VFS if it hasn't been done already if (!vfs) vfs = new OgreVFS(resourceGroup); @@ -1096,62 +1079,24 @@ void NIFLoader::loadResource(Resource *resource) bounds.maxX(), bounds.maxY(), bounds.maxZ())); mesh->_setBoundingSphereRadius(bounds.getRadius()); } - - // set skeleton -// if (!skel.isNull()) -// mesh->setSkeletonName(getSkeletonName()); } 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"; - 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"; - + MeshPtr themesh; if (!ptr.isNull()){ - - //if(pieces > 1) - //cout << "It exists\n"; - resize = MeshPtr(ptr); - //resize->load(); - //resize->reload(); + themesh = MeshPtr(ptr); } 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; + themesh = MeshManager::getSingleton().createManual(name, group, NIFLoader::getSingletonPtr()); } - return resize; + return themesh; } diff --git a/components/nifogre/ogre_nif_loader.hpp b/components/nifogre/ogre_nif_loader.hpp index bf8a94266..b721fedf4 100644 --- a/components/nifogre/ogre_nif_loader.hpp +++ b/components/nifogre/ogre_nif_loader.hpp @@ -85,9 +85,11 @@ class NIFLoader : Ogre::ManualResourceLoader Ogre::Quaternion convertRotation(const Nif::Matrix& rot); private: - NIFLoader() : resourceGroup("General") { skincounter = 0; resourceName = "";} + NIFLoader() : resourceGroup("General") {resourceName = "";} NIFLoader(NIFLoader& n) {} + void calculateTransform(); + void warn(std::string msg); void fail(std::string msg); @@ -126,19 +128,17 @@ class NIFLoader : Ogre::ManualResourceLoader std::string resourceName; std::string resourceGroup; - int skincounter; - bool isChest; - bool isBeast; - bool isHands; - bool isFeet; - int counter; - int numbers; - int stack; + Ogre::Matrix4 mTransform; + Ogre::AxisAlignedBox mBoundingBox; + bool flip; + bool mNormaliseNormals; + bool mFlipVertexWinding; std::multimap MaterialMap; // pointer to the ogre mesh which is currently build Ogre::Mesh *mesh; Ogre::SkeletonPtr mSkel; + Ogre::Vector3 vector; }; } From e8ec9093f83d304d844a9dfabb58ab166c9df880 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Wed, 23 Nov 2011 18:18:51 -0500 Subject: [PATCH 057/104] More NIFLoader code --- components/nif/data.hpp | 469 +++++++++++++++++++++---- components/nif/node.hpp | 36 ++ components/nifogre/ogre_nif_loader.cpp | 227 ++++++++++-- components/nifogre/ogre_nif_loader.hpp | 42 ++- 4 files changed, 664 insertions(+), 110 deletions(-) diff --git a/components/nif/data.hpp b/components/nif/data.hpp index c483b4873..f4c907edb 100644 --- a/components/nif/data.hpp +++ b/components/nif/data.hpp @@ -26,6 +26,7 @@ #include "controlled.hpp" #include +#include namespace Nif { @@ -366,6 +367,12 @@ public: Vector trans; // Translation float scale; // Probably scale (always 1) }; + struct BoneTrafoCopy + { + Ogre::Quaternion rotation; + Ogre::Vector3 trans; + float scale; + }; struct VertWeight { @@ -380,6 +387,13 @@ public: const Vector4 *unknown; Misc::SliceArray weights; }; + struct BoneInfoCopy + { + std::string bonename; + BoneTrafoCopy trafo; + Vector4 unknown; + std::vector weights; + }; const BoneTrafo *trafo; std::vector bones; @@ -412,92 +426,397 @@ public: class NiMorphData : public Record { + float startTime; + float stopTime; + std::vector initialVertices; + std::vector> relevantTimes; + std::vector> relevantData; + std::vector> additionalVertices; + + public: - void read(NIFFile *nif) + float getStartTime(){ + return startTime; + } + float getStopTime(){ + return stopTime; + } + void setStartTime(float time){ + startTime = time; + } + + void setStopTime(float time){ + stopTime = time; + } + std::vector getInitialVertices(){ + return initialVertices; + } + std::vector> getRelevantData(){ + return relevantData; + } + std::vector> getRelevantTimes(){ + return relevantTimes; + } + std::vector> getAdditionalVertices(){ + return additionalVertices; + } + +void read(NIFFile *nif) { int morphCount = nif->getInt(); int vertCount = nif->getInt(); nif->getByte(); - - for(int i=0; igetInt(); - nif->getInt(); - if(magic) - // Time, data, forward, backward tangents - nif->getFloatLen(4*magic); - - nif->getFloatLen(vertCount*3); + int magic = nif->getInt(); + int type = nif->getInt(); + for(int i = 0; i < vertCount; i++){ + + float x = nif->getFloat(); + float y = nif->getFloat(); + float z = nif->getFloat(); + initialVertices.push_back(Ogre::Vector3(x, y, z)); + } + + for(int i=1; igetInt(); + type = nif->getInt(); + std::vector current; + std::vector currentTime; + for(int i = 0; i < magic; i++){ + // Time, data, forward, backward tangents + float time = nif->getFloat(); + float x = nif->getFloat(); + float y = nif->getFloat(); + float z = nif->getFloat(); + current.push_back(Ogre::Vector3(x,y,z)); + currentTime.push_back(time); + //nif->getFloatLen(4*magic); + } + if(magic){ + relevantData.push_back(current); + relevantTimes.push_back(currentTime); + } + std::vector verts; + for(int i = 0; i < vertCount; i++){ + float x = nif->getFloat(); + float y = nif->getFloat(); + float z = nif->getFloat(); + verts.push_back(Ogre::Vector3(x, y, z)); + } + additionalVertices.push_back(verts); } } }; + class NiKeyframeData : public Record { - 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); - } - } + std::string bonename; + //Rotations + std::vector quats; + std::vector tbc; + std::vector rottime; + float startTime; + float stopTime; + 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 clone(NiKeyframeData c) + { + quats = c.getQuat(); + tbc = c.getrTbc(); + rottime = c.getrTime(); + + //types + ttype = c.getTtype(); + rtype = c.getRtype(); + stype = c.getStype(); + + + translist1 = c.getTranslist1(); + translist2 = c.getTranslist2(); + translist3 = c.getTranslist3(); + + transtime = c.gettTime(); + + bonename = c.getBonename(); + + + } + + void setBonename(std::string bone) + { + bonename = bone; + } + void setStartTime(float start) + { + startTime = start; + } + void setStopTime(float end) + { + stopTime = end; + } + 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; + } + float getStartTime(){ + return startTime; + } + float getStopTime(){ + return stopTime; + } + 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; + } + std::string getBonename(){ return bonename; + } + + }; } // Namespace diff --git a/components/nif/node.hpp b/components/nif/node.hpp index f0ad54655..02387d219 100644 --- a/components/nif/node.hpp +++ b/components/nif/node.hpp @@ -93,6 +93,19 @@ public: } }; +struct NiTriShapeCopy +{ + std::string sname; + std::vector boneSequence; + Nif::NiSkinData::BoneTrafoCopy trafo; + //Ogre::Quaternion initialBoneRotation; + //Ogre::Vector3 initialBoneTranslation; + std::vector vertices; + std::vector normals; + std::vector boneinfo; + Nif::NiMorphData morph; +}; + struct NiNode : Node { NodeList children; @@ -133,6 +146,27 @@ struct NiTriShape : Node data.read(nif); skin.read(nif); } + + NiTriShapeCopy clone(){ + NiTriShapeCopy copy; + copy.sname = name.toString(); + float *ptr = (float*)data->vertices.ptr; + float *ptrNormals = (float*)data->normals.ptr; + int numVerts = data->vertices.length / 3; + for(int i = 0; i < numVerts; i++) + { + float *current = (float*) (ptr + i * 3); + copy.vertices.push_back(Ogre::Vector3(*current, *(current + 1), *(current + 2))); + + if(ptrNormals){ + float *currentNormals = (float*) (ptrNormals + i * 3); + copy.normals.push_back(Ogre::Vector3(*currentNormals, *(currentNormals + 1), *(currentNormals + 2))); + } + } + + + return copy; + } }; struct NiCamera : Node @@ -186,5 +220,7 @@ struct NiRotatingParticles : Node } }; + + } // Namespace #endif diff --git a/components/nifogre/ogre_nif_loader.cpp b/components/nifogre/ogre_nif_loader.cpp index 9f98c98d8..b8596d3c5 100644 --- a/components/nifogre/ogre_nif_loader.cpp +++ b/components/nifogre/ogre_nif_loader.cpp @@ -24,25 +24,7 @@ //loadResource->handleNode->handleNiTriShape->createSubMesh #include "ogre_nif_loader.hpp" -#include -#include - -#include -#include "../nif/nif_file.hpp" -#include "../nif/node.hpp" -#include "../nif/data.hpp" -#include "../nif/property.hpp" -#include "../nif/controller.hpp" -#include "../nif/extra.hpp" -#include - -#include -#include -// For warning messages -#include - -// float infinity -#include + typedef unsigned char ubyte; @@ -583,7 +565,7 @@ static void vectorMul(const Matrix &A, float *C) } -void NIFLoader::handleNiTriShape(NiTriShape *shape, int flags, BoundsFinder &bounds) +void NIFLoader::handleNiTriShape(NiTriShape *shape, int flags, BoundsFinder &bounds, Transformation original, std::vector boneSequence) { assert(shape != NULL); @@ -744,11 +726,39 @@ void NIFLoader::handleNiTriShape(NiTriShape *shape, int flags, BoundsFinder &bou std::list vertexBoneAssignments; + Nif::NiTriShapeCopy copy = shape->clone(); + if(!shape->controller.empty()) + { + //Nif::NiGeomMorpherController* cont = dynamic_cast (shape->controller.getPtr()); + Nif::Controller* cont = shape->controller.getPtr(); + if(cont->recType == RC_NiGeomMorpherController) + { + Nif::NiGeomMorpherController* morph = dynamic_cast (cont); + copy.morph = morph->data.get(); + copy.morph.setStartTime(morph->timeStart); + copy.morph.setStopTime(morph->timeStop); + //std::cout << "Size" << morph->data->getInitialVertices().size() << "\n"; + + } + + //std::cout << "We have a controller"; + } //use niskindata for the position of vertices. if (!shape->skin.empty()) { + + //std::cout << "Skin is not empty\n"; + //Bone assignments are stored in submeshes, so we don't need to copy them + //std::string triname + //std::vector vertices; + //std::vector normals; + //std::vector boneinfo; + + // vector that stores if the position if a vertex is absolute std::vector vertexPosAbsolut(numVerts,false); + std::vector vertexPosOriginal(numVerts, Ogre::Vector3::ZERO); + std::vector vertexNormalOriginal(numVerts, Ogre::Vector3::ZERO); float *ptrNormals = (float*)data->normals.ptr; //the bone from skin->bones[boneIndex] is linked to skin->data->bones[boneIndex] @@ -775,24 +785,34 @@ void NIFLoader::handleNiTriShape(NiTriShape *shape, int flags, BoundsFinder &bou break; } //get the bone from bones array of skindata + if(!mSkel->hasBone(shape->skin->bones[boneIndex].name.toString())) + std::cout << "We don't have this bone"; bonePtr = mSkel->getBone(shape->skin->bones[boneIndex].name.toString()); // final_vector = old_vector + old_rotation*new_vector*old_scale - vecPos = bonePtr->_getDerivedPosition() + - bonePtr->_getDerivedOrientation() * convertVector3(it->trafo->trans); - - vecRot = bonePtr->_getDerivedOrientation() * convertRotation(it->trafo->rotation); + + Nif::NiSkinData::BoneInfoCopy boneinfo; + boneinfo.trafo.rotation = convertRotation(it->trafo->rotation); + boneinfo.trafo.trans = convertVector3(it->trafo->trans); + boneinfo.bonename = shape->skin->bones[boneIndex].name.toString(); for (unsigned int i=0; iweights.length; i++) { - unsigned int verIndex = (it->weights.ptr + i)->vertex; + vecPos = bonePtr->_getDerivedPosition() + + bonePtr->_getDerivedOrientation() * convertVector3(it->trafo->trans); + vecRot = bonePtr->_getDerivedOrientation() * convertRotation(it->trafo->rotation); + unsigned int verIndex = (it->weights.ptr + i)->vertex; + boneinfo.weights.push_back(*(it->weights.ptr + i)); //Check if the vertex is relativ, FIXME: Is there a better solution? if (vertexPosAbsolut[verIndex] == false) { //apply transformation to the vertices Vector3 absVertPos = vecPos + vecRot * Vector3(ptr + verIndex *3); + absVertPos = absVertPos * (it->weights.ptr + i)->weight; + vertexPosOriginal[verIndex] = Vector3(ptr + verIndex *3); + mBoundingBox.merge(absVertPos); //convert it back to float * for (int j=0; j<3; j++) (ptr + verIndex*3)[j] = absVertPos[j]; @@ -802,37 +822,79 @@ void NIFLoader::handleNiTriShape(NiTriShape *shape, int flags, BoundsFinder &bou if (verIndex < data->normals.length) { Vector3 absNormalsPos = vecRot * Vector3(ptrNormals + verIndex *3); - + absNormalsPos = absNormalsPos * (it->weights.ptr + i)->weight; + vertexNormalOriginal[verIndex] = Vector3(ptrNormals + verIndex *3); + for (int j=0; j<3; j++) (ptrNormals + verIndex*3)[j] = absNormalsPos[j]; } vertexPosAbsolut[verIndex] = true; } + else + { + Vector3 absVertPos = vecPos + vecRot * vertexPosOriginal[verIndex]; + absVertPos = absVertPos * (it->weights.ptr + i)->weight; + Vector3 old = Vector3(ptr + verIndex *3); + absVertPos = absVertPos + old; + + mBoundingBox.merge(absVertPos); + //convert it back to float * + for (int j=0; j<3; j++) + (ptr + verIndex*3)[j] = absVertPos[j]; + + //apply rotation to the normals (not every vertex has a normal) + //FIXME: I guessed that vertex[i] = normal[i], is that true? + if (verIndex < data->normals.length) + { + Vector3 absNormalsPos = vecRot * vertexNormalOriginal[verIndex]; + absNormalsPos = absNormalsPos * (it->weights.ptr + i)->weight; + Vector3 oldNormal = Vector3(ptrNormals + verIndex *3); + absNormalsPos = absNormalsPos + oldNormal; + + for (int j=0; j<3; j++) + (ptrNormals + verIndex*3)[j] = absNormalsPos[j]; + } + } + VertexBoneAssignment vba; vba.boneIndex = bonePtr->getHandle(); vba.vertexIndex = verIndex; vba.weight = (it->weights.ptr + i)->weight; + vertexBoneAssignments.push_back(vba); } + copy.boneinfo.push_back(boneinfo); boneIndex++; } + } else { + + copy.boneSequence = boneSequence; // Rotate, scale and translate all the vertices, const Matrix &rot = shape->trafo->rotation; const Vector &pos = shape->trafo->pos; float scale = shape->trafo->scale; + + copy.trafo.trans = convertVector3(original.pos); + copy.trafo.rotation = convertRotation(original.rotation); + copy.trafo.scale = original.scale; + //We don't use velocity for anything yet, so it does not need to be saved + + // Computes C = B + AxC*scale for (int i=0; inormals.length) { @@ -843,12 +905,28 @@ void NIFLoader::handleNiTriShape(NiTriShape *shape, int flags, BoundsFinder &bou ptr += 3; } } + if(!mSkel.isNull() ){ + int boneIndex; + Ogre::Bone *parentBone = mSkel->getBone(boneSequence[boneSequence.size() - 1]); + if(parentBone) + boneIndex = parentBone->getHandle(); + else + boneIndex = mSkel->getNumBones() - 1; + for(int i = 0; i < numVerts; i++){ + VertexBoneAssignment vba; + vba.boneIndex = boneIndex; + vba.vertexIndex = i; + vba.weight = 1; + vertexBoneAssignments.push_back(vba); + } + } } if (!hidden) { // Add this vertex set to the bounding box bounds.add(optr, numVerts); + shapes.push_back(copy); // Create the submesh createOgreSubMesh(shape, material, vertexBoneAssignments); @@ -877,7 +955,7 @@ void NIFLoader::calculateTransform() } void NIFLoader::handleNode(Nif::Node *node, int flags, - const Transformation *trafo, BoundsFinder &bounds, Bone *parentBone) + const Transformation *trafo, BoundsFinder &bounds, Ogre::Bone *parentBone, std::vector boneSequence) { //if( MWClass::isChest) // cout << "u:" << node << "\n"; @@ -908,6 +986,48 @@ void NIFLoader::handleNode(Nif::Node *node, int flags, // the engine, just skip this entire node. return; } + + if (e->recType == RC_NiTextKeyExtraData){ + Nif::NiTextKeyExtraData* extra = dynamic_cast (e); + + std::vector::iterator textiter = extra->list.begin(); + //std::ofstream File("Indices" + name + ".txt"); + + //std::string sample = "uy"; + + std::string cut = ""; + for(int i = 0; i < name.length(); i++) + { + if(!(name.at(i) == '\\' || name.at(i) == '/' || name.at(i) == '>' || name.at(i) == '<' || name.at(i) == '?' || name.at(i) == '*' || name.at(i) == '|' || name.at(i) == ':' || name.at(i) == '"')) + { + cut += name.at(i); + } + } + //std::cout << "End" << end; + + std::cout << "Outputting " << cut << "\n"; + + std::ofstream File("Indices" + cut + ".txt"); + + /*if(File.is_open()) + std::cout << "We could open\n"; + else + std::cout << "We could not\n";*/ + for(; textiter != extra->list.end(); textiter++) + { + //if(textiter->text.toString().find("Torch") < textiter->text.toString().length()) + //std::cout << "Time: " << textiter->time << " " << textiter->text.toString() << "\n"; + std::string text = textiter->text.toString(); + + replace(text.begin(), text.end(), '\n', '/'); + + text.erase(std::remove(text.begin(), text.end(), '\r'), text.end()); + File << "Time: " << textiter->time << "|" << text << "\n"; + + textmappings[text] = textiter->time; + } + File.close(); + } } Bone *bone = 0; @@ -930,6 +1050,7 @@ void NIFLoader::handleNode(Nif::Node *node, int flags, if (!mSkel.isNull()) //if there is a skeleton { std::string name = node->name.toString(); + boneSequence.push_back(name); //if (isBeast && isChest) // std::cout << "NAME: " << name << "\n"; // Quick-n-dirty workaround for the fact that several @@ -947,7 +1068,7 @@ void NIFLoader::handleNode(Nif::Node *node, int flags, } } } - + Transformation original = *(node->trafo); // Apply the parent transformation to this node. We overwrite the // existing data with the final transformation. if (trafo) @@ -978,12 +1099,23 @@ void NIFLoader::handleNode(Nif::Node *node, int flags, { if (list.has(i)) - handleNode(&list[i], flags, node->trafo, bounds, bone); + handleNode(&list[i], flags, node->trafo, bounds, bone, boneSequence); } } else if (node->recType == RC_NiTriShape) { - handleNiTriShape(dynamic_cast(node), flags, bounds); + std::string nodename = node->name.toString(); + + if (triname == "") + { + handleNiTriShape(dynamic_cast(node), flags, bounds, original, boneSequence); + } + else if(name.length() >= triname.length()) + { + std::transform(nodename.begin(), nodename.end(), nodename.begin(), std::tolower); + if(triname == name.substr(0, triname.length())) + handleNiTriShape(dynamic_cast(node), flags, bounds, original, boneSequence); + } } } @@ -993,7 +1125,7 @@ void NIFLoader::loadResource(Resource *resource) mesh = 0; mSkel.setNull(); flip = false; - std::string name = resource->getName(); + name = resource->getName(); char suffix = name.at(name.length() - 2); if(suffix == '*') @@ -1019,6 +1151,31 @@ void NIFLoader::loadResource(Resource *resource) // addAnim = false; } + + switch(name.at(name.length() - 1)) + { + case '"': + triname = "tri chest"; + break; + case '*': + triname = "tri tail"; + break; + case ':': + triname = "tri left foot"; + break; + case '<': + triname = "tri right foot"; + break; + case '>': + triname = "tri left hand"; + break; + case '?': + triname = "tri right hand"; + break; + default: + triname = ""; + break; + } if(flip) { //std::cout << "Flipping"; @@ -1070,7 +1227,11 @@ void NIFLoader::loadResource(Resource *resource) } // Handle the node - handleNode(node, 0, NULL, bounds, 0); + std::vector boneSequence; + + + + handleNode(node, 0, NULL, bounds, 0, boneSequence); // set the bounding value. if (bounds.isValid()) diff --git a/components/nifogre/ogre_nif_loader.hpp b/components/nifogre/ogre_nif_loader.hpp index b721fedf4..a110e7e4f 100644 --- a/components/nifogre/ogre_nif_loader.hpp +++ b/components/nifogre/ogre_nif_loader.hpp @@ -28,10 +28,39 @@ #include #include #include +#include +#include +#include + +#include +#include "../nif/nif_file.hpp" +#include "../nif/node.hpp" +#include "../nif/data.hpp" +#include "../nif/property.hpp" +#include "../nif/controller.hpp" +#include "../nif/extra.hpp" +#include + +#include +#include +// For warning messages +#include + +// float infinity +#include +using namespace boost::algorithm; class BoundsFinder; +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, is_iless()); + } +}; + namespace Nif { class Node; @@ -51,6 +80,7 @@ namespace Mangle namespace NifOgre { + /** Manual resource loader for NIF meshes. This is the main class responsible for translating the internal NIF mesh structure into @@ -94,9 +124,9 @@ class NIFLoader : Ogre::ManualResourceLoader void fail(std::string msg); void handleNode( Nif::Node *node, int flags, - const Nif::Transformation *trafo, BoundsFinder &bounds, Ogre::Bone *parentBone); + const Nif::Transformation *trafo, BoundsFinder &bounds, Ogre::Bone *parentBone, std::vector boneSequence); - void handleNiTriShape(Nif::NiTriShape *shape, int flags, BoundsFinder &bounds); + void handleNiTriShape(Nif::NiTriShape *shape, int flags, BoundsFinder &bounds, Nif::Transformation original, std::vector boneSequence); void createOgreSubMesh(Nif::NiTriShape *shape, const Ogre::String &material, std::list &vertexBoneAssignments); @@ -139,6 +169,14 @@ class NIFLoader : Ogre::ManualResourceLoader Ogre::Mesh *mesh; Ogre::SkeletonPtr mSkel; Ogre::Vector3 vector; + std::vector shapes; + std::string name; + std::string triname; + std::vector allanim; + std::map textmappings; + std::map,ciLessBoost> alltextmappings; + std::map,ciLessBoost> allanimmap; + std::map,ciLessBoost> allshapesmap; }; } From 16ff2a7a1b35a9d7d8de1db60324f3097fda417a Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Thu, 24 Nov 2011 01:48:54 -0500 Subject: [PATCH 058/104] Changing to Actors;NPCAnimation;CreatureAnimation --- apps/openmw/CMakeLists.txt | 2 +- apps/openmw/mwclass/creature.hpp | 2 +- apps/openmw/mwclass/npc.hpp | 2 +- apps/openmw/mwrender/actors.hpp | 23 +++++++++++++++++++++ apps/openmw/mwrender/animation.cpp | 0 apps/openmw/mwrender/animation.hpp | 10 +++++++++ apps/openmw/mwrender/creatureanimation.cpp | 0 apps/openmw/mwrender/creatureanimation.hpp | 12 +++++++++++ apps/openmw/mwrender/creatures.cpp | 2 -- apps/openmw/mwrender/creatures.hpp | 10 --------- apps/openmw/mwrender/npcanimation.cpp | 0 apps/openmw/mwrender/npcanimation.hpp | 12 +++++++++++ apps/openmw/mwrender/npcs.cpp | 2 -- apps/openmw/mwrender/npcs.hpp | 9 -------- apps/openmw/mwrender/renderinginterface.hpp | 7 +++---- apps/openmw/mwrender/renderingmanager.cpp | 11 +++++----- apps/openmw/mwrender/renderingmanager.hpp | 12 +++++------ 17 files changed, 74 insertions(+), 42 deletions(-) create mode 100644 apps/openmw/mwrender/actors.hpp create mode 100644 apps/openmw/mwrender/animation.cpp create mode 100644 apps/openmw/mwrender/animation.hpp create mode 100644 apps/openmw/mwrender/creatureanimation.cpp create mode 100644 apps/openmw/mwrender/creatureanimation.hpp delete mode 100644 apps/openmw/mwrender/creatures.cpp delete mode 100644 apps/openmw/mwrender/creatures.hpp create mode 100644 apps/openmw/mwrender/npcanimation.cpp create mode 100644 apps/openmw/mwrender/npcanimation.hpp delete mode 100644 apps/openmw/mwrender/npcs.cpp delete mode 100644 apps/openmw/mwrender/npcs.hpp diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index b3bd51e20..aae2251a1 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -16,7 +16,7 @@ set(GAME_HEADER source_group(game FILES ${GAME} ${GAME_HEADER}) add_openmw_dir (mwrender - renderingmanager debugging sky player npcs creatures objects renderinginterface + renderingmanager debugging sky player animation npcanimation creatureanimation actors objects renderinginterface ) add_openmw_dir (mwinput diff --git a/apps/openmw/mwclass/creature.hpp b/apps/openmw/mwclass/creature.hpp index f74cdf991..46f83ff0c 100644 --- a/apps/openmw/mwclass/creature.hpp +++ b/apps/openmw/mwclass/creature.hpp @@ -2,7 +2,7 @@ #define GAME_MWCLASS_CREATURE_H #include "../mwworld/class.hpp" -#include "../mwrender/creatures.hpp" + namespace MWClass { diff --git a/apps/openmw/mwclass/npc.hpp b/apps/openmw/mwclass/npc.hpp index 271d66392..cc9dbef7f 100644 --- a/apps/openmw/mwclass/npc.hpp +++ b/apps/openmw/mwclass/npc.hpp @@ -2,7 +2,7 @@ #define GAME_MWCLASS_NPC_H #include "../mwworld/class.hpp" -#include "../mwrender/npcs.hpp" + namespace MWClass { diff --git a/apps/openmw/mwrender/actors.hpp b/apps/openmw/mwrender/actors.hpp new file mode 100644 index 000000000..86be6d140 --- /dev/null +++ b/apps/openmw/mwrender/actors.hpp @@ -0,0 +1,23 @@ +#ifndef _GAME_RENDER_ACTORS_H +#define _GAME_RENDER_ACTORS_H + +#include "components/esm_store/cell_store.hpp" + +#include "../mwworld/refdata.hpp" +#include "../mwworld/ptr.hpp" +#include +namespace MWRender{ + class Actors{ + OEngine::Render::OgreRenderer &mRend; + std::map mCellSceneNodes; + std::map mSG; + Ogre::SceneNode* mMwRoot; + bool isStatic; + static int uniqueID; + + public: + Actors(OEngine::Render::OgreRenderer& _rend): mRend(_rend){} + ~Actors(){} + }; +} +#endif \ No newline at end of file diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp new file mode 100644 index 000000000..e69de29bb diff --git a/apps/openmw/mwrender/animation.hpp b/apps/openmw/mwrender/animation.hpp new file mode 100644 index 000000000..cb922d7f3 --- /dev/null +++ b/apps/openmw/mwrender/animation.hpp @@ -0,0 +1,10 @@ +#ifndef _GAME_RENDER_ANIMATION_H +#define _GAME_RENDER_ANIMATION_H +#include +namespace MWRender{ +class Animation{ + std::vector transformations; + std::map textmappings; +}; +} +#endif \ No newline at end of file diff --git a/apps/openmw/mwrender/creatureanimation.cpp b/apps/openmw/mwrender/creatureanimation.cpp new file mode 100644 index 000000000..e69de29bb diff --git a/apps/openmw/mwrender/creatureanimation.hpp b/apps/openmw/mwrender/creatureanimation.hpp new file mode 100644 index 000000000..2bad5f769 --- /dev/null +++ b/apps/openmw/mwrender/creatureanimation.hpp @@ -0,0 +1,12 @@ +#ifndef _GAME_RENDER_CREATUREANIMATION_H +#define _GAME_RENDER_CREATUREANIMATION_H + +#include "animation.hpp" +#include +namespace MWRender{ + +class CreatureAnimation: Animation{ + std::vector shapes; //All the NiTriShapeData for this creature +}; +} +#endif \ No newline at end of file diff --git a/apps/openmw/mwrender/creatures.cpp b/apps/openmw/mwrender/creatures.cpp deleted file mode 100644 index 998951249..000000000 --- a/apps/openmw/mwrender/creatures.cpp +++ /dev/null @@ -1,2 +0,0 @@ -#include "creatures.hpp" -using namespace MWRender; \ No newline at end of file diff --git a/apps/openmw/mwrender/creatures.hpp b/apps/openmw/mwrender/creatures.hpp deleted file mode 100644 index 9aabb175b..000000000 --- a/apps/openmw/mwrender/creatures.hpp +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef _GAME_RENDER_CREATURES_H -#define _GAME_RENDER_CREATURES_H -#include - -namespace MWRender{ -class Creatures{ - -}; -} -#endif \ No newline at end of file diff --git a/apps/openmw/mwrender/npcanimation.cpp b/apps/openmw/mwrender/npcanimation.cpp new file mode 100644 index 000000000..e69de29bb diff --git a/apps/openmw/mwrender/npcanimation.hpp b/apps/openmw/mwrender/npcanimation.hpp new file mode 100644 index 000000000..9358e2c0a --- /dev/null +++ b/apps/openmw/mwrender/npcanimation.hpp @@ -0,0 +1,12 @@ +#ifndef _GAME_RENDER_NPCANIMATION_H +#define _GAME_RENDER_NPCANIMATION_H +#include "animation.hpp" +#include +#include +namespace MWRender{ + +class NpcAnimation: Animation{ + std::vector> shapeparts; //All the NiTriShape data that we need for animating this particular npc +}; +} +#endif \ No newline at end of file diff --git a/apps/openmw/mwrender/npcs.cpp b/apps/openmw/mwrender/npcs.cpp deleted file mode 100644 index 7012ccb18..000000000 --- a/apps/openmw/mwrender/npcs.cpp +++ /dev/null @@ -1,2 +0,0 @@ -#include "npcs.hpp" -using namespace MWRender; diff --git a/apps/openmw/mwrender/npcs.hpp b/apps/openmw/mwrender/npcs.hpp deleted file mode 100644 index 88ee5ca30..000000000 --- a/apps/openmw/mwrender/npcs.hpp +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef _GAME_RENDER_NPCS_H -#define _GAME_RENDER_NPCS_H -#include -namespace MWRender{ -class Npcs{ - -}; -} -#endif diff --git a/apps/openmw/mwrender/renderinginterface.hpp b/apps/openmw/mwrender/renderinginterface.hpp index ebd4af2bd..03935bef6 100644 --- a/apps/openmw/mwrender/renderinginterface.hpp +++ b/apps/openmw/mwrender/renderinginterface.hpp @@ -1,16 +1,15 @@ #ifndef _GAME_RENDERING_INTERFACE_H #define _GAME_RENDERING_INTERFACE_H namespace MWRender{ - class Npcs; - class Creatures; class Objects; + class Actors; class Player; + class RenderingInterface{ public: - virtual MWRender::Npcs& getNPCs() = 0; - virtual MWRender::Creatures& getCreatures() = 0; virtual MWRender::Objects& getObjects() = 0; virtual MWRender::Player& getPlayer() = 0; + virtual MWRender::Actors& getActors() = 0; virtual ~RenderingInterface(){}; }; } diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index 878a76b3d..aee08bd0b 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -22,7 +22,7 @@ namespace MWRender { RenderingManager::RenderingManager (OEngine::Render::OgreRenderer& _rend, const boost::filesystem::path& resDir, OEngine::Physic::PhysicEngine* engine) -:mRendering(_rend), mObjects(mRendering), mDebugging(engine) +:mRendering(_rend), mObjects(mRendering), mDebugging(engine), mActors(mRendering) { mRendering.createScene("PlayerCam", 55, 5); mSkyManager = MWRender::SkyManager::create(mRendering.getWindow(), mRendering.getCamera(), resDir); @@ -61,15 +61,14 @@ RenderingManager::~RenderingManager () delete mSkyManager; } -MWRender::Npcs& RenderingManager::getNPCs(){ - return mNpcs; -} + MWRender::Objects& RenderingManager::getObjects(){ return mObjects; } -MWRender::Creatures& RenderingManager::getCreatures(){ - return mCreatures; +MWRender::Actors& RenderingManager::getActors(){ + return mActors; } + MWRender::Player& RenderingManager::getPlayer(){ return (*mPlayer); } diff --git a/apps/openmw/mwrender/renderingmanager.hpp b/apps/openmw/mwrender/renderingmanager.hpp index f212b4289..5189db870 100644 --- a/apps/openmw/mwrender/renderingmanager.hpp +++ b/apps/openmw/mwrender/renderingmanager.hpp @@ -19,9 +19,9 @@ #include #include "renderinginterface.hpp" -#include "npcs.hpp" -#include "creatures.hpp" + #include "objects.hpp" +#include "actors.hpp" #include "player.hpp" namespace Ogre @@ -49,9 +49,9 @@ class RenderingManager: private RenderingInterface { private: - virtual MWRender::Npcs& getNPCs(); - virtual MWRender::Creatures& getCreatures(); + virtual MWRender::Objects& getObjects(); + virtual MWRender::Actors& getActors(); public: RenderingManager(OEngine::Render::OgreRenderer& _rend, const boost::filesystem::path& resDir, OEngine::Physic::PhysicEngine* engine); @@ -110,9 +110,9 @@ class RenderingManager: private RenderingInterface { void setAmbientMode(); SkyManager* mSkyManager; OEngine::Render::OgreRenderer &mRendering; - MWRender::Npcs mNpcs; - MWRender::Creatures mCreatures; + MWRender::Objects mObjects; + MWRender::Actors mActors; // 0 normal, 1 more bright, 2 max int mAmbientMode; From 7bd911b40139d0bfd5e979cb4dc3ef2eee2128d5 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Thu, 24 Nov 2011 23:13:34 -0500 Subject: [PATCH 059/104] Problems with handles --- apps/openmw/mwclass/creature.cpp | 13 ++- apps/openmw/mwclass/creature.hpp | 2 + apps/openmw/mwmechanics/mechanicsmanager.cpp | 1 + apps/openmw/mwrender/actors.cpp | 89 ++++++++++++++++++++ apps/openmw/mwrender/actors.hpp | 18 ++-- apps/openmw/mwrender/renderingmanager.cpp | 6 ++ apps/openmw/mwworld/physicssystem.cpp | 1 + apps/openmw/mwworld/scene.cpp | 3 +- components/nif/data.hpp | 1 - components/nifogre/ogre_nif_loader.cpp | 6 ++ 10 files changed, 126 insertions(+), 14 deletions(-) create mode 100644 apps/openmw/mwrender/actors.cpp diff --git a/apps/openmw/mwclass/creature.cpp b/apps/openmw/mwclass/creature.cpp index 852701cce..8b06dec49 100644 --- a/apps/openmw/mwclass/creature.cpp +++ b/apps/openmw/mwclass/creature.cpp @@ -24,7 +24,7 @@ namespace MWClass void Creature::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const { - /* + ESMS::LiveCellRef *ref = ptr.get(); @@ -33,15 +33,14 @@ namespace MWClass if (!model.empty()) { - MWRender::Creatures& creatures = renderingInterface.getCreatures(); - //creatures.insertBegin(ptr, ptr.getRefData().isEnabled(), false); - //creatures.insertMesh(ptr, "meshes\\" + model); - }*/ + MWRender::Actors& actors = renderingInterface.getActors(); + actors.insertBegin(ptr, ptr.getRefData().isEnabled(), false); + actors.insertMesh(ptr, "meshes\\" + model); + } } void Creature::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const { - /* ESMS::LiveCellRef *ref = ptr.get(); @@ -50,7 +49,7 @@ namespace MWClass assert (ref->base != NULL); if(!model.empty()){ physics.insertActorPhysics(ptr, "meshes\\" + model); - }*/ + } } diff --git a/apps/openmw/mwclass/creature.hpp b/apps/openmw/mwclass/creature.hpp index 46f83ff0c..b7b654bc0 100644 --- a/apps/openmw/mwclass/creature.hpp +++ b/apps/openmw/mwclass/creature.hpp @@ -2,6 +2,8 @@ #define GAME_MWCLASS_CREATURE_H #include "../mwworld/class.hpp" +#include "../mwrender/renderinginterface.hpp" +#include "../mwrender/actors.hpp" namespace MWClass diff --git a/apps/openmw/mwmechanics/mechanicsmanager.cpp b/apps/openmw/mwmechanics/mechanicsmanager.cpp index 33093c24d..417a062f3 100644 --- a/apps/openmw/mwmechanics/mechanicsmanager.cpp +++ b/apps/openmw/mwmechanics/mechanicsmanager.cpp @@ -250,6 +250,7 @@ namespace MWMechanics while (iter!=mActors.end()) if (iter->getCell()==cellStore) { + std::cout << "Erasing an actor"; mActors.erase (iter++); } else diff --git a/apps/openmw/mwrender/actors.cpp b/apps/openmw/mwrender/actors.cpp new file mode 100644 index 000000000..b14d1344e --- /dev/null +++ b/apps/openmw/mwrender/actors.cpp @@ -0,0 +1,89 @@ +#include "actors.hpp" +#include +#include + +using namespace Ogre; +using namespace MWRender; + +void Actors::setMwRoot(Ogre::SceneNode* root){ + mMwRoot = root; +} +void Actors::insertBegin (const MWWorld::Ptr& ptr, bool enabled, bool static_){ + Ogre::SceneNode* cellnode; + if(mCellSceneNodes.find(ptr.getCell()) == mCellSceneNodes.end()) + { + //Create the scenenode and put it in the map + cellnode = mMwRoot->createChildSceneNode(); + mCellSceneNodes[ptr.getCell()] = cellnode; + } + else + { + cellnode = mCellSceneNodes[ptr.getCell()]; + } + + Ogre::SceneNode* insert = cellnode->createChildSceneNode(); + const float *f = ptr.getRefData().getPosition().pos; + insert->setPosition(f[0], f[1], f[2]); + insert->setScale(ptr.getCellRef().scale, ptr.getCellRef().scale, ptr.getCellRef().scale); + + // Convert MW rotation to a quaternion: + f = ptr.getCellRef().pos.rot; + + // Rotate around X axis + Quaternion xr(Radian(-f[0]), Vector3::UNIT_X); + + // Rotate around Y axis + Quaternion yr(Radian(-f[1]), Vector3::UNIT_Y); + + // Rotate around Z axis + Quaternion zr(Radian(-f[2]), Vector3::UNIT_Z); + + // Rotates first around z, then y, then x + insert->setOrientation(xr*yr*zr); + if (!enabled) + insert->setVisible (false); + ptr.getRefData().setBaseNode(insert); + + +} +void Actors::insertMesh (const MWWorld::Ptr& ptr, const std::string& mesh){ + Ogre::SceneNode* insert = ptr.getRefData().getBaseNode(); + assert(insert); + + NifOgre::NIFLoader::load(mesh); + Entity *ent = mRend.getScene()->createEntity(mesh); + insert->attachObject(ent); +} + +bool Actors::deleteObject (const MWWorld::Ptr& ptr) +{ + if (Ogre::SceneNode *base = ptr.getRefData().getBaseNode()) + { + Ogre::SceneNode *parent = base->getParentSceneNode(); + + for (std::map::const_iterator iter ( + mCellSceneNodes.begin()); iter!=mCellSceneNodes.end(); ++iter) + if (iter->second==parent) + { + base->removeAndDestroyAllChildren(); + mRend.getScene()->destroySceneNode (base); + ptr.getRefData().setBaseNode (0); + return true; + } + + return false; + } + + return true; +} + +void Actors::removeCell(MWWorld::Ptr::CellStore* store){ + if(mCellSceneNodes.find(store) != mCellSceneNodes.end()) + { + Ogre::SceneNode* base = mCellSceneNodes[store]; + base->removeAndDestroyAllChildren(); + mCellSceneNodes.erase(store); + mRend.getScene()->destroySceneNode(base); + base = 0; + } +} \ No newline at end of file diff --git a/apps/openmw/mwrender/actors.hpp b/apps/openmw/mwrender/actors.hpp index 86be6d140..abcc2a28b 100644 --- a/apps/openmw/mwrender/actors.hpp +++ b/apps/openmw/mwrender/actors.hpp @@ -2,6 +2,7 @@ #define _GAME_RENDER_ACTORS_H #include "components/esm_store/cell_store.hpp" +#include #include "../mwworld/refdata.hpp" #include "../mwworld/ptr.hpp" @@ -10,14 +11,21 @@ namespace MWRender{ class Actors{ OEngine::Render::OgreRenderer &mRend; std::map mCellSceneNodes; - std::map mSG; Ogre::SceneNode* mMwRoot; - bool isStatic; - static int uniqueID; + + public: - Actors(OEngine::Render::OgreRenderer& _rend): mRend(_rend){} - ~Actors(){} + Actors(OEngine::Render::OgreRenderer& _rend): mRend(_rend){} + ~Actors(){} + void setMwRoot(Ogre::SceneNode* root); + void insertBegin (const MWWorld::Ptr& ptr, bool enabled, bool static_); + void insertMesh (const MWWorld::Ptr& ptr, const std::string& mesh); + bool deleteObject (const MWWorld::Ptr& ptr); + ///< \return found? + + void removeCell(MWWorld::Ptr::CellStore* store); + }; } #endif \ No newline at end of file diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index aee08bd0b..206dfbfd0 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -42,6 +42,7 @@ RenderingManager::RenderingManager (OEngine::Render::OgreRenderer& _rend, const mMwRoot = rt->createChildSceneNode(); mMwRoot->pitch(Degree(-90)); mObjects.setMwRoot(mMwRoot); + mActors.setMwRoot(mMwRoot); //used to obtain ingame information of ogre objects (which are faced or selected) mRaySceneQuery = mRendering.getScene()->createRayQuery(Ray()); @@ -75,6 +76,7 @@ MWRender::Player& RenderingManager::getPlayer(){ void RenderingManager::removeCell (MWWorld::Ptr::CellStore *store){ mObjects.removeCell(store); + mActors.removeCell(store); } void RenderingManager::cellAdded (MWWorld::Ptr::CellStore *store) @@ -94,6 +96,10 @@ void RenderingManager::removeObject (const MWWorld::Ptr& ptr) { /// \todo delete non-object MW-references } + if (!mActors.deleteObject (ptr)) + { + /// \todo delete non-object MW-references + } } void RenderingManager::moveObject (const MWWorld::Ptr& ptr, const Ogre::Vector3& position) diff --git a/apps/openmw/mwworld/physicssystem.cpp b/apps/openmw/mwworld/physicssystem.cpp index eb5c3c91c..8212dbeea 100644 --- a/apps/openmw/mwworld/physicssystem.cpp +++ b/apps/openmw/mwworld/physicssystem.cpp @@ -191,6 +191,7 @@ namespace MWWorld void PhysicsSystem::insertActorPhysics(const MWWorld::Ptr& ptr, const std::string model){ Ogre::SceneNode* node = ptr.getRefData().getBaseNode(); + std::cout << "Adding node with name" << node->getName(); addActor (node->getName(), model, node->getPosition()); } diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index 2f9a5185a..5f0632850 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -55,7 +55,7 @@ namespace MWWorld void Scene::unloadCell (CellStoreCollection::iterator iter) { - + std::cout << "Unloading cell\n"; ListHandles functor; MWWorld::Ptr::CellStore* active = *iter; @@ -73,6 +73,7 @@ namespace MWWorld mPhysics->removeObject (node->getName()); } } + //mPhysics->removeObject("Unnamed_43"); mWorld->getLocalScripts().clearCell (active); mEnvironment.mMechanicsManager->dropActors (active); mEnvironment.mSoundManager->stopSound (active); diff --git a/components/nif/data.hpp b/components/nif/data.hpp index f4c907edb..47ecfdd2c 100644 --- a/components/nif/data.hpp +++ b/components/nif/data.hpp @@ -581,7 +581,6 @@ public: int count = nif->getInt(); //std::vector quat(count); //std::vector rottime(count); - std::cout << "r"; if(count) { diff --git a/components/nifogre/ogre_nif_loader.cpp b/components/nifogre/ogre_nif_loader.cpp index b8596d3c5..6db23c5ce 100644 --- a/components/nifogre/ogre_nif_loader.cpp +++ b/components/nifogre/ogre_nif_loader.cpp @@ -1038,6 +1038,7 @@ void NIFLoader::handleNode(Nif::Node *node, int flags, //FIXME: "Bip01" isn't every time the root bone if (node->name == "Bip01" || node->name == "Root Bone") //root node, create a skeleton { + mSkel = SkeletonManager::getSingleton().create(getSkeletonName(), resourceGroup, true); /*if (node->extra->recType == RC_NiTextKeyExtraData ) @@ -1240,6 +1241,11 @@ void NIFLoader::loadResource(Resource *resource) bounds.maxX(), bounds.maxY(), bounds.maxZ())); mesh->_setBoundingSphereRadius(bounds.getRadius()); } + + if (!mSkel.isNull()) + { + mesh->_notifySkeleton(mSkel); + } } MeshPtr NIFLoader::load(const std::string &name, From 835c3f260398aab2799433a59e72961dc4804f9d Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Sun, 27 Nov 2011 02:27:06 -0500 Subject: [PATCH 060/104] Working towards npc rendering --- apps/openmw/mwclass/creature.cpp | 2 +- components/nifogre/ogre_nif_loader.cpp | 342 ++++++++++++++++++++++++- components/nifogre/ogre_nif_loader.hpp | 10 +- 3 files changed, 346 insertions(+), 8 deletions(-) diff --git a/apps/openmw/mwclass/creature.cpp b/apps/openmw/mwclass/creature.cpp index 8b06dec49..a58a851f2 100644 --- a/apps/openmw/mwclass/creature.cpp +++ b/apps/openmw/mwclass/creature.cpp @@ -48,7 +48,7 @@ namespace MWClass const std::string &model = ref->base->model; assert (ref->base != NULL); if(!model.empty()){ - physics.insertActorPhysics(ptr, "meshes\\" + model); + // physics.insertActorPhysics(ptr, "meshes\\" + model); } } diff --git a/components/nifogre/ogre_nif_loader.cpp b/components/nifogre/ogre_nif_loader.cpp index 6db23c5ce..796ece5be 100644 --- a/components/nifogre/ogre_nif_loader.cpp +++ b/components/nifogre/ogre_nif_loader.cpp @@ -1103,7 +1103,7 @@ void NIFLoader::handleNode(Nif::Node *node, int flags, handleNode(&list[i], flags, node->trafo, bounds, bone, boneSequence); } } - else if (node->recType == RC_NiTriShape) + else if (node->recType == RC_NiTriShape && bNiTri) { std::string nodename = node->name.toString(); @@ -1128,6 +1128,10 @@ void NIFLoader::loadResource(Resource *resource) flip = false; name = resource->getName(); char suffix = name.at(name.length() - 2); + bool addAnim = true; + bool hasAnim = false; + bool baddin = false; + bNiTri = true; if(suffix == '*') { @@ -1144,12 +1148,12 @@ void NIFLoader::loadResource(Resource *resource) } else if(suffix == '>') { - - //bNiTri = false; - //baddin = true; + baddin = true; + bNiTri = false; std::string sub = name.substr(name.length() - 6, 4); - //if(sub.compare("0000") != 0) - // addAnim = false; + + if(sub.compare("0000") != 0) + addAnim = false; } @@ -1233,7 +1237,31 @@ void NIFLoader::loadResource(Resource *resource) handleNode(node, 0, NULL, bounds, 0, boneSequence); + if(addAnim) + { + for(int i = 0; i < nif.numRecords(); i++) + { + Nif::NiKeyframeController *f = dynamic_cast(nif.getRecord(i)); + + Nif::Node *n = dynamic_cast(nif.getRecord(i)); + if(f != NULL) + { + hasAnim = true; + Nif::Node *o = dynamic_cast(f->target.getPtr()); + Nif::NiKeyframeDataPtr data = f->data; + + if (f->timeStart == FLT_MAX) + continue; + data->setBonename(o->name.toString()); + data->setStartTime(f->timeStart); + data->setStopTime(f->timeStop); + allanim.push_back(data.get()); + + + } + } + } // set the bounding value. if (bounds.isValid()) { @@ -1241,13 +1269,45 @@ void NIFLoader::loadResource(Resource *resource) bounds.maxX(), bounds.maxY(), bounds.maxZ())); mesh->_setBoundingSphereRadius(bounds.getRadius()); } + if(hasAnim && addAnim){ + //std::cout << "Lower" << lowername << "\n"; + //std::cout << "Adding the animations\n"; + allanimmap[name] = allanim; + alltextmappings[name] = textmappings; + } + if(!mSkel.isNull() && shapes.size() > 0 && addAnim) + { + allshapesmap[name] = shapes; + } + if(baddin){ + /*if(addAnim){ + if(isBeast) + npcknaSkel = mSkel; + else + npcSkel = mSkel; + }*/ + for(int i = 0; i < addin.size(); i++){ + insertMeshInsideBase(addin[i]); + } + addin.clear(); + } + if(flip){ + mesh->_setBounds(mBoundingBox, false); + } if (!mSkel.isNull()) { mesh->_notifySkeleton(mSkel); } + flip = false; +} + +void NIFLoader::addInMesh(Ogre::Mesh* input){ + addin.push_back(input); } + + MeshPtr NIFLoader::load(const std::string &name, const std::string &group) { @@ -1266,6 +1326,276 @@ MeshPtr NIFLoader::load(const std::string &name, return themesh; } +/* +This function shares much of the same code handleShapes() in MWRender::Animation +This function also creates new position and normal buffers for submeshes. +This function points to existing texture and IndexData buffers +*/ + +std::vector& NIFLoader::getAnim(std::string lowername){ + + std::map,ciLessBoost>::iterator iter = allanimmap.find(lowername); + if(iter != allanimmap.end()) + mAnim = iter->second; + return mAnim; + +} +std::vector& NIFLoader::getShapes(std::string lowername){ + + std::map,ciLessBoost>::iterator iter = allshapesmap.find(lowername); + if(iter != allshapesmap.end()) + mS = iter->second; + return mS; +} + +float NIFLoader::getTime(std::string filename, std::string text){ + std::map,ciLessBoost>::iterator iter = alltextmappings.find(filename); + if(iter != alltextmappings.end()){ + std::map::iterator insideiter = (iter->second).find(text); + if(insideiter != (iter->second).end()) + return insideiter->second; + else + return -20000000.0; + } + + return -10000000.0; +} + +void NIFLoader::insertMeshInsideBase(Ogre::Mesh* input) +{ + /*if(addin) + { + std::cout << "InsideBase:" << addin->getName() << "\n"; + }*/ + if(input) + { + std::vector shapes = NIFLoader::getSingletonPtr()->getShapes(input->getName()); + for(int i = 0; i < shapes.size(); i++){ + + //std::cout << "Shapes" << shapes[i].sname; + + Ogre::SubMesh* sub = input->getSubMesh(shapes[i].sname); + Ogre::SubMesh* subNew = mesh->createSubMesh(shapes[i].sname); + + + int nextBuf = 0; + + + //----------------------------------------VERTICES---------------------------------------- + int numVerts = shapes[i].vertices.size(); + subNew->vertexData = new VertexData(); + subNew->vertexData->vertexCount = numVerts; + subNew->useSharedVertices = false; + + //-----------------------------------------POSITIONS--------------------------------------- + + + VertexDeclaration *decl = subNew->vertexData->vertexDeclaration; + const VertexElement* position = + sub->vertexData->vertexDeclaration->findElementBySemantic(Ogre::VES_POSITION); + Ogre::HardwareVertexBufferSharedPtr vbuf; + HardwareVertexBufferSharedPtr newvbuf; + float* pRealNormal = new float[numVerts * 3]; + VertexBufferBinding* bind; + + + + + + + //std::cout << "X " << pReal[0] << "Y " << pReal[1] << "Z" << pReal[2] << "\n"; + float* pReal = new float[numVerts * 3]; + + std::map vertices; + std::map normals; + std::vector boneinfovector = shapes[i].boneinfo; + + //std::cout << "Name " << copy.sname << "\n"; + + if(boneinfovector.size() > 0){ + + + for (int j = 0; j < boneinfovector.size(); j++) + { + Nif::NiSkinData::BoneInfoCopy boneinfo = boneinfovector[j]; + Ogre::Bone *bonePtr = mSkel->getBone(boneinfo.bonename); + Ogre::Vector3 vecPos = bonePtr->_getDerivedPosition() + bonePtr->_getDerivedOrientation() * boneinfo.trafo.trans; + Ogre::Quaternion vecRot = bonePtr->_getDerivedOrientation() * boneinfo.trafo.rotation; + //std::cout << "Bone" << bonePtr->getName() << "\n"; + for (unsigned int k=0; k< boneinfo.weights.size(); k++) + { + unsigned int verIndex = boneinfo.weights[k].vertex; + if(vertices.find(verIndex) == vertices.end()) + { + Ogre::Vector3 absVertPos = vecPos + vecRot * shapes[i].vertices[verIndex]; + vertices[verIndex] = true; + absVertPos = absVertPos * boneinfo.weights[k].weight; + Ogre::Real* addr = (pReal + 3 * verIndex); + *addr = absVertPos.x; + *(addr+1) = absVertPos.y; + *(addr+2) = absVertPos.z; + + //std::cout << "Vertex" << vertices[verIndex] << "\n"; + } + else + { + Ogre::Vector3 absVertPos = vecPos + vecRot * shapes[i].vertices[verIndex]; + absVertPos = absVertPos * boneinfo.weights[k].weight; + Ogre::Vector3 old = Ogre::Vector3(pReal + 3 * verIndex); + absVertPos = absVertPos + old; + Ogre::Real* addr = (pReal + 3 * verIndex); + *addr = absVertPos.x; + *(addr+1) = absVertPos.y; + *(addr+2) = absVertPos.z; + + } + + if(normals.find(verIndex) == normals.end()) + { + Ogre::Vector3 absNormalsPos = vecRot * shapes[i].normals[verIndex]; + absNormalsPos = absNormalsPos * boneinfo.weights[k].weight; + normals[verIndex] = true; + Ogre::Real* addr = (pRealNormal + 3 * verIndex); + *addr = absNormalsPos.x; + *(addr+1) = absNormalsPos.y; + *(addr+2) = absNormalsPos.z; + } + else{ + Ogre::Vector3 absNormalsPos = vecRot * shapes[i].normals[verIndex]; + absNormalsPos = absNormalsPos * boneinfo.weights[k].weight; + Ogre::Vector3 old = Ogre::Vector3(pRealNormal + 3 * verIndex); + absNormalsPos = absNormalsPos + old; + + Ogre::Real* addr = (pRealNormal + 3 * verIndex); + *addr = absNormalsPos.x; + *(addr+1) = absNormalsPos.y; + *(addr+2) = absNormalsPos.z; + } + + } + + /* + std::cout << "TransformRot:" << boneinfo.trafo.rotation << "TransformTrans:" << boneinfo.trafo.trans << "\n"; + std::vector weights = boneinfo.weights; + for (int j = 0; j < weights.size(); j++){ + std::cout << "Vertex: " << weights[j].vertex << " Weight: " << weights[j].weight << "\n"; + }*/ + } + } + + if(position){ + decl->addElement(nextBuf, 0, VET_FLOAT3, VES_POSITION); + + + + newvbuf = + HardwareBufferManager::getSingleton().createVertexBuffer( + VertexElement::getTypeSize(VET_FLOAT3), + numVerts, HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY); + + newvbuf->writeData(0, newvbuf->getSizeInBytes(), pReal, false); + + + bind = subNew->vertexData->vertexBufferBinding; + bind->setBinding(nextBuf++, newvbuf); + + + } + //----------------------------------------NORMALS------------------------------------------- + + const VertexElement* normal = + sub->vertexData->vertexDeclaration->findElementBySemantic(Ogre::VES_NORMAL); + if(normal) + { + decl->addElement(nextBuf, 0, VET_FLOAT3, VES_NORMAL); + newvbuf = HardwareBufferManager::getSingleton().createVertexBuffer( + VertexElement::getTypeSize(VET_FLOAT3), + numVerts, HardwareBuffer::HBU_DYNAMIC); + + + newvbuf->writeData(0, newvbuf->getSizeInBytes(), pRealNormal, false); + + bind->setBinding(nextBuf++, newvbuf); + } + + + //--------------------------------------COLORS-------------------------------------------- + const VertexElement* color = + sub->vertexData->vertexDeclaration->findElementBySemantic(Ogre::VES_DIFFUSE); + if(color) + { + + decl->addElement(nextBuf, 0, VET_COLOUR, VES_DIFFUSE); + + vbuf = sub->vertexData->vertexBufferBinding->getBuffer(color->getSource()); + newvbuf = vbuf; + //RGBA* pReal2 = static_cast(vbuf->lock(Ogre::HardwareBuffer::HBL_NORMAL)); + //newvbuf->writeData(0, vbuf->getSizeInBytes(), pReal2, false); + + //vbuf->unlock(); + + bind->setBinding(nextBuf++, newvbuf); + } + + //-------------------------------------TEXTURES------------------------------------------- + + const VertexElement* text = + sub->vertexData->vertexDeclaration->findElementBySemantic(Ogre::VES_TEXTURE_COORDINATES); + if(text){ + vbuf = sub->vertexData->vertexBufferBinding->getBuffer(text->getSource()); + + decl->addElement(nextBuf, 0, VET_FLOAT2, VES_TEXTURE_COORDINATES); + newvbuf = vbuf; + //float* pRealf = static_cast(vbuf->lock(Ogre::HardwareBuffer::HBL_NORMAL)); + + //std::cout << "SIze" << vbuf->getSizeInBytes(); + + // newvbuf->writeData(0, vbuf->getSizeInBytes(), pRealf, false); + //vbuf->unlock(); + bind->setBinding(nextBuf++, newvbuf); + } + + //----------------------------------INDEX DATA-------------------------------------- + int numFaces = sub->indexData->indexCount; + subNew->indexData->indexCount = numFaces; + subNew->indexData->indexStart = 0; + + HardwareIndexBufferSharedPtr ibuf = sub->indexData->indexBuffer; + HardwareIndexBufferSharedPtr ibufNew = ibuf; + + //uint16* tri = static_cast(ibuf->lock(Ogre::HardwareBuffer::HBL_NORMAL)); + //ibufNew->writeData(0, ibuf->getSizeInBytes(), tri, false); + subNew->indexData->indexBuffer = ibufNew; + //ibuf->unlock(); + + if (!sub->getMaterialName().empty()){ + subNew->setMaterialName(sub->getMaterialName()); + } + + //Ogre::SubMesh::VertexBoneAssignmentList bonelist = sub->getBoneAssignments(); + + /* + Ogre::VertexBoneAssignment assign; + assign.boneIndex = 0; + assign.vertexIndex = 0; + assign.weight = 1.0; + subNew->addBoneAssignment(assign);*/ + + Ogre::SubMesh::BoneAssignmentIterator boneiter = sub->getBoneAssignmentIterator(); + while(boneiter.hasMoreElements()) + { + subNew->addBoneAssignment(boneiter.current()->second); + boneiter.getNext(); + } + subNew->addBoneAssignment(boneiter.current()->second); + + + + } + } + +} + /* 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 diff --git a/components/nifogre/ogre_nif_loader.hpp b/components/nifogre/ogre_nif_loader.hpp index a110e7e4f..a5b33bcbe 100644 --- a/components/nifogre/ogre_nif_loader.hpp +++ b/components/nifogre/ogre_nif_loader.hpp @@ -108,7 +108,11 @@ class NIFLoader : Ogre::ManualResourceLoader static Ogre::MeshPtr load(const std::string &name, const std::string &group="General"); - + void insertMeshInsideBase(Ogre::Mesh* mesh); + std::vector& getAnim(std::string name); + std::vector& getShapes(std::string name); + float getTime(std::string filename, std::string text); + void addInMesh(Ogre::Mesh* input); Ogre::Vector3 convertVector3(const Nif::Vector& vec); @@ -163,6 +167,7 @@ class NIFLoader : Ogre::ManualResourceLoader bool flip; bool mNormaliseNormals; bool mFlipVertexWinding; + bool bNiTri; std::multimap MaterialMap; // pointer to the ogre mesh which is currently build @@ -177,6 +182,9 @@ class NIFLoader : Ogre::ManualResourceLoader std::map,ciLessBoost> alltextmappings; std::map,ciLessBoost> allanimmap; std::map,ciLessBoost> allshapesmap; + std::vector addin; + std::vector mAnim; + std::vector mS; }; } From ee98a2af1a28c5b272408fc21393f3a3e6b7e92d Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Fri, 9 Dec 2011 00:08:30 -0500 Subject: [PATCH 061/104] Empty npcs --- apps/openmw/mwclass/npc.cpp | 1 + apps/openmw/mwmechanics/mechanicsmanager.cpp | 2 +- apps/openmw/mwrender/actors.cpp | 71 ++++++++++++++++++++ apps/openmw/mwrender/actors.hpp | 7 +- apps/openmw/mwrender/renderingmanager.cpp | 4 +- apps/openmw/mwrender/renderingmanager.hpp | 2 +- apps/openmw/mwworld/world.cpp | 2 +- 7 files changed, 83 insertions(+), 6 deletions(-) diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index cce23407f..b5bb4b773 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -32,6 +32,7 @@ namespace MWClass void Npc::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const { + renderingInterface.getActors().insertNPC(ptr); /* ESMS::LiveCellRef *ref = ptr.get(); diff --git a/apps/openmw/mwmechanics/mechanicsmanager.cpp b/apps/openmw/mwmechanics/mechanicsmanager.cpp index 417a062f3..7ed81f785 100644 --- a/apps/openmw/mwmechanics/mechanicsmanager.cpp +++ b/apps/openmw/mwmechanics/mechanicsmanager.cpp @@ -250,7 +250,7 @@ namespace MWMechanics while (iter!=mActors.end()) if (iter->getCell()==cellStore) { - std::cout << "Erasing an actor"; + //std::cout << "Erasing an actor"; mActors.erase (iter++); } else diff --git a/apps/openmw/mwrender/actors.cpp b/apps/openmw/mwrender/actors.cpp index b14d1344e..6fbbd755f 100644 --- a/apps/openmw/mwrender/actors.cpp +++ b/apps/openmw/mwrender/actors.cpp @@ -4,10 +4,76 @@ using namespace Ogre; using namespace MWRender; +using namespace NifOgre; void Actors::setMwRoot(Ogre::SceneNode* root){ mMwRoot = root; } +void Actors::insertNPC(const MWWorld::Ptr& ptr){ +/* + ESMS::LiveCellRef *ref = + ptr.get(); + assert (ref->base != NULL); + + insertBegin(ptr, true, true); + + //Part selection on last character of the file string + // " Tri Chest + // * Tri Tail + // : Tri Left Foot + // < Tri Right Foot + // > Tri Left Hand + // ? Tri Right Hand + // | Normal + + //Mirroring Parts on second to last character + //suffix == '*' + // vector = Ogre::Vector3(-1,1,1); + // suffix == '?' + // vector = Ogre::Vector3(1,-1,1); + // suffix == '<' + // vector = Ogre::Vector3(1,1,-1); + + + + std::string hairID = ref->base->hair; + std::string headID = ref->base->head; + std::string npcName = ref->base->name; + + std::string bodyRaceID = headID.substr(0, headID.find_last_of("head_") - 4); + char secondtolast = bodyRaceID.at(bodyRaceID.length() - 2); + bool female = tolower(secondtolast) == 'f'; + bool beast = bodyRaceID == "b_n_khajiit_m_" || bodyRaceID == "b_n_khajiit_f_" || bodyRaceID == "b_n_argonian_m_" || bodyRaceID == "b_n_argonian_f_"; + + std::string headModel = "meshes\\" + + mEnvironment.mWorld->getStore().bodyParts.find(headID)->model; + + std::string hairModel = "meshes\\" + + mEnvironment.mWorld->getStore().bodyParts.find(hairID)->model; + + const ESM::BodyPart *upperleg = mEnvironment.mWorld->getStore().bodyParts.search (bodyRaceID + "upper leg"); + const ESM::BodyPart *groin = mEnvironment.mWorld->getStore().bodyParts.search (bodyRaceID + "groin"); + const ESM::BodyPart *arml = mEnvironment.mWorld->getStore().bodyParts.search (bodyRaceID + "upper arm"); //We need two + const ESM::BodyPart *neck = mEnvironment.mWorld->getStore().bodyParts.search (bodyRaceID + "neck"); + const ESM::BodyPart *knee = mEnvironment.mWorld->getStore().bodyParts.search (bodyRaceID + "knee"); + const ESM::BodyPart *ankle = mEnvironment.mWorld->getStore().bodyParts.search (bodyRaceID + "ankle"); + const ESM::BodyPart *foot = mEnvironment.mWorld->getStore().bodyParts.search (bodyRaceID + "foot"); + const ESM::BodyPart *feet = mEnvironment.mWorld->getStore().bodyParts.search (bodyRaceID + "feet"); + const ESM::BodyPart *tail = mEnvironment.mWorld->getStore().bodyParts.search (bodyRaceID + "tail"); + const ESM::BodyPart *wristl = mEnvironment.mWorld->getStore().bodyParts.search (bodyRaceID + "wrist"); //We need two + const ESM::BodyPart *forearml = mEnvironment.mWorld->getStore().bodyParts.search (bodyRaceID + "forearm"); //We need two + const ESM::BodyPart *handl = mEnvironment.mWorld->getStore().bodyParts.search (bodyRaceID + "hand"); //We need two + const ESM::BodyPart *hair = mEnvironment.mWorld->getStore().bodyParts.search(hairID); + const ESM::BodyPart *head = mEnvironment.mWorld->getStore().bodyParts.search(headID); + if(!handl) + handl = mEnvironment.mWorld->getStore().bodyParts.search (bodyRaceID + "hands"); + //const ESM::BodyPart* claviclel = environment.mWorld->getStore().bodyParts.search (bodyRaceID + "clavicle"); + //const ESM::BodyPart* clavicler = claviclel; + const ESM::BodyPart* handr = handl; + const ESM::BodyPart* forearmr = forearml; + const ESM::BodyPart* wristr = wristl; + const ESM::BodyPart* armr = arml;*/ +} void Actors::insertBegin (const MWWorld::Ptr& ptr, bool enabled, bool static_){ Ogre::SceneNode* cellnode; if(mCellSceneNodes.find(ptr.getCell()) == mCellSceneNodes.end()) @@ -45,6 +111,11 @@ void Actors::insertBegin (const MWWorld::Ptr& ptr, bool enabled, bool static_){ ptr.getRefData().setBaseNode(insert); +} +void Actors::insertFreePart(const MWWorld::Ptr& ptr, const std::string& mesh){ + MeshPtr meshp = NIFLoader::load(mesh); + Entity *ent = mRend.getScene()->createEntity(mesh); + NIFLoader::getSingletonPtr()->addInMesh(ent->getMesh().getPointer()); } void Actors::insertMesh (const MWWorld::Ptr& ptr, const std::string& mesh){ Ogre::SceneNode* insert = ptr.getRefData().getBaseNode(); diff --git a/apps/openmw/mwrender/actors.hpp b/apps/openmw/mwrender/actors.hpp index abcc2a28b..5096c453d 100644 --- a/apps/openmw/mwrender/actors.hpp +++ b/apps/openmw/mwrender/actors.hpp @@ -7,20 +7,25 @@ #include "../mwworld/refdata.hpp" #include "../mwworld/ptr.hpp" #include +#include "components/nifogre/ogre_nif_loader.hpp" +#include "../mwworld/environment.hpp" namespace MWRender{ class Actors{ OEngine::Render::OgreRenderer &mRend; std::map mCellSceneNodes; Ogre::SceneNode* mMwRoot; + MWWorld::Environment& mEnvironment; public: - Actors(OEngine::Render::OgreRenderer& _rend): mRend(_rend){} + Actors(OEngine::Render::OgreRenderer& _rend, MWWorld::Environment& _env): mRend(_rend), mEnvironment(_env){} ~Actors(){} void setMwRoot(Ogre::SceneNode* root); void insertBegin (const MWWorld::Ptr& ptr, bool enabled, bool static_); void insertMesh (const MWWorld::Ptr& ptr, const std::string& mesh); + void insertFreePart(const MWWorld::Ptr& ptr, const std::string& mesh); + void insertNPC(const MWWorld::Ptr& ptr); bool deleteObject (const MWWorld::Ptr& ptr); ///< \return found? diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index 206dfbfd0..6f21db2b3 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -21,8 +21,8 @@ namespace MWRender { -RenderingManager::RenderingManager (OEngine::Render::OgreRenderer& _rend, const boost::filesystem::path& resDir, OEngine::Physic::PhysicEngine* engine) -:mRendering(_rend), mObjects(mRendering), mDebugging(engine), mActors(mRendering) +RenderingManager::RenderingManager (OEngine::Render::OgreRenderer& _rend, const boost::filesystem::path& resDir, OEngine::Physic::PhysicEngine* engine, MWWorld::Environment& environment) +:mRendering(_rend), mObjects(mRendering), mDebugging(engine), mActors(mRendering, environment) { mRendering.createScene("PlayerCam", 55, 5); mSkyManager = MWRender::SkyManager::create(mRendering.getWindow(), mRendering.getCamera(), resDir); diff --git a/apps/openmw/mwrender/renderingmanager.hpp b/apps/openmw/mwrender/renderingmanager.hpp index 5189db870..77a1f4a55 100644 --- a/apps/openmw/mwrender/renderingmanager.hpp +++ b/apps/openmw/mwrender/renderingmanager.hpp @@ -54,7 +54,7 @@ class RenderingManager: private RenderingInterface { virtual MWRender::Actors& getActors(); public: - RenderingManager(OEngine::Render::OgreRenderer& _rend, const boost::filesystem::path& resDir, OEngine::Physic::PhysicEngine* engine); + RenderingManager(OEngine::Render::OgreRenderer& _rend, const boost::filesystem::path& resDir, OEngine::Physic::PhysicEngine* engine, MWWorld::Environment& environment); virtual ~RenderingManager(); virtual MWRender::Player& getPlayer(); /// \todo move this to private again as soon as diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index 126bdaf38..6f41804c2 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -147,7 +147,7 @@ namespace MWWorld const Files::Collections& fileCollections, const std::string& master, const boost::filesystem::path& resDir, bool newGame, Environment& environment, const std::string& encoding) - : mRendering (renderer,resDir, physEng),mPlayer (0), mLocalScripts (mStore), mGlobalVariables (0), + : mRendering (renderer,resDir, physEng, environment),mPlayer (0), mLocalScripts (mStore), mGlobalVariables (0), mSky (false), mEnvironment (environment), mNextDynamicRecord (0), mCells (mStore, mEsm, *this) { mPhysEngine = physEng; From 5c48d8fc1e1ae159aea13df670b18bb6ce9ebda3 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Fri, 9 Dec 2011 03:02:09 -0500 Subject: [PATCH 062/104] more stuff --- apps/openmw/mwclass/npc.cpp | 13 --------- apps/openmw/mwrender/actors.cpp | 40 ++++++++++++++++++++++++-- apps/openmw/mwrender/actors.hpp | 11 +++++-- components/nifogre/ogre_nif_loader.cpp | 3 +- components/nifogre/ogre_nif_loader.hpp | 3 +- 5 files changed, 51 insertions(+), 19 deletions(-) diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index b5bb4b773..16b3cff75 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -33,19 +33,6 @@ namespace MWClass void Npc::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const { renderingInterface.getActors().insertNPC(ptr); - /* - ESMS::LiveCellRef *ref = - ptr.get(); - - assert (ref->base != NULL); - const std::string &model = ref->base->model; - - if (!model.empty()) - { - MWRender::Npcs& npcs = renderingInterface.getNPCs(); - //npcs.insertBegin(ptr, ptr.getRefData().isEnabled(), false); - //npcs.insertMesh(ptr, "meshes\\" + model); - }*/ } void Npc::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const diff --git a/apps/openmw/mwrender/actors.cpp b/apps/openmw/mwrender/actors.cpp index 6fbbd755f..1876bd3cf 100644 --- a/apps/openmw/mwrender/actors.cpp +++ b/apps/openmw/mwrender/actors.cpp @@ -1,6 +1,7 @@ #include "actors.hpp" #include #include +#include "../mwworld/world.hpp" using namespace Ogre; using namespace MWRender; @@ -9,8 +10,15 @@ using namespace NifOgre; void Actors::setMwRoot(Ogre::SceneNode* root){ mMwRoot = root; } +Ogre::Entity* Actors::insertBoundedPart(const std::string &mesh, std::string bonename, Ogre::Entity* base){ + NIFLoader::load(mesh); + Entity* ent = mRend.getScene()->createEntity(mesh); + + base->attachObjectToBone(bonename, ent); + return ent; + +} void Actors::insertNPC(const MWWorld::Ptr& ptr){ -/* ESMS::LiveCellRef *ref = ptr.get(); assert (ref->base != NULL); @@ -45,6 +53,18 @@ void Actors::insertNPC(const MWWorld::Ptr& ptr){ bool female = tolower(secondtolast) == 'f'; bool beast = bodyRaceID == "b_n_khajiit_m_" || bodyRaceID == "b_n_khajiit_f_" || bodyRaceID == "b_n_argonian_m_" || bodyRaceID == "b_n_argonian_f_"; + + std::string smodel = "meshes\\base_anim.nif"; + if(beast) + smodel = "meshes\\base_animkna.nif"; + + Ogre::SceneNode* insert = ptr.getRefData().getBaseNode(); + assert(insert); + + NifOgre::NIFLoader::load(smodel); + Entity *base = mRend.getScene()->createEntity(smodel); + insert->attachObject(base); + std::string headModel = "meshes\\" + mEnvironment.mWorld->getStore().bodyParts.find(headID)->model; @@ -72,7 +92,23 @@ void Actors::insertNPC(const MWWorld::Ptr& ptr){ const ESM::BodyPart* handr = handl; const ESM::BodyPart* forearmr = forearml; const ESM::BodyPart* wristr = wristl; - const ESM::BodyPart* armr = arml;*/ + const ESM::BodyPart* armr = arml; + if(upperleg){ + insertBoundedPart("meshes\\" + upperleg->model + "*|", "Left Upper Leg", base); + insertBoundedPart("meshes\\" + upperleg->model, "Right Upper Leg", base); + + } + if(foot){ + if(bodyRaceID.compare("b_n_khajiit_m_") == 0) + { + feet = foot; + } + else + { + insertBoundedPart("meshes\\" + foot->model, "Right Foot", base); + insertBoundedPart("meshes\\" + foot->model + "*|", "Left Foot", base); + } + } } void Actors::insertBegin (const MWWorld::Ptr& ptr, bool enabled, bool static_){ Ogre::SceneNode* cellnode; diff --git a/apps/openmw/mwrender/actors.hpp b/apps/openmw/mwrender/actors.hpp index 5096c453d..d533e77f9 100644 --- a/apps/openmw/mwrender/actors.hpp +++ b/apps/openmw/mwrender/actors.hpp @@ -4,11 +4,17 @@ #include "components/esm_store/cell_store.hpp" #include -#include "../mwworld/refdata.hpp" -#include "../mwworld/ptr.hpp" + + #include #include "components/nifogre/ogre_nif_loader.hpp" + +#include "../mwworld/refdata.hpp" +#include "../mwworld/ptr.hpp" +#include "../mwworld/actiontalk.hpp" #include "../mwworld/environment.hpp" + + namespace MWRender{ class Actors{ OEngine::Render::OgreRenderer &mRend; @@ -21,6 +27,7 @@ namespace MWRender{ public: Actors(OEngine::Render::OgreRenderer& _rend, MWWorld::Environment& _env): mRend(_rend), mEnvironment(_env){} ~Actors(){} + Ogre::Entity* Actors::insertBoundedPart(const std::string &mesh, std::string bonename, Ogre::Entity* base); void setMwRoot(Ogre::SceneNode* root); void insertBegin (const MWWorld::Ptr& ptr, bool enabled, bool static_); void insertMesh (const MWWorld::Ptr& ptr, const std::string& mesh); diff --git a/components/nifogre/ogre_nif_loader.cpp b/components/nifogre/ogre_nif_loader.cpp index 796ece5be..8be945950 100644 --- a/components/nifogre/ogre_nif_loader.cpp +++ b/components/nifogre/ogre_nif_loader.cpp @@ -476,6 +476,7 @@ void NIFLoader::createOgreSubMesh(NiTriShape *shape, const String &material, std HardwareBuffer::HBU_STATIC_WRITE_ONLY, true); if(flip && mFlipVertexWinding && sub->indexData->indexCount % 3 == 0){ + std::cout << "INTHEWINDING\n"; sub->indexData->indexBuffer = ibuf; uint16 *datamod = new uint16[numFaces]; @@ -1183,7 +1184,7 @@ void NIFLoader::loadResource(Resource *resource) } if(flip) { - //std::cout << "Flipping"; + std::cout << "Flipping"; calculateTransform(); } // Set up the VFS if it hasn't been done already diff --git a/components/nifogre/ogre_nif_loader.hpp b/components/nifogre/ogre_nif_loader.hpp index a5b33bcbe..ec0fb412a 100644 --- a/components/nifogre/ogre_nif_loader.hpp +++ b/components/nifogre/ogre_nif_loader.hpp @@ -119,7 +119,8 @@ class NIFLoader : Ogre::ManualResourceLoader Ogre::Quaternion convertRotation(const Nif::Matrix& rot); private: - NIFLoader() : resourceGroup("General") {resourceName = "";} + NIFLoader() : resourceGroup("General"),mNormaliseNormals(false), + mFlipVertexWinding(false), flip(false) {resourceName = "";} NIFLoader(NIFLoader& n) {} void calculateTransform(); From 39338f4be118f93b301b4a454b4f0e1eefd524b5 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Fri, 9 Dec 2011 15:20:35 -0500 Subject: [PATCH 063/104] NPC bounded parts --- apps/openmw/mwrender/actors.cpp | 54 ++++++++++++++++++++++++++ components/nifogre/ogre_nif_loader.cpp | 6 +-- 2 files changed, 55 insertions(+), 5 deletions(-) diff --git a/apps/openmw/mwrender/actors.cpp b/apps/openmw/mwrender/actors.cpp index 1876bd3cf..6a3aeba23 100644 --- a/apps/openmw/mwrender/actors.cpp +++ b/apps/openmw/mwrender/actors.cpp @@ -109,6 +109,60 @@ void Actors::insertNPC(const MWWorld::Ptr& ptr){ insertBoundedPart("meshes\\" + foot->model + "*|", "Left Foot", base); } } + if(groin){ + insertBoundedPart("meshes\\" + groin->model, "Groin", base); + } + if(knee) + { + insertBoundedPart("meshes\\" + knee->model + "*|", "Left Knee", base); //e + insertBoundedPart("meshes\\" + knee->model, "Right Knee", base); //e + + } + if(ankle){ + + insertBoundedPart("meshes\\" + ankle->model + "*|", "Left Ankle", base); //Ogre::Quaternion(Ogre::Radian(3.14 / 4), Ogre::Vector3(1, 0, 0)),blank); //1,0,0, blank); + insertBoundedPart("meshes\\" + ankle->model, "Right Ankle", base); + } + if (armr){ + insertBoundedPart("meshes\\" + armr->model, "Right Upper Arm", base); + } + if(arml){ + insertBoundedPart("meshes\\" + arml->model + "*|", "Left Upper Arm", base); + } + + if (forearmr) + { + insertBoundedPart("meshes\\" + forearmr->model, "Right Forearm", base); + } + if(forearml) + insertBoundedPart("meshes\\" + forearml->model + "*|", "Left Forearm", base); + + if (wristr) + { + insertBoundedPart("meshes\\" + wristr->model, "Right Wrist", base); + } + + if(wristl) + insertBoundedPart("meshes\\" + wristl->model + "*|", "Left Wrist", base); + + + + + + /*if(claviclel) + insertBoundedPart("meshes\\" + claviclel->model + "*|", "Left Clavicle", base); + if(clavicler) + insertBoundedPart("meshes\\" + clavicler->model , "Right Clavicle", base);*/ + + + if(neck) + { + insertBoundedPart("meshes\\" + neck->model, "Neck", base); + } + if(head) + insertBoundedPart("meshes\\" + head->model, "Head", base); + if(hair) + insertBoundedPart("meshes\\" + hair->model, "Head", base); } void Actors::insertBegin (const MWWorld::Ptr& ptr, bool enabled, bool static_){ Ogre::SceneNode* cellnode; diff --git a/components/nifogre/ogre_nif_loader.cpp b/components/nifogre/ogre_nif_loader.cpp index 8be945950..eb658dd25 100644 --- a/components/nifogre/ogre_nif_loader.cpp +++ b/components/nifogre/ogre_nif_loader.cpp @@ -343,7 +343,6 @@ void NIFLoader::createOgreSubMesh(NiTriShape *shape, const String &material, std { float *datamod = new float[data->vertices.length]; //std::cout << "Shape" << shape->name.toString() << "\n"; - //std::cout << "MTransform" << mTransform << "\n"; for(int i = 0; i < numVerts; i++) { int index = i * 3; @@ -368,7 +367,6 @@ void NIFLoader::createOgreSubMesh(NiTriShape *shape, const String &material, std vbuf->writeData(0, vbuf->getSizeInBytes(), data->vertices.ptr, false); } - vbuf->writeData(0, vbuf->getSizeInBytes(), data->vertices.ptr, true); VertexBufferBinding* bind = sub->vertexData->vertexBufferBinding; bind->setBinding(nextBuf++, vbuf); @@ -476,7 +474,6 @@ void NIFLoader::createOgreSubMesh(NiTriShape *shape, const String &material, std HardwareBuffer::HBU_STATIC_WRITE_ONLY, true); if(flip && mFlipVertexWinding && sub->indexData->indexCount % 3 == 0){ - std::cout << "INTHEWINDING\n"; sub->indexData->indexBuffer = ibuf; uint16 *datamod = new uint16[numFaces]; @@ -939,6 +936,7 @@ void NIFLoader::calculateTransform() // Calculate transform Matrix4 transform = Matrix4::IDENTITY; transform = Matrix4::getScale(vector) * transform; + // Check whether we have to flip vertex winding. // We do have to, if we changed our right hand base. // We can test it by using the cross product from X and Y and see, if it is a non-negative @@ -953,7 +951,6 @@ void NIFLoader::calculateTransform() } mTransform = transform; - } void NIFLoader::handleNode(Nif::Node *node, int flags, const Transformation *trafo, BoundsFinder &bounds, Ogre::Bone *parentBone, std::vector boneSequence) @@ -1184,7 +1181,6 @@ void NIFLoader::loadResource(Resource *resource) } if(flip) { - std::cout << "Flipping"; calculateTransform(); } // Set up the VFS if it hasn't been done already From 0902a3db89fbc39456cefb9cc58bbbfe049fcb37 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Sun, 11 Dec 2011 22:40:00 -0500 Subject: [PATCH 064/104] Filled out NpcAnimation and CreatureAnimation classes --- apps/openmw/mwclass/creature.cpp | 9 +- apps/openmw/mwrender/actors.cpp | 165 +-------------------- apps/openmw/mwrender/actors.hpp | 7 +- apps/openmw/mwrender/animation.hpp | 16 ++ apps/openmw/mwrender/creatureanimation.cpp | 23 +++ apps/openmw/mwrender/creatureanimation.hpp | 12 +- apps/openmw/mwrender/npcanimation.cpp | 165 +++++++++++++++++++++ apps/openmw/mwrender/npcanimation.hpp | 11 +- components/nifogre/ogre_nif_loader.cpp | 5 +- 9 files changed, 240 insertions(+), 173 deletions(-) diff --git a/apps/openmw/mwclass/creature.cpp b/apps/openmw/mwclass/creature.cpp index a58a851f2..e2f9ca6d8 100644 --- a/apps/openmw/mwclass/creature.cpp +++ b/apps/openmw/mwclass/creature.cpp @@ -25,18 +25,17 @@ namespace MWClass void Creature::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const { - ESMS::LiveCellRef *ref = + /*ESMS::LiveCellRef *ref = ptr.get(); assert (ref->base != NULL); const std::string &model = ref->base->model; if (!model.empty()) - { + {*/ MWRender::Actors& actors = renderingInterface.getActors(); - actors.insertBegin(ptr, ptr.getRefData().isEnabled(), false); - actors.insertMesh(ptr, "meshes\\" + model); - } + actors.insertCreature(ptr); + } void Creature::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const diff --git a/apps/openmw/mwrender/actors.cpp b/apps/openmw/mwrender/actors.cpp index 6a3aeba23..2f605dd73 100644 --- a/apps/openmw/mwrender/actors.cpp +++ b/apps/openmw/mwrender/actors.cpp @@ -3,6 +3,7 @@ #include #include "../mwworld/world.hpp" + using namespace Ogre; using namespace MWRender; using namespace NifOgre; @@ -10,159 +11,11 @@ using namespace NifOgre; void Actors::setMwRoot(Ogre::SceneNode* root){ mMwRoot = root; } -Ogre::Entity* Actors::insertBoundedPart(const std::string &mesh, std::string bonename, Ogre::Entity* base){ - NIFLoader::load(mesh); - Entity* ent = mRend.getScene()->createEntity(mesh); - - base->attachObjectToBone(bonename, ent); - return ent; - -} void Actors::insertNPC(const MWWorld::Ptr& ptr){ - ESMS::LiveCellRef *ref = - ptr.get(); - assert (ref->base != NULL); - insertBegin(ptr, true, true); + MWRender::NpcAnimation(ptr, mEnvironment, mRend); - //Part selection on last character of the file string - // " Tri Chest - // * Tri Tail - // : Tri Left Foot - // < Tri Right Foot - // > Tri Left Hand - // ? Tri Right Hand - // | Normal - - //Mirroring Parts on second to last character - //suffix == '*' - // vector = Ogre::Vector3(-1,1,1); - // suffix == '?' - // vector = Ogre::Vector3(1,-1,1); - // suffix == '<' - // vector = Ogre::Vector3(1,1,-1); - - - - std::string hairID = ref->base->hair; - std::string headID = ref->base->head; - std::string npcName = ref->base->name; - - std::string bodyRaceID = headID.substr(0, headID.find_last_of("head_") - 4); - char secondtolast = bodyRaceID.at(bodyRaceID.length() - 2); - bool female = tolower(secondtolast) == 'f'; - bool beast = bodyRaceID == "b_n_khajiit_m_" || bodyRaceID == "b_n_khajiit_f_" || bodyRaceID == "b_n_argonian_m_" || bodyRaceID == "b_n_argonian_f_"; - - - std::string smodel = "meshes\\base_anim.nif"; - if(beast) - smodel = "meshes\\base_animkna.nif"; - - Ogre::SceneNode* insert = ptr.getRefData().getBaseNode(); - assert(insert); - - NifOgre::NIFLoader::load(smodel); - Entity *base = mRend.getScene()->createEntity(smodel); - insert->attachObject(base); - - std::string headModel = "meshes\\" + - mEnvironment.mWorld->getStore().bodyParts.find(headID)->model; - - std::string hairModel = "meshes\\" + - mEnvironment.mWorld->getStore().bodyParts.find(hairID)->model; - - const ESM::BodyPart *upperleg = mEnvironment.mWorld->getStore().bodyParts.search (bodyRaceID + "upper leg"); - const ESM::BodyPart *groin = mEnvironment.mWorld->getStore().bodyParts.search (bodyRaceID + "groin"); - const ESM::BodyPart *arml = mEnvironment.mWorld->getStore().bodyParts.search (bodyRaceID + "upper arm"); //We need two - const ESM::BodyPart *neck = mEnvironment.mWorld->getStore().bodyParts.search (bodyRaceID + "neck"); - const ESM::BodyPart *knee = mEnvironment.mWorld->getStore().bodyParts.search (bodyRaceID + "knee"); - const ESM::BodyPart *ankle = mEnvironment.mWorld->getStore().bodyParts.search (bodyRaceID + "ankle"); - const ESM::BodyPart *foot = mEnvironment.mWorld->getStore().bodyParts.search (bodyRaceID + "foot"); - const ESM::BodyPart *feet = mEnvironment.mWorld->getStore().bodyParts.search (bodyRaceID + "feet"); - const ESM::BodyPart *tail = mEnvironment.mWorld->getStore().bodyParts.search (bodyRaceID + "tail"); - const ESM::BodyPart *wristl = mEnvironment.mWorld->getStore().bodyParts.search (bodyRaceID + "wrist"); //We need two - const ESM::BodyPart *forearml = mEnvironment.mWorld->getStore().bodyParts.search (bodyRaceID + "forearm"); //We need two - const ESM::BodyPart *handl = mEnvironment.mWorld->getStore().bodyParts.search (bodyRaceID + "hand"); //We need two - const ESM::BodyPart *hair = mEnvironment.mWorld->getStore().bodyParts.search(hairID); - const ESM::BodyPart *head = mEnvironment.mWorld->getStore().bodyParts.search(headID); - if(!handl) - handl = mEnvironment.mWorld->getStore().bodyParts.search (bodyRaceID + "hands"); - //const ESM::BodyPart* claviclel = environment.mWorld->getStore().bodyParts.search (bodyRaceID + "clavicle"); - //const ESM::BodyPart* clavicler = claviclel; - const ESM::BodyPart* handr = handl; - const ESM::BodyPart* forearmr = forearml; - const ESM::BodyPart* wristr = wristl; - const ESM::BodyPart* armr = arml; - if(upperleg){ - insertBoundedPart("meshes\\" + upperleg->model + "*|", "Left Upper Leg", base); - insertBoundedPart("meshes\\" + upperleg->model, "Right Upper Leg", base); - - } - if(foot){ - if(bodyRaceID.compare("b_n_khajiit_m_") == 0) - { - feet = foot; - } - else - { - insertBoundedPart("meshes\\" + foot->model, "Right Foot", base); - insertBoundedPart("meshes\\" + foot->model + "*|", "Left Foot", base); - } - } - if(groin){ - insertBoundedPart("meshes\\" + groin->model, "Groin", base); - } - if(knee) - { - insertBoundedPart("meshes\\" + knee->model + "*|", "Left Knee", base); //e - insertBoundedPart("meshes\\" + knee->model, "Right Knee", base); //e - - } - if(ankle){ - - insertBoundedPart("meshes\\" + ankle->model + "*|", "Left Ankle", base); //Ogre::Quaternion(Ogre::Radian(3.14 / 4), Ogre::Vector3(1, 0, 0)),blank); //1,0,0, blank); - insertBoundedPart("meshes\\" + ankle->model, "Right Ankle", base); - } - if (armr){ - insertBoundedPart("meshes\\" + armr->model, "Right Upper Arm", base); - } - if(arml){ - insertBoundedPart("meshes\\" + arml->model + "*|", "Left Upper Arm", base); - } - - if (forearmr) - { - insertBoundedPart("meshes\\" + forearmr->model, "Right Forearm", base); - } - if(forearml) - insertBoundedPart("meshes\\" + forearml->model + "*|", "Left Forearm", base); - - if (wristr) - { - insertBoundedPart("meshes\\" + wristr->model, "Right Wrist", base); - } - - if(wristl) - insertBoundedPart("meshes\\" + wristl->model + "*|", "Left Wrist", base); - - - - - /*if(claviclel) - insertBoundedPart("meshes\\" + claviclel->model + "*|", "Left Clavicle", base); - if(clavicler) - insertBoundedPart("meshes\\" + clavicler->model , "Right Clavicle", base);*/ - - - if(neck) - { - insertBoundedPart("meshes\\" + neck->model, "Neck", base); - } - if(head) - insertBoundedPart("meshes\\" + head->model, "Head", base); - if(hair) - insertBoundedPart("meshes\\" + hair->model, "Head", base); } void Actors::insertBegin (const MWWorld::Ptr& ptr, bool enabled, bool static_){ Ogre::SceneNode* cellnode; @@ -202,18 +55,10 @@ void Actors::insertBegin (const MWWorld::Ptr& ptr, bool enabled, bool static_){ } -void Actors::insertFreePart(const MWWorld::Ptr& ptr, const std::string& mesh){ - MeshPtr meshp = NIFLoader::load(mesh); - Entity *ent = mRend.getScene()->createEntity(mesh); - NIFLoader::getSingletonPtr()->addInMesh(ent->getMesh().getPointer()); -} -void Actors::insertMesh (const MWWorld::Ptr& ptr, const std::string& mesh){ - Ogre::SceneNode* insert = ptr.getRefData().getBaseNode(); - assert(insert); +void Actors::insertCreature (const MWWorld::Ptr& ptr){ + insertBegin(ptr, true, true); - NifOgre::NIFLoader::load(mesh); - Entity *ent = mRend.getScene()->createEntity(mesh); - insert->attachObject(ent); + MWRender::CreatureAnimation(ptr, mEnvironment, mRend); } bool Actors::deleteObject (const MWWorld::Ptr& ptr) diff --git a/apps/openmw/mwrender/actors.hpp b/apps/openmw/mwrender/actors.hpp index d533e77f9..1fe0c2e34 100644 --- a/apps/openmw/mwrender/actors.hpp +++ b/apps/openmw/mwrender/actors.hpp @@ -13,7 +13,8 @@ #include "../mwworld/ptr.hpp" #include "../mwworld/actiontalk.hpp" #include "../mwworld/environment.hpp" - +#include "npcanimation.hpp" +#include "creatureanimation.hpp" namespace MWRender{ class Actors{ @@ -27,11 +28,9 @@ namespace MWRender{ public: Actors(OEngine::Render::OgreRenderer& _rend, MWWorld::Environment& _env): mRend(_rend), mEnvironment(_env){} ~Actors(){} - Ogre::Entity* Actors::insertBoundedPart(const std::string &mesh, std::string bonename, Ogre::Entity* base); void setMwRoot(Ogre::SceneNode* root); void insertBegin (const MWWorld::Ptr& ptr, bool enabled, bool static_); - void insertMesh (const MWWorld::Ptr& ptr, const std::string& mesh); - void insertFreePart(const MWWorld::Ptr& ptr, const std::string& mesh); + void insertCreature (const MWWorld::Ptr& ptr); void insertNPC(const MWWorld::Ptr& ptr); bool deleteObject (const MWWorld::Ptr& ptr); ///< \return found? diff --git a/apps/openmw/mwrender/animation.hpp b/apps/openmw/mwrender/animation.hpp index cb922d7f3..81938155f 100644 --- a/apps/openmw/mwrender/animation.hpp +++ b/apps/openmw/mwrender/animation.hpp @@ -1,10 +1,26 @@ #ifndef _GAME_RENDER_ANIMATION_H #define _GAME_RENDER_ANIMATION_H #include +#include +#include "../mwworld/refdata.hpp" +#include "../mwworld/ptr.hpp" +#include "../mwworld/actiontalk.hpp" +#include "../mwworld/environment.hpp" + namespace MWRender{ + class Animation{ + protected: + OEngine::Render::OgreRenderer &mRend; + MWWorld::Environment& mEnvironment; + + std::vector transformations; std::map textmappings; + Ogre::Entity* base; + public: + Animation(MWWorld::Environment& _env, OEngine::Render::OgreRenderer& _rend): mRend(_rend), mEnvironment(_env){}; + }; } #endif \ No newline at end of file diff --git a/apps/openmw/mwrender/creatureanimation.cpp b/apps/openmw/mwrender/creatureanimation.cpp index e69de29bb..403f5da61 100644 --- a/apps/openmw/mwrender/creatureanimation.cpp +++ b/apps/openmw/mwrender/creatureanimation.cpp @@ -0,0 +1,23 @@ +#include "creatureanimation.hpp" + +#include "../mwworld/world.hpp" + +using namespace Ogre; +using namespace NifOgre; +namespace MWRender{ +CreatureAnimation::CreatureAnimation(const MWWorld::Ptr& ptr, MWWorld::Environment& _env,OEngine::Render::OgreRenderer& _rend): Animation(_env,_rend){ + Ogre::SceneNode* insert = ptr.getRefData().getBaseNode(); + assert(insert); + ESMS::LiveCellRef *ref = + ptr.get(); + + assert (ref->base != NULL); + if(!ref->base->model.empty()){ + const std::string &mesh = "meshes\\" + ref->base->model; + + NifOgre::NIFLoader::load(mesh); + base = mRend.getScene()->createEntity(mesh); + insert->attachObject(base); + } +} +} \ No newline at end of file diff --git a/apps/openmw/mwrender/creatureanimation.hpp b/apps/openmw/mwrender/creatureanimation.hpp index 2bad5f769..26e4f33e0 100644 --- a/apps/openmw/mwrender/creatureanimation.hpp +++ b/apps/openmw/mwrender/creatureanimation.hpp @@ -3,10 +3,20 @@ #include "animation.hpp" #include + + +#include "../mwworld/refdata.hpp" +#include "../mwworld/ptr.hpp" +#include "../mwworld/environment.hpp" +#include "components/nifogre/ogre_nif_loader.hpp" + + namespace MWRender{ -class CreatureAnimation: Animation{ +class CreatureAnimation: public Animation{ std::vector shapes; //All the NiTriShapeData for this creature + public: + CreatureAnimation(const MWWorld::Ptr& ptr, MWWorld::Environment& _env, OEngine::Render::OgreRenderer& _rend); }; } #endif \ No newline at end of file diff --git a/apps/openmw/mwrender/npcanimation.cpp b/apps/openmw/mwrender/npcanimation.cpp index e69de29bb..b2a3d5825 100644 --- a/apps/openmw/mwrender/npcanimation.cpp +++ b/apps/openmw/mwrender/npcanimation.cpp @@ -0,0 +1,165 @@ +#include "npcanimation.hpp" +#include "../mwworld/world.hpp" + +using namespace Ogre; +using namespace NifOgre; +namespace MWRender{ + +NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, MWWorld::Environment& _env,OEngine::Render::OgreRenderer& _rend): Animation(_env,_rend){ + ESMS::LiveCellRef *ref = + ptr.get(); + //assert (ref->base != NULL); + + //insertBegin(ptr, true, true); + + //Part selection on last character of the file string + // " Tri Chest + // * Tri Tail + // : Tri Left Foot + // < Tri Right Foot + // > Tri Left Hand + // ? Tri Right Hand + // | Normal + + //Mirroring Parts on second to last character + //suffix == '*' + // vector = Ogre::Vector3(-1,1,1); + // suffix == '?' + // vector = Ogre::Vector3(1,-1,1); + // suffix == '<' + // vector = Ogre::Vector3(1,1,-1); + + + + std::string hairID = ref->base->hair; + std::string headID = ref->base->head; + std::string npcName = ref->base->name; + + std::string bodyRaceID = headID.substr(0, headID.find_last_of("head_") - 4); + char secondtolast = bodyRaceID.at(bodyRaceID.length() - 2); + bool female = tolower(secondtolast) == 'f'; + bool beast = bodyRaceID == "b_n_khajiit_m_" || bodyRaceID == "b_n_khajiit_f_" || bodyRaceID == "b_n_argonian_m_" || bodyRaceID == "b_n_argonian_f_"; + + + std::string smodel = "meshes\\base_anim.nif"; + if(beast) + smodel = "meshes\\base_animkna.nif"; + + Ogre::SceneNode* insert = ptr.getRefData().getBaseNode(); + assert(insert); + + NifOgre::NIFLoader::load(smodel); + + base = mRend.getScene()->createEntity(smodel); + insert->attachObject(base); + std::cout << "Nifloader\n"; + + std::string headModel = "meshes\\" + + mEnvironment.mWorld->getStore().bodyParts.find(headID)->model; + + std::string hairModel = "meshes\\" + + mEnvironment.mWorld->getStore().bodyParts.find(hairID)->model; + + const ESM::BodyPart *upperleg = mEnvironment.mWorld->getStore().bodyParts.search (bodyRaceID + "upper leg"); + const ESM::BodyPart *groin = mEnvironment.mWorld->getStore().bodyParts.search (bodyRaceID + "groin"); + const ESM::BodyPart *arml = mEnvironment.mWorld->getStore().bodyParts.search (bodyRaceID + "upper arm"); //We need two + const ESM::BodyPart *neck = mEnvironment.mWorld->getStore().bodyParts.search (bodyRaceID + "neck"); + const ESM::BodyPart *knee = mEnvironment.mWorld->getStore().bodyParts.search (bodyRaceID + "knee"); + const ESM::BodyPart *ankle = mEnvironment.mWorld->getStore().bodyParts.search (bodyRaceID + "ankle"); + const ESM::BodyPart *foot = mEnvironment.mWorld->getStore().bodyParts.search (bodyRaceID + "foot"); + const ESM::BodyPart *feet = mEnvironment.mWorld->getStore().bodyParts.search (bodyRaceID + "feet"); + const ESM::BodyPart *tail = mEnvironment.mWorld->getStore().bodyParts.search (bodyRaceID + "tail"); + const ESM::BodyPart *wristl = mEnvironment.mWorld->getStore().bodyParts.search (bodyRaceID + "wrist"); //We need two + const ESM::BodyPart *forearml = mEnvironment.mWorld->getStore().bodyParts.search (bodyRaceID + "forearm"); //We need two + const ESM::BodyPart *handl = mEnvironment.mWorld->getStore().bodyParts.search (bodyRaceID + "hand"); //We need two + const ESM::BodyPart *hair = mEnvironment.mWorld->getStore().bodyParts.search(hairID); + const ESM::BodyPart *head = mEnvironment.mWorld->getStore().bodyParts.search(headID); + if(!handl) + handl = mEnvironment.mWorld->getStore().bodyParts.search (bodyRaceID + "hands"); + //const ESM::BodyPart* claviclel = environment.mWorld->getStore().bodyParts.search (bodyRaceID + "clavicle"); + //const ESM::BodyPart* clavicler = claviclel; + const ESM::BodyPart* handr = handl; + const ESM::BodyPart* forearmr = forearml; + const ESM::BodyPart* wristr = wristl; + const ESM::BodyPart* armr = arml; + std::cout << "upperleg"; + if(upperleg){ + insertBoundedPart("meshes\\" + upperleg->model + "*|", "Left Upper Leg"); + insertBoundedPart("meshes\\" + upperleg->model, "Right Upper Leg"); + + } + if(foot){ + if(bodyRaceID.compare("b_n_khajiit_m_") == 0) + { + feet = foot; + } + else + { + insertBoundedPart("meshes\\" + foot->model, "Right Foot"); + insertBoundedPart("meshes\\" + foot->model + "*|", "Left Foot"); + } + } + if(groin){ + insertBoundedPart("meshes\\" + groin->model, "Groin"); + } + if(knee) + { + insertBoundedPart("meshes\\" + knee->model + "*|", "Left Knee"); //e + insertBoundedPart("meshes\\" + knee->model, "Right Knee"); //e + + } + if(ankle){ + + insertBoundedPart("meshes\\" + ankle->model + "*|", "Left Ankle"); //Ogre::Quaternion(Ogre::Radian(3.14 / 4), Ogre::Vector3(1, 0, 0)),blank); //1,0,0, blank); + insertBoundedPart("meshes\\" + ankle->model, "Right Ankle"); + } + if (armr){ + insertBoundedPart("meshes\\" + armr->model, "Right Upper Arm"); + } + if(arml){ + insertBoundedPart("meshes\\" + arml->model + "*|", "Left Upper Arm"); + } + + if (forearmr) + { + insertBoundedPart("meshes\\" + forearmr->model, "Right Forearm"); + } + if(forearml) + insertBoundedPart("meshes\\" + forearml->model + "*|", "Left Forearm"); + + if (wristr) + { + insertBoundedPart("meshes\\" + wristr->model, "Right Wrist"); + } + + if(wristl) + insertBoundedPart("meshes\\" + wristl->model + "*|", "Left Wrist"); + + + + + + /*if(claviclel) + insertBoundedPart("meshes\\" + claviclel->model + "*|", "Left Clavicle", base); + if(clavicler) + insertBoundedPart("meshes\\" + clavicler->model , "Right Clavicle", base);*/ + + + if(neck) + { + insertBoundedPart("meshes\\" + neck->model, "Neck"); + } + if(head) + insertBoundedPart("meshes\\" + head->model, "Head"); + if(hair) + insertBoundedPart("meshes\\" + hair->model, "Head"); +} + +Ogre::Entity* NpcAnimation::insertBoundedPart(const std::string &mesh, std::string bonename){ + NIFLoader::load(mesh); + Entity* ent = mRend.getScene()->createEntity(mesh); + + base->attachObjectToBone(bonename, ent); + return ent; +} +} \ No newline at end of file diff --git a/apps/openmw/mwrender/npcanimation.hpp b/apps/openmw/mwrender/npcanimation.hpp index 9358e2c0a..b9c55ff93 100644 --- a/apps/openmw/mwrender/npcanimation.hpp +++ b/apps/openmw/mwrender/npcanimation.hpp @@ -3,10 +3,19 @@ #include "animation.hpp" #include #include + +#include "../mwworld/refdata.hpp" +#include "../mwworld/ptr.hpp" +#include "../mwworld/environment.hpp" +#include "components/nifogre/ogre_nif_loader.hpp" + namespace MWRender{ -class NpcAnimation: Animation{ +class NpcAnimation: public Animation{ std::vector> shapeparts; //All the NiTriShape data that we need for animating this particular npc + public: + NpcAnimation(const MWWorld::Ptr& ptr, MWWorld::Environment& _env, OEngine::Render::OgreRenderer& _rend); + Ogre::Entity* insertBoundedPart(const std::string &mesh, std::string bonename); }; } #endif \ No newline at end of file diff --git a/components/nifogre/ogre_nif_loader.cpp b/components/nifogre/ogre_nif_loader.cpp index eb658dd25..8f19be44c 100644 --- a/components/nifogre/ogre_nif_loader.cpp +++ b/components/nifogre/ogre_nif_loader.cpp @@ -474,6 +474,7 @@ void NIFLoader::createOgreSubMesh(NiTriShape *shape, const String &material, std HardwareBuffer::HBU_STATIC_WRITE_ONLY, true); if(flip && mFlipVertexWinding && sub->indexData->indexCount % 3 == 0){ + sub->indexData->indexBuffer = ibuf; uint16 *datamod = new uint16[numFaces]; @@ -1109,10 +1110,10 @@ void NIFLoader::handleNode(Nif::Node *node, int flags, { handleNiTriShape(dynamic_cast(node), flags, bounds, original, boneSequence); } - else if(name.length() >= triname.length()) + else if(nodename.length() >= triname.length()) { std::transform(nodename.begin(), nodename.end(), nodename.begin(), std::tolower); - if(triname == name.substr(0, triname.length())) + if(triname == nodename.substr(0, triname.length())) handleNiTriShape(dynamic_cast(node), flags, bounds, original, boneSequence); } } From 509009e5c16b41d389378abd0655d26df85972db Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Sun, 11 Dec 2011 23:42:39 -0500 Subject: [PATCH 065/104] Putting the actors in a list --- apps/openmw/mwrender/actors.cpp | 8 +++++--- apps/openmw/mwrender/actors.hpp | 2 ++ apps/openmw/mwrender/animation.cpp | 7 +++++++ apps/openmw/mwrender/animation.hpp | 1 + apps/openmw/mwrender/creatureanimation.cpp | 4 ++++ apps/openmw/mwrender/creatureanimation.hpp | 1 + apps/openmw/mwrender/npcanimation.cpp | 5 +++-- apps/openmw/mwrender/npcanimation.hpp | 1 + 8 files changed, 24 insertions(+), 5 deletions(-) diff --git a/apps/openmw/mwrender/actors.cpp b/apps/openmw/mwrender/actors.cpp index 2f605dd73..f2fa59786 100644 --- a/apps/openmw/mwrender/actors.cpp +++ b/apps/openmw/mwrender/actors.cpp @@ -13,7 +13,8 @@ void Actors::setMwRoot(Ogre::SceneNode* root){ } void Actors::insertNPC(const MWWorld::Ptr& ptr){ insertBegin(ptr, true, true); - MWRender::NpcAnimation(ptr, mEnvironment, mRend); + MWRender::Animation anim = MWRender::NpcAnimation(ptr, mEnvironment, mRend); + mAllActors.push_back(anim); } @@ -57,8 +58,8 @@ void Actors::insertBegin (const MWWorld::Ptr& ptr, bool enabled, bool static_){ } void Actors::insertCreature (const MWWorld::Ptr& ptr){ insertBegin(ptr, true, true); - - MWRender::CreatureAnimation(ptr, mEnvironment, mRend); + MWRender::Animation anim = MWRender::CreatureAnimation(ptr, mEnvironment, mRend); + mAllActors.push_back(anim); } bool Actors::deleteObject (const MWWorld::Ptr& ptr) @@ -92,4 +93,5 @@ void Actors::removeCell(MWWorld::Ptr::CellStore* store){ mRend.getScene()->destroySceneNode(base); base = 0; } + } \ No newline at end of file diff --git a/apps/openmw/mwrender/actors.hpp b/apps/openmw/mwrender/actors.hpp index 1fe0c2e34..82e4de6ad 100644 --- a/apps/openmw/mwrender/actors.hpp +++ b/apps/openmw/mwrender/actors.hpp @@ -3,6 +3,7 @@ #include "components/esm_store/cell_store.hpp" #include +#include @@ -22,6 +23,7 @@ namespace MWRender{ std::map mCellSceneNodes; Ogre::SceneNode* mMwRoot; MWWorld::Environment& mEnvironment; + std::list mAllActors; diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index e69de29bb..067fb8f2a 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -0,0 +1,7 @@ +#include "animation.hpp" + +namespace MWRender{ + Animation::~Animation(){ + base = 0; + } +} \ No newline at end of file diff --git a/apps/openmw/mwrender/animation.hpp b/apps/openmw/mwrender/animation.hpp index 81938155f..82dca80b2 100644 --- a/apps/openmw/mwrender/animation.hpp +++ b/apps/openmw/mwrender/animation.hpp @@ -20,6 +20,7 @@ class Animation{ Ogre::Entity* base; public: Animation(MWWorld::Environment& _env, OEngine::Render::OgreRenderer& _rend): mRend(_rend), mEnvironment(_env){}; + ~Animation(); }; } diff --git a/apps/openmw/mwrender/creatureanimation.cpp b/apps/openmw/mwrender/creatureanimation.cpp index 403f5da61..66bc4d4d9 100644 --- a/apps/openmw/mwrender/creatureanimation.cpp +++ b/apps/openmw/mwrender/creatureanimation.cpp @@ -5,6 +5,10 @@ using namespace Ogre; using namespace NifOgre; namespace MWRender{ + +CreatureAnimation::~CreatureAnimation(){ + +} CreatureAnimation::CreatureAnimation(const MWWorld::Ptr& ptr, MWWorld::Environment& _env,OEngine::Render::OgreRenderer& _rend): Animation(_env,_rend){ Ogre::SceneNode* insert = ptr.getRefData().getBaseNode(); assert(insert); diff --git a/apps/openmw/mwrender/creatureanimation.hpp b/apps/openmw/mwrender/creatureanimation.hpp index 26e4f33e0..9bbd149ce 100644 --- a/apps/openmw/mwrender/creatureanimation.hpp +++ b/apps/openmw/mwrender/creatureanimation.hpp @@ -16,6 +16,7 @@ namespace MWRender{ class CreatureAnimation: public Animation{ std::vector shapes; //All the NiTriShapeData for this creature public: + ~CreatureAnimation(); CreatureAnimation(const MWWorld::Ptr& ptr, MWWorld::Environment& _env, OEngine::Render::OgreRenderer& _rend); }; } diff --git a/apps/openmw/mwrender/npcanimation.cpp b/apps/openmw/mwrender/npcanimation.cpp index b2a3d5825..c33892c21 100644 --- a/apps/openmw/mwrender/npcanimation.cpp +++ b/apps/openmw/mwrender/npcanimation.cpp @@ -4,6 +4,9 @@ using namespace Ogre; using namespace NifOgre; namespace MWRender{ +NpcAnimation::~NpcAnimation(){ + +} NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, MWWorld::Environment& _env,OEngine::Render::OgreRenderer& _rend): Animation(_env,_rend){ ESMS::LiveCellRef *ref = @@ -52,7 +55,6 @@ NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, MWWorld::Environment& _env,O base = mRend.getScene()->createEntity(smodel); insert->attachObject(base); - std::cout << "Nifloader\n"; std::string headModel = "meshes\\" + mEnvironment.mWorld->getStore().bodyParts.find(headID)->model; @@ -82,7 +84,6 @@ NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, MWWorld::Environment& _env,O const ESM::BodyPart* forearmr = forearml; const ESM::BodyPart* wristr = wristl; const ESM::BodyPart* armr = arml; - std::cout << "upperleg"; if(upperleg){ insertBoundedPart("meshes\\" + upperleg->model + "*|", "Left Upper Leg"); insertBoundedPart("meshes\\" + upperleg->model, "Right Upper Leg"); diff --git a/apps/openmw/mwrender/npcanimation.hpp b/apps/openmw/mwrender/npcanimation.hpp index b9c55ff93..90204f6d5 100644 --- a/apps/openmw/mwrender/npcanimation.hpp +++ b/apps/openmw/mwrender/npcanimation.hpp @@ -15,6 +15,7 @@ class NpcAnimation: public Animation{ std::vector> shapeparts; //All the NiTriShape data that we need for animating this particular npc public: NpcAnimation(const MWWorld::Ptr& ptr, MWWorld::Environment& _env, OEngine::Render::OgreRenderer& _rend); + ~NpcAnimation(); Ogre::Entity* insertBoundedPart(const std::string &mesh, std::string bonename); }; } From 47112ad7f985f32c04514bb752fdd0b60e0fca12 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Tue, 13 Dec 2011 23:49:03 -0500 Subject: [PATCH 066/104] Changing a lot of things --- apps/openmw/mwrender/actors.cpp | 11 ++++---- apps/openmw/mwrender/actors.hpp | 2 +- apps/openmw/mwrender/animation.hpp | 18 ++++++++++++- apps/openmw/mwrender/npcanimation.cpp | 34 +++++++++++++++++++++++-- apps/openmw/mwrender/npcanimation.hpp | 8 +++++- components/nifogre/ogre_nif_loader.cpp | 35 +++++++++++--------------- components/nifogre/ogre_nif_loader.hpp | 6 ++--- 7 files changed, 80 insertions(+), 34 deletions(-) diff --git a/apps/openmw/mwrender/actors.cpp b/apps/openmw/mwrender/actors.cpp index f2fa59786..d3493bf4a 100644 --- a/apps/openmw/mwrender/actors.cpp +++ b/apps/openmw/mwrender/actors.cpp @@ -1,7 +1,7 @@ #include "actors.hpp" #include #include -#include "../mwworld/world.hpp" + using namespace Ogre; @@ -13,8 +13,8 @@ void Actors::setMwRoot(Ogre::SceneNode* root){ } void Actors::insertNPC(const MWWorld::Ptr& ptr){ insertBegin(ptr, true, true); - MWRender::Animation anim = MWRender::NpcAnimation(ptr, mEnvironment, mRend); - mAllActors.push_back(anim); + NpcAnimation* anim = new MWRender::NpcAnimation(ptr, mEnvironment, mRend); + mAllActors.push_back(anim); } @@ -58,8 +58,9 @@ void Actors::insertBegin (const MWWorld::Ptr& ptr, bool enabled, bool static_){ } void Actors::insertCreature (const MWWorld::Ptr& ptr){ insertBegin(ptr, true, true); - MWRender::Animation anim = MWRender::CreatureAnimation(ptr, mEnvironment, mRend); - mAllActors.push_back(anim); + CreatureAnimation* anim = new MWRender::CreatureAnimation(ptr, mEnvironment, mRend); + mAllActors.push_back(anim); + //mAllActors.push_back(&anim); } bool Actors::deleteObject (const MWWorld::Ptr& ptr) diff --git a/apps/openmw/mwrender/actors.hpp b/apps/openmw/mwrender/actors.hpp index 82e4de6ad..afd6e9ae6 100644 --- a/apps/openmw/mwrender/actors.hpp +++ b/apps/openmw/mwrender/actors.hpp @@ -23,7 +23,7 @@ namespace MWRender{ std::map mCellSceneNodes; Ogre::SceneNode* mMwRoot; MWWorld::Environment& mEnvironment; - std::list mAllActors; + std::list mAllActors; diff --git a/apps/openmw/mwrender/animation.hpp b/apps/openmw/mwrender/animation.hpp index 82dca80b2..111e2d0c7 100644 --- a/apps/openmw/mwrender/animation.hpp +++ b/apps/openmw/mwrender/animation.hpp @@ -13,9 +13,25 @@ class Animation{ protected: OEngine::Render::OgreRenderer &mRend; MWWorld::Environment& mEnvironment; + + float time; + float startTime; + float stopTime; + bool loop; + //Represents a rotation index for each bone + std::vectorrindexI; + //Represents a translation index for each bone + std::vectortindexI; + + //Only shapes with morphing data will need a shape number + int shapeNumber; + std::vector> shapeIndexI; + + Ogre::SkeletonInstance* skel; + - std::vector transformations; + std::vector* transformations; std::map textmappings; Ogre::Entity* base; public: diff --git a/apps/openmw/mwrender/npcanimation.cpp b/apps/openmw/mwrender/npcanimation.cpp index c33892c21..bd60a548e 100644 --- a/apps/openmw/mwrender/npcanimation.cpp +++ b/apps/openmw/mwrender/npcanimation.cpp @@ -1,6 +1,7 @@ #include "npcanimation.hpp" #include "../mwworld/world.hpp" + using namespace Ogre; using namespace NifOgre; namespace MWRender{ @@ -54,6 +55,15 @@ NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, MWWorld::Environment& _env,O NifOgre::NIFLoader::load(smodel); base = mRend.getScene()->createEntity(smodel); + + /* + transformations = &(NIFLoader::getSingletonPtr())->getAnim(smodel); + for(int init = 0; init < transformations->size(); init++){ + rindexI.push_back(0); + //a.rindexJ.push_back(0); + tindexI.push_back(0); + //a.tindexJ.push_back(0); + }*/ insert->attachObject(base); std::string headModel = "meshes\\" + @@ -61,7 +71,7 @@ NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, MWWorld::Environment& _env,O std::string hairModel = "meshes\\" + mEnvironment.mWorld->getStore().bodyParts.find(hairID)->model; - + const ESM::BodyPart *chest = mEnvironment.mWorld->getStore().bodyParts.search (bodyRaceID + "chest"); const ESM::BodyPart *upperleg = mEnvironment.mWorld->getStore().bodyParts.search (bodyRaceID + "upper leg"); const ESM::BodyPart *groin = mEnvironment.mWorld->getStore().bodyParts.search (bodyRaceID + "groin"); const ESM::BodyPart *arml = mEnvironment.mWorld->getStore().bodyParts.search (bodyRaceID + "upper arm"); //We need two @@ -136,7 +146,7 @@ NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, MWWorld::Environment& _env,O if(wristl) insertBoundedPart("meshes\\" + wristl->model + "*|", "Left Wrist"); - + @@ -154,6 +164,15 @@ NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, MWWorld::Environment& _env,O insertBoundedPart("meshes\\" + head->model, "Head"); if(hair) insertBoundedPart("meshes\\" + hair->model, "Head"); + + if (chest){ + insertFreePart("meshes\\" + chest->model + "|\"", insert); + + } + if (handr){ + insertFreePart("meshes\\" + handr->model + "|?", insert); + + } } Ogre::Entity* NpcAnimation::insertBoundedPart(const std::string &mesh, std::string bonename){ @@ -162,5 +181,16 @@ Ogre::Entity* NpcAnimation::insertBoundedPart(const std::string &mesh, std::stri base->attachObjectToBone(bonename, ent); return ent; +} +void NpcAnimation::insertFreePart(const std::string &mesh, Ogre::SceneNode* insert){ + NIFLoader::load(mesh); + Entity* ent = mRend.getScene()->createEntity(mesh); + insert->attachObject(ent); + entityparts.push_back(ent); + //std::vector shapes = (NIFLoader::getSingletonPtr())->getShapes(mesh); + std::vector* shapes = ((NIFLoader::getSingletonPtr())->getShapes(mesh)); + shapeparts.push_back(shapes); + + } } \ No newline at end of file diff --git a/apps/openmw/mwrender/npcanimation.hpp b/apps/openmw/mwrender/npcanimation.hpp index 90204f6d5..96a2eeb31 100644 --- a/apps/openmw/mwrender/npcanimation.hpp +++ b/apps/openmw/mwrender/npcanimation.hpp @@ -3,6 +3,9 @@ #include "animation.hpp" #include #include +#include +#include +#include #include "../mwworld/refdata.hpp" #include "../mwworld/ptr.hpp" @@ -12,11 +15,14 @@ namespace MWRender{ class NpcAnimation: public Animation{ - std::vector> shapeparts; //All the NiTriShape data that we need for animating this particular npc + std::vector entityparts; + + std::vector*> shapeparts; //All the NiTriShape data that we need for animating this particular npc public: NpcAnimation(const MWWorld::Ptr& ptr, MWWorld::Environment& _env, OEngine::Render::OgreRenderer& _rend); ~NpcAnimation(); Ogre::Entity* insertBoundedPart(const std::string &mesh, std::string bonename); + void insertFreePart(const std::string &mesh, Ogre::SceneNode* insert); }; } #endif \ No newline at end of file diff --git a/components/nifogre/ogre_nif_loader.cpp b/components/nifogre/ogre_nif_loader.cpp index 8f19be44c..26b1111a1 100644 --- a/components/nifogre/ogre_nif_loader.cpp +++ b/components/nifogre/ogre_nif_loader.cpp @@ -1277,18 +1277,7 @@ void NIFLoader::loadResource(Resource *resource) { allshapesmap[name] = shapes; } - if(baddin){ - /*if(addAnim){ - if(isBeast) - npcknaSkel = mSkel; - else - npcSkel = mSkel; - }*/ - for(int i = 0; i < addin.size(); i++){ - insertMeshInsideBase(addin[i]); - } - addin.clear(); - } + if(flip){ mesh->_setBounds(mBoundingBox, false); } @@ -1330,20 +1319,22 @@ This function also creates new position and normal buffers for submeshes. This function points to existing texture and IndexData buffers */ -std::vector& NIFLoader::getAnim(std::string lowername){ +std::vector* NIFLoader::getAnim(std::string lowername){ std::map,ciLessBoost>::iterator iter = allanimmap.find(lowername); + std::vector* pass = 0; if(iter != allanimmap.end()) - mAnim = iter->second; - return mAnim; + pass = &(iter->second); + return pass; } -std::vector& NIFLoader::getShapes(std::string lowername){ +std::vector* NIFLoader::getShapes(std::string lowername){ std::map,ciLessBoost>::iterator iter = allshapesmap.find(lowername); + std::vector* pass = 0; if(iter != allshapesmap.end()) - mS = iter->second; - return mS; + pass = &(iter->second); + return pass; } float NIFLoader::getTime(std::string filename, std::string text){ @@ -1359,12 +1350,14 @@ float NIFLoader::getTime(std::string filename, std::string text){ return -10000000.0; } +/* void NIFLoader::insertMeshInsideBase(Ogre::Mesh* input) { /*if(addin) { std::cout << "InsideBase:" << addin->getName() << "\n"; }*/ +/* if(input) { std::vector shapes = NIFLoader::getSingletonPtr()->getShapes(input->getName()); @@ -1478,7 +1471,7 @@ void NIFLoader::insertMeshInsideBase(Ogre::Mesh* input) for (int j = 0; j < weights.size(); j++){ std::cout << "Vertex: " << weights[j].vertex << " Weight: " << weights[j].weight << "\n"; }*/ - } + /*} } if(position){ @@ -1578,7 +1571,7 @@ void NIFLoader::insertMeshInsideBase(Ogre::Mesh* input) assign.vertexIndex = 0; assign.weight = 1.0; subNew->addBoneAssignment(assign);*/ - + /* Ogre::SubMesh::BoneAssignmentIterator boneiter = sub->getBoneAssignmentIterator(); while(boneiter.hasMoreElements()) { @@ -1592,7 +1585,7 @@ void NIFLoader::insertMeshInsideBase(Ogre::Mesh* input) } } -} +}*/ /* More code currently not in use, from the old D source. This was diff --git a/components/nifogre/ogre_nif_loader.hpp b/components/nifogre/ogre_nif_loader.hpp index ec0fb412a..7dab61a54 100644 --- a/components/nifogre/ogre_nif_loader.hpp +++ b/components/nifogre/ogre_nif_loader.hpp @@ -108,9 +108,9 @@ class NIFLoader : Ogre::ManualResourceLoader static Ogre::MeshPtr load(const std::string &name, const std::string &group="General"); - void insertMeshInsideBase(Ogre::Mesh* mesh); - std::vector& getAnim(std::string name); - std::vector& getShapes(std::string name); + //void insertMeshInsideBase(Ogre::Mesh* mesh); + std::vector* getAnim(std::string name); + std::vector* getShapes(std::string name); float getTime(std::string filename, std::string text); void addInMesh(Ogre::Mesh* input); From d51dfebde1c24805bdf69d76161baff2c279abfa Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Thu, 15 Dec 2011 00:33:10 -0500 Subject: [PATCH 067/104] NPCs fully rendered --- apps/openmw/mwrender/actors.cpp | 1 + apps/openmw/mwrender/actors.hpp | 2 +- apps/openmw/mwrender/animation.cpp | 296 +++++++++++++++++++++ apps/openmw/mwrender/animation.hpp | 3 + apps/openmw/mwrender/creatureanimation.cpp | 15 ++ apps/openmw/mwrender/npcanimation.cpp | 30 ++- components/nifogre/ogre_nif_loader.cpp | 3 + 7 files changed, 344 insertions(+), 6 deletions(-) diff --git a/apps/openmw/mwrender/actors.cpp b/apps/openmw/mwrender/actors.cpp index d3493bf4a..7454261f0 100644 --- a/apps/openmw/mwrender/actors.cpp +++ b/apps/openmw/mwrender/actors.cpp @@ -59,6 +59,7 @@ void Actors::insertBegin (const MWWorld::Ptr& ptr, bool enabled, bool static_){ void Actors::insertCreature (const MWWorld::Ptr& ptr){ insertBegin(ptr, true, true); CreatureAnimation* anim = new MWRender::CreatureAnimation(ptr, mEnvironment, mRend); + //mAllActors.insert(std::pair(ptr,anim)); mAllActors.push_back(anim); //mAllActors.push_back(&anim); } diff --git a/apps/openmw/mwrender/actors.hpp b/apps/openmw/mwrender/actors.hpp index afd6e9ae6..011180f19 100644 --- a/apps/openmw/mwrender/actors.hpp +++ b/apps/openmw/mwrender/actors.hpp @@ -23,7 +23,7 @@ namespace MWRender{ std::map mCellSceneNodes; Ogre::SceneNode* mMwRoot; MWWorld::Environment& mEnvironment; - std::list mAllActors; + std::list mAllActors; diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index 067fb8f2a..857798e8c 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -4,4 +4,300 @@ namespace MWRender{ Animation::~Animation(){ base = 0; } + void Animation::handleShapes(std::vector* allshapes, Ogre::Entity* creaturemodel, Ogre::SkeletonInstance *skel){ + shapeNumber = 0; + std::vector::iterator allshapesiter; + for(allshapesiter = allshapes->begin(); allshapesiter != allshapes->end(); allshapesiter++) + { + + Nif::NiTriShapeCopy copy = *allshapesiter; + std::vector allvertices = copy.vertices; + std::vector allnormals = copy.normals; + + + + std::map vertices; + std::map normals; + std::vector boneinfovector = copy.boneinfo; + + //std::cout << "Name " << copy.sname << "\n"; + Ogre::HardwareVertexBufferSharedPtr vbuf = creaturemodel->getMesh()->getSubMesh(copy.sname)->vertexData->vertexBufferBinding->getBuffer(0); + Ogre::Real* pReal = static_cast(vbuf->lock(Ogre::HardwareBuffer::HBL_NORMAL)); + Ogre::HardwareVertexBufferSharedPtr vbufNormal = creaturemodel->getMesh()->getSubMesh(copy.sname)->vertexData->vertexBufferBinding->getBuffer(1); + Ogre::Real* pRealNormal = static_cast(vbufNormal->lock(Ogre::HardwareBuffer::HBL_NORMAL)); + + std::vector initialVertices = copy.morph.getInitialVertices(); + //Each shape has multiple indices + if(initialVertices.size() ) + { + + if(copy.vertices.size() == initialVertices.size()) + { + //Create if it doesn't already exist + if(shapeIndexI.size() == shapeNumber) + { + std::vector vec; + shapeIndexI.push_back(vec); + } + if(time >= copy.morph.getStartTime() && time <= copy.morph.getStopTime()){ + float x; + for (int i = 0; i < copy.morph.getAdditionalVertices().size(); i++){ + int j = 0; + if(shapeIndexI[shapeNumber].size() <= i) + shapeIndexI[shapeNumber].push_back(0); + + + if(timeIndex(time,copy.morph.getRelevantTimes()[i],(shapeIndexI[shapeNumber])[i], j, x)){ + int indexI = (shapeIndexI[shapeNumber])[i]; + std::vector relevantData = (copy.morph.getRelevantData()[i]); + float v1 = relevantData[indexI].x; + float v2 = relevantData[j].x; + float t = v1 + (v2 - v1) * x; + if ( t < 0 ) t = 0; + if ( t > 1 ) t = 1; + if( t != 0 && initialVertices.size() == copy.morph.getAdditionalVertices()[i].size()) + { + for (int v = 0; v < initialVertices.size(); v++){ + initialVertices[v] += ((copy.morph.getAdditionalVertices()[i])[v]) * t; + } + } + + } + + + + } + //After everything, write everything out + + /* + for(int i = 0; i < initialVertices.size(); i++){ + Ogre::Vector3 current = initialVertices[i]; + Ogre::Real* addr = pReal + i * 3; + *addr = current.x; + *(addr+1) = current.y; + *(addr + 2) = current.z; + + }*/ + allvertices = initialVertices; + } + shapeNumber++; + } + } + + + if(boneinfovector.size() > 0){ + + + for (int i = 0; i < boneinfovector.size(); i++) + { + Nif::NiSkinData::BoneInfoCopy boneinfo = boneinfovector[i]; + if(skel->hasBone(boneinfo.bonename)){ + Ogre::Bone *bonePtr = skel->getBone(boneinfo.bonename); + Ogre::Vector3 vecPos = bonePtr->_getDerivedPosition() + bonePtr->_getDerivedOrientation() * boneinfo.trafo.trans; + Ogre::Quaternion vecRot = bonePtr->_getDerivedOrientation() * boneinfo.trafo.rotation; + //std::cout << "Bone" << bonePtr->getName() << "\n"; + for (unsigned int j=0; j < boneinfo.weights.size(); j++) + { + unsigned int verIndex = boneinfo.weights[j].vertex; + if(vertices.find(verIndex) == vertices.end()) + { + Ogre::Vector3 absVertPos = vecPos + vecRot * allvertices[verIndex]; + absVertPos = absVertPos * boneinfo.weights[j].weight; + vertices[verIndex] = true; + Ogre::Real* addr = (pReal + 3 * verIndex); + *addr = absVertPos.x; + *(addr+1) = absVertPos.y; + *(addr+2) = absVertPos.z; + + //std::cout << "Vertex" << vertices[verIndex] << "\n"; + } + else + { + + Ogre::Vector3 absVertPos = vecPos + vecRot * allvertices[verIndex]; + absVertPos = absVertPos * boneinfo.weights[j].weight; + Ogre::Vector3 old = Ogre::Vector3(pReal + 3 * verIndex); + absVertPos = absVertPos + old; + Ogre::Real* addr = (pReal + 3 * verIndex); + *addr = absVertPos.x; + *(addr+1) = absVertPos.y; + *(addr+2) = absVertPos.z; + //std::cout << "Vertex" << verIndex << "Weight: " << boneinfo.weights[i].weight << "was seen twice\n"; + + } + + if(normals.find(verIndex) == normals.end()) + { + Ogre::Vector3 absNormalsPos = vecRot * allnormals[verIndex]; + absNormalsPos = absNormalsPos * boneinfo.weights[j].weight; + normals[verIndex] = true; + Ogre::Real* addr = (pRealNormal + 3 * verIndex); + *addr = absNormalsPos.x; + *(addr+1) = absNormalsPos.y; + *(addr+2) = absNormalsPos.z; + } + else + { + Ogre::Vector3 absNormalsPos = vecRot * allnormals[verIndex]; + absNormalsPos = absNormalsPos * boneinfo.weights[j].weight; + Ogre::Vector3 old = Ogre::Vector3(pRealNormal + 3 * verIndex); + absNormalsPos = absNormalsPos + old; + + Ogre::Real* addr = (pRealNormal + 3 * verIndex); + *addr = absNormalsPos.x; + *(addr+1) = absNormalsPos.y; + *(addr+2) = absNormalsPos.z; + + } + + } + } + + + } + + + } + else + { + //Ogre::Bone *bonePtr = creaturemodel->getSkeleton()->getBone(copy.bonename); + Ogre::Quaternion shaperot = copy.trafo.rotation; + Ogre::Vector3 shapetrans = copy.trafo.trans; + float shapescale = copy.trafo.scale; + std::vector boneSequence = copy.boneSequence; + std::vector::iterator boneSequenceIter = boneSequence.begin(); + Ogre::Vector3 transmult; + Ogre::Quaternion rotmult; + float scale; + if(creaturemodel->getSkeleton()->hasBone(*boneSequenceIter)){ + Ogre::Bone *bonePtr = creaturemodel->getSkeleton()->getBone(*boneSequenceIter); + + + + + transmult = bonePtr->getPosition(); + rotmult = bonePtr->getOrientation(); + scale = bonePtr->getScale().x; + boneSequenceIter++; + for(; boneSequenceIter != boneSequence.end(); boneSequenceIter++) + { + if(creaturemodel->getSkeleton()->hasBone(*boneSequenceIter)){ + Ogre::Bone *bonePtr = creaturemodel->getSkeleton()->getBone(*boneSequenceIter); + // Computes C = B + AxC*scale + transmult = transmult + rotmult * bonePtr->getPosition(); + rotmult = rotmult * bonePtr->getOrientation(); + scale = scale * bonePtr->getScale().x; + } + //std::cout << "Bone:" << *boneSequenceIter << " "; + } + transmult = transmult + rotmult * shapetrans; + rotmult = rotmult * shaperot; + scale = shapescale * scale; + + //std::cout << "Position: " << transmult << "Rotation: " << rotmult << "\n"; + } + else + { + transmult = shapetrans; + rotmult = shaperot; + scale = shapescale; + } + + + + + // Computes C = B + AxC*scale + // final_vector = old_vector + old_rotation*new_vector*old_scale/ + + for(int i = 0; i < allvertices.size(); i++){ + Ogre::Vector3 current = transmult + rotmult * allvertices[i]; + Ogre::Real* addr = pReal + i * 3; + *addr = current.x; + *(addr+1) = current.y; + *(addr + 2) = current.z; + + } + for(int i = 0; i < allnormals.size(); i++){ + Ogre::Vector3 current =rotmult * allnormals[i]; + Ogre::Real* addr = pRealNormal + i * 3; + *addr = current.x; + *(addr+1) = current.y; + *(addr + 2) = current.z; + + } + + } + + } + + + for(allshapesiter = allshapes->begin(); allshapesiter != allshapes->end(); allshapesiter++) + { + Nif::NiTriShapeCopy copy = *allshapesiter; + Ogre::HardwareVertexBufferSharedPtr vbuf = creaturemodel->getMesh()->getSubMesh(copy.sname)->vertexData->vertexBufferBinding->getBuffer(0); + + Ogre::HardwareVertexBufferSharedPtr vbufNormal = creaturemodel->getMesh()->getSubMesh(copy.sname)->vertexData->vertexBufferBinding->getBuffer(1); + vbuf->unlock(); + vbufNormal->unlock(); + } + + + + } + bool Animation::timeIndex( float time, std::vector times, int & i, int & j, float & x ){ + int count; + if ( (count = times.size()) > 0 ) + { + if ( time <= times[0] ) + { + i = j = 0; + x = 0.0; + return true; + } + if ( time >= times[count - 1] ) + { + i = j = count - 1; + x = 0.0; + return true; + } + + if ( i < 0 || i >= count ) + i = 0; + + float tI = times[i]; + if ( time > tI ) + { + j = i + 1; + float tJ; + while ( time >= ( tJ = times[j]) ) + { + i = j++; + tI = tJ; + } + x = ( time - tI ) / ( tJ - tI ); + return true; + } + else if ( time < tI ) + { + j = i - 1; + float tJ; + while ( time <= ( tJ = times[j] ) ) + { + i = j--; + tI = tJ; + } + x = ( time - tI ) / ( tJ - tI ); + return true; + } + else + { + j = i; + x = 0.0; + return true; + } + } + else + return false; + +} } \ No newline at end of file diff --git a/apps/openmw/mwrender/animation.hpp b/apps/openmw/mwrender/animation.hpp index 111e2d0c7..31910b814 100644 --- a/apps/openmw/mwrender/animation.hpp +++ b/apps/openmw/mwrender/animation.hpp @@ -6,6 +6,7 @@ #include "../mwworld/ptr.hpp" #include "../mwworld/actiontalk.hpp" #include "../mwworld/environment.hpp" +#include namespace MWRender{ @@ -34,8 +35,10 @@ class Animation{ std::vector* transformations; std::map textmappings; Ogre::Entity* base; + void handleShapes(std::vector* allshapes, Ogre::Entity* creaturemodel, Ogre::SkeletonInstance *skel); public: Animation(MWWorld::Environment& _env, OEngine::Render::OgreRenderer& _rend): mRend(_rend), mEnvironment(_env){}; + bool timeIndex( float time, std::vector times, int & i, int & j, float & x ); ~Animation(); }; diff --git a/apps/openmw/mwrender/creatureanimation.cpp b/apps/openmw/mwrender/creatureanimation.cpp index 66bc4d4d9..fac54db64 100644 --- a/apps/openmw/mwrender/creatureanimation.cpp +++ b/apps/openmw/mwrender/creatureanimation.cpp @@ -21,6 +21,21 @@ CreatureAnimation::CreatureAnimation(const MWWorld::Ptr& ptr, MWWorld::Environme NifOgre::NIFLoader::load(mesh); base = mRend.getScene()->createEntity(mesh); + + if(transformations = (NIFLoader::getSingletonPtr())->getAnim(mesh)){ + + for(int init = 0; init < transformations->size(); init++){ + rindexI.push_back(0); + //a.rindexJ.push_back(0); + tindexI.push_back(0); + //a.tindexJ.push_back(0); + } + loop = false; + skel = base->getSkeleton(); + stopTime = transformations->begin()->getStopTime(); + //a.startTime = NIFLoader::getSingletonPtr()->getTime(item.smodel, "IdleSneak: Start"); + startTime = transformations->end()->getStartTime(); + } insert->attachObject(base); } } diff --git a/apps/openmw/mwrender/npcanimation.cpp b/apps/openmw/mwrender/npcanimation.cpp index bd60a548e..17cb639ce 100644 --- a/apps/openmw/mwrender/npcanimation.cpp +++ b/apps/openmw/mwrender/npcanimation.cpp @@ -56,14 +56,21 @@ NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, MWWorld::Environment& _env,O base = mRend.getScene()->createEntity(smodel); - /* - transformations = &(NIFLoader::getSingletonPtr())->getAnim(smodel); + + if(transformations = (NIFLoader::getSingletonPtr())->getAnim(smodel)){ + for(int init = 0; init < transformations->size(); init++){ rindexI.push_back(0); //a.rindexJ.push_back(0); tindexI.push_back(0); //a.tindexJ.push_back(0); - }*/ + } + loop = false; + skel = base->getSkeleton(); + stopTime = transformations->begin()->getStopTime(); + //a.startTime = NIFLoader::getSingletonPtr()->getTime(item.smodel, "IdleSneak: Start"); + startTime = transformations->end()->getStartTime(); + } insert->attachObject(base); std::string headModel = "meshes\\" + @@ -173,6 +180,17 @@ NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, MWWorld::Environment& _env,O insertFreePart("meshes\\" + handr->model + "|?", insert); } + if (handl){ + insertFreePart("meshes\\" + handl->model + "|>", insert); + + } + if(tail){ + insertFreePart("meshes\\" + tail->model + "|*", insert); + } + if(feet){ + insertFreePart("meshes\\" + feet->model + "|<", insert); + insertFreePart("meshes\\" + feet->model + "|:", insert); + } } Ogre::Entity* NpcAnimation::insertBoundedPart(const std::string &mesh, std::string bonename){ @@ -187,9 +205,11 @@ void NpcAnimation::insertFreePart(const std::string &mesh, Ogre::SceneNode* inse Entity* ent = mRend.getScene()->createEntity(mesh); insert->attachObject(ent); entityparts.push_back(ent); - //std::vector shapes = (NIFLoader::getSingletonPtr())->getShapes(mesh); std::vector* shapes = ((NIFLoader::getSingletonPtr())->getShapes(mesh)); - shapeparts.push_back(shapes); + if(shapes){ + shapeparts.push_back(shapes); + handleShapes(shapes, ent, skel); + } } diff --git a/components/nifogre/ogre_nif_loader.cpp b/components/nifogre/ogre_nif_loader.cpp index 26b1111a1..21dea31b1 100644 --- a/components/nifogre/ogre_nif_loader.cpp +++ b/components/nifogre/ogre_nif_loader.cpp @@ -1121,6 +1121,8 @@ void NIFLoader::handleNode(Nif::Node *node, int flags, void NIFLoader::loadResource(Resource *resource) { + allanim.clear(); + shapes.clear(); mBoundingBox.setNull(); mesh = 0; mSkel.setNull(); @@ -1276,6 +1278,7 @@ void NIFLoader::loadResource(Resource *resource) if(!mSkel.isNull() && shapes.size() > 0 && addAnim) { allshapesmap[name] = shapes; + } if(flip){ From 93a4060346aee2287fdebf544760cdf16f6e95df Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Thu, 15 Dec 2011 00:41:44 -0500 Subject: [PATCH 068/104] Switching handleShapes to use sets instead of maps --- apps/openmw/mwrender/animation.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index 857798e8c..78e9b76cd 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -16,8 +16,8 @@ namespace MWRender{ - std::map vertices; - std::map normals; + std::set vertices; + std::set normals; std::vector boneinfovector = copy.boneinfo; //std::cout << "Name " << copy.sname << "\n"; @@ -103,7 +103,7 @@ namespace MWRender{ { Ogre::Vector3 absVertPos = vecPos + vecRot * allvertices[verIndex]; absVertPos = absVertPos * boneinfo.weights[j].weight; - vertices[verIndex] = true; + vertices.insert(verIndex); Ogre::Real* addr = (pReal + 3 * verIndex); *addr = absVertPos.x; *(addr+1) = absVertPos.y; @@ -130,7 +130,7 @@ namespace MWRender{ { Ogre::Vector3 absNormalsPos = vecRot * allnormals[verIndex]; absNormalsPos = absNormalsPos * boneinfo.weights[j].weight; - normals[verIndex] = true; + normals.insert(verIndex); Ogre::Real* addr = (pRealNormal + 3 * verIndex); *addr = absNormalsPos.x; *(addr+1) = absNormalsPos.y; From 6d10c76b06353db6fee8c8e3f08bba9fac042ee5 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Sat, 17 Dec 2011 01:29:08 -0500 Subject: [PATCH 069/104] Unique Identifiers for Creatures and NPC Free Parts --- apps/openmw/mwrender/actors.cpp | 2 +- apps/openmw/mwrender/animation.cpp | 21 +++++++++++++++++++ apps/openmw/mwrender/animation.hpp | 11 ++++++++-- apps/openmw/mwrender/creatureanimation.cpp | 9 ++++---- apps/openmw/mwrender/npcanimation.cpp | 24 +++++++++++++--------- apps/openmw/mwrender/npcanimation.hpp | 2 +- components/nifogre/ogre_nif_loader.cpp | 2 +- components/nifogre/ogre_nif_loader.hpp | 3 +-- 8 files changed, 53 insertions(+), 21 deletions(-) diff --git a/apps/openmw/mwrender/actors.cpp b/apps/openmw/mwrender/actors.cpp index 7454261f0..21403d3b2 100644 --- a/apps/openmw/mwrender/actors.cpp +++ b/apps/openmw/mwrender/actors.cpp @@ -1,6 +1,6 @@ #include "actors.hpp" #include -#include + diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index 78e9b76cd..4d725b4de 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -1,9 +1,30 @@ #include "animation.hpp" + namespace MWRender{ + std::map Animation::mUniqueIDs; Animation::~Animation(){ base = 0; } + std::string Animation::getUniqueID(std::string mesh){ + int counter; + if(mUniqueIDs.find(mesh) == mUniqueIDs.end()){ + counter = mUniqueIDs[mesh] = 0; + } + else + counter = mUniqueIDs[mesh]++; + + std::stringstream out; + if(counter > 99 && counter < 1000) + out << "0"; + else if(counter > 9) + out << "00"; + else + out << "000"; + out << counter; + return out.str(); +} + void Animation::handleShapes(std::vector* allshapes, Ogre::Entity* creaturemodel, Ogre::SkeletonInstance *skel){ shapeNumber = 0; std::vector::iterator allshapesiter; diff --git a/apps/openmw/mwrender/animation.hpp b/apps/openmw/mwrender/animation.hpp index 31910b814..19635270c 100644 --- a/apps/openmw/mwrender/animation.hpp +++ b/apps/openmw/mwrender/animation.hpp @@ -7,13 +7,17 @@ #include "../mwworld/actiontalk.hpp" #include "../mwworld/environment.hpp" #include +#include namespace MWRender{ class Animation{ + protected: + OEngine::Render::OgreRenderer &mRend; - MWWorld::Environment& mEnvironment; + MWWorld::Environment& mEnvironment; + static std::map mUniqueIDs; float time; float startTime; @@ -36,9 +40,12 @@ class Animation{ std::map textmappings; Ogre::Entity* base; void handleShapes(std::vector* allshapes, Ogre::Entity* creaturemodel, Ogre::SkeletonInstance *skel); + bool timeIndex( float time, std::vector times, int & i, int & j, float & x ); + std::string getUniqueID(std::string mesh); public: Animation(MWWorld::Environment& _env, OEngine::Render::OgreRenderer& _rend): mRend(_rend), mEnvironment(_env){}; - bool timeIndex( float time, std::vector times, int & i, int & j, float & x ); + + ~Animation(); }; diff --git a/apps/openmw/mwrender/creatureanimation.cpp b/apps/openmw/mwrender/creatureanimation.cpp index fac54db64..b2be18993 100644 --- a/apps/openmw/mwrender/creatureanimation.cpp +++ b/apps/openmw/mwrender/creatureanimation.cpp @@ -18,11 +18,12 @@ CreatureAnimation::CreatureAnimation(const MWWorld::Ptr& ptr, MWWorld::Environme assert (ref->base != NULL); if(!ref->base->model.empty()){ const std::string &mesh = "meshes\\" + ref->base->model; + std::string meshNumbered = mesh + getUniqueID(mesh) + ">|"; + NifOgre::NIFLoader::load(meshNumbered); + base = mRend.getScene()->createEntity(meshNumbered); + std::string meshZero = mesh + "0000>|"; - NifOgre::NIFLoader::load(mesh); - base = mRend.getScene()->createEntity(mesh); - - if(transformations = (NIFLoader::getSingletonPtr())->getAnim(mesh)){ + if(transformations = (NIFLoader::getSingletonPtr())->getAnim(meshZero)){ for(int init = 0; init < transformations->size(); init++){ rindexI.push_back(0); diff --git a/apps/openmw/mwrender/npcanimation.cpp b/apps/openmw/mwrender/npcanimation.cpp index 17cb639ce..4a8bac655 100644 --- a/apps/openmw/mwrender/npcanimation.cpp +++ b/apps/openmw/mwrender/npcanimation.cpp @@ -173,23 +173,25 @@ NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, MWWorld::Environment& _env,O insertBoundedPart("meshes\\" + hair->model, "Head"); if (chest){ - insertFreePart("meshes\\" + chest->model + "|\"", insert); + insertFreePart("meshes\\" + chest->model, ">\"", insert); + } if (handr){ - insertFreePart("meshes\\" + handr->model + "|?", insert); + insertFreePart("meshes\\" + handr->model , ">?", insert); } if (handl){ - insertFreePart("meshes\\" + handl->model + "|>", insert); + insertFreePart("meshes\\" + handl->model, ">>", insert); } if(tail){ - insertFreePart("meshes\\" + tail->model + "|*", insert); + insertFreePart("meshes\\" + tail->model, ">*", insert); } if(feet){ - insertFreePart("meshes\\" + feet->model + "|<", insert); - insertFreePart("meshes\\" + feet->model + "|:", insert); + std::string num = getUniqueID(feet->model); + insertFreePart("meshes\\" + feet->model,"><", insert); + insertFreePart("meshes\\" + feet->model,">:", insert); } } @@ -200,12 +202,14 @@ Ogre::Entity* NpcAnimation::insertBoundedPart(const std::string &mesh, std::stri base->attachObjectToBone(bonename, ent); return ent; } -void NpcAnimation::insertFreePart(const std::string &mesh, Ogre::SceneNode* insert){ - NIFLoader::load(mesh); - Entity* ent = mRend.getScene()->createEntity(mesh); +void NpcAnimation::insertFreePart(const std::string &mesh, const std::string suffix, Ogre::SceneNode* insert){ + std::string meshNumbered = mesh + getUniqueID(mesh + suffix) + suffix; + NIFLoader::load(meshNumbered); + + Entity* ent = mRend.getScene()->createEntity(meshNumbered); insert->attachObject(ent); entityparts.push_back(ent); - std::vector* shapes = ((NIFLoader::getSingletonPtr())->getShapes(mesh)); + std::vector* shapes = ((NIFLoader::getSingletonPtr())->getShapes(mesh + "0000" + suffix)); if(shapes){ shapeparts.push_back(shapes); handleShapes(shapes, ent, skel); diff --git a/apps/openmw/mwrender/npcanimation.hpp b/apps/openmw/mwrender/npcanimation.hpp index 96a2eeb31..9ecabd254 100644 --- a/apps/openmw/mwrender/npcanimation.hpp +++ b/apps/openmw/mwrender/npcanimation.hpp @@ -22,7 +22,7 @@ class NpcAnimation: public Animation{ NpcAnimation(const MWWorld::Ptr& ptr, MWWorld::Environment& _env, OEngine::Render::OgreRenderer& _rend); ~NpcAnimation(); Ogre::Entity* insertBoundedPart(const std::string &mesh, std::string bonename); - void insertFreePart(const std::string &mesh, Ogre::SceneNode* insert); + void insertFreePart(const std::string &mesh, const std::string suffix, Ogre::SceneNode* insert); }; } #endif \ No newline at end of file diff --git a/components/nifogre/ogre_nif_loader.cpp b/components/nifogre/ogre_nif_loader.cpp index 21dea31b1..cbb137511 100644 --- a/components/nifogre/ogre_nif_loader.cpp +++ b/components/nifogre/ogre_nif_loader.cpp @@ -1150,7 +1150,7 @@ void NIFLoader::loadResource(Resource *resource) else if(suffix == '>') { baddin = true; - bNiTri = false; + bNiTri = true; std::string sub = name.substr(name.length() - 6, 4); if(sub.compare("0000") != 0) diff --git a/components/nifogre/ogre_nif_loader.hpp b/components/nifogre/ogre_nif_loader.hpp index 7dab61a54..c97968510 100644 --- a/components/nifogre/ogre_nif_loader.hpp +++ b/components/nifogre/ogre_nif_loader.hpp @@ -44,8 +44,7 @@ #include #include // For warning messages -#include - +#include 5 // float infinity #include using namespace boost::algorithm; From 7cf3fc89910576f6befb3ea12f3dba2c02208399 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Sun, 18 Dec 2011 03:18:26 -0500 Subject: [PATCH 070/104] handleAnimationTransforms --- apps/openmw/mwrender/animation.cpp | 69 +++++++++++++++++++++++++++++- apps/openmw/mwrender/animation.hpp | 1 + 2 files changed, 69 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index 4d725b4de..1c8ceffd7 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -4,7 +4,6 @@ namespace MWRender{ std::map Animation::mUniqueIDs; Animation::~Animation(){ - base = 0; } std::string Animation::getUniqueID(std::string mesh){ int counter; @@ -320,5 +319,73 @@ namespace MWRender{ else return false; +} + + void Animation::handleAnimationTransforms(){ + Ogre::Bone* b = skel->getRootBone(); + b->setOrientation(.3,.3,.3,.3); //This is a trick + skel->getManualBonesDirty(); + skel->_updateTransforms(); + skel->_notifyManualBonesDirty(); + + std::vector::iterator iter; + int slot = 0; + if(transformations){ + for(iter = transformations->begin(); iter != transformations->end(); iter++){ + if(time < iter->getStartTime() || time < startTime || time > iter->getStopTime()) + { + continue; + } + + if(skel->hasBone(iter->getBonename())){ + Ogre::Bone* bone = skel->getBone(iter->getBonename()); + + float x; + float x2; + + std::vector quats = iter->getQuat(); + + std::vector ttime = iter->gettTime(); + std::vector::iterator ttimeiter = ttime.begin(); + + std::vector rtime = iter->getrTime(); + int rindexJ = 0; + timeIndex(time, rtime, rindexI[slot], rindexJ, x2); + int tindexJ = 0; + + + std::vector translist1 = iter->getTranslist1(); + + timeIndex(time, ttime, tindexI[slot], tindexJ, x); + + //std::cout << "X: " << x << " X2: " << x2 << "\n"; + + + if(translist1.size() > 0){ + Ogre::Vector3 v1 = translist1[tindexI[slot]]; + Ogre::Vector3 v2 = translist1[tindexJ]; + Ogre::Vector3 t = v1 + (v2 - v1) * x; + bone->setPosition(t); + } + + if(quats.size() > 0){ + Ogre::Quaternion r = Ogre::Quaternion::Slerp(x2, quats[rindexI[slot]], quats[rindexJ], true); + bone->setOrientation(r); + } + + + skel->getManualBonesDirty(); + skel->_updateTransforms(); + skel->_notifyManualBonesDirty(); + + Ogre::Entity* ent = base; + + ent->getAllAnimationStates()->_notifyDirty(); + ent->_updateAnimation(); + ent->_notifyMoved(); + } + slot++; + } +} } } \ No newline at end of file diff --git a/apps/openmw/mwrender/animation.hpp b/apps/openmw/mwrender/animation.hpp index 19635270c..acead8c07 100644 --- a/apps/openmw/mwrender/animation.hpp +++ b/apps/openmw/mwrender/animation.hpp @@ -40,6 +40,7 @@ class Animation{ std::map textmappings; Ogre::Entity* base; void handleShapes(std::vector* allshapes, Ogre::Entity* creaturemodel, Ogre::SkeletonInstance *skel); + void handleAnimationTransforms(); bool timeIndex( float time, std::vector times, int & i, int & j, float & x ); std::string getUniqueID(std::string mesh); public: From 1b835d6702bb6e302bf4ca50262acc7ca1e5ec4e Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Sat, 24 Dec 2011 21:53:12 -0500 Subject: [PATCH 071/104] Cell changing fixes --- apps/openmw/mwclass/creature.cpp | 2 +- apps/openmw/mwclass/npc.cpp | 4 ++-- apps/openmw/mwrender/actors.cpp | 24 ++++++++++++++++++++---- apps/openmw/mwrender/actors.hpp | 2 +- apps/openmw/mwworld/scene.cpp | 10 +++++++--- 5 files changed, 31 insertions(+), 11 deletions(-) diff --git a/apps/openmw/mwclass/creature.cpp b/apps/openmw/mwclass/creature.cpp index e2f9ca6d8..5aa203a49 100644 --- a/apps/openmw/mwclass/creature.cpp +++ b/apps/openmw/mwclass/creature.cpp @@ -47,7 +47,7 @@ namespace MWClass const std::string &model = ref->base->model; assert (ref->base != NULL); if(!model.empty()){ - // physics.insertActorPhysics(ptr, "meshes\\" + model); + physics.insertActorPhysics(ptr, "meshes\\" + model); } } diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index 16b3cff75..cedca5bca 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -38,7 +38,7 @@ namespace MWClass void Npc::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const { - /* + ESMS::LiveCellRef *ref = ptr.get(); @@ -47,7 +47,7 @@ namespace MWClass assert (ref->base != NULL); if(!model.empty()){ physics.insertActorPhysics(ptr, "meshes\\" + model); - }*/ + } } diff --git a/apps/openmw/mwrender/actors.cpp b/apps/openmw/mwrender/actors.cpp index 21403d3b2..7c5aaeec2 100644 --- a/apps/openmw/mwrender/actors.cpp +++ b/apps/openmw/mwrender/actors.cpp @@ -12,9 +12,13 @@ void Actors::setMwRoot(Ogre::SceneNode* root){ mMwRoot = root; } void Actors::insertNPC(const MWWorld::Ptr& ptr){ + insertBegin(ptr, true, true); - NpcAnimation* anim = new MWRender::NpcAnimation(ptr, mEnvironment, mRend); - mAllActors.push_back(anim); + NpcAnimation* anim = new MWRender::NpcAnimation(ptr, mEnvironment, mRend); + + // + + mAllActors[ptr] = anim; } @@ -57,17 +61,20 @@ void Actors::insertBegin (const MWWorld::Ptr& ptr, bool enabled, bool static_){ } void Actors::insertCreature (const MWWorld::Ptr& ptr){ + insertBegin(ptr, true, true); CreatureAnimation* anim = new MWRender::CreatureAnimation(ptr, mEnvironment, mRend); //mAllActors.insert(std::pair(ptr,anim)); - mAllActors.push_back(anim); - //mAllActors.push_back(&anim); + mAllActors[ptr] = anim; + //mAllActors.push_back(&anim);*/ } bool Actors::deleteObject (const MWWorld::Ptr& ptr) { + mAllActors.erase(ptr); if (Ogre::SceneNode *base = ptr.getRefData().getBaseNode()) { + Ogre::SceneNode *parent = base->getParentSceneNode(); for (std::map::const_iterator iter ( @@ -91,6 +98,15 @@ void Actors::removeCell(MWWorld::Ptr::CellStore* store){ { Ogre::SceneNode* base = mCellSceneNodes[store]; base->removeAndDestroyAllChildren(); + + + + + + + + + mCellSceneNodes.erase(store); mRend.getScene()->destroySceneNode(base); base = 0; diff --git a/apps/openmw/mwrender/actors.hpp b/apps/openmw/mwrender/actors.hpp index 011180f19..5a26ed9bb 100644 --- a/apps/openmw/mwrender/actors.hpp +++ b/apps/openmw/mwrender/actors.hpp @@ -23,7 +23,7 @@ namespace MWRender{ std::map mCellSceneNodes; Ogre::SceneNode* mMwRoot; MWWorld::Environment& mEnvironment; - std::list mAllActors; + std::map mAllActors; diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index 5f0632850..b2e4f3708 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -59,7 +59,9 @@ namespace MWWorld ListHandles functor; MWWorld::Ptr::CellStore* active = *iter; - mRendering.removeCell(active); + + + active->forEach(functor); @@ -73,11 +75,13 @@ namespace MWWorld mPhysics->removeObject (node->getName()); } } - //mPhysics->removeObject("Unnamed_43"); + mRendering.removeCell(active); + //mPhysics->removeObject("Unnamed_43"); mWorld->getLocalScripts().clearCell (active); mEnvironment.mMechanicsManager->dropActors (active); mEnvironment.mSoundManager->stopSound (active); - mActiveCells.erase (iter); + mActiveCells.erase(active); + } void Scene::loadCell (Ptr::CellStore *cell) From 7eee54bcd79cfbbc9d4b2046aad318221df38f59 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Sun, 25 Dec 2011 01:52:57 -0500 Subject: [PATCH 072/104] More physics and managing of Animation objects --- apps/openmw/mwclass/npc.cpp | 13 ++++++++++--- apps/openmw/mwrender/actors.cpp | 15 ++++++--------- apps/openmw/mwworld/physicssystem.cpp | 2 +- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index cedca5bca..e09cd6051 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -45,9 +45,16 @@ namespace MWClass const std::string &model = ref->base->model; assert (ref->base != NULL); - if(!model.empty()){ - physics.insertActorPhysics(ptr, "meshes\\" + model); - } + std::string headID = ref->base->head; + std::string bodyRaceID = headID.substr(0, headID.find_last_of("head_") - 4); + bool beast = bodyRaceID == "b_n_khajiit_m_" || bodyRaceID == "b_n_khajiit_f_" || bodyRaceID == "b_n_argonian_m_" || bodyRaceID == "b_n_argonian_f_"; + + + std::string smodel = "meshes\\base_anim.nif"; + if(beast) + smodel = "meshes\\base_animkna.nif"; + physics.insertActorPhysics(ptr, smodel); + } diff --git a/apps/openmw/mwrender/actors.cpp b/apps/openmw/mwrender/actors.cpp index 7c5aaeec2..dc99d8809 100644 --- a/apps/openmw/mwrender/actors.cpp +++ b/apps/openmw/mwrender/actors.cpp @@ -98,18 +98,15 @@ void Actors::removeCell(MWWorld::Ptr::CellStore* store){ { Ogre::SceneNode* base = mCellSceneNodes[store]; base->removeAndDestroyAllChildren(); - - - - - - - - - mCellSceneNodes.erase(store); mRend.getScene()->destroySceneNode(base); base = 0; } + for(std::map::iterator iter = mAllActors.begin(); iter != mAllActors.end(); iter++) + { + if(iter->first.getCell() == store){ + mAllActors.erase(iter); + } + } } \ No newline at end of file diff --git a/apps/openmw/mwworld/physicssystem.cpp b/apps/openmw/mwworld/physicssystem.cpp index 8212dbeea..cfe5edab4 100644 --- a/apps/openmw/mwworld/physicssystem.cpp +++ b/apps/openmw/mwworld/physicssystem.cpp @@ -191,7 +191,7 @@ namespace MWWorld void PhysicsSystem::insertActorPhysics(const MWWorld::Ptr& ptr, const std::string model){ Ogre::SceneNode* node = ptr.getRefData().getBaseNode(); - std::cout << "Adding node with name" << node->getName(); + // std::cout << "Adding node with name" << node->getName(); addActor (node->getName(), model, node->getPosition()); } From 88c427543bf6712a053b9631f646277d0a04d65b Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Sun, 25 Dec 2011 22:37:26 -0500 Subject: [PATCH 073/104] Deleting animations; Empty Functions/Planning --- apps/openmw/mwrender/actors.cpp | 2 ++ apps/openmw/mwrender/animation.cpp | 5 +++++ apps/openmw/mwrender/animation.hpp | 6 +++++- apps/openmw/mwrender/creatureanimation.cpp | 14 +++++++++++++- apps/openmw/mwrender/creatureanimation.hpp | 5 ++++- apps/openmw/mwrender/npcanimation.cpp | 13 ++++++++++++- apps/openmw/mwrender/npcanimation.hpp | 2 ++ apps/openmw/mwrender/renderingmanager.cpp | 3 +++ apps/openmw/mwrender/renderingmanager.hpp | 2 ++ 9 files changed, 48 insertions(+), 4 deletions(-) diff --git a/apps/openmw/mwrender/actors.cpp b/apps/openmw/mwrender/actors.cpp index dc99d8809..38ed3a2b3 100644 --- a/apps/openmw/mwrender/actors.cpp +++ b/apps/openmw/mwrender/actors.cpp @@ -71,6 +71,7 @@ void Actors::insertCreature (const MWWorld::Ptr& ptr){ bool Actors::deleteObject (const MWWorld::Ptr& ptr) { + delete mAllActors[ptr]; mAllActors.erase(ptr); if (Ogre::SceneNode *base = ptr.getRefData().getBaseNode()) { @@ -105,6 +106,7 @@ void Actors::removeCell(MWWorld::Ptr::CellStore* store){ for(std::map::iterator iter = mAllActors.begin(); iter != mAllActors.end(); iter++) { if(iter->first.getCell() == store){ + delete iter->second; mAllActors.erase(iter); } } diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index 1c8ceffd7..3b5b58e7f 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -23,6 +23,11 @@ namespace MWRender{ out << counter; return out.str(); } + void Animation::startScript(std::string groupname, int mode, int loops){ + //If groupname is recognized set animate to true + //Set the start time and stop time + //How many times to loop + } void Animation::handleShapes(std::vector* allshapes, Ogre::Entity* creaturemodel, Ogre::SkeletonInstance *skel){ shapeNumber = 0; diff --git a/apps/openmw/mwrender/animation.hpp b/apps/openmw/mwrender/animation.hpp index acead8c07..57673061d 100644 --- a/apps/openmw/mwrender/animation.hpp +++ b/apps/openmw/mwrender/animation.hpp @@ -23,6 +23,7 @@ class Animation{ float startTime; float stopTime; bool loop; + bool animate; //Represents a rotation index for each bone std::vectorrindexI; //Represents a translation index for each bone @@ -43,8 +44,11 @@ class Animation{ void handleAnimationTransforms(); bool timeIndex( float time, std::vector times, int & i, int & j, float & x ); std::string getUniqueID(std::string mesh); + public: - Animation(MWWorld::Environment& _env, OEngine::Render::OgreRenderer& _rend): mRend(_rend), mEnvironment(_env){}; + Animation(MWWorld::Environment& _env, OEngine::Render::OgreRenderer& _rend): mRend(_rend), mEnvironment(_env), loop(false), animate(false){}; + virtual void runAnimation(float timepassed) = 0; + void startScript(std::string groupname, int mode, int loops); ~Animation(); diff --git a/apps/openmw/mwrender/creatureanimation.cpp b/apps/openmw/mwrender/creatureanimation.cpp index b2be18993..c9c4d7d16 100644 --- a/apps/openmw/mwrender/creatureanimation.cpp +++ b/apps/openmw/mwrender/creatureanimation.cpp @@ -35,9 +35,21 @@ CreatureAnimation::CreatureAnimation(const MWWorld::Ptr& ptr, MWWorld::Environme skel = base->getSkeleton(); stopTime = transformations->begin()->getStopTime(); //a.startTime = NIFLoader::getSingletonPtr()->getTime(item.smodel, "IdleSneak: Start"); - startTime = transformations->end()->getStartTime(); + startTime = transformations->begin()->getStartTime(); + shapes = (NIFLoader::getSingletonPtr())->getShapes(meshZero); } insert->attachObject(base); } } + +void CreatureAnimation::runAnimation(float timepassed){ + if(animate){ + //Add the amount of time passed to time + + //Handle the animation transforms dependent on time + + //Handle the shapes dependent on animation transforms + + } +} } \ No newline at end of file diff --git a/apps/openmw/mwrender/creatureanimation.hpp b/apps/openmw/mwrender/creatureanimation.hpp index 9bbd149ce..4c2b2ec77 100644 --- a/apps/openmw/mwrender/creatureanimation.hpp +++ b/apps/openmw/mwrender/creatureanimation.hpp @@ -14,10 +14,13 @@ namespace MWRender{ class CreatureAnimation: public Animation{ - std::vector shapes; //All the NiTriShapeData for this creature + std::vector* shapes; //All the NiTriShapeData for this creature public: ~CreatureAnimation(); CreatureAnimation(const MWWorld::Ptr& ptr, MWWorld::Environment& _env, OEngine::Render::OgreRenderer& _rend); + virtual void runAnimation(float timepassed); + + }; } #endif \ No newline at end of file diff --git a/apps/openmw/mwrender/npcanimation.cpp b/apps/openmw/mwrender/npcanimation.cpp index 4a8bac655..405a60c4e 100644 --- a/apps/openmw/mwrender/npcanimation.cpp +++ b/apps/openmw/mwrender/npcanimation.cpp @@ -9,6 +9,7 @@ NpcAnimation::~NpcAnimation(){ } + NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, MWWorld::Environment& _env,OEngine::Render::OgreRenderer& _rend): Animation(_env,_rend){ ESMS::LiveCellRef *ref = ptr.get(); @@ -69,7 +70,7 @@ NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, MWWorld::Environment& _env,O skel = base->getSkeleton(); stopTime = transformations->begin()->getStopTime(); //a.startTime = NIFLoader::getSingletonPtr()->getTime(item.smodel, "IdleSneak: Start"); - startTime = transformations->end()->getStartTime(); + startTime = transformations->begin()->getStartTime(); } insert->attachObject(base); @@ -217,4 +218,14 @@ void NpcAnimation::insertFreePart(const std::string &mesh, const std::string suf } + +void NpcAnimation::runAnimation(float timepassed){ + if(animate){ + //Add the amount of time passed to time + + //Handle the animation transforms dependent on time + + //Handle the shapes dependent on animation transforms + } +} } \ No newline at end of file diff --git a/apps/openmw/mwrender/npcanimation.hpp b/apps/openmw/mwrender/npcanimation.hpp index 9ecabd254..1ce949f3a 100644 --- a/apps/openmw/mwrender/npcanimation.hpp +++ b/apps/openmw/mwrender/npcanimation.hpp @@ -23,6 +23,8 @@ class NpcAnimation: public Animation{ ~NpcAnimation(); Ogre::Entity* insertBoundedPart(const std::string &mesh, std::string bonename); void insertFreePart(const std::string &mesh, const std::string suffix, Ogre::SceneNode* insert); + virtual void runAnimation(float timepassed); + }; } #endif \ No newline at end of file diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index 6f21db2b3..fd74c282f 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -240,5 +240,8 @@ void RenderingManager::skipAnimation (const MWWorld::Ptr& ptr) { std::cout<<"skip animation"< Date: Mon, 26 Dec 2011 19:23:46 -0500 Subject: [PATCH 074/104] Animation creatures --- apps/openmw/engine.cpp | 1 + apps/openmw/mwrender/actors.cpp | 16 +++++++- apps/openmw/mwrender/actors.hpp | 14 +++++++ apps/openmw/mwrender/animation.cpp | 21 ++++++---- apps/openmw/mwrender/creatureanimation.cpp | 13 +++++++ apps/openmw/mwrender/npcanimation.cpp | 45 +++++++++++++++++----- apps/openmw/mwrender/npcanimation.hpp | 2 +- apps/openmw/mwrender/renderingmanager.cpp | 4 +- apps/openmw/mwrender/renderingmanager.hpp | 2 +- apps/openmw/mwworld/scene.cpp | 4 +- apps/openmw/mwworld/scene.hpp | 1 + apps/openmw/mwworld/world.cpp | 3 +- 12 files changed, 102 insertions(+), 24 deletions(-) diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 3ab499396..5d235b5d1 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -135,6 +135,7 @@ bool OMW::Engine::frameRenderingQueued (const Ogre::FrameEvent& evt) mEnvironment.mWorld->advanceTime ( mEnvironment.mFrameDuration*mEnvironment.mWorld->getTimeScaleFactor()/3600); + if (changed) // keep change flag for another frame, if cell changed happend in local script mEnvironment.mWorld->markCellAsUnchanged(); diff --git a/apps/openmw/mwrender/actors.cpp b/apps/openmw/mwrender/actors.cpp index 38ed3a2b3..6f479d877 100644 --- a/apps/openmw/mwrender/actors.cpp +++ b/apps/openmw/mwrender/actors.cpp @@ -111,4 +111,18 @@ void Actors::removeCell(MWWorld::Ptr::CellStore* store){ } } -} \ No newline at end of file +} + +void Actors::playAnimationGroup (const MWWorld::Ptr& ptr, const std::string& groupName, int mode, int number){ + mAllActors.find(ptr)->second->startScript(groupName, mode, number); +} +void Actors::skipAnimation (const MWWorld::Ptr& ptr){ + +} +void Actors::addTime(){ + //std::cout << "Adding time in actors\n"; + for(std::map::iterator iter = mAllActors.begin(); iter != mAllActors.end(); iter++) + { + (iter->second)->runAnimation(mEnvironment.mFrameDuration); + } +} diff --git a/apps/openmw/mwrender/actors.hpp b/apps/openmw/mwrender/actors.hpp index 5a26ed9bb..be6486fd7 100644 --- a/apps/openmw/mwrender/actors.hpp +++ b/apps/openmw/mwrender/actors.hpp @@ -38,6 +38,20 @@ namespace MWRender{ ///< \return found? void removeCell(MWWorld::Ptr::CellStore* store); + + void playAnimationGroup (const MWWorld::Ptr& ptr, const std::string& groupName, int mode, + int number = 1); + ///< Run animation for a MW-reference. Calls to this function for references that are currently not + /// in the rendered scene should be ignored. + /// + /// \param mode: 0 normal, 1 immediate start, 2 immediate loop + /// \param number How offen the animation should be run + + void skipAnimation (const MWWorld::Ptr& ptr); + ///< Skip the animation for the given MW-reference for one frame. Calls to this function for + /// references that are currently not in the rendered scene should be ignored. + + void addTime(); }; } diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index 3b5b58e7f..9ec88501f 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -3,8 +3,10 @@ namespace MWRender{ std::map Animation::mUniqueIDs; + Animation::~Animation(){ } + std::string Animation::getUniqueID(std::string mesh){ int counter; if(mUniqueIDs.find(mesh) == mUniqueIDs.end()){ @@ -27,6 +29,11 @@ namespace MWRender{ //If groupname is recognized set animate to true //Set the start time and stop time //How many times to loop + if(groupname == "all"){ + animate = true; + time = startTime; + } + } void Animation::handleShapes(std::vector* allshapes, Ogre::Entity* creaturemodel, Ogre::SkeletonInstance *skel){ @@ -35,7 +42,7 @@ namespace MWRender{ for(allshapesiter = allshapes->begin(); allshapesiter != allshapes->end(); allshapesiter++) { - Nif::NiTriShapeCopy copy = *allshapesiter; + Nif::NiTriShapeCopy& copy = *allshapesiter; std::vector allvertices = copy.vertices; std::vector allnormals = copy.normals; @@ -133,6 +140,7 @@ namespace MWRender{ *addr = absVertPos.x; *(addr+1) = absVertPos.y; *(addr+2) = absVertPos.z; + //std::cout << "Vertex" << vertices[verIndex] << "\n"; } @@ -147,6 +155,7 @@ namespace MWRender{ *addr = absVertPos.x; *(addr+1) = absVertPos.y; *(addr+2) = absVertPos.z; + std::cout << "We are actually 2\n"; //std::cout << "Vertex" << verIndex << "Weight: " << boneinfo.weights[i].weight << "was seen twice\n"; } @@ -194,8 +203,8 @@ namespace MWRender{ Ogre::Vector3 transmult; Ogre::Quaternion rotmult; float scale; - if(creaturemodel->getSkeleton()->hasBone(*boneSequenceIter)){ - Ogre::Bone *bonePtr = creaturemodel->getSkeleton()->getBone(*boneSequenceIter); + if(skel->hasBone(*boneSequenceIter)){ + Ogre::Bone *bonePtr = skel->getBone(*boneSequenceIter); @@ -327,11 +336,7 @@ namespace MWRender{ } void Animation::handleAnimationTransforms(){ - Ogre::Bone* b = skel->getRootBone(); - b->setOrientation(.3,.3,.3,.3); //This is a trick - skel->getManualBonesDirty(); - skel->_updateTransforms(); - skel->_notifyManualBonesDirty(); + std::vector::iterator iter; int slot = 0; diff --git a/apps/openmw/mwrender/creatureanimation.cpp b/apps/openmw/mwrender/creatureanimation.cpp index c9c4d7d16..c97401f73 100644 --- a/apps/openmw/mwrender/creatureanimation.cpp +++ b/apps/openmw/mwrender/creatureanimation.cpp @@ -49,6 +49,19 @@ void CreatureAnimation::runAnimation(float timepassed){ //Handle the animation transforms dependent on time //Handle the shapes dependent on animation transforms + time += timepassed; + Ogre::Bone* b = skel->getRootBone(); + b->setOrientation(.3,.3,.3,.3); //This is a trick + skel->getManualBonesDirty(); + skel->_updateTransforms(); + skel->_notifyManualBonesDirty(); + + base->getAllAnimationStates()->_notifyDirty(); + base->_updateAnimation(); + base->_notifyMoved(); + + handleAnimationTransforms(); + handleShapes(shapes, base, skel); } } diff --git a/apps/openmw/mwrender/npcanimation.cpp b/apps/openmw/mwrender/npcanimation.cpp index 405a60c4e..136a1d2bc 100644 --- a/apps/openmw/mwrender/npcanimation.cpp +++ b/apps/openmw/mwrender/npcanimation.cpp @@ -173,7 +173,7 @@ NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, MWWorld::Environment& _env,O if(hair) insertBoundedPart("meshes\\" + hair->model, "Head"); - if (chest){ + /*if (chest){ insertFreePart("meshes\\" + chest->model, ">\"", insert); @@ -181,7 +181,7 @@ NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, MWWorld::Environment& _env,O if (handr){ insertFreePart("meshes\\" + handr->model , ">?", insert); - } + }*/ if (handl){ insertFreePart("meshes\\" + handl->model, ">>", insert); @@ -207,25 +207,50 @@ void NpcAnimation::insertFreePart(const std::string &mesh, const std::string suf std::string meshNumbered = mesh + getUniqueID(mesh + suffix) + suffix; NIFLoader::load(meshNumbered); - Entity* ent = mRend.getScene()->createEntity(meshNumbered); - insert->attachObject(ent); - entityparts.push_back(ent); + hand = mRend.getScene()->createEntity(meshNumbered); + insert->attachObject(hand); + //entityparts.push_back(ent); std::vector* shapes = ((NIFLoader::getSingletonPtr())->getShapes(mesh + "0000" + suffix)); if(shapes){ shapeparts.push_back(shapes); - handleShapes(shapes, ent, skel); + handleShapes(shapes, hand, skel); } } + void NpcAnimation::runAnimation(float timepassed){ + //Add the amount of time passed to time + + //Handle the animation transforms dependent on time + + //Handle the shapes dependent on animation transforms if(animate){ - //Add the amount of time passed to time + time += timepassed; + Ogre::Bone* b = skel->getRootBone(); + b->setOrientation(.3,.3,.3,.3); //This is a trick + skel->getManualBonesDirty(); + skel->_updateTransforms(); + skel->_notifyManualBonesDirty(); + + base->getAllAnimationStates()->_notifyDirty(); + base->_updateAnimation(); + base->_notifyMoved(); - //Handle the animation transforms dependent on time - //Handle the shapes dependent on animation transforms - } + handleAnimationTransforms(); + std::vector*>::iterator shapepartsiter = shapeparts.begin(); + std::vector::iterator entitypartsiter = entityparts.begin(); + int i = 0; + while(shapepartsiter != shapeparts.end() && entitypartsiter != entityparts.end()) + { + std::vector* shapes = *shapepartsiter; + handleShapes(shapes, *entitypartsiter, skel); + //std::cout << "Shape part size" << shapes->size() << "\n"; + shapepartsiter++; + entitypartsiter++; + } + } } } \ No newline at end of file diff --git a/apps/openmw/mwrender/npcanimation.hpp b/apps/openmw/mwrender/npcanimation.hpp index 1ce949f3a..327e4b0e2 100644 --- a/apps/openmw/mwrender/npcanimation.hpp +++ b/apps/openmw/mwrender/npcanimation.hpp @@ -16,7 +16,7 @@ namespace MWRender{ class NpcAnimation: public Animation{ std::vector entityparts; - + Ogre::Entity* hand; std::vector*> shapeparts; //All the NiTriShape data that we need for animating this particular npc public: NpcAnimation(const MWWorld::Ptr& ptr, MWWorld::Environment& _env, OEngine::Render::OgreRenderer& _rend); diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index fd74c282f..235606b5c 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -234,13 +234,15 @@ void RenderingManager::playAnimationGroup (const MWWorld::Ptr& ptr, const std::s int mode, int number) { std::cout<<"play animation " << groupName << ", " << mode << ", " << number << std::endl; + mActors.playAnimationGroup(ptr, groupName, mode, number); } void RenderingManager::skipAnimation (const MWWorld::Ptr& ptr) { std::cout<<"skip animation"< &cell, MWWorld::Environment& environment); + void advanceTime(); }; } diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index 6f41804c2..a4f167103 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -348,13 +348,14 @@ namespace MWWorld void World::advanceTime (double hours) { hours += mGlobalVariables->getFloat ("gamehour"); - + setHour (hours); int days = hours / 24; if (days>0) mGlobalVariables->setInt ("dayspassed", days + mGlobalVariables->getInt ("dayspassed")); + mWorldScene->advanceTime(); } void World::setHour (double hour) From a6b88b48ecb888d95c1c11da6391c86683d417d4 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Tue, 27 Dec 2011 00:20:14 -0500 Subject: [PATCH 075/104] A different way --- apps/openmw/mwclass/creature.cpp | 2 +- apps/openmw/mwclass/npc.cpp | 4 +-- apps/openmw/mwrender/animation.cpp | 26 ++++++++++---- apps/openmw/mwrender/animation.hpp | 6 ++-- apps/openmw/mwrender/creatureanimation.cpp | 16 ++------- apps/openmw/mwrender/creatureanimation.hpp | 2 +- apps/openmw/mwrender/npcanimation.cpp | 40 +++++++++++----------- apps/openmw/mwrender/npcanimation.hpp | 1 + 8 files changed, 51 insertions(+), 46 deletions(-) diff --git a/apps/openmw/mwclass/creature.cpp b/apps/openmw/mwclass/creature.cpp index 5aa203a49..04853dfc1 100644 --- a/apps/openmw/mwclass/creature.cpp +++ b/apps/openmw/mwclass/creature.cpp @@ -47,7 +47,7 @@ namespace MWClass const std::string &model = ref->base->model; assert (ref->base != NULL); if(!model.empty()){ - physics.insertActorPhysics(ptr, "meshes\\" + model); + // physics.insertActorPhysics(ptr, "meshes\\" + model); } } diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index e09cd6051..b43223691 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -49,11 +49,11 @@ namespace MWClass std::string bodyRaceID = headID.substr(0, headID.find_last_of("head_") - 4); bool beast = bodyRaceID == "b_n_khajiit_m_" || bodyRaceID == "b_n_khajiit_f_" || bodyRaceID == "b_n_argonian_m_" || bodyRaceID == "b_n_argonian_f_"; - + /* std::string smodel = "meshes\\base_anim.nif"; if(beast) smodel = "meshes\\base_animkna.nif"; - physics.insertActorPhysics(ptr, smodel); + physics.insertActorPhysics(ptr, smodel);*/ } diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index 9ec88501f..c6fc13a1f 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -155,7 +155,7 @@ namespace MWRender{ *addr = absVertPos.x; *(addr+1) = absVertPos.y; *(addr+2) = absVertPos.z; - std::cout << "We are actually 2\n"; + //std::cout << "Vertex" << verIndex << "Weight: " << boneinfo.weights[i].weight << "was seen twice\n"; } @@ -335,8 +335,18 @@ namespace MWRender{ } - void Animation::handleAnimationTransforms(){ - + void Animation::handleAnimationTransforms(Ogre::Entity* entity){ + Ogre::SkeletonInstance* skel = entity->getSkeleton(); + + Ogre::Bone* b = skel->getRootBone(); + b->setOrientation(.3,.3,.3,.3); //This is a trick + skel->getManualBonesDirty(); + skel->_updateTransforms(); + skel->_notifyManualBonesDirty(); + + entity->getAllAnimationStates()->_notifyDirty(); + entity->_updateAnimation(); + entity->_notifyMoved(); std::vector::iterator iter; int slot = 0; @@ -345,6 +355,7 @@ namespace MWRender{ if(time < iter->getStartTime() || time < startTime || time > iter->getStopTime()) { continue; + slot++; } if(skel->hasBone(iter->getBonename())){ @@ -387,12 +398,13 @@ namespace MWRender{ skel->getManualBonesDirty(); skel->_updateTransforms(); skel->_notifyManualBonesDirty(); + - Ogre::Entity* ent = base; + - ent->getAllAnimationStates()->_notifyDirty(); - ent->_updateAnimation(); - ent->_notifyMoved(); + entity->getAllAnimationStates()->_notifyDirty(); + entity->_updateAnimation(); + entity->_notifyMoved(); } slot++; } diff --git a/apps/openmw/mwrender/animation.hpp b/apps/openmw/mwrender/animation.hpp index 57673061d..a32437e69 100644 --- a/apps/openmw/mwrender/animation.hpp +++ b/apps/openmw/mwrender/animation.hpp @@ -33,7 +33,9 @@ class Animation{ int shapeNumber; std::vector> shapeIndexI; - Ogre::SkeletonInstance* skel; + //Ogre::SkeletonInstance* skel; + std::vector* shapes; //All the NiTriShapeData for this creature + @@ -41,7 +43,7 @@ class Animation{ std::map textmappings; Ogre::Entity* base; void handleShapes(std::vector* allshapes, Ogre::Entity* creaturemodel, Ogre::SkeletonInstance *skel); - void handleAnimationTransforms(); + void handleAnimationTransforms(Ogre::Entity* model); bool timeIndex( float time, std::vector times, int & i, int & j, float & x ); std::string getUniqueID(std::string mesh); diff --git a/apps/openmw/mwrender/creatureanimation.cpp b/apps/openmw/mwrender/creatureanimation.cpp index c97401f73..033e0f7df 100644 --- a/apps/openmw/mwrender/creatureanimation.cpp +++ b/apps/openmw/mwrender/creatureanimation.cpp @@ -32,7 +32,6 @@ CreatureAnimation::CreatureAnimation(const MWWorld::Ptr& ptr, MWWorld::Environme //a.tindexJ.push_back(0); } loop = false; - skel = base->getSkeleton(); stopTime = transformations->begin()->getStopTime(); //a.startTime = NIFLoader::getSingletonPtr()->getTime(item.smodel, "IdleSneak: Start"); startTime = transformations->begin()->getStartTime(); @@ -50,18 +49,9 @@ void CreatureAnimation::runAnimation(float timepassed){ //Handle the shapes dependent on animation transforms time += timepassed; - Ogre::Bone* b = skel->getRootBone(); - b->setOrientation(.3,.3,.3,.3); //This is a trick - skel->getManualBonesDirty(); - skel->_updateTransforms(); - skel->_notifyManualBonesDirty(); - - base->getAllAnimationStates()->_notifyDirty(); - base->_updateAnimation(); - base->_notifyMoved(); - - handleAnimationTransforms(); - handleShapes(shapes, base, skel); + + handleAnimationTransforms(base); + handleShapes(shapes, base, base->getSkeleton()); } } diff --git a/apps/openmw/mwrender/creatureanimation.hpp b/apps/openmw/mwrender/creatureanimation.hpp index 4c2b2ec77..179991442 100644 --- a/apps/openmw/mwrender/creatureanimation.hpp +++ b/apps/openmw/mwrender/creatureanimation.hpp @@ -14,7 +14,7 @@ namespace MWRender{ class CreatureAnimation: public Animation{ - std::vector* shapes; //All the NiTriShapeData for this creature + public: ~CreatureAnimation(); CreatureAnimation(const MWWorld::Ptr& ptr, MWWorld::Environment& _env, OEngine::Render::OgreRenderer& _rend); diff --git a/apps/openmw/mwrender/npcanimation.cpp b/apps/openmw/mwrender/npcanimation.cpp index 136a1d2bc..5ff378dcf 100644 --- a/apps/openmw/mwrender/npcanimation.cpp +++ b/apps/openmw/mwrender/npcanimation.cpp @@ -50,7 +50,7 @@ NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, MWWorld::Environment& _env,O if(beast) smodel = "meshes\\base_animkna.nif"; - Ogre::SceneNode* insert = ptr.getRefData().getBaseNode(); + insert = ptr.getRefData().getBaseNode(); assert(insert); NifOgre::NIFLoader::load(smodel); @@ -67,7 +67,7 @@ NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, MWWorld::Environment& _env,O //a.tindexJ.push_back(0); } loop = false; - skel = base->getSkeleton(); + stopTime = transformations->begin()->getStopTime(); //a.startTime = NIFLoader::getSingletonPtr()->getTime(item.smodel, "IdleSneak: Start"); startTime = transformations->begin()->getStartTime(); @@ -207,13 +207,13 @@ void NpcAnimation::insertFreePart(const std::string &mesh, const std::string suf std::string meshNumbered = mesh + getUniqueID(mesh + suffix) + suffix; NIFLoader::load(meshNumbered); - hand = mRend.getScene()->createEntity(meshNumbered); - insert->attachObject(hand); - //entityparts.push_back(ent); - std::vector* shapes = ((NIFLoader::getSingletonPtr())->getShapes(mesh + "0000" + suffix)); + Ogre::Entity* ent = mRend.getScene()->createEntity(meshNumbered); + insert->attachObject(ent); + entityparts.push_back(ent); + shapes = ((NIFLoader::getSingletonPtr())->getShapes(mesh + "0000" + suffix)); if(shapes){ shapeparts.push_back(shapes); - handleShapes(shapes, hand, skel); + handleShapes(shapes, ent, base->getSkeleton()); } @@ -228,25 +228,25 @@ void NpcAnimation::runAnimation(float timepassed){ //Handle the shapes dependent on animation transforms if(animate){ time += timepassed; - Ogre::Bone* b = skel->getRootBone(); - b->setOrientation(.3,.3,.3,.3); //This is a trick - skel->getManualBonesDirty(); - skel->_updateTransforms(); - skel->_notifyManualBonesDirty(); - - base->getAllAnimationStates()->_notifyDirty(); - base->_updateAnimation(); - base->_notifyMoved(); + - handleAnimationTransforms(); + handleAnimationTransforms(base); + // handleAnimationTransforms(base); + //handleAnimationTransforms(hand); + // std::vector*>::iterator shapepartsiter = shapeparts.begin(); std::vector::iterator entitypartsiter = entityparts.begin(); - int i = 0; - while(shapepartsiter != shapeparts.end() && entitypartsiter != entityparts.end()) + //int i = 0; + while(shapepartsiter != shapeparts.end()) { std::vector* shapes = *shapepartsiter; - handleShapes(shapes, *entitypartsiter, skel); + //insert-> + //insert->detachObject(hand->getName()); + Ogre::Entity* theentity = *entitypartsiter; + handleAnimationTransforms(theentity); + handleShapes(shapes, theentity, theentity->getSkeleton()); + //insert->attachObject(hand); //std::cout << "Shape part size" << shapes->size() << "\n"; shapepartsiter++; entitypartsiter++; diff --git a/apps/openmw/mwrender/npcanimation.hpp b/apps/openmw/mwrender/npcanimation.hpp index 327e4b0e2..65b1a9300 100644 --- a/apps/openmw/mwrender/npcanimation.hpp +++ b/apps/openmw/mwrender/npcanimation.hpp @@ -17,6 +17,7 @@ namespace MWRender{ class NpcAnimation: public Animation{ std::vector entityparts; Ogre::Entity* hand; + Ogre::SceneNode* insert; std::vector*> shapeparts; //All the NiTriShape data that we need for animating this particular npc public: NpcAnimation(const MWWorld::Ptr& ptr, MWWorld::Environment& _env, OEngine::Render::OgreRenderer& _rend); From 1a90f4241b689848c5b30d4008f3c37543f947c0 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Tue, 27 Dec 2011 00:25:52 -0500 Subject: [PATCH 076/104] Npc Animation Working --- apps/openmw/mwrender/npcanimation.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwrender/npcanimation.cpp b/apps/openmw/mwrender/npcanimation.cpp index 5ff378dcf..cb78c664c 100644 --- a/apps/openmw/mwrender/npcanimation.cpp +++ b/apps/openmw/mwrender/npcanimation.cpp @@ -173,7 +173,7 @@ NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, MWWorld::Environment& _env,O if(hair) insertBoundedPart("meshes\\" + hair->model, "Head"); - /*if (chest){ + if (chest){ insertFreePart("meshes\\" + chest->model, ">\"", insert); @@ -181,7 +181,7 @@ NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, MWWorld::Environment& _env,O if (handr){ insertFreePart("meshes\\" + handr->model , ">?", insert); - }*/ + } if (handl){ insertFreePart("meshes\\" + handl->model, ">>", insert); From c399f4f2103168e9125e4d6d44e266244ce1957f Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Tue, 27 Dec 2011 17:12:47 -0500 Subject: [PATCH 077/104] Fixing a few things --- apps/openmw/mwrender/actors.cpp | 3 ++- apps/openmw/mwrender/animation.cpp | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwrender/actors.cpp b/apps/openmw/mwrender/actors.cpp index 6f479d877..937bf96b0 100644 --- a/apps/openmw/mwrender/actors.cpp +++ b/apps/openmw/mwrender/actors.cpp @@ -114,7 +114,8 @@ void Actors::removeCell(MWWorld::Ptr::CellStore* store){ } void Actors::playAnimationGroup (const MWWorld::Ptr& ptr, const std::string& groupName, int mode, int number){ - mAllActors.find(ptr)->second->startScript(groupName, mode, number); + if(mAllActors.find(ptr) != mAllActors.end()) + mAllActors[ptr]->startScript(groupName, mode, number); } void Actors::skipAnimation (const MWWorld::Ptr& ptr){ diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index c6fc13a1f..e9d6710be 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -354,8 +354,10 @@ namespace MWRender{ for(iter = transformations->begin(); iter != transformations->end(); iter++){ if(time < iter->getStartTime() || time < startTime || time > iter->getStopTime()) { - continue; slot++; + iter++; + continue; + } if(skel->hasBone(iter->getBonename())){ From d855bb4fc6e6514ffac937e5c952f53342661304 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Tue, 27 Dec 2011 17:52:17 -0500 Subject: [PATCH 078/104] physics reenabled --- apps/openmw/mwclass/creature.cpp | 2 +- apps/openmw/mwclass/npc.cpp | 4 ++-- components/nifogre/ogre_nif_loader.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/openmw/mwclass/creature.cpp b/apps/openmw/mwclass/creature.cpp index 04853dfc1..5aa203a49 100644 --- a/apps/openmw/mwclass/creature.cpp +++ b/apps/openmw/mwclass/creature.cpp @@ -47,7 +47,7 @@ namespace MWClass const std::string &model = ref->base->model; assert (ref->base != NULL); if(!model.empty()){ - // physics.insertActorPhysics(ptr, "meshes\\" + model); + physics.insertActorPhysics(ptr, "meshes\\" + model); } } diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index b43223691..acb0a5a35 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -49,11 +49,11 @@ namespace MWClass std::string bodyRaceID = headID.substr(0, headID.find_last_of("head_") - 4); bool beast = bodyRaceID == "b_n_khajiit_m_" || bodyRaceID == "b_n_khajiit_f_" || bodyRaceID == "b_n_argonian_m_" || bodyRaceID == "b_n_argonian_f_"; - /* + std::string smodel = "meshes\\base_anim.nif"; if(beast) smodel = "meshes\\base_animkna.nif"; - physics.insertActorPhysics(ptr, smodel);*/ + physics.insertActorPhysics(ptr, smodel); } diff --git a/components/nifogre/ogre_nif_loader.cpp b/components/nifogre/ogre_nif_loader.cpp index cbb137511..e3765fd61 100644 --- a/components/nifogre/ogre_nif_loader.cpp +++ b/components/nifogre/ogre_nif_loader.cpp @@ -337,7 +337,7 @@ void NIFLoader::createOgreSubMesh(NiTriShape *shape, const String &material, std HardwareVertexBufferSharedPtr vbuf = HardwareBufferManager::getSingleton().createVertexBuffer( VertexElement::getTypeSize(VET_FLOAT3), - numVerts, HardwareBuffer::HBU_STATIC_WRITE_ONLY); + numVerts, HardwareBuffer::HBU_DYNAMIC); if(flip) { From cef2f5e9277de4f399a1f79b9791ab344ccefd4f Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Tue, 27 Dec 2011 19:19:45 -0500 Subject: [PATCH 079/104] Trying to get code to conform with older c++ --- apps/openmw/mwrender/animation.hpp | 2 +- apps/openmw/mwrender/npcanimation.hpp | 2 +- components/nif/data.hpp | 8 ++++---- components/nifogre/ogre_nif_loader.cpp | 2 +- components/nifogre/ogre_nif_loader.hpp | 1 + 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/apps/openmw/mwrender/animation.hpp b/apps/openmw/mwrender/animation.hpp index a32437e69..eb0acd575 100644 --- a/apps/openmw/mwrender/animation.hpp +++ b/apps/openmw/mwrender/animation.hpp @@ -31,7 +31,7 @@ class Animation{ //Only shapes with morphing data will need a shape number int shapeNumber; - std::vector> shapeIndexI; + std::vector > shapeIndexI; //Ogre::SkeletonInstance* skel; std::vector* shapes; //All the NiTriShapeData for this creature diff --git a/apps/openmw/mwrender/npcanimation.hpp b/apps/openmw/mwrender/npcanimation.hpp index 65b1a9300..9dcbce9a3 100644 --- a/apps/openmw/mwrender/npcanimation.hpp +++ b/apps/openmw/mwrender/npcanimation.hpp @@ -18,7 +18,7 @@ class NpcAnimation: public Animation{ std::vector entityparts; Ogre::Entity* hand; Ogre::SceneNode* insert; - std::vector*> shapeparts; //All the NiTriShape data that we need for animating this particular npc + std::vector* > shapeparts; //All the NiTriShape data that we need for animating this particular npc public: NpcAnimation(const MWWorld::Ptr& ptr, MWWorld::Environment& _env, OEngine::Render::OgreRenderer& _rend); ~NpcAnimation(); diff --git a/components/nif/data.hpp b/components/nif/data.hpp index 47ecfdd2c..898dd2283 100644 --- a/components/nif/data.hpp +++ b/components/nif/data.hpp @@ -429,9 +429,9 @@ class NiMorphData : public Record float startTime; float stopTime; std::vector initialVertices; - std::vector> relevantTimes; - std::vector> relevantData; - std::vector> additionalVertices; + std::vector > relevantTimes; + std::vector > relevantData; + std::vector > additionalVertices; public: @@ -457,7 +457,7 @@ public: std::vector> getRelevantTimes(){ return relevantTimes; } - std::vector> getAdditionalVertices(){ + std::vector > getAdditionalVertices(){ return additionalVertices; } diff --git a/components/nifogre/ogre_nif_loader.cpp b/components/nifogre/ogre_nif_loader.cpp index e3765fd61..62074f2f9 100644 --- a/components/nifogre/ogre_nif_loader.cpp +++ b/components/nifogre/ogre_nif_loader.cpp @@ -1250,7 +1250,7 @@ void NIFLoader::loadResource(Resource *resource) Nif::Node *o = dynamic_cast(f->target.getPtr()); Nif::NiKeyframeDataPtr data = f->data; - if (f->timeStart == FLT_MAX) + if (f->timeStart == 10000000000000000) continue; data->setBonename(o->name.toString()); data->setStartTime(f->timeStart); diff --git a/components/nifogre/ogre_nif_loader.hpp b/components/nifogre/ogre_nif_loader.hpp index c97968510..e9caf8d11 100644 --- a/components/nifogre/ogre_nif_loader.hpp +++ b/components/nifogre/ogre_nif_loader.hpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include "../nif/nif_file.hpp" From 8c3127367aa7a4f40025cdc244df3a7882f14bad Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Tue, 27 Dec 2011 22:35:22 -0500 Subject: [PATCH 080/104] Npc Optimization --- apps/openmw/mwrender/animation.cpp | 83 +++++++++++++++------- apps/openmw/mwrender/animation.hpp | 3 +- apps/openmw/mwrender/creatureanimation.cpp | 2 +- apps/openmw/mwrender/npcanimation.cpp | 4 +- apps/openmw/mwrender/npcanimation.hpp | 3 +- 5 files changed, 64 insertions(+), 31 deletions(-) diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index e9d6710be..f5ab9e8c5 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -335,8 +335,9 @@ namespace MWRender{ } - void Animation::handleAnimationTransforms(Ogre::Entity* entity){ - Ogre::SkeletonInstance* skel = entity->getSkeleton(); + void Animation::handleAnimationTransforms(){ + Ogre::SkeletonInstance* skel = base->getSkeleton(); + Ogre::Bone* b = skel->getRootBone(); b->setOrientation(.3,.3,.3,.3); //This is a trick @@ -344,9 +345,23 @@ namespace MWRender{ skel->_updateTransforms(); skel->_notifyManualBonesDirty(); - entity->getAllAnimationStates()->_notifyDirty(); - entity->_updateAnimation(); - entity->_notifyMoved(); + base->getAllAnimationStates()->_notifyDirty(); + base->_updateAnimation(); + base->_notifyMoved(); + + for(int i = 0; i < entityparts.size(); i++){ + Ogre::SkeletonInstance* skel = entityparts[i]->getSkeleton(); + + Ogre::Bone* b = skel->getRootBone(); + b->setOrientation(.3,.3,.3,.3); //This is a trick + skel->getManualBonesDirty(); + skel->_updateTransforms(); + skel->_notifyManualBonesDirty(); + + entityparts[i]->getAllAnimationStates()->_notifyDirty(); + entityparts[i]->_updateAnimation(); + entityparts[i]->_notifyMoved(); + } std::vector::iterator iter; int slot = 0; @@ -360,10 +375,7 @@ namespace MWRender{ } - if(skel->hasBone(iter->getBonename())){ - Ogre::Bone* bone = skel->getBone(iter->getBonename()); - - float x; + float x; float x2; std::vector quats = iter->getQuat(); @@ -382,32 +394,53 @@ namespace MWRender{ timeIndex(time, ttime, tindexI[slot], tindexJ, x); //std::cout << "X: " << x << " X2: " << x2 << "\n"; - - - if(translist1.size() > 0){ + Ogre::Vector3 t; + Ogre::Quaternion r; + + bool bTrans = translist1.size() > 0; + if(bTrans){ Ogre::Vector3 v1 = translist1[tindexI[slot]]; Ogre::Vector3 v2 = translist1[tindexJ]; - Ogre::Vector3 t = v1 + (v2 - v1) * x; - bone->setPosition(t); + t = (v1 + (v2 - v1) * x); + } - if(quats.size() > 0){ - Ogre::Quaternion r = Ogre::Quaternion::Slerp(x2, quats[rindexI[slot]], quats[rindexJ], true); - bone->setOrientation(r); + bool bQuats = quats.size() > 0; + if(bQuats){ + r = Ogre::Quaternion::Slerp(x2, quats[rindexI[slot]], quats[rindexJ], true); + //bone->setOrientation(r); } + skel = base->getSkeleton(); - + if(skel->hasBone(iter->getBonename())){ + Ogre::Bone* bone = skel->getBone(iter->getBonename()); + if(bTrans) + bone->setPosition(t); + if(bQuats) + bone->setOrientation(r); skel->getManualBonesDirty(); skel->_updateTransforms(); skel->_notifyManualBonesDirty(); - - - - - entity->getAllAnimationStates()->_notifyDirty(); - entity->_updateAnimation(); - entity->_notifyMoved(); + base->getAllAnimationStates()->_notifyDirty(); + base->_updateAnimation(); + base->_notifyMoved(); } + for(int i = 0; i < entityparts.size(); i++){ + skel = entityparts[i]->getSkeleton(); + if(skel->hasBone(iter->getBonename())){ + Ogre::Bone* bone = skel->getBone(iter->getBonename()); + if(bTrans) + bone->setPosition(t); + if(bQuats) + bone->setOrientation(r); + skel->getManualBonesDirty(); + skel->_updateTransforms(); + skel->_notifyManualBonesDirty(); + entityparts[i]->getAllAnimationStates()->_notifyDirty(); + entityparts[i]->_updateAnimation(); + entityparts[i]->_notifyMoved(); + } + } slot++; } } diff --git a/apps/openmw/mwrender/animation.hpp b/apps/openmw/mwrender/animation.hpp index eb0acd575..d97ccbe29 100644 --- a/apps/openmw/mwrender/animation.hpp +++ b/apps/openmw/mwrender/animation.hpp @@ -35,6 +35,7 @@ class Animation{ //Ogre::SkeletonInstance* skel; std::vector* shapes; //All the NiTriShapeData for this creature + std::vector entityparts; @@ -43,7 +44,7 @@ class Animation{ std::map textmappings; Ogre::Entity* base; void handleShapes(std::vector* allshapes, Ogre::Entity* creaturemodel, Ogre::SkeletonInstance *skel); - void handleAnimationTransforms(Ogre::Entity* model); + void handleAnimationTransforms(); bool timeIndex( float time, std::vector times, int & i, int & j, float & x ); std::string getUniqueID(std::string mesh); diff --git a/apps/openmw/mwrender/creatureanimation.cpp b/apps/openmw/mwrender/creatureanimation.cpp index 033e0f7df..868561ca8 100644 --- a/apps/openmw/mwrender/creatureanimation.cpp +++ b/apps/openmw/mwrender/creatureanimation.cpp @@ -50,7 +50,7 @@ void CreatureAnimation::runAnimation(float timepassed){ //Handle the shapes dependent on animation transforms time += timepassed; - handleAnimationTransforms(base); + handleAnimationTransforms(); handleShapes(shapes, base, base->getSkeleton()); } diff --git a/apps/openmw/mwrender/npcanimation.cpp b/apps/openmw/mwrender/npcanimation.cpp index cb78c664c..c1c3ea680 100644 --- a/apps/openmw/mwrender/npcanimation.cpp +++ b/apps/openmw/mwrender/npcanimation.cpp @@ -231,7 +231,7 @@ void NpcAnimation::runAnimation(float timepassed){ - handleAnimationTransforms(base); + handleAnimationTransforms(); // handleAnimationTransforms(base); //handleAnimationTransforms(hand); // @@ -244,7 +244,7 @@ void NpcAnimation::runAnimation(float timepassed){ //insert-> //insert->detachObject(hand->getName()); Ogre::Entity* theentity = *entitypartsiter; - handleAnimationTransforms(theentity); + // handleAnimationTransforms(theentity); handleShapes(shapes, theentity, theentity->getSkeleton()); //insert->attachObject(hand); //std::cout << "Shape part size" << shapes->size() << "\n"; diff --git a/apps/openmw/mwrender/npcanimation.hpp b/apps/openmw/mwrender/npcanimation.hpp index 9dcbce9a3..ef9bef29f 100644 --- a/apps/openmw/mwrender/npcanimation.hpp +++ b/apps/openmw/mwrender/npcanimation.hpp @@ -15,8 +15,7 @@ namespace MWRender{ class NpcAnimation: public Animation{ - std::vector entityparts; - Ogre::Entity* hand; + Ogre::SceneNode* insert; std::vector* > shapeparts; //All the NiTriShape data that we need for animating this particular npc public: From baa3f5188649db6606fafc3dbbc035477d473cbb Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Wed, 28 Dec 2011 14:48:28 -0500 Subject: [PATCH 081/104] Trying to fix errors --- components/nif/data.hpp | 4 ++-- components/nifogre/ogre_nif_loader.cpp | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/components/nif/data.hpp b/components/nif/data.hpp index 898dd2283..892e98003 100644 --- a/components/nif/data.hpp +++ b/components/nif/data.hpp @@ -451,10 +451,10 @@ public: std::vector getInitialVertices(){ return initialVertices; } - std::vector> getRelevantData(){ + std::vector > getRelevantData(){ return relevantData; } - std::vector> getRelevantTimes(){ + std::vector > getRelevantTimes(){ return relevantTimes; } std::vector > getAdditionalVertices(){ diff --git a/components/nifogre/ogre_nif_loader.cpp b/components/nifogre/ogre_nif_loader.cpp index 62074f2f9..a19f5df89 100644 --- a/components/nifogre/ogre_nif_loader.cpp +++ b/components/nifogre/ogre_nif_loader.cpp @@ -1006,7 +1006,7 @@ void NIFLoader::handleNode(Nif::Node *node, int flags, std::cout << "Outputting " << cut << "\n"; - std::ofstream File("Indices" + cut + ".txt"); + std::ofstream file(("Indices" + cut + ".txt").c_str()); /*if(File.is_open()) std::cout << "We could open\n"; @@ -1021,11 +1021,11 @@ void NIFLoader::handleNode(Nif::Node *node, int flags, replace(text.begin(), text.end(), '\n', '/'); text.erase(std::remove(text.begin(), text.end(), '\r'), text.end()); - File << "Time: " << textiter->time << "|" << text << "\n"; + file << "Time: " << textiter->time << "|" << text << "\n"; textmappings[text] = textiter->time; } - File.close(); + file.close(); } } @@ -1112,7 +1112,7 @@ void NIFLoader::handleNode(Nif::Node *node, int flags, } else if(nodename.length() >= triname.length()) { - std::transform(nodename.begin(), nodename.end(), nodename.begin(), std::tolower); + std::transform(nodename.begin(), nodename.end(), nodename.begin(), ::tolower); if(triname == nodename.substr(0, triname.length())) handleNiTriShape(dynamic_cast(node), flags, bounds, original, boneSequence); } From c8cca06b40ce97dd6d13118b83ca7c3ac697f2f8 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Wed, 28 Dec 2011 17:34:47 -0500 Subject: [PATCH 082/104] unlocking change and stop change --- apps/openmw/mwrender/animation.cpp | 19 ++++--------------- apps/openmw/mwrender/creatureanimation.cpp | 7 ++++++- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index f5ab9e8c5..93025ae09 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -40,7 +40,8 @@ namespace MWRender{ shapeNumber = 0; std::vector::iterator allshapesiter; for(allshapesiter = allshapes->begin(); allshapesiter != allshapes->end(); allshapesiter++) - { + + { Nif::NiTriShapeCopy& copy = *allshapesiter; std::vector allvertices = copy.vertices; @@ -261,21 +262,9 @@ namespace MWRender{ } } - - } - - - for(allshapesiter = allshapes->begin(); allshapesiter != allshapes->end(); allshapesiter++) - { - Nif::NiTriShapeCopy copy = *allshapesiter; - Ogre::HardwareVertexBufferSharedPtr vbuf = creaturemodel->getMesh()->getSubMesh(copy.sname)->vertexData->vertexBufferBinding->getBuffer(0); - - Ogre::HardwareVertexBufferSharedPtr vbufNormal = creaturemodel->getMesh()->getSubMesh(copy.sname)->vertexData->vertexBufferBinding->getBuffer(1); - vbuf->unlock(); + vbuf->unlock(); vbufNormal->unlock(); - } - - + } } bool Animation::timeIndex( float time, std::vector times, int & i, int & j, float & x ){ diff --git a/apps/openmw/mwrender/creatureanimation.cpp b/apps/openmw/mwrender/creatureanimation.cpp index 868561ca8..2829c7ea1 100644 --- a/apps/openmw/mwrender/creatureanimation.cpp +++ b/apps/openmw/mwrender/creatureanimation.cpp @@ -49,7 +49,12 @@ void CreatureAnimation::runAnimation(float timepassed){ //Handle the shapes dependent on animation transforms time += timepassed; - + if(time > transformations->begin()->getStopTime()){ + animate = false; + std::cout << "Stopping the animation\n"; + return; + } + handleAnimationTransforms(); handleShapes(shapes, base, base->getSkeleton()); From 42e7ff9b131a25755f1e75d04b7bf917bbcda7d6 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Wed, 28 Dec 2011 21:52:05 -0500 Subject: [PATCH 083/104] Introducing loops; SkipAnim; Skeleton reset bug fixed --- apps/openmw/mwrender/actors.cpp | 3 ++- apps/openmw/mwrender/animation.cpp | 5 ++++- apps/openmw/mwrender/animation.hpp | 6 ++++-- apps/openmw/mwrender/creatureanimation.cpp | 13 ++++++++----- apps/openmw/mwrender/npcanimation.cpp | 14 ++++++++++++-- apps/openmw/mwrender/npcanimation.hpp | 2 +- apps/openmw/mwrender/renderingmanager.cpp | 1 + 7 files changed, 32 insertions(+), 12 deletions(-) diff --git a/apps/openmw/mwrender/actors.cpp b/apps/openmw/mwrender/actors.cpp index 937bf96b0..3b94b19f7 100644 --- a/apps/openmw/mwrender/actors.cpp +++ b/apps/openmw/mwrender/actors.cpp @@ -118,7 +118,8 @@ void Actors::playAnimationGroup (const MWWorld::Ptr& ptr, const std::string& gro mAllActors[ptr]->startScript(groupName, mode, number); } void Actors::skipAnimation (const MWWorld::Ptr& ptr){ - + if(mAllActors.find(ptr) != mAllActors.end()) + mAllActors[ptr]->stopScript(); } void Actors::addTime(){ //std::cout << "Adding time in actors\n"; diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index 93025ae09..7f59bc7d1 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -30,11 +30,14 @@ namespace MWRender{ //Set the start time and stop time //How many times to loop if(groupname == "all"){ - animate = true; + animate = loops; time = startTime; } } + void Animation::stopScript(){ + animate = 0; + } void Animation::handleShapes(std::vector* allshapes, Ogre::Entity* creaturemodel, Ogre::SkeletonInstance *skel){ shapeNumber = 0; diff --git a/apps/openmw/mwrender/animation.hpp b/apps/openmw/mwrender/animation.hpp index d97ccbe29..65f872e0a 100644 --- a/apps/openmw/mwrender/animation.hpp +++ b/apps/openmw/mwrender/animation.hpp @@ -18,12 +18,13 @@ class Animation{ OEngine::Render::OgreRenderer &mRend; MWWorld::Environment& mEnvironment; static std::map mUniqueIDs; + std::vector* > shapeparts; //All the NiTriShape data that we need for animating an npc float time; float startTime; float stopTime; bool loop; - bool animate; + int animate; //Represents a rotation index for each bone std::vectorrindexI; //Represents a translation index for each bone @@ -49,9 +50,10 @@ class Animation{ std::string getUniqueID(std::string mesh); public: - Animation(MWWorld::Environment& _env, OEngine::Render::OgreRenderer& _rend): mRend(_rend), mEnvironment(_env), loop(false), animate(false){}; + Animation(MWWorld::Environment& _env, OEngine::Render::OgreRenderer& _rend): mRend(_rend), mEnvironment(_env), loop(false), animate(0){}; virtual void runAnimation(float timepassed) = 0; void startScript(std::string groupname, int mode, int loops); + void stopScript(); ~Animation(); diff --git a/apps/openmw/mwrender/creatureanimation.cpp b/apps/openmw/mwrender/creatureanimation.cpp index 2829c7ea1..fe717a9f3 100644 --- a/apps/openmw/mwrender/creatureanimation.cpp +++ b/apps/openmw/mwrender/creatureanimation.cpp @@ -42,17 +42,20 @@ CreatureAnimation::CreatureAnimation(const MWWorld::Ptr& ptr, MWWorld::Environme } void CreatureAnimation::runAnimation(float timepassed){ - if(animate){ + if(animate > 0){ //Add the amount of time passed to time //Handle the animation transforms dependent on time //Handle the shapes dependent on animation transforms time += timepassed; - if(time > transformations->begin()->getStopTime()){ - animate = false; - std::cout << "Stopping the animation\n"; - return; + if(time > stopTime){ + animate--; + //std::cout << "Stopping the animation\n"; + if(animate == 0) + time = stopTime; + else + time = startTime + (time - stopTime); } handleAnimationTransforms(); diff --git a/apps/openmw/mwrender/npcanimation.cpp b/apps/openmw/mwrender/npcanimation.cpp index c1c3ea680..297aa2484 100644 --- a/apps/openmw/mwrender/npcanimation.cpp +++ b/apps/openmw/mwrender/npcanimation.cpp @@ -56,6 +56,8 @@ NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, MWWorld::Environment& _env,O NifOgre::NIFLoader::load(smodel); base = mRend.getScene()->createEntity(smodel); + base->setSkipAnimationStateUpdate(true); //Magical line of code, this makes the bones + //stay in the same place when we skipanim, or open a gui window if(transformations = (NIFLoader::getSingletonPtr())->getAnim(smodel)){ @@ -226,10 +228,17 @@ void NpcAnimation::runAnimation(float timepassed){ //Handle the animation transforms dependent on time //Handle the shapes dependent on animation transforms - if(animate){ + if(animate > 0){ time += timepassed; - + if(time > stopTime){ + animate--; + //std::cout << "Stopping the animation\n"; + if(animate == 0) + time = stopTime; + else + time = startTime + (time - stopTime); + } handleAnimationTransforms(); // handleAnimationTransforms(base); @@ -252,5 +261,6 @@ void NpcAnimation::runAnimation(float timepassed){ entitypartsiter++; } } + } } \ No newline at end of file diff --git a/apps/openmw/mwrender/npcanimation.hpp b/apps/openmw/mwrender/npcanimation.hpp index ef9bef29f..edc0648ef 100644 --- a/apps/openmw/mwrender/npcanimation.hpp +++ b/apps/openmw/mwrender/npcanimation.hpp @@ -17,7 +17,7 @@ namespace MWRender{ class NpcAnimation: public Animation{ Ogre::SceneNode* insert; - std::vector* > shapeparts; //All the NiTriShape data that we need for animating this particular npc + public: NpcAnimation(const MWWorld::Ptr& ptr, MWWorld::Environment& _env, OEngine::Render::OgreRenderer& _rend); ~NpcAnimation(); diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index 235606b5c..ae2e0f791 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -240,6 +240,7 @@ std::cout<<"play animation " << groupName << ", " << mode << ", " << number << s void RenderingManager::skipAnimation (const MWWorld::Ptr& ptr) { std::cout<<"skip animation"< Date: Sat, 31 Dec 2011 02:41:26 -0500 Subject: [PATCH 084/104] female argonian fix --- apps/openmw/mwrender/npcanimation.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/apps/openmw/mwrender/npcanimation.cpp b/apps/openmw/mwrender/npcanimation.cpp index 297aa2484..608a83d5d 100644 --- a/apps/openmw/mwrender/npcanimation.cpp +++ b/apps/openmw/mwrender/npcanimation.cpp @@ -96,6 +96,8 @@ NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, MWWorld::Environment& _env,O const ESM::BodyPart *handl = mEnvironment.mWorld->getStore().bodyParts.search (bodyRaceID + "hand"); //We need two const ESM::BodyPart *hair = mEnvironment.mWorld->getStore().bodyParts.search(hairID); const ESM::BodyPart *head = mEnvironment.mWorld->getStore().bodyParts.search(headID); + if(bodyRaceID == "b_n_argonian_f_") + forearml = mEnvironment.mWorld->getStore().bodyParts.search ("b_n_argonian_m_forearm"); //We need two if(!handl) handl = mEnvironment.mWorld->getStore().bodyParts.search (bodyRaceID + "hands"); //const ESM::BodyPart* claviclel = environment.mWorld->getStore().bodyParts.search (bodyRaceID + "clavicle"); From f7d26b2695c0be7b1405338a6c1515caf8809011 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Sun, 1 Jan 2012 00:05:21 -0500 Subject: [PATCH 085/104] Scaling for wood elves --- apps/openmw/mwrender/npcanimation.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwrender/npcanimation.cpp b/apps/openmw/mwrender/npcanimation.cpp index 608a83d5d..994e21a41 100644 --- a/apps/openmw/mwrender/npcanimation.cpp +++ b/apps/openmw/mwrender/npcanimation.cpp @@ -75,7 +75,9 @@ NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, MWWorld::Environment& _env,O startTime = transformations->begin()->getStartTime(); } insert->attachObject(base); - + + if(bodyRaceID == "b_n_wood elf_f_" || bodyRaceID == "b_n_wood elf_m_") + insert->scale(.9,.9,.9); std::string headModel = "meshes\\" + mEnvironment.mWorld->getStore().bodyParts.find(headID)->model; From 289b8f667ed81278d6984af3253e314f870c5c68 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Sun, 1 Jan 2012 17:28:46 -0500 Subject: [PATCH 086/104] Various npc heights --- apps/openmw/mwrender/npcanimation.cpp | 32 +++++++++++++++++++-------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/apps/openmw/mwrender/npcanimation.cpp b/apps/openmw/mwrender/npcanimation.cpp index 994e21a41..c5c5c3ff5 100644 --- a/apps/openmw/mwrender/npcanimation.cpp +++ b/apps/openmw/mwrender/npcanimation.cpp @@ -35,16 +35,26 @@ NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, MWWorld::Environment& _env,O // vector = Ogre::Vector3(1,1,-1); - std::string hairID = ref->base->hair; std::string headID = ref->base->head; std::string npcName = ref->base->name; - + //ESMStore::Races r = + const ESM::Race* race = mEnvironment.mWorld->getStore().races.find(ref->base->race); + + std::string bodyRaceID = headID.substr(0, headID.find_last_of("head_") - 4); char secondtolast = bodyRaceID.at(bodyRaceID.length() - 2); bool female = tolower(secondtolast) == 'f'; bool beast = bodyRaceID == "b_n_khajiit_m_" || bodyRaceID == "b_n_khajiit_f_" || bodyRaceID == "b_n_argonian_m_" || bodyRaceID == "b_n_argonian_f_"; + std::cout << "Race: " << ref->base->race ; + if(female){ + std::cout << " Sex: Female" << " Height: " << race->data.height.female << "\n"; + } + else{ + std::cout << " Sex: Male" << " Height: " << race->data.height.male << "\n"; + } + std::string smodel = "meshes\\base_anim.nif"; if(beast) @@ -76,8 +86,10 @@ NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, MWWorld::Environment& _env,O } insert->attachObject(base); - if(bodyRaceID == "b_n_wood elf_f_" || bodyRaceID == "b_n_wood elf_m_") - insert->scale(.9,.9,.9); + if(female) + insert->scale(race->data.height.female, race->data.height.female, race->data.height.female); + else + insert->scale(race->data.height.male, race->data.height.male, race->data.height.male); std::string headModel = "meshes\\" + mEnvironment.mWorld->getStore().bodyParts.find(headID)->model; @@ -108,6 +120,8 @@ NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, MWWorld::Environment& _env,O const ESM::BodyPart* forearmr = forearml; const ESM::BodyPart* wristr = wristl; const ESM::BodyPart* armr = arml; + + if(upperleg){ insertBoundedPart("meshes\\" + upperleg->model + "*|", "Left Upper Leg"); insertBoundedPart("meshes\\" + upperleg->model, "Right Upper Leg"); @@ -168,8 +182,8 @@ NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, MWWorld::Environment& _env,O insertBoundedPart("meshes\\" + claviclel->model + "*|", "Left Clavicle", base); if(clavicler) insertBoundedPart("meshes\\" + clavicler->model , "Right Clavicle", base);*/ - - + + if(neck) { insertBoundedPart("meshes\\" + neck->model, "Neck"); @@ -178,7 +192,7 @@ NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, MWWorld::Environment& _env,O insertBoundedPart("meshes\\" + head->model, "Head"); if(hair) insertBoundedPart("meshes\\" + hair->model, "Head"); - + if (chest){ insertFreePart("meshes\\" + chest->model, ">\"", insert); @@ -248,7 +262,7 @@ void NpcAnimation::runAnimation(float timepassed){ // handleAnimationTransforms(base); //handleAnimationTransforms(hand); // - std::vector*>::iterator shapepartsiter = shapeparts.begin(); + /*std::vector*>::iterator shapepartsiter = shapeparts.begin(); std::vector::iterator entitypartsiter = entityparts.begin(); //int i = 0; while(shapepartsiter != shapeparts.end()) @@ -263,7 +277,7 @@ void NpcAnimation::runAnimation(float timepassed){ //std::cout << "Shape part size" << shapes->size() << "\n"; shapepartsiter++; entitypartsiter++; - } + }*/ } } From a4c6d948d47941dbe95bc33fef7e9752cde610b1 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Sun, 1 Jan 2012 20:51:26 -0500 Subject: [PATCH 087/104] Disabling normal updates --- apps/openmw/mwrender/animation.cpp | 16 ++++++++-------- apps/openmw/mwrender/npcanimation.cpp | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index 7f59bc7d1..bea0873b7 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -53,14 +53,14 @@ namespace MWRender{ std::set vertices; - std::set normals; + //std::set normals; std::vector boneinfovector = copy.boneinfo; //std::cout << "Name " << copy.sname << "\n"; Ogre::HardwareVertexBufferSharedPtr vbuf = creaturemodel->getMesh()->getSubMesh(copy.sname)->vertexData->vertexBufferBinding->getBuffer(0); Ogre::Real* pReal = static_cast(vbuf->lock(Ogre::HardwareBuffer::HBL_NORMAL)); - Ogre::HardwareVertexBufferSharedPtr vbufNormal = creaturemodel->getMesh()->getSubMesh(copy.sname)->vertexData->vertexBufferBinding->getBuffer(1); - Ogre::Real* pRealNormal = static_cast(vbufNormal->lock(Ogre::HardwareBuffer::HBL_NORMAL)); + //Ogre::HardwareVertexBufferSharedPtr vbufNormal = creaturemodel->getMesh()->getSubMesh(copy.sname)->vertexData->vertexBufferBinding->getBuffer(1); + // Ogre::Real* pRealNormal = static_cast(vbufNormal->lock(Ogre::HardwareBuffer::HBL_NORMAL)); std::vector initialVertices = copy.morph.getInitialVertices(); //Each shape has multiple indices @@ -164,7 +164,7 @@ namespace MWRender{ } - if(normals.find(verIndex) == normals.end()) + /*if(normals.find(verIndex) == normals.end()) { Ogre::Vector3 absNormalsPos = vecRot * allnormals[verIndex]; absNormalsPos = absNormalsPos * boneinfo.weights[j].weight; @@ -186,7 +186,7 @@ namespace MWRender{ *(addr+1) = absNormalsPos.y; *(addr+2) = absNormalsPos.z; - } + }*/ } } @@ -254,7 +254,7 @@ namespace MWRender{ *(addr+1) = current.y; *(addr + 2) = current.z; - } + }/* for(int i = 0; i < allnormals.size(); i++){ Ogre::Vector3 current =rotmult * allnormals[i]; Ogre::Real* addr = pRealNormal + i * 3; @@ -262,11 +262,11 @@ namespace MWRender{ *(addr+1) = current.y; *(addr + 2) = current.z; - } + }*/ } vbuf->unlock(); - vbufNormal->unlock(); + //vbufNormal->unlock(); } } diff --git a/apps/openmw/mwrender/npcanimation.cpp b/apps/openmw/mwrender/npcanimation.cpp index c5c5c3ff5..31183d076 100644 --- a/apps/openmw/mwrender/npcanimation.cpp +++ b/apps/openmw/mwrender/npcanimation.cpp @@ -262,7 +262,7 @@ void NpcAnimation::runAnimation(float timepassed){ // handleAnimationTransforms(base); //handleAnimationTransforms(hand); // - /*std::vector*>::iterator shapepartsiter = shapeparts.begin(); + std::vector*>::iterator shapepartsiter = shapeparts.begin(); std::vector::iterator entitypartsiter = entityparts.begin(); //int i = 0; while(shapepartsiter != shapeparts.end()) @@ -277,7 +277,7 @@ void NpcAnimation::runAnimation(float timepassed){ //std::cout << "Shape part size" << shapes->size() << "\n"; shapepartsiter++; entitypartsiter++; - }*/ + } } } From 762727308e51fd7fad30dcd1dd905aedb405eaee Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Mon, 2 Jan 2012 23:06:10 -0500 Subject: [PATCH 088/104] Hardware skinning working (YESgit add components --allgit add components --allgit add components --allgit add components --allgit add components --allgit add components --allgit add components --allgit add components --allgit add components --allgit add components --allgit add components --all) --- apps/openmw/mwrender/npcanimation.cpp | 12 ++++++++++++ components/nifogre/ogre_nif_loader.cpp | 10 ++++++++++ 2 files changed, 22 insertions(+) diff --git a/apps/openmw/mwrender/npcanimation.cpp b/apps/openmw/mwrender/npcanimation.cpp index 31183d076..9466fd9ab 100644 --- a/apps/openmw/mwrender/npcanimation.cpp +++ b/apps/openmw/mwrender/npcanimation.cpp @@ -271,6 +271,18 @@ void NpcAnimation::runAnimation(float timepassed){ //insert-> //insert->detachObject(hand->getName()); Ogre::Entity* theentity = *entitypartsiter; + /* + Pass* pass = theentity->getSubEntity(0)->getMaterial()->getBestTechnique()->getPass(0); + if (pass->hasVertexProgram() && pass->getVertexProgram()->isSkeletalAnimationIncluded()) + std::cout << "It's hardware\n"; + else + std::cout << "It's software\n";*/ + //std::cout << "Techniques:" << theentity->getSubEntity(0)->getMaterial()->getNumTechniques() << "\n"; + /*if (pass->hasVertexProgram())// && pass->getVertexProgram()->isSkeletalAnimationIncluded()) value = "Hardware" + std::cout << "Its hardware\n"; + else + std::cout << "Its software\n";*/ + // handleAnimationTransforms(theentity); handleShapes(shapes, theentity, theentity->getSkeleton()); //insert->attachObject(hand); diff --git a/components/nifogre/ogre_nif_loader.cpp b/components/nifogre/ogre_nif_loader.cpp index a19f5df89..4cfbc3e7f 100644 --- a/components/nifogre/ogre_nif_loader.cpp +++ b/components/nifogre/ogre_nif_loader.cpp @@ -217,6 +217,14 @@ void NIFLoader::createMaterial(const String &name, // will automatically be loaded when needed. If not (such as for // internal NIF textures that we might support later), we should // already have inserted a manual loader for the texture. + if(!mSkel.isNull()){ + material->removeAllTechniques(); + + Ogre::Technique* tech = material->createTechnique(); + //tech->setSchemeName("blahblah"); + Pass* pass = tech->createPass(); + pass->setVertexProgram("Ogre/HardwareSkinningFourWeights"); + } if (!texName.empty()) { Pass *pass = material->getTechnique(0)->getPass(0); @@ -276,6 +284,8 @@ void NIFLoader::createMaterial(const String &name, material->setSpecular(specular.array[0], specular.array[1], specular.array[2], alpha); material->setSelfIllumination(emissive.array[0], emissive.array[1], emissive.array[2]); material->setShininess(glossiness); + + } // Takes a name and adds a unique part to it. This is just used to From 1d2e77d9474c886c8d24dd2b69d89daba079aa74 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Wed, 4 Jan 2012 19:47:06 -0500 Subject: [PATCH 089/104] Turning off hardware skinning --- apps/openmw/mwrender/actors.hpp | 1 + apps/openmw/mwrender/animation.cpp | 5 +++++ apps/openmw/mwrender/animation.hpp | 6 ++++-- apps/openmw/mwrender/npcanimation.cpp | 10 ++++++++++ apps/openmw/mwworld/physicssystem.cpp | 6 ++++++ apps/openmw/mwworld/world.cpp | 6 ++++++ apps/openmw/mwworld/world.hpp | 2 ++ 7 files changed, 34 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwrender/actors.hpp b/apps/openmw/mwrender/actors.hpp index be6486fd7..93ec07f98 100644 --- a/apps/openmw/mwrender/actors.hpp +++ b/apps/openmw/mwrender/actors.hpp @@ -16,6 +16,7 @@ #include "../mwworld/environment.hpp" #include "npcanimation.hpp" #include "creatureanimation.hpp" +#include namespace MWRender{ class Actors{ diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index bea0873b7..b272980c7 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -410,6 +410,11 @@ namespace MWRender{ bone->setPosition(t); if(bQuats) bone->setOrientation(r); + + if(iter == transformations->begin()){ + trans = bone->_getDerivedPosition(); + rotate = bone->_getDerivedOrientation(); + } skel->getManualBonesDirty(); skel->_updateTransforms(); skel->_notifyManualBonesDirty(); diff --git a/apps/openmw/mwrender/animation.hpp b/apps/openmw/mwrender/animation.hpp index 65f872e0a..9c240f7a6 100644 --- a/apps/openmw/mwrender/animation.hpp +++ b/apps/openmw/mwrender/animation.hpp @@ -8,6 +8,7 @@ #include "../mwworld/environment.hpp" #include #include +#include namespace MWRender{ @@ -15,9 +16,12 @@ class Animation{ protected: + OEngine::Physic::PhysicEngine* engine; OEngine::Render::OgreRenderer &mRend; MWWorld::Environment& mEnvironment; static std::map mUniqueIDs; + Ogre::Quaternion rotate; + Ogre::Vector3 trans; std::vector* > shapeparts; //All the NiTriShape data that we need for animating an npc float time; @@ -38,8 +42,6 @@ class Animation{ std::vector* shapes; //All the NiTriShapeData for this creature std::vector entityparts; - - std::vector* transformations; std::map textmappings; diff --git a/apps/openmw/mwrender/npcanimation.cpp b/apps/openmw/mwrender/npcanimation.cpp index 9466fd9ab..4630f0d3b 100644 --- a/apps/openmw/mwrender/npcanimation.cpp +++ b/apps/openmw/mwrender/npcanimation.cpp @@ -259,6 +259,16 @@ void NpcAnimation::runAnimation(float timepassed){ } handleAnimationTransforms(); + //mEnvironment.mWorld-> + /*if(base->hasSkeleton()) + { + + Ogre::Quaternion boneQuat = rotate; + Ogre::Vector3 boneTrans = trans; + mEnvironment.mWorld->setObjectPhysicsPosition(insert->getName(), boneTrans + insert->getPosition()); + mEnvironment.mWorld->setObjectPhysicsRotation(insert->getName(), boneQuat * insert->getOrientation()); + + }*/ // handleAnimationTransforms(base); //handleAnimationTransforms(hand); // diff --git a/apps/openmw/mwworld/physicssystem.cpp b/apps/openmw/mwworld/physicssystem.cpp index cfe5edab4..e74e201f5 100644 --- a/apps/openmw/mwworld/physicssystem.cpp +++ b/apps/openmw/mwworld/physicssystem.cpp @@ -145,6 +145,12 @@ namespace MWWorld void PhysicsSystem::rotateObject (const std::string& handle, const Ogre::Quaternion& rotation) { + if (OEngine::Physic::PhysicActor* act = mEngine->getCharacter(handle)) + { + // TODO very dirty hack to avoid crash during setup -> needs cleaning up to allow + // start positions others than 0, 0, 0 + act->setRotation(btQuaternion(rotation.x, rotation.y, rotation.z, rotation.w)); + } } void PhysicsSystem::scaleObject (const std::string& handle, float scale) diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index a4f167103..2232e8a1d 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -685,4 +685,10 @@ namespace MWWorld { mRendering.skipAnimation (ptr); } + void World::setObjectPhysicsRotation(const std::string& handle, Ogre::Quaternion quat){ + mPhysics->rotateObject(handle, quat); + } + void World::setObjectPhysicsPosition(const std::string& handle, Ogre::Vector3 vec){ + mPhysics->moveObject(handle, vec); + } } diff --git a/apps/openmw/mwworld/world.hpp b/apps/openmw/mwworld/world.hpp index 2c7b43280..235d203a6 100644 --- a/apps/openmw/mwworld/world.hpp +++ b/apps/openmw/mwworld/world.hpp @@ -218,6 +218,8 @@ namespace MWWorld void skipAnimation (const MWWorld::Ptr& ptr); ///< Skip the animation for the given MW-reference for one frame. Calls to this function for /// references that are currently not in the rendered scene should be ignored. + void setObjectPhysicsRotation(const std::string& handle,Ogre::Quaternion quat); + void setObjectPhysicsPosition(const std::string& handle,Ogre::Vector3 vector); }; } From 45c57721ffb993a19294326a36c25b64c2a985ff Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Wed, 4 Jan 2012 20:30:06 -0500 Subject: [PATCH 090/104] Turning off hardware skinning2 --- apps/openmw/mwrender/animation.cpp | 4 ++-- apps/openmw/mwrender/npcanimation.cpp | 2 +- components/nifogre/ogre_nif_loader.cpp | 3 ++- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index b272980c7..e83cd44fd 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -412,8 +412,8 @@ namespace MWRender{ bone->setOrientation(r); if(iter == transformations->begin()){ - trans = bone->_getDerivedPosition(); - rotate = bone->_getDerivedOrientation(); + trans = bone->getPosition(); + rotate = bone->getOrientation(); } skel->getManualBonesDirty(); skel->_updateTransforms(); diff --git a/apps/openmw/mwrender/npcanimation.cpp b/apps/openmw/mwrender/npcanimation.cpp index 4630f0d3b..442ee4c81 100644 --- a/apps/openmw/mwrender/npcanimation.cpp +++ b/apps/openmw/mwrender/npcanimation.cpp @@ -266,7 +266,7 @@ void NpcAnimation::runAnimation(float timepassed){ Ogre::Quaternion boneQuat = rotate; Ogre::Vector3 boneTrans = trans; mEnvironment.mWorld->setObjectPhysicsPosition(insert->getName(), boneTrans + insert->getPosition()); - mEnvironment.mWorld->setObjectPhysicsRotation(insert->getName(), boneQuat * insert->getOrientation()); + //mEnvironment.mWorld->setObjectPhysicsRotation(insert->getName(), boneQuat * insert->getOrientation()); }*/ // handleAnimationTransforms(base); diff --git a/components/nifogre/ogre_nif_loader.cpp b/components/nifogre/ogre_nif_loader.cpp index 4cfbc3e7f..f6c028854 100644 --- a/components/nifogre/ogre_nif_loader.cpp +++ b/components/nifogre/ogre_nif_loader.cpp @@ -217,6 +217,7 @@ void NIFLoader::createMaterial(const String &name, // will automatically be loaded when needed. If not (such as for // internal NIF textures that we might support later), we should // already have inserted a manual loader for the texture. + /* if(!mSkel.isNull()){ material->removeAllTechniques(); @@ -224,7 +225,7 @@ void NIFLoader::createMaterial(const String &name, //tech->setSchemeName("blahblah"); Pass* pass = tech->createPass(); pass->setVertexProgram("Ogre/HardwareSkinningFourWeights"); - } + }*/ if (!texName.empty()) { Pass *pass = material->getTechnique(0)->getPass(0); From c2fa82326dd30f331200d9b6f7da66ac20940e02 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Wed, 4 Jan 2012 23:48:25 -0500 Subject: [PATCH 091/104] Animation with physics attempt --- apps/openmw/mwrender/animation.cpp | 5 +---- apps/openmw/mwrender/animation.hpp | 5 +++-- apps/openmw/mwrender/npcanimation.cpp | 10 +++++++++- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index e83cd44fd..0e42729a9 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -411,10 +411,7 @@ namespace MWRender{ if(bQuats) bone->setOrientation(r); - if(iter == transformations->begin()){ - trans = bone->getPosition(); - rotate = bone->getOrientation(); - } + skel->getManualBonesDirty(); skel->_updateTransforms(); skel->_notifyManualBonesDirty(); diff --git a/apps/openmw/mwrender/animation.hpp b/apps/openmw/mwrender/animation.hpp index 9c240f7a6..7ec128fa9 100644 --- a/apps/openmw/mwrender/animation.hpp +++ b/apps/openmw/mwrender/animation.hpp @@ -20,8 +20,9 @@ class Animation{ OEngine::Render::OgreRenderer &mRend; MWWorld::Environment& mEnvironment; static std::map mUniqueIDs; - Ogre::Quaternion rotate; - Ogre::Vector3 trans; + + Ogre::Vector3 originalpos; + Ogre::Vector3 originalscenenode; std::vector* > shapeparts; //All the NiTriShape data that we need for animating an npc float time; diff --git a/apps/openmw/mwrender/npcanimation.cpp b/apps/openmw/mwrender/npcanimation.cpp index 442ee4c81..1e324acc7 100644 --- a/apps/openmw/mwrender/npcanimation.cpp +++ b/apps/openmw/mwrender/npcanimation.cpp @@ -214,6 +214,8 @@ NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, MWWorld::Environment& _env,O insertFreePart("meshes\\" + feet->model,"><", insert); insertFreePart("meshes\\" + feet->model,">:", insert); } + originalpos = insert->_getWorldAABB().getCenter(); + originalscenenode = insert->getPosition(); } Ogre::Entity* NpcAnimation::insertBoundedPart(const std::string &mesh, std::string bonename){ @@ -259,7 +261,13 @@ void NpcAnimation::runAnimation(float timepassed){ } handleAnimationTransforms(); - //mEnvironment.mWorld-> + Ogre::Vector3 current = insert->_getWorldAABB().getCenter(); + + //This is the attempt at npc physics + //mEnvironment.mWorld->setObjectPhysicsPosition(insert->getName(), current); + + + /*if(base->hasSkeleton()) { From 595d0b119252b1c52f47357508ed53c91c0aa026 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Thu, 5 Jan 2012 21:45:17 -0500 Subject: [PATCH 092/104] Cleanup; warnings --- apps/openmw/mwrender/animation.cpp | 27 +- apps/openmw/mwrender/animation.hpp | 13 +- apps/openmw/mwrender/creatureanimation.cpp | 9 +- apps/openmw/mwrender/npcanimation.cpp | 46 +-- apps/openmw/mwrender/npcanimation.hpp | 2 +- components/nifogre/ogre_nif_loader.cpp | 317 ++------------------- components/nifogre/ogre_nif_loader.hpp | 3 +- 7 files changed, 53 insertions(+), 364 deletions(-) diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index 0e42729a9..2b22ea589 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -77,7 +77,7 @@ namespace MWRender{ } if(time >= copy.morph.getStartTime() && time <= copy.morph.getStopTime()){ float x; - for (int i = 0; i < copy.morph.getAdditionalVertices().size(); i++){ + for (unsigned int i = 0; i < copy.morph.getAdditionalVertices().size(); i++){ int j = 0; if(shapeIndexI[shapeNumber].size() <= i) shapeIndexI[shapeNumber].push_back(0); @@ -93,7 +93,7 @@ namespace MWRender{ if ( t > 1 ) t = 1; if( t != 0 && initialVertices.size() == copy.morph.getAdditionalVertices()[i].size()) { - for (int v = 0; v < initialVertices.size(); v++){ + for (unsigned int v = 0; v < initialVertices.size(); v++){ initialVertices[v] += ((copy.morph.getAdditionalVertices()[i])[v]) * t; } } @@ -103,17 +103,7 @@ namespace MWRender{ } - //After everything, write everything out - /* - for(int i = 0; i < initialVertices.size(); i++){ - Ogre::Vector3 current = initialVertices[i]; - Ogre::Real* addr = pReal + i * 3; - *addr = current.x; - *(addr+1) = current.y; - *(addr + 2) = current.z; - - }*/ allvertices = initialVertices; } shapeNumber++; @@ -124,14 +114,14 @@ namespace MWRender{ if(boneinfovector.size() > 0){ - for (int i = 0; i < boneinfovector.size(); i++) + for (unsigned int i = 0; i < boneinfovector.size(); i++) { Nif::NiSkinData::BoneInfoCopy boneinfo = boneinfovector[i]; if(skel->hasBone(boneinfo.bonename)){ Ogre::Bone *bonePtr = skel->getBone(boneinfo.bonename); Ogre::Vector3 vecPos = bonePtr->_getDerivedPosition() + bonePtr->_getDerivedOrientation() * boneinfo.trafo.trans; Ogre::Quaternion vecRot = bonePtr->_getDerivedOrientation() * boneinfo.trafo.rotation; - //std::cout << "Bone" << bonePtr->getName() << "\n"; + for (unsigned int j=0; j < boneinfo.weights.size(); j++) { unsigned int verIndex = boneinfo.weights[j].vertex; @@ -146,7 +136,6 @@ namespace MWRender{ *(addr+2) = absVertPos.z; - //std::cout << "Vertex" << vertices[verIndex] << "\n"; } else { @@ -247,7 +236,7 @@ namespace MWRender{ // Computes C = B + AxC*scale // final_vector = old_vector + old_rotation*new_vector*old_scale/ - for(int i = 0; i < allvertices.size(); i++){ + for(unsigned int i = 0; i < allvertices.size(); i++){ Ogre::Vector3 current = transmult + rotmult * allvertices[i]; Ogre::Real* addr = pReal + i * 3; *addr = current.x; @@ -332,7 +321,7 @@ namespace MWRender{ Ogre::Bone* b = skel->getRootBone(); - b->setOrientation(.3,.3,.3,.3); //This is a trick + b->setOrientation(Ogre::Real(.3),Ogre::Real(.3),Ogre::Real(.3), Ogre::Real(.3)); //This is a trick skel->getManualBonesDirty(); skel->_updateTransforms(); skel->_notifyManualBonesDirty(); @@ -341,11 +330,11 @@ namespace MWRender{ base->_updateAnimation(); base->_notifyMoved(); - for(int i = 0; i < entityparts.size(); i++){ + for(unsigned int i = 0; i < entityparts.size(); i++){ Ogre::SkeletonInstance* skel = entityparts[i]->getSkeleton(); Ogre::Bone* b = skel->getRootBone(); - b->setOrientation(.3,.3,.3,.3); //This is a trick + b->setOrientation(Ogre::Real(.3),Ogre::Real(.3),Ogre::Real(.3), Ogre::Real(.3));//This is a trick skel->getManualBonesDirty(); skel->_updateTransforms(); skel->_notifyManualBonesDirty(); diff --git a/apps/openmw/mwrender/animation.hpp b/apps/openmw/mwrender/animation.hpp index 7ec128fa9..f81f38094 100644 --- a/apps/openmw/mwrender/animation.hpp +++ b/apps/openmw/mwrender/animation.hpp @@ -15,32 +15,29 @@ namespace MWRender{ class Animation{ protected: - - OEngine::Physic::PhysicEngine* engine; + Ogre::SceneNode* insert; OEngine::Render::OgreRenderer &mRend; MWWorld::Environment& mEnvironment; static std::map mUniqueIDs; - Ogre::Vector3 originalpos; - Ogre::Vector3 originalscenenode; + std::vector* > shapeparts; //All the NiTriShape data that we need for animating an npc float time; float startTime; float stopTime; - bool loop; int animate; //Represents a rotation index for each bone std::vectorrindexI; //Represents a translation index for each bone std::vectortindexI; - //Only shapes with morphing data will need a shape number + //Only shapes with morphing data will use a shape number int shapeNumber; std::vector > shapeIndexI; //Ogre::SkeletonInstance* skel; - std::vector* shapes; //All the NiTriShapeData for this creature + std::vector* shapes; //All the NiTriShapeData for a creature std::vector entityparts; @@ -53,7 +50,7 @@ class Animation{ std::string getUniqueID(std::string mesh); public: - Animation(MWWorld::Environment& _env, OEngine::Render::OgreRenderer& _rend): mRend(_rend), mEnvironment(_env), loop(false), animate(0){}; + Animation(MWWorld::Environment& _env, OEngine::Render::OgreRenderer& _rend): mRend(_rend), mEnvironment(_env), animate(0){}; virtual void runAnimation(float timepassed) = 0; void startScript(std::string groupname, int mode, int loops); void stopScript(); diff --git a/apps/openmw/mwrender/creatureanimation.cpp b/apps/openmw/mwrender/creatureanimation.cpp index fe717a9f3..3d4e93d7b 100644 --- a/apps/openmw/mwrender/creatureanimation.cpp +++ b/apps/openmw/mwrender/creatureanimation.cpp @@ -10,8 +10,7 @@ CreatureAnimation::~CreatureAnimation(){ } CreatureAnimation::CreatureAnimation(const MWWorld::Ptr& ptr, MWWorld::Environment& _env,OEngine::Render::OgreRenderer& _rend): Animation(_env,_rend){ - Ogre::SceneNode* insert = ptr.getRefData().getBaseNode(); - assert(insert); + insert = ptr.getRefData().getBaseNode(); ESMS::LiveCellRef *ref = ptr.get(); @@ -27,14 +26,10 @@ CreatureAnimation::CreatureAnimation(const MWWorld::Ptr& ptr, MWWorld::Environme for(int init = 0; init < transformations->size(); init++){ rindexI.push_back(0); - //a.rindexJ.push_back(0); tindexI.push_back(0); - //a.tindexJ.push_back(0); } - loop = false; stopTime = transformations->begin()->getStopTime(); - //a.startTime = NIFLoader::getSingletonPtr()->getTime(item.smodel, "IdleSneak: Start"); - startTime = transformations->begin()->getStartTime(); + startTime = transformations->begin()->getStartTime(); shapes = (NIFLoader::getSingletonPtr())->getShapes(meshZero); } insert->attachObject(base); diff --git a/apps/openmw/mwrender/npcanimation.cpp b/apps/openmw/mwrender/npcanimation.cpp index 1e324acc7..1af4d7596 100644 --- a/apps/openmw/mwrender/npcanimation.cpp +++ b/apps/openmw/mwrender/npcanimation.cpp @@ -13,9 +13,6 @@ NpcAnimation::~NpcAnimation(){ NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, MWWorld::Environment& _env,OEngine::Render::OgreRenderer& _rend): Animation(_env,_rend){ ESMS::LiveCellRef *ref = ptr.get(); - //assert (ref->base != NULL); - - //insertBegin(ptr, true, true); //Part selection on last character of the file string // " Tri Chest @@ -46,13 +43,13 @@ NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, MWWorld::Environment& _env,O char secondtolast = bodyRaceID.at(bodyRaceID.length() - 2); bool female = tolower(secondtolast) == 'f'; bool beast = bodyRaceID == "b_n_khajiit_m_" || bodyRaceID == "b_n_khajiit_f_" || bodyRaceID == "b_n_argonian_m_" || bodyRaceID == "b_n_argonian_f_"; - std::cout << "Race: " << ref->base->race ; + /*std::cout << "Race: " << ref->base->race ; if(female){ std::cout << " Sex: Female" << " Height: " << race->data.height.female << "\n"; } else{ std::cout << " Sex: Male" << " Height: " << race->data.height.male << "\n"; - } + }*/ @@ -72,17 +69,13 @@ NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, MWWorld::Environment& _env,O if(transformations = (NIFLoader::getSingletonPtr())->getAnim(smodel)){ - for(int init = 0; init < transformations->size(); init++){ + for(unsigned int init = 0; init < transformations->size(); init++){ rindexI.push_back(0); - //a.rindexJ.push_back(0); tindexI.push_back(0); - //a.tindexJ.push_back(0); } - loop = false; stopTime = transformations->begin()->getStopTime(); - //a.startTime = NIFLoader::getSingletonPtr()->getTime(item.smodel, "IdleSneak: Start"); - startTime = transformations->begin()->getStartTime(); + startTime = transformations->begin()->getStartTime(); } insert->attachObject(base); @@ -114,7 +107,7 @@ NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, MWWorld::Environment& _env,O forearml = mEnvironment.mWorld->getStore().bodyParts.search ("b_n_argonian_m_forearm"); //We need two if(!handl) handl = mEnvironment.mWorld->getStore().bodyParts.search (bodyRaceID + "hands"); - //const ESM::BodyPart* claviclel = environment.mWorld->getStore().bodyParts.search (bodyRaceID + "clavicle"); + //const ESM::BodyPart* claviclel = environment.mWorld->getStore().bodyParts.search (bodyRaceID + "clavicle"); //const ESM::BodyPart* clavicler = claviclel; const ESM::BodyPart* handr = handl; const ESM::BodyPart* forearmr = forearml; @@ -214,8 +207,8 @@ NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, MWWorld::Environment& _env,O insertFreePart("meshes\\" + feet->model,"><", insert); insertFreePart("meshes\\" + feet->model,">:", insert); } - originalpos = insert->_getWorldAABB().getCenter(); - originalscenenode = insert->getPosition(); + //originalpos = insert->_getWorldAABB().getCenter(); + //originalscenenode = insert->getPosition(); } Ogre::Entity* NpcAnimation::insertBoundedPart(const std::string &mesh, std::string bonename){ @@ -243,17 +236,17 @@ void NpcAnimation::insertFreePart(const std::string &mesh, const std::string suf void NpcAnimation::runAnimation(float timepassed){ - //Add the amount of time passed to time + //1. Add the amount of time passed to time - //Handle the animation transforms dependent on time + //2. Handle the animation transforms dependent on time - //Handle the shapes dependent on animation transforms + //3. Handle the shapes dependent on animation transforms if(animate > 0){ time += timepassed; if(time > stopTime){ animate--; - //std::cout << "Stopping the animation\n"; + if(animate == 0) time = stopTime; else @@ -277,17 +270,12 @@ void NpcAnimation::runAnimation(float timepassed){ //mEnvironment.mWorld->setObjectPhysicsRotation(insert->getName(), boneQuat * insert->getOrientation()); }*/ - // handleAnimationTransforms(base); - //handleAnimationTransforms(hand); - // + std::vector*>::iterator shapepartsiter = shapeparts.begin(); std::vector::iterator entitypartsiter = entityparts.begin(); - //int i = 0; while(shapepartsiter != shapeparts.end()) { std::vector* shapes = *shapepartsiter; - //insert-> - //insert->detachObject(hand->getName()); Ogre::Entity* theentity = *entitypartsiter; /* Pass* pass = theentity->getSubEntity(0)->getMaterial()->getBestTechnique()->getPass(0); @@ -295,16 +283,8 @@ void NpcAnimation::runAnimation(float timepassed){ std::cout << "It's hardware\n"; else std::cout << "It's software\n";*/ - //std::cout << "Techniques:" << theentity->getSubEntity(0)->getMaterial()->getNumTechniques() << "\n"; - /*if (pass->hasVertexProgram())// && pass->getVertexProgram()->isSkeletalAnimationIncluded()) value = "Hardware" - std::cout << "Its hardware\n"; - else - std::cout << "Its software\n";*/ - - // handleAnimationTransforms(theentity); + handleShapes(shapes, theentity, theentity->getSkeleton()); - //insert->attachObject(hand); - //std::cout << "Shape part size" << shapes->size() << "\n"; shapepartsiter++; entitypartsiter++; } diff --git a/apps/openmw/mwrender/npcanimation.hpp b/apps/openmw/mwrender/npcanimation.hpp index edc0648ef..e8ce735f7 100644 --- a/apps/openmw/mwrender/npcanimation.hpp +++ b/apps/openmw/mwrender/npcanimation.hpp @@ -16,7 +16,7 @@ namespace MWRender{ class NpcAnimation: public Animation{ - Ogre::SceneNode* insert; + public: NpcAnimation(const MWWorld::Ptr& ptr, MWWorld::Environment& _env, OEngine::Render::OgreRenderer& _rend); diff --git a/components/nifogre/ogre_nif_loader.cpp b/components/nifogre/ogre_nif_loader.cpp index f6c028854..48edde4f3 100644 --- a/components/nifogre/ogre_nif_loader.cpp +++ b/components/nifogre/ogre_nif_loader.cpp @@ -212,13 +212,9 @@ void NIFLoader::createMaterial(const String &name, { MaterialPtr material = MaterialManager::getSingleton().create(name, resourceGroup); - // This assigns the texture to this material. If the texture name is - // a file name, and this file exists (in a resource directory), it - // will automatically be loaded when needed. If not (such as for - // internal NIF textures that we might support later), we should - // already have inserted a manual loader for the texture. - /* - if(!mSkel.isNull()){ + + //Hardware Skinning code, textures may be the wrong color if enabled + /*if(!mSkel.isNull()){ material->removeAllTechniques(); Ogre::Technique* tech = material->createTechnique(); @@ -226,6 +222,14 @@ void NIFLoader::createMaterial(const String &name, Pass* pass = tech->createPass(); pass->setVertexProgram("Ogre/HardwareSkinningFourWeights"); }*/ + + // This assigns the texture to this material. If the texture name is + // a file name, and this file exists (in a resource directory), it + // will automatically be loaded when needed. If not (such as for + // internal NIF textures that we might support later), we should + // already have inserted a manual loader for the texture. + + if (!texName.empty()) { Pass *pass = material->getTechnique(0)->getPass(0); @@ -359,22 +363,16 @@ void NIFLoader::createOgreSubMesh(NiTriShape *shape, const String &material, std int index = i * 3; const float *pos = data->vertices.ptr + index; Ogre::Vector3 original = Ogre::Vector3(*pos ,*(pos+1), *(pos+2)); - //std::cout << "Original: " << original; - //rstd::cout << "vectorfirst" << original << "\n"; original = mTransform * original; mBoundingBox.merge(original); - //std::cout <<" New: " << original << "\n"; datamod[index] = original.x; datamod[index+1] = original.y; datamod[index+2] = original.z; - //std::cout << "vector " << original << "\n"; - //std::cout << "datamod: " << datamod[index+1] << "datamod2: " << *(pos+1) << "\n"; } vbuf->writeData(0, vbuf->getSizeInBytes(), datamod, false); } else { - //std::cout << "X " << data->vertices.ptr[0] << "Y " << data->vertices.ptr[1] << "Z " << data->vertices.ptr[2] << "NIFLOADER" << "\n"; vbuf->writeData(0, vbuf->getSizeInBytes(), data->vertices.ptr, false); } @@ -382,7 +380,6 @@ void NIFLoader::createOgreSubMesh(NiTriShape *shape, const String &material, std VertexBufferBinding* bind = sub->vertexData->vertexBufferBinding; bind->setBinding(nextBuf++, vbuf); - // Vertex normals if (data->normals.length) { decl->addElement(nextBuf, 0, VET_FLOAT3, VES_NORMAL); @@ -398,14 +395,14 @@ void NIFLoader::createOgreSubMesh(NiTriShape *shape, const String &material, std float *datamod = new float[data->normals.length]; for(int i = 0; i < numVerts; i++) { - int index = i * 3; - const float *pos = data->normals.ptr + index; + int index = i * 3; + const float *pos = data->normals.ptr + index; Ogre::Vector3 original = Ogre::Vector3(*pos ,*(pos+1), *(pos+2)); original = rotation * original; - if (mNormaliseNormals) - { - original.normalise(); - } + if (mNormaliseNormals) + { + original.normalise(); + } datamod[index] = original.x; @@ -445,8 +442,6 @@ void NIFLoader::createOgreSubMesh(NiTriShape *shape, const String &material, std if (data->uvlist.length) { - - decl->addElement(nextBuf, 0, VET_FLOAT2, VES_TEXTURE_COORDINATES); vbuf = HardwareBufferManager::getSingleton().createVertexBuffer( VertexElement::getTypeSize(VET_FLOAT2), @@ -456,7 +451,7 @@ void NIFLoader::createOgreSubMesh(NiTriShape *shape, const String &material, std { float *datamod = new float[data->uvlist.length]; - for(int i = 0; i < data->uvlist.length; i+=2){ + for(unsigned int i = 0; i < data->uvlist.length; i+=2){ float x = *(data->uvlist.ptr + i); float y = *(data->uvlist.ptr + i + 1); @@ -739,7 +734,6 @@ void NIFLoader::handleNiTriShape(NiTriShape *shape, int flags, BoundsFinder &bou Nif::NiTriShapeCopy copy = shape->clone(); if(!shape->controller.empty()) { - //Nif::NiGeomMorpherController* cont = dynamic_cast (shape->controller.getPtr()); Nif::Controller* cont = shape->controller.getPtr(); if(cont->recType == RC_NiGeomMorpherController) { @@ -747,25 +741,17 @@ void NIFLoader::handleNiTriShape(NiTriShape *shape, int flags, BoundsFinder &bou copy.morph = morph->data.get(); copy.morph.setStartTime(morph->timeStart); copy.morph.setStopTime(morph->timeStop); - //std::cout << "Size" << morph->data->getInitialVertices().size() << "\n"; - } - //std::cout << "We have a controller"; } //use niskindata for the position of vertices. if (!shape->skin.empty()) { - //std::cout << "Skin is not empty\n"; //Bone assignments are stored in submeshes, so we don't need to copy them - //std::string triname - //std::vector vertices; - //std::vector normals; - //std::vector boneinfo; - // vector that stores if the position if a vertex is absolute + // vector that stores if the position of a vertex is absolute std::vector vertexPosAbsolut(numVerts,false); std::vector vertexPosOriginal(numVerts, Ogre::Vector3::ZERO); std::vector vertexNormalOriginal(numVerts, Ogre::Vector3::ZERO); @@ -967,8 +953,6 @@ void NIFLoader::calculateTransform() void NIFLoader::handleNode(Nif::Node *node, int flags, const Transformation *trafo, BoundsFinder &bounds, Ogre::Bone *parentBone, std::vector boneSequence) { - //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; @@ -1000,33 +984,23 @@ void NIFLoader::handleNode(Nif::Node *node, int flags, if (e->recType == RC_NiTextKeyExtraData){ Nif::NiTextKeyExtraData* extra = dynamic_cast (e); - std::vector::iterator textiter = extra->list.begin(); - //std::ofstream File("Indices" + name + ".txt"); - - //std::string sample = "uy"; std::string cut = ""; - for(int i = 0; i < name.length(); i++) + for(unsigned int i = 0; i < name.length(); i++) { if(!(name.at(i) == '\\' || name.at(i) == '/' || name.at(i) == '>' || name.at(i) == '<' || name.at(i) == '?' || name.at(i) == '*' || name.at(i) == '|' || name.at(i) == ':' || name.at(i) == '"')) { cut += name.at(i); } } - //std::cout << "End" << end; std::cout << "Outputting " << cut << "\n"; std::ofstream file(("Indices" + cut + ".txt").c_str()); - /*if(File.is_open()) - std::cout << "We could open\n"; - else - std::cout << "We could not\n";*/ - for(; textiter != extra->list.end(); textiter++) + for(std::vector::iterator textiter = extra->list.begin(); textiter != extra->list.end(); textiter++) { - //if(textiter->text.toString().find("Torch") < textiter->text.toString().length()) - //std::cout << "Time: " << textiter->time << " " << textiter->text.toString() << "\n"; + std::string text = textiter->text.toString(); replace(text.begin(), text.end(), '\n', '/'); @@ -1050,20 +1024,13 @@ void NIFLoader::handleNode(Nif::Node *node, int flags, { mSkel = SkeletonManager::getSingleton().create(getSkeletonName(), resourceGroup, true); - - /*if (node->extra->recType == RC_NiTextKeyExtraData ) - { - //TODO: Get animation names - std::cout << node->name.toString() << " is root bone and has textkeyextradata!\n"; - }*/ } if (!mSkel.isNull()) //if there is a skeleton { std::string name = node->name.toString(); boneSequence.push_back(name); - //if (isBeast && isChest) - // std::cout << "NAME: " << name << "\n"; + // Quick-n-dirty workaround for the fact that several // bones may have the same name. if(!mSkel->hasBone(name)) @@ -1281,8 +1248,6 @@ void NIFLoader::loadResource(Resource *resource) mesh->_setBoundingSphereRadius(bounds.getRadius()); } if(hasAnim && addAnim){ - //std::cout << "Lower" << lowername << "\n"; - //std::cout << "Adding the animations\n"; allanimmap[name] = allanim; alltextmappings[name] = textmappings; } @@ -1300,7 +1265,6 @@ void NIFLoader::loadResource(Resource *resource) { mesh->_notifySkeleton(mSkel); } - flip = false; } void NIFLoader::addInMesh(Ogre::Mesh* input){ @@ -1364,242 +1328,7 @@ float NIFLoader::getTime(std::string filename, std::string text){ return -10000000.0; } -/* -void NIFLoader::insertMeshInsideBase(Ogre::Mesh* input) -{ - /*if(addin) - { - std::cout << "InsideBase:" << addin->getName() << "\n"; - }*/ -/* - if(input) - { - std::vector shapes = NIFLoader::getSingletonPtr()->getShapes(input->getName()); - for(int i = 0; i < shapes.size(); i++){ - - //std::cout << "Shapes" << shapes[i].sname; - - Ogre::SubMesh* sub = input->getSubMesh(shapes[i].sname); - Ogre::SubMesh* subNew = mesh->createSubMesh(shapes[i].sname); - - - int nextBuf = 0; - - - //----------------------------------------VERTICES---------------------------------------- - int numVerts = shapes[i].vertices.size(); - subNew->vertexData = new VertexData(); - subNew->vertexData->vertexCount = numVerts; - subNew->useSharedVertices = false; - - //-----------------------------------------POSITIONS--------------------------------------- - - - VertexDeclaration *decl = subNew->vertexData->vertexDeclaration; - const VertexElement* position = - sub->vertexData->vertexDeclaration->findElementBySemantic(Ogre::VES_POSITION); - Ogre::HardwareVertexBufferSharedPtr vbuf; - HardwareVertexBufferSharedPtr newvbuf; - float* pRealNormal = new float[numVerts * 3]; - VertexBufferBinding* bind; - - - - - - - //std::cout << "X " << pReal[0] << "Y " << pReal[1] << "Z" << pReal[2] << "\n"; - float* pReal = new float[numVerts * 3]; - - std::map vertices; - std::map normals; - std::vector boneinfovector = shapes[i].boneinfo; - - //std::cout << "Name " << copy.sname << "\n"; - - if(boneinfovector.size() > 0){ - - - for (int j = 0; j < boneinfovector.size(); j++) - { - Nif::NiSkinData::BoneInfoCopy boneinfo = boneinfovector[j]; - Ogre::Bone *bonePtr = mSkel->getBone(boneinfo.bonename); - Ogre::Vector3 vecPos = bonePtr->_getDerivedPosition() + bonePtr->_getDerivedOrientation() * boneinfo.trafo.trans; - Ogre::Quaternion vecRot = bonePtr->_getDerivedOrientation() * boneinfo.trafo.rotation; - //std::cout << "Bone" << bonePtr->getName() << "\n"; - for (unsigned int k=0; k< boneinfo.weights.size(); k++) - { - unsigned int verIndex = boneinfo.weights[k].vertex; - if(vertices.find(verIndex) == vertices.end()) - { - Ogre::Vector3 absVertPos = vecPos + vecRot * shapes[i].vertices[verIndex]; - vertices[verIndex] = true; - absVertPos = absVertPos * boneinfo.weights[k].weight; - Ogre::Real* addr = (pReal + 3 * verIndex); - *addr = absVertPos.x; - *(addr+1) = absVertPos.y; - *(addr+2) = absVertPos.z; - - //std::cout << "Vertex" << vertices[verIndex] << "\n"; - } - else - { - Ogre::Vector3 absVertPos = vecPos + vecRot * shapes[i].vertices[verIndex]; - absVertPos = absVertPos * boneinfo.weights[k].weight; - Ogre::Vector3 old = Ogre::Vector3(pReal + 3 * verIndex); - absVertPos = absVertPos + old; - Ogre::Real* addr = (pReal + 3 * verIndex); - *addr = absVertPos.x; - *(addr+1) = absVertPos.y; - *(addr+2) = absVertPos.z; - - } - - if(normals.find(verIndex) == normals.end()) - { - Ogre::Vector3 absNormalsPos = vecRot * shapes[i].normals[verIndex]; - absNormalsPos = absNormalsPos * boneinfo.weights[k].weight; - normals[verIndex] = true; - Ogre::Real* addr = (pRealNormal + 3 * verIndex); - *addr = absNormalsPos.x; - *(addr+1) = absNormalsPos.y; - *(addr+2) = absNormalsPos.z; - } - else{ - Ogre::Vector3 absNormalsPos = vecRot * shapes[i].normals[verIndex]; - absNormalsPos = absNormalsPos * boneinfo.weights[k].weight; - Ogre::Vector3 old = Ogre::Vector3(pRealNormal + 3 * verIndex); - absNormalsPos = absNormalsPos + old; - - Ogre::Real* addr = (pRealNormal + 3 * verIndex); - *addr = absNormalsPos.x; - *(addr+1) = absNormalsPos.y; - *(addr+2) = absNormalsPos.z; - } - - } - - /* - std::cout << "TransformRot:" << boneinfo.trafo.rotation << "TransformTrans:" << boneinfo.trafo.trans << "\n"; - std::vector weights = boneinfo.weights; - for (int j = 0; j < weights.size(); j++){ - std::cout << "Vertex: " << weights[j].vertex << " Weight: " << weights[j].weight << "\n"; - }*/ - /*} - } - - if(position){ - decl->addElement(nextBuf, 0, VET_FLOAT3, VES_POSITION); - - - - newvbuf = - HardwareBufferManager::getSingleton().createVertexBuffer( - VertexElement::getTypeSize(VET_FLOAT3), - numVerts, HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY); - - newvbuf->writeData(0, newvbuf->getSizeInBytes(), pReal, false); - - - bind = subNew->vertexData->vertexBufferBinding; - bind->setBinding(nextBuf++, newvbuf); - - - } - //----------------------------------------NORMALS------------------------------------------- - - const VertexElement* normal = - sub->vertexData->vertexDeclaration->findElementBySemantic(Ogre::VES_NORMAL); - if(normal) - { - decl->addElement(nextBuf, 0, VET_FLOAT3, VES_NORMAL); - newvbuf = HardwareBufferManager::getSingleton().createVertexBuffer( - VertexElement::getTypeSize(VET_FLOAT3), - numVerts, HardwareBuffer::HBU_DYNAMIC); - - - newvbuf->writeData(0, newvbuf->getSizeInBytes(), pRealNormal, false); - - bind->setBinding(nextBuf++, newvbuf); - } - - - //--------------------------------------COLORS-------------------------------------------- - const VertexElement* color = - sub->vertexData->vertexDeclaration->findElementBySemantic(Ogre::VES_DIFFUSE); - if(color) - { - - decl->addElement(nextBuf, 0, VET_COLOUR, VES_DIFFUSE); - - vbuf = sub->vertexData->vertexBufferBinding->getBuffer(color->getSource()); - newvbuf = vbuf; - //RGBA* pReal2 = static_cast(vbuf->lock(Ogre::HardwareBuffer::HBL_NORMAL)); - //newvbuf->writeData(0, vbuf->getSizeInBytes(), pReal2, false); - - //vbuf->unlock(); - - bind->setBinding(nextBuf++, newvbuf); - } - - //-------------------------------------TEXTURES------------------------------------------- - - const VertexElement* text = - sub->vertexData->vertexDeclaration->findElementBySemantic(Ogre::VES_TEXTURE_COORDINATES); - if(text){ - vbuf = sub->vertexData->vertexBufferBinding->getBuffer(text->getSource()); - - decl->addElement(nextBuf, 0, VET_FLOAT2, VES_TEXTURE_COORDINATES); - newvbuf = vbuf; - //float* pRealf = static_cast(vbuf->lock(Ogre::HardwareBuffer::HBL_NORMAL)); - - //std::cout << "SIze" << vbuf->getSizeInBytes(); - - // newvbuf->writeData(0, vbuf->getSizeInBytes(), pRealf, false); - //vbuf->unlock(); - bind->setBinding(nextBuf++, newvbuf); - } - - //----------------------------------INDEX DATA-------------------------------------- - int numFaces = sub->indexData->indexCount; - subNew->indexData->indexCount = numFaces; - subNew->indexData->indexStart = 0; - - HardwareIndexBufferSharedPtr ibuf = sub->indexData->indexBuffer; - HardwareIndexBufferSharedPtr ibufNew = ibuf; - - //uint16* tri = static_cast(ibuf->lock(Ogre::HardwareBuffer::HBL_NORMAL)); - //ibufNew->writeData(0, ibuf->getSizeInBytes(), tri, false); - subNew->indexData->indexBuffer = ibufNew; - //ibuf->unlock(); - - if (!sub->getMaterialName().empty()){ - subNew->setMaterialName(sub->getMaterialName()); - } - - //Ogre::SubMesh::VertexBoneAssignmentList bonelist = sub->getBoneAssignments(); - - /* - Ogre::VertexBoneAssignment assign; - assign.boneIndex = 0; - assign.vertexIndex = 0; - assign.weight = 1.0; - subNew->addBoneAssignment(assign);*/ - /* - Ogre::SubMesh::BoneAssignmentIterator boneiter = sub->getBoneAssignmentIterator(); - while(boneiter.hasMoreElements()) - { - subNew->addBoneAssignment(boneiter.current()->second); - boneiter.getNext(); - } - subNew->addBoneAssignment(boneiter.current()->second); - - - - } - } -}*/ /* More code currently not in use, from the old D source. This was diff --git a/components/nifogre/ogre_nif_loader.hpp b/components/nifogre/ogre_nif_loader.hpp index e9caf8d11..b160f9dbc 100644 --- a/components/nifogre/ogre_nif_loader.hpp +++ b/components/nifogre/ogre_nif_loader.hpp @@ -45,8 +45,7 @@ #include #include // For warning messages -#include 5 -// float infinity +#include #include using namespace boost::algorithm; From 0715f9b6aba8bbba8837e3a350132a445780ebc2 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Fri, 6 Jan 2012 00:55:02 -0500 Subject: [PATCH 093/104] Preparing to use text indices --- apps/openmw/mwrender/animation.hpp | 2 +- apps/openmw/mwrender/creatureanimation.cpp | 3 ++- apps/openmw/mwrender/npcanimation.cpp | 1 + components/nifogre/ogre_nif_loader.cpp | 17 ++++++----------- components/nifogre/ogre_nif_loader.hpp | 2 +- 5 files changed, 11 insertions(+), 14 deletions(-) diff --git a/apps/openmw/mwrender/animation.hpp b/apps/openmw/mwrender/animation.hpp index f81f38094..d948cd7b8 100644 --- a/apps/openmw/mwrender/animation.hpp +++ b/apps/openmw/mwrender/animation.hpp @@ -42,7 +42,7 @@ class Animation{ std::vector* transformations; - std::map textmappings; + std::map* textmappings; Ogre::Entity* base; void handleShapes(std::vector* allshapes, Ogre::Entity* creaturemodel, Ogre::SkeletonInstance *skel); void handleAnimationTransforms(); diff --git a/apps/openmw/mwrender/creatureanimation.cpp b/apps/openmw/mwrender/creatureanimation.cpp index 3d4e93d7b..eac6a3f19 100644 --- a/apps/openmw/mwrender/creatureanimation.cpp +++ b/apps/openmw/mwrender/creatureanimation.cpp @@ -31,7 +31,8 @@ CreatureAnimation::CreatureAnimation(const MWWorld::Ptr& ptr, MWWorld::Environme stopTime = transformations->begin()->getStopTime(); startTime = transformations->begin()->getStartTime(); shapes = (NIFLoader::getSingletonPtr())->getShapes(meshZero); - } + } + textmappings = NIFLoader::getSingletonPtr()->getTextIndices(meshZero); insert->attachObject(base); } } diff --git a/apps/openmw/mwrender/npcanimation.cpp b/apps/openmw/mwrender/npcanimation.cpp index 1af4d7596..c98ddc37d 100644 --- a/apps/openmw/mwrender/npcanimation.cpp +++ b/apps/openmw/mwrender/npcanimation.cpp @@ -77,6 +77,7 @@ NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, MWWorld::Environment& _env,O stopTime = transformations->begin()->getStopTime(); startTime = transformations->begin()->getStartTime(); } + textmappings = NIFLoader::getSingletonPtr()->getTextIndices(smodel); insert->attachObject(base); if(female) diff --git a/components/nifogre/ogre_nif_loader.cpp b/components/nifogre/ogre_nif_loader.cpp index 48edde4f3..6990e1a4b 100644 --- a/components/nifogre/ogre_nif_loader.cpp +++ b/components/nifogre/ogre_nif_loader.cpp @@ -1315,17 +1315,12 @@ std::vector* NIFLoader::getShapes(std::string lowername){ return pass; } -float NIFLoader::getTime(std::string filename, std::string text){ - std::map,ciLessBoost>::iterator iter = alltextmappings.find(filename); - if(iter != alltextmappings.end()){ - std::map::iterator insideiter = (iter->second).find(text); - if(insideiter != (iter->second).end()) - return insideiter->second; - else - return -20000000.0; - } - - return -10000000.0; +std::map* NIFLoader::getTextIndices(std::string lowername){ + std::map, ciLessBoost>::iterator iter = alltextmappings.find(lowername); + std::map* pass = 0; + if(iter != alltextmappings.end()) + pass = &(iter->second); + return pass; } diff --git a/components/nifogre/ogre_nif_loader.hpp b/components/nifogre/ogre_nif_loader.hpp index b160f9dbc..ef6374b23 100644 --- a/components/nifogre/ogre_nif_loader.hpp +++ b/components/nifogre/ogre_nif_loader.hpp @@ -110,7 +110,7 @@ class NIFLoader : Ogre::ManualResourceLoader //void insertMeshInsideBase(Ogre::Mesh* mesh); std::vector* getAnim(std::string name); std::vector* getShapes(std::string name); - float getTime(std::string filename, std::string text); + std::map* getTextIndices(std::string name); void addInMesh(Ogre::Mesh* input); From 859ac1153ed0748e20aec76e0c6f261052dbb823 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Fri, 6 Jan 2012 02:27:10 -0500 Subject: [PATCH 094/104] Basic Text Indices Working --- apps/openmw/mwrender/animation.cpp | 26 ++++++++++++++++++++++++++ apps/openmw/mwrender/animation.hpp | 5 +++++ components/nifogre/ogre_nif_loader.cpp | 2 ++ 3 files changed, 33 insertions(+) diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index 2b22ea589..346f5a86b 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -33,6 +33,32 @@ namespace MWRender{ animate = loops; time = startTime; } + else if(textmappings){ + std::string startName = groupname + ": start"; + std::string stopName = groupname + ": stop"; + std::cout << "StartName:" << startName << "\n"; + bool first = false; + for(std::map::iterator iter = textmappings->begin(); iter != textmappings->end(); iter++){ + + std::string current = iter->first.substr(0, startName.size()); + std::transform(current.begin(), current.end(), current.begin(), ::tolower); + std::string current2 = iter->first.substr(0, stopName.size()); + std::transform(current2.begin(), current2.end(), current2.begin(), ::tolower); + + if(current == startName){ + startTime = iter->second; + animate = loops; + time = startTime; + first = true; + } + if(current2 == stopName){ + stopTime = iter->second; + if(first) + break; + } + } + + } } void Animation::stopScript(){ diff --git a/apps/openmw/mwrender/animation.hpp b/apps/openmw/mwrender/animation.hpp index d948cd7b8..d3af1b6cb 100644 --- a/apps/openmw/mwrender/animation.hpp +++ b/apps/openmw/mwrender/animation.hpp @@ -10,6 +10,11 @@ #include #include +using namespace boost::algorithm; + + + + namespace MWRender{ class Animation{ diff --git a/components/nifogre/ogre_nif_loader.cpp b/components/nifogre/ogre_nif_loader.cpp index 6990e1a4b..500d5496b 100644 --- a/components/nifogre/ogre_nif_loader.cpp +++ b/components/nifogre/ogre_nif_loader.cpp @@ -1006,6 +1006,8 @@ void NIFLoader::handleNode(Nif::Node *node, int flags, replace(text.begin(), text.end(), '\n', '/'); text.erase(std::remove(text.begin(), text.end(), '\r'), text.end()); + if(text.at(0) == '/') + text.erase(0, 1); file << "Time: " << textiter->time << "|" << text << "\n"; textmappings[text] = textiter->time; From 295eb27c2dcdda10a7dd10cfe387ab6a422c2aee Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Fri, 6 Jan 2012 18:23:41 -0500 Subject: [PATCH 095/104] Better Text Indices; Better file output --- apps/openmw/mwrender/animation.cpp | 6 ++++++ components/nifogre/ogre_nif_loader.cpp | 23 +++++++++++++++++++---- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index 346f5a86b..f15bbb074 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -34,8 +34,14 @@ namespace MWRender{ time = startTime; } else if(textmappings){ + std::string startName = groupname + ": start"; std::string stopName = groupname + ": stop"; + + if(loops > 1){ + startName = groupname + ": loop start"; + std::string stopName = groupname + ": loop stop"; + } std::cout << "StartName:" << startName << "\n"; bool first = false; for(std::map::iterator iter = textmappings->begin(); iter != textmappings->end(); iter++){ diff --git a/components/nifogre/ogre_nif_loader.cpp b/components/nifogre/ogre_nif_loader.cpp index 500d5496b..380301551 100644 --- a/components/nifogre/ogre_nif_loader.cpp +++ b/components/nifogre/ogre_nif_loader.cpp @@ -1006,11 +1006,26 @@ void NIFLoader::handleNode(Nif::Node *node, int flags, replace(text.begin(), text.end(), '\n', '/'); text.erase(std::remove(text.begin(), text.end(), '\r'), text.end()); - if(text.at(0) == '/') - text.erase(0, 1); - file << "Time: " << textiter->time << "|" << text << "\n"; + int i = 0; + while(i < text.length()){ + while(i < text.length() && text.at(i) == '/' ){ + i++; + } + int first = i; + int length = 0; + while(i < text.length() && text.at(i) != '/' ){ + i++; + length++; + } + if(first < text.length()){ + //length = text.length() - first; + std::string sub = text.substr(first, length); + + file << "Time: " << textiter->time << "|" << sub << "\n"; - textmappings[text] = textiter->time; + textmappings[sub] = textiter->time; + } + } } file.close(); } From a615369189f4b2a672fc5e4d16dbb3325fef1e1e Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Fri, 6 Jan 2012 22:52:15 -0500 Subject: [PATCH 096/104] Warning and different physics --- apps/openmw/mwclass/creature.cpp | 2 +- apps/openmw/mwclass/npc.cpp | 2 +- apps/openmw/mwrender/animation.cpp | 35 +++++++++++++++++++++++++----- apps/openmw/mwrender/animation.hpp | 2 -- 4 files changed, 32 insertions(+), 9 deletions(-) diff --git a/apps/openmw/mwclass/creature.cpp b/apps/openmw/mwclass/creature.cpp index 5aa203a49..9b7ea192c 100644 --- a/apps/openmw/mwclass/creature.cpp +++ b/apps/openmw/mwclass/creature.cpp @@ -47,7 +47,7 @@ namespace MWClass const std::string &model = ref->base->model; assert (ref->base != NULL); if(!model.empty()){ - physics.insertActorPhysics(ptr, "meshes\\" + model); + physics.insertObjectPhysics(ptr, "meshes\\" + model); } } diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index acb0a5a35..03c96a4ac 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -53,7 +53,7 @@ namespace MWClass std::string smodel = "meshes\\base_anim.nif"; if(beast) smodel = "meshes\\base_animkna.nif"; - physics.insertActorPhysics(ptr, smodel); + physics.insertObjectPhysics(ptr, smodel); } diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index f15bbb074..e1420f477 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -35,15 +35,39 @@ namespace MWRender{ } else if(textmappings){ - std::string startName = groupname + ": start"; - std::string stopName = groupname + ": stop"; + std::string startName = groupname + ": loop start"; + std::string stopName = groupname + ": loop stop"; + + bool first = false; if(loops > 1){ startName = groupname + ": loop start"; - std::string stopName = groupname + ": loop stop"; + stopName = groupname + ": loop stop"; + + for(std::map::iterator iter = textmappings->begin(); iter != textmappings->end(); iter++){ + + std::string current = iter->first.substr(0, startName.size()); + std::transform(current.begin(), current.end(), current.begin(), ::tolower); + std::string current2 = iter->first.substr(0, stopName.size()); + std::transform(current2.begin(), current2.end(), current2.begin(), ::tolower); + + if(current == startName){ + startTime = iter->second; + animate = loops; + time = startTime; + first = true; + } + if(current2 == stopName){ + stopTime = iter->second; + if(first) + break; + } + } } - std::cout << "StartName:" << startName << "\n"; - bool first = false; + if(!first){ + startName = groupname + ": start"; + stopName = groupname + ": stop"; + for(std::map::iterator iter = textmappings->begin(); iter != textmappings->end(); iter++){ std::string current = iter->first.substr(0, startName.size()); @@ -63,6 +87,7 @@ namespace MWRender{ break; } } + } } diff --git a/apps/openmw/mwrender/animation.hpp b/apps/openmw/mwrender/animation.hpp index d3af1b6cb..14b18bf54 100644 --- a/apps/openmw/mwrender/animation.hpp +++ b/apps/openmw/mwrender/animation.hpp @@ -10,8 +10,6 @@ #include #include -using namespace boost::algorithm; - From 7fde576dd94aa73c446e75366e13163ee97523df Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Sat, 7 Jan 2012 23:21:19 -0500 Subject: [PATCH 097/104] actor physics again --- apps/openmw/mwclass/creature.cpp | 2 +- apps/openmw/mwclass/npc.cpp | 2 +- apps/openmw/mwrender/npcanimation.cpp | 12 ++++++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwclass/creature.cpp b/apps/openmw/mwclass/creature.cpp index 9b7ea192c..5aa203a49 100644 --- a/apps/openmw/mwclass/creature.cpp +++ b/apps/openmw/mwclass/creature.cpp @@ -47,7 +47,7 @@ namespace MWClass const std::string &model = ref->base->model; assert (ref->base != NULL); if(!model.empty()){ - physics.insertObjectPhysics(ptr, "meshes\\" + model); + physics.insertActorPhysics(ptr, "meshes\\" + model); } } diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index 03c96a4ac..acb0a5a35 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -53,7 +53,7 @@ namespace MWClass std::string smodel = "meshes\\base_anim.nif"; if(beast) smodel = "meshes\\base_animkna.nif"; - physics.insertObjectPhysics(ptr, smodel); + physics.insertActorPhysics(ptr, smodel); } diff --git a/apps/openmw/mwrender/npcanimation.cpp b/apps/openmw/mwrender/npcanimation.cpp index c98ddc37d..f8755bc9f 100644 --- a/apps/openmw/mwrender/npcanimation.cpp +++ b/apps/openmw/mwrender/npcanimation.cpp @@ -224,6 +224,18 @@ void NpcAnimation::insertFreePart(const std::string &mesh, const std::string suf NIFLoader::load(meshNumbered); Ogre::Entity* ent = mRend.getScene()->createEntity(meshNumbered); + + /*MaterialPtr material = ent->getSubEntity(0)->getMaterial(); + material->removeAllTechniques(); + + Ogre::Technique* tech = material->createTechnique(); + + Pass* pass2 = tech->createPass(); + pass2->setVertexProgram("Ogre/HardwareSkinningTwoWeights"); + pass2->setColourWriteEnabled(false); + //tech->setSchemeName("blahblah");*/ + + insert->attachObject(ent); entityparts.push_back(ent); shapes = ((NIFLoader::getSingletonPtr())->getShapes(mesh + "0000" + suffix)); From eab69f18ac7ab2d0988d39d98420464b3a02d687 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Tue, 10 Jan 2012 00:34:29 -0500 Subject: [PATCH 098/104] File output switch --- apps/openmw/engine.cpp | 7 ++++++ apps/openmw/engine.hpp | 2 ++ apps/openmw/main.cpp | 4 ++++ components/nifogre/ogre_nif_loader.cpp | 31 ++++++++++++++++---------- components/nifogre/ogre_nif_loader.hpp | 9 ++++++-- 5 files changed, 39 insertions(+), 14 deletions(-) diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 5d235b5d1..c4623b375 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include "mwinput/inputmanager.hpp" @@ -45,6 +46,7 @@ #include "mwmechanics/mechanicsmanager.hpp" + void OMW::Engine::executeLocalScripts() { MWWorld::LocalScripts& localScripts = mEnvironment.mWorld->getLocalScripts(); @@ -99,6 +101,11 @@ void OMW::Engine::updateFocusReport (float duration) } } +void OMW::Engine::setAnimationVerbose(bool animverbose){ + if(animverbose) + NifOgre::NIFLoader::getSingletonPtr()->setOutputAnimFiles(true); +} + bool OMW::Engine::frameRenderingQueued (const Ogre::FrameEvent& evt) { try diff --git a/apps/openmw/engine.hpp b/apps/openmw/engine.hpp index 443f790a4..741d46624 100644 --- a/apps/openmw/engine.hpp +++ b/apps/openmw/engine.hpp @@ -158,6 +158,8 @@ namespace OMW /// Font encoding void setEncoding(const std::string& encoding); + void setAnimationVerbose(bool animverbose); + private: Cfg::ConfigurationManager& mCfgMgr; }; diff --git a/apps/openmw/main.cpp b/apps/openmw/main.cpp index 933d1c48a..6e26d6258 100644 --- a/apps/openmw/main.cpp +++ b/apps/openmw/main.cpp @@ -78,6 +78,9 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Cfg::Configuratio ("fps", boost::program_options::value()->implicit_value(true) ->default_value(false), "show fps counter") + ("anim-verbose", boost::program_options::value()->implicit_value(true) + ->default_value(false), "output animation indices files") + ("debug", boost::program_options::value()->implicit_value(true) ->default_value(false), "debug mode") @@ -206,6 +209,7 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Cfg::Configuratio engine.setScriptsVerbosity(variables["script-verbose"].as()); engine.setCompileAll(variables["script-all"].as()); engine.setReportFocus(variables["report-focus"].as()); + engine.setAnimationVerbose(variables["anim-verbose"].as()); return true; } diff --git a/components/nifogre/ogre_nif_loader.cpp b/components/nifogre/ogre_nif_loader.cpp index 380301551..c1d05ef2f 100644 --- a/components/nifogre/ogre_nif_loader.cpp +++ b/components/nifogre/ogre_nif_loader.cpp @@ -201,6 +201,9 @@ static CompareFunction getTestMode(int mode) } */ +void NIFLoader::setOutputAnimFiles(bool output){ + mOutputAnimFiles = output; +} void NIFLoader::createMaterial(const String &name, const Vector &ambient, const Vector &diffuse, @@ -984,19 +987,22 @@ void NIFLoader::handleNode(Nif::Node *node, int flags, if (e->recType == RC_NiTextKeyExtraData){ Nif::NiTextKeyExtraData* extra = dynamic_cast (e); + std::ofstream file; + + if(mOutputAnimFiles){ + std::string cut = ""; + for(unsigned int i = 0; i < name.length(); i++) + { + if(!(name.at(i) == '\\' || name.at(i) == '/' || name.at(i) == '>' || name.at(i) == '<' || name.at(i) == '?' || name.at(i) == '*' || name.at(i) == '|' || name.at(i) == ':' || name.at(i) == '"')) + { + cut += name.at(i); + } + } - std::string cut = ""; - for(unsigned int i = 0; i < name.length(); i++) - { - if(!(name.at(i) == '\\' || name.at(i) == '/' || name.at(i) == '>' || name.at(i) == '<' || name.at(i) == '?' || name.at(i) == '*' || name.at(i) == '|' || name.at(i) == ':' || name.at(i) == '"')) - { - cut += name.at(i); - } - } - - std::cout << "Outputting " << cut << "\n"; + std::cout << "Outputting " << cut << "\n"; - std::ofstream file(("Indices" + cut + ".txt").c_str()); + file.open(("Indices" + cut + ".txt").c_str()); + } for(std::vector::iterator textiter = extra->list.begin(); textiter != extra->list.end(); textiter++) { @@ -1021,7 +1027,8 @@ void NIFLoader::handleNode(Nif::Node *node, int flags, //length = text.length() - first; std::string sub = text.substr(first, length); - file << "Time: " << textiter->time << "|" << sub << "\n"; + if(mOutputAnimFiles) + file << "Time: " << textiter->time << "|" << sub << "\n"; textmappings[sub] = textiter->time; } diff --git a/components/nifogre/ogre_nif_loader.hpp b/components/nifogre/ogre_nif_loader.hpp index ef6374b23..2cacb6728 100644 --- a/components/nifogre/ogre_nif_loader.hpp +++ b/components/nifogre/ogre_nif_loader.hpp @@ -117,12 +117,15 @@ class NIFLoader : Ogre::ManualResourceLoader Ogre::Vector3 convertVector3(const Nif::Vector& vec); Ogre::Quaternion convertRotation(const Nif::Matrix& rot); + void setOutputAnimFiles(bool output); + private: - NIFLoader() : resourceGroup("General"),mNormaliseNormals(false), - mFlipVertexWinding(false), flip(false) {resourceName = "";} + NIFLoader() : mNormaliseNormals(false), resourceGroup("General"), resourceName(""), flip(false), + mFlipVertexWinding(false), mOutputAnimFiles(false) {} NIFLoader(NIFLoader& n) {} void calculateTransform(); + void warn(std::string msg); void fail(std::string msg); @@ -168,6 +171,7 @@ class NIFLoader : Ogre::ManualResourceLoader bool mNormaliseNormals; bool mFlipVertexWinding; bool bNiTri; + bool mOutputAnimFiles; std::multimap MaterialMap; // pointer to the ogre mesh which is currently build @@ -185,6 +189,7 @@ class NIFLoader : Ogre::ManualResourceLoader std::vector addin; std::vector mAnim; std::vector mS; + }; } From 5e1cc07ee820efa7b408979f70366d7bb76feb90 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Tue, 10 Jan 2012 02:00:04 -0500 Subject: [PATCH 099/104] Fixed ancestor ghost crash --- apps/openmw/mwrender/animation.cpp | 6 +++--- apps/openmw/mwrender/creatureanimation.cpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index e1420f477..e31553012 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -408,7 +408,7 @@ namespace MWRender{ if(time < iter->getStartTime() || time < startTime || time > iter->getStopTime()) { slot++; - iter++; + //iter++; continue; } @@ -442,14 +442,13 @@ namespace MWRender{ t = (v1 + (v2 - v1) * x); } - + bool bQuats = quats.size() > 0; if(bQuats){ r = Ogre::Quaternion::Slerp(x2, quats[rindexI[slot]], quats[rindexJ], true); //bone->setOrientation(r); } skel = base->getSkeleton(); - if(skel->hasBone(iter->getBonename())){ Ogre::Bone* bone = skel->getBone(iter->getBonename()); if(bTrans) @@ -485,4 +484,5 @@ namespace MWRender{ } } } + } \ No newline at end of file diff --git a/apps/openmw/mwrender/creatureanimation.cpp b/apps/openmw/mwrender/creatureanimation.cpp index eac6a3f19..c2b95186b 100644 --- a/apps/openmw/mwrender/creatureanimation.cpp +++ b/apps/openmw/mwrender/creatureanimation.cpp @@ -45,7 +45,7 @@ void CreatureAnimation::runAnimation(float timepassed){ //Handle the shapes dependent on animation transforms time += timepassed; - if(time > stopTime){ + if(time >= stopTime){ animate--; //std::cout << "Stopping the animation\n"; if(animate == 0) From 0712bba49b5858bbffda700b2d94f4ff6c4cb1f2 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Thu, 12 Jan 2012 16:03:07 -0500 Subject: [PATCH 100/104] Changing a few things around with handleshapes --- apps/openmw/mwrender/animation.cpp | 108 +++++++++++++++++++++---- apps/openmw/mwrender/animation.hpp | 5 ++ components/nif/data.hpp | 8 +- components/nif/node.hpp | 1 + components/nifogre/ogre_nif_loader.cpp | 33 +++++--- 5 files changed, 130 insertions(+), 25 deletions(-) diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index e31553012..5105d12b4 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -97,21 +97,25 @@ namespace MWRender{ } void Animation::handleShapes(std::vector* allshapes, Ogre::Entity* creaturemodel, Ogre::SkeletonInstance *skel){ + bool useHandles = skel == creaturemodel->getSkeleton(); shapeNumber = 0; + std::vector::iterator allshapesiter; for(allshapesiter = allshapes->begin(); allshapesiter != allshapes->end(); allshapesiter++) { + //std::map vecPosRot; Nif::NiTriShapeCopy& copy = *allshapesiter; - std::vector allvertices = copy.vertices; - std::vector allnormals = copy.normals; + std::vector* allvertices = ©.vertices; + std::vector* allnormals = ©.normals; - std::set vertices; + //std::set vertices; //std::set normals; - std::vector boneinfovector = copy.boneinfo; + //std::vector boneinfovector = copy.boneinfo; + std::map>* verticesToChange = ©.vertsToWeights; //std::cout << "Name " << copy.sname << "\n"; Ogre::HardwareVertexBufferSharedPtr vbuf = creaturemodel->getMesh()->getSubMesh(copy.sname)->vertexData->vertexBufferBinding->getBuffer(0); @@ -161,17 +165,91 @@ namespace MWRender{ } - allvertices = initialVertices; + allvertices = &initialVertices; } shapeNumber++; } } - if(boneinfovector.size() > 0){ - + if(verticesToChange->size() > 0){ + + for(std::map>::iterator iter = verticesToChange->begin(); + iter != verticesToChange->end(); iter++) + { + std::vector inds = iter->second; + int verIndex = iter->first; + Ogre::Vector3 currentVertex = (*allvertices)[verIndex]; + Nif::NiSkinData::BoneInfoCopy* boneinfocopy = &(allshapesiter->boneinfo[inds[0].boneinfocopyindex]); + Ogre::Bone *bonePtr = 0; + if(useHandles) + { + bonePtr = skel->getBone(boneinfocopy->bonehandle); + } + else + bonePtr = skel->getBone(boneinfocopy->bonename); + + Ogre::Vector3 vecPos = bonePtr->_getDerivedPosition() + bonePtr->_getDerivedOrientation() * boneinfocopy->trafo.trans; + Ogre::Quaternion vecRot = bonePtr->_getDerivedOrientation() * boneinfocopy->trafo.rotation; + + + /*if(vecPosRot.find(boneinfocopy->bonehandle) == vecPosRot.end()){ + vecPos = bonePtr->_getDerivedPosition() + bonePtr->_getDerivedOrientation() * boneinfocopy->trafo.trans; + vecRot = bonePtr->_getDerivedOrientation() * boneinfocopy->trafo.rotation; + + if(useHandles){ + PosAndRot both; + both.vecPos = vecPos; + both.vecRot = vecRot; + vecPosRot[boneinfocopy->bonehandle] = both; + } + } + else{ + PosAndRot both = vecPosRot[boneinfocopy->bonehandle]; + vecPos = both.vecPos; + vecRot = both.vecRot; + }*/ + + Ogre::Vector3 absVertPos = (vecPos + vecRot * currentVertex) * inds[0].weight; + + + for(int i = 1; i < inds.size(); i++){ + boneinfocopy = &(allshapesiter->boneinfo[inds[i].boneinfocopyindex]); + if(useHandles) + bonePtr = skel->getBone(boneinfocopy->bonehandle); + else + bonePtr = skel->getBone(boneinfocopy->bonename); + vecPos = bonePtr->_getDerivedPosition() + bonePtr->_getDerivedOrientation() * boneinfocopy->trafo.trans; + vecRot = bonePtr->_getDerivedOrientation() * boneinfocopy->trafo.rotation; + + /*if(vecPosRot.find(boneinfocopy->bonehandle) == vecPosRot.end()){ + vecPos = bonePtr->_getDerivedPosition() + bonePtr->_getDerivedOrientation() * boneinfocopy->trafo.trans; + vecRot = bonePtr->_getDerivedOrientation() * boneinfocopy->trafo.rotation; + + if(useHandles){ + PosAndRot both; + both.vecPos = vecPos; + both.vecRot = vecRot; + vecPosRot[boneinfocopy->bonehandle] = both; + } + } + else{ + PosAndRot both = vecPosRot[boneinfocopy->bonehandle]; + vecPos = both.vecPos; + vecRot = both.vecRot; + }*/ + + + absVertPos += (vecPos + vecRot * currentVertex) * inds[i].weight; + + } + Ogre::Real* addr = (pReal + 3 * verIndex); + *addr = absVertPos.x; + *(addr+1) = absVertPos.y; + *(addr+2) = absVertPos.z; + } - for (unsigned int i = 0; i < boneinfovector.size(); i++) + /*for (unsigned int i = 0; i < boneinfovector.size(); i++) { Nif::NiSkinData::BoneInfoCopy boneinfo = boneinfovector[i]; if(skel->hasBone(boneinfo.bonename)){ @@ -234,14 +312,14 @@ namespace MWRender{ }*/ - } - } + //} + //} - } - + //} //Comment out - } + ; + } else { //Ogre::Bone *bonePtr = creaturemodel->getSkeleton()->getBone(copy.bonename); @@ -293,8 +371,8 @@ namespace MWRender{ // Computes C = B + AxC*scale // final_vector = old_vector + old_rotation*new_vector*old_scale/ - for(unsigned int i = 0; i < allvertices.size(); i++){ - Ogre::Vector3 current = transmult + rotmult * allvertices[i]; + for(unsigned int i = 0; i < allvertices->size(); i++){ + Ogre::Vector3 current = transmult + rotmult * (*allvertices)[i]; Ogre::Real* addr = pReal + i * 3; *addr = current.x; *(addr+1) = current.y; diff --git a/apps/openmw/mwrender/animation.hpp b/apps/openmw/mwrender/animation.hpp index 14b18bf54..15c25707c 100644 --- a/apps/openmw/mwrender/animation.hpp +++ b/apps/openmw/mwrender/animation.hpp @@ -15,6 +15,11 @@ namespace MWRender{ +struct PosAndRot{ + Ogre::Quaternion vecRot; + Ogre::Vector3 vecPos; +}; + class Animation{ protected: diff --git a/components/nif/data.hpp b/components/nif/data.hpp index 892e98003..9e28e1534 100644 --- a/components/nif/data.hpp +++ b/components/nif/data.hpp @@ -390,9 +390,15 @@ public: struct BoneInfoCopy { std::string bonename; + unsigned short bonehandle; BoneTrafoCopy trafo; Vector4 unknown; - std::vector weights; + //std::vector weights; + }; + struct IndividualWeight + { + float weight; + unsigned int boneinfocopyindex; }; const BoneTrafo *trafo; diff --git a/components/nif/node.hpp b/components/nif/node.hpp index 02387d219..bbceb866e 100644 --- a/components/nif/node.hpp +++ b/components/nif/node.hpp @@ -103,6 +103,7 @@ struct NiTriShapeCopy std::vector vertices; std::vector normals; std::vector boneinfo; + std::map> vertsToWeights; Nif::NiMorphData morph; }; diff --git a/components/nifogre/ogre_nif_loader.cpp b/components/nifogre/ogre_nif_loader.cpp index c1d05ef2f..b6f09eaff 100644 --- a/components/nifogre/ogre_nif_loader.cpp +++ b/components/nifogre/ogre_nif_loader.cpp @@ -355,7 +355,7 @@ void NIFLoader::createOgreSubMesh(NiTriShape *shape, const String &material, std HardwareVertexBufferSharedPtr vbuf = HardwareBufferManager::getSingleton().createVertexBuffer( VertexElement::getTypeSize(VET_FLOAT3), - numVerts, HardwareBuffer::HBU_DYNAMIC); + numVerts, HardwareBuffer::HBU_STATIC_WRITE_ONLY, false); if(flip) { @@ -388,7 +388,7 @@ void NIFLoader::createOgreSubMesh(NiTriShape *shape, const String &material, std decl->addElement(nextBuf, 0, VET_FLOAT3, VES_NORMAL); vbuf = HardwareBufferManager::getSingleton().createVertexBuffer( VertexElement::getTypeSize(VET_FLOAT3), - numVerts, HardwareBuffer::HBU_DYNAMIC,true); + numVerts, HardwareBuffer::HBU_STATIC_WRITE_ONLY, false); if(flip) { @@ -751,7 +751,6 @@ void NIFLoader::handleNiTriShape(NiTriShape *shape, int flags, BoundsFinder &bou if (!shape->skin.empty()) { - //Bone assignments are stored in submeshes, so we don't need to copy them // vector that stores if the position of a vertex is absolute @@ -791,10 +790,12 @@ void NIFLoader::handleNiTriShape(NiTriShape *shape, int flags, BoundsFinder &bou // final_vector = old_vector + old_rotation*new_vector*old_scale - Nif::NiSkinData::BoneInfoCopy boneinfo; - boneinfo.trafo.rotation = convertRotation(it->trafo->rotation); - boneinfo.trafo.trans = convertVector3(it->trafo->trans); - boneinfo.bonename = shape->skin->bones[boneIndex].name.toString(); + Nif::NiSkinData::BoneInfoCopy boneinfocopy; + boneinfocopy.trafo.rotation = convertRotation(it->trafo->rotation); + boneinfocopy.trafo.trans = convertVector3(it->trafo->trans); + boneinfocopy.bonename = shape->skin->bones[boneIndex].name.toString(); + boneinfocopy.bonehandle = bonePtr->getHandle(); + copy.boneinfo.push_back(boneinfocopy); for (unsigned int i=0; iweights.length; i++) { vecPos = bonePtr->_getDerivedPosition() + @@ -802,7 +803,21 @@ void NIFLoader::handleNiTriShape(NiTriShape *shape, int flags, BoundsFinder &bou vecRot = bonePtr->_getDerivedOrientation() * convertRotation(it->trafo->rotation); unsigned int verIndex = (it->weights.ptr + i)->vertex; - boneinfo.weights.push_back(*(it->weights.ptr + i)); + //boneinfo.weights.push_back(*(it->weights.ptr + i)); + Nif::NiSkinData::IndividualWeight ind; + ind.weight = (it->weights.ptr + i)->weight; + ind.boneinfocopyindex = copy.boneinfo.size() - 1; + if(copy.vertsToWeights.find(verIndex) == copy.vertsToWeights.end()) + { + std::vector blank; + blank.push_back(ind); + copy.vertsToWeights[verIndex] = blank; + } + else + { + copy.vertsToWeights[verIndex].push_back(ind); + } + //Check if the vertex is relativ, FIXME: Is there a better solution? if (vertexPosAbsolut[verIndex] == false) { @@ -865,7 +880,7 @@ void NIFLoader::handleNiTriShape(NiTriShape *shape, int flags, BoundsFinder &bou vertexBoneAssignments.push_back(vba); } - copy.boneinfo.push_back(boneinfo); + boneIndex++; } From d1793bc4bd962c1b870028dff60ae9765696a829 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Thu, 12 Jan 2012 20:09:55 -0500 Subject: [PATCH 101/104] Animation files in the correct directory --- apps/openmw/engine.cpp | 5 ++++- apps/openmw/mwrender/npcanimation.cpp | 1 + components/nifogre/ogre_nif_loader.cpp | 5 ++++- components/nifogre/ogre_nif_loader.hpp | 2 ++ 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index c4623b375..20f9dc0e7 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -102,8 +102,10 @@ void OMW::Engine::updateFocusReport (float duration) } void OMW::Engine::setAnimationVerbose(bool animverbose){ - if(animverbose) + if(animverbose){ NifOgre::NIFLoader::getSingletonPtr()->setOutputAnimFiles(true); + NifOgre::NIFLoader::getSingletonPtr()->setVerbosePath(mCfgMgr.getLogPath().string()); + } } bool OMW::Engine::frameRenderingQueued (const Ogre::FrameEvent& evt) @@ -338,6 +340,7 @@ void OMW::Engine::go() // Set up the GUI system mGuiManager = new OEngine::GUI::MyGUIManager(mOgre->getWindow(), mOgre->getScene(), false, mCfgMgr.getLogPath().string() + std::string("/")); + // Create window manager - this manages all the MW-specific GUI windows MWScript::registerExtensions (mExtensions); diff --git a/apps/openmw/mwrender/npcanimation.cpp b/apps/openmw/mwrender/npcanimation.cpp index f8755bc9f..0ff679507 100644 --- a/apps/openmw/mwrender/npcanimation.cpp +++ b/apps/openmw/mwrender/npcanimation.cpp @@ -284,6 +284,7 @@ void NpcAnimation::runAnimation(float timepassed){ }*/ + std::vector*>::iterator shapepartsiter = shapeparts.begin(); std::vector::iterator entitypartsiter = entityparts.begin(); while(shapepartsiter != shapeparts.end()) diff --git a/components/nifogre/ogre_nif_loader.cpp b/components/nifogre/ogre_nif_loader.cpp index b6f09eaff..92a5713a3 100644 --- a/components/nifogre/ogre_nif_loader.cpp +++ b/components/nifogre/ogre_nif_loader.cpp @@ -204,6 +204,9 @@ static CompareFunction getTestMode(int mode) void NIFLoader::setOutputAnimFiles(bool output){ mOutputAnimFiles = output; } +void NIFLoader::setVerbosePath(std::string path){ + verbosePath = path; +} void NIFLoader::createMaterial(const String &name, const Vector &ambient, const Vector &diffuse, @@ -1016,7 +1019,7 @@ void NIFLoader::handleNode(Nif::Node *node, int flags, std::cout << "Outputting " << cut << "\n"; - file.open(("Indices" + cut + ".txt").c_str()); + file.open((verbosePath + "/Indices" + cut + ".txt").c_str()); } for(std::vector::iterator textiter = extra->list.begin(); textiter != extra->list.end(); textiter++) diff --git a/components/nifogre/ogre_nif_loader.hpp b/components/nifogre/ogre_nif_loader.hpp index 2cacb6728..fd1620822 100644 --- a/components/nifogre/ogre_nif_loader.hpp +++ b/components/nifogre/ogre_nif_loader.hpp @@ -118,6 +118,7 @@ class NIFLoader : Ogre::ManualResourceLoader Ogre::Quaternion convertRotation(const Nif::Matrix& rot); void setOutputAnimFiles(bool output); + void setVerbosePath(std::string path); private: NIFLoader() : mNormaliseNormals(false), resourceGroup("General"), resourceName(""), flip(false), @@ -163,6 +164,7 @@ class NIFLoader : Ogre::ManualResourceLoader // extension from .tga to .dds if the texture is missing. Mangle::VFS::OgreVFS *vfs; + std::string verbosePath; std::string resourceName; std::string resourceGroup; Ogre::Matrix4 mTransform; From 41769f202c50c9b934d501176520e4ac06da3817 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Fri, 13 Jan 2012 00:48:52 -0500 Subject: [PATCH 102/104] Huge Performance Increase --- apps/openmw/mwrender/animation.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index 5105d12b4..fbe30bbb0 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -457,12 +457,12 @@ namespace MWRender{ Ogre::Bone* b = skel->getRootBone(); b->setOrientation(Ogre::Real(.3),Ogre::Real(.3),Ogre::Real(.3), Ogre::Real(.3)); //This is a trick - skel->getManualBonesDirty(); + skel->_updateTransforms(); - skel->_notifyManualBonesDirty(); + //skel->_notifyManualBonesDirty(); base->getAllAnimationStates()->_notifyDirty(); - base->_updateAnimation(); + //base->_updateAnimation(); base->_notifyMoved(); for(unsigned int i = 0; i < entityparts.size(); i++){ @@ -470,12 +470,12 @@ namespace MWRender{ Ogre::Bone* b = skel->getRootBone(); b->setOrientation(Ogre::Real(.3),Ogre::Real(.3),Ogre::Real(.3), Ogre::Real(.3));//This is a trick - skel->getManualBonesDirty(); + skel->_updateTransforms(); - skel->_notifyManualBonesDirty(); + // skel->_notifyManualBonesDirty(); entityparts[i]->getAllAnimationStates()->_notifyDirty(); - entityparts[i]->_updateAnimation(); + //entityparts[i]->_updateAnimation(); entityparts[i]->_notifyMoved(); } @@ -535,11 +535,11 @@ namespace MWRender{ bone->setOrientation(r); - skel->getManualBonesDirty(); + skel->_updateTransforms(); - skel->_notifyManualBonesDirty(); + //skel->_notifyManualBonesDirty(); base->getAllAnimationStates()->_notifyDirty(); - base->_updateAnimation(); + //base->_updateAnimation(); base->_notifyMoved(); } for(int i = 0; i < entityparts.size(); i++){ @@ -550,11 +550,11 @@ namespace MWRender{ bone->setPosition(t); if(bQuats) bone->setOrientation(r); - skel->getManualBonesDirty(); + skel->_updateTransforms(); - skel->_notifyManualBonesDirty(); + //skel->_notifyManualBonesDirty(); entityparts[i]->getAllAnimationStates()->_notifyDirty(); - entityparts[i]->_updateAnimation(); + // entityparts[i]->_updateAnimation(); entityparts[i]->_notifyMoved(); } } From e35aee0f89766599a27c7652f0c27da5f3b38ae7 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Fri, 13 Jan 2012 02:19:28 -0500 Subject: [PATCH 103/104] Disjointed free part fix --- apps/openmw/mwrender/animation.cpp | 14 +++++++++----- apps/openmw/mwrender/renderingmanager.cpp | 2 -- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index fbe30bbb0..3bd160e6d 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -9,11 +9,15 @@ namespace MWRender{ std::string Animation::getUniqueID(std::string mesh){ int counter; - if(mUniqueIDs.find(mesh) == mUniqueIDs.end()){ - counter = mUniqueIDs[mesh] = 0; + std::string copy = mesh; + std::transform(copy.begin(), copy.end(), copy.begin(), ::tolower); + if(mUniqueIDs.find(copy) == mUniqueIDs.end()){ + counter = mUniqueIDs[copy] = 0; + } + else{ + mUniqueIDs[copy] = mUniqueIDs[copy] + 1; + counter = mUniqueIDs[copy]; } - else - counter = mUniqueIDs[mesh]++; std::stringstream out; if(counter > 99 && counter < 1000) @@ -463,7 +467,7 @@ namespace MWRender{ base->getAllAnimationStates()->_notifyDirty(); //base->_updateAnimation(); - base->_notifyMoved(); + base->_notifyMoved(); for(unsigned int i = 0; i < entityparts.size(); i++){ Ogre::SkeletonInstance* skel = entityparts[i]->getSkeleton(); diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index ae2e0f791..fff141263 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -233,13 +233,11 @@ void RenderingManager::toggleLight() void RenderingManager::playAnimationGroup (const MWWorld::Ptr& ptr, const std::string& groupName, int mode, int number) { -std::cout<<"play animation " << groupName << ", " << mode << ", " << number << std::endl; mActors.playAnimationGroup(ptr, groupName, mode, number); } void RenderingManager::skipAnimation (const MWWorld::Ptr& ptr) { -std::cout<<"skip animation"< Date: Tue, 17 Jan 2012 15:10:53 +0100 Subject: [PATCH 104/104] clean up --- apps/openmw/mwclass/npc.cpp | 5 +- apps/openmw/mwrender/animation.cpp | 136 +++++++------ apps/openmw/mwrender/creatureanimation.cpp | 10 +- apps/openmw/mwrender/npcanimation.cpp | 90 ++++----- apps/openmw/mwrender/renderingmanager.cpp | 2 +- components/nif/node.hpp | 8 +- components/nifogre/ogre_nif_loader.cpp | 220 ++++++++++----------- components/nifogre/ogre_nif_loader.hpp | 22 +-- 8 files changed, 243 insertions(+), 250 deletions(-) diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index acb0a5a35..2b98a3d60 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -38,18 +38,17 @@ namespace MWClass void Npc::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const { - + ESMS::LiveCellRef *ref = ptr.get(); - const std::string &model = ref->base->model; assert (ref->base != NULL); std::string headID = ref->base->head; std::string bodyRaceID = headID.substr(0, headID.find_last_of("head_") - 4); bool beast = bodyRaceID == "b_n_khajiit_m_" || bodyRaceID == "b_n_khajiit_f_" || bodyRaceID == "b_n_argonian_m_" || bodyRaceID == "b_n_argonian_f_"; - + std::string smodel = "meshes\\base_anim.nif"; if(beast) smodel = "meshes\\base_animkna.nif"; diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index 3bd160e6d..5a9731d2d 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -18,7 +18,7 @@ namespace MWRender{ mUniqueIDs[copy] = mUniqueIDs[copy] + 1; counter = mUniqueIDs[copy]; } - + std::stringstream out; if(counter > 99 && counter < 1000) out << "0"; @@ -38,7 +38,7 @@ namespace MWRender{ time = startTime; } else if(textmappings){ - + std::string startName = groupname + ": loop start"; std::string stopName = groupname + ": loop stop"; @@ -49,7 +49,7 @@ namespace MWRender{ stopName = groupname + ": loop stop"; for(std::map::iterator iter = textmappings->begin(); iter != textmappings->end(); iter++){ - + std::string current = iter->first.substr(0, startName.size()); std::transform(current.begin(), current.end(), current.begin(), ::tolower); std::string current2 = iter->first.substr(0, stopName.size()); @@ -71,9 +71,9 @@ namespace MWRender{ if(!first){ startName = groupname + ": start"; stopName = groupname + ": stop"; - + for(std::map::iterator iter = textmappings->begin(); iter != textmappings->end(); iter++){ - + std::string current = iter->first.substr(0, startName.size()); std::transform(current.begin(), current.end(), current.begin(), ::tolower); std::string current2 = iter->first.substr(0, stopName.size()); @@ -92,9 +92,9 @@ namespace MWRender{ } } } - + } - + } void Animation::stopScript(){ animate = 0; @@ -103,24 +103,21 @@ namespace MWRender{ void Animation::handleShapes(std::vector* allshapes, Ogre::Entity* creaturemodel, Ogre::SkeletonInstance *skel){ bool useHandles = skel == creaturemodel->getSkeleton(); shapeNumber = 0; - + std::vector::iterator allshapesiter; for(allshapesiter = allshapes->begin(); allshapesiter != allshapes->end(); allshapesiter++) - + { //std::map vecPosRot; - + Nif::NiTriShapeCopy& copy = *allshapesiter; std::vector* allvertices = ©.vertices; - std::vector* allnormals = ©.normals; - - //std::set vertices; //std::set normals; //std::vector boneinfovector = copy.boneinfo; - std::map>* verticesToChange = ©.vertsToWeights; - + std::map >* verticesToChange = ©.vertsToWeights; + //std::cout << "Name " << copy.sname << "\n"; Ogre::HardwareVertexBufferSharedPtr vbuf = creaturemodel->getMesh()->getSubMesh(copy.sname)->vertexData->vertexBufferBinding->getBuffer(0); Ogre::Real* pReal = static_cast(vbuf->lock(Ogre::HardwareBuffer::HBL_NORMAL)); @@ -135,7 +132,7 @@ namespace MWRender{ if(copy.vertices.size() == initialVertices.size()) { //Create if it doesn't already exist - if(shapeIndexI.size() == shapeNumber) + if(shapeIndexI.size() == static_cast (shapeNumber)) { std::vector vec; shapeIndexI.push_back(vec); @@ -165,10 +162,10 @@ namespace MWRender{ } - + } - + allvertices = &initialVertices; } shapeNumber++; @@ -177,8 +174,8 @@ namespace MWRender{ if(verticesToChange->size() > 0){ - - for(std::map>::iterator iter = verticesToChange->begin(); + + for(std::map >::iterator iter = verticesToChange->begin(); iter != verticesToChange->end(); iter++) { std::vector inds = iter->second; @@ -192,15 +189,15 @@ namespace MWRender{ } else bonePtr = skel->getBone(boneinfocopy->bonename); - + Ogre::Vector3 vecPos = bonePtr->_getDerivedPosition() + bonePtr->_getDerivedOrientation() * boneinfocopy->trafo.trans; Ogre::Quaternion vecRot = bonePtr->_getDerivedOrientation() * boneinfocopy->trafo.rotation; - - + + /*if(vecPosRot.find(boneinfocopy->bonehandle) == vecPosRot.end()){ vecPos = bonePtr->_getDerivedPosition() + bonePtr->_getDerivedOrientation() * boneinfocopy->trafo.trans; vecRot = bonePtr->_getDerivedOrientation() * boneinfocopy->trafo.rotation; - + if(useHandles){ PosAndRot both; both.vecPos = vecPos; @@ -215,9 +212,9 @@ namespace MWRender{ }*/ Ogre::Vector3 absVertPos = (vecPos + vecRot * currentVertex) * inds[0].weight; - - for(int i = 1; i < inds.size(); i++){ + + for(std::size_t i = 1; i < inds.size(); i++){ boneinfocopy = &(allshapesiter->boneinfo[inds[i].boneinfocopyindex]); if(useHandles) bonePtr = skel->getBone(boneinfocopy->bonehandle); @@ -229,7 +226,7 @@ namespace MWRender{ /*if(vecPosRot.find(boneinfocopy->bonehandle) == vecPosRot.end()){ vecPos = bonePtr->_getDerivedPosition() + bonePtr->_getDerivedOrientation() * boneinfocopy->trafo.trans; vecRot = bonePtr->_getDerivedOrientation() * boneinfocopy->trafo.rotation; - + if(useHandles){ PosAndRot both; both.vecPos = vecPos; @@ -243,24 +240,25 @@ namespace MWRender{ vecRot = both.vecRot; }*/ - + absVertPos += (vecPos + vecRot * currentVertex) * inds[i].weight; - + } Ogre::Real* addr = (pReal + 3 * verIndex); *addr = absVertPos.x; *(addr+1) = absVertPos.y; *(addr+2) = absVertPos.z; } - - /*for (unsigned int i = 0; i < boneinfovector.size(); i++) + +#if 0 + for (unsigned int i = 0; i < boneinfovector.size(); i++) { Nif::NiSkinData::BoneInfoCopy boneinfo = boneinfovector[i]; if(skel->hasBone(boneinfo.bonename)){ Ogre::Bone *bonePtr = skel->getBone(boneinfo.bonename); Ogre::Vector3 vecPos = bonePtr->_getDerivedPosition() + bonePtr->_getDerivedOrientation() * boneinfo.trafo.trans; Ogre::Quaternion vecRot = bonePtr->_getDerivedOrientation() * boneinfo.trafo.rotation; - + for (unsigned int j=0; j < boneinfo.weights.size(); j++) { unsigned int verIndex = boneinfo.weights[j].vertex; @@ -273,12 +271,12 @@ namespace MWRender{ *addr = absVertPos.x; *(addr+1) = absVertPos.y; *(addr+2) = absVertPos.z; - + } - else + else { - + Ogre::Vector3 absVertPos = vecPos + vecRot * allvertices[verIndex]; absVertPos = absVertPos * boneinfo.weights[j].weight; Ogre::Vector3 old = Ogre::Vector3(pReal + 3 * verIndex); @@ -287,12 +285,12 @@ namespace MWRender{ *addr = absVertPos.x; *(addr+1) = absVertPos.y; *(addr+2) = absVertPos.z; - + //std::cout << "Vertex" << verIndex << "Weight: " << boneinfo.weights[i].weight << "was seen twice\n"; } - - /*if(normals.find(verIndex) == normals.end()) + + if(normals.find(verIndex) == normals.end()) { Ogre::Vector3 absNormalsPos = vecRot * allnormals[verIndex]; absNormalsPos = absNormalsPos * boneinfo.weights[j].weight; @@ -314,16 +312,16 @@ namespace MWRender{ *(addr+1) = absNormalsPos.y; *(addr+2) = absNormalsPos.z; - }*/ - + } +#endif //} //} - - + + //} //Comment out - + ; - } + } else { //Ogre::Bone *bonePtr = creaturemodel->getSkeleton()->getBone(copy.bonename); @@ -337,9 +335,9 @@ namespace MWRender{ float scale; if(skel->hasBone(*boneSequenceIter)){ Ogre::Bone *bonePtr = skel->getBone(*boneSequenceIter); - - - + + + transmult = bonePtr->getPosition(); rotmult = bonePtr->getOrientation(); @@ -368,13 +366,13 @@ namespace MWRender{ rotmult = shaperot; scale = shapescale; } - - - + + + // Computes C = B + AxC*scale // final_vector = old_vector + old_rotation*new_vector*old_scale/ - + for(unsigned int i = 0; i < allvertices->size(); i++){ Ogre::Vector3 current = transmult + rotmult * (*allvertices)[i]; Ogre::Real* addr = pReal + i * 3; @@ -414,10 +412,10 @@ namespace MWRender{ x = 0.0; return true; } - + if ( i < 0 || i >= count ) i = 0; - + float tI = times[i]; if ( time > tI ) { @@ -457,11 +455,11 @@ namespace MWRender{ void Animation::handleAnimationTransforms(){ Ogre::SkeletonInstance* skel = base->getSkeleton(); - + Ogre::Bone* b = skel->getRootBone(); b->setOrientation(Ogre::Real(.3),Ogre::Real(.3),Ogre::Real(.3), Ogre::Real(.3)); //This is a trick - + skel->_updateTransforms(); //skel->_notifyManualBonesDirty(); @@ -474,7 +472,7 @@ namespace MWRender{ Ogre::Bone* b = skel->getRootBone(); b->setOrientation(Ogre::Real(.3),Ogre::Real(.3),Ogre::Real(.3), Ogre::Real(.3));//This is a trick - + skel->_updateTransforms(); // skel->_notifyManualBonesDirty(); @@ -492,17 +490,17 @@ namespace MWRender{ slot++; //iter++; continue; - + } float x; float x2; - + std::vector quats = iter->getQuat(); std::vector ttime = iter->gettTime(); std::vector::iterator ttimeiter = ttime.begin(); - + std::vector rtime = iter->getrTime(); int rindexJ = 0; timeIndex(time, rtime, rindexI[slot], rindexJ, x2); @@ -516,15 +514,15 @@ namespace MWRender{ //std::cout << "X: " << x << " X2: " << x2 << "\n"; Ogre::Vector3 t; Ogre::Quaternion r; - + bool bTrans = translist1.size() > 0; if(bTrans){ Ogre::Vector3 v1 = translist1[tindexI[slot]]; Ogre::Vector3 v2 = translist1[tindexJ]; t = (v1 + (v2 - v1) * x); - + } - + bool bQuats = quats.size() > 0; if(bQuats){ r = Ogre::Quaternion::Slerp(x2, quats[rindexI[slot]], quats[rindexJ], true); @@ -538,15 +536,15 @@ namespace MWRender{ if(bQuats) bone->setOrientation(r); - - + + skel->_updateTransforms(); //skel->_notifyManualBonesDirty(); base->getAllAnimationStates()->_notifyDirty(); //base->_updateAnimation(); base->_notifyMoved(); - } - for(int i = 0; i < entityparts.size(); i++){ + } + for(std::size_t i = 0; i < entityparts.size(); i++){ skel = entityparts[i]->getSkeleton(); if(skel->hasBone(iter->getBonename())){ Ogre::Bone* bone = skel->getBone(iter->getBonename()); @@ -554,17 +552,17 @@ namespace MWRender{ bone->setPosition(t); if(bQuats) bone->setOrientation(r); - + skel->_updateTransforms(); //skel->_notifyManualBonesDirty(); entityparts[i]->getAllAnimationStates()->_notifyDirty(); // entityparts[i]->_updateAnimation(); entityparts[i]->_notifyMoved(); - } + } } slot++; } } } -} \ No newline at end of file +} diff --git a/apps/openmw/mwrender/creatureanimation.cpp b/apps/openmw/mwrender/creatureanimation.cpp index c2b95186b..3cb40f2f1 100644 --- a/apps/openmw/mwrender/creatureanimation.cpp +++ b/apps/openmw/mwrender/creatureanimation.cpp @@ -14,7 +14,7 @@ CreatureAnimation::CreatureAnimation(const MWWorld::Ptr& ptr, MWWorld::Environme ESMS::LiveCellRef *ref = ptr.get(); - assert (ref->base != NULL); + assert (ref->base != NULL); if(!ref->base->model.empty()){ const std::string &mesh = "meshes\\" + ref->base->model; std::string meshNumbered = mesh + getUniqueID(mesh) + ">|"; @@ -22,9 +22,9 @@ CreatureAnimation::CreatureAnimation(const MWWorld::Ptr& ptr, MWWorld::Environme base = mRend.getScene()->createEntity(meshNumbered); std::string meshZero = mesh + "0000>|"; - if(transformations = (NIFLoader::getSingletonPtr())->getAnim(meshZero)){ + if((transformations = (NIFLoader::getSingletonPtr())->getAnim(meshZero))){ - for(int init = 0; init < transformations->size(); init++){ + for(std::size_t init = 0; init < transformations->size(); init++){ rindexI.push_back(0); tindexI.push_back(0); } @@ -53,10 +53,10 @@ void CreatureAnimation::runAnimation(float timepassed){ else time = startTime + (time - stopTime); } - + handleAnimationTransforms(); handleShapes(shapes, base, base->getSkeleton()); } } -} \ No newline at end of file +} diff --git a/apps/openmw/mwrender/npcanimation.cpp b/apps/openmw/mwrender/npcanimation.cpp index 0ff679507..ef5c10559 100644 --- a/apps/openmw/mwrender/npcanimation.cpp +++ b/apps/openmw/mwrender/npcanimation.cpp @@ -13,7 +13,7 @@ NpcAnimation::~NpcAnimation(){ NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, MWWorld::Environment& _env,OEngine::Render::OgreRenderer& _rend): Animation(_env,_rend){ ESMS::LiveCellRef *ref = ptr.get(); - + //Part selection on last character of the file string // " Tri Chest // * Tri Tail @@ -35,10 +35,10 @@ NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, MWWorld::Environment& _env,O std::string hairID = ref->base->hair; std::string headID = ref->base->head; std::string npcName = ref->base->name; - //ESMStore::Races r = + //ESMStore::Races r = const ESM::Race* race = mEnvironment.mWorld->getStore().races.find(ref->base->race); - - + + std::string bodyRaceID = headID.substr(0, headID.find_last_of("head_") - 4); char secondtolast = bodyRaceID.at(bodyRaceID.length() - 2); bool female = tolower(secondtolast) == 'f'; @@ -51,7 +51,7 @@ NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, MWWorld::Environment& _env,O std::cout << " Sex: Male" << " Height: " << race->data.height.male << "\n"; }*/ - + std::string smodel = "meshes\\base_anim.nif"; if(beast) @@ -61,25 +61,25 @@ NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, MWWorld::Environment& _env,O assert(insert); NifOgre::NIFLoader::load(smodel); - + base = mRend.getScene()->createEntity(smodel); - base->setSkipAnimationStateUpdate(true); //Magical line of code, this makes the bones + base->setSkipAnimationStateUpdate(true); //Magical line of code, this makes the bones //stay in the same place when we skipanim, or open a gui window - - if(transformations = (NIFLoader::getSingletonPtr())->getAnim(smodel)){ + + if((transformations = (NIFLoader::getSingletonPtr())->getAnim(smodel))){ for(unsigned int init = 0; init < transformations->size(); init++){ rindexI.push_back(0); tindexI.push_back(0); } - + stopTime = transformations->begin()->getStopTime(); startTime = transformations->begin()->getStartTime(); } textmappings = NIFLoader::getSingletonPtr()->getTextIndices(smodel); insert->attachObject(base); - + if(female) insert->scale(race->data.height.female, race->data.height.female, race->data.height.female); else @@ -108,18 +108,18 @@ NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, MWWorld::Environment& _env,O forearml = mEnvironment.mWorld->getStore().bodyParts.search ("b_n_argonian_m_forearm"); //We need two if(!handl) handl = mEnvironment.mWorld->getStore().bodyParts.search (bodyRaceID + "hands"); - //const ESM::BodyPart* claviclel = environment.mWorld->getStore().bodyParts.search (bodyRaceID + "clavicle"); + //const ESM::BodyPart* claviclel = environment.mWorld->getStore().bodyParts.search (bodyRaceID + "clavicle"); //const ESM::BodyPart* clavicler = claviclel; const ESM::BodyPart* handr = handl; const ESM::BodyPart* forearmr = forearml; const ESM::BodyPart* wristr = wristl; const ESM::BodyPart* armr = arml; - + if(upperleg){ insertBoundedPart("meshes\\" + upperleg->model + "*|", "Left Upper Leg"); insertBoundedPart("meshes\\" + upperleg->model, "Right Upper Leg"); - + } if(foot){ if(bodyRaceID.compare("b_n_khajiit_m_") == 0) @@ -139,10 +139,10 @@ NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, MWWorld::Environment& _env,O { insertBoundedPart("meshes\\" + knee->model + "*|", "Left Knee"); //e insertBoundedPart("meshes\\" + knee->model, "Right Knee"); //e - + } if(ankle){ - + insertBoundedPart("meshes\\" + ankle->model + "*|", "Left Ankle"); //Ogre::Quaternion(Ogre::Radian(3.14 / 4), Ogre::Vector3(1, 0, 0)),blank); //1,0,0, blank); insertBoundedPart("meshes\\" + ankle->model, "Right Ankle"); } @@ -167,17 +167,17 @@ NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, MWWorld::Environment& _env,O if(wristl) insertBoundedPart("meshes\\" + wristl->model + "*|", "Left Wrist"); - - - - + + + + /*if(claviclel) insertBoundedPart("meshes\\" + claviclel->model + "*|", "Left Clavicle", base); if(clavicler) insertBoundedPart("meshes\\" + clavicler->model , "Right Clavicle", base);*/ - - + + if(neck) { insertBoundedPart("meshes\\" + neck->model, "Neck"); @@ -186,19 +186,19 @@ NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, MWWorld::Environment& _env,O insertBoundedPart("meshes\\" + head->model, "Head"); if(hair) insertBoundedPart("meshes\\" + hair->model, "Head"); - + if (chest){ insertFreePart("meshes\\" + chest->model, ">\"", insert); - - + + } if (handr){ insertFreePart("meshes\\" + handr->model , ">?", insert); - + } if (handl){ insertFreePart("meshes\\" + handl->model, ">>", insert); - + } if(tail){ insertFreePart("meshes\\" + tail->model, ">*", insert); @@ -215,16 +215,16 @@ NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, MWWorld::Environment& _env,O Ogre::Entity* NpcAnimation::insertBoundedPart(const std::string &mesh, std::string bonename){ NIFLoader::load(mesh); Entity* ent = mRend.getScene()->createEntity(mesh); - - base->attachObjectToBone(bonename, ent); + + base->attachObjectToBone(bonename, ent); return ent; } void NpcAnimation::insertFreePart(const std::string &mesh, const std::string suffix, Ogre::SceneNode* insert){ - std::string meshNumbered = mesh + getUniqueID(mesh + suffix) + suffix; + std::string meshNumbered = mesh + getUniqueID(mesh + suffix) + suffix; NIFLoader::load(meshNumbered); - + Ogre::Entity* ent = mRend.getScene()->createEntity(meshNumbered); - + /*MaterialPtr material = ent->getSubEntity(0)->getMaterial(); material->removeAllTechniques(); @@ -234,7 +234,7 @@ void NpcAnimation::insertFreePart(const std::string &mesh, const std::string suf pass2->setVertexProgram("Ogre/HardwareSkinningTwoWeights"); pass2->setColourWriteEnabled(false); //tech->setSchemeName("blahblah");*/ - + insert->attachObject(ent); entityparts.push_back(ent); @@ -244,7 +244,7 @@ void NpcAnimation::insertFreePart(const std::string &mesh, const std::string suf handleShapes(shapes, ent, base->getSkeleton()); } - + } @@ -256,10 +256,10 @@ void NpcAnimation::runAnimation(float timepassed){ //3. Handle the shapes dependent on animation transforms if(animate > 0){ time += timepassed; - + if(time > stopTime){ animate--; - + if(animate == 0) time = stopTime; else @@ -270,21 +270,21 @@ void NpcAnimation::runAnimation(float timepassed){ Ogre::Vector3 current = insert->_getWorldAABB().getCenter(); //This is the attempt at npc physics - //mEnvironment.mWorld->setObjectPhysicsPosition(insert->getName(), current); + //mEnvironment.mWorld->setObjectPhysicsPosition(insert->getName(), current); + - /*if(base->hasSkeleton()) { - + Ogre::Quaternion boneQuat = rotate; Ogre::Vector3 boneTrans = trans; mEnvironment.mWorld->setObjectPhysicsPosition(insert->getName(), boneTrans + insert->getPosition()); //mEnvironment.mWorld->setObjectPhysicsRotation(insert->getName(), boneQuat * insert->getOrientation()); - + }*/ - - + + std::vector*>::iterator shapepartsiter = shapeparts.begin(); std::vector::iterator entitypartsiter = entityparts.begin(); while(shapepartsiter != shapeparts.end()) @@ -292,12 +292,12 @@ void NpcAnimation::runAnimation(float timepassed){ std::vector* shapes = *shapepartsiter; Ogre::Entity* theentity = *entitypartsiter; /* - Pass* pass = theentity->getSubEntity(0)->getMaterial()->getBestTechnique()->getPass(0); + Pass* pass = theentity->getSubEntity(0)->getMaterial()->getBestTechnique()->getPass(0); if (pass->hasVertexProgram() && pass->getVertexProgram()->isSkeletalAnimationIncluded()) std::cout << "It's hardware\n"; else std::cout << "It's software\n";*/ - + handleShapes(shapes, theentity, theentity->getSkeleton()); shapepartsiter++; entitypartsiter++; @@ -305,4 +305,4 @@ void NpcAnimation::runAnimation(float timepassed){ } } -} \ No newline at end of file +} diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index fff141263..6215c1913 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -22,7 +22,7 @@ namespace MWRender { RenderingManager::RenderingManager (OEngine::Render::OgreRenderer& _rend, const boost::filesystem::path& resDir, OEngine::Physic::PhysicEngine* engine, MWWorld::Environment& environment) -:mRendering(_rend), mObjects(mRendering), mDebugging(engine), mActors(mRendering, environment) +:mRendering(_rend), mObjects(mRendering), mActors(mRendering, environment), mDebugging(engine) { mRendering.createScene("PlayerCam", 55, 5); mSkyManager = MWRender::SkyManager::create(mRendering.getWindow(), mRendering.getCamera(), resDir); diff --git a/components/nif/node.hpp b/components/nif/node.hpp index bbceb866e..080042746 100644 --- a/components/nif/node.hpp +++ b/components/nif/node.hpp @@ -103,7 +103,7 @@ struct NiTriShapeCopy std::vector vertices; std::vector normals; std::vector boneinfo; - std::map> vertsToWeights; + std::map > vertsToWeights; Nif::NiMorphData morph; }; @@ -158,13 +158,13 @@ struct NiTriShape : Node { float *current = (float*) (ptr + i * 3); copy.vertices.push_back(Ogre::Vector3(*current, *(current + 1), *(current + 2))); - + if(ptrNormals){ float *currentNormals = (float*) (ptrNormals + i * 3); - copy.normals.push_back(Ogre::Vector3(*currentNormals, *(currentNormals + 1), *(currentNormals + 2))); + copy.normals.push_back(Ogre::Vector3(*currentNormals, *(currentNormals + 1), *(currentNormals + 2))); } } - + return copy; } diff --git a/components/nifogre/ogre_nif_loader.cpp b/components/nifogre/ogre_nif_loader.cpp index 92a5713a3..c62f59ea3 100644 --- a/components/nifogre/ogre_nif_loader.cpp +++ b/components/nifogre/ogre_nif_loader.cpp @@ -222,7 +222,7 @@ void NIFLoader::createMaterial(const String &name, //Hardware Skinning code, textures may be the wrong color if enabled /*if(!mSkel.isNull()){ material->removeAllTechniques(); - + Ogre::Technique* tech = material->createTechnique(); //tech->setSchemeName("blahblah"); Pass* pass = tech->createPass(); @@ -234,8 +234,8 @@ void NIFLoader::createMaterial(const String &name, // will automatically be loaded when needed. If not (such as for // internal NIF textures that we might support later), we should // already have inserted a manual loader for the texture. - - + + if (!texName.empty()) { Pass *pass = material->getTechnique(0)->getPass(0); @@ -295,8 +295,8 @@ void NIFLoader::createMaterial(const String &name, material->setSpecular(specular.array[0], specular.array[1], specular.array[2], alpha); material->setSelfIllumination(emissive.array[0], emissive.array[1], emissive.array[2]); material->setShininess(glossiness); - - + + } // Takes a name and adds a unique part to it. This is just used to @@ -359,7 +359,7 @@ void NIFLoader::createOgreSubMesh(NiTriShape *shape, const String &material, std HardwareBufferManager::getSingleton().createVertexBuffer( VertexElement::getTypeSize(VET_FLOAT3), numVerts, HardwareBuffer::HBU_STATIC_WRITE_ONLY, false); - + if(flip) { float *datamod = new float[data->vertices.length]; @@ -381,7 +381,7 @@ void NIFLoader::createOgreSubMesh(NiTriShape *shape, const String &material, std { vbuf->writeData(0, vbuf->getSizeInBytes(), data->vertices.ptr, false); } - + VertexBufferBinding* bind = sub->vertexData->vertexBufferBinding; bind->setBinding(nextBuf++, vbuf); @@ -392,7 +392,7 @@ void NIFLoader::createOgreSubMesh(NiTriShape *shape, const String &material, std vbuf = HardwareBufferManager::getSingleton().createVertexBuffer( VertexElement::getTypeSize(VET_FLOAT3), numVerts, HardwareBuffer::HBU_STATIC_WRITE_ONLY, false); - + if(flip) { Quaternion rotation = mTransform.extractQuaternion(); @@ -456,10 +456,10 @@ void NIFLoader::createOgreSubMesh(NiTriShape *shape, const String &material, std if(flip) { float *datamod = new float[data->uvlist.length]; - + for(unsigned int i = 0; i < data->uvlist.length; i+=2){ float x = *(data->uvlist.ptr + i); - + float y = *(data->uvlist.ptr + i + 1); datamod[i] =x; @@ -474,10 +474,10 @@ void NIFLoader::createOgreSubMesh(NiTriShape *shape, const String &material, std // Triangle faces - The total number of triangle points int numFaces = data->triangles.length; - + if (numFaces) { - + sub->indexData->indexCount = numFaces; sub->indexData->indexStart = 0; HardwareIndexBufferSharedPtr ibuf = HardwareBufferManager::getSingleton(). @@ -508,14 +508,14 @@ void NIFLoader::createOgreSubMesh(NiTriShape *shape, const String &material, std index += 3; } - + ibuf->writeData(0, ibuf->getSizeInBytes(), datamod, false); } else ibuf->writeData(0, ibuf->getSizeInBytes(), data->triangles.ptr, false); sub->indexData->indexBuffer = ibuf; - + } @@ -753,9 +753,9 @@ void NIFLoader::handleNiTriShape(NiTriShape *shape, int flags, BoundsFinder &bou //use niskindata for the position of vertices. if (!shape->skin.empty()) { - - - + + + // vector that stores if the position of a vertex is absolute std::vector vertexPosAbsolut(numVerts,false); std::vector vertexPosOriginal(numVerts, Ogre::Vector3::ZERO); @@ -791,7 +791,7 @@ void NIFLoader::handleNiTriShape(NiTriShape *shape, int flags, BoundsFinder &bou bonePtr = mSkel->getBone(shape->skin->bones[boneIndex].name.toString()); // final_vector = old_vector + old_rotation*new_vector*old_scale - + Nif::NiSkinData::BoneInfoCopy boneinfocopy; boneinfocopy.trafo.rotation = convertRotation(it->trafo->rotation); @@ -841,7 +841,7 @@ void NIFLoader::handleNiTriShape(NiTriShape *shape, int flags, BoundsFinder &bou Vector3 absNormalsPos = vecRot * Vector3(ptrNormals + verIndex *3); absNormalsPos = absNormalsPos * (it->weights.ptr + i)->weight; vertexNormalOriginal[verIndex] = Vector3(ptrNormals + verIndex *3); - + for (int j=0; j<3; j++) (ptrNormals + verIndex*3)[j] = absNormalsPos[j]; } @@ -868,7 +868,7 @@ void NIFLoader::handleNiTriShape(NiTriShape *shape, int flags, BoundsFinder &bou absNormalsPos = absNormalsPos * (it->weights.ptr + i)->weight; Vector3 oldNormal = Vector3(ptrNormals + verIndex *3); absNormalsPos = absNormalsPos + oldNormal; - + for (int j=0; j<3; j++) (ptrNormals + verIndex*3)[j] = absNormalsPos[j]; } @@ -879,19 +879,19 @@ void NIFLoader::handleNiTriShape(NiTriShape *shape, int flags, BoundsFinder &bou vba.boneIndex = bonePtr->getHandle(); vba.vertexIndex = verIndex; vba.weight = (it->weights.ptr + i)->weight; - + vertexBoneAssignments.push_back(vba); } - + boneIndex++; } - + } else { - + copy.boneSequence = boneSequence; // Rotate, scale and translate all the vertices, const Matrix &rot = shape->trafo->rotation; @@ -902,7 +902,7 @@ void NIFLoader::handleNiTriShape(NiTriShape *shape, int flags, BoundsFinder &bou copy.trafo.rotation = convertRotation(original.rotation); copy.trafo.scale = original.scale; //We don't use velocity for anything yet, so it does not need to be saved - + // Computes C = B + AxC*scale for (int i=0; inormals.length) { @@ -955,7 +955,7 @@ void NIFLoader::calculateTransform() // Calculate transform Matrix4 transform = Matrix4::IDENTITY; transform = Matrix4::getScale(vector) * transform; - + // Check whether we have to flip vertex winding. // We do have to, if we changed our right hand base. // We can test it by using the cross product from X and Y and see, if it is a non-negative @@ -963,7 +963,7 @@ void NIFLoader::calculateTransform() // but the test is cheap either way. Matrix3 m3; transform.extract3x3Matrix(m3); - + if (m3.GetColumn(0).crossProduct(m3.GetColumn(1)).dotProduct(m3.GetColumn(2)) < 0) { mFlipVertexWinding = true; @@ -1003,39 +1003,38 @@ void NIFLoader::handleNode(Nif::Node *node, int flags, } if (e->recType == RC_NiTextKeyExtraData){ - Nif::NiTextKeyExtraData* extra = dynamic_cast (e); - - std::ofstream file; + Nif::NiTextKeyExtraData* extra = dynamic_cast (e); + + std::ofstream file; if(mOutputAnimFiles){ - std::string cut = ""; - for(unsigned int i = 0; i < name.length(); i++) - { - if(!(name.at(i) == '\\' || name.at(i) == '/' || name.at(i) == '>' || name.at(i) == '<' || name.at(i) == '?' || name.at(i) == '*' || name.at(i) == '|' || name.at(i) == ':' || name.at(i) == '"')) - { - cut += name.at(i); - } - } - - std::cout << "Outputting " << cut << "\n"; - - file.open((verbosePath + "/Indices" + cut + ".txt").c_str()); + std::string cut = ""; + for(unsigned int i = 0; i < name.length(); i++) + { + if(!(name.at(i) == '\\' || name.at(i) == '/' || name.at(i) == '>' || name.at(i) == '<' || name.at(i) == '?' || name.at(i) == '*' || name.at(i) == '|' || name.at(i) == ':' || name.at(i) == '"')) + { + cut += name.at(i); + } + } + + std::cout << "Outputting " << cut << "\n"; + + file.open((verbosePath + "/Indices" + cut + ".txt").c_str()); } - - for(std::vector::iterator textiter = extra->list.begin(); textiter != extra->list.end(); textiter++) - { - - std::string text = textiter->text.toString(); - - replace(text.begin(), text.end(), '\n', '/'); - text.erase(std::remove(text.begin(), text.end(), '\r'), text.end()); - int i = 0; + for(std::vector::iterator textiter = extra->list.begin(); textiter != extra->list.end(); textiter++) + { + std::string text = textiter->text.toString(); + + replace(text.begin(), text.end(), '\n', '/'); + + text.erase(std::remove(text.begin(), text.end(), '\r'), text.end()); + std::size_t i = 0; while(i < text.length()){ while(i < text.length() && text.at(i) == '/' ){ i++; } - int first = i; + std::size_t first = i; int length = 0; while(i < text.length() && text.at(i) != '/' ){ i++; @@ -1045,15 +1044,15 @@ void NIFLoader::handleNode(Nif::Node *node, int flags, //length = text.length() - first; std::string sub = text.substr(first, length); - if(mOutputAnimFiles) + if(mOutputAnimFiles) file << "Time: " << textiter->time << "|" << sub << "\n"; - - textmappings[sub] = textiter->time; + + textmappings[sub] = textiter->time; } } - } - file.close(); - } + } + file.close(); + } } Bone *bone = 0; @@ -1064,7 +1063,7 @@ void NIFLoader::handleNode(Nif::Node *node, int flags, //FIXME: "Bip01" isn't every time the root bone if (node->name == "Bip01" || node->name == "Root Bone") //root node, create a skeleton { - + mSkel = SkeletonManager::getSingleton().create(getSkeletonName(), resourceGroup, true); } @@ -1072,7 +1071,7 @@ void NIFLoader::handleNode(Nif::Node *node, int flags, { std::string name = node->name.toString(); boneSequence.push_back(name); - + // Quick-n-dirty workaround for the fact that several // bones may have the same name. if(!mSkel->hasBone(name)) @@ -1125,7 +1124,7 @@ void NIFLoader::handleNode(Nif::Node *node, int flags, else if (node->recType == RC_NiTriShape && bNiTri) { std::string nodename = node->name.toString(); - + if (triname == "") { handleNiTriShape(dynamic_cast(node), flags, bounds, original, boneSequence); @@ -1172,12 +1171,12 @@ void NIFLoader::loadResource(Resource *resource) baddin = true; bNiTri = true; std::string sub = name.substr(name.length() - 6, 4); - + if(sub.compare("0000") != 0) addAnim = false; - + } - + switch(name.at(name.length() - 1)) { case '"': @@ -1253,33 +1252,30 @@ void NIFLoader::loadResource(Resource *resource) // Handle the node std::vector boneSequence; - - + + handleNode(node, 0, NULL, bounds, 0, boneSequence); if(addAnim) { for(int i = 0; i < nif.numRecords(); i++) - { - Nif::NiKeyframeController *f = dynamic_cast(nif.getRecord(i)); - - Nif::Node *n = dynamic_cast(nif.getRecord(i)); - if(f != NULL) - { - hasAnim = true; - Nif::Node *o = dynamic_cast(f->target.getPtr()); - Nif::NiKeyframeDataPtr data = f->data; - - if (f->timeStart == 10000000000000000) - continue; - data->setBonename(o->name.toString()); - data->setStartTime(f->timeStart); - data->setStopTime(f->timeStop); - - allanim.push_back(data.get()); - - - } + { + Nif::NiKeyframeController *f = dynamic_cast(nif.getRecord(i)); + + if(f != NULL) + { + hasAnim = true; + Nif::Node *o = dynamic_cast(f->target.getPtr()); + Nif::NiKeyframeDataPtr data = f->data; + + if (f->timeStart == 10000000000000000) + continue; + data->setBonename(o->name.toString()); + data->setStartTime(f->timeStart); + data->setStopTime(f->timeStop); + + allanim.push_back(data.get()); + } } } // set the bounding value. @@ -1290,18 +1286,18 @@ void NIFLoader::loadResource(Resource *resource) mesh->_setBoundingSphereRadius(bounds.getRadius()); } if(hasAnim && addAnim){ - allanimmap[name] = allanim; - alltextmappings[name] = textmappings; - } - if(!mSkel.isNull() && shapes.size() > 0 && addAnim) - { - allshapesmap[name] = shapes; - - } - + allanimmap[name] = allanim; + alltextmappings[name] = textmappings; + } + if(!mSkel.isNull() && shapes.size() > 0 && addAnim) + { + allshapesmap[name] = shapes; + + } + if(flip){ - mesh->_setBounds(mBoundingBox, false); - } + mesh->_setBounds(mBoundingBox, false); + } if (!mSkel.isNull()) { @@ -1310,7 +1306,7 @@ void NIFLoader::loadResource(Resource *resource) } void NIFLoader::addInMesh(Ogre::Mesh* input){ - addin.push_back(input); + addin.push_back(input); } @@ -1318,7 +1314,7 @@ void NIFLoader::addInMesh(Ogre::Mesh* input){ MeshPtr NIFLoader::load(const std::string &name, const std::string &group) { - + MeshManager *m = MeshManager::getSingletonPtr(); // Check if the resource already exists ResourcePtr ptr = m->getByName(name, group); @@ -1335,26 +1331,26 @@ MeshPtr NIFLoader::load(const std::string &name, /* This function shares much of the same code handleShapes() in MWRender::Animation -This function also creates new position and normal buffers for submeshes. +This function also creates new position and normal buffers for submeshes. This function points to existing texture and IndexData buffers */ std::vector* NIFLoader::getAnim(std::string lowername){ - - std::map,ciLessBoost>::iterator iter = allanimmap.find(lowername); + + std::map,ciLessBoost>::iterator iter = allanimmap.find(lowername); std::vector* pass = 0; - if(iter != allanimmap.end()) - pass = &(iter->second); - return pass; - + if(iter != allanimmap.end()) + pass = &(iter->second); + return pass; + } std::vector* NIFLoader::getShapes(std::string lowername){ - - std::map,ciLessBoost>::iterator iter = allshapesmap.find(lowername); + + std::map,ciLessBoost>::iterator iter = allshapesmap.find(lowername); std::vector* pass = 0; - if(iter != allshapesmap.end()) - pass = &(iter->second); - return pass; + if(iter != allshapesmap.end()) + pass = &(iter->second); + return pass; } std::map* NIFLoader::getTextIndices(std::string lowername){ diff --git a/components/nifogre/ogre_nif_loader.hpp b/components/nifogre/ogre_nif_loader.hpp index fd1620822..62239bb4c 100644 --- a/components/nifogre/ogre_nif_loader.hpp +++ b/components/nifogre/ogre_nif_loader.hpp @@ -79,7 +79,7 @@ namespace Mangle namespace NifOgre { - + /** Manual resource loader for NIF meshes. This is the main class responsible for translating the internal NIF mesh structure into @@ -109,7 +109,7 @@ class NIFLoader : Ogre::ManualResourceLoader const std::string &group="General"); //void insertMeshInsideBase(Ogre::Mesh* mesh); std::vector* getAnim(std::string name); - std::vector* getShapes(std::string name); + std::vector* getShapes(std::string name); std::map* getTextIndices(std::string name); void addInMesh(Ogre::Mesh* input); @@ -121,12 +121,12 @@ class NIFLoader : Ogre::ManualResourceLoader void setVerbosePath(std::string path); private: - NIFLoader() : mNormaliseNormals(false), resourceGroup("General"), resourceName(""), flip(false), + NIFLoader() : resourceName(""), resourceGroup("General"), flip(false), mNormaliseNormals(false), mFlipVertexWinding(false), mOutputAnimFiles(false) {} NIFLoader(NIFLoader& n) {} void calculateTransform(); - + void warn(std::string msg); void fail(std::string msg); @@ -167,7 +167,7 @@ class NIFLoader : Ogre::ManualResourceLoader std::string verbosePath; std::string resourceName; std::string resourceGroup; - Ogre::Matrix4 mTransform; + Ogre::Matrix4 mTransform; Ogre::AxisAlignedBox mBoundingBox; bool flip; bool mNormaliseNormals; @@ -184,14 +184,14 @@ class NIFLoader : Ogre::ManualResourceLoader std::string name; std::string triname; std::vector allanim; - std::map textmappings; - std::map,ciLessBoost> alltextmappings; - std::map,ciLessBoost> allanimmap; - std::map,ciLessBoost> allshapesmap; + std::map textmappings; + std::map,ciLessBoost> alltextmappings; + std::map,ciLessBoost> allanimmap; + std::map,ciLessBoost> allshapesmap; std::vector addin; std::vector mAnim; - std::vector mS; - + std::vector mS; + }; }