#include "stdafx.h" #include "KResource.h" #include "KResourceDX.h" #include "KResourceManager.h" #include "KRenderDefine.h" #include "KDeviceManager.h" //////////////////////////////////////////////////////////////////////////////////////////////////////////////// // KResource Implement /////////////////////////////////////////////////////////////////////////////////////////////////////////////// KResource::KResource() : m_nRef(0), m_dwLoadedTime(0), m_nTextureMode(0) { } KResource::~KResource() { //if( m_type == RESTYPE_TEXTURE ) //{ // _oprint( "TEXTURE : Delete\n" ); //} } int KResource::GetResourceType() const { return m_type; } int KResource::GetState() const { return m_state; } bool KResource::Discard() { bool bRet = m_nRef ? false : true; if( !( bRet && m_strName.empty()) ) // Fraun removal of outputs when name is fucking empty (few thousands of them, really) { _oprint("Warning! Resource Ref of [ %s ] is not Zero but %d when discarded\n", m_strName.c_str(), m_nRef); } delete this; return bRet; } int KResource::AddRef() { return InterlockedIncrement( (volatile LONG *)&m_nRef ); //m_nRef++; } int KResource::GetRefCount() const { return m_nRef; } void KResource::Release() { assert(m_nRef && "사용 하지 않은 리소스를 삭제 한다.!!!" ); InterlockedDecrement( (volatile LONG *)&m_nRef ); ////m_nRef--; assert(m_nRef >= 0); if ( m_nRef == 0 ) Recycle(); } void KResource::Recycle() // 재사용 { delete this; } void KResource::SetName(const char *name) { m_strName = name; } LPCSTR KResource::GetName() const { return m_strName.c_str(); } void KResource::SetVersion( DWORD dwVersion ) { m_dwVersion = dwVersion; } DWORD KResource::GetVersion() { return m_dwVersion; } //static KRESOURCEID g_texID = 0; //////////////////////////////////////////////////////////////////////// // K3DTexture::K3DTexture() { m_nQuality = 0; m_size.cx = m_size.cy = 0; m_type = RESTYPE_TEXTURE; m_format = K3DFMT_UNKNOWN; m_pSurface = NULL; m_nLevels = 1; m_bManagedByTexManager = false; m_flags = 0; m_ColorizedMode = 0; // SetID( g_texID++ ); // _oprint( "K3DTexture::K3DTexture:(%08X):(%08d)\n", this, GetID() ); } K3DTexture::~K3DTexture() { // _oprint( "K3DTexture::Destroy:(%08X):(%08d)\n", this, GetID() ); } bool K3DTexture::IsValid() const { return false; } void K3DTexture::Release() { assert( m_nRef && "0이 들어 온다." ); if ( m_nRef <= 1 ) { // IsValid Check 일부러 뺐음 (안그러면 RenderTarget 실패시 Memory Leak 가능성) //_oprint( "K3DTexture::Release:(%08X)\n", this ); if( m_bManagedByTexManager) KTextureManager::GetManager()->RemoveTexture( this ); K3DRenderDevice* pDev = KDeviceManager::GetDeviceManager()->GetRenderDevice(); if(pDev) pDev->RemoveTexture( this ); } KResource::Release(); } //////////////////////////////////////////////////////////////////////////////////////////////////////////////// // K3DResVertexAnimation Implement /////////////////////////////////////////////////////////////////////////////////////////////////////////////// K3DResVertexAnimation::Key::Key() { time = 0; } bool K3DResVertexAnimation::Key::operator<( const Key &target ) const { return time < target.time; } K3DResVertexAnimation::K3DResVertexAnimation() { m_bUseAnimation = false; m_bTransparent = false; m_type = RESTYPE_VERTEXANIMATION; } K3DResVertexAnimation::~K3DResVertexAnimation() { } const KInterval &K3DResVertexAnimation::GetInterval() { return m_keys.GetInterval(); } void K3DResVertexAnimation::SetKeyCount( int count ) { if ( count > 1 ) { m_bUseAnimation = true; m_keys.SetKeyCount( count ); } else m_bUseAnimation = false; } void K3DResVertexAnimation::SetKey( int index, Key *key, int count) { if ( m_bUseAnimation ) { m_keys.SetKey( index, key, count ); } else { m_akey = key[0]; } } int K3DResVertexAnimation::GetKeyCount() { return m_keys.GetKeyCount(); } K3DResVertexAnimation::Key& K3DResVertexAnimation::GetKey( int nIndex ) { return m_keys.GetKey( nIndex ); } void K3DResVertexAnimation::SetWholeKey( Key *key, int count ) { if ( count > 1 ) { m_bUseAnimation = true; m_keys.SetWholeKey( key, count ); } else { m_bUseAnimation = false; m_akey = key[0]; } } void K3DResVertexAnimation::GetData( int time, Key*& key1, Key*& key2 ) { if ( m_bUseAnimation == false ) { key1 = &m_akey; key2 = NULL; } else { m_keys.GetData( time, key1, key2 ); } } void K3DResVertexAnimation::SetIndexArray( K3DUnsignedShortRes * pUS ) { m_spUS = pUS; } void K3DResVertexAnimation::SetIndexBuffer( K3DIndexBuffer *pIB ) { m_spIB = pIB; } bool K3DResVertexAnimation::IsTransparent() { return m_bTransparent; } void K3DResVertexAnimation::SetMaterial( K3DMaterial *mat ) { if( mat ) memcpy( &m_Mtl, mat, sizeof(m_Mtl) ); } void K3DResVertexAnimation::SetBlendMode( int blendmode ) { m_nBlendMode = blendmode; if ( blendmode == K3DMaterial::MBM_ADDITIVE ) m_bTransparent = true; } void K3DResVertexAnimation::SetTexturePack( TEXPACK * pTexPack ) { if( pTexPack->spTexture == NULL) return; m_TexPack = *pTexPack; m_TexPack.nTextureMode = m_TexPack.spTexture->m_nTextureMode; K3DFORMAT fmt = m_TexPack.spTexture->GetFormat(); m_bTransparent = false; switch( fmt ) { case K3DFMT_A8R8G8B8: case K3DFMT_A4R4G4B4: case K3DFMT_A8R3G3B2: case K3DFMT_A2B10G10R10: case K3DFMT_DXT3: case K3DFMT_DXT5: m_bTransparent = true; break; default: if ( m_nBlendMode != K3DMaterial::MBM_DEFAULT ) m_bTransparent = true; break; } } K3DMaterial *K3DResVertexAnimation::GetMaterial() { return &m_Mtl; } int K3DResVertexAnimation::GetBlendMode() { return m_nBlendMode; } TEXPACK* K3DResVertexAnimation::GetTexturePack() { if(m_TexPack.spTexture != NULL) { K3DFORMAT fmt = m_TexPack.spTexture->GetFormat(); m_bTransparent = false; m_TexPack.nTextureMode = m_TexPack.spTexture->m_nTextureMode; switch( fmt ) { case K3DFMT_A8R8G8B8: case K3DFMT_A4R4G4B4: case K3DFMT_A8R3G3B2: case K3DFMT_A2B10G10R10: case K3DFMT_DXT3: case K3DFMT_DXT5: m_bTransparent = true; break; default: if ( m_nBlendMode != K3DMaterial::MBM_DEFAULT ) m_bTransparent = true; break; } } return &m_TexPack; } K3DUnsignedShortRes* K3DResVertexAnimation::GetIndexArray() { return m_spUS; } K3DIndexBuffer* K3DResVertexAnimation::GetIndexBuffer() { return m_spIB; } bool K3DResVertexAnimation::Reload() { return true; } //////////////////////////////////////////////////////////////////////////////////////////////////////////////// // K3DBoneResource ImplementK3DBoneResource K3DBone::K3DBone() { m_nParentIndex = -1; memset( m_BaseTM, 0, sizeof(m_BaseTM) ); m_dwFlag = 0; //Key flag m_dwPosCount = 0; m_pPosKey = NULL; m_dwRotCount = 0; m_pRotKey = NULL; m_dwChildCount = 0; m_pChildList = NULL; m_pChild = NULL; m_pParent = NULL; m_nIndex = -1; K3DMatrixIdentity( m_BaseMat ); K3DMatrixIdentity( m_CacheMat ); memset( m_szBoneName, 0, sizeof(m_szBoneName) ); //보간 관련 m_CacheAniData.pos = K3DVector(0,0,0); //보간 전달용 m_CacheAniData.quat = K3DQuaternion(0,0,0,1); //보간 전달용 } K3DBone::~K3DBone() { SAFE_DELETE_ARRAY( m_pPosKey ); SAFE_DELETE_ARRAY( m_pRotKey ); SAFE_DELETE_ARRAY( m_pChildList ); SAFE_DELETE_ARRAY( m_pChild ); } //Key로 변환 시키자~ Kgeneric_key_t * K3DBone::GetPosKey( DWORD mSec, K3DVector &pos ) { if( m_dwPosCount <= 0 ) return NULL; Kgeneric_key_t *key1 = NULL; Kgeneric_key_t *key2 = NULL; //와 보간두 되겠다~. m_PosKey.GetData( (int)mSec, key1, key2 ); if( key1 && key2 ) { K3DVector v1 = K3DVector(key1->lin_pos.pos); K3DVector v2 = K3DVector(key2->lin_pos.pos); float t = 0; if( key1->time != 0 ) t = (mSec % key1->time) / (float)(key2->time - key1->time); K3DVector dir = v2 - v1; dir = dir * t; pos = v1 + dir; return key1; } if( key1 ) { pos = K3DVector(key1->lin_pos.pos); return key1; } return NULL; } Kgeneric_key_t * K3DBone::GetRotKey( DWORD mSec, K3DQuaternion &quat ) { if( m_dwRotCount <= 0 ) return NULL; Kgeneric_key_t *key1 = NULL; Kgeneric_key_t *key2 = NULL; //와 보간두 되겠다~. m_RotKey.GetData( (int)mSec, key1, key2 ); if( key1 && key2 ) { K3DQuaternion q1 = K3DQuaternion(key1->lin_rot.quat); K3DQuaternion q2 = K3DQuaternion(key2->lin_rot.quat); float t = 0; if( key1->time != 0 ) t = (float)(mSec % key1->time) / (float)(key2->time - key1->time); K3DQuaternionSlerp(quat, q1, q2, t ); return key1; } if( key1 ) { quat = K3DQuaternion(key1->lin_rot.quat); return key1; } return NULL; } void K3DBone::Interpolate(DWORD mSec, K3DVector &pos, K3DQuaternion &quat) { // Linear interpolate position Kgeneric_key_t *posKeyStart = GetPosKey(mSec, pos); Kgeneric_key_t *rotKeyStart = GetRotKey(mSec, quat); } void K3DBone::CalcTM(DWORD mSec, DWORD mSecLimit, BONE_ANI_DATA *pAniData/*=NULL*/, float fWeight/*=0.f*/) { K3DVector pos = K3DVector(0,0,0); K3DQuaternion quat = K3DQuaternion(0,0,0,1); Interpolate( mSec, pos, quat ); if( pAniData ) { //Pos K3DVector dir = pos - pAniData[GetIndex()].pos; dir = dir * fWeight; pos = pAniData[GetIndex()].pos + dir; //Quaternion K3DQuaternionSlerp(quat, pAniData[GetIndex()].quat, quat, fWeight ); } m_CacheAniData.pos = pos; m_CacheAniData.quat = quat; K3DMatrixIdentity( m_CacheMat ); K3DMatrixRotationQuaternion( m_CacheMat, quat ); m_CacheMat._41 = pos.x; m_CacheMat._42 = pos.y; m_CacheMat._43 = pos.z; //if(mSec >= mSecLimit) //{ // GetPosKey(mSec, pos ); // GetRotKey(mSec, quat); //} //else // Interpolate( mSec, pos, quat ); //K3DQuaternion ang; //float scale, tw; //tw = (float)acos(quat.w) * 2.f; //scale = (float)sin(tw * 0.5); //ang.x = quat.x / scale; //ang.y = quat.y / scale; //ang.z = quat.z / scale; //ang.w = (tw * 180.f) / (float)K3D_PI; //D3DXMATRIX mat1, mat2, mOut; //D3DXMatrixIdentity( &mat1 ); //D3DXMatrixIdentity( &mat2 ); //D3DXMatrixIdentity( &mOut ); //////최적화 할 수 있게 바꿔야 할 부분.. //D3DXMatrixTranslation( &mat1, pos.x, pos.y, pos.z); //D3DXVECTOR3 vector = D3DXVECTOR3(ang.x, ang.y, ang.z ); //float angRadian = ang.w*K3D_PI/180; //anf[_W_]는 Degree 값. //D3DXMatrixRotationAxis( &mat2, &vector, angRadian ); //mOut = mat2; //mOut._41 = mat1._41; //mOut._42 = mat1._42; //mOut._43 = mat1._43; //mOut._44 = mat1._44; //m_cacheTM[0] = mOut._11; //m_cacheTM[1] = mOut._12; //m_cacheTM[2] = mOut._13; //m_cacheTM[3] = mOut._14; //m_cacheTM[4] = mOut._21; //m_cacheTM[5] = mOut._22; //m_cacheTM[6] = mOut._23; //m_cacheTM[7] = mOut._24; //m_cacheTM[8] = mOut._31; //m_cacheTM[9] = mOut._32; //m_cacheTM[10] = mOut._33; //m_cacheTM[11] = mOut._34; //m_cacheTM[12] = mOut._41; //m_cacheTM[13] = mOut._42; //m_cacheTM[14] = mOut._43; //m_cacheTM[15] = mOut._44; //캐쉬 Matrix 갱신 //m_CacheMat = K3DMatrix(m_cacheTM); for(int i = 0; i < GetChildCount(); i++) { // _oprint( "ChildName : %s\n", m_pChild[i]->GetName() ); m_pChild[i]->CalcTM(mSec, mSecLimit, pAniData, fWeight); } } K3DBoneResource::K3DBoneResource() { m_type = RESTYPE_BONE; m_nBoneCount = 0; m_pBoneList = NULL; m_pParent = NULL; m_nChildCount = 0; m_ppChild = NULL; m_dwTimeSpan = 0; m_pBoneBaseTM = NULL; } K3DBoneResource::~K3DBoneResource() { if( m_pBoneList ) { for( int i(0); m_nBoneCount>i; i++ ) { delete m_pBoneList[i]; } delete [] m_pBoneList; } if( m_ppChild ) delete [] m_ppChild; SAFE_DELETE_ARRAY(m_pBoneBaseTM ); } const KInterval & K3DBoneResource::GetInterval() { return m_Interval; } bool K3DBoneResource::Reload() { //작업중.. return true; } void K3DBoneResource::AddBone(int nIndex, K3DBone * pBone) { if( m_nBoneCount == 0 || m_nBoneCount <= nIndex ) return; //#ifndef _RELEASE // _oprint( "Bone Name[%d] : %s\n", nIndex, pBone->GetName() ); //#endif pBone->SetIndex(nIndex); m_pBoneList[nIndex] = pBone; std::string strPureBoneName; GetPureBoneName(strPureBoneName, pBone->GetName() ); pBone->SetName( strPureBoneName.c_str() ); } void K3DBoneResource::SetBone( int nBoneCount ) { assert( m_nBoneCount == 0 ); m_nBoneCount = nBoneCount; m_pBoneList = new K3DBone*[m_nBoneCount]; // m_pBoneBaseTM = new K3DMatrix[m_nBoneCount]; } void K3DBoneResource::SetChildCount( int nChildCount ) { m_nChildCount = nChildCount; if( m_nChildCount > 0 ) { m_ppChild = new K3DBone*[m_nChildCount]; int idx(0); for(int i(0); i < m_nBoneCount; i++) { K3DBone *pBone = m_pBoneList[i]; if(pBone->GetParentBone() == NULL) { m_ppChild[idx] = pBone; idx++; } } } } float K3DBoneResource::GetHeadZ() { int nIndex; K3DBone * pHead = GetBone( "Head", nIndex ); if(pHead) { return pHead->GetCacheTM()->_43; } return 0.f; } void K3DBoneResource::GetHandLeft( K3DVector & pos ) { int nIndex; K3DBone * pHandLeft = GetBone( "HandL", nIndex ); if(pHandLeft) { pos.x = pHandLeft->GetCacheTM()->_41; pos.y = pHandLeft->GetCacheTM()->_42; pos.z = pHandLeft->GetCacheTM()->_43; } } void K3DBoneResource::GetHandRight( K3DVector & pos ) { int nIndex; K3DBone * pHandRight = GetBone( "HandR", nIndex ); if(pHandRight) { pos.x = pHandRight->GetCacheTM()->_41; pos.y = pHandRight->GetCacheTM()->_42; pos.z = pHandRight->GetCacheTM()->_43; } } void K3DBoneResource::CalcBoneTransforms( DWORD dwTime, K3DMatrix *pMatList, BONE_ANI_DATA *pAniData, BONE_ANI_DATA *pPrevAniData/*=NULL*/, float fWeight/*=1.f*/ ) { // if( GetAsyncKeyState(VK_CONTROL) < 0 ) // _oprint( "CalcBoneTransforms : %d\n", dwTime ); for(int i(0); GetChildCount()>i; i++ ) { // _oprint( "ChildName : %s\n", m_ppChild[i]->GetName() ); m_ppChild[i]->CalcTM( dwTime, GetTimeSpan(), pPrevAniData, fWeight ); } //계산이 완료 되면, CacheTM을 얻어 온다. for(int i(0); GetBoneCount()>i; i++ ) { // _oprint( "BoneName : %s\n", GetBone(i)->GetName() ); pMatList[i] = *GetBone(i)->GetCacheTM(); pAniData[i] = *GetBone(i)->GetCacheAniData(); } } //////////////////////////////////////////////////////////////////////////////////////////////////////////////// // K3DMeshResource Implement /////////////////////////////////////////////////////////////////////////////////////////////////////////////// K3DMeshResource::K3DMeshResource() { m_spVBArray = NULL; m_nVBCount = 0; m_type = RESTYPE_MESH; m_nWeightCount = 0; m_ppWeight = NULL; m_nNodeCount = 0; m_pNodeTM = NULL; m_nMeshTMCount = 0; m_pMeshTM = NULL; m_pMeshTM_Array = NULL; } K3DMeshResource::~K3DMeshResource() { if ( m_spVBArray != NULL ) { delete[] m_spVBArray; } if ( m_ppWeight != NULL ) { for ( int i=0 ; i m_nWeightCount ) return NULL; return m_ppWeight[nIndex]; } K3DWeight** K3DMeshResource::GetWeightResList() { if( m_nWeightCount <= 0 ) return NULL; return m_ppWeight; } K3DMatrix * K3DMeshResource::GetNodeTM( int nIndex ) { if( m_nNodeCount <= 0 && nIndex > m_nNodeCount ) return NULL; return &m_pNodeTM[nIndex]; } void K3DMeshResource::SetNodeTM( K3DMatrix * pMatrix, int count ) { assert( m_pNodeTM == NULL ); if( count <= 0) return; m_nNodeCount = count; m_pNodeTM = new K3DMatrix[count]; for( int i(0); count>i; i++ ) { memcpy( &m_pNodeTM[i], &pMatrix[i], sizeof(m_pNodeTM[i]) ); } } void K3DMeshResource::SetMeshTM( K3DMeshTM * pMeshTM, int count ) { assert( m_pMeshTM == NULL ); if( count <= 0) return; m_nMeshTMCount = count; m_pMeshTM = new K3DMeshTM[count]; m_pMeshTM_Array = new K3DMatrix[count]; for( int i(0); count>i; i++ ) { memcpy( &m_pMeshTM[i], &pMeshTM[i], sizeof(m_pMeshTM[i]) ); memcpy( &m_pMeshTM_Array[i], &pMeshTM[i].mTM, sizeof(m_pMeshTM_Array[i]) ); } } void K3DMeshResource::SetWeightResource( K3DWeight **ppWeight, int count ) { assert( m_ppWeight == NULL ); if( count <= 0) return; if( ppWeight[0] == NULL ) return; m_nWeightCount = count; m_ppWeight = new K3DWeight*[count]; for( int i=0; iGetInterval() ); } } int K3DMeshResource::GetResCount() { return m_nVBCount; } K3DResVertexAnimation* K3DMeshResource::GetRes( int index ) { return m_spVBArray[index]; } K3DResVertexAnimationSPtr* K3DMeshResource::GetResList() { return m_spVBArray; } void K3DMeshResource::SetBound( const K3DBoundRotCube &cube, const K3DBoundSphere &sphere ) { m_boundCube = cube; m_boundSphere = sphere; } const K3DBoundRotCube &K3DMeshResource::GetBoundCube() { return m_boundCube; } const K3DBoundSphere &K3DMeshResource::GetBoundSphere() { return m_boundSphere; } bool K3DMeshResource::Reload() { return true; } //////////////////////////////////////////////////////////////////////////////////////////////////////////////// // K3DResMeshMatrixAnimation Implement /////////////////////////////////////////////////////////////////////////////////////////////////////////////// K3DResMeshMatrixAnimation::K3DResMeshMatrixAnimation() { m_type = RESTYPE_MESHMATRIX; } K3DResMeshMatrixAnimation::~K3DResMeshMatrixAnimation() { } bool K3DResMeshMatrixAnimation::Key::operator<( const Key &target ) const { return time < target.time; } const KInterval &K3DResMeshMatrixAnimation::GetInterval() { return m_keys.GetInterval(); } void K3DResMeshMatrixAnimation::SetKeyCount( int count ) { m_keys.SetKeyCount( count ); } void K3DResMeshMatrixAnimation::SetKey( int index, Key *key, int count) { m_keys.SetKey( index, key, count ); } void K3DResMeshMatrixAnimation::SetWholeKey( Key *key, int count ) { m_keys.SetWholeKey( key, count ); } void K3DResMeshMatrixAnimation::GetLerpMatrix(int time, K3DMatrix* pMat) { Key *key1 = NULL, *key2 = NULL; m_keys.GetData( time, key1, key2 ); if ( key2 != NULL ) { int ctime = time - key1->time; float ratio = (float)ctime / float(key2->time - key1->time); K3DMatrix resmat; K3DMatrixLerp( resmat, key1->mat, key2->mat, ratio ); *pMat = resmat; } else { *pMat = key1->mat; } } bool K3DResMeshMatrixAnimation::Reload() { return true; } //////////////////////////////////////////////////////////////////////////////////////////////////////////////// // K3DResMeshUVAnimation Implement /////////////////////////////////////////////////////////////////////////////////////////////////////////////// K3DResMeshUVAnimation::K3DResMeshUVAnimation() { m_type = RESTYPE_MESHUV; m_nMode = 0; } K3DResMeshUVAnimation::~K3DResMeshUVAnimation() { } bool K3DResMeshUVAnimation::Key::operator<( const Key &target ) const { return time < target.time; } const KInterval &K3DResMeshUVAnimation::GetInterval() { return m_keys.GetInterval(); } void K3DResMeshUVAnimation::SetKeyCount( int count ) { m_keys.SetKeyCount( count ); } void K3DResMeshUVAnimation::SetKey( int index, Key *key, int count) { m_keys.SetKey( index, key, count ); } void K3DResMeshUVAnimation::SetWholeKey( Key *key, int count ) { m_keys.SetWholeKey( key, count ); } void K3DResMeshUVAnimation::SetMode( int nMode ) { m_nMode = nMode; } int K3DResMeshUVAnimation::GetMode() { return m_nMode; } void K3DResMeshUVAnimation::SetUvAnimation( bool bUseUvAni, int nMaxFrame, int nLoopFrame ) { m_bUseUvAni = bUseUvAni; m_nUvMaxFrame = nMaxFrame; m_nUvLoopFrame = nLoopFrame; } void K3DResMeshUVAnimation::GetLerpMatrix(int time, K3DMatrix* pMat) { if( m_bUseUvAni ) { int nMaxFrame = m_nUvMaxFrame; assert( nMaxFrame ); float fUVRatio = 1.0f / sqrtf( ( float ) nMaxFrame ); int nLoopFrame = m_nUvLoopFrame; if( nLoopFrame == 0 ) nLoopFrame = m_keys.GetInterval().GetLength(); int nAniCount = int(( nMaxFrame / ( float ) nLoopFrame ) * time ); if ( nAniCount >= nMaxFrame ) nAniCount %= nMaxFrame; int width = ( int ) ( 1.0f / fUVRatio ); int txtpos = nAniCount % nMaxFrame; int px = txtpos % width; int py = txtpos / width; float l, t; l = fUVRatio * px; t = fUVRatio * py; K3DMatrixIdentity( *pMat ); pMat->_31 = l; pMat->_32 = t; pMat->_41 = 1.0f; } else { Key *key1 = NULL, *key2 = NULL; m_keys.GetData( time, key1, key2 ); if ( key2 != NULL ) { int ctime = time - key1->time; float ratio = (float)ctime / float(key2->time - key1->time); K3DMatrix resmat; K3DMatrixLerp( resmat, key1->mat, key2->mat, ratio ); *pMat = resmat; } else { *pMat = key1->mat; } } } bool K3DResMeshUVAnimation::Reload() { return true; } //////////////////////////////////////////////////////////////////////////////////////////////////////////////// // K3DResMeshVisibilityAnimation Implement /////////////////////////////////////////////////////////////////////////////////////////////////////////////// K3DResMeshVisibilityAnimation::K3DResMeshVisibilityAnimation() { m_type = RESTYPE_MESHVISIBILITY; } K3DResMeshVisibilityAnimation::~K3DResMeshVisibilityAnimation() { } bool K3DResMeshVisibilityAnimation::Key::operator<( const Key &target ) const { return time < target.time; } const KInterval& K3DResMeshVisibilityAnimation::GetInterval() { return m_keys.GetInterval(); } void K3DResMeshVisibilityAnimation::SetKeyCount( int count ) { m_keys.SetKeyCount( count ); } void K3DResMeshVisibilityAnimation::SetKey( int index, Key *key, int count) { m_keys.SetKey( index, key, count ); } void K3DResMeshVisibilityAnimation::SetWholeKey( Key *key, int count ) { m_keys.SetWholeKey( key, count ); } void K3DResMeshVisibilityAnimation::GetVisibility(int time, float* pVisi) { Key *key1 = NULL, *key2 = NULL; m_keys.GetData( time, key1, key2 ); if ( key2 != NULL ) { int ctime = time - key1->time; float ratio = (float)ctime / float(key2->time - key1->time); *pVisi = key1->val + ((key2->val - key1->val) * ratio); } else { *pVisi = key1->val; } } bool K3DResMeshVisibilityAnimation::Reload() { return true; } //////////////////////////////////////////////////////////////////////////////////////////////////////////////// // K3DResEventPoint Implement /////////////////////////////////////////////////////////////////////////////////////////////////////////////// K3DResEventPoint::K3DResEventPoint() { m_type = RESTYPE_EVENTPOINT; } K3DResEventPoint::~K3DResEventPoint() { } const KInterval& K3DResEventPoint::GetInterval() { return m_Interval; } void K3DResEventPoint::SetRes( K3DResMeshMatrixAnimation *matres ) { m_spResMat = matres; if(m_spResMat != NULL) { m_Interval = m_spResMat->GetInterval(); } } void K3DResEventPoint::GetData( int time, K3DMatrix *point ) { if(m_spResMat != NULL) { m_spResMat->GetLerpMatrix(time, point); } } bool K3DResEventPoint::Reload() { return true; } //////////////////////////////////////////////////////////////////////////////////////////////////////////////// // K3DResEventBox Implement /////////////////////////////////////////////////////////////////////////////////////////////////////////////// K3DResEventBox::K3DResEventBox() { m_type = RESTYPE_EVENTBOX; } K3DResEventBox::~K3DResEventBox() { } const KInterval&K3DResEventBox::GetInterval() { return m_Interval; } void K3DResEventBox::SetRes( const K3DBoundRotCube &cube, K3DResMeshMatrixAnimation *matres ) { m_Cube = cube; assert( m_spResMat == NULL); m_spResMat = matres; if(m_spResMat != NULL) { m_Interval = m_spResMat->GetInterval(); } } void K3DResEventBox::GetData( int time, K3DBoundRotCube *cube ) { if(m_spResMat != NULL) { static K3DMatrix resmat; m_spResMat->GetLerpMatrix(time, &resmat); m_Cube.SetTransform(resmat); } *cube = m_Cube; } bool K3DResEventBox::Reload() { return true; } //////////////////////////////////////////////////////////////////////////////////////////////////////////////// // K3DResCamera Implement /////////////////////////////////////////////////////////////////////////////////////////////////////////////// K3DResCamera::K3DResCamera() { m_type = RESTYPE_CAMERA; } K3DResCamera::~K3DResCamera() { } bool K3DResCamera::Key::operator<( const Key &target ) const { return time < target.time; } const KInterval& K3DResCamera::GetInterval() { return m_keys.GetInterval(); } void K3DResCamera::SetKeyCount( int count ) { m_keys.SetKeyCount( count ); } void K3DResCamera::SetKey( int index, Key *key, int count ) { m_keys.SetKey( index, key, count ); } void K3DResCamera::SetWholeKey( Key *key, int count ) { m_keys.SetWholeKey( key, count ); } void K3DResCamera::GetData( int time, Key*& key1, Key*& key2 ) { m_keys.GetData( time, key1, key2 ); } bool K3DResCamera::Reload() { return true; } //////////////////////////////////////////////////////////////////////////////////////////////////////////////// // K3DResLight Implement /////////////////////////////////////////////////////////////////////////////////////////////////////////////// K3DResLight::K3DResLight() { m_type = RESTYPE_LIGHT; } K3DResLight::~K3DResLight() { } bool K3DResLight::Key::operator<( const Key &target ) const { return time < target.time; } const KInterval& K3DResLight::GetInterval() { return m_keys.GetInterval(); } void K3DResLight::SetKeyCount( int count ) { m_keys.SetKeyCount( count ); } void K3DResLight::SetKey( int index, Key *key, int count) { m_keys.SetKey( index, key, count ); } void K3DResLight::SetWholeKey( Key *key, int count ) { m_keys.SetWholeKey( key, count ); } void K3DResLight::GetData( int time, Key*& key1, Key*& key2 ) { m_keys.GetData( time, key1, key2 ); } bool K3DResLight::Reload() { return true; } //////////////////////////////////////////////////////////////////////////////////////////////////////////////// // KResSprite Implement /////////////////////////////////////////////////////////////////////////////////////////////////////////////// KResSprite::KResSprite() { m_type = RESTYPE_SPRITE; m_ptOffset.x = m_ptOffset.y = 0; m_fSizeX = m_fSizeY = .0f; m_fTop = 0.f; m_fLeft = 0.f; m_fRight = 1.f; m_fBottom = 1.f; m_fVisibility = 1.0f; m_bMirrorH = m_bMirrorV = false; m_bUseAdditive = false; m_bCWRotation = m_bCCWRotation = false; K3DMatrixIdentity(m_matTransform); } KResSprite::~KResSprite() { //_LEAK_SUN m_sNote.clear(); m_vtBoundBox.clear(); } void KResSprite::SetTexture( K3DTexture *pTex, const KRect *srcrect ) { m_spTexture = pTex; if(m_spTexture == NULL) return; if ( srcrect ) { m_rectSrc = *srcrect; m_fSizeX = (float)m_rectSrc.right - m_rectSrc.left; m_fSizeY = (float)m_rectSrc.bottom - m_rectSrc.top; KSize texsize; texsize.width = m_spTexture->GetWidth(); texsize.height = m_spTexture->GetHeight(); m_fLeft = (float)m_rectSrc.left / texsize.width; m_fRight = (float)m_rectSrc.right / texsize.width; m_fTop = (float)m_rectSrc.top / texsize.height; m_fBottom = (float)m_rectSrc.bottom / texsize.height; } else { KSize texsize; texsize.width = m_spTexture->GetWidth(); texsize.height = m_spTexture->GetHeight(); m_fSizeX = static_cast(texsize.width); m_fSizeY = static_cast(texsize.height); m_rectSrc = KRect( 0, 0, texsize.width, texsize.height ); m_fLeft = m_fTop = .0f; m_fRight = m_fBottom = 1.0f; } } void KResSprite::AddNote( const char *note ) { m_sNote.push_back( note ); } int KResSprite::GetNoteCount() { return static_cast(m_sNote.size()); } LPCSTR KResSprite::GetNote( int index ) { return m_sNote[index].c_str(); } void KResSprite::SetMirror( bool h, bool v ) { m_bMirrorH = h; m_bMirrorV = v; } void KResSprite::SetCWRotation(bool r) { m_bCWRotation = r; } void KResSprite::SetCCWRotation(bool r) { m_bCCWRotation = r; } bool KResSprite::IsCWRotate() { return m_bCWRotation; } bool KResSprite::IsCCWRotate() { return m_bCCWRotation; } void KResSprite::SetAdditiveRenderMode( bool useAdditive ) { m_bUseAdditive = useAdditive; } bool KResSprite::IsAdditiveRenderMode() { return m_bUseAdditive; } bool KResSprite::IsMirrorHori() { return m_bMirrorH; } bool KResSprite::IsMirrorVert() { return m_bMirrorV; } void KResSprite::SetOffset( const K3DPoint &offset ) { m_ptOffset = offset; } void KResSprite::GetSourceUVRect( float &left, float &top, float &right, float &bottom ) { left = m_fLeft; top = m_fTop; right = m_fRight; bottom = m_fBottom; } float KResSprite::GetSizeX() { return m_fSizeX; } float KResSprite::GetSizeY() { return m_fSizeY; } void KResSprite::SetSize( float cx, float cy ) { m_fSizeX = cx; m_fSizeY = cy; } K3DTexture* KResSprite::GetTexture() { return m_spTexture; } const KRect& KResSprite::GetSourceRect() { return m_rectSrc; } const K3DPoint& KResSprite::GetOffset() { return m_ptOffset; } bool KResSprite::Reload() { return true; } void KResSprite::SetTransform( const K3DMatrix &mat ) { m_matTransform = mat; } const K3DMatrix& KResSprite::GetTransform() { return m_matTransform; } void KResSprite::SetVisibility( float vis ) { m_fVisibility = vis; } float KResSprite::GetVisibility() { return m_fVisibility; } int KResSprite::GetBoundBoxSize() { return static_cast(m_vtBoundBox.size()); } KResSprite::KSpriteBoundBox & KResSprite::GetBoundBox(int nIndex) { if(nIndex < 0 || nIndex >= (int)m_vtBoundBox.size() ) { { assert(false && "Error on Index"); } } return m_vtBoundBox.at(nIndex); } void KResSprite::PushBoundBox(KResSprite::KSpriteBoundBox & cBoundBox) { m_vtBoundBox.push_back(cBoundBox); } KResSprite::KSpriteBoundBox::KSpriteBoundBox() { } KResSprite::KSpriteBoundBox::KSpriteBoundBox(LPCSTR lpszName, KRect & rcArea) { m_sBoxName = lpszName; m_rcArea = rcArea; } KResSprite::KSpriteBoundBox::KSpriteBoundBox(const KSpriteBoundBox & rhs) { _Copy(rhs); } KResSprite::KSpriteBoundBox & KResSprite::KSpriteBoundBox::operator=(const KSpriteBoundBox & rhs) { _Copy(rhs); return *this; } bool KResSprite::KSpriteBoundBox::operator<(KSpriteBoundBox & rhs) const { return this->m_sBoxName < rhs.m_sBoxName; } KRect KResSprite::KSpriteBoundBox::GetRect() { return m_rcArea; } void KResSprite::KSpriteBoundBox::_Copy(const KSpriteBoundBox & rhs) { m_sBoxName = rhs.m_sBoxName; m_rcArea = rhs.m_rcArea; } //////////////////////////////////////////////////////////////////////////////////////////////////////////////// // KResSpriteAnimation Implement /////////////////////////////////////////////////////////////////////////////////////////////////////////////// KResSpriteAnimation::KResSpriteAnimation() { m_type = RESTYPE_SPRITEANIMATION; m_bIsLoad = false; m_bEncrypt = false; m_bUseColorKey = false; m_ColorKey = KColor( 0,0,0 ); } KResSpriteAnimation::~KResSpriteAnimation() { //_LEAK_SUN ClearFrame(); m_vtTrack.clear(); } KResSpriteAnimation::Key::Key() { time = 0; } bool KResSpriteAnimation::Key::operator<( const Key &target ) const { return time < target.time; } const KInterval& KResSpriteAnimation::GetInterval() { return m_keys.GetInterval(); } void KResSpriteAnimation::SetKeyCount( int count ) { m_keys.SetKeyCount( count ); } void KResSpriteAnimation::SetKey( int index, Key *key, int count) { m_keys.SetKey( index, key, count ); } void KResSpriteAnimation::SetWholeKey( Key *key, int count ) { m_keys.SetWholeKey( key, count ); } int KResSpriteAnimation::GetKeyCount() { return m_keys.GetKeyCount(); } void KResSpriteAnimation::GetData( int time, Key*& key1, Key*& key2 ) { m_keys.GetData( time, key1, key2 ); } bool KResSpriteAnimation::Reload() { return true; } int KResSpriteAnimation::GetIndexNumber(DWORD dwTime) { return m_keys.GetIndexNumber(dwTime); } void KResSpriteAnimation::AddTrack(const Track & trackData) { m_vtTrack.push_back(trackData); } DWORD KResSpriteAnimation::GetTrackSize() { return static_cast(m_vtTrack.size()); } KResSpriteAnimation::Track & KResSpriteAnimation::GetTrack(int nIndeX) { return m_vtTrack.at(nIndeX); } KResSprite * KResSpriteAnimation::GetSpriteByFrame(int nFrame) { if(nFrame < 0 || nFrame >= m_keys.GetKeyCount() ) return NULL; return m_keys.GetKey(nFrame).spSprite; } //////////////////////////////////////////////////////////////////////////////////////////////////////////////// // KResFXBillboard Implement /////////////////////////////////////////////////////////////////////////////////////////////////////////////// KResFXBillboard::KResFXBillboard() { m_type = RESTYPE_FXBILLBOARD; } KResFXBillboard::~KResFXBillboard() { } void KResFXBillboard::SetTexture( K3DTexture *pTex) { m_spTex = pTex; } void KResFXBillboard::SetVertices( K3DVertex *vtxs ) { memcpy( m_vtxBillBoard, vtxs, sizeof(m_vtxBillBoard) ); } const K3DVertex* KResFXBillboard::GetVertices() { return m_vtxBillBoard; } void KResFXBillboard::SetRes( K3DResMeshMatrixAnimation *pResMat, K3DResMeshVisibilityAnimation *pResVis) { assert(m_spResMat == NULL && m_spResVis == NULL); m_spResMat = pResMat; if(m_spResMat != NULL) { m_interval = m_spResMat->GetInterval(); } m_spResVis = pResVis; } const KInterval &KResFXBillboard::GetInterval() { return m_interval; } K3DTexture *KResFXBillboard::GetTexture() { return m_spTex; } void KResFXBillboard::GetData( int time, float *vis, K3DMatrix *mat ) { if(m_spResMat != NULL) { m_spResMat->GetLerpMatrix(time, mat); } if(m_spResVis != NULL) { m_spResVis->GetVisibility(time, vis); } else { *vis = 1.0f; } } bool KResFXBillboard::Reload() { return true; } //////////////////////////////////////////////////////////////////////////////////////////////////////////////// // KResFXParticle Implement /////////////////////////////////////////////////////////////////////////////////////////////////////////////// KResFXParticle::KResFXParticle() { m_type = RESTYPE_FXPARTICLE; } KResFXParticle::~KResFXParticle() { } void KResFXParticle::SetTexture( K3DTexture *pTex ) { m_spTex = pTex; } void KResFXParticle::SetRes( K3DResMeshMatrixAnimation *pResMat, K3DResMeshVisibilityAnimation *pResVis) { assert(m_spResVis == NULL && m_spResMat == NULL); m_spResMat = pResMat; if(m_spResMat != NULL) { m_interval = m_spResMat->GetInterval(); } m_spResVis = pResVis; } const KInterval& KResFXParticle::GetInterval() { return m_interval; } K3DTexture* KResFXParticle::GetTexture() { return m_spTex; } void KResFXParticle::SetVertices( K3DVertex *vtxs ) { memcpy( m_vtxBillBoard, vtxs, sizeof(m_vtxBillBoard) ); } const K3DVertex* KResFXParticle::GetVertices() { return m_vtxBillBoard; } void KResFXParticle::CalcNormal( K3DVertex* vtxs ) { K3DVector v1( vtxs[ 1 ] - vtxs[ 0 ] ); K3DVector v2( vtxs[ 2 ] - vtxs[ 0 ] ); K3DVectorCross( m_vecNormal, v1, v2 ); m_vecNormal.Normalize(); } const K3DVector& KResFXParticle::GetNormal() { return m_vecNormal; } void KResFXParticle::GetData( int time, float *vis, K3DMatrix *mat ) { if ( m_spResMat != NULL) { m_spResMat->GetLerpMatrix(time, mat); } if ( m_spResVis != NULL) { m_spResVis->GetVisibility(time, vis); } else { *vis = 1.0f; } } bool KResFXParticle::Reload() { return true; } //////////////////////////////////////////////////////////////////////////////////////////////////////////////// // KResFXAfterImage Implement /////////////////////////////////////////////////////////////////////////////////////////////////////////////// KResFXAfterImage::KResFXAfterImage() { m_type = RESTYPE_FXAFTERIMAGE; } KResFXAfterImage::~KResFXAfterImage() { } void KResFXAfterImage::SetTexture( K3DTexture *pTex ) { m_spTex = pTex; } void KResFXAfterImage::SetVertices( K3DVertex *vtxs ) { memcpy( m_vtxAfterImage, vtxs, sizeof(m_vtxAfterImage) ); } const K3DVertex *KResFXAfterImage::GetVertices() { return m_vtxAfterImage; } void KResFXAfterImage::SetRes( K3DResMeshMatrixAnimation *pMatRes, K3DResMeshVisibilityAnimation *pVisRes) { assert(m_spResMat == NULL && m_spResVis == NULL); m_spResMat = pMatRes; if ( m_spResMat != NULL ) { m_interval = m_spResMat->GetInterval(); } m_spResVis = pVisRes; } const KInterval &KResFXAfterImage::GetInterval() { return m_interval; } K3DTexture *KResFXAfterImage::GetTexture() { return m_spTex; } void KResFXAfterImage::GetData( int time, K3DSPRITEVERTEX& vtx0, K3DSPRITEVERTEX& vtx1, const K3DMatrix& matParent, float& vis ) { static K3DMatrix mat; if ( m_spResMat != NULL) { m_spResMat->GetLerpMatrix(time, &mat); } if ( m_spResVis != NULL) { m_spResVis->GetVisibility(time, &vis); } else { vis = 1.0f; } K3DVectorTransform(vtx0.pos, m_vtxAfterImage[0], mat ); K3DVectorTransform(vtx1.pos, m_vtxAfterImage[2], mat ); vtx0.diffuse = KColor(255,255,255,unsigned char( 255 * vis )); vtx1.diffuse = KColor(255,255,255,unsigned char( 255 * vis )); } bool KResFXAfterImage::Reload() { return true; }