diff --git a/apps/openmw/mwrender/pathgrid.cpp b/apps/openmw/mwrender/pathgrid.cpp index d79604a91..8d790e5e0 100644 --- a/apps/openmw/mwrender/pathgrid.cpp +++ b/apps/openmw/mwrender/pathgrid.cpp @@ -8,6 +8,7 @@ #include #include +#include #include "../mwbase/world.hpp" // these includes can be removed once the static-hack is gone #include "../mwbase/environment.hpp" @@ -23,107 +24,6 @@ namespace MWRender { -static const int POINT_MESH_BASE = 35; - -osg::ref_ptr Pathgrid::createPathgridLines(const ESM::Pathgrid *pathgrid) -{ - osg::ref_ptr geom = new osg::Geometry; - - osg::ref_ptr vertices = new osg::Vec3Array; - - for(ESM::Pathgrid::EdgeList::const_iterator it = pathgrid->mEdges.begin(); - it != pathgrid->mEdges.end(); - ++it) - { - const ESM::Pathgrid::Edge &edge = *it; - const ESM::Pathgrid::Point &p1 = pathgrid->mPoints[edge.mV0], &p2 = pathgrid->mPoints[edge.mV1]; - - osg::Vec3f direction = MWMechanics::PathFinder::MakeOsgVec3(p2) - MWMechanics::PathFinder::MakeOsgVec3(p1); - osg::Vec3f lineDisplacement = (direction^osg::Vec3f(0,0,1)); - lineDisplacement.normalize(); - - lineDisplacement = lineDisplacement * POINT_MESH_BASE + - osg::Vec3f(0, 0, 10); // move lines up a little, so they will be less covered by meshes/landscape - - vertices->push_back(MWMechanics::PathFinder::MakeOsgVec3(p1) + lineDisplacement); - vertices->push_back(MWMechanics::PathFinder::MakeOsgVec3(p2) + lineDisplacement); - } - - geom->setVertexArray(vertices); - - geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINES, 0, vertices->size())); - - osg::ref_ptr colors = new osg::Vec4Array; - colors->push_back(osg::Vec4(1.f, 1.f, 0.f, 1.f)); - geom->setColorArray(colors, osg::Array::BIND_OVERALL); - - return geom; -} - -osg::ref_ptr Pathgrid::createPathgridPoints(const ESM::Pathgrid *pathgrid) -{ - osg::ref_ptr geom = new osg::Geometry; - - const float height = POINT_MESH_BASE * sqrtf(2); - - osg::ref_ptr vertices = new osg::Vec3Array; - osg::ref_ptr indices = new osg::UShortArray; - - bool first = true; - unsigned short startIndex = 0; - for(ESM::Pathgrid::PointList::const_iterator it = pathgrid->mPoints.begin(); - it != pathgrid->mPoints.end(); - ++it, startIndex += 6) - { - osg::Vec3f pointPos(MWMechanics::PathFinder::MakeOsgVec3(*it)); - - if (!first) - { - // degenerate triangle from previous octahedron - indices->push_back(startIndex - 4); // 2nd point of previous octahedron - indices->push_back(startIndex); // start point of current octahedron - } - - float pointMeshBase = static_cast(POINT_MESH_BASE); - - vertices->push_back(pointPos + osg::Vec3f(0, 0, height)); // 0 - vertices->push_back(pointPos + osg::Vec3f(-pointMeshBase, -pointMeshBase, 0)); // 1 - vertices->push_back(pointPos + osg::Vec3f(pointMeshBase, -pointMeshBase, 0)); // 2 - vertices->push_back(pointPos + osg::Vec3f(pointMeshBase, pointMeshBase, 0)); // 3 - vertices->push_back(pointPos + osg::Vec3f(-pointMeshBase, pointMeshBase, 0)); // 4 - vertices->push_back(pointPos + osg::Vec3f(0, 0, -height)); // 5 - - indices->push_back(startIndex + 0); - indices->push_back(startIndex + 1); - indices->push_back(startIndex + 2); - indices->push_back(startIndex + 5); - indices->push_back(startIndex + 3); - indices->push_back(startIndex + 4); - // degenerates - indices->push_back(startIndex + 4); - indices->push_back(startIndex + 5); - indices->push_back(startIndex + 5); - // end degenerates - indices->push_back(startIndex + 1); - indices->push_back(startIndex + 4); - indices->push_back(startIndex + 0); - indices->push_back(startIndex + 3); - indices->push_back(startIndex + 2); - - first = false; - } - - geom->setVertexArray(vertices); - - geom->addPrimitiveSet(new osg::DrawElementsUShort(osg::PrimitiveSet::TRIANGLE_STRIP, indices->size(), &(*indices)[0])); - - osg::ref_ptr colors = new osg::Vec4Array; - colors->push_back(osg::Vec4(1.f, 0.f, 0.f, 1.f)); - geom->setColorArray(colors, osg::Array::BIND_OVERALL); - - return geom; -} - Pathgrid::Pathgrid(osg::ref_ptr root) : mPathgridEnabled(false) , mRootNode(root) @@ -212,12 +112,9 @@ void Pathgrid::enableCellPathgrid(const MWWorld::CellStore *store) osg::ref_ptr cellPathGrid = new osg::PositionAttitudeTransform; cellPathGrid->setPosition(cellPathGridPos); - osg::ref_ptr lines = createPathgridLines(pathgrid); + osg::ref_ptr geometry = SceneUtil::PathgridGeometryFactory::get().create(*pathgrid); - osg::ref_ptr points = createPathgridPoints(pathgrid); - - cellPathGrid->addChild(lines); - cellPathGrid->addChild(points); + cellPathGrid->addChild(geometry); mPathGridRoot->addChild(cellPathGrid); diff --git a/apps/openmw/mwrender/pathgrid.hpp b/apps/openmw/mwrender/pathgrid.hpp index 39a6d71ed..22bfa8e73 100644 --- a/apps/openmw/mwrender/pathgrid.hpp +++ b/apps/openmw/mwrender/pathgrid.hpp @@ -48,9 +48,6 @@ namespace MWRender void enableCellPathgrid(const MWWorld::CellStore *store); void disableCellPathgrid(const MWWorld::CellStore *store); - // path grid meshes - osg::ref_ptr createPathgridLines(const ESM::Pathgrid *pathgrid); - osg::ref_ptr createPathgridPoints(const ESM::Pathgrid *pathgrid); public: Pathgrid(osg::ref_ptr root); ~Pathgrid();