Exposed DensityType and MaterialType on voxels.
This commit is contained in:
parent
97e6b56778
commit
b972a2ceaf
@ -39,14 +39,21 @@ namespace PolyVox
|
||||
/// funtion is used to determine what material should be assigned to the resulting mesh.
|
||||
///
|
||||
/// This class meets these requirements, although it only actually stores a density value.
|
||||
/// For the getMaterial() function it just returens a constant value of '1'.
|
||||
/// For the getMaterial() function it just returns a constant value of '1'.
|
||||
///
|
||||
/// \sa Material, MaterialDensityPair
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
template <typename DensityType>
|
||||
template <typename Type>
|
||||
class Density
|
||||
{
|
||||
public:
|
||||
//We expose DensityType and MaterialType in this way so that, when code is
|
||||
//templatised on voxel type, it can determine the underlying storage type
|
||||
//using code such as 'VoxelType::DensityType value = voxel.getDensity()'
|
||||
//or 'VoxelType::MaterialType value = voxel.getMaterial()'.
|
||||
typedef Type DensityType;
|
||||
typedef uint8_t MaterialType;
|
||||
|
||||
Density() : m_uDensity(0) {}
|
||||
Density(DensityType uDensity) : m_uDensity(uDensity) {}
|
||||
|
||||
@ -61,10 +68,10 @@ namespace PolyVox
|
||||
}
|
||||
|
||||
DensityType getDensity() const throw() { return m_uDensity; }
|
||||
uint32_t getMaterial() const throw() { return 1; }
|
||||
MaterialType getMaterial() const throw() { return 1; }
|
||||
|
||||
void setDensity(DensityType uDensity) { m_uDensity = uDensity; }
|
||||
void setMaterial(uint32_t uMaterial) { assert(false); } //Cannot set material on voxel of type Density
|
||||
void setMaterial(MaterialType /*uMaterial*/) { assert(false); } //Cannot set material on voxel of type Density
|
||||
|
||||
static DensityType getMaxDensity() throw() { return (std::numeric_limits<DensityType>::max)(); }
|
||||
static DensityType getMinDensity() throw() { return (std::numeric_limits<DensityType>::min)(); }
|
||||
|
@ -43,10 +43,17 @@ namespace PolyVox
|
||||
///
|
||||
/// \sa Density, MaterialDensityPair
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
template <typename MaterialType>
|
||||
template <typename Type>
|
||||
class Material
|
||||
{
|
||||
public:
|
||||
//We expose DensityType and MaterialType in this way so that, when code is
|
||||
//templatised on voxel type, it can determine the underlying storage type
|
||||
//using code such as 'VoxelType::DensityType value = voxel.getDensity()'
|
||||
//or 'VoxelType::MaterialType value = voxel.getMaterial()'.
|
||||
typedef uint8_t DensityType;
|
||||
typedef Type MaterialType;
|
||||
|
||||
Material() : m_uMaterial(0) {}
|
||||
Material(MaterialType uMaterial) : m_uMaterial(uMaterial) {}
|
||||
|
||||
@ -60,7 +67,7 @@ namespace PolyVox
|
||||
return !(*this == rhs);
|
||||
}
|
||||
|
||||
uint32_t getDensity() const throw()
|
||||
DensityType getDensity() const throw()
|
||||
{
|
||||
//We don't actually have a density, so make one up based on the material.
|
||||
if(m_uMaterial == 0)
|
||||
@ -75,12 +82,12 @@ namespace PolyVox
|
||||
|
||||
MaterialType getMaterial() const throw() { return m_uMaterial; }
|
||||
|
||||
void setDensity(uint32_t /*uDensity*/) { assert(false); } //Cannot set density on voxel of type Material
|
||||
void setDensity(DensityType /*uDensity*/) { assert(false); } //Cannot set density on voxel of type Material
|
||||
void setMaterial(MaterialType uMaterial) { m_uMaterial = uMaterial; }
|
||||
|
||||
static uint32_t getMaxDensity() throw() { return 2; }
|
||||
static uint32_t getMinDensity() throw() { return 0; }
|
||||
static uint32_t getThreshold() throw() { return 1; }
|
||||
static DensityType getMaxDensity() throw() { return 2; }
|
||||
static DensityType getMinDensity() throw() { return 0; }
|
||||
static DensityType getThreshold() throw() { return 1; }
|
||||
|
||||
private:
|
||||
MaterialType m_uMaterial;
|
||||
|
@ -46,6 +46,13 @@ namespace PolyVox
|
||||
class MaterialDensityPair
|
||||
{
|
||||
public:
|
||||
//We expose DensityType and MaterialType in this way so that, when code is
|
||||
//templatised on voxel type, it can determine the underlying storage type
|
||||
//using code such as 'VoxelType::DensityType value = voxel.getDensity()'
|
||||
//or 'VoxelType::MaterialType value = voxel.getMaterial()'.
|
||||
typedef Type DensityType;
|
||||
typedef Type MaterialType;
|
||||
|
||||
MaterialDensityPair() : m_uMaterial(0), m_uDensity(0) {}
|
||||
MaterialDensityPair(Type uMaterial, Type uDensity) : m_uMaterial(uMaterial), m_uDensity(uDensity) {}
|
||||
|
||||
@ -59,19 +66,19 @@ namespace PolyVox
|
||||
return !(*this == rhs);
|
||||
}
|
||||
|
||||
Type getDensity() const throw() { return m_uDensity; }
|
||||
Type getMaterial() const throw() { return m_uMaterial; }
|
||||
DensityType getDensity() const throw() { return m_uDensity; }
|
||||
MaterialType getMaterial() const throw() { return m_uMaterial; }
|
||||
|
||||
void setDensity(Type uDensity) { m_uDensity = uDensity; }
|
||||
void setMaterial(Type uMaterial) { m_uMaterial = uMaterial; }
|
||||
void setDensity(DensityType uDensity) { m_uDensity = uDensity; }
|
||||
void setMaterial(MaterialType uMaterial) { m_uMaterial = uMaterial; }
|
||||
|
||||
static Type getMaxDensity() throw() { return (0x01 << NoOfDensityBits) - 1; }
|
||||
static Type getMinDensity() throw() { return 0; }
|
||||
static Type getThreshold() throw() {return 0x01 << (NoOfDensityBits - 1);}
|
||||
static DensityType getMaxDensity() throw() { return (0x01 << NoOfDensityBits) - 1; }
|
||||
static DensityType getMinDensity() throw() { return 0; }
|
||||
static DensityType getThreshold() throw() {return 0x01 << (NoOfDensityBits - 1);}
|
||||
|
||||
private:
|
||||
Type m_uMaterial : NoOfMaterialBits;
|
||||
Type m_uDensity : NoOfDensityBits;
|
||||
MaterialType m_uMaterial : NoOfMaterialBits;
|
||||
DensityType m_uDensity : NoOfDensityBits;
|
||||
};
|
||||
|
||||
typedef MaterialDensityPair<uint8_t, 4, 4> MaterialDensityPair44;
|
||||
|
Loading…
x
Reference in New Issue
Block a user