1
0
forked from metin2/client
client/src/EterGrnLib/ModelInstance.h

203 lines
6.3 KiB
C
Raw Permalink Normal View History

#pragma once
//#define CACHE_DEFORMED_VERTEX
#include "../eterlib/GrpImage.h"
#include "../eterlib/GrpCollisionObject.h"
#include "Model.h"
#include "Motion.h"
class CGrannyModelInstance : public CGraphicCollisionObject
{
public:
enum
{
ANIFPS_MIN = 30,
ANIFPS_MAX = 120,
};
public:
static void DestroySystem();
static CGrannyModelInstance* New();
static void Delete(CGrannyModelInstance* pkInst);
static CDynamicPool<CGrannyModelInstance> ms_kPool;
public:
struct FCreateDeviceObjects
{
void operator() (CGrannyModelInstance * pModelInstance)
{pModelInstance->CreateDeviceObjects();}
};
struct FDestroyDeviceObjects
{
void operator() (CGrannyModelInstance * pModelInstance)
{pModelInstance->DestroyDeviceObjects();}
};
public:
CGrannyModelInstance();
virtual ~CGrannyModelInstance();
bool IsEmpty();
void Clear();
bool CreateDeviceObjects();
void DestroyDeviceObjects();
// Update & Render
void Update(DWORD dwAniFPS);
void UpdateLocalTime(float fElapsedTime);
void UpdateTransform(D3DXMATRIX * pMatrix, float fSecondsElapsed);
void UpdateSkeleton(const D3DXMATRIX * c_pWorldMatrix, float fLocalTime);
void DeformNoSkin(const D3DXMATRIX * c_pWorldMatrix);
void Deform(const D3DXMATRIX * c_pWorldMatrix);
// FIXME : <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ϵ<EFBFBD><CFB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>Ѱ<EFBFBD><D1B0><EFBFBD> 2<><32><EFBFBD><EFBFBD> <20>ؽ<EFBFBD><D8BD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>Ǿ<EFBFBD><C7BE>ִ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>̱⿡ <20>̷<EFBFBD>
// <20>Ҿ<EFBFBD><D2BE><EFBFBD><EFBFBD><EFBFBD> <20><>Ű<EFBFBD><C5B0><EFBFBD><20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20>ñ<EFBFBD><C3B1><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> (<28><><EFBFBD><EFBFBD> <20>ؽ<EFBFBD><D8BD><EFBFBD> <20><><EFBFBD><EFBFBD>) + (ȿ<><C8BF><EFBFBD><EFBFBD> <20>ؽ<EFBFBD><D8BD><EFBFBD>)
// <20>̷<EFBFBD><CCB7><EFBFBD><EFBFBD><EFBFBD> <20>ڵ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>̷<EFBFBD><CCB7><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20>ʳ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>մϴ<D5B4>. - [levites]
// NOTE : <20><><EFBFBD>ο<EFBFBD> if<69><66><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><>Ű<EFBFBD><C5B0> <20><><EFBFBD>ٴ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>ŷ<EFBFBD><C5B7><EFBFBD><EFBFBD><EFBFBD> <20>̷<EFBFBD><CCB7><EFBFBD> <20>Լ<EFBFBD> <20><> <20><>ü<EFBFBD><C3BC> <20>и<EFBFBD>
// <20><>Ű<EFBFBD><C5B0> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>ս<EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><E9BFA1><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD>. - [levites]
// NOTE : <20>ǹ<EFBFBD><C7B9><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> OneTexture. ij<><C4B3><EFBFBD>ʹ<EFBFBD> <20><><EFBFBD><20><><EFBFBD><EFBFBD> TwoTexture.
void RenderWithOneTexture();
void RenderWithTwoTexture();
void BlendRenderWithOneTexture();
void BlendRenderWithTwoTexture();
void RenderWithoutTexture();
// Model
CGrannyModel* GetModel();
void SetMaterialImagePointer(const char* c_szImageName, CGraphicImage* pImage);
void SetMaterialData(const char* c_szImageName, const SMaterialData& c_rkMaterialData);
void SetSpecularInfo(const char* c_szMtrlName, BOOL bEnable, float fPower);
void SetMainModelPointer(CGrannyModel* pkModel, CGraphicVertexBuffer* pkSharedDefromableVertexBuffer);
void SetLinkedModelPointer(CGrannyModel* pkModel, CGraphicVertexBuffer* pkSharedDefromableVertexBuffer, CGrannyModelInstance** ppkSkeletonInst);
// Motion
void SetMotionPointer(const CGrannyMotion* pMotion, float blendTime=0.0f, int loopCount=0, float speedRatio=1.0f);
void ChangeMotionPointer(const CGrannyMotion* pMotion, int loopCount=0, float speedRatio=1.0f);
void SetMotionAtEnd();
bool IsMotionPlaying();
void CopyMotion(CGrannyModelInstance * pModelInstance, bool bIsFreeSourceControl=false);
// Time
void SetLocalTime(float fLocalTime);
int ResetLocalTime();
float GetLocalTime();
float GetNextTime();
// WORK
DWORD GetDeformableVertexCount();
DWORD GetVertexCount();
// END_OF_WORK
// Bone & Attaching
const float * GetBoneMatrixPointer(int iBone) const;
const float * GetCompositeBoneMatrixPointer(int iBone) const;
bool GetMeshMatrixPointer(int iMesh, const D3DXMATRIX ** c_ppMatrix) const;
bool GetBoneIndexByName(const char * c_szBoneName, int * pBoneIndex) const;
void SetParentModelInstance(const CGrannyModelInstance* c_pParentModelInstance, const char * c_szBoneName);
void SetParentModelInstance(const CGrannyModelInstance* c_pParentModelInstance, int iBone);
// Collision Detection
bool Intersect(const D3DXMATRIX * c_pMatrix, float * pu, float * pv, float * pt);
void MakeBoundBox(TBoundBox* pBoundBox, const float* mat, const float* OBBMin, const float* OBBMax, D3DXVECTOR3* vtMin, D3DXVECTOR3* vtMax);
void GetBoundBox(D3DXVECTOR3 * vtMin, D3DXVECTOR3* vtMax);
// Reload Texture
void ReloadTexture();
protected:
void __Initialize();
void __DestroyModelInstance();
void __DestroyMeshMatrices();
void __DestroyDynamicVertexBuffer();
void __CreateModelInstance();
void __CreateMeshMatrices();
void __CreateDynamicVertexBuffer();
// WORK
void __DestroyWorldPose();
void __CreateWorldPose(CGrannyModelInstance* pkSrcModelInst);
bool __CreateMeshBindingVector(CGrannyModelInstance* pkDstModelInst);
void __DestroyMeshBindingVector();
int* __GetMeshBoneIndices(unsigned int iMeshBinding) const;
bool __IsDeformableVertexBuffer();
void __SetSharedDeformableVertexBuffer(CGraphicVertexBuffer* pkSharedDeformableVertexBuffer);
2024-03-28 22:27:09 +02:00
IDirect3DVertexBuffer9* __GetDeformableD3DVertexBufferPtr();
CGraphicVertexBuffer& __GetDeformableVertexBufferRef();
granny_world_pose* __GetWorldPosePtr() const;
// END_OF_WORK
// Update & Render
void UpdateWorldPose();
void UpdateWorldMatrices(const D3DXMATRIX * c_pWorldMatrix);
void DeformPNTVertices(void * pvDest);
void RenderMeshNodeListWithOneTexture(CGrannyMesh::EType eMeshType, CGrannyMaterial::EType eMtrlType);
void RenderMeshNodeListWithTwoTexture(CGrannyMesh::EType eMeshType, CGrannyMaterial::EType eMtrlType);
void RenderMeshNodeListWithoutTexture(CGrannyMesh::EType eMeshType, CGrannyMaterial::EType eMtrlType);
protected:
// Static Data
CGrannyModel * m_pModel;
// Granny Data
granny_model_instance * m_pgrnModelInstance;
//granny_world_pose * m_pgrnWorldPose; // <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
granny_control * m_pgrnCtrl;
granny_animation * m_pgrnAni;
// Meshes' Transform Data
D3DXMATRIX * m_meshMatrices;
// Attaching Data
const CGrannyModelInstance * mc_pParentInstance;
int m_iParentBoneIndex;
// Game Data
float m_fLocalTime;
float m_fSecondsElapsed;
DWORD m_dwOldUpdateFrame;
CGrannyMaterialPalette m_kMtrlPal;
// WORK
granny_world_pose* m_pgrnWorldPoseReal; // <20><><EFBFBD><EFBFBD> <20>޸𸮴<DEB8> <20><><EFBFBD><20>Ҵ<EFBFBD>
std::vector<granny_mesh_binding*> m_vct_pgrnMeshBinding;
// Dynamic Vertex Buffer
CGraphicVertexBuffer* m_pkSharedDeformableVertexBuffer;
CGraphicVertexBuffer m_kLocalDeformableVertexBuffer;
bool m_isDeformableVertexBuffer;
// END_OF_WORK
// TEST
CGrannyModelInstance** m_ppkSkeletonInst;
// END_OF_TEST
#ifdef _TEST
D3DXMATRIX TEST_matWorld;
#endif
public:
bool HaveBlendThing() { return m_pModel->HaveBlendThing(); }
};