Refactoring smoothing and normal generation code.

This commit is contained in:
David Williams 2009-05-27 22:09:38 +00:00
parent 5682b204a6
commit b1e111d940
8 changed files with 45 additions and 17 deletions

View File

@ -17,7 +17,7 @@ void renderRegionImmediateMode(PolyVox::IndexedSurfacePatch& isp)
const SurfaceVertex& vertex = vecVertices[*iterIndex];
const Vector3DFloat& v3dVertexPos = vertex.getPosition();
//const Vector3DFloat v3dRegionOffset(uRegionX * g_uRegionSideLength, uRegionY * g_uRegionSideLength, uRegionZ * g_uRegionSideLength);
const Vector3DFloat v3dFinalVertexPos = v3dVertexPos + static_cast<Vector3DFloat>(isp.m_v3dRegionPosition);
const Vector3DFloat v3dFinalVertexPos = v3dVertexPos + static_cast<Vector3DFloat>(isp.m_Region.getLowerCorner());

View File

@ -41,7 +41,7 @@ OpenGLSurfacePatch BuildOpenGLSurfacePatch(const IndexedSurfacePatch& isp)
const SurfaceVertex& vertex = *iterVertex;
const Vector3DFloat& v3dVertexPos = vertex.getPosition();
//const Vector3DFloat v3dRegionOffset(uRegionX * g_uRegionSideLength, uRegionY * g_uRegionSideLength, uRegionZ * g_uRegionSideLength);
const Vector3DFloat v3dFinalVertexPos = v3dVertexPos + static_cast<Vector3DFloat>(isp.m_v3dRegionPosition);
const Vector3DFloat v3dFinalVertexPos = v3dVertexPos + static_cast<Vector3DFloat>(isp.m_Region.getLowerCorner());
*ptr = v3dFinalVertexPos.getX();
ptr++;

View File

@ -70,10 +70,10 @@ void OpenGLWidget::setVolume(PolyVox::Volume<PolyVox::uint8_t>* volData)
//extractSurface(m_volData, 0, PolyVox::Region(regLowerCorner, regUpperCorner), ispCurrent);
surfaceExtractor.extractSurfaceForRegion(PolyVox::Region(regLowerCorner, regUpperCorner), ispCurrent);
//computeNormalsForVertices(m_volData, *ispCurrent, SOBEL_SMOOTHED);
computeNormalsForVertices(m_volData, *ispCurrent, SOBEL_SMOOTHED);
//*ispCurrent = getSmoothedSurface(*ispCurrent);
ispCurrent->smooth(0.2f);
ispCurrent->generateAveragedFaceNormals(true);
ispCurrent->smooth(0.3f);
//ispCurrent->generateAveragedFaceNormals(true);
Vector3DUint8 v3dRegPos(uRegionX,uRegionY,uRegionZ);

View File

@ -27,6 +27,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "PolyVoxImpl/CPlusPlusZeroXSupport.h"
#include "PolyVoxForwardDeclarations.h"
#include "Region.h"
#include "SurfaceVertex.h"
#include "PolyVoxImpl/TypeDef.h"
@ -55,7 +56,9 @@ namespace PolyVox
void generateAveragedFaceNormals(bool bNormalise, bool bIncludeEdgeVertices = false);
Vector3DInt32 m_v3dRegionPosition; //FIXME - remove this?
//Vector3DInt32 m_v3dRegionPosition; //FIXME - remove this?
Region m_Region;
int32_t m_iTimeStamp;

View File

@ -13,7 +13,7 @@ namespace PolyVox
std::vector<SurfaceVertex>::iterator iterSurfaceVertex = vecVertices.begin();
while(iterSurfaceVertex != vecVertices.end())
{
const Vector3DFloat& v3dPos = iterSurfaceVertex->getPosition() + static_cast<Vector3DFloat>(isp.m_v3dRegionPosition);
const Vector3DFloat& v3dPos = iterSurfaceVertex->getPosition() + static_cast<Vector3DFloat>(isp.m_Region.getLowerCorner());
const Vector3DInt32 v3dFloor = static_cast<Vector3DInt32>(v3dPos);
VolumeSampler<uint8_t> volIter(*volumeData);

View File

@ -118,6 +118,8 @@ namespace PolyVox
{
std::vector<SurfaceVertex> vecOriginalVertices = m_vecVertices;
Vector3DFloat offset = static_cast<Vector3DFloat>(m_Region.getLowerCorner());
for(vector<uint32_t>::iterator iterIndex = m_vecTriangleIndices.begin(); iterIndex != m_vecTriangleIndices.end();)
{
SurfaceVertex& v0 = vecOriginalVertices[*iterIndex];
@ -147,19 +149,33 @@ namespace PolyVox
Vector3DFloat n1 = v1.getNormal();
n1.normalise();
Vector3DFloat n2 = v2.getNormal();
n2.normalise();
n2.normalise();
v0New.position += (n0 * (n0.dot(v0ToOpp)) * fAmount);
v1New.position += (n1 * (n1.dot(v1ToOpp)) * fAmount);
v2New.position += (n2 * (n2.dot(v2ToOpp)) * fAmount);
if(m_Region.containsPoint(v0.getPosition() + offset, 0.001))
{
v0New.position += (n0 * (n0.dot(v0ToOpp)) * fAmount);
}
if(m_Region.containsPoint(v1.getPosition() + offset, 0.001))
{
v1New.position += (n1 * (n1.dot(v1ToOpp)) * fAmount);
}
if(m_Region.containsPoint(v2.getPosition() + offset, 0.001))
{
v2New.position += (n2 * (n2.dot(v2ToOpp)) * fAmount);
}
}
}
void IndexedSurfacePatch::generateAveragedFaceNormals(bool bNormalise, bool bIncludeEdgeVertices)
{
Vector3DFloat offset = static_cast<Vector3DFloat>(m_Region.getLowerCorner());
for(vector<SurfaceVertex>::iterator iterVertex = m_vecVertices.begin(); iterVertex != m_vecVertices.end(); iterVertex++)
{
iterVertex->setNormal(Vector3DFloat(0.0f,0.0f,0.0f));
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();)
@ -173,9 +189,18 @@ namespace PolyVox
Vector3DFloat triangleNormal = (v1.getPosition()-v0.getPosition()).cross(v2.getPosition()-v0.getPosition());
v0.setNormal(v0.getNormal() + triangleNormal);
v1.setNormal(v1.getNormal() + triangleNormal);
v2.setNormal(v2.getNormal() + triangleNormal);
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)

View File

@ -33,7 +33,7 @@ namespace PolyVox
{
extractDecimatedSurfaceImpl(&m_volData, m_uLodLevel, region, singleMaterialPatch);
}
singleMaterialPatch->m_v3dRegionPosition = region.getLowerCorner();
singleMaterialPatch->m_Region = region;
}
uint32_t SurfaceExtractor::getIndex(uint32_t x, uint32_t y, uint32_t regionWidth)

View File

@ -27,6 +27,6 @@ namespace PolyVox
extractDecimatedSurfaceImpl(volumeData, uLevel, region, singleMaterialPatch);
}
singleMaterialPatch->m_v3dRegionPosition = region.getLowerCorner();
singleMaterialPatch->m_Region = region;
}
}