Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/ogre/OgreMain/include/OgreEntity.h @ 11

Last change on this file since 11 was 5, checked in by anonymous, 17 years ago

=hoffentlich gehts jetzt

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