PolyVox now returns vertex positions as floats rather than ints.
Avoids converting and scaling in the engine.
This commit is contained in:
parent
1d8fc1c544
commit
2bc1fc2b88
@ -30,8 +30,8 @@ namespace PolyVox
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SurfaceVertex();
|
SurfaceVertex();
|
||||||
SurfaceVertex(Vector3DUint32 positionToSet, float materialToSet, float alphaToSet);
|
SurfaceVertex(Vector3DFloat positionToSet, float materialToSet, float alphaToSet);
|
||||||
SurfaceVertex(Vector3DUint32 positionToSet, Vector3DFloat normalToSet);
|
SurfaceVertex(Vector3DFloat positionToSet, Vector3DFloat normalToSet);
|
||||||
|
|
||||||
friend bool operator==(const SurfaceVertex& lhs, const SurfaceVertex& rhs);
|
friend bool operator==(const SurfaceVertex& lhs, const SurfaceVertex& rhs);
|
||||||
friend bool operator < (const SurfaceVertex& lhs, const SurfaceVertex& rhs);
|
friend bool operator < (const SurfaceVertex& lhs, const SurfaceVertex& rhs);
|
||||||
@ -40,7 +40,7 @@ namespace PolyVox
|
|||||||
const SurfaceEdgeIterator& getEdge(void) const;
|
const SurfaceEdgeIterator& getEdge(void) const;
|
||||||
float getMaterial(void) const;
|
float getMaterial(void) const;
|
||||||
const Vector3DFloat& getNormal(void) const;
|
const Vector3DFloat& getNormal(void) const;
|
||||||
const Vector3DUint32& getPosition(void) const;
|
const Vector3DFloat& getPosition(void) const;
|
||||||
|
|
||||||
void setAlpha(float alphaToSet);
|
void setAlpha(float alphaToSet);
|
||||||
void setEdge(const SurfaceEdgeIterator& edgeToSet);
|
void setEdge(const SurfaceEdgeIterator& edgeToSet);
|
||||||
@ -50,7 +50,7 @@ namespace PolyVox
|
|||||||
std::string tostring(void) const;
|
std::string tostring(void) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Vector3DUint32 position;
|
Vector3DFloat position;
|
||||||
Vector3DFloat normal;
|
Vector3DFloat normal;
|
||||||
float material;
|
float material;
|
||||||
float alpha;
|
float alpha;
|
||||||
|
@ -244,7 +244,7 @@ namespace PolyVox
|
|||||||
const uint16_t lastZ = (std::min)(firstZ + POLYVOX_REGION_SIDE_LENGTH-1,static_cast<uint32_t>(POLYVOX_VOLUME_SIDE_LENGTH-2));
|
const uint16_t lastZ = (std::min)(firstZ + POLYVOX_REGION_SIDE_LENGTH-1,static_cast<uint32_t>(POLYVOX_VOLUME_SIDE_LENGTH-2));
|
||||||
|
|
||||||
//Offset from lower block corner
|
//Offset from lower block corner
|
||||||
const Vector3DUint32 offset(firstX*2,firstY*2,firstZ*2);
|
const Vector3DFloat offset(firstX,firstY,firstZ);
|
||||||
|
|
||||||
Vector3DUint32 vertlist[12];
|
Vector3DUint32 vertlist[12];
|
||||||
uint8_t vertMaterials[12];
|
uint8_t vertMaterials[12];
|
||||||
@ -380,9 +380,14 @@ namespace PolyVox
|
|||||||
for (int i=0;triTable[iCubeIndex][i]!=-1;i+=3)
|
for (int i=0;triTable[iCubeIndex][i]!=-1;i+=3)
|
||||||
{
|
{
|
||||||
//The three vertices forming a triangle
|
//The three vertices forming a triangle
|
||||||
const Vector3DUint32 vertex0 = vertlist[triTable[iCubeIndex][i ]] - offset;
|
const Vector3DUint32 vertex0 = vertlist[triTable[iCubeIndex][i ]];
|
||||||
const Vector3DUint32 vertex1 = vertlist[triTable[iCubeIndex][i+1]] - offset;
|
const Vector3DUint32 vertex1 = vertlist[triTable[iCubeIndex][i+1]];
|
||||||
const Vector3DUint32 vertex2 = vertlist[triTable[iCubeIndex][i+2]] - offset;
|
const Vector3DUint32 vertex2 = vertlist[triTable[iCubeIndex][i+2]];
|
||||||
|
|
||||||
|
//Cast to floats and divide by two.
|
||||||
|
const Vector3DFloat vertex0AsFloat = (static_cast<Vector3DFloat>(vertex0) / 2.0f) - offset;
|
||||||
|
const Vector3DFloat vertex1AsFloat = (static_cast<Vector3DFloat>(vertex1) / 2.0f) - offset;
|
||||||
|
const Vector3DFloat vertex2AsFloat = (static_cast<Vector3DFloat>(vertex2) / 2.0f) - offset;
|
||||||
|
|
||||||
const uint8_t material0 = vertMaterials[triTable[iCubeIndex][i ]];
|
const uint8_t material0 = vertMaterials[triTable[iCubeIndex][i ]];
|
||||||
const uint8_t material1 = vertMaterials[triTable[iCubeIndex][i+1]];
|
const uint8_t material1 = vertMaterials[triTable[iCubeIndex][i+1]];
|
||||||
@ -392,79 +397,79 @@ namespace PolyVox
|
|||||||
//If all the materials are the same, we just need one triangle for that material with all the alphas set high.
|
//If all the materials are the same, we just need one triangle for that material with all the alphas set high.
|
||||||
if((material0 == material1) && (material1 == material2))
|
if((material0 == material1) && (material1 == material2))
|
||||||
{
|
{
|
||||||
SurfaceVertex surfaceVertex0Alpha1(vertex0,material0 + 0.1,1.0);
|
SurfaceVertex surfaceVertex0Alpha1(vertex0AsFloat,material0 + 0.1,1.0);
|
||||||
SurfaceVertex surfaceVertex1Alpha1(vertex1,material1 + 0.1,1.0);
|
SurfaceVertex surfaceVertex1Alpha1(vertex1AsFloat,material1 + 0.1,1.0);
|
||||||
SurfaceVertex surfaceVertex2Alpha1(vertex2,material2 + 0.1,1.0);
|
SurfaceVertex surfaceVertex2Alpha1(vertex2AsFloat,material2 + 0.1,1.0);
|
||||||
singleMaterialPatch->addTriangle(surfaceVertex0Alpha1, surfaceVertex1Alpha1, surfaceVertex2Alpha1);
|
singleMaterialPatch->addTriangle(surfaceVertex0Alpha1, surfaceVertex1Alpha1, surfaceVertex2Alpha1);
|
||||||
}
|
}
|
||||||
else if(material0 == material1)
|
else if(material0 == material1)
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
SurfaceVertex surfaceVertex0Alpha1(vertex0,material0 + 0.1,1.0);
|
SurfaceVertex surfaceVertex0Alpha1(vertex0AsFloat,material0 + 0.1,1.0);
|
||||||
SurfaceVertex surfaceVertex1Alpha1(vertex1,material0 + 0.1,1.0);
|
SurfaceVertex surfaceVertex1Alpha1(vertex1AsFloat,material0 + 0.1,1.0);
|
||||||
SurfaceVertex surfaceVertex2Alpha1(vertex2,material0 + 0.1,0.0);
|
SurfaceVertex surfaceVertex2Alpha1(vertex2AsFloat,material0 + 0.1,0.0);
|
||||||
multiMaterialPatch->addTriangle(surfaceVertex0Alpha1, surfaceVertex1Alpha1, surfaceVertex2Alpha1);
|
multiMaterialPatch->addTriangle(surfaceVertex0Alpha1, surfaceVertex1Alpha1, surfaceVertex2Alpha1);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
SurfaceVertex surfaceVertex0Alpha1(vertex0,material2 + 0.1,0.0);
|
SurfaceVertex surfaceVertex0Alpha1(vertex0AsFloat,material2 + 0.1,0.0);
|
||||||
SurfaceVertex surfaceVertex1Alpha1(vertex1,material2 + 0.1,0.0);
|
SurfaceVertex surfaceVertex1Alpha1(vertex1AsFloat,material2 + 0.1,0.0);
|
||||||
SurfaceVertex surfaceVertex2Alpha1(vertex2,material2 + 0.1,1.0);
|
SurfaceVertex surfaceVertex2Alpha1(vertex2AsFloat,material2 + 0.1,1.0);
|
||||||
multiMaterialPatch->addTriangle(surfaceVertex0Alpha1, surfaceVertex1Alpha1, surfaceVertex2Alpha1);
|
multiMaterialPatch->addTriangle(surfaceVertex0Alpha1, surfaceVertex1Alpha1, surfaceVertex2Alpha1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(material0 == material2)
|
else if(material0 == material2)
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
SurfaceVertex surfaceVertex0Alpha1(vertex0,material0 + 0.1,1.0);
|
SurfaceVertex surfaceVertex0Alpha1(vertex0AsFloat,material0 + 0.1,1.0);
|
||||||
SurfaceVertex surfaceVertex1Alpha1(vertex1,material0 + 0.1,0.0);
|
SurfaceVertex surfaceVertex1Alpha1(vertex1AsFloat,material0 + 0.1,0.0);
|
||||||
SurfaceVertex surfaceVertex2Alpha1(vertex2,material0 + 0.1,1.0);
|
SurfaceVertex surfaceVertex2Alpha1(vertex2AsFloat,material0 + 0.1,1.0);
|
||||||
multiMaterialPatch->addTriangle(surfaceVertex0Alpha1, surfaceVertex1Alpha1, surfaceVertex2Alpha1);
|
multiMaterialPatch->addTriangle(surfaceVertex0Alpha1, surfaceVertex1Alpha1, surfaceVertex2Alpha1);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
SurfaceVertex surfaceVertex0Alpha1(vertex0,material1 + 0.1,0.0);
|
SurfaceVertex surfaceVertex0Alpha1(vertex0AsFloat,material1 + 0.1,0.0);
|
||||||
SurfaceVertex surfaceVertex1Alpha1(vertex1,material1 + 0.1,1.0);
|
SurfaceVertex surfaceVertex1Alpha1(vertex1AsFloat,material1 + 0.1,1.0);
|
||||||
SurfaceVertex surfaceVertex2Alpha1(vertex2,material1 + 0.1,0.0);
|
SurfaceVertex surfaceVertex2Alpha1(vertex2AsFloat,material1 + 0.1,0.0);
|
||||||
multiMaterialPatch->addTriangle(surfaceVertex0Alpha1, surfaceVertex1Alpha1, surfaceVertex2Alpha1);
|
multiMaterialPatch->addTriangle(surfaceVertex0Alpha1, surfaceVertex1Alpha1, surfaceVertex2Alpha1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(material1 == material2)
|
else if(material1 == material2)
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
SurfaceVertex surfaceVertex0Alpha1(vertex0,material1 + 0.1,0.0);
|
SurfaceVertex surfaceVertex0Alpha1(vertex0AsFloat,material1 + 0.1,0.0);
|
||||||
SurfaceVertex surfaceVertex1Alpha1(vertex1,material1 + 0.1,1.0);
|
SurfaceVertex surfaceVertex1Alpha1(vertex1AsFloat,material1 + 0.1,1.0);
|
||||||
SurfaceVertex surfaceVertex2Alpha1(vertex2,material1 + 0.1,1.0);
|
SurfaceVertex surfaceVertex2Alpha1(vertex2AsFloat,material1 + 0.1,1.0);
|
||||||
multiMaterialPatch->addTriangle(surfaceVertex0Alpha1, surfaceVertex1Alpha1, surfaceVertex2Alpha1);
|
multiMaterialPatch->addTriangle(surfaceVertex0Alpha1, surfaceVertex1Alpha1, surfaceVertex2Alpha1);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
SurfaceVertex surfaceVertex0Alpha1(vertex0,material0 + 0.1,1.0);
|
SurfaceVertex surfaceVertex0Alpha1(vertex0AsFloat,material0 + 0.1,1.0);
|
||||||
SurfaceVertex surfaceVertex1Alpha1(vertex1,material0 + 0.1,0.0);
|
SurfaceVertex surfaceVertex1Alpha1(vertex1AsFloat,material0 + 0.1,0.0);
|
||||||
SurfaceVertex surfaceVertex2Alpha1(vertex2,material0 + 0.1,0.0);
|
SurfaceVertex surfaceVertex2Alpha1(vertex2AsFloat,material0 + 0.1,0.0);
|
||||||
multiMaterialPatch->addTriangle(surfaceVertex0Alpha1, surfaceVertex1Alpha1, surfaceVertex2Alpha1);
|
multiMaterialPatch->addTriangle(surfaceVertex0Alpha1, surfaceVertex1Alpha1, surfaceVertex2Alpha1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
SurfaceVertex surfaceVertex0Alpha1(vertex0,material0 + 0.1,1.0);
|
SurfaceVertex surfaceVertex0Alpha1(vertex0AsFloat,material0 + 0.1,1.0);
|
||||||
SurfaceVertex surfaceVertex1Alpha1(vertex1,material0 + 0.1,0.0);
|
SurfaceVertex surfaceVertex1Alpha1(vertex1AsFloat,material0 + 0.1,0.0);
|
||||||
SurfaceVertex surfaceVertex2Alpha1(vertex2,material0 + 0.1,0.0);
|
SurfaceVertex surfaceVertex2Alpha1(vertex2AsFloat,material0 + 0.1,0.0);
|
||||||
multiMaterialPatch->addTriangle(surfaceVertex0Alpha1, surfaceVertex1Alpha1, surfaceVertex2Alpha1);
|
multiMaterialPatch->addTriangle(surfaceVertex0Alpha1, surfaceVertex1Alpha1, surfaceVertex2Alpha1);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
SurfaceVertex surfaceVertex0Alpha1(vertex0,material1 + 0.1,0.0);
|
SurfaceVertex surfaceVertex0Alpha1(vertex0AsFloat,material1 + 0.1,0.0);
|
||||||
SurfaceVertex surfaceVertex1Alpha1(vertex1,material1 + 0.1,1.0);
|
SurfaceVertex surfaceVertex1Alpha1(vertex1AsFloat,material1 + 0.1,1.0);
|
||||||
SurfaceVertex surfaceVertex2Alpha1(vertex2,material1 + 0.1,0.0);
|
SurfaceVertex surfaceVertex2Alpha1(vertex2AsFloat,material1 + 0.1,0.0);
|
||||||
multiMaterialPatch->addTriangle(surfaceVertex0Alpha1, surfaceVertex1Alpha1, surfaceVertex2Alpha1);
|
multiMaterialPatch->addTriangle(surfaceVertex0Alpha1, surfaceVertex1Alpha1, surfaceVertex2Alpha1);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
SurfaceVertex surfaceVertex0Alpha1(vertex0,material2 + 0.1,0.0);
|
SurfaceVertex surfaceVertex0Alpha1(vertex0AsFloat,material2 + 0.1,0.0);
|
||||||
SurfaceVertex surfaceVertex1Alpha1(vertex1,material2 + 0.1,0.0);
|
SurfaceVertex surfaceVertex1Alpha1(vertex1AsFloat,material2 + 0.1,0.0);
|
||||||
SurfaceVertex surfaceVertex2Alpha1(vertex2,material2 + 0.1,1.0);
|
SurfaceVertex surfaceVertex2Alpha1(vertex2AsFloat,material2 + 0.1,1.0);
|
||||||
multiMaterialPatch->addTriangle(surfaceVertex0Alpha1, surfaceVertex1Alpha1, surfaceVertex2Alpha1);
|
multiMaterialPatch->addTriangle(surfaceVertex0Alpha1, surfaceVertex1Alpha1, surfaceVertex2Alpha1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -510,7 +515,7 @@ namespace PolyVox
|
|||||||
std::vector<SurfaceVertex>::iterator iterSurfaceVertex = singleMaterialPatch->m_vecVertices.begin();
|
std::vector<SurfaceVertex>::iterator iterSurfaceVertex = singleMaterialPatch->m_vecVertices.begin();
|
||||||
while(iterSurfaceVertex != singleMaterialPatch->m_vecVertices.end())
|
while(iterSurfaceVertex != singleMaterialPatch->m_vecVertices.end())
|
||||||
{
|
{
|
||||||
Vector3DFloat tempNormal = computeNormal(static_cast<Vector3DFloat>(iterSurfaceVertex->getPosition() + offset)/2.0f, CENTRAL_DIFFERENCE);
|
Vector3DFloat tempNormal = computeNormal(static_cast<Vector3DFloat>(iterSurfaceVertex->getPosition() + offset), CENTRAL_DIFFERENCE);
|
||||||
const_cast<SurfaceVertex&>(*iterSurfaceVertex).setNormal(tempNormal);
|
const_cast<SurfaceVertex&>(*iterSurfaceVertex).setNormal(tempNormal);
|
||||||
++iterSurfaceVertex;
|
++iterSurfaceVertex;
|
||||||
}
|
}
|
||||||
@ -518,7 +523,7 @@ namespace PolyVox
|
|||||||
iterSurfaceVertex = multiMaterialPatch->m_vecVertices.begin();
|
iterSurfaceVertex = multiMaterialPatch->m_vecVertices.begin();
|
||||||
while(iterSurfaceVertex != multiMaterialPatch->m_vecVertices.end())
|
while(iterSurfaceVertex != multiMaterialPatch->m_vecVertices.end())
|
||||||
{
|
{
|
||||||
Vector3DFloat tempNormal = computeNormal(static_cast<Vector3DFloat>(iterSurfaceVertex->getPosition() + offset)/2.0f, CENTRAL_DIFFERENCE);
|
Vector3DFloat tempNormal = computeNormal(static_cast<Vector3DFloat>(iterSurfaceVertex->getPosition() + offset), CENTRAL_DIFFERENCE);
|
||||||
const_cast<SurfaceVertex&>(*iterSurfaceVertex).setNormal(tempNormal);
|
const_cast<SurfaceVertex&>(*iterSurfaceVertex).setNormal(tempNormal);
|
||||||
++iterSurfaceVertex;
|
++iterSurfaceVertex;
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ namespace PolyVox
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
SurfaceVertex::SurfaceVertex(Vector3DUint32 positionToSet, float materialToSet, float alphaToSet)
|
SurfaceVertex::SurfaceVertex(Vector3DFloat positionToSet, float materialToSet, float alphaToSet)
|
||||||
:material(materialToSet)
|
:material(materialToSet)
|
||||||
,alpha(alphaToSet)
|
,alpha(alphaToSet)
|
||||||
,position(positionToSet)
|
,position(positionToSet)
|
||||||
@ -20,7 +20,7 @@ namespace PolyVox
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SurfaceVertex::SurfaceVertex(Vector3DUint32 positionToSet, Vector3DFloat normalToSet)
|
SurfaceVertex::SurfaceVertex(Vector3DFloat positionToSet, Vector3DFloat normalToSet)
|
||||||
:position(positionToSet)
|
:position(positionToSet)
|
||||||
,normal(normalToSet)
|
,normal(normalToSet)
|
||||||
{
|
{
|
||||||
@ -47,7 +47,7 @@ namespace PolyVox
|
|||||||
return normal;
|
return normal;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Vector3DUint32& SurfaceVertex::getPosition(void) const
|
const Vector3DFloat& SurfaceVertex::getPosition(void) const
|
||||||
{
|
{
|
||||||
return position;
|
return position;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user