Started using texture atlas instead of many small meshes.
This commit is contained in:
@ -4,6 +4,7 @@ namespace Ogre
|
||||
{
|
||||
IndexedSurfacePatch::IndexedSurfacePatch()
|
||||
{
|
||||
memset(vertexIndices,0xFF,sizeof(vertexIndices)); //0xFF is -1 as two's complement - this may not be portable...
|
||||
}
|
||||
|
||||
IndexedSurfacePatch::~IndexedSurfacePatch()
|
||||
@ -12,24 +13,60 @@ namespace Ogre
|
||||
|
||||
void IndexedSurfacePatch::addTriangle(const SurfaceVertex& v0,const SurfaceVertex& v1,const SurfaceVertex& v2)
|
||||
{
|
||||
SurfaceVertexIterator v0Iter = m_listVertices.insert(v0).first;
|
||||
SurfaceVertexIterator v1Iter = m_listVertices.insert(v1).first;
|
||||
SurfaceVertexIterator v2Iter = m_listVertices.insert(v2).first;
|
||||
long int index = vertexIndices[long int(v0.getPosition().x +0.5)][long int(v0.getPosition().y +0.5)][long int(v0.getPosition().z +0.5)];
|
||||
if(index == -1)
|
||||
{
|
||||
m_vecVertices.push_back(v0);
|
||||
m_vecTriangleIndices.push_back(m_vecVertices.size()-1);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_vecTriangleIndices.push_back(index);
|
||||
}
|
||||
|
||||
m_vecTriangleIndices.push_back(v0Iter);
|
||||
m_vecTriangleIndices.push_back(v1Iter);
|
||||
m_vecTriangleIndices.push_back(v2Iter);
|
||||
index = vertexIndices[long int(v1.getPosition().x +0.5)][long int(v1.getPosition().y +0.5)][long int(v1.getPosition().z +0.5)];
|
||||
if(index == -1)
|
||||
{
|
||||
m_vecVertices.push_back(v1);
|
||||
m_vecTriangleIndices.push_back(m_vecVertices.size()-1);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_vecTriangleIndices.push_back(index);
|
||||
}
|
||||
|
||||
index = vertexIndices[long int(v2.getPosition().x +0.5)][long int(v2.getPosition().y +0.5)][long int(v2.getPosition().z +0.5)];
|
||||
if(index == -1)
|
||||
{
|
||||
m_vecVertices.push_back(v2);
|
||||
m_vecTriangleIndices.push_back(m_vecVertices.size()-1);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_vecTriangleIndices.push_back(index);
|
||||
}
|
||||
|
||||
|
||||
/*m_vecVertices.push_back(v0);
|
||||
m_vecTriangleIndices.push_back(m_vecVertices.size()-1);
|
||||
m_vecVertices.push_back(v1);
|
||||
m_vecTriangleIndices.push_back(m_vecVertices.size()-1);
|
||||
m_vecVertices.push_back(v2);
|
||||
m_vecTriangleIndices.push_back(m_vecVertices.size()-1);*/
|
||||
}
|
||||
|
||||
void IndexedSurfacePatch::fillVertexAndIndexData(std::vector<SurfaceVertex>& vecVertices, std::vector<ushort>& vecIndices)
|
||||
{
|
||||
vecVertices.resize(m_listVertices.size());
|
||||
std::copy(m_listVertices.begin(), m_listVertices.end(), vecVertices.begin());
|
||||
vecVertices.resize(m_vecVertices.size());
|
||||
std::copy(m_vecVertices.begin(), m_vecVertices.end(), vecVertices.begin());
|
||||
|
||||
for(std::vector<SurfaceVertexIterator>::iterator iterVertices = m_vecTriangleIndices.begin(); iterVertices != m_vecTriangleIndices.end(); ++iterVertices)
|
||||
vecIndices.resize(m_vecTriangleIndices.size());
|
||||
std::copy(m_vecTriangleIndices.begin(), m_vecTriangleIndices.end(), vecIndices.begin());
|
||||
|
||||
/*for(std::vector<SurfaceVertexIterator>::iterator iterVertices = m_vecTriangleIndices.begin(); iterVertices != m_vecTriangleIndices.end(); ++iterVertices)
|
||||
{
|
||||
std::vector<SurfaceVertex>::iterator iterVertex = lower_bound(vecVertices.begin(), vecVertices.end(), **iterVertices);
|
||||
vecIndices.push_back(iterVertex - vecVertices.begin());
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
@ -144,7 +144,7 @@ namespace Ogre
|
||||
//Generate the surface
|
||||
//std::vector< std::vector<SurfaceVertex> > vertexData;
|
||||
//std::vector< std::vector<SurfaceTriangle> > indexData;
|
||||
std::map<uchar, AbstractSurfacePatch*> mapSurfacePatch = generateMeshDataForRegion(regionX,regionY,regionZ);
|
||||
std::map<uchar, IndexedSurfacePatch*> mapSurfacePatch = generateMeshDataForRegion(regionX,regionY,regionZ);
|
||||
|
||||
//If a SceneNode doesn't exist in this position then create one.
|
||||
std::map<UIntVector3, SceneNode*>::iterator iterSceneNode = sceneNodes.find(UIntVector3(regionX,regionY,regionZ));
|
||||
@ -162,7 +162,7 @@ namespace Ogre
|
||||
|
||||
//For each surface attach it to the scene node.
|
||||
//for(uint meshCt = 1; meshCt < 256; ++meshCt)
|
||||
for(std::map<uchar, AbstractSurfacePatch*>::iterator iterSurfacePatch = mapSurfacePatch.begin(); iterSurfacePatch != mapSurfacePatch.end(); ++iterSurfacePatch)
|
||||
for(std::map<uchar, IndexedSurfacePatch*>::iterator iterSurfacePatch = mapSurfacePatch.begin(); iterSurfacePatch != mapSurfacePatch.end(); ++iterSurfacePatch)
|
||||
{
|
||||
/*std::vector<SurfaceVertex> vertexData;
|
||||
std::vector<uint> indexData;
|
||||
@ -349,9 +349,11 @@ namespace Ogre
|
||||
}
|
||||
}
|
||||
|
||||
std::map<uchar, AbstractSurfacePatch*> PolyVoxSceneManager::generateMeshDataForRegion(const uint regionX, const uint regionY, const uint regionZ) const
|
||||
std::map<uchar, IndexedSurfacePatch*> PolyVoxSceneManager::generateMeshDataForRegion(const uint regionX, const uint regionY, const uint regionZ) const
|
||||
{
|
||||
std::map<uchar, AbstractSurfacePatch*> surfacePatchMapResult;
|
||||
std::map<uchar, IndexedSurfacePatch*> surfacePatchMapResult;
|
||||
|
||||
surfacePatchMapResult.insert(std::make_pair(1,new IndexedSurfacePatch));
|
||||
|
||||
//LogManager::getSingleton().logMessage("Generating Mesh Data");
|
||||
//First and last voxels in the region
|
||||
@ -509,7 +511,7 @@ namespace Ogre
|
||||
const uchar material1 = vertMaterials[triTable[iCubeIndex][i+1]];
|
||||
const uchar material2 = vertMaterials[triTable[iCubeIndex][i+2]];
|
||||
|
||||
if(surfacePatchMapResult.find(material0) == surfacePatchMapResult.end())
|
||||
/*if(surfacePatchMapResult.find(material0) == surfacePatchMapResult.end())
|
||||
{
|
||||
surfacePatchMapResult.insert(std::make_pair(material0,new IndexedSurfacePatch));
|
||||
}
|
||||
@ -520,20 +522,23 @@ namespace Ogre
|
||||
if(surfacePatchMapResult.find(material2) == surfacePatchMapResult.end())
|
||||
{
|
||||
surfacePatchMapResult.insert(std::make_pair(material2,new IndexedSurfacePatch));
|
||||
}
|
||||
}*/
|
||||
|
||||
SurfaceVertex surfaceVertex0Alpha1(vertex0,1.0);
|
||||
SurfaceVertex surfaceVertex1Alpha1(vertex1,1.0);
|
||||
SurfaceVertex surfaceVertex2Alpha1(vertex2,1.0);
|
||||
//float materialToUse = std::max(material0,std::max(material1,material2));
|
||||
|
||||
|
||||
|
||||
//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))
|
||||
{
|
||||
surfacePatchMapResult[material0]->addTriangle(surfaceVertex0Alpha1, surfaceVertex1Alpha1, surfaceVertex2Alpha1);
|
||||
SurfaceVertex surfaceVertex0Alpha1(vertex0,material0 + 0.1);
|
||||
SurfaceVertex surfaceVertex1Alpha1(vertex1,material1 + 0.1);
|
||||
SurfaceVertex surfaceVertex2Alpha1(vertex2,material2 + 0.1);
|
||||
surfacePatchMapResult[1]->addTriangle(surfaceVertex0Alpha1, surfaceVertex1Alpha1, surfaceVertex2Alpha1);
|
||||
}
|
||||
//If there not all the same, we need one triangle for each unique material.
|
||||
//We'll also need some vertices with low alphas for blending.
|
||||
else
|
||||
/*else
|
||||
{
|
||||
SurfaceVertex surfaceVertex0Alpha0(vertex0,0.0);
|
||||
SurfaceVertex surfaceVertex1Alpha0(vertex1,0.0);
|
||||
@ -560,18 +565,18 @@ namespace Ogre
|
||||
surfacePatchMapResult[material1]->addTriangle(surfaceVertex0Alpha0, surfaceVertex1Alpha1, surfaceVertex2Alpha0);
|
||||
surfacePatchMapResult[material2]->addTriangle(surfaceVertex0Alpha0, surfaceVertex1Alpha0, surfaceVertex2Alpha1);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}//For each triangle
|
||||
}//For each cell
|
||||
|
||||
//FIXME - can it happen that we have no vertices or triangles? Should exit early?
|
||||
|
||||
|
||||
for(std::map<uchar, AbstractSurfacePatch*>::iterator iterPatch = surfacePatchMapResult.begin(); iterPatch != surfacePatchMapResult.end(); ++iterPatch)
|
||||
for(std::map<uchar, IndexedSurfacePatch*>::iterator iterPatch = surfacePatchMapResult.begin(); iterPatch != surfacePatchMapResult.end(); ++iterPatch)
|
||||
{
|
||||
|
||||
SurfaceVertexIterator iterSurfaceVertex = iterPatch->second->getVerticesBegin();
|
||||
while(iterSurfaceVertex != iterPatch->second->getVerticesEnd())
|
||||
std::vector<SurfaceVertex>::iterator iterSurfaceVertex = iterPatch->second->m_vecVertices.begin();
|
||||
while(iterSurfaceVertex != iterPatch->second->m_vecVertices.end())
|
||||
{
|
||||
Vector3 tempNormal = computeNormal((iterSurfaceVertex->getPosition() + offset).toOgreVector3()/2.0f, CENTRAL_DIFFERENCE);
|
||||
const_cast<SurfaceVertex&>(*iterSurfaceVertex).setNormal(tempNormal);
|
||||
|
@ -1,13 +1,14 @@
|
||||
#include "SurfacePatchRenderable.h"
|
||||
|
||||
#include "SurfaceEdge.h"
|
||||
#include "SurfaceVertex.h"
|
||||
#include "OgreVertexIndexData.h"
|
||||
|
||||
#include <limits>
|
||||
|
||||
namespace Ogre
|
||||
{
|
||||
SurfacePatchRenderable::SurfacePatchRenderable(AbstractSurfacePatch* patchToRender, const String& material)
|
||||
SurfacePatchRenderable::SurfacePatchRenderable(IndexedSurfacePatch* patchToRender, const String& material)
|
||||
{
|
||||
//Set up what we can of the vertex data
|
||||
mRenderOp.vertexData = new VertexData();
|
||||
@ -40,12 +41,12 @@ namespace Ogre
|
||||
delete mRenderOp.indexData;
|
||||
}
|
||||
|
||||
void SurfacePatchRenderable::updateWithNewSurfacePatch(AbstractSurfacePatch* patchToRender)
|
||||
{
|
||||
void SurfacePatchRenderable::updateWithNewSurfacePatch(IndexedSurfacePatch* patchToRender)
|
||||
{
|
||||
setGeometry(patchToRender);
|
||||
}
|
||||
|
||||
void SurfacePatchRenderable::setGeometry(AbstractSurfacePatch* patchToRender)
|
||||
void SurfacePatchRenderable::setGeometry(IndexedSurfacePatch* patchToRender)
|
||||
{
|
||||
std::vector<SurfaceVertex> vecVertices;
|
||||
std::vector<ushort> vecIndices;
|
||||
|
@ -61,10 +61,10 @@ namespace Ogre
|
||||
volIter.setVoxelAt(x,y,z,value);
|
||||
/*if(z < 24)
|
||||
{
|
||||
//if(x % 32 < 16)
|
||||
volIter.setVoxelAt(x,y,z,4);
|
||||
//else
|
||||
//volIter.setVoxelAt(x,y,z,5);
|
||||
if(x % 32 < 16)
|
||||
volIter.setVoxelAt(x,y,z,5);
|
||||
else
|
||||
volIter.setVoxelAt(x,y,z,5);
|
||||
}
|
||||
else
|
||||
volIter.setVoxelAt(x,y,z,0);*/
|
||||
|
Reference in New Issue
Block a user