Cleaning up decimation, moving to sets.
This commit is contained in:
parent
cd26634131
commit
15692f7a3f
@ -36,28 +36,34 @@ namespace Ogre
|
||||
|
||||
class SurfaceVertex
|
||||
{
|
||||
public:
|
||||
|
||||
Vector3 normal;
|
||||
float alpha;
|
||||
|
||||
|
||||
public:
|
||||
SurfaceEdgeIterator edge;
|
||||
|
||||
SurfaceVertex();
|
||||
SurfaceVertex(UIntVector3 positionToSet);
|
||||
SurfaceVertex(UIntVector3 positionToSet, Vector3 normalToSet);
|
||||
|
||||
friend bool operator==(const SurfaceVertex& lhs, const SurfaceVertex& rhs);
|
||||
friend bool operator < (const SurfaceVertex& lhs, const SurfaceVertex& rhs);
|
||||
|
||||
const UIntVector3& getPosition(void) const;
|
||||
|
||||
const Vector3& getNormal(void) const;
|
||||
void setNormal(const Vector3& normalToSet);
|
||||
|
||||
std::string toString(void);
|
||||
float alpha;
|
||||
|
||||
private:
|
||||
UIntVector3 position;
|
||||
Vector3 normal;
|
||||
|
||||
|
||||
unsigned long m_uHash;
|
||||
};
|
||||
|
||||
bool operator==(const SurfaceVertex& lhs, const SurfaceVertex& rhs);
|
||||
bool operator < (const SurfaceVertex& lhs, const SurfaceVertex& rhs);
|
||||
|
||||
|
||||
|
||||
|
||||
//bool operator < (const SurfaceVertexIterator& lhs, const SurfaceVertexIterator& rhs);
|
||||
|
@ -324,10 +324,10 @@ namespace Ogre
|
||||
for(uint regionZ = 0; regionZ < OGRE_VOLUME_SIDE_LENGTH_IN_REGIONS; ++regionZ)
|
||||
{
|
||||
LogManager::getSingleton().logMessage("regionZ = " + StringConverter::toString(regionZ));
|
||||
for(uint regionY = OGRE_VOLUME_SIDE_LENGTH_IN_REGIONS/2-2; regionY < OGRE_VOLUME_SIDE_LENGTH_IN_REGIONS/2+1; ++regionY)
|
||||
for(uint regionY = OGRE_VOLUME_SIDE_LENGTH_IN_REGIONS/2-1; regionY < OGRE_VOLUME_SIDE_LENGTH_IN_REGIONS/2+1; ++regionY)
|
||||
{
|
||||
//LogManager::getSingleton().logMessage("regionY = " + StringConverter::toString(regionY));
|
||||
for(uint regionX = OGRE_VOLUME_SIDE_LENGTH_IN_REGIONS/2-2; regionX < OGRE_VOLUME_SIDE_LENGTH_IN_REGIONS/2+1; ++regionX)
|
||||
for(uint regionX = OGRE_VOLUME_SIDE_LENGTH_IN_REGIONS/2-1; regionX < OGRE_VOLUME_SIDE_LENGTH_IN_REGIONS/2+1; ++regionX)
|
||||
{
|
||||
//LogManager::getSingleton().logMessage("regionX = " + StringConverter::toString(regionX));
|
||||
if(surfaceUpToDate[regionX][regionY][regionZ] == false)
|
||||
@ -774,7 +774,7 @@ namespace Ogre
|
||||
else
|
||||
surfaceVertex0.alpha = 0.0;
|
||||
//surfaceVertex0.normal = Vector3(1.0,1.0,1.0);
|
||||
surfaceVertex0.normal = Vector3(0.0,0.0,0.0);
|
||||
surfaceVertex0.setNormal(Vector3(0.0,0.0,0.0));
|
||||
|
||||
SurfaceVertex surfaceVertex1(vertex1);
|
||||
if(material1 == material)
|
||||
@ -782,7 +782,7 @@ namespace Ogre
|
||||
else
|
||||
surfaceVertex1.alpha = 0.0;
|
||||
//surfaceVertex1.normal = Vector3(1.0,1.0,1.0);
|
||||
surfaceVertex1.normal = Vector3(0.0,0.0,0.0);
|
||||
surfaceVertex1.setNormal(Vector3(0.0,0.0,0.0));
|
||||
|
||||
SurfaceVertex surfaceVertex2(vertex2);
|
||||
if(material2 == material)
|
||||
@ -790,7 +790,7 @@ namespace Ogre
|
||||
else
|
||||
surfaceVertex2.alpha = 0.0;
|
||||
//surfaceVertex2.normal = Vector3(1.0,1.0,1.0);
|
||||
surfaceVertex2.normal = Vector3(0.0,0.0,0.0);
|
||||
surfaceVertex2.setNormal(Vector3(0.0,0.0,0.0));
|
||||
|
||||
result[material].addTriangle(surfaceVertex0, surfaceVertex1, surfaceVertex2);
|
||||
|
||||
|
@ -194,19 +194,18 @@ namespace Ogre
|
||||
if((posX - floorX) > 0.25) //The result should be 0.0 or 0.5
|
||||
{
|
||||
uchar uCeil = volIter.peekVoxel1px0py0pz() > 0 ? 1 : 0;
|
||||
vertexIter->normal = Vector3(uFloor - uCeil,0.0,0.0);
|
||||
vertexIter->setNormal(Vector3(uFloor - uCeil,0.0,0.0));
|
||||
}
|
||||
else if((posY - floorY) > 0.25) //The result should be 0.0 or 0.5
|
||||
{
|
||||
uchar uCeil = volIter.peekVoxel0px1py0pz() > 0 ? 1 : 0;
|
||||
vertexIter->normal = Vector3(0.0,uFloor - uCeil,0.0);
|
||||
vertexIter->setNormal(Vector3(0.0,uFloor - uCeil,0.0));
|
||||
}
|
||||
else if((posZ - floorZ) > 0.25) //The result should be 0.0 or 0.5
|
||||
{
|
||||
uchar uCeil = volIter.peekVoxel0px0py1pz() > 0 ? 1 : 0;
|
||||
vertexIter->normal = Vector3(0.0, 0.0,uFloor - uCeil);
|
||||
vertexIter->setNormal(Vector3(0.0, 0.0,uFloor - uCeil));
|
||||
}
|
||||
vertexIter->normal.normalise();
|
||||
break;
|
||||
}
|
||||
case CENTRAL_DIFFERENCE:
|
||||
@ -226,9 +225,7 @@ namespace Ogre
|
||||
volIter.setPosition(static_cast<uint>(posX),static_cast<uint>(posY),static_cast<uint>(posZ+1.0));
|
||||
}
|
||||
const Vector3 gradCeil = volIter.getCentralDifferenceGradient();
|
||||
vertexIter->normal = gradFloor + gradCeil;
|
||||
vertexIter->normal *= -1;
|
||||
vertexIter->normal.normalise();
|
||||
vertexIter->setNormal((gradFloor + gradCeil) * -1.0);
|
||||
break;
|
||||
}
|
||||
case SOBEL:
|
||||
@ -248,9 +245,7 @@ namespace Ogre
|
||||
volIter.setPosition(static_cast<uint>(posX),static_cast<uint>(posY),static_cast<uint>(posZ+1.0));
|
||||
}
|
||||
const Vector3 gradCeil = volIter.getSobelGradient();
|
||||
vertexIter->normal = gradFloor + gradCeil;
|
||||
vertexIter->normal *= -1;
|
||||
vertexIter->normal.normalise();
|
||||
vertexIter->setNormal((gradFloor + gradCeil) * -1.0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -322,7 +317,7 @@ namespace Ogre
|
||||
allZMatch = false;
|
||||
}
|
||||
//FIXME - already normalised?
|
||||
if((*connectedIter)->normal.normalisedCopy().dotProduct(vertexIter->normal.normalisedCopy()) < 0.99)
|
||||
if((*connectedIter)->getNormal().dotProduct(vertexIter->getNormal()) < 0.99)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -433,7 +428,7 @@ namespace Ogre
|
||||
continue;
|
||||
}
|
||||
|
||||
if(isPolygonConvex(listConnectedVertices, vertexIter->normal) == false)
|
||||
if(isPolygonConvex(listConnectedVertices, vertexIter->getNormal()) == false)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@ -499,7 +494,6 @@ namespace Ogre
|
||||
|
||||
bool SurfacePatch::isPolygonConvex(std::list<SurfaceVertexIterator> listVertices, Vector3 normal)
|
||||
{
|
||||
normal.normalise(); //FIXME - don't need this?
|
||||
std::list<SurfaceVertexIterator>::iterator v0IterIter = listVertices.begin();
|
||||
std::list<SurfaceVertexIterator>::iterator v1IterIter = listVertices.begin();
|
||||
std::list<SurfaceVertexIterator>::iterator v2IterIter = listVertices.begin();
|
||||
|
@ -83,9 +83,9 @@ namespace Ogre
|
||||
*prPos++ = verticesToSet[i].getPosition().y/2.0f;
|
||||
*prPos++ = verticesToSet[i].getPosition().z/2.0f;
|
||||
|
||||
*prPos++ = verticesToSet[i].normal.x;
|
||||
*prPos++ = verticesToSet[i].normal.y;
|
||||
*prPos++ = verticesToSet[i].normal.z;
|
||||
*prPos++ = verticesToSet[i].getNormal().x;
|
||||
*prPos++ = verticesToSet[i].getNormal().y;
|
||||
*prPos++ = verticesToSet[i].getNormal().z;
|
||||
|
||||
*prPos++ = verticesToSet[i].alpha;
|
||||
|
||||
|
@ -14,40 +14,14 @@ namespace Ogre
|
||||
SurfaceVertex::SurfaceVertex(UIntVector3 positionToSet)
|
||||
:position(positionToSet)
|
||||
{
|
||||
/*noOfUses = 0;
|
||||
flags = 0;
|
||||
if(position.x == 0)
|
||||
flags |= 1;
|
||||
if(position.x == 8)
|
||||
flags |= 2;
|
||||
if(position.y == 0)
|
||||
flags |= 4;
|
||||
if(position.y == 8)
|
||||
flags |= 8;
|
||||
if(position.z == 0)
|
||||
flags |= 16;
|
||||
if(position.z == 8)
|
||||
flags |= 32;*/
|
||||
m_uHash = (position.x*(OGRE_REGION_SIDE_LENGTH*2+1)*(OGRE_REGION_SIDE_LENGTH*2+1)) + (position.y*(OGRE_REGION_SIDE_LENGTH*2+1)) + (position.z);
|
||||
}
|
||||
|
||||
SurfaceVertex::SurfaceVertex(UIntVector3 positionToSet, Vector3 normalToSet)
|
||||
:position(positionToSet)
|
||||
,normal(normalToSet)
|
||||
{
|
||||
/*noOfUses = 0;
|
||||
flags = 0;
|
||||
if(position.x == 0)
|
||||
flags |= 1;
|
||||
if(position.x == 8)
|
||||
flags |= 2;
|
||||
if(position.y == 0)
|
||||
flags |= 4;
|
||||
if(position.y == 8)
|
||||
flags |= 8;
|
||||
if(position.z == 0)
|
||||
flags |= 16;
|
||||
if(position.z == 8)
|
||||
flags |= 32;*/
|
||||
m_uHash = (position.x*(OGRE_REGION_SIDE_LENGTH*2+1)*(OGRE_REGION_SIDE_LENGTH*2+1)) + (position.y*(OGRE_REGION_SIDE_LENGTH*2+1)) + (position.z);
|
||||
}
|
||||
|
||||
const UIntVector3& SurfaceVertex::getPosition(void) const
|
||||
@ -55,6 +29,17 @@ namespace Ogre
|
||||
return position;
|
||||
}
|
||||
|
||||
const Vector3& SurfaceVertex::getNormal(void) const
|
||||
{
|
||||
return normal;
|
||||
}
|
||||
|
||||
void SurfaceVertex::setNormal(const Vector3& normalToSet)
|
||||
{
|
||||
normal = normalToSet;
|
||||
normal.normalise();
|
||||
}
|
||||
|
||||
std::string SurfaceVertex::toString(void)
|
||||
{
|
||||
std::stringstream ss;
|
||||
@ -64,42 +49,11 @@ namespace Ogre
|
||||
|
||||
bool operator==(const SurfaceVertex& lhs, const SurfaceVertex& rhs)
|
||||
{
|
||||
//We dont't check the normal here as it may not have been set. But if two vertices have the same position they should have the same normal too.
|
||||
/*return
|
||||
(
|
||||
(position.x == rhs.position.x) &&
|
||||
(position.y == rhs.position.y) &&
|
||||
(position.z == rhs.position.z) //&&
|
||||
//(abs(alpha - rhs.alpha) <= 0.01)
|
||||
);*/
|
||||
|
||||
/*ulong value = 0;
|
||||
value |= position.x;
|
||||
value << 10;
|
||||
value |= position.y;
|
||||
value << 10;
|
||||
value |= position.z;
|
||||
|
||||
ulong rhsValue = 0;
|
||||
rhsValue |= rhs.position.x;
|
||||
rhsValue << 10;
|
||||
rhsValue |= rhs.position.y;
|
||||
rhsValue << 10;
|
||||
rhsValue |= rhs.position.z;
|
||||
|
||||
return value == rhsValue;*/
|
||||
|
||||
unsigned long lhsOffset = (lhs.getPosition().x*(OGRE_REGION_SIDE_LENGTH*2+1)*(OGRE_REGION_SIDE_LENGTH*2+1)) + (lhs.getPosition().y*(OGRE_REGION_SIDE_LENGTH*2+1)) + (lhs.getPosition().z);
|
||||
unsigned long rhsOffset = (rhs.getPosition().x*(OGRE_REGION_SIDE_LENGTH*2+1)*(OGRE_REGION_SIDE_LENGTH*2+1)) + (rhs.getPosition().y*(OGRE_REGION_SIDE_LENGTH*2+1)) + (rhs.getPosition().z);
|
||||
|
||||
return (lhsOffset == rhsOffset) /*&& (abs(lhs.alpha - rhs.alpha) <= 0.01)*/;
|
||||
return (lhs.m_uHash == rhs.m_uHash);
|
||||
}
|
||||
|
||||
bool operator < (const SurfaceVertex& lhs, const SurfaceVertex& rhs)
|
||||
{
|
||||
unsigned long lhsOffset = (lhs.getPosition().x*(OGRE_REGION_SIDE_LENGTH*2+1)*(OGRE_REGION_SIDE_LENGTH*2+1)) + (lhs.getPosition().y*(OGRE_REGION_SIDE_LENGTH*2+1)) + (lhs.getPosition().z);
|
||||
unsigned long rhsOffset = (rhs.getPosition().x*(OGRE_REGION_SIDE_LENGTH*2+1)*(OGRE_REGION_SIDE_LENGTH*2+1)) + (rhs.getPosition().y*(OGRE_REGION_SIDE_LENGTH*2+1)) + (rhs.getPosition().z);
|
||||
|
||||
return lhsOffset < rhsOffset;
|
||||
return (lhs.m_uHash < rhs.m_uHash);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user