PolyVox Surface extractor for Irrlicht mesh buffer.

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.

PolyVox Surface extractor for Irrlicht mesh buffer.

Postby Virror » Thu Nov 10, 2011 12:39 pm

Posted this on the PolyVox forum and thought i could post it here as well if anyone wants to try out PolyVox.
This class can be used to instead of the standard SurfaceExtractor class to extract directly into a CDynamicMeshBuffer instead of converting it into a PolyVox mesh and than have to convert it into a Irrlicht mesh.
Should speed things up a bit and make integration easier.

PolyVox webside

Example:
cpp Code: Select all
//Include files needed for PolyVox
#include "PolyVoxCore/MaterialDensityPair.h"
#include "PolyVoxCore/CubicSurfaceExtractorWithNormals.h"
#include "PolyVoxCore/SurfaceMesh.h"
#include "PolyVoxCore/SimpleVolume.h"
 
//Create the volume that contains the actual voxel data and make it 64x64x64
SimpleVolume<MaterialDensityPair44> volData(PolyVox::Region(Vector3DInt32(0,0,0), Vector3DInt32(63, 63, 63)));
 
//This vector hold the position of the center of the volume
Vector3DFloat v3dVolCenter(volData.getWidth() / 2, volData.getHeight() / 2, volData.getDepth() / 2);
 
//Create a simple sphere
//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);
            }
        }
    }
}
 
//Create a new meshBuffer
CDynamicMeshBuffer *newBuffer = new CDynamicMeshBuffer(EVT_STANDARD, EIT_32BIT);
 
//Create a new mesh extractor for making a mesh out of the voxel data
IrrSurfaceExtractor<SimpleVolume, MaterialDensityPair44 > irrsurfaceExtractor(volData, volData->getEnclosingRegion(), newBuffer);
 
//Execute the extractor
irrsurfaceExtractor.execute();
 
//Create the scene node
SMesh * newMesh = new SMesh;
newMesh->addMeshBuffer(newBuffer);
newMesh->recalculateBoundingBox();
ISceneNode * newNode = SceneManager->addMeshSceneNode(newMesh, Parent, ID, Position, Rotation, Scale);
newMesh->drop();
newBuffer->drop();


Download link:
IrrSurfaceExtractor
Last edited by Virror on Thu Nov 17, 2011 6:25 pm, edited 4 times in total.
Virror
 
Posts: 191
Joined: Mon May 02, 2011 3:15 pm

Re: PolyVox Surface extractor for Irrlicht mesh buffer.

Postby serengeor » Thu Nov 10, 2011 3:35 pm

Download not working :\
Working on game: Marrbles (Currently stopped).
User avatar
serengeor
 
Posts: 1695
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Re: PolyVox Surface extractor for Irrlicht mesh buffer.

Postby Virror » Thu Nov 10, 2011 5:01 pm

Edit: Should be fixed now : )
Virror
 
Posts: 191
Joined: Mon May 02, 2011 3:15 pm

Re: PolyVox Surface extractor for Irrlicht mesh buffer.

Postby christianclavet » Thu Nov 17, 2011 5:28 pm

Virror, is there an example to show how to use it?
User avatar
christianclavet
 
Posts: 1383
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA

Re: PolyVox Surface extractor for Irrlicht mesh buffer.

Postby Virror » Thu Nov 17, 2011 5:40 pm

Well, you should read the PolyVox example on how to use that part, then you can just use this one instead of the original SurfaceExtractor.
Note that if you are yousing the example, they use the cubicsurfaceextractor, so you need to change the include to "surfaceextractor.h" instead of "cubicsurfaceextractor.h"
Maybe i can make a short example later tonight, have to make food and stuff now : p

Edit: Copied the example from the PolyVox webpage and expanded it with some Irrlicht stuff, this should be all you need to get started i hope.
Just give me a tell or post here i you need any help.
Virror
 
Posts: 191
Joined: Mon May 02, 2011 3:15 pm

Re: PolyVox Surface extractor for Irrlicht mesh buffer.

Postby stoertebecker » Sat Jan 14, 2012 3:53 pm

hey virror, if i use
cpp Code: Select all
   PolyVox::IrrSurfaceExtractor<PolyVox::SimpleVolume, PolyVox::MaterialDensityPair44 > irrsurfaceExtractor(&volData,   volData.getEnclosingRegion(), newBuffer);

instead of
cpp Code: Select all
   IrrSurfaceExtractor<SimpleVolume, MaterialDensityPair44 > irrsurfaceExtractor(volData, volData->getEnclosingRegion(), newBuffer);

and
cpp Code: Select all
   irrsurfaceExtractor.execute();
   printf("%i ",newBuffer->getVertexCount());
   printf("%i ",newBuffer->getIndexCount());
   //Create the scene node
   SMesh * newMesh = new SMesh;
   newMesh->addMeshBuffer(newBuffer);
   newMesh->recalculateBoundingBox();
   ISceneNode * newNode = smgr->addMeshSceneNode(newMesh);
   ...

i get for a 2-radiussphereexample 78 vertices and 456 indices -
But the node isnt displayed (other nodes are displayed), whats the problem please?
trying to display the buffer with driver->drawMeshBuffer(newBuffer); the same, no display
stoertebecker
 
Posts: 2
Joined: Sat Jan 07, 2012 3:20 pm

Re: PolyVox Surface extractor for Irrlicht mesh buffer.

Postby stoertebecker » Sun Jan 15, 2012 10:37 am

hey virror ok i found my problem, wasnt your code, my irrlicht 1.7.2 was broken dont know why, with a fresh new from sourceforge it works.
thanks for your extractor.
stoertebecker
 
Posts: 2
Joined: Sat Jan 07, 2012 3:20 pm

Re: PolyVox Surface extractor for Irrlicht mesh buffer.

Postby Virror » Mon Jan 16, 2012 8:57 am

Nice that it works : )
Virror
 
Posts: 191
Joined: Mon May 02, 2011 3:15 pm


Return to Code Snippets

Who is online

Users browsing this forum: No registered users and 1 guest