The new, more compact vertex types are specific to their respective surface extractors, so they belong in the corresponding source files.
This commit is contained in:
parent
224c27de50
commit
78ac1d12b5
@ -32,9 +32,37 @@ freely, subject to the following restrictions:
|
|||||||
#include "PolyVoxCore/BaseVolume.h" //For wrap modes... should move these?
|
#include "PolyVoxCore/BaseVolume.h" //For wrap modes... should move these?
|
||||||
#include "PolyVoxCore/DefaultIsQuadNeeded.h"
|
#include "PolyVoxCore/DefaultIsQuadNeeded.h"
|
||||||
#include "PolyVoxCore/Mesh.h"
|
#include "PolyVoxCore/Mesh.h"
|
||||||
|
#include "PolyVoxCore/VertexTypes.h"
|
||||||
|
|
||||||
namespace PolyVox
|
namespace PolyVox
|
||||||
{
|
{
|
||||||
|
#ifdef SWIG
|
||||||
|
struct CubicVertex
|
||||||
|
#else
|
||||||
|
template<typename _DataType>
|
||||||
|
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<typename DataType>
|
||||||
|
Vertex<DataType> decode(const CubicVertex<DataType>& cubicVertex)
|
||||||
|
{
|
||||||
|
Vertex<DataType> 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
|
/// The CubicSurfaceExtractor creates a mesh in which each voxel appears to be rendered as a cube
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
/// Introduction
|
/// Introduction
|
||||||
|
@ -31,9 +31,44 @@ freely, subject to the following restrictions:
|
|||||||
#include "PolyVoxCore/BaseVolume.h" //For wrap modes... should move these?
|
#include "PolyVoxCore/BaseVolume.h" //For wrap modes... should move these?
|
||||||
#include "PolyVoxCore/Mesh.h"
|
#include "PolyVoxCore/Mesh.h"
|
||||||
#include "PolyVoxCore/DefaultMarchingCubesController.h"
|
#include "PolyVoxCore/DefaultMarchingCubesController.h"
|
||||||
|
#include "PolyVoxCore/VertexTypes.h"
|
||||||
|
|
||||||
namespace PolyVox
|
namespace PolyVox
|
||||||
{
|
{
|
||||||
|
#ifdef SWIG
|
||||||
|
struct MarchingCubesVertex
|
||||||
|
#else
|
||||||
|
template<typename _DataType>
|
||||||
|
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<typename DataType>
|
||||||
|
Vertex<DataType> decode(const MarchingCubesVertex<DataType>& marchingCubesVertex)
|
||||||
|
{
|
||||||
|
Vertex<DataType> 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<typename VolumeType::VoxelType> >
|
template< typename VolumeType, typename Controller = DefaultMarchingCubesController<typename VolumeType::VoxelType> >
|
||||||
class MarchingCubesSurfaceExtractor
|
class MarchingCubesSurfaceExtractor
|
||||||
{
|
{
|
||||||
|
@ -46,67 +46,6 @@ namespace PolyVox
|
|||||||
Vector3DFloat normal;
|
Vector3DFloat normal;
|
||||||
DataType data;
|
DataType data;
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef SWIG
|
|
||||||
struct CubicVertex
|
|
||||||
#else
|
|
||||||
template<typename _DataType>
|
|
||||||
struct POLYVOX_API CubicVertex
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
typedef _DataType DataType;
|
|
||||||
|
|
||||||
Vector3DUint8 position;
|
|
||||||
uint8_t normal;
|
|
||||||
DataType data;
|
|
||||||
};
|
|
||||||
|
|
||||||
#ifdef SWIG
|
|
||||||
struct MarchingCubesVertex
|
|
||||||
#else
|
|
||||||
template<typename _DataType>
|
|
||||||
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<typename DataType>
|
|
||||||
Vertex<DataType> decode(const CubicVertex<DataType>& cubicVertex)
|
|
||||||
{
|
|
||||||
Vertex<DataType> 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<typename DataType>
|
|
||||||
Vertex<DataType> decode(const MarchingCubesVertex<DataType>& marchingCubesVertex)
|
|
||||||
{
|
|
||||||
Vertex<DataType> 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
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user