Tidying up.
This commit is contained in:
parent
c9b098b14e
commit
72a4e9902c
@ -35,11 +35,9 @@ namespace PolyVox
|
|||||||
|
|
||||||
bool m_bIsEmpty;
|
bool m_bIsEmpty;
|
||||||
bool m_bContainsSingleMaterialPatch;
|
bool m_bContainsSingleMaterialPatch;
|
||||||
bool m_bContainsMultiMaterialPatch;
|
|
||||||
|
|
||||||
Vector3DInt32 m_v3dRegionPosition;
|
Vector3DInt32 m_v3dRegionPosition;
|
||||||
IndexedSurfacePatch* m_patchSingleMaterial;
|
IndexedSurfacePatch* m_patchSingleMaterial;
|
||||||
IndexedSurfacePatch* m_patchMultiMaterial;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,12 +34,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||||||
namespace PolyVox
|
namespace PolyVox
|
||||||
{
|
{
|
||||||
POLYVOX_API std::list<RegionGeometry> getChangedRegionGeometry(VolumeChangeTracker& volume);
|
POLYVOX_API std::list<RegionGeometry> getChangedRegionGeometry(VolumeChangeTracker& volume);
|
||||||
void genMultiFromSingle(IndexedSurfacePatch* singleMaterialPatch, IndexedSurfacePatch* multiMaterialPatch);
|
|
||||||
|
|
||||||
POLYVOX_API void generateRoughMeshDataForRegion(BlockVolume<boost::uint8_t>* volumeData, Region region, IndexedSurfacePatch* singleMaterialPatch, IndexedSurfacePatch* multiMaterialPatch);
|
POLYVOX_API void generateRoughMeshDataForRegion(BlockVolume<boost::uint8_t>* volumeData, Region region, IndexedSurfacePatch* singleMaterialPatch);
|
||||||
POLYVOX_API Vector3DFloat computeNormal(BlockVolume<boost::uint8_t>* volumeData, const Vector3DFloat& position, NormalGenerationMethod normalGenerationMethod);
|
POLYVOX_API Vector3DFloat computeNormal(BlockVolume<boost::uint8_t>* volumeData, const Vector3DFloat& position, NormalGenerationMethod normalGenerationMethod);
|
||||||
|
|
||||||
POLYVOX_API void generateSmoothMeshDataForRegion(BlockVolume<boost::uint8_t>* volumeData, Region region, IndexedSurfacePatch* singleMaterialPatch, IndexedSurfacePatch* multiMaterialPatch);
|
POLYVOX_API void generateSmoothMeshDataForRegion(BlockVolume<boost::uint8_t>* volumeData, Region region, IndexedSurfacePatch* singleMaterialPatch);
|
||||||
POLYVOX_API Vector3DFloat computeSmoothNormal(BlockVolume<boost::uint8_t>* volumeData, const Vector3DFloat& position, NormalGenerationMethod normalGenerationMethod);
|
POLYVOX_API Vector3DFloat computeSmoothNormal(BlockVolume<boost::uint8_t>* volumeData, const Vector3DFloat& position, NormalGenerationMethod normalGenerationMethod);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,16 +24,14 @@ namespace PolyVox
|
|||||||
//Generate the surface
|
//Generate the surface
|
||||||
RegionGeometry regionGeometry;
|
RegionGeometry regionGeometry;
|
||||||
regionGeometry.m_patchSingleMaterial = new IndexedSurfacePatch(false);
|
regionGeometry.m_patchSingleMaterial = new IndexedSurfacePatch(false);
|
||||||
regionGeometry.m_patchMultiMaterial = new IndexedSurfacePatch(true);
|
|
||||||
regionGeometry.m_v3dRegionPosition = iterChangedRegions->getLowerCorner();
|
regionGeometry.m_v3dRegionPosition = iterChangedRegions->getLowerCorner();
|
||||||
|
|
||||||
generateRoughMeshDataForRegion(volume.getVolumeData(), *iterChangedRegions, regionGeometry.m_patchSingleMaterial, regionGeometry.m_patchMultiMaterial);
|
generateRoughMeshDataForRegion(volume.getVolumeData(), *iterChangedRegions, regionGeometry.m_patchSingleMaterial);
|
||||||
|
|
||||||
//genMultiFromSingle(regionGeometry.m_patchSingleMaterial, regionGeometry.m_patchMultiMaterial);
|
//genMultiFromSingle(regionGeometry.m_patchSingleMaterial, regionGeometry.m_patchMultiMaterial);
|
||||||
|
|
||||||
regionGeometry.m_bContainsSingleMaterialPatch = regionGeometry.m_patchSingleMaterial->getVertices().size() > 0;
|
regionGeometry.m_bContainsSingleMaterialPatch = regionGeometry.m_patchSingleMaterial->getVertices().size() > 0;
|
||||||
regionGeometry.m_bContainsMultiMaterialPatch = regionGeometry.m_patchMultiMaterial->getVertices().size() > 0;
|
regionGeometry.m_bIsEmpty = (regionGeometry.m_patchSingleMaterial->getVertices().size() == 0);
|
||||||
regionGeometry.m_bIsEmpty = ((regionGeometry.m_patchSingleMaterial->getVertices().size() == 0) && (regionGeometry.m_patchMultiMaterial->getIndices().size() == 0));
|
|
||||||
|
|
||||||
listChangedRegionGeometry.push_back(regionGeometry);
|
listChangedRegionGeometry.push_back(regionGeometry);
|
||||||
}
|
}
|
||||||
@ -41,58 +39,7 @@ namespace PolyVox
|
|||||||
return listChangedRegionGeometry;
|
return listChangedRegionGeometry;
|
||||||
}
|
}
|
||||||
|
|
||||||
void genMultiFromSingle(IndexedSurfacePatch* singleMaterialPatch, IndexedSurfacePatch* multiMaterialPatch)
|
void generateRoughMeshDataForRegion(BlockVolume<uint8_t>* volumeData, Region region, IndexedSurfacePatch* singleMaterialPatch)
|
||||||
{
|
|
||||||
std::vector<SurfaceVertex>& vertices = singleMaterialPatch->m_vecVertices;
|
|
||||||
std::vector<boost::uint32_t>& indices = singleMaterialPatch->m_vecTriangleIndices;
|
|
||||||
if(vertices.size() == 0)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
singleMaterialPatch->m_AllowDuplicateVertices = true;
|
|
||||||
for(boost::uint32_t ct = 0; ct < indices.size()-2; ct+=3)
|
|
||||||
{
|
|
||||||
if((vertices[indices[ct]].getMaterial() != vertices[indices[ct+1]].getMaterial()) || (vertices[indices[ct]].getMaterial() != vertices[indices[ct+2]].getMaterial()))
|
|
||||||
{
|
|
||||||
SurfaceVertex vert0 = vertices[indices[ct+0]];
|
|
||||||
SurfaceVertex vert1 = vertices[indices[ct+1]];
|
|
||||||
SurfaceVertex vert2 = vertices[indices[ct+2]];
|
|
||||||
|
|
||||||
float mat0 = vert0.getMaterial();
|
|
||||||
float mat1 = vert1.getMaterial();
|
|
||||||
float mat2 = vert2.getMaterial();
|
|
||||||
|
|
||||||
vert0.setMaterial(0.0f); vert0.setAlpha(1.0);
|
|
||||||
vert1.setMaterial(0.0f); vert1.setAlpha(1.0);
|
|
||||||
vert2.setMaterial(0.0f); vert2.setAlpha(1.0);
|
|
||||||
singleMaterialPatch->addTriangle(vert0, vert1, vert2);
|
|
||||||
|
|
||||||
vert0.setMaterial(mat0); vert0.setAlpha(1.0);
|
|
||||||
vert1.setMaterial(mat0); vert1.setAlpha(0.0);
|
|
||||||
vert2.setMaterial(mat0); vert2.setAlpha(0.0);
|
|
||||||
singleMaterialPatch->addTriangle(vert0, vert1, vert2);
|
|
||||||
|
|
||||||
vert0.setMaterial(mat1); vert0.setAlpha(0.0);
|
|
||||||
vert1.setMaterial(mat1); vert1.setAlpha(1.0);
|
|
||||||
vert2.setMaterial(mat1); vert2.setAlpha(0.0);
|
|
||||||
singleMaterialPatch->addTriangle(vert0, vert1, vert2);
|
|
||||||
|
|
||||||
vert0.setMaterial(mat2); vert0.setAlpha(0.0);
|
|
||||||
vert1.setMaterial(mat2); vert1.setAlpha(0.0);
|
|
||||||
vert2.setMaterial(mat2); vert2.setAlpha(1.0);
|
|
||||||
singleMaterialPatch->addTriangle(vert0, vert1, vert2);
|
|
||||||
|
|
||||||
//Cause the original one to become degenerate...
|
|
||||||
indices[ct+0] = 0;
|
|
||||||
indices[ct+1] = 0;
|
|
||||||
indices[ct+2] = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
singleMaterialPatch->m_AllowDuplicateVertices = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void generateRoughMeshDataForRegion(BlockVolume<uint8_t>* volumeData, Region region, IndexedSurfacePatch* singleMaterialPatch, IndexedSurfacePatch* multiMaterialPatch)
|
|
||||||
{
|
{
|
||||||
//When generating the mesh for a region we actually look one voxel outside it in the
|
//When generating the mesh for a region we actually look one voxel outside it in the
|
||||||
// back, bottom, right direction. Protect against access violations by cropping region here
|
// back, bottom, right direction. Protect against access violations by cropping region here
|
||||||
@ -272,24 +219,7 @@ namespace PolyVox
|
|||||||
const_cast<SurfaceVertex&>(*iterSurfaceVertex).setNormal(tempNormal);
|
const_cast<SurfaceVertex&>(*iterSurfaceVertex).setNormal(tempNormal);
|
||||||
++iterSurfaceVertex;
|
++iterSurfaceVertex;
|
||||||
}
|
}
|
||||||
|
|
||||||
iterSurfaceVertex = multiMaterialPatch->getVertices().begin();
|
|
||||||
while(iterSurfaceVertex != multiMaterialPatch->getVertices().end())
|
|
||||||
{
|
|
||||||
Vector3DFloat tempNormal = computeNormal(volumeData, static_cast<Vector3DFloat>(iterSurfaceVertex->getPosition() + offset), CENTRAL_DIFFERENCE);
|
|
||||||
const_cast<SurfaceVertex&>(*iterSurfaceVertex).setNormal(tempNormal);
|
|
||||||
++iterSurfaceVertex;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t noOfRemovedVertices = 0;
|
|
||||||
//do
|
|
||||||
{
|
|
||||||
//noOfRemovedVertices = iterPatch->second.decimate();
|
|
||||||
}
|
|
||||||
//while(noOfRemovedVertices > 10); //We don't worry about the last few vertices - it's not worth the overhead of calling the function.
|
|
||||||
}
|
|
||||||
|
|
||||||
//return singleMaterialPatch;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3DFloat computeNormal(BlockVolume<uint8_t>* volumeData, const Vector3DFloat& position, NormalGenerationMethod normalGenerationMethod)
|
Vector3DFloat computeNormal(BlockVolume<uint8_t>* volumeData, const Vector3DFloat& position, NormalGenerationMethod normalGenerationMethod)
|
||||||
@ -386,7 +316,7 @@ namespace PolyVox
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void generateSmoothMeshDataForRegion(BlockVolume<uint8_t>* volumeData, Region region, IndexedSurfacePatch* singleMaterialPatch, IndexedSurfacePatch* multiMaterialPatch)
|
void generateSmoothMeshDataForRegion(BlockVolume<uint8_t>* volumeData, Region region, IndexedSurfacePatch* singleMaterialPatch)
|
||||||
{
|
{
|
||||||
//When generating the mesh for a region we actually look one voxel outside it in the
|
//When generating the mesh for a region we actually look one voxel outside it in the
|
||||||
// back, bottom, right direction. Protect against access violations by cropping region here
|
// back, bottom, right direction. Protect against access violations by cropping region here
|
||||||
@ -586,85 +516,11 @@ namespace PolyVox
|
|||||||
const uint8_t material1 = vertMaterials[triTable[iCubeIndex][i+1]];
|
const uint8_t material1 = vertMaterials[triTable[iCubeIndex][i+1]];
|
||||||
const uint8_t material2 = vertMaterials[triTable[iCubeIndex][i+2]];
|
const uint8_t material2 = vertMaterials[triTable[iCubeIndex][i+2]];
|
||||||
|
|
||||||
//If all the materials are the same, we just need one triangle for that material with all the alphas set high.
|
|
||||||
/*if((material0 == material1) && (material1 == material2))
|
|
||||||
{*/
|
|
||||||
SurfaceVertex surfaceVertex0Alpha1(vertex0,material0 + 0.1f,1.0f);
|
SurfaceVertex surfaceVertex0Alpha1(vertex0,material0 + 0.1f,1.0f);
|
||||||
SurfaceVertex surfaceVertex1Alpha1(vertex1,material1 + 0.1f,1.0f);
|
SurfaceVertex surfaceVertex1Alpha1(vertex1,material1 + 0.1f,1.0f);
|
||||||
SurfaceVertex surfaceVertex2Alpha1(vertex2,material2 + 0.1f,1.0f);
|
SurfaceVertex surfaceVertex2Alpha1(vertex2,material2 + 0.1f,1.0f);
|
||||||
singleMaterialPatch->addTriangle(surfaceVertex0Alpha1, surfaceVertex1Alpha1, surfaceVertex2Alpha1);
|
singleMaterialPatch->addTriangle(surfaceVertex0Alpha1, surfaceVertex1Alpha1, surfaceVertex2Alpha1);
|
||||||
/*}
|
|
||||||
else if(material0 == material1)
|
|
||||||
{
|
|
||||||
{
|
|
||||||
SurfaceVertex surfaceVertex0Alpha1(vertex0,material0 + 0.1,1.0);
|
|
||||||
SurfaceVertex surfaceVertex1Alpha1(vertex1,material0 + 0.1,1.0);
|
|
||||||
SurfaceVertex surfaceVertex2Alpha1(vertex2,material0 + 0.1,0.0);
|
|
||||||
multiMaterialPatch->addTriangle(surfaceVertex0Alpha1, surfaceVertex1Alpha1, surfaceVertex2Alpha1);
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
SurfaceVertex surfaceVertex0Alpha1(vertex0,material2 + 0.1,0.0);
|
|
||||||
SurfaceVertex surfaceVertex1Alpha1(vertex1,material2 + 0.1,0.0);
|
|
||||||
SurfaceVertex surfaceVertex2Alpha1(vertex2,material2 + 0.1,1.0);
|
|
||||||
multiMaterialPatch->addTriangle(surfaceVertex0Alpha1, surfaceVertex1Alpha1, surfaceVertex2Alpha1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if(material0 == material2)
|
|
||||||
{
|
|
||||||
{
|
|
||||||
SurfaceVertex surfaceVertex0Alpha1(vertex0,material0 + 0.1,1.0);
|
|
||||||
SurfaceVertex surfaceVertex1Alpha1(vertex1,material0 + 0.1,0.0);
|
|
||||||
SurfaceVertex surfaceVertex2Alpha1(vertex2,material0 + 0.1,1.0);
|
|
||||||
multiMaterialPatch->addTriangle(surfaceVertex0Alpha1, surfaceVertex1Alpha1, surfaceVertex2Alpha1);
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
SurfaceVertex surfaceVertex0Alpha1(vertex0,material1 + 0.1,0.0);
|
|
||||||
SurfaceVertex surfaceVertex1Alpha1(vertex1,material1 + 0.1,1.0);
|
|
||||||
SurfaceVertex surfaceVertex2Alpha1(vertex2,material1 + 0.1,0.0);
|
|
||||||
multiMaterialPatch->addTriangle(surfaceVertex0Alpha1, surfaceVertex1Alpha1, surfaceVertex2Alpha1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if(material1 == material2)
|
|
||||||
{
|
|
||||||
{
|
|
||||||
SurfaceVertex surfaceVertex0Alpha1(vertex0,material1 + 0.1,0.0);
|
|
||||||
SurfaceVertex surfaceVertex1Alpha1(vertex1,material1 + 0.1,1.0);
|
|
||||||
SurfaceVertex surfaceVertex2Alpha1(vertex2,material1 + 0.1,1.0);
|
|
||||||
multiMaterialPatch->addTriangle(surfaceVertex0Alpha1, surfaceVertex1Alpha1, surfaceVertex2Alpha1);
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
SurfaceVertex surfaceVertex0Alpha1(vertex0,material0 + 0.1,1.0);
|
|
||||||
SurfaceVertex surfaceVertex1Alpha1(vertex1,material0 + 0.1,0.0);
|
|
||||||
SurfaceVertex surfaceVertex2Alpha1(vertex2,material0 + 0.1,0.0);
|
|
||||||
multiMaterialPatch->addTriangle(surfaceVertex0Alpha1, surfaceVertex1Alpha1, surfaceVertex2Alpha1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
{
|
|
||||||
SurfaceVertex surfaceVertex0Alpha1(vertex0,material0 + 0.1,1.0);
|
|
||||||
SurfaceVertex surfaceVertex1Alpha1(vertex1,material0 + 0.1,0.0);
|
|
||||||
SurfaceVertex surfaceVertex2Alpha1(vertex2,material0 + 0.1,0.0);
|
|
||||||
multiMaterialPatch->addTriangle(surfaceVertex0Alpha1, surfaceVertex1Alpha1, surfaceVertex2Alpha1);
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
SurfaceVertex surfaceVertex0Alpha1(vertex0,material1 + 0.1,0.0);
|
|
||||||
SurfaceVertex surfaceVertex1Alpha1(vertex1,material1 + 0.1,1.0);
|
|
||||||
SurfaceVertex surfaceVertex2Alpha1(vertex2,material1 + 0.1,0.0);
|
|
||||||
multiMaterialPatch->addTriangle(surfaceVertex0Alpha1, surfaceVertex1Alpha1, surfaceVertex2Alpha1);
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
SurfaceVertex surfaceVertex0Alpha1(vertex0,material2 + 0.1,0.0);
|
|
||||||
SurfaceVertex surfaceVertex1Alpha1(vertex1,material2 + 0.1,0.0);
|
|
||||||
SurfaceVertex surfaceVertex2Alpha1(vertex2,material2 + 0.1,1.0);
|
|
||||||
multiMaterialPatch->addTriangle(surfaceVertex0Alpha1, surfaceVertex1Alpha1, surfaceVertex2Alpha1);
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
}//For each triangle
|
}//For each triangle
|
||||||
}//For each cell
|
}//For each cell
|
||||||
|
|
||||||
@ -681,14 +537,6 @@ namespace PolyVox
|
|||||||
const_cast<SurfaceVertex&>(*iterSurfaceVertex).setNormal(tempNormal);
|
const_cast<SurfaceVertex&>(*iterSurfaceVertex).setNormal(tempNormal);
|
||||||
++iterSurfaceVertex;
|
++iterSurfaceVertex;
|
||||||
}
|
}
|
||||||
|
|
||||||
iterSurfaceVertex = multiMaterialPatch->getVertices().begin();
|
|
||||||
while(iterSurfaceVertex != multiMaterialPatch->getVertices().end())
|
|
||||||
{
|
|
||||||
Vector3DFloat tempNormal = computeSmoothNormal(volumeData, static_cast<Vector3DFloat>(iterSurfaceVertex->getPosition() + offset), CENTRAL_DIFFERENCE);
|
|
||||||
const_cast<SurfaceVertex&>(*iterSurfaceVertex).setNormal(tempNormal);
|
|
||||||
++iterSurfaceVertex;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user