My Project
ParaXModel.h
1 #pragma once
2 #include "IAttributeFields.h"
3 #include "modelheaders.h"
4 #include "animated.h"
5 #include "AnimInstanceBase.h"
6 #include "ParameterBlock.h"
7 #include "ParaXModelInstance.h"
8 #include "TextureAnim.h"
9 #include "ParaXModelCommon.h"
10 #include "ModelRenderPass.h"
11 
12 namespace ParaEngine
13 {
14  class Bone;
15  class ParticleSystem;
16  class RibbonEmitter;
17  class CParaXModel;
18  struct TextureEntity;
19  class CEffectFile;
20  struct CharacterPose;
21  class ShadowVolume;
22  struct LightParams;
23  class CFaceGroup;
24  struct ModelAttachment;
25 
26 
31  {
32  public:
33  CParaXModel(const ParaXHeaderDef& xheader);
34  virtual ~CParaXModel(void);
35 
39  SOFT_ANIM = 0,
46  };
47  public:
49  // implementation of IAttributeFields
50 
52  virtual int GetAttributeClassID(){return ATTRIBUTE_CLASSID_CParaXModel;}
54  virtual const char* GetAttributeClassName(){static const char name[] = "CParaXModel"; return name;}
56  virtual const char* GetAttributeClassDescription(){static const char desc[] = ""; return desc;}
58  virtual int InstallFields(CAttributeClass* pClass, bool bOverride);
59 
61  virtual int GetChildAttributeColumnCount();
63  virtual IAttributeFields* GetChildAttributeObject(const std::string& sName);
65  virtual int GetChildAttributeObjectCount(int nColumnIndex = 0);
66  virtual IAttributeFields* GetChildAttributeObject(int nRowIndex, int nColumnIndex = 0);
67 
68  ATTRIBUTE_METHOD1(CParaXModel, DumpTextureUsage_s, const char**) {*p1 = cls->DumpTextureUsage(); return S_OK;}
69  ATTRIBUTE_METHOD1(CParaXModel, GetPolyCount_s, int*) {*p1 = cls->GetPolyCount(); return S_OK;}
70  ATTRIBUTE_METHOD1(CParaXModel, GetPhysicsCount_s, int*) {*p1 = cls->GetPhysicsCount(); return S_OK;}
71  ATTRIBUTE_METHOD1(CParaXModel, GetGeosetsCount_s, int*) { *p1 = (int)cls->geosets.size(); return S_OK; }
72  ATTRIBUTE_METHOD1(CParaXModel, GetRenderPassesCount_s, int*) { *p1 = (int)cls->passes.size(); return S_OK; }
73  ATTRIBUTE_METHOD1(CParaXModel, GetObjectNum_s, void**) { *p1 = (void*)(&(cls->GetObjectNum())); return S_OK; }
74  ATTRIBUTE_METHOD1(CParaXModel, GetVertices_s, void**) { *p1 = (void*)(cls->m_origVertices); return S_OK; }
75  ATTRIBUTE_METHOD1(CParaXModel, GetRenderPasses_s, void**) { *p1 = (void*)(&(cls->passes[0])); return S_OK; }
76  ATTRIBUTE_METHOD1(CParaXModel, GetGeosets_s, void**) { *p1 = (void*)(&(cls->geosets[0])); return S_OK; }
77  ATTRIBUTE_METHOD1(CParaXModel, GetIndices_s, void**) { *p1 = (void*)(&(cls->m_indices[0])); return S_OK; }
78  ATTRIBUTE_METHOD1(CParaXModel, GetAnimations_s, void**) { *p1 = (void*)(cls->anims); return S_OK; }
79  ATTRIBUTE_METHOD1(CParaXModel, SaveToDisk_s, char*) { cls->SaveToDisk(p1); return S_OK; }
80  public:
82  int GetPolyCount();
84  int GetPhysicsCount();
86  const char* DumpTextureUsage();
87 
89  inline const ParaXModelObjNum& GetObjectNum() const {return m_objNum;};
90  inline const ParaXHeaderDef& GetHeader() const {return m_header;};
92  bool CheckMinVersion(int v0, int v1=0, int v2=0, int v3=0);
93 
95  void initVertices(int nVertices, ModelVertex* pVertices);
96  void initIndices(int nIndices, uint16* pIndices);
97 
98 
103 
105  ModelAttachment& NewAttachment(bool bOverwrite, int nAttachmentID, int nBoneIndex, const Vector3& pivotPoint);
106 
108  bool IsValid();
109 
111  bool InitDeviceObjects();
113  bool DeleteDeviceObjects();
114 
120  bool SetupTransformByID(int nID);
121 
122  void drawModel(SceneState * pSceneState, CParameterBlock* pMaterialParam = NULL, int nRenderMethod = -1);
123 
126  void animate(SceneState * pSceneState, CharacterPose* pPose, IAttributeFields* pAnimInstance = NULL);
127 
129  void draw(SceneState * pSceneState, CParameterBlock* materialParams = NULL, int nRenderMethod = -1);
130 
132  void BuildShadowVolume(ShadowVolume * pShadowVolume, LightParams* pLight, Matrix4* mxWorld);
133 
134  void updateEmitters(SceneState * pSceneState, float dt);
135  void drawBones();
136  void drawBoundingVolume();
137 
151  void calcBones(CharacterPose* pPose, const AnimIndex& CurrentAnim, const AnimIndex& BlendingAnim, float blendingFactor, IAttributeFields* pAnimInstance = NULL);
152 
154  void calcBones();
155 
156  void PostCalculateBoneMatrix(uint32 nBones);
157 
164  Matrix4* GetAttachmentMatrix(Matrix4* pOut, int nAttachmentID, const AnimIndex& CurrentAnim, const AnimIndex& BlendingAnim, float blendingFactor, bool bRecalcBone = true, IAttributeFields* pAnimInstance = NULL);
165 
169  bool HasAttachmentMatrix(int nAttachmentID);
170 
174  inline Vector3 GetWeightedVertexByIndex(unsigned short nIndex);
175  void lightsOn(uint32 lbase);
176  void lightsOff(uint32 lbase);
178  bool HasAnimation();
179 
181  bool IsBmaxModel();
182  void SetBmaxModel();
183 
185  void LoadTextures();
186 
194  AnimIndex GetAnimIndexByID(int nAnimID);
198  int GetAnimIDByIndex(int nAnimIndex);
199 
201  const ModelAnimation* GetModelAnimByIndex(int nAnimIndex);
202 
204  float GetBoundingRadius();
206  bool canAttach(int id);
207 
208  void RenderNoAnim(SceneState* pSceneState);
209  void RenderSoftAnim(SceneState* pSceneState,CParameterBlock* pMaterialParams=NULL);
210  void RenderSoftNoAnim(SceneState* pSceneState, CParameterBlock* pMaterialParams = NULL);
211  void RenderShaderAnim(SceneState* pSceneState);
212  void RenderBMaxModel(SceneState* pSceneState, CParameterBlock* pMaterialParams = NULL);
214  void DrawPass(ModelRenderPass &p);
215  void DrawPass_NoAnim(ModelRenderPass &p);
216  void DrawPass_NoAnim_VB(ModelRenderPass &p, size_t start);
217  void DrawPass_BMax_VB(ModelRenderPass &p, size_t start);
218  void DrawPass_BMax(ModelRenderPass &p);
220  void ClearFaceGroups();
221  bool HasAlphaBlendedObjects();
222 
224  int GetNextPhysicsGroupID(int nPhysicsGroup = -1);
225 
236  HRESULT ClonePhysicsMesh(DWORD* pNumVertices, Vector3 ** ppVerts, DWORD* pNumTriangles, DWORD** ppIndices, int* pnMeshPhysicsGroup = NULL, int* pnTotalMeshGroupCount = NULL);
237 
238  void SaveToDisk(const char* path);
239 
240  void SetRenderMethod(RENDER_METHOD method);
241 
242  void SetVertexBufferDirty();
243 
244  friend struct ModelRenderPass;
245 
246  private:
247  void InitVertexBuffer_NOANIM();
248  void InitVertexBuffer_BMAX();
249  void InitVertexBuffer();
250 
251  public:
257  float m_radius;
260 
261  RENDER_METHOD m_RenderMethod;
262 
264  const static int MAX_MODEL_TEXTURES = 32;
266  const static int MAX_MODEL_ATTACHMENTS = 40;
267 
270 
279 
280  size_t vbufsize;
281  bool animated : 1;
282  bool animGeometry : 1, animTextures : 1, animBones : 1, animTexRGB : 1;
283  bool rotatePartice2SpeedVector : 1;
284  bool forceAnim : 1;
285 
286  TextureAnim *texanims;
287  int *globalSequences;
288  ModelColor *colors;
289  ModelTransparency *transparency;
290  ModelLight *lights;
291  ParticleSystem *particleSystems;
292  RibbonEmitter *ribbons;
293 
294  ModelVertex *m_origVertices;
299  int m_nCurrentFrameNumber;
300  Vector3 * m_vertices, *m_normals;// the position and normals for the vertices
301  Vector2 *texcoords1;// the texture coordinates for the vertices
302  uint16 *m_indices;
303 
304  Vector3 *bounds;
305  uint16 *boundTris;
306 
307  ModelCamera cam;
308  Bone *bones;
309  asset_ptr<TextureEntity> *textures;
310 
311  std::vector<ModelRenderPass> passes;
313  std::vector<int> m_TranslucentPassIndice;
315  std::vector<CFaceGroup*> m_faceGroups;
316 
317  std::vector<ModelGeoset> geosets;
320  bool *showGeosets;
321 
322  int specialTextures[MAX_MODEL_TEXTURES];
323  TextureEntity* replaceTextures[MAX_MODEL_TEXTURES];
324  bool useReplaceTextures[MAX_MODEL_TEXTURES];
325 
330 
335 
340 
345 
348 
349  bool m_bIsValid;
350  bool hasCamera;
351  bool m_bTextureLoaded;
352 
353  float m_trans;
354  std::vector<ModelAttachment> m_atts;
355  int m_attLookup[MAX_MODEL_ATTACHMENTS];
356 
361 
363  int m_boneLookup[MAX_KNOWN_BONE_NODE];
364 
365  private:
366  enum VERTEX_BUFFER_STATE
367  {
368  NOT_SET = 0,
369  NEED_INIT = 1,
370  INITED = 2,
371  NOT_USE = 3,
372  };
373 
374  VERTEX_BUFFER_STATE m_vbState;
375 
376  static const size_t MAX_USE_VERTEX_BUFFER_SIZE = 1024 * 1024 * 256;
377  static size_t m_uUsedVB;
378  };
379 
382  {
383  float m_fUpperBodyFacingAngle;
384  float m_fUpperBodyUpDownAngle;
385  };
386 
387  typedef asset_ptr<CParaXModel> CParaXModelPtr;
388 }
int GetNextPhysicsGroupID(int nPhysicsGroup=-1)
return the physics group id that is closest to nPhysicsGroup.
Definition: ParaXModel.cpp:2156
Which DXT Compression to Use? Obviously, there are some trade-offs between the different formats whic...
Definition: TextureEntity.h:29
bool * showGeosets
a list of face group
Definition: ParaXModel.h:320
void calcBones()
for model without animations, but with bones.
Definition: ParaXModel.cpp:743
bool IsBmaxModel()
whether it is bmax model with vertex color.
Definition: ParaXModel.cpp:247
using software skinning
Definition: ParaXModel.h:39
HRESULT ClonePhysicsMesh(DWORD *pNumVertices, Vector3 **ppVerts, DWORD *pNumTriangles, DWORD **ppIndices, int *pnMeshPhysicsGroup=NULL, int *pnTotalMeshGroupCount=NULL)
Get the physics mesh in terms of vertices and indices.
Definition: ParaXModel.cpp:2172
an attribute class is a collection of attribute fields.
Definition: AttributeClass.h:10
int * m_frame_number_vertices
this always contains the same number of items as m_origVertices.
Definition: ParaXModel.h:298
ShadowVolume is a structure for storing shadow volume geometries.
Definition: ShadowVolume.h:39
It&#39;s used as parameter to Draw method of each scene object.
Definition: SceneState.h:284
const char * DumpTextureUsage()
get texture usage such as the number of textures and their sizes.
Definition: ParaXModel.cpp:2069
AnimIndex m_NextAnim
the next animation index.if it is -1, the next animation will depends on the loop property of the cur...
Definition: ParaXModel.h:334
float GetBoundingRadius()
get the mesh radius
Definition: ParaXModel.cpp:2033
void animate(SceneState *pSceneState, CharacterPose *pPose, IAttributeFields *pAnimInstance=NULL)
animate the entire model according to the current animation and blending settings.
Definition: ParaXModel.cpp:852
this is another kind of particle system.
Definition: particle.h:253
virtual IAttributeFields * GetChildAttributeObject(const std::string &sName)
get attribute by child object.
Definition: ParaXModel.cpp:2146
different physics engine has different winding order.
Definition: EventBinding.h:32
const ParaXModelObjNum & GetObjectNum() const
get the number of objects in the model.
Definition: ParaXModel.h:89
bool canAttach(int id)
whether the model has a specified attachment point
Definition: ParaXModel.cpp:2047
int m_boneLookup[MAX_KNOWN_BONE_NODE]
a mapping from known bone id to bone index.
Definition: ParaXModel.h:363
bool InitDeviceObjects()
TODO: currently this is not implemented.
Definition: ParaXModel.cpp:207
render without animation.
Definition: ParaXModel.h:43
float m_radius
bounding radius
Definition: ParaXModel.h:257
AnimIndex m_BlendingAnim
the animation sequence with which the current animation should be blended.
Definition: ParaXModel.h:339
using hardware skinning, need vertex shader 1.1 or later
Definition: ParaXModel.h:41
a single animated bone, it contains both the bone instance data and all animation data of the bone...
Definition: ParaXBone.h:15
void LoadTextures()
load textures
Definition: ParaXModel.cpp:219
const ModelAnimation * GetModelAnimByIndex(int nAnimIndex)
return NULL if not exist
Definition: ParaXModel.cpp:295
ParaXModelObjNum m_objNum
object counts
Definition: ParaXModel.h:255
Definition: modelheaders.h:226
cross platform vertex/index buffer.
Definition: ParaVertexBuffer.h:18
static const int MAX_MODEL_TEXTURES
max number of textures per model
Definition: ParaXModel.h:264
Vector3 m_vNeckYawAxis
default to unitY
Definition: ParaXModel.h:358
Standard 3-dimensional vector.
Definition: ParaVector3.h:16
virtual const char * GetAttributeClassDescription()
a static string, describing the attribute class object
Definition: ParaXModel.h:56
int GetAnimIDByIndex(int nAnimIndex)
return the ID of the animation at the specified index.
Definition: ParaXModel.cpp:287
ParaVertexBuffer m_pVertexBuffer
vertex buffer for skinned vertex
Definition: ParaXModel.h:276
static VertexDeclarationPtr m_pVertexDeclaration
vertex declaration used in the vertex shader of the effect file
Definition: ParaXModel.h:274
Definition: ParaXModelCommon.h:13
LightParams is a structure for which a shadow volume is built.
Definition: ShadowVolume.h:8
void drawModel(SceneState *pSceneState, CParameterBlock *pMaterialParam=NULL, int nRenderMethod=-1)
Definition: ParaXModel.cpp:1706
Definition: ParaXModelCommon.h:57
Matrix4 * GetAttachmentMatrix(Matrix4 *pOut, int nAttachmentID, const AnimIndex &CurrentAnim, const AnimIndex &BlendingAnim, float blendingFactor, bool bRecalcBone=true, IAttributeFields *pAnimInstance=NULL)
calculate only specified bone in the attachment, all parent bones will also be calculated in order to...
Definition: ParaXModel.cpp:695
int GetPhysicsCount()
get physics polycount of this mesh object
Definition: ParaXModel.cpp:2064
static CEffectFile * m_pEffectFile
The effect file entity used to render the animated model.
Definition: ParaXModel.h:272
Standard 2-dimensional vector.
Definition: ParaVector2.h:16
ParaIndexBuffer m_pIndexBuffer
index buffer
Definition: ParaXModel.h:278
ParaX header definition: this header is shared by all ParaEngine model files.
Definition: modelheaders.h:31
float blendingFactor
by how much the blending frame should be blended with the current frame.
Definition: ParaXModel.h:344
int m_nHasAlphaBlendedRenderPass
-1 uninitialized.
Definition: ParaXModel.h:259
The particle class keeps a list of all of its instances.A particle system instance is always associat...
Definition: particle.h:99
AnimIndex GetAnimIndexByID(int nAnimID)
return the animation index by animation ID.
Definition: ParaXModel.cpp:274
bool DeleteDeviceObjects()
TODO: currently this is not implemented.
Definition: ParaXModel.cpp:214
Definition: TextureAnim.h:5
Class encapsulating a standard 4x4 homogeneous matrix.
Definition: ParaMatrix4.h:23
RENDER_METHOD
in what method to render the mesh
Definition: ParaXModel.h:37
std::vector< CFaceGroup * > m_faceGroups
translucent face groups.
Definition: ParaXModel.h:315
vertex element
Definition: VertexDeclarationOpenGL.h:21
in OpenGL, there is no different between vertex and index buffer.
Definition: ParaVertexBuffer.h:78
virtual int GetChildAttributeObjectCount(int nColumnIndex=0)
get the number of child objects (row count) in the given column.
Definition: ParaXModel.cpp:2115
Definition: effect_file.h:323
ModelAttachment & NewAttachment(bool bOverwrite, int nAttachmentID, int nBoneIndex, const Vector3 &pivotPoint)
create new attachment
Definition: ParaXModel.cpp:652
it presents a given in bone animation providers or parax local model bone animation pools ...
Definition: AnimInstanceBase.h:13
A common interface for all classes implementing IAttributeFields By implementing this class&#39;s virtual...
Definition: IAttributeFields.h:59
Definition: ParaXModelCommon.h:8
float fBlendingTime
blending time in seconds
Definition: ParaXModel.h:347
ParaXHeaderDef m_header
model header
Definition: ParaXModel.h:253
Definition: ParaXModelCommon.h:27
static const int MAX_MODEL_ATTACHMENTS
max number of attachment points per model
Definition: ParaXModel.h:266
BMAX model color model.
Definition: ParaXModel.h:45
void draw(SceneState *pSceneState, CParameterBlock *materialParams=NULL, int nRenderMethod=-1)
render the model, according to the current animation states.
Definition: ParaXModel.cpp:1973
the pose of the character.
Definition: ParaXModel.h:381
int GetPolyCount()
get polycount of this mesh object
Definition: ParaXModel.cpp:2052
bool CheckMinVersion(int v0, int v1=0, int v2=0, int v3=0)
check the minimum file version.
Definition: ParaXModel.cpp:202
bool SetupTransformByID(int nID)
set the transform matrix for the specified attachment ID on this model.
Definition: ParaXModel.cpp:682
Definition: ParaXModelCommon.h:40
void BuildShadowVolume(ShadowVolume *pShadowVolume, LightParams *pLight, Matrix4 *mxWorld)
Build Shadow Volume.
Definition: ParaXModel.cpp:1782
Vector3 GetWeightedVertexByIndex(unsigned short nIndex)
Definition: ParaXModel.cpp:1962
virtual int GetChildAttributeColumnCount()
we support multi-dimensional child object.
Definition: ParaXModel.cpp:2151
virtual const char * GetAttributeClassName()
a static string, describing the attribute class object&#39;s name
Definition: ParaXModel.h:54
void initTranslucentFaceGroups()
call this function only once after the model data is loaded.
Definition: ParaXModel.cpp:575
Definition: ParaXModelCommon.h:50
bool HasAttachmentMatrix(int nAttachmentID)
whether we have attachment matrix.
Definition: ParaXModel.cpp:730
bool IsValid()
whether this is a valid model
Definition: ParaXModel.cpp:269
std::vector< int > m_TranslucentPassIndice
it has the same number of element as the passes.
Definition: ParaXModel.h:313
AnimIndex m_CurrentAnim
current animation index, this is different from sequence ID an absolute ParaX frame number denoting t...
Definition: ParaXModel.h:329
void initVertices(int nVertices, ModelVertex *pVertices)
file loading for ParaX file type
Definition: ParaXModel.cpp:471
ModelAnimation * anims
animation info for the current model
Definition: ParaXModel.h:269
ParaX model is the model file for character animation, etc in the game world.
Definition: ParaXModel.h:30
Definition: ModelRenderPass.h:9
virtual int InstallFields(CAttributeClass *pClass, bool bOverride)
this class should be implemented if one wants to add new attribute.
Definition: ParaXModel.cpp:2339
Vector3 m_vNeckPitchAxis
default to unitZ
Definition: ParaXModel.h:360
virtual int GetAttributeClassID()
attribute class ID should be identical, unless one knows how overriding rules work.
Definition: ParaXModel.h:52
void ClearFaceGroups()
clear all face groups.
Definition: ParaXModel.cpp:258
Definition: modelheaders.h:165
void DrawPass(ModelRenderPass &p)
only called inside Render* function
Definition: ParaXModel.cpp:1596
bool HasAnimation()
return true if the model has animation.
Definition: ParaXModel.cpp:847
a list of CParameter{name, value} pairs of anything.
Definition: ParameterBlock.h:108