# OgreEntity.h

Go to the documentation of this file.

    00001 /*
    00002 -----------------------------------------------------------------------------
    00003 This source file is part of OGRE
    00004 (Object-oriented Graphics Rendering Engine)
    00005 For the latest info, see http://www.ogre3d.org
    00006
    00007 Copyright (c) 2000-2006 Torus Knot Software Ltd
    00008 Also see acknowledgements in Readme.html
    00009
    00010 This program is free software; you can redistribute it and/or modify it under
    00011 the terms of the GNU Lesser General Public License as published by the Free Software
    00012 Foundation; either version 2 of the License, or (at your option) any later
    00013 version.
    00014
    00015 This program is distributed in the hope that it will be useful, but WITHOUT
    00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
    00018
    00019 You should have received a copy of the GNU Lesser General Public License along with
    00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
    00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
    00022 http://www.gnu.org/copyleft/lesser.txt.
    00023
    00024 You may alternatively use this source under the terms of a specific version of
    00025 the OGRE Unrestricted License provided you have obtained such a license from
    00026 Torus Knot Software Ltd.
    00027 -----------------------------------------------------------------------------
    00028 */
    00029 #ifndef __Entity_H__
    00030 #define __Entity_H__
    00031
    00032 #include "OgrePrerequisites.h"
    00033 #include "OgreCommon.h"
    00034
    00035 #include "OgreString.h"
    00036 #include "OgreMovableObject.h"
    00037 #include "OgreQuaternion.h"
    00038 #include "OgreVector3.h"
    00039 #include "OgreHardwareBufferManager.h"
    00040 #include "OgreMesh.h"
    00041 #include "OgreRenderable.h"
    00042
    00043 namespace Ogre {
    00075     class _OgreExport Entity: public MovableObject, public Resource::Listener
    00076     {
    00077         // Allow EntityFactory full access
    00078         friend class EntityFactory;
    00079         friend class SubEntity;
    00080     public:
    00081         typedef std::set<Entity*> EntitySet;
    00082
    00083     protected:
    00084
    00087         Entity();
    00090         Entity( const String& name, const MeshPtr& mesh);
    00091
    00094         MeshPtr mMesh;
    00095
    00098         typedef std::vector<SubEntity*> SubEntityList;
    00099         SubEntityList mSubEntityList;
    00100
    00101
    00103         AnimationStateSet* mAnimationState;
    00104
    00105
    00107         TempBlendedBufferInfo mTempSkelAnimInfo;
    00109         VertexData* mSkelAnimVertexData;
    00111         TempBlendedBufferInfo mTempVertexAnimInfo;
    00113         VertexData* mSoftwareVertexAnimVertexData;
    00117         VertexData* mHardwareVertexAnimVertexData;
    00119         bool mVertexAnimationAppliedThisFrame;
    00121         bool mPreparedForShadowVolumes;
    00122
    00125         const VertexData* findBlendedVertexData(const VertexData* orig);
    00128         SubEntity* findSubEntityForVertexData(const VertexData* orig);
    00129
    00132         void extractTempBufferInfo(VertexData* sourceData, TempBlendedBufferInfo* info);
    00134         VertexData* cloneVertexDataRemoveBlendInfo(const VertexData* source);
    00136         void prepareTempBlendBuffers(void);
    00139         void markBuffersUnusedForAnimation(void);
    00143         void restoreBuffersForUnusedAnimation(bool hardwareAnimation);
    00144
    00150         void bindMissingHardwarePoseBuffers(const VertexData* srcData,
    00151             VertexData* destData);
    00152
    00154         Matrix4 *mBoneWorldMatrices;
    00156         Matrix4 *mBoneMatrices;
    00157         unsigned short mNumBoneMatrices;
    00159         unsigned long mFrameAnimationLastUpdated;
    00160
    00162         void updateAnimation(void);
    00163
    00167         unsigned long *mFrameBonesLastUpdated;
    00168
    00174         EntitySet* mSharedSkeletonEntities;
    00175
    00177         void cacheBoneMatrices(void);
    00178
    00180         bool mDisplaySkeleton;
    00182         bool mHardwareAnimation;
    00184         ushort mHardwarePoseCount;
    00186         bool mVertexProgramInUse;
    00188         int mSoftwareAnimationRequests;
    00190         int mSoftwareAnimationNormalsRequests;
    00191
    00192
    00194         ushort mMeshLodIndex;
    00195
    00197         Real mMeshLodFactorInv;
    00199         ushort mMinMeshLodIndex;
    00201         ushort mMaxMeshLodIndex;
    00202
    00204         Real mMaterialLodFactorInv;
    00206         ushort mMinMaterialLodIndex;
    00208         ushort mMaxMaterialLodIndex;
    00209
    00215         typedef std::vector<Entity*> LODEntityList;
    00216         LODEntityList mLodEntityList;
    00217
    00220         SkeletonInstance* mSkeletonInstance;
    00221
    00223         bool mInitialised;
    00224
    00226         Matrix4 mLastParentXform;
    00227
    00229         size_t mMeshStateCount;
    00230
    00232         void buildSubEntityList(MeshPtr& mesh, SubEntityList* sublist);
    00233
    00235         void attachObjectImpl(MovableObject *pMovable, TagPoint *pAttachingPoint);
    00236
    00238         void detachObjectImpl(MovableObject* pObject);
    00239
    00241         void detachAllObjectsImpl(void);
    00242
    00244         void reevaluateVertexProcessing(void);
    00245
    00247         void applyVertexAnimation(bool hardwareAnimation, bool stencilShadows);
    00249         void initHardwareAnimationElements(VertexData* vdata,
    00250             ushort numberOfElements);
    00252         bool tempVertexAnimBuffersBound(void) const;
    00254         bool tempSkelAnimBuffersBound(bool requestNormals) const;
    00255
    00256     public:
    00258         typedef std::map<String, MovableObject*> ChildObjectList;
    00259     protected:
    00260         ChildObjectList mChildObjectList;
    00261
    00262
    00264         mutable AxisAlignedBox mFullBoundingBox;
    00265
    00266         ShadowRenderableList mShadowRenderables;
    00267
    00269         class _OgreExport EntityShadowRenderable : public ShadowRenderable
    00270         {
    00271         protected:
    00272             Entity* mParent;
    00273             // Shared link to position buffer
    00274             HardwareVertexBufferSharedPtr mPositionBuffer;
    00275             // Shared link to w-coord buffer (optional)
    00276             HardwareVertexBufferSharedPtr mWBuffer;
    00277             // Link to current vertex data used to bind (maybe changes)
    00278             const VertexData* mCurrentVertexData;
    00279             // Original position buffer source binding
    00280             unsigned short mOriginalPosBufferBinding;
    00282             SubEntity* mSubEntity;
    00283
    00284
    00285         public:
    00286             EntityShadowRenderable(Entity* parent,
    00287                 HardwareIndexBufferSharedPtr* indexBuffer, const VertexData* vertexData,
    00288                 bool createSeparateLightCap, SubEntity* subent, bool isLightCap = false);
    00289             ~EntityShadowRenderable();
    00291             void getWorldTransforms(Matrix4* xform) const;
    00292             HardwareVertexBufferSharedPtr getPositionBuffer(void) { return mPositionBuffer; }
    00293             HardwareVertexBufferSharedPtr getWBuffer(void) { return mWBuffer; }
    00295             void rebindPositionBuffer(const VertexData* vertexData, bool force);
    00297             bool isVisible(void) const;
    00298
    00299         };
    00300     public:
    00303         ~Entity();
    00304
    00307         const MeshPtr& getMesh(void) const;
    00308
    00311         SubEntity* getSubEntity(unsigned int index) const;
    00312
    00316         SubEntity* getSubEntity( const String& name ) const;
    00317
    00320         unsigned int getNumSubEntities(void) const;
    00321
    00331         Entity* clone( const String& newName ) const;
    00332
    00341         void setMaterialName(const String& name);
    00342
    00343
    00352         void setMaterial(const MaterialPtr& material);
    00353
    00356         void _notifyCurrentCamera(Camera* cam);
    00357
    00359         void setRenderQueueGroup(uint8 queueID);
    00360
    00363         const AxisAlignedBox& getBoundingBox(void) const;
    00364
    00366         AxisAlignedBox getChildObjectsBoundingBox(void) const;
    00367
    00370         void _updateRenderQueue(RenderQueue* queue);
    00371
    00373         const String& getMovableType(void) const;
    00374
    00381         AnimationState* getAnimationState(const String& name) const;
    00391         AnimationStateSet* getAllAnimationStates(void) const;
    00392
    00395         void setDisplaySkeleton(bool display);
    00396
    00399         bool getDisplaySkeleton(void) const;
    00400
    00401
    00407         Entity* getManualLodLevel(size_t index) const;
    00408
    00414         size_t getNumManualLodLevels(void) const;
    00415
    00418         ushort getCurrentLodIndex() { return mMeshLodIndex; }
    00419
    00446         void setMeshLodBias(Real factor, ushort maxDetailIndex = 0, ushort minDetailIndex = 99);
    00447
    00474         void setMaterialLodBias(Real factor, ushort maxDetailIndex = 0, ushort minDetailIndex = 99);
    00475
    00479         void setPolygonModeOverrideable(bool PolygonModeOverrideable);
    00494         TagPoint* attachObjectToBone(const String &boneName,
    00495             MovableObject *pMovable,
    00496             const Quaternion &offsetOrientation = Quaternion::IDENTITY,
    00497             const Vector3 &offsetPosition = Vector3::ZERO);
    00498
    00503         MovableObject* detachObjectFromBone(const String &movableName);
    00504
    00511         void detachObjectFromBone(MovableObject* obj);
    00512
    00514         void detachAllObjectsFromBone(void);
    00515
    00516         typedef MapIterator<ChildObjectList> ChildObjectListIterator;
    00518         ChildObjectListIterator getAttachedObjectIterator(void);
    00520         Real getBoundingRadius(void) const;
    00521
    00523         const AxisAlignedBox& getWorldBoundingBox(bool derive = false) const;
    00525         const Sphere& getWorldBoundingSphere(bool derive = false) const;
    00526
    00528         EdgeData* getEdgeList(void);
    00530         bool hasEdgeList(void);
    00532         ShadowRenderableListIterator getShadowVolumeRenderableIterator(
    00533             ShadowTechnique shadowTechnique, const Light* light,
    00534             HardwareIndexBufferSharedPtr* indexBuffer,
    00535             bool extrudeVertices, Real extrusionDistance, unsigned long flags = 0 );
    00536
    00538         const Matrix4* _getBoneMatrices(void) const { return mBoneMatrices;}
    00540         unsigned short _getNumBoneMatrices(void) const { return mNumBoneMatrices; }
    00542         bool hasSkeleton(void) const { return mSkeletonInstance != 0; }
    00544         SkeletonInstance* getSkeleton(void) const { return mSkeletonInstance; }
    00556         bool isHardwareAnimationEnabled(void) const { return mHardwareAnimation; }
    00557
    00559         void _notifyAttached(Node* parent, bool isTagPoint = false);
    00567         int getSoftwareAnimationRequests(void) const { return mSoftwareAnimationRequests; }
    00579         int getSoftwareAnimationNormalsRequests(void) const { return mSoftwareAnimationNormalsRequests; }
    00595         void addSoftwareAnimationRequest(bool normalsAlso);
    00604         void removeSoftwareAnimationRequest(bool normalsAlso);
    00605
    00610         void shareSkeletonInstanceWith(Entity* entity);
    00611
    00614         bool hasVertexAnimation(void) const;
    00615
    00616
    00619         void stopSharingSkeletonInstance();
    00620
    00621
    00625         inline bool sharesSkeletonInstance() const { return mSharedSkeletonEntities != NULL; }
    00626
    00631         inline const EntitySet* getSkeletonInstanceSharingSet() const { return mSharedSkeletonEntities; }
    00632
    00643         void refreshAvailableAnimationState(void);
    00644
    00652         void _updateAnimation(void);
    00653
    00659         bool _isAnimated(void) const;
    00660
    00663         bool _isSkeletonAnimated(void) const;
    00664
    00674         VertexData* _getSkelAnimVertexData(void) const;
    00683         VertexData* _getSoftwareVertexAnimVertexData(void) const;
    00688         VertexData* _getHardwareVertexAnimVertexData(void) const;
    00692         TempBlendedBufferInfo* _getSkelAnimTempBufferInfo(void);
    00696         TempBlendedBufferInfo* _getVertexAnimTempBufferInfo(void);
    00698         uint32 getTypeFlags(void) const;
    00700         VertexData* getVertexDataForBinding(void);
    00701
    00703         enum VertexDataBindChoice
    00704         {
    00705             BIND_ORIGINAL,
    00706             BIND_SOFTWARE_SKELETAL,
    00707             BIND_SOFTWARE_MORPH,
    00708             BIND_HARDWARE_MORPH
    00709         };
    00711         VertexDataBindChoice chooseVertexDataForBinding(bool hasVertexAnim) const;
    00712
    00714         bool _getBuffersMarkedForAnimation(void) const { return mVertexAnimationAppliedThisFrame; }
    00717         void _markBuffersUsedForAnimation(void);
    00718
    00727         bool isInitialised(void) const { return mInitialised; }
    00728
    00739         void _initialise(bool forceReinitialise = false);
    00741         void _deinitialise(void);
    00742
    00746         void backgroundLoadingComplete(Resource* res);
    00747
    00749         void visitRenderables(Renderable::Visitor* visitor,
    00750             bool debugRenderables = false);
    00751
    00752
    00753
    00754
    00755     };
    00756
    00758     class _OgreExport EntityFactory : public MovableObjectFactory
    00759     {
    00760     protected:
    00761         MovableObject* createInstanceImpl( const String& name, const NameValuePairList* params);
    00762     public:
    00763         EntityFactory() {}
    00764         ~EntityFactory() {}
    00765
    00766         static String FACTORY_TYPE_NAME;
    00767
    00768         const String& getType(void) const;
    00769         void destroyInstance( MovableObject* obj);
    00770
    00771     };
    00772
    00773 } // namespace
    00774
    00775 #endif

Copyright © 2008 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sat Apr 11 13:46:40 2009