CubicVertex now uses a more memory efficient representation which can be decoded on the CPU or GPU.

This commit is contained in:
David Williams 2014-05-27 23:01:38 +02:00
parent 1790d8338f
commit 37ba9ab338
4 changed files with 11 additions and 9 deletions

View File

@ -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());

View File

@ -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<typename VolumeType::VoxelType> cubicVertex;
cubicVertex.position.setElements(static_cast<float>(uX)-0.5f, static_cast<float>(uY)-0.5f, static_cast<float>(uZ)-0.5f);
cubicVertex.position.setElements(static_cast<uint8_t>(uX), static_cast<uint8_t>(uY), static_cast<uint8_t>(uZ));
cubicVertex.material = uMaterialIn;
rEntry.iIndex = m_meshCurrent->addVertex(cubicVertex);
rEntry.uMaterial = uMaterialIn;

View File

@ -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++)
{

View File

@ -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<VoxelType> decode(const CubicVertex<VoxelType>& cubicVertex)
{
Vertex<VoxelType> 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;
}