diff --git a/library/PolyVoxCore/include/PolyVoxCore/DefaultMarchingCubesController.h b/library/PolyVoxCore/include/PolyVoxCore/DefaultMarchingCubesController.h index 7be8dc9e..55eef19e 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/DefaultMarchingCubesController.h +++ b/library/PolyVoxCore/include/PolyVoxCore/DefaultMarchingCubesController.h @@ -103,6 +103,26 @@ namespace PolyVox return 1; } + /** + * Returns a material which is in some sense a weighted combination of the supplied 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 + * (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 + * types do support interpolation then it can be implemented in this function. + */ + MaterialType blendMaterials(MaterialType a, MaterialType b, float weight) + { + if(weight < 0.5f) + { + return a; + } + else + { + return b; + } + } + /** * Returns the density value which was passed to the constructor. * diff --git a/library/PolyVoxCore/include/PolyVoxCore/Density.h b/library/PolyVoxCore/include/PolyVoxCore/Density.h index 8869b094..72248fda 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Density.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Density.h @@ -168,6 +168,11 @@ namespace PolyVox return 1; } + MaterialType blendMaterials(MaterialType /*a*/, MaterialType /*b*/, float /*weight*/) + { + return 1; + } + DensityType getThreshold(void) { return m_tThreshold; diff --git a/library/PolyVoxCore/include/PolyVoxCore/MaterialDensityPair.h b/library/PolyVoxCore/include/PolyVoxCore/MaterialDensityPair.h index cdde07f7..6f9e2d11 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/MaterialDensityPair.h +++ b/library/PolyVoxCore/include/PolyVoxCore/MaterialDensityPair.h @@ -132,6 +132,18 @@ namespace PolyVox return voxel.getMaterial(); } + MaterialType blendMaterials(MaterialType a, MaterialType b, float weight) + { + if(weight < 0.5f) + { + return a; + } + else + { + return b; + } + } + DensityType getThreshold(void) { return m_tThreshold; diff --git a/tests/TestSurfaceExtractor.cpp b/tests/TestSurfaceExtractor.cpp index 45c0958a..796f3b2c 100644 --- a/tests/TestSurfaceExtractor.cpp +++ b/tests/TestSurfaceExtractor.cpp @@ -55,6 +55,11 @@ public: return 1; } + float blendMaterials(float /*a*/, float /*b*/, float /*weight*/) + { + return 1; + } + float getThreshold(void) { return 50.0f;