diff --git a/examples/Basic/main.cpp b/examples/Basic/main.cpp index f123361b..a13da717 100644 --- a/examples/Basic/main.cpp +++ b/examples/Basic/main.cpp @@ -81,11 +81,12 @@ int main(int argc, char *argv[]) auto mesh = extractCubicMesh(&volData, volData.getEnclosingRegion()); //auto mesh = extractMarchingCubesMesh(&volData, volData.getEnclosingRegion()); - //auto mesh = extractCubicMesh(&volData, PolyVox::Region(Vector3DInt32(0, 0, 0), Vector3DInt32(31, 31, 31))); - //auto mesh2 = extractCubicMesh(&volData, PolyVox::Region(Vector3DInt32(32, 32, 32), Vector3DInt32(63, 63, 63))); + // The surface extractor outputs the mesh in an efficient compressed format which is not directly suitable for rendering. The easiest approach is to + // decode this on the CPU as shown below, though more advanced applications can upload the compressed mesh to the GPU and decompress in shader code. + auto decodedMesh = decode(mesh); //Pass the surface to the OpenGL window - openGLWidget.addMesh(mesh); + openGLWidget.addMesh(decodedMesh); //openGLWidget.addMesh(mesh2); openGLWidget.setViewableRegion(volData.getEnclosingRegion()); diff --git a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.inl b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.inl index f62ce7ae..b152f90c 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.inl @@ -215,7 +215,7 @@ namespace PolyVox { //No vertices matched and we've now hit an empty space. Fill it by creating a vertex. The 0.5f offset is because vertices set between voxels in order to build cubes around them. CubicVertex cubicVertex; - cubicVertex.position.setElements(static_cast(uX)-0.5f, static_cast(uY)-0.5f, static_cast(uZ)-0.5f); + cubicVertex.position.setElements(static_cast(uX), static_cast(uY), static_cast(uZ)); cubicVertex.material = uMaterialIn; rEntry.iIndex = m_meshCurrent->addVertex(cubicVertex); rEntry.uMaterial = uMaterialIn; diff --git a/library/PolyVoxCore/include/PolyVoxCore/Mesh.h b/library/PolyVoxCore/include/PolyVoxCore/Mesh.h index bad1a7fb..d23f7716 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Mesh.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Mesh.h @@ -105,7 +105,7 @@ namespace PolyVox Mesh< Vertex< typename MeshType::VertexType::VoxelType > > decode(const MeshType& mesh) { Mesh< Vertex< typename MeshType::VertexType::VoxelType > > result; - result.m_vecVertices.reserve(mesh.m_vecVertices.size()); + result.m_vecVertices.resize(mesh.m_vecVertices.size()); for(uint32_t ct = 0; ct < mesh.m_vecVertices.size(); ct++) { diff --git a/library/PolyVoxCore/include/PolyVoxCore/VertexTypes.h b/library/PolyVoxCore/include/PolyVoxCore/VertexTypes.h index 1f421fd9..fc53fc2e 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/VertexTypes.h +++ b/library/PolyVoxCore/include/PolyVoxCore/VertexTypes.h @@ -56,8 +56,8 @@ namespace PolyVox { typedef _VoxelType VoxelType; - Vector3DFloat position; - Vector3DFloat normal; + Vector3DUint8 position; + uint8_t normal; VoxelType material; }; @@ -81,8 +81,9 @@ namespace PolyVox Vertex decode(const CubicVertex& cubicVertex) { Vertex result; - result.position = cubicVertex.position; - result.normal = cubicVertex.normal; + Vector3DUint8 temp = cubicVertex.position; // For some reason we can't cast Vector3DUint8 to Vector3DFloat - investigate why. + result.position = Vector3DFloat(temp.getX(), temp.getY(), temp.getZ()) - Vector3DFloat(0.5, 0.5, 0.5); + //result.normal = cubicVertex.normal; result.material = cubicVertex.material; return result; }