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-2013 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 #include "OgreHeaderPrefix.h" 00043 00044 namespace Ogre { 00082 class _OgreExport Entity: public MovableObject, public Resource::Listener 00083 { 00084 // Allow EntityFactory full access 00085 friend class EntityFactory; 00086 friend class SubEntity; 00087 public: 00088 00089 typedef set<Entity*>::type EntitySet; 00090 typedef map<unsigned short, bool>::type SchemeHardwareAnimMap; 00091 00092 protected: 00093 00096 Entity(); 00099 Entity( const String& name, const MeshPtr& mesh); 00100 00103 MeshPtr mMesh; 00104 00107 typedef vector<SubEntity*>::type SubEntityList; 00108 SubEntityList mSubEntityList; 00109 00110 00112 AnimationStateSet* mAnimationState; 00113 00114 00116 TempBlendedBufferInfo mTempSkelAnimInfo; 00118 VertexData* mSkelAnimVertexData; 00120 TempBlendedBufferInfo mTempVertexAnimInfo; 00122 VertexData* mSoftwareVertexAnimVertexData; 00126 VertexData* mHardwareVertexAnimVertexData; 00128 bool mVertexAnimationAppliedThisFrame; 00130 bool mPreparedForShadowVolumes; 00131 00135 const VertexData* findBlendedVertexData(const VertexData* orig); 00139 SubEntity* findSubEntityForVertexData(const VertexData* orig); 00140 00144 void extractTempBufferInfo(VertexData* sourceData, TempBlendedBufferInfo* info); 00146 VertexData* cloneVertexDataRemoveBlendInfo(const VertexData* source); 00148 void prepareTempBlendBuffers(void); 00151 void markBuffersUnusedForAnimation(void); 00155 void restoreBuffersForUnusedAnimation(bool hardwareAnimation); 00156 00164 void bindMissingHardwarePoseBuffers(const VertexData* srcData, 00165 VertexData* destData); 00166 00170 void initialisePoseVertexData(const VertexData* srcData, VertexData* destData, 00171 bool animateNormals); 00172 00176 void finalisePoseNormals(const VertexData* srcData, VertexData* destData); 00177 00179 Matrix4 *mBoneWorldMatrices; 00181 Matrix4 *mBoneMatrices; 00182 unsigned short mNumBoneMatrices; 00184 unsigned long mFrameAnimationLastUpdated; 00185 00187 void updateAnimation(void); 00188 00192 unsigned long *mFrameBonesLastUpdated; 00193 00198 EntitySet* mSharedSkeletonEntities; 00199 00204 bool cacheBoneMatrices(void); 00205 00207 bool mDisplaySkeleton; 00211 SchemeHardwareAnimMap mSchemeHardwareAnim; 00212 00214 bool mCurrentHWAnimationState; 00215 00217 ushort mHardwarePoseCount; 00219 bool mVertexProgramInUse; 00221 int mSoftwareAnimationRequests; 00223 int mSoftwareAnimationNormalsRequests; 00225 bool mSkipAnimStateUpdates; 00227 bool mAlwaysUpdateMainSkeleton; 00228 00229 00231 ushort mMeshLodIndex; 00232 00234 Real mMeshLodFactorTransformed; 00236 ushort mMinMeshLodIndex; 00238 ushort mMaxMeshLodIndex; 00239 00241 Real mMaterialLodFactor; 00243 Real mMaterialLodFactorTransformed; 00245 ushort mMinMaterialLodIndex; 00247 ushort mMaxMaterialLodIndex; 00248 00254 typedef vector<Entity*>::type LODEntityList; 00255 LODEntityList mLodEntityList; 00256 00259 SkeletonInstance* mSkeletonInstance; 00260 00262 bool mInitialised; 00263 00265 Matrix4 mLastParentXform; 00266 00268 size_t mMeshStateCount; 00269 00271 void buildSubEntityList(MeshPtr& mesh, SubEntityList* sublist); 00272 00274 void attachObjectImpl(MovableObject *pMovable, TagPoint *pAttachingPoint); 00275 00277 void detachObjectImpl(MovableObject* pObject); 00278 00280 void detachAllObjectsImpl(void); 00281 00283 void reevaluateVertexProcessing(void); 00284 00291 bool calcVertexProcessing(void); 00292 00294 void applyVertexAnimation(bool hardwareAnimation, bool stencilShadows); 00296 ushort initHardwareAnimationElements(VertexData* vdata, ushort numberOfElements, bool animateNormals); 00298 bool tempVertexAnimBuffersBound(void) const; 00300 bool tempSkelAnimBuffersBound(bool requestNormals) const; 00301 00302 public: 00304 typedef map<String, MovableObject*>::type ChildObjectList; 00305 protected: 00306 ChildObjectList mChildObjectList; 00307 00308 00310 mutable AxisAlignedBox mFullBoundingBox; 00311 00312 ShadowRenderableList mShadowRenderables; 00313 00315 class _OgreExport EntityShadowRenderable : public ShadowRenderable 00316 { 00317 protected: 00318 Entity* mParent; 00320 HardwareVertexBufferSharedPtr mPositionBuffer; 00322 HardwareVertexBufferSharedPtr mWBuffer; 00324 const VertexData* mCurrentVertexData; 00326 unsigned short mOriginalPosBufferBinding; 00328 SubEntity* mSubEntity; 00329 00330 00331 public: 00332 EntityShadowRenderable(Entity* parent, 00333 HardwareIndexBufferSharedPtr* indexBuffer, const VertexData* vertexData, 00334 bool createSeparateLightCap, SubEntity* subent, bool isLightCap = false); 00335 ~EntityShadowRenderable(); 00336 00338 void _createSeparateLightCap(); 00340 void getWorldTransforms(Matrix4* xform) const; 00341 HardwareVertexBufferSharedPtr getPositionBuffer(void) { return mPositionBuffer; } 00342 HardwareVertexBufferSharedPtr getWBuffer(void) { return mWBuffer; } 00344 void rebindPositionBuffer(const VertexData* vertexData, bool force); 00346 bool isVisible(void) const; 00348 virtual void rebindIndexBuffer(const HardwareIndexBufferSharedPtr& indexBuffer); 00349 }; 00350 public: 00353 ~Entity(); 00354 00357 const MeshPtr& getMesh(void) const; 00358 00361 SubEntity* getSubEntity(unsigned int index) const; 00362 00367 SubEntity* getSubEntity( const String& name ) const; 00368 00371 unsigned int getNumSubEntities(void) const; 00372 00382 Entity* clone( const String& newName ) const; 00383 00392 void setMaterialName( const String& name, const String& groupName = ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME ); 00393 00394 00403 void setMaterial(const MaterialPtr& material); 00404 00407 void _notifyCurrentCamera(Camera* cam); 00408 00410 void setRenderQueueGroup(uint8 queueID); 00411 00413 void setRenderQueueGroupAndPriority(uint8 queueID, ushort priority); 00414 00417 const AxisAlignedBox& getBoundingBox(void) const; 00418 00420 AxisAlignedBox getChildObjectsBoundingBox(void) const; 00421 00424 void _updateRenderQueue(RenderQueue* queue); 00425 00427 const String& getMovableType(void) const; 00428 00435 AnimationState* getAnimationState(const String& name) const; 00437 bool hasAnimationState(const String& name) const; 00447 AnimationStateSet* getAllAnimationStates(void) const; 00448 00451 void setDisplaySkeleton(bool display); 00452 00455 bool getDisplaySkeleton(void) const; 00456 00457 00463 Entity* getManualLodLevel(size_t index) const; 00464 00470 size_t getNumManualLodLevels(void) const; 00471 00474 ushort getCurrentLodIndex() { return mMeshLodIndex; } 00475 00505 void setMeshLodBias(Real factor, ushort maxDetailIndex = 0, ushort minDetailIndex = 99); 00506 00536 void setMaterialLodBias(Real factor, ushort maxDetailIndex = 0, ushort minDetailIndex = 99); 00537 00541 void setPolygonModeOverrideable(bool PolygonModeOverrideable); 00561 TagPoint* attachObjectToBone(const String &boneName, 00562 MovableObject *pMovable, 00563 const Quaternion &offsetOrientation = Quaternion::IDENTITY, 00564 const Vector3 &offsetPosition = Vector3::ZERO); 00565 00571 MovableObject* detachObjectFromBone(const String &movableName); 00572 00579 void detachObjectFromBone(MovableObject* obj); 00580 00582 void detachAllObjectsFromBone(void); 00583 00584 typedef MapIterator<ChildObjectList> ChildObjectListIterator; 00586 ChildObjectListIterator getAttachedObjectIterator(void); 00588 Real getBoundingRadius(void) const; 00589 00591 const AxisAlignedBox& getWorldBoundingBox(bool derive = false) const; 00593 const Sphere& getWorldBoundingSphere(bool derive = false) const; 00594 00596 EdgeData* getEdgeList(void); 00598 bool hasEdgeList(void); 00600 ShadowRenderableListIterator getShadowVolumeRenderableIterator( 00601 ShadowTechnique shadowTechnique, const Light* light, 00602 HardwareIndexBufferSharedPtr* indexBuffer, size_t* indexBufferUsedSize, 00603 bool extrudeVertices, Real extrusionDistance, unsigned long flags = 0 ); 00604 00606 const Matrix4* _getBoneMatrices(void) const { return mBoneMatrices;} 00608 unsigned short _getNumBoneMatrices(void) const { return mNumBoneMatrices; } 00610 bool hasSkeleton(void) const { return mSkeletonInstance != 0; } 00612 SkeletonInstance* getSkeleton(void) const { return mSkeletonInstance; } 00628 bool isHardwareAnimationEnabled(void); 00629 00631 void _notifyAttached(Node* parent, bool isTagPoint = false); 00639 int getSoftwareAnimationRequests(void) const { return mSoftwareAnimationRequests; } 00651 int getSoftwareAnimationNormalsRequests(void) const { return mSoftwareAnimationNormalsRequests; } 00667 void addSoftwareAnimationRequest(bool normalsAlso); 00676 void removeSoftwareAnimationRequest(bool normalsAlso); 00677 00682 void shareSkeletonInstanceWith(Entity* entity); 00683 00686 bool hasVertexAnimation(void) const; 00687 00688 00691 void stopSharingSkeletonInstance(); 00692 00693 00696 inline bool sharesSkeletonInstance() const { return mSharedSkeletonEntities != NULL; } 00697 00701 inline const EntitySet* getSkeletonInstanceSharingSet() const { return mSharedSkeletonEntities; } 00702 00713 void refreshAvailableAnimationState(void); 00714 00722 void _updateAnimation(void); 00723 00729 bool _isAnimated(void) const; 00730 00733 bool _isSkeletonAnimated(void) const; 00734 00744 VertexData* _getSkelAnimVertexData(void) const; 00753 VertexData* _getSoftwareVertexAnimVertexData(void) const; 00758 VertexData* _getHardwareVertexAnimVertexData(void) const; 00762 TempBlendedBufferInfo* _getSkelAnimTempBufferInfo(void); 00766 TempBlendedBufferInfo* _getVertexAnimTempBufferInfo(void); 00768 uint32 getTypeFlags(void) const; 00770 VertexData* getVertexDataForBinding(void); 00771 00773 enum VertexDataBindChoice 00774 { 00775 BIND_ORIGINAL, 00776 BIND_SOFTWARE_SKELETAL, 00777 BIND_SOFTWARE_MORPH, 00778 BIND_HARDWARE_MORPH 00779 }; 00781 VertexDataBindChoice chooseVertexDataForBinding(bool hasVertexAnim); 00782 00784 bool _getBuffersMarkedForAnimation(void) const { return mVertexAnimationAppliedThisFrame; } 00787 void _markBuffersUsedForAnimation(void); 00788 00797 bool isInitialised(void) const { return mInitialised; } 00798 00810 void _initialise(bool forceReinitialise = false); 00812 void _deinitialise(void); 00813 00817 void backgroundLoadingComplete(Resource* res); 00818 00820 void visitRenderables(Renderable::Visitor* visitor, 00821 bool debugRenderables = false); 00822 00824 Real _getMeshLodFactorTransformed() const; 00825 00829 void setSkipAnimationStateUpdate(bool skip) { 00830 mSkipAnimStateUpdates = skip; 00831 } 00832 00836 bool getSkipAnimationStateUpdate() const { 00837 return mSkipAnimStateUpdates; 00838 } 00839 00844 void setAlwaysUpdateMainSkeleton(bool update) { 00845 mAlwaysUpdateMainSkeleton = update; 00846 } 00847 00852 bool getAlwaysUpdateMainSkeleton() const { 00853 return mAlwaysUpdateMainSkeleton; 00854 } 00855 00856 00857 }; 00858 00860 class _OgreExport EntityFactory : public MovableObjectFactory 00861 { 00862 protected: 00863 MovableObject* createInstanceImpl( const String& name, const NameValuePairList* params); 00864 public: 00865 EntityFactory() {} 00866 ~EntityFactory() {} 00867 00868 static String FACTORY_TYPE_NAME; 00869 00870 const String& getType(void) const; 00871 void destroyInstance( MovableObject* obj); 00872 00873 }; 00877 } // namespace Ogre 00878 00879 #include "OgreHeaderSuffix.h" 00880 00881 #endif // __Entity_H__
Copyright © 2012 Torus Knot Software Ltd

This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Mon Jul 27 2020 13:40:42