CubicSurfaceExtractor now makes use of callback.
This commit is contained in:
parent
96c3b75804
commit
92ca1048b3
@ -87,78 +87,76 @@ namespace PolyVox
|
|||||||
|
|
||||||
volumeSampler.setPosition(x,y,z);
|
volumeSampler.setPosition(x,y,z);
|
||||||
|
|
||||||
|
uint32_t material; //Filled in by callback
|
||||||
typename VolumeType::VoxelType currentVoxel = volumeSampler.getVoxel();
|
typename VolumeType::VoxelType currentVoxel = volumeSampler.getVoxel();
|
||||||
bool currentVoxelIsSolid = currentVoxel.getMaterial() != 0;
|
|
||||||
|
|
||||||
typename VolumeType::VoxelType negXVoxel = volumeSampler.peekVoxel1nx0py0pz();
|
typename VolumeType::VoxelType negXVoxel = volumeSampler.peekVoxel1nx0py0pz();
|
||||||
bool negXVoxelIsSolid = negXVoxel.getMaterial() != 0;
|
typename VolumeType::VoxelType negYVoxel = volumeSampler.peekVoxel0px1ny0pz();
|
||||||
|
typename VolumeType::VoxelType negZVoxel = volumeSampler.peekVoxel0px0py1nz();
|
||||||
|
|
||||||
if(currentVoxelIsSolid != negXVoxelIsSolid)
|
// X
|
||||||
|
if(m_funcIsQuadNeededCallback(currentVoxel, negXVoxel, material))
|
||||||
{
|
{
|
||||||
uint32_t material = (std::max)(currentVoxel.getMaterial(), negXVoxel.getMaterial());
|
|
||||||
|
|
||||||
uint32_t v0 = addVertex(regX - 0.5f, regY - 0.5f, regZ - 0.5f, material, m_previousSliceVertices);
|
uint32_t v0 = addVertex(regX - 0.5f, regY - 0.5f, regZ - 0.5f, material, m_previousSliceVertices);
|
||||||
uint32_t v1 = addVertex(regX - 0.5f, regY - 0.5f, regZ + 0.5f, material, m_currentSliceVertices);
|
uint32_t v1 = addVertex(regX - 0.5f, regY - 0.5f, regZ + 0.5f, material, m_currentSliceVertices);
|
||||||
uint32_t v2 = addVertex(regX - 0.5f, regY + 0.5f, regZ + 0.5f, material, m_currentSliceVertices);
|
uint32_t v2 = addVertex(regX - 0.5f, regY + 0.5f, regZ + 0.5f, material, m_currentSliceVertices);
|
||||||
uint32_t v3 = addVertex(regX - 0.5f, regY + 0.5f, regZ - 0.5f, material, m_previousSliceVertices);
|
uint32_t v3 = addVertex(regX - 0.5f, regY + 0.5f, regZ - 0.5f, material, m_previousSliceVertices);
|
||||||
|
|
||||||
if(currentVoxelIsSolid > negXVoxelIsSolid)
|
|
||||||
{
|
|
||||||
m_vecQuads[NegativeX][regX].push_back(Quad(v0, v1, v2, v3));
|
m_vecQuads[NegativeX][regX].push_back(Quad(v0, v1, v2, v3));
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
if(m_funcIsQuadNeededCallback(negXVoxel, currentVoxel, material))
|
||||||
{
|
{
|
||||||
m_vecQuads[PositiveX][regX].push_back(Quad(v0, v3, v2, v1));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
typename VolumeType::VoxelType negYVoxel = volumeSampler.peekVoxel0px1ny0pz();
|
|
||||||
bool negYVoxelIsSolid = negYVoxel.getMaterial() != 0;
|
|
||||||
|
|
||||||
if(currentVoxelIsSolid != negYVoxelIsSolid)
|
|
||||||
{
|
|
||||||
int material = (std::max)(currentVoxel.getMaterial(),negYVoxel.getMaterial());
|
|
||||||
|
|
||||||
uint32_t v0 = addVertex(regX - 0.5f, regY - 0.5f, regZ - 0.5f, material, m_previousSliceVertices);
|
uint32_t v0 = addVertex(regX - 0.5f, regY - 0.5f, regZ - 0.5f, material, m_previousSliceVertices);
|
||||||
uint32_t v1 = addVertex(regX - 0.5f, regY - 0.5f, regZ + 0.5f, material, m_currentSliceVertices);
|
uint32_t v1 = addVertex(regX - 0.5f, regY - 0.5f, regZ + 0.5f, material, m_currentSliceVertices);
|
||||||
|
uint32_t v2 = addVertex(regX - 0.5f, regY + 0.5f, regZ + 0.5f, material, m_currentSliceVertices);
|
||||||
|
uint32_t v3 = addVertex(regX - 0.5f, regY + 0.5f, regZ - 0.5f, material, m_previousSliceVertices);
|
||||||
|
|
||||||
|
m_vecQuads[PositiveX][regX].push_back(Quad(v0, v3, v2, v1));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Y
|
||||||
|
if(m_funcIsQuadNeededCallback(currentVoxel, negYVoxel, material))
|
||||||
|
{
|
||||||
|
uint32_t v0 = addVertex(regX - 0.5f, regY - 0.5f, regZ - 0.5f, material, m_previousSliceVertices);
|
||||||
|
uint32_t v1 = addVertex(regX + 0.5f, regY - 0.5f, regZ - 0.5f, material, m_previousSliceVertices);
|
||||||
uint32_t v2 = addVertex(regX + 0.5f, regY - 0.5f, regZ + 0.5f, material, m_currentSliceVertices);
|
uint32_t v2 = addVertex(regX + 0.5f, regY - 0.5f, regZ + 0.5f, material, m_currentSliceVertices);
|
||||||
uint32_t v3 = addVertex(regX + 0.5f, regY - 0.5f, regZ - 0.5f, material, m_previousSliceVertices);
|
uint32_t v3 = addVertex(regX - 0.5f, regY - 0.5f, regZ + 0.5f, material, m_currentSliceVertices);
|
||||||
|
|
||||||
if(currentVoxelIsSolid > negYVoxelIsSolid)
|
m_vecQuads[NegativeY][regY].push_back(Quad(v0, v1, v2, v3));
|
||||||
{
|
|
||||||
//NOTE: For some reason y windong is opposite of X and Z. Investigate this...
|
|
||||||
m_vecQuads[NegativeY][regY].push_back(Quad(v0, v3, v2, v1));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//NOTE: For some reason y windong is opposite of X and Z. Investigate this...
|
|
||||||
m_vecQuads[PositiveY][regY].push_back(Quad(v0, v1, v2, v3));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
typename VolumeType::VoxelType negZVoxel = volumeSampler.peekVoxel0px0py1nz();
|
if(m_funcIsQuadNeededCallback(negYVoxel, currentVoxel, material))
|
||||||
bool negZVoxelIsSolid = negZVoxel.getMaterial() != 0;
|
|
||||||
|
|
||||||
if(currentVoxelIsSolid != negZVoxelIsSolid)
|
|
||||||
{
|
{
|
||||||
int material = (std::max)(currentVoxel.getMaterial(), negZVoxel.getMaterial());
|
uint32_t v0 = addVertex(regX - 0.5f, regY - 0.5f, regZ - 0.5f, material, m_previousSliceVertices);
|
||||||
|
uint32_t v1 = addVertex(regX + 0.5f, regY - 0.5f, regZ - 0.5f, material, m_previousSliceVertices);
|
||||||
|
uint32_t v2 = addVertex(regX + 0.5f, regY - 0.5f, regZ + 0.5f, material, m_currentSliceVertices);
|
||||||
|
uint32_t v3 = addVertex(regX - 0.5f, regY - 0.5f, regZ + 0.5f, material, m_currentSliceVertices);
|
||||||
|
|
||||||
|
m_vecQuads[PositiveY][regY].push_back(Quad(v0, v3, v2, v1));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Z
|
||||||
|
if(m_funcIsQuadNeededCallback(currentVoxel, negZVoxel, material))
|
||||||
|
{
|
||||||
uint32_t v0 = addVertex(regX - 0.5f, regY - 0.5f, regZ - 0.5f, material, m_previousSliceVertices);
|
uint32_t v0 = addVertex(regX - 0.5f, regY - 0.5f, regZ - 0.5f, material, m_previousSliceVertices);
|
||||||
uint32_t v1 = addVertex(regX - 0.5f, regY + 0.5f, regZ - 0.5f, material, m_previousSliceVertices);
|
uint32_t v1 = addVertex(regX - 0.5f, regY + 0.5f, regZ - 0.5f, material, m_previousSliceVertices);
|
||||||
uint32_t v2 = addVertex(regX + 0.5f, regY + 0.5f, regZ - 0.5f, material, m_previousSliceVertices);
|
uint32_t v2 = addVertex(regX + 0.5f, regY + 0.5f, regZ - 0.5f, material, m_previousSliceVertices);
|
||||||
uint32_t v3 = addVertex(regX + 0.5f, regY - 0.5f, regZ - 0.5f, material, m_previousSliceVertices);
|
uint32_t v3 = addVertex(regX + 0.5f, regY - 0.5f, regZ - 0.5f, material, m_previousSliceVertices);
|
||||||
|
|
||||||
if(currentVoxelIsSolid > negZVoxelIsSolid)
|
|
||||||
{
|
|
||||||
m_vecQuads[NegativeZ][regZ].push_back(Quad(v0, v1, v2, v3));
|
m_vecQuads[NegativeZ][regZ].push_back(Quad(v0, v1, v2, v3));
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
if(m_funcIsQuadNeededCallback(negZVoxel, currentVoxel, material))
|
||||||
{
|
{
|
||||||
|
uint32_t v0 = addVertex(regX - 0.5f, regY - 0.5f, regZ - 0.5f, material, m_previousSliceVertices);
|
||||||
|
uint32_t v1 = addVertex(regX - 0.5f, regY + 0.5f, regZ - 0.5f, material, m_previousSliceVertices);
|
||||||
|
uint32_t v2 = addVertex(regX + 0.5f, regY + 0.5f, regZ - 0.5f, material, m_previousSliceVertices);
|
||||||
|
uint32_t v3 = addVertex(regX + 0.5f, regY - 0.5f, regZ - 0.5f, material, m_previousSliceVertices);
|
||||||
|
|
||||||
m_vecQuads[PositiveZ][regZ].push_back(Quad(v0, v3, v2, v1));
|
m_vecQuads[PositiveZ][regZ].push_back(Quad(v0, v3, v2, v1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
m_previousSliceVertices.swap(m_currentSliceVertices);
|
m_previousSliceVertices.swap(m_currentSliceVertices);
|
||||||
memset(m_currentSliceVertices.getRawData(), 0xff, m_currentSliceVertices.getNoOfElements() * sizeof(IndexAndMaterial));
|
memset(m_currentSliceVertices.getRawData(), 0xff, m_currentSliceVertices.getNoOfElements() * sizeof(IndexAndMaterial));
|
||||||
|
@ -49,7 +49,7 @@ namespace PolyVox
|
|||||||
float regY = static_cast<float>(y - m_regSizeInVoxels.getLowerCorner().getY());
|
float regY = static_cast<float>(y - m_regSizeInVoxels.getLowerCorner().getY());
|
||||||
float regZ = static_cast<float>(z - m_regSizeInVoxels.getLowerCorner().getZ());
|
float regZ = static_cast<float>(z - m_regSizeInVoxels.getLowerCorner().getZ());
|
||||||
|
|
||||||
float material = 0.0f;
|
uint32_t material = 0.0f;
|
||||||
|
|
||||||
if(m_funcIsQuadNeededCallback(m_volData->getVoxelAt(x,y,z), m_volData->getVoxelAt(x+1,y,z), material))
|
if(m_funcIsQuadNeededCallback(m_volData->getVoxelAt(x,y,z), m_volData->getVoxelAt(x+1,y,z), material))
|
||||||
{
|
{
|
||||||
|
@ -24,17 +24,19 @@ freely, subject to the following restrictions:
|
|||||||
#ifndef __PolyVox_DefaultIsQuadNeeded_H__
|
#ifndef __PolyVox_DefaultIsQuadNeeded_H__
|
||||||
#define __PolyVox_DefaultIsQuadNeeded_H__
|
#define __PolyVox_DefaultIsQuadNeeded_H__
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
namespace PolyVox
|
namespace PolyVox
|
||||||
{
|
{
|
||||||
template<typename VoxelType>
|
template<typename VoxelType>
|
||||||
class DefaultIsQuadNeeded
|
class DefaultIsQuadNeeded
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
bool operator()(VoxelType back, VoxelType front, float& materialToUse)
|
bool operator()(VoxelType back, VoxelType front, uint32_t& materialToUse)
|
||||||
{
|
{
|
||||||
if((back > 0) && (front == 0))
|
if((back > 0) && (front == 0))
|
||||||
{
|
{
|
||||||
materialToUse = static_cast<float>(back);
|
materialToUse = static_cast<uint32_t>(back);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -72,11 +72,11 @@ namespace PolyVox
|
|||||||
class DefaultIsQuadNeeded< Material<Type> >
|
class DefaultIsQuadNeeded< Material<Type> >
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
bool operator()(Material<Type> back, Material<Type> front, float& materialToUse)
|
bool operator()(Material<Type> back, Material<Type> front, uint32_t& materialToUse)
|
||||||
{
|
{
|
||||||
if((back.getMaterial() > 0) && (front.getMaterial() == 0))
|
if((back.getMaterial() > 0) && (front.getMaterial() == 0))
|
||||||
{
|
{
|
||||||
materialToUse = static_cast<float>(back.getMaterial());
|
materialToUse = static_cast<uint32_t>(back.getMaterial());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -90,11 +90,11 @@ namespace PolyVox
|
|||||||
class DefaultIsQuadNeeded< MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits> >
|
class DefaultIsQuadNeeded< MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits> >
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
bool operator()(MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits> back, MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits> front, float& materialToUse)
|
bool operator()(MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits> back, MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits> front, uint32_t& materialToUse)
|
||||||
{
|
{
|
||||||
if((back.getMaterial() > 0) && (front.getMaterial() == 0))
|
if((back.getMaterial() > 0) && (front.getMaterial() == 0))
|
||||||
{
|
{
|
||||||
materialToUse = static_cast<float>(back.getMaterial());
|
materialToUse = static_cast<uint32_t>(back.getMaterial());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
Loading…
x
Reference in New Issue
Block a user