My Project
CustomCharModelInstance.h
1 #pragma once
2 #include "IAttributeFields.h"
3 #include "CustomCharCommon.h"
4 #include "CustomCharFace.h"
5 
6 namespace ParaEngine
7 {
8  class CartoonFace;
9  class ParaXModelCanvas;
10  class CParaXModel;
11  struct LightParams;
12  struct AnimIndex;
13 
18  {
19  public:
21  virtual ~CharModelInstance();
22 
23  ATTRIBUTE_DEFINE_CLASS(CharModelInstance);
24 
26  virtual int InstallFields(CAttributeClass* pClass, bool bOverride);
27 
29  virtual IAttributeFields* GetChildAttributeObject(const std::string& sName);
31  virtual int GetChildAttributeObjectCount(int nColumnIndex = 0);
33  virtual int GetChildAttributeColumnCount();
34  virtual IAttributeFields* GetChildAttributeObject(int nRowIndex, int nColumnIndex = 0);
35 
36  public:
38  static std::list <CharModelInstance*> g_listPendingCartoonFaces;
39 
41  static std::list <CharModelInstance*> g_listPendingBodyTextures;
42 
47  static void ProcessPendingTextures(int nMaxNumber = 20);
48 
50  static void AddPendingCartoonFace(CharModelInstance* pendingInstance);
51  static bool HasPendingCartoonFace(CharModelInstance* pendingInstance);
52  static bool RemovePendingCartoonFace(CharModelInstance* pendingInstance);
53 
55  static void AddPendingBodyTexture(CharModelInstance* pendingInstance);
56  static bool HasPendingBodyTexture(CharModelInstance* pendingInstance);
57  static bool RemovePendingBodyTexture(CharModelInstance* pendingInstance);
58 
59 
67  void SetUpperBodyTurningAngle(float fAngle);
70 
71  void SetUpperBodyUpdownAngle(float fAngle);
74 
80  void SetSkin(int nIndex = 0);
81 
83  int GetSkin();
84 
85 
90  void SetSkinColorMask(DWORD dwColor);
91 
96  DWORD GetSkinColorMask();
97 
101  bool IsCustomModel();
102 
107  void SetCharacterSlot(int nSlotID, int nItemID);
108 
110  int GetCharacterSlot(int nSlotID);
111 
120  void SetBodyParams(int skinColor, int faceType, int hairColor, int hairStyle, int facialHair);
121 
122  int GetBodyParams(int type);
123 
126  void SetDisplayOptions(int bShowUnderwear, int bShowEars, int bShowHair);
127 
131  bool GetDisplayOptions(int type);
132 
138  bool MapItemTypeToSlot(int nItemType, int& nSlotIndex);
139 
141  bool CanItemInSlot(int nItemType, int nSlotIndex);
142 
144  void SetModifiedModel();
146  void SetModifiedEquipment();
148  void SetModified();
149 
152  void UpdateBaseModelByEquipment(int slot, int itemnum, int layer, CharTexture &tex);
153 
155  void RefreshItem(int slot);
156 
157 
163  bool AnimateModel(SceneState * sceneState, const AnimIndex& CurrentFrame, const AnimIndex& NextAnim, const AnimIndex& BlendingAnim, float blendingFactor, IAttributeFields* pAnimInstance = NULL);
164 
168  void Draw(SceneState * sceneState, CParameterBlock* materialParams = NULL);
169 
171  void BuildShadowVolume(SceneState * sceneState, ShadowVolume * pShadowVolume, LightParams* pLight, Matrix4* mxWorld);
172 
174  void AdvanceTime(float fDeltaTime);
175 
177  bool InitBaseModel(ParaXEntity * pModel);
178 
183 
184  void reset();
185 
199  void CastEffect(int nEffectID, int nAttachmentID = ATT_ID_HAND_LEFT, int nSlotID = -1);
212  void AddAttachment(ParaXEntity* pModelEntity, int nAttachmentID = ATT_ID_HAND_LEFT, int nSlotID = -1, float fScaling = 1.0, TextureEntity* pReplaceableTexture = NULL);
213  void AddAttachment(MeshEntity* pModelEntity, int nAttachmentID = ATT_ID_HAND_LEFT, int nSlotID = -1, float fScaling = 1.0, TextureEntity* pReplaceableTexture = NULL);
214 
216  IAttributeFields * GetAttachmentAttObj(int nAttachmentID);
217 
226  TextureEntity* GetReplaceableTexture(int ReplaceableTextureID);
227 
237  bool SetReplaceableTexture(int ReplaceableTextureID, TextureEntity* pTextureEntity);
238 
242  CartoonFace* GetCartoonFace(bool bCreateIfNotExist = true);
243 
245  bool IsSupportCartoonFace();
246 
247  public:
248  static bool IsStaticMeshAsset(const std::string& filename);
249 
250  private:
254  std::string makeSkinTexture(const char *texfn, const char *skin);
255 
271  std::string makeItemTexture(int region, const char *name);
272 
276  std::string makeItemModel(int region, const char *name);
277 
278  bool slotHasModel(int i);
279  void adjustHairVisibility();
280 
282  //static DatabaseEntity* m_pDbCharacters;
283 
285  void RefreshModel_imp();
286 
288  void RefreshEquipment_imp();
289 
291  void UpdateGeosetsToModel(CParaXModel* pModel);
292  void UpdateTexturesToModel(CParaXModel* pModel);
293 
294  /* check whether the model has custom geometry sets */
295  bool HasCustomGeosets(CParaXModel* pModel);
296 
297  public:
298  static const size_t NumItems = 8;
299 
300  enum CharSections
301  {
302  SkinType = 0,
303  FaceType = 1,
304  FacialHairType = 2,
305  HairType = 3,
306  UnderwearType = 4
307  };
308 
310  enum {
311  CHAR_TEX = 0,
312  HAIR_TEX,
313  FUR_TEX,
314  CAPE_TEX,
315  WING_TEX,
316  CARTOON_FACE_TEX,
317  NUM_TEX
318  };
319  asset_ptr<TextureEntity> m_textures[NUM_TEX];
320 
321  enum CharGeosets {
322  CSET_HAIR = 0,
323  CSET_FACIAL_HAIR1 = 1,
324  CSET_FACIAL_HAIR2 = 2,
325  CSET_FACIAL_HAIR3 = 3,
326  CSET_GLOVES = 4,
327  CSET_BOOTS = 5,
328  CSET_EARS = 7,
329  CSET_ARM_SLEEVES = 8,
330  CSET_PANTS = 9,
331  CSET_WINGS = 10, // newly added 2007.7.7
332  CSET_TABARD = 12,
333  CSET_ROBE = 13,
334  CSET_SKIRT = 14,// newly added 2007.7.8
335  CSET_CAPE = 15,
336  // TOTAL
337  NUM_CHAR_GEOSETS = 16
338  };
339  int geosets[NUM_CHAR_GEOSETS];
340 
343 
344  /* model display information */
345  int nSetID;
346 
347  int skinColor; // for customizable character
348  int m_skinIndex; // for non-customizable character
349 
350  int faceType;
351  int hairColor;
352  int hairStyle;
353  int facialHair;
354 
355  //int maxHairStyle, maxHairColor, maxSkinColor, maxFaceType, maxFacialHair;
356 
357  int race, gender;
358 
365 
366  bool showUnderwear, showEars, showHair, showFacialHair:1;
367  bool hadRobe : 1;
368  bool showAriesPantByItem, showAriesHandByItem, showAriesFootByItem, showAriesGlassByItem:1;
369  bool autoHair : 1;
370 
371  int equipment[NUM_CHAR_SLOTS];
372 
378 
383 
384  // temp character skin texture name
385  std::string m_sSkinTextureName;
386 
387  // temp face texture name
388  std::string m_sFaceTextureName;
389 
391  //static void LoadCharacterDatabase();
393  //DatabaseEntity* GetCharDB();
394 
395  /* model pose information */
397  float m_fUpperBodyUpDownAngle;
398  private:
400  bool m_bNeedRefreshModel;
402  bool m_bNeedRefreshEquipment;
406  bool m_bNeedComposeBodyTexture;
407  };
408 }
Which DXT Compression to Use? Obviously, there are some trade-offs between the different formats whic...
Definition: TextureEntity.h:29
void CastEffect(int nEffectID, int nAttachmentID=ATT_ID_HAND_LEFT, int nSlotID=-1)
cast a magic effect by the effect ID.
Definition: CustomCharModelInstance.cpp:1546
static void ProcessPendingTextures(int nMaxNumber=20)
Compose pending cartoon faces in a batch.
Definition: CustomCharModelInstance.cpp:1641
an attribute class is a collection of attribute fields.
Definition: AttributeClass.h:10
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
void SetCharacterSlot(int nSlotID, int nItemID)
set the model or geoset ID of a specified character slot.
Definition: CustomCharModelInstance.cpp:1790
bool CanItemInSlot(int nItemType, int nSlotIndex)
whether an item can be inserted in to a certain slot
Definition: CustomCharModelInstance.cpp:1507
DWORD m_dwSkinColorMask
the color mask to be applied to cartoon face and ccs base layer.
Definition: CustomCharModelInstance.h:377
void SetSkinColorMask(DWORD dwColor)
the color mask to be applied to cartoon face and ccs base layer.
Definition: CustomCharModelInstance.cpp:1776
float GetCurrrentUpperBodyTurningAngle()
return the angle which will be used for rendering in the next frame.
Definition: CustomCharModelInstance.cpp:341
different physics engine has different winding order.
Definition: EventBinding.h:32
void AdvanceTime(float fDeltaTime)
advance by a delta time
Definition: CustomCharModelInstance.cpp:376
int GetCharacterSlot(int nSlotID)
return the item id at the given slot_id
Definition: CustomCharModelInstance.cpp:1815
character animation instance: it includes both the animation and model display information.
Definition: CustomCharModelInstance.h:17
int skinColor
-1 stands for non-standard set
Definition: CustomCharModelInstance.h:347
int GetSkin()
return the current skin.
Definition: CustomCharModelInstance.cpp:208
virtual IAttributeFields * GetChildAttributeObject(const std::string &sName)
get attribute by child object.
Definition: CustomCharModelInstance.cpp:1882
bool GetDisplayOptions(int type)
Get the display option parameters.
Definition: CustomCharModelInstance.cpp:96
bool IsSupportCartoonFace()
check whether the associated cartoon model supports cartoon face.
Definition: CustomCharModelInstance.cpp:1630
CartoonFace * m_cartoonFace
data structure for the cartoon face
Definition: CustomCharModelInstance.h:380
static void AddPendingCartoonFace(CharModelInstance *pendingInstance)
add an instance to the global list
Definition: CustomCharModelInstance.cpp:1740
void SetModifiedModel()
refresh model resource entities according to the display information
Definition: CustomCharModelInstance.cpp:571
CartoonFace * GetCartoonFace(bool bCreateIfNotExist=true)
get the cartoon face associated with this object.
Definition: CustomCharModelInstance.cpp:1615
bool MapItemTypeToSlot(int nItemType, int &nSlotIndex)
given an item type, return the slot index to which it should be attached.
LightParams is a structure for which a shadow volume is built.
Definition: ShadowVolume.h:8
void Draw(SceneState *sceneState, CParameterBlock *materialParams=NULL)
draw the model instance.
Definition: CustomCharModelInstance.cpp:538
data structure for a cartoon face
Definition: CustomCharFace.h:75
static std::list< CharModelInstance * > g_listPendingCartoonFaces
the cartoon faces that needs to recomposed as soon as possible.
Definition: CustomCharModelInstance.h:38
virtual int GetChildAttributeObjectCount(int nColumnIndex=0)
get the number of child objects (row count) in the given column.
Definition: CustomCharModelInstance.cpp:1894
CharModelInstance()
Definition: CustomCharModelInstance.cpp:31
TextureEntity * GetReplaceableTexture(int ReplaceableTextureID)
get the current replaceable texture by its ID.
Definition: CustomCharModelInstance.cpp:1230
CharTexture * m_bodyTexture
data structure for the body textures
Definition: CustomCharModelInstance.h:382
ref_ptr< ParaXModelCanvas > m_pModelCanvas
a base model and its attachments.
Definition: CustomCharModelInstance.h:342
The ref_ptr class template stores a pointer to a dynamically allocated (AssetEntity|CRefCounted|BaseA...
Definition: PERefPtr.h:13
Class encapsulating a standard 4x4 homogeneous matrix.
Definition: ParaMatrix4.h:23
Definition: ParaXEntity.h:9
bool InitBaseModel(ParaXEntity *pModel)
init base model.
Definition: CustomCharModelInstance.cpp:139
bool AnimateModel(SceneState *sceneState, const AnimIndex &CurrentFrame, const AnimIndex &NextAnim, const AnimIndex &BlendingAnim, float blendingFactor, IAttributeFields *pAnimInstance=NULL)
Animate ParaX model, so that it is ready to be drawn.
Definition: CustomCharModelInstance.cpp:482
void SetUpperBodyTurningAngle(float fAngle)
the model will be rendered with the character&#39;s upper body turning m_fUpperBodyFacing rads this is do...
Definition: CustomCharModelInstance.cpp:345
void UpdateBaseModelByEquipment(int slot, int itemnum, int layer, CharTexture &tex)
update the base model according to a given equipment.
Definition: CustomCharModelInstance.cpp:749
it presents a given in bone animation providers or parax local model bone animation pools ...
Definition: AnimInstanceBase.h:13
bool m_bIsCustomModel
whether this is a customizable model.
Definition: CustomCharModelInstance.h:362
A common interface for all classes implementing IAttributeFields By implementing this class&#39;s virtual...
Definition: IAttributeFields.h:59
void SetModifiedEquipment()
refresh all attached items (equipment)
Definition: CustomCharModelInstance.cpp:972
void BuildShadowVolume(SceneState *sceneState, ShadowVolume *pShadowVolume, LightParams *pLight, Matrix4 *mxWorld)
build the shadow volume, call AnimateModel() before calling this function.
Definition: CustomCharModelInstance.cpp:532
void SetModified()
set both model and equipment modified.
Definition: CustomCharModelInstance.cpp:80
virtual int InstallFields(CAttributeClass *pClass, bool bOverride)
this class should be implemented if one wants to add new attribute.
Definition: CustomCharModelInstance.cpp:1906
void RefreshItem(int slot)
refresh an item on the canvas
Definition: CustomCharModelInstance.cpp:977
MeshEntity distinguish one template from other.
Definition: MeshEntity.h:38
void SetSkin(int nIndex=0)
set the replaceable skin according to the skin database.
Definition: CustomCharModelInstance.cpp:213
DWORD GetSkinColorMask()
the color mask to be applied to cartoon face and ccs base layer.
Definition: CustomCharModelInstance.cpp:1771
bool m_bHasCustomGeosets
whether the model has geosets that can be toggled.
Definition: CustomCharModelInstance.h:364
void SetBodyParams(int skinColor, int faceType, int hairColor, int hairStyle, int facialHair)
Set the character body parameters.
Definition: CustomCharModelInstance.cpp:1828
static void AddPendingBodyTexture(CharModelInstance *pendingInstance)
add an instance to the global list
Definition: CustomCharModelInstance.cpp:1677
virtual int GetChildAttributeColumnCount()
we support multi-dimensional child object.
Definition: CustomCharModelInstance.cpp:1901
void SetDisplayOptions(int bShowUnderwear, int bShowEars, int bShowHair)
Set the display options for the character.
Definition: CustomCharModelInstance.cpp:86
bool SetReplaceableTexture(int ReplaceableTextureID, TextureEntity *pTextureEntity)
set the replaceable texture at the given index with a new texture.
Definition: CustomCharModelInstance.cpp:1276
ParaXEntity * GetBaseModel()
get the base model for the current character.
Definition: CustomCharModelInstance.cpp:123
float GetCurrrentUpperBodyUpdownAngle()
return the angle which will be used for rendering in the next frame.
Definition: CustomCharModelInstance.cpp:371
ParaX model is the model file for character animation, etc in the game world.
Definition: ParaXModel.h:30
IAttributeFields * GetAttachmentAttObj(int nAttachmentID)
get attribute fields of the given attachment ID
Definition: CustomCharModelInstance.cpp:1584
static bool IsStaticMeshAsset(const std::string &filename)
return true if filename ends with *.anim.x
Definition: CustomCharModelInstance.cpp:116
void AddAttachment(ParaXEntity *pModelEntity, int nAttachmentID=ATT_ID_HAND_LEFT, int nSlotID=-1, float fScaling=1.0, TextureEntity *pReplaceableTexture=NULL)
Definition: CustomCharModelInstance.cpp:1565
bool IsCustomModel()
check whether this character is customizable.
Definition: CustomCharModelInstance.cpp:1823
ParaXEntity * GetAnimModel()
get the Anim model for the current character.
Definition: CustomCharModelInstance.cpp:131
static std::list< CharModelInstance * > g_listPendingBodyTextures
the body textures that needs to recomposed as soon as possible.
Definition: CustomCharModelInstance.h:41
a list of CParameter{name, value} pairs of anything.
Definition: ParameterBlock.h:108
Definition: CustomCharCommon.h:269
float m_fUpperBodyTurningAngle
load the global characters.db database if it has not been loaded.
Definition: CustomCharModelInstance.h:396