Purged old/dead code from Mesh class.
This commit is contained in:
parent
82f9d6ad6f
commit
0bff22fbf5
@ -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<VertexType> > extractSubset(std::set<uint8_t> 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<uint32_t> m_vecTriangleIndices;
|
||||
std::vector<VertexType> m_vecVertices;
|
||||
|
||||
std::vector<LodRecord> m_vecLodRecords;
|
||||
};
|
||||
|
||||
template <typename VertexType>
|
||||
std::shared_ptr< Mesh<VertexType> > extractSubset(Mesh<VertexType>& inputMesh, std::set<uint8_t> setMaterials);
|
||||
};
|
||||
|
||||
template <typename MeshType>
|
||||
Mesh< Vertex< typename MeshType::VertexType::DataType > > decode(const MeshType& mesh)
|
||||
|
@ -26,7 +26,6 @@ namespace PolyVox
|
||||
template <typename VertexType>
|
||||
Mesh<VertexType>::Mesh()
|
||||
{
|
||||
m_iTimeStamp = -1;
|
||||
}
|
||||
|
||||
template <typename VertexType>
|
||||
@ -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 <typename VertexType>
|
||||
void Mesh<VertexType>::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<Vector3DFloat> 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<uint32_t>::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 <typename VertexType>
|
||||
void Mesh<VertexType>::generateAveragedFaceNormals(bool bNormalise, bool bIncludeEdgeVertices)
|
||||
{
|
||||
Vector3DFloat offset = static_cast<Vector3DFloat>(m_Region.getLowerCorner());
|
||||
|
||||
//Initially zero the normals
|
||||
for(vector<PositionMaterialNormal>::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<uint32_t>::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<PositionMaterialNormal>::iterator iterVertex = m_vecVertices.begin(); iterVertex != m_vecVertices.end(); iterVertex++)
|
||||
{
|
||||
Vector3DFloat normal = iterVertex->getNormal();
|
||||
normal.normalise();
|
||||
iterVertex->setNormal(normal);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
/*template <typename VertexType>
|
||||
std::shared_ptr< Mesh<VertexType> > Mesh<VertexType>::extractSubset(std::set<uint8_t> setMaterials)
|
||||
{
|
||||
std::shared_ptr< Mesh<VertexType> > result(new Mesh<VertexType>);
|
||||
|
||||
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<int32_t> 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 <typename VertexType>
|
||||
int Mesh<VertexType>::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 <typename VertexType>
|
||||
std::shared_ptr< Mesh<VertexType> > extractSubset(Mesh<VertexType>& inputMesh, std::set<uint8_t> setMaterials)
|
||||
{
|
||||
std::shared_ptr< Mesh<VertexType> > result(new Mesh<VertexType>);
|
||||
|
||||
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<int32_t> 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 <typename VertexType>
|
||||
void Mesh<VertexType>::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 <typename VertexType>
|
||||
void Mesh<VertexType>::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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user