[657] | 1 | /*
|
---|
| 2 | -----------------------------------------------------------------------------
|
---|
| 3 | This source file is part of OGRE
|
---|
| 4 | (Object-oriented Graphics Rendering Engine)
|
---|
| 5 | For the latest info, see http://ogre.sourceforge.net/
|
---|
| 6 |
|
---|
| 7 | Copyright (c) 2000-2005 The OGRE Team
|
---|
| 8 | Also see acknowledgements in Readme.html
|
---|
| 9 |
|
---|
| 10 | This program is free software; you can redistribute it and/or modify it under
|
---|
| 11 | the terms of the GNU Lesser General Public License as published by the Free Software
|
---|
| 12 | Foundation; either version 2 of the License, or (at your option) any later
|
---|
| 13 | version.
|
---|
| 14 |
|
---|
| 15 | This program is distributed in the hope that it will be useful, but WITHOUT
|
---|
| 16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
---|
| 17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
---|
| 18 |
|
---|
| 19 | You should have received a copy of the GNU Lesser General Public License along with
|
---|
| 20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
---|
| 21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to
|
---|
| 22 | http://www.gnu.org/copyleft/lesser.txt.
|
---|
| 23 | -----------------------------------------------------------------------------
|
---|
| 24 | */
|
---|
| 25 | #ifndef __Entity_H__
|
---|
| 26 | #define __Entity_H__
|
---|
| 27 |
|
---|
| 28 | #include "OgrePrerequisites.h"
|
---|
| 29 | #include "OgreCommon.h"
|
---|
| 30 |
|
---|
| 31 | #include "OgreString.h"
|
---|
| 32 | #include "OgreMovableObject.h"
|
---|
| 33 | #include "OgreAnimationState.h"
|
---|
| 34 | #include "OgreQuaternion.h"
|
---|
| 35 | #include "OgreVector3.h"
|
---|
| 36 | #include "OgreHardwareBufferManager.h"
|
---|
| 37 | #include "OgreMesh.h"
|
---|
| 38 |
|
---|
| 39 | namespace Ogre {
|
---|
| 40 | /** Defines an instance of a discrete, movable object based on a Mesh.
|
---|
| 41 | @remarks
|
---|
| 42 | Ogre generally divides renderable objects into 2 groups, discrete
|
---|
| 43 | (separate) and relatively small objects which move around the world,
|
---|
| 44 | and large, sprawling geometry which makes up generally immovable
|
---|
| 45 | scenery, aka 'level geometry'.
|
---|
| 46 | @par
|
---|
| 47 | The Mesh and SubMesh classes deal with the definition of the geometry
|
---|
| 48 | used by discrete movable objects. Entities are actual instances of
|
---|
| 49 | objects based on this geometry in the world. Therefore there is
|
---|
| 50 | usually a single set Mesh for a car, but there may be multiple
|
---|
| 51 | entities based on it in the world. Entities are able to override
|
---|
| 52 | aspects of the Mesh it is defined by, such as changing material
|
---|
| 53 | properties per instance (so you can have many cars using the same
|
---|
| 54 | geometry but different textures for example). Because a Mesh is split
|
---|
| 55 | into SubMeshes for this purpose, the Entity class is a grouping class
|
---|
| 56 | (much like the Mesh class) and much of the detail regarding
|
---|
| 57 | individual changes is kept in the SubEntity class. There is a 1:1
|
---|
| 58 | relationship between SubEntity instances and the SubMesh instances
|
---|
| 59 | associated with the Mesh the Entity is based on.
|
---|
| 60 | @par
|
---|
| 61 | Entity and SubEntity classes are never created directly. Use the
|
---|
| 62 | createEntity method of the SceneManager (passing a model name) to
|
---|
| 63 | create one.
|
---|
| 64 | @par
|
---|
| 65 | Entities are included in the scene by associating them with a
|
---|
| 66 | SceneNode, using the attachEntity method. See the SceneNode class
|
---|
| 67 | for full information.
|
---|
| 68 | @note
|
---|
| 69 | No functions were declared virtual to improve performance.
|
---|
| 70 | */
|
---|
| 71 | class _OgreExport Entity: public MovableObject
|
---|
| 72 | {
|
---|
| 73 | // Allow SceneManager full access
|
---|
| 74 | friend class SceneManager;
|
---|
| 75 | friend class SubEntity;
|
---|
| 76 | public:
|
---|
| 77 | typedef std::set<Entity*> EntitySet;
|
---|
| 78 |
|
---|
| 79 | protected:
|
---|
| 80 |
|
---|
| 81 | /** Private constructor (instances cannot be created directly).
|
---|
| 82 | */
|
---|
| 83 | Entity();
|
---|
| 84 | /** Private constructor - specify name (the usual constructor used).
|
---|
| 85 | */
|
---|
| 86 | Entity( const String& name, MeshPtr& mesh, SceneManager* creator);
|
---|
| 87 |
|
---|
| 88 | /** Name of the entity; used for location in the scene.
|
---|
| 89 | */
|
---|
| 90 | String mName;
|
---|
| 91 |
|
---|
| 92 | /** The Mesh that this Entity is based on.
|
---|
| 93 | */
|
---|
| 94 | MeshPtr mMesh;
|
---|
| 95 |
|
---|
| 96 | /** List of SubEntities (point to SubMeshes).
|
---|
| 97 | */
|
---|
| 98 | typedef std::vector<SubEntity*> SubEntityList;
|
---|
| 99 | SubEntityList mSubEntityList;
|
---|
| 100 |
|
---|
| 101 | /** Pointer back to the SceneManager that created this instance, for
|
---|
| 102 | notification purposes.
|
---|
| 103 | */
|
---|
| 104 | SceneManager* mCreatorSceneManager;
|
---|
| 105 |
|
---|
| 106 |
|
---|
| 107 | /// State of animation for animable meshes
|
---|
| 108 | AnimationStateSet* mAnimationState;
|
---|
| 109 |
|
---|
| 110 | /// Shared class-level name for Movable type
|
---|
| 111 | static String msMovableType;
|
---|
| 112 |
|
---|
| 113 |
|
---|
| 114 | /// Temp blend buffer details for shared geometry
|
---|
| 115 | TempBlendedBufferInfo mTempBlendedBuffer;
|
---|
| 116 | /// Temp blend buffer details for shared geometry
|
---|
| 117 | VertexData* mSharedBlendedVertexData;
|
---|
| 118 |
|
---|
| 119 | /** Internal method - given vertex data which could be from the Mesh or
|
---|
| 120 | any submesh, finds the temporary blend copy. */
|
---|
| 121 | const VertexData* findBlendedVertexData(const VertexData* orig);
|
---|
| 122 | /** Internal method - given vertex data which could be from the Mesh or
|
---|
| 123 | any SubMesh, finds the corresponding SubEntity. */
|
---|
| 124 | SubEntity* findSubEntityForVertexData(const VertexData* orig);
|
---|
| 125 |
|
---|
| 126 | /** Internal method for extracting metadata out of source vertex data
|
---|
| 127 | for fast assignment of temporary buffers later. */
|
---|
| 128 | void extractTempBufferInfo(VertexData* sourceData, TempBlendedBufferInfo* info);
|
---|
| 129 | /** Internal method to clone vertex data definitions but to remove blend buffers. */
|
---|
| 130 | VertexData* cloneVertexDataRemoveBlendInfo(const VertexData* source);
|
---|
| 131 | /** Internal method for preparing this Entity for use in animation. */
|
---|
| 132 | void prepareTempBlendBuffers(void);
|
---|
| 133 |
|
---|
| 134 | /// Cached bone matrices, including any world transform
|
---|
| 135 | Matrix4 *mBoneMatrices;
|
---|
| 136 | unsigned short mNumBoneMatrices;
|
---|
| 137 | /// Records the last frame in which animation was updated
|
---|
| 138 | unsigned long mFrameAnimationLastUpdated;
|
---|
| 139 |
|
---|
| 140 | /// Perform all the updates required for an animated entity
|
---|
| 141 | void updateAnimation(void);
|
---|
| 142 |
|
---|
| 143 | /// Records the last frame in which the bones was updated
|
---|
| 144 | /// It's a pointer because it can be shared between different entities with
|
---|
| 145 | /// a shared skeleton.
|
---|
| 146 | unsigned long *mFrameBonesLastUpdated;
|
---|
| 147 |
|
---|
| 148 | /**
|
---|
| 149 | * A set of all the entities which shares a single SkeletonInstance.
|
---|
| 150 | * This is only created if the entity is in fact sharing it's SkeletonInstance with
|
---|
| 151 | * other Entities.
|
---|
| 152 | */
|
---|
| 153 | EntitySet* mSharedSkeletonEntities;
|
---|
| 154 |
|
---|
| 155 | /// Private method to cache bone matrices from skeleton
|
---|
| 156 | void cacheBoneMatrices(void);
|
---|
| 157 |
|
---|
| 158 | /// Flag determines whether or not to display skeleton
|
---|
| 159 | bool mDisplaySkeleton;
|
---|
| 160 | /// Flag indicating whether hardware skinning is supported by this entities materials
|
---|
| 161 | bool mHardwareSkinning;
|
---|
| 162 | /// Counter indicating number of requests for software skinning.
|
---|
| 163 | int mSoftwareSkinningRequests;
|
---|
| 164 | /// Counter indicating number of requests for software skinned normals.
|
---|
| 165 | int mSoftwareSkinningNormalsRequests;
|
---|
| 166 | /// Flag indicating whether we have a vertex program in use on any of our subentities
|
---|
| 167 | bool mVertexProgramInUse;
|
---|
| 168 |
|
---|
| 169 |
|
---|
| 170 | /// The LOD number of the mesh to use, calculated by _notifyCurrentCamera
|
---|
| 171 | ushort mMeshLodIndex;
|
---|
| 172 |
|
---|
| 173 | /// LOD bias factor, inverted for optimisation when calculating adjusted depth
|
---|
| 174 | Real mMeshLodFactorInv;
|
---|
| 175 | /// Index of minimum detail LOD (NB higher index is lower detail)
|
---|
| 176 | ushort mMinMeshLodIndex;
|
---|
| 177 | /// Index of maximum detail LOD (NB lower index is higher detail)
|
---|
| 178 | ushort mMaxMeshLodIndex;
|
---|
| 179 |
|
---|
| 180 | /// LOD bias factor, inverted for optimisation when calculating adjusted depth
|
---|
| 181 | Real mMaterialLodFactorInv;
|
---|
| 182 | /// Index of minimum detail LOD (NB higher index is lower detail)
|
---|
| 183 | ushort mMinMaterialLodIndex;
|
---|
| 184 | /// Index of maximum detail LOD (NB lower index is higher detail)
|
---|
| 185 | ushort mMaxMaterialLodIndex;
|
---|
| 186 |
|
---|
| 187 | /// Flag indicating that mesh uses manual LOD and so might have multiple SubEntity versions
|
---|
| 188 | bool mUsingManualLOD;
|
---|
| 189 | /** List of LOD Entity instances (for manual LODs).
|
---|
| 190 | We don't know when the mesh is using manual LODs whether one LOD to the next will have the
|
---|
| 191 | same number of SubMeshes, therefore we have to allow a separate Entity list
|
---|
| 192 | with each alternate one.
|
---|
| 193 | */
|
---|
| 194 | typedef std::vector<Entity*> LODEntityList;
|
---|
| 195 | LODEntityList mLodEntityList;
|
---|
| 196 |
|
---|
| 197 | /** This Entity's personal copy of the skeleton, if skeletally animated
|
---|
| 198 | */
|
---|
| 199 | SkeletonInstance* mSkeletonInstance;
|
---|
| 200 |
|
---|
| 201 | /** Builds a list of SubEntities based on the SubMeshes contained in the Mesh. */
|
---|
| 202 | void buildSubEntityList(MeshPtr& mesh, SubEntityList* sublist);
|
---|
| 203 |
|
---|
| 204 | /// internal implementation of attaching a 'child' object to this entity and assign the parent node to the child entity
|
---|
| 205 | void attachObjectImpl(MovableObject *pMovable, TagPoint *pAttachingPoint);
|
---|
| 206 |
|
---|
| 207 | /// internal implementation of detaching a 'child' object of this entity and clear the parent node of the child entity
|
---|
| 208 | void detachObjectImpl(MovableObject* pObject);
|
---|
| 209 |
|
---|
| 210 | /// internal implementation of detaching all 'child' objects of this entity
|
---|
| 211 | void detachAllObjectsImpl(void);
|
---|
| 212 |
|
---|
| 213 | /// Trigger reevaluation of the kind of vertex processing in use
|
---|
| 214 | void reevaluateVertexProcessing(void);
|
---|
| 215 |
|
---|
| 216 | public:
|
---|
| 217 | /// Contains the child objects (attached to bones) indexed by name
|
---|
| 218 | typedef std::map<String, MovableObject*> ChildObjectList;
|
---|
| 219 | protected:
|
---|
| 220 | ChildObjectList mChildObjectList;
|
---|
| 221 |
|
---|
| 222 |
|
---|
| 223 | /// Bounding box that 'contains' all the mesh of each child entity
|
---|
| 224 | AxisAlignedBox *mFullBoundingBox;
|
---|
| 225 |
|
---|
| 226 | bool mNormaliseNormals;
|
---|
| 227 |
|
---|
| 228 | ShadowRenderableList mShadowRenderables;
|
---|
| 229 |
|
---|
| 230 | /** Nested class to allow entity shadows. */
|
---|
| 231 | class _OgreExport EntityShadowRenderable : public ShadowRenderable
|
---|
| 232 | {
|
---|
| 233 | protected:
|
---|
| 234 | Entity* mParent;
|
---|
| 235 | // Shared link to position buffer
|
---|
| 236 | HardwareVertexBufferSharedPtr mPositionBuffer;
|
---|
| 237 | // Shared link to w-coord buffer (optional)
|
---|
| 238 | HardwareVertexBufferSharedPtr mWBuffer;
|
---|
| 239 | // Link to original vertex data
|
---|
| 240 | const VertexData* mOriginalVertexData;
|
---|
| 241 | // Original position buffer source binding
|
---|
| 242 | unsigned short mOriginalPosBufferBinding;
|
---|
| 243 | /// Link to SubEntity, only present if SubEntity has it's own geometry
|
---|
| 244 | SubEntity* mSubEntity;
|
---|
| 245 |
|
---|
| 246 |
|
---|
| 247 | public:
|
---|
| 248 | EntityShadowRenderable(Entity* parent,
|
---|
| 249 | HardwareIndexBufferSharedPtr* indexBuffer, const VertexData* vertexData,
|
---|
| 250 | bool createSeparateLightCap, SubEntity* subent, bool isLightCap = false);
|
---|
| 251 | ~EntityShadowRenderable();
|
---|
| 252 | /// Overridden from ShadowRenderable
|
---|
| 253 | void getWorldTransforms(Matrix4* xform) const;
|
---|
| 254 | /// Overridden from ShadowRenderable
|
---|
| 255 | const Quaternion& getWorldOrientation(void) const;
|
---|
| 256 | /// Overridden from ShadowRenderable
|
---|
| 257 | const Vector3& getWorldPosition(void) const;
|
---|
| 258 | HardwareVertexBufferSharedPtr getPositionBuffer(void) { return mPositionBuffer; }
|
---|
| 259 | HardwareVertexBufferSharedPtr getWBuffer(void) { return mWBuffer; }
|
---|
| 260 | /// Rebind the source positions (for temp buffer users)
|
---|
| 261 | void rebindPositionBuffer(void);
|
---|
| 262 | /// Overridden from ShadowRenderable
|
---|
| 263 | bool isVisible(void) const;
|
---|
| 264 |
|
---|
| 265 | };
|
---|
| 266 | public:
|
---|
| 267 | /** Default destructor.
|
---|
| 268 | */
|
---|
| 269 | ~Entity();
|
---|
| 270 |
|
---|
| 271 | /** Gets the Mesh that this Entity is based on.
|
---|
| 272 | */
|
---|
| 273 | MeshPtr& getMesh(void);
|
---|
| 274 |
|
---|
| 275 | /** Gets a pointer to a SubEntity, ie a part of an Entity.
|
---|
| 276 | */
|
---|
| 277 | SubEntity* getSubEntity(unsigned int index);
|
---|
| 278 |
|
---|
| 279 | /** Gets a pointer to a SubEntity by name
|
---|
| 280 | @remarks - names should be initialized during a Mesh creation.
|
---|
| 281 | */
|
---|
| 282 | SubEntity* getSubEntity( const String& name );
|
---|
| 283 |
|
---|
| 284 | /** Retrieves the number of SubEntity objects making up this entity.
|
---|
| 285 | */
|
---|
| 286 | unsigned int getNumSubEntities(void) const;
|
---|
| 287 |
|
---|
| 288 | /** Clones this entity and returns a pointer to the clone.
|
---|
| 289 | @remarks
|
---|
| 290 | Useful method for duplicating an entity. The new entity must be
|
---|
| 291 | given a unique name, and is not attached to the scene in any way
|
---|
| 292 | so must be attached to a SceneNode to be visible (exactly as
|
---|
| 293 | entities returned from SceneManager::createEntity).
|
---|
| 294 | @param
|
---|
| 295 | newName Name for the new entity.
|
---|
| 296 | */
|
---|
| 297 | Entity* clone( const String& newName );
|
---|
| 298 |
|
---|
| 299 | /** Sets the material to use for the whole of this entity.
|
---|
| 300 | @remarks
|
---|
| 301 | This is a shortcut method to set all the materials for all
|
---|
| 302 | subentities of this entity. Only use this method is you want to
|
---|
| 303 | set the same material for all subentities or if you know there
|
---|
| 304 | is only one. Otherwise call getSubEntity() and call the same
|
---|
| 305 | method on the individual SubEntity.
|
---|
| 306 | */
|
---|
| 307 | void setMaterialName(const String& name);
|
---|
| 308 |
|
---|
| 309 | /** Overridden - see MovableObject.
|
---|
| 310 | */
|
---|
| 311 | void _notifyCurrentCamera(Camera* cam);
|
---|
| 312 |
|
---|
| 313 | /// Overridden - see MovableObject.
|
---|
| 314 | void setRenderQueueGroup(RenderQueueGroupID queueID);
|
---|
| 315 |
|
---|
| 316 | /** Overridden - see MovableObject.
|
---|
| 317 | */
|
---|
| 318 | const AxisAlignedBox& getBoundingBox(void) const;
|
---|
| 319 |
|
---|
| 320 | /// merge all the child object Bounds a return it
|
---|
| 321 | AxisAlignedBox getChildObjectsBoundingBox(void) const;
|
---|
| 322 |
|
---|
| 323 | /** Overridden - see MovableObject.
|
---|
| 324 | */
|
---|
| 325 | void _updateRenderQueue(RenderQueue* queue);
|
---|
| 326 |
|
---|
| 327 | /** Overridden from MovableObject */
|
---|
| 328 | const String& getName(void) const;
|
---|
| 329 |
|
---|
| 330 | /** Overridden from MovableObject */
|
---|
| 331 | const String& getMovableType(void) const;
|
---|
| 332 |
|
---|
| 333 | /** For entities based on animated meshes, gets the AnimationState object for a single animation.
|
---|
| 334 | @remarks
|
---|
| 335 | You animate an entity by updating the animation state objects. Each of these represents the
|
---|
| 336 | current state of each animation available to the entity. The AnimationState objects are
|
---|
| 337 | initialised from the Mesh object.
|
---|
| 338 | */
|
---|
| 339 | AnimationState* getAnimationState(const String& name);
|
---|
| 340 | /** For entities based on animated meshes, gets the AnimationState objects for all animations.
|
---|
| 341 | @returns
|
---|
| 342 | In case the entity is animated, this functions returns the pointer to a AnimationStateSet
|
---|
| 343 | containing all animations of the entries. If the entity is not animated, it returns 0.
|
---|
| 344 | @remarks
|
---|
| 345 | You animate an entity by updating the animation state objects. Each of these represents the
|
---|
| 346 | current state of each animation available to the entity. The AnimationState objects are
|
---|
| 347 | initialised from the Mesh object.
|
---|
| 348 | */
|
---|
| 349 | AnimationStateSet* getAllAnimationStates(void);
|
---|
| 350 |
|
---|
| 351 | /** Tells the Entity whether or not it should display it's skeleton, if it has one.
|
---|
| 352 | */
|
---|
| 353 | void setDisplaySkeleton(bool display);
|
---|
| 354 |
|
---|
| 355 | /** Returns whether or not the entity is currently displaying its skeleton.
|
---|
| 356 | */
|
---|
| 357 | bool getDisplaySkeleton(void) const;
|
---|
| 358 |
|
---|
| 359 |
|
---|
| 360 | /** Gets a pointer to the entity representing the numbered manual level of detail.
|
---|
| 361 | @remarks
|
---|
| 362 | The zero-based index never includes the original entity, unlike
|
---|
| 363 | Mesh::getLodLevel.
|
---|
| 364 | */
|
---|
| 365 | Entity* getManualLodLevel(size_t index) const;
|
---|
| 366 |
|
---|
| 367 | /** Returns the number of manual levels of detail that this entity supports.
|
---|
| 368 | @remarks
|
---|
| 369 | This number never includes the original entity, it is difference
|
---|
| 370 | with Mesh::getNumLodLevels.
|
---|
| 371 | */
|
---|
| 372 | size_t getNumManualLodLevels(void) const;
|
---|
| 373 |
|
---|
| 374 | /** Sets a level-of-detail bias for the mesh detail of this entity.
|
---|
| 375 | @remarks
|
---|
| 376 | Level of detail reduction is normally applied automatically based on the Mesh
|
---|
| 377 | settings. However, it is possible to influence this behaviour for this entity
|
---|
| 378 | by adjusting the LOD bias. This 'nudges' the mesh level of detail used for this
|
---|
| 379 | entity up or down depending on your requirements. You might want to use this
|
---|
| 380 | if there was a particularly important entity in your scene which you wanted to
|
---|
| 381 | detail better than the others, such as a player model.
|
---|
| 382 | @par
|
---|
| 383 | There are three parameters to this method; the first is a factor to apply; it
|
---|
| 384 | defaults to 1.0 (no change), by increasing this to say 2.0, this model would
|
---|
| 385 | take twice as long to reduce in detail, whilst at 0.5 this entity would use lower
|
---|
| 386 | detail versions twice as quickly. The other 2 parameters are hard limits which
|
---|
| 387 | let you set the maximum and minimum level-of-detail version to use, after all
|
---|
| 388 | other calculations have been made. This lets you say that this entity should
|
---|
| 389 | never be simplified, or that it can only use LODs below a certain level even
|
---|
| 390 | when right next to the camera.
|
---|
| 391 | @param factor Proportional factor to apply to the distance at which LOD is changed.
|
---|
| 392 | Higher values increase the distance at which higher LODs are displayed (2.0 is
|
---|
| 393 | twice the normal distance, 0.5 is half).
|
---|
| 394 | @param maxDetailIndex The index of the maximum LOD this entity is allowed to use (lower
|
---|
| 395 | indexes are higher detail: index 0 is the original full detail model).
|
---|
| 396 | @param minDetailIndex The index of the minimum LOD this entity is allowed to use (higher
|
---|
| 397 | indexes are lower detail. Use something like 99 if you want unlimited LODs (the actual
|
---|
| 398 | LOD will be limited by the number in the Mesh)
|
---|
| 399 | */
|
---|
| 400 | void setMeshLodBias(Real factor, ushort maxDetailIndex = 0, ushort minDetailIndex = 99);
|
---|
| 401 |
|
---|
| 402 | /** Sets a level-of-detail bias for the material detail of this entity.
|
---|
| 403 | @remarks
|
---|
| 404 | Level of detail reduction is normally applied automatically based on the Material
|
---|
| 405 | settings. However, it is possible to influence this behaviour for this entity
|
---|
| 406 | by adjusting the LOD bias. This 'nudges' the material level of detail used for this
|
---|
| 407 | entity up or down depending on your requirements. You might want to use this
|
---|
| 408 | if there was a particularly important entity in your scene which you wanted to
|
---|
| 409 | detail better than the others, such as a player model.
|
---|
| 410 | @par
|
---|
| 411 | There are three parameters to this method; the first is a factor to apply; it
|
---|
| 412 | defaults to 1.0 (no change), by increasing this to say 2.0, this entity would
|
---|
| 413 | take twice as long to use a lower detail material, whilst at 0.5 this entity
|
---|
| 414 | would use lower detail versions twice as quickly. The other 2 parameters are
|
---|
| 415 | hard limits which let you set the maximum and minimum level-of-detail index
|
---|
| 416 | to use, after all other calculations have been made. This lets you say that
|
---|
| 417 | this entity should never be simplified, or that it can only use LODs below
|
---|
| 418 | a certain level even when right next to the camera.
|
---|
| 419 | @param factor Proportional factor to apply to the distance at which LOD is changed.
|
---|
| 420 | Higher values increase the distance at which higher LODs are displayed (2.0 is
|
---|
| 421 | twice the normal distance, 0.5 is half).
|
---|
| 422 | @param maxDetailIndex The index of the maximum LOD this entity is allowed to use (lower
|
---|
| 423 | indexes are higher detail: index 0 is the original full detail model).
|
---|
| 424 | @param minDetailIndex The index of the minimum LOD this entity is allowed to use (higher
|
---|
| 425 | indexes are lower detail. Use something like 99 if you want unlimited LODs (the actual
|
---|
| 426 | LOD will be limited by the number of lod indexes used in the Material)
|
---|
| 427 | */
|
---|
| 428 | void setMaterialLodBias(Real factor, ushort maxDetailIndex = 0, ushort minDetailIndex = 99);
|
---|
| 429 |
|
---|
| 430 | /** Sets the rendering detail of this entire entity (solid, wireframe etc) */
|
---|
| 431 | void setRenderDetail(SceneDetailLevel renderDetail);
|
---|
| 432 |
|
---|
| 433 | /** Sets whether the rendering detail of this entire entity may be
|
---|
| 434 | overridden by the camera detail settings.
|
---|
| 435 | */
|
---|
| 436 | void setRenderDetailOverrideable(bool renderDetailOverrideable);
|
---|
| 437 | /** Attaches another object to a certain bone of the skeleton which this entity uses.
|
---|
| 438 | @remarks
|
---|
| 439 | This method can be used to attach another object to an animated part of this entity,
|
---|
| 440 | by attaching it to a bone in the skeleton (with an offset if required). As this entity
|
---|
| 441 | is animated, the attached object will move relative to the bone to which it is attached.
|
---|
| 442 | @param boneName The name of the bone (in the skeleton) to attach this object
|
---|
| 443 | @param pMovable Pointer to the object to attach
|
---|
| 444 | @param offsetOrientation An adjustment to the orientation of the attached object, relative to the bone.
|
---|
| 445 | @param offsetPosition An adjustment to the position of the attached object, relative to the bone.
|
---|
| 446 | */
|
---|
| 447 | void attachObjectToBone(const String &boneName, MovableObject *pMovable, const Quaternion &offsetOrientation = Quaternion::IDENTITY, const Vector3 &offsetPosition = Vector3::ZERO);
|
---|
| 448 |
|
---|
| 449 | /// detach a MovableObject previously attached using attachObjectToBone
|
---|
| 450 | MovableObject* detachObjectFromBone(const String &movableName);
|
---|
| 451 |
|
---|
| 452 | /** Detaches an object by pointer.
|
---|
| 453 | @remarks
|
---|
| 454 | This method is need when destroy a MovableObject which attached to a bone of this entity.
|
---|
| 455 | But sometimes the object may be not in the child object list because it is a lod entity,
|
---|
| 456 | this method can safely detect and ignore in this case.
|
---|
| 457 | */
|
---|
| 458 | void detachObjectFromBone(MovableObject* obj);
|
---|
| 459 |
|
---|
| 460 | /// Detach all MovableObjects previously attached using attachObjectToBone
|
---|
| 461 | void detachAllObjectsFromBone(void);
|
---|
| 462 |
|
---|
| 463 | typedef MapIterator<ChildObjectList> ChildObjectListIterator;
|
---|
| 464 | /** Gets an iterator to the list of objects attached to bones on this entity. */
|
---|
| 465 | ChildObjectListIterator getAttachedObjectIterator(void);
|
---|
| 466 | /** @see MovableObject::getBoundingRadius */
|
---|
| 467 | Real getBoundingRadius(void) const;
|
---|
| 468 | /** @copy MovableObject::getWorldBoundingBox */
|
---|
| 469 | const AxisAlignedBox& getWorldBoundingBox(bool derive = false) const;
|
---|
| 470 | /** @copy MovableObject::getWorldBoundingSphere */
|
---|
| 471 | const Sphere& getWorldBoundingSphere(bool derive = false) const;
|
---|
| 472 |
|
---|
| 473 | /** If set to true, this forces normals of this entity to be normalised
|
---|
| 474 | dynamically by the hardware.
|
---|
| 475 | @remarks
|
---|
| 476 | This option can be used to prevent lighting variations when scaling an
|
---|
| 477 | Entity using a SceneNode - normally because this scaling is hardware
|
---|
| 478 | based, the normals get scaled too which causes lighting to become inconsistent.
|
---|
| 479 | However, this has an overhead so only do this if you really need to.
|
---|
| 480 | */
|
---|
| 481 | void setNormaliseNormals(bool normalise) { mNormaliseNormals = normalise; }
|
---|
| 482 |
|
---|
| 483 | /** Returns true if this entity has auto-normalisation of normals set. */
|
---|
| 484 | bool getNormaliseNormals(void) const {return mNormaliseNormals; }
|
---|
| 485 |
|
---|
| 486 |
|
---|
| 487 | /** Overridden member from ShadowCaster. */
|
---|
| 488 | EdgeData* getEdgeList(void);
|
---|
| 489 | /** Overridden member from ShadowCaster. */
|
---|
| 490 | ShadowRenderableListIterator getShadowVolumeRenderableIterator(
|
---|
| 491 | ShadowTechnique shadowTechnique, const Light* light,
|
---|
| 492 | HardwareIndexBufferSharedPtr* indexBuffer,
|
---|
| 493 | bool extrudeVertices, Real extrusionDistance, unsigned long flags = 0 );
|
---|
| 494 |
|
---|
| 495 | /** Internal method for retrieving bone matrix information. */
|
---|
| 496 | const Matrix4* _getBoneMatrices(void) { return mBoneMatrices;}
|
---|
| 497 | /** Internal method for retrieving bone matrix information. */
|
---|
| 498 | unsigned short _getNumBoneMatrices(void) { return mNumBoneMatrices; }
|
---|
| 499 | /** Returns whether or not this entity is skeletally animated. */
|
---|
| 500 | bool hasSkeleton(void) { return mSkeletonInstance != 0; }
|
---|
| 501 | /** Get this Entity's personal skeleton instance. */
|
---|
| 502 | SkeletonInstance* getSkeleton(void) { return mSkeletonInstance; }
|
---|
| 503 | /** Returns whether or not hardware skinning is enabled.
|
---|
| 504 | @remarks
|
---|
| 505 | Because fixed-function indexed vertex blending is rarely supported
|
---|
| 506 | by existing graphics cards, hardware skinning can only be done if
|
---|
| 507 | the vertex programs in the materials used to render an entity support
|
---|
| 508 | it. Therefore, this method will only return true if all the materials
|
---|
| 509 | assigned to this entity have vertex programs assigned, and all those
|
---|
| 510 | vertex programs must support 'include_skeletal_animation true'.
|
---|
| 511 | */
|
---|
| 512 | bool isHardwareSkinningEnabled(void) const { return mHardwareSkinning; }
|
---|
| 513 | /** Returns the number of requests that have been made for software skinning
|
---|
| 514 | @remarks
|
---|
| 515 | If non-zero then software skinning will be performed in updateAnimation
|
---|
| 516 | regardless of the current setting of isHardwareSkinningEnabled.
|
---|
| 517 | Requests for software skinning are made by calling the
|
---|
| 518 | addSoftwareSkinningRequest() method.
|
---|
| 519 | */
|
---|
| 520 | int getSoftwareSkinningRequests(void) const { return mSoftwareSkinningRequests; }
|
---|
| 521 | /** Returns the number of requests that have been made for software skinning of normals
|
---|
| 522 | @remarks
|
---|
| 523 | If non-zero, and getSoftwareSkinningRequests() also returns non-zero,
|
---|
| 524 | then software skinning of normals will be performed in updateAnimation
|
---|
| 525 | regardless of the current setting of isHardwareSkinningEnabled.
|
---|
| 526 | Currently it is not possible to force software skinning of only normals.
|
---|
| 527 | Consequently this value is always less than or equal to that returned
|
---|
| 528 | by getSoftwareSkinningRequests().
|
---|
| 529 | Requests for software skinning of normals are made by calling the
|
---|
| 530 | addSoftwareSkinningRequest() method with 'true' as the parameter.
|
---|
| 531 | */
|
---|
| 532 | int getSoftwareSkinningNormalsRequests(void) const { return mSoftwareSkinningNormalsRequests; }
|
---|
| 533 | /** Add a request for software skinning
|
---|
| 534 | @remarks
|
---|
| 535 | Tells the entity to perform skinning calculations for skeletal
|
---|
| 536 | animations in software, regardless of the current setting of
|
---|
| 537 | isHardwareSkinningEnabled(). Software skinning will be performed
|
---|
| 538 | any time one or more requests have been made. If 'normalsAlso' is
|
---|
| 539 | 'true', then the entity will also do software blending on normal
|
---|
| 540 | vectors, in addition to positions. This advanced method useful for
|
---|
| 541 | situations in which access to actual mesh vertices is required,
|
---|
| 542 | such as accurate collision detection or certain advanced shading
|
---|
| 543 | techniques. When software skinning is no longer needed,
|
---|
| 544 | the caller of this method should always remove the request by calling
|
---|
| 545 | removeSoftwareSkinningRequest(), passing the same value for
|
---|
| 546 | 'normalsAlso'.
|
---|
| 547 | */
|
---|
| 548 | void addSoftwareSkinningRequest(bool normalsAlso);
|
---|
| 549 | /** Removes a request for software skinning
|
---|
| 550 | @remarks
|
---|
| 551 | Calling this decrements the entity's internal counter of the number
|
---|
| 552 | of requests for software skinning. If the counter is already zero
|
---|
| 553 | then calling this method throws an exception. The 'normalsAlso'
|
---|
| 554 | flag if set to 'true' will also decrement the internal counter of
|
---|
| 555 | number of requests for software skinning of normals.
|
---|
| 556 | */
|
---|
| 557 | void removeSoftwareSkinningRequest(bool normalsAlso);
|
---|
| 558 |
|
---|
| 559 | /** Overridden from MovableObject */
|
---|
| 560 | void _notifyAttached(Node* parent, bool isTagPoint = false);
|
---|
| 561 |
|
---|
| 562 | /** Shares the SkeletonInstance with the supplied entity.
|
---|
| 563 | * Note that in order for this to work, both entities must have the same
|
---|
| 564 | * Skeleton.
|
---|
| 565 | */
|
---|
| 566 | void shareSkeletonInstanceWith(Entity* entity);
|
---|
| 567 |
|
---|
| 568 |
|
---|
| 569 | /** Stops sharing the SkeletonInstance with other entities.
|
---|
| 570 | */
|
---|
| 571 | void Entity::stopSharingSkeletonInstance();
|
---|
| 572 |
|
---|
| 573 |
|
---|
| 574 | /**
|
---|
| 575 | * Returns whether this entity shares it's SkeltonInstance with other entity instances.
|
---|
| 576 | */
|
---|
| 577 | inline bool sharesSkeletonInstance() const { return mSharedSkeletonEntities != NULL; }
|
---|
| 578 |
|
---|
| 579 | /**
|
---|
| 580 | * Returns a pointer to the set of entities which share a SkeletonInstance.
|
---|
| 581 | * If this instance does not share it's SkeletonInstance with other instances NULL will be returned
|
---|
| 582 | */
|
---|
| 583 | inline const EntitySet* getSkeletonInstanceSharingSet() const { return mSharedSkeletonEntities; }
|
---|
| 584 |
|
---|
| 585 | /** Updates the internal animation state set to include the latest
|
---|
| 586 | available animations from the attached skeleton.
|
---|
| 587 | @remarks
|
---|
| 588 | Use this method if you manually add animations to a skeleton, or have
|
---|
| 589 | linked the skeleton to another for animation purposes since creating
|
---|
| 590 | this entity.
|
---|
| 591 | @note
|
---|
| 592 | If you have called getAnimationState prior to calling this method,
|
---|
| 593 | the pointers will still remain valid.
|
---|
| 594 | */
|
---|
| 595 | void refreshAvailableAnimationState(void);
|
---|
| 596 |
|
---|
| 597 | /** Advanced method to perform all the updates required for an animated entity.
|
---|
| 598 | @remarks
|
---|
| 599 | You don't normally need to call this, but it's here incase you wish
|
---|
| 600 | to manually update the animation of an Entity at a specific point in
|
---|
| 601 | time. Animation will not be updated more than once a frame no matter
|
---|
| 602 | how many times you call this method.
|
---|
| 603 | */
|
---|
| 604 | void _updateAnimation(void);
|
---|
| 605 |
|
---|
| 606 | /** Advanced method to get the temporarily blended vertex information
|
---|
| 607 | for entities which are software skinned.
|
---|
| 608 | */
|
---|
| 609 | const VertexData* _getSharedBlendedVertexData(void) const;
|
---|
| 610 |
|
---|
| 611 |
|
---|
| 612 |
|
---|
| 613 | };
|
---|
| 614 |
|
---|
| 615 | } // namespace
|
---|
| 616 |
|
---|
| 617 | #endif
|
---|