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, 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 00345 void _notifyCurrentCamera(Camera* cam); 00346 00348 void setRenderQueueGroup(uint8 queueID); 00349 00352 const AxisAlignedBox& getBoundingBox(void) const; 00353 00355 AxisAlignedBox getChildObjectsBoundingBox(void) const; 00356 00359 void _updateRenderQueue(RenderQueue* queue); 00360 00362 const String& getMovableType(void) const; 00363 00370 AnimationState* getAnimationState(const String& name) const; 00380 AnimationStateSet* getAllAnimationStates(void) const; 00381 00384 void setDisplaySkeleton(bool display); 00385 00388 bool getDisplaySkeleton(void) const; 00389 00390 00396 Entity* getManualLodLevel(size_t index) const; 00397 00403 size_t getNumManualLodLevels(void) const; 00404 00407 ushort getCurrentLodIndex() { return mMeshLodIndex; } 00408 00435 void setMeshLodBias(Real factor, ushort maxDetailIndex = 0, ushort minDetailIndex = 99); 00436 00463 void setMaterialLodBias(Real factor, ushort maxDetailIndex = 0, ushort minDetailIndex = 99); 00464 00468 void setPolygonModeOverrideable(bool PolygonModeOverrideable); 00483 TagPoint* attachObjectToBone(const String &boneName, 00484 MovableObject *pMovable, 00485 const Quaternion &offsetOrientation = Quaternion::IDENTITY, 00486 const Vector3 &offsetPosition = Vector3::ZERO); 00487 00492 MovableObject* detachObjectFromBone(const String &movableName); 00493 00500 void detachObjectFromBone(MovableObject* obj); 00501 00503 void detachAllObjectsFromBone(void); 00504 00505 typedef MapIterator<ChildObjectList> ChildObjectListIterator; 00507 ChildObjectListIterator getAttachedObjectIterator(void); 00509 Real getBoundingRadius(void) const; 00510 00512 const AxisAlignedBox& getWorldBoundingBox(bool derive = false) const; 00514 const Sphere& getWorldBoundingSphere(bool derive = false) const; 00515 00517 EdgeData* getEdgeList(void); 00519 bool hasEdgeList(void); 00521 ShadowRenderableListIterator getShadowVolumeRenderableIterator( 00522 ShadowTechnique shadowTechnique, const Light* light, 00523 HardwareIndexBufferSharedPtr* indexBuffer, 00524 bool extrudeVertices, Real extrusionDistance, unsigned long flags = 0 ); 00525 00527 const Matrix4* _getBoneMatrices(void) const { return mBoneMatrices;} 00529 unsigned short _getNumBoneMatrices(void) const { return mNumBoneMatrices; } 00531 bool hasSkeleton(void) const { return mSkeletonInstance != 0; } 00533 SkeletonInstance* getSkeleton(void) const { return mSkeletonInstance; } 00545 bool isHardwareAnimationEnabled(void) const { return mHardwareAnimation; } 00546 00548 void _notifyAttached(Node* parent, bool isTagPoint = false); 00556 int getSoftwareAnimationRequests(void) const { return mSoftwareAnimationRequests; } 00568 int getSoftwareAnimationNormalsRequests(void) const { return mSoftwareAnimationNormalsRequests; } 00584 void addSoftwareAnimationRequest(bool normalsAlso); 00593 void removeSoftwareAnimationRequest(bool normalsAlso); 00594 00599 void shareSkeletonInstanceWith(Entity* entity); 00600 00603 bool hasVertexAnimation(void) const; 00604 00605 00608 void stopSharingSkeletonInstance(); 00609 00610 00614 inline bool sharesSkeletonInstance() const { return mSharedSkeletonEntities != NULL; } 00615 00620 inline const EntitySet* getSkeletonInstanceSharingSet() const { return mSharedSkeletonEntities; } 00621 00632 void refreshAvailableAnimationState(void); 00633 00641 void _updateAnimation(void); 00642 00648 bool _isAnimated(void) const; 00649 00652 bool _isSkeletonAnimated(void) const; 00653 00663 VertexData* _getSkelAnimVertexData(void) const; 00672 VertexData* _getSoftwareVertexAnimVertexData(void) const; 00677 VertexData* _getHardwareVertexAnimVertexData(void) const; 00681 TempBlendedBufferInfo* _getSkelAnimTempBufferInfo(void); 00685 TempBlendedBufferInfo* _getVertexAnimTempBufferInfo(void); 00687 uint32 getTypeFlags(void) const; 00689 VertexData* getVertexDataForBinding(void); 00690 00692 enum VertexDataBindChoice 00693 { 00694 BIND_ORIGINAL, 00695 BIND_SOFTWARE_SKELETAL, 00696 BIND_SOFTWARE_MORPH, 00697 BIND_HARDWARE_MORPH 00698 }; 00700 VertexDataBindChoice chooseVertexDataForBinding(bool hasVertexAnim) const; 00701 00703 bool _getBuffersMarkedForAnimation(void) const { return mVertexAnimationAppliedThisFrame; } 00706 void _markBuffersUsedForAnimation(void); 00707 00716 bool isInitialised(void) const { return mInitialised; } 00717 00728 void _initialise(bool forceReinitialise = false); 00730 void _deinitialise(void); 00731 00735 void backgroundLoadingComplete(Resource* res); 00736 00738 void visitRenderables(Renderable::Visitor* visitor, 00739 bool debugRenderables = false); 00740 00741 00742 00743 00744 }; 00745 00747 class _OgreExport EntityFactory : public MovableObjectFactory 00748 { 00749 protected: 00750 MovableObject* createInstanceImpl( const String& name, const NameValuePairList* params); 00751 public: 00752 EntityFactory() {} 00753 ~EntityFactory() {} 00754 00755 static String FACTORY_TYPE_NAME; 00756 00757 const String& getType(void) const; 00758 void destroyInstance( MovableObject* obj); 00759 00760 }; 00761 00762 } // namespace 00763 00764 #endif
Copyright © 2008 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Thu Aug 28 20:53:47 2008