Moving from using ManualObject to using HardwareBuffers directly.

This commit is contained in:
David Williams 2007-08-14 22:10:33 +00:00
parent 8f70a4edc5
commit 6896e9b7f3
3 changed files with 95 additions and 8 deletions

69
include/IntegralVector3.h Normal file
View File

@ -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 <OgrePrerequisites.h>
namespace Ogre
{
template <typename Type> class IntegralVector3
{
public:
IntegralVector3(Type xToSet, Type yToSet, Type zToSet)
{
x = xToSet;
y = yToSet;
z = zToSet;
}
bool operator==(const IntegralVector3<Type>& rhs) const throw()
{
return ((x == rhs.x) && (y == rhs.y) && (z == rhs.z));
}
bool operator<(const IntegralVector3<Type>& 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<char> CharVector3;
typedef IntegralVector3<short> ShortVector3;
typedef IntegralVector3<int> IntVector3;
typedef IntegralVector3<long> LongVector3;
typedef IntegralVector3<uchar> UCharVector3;
typedef IntegralVector3<ushort> UShortVector3;
typedef IntegralVector3<uint> UIntVector3;
typedef IntegralVector3<ulong> ULongVector3;
}
#endif

View File

@ -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<UIntVector3, SceneNode*> sceneNodes;
std::map<uchar,ManualObject*> 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];

View File

@ -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<UIntVector3, SceneNode*>::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<UIntVector3, SceneNode*>::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;