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-2009 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 typedef set<Entity*>::type EntitySet; 00088 00089 protected: 00090 00093 Entity(); 00096 Entity( const String& name, const MeshPtr& mesh); 00097 00100 MeshPtr mMesh; 00101 00104 typedef vector<SubEntity*>::type SubEntityList; 00105 SubEntityList mSubEntityList; 00106 00107 00109 AnimationStateSet* mAnimationState; 00110 00111 00113 TempBlendedBufferInfo mTempSkelAnimInfo; 00115 VertexData* mSkelAnimVertexData; 00117 TempBlendedBufferInfo mTempVertexAnimInfo; 00119 VertexData* mSoftwareVertexAnimVertexData; 00123 VertexData* mHardwareVertexAnimVertexData; 00125 bool mVertexAnimationAppliedThisFrame; 00127 bool mPreparedForShadowVolumes; 00128 00131 const VertexData* findBlendedVertexData(const VertexData* orig); 00134 SubEntity* findSubEntityForVertexData(const VertexData* orig); 00135 00138 void extractTempBufferInfo(VertexData* sourceData, TempBlendedBufferInfo* info); 00140 VertexData* cloneVertexDataRemoveBlendInfo(const VertexData* source); 00142 void prepareTempBlendBuffers(void); 00145 void markBuffersUnusedForAnimation(void); 00149 void restoreBuffersForUnusedAnimation(bool hardwareAnimation); 00150 00156 void bindMissingHardwarePoseBuffers(const VertexData* srcData, 00157 VertexData* destData); 00158 00160 Matrix4 *mBoneWorldMatrices; 00162 Matrix4 *mBoneMatrices; 00163 unsigned short mNumBoneMatrices; 00165 unsigned long mFrameAnimationLastUpdated; 00166 00168 void updateAnimation(void); 00169 00173 unsigned long *mFrameBonesLastUpdated; 00174 00180 EntitySet* mSharedSkeletonEntities; 00181 00183 void cacheBoneMatrices(void); 00184 00186 bool mDisplaySkeleton; 00188 bool mHardwareAnimation; 00190 ushort mHardwarePoseCount; 00192 bool mVertexProgramInUse; 00194 int mSoftwareAnimationRequests; 00196 int mSoftwareAnimationNormalsRequests; 00198 bool mSkipAnimStateUpdates; 00199 00200 00202 ushort mMeshLodIndex; 00203 00205 Real mMeshLodFactorTransformed; 00207 ushort mMinMeshLodIndex; 00209 ushort mMaxMeshLodIndex; 00210 00212 Real mMaterialLodFactor; 00214 Real mMaterialLodFactorTransformed; 00216 ushort mMinMaterialLodIndex; 00218 ushort mMaxMaterialLodIndex; 00219 00225 typedef vector<Entity*>::type LODEntityList; 00226 LODEntityList mLodEntityList; 00227 00230 SkeletonInstance* mSkeletonInstance; 00231 00233 bool mInitialised; 00234 00236 Matrix4 mLastParentXform; 00237 00239 size_t mMeshStateCount; 00240 00242 void buildSubEntityList(MeshPtr& mesh, SubEntityList* sublist); 00243 00245 void attachObjectImpl(MovableObject *pMovable, TagPoint *pAttachingPoint); 00246 00248 void detachObjectImpl(MovableObject* pObject); 00249 00251 void detachAllObjectsImpl(void); 00252 00254 void reevaluateVertexProcessing(void); 00255 00257 void applyVertexAnimation(bool hardwareAnimation, bool stencilShadows); 00259 void initHardwareAnimationElements(VertexData* vdata, 00260 ushort numberOfElements); 00262 bool tempVertexAnimBuffersBound(void) const; 00264 bool tempSkelAnimBuffersBound(bool requestNormals) const; 00265 00266 public: 00268 typedef map<String, MovableObject*>::type ChildObjectList; 00269 protected: 00270 ChildObjectList mChildObjectList; 00271 00272 00274 mutable AxisAlignedBox mFullBoundingBox; 00275 00276 ShadowRenderableList mShadowRenderables; 00277 00279 class _OgreExport EntityShadowRenderable : public ShadowRenderable 00280 { 00281 protected: 00282 Entity* mParent; 00283 // Shared link to position buffer 00284 HardwareVertexBufferSharedPtr mPositionBuffer; 00285 // Shared link to w-coord buffer (optional) 00286 HardwareVertexBufferSharedPtr mWBuffer; 00287 // Link to current vertex data used to bind (maybe changes) 00288 const VertexData* mCurrentVertexData; 00289 // Original position buffer source binding 00290 unsigned short mOriginalPosBufferBinding; 00292 SubEntity* mSubEntity; 00293 00294 00295 public: 00296 EntityShadowRenderable(Entity* parent, 00297 HardwareIndexBufferSharedPtr* indexBuffer, const VertexData* vertexData, 00298 bool createSeparateLightCap, SubEntity* subent, bool isLightCap = false); 00299 ~EntityShadowRenderable(); 00301 void getWorldTransforms(Matrix4* xform) const; 00302 HardwareVertexBufferSharedPtr getPositionBuffer(void) { return mPositionBuffer; } 00303 HardwareVertexBufferSharedPtr getWBuffer(void) { return mWBuffer; } 00305 void rebindPositionBuffer(const VertexData* vertexData, bool force); 00307 bool isVisible(void) const; 00308 00309 }; 00310 public: 00313 ~Entity(); 00314 00317 const MeshPtr& getMesh(void) const; 00318 00321 SubEntity* getSubEntity(unsigned int index) const; 00322 00326 SubEntity* getSubEntity( const String& name ) const; 00327 00330 unsigned int getNumSubEntities(void) const; 00331 00341 Entity* clone( const String& newName ) const; 00342 00351 void setMaterialName( const String& name, const String& groupName = ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME ); 00352 00353 00362 void setMaterial(const MaterialPtr& material); 00363 00366 void _notifyCurrentCamera(Camera* cam); 00367 00369 void setRenderQueueGroup(uint8 queueID); 00370 00373 const AxisAlignedBox& getBoundingBox(void) const; 00374 00376 AxisAlignedBox getChildObjectsBoundingBox(void) const; 00377 00380 void _updateRenderQueue(RenderQueue* queue); 00381 00383 const String& getMovableType(void) const; 00384 00391 AnimationState* getAnimationState(const String& name) const; 00401 AnimationStateSet* getAllAnimationStates(void) const; 00402 00405 void setDisplaySkeleton(bool display); 00406 00409 bool getDisplaySkeleton(void) const; 00410 00411 00417 Entity* getManualLodLevel(size_t index) const; 00418 00424 size_t getNumManualLodLevels(void) const; 00425 00428 ushort getCurrentLodIndex() { return mMeshLodIndex; } 00429 00456 void setMeshLodBias(Real factor, ushort maxDetailIndex = 0, ushort minDetailIndex = 99); 00457 00484 void setMaterialLodBias(Real factor, ushort maxDetailIndex = 0, ushort minDetailIndex = 99); 00485 00489 void setPolygonModeOverrideable(bool PolygonModeOverrideable); 00504 TagPoint* attachObjectToBone(const String &boneName, 00505 MovableObject *pMovable, 00506 const Quaternion &offsetOrientation = Quaternion::IDENTITY, 00507 const Vector3 &offsetPosition = Vector3::ZERO); 00508 00513 MovableObject* detachObjectFromBone(const String &movableName); 00514 00521 void detachObjectFromBone(MovableObject* obj); 00522 00524 void detachAllObjectsFromBone(void); 00525 00526 typedef MapIterator<ChildObjectList> ChildObjectListIterator; 00528 ChildObjectListIterator getAttachedObjectIterator(void); 00530 Real getBoundingRadius(void) const; 00531 00533 const AxisAlignedBox& getWorldBoundingBox(bool derive = false) const; 00535 const Sphere& getWorldBoundingSphere(bool derive = false) const; 00536 00538 EdgeData* getEdgeList(void); 00540 bool hasEdgeList(void); 00542 ShadowRenderableListIterator getShadowVolumeRenderableIterator( 00543 ShadowTechnique shadowTechnique, const Light* light, 00544 HardwareIndexBufferSharedPtr* indexBuffer, 00545 bool extrudeVertices, Real extrusionDistance, unsigned long flags = 0 ); 00546 00548 const Matrix4* _getBoneMatrices(void) const { return mBoneMatrices;} 00550 unsigned short _getNumBoneMatrices(void) const { return mNumBoneMatrices; } 00552 bool hasSkeleton(void) const { return mSkeletonInstance != 0; } 00554 SkeletonInstance* getSkeleton(void) const { return mSkeletonInstance; } 00566 bool isHardwareAnimationEnabled(void) const { return mHardwareAnimation; } 00567 00569 void _notifyAttached(Node* parent, bool isTagPoint = false); 00577 int getSoftwareAnimationRequests(void) const { return mSoftwareAnimationRequests; } 00589 int getSoftwareAnimationNormalsRequests(void) const { return mSoftwareAnimationNormalsRequests; } 00605 void addSoftwareAnimationRequest(bool normalsAlso); 00614 void removeSoftwareAnimationRequest(bool normalsAlso); 00615 00620 void shareSkeletonInstanceWith(Entity* entity); 00621 00624 bool hasVertexAnimation(void) const; 00625 00626 00629 void stopSharingSkeletonInstance(); 00630 00631 00635 inline bool sharesSkeletonInstance() const { return mSharedSkeletonEntities != NULL; } 00636 00641 inline const EntitySet* getSkeletonInstanceSharingSet() const { return mSharedSkeletonEntities; } 00642 00653 void refreshAvailableAnimationState(void); 00654 00662 void _updateAnimation(void); 00663 00669 bool _isAnimated(void) const; 00670 00673 bool _isSkeletonAnimated(void) const; 00674 00684 VertexData* _getSkelAnimVertexData(void) const; 00693 VertexData* _getSoftwareVertexAnimVertexData(void) const; 00698 VertexData* _getHardwareVertexAnimVertexData(void) const; 00702 TempBlendedBufferInfo* _getSkelAnimTempBufferInfo(void); 00706 TempBlendedBufferInfo* _getVertexAnimTempBufferInfo(void); 00708 uint32 getTypeFlags(void) const; 00710 VertexData* getVertexDataForBinding(void); 00711 00713 enum VertexDataBindChoice 00714 { 00715 BIND_ORIGINAL, 00716 BIND_SOFTWARE_SKELETAL, 00717 BIND_SOFTWARE_MORPH, 00718 BIND_HARDWARE_MORPH 00719 }; 00721 VertexDataBindChoice chooseVertexDataForBinding(bool hasVertexAnim) const; 00722 00724 bool _getBuffersMarkedForAnimation(void) const { return mVertexAnimationAppliedThisFrame; } 00727 void _markBuffersUsedForAnimation(void); 00728 00737 bool isInitialised(void) const { return mInitialised; } 00738 00749 void _initialise(bool forceReinitialise = false); 00751 void _deinitialise(void); 00752 00756 void backgroundLoadingComplete(Resource* res); 00757 00759 void visitRenderables(Renderable::Visitor* visitor, 00760 bool debugRenderables = false); 00761 00763 Real _getMeshLodFactorTransformed() const; 00764 00768 void setSkipAnimationStateUpdate(bool skip) { 00769 mSkipAnimStateUpdates = skip; 00770 } 00771 00775 bool getSkipAnimationStateUpdate() const { 00776 return mSkipAnimStateUpdates; 00777 } 00778 00779 00780 }; 00781 00783 class _OgreExport EntityFactory : public MovableObjectFactory 00784 { 00785 protected: 00786 MovableObject* createInstanceImpl( const String& name, const NameValuePairList* params); 00787 public: 00788 EntityFactory() {} 00789 ~EntityFactory() {} 00790 00791 static String FACTORY_TYPE_NAME; 00792 00793 const String& getType(void) const; 00794 void destroyInstance( MovableObject* obj); 00795 00796 }; 00800 } // namespace 00801 00802 #endif
Copyright © 2008 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Thu Dec 31 16:27:09 2009