Merge branch 'develop' into feature/extractor-refactor

This commit is contained in:
David Williams 2014-03-17 16:07:29 +01:00
commit f05d54b985
4 changed files with 17 additions and 29 deletions

View File

@ -108,18 +108,18 @@ namespace PolyVox
* *
* The Marching Cubes algotithm generates vertices which lie between voxels, and ideally the material of the vertex should be interpolated from the materials * The Marching Cubes algotithm generates vertices which lie between voxels, and ideally the material of the vertex should be interpolated from the materials
* of the voxels. In practice, that material type is often an integer identifier (e.g. 1 = rock, 2 = soil, 3 = grass) and an interpolation doean't make sense * of the voxels. In practice, that material type is often an integer identifier (e.g. 1 = rock, 2 = soil, 3 = grass) and an interpolation doean't make sense
* (e.g. soil is not a combination or rock and grass). Therefore this default interpolation just return one material or the other, but if more advanced voxel * (e.g. soil is not a combination or rock and grass). Therefore this default interpolation just returns whichever material is associated with a voxel of the
* types do support interpolation then it can be implemented in this function. * higher density, but if more advanced voxel types do support interpolation then it can be implemented in this function.
*/ */
MaterialType blendMaterials(MaterialType a, MaterialType b, float weight) MaterialType blendMaterials(VoxelType a, VoxelType b, float /*weight*/)
{ {
if(weight < 0.5f) if(convertToDensity(a) > convertToDensity(b))
{ {
return a; return convertToMaterial(a);
} }
else else
{ {
return b; return convertToMaterial(b);
} }
} }

View File

@ -168,7 +168,7 @@ namespace PolyVox
return 1; return 1;
} }
MaterialType blendMaterials(MaterialType /*a*/, MaterialType /*b*/, float /*weight*/) MaterialType blendMaterials(Density<Type> /*a*/, Density<Type> /*b*/, float /*weight*/)
{ {
return 1; return 1;
} }

View File

@ -456,12 +456,8 @@ namespace PolyVox
v3dNormal.normalise(); v3dNormal.normalise();
} }
//Choose one of the two materials to use for the vertex (we don't interpolate as interpolation of // Allow the controller to decide how the material should be derived from the voxels.
//material IDs does not make sense). We take the largest, so that if we are working on a material-only const typename Controller::MaterialType uMaterial = m_controller.blendMaterials(v000, v100, fInterp);
//volume we get the one which is non-zero. Both materials can be non-zero if our volume has a density component.
const typename Controller::MaterialType uMaterial000 = m_controller.convertToMaterial(v000);
const typename Controller::MaterialType uMaterial100 = m_controller.convertToMaterial(v100);
const typename Controller::MaterialType uMaterial = m_controller.blendMaterials(uMaterial000, uMaterial100, fInterp);
const PositionMaterialNormal surfaceVertex(v3dPosition, v3dNormal, static_cast<float>(uMaterial)); const PositionMaterialNormal surfaceVertex(v3dPosition, v3dNormal, static_cast<float>(uMaterial));
const uint32_t uLastVertexIndex = m_meshCurrent->addVertex(surfaceVertex); const uint32_t uLastVertexIndex = m_meshCurrent->addVertex(surfaceVertex);
@ -489,12 +485,8 @@ namespace PolyVox
v3dNormal.normalise(); v3dNormal.normalise();
} }
//Choose one of the two materials to use for the vertex (we don't interpolate as interpolation of // Allow the controller to decide how the material should be derived from the voxels.
//material IDs does not make sense). We take the largest, so that if we are working on a material-only const typename Controller::MaterialType uMaterial = m_controller.blendMaterials(v000, v010, fInterp);
//volume we get the one which is non-zero. Both materials can be non-zero if our volume has a density component.
const typename Controller::MaterialType uMaterial000 = m_controller.convertToMaterial(v000);
const typename Controller::MaterialType uMaterial010 = m_controller.convertToMaterial(v010);
const typename Controller::MaterialType uMaterial = m_controller.blendMaterials(uMaterial000, uMaterial010, fInterp);
const PositionMaterialNormal surfaceVertex(v3dPosition, v3dNormal, static_cast<float>(uMaterial)); const PositionMaterialNormal surfaceVertex(v3dPosition, v3dNormal, static_cast<float>(uMaterial));
const uint32_t uLastVertexIndex = m_meshCurrent->addVertex(surfaceVertex); const uint32_t uLastVertexIndex = m_meshCurrent->addVertex(surfaceVertex);
@ -521,12 +513,8 @@ namespace PolyVox
v3dNormal.normalise(); v3dNormal.normalise();
} }
//Choose one of the two materials to use for the vertex (we don't interpolate as interpolation of // Allow the controller to decide how the material should be derived from the voxels.
//material IDs does not make sense). We take the largest, so that if we are working on a material-only const typename Controller::MaterialType uMaterial = m_controller.blendMaterials(v000, v001, fInterp);
//volume we get the one which is non-zero. Both materials can be non-zero if our volume has a density component.
const typename Controller::MaterialType uMaterial000 = m_controller.convertToMaterial(v000);
const typename Controller::MaterialType uMaterial001 = m_controller.convertToMaterial(v001);
const typename Controller::MaterialType uMaterial = m_controller.blendMaterials(uMaterial000, uMaterial001, fInterp);
const PositionMaterialNormal surfaceVertex(v3dPosition, v3dNormal, static_cast<float>(uMaterial)); const PositionMaterialNormal surfaceVertex(v3dPosition, v3dNormal, static_cast<float>(uMaterial));
const uint32_t uLastVertexIndex = m_meshCurrent->addVertex(surfaceVertex); const uint32_t uLastVertexIndex = m_meshCurrent->addVertex(surfaceVertex);

View File

@ -132,15 +132,15 @@ namespace PolyVox
return voxel.getMaterial(); return voxel.getMaterial();
} }
MaterialType blendMaterials(MaterialType a, MaterialType b, float weight) MaterialType blendMaterials(MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits> a, MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits> b, float /*weight*/)
{ {
if(weight < 0.5f) if(convertToDensity(a) > convertToDensity(b))
{ {
return a; return convertToMaterial(a);
} }
else else
{ {
return b; return convertToMaterial(b);
} }
} }