OK, there had been a few simple mistakes...
-i forgot to include the irrlicht-lib
-i mixed up a few versions of polyvox
Here is my code:
Code: Select all
#include <PolyVoxCore/MaterialDensityPair.h>
//#include <PolyVoxCore/CubicSurfaceExtractorWithNormals.h>
#include <irrsurfaceextractor.h>
#include <PolyVoxCore/SurfaceMesh.h>
#include <PolyVoxCore/SimpleVolume.h>
#include <irrlicht.h>
#ifdef _IRR_WINDOWS_
#pragma comment(lib, "Irrlicht.lib")
#pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup")
#endif
using namespace PolyVox;
using namespace irr;
void createSphereInVolume(PolyVox::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);
//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 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);
}
}
}
}
}
int main()
{
IrrlichtDevice* device = createDevice(video::EDT_OPENGL, core::dimension2d<u32>(1024, 768), 16);
if (device == 0)
return 1; // could not create selected driver.
gui::IGUIEnvironment* gui = device->getGUIEnvironment();
video::IVideoDriver* driver = device->getVideoDriver();
irr::scene::ISceneManager* smgr = device->getSceneManager();
//Create an empty volume and then place a sphere in it
PolyVox::SimpleVolume<MaterialDensityPair44> volData(PolyVox::Region(Vector3DInt32(0,0,0), Vector3DInt32(63, 63, 63)));
createSphereInVolume(volData, 30);
//Extract the surface
scene::IMeshBuffer * meshbuffer;
IrrSurfaceExtractor<SimpleVolume, MaterialDensityPair44 > surfaceExtractor([b][i][u]&volData[/u][/i][/b], volData.getEnclosingRegion(), &meshbuffer);
surfaceExtractor.execute();
scene::SMesh *my_mesh = new scene::SMesh;
my_mesh->recalculateBoundingBox();
scene::ISceneNode* my_node = smgr->addMeshSceneNode(my_mesh, 0, 0, core::vector3df(2000*2, 550*2, 2000*2),core::vector3df(0, 100, 0),core::vector3df(20.0F, 20.0F, 20.0F));
while(device->run()){
if(device->isWindowActive()){
driver->beginScene();
smgr->drawAll();
driver->endScene();
}
}
device->drop();
return 1;
}
and now there is a compiler error (i think something with the constructor)...
Code: Select all
IrrSurfaceExtractor<SimpleVolume, MaterialDensityPair44 > surfaceExtractor([b][i][u]&volData[/u][/i][/b], volData.getEnclosingRegion(), &meshbuffer);
i found an interresting article in this forum and implemented it to my code (irrsurfaceextractor.h)
http://irrlicht.sourceforge.net/forum/v ... 5&p=259648