OGRE: Ogre::StaticGeometry Class Reference

| OGRE 14.5 Object-Oriented Graphics Rendering Engine

Loading...
Searching...
No Matches
Ogre::StaticGeometry Class Reference
Core » Scene

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

`#include <OgreStaticGeometry.h>`

Inheritance diagram for Ogre::StaticGeometry:
[legend]

## Classes
class | GeometryBucket
| A GeometryBucket is a the lowest level bucket where geometry with the same vertex & index format is stored. More...
class | LODBucket
| A LODBucket is a collection of smaller buckets with the same LOD. More...
class | MaterialBucket
| A MaterialBucket is a collection of smaller buckets with the same Material (and implicitly the same LOD). More...
class | OptimisedSubMeshGeometry
| Struct holding geometry optimised per SubMesh / LOD level, ready for copying to instances. More...
struct | QueuedGeometry
| Structure recording a queued geometry for low level builds. More...
struct | QueuedSubMesh
| Structure recording a queued submesh for the build. More...
class | Region
| The details of a topological region which is the highest level of partitioning for this class. More...
struct | SubMeshLodGeometryLink
| Saved link between SubMesh at a LOD and vertex/index data May point to original or optimised geometry. More...

## Public Types
typedef std::list< OptimisedSubMeshGeometry * > | OptimisedSubMeshGeometryList
typedef std::vector< QueuedGeometry * > | QueuedGeometryList
typedef std::vector< QueuedSubMesh * > | QueuedSubMeshList
typedef MapIterator< RegionMap > | RegionIterator
| Iterator for iterating over contained regions.
typedef std::map< uint32, Region * > | RegionMap
| Indexed region map based on packed x/y/z region index, 10 bits for each axis.
typedef std::map< SubMesh *, SubMeshLodGeometryLinkList * > | SubMeshGeometryLookup
typedef std::vector< SubMeshLodGeometryLink > | SubMeshLodGeometryLinkList

## Public Member Functions
| StaticGeometry (SceneManager *owner, const String &name)
| You should not construct instances of this class directly; instead, call 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.
virtual | ~StaticGeometry ()
| Destructor.
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.
void | destroy (void)
| Destroys all the built geometry state (reverse of build).
virtual bool | getCastShadows (void)
| Will the geometry from this object cast shadows?
const String & | getName (void) const
| Get the name of this object.
virtual const Vector3 & | getOrigin (void) const
| Gets the origin of this geometry.
virtual const Vector3 & | getRegionDimensions (void) const
| Gets the size of a single batch of geometry.
RegionIterator | getRegionIterator (void)
const RegionMap & | getRegions () const
| Get an list of the regions in this geometry.
virtual Real | getRenderingDistance (void) const
| Gets the distance at which batches are no longer rendered.
virtual uint8 | getRenderQueueGroup (void) const
| Gets the queue group for this entity, see setRenderQueueGroup for full details.
virtual Real | getSquaredRenderingDistance (void) const
| Gets the squared distance at which batches are no longer rendered.
uint32 | getVisibilityFlags () const
| Returns the visibility flags of the regions.
virtual bool | isVisible (void) const
| Are the batches visible?
void | reset (void)
| Clears any of the entities / nodes added to this geometry and destroys anything which has already been built.
virtual void | setCastShadows (bool castShadows)
| Sets whether this geometry should cast shadows.
virtual void | setOrigin (const Vector3 &origin)
| Sets the origin of the geometry.
virtual void | setRegionDimensions (const Vector3 &size)
| Sets the size of a single region of geometry.
virtual void | setRenderingDistance (Real dist)
| Sets the distance at which batches are no longer rendered.
virtual void | setRenderQueueGroup (uint8 queueID)
| Sets the render queue group this object will be rendered through.
void | setVisibilityFlags (uint32 flags)
| Sets the visibility flags of all the regions at once.
virtual void | setVisible (bool visible)
| Hides or shows all the batches.
void | visitRenderables (Renderable::Visitor *visitor, bool debugRenderables=false)
| Method to allow a caller to abstractly iterate over the Renderable instances that this MovableObject will add to the render queue when asked, if any.

## Detailed Description

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

This class allows you to build a batched object from a series of entities. Batching has implications of it's own though:

- Batched geometry cannot be subdivided; that means that the whole group will be displayed, or none of it will. This obivously has culling issues.
- A single world transform must apply to the entire batch. Therefore once you have batched things, you can't move them around relative to each other. That's why this class is most useful when dealing with static geometry (hence the name). In addition, geometry is effectively duplicated, so if you add 3 entities based on the same mesh in different positions, they will use 3 times the geometry space than the movable version (which re-uses the same geometry). So you trade memory and flexibility of movement for pure speed when using this class.
- A single material must apply for each batch. In fact this class allows you to use multiple materials, but you should be aware that internally this means that there is one batch per material. Therefore you won't gain as much benefit from the batching if you use many different materials; try to keep the number down.

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 constructs 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 everything you need to, you have to call build() the fix the geometry in place.

Note
  This class is not a replacement for world geometry (Ogre::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.

Attention
  this class only works with indexed triangle lists at the moment, do not pass it triangle strips, fans or lines / points, or unindexed geometry.

## Member Typedef Documentation

## ◆ OptimisedSubMeshGeometryList

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

## ◆ SubMeshLodGeometryLinkList

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

## ◆ SubMeshGeometryLookup

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

## ◆ QueuedSubMeshList

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

## ◆ QueuedGeometryList

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

## ◆ RegionMap

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

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

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).

## ◆ RegionIterator

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

Iterator for iterating over contained regions.

## Constructor & Destructor Documentation

## ◆ StaticGeometry()

Ogre::StaticGeometry::StaticGeometry | ( | SceneManager * | owner,
|  | const String & | name )

You should not construct instances of this class directly; instead, call 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.

Referenced by Ogre::StaticGeometry::Region::Region(), Ogre::StaticGeometry::Region::getParent(), and operator<<.

## ◆ ~StaticGeometry()

virtual Ogre::StaticGeometry::~StaticGeometry | ( |  | ) |
| virtual

Destructor.

## Member Function Documentation

## ◆ getName()

const String & Ogre::StaticGeometry::getName | ( | void |  | ) | const
| inline

Get the name of this object.

## ◆ addEntity()

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.

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

Attention
  Do not unload the Mesh used by the Entity until after you have called build(), as the geometry is read at that time.

References Ogre::Quaternion::IDENTITY.

## ◆ addSceneNode()

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.

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 in case you are preparing this in advance and so don't want the originals detached yet.
  Must be called before 'build'.

Attention
  Do not unload the Mesh used by the Entities until after you have called build(), as the geometry is read at that time.

Parameters

  node | Pointer to the node to use to provide a set of Entity templates

## ◆ build()

virtual void Ogre::StaticGeometry::build | ( | void |  | ) |
| virtual

Build the geometry.

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.

## ◆ destroy()

void Ogre::StaticGeometry::destroy | ( | void |  | ) |

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

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

## ◆ reset()

void Ogre::StaticGeometry::reset | ( | void |  | ) |

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

## ◆ setRenderingDistance()

virtual void Ogre::StaticGeometry::setRenderingDistance | ( | Real | dist | ) |
| inlinevirtual

Sets the distance at which batches are no longer rendered.

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).

## ◆ getRenderingDistance()

virtual Real Ogre::StaticGeometry::getRenderingDistance | ( | void |  | ) | const
| inlinevirtual

Gets the distance at which batches are no longer rendered.

## ◆ getSquaredRenderingDistance()

virtual Real Ogre::StaticGeometry::getSquaredRenderingDistance | ( | void |  | ) | const
| inlinevirtual

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

## ◆ setVisible()

virtual void Ogre::StaticGeometry::setVisible | ( | bool | visible | ) |
| virtual

Hides or shows all the batches.

## ◆ isVisible()

virtual bool Ogre::StaticGeometry::isVisible | ( | void |  | ) | const
| inlinevirtual

Are the batches visible?

## ◆ setCastShadows()

virtual void Ogre::StaticGeometry::setCastShadows | ( | bool | castShadows | ) |
| virtual

Sets whether this geometry should cast shadows.

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.

## ◆ getCastShadows()

virtual bool Ogre::StaticGeometry::getCastShadows | ( | void |  | ) |
| inlinevirtual

Will the geometry from this object cast shadows?

## ◆ setRegionDimensions()

virtual void Ogre::StaticGeometry::setRegionDimensions | ( | const Vector3 & | size | ) |
| inlinevirtual

Sets the size of a single region of geometry.

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.

## ◆ getRegionDimensions()

virtual const Vector3 & Ogre::StaticGeometry::getRegionDimensions | ( | void |  | ) | const
| inlinevirtual

Gets the size of a single batch of geometry.

## ◆ setOrigin()

virtual void Ogre::StaticGeometry::setOrigin | ( | const Vector3 & | origin | ) |
| inlinevirtual

Sets the origin of the geometry.

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

  origin | Vector3 expressing the 3D origin of the geometry.

## ◆ getOrigin()

virtual const Vector3 & Ogre::StaticGeometry::getOrigin | ( | void |  | ) | const
| inlinevirtual

Gets the origin of this geometry.

## ◆ setVisibilityFlags()

void Ogre::StaticGeometry::setVisibilityFlags | ( | uint32 | flags | ) |

Sets the visibility flags of all the regions at once.

## ◆ getVisibilityFlags()

uint32 Ogre::StaticGeometry::getVisibilityFlags | ( |  | ) | const

Returns the visibility flags of the regions.

## ◆ setRenderQueueGroup()

virtual void Ogre::StaticGeometry::setRenderQueueGroup | ( | uint8 | queueID | ) |
| virtual

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

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.

## ◆ getRenderQueueGroup()

virtual uint8 Ogre::StaticGeometry::getRenderQueueGroup | ( | void |  | ) | const
| virtual

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

## ◆ visitRenderables()

void Ogre::StaticGeometry::visitRenderables | ( | Renderable::Visitor * | visitor,
|  | bool | debugRenderables = false )

Method to allow a caller to abstractly iterate over the Renderable instances that this MovableObject will add to the render queue when asked, if any.

Parameters

  visitor | Pointer to a class implementing the Renderable::Visitor interface which will be called back for each Renderable which will be queued. Bear in mind that the state of the Renderable instances may not be finalised depending on when you call this.
  debugRenderables | If false, only regular renderables will be visited (those for normal display). If true, debug renderables will be included too.

## ◆ getRegions()

const RegionMap & Ogre::StaticGeometry::getRegions | ( |  | ) | const
| inline

Get an list of the regions in this geometry.

## ◆ getRegionIterator()

RegionIterator Ogre::StaticGeometry::getRegionIterator | ( | void |  | ) |

Deprecated
  use getRegions()

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

- OgreStaticGeometry.h