Volumes Of Fun
http://www.volumesoffun.com/phpBB3/

polyvox integration to irrlicht
http://www.volumesoffun.com/phpBB3/viewtopic.php?f=14&t=185
Page 2 of 5

Author:  DefiniteIntegral [ Tue Mar 29, 2011 4:59 am ]
Post subject:  Re: polyvox integration to irrlicht

Not to mention that the code was just an example, it wasn't intended to be compiled... you would be better to learn what it does and write your own function.

Author:  granyte [ Tue Mar 29, 2011 5:20 am ]
Post subject:  Re: polyvox integration to irrlicht

Thanks both of you i can't belive i made such a beginer mistake thanks again


yes i guessed it wasen't ment to be compiled and is not even fully suited to be integrated in irrlicht so i modified it quite a bit but kept the structure (it's actualy 2 function now) so that i had to call it and just forgot to do so

my job has just been way to much takin i can barely get 3 hours of sleep a night

Author:  Gnurfos [ Sun Sep 25, 2011 10:17 am ]
Post subject:  Re: polyvox integration to irrlicht

In case someone else needs it, here is a full version of the convert function.

It took some time filling the missing parts (that *should* have been obvious), because in my version of Irrlicht (at least), the basic CMeshBuffer is limited to 16 bit indices (insufficient for the sphere demo), and CDynamicMeshBuffer::append was silently doing nothing.

Code:
irr::scene::IMeshBuffer* ChunkLoader::ConvertMesh(const PolyVox::SurfaceMesh<PolyVox::PositionMaterialNormal>& mesh)
{
    const std::vector<uint32_t>& indices = mesh.getIndices();
    const std::vector<PolyVox::PositionMaterialNormal>& vertices = mesh.getVertices();

    irr::scene::IDynamicMeshBuffer *mb = new irr::scene::CDynamicMeshBuffer(irr::video::EVT_STANDARD, irr::video::EIT_32BIT);
    mb->getVertexBuffer().set_used(vertices.size());
    for (size_t i = 0; i < vertices.size(); ++i)
    {
        const PolyVox::Vector3DFloat& position = vertices[i].getPosition();
        const PolyVox::Vector3DFloat& normal = vertices[i].getNormal();
        mb->getVertexBuffer()[i].Pos.X = position.getX();
        mb->getVertexBuffer()[i].Pos.Y = position.getY();
        mb->getVertexBuffer()[i].Pos.Z = position.getZ();
        mb->getVertexBuffer()[i].Normal.X = normal.getX();
        mb->getVertexBuffer()[i].Normal.Y = normal.getY();
        mb->getVertexBuffer()[i].Normal.Z = normal.getZ();
        mb->getVertexBuffer()[i].Color = irr::video::SColor(255,0,200,200);
    }
    mb->getIndexBuffer().set_used(indices.size());
    for (size_t i = 0; i < indices.size(); ++i)
    {
        mb->getIndexBuffer().setValue(i, indices[i]);
    }
    mb->recalculateBoundingBox();
    return mb;
}

Author:  David Williams [ Sun Sep 25, 2011 12:18 pm ]
Post subject:  Re: polyvox integration to irrlicht

Thanks for the code.
Gnurfos wrote:
... the basic CMeshBuffer is limited to 16 bit indices...

Yes, I found in my own project that the SurfaceExtractor will easily go past the 16-bit limit. If you can't move to 32-bit indices then your only option is to make you regions smaller, so that you generate smaller meshes but have more of them.

Author:  Virror [ Wed Oct 26, 2011 6:04 pm ]
Post subject:  Re: polyvox integration to irrlicht

Hello, i wanted to try to integrate this into my Irrlicht project, so i took the basic example code (one with the sphere) and then this code example posted above. Problem is i don't get any result at all : / Anyone know what I'm doing wrong?

Code:
//Example code (sphere) ends here
SMesh* testMesh = new SMesh;
IMeshBuffer * testBuffer = ConvertMesh(mesh);
testMesh->addMeshBuffer(testBuffer);
testMesh->recalculateBoundingBox();
ISceneNode* testNode= irrScene->addMeshSceneNode(testMesh, 0, 0, vector3df(2000*2, 550*2, 2000*2),
                                       vector3df(0, 100, 0),vector3df(20.0F, 20.0F, 20.0F));

Author:  David Williams [ Wed Oct 26, 2011 8:04 pm ]
Post subject:  Re: polyvox integration to irrlicht

Can you verify that you have a valid mesh before passing it to Irrlicht? Check that it has valid index and vertex data?

Author:  Virror [ Thu Oct 27, 2011 7:57 am ]
Post subject:  Re: polyvox integration to irrlicht

Not exactly sure how to know the mesh is correct, but it seems to be ok.
Made a sphere with a radius of 10, and Vertices size is 7548 and Triangle size is 11322 and all other data seems to be valid.

Edit: It works now : ) When i made the volume smaller i forgot to make the radius smaller as well, so the sphere was larger than the volume = only empty space : p

Author:  zprg [ Tue Jul 31, 2012 3:34 pm ]
Post subject:  Re: polyvox integration to irrlicht

hey voxelfans,

thx to gnurfos!

if you like to use a texture for the voxels in irrlicht, you should add this lines in the vertices-for-loop:

Code:
if(fabsf(normal.getX())>fabsf(normal.getY()) && fabsf(normal.getX())>fabsf(normal.getZ())) {
   mb->getVertexBuffer()[i].TCoords.X = position.getY();
   mb->getVertexBuffer()[i].TCoords.Y = position.getZ();
} else if(fabsf(normal.getY())>fabsf(normal.getX()) && fabsf(normal.getY())>fabsf(normal.getZ())) {
   mb->getVertexBuffer()[i].TCoords.X = position.getX();
   mb->getVertexBuffer()[i].TCoords.Y = position.getZ();
} else {
   mb->getVertexBuffer()[i].TCoords.X = position.getX();
   mb->getVertexBuffer()[i].TCoords.Y = position.getY();
}


zprg ( homepage http://zenprogramming.tripod.com )

Author:  granyte [ Thu Jan 03, 2013 11:09 am ]
Post subject:  Re: polyvox integration to irrlicht

wow it's been a while since i have been here.

but i finaly got around finishing my polyvox/irrlicht integration and with the noise algo i already have the results are absolutely stuning.

how ever i was wondering if there is a quick way with polyvox to distinguish betwen isolated volumes that crosses the density treshold. Because my current noise algorythm generate a lots of small island and one big one and i would need to have the small island and the big one in diferent entities

Author:  David Williams [ Thu Jan 03, 2013 8:08 pm ]
Post subject:  Re: polyvox integration to irrlicht

I'm not exactly clear what you mean... but in general it is expected that you will have one large volume rather than several seperate ones. Can you elaborate on you problem or why you need this? Also have a read of this: http://www.volumesoffun.com/polyvox/doc ... aller-ones

Page 2 of 5 All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/