diff --git a/library/PolyVoxCore/include/PolyVoxCore/Mesh.h b/library/PolyVoxCore/include/PolyVoxCore/Mesh.h index 0499b9f1..657d7e1a 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Mesh.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Mesh.h @@ -69,37 +69,18 @@ namespace PolyVox void clear(void); bool isEmpty(void) const; - void scaleVertices(float amount); - void translateVertices(const Vector3DFloat& amount); - - //THESE FUNCTIONS TO BE REMOVED IN THE FUTURE. OR AT LEAST MOVED OUT OF THIS CLASS INTO FREE FUNCTIONS. - //THEY ARE CAUSING PROBLEMS WITH THE SWIG BINDINGS. THE FUNCTIONS REGARDING NORMALS MAKE NO SENSE WHEN - //A VERTEX MIGHT NOT HAVE NORMALS. THE EXTRACT SUBSET FUNCTION SHOULD MAYBE BE APPLICATION CODE, AT ANY - //RATE THE STD::SET CAUSES PROBLEMS WITH SWIG. IF YOU UNCOMMENT ANY OF THESE FUNCTIONS, PLEASE POST ON - //THE FORUM SO WE CAN KNOW THE FUNCTIONALITY IS STILL NEEDED IN SOME FORM. - //void sumNearbyNormals(bool bNormaliseResult = true); - //std::shared_ptr< Mesh > extractSubset(std::set setMaterials); - //void generateAveragedFaceNormals(bool bNormalise, bool bIncludeEdgeVertices = false); - int noOfDegenerateTris(void); void removeDegenerateTris(void); void removeUnusedVertices(void); Region m_Region; - - int32_t m_iTimeStamp; - - int32_t m_iNoOfLod0Tris; public: std::vector m_vecTriangleIndices; std::vector m_vecVertices; std::vector m_vecLodRecords; - }; - - template - std::shared_ptr< Mesh > extractSubset(Mesh& inputMesh, std::set setMaterials); + }; template Mesh< Vertex< typename MeshType::VertexType::DataType > > decode(const MeshType& mesh) diff --git a/library/PolyVoxCore/include/PolyVoxCore/Mesh.inl b/library/PolyVoxCore/include/PolyVoxCore/Mesh.inl index 44fc5320..a886defa 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Mesh.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/Mesh.inl @@ -26,7 +26,6 @@ namespace PolyVox template Mesh::Mesh() { - m_iTimeStamp = -1; } template @@ -143,173 +142,7 @@ namespace PolyVox { return (getNoOfVertices() == 0) || (getNoOfIndices() == 0); } - - //////////////////////////////////////////////////////////////////////////////// - /// This function can help improve the visual appearance of a surface patch by - /// smoothing normals with other nearby normals. It iterates over each triangle - /// in the surface patch and determines the sum of its corners normals. For any - /// given vertex, these sums are in turn summed for any triangles which use the - /// vertex. Usually, the resulting normals should be renormalised afterwards. - /// Note: This function can cause lighting discontinuities accross region boundaries. - //////////////////////////////////////////////////////////////////////////////// - /*template - void Mesh::sumNearbyNormals(bool bNormaliseResult) - { - if(m_vecVertices.size() == 0) //FIXME - I don't think we should need this test, but I have seen crashes otherwise... - { - return; - } - - std::vector summedNormals(m_vecVertices.size()); - - //Initialise all normals to zero. Should be ok as the vector should store all elements contiguously. - memset(&summedNormals[0], 0, summedNormals.size() * sizeof(Vector3DFloat)); - - for(vector::iterator iterIndex = m_vecTriangleIndices.begin(); iterIndex != m_vecTriangleIndices.end();) - { - PositionMaterialNormal& v0 = m_vecVertices[*iterIndex]; - Vector3DFloat& v0New = summedNormals[*iterIndex]; - iterIndex++; - PositionMaterialNormal& v1 = m_vecVertices[*iterIndex]; - Vector3DFloat& v1New = summedNormals[*iterIndex]; - iterIndex++; - PositionMaterialNormal& v2 = m_vecVertices[*iterIndex]; - Vector3DFloat& v2New = summedNormals[*iterIndex]; - iterIndex++; - - Vector3DFloat sumOfNormals = v0.getNormal() + v1.getNormal() + v2.getNormal(); - - v0New += sumOfNormals; - v1New += sumOfNormals; - v2New += sumOfNormals; - } - - for(uint32_t uIndex = 0; uIndex < summedNormals.size(); uIndex++) - { - if(bNormaliseResult) - { - summedNormals[uIndex].normalise(); - } - m_vecVertices[uIndex].setNormal(summedNormals[uIndex]); - } - }*/ - - /*template - void Mesh::generateAveragedFaceNormals(bool bNormalise, bool bIncludeEdgeVertices) - { - Vector3DFloat offset = static_cast(m_Region.getLowerCorner()); - - //Initially zero the normals - for(vector::iterator iterVertex = m_vecVertices.begin(); iterVertex != m_vecVertices.end(); iterVertex++) - { - if(m_Region.containsPoint(iterVertex->getPosition() + offset, 0.001)) - { - iterVertex->setNormal(Vector3DFloat(0.0f,0.0f,0.0f)); - } - } - - for(vector::iterator iterIndex = m_vecTriangleIndices.begin(); iterIndex != m_vecTriangleIndices.end();) - { - PositionMaterialNormal& v0 = m_vecVertices[*iterIndex]; - iterIndex++; - PositionMaterialNormal& v1 = m_vecVertices[*iterIndex]; - iterIndex++; - PositionMaterialNormal& v2 = m_vecVertices[*iterIndex]; - iterIndex++; - - Vector3DFloat triangleNormal = (v1.getPosition()-v0.getPosition()).cross(v2.getPosition()-v0.getPosition()); - - if(m_Region.containsPoint(v0.getPosition() + offset, 0.001)) - { - v0.setNormal(v0.getNormal() + triangleNormal); - } - if(m_Region.containsPoint(v1.getPosition() + offset, 0.001)) - { - v1.setNormal(v1.getNormal() + triangleNormal); - } - if(m_Region.containsPoint(v2.getPosition() + offset, 0.001)) - { - v2.setNormal(v2.getNormal() + triangleNormal); - } - } - - if(bNormalise) - { - for(vector::iterator iterVertex = m_vecVertices.begin(); iterVertex != m_vecVertices.end(); iterVertex++) - { - Vector3DFloat normal = iterVertex->getNormal(); - normal.normalise(); - iterVertex->setNormal(normal); - } - } - }*/ - - /*template - std::shared_ptr< Mesh > Mesh::extractSubset(std::set setMaterials) - { - std::shared_ptr< Mesh > result(new Mesh); - - if(m_vecVertices.size() == 0) //FIXME - I don't think we should need this test, but I have seen crashes otherwise... - { - return result; - } - - assert(m_vecLodRecords.size() == 1); - if(m_vecLodRecords.size() != 1) - { - //If we have done progressive LOD then it's too late to split into subsets. - return result; - } - - std::vector indexMap(m_vecVertices.size()); - std::fill(indexMap.begin(), indexMap.end(), -1); - - for(uint32_t triCt = 0; triCt < m_vecTriangleIndices.size(); triCt += 3) - { - - PositionMaterialNormal& v0 = m_vecVertices[m_vecTriangleIndices[triCt]]; - PositionMaterialNormal& v1 = m_vecVertices[m_vecTriangleIndices[triCt + 1]]; - PositionMaterialNormal& v2 = m_vecVertices[m_vecTriangleIndices[triCt + 2]]; - - if( - (setMaterials.find(v0.getMaterial()) != setMaterials.end()) || - (setMaterials.find(v1.getMaterial()) != setMaterials.end()) || - (setMaterials.find(v2.getMaterial()) != setMaterials.end())) - { - uint32_t i0; - if(indexMap[m_vecTriangleIndices[triCt]] == -1) - { - indexMap[m_vecTriangleIndices[triCt]] = result->addVertex(v0); - } - i0 = indexMap[m_vecTriangleIndices[triCt]]; - - uint32_t i1; - if(indexMap[m_vecTriangleIndices[triCt+1]] == -1) - { - indexMap[m_vecTriangleIndices[triCt+1]] = result->addVertex(v1); - } - i1 = indexMap[m_vecTriangleIndices[triCt+1]]; - - uint32_t i2; - if(indexMap[m_vecTriangleIndices[triCt+2]] == -1) - { - indexMap[m_vecTriangleIndices[triCt+2]] = result->addVertex(v2); - } - i2 = indexMap[m_vecTriangleIndices[triCt+2]]; - - result->addTriangle(i0,i1,i2); - } - } - - result->m_vecLodRecords.clear(); - LodRecord lodRecord; - lodRecord.beginIndex = 0; - lodRecord.endIndex = result->getNoOfIndices(); - result->m_vecLodRecords.push_back(lodRecord); - - return result; - }*/ - + template int Mesh::noOfDegenerateTris(void) { @@ -392,97 +225,4 @@ namespace PolyVox m_vecTriangleIndices[triCt] = newPos[m_vecTriangleIndices[triCt]]; } } - - //Currently a free function - think where this needs to go. - template - std::shared_ptr< Mesh > extractSubset(Mesh& inputMesh, std::set setMaterials) - { - std::shared_ptr< Mesh > result(new Mesh); - - result->m_Region = inputMesh.m_Region; - - if(inputMesh.m_vecVertices.size() == 0) //FIXME - I don't think we should need this test, but I have seen crashes otherwise... - { - return result; - } - - POLYVOX_ASSERT(inputMesh.m_vecLodRecords.size() == 1, "Number of LOD records must equal one."); - if(inputMesh.m_vecLodRecords.size() != 1) - { - //If we have done progressive LOD then it's too late to split into subsets. - return result; - } - - std::vector indexMap(inputMesh.m_vecVertices.size()); - std::fill(indexMap.begin(), indexMap.end(), -1); - - for(uint32_t triCt = 0; triCt < inputMesh.m_vecTriangleIndices.size(); triCt += 3) - { - - VertexType& v0 = inputMesh.m_vecVertices[inputMesh.m_vecTriangleIndices[triCt]]; - VertexType& v1 = inputMesh.m_vecVertices[inputMesh.m_vecTriangleIndices[triCt + 1]]; - VertexType& v2 = inputMesh.m_vecVertices[inputMesh.m_vecTriangleIndices[triCt + 2]]; - - if( - (setMaterials.find(v0.getMaterial()) != setMaterials.end()) || - (setMaterials.find(v1.getMaterial()) != setMaterials.end()) || - (setMaterials.find(v2.getMaterial()) != setMaterials.end())) - { - uint32_t i0; - if(indexMap[inputMesh.m_vecTriangleIndices[triCt]] == -1) - { - indexMap[inputMesh.m_vecTriangleIndices[triCt]] = result->addVertex(v0); - } - i0 = indexMap[inputMesh.m_vecTriangleIndices[triCt]]; - - uint32_t i1; - if(indexMap[inputMesh.m_vecTriangleIndices[triCt+1]] == -1) - { - indexMap[inputMesh.m_vecTriangleIndices[triCt+1]] = result->addVertex(v1); - } - i1 = indexMap[inputMesh.m_vecTriangleIndices[triCt+1]]; - - uint32_t i2; - if(indexMap[inputMesh.m_vecTriangleIndices[triCt+2]] == -1) - { - indexMap[inputMesh.m_vecTriangleIndices[triCt+2]] = result->addVertex(v2); - } - i2 = indexMap[inputMesh.m_vecTriangleIndices[triCt+2]]; - - result->addTriangle(i0,i1,i2); - } - } - - result->m_vecLodRecords.clear(); - LodRecord lodRecord; - lodRecord.beginIndex = 0; - lodRecord.endIndex = result->getNoOfIndices(); - result->m_vecLodRecords.push_back(lodRecord); - - return result; - } - - template - void Mesh::scaleVertices(float amount) - { - for(uint32_t ct = 0; ct < m_vecVertices.size(); ct++) - { - //TODO: Should rethink accessors here to provide faster access - Vector3DFloat position = m_vecVertices[ct].getPosition(); - position *= amount; - m_vecVertices[ct].setPosition(position); - } - } - - template - void Mesh::translateVertices(const Vector3DFloat& amount) - { - for(uint32_t ct = 0; ct < m_vecVertices.size(); ct++) - { - //TODO: Should rethink accessors here to provide faster access - Vector3DFloat position = m_vecVertices[ct].getPosition(); - position += amount; - m_vecVertices[ct].setPosition(position); - } - } }