My Project
MeshEntity.h
1 #pragma once
2 #include "AssetEntity.h"
3 #include "ParaXModel/ParaXModel.h"
4 #include "ParaXModel/ParaXStaticModel.h"
5 
6 namespace ParaEngine
7 {
9  struct MeshLOD
10  {
11  public:
12  MeshLOD() :m_fromDepthSquared(0.f){}
13 
16 
18  std::string m_sMeshFileName;
19 
22  CParaXModelPtr m_pParaXMesh;
23  };
24 
25  struct MeshLodSortLess :
26  public std::binary_function<const MeshLOD&, const MeshLOD&, bool>
27  {
28  bool operator() (const MeshLOD& mesh1, const MeshLOD& mesh2)
29  {
30  // sort ascending by depth
31  return mesh1.m_fromDepthSquared < mesh2.m_fromDepthSquared;
32  }
33  };
34 
35  //--------------------------------------------------------
37  //--------------------------------------------------------
38  struct MeshEntity : public AssetEntity
39  {
40  public:
41  friend class CMeshProcessor;
42  virtual AssetEntity::AssetType GetType(){return AssetEntity::mesh;};
43 
49  void Refresh(const char* sFilename=NULL,bool bLazyLoad = false);
50 
55  virtual bool IsLoaded();
56 
58  const string& GetFileName();
59 
60  void SetPrimaryTechniqueHandle(int nHandle);
61  int GetPrimaryTechniqueHandle();
65  virtual CParameterBlock* GetParamBlock(bool bCreateIfNotExist = false);
66 
80  void CreateMeshLODLevel(float fromDepth, const string& sFilename);
81 
89  void UpdateManualLodLevel(int index, const string& sFilename);
90 
93  int GetLodIndex(float depth) const;
94 
101  int GetLodIndexSquaredDepth(float squaredDepth) const;
102 
104  void RemoveLodLevels(void);
110  HRESULT CreateMeshFromFile_Serial(RenderDevicePtr pDev=NULL, const char* sFileName=NULL);
111 
118  HRESULT CreateMeshFromFile_Async(void* pContext, RenderDevicePtr pDev = NULL, const char* sFileName = NULL);
119 
120  public:
121  MeshEntity(const AssetKey& key)
122  :AssetEntity(key),m_nTechniqueHandle(-1), m_pParamBlock(NULL), m_vMin(0,0,0), m_vMax(0,0,0)
123  {
124  }
125 
126  virtual HRESULT InitDeviceObjects();
127  virtual HRESULT RestoreDeviceObjects();
128  virtual HRESULT InvalidateDeviceObjects();
129  virtual HRESULT DeleteDeviceObjects();
130  virtual void Cleanup();
131 
132  virtual IAttributeFields* GetAttributeObject();
133 
137  CParaXStaticBase* GetMesh(int nLODIndex = 0);
138  ref_ptr<CParaXStaticBase> CreateMesh(const char* sFilename);
139 
144  void Init(const char* sFilename=NULL);
145 
147  void SetAABB(const Vector3* vMin, const Vector3* vMax){ m_vMin = *vMin; m_vMax = *vMax; }
148 
149  const Vector3& GetAABBMin(){return m_vMin;}
150  const Vector3& GetAABBMax(){return m_vMax;}
151 
153  virtual bool GetBoundingBox(Vector3* pMin, Vector3* pMax);
154  public:
155  Vector3 m_vMin;
156  Vector3 m_vMax;
157 
158  private:
161  std::vector<MeshLOD> m_MeshLODs;
162 
164  int m_nTechniqueHandle;
165 
167  CParameterBlock* m_pParamBlock;
168  };
169 
171 }
std::string m_sMeshFileName
Only relevant if m_bIsLodManual is true, the name of the alternative mesh to use. ...
Definition: MeshEntity.h:18
CMeshProcessor implementation of IDataProcessor.
Definition: ContentLoaderMesh.h:51
AssetType
each asset type has a unique asset type number
Definition: AssetEntity.h:82
different physics engine has different winding order.
Definition: EventBinding.h:32
float m_fromDepthSquared
squared Z value from which this LOD will apply
Definition: MeshEntity.h:15
a very thin wrapper to DirectX device with a portable version of openGL implementation.
Definition: RenderDeviceDirectX.h:10
A way of recording the way each LODs is recorded a static Mesh or ParaXMesh object.
Definition: MeshEntity.h:9
Standard 3-dimensional vector.
Definition: ParaVector3.h:16
AssetManager manages a set of asset entities of a certain type.
Definition: AssetManager.h:13
The ref_ptr class template stores a pointer to a dynamically allocated (AssetEntity|CRefCounted|BaseA...
Definition: PERefPtr.h:13
void SetAABB(const Vector3 *vMin, const Vector3 *vMax)
set AABB
Definition: MeshEntity.h:147
A common interface for all classes implementing IAttributeFields By implementing this class&#39;s virtual...
Definition: IAttributeFields.h:59
MeshEntity distinguish one template from other.
Definition: MeshEntity.h:38
Definition: MeshEntity.h:25
std::string AssetKey
the unique key object for asset entity.
Definition: AssetEntity.h:13
Definition: ParaXStaticBase.h:32
ref_ptr< CParaXStaticBase > m_pStaticMesh
Hard link to mesh to avoid looking up each time.
Definition: MeshEntity.h:21
Base class for managed asset entity in ParaEngine.
Definition: AssetEntity.h:25
a list of CParameter{name, value} pairs of anything.
Definition: ParameterBlock.h:108