Ok. I followed the example you mentioned, and added the code that should create a sphere in the volume. It compiles fine but still doesn't render anything. Here is the relevant part of the code again:
Code:
#include "TutorialApplication.h"
#include <PolyVoxCore/SimpleInterface.h>
#include <PolyVoxCore/Material.h>
#include <PolyVoxCore/MeshDecimator.h>
#include <PolyVoxCore/Vector.h>
//Use the PolyVox namespace
using namespace PolyVox;
using namespace std;
void createSphereInVolume(SimpleVolume<MaterialDensityPair44>& volData, float fRadius)
{
//This vector hold the position of the center of the volume
Vector3DFloat v3dVolCenter(volData.getWidth() / 2, volData.getHeight() / 2, volData.getDepth() / 2);
for (int z = 0; z < volData.getWidth(); z++)
{
for (int y = 0; y < volData.getHeight(); y++)
{
for (int x = 0; x < volData.getDepth(); x++)
{
//Store our current position as a vector...
Vector3DFloat v3dCurrentPos(x,y,z);
//And compute how far the current position is from the center of the volume
float fDistToCenter = (v3dCurrentPos - v3dVolCenter).length();
//If the current voxel is less than 'radius' units from the center then we make it solid.
if(fDistToCenter <= fRadius)
{
//Our new density value
uint8_t uDensity = MaterialDensityPair44::getMaxDensity();
//Get the old voxel
MaterialDensityPair44 voxel = volData.getVoxelAt(x, y, z);
//Modify the density
voxel.setDensity(uDensity);
//Wrte the voxel value into the volume
volData.setVoxelAt(x, y, z, voxel);
}
}
}
}
}
//-------------------------------------------------------------------------------------
TutorialApplication::TutorialApplication(void)
{
}
//-------------------------------------------------------------------------------------
TutorialApplication::~TutorialApplication(void)
{
}
//-------------------------------------------------------------------------------------
void TutorialApplication::createScene(void)
{
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<MaterialDensityPair44> volume(regValid);
// now add some data to it
createSphereInVolume(volume, 30);
std::cout << "smoothing volume" << std::endl;
// smoothRegion<MaterialDensityPair44>(volume, volume.getEnclosingRegion());
std::cout << "updating volume surface" << std::endl;
{
PolyVox::SurfaceExtractor<SimpleVolume,MaterialDensityPair44> 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));
}