[add] 모델 바이너리
This commit is contained in:
@@ -196,6 +196,70 @@ HRESULT CMesh::Initialize_Prototype(HANDLE hFile, DWORD& dwByte)
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CMesh::Initialize_Prototype(MODEL eType, const CModel* pModel, SaveMesh* _SaveMesh, _fmatrix PreTransformMatrix)
|
||||
{
|
||||
strcpy_s(m_szName, _SaveMesh->Name);
|
||||
|
||||
m_iMaterialIndex = _SaveMesh->MaterialIndex;
|
||||
m_iNumVertexBuffers = 1;
|
||||
m_iNumVertices = _SaveMesh->VertexCount;
|
||||
|
||||
m_iNumIndices = _SaveMesh->IndexCount;
|
||||
m_iIndexStride = 4;
|
||||
|
||||
m_eIndexFormat = DXGI_FORMAT_R32_UINT;
|
||||
m_ePrimitive = D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST;
|
||||
|
||||
m_Indices = _SaveMesh->Indices;
|
||||
|
||||
m_Vertices.clear();
|
||||
m_Vertices.reserve(_SaveMesh->Vertices.size());
|
||||
|
||||
XMMATRIX matPre = PreTransformMatrix;
|
||||
for (size_t i = 0; i < _SaveMesh->Vertices.size(); ++i)
|
||||
{
|
||||
_float3 pos = _SaveMesh->Vertices[i].Pos;
|
||||
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(_SaveMesh, PreTransformMatrix) :
|
||||
Ready_VertexBuffer_For_Anim(pModel, _SaveMesh);
|
||||
|
||||
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;
|
||||
|
||||
|
||||
D3D11_SUBRESOURCE_DATA InitialIBData{};
|
||||
InitialIBData.pSysMem = _SaveMesh->Indices.data();
|
||||
|
||||
if (FAILED(m_pDevice->CreateBuffer(&IBDesc, &InitialIBData, &m_pIB)))
|
||||
return E_FAIL;
|
||||
|
||||
#pragma endregion
|
||||
|
||||
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CMesh::Ready_VertexBuffer_For_NonAnim(HANDLE hFile, DWORD& dwByte)
|
||||
{
|
||||
D3D11_BUFFER_DESC VBDesc{};
|
||||
@@ -254,6 +318,165 @@ HRESULT CMesh::Ready_VertexBuffer_For_Anim(HANDLE hFile, DWORD& dwByte)
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CMesh::Ready_VertexBuffer_For_NonAnim(SaveMesh* _SaveMesh, _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, &_SaveMesh->Vertices[i].Pos, sizeof(_float3));
|
||||
XMStoreFloat3(&pVertices[i].vPosition,
|
||||
XMVector3TransformCoord(XMLoadFloat3(&pVertices[i].vPosition), PreTransformMatrix));
|
||||
|
||||
memcpy(&pVertices[i].vNormal, &_SaveMesh->Vertices[i].Normal, sizeof(_float3));
|
||||
XMStoreFloat3(&pVertices[i].vNormal,
|
||||
XMVector3Normalize(XMVector3TransformNormal(XMLoadFloat3(&pVertices[i].vNormal), PreTransformMatrix)));
|
||||
|
||||
memcpy(&pVertices[i].vTangent, &_SaveMesh->Vertices[i].Tan, sizeof(_float3));
|
||||
XMStoreFloat3(&pVertices[i].vTangent,
|
||||
XMVector3Normalize(XMVector3TransformNormal(XMLoadFloat3(&pVertices[i].vTangent), PreTransformMatrix)));
|
||||
|
||||
memcpy(&pVertices[i].vBinormal, &_SaveMesh->Vertices[i].BiNoraml, sizeof(_float3));
|
||||
XMStoreFloat3(&pVertices[i].vBinormal,
|
||||
XMVector3Normalize(XMVector3TransformNormal(XMLoadFloat3(&pVertices[i].vBinormal), PreTransformMatrix)));
|
||||
|
||||
pVertices[i].vTexcoord = _SaveMesh->Vertices[i].UV;
|
||||
}
|
||||
|
||||
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, SaveMesh* _SaveMesh)
|
||||
{
|
||||
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, &_SaveMesh->Vertices[i].Pos, sizeof(_float3));
|
||||
if (_SaveMesh->Vertices[i].bHasNormal)
|
||||
memcpy(&pVertices[i].vNormal, &_SaveMesh->Vertices[i].Normal, sizeof(_float3));
|
||||
else
|
||||
pVertices[i].vNormal = _float3(0.f, 1.f, 0.f);
|
||||
if (_SaveMesh->Vertices[i].bHasTan)
|
||||
memcpy(&pVertices[i].vTangent, &_SaveMesh->Vertices[i].Tan, sizeof(_float3));
|
||||
else
|
||||
pVertices[i].vTangent = _float3(1.f, 0.f, 0.f);
|
||||
|
||||
memcpy(&pVertices[i].vBinormal, &_SaveMesh->Vertices[i].BiNoraml, sizeof(_float3));
|
||||
|
||||
if (_SaveMesh->Vertices[i].bHasUV)
|
||||
memcpy(&pVertices[i].vTexcoord, &_SaveMesh->Vertices[i].UV, sizeof(_float2));
|
||||
else
|
||||
pVertices[i].vTexcoord = _float2(0.f, 0.f);
|
||||
}
|
||||
|
||||
m_iNumBones = (_uint)_SaveMesh->Bones.size();
|
||||
|
||||
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++)
|
||||
{
|
||||
SaveBone _SaveBone = _SaveMesh->Bones[i];
|
||||
strcpy_s(m_szName, _SaveBone.Name);
|
||||
|
||||
memcpy(&OffsetMatrix, &_SaveBone.OffsetMatrix, sizeof(_float4x4));
|
||||
|
||||
_int iBoneIndex = pModel->Get_BoneIndex(_SaveBone.Name);
|
||||
|
||||
if (-1 == iBoneIndex)
|
||||
return E_FAIL;
|
||||
|
||||
m_BoneIndices.push_back(iBoneIndex);
|
||||
m_offsetMatrices.push_back(OffsetMatrix);
|
||||
|
||||
|
||||
for (_uint j = 0; j < _SaveBone.Weights.size(); j++)
|
||||
{
|
||||
SaveBoneWeight _SaveBoneWeight = _SaveBone.Weights[j];
|
||||
|
||||
if (0.f == pVertices[_SaveBoneWeight.VertexId].vBlendWeight.x)
|
||||
{
|
||||
pVertices[_SaveBoneWeight.VertexId].vBlendIndex.x = i;
|
||||
pVertices[_SaveBoneWeight.VertexId].vBlendWeight.x = _SaveBoneWeight.Weight;
|
||||
}
|
||||
else if (0.f == pVertices[_SaveBoneWeight.VertexId].vBlendWeight.y)
|
||||
{
|
||||
pVertices[_SaveBoneWeight.VertexId].vBlendIndex.y = i;
|
||||
pVertices[_SaveBoneWeight.VertexId].vBlendWeight.y = _SaveBoneWeight.Weight;
|
||||
}
|
||||
else if (0.f == pVertices[_SaveBoneWeight.VertexId].vBlendWeight.z)
|
||||
{
|
||||
pVertices[_SaveBoneWeight.VertexId].vBlendIndex.z = i;
|
||||
pVertices[_SaveBoneWeight.VertexId].vBlendWeight.z = _SaveBoneWeight.Weight;
|
||||
}
|
||||
else
|
||||
{
|
||||
pVertices[_SaveBoneWeight.VertexId].vBlendIndex.w = i;
|
||||
pVertices[_SaveBoneWeight.VertexId].vBlendWeight.w = _SaveBoneWeight.Weight;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
HRESULT CMesh::Initialize(void* pArg)
|
||||
{
|
||||
return S_OK;
|
||||
@@ -491,6 +714,19 @@ CMesh* CMesh::Create(ID3D11Device* pDevice, ID3D11DeviceContext* pContext, HANDL
|
||||
return pInstance;
|
||||
}
|
||||
|
||||
CMesh* CMesh::Create(ID3D11Device* pDevice, ID3D11DeviceContext* pContext, MODEL eType, const CModel* pModel, SaveMesh* _SaveMesh, _fmatrix PreTransformMatrix)
|
||||
{
|
||||
CMesh* pInstance = new CMesh(pDevice, pContext);
|
||||
|
||||
if (FAILED(pInstance->Initialize_Prototype(eType, pModel, _SaveMesh, PreTransformMatrix)))
|
||||
{
|
||||
MSG_BOX("Failed to Created : CMesh");
|
||||
Safe_Release(pInstance);
|
||||
}
|
||||
|
||||
return pInstance;
|
||||
}
|
||||
|
||||
CMesh* CMesh::Clone(void* pArg, class CGameObject* pOwner)
|
||||
{
|
||||
CMesh* pInstance = new CMesh(*this);
|
||||
|
||||
Reference in New Issue
Block a user