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:
|
||||
SurfaceVertex();
|
||||
SurfaceVertex(Vector3DUint32 positionToSet, float materialToSet, float alphaToSet);
|
||||
SurfaceVertex(Vector3DUint32 positionToSet, Vector3DFloat normalToSet);
|
||||
SurfaceVertex(Vector3DFloat positionToSet, float materialToSet, float alphaToSet);
|
||||
SurfaceVertex(Vector3DFloat positionToSet, Vector3DFloat normalToSet);
|
||||
|
||||
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;
|
||||
float getMaterial(void) const;
|
||||
const Vector3DFloat& getNormal(void) const;
|
||||
const Vector3DUint32& getPosition(void) const;
|
||||
const Vector3DFloat& getPosition(void) const;
|
||||
|
||||
void setAlpha(float alphaToSet);
|
||||
void setEdge(const SurfaceEdgeIterator& edgeToSet);
|
||||
@ -50,7 +50,7 @@ namespace PolyVox
|
||||
std::string tostring(void) const;
|
||||
|
||||
private:
|
||||
Vector3DUint32 position;
|
||||
Vector3DFloat position;
|
||||
Vector3DFloat normal;
|
||||
float material;
|
||||
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));
|
||||
|
||||
//Offset from lower block corner
|
||||
const Vector3DUint32 offset(firstX*2,firstY*2,firstZ*2);
|
||||
const Vector3DFloat offset(firstX,firstY,firstZ);
|
||||
|
||||
Vector3DUint32 vertlist[12];
|
||||
uint8_t vertMaterials[12];
|
||||
@ -380,9 +380,14 @@ namespace PolyVox
|
||||
for (int i=0;triTable[iCubeIndex][i]!=-1;i+=3)
|
||||
{
|
||||
//The three vertices forming a triangle
|
||||
const Vector3DUint32 vertex0 = vertlist[triTable[iCubeIndex][i ]] - offset;
|
||||
const Vector3DUint32 vertex1 = vertlist[triTable[iCubeIndex][i+1]] - offset;
|
||||
const Vector3DUint32 vertex2 = vertlist[triTable[iCubeIndex][i+2]] - offset;
|
||||
const Vector3DUint32 vertex0 = vertlist[triTable[iCubeIndex][i ]];
|
||||
const Vector3DUint32 vertex1 = vertlist[triTable[iCubeIndex][i+1]];
|
||||
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 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((material0 == material1) && (material1 == material2))
|
||||
{
|
||||
SurfaceVertex surfaceVertex0Alpha1(vertex0,material0 + 0.1,1.0);
|
||||
SurfaceVertex surfaceVertex1Alpha1(vertex1,material1 + 0.1,1.0);
|
||||
SurfaceVertex surfaceVertex2Alpha1(vertex2,material2 + 0.1,1.0);
|
||||
SurfaceVertex surfaceVertex0Alpha1(vertex0AsFloat,material0 + 0.1,1.0);
|
||||
SurfaceVertex surfaceVertex1Alpha1(vertex1AsFloat,material1 + 0.1,1.0);
|
||||
SurfaceVertex surfaceVertex2Alpha1(vertex2AsFloat,material2 + 0.1,1.0);
|
||||
singleMaterialPatch->addTriangle(surfaceVertex0Alpha1, surfaceVertex1Alpha1, surfaceVertex2Alpha1);
|
||||
}
|
||||
else if(material0 == material1)
|
||||
{
|
||||
{
|
||||
SurfaceVertex surfaceVertex0Alpha1(vertex0,material0 + 0.1,1.0);
|
||||
SurfaceVertex surfaceVertex1Alpha1(vertex1,material0 + 0.1,1.0);
|
||||
SurfaceVertex surfaceVertex2Alpha1(vertex2,material0 + 0.1,0.0);
|
||||
SurfaceVertex surfaceVertex0Alpha1(vertex0AsFloat,material0 + 0.1,1.0);
|
||||
SurfaceVertex surfaceVertex1Alpha1(vertex1AsFloat,material0 + 0.1,1.0);
|
||||
SurfaceVertex surfaceVertex2Alpha1(vertex2AsFloat,material0 + 0.1,0.0);
|
||||
multiMaterialPatch->addTriangle(surfaceVertex0Alpha1, surfaceVertex1Alpha1, surfaceVertex2Alpha1);
|
||||
}
|
||||
|
||||
{
|
||||
SurfaceVertex surfaceVertex0Alpha1(vertex0,material2 + 0.1,0.0);
|
||||
SurfaceVertex surfaceVertex1Alpha1(vertex1,material2 + 0.1,0.0);
|
||||
SurfaceVertex surfaceVertex2Alpha1(vertex2,material2 + 0.1,1.0);
|
||||
SurfaceVertex surfaceVertex0Alpha1(vertex0AsFloat,material2 + 0.1,0.0);
|
||||
SurfaceVertex surfaceVertex1Alpha1(vertex1AsFloat,material2 + 0.1,0.0);
|
||||
SurfaceVertex surfaceVertex2Alpha1(vertex2AsFloat,material2 + 0.1,1.0);
|
||||
multiMaterialPatch->addTriangle(surfaceVertex0Alpha1, surfaceVertex1Alpha1, surfaceVertex2Alpha1);
|
||||
}
|
||||
}
|
||||
else if(material0 == material2)
|
||||
{
|
||||
{
|
||||
SurfaceVertex surfaceVertex0Alpha1(vertex0,material0 + 0.1,1.0);
|
||||
SurfaceVertex surfaceVertex1Alpha1(vertex1,material0 + 0.1,0.0);
|
||||
SurfaceVertex surfaceVertex2Alpha1(vertex2,material0 + 0.1,1.0);
|
||||
SurfaceVertex surfaceVertex0Alpha1(vertex0AsFloat,material0 + 0.1,1.0);
|
||||
SurfaceVertex surfaceVertex1Alpha1(vertex1AsFloat,material0 + 0.1,0.0);
|
||||
SurfaceVertex surfaceVertex2Alpha1(vertex2AsFloat,material0 + 0.1,1.0);
|
||||
multiMaterialPatch->addTriangle(surfaceVertex0Alpha1, surfaceVertex1Alpha1, surfaceVertex2Alpha1);
|
||||
}
|
||||
|
||||
{
|
||||
SurfaceVertex surfaceVertex0Alpha1(vertex0,material1 + 0.1,0.0);
|
||||
SurfaceVertex surfaceVertex1Alpha1(vertex1,material1 + 0.1,1.0);
|
||||
SurfaceVertex surfaceVertex2Alpha1(vertex2,material1 + 0.1,0.0);
|
||||
SurfaceVertex surfaceVertex0Alpha1(vertex0AsFloat,material1 + 0.1,0.0);
|
||||
SurfaceVertex surfaceVertex1Alpha1(vertex1AsFloat,material1 + 0.1,1.0);
|
||||
SurfaceVertex surfaceVertex2Alpha1(vertex2AsFloat,material1 + 0.1,0.0);
|
||||
multiMaterialPatch->addTriangle(surfaceVertex0Alpha1, surfaceVertex1Alpha1, surfaceVertex2Alpha1);
|
||||
}
|
||||
}
|
||||
else if(material1 == material2)
|
||||
{
|
||||
{
|
||||
SurfaceVertex surfaceVertex0Alpha1(vertex0,material1 + 0.1,0.0);
|
||||
SurfaceVertex surfaceVertex1Alpha1(vertex1,material1 + 0.1,1.0);
|
||||
SurfaceVertex surfaceVertex2Alpha1(vertex2,material1 + 0.1,1.0);
|
||||
SurfaceVertex surfaceVertex0Alpha1(vertex0AsFloat,material1 + 0.1,0.0);
|
||||
SurfaceVertex surfaceVertex1Alpha1(vertex1AsFloat,material1 + 0.1,1.0);
|
||||
SurfaceVertex surfaceVertex2Alpha1(vertex2AsFloat,material1 + 0.1,1.0);
|
||||
multiMaterialPatch->addTriangle(surfaceVertex0Alpha1, surfaceVertex1Alpha1, surfaceVertex2Alpha1);
|
||||
}
|
||||
|
||||
{
|
||||
SurfaceVertex surfaceVertex0Alpha1(vertex0,material0 + 0.1,1.0);
|
||||
SurfaceVertex surfaceVertex1Alpha1(vertex1,material0 + 0.1,0.0);
|
||||
SurfaceVertex surfaceVertex2Alpha1(vertex2,material0 + 0.1,0.0);
|
||||
SurfaceVertex surfaceVertex0Alpha1(vertex0AsFloat,material0 + 0.1,1.0);
|
||||
SurfaceVertex surfaceVertex1Alpha1(vertex1AsFloat,material0 + 0.1,0.0);
|
||||
SurfaceVertex surfaceVertex2Alpha1(vertex2AsFloat,material0 + 0.1,0.0);
|
||||
multiMaterialPatch->addTriangle(surfaceVertex0Alpha1, surfaceVertex1Alpha1, surfaceVertex2Alpha1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
{
|
||||
SurfaceVertex surfaceVertex0Alpha1(vertex0,material0 + 0.1,1.0);
|
||||
SurfaceVertex surfaceVertex1Alpha1(vertex1,material0 + 0.1,0.0);
|
||||
SurfaceVertex surfaceVertex2Alpha1(vertex2,material0 + 0.1,0.0);
|
||||
SurfaceVertex surfaceVertex0Alpha1(vertex0AsFloat,material0 + 0.1,1.0);
|
||||
SurfaceVertex surfaceVertex1Alpha1(vertex1AsFloat,material0 + 0.1,0.0);
|
||||
SurfaceVertex surfaceVertex2Alpha1(vertex2AsFloat,material0 + 0.1,0.0);
|
||||
multiMaterialPatch->addTriangle(surfaceVertex0Alpha1, surfaceVertex1Alpha1, surfaceVertex2Alpha1);
|
||||
}
|
||||
|
||||
{
|
||||
SurfaceVertex surfaceVertex0Alpha1(vertex0,material1 + 0.1,0.0);
|
||||
SurfaceVertex surfaceVertex1Alpha1(vertex1,material1 + 0.1,1.0);
|
||||
SurfaceVertex surfaceVertex2Alpha1(vertex2,material1 + 0.1,0.0);
|
||||
SurfaceVertex surfaceVertex0Alpha1(vertex0AsFloat,material1 + 0.1,0.0);
|
||||
SurfaceVertex surfaceVertex1Alpha1(vertex1AsFloat,material1 + 0.1,1.0);
|
||||
SurfaceVertex surfaceVertex2Alpha1(vertex2AsFloat,material1 + 0.1,0.0);
|
||||
multiMaterialPatch->addTriangle(surfaceVertex0Alpha1, surfaceVertex1Alpha1, surfaceVertex2Alpha1);
|
||||
}
|
||||
|
||||
{
|
||||
SurfaceVertex surfaceVertex0Alpha1(vertex0,material2 + 0.1,0.0);
|
||||
SurfaceVertex surfaceVertex1Alpha1(vertex1,material2 + 0.1,0.0);
|
||||
SurfaceVertex surfaceVertex2Alpha1(vertex2,material2 + 0.1,1.0);
|
||||
SurfaceVertex surfaceVertex0Alpha1(vertex0AsFloat,material2 + 0.1,0.0);
|
||||
SurfaceVertex surfaceVertex1Alpha1(vertex1AsFloat,material2 + 0.1,0.0);
|
||||
SurfaceVertex surfaceVertex2Alpha1(vertex2AsFloat,material2 + 0.1,1.0);
|
||||
multiMaterialPatch->addTriangle(surfaceVertex0Alpha1, surfaceVertex1Alpha1, surfaceVertex2Alpha1);
|
||||
}
|
||||
}
|
||||
@ -510,7 +515,7 @@ namespace PolyVox
|
||||
std::vector<SurfaceVertex>::iterator iterSurfaceVertex = singleMaterialPatch->m_vecVertices.begin();
|
||||
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);
|
||||
++iterSurfaceVertex;
|
||||
}
|
||||
@ -518,7 +523,7 @@ namespace PolyVox
|
||||
iterSurfaceVertex = multiMaterialPatch->m_vecVertices.begin();
|
||||
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);
|
||||
++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)
|
||||
,alpha(alphaToSet)
|
||||
,position(positionToSet)
|
||||
@ -20,7 +20,7 @@ namespace PolyVox
|
||||
|
||||
}
|
||||
|
||||
SurfaceVertex::SurfaceVertex(Vector3DUint32 positionToSet, Vector3DFloat normalToSet)
|
||||
SurfaceVertex::SurfaceVertex(Vector3DFloat positionToSet, Vector3DFloat normalToSet)
|
||||
:position(positionToSet)
|
||||
,normal(normalToSet)
|
||||
{
|
||||
@ -47,7 +47,7 @@ namespace PolyVox
|
||||
return normal;
|
||||
}
|
||||
|
||||
const Vector3DUint32& SurfaceVertex::getPosition(void) const
|
||||
const Vector3DFloat& SurfaceVertex::getPosition(void) const
|
||||
{
|
||||
return position;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user