BVB Source Codes

CRYENGINE Show StatObj.h Source code

Return Download CRYENGINE: download StatObj.h Source code - Download CRYENGINE Source code - Type:.h
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. // -------------------------------------------------------------------------
  4. //  File name:   statobj.h
  5. //  Version:     v1.00
  6. //  Created:     28/5/2001 by Vladimir Kajalin
  7. //  Compilers:   Visual Studio.NET
  8. //  Description:
  9. // -------------------------------------------------------------------------
  10. //  History:
  11. //
  12. ////////////////////////////////////////////////////////////////////////////
  13.  
  14. #ifndef STAT_OBJ_H
  15. #define STAT_OBJ_H
  16.  
  17. #if CRY_PLATFORM_DESKTOP
  18.         #define TRACE_CGF_LEAKS
  19. #endif
  20.  
  21. class CIndexedMesh;
  22. class CRenderObject;
  23. class CContentCGF;
  24. struct CNodeCGF;
  25. struct CMaterialCGF;
  26. struct phys_geometry;
  27. struct IIndexedMesh;
  28. struct IParticleEffect;
  29.  
  30. #include "../Cry3DEngine/Cry3DEngineBase.h"
  31. #include <CryCore/Containers/CryArray.h>
  32.  
  33. #include <Cry3DEngine/IStatObj.h>
  34. #include <CrySystem/IStreamEngine.h>
  35. #include "RenderMeshUtils.h"
  36. #include <CryMath/GeomQuery.h>
  37.  
  38. #define MAX_PHYS_GEOMS_TYPES 4
  39.  
  40. struct SDeformableMeshData
  41. {
  42.         IGeometry*    pInternalGeom;
  43.         int*          pVtxMap;
  44.         unsigned int* pUsedVtx;
  45.         int*          pVtxTri;
  46.         int*          pVtxTriBuf;
  47.         float*        prVtxValency;
  48.         Vec3*         pPrevVtx;
  49.         float         kViscosity;
  50. };
  51.  
  52. struct SSpine
  53. {
  54.         ~SSpine() { delete[] pVtx; delete[] pVtxCur; delete[] pSegDim; }
  55.         SSpine() { pVtx = 0; pVtxCur = 0; pSegDim = 0; bActive = false; nVtx = 0; len = 0; navg = Vec3(0, 0, 0); idmat = 0; iAttachSpine = 0; iAttachSeg = 0; }
  56.  
  57.         bool  bActive;
  58.         Vec3* pVtx;
  59.         Vec3* pVtxCur;
  60.         Vec4* pSegDim;
  61.         int   nVtx;
  62.         float len;
  63.         Vec3  navg;
  64.         int   idmat;
  65.         int   iAttachSpine;
  66.         int   iAttachSeg;
  67. };
  68.  
  69. class CStatObjFoliage : public IFoliage, public Cry3DEngineBase
  70. {
  71. public:
  72.         CStatObjFoliage()
  73.         {
  74.                 m_next = 0;
  75.                 m_prev = 0;
  76.                 m_lifeTime = 0;
  77.                 m_ppThis = 0;
  78.                 m_pStatObj = 0;
  79.                 m_pRopes = 0;
  80.                 m_pRopesActiveTime = 0;
  81.                 m_nRopes = 0;
  82.                 m_nRefCount = 1;
  83.                 m_timeIdle = 0;
  84.                 m_pVegInst = 0;
  85.                 m_pTrunk = 0;
  86.                 m_pSkinningTransformations[0] = 0;
  87.                 m_pSkinningTransformations[1] = 0;
  88.                 m_iActivationSource = 0;
  89.                 m_flags = 0;
  90.                 m_bGeomRemoved = 0;
  91.                 m_bEnabled = 1;
  92.                 m_timeInvisible = 0;
  93.                 m_bDelete = 0;
  94.                 m_pRenderObject = 0;
  95.                 m_minEnergy = 0.0f;
  96.                 m_stiffness = 0.0f;
  97.                 arrSkinningRendererData[0].pSkinningData = NULL;
  98.                 arrSkinningRendererData[0].nFrameID = 0;
  99.                 arrSkinningRendererData[1].pSkinningData = NULL;
  100.                 arrSkinningRendererData[1].nFrameID = 0;
  101.                 arrSkinningRendererData[2].pSkinningData = NULL;
  102.                 arrSkinningRendererData[2].nFrameID = 0;
  103.         }
  104.         ~CStatObjFoliage();
  105.         virtual void             AddRef()  { m_nRefCount++; }
  106.         virtual void             Release() { if (--m_nRefCount <= 0) m_bDelete = 2; }
  107.  
  108.         virtual int              Serialize(TSerialize ser);
  109.         virtual void             SetFlags(int flags);
  110.         virtual int              GetFlags()                    { return m_flags; }
  111.         virtual IRenderNode*     GetIRenderNode()              { return m_pVegInst; }
  112.         virtual int              GetBranchCount()              { return m_nRopes; }
  113.         virtual IPhysicalEntity* GetBranchPhysics(int iBranch) { return (unsigned int)iBranch < (unsigned int)m_nRopes ? m_pRopes[iBranch] : 0; }
  114.  
  115.         virtual SSkinningData*   GetSkinningData(const Matrix34& RenderMat34, const SRenderingPassInfo& passInfo);
  116.  
  117.         uint32                   ComputeSkinningTransformationsCount();
  118.         void                     ComputeSkinningTransformations(uint32 nList);
  119.  
  120.         void                     OnHit(struct EventPhysCollision* pHit);
  121.         void                     Update(float dt, const CCamera& rCamera);
  122.         void                     BreakBranch(int idx);
  123.  
  124.         CStatObjFoliage*  m_next, * m_prev;
  125.         int               m_nRefCount;
  126.         int               m_flags;
  127.         CStatObj*         m_pStatObj;
  128.         IPhysicalEntity** m_pRopes;
  129.         float*            m_pRopesActiveTime;
  130.         IPhysicalEntity*  m_pTrunk;
  131.         int16             m_nRopes;
  132.         int16             m_bEnabled;
  133.         float             m_timeIdle, m_lifeTime;
  134.         IFoliage**        m_ppThis;
  135.         QuatTS*           m_pSkinningTransformations[2];
  136.         int               m_iActivationSource;
  137.         int               m_bGeomRemoved;
  138.         IRenderNode*      m_pVegInst;
  139.         CRenderObject*    m_pRenderObject;
  140.         float             m_timeInvisible;
  141.         float             m_minEnergy;
  142.         float             m_stiffness;
  143.         int               m_bDelete;
  144.         // history for skinning data, needed for motion blur
  145.         struct { SSkinningData* pSkinningData; int nFrameID; } arrSkinningRendererData[3]; // tripple buffered for motion blur
  146. };
  147.  
  148. struct SClothTangentVtx
  149. {
  150.         int  ivtxT;   // for each vertex, specifies the iThisVtx->ivtxT edge, which is the closest to the vertex's tangent vector
  151.         Vec3 edge;    // that edge's projection on the vertex's normal basis
  152.         int  sgnNorm; // sign of phys normal * normal from the basis
  153. };
  154.  
  155. struct SSkinVtx
  156. {
  157.         int      bVolumetric;
  158.         int      idx[4];
  159.         float    w[4];
  160.         Matrix33 M;
  161. };
  162.  
  163. struct SDelayedSkinParams
  164. {
  165.         Matrix34   mtxSkelToMesh;
  166.         IGeometry* pPhysSkel;
  167.         float      r;
  168. };
  169.  
  170. struct SPhysGeomThunk
  171. {
  172.         phys_geometry* pgeom;
  173.         int            type;
  174.         void           GetMemoryUsage(ICrySizer* pSizer) const
  175.         {
  176.                 //              pSizer->AddObject(pgeom);
  177.         }
  178. };
  179.  
  180. struct SPhysGeomArray
  181. {
  182.         phys_geometry* operator[](int idx) const
  183.         {
  184.                 if (idx < PHYS_GEOM_TYPE_DEFAULT)
  185.                         return idx < (int)m_array.size() ? m_array[idx].pgeom : 0;
  186.                 else
  187.                 {
  188.                         int i;
  189.                         for (i = m_array.size() - 1; i >= 0 && m_array[i].type != idx; i--);
  190.                         return i >= 0 ? m_array[i].pgeom : 0;
  191.                 }
  192.         }
  193.         void SetPhysGeom(phys_geometry* pgeom, int idx = PHYS_GEOM_TYPE_DEFAULT, int type = PHYS_GEOM_TYPE_DEFAULT)
  194.         {
  195.                 int i;
  196.                 if (idx < PHYS_GEOM_TYPE_DEFAULT)
  197.                         i = idx, idx = type;
  198.                 else
  199.                         for (i = 0; i < (int)m_array.size() && m_array[i].type != idx; i++);
  200.                 if (pgeom)
  201.                 {
  202.                         if (i >= (int)m_array.size())
  203.                                 m_array.resize(i + 1);
  204.                         m_array[i].pgeom = pgeom;
  205.                         m_array[i].type = idx;
  206.                 }
  207.                 else if (i < (int)m_array.size())
  208.                         m_array.erase(m_array.begin() + i);
  209.         }
  210.         int  GetGeomCount() const { return m_array.size(); }
  211.         int  GetGeomType(int idx) { return idx >= PHYS_GEOM_TYPE_DEFAULT ? idx : m_array[idx].type; }
  212.         std::vector<SPhysGeomThunk> m_array;
  213.         void GetMemoryUsage(ICrySizer* pSizer) const
  214.         {
  215.                 pSizer->AddObject(m_array);
  216.         }
  217. };
  218.  
  219. struct SSyncToRenderMeshContext
  220. {
  221.         Vec3*                         vmin, * vmax;
  222.         int                           iVtx0;
  223.         int                           nVtx;
  224.         strided_pointer<Vec3>         pVtx;
  225.         int*                          pVtxMap;
  226.         int                           mask;
  227.         float                         rscale;
  228.         SClothTangentVtx*             ctd;
  229.         strided_pointer<Vec3>         pMeshVtx;
  230.         strided_pointer<SPipTangents> pTangents;
  231.         strided_pointer<Vec3>         pNormals; // TODO: change Vec3 to SPipNormal
  232.         CStatObj*                     pObj;
  233.         JobManager::SJobState         jobState;
  234.  
  235.         void                          Set(Vec3* _vmin, Vec3* _vmax, int _iVtx0, int _nVtx, strided_pointer<Vec3> _pVtx, int* _pVtxMap
  236.                                           , int _mask, float _rscale, SClothTangentVtx* _ctd, strided_pointer<Vec3> _pMeshVtx
  237.                                           , strided_pointer<SPipTangents> _pTangents, strided_pointer<Vec3> _pNormals, CStatObj* _pObj)
  238.         {
  239.                 vmin = _vmin;
  240.                 vmax = _vmax;
  241.                 iVtx0 = _iVtx0;
  242.                 nVtx = _nVtx;
  243.                 pVtx = _pVtx;
  244.                 pVtxMap = _pVtxMap;
  245.                 mask = _mask;
  246.                 rscale = _rscale;
  247.                 ctd = _ctd;
  248.                 pMeshVtx = _pMeshVtx;
  249.                 pTangents = _pTangents;
  250.                 pNormals = _pNormals;
  251.                 pObj = _pObj;
  252.         }
  253. };
  254.  
  255. struct CRY_ALIGN(8) CStatObj: public IStatObj, public IStreamCallback, public stl::intrusive_linked_list_node<CStatObj>, public Cry3DEngineBase
  256. {
  257.         CStatObj();
  258.         ~CStatObj();
  259.  
  260. public:
  261.         //////////////////////////////////////////////////////////////////////////
  262.         // Variables.
  263.         //////////////////////////////////////////////////////////////////////////
  264.         volatile int m_nUsers; // reference counter
  265.  
  266.         uint32 m_nLastDrawMainFrameId;
  267.  
  268.         _smart_ptr<IRenderMesh> m_pRenderMesh;
  269.  
  270.         CryCriticalSection m_streamingMeshLock;
  271.         _smart_ptr<IRenderMesh> m_pStreamedRenderMesh;
  272.         _smart_ptr<IRenderMesh> m_pMergedRenderMesh;
  273.  
  274.         // Used by hierarchical breaking to hide sub-objects that initially must be hidden.
  275.         hidemask m_nInitialSubObjHideMask;
  276.  
  277.         CIndexedMesh* m_pIndexedMesh;
  278.         volatile int m_lockIdxMesh;
  279.  
  280.         string m_szFileName;
  281.         string m_szGeomName;
  282.         string m_szProperties;
  283.         string m_szStreamingDependencyFilePath;
  284.  
  285.         int m_nLoadedTrisCount;
  286.         int m_nLoadedVertexCount;
  287.         int m_nRenderTrisCount;
  288.         int m_nRenderMatIds;
  289.         float m_fGeometricMeanFaceArea;
  290.         float m_fLodDistance;
  291.         Vec3 m_depthSortOffset;
  292.  
  293.         // Default material.
  294.         _smart_ptr<IMaterial> m_pMaterial;
  295.  
  296.         float m_fRadiusHors;
  297.         float m_fRadiusVert;
  298.  
  299.         AABB m_AABB;
  300.         Vec3 m_vVegCenter;
  301.  
  302.         SPhysGeomArray m_arrPhysGeomInfo;
  303.         ITetrLattice* m_pLattice;
  304.         IStatObj* m_pLastBooleanOp;
  305.         float m_lastBooleanOpScale;
  306.  
  307.         _smart_ptr<CStatObj>* m_pLODs;
  308.         _smart_ptr<CStatObj> m_pLod0;      // Level 0 stat object. (Pointer to the original object of the LOD)
  309.         unsigned int m_nMinUsableLod0 : 8; // What is the minimal LOD that can be used as LOD0.
  310.         unsigned int m_nMaxUsableLod0 : 8; // What is the maximal LOD that can be used as LOD0.
  311.         unsigned int m_nMaxUsableLod  : 8; // What is the maximal LOD that can be used.
  312.         unsigned int m_nLoadedLodsNum : 8; // How many lods loaded.
  313.  
  314.         string m_cgfNodeName;
  315.  
  316.         //////////////////////////////////////////////////////////////////////////
  317.         // Externally set flags from enum EStaticObjectFlags.
  318.         //////////////////////////////////////////////////////////////////////////
  319.         int m_nFlags;
  320.  
  321.         //////////////////////////////////////////////////////////////////////////
  322.         // Internal Flags.
  323.         //////////////////////////////////////////////////////////////////////////
  324.         unsigned int m_bCheckGarbage : 1;
  325.         unsigned int m_bCanUnload : 1;
  326.         unsigned int m_bLodsLoaded : 1;
  327.         unsigned int m_bDefaultObject : 1;
  328.         unsigned int m_bOpenEdgesTested : 1;
  329.         unsigned int m_bSubObject : 1;          // This is sub object.
  330.         unsigned int m_bVehicleOnlyPhysics : 1; // Object can be used for collisions with vehicles only
  331.         unsigned int m_bBreakableByGame : 1;    // material is marked as breakable by game
  332.         unsigned int m_bSharesChildren : 1;     // means its subobjects belong to another parent statobj
  333.         unsigned int m_bHasDeformationMorphs : 1;
  334.         unsigned int m_bTmpIndexedMesh : 1; // indexed mesh is temporary and can be deleted after MakeRenderMesh
  335.         unsigned int m_bUnmergable : 1;     // Set if sub objects cannot be merged together to the single render merge.
  336.         unsigned int m_bMerged : 1;         // Set if sub objects merged together to the single render merge.
  337.         unsigned int m_bMergedLODs : 1;     // Set if m_pLODs were created while merging LODs
  338.         unsigned int m_bLowSpecLod0Set : 1;
  339.         unsigned int m_bHaveOcclusionProxy : 1; // If this stat object or its childs have occlusion proxy.
  340.         unsigned int m_bLodsAreLoadedFromSeparateFile : 1;
  341.         unsigned int m_bNoHitRefinement : 1;       // doesn't refine bullet hits against rendermesh
  342.         unsigned int m_bDontOccludeExplosions : 1; // don't act as an explosion occluder in physics
  343.         unsigned int m_hasClothTangentsData : 1;
  344.         unsigned int m_hasSkinInfo : 1;
  345.         unsigned int m_bMeshStrippedCGF : 1; // This CGF was loaded from the Mesh Stripped CGF, (in Level Cache)
  346.         unsigned int m_isDeformable : 1;     // This cgf is deformable in the sense that it has a special renderpath
  347.         unsigned int m_isProxyTooBig : 1;
  348.         unsigned int m_bHasStreamOnlyCGF : 1;
  349.  
  350.         int m_idmatBreakable; // breakable id for the physics
  351.         //////////////////////////////////////////////////////////////////////////
  352.  
  353.         // streaming
  354.         int m_nRenderMeshMemoryUsage;
  355.         int m_nMergedMemoryUsage;
  356.         int m_arrRenderMeshesPotentialMemoryUsage[2];
  357.         IReadStreamPtr m_pReadStream;
  358.         uint32 m_nModificationId; // used to detect the cases when dependent permanent render objects have to be updated
  359.  
  360. #if !defined (_RELEASE) || defined(ENABLE_STATOSCOPE_RELEASE)
  361.         static float s_fStreamingTime;
  362.         static int s_nBandwidth;
  363.         float m_fStreamingStart;
  364. #endif
  365.  
  366. #ifdef OBJMAN_STREAM_STATS
  367.         int m_nStatoscopeState;
  368. #endif
  369.  
  370.         //////////////////////////////////////////////////////////////////////////
  371.  
  372.         uint16* m_pMapFaceToFace0;
  373.         union
  374.         {
  375.                 SClothTangentVtx* m_pClothTangentsData;
  376.                 SSkinVtx*         m_pSkinInfo;
  377.         };
  378.         SDelayedSkinParams* m_pDelayedSkinParams;
  379.         //////////////////////////////////////////////////////////////////////////
  380.  
  381.         //////////////////////////////////////////////////////////////////////////
  382.         // Bendable Foliage.
  383.         //////////////////////////////////////////////////////////////////////////
  384.         SSpine* m_pSpines;
  385.         int m_nSpines;
  386.         struct SMeshBoneMapping_uint8* m_pBoneMapping;
  387.         std::vector<uint16> m_chunkBoneIds;
  388.         //////////////////////////////////////////////////////////////////////////
  389.  
  390.         //////////////////////////////////////////////////////////////////////////
  391.         // for debug purposes
  392.         //////////////////////////////////////////////////////////////////////////
  393. #ifdef TRACE_CGF_LEAKS
  394.         string m_sLoadingCallstack;
  395. #endif
  396.  
  397. private:
  398.  
  399.         // Returns a list of all CStatObj instances contained within this object (all sub-objects plus the parent object itself).
  400.         std::vector<CStatObj*> GatherAllObjects();
  401.  
  402.         //////////////////////////////////////////////////////////////////////////
  403.         // Sub objects.
  404.         //////////////////////////////////////////////////////////////////////////
  405.         std::vector<SSubObject> m_subObjects;
  406.         CStatObj* m_pParentObject;       // Parent object (Must not be smart pointer).
  407.         CStatObj* m_pClonedSourceObject; // If this is cloned object, pointer to original source object (Must not be smart pointer).
  408.         int m_nSubObjectMeshCount;
  409.         int m_nNodeCount;
  410.  
  411.         CGeomExtents m_Extents;           // Cached extents for random pos generation.
  412.  
  413.         //////////////////////////////////////////////////////////////////////////
  414.         // Special AI/Physics parameters.
  415.         //////////////////////////////////////////////////////////////////////////
  416.         float m_aiVegetationRadius;
  417.         float m_phys_mass;
  418.         float m_phys_density;
  419.  
  420.         //////////////////////////////////////////////////////////////////////////
  421.         // used only in the editor
  422.         //////////////////////////////////////////////////////////////////////////
  423.  
  424.         SSyncToRenderMeshContext* m_pAsyncUpdateContext;
  425.  
  426.         //////////////////////////////////////////////////////////////////////////
  427.         // METHODS.
  428.         //////////////////////////////////////////////////////////////////////////
  429. public:
  430.         //////////////////////////////////////////////////////////////////////////
  431.         // Fast non virtual access functions.
  432.         ILINE IStatObj::SSubObject& SubObject(int nIndex)  { return m_subObjects[nIndex]; };
  433.         ILINE int                   SubObjectCount() const { return m_subObjects.size(); };
  434.         //////////////////////////////////////////////////////////////////////////
  435.  
  436.         virtual bool IsUnloadable() const final { return m_bCanUnload; }
  437.         void DisableStreaming();
  438.  
  439.         virtual IIndexedMesh*    GetIndexedMesh(bool bCreatefNone = false) final;
  440.         virtual IIndexedMesh*    CreateIndexedMesh() final;
  441.         void ReleaseIndexedMesh(bool bRenderMeshUpdated = false);
  442.         virtual ILINE const Vec3 GetVegCenter() final          { return m_vVegCenter; }
  443.  
  444.         virtual void             SetFlags(int nFlags) final             { m_nFlags = nFlags; IncrementModificationId(); }
  445.         virtual int              GetFlags() const final         { return m_nFlags; };
  446.  
  447.         virtual unsigned int     GetVehicleOnlyPhysics() final { return m_bVehicleOnlyPhysics; };
  448.         virtual int              GetIDMatBreakable() final     { return m_idmatBreakable; };
  449.         virtual unsigned int     GetBreakableByGame() final    { return m_bBreakableByGame; };
  450.  
  451.         virtual bool IsDeformable() final;
  452.  
  453.         // Loader
  454.         bool LoadCGF(const char* filename, bool bLod, unsigned long nLoadingFlags, const void* pData, const int nDataSize);
  455.         bool LoadCGF_Int(const char* filename, bool bLod, unsigned long nLoadingFlags, const void* pData, const int nDataSize);
  456.  
  457.         //////////////////////////////////////////////////////////////////////////
  458.         virtual void SetMaterial(IMaterial * pMaterial) final;
  459.         virtual IMaterial* GetMaterial() const final { return m_pMaterial; }
  460.         //////////////////////////////////////////////////////////////////////////
  461.  
  462.         void RenderInternal(CRenderObject * pRenderObject, hidemask nSubObjectHideMask, const CLodValue &lodValue, const SRenderingPassInfo &passInfo);
  463.         void RenderObjectInternal(CRenderObject * pRenderObject, int nLod, uint8 uLodDissolveRef, bool dissolveOut, const SRenderingPassInfo &passInfo);
  464.         void RenderSubObject(CRenderObject * pRenderObject, int nLod,
  465.                              int nSubObjId, const Matrix34A &renderTM, const SRenderingPassInfo &passInfo);
  466.         void RenderSubObjectInternal(CRenderObject * pRenderObject, int nLod, const SRenderingPassInfo &passInfo);
  467.         virtual void Render(const SRendParams &rParams, const SRenderingPassInfo &passInfo) final;
  468.         void RenderRenderMesh(CRenderObject * pObj, struct SInstancingInfo* pInstInfo, const SRenderingPassInfo &passInfo);
  469.         virtual phys_geometry* GetPhysGeom(int nGeomType = PHYS_GEOM_TYPE_DEFAULT) const final { return m_arrPhysGeomInfo[nGeomType]; }
  470.         virtual void           SetPhysGeom(phys_geometry* pPhysGeom, int nGeomType = PHYS_GEOM_TYPE_DEFAULT) final
  471.         {
  472.                 if (m_arrPhysGeomInfo[nGeomType])
  473.                         GetPhysicalWorld()->GetGeomManager()->UnregisterGeometry(m_arrPhysGeomInfo[nGeomType]);
  474.                 m_arrPhysGeomInfo.SetPhysGeom(pPhysGeom, nGeomType);
  475.         }
  476.         virtual IPhysicalEntity* GetPhysEntity() const final               { return NULL; }
  477.         virtual ITetrLattice*    GetTetrLattice() final                    { return m_pLattice; }
  478.  
  479.         virtual float            GetAIVegetationRadius() const final       { return m_aiVegetationRadius; }
  480.         virtual void             SetAIVegetationRadius(float radius) final { m_aiVegetationRadius = radius; }
  481.  
  482.         //! Refresh object ( reload shaders or/and object geometry )
  483.         virtual void Refresh(int nFlags) final;
  484.  
  485.         virtual IRenderMesh* GetRenderMesh() const final { return m_pRenderMesh; };
  486.         void SetRenderMesh(IRenderMesh * pRM);
  487.  
  488.         virtual const char* GetFilePath() final                       { return (m_szFileName); }
  489.         virtual void        SetFilePath(const char* szFileName) final { m_szFileName = szFileName; }
  490.         virtual const char* GetGeoName() final                        { return (m_szGeomName); }
  491.         virtual void        SetGeoName(const char* szGeoName) final   { m_szGeomName = szGeoName; }
  492.         virtual bool IsSameObject(const char* szFileName, const char* szGeomName) final;
  493.  
  494.         //set object's min/max bbox
  495.         virtual void SetBBoxMin(const Vec3& vBBoxMin) final { m_AABB.min = vBBoxMin; }
  496.         virtual void SetBBoxMax(const Vec3& vBBoxMax) final { m_AABB.max = vBBoxMax; }
  497.         virtual AABB GetAABB() const final                  { return m_AABB; }
  498.  
  499.         virtual float GetExtent(EGeomForm eForm) final;
  500.         virtual void GetRandomPos(PosNorm & ran, CRndGen & seed, EGeomForm eForm) const final;
  501.  
  502.         virtual Vec3 GetHelperPos(const char* szHelperName) final;
  503.         virtual const Matrix34& GetHelperTM(const char* szHelperName) final;
  504.  
  505.         virtual float           GetRadiusVert() const final { return m_fRadiusVert; }
  506.         virtual float           GetRadiusHors() const final { return m_fRadiusHors; }
  507.  
  508.         virtual int AddRef() final;
  509.         virtual int Release() final;
  510.         virtual int  GetRefCount() const final { return m_nUsers; }
  511.  
  512.         virtual bool IsDefaultObject() final   { return (m_bDefaultObject); }
  513.  
  514.         int          GetLoadedTrisCount()         { return m_nLoadedTrisCount; }
  515.         int          GetRenderTrisCount()         { return m_nRenderTrisCount; }
  516.  
  517.         // Load LODs
  518.         virtual void SetLodObject(int nLod, IStatObj * pLod) final;
  519.         bool LoadLowLODS_Prep(bool bUseStreaming, unsigned long nLoadingFlags);
  520.         CStatObj* LoadLowLODS_Load(int nLodLevel, bool bUseStreaming, unsigned long nLoadingFlags, const void* pData, int nDataLen);
  521.         void LoadLowLODS_Finalize(int nLoadedLods, CStatObj * loadedLods[MAX_STATOBJ_LODS_NUM]);
  522.         void LoadLowLODs(bool bUseStreaming, unsigned long nLoadingFlags);
  523.         // Free render resources for unused upper LODs.
  524.         void CleanUnusedLods();
  525.  
  526.         virtual void FreeIndexedMesh() final;
  527.         bool RenderDebugInfo(CRenderObject * pObj, const SRenderingPassInfo &passInfo);
  528.  
  529.         //! Release method.
  530.         virtual void GetMemoryUsage(class ICrySizer* pSizer) const final;
  531.  
  532.         void ShutDown();
  533.         void Init();
  534.  
  535.         //  void CheckLoaded();
  536.         virtual IStatObj* GetLodObject(int nLodLevel, bool bReturnNearest = false) final;
  537.         virtual IStatObj* GetLowestLod() final;
  538.  
  539.         virtual int FindNearesLoadedLOD(int nLodIn, bool bSearchUp = false) final;
  540.         virtual int FindHighestLOD(int nBias) final;
  541.  
  542.         // interface IStreamCallback -----------------------------------------------------
  543.  
  544.         virtual void StreamAsyncOnComplete(IReadStream * pStream, unsigned nError) final;
  545.         virtual void StreamOnComplete(IReadStream * pStream, unsigned nError) final;
  546.         void IncrementModificationId();
  547.         uint32 GetModificationId() { return m_nModificationId; }
  548.  
  549.         // -------------------------------------------------------------------------------
  550.  
  551.         virtual void StartStreaming(bool bFinishNow, IReadStream_AutoPtr * ppStream) final;
  552.         void UpdateStreamingPrioriryInternal(const Matrix34A &objMatrix, float fDistance, bool bFullUpdate);
  553.  
  554.         void MakeCompiledFileName(char* szCompiledFileName, int nMaxLen);
  555.  
  556.         virtual bool IsPhysicsExist() const final;
  557.         bool IsSphereOverlap(const Sphere &sSphere);
  558.         virtual void Invalidate(bool bPhysics = false, float tolerance = 0.05f) final;
  559.  
  560.         void AnalyzeFoliage(IRenderMesh * pRenderMesh, CContentCGF * pCGF);
  561.         void FreeFoliageData();
  562.         virtual void CopyFoliageData(IStatObj * pObjDst, bool bMove = false, IFoliage * pSrcFoliage = 0, int* pVtxMap = 0, primitives::box * pMoveBoxes = 0, int nMovedBoxes = -1) final;
  563.         virtual int PhysicalizeFoliage(IPhysicalEntity * pTrunk, const Matrix34 &mtxWorld, IFoliage * &pRes, float lifeTime = 0.0f, int iSource = 0) final;
  564.         int SerializeFoliage(TSerialize ser, IFoliage * pFoliage);
  565.  
  566.         virtual IStatObj* UpdateVertices(strided_pointer<Vec3> pVtx, strided_pointer<Vec3> pNormals, int iVtx0, int nVtx, int* pVtxMap = 0, float rscale = 1.f) final;
  567.         bool              HasSkinInfo(float skinRadius = -1.0f)                                                { return m_hasSkinInfo && m_pSkinInfo && (skinRadius < 0.0f || m_pSkinInfo[m_nLoadedVertexCount].w[0] == skinRadius); }
  568.         void PrepareSkinData(const Matrix34 &mtxSkelToMesh, IGeometry * pPhysSkel, float r = 0.0f);
  569.         virtual IStatObj* SkinVertices(strided_pointer<Vec3> pSkelVtx, const Matrix34& mtxSkelToMesh) final { return SkinVertices(pSkelVtx, mtxSkelToMesh, NULL);  }
  570.         IStatObj*         SkinVertices(strided_pointer<Vec3> pSkelVtx, const Matrix34& mtxSkelToMesh, volatile int* ready);
  571.  
  572.         //////////////////////////////////////////////////////////////////////////
  573.         // Sub objects.
  574.         //////////////////////////////////////////////////////////////////////////
  575.         virtual int                   GetSubObjectCount() const final { return m_subObjects.size(); }
  576.         virtual void SetSubObjectCount(int nCount) final;
  577.         virtual IStatObj::SSubObject* FindSubObject(const char* sNodeName) final;
  578.         virtual IStatObj::SSubObject* FindSubObject_StrStr(const char* sNodeName) final;
  579.         virtual IStatObj::SSubObject* FindSubObject_CGA(const char* sNodeName) final;
  580.         virtual IStatObj::SSubObject* GetSubObject(int nIndex) final
  581.         {
  582.                 if (nIndex >= 0 && nIndex < (int)m_subObjects.size())
  583.                         return &m_subObjects[nIndex];
  584.                 else
  585.                         return 0;
  586.         }
  587.         virtual bool RemoveSubObject(int nIndex) final;
  588.         virtual IStatObj* GetParentObject() const final      { return m_pParentObject; }
  589.         virtual IStatObj* GetCloneSourceObject() const final { return m_pClonedSourceObject; }
  590.         virtual bool      IsSubObject() const final          { return m_bSubObject; };
  591.         virtual bool CopySubObject(int nToIndex, IStatObj * pFromObj, int nFromIndex) final;
  592.         virtual int PhysicalizeSubobjects(IPhysicalEntity * pent, const Matrix34 * pMtx, float mass, float density = 0.0f, int id0 = 0,
  593.                                           strided_pointer<int> pJointsIdMap = 0, const char* szPropsOverride = 0) final;
  594.         virtual IStatObj::SSubObject& AddSubObject(IStatObj* pStatObj) final;
  595.         virtual int Physicalize(IPhysicalEntity * pent, pe_geomparams * pgp, int id = -1, const char* szPropsOverride = 0) final;
  596.         //////////////////////////////////////////////////////////////////////////
  597.  
  598.         virtual bool SaveToCGF(const char* sFilename, IChunkFile * *pOutChunkFile = NULL, bool bHavePhiscalProxy = false) final;
  599.  
  600.         //virtual IStatObj* Clone(bool bCloneChildren=true, bool nDynamic=false);
  601.         virtual IStatObj* Clone(bool bCloneGeometry, bool bCloneChildren, bool bMeshesOnly) final;
  602.  
  603.         virtual int SetDeformationMorphTarget(IStatObj * pDeformed) final;
  604.         virtual int SubobjHasDeformMorph(int iSubObj);
  605.         virtual IStatObj* DeformMorph(const Vec3& pt, float r, float strength, IRenderMesh* pWeights = 0) final;
  606.  
  607.         virtual IStatObj* HideFoliage() final;
  608.  
  609.         virtual int Serialize(TSerialize ser) final;
  610.  
  611.         // Get object properties as loaded from CGF.
  612.         virtual const char* GetProperties() final                  { return m_szProperties.c_str(); };
  613.         virtual void        SetProperties(const char* props) final { m_szProperties = props; ParseProperties(); }
  614.  
  615.         virtual bool GetPhysicalProperties(float& mass, float& density) final;
  616.  
  617.         virtual IStatObj* GetLastBooleanOp(float& scale) final { scale = m_lastBooleanOpScale; return m_pLastBooleanOp; }
  618.  
  619.         // Intersect ray with static object.
  620.         // Ray must be in object local space.
  621.         virtual bool RayIntersection(SRayHitInfo & hitInfo, IMaterial * pCustomMtl = 0) final;
  622.         virtual bool LineSegIntersection(const Lineseg &lineSeg, Vec3 & hitPos, int& surfaceTypeId) final;
  623.  
  624.         virtual void DebugDraw(const SGeometryDebugDrawInfo &info) final;
  625.         virtual void GetStatistics(SStatistics & stats) final;
  626.         //////////////////////////////////////////////////////////////////////////
  627.  
  628.         IParticleEffect* GetSurfaceBreakageEffect(const char* sType);
  629.  
  630.         virtual hidemask GetInitialHideMask() final { return m_nInitialSubObjHideMask; }
  631.  
  632.         virtual void     SetStreamingDependencyFilePath(const char* szFileName) final
  633.         {
  634.                 const bool streamingDependencyLoop = CheckForStreamingDependencyLoop(szFileName);
  635.                 if (streamingDependencyLoop)
  636.                 {
  637.                         CryWarning(VALIDATOR_MODULE_3DENGINE, VALIDATOR_WARNING, "StatObj '%s' cannot set '%s' as a streaming dependency as it would result in a looping dependency.", GetFilePath(), szFileName);
  638.                         return;
  639.                 }
  640.  
  641.                 m_szStreamingDependencyFilePath = szFileName;
  642.         }
  643.  
  644.         int GetMaxUsableLod();
  645.         int GetMinUsableLod();
  646.         void RenderStreamingDebugInfo(CRenderObject * pRenderObject);
  647.         void RenderCoverInfo(CRenderObject * pRenderObject);
  648.         int CountChildReferences();
  649.         void ReleaseStreamableContent() final;
  650.         int GetStreamableContentMemoryUsage(bool bJustForDebug = false) final;
  651.         virtual SMeshLodInfo ComputeGeometricMean() const final;
  652.         SMeshLodInfo ComputeAndStoreLodDistances();
  653.         virtual float GetLodDistance() const final     { return m_fLodDistance; }
  654.         virtual Vec3  GetDepthSortOffset() const final { return m_depthSortOffset; }
  655.         virtual int ComputeLodFromScale(float fScale, float fLodRatioNormalized, float fEntDistance, bool bFoliage, bool bForPrecache) final;
  656.         bool UpdateStreamableComponents(float fImportance, const Matrix34A &objMatrix, bool bFullUpdate, int nNewLod);
  657.         void GetStreamableName(string& sName) final
  658.         {
  659.                 sName = m_szFileName;
  660.                 if (m_szGeomName.length())
  661.                 {
  662.                         sName += " - ";
  663.                         sName += m_szGeomName;
  664.                 }
  665.         };
  666.         void GetStreamFilePath(stack_string & strOut);
  667.         void FillRenderObject(const SRendParams &rParams, IRenderNode * pRenderNode, IMaterial * pMaterial,
  668.                               SInstancingInfo * pInstInfo, CRenderObject * &pObj, const SRenderingPassInfo &passInfo);
  669.         virtual uint32 GetLastDrawMainFrameId() final { return m_nLastDrawMainFrameId; }
  670.  
  671.         // Allow pooled allocs
  672.         static void* operator new(size_t size);
  673.         static void  operator delete(void* pToFree);
  674.  
  675.         // Used in ObjMan.
  676.         void TryMergeSubObjects(bool bFromStreaming);
  677.         void SavePhysicalizeData(CNodeCGF * pNode);
  678.  
  679. protected:
  680.         // Called by async stream callback.
  681.         bool LoadStreamRenderMeshes(const char* filename, const void* pData, const int nDataSize, bool bLod);
  682.         // Called by sync stream complete callback.
  683.         void CommitStreamRenderMeshes();
  684.  
  685.         void MergeSubObjectsRenderMeshes(bool bFromStreaming, CStatObj * pLod0, int nLod);
  686.         void UnMergeSubObjectsRenderMeshes();
  687.         bool CanMergeSubObjects();
  688.         bool IsMatIDReferencedByObj(uint16 matID);
  689.  
  690.         //      bool LoadCGF_Info( const char *filename );
  691.         CStatObj* MakeStatObjFromCgfNode(CContentCGF* pCGF, CNodeCGF* pNode, bool bLod, int nLoadingFlags, AABB& commonBBox);
  692.         void ParseProperties();
  693.  
  694.         void CalcRadiuses();
  695.         void GetStatisticsNonRecursive(SStatistics & stats);
  696.  
  697.         void PhysicalizeCompiled(CNodeCGF * pNode, int bAppend = 0);
  698.         bool PhysicalizeGeomType(int nGeomType, CMesh & mesh, float tolerance = 0.05f, int bAppend = 0);
  699.         bool RegisterPhysicGeom(int nGeomType, phys_geometry * pPhysGeom);
  700.         void AssignPhysGeom(int nGeomType, phys_geometry * pPhysGeom, int bAppend = 0, int bLoading = 0);
  701.  
  702.         // Creates static object contents from mesh.
  703.         // Return true if successful.
  704.         _smart_ptr<IRenderMesh> MakeRenderMesh(CMesh * pMesh, bool bDoRenderMesh);
  705.         void MakeRenderMesh();
  706.  
  707.         const char* stristr(const char* szString, const char* szSubstring)
  708.         {
  709.                 int nSuperstringLength = (int)strlen(szString);
  710.                 int nSubstringLength = (int)strlen(szSubstring);
  711.  
  712.                 for (int nSubstringPos = 0; nSubstringPos <= nSuperstringLength - nSubstringLength; ++nSubstringPos)
  713.                 {
  714.                         if (strnicmp(szString + nSubstringPos, szSubstring, nSubstringLength) == 0)
  715.                                 return szString + nSubstringPos;
  716.                 }
  717.                 return NULL;
  718.         }
  719.  
  720.         bool CheckForStreamingDependencyLoop(const char* szFilenameDependancy) const;
  721. };
  722.  
  723. //////////////////////////////////////////////////////////////////////////
  724. inline void InitializeSubObject(IStatObj::SSubObject& so)
  725. {
  726.         so.localTM.SetIdentity();
  727.         so.name = "";
  728.         so.properties = "";
  729.         so.nType = STATIC_SUB_OBJECT_MESH;
  730.         so.pWeights = 0;
  731.         so.pFoliage = 0;
  732.         so.nParent = -1;
  733.         so.tm.SetIdentity();
  734.         so.bIdentityMatrix = true;
  735.         so.bHidden = false;
  736.         so.helperSize = Vec3(0, 0, 0);
  737.         so.pStatObj = 0;
  738.         so.bShadowProxy = 0;
  739. }
  740.  
  741. #endif // STAT_OBJ_H
  742.  
downloadStatObj.h Source code - Download CRYENGINE Source code
Related Source Codes/Software:
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top