Coverage Report

Created: 2025-07-18 07:08

/src/ogre/OgreMain/include/OgreEntity.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
-----------------------------------------------------------------------------
3
This source file is part of OGRE
4
(Object-oriented Graphics Rendering Engine)
5
For the latest info, see http://www.ogre3d.org
6
7
Copyright (c) 2000-2014 Torus Knot Software Ltd
8
9
Permission is hereby granted, free of charge, to any person obtaining a copy
10
of this software and associated documentation files (the "Software"), to deal
11
in the Software without restriction, including without limitation the rights
12
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
copies of the Software, and to permit persons to whom the Software is
14
furnished to do so, subject to the following conditions:
15
16
The above copyright notice and this permission notice shall be included in
17
all copies or substantial portions of the Software.
18
19
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25
THE SOFTWARE.
26
-----------------------------------------------------------------------------
27
*/
28
#ifndef __Entity_H__
29
#define __Entity_H__
30
31
#include "OgrePrerequisites.h"
32
#include "OgreCommon.h"
33
34
#include "OgreMovableObject.h"
35
#include "OgreQuaternion.h"
36
#include "OgreVector.h"
37
#include "OgreHardwareBufferManager.h"
38
#include "OgreRenderable.h"
39
#include "OgreResourceGroupManager.h"
40
#include "OgreHeaderPrefix.h"
41
42
namespace Ogre {
43
    /** \addtogroup Core
44
    *  @{
45
    */
46
    /** \addtogroup Scene
47
    *  @{
48
    */
49
    /** Defines an instance of a discrete, movable object based on a Mesh.
50
51
        %Ogre generally divides renderable objects into 2 groups, discrete
52
        (separate) and relatively small objects which move around the world,
53
        and large, sprawling geometry which makes up generally immovable
54
        scenery, aka 'level geometry'.
55
56
        The Mesh and SubMesh classes deal with the definition of the geometry
57
        used by discrete movable objects. Entities are actual instances of
58
        objects based on this geometry in the world. Therefore there is
59
        usually a single set Mesh for a car, but there may be multiple
60
        entities based on it in the world. Entities are able to override
61
        aspects of the Mesh it is defined by, such as changing material
62
        properties per instance (so you can have many cars using the same
63
        geometry but different textures for example). Because a Mesh is split
64
        into SubMeshes for this purpose, the Entity class is a grouping class
65
        (much like the Mesh class) and much of the detail regarding
66
        individual changes is kept in the SubEntity class. There is a 1:1
67
        relationship between SubEntity instances and the SubMesh instances
68
        associated with the Mesh the Entity is based on.
69
70
        Entity and SubEntity classes are never created directly. Use the
71
        createEntity method of the SceneManager (passing a model name) to
72
        create one.
73
74
        Entities are included in the scene by associating them with a
75
        SceneNode, using the @ref SceneNode::attachObject method.
76
    @note
77
        No functions were declared virtual to improve performance.
78
    */
79
    class _OgreExport Entity: public MovableObject, public Resource::Listener
80
    {
81
        // Allow EntityFactory full access
82
        friend class EntityFactory;
83
        friend class SubEntity;
84
    public:
85
        
86
        typedef std::set<Entity*> EntitySet;
87
        typedef std::vector<std::pair<unsigned short, bool>> SchemeHardwareAnimMap;
88
        typedef std::vector<SubEntity*> SubEntityList;
89
    private:
90
91
        /** Private constructor (instances cannot be created directly).
92
        */
93
        Entity();
94
        /** Private constructor - specify name (the usual constructor used).
95
        */
96
        Entity( const String& name, const MeshPtr& mesh);
97
98
        /** The Mesh that this Entity is based on.
99
        */
100
        MeshPtr mMesh;
101
102
        /** List of SubEntities (point to SubMeshes).
103
        */
104
        SubEntityList mSubEntityList;
105
106
107
        /// State of animation for animable meshes
108
        AnimationStateSet* mAnimationState;
109
110
        /** Structure for recording the use of temporary blend buffers. */
111
        class TempBlendedBufferInfo : public HardwareBufferLicensee
112
        {
113
        private:
114
            // Pre-blended
115
            HardwareVertexBufferPtr srcPositionBuffer;
116
            HardwareVertexBufferPtr srcNormalBuffer;
117
            // Post-blended
118
            HardwareVertexBufferPtr destPositionBuffer;
119
            HardwareVertexBufferPtr destNormalBuffer;
120
            unsigned short posBindIndex;
121
            unsigned short normBindIndex;
122
            /// Both positions and normals are contained in the same buffer.
123
            bool posNormalShareBuffer;
124
            bool posNormalExtraData;
125
            bool bindPositions;
126
            bool bindNormals;
127
128
        public:
129
            ~TempBlendedBufferInfo(void);
130
            /// Utility method, extract info from the given VertexData.
131
            void extractFrom(const VertexData* sourceData);
132
            /// Utility method, checks out temporary copies of src into dest.
133
            void checkoutTempCopies(bool positions = true, bool normals = true);
134
            /// Utility method, binds dest copies into a given VertexData struct.
135
            void bindTempCopies(VertexData* targetData, bool suppressHardwareUpload);
136
            /** Overridden member from HardwareBufferLicensee. */
137
            void licenseExpired(HardwareBuffer* buffer) override;
138
            /** Detect currently have buffer copies checked out and touch it. */
139
            bool buffersCheckedOut(bool positions = true, bool normals = true) const;
140
        };
141
142
143
        /// Temp buffer details for software skeletal anim of shared geometry
144
        TempBlendedBufferInfo mTempSkelAnimInfo;
145
        /// Vertex data details for software skeletal anim of shared geometry
146
        std::unique_ptr<VertexData> mSkelAnimVertexData;
147
        /// Temp buffer details for software vertex anim of shared geometry
148
        TempBlendedBufferInfo mTempVertexAnimInfo;
149
        /// Vertex data details for software vertex anim of shared geometry
150
        std::unique_ptr<VertexData> mSoftwareVertexAnimVertexData;
151
        /// Vertex data details for hardware vertex anim of shared geometry
152
        /// - separate since we need to s/w anim for shadows whilst still altering
153
        ///   the vertex data for hardware morphing (pos2 binding)
154
        std::unique_ptr<VertexData> mHardwareVertexAnimVertexData;
155
156
        /// Have we applied any vertex animation to shared geometry?
157
        bool mVertexAnimationAppliedThisFrame : 1;
158
        /// Have the temp buffers already had their geometry prepared for use in rendering shadow volumes?
159
        bool mPreparedForShadowVolumes : 1;
160
        /// Flag determines whether or not to display skeleton.
161
        bool mDisplaySkeleton : 1;
162
        /// Current state of the hardware animation as represented by the entities parameters.
163
        bool mCurrentHWAnimationState : 1;
164
        /// Flag indicating whether to skip automatic updating of the Skeleton's AnimationState.
165
        bool mSkipAnimStateUpdates : 1;
166
        /// Flag indicating whether to update the main entity skeleton even when an LOD is displayed.
167
        bool mAlwaysUpdateMainSkeleton : 1;
168
        /// Flag indicating whether to update the bounding box from the bones of the skeleton.
169
        bool mUpdateBoundingBoxFromSkeleton : 1;
170
        /// Flag indicating whether we have a vertex program in use on any of our subentities.
171
        bool mVertexProgramInUse : 1;
172
        /// Has this entity been initialised yet?
173
        bool mInitialised : 1;
174
175
        /** Internal method - given vertex data which could be from the Mesh or
176
            any submesh, finds the temporary blend copy.
177
        */
178
        const VertexData* findBlendedVertexData(const VertexData* orig);
179
        /** Internal method - given vertex data which could be from the Mesh or
180
            any SubMesh, finds the corresponding SubEntity.
181
        */
182
        SubEntity* findSubEntityForVertexData(const VertexData* orig);
183
184
        /** Internal method for preparing this Entity for use in animation. */
185
        void prepareTempBlendBuffers(void);
186
        /** Mark all vertex data as so far unanimated.
187
        */
188
        void markBuffersUnusedForAnimation(void);
189
        /** Internal method to restore original vertex data where we didn't
190
            perform any vertex animation this frame.
191
        */
192
        void restoreBuffersForUnusedAnimation(bool hardwareAnimation);
193
194
        /** Ensure that any unbound  pose animation buffers are bound to a safe
195
            default.
196
        @param srcData
197
            Original vertex data containing original positions.
198
        @param destData
199
            Hardware animation vertex data to be checked.
200
        */
201
        void bindMissingHardwarePoseBuffers(const VertexData* srcData, 
202
            VertexData* destData);
203
            
204
        /** When performing software pose animation, initialise software copy
205
            of vertex data.
206
        */
207
        void initialisePoseVertexData(const VertexData* srcData, VertexData* destData, 
208
            bool animateNormals);
209
210
        /** When animating normals for pose animation, finalise normals by filling in
211
            with the reference mesh normal where applied normal weights < 1.
212
        */
213
        void finalisePoseNormals(const VertexData* srcData, VertexData* destData);
214
215
        /// Number of hardware poses supported by materials.
216
        ushort mHardwarePoseCount;
217
        ushort mNumBoneMatrices;
218
        /// Cached bone matrices, including any world transform.
219
        Affine3 *mBoneWorldMatrices;
220
        /// Cached bone matrices in skeleton local space, might shares with other entity instances.
221
        Affine3 *mBoneMatrices;
222
        /// Records the last frame in which animation was updated.
223
        unsigned long mFrameAnimationLastUpdated;
224
225
        /// Perform all the updates required for an animated entity.
226
        void updateAnimation(void);
227
228
        /// Records the last frame in which the bones was updated.
229
        /// It's a pointer because it can be shared between different entities with
230
        /// a shared skeleton.
231
        unsigned long *mFrameBonesLastUpdated;
232
233
        /** A set of all the entities which shares a single SkeletonInstance.
234
            This is only created if the entity is in fact sharing it's SkeletonInstance with
235
            other Entities.
236
        */
237
        EntitySet* mSharedSkeletonEntities;
238
239
        /** Private method to cache bone matrices from skeleton.
240
        @return
241
            True if the bone matrices cache has been updated. False if note.
242
        */
243
        bool cacheBoneMatrices(void);
244
245
        /** Flag indicating whether hardware animation is supported by this entities materials
246
            data is saved per scehme number.
247
        */
248
        SchemeHardwareAnimMap mSchemeHardwareAnim;
249
250
        /// Counter indicating number of requests for software animation.
251
        int mSoftwareAnimationRequests;
252
        /// Counter indicating number of requests for software blended normals.
253
        int mSoftwareAnimationNormalsRequests;
254
255
256
#if !OGRE_NO_MESHLOD
257
        /// The LOD number of the mesh to use, calculated by _notifyCurrentCamera.
258
        ushort mMeshLodIndex;
259
260
        /// LOD bias factor, transformed for optimisation when calculating adjusted LOD value.
261
        Real mMeshLodFactorTransformed;
262
        /// Index of minimum detail LOD (NB higher index is lower detail).
263
        ushort mMinMeshLodIndex;
264
        /// Index of maximum detail LOD (NB lower index is higher detail).
265
        ushort mMaxMeshLodIndex;
266
267
        /** List of LOD Entity instances (for manual LODs).
268
            We don't know when the mesh is using manual LODs whether one LOD to the next will have the
269
            same number of SubMeshes, therefore we have to allow a separate Entity list
270
            with each alternate one.
271
        */
272
        typedef std::vector<Entity*> LODEntityList;
273
        LODEntityList mLodEntityList;
274
#else
275
        const ushort mMeshLodIndex;
276
        const Real mMeshLodFactorTransformed;
277
        const ushort mMinMeshLodIndex;
278
        const ushort mMaxMeshLodIndex;
279
#endif
280
        /// LOD bias factor, not transformed.
281
        Real mMaterialLodFactor;
282
        /// Index of minimum detail LOD (NB higher index is lower detail).
283
        ushort mMinMaterialLodIndex;
284
        /// Index of maximum detail LOD (NB lower index is higher detail).
285
        ushort mMaxMaterialLodIndex;
286
        /** This Entity's personal copy of the skeleton, if skeletally animated.
287
        */
288
        SkeletonInstance* mSkeletonInstance;
289
290
        /// Last parent transform.
291
        Affine3 mLastParentXform;
292
293
        /// Mesh state count, used to detect differences.
294
        size_t mMeshStateCount;
295
296
        /** Builds a list of SubEntities based on the SubMeshes contained in the Mesh. */
297
        void buildSubEntityList(MeshPtr& mesh, SubEntityList* sublist);
298
299
        /// Internal implementation of attaching a 'child' object to this entity and assign the parent node to the child entity.
300
        void attachObjectImpl(MovableObject *pMovable, TagPoint *pAttachingPoint);
301
302
        /// Internal implementation of detaching a 'child' object of this entity and clear the parent node of the child entity.
303
        void detachObjectImpl(MovableObject* pObject);
304
305
        /// Internal implementation of detaching all 'child' objects of this entity.
306
        void detachAllObjectsImpl(void);
307
308
        /// Ensures reevaluation of the vertex processing usage.
309
        void reevaluateVertexProcessing(void);
310
311
        /** Calculates the kind of vertex processing in use.
312
313
            This function's return value is calculated according to the current 
314
            active scheme. This is due to the fact that RTSS schemes may be different
315
            in their handling of hardware animation.
316
        */
317
        bool calcVertexProcessing(void);
318
    
319
        /// Apply vertex animation.
320
        void applyVertexAnimation(bool hardwareAnimation, bool stencilShadows);
321
        /// Initialise the hardware animation elements for given vertex data.
322
        ushort initHardwareAnimationElements(VertexData* vdata, ushort numberOfElements, bool animateNormals);
323
        /// Are software vertex animation temp buffers bound?
324
        bool tempVertexAnimBuffersBound(void) const;
325
        /// Are software skeleton animation temp buffers bound?
326
        bool tempSkelAnimBuffersBound(bool requestNormals) const;
327
328
    public:
329
        /// Contains the child objects (attached to bones) indexed by name.
330
        typedef std::vector<MovableObject*> ChildObjectList;
331
    private:
332
        ChildObjectList mChildObjectList;
333
334
335
        /// Bounding box that 'contains' all the mesh of each child entity.
336
        mutable AxisAlignedBox mFullBoundingBox;  // note: this exists only so that getBoundingBox() can return an AAB by reference
337
338
        ShadowRenderableList mShadowRenderables;
339
340
        /** Nested class to allow entity shadows. */
341
        class EntityShadowRenderable : public ShadowRenderable
342
        {
343
            /// Link to current vertex data used to bind (maybe changes).
344
            const VertexData* mCurrentVertexData;
345
            /// Link to SubEntity, only present if SubEntity has it's own geometry.
346
            SubEntity* mSubEntity;
347
            /// Original position buffer source binding.
348
            ushort mOriginalPosBufferBinding;
349
350
        public:
351
            EntityShadowRenderable(MovableObject* parent,
352
                const HardwareIndexBufferSharedPtr& indexBuffer, const VertexData* vertexData,
353
                bool createSeparateLightCap, SubEntity* subent, bool isLightCap = false);
354
            
355
            /// Create the separate light cap if it doesn't already exists.
356
            void _createSeparateLightCap();
357
            /// Rebind the source positions (for temp buffer users).
358
            void rebindPositionBuffer(const VertexData* vertexData, bool force);
359
            bool isVisible(void) const override;
360
        };
361
    public:
362
        /** Default destructor.
363
        */
364
        ~Entity();
365
366
        /** Gets the Mesh that this Entity is based on.
367
        */
368
        const MeshPtr& getMesh(void) const;
369
370
        /** Gets a pointer to a SubEntity, ie a part of an Entity.
371
        */
372
0
        SubEntity* getSubEntity(size_t index) const { return mSubEntityList.at(index); }
373
374
        /** Gets a pointer to a SubEntity by name
375
376
            Names should be initialized during a Mesh creation.
377
        */
378
        SubEntity* getSubEntity( const String& name ) const;
379
380
        /** Retrieves the number of SubEntity objects making up this entity.
381
        */
382
0
        size_t getNumSubEntities(void) const { return mSubEntityList.size(); }
383
384
        /** Retrieves SubEntity objects making up this entity.
385
        */
386
0
        const SubEntityList& getSubEntities() const {
387
0
            return mSubEntityList;
388
0
        }
389
390
        /** Clones this entity and returns a pointer to the clone.
391
392
            Useful method for duplicating an entity. The new entity must be
393
            given a unique name, and is not attached to the scene in any way
394
            so must be attached to a SceneNode to be visible (exactly as
395
            entities returned from SceneManager::createEntity).
396
        @param newName
397
            Name for the new entity.
398
        */
399
        Entity* clone( const String& newName ) const;
400
401
        /** Sets the material to use for the whole of this entity.
402
403
            This is a shortcut method to set all the materials for all
404
            subentities of this entity. Only use this method is you want to
405
            set the same material for all subentities or if you know there
406
            is only one. Otherwise call getSubEntity() and call the same
407
            method on the individual SubEntity.
408
        */
409
        void setMaterialName( const String& name, const String& groupName = ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME );
410
411
        
412
        /** Sets the material to use for the whole of this entity.
413
414
            This is a shortcut method to set all the materials for all
415
            subentities of this entity. Only use this method is you want to
416
            set the same material for all subentities or if you know there
417
            is only one. Otherwise call getSubEntity() and call the same
418
            method on the individual SubEntity.
419
        */
420
        void setMaterial(const MaterialPtr& material);
421
422
        void _releaseManualHardwareResources() override;
423
        void _restoreManualHardwareResources() override;
424
425
        void _notifyCurrentCamera(Camera* cam) override;
426
427
        void setRenderQueueGroup(uint8 queueID) override;
428
429
        void setRenderQueueGroupAndPriority(uint8 queueID, ushort priority) override;
430
431
        const AxisAlignedBox& getBoundingBox(void) const override;
432
433
        /// Merge all the child object Bounds a return it.
434
        AxisAlignedBox getChildObjectsBoundingBox(void) const;
435
436
        void _updateRenderQueue(RenderQueue* queue) override;
437
        const String& getMovableType(void) const override;
438
439
        /** For entities based on animated meshes, gets the AnimationState object for a single animation.
440
441
            You animate an entity by updating the animation state objects. Each of these represents the
442
            current state of each animation available to the entity. The AnimationState objects are
443
            initialised from the Mesh object.
444
        */
445
        AnimationState* getAnimationState(const String& name) const;
446
        /** Returns whether the AnimationState with the given name exists. */
447
        bool hasAnimationState(const String& name) const;
448
        /** For entities based on animated meshes, gets the AnimationState objects for all animations.
449
        @return
450
            In case the entity is animated, this functions returns the pointer to a AnimationStateSet
451
            containing all animations of the entries. If the entity is not animated, it returns 0.
452
453
            You animate an entity by updating the animation state objects. Each of these represents the
454
            current state of each animation available to the entity. The AnimationState objects are
455
            initialised from the Mesh object.
456
        */
457
        AnimationStateSet* getAllAnimationStates(void) const;
458
459
        /** Tells the Entity whether or not it should display it's skeleton, if it has one.
460
        */
461
        void setDisplaySkeleton(bool display);
462
463
        /** Returns whether or not the entity is currently displaying its skeleton.
464
        */
465
        bool getDisplaySkeleton(void) const;
466
467
        /** Returns the number of manual levels of detail that this entity supports.
468
469
            This number never includes the original entity, it is difference
470
            with Mesh::getNumLodLevels.
471
        */
472
        size_t getNumManualLodLevels(void) const;
473
474
        /** Returns the current LOD used to render
475
        */
476
0
        ushort getCurrentLodIndex() { return mMeshLodIndex; }
477
478
        /** Gets a pointer to the entity representing the numbered manual level of detail.
479
480
            The zero-based index never includes the original entity, unlike
481
            Mesh::getLodLevel.
482
        */
483
        Entity* getManualLodLevel(size_t index) const;
484
485
#if !OGRE_NO_MESHLOD
486
        /** Sets a level-of-detail bias for the mesh detail of this entity.
487
488
            Level of detail reduction is normally applied automatically based on the Mesh
489
            settings. However, it is possible to influence this behaviour for this entity
490
            by adjusting the LOD bias. This 'nudges' the mesh level of detail used for this
491
            entity up or down depending on your requirements. You might want to use this
492
            if there was a particularly important entity in your scene which you wanted to
493
            detail better than the others, such as a player model.
494
        @par
495
            There are three parameters to this method; the first is a factor to apply; it
496
            defaults to 1.0 (no change), by increasing this to say 2.0, this model would
497
            take twice as long to reduce in detail, whilst at 0.5 this entity would use lower
498
            detail versions twice as quickly. The other 2 parameters are hard limits which
499
            let you set the maximum and minimum level-of-detail version to use, after all
500
            other calculations have been made. This lets you say that this entity should
501
            never be simplified, or that it can only use LODs below a certain level even
502
            when right next to the camera.
503
        @param factor
504
            Proportional factor to apply to the distance at which LOD is changed.
505
            Higher values increase the distance at which higher LODs are displayed (2.0 is
506
            twice the normal distance, 0.5 is half).
507
        @param maxDetailIndex
508
            The index of the maximum LOD this entity is allowed to use (lower
509
            indexes are higher detail: index 0 is the original full detail model).
510
        @param minDetailIndex
511
            The index of the minimum LOD this entity is allowed to use (higher
512
            indexes are lower detail). Use something like 99 if you want unlimited LODs (the actual
513
            LOD will be limited by the number in the Mesh).
514
        */
515
        void setMeshLodBias(Real factor, ushort maxDetailIndex = 0, ushort minDetailIndex = 99);
516
#endif
517
        /** Sets a level-of-detail bias for the material detail of this entity.
518
519
            Level of detail reduction is normally applied automatically based on the Material
520
            settings. However, it is possible to influence this behaviour for this entity
521
            by adjusting the LOD bias. This 'nudges' the material level of detail used for this
522
            entity up or down depending on your requirements. You might want to use this
523
            if there was a particularly important entity in your scene which you wanted to
524
            detail better than the others, such as a player model.
525
        @par
526
            There are three parameters to this method; the first is a factor to apply; it
527
            defaults to 1.0 (no change), by increasing this to say 2.0, this entity would
528
            take twice as long to use a lower detail material, whilst at 0.5 this entity
529
            would use lower detail versions twice as quickly. The other 2 parameters are
530
            hard limits which let you set the maximum and minimum level-of-detail index
531
            to use, after all other calculations have been made. This lets you say that
532
            this entity should never be simplified, or that it can only use LODs below
533
            a certain level even when right next to the camera.
534
        @param factor
535
            Proportional factor to apply to the distance at which LOD is changed.
536
            Higher values increase the distance at which higher LODs are displayed (2.0 is
537
            twice the normal distance, 0.5 is half).
538
        @param maxDetailIndex
539
            The index of the maximum LOD this entity is allowed to use (lower
540
            indexes are higher detail: index 0 is the original full detail model).
541
        @param minDetailIndex
542
            The index of the minimum LOD this entity is allowed to use (higher
543
            indexes are lower detail. Use something like 99 if you want unlimited LODs (the actual
544
            LOD will be limited by the number of LOD indexes used in the Material).
545
        */
546
        void setMaterialLodBias(Real factor, ushort maxDetailIndex = 0, ushort minDetailIndex = 99);
547
548
        /** Sets whether the polygon mode of this entire entity may be
549
            overridden by the camera detail settings.
550
        */
551
        void setPolygonModeOverrideable(bool PolygonModeOverrideable);
552
        /** Attaches another object to a certain bone of the skeleton which this entity uses.
553
554
            This method can be used to attach another object to an animated part of this entity,
555
            by attaching it to a bone in the skeleton (with an offset if required). As this entity
556
            is animated, the attached object will move relative to the bone to which it is attached.
557
        @par
558
            An exception is thrown if the movable object is already attached to the bone, another bone or scenenode.
559
            If the entity has no skeleton or the bone name cannot be found then an exception is thrown.
560
        @param boneName
561
            The name of the bone (in the skeleton) to attach this object
562
        @param pMovable
563
            Pointer to the object to attach
564
        @param offsetOrientation
565
            An adjustment to the orientation of the attached object, relative to the bone.
566
        @param offsetPosition
567
            An adjustment to the position of the attached object, relative to the bone.
568
        @return
569
            The TagPoint to which the object has been attached
570
        */
571
        TagPoint* attachObjectToBone(const String &boneName,
572
            MovableObject *pMovable,
573
            const Quaternion &offsetOrientation = Quaternion::IDENTITY,
574
            const Vector3 &offsetPosition = Vector3::ZERO);
575
576
        /** Detach a MovableObject previously attached using attachObjectToBone.
577
            If the movable object name is not found then an exception is raised.
578
        @param movableName
579
            The name of the movable object to be detached.
580
        */
581
        MovableObject* detachObjectFromBone(const String &movableName);
582
583
        /** Detaches an object by pointer.
584
585
            Use this method to destroy a MovableObject which is attached to a bone of belonging this entity.
586
            But sometimes the object may be not in the child object list because it is a LOD entity,
587
            this method can safely detect and ignore in this case and won't raise an exception.
588
        */
589
        void detachObjectFromBone(MovableObject* obj);
590
591
        /// Detach all MovableObjects previously attached using attachObjectToBone
592
        void detachAllObjectsFromBone(void);
593
594
        typedef VectorIterator<ChildObjectList> ChildObjectListIterator;
595
        /// @deprecated use getAttachedObjects()
596
        OGRE_DEPRECATED ChildObjectListIterator getAttachedObjectIterator(void);
597
        /** Gets an iterator to the list of objects attached to bones on this entity. */
598
0
        const ChildObjectList& getAttachedObjects() const { return mChildObjectList; }
599
600
        Real getBoundingRadius(void) const override;
601
        const AxisAlignedBox& getWorldBoundingBox(bool derive = false) const override;
602
        const Sphere& getWorldBoundingSphere(bool derive = false) const override;
603
604
        EdgeData* getEdgeList(void) override;
605
        const ShadowRenderableList& getShadowVolumeRenderableList(
606
            const Light* light, const HardwareIndexBufferPtr& indexBuffer,
607
            size_t& indexBufferUsedSize, float extrusionDistance, int flags = 0) override;
608
609
        /** Internal method for retrieving bone matrix information. */
610
0
        const Affine3* _getBoneMatrices(void) const { return mBoneMatrices;}
611
        /** Internal method for retrieving bone matrix information. */
612
0
        unsigned short _getNumBoneMatrices(void) const { return mNumBoneMatrices; }
613
        /** Returns whether or not this entity is skeletally animated. */
614
0
        bool hasSkeleton(void) const { return mSkeletonInstance != 0; }
615
        /** Get this Entity's personal skeleton instance. */
616
0
        SkeletonInstance* getSkeleton(void) const { return mSkeletonInstance; }
617
        /** Returns whether or not hardware animation is enabled.
618
619
            Because fixed-function indexed vertex blending is rarely supported
620
            by existing graphics cards, hardware animation can only be done if
621
            the vertex programs in the materials used to render an entity support
622
            it. Therefore, this method will only return true if all the materials
623
            assigned to this entity have vertex programs assigned, and all those
624
            vertex programs must support 'includes_morph_animation true' if using
625
            morph animation, 'includes_pose_animation true' if using pose animation
626
            and 'includes_skeletal_animation true' if using skeletal animation.
627
628
            Also note the the function returns value according to the current active
629
            scheme. This is due to the fact that RTSS schemes may be different in their
630
            handling of hardware animation.
631
        */
632
        bool isHardwareAnimationEnabled(void);
633
634
        void _notifyAttached(Node* parent, bool isTagPoint = false) override;
635
        /** Returns the number of requests that have been made for software animation
636
637
            If non-zero then software animation will be performed in updateAnimation
638
            regardless of the current setting of isHardwareAnimationEnabled or any
639
            internal optimise for eliminate software animation. Requests for software
640
            animation are made by calling the addSoftwareAnimationRequest() method.
641
        */
642
0
        int getSoftwareAnimationRequests(void) const { return mSoftwareAnimationRequests; }
643
        /** Returns the number of requests that have been made for software animation of normals
644
645
            If non-zero, and getSoftwareAnimationRequests() also returns non-zero,
646
            then software animation of normals will be performed in updateAnimation
647
            regardless of the current setting of isHardwareAnimationEnabled or any
648
            internal optimise for eliminate software animation. Currently it is not
649
            possible to force software animation of only normals. Consequently this
650
            value is always less than or equal to that returned by getSoftwareAnimationRequests().
651
            Requests for software animation of normals are made by calling the
652
            addSoftwareAnimationRequest() method with 'true' as the parameter.
653
        */
654
0
        int getSoftwareAnimationNormalsRequests(void) const { return mSoftwareAnimationNormalsRequests; }
655
        /** Add a request for software animation
656
657
            Tells the entity to perform animation calculations for skeletal/vertex
658
            animations in software, regardless of the current setting of
659
            isHardwareAnimationEnabled().  Software animation will be performed
660
            any time one or more requests have been made.  If 'normalsAlso' is
661
            'true', then the entity will also do software blending on normal
662
            vectors, in addition to positions. This advanced method useful for
663
            situations in which access to actual mesh vertices is required,
664
            such as accurate collision detection or certain advanced shading
665
            techniques. When software animation is no longer needed,
666
            the caller of this method should always remove the request by calling
667
            removeSoftwareAnimationRequest(), passing the same value for
668
            'normalsAlso'.
669
        */
670
        void addSoftwareAnimationRequest(bool normalsAlso);
671
        /** Removes a request for software animation
672
673
            Calling this decrements the entity's internal counter of the number
674
            of requests for software animation.  If the counter is already zero
675
            then calling this method throws an exception.  The 'normalsAlso'
676
            flag if set to 'true' will also decrement the internal counter of
677
            number of requests for software animation of normals.
678
        */
679
        void removeSoftwareAnimationRequest(bool normalsAlso);
680
681
        /** Shares the SkeletonInstance with the supplied entity.
682
            Note that in order for this to work, both entities must have the same
683
            Skeleton.
684
        */
685
        void shareSkeletonInstanceWith(Entity* entity);
686
687
        /** Returns whether or not this entity is either morph or pose animated.
688
        */
689
        bool hasVertexAnimation(void) const;
690
691
692
        /** Stops sharing the SkeletonInstance with other entities.
693
        */
694
        void stopSharingSkeletonInstance();
695
696
697
        /** Returns whether this entity shares it's SkeltonInstance with other entity instances.
698
        */
699
0
        inline bool sharesSkeletonInstance() const { return mSharedSkeletonEntities != NULL; }
700
701
        /** Returns a pointer to the set of entities which share a SkeletonInstance.
702
            If this instance does not share it's SkeletonInstance with other instances @c NULL will be returned
703
        */
704
0
        inline const EntitySet* getSkeletonInstanceSharingSet() const { return mSharedSkeletonEntities; }
705
706
        /** Updates the internal animation state set to include the latest
707
            available animations from the attached skeleton.
708
709
            Use this method if you manually add animations to a skeleton, or have
710
            linked the skeleton to another for animation purposes since creating
711
            this entity.
712
        @note
713
            If you have called getAnimationState prior to calling this method,
714
            the pointers will still remain valid.
715
        */
716
        void refreshAvailableAnimationState(void);
717
718
        /** Advanced method to perform all the updates required for an animated entity.
719
720
            You don't normally need to call this, but it's here in case you wish
721
            to manually update the animation of an Entity at a specific point in
722
            time. Animation will not be updated more than once a frame no matter
723
            how many times you call this method.
724
        */
725
        void _updateAnimation(void);
726
727
        /** Tests if any animation applied to this entity.
728
729
            An entity is animated if any animation state is enabled, or any manual bone
730
            applied to the skeleton.
731
        */
732
        bool _isAnimated(void) const;
733
734
        /** Tests if skeleton was animated.
735
        */
736
        bool _isSkeletonAnimated(void) const;
737
738
        /** Advanced method to get the temporarily blended skeletal vertex information
739
            for entities which are software skinned.
740
741
            Internal engine will eliminate software animation if possible, this
742
            information is unreliable unless added request for software animation
743
            via addSoftwareAnimationRequest.
744
        @note
745
            The positions/normals of the returned vertex data is in object space.
746
        */
747
        VertexData* _getSkelAnimVertexData(void) const;
748
        /** Advanced method to get the temporarily blended software vertex animation information
749
750
            Internal engine will eliminate software animation if possible, this
751
            information is unreliable unless added request for software animation
752
            via addSoftwareAnimationRequest.
753
        @note
754
            The positions/normals of the returned vertex data is in object space.
755
        */
756
        VertexData* _getSoftwareVertexAnimVertexData(void) const;
757
        /** Advanced method to get the hardware morph vertex information
758
        @note
759
            The positions/normals of the returned vertex data is in object space.
760
        */
761
        VertexData* _getHardwareVertexAnimVertexData(void) const;
762
        /// Override to return specific type flag.
763
        uint32 getTypeFlags(void) const override;
764
        /// Retrieve the VertexData which should be used for GPU binding.
765
        VertexData* getVertexDataForBinding(void);
766
767
        /// Identify which vertex data we should be sending to the renderer.
768
        enum VertexDataBindChoice
769
        {
770
            BIND_ORIGINAL,
771
            BIND_SOFTWARE_SKELETAL,
772
            BIND_SOFTWARE_MORPH,
773
            BIND_HARDWARE_MORPH
774
        };
775
        /// Choose which vertex data to bind to the renderer.
776
        VertexDataBindChoice chooseVertexDataForBinding(bool hasVertexAnim);
777
778
        /** Are buffers already marked as vertex animated? */
779
0
        bool _getBuffersMarkedForAnimation(void) const { return mVertexAnimationAppliedThisFrame; }
780
        /** Mark just this vertex data as animated.
781
        */
782
        void _markBuffersUsedForAnimation(void);
783
784
        /** Has this Entity been initialised yet?
785
786
            If this returns false, it means this Entity hasn't been completely
787
            constructed yet from the underlying resources (Mesh, Skeleton), which 
788
            probably means they were delay-loaded and aren't available yet. This
789
            Entity won't render until it has been successfully initialised, nor
790
            will many of the manipulation methods function.
791
        */
792
0
        bool isInitialised(void) const { return mInitialised; }
793
794
        /** Try to initialise the Entity from the underlying resources.
795
796
            This method builds the internal structures of the Entity based on it
797
            resources (Mesh, Skeleton). This may or may not succeed if the 
798
            resources it references have been earmarked for background loading,
799
            so you should check isInitialised afterwards to see if it was successful.
800
        @param forceReinitialise
801
            If @c true, this forces the Entity to tear down it's
802
            internal structures and try to rebuild them. Useful if you changed the
803
            content of a Mesh or Skeleton at runtime.
804
        */
805
        void _initialise(bool forceReinitialise = false);
806
        /** Tear down the internal structures of this Entity, rendering it uninitialised. */
807
        void _deinitialise(void);
808
809
        /** Resource::Listener hook to notify Entity that a delay-loaded Mesh is
810
            complete.
811
        */
812
        void loadingComplete(Resource* res) override;
813
814
        void visitRenderables(Renderable::Visitor* visitor, bool debugRenderables = false) override;
815
816
        /** Get the LOD strategy transformation of the mesh LOD factor. */
817
        Real _getMeshLodFactorTransformed() const;
818
        
819
        /** Entity's skeleton's AnimationState will not be automatically updated when set to true.
820
            Useful if you wish to handle AnimationState updates manually.
821
        */
822
0
        void setSkipAnimationStateUpdate(bool skip) {
823
0
            mSkipAnimStateUpdates = skip;
824
0
        }
825
        
826
        /** Entity's skeleton's AnimationState will not be automatically updated when set to true.
827
            Useful if you wish to handle AnimationState updates manually.
828
        */
829
0
        bool getSkipAnimationStateUpdate() const {
830
0
            return mSkipAnimStateUpdates;
831
0
        }
832
833
        /** The skeleton of the main entity will be updated even if the an LOD entity is being displayed.
834
            useful if you have entities attached to the main entity. Otherwise position of attached
835
            entities will not be updated.
836
        */
837
0
        void setAlwaysUpdateMainSkeleton(bool update) {
838
0
            mAlwaysUpdateMainSkeleton = update;
839
0
        }
840
841
        /** The skeleton of the main entity will be updated even if the an LOD entity is being displayed.
842
            useful if you have entities attached to the main entity. Otherwise position of attached
843
            entities will not be updated.
844
        */
845
0
        bool getAlwaysUpdateMainSkeleton() const {
846
0
            return mAlwaysUpdateMainSkeleton;
847
0
        }
848
849
        /** If true, the skeleton of the entity will be used to update the bounding box for culling.
850
            Useful if you have skeletal animations that move the bones away from the root.  Otherwise, the
851
            bounding box of the mesh in the binding pose will be used.
852
853
            When true, the bounding box will be generated to only enclose the bones that are used for skinning.
854
            Also the resulting bounding box will be expanded by the amount of GetMesh()->getBoneBoundingRadius().
855
            The expansion amount can be changed on the mesh to achieve a better fitting bounding box.
856
        */
857
        void setUpdateBoundingBoxFromSkeleton(bool update);
858
859
        /** If true, the skeleton of the entity will be used to update the bounding box for culling.
860
            Useful if you have skeletal animations that move the bones away from the root.  Otherwise, the
861
            bounding box of the mesh in the binding pose will be used.
862
        */
863
0
        bool getUpdateBoundingBoxFromSkeleton() const {
864
0
            return mUpdateBoundingBoxFromSkeleton;
865
0
        }
866
867
        
868
    };
869
    /** @} */
870
    /** @} */
871
872
} // namespace Ogre
873
874
#include "OgreHeaderSuffix.h"
875
876
#endif // __Entity_H__