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

extractMarchingCubesMesh not producing vertices.
http://www.volumesoffun.com/phpBB3/viewtopic.php?f=2&t=704
Page 1 of 1

Author:  Devy [ Tue Aug 08, 2017 7:25 pm ]
Post subject:  extractMarchingCubesMesh not producing vertices.

Hello, I'm trying to use this function to produce terrain using the built-in paging system.

Here's the code:
Code:
class PerlinNoisePager : public PolyVox::PagedVolume<MaterialDensityPair44>::Pager
{
public:
   /// Constructor
   PerlinNoisePager()
      :PagedVolume<MaterialDensityPair44>::Pager()
   {
   }

   /// Destructor
   virtual ~PerlinNoisePager() {};

   virtual void pageIn(const PolyVox::Region& region, PagedVolume<MaterialDensityPair44>::Chunk* pChunk)
   {

            FastNoise n;
            n.SetFractalOctaves(2);
           
           
            for (int x = region.getLowerX(); x <= region.getUpperX(); x++)
            {
                for (int y = region.getLowerY(); y <= region.getUpperY(); y++)
                {
                    for (int z = region.getLowerZ(); z <= region.getUpperZ(); z++)
                    {
                       
                        MaterialDensityPair44 voxel;
                        //Even setting this to 245 or 255 doesn't produce vertices.
                        voxel.setMaterial(n.GetValueFractal(x, y, z) * 40);

                        voxel.setDensity(MaterialDensityPair44::getMaxDensity());
                        //Wrte the voxel value into the volume
                        pChunk->setVoxel(x - region.getLowerX(), y - region.getLowerY(), z -region.getLowerZ(), voxel);
                       
                    }
                }
            }
   }

   virtual void pageOut(const PolyVox::Region& region, PagedVolume<MaterialDensityPair44>::Chunk* /*pChunk*/)
   {
      std::cout << "warning unloading region: " << region.getLowerCorner() << " -> " << region.getUpperCorner() << std::endl;
   }
};


Here's the code that calls this stuff:

Code:
PerlinNoisePager* pager = new PerlinNoisePager();
    PagedVolume<MaterialDensityPair44> volData(pager, 8 * 1024 * 1024, 32);
    PolyVox::Region reg2(Vector3DInt32(0, 0, 0), Vector3DInt32(154, 154, 154));
    auto mesh = extractMarchingCubesMesh(&volData, reg2);
    std::cout << "#vertices: " << mesh.getNoOfVertices() << std::endl;


This does not produce vertices but if I use the cubic extractor it does. Any ideas?

Thank you!

Author:  David Williams [ Thu Aug 10, 2017 5:28 pm ]
Post subject:  Re: extractMarchingCubesMesh not producing vertices.

The Marching Cubes extractor uses thedensity (not the material) to decide whether to generate a vertex. In your case you are setting all the voxels to maximum density which means there is no isosurface present and so no mesh is generated.

As a first improvement, set voxels to have a density of zero if you want them to be empty space and to max density if you want them to be solid.

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