모델오류
This commit is contained in:
@@ -0,0 +1,152 @@
|
||||
#include "pch.h"
|
||||
#include "Animation.h"
|
||||
#include "Channel.h"
|
||||
#include "Model.h"
|
||||
#include "Bone.h"
|
||||
|
||||
CAnimation::CAnimation()
|
||||
{
|
||||
}
|
||||
|
||||
CAnimation::CAnimation(const CAnimation& Prototype)
|
||||
: m_fCurrentTrackPosition{ Prototype.m_fCurrentTrackPosition }
|
||||
, m_fDuration{ Prototype.m_fDuration }
|
||||
, m_fTickPerSecond{ Prototype.m_fTickPerSecond }
|
||||
, m_iNumChannels{ Prototype.m_iNumChannels }
|
||||
, m_Channels{ Prototype.m_Channels }
|
||||
, m_CurrentKeyFrameIndices{ Prototype.m_CurrentKeyFrameIndices }
|
||||
, m_pAIAnimation{ Prototype.m_pAIAnimation }
|
||||
{
|
||||
for (auto& pChannel : m_Channels)
|
||||
Safe_AddRef(pChannel);
|
||||
|
||||
}
|
||||
|
||||
|
||||
HRESULT CAnimation::Initialize(const CModel* pModel, const aiAnimation* pAIAnimation)
|
||||
{
|
||||
m_pAIAnimation = pAIAnimation;
|
||||
m_fDuration = pAIAnimation->mDuration;
|
||||
m_fTickPerSecond = (_float)pAIAnimation->mTicksPerSecond;
|
||||
|
||||
m_iNumChannels = pAIAnimation->mNumChannels;
|
||||
|
||||
m_CurrentKeyFrameIndices.resize(m_iNumChannels);
|
||||
|
||||
for (size_t i = 0; i < m_iNumChannels; i++)
|
||||
{
|
||||
CChannel* pChannel = CChannel::Create(pModel, pAIAnimation->mChannels[i]);
|
||||
if (nullptr == pChannel)
|
||||
return E_FAIL;
|
||||
|
||||
m_Channels.push_back(pChannel);
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
_bool CAnimation::Update_TransformationMatrices(_float fTimeDelta, _bool isLoop, vector<CBone*>& Bones)
|
||||
{
|
||||
m_fCurrentTrackPosition += m_fTickPerSecond * fTimeDelta;
|
||||
|
||||
if (m_fCurrentTrackPosition >= m_fDuration)
|
||||
{
|
||||
if (isLoop)
|
||||
m_fCurrentTrackPosition = 0.f;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
||||
_uint iIndex = {};
|
||||
m_vBoneTransformationMatrix.clear();
|
||||
|
||||
for (auto& pChannel : m_Channels)
|
||||
{
|
||||
pChannel->Update_TransformationMatrix(m_fCurrentTrackPosition, Bones, &m_CurrentKeyFrameIndices[iIndex++]);
|
||||
m_vBoneTransformationMatrix.push_back(pChannel->Get_BoneTransformationMatrix());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void CAnimation::InterpAnim(CAnimation* pPreAnim, vector<CBone*>& Bones, float fRatio)
|
||||
{
|
||||
|
||||
for (size_t i = 0; i < m_Channels.size(); i++)
|
||||
{
|
||||
if (m_vBoneTransformationMatrix.size() > pPreAnim->m_vBoneTransformationMatrix.size())
|
||||
{
|
||||
for (size_t j = 0; j < pPreAnim->m_Channels.size(); j++)
|
||||
{
|
||||
if (strcmp(m_pAIAnimation->mChannels[i]->mNodeName.C_Str(), pPreAnim->m_pAIAnimation->mChannels[j]->mNodeName.C_Str()) == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (j == pPreAnim->m_Channels.size() - 1)
|
||||
{
|
||||
pPreAnim->m_vBoneTransformationMatrix.push_back(m_vBoneTransformationMatrix[i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (size_t i = 0; i < m_Channels.size(); i++)
|
||||
{
|
||||
for (size_t j = 0; j < pPreAnim->m_pAIAnimation->mNumChannels; j++)
|
||||
{
|
||||
if (strcmp(m_pAIAnimation->mChannels[i]->mNodeName.C_Str(), pPreAnim->m_pAIAnimation->mChannels[j]->mNodeName.C_Str()) == 0)
|
||||
{
|
||||
_matrix CurMat = m_vBoneTransformationMatrix[i];
|
||||
_matrix PreMat = pPreAnim->m_vBoneTransformationMatrix[j];
|
||||
|
||||
_vector CurScale, CurRot, CurPos;
|
||||
_vector PreScale, PreRot, PrePos;
|
||||
XMMatrixDecompose(&CurScale, &CurRot, &CurPos, CurMat);
|
||||
XMMatrixDecompose(&PreScale, &PreRot, &PrePos, PreMat);
|
||||
|
||||
_vector FinalScale = XMVectorLerp(PreScale, CurScale, fRatio);
|
||||
_vector FinalRot = XMQuaternionSlerp(PreRot, CurRot, fRatio);
|
||||
_vector FinalPos = XMVectorLerp(PrePos, CurPos, fRatio);
|
||||
|
||||
m_vBoneTransformationMatrix[i] = XMMatrixAffineTransformation(FinalScale, XMVectorZero(), FinalRot, FinalPos);
|
||||
_int BoneIndex = m_Channels[i]->Get_BoneIndex();
|
||||
if (BoneIndex < Bones.size())
|
||||
{
|
||||
Bones[BoneIndex]->Set_Transformation(m_vBoneTransformationMatrix[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CAnimation* CAnimation::Create(const CModel* pModel, const aiAnimation* pAIAnimation)
|
||||
{
|
||||
CAnimation* pInstance = new CAnimation();
|
||||
|
||||
if (FAILED(pInstance->Initialize(pModel, pAIAnimation)))
|
||||
{
|
||||
MSG_BOX("Failed to Created : CAnimation");
|
||||
Safe_Release(pInstance);
|
||||
}
|
||||
|
||||
return pInstance;
|
||||
}
|
||||
|
||||
CAnimation* CAnimation::Clone()
|
||||
{
|
||||
return new CAnimation(*this);
|
||||
}
|
||||
|
||||
void CAnimation::Free()
|
||||
{
|
||||
__super::Free();
|
||||
|
||||
for (auto& pChannel : m_Channels)
|
||||
Safe_Release(pChannel);
|
||||
|
||||
m_Channels.clear();
|
||||
|
||||
m_CurrentKeyFrameIndices.clear();
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
#include "pch.h"
|
||||
#include "Bone.h"
|
||||
|
||||
CBone::CBone()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
HRESULT CBone::Initialize(const aiNode* pAINode, _int iParentIndex)
|
||||
{
|
||||
strcpy_s(m_szName, pAINode->mName.data);
|
||||
|
||||
m_iParentBoneIndex = iParentIndex;
|
||||
|
||||
memcpy(&m_TransformationMatrix, &pAINode->mTransformation, sizeof(_float4x4));
|
||||
XMStoreFloat4x4(&m_TransformationMatrix, XMMatrixTranspose(XMLoadFloat4x4(&m_TransformationMatrix)));
|
||||
|
||||
XMStoreFloat4x4(&m_CombinedTransformationMatrix, XMMatrixIdentity());
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
void CBone::Update_CombinedTransformationMatrix(const vector<CBone*>& Bones, _fmatrix PreTransformMatrix)
|
||||
{
|
||||
if (-1 == m_iParentBoneIndex)
|
||||
XMStoreFloat4x4(&m_CombinedTransformationMatrix,
|
||||
XMLoadFloat4x4(&m_TransformationMatrix) * PreTransformMatrix);
|
||||
|
||||
else
|
||||
XMStoreFloat4x4(&m_CombinedTransformationMatrix,
|
||||
XMLoadFloat4x4(&m_TransformationMatrix) * Bones[m_iParentBoneIndex]->Get_CombinedTransformationMatrix());
|
||||
}
|
||||
|
||||
void CBone::Set_Transformation(_fmatrix BoneTransformationMatrix)
|
||||
{
|
||||
XMStoreFloat4x4(&m_TransformationMatrix, BoneTransformationMatrix);
|
||||
}
|
||||
|
||||
CBone* CBone::Create(const aiNode* pAINode, _int iParentIndex)
|
||||
{
|
||||
CBone* pInstance = new CBone();
|
||||
|
||||
if (FAILED(pInstance->Initialize(pAINode, iParentIndex)))
|
||||
{
|
||||
MSG_BOX("Failed to Created : CBone");
|
||||
Safe_Release(pInstance);
|
||||
}
|
||||
|
||||
return pInstance;
|
||||
}
|
||||
|
||||
CBone* CBone::Clone()
|
||||
{
|
||||
return new CBone(*this);
|
||||
}
|
||||
|
||||
void CBone::Free()
|
||||
{
|
||||
__super::Free();
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
#include "pch.h"
|
||||
#include "Channel.h"
|
||||
#include "Model.h"
|
||||
#include "Bone.h"
|
||||
|
||||
CChannel::CChannel()
|
||||
{
|
||||
}
|
||||
|
||||
HRESULT CChannel::Initialize(const CModel* pModel, const aiNodeAnim* pAIChannel)
|
||||
{
|
||||
strcpy_s(m_szName, pAIChannel->mNodeName.data);
|
||||
|
||||
m_iBoneIndex = pModel->Get_BoneIndex(m_szName);
|
||||
if (-1 == m_iBoneIndex)
|
||||
return E_FAIL;
|
||||
|
||||
m_iNumKeyFrames = max(pAIChannel->mNumScalingKeys, pAIChannel->mNumRotationKeys);
|
||||
m_iNumKeyFrames = max(m_iNumKeyFrames, pAIChannel->mNumPositionKeys);
|
||||
|
||||
_float3 vScale{};
|
||||
_float4 vRotation{};
|
||||
_float3 vTranslation{};
|
||||
|
||||
for (size_t i = 0; i < m_iNumKeyFrames; i++)
|
||||
{
|
||||
KEYFRAME KeyFrame{};
|
||||
|
||||
if (i < pAIChannel->mNumScalingKeys)
|
||||
{
|
||||
memcpy(&vScale, &pAIChannel->mScalingKeys[i].mValue, sizeof(_float3));
|
||||
KeyFrame.fTrackPosition = (_float)pAIChannel->mScalingKeys[i].mTime;
|
||||
}
|
||||
|
||||
if (i < pAIChannel->mNumRotationKeys)
|
||||
{
|
||||
vRotation.x = pAIChannel->mRotationKeys[i].mValue.x;
|
||||
vRotation.y = pAIChannel->mRotationKeys[i].mValue.y;
|
||||
vRotation.z = pAIChannel->mRotationKeys[i].mValue.z;
|
||||
vRotation.w = pAIChannel->mRotationKeys[i].mValue.w;
|
||||
|
||||
KeyFrame.fTrackPosition = (_float)pAIChannel->mRotationKeys[i].mTime;
|
||||
}
|
||||
|
||||
if (i < pAIChannel->mNumPositionKeys)
|
||||
{
|
||||
memcpy(&vTranslation, &pAIChannel->mPositionKeys[i].mValue, sizeof(_float3));
|
||||
KeyFrame.fTrackPosition = (_float)pAIChannel->mPositionKeys[i].mTime;
|
||||
}
|
||||
|
||||
KeyFrame.vScale = vScale;
|
||||
KeyFrame.vRotation = vRotation;
|
||||
KeyFrame.vTranslation = vTranslation;
|
||||
|
||||
m_KeyFrames.push_back(KeyFrame);
|
||||
}
|
||||
|
||||
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
void CChannel::Update_TransformationMatrix(_float fCurrentTrackPosition, vector<CBone*>& Bones, _uint* pCurrentKeyFrameIndex)
|
||||
{
|
||||
if (0.f == fCurrentTrackPosition)
|
||||
*pCurrentKeyFrameIndex = 0;
|
||||
|
||||
KEYFRAME LastKeyFrame = m_KeyFrames.back();
|
||||
|
||||
_vector vScale{};
|
||||
_vector vRotation{};
|
||||
_vector vTranslation{};
|
||||
|
||||
if (fCurrentTrackPosition >= LastKeyFrame.fTrackPosition)
|
||||
{
|
||||
vScale = XMLoadFloat3(&LastKeyFrame.vScale);
|
||||
vRotation = XMLoadFloat4(&LastKeyFrame.vRotation);
|
||||
vTranslation = XMVectorSetW(XMLoadFloat3(&LastKeyFrame.vTranslation), 1.f);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
while (fCurrentTrackPosition >= m_KeyFrames[*pCurrentKeyFrameIndex + 1].fTrackPosition)
|
||||
++*pCurrentKeyFrameIndex;
|
||||
|
||||
_float3 vSourScale{}, vDestScale{};
|
||||
_float4 vSourRotation{}, vDestRotation{};
|
||||
_float3 vSourTranslation{}, vDestTranslation{};
|
||||
|
||||
vSourScale = m_KeyFrames[*pCurrentKeyFrameIndex].vScale;
|
||||
vDestScale = m_KeyFrames[*pCurrentKeyFrameIndex + 1].vScale;
|
||||
|
||||
vSourRotation = m_KeyFrames[*pCurrentKeyFrameIndex].vRotation;
|
||||
vDestRotation = m_KeyFrames[*pCurrentKeyFrameIndex + 1].vRotation;
|
||||
|
||||
vSourTranslation = m_KeyFrames[*pCurrentKeyFrameIndex].vTranslation;
|
||||
vDestTranslation = m_KeyFrames[*pCurrentKeyFrameIndex + 1].vTranslation;
|
||||
|
||||
_float fRatio = (fCurrentTrackPosition - m_KeyFrames[*pCurrentKeyFrameIndex].fTrackPosition) /
|
||||
(m_KeyFrames[*pCurrentKeyFrameIndex + 1].fTrackPosition - m_KeyFrames[*pCurrentKeyFrameIndex].fTrackPosition);
|
||||
|
||||
vScale = XMVectorLerp(XMLoadFloat3(&vSourScale), XMLoadFloat3(&vDestScale), fRatio);
|
||||
vRotation = XMQuaternionSlerp(XMLoadFloat4(&vSourRotation), XMLoadFloat4(&vDestRotation), fRatio);
|
||||
vTranslation = XMVectorSetW(XMVectorLerp(XMLoadFloat3(&vSourTranslation), XMLoadFloat3(&vDestTranslation), fRatio), 1.f);
|
||||
|
||||
}
|
||||
|
||||
m_BoneTransformationMatrix = XMMatrixAffineTransformation(vScale, XMVectorSet(0.f, 0.f, 0.f, 1.f), vRotation, vTranslation);
|
||||
|
||||
Bones[m_iBoneIndex]->Set_Transformation(m_BoneTransformationMatrix);
|
||||
|
||||
|
||||
}
|
||||
|
||||
CChannel* CChannel::Create(const CModel* pModel, const aiNodeAnim* pAIChannel)
|
||||
{
|
||||
CChannel* pInstance = new CChannel();
|
||||
|
||||
if (FAILED(pInstance->Initialize(pModel, pAIChannel)))
|
||||
{
|
||||
MSG_BOX("Failed to Created : CChannel");
|
||||
Safe_Release(pInstance);
|
||||
}
|
||||
|
||||
return pInstance;
|
||||
}
|
||||
|
||||
void CChannel::Free()
|
||||
{
|
||||
__super::Free();
|
||||
|
||||
m_KeyFrames.clear();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
#include "pch.h"
|
||||
#include "Material.h"
|
||||
|
||||
#include "Shader.h"
|
||||
|
||||
CMaterial::CMaterial(ID3D11Device* pDevice, ID3D11DeviceContext* pContext)
|
||||
: m_pDevice{ pDevice }
|
||||
, m_pContext{ pContext }
|
||||
{
|
||||
Safe_AddRef(m_pDevice);
|
||||
Safe_AddRef(m_pContext);
|
||||
}
|
||||
|
||||
HRESULT CMaterial::Initialize(const _char* pModelFilePath, const aiMaterial* pAIMaterial)
|
||||
{
|
||||
for (_uint i = 0; i < AI_TEXTURE_TYPE_MAX; i++)
|
||||
{
|
||||
m_iNumSRVs = pAIMaterial->GetTextureCount(static_cast<aiTextureType>(i));
|
||||
|
||||
m_SRVs[i].reserve(m_iNumSRVs);
|
||||
|
||||
for (_uint j = 0; j < m_iNumSRVs; j++)
|
||||
{
|
||||
aiString strTexturePath;
|
||||
|
||||
|
||||
char szDrive[MAX_PATH] = {};
|
||||
char szDir[MAX_PATH] = {};
|
||||
char szFileName[MAX_PATH] = {};
|
||||
char szEXT[MAX_PATH] = {};
|
||||
|
||||
if (FAILED(pAIMaterial->GetTexture(static_cast<aiTextureType>(i), j, &strTexturePath)))
|
||||
continue;
|
||||
|
||||
_char szTextureFilePath[MAX_PATH] = {};
|
||||
_splitpath_s(pModelFilePath, szDrive, MAX_PATH, szDir, MAX_PATH, nullptr, 0, nullptr, 0);
|
||||
_splitpath_s(strTexturePath.data, nullptr, 0, nullptr, 0, szFileName, MAX_PATH, szEXT, MAX_PATH);
|
||||
|
||||
strcpy_s(szTextureFilePath, szDrive);
|
||||
strcat_s(szTextureFilePath, szDir);
|
||||
strcat_s(szTextureFilePath, szFileName);
|
||||
strcat_s(szTextureFilePath, szEXT);
|
||||
|
||||
_tchar szPerfectPath[MAX_PATH] = {};
|
||||
MultiByteToWideChar(CP_ACP, 0, szTextureFilePath, (_int)strlen(szTextureFilePath),
|
||||
szPerfectPath, MAX_PATH);
|
||||
|
||||
ID3D11ShaderResourceView* pSRV = { nullptr };
|
||||
|
||||
HRESULT hr = {};
|
||||
|
||||
if (false == strcmp(".dds", szEXT))
|
||||
hr = CreateDDSTextureFromFile(m_pDevice, szPerfectPath, nullptr, &pSRV);
|
||||
else if (false == strcmp(".tga", szEXT))
|
||||
hr = S_OK;
|
||||
else
|
||||
hr = CreateWICTextureFromFile(m_pDevice, szPerfectPath, nullptr, &pSRV);
|
||||
|
||||
if (FAILED(hr))
|
||||
return E_FAIL;
|
||||
|
||||
m_SRVs[i].push_back(pSRV);
|
||||
}
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CMaterial::Bind_SRV(CShader* pShader, const _char* pConstantName, aiTextureType eType, _uint iTextureIndex)
|
||||
{
|
||||
if (m_SRVs[eType].empty())
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
return pShader->Bind_SRV(pConstantName, m_SRVs[eType][iTextureIndex]);
|
||||
}
|
||||
|
||||
CMaterial* CMaterial::Create(ID3D11Device* pDevice, ID3D11DeviceContext* pContext, const _char* pModelFilePath, const aiMaterial* pAIMaterial)
|
||||
{
|
||||
CMaterial* pInstance = new CMaterial(pDevice, pContext);
|
||||
|
||||
if (FAILED(pInstance->Initialize(pModelFilePath, pAIMaterial)))
|
||||
{
|
||||
MSG_BOX("Failed to Created : CMaterial");
|
||||
Safe_Release(pInstance);
|
||||
}
|
||||
|
||||
return pInstance;
|
||||
}
|
||||
void CMaterial::Free()
|
||||
{
|
||||
__super::Free();
|
||||
|
||||
Safe_Release(m_pDevice);
|
||||
Safe_Release(m_pContext);
|
||||
|
||||
for (auto& SRVs : m_SRVs)
|
||||
{
|
||||
for (auto& pSRV : SRVs)
|
||||
Safe_Release(pSRV);
|
||||
SRVs.clear();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,359 @@
|
||||
#include "pch.h"
|
||||
#include "Mesh.h"
|
||||
|
||||
#include "Bone.h"
|
||||
#include "Model.h"
|
||||
#include "Shader.h"
|
||||
|
||||
|
||||
CMesh::CMesh(ID3D11Device* pDevice, ID3D11DeviceContext* pContext)
|
||||
: CVIBuffer( pDevice, pContext )
|
||||
{
|
||||
}
|
||||
|
||||
CMesh::CMesh(const CMesh& Prototype)
|
||||
: CVIBuffer( Prototype )
|
||||
{
|
||||
}
|
||||
|
||||
HRESULT CMesh::Initialize_Prototype(MODEL eType, const class CModel* pModel, const aiMesh* pAIMesh, _fmatrix PreTransformMatrix)
|
||||
{
|
||||
strcpy_s(m_szName, pAIMesh->mName.data);
|
||||
|
||||
m_iMaterialIndex = pAIMesh->mMaterialIndex;
|
||||
m_iNumVertexBuffers = 1;
|
||||
m_iNumVertices = pAIMesh->mNumVertices;
|
||||
|
||||
m_iNumIndices = pAIMesh->mNumFaces * 3;
|
||||
m_iIndexStride = 4;
|
||||
|
||||
m_eIndexFormat = DXGI_FORMAT_R32_UINT;
|
||||
m_ePrimitive = D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST;
|
||||
|
||||
|
||||
m_Indices.clear();
|
||||
m_Indices.reserve(pAIMesh->mNumFaces * 3);
|
||||
for (unsigned int f = 0; f < pAIMesh->mNumFaces; ++f)
|
||||
{
|
||||
const aiFace& face = pAIMesh->mFaces[f];
|
||||
if (face.mNumIndices == 3)
|
||||
{
|
||||
m_Indices.push_back(face.mIndices[0]);
|
||||
m_Indices.push_back(face.mIndices[1]);
|
||||
m_Indices.push_back(face.mIndices[2]);
|
||||
}
|
||||
}
|
||||
|
||||
m_Vertices.clear();
|
||||
m_Vertices.reserve(pAIMesh->mNumVertices);
|
||||
|
||||
XMMATRIX matPre = PreTransformMatrix;
|
||||
for (size_t i = 0; i < pAIMesh->mNumVertices; ++i)
|
||||
{
|
||||
_float3 pos{ pAIMesh->mVertices[i].x,
|
||||
pAIMesh->mVertices[i].y,
|
||||
pAIMesh->mVertices[i].z };
|
||||
XMVECTOR v = XMLoadFloat3(&pos);
|
||||
v = XMVector3TransformCoord(v, matPre);
|
||||
XMFLOAT3 tp;
|
||||
XMStoreFloat3(&tp, v);
|
||||
m_Vertices.push_back(tp);
|
||||
}
|
||||
|
||||
#pragma region VERTEX_BUFFER
|
||||
|
||||
HRESULT hr = MODEL::NONANIM == eType ?
|
||||
Ready_VertexBuffer_For_NonAnim(pAIMesh, PreTransformMatrix) :
|
||||
Ready_VertexBuffer_For_Anim(pModel, pAIMesh);
|
||||
|
||||
if (FAILED(hr))
|
||||
return E_FAIL;
|
||||
|
||||
#pragma endregion
|
||||
|
||||
#pragma region INDEX_BUFFER
|
||||
D3D11_BUFFER_DESC IBDesc{};
|
||||
IBDesc.ByteWidth = m_iIndexStride * m_iNumIndices;
|
||||
IBDesc.Usage = D3D11_USAGE_DEFAULT;
|
||||
IBDesc.BindFlags = D3D11_BIND_INDEX_BUFFER;
|
||||
IBDesc.StructureByteStride = m_iIndexStride;
|
||||
IBDesc.CPUAccessFlags = 0;
|
||||
IBDesc.MiscFlags = 0;
|
||||
|
||||
|
||||
_uint* pIndices = new _uint[m_iNumIndices];
|
||||
ZeroMemory(pIndices, sizeof(_uint) * m_iNumIndices);
|
||||
|
||||
_uint iNumIndices = {};
|
||||
|
||||
for (size_t i = 0; i < pAIMesh->mNumFaces; i++)
|
||||
{
|
||||
pIndices[iNumIndices++] = pAIMesh->mFaces[i].mIndices[0];
|
||||
pIndices[iNumIndices++] = pAIMesh->mFaces[i].mIndices[1];
|
||||
pIndices[iNumIndices++] = pAIMesh->mFaces[i].mIndices[2];
|
||||
}
|
||||
|
||||
|
||||
D3D11_SUBRESOURCE_DATA InitialIBData{};
|
||||
InitialIBData.pSysMem = pIndices;
|
||||
|
||||
if (FAILED(m_pDevice->CreateBuffer(&IBDesc, &InitialIBData, &m_pIB)))
|
||||
return E_FAIL;
|
||||
|
||||
Safe_Delete_Array(pIndices);
|
||||
|
||||
#pragma endregion
|
||||
|
||||
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CMesh::Initialize(void* pArg)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CMesh::Bind_BoneMatrices(const vector<CBone*>& Bones, CShader* pShader, const _char* pConstantName)
|
||||
{
|
||||
if (m_iNumBones >= 512)
|
||||
return E_FAIL;
|
||||
|
||||
|
||||
for (size_t i = 0; i < m_iNumBones; i++)
|
||||
{
|
||||
XMStoreFloat4x4(&m_pBoneMatrices[i], XMLoadFloat4x4(&m_OffsetMatrices[i]) * Bones[m_BoneIndices[i]]->Get_CombinedTransformationMatrix());
|
||||
}
|
||||
|
||||
if (0 == m_iNumBones)
|
||||
return S_OK;
|
||||
|
||||
return pShader->Bind_Matrices(pConstantName, m_pBoneMatrices, m_iNumBones);
|
||||
|
||||
}
|
||||
|
||||
HRESULT CMesh::Ready_VertexBuffer_For_NonAnim(const aiMesh* pAIMesh, _fmatrix PreTransformMatrix)
|
||||
{
|
||||
m_iVertexStride = sizeof(VTXMESH);
|
||||
D3D11_BUFFER_DESC VBDesc{};
|
||||
VBDesc.ByteWidth = m_iVertexStride * m_iNumVertices;
|
||||
VBDesc.Usage = D3D11_USAGE_DEFAULT;
|
||||
VBDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
|
||||
VBDesc.StructureByteStride = m_iVertexStride;
|
||||
VBDesc.CPUAccessFlags = 0;
|
||||
VBDesc.MiscFlags = 0;
|
||||
|
||||
VTXMESH* pVertices = new VTXMESH[m_iNumVertices];
|
||||
ZeroMemory(pVertices, sizeof(VTXMESH) * m_iNumVertices);
|
||||
|
||||
m_pVertexPositions = new _float3[m_iNumVertices];
|
||||
ZeroMemory(m_pVertexPositions, sizeof(_float3) * m_iNumVertices);
|
||||
|
||||
for (_uint i = 0; i < m_iNumVertices; ++i)
|
||||
{
|
||||
memcpy(&pVertices[i].vPosition, &pAIMesh->mVertices[i], sizeof(_float3));
|
||||
XMStoreFloat3(&pVertices[i].vPosition, XMVector3TransformCoord(XMLoadFloat3(&pVertices[i].vPosition), PreTransformMatrix));
|
||||
|
||||
if (pAIMesh->HasNormals())
|
||||
{
|
||||
memcpy(&pVertices[i].vNormal, &pAIMesh->mNormals[i], sizeof(_float3));
|
||||
XMStoreFloat3(&pVertices[i].vNormal,
|
||||
XMVector3Normalize(XMVector3TransformNormal(XMLoadFloat3(&pVertices[i].vNormal), PreTransformMatrix)));
|
||||
}
|
||||
else
|
||||
{
|
||||
pVertices[i].vNormal = _float3(0.f, 1.f, 0.f);
|
||||
}
|
||||
|
||||
if (pAIMesh->HasTangentsAndBitangents())
|
||||
{
|
||||
memcpy(&pVertices[i].vTangent, &pAIMesh->mTangents[i], sizeof(_float3));
|
||||
XMStoreFloat3(&pVertices[i].vTangent,
|
||||
XMVector3Normalize(XMVector3TransformNormal(XMLoadFloat3(&pVertices[i].vTangent), PreTransformMatrix)));
|
||||
}
|
||||
else
|
||||
{
|
||||
pVertices[i].vTangent = _float3(1.f, 0.f, 0.f);
|
||||
}
|
||||
|
||||
if (pAIMesh->HasTextureCoords(0))
|
||||
{
|
||||
memcpy(&pVertices[i].vTexcoord, &pAIMesh->mTextureCoords[0][i], sizeof(_float2));
|
||||
}
|
||||
else
|
||||
{
|
||||
pVertices[i].vTexcoord = _float2(0.f, 0.f);
|
||||
}
|
||||
}
|
||||
|
||||
D3D11_SUBRESOURCE_DATA InitialVBData{};
|
||||
InitialVBData.pSysMem = pVertices;
|
||||
|
||||
if (FAILED(m_pDevice->CreateBuffer(&VBDesc, &InitialVBData, &m_pVB)))
|
||||
return E_FAIL;
|
||||
|
||||
Safe_Delete_Array(pVertices);
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CMesh::Ready_VertexBuffer_For_Anim(const CModel* pModel, const aiMesh* pAIMesh)
|
||||
{
|
||||
m_iVertexStride = sizeof(VTXANIMMESH);
|
||||
D3D11_BUFFER_DESC VBDesc{};
|
||||
VBDesc.ByteWidth = m_iVertexStride * m_iNumVertices;
|
||||
VBDesc.Usage = D3D11_USAGE_DEFAULT;
|
||||
VBDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
|
||||
VBDesc.StructureByteStride = m_iVertexStride;
|
||||
VBDesc.CPUAccessFlags = 0;
|
||||
VBDesc.MiscFlags = 0;
|
||||
|
||||
VTXANIMMESH* pVertices = new VTXANIMMESH[m_iNumVertices];
|
||||
ZeroMemory(pVertices, sizeof(VTXANIMMESH) * m_iNumVertices);
|
||||
|
||||
m_pVertexPositions = new _float3[m_iNumVertices];
|
||||
ZeroMemory(m_pVertexPositions, sizeof(_float3) * m_iNumVertices);
|
||||
|
||||
for (_uint i = 0; i < m_iNumVertices; ++i)
|
||||
{
|
||||
memcpy(&pVertices[i].vPosition, &pAIMesh->mVertices[i], sizeof(_float3));
|
||||
if (pAIMesh->HasNormals())
|
||||
{
|
||||
memcpy(&pVertices[i].vNormal, &pAIMesh->mNormals[i], sizeof(_float3));
|
||||
}
|
||||
else
|
||||
{
|
||||
pVertices[i].vNormal = _float3(0.f, 1.f, 0.f);
|
||||
}
|
||||
|
||||
if (pAIMesh->HasTangentsAndBitangents())
|
||||
{
|
||||
memcpy(&pVertices[i].vTangent, &pAIMesh->mTangents[i], sizeof(_float3));
|
||||
}
|
||||
else
|
||||
{
|
||||
pVertices[i].vTangent = _float3(1.f, 0.f, 0.f);
|
||||
}
|
||||
|
||||
if (pAIMesh->HasTextureCoords(0))
|
||||
{
|
||||
memcpy(&pVertices[i].vTexcoord, &pAIMesh->mTextureCoords[0][i], sizeof(_float2));
|
||||
}
|
||||
else
|
||||
{
|
||||
pVertices[i].vTexcoord = _float2(0.f, 0.f);
|
||||
}
|
||||
}
|
||||
|
||||
m_iNumBones = pAIMesh->mNumBones;
|
||||
|
||||
m_OffsetMatrices.reserve(m_iNumBones);
|
||||
|
||||
m_pBoneMatrices = new _float4x4[0 == m_iNumBones ? 1 : m_iNumBones];
|
||||
ZeroMemory(m_pBoneMatrices, sizeof(_float4x4) * m_iNumBones);
|
||||
|
||||
_float4x4 OffsetMatrix;
|
||||
XMStoreFloat4x4(&OffsetMatrix, XMMatrixIdentity());
|
||||
|
||||
for (_uint i = 0; i < m_iNumBones; i++)
|
||||
{
|
||||
aiBone* pAIBone = pAIMesh->mBones[i];
|
||||
|
||||
memcpy(&OffsetMatrix, &pAIBone->mOffsetMatrix, sizeof(_float4x4));
|
||||
XMStoreFloat4x4(&OffsetMatrix, XMMatrixTranspose(XMLoadFloat4x4(&OffsetMatrix)));
|
||||
|
||||
_int iBoneIndex = pModel->Get_BoneIndex(pAIBone->mName.data);
|
||||
|
||||
if (-1 == iBoneIndex)
|
||||
return E_FAIL;
|
||||
|
||||
m_OffsetMatrices.push_back(OffsetMatrix);
|
||||
m_BoneIndices.push_back(iBoneIndex);
|
||||
|
||||
for (_uint j = 0; j < pAIBone->mNumWeights; j++)
|
||||
{
|
||||
aiVertexWeight AIWeight = pAIBone->mWeights[j];
|
||||
|
||||
if (0.f == pVertices[AIWeight.mVertexId].vBlendWeight.x)
|
||||
{
|
||||
pVertices[AIWeight.mVertexId].vBlendIndex.x = i;
|
||||
pVertices[AIWeight.mVertexId].vBlendWeight.x = AIWeight.mWeight;
|
||||
}
|
||||
|
||||
else if (0.f == pVertices[AIWeight.mVertexId].vBlendWeight.y)
|
||||
{
|
||||
pVertices[AIWeight.mVertexId].vBlendIndex.y = i;
|
||||
pVertices[AIWeight.mVertexId].vBlendWeight.y = AIWeight.mWeight;
|
||||
}
|
||||
|
||||
else if (0.f == pVertices[AIWeight.mVertexId].vBlendWeight.z)
|
||||
{
|
||||
pVertices[AIWeight.mVertexId].vBlendIndex.z = i;
|
||||
pVertices[AIWeight.mVertexId].vBlendWeight.z = AIWeight.mWeight;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
pVertices[AIWeight.mVertexId].vBlendIndex.w = i;
|
||||
pVertices[AIWeight.mVertexId].vBlendWeight.w = AIWeight.mWeight;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (0 == m_iNumBones)
|
||||
{
|
||||
m_iNumBones = 1;
|
||||
|
||||
m_BoneIndices.push_back(pModel->Get_BoneIndex(m_szName));
|
||||
|
||||
m_OffsetMatrices.push_back(OffsetMatrix);
|
||||
}
|
||||
|
||||
D3D11_SUBRESOURCE_DATA InitialVBData{};
|
||||
InitialVBData.pSysMem = pVertices;
|
||||
|
||||
if (FAILED(m_pDevice->CreateBuffer(&VBDesc, &InitialVBData, &m_pVB)))
|
||||
return E_FAIL;
|
||||
|
||||
Safe_Delete_Array(pVertices);
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
CMesh* CMesh::Create(ID3D11Device* pDevice, ID3D11DeviceContext* pContext, MODEL eType, const CModel* pModel, const aiMesh* pAIMesh, _fmatrix PreTransformMatrix)
|
||||
{
|
||||
CMesh* pInstance = new CMesh(pDevice, pContext);
|
||||
|
||||
if (FAILED(pInstance->Initialize_Prototype(eType, pModel, pAIMesh, PreTransformMatrix)))
|
||||
{
|
||||
MSG_BOX("Failed to Created : CMesh");
|
||||
Safe_Release(pInstance);
|
||||
}
|
||||
|
||||
return pInstance;
|
||||
}
|
||||
|
||||
CComponent* CMesh::Clone(void* pArg, CGameObject* pOwner)
|
||||
{
|
||||
CMesh* pInstance = new CMesh(*this);
|
||||
|
||||
if (FAILED(pInstance->Initialize(pArg)))
|
||||
{
|
||||
MSG_BOX("Failed to Cloned : CMesh");
|
||||
Safe_Release(pInstance);
|
||||
}
|
||||
|
||||
return pInstance;
|
||||
}
|
||||
void CMesh::Free()
|
||||
{
|
||||
__super::Free();
|
||||
|
||||
Safe_Delete_Array(m_pBoneMatrices);
|
||||
|
||||
|
||||
}
|
||||
|
||||
void CMesh::Describe_Entity()
|
||||
{
|
||||
}
|
||||
@@ -1,2 +1,301 @@
|
||||
#include "pch.h"
|
||||
#include "Model.h"
|
||||
#include "Model.h"
|
||||
#include "Mesh.h"
|
||||
#include "Shader.h"
|
||||
#include "Material.h"
|
||||
#include "Bone.h"
|
||||
#include "Animation.h"
|
||||
|
||||
CModel::CModel(ID3D11Device* pDevice, ID3D11DeviceContext* pContext)
|
||||
: CComponent( pDevice, pContext )
|
||||
{
|
||||
}
|
||||
|
||||
CModel::CModel(const CModel& Prototype)
|
||||
: CComponent( Prototype )
|
||||
, m_eType{ Prototype.m_eType }
|
||||
, m_iNumMeshes{ Prototype.m_iNumMeshes }
|
||||
, m_Meshes{ Prototype.m_Meshes }
|
||||
, m_iNumMaterials{ Prototype.m_iNumMaterials }
|
||||
, m_Materials{ Prototype.m_Materials }
|
||||
, m_PreTransformMatrix{ Prototype.m_PreTransformMatrix }
|
||||
, m_iNumAnimations{ Prototype.m_iNumAnimations }
|
||||
{
|
||||
for (auto& pPrototypeBone : Prototype.m_Bones)
|
||||
m_Bones.push_back(pPrototypeBone->Clone());
|
||||
|
||||
for (auto& pMesh : m_Meshes)
|
||||
Safe_AddRef(pMesh);
|
||||
|
||||
for (auto& pMaterial : m_Materials)
|
||||
Safe_AddRef(pMaterial);
|
||||
|
||||
for (auto& pPrototypeAnim : Prototype.m_Animations)
|
||||
m_Animations.push_back(pPrototypeAnim->Clone());
|
||||
}
|
||||
|
||||
_int CModel::Get_BoneIndex(const _char* pBoneName) const
|
||||
{
|
||||
_int iBoneIndex = {};
|
||||
|
||||
auto iter = find_if(m_Bones.begin(), m_Bones.end(), [&](CBone* pBone)->_bool
|
||||
{
|
||||
if (true == pBone->Compare_Name(pBoneName))
|
||||
return true;
|
||||
|
||||
++iBoneIndex;
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
if (iter == m_Bones.end())
|
||||
return -1;
|
||||
|
||||
return iBoneIndex;
|
||||
}
|
||||
|
||||
const _float4x4* CModel::Get_BoneMatrixPtr(const _char* pBoneName) const
|
||||
{
|
||||
auto iter = find_if(m_Bones.begin(), m_Bones.end(), [&](CBone* pBone)->_bool
|
||||
{
|
||||
if (true == pBone->Compare_Name(pBoneName))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
|
||||
return (*iter)->Get_CombinedTransformationMatrixPtr();
|
||||
}
|
||||
|
||||
HRESULT CModel::Initialize_Prototype(MODEL eType, const _char* pModelFilePath, _fmatrix PreTransformMatrix)
|
||||
{
|
||||
_uint iFlag = {};
|
||||
|
||||
iFlag = aiProcess_ConvertToLeftHanded | aiProcessPreset_TargetRealtime_Fast;
|
||||
|
||||
if (MODEL::NONANIM == eType)
|
||||
iFlag |= aiProcess_PreTransformVertices;
|
||||
|
||||
m_pAIScene = m_Importer.ReadFile(pModelFilePath, iFlag);
|
||||
if (nullptr == m_pAIScene)
|
||||
return E_FAIL;
|
||||
|
||||
m_eType = eType;
|
||||
XMStoreFloat4x4(&m_PreTransformMatrix, PreTransformMatrix);
|
||||
|
||||
Ready_Bones(m_pAIScene->mRootNode, -1);
|
||||
|
||||
if (FAILED(Ready_Meshes()))
|
||||
return E_FAIL;
|
||||
|
||||
if (FAILED(Ready_Materials(pModelFilePath)))
|
||||
return E_FAIL;
|
||||
|
||||
if (FAILED(Ready_Animations()))
|
||||
return E_FAIL;
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CModel::Initialize(void* pArg)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CModel::Bind_BoneMatrices(_uint iMeshIndex, CShader* pShader, const _char* pConstantName)
|
||||
{
|
||||
if (iMeshIndex >= m_iNumMeshes)
|
||||
return E_FAIL;
|
||||
|
||||
return m_Meshes[iMeshIndex]->Bind_BoneMatrices(m_Bones, pShader, pConstantName);
|
||||
}
|
||||
|
||||
HRESULT CModel::Bind_Material(_uint iMeshIndex, CShader* pShader, const _char* pConstantName, aiTextureType eType, _uint iTextureIndex)
|
||||
{
|
||||
if (iMeshIndex >= m_iNumMeshes)
|
||||
return E_FAIL;
|
||||
|
||||
_uint iMaterialIndex = m_Meshes[iMeshIndex]->Get_MaterialIndex();
|
||||
|
||||
if (iMaterialIndex >= m_iNumMaterials)
|
||||
return E_FAIL;
|
||||
|
||||
return m_Materials[iMaterialIndex]->Bind_SRV(pShader, pConstantName, eType, iTextureIndex);
|
||||
|
||||
}
|
||||
|
||||
_bool CModel::Play_Animation(_float fTimeDelta)
|
||||
{
|
||||
if (-1 == m_iCurrentAnimIndex ||
|
||||
m_iCurrentAnimIndex >= m_iNumAnimations)
|
||||
return false;
|
||||
|
||||
if (m_iPreAnimIndex != m_iCurrentAnimIndex)
|
||||
{
|
||||
m_fBlendTime += fTimeDelta;
|
||||
_float fRatio = m_fBlendTime / m_fBlendDuration;
|
||||
fRatio = min(fRatio, 1.f);
|
||||
|
||||
m_Animations[m_iPreAnimIndex]->Update_TransformationMatrices(fTimeDelta, m_isLoop, m_Bones);
|
||||
m_isFinish = m_Animations[m_iCurrentAnimIndex]->Update_TransformationMatrices(fTimeDelta, m_isLoop, m_Bones);
|
||||
m_Animations[m_iCurrentAnimIndex]->InterpAnim(m_Animations[m_iPreAnimIndex], m_Bones, fRatio);
|
||||
|
||||
if (fRatio >= 1.f)
|
||||
{
|
||||
m_iPreAnimIndex = m_iCurrentAnimIndex;
|
||||
m_fBlendTime = 0.f;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_isFinish = m_Animations[m_iCurrentAnimIndex]->Update_TransformationMatrices(fTimeDelta, m_isLoop, m_Bones);
|
||||
}
|
||||
|
||||
|
||||
for (auto& pBone : m_Bones)
|
||||
{
|
||||
pBone->Update_CombinedTransformationMatrix(m_Bones, XMLoadFloat4x4(&m_PreTransformMatrix));
|
||||
}
|
||||
|
||||
return m_isFinish;
|
||||
}
|
||||
|
||||
void CModel::Set_AnimationIndex(_int iIndex, _bool isLoop)
|
||||
{
|
||||
if (iIndex >= 0 && iIndex < m_iNumAnimations)
|
||||
{
|
||||
m_iCurrentAnimIndex = iIndex;
|
||||
m_isLoop = isLoop;
|
||||
}
|
||||
else
|
||||
m_iCurrentAnimIndex = -1;
|
||||
}
|
||||
|
||||
HRESULT CModel::Render(_uint iMeshIndex)
|
||||
{
|
||||
m_Meshes[iMeshIndex]->Bind_Resources();
|
||||
m_Meshes[iMeshIndex]->Render();
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CModel::Ready_Meshes()
|
||||
{
|
||||
m_iNumMeshes = m_pAIScene->mNumMeshes;
|
||||
|
||||
for (size_t i = 0; i < m_iNumMeshes; i++)
|
||||
{
|
||||
CMesh* pMesh = CMesh::Create(m_pDevice, m_pContext, m_eType, this, m_pAIScene->mMeshes[i], XMLoadFloat4x4(&m_PreTransformMatrix));
|
||||
if (nullptr == pMesh)
|
||||
return E_FAIL;
|
||||
|
||||
m_Meshes.push_back(pMesh);
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CModel::Ready_Materials(const _char* pModelFilePath)
|
||||
{
|
||||
m_iNumMaterials = m_pAIScene->mNumMaterials;
|
||||
|
||||
for (size_t i = 0; i < m_iNumMaterials; i++)
|
||||
{
|
||||
CMaterial* pMaterial = CMaterial::Create(m_pDevice, m_pContext, pModelFilePath, m_pAIScene->mMaterials[i]);
|
||||
if (nullptr == pMaterial)
|
||||
return E_FAIL;
|
||||
|
||||
m_Materials.push_back(pMaterial);
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CModel::Ready_Bones(const aiNode* pAINode, _int iParentIndex)
|
||||
{
|
||||
CBone* pBone = CBone::Create(pAINode, iParentIndex);
|
||||
if (nullptr == pBone)
|
||||
return E_FAIL;
|
||||
|
||||
m_Bones.push_back(pBone);
|
||||
|
||||
_int iParent = (_int)m_Bones.size() - 1;
|
||||
|
||||
for (_uint i = 0; i < pAINode->mNumChildren; i++)
|
||||
{
|
||||
Ready_Bones(pAINode->mChildren[i], iParent);
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CModel::Ready_Animations()
|
||||
{
|
||||
m_iNumAnimations = m_pAIScene->mNumAnimations;
|
||||
|
||||
for (size_t i = 0; i < m_iNumAnimations; i++)
|
||||
{
|
||||
CAnimation* pAnimation = CAnimation::Create(this, m_pAIScene->mAnimations[i]);
|
||||
if (nullptr == pAnimation)
|
||||
return E_FAIL;
|
||||
|
||||
m_Animations.push_back(pAnimation);
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
CModel* CModel::Create(ID3D11Device* pDevice, ID3D11DeviceContext* pContext, MODEL eType, const _char* pModelFilePath, _fmatrix PreTransformMatrix)
|
||||
{
|
||||
CModel* pInstance = new CModel(pDevice, pContext);
|
||||
|
||||
if (FAILED(pInstance->Initialize_Prototype(eType, pModelFilePath, PreTransformMatrix)))
|
||||
{
|
||||
MSG_BOX("Failed to Created : CModel");
|
||||
Safe_Release(pInstance);
|
||||
}
|
||||
|
||||
return pInstance;
|
||||
}
|
||||
|
||||
CComponent* CModel::Clone(void* pArg, CGameObject* pOwner)
|
||||
{
|
||||
CModel* pInstance = new CModel(*this);
|
||||
|
||||
if (FAILED(pInstance->Initialize(pArg)))
|
||||
{
|
||||
MSG_BOX("Failed to Cloned : CModel");
|
||||
Safe_Release(pInstance);
|
||||
}
|
||||
|
||||
return pInstance;
|
||||
}
|
||||
|
||||
|
||||
void CModel::Free()
|
||||
{
|
||||
__super::Free();
|
||||
|
||||
for (auto& pMaterial : m_Materials)
|
||||
Safe_Release(pMaterial);
|
||||
m_Materials.clear();
|
||||
|
||||
for (auto& pMesh : m_Meshes)
|
||||
Safe_Release(pMesh);
|
||||
m_Meshes.clear();
|
||||
|
||||
for (auto& pBone : m_Bones)
|
||||
Safe_Release(pBone);
|
||||
m_Bones.clear();
|
||||
|
||||
for (auto& pAnim : m_Animations)
|
||||
Safe_Release(pAnim);
|
||||
m_Animations.clear();
|
||||
|
||||
m_Importer.FreeScene();
|
||||
}
|
||||
|
||||
void CModel::Describe_Entity()
|
||||
{
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user