From bd8f0248f00c537bca974f3998eae44fafb30b56 Mon Sep 17 00:00:00 2001 From: scrawl Date: Fri, 1 May 2015 18:21:50 +0200 Subject: [PATCH] Player rendering --- .../mwmechanics/mechanicsmanagerimp.cpp | 2 ++ apps/openmw/mwrender/animation.cpp | 2 ++ apps/openmw/mwrender/objects.cpp | 12 -------- apps/openmw/mwrender/renderingmanager.cpp | 29 +++++++++++++++++++ apps/openmw/mwrender/renderingmanager.hpp | 11 ++++++- apps/openmw/mwworld/worldimp.cpp | 15 ++++++---- 6 files changed, 53 insertions(+), 18 deletions(-) diff --git a/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp b/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp index 7e6e29670..077f67b5e 100644 --- a/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp +++ b/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp @@ -1318,6 +1318,8 @@ namespace MWMechanics bool MechanicsManager::awarenessCheck(const MWWorld::Ptr &ptr, const MWWorld::Ptr &observer) { + return false; + if (observer.getClass().getCreatureStats(observer).isDead() || !observer.getRefData().isEnabled()) return false; diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index 245095492..1f749ab4e 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -866,6 +866,8 @@ namespace MWRender NodeMapVisitor visitor; mObjectRoot->accept(visitor); mNodeMap = visitor.getNodeMap(); + + mObjectRoot->addCullCallback(new SceneUtil::LightListCallback); } osg::Group* Animation::getObjectRoot() diff --git a/apps/openmw/mwrender/objects.cpp b/apps/openmw/mwrender/objects.cpp index f77865634..a06b751cc 100644 --- a/apps/openmw/mwrender/objects.cpp +++ b/apps/openmw/mwrender/objects.cpp @@ -10,9 +10,6 @@ #include #include -// light -#include - #include #include @@ -112,9 +109,6 @@ void Objects::insertModel(const MWWorld::Ptr &ptr, const std::string &mesh, bool std::auto_ptr anim (new ObjectAnimation(ptr, mesh, mResourceSystem, allowLight)); - if (anim->getObjectRoot()) - anim->getObjectRoot()->addCullCallback(new SceneUtil::LightListCallback); - if (!allowLight) { RemoveParticlesVisitor visitor; @@ -137,9 +131,6 @@ void Objects::insertCreature(const MWWorld::Ptr &ptr, const std::string &mesh, b else anim.reset(new CreatureAnimation(ptr, mesh, mResourceSystem)); - if (anim->getObjectRoot()) - anim->getObjectRoot()->addCullCallback(new SceneUtil::LightListCallback); - mObjects.insert(std::make_pair(ptr, anim.release())); } @@ -149,9 +140,6 @@ void Objects::insertNPC(const MWWorld::Ptr &ptr) std::auto_ptr anim (new NpcAnimation(ptr, osg::ref_ptr(ptr.getRefData().getBaseNode()), mResourceSystem, 0)); - if (anim->getObjectRoot()) - anim->getObjectRoot()->addCullCallback(new SceneUtil::LightListCallback); - mObjects.insert(std::make_pair(ptr, anim.release())); } diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index 8689935d0..d07c98ed7 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -23,6 +23,7 @@ #include "sky.hpp" #include "effectmanager.hpp" +#include "npcanimation.hpp" #include "vismask.hpp" namespace MWRender @@ -82,6 +83,7 @@ namespace MWRender , mResourceSystem(resourceSystem) { osg::ref_ptr lightRoot = new SceneUtil::LightManager; + mLightRoot = lightRoot; lightRoot->setStartLight(1); mRootNode->addChild(lightRoot); @@ -258,4 +260,31 @@ namespace MWRender return mObjects->getAnimation(ptr); } + MWRender::Animation* RenderingManager::getPlayerAnimation() + { + return mPlayerAnimation.get(); + } + + void RenderingManager::setupPlayer(const MWWorld::Ptr &player) + { + if (!mPlayerNode) + { + mPlayerNode = new osg::PositionAttitudeTransform; + mLightRoot->addChild(mPlayerNode); + } + + player.getRefData().setBaseNode(mPlayerNode); + + //attachCameraTo(player); + } + + void RenderingManager::renderPlayer(const MWWorld::Ptr &player) + { + mPlayerAnimation.reset(new NpcAnimation(player, player.getRefData().getBaseNode(), mResourceSystem, 0)); + + //mCamera->setAnimation(mPlayerAnimation); + //mWater->removeEmitter(ptr); + //mWater->addEmitter(ptr); + } + } diff --git a/apps/openmw/mwrender/renderingmanager.hpp b/apps/openmw/mwrender/renderingmanager.hpp index 005100701..71c70b990 100644 --- a/apps/openmw/mwrender/renderingmanager.hpp +++ b/apps/openmw/mwrender/renderingmanager.hpp @@ -11,6 +11,7 @@ namespace osg { class Group; + class PositionAttitudeTransform; } namespace Resource @@ -35,6 +36,7 @@ namespace MWRender class EffectManager; class SkyManager; + class NpcAnimation; class RenderingManager : public MWRender::RenderingInterface { @@ -78,11 +80,16 @@ namespace MWRender void update(float dt, bool paused); - MWRender::Animation* getAnimation(const MWWorld::Ptr& ptr); + Animation* getAnimation(const MWWorld::Ptr& ptr); + Animation* getPlayerAnimation(); + + void setupPlayer(const MWWorld::Ptr& player); + void renderPlayer(const MWWorld::Ptr& player); private: osgViewer::Viewer& mViewer; osg::ref_ptr mRootNode; + osg::ref_ptr mLightRoot; Resource::ResourceSystem* mResourceSystem; osg::ref_ptr mSunLight; @@ -90,6 +97,8 @@ namespace MWRender std::auto_ptr mObjects; std::auto_ptr mSky; std::auto_ptr mEffectManager; + std::auto_ptr mPlayerAnimation; + osg::ref_ptr mPlayerNode; osg::ref_ptr mStateUpdater; diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 4e737fc07..8cb9f4d50 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -1563,7 +1563,8 @@ namespace MWWorld } const ESM::NPC *ret = mStore.insert(record); if (update) { - //mRendering->renderPlayer(mPlayer->getPlayer()); + mRendering->renderPlayer(getPlayerPtr()); + scaleObject(getPlayerPtr(), 1.f); // apply race height } return ret; } @@ -2120,18 +2121,20 @@ namespace MWWorld mPlayer->set(player); } - //Ptr ptr = mPlayer->getPlayer(); - //mRendering->setupPlayer(ptr); + Ptr ptr = mPlayer->getPlayer(); + mRendering->setupPlayer(ptr); } void World::renderPlayer() { - //mRendering->renderPlayer(mPlayer->getPlayer()); + mRendering->renderPlayer(getPlayerPtr()); + + scaleObject(getPlayerPtr(), 1.f); // apply race height // At this point the Animation object is live, and the CharacterController associated with it must be created. // It has to be done at this point: resetCamera below does animation->setViewMode -> CharacterController::forceStateUpdate // so we should make sure not to use a "stale" controller for that. - MWBase::Environment::get().getMechanicsManager()->add(mPlayer->getPlayer()); + MWBase::Environment::get().getMechanicsManager()->add(getPlayerPtr()); std::string model = getPlayerPtr().getClass().getModel(getPlayerPtr()); //model = Misc::ResourceHelpers::correctActorModelPath(model); @@ -2163,6 +2166,8 @@ namespace MWWorld MWRender::Animation* World::getAnimation(const MWWorld::Ptr &ptr) { + if (ptr == getPlayerPtr()) + return mRendering->getPlayerAnimation(); return mRendering->getAnimation(ptr); }