source: OGRE/trunk/ogrenew/OgreMain/include/OgreEntity.h @ 692

Revision 692, 31.8 KB checked in by mattausch, 18 years ago (diff)

adding ogre 1.2 and dependencies

Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4(Object-oriented Graphics Rendering Engine)
5For the latest info, see http://ogre.sourceforge.net/
6
7Copyright (c) 2000-2005 The OGRE Team
8Also see acknowledgements in Readme.html
9
10This program is free software; you can redistribute it and/or modify it under
11the terms of the GNU Lesser General Public License as published by the Free Software
12Foundation; either version 2 of the License, or (at your option) any later
13version.
14
15This program is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
18
19You should have received a copy of the GNU Lesser General Public License along with
20this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21Place - Suite 330, Boston, MA 02111-1307, USA, or go to
22http://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
38namespace 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                @param boneName The name of the bone (in the skeleton) to attach this object
458                @param pMovable Pointer to the object to attach
459                @param offsetOrientation An adjustment to the orientation of the attached object, relative to the bone.
460                @param offsetPosition An adjustment to the position of the attached object, relative to the bone.
461                @returns The TagPoint to which the object has been attached
462                */
463                TagPoint* attachObjectToBone(const String &boneName,
464                        MovableObject *pMovable,
465                        const Quaternion &offsetOrientation = Quaternion::IDENTITY,
466                        const Vector3 &offsetPosition = Vector3::ZERO);
467
468                /// detach a MovableObject previously attached using attachObjectToBone
469                MovableObject* detachObjectFromBone(const String &movableName);
470
471                /** Detaches an object by pointer.
472                @remarks
473                This method is need when destroy a MovableObject which attached to a bone of this entity.
474                But sometimes the object may be not in the child object list because it is a lod entity,
475                this method can safely detect and ignore in this case.
476                */
477                void detachObjectFromBone(MovableObject* obj);
478
479                /// Detach all MovableObjects previously attached using attachObjectToBone
480                void detachAllObjectsFromBone(void);
481
482                typedef MapIterator<ChildObjectList> ChildObjectListIterator;
483                /** Gets an iterator to the list of objects attached to bones on this entity. */
484                ChildObjectListIterator getAttachedObjectIterator(void);
485                /** @see MovableObject::getBoundingRadius */
486                Real getBoundingRadius(void) const;
487
488                /** @copy MovableObject::getWorldBoundingBox */
489                const AxisAlignedBox& getWorldBoundingBox(bool derive = false) const;
490                /** @copy MovableObject::getWorldBoundingSphere */
491                const Sphere& getWorldBoundingSphere(bool derive = false) const;
492
493        /** If set to true, this forces normals of this entity to be normalised
494            dynamically by the hardware.
495        @remarks
496            This option can be used to prevent lighting variations when scaling an
497            Entity using a SceneNode - normally because this scaling is hardware
498            based, the normals get scaled too which causes lighting to become inconsistent.
499            However, this has an overhead so only do this if you really need to.
500        */
501        void setNormaliseNormals(bool normalise) { mNormaliseNormals = normalise; }
502
503        /** Returns true if this entity has auto-normalisation of normals set. */
504        bool getNormaliseNormals(void) const {return mNormaliseNormals; }
505
506
507        /** Overridden member from ShadowCaster. */
508        EdgeData* getEdgeList(void);
509        /** Overridden member from ShadowCaster. */
510        ShadowRenderableListIterator getShadowVolumeRenderableIterator(
511            ShadowTechnique shadowTechnique, const Light* light,
512            HardwareIndexBufferSharedPtr* indexBuffer,
513            bool extrudeVertices, Real extrusionDistance, unsigned long flags = 0 );
514
515                /** Internal method for retrieving bone matrix information. */
516                const Matrix4* _getBoneMatrices(void) const { return mBoneMatrices;}
517                /** Internal method for retrieving bone matrix information. */
518                unsigned short _getNumBoneMatrices(void) const { return mNumBoneMatrices; }
519                /** Returns whether or not this entity is skeletally animated. */
520                bool hasSkeleton(void) const { return mSkeletonInstance != 0; }
521                /** Get this Entity's personal skeleton instance. */
522                SkeletonInstance* getSkeleton(void) const { return mSkeletonInstance; }
523                /** Returns whether or not hardware animation is enabled.
524                @remarks
525                Because fixed-function indexed vertex blending is rarely supported
526                by existing graphics cards, hardware animation can only be done if
527                the vertex programs in the materials used to render an entity support
528                it. Therefore, this method will only return true if all the materials
529                assigned to this entity have vertex programs assigned, and all those
530                vertex programs must support 'includes_morph_animation true' if using
531        morph animation, 'includes_pose_animation true' if using pose animation
532        and 'includes_skeletal_animation true' if using skeletal animation.
533                */
534                bool isHardwareAnimationEnabled(void) const { return mHardwareAnimation; }
535
536                /** Overridden from MovableObject */
537                void _notifyAttached(Node* parent, bool isTagPoint = false);
538        /** Returns the number of requests that have been made for software animation
539        @remarks
540            If non-zero then software animation will be performed in updateAnimation
541            regardless of the current setting of isHardwareAnimationEnabled or any
542            internal optimise for eliminate software animation. Requests for software
543            animation are made by calling the addSoftwareAnimationRequest() method.
544        */
545        int getSoftwareAnimationRequests(void) const { return mSoftwareAnimationRequests; }
546        /** Returns the number of requests that have been made for software animation of normals
547        @remarks
548            If non-zero, and getSoftwareAnimationRequests() also returns non-zero,
549            then software animation of normals will be performed in updateAnimation
550            regardless of the current setting of isHardwareAnimationEnabled or any
551            internal optimise for eliminate software animation. Currently it is not
552            possible to force software animation of only normals. Consequently this
553            value is always less than or equal to that returned by getSoftwareAnimationRequests().
554            Requests for software animation of normals are made by calling the
555            addSoftwareAnimationRequest() method with 'true' as the parameter.
556        */
557        int getSoftwareAnimationNormalsRequests(void) const { return mSoftwareAnimationNormalsRequests; }
558        /** Add a request for software animation
559        @remarks
560            Tells the entity to perform animation calculations for skeletal/vertex
561            animations in software, regardless of the current setting of
562            isHardwareAnimationEnabled().  Software animation will be performed
563            any time one or more requests have been made.  If 'normalsAlso' is
564            'true', then the entity will also do software blending on normal
565            vectors, in addition to positions. This advanced method useful for
566            situations in which access to actual mesh vertices is required,
567            such as accurate collision detection or certain advanced shading
568            techniques. When software animation is no longer needed,
569            the caller of this method should always remove the request by calling
570            removeSoftwareAnimationRequest(), passing the same value for
571            'normalsAlso'.
572        */
573        void addSoftwareAnimationRequest(bool normalsAlso);
574        /** Removes a request for software animation
575        @remarks
576            Calling this decrements the entity's internal counter of the number
577            of requests for software animation.  If the counter is already zero
578            then calling this method throws an exception.  The 'normalsAlso'
579            flag if set to 'true' will also decrement the internal counter of
580            number of requests for software animation of normals.
581        */
582        void removeSoftwareAnimationRequest(bool normalsAlso);
583
584                /** Shares the SkeletonInstance with the supplied entity.
585                *   Note that in order for this to work, both entities must have the same
586                *   Skeleton.
587                */
588                void shareSkeletonInstanceWith(Entity* entity);
589
590                /** Returns whether or not this entity is either morph or pose animated.
591                */
592                bool hasVertexAnimation(void) const;
593
594
595                /** Stops sharing the SkeletonInstance with other entities.
596                */
597                void stopSharingSkeletonInstance();
598
599
600                /**
601                * Returns whether this entity shares it's SkeltonInstance with other entity instances.
602                */
603                inline bool sharesSkeletonInstance() const { return mSharedSkeletonEntities != NULL; }
604
605                /**
606                * Returns a pointer to the set of entities which share a SkeletonInstance.
607                * If this instance does not share it's SkeletonInstance with other instances NULL will be returned
608                */
609                inline const EntitySet* getSkeletonInstanceSharingSet() const { return mSharedSkeletonEntities; }
610
611                /** Updates the internal animation state set to include the latest
612                available animations from the attached skeleton.
613                @remarks
614                Use this method if you manually add animations to a skeleton, or have
615                linked the skeleton to another for animation purposes since creating
616                this entity.
617                @note
618                If you have called getAnimationState prior to calling this method,
619                the pointers will still remain valid.
620                */
621                void refreshAvailableAnimationState(void);
622
623                /** Advanced method to perform all the updates required for an animated entity.
624                @remarks
625                You don't normally need to call this, but it's here incase you wish
626                to manually update the animation of an Entity at a specific point in
627                time. Animation will not be updated more than once a frame no matter
628                how many times you call this method.
629                */
630                void _updateAnimation(void);
631
632        /** Tests if any animation applied to this entity.
633        @remarks
634            An entity is animated if any animation state is enabled, or any manual bone
635            applied to the skeleton.
636        */
637        bool _isAnimated(void) const;
638
639        /** Tests if skeleton was animated.
640        */
641        bool _isSkeletonAnimated(void) const;
642
643                /** Advanced method to get the temporarily blended skeletal vertex information
644                for entities which are software skinned.
645        @remarks
646            Internal engine will eliminate software animation if possible, this
647            information is unreliable unless added request for software animation
648            via addSoftwareAnimationRequest.
649        @note
650            The positions/normals of the returned vertex data is in object space.
651                */
652                VertexData* _getSkelAnimVertexData(void) const;
653                /** Advanced method to get the temporarily blended software vertex animation information
654        @remarks
655            Internal engine will eliminate software animation if possible, this
656            information is unreliable unless added request for software animation
657            via addSoftwareAnimationRequest.
658        @note
659            The positions/normals of the returned vertex data is in object space.
660                */
661                VertexData* _getSoftwareVertexAnimVertexData(void) const;
662                /** Advanced method to get the hardware morph vertex information
663        @note
664            The positions/normals of the returned vertex data is in object space.
665                */
666                VertexData* _getHardwareVertexAnimVertexData(void) const;
667                /** Advanced method to get the temp buffer information for software
668                skeletal animation.
669                */
670                TempBlendedBufferInfo* _getSkelAnimTempBufferInfo(void);
671                /** Advanced method to get the temp buffer information for software
672                morph animation.
673                */
674                TempBlendedBufferInfo* _getVertexAnimTempBufferInfo(void);
675                /// Override to return specific type flag
676                uint32 getTypeFlags(void) const;
677                /// Retrieve the VertexData which should be used for GPU binding
678                VertexData* getVertexDataForBinding(void);
679
680                /// Identify which vertex data we should be sending to the renderer
681                enum VertexDataBindChoice
682                {
683                        BIND_ORIGINAL,
684                        BIND_SOFTWARE_SKELETAL,
685                        BIND_SOFTWARE_MORPH,
686                        BIND_HARDWARE_MORPH
687                };
688                /// Choose which vertex data to bind to the renderer
689                VertexDataBindChoice chooseVertexDataForBinding(bool hasVertexAnim) const;
690
691                /** Are buffers already marked as vertex animated? */
692                bool _getBuffersMarkedForAnimation(void) const { return mVertexAnimationAppliedThisFrame; }
693                /** Mark just this vertex data as animated.
694                */
695                void _markBuffersUsedForAnimation(void);
696
697
698        };
699
700        /** Factory object for creating Entity instances */
701        class _OgreExport EntityFactory : public MovableObjectFactory
702        {
703        protected:
704                MovableObject* createInstanceImpl( const String& name, const NameValuePairList* params);
705        public:
706                EntityFactory() {}
707                ~EntityFactory() {}
708
709                static String FACTORY_TYPE_NAME;
710
711                const String& getType(void) const;
712                void destroyInstance( MovableObject* obj); 
713
714        };
715
716} // namespace
717
718#endif
Note: See TracBrowser for help on using the repository browser.