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 00042 namespace Ogre { 00074 class _OgreExport Entity: public MovableObject, public Resource::Listener 00075 { 00076 // Allow EntityFactory full access 00077 friend class EntityFactory; 00078 friend class SubEntity; 00079 public: 00080 typedef std::set<Entity*> EntitySet; 00081 00082 protected: 00083 00086 Entity(); 00089 Entity( const String& name, MeshPtr& mesh); 00090 00093 MeshPtr mMesh; 00094 00097 typedef std::vector<SubEntity*> SubEntityList; 00098 SubEntityList mSubEntityList; 00099 00100 00102 AnimationStateSet* mAnimationState; 00103 00104 00106 TempBlendedBufferInfo mTempSkelAnimInfo; 00108 VertexData* mSkelAnimVertexData; 00110 TempBlendedBufferInfo mTempVertexAnimInfo; 00112 VertexData* mSoftwareVertexAnimVertexData; 00116 VertexData* mHardwareVertexAnimVertexData; 00118 bool mVertexAnimationAppliedThisFrame; 00120 bool mPreparedForShadowVolumes; 00121 00124 const VertexData* findBlendedVertexData(const VertexData* orig); 00127 SubEntity* findSubEntityForVertexData(const VertexData* orig); 00128 00131 void extractTempBufferInfo(VertexData* sourceData, TempBlendedBufferInfo* info); 00133 VertexData* cloneVertexDataRemoveBlendInfo(const VertexData* source); 00135 void prepareTempBlendBuffers(void); 00138 void markBuffersUnusedForAnimation(void); 00142 void restoreBuffersForUnusedAnimation(bool hardwareAnimation); 00143 00149 void bindMissingHardwarePoseBuffers(const VertexData* srcData, 00150 VertexData* destData); 00151 00153 Matrix4 *mBoneWorldMatrices; 00155 Matrix4 *mBoneMatrices; 00156 unsigned short mNumBoneMatrices; 00158 unsigned long mFrameAnimationLastUpdated; 00159 00161 void updateAnimation(void); 00162 00166 unsigned long *mFrameBonesLastUpdated; 00167 00173 EntitySet* mSharedSkeletonEntities; 00174 00176 void cacheBoneMatrices(void); 00177 00179 bool mDisplaySkeleton; 00181 bool mHardwareAnimation; 00183 ushort mHardwarePoseCount; 00185 bool mVertexProgramInUse; 00187 int mSoftwareAnimationRequests; 00189 int mSoftwareAnimationNormalsRequests; 00190 00191 00193 ushort mMeshLodIndex; 00194 00196 Real mMeshLodFactorInv; 00198 ushort mMinMeshLodIndex; 00200 ushort mMaxMeshLodIndex; 00201 00203 Real mMaterialLodFactorInv; 00205 ushort mMinMaterialLodIndex; 00207 ushort mMaxMaterialLodIndex; 00208 00214 typedef std::vector<Entity*> LODEntityList; 00215 LODEntityList mLodEntityList; 00216 00219 SkeletonInstance* mSkeletonInstance; 00220 00222 bool mInitialised; 00223 00225 Matrix4 mLastParentXform; 00226 00228 void buildSubEntityList(MeshPtr& mesh, SubEntityList* sublist); 00229 00231 void attachObjectImpl(MovableObject *pMovable, TagPoint *pAttachingPoint); 00232 00234 void detachObjectImpl(MovableObject* pObject); 00235 00237 void detachAllObjectsImpl(void); 00238 00240 void reevaluateVertexProcessing(void); 00241 00243 void applyVertexAnimation(bool hardwareAnimation, bool stencilShadows); 00245 void initHardwareAnimationElements(VertexData* vdata, 00246 ushort numberOfElements); 00248 bool tempVertexAnimBuffersBound(void) const; 00250 bool tempSkelAnimBuffersBound(bool requestNormals) const; 00251 00252 public: 00254 typedef std::map<String, MovableObject*> ChildObjectList; 00255 protected: 00256 ChildObjectList mChildObjectList; 00257 00258 00260 mutable AxisAlignedBox mFullBoundingBox; 00261 00262 bool mNormaliseNormals; 00263 00264 ShadowRenderableList mShadowRenderables; 00265 00267 class _OgreExport EntityShadowRenderable : public ShadowRenderable 00268 { 00269 protected: 00270 Entity* mParent; 00271 // Shared link to position buffer 00272 HardwareVertexBufferSharedPtr mPositionBuffer; 00273 // Shared link to w-coord buffer (optional) 00274 HardwareVertexBufferSharedPtr mWBuffer; 00275 // Link to current vertex data used to bind (maybe changes) 00276 const VertexData* mCurrentVertexData; 00277 // Original position buffer source binding 00278 unsigned short mOriginalPosBufferBinding; 00280 SubEntity* mSubEntity; 00281 00282 00283 public: 00284 EntityShadowRenderable(Entity* parent, 00285 HardwareIndexBufferSharedPtr* indexBuffer, const VertexData* vertexData, 00286 bool createSeparateLightCap, SubEntity* subent, bool isLightCap = false); 00287 ~EntityShadowRenderable(); 00289 void getWorldTransforms(Matrix4* xform) const; 00291 const Quaternion& getWorldOrientation(void) const; 00293 const Vector3& getWorldPosition(void) const; 00294 HardwareVertexBufferSharedPtr getPositionBuffer(void) { return mPositionBuffer; } 00295 HardwareVertexBufferSharedPtr getWBuffer(void) { return mWBuffer; } 00297 void rebindPositionBuffer(const VertexData* vertexData, bool force); 00299 bool isVisible(void) const; 00300 00301 }; 00302 public: 00305 ~Entity(); 00306 00309 const MeshPtr& getMesh(void) const; 00310 00313 SubEntity* getSubEntity(unsigned int index) const; 00314 00318 SubEntity* getSubEntity( const String& name ) const; 00319 00322 unsigned int getNumSubEntities(void) const; 00323 00333 Entity* clone( const String& newName ) const; 00334 00343 void setMaterialName(const String& name); 00344 00347 void _notifyCurrentCamera(Camera* cam); 00348 00350 void setRenderQueueGroup(uint8 queueID); 00351 00354 const AxisAlignedBox& getBoundingBox(void) const; 00355 00357 AxisAlignedBox getChildObjectsBoundingBox(void) const; 00358 00361 void _updateRenderQueue(RenderQueue* queue); 00362 00364 const String& getMovableType(void) const; 00365 00372 AnimationState* getAnimationState(const String& name) const; 00382 AnimationStateSet* getAllAnimationStates(void) const; 00383 00386 void setDisplaySkeleton(bool display); 00387 00390 bool getDisplaySkeleton(void) const; 00391 00392 00398 Entity* getManualLodLevel(size_t index) const; 00399 00405 size_t getNumManualLodLevels(void) const; 00406 00433 void setMeshLodBias(Real factor, ushort maxDetailIndex = 0, ushort minDetailIndex = 99); 00434 00461 void setMaterialLodBias(Real factor, ushort maxDetailIndex = 0, ushort minDetailIndex = 99); 00462 00466 void setPolygonModeOverrideable(bool PolygonModeOverrideable); 00481 TagPoint* attachObjectToBone(const String &boneName, 00482 MovableObject *pMovable, 00483 const Quaternion &offsetOrientation = Quaternion::IDENTITY, 00484 const Vector3 &offsetPosition = Vector3::ZERO); 00485 00490 MovableObject* detachObjectFromBone(const String &movableName); 00491 00498 void detachObjectFromBone(MovableObject* obj); 00499 00501 void detachAllObjectsFromBone(void); 00502 00503 typedef MapIterator<ChildObjectList> ChildObjectListIterator; 00505 ChildObjectListIterator getAttachedObjectIterator(void); 00507 Real getBoundingRadius(void) const; 00508 00510 const AxisAlignedBox& getWorldBoundingBox(bool derive = false) const; 00512 const Sphere& getWorldBoundingSphere(bool derive = false) const; 00513 00522 void setNormaliseNormals(bool normalise) { mNormaliseNormals = normalise; } 00523 00525 bool getNormaliseNormals(void) const {return mNormaliseNormals; } 00526 00527 00529 EdgeData* getEdgeList(void); 00531 bool hasEdgeList(void); 00533 ShadowRenderableListIterator getShadowVolumeRenderableIterator( 00534 ShadowTechnique shadowTechnique, const Light* light, 00535 HardwareIndexBufferSharedPtr* indexBuffer, 00536 bool extrudeVertices, Real extrusionDistance, unsigned long flags = 0 ); 00537 00539 const Matrix4* _getBoneMatrices(void) const { return mBoneMatrices;} 00541 unsigned short _getNumBoneMatrices(void) const { return mNumBoneMatrices; } 00543 bool hasSkeleton(void) const { return mSkeletonInstance != 0; } 00545 SkeletonInstance* getSkeleton(void) const { return mSkeletonInstance; } 00557 bool isHardwareAnimationEnabled(void) const { return mHardwareAnimation; } 00558 00560 void _notifyAttached(Node* parent, bool isTagPoint = false); 00568 int getSoftwareAnimationRequests(void) const { return mSoftwareAnimationRequests; } 00580 int getSoftwareAnimationNormalsRequests(void) const { return mSoftwareAnimationNormalsRequests; } 00596 void addSoftwareAnimationRequest(bool normalsAlso); 00605 void removeSoftwareAnimationRequest(bool normalsAlso); 00606 00611 void shareSkeletonInstanceWith(Entity* entity); 00612 00615 bool hasVertexAnimation(void) const; 00616 00617 00620 void stopSharingSkeletonInstance(); 00621 00622 00626 inline bool sharesSkeletonInstance() const { return mSharedSkeletonEntities != NULL; } 00627 00632 inline const EntitySet* getSkeletonInstanceSharingSet() const { return mSharedSkeletonEntities; } 00633 00644 void refreshAvailableAnimationState(void); 00645 00653 void _updateAnimation(void); 00654 00660 bool _isAnimated(void) const; 00661 00664 bool _isSkeletonAnimated(void) const; 00665 00675 VertexData* _getSkelAnimVertexData(void) const; 00684 VertexData* _getSoftwareVertexAnimVertexData(void) const; 00689 VertexData* _getHardwareVertexAnimVertexData(void) const; 00693 TempBlendedBufferInfo* _getSkelAnimTempBufferInfo(void); 00697 TempBlendedBufferInfo* _getVertexAnimTempBufferInfo(void); 00699 uint32 getTypeFlags(void) const; 00701 VertexData* getVertexDataForBinding(void); 00702 00704 enum VertexDataBindChoice 00705 { 00706 BIND_ORIGINAL, 00707 BIND_SOFTWARE_SKELETAL, 00708 BIND_SOFTWARE_MORPH, 00709 BIND_HARDWARE_MORPH 00710 }; 00712 VertexDataBindChoice chooseVertexDataForBinding(bool hasVertexAnim) const; 00713 00715 bool _getBuffersMarkedForAnimation(void) const { return mVertexAnimationAppliedThisFrame; } 00718 void _markBuffersUsedForAnimation(void); 00719 00728 bool isInitialised(void) const { return mInitialised; } 00729 00740 void _initialise(bool forceReinitialise = false); 00742 void _deinitialise(void); 00743 00747 void backgroundLoadingComplete(Resource* res); 00748 00749 00750 00751 }; 00752 00754 class _OgreExport EntityFactory : public MovableObjectFactory 00755 { 00756 protected: 00757 MovableObject* createInstanceImpl( const String& name, const NameValuePairList* params); 00758 public: 00759 EntityFactory() {} 00760 ~EntityFactory() {} 00761 00762 static String FACTORY_TYPE_NAME; 00763 00764 const String& getType(void) const; 00765 void destroyInstance( MovableObject* obj); 00766 00767 }; 00768 00769 } // namespace 00770 00771 #endif
Copyright © 2000-2005 by The OGRE Team
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Sep 30 10:50:56 2007