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-2011 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 
00372         void setRenderQueueGroupAndPriority(uint8 queueID, ushort priority);
00373 
00376         const AxisAlignedBox& getBoundingBox(void) const;
00377 
00379         AxisAlignedBox getChildObjectsBoundingBox(void) const;
00380 
00383         void _updateRenderQueue(RenderQueue* queue);
00384 
00386         const String& getMovableType(void) const;
00387 
00394         AnimationState* getAnimationState(const String& name) const;
00404         AnimationStateSet* getAllAnimationStates(void) const;
00405 
00408         void setDisplaySkeleton(bool display);
00409 
00412         bool getDisplaySkeleton(void) const;
00413 
00414 
00420         Entity* getManualLodLevel(size_t index) const;
00421 
00427         size_t getNumManualLodLevels(void) const;
00428 
00431         ushort getCurrentLodIndex() { return mMeshLodIndex; }
00432 
00459         void setMeshLodBias(Real factor, ushort maxDetailIndex = 0, ushort minDetailIndex = 99);
00460 
00487         void setMaterialLodBias(Real factor, ushort maxDetailIndex = 0, ushort minDetailIndex = 99);
00488 
00492         void setPolygonModeOverrideable(bool PolygonModeOverrideable);
00507         TagPoint* attachObjectToBone(const String &boneName,
00508             MovableObject *pMovable,
00509             const Quaternion &offsetOrientation = Quaternion::IDENTITY,
00510             const Vector3 &offsetPosition = Vector3::ZERO);
00511 
00516         MovableObject* detachObjectFromBone(const String &movableName);
00517 
00524         void detachObjectFromBone(MovableObject* obj);
00525 
00527         void detachAllObjectsFromBone(void);
00528 
00529         typedef MapIterator<ChildObjectList> ChildObjectListIterator;
00531         ChildObjectListIterator getAttachedObjectIterator(void);
00533         Real getBoundingRadius(void) const;
00534 
00536         const AxisAlignedBox& getWorldBoundingBox(bool derive = false) const;
00538         const Sphere& getWorldBoundingSphere(bool derive = false) const;
00539 
00541         EdgeData* getEdgeList(void);
00543         bool hasEdgeList(void);
00545         ShadowRenderableListIterator getShadowVolumeRenderableIterator(
00546             ShadowTechnique shadowTechnique, const Light* light,
00547             HardwareIndexBufferSharedPtr* indexBuffer,
00548             bool extrudeVertices, Real extrusionDistance, unsigned long flags = 0 );
00549 
00551         const Matrix4* _getBoneMatrices(void) const { return mBoneMatrices;}
00553         unsigned short _getNumBoneMatrices(void) const { return mNumBoneMatrices; }
00555         bool hasSkeleton(void) const { return mSkeletonInstance != 0; }
00557         SkeletonInstance* getSkeleton(void) const { return mSkeletonInstance; }
00569         bool isHardwareAnimationEnabled(void) const { return mHardwareAnimation; }
00570 
00572         void _notifyAttached(Node* parent, bool isTagPoint = false);
00580         int getSoftwareAnimationRequests(void) const { return mSoftwareAnimationRequests; }
00592         int getSoftwareAnimationNormalsRequests(void) const { return mSoftwareAnimationNormalsRequests; }
00608         void addSoftwareAnimationRequest(bool normalsAlso);
00617         void removeSoftwareAnimationRequest(bool normalsAlso);
00618 
00623         void shareSkeletonInstanceWith(Entity* entity);
00624 
00627         bool hasVertexAnimation(void) const;
00628 
00629 
00632         void stopSharingSkeletonInstance();
00633 
00634 
00638         inline bool sharesSkeletonInstance() const { return mSharedSkeletonEntities != NULL; }
00639 
00644         inline const EntitySet* getSkeletonInstanceSharingSet() const { return mSharedSkeletonEntities; }
00645 
00656         void refreshAvailableAnimationState(void);
00657 
00665         void _updateAnimation(void);
00666 
00672         bool _isAnimated(void) const;
00673 
00676         bool _isSkeletonAnimated(void) const;
00677 
00687         VertexData* _getSkelAnimVertexData(void) const;
00696         VertexData* _getSoftwareVertexAnimVertexData(void) const;
00701         VertexData* _getHardwareVertexAnimVertexData(void) const;
00705         TempBlendedBufferInfo* _getSkelAnimTempBufferInfo(void);
00709         TempBlendedBufferInfo* _getVertexAnimTempBufferInfo(void);
00711         uint32 getTypeFlags(void) const;
00713         VertexData* getVertexDataForBinding(void);
00714 
00716         enum VertexDataBindChoice
00717         {
00718             BIND_ORIGINAL,
00719             BIND_SOFTWARE_SKELETAL,
00720             BIND_SOFTWARE_MORPH,
00721             BIND_HARDWARE_MORPH
00722         };
00724         VertexDataBindChoice chooseVertexDataForBinding(bool hasVertexAnim) const;
00725 
00727         bool _getBuffersMarkedForAnimation(void) const { return mVertexAnimationAppliedThisFrame; }
00730         void _markBuffersUsedForAnimation(void);
00731 
00740         bool isInitialised(void) const { return mInitialised; }
00741 
00752         void _initialise(bool forceReinitialise = false);
00754         void _deinitialise(void);
00755 
00759         void backgroundLoadingComplete(Resource* res);
00760 
00762         void visitRenderables(Renderable::Visitor* visitor, 
00763             bool debugRenderables = false);
00764 
00766         Real _getMeshLodFactorTransformed() const;
00767         
00771         void setSkipAnimationStateUpdate(bool skip) {
00772             mSkipAnimStateUpdates = skip;
00773         }
00774         
00778         bool getSkipAnimationStateUpdate() const {
00779             return mSkipAnimStateUpdates;
00780         }
00781 
00782 
00783     };
00784 
00786     class _OgreExport EntityFactory : public MovableObjectFactory
00787     {
00788     protected:
00789         MovableObject* createInstanceImpl( const String& name, const NameValuePairList* params);
00790     public:
00791         EntityFactory() {}
00792         ~EntityFactory() {}
00793 
00794         static String FACTORY_TYPE_NAME;
00795 
00796         const String& getType(void) const;
00797         void destroyInstance( MovableObject* obj);
00798 
00799     };
00803 } // namespace
00804 
00805 #endif

Copyright © 2008 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Sat Jan 14 2012 18:40:43