diff --git a/examples/OpenGL/OpenGLImmediateModeSupport.cpp b/examples/OpenGL/OpenGLImmediateModeSupport.cpp index 554b1f52..b868a907 100644 --- a/examples/OpenGL/OpenGLImmediateModeSupport.cpp +++ b/examples/OpenGL/OpenGLImmediateModeSupport.cpp @@ -17,7 +17,7 @@ void renderRegionImmediateMode(PolyVox::IndexedSurfacePatch& isp) const SurfaceVertex& vertex = vecVertices[*iterIndex]; const Vector3DFloat& v3dVertexPos = vertex.getPosition(); //const Vector3DFloat v3dRegionOffset(uRegionX * g_uRegionSideLength, uRegionY * g_uRegionSideLength, uRegionZ * g_uRegionSideLength); - const Vector3DFloat v3dFinalVertexPos = v3dVertexPos + static_cast(isp.m_v3dRegionPosition); + const Vector3DFloat v3dFinalVertexPos = v3dVertexPos + static_cast(isp.m_Region.getLowerCorner()); diff --git a/examples/OpenGL/OpenGLVertexBufferObjectSupport.cpp b/examples/OpenGL/OpenGLVertexBufferObjectSupport.cpp index b1bbc220..3b1040a3 100644 --- a/examples/OpenGL/OpenGLVertexBufferObjectSupport.cpp +++ b/examples/OpenGL/OpenGLVertexBufferObjectSupport.cpp @@ -41,7 +41,7 @@ OpenGLSurfacePatch BuildOpenGLSurfacePatch(const IndexedSurfacePatch& isp) const SurfaceVertex& vertex = *iterVertex; const Vector3DFloat& v3dVertexPos = vertex.getPosition(); //const Vector3DFloat v3dRegionOffset(uRegionX * g_uRegionSideLength, uRegionY * g_uRegionSideLength, uRegionZ * g_uRegionSideLength); - const Vector3DFloat v3dFinalVertexPos = v3dVertexPos + static_cast(isp.m_v3dRegionPosition); + const Vector3DFloat v3dFinalVertexPos = v3dVertexPos + static_cast(isp.m_Region.getLowerCorner()); *ptr = v3dFinalVertexPos.getX(); ptr++; diff --git a/examples/OpenGL/OpenGLWidget.cpp b/examples/OpenGL/OpenGLWidget.cpp index 986db96b..16148e4b 100644 --- a/examples/OpenGL/OpenGLWidget.cpp +++ b/examples/OpenGL/OpenGLWidget.cpp @@ -70,10 +70,10 @@ void OpenGLWidget::setVolume(PolyVox::Volume* volData) //extractSurface(m_volData, 0, PolyVox::Region(regLowerCorner, regUpperCorner), ispCurrent); surfaceExtractor.extractSurfaceForRegion(PolyVox::Region(regLowerCorner, regUpperCorner), ispCurrent); - //computeNormalsForVertices(m_volData, *ispCurrent, SOBEL_SMOOTHED); + computeNormalsForVertices(m_volData, *ispCurrent, SOBEL_SMOOTHED); //*ispCurrent = getSmoothedSurface(*ispCurrent); - ispCurrent->smooth(0.2f); - ispCurrent->generateAveragedFaceNormals(true); + ispCurrent->smooth(0.3f); + //ispCurrent->generateAveragedFaceNormals(true); Vector3DUint8 v3dRegPos(uRegionX,uRegionY,uRegionZ); diff --git a/library/PolyVoxCore/include/IndexedSurfacePatch.h b/library/PolyVoxCore/include/IndexedSurfacePatch.h index 70bb9dae..06061e49 100644 --- a/library/PolyVoxCore/include/IndexedSurfacePatch.h +++ b/library/PolyVoxCore/include/IndexedSurfacePatch.h @@ -27,6 +27,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "PolyVoxImpl/CPlusPlusZeroXSupport.h" #include "PolyVoxForwardDeclarations.h" +#include "Region.h" #include "SurfaceVertex.h" #include "PolyVoxImpl/TypeDef.h" @@ -55,7 +56,9 @@ namespace PolyVox void generateAveragedFaceNormals(bool bNormalise, bool bIncludeEdgeVertices = false); - Vector3DInt32 m_v3dRegionPosition; //FIXME - remove this? + //Vector3DInt32 m_v3dRegionPosition; //FIXME - remove this? + + Region m_Region; int32_t m_iTimeStamp; diff --git a/library/PolyVoxCore/source/GradientEstimators.cpp b/library/PolyVoxCore/source/GradientEstimators.cpp index edd9ae57..a6c81d0b 100644 --- a/library/PolyVoxCore/source/GradientEstimators.cpp +++ b/library/PolyVoxCore/source/GradientEstimators.cpp @@ -13,7 +13,7 @@ namespace PolyVox std::vector::iterator iterSurfaceVertex = vecVertices.begin(); while(iterSurfaceVertex != vecVertices.end()) { - const Vector3DFloat& v3dPos = iterSurfaceVertex->getPosition() + static_cast(isp.m_v3dRegionPosition); + const Vector3DFloat& v3dPos = iterSurfaceVertex->getPosition() + static_cast(isp.m_Region.getLowerCorner()); const Vector3DInt32 v3dFloor = static_cast(v3dPos); VolumeSampler volIter(*volumeData); diff --git a/library/PolyVoxCore/source/IndexedSurfacePatch.cpp b/library/PolyVoxCore/source/IndexedSurfacePatch.cpp index 194034c4..0fda1845 100644 --- a/library/PolyVoxCore/source/IndexedSurfacePatch.cpp +++ b/library/PolyVoxCore/source/IndexedSurfacePatch.cpp @@ -118,6 +118,8 @@ namespace PolyVox { std::vector vecOriginalVertices = m_vecVertices; + Vector3DFloat offset = static_cast(m_Region.getLowerCorner()); + for(vector::iterator iterIndex = m_vecTriangleIndices.begin(); iterIndex != m_vecTriangleIndices.end();) { SurfaceVertex& v0 = vecOriginalVertices[*iterIndex]; @@ -147,19 +149,33 @@ namespace PolyVox Vector3DFloat n1 = v1.getNormal(); n1.normalise(); Vector3DFloat n2 = v2.getNormal(); - n2.normalise(); + n2.normalise(); - v0New.position += (n0 * (n0.dot(v0ToOpp)) * fAmount); - v1New.position += (n1 * (n1.dot(v1ToOpp)) * fAmount); - v2New.position += (n2 * (n2.dot(v2ToOpp)) * fAmount); + if(m_Region.containsPoint(v0.getPosition() + offset, 0.001)) + { + v0New.position += (n0 * (n0.dot(v0ToOpp)) * fAmount); + } + if(m_Region.containsPoint(v1.getPosition() + offset, 0.001)) + { + v1New.position += (n1 * (n1.dot(v1ToOpp)) * fAmount); + } + if(m_Region.containsPoint(v2.getPosition() + offset, 0.001)) + { + v2New.position += (n2 * (n2.dot(v2ToOpp)) * fAmount); + } } } void IndexedSurfacePatch::generateAveragedFaceNormals(bool bNormalise, bool bIncludeEdgeVertices) { + Vector3DFloat offset = static_cast(m_Region.getLowerCorner()); + for(vector::iterator iterVertex = m_vecVertices.begin(); iterVertex != m_vecVertices.end(); iterVertex++) { - iterVertex->setNormal(Vector3DFloat(0.0f,0.0f,0.0f)); + if(m_Region.containsPoint(iterVertex->getPosition() + offset, 0.001)) + { + iterVertex->setNormal(Vector3DFloat(0.0f,0.0f,0.0f)); + } } for(vector::iterator iterIndex = m_vecTriangleIndices.begin(); iterIndex != m_vecTriangleIndices.end();) @@ -173,9 +189,18 @@ namespace PolyVox Vector3DFloat triangleNormal = (v1.getPosition()-v0.getPosition()).cross(v2.getPosition()-v0.getPosition()); - v0.setNormal(v0.getNormal() + triangleNormal); - v1.setNormal(v1.getNormal() + triangleNormal); - v2.setNormal(v2.getNormal() + triangleNormal); + if(m_Region.containsPoint(v0.getPosition() + offset, 0.001)) + { + v0.setNormal(v0.getNormal() + triangleNormal); + } + if(m_Region.containsPoint(v1.getPosition() + offset, 0.001)) + { + v1.setNormal(v1.getNormal() + triangleNormal); + } + if(m_Region.containsPoint(v2.getPosition() + offset, 0.001)) + { + v2.setNormal(v2.getNormal() + triangleNormal); + } } if(bNormalise) diff --git a/library/PolyVoxCore/source/SurfaceExtractor.cpp b/library/PolyVoxCore/source/SurfaceExtractor.cpp index e5a81131..843691d2 100644 --- a/library/PolyVoxCore/source/SurfaceExtractor.cpp +++ b/library/PolyVoxCore/source/SurfaceExtractor.cpp @@ -33,7 +33,7 @@ namespace PolyVox { extractDecimatedSurfaceImpl(&m_volData, m_uLodLevel, region, singleMaterialPatch); } - singleMaterialPatch->m_v3dRegionPosition = region.getLowerCorner(); + singleMaterialPatch->m_Region = region; } uint32_t SurfaceExtractor::getIndex(uint32_t x, uint32_t y, uint32_t regionWidth) diff --git a/library/PolyVoxCore/source/SurfaceExtractors.cpp b/library/PolyVoxCore/source/SurfaceExtractors.cpp index cc2f72a7..646426f9 100644 --- a/library/PolyVoxCore/source/SurfaceExtractors.cpp +++ b/library/PolyVoxCore/source/SurfaceExtractors.cpp @@ -27,6 +27,6 @@ namespace PolyVox extractDecimatedSurfaceImpl(volumeData, uLevel, region, singleMaterialPatch); } - singleMaterialPatch->m_v3dRegionPosition = region.getLowerCorner(); + singleMaterialPatch->m_Region = region; } }