From 1e3904098a84ec9087989f5458b298ec6e2d0c3a Mon Sep 17 00:00:00 2001 From: David Williams Date: Mon, 4 Feb 2008 19:30:57 +0000 Subject: [PATCH] Moved SurfacePatchRenderable to main application. --- CMakeLists.txt | 2 - include/IndexedSurfacePatch.h | 3 +- include/PolyVoxSceneManager.h | 1 - include/SurfacePatchRenderable.h | 56 --------- include/SurfaceVertex.h | 4 +- source/SurfacePatchRenderable.cpp | 198 ------------------------------ 6 files changed, 5 insertions(+), 259 deletions(-) delete mode 100644 include/SurfacePatchRenderable.h delete mode 100644 source/SurfacePatchRenderable.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 1d2ab837..a5fe9a2d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,6 @@ SET(SRC_FILES source/MarchingCubesTables.cpp source/PolyVoxSceneManager.cpp source/SurfaceEdge.cpp - source/SurfacePatchRenderable.cpp source/SurfaceTriangle.cpp source/SurfaceVertex.cpp source/Volume.cpp @@ -25,7 +24,6 @@ SET(INC_FILES include/RegionGeometry.h include/SurfaceEdge.h include/SurfaceTypes.h - include/SurfacePatchRenderable.h include/SurfaceTriangle.h include/SurfaceVertex.h include/TypeDef.h diff --git a/include/IndexedSurfacePatch.h b/include/IndexedSurfacePatch.h index 963540d9..56c75f50 100644 --- a/include/IndexedSurfacePatch.h +++ b/include/IndexedSurfacePatch.h @@ -8,12 +8,13 @@ #include "IntegralVector3.h" #include "SurfaceTypes.h" #include "SurfaceVertex.h" +#include "TypeDef.h" #include "VolumeIterator.h" namespace Ogre { - class IndexedSurfacePatch + class VOXEL_SCENE_MANAGER_API IndexedSurfacePatch { public: IndexedSurfacePatch(bool allowDuplicateVertices); diff --git a/include/PolyVoxSceneManager.h b/include/PolyVoxSceneManager.h index d9018d36..71afb071 100644 --- a/include/PolyVoxSceneManager.h +++ b/include/PolyVoxSceneManager.h @@ -24,7 +24,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "Constants.h" #include "IndexedSurfacePatch.h" -#include "SurfacePatchRenderable.h" #include "SurfaceTriangle.h" //#include "AbstractSurfacePatch.h" #include "TypeDef.h" diff --git a/include/SurfacePatchRenderable.h b/include/SurfacePatchRenderable.h deleted file mode 100644 index 15ebcd4e..00000000 --- a/include/SurfacePatchRenderable.h +++ /dev/null @@ -1,56 +0,0 @@ -#ifndef __SurfacePatchRenderable_H__ -#define __SurfacePatchRenderable_H__ - -#include "Ogre.h" -#include - -//#include "AbstractSurfacePatch.h" -//#include "SurfaceTriangle.h" -//#include "SurfaceVertex.h" - -#include "IndexedSurfacePatch.h" - -namespace Ogre -{ - //IDEA - If profiling identifies this class as a bottleneck, we could implement a memory pooling system. - //All buffers could be powers of two, and we get the smallest one which is big enough for our needs. - //See http://www.ogre3d.org/wiki/index.php/DynamicGrowingBuffers - class VOXEL_SCENE_MANAGER_API SurfacePatchRenderable : public SimpleRenderable - { - public: - SurfacePatchRenderable(const String& name); - ~SurfacePatchRenderable(void); - - void setInitialSurfacePatch(IndexedSurfacePatch* patchToRender, const String& material = "BaseWhiteNoLighting"); - void updateWithNewSurfacePatch(IndexedSurfacePatch* patchToRender); - - void setGeometry(IndexedSurfacePatch* patchToRender); - - Real getSquaredViewDepth(const Camera *cam) const; - Real getBoundingRadius(void) const; - - virtual const String& getMovableType(void) const; - protected: - //void getWorldTransforms(Matrix4 *xform) const; - const Quaternion &getWorldOrientation(void) const; - const Vector3 &getWorldPosition(void) const; - }; - - /** Factory object for creating Light instances */ - class VOXEL_SCENE_MANAGER_API SurfacePatchRenderableFactory : public MovableObjectFactory - { - protected: - MovableObject* createInstanceImpl( const String& name, const NameValuePairList* params); - public: - SurfacePatchRenderableFactory() {} - ~SurfacePatchRenderableFactory() {} - - static String FACTORY_TYPE_NAME; - - const String& getType(void) const; - void destroyInstance( MovableObject* obj); - - }; -} - -#endif /* __SurfacePatchRenderable_H__ */ diff --git a/include/SurfaceVertex.h b/include/SurfaceVertex.h index 15c69f8e..23a53301 100644 --- a/include/SurfaceVertex.h +++ b/include/SurfaceVertex.h @@ -20,6 +20,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #ifndef __SurfaceVertex_H__ #define __SurfaceVertex_H__ +#include "TypeDef.h" + #include "OgrePrerequisites.h" #include "OgreVector3.h" @@ -28,7 +30,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. namespace Ogre { - class SurfaceVertex + class VOXEL_SCENE_MANAGER_API SurfaceVertex { public: SurfaceVertex(); diff --git a/source/SurfacePatchRenderable.cpp b/source/SurfacePatchRenderable.cpp deleted file mode 100644 index a0ada0d9..00000000 --- a/source/SurfacePatchRenderable.cpp +++ /dev/null @@ -1,198 +0,0 @@ -#include "SurfacePatchRenderable.h" - -#include "SurfaceEdge.h" -#include "SurfaceVertex.h" -#include "OgreVertexIndexData.h" - -#include - -namespace Ogre -{ - SurfacePatchRenderable::SurfacePatchRenderable(const String& name) - :SimpleRenderable(name) - { - //Set up what we can of the vertex data - mRenderOp.vertexData = new VertexData(); - mRenderOp.vertexData->vertexStart = 0; - mRenderOp.vertexData->vertexCount = 0; - mRenderOp.operationType = RenderOperation::OT_TRIANGLE_LIST; - - //Set up what we can of the index data - mRenderOp.indexData = new IndexData(); - mRenderOp.useIndexes = true; - mRenderOp.indexData->indexStart = 0; - mRenderOp.indexData->indexCount = 0; - - //Set up the vertex declaration - VertexDeclaration *decl = mRenderOp.vertexData->vertexDeclaration; - decl->removeAllElements(); - decl->addElement(0, 0, VET_FLOAT3, VES_POSITION); - decl->addElement(0, 3 * sizeof(float), VET_FLOAT3, VES_NORMAL); - decl->addElement(0, 6 * sizeof(float), VET_FLOAT2, VES_TEXTURE_COORDINATES); - - } - - SurfacePatchRenderable::~SurfacePatchRenderable(void) - { - delete mRenderOp.vertexData; - delete mRenderOp.indexData; - } - - void SurfacePatchRenderable::setInitialSurfacePatch(IndexedSurfacePatch* patchToRender, const String& material) - { - this->setMaterial(material); - - setGeometry(patchToRender); - } - - void SurfacePatchRenderable::updateWithNewSurfacePatch(IndexedSurfacePatch* patchToRender) - { - setGeometry(patchToRender); - } - - void SurfacePatchRenderable::setGeometry(IndexedSurfacePatch* patchToRender) - { - std::vector vecVertices; - std::vector vecIndices; - patchToRender->fillVertexAndIndexData(vecVertices,vecIndices); - - //LogManager::getSingleton().logMessage("No of Vertices = " + StringConverter::toString(vecVertices.size())); - //LogManager::getSingleton().logMessage("No of Indices = " + StringConverter::toString(vecIndices.size())); - - //Initialization stuff - mRenderOp.vertexData->vertexCount = vecVertices.size(); - mRenderOp.indexData->indexCount = vecIndices.size(); - - VertexBufferBinding *bind = mRenderOp.vertexData->vertexBufferBinding; - - HardwareVertexBufferSharedPtr vbuf = - HardwareBufferManager::getSingleton().createVertexBuffer( - mRenderOp.vertexData->vertexDeclaration->getVertexSize(0), - mRenderOp.vertexData->vertexCount, - HardwareBuffer::HBU_STATIC_WRITE_ONLY, - false); - - bind->setBinding(0, vbuf); - - HardwareIndexBufferSharedPtr ibuf = - HardwareBufferManager::getSingleton().createIndexBuffer( - HardwareIndexBuffer::IT_16BIT, // type of index - mRenderOp.indexData->indexCount, // number of indexes - HardwareBuffer::HBU_STATIC_WRITE_ONLY, // usage - false); // no shadow buffer - - mRenderOp.indexData->indexBuffer = ibuf; - - // Drawing stuff - Vector3 vaabMin(std::numeric_limits::max(),std::numeric_limits::max(),std::numeric_limits::max()); - Vector3 vaabMax(0.0,0.0,0.0); - - Real *prPos = static_cast(vbuf->lock(HardwareBuffer::HBL_DISCARD)); - - for(std::vector::iterator vertexIter = vecVertices.begin(); vertexIter != vecVertices.end(); ++vertexIter) - { - *prPos++ = vertexIter->getPosition().x/2.0f; - *prPos++ = vertexIter->getPosition().y/2.0f; - *prPos++ = vertexIter->getPosition().z/2.0f; - - *prPos++ = vertexIter->getNormal().x; - *prPos++ = vertexIter->getNormal().y; - *prPos++ = vertexIter->getNormal().z; - - *prPos++ = vertexIter->getMaterial(); - - *prPos++ = vertexIter->getAlpha(); - - if(vertexIter->getPosition().x < vaabMin.x) - vaabMin.x = vertexIter->getPosition().x; - if(vertexIter->getPosition().y < vaabMin.y) - vaabMin.y = vertexIter->getPosition().y; - if(vertexIter->getPosition().z < vaabMin.z) - vaabMin.z = vertexIter->getPosition().z; - - if(vertexIter->getPosition().x > vaabMax.x) - vaabMax.x = vertexIter->getPosition().x; - if(vertexIter->getPosition().y > vaabMax.y) - vaabMax.y = vertexIter->getPosition().y; - if(vertexIter->getPosition().z > vaabMax.z) - vaabMax.z = vertexIter->getPosition().z; - } - - vbuf->unlock(); - - vaabMin /= 2.0f; - vaabMax /= 2.0f; - mBox.setExtents(vaabMin, vaabMax); - - unsigned short* pIdx = static_cast(ibuf->lock(HardwareBuffer::HBL_DISCARD)); - //for(int i = 0; i < indexData.size(); i++) - for(std::vector::iterator indexIter = vecIndices.begin(); indexIter != vecIndices.end(); ++indexIter) - { - //*pIdx = indexData[i]; - *pIdx = *indexIter; - pIdx++; - } - - ibuf->unlock(); - } - - Real SurfacePatchRenderable::getSquaredViewDepth(const Camera *cam) const - { - Vector3 vMin, vMax, vMid, vDist; - vMin = mBox.getMinimum(); - vMax = mBox.getMaximum(); - vMid = ((vMin - vMax) * 0.5) + vMin; - vDist = cam->getDerivedPosition() - vMid; - - return vDist.squaredLength(); - } - - Real SurfacePatchRenderable::getBoundingRadius(void) const - { - return Math::Sqrt((std::max)(mBox.getMaximum().squaredLength(), mBox.getMinimum().squaredLength())); - //return mRadius; - } - /* - void Line3D::getWorldTransforms(Matrix4 *xform) const - { - // return identity matrix to prevent parent transforms - *xform = Matrix4::IDENTITY; - } - */ - const Quaternion &SurfacePatchRenderable::getWorldOrientation(void) const - { - return Quaternion::IDENTITY; - } - - const Vector3 &SurfacePatchRenderable::getWorldPosition(void) const - { - return Vector3::ZERO; - } - - const String& SurfacePatchRenderable::getMovableType(void) const - { - static String movType = "SurfacePatchRenderable"; - return movType; - } - - //----------------------------------------------------------------------- - String SurfacePatchRenderableFactory::FACTORY_TYPE_NAME = "SurfacePatchRenderable"; - //----------------------------------------------------------------------- - const String& SurfacePatchRenderableFactory::getType(void) const - { - return FACTORY_TYPE_NAME; - } - //----------------------------------------------------------------------- - MovableObject* SurfacePatchRenderableFactory::createInstanceImpl( const String& name, - const NameValuePairList* params) - { - - return new SurfacePatchRenderable(name); - - } - //----------------------------------------------------------------------- - void SurfacePatchRenderableFactory::destroyInstance( MovableObject* obj) - { - delete obj; - } -}