|
|
|
@ -8,6 +8,7 @@
|
|
|
|
|
|
|
|
|
|
#include <components/esm/loadstat.hpp>
|
|
|
|
|
#include <components/esm/loadpgrd.hpp>
|
|
|
|
|
#include <components/sceneutil/pathgridutil.hpp>
|
|
|
|
|
|
|
|
|
|
#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<osg::Geometry> Pathgrid::createPathgridLines(const ESM::Pathgrid *pathgrid)
|
|
|
|
|
{
|
|
|
|
|
osg::ref_ptr<osg::Geometry> geom = new osg::Geometry;
|
|
|
|
|
|
|
|
|
|
osg::ref_ptr<osg::Vec3Array> 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<osg::Vec4Array> 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<osg::Geometry> Pathgrid::createPathgridPoints(const ESM::Pathgrid *pathgrid)
|
|
|
|
|
{
|
|
|
|
|
osg::ref_ptr<osg::Geometry> geom = new osg::Geometry;
|
|
|
|
|
|
|
|
|
|
const float height = POINT_MESH_BASE * sqrtf(2);
|
|
|
|
|
|
|
|
|
|
osg::ref_ptr<osg::Vec3Array> vertices = new osg::Vec3Array;
|
|
|
|
|
osg::ref_ptr<osg::UShortArray> 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<float>(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<osg::Vec4Array> 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<osg::Group> root)
|
|
|
|
|
: mPathgridEnabled(false)
|
|
|
|
|
, mRootNode(root)
|
|
|
|
@ -212,12 +112,9 @@ void Pathgrid::enableCellPathgrid(const MWWorld::CellStore *store)
|
|
|
|
|
osg::ref_ptr<osg::PositionAttitudeTransform> cellPathGrid = new osg::PositionAttitudeTransform;
|
|
|
|
|
cellPathGrid->setPosition(cellPathGridPos);
|
|
|
|
|
|
|
|
|
|
osg::ref_ptr<osg::Geometry> lines = createPathgridLines(pathgrid);
|
|
|
|
|
|
|
|
|
|
osg::ref_ptr<osg::Geometry> points = createPathgridPoints(pathgrid);
|
|
|
|
|
osg::ref_ptr<osg::Geometry> geometry = SceneUtil::PathgridGeometryFactory::get().create(*pathgrid);
|
|
|
|
|
|
|
|
|
|
cellPathGrid->addChild(lines);
|
|
|
|
|
cellPathGrid->addChild(points);
|
|
|
|
|
cellPathGrid->addChild(geometry);
|
|
|
|
|
|
|
|
|
|
mPathGridRoot->addChild(cellPathGrid);
|
|
|
|
|
|
|
|
|
|