CubicVertex now uses a more memory efficient representation which can be decoded on the CPU or GPU.
This commit is contained in:
parent
1790d8338f
commit
37ba9ab338
@ -81,11 +81,12 @@ int main(int argc, char *argv[])
|
|||||||
auto mesh = extractCubicMesh(&volData, volData.getEnclosingRegion());
|
auto mesh = extractCubicMesh(&volData, volData.getEnclosingRegion());
|
||||||
//auto mesh = extractMarchingCubesMesh(&volData, volData.getEnclosingRegion());
|
//auto mesh = extractMarchingCubesMesh(&volData, volData.getEnclosingRegion());
|
||||||
|
|
||||||
//auto mesh = extractCubicMesh(&volData, PolyVox::Region(Vector3DInt32(0, 0, 0), Vector3DInt32(31, 31, 31)));
|
// The surface extractor outputs the mesh in an efficient compressed format which is not directly suitable for rendering. The easiest approach is to
|
||||||
//auto mesh2 = extractCubicMesh(&volData, PolyVox::Region(Vector3DInt32(32, 32, 32), Vector3DInt32(63, 63, 63)));
|
// 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
|
//Pass the surface to the OpenGL window
|
||||||
openGLWidget.addMesh(mesh);
|
openGLWidget.addMesh(decodedMesh);
|
||||||
//openGLWidget.addMesh(mesh2);
|
//openGLWidget.addMesh(mesh2);
|
||||||
openGLWidget.setViewableRegion(volData.getEnclosingRegion());
|
openGLWidget.setViewableRegion(volData.getEnclosingRegion());
|
||||||
|
|
||||||
|
@ -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.
|
//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<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;
|
cubicVertex.material = uMaterialIn;
|
||||||
rEntry.iIndex = m_meshCurrent->addVertex(cubicVertex);
|
rEntry.iIndex = m_meshCurrent->addVertex(cubicVertex);
|
||||||
rEntry.uMaterial = uMaterialIn;
|
rEntry.uMaterial = uMaterialIn;
|
||||||
|
@ -105,7 +105,7 @@ namespace PolyVox
|
|||||||
Mesh< Vertex< typename MeshType::VertexType::VoxelType > > decode(const MeshType& mesh)
|
Mesh< Vertex< typename MeshType::VertexType::VoxelType > > decode(const MeshType& mesh)
|
||||||
{
|
{
|
||||||
Mesh< Vertex< typename MeshType::VertexType::VoxelType > > result;
|
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++)
|
for(uint32_t ct = 0; ct < mesh.m_vecVertices.size(); ct++)
|
||||||
{
|
{
|
||||||
|
@ -56,8 +56,8 @@ namespace PolyVox
|
|||||||
{
|
{
|
||||||
typedef _VoxelType VoxelType;
|
typedef _VoxelType VoxelType;
|
||||||
|
|
||||||
Vector3DFloat position;
|
Vector3DUint8 position;
|
||||||
Vector3DFloat normal;
|
uint8_t normal;
|
||||||
VoxelType material;
|
VoxelType material;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -81,8 +81,9 @@ namespace PolyVox
|
|||||||
Vertex<VoxelType> decode(const CubicVertex<VoxelType>& cubicVertex)
|
Vertex<VoxelType> decode(const CubicVertex<VoxelType>& cubicVertex)
|
||||||
{
|
{
|
||||||
Vertex<VoxelType> result;
|
Vertex<VoxelType> result;
|
||||||
result.position = cubicVertex.position;
|
Vector3DUint8 temp = cubicVertex.position; // For some reason we can't cast Vector3DUint8 to Vector3DFloat - investigate why.
|
||||||
result.normal = cubicVertex.normal;
|
result.position = Vector3DFloat(temp.getX(), temp.getY(), temp.getZ()) - Vector3DFloat(0.5, 0.5, 0.5);
|
||||||
|
//result.normal = cubicVertex.normal;
|
||||||
result.material = cubicVertex.material;
|
result.material = cubicVertex.material;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user