diff --git a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.h b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.h index 03e973a3..efd001e4 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.h +++ b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.h @@ -32,9 +32,37 @@ freely, subject to the following restrictions: #include "PolyVoxCore/BaseVolume.h" //For wrap modes... should move these? #include "PolyVoxCore/DefaultIsQuadNeeded.h" #include "PolyVoxCore/Mesh.h" +#include "PolyVoxCore/VertexTypes.h" namespace PolyVox { +#ifdef SWIG + struct CubicVertex +#else + template + struct POLYVOX_API CubicVertex +#endif + { + typedef _DataType DataType; + + Vector3DUint8 position; + uint8_t normal; + DataType data; + }; + + // Hopefully the compiler will implement the 'Return value optimization' here, but + // performance critical code will most likely decode the vertices in a shader anyway. + template + Vertex decode(const CubicVertex& cubicVertex) + { + Vertex result; + 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.data = cubicVertex.data; + return result; + } + /// The CubicSurfaceExtractor creates a mesh in which each voxel appears to be rendered as a cube //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// Introduction diff --git a/library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.h b/library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.h index 6510ac5c..a609326f 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.h +++ b/library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.h @@ -31,9 +31,44 @@ freely, subject to the following restrictions: #include "PolyVoxCore/BaseVolume.h" //For wrap modes... should move these? #include "PolyVoxCore/Mesh.h" #include "PolyVoxCore/DefaultMarchingCubesController.h" +#include "PolyVoxCore/VertexTypes.h" namespace PolyVox { +#ifdef SWIG + struct MarchingCubesVertex +#else + template + struct POLYVOX_API MarchingCubesVertex +#endif + { + typedef _DataType DataType; + + Vector3DUint16 position; + uint16_t normal; + DataType data; + }; + + // Hopefully the compiler will implement the 'Return value optimization' here, but + // performance critical code will most likely decode the vertices in a shader anyway. + template + Vertex decode(const MarchingCubesVertex& marchingCubesVertex) + { + Vertex result; + result.position = Vector3DFloat(marchingCubesVertex.position.getX(), marchingCubesVertex.position.getY(), marchingCubesVertex.position.getZ()); + result.position *= (1.0 / 256.0); + + uint16_t encodedX = (marchingCubesVertex.normal >> 10) & 0x1F; + uint16_t encodedY = (marchingCubesVertex.normal >> 5) & 0x1F; + uint16_t encodedZ = (marchingCubesVertex.normal) & 0x1F; + result.normal = Vector3DFloat(encodedX, encodedY, encodedZ); + result.normal /= 15.5f; + result.normal -= Vector3DFloat(1.0f, 1.0f, 1.0f); + + result.data = marchingCubesVertex.data; + return result; + } + template< typename VolumeType, typename Controller = DefaultMarchingCubesController > class MarchingCubesSurfaceExtractor { diff --git a/library/PolyVoxCore/include/PolyVoxCore/VertexTypes.h b/library/PolyVoxCore/include/PolyVoxCore/VertexTypes.h index a4c31b27..964ff88d 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/VertexTypes.h +++ b/library/PolyVoxCore/include/PolyVoxCore/VertexTypes.h @@ -46,67 +46,6 @@ namespace PolyVox Vector3DFloat normal; DataType data; }; - -#ifdef SWIG - struct CubicVertex -#else - template - struct POLYVOX_API CubicVertex -#endif - { - typedef _DataType DataType; - - Vector3DUint8 position; - uint8_t normal; - DataType data; - }; - -#ifdef SWIG - struct MarchingCubesVertex -#else - template - struct POLYVOX_API MarchingCubesVertex -#endif - { - typedef _DataType DataType; - - Vector3DUint16 position; - uint16_t normal; - DataType data; - }; - - // Hopefully the compiler will implement the 'Return value optimization' here, but - // performance critical code will most likely decode the vertices in a shader anyway. - template - Vertex decode(const CubicVertex& cubicVertex) - { - Vertex result; - 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.data = cubicVertex.data; - return result; - } - - // Hopefully the compiler will implement the 'Return value optimization' here, but - // performance critical code will most likely decode the vertices in a shader anyway. - template - Vertex decode(const MarchingCubesVertex& marchingCubesVertex) - { - Vertex result; - result.position = Vector3DFloat(marchingCubesVertex.position.getX(), marchingCubesVertex.position.getY(), marchingCubesVertex.position.getZ()); - result.position *= (1.0 / 256.0); - - uint16_t encodedX = (marchingCubesVertex.normal >> 10) & 0x1F; - uint16_t encodedY = (marchingCubesVertex.normal >> 5) & 0x1F; - uint16_t encodedZ = (marchingCubesVertex.normal) & 0x1F; - result.normal = Vector3DFloat(encodedX, encodedY, encodedZ); - result.normal /= 15.5f; - result.normal -= Vector3DFloat(1.0f, 1.0f, 1.0f); - - result.data = marchingCubesVertex.data; - return result; - } } #endif