Changes to make SWIG bindings easier. Also removed SurfaceMesh::smoothPositions().
This commit is contained in:
parent
36f8dc0296
commit
21d24ef7d4
@ -63,7 +63,6 @@ namespace PolyVox
|
|||||||
void clear(void);
|
void clear(void);
|
||||||
const bool isEmpty(void) const;
|
const bool isEmpty(void) const;
|
||||||
|
|
||||||
void smoothPositions(float fAmount, bool bIncludeGeometryEdgeVertices = false);
|
|
||||||
void sumNearbyNormals(bool bNormaliseResult = true);
|
void sumNearbyNormals(bool bNormaliseResult = true);
|
||||||
|
|
||||||
polyvox_shared_ptr< SurfaceMesh<VertexType> > extractSubset(std::set<uint8_t> setMaterials);
|
polyvox_shared_ptr< SurfaceMesh<VertexType> > extractSubset(std::set<uint8_t> setMaterials);
|
||||||
|
@ -146,86 +146,6 @@ namespace PolyVox
|
|||||||
return (getNoOfVertices() == 0) || (getNoOfIndices() == 0);
|
return (getNoOfVertices() == 0) || (getNoOfIndices() == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
/// The function works on a per triangle basis without any need for connectivity
|
|
||||||
/// information. It determines whether a triangle is lying on a flat or curved
|
|
||||||
/// section of the surface patch by examining the normals - therefore these
|
|
||||||
/// normals must hve been set to something sensible before this functions is called.
|
|
||||||
/// \param fAmount A factor controlling how much the vertices move by. Find a good
|
|
||||||
/// value by experimentation, starting with something small such as 0.1f.
|
|
||||||
/// \param bIncludeGeometryEdgeVertices Indicates whether vertices on the edge of an
|
|
||||||
/// SurfaceMesh should be smoothed. This can cause dicontinuities between
|
|
||||||
/// neighbouring patches.
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
template <typename VertexType>
|
|
||||||
void SurfaceMesh<VertexType>::smoothPositions(float fAmount, bool bIncludeGeometryEdgeVertices)
|
|
||||||
{
|
|
||||||
if(m_vecVertices.size() == 0) //FIXME - I don't think we should need this test, but I have seen crashes otherwise...
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//This will hold the new positions, and is initialised with the current positions.
|
|
||||||
std::vector<Vector3DFloat> newPositions(m_vecVertices.size());
|
|
||||||
for(uint32_t uIndex = 0; uIndex < newPositions.size(); uIndex++)
|
|
||||||
{
|
|
||||||
newPositions[uIndex] = m_vecVertices[uIndex].getPosition();
|
|
||||||
}
|
|
||||||
|
|
||||||
//Iterate over each triangle
|
|
||||||
for(vector<uint32_t>::iterator iterIndex = m_vecTriangleIndices.begin(); iterIndex != m_vecTriangleIndices.end();)
|
|
||||||
{
|
|
||||||
//Get the vertex data for the triangle
|
|
||||||
PositionMaterialNormal& v0 = m_vecVertices[*iterIndex];
|
|
||||||
Vector3DFloat& v0New = newPositions[*iterIndex];
|
|
||||||
iterIndex++;
|
|
||||||
PositionMaterialNormal& v1 = m_vecVertices[*iterIndex];
|
|
||||||
Vector3DFloat& v1New = newPositions[*iterIndex];
|
|
||||||
iterIndex++;
|
|
||||||
PositionMaterialNormal& v2 = m_vecVertices[*iterIndex];
|
|
||||||
Vector3DFloat& v2New = newPositions[*iterIndex];
|
|
||||||
iterIndex++;
|
|
||||||
|
|
||||||
//Find the midpoint
|
|
||||||
Vector3DFloat v3dMidpoint = (v0.position + v1.position + v2.position) / 3.0f;
|
|
||||||
|
|
||||||
//Vectors from vertex to midpoint
|
|
||||||
Vector3DFloat v0ToMidpoint = v3dMidpoint - v0.position;
|
|
||||||
Vector3DFloat v1ToMidpoint = v3dMidpoint - v1.position;
|
|
||||||
Vector3DFloat v2ToMidpoint = v3dMidpoint - v2.position;
|
|
||||||
|
|
||||||
//Get the vertex normals
|
|
||||||
Vector3DFloat n0 = v0.getNormal();
|
|
||||||
Vector3DFloat n1 = v1.getNormal();
|
|
||||||
Vector3DFloat n2 = v2.getNormal();
|
|
||||||
|
|
||||||
//I don't think these normalisation are necessary... and could be slow.
|
|
||||||
//Normals should be normalised anyway, and as long as all triangles are
|
|
||||||
//about the same size the distances to midpoint should be similar too.
|
|
||||||
//v0ToMidpoint.normalise();
|
|
||||||
//v1ToMidpoint.normalise();
|
|
||||||
//v2ToMidpoint.normalise();
|
|
||||||
//n0.normalise();
|
|
||||||
//n1.normalise();
|
|
||||||
//n2.normalise();
|
|
||||||
|
|
||||||
//If the dot product is zero the the normals are perpendicular
|
|
||||||
//to the triangle, hence the positions do not move.
|
|
||||||
v0New += (n0 * (n0.dot(v0ToMidpoint)) * fAmount);
|
|
||||||
v1New += (n1 * (n1.dot(v1ToMidpoint)) * fAmount);
|
|
||||||
v2New += (n2 * (n2.dot(v2ToMidpoint)) * fAmount);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Update with the new positions
|
|
||||||
for(uint32_t uIndex = 0; uIndex < newPositions.size(); uIndex++)
|
|
||||||
{
|
|
||||||
if((bIncludeGeometryEdgeVertices) || (m_vecVertices[uIndex].isOnGeometryEdge() == false))
|
|
||||||
{
|
|
||||||
m_vecVertices[uIndex].setPosition(newPositions[uIndex]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// This function can help improve the visual appearance of a surface patch by
|
/// This function can help improve the visual appearance of a surface patch by
|
||||||
/// smoothing normals with other nearby normals. It iterates over each triangle
|
/// smoothing normals with other nearby normals. It iterates over each triangle
|
||||||
|
@ -32,7 +32,11 @@ freely, subject to the following restrictions:
|
|||||||
|
|
||||||
namespace PolyVox
|
namespace PolyVox
|
||||||
{
|
{
|
||||||
|
#ifdef SWIG
|
||||||
|
class PositionMaterial
|
||||||
|
#else
|
||||||
class POLYVOXCORE_API PositionMaterial
|
class POLYVOXCORE_API PositionMaterial
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PositionMaterial();
|
PositionMaterial();
|
||||||
@ -49,7 +53,11 @@ namespace PolyVox
|
|||||||
float material;
|
float material;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#ifdef SWIG
|
||||||
|
class PositionMaterialNormal
|
||||||
|
#else
|
||||||
class POLYVOXCORE_API PositionMaterialNormal
|
class POLYVOXCORE_API PositionMaterialNormal
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PositionMaterialNormal();
|
PositionMaterialNormal();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user