[1809] | 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 "OgreQuaternion.h"
|
---|
| 34 | #include "OgreVector3.h"
|
---|
| 35 | #include "OgreHardwareBufferManager.h"
|
---|
| 36 | #include "OgreMesh.h"
|
---|
| 37 |
|
---|
| 38 | namespace Ogre {
|
---|
| 39 | /** Defines an instance of a discrete, movable object based on a Mesh.
|
---|
| 40 | @remarks
|
---|
| 41 | Ogre generally divides renderable objects into 2 groups, discrete
|
---|
| 42 | (separate) and relatively small objects which move around the world,
|
---|
| 43 | and large, sprawling geometry which makes up generally immovable
|
---|
| 44 | scenery, aka 'level geometry'.
|
---|
| 45 | @par
|
---|
| 46 | The Mesh and SubMesh classes deal with the definition of the geometry
|
---|
| 47 | used by discrete movable objects. Entities are actual instances of
|
---|
| 48 | objects based on this geometry in the world. Therefore there is
|
---|
| 49 | usually a single set Mesh for a car, but there may be multiple
|
---|
| 50 | entities based on it in the world. Entities are able to override
|
---|
| 51 | aspects of the Mesh it is defined by, such as changing material
|
---|
| 52 | properties per instance (so you can have many cars using the same
|
---|
| 53 | geometry but different textures for example). Because a Mesh is split
|
---|
| 54 | into SubMeshes for this purpose, the Entity class is a grouping class
|
---|
| 55 | (much like the Mesh class) and much of the detail regarding
|
---|
| 56 | individual changes is kept in the SubEntity class. There is a 1:1
|
---|
| 57 | relationship between SubEntity instances and the SubMesh instances
|
---|
| 58 | associated with the Mesh the Entity is based on.
|
---|
| 59 | @par
|
---|
| 60 | Entity and SubEntity classes are never created directly. Use the
|
---|
| 61 | createEntity method of the SceneManager (passing a model name) to
|
---|
| 62 | create one.
|
---|
| 63 | @par
|
---|
| 64 | Entities are included in the scene by associating them with a
|
---|
| 65 | SceneNode, using the attachEntity method. See the SceneNode class
|
---|
| 66 | for full information.
|
---|
| 67 | @note
|
---|
| 68 | No functions were declared virtual to improve performance.
|
---|
| 69 | */
|
---|
| 70 | class _OgreExport Entity: public MovableObject
|
---|
| 71 | {
|
---|
| 72 | // Allow EntityFactory full access
|
---|
| 73 | friend class EntityFactory;
|
---|
| 74 | friend class SubEntity;
|
---|
| 75 | public:
|
---|
| 76 | typedef std::set<Entity*> EntitySet;
|
---|
| 77 |
|
---|
| 78 | protected:
|
---|
| 79 |
|
---|
| 80 | /** Private constructor (instances cannot be created directly).
|
---|
| 81 | */
|
---|
| 82 | Entity();
|
---|
| 83 | /** Private constructor - specify name (the usual constructor used).
|
---|
| 84 | */
|
---|
| 85 | Entity( const String& name, MeshPtr& mesh);
|
---|
| 86 |
|
---|
| 87 | /** The Mesh that this Entity is based on.
|
---|
| 88 | */
|
---|
| 89 | MeshPtr mMesh;
|
---|
| 90 |
|
---|
| 91 | /** List of SubEntities (point to SubMeshes).
|
---|
| 92 | */
|
---|
| 93 | typedef std::vector<SubEntity*> SubEntityList;
|
---|
| 94 | SubEntityList mSubEntityList;
|
---|
| 95 |
|
---|
| 96 |
|
---|
| 97 | /// State of animation for animable meshes
|
---|
| 98 | AnimationStateSet* mAnimationState;
|
---|
| 99 |
|
---|
| 100 |
|
---|
| 101 | /// Temp buffer details for software skeletal anim of shared geometry
|
---|
| 102 | TempBlendedBufferInfo mTempSkelAnimInfo;
|
---|
| 103 | /// Vertex data details for software skeletal anim of shared geometry
|
---|
| 104 | VertexData* mSkelAnimVertexData;
|
---|
| 105 | /// Temp buffer details for software vertex anim of shared geometry
|
---|
| 106 | TempBlendedBufferInfo mTempVertexAnimInfo;
|
---|
| 107 | /// Vertex data details for software vertex anim of shared geometry
|
---|
| 108 | VertexData* mSoftwareVertexAnimVertexData;
|
---|
| 109 | /// Vertex data details for hardware vertex anim of shared geometry
|
---|
| 110 | /// - separate since we need to s/w anim for shadows whilst still altering
|
---|
| 111 | /// the vertex data for hardware morphing (pos2 binding)
|
---|
| 112 | VertexData* mHardwareVertexAnimVertexData;
|
---|
| 113 | /// Have we applied any vertex animation to shared geometry?
|
---|
| 114 | bool mVertexAnimationAppliedThisFrame;
|
---|
| 115 | /// Have the temp buffers already had their geometry prepared for use in rendering shadow volumes?
|
---|
| 116 | bool mPreparedForShadowVolumes;
|
---|
| 117 |
|
---|
| 118 | /** Internal method - given vertex data which could be from the Mesh or
|
---|
| 119 | any submesh, finds the temporary blend copy. */
|
---|
| 120 | const VertexData* findBlendedVertexData(const VertexData* orig);
|
---|
| 121 | /** Internal method - given vertex data which could be from the Mesh or
|
---|
| 122 | any SubMesh, finds the corresponding SubEntity. */
|
---|
| 123 | SubEntity* findSubEntityForVertexData(const VertexData* orig);
|
---|
| 124 |
|
---|
| 125 | /** Internal method for extracting metadata out of source vertex data
|
---|
| 126 | for fast assignment of temporary buffers later. */
|
---|
| 127 | void extractTempBufferInfo(VertexData* sourceData, TempBlendedBufferInfo* info);
|
---|
| 128 | /** Internal method to clone vertex data definitions but to remove blend buffers. */
|
---|
| 129 | VertexData* cloneVertexDataRemoveBlendInfo(const VertexData* source);
|
---|
| 130 | /** Internal method for preparing this Entity for use in animation. */
|
---|
| 131 | void prepareTempBlendBuffers(void);
|
---|
| 132 | /** Mark all vertex data as so far unanimated.
|
---|
| 133 | */
|
---|
| 134 | void markBuffersUnusedForAnimation(void);
|
---|
| 135 | /** Internal method to restore original vertex data where we didn't
|
---|
| 136 | perform any vertex animation this frame.
|
---|
| 137 | */
|
---|
| 138 | void restoreBuffersForUnusedAnimation(bool hardwareAnimation);
|
---|
| 139 |
|
---|
| 140 | /// Cached bone matrices, including any world transform
|
---|
| 141 | Matrix4 *mBoneWorldMatrices;
|
---|
| 142 | /// Cached bone matrices in skeleton local space, might shares with other entity instances.
|
---|
| 143 | Matrix4 *mBoneMatrices;
|
---|
| 144 | unsigned short mNumBoneMatrices;
|
---|
| 145 | /// Records the last frame in which animation was updated
|
---|
| 146 | unsigned long mFrameAnimationLastUpdated;
|
---|
| 147 |
|
---|
| 148 | /// Perform all the updates required for an animated entity
|
---|
| 149 | void updateAnimation(void);
|
---|
| 150 |
|
---|
| 151 | /// Records the last frame in which the bones was updated
|
---|
| 152 | /// It's a pointer because it can be shared between different entities with
|
---|
| 153 | /// a shared skeleton.
|
---|
| 154 | unsigned long *mFrameBonesLastUpdated;
|
---|
| 155 |
|
---|
| 156 | /**
|
---|
| 157 | * A set of all the entities which shares a single SkeletonInstance.
|
---|
| 158 | * This is only created if the entity is in fact sharing it's SkeletonInstance with
|
---|
| 159 | * other Entities.
|
---|
| 160 | */
|
---|
| 161 | EntitySet* mSharedSkeletonEntities;
|
---|
| 162 |
|
---|
| 163 | /// Private method to cache bone matrices from skeleton
|
---|
| 164 | void cacheBoneMatrices(void);
|
---|
| 165 |
|
---|
| 166 | /// Flag determines whether or not to display skeleton
|
---|
| 167 | bool mDisplaySkeleton;
|
---|
| 168 | /// Flag indicating whether hardware animation is supported by this entities materials
|
---|
| 169 | bool mHardwareAnimation;
|
---|
| 170 | /// Number of hardware poses supported by materials
|
---|
| 171 | ushort mHardwarePoseCount;
|
---|
| 172 | /// Flag indicating whether we have a vertex program in use on any of our subentities
|
---|
| 173 | bool mVertexProgramInUse;
|
---|
| 174 | /// Counter indicating number of requests for software animation.
|
---|
| 175 | int mSoftwareAnimationRequests;
|
---|
| 176 | /// Counter indicating number of requests for software blended normals.
|
---|
| 177 | int mSoftwareAnimationNormalsRequests;
|
---|
| 178 |
|
---|
| 179 |
|
---|
| 180 | /// The LOD number of the mesh to use, calculated by _notifyCurrentCamera
|
---|
| 181 | ushort mMeshLodIndex;
|
---|
| 182 |
|
---|
| 183 | /// LOD bias factor, inverted for optimisation when calculating adjusted depth
|
---|
| 184 | Real mMeshLodFactorInv;
|
---|
| 185 | /// Index of minimum detail LOD (NB higher index is lower detail)
|
---|
| 186 | ushort mMinMeshLodIndex;
|
---|
| 187 | /// Index of maximum detail LOD (NB lower index is higher detail)
|
---|
| 188 | ushort mMaxMeshLodIndex;
|
---|
| 189 |
|
---|
| 190 | /// LOD bias factor, inverted for optimisation when calculating adjusted depth
|
---|
| 191 | Real mMaterialLodFactorInv;
|
---|
| 192 | /// Index of minimum detail LOD (NB higher index is lower detail)
|
---|
| 193 | ushort mMinMaterialLodIndex;
|
---|
| 194 | /// Index of maximum detail LOD (NB lower index is higher detail)
|
---|
| 195 | ushort mMaxMaterialLodIndex;
|
---|
| 196 |
|
---|
| 197 | /** List of LOD Entity instances (for manual LODs).
|
---|
| 198 | We don't know when the mesh is using manual LODs whether one LOD to the next will have the
|
---|
| 199 | same number of SubMeshes, therefore we have to allow a separate Entity list
|
---|
| 200 | with each alternate one.
|
---|
| 201 | */
|
---|
| 202 | typedef std::vector<Entity*> LODEntityList;
|
---|
| 203 | LODEntityList mLodEntityList;
|
---|
| 204 |
|
---|
| 205 | /** This Entity's personal copy of the skeleton, if skeletally animated
|
---|
| 206 | */
|
---|
| 207 | SkeletonInstance* mSkeletonInstance;
|
---|
| 208 |
|
---|
| 209 | /// Last parent xform
|
---|
| 210 | Matrix4 mLastParentXform;
|
---|
| 211 |
|
---|
| 212 | /** Builds a list of SubEntities based on the SubMeshes contained in the Mesh. */
|
---|
| 213 | void buildSubEntityList(MeshPtr& mesh, SubEntityList* sublist);
|
---|
| 214 |
|
---|
| 215 | /// internal implementation of attaching a 'child' object to this entity and assign the parent node to the child entity
|
---|
| 216 | void attachObjectImpl(MovableObject *pMovable, TagPoint *pAttachingPoint);
|
---|
| 217 |
|
---|
| 218 | /// internal implementation of detaching a 'child' object of this entity and clear the parent node of the child entity
|
---|
| 219 | void detachObjectImpl(MovableObject* pObject);
|
---|
| 220 |
|
---|
| 221 | /// internal implementation of detaching all 'child' objects of this entity
|
---|
| 222 | void detachAllObjectsImpl(void);
|
---|
| 223 |
|
---|
| 224 | /// Trigger reevaluation of the kind of vertex processing in use
|
---|
| 225 | void reevaluateVertexProcessing(void);
|
---|
| 226 |
|
---|
| 227 | /// Apply vertex animation
|
---|
| 228 | void applyVertexAnimation(bool hardwareAnimation, bool stencilShadows);
|
---|
| 229 | /// Initialise the hardware animation elements for given vertex data
|
---|
| 230 | void initHardwareAnimationElements(VertexData* vdata,
|
---|
| 231 | ushort numberOfElements);
|
---|
| 232 | /// Are software vertex animation temp buffers bound?
|
---|
| 233 | bool tempVertexAnimBuffersBound(void) const;
|
---|
| 234 | /// Are software skeleton animation temp buffers bound?
|
---|
| 235 | bool tempSkelAnimBuffersBound(bool requestNormals) const;
|
---|
| 236 |
|
---|
| 237 | public:
|
---|
| 238 | /// Contains the child objects (attached to bones) indexed by name
|
---|
| 239 | typedef std::map<String, MovableObject*> ChildObjectList;
|
---|
| 240 | protected:
|
---|
| 241 | ChildObjectList mChildObjectList;
|
---|
| 242 |
|
---|
| 243 |
|
---|
| 244 | /// Bounding box that 'contains' all the mesh of each child entity
|
---|
| 245 | mutable AxisAlignedBox mFullBoundingBox;
|
---|
| 246 |
|
---|
| 247 | bool mNormaliseNormals;
|
---|
| 248 |
|
---|
| 249 | ShadowRenderableList mShadowRenderables;
|
---|
| 250 |
|
---|
| 251 | /** Nested class to allow entity shadows. */
|
---|
| 252 | class _OgreExport EntityShadowRenderable : public ShadowRenderable
|
---|
| 253 | {
|
---|
| 254 | protected:
|
---|
| 255 | Entity* mParent;
|
---|
| 256 | // Shared link to position buffer
|
---|
| 257 | HardwareVertexBufferSharedPtr mPositionBuffer;
|
---|
| 258 | // Shared link to w-coord buffer (optional)
|
---|
| 259 | HardwareVertexBufferSharedPtr mWBuffer;
|
---|
| 260 | // Link to current vertex data used to bind (maybe changes)
|
---|
| 261 | const VertexData* mCurrentVertexData;
|
---|
| 262 | // Original position buffer source binding
|
---|
| 263 | unsigned short mOriginalPosBufferBinding;
|
---|
| 264 | /// Link to SubEntity, only present if SubEntity has it's own geometry
|
---|
| 265 | SubEntity* mSubEntity;
|
---|
| 266 |
|
---|
| 267 |
|
---|
| 268 | public:
|
---|
| 269 | EntityShadowRenderable(Entity* parent,
|
---|
| 270 | HardwareIndexBufferSharedPtr* indexBuffer, const VertexData* vertexData,
|
---|
| 271 | bool createSeparateLightCap, SubEntity* subent, bool isLightCap = false);
|
---|
| 272 | ~EntityShadowRenderable();
|
---|
| 273 | /// Overridden from ShadowRenderable
|
---|
| 274 | void getWorldTransforms(Matrix4* xform) const;
|
---|
| 275 | /// Overridden from ShadowRenderable
|
---|
| 276 | const Quaternion& getWorldOrientation(void) const;
|
---|
| 277 | /// Overridden from ShadowRenderable
|
---|
| 278 | const Vector3& getWorldPosition(void) const;
|
---|
| 279 | HardwareVertexBufferSharedPtr getPositionBuffer(void) { return mPositionBuffer; }
|
---|
| 280 | HardwareVertexBufferSharedPtr getWBuffer(void) { return mWBuffer; }
|
---|
| 281 | /// Rebind the source positions (for temp buffer users)
|
---|
| 282 | void rebindPositionBuffer(const VertexData* vertexData, bool force);
|
---|
| 283 | /// Overridden from ShadowRenderable
|
---|
| 284 | bool isVisible(void) const;
|
---|
| 285 |
|
---|
| 286 | };
|
---|
| 287 | public:
|
---|
| 288 | /** Default destructor.
|
---|
| 289 | */
|
---|
| 290 | ~Entity();
|
---|
| 291 |
|
---|
| 292 | /** Gets the Mesh that this Entity is based on.
|
---|
| 293 | */
|
---|
| 294 | const MeshPtr& getMesh(void) const;
|
---|
| 295 |
|
---|
| 296 | /** Gets a pointer to a SubEntity, ie a part of an Entity.
|
---|
| 297 | */
|
---|
| 298 | SubEntity* getSubEntity(unsigned int index) const;
|
---|
| 299 |
|
---|
| 300 | /** Gets a pointer to a SubEntity by name
|
---|
| 301 | @remarks - names should be initialized during a Mesh creation.
|
---|
| 302 | */
|
---|
| 303 | SubEntity* getSubEntity( const String& name ) const;
|
---|
| 304 |
|
---|
| 305 | /** Retrieves the number of SubEntity objects making up this entity.
|
---|
| 306 | */
|
---|
| 307 | unsigned int getNumSubEntities(void) const;
|
---|
| 308 |
|
---|
| 309 | /** Clones this entity and returns a pointer to the clone.
|
---|
| 310 | @remarks
|
---|
| 311 | Useful method for duplicating an entity. The new entity must be
|
---|
| 312 | given a unique name, and is not attached to the scene in any way
|
---|
| 313 | so must be attached to a SceneNode to be visible (exactly as
|
---|
| 314 | entities returned from SceneManager::createEntity).
|
---|
| 315 | @param
|
---|
| 316 | newName Name for the new entity.
|
---|
| 317 | */
|
---|
| 318 | Entity* clone( const String& newName ) const;
|
---|
| 319 |
|
---|
| 320 | /** Sets the material to use for the whole of this entity.
|
---|
| 321 | @remarks
|
---|
| 322 | This is a shortcut method to set all the materials for all
|
---|
| 323 | subentities of this entity. Only use this method is you want to
|
---|
| 324 | set the same material for all subentities or if you know there
|
---|
| 325 | is only one. Otherwise call getSubEntity() and call the same
|
---|
| 326 | method on the individual SubEntity.
|
---|
| 327 | */
|
---|
| 328 | void setMaterialName(const String& name);
|
---|
| 329 |
|
---|
| 330 | /** Overridden - see MovableObject.
|
---|
| 331 | */
|
---|
| 332 | void _notifyCurrentCamera(Camera* cam);
|
---|
| 333 |
|
---|
| 334 | /// Overridden - see MovableObject.
|
---|
| 335 | void setRenderQueueGroup(uint8 queueID);
|
---|
| 336 |
|
---|
| 337 | /** Overridden - see MovableObject.
|
---|
| 338 | */
|
---|
| 339 | const AxisAlignedBox& getBoundingBox(void) const;
|
---|
| 340 |
|
---|
| 341 | /// merge all the child object Bounds a return it
|
---|
| 342 | AxisAlignedBox getChildObjectsBoundingBox(void) const;
|
---|
| 343 |
|
---|
| 344 | /** Overridden - see MovableObject.
|
---|
| 345 | */
|
---|
| 346 | void _updateRenderQueue(RenderQueue* queue);
|
---|
| 347 |
|
---|
| 348 | /** Overridden from MovableObject */
|
---|
| 349 | const String& getMovableType(void) const;
|
---|
| 350 |
|
---|
| 351 | /** For entities based on animated meshes, gets the AnimationState object for a single animation.
|
---|
| 352 | @remarks
|
---|
| 353 | You animate an entity by updating the animation state objects. Each of these represents the
|
---|
| 354 | current state of each animation available to the entity. The AnimationState objects are
|
---|
| 355 | initialised from the Mesh object.
|
---|
| 356 | */
|
---|
| 357 | AnimationState* getAnimationState(const String& name) const;
|
---|
| 358 | /** For entities based on animated meshes, gets the AnimationState objects for all animations.
|
---|
| 359 | @returns
|
---|
| 360 | In case the entity is animated, this functions returns the pointer to a AnimationStateSet
|
---|
| 361 | containing all animations of the entries. If the entity is not animated, it returns 0.
|
---|
| 362 | @remarks
|
---|
| 363 | You animate an entity by updating the animation state objects. Each of these represents the
|
---|
| 364 | current state of each animation available to the entity. The AnimationState objects are
|
---|
| 365 | initialised from the Mesh object.
|
---|
| 366 | */
|
---|
| 367 | AnimationStateSet* getAllAnimationStates(void) const;
|
---|
| 368 |
|
---|
| 369 | /** Tells the Entity whether or not it should display it's skeleton, if it has one.
|
---|
| 370 | */
|
---|
| 371 | void setDisplaySkeleton(bool display);
|
---|
| 372 |
|
---|
| 373 | /** Returns whether or not the entity is currently displaying its skeleton.
|
---|
| 374 | */
|
---|
| 375 | bool getDisplaySkeleton(void) const;
|
---|
| 376 |
|
---|
| 377 |
|
---|
| 378 | /** Gets a pointer to the entity representing the numbered manual level of detail.
|
---|
| 379 | @remarks
|
---|
| 380 | The zero-based index never includes the original entity, unlike
|
---|
| 381 | Mesh::getLodLevel.
|
---|
| 382 | */
|
---|
| 383 | Entity* getManualLodLevel(size_t index) const;
|
---|
| 384 |
|
---|
| 385 | /** Returns the number of manual levels of detail that this entity supports.
|
---|
| 386 | @remarks
|
---|
| 387 | This number never includes the original entity, it is difference
|
---|
| 388 | with Mesh::getNumLodLevels.
|
---|
| 389 | */
|
---|
| 390 | size_t getNumManualLodLevels(void) const;
|
---|
| 391 |
|
---|
| 392 | /** Sets a level-of-detail bias for the mesh detail of this entity.
|
---|
| 393 | @remarks
|
---|
| 394 | Level of detail reduction is normally applied automatically based on the Mesh
|
---|
| 395 | settings. However, it is possible to influence this behaviour for this entity
|
---|
| 396 | by adjusting the LOD bias. This 'nudges' the mesh level of detail used for this
|
---|
| 397 | entity up or down depending on your requirements. You might want to use this
|
---|
| 398 | if there was a particularly important entity in your scene which you wanted to
|
---|
| 399 | detail better than the others, such as a player model.
|
---|
| 400 | @par
|
---|
| 401 | There are three parameters to this method; the first is a factor to apply; it
|
---|
| 402 | defaults to 1.0 (no change), by increasing this to say 2.0, this model would
|
---|
| 403 | take twice as long to reduce in detail, whilst at 0.5 this entity would use lower
|
---|
| 404 | detail versions twice as quickly. The other 2 parameters are hard limits which
|
---|
| 405 | let you set the maximum and minimum level-of-detail version to use, after all
|
---|
| 406 | other calculations have been made. This lets you say that this entity should
|
---|
| 407 | never be simplified, or that it can only use LODs below a certain level even
|
---|
| 408 | when right next to the camera.
|
---|
| 409 | @param factor Proportional factor to apply to the distance at which LOD is changed.
|
---|
| 410 | Higher values increase the distance at which higher LODs are displayed (2.0 is
|
---|
| 411 | twice the normal distance, 0.5 is half).
|
---|
| 412 | @param maxDetailIndex The index of the maximum LOD this entity is allowed to use (lower
|
---|
| 413 | indexes are higher detail: index 0 is the original full detail model).
|
---|
| 414 | @param minDetailIndex The index of the minimum LOD this entity is allowed to use (higher
|
---|
| 415 | indexes are lower detail). Use something like 99 if you want unlimited LODs (the actual
|
---|
| 416 | LOD will be limited by the number in the Mesh)
|
---|
| 417 | */
|
---|
| 418 | void setMeshLodBias(Real factor, ushort maxDetailIndex = 0, ushort minDetailIndex = 99);
|
---|
| 419 |
|
---|
| 420 | /** Sets a level-of-detail bias for the material detail of this entity.
|
---|
| 421 | @remarks
|
---|
| 422 | Level of detail reduction is normally applied automatically based on the Material
|
---|
| 423 | settings. However, it is possible to influence this behaviour for this entity
|
---|
| 424 | by adjusting the LOD bias. This 'nudges' the material level of detail used for this
|
---|
| 425 | entity up or down depending on your requirements. You might want to use this
|
---|
| 426 | if there was a particularly important entity in your scene which you wanted to
|
---|
| 427 | detail better than the others, such as a player model.
|
---|
| 428 | @par
|
---|
| 429 | There are three parameters to this method; the first is a factor to apply; it
|
---|
| 430 | defaults to 1.0 (no change), by increasing this to say 2.0, this entity would
|
---|
| 431 | take twice as long to use a lower detail material, whilst at 0.5 this entity
|
---|
| 432 | would use lower detail versions twice as quickly. The other 2 parameters are
|
---|
| 433 | hard limits which let you set the maximum and minimum level-of-detail index
|
---|
| 434 | to use, after all other calculations have been made. This lets you say that
|
---|
| 435 | this entity should never be simplified, or that it can only use LODs below
|
---|
| 436 | a certain level even when right next to the camera.
|
---|
| 437 | @param factor Proportional factor to apply to the distance at which LOD is changed.
|
---|
| 438 | Higher values increase the distance at which higher LODs are displayed (2.0 is
|
---|
| 439 | twice the normal distance, 0.5 is half).
|
---|
| 440 | @param maxDetailIndex The index of the maximum LOD this entity is allowed to use (lower
|
---|
| 441 | indexes are higher detail: index 0 is the original full detail model).
|
---|
| 442 | @param minDetailIndex The index of the minimum LOD this entity is allowed to use (higher
|
---|
| 443 | indexes are lower detail. Use something like 99 if you want unlimited LODs (the actual
|
---|
| 444 | LOD will be limited by the number of lod indexes used in the Material)
|
---|
| 445 | */
|
---|
| 446 | void setMaterialLodBias(Real factor, ushort maxDetailIndex = 0, ushort minDetailIndex = 99);
|
---|
| 447 |
|
---|
| 448 | /** Sets whether the polygon mode of this entire entity may be
|
---|
| 449 | overridden by the camera detail settings.
|
---|
| 450 | */
|
---|
| 451 | void setPolygonModeOverrideable(bool PolygonModeOverrideable);
|
---|
| 452 | /** Attaches another object to a certain bone of the skeleton which this entity uses.
|
---|
| 453 | @remarks
|
---|
| 454 | This method can be used to attach another object to an animated part of this entity,
|
---|
| 455 | by attaching it to a bone in the skeleton (with an offset if required). As this entity
|
---|
| 456 | is animated, the attached object will move relative to the bone to which it is attached.
|
---|
| 457 | @par
|
---|
| 458 | An exception is thrown if the movable object is already attached to the bone, another bone or scenenode.
|
---|
| 459 | If the entity has no skeleton or the bone name cannot be found then an exception is thrown.
|
---|
| 460 | @param boneName The name of the bone (in the skeleton) to attach this object
|
---|
| 461 | @param pMovable Pointer to the object to attach
|
---|
| 462 | @param offsetOrientation An adjustment to the orientation of the attached object, relative to the bone.
|
---|
| 463 | @param offsetPosition An adjustment to the position of the attached object, relative to the bone.
|
---|
| 464 | @returns The TagPoint to which the object has been attached
|
---|
| 465 | */
|
---|
| 466 | TagPoint* attachObjectToBone(const String &boneName,
|
---|
| 467 | MovableObject *pMovable,
|
---|
| 468 | const Quaternion &offsetOrientation = Quaternion::IDENTITY,
|
---|
| 469 | const Vector3 &offsetPosition = Vector3::ZERO);
|
---|
| 470 |
|
---|
| 471 | /** Detach a MovableObject previously attached using attachObjectToBone.
|
---|
| 472 | If the movable object name is not found then an exception is raised.
|
---|
| 473 | @param movableName is the name of the movable object to be detached.
|
---|
| 474 | */
|
---|
| 475 | MovableObject* detachObjectFromBone(const String &movableName);
|
---|
| 476 |
|
---|
| 477 | /** Detaches an object by pointer.
|
---|
| 478 | @remarks
|
---|
| 479 | Use this method to destroy a MovableObject which is attached to a bone of belonging this entity.
|
---|
| 480 | But sometimes the object may be not in the child object list because it is a lod entity,
|
---|
| 481 | this method can safely detect and ignore in this case and won't raise an exception.
|
---|
| 482 | */
|
---|
| 483 | void detachObjectFromBone(MovableObject* obj);
|
---|
| 484 |
|
---|
| 485 | /// Detach all MovableObjects previously attached using attachObjectToBone
|
---|
| 486 | void detachAllObjectsFromBone(void);
|
---|
| 487 |
|
---|
| 488 | typedef MapIterator<ChildObjectList> ChildObjectListIterator;
|
---|
| 489 | /** Gets an iterator to the list of objects attached to bones on this entity. */
|
---|
| 490 | ChildObjectListIterator getAttachedObjectIterator(void);
|
---|
| 491 | /** @see MovableObject::getBoundingRadius */
|
---|
| 492 | Real getBoundingRadius(void) const;
|
---|
| 493 |
|
---|
| 494 | /** @copy MovableObject::getWorldBoundingBox */
|
---|
| 495 | const AxisAlignedBox& getWorldBoundingBox(bool derive = false) const;
|
---|
| 496 | /** @copy MovableObject::getWorldBoundingSphere */
|
---|
| 497 | const Sphere& getWorldBoundingSphere(bool derive = false) const;
|
---|
| 498 |
|
---|
| 499 | /** If set to true, this forces normals of this entity to be normalised
|
---|
| 500 | dynamically by the hardware.
|
---|
| 501 | @remarks
|
---|
| 502 | This option can be used to prevent lighting variations when scaling an
|
---|
| 503 | Entity using a SceneNode - normally because this scaling is hardware
|
---|
| 504 | based, the normals get scaled too which causes lighting to become inconsistent.
|
---|
| 505 | However, this has an overhead so only do this if you really need to.
|
---|
| 506 | */
|
---|
| 507 | void setNormaliseNormals(bool normalise) { mNormaliseNormals = normalise; }
|
---|
| 508 |
|
---|
| 509 | /** Returns true if this entity has auto-normalisation of normals set. */
|
---|
| 510 | bool getNormaliseNormals(void) const {return mNormaliseNormals; }
|
---|
| 511 |
|
---|
| 512 |
|
---|
| 513 | /** Overridden member from ShadowCaster. */
|
---|
| 514 | EdgeData* getEdgeList(void);
|
---|
| 515 | /** Overridden member from ShadowCaster. */
|
---|
| 516 | ShadowRenderableListIterator getShadowVolumeRenderableIterator(
|
---|
| 517 | ShadowTechnique shadowTechnique, const Light* light,
|
---|
| 518 | HardwareIndexBufferSharedPtr* indexBuffer,
|
---|
| 519 | bool extrudeVertices, Real extrusionDistance, unsigned long flags = 0 );
|
---|
| 520 |
|
---|
| 521 | /** Internal method for retrieving bone matrix information. */
|
---|
| 522 | const Matrix4* _getBoneMatrices(void) const { return mBoneMatrices;}
|
---|
| 523 | /** Internal method for retrieving bone matrix information. */
|
---|
| 524 | unsigned short _getNumBoneMatrices(void) const { return mNumBoneMatrices; }
|
---|
| 525 | /** Returns whether or not this entity is skeletally animated. */
|
---|
| 526 | bool hasSkeleton(void) const { return mSkeletonInstance != 0; }
|
---|
| 527 | /** Get this Entity's personal skeleton instance. */
|
---|
| 528 | SkeletonInstance* getSkeleton(void) const { return mSkeletonInstance; }
|
---|
| 529 | /** Returns whether or not hardware animation is enabled.
|
---|
| 530 | @remarks
|
---|
| 531 | Because fixed-function indexed vertex blending is rarely supported
|
---|
| 532 | by existing graphics cards, hardware animation can only be done if
|
---|
| 533 | the vertex programs in the materials used to render an entity support
|
---|
| 534 | it. Therefore, this method will only return true if all the materials
|
---|
| 535 | assigned to this entity have vertex programs assigned, and all those
|
---|
| 536 | vertex programs must support 'includes_morph_animation true' if using
|
---|
| 537 | morph animation, 'includes_pose_animation true' if using pose animation
|
---|
| 538 | and 'includes_skeletal_animation true' if using skeletal animation.
|
---|
| 539 | */
|
---|
| 540 | bool isHardwareAnimationEnabled(void) const { return mHardwareAnimation; }
|
---|
| 541 |
|
---|
| 542 | /** Overridden from MovableObject */
|
---|
| 543 | void _notifyAttached(Node* parent, bool isTagPoint = false);
|
---|
| 544 | /** Returns the number of requests that have been made for software animation
|
---|
| 545 | @remarks
|
---|
| 546 | If non-zero then software animation will be performed in updateAnimation
|
---|
| 547 | regardless of the current setting of isHardwareAnimationEnabled or any
|
---|
| 548 | internal optimise for eliminate software animation. Requests for software
|
---|
| 549 | animation are made by calling the addSoftwareAnimationRequest() method.
|
---|
| 550 | */
|
---|
| 551 | int getSoftwareAnimationRequests(void) const { return mSoftwareAnimationRequests; }
|
---|
| 552 | /** Returns the number of requests that have been made for software animation of normals
|
---|
| 553 | @remarks
|
---|
| 554 | If non-zero, and getSoftwareAnimationRequests() also returns non-zero,
|
---|
| 555 | then software animation of normals will be performed in updateAnimation
|
---|
| 556 | regardless of the current setting of isHardwareAnimationEnabled or any
|
---|
| 557 | internal optimise for eliminate software animation. Currently it is not
|
---|
| 558 | possible to force software animation of only normals. Consequently this
|
---|
| 559 | value is always less than or equal to that returned by getSoftwareAnimationRequests().
|
---|
| 560 | Requests for software animation of normals are made by calling the
|
---|
| 561 | addSoftwareAnimationRequest() method with 'true' as the parameter.
|
---|
| 562 | */
|
---|
| 563 | int getSoftwareAnimationNormalsRequests(void) const { return mSoftwareAnimationNormalsRequests; }
|
---|
| 564 | /** Add a request for software animation
|
---|
| 565 | @remarks
|
---|
| 566 | Tells the entity to perform animation calculations for skeletal/vertex
|
---|
| 567 | animations in software, regardless of the current setting of
|
---|
| 568 | isHardwareAnimationEnabled(). Software animation will be performed
|
---|
| 569 | any time one or more requests have been made. If 'normalsAlso' is
|
---|
| 570 | 'true', then the entity will also do software blending on normal
|
---|
| 571 | vectors, in addition to positions. This advanced method useful for
|
---|
| 572 | situations in which access to actual mesh vertices is required,
|
---|
| 573 | such as accurate collision detection or certain advanced shading
|
---|
| 574 | techniques. When software animation is no longer needed,
|
---|
| 575 | the caller of this method should always remove the request by calling
|
---|
| 576 | removeSoftwareAnimationRequest(), passing the same value for
|
---|
| 577 | 'normalsAlso'.
|
---|
| 578 | */
|
---|
| 579 | void addSoftwareAnimationRequest(bool normalsAlso);
|
---|
| 580 | /** Removes a request for software animation
|
---|
| 581 | @remarks
|
---|
| 582 | Calling this decrements the entity's internal counter of the number
|
---|
| 583 | of requests for software animation. If the counter is already zero
|
---|
| 584 | then calling this method throws an exception. The 'normalsAlso'
|
---|
| 585 | flag if set to 'true' will also decrement the internal counter of
|
---|
| 586 | number of requests for software animation of normals.
|
---|
| 587 | */
|
---|
| 588 | void removeSoftwareAnimationRequest(bool normalsAlso);
|
---|
| 589 |
|
---|
| 590 | /** Shares the SkeletonInstance with the supplied entity.
|
---|
| 591 | * Note that in order for this to work, both entities must have the same
|
---|
| 592 | * Skeleton.
|
---|
| 593 | */
|
---|
| 594 | void shareSkeletonInstanceWith(Entity* entity);
|
---|
| 595 |
|
---|
| 596 | /** Returns whether or not this entity is either morph or pose animated.
|
---|
| 597 | */
|
---|
| 598 | bool hasVertexAnimation(void) const;
|
---|
| 599 |
|
---|
| 600 |
|
---|
| 601 | /** Stops sharing the SkeletonInstance with other entities.
|
---|
| 602 | */
|
---|
| 603 | void stopSharingSkeletonInstance();
|
---|
| 604 |
|
---|
| 605 |
|
---|
| 606 | /**
|
---|
| 607 | * Returns whether this entity shares it's SkeltonInstance with other entity instances.
|
---|
| 608 | */
|
---|
| 609 | inline bool sharesSkeletonInstance() const { return mSharedSkeletonEntities != NULL; }
|
---|
| 610 |
|
---|
| 611 | /**
|
---|
| 612 | * Returns a pointer to the set of entities which share a SkeletonInstance.
|
---|
| 613 | * If this instance does not share it's SkeletonInstance with other instances NULL will be returned
|
---|
| 614 | */
|
---|
| 615 | inline const EntitySet* getSkeletonInstanceSharingSet() const { return mSharedSkeletonEntities; }
|
---|
| 616 |
|
---|
| 617 | /** Updates the internal animation state set to include the latest
|
---|
| 618 | available animations from the attached skeleton.
|
---|
| 619 | @remarks
|
---|
| 620 | Use this method if you manually add animations to a skeleton, or have
|
---|
| 621 | linked the skeleton to another for animation purposes since creating
|
---|
| 622 | this entity.
|
---|
| 623 | @note
|
---|
| 624 | If you have called getAnimationState prior to calling this method,
|
---|
| 625 | the pointers will still remain valid.
|
---|
| 626 | */
|
---|
| 627 | void refreshAvailableAnimationState(void);
|
---|
| 628 |
|
---|
| 629 | /** Advanced method to perform all the updates required for an animated entity.
|
---|
| 630 | @remarks
|
---|
| 631 | You don't normally need to call this, but it's here incase you wish
|
---|
| 632 | to manually update the animation of an Entity at a specific point in
|
---|
| 633 | time. Animation will not be updated more than once a frame no matter
|
---|
| 634 | how many times you call this method.
|
---|
| 635 | */
|
---|
| 636 | void _updateAnimation(void);
|
---|
| 637 |
|
---|
| 638 | /** Tests if any animation applied to this entity.
|
---|
| 639 | @remarks
|
---|
| 640 | An entity is animated if any animation state is enabled, or any manual bone
|
---|
| 641 | applied to the skeleton.
|
---|
| 642 | */
|
---|
| 643 | bool _isAnimated(void) const;
|
---|
| 644 |
|
---|
| 645 | /** Tests if skeleton was animated.
|
---|
| 646 | */
|
---|
| 647 | bool _isSkeletonAnimated(void) const;
|
---|
| 648 |
|
---|
| 649 | /** Advanced method to get the temporarily blended skeletal vertex information
|
---|
| 650 | for entities which are software skinned.
|
---|
| 651 | @remarks
|
---|
| 652 | Internal engine will eliminate software animation if possible, this
|
---|
| 653 | information is unreliable unless added request for software animation
|
---|
| 654 | via addSoftwareAnimationRequest.
|
---|
| 655 | @note
|
---|
| 656 | The positions/normals of the returned vertex data is in object space.
|
---|
| 657 | */
|
---|
| 658 | VertexData* _getSkelAnimVertexData(void) const;
|
---|
| 659 | /** Advanced method to get the temporarily blended software vertex animation information
|
---|
| 660 | @remarks
|
---|
| 661 | Internal engine will eliminate software animation if possible, this
|
---|
| 662 | information is unreliable unless added request for software animation
|
---|
| 663 | via addSoftwareAnimationRequest.
|
---|
| 664 | @note
|
---|
| 665 | The positions/normals of the returned vertex data is in object space.
|
---|
| 666 | */
|
---|
| 667 | VertexData* _getSoftwareVertexAnimVertexData(void) const;
|
---|
| 668 | /** Advanced method to get the hardware morph vertex information
|
---|
| 669 | @note
|
---|
| 670 | The positions/normals of the returned vertex data is in object space.
|
---|
| 671 | */
|
---|
| 672 | VertexData* _getHardwareVertexAnimVertexData(void) const;
|
---|
| 673 | /** Advanced method to get the temp buffer information for software
|
---|
| 674 | skeletal animation.
|
---|
| 675 | */
|
---|
| 676 | TempBlendedBufferInfo* _getSkelAnimTempBufferInfo(void);
|
---|
| 677 | /** Advanced method to get the temp buffer information for software
|
---|
| 678 | morph animation.
|
---|
| 679 | */
|
---|
| 680 | TempBlendedBufferInfo* _getVertexAnimTempBufferInfo(void);
|
---|
| 681 | /// Override to return specific type flag
|
---|
| 682 | uint32 getTypeFlags(void) const;
|
---|
| 683 | /// Retrieve the VertexData which should be used for GPU binding
|
---|
| 684 | VertexData* getVertexDataForBinding(void);
|
---|
| 685 |
|
---|
| 686 | /// Identify which vertex data we should be sending to the renderer
|
---|
| 687 | enum VertexDataBindChoice
|
---|
| 688 | {
|
---|
| 689 | BIND_ORIGINAL,
|
---|
| 690 | BIND_SOFTWARE_SKELETAL,
|
---|
| 691 | BIND_SOFTWARE_MORPH,
|
---|
| 692 | BIND_HARDWARE_MORPH
|
---|
| 693 | };
|
---|
| 694 | /// Choose which vertex data to bind to the renderer
|
---|
| 695 | VertexDataBindChoice chooseVertexDataForBinding(bool hasVertexAnim) const;
|
---|
| 696 |
|
---|
| 697 | /** Are buffers already marked as vertex animated? */
|
---|
| 698 | bool _getBuffersMarkedForAnimation(void) const { return mVertexAnimationAppliedThisFrame; }
|
---|
| 699 | /** Mark just this vertex data as animated.
|
---|
| 700 | */
|
---|
| 701 | void _markBuffersUsedForAnimation(void);
|
---|
| 702 |
|
---|
| 703 |
|
---|
| 704 | };
|
---|
| 705 |
|
---|
| 706 | /** Factory object for creating Entity instances */
|
---|
| 707 | class _OgreExport EntityFactory : public MovableObjectFactory
|
---|
| 708 | {
|
---|
| 709 | protected:
|
---|
| 710 | MovableObject* createInstanceImpl( const String& name, const NameValuePairList* params);
|
---|
| 711 | public:
|
---|
| 712 | EntityFactory() {}
|
---|
| 713 | ~EntityFactory() {}
|
---|
| 714 |
|
---|
| 715 | static String FACTORY_TYPE_NAME;
|
---|
| 716 |
|
---|
| 717 | const String& getType(void) const;
|
---|
| 718 | void destroyInstance( MovableObject* obj);
|
---|
| 719 |
|
---|
| 720 | };
|
---|
| 721 |
|
---|
| 722 | } // namespace
|
---|
| 723 |
|
---|
| 724 | #endif
|
---|