28 #ifndef __InstancedGeometry_H__
29 #define __InstancedGeometry_H__
206 void copyIndexes(
const T* src, T* dst,
size_t count,
size_t indexOffset)
208 if (indexOffset == 0)
210 memcpy(dst, src,
sizeof(T) * count);
216 *dst++ =
static_cast<T
>(*src++ + indexOffset);
254 void dump(std::ofstream& of)
const;
366 void dump(std::ofstream& of)
const;
420 void dump(std::ofstream& of)
const;
502 bool debugRenderables =
false);
516 void dump(std::ofstream& of)
const;
631 template <
typename T>
635 for (
size_t i = 0; i < numIndexes; ++i)
638 remap.insert(IndexRemap::value_type(*pBuffer++, remap.size()));
644 template <
typename T>
648 for (
size_t i = 0; i < numIndexes; ++i)
651 IndexRemap::const_iterator ix = remap.find(*src++);
652 assert(ix != remap.end());
653 *dst++ =
static_cast<T
>(ix->second);
751 mUpperDistance = dist;
752 mSquaredUpperDistance = mUpperDistance * mUpperDistance;
760 {
return mSquaredUpperDistance; }
800 mBatchInstanceDimensions = size;
801 mHalfBatchInstanceDimensions = size * 0.5;
843 bool debugRenderables =
false);
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
Class encapsulating a set of AnimationState objects.
Represents the state of an animation and the weight of its influence.
A 3D box aligned with the x/y/z axes.
A viewpoint from which the scene will be rendered.
Defines an instance of a discrete, movable object based on a Mesh.
Summary class collecting together index data source information.
The details of a topological BatchInstance which is the highest level of partitioning for this class.
SceneNode * mNode
Scene node.
void attachToScene()
attach the BatchInstance to the scene
void visitRenderables(Renderable::Visitor *visitor, bool debugRenderables=false)
Method to allow a caller to abstractly iterate over the Renderable instances that this MovableObject ...
void setBoundingBox(AxisAlignedBox &box)
bool isVisible(void) const
Returns whether or not this object is supposed to be visible or not.
InstancedObjectIterator getObjectIterator()
uint32 mBatchInstanceID
Unique identifier for the BatchInstance.
void assign(QueuedSubMesh *qmesh)
Assign a queued mesh to this BatchInstance, read for final build.
SceneManager * mSceneMgr
Scene manager link.
vector< LODBucket * >::type LODBucketList
list of LOD Buckets in this BatchInstance
const LodStrategy * mLodStrategy
LOD strategy reference.
ObjectsMap & getInstancesMap(void)
void addInstancedObject(unsigned short index, InstancedObject *object)
const String & getMovableType(void) const
Get the centre point of the BatchInstance.
InstancedGeometry * getParent(void) const
InstancedGeometry * mParent
Parent static geometry.
void updateBoundingBox()
update the bounding box of the BatchInstance according to the positions of the objects
Real getBoundingRadius(void) const
Retrieves the radius of the origin-centered bounding sphere for this object.
map< unsigned short, InstancedObject * >::type ObjectsMap
const LightList & getLights(void) const
Shared set of lights for all GeometryBuckets.
ushort mCurrentLod
The current LOD level, as determined from the last camera.
AxisAlignedBox mAABB
Local AABB relative to BatchInstance centre.
uint32 getID(void) const
Get the BatchInstance ID of this BatchInstance.
Real mSquaredViewDepth
Cached squared view depth value to avoid recalculation by GeometryBucket.
void build()
Build this BatchInstance.
VectorIterator< LODBucketList > LODIterator
QueuedSubMeshList mQueuedSubMeshes
Local list of queued meshes (not used for deallocation)
void dump(std::ofstream &of) const
Dump contents for diagnostics.
void _updateRenderQueue(RenderQueue *queue)
Internal method by which the movable object must add Renderable subclass instances to the rendering q...
LODBucketList mLodBucketList
List of LOD buckets
SceneNode * getSceneNode(void)
Real mBoundingRadius
Local bounding radius.
Mesh::LodValueList mLodValues
LOD values as built up - use the max at each level.
const AxisAlignedBox & getBoundingBox(void) const
Retrieves the local axis-aligned bounding box for this object.
InstancedObject * isInstancedObjectPresent(unsigned short index)
BatchInstance(InstancedGeometry *parent, const String &name, SceneManager *mgr, uint32 BatchInstanceID)
void _notifyCurrentCamera(Camera *cam)
Internal method to notify the object of the camera to be used for the next rendering operation.
Real mLodValue
Current LOD value, passed on to do material LOD later.
LODIterator getLODIterator(void)
Get an iterator over the LODs in this BatchInstance.
MapIterator< ObjectsMap > InstancedObjectIterator
Camera * mCamera
Current camera, passed on to do material LOD later.
void updateContainers(LODBucket *bucket)
fill in the list
A GeometryBucket is a the lowest level bucket where geometry with the same vertex & index format is s...
void _initGeometryBucket(GeometryBucket *bucket)
GeometryBucket(const String &name, MaterialBucket *parent, const String &formatString, GeometryBucket *bucket)
const LightList & getLights(void) const
Gets a list of lights, ordered relative to how close they are to this renderable.
Real getBoundingRadius(void) const
Retrieves the radius of the origin-centered bounding sphere for this object.
void _initGeometryBucket(const VertexData *vData, const IndexData *iData)
InstancedGeometry * mBatch
Pointer to the Batch.
bool assign(QueuedGeometry *qsm)
Try to assign geometry to this bucket.
size_t mMaxVertexIndex
Maximum vertex indexable.
GeometryBucket(const String &name, MaterialBucket *parent, const String &formatString, const VertexData *vData, const IndexData *iData)
IndexData * mIndexData
Index information, includes index type which limits the max number of vertices which are allowed in o...
const MaterialPtr & getMaterial(void) const
Retrieves a weak reference to the material this renderable object uses.
unsigned short mTexCoordIndex
Index of the Texcoord where the index is stored.
String mFormatString
String identifying the vertex / index format.
Real getSquaredViewDepth(const Camera *cam) const
Returns the camera-relative squared depth of this renderable.
GeometryBucket(MaterialBucket *parent, const String &formatString, GeometryBucket *bucket)
void getWorldTransforms(Matrix4 *xform) const
Gets the world transform matrix / matrices for this renderable object.
Technique * getTechnique(void) const
Retrieves a pointer to the Material Technique this renderable object uses.
AxisAlignedBox & getAABB(void)
Return the BoundingBox information. Useful when cloning the batch instance.
HardwareIndexBuffer::IndexType mIndexType
Size of indexes.
String getFormatString(void) const
const VertexData * getVertexData(void) const
Get the vertex data for this geometry.
const IndexData * getIndexData(void) const
Get the index data for this geometry.
MaterialBucket * mParent
Pointer to parent bucket.
MaterialBucket * getParent(void)
VertexData * mVertexData
Vertex information, includes current number of vertices committed to be a part of this bucket.
QueuedGeometryList mQueuedGeometry
Geometry which has been queued up pre-build (not for deallocation)
virtual unsigned short getNumWorldTransforms(void) const
Returns the number of world transform matrices this renderable requires.
void copyIndexes(const T *src, T *dst, size_t count, size_t indexOffset)
virtual ~GeometryBucket()
void visitRenderables(Renderable::Visitor *visitor, bool debugRenderables)
Method to allow a caller to abstractly iterate over the Renderable instances that this MovableObject ...
void dump(std::ofstream &of) const
Dump contents for diagnostics.
bool getCastsShadows(void) const
Method which reports whether this renderable would normally cast a shadow.
GeometryBucket(MaterialBucket *parent, const String &formatString, const VertexData *vData, const IndexData *iData)
const Vector3 & getScale() const
void updateAnimation(void)
void setScale(const Vector3 &scale)
Matrix3 getLocalAxes(void) const
AnimationStateSet * mAnimationState
State of animation for animable meshes.
SkeletonInstance * getSkeletonInstance(void)
Quaternion & getOrientation(void)
void setPositionAndOrientation(Vector3 p, const Quaternion &q)
@ TS_PARENT
Transform is relative to the space of the parent node.
@ TS_LOCAL
Transform is relative to the local space.
void addBucketToList(GeometryBucket *bucket)
void translate(const Matrix3 &axes, const Vector3 &move)
InstancedObject(unsigned short index, SkeletonInstance *skeleton, AnimationStateSet *animations)
Matrix4 * mBoneMatrices
Cached bone matrices in skeleton local space.
void setPosition(Vector3 position)
GeometryBucketList & getGeometryBucketList(void)
unsigned short mNumBoneMatrices
GeometryBucketList mGeometryBucketList
unsigned long mFrameAnimationLastUpdated
Records the last frame in which animation was updated.
InstancedObject(unsigned short index)
Matrix4 * mBoneWorldMatrices
Cached bone matrices, including any world transform.
void setOrientation(const Quaternion &q)
const Vector3 & getPosition(void) const
vector< GeometryBucket * >::type GeometryBucketList
list of Geometry Buckets that contains the instanced object
void roll(const Radian &angle)
SkeletonInstance * mSkeletonInstance
void rotate(const Quaternion &q)
void pitch(const Radian &angle)
AnimationState * getAnimationState(const String &name) const
void translate(const Vector3 &d)
void yaw(const Radian &angle)
A LODBucket is a collection of smaller buckets with the same LOD.
ushort getLod(void) const
Get the LOD index.
void visitRenderables(Renderable::Visitor *visitor, bool debugRenderables)
map< String, MaterialBucket * >::type MaterialBucketMap
Lookup of Material Buckets in this BatchInstance.
MaterialIterator getMaterialIterator(void)
Get an iterator over the materials in this LOD.
MapIterator< MaterialBucketMap > MaterialIterator
Iterator over the materials in this LOD.
Real getLodValue(void) const
Get the LOD value.
BatchInstance * getParent(void)
QueuedGeometryList mQueuedGeometryList
Geometry queued for a single LOD (deallocated here)
LODBucket(BatchInstance *parent, unsigned short lod, Real lodValue)
Real mLodValue
LOD value at which this LOD starts to apply (squared)
BatchInstance * mParent
Pointer to parent BatchInstance.
void dump(std::ofstream &of) const
Dump contents for diagnostics.
void addRenderables(RenderQueue *queue, uint8 group, Real lodValue)
Add children to the render queue.
void assign(QueuedSubMesh *qsm, ushort atLod)
Assign a queued submesh to this bucket, using specified mesh LOD.
void updateContainers(MaterialBucket *bucket, String &name)
fill the map
unsigned short mLod
LOD level (0 == full LOD)
MaterialBucketMap mMaterialBucketMap
Lookup of Material Buckets in this BatchInstance.
A MaterialBucket is a collection of smaller buckets with the same Material (and implicitly the same L...
LODBucket * mParent
Pointer to parent LODBucket.
GeometryBucketList mGeometryBucketList
list of Geometry Buckets in this BatchInstance
GeometryIterator getGeometryIterator(void)
Get an iterator over the contained geometry.
CurrentGeometryMap mCurrentGeometryMap
String mMaterialName
Material being used.
MaterialBucket::CurrentGeometryMap * getMaterialBucketMap(void) const
Return the geometry map.
virtual ~MaterialBucket()
void updateContainers(GeometryBucket *bucket, const String &format)
fill in the map and the list
MaterialPtr mMaterial
Pointer to material being used.
Technique * getCurrentTechnique(void) const
Get the current Technique.
Technique * mTechnique
Active technique.
void setMaterial(const String &name)
MaterialBucket(LODBucket *parent, const String &materialName)
MaterialBucket::GeometryBucketList * getGeometryBucketList(void) const
Return the geometry list.
void setLastIndex(int index)
String getGeometryFormatString(SubMeshLodGeometryLink *geom)
Get a packed string identifying the geometry format.
void dump(std::ofstream &of) const
Dump contents for diagnostics.
map< String, GeometryBucket * >::type CurrentGeometryMap
void assign(QueuedGeometry *qsm)
Assign geometry to this bucket.
void visitRenderables(Renderable::Visitor *visitor, bool debugRenderables)
VectorIterator< GeometryBucketList > GeometryIterator
Iterator over geometry.
void addRenderables(RenderQueue *queue, uint8 group, Real lodValue)
Add children to the render queue.
const MaterialPtr & getMaterial(void) const
Get the material for this bucket.
vector< GeometryBucket * >::type GeometryBucketList
list of Geometry Buckets in this BatchInstance
LODBucket * getParent(void)
const String & getMaterialName(void) const
Get the material name.
Struct holding geometry optimised per SubMesh / LOD level, ready for copying to instances.
OptimisedSubMeshGeometry()
~OptimisedSubMeshGeometry()
Pre-transforms and batches up meshes for efficient use as instanced geometry in a scene.
Real mSquaredUpperDistance
virtual bool getProvideWorldInverses(void) const
const String & getName(void) const
Get the name of this object.
unsigned int mObjectCount
number of objects in the batch
virtual BatchInstance * getBatchInstance(const AxisAlignedBox &bounds, bool autoCreate)
Virtual method for getting a BatchInstance most suitable for the passed in bounds.
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...
bool mProvideWorldInverses
Flags to indicate whether the World Transform Inverse matrices are passed to the shaders.
virtual uint32 packIndex(ushort x, ushort y, ushort z)
Pack 3 indexes into a single index value.
virtual uint8 getRenderQueueGroup(void) const
Gets the queue group for this entity, see setRenderQueueGroup for full details.
MapIterator< BatchInstanceMap > BatchInstanceIterator
Iterator for iterating over contained BatchInstances.
virtual Real getVolumeIntersection(const AxisAlignedBox &box, ushort x, ushort y, ushort z)
Get the volume intersection for an indexed BatchInstance with some bounds.
SkeletonPtr mBaseSkeleton
this is just a pointer to the base skeleton that will be used for each animated object in the batches...
virtual void setBatchInstanceDimensions(const Vector3 &size)
Sets the size of a single BatchInstance of geometry.
virtual bool isVisible(void) const
Are the batches visible?
virtual void setProvideWorldInverses(bool flag)
void addBatchInstance(void)
Add a new batch instance.
void visitRenderables(Renderable::Visitor *visitor, bool debugRenderables=false)
Method to allow a caller to abstractly iterate over the Renderable instances that this MovableObject ...
vector< String >::type QueuedSubMeshOriginList
virtual bool getCastShadows(void)
Will the geometry from this object cast shadows?
map< uint32, BatchInstance * >::type BatchInstanceMap
Indexed BatchInstance map based on packed x/y/z BatchInstance index, 10 bits for each axis.
virtual AxisAlignedBox calculateBounds(VertexData *vertexData, const Vector3 &position, const Quaternion &orientation, const Vector3 &scale)
Calculate world bounds from a set of vertex data.
SkeletonInstance * getBaseSkeletonInstance(void)
virtual const Vector3 & getBatchInstanceDimensions(void) const
Gets the size of a single batch of geometry.
virtual BatchInstance * getBatchInstance(ushort x, ushort y, ushort z, bool autoCreate)
Get the BatchInstance using indexes.
uint8 mRenderQueueID
The render queue to use when rendering this object.
unsigned int getObjectCount(void)
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.
BatchInstance * mInstancedGeometryInstance
virtual Real getRenderingDistance(void) const
Gets the distance at which batches are no longer rendered.
OptimisedSubMeshGeometryList mOptimisedSubMeshGeometryList
List of geometry which has been optimised for SubMesh use This is the primary storage used for cleani...
virtual AxisAlignedBox getBatchInstanceBounds(ushort x, ushort y, ushort z)
Get the bounds of an indexed BatchInstance.
virtual BatchInstance * getBatchInstance(const Vector3 &point, bool autoCreate)
Get the BatchInstance within which a point lies.
SubMeshLodGeometryLinkList * determineGeometry(SubMesh *sm)
Look up or calculate the geometry data to use for this SubMesh.
virtual void getBatchInstanceIndexes(const Vector3 &point, ushort &x, ushort &y, ushort &z)
Get the BatchInstance indexes for a point.
vector< SubMeshLodGeometryLink >::type SubMeshLodGeometryLinkList
virtual void setCastShadows(bool castShadows)
Sets whether this geometry should cast shadows.
SkeletonInstance * mSkeletonInstance
map< size_t, size_t >::type IndexRemap
Vector3 mHalfBatchInstanceDimensions
virtual void setOrigin(const Vector3 &origin)
Sets the origin of the geometry.
RenderOperationVector & getRenderOperationVector()
get the mRenderOps vector.
void splitGeometry(VertexData *vd, IndexData *id, SubMeshLodGeometryLink *targetGeomLink)
Split some shared geometry into dedicated geometry.
virtual void setVisible(bool visible)
Hides or shows all the batches.
bool mRenderQueueIDSet
Flags whether the RenderQueue's default should be used.
InstancedGeometry(SceneManager *owner, const String &name)
Constructor; do not use directly (.
virtual BatchInstance * getBatchInstance(uint32 index)
Get the BatchInstance using a packed index, returns null if it doesn't exist.
virtual void build(void)
Build the geometry.
SkeletonPtr getBaseSkeleton(void)
virtual void reset(void)
Clears any of the entities / nodes added to this geometry and destroys anything which has already bee...
map< SubMesh *, SubMeshLodGeometryLinkList * >::type SubMeshGeometryLookup
virtual const Vector3 & getOrigin(void) const
Gets the origin of this geometry.
vector< QueuedGeometry * >::type QueuedGeometryList
virtual Vector3 getBatchInstanceCentre(ushort x, ushort y, ushort z)
Get the centre of an indexed BatchInstance.
SubMeshGeometryLookup mSubMeshGeometryLookup
Cached links from SubMeshes to (potentially optimised) geometry This is not used for deletion since t...
list< OptimisedSubMeshGeometry * >::type OptimisedSubMeshGeometryList
virtual void destroy(void)
Destroys all the built geometry state (reverse of build).
BatchInstanceIterator getBatchInstanceIterator(void)
Get an iterator over the BatchInstances in this geometry.
BatchInstanceMap mBatchInstanceMap
Map of BatchInstances.
void remapIndexes(T *src, T *dst, const IndexRemap &remap, size_t numIndexes)
Method for altering indexes based on a remap.
vector< QueuedSubMesh * >::type QueuedSubMeshList
AnimationStateSet * mAnimationState
This is the main animation state.
virtual void setRenderQueueGroup(uint8 queueID)
Sets the render queue group this object will be rendered through.
vector< RenderOperation * >::type RenderOperationVector
Simple vectors where are stored all the render operations of the Batch.
AnimationStateSet * getBaseAnimationState(void)
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 setRenderingDistance(Real dist)
Sets 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 ~InstancedGeometry()
Destructor.
QueuedSubMeshList mQueuedSubMeshes
virtual BatchInstance * getInstancedGeometryInstance(void)
get the first BatchInstance or create on if it does not exists.
RenderOperationVector mRenderOps
This vector stores all the renderOperation used in the batch.
virtual void dump(const String &filename) const
Dump the contents of this InstancedGeometry to a file for diagnostic purposes.
Vector3 mBatchInstanceDimensions
Strategy for determining level of detail.
Concrete IteratorWrapper for nonconst access to the underlying key-value container.
A 3x3 matrix which can represent rotations around axes.
Class encapsulating a standard 4x4 homogeneous matrix.
vector< Real >::type LodValueList
Abstract class defining a movable object in a scene.
Implementation of a Quaternion, i.e.
static const Quaternion IDENTITY
Wrapper class which indicates a given angle value is in Radians.
Class to manage the scene object rendering queue.
Visitor object that can be used to iterate over a collection of Renderable instances abstractly.
Manages the organisation and rendering of a 'scene' i.e.
Class representing a node in the scene graph.
Simple implementation of MovableObject and Renderable for single-part custom objects.
A SkeletonInstance is a single instance of a Skeleton used by a world object.
Defines a part of a complete mesh.
Class representing an approach to rendering this particular Material.
Standard 3-dimensional vector.
static const Vector3 UNIT_SCALE
Concrete IteratorWrapper for nonconst access to the underlying container.
Summary class collecting together vertex source information.
float Real
Software floating point type.
Structure recording a queued geometry for low level builds.
SubMeshLodGeometryLink * geometry
Structure recording a queued submesh for the build.
SubMeshLodGeometryLinkList * geometryLodList
Link to LOD list of geometry, potentially optimised.
AxisAlignedBox worldBounds
Pre-transformed world AABB.
Saved link between SubMesh at a LOD and vertex/index data May point to original or optimised geometry...
std::map< K, V, P, A > type