From 247535f4717b789a9158aa94af269c776a31fa0a Mon Sep 17 00:00:00 2001 From: David Williams Date: Sat, 19 Jan 2008 22:39:15 +0000 Subject: [PATCH] Cleaning up _findVisibleObjects. --- include/PolyVoxSceneManager.h | 2 +- source/PolyVoxSceneManager.cpp | 26 ++++++++++++++++---------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/include/PolyVoxSceneManager.h b/include/PolyVoxSceneManager.h index eeea6273..0c50b6be 100644 --- a/include/PolyVoxSceneManager.h +++ b/include/PolyVoxSceneManager.h @@ -95,7 +95,7 @@ namespace Ogre - std::map sceneNodes; + //std::map sceneNodes; bool surfaceUpToDate[OGRE_VOLUME_SIDE_LENGTH_IN_REGIONS][OGRE_VOLUME_SIDE_LENGTH_IN_REGIONS][OGRE_VOLUME_SIDE_LENGTH_IN_REGIONS]; bool regionIsHomogenous[OGRE_VOLUME_SIDE_LENGTH_IN_REGIONS][OGRE_VOLUME_SIDE_LENGTH_IN_REGIONS][OGRE_VOLUME_SIDE_LENGTH_IN_REGIONS]; diff --git a/source/PolyVoxSceneManager.cpp b/source/PolyVoxSceneManager.cpp index 1553d471..8f61d904 100644 --- a/source/PolyVoxSceneManager.cpp +++ b/source/PolyVoxSceneManager.cpp @@ -70,7 +70,7 @@ namespace Ogre ,m_bHaveGeneratedMeshes(false) ,m_axisNode(0) { - sceneNodes.clear(); + //sceneNodes.clear(); } PolyVoxSceneManager::~PolyVoxSceneManager() @@ -139,32 +139,38 @@ namespace Ogre std::string location(""); location = location + "(" + iterRegionGeometry->m_v3dRegionPosition.x + "," + iterRegionGeometry->m_v3dRegionPosition.y + "," + iterRegionGeometry->m_v3dRegionPosition.z + ")"; - //Generate the surface + //Get the surface 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::iterator iterSceneNode = sceneNodes.find(iterRegionGeometry->m_v3dRegionPosition); - if(iterSceneNode != sceneNodes.end()) + try + { + getRootSceneNode()->removeAndDestroyChild(location); + } + catch(...) { - getRootSceneNode()->removeChild(location); } continue; } //If a SceneNode doesn't exist in this position then create one. - std::map::iterator iterSceneNode = sceneNodes.find(iterRegionGeometry->m_v3dRegionPosition); SceneNode* sceneNode; - if(iterSceneNode == sceneNodes.end()) + try + { + sceneNode = dynamic_cast(getRootSceneNode()->getChild(location)); + } + catch(...) + { + sceneNode = 0; + } + if(sceneNode == 0) { 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 { - sceneNode = iterSceneNode->second; sceneNode->detachAllObjects(); }