|
|
|
@ -29,6 +29,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
#include "OgreStringConverter.h"
|
|
|
|
|
#include "OgreLogManager.h"
|
|
|
|
|
|
|
|
|
|
#include <list>
|
|
|
|
|
|
|
|
|
|
namespace Ogre
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
@ -130,48 +132,35 @@ namespace Ogre
|
|
|
|
|
{
|
|
|
|
|
if(!volumeData.isNull())
|
|
|
|
|
{
|
|
|
|
|
unsigned long triangleCounter = 0;
|
|
|
|
|
//Regenerate meshes.
|
|
|
|
|
for(uint regionZ = 0; regionZ < OGRE_VOLUME_SIDE_LENGTH_IN_REGIONS; ++regionZ)
|
|
|
|
|
std::list<RegionGeometry> listChangedRegionGeometry = getChangedRegionGeometry();
|
|
|
|
|
|
|
|
|
|
for(std::list<RegionGeometry>::iterator iterRegionGeometry = listChangedRegionGeometry.begin(); iterRegionGeometry != listChangedRegionGeometry.end(); iterRegionGeometry++)
|
|
|
|
|
{
|
|
|
|
|
//LogManager::getSingleton().logMessage("regionZ = " + StringConverter::toString(regionZ));
|
|
|
|
|
for(uint regionY = 0; regionY < OGRE_VOLUME_SIDE_LENGTH_IN_REGIONS; ++regionY)
|
|
|
|
|
{
|
|
|
|
|
//LogManager::getSingleton().logMessage("regionY = " + StringConverter::toString(regionY));
|
|
|
|
|
for(uint regionX = 0; regionX < OGRE_VOLUME_SIDE_LENGTH_IN_REGIONS; ++regionX)
|
|
|
|
|
{
|
|
|
|
|
//LogManager::getSingleton().logMessage("regionX = " + StringConverter::toString(regionX));
|
|
|
|
|
if(surfaceUpToDate[regionX][regionY][regionZ] == false)
|
|
|
|
|
{
|
|
|
|
|
std::stringstream locationStream;
|
|
|
|
|
locationStream << "(" << regionX << "," << regionY << "," << regionZ << ")";
|
|
|
|
|
std::string location = locationStream.str();
|
|
|
|
|
std::string location("");
|
|
|
|
|
location = location + "(" + iterRegionGeometry->m_v3dRegionPosition.x + "," + iterRegionGeometry->m_v3dRegionPosition.y + "," + iterRegionGeometry->m_v3dRegionPosition.z + ")";
|
|
|
|
|
|
|
|
|
|
//Generate the surface
|
|
|
|
|
IndexedSurfacePatch* singleMaterialPatch = new IndexedSurfacePatch(false);
|
|
|
|
|
IndexedSurfacePatch* multiMaterialPatch = new IndexedSurfacePatch(true);
|
|
|
|
|
|
|
|
|
|
generateMeshDataForRegion(regionX,regionY,regionZ, singleMaterialPatch, multiMaterialPatch);
|
|
|
|
|
IndexedSurfacePatch* singleMaterialPatch = iterRegionGeometry->m_patchSingleMaterial;
|
|
|
|
|
IndexedSurfacePatch* multiMaterialPatch = iterRegionGeometry->m_patchMultiMaterial;
|
|
|
|
|
|
|
|
|
|
if((singleMaterialPatch->m_vecVertices.size() == 0) && (singleMaterialPatch->m_vecTriangleIndices.size() == 0))
|
|
|
|
|
{
|
|
|
|
|
//No geometry exists. We can delete the scene node if it exists
|
|
|
|
|
std::map<UIntVector3, SceneNode*>::iterator iterSceneNode = sceneNodes.find(UIntVector3(regionX,regionY,regionZ));
|
|
|
|
|
std::map<UIntVector3, SceneNode*>::iterator iterSceneNode = sceneNodes.find(iterRegionGeometry->m_v3dRegionPosition);
|
|
|
|
|
if(iterSceneNode != sceneNodes.end())
|
|
|
|
|
{
|
|
|
|
|
getRootSceneNode()->removeChild(location);
|
|
|
|
|
}
|
|
|
|
|
surfaceUpToDate[regionX][regionY][regionZ] = true;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//If a SceneNode doesn't exist in this position then create one.
|
|
|
|
|
std::map<UIntVector3, SceneNode*>::iterator iterSceneNode = sceneNodes.find(UIntVector3(regionX,regionY,regionZ));
|
|
|
|
|
std::map<UIntVector3, SceneNode*>::iterator iterSceneNode = sceneNodes.find(iterRegionGeometry->m_v3dRegionPosition);
|
|
|
|
|
SceneNode* sceneNode;
|
|
|
|
|
if(iterSceneNode == sceneNodes.end())
|
|
|
|
|
{
|
|
|
|
|
sceneNode = getRootSceneNode()->createChildSceneNode(location, Vector3(regionX*OGRE_REGION_SIDE_LENGTH,regionY*OGRE_REGION_SIDE_LENGTH,regionZ*OGRE_REGION_SIDE_LENGTH));
|
|
|
|
|
sceneNodes.insert(std::make_pair(UIntVector3(regionX,regionY,regionZ),sceneNode));
|
|
|
|
|
sceneNode = getRootSceneNode()->createChildSceneNode(location, Vector3(iterRegionGeometry->m_v3dRegionPosition.x*OGRE_REGION_SIDE_LENGTH,iterRegionGeometry->m_v3dRegionPosition.y*OGRE_REGION_SIDE_LENGTH,iterRegionGeometry->m_v3dRegionPosition.z*OGRE_REGION_SIDE_LENGTH));
|
|
|
|
|
sceneNodes.insert(std::make_pair(iterRegionGeometry->m_v3dRegionPosition, sceneNode));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
@ -179,17 +168,8 @@ namespace Ogre
|
|
|
|
|
sceneNode->detachAllObjects();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//For each surface attach it to the scene node.
|
|
|
|
|
//for(uint meshCt = 1; meshCt < 256; ++meshCt)
|
|
|
|
|
//for(std::map<uchar, IndexedSurfacePatch*>::iterator iterSurfacePatch = mapSurfacePatch.begin(); iterSurfacePatch != mapSurfacePatch.end(); ++iterSurfacePatch)
|
|
|
|
|
{
|
|
|
|
|
/*std::vector<SurfaceVertex> vertexData;
|
|
|
|
|
std::vector<uint> indexData;
|
|
|
|
|
iterSurfacePatch->second.getVertexAndIndexData(vertexData, indexData);
|
|
|
|
|
triangleCounter += iterSurfacePatch->second.getNoOfTriangles();*/
|
|
|
|
|
|
|
|
|
|
SurfacePatchRenderable* singleMaterialSurfacePatchRenderable = m_singleMaterialSurfaces[regionX][regionY][regionZ];
|
|
|
|
|
SurfacePatchRenderable* multiMaterialSurfacePatchRenderable = m_multiMaterialSurfaces[regionX][regionY][regionZ];
|
|
|
|
|
SurfacePatchRenderable* singleMaterialSurfacePatchRenderable = m_singleMaterialSurfaces[iterRegionGeometry->m_v3dRegionPosition.x][iterRegionGeometry->m_v3dRegionPosition.y][iterRegionGeometry->m_v3dRegionPosition.z];
|
|
|
|
|
SurfacePatchRenderable* multiMaterialSurfacePatchRenderable = m_multiMaterialSurfaces[iterRegionGeometry->m_v3dRegionPosition.x][iterRegionGeometry->m_v3dRegionPosition.y][iterRegionGeometry->m_v3dRegionPosition.z];
|
|
|
|
|
if(singleMaterialSurfacePatchRenderable == 0) //if single is null then multi should also be null
|
|
|
|
|
{
|
|
|
|
|
//We have to create the surfaces
|
|
|
|
@ -199,10 +179,10 @@ namespace Ogre
|
|
|
|
|
multiMaterialSurfacePatchRenderable->setRenderQueueGroup(RENDER_QUEUE_3);
|
|
|
|
|
singleMaterialSurfacePatchRenderable->setRenderQueueGroup(RENDER_QUEUE_4);
|
|
|
|
|
|
|
|
|
|
m_singleMaterialSurfaces[regionX][regionY][regionZ] = singleMaterialSurfacePatchRenderable;
|
|
|
|
|
m_singleMaterialSurfaces[iterRegionGeometry->m_v3dRegionPosition.x][iterRegionGeometry->m_v3dRegionPosition.y][iterRegionGeometry->m_v3dRegionPosition.z] = singleMaterialSurfacePatchRenderable;
|
|
|
|
|
sceneNode->attachObject(singleMaterialSurfacePatchRenderable);
|
|
|
|
|
|
|
|
|
|
m_multiMaterialSurfaces[regionX][regionY][regionZ] = multiMaterialSurfacePatchRenderable;
|
|
|
|
|
m_multiMaterialSurfaces[iterRegionGeometry->m_v3dRegionPosition.x][iterRegionGeometry->m_v3dRegionPosition.y][iterRegionGeometry->m_v3dRegionPosition.z] = multiMaterialSurfacePatchRenderable;
|
|
|
|
|
sceneNode->attachObject(multiMaterialSurfacePatchRenderable);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
@ -215,14 +195,11 @@ namespace Ogre
|
|
|
|
|
sceneNode->attachObject(multiMaterialSurfacePatchRenderable);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//sceneNode->showBoundingBox(true);
|
|
|
|
|
surfaceUpToDate[regionX][regionY][regionZ] = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//LogManager::getSingleton().logMessage("No of tris = " + StringConverter::toString(triangleCounter));
|
|
|
|
|
|
|
|
|
|
setAllUpToDateFlagsTo(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//showBoundingBoxes(true);
|
|
|
|
|
|
|
|
|
|
//Now call the base class to do the actual visibility determination...
|
|
|
|
@ -233,7 +210,40 @@ namespace Ogre
|
|
|
|
|
//LogManager::getSingleton().logMessage("No of vertices accepted = " + StringConverter::toString(IndexedSurfacePatch::noOfVerticesAccepted));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PolyVoxSceneManager::setAllUpToDateFalse(void)
|
|
|
|
|
std::list<RegionGeometry> PolyVoxSceneManager::getChangedRegionGeometry(void)
|
|
|
|
|
{
|
|
|
|
|
std::list<RegionGeometry> listChangedRegionGeometry;
|
|
|
|
|
|
|
|
|
|
//Regenerate meshes.
|
|
|
|
|
for(uint regionZ = 0; regionZ < OGRE_VOLUME_SIDE_LENGTH_IN_REGIONS; ++regionZ)
|
|
|
|
|
{
|
|
|
|
|
//LogManager::getSingleton().logMessage("regionZ = " + StringConverter::toString(regionZ));
|
|
|
|
|
for(uint regionY = 0; regionY < OGRE_VOLUME_SIDE_LENGTH_IN_REGIONS; ++regionY)
|
|
|
|
|
{
|
|
|
|
|
//LogManager::getSingleton().logMessage("regionY = " + StringConverter::toString(regionY));
|
|
|
|
|
for(uint regionX = 0; regionX < OGRE_VOLUME_SIDE_LENGTH_IN_REGIONS; ++regionX)
|
|
|
|
|
{
|
|
|
|
|
//LogManager::getSingleton().logMessage("regionX = " + StringConverter::toString(regionX));
|
|
|
|
|
if(surfaceUpToDate[regionX][regionY][regionZ] == false)
|
|
|
|
|
{
|
|
|
|
|
//Generate the surface
|
|
|
|
|
RegionGeometry regionGeometry;
|
|
|
|
|
regionGeometry.m_patchSingleMaterial = new IndexedSurfacePatch(false);
|
|
|
|
|
regionGeometry.m_patchMultiMaterial = new IndexedSurfacePatch(true);
|
|
|
|
|
regionGeometry.m_v3dRegionPosition.setData(regionX, regionY, regionZ);
|
|
|
|
|
|
|
|
|
|
generateMeshDataForRegion(regionX,regionY,regionZ, regionGeometry.m_patchSingleMaterial, regionGeometry.m_patchMultiMaterial);
|
|
|
|
|
|
|
|
|
|
listChangedRegionGeometry.push_back(regionGeometry);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return listChangedRegionGeometry;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PolyVoxSceneManager::setAllUpToDateFlagsTo(bool newUpToDateValue)
|
|
|
|
|
{
|
|
|
|
|
for(uint blockZ = 0; blockZ < OGRE_VOLUME_SIDE_LENGTH_IN_REGIONS; ++blockZ)
|
|
|
|
|
{
|
|
|
|
@ -241,7 +251,7 @@ namespace Ogre
|
|
|
|
|
{
|
|
|
|
|
for(uint blockX = 0; blockX < OGRE_VOLUME_SIDE_LENGTH_IN_REGIONS; ++blockX)
|
|
|
|
|
{
|
|
|
|
|
surfaceUpToDate[blockX][blockY][blockZ] = false;
|
|
|
|
|
surfaceUpToDate[blockX][blockY][blockZ] = newUpToDateValue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|