Moved SurfacePatchRenderable to main application.
This commit is contained in:
parent
d2c87f7bf7
commit
1e3904098a
@ -7,7 +7,6 @@ SET(SRC_FILES
|
|||||||
source/MarchingCubesTables.cpp
|
source/MarchingCubesTables.cpp
|
||||||
source/PolyVoxSceneManager.cpp
|
source/PolyVoxSceneManager.cpp
|
||||||
source/SurfaceEdge.cpp
|
source/SurfaceEdge.cpp
|
||||||
source/SurfacePatchRenderable.cpp
|
|
||||||
source/SurfaceTriangle.cpp
|
source/SurfaceTriangle.cpp
|
||||||
source/SurfaceVertex.cpp
|
source/SurfaceVertex.cpp
|
||||||
source/Volume.cpp
|
source/Volume.cpp
|
||||||
@ -25,7 +24,6 @@ SET(INC_FILES
|
|||||||
include/RegionGeometry.h
|
include/RegionGeometry.h
|
||||||
include/SurfaceEdge.h
|
include/SurfaceEdge.h
|
||||||
include/SurfaceTypes.h
|
include/SurfaceTypes.h
|
||||||
include/SurfacePatchRenderable.h
|
|
||||||
include/SurfaceTriangle.h
|
include/SurfaceTriangle.h
|
||||||
include/SurfaceVertex.h
|
include/SurfaceVertex.h
|
||||||
include/TypeDef.h
|
include/TypeDef.h
|
||||||
|
@ -8,12 +8,13 @@
|
|||||||
#include "IntegralVector3.h"
|
#include "IntegralVector3.h"
|
||||||
#include "SurfaceTypes.h"
|
#include "SurfaceTypes.h"
|
||||||
#include "SurfaceVertex.h"
|
#include "SurfaceVertex.h"
|
||||||
|
#include "TypeDef.h"
|
||||||
#include "VolumeIterator.h"
|
#include "VolumeIterator.h"
|
||||||
|
|
||||||
|
|
||||||
namespace Ogre
|
namespace Ogre
|
||||||
{
|
{
|
||||||
class IndexedSurfacePatch
|
class VOXEL_SCENE_MANAGER_API IndexedSurfacePatch
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
IndexedSurfacePatch(bool allowDuplicateVertices);
|
IndexedSurfacePatch(bool allowDuplicateVertices);
|
||||||
|
@ -24,7 +24,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||||||
|
|
||||||
#include "Constants.h"
|
#include "Constants.h"
|
||||||
#include "IndexedSurfacePatch.h"
|
#include "IndexedSurfacePatch.h"
|
||||||
#include "SurfacePatchRenderable.h"
|
|
||||||
#include "SurfaceTriangle.h"
|
#include "SurfaceTriangle.h"
|
||||||
//#include "AbstractSurfacePatch.h"
|
//#include "AbstractSurfacePatch.h"
|
||||||
#include "TypeDef.h"
|
#include "TypeDef.h"
|
||||||
|
@ -1,56 +0,0 @@
|
|||||||
#ifndef __SurfacePatchRenderable_H__
|
|
||||||
#define __SurfacePatchRenderable_H__
|
|
||||||
|
|
||||||
#include "Ogre.h"
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
//#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__ */
|
|
@ -20,6 +20,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||||||
#ifndef __SurfaceVertex_H__
|
#ifndef __SurfaceVertex_H__
|
||||||
#define __SurfaceVertex_H__
|
#define __SurfaceVertex_H__
|
||||||
|
|
||||||
|
#include "TypeDef.h"
|
||||||
|
|
||||||
#include "OgrePrerequisites.h"
|
#include "OgrePrerequisites.h"
|
||||||
|
|
||||||
#include "OgreVector3.h"
|
#include "OgreVector3.h"
|
||||||
@ -28,7 +30,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||||||
|
|
||||||
namespace Ogre
|
namespace Ogre
|
||||||
{
|
{
|
||||||
class SurfaceVertex
|
class VOXEL_SCENE_MANAGER_API SurfaceVertex
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SurfaceVertex();
|
SurfaceVertex();
|
||||||
|
@ -1,198 +0,0 @@
|
|||||||
#include "SurfacePatchRenderable.h"
|
|
||||||
|
|
||||||
#include "SurfaceEdge.h"
|
|
||||||
#include "SurfaceVertex.h"
|
|
||||||
#include "OgreVertexIndexData.h"
|
|
||||||
|
|
||||||
#include <limits>
|
|
||||||
|
|
||||||
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<SurfaceVertex> vecVertices;
|
|
||||||
std::vector<ushort> 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<Real>::max(),std::numeric_limits<Real>::max(),std::numeric_limits<Real>::max());
|
|
||||||
Vector3 vaabMax(0.0,0.0,0.0);
|
|
||||||
|
|
||||||
Real *prPos = static_cast<Real*>(vbuf->lock(HardwareBuffer::HBL_DISCARD));
|
|
||||||
|
|
||||||
for(std::vector<SurfaceVertex>::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<unsigned short*>(ibuf->lock(HardwareBuffer::HBL_DISCARD));
|
|
||||||
//for(int i = 0; i < indexData.size(); i++)
|
|
||||||
for(std::vector<ushort>::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;
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user