Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

Ogre::StaticGeometry Class Reference

Pre-transforms and batches up meshes for efficient use as static geometry in a scene. More...

#include <OgreStaticGeometry.h>

List of all members.

Public Types

typedef std::list< OptimisedSubMeshGeometry * > OptimisedSubMeshGeometryList
typedef std::vector< SubMeshLodGeometryLinkSubMeshLodGeometryLinkList
typedef std::map< SubMesh *,
SubMeshLodGeometryLinkList * > 
SubMeshGeometryLookup
typedef std::vector< QueuedSubMesh * > QueuedSubMeshList
typedef std::vector< QueuedGeometry * > QueuedGeometryList
typedef std::map< uint32,
Region * > 
RegionMap
 Indexed region map based on packed x/y/z region index, 10 bits for each axis.

typedef MapIterator< RegionMapRegionIterator
 Iterator for iterating over contained regions.


Public Member Functions

 StaticGeometry (SceneManager *owner, const String &name)
 Constructor; do not use directly ( SceneManager::createStaticGeometry).

virtual ~StaticGeometry ()
 Destructor.

const StringgetName (void) const
 Get the name of this object.

virtual void addEntity (Entity *ent, const Vector3 &position, const Quaternion &orientation=Quaternion::IDENTITY, const Vector3 &scale=Vector3::UNIT_SCALE)
 Adds an Entity to the static geometry.

virtual void addSceneNode (const SceneNode *node)
 Adds all the Entity objects attached to a SceneNode and all it's children to the static geometry.

virtual void build (void)
 Build the geometry.

virtual void destroy (void)
 Destroys all the built geometry state (reverse of build).

virtual void reset (void)
 Clears any of the entities / nodes added to this geometry and destroys anything which has already been built.

virtual void setRenderingDistance (Real dist)
 Sets the distance at which batches are no longer rendered.

virtual Real getRenderingDistance (void) const
 Gets the distance at which batches are no longer rendered.

virtual Real getSquaredRenderingDistance (void) const
 Gets the squared distance at which batches are no longer rendered.

virtual void setVisible (bool visible)
 Hides or shows all the batches.

virtual bool isVisible (void) const
 Are the batches visible?

virtual void setCastShadows (bool castShadows)
 Sets whether this geometry should cast shadows.

virtual bool getCastShadows (void)
 Will the geometry from this object cast shadows?

virtual void setRegionDimensions (const Vector3 &size)
 Sets the size of a single region of geometry.

virtual const Vector3getRegionDimensions (void) const
 Gets the size of a single batch of geometry.

virtual void setOrigin (const Vector3 &origin)
 Sets the origin of the geometry.

virtual const Vector3getOrigin (void) const
 Gets the origin of this geometry.

virtual void setRenderQueueGroup (uint8 queueID)
 Sets the render queue group this object will be rendered through.

virtual uint8 getRenderQueueGroup (void) const
 Gets the queue group for this entity, see setRenderQueueGroup for full details.

RegionIterator getRegionIterator (void)
 Get an iterator over the regions in this geometry.

virtual void dump (const String &filename) const
 Dump the contents of this StaticGeometry to a file for diagnostic purposes.


Protected Types

typedef std::map< size_t,
size_t > 
IndexRemap

Protected Member Functions

virtual RegiongetRegion (const AxisAlignedBox &bounds, bool autoCreate)
 Virtual method for getting a region most suitable for the passed in bounds.

virtual RegiongetRegion (const Vector3 &point, bool autoCreate)
 Get the region within which a point lies.

virtual RegiongetRegion (ushort x, ushort y, ushort z, bool autoCreate)
 Get the region using indexes.

virtual RegiongetRegion (uint32 index)
 Get the region using a packed index, returns null if it doesn't exist.

virtual void getRegionIndexes (const Vector3 &point, ushort &x, ushort &y, ushort &z)
 Get the region indexes for a point.

virtual uint32 packIndex (ushort x, ushort y, ushort z)
 Pack 3 indexes into a single index value.

virtual Real getVolumeIntersection (const AxisAlignedBox &box, ushort x, ushort y, ushort z)
 Get the volume intersection for an indexed region with some bounds.

virtual AxisAlignedBox getRegionBounds (ushort x, ushort y, ushort z)
 Get the bounds of an indexed region.

virtual Vector3 getRegionCentre (ushort x, ushort y, ushort z)
 Get the centre of an indexed region.

virtual AxisAlignedBox calculateBounds (VertexData *vertexData, const Vector3 &position, const Quaternion &orientation, const Vector3 &scale)
 Calculate world bounds from a set of vertex data.

SubMeshLodGeometryLinkListdetermineGeometry (SubMesh *sm)
 Look up or calculate the geometry data to use for this SubMesh.

void splitGeometry (VertexData *vd, IndexData *id, SubMeshLodGeometryLink *targetGeomLink)
 Split some shared geometry into dedicated geometry.

template<typename T> void buildIndexRemap (T *pBuffer, size_t numIndexes, IndexRemap &remap)
 Method for figuring out which vertices are used by an index buffer and calculating a remap lookup for a vertex buffer just containing those vertices.

template<typename T> void remapIndexes (T *src, T *dst, const IndexRemap &remap, size_t numIndexes)
 Method for altering indexes based on a remap.


Protected Attributes

SceneManagermOwner
String mName
bool mBuilt
Real mUpperDistance
Real mSquaredUpperDistance
bool mCastShadows
Vector3 mRegionDimensions
Vector3 mHalfRegionDimensions
Vector3 mOrigin
bool mVisible
uint8 mRenderQueueID
 The render queue to use when rendering this object.

bool mRenderQueueIDSet
 Flags whether the RenderQueue's default should be used.

QueuedSubMeshList mQueuedSubMeshes
OptimisedSubMeshGeometryList mOptimisedSubMeshGeometryList
 List of geometry which has been optimised for SubMesh use This is the primary storage used for cleaning up later.

SubMeshGeometryLookup mSubMeshGeometryLookup
 Cached links from SubMeshes to (potentially optimised) geometry This is not used for deletion since the lookup may reference original vertex data.

RegionMap mRegionMap
 Map of regions.


Detailed Description

Pre-transforms and batches up meshes for efficient use as static geometry in a scene.

Remarks:
Modern graphics cards (GPUs) prefer to receive geometry in large batches. It is orders of magnitude faster to render 10 batches of 10,000 triangles than it is to render 10,000 batches of 10 triangles, even though both result in the same number of on-screen triangles.
Therefore it is important when you are rendering a lot of geometry to batch things up into as few rendering calls as possible. This class allows you to build a batched object from a series of entities in order to benefit from this behaviour. Batching has implications of it's own though:
In order to retain some sort of culling, this class will batch up meshes in localised regions. The size and shape of these blocks is controlled by the SceneManager which contructs this object, since it makes sense to batch things up in the most appropriate way given the existing partitioning of the scene.
The LOD settings of both the Mesh and the Materials used in constructing this static geometry will be respected. This means that if you use meshes/materials which have LOD, batches in the distance will have a lower polygon count or material detail to those in the foreground. Since each mesh might have different LOD distances, during build the furthest distance at each LOD level from all meshes in that region is used. This means all the LOD levels change at the same time, but at the furthest distance of any of them (so quality is not degraded). Be aware that using Mesh LOD in this class will further increase the memory required. Only generated LOD is supported for meshes.
There are 2 ways you can add geometry to this class; you can add Entity objects directly with predetermined positions, scales and orientations, or you can add an entire SceneNode and it's subtree, including all the objects attached to it. Once you've added everthing you need to, you have to call build() the fix the geometry in place.
Note:
This class is not a replacement for world geometry (
See also:
SceneManager::setWorldGeometry). The single most efficient way to render large amounts of static geometry is to use a SceneManager which is specialised for dealing with that particular world structure. However, this class does provide you with a good 'halfway house' between generalised movable geometry (Entity) which works with all SceneManagers but isn't efficient when using very large numbers, and highly specialised world geometry which is extremely fast but not generic and typically requires custom world editors.
You should not construct instances of this class directly; instead, cal SceneManager::createStaticGeometry, which gives the SceneManager the option of providing you with a specialised version of this class if it wishes, and also handles the memory management for you like other classes.

Definition at line 106 of file OgreStaticGeometry.h.


Member Typedef Documentation

typedef std::map<size_t, size_t> Ogre::StaticGeometry::IndexRemap [protected]
 

Definition at line 526 of file OgreStaticGeometry.h.

Referenced by buildIndexRemap(), and remapIndexes().

typedef std::list<OptimisedSubMeshGeometry*> Ogre::StaticGeometry::OptimisedSubMeshGeometryList
 

Definition at line 133 of file OgreStaticGeometry.h.

typedef std::vector<QueuedGeometry*> Ogre::StaticGeometry::QueuedGeometryList
 

Definition at line 165 of file OgreStaticGeometry.h.

typedef std::vector<QueuedSubMesh*> Ogre::StaticGeometry::QueuedSubMeshList
 

Definition at line 156 of file OgreStaticGeometry.h.

typedef MapIterator<RegionMap> Ogre::StaticGeometry::RegionIterator
 

Iterator for iterating over contained regions.

Definition at line 727 of file OgreStaticGeometry.h.

typedef std::map<uint32, Region*> Ogre::StaticGeometry::RegionMap
 

Indexed region map based on packed x/y/z region index, 10 bits for each axis.

Remarks:
Regions are indexed 0-1023 in all axes, where for example region 0 in the x axis begins at mOrigin.x + (mRegionDimensions.x * -512), and region 1023 ends at mOrigin + (mRegionDimensions.x * 512).

Definition at line 456 of file OgreStaticGeometry.h.

typedef std::map<SubMesh*, SubMeshLodGeometryLinkList*> Ogre::StaticGeometry::SubMeshGeometryLookup
 

Definition at line 142 of file OgreStaticGeometry.h.

typedef std::vector<SubMeshLodGeometryLink> Ogre::StaticGeometry::SubMeshLodGeometryLinkList
 

Definition at line 141 of file OgreStaticGeometry.h.


Constructor & Destructor Documentation

Ogre::StaticGeometry::StaticGeometry SceneManager owner,
const String name
 

Constructor; do not use directly ( SceneManager::createStaticGeometry).

virtual Ogre::StaticGeometry::~StaticGeometry  )  [virtual]
 

Destructor.


Member Function Documentation

virtual void Ogre::StaticGeometry::addEntity Entity ent,
const Vector3 position,
const Quaternion orientation = Quaternion::IDENTITY,
const Vector3 scale = Vector3::UNIT_SCALE
[virtual]
 

Adds an Entity to the static geometry.

Remarks:
This method takes an existing Entity and adds its details to the list of elements to include when building. Note that the Entity itself is not copied or referenced in this method; an Entity is passed simply so that you can change the materials of attached SubEntity objects if you want. You can add the same Entity instance multiple times with different material settings completely safely, and destroy the Entity before destroying this StaticGeometry if you like. The Entity passed in is simply used as a definition.
Note:
Must be called before 'build'.
Parameters:
ent The Entity to use as a definition (the Mesh and Materials referenced will be recorded for the build call).
position The world position at which to add this Entity
orientation The world orientation at which to add this Entity
scale The scale at which to add this entity

virtual void Ogre::StaticGeometry::addSceneNode const SceneNode node  )  [virtual]
 

Adds all the Entity objects attached to a SceneNode and all it's children to the static geometry.

Remarks:
This method performs just like addEntity, except it adds all the entities attached to an entire sub-tree to the geometry. The position / orientation / scale parameters are taken from the node structure instead of being specified manually.
Note:
The SceneNode you pass in will not be automatically detached from it's parent, so if you have this node already attached to the scene graph, you will need to remove it if you wish to avoid the overhead of rendering both the original objects and their new static versions! We don't do this for you incase you are preparing this in advance and so don't want the originals detached yet.

Must be called before 'build'.

Parameters:
node Pointer to the node to use to provide a set of Entity templates

virtual void Ogre::StaticGeometry::build void   )  [virtual]
 

Build the geometry.

Remarks:
Based on all the entities which have been added, and the batching options which have been set, this method constructs the batched geometry structures required. The batches are added to the scene and will be rendered unless you specifically hide them.
Note:
Once you have called this method, you can no longer add any more entities.

template<typename T>
void Ogre::StaticGeometry::buildIndexRemap T *  pBuffer,
size_t  numIndexes,
IndexRemap remap
[protected]
 

Method for figuring out which vertices are used by an index buffer and calculating a remap lookup for a vertex buffer just containing those vertices.

Definition at line 532 of file OgreStaticGeometry.h.

References IndexRemap.

virtual AxisAlignedBox Ogre::StaticGeometry::calculateBounds VertexData vertexData,
const Vector3 position,
const Quaternion orientation,
const Vector3 scale
[protected, virtual]
 

Calculate world bounds from a set of vertex data.

virtual void Ogre::StaticGeometry::destroy void   )  [virtual]
 

Destroys all the built geometry state (reverse of build).

Remarks:
You can call build() again after this and it will pick up all the same entities / nodes you queued last time.

SubMeshLodGeometryLinkList* Ogre::StaticGeometry::determineGeometry SubMesh sm  )  [protected]
 

Look up or calculate the geometry data to use for this SubMesh.

virtual void Ogre::StaticGeometry::dump const String filename  )  const [virtual]
 

Dump the contents of this StaticGeometry to a file for diagnostic purposes.

virtual bool Ogre::StaticGeometry::getCastShadows void   )  [virtual]
 

Will the geometry from this object cast shadows?

Definition at line 677 of file OgreStaticGeometry.h.

const String& Ogre::StaticGeometry::getName void   )  const
 

Get the name of this object.

Definition at line 564 of file OgreStaticGeometry.h.

References Ogre::String.

virtual const Vector3& Ogre::StaticGeometry::getOrigin void   )  const [virtual]
 

Gets the origin of this geometry.

Definition at line 708 of file OgreStaticGeometry.h.

virtual Region* Ogre::StaticGeometry::getRegion uint32  index  )  [protected, virtual]
 

Get the region using a packed index, returns null if it doesn't exist.

virtual Region* Ogre::StaticGeometry::getRegion ushort  x,
ushort  y,
ushort  z,
bool  autoCreate
[protected, virtual]
 

Get the region using indexes.

virtual Region* Ogre::StaticGeometry::getRegion const Vector3 point,
bool  autoCreate
[protected, virtual]
 

Get the region within which a point lies.

virtual Region* Ogre::StaticGeometry::getRegion const AxisAlignedBox bounds,
bool  autoCreate
[protected, virtual]
 

Virtual method for getting a region most suitable for the passed in bounds.

Can be overridden by subclasses.

virtual AxisAlignedBox Ogre::StaticGeometry::getRegionBounds ushort  x,
ushort  y,
ushort  z
[protected, virtual]
 

Get the bounds of an indexed region.

virtual Vector3 Ogre::StaticGeometry::getRegionCentre ushort  x,
ushort  y,
ushort  z
[protected, virtual]
 

Get the centre of an indexed region.

virtual const Vector3& Ogre::StaticGeometry::getRegionDimensions void   )  const [virtual]
 

Gets the size of a single batch of geometry.

Definition at line 694 of file OgreStaticGeometry.h.

virtual void Ogre::StaticGeometry::getRegionIndexes const Vector3 point,
ushort x,
ushort y,
ushort z
[protected, virtual]
 

Get the region indexes for a point.

RegionIterator Ogre::StaticGeometry::getRegionIterator void   ) 
 

Get an iterator over the regions in this geometry.

virtual Real Ogre::StaticGeometry::getRenderingDistance void   )  const [virtual]
 

Gets the distance at which batches are no longer rendered.

Definition at line 646 of file OgreStaticGeometry.h.

References Ogre::Real.

virtual uint8 Ogre::StaticGeometry::getRenderQueueGroup void   )  const [virtual]
 

Gets the queue group for this entity, see setRenderQueueGroup for full details.

virtual Real Ogre::StaticGeometry::getSquaredRenderingDistance void   )  const [virtual]
 

Gets the squared distance at which batches are no longer rendered.

Definition at line 649 of file OgreStaticGeometry.h.

References Ogre::Real.

virtual Real Ogre::StaticGeometry::getVolumeIntersection const AxisAlignedBox box,
ushort  x,
ushort  y,
ushort  z
[protected, virtual]
 

Get the volume intersection for an indexed region with some bounds.

virtual bool Ogre::StaticGeometry::isVisible void   )  const [virtual]
 

Are the batches visible?

Definition at line 656 of file OgreStaticGeometry.h.

virtual uint32 Ogre::StaticGeometry::packIndex ushort  x,
ushort  y,
ushort  z
[protected, virtual]
 

Pack 3 indexes into a single index value.

template<typename T>
void Ogre::StaticGeometry::remapIndexes T *  src,
T *  dst,
const IndexRemap remap,
size_t  numIndexes
[protected]
 

Method for altering indexes based on a remap.

Definition at line 545 of file OgreStaticGeometry.h.

References IndexRemap.

virtual void Ogre::StaticGeometry::reset void   )  [virtual]
 

Clears any of the entities / nodes added to this geometry and destroys anything which has already been built.

virtual void Ogre::StaticGeometry::setCastShadows bool  castShadows  )  [virtual]
 

Sets whether this geometry should cast shadows.

Remarks:
No matter what the settings on the original entities, the StaticGeometry class defaults to not casting shadows. This is because, being static, unless you have moving lights you'd be better to use precalculated shadows of some sort. However, if you need them, you can enable them using this method. If the SceneManager is set up to use stencil shadows, edge lists will be copied from the underlying meshes on build. It is essential that all meshes support stencil shadows in this case.
Note:
If you intend to use stencil shadows, you must set this to true before calling 'build' as well as making sure you set the scene's shadow type (that should always be the first thing you do anyway). You can turn shadows off temporarily but they can never be turned on if they were not at the time of the build.

virtual void Ogre::StaticGeometry::setOrigin const Vector3 origin  )  [virtual]
 

Sets the origin of the geometry.

Remarks:
This method allows you to configure the world centre of the geometry, thus the place which all regions surround. You probably don't need to mess with this unless you have a seriously large world, since the default set up can handle an area 1024 * mRegionDimensions, and the sparseness of population is no issue when it comes to rendering. The default is Vector3(0,0,0).
Note:
Must be called before 'build'.
Parameters:
size Vector3 expressing the 3D origin of the geometry.

Definition at line 706 of file OgreStaticGeometry.h.

virtual void Ogre::StaticGeometry::setRegionDimensions const Vector3 size  )  [virtual]
 

Sets the size of a single region of geometry.

Remarks:
This method allows you to configure the physical world size of each region, so you can balance culling against batch size. Entities will be fitted within the batch they most closely fit, and the eventual bounds of each batch may well be slightly larger than this if they overlap a little. The default is Vector3(1000, 1000, 1000).
Note:
Must be called before 'build'.
Parameters:
size Vector3 expressing the 3D size of each region.

Definition at line 689 of file OgreStaticGeometry.h.

virtual void Ogre::StaticGeometry::setRenderingDistance Real  dist  )  [virtual]
 

Sets the distance at which batches are no longer rendered.

Remarks:
This lets you turn off batches at a given distance. This can be useful for things like detail meshes (grass, foliage etc) and could be combined with a shader which fades the geometry out beforehand to lessen the effect.
Parameters:
dist Distance beyond which the batches will not be rendered (the default is 0, which means batches are always rendered).

Definition at line 640 of file OgreStaticGeometry.h.

References Ogre::Real.

virtual void Ogre::StaticGeometry::setRenderQueueGroup uint8  queueID  )  [virtual]
 

Sets the render queue group this object will be rendered through.

Remarks:
Render queues are grouped to allow you to more tightly control the ordering of rendered objects. If you do not call this method, all objects default to the default queue (RenderQueue::getDefaultQueueGroup), which is fine for most objects. You may want to alter this if you want to perform more complex rendering.
See RenderQueue for more details.
Parameters:
queueID Enumerated value of the queue group to use.

virtual void Ogre::StaticGeometry::setVisible bool  visible  )  [virtual]
 

Hides or shows all the batches.

void Ogre::StaticGeometry::splitGeometry VertexData vd,
IndexData id,
SubMeshLodGeometryLink targetGeomLink
[protected]
 

Split some shared geometry into dedicated geometry.


Member Data Documentation

bool Ogre::StaticGeometry::mBuilt [protected]
 

Definition at line 461 of file OgreStaticGeometry.h.

bool Ogre::StaticGeometry::mCastShadows [protected]
 

Definition at line 464 of file OgreStaticGeometry.h.

Vector3 Ogre::StaticGeometry::mHalfRegionDimensions [protected]
 

Definition at line 466 of file OgreStaticGeometry.h.

String Ogre::StaticGeometry::mName [protected]
 

Definition at line 460 of file OgreStaticGeometry.h.

OptimisedSubMeshGeometryList Ogre::StaticGeometry::mOptimisedSubMeshGeometryList [protected]
 

List of geometry which has been optimised for SubMesh use This is the primary storage used for cleaning up later.

Definition at line 478 of file OgreStaticGeometry.h.

Vector3 Ogre::StaticGeometry::mOrigin [protected]
 

Definition at line 467 of file OgreStaticGeometry.h.

SceneManager* Ogre::StaticGeometry::mOwner [protected]
 

Definition at line 459 of file OgreStaticGeometry.h.

QueuedSubMeshList Ogre::StaticGeometry::mQueuedSubMeshes [protected]
 

Definition at line 474 of file OgreStaticGeometry.h.

Vector3 Ogre::StaticGeometry::mRegionDimensions [protected]
 

Definition at line 465 of file OgreStaticGeometry.h.

RegionMap Ogre::StaticGeometry::mRegionMap [protected]
 

Map of regions.

Definition at line 487 of file OgreStaticGeometry.h.

uint8 Ogre::StaticGeometry::mRenderQueueID [protected]
 

The render queue to use when rendering this object.

Definition at line 470 of file OgreStaticGeometry.h.

bool Ogre::StaticGeometry::mRenderQueueIDSet [protected]
 

Flags whether the RenderQueue's default should be used.

Definition at line 472 of file OgreStaticGeometry.h.

Real Ogre::StaticGeometry::mSquaredUpperDistance [protected]
 

Definition at line 463 of file OgreStaticGeometry.h.

SubMeshGeometryLookup Ogre::StaticGeometry::mSubMeshGeometryLookup [protected]
 

Cached links from SubMeshes to (potentially optimised) geometry This is not used for deletion since the lookup may reference original vertex data.

Definition at line 484 of file OgreStaticGeometry.h.

Real Ogre::StaticGeometry::mUpperDistance [protected]
 

Definition at line 462 of file OgreStaticGeometry.h.

bool Ogre::StaticGeometry::mVisible [protected]
 

Definition at line 468 of file OgreStaticGeometry.h.


The documentation for this class was generated from the following file:

Copyright © 2000-2005 by The OGRE Team
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Mar 12 14:44:40 2006