it seems easy to set... but i can't get it work. look at this code please. i'm doing something wrong?
Code:
#include "testApp.h"
#include "ofxPolyvox.h"
#include "PolyVoxCore/MarchingCubesSurfaceExtractor.h"
#include "PolyVoxCore/RawVolume.h"
#include "PolyVoxCore/MaterialDensityPair.h"
#include "PolyVoxCore/PolyVoxForwardDeclarations.h"
//Use the PolyVox namespace
using namespace PolyVox;
void createRawVolume(RawVolume<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);
MaterialDensityPair44 voxel;
//This three-level for loop iterates over every voxel in the volume
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(fDistToCenter <= fRadius)
{
uint8_t uMaterial = 2;
uint8_t uValue = 3;
//Modify the density and material
voxel.setMaterial( uMaterial );
voxel.setDensity( MaterialDensityPair44::getMaxDensity() );
//voxel = MaterialDensityPair44(uValue, uValue > 0 ? MaterialDensityPair44::getMaxDensity() : MaterialDensityPair44::getMinDensity());
uint8_t mat = voxel.getMaterial();
cout << "mat:" << mat << endl;
volData.setVoxelAt( x, y, z, voxel );
}
}
}
}
}
//--------------------------------------------------------------
void testApp::setup(){
ofSetLogLevel(OF_LOG_VERBOSE);
PolyVox::Region reg(Vector3DInt32(0,0,0), Vector3DInt32(32, 32, 32));
RawVolume<MaterialDensityPair44> volData(reg);
createRawVolume(volData, 12);
SurfaceMesh<PositionMaterialNormal> mesh;
MarchingCubesSurfaceExtractor< RawVolume<MaterialDensityPair44> > surfaceExtractor(&volData, volData.getEnclosingRegion(), &mesh);
surfaceExtractor.execute();
std::cout << "polyvox vertices: " << mesh.getNoOfVertices() << std::endl;
std::cout << "polyvox indices: " << mesh.getNoOfIndices() << std::endl;
OF_mesh.setMode(OF_PRIMITIVE_TRIANGLES);
polyvox.polyvoxToOfMesh(mesh,OF_mesh);
std::cout << "OF_mesh vertices: " << OF_mesh.getNumVertices() << std::endl;
}
and here where i get the materialid and i apply to the OF mesh:
Code:
for (int i = 0; i < surfaceMesh.getNoOfVertices(); i++ ){
PositionMaterialNormal vert0 = vecVertices[i];
//uint8_t material = static_cast<uint8_t>(vert0.getMaterial() + 0.5);
uint8_t material = static_cast<uint8_t>(vert0.getMaterial() + 0.5);
cout << "material:" << material << endl;
ofFloatColor colour = convertMaterialIDToColour(material);
polyvxToOfMesh.addColor(colour);
}
ofFloatColor ofxPolyvox::convertMaterialIDToColour(uint8_t materialID)
{
ofFloatColor colour;
switch(materialID)
{
case 1:
colour.red = 255.0f;
colour.green = 0.0f;
colour.blue = 0.0f;
break;
case 2:
colour.red = 0.0f;
colour.green = 255.0f;
colour.blue = 0.0f;
break;
case 3:
colour.red = 0.0f;
colour.green = 0.0f;
colour.blue = 1.0f;
break;
case 4:
colour.red = 1.0f;
colour.green = 1.0f;
colour.blue = 0.0f;
break;
case 5:
colour.red = 1.0f;
colour.green = 0.0f;
colour.blue = 1.0f;
break;
default:
colour.red = 1.0f;
colour.green = 1.0f;
colour.blue = 1.0f;
}
return colour;
}
but it seems that no material is assigned to every vertex because i receive from
Code:
uint8_t mat = voxel.getMaterial();
cout << "mat:" << mat << endl;
the cout output absolutely nothing! So i suppose that i miss to add some very relevant part...
I looked for this at your OpenGL example, but you use LargeVolume, i tried also with LargeVolume but with the same luck.