1
/*-------------------------------------------------------------------------------------
2
Copyright (c) 2006 John Judnich
4
This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software.
5
Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:
6
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
7
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
8
3. This notice may not be removed or altered from any source distribution.
9
-------------------------------------------------------------------------------------*/
12
//A "lightweight" version of Ogre::StaticGeometry, which gives you a little more control
13
//over the batch materials, etc.
14
//-------------------------------------------------------------------------------------
16
#ifndef __BatchedGeometry_H__
17
#define __BatchedGeometry_H__
19
#include <OgrePrerequisites.h>
20
#include <OgreMovableObject.h>
21
#include <OgreSceneNode.h>
22
#include <OgreMaterialManager.h>
24
namespace PagedGeometry {
26
class BatchedGeometry: public Ogre::MovableObject
29
BatchedGeometry(Ogre::SceneManager *mgr, Ogre::SceneNode *rootSceneNode);
32
void addEntity(Ogre::Entity *ent, const Ogre::Vector3 &position, const Ogre::Quaternion &orientation = Ogre::Quaternion::IDENTITY, const Ogre::Vector3 &scale = Ogre::Vector3::UNIT_SCALE, const Ogre::ColourValue &color = Ogre::ColourValue::White);
36
Ogre::Vector3 _convertToLocal(const Ogre::Vector3 &globalVec) const;
38
void _notifyCurrentCamera(Ogre::Camera *cam);
39
void _updateRenderQueue(Ogre::RenderQueue *queue);
41
const Ogre::AxisAlignedBox &getBoundingBox(void) const { return bounds; }
42
Ogre::Real getBoundingRadius(void) const { return radius; }
43
const Ogre::String &getMovableType(void) const { static Ogre::String t = "BatchedGeometry"; return t; }
45
#if OGRE_VERSION_MAJOR == 1 && OGRE_VERSION_MINOR > 4
46
//Shaggoth compatibility
47
void visitRenderables(Ogre::Renderable::Visitor* visitor, bool debugRenderables) {}
50
class SubBatch: public Ogre::Renderable
53
SubBatch(BatchedGeometry *parent, Ogre::SubEntity *ent);
56
void addSubEntity(Ogre::SubEntity *ent, const Ogre::Vector3 &position, const Ogre::Quaternion &orientation, const Ogre::Vector3 &scale, const Ogre::ColourValue &color = Ogre::ColourValue::White);
60
void setMaterial(Ogre::MaterialPtr &mat) { material = mat; }
61
void setMaterialName(const Ogre::String &mat) { material = Ogre::MaterialManager::getSingleton().getByName(mat); }
62
inline Ogre::String getMaterialName() const { return material->getName(); }
64
void addSelfToRenderQueue(Ogre::RenderQueue *queue, Ogre::uint8 group);
65
void getRenderOperation(Ogre::RenderOperation& op);
66
Ogre::Real getSquaredViewDepth(const Ogre::Camera* cam) const;
67
const Ogre::LightList& getLights(void) const;
69
Ogre::Technique *getTechnique() const { return bestTechnqiue; }
70
const Ogre::MaterialPtr &getMaterial(void) const { return material; }
71
void getWorldTransforms(Ogre::Matrix4* xform) const { *xform = parent->_getParentNodeFullTransform(); }
72
const Ogre::Quaternion& getWorldOrientation(void) const { return parent->sceneNode->_getDerivedOrientation(); }
73
const Ogre::Vector3& getWorldPosition(void) const { return parent->sceneNode->_getDerivedPosition(); }
74
bool castsShadows(void) const { return parent->getCastShadows(); }
77
//This function is used to make a single clone of materials used, since the materials
78
//will be modified by the batch system (and it wouldn't be good to modify the original materials
79
//that the user may be using somewhere else).
80
Ogre::Material *getMaterialClone(Ogre::Material *mat);
82
//A structure defining the desired position/orientation/scale of a batched mesh. The
83
//SubMesh is not specified since that can be determined by which MeshQueue this belongs to.
87
Ogre::Vector3 position;
88
Ogre::Quaternion orientation;
90
Ogre::ColourValue color;
95
Ogre::VertexData *vertexData;
96
Ogre::IndexData *indexData;
98
Ogre::SubMesh *meshType;
99
BatchedGeometry *parent;
100
Ogre::MaterialPtr material;
101
Ogre::Technique *bestTechnqiue; //This is recalculated every frame
103
typedef std::vector<QueuedMesh>::iterator MeshQueueIterator;
104
typedef std::vector<QueuedMesh> MeshQueue;
105
MeshQueue meshQueue; //The list of meshes to be added to this batch
109
Ogre::String getFormatString(Ogre::SubEntity *ent);
111
typedef std::map<Ogre::String, SubBatch*> SubBatchMap; //Stores a list of GeomBatch'es, using a format string (generated with getGeometryFormatString()) as the key value
112
SubBatchMap subBatchMap;
114
Ogre::Vector3 center;
115
Ogre::AxisAlignedBox bounds;
116
bool boundsUndefined;
119
Ogre::SceneManager *sceneMgr;
120
Ogre::SceneNode *sceneNode, *parentSceneNode;
122
Ogre::Real minDistanceSquared;
123
bool withinFarDistance;
128
typedef Ogre::MapIterator<SubBatchMap> SubBatchIterator;
129
SubBatchIterator getSubBatchIterator() const;