diff --git a/include/IntegralVector3.h b/include/IntegralVector3.h new file mode 100644 index 00000000..d38d92ae --- /dev/null +++ b/include/IntegralVector3.h @@ -0,0 +1,69 @@ +/****************************************************************************** +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 __IntegralVector3_H__ +#define __IntegralVector3_H__ + +#include + +namespace Ogre +{ + template class IntegralVector3 + { + public: + IntegralVector3(Type xToSet, Type yToSet, Type zToSet) + { + x = xToSet; + y = yToSet; + z = zToSet; + } + + bool operator==(const IntegralVector3& rhs) const throw() + { + return ((x == rhs.x) && (y == rhs.y) && (z == rhs.z)); + } + + bool operator<(const IntegralVector3& rhs) const throw() + { + if(x != rhs.x) + return (x < rhs.x); + else if(y != rhs.y) + return (y < rhs.y); + else if(z != rhs.z) + return (z < rhs.z); + else + return false; //They are equal + } + + Type x; + Type y; + Type z; + }; + + typedef IntegralVector3 CharVector3; + typedef IntegralVector3 ShortVector3; + typedef IntegralVector3 IntVector3; + typedef IntegralVector3 LongVector3; + + typedef IntegralVector3 UCharVector3; + typedef IntegralVector3 UShortVector3; + typedef IntegralVector3 UIntVector3; + typedef IntegralVector3 ULongVector3; +} + +#endif diff --git a/include/PolyVoxSceneManager.h b/include/PolyVoxSceneManager.h index e36a0932..d4001e10 100644 --- a/include/PolyVoxSceneManager.h +++ b/include/PolyVoxSceneManager.h @@ -91,7 +91,8 @@ namespace Ogre - SceneNode* sceneNodes[OGRE_VOLUME_SIDE_LENGTH_IN_REGIONS][OGRE_VOLUME_SIDE_LENGTH_IN_REGIONS][OGRE_VOLUME_SIDE_LENGTH_IN_REGIONS]; + //SceneNode* sceneNodes[OGRE_VOLUME_SIDE_LENGTH_IN_REGIONS][OGRE_VOLUME_SIDE_LENGTH_IN_REGIONS][OGRE_VOLUME_SIDE_LENGTH_IN_REGIONS]; + std::map sceneNodes; std::map m_mapManualObjects[OGRE_VOLUME_SIDE_LENGTH_IN_REGIONS][OGRE_VOLUME_SIDE_LENGTH_IN_REGIONS][OGRE_VOLUME_SIDE_LENGTH_IN_REGIONS]; bool manualObjectUpToDate[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 93eeb3ff..0b1a208f 100644 --- a/source/PolyVoxSceneManager.cpp +++ b/source/PolyVoxSceneManager.cpp @@ -70,7 +70,7 @@ namespace Ogre ,m_normalGenerationMethod(SOBEL) ,m_bHaveGeneratedMeshes(false) { - for(uint regionZ = 0; regionZ < OGRE_VOLUME_SIDE_LENGTH_IN_REGIONS; ++regionZ) + /*for(uint regionZ = 0; regionZ < OGRE_VOLUME_SIDE_LENGTH_IN_REGIONS; ++regionZ) { for(uint regionY = 0; regionY < OGRE_VOLUME_SIDE_LENGTH_IN_REGIONS; ++regionY) { @@ -79,7 +79,8 @@ namespace Ogre sceneNodes[regionX][regionY][regionZ] = 0; } } - } + }*/ + sceneNodes.clear(); } PolyVoxSceneManager::~PolyVoxSceneManager() @@ -142,16 +143,21 @@ namespace Ogre { m_mapManualObjects[blockX][blockY][blockZ].clear(); - if(sceneNodes[blockX][blockY][blockZ] != 0) + /*if(sceneNodes[blockX][blockY][blockZ] != 0) { destroySceneNode(sceneNodes[blockX][blockY][blockZ]->getName()); //FIXME - when it's available in CVS, use destroyAllSceneNodes commented out below. } - sceneNodes[blockX][blockY][blockZ] = getRootSceneNode()->createChildSceneNode(Vector3(blockX*OGRE_REGION_SIDE_LENGTH,blockY*OGRE_REGION_SIDE_LENGTH,blockZ*OGRE_REGION_SIDE_LENGTH));; + sceneNodes[blockX][blockY][blockZ] = getRootSceneNode()->createChildSceneNode(Vector3(blockX*OGRE_REGION_SIDE_LENGTH,blockY*OGRE_REGION_SIDE_LENGTH,blockZ*OGRE_REGION_SIDE_LENGTH)); */ manualObjectUpToDate[blockX][blockY][blockZ] = false; } } } + for(std::map::iterator iterSceneNodes = sceneNodes.begin(); iterSceneNodes != sceneNodes.end(); ++iterSceneNodes) + { + destroySceneNode(iterSceneNodes->second->getName()); //FIXME - when it's available in CVS, use destroyAllSceneNodes commented out below. + } + destroyAllManualObjects(); //destroyAllSceneNodes(); @@ -335,7 +341,18 @@ namespace Ogre std::vector< std::vector< Triangle> > indexData; generateMeshDataForRegion(regionX,regionY,regionZ,vertexData,indexData); - sceneNodes[regionX][regionY][regionZ]->detachAllObjects(); + std::map::iterator iterSceneNode = sceneNodes.find(UIntVector3(regionX,regionY,regionZ)); + SceneNode* sceneNode; + if(iterSceneNode == sceneNodes.end()) + { + sceneNode = getRootSceneNode()->createChildSceneNode(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)); + } + else + { + sceneNode = iterSceneNode->second; + sceneNode->detachAllObjects(); + } for(uint meshCt = 1; meshCt < 256; ++meshCt) { @@ -349,7 +366,7 @@ namespace Ogre //We have to create the surface Surface* surface = new Surface(materialMap->getMaterialAtIndex(meshCt)); - sceneNodes[regionX][regionY][regionZ]->attachObject(surface); + sceneNode->attachObject(surface); m_mapSurfaces[regionX][regionY][regionZ].insert(std::make_pair(meshCt,surface)); @@ -359,7 +376,7 @@ namespace Ogre { //We just update the existing surface iterSurface->second->setGeometry(vertexData,indexData[meshCt]); - sceneNodes[regionX][regionY][regionZ]->attachObject(iterSurface->second); + sceneNode->attachObject(iterSurface->second); //sceneNodes[regionX][regionY][regionZ]->detachObject(iterSurface->second); /*delete iterSurface->second;