diff --git a/examples/OpenGL/main.cpp b/examples/OpenGL/main.cpp index a95d66e5..12d1068f 100644 --- a/examples/OpenGL/main.cpp +++ b/examples/OpenGL/main.cpp @@ -130,8 +130,9 @@ int main(int argc, char *argv[]) // The returned mesh needs to be decoded to be appropriate for GPU rendering. auto decodedMesh = decode(mesh); - //Pass the surface to the OpenGL window - openGLWidget.addMesh(decodedMesh, Vector3DInt32(x, y, z)); + // Pass the surface to the OpenGL window. Note that we are also passing an offset in this multi-mesh example. This is because + // the surface extractors return a mesh with 'local space' positions to reduce storage requirements and precision problems. + openGLWidget.addMesh(decodedMesh, decodedMesh.getOffset()); meshCounter++; } diff --git a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.inl b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.inl index 63d021e2..d05a7c57 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.inl @@ -196,7 +196,7 @@ namespace PolyVox } } - m_meshCurrent->m_Region = m_regSizeInVoxels; + m_meshCurrent->setOffset(m_regSizeInVoxels.getLowerCorner()); m_meshCurrent->removeUnusedVertices(); m_meshCurrent->m_vecLodRecords.clear(); diff --git a/library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.inl b/library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.inl index 0f506763..382dc85a 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.inl @@ -122,7 +122,7 @@ namespace PolyVox m_regSliceCurrent.shift(Vector3DInt32(0,0,1)); } - m_meshCurrent->m_Region = m_regSizeInVoxels; + m_meshCurrent->setOffset(m_regSizeInVoxels.getLowerCorner()); m_meshCurrent->m_vecLodRecords.clear(); LodRecord lodRecord; diff --git a/library/PolyVoxCore/include/PolyVoxCore/Mesh.h b/library/PolyVoxCore/include/PolyVoxCore/Mesh.h index 408c1ddc..18537e9e 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Mesh.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Mesh.h @@ -59,6 +59,9 @@ namespace PolyVox uint32_t getNoOfIndices(void) const; uint32_t getNoOfVertices(void) const; const std::vector& getVertices(void) const; + const Vector3DInt32& getOffset(void) const; + + void setOffset(const Vector3DInt32& offset); void addTriangle(uint32_t index0, uint32_t index1, uint32_t index2); uint32_t addVertex(const VertexType& vertex); @@ -66,7 +69,7 @@ namespace PolyVox bool isEmpty(void) const; void removeUnusedVertices(void); - Region m_Region; + Vector3DInt32 m_offset; public: std::vector m_vecTriangleIndices; @@ -88,7 +91,7 @@ namespace PolyVox result.m_vecTriangleIndices = mesh.m_vecTriangleIndices; - result.m_Region = mesh.m_Region; + result.m_offset = mesh.m_offset; return result; } diff --git a/library/PolyVoxCore/include/PolyVoxCore/Mesh.inl b/library/PolyVoxCore/include/PolyVoxCore/Mesh.inl index 2f62c051..d2363046 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Mesh.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/Mesh.inl @@ -55,7 +55,19 @@ namespace PolyVox const std::vector& Mesh::getVertices(void) const { return m_vecVertices; - } + } + + template + const Vector3DInt32& Mesh::getOffset(void) const + { + return m_offset; + } + + template + void Mesh::setOffset(const Vector3DInt32& offset) + { + m_offset = offset; + } template void Mesh::addTriangle(uint32_t index0, uint32_t index1, uint32_t index2)