Separated getChangedRegionGeometry() from _findVisibleObjects().
This commit is contained in:
parent
b41793b520
commit
e368926b5f
@ -30,6 +30,7 @@ SET(INC_FILES
|
|||||||
include/MaterialMapManager.h
|
include/MaterialMapManager.h
|
||||||
include/MaterialMapSerializer.h
|
include/MaterialMapSerializer.h
|
||||||
include/PolyVoxSceneManager.h
|
include/PolyVoxSceneManager.h
|
||||||
|
include/RegionGeometry.h
|
||||||
include/SurfaceEdge.h
|
include/SurfaceEdge.h
|
||||||
include/SurfaceTypes.h
|
include/SurfaceTypes.h
|
||||||
include/SurfacePatchRenderable.h
|
include/SurfacePatchRenderable.h
|
||||||
|
@ -41,6 +41,13 @@ namespace Ogre
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setData(Type xToSet, Type yToSet, Type zToSet)
|
||||||
|
{
|
||||||
|
x = xToSet;
|
||||||
|
y = yToSet;
|
||||||
|
z = zToSet;
|
||||||
|
}
|
||||||
|
|
||||||
bool operator==(const IntegralVector3<Type>& rhs) const throw()
|
bool operator==(const IntegralVector3<Type>& rhs) const throw()
|
||||||
{
|
{
|
||||||
return ((x == rhs.x) && (y == rhs.y) && (z == rhs.z));
|
return ((x == rhs.x) && (y == rhs.y) && (z == rhs.z));
|
||||||
|
@ -31,6 +31,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||||||
#include "TypeDef.h"
|
#include "TypeDef.h"
|
||||||
#include "Volume.h"
|
#include "Volume.h"
|
||||||
#include "SurfaceVertex.h"
|
#include "SurfaceVertex.h"
|
||||||
|
#include "RegionGeometry.h"
|
||||||
|
|
||||||
#include <set>
|
#include <set>
|
||||||
|
|
||||||
@ -73,7 +74,9 @@ namespace Ogre
|
|||||||
void setNormalGenerationMethod(NormalGenerationMethod method);
|
void setNormalGenerationMethod(NormalGenerationMethod method);
|
||||||
void _findVisibleObjects(Camera* cam, VisibleObjectsBoundsInfo * visibleBounds, bool onlyShadowCasters);
|
void _findVisibleObjects(Camera* cam, VisibleObjectsBoundsInfo * visibleBounds, bool onlyShadowCasters);
|
||||||
|
|
||||||
void setAllUpToDateFalse(void);
|
std::list<RegionGeometry> getChangedRegionGeometry(void);
|
||||||
|
|
||||||
|
void setAllUpToDateFlagsTo(bool newUpToDateValue);
|
||||||
void createSphereAt(Vector3 centre, Real radius, uchar value, bool painting);
|
void createSphereAt(Vector3 centre, Real radius, uchar value, bool painting);
|
||||||
|
|
||||||
bool loadScene(const String& filename);
|
bool loadScene(const String& filename);
|
||||||
|
41
include/RegionGeometry.h
Normal file
41
include/RegionGeometry.h
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
/******************************************************************************
|
||||||
|
This file is part of a voxel plugin for OGRE
|
||||||
|
Copyright (C) 2006 David Williams
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU General Public License
|
||||||
|
as published by the Free Software Foundation; either version 2
|
||||||
|
of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
#ifndef __RegionGeometry_H__
|
||||||
|
#define __RegionGeometry_H__
|
||||||
|
|
||||||
|
#include "IndexedSurfacePatch.h"
|
||||||
|
#include "IntegralVector3.h"
|
||||||
|
|
||||||
|
namespace Ogre
|
||||||
|
{
|
||||||
|
class RegionGeometry
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
RegionGeometry(){};
|
||||||
|
|
||||||
|
bool m_bIsEmpty;
|
||||||
|
UIntVector3 m_v3dRegionPosition;
|
||||||
|
IndexedSurfacePatch* m_patchSingleMaterial;
|
||||||
|
IndexedSurfacePatch* m_patchMultiMaterial;
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
@ -29,6 +29,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||||||
#include "OgreStringConverter.h"
|
#include "OgreStringConverter.h"
|
||||||
#include "OgreLogManager.h"
|
#include "OgreLogManager.h"
|
||||||
|
|
||||||
|
#include <list>
|
||||||
|
|
||||||
namespace Ogre
|
namespace Ogre
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -130,48 +132,35 @@ namespace Ogre
|
|||||||
{
|
{
|
||||||
if(!volumeData.isNull())
|
if(!volumeData.isNull())
|
||||||
{
|
{
|
||||||
unsigned long triangleCounter = 0;
|
std::list<RegionGeometry> listChangedRegionGeometry = getChangedRegionGeometry();
|
||||||
//Regenerate meshes.
|
|
||||||
for(uint regionZ = 0; regionZ < OGRE_VOLUME_SIDE_LENGTH_IN_REGIONS; ++regionZ)
|
for(std::list<RegionGeometry>::iterator iterRegionGeometry = listChangedRegionGeometry.begin(); iterRegionGeometry != listChangedRegionGeometry.end(); iterRegionGeometry++)
|
||||||
{
|
{
|
||||||
//LogManager::getSingleton().logMessage("regionZ = " + StringConverter::toString(regionZ));
|
std::string location("");
|
||||||
for(uint regionY = 0; regionY < OGRE_VOLUME_SIDE_LENGTH_IN_REGIONS; ++regionY)
|
location = location + "(" + iterRegionGeometry->m_v3dRegionPosition.x + "," + iterRegionGeometry->m_v3dRegionPosition.y + "," + iterRegionGeometry->m_v3dRegionPosition.z + ")";
|
||||||
{
|
|
||||||
//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();
|
|
||||||
|
|
||||||
//Generate the surface
|
//Generate the surface
|
||||||
IndexedSurfacePatch* singleMaterialPatch = new IndexedSurfacePatch(false);
|
IndexedSurfacePatch* singleMaterialPatch = iterRegionGeometry->m_patchSingleMaterial;
|
||||||
IndexedSurfacePatch* multiMaterialPatch = new IndexedSurfacePatch(true);
|
IndexedSurfacePatch* multiMaterialPatch = iterRegionGeometry->m_patchMultiMaterial;
|
||||||
|
|
||||||
generateMeshDataForRegion(regionX,regionY,regionZ, singleMaterialPatch, multiMaterialPatch);
|
|
||||||
|
|
||||||
if((singleMaterialPatch->m_vecVertices.size() == 0) && (singleMaterialPatch->m_vecTriangleIndices.size() == 0))
|
if((singleMaterialPatch->m_vecVertices.size() == 0) && (singleMaterialPatch->m_vecTriangleIndices.size() == 0))
|
||||||
{
|
{
|
||||||
//No geometry exists. We can delete the scene node if it exists
|
//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())
|
if(iterSceneNode != sceneNodes.end())
|
||||||
{
|
{
|
||||||
getRootSceneNode()->removeChild(location);
|
getRootSceneNode()->removeChild(location);
|
||||||
}
|
}
|
||||||
surfaceUpToDate[regionX][regionY][regionZ] = true;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
//If a SceneNode doesn't exist in this position then create one.
|
//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;
|
SceneNode* sceneNode;
|
||||||
if(iterSceneNode == sceneNodes.end())
|
if(iterSceneNode == sceneNodes.end())
|
||||||
{
|
{
|
||||||
sceneNode = getRootSceneNode()->createChildSceneNode(location, Vector3(regionX*OGRE_REGION_SIDE_LENGTH,regionY*OGRE_REGION_SIDE_LENGTH,regionZ*OGRE_REGION_SIDE_LENGTH));
|
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(UIntVector3(regionX,regionY,regionZ),sceneNode));
|
sceneNodes.insert(std::make_pair(iterRegionGeometry->m_v3dRegionPosition, sceneNode));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -179,17 +168,8 @@ namespace Ogre
|
|||||||
sceneNode->detachAllObjects();
|
sceneNode->detachAllObjects();
|
||||||
}
|
}
|
||||||
|
|
||||||
//For each surface attach it to the scene node.
|
SurfacePatchRenderable* singleMaterialSurfacePatchRenderable = m_singleMaterialSurfaces[iterRegionGeometry->m_v3dRegionPosition.x][iterRegionGeometry->m_v3dRegionPosition.y][iterRegionGeometry->m_v3dRegionPosition.z];
|
||||||
//for(uint meshCt = 1; meshCt < 256; ++meshCt)
|
SurfacePatchRenderable* multiMaterialSurfacePatchRenderable = m_multiMaterialSurfaces[iterRegionGeometry->m_v3dRegionPosition.x][iterRegionGeometry->m_v3dRegionPosition.y][iterRegionGeometry->m_v3dRegionPosition.z];
|
||||||
//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];
|
|
||||||
if(singleMaterialSurfacePatchRenderable == 0) //if single is null then multi should also be null
|
if(singleMaterialSurfacePatchRenderable == 0) //if single is null then multi should also be null
|
||||||
{
|
{
|
||||||
//We have to create the surfaces
|
//We have to create the surfaces
|
||||||
@ -199,10 +179,10 @@ namespace Ogre
|
|||||||
multiMaterialSurfacePatchRenderable->setRenderQueueGroup(RENDER_QUEUE_3);
|
multiMaterialSurfacePatchRenderable->setRenderQueueGroup(RENDER_QUEUE_3);
|
||||||
singleMaterialSurfacePatchRenderable->setRenderQueueGroup(RENDER_QUEUE_4);
|
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);
|
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);
|
sceneNode->attachObject(multiMaterialSurfacePatchRenderable);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -215,14 +195,11 @@ namespace Ogre
|
|||||||
sceneNode->attachObject(multiMaterialSurfacePatchRenderable);
|
sceneNode->attachObject(multiMaterialSurfacePatchRenderable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//sceneNode->showBoundingBox(true);
|
|
||||||
surfaceUpToDate[regionX][regionY][regionZ] = true;
|
setAllUpToDateFlagsTo(true);
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//LogManager::getSingleton().logMessage("No of tris = " + StringConverter::toString(triangleCounter));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//showBoundingBoxes(true);
|
//showBoundingBoxes(true);
|
||||||
|
|
||||||
//Now call the base class to do the actual visibility determination...
|
//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));
|
//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)
|
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)
|
for(uint blockX = 0; blockX < OGRE_VOLUME_SIDE_LENGTH_IN_REGIONS; ++blockX)
|
||||||
{
|
{
|
||||||
surfaceUpToDate[blockX][blockY][blockZ] = false;
|
surfaceUpToDate[blockX][blockY][blockZ] = newUpToDateValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user