Sorry for being late to reply. I might check that alternative implementation for OGRE as well. Personally I prefer PolyVox as it's a library developed specifically for this purpose, so it should be better and more consistent to use.
Anyway, I haven't made any progress with my code. The latest changes are still using the OGRE Tutorial Framework, combined with that wiki article on how to add a PolyVox scene to it. As I said last time, nothing renders... possibly because I need to add data to my scene.
If anyone wishes to help, here is the code function I got running so far. Please tell me what I should change and add to it. For starters, I'm looking to get a simple area of terrain which I can modify (add / subtract to / from). Once that works I'll probably make another thread with more information about what I'm trying to get going and other questions.
Code:
void TutorialApplication::createScene(void)
{
using namespace std;
using namespace PolyVox;
typedef PolyVox::PositionMaterialNormal VertexType;
SurfaceMesh <VertexType> mesh;
SurfaceMesh <VertexType> mesh2;
Region regValid(Vector3DInt32(0,0,0), Vector3DInt32(128,128,128));
Ogre::ManualObject* ogreMesh;
// create something to draw the PolyVox stuff to
ogreMesh = mSceneMgr->createManualObject("PolyVox Mesh");
// YES we do intend to change the mesh later -.-
/*
ogreMesh->setDynamic(true);
ogreMesh->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_TRIANGLE_LIST);
{
// do nothing, this will be updated
}
ogreMesh->end();
*/
Ogre::SceneNode* ogreNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("testnode1", Ogre::Vector3(20, 0, 0));
ogreNode->attachObject(ogreMesh);
SimpleVolume<Material8> volume(regValid);
// now add some data to it
std::cout << "smoothing volume" << std::endl;
// smoothRegion<Material8>(volume, volume.getEnclosingRegion());
std::cout << "updating volume surface" << std::endl;
{
PolyVox::SurfaceExtractor<SimpleVolume,Material8> suf(&volume, volume.getEnclosingRegion(), &mesh);
suf.execute();
}
std::cout << "decimating meshes" << std::endl;
{
PolyVox::MeshDecimator<PolyVox::PositionMaterialNormal> decim(&mesh, &mesh2);
decim.execute();
}
// std::cout << "drawing mesh: " << mesh2.getNoOfVertices() << std::endl;
ogreMesh->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_TRIANGLE_LIST);
{
const vector<PolyVox::PositionMaterialNormal>& vecVertices = mesh2.getVertices();
const vector<uint32_t>& vecIndices = mesh2.getIndices();
unsigned int uLodLevel = 0;
int beginIndex = mesh2.m_vecLodRecords[uLodLevel].beginIndex;
int endIndex = mesh2.m_vecLodRecords[uLodLevel].endIndex;
for(int index = beginIndex; index < endIndex; ++index) {
const PolyVox::PositionMaterialNormal& vertex = vecVertices[vecIndices[index]];
const PolyVox::Vector3DFloat& v3dVertexPos = vertex.getPosition();
const PolyVox::Vector3DFloat& v3dVertexNormal = vertex.getNormal();
//const Vector3DFloat v3dRegionOffset(uRegionX * g_uRegionSideLength, uRegionY * g_uRegionSideLength, uRegionZ * g_uRegionSideLength);
const PolyVox::Vector3DFloat v3dFinalVertexPos = v3dVertexPos + static_cast<PolyVox::Vector3DFloat>(mesh2.m_Region.getLowerCorner());
ogreMesh->position(v3dFinalVertexPos.getX(), v3dFinalVertexPos.getY(), v3dFinalVertexPos.getZ());
ogreMesh->normal(v3dVertexNormal.getX(), v3dVertexNormal.getY(), v3dVertexNormal.getZ());
uint8_t mat = vertex.getMaterial() + 0.5;
uint8_t red = mat & 0xF0;
uint8_t green = mat & 0x03;
uint8_t blue = mat & 0x0C;
ogreMesh->colour(red*2, green*4, blue*4);// just some random colors, I'm too lazy for hsv
}
}
ogreMesh->end();
mSceneMgr->setAmbientLight(Ogre::ColourValue(0.5f, 0.5f, 0.5f));
}