mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-22 15:23:58 +00:00
Feature #37 (In Progress) Render Path Grid
improved path grid point mesh (closer to vanilla MW)
This commit is contained in:
parent
a7f89b864e
commit
a8e25bc32c
2 changed files with 86 additions and 24 deletions
|
@ -4,6 +4,8 @@
|
||||||
|
|
||||||
#include <OgreNode.h>
|
#include <OgreNode.h>
|
||||||
#include <OgreSceneManager.h>
|
#include <OgreSceneManager.h>
|
||||||
|
#include <OgreMaterial.h>
|
||||||
|
#include <OgreMaterialManager.h>
|
||||||
|
|
||||||
#include "../mwworld/world.hpp" // these includes can be removed once the static-hack is gone
|
#include "../mwworld/world.hpp" // these includes can be removed once the static-hack is gone
|
||||||
#include "../mwworld/environment.hpp"
|
#include "../mwworld/environment.hpp"
|
||||||
|
@ -18,12 +20,15 @@ using namespace Ogre;
|
||||||
namespace MWRender
|
namespace MWRender
|
||||||
{
|
{
|
||||||
|
|
||||||
|
static const std::string PATHGRID_POINT_MATERIAL = "pathgridPointMaterial";
|
||||||
static const std::string PATHGRID_LINE_MATERIAL = "pathgridLineMaterial";
|
static const std::string PATHGRID_LINE_MATERIAL = "pathgridLineMaterial";
|
||||||
static const std::string DEBUGGING_GROUP = "debugging";
|
static const std::string DEBUGGING_GROUP = "debugging";
|
||||||
|
static const int POINT_MESH_BASE = 80;
|
||||||
|
|
||||||
ManualObject *createPathgridLine(SceneManager* sceneMgr, const Vector3& from, const Vector3& to)
|
void Debugging::createGridMaterials()
|
||||||
{
|
{
|
||||||
ManualObject *line = sceneMgr->createManualObject();
|
if (mGridMatsCreated) return;
|
||||||
|
|
||||||
if (MaterialManager::getSingleton().getByName(PATHGRID_LINE_MATERIAL, DEBUGGING_GROUP).isNull())
|
if (MaterialManager::getSingleton().getByName(PATHGRID_LINE_MATERIAL, DEBUGGING_GROUP).isNull())
|
||||||
{
|
{
|
||||||
MaterialPtr lineMatPtr = MaterialManager::getSingleton().create(PATHGRID_LINE_MATERIAL, DEBUGGING_GROUP);
|
MaterialPtr lineMatPtr = MaterialManager::getSingleton().create(PATHGRID_LINE_MATERIAL, DEBUGGING_GROUP);
|
||||||
|
@ -34,6 +39,31 @@ ManualObject *createPathgridLine(SceneManager* sceneMgr, const Vector3& from, co
|
||||||
lineMatPtr->getTechnique(0)->getPass(0)->setSelfIllumination(1,1,0);
|
lineMatPtr->getTechnique(0)->getPass(0)->setSelfIllumination(1,1,0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (MaterialManager::getSingleton().getByName(PATHGRID_POINT_MATERIAL, DEBUGGING_GROUP).isNull())
|
||||||
|
{
|
||||||
|
MaterialPtr pointMatPtr = MaterialManager::getSingleton().create(PATHGRID_POINT_MATERIAL, DEBUGGING_GROUP);
|
||||||
|
pointMatPtr->setReceiveShadows(false);
|
||||||
|
pointMatPtr->getTechnique(0)->setLightingEnabled(true);
|
||||||
|
pointMatPtr->getTechnique(0)->getPass(0)->setDiffuse(1,0,0,0);
|
||||||
|
pointMatPtr->getTechnique(0)->getPass(0)->setAmbient(1,0,0);
|
||||||
|
pointMatPtr->getTechnique(0)->getPass(0)->setSelfIllumination(1,0,0);
|
||||||
|
}
|
||||||
|
mGridMatsCreated = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Debugging::destroyGridMaterials()
|
||||||
|
{
|
||||||
|
if (mGridMatsCreated)
|
||||||
|
{
|
||||||
|
MaterialManager::getSingleton().remove(PATHGRID_POINT_MATERIAL);
|
||||||
|
MaterialManager::getSingleton().remove(PATHGRID_LINE_MATERIAL);
|
||||||
|
mGridMatsCreated = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MovableObject *Debugging::createPathgridLine(const Vector3& from, const Vector3& to)
|
||||||
|
{
|
||||||
|
ManualObject *line = mSceneMgr->createManualObject();
|
||||||
line->begin(PATHGRID_LINE_MATERIAL, Ogre::RenderOperation::OT_LINE_LIST);
|
line->begin(PATHGRID_LINE_MATERIAL, Ogre::RenderOperation::OT_LINE_LIST);
|
||||||
line->position(from);
|
line->position(from);
|
||||||
line->position(to);
|
line->position(to);
|
||||||
|
@ -42,21 +72,47 @@ ManualObject *createPathgridLine(SceneManager* sceneMgr, const Vector3& from, co
|
||||||
return line;
|
return line;
|
||||||
}
|
}
|
||||||
|
|
||||||
ManualObject *createPathgridPoint(SceneManager* sceneMgr, const Vector3& pos)
|
MovableObject *Debugging::createPathgridPoint()
|
||||||
{
|
{
|
||||||
|
ManualObject *point = mSceneMgr->createManualObject();
|
||||||
|
point->begin(PATHGRID_POINT_MATERIAL, Ogre::RenderOperation::OT_TRIANGLE_FAN);
|
||||||
|
float height = POINT_MESH_BASE /*/ sqrtf(2)*/;
|
||||||
|
point->position(0, 0, height);
|
||||||
|
point->position(-POINT_MESH_BASE, -POINT_MESH_BASE, 0);
|
||||||
|
point->position(POINT_MESH_BASE, -POINT_MESH_BASE, 0);
|
||||||
|
point->position(POINT_MESH_BASE, POINT_MESH_BASE, 0);
|
||||||
|
point->position(-POINT_MESH_BASE, POINT_MESH_BASE, 0);
|
||||||
|
point->position(-POINT_MESH_BASE, -POINT_MESH_BASE, 0);
|
||||||
|
point->end();
|
||||||
|
point->begin(PATHGRID_POINT_MATERIAL, Ogre::RenderOperation::OT_TRIANGLE_FAN);
|
||||||
|
point->position(0, 0, -height);
|
||||||
|
point->position(-POINT_MESH_BASE, -POINT_MESH_BASE, 0);
|
||||||
|
point->position(-POINT_MESH_BASE, POINT_MESH_BASE, 0);
|
||||||
|
point->position(POINT_MESH_BASE, POINT_MESH_BASE, 0);
|
||||||
|
point->position(POINT_MESH_BASE, -POINT_MESH_BASE, 0);
|
||||||
|
point->position(-POINT_MESH_BASE, -POINT_MESH_BASE, 0);
|
||||||
|
point->end();
|
||||||
|
|
||||||
|
return point;
|
||||||
}
|
}
|
||||||
|
|
||||||
Debugging::Debugging(SceneNode *mwRoot, MWWorld::Environment &env, OEngine::Physic::PhysicEngine *engine) :
|
Debugging::Debugging(SceneNode *mwRoot, MWWorld::Environment &env, OEngine::Physic::PhysicEngine *engine) :
|
||||||
mMwRoot(mwRoot), mEnvironment(env), mEngine(engine),
|
mMwRoot(mwRoot), mEnvironment(env), mEngine(engine),
|
||||||
mSceneMgr(mwRoot->getCreator()),
|
mSceneMgr(mwRoot->getCreator()),
|
||||||
pathgridEnabled(false),
|
mPathgridEnabled(false),
|
||||||
mInteriorPathgridNode(NULL), mPathGridRoot(NULL)
|
mInteriorPathgridNode(NULL), mPathGridRoot(NULL),
|
||||||
|
mGridMatsCreated(false)
|
||||||
{
|
{
|
||||||
ResourceGroupManager::getSingleton().createResourceGroup(DEBUGGING_GROUP);
|
ResourceGroupManager::getSingleton().createResourceGroup(DEBUGGING_GROUP);
|
||||||
}
|
}
|
||||||
|
|
||||||
Debugging::~Debugging()
|
Debugging::~Debugging()
|
||||||
{
|
{
|
||||||
|
if (mPathgridEnabled)
|
||||||
|
{
|
||||||
|
togglePathgrid();
|
||||||
|
}
|
||||||
|
|
||||||
ResourceGroupManager::getSingleton().destroyResourceGroup(DEBUGGING_GROUP);
|
ResourceGroupManager::getSingleton().destroyResourceGroup(DEBUGGING_GROUP);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,7 +128,7 @@ bool Debugging::toggleRenderMode (int mode){
|
||||||
return mEngine->isDebugCreated;
|
return mEngine->isDebugCreated;
|
||||||
case MWWorld::World::Render_Pathgrid:
|
case MWWorld::World::Render_Pathgrid:
|
||||||
togglePathgrid();
|
togglePathgrid();
|
||||||
return pathgridEnabled;
|
return mPathgridEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@ -82,7 +138,7 @@ void Debugging::cellAdded(MWWorld::Ptr::CellStore *store)
|
||||||
{
|
{
|
||||||
std::cout << "Cell added to debugging" << std::endl;
|
std::cout << "Cell added to debugging" << std::endl;
|
||||||
mActiveCells.push_back(store);
|
mActiveCells.push_back(store);
|
||||||
if (pathgridEnabled)
|
if (mPathgridEnabled)
|
||||||
enableCellPathgrid(store);
|
enableCellPathgrid(store);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,15 +146,17 @@ void Debugging::cellRemoved(MWWorld::Ptr::CellStore *store)
|
||||||
{
|
{
|
||||||
mActiveCells.erase(std::remove(mActiveCells.begin(), mActiveCells.end(), store), mActiveCells.end());
|
mActiveCells.erase(std::remove(mActiveCells.begin(), mActiveCells.end(), store), mActiveCells.end());
|
||||||
std::cout << "Cell removed from debugging, active cells count: " << mActiveCells.size() << std::endl;
|
std::cout << "Cell removed from debugging, active cells count: " << mActiveCells.size() << std::endl;
|
||||||
if (pathgridEnabled)
|
if (mPathgridEnabled)
|
||||||
disableCellPathgrid(store);
|
disableCellPathgrid(store);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Debugging::togglePathgrid()
|
void Debugging::togglePathgrid()
|
||||||
{
|
{
|
||||||
pathgridEnabled = !pathgridEnabled;
|
mPathgridEnabled = !mPathgridEnabled;
|
||||||
if (pathgridEnabled)
|
if (mPathgridEnabled)
|
||||||
{
|
{
|
||||||
|
createGridMaterials();
|
||||||
|
|
||||||
// add path grid meshes to already loaded cells
|
// add path grid meshes to already loaded cells
|
||||||
mPathGridRoot = mMwRoot->createChildSceneNode();
|
mPathGridRoot = mMwRoot->createChildSceneNode();
|
||||||
for(CellList::iterator it = mActiveCells.begin(); it != mActiveCells.end(); it++)
|
for(CellList::iterator it = mActiveCells.begin(); it != mActiveCells.end(); it++)
|
||||||
|
@ -106,7 +164,8 @@ void Debugging::togglePathgrid()
|
||||||
enableCellPathgrid(*it);
|
enableCellPathgrid(*it);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
// remove path grid meshes from already loaded cells
|
// remove path grid meshes from already loaded cells
|
||||||
for(CellList::iterator it = mActiveCells.begin(); it != mActiveCells.end(); it++)
|
for(CellList::iterator it = mActiveCells.begin(); it != mActiveCells.end(); it++)
|
||||||
{
|
{
|
||||||
|
@ -115,16 +174,14 @@ void Debugging::togglePathgrid()
|
||||||
mPathGridRoot->removeAndDestroyAllChildren();
|
mPathGridRoot->removeAndDestroyAllChildren();
|
||||||
mSceneMgr->destroySceneNode(mPathGridRoot);
|
mSceneMgr->destroySceneNode(mPathGridRoot);
|
||||||
mPathGridRoot = NULL;
|
mPathGridRoot = NULL;
|
||||||
|
destroyGridMaterials();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Debugging::enableCellPathgrid(MWWorld::Ptr::CellStore *store)
|
void Debugging::enableCellPathgrid(MWWorld::Ptr::CellStore *store)
|
||||||
{
|
{
|
||||||
ESM::Pathgrid *pathgrid = mEnvironment.mWorld->getStore().pathgrids.search(*store->cell);
|
ESM::Pathgrid *pathgrid = mEnvironment.mWorld->getStore().pathgrids.search(*store->cell);
|
||||||
if (!pathgrid)
|
if (!pathgrid) return;
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Vector3 cellPathGridPos;
|
Vector3 cellPathGridPos;
|
||||||
/// \todo replace tests like this with isExterior method of ESM::Cell after merging with terrain branch
|
/// \todo replace tests like this with isExterior method of ESM::Cell after merging with terrain branch
|
||||||
|
@ -141,8 +198,7 @@ void Debugging::enableCellPathgrid(MWWorld::Ptr::CellStore *store)
|
||||||
Vector3 position(it->x, it->y, it->z);
|
Vector3 position(it->x, it->y, it->z);
|
||||||
SceneNode* pointNode = cellPathGrid->createChildSceneNode(position);
|
SceneNode* pointNode = cellPathGrid->createChildSceneNode(position);
|
||||||
pointNode->setScale(0.5, 0.5, 0.5);
|
pointNode->setScale(0.5, 0.5, 0.5);
|
||||||
Entity *pointMesh = mSceneMgr->createEntity(SceneManager::PT_CUBE);
|
pointNode->attachObject(createPathgridPoint());
|
||||||
pointNode->attachObject(pointMesh);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ESM::Pathgrid::EdgeList edges = pathgrid->edges;
|
ESM::Pathgrid::EdgeList edges = pathgrid->edges;
|
||||||
|
@ -151,8 +207,7 @@ void Debugging::enableCellPathgrid(MWWorld::Ptr::CellStore *store)
|
||||||
{
|
{
|
||||||
ESM::Pathgrid::Edge edge = *it;
|
ESM::Pathgrid::Edge edge = *it;
|
||||||
ESM::Pathgrid::Point p1 = points[edge.v0], p2 = points[edge.v1];
|
ESM::Pathgrid::Point p1 = points[edge.v0], p2 = points[edge.v1];
|
||||||
cellPathGrid->attachObject(createPathgridLine(cellPathGrid->getCreator(),
|
cellPathGrid->attachObject(createPathgridLine(Vector3(p1.x, p1.y, p1.z),
|
||||||
Vector3(p1.x, p1.y, p1.z),
|
|
||||||
Vector3(p2.x, p2.y, p2.z)));
|
Vector3(p2.x, p2.y, p2.z)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -193,7 +248,6 @@ void Debugging::destroyCellPathgridNode(SceneNode *node)
|
||||||
{
|
{
|
||||||
mPathGridRoot->removeChild(node);
|
mPathGridRoot->removeChild(node);
|
||||||
|
|
||||||
/// \todo should object be killed by hand or removeAndDestroyAllChildren is sufficient?
|
|
||||||
SceneNode::ChildNodeIterator childIt = node->getChildIterator();
|
SceneNode::ChildNodeIterator childIt = node->getChildIterator();
|
||||||
while (childIt.hasMoreElements())
|
while (childIt.hasMoreElements())
|
||||||
{
|
{
|
||||||
|
@ -211,7 +265,7 @@ void Debugging::destroyAttachedObjects(SceneNode *node)
|
||||||
while (objIt.hasMoreElements())
|
while (objIt.hasMoreElements())
|
||||||
{
|
{
|
||||||
MovableObject *mesh = static_cast<MovableObject *>(objIt.getNext());
|
MovableObject *mesh = static_cast<MovableObject *>(objIt.getNext());
|
||||||
node->getCreator()->destroyMovableObject(mesh);
|
mSceneMgr->destroyMovableObject(mesh);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,20 +37,20 @@ namespace MWRender
|
||||||
MWWorld::Environment& mEnvironment;
|
MWWorld::Environment& mEnvironment;
|
||||||
|
|
||||||
// Path grid stuff
|
// Path grid stuff
|
||||||
bool pathgridEnabled;
|
bool mPathgridEnabled;
|
||||||
|
|
||||||
void togglePathgrid();
|
void togglePathgrid();
|
||||||
|
|
||||||
typedef std::vector<MWWorld::Ptr::CellStore *> CellList;
|
typedef std::vector<MWWorld::Ptr::CellStore *> CellList;
|
||||||
|
|
||||||
CellList mActiveCells;
|
CellList mActiveCells;
|
||||||
|
|
||||||
Ogre::SceneNode *mMwRoot;
|
Ogre::SceneNode *mMwRoot;
|
||||||
|
|
||||||
Ogre::SceneNode *mPathGridRoot;
|
Ogre::SceneNode *mPathGridRoot;
|
||||||
Ogre::SceneNode *mInteriorPathgridNode;
|
|
||||||
|
|
||||||
typedef std::map<std::pair<int,int>, Ogre::SceneNode *> ExteriorPathgridNodes;
|
typedef std::map<std::pair<int,int>, Ogre::SceneNode *> ExteriorPathgridNodes;
|
||||||
ExteriorPathgridNodes mExteriorPathgridNodes;
|
ExteriorPathgridNodes mExteriorPathgridNodes;
|
||||||
|
Ogre::SceneNode *mInteriorPathgridNode;
|
||||||
|
|
||||||
void enableCellPathgrid(MWWorld::Ptr::CellStore *store);
|
void enableCellPathgrid(MWWorld::Ptr::CellStore *store);
|
||||||
void disableCellPathgrid(MWWorld::Ptr::CellStore *store);
|
void disableCellPathgrid(MWWorld::Ptr::CellStore *store);
|
||||||
|
@ -59,6 +59,14 @@ namespace MWRender
|
||||||
void destroyCellPathgridNode(Ogre::SceneNode *node);
|
void destroyCellPathgridNode(Ogre::SceneNode *node);
|
||||||
void destroyAttachedObjects(Ogre::SceneNode *node);
|
void destroyAttachedObjects(Ogre::SceneNode *node);
|
||||||
|
|
||||||
|
// materials
|
||||||
|
bool mGridMatsCreated;
|
||||||
|
void createGridMaterials();
|
||||||
|
void destroyGridMaterials();
|
||||||
|
|
||||||
|
// path grid meshes
|
||||||
|
Ogre::MovableObject* createPathgridLine(const Ogre::Vector3& from, const Ogre::Vector3& to);
|
||||||
|
Ogre::MovableObject* createPathgridPoint();
|
||||||
public:
|
public:
|
||||||
Debugging(Ogre::SceneNode* mwRoot, MWWorld::Environment &env, OEngine::Physic::PhysicEngine *engine);
|
Debugging(Ogre::SceneNode* mwRoot, MWWorld::Environment &env, OEngine::Physic::PhysicEngine *engine);
|
||||||
~Debugging();
|
~Debugging();
|
||||||
|
|
Loading…
Reference in a new issue