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-2012 Torus Knot Software Ltd
00008 
00009 Permission is hereby granted, free of charge, to any person obtaining a copy
00010 of this software and associated documentation files (the "Software"), to deal
00011 in the Software without restriction, including without limitation the rights
00012 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00013 copies of the Software, and to permit persons to whom the Software is
00014 furnished to do so, subject to the following conditions:
00015 
00016 The above copyright notice and this permission notice shall be included in
00017 all copies or substantial portions of the Software.
00018 
00019 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00020 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00021 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00022 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00023 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00024 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00025 THE SOFTWARE.
00026 -----------------------------------------------------------------------------
00027 */
00028 #ifndef __Entity_H__
00029 #define __Entity_H__
00030 
00031 #include "OgrePrerequisites.h"
00032 #include "OgreCommon.h"
00033 
00034 #include "OgreString.h"
00035 #include "OgreMovableObject.h"
00036 #include "OgreQuaternion.h"
00037 #include "OgreVector3.h"
00038 #include "OgreHardwareBufferManager.h"
00039 #include "OgreMesh.h"
00040 #include "OgreRenderable.h"
00041 #include "OgreResourceGroupManager.h"
00042 
00043 namespace Ogre {
00081     class _OgreExport Entity: public MovableObject, public Resource::Listener
00082     {
00083         // Allow EntityFactory full access
00084         friend class EntityFactory;
00085         friend class SubEntity;
00086     public:
00087         
00088         typedef set<Entity*>::type EntitySet;
00089         typedef map<unsigned short, bool>::type SchemeHardwareAnimMap;
00090 
00091     protected:
00092 
00095         Entity();
00098         Entity( const String& name, const MeshPtr& mesh);
00099 
00102         MeshPtr mMesh;
00103 
00106         typedef vector<SubEntity*>::type SubEntityList;
00107         SubEntityList mSubEntityList;
00108 
00109 
00111         AnimationStateSet* mAnimationState;
00112 
00113 
00115         TempBlendedBufferInfo mTempSkelAnimInfo;
00117         VertexData* mSkelAnimVertexData;
00119         TempBlendedBufferInfo mTempVertexAnimInfo;
00121         VertexData* mSoftwareVertexAnimVertexData;
00125         VertexData* mHardwareVertexAnimVertexData;
00127         bool mVertexAnimationAppliedThisFrame;
00129         bool mPreparedForShadowVolumes;
00130 
00133         const VertexData* findBlendedVertexData(const VertexData* orig);
00136         SubEntity* findSubEntityForVertexData(const VertexData* orig);
00137 
00140         void extractTempBufferInfo(VertexData* sourceData, TempBlendedBufferInfo* info);
00142         VertexData* cloneVertexDataRemoveBlendInfo(const VertexData* source);
00144         void prepareTempBlendBuffers(void);
00147         void markBuffersUnusedForAnimation(void);
00151         void restoreBuffersForUnusedAnimation(bool hardwareAnimation);
00152 
00158         void bindMissingHardwarePoseBuffers(const VertexData* srcData, 
00159             VertexData* destData);
00160             
00164         void initialisePoseVertexData(const VertexData* srcData, VertexData* destData, 
00165             bool animateNormals);
00166 
00170         void finalisePoseNormals(const VertexData* srcData, VertexData* destData);
00171 
00173         Matrix4 *mBoneWorldMatrices;
00175         Matrix4 *mBoneMatrices;
00176         unsigned short mNumBoneMatrices;
00178         unsigned long mFrameAnimationLastUpdated;
00179 
00181         void updateAnimation(void);
00182 
00186         unsigned long *mFrameBonesLastUpdated;
00187 
00193         EntitySet* mSharedSkeletonEntities;
00194 
00200         bool cacheBoneMatrices(void);
00201 
00203         bool mDisplaySkeleton;
00208         SchemeHardwareAnimMap mSchemeHardwareAnim;
00209 
00211         bool mCurrentHWAnimationState;
00212 
00214         ushort mHardwarePoseCount;
00216         bool mVertexProgramInUse;
00218         int mSoftwareAnimationRequests;
00220         int mSoftwareAnimationNormalsRequests;
00222         bool mSkipAnimStateUpdates;
00224         bool mAlwaysUpdateMainSkeleton;
00225 
00226 
00228         ushort mMeshLodIndex;
00229 
00231         Real mMeshLodFactorTransformed;
00233         ushort mMinMeshLodIndex;
00235         ushort mMaxMeshLodIndex;
00236 
00238         Real mMaterialLodFactor;
00240         Real mMaterialLodFactorTransformed;
00242         ushort mMinMaterialLodIndex;
00244         ushort mMaxMaterialLodIndex;
00245 
00251         typedef vector<Entity*>::type LODEntityList;
00252         LODEntityList mLodEntityList;
00253 
00256         SkeletonInstance* mSkeletonInstance;
00257 
00259         bool mInitialised;
00260 
00262         Matrix4 mLastParentXform;
00263 
00265         size_t mMeshStateCount;
00266 
00268         void buildSubEntityList(MeshPtr& mesh, SubEntityList* sublist);
00269 
00271         void attachObjectImpl(MovableObject *pMovable, TagPoint *pAttachingPoint);
00272 
00274         void detachObjectImpl(MovableObject* pObject);
00275 
00277         void detachAllObjectsImpl(void);
00278 
00280         void reevaluateVertexProcessing(void);
00281 
00288         bool calcVertexProcessing(void);
00289     
00291         void applyVertexAnimation(bool hardwareAnimation, bool stencilShadows);
00293         ushort initHardwareAnimationElements(VertexData* vdata,
00294             ushort numberOfElements, bool animateNormals);
00296         bool tempVertexAnimBuffersBound(void) const;
00298         bool tempSkelAnimBuffersBound(bool requestNormals) const;
00299 
00300     public:
00302         typedef map<String, MovableObject*>::type ChildObjectList;
00303     protected:
00304         ChildObjectList mChildObjectList;
00305 
00306 
00308         mutable AxisAlignedBox mFullBoundingBox;
00309 
00310         ShadowRenderableList mShadowRenderables;
00311 
00313         class _OgreExport EntityShadowRenderable : public ShadowRenderable
00314         {
00315         protected:
00316             Entity* mParent;
00318             HardwareVertexBufferSharedPtr mPositionBuffer;
00320             HardwareVertexBufferSharedPtr mWBuffer;
00322             const VertexData* mCurrentVertexData;
00324             unsigned short mOriginalPosBufferBinding;
00326             SubEntity* mSubEntity;
00327 
00328 
00329         public:
00330             EntityShadowRenderable(Entity* parent,
00331                 HardwareIndexBufferSharedPtr* indexBuffer, const VertexData* vertexData,
00332                 bool createSeparateLightCap, SubEntity* subent, bool isLightCap = false);
00333             ~EntityShadowRenderable();
00334             
00336             void _createSeparateLightCap();
00338             void getWorldTransforms(Matrix4* xform) const;
00339             HardwareVertexBufferSharedPtr getPositionBuffer(void) { return mPositionBuffer; }
00340             HardwareVertexBufferSharedPtr getWBuffer(void) { return mWBuffer; }
00342             void rebindPositionBuffer(const VertexData* vertexData, bool force);
00344             bool isVisible(void) const;
00346             virtual void rebindIndexBuffer(const HardwareIndexBufferSharedPtr& indexBuffer);
00347         };
00348     public:
00351         ~Entity();
00352 
00355         const MeshPtr& getMesh(void) const;
00356 
00359         SubEntity* getSubEntity(unsigned int index) const;
00360 
00364         SubEntity* getSubEntity( const String& name ) const;
00365 
00368         unsigned int getNumSubEntities(void) const;
00369 
00379         Entity* clone( const String& newName ) const;
00380 
00389         void setMaterialName( const String& name, const String& groupName = ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME );
00390 
00391         
00400         void setMaterial(const MaterialPtr& material);
00401 
00404         void _notifyCurrentCamera(Camera* cam);
00405 
00407         void setRenderQueueGroup(uint8 queueID);
00408 
00410         void setRenderQueueGroupAndPriority(uint8 queueID, ushort priority);
00411 
00414         const AxisAlignedBox& getBoundingBox(void) const;
00415 
00417         AxisAlignedBox getChildObjectsBoundingBox(void) const;
00418 
00421         void _updateRenderQueue(RenderQueue* queue);
00422 
00424         const String& getMovableType(void) const;
00425 
00432         AnimationState* getAnimationState(const String& name) const;
00434         bool hasAnimationState(const String& name) const;
00444         AnimationStateSet* getAllAnimationStates(void) const;
00445 
00448         void setDisplaySkeleton(bool display);
00449 
00452         bool getDisplaySkeleton(void) const;
00453 
00454 
00460         Entity* getManualLodLevel(size_t index) const;
00461 
00467         size_t getNumManualLodLevels(void) const;
00468 
00471         ushort getCurrentLodIndex() { return mMeshLodIndex; }
00472 
00499         void setMeshLodBias(Real factor, ushort maxDetailIndex = 0, ushort minDetailIndex = 99);
00500 
00527         void setMaterialLodBias(Real factor, ushort maxDetailIndex = 0, ushort minDetailIndex = 99);
00528 
00532         void setPolygonModeOverrideable(bool PolygonModeOverrideable);
00547         TagPoint* attachObjectToBone(const String &boneName,
00548             MovableObject *pMovable,
00549             const Quaternion &offsetOrientation = Quaternion::IDENTITY,
00550             const Vector3 &offsetPosition = Vector3::ZERO);
00551 
00556         MovableObject* detachObjectFromBone(const String &movableName);
00557 
00564         void detachObjectFromBone(MovableObject* obj);
00565 
00567         void detachAllObjectsFromBone(void);
00568 
00569         typedef MapIterator<ChildObjectList> ChildObjectListIterator;
00571         ChildObjectListIterator getAttachedObjectIterator(void);
00573         Real getBoundingRadius(void) const;
00574 
00576         const AxisAlignedBox& getWorldBoundingBox(bool derive = false) const;
00578         const Sphere& getWorldBoundingSphere(bool derive = false) const;
00579 
00581         EdgeData* getEdgeList(void);
00583         bool hasEdgeList(void);
00585         ShadowRenderableListIterator getShadowVolumeRenderableIterator(
00586             ShadowTechnique shadowTechnique, const Light* light,
00587             HardwareIndexBufferSharedPtr* indexBuffer,
00588             bool extrudeVertices, Real extrusionDistance, unsigned long flags = 0 );
00589 
00591         const Matrix4* _getBoneMatrices(void) const { return mBoneMatrices;}
00593         unsigned short _getNumBoneMatrices(void) const { return mNumBoneMatrices; }
00595         bool hasSkeleton(void) const { return mSkeletonInstance != 0; }
00597         SkeletonInstance* getSkeleton(void) const { return mSkeletonInstance; }
00613         bool isHardwareAnimationEnabled(void);
00614 
00616         void _notifyAttached(Node* parent, bool isTagPoint = false);
00624         int getSoftwareAnimationRequests(void) const { return mSoftwareAnimationRequests; }
00636         int getSoftwareAnimationNormalsRequests(void) const { return mSoftwareAnimationNormalsRequests; }
00652         void addSoftwareAnimationRequest(bool normalsAlso);
00661         void removeSoftwareAnimationRequest(bool normalsAlso);
00662 
00667         void shareSkeletonInstanceWith(Entity* entity);
00668 
00671         bool hasVertexAnimation(void) const;
00672 
00673 
00676         void stopSharingSkeletonInstance();
00677 
00678 
00682         inline bool sharesSkeletonInstance() const { return mSharedSkeletonEntities != NULL; }
00683 
00688         inline const EntitySet* getSkeletonInstanceSharingSet() const { return mSharedSkeletonEntities; }
00689 
00700         void refreshAvailableAnimationState(void);
00701 
00709         void _updateAnimation(void);
00710 
00716         bool _isAnimated(void) const;
00717 
00720         bool _isSkeletonAnimated(void) const;
00721 
00731         VertexData* _getSkelAnimVertexData(void) const;
00740         VertexData* _getSoftwareVertexAnimVertexData(void) const;
00745         VertexData* _getHardwareVertexAnimVertexData(void) const;
00749         TempBlendedBufferInfo* _getSkelAnimTempBufferInfo(void);
00753         TempBlendedBufferInfo* _getVertexAnimTempBufferInfo(void);
00755         uint32 getTypeFlags(void) const;
00757         VertexData* getVertexDataForBinding(void);
00758 
00760         enum VertexDataBindChoice
00761         {
00762             BIND_ORIGINAL,
00763             BIND_SOFTWARE_SKELETAL,
00764             BIND_SOFTWARE_MORPH,
00765             BIND_HARDWARE_MORPH
00766         };
00768         VertexDataBindChoice chooseVertexDataForBinding(bool hasVertexAnim);
00769 
00771         bool _getBuffersMarkedForAnimation(void) const { return mVertexAnimationAppliedThisFrame; }
00774         void _markBuffersUsedForAnimation(void);
00775 
00784         bool isInitialised(void) const { return mInitialised; }
00785 
00796         void _initialise(bool forceReinitialise = false);
00798         void _deinitialise(void);
00799 
00803         void backgroundLoadingComplete(Resource* res);
00804 
00806         void visitRenderables(Renderable::Visitor* visitor, 
00807             bool debugRenderables = false);
00808 
00810         Real _getMeshLodFactorTransformed() const;
00811         
00815         void setSkipAnimationStateUpdate(bool skip) {
00816             mSkipAnimStateUpdates = skip;
00817         }
00818         
00822         bool getSkipAnimationStateUpdate() const {
00823             return mSkipAnimStateUpdates;
00824         }
00825 
00826 
00831         void setAlwaysUpdateMainSkeleton(bool update) {
00832             mAlwaysUpdateMainSkeleton = update;
00833         }
00834 
00839         bool getAlwaysUpdateMainSkeleton() const {
00840             return mAlwaysUpdateMainSkeleton;
00841         }
00842 
00843         
00844     };
00845 
00847     class _OgreExport EntityFactory : public MovableObjectFactory
00848     {
00849     protected:
00850         MovableObject* createInstanceImpl( const String& name, const NameValuePairList* params);
00851     public:
00852         EntityFactory() {}
00853         ~EntityFactory() {}
00854 
00855         static String FACTORY_TYPE_NAME;
00856 
00857         const String& getType(void) const;
00858         void destroyInstance( MovableObject* obj);
00859 
00860     };
00864 } // namespace
00865 
00866 #endif

Copyright © 2012 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Fri May 25 23:36:23 2012