diff --git a/examples/Basic/main.cpp b/examples/Basic/main.cpp index 5f4de9ab..da7bedad 100644 --- a/examples/Basic/main.cpp +++ b/examples/Basic/main.cpp @@ -23,7 +23,6 @@ freely, subject to the following restrictions: #include "OpenGLWidget.h" -#include "PolyVoxCore/Material.h" #include "PolyVoxCore/CubicSurfaceExtractorWithNormals.h" #include "PolyVoxCore/SurfaceMesh.h" #include "PolyVoxCore/SimpleVolume.h" @@ -33,7 +32,7 @@ freely, subject to the following restrictions: //Use the PolyVox namespace using namespace PolyVox; -void createSphereInVolume(SimpleVolume& volData, float fRadius) +void createSphereInVolume(SimpleVolume& 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); @@ -60,13 +59,13 @@ void createSphereInVolume(SimpleVolume& volData, float fRadius) } //Get the old voxel - Material8 voxel = volData.getVoxelAt(x,y,z); + //Material8 voxel = volData.getVoxelAt(x,y,z); //Modify the density and material - voxel.setMaterial(uMaterial); + //voxel.setMaterial(uMaterial); //Wrte the voxel value into the volume - volData.setVoxelAt(x, y, z, voxel); + volData.setVoxelAt(x, y, z, uMaterial); } } } @@ -80,12 +79,12 @@ int main(int argc, char *argv[]) openGLWidget.show(); //Create an empty volume and then place a sphere in it - SimpleVolume volData(PolyVox::Region(Vector3DInt32(0,0,0), Vector3DInt32(63, 63, 63))); + SimpleVolume volData(PolyVox::Region(Vector3DInt32(0,0,0), Vector3DInt32(63, 63, 63))); createSphereInVolume(volData, 30); //Extract the surface SurfaceMesh mesh; - CubicSurfaceExtractorWithNormals surfaceExtractor(&volData, volData.getEnclosingRegion(), &mesh, Material8::isQuadNeeded); + CubicSurfaceExtractorWithNormals surfaceExtractor(&volData, volData.getEnclosingRegion(), &mesh); surfaceExtractor.execute(); //Pass the surface to the OpenGL window diff --git a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractorWithNormals.h b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractorWithNormals.h index ced5b677..e2232e35 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractorWithNormals.h +++ b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractorWithNormals.h @@ -31,11 +31,25 @@ freely, subject to the following restrictions: namespace PolyVox { + template + bool defaultIsQuadNeeded(VoxelType from, VoxelType to, float& materialToUse) + { + if((from > 0) && (to == 0)) + { + materialToUse = static_cast(from); + return true; + } + else + { + return false; + } + } + template< template class VolumeType, typename VoxelType> class CubicSurfaceExtractorWithNormals { public: - CubicSurfaceExtractorWithNormals(VolumeType* volData, Region region, SurfaceMesh* result, polyvox_function funcIsQuadNeededCallback); + CubicSurfaceExtractorWithNormals(VolumeType* volData, Region region, SurfaceMesh* result, polyvox_function funcIsQuadNeededCallback = defaultIsQuadNeeded); void execute(); diff --git a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractorWithNormals.inl b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractorWithNormals.inl index f1955e94..526d094f 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractorWithNormals.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractorWithNormals.inl @@ -24,7 +24,7 @@ freely, subject to the following restrictions: namespace PolyVox { template< template class VolumeType, typename VoxelType> - CubicSurfaceExtractorWithNormals::CubicSurfaceExtractorWithNormals(VolumeType* volData, Region region, SurfaceMesh* result, polyvox_function funcIsQuadNeededCallback) + CubicSurfaceExtractorWithNormals::CubicSurfaceExtractorWithNormals(VolumeType* volData, Region region, SurfaceMesh* result, polyvox_function funcIsQuadNeededCallback) :m_volData(volData) ,m_sampVolume(volData) ,m_meshCurrent(result) @@ -54,8 +54,6 @@ namespace PolyVox if(m_funcIsQuadNeededCallback(m_volData->getVoxelAt(x,y,z), m_volData->getVoxelAt(x+1,y,z), material)) { - material = static_cast(m_volData->getVoxelAt(x,y,z).getMaterial()); - uint32_t v0 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX + 0.5f, regY - 0.5f, regZ - 0.5f), Vector3DFloat(1.0f, 0.0f, 0.0f), material)); uint32_t v1 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX + 0.5f, regY - 0.5f, regZ + 0.5f), Vector3DFloat(1.0f, 0.0f, 0.0f), material)); uint32_t v2 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX + 0.5f, regY + 0.5f, regZ - 0.5f), Vector3DFloat(1.0f, 0.0f, 0.0f), material)); @@ -66,8 +64,6 @@ namespace PolyVox } if(m_funcIsQuadNeededCallback(m_volData->getVoxelAt(x+1,y,z), m_volData->getVoxelAt(x,y,z), material)) { - material = static_cast(m_volData->getVoxelAt(x+1,y,z).getMaterial()); - uint32_t v0 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX + 0.5f, regY - 0.5f, regZ - 0.5f), Vector3DFloat(-1.0f, 0.0f, 0.0f), material)); uint32_t v1 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX + 0.5f, regY - 0.5f, regZ + 0.5f), Vector3DFloat(-1.0f, 0.0f, 0.0f), material)); uint32_t v2 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX + 0.5f, regY + 0.5f, regZ - 0.5f), Vector3DFloat(-1.0f, 0.0f, 0.0f), material)); @@ -77,11 +73,8 @@ namespace PolyVox m_meshCurrent->addTriangleCubic(v1,v3,v2); } - int plusYVoxel = m_volData->getVoxelAt(x,y+1,z).getMaterial() != 0; if(m_funcIsQuadNeededCallback(m_volData->getVoxelAt(x,y,z), m_volData->getVoxelAt(x,y+1,z), material)) { - material = static_cast(m_volData->getVoxelAt(x,y,z).getMaterial()); - uint32_t v0 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX - 0.5f, regY + 0.5f, regZ - 0.5f), Vector3DFloat(0.0f, 1.0f, 0.0f), material)); uint32_t v1 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX - 0.5f, regY + 0.5f, regZ + 0.5f), Vector3DFloat(0.0f, 1.0f, 0.0f), material)); uint32_t v2 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX + 0.5f, regY + 0.5f, regZ - 0.5f), Vector3DFloat(0.0f, 1.0f, 0.0f), material)); @@ -92,8 +85,6 @@ namespace PolyVox } if(m_funcIsQuadNeededCallback(m_volData->getVoxelAt(x,y+1,z), m_volData->getVoxelAt(x,y,z), material)) { - material = static_cast(m_volData->getVoxelAt(x,y+1,z).getMaterial()); - uint32_t v0 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX - 0.5f, regY + 0.5f, regZ - 0.5f), Vector3DFloat(0.0f, -1.0f, 0.0f), material)); uint32_t v1 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX - 0.5f, regY + 0.5f, regZ + 0.5f), Vector3DFloat(0.0f, -1.0f, 0.0f), material)); uint32_t v2 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX + 0.5f, regY + 0.5f, regZ - 0.5f), Vector3DFloat(0.0f, -1.0f, 0.0f), material)); @@ -103,11 +94,8 @@ namespace PolyVox m_meshCurrent->addTriangleCubic(v1,v2,v3); } - int plusZVoxel = m_volData->getVoxelAt(x,y,z+1).getMaterial() != 0; if(m_funcIsQuadNeededCallback(m_volData->getVoxelAt(x,y,z), m_volData->getVoxelAt(x,y,z+1), material)) { - material = static_cast(m_volData->getVoxelAt(x,y,z).getMaterial()); - uint32_t v0 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX - 0.5f, regY - 0.5f, regZ + 0.5f), Vector3DFloat(0.0f, 0.0f, 1.0f), material)); uint32_t v1 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX - 0.5f, regY + 0.5f, regZ + 0.5f), Vector3DFloat(0.0f, 0.0f, 1.0f), material)); uint32_t v2 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX + 0.5f, regY - 0.5f, regZ + 0.5f), Vector3DFloat(0.0f, 0.0f, 1.0f), material)); @@ -118,8 +106,6 @@ namespace PolyVox } if(m_funcIsQuadNeededCallback(m_volData->getVoxelAt(x,y,z+1), m_volData->getVoxelAt(x,y,z), material)) { - material = static_cast(m_volData->getVoxelAt(x,y,z+1).getMaterial()); - uint32_t v0 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX - 0.5f, regY - 0.5f, regZ + 0.5f), Vector3DFloat(0.0f, 0.0f, -1.0f), material)); uint32_t v1 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX - 0.5f, regY + 0.5f, regZ + 0.5f), Vector3DFloat(0.0f, 0.0f, -1.0f), material)); uint32_t v2 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX + 0.5f, regY - 0.5f, regZ + 0.5f), Vector3DFloat(0.0f, 0.0f, -1.0f), material));