[add] 모델 기초 렌더링
This commit is contained in:
@@ -42,7 +42,7 @@
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<PlatformToolset>v145</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
<EnableASAN>true</EnableASAN>
|
||||
</PropertyGroup>
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
After Width: | Height: | Size: 296 B |
Binary file not shown.
Binary file not shown.
|
After Width: | Height: | Size: 285 B |
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
After Width: | Height: | Size: 245 B |
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
After Width: | Height: | Size: 367 B |
Binary file not shown.
Binary file not shown.
|
After Width: | Height: | Size: 2.2 KiB |
@@ -334,8 +334,8 @@ technique11 MeshTechnique11
|
||||
|
||||
pass SkyBoxPass // 2
|
||||
{
|
||||
SetRasterizerState(RS_Nocull);
|
||||
SetDepthStencilState(DSS_None, 0);
|
||||
SetRasterizerState(RS_Default);
|
||||
SetDepthStencilState(DSS_Default, 0);
|
||||
SetBlendState(BS_None, float4(0.f, 0.f, 0.f, 0.f), 0xffffffff);
|
||||
VertexShader = compile vs_5_0 VS_MAIN();
|
||||
GeometryShader = NULL;
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<PlatformToolset>v145</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
<EnableASAN>true</EnableASAN>
|
||||
</PropertyGroup>
|
||||
@@ -150,6 +150,7 @@
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\Public\DebugCamera.h" />
|
||||
<ClInclude Include="..\Public\Dummy_Cube.h" />
|
||||
<ClInclude Include="..\Public\Dummy_Goblin.h" />
|
||||
<ClInclude Include="..\Public\Editor_Define.h" />
|
||||
<ClInclude Include="..\Public\Editor_Macro.h" />
|
||||
@@ -166,6 +167,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\Private\DebugCamera.cpp" />
|
||||
<ClCompile Include="..\Private\Dummy_Cube.cpp" />
|
||||
<ClCompile Include="..\Private\Dummy_Goblin.cpp" />
|
||||
<ClCompile Include="..\Private\Level_Loading.cpp" />
|
||||
<ClCompile Include="..\Private\Level_Logo.cpp" />
|
||||
|
||||
@@ -105,6 +105,9 @@
|
||||
<ClInclude Include="..\Public\Level_ObjectViewer.h">
|
||||
<Filter>01.Level\20.ObjectViewer</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\Public\Dummy_Cube.h">
|
||||
<Filter>02.GameObjects\Dummys\DummyCube</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Image Include="Editor.ico">
|
||||
@@ -142,6 +145,9 @@
|
||||
<ClCompile Include="..\Private\Level_ObjectViewer.cpp">
|
||||
<Filter>01.Level\20.ObjectViewer</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\Private\Dummy_Cube.cpp">
|
||||
<Filter>02.GameObjects\Dummys\DummyCube</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="Editor.rc">
|
||||
|
||||
@@ -0,0 +1,158 @@
|
||||
#include "pch.h"
|
||||
#include "Dummy_Cube.h"
|
||||
|
||||
#include "GameInstance.h"
|
||||
|
||||
|
||||
CDummy_Cube::CDummy_Cube(ID3D11Device* pDevice, ID3D11DeviceContext* pContext)
|
||||
: CGameObject{ pDevice, pContext }
|
||||
{
|
||||
}
|
||||
|
||||
CDummy_Cube::CDummy_Cube(const CDummy_Cube& rhs)
|
||||
: CGameObject(rhs)
|
||||
{
|
||||
}
|
||||
|
||||
HRESULT CDummy_Cube::Initialize_Prototype()
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CDummy_Cube::Initialize(void* pArg)
|
||||
{
|
||||
if (FAILED(__super::Initialize(pArg)))
|
||||
return E_FAIL;
|
||||
|
||||
if (FAILED(Ready_Components(pArg)))
|
||||
return E_FAIL;
|
||||
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
void CDummy_Cube::Priority_Update(_float fTimeDelta)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CDummy_Cube::Update(_float fTimeDelta)
|
||||
{
|
||||
}
|
||||
|
||||
void CDummy_Cube::Late_Update(_float fTimeDelta)
|
||||
{
|
||||
_float4* vPos = (_float4*)(m_pTransformCom->Get_WorldMatrixPtr()->m[3]);
|
||||
m_pGameInstance->Add_RenderGroup(RENDER::NONBLEND, this, *vPos, m_pTransformCom->Get_Radius());
|
||||
}
|
||||
|
||||
HRESULT CDummy_Cube::Render()
|
||||
{
|
||||
if (FAILED(Bind_ShaderResources())) {
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
|
||||
_uint iNumMeshes = m_pModelCom->Get_NumMeshes();
|
||||
|
||||
for (_uint i = 0; i < iNumMeshes; i++)
|
||||
{
|
||||
if (FAILED(m_pModelCom->Bind_Material(i, m_pShaderCom, "g_DiffuseTexture", aiTextureType_DIFFUSE, 0))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
if (FAILED(m_pModelCom->Bind_Material(i, m_pShaderCom, "g_NormalTexture", aiTextureType_NORMALS, 0))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
if (FAILED(m_pShaderCom->Begin(ENUM_CLASS(SHADER_PASS_MESH::SKYBOX)))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
if (FAILED(m_pModelCom->Render(i))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CDummy_Cube::Ready_Components(void* pArg)
|
||||
{
|
||||
if (FAILED(__super::Ready_Components(pArg))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
///* Com_Model */
|
||||
//if (FAILED(__super::Add_Asset_Component(g_iStaticLevel, TEXT("Prototype_Component_GoblinBody_Model"),
|
||||
// reinterpret_cast<CComponent**>(&m_pModelCom))))
|
||||
// return E_FAIL;
|
||||
|
||||
/* Com_Model */
|
||||
if (FAILED(__super::Add_Asset_Component(g_iStaticLevel, TEXT("Desc_Box"),
|
||||
reinterpret_cast<CComponent**>(&m_pModelCom))))
|
||||
return E_FAIL;
|
||||
|
||||
/* Com_Shader */
|
||||
if (FAILED(__super::Add_Asset_Component(g_iStaticLevel, FX_MESH,
|
||||
reinterpret_cast<CComponent**>(&m_pShaderCom))))
|
||||
return E_FAIL;
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CDummy_Cube::Bind_ShaderResources()
|
||||
{
|
||||
if (FAILED(m_pTransformCom->Bind_ShaderResource(m_pShaderCom, "g_WorldMatrix"))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
if (FAILED(m_pShaderCom->Bind_Matrix("g_ViewMatrix", m_pGameInstance->Get_Transform_Float4x4(D3DTS::VIEW)))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
if (FAILED(m_pShaderCom->Bind_Matrix("g_ProjMatrix", m_pGameInstance->Get_Transform_Float4x4(D3DTS::PROJ)))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
if (FAILED(m_pShaderCom->Bind_RawValue("g_fFar", m_pGameInstance->Get_CurrentCameraFar(), sizeof(_float)))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
CDummy_Cube* CDummy_Cube::Create(ID3D11Device* pDevice, ID3D11DeviceContext* pContext)
|
||||
{
|
||||
CDummy_Cube* pInstance = new CDummy_Cube(pDevice, pContext);
|
||||
|
||||
if (FAILED(pInstance->Initialize_Prototype()))
|
||||
{
|
||||
MSG_BOX("Failed to Created : CDummy_Cube");
|
||||
SAFE_RELEASE(pInstance);
|
||||
}
|
||||
|
||||
return pInstance;
|
||||
}
|
||||
|
||||
CGameObject* CDummy_Cube::Clone(void* pArg, CGameObject* pOwner)
|
||||
{
|
||||
CDummy_Cube* pInstance = new CDummy_Cube(*this);
|
||||
pInstance->m_pOwner = pOwner;
|
||||
if (FAILED(pInstance->Initialize(pArg)))
|
||||
{
|
||||
MSG_BOX("Failed to Cloned : CDummy_Cube");
|
||||
SAFE_RELEASE(pInstance);
|
||||
}
|
||||
|
||||
return pInstance;
|
||||
}
|
||||
|
||||
void CDummy_Cube::Free()
|
||||
{
|
||||
__super::Free();
|
||||
|
||||
SAFE_RELEASE(m_pModelCom);
|
||||
SAFE_RELEASE(m_pShaderCom);
|
||||
}
|
||||
|
||||
void CDummy_Cube::Describe_Entity()
|
||||
{
|
||||
}
|
||||
@@ -38,8 +38,6 @@ void CDummy_Goblin::Priority_Update(_float fTimeDelta)
|
||||
|
||||
void CDummy_Goblin::Update(_float fTimeDelta)
|
||||
{
|
||||
m_pModelCom->Set_AnimationIndex(0);
|
||||
|
||||
m_pModelCom->Play_Animation(fTimeDelta);
|
||||
}
|
||||
|
||||
@@ -52,24 +50,33 @@ void CDummy_Goblin::Late_Update(_float fTimeDelta)
|
||||
|
||||
HRESULT CDummy_Goblin::Render()
|
||||
{
|
||||
if (FAILED(Bind_ShaderResources()))
|
||||
if (FAILED(Bind_ShaderResources())) {
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
_uint iNumMeshes = m_pModelCom->Get_NumMeshes();
|
||||
|
||||
//m_pShaderCom->Bind_SRV("g_NormalTexture", nullptr);
|
||||
for (_uint i = 0; i < iNumMeshes; i++)
|
||||
{
|
||||
//if (FAILED(m_pModelCom->Bind_BoneMatrices(i, m_pShaderCom, "g_BoneMatrices")))
|
||||
// return E_FAIL;
|
||||
|
||||
if (FAILED(m_pModelCom->Bind_Material(i, m_pShaderCom, "g_DiffuseTexture", aiTextureType_DIFFUSE, 0)))
|
||||
if (FAILED(m_pModelCom->Bind_BoneMatrices(i, m_pShaderCom, "g_BoneMatrices"))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
if (FAILED(m_pShaderCom->Begin(0)))
|
||||
if (FAILED(m_pModelCom->Bind_Material(i, m_pShaderCom, "g_DiffuseTexture", aiTextureType_DIFFUSE, 0))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
if (FAILED(m_pModelCom->Bind_Material(i, m_pShaderCom, "g_NormalTexture", aiTextureType_NORMALS, 0))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
if (FAILED(m_pModelCom->Render(i)))
|
||||
if (FAILED(m_pShaderCom->Begin(ENUM_CLASS(SHADER_PASS_ANIM::DEFAULT)))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
if (FAILED(m_pModelCom->Render(i))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
@@ -80,43 +87,50 @@ HRESULT CDummy_Goblin::Ready_Components()
|
||||
__super::Ready_Components(nullptr);
|
||||
|
||||
/* Com_Model */
|
||||
if (FAILED(__super::Add_Asset_Component(ENUM_CLASS(LEVEL::OBJECT), TEXT("Prototype_Component_GoblinBody_Model"),
|
||||
if (FAILED(__super::Add_Asset_Component(g_iStaticLevel, TEXT("Prototype_Component_GoblinBody_Model"),
|
||||
reinterpret_cast<CComponent**>(&m_pModelCom))))
|
||||
return E_FAIL;
|
||||
|
||||
/* Com_Shader */
|
||||
if (FAILED(__super::Add_Asset_Component(ENUM_CLASS(LEVEL::STATIC), FX_MESH,
|
||||
if (FAILED(__super::Add_Asset_Component(g_iStaticLevel, FX_ANIMMESH,
|
||||
reinterpret_cast<CComponent**>(&m_pShaderCom))))
|
||||
return E_FAIL;
|
||||
|
||||
CDebugCamera::CAMERA_DEBUG_DESC CameraDesc{};
|
||||
CameraDesc.fFovy = XMConvertToRadians(60.0f);
|
||||
CameraDesc.fNear = 0.1f;
|
||||
CameraDesc.fFar = 500.f;
|
||||
CameraDesc.vEye = _float3(0.f, 10.f, -10.f);
|
||||
CameraDesc.vAt = _float3(0.f, 0.f, 0.f);
|
||||
CameraDesc.fSpeedPerSec = 5.f;
|
||||
CameraDesc.fRotationPerSec = XMConvertToRadians(90.0f);
|
||||
CameraDesc.fMouseSensor = 0.1f;
|
||||
CameraDesc.pFollowTarget = this;
|
||||
CameraDesc.pLookTarget = this;
|
||||
|
||||
if (FAILED(m_pGameInstance->Add_GameObject_ToLayer<CDebugCamera>(ENUM_CLASS(LEVEL::STATIC), ENUM_CLASS(LEVEL::OBJECT),
|
||||
TEXT("Layer_Camera"), &CameraDesc)))
|
||||
return E_FAIL;
|
||||
m_pModelCom->Change_AnimationIndex(0, true, 0.4f, true);
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CDummy_Goblin::Bind_ShaderResources()
|
||||
{
|
||||
if (FAILED(m_pTransformCom->Bind_ShaderResource(m_pShaderCom, "g_WorldMatrix")))
|
||||
if (FAILED(m_pTransformCom->Bind_ShaderResource(m_pShaderCom, "g_WorldMatrix"))){
|
||||
return E_FAIL;
|
||||
if (FAILED(m_pShaderCom->Bind_Matrix("g_ViewMatrix", m_pGameInstance->Get_Transform_Float4x4(D3DTS::VIEW))))
|
||||
}
|
||||
if (FAILED(m_pShaderCom->Bind_Matrix("g_ViewMatrix", m_pGameInstance->Get_Transform_Float4x4(D3DTS::VIEW)))){
|
||||
return E_FAIL;
|
||||
if (FAILED(m_pShaderCom->Bind_Matrix("g_ProjMatrix", m_pGameInstance->Get_Transform_Float4x4(D3DTS::PROJ))))
|
||||
}
|
||||
if (FAILED(m_pShaderCom->Bind_Matrix("g_ProjMatrix", m_pGameInstance->Get_Transform_Float4x4(D3DTS::PROJ)))){
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
if (FAILED(m_pShaderCom->Bind_RawValue("g_fFar", m_pGameInstance->Get_CurrentCameraFar(), sizeof(_float)))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
//if (FAILED(m_pShaderCom->Bind_RawValue("g_vCamPosition", m_pGameInstance->Get_CamPosition(), sizeof(_float4)))) {
|
||||
// return E_FAIL;
|
||||
//}
|
||||
//if (FAILED(m_pShaderCom->Bind_RawValue("g_bRimLight", &m_bRimLight, sizeof(_bool)))) {
|
||||
// return E_FAIL;
|
||||
//}
|
||||
//if (FAILED(m_pShaderCom->Bind_RawValue("g_fRimStrength", &m_fRimLightStrength, sizeof(_float)))) {
|
||||
// return E_FAIL;
|
||||
//}
|
||||
//if (FAILED(m_pShaderCom->Bind_RawValue("g_fRimPower", &m_fRimLightPower, sizeof(_float)))) {
|
||||
// return E_FAIL;
|
||||
//}
|
||||
//if (FAILED(m_pShaderCom->Bind_RawValue("g_vRimColor", &m_vRimLightColor, sizeof(_float3)))) {
|
||||
// return E_FAIL;
|
||||
//}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ HRESULT CLevel_Loading::Initialize(LEVEL eNextLevelID)
|
||||
void CLevel_Loading::Update(_float fTimeDelta)
|
||||
{
|
||||
if (true == m_pLoader->isFinished() &&
|
||||
m_pGameInstance->Key_Down(DIK_RETURN))
|
||||
m_pGameInstance->Key_Down(DIK_F1))
|
||||
{
|
||||
CLevel* pNewLevel = { nullptr };
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "GameInstance.h"
|
||||
#include "Level_Loading.h"
|
||||
#include "Dummy_Goblin.h"
|
||||
#include "Dummy_Cube.h"
|
||||
#include "DebugCamera.h"
|
||||
|
||||
CLevel_ObjectViewer::CLevel_ObjectViewer(ID3D11Device* pDevice, ID3D11DeviceContext* pContext, LEVEL eLevelID)
|
||||
@@ -13,7 +14,9 @@ CLevel_ObjectViewer::CLevel_ObjectViewer(ID3D11Device* pDevice, ID3D11DeviceCont
|
||||
|
||||
HRESULT CLevel_ObjectViewer::Initialize()
|
||||
{
|
||||
|
||||
if (FAILED(Ready_Layer_Light())) {
|
||||
return E_FAIL;
|
||||
}
|
||||
if (FAILED(Ready_Layer_Camera(TEXT("Layer_Camera"))))
|
||||
{
|
||||
return E_FAIL;
|
||||
@@ -45,23 +48,39 @@ HRESULT CLevel_ObjectViewer::Render()
|
||||
|
||||
HRESULT CLevel_ObjectViewer::Ready_Layer_Camera(const _wstring& strLayerTag)
|
||||
{
|
||||
//CDebugCamera::CAMERA_DEBUG_DESC CameraDesc{};
|
||||
//CameraDesc.fFovy = XMConvertToRadians(60.0f);
|
||||
//CameraDesc.fNear = 0.1f;
|
||||
//CameraDesc.fFar = 500.f;
|
||||
//CameraDesc.vEye = _float3(0.f, 10.f, -10.f);
|
||||
//CameraDesc.vAt = _float3(0.f, 0.f, 0.f);
|
||||
//CameraDesc.fSpeedPerSec = 5.f;
|
||||
//CameraDesc.fRotationPerSec = XMConvertToRadians(90.0f);
|
||||
//CameraDesc.fMouseSensor = 0.1f;
|
||||
CDebugCamera::CAMERA_DEBUG_DESC CameraDesc{};
|
||||
CameraDesc.fFovy = XMConvertToRadians(60.0f);
|
||||
CameraDesc.fNear = 0.1f;
|
||||
CameraDesc.fFar = 500.f;
|
||||
CameraDesc.vEye = _float3(0.f, 10.f, -10.f);
|
||||
CameraDesc.vAt = _float3(0.f, 0.f, 0.f);
|
||||
CameraDesc.fSpeedPerSec = 5.f;
|
||||
CameraDesc.fRotationPerSec = XMConvertToRadians(90.0f);
|
||||
CameraDesc.fMouseSensor = 0.1f;
|
||||
|
||||
//if (FAILED(m_pGameInstance->Add_GameObject_ToLayer<CDebugCamera>(ENUM_CLASS(LEVEL::STATIC),ENUM_CLASS(LEVEL::OBJECT),
|
||||
// strLayerTag, &CameraDesc)))
|
||||
// return E_FAIL;
|
||||
if (FAILED(m_pGameInstance->Add_GameObject_ToLayer<CDebugCamera>(g_iStaticLevel, NEXT_LEVEL,
|
||||
strLayerTag, &CameraDesc)))
|
||||
return E_FAIL;
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CLevel_ObjectViewer::Ready_Layer_Light()
|
||||
{
|
||||
LIGHT_DESC LightDesc{};
|
||||
|
||||
LightDesc.eType = LIGHT::DIRECTIONAL;
|
||||
LightDesc.vDiffuse = _float4(0.8f, 0.8f, 0.8f, 0.f);
|
||||
LightDesc.vAmbient = _float4(0.2f, 0.2f, 0.2f, 0.f);
|
||||
LightDesc.vSpecular = _float4(0.f, 0.f, 0.f, 0.f);
|
||||
LightDesc.vDirection = _float4(1.f, -1.f, 1.f, 0.f);
|
||||
|
||||
if (FAILED(m_pGameInstance->On_Light(NEXT_LEVEL, TEXT("Main_Light"), LightDesc, nullptr))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CLevel_ObjectViewer::Ready_Layer_UI(const _wstring& strLayerTag)
|
||||
{
|
||||
return S_OK;
|
||||
@@ -69,7 +88,10 @@ HRESULT CLevel_ObjectViewer::Ready_Layer_UI(const _wstring& strLayerTag)
|
||||
|
||||
HRESULT CLevel_ObjectViewer::Ready_Layer_Dummy(const _wstring& strLayerTag)
|
||||
{
|
||||
if (FAILED(m_pGameInstance->Add_GameObject_ToLayer<CDummy_Goblin>(ENUM_CLASS(LEVEL::OBJECT), ENUM_CLASS(LEVEL::OBJECT), TEXT("Layer_Dummy"))))
|
||||
if (FAILED(m_pGameInstance->Add_GameObject_ToLayer<CDummy_Goblin>(g_iStaticLevel, NEXT_LEVEL, LAYER_MONSTER)))
|
||||
return E_FAIL;
|
||||
|
||||
if (FAILED(m_pGameInstance->Add_GameObject_ToLayer<CDummy_Cube>(g_iStaticLevel, NEXT_LEVEL, LAYER_CUBE)))
|
||||
return E_FAIL;
|
||||
|
||||
return S_OK;
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "GameInstance.h"
|
||||
#include "MainApp.h"
|
||||
#include "Dummy_Goblin.h"
|
||||
#include "Dummy_Cube.h"
|
||||
|
||||
CLoader::CLoader(ID3D11Device* pDevice, ID3D11DeviceContext* pContext)
|
||||
: m_pDevice{ pDevice }
|
||||
@@ -147,10 +148,13 @@ HRESULT CLoader::Loading_For_ObjectViewer()
|
||||
m_strMessage = TEXT("텍스쳐를(을) 로딩 중 입니다.");
|
||||
|
||||
m_strMessage = TEXT("모델를(을) 로딩 중 입니다.");
|
||||
|
||||
/* For.Prototype_Component_GoblinBody_Model */
|
||||
if (FAILED(m_pGameInstance->Add_Asset_Prototype(ENUM_CLASS(LEVEL::OBJECT), TEXT("Prototype_Component_GoblinBody_Model"),
|
||||
CModel::Create(m_pDevice, m_pContext, MODEL::NONANIM, "../Bin/Resources/Models/Sword/Sword.fbx"))))
|
||||
|
||||
if (FAILED(m_pGameInstance->Add_Asset_Prototype(g_iStaticLevel, TEXT("Prototype_Component_GoblinBody_Model"),
|
||||
CModel::Create(m_pDevice, m_pContext, "../Bin/Resources/Models/Goblin/GoblinBody.fbx", MODEL::ANIM, XMMatrixScaling(0.01f, 0.01f, 0.01f) * XMMatrixIdentity(), 0))))
|
||||
return E_FAIL;
|
||||
|
||||
if (FAILED(m_pGameInstance->Add_Asset_Prototype(g_iStaticLevel, TEXT("Desc_Box"),
|
||||
CModel::Create(m_pDevice, m_pContext, "../Bin/Resources/Models/Box/Box.fbx", MODEL::NONANIM, XMMatrixIdentity(), 0))))
|
||||
return E_FAIL;
|
||||
|
||||
m_strMessage = TEXT("셰이더를(을) 로딩 중 입니다.");
|
||||
@@ -160,7 +164,11 @@ HRESULT CLoader::Loading_For_ObjectViewer()
|
||||
m_strMessage = TEXT("객체원형를(을) 로딩 중 입니다.");
|
||||
|
||||
/* For.Prototype_GameObject_Dummy_Goblin */
|
||||
if (FAILED(m_pGameInstance->Add_Prototype<CDummy_Goblin>(ENUM_CLASS(LEVEL::OBJECT), CDummy_Goblin::Create(m_pDevice, m_pContext))))
|
||||
if (FAILED(m_pGameInstance->Add_Prototype<CDummy_Goblin>(g_iStaticLevel, CDummy_Goblin::Create(m_pDevice, m_pContext))))
|
||||
return E_FAIL;
|
||||
|
||||
/* For.Prototype_GameObject_Dummy_Cube */
|
||||
if (FAILED(m_pGameInstance->Add_Prototype<CDummy_Cube>(g_iStaticLevel, CDummy_Cube::Create(m_pDevice, m_pContext))))
|
||||
return E_FAIL;
|
||||
|
||||
m_strMessage = TEXT("정보를 불러오는 중입니다.");
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
#pragma once
|
||||
|
||||
#include "Editor_Define.h"
|
||||
#include "GameObject.h"
|
||||
|
||||
NS_BEGIN(Engine)
|
||||
class CModel;
|
||||
class CShader;
|
||||
NS_END
|
||||
|
||||
NS_BEGIN(Editor)
|
||||
|
||||
class CDummy_Cube final : public CGameObject
|
||||
{
|
||||
private:
|
||||
CDummy_Cube(ID3D11Device* pDevice, ID3D11DeviceContext* pContext);
|
||||
CDummy_Cube(const CDummy_Cube& rhs);
|
||||
virtual ~CDummy_Cube() = default;
|
||||
|
||||
public:
|
||||
virtual void Priority_Update(_float fTimeDelta) override;
|
||||
virtual void Update(_float fTimeDelta) override;
|
||||
virtual void Late_Update(_float fTimeDelta) override;
|
||||
virtual HRESULT Render() override;
|
||||
|
||||
private:
|
||||
CModel* m_pModelCom = { nullptr };
|
||||
CShader* m_pShaderCom = { nullptr };
|
||||
|
||||
|
||||
private:
|
||||
virtual HRESULT Initialize_Prototype() override;
|
||||
virtual HRESULT Initialize(void* pArg) override;
|
||||
virtual HRESULT Ready_Components(void* pArg) override;
|
||||
virtual HRESULT Bind_ShaderResources() override;
|
||||
|
||||
public:
|
||||
static CDummy_Cube* Create(ID3D11Device* pDevice, ID3D11DeviceContext* pContext);
|
||||
virtual CGameObject* Clone(void* pArg, class CGameObject* pOwner) override;
|
||||
virtual void Free() override;
|
||||
void Describe_Entity() override;
|
||||
};
|
||||
|
||||
NS_END
|
||||
@@ -28,7 +28,10 @@ class CDummy_Goblin final : public CGameObject
|
||||
private:
|
||||
CShader* m_pShaderCom = { nullptr };
|
||||
CModel* m_pModelCom = { nullptr };
|
||||
|
||||
_bool m_bRimLight = { true };
|
||||
_float m_fRimLightPower = { 3.2f };
|
||||
_float m_fRimLightStrength = { 3.04f };
|
||||
_float3 m_vRimLightColor = { 69.f / 255.f, 5.f / 255.f, 10.f / 255.f };
|
||||
|
||||
private:
|
||||
HRESULT Ready_Components();
|
||||
|
||||
@@ -19,6 +19,7 @@ class CLevel_ObjectViewer final : public CLevel
|
||||
/* 이 레벨에서 쓰기위한 객체들을 생성한다. */
|
||||
virtual HRESULT Initialize() override;
|
||||
HRESULT Ready_Layer_Camera(const _wstring& strLayerTag);
|
||||
HRESULT Ready_Layer_Light();
|
||||
HRESULT Ready_Layer_UI(const _wstring& strLayerTag);
|
||||
HRESULT Ready_Layer_Dummy(const _wstring& strLayerTag);
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<PlatformToolset>v145</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
<EnableASAN>true</EnableASAN>
|
||||
</PropertyGroup>
|
||||
@@ -229,6 +229,7 @@
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\Private\Key_Manager.cpp" />
|
||||
<ClCompile Include="..\Private\Layer.cpp" />
|
||||
<ClCompile Include="..\Private\LerpAnim.cpp" />
|
||||
<ClCompile Include="..\Private\Level.cpp" />
|
||||
<ClCompile Include="..\Private\Level_Manager.cpp" />
|
||||
<ClCompile Include="..\Private\Light.cpp" />
|
||||
@@ -258,6 +259,7 @@
|
||||
<ClCompile Include="..\Private\Transform.cpp" />
|
||||
<ClCompile Include="..\Private\VIBuffer.cpp" />
|
||||
<ClCompile Include="..\Private\VIBuffer_Cell.cpp" />
|
||||
<ClCompile Include="..\Private\VIBuffer_Cube.cpp" />
|
||||
<ClCompile Include="..\Private\VIBuffer_Rect.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
@@ -426,6 +428,7 @@
|
||||
<ClInclude Include="..\Public\IMGUI\imstb_truetype.h" />
|
||||
<ClInclude Include="..\Public\Key_Manager.h" />
|
||||
<ClInclude Include="..\Public\Layer.h" />
|
||||
<ClInclude Include="..\Public\LerpAnim.h" />
|
||||
<ClInclude Include="..\Public\Level.h" />
|
||||
<ClInclude Include="..\Public\Level_Manager.h" />
|
||||
<ClInclude Include="..\Public\Light.h" />
|
||||
@@ -452,6 +455,7 @@
|
||||
<ClInclude Include="..\Public\Transform.h" />
|
||||
<ClInclude Include="..\Public\VIBuffer.h" />
|
||||
<ClInclude Include="..\Public\VIBuffer_Cell.h" />
|
||||
<ClInclude Include="..\Public\VIBuffer_Cube.h" />
|
||||
<ClInclude Include="..\Public\VIBuffer_Rect.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
||||
@@ -205,6 +205,12 @@
|
||||
<Filter Include="02.Element\02.Component\06.Model\Animation\Channel">
|
||||
<UniqueIdentifier>{3625aad6-89b2-490e-bd9c-3cff284605e4}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="02.Element\02.Component\06.Model\LerpAnim">
|
||||
<UniqueIdentifier>{92ec7ae6-14ee-455c-a3ad-378e46f3b1f0}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="02.Element\02.Component\02.VIBuffer\Cube">
|
||||
<UniqueIdentifier>{be0d499e-e4cf-4dde-92a0-a0904e713045}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\Private\Base.cpp">
|
||||
@@ -372,6 +378,12 @@
|
||||
<ClCompile Include="..\Private\Channel.cpp">
|
||||
<Filter>02.Element\02.Component\06.Model\Animation\Channel</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\Private\LerpAnim.cpp">
|
||||
<Filter>02.Element\02.Component\06.Model\LerpAnim</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\Private\VIBuffer_Cube.cpp">
|
||||
<Filter>02.Element\02.Component\02.VIBuffer\Cube</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\Public\Base.h">
|
||||
@@ -905,6 +917,12 @@
|
||||
<ClInclude Include="..\Public\Channel.h">
|
||||
<Filter>02.Element\02.Component\06.Model\Animation\Channel</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\Public\LerpAnim.h">
|
||||
<Filter>02.Element\02.Component\06.Model\LerpAnim</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\Public\VIBuffer_Cube.h">
|
||||
<Filter>02.Element\02.Component\02.VIBuffer\Cube</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\Public\Assimp\color4.inl">
|
||||
|
||||
@@ -1,134 +1,205 @@
|
||||
#include "pch.h"
|
||||
|
||||
#include "Animation.h"
|
||||
#include "Channel.h"
|
||||
#include "Model.h"
|
||||
#include "Bone.h"
|
||||
|
||||
CAnimation::CAnimation()
|
||||
{
|
||||
/*XMMatrixDecompose();*/
|
||||
}
|
||||
|
||||
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 }
|
||||
CAnimation::CAnimation(const CAnimation& rhs)
|
||||
: m_fCurrentTrackPosition{ rhs.m_fCurrentTrackPosition }
|
||||
, m_fDuration{ rhs.m_fDuration }
|
||||
, m_iNumChannels{ rhs.m_iNumChannels }
|
||||
, m_Channels{ rhs.m_Channels }
|
||||
, m_CurrentKeyFrameIndices{ rhs.m_CurrentKeyFrameIndices }
|
||||
, m_StartKeyFrames{ rhs.m_StartKeyFrames }
|
||||
, m_DestBones{ rhs.m_DestBones }
|
||||
, m_strName{ rhs.m_strName }
|
||||
{
|
||||
for (auto& pChannel : m_Channels)
|
||||
Safe_AddRef(pChannel);
|
||||
memcpy_s(m_TickPerSeconds, sizeof(_float) * 2, rhs.m_TickPerSeconds, sizeof(_float) * 2);
|
||||
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
for (auto& pChannel : m_Channels) {
|
||||
SAFE_ADDREF(pChannel);
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
_bool CAnimation::Update_TransformationMatrices(_float fTimeDelta, _bool isLoop, vector<CBone*>& Bones)
|
||||
_bool CAnimation::Update_TransformationMatrices(const vector<class CBone*>& Bones, _bool bIsLoop, _float fTimeDelta)
|
||||
{
|
||||
m_fCurrentTrackPosition += m_fTickPerSecond * fTimeDelta;
|
||||
m_fCurrentTrackPosition += m_TickPerSeconds[m_bPause] * fTimeDelta;
|
||||
|
||||
if (m_fCurrentTrackPosition >= m_fDuration)
|
||||
{
|
||||
if (isLoop)
|
||||
m_fCurrentTrackPosition = 0.f;
|
||||
else
|
||||
if (m_fCurrentTrackPosition >= m_fDuration) {
|
||||
m_fCurrentTrackPosition = 0.f; // ·çÇÁ
|
||||
if (false == bIsLoop) {
|
||||
m_fCurrentTrackPosition = m_fDuration;
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
Depart_Animation();
|
||||
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());
|
||||
_uint iIndex = {};
|
||||
for (auto& pChannel : m_Channels) {
|
||||
pChannel->Update_TransformationMatirx(Bones, m_fCurrentTrackPosition, &m_CurrentKeyFrameIndices[iIndex++]);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void CAnimation::InterpAnim(CAnimation* pPreAnim, vector<CBone*>& Bones, float fRatio)
|
||||
void CAnimation::Depart_Animation()
|
||||
{
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
m_fCurrentTrackPosition = 0.f;
|
||||
fill(m_CurrentKeyFrameIndices.begin(), m_CurrentKeyFrameIndices.end(), 0);
|
||||
}
|
||||
_float CAnimation::Get_AnimProgressRatio()
|
||||
{
|
||||
return (m_fCurrentTrackPosition / m_fDuration);
|
||||
}
|
||||
_float CAnimation::Get_AnimEstimatedDuration()
|
||||
{
|
||||
return m_fDuration / m_TickPerSeconds[0];
|
||||
}
|
||||
_int CAnimation::Get_AnimProgressPostion(const _char* pAnimChannelName)
|
||||
{
|
||||
for (_int iIndex = 0; iIndex < m_Channels.size(); ++iIndex) {
|
||||
if (true == m_Channels[iIndex]->Compare_Name(pAnimChannelName)) {
|
||||
return m_CurrentKeyFrameIndices[iIndex];
|
||||
}
|
||||
}
|
||||
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];
|
||||
return -1;
|
||||
}
|
||||
void CAnimation::Set_AnimProgressPostion(const _char* pChannelName, _uint iPosition)
|
||||
{
|
||||
Depart_Animation();
|
||||
|
||||
_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]);
|
||||
}
|
||||
}
|
||||
for (_int iIndex = 0; iIndex < m_Channels.size(); ++iIndex) {
|
||||
if (true == m_Channels[iIndex]->Compare_Name(pChannelName)) {
|
||||
m_fCurrentTrackPosition = m_Channels[iIndex]->Get_Frame(iPosition)->fTrackPosition;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
vector<_int>* CAnimation::Capture_Bones()
|
||||
{
|
||||
if (m_DestBones.empty()) {
|
||||
m_DestBones.reserve(m_iNumChannels);
|
||||
for (_uint i = 0; i < m_iNumChannels; ++i) {
|
||||
m_DestBones.push_back(m_Channels[i]->Get_BoneIndex());
|
||||
}
|
||||
}
|
||||
return &m_DestBones;
|
||||
}
|
||||
#ifdef EDITOR_PROJECT
|
||||
HRESULT CAnimation::Initialize(const vector<CBone*>& Bones, const aiAnimation* pAIAnimation)
|
||||
{
|
||||
m_strName = pAIAnimation->mName.data;
|
||||
size_t pos = m_strName.find_last_of('|');
|
||||
if (0 > pos) {
|
||||
pos = 0;
|
||||
}
|
||||
else {
|
||||
pos++;
|
||||
}
|
||||
m_strName = m_strName.substr(pos);
|
||||
m_fDuration = (_float)pAIAnimation->mDuration;
|
||||
m_TickPerSeconds[0] = (_float)pAIAnimation->mTicksPerSecond;
|
||||
m_iNumChannels = pAIAnimation->mNumChannels;
|
||||
m_CurrentKeyFrameIndices.resize(m_iNumChannels);
|
||||
|
||||
CAnimation* CAnimation::Create(const CModel* pModel, const aiAnimation* pAIAnimation)
|
||||
for (_uint i = 0; i < m_iNumChannels; ++i) {
|
||||
CChannel* pChannel = CChannel::Create(Bones, pAIAnimation->mChannels[i]);
|
||||
if (nullptr == pChannel) {
|
||||
return E_FAIL;
|
||||
}
|
||||
m_Channels.push_back(pChannel);
|
||||
}
|
||||
|
||||
if (FAILED(Combined_Initialize())) {
|
||||
return E_FAIL;
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnimation::SaveAsBinary(HANDLE hFile, DWORD& dwByte)
|
||||
{
|
||||
size_t iNameLength = m_strName.length();
|
||||
WriteFile(hFile, &iNameLength, sizeof(size_t), &dwByte, nullptr);
|
||||
WriteFile(hFile, m_strName.data(), (DWORD)m_strName.length(), &dwByte, nullptr);
|
||||
WriteFile(hFile, &m_fDuration, sizeof(_float), &dwByte, nullptr);
|
||||
WriteFile(hFile, &m_TickPerSeconds, sizeof(_float) * 2, &dwByte, nullptr);
|
||||
WriteFile(hFile, &m_iNumChannels, sizeof(_uint), &dwByte, nullptr);
|
||||
|
||||
for (_uint i = 0; i < m_iNumChannels; ++i) {
|
||||
m_Channels[i]->SaveAsBinary(hFile, dwByte);
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
CAnimation* CAnimation::Create(const vector<CBone*>& Bones, const aiAnimation* pAnimation)
|
||||
{
|
||||
CAnimation* pInstance = new CAnimation;
|
||||
if (FAILED(pInstance->Initialize(Bones, pAnimation))) {
|
||||
SAFE_RELEASE(pInstance);
|
||||
}
|
||||
return pInstance;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
HRESULT CAnimation::Initialize(HANDLE hFile, DWORD& dwByte)
|
||||
{
|
||||
size_t iNameLength = {};
|
||||
if (!ReadFile(hFile, &iNameLength, sizeof(size_t), &dwByte, nullptr)) {
|
||||
return E_FAIL;
|
||||
}
|
||||
m_strName.resize(iNameLength);
|
||||
if (!ReadFile(hFile, (void*)m_strName.data(), (DWORD)iNameLength, &dwByte, nullptr)) {
|
||||
return E_FAIL;
|
||||
}
|
||||
if (!ReadFile(hFile, &m_fDuration, sizeof(_float), &dwByte, nullptr)) {
|
||||
return E_FAIL;
|
||||
}
|
||||
if (!ReadFile(hFile, &m_TickPerSeconds, sizeof(_float) * 2, &dwByte, nullptr)) {
|
||||
return E_FAIL;
|
||||
}
|
||||
if (!ReadFile(hFile, &m_iNumChannels, sizeof(_uint), &dwByte, nullptr)) {
|
||||
return E_FAIL;
|
||||
}
|
||||
m_CurrentKeyFrameIndices.resize(m_iNumChannels);
|
||||
m_Channels.reserve(m_iNumChannels);
|
||||
for (_uint i = 0; i < m_iNumChannels; ++i) {
|
||||
m_Channels.push_back(CChannel::Create(hFile, dwByte));
|
||||
}
|
||||
if (FAILED(Combined_Initialize())) {
|
||||
return E_FAIL;
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CAnimation::Combined_Initialize()
|
||||
{
|
||||
m_StartKeyFrames.reserve(m_iNumChannels);
|
||||
for (auto& pChannel : m_Channels) {
|
||||
LERPDESC desc = { pChannel->Get_BoneIndex(), *pChannel->Get_Frame(0) };
|
||||
m_StartKeyFrames.push_back(desc);
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
_uint CAnimation::Get_BoneIndex(const char* pChannelName)
|
||||
{
|
||||
return _uint();
|
||||
}
|
||||
|
||||
CAnimation* CAnimation::Create(HANDLE hFile, DWORD& dwByte)
|
||||
{
|
||||
CAnimation* pInstance = new CAnimation();
|
||||
|
||||
if (FAILED(pInstance->Initialize(pModel, pAIAnimation)))
|
||||
if (FAILED(pInstance->Initialize(hFile, dwByte)))
|
||||
{
|
||||
MSG_BOX("Failed to Created : CAnimation");
|
||||
Safe_Release(pInstance);
|
||||
SAFE_RELEASE(pInstance);
|
||||
}
|
||||
|
||||
return pInstance;
|
||||
@@ -143,10 +214,17 @@ void CAnimation::Free()
|
||||
{
|
||||
__super::Free();
|
||||
|
||||
for (auto& pChannel : m_Channels)
|
||||
Safe_Release(pChannel);
|
||||
|
||||
for (auto& pChannel : m_Channels) {
|
||||
SAFE_RELEASE(pChannel);
|
||||
}
|
||||
m_Channels.clear();
|
||||
|
||||
m_CurrentKeyFrameIndices.clear();
|
||||
}
|
||||
;
|
||||
void CAnimation::Describe_Entity()
|
||||
{
|
||||
//if (GUI::CollapsingHeader(m_strName.c_str())) {
|
||||
//
|
||||
//}
|
||||
}
|
||||
@@ -3,7 +3,70 @@
|
||||
|
||||
CBone::CBone()
|
||||
{
|
||||
}
|
||||
|
||||
void CBone::Get_KeyFrame(KEYFRAME& kf, _bool bIsCurrentFrame)
|
||||
{
|
||||
_vector vScale = {};
|
||||
_vector vRotation = {};
|
||||
_vector vTranspose = {};
|
||||
if (bIsCurrentFrame) {
|
||||
XMMatrixDecompose(&vScale, &vRotation, &vTranspose, XMLoadFloat4x4(&m_TransformationMatrix));
|
||||
}
|
||||
else {
|
||||
XMMatrixDecompose(&vScale, &vRotation, &vTranspose, XMLoadFloat4x4(&m_matInitial));
|
||||
}
|
||||
XMStoreFloat3(&kf.vScale, vScale);
|
||||
XMStoreFloat4(&kf.vRotation, vRotation);
|
||||
XMStoreFloat3(&kf.vTranslation, vTranspose);
|
||||
kf.fTrackPosition = 0.f;
|
||||
}
|
||||
|
||||
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_TransformationMatrix(_fmatrix TransformationMatrix)
|
||||
{
|
||||
XMStoreFloat4x4(&m_TransformationMatrix, TransformationMatrix);
|
||||
}
|
||||
_float3 CBone::Get_LocalPosition()
|
||||
{
|
||||
_float3 vPos = { m_TransformationMatrix.m[3][0], m_TransformationMatrix.m[3][1], m_TransformationMatrix.m[3][2] };
|
||||
return vPos;
|
||||
}
|
||||
#ifdef EDITOR_PROJECT
|
||||
HRESULT CBone::SaveAsBinary(HANDLE hFile, DWORD& dwByte)
|
||||
{
|
||||
string strName = m_szName;
|
||||
strName.shrink_to_fit();
|
||||
DWORD iLength = (DWORD)strName.length();
|
||||
WriteFile(hFile, &iLength, sizeof(_uint), &dwByte, nullptr);
|
||||
WriteFile(hFile, strName.data(), iLength, &dwByte, nullptr);
|
||||
WriteFile(hFile, &m_iParentBoneIndex, sizeof(_int), &dwByte, nullptr);
|
||||
WriteFile(hFile, &m_TransformationMatrix, sizeof(_float4x4), &dwByte, nullptr);
|
||||
WriteFile(hFile, &m_matInitial, sizeof(_float4x4), &dwByte, nullptr);
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
HRESULT CBone::Initialize(const aiNode* pAINode, _int iParentIndex)
|
||||
@@ -14,36 +77,46 @@ HRESULT CBone::Initialize(const aiNode* pAINode, _int iParentIndex)
|
||||
|
||||
memcpy(&m_TransformationMatrix, &pAINode->mTransformation, sizeof(_float4x4));
|
||||
XMStoreFloat4x4(&m_TransformationMatrix, XMMatrixTranspose(XMLoadFloat4x4(&m_TransformationMatrix)));
|
||||
m_matInitial = m_TransformationMatrix;
|
||||
XMStoreFloat4x4(&m_CombinedTransformationMatrix, XMMatrixIdentity());
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
HRESULT CBone::Initialize(HANDLE hFile, DWORD& dwByte)
|
||||
{
|
||||
_uint iLength = { 0 };
|
||||
if (!ReadFile(hFile, &iLength, sizeof(_uint), &dwByte, nullptr)) {
|
||||
return E_FAIL;
|
||||
}
|
||||
if (!ReadFile(hFile, m_szName, iLength, &dwByte, nullptr)) {
|
||||
return E_FAIL;
|
||||
}
|
||||
if (!ReadFile(hFile, &m_iParentBoneIndex, sizeof(_int), &dwByte, nullptr)) {
|
||||
return E_FAIL;
|
||||
}
|
||||
if (!ReadFile(hFile, &m_TransformationMatrix, sizeof(_float4x4), &dwByte, nullptr)) {
|
||||
return E_FAIL;
|
||||
}
|
||||
if (!ReadFile(hFile, &m_matInitial, sizeof(_float4x4), &dwByte, nullptr)) {
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
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* CBone::Create(HANDLE hFile, DWORD& dwByte)
|
||||
{
|
||||
CBone* pInstance = new CBone();
|
||||
|
||||
if (FAILED(pInstance->Initialize(pAINode, iParentIndex)))
|
||||
if (FAILED(pInstance->Initialize(hFile, dwByte)))
|
||||
{
|
||||
MSG_BOX("Failed to Created : CBone");
|
||||
Safe_Release(pInstance);
|
||||
SAFE_RELEASE(pInstance);
|
||||
}
|
||||
|
||||
return pInstance;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "pch.h"
|
||||
|
||||
#include "Channel.h"
|
||||
#include "Model.h"
|
||||
#include "Bone.h"
|
||||
@@ -6,22 +7,22 @@
|
||||
CChannel::CChannel()
|
||||
{
|
||||
}
|
||||
|
||||
HRESULT CChannel::Initialize(const CModel* pModel, const aiNodeAnim* pAIChannel)
|
||||
#ifdef EDITOR_PROJECT
|
||||
HRESULT CChannel::Initialize(const vector<CBone*>& Bones, const aiNodeAnim* pAIChannel)
|
||||
{
|
||||
strcpy_s(m_szName, pAIChannel->mNodeName.data);
|
||||
|
||||
m_iBoneIndex = pModel->Get_BoneIndex(m_szName);
|
||||
if (-1 == m_iBoneIndex)
|
||||
m_iBoneIndex = CModel::Get_BoneIndex(m_szName, Bones);
|
||||
if (-1 == m_iBoneIndex) {
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
m_iNumKeyFrames = max(pAIChannel->mNumScalingKeys, pAIChannel->mNumRotationKeys);
|
||||
m_iNumKeyFrames = max(m_iNumKeyFrames, pAIChannel->mNumPositionKeys);
|
||||
m_iNumKeyFrames = max(m_iNumKeyFrames, (_uint)pAIChannel->mNumPositionKeys);
|
||||
|
||||
_float3 vScale{};
|
||||
_float3 vScale = { };
|
||||
_float4 vRotation{};
|
||||
_float3 vTranslation{};
|
||||
|
||||
for (size_t i = 0; i < m_iNumKeyFrames; i++)
|
||||
{
|
||||
KEYFRAME KeyFrame{};
|
||||
@@ -55,21 +56,60 @@ HRESULT CChannel::Initialize(const CModel* pModel, const aiNodeAnim* pAIChannel)
|
||||
m_KeyFrames.push_back(KeyFrame);
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CChannel::SaveAsBinary(HANDLE hFile, DWORD& dwByte)
|
||||
{
|
||||
string strName = m_szName;
|
||||
strName.shrink_to_fit();
|
||||
DWORD iLength = (DWORD)strName.length();
|
||||
WriteFile(hFile, &iLength, sizeof(_uint), &dwByte, nullptr);
|
||||
WriteFile(hFile, strName.data(), iLength, &dwByte, nullptr);
|
||||
WriteFile(hFile, &m_iBoneIndex, sizeof(_int), &dwByte, nullptr);
|
||||
WriteFile(hFile, &m_iNumKeyFrames, sizeof(_uint), &dwByte, nullptr);
|
||||
for (auto& keyFrame : m_KeyFrames) {
|
||||
WriteFile(hFile, &keyFrame, sizeof(KEYFRAME), &dwByte, nullptr);
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
CChannel* CChannel::Create(const vector<CBone*>& Bones, const aiNodeAnim* pAIChannel)
|
||||
{
|
||||
CChannel* pInstance = new CChannel();
|
||||
|
||||
if (FAILED(pInstance->Initialize(Bones, pAIChannel))) {
|
||||
MSG_BOX("Failed to Created : CChannel");
|
||||
SAFE_RELEASE(pInstance);
|
||||
}
|
||||
return pInstance;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
HRESULT CChannel::Initialize(const vector<CBone*>& Bones, _uint iIndex)
|
||||
{
|
||||
m_iBoneIndex = iIndex;
|
||||
memcpy_s(m_szName, sizeof(_char) * MAX_PATH, Bones[iIndex]->Get_Name(), sizeof(_char) * MAX_PATH);
|
||||
|
||||
m_iNumKeyFrames = 2;
|
||||
m_KeyFrames.resize(m_iNumKeyFrames);
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
void CChannel::Update_TransformationMatrix(_float fCurrentTrackPosition, vector<CBone*>& Bones, _uint* pCurrentKeyFrameIndex)
|
||||
|
||||
void CChannel::Update_TransformationMatirx(const vector<CBone*>& Bones, _float fCurrentTrackPosition, _uint* pCurrentKeyFrameIndex)
|
||||
|
||||
{
|
||||
if (0.f == fCurrentTrackPosition)
|
||||
if (0.f == fCurrentTrackPosition) {
|
||||
*pCurrentKeyFrameIndex = 0;
|
||||
}
|
||||
KEYFRAME LastKeyFrame = m_KeyFrames.back();
|
||||
|
||||
KEYFRAME LastKeyFrame = m_KeyFrames.back();
|
||||
|
||||
_vector vScale{};
|
||||
_vector vRotation{};
|
||||
_vector vTranslation{};
|
||||
_vector vScale = {};
|
||||
_vector vRotation = {};
|
||||
_vector vTranslation = {};
|
||||
|
||||
if (fCurrentTrackPosition >= LastKeyFrame.fTrackPosition)
|
||||
{
|
||||
@@ -77,49 +117,93 @@ void CChannel::Update_TransformationMatrix(_float fCurrentTrackPosition, vector<
|
||||
vRotation = XMLoadFloat4(&LastKeyFrame.vRotation);
|
||||
vTranslation = XMVectorSetW(XMLoadFloat3(&LastKeyFrame.vTranslation), 1.f);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
while (fCurrentTrackPosition >= m_KeyFrames[*pCurrentKeyFrameIndex + 1].fTrackPosition)
|
||||
else {
|
||||
while (fCurrentTrackPosition >= m_KeyFrames[*pCurrentKeyFrameIndex + 1].fTrackPosition) {
|
||||
++*pCurrentKeyFrameIndex;
|
||||
}
|
||||
|
||||
_float3 vSourScale{}, vDestScale{};
|
||||
_float4 vSourRotation{}, vDestRotation{};
|
||||
_float3 vSourTranslation{}, vDestTranslation{};
|
||||
_float3 vSrcScale = {}, vDstScale = {};
|
||||
_float4 vSrcRotation = {}, vDstRotation = {};
|
||||
_float3 vSrcTranslation = {}, vDstTranslation = {};
|
||||
|
||||
vSourScale = m_KeyFrames[*pCurrentKeyFrameIndex].vScale;
|
||||
vDestScale = m_KeyFrames[*pCurrentKeyFrameIndex + 1].vScale;
|
||||
vSrcScale = m_KeyFrames[*pCurrentKeyFrameIndex].vScale;
|
||||
vDstScale = m_KeyFrames[*pCurrentKeyFrameIndex + 1].vScale;
|
||||
|
||||
vSourRotation = m_KeyFrames[*pCurrentKeyFrameIndex].vRotation;
|
||||
vDestRotation = m_KeyFrames[*pCurrentKeyFrameIndex + 1].vRotation;
|
||||
vSrcRotation = m_KeyFrames[*pCurrentKeyFrameIndex].vRotation;
|
||||
vDstRotation = m_KeyFrames[*pCurrentKeyFrameIndex + 1].vRotation;
|
||||
|
||||
vSourTranslation = m_KeyFrames[*pCurrentKeyFrameIndex].vTranslation;
|
||||
vDestTranslation = m_KeyFrames[*pCurrentKeyFrameIndex + 1].vTranslation;
|
||||
vSrcTranslation = m_KeyFrames[*pCurrentKeyFrameIndex].vTranslation;
|
||||
vDstTranslation = 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);
|
||||
|
||||
vScale = XMVectorLerp(XMLoadFloat3(&vSrcScale), XMLoadFloat3(&vDstScale), fRatio);
|
||||
vRotation = XMQuaternionSlerp(XMLoadFloat4(&vSrcRotation), XMLoadFloat4(&vDstRotation), fRatio);
|
||||
vTranslation = XMVectorSetW(XMVectorLerp(XMLoadFloat3(&vSrcTranslation), XMLoadFloat3(&vDstTranslation), fRatio), 1.f);
|
||||
}
|
||||
_matrix BoneTransformationMatrix = XMMatrixAffineTransformation(vScale, XMVectorSet(0.f, 0.f, 0.f, 1.f), vRotation, vTranslation);
|
||||
|
||||
m_BoneTransformationMatrix = XMMatrixAffineTransformation(vScale, XMVectorSet(0.f, 0.f, 0.f, 1.f), vRotation, vTranslation);
|
||||
|
||||
Bones[m_iBoneIndex]->Set_Transformation(m_BoneTransformationMatrix);
|
||||
|
||||
|
||||
Bones[m_iBoneIndex]->Set_TransformationMatrix(BoneTransformationMatrix);
|
||||
}
|
||||
|
||||
CChannel* CChannel::Create(const CModel* pModel, const aiNodeAnim* pAIChannel)
|
||||
|
||||
KEYFRAME* CChannel::Get_Frame(_uint iIndex)
|
||||
{
|
||||
return &m_KeyFrames[iIndex];
|
||||
}
|
||||
|
||||
void CChannel::Set_Frame(_uint iIndex, KEYFRAME& kf)
|
||||
{
|
||||
m_KeyFrames[iIndex] = kf;
|
||||
}
|
||||
|
||||
|
||||
HRESULT CChannel::Initialize(HANDLE hFile, DWORD& dwByte)
|
||||
{
|
||||
_uint iLength = { 0 };
|
||||
if (!ReadFile(hFile, &iLength, sizeof(_uint), &dwByte, nullptr)) {
|
||||
return E_FAIL;
|
||||
}
|
||||
if (!ReadFile(hFile, m_szName, iLength, &dwByte, nullptr)) {
|
||||
return E_FAIL;
|
||||
}
|
||||
if (!ReadFile(hFile, &m_iBoneIndex, sizeof(_int), &dwByte, nullptr)) {
|
||||
return E_FAIL;
|
||||
}
|
||||
if (!ReadFile(hFile, &m_iNumKeyFrames, sizeof(_uint), &dwByte, nullptr)) {
|
||||
return E_FAIL;
|
||||
}
|
||||
m_KeyFrames.resize(m_iNumKeyFrames);
|
||||
for (_uint i = 0; i < m_iNumKeyFrames; ++i) {
|
||||
if (!ReadFile(hFile, &m_KeyFrames[i], sizeof(KEYFRAME), &dwByte, nullptr)) {
|
||||
return E_FAIL;
|
||||
}
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
CChannel* CChannel::Create(const vector<CBone*>& Bones, _uint iIndex)
|
||||
{
|
||||
CChannel* pInstance = new CChannel();
|
||||
|
||||
if (FAILED(pInstance->Initialize(pModel, pAIChannel)))
|
||||
if (FAILED(pInstance->Initialize(Bones, iIndex)))
|
||||
{
|
||||
MSG_BOX("Failed to Created : CChannel");
|
||||
Safe_Release(pInstance);
|
||||
SAFE_RELEASE(pInstance);
|
||||
}
|
||||
|
||||
return pInstance;
|
||||
}
|
||||
|
||||
CChannel* CChannel::Create(HANDLE hFile, DWORD& dwByte)
|
||||
{
|
||||
CChannel* pInstance = new CChannel();
|
||||
|
||||
if (FAILED(pInstance->Initialize(hFile, dwByte)))
|
||||
{
|
||||
MSG_BOX("Failed to Created : CChannel");
|
||||
SAFE_RELEASE(pInstance);
|
||||
}
|
||||
|
||||
return pInstance;
|
||||
@@ -130,5 +214,4 @@ void CChannel::Free()
|
||||
__super::Free();
|
||||
|
||||
m_KeyFrames.clear();
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
#include "pch.h"
|
||||
#include "LerpAnim.h"
|
||||
#include "Channel.h"
|
||||
#include "Bone.h"
|
||||
|
||||
CLerpAnim::CLerpAnim()
|
||||
{
|
||||
}
|
||||
|
||||
_bool CLerpAnim::Update_TransformationMatrices(const vector<CBone*>& Bones, _float fTimeDelta)
|
||||
{
|
||||
m_fCurrentTrackPosition += m_fTickPerSecond * fTimeDelta;
|
||||
|
||||
if (m_fCurrentTrackPosition >= m_fDuration) {
|
||||
m_fCurrentTrackPosition = m_fDuration;
|
||||
m_bLerping = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
_uint iIndex = {};
|
||||
for (auto& pChannel : m_Channels) {
|
||||
if (true == m_Movable[iIndex]) {
|
||||
pChannel->Update_TransformationMatirx(Bones, m_fCurrentTrackPosition, &m_CurrentKeyFrameIndices[iIndex]);
|
||||
}
|
||||
iIndex++;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
HRESULT CLerpAnim::Initialize(_uint iNumBone, _float fTickPerSecond, const vector<CBone*>& Bones)
|
||||
{
|
||||
m_iNumChannels = iNumBone;
|
||||
m_fTickPerSecond = fTickPerSecond;
|
||||
m_CurrentKeyFrameIndices.resize(m_iNumChannels);
|
||||
m_Movable.resize(m_iNumChannels);
|
||||
m_InitialFrames.resize(m_iNumChannels);
|
||||
m_Channels.reserve(m_iNumChannels);
|
||||
|
||||
for (_uint i = 0; i < m_iNumChannels; ++i) {
|
||||
CChannel* pChannel = CChannel::Create(Bones, i);
|
||||
if (nullptr == pChannel) {
|
||||
return E_FAIL;
|
||||
}
|
||||
m_Channels.push_back(pChannel);
|
||||
Bones[i]->Get_KeyFrame(m_InitialFrames[i], false);
|
||||
m_InitialFrames[i].fTrackPosition = m_fDuration;
|
||||
pChannel->Set_Frame(1, m_InitialFrames[i]);
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
void CLerpAnim::Begin(const vector<class CBone*>& Bones, vector<LERPDESC>& StartFrames, vector<LERPDESC>& EndFrames, _float fDuration, _uint iRootBoneIndex)
|
||||
{
|
||||
{ // 초기화
|
||||
|
||||
//KEYFRAME kf = { // 항등행렬의 키프레임
|
||||
// { 1.f, 1.f, 1.f },
|
||||
// { 0.f, 0.f, 0.f, 1.f },
|
||||
// { 0.f, 0.f, 0.f},
|
||||
// m_fDuration };
|
||||
m_bLerping = true;
|
||||
m_fDuration = fDuration;
|
||||
m_fCurrentTrackPosition = 0.f;
|
||||
for (_uint i = 0; i < m_iNumChannels; ++i) {
|
||||
m_Channels[i]->Set_Frame(1, m_InitialFrames[i]); // 끝프레임을 초기 값으로 채우기
|
||||
}
|
||||
fill(m_CurrentKeyFrameIndices.begin(), m_CurrentKeyFrameIndices.end(), 0);
|
||||
fill(m_Movable.begin(), m_Movable.end(), false);
|
||||
}
|
||||
{ // 실제 값 채우기
|
||||
for (LERPDESC& Desc : EndFrames) // 끝프레임을 실제 값으로 채우기
|
||||
{
|
||||
_int iIndex = Desc.iSlot;
|
||||
Desc.tagKeyFrame.fTrackPosition = m_fDuration;
|
||||
m_Channels[iIndex]->Set_Frame(1, Desc.tagKeyFrame);
|
||||
}
|
||||
for (_uint i = 0; i < StartFrames.size(); ++i) { // 시작 프레임을 현재 본 상태 키프레임으로 채우기
|
||||
_int iIndex = StartFrames[i].iSlot;
|
||||
m_Movable[iIndex] = true;
|
||||
m_Channels[iIndex]->Set_Frame(0, StartFrames[i].tagKeyFrame);
|
||||
}
|
||||
//m_Movable[iRootBoneIndex] = false;
|
||||
}
|
||||
}
|
||||
CLerpAnim* CLerpAnim::Create(_uint iNumBone, _float fTickPerSecond, const vector<CBone*>& Bones)
|
||||
{
|
||||
CLerpAnim* pInstance = new CLerpAnim;
|
||||
if (FAILED(pInstance->Initialize(iNumBone, fTickPerSecond, Bones))) {
|
||||
SAFE_RELEASE(pInstance);
|
||||
}
|
||||
return pInstance;
|
||||
}
|
||||
|
||||
void CLerpAnim::Free()
|
||||
{
|
||||
__super::Free();
|
||||
|
||||
for (auto& pChannel : m_Channels) {
|
||||
SAFE_RELEASE(pChannel);
|
||||
}
|
||||
m_Channels.clear();
|
||||
|
||||
m_CurrentKeyFrameIndices.clear();
|
||||
}
|
||||
;
|
||||
@@ -1,80 +1,114 @@
|
||||
#include "pch.h"
|
||||
#include "Material.h"
|
||||
|
||||
#include "GameInstance.h"
|
||||
#include "Shader.h"
|
||||
|
||||
CMaterial::CMaterial(ID3D11Device* pDevice, ID3D11DeviceContext* pContext)
|
||||
: m_pDevice{ pDevice }
|
||||
, m_pContext{ pContext }
|
||||
, m_pGameInstance{ CGameInstance::GetInstance() }
|
||||
{
|
||||
Safe_AddRef(m_pDevice);
|
||||
Safe_AddRef(m_pContext);
|
||||
SAFE_ADDREF(m_pDevice);
|
||||
SAFE_ADDREF(m_pContext);
|
||||
SAFE_ADDREF(m_pGameInstance);
|
||||
}
|
||||
|
||||
#ifdef EDITOR_PROJECT
|
||||
HRESULT CMaterial::Initialize(const _char* pModelFilePath, const aiMaterial* pAIMaterial)
|
||||
{
|
||||
for (_uint i = 0; i < AI_TEXTURE_TYPE_MAX; i++)
|
||||
for (size_t i = 0; i < AI_TEXTURE_TYPE_MAX; i++)
|
||||
{
|
||||
m_iNumSRVs = pAIMaterial->GetTextureCount(static_cast<aiTextureType>(i));
|
||||
_uint iNumSRVs = pAIMaterial->GetTextureCount(static_cast<aiTextureType>(i));
|
||||
|
||||
m_SRVs[i].reserve(m_iNumSRVs);
|
||||
m_SRVs[i].reserve(iNumSRVs);
|
||||
|
||||
for (_uint j = 0; j < m_iNumSRVs; j++)
|
||||
ID3D11ShaderResourceView* pSRV = { nullptr };
|
||||
|
||||
HRESULT hr = {};
|
||||
|
||||
for (size_t j = 0; j < 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)))
|
||||
if (FAILED(pAIMaterial->GetTexture(static_cast<aiTextureType>(i), (_uint)j, &strTexturePath))) {
|
||||
continue;
|
||||
|
||||
_char szTextureFilePath[MAX_PATH] = {};
|
||||
}
|
||||
_char szTextureDir[MAX_PATH] = {};
|
||||
_char szSaveDir[MAX_PATH] = {};
|
||||
_char szDrive[MAX_PATH] = {};
|
||||
_char szDir[MAX_PATH] = {};
|
||||
_char szName[MAX_PATH] = {};
|
||||
_char szExt[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);
|
||||
_splitpath_s(strTexturePath.C_Str(), nullptr, 0, nullptr, 0, szName, MAX_PATH, szExt, MAX_PATH);
|
||||
strcpy_s(szTextureDir, sizeof(_char) * MAX_PATH, szDrive);
|
||||
strcat_s(szTextureDir, sizeof(_char) * MAX_PATH, szDir);
|
||||
strcat_s(szTextureDir, sizeof(_char) * MAX_PATH, szName);
|
||||
strcat_s(szTextureDir, sizeof(_char) * MAX_PATH, szExt);
|
||||
|
||||
strcpy_s(szTextureFilePath, szDrive);
|
||||
strcat_s(szTextureFilePath, szDir);
|
||||
strcat_s(szTextureFilePath, szFileName);
|
||||
strcat_s(szTextureFilePath, szEXT);
|
||||
{
|
||||
_char szTextureFileName[MAX_PATH] = {};
|
||||
_char szTextureFilePath[MAX_PATH] = {};
|
||||
_char szDrive[MAX_PATH] = {};
|
||||
_char szDir[MAX_PATH] = {};
|
||||
_char szFileName[MAX_PATH] = {};
|
||||
_char szEXT[MAX_PATH] = {};
|
||||
_splitpath_s(szTextureDir, szDrive, MAX_PATH, szDir, MAX_PATH, szFileName, MAX_PATH, szEXT, MAX_PATH);
|
||||
strcpy_s(szTextureFileName, szDrive);
|
||||
strcat_s(szTextureFileName, szDir);
|
||||
strcat_s(szTextureFileName, szFileName);
|
||||
|
||||
_tchar szPerfectPath[MAX_PATH] = {};
|
||||
MultiByteToWideChar(CP_ACP, 0, szTextureFilePath, (_int)strlen(szTextureFilePath),
|
||||
szPerfectPath, MAX_PATH);
|
||||
strcat_s(szTextureFilePath, szTextureFileName);
|
||||
strcat_s(szTextureFilePath, ".dds");
|
||||
|
||||
ID3D11ShaderResourceView* pSRV = { nullptr };
|
||||
hr = CreateDDSTextureFromFile(m_pDevice, CMyTools::ToWstring(szTextureFilePath).c_str(), nullptr, &pSRV); // 일단 dds로 시도하고
|
||||
if (FAILED(hr)) {
|
||||
memset(szTextureFilePath, 0, sizeof(_char) * MAX_PATH); // 실패하면 원래 확장자로 다시 시도
|
||||
strcat_s(szTextureFilePath, szTextureFileName);
|
||||
strcat_s(szTextureFilePath, szEXT);
|
||||
|
||||
HRESULT hr = {};
|
||||
if (false == strcmp(".tga", szEXT)) {
|
||||
assert(false); // trying to Load TGA
|
||||
hr = S_OK;
|
||||
}
|
||||
else {
|
||||
hr = CreateWICTextureFromFile(m_pDevice, CMyTools::ToWstring(szTextureFilePath).c_str(), nullptr, &pSRV);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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))
|
||||
strcpy_s(szSaveDir, sizeof(_char) * MAX_PATH, szName);
|
||||
strcat_s(szSaveDir, sizeof(_char) * MAX_PATH, szExt);
|
||||
|
||||
if (FAILED(hr)) {
|
||||
return E_FAIL;
|
||||
|
||||
}
|
||||
m_strPath[i].push_back(szSaveDir);
|
||||
m_SRVs[i].push_back(pSRV);
|
||||
}
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CMaterial::Bind_SRV(CShader* pShader, const _char* pConstantName, aiTextureType eType, _uint iTextureIndex)
|
||||
HRESULT CMaterial::SaveAsBinary(HANDLE hFile, DWORD& dwByte)
|
||||
{
|
||||
if (m_SRVs[eType].empty())
|
||||
{
|
||||
return S_OK;
|
||||
// 실제 값을 저장하지 않고 파일이름.확장자명의 문자열을 저장해서 수정하기 편하게 만들기
|
||||
// 대신 리소스를 공유해야함
|
||||
// 텍스쳐를 저장하지 않고
|
||||
// 텍스쳐 경로만 ( "이름.확장자" ) 만 저장함
|
||||
for (int i = 0; i < AI_TEXTURE_TYPE_MAX; ++i) {
|
||||
_uint iNumSrv = (_uint)m_strPath[i].size();
|
||||
WriteFile(hFile, &i, sizeof(_uint), &dwByte, nullptr); // 종류 저장
|
||||
WriteFile(hFile, &iNumSrv, sizeof(_uint), &dwByte, nullptr); // 종류의 갯수 저장
|
||||
for (_uint j = 0; j < iNumSrv; ++j) {
|
||||
m_strPath[i][j].shrink_to_fit();
|
||||
_uint strLength = (_uint)(sizeof(_char) * m_strPath[i][j].length());
|
||||
WriteFile(hFile, &strLength, sizeof(_uint), &dwByte, nullptr); // 사이즈 저장
|
||||
WriteFile(hFile, m_strPath[i][j].data(), strLength, &dwByte, nullptr); // 실제 값 저장
|
||||
}
|
||||
}
|
||||
return pShader->Bind_SRV(pConstantName, m_SRVs[eType][iTextureIndex]);
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
CMaterial* CMaterial::Create(ID3D11Device* pDevice, ID3D11DeviceContext* pContext, const _char* pModelFilePath, const aiMaterial* pAIMaterial)
|
||||
{
|
||||
CMaterial* pInstance = new CMaterial(pDevice, pContext);
|
||||
@@ -82,22 +116,128 @@ CMaterial* CMaterial::Create(ID3D11Device* pDevice, ID3D11DeviceContext* pContex
|
||||
if (FAILED(pInstance->Initialize(pModelFilePath, pAIMaterial)))
|
||||
{
|
||||
MSG_BOX("Failed to Created : CMaterial");
|
||||
Safe_Release(pInstance);
|
||||
SAFE_RELEASE(pInstance);
|
||||
}
|
||||
|
||||
return pInstance;
|
||||
}
|
||||
#endif
|
||||
|
||||
HRESULT CMaterial::Bind_SRV(CShader* pShader, const _char* pConstantName, _uint iType, _uint iTextureIndex)
|
||||
{
|
||||
if (m_SRVs[iType].empty()) {
|
||||
//assert(false);
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
|
||||
return pShader->Bind_SRV(pConstantName, m_SRVs[iType][iTextureIndex]);
|
||||
}
|
||||
|
||||
|
||||
HRESULT CMaterial::Initialize(const _char* pModelFilePath, HANDLE hFile, DWORD& dwByte)
|
||||
{
|
||||
for (int i = 0; i < AI_TEXTURE_TYPE_MAX; ++i) {
|
||||
_uint iNumSrv = { 0 };
|
||||
if (!ReadFile(hFile, &i, sizeof(_uint), &dwByte, nullptr)) {
|
||||
return E_FAIL;
|
||||
}
|
||||
if (!ReadFile(hFile, &iNumSrv, sizeof(_uint), &dwByte, nullptr)) {
|
||||
return E_FAIL;
|
||||
}
|
||||
if (iNumSrv == 0) {
|
||||
continue;
|
||||
}
|
||||
m_SRVs[i].reserve(iNumSrv);
|
||||
|
||||
ID3D11ShaderResourceView* pSRV = { nullptr };
|
||||
HRESULT hr = {};
|
||||
|
||||
for (_uint j = 0; j < iNumSrv; ++j) {
|
||||
_uint strLength = { 0 };
|
||||
if (!ReadFile(hFile, &strLength, sizeof(_uint), &dwByte, nullptr)) {
|
||||
return E_FAIL;
|
||||
}
|
||||
_char szTextureName[MAX_PATH] = {};
|
||||
if (!ReadFile(hFile, szTextureName, strLength, &dwByte, nullptr)) {
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
_char szTextureDir[MAX_PATH] = {};
|
||||
_char szDrive[MAX_PATH] = {};
|
||||
_char szDir[MAX_PATH] = {};
|
||||
_splitpath_s(pModelFilePath, szDrive, MAX_PATH, szDir, MAX_PATH, nullptr, 0, nullptr, 0);
|
||||
strcpy_s(szTextureDir, sizeof(_char) * MAX_PATH, szDrive);
|
||||
strcat_s(szTextureDir, sizeof(_char) * MAX_PATH, szDir);
|
||||
strcat_s(szTextureDir, sizeof(_char) * MAX_PATH, szTextureName);
|
||||
|
||||
{
|
||||
_char szTextureFileName[MAX_PATH] = {};
|
||||
_char szTextureFilePath[MAX_PATH] = {};
|
||||
_char szDrive[MAX_PATH] = {};
|
||||
_char szDir[MAX_PATH] = {};
|
||||
_char szFileName[MAX_PATH] = {};
|
||||
_char szEXT[MAX_PATH] = {};
|
||||
_splitpath_s(szTextureDir, szDrive, MAX_PATH, szDir, MAX_PATH, szFileName, MAX_PATH, szEXT, MAX_PATH);
|
||||
strcpy_s(szTextureFileName, szDrive);
|
||||
strcat_s(szTextureFileName, szDir);
|
||||
strcat_s(szTextureFileName, szFileName);
|
||||
|
||||
strcat_s(szTextureFilePath, szTextureFileName);
|
||||
strcat_s(szTextureFilePath, ".dds");
|
||||
|
||||
hr = CreateDDSTextureFromFile(m_pDevice, CMyTools::ToWstring(szTextureFilePath).c_str(), nullptr, &pSRV); // 일단 dds로 시도하고
|
||||
if (FAILED(hr)) {
|
||||
memset(szTextureFilePath, 0, sizeof(_char) * MAX_PATH); // 실패하면 원래 확장자로 다시 시도
|
||||
strcat_s(szTextureFilePath, szTextureFileName);
|
||||
strcat_s(szTextureFilePath, szEXT);
|
||||
|
||||
if (false == strcmp(".tga", szEXT)) {
|
||||
assert(false); // trying to Load TGA
|
||||
hr = S_OK;
|
||||
}
|
||||
else {
|
||||
hr = CreateWICTextureFromFile(m_pDevice, CMyTools::ToWstring(szTextureFilePath).c_str(), nullptr, &pSRV);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (FAILED(hr)) {
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
m_SRVs[i].push_back(pSRV);
|
||||
}
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
|
||||
CMaterial* CMaterial::Create(ID3D11Device* pDevice, ID3D11DeviceContext* pContext, const _char* pModelFilePath, HANDLE hFile, DWORD& dwByte) {
|
||||
CMaterial* pInstance = new CMaterial(pDevice, pContext);
|
||||
|
||||
if (FAILED(pInstance->Initialize(pModelFilePath, hFile, dwByte)))
|
||||
{
|
||||
MSG_BOX("Failed to Created : CMaterial");
|
||||
SAFE_RELEASE(pInstance);
|
||||
}
|
||||
|
||||
return pInstance;
|
||||
}
|
||||
|
||||
|
||||
void CMaterial::Free()
|
||||
{
|
||||
__super::Free();
|
||||
|
||||
Safe_Release(m_pDevice);
|
||||
Safe_Release(m_pContext);
|
||||
SAFE_RELEASE(m_pGameInstance);
|
||||
SAFE_RELEASE(m_pDevice);
|
||||
SAFE_RELEASE(m_pContext);
|
||||
|
||||
for (auto& SRVs : m_SRVs)
|
||||
{
|
||||
for (auto& pSRV : SRVs)
|
||||
Safe_Release(pSRV);
|
||||
for (auto& pSRV : SRVs) {
|
||||
SAFE_RELEASE(pSRV);
|
||||
}
|
||||
SRVs.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,22 +1,61 @@
|
||||
#include "pch.h"
|
||||
#include "Mesh.h"
|
||||
|
||||
#include "Bone.h"
|
||||
#include "Model.h"
|
||||
#include "Bone.h"
|
||||
#include "Shader.h"
|
||||
|
||||
|
||||
CMesh::CMesh(ID3D11Device* pDevice, ID3D11DeviceContext* pContext)
|
||||
: CVIBuffer( pDevice, pContext )
|
||||
: CVIBuffer{ pDevice, pContext }
|
||||
{
|
||||
}
|
||||
|
||||
CMesh::CMesh(const CMesh& Prototype)
|
||||
: CVIBuffer( Prototype )
|
||||
CMesh::CMesh(const CMesh& rhs)
|
||||
: CVIBuffer(rhs)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
HRESULT CMesh::Initialize_Prototype(MODEL eType, const class CModel* pModel, const aiMesh* pAIMesh, _fmatrix PreTransformMatrix)
|
||||
HRESULT CMesh::Bind_BoneMatrices(const vector<class 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::Bind_BoneMatrices(_float4x4* pCombinedMatrices, 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]) * XMLoadFloat4x4(&pCombinedMatrices[m_BoneIndices[i]]));
|
||||
}
|
||||
if (0 == m_iNumBones) {
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
return pShader->Bind_Matrices(pConstantName, m_pBoneMatrices, m_iNumBones);
|
||||
}
|
||||
|
||||
HRESULT CMesh::Render_Indexed(_uint IndexCount, _uint StartIndexLocation, _uint BaseVertexLocation)
|
||||
{
|
||||
m_pContext->DrawIndexed(IndexCount, StartIndexLocation, BaseVertexLocation);
|
||||
return S_OK;
|
||||
}
|
||||
#ifdef EDITOR_PROJECT
|
||||
HRESULT CMesh::Initialize_Prototype(MODEL eType, vector<class CBone*>& Bones, const aiMesh* pAIMesh, _fmatrix& PreTransformMatrix)
|
||||
{
|
||||
strcpy_s(m_szName, pAIMesh->mName.data);
|
||||
|
||||
@@ -30,44 +69,11 @@ HRESULT CMesh::Initialize_Prototype(MODEL eType, const class CModel* pModel, con
|
||||
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 ?
|
||||
HRESULT hr = (eType == MODEL::NONANIM) ?
|
||||
Ready_VertexBuffer_For_NonAnim(pAIMesh, PreTransformMatrix) :
|
||||
Ready_VertexBuffer_For_Anim(pModel, pAIMesh);
|
||||
|
||||
if (FAILED(hr))
|
||||
return E_FAIL;
|
||||
Ready_VertexBuffer_For_Anim(Bones, pAIMesh);
|
||||
|
||||
#pragma endregion
|
||||
|
||||
@@ -88,6 +94,7 @@ HRESULT CMesh::Initialize_Prototype(MODEL eType, const class CModel* pModel, con
|
||||
|
||||
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];
|
||||
@@ -106,6 +113,144 @@ HRESULT CMesh::Initialize_Prototype(MODEL eType, const class CModel* pModel, con
|
||||
|
||||
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
#endif
|
||||
HRESULT CMesh::Initialize_Prototype(HANDLE hFile, DWORD& dwByte)
|
||||
{
|
||||
{ // 멤버변수
|
||||
if (!ReadFile(hFile, &m_iMaterialIndex, sizeof(_uint), &dwByte, nullptr)) {
|
||||
return E_FAIL;
|
||||
}
|
||||
if (!ReadFile(hFile, &m_iNumVertexBuffers, sizeof(_uint), &dwByte, nullptr)) {
|
||||
return E_FAIL;
|
||||
}
|
||||
if (!ReadFile(hFile, &m_iNumVertices, sizeof(_uint), &dwByte, nullptr)) {
|
||||
return E_FAIL;
|
||||
}
|
||||
if (!ReadFile(hFile, &m_iVertexStride, sizeof(_uint), &dwByte, nullptr)) {
|
||||
return E_FAIL;
|
||||
}
|
||||
if (!ReadFile(hFile, &m_iNumIndices, sizeof(_uint), &dwByte, nullptr)) {
|
||||
return E_FAIL;
|
||||
}
|
||||
if (!ReadFile(hFile, &m_iIndexStride, sizeof(_uint), &dwByte, nullptr)) {
|
||||
return E_FAIL;
|
||||
}
|
||||
if (!ReadFile(hFile, &m_iNumBones, sizeof(_uint), &dwByte, nullptr)) {
|
||||
return E_FAIL;
|
||||
}
|
||||
if (!ReadFile(hFile, &m_eIndexFormat, sizeof(DXGI_FORMAT), &dwByte, nullptr)) {
|
||||
return E_FAIL;
|
||||
}
|
||||
if (!ReadFile(hFile, &m_ePrimitive, sizeof(D3D_PRIMITIVE_TOPOLOGY), &dwByte, nullptr)) {
|
||||
return E_FAIL;
|
||||
}
|
||||
DWORD iSize = {};
|
||||
if (!ReadFile(hFile, &iSize, sizeof(DWORD), &dwByte, nullptr)) {
|
||||
return E_FAIL;
|
||||
}
|
||||
m_BoneIndices.resize(iSize / sizeof(_int));
|
||||
if (!ReadFile(hFile, m_BoneIndices.data(), iSize, &dwByte, nullptr)) {
|
||||
return E_FAIL;
|
||||
}
|
||||
if (!ReadFile(hFile, &iSize, sizeof(DWORD), &dwByte, nullptr)) {
|
||||
return E_FAIL;
|
||||
}
|
||||
m_offsetMatrices.resize(iSize / sizeof(_float4x4));
|
||||
if (!ReadFile(hFile, m_offsetMatrices.data(), iSize, &dwByte, nullptr)) {
|
||||
DWORD err = GetLastError();
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
m_pBoneMatrices = new _float4x4[0 == m_iNumBones ? 1 : m_iNumBones];
|
||||
ZeroMemory(m_pBoneMatrices, sizeof(_float4x4) * m_iNumBones);
|
||||
}
|
||||
{ // Vertex Buffer
|
||||
HRESULT hr = (m_iVertexStride == sizeof(VTXMESH)) ?
|
||||
Ready_VertexBuffer_For_NonAnim(hFile, dwByte) :
|
||||
Ready_VertexBuffer_For_Anim(hFile, dwByte);
|
||||
}
|
||||
{ // Index Buffer
|
||||
D3D11_BUFFER_DESC IBDesc{};
|
||||
if (!ReadFile(hFile, &IBDesc, sizeof(D3D11_BUFFER_DESC), &dwByte, nullptr)) {
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
_uint* pIndices = new _uint[m_iNumIndices];
|
||||
ZeroMemory(pIndices, sizeof(_uint) * m_iNumIndices);
|
||||
|
||||
if (!ReadFile(hFile, pIndices, IBDesc.ByteWidth, &dwByte, nullptr)) {
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
D3D11_SUBRESOURCE_DATA InitialIBData{};
|
||||
InitialIBData.pSysMem = pIndices;
|
||||
|
||||
if (FAILED(m_pDevice->CreateBuffer(&IBDesc, &InitialIBData, &m_pIB))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
Safe_Delete_Array(pIndices);
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CMesh::Ready_VertexBuffer_For_NonAnim(HANDLE hFile, DWORD& dwByte)
|
||||
{
|
||||
D3D11_BUFFER_DESC VBDesc{};
|
||||
if (!ReadFile(hFile, &VBDesc, sizeof(D3D11_BUFFER_DESC), &dwByte, nullptr)) {
|
||||
return E_FAIL;
|
||||
}
|
||||
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);
|
||||
if (!ReadFile(hFile, pVertices, VBDesc.ByteWidth, &dwByte, nullptr)) {
|
||||
return E_FAIL;
|
||||
}
|
||||
for (_uint i = 0; i < m_iNumVertices; ++i) {
|
||||
m_pVertexPositions[i] = pVertices[i].vPosition;
|
||||
}
|
||||
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(HANDLE hFile, DWORD& dwByte)
|
||||
{
|
||||
D3D11_BUFFER_DESC VBDesc{};
|
||||
if (!ReadFile(hFile, &VBDesc, sizeof(D3D11_BUFFER_DESC), &dwByte, nullptr)) {
|
||||
return E_FAIL;
|
||||
}
|
||||
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);
|
||||
if (!ReadFile(hFile, pVertices, VBDesc.ByteWidth, &dwByte, nullptr)) {
|
||||
return E_FAIL;
|
||||
}
|
||||
for (_uint i = 0; i < m_iNumVertices; ++i) {
|
||||
m_pVertexPositions[i] = pVertices[i].vPosition;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -114,22 +259,92 @@ HRESULT CMesh::Initialize(void* pArg)
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CMesh::Bind_BoneMatrices(const vector<CBone*>& Bones, CShader* pShader, const _char* pConstantName)
|
||||
#ifdef EDITOR_PROJECT
|
||||
CMesh* CMesh::Create(ID3D11Device* pDevice, ID3D11DeviceContext* pContext, MODEL eType, vector<class CBone*>& Bones, const aiMesh* pAIMesh, _fmatrix& PreTransformMatrix)
|
||||
{
|
||||
if (m_iNumBones >= 512)
|
||||
return E_FAIL;
|
||||
CMesh* pInstance = new CMesh(pDevice, pContext);
|
||||
|
||||
|
||||
for (size_t i = 0; i < m_iNumBones; i++)
|
||||
if (FAILED(pInstance->Initialize_Prototype(eType, Bones, pAIMesh, PreTransformMatrix)))
|
||||
{
|
||||
XMStoreFloat4x4(&m_pBoneMatrices[i], XMLoadFloat4x4(&m_OffsetMatrices[i]) * Bones[m_BoneIndices[i]]->Get_CombinedTransformationMatrix());
|
||||
MSG_BOX("Failed to Created : CMesh");
|
||||
SAFE_RELEASE(pInstance);
|
||||
}
|
||||
|
||||
if (0 == m_iNumBones)
|
||||
return S_OK;
|
||||
return pInstance;
|
||||
}
|
||||
|
||||
return pShader->Bind_Matrices(pConstantName, m_pBoneMatrices, m_iNumBones);
|
||||
HRESULT CMesh::SaveAsBinary(HANDLE hFile, DWORD& dwByte)
|
||||
{
|
||||
{ // 멤버변수
|
||||
WriteFile(hFile, &m_iMaterialIndex, sizeof(_uint), &dwByte, nullptr);
|
||||
WriteFile(hFile, &m_iNumVertexBuffers, sizeof(_uint), &dwByte, nullptr);
|
||||
WriteFile(hFile, &m_iNumVertices, sizeof(_uint), &dwByte, nullptr);
|
||||
WriteFile(hFile, &m_iVertexStride, sizeof(_uint), &dwByte, nullptr);
|
||||
WriteFile(hFile, &m_iNumIndices, sizeof(_uint), &dwByte, nullptr);
|
||||
WriteFile(hFile, &m_iIndexStride, sizeof(_uint), &dwByte, nullptr);
|
||||
WriteFile(hFile, &m_iNumBones, sizeof(_uint), &dwByte, nullptr);
|
||||
WriteFile(hFile, &m_eIndexFormat, sizeof(DXGI_FORMAT), &dwByte, nullptr);
|
||||
WriteFile(hFile, &m_ePrimitive, sizeof(D3D_PRIMITIVE_TOPOLOGY), &dwByte, nullptr);
|
||||
|
||||
DWORD iSize = (DWORD)(sizeof(_int) * m_BoneIndices.size());
|
||||
WriteFile(hFile, &iSize, sizeof(DWORD), &dwByte, nullptr);
|
||||
WriteFile(hFile, m_BoneIndices.data(), iSize, &dwByte, nullptr);
|
||||
|
||||
iSize = (DWORD)(sizeof(_float4x4) * m_offsetMatrices.size());
|
||||
WriteFile(hFile, &iSize, sizeof(DWORD), &dwByte, nullptr);
|
||||
WriteFile(hFile, m_offsetMatrices.data(), iSize, &dwByte, nullptr);
|
||||
}
|
||||
{ // Vertex Buffer
|
||||
D3D11_BUFFER_DESC VBDesc{};
|
||||
m_pVB->GetDesc(&VBDesc); // 버퍼 디스크립션 저장
|
||||
WriteFile(hFile, &VBDesc, sizeof(D3D11_BUFFER_DESC), &dwByte, nullptr);
|
||||
|
||||
D3D11_BUFFER_DESC StagingDesc{};
|
||||
StagingDesc.Usage = D3D11_USAGE_STAGING;
|
||||
StagingDesc.ByteWidth = VBDesc.ByteWidth;
|
||||
StagingDesc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
|
||||
StagingDesc.BindFlags = 0;
|
||||
StagingDesc.MiscFlags = 0;
|
||||
|
||||
ID3D11Buffer* pStaging = nullptr;
|
||||
if (FAILED(m_pDevice->CreateBuffer(&StagingDesc, nullptr, &pStaging)) || nullptr == pStaging) {
|
||||
return E_FAIL;
|
||||
}
|
||||
m_pContext->CopyResource(pStaging, m_pVB); // 버퍼 복사
|
||||
|
||||
D3D11_MAPPED_SUBRESOURCE mapped{};
|
||||
m_pContext->Map(pStaging, 0, D3D11_MAP_READ, 0, &mapped);
|
||||
WriteFile(hFile, mapped.pData, VBDesc.ByteWidth, &dwByte, nullptr);
|
||||
|
||||
m_pContext->Unmap(pStaging, 0);
|
||||
pStaging->Release();
|
||||
}
|
||||
{ // Index Buffer
|
||||
D3D11_BUFFER_DESC IBDesc{};
|
||||
m_pIB->GetDesc(&IBDesc);
|
||||
WriteFile(hFile, &IBDesc, sizeof(D3D11_BUFFER_DESC), &dwByte, nullptr);
|
||||
|
||||
D3D11_BUFFER_DESC StagingDesc{};
|
||||
StagingDesc.Usage = D3D11_USAGE_STAGING;
|
||||
StagingDesc.ByteWidth = IBDesc.ByteWidth;
|
||||
StagingDesc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
|
||||
StagingDesc.BindFlags = 0;
|
||||
StagingDesc.MiscFlags = 0;
|
||||
|
||||
ID3D11Buffer* pStaging = nullptr;
|
||||
if (FAILED(m_pDevice->CreateBuffer(&StagingDesc, nullptr, &pStaging)) || nullptr == pStaging) {
|
||||
return E_FAIL;
|
||||
}
|
||||
m_pContext->CopyResource(pStaging, m_pIB);
|
||||
|
||||
D3D11_MAPPED_SUBRESOURCE mapped{};
|
||||
m_pContext->Map(pStaging, 0, D3D11_MAP_READ, 0, &mapped);
|
||||
WriteFile(hFile, mapped.pData, IBDesc.ByteWidth, &dwByte, nullptr);
|
||||
|
||||
m_pContext->Unmap(pStaging, 0);
|
||||
pStaging->Release();
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CMesh::Ready_VertexBuffer_For_NonAnim(const aiMesh* pAIMesh, _fmatrix PreTransformMatrix)
|
||||
@@ -153,37 +368,13 @@ HRESULT CMesh::Ready_VertexBuffer_For_NonAnim(const aiMesh* pAIMesh, _fmatrix Pr
|
||||
{
|
||||
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);
|
||||
}
|
||||
memcpy(&pVertices[i].vNormal, &pAIMesh->mNormals[i], sizeof(_float3));
|
||||
XMStoreFloat3(&pVertices[i].vNormal, XMVector3Normalize(XMVector3TransformNormal(XMLoadFloat3(&pVertices[i].vNormal), PreTransformMatrix)));
|
||||
memcpy(&pVertices[i].vTangent, &pAIMesh->mTangents[i], sizeof(_float3));
|
||||
XMStoreFloat3(&pVertices[i].vTangent, XMVector3Normalize(XMVector3TransformNormal(XMLoadFloat3(&pVertices[i].vTangent), PreTransformMatrix)));
|
||||
memcpy(&pVertices[i].vBinormal, &pAIMesh->mBitangents[i], sizeof(_float3));
|
||||
XMStoreFloat3(&pVertices[i].vBinormal, XMVector3Normalize(XMVector3TransformNormal(XMLoadFloat3(&pVertices[i].vBinormal), PreTransformMatrix)));
|
||||
memcpy(&pVertices[i].vTexcoord, &pAIMesh->mTextureCoords[0][i], sizeof(_float2));
|
||||
}
|
||||
|
||||
D3D11_SUBRESOURCE_DATA InitialVBData{};
|
||||
@@ -197,7 +388,7 @@ HRESULT CMesh::Ready_VertexBuffer_For_NonAnim(const aiMesh* pAIMesh, _fmatrix Pr
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CMesh::Ready_VertexBuffer_For_Anim(const CModel* pModel, const aiMesh* pAIMesh)
|
||||
HRESULT CMesh::Ready_VertexBuffer_For_Anim(vector<class CBone*>& Bones, const aiMesh* pAIMesh)
|
||||
{
|
||||
m_iVertexStride = sizeof(VTXANIMMESH);
|
||||
D3D11_BUFFER_DESC VBDesc{};
|
||||
@@ -217,96 +408,62 @@ HRESULT CMesh::Ready_VertexBuffer_For_Anim(const CModel* pModel, const aiMesh* p
|
||||
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);
|
||||
}
|
||||
memcpy(&pVertices[i].vNormal, &pAIMesh->mNormals[i], sizeof(_float3));
|
||||
memcpy(&pVertices[i].vTangent, &pAIMesh->mTangents[i], sizeof(_float3));
|
||||
memcpy(&pVertices[i].vBinormal, &pAIMesh->mBitangents[i], sizeof(_float3));
|
||||
memcpy(&pVertices[i].vTexcoord, &pAIMesh->mTextureCoords[0][i], sizeof(_float2));
|
||||
}
|
||||
|
||||
m_iNumBones = pAIMesh->mNumBones;
|
||||
|
||||
m_OffsetMatrices.reserve(m_iNumBones);
|
||||
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());
|
||||
_float4x4 OffSetMatrix;
|
||||
XMStoreFloat4x4(&OffSetMatrix, XMMatrixIdentity());
|
||||
|
||||
for (_uint i = 0; i < m_iNumBones; i++)
|
||||
{
|
||||
for (_uint i = 0; i < m_iNumBones; ++i) {
|
||||
aiBone* pAIBone = pAIMesh->mBones[i];
|
||||
_uint iNumWeight = pAIBone->mNumWeights;
|
||||
|
||||
memcpy(&OffsetMatrix, &pAIBone->mOffsetMatrix, sizeof(_float4x4));
|
||||
XMStoreFloat4x4(&OffsetMatrix, XMMatrixTranspose(XMLoadFloat4x4(&OffsetMatrix)));
|
||||
memcpy(&OffSetMatrix, &pAIBone->mOffsetMatrix, sizeof(_float4x4));
|
||||
XMStoreFloat4x4(&OffSetMatrix, XMMatrixTranspose(XMLoadFloat4x4(&OffSetMatrix)));
|
||||
|
||||
_int iBoneIndex = pModel->Get_BoneIndex(pAIBone->mName.data);
|
||||
_int iBoneIndex = CModel::Get_BoneIndex(pAIBone->mName.data, Bones);
|
||||
|
||||
if (-1 == iBoneIndex)
|
||||
if (-1 == iBoneIndex) {
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
m_OffsetMatrices.push_back(OffsetMatrix);
|
||||
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)
|
||||
{
|
||||
for (_uint j = 0; j < iNumWeight; ++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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
else if (0.f == pVertices[AIWeight.mVertexId].vBlendWeight.z) {
|
||||
pVertices[AIWeight.mVertexId].vBlendIndex.z = i;
|
||||
pVertices[AIWeight.mVertexId].vBlendWeight.z = AIWeight.mWeight;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
else {
|
||||
pVertices[AIWeight.mVertexId].vBlendIndex.w = i;
|
||||
pVertices[AIWeight.mVertexId].vBlendWeight.w = AIWeight.mWeight;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (0 == m_iNumBones)
|
||||
{
|
||||
if (0 == m_iNumBones) {
|
||||
m_iNumBones = 1;
|
||||
|
||||
m_BoneIndices.push_back(pModel->Get_BoneIndex(m_szName));
|
||||
|
||||
m_OffsetMatrices.push_back(OffsetMatrix);
|
||||
m_BoneIndices.push_back(CModel::Get_BoneIndex(m_szName, Bones));
|
||||
m_offsetMatrices.push_back(OffSetMatrix);
|
||||
}
|
||||
|
||||
D3D11_SUBRESOURCE_DATA InitialVBData{};
|
||||
@@ -319,28 +476,29 @@ HRESULT CMesh::Ready_VertexBuffer_For_Anim(const CModel* pModel, const aiMesh* p
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
CMesh* CMesh::Create(ID3D11Device* pDevice, ID3D11DeviceContext* pContext, MODEL eType, const CModel* pModel, const aiMesh* pAIMesh, _fmatrix PreTransformMatrix)
|
||||
CMesh* CMesh::Create(ID3D11Device* pDevice, ID3D11DeviceContext* pContext, HANDLE hFile, DWORD& dwByte)
|
||||
{
|
||||
CMesh* pInstance = new CMesh(pDevice, pContext);
|
||||
|
||||
if (FAILED(pInstance->Initialize_Prototype(eType, pModel, pAIMesh, PreTransformMatrix)))
|
||||
if (FAILED(pInstance->Initialize_Prototype(hFile, dwByte)))
|
||||
{
|
||||
MSG_BOX("Failed to Created : CMesh");
|
||||
Safe_Release(pInstance);
|
||||
SAFE_RELEASE(pInstance);
|
||||
}
|
||||
|
||||
return pInstance;
|
||||
}
|
||||
|
||||
CComponent* CMesh::Clone(void* pArg, CGameObject* pOwner)
|
||||
CMesh* CMesh::Clone(void* pArg, class CGameObject* pOwner)
|
||||
{
|
||||
CMesh* pInstance = new CMesh(*this);
|
||||
|
||||
pInstance->m_pOwner = pOwner;
|
||||
if (FAILED(pInstance->Initialize(pArg)))
|
||||
{
|
||||
MSG_BOX("Failed to Cloned : CMesh");
|
||||
Safe_Release(pInstance);
|
||||
SAFE_RELEASE(pInstance);
|
||||
}
|
||||
|
||||
return pInstance;
|
||||
@@ -350,8 +508,6 @@ void CMesh::Free()
|
||||
__super::Free();
|
||||
|
||||
Safe_Delete_Array(m_pBoneMatrices);
|
||||
|
||||
|
||||
}
|
||||
|
||||
void CMesh::Describe_Entity()
|
||||
|
||||
@@ -1,62 +1,221 @@
|
||||
#include "pch.h"
|
||||
#include "Model.h"
|
||||
#include "Mesh.h"
|
||||
#include "Shader.h"
|
||||
#include "Material.h"
|
||||
#include "Bone.h"
|
||||
#include "Mesh.h"
|
||||
#include "Material.h"
|
||||
#include "Animation.h"
|
||||
#include "LerpAnim.h"
|
||||
#include "GameObject.h"
|
||||
|
||||
CModel::CModel(ID3D11Device* pDevice, ID3D11DeviceContext* pContext)
|
||||
: CComponent( pDevice, 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 }
|
||||
CModel::CModel(const CModel& rhs)
|
||||
: CComponent(rhs),
|
||||
m_eType(rhs.m_eType),
|
||||
m_PreTransformMatrix(rhs.m_PreTransformMatrix),
|
||||
m_iRootBoneIndex(rhs.m_iRootBoneIndex),
|
||||
m_Meshes(rhs.m_Meshes),
|
||||
m_iNumMeshes(rhs.m_iNumMeshes),
|
||||
m_Materials(rhs.m_Materials),
|
||||
m_iNumMaterials(rhs.m_iNumMaterials),
|
||||
m_iNumAnimations(rhs.m_iNumAnimations),
|
||||
m_pLerpAnim(rhs.m_pLerpAnim)
|
||||
{
|
||||
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());
|
||||
_uint iNumBones = (_uint)(rhs.m_Bones.size());
|
||||
m_Bones.reserve(iNumBones);
|
||||
for (_uint i = 0; i < iNumBones; ++i) {
|
||||
m_Bones.push_back(rhs.m_Bones[i]->Clone());
|
||||
}
|
||||
for (auto& pMesh : m_Meshes) {
|
||||
SAFE_ADDREF(pMesh);
|
||||
}
|
||||
for (auto& pMat : m_Materials) {
|
||||
SAFE_ADDREF(pMat);
|
||||
}
|
||||
m_Animations.reserve(m_iNumAnimations);
|
||||
for (_uint i = 0; i < m_iNumAnimations; ++i) {
|
||||
m_Animations.push_back(rhs.m_Animations[i]->Clone()); // 멤버 전부 얕은복사.
|
||||
}
|
||||
}
|
||||
|
||||
_int CModel::Get_BoneIndex(const _char* pBoneName) const
|
||||
_int CModel::Get_BoneIndex(const _char* pBoneName, vector<class CBone*> Bones)
|
||||
{
|
||||
_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;
|
||||
_int iBoneIndex = {};
|
||||
vector<CBone*>::const_iterator iter = find_if(Bones.begin(), Bones.end(), [&](CBone* pBone)->_bool {
|
||||
if (true == pBone->Compare_Name(pBoneName)) {
|
||||
return true;
|
||||
}
|
||||
++iBoneIndex;
|
||||
return false;
|
||||
});
|
||||
if (iter == Bones.end()) {
|
||||
|
||||
if (iter == m_Bones.end())
|
||||
return -1;
|
||||
}
|
||||
|
||||
return iBoneIndex;
|
||||
}
|
||||
|
||||
void CModel::Change_AnimationIndex(_int iAnimationIndex, _bool bIsLoop, _float fLerpDuration, _bool bIgnoreCurrentIndex)
|
||||
{
|
||||
if (false == bIgnoreCurrentIndex && m_iCurrentAnimIndex == iAnimationIndex) { return; }
|
||||
m_iCurrentAnimIndex = iAnimationIndex;
|
||||
m_bIsLoop = bIsLoop;
|
||||
RefreshAnim();
|
||||
|
||||
m_PrevAnimationMatrix = Get_BoneMatrix(m_iRootBoneIndex);
|
||||
|
||||
|
||||
m_Animations[m_iCurrentAnimIndex]->Depart_Animation(); // 애니메이션 종료 이벤트 ( 럴프애님은 자체적으로 불림 )
|
||||
vector<_int>* BeforeAnimIndex = m_Animations[m_iCurrentAnimIndex]->Capture_Bones(); // 영향을 받는 본 인덱스 추출 1
|
||||
vector<_int>* AfterAnimIndex = m_Animations[iAnimationIndex]->Capture_Bones(); // 영향을 받는 본 인덱스 추출 2
|
||||
unordered_set<_int> UnionAnimIndex = {};
|
||||
|
||||
vector<LERPDESC> LerpStartFrames;
|
||||
for (_int i : *BeforeAnimIndex) {
|
||||
UnionAnimIndex.insert(i);
|
||||
}
|
||||
for (_int i : *AfterAnimIndex) {
|
||||
UnionAnimIndex.insert(i);
|
||||
}
|
||||
LerpStartFrames.reserve(UnionAnimIndex.size()); // 영향을 받는 모든 현재 본을 가져옴
|
||||
|
||||
// 스타팅 키프레임 채우기 pair < 본 인덱스, 키프레임 >
|
||||
for (auto iter = UnionAnimIndex.begin(); iter != UnionAnimIndex.end(); ++iter) {
|
||||
LERPDESC desc = {};
|
||||
desc.iSlot = *iter;
|
||||
m_Bones[desc.iSlot]->Get_KeyFrame(desc.tagKeyFrame, true); // 스타팅 키프레임 채우기
|
||||
LerpStartFrames.emplace_back(desc);
|
||||
}
|
||||
|
||||
// 엔딩 키프레임 채우기 pair < 본인덱스, 키프레임 >
|
||||
vector<LERPDESC> LerpEndFrames = m_Animations[iAnimationIndex]->Get_StartFrameInformations();
|
||||
|
||||
// 럴프 애니메이션 시작
|
||||
m_pLerpAnim->Begin(m_Bones, LerpStartFrames, LerpEndFrames, fLerpDuration, m_iRootBoneIndex);
|
||||
|
||||
}
|
||||
HRESULT CModel::Bind_Material(_uint iMeshIndex, CShader* pShader, const _char* pConstantName, _uint iType, _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, iType, iTextureIndex);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
_bool CModel::Play_Animation(_float fTimeDelta)
|
||||
{
|
||||
if (-1 == m_iCurrentAnimIndex // 정지 혹은 시작을 안시켜준 애님
|
||||
|| m_iCurrentAnimIndex >= (_int)m_iNumAnimations) // 애님 인덱스 초과됨
|
||||
{
|
||||
return false; // 잘못된 초기화
|
||||
}
|
||||
|
||||
if (true == m_pLerpAnim->IsLerping()) { // 럴프중이면 자동으로 럴프 Update를 부름
|
||||
m_bIsFinishedLerp = m_pLerpAnim->Update_TransformationMatrices(m_Bones, fTimeDelta);
|
||||
}
|
||||
else { // 럴프중이지 않다면 실제 애니메이션 재생을 시작함
|
||||
m_bIsFinishedAnim = m_Animations[m_iCurrentAnimIndex]->Update_TransformationMatrices(m_Bones, m_bIsLoop, fTimeDelta);
|
||||
}
|
||||
|
||||
for (int i = 0; i < m_Bones.size(); ++i)
|
||||
{
|
||||
m_Bones[i]->Update_CombinedTransformationMatrix(m_Bones, XMLoadFloat4x4(&m_PreTransformMatrix));
|
||||
|
||||
if (i == m_iRootBoneIndex) { // 루트본의 매트릭스를 갱신했다면 애니메이션에 맞게 이동량을 루트본에서 트랜스폼으로 보정시킴
|
||||
if (true == m_pLerpAnim->IsLerping()) { // 럴프중이었으면 이동량 반영 x
|
||||
_matrix currAnimMatrix = Get_BoneMatrix(m_iRootBoneIndex);
|
||||
currAnimMatrix.r[3] = XMVectorSet(0.f, 0.f, 0.f, 1.f);
|
||||
m_Bones[i]->Set_CombinedTransformationMatrixPtr(currAnimMatrix);
|
||||
}
|
||||
else {
|
||||
_matrix currAnimMatrix = Get_BoneMatrix(m_iRootBoneIndex); // 현재 루트본의 컴바인드 트랜스폼을 꺼내오고
|
||||
_matrix deltaAnimMatrix = XMMatrixMultiply(XMMatrixInverse(nullptr, m_PrevAnimationMatrix), currAnimMatrix); // 이전 트랜스폼이랑 비교해서 델타매트릭스를 꺼냄
|
||||
_vector momentum = XMMatrixMultiply(deltaAnimMatrix, XMMatrixRotationQuaternion(m_pTransform->Get_QuarternionVector())).r[3];
|
||||
deltaAnimMatrix.r[3] = XMVectorSetW(momentum, 0.f);
|
||||
|
||||
m_pTransform->AccumulateMomentum(deltaAnimMatrix.r[3]); // 모체 트랜스폼에 이동량 반영
|
||||
//m_pTransform->Set_State(STATE::POSITION, m_pTransform->Get_State(STATE::POSITION) + deltaAnimMatrix.r[3]);
|
||||
|
||||
m_PrevAnimationMatrix = currAnimMatrix;
|
||||
currAnimMatrix.r[3] = XMVectorSet(0.f, 0.f, 0.f, 1.f);
|
||||
m_Bones[i]->Set_CombinedTransformationMatrixPtr(currAnimMatrix); // 루트본의 이동량 소거
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return m_bIsFinishedAnim;
|
||||
}
|
||||
|
||||
void CModel::Stop_Animation()
|
||||
{
|
||||
if (-1 == m_iCurrentAnimIndex // 정지 혹은 시작을 안시켜준 애님
|
||||
|| m_iCurrentAnimIndex >= (_int)m_iNumAnimations) // 애님 인덱스 초과됨
|
||||
{
|
||||
return; // 잘못된 초기화
|
||||
}
|
||||
|
||||
m_Animations[m_iCurrentAnimIndex]->Depart_Animation(); // 애님이 퇴근할 때 불리는 함수를 부르면서 초기상태로 되돌림
|
||||
}
|
||||
|
||||
void CModel::RefreshAnim()
|
||||
{
|
||||
m_bIsFinishedAnim = false;
|
||||
m_bIsFinishedLerp = false;
|
||||
}
|
||||
_float CModel::Get_AnimProgressRatio()
|
||||
{
|
||||
return m_Animations[m_iCurrentAnimIndex]->Get_AnimProgressRatio();
|
||||
}
|
||||
_int CModel::Get_AnimProgressPostion(const char* pAnimChannelName)
|
||||
{
|
||||
return m_Animations[m_iCurrentAnimIndex]->Get_AnimProgressPostion(pAnimChannelName);
|
||||
}
|
||||
_float CModel::Get_AnimEstimatedDuration()
|
||||
{
|
||||
if (MODEL::ANIM == m_eType) {
|
||||
return m_Animations[m_iCurrentAnimIndex]->Get_AnimEstimatedDuration();
|
||||
}
|
||||
else {
|
||||
return 0.f;
|
||||
}
|
||||
|
||||
}
|
||||
void CModel::Set_AnimProgressPostion(const _char* pChannelName, _uint iPosition)
|
||||
{
|
||||
return m_Animations[m_iCurrentAnimIndex]->Set_AnimProgressPostion(pChannelName, iPosition);
|
||||
}
|
||||
void CModel::Set_AnimPauseState(_bool bValue) {
|
||||
m_Animations[m_iCurrentAnimIndex]->Set_AnimPause(bValue);
|
||||
}
|
||||
|
||||
void CModel::ReallocateResources(CTransform* pTransform)
|
||||
{
|
||||
SAFE_RELEASE(m_pTransform);
|
||||
m_pTransform = pTransform;
|
||||
SAFE_ADDREF(m_pTransform);
|
||||
}
|
||||
|
||||
const _float4x4* CModel::Get_BoneMatrixPtr(const _char* pBoneName) const
|
||||
{
|
||||
auto iter = find_if(m_Bones.begin(), m_Bones.end(), [&](CBone* pBone)->_bool
|
||||
vector<CBone*>::const_iterator iter = find_if(m_Bones.begin(), m_Bones.end(), [&](CBone* pBone)->_bool
|
||||
{
|
||||
if (true == pBone->Compare_Name(pBoneName))
|
||||
return true;
|
||||
@@ -68,108 +227,20 @@ const _float4x4* CModel::Get_BoneMatrixPtr(const _char* pBoneName) const
|
||||
return (*iter)->Get_CombinedTransformationMatrixPtr();
|
||||
}
|
||||
|
||||
HRESULT CModel::Initialize_Prototype(MODEL eType, const _char* pModelFilePath, _fmatrix PreTransformMatrix)
|
||||
|
||||
_matrix CModel::Get_BoneMatrix(_uint iBoneIndex)
|
||||
{
|
||||
_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;
|
||||
return m_Bones[iBoneIndex]->Get_CombinedTransformationMatrix();
|
||||
}
|
||||
|
||||
HRESULT CModel::Initialize(void* pArg)
|
||||
void CModel::Get_BoneMatrices(_float4x4* pOut)
|
||||
{
|
||||
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;
|
||||
}
|
||||
if (0 == m_Bones.size()) {
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_isFinish = m_Animations[m_iCurrentAnimIndex]->Update_TransformationMatrices(fTimeDelta, m_isLoop, m_Bones);
|
||||
for (_uint i = 0; i < m_Bones.size(); ++i) {
|
||||
pOut[i] = *m_Bones[i]->Get_CombinedTransformationMatrixPtr();
|
||||
}
|
||||
|
||||
|
||||
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)
|
||||
@@ -180,63 +251,57 @@ HRESULT CModel::Render(_uint iMeshIndex)
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CModel::Ready_Meshes()
|
||||
HRESULT CModel::Render_Indexed(_uint iMeshIndex, _uint IndexCount, _uint StartIndexLocation, _uint BaseVertexLocation)
|
||||
{
|
||||
m_iNumMeshes = m_pAIScene->mNumMeshes;
|
||||
m_Meshes[iMeshIndex]->Bind_Resources();
|
||||
m_Meshes[iMeshIndex]->Render_Indexed(IndexCount, StartIndexLocation, BaseVertexLocation);
|
||||
|
||||
for (size_t i = 0; i < m_iNumMeshes; i++)
|
||||
return S_OK;
|
||||
}
|
||||
#ifdef EDITOR_PROJECT
|
||||
|
||||
HRESULT CModel::Ready_Meshes(MODEL eType, const aiScene* pAIScene, _fmatrix& PreTransformMatrix)
|
||||
{
|
||||
XMStoreFloat4x4(&m_PreTransformMatrix, PreTransformMatrix);
|
||||
m_iNumMeshes = pAIScene->mNumMeshes;
|
||||
|
||||
m_Meshes.reserve(m_iNumMeshes);
|
||||
|
||||
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)
|
||||
CMesh* pMesh = CMesh::Create(m_pDevice, m_pContext, eType, m_Bones, pAIScene->mMeshes[i], PreTransformMatrix);
|
||||
if (nullptr == pMesh) {
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
m_Meshes.push_back(pMesh);
|
||||
}
|
||||
|
||||
m_Meshes.shrink_to_fit();
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CModel::Ready_Materials(const _char* pModelFilePath)
|
||||
HRESULT CModel::Ready_Materials(const aiScene* pAIScene, 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)
|
||||
m_iNumMaterials = pAIScene->mNumMaterials;
|
||||
m_Materials.reserve(m_iNumMaterials);
|
||||
for (size_t i = 0; i < m_iNumMaterials; ++i) {
|
||||
CMaterial* pMaterial = CMaterial::Create(m_pDevice, m_pContext, pModelFilePath, pAIScene->mMaterials[i]);
|
||||
if (nullptr == pMaterial) {
|
||||
return E_FAIL;
|
||||
|
||||
}
|
||||
m_Materials.push_back(pMaterial);
|
||||
}
|
||||
|
||||
m_Materials.shrink_to_fit();
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CModel::Ready_Bones(const aiNode* pAINode, _int iParentIndex)
|
||||
HRESULT CModel::Ready_Animations(const aiScene* pAIScene)
|
||||
{
|
||||
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;
|
||||
|
||||
m_iNumAnimations = pAIScene->mNumAnimations;
|
||||
m_Animations.reserve(m_iNumAnimations);
|
||||
for (size_t i = 0; i < m_iNumAnimations; i++)
|
||||
{
|
||||
CAnimation* pAnimation = CAnimation::Create(this, m_pAIScene->mAnimations[i]);
|
||||
CAnimation* pAnimation = CAnimation::Create(m_Bones, pAIScene->mAnimations[i]);
|
||||
if (nullptr == pAnimation)
|
||||
return E_FAIL;
|
||||
|
||||
@@ -246,27 +311,123 @@ HRESULT CModel::Ready_Animations()
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
CModel* CModel::Create(ID3D11Device* pDevice, ID3D11DeviceContext* pContext, MODEL eType, const _char* pModelFilePath, _fmatrix PreTransformMatrix)
|
||||
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 (size_t i = 0; i < pAINode->mNumChildren; i++)
|
||||
{
|
||||
Ready_Bones(pAINode->mChildren[i], iParent);
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
#endif // EDITOR_PROJECT
|
||||
|
||||
HRESULT CModel::Initialize_Prototype()
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CModel::Initialize_Prototype(const _char* pModelFilePath, MODEL eType, _fmatrix& PreTransformMatrix, _uint iRootBoneIndex)
|
||||
{
|
||||
return Assimp_Model_Load(pModelFilePath, eType, PreTransformMatrix, iRootBoneIndex);
|
||||
}
|
||||
|
||||
CModel* CModel::Create(ID3D11Device* pDevice, ID3D11DeviceContext* pContext, const _char* pModelFilePath, MODEL eType, _fmatrix& PreTransformMatrix, _uint iRootBoneIndex)
|
||||
{
|
||||
CModel* pInstance = new CModel(pDevice, pContext);
|
||||
|
||||
if (FAILED(pInstance->Initialize_Prototype(eType, pModelFilePath, PreTransformMatrix)))
|
||||
if (FAILED(pInstance->Initialize_Prototype(pModelFilePath, eType, PreTransformMatrix, iRootBoneIndex)))
|
||||
{
|
||||
MSG_BOX("Failed to Created : CModel");
|
||||
Safe_Release(pInstance);
|
||||
SAFE_RELEASE(pInstance);
|
||||
}
|
||||
|
||||
return pInstance;
|
||||
}
|
||||
|
||||
CComponent* CModel::Clone(void* pArg, CGameObject* pOwner)
|
||||
HRESULT CModel::Assimp_Model_Load(const _char* pModelFilePath, MODEL eType, _fmatrix& PreTransformMatrix, _uint iRootBoneIndex)
|
||||
{
|
||||
_uint iFlag = {};
|
||||
iFlag = aiProcess_ConvertToLeftHanded | aiProcessPreset_TargetRealtime_Fast;
|
||||
|
||||
if (MODEL::NONANIM == eType) {
|
||||
iFlag |= aiProcess_PreTransformVertices;
|
||||
}
|
||||
m_iRootBoneIndex = iRootBoneIndex;
|
||||
|
||||
Assimp::Importer Importer = {};
|
||||
const aiScene* pAIScene = { nullptr };
|
||||
|
||||
pAIScene = Importer.ReadFile(pModelFilePath, iFlag);
|
||||
if (nullptr == pAIScene) {
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
#pragma region Bone
|
||||
if (FAILED(Ready_Bones(pAIScene->mRootNode, -1))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
#pragma endregion
|
||||
#pragma region Mesh
|
||||
if (FAILED(Ready_Meshes(eType, pAIScene, PreTransformMatrix))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
#pragma endregion
|
||||
#pragma region Material
|
||||
if (FAILED(Ready_Materials(pAIScene, pModelFilePath))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
#pragma endregion
|
||||
#pragma region Animation
|
||||
if (FAILED(Ready_Animations(pAIScene))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
#pragma endregion
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CModel::Initialize(void* pArg)
|
||||
{
|
||||
m_pLerpAnim = CLerpAnim::Create((_uint)m_Bones.size(), 1.f, m_Bones);
|
||||
if (nullptr == m_pLerpAnim) {
|
||||
return E_FAIL;
|
||||
}
|
||||
m_pTransform = m_pOwner->Get_Component<CTransform>();
|
||||
SAFE_ADDREF(m_pTransform);
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
CModel* CModel::Create(ID3D11Device* pDevice, ID3D11DeviceContext* pContext)
|
||||
{
|
||||
CModel* pInstance = new CModel(pDevice, pContext);
|
||||
|
||||
if (FAILED(pInstance->Initialize_Prototype()))
|
||||
{
|
||||
MSG_BOX("Failed to Created : CModel");
|
||||
SAFE_RELEASE(pInstance);
|
||||
}
|
||||
|
||||
return pInstance;
|
||||
}
|
||||
|
||||
CComponent* CModel::Clone(void* pArg, class CGameObject* pOwner)
|
||||
{
|
||||
CModel* pInstance = new CModel(*this);
|
||||
|
||||
pInstance->m_pOwner = pOwner;
|
||||
if (FAILED(pInstance->Initialize(pArg)))
|
||||
{
|
||||
MSG_BOX("Failed to Cloned : CModel");
|
||||
Safe_Release(pInstance);
|
||||
SAFE_RELEASE(pInstance);
|
||||
}
|
||||
|
||||
return pInstance;
|
||||
@@ -277,25 +438,73 @@ 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);
|
||||
for (auto& pAnimation : m_Animations) {
|
||||
SAFE_RELEASE(pAnimation);
|
||||
}
|
||||
m_Animations.clear();
|
||||
|
||||
m_Importer.FreeScene();
|
||||
for (auto& pMesh : m_Meshes) {
|
||||
SAFE_RELEASE(pMesh);
|
||||
}
|
||||
m_Meshes.clear();
|
||||
for (auto& pMaterial : m_Materials) {
|
||||
SAFE_RELEASE(pMaterial);
|
||||
}
|
||||
m_Materials.clear();
|
||||
for (auto& pBone : m_Bones) {
|
||||
SAFE_RELEASE(pBone);
|
||||
}
|
||||
m_Bones.clear();
|
||||
|
||||
SAFE_RELEASE(m_pTransform);
|
||||
SAFE_RELEASE(m_pLerpAnim);
|
||||
}
|
||||
|
||||
void CModel::Describe_Entity()
|
||||
{
|
||||
//GUI::Begin("Model_Desc");
|
||||
//GUI::Text("Lerping : %d\nAnim : %d", m_pLerpAnim->IsLerping(), m_bIsFinishedAnim);
|
||||
//for (_uint i = 0; i < m_iNumAnimations; ++i) {
|
||||
// if (GUI::Button(m_Animations[i]->Get_Name().c_str())) {
|
||||
// Change_AnimationIndex(i, false, 0.25f);
|
||||
// }
|
||||
//}
|
||||
//if (GUI::Button("SaveAnimIndexWithName")) {
|
||||
// _wstring wstrPath = TEXT("../Bin/AnimIndex.txt");
|
||||
// HANDLE hFile = CreateFile(wstrPath.c_str(),
|
||||
// GENERIC_WRITE, NULL,
|
||||
// NULL, CREATE_ALWAYS,
|
||||
// FILE_ATTRIBUTE_NORMAL, NULL
|
||||
// );
|
||||
|
||||
// if (hFile == INVALID_HANDLE_VALUE)
|
||||
// {
|
||||
// GUI::End();
|
||||
// CloseHandle(hFile);
|
||||
// return;
|
||||
// }
|
||||
|
||||
// _string name = {};
|
||||
// for (_uint i = 0; i < m_iNumAnimations; ++i) {
|
||||
//
|
||||
// name.clear();
|
||||
// name.append(to_string(i) + '\t' + m_Animations[i]->Get_Name() + "\n");
|
||||
// name.shrink_to_fit();
|
||||
// WriteFile(hFile, name.data(),(DWORD) name.length(), nullptr, nullptr);
|
||||
// }
|
||||
|
||||
// CloseHandle(hFile);
|
||||
|
||||
//}
|
||||
//GUI::End();
|
||||
//
|
||||
//GUI::Begin("Bone_Desc");
|
||||
//_uint iNumBones = (_uint)m_Bones.size();
|
||||
//for (_uint i = 0; i < iNumBones; ++i){
|
||||
// _float3 vPos = m_Bones[i]->Get_LocalPosition();
|
||||
// GUI::PushID(i);
|
||||
// GUI::DragFloat3(m_Bones[i]->Get_Name(), (_float*)&vPos, 1.f, 0.f, 0.f, "%.3f", ImGuiSliderFlags_NoInput);
|
||||
// GUI::PopID();
|
||||
//}
|
||||
//GUI::End();
|
||||
}
|
||||
|
||||
@@ -92,6 +92,9 @@ HRESULT CPrototype_Manager::Ready_StaticComponents()
|
||||
if (FAILED(Add_Prototype(g_iStaticLevel, CVIBuffer_Rect::Create(m_pDevice, m_pContext)))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
if (FAILED(Add_Prototype(g_iStaticLevel, CVIBuffer_Cube::Create(m_pDevice, m_pContext)))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
@@ -58,22 +58,22 @@ HRESULT CRenderer::Add_RenderGroup(RENDER eRenderGroup, CGameObject* pRenderObje
|
||||
return E_FAIL;
|
||||
|
||||
_bool bPossible = { true };
|
||||
if (pRenderObject->isDead()) {
|
||||
return E_FAIL;
|
||||
}
|
||||
// ÇÁ·¯½ºÅÒÄøµ ¿¹¿Ü Ãß°¡
|
||||
if (RENDER::UI == eRenderGroup || RENDER::PRIORITY == eRenderGroup /* || RENDER::SHADOW == eRenderGroup*/ || RENDER::BLUR == eRenderGroup) {
|
||||
m_RenderObjects[ENUM_CLASS(eRenderGroup)].push_back(pRenderObject);
|
||||
SAFE_ADDREF(pRenderObject);
|
||||
return S_OK;
|
||||
}
|
||||
for (int i = 0; i < 6; ++i) {
|
||||
if (XMVectorGetX(XMVector4Dot(XMLoadFloat4(&m_vPlanes[i]),
|
||||
XMLoadFloat4(&vPos))) + fCullRadius < 0) {
|
||||
bPossible = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
//if (pRenderObject->isDead()) {
|
||||
// return E_FAIL;
|
||||
//}
|
||||
//// ÇÁ·¯½ºÅÒÄøµ ¿¹¿Ü Ãß°¡
|
||||
//if (RENDER::UI == eRenderGroup || RENDER::PRIORITY == eRenderGroup /* || RENDER::SHADOW == eRenderGroup*/ || RENDER::BLUR == eRenderGroup) {
|
||||
// m_RenderObjects[ENUM_CLASS(eRenderGroup)].push_back(pRenderObject);
|
||||
// SAFE_ADDREF(pRenderObject);
|
||||
// return S_OK;
|
||||
//}
|
||||
//for (int i = 0; i < 6; ++i) {
|
||||
// if (XMVectorGetX(XMVector4Dot(XMLoadFloat4(&m_vPlanes[i]),
|
||||
// XMLoadFloat4(&vPos))) + fCullRadius < 0) {
|
||||
// bPossible = false;
|
||||
// break;
|
||||
// }
|
||||
//}
|
||||
if (bPossible) {
|
||||
m_RenderObjects[ENUM_CLASS(eRenderGroup)].push_back(pRenderObject);
|
||||
SAFE_ADDREF(pRenderObject);
|
||||
@@ -113,9 +113,9 @@ void CRenderer::Render()
|
||||
Render_Blend();
|
||||
Render_UI();
|
||||
|
||||
#ifdef _DEBUG
|
||||
Render_Debug();
|
||||
#endif
|
||||
//#ifdef _DEBUG
|
||||
// Render_Debug();
|
||||
//#endif
|
||||
}
|
||||
|
||||
void CRenderer::Render_Priority()
|
||||
|
||||
@@ -2,29 +2,87 @@
|
||||
#include "Shader.h"
|
||||
|
||||
CShader::CShader(ID3D11Device* pDevice, ID3D11DeviceContext* pContext)
|
||||
:CComponent(pDevice, pContext)
|
||||
: CComponent{ pDevice, pContext }
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CShader::CShader(const CShader& rhs)
|
||||
: CComponent(rhs)
|
||||
, m_pEffect{ rhs.m_pEffect }
|
||||
, m_iNumPasses{ rhs.m_iNumPasses }
|
||||
, m_pLayouts{ rhs.m_pLayouts }
|
||||
, m_InputLayouts{ rhs.m_InputLayouts }
|
||||
{
|
||||
SAFE_ADDREF(m_pEffect);
|
||||
Safe_AddRef(m_pEffect);
|
||||
|
||||
for (auto& pInputLayout : m_pLayouts){
|
||||
SAFE_ADDREF(pInputLayout);
|
||||
}
|
||||
for (auto& pInputLayout : m_InputLayouts)
|
||||
Safe_AddRef(pInputLayout);
|
||||
}
|
||||
|
||||
HRESULT CShader::Initialize_Prototype(const _tchar* pShaderFilePath, const D3D11_INPUT_ELEMENT_DESC* pElements, _uint iNumElements)
|
||||
{
|
||||
_uint iHlslFlag = {};
|
||||
|
||||
#ifdef _DEBUG
|
||||
iHlslFlag = D3DCOMPILE_DEBUG | D3DCOMPILE_SKIP_OPTIMIZATION;
|
||||
#else
|
||||
iHlslFlag = D3DCOMPILE_OPTIMIZATION_LEVEL1;
|
||||
#endif
|
||||
|
||||
/*ID3DBlob* pBlob;*/
|
||||
|
||||
if (FAILED(D3DX11CompileEffectFromFile(pShaderFilePath, nullptr, D3D_COMPILE_STANDARD_FILE_INCLUDE, iHlslFlag, 0, m_pDevice, &m_pEffect, nullptr)))
|
||||
return E_FAIL;
|
||||
|
||||
ID3DX11EffectTechnique* pTechnique = m_pEffect->GetTechniqueByIndex(0);
|
||||
if (nullptr == pTechnique)
|
||||
return E_FAIL;
|
||||
|
||||
D3DX11_TECHNIQUE_DESC TechniqueDesc{};
|
||||
|
||||
if (FAILED(pTechnique->GetDesc(&TechniqueDesc)))
|
||||
return E_FAIL;
|
||||
|
||||
m_iNumPasses = TechniqueDesc.Passes;
|
||||
|
||||
for (_uint i = 0; i < m_iNumPasses; i++)
|
||||
{
|
||||
ID3D11InputLayout* pInputLayout = { nullptr };
|
||||
|
||||
ID3DX11EffectPass* pPass = pTechnique->GetPassByIndex(i);
|
||||
if (nullptr == pPass)
|
||||
return E_FAIL;
|
||||
|
||||
D3DX11_PASS_DESC PassDesc{};
|
||||
if (FAILED(pPass->GetDesc(&PassDesc)))
|
||||
return E_FAIL;
|
||||
|
||||
if (FAILED(m_pDevice->CreateInputLayout(
|
||||
pElements,
|
||||
iNumElements,
|
||||
PassDesc.pIAInputSignature/*쉐이더에서 받아줄수 있는 정점의 정보*/,
|
||||
PassDesc.IAInputSignatureSize/*쉐이더에서 받아줄수 있는 정점의 멤버변수갯수*/,
|
||||
&pInputLayout)))
|
||||
return E_FAIL;
|
||||
|
||||
m_InputLayouts.push_back(pInputLayout);
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CShader::Initialize(void* pArg)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
HRESULT CShader::Bind_RawValue(const _char* pConstantName, const void* pData, _uint iLength)
|
||||
{
|
||||
ID3DX11EffectVariable* pVariable = m_pEffect->GetVariableByName(pConstantName);
|
||||
if (nullptr == pVariable){
|
||||
if (nullptr == pVariable)
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
return pVariable->SetRawValue(pData, 0, iLength);
|
||||
}
|
||||
@@ -32,137 +90,69 @@ HRESULT CShader::Bind_RawValue(const _char* pConstantName, const void* pData, _u
|
||||
HRESULT CShader::Bind_Matrix(const _char* pConstantName, const _float4x4* pMatrix)
|
||||
{
|
||||
ID3DX11EffectVariable* pVariable = m_pEffect->GetVariableByName(pConstantName);
|
||||
if (nullptr == pVariable) {
|
||||
if (nullptr == pVariable)
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
ID3DX11EffectMatrixVariable* pMatrixVariable = pVariable->AsMatrix();
|
||||
if (nullptr == pMatrixVariable) {
|
||||
if (nullptr == pMatrixVariable)
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
return pMatrixVariable->SetMatrix(reinterpret_cast<const _float*>(pMatrix));
|
||||
}
|
||||
|
||||
HRESULT CShader::Bind_Matrices(const _char* pConstantName, const _float4x4* pMatrices, _uint iNumMatrices)
|
||||
HRESULT CShader::Bind_Matrices(const _char* pConstantName, const _float4x4* pMatrix, _uint iNumMatrices)
|
||||
{
|
||||
ID3DX11EffectVariable* pVariable = m_pEffect->GetVariableByName(pConstantName);
|
||||
if (nullptr == pVariable) {
|
||||
if (nullptr == pVariable)
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
ID3DX11EffectMatrixVariable* pMatrixVariable = pVariable->AsMatrix();
|
||||
if (nullptr == pMatrixVariable) {
|
||||
if (nullptr == pMatrixVariable)
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
return pMatrixVariable->SetMatrixArray(reinterpret_cast<const _float*>(pMatrices), 0, iNumMatrices);
|
||||
return pMatrixVariable->SetMatrixArray(reinterpret_cast<const _float*>(pMatrix), 0, iNumMatrices);
|
||||
}
|
||||
|
||||
HRESULT CShader::Bind_SRV(const _char* pConstantName, ID3D11ShaderResourceView* pSRV)
|
||||
{
|
||||
ID3DX11EffectVariable* pVariable = m_pEffect->GetVariableByName(pConstantName);
|
||||
if (nullptr == pVariable) {
|
||||
if (nullptr == pVariable)
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
ID3DX11EffectShaderResourceVariable* pSRVariable = pVariable->AsShaderResource();
|
||||
if (nullptr == pSRVariable) {
|
||||
if (nullptr == pSRVariable)
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
return pSRVariable->SetResource(pSRV);
|
||||
}
|
||||
|
||||
HRESULT CShader::Bind_SRVs(const _char* pConstantName, ID3D11ShaderResourceView** pSRVs, _uint iOffset, _uint iCount)
|
||||
HRESULT CShader::Bind_SRVs(const _char* pConstantName, ID3D11ShaderResourceView** ppSRV, _uint iNumSRVs)
|
||||
{
|
||||
ID3DX11EffectVariable* pVariable = m_pEffect->GetVariableByName(pConstantName);
|
||||
if (nullptr == pVariable) {
|
||||
if (nullptr == pVariable)
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
ID3DX11EffectShaderResourceVariable* pSRVariable = pVariable->AsShaderResource();
|
||||
if (nullptr == pSRVariable) {
|
||||
if (nullptr == pSRVariable)
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
return pSRVariable->SetResourceArray(pSRVs, iOffset, iCount);
|
||||
return pSRVariable->SetResourceArray(ppSRV, 0, iNumSRVs);
|
||||
}
|
||||
|
||||
HRESULT CShader::Begin(_uint iPassIndex)
|
||||
{
|
||||
if (iPassIndex >= m_iNumPasses) {
|
||||
if (iPassIndex >= m_iNumPasses)
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
m_pContext->IASetInputLayout(m_pLayouts[iPassIndex]);
|
||||
m_pContext->IASetInputLayout(m_InputLayouts[iPassIndex]);
|
||||
|
||||
/* Apply를 반드시 호출해야만 쉐이더로 그려진다. */
|
||||
/* Apply이전에 쉐이더에 전달할 모든 데이터들을 다 던져놓아야한다. */
|
||||
m_pEffect->GetTechniqueByIndex(0)->GetPassByIndex(iPassIndex)->Apply(0, m_pContext);
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CShader::Initialize_Prototype(const _tchar* pShaderFilePath, const D3D11_INPUT_ELEMENT_DESC* pElements, _uint iNumElements)
|
||||
{
|
||||
UINT HLSLFlags = 0;
|
||||
|
||||
#ifdef _DEBUG
|
||||
HLSLFlags = D3DCOMPILE_DEBUG | D3DCOMPILE_SKIP_OPTIMIZATION;
|
||||
#else
|
||||
HLSLFlags = D3DCOMPILE_OPTIMIZATION_LEVEL1;
|
||||
#endif
|
||||
|
||||
ID3DBlob* pErrorBlob = { nullptr };
|
||||
if (FAILED(D3DX11CompileEffectFromFile(pShaderFilePath,
|
||||
nullptr, D3D_COMPILE_STANDARD_FILE_INCLUDE, HLSLFlags,
|
||||
0, m_pDevice, &m_pEffect, &pErrorBlob))) {
|
||||
|
||||
if (pErrorBlob) {
|
||||
OutputDebugStringA((char*)pErrorBlob->GetBufferPointer());
|
||||
pErrorBlob->Release();
|
||||
}
|
||||
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
ID3DX11EffectTechnique* pTechnique = m_pEffect->GetTechniqueByIndex(0);
|
||||
if (nullptr == pTechnique) {
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
D3DX11_TECHNIQUE_DESC TechniqueDesc = {};
|
||||
if (FAILED(pTechnique->GetDesc(&TechniqueDesc))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
m_iNumPasses = TechniqueDesc.Passes;
|
||||
for (_uint i = 0; i < m_iNumPasses; ++i) {
|
||||
ID3D11InputLayout* pInputLayout = { nullptr };
|
||||
ID3DX11EffectPass* pPass = pTechnique->GetPassByIndex(i);
|
||||
if (nullptr == pPass) {
|
||||
return E_FAIL;
|
||||
}
|
||||
D3DX11_PASS_DESC PassDesc = {};
|
||||
if (FAILED(pPass->GetDesc(&PassDesc))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
if (FAILED(m_pDevice->CreateInputLayout(
|
||||
pElements, iNumElements,
|
||||
PassDesc.pIAInputSignature, PassDesc.IAInputSignatureSize,
|
||||
&pInputLayout
|
||||
))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
m_pLayouts.push_back(pInputLayout);
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CShader::Initialize(void* pArg)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
CShader* CShader::Create(ID3D11Device* pDevice, ID3D11DeviceContext* pContext, const _tchar* pShaderFilePath, const D3D11_INPUT_ELEMENT_DESC* pElements, _uint iNumElements)
|
||||
{
|
||||
CShader* pInstance = new CShader(pDevice, pContext);
|
||||
@@ -170,21 +160,20 @@ CShader* CShader::Create(ID3D11Device* pDevice, ID3D11DeviceContext* pContext, c
|
||||
if (FAILED(pInstance->Initialize_Prototype(pShaderFilePath, pElements, iNumElements)))
|
||||
{
|
||||
MSG_BOX("Failed to Created : CShader");
|
||||
SAFE_RELEASE(pInstance);
|
||||
Safe_Release(pInstance);
|
||||
}
|
||||
|
||||
return pInstance;
|
||||
}
|
||||
|
||||
CComponent* CShader::Clone(void* pArg, CGameObject* pOwner)
|
||||
CComponent* CShader::Clone(void* pArg, class CGameObject* pOwner)
|
||||
{
|
||||
CShader* pInstance = new CShader(*this);
|
||||
pInstance->m_pOwner = pOwner;
|
||||
|
||||
if (FAILED(pInstance->Initialize(pArg)))
|
||||
{
|
||||
MSG_BOX("Failed to Cloned : CShader");
|
||||
SAFE_RELEASE(pInstance);
|
||||
Safe_Release(pInstance);
|
||||
}
|
||||
|
||||
return pInstance;
|
||||
@@ -194,11 +183,12 @@ void CShader::Free()
|
||||
{
|
||||
__super::Free();
|
||||
|
||||
SAFE_RELEASE(m_pEffect);
|
||||
for (auto& iter : m_pLayouts) {
|
||||
SAFE_RELEASE(iter);
|
||||
}
|
||||
m_pLayouts.clear();
|
||||
Safe_Release(m_pEffect);
|
||||
|
||||
for (auto& pInputLayout : m_InputLayouts)
|
||||
Safe_Release(pInputLayout);
|
||||
|
||||
m_InputLayouts.clear();
|
||||
}
|
||||
|
||||
void CShader::Describe_Entity()
|
||||
|
||||
@@ -26,7 +26,7 @@ HRESULT CTexture::Bind_ShaderResources(CShader* pShader, const _char* pConstantN
|
||||
{
|
||||
|
||||
_uint iCnt = (iCount == UINT_MAX) ? (_uint)m_pSRVs.size() : iCount;
|
||||
return pShader->Bind_SRVs(pConstantName, m_pSRVs.data(), 0, iCnt);
|
||||
return pShader->Bind_SRVs(pConstantName, m_pSRVs.data(), iCnt);
|
||||
}
|
||||
|
||||
ID3D11ShaderResourceView* CTexture::Get_SRV(_uint iTextureIndex)
|
||||
|
||||
@@ -0,0 +1,279 @@
|
||||
#include "pch.h"
|
||||
#include "VIBuffer_Cube.h"
|
||||
|
||||
CVIBuffer_Cube::CVIBuffer_Cube(ID3D11Device* pDevice, ID3D11DeviceContext* pContext)
|
||||
: CVIBuffer(pDevice, pContext)
|
||||
{
|
||||
}
|
||||
|
||||
CVIBuffer_Cube::CVIBuffer_Cube(const CVIBuffer_Cube& rhs)
|
||||
: CVIBuffer(rhs)
|
||||
{
|
||||
}
|
||||
|
||||
HRESULT CVIBuffer_Cube::Bind_Resources()
|
||||
{
|
||||
return __super::Bind_Resources();
|
||||
}
|
||||
|
||||
HRESULT CVIBuffer_Cube::Bind_Resources(_uint iStartSlot, _uint iNumBuffer, vector<ID3D11Buffer*>& pBuffer, vector<_uint>& strides, vector<_uint>& offsets)
|
||||
{
|
||||
vector<ID3D11Buffer*> vBuffers;
|
||||
vBuffers.reserve(1 + iNumBuffer);
|
||||
vBuffers.push_back(m_pVB);
|
||||
for (ID3D11Buffer* iter : pBuffer) {
|
||||
vBuffers.push_back(iter);
|
||||
}
|
||||
vector<_uint> vStrides;
|
||||
vStrides.reserve(1 + iNumBuffer);
|
||||
vStrides.push_back(m_iVertexStride);
|
||||
for (_uint iter : strides) {
|
||||
vStrides.push_back(iter);
|
||||
}
|
||||
vector<_uint> vOffsets;
|
||||
vOffsets.reserve(1 + iNumBuffer);
|
||||
vOffsets.push_back(0);
|
||||
for (_uint iter : offsets) {
|
||||
vOffsets.push_back(iter);
|
||||
}
|
||||
|
||||
|
||||
|
||||
m_pContext->IASetVertexBuffers(iStartSlot, 1 + iNumBuffer, vBuffers.data(), vStrides.data(), vOffsets.data());
|
||||
m_pContext->IASetIndexBuffer(m_pIB, m_eIndexFormat, 0);
|
||||
m_pContext->IASetPrimitiveTopology(m_ePrimitive);
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CVIBuffer_Cube::Initialize_Prototype()
|
||||
{
|
||||
m_iNumVertexBuffers = 1;
|
||||
m_iNumVertices = 24;
|
||||
m_iVertexStride = sizeof(VTXBLOCK);
|
||||
|
||||
m_iIndexStride = sizeof(_uint);
|
||||
m_iNumIndices = 36;
|
||||
|
||||
m_eIndexFormat = DXGI_FORMAT_R32_UINT;
|
||||
m_ePrimitive = D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST;
|
||||
|
||||
#pragma region VTX_BUFFER
|
||||
D3D11_BUFFER_DESC VBDesc{};
|
||||
VBDesc.ByteWidth = m_iVertexStride * m_iNumVertices;
|
||||
VBDesc.Usage = D3D11_USAGE_IMMUTABLE;
|
||||
VBDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
|
||||
VBDesc.CPUAccessFlags = 0;
|
||||
VBDesc.MiscFlags = 0;
|
||||
VBDesc.StructureByteStride = m_iVertexStride;
|
||||
|
||||
m_pVertexPositions = new _float3[m_iNumVertices];
|
||||
VTXBLOCK* pVertices = new VTXBLOCK[m_iNumVertices];
|
||||
memset(pVertices, 0, sizeof(VTXBLOCK) * m_iNumVertices);
|
||||
|
||||
m_pVertexPositions[0] = pVertices[0].vTexcoord = pVertices[0].vPosition = { -0.5f, 0.5f, -0.5f };
|
||||
m_pVertexPositions[1] = pVertices[1].vTexcoord = pVertices[1].vPosition = { 0.5f, 0.5f, -0.5f };
|
||||
m_pVertexPositions[2] = pVertices[2].vTexcoord = pVertices[2].vPosition = { 0.5f, 0.5f, 0.5f };
|
||||
m_pVertexPositions[3] = pVertices[3].vTexcoord = pVertices[3].vPosition = { -0.5f, 0.5f, 0.5f };
|
||||
XMStoreFloat3(&pVertices[0].vTexcoord, XMVector3Normalize(XMLoadFloat3(&pVertices[0].vTexcoord)));
|
||||
XMStoreFloat3(&pVertices[1].vTexcoord, XMVector3Normalize(XMLoadFloat3(&pVertices[1].vTexcoord)));
|
||||
XMStoreFloat3(&pVertices[2].vTexcoord, XMVector3Normalize(XMLoadFloat3(&pVertices[2].vTexcoord)));
|
||||
XMStoreFloat3(&pVertices[3].vTexcoord, XMVector3Normalize(XMLoadFloat3(&pVertices[3].vTexcoord)));
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
pVertices[i].vNormal = { 0,1,0 };
|
||||
}
|
||||
|
||||
|
||||
m_pVertexPositions[4] = pVertices[4].vTexcoord = pVertices[4].vPosition = { -0.5f, -0.5f, 0.5f };
|
||||
m_pVertexPositions[5] = pVertices[5].vTexcoord = pVertices[5].vPosition = { 0.5f, -0.5f, 0.5f };
|
||||
m_pVertexPositions[6] = pVertices[6].vTexcoord = pVertices[6].vPosition = { 0.5f, 0.5f, 0.5f };
|
||||
m_pVertexPositions[7] = pVertices[7].vTexcoord = pVertices[7].vPosition = { -0.5f, 0.5f, 0.5f };
|
||||
XMStoreFloat3(&pVertices[4].vTexcoord, XMVector3Normalize(XMLoadFloat3(&pVertices[4].vTexcoord)));
|
||||
XMStoreFloat3(&pVertices[5].vTexcoord, XMVector3Normalize(XMLoadFloat3(&pVertices[5].vTexcoord)));
|
||||
XMStoreFloat3(&pVertices[6].vTexcoord, XMVector3Normalize(XMLoadFloat3(&pVertices[6].vTexcoord)));
|
||||
XMStoreFloat3(&pVertices[7].vTexcoord, XMVector3Normalize(XMLoadFloat3(&pVertices[7].vTexcoord)));
|
||||
|
||||
for (int i = 4; i < 8; ++i) {
|
||||
pVertices[i].vNormal = { 0,0,1 };
|
||||
}
|
||||
|
||||
|
||||
m_pVertexPositions[8] = pVertices[8].vTexcoord = pVertices[8].vPosition = { 0.5f, -0.5f, 0.5f };
|
||||
m_pVertexPositions[9] = pVertices[9].vTexcoord = pVertices[9].vPosition = { 0.5f, 0.5f, 0.5f };
|
||||
m_pVertexPositions[10] = pVertices[10].vTexcoord = pVertices[10].vPosition = { 0.5f, 0.5f, -0.5f };
|
||||
m_pVertexPositions[11] = pVertices[11].vTexcoord = pVertices[11].vPosition = { 0.5f, -0.5f, -0.5f };
|
||||
XMStoreFloat3(&pVertices[8].vTexcoord, XMVector3Normalize(XMLoadFloat3(&pVertices[8].vTexcoord)));
|
||||
XMStoreFloat3(&pVertices[9].vTexcoord, XMVector3Normalize(XMLoadFloat3(&pVertices[9].vTexcoord)));
|
||||
XMStoreFloat3(&pVertices[10].vTexcoord, XMVector3Normalize(XMLoadFloat3(&pVertices[10].vTexcoord)));
|
||||
XMStoreFloat3(&pVertices[11].vTexcoord, XMVector3Normalize(XMLoadFloat3(&pVertices[11].vTexcoord)));
|
||||
|
||||
for (int i = 8; i < 12; ++i) {
|
||||
pVertices[i].vNormal = { 1,0,0 };
|
||||
}
|
||||
|
||||
|
||||
m_pVertexPositions[12] = pVertices[12].vTexcoord = pVertices[12].vPosition = { 0.5f, -0.5f, -0.5f };
|
||||
m_pVertexPositions[13] = pVertices[13].vTexcoord = pVertices[13].vPosition = { -0.5f, -0.5f, -0.5f };
|
||||
m_pVertexPositions[14] = pVertices[14].vTexcoord = pVertices[14].vPosition = { -0.5f, -0.5f, 0.5f };
|
||||
m_pVertexPositions[15] = pVertices[15].vTexcoord = pVertices[15].vPosition = { 0.5f, -0.5f, 0.5f };
|
||||
XMStoreFloat3(&pVertices[12].vTexcoord, XMVector3Normalize(XMLoadFloat3(&pVertices[12].vTexcoord)));
|
||||
XMStoreFloat3(&pVertices[13].vTexcoord, XMVector3Normalize(XMLoadFloat3(&pVertices[13].vTexcoord)));
|
||||
XMStoreFloat3(&pVertices[14].vTexcoord, XMVector3Normalize(XMLoadFloat3(&pVertices[14].vTexcoord)));
|
||||
XMStoreFloat3(&pVertices[15].vTexcoord, XMVector3Normalize(XMLoadFloat3(&pVertices[15].vTexcoord)));
|
||||
|
||||
for (int i = 12; i < 16; ++i) {
|
||||
pVertices[i].vNormal = { 0,-1,0 };
|
||||
}
|
||||
|
||||
|
||||
m_pVertexPositions[16] = pVertices[16].vTexcoord = pVertices[16].vPosition = { -0.5f, -0.5f, -0.5f };
|
||||
m_pVertexPositions[17] = pVertices[17].vTexcoord = pVertices[17].vPosition = { -0.5f, 0.5f, -0.5f };
|
||||
m_pVertexPositions[18] = pVertices[18].vTexcoord = pVertices[18].vPosition = { -0.5f, 0.5f, 0.5f };
|
||||
m_pVertexPositions[19] = pVertices[19].vTexcoord = pVertices[19].vPosition = { -0.5f, -0.5f, 0.5f };
|
||||
XMStoreFloat3(&pVertices[16].vTexcoord, XMVector3Normalize(XMLoadFloat3(&pVertices[16].vTexcoord)));
|
||||
XMStoreFloat3(&pVertices[17].vTexcoord, XMVector3Normalize(XMLoadFloat3(&pVertices[17].vTexcoord)));
|
||||
XMStoreFloat3(&pVertices[18].vTexcoord, XMVector3Normalize(XMLoadFloat3(&pVertices[18].vTexcoord)));
|
||||
XMStoreFloat3(&pVertices[19].vTexcoord, XMVector3Normalize(XMLoadFloat3(&pVertices[19].vTexcoord)));
|
||||
|
||||
for (int i = 16; i < 20; ++i) {
|
||||
pVertices[i].vNormal = { -1,0,0 };
|
||||
}
|
||||
|
||||
m_pVertexPositions[20] = pVertices[20].vTexcoord = pVertices[20].vPosition = { 0.5f, -0.5f, -0.5f };
|
||||
m_pVertexPositions[21] = pVertices[21].vTexcoord = pVertices[21].vPosition = { 0.5f, 0.5f, -0.5f };
|
||||
m_pVertexPositions[22] = pVertices[22].vTexcoord = pVertices[22].vPosition = { -0.5f, 0.5f, -0.5f };
|
||||
m_pVertexPositions[23] = pVertices[23].vTexcoord = pVertices[23].vPosition = { -0.5f, -0.5f, -0.5f };
|
||||
XMStoreFloat3(&pVertices[20].vTexcoord, XMVector3Normalize(XMLoadFloat3(&pVertices[20].vTexcoord)));
|
||||
XMStoreFloat3(&pVertices[21].vTexcoord, XMVector3Normalize(XMLoadFloat3(&pVertices[21].vTexcoord)));
|
||||
XMStoreFloat3(&pVertices[22].vTexcoord, XMVector3Normalize(XMLoadFloat3(&pVertices[22].vTexcoord)));
|
||||
XMStoreFloat3(&pVertices[23].vTexcoord, XMVector3Normalize(XMLoadFloat3(&pVertices[23].vTexcoord)));
|
||||
|
||||
for (int i = 20; i < 24; ++i) {
|
||||
pVertices[i].vNormal = { 0,0,-1 };
|
||||
}
|
||||
|
||||
D3D11_SUBRESOURCE_DATA VBRes{};
|
||||
VBRes.pSysMem = pVertices;
|
||||
|
||||
if (FAILED(m_pDevice->CreateBuffer(&VBDesc, &VBRes, &m_pVB))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
Safe_Delete_Array(pVertices);
|
||||
|
||||
#pragma endregion
|
||||
|
||||
#pragma region IDX_BUFFER
|
||||
D3D11_BUFFER_DESC IBDesc{};
|
||||
|
||||
IBDesc.ByteWidth = m_iIndexStride * m_iNumIndices;
|
||||
IBDesc.Usage = D3D11_USAGE_IMMUTABLE;
|
||||
IBDesc.BindFlags = D3D11_BIND_INDEX_BUFFER;
|
||||
IBDesc.CPUAccessFlags = 0;
|
||||
IBDesc.MiscFlags = 0;
|
||||
IBDesc.StructureByteStride = m_iIndexStride;
|
||||
|
||||
|
||||
_uint* pIndices = new _uint[m_iNumIndices]{};
|
||||
m_pIndices = new _uint[m_iNumIndices];
|
||||
|
||||
m_pIndices[0] = pIndices[0] = 1;
|
||||
m_pIndices[1] = pIndices[1] = 0;
|
||||
m_pIndices[2] = pIndices[2] = 3;
|
||||
|
||||
m_pIndices[3] = pIndices[3] = 2;
|
||||
m_pIndices[4] = pIndices[4] = 1;
|
||||
m_pIndices[5] = pIndices[5] = 3;
|
||||
|
||||
m_pIndices[6] = pIndices[6] = 6;
|
||||
m_pIndices[7] = pIndices[7] = 7;
|
||||
m_pIndices[8] = pIndices[8] = 4;
|
||||
|
||||
m_pIndices[9] = pIndices[9] = 4;
|
||||
m_pIndices[10] = pIndices[10] = 5;
|
||||
m_pIndices[11] = pIndices[11] = 6;
|
||||
|
||||
m_pIndices[12] = pIndices[12] = 10;
|
||||
m_pIndices[13] = pIndices[13] = 9;
|
||||
m_pIndices[14] = pIndices[14] = 8;
|
||||
|
||||
m_pIndices[15] = pIndices[15] = 8;
|
||||
m_pIndices[16] = pIndices[16] = 11;
|
||||
m_pIndices[17] = pIndices[17] = 10;
|
||||
|
||||
|
||||
m_pIndices[18] = pIndices[18] = 13;
|
||||
m_pIndices[19] = pIndices[19] = 12;
|
||||
m_pIndices[20] = pIndices[20] = 15;
|
||||
|
||||
m_pIndices[21] = pIndices[21] = 15;
|
||||
m_pIndices[22] = pIndices[22] = 14;
|
||||
m_pIndices[23] = pIndices[23] = 13;
|
||||
|
||||
m_pIndices[24] = pIndices[24] = 18;
|
||||
m_pIndices[25] = pIndices[25] = 17;
|
||||
m_pIndices[26] = pIndices[26] = 16;
|
||||
|
||||
m_pIndices[27] = pIndices[27] = 16;
|
||||
m_pIndices[28] = pIndices[28] = 19;
|
||||
m_pIndices[29] = pIndices[29] = 18;
|
||||
|
||||
m_pIndices[30] = pIndices[30] = 22;
|
||||
m_pIndices[31] = pIndices[31] = 21;
|
||||
m_pIndices[32] = pIndices[32] = 20;
|
||||
|
||||
m_pIndices[33] = pIndices[33] = 20;
|
||||
m_pIndices[34] = pIndices[34] = 23;
|
||||
m_pIndices[35] = pIndices[35] = 22;
|
||||
|
||||
D3D11_SUBRESOURCE_DATA IBRes{};
|
||||
IBRes.pSysMem = pIndices;
|
||||
|
||||
if (FAILED(m_pDevice->CreateBuffer(&IBDesc, &IBRes, &m_pIB))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
Safe_Delete_Array(pIndices);
|
||||
#pragma endregion
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CVIBuffer_Cube::Initialize(void* pArg)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
CVIBuffer_Cube* CVIBuffer_Cube::Create(ID3D11Device* pDevice, ID3D11DeviceContext* pContext)
|
||||
{
|
||||
CVIBuffer_Cube* pInstance = new CVIBuffer_Cube(pDevice, pContext);
|
||||
|
||||
if (FAILED(pInstance->Initialize_Prototype()))
|
||||
{
|
||||
MSG_BOX("Failed to Created : CVIBuffer_Cube");
|
||||
SAFE_RELEASE(pInstance);
|
||||
}
|
||||
|
||||
return pInstance;
|
||||
}
|
||||
|
||||
CVIBuffer_Cube* CVIBuffer_Cube::Clone(void* pArg, CGameObject* pOwner)
|
||||
{
|
||||
CVIBuffer_Cube* pInstance = new CVIBuffer_Cube(*this);
|
||||
pInstance->m_pOwner = pOwner;
|
||||
if (FAILED(pInstance->Initialize(pArg)))
|
||||
{
|
||||
MSG_BOX("Failed to Cloned : CVIBuffer_Cube");
|
||||
SAFE_RELEASE(pInstance);
|
||||
}
|
||||
|
||||
return pInstance;
|
||||
}
|
||||
|
||||
void CVIBuffer_Cube::Free()
|
||||
{
|
||||
__super::Free();
|
||||
|
||||
|
||||
}
|
||||
|
||||
void CVIBuffer_Cube::Describe_Entity()
|
||||
{
|
||||
}
|
||||
@@ -4,35 +4,57 @@
|
||||
|
||||
NS_BEGIN(Engine)
|
||||
|
||||
class CAnimation final : public CBase
|
||||
class ENGINE_DLL CAnimation : public CBase
|
||||
{
|
||||
private:
|
||||
CAnimation();
|
||||
CAnimation(const CAnimation& Prototype);
|
||||
CAnimation(const CAnimation& rhs);
|
||||
virtual ~CAnimation() = default;
|
||||
|
||||
public:
|
||||
HRESULT Initialize(const class CModel* pModel, const aiAnimation* pAIAnimation);
|
||||
_bool Update_TransformationMatrices(_float fTimeDelta, _bool isLoop, vector<class CBone*>& Bones);
|
||||
void InterpAnim(CAnimation* pPreAnim, vector<CBone*>& Bones, float fRatio);
|
||||
_bool Update_TransformationMatrices(const vector<class CBone*>& Bones, _bool bIsLoop, _float fTimeDelta);
|
||||
void Depart_Animation();
|
||||
void Set_AnimPause(_bool bValue) { m_bPause = bValue; }
|
||||
_float Get_AnimProgressRatio();
|
||||
_float Get_AnimEstimatedDuration();
|
||||
_int Get_AnimProgressPostion(const _char* pAnimChannelName);
|
||||
void Set_AnimProgressPostion(const _char* pChannelName, _uint iPosition);
|
||||
vector<_int>* Capture_Bones();
|
||||
vector<LERPDESC> Get_StartFrameInformations() { return m_StartKeyFrames; }
|
||||
const _string& Get_Name() const { return m_strName; }
|
||||
|
||||
|
||||
#ifdef EDITOR_PROJECT
|
||||
private:
|
||||
HRESULT Initialize(const vector<class CBone*>& Bones, const aiAnimation* pAIAnimation);
|
||||
public:
|
||||
HRESULT SaveAsBinary(HANDLE hFile, DWORD& dwByte);
|
||||
static CAnimation* Create(const vector<class CBone*>& Bones, const aiAnimation* pAnimation);
|
||||
#endif // EDITOR_PROJECT
|
||||
|
||||
private:
|
||||
const aiAnimation* m_pAIAnimation = { nullptr };
|
||||
HRESULT Initialize(HANDLE hFile, DWORD& dwByte);
|
||||
HRESULT Combined_Initialize();
|
||||
_uint Get_BoneIndex(const char* pChannelName);
|
||||
|
||||
_float m_fCurrentTrackPosition = {};
|
||||
_double m_fDuration = {};
|
||||
_float m_fTickPerSecond = {};
|
||||
private:
|
||||
_bool m_bPause = { FALSE }; // 애님퍼즈 인덱스
|
||||
_string m_strName = {}; // 애님 이름
|
||||
_float m_fCurrentTrackPosition = {}; // 현재 트랙 위치
|
||||
_float m_fDuration = {}; // 트랙의 전체 길이
|
||||
_float m_TickPerSeconds[2] = { 0.f, 0.f }; // 초당 트랙 이동 거리
|
||||
_uint m_iNumChannels = {}; // 영향을 받는 본의 수
|
||||
|
||||
vector<class CChannel*> m_Channels;
|
||||
_uint m_iNumChannels = {};
|
||||
vector<_uint> m_CurrentKeyFrameIndices;
|
||||
vector<_matrix> m_vBoneTransformationMatrix = {};
|
||||
vector<class CChannel*> m_Channels; // 이 애니메이션이 영향을 준 사전 계산된 본의 배열
|
||||
vector<_uint> m_CurrentKeyFrameIndices; // 각 본이 현재 애니메이션에서 취해야할 키프레임 왼쪽 인덱스
|
||||
|
||||
vector<_int> m_DestBones; // 이 애니메이션에서 영향을 받는 본들의 집합
|
||||
vector<LERPDESC> m_StartKeyFrames; // 이 애니메이션의 영향을 받는 본들의 초기값
|
||||
|
||||
public:
|
||||
static CAnimation* Create(const class CModel* pModel, const aiAnimation* pAIAnimation);
|
||||
static CAnimation* Create(HANDLE hFile, DWORD& dwByte);
|
||||
CAnimation* Clone();
|
||||
virtual void Free() override;
|
||||
void Describe_Entity();
|
||||
};
|
||||
|
||||
NS_END
|
||||
|
||||
NS_END
|
||||
@@ -4,36 +4,53 @@
|
||||
|
||||
NS_BEGIN(Engine)
|
||||
|
||||
class CBone final : public CBase
|
||||
class ENGINE_DLL CBone final : public CBase
|
||||
{
|
||||
private:
|
||||
CBone();
|
||||
virtual ~CBone() = default;
|
||||
|
||||
public:
|
||||
_matrix Get_CombinedTransformationMatrix() const {
|
||||
return XMLoadFloat4x4(&m_CombinedTransformationMatrix);
|
||||
}
|
||||
|
||||
const _float4x4* Get_CombinedTransformationMatrixPtr() const {
|
||||
_float4x4* Get_CombinedTransformationMatrixPtr() {
|
||||
return &m_CombinedTransformationMatrix;
|
||||
}
|
||||
void Set_CombinedTransformationMatrixPtr(_matrix& newMatrix) {
|
||||
return XMStoreFloat4x4(&m_CombinedTransformationMatrix, newMatrix);
|
||||
}
|
||||
_bool Compare_Name(const _char* pBoneName) const {
|
||||
return !strcmp(pBoneName, m_szName);
|
||||
}
|
||||
public:
|
||||
HRESULT Initialize(const aiNode* pAINode, _int iParentIndex);
|
||||
void Update_CombinedTransformationMatrix(const vector<CBone*>& Bones, _fmatrix PreTransformMatrix);
|
||||
void Set_Transformation(_fmatrix BoneTransformationMatrix);
|
||||
void Get_KeyFrame(KEYFRAME& kf, _bool bIsCurrentFrame); // 현재 본의 로컬매트릭스를 캡쳐해서 키프레임으로 성분 분해하여 올려보낸다.
|
||||
const _char* Get_Name() const { return m_szName; }
|
||||
_float3 Get_LocalPosition();
|
||||
void Update_CombinedTransformationMatrix(const vector<CBone*>& Bones, _fmatrix PreTransformMatrix);
|
||||
void Set_TransformationMatrix(_fmatrix TransformationMatrix); // 애니메이션에서 현재 로컬 매트릭스를 변경할 때 사용된다
|
||||
|
||||
private:
|
||||
_char m_szName[MAX_PATH] = {};
|
||||
_float4x4 m_TransformationMatrix = {};
|
||||
_float4x4 m_CombinedTransformationMatrix = {};
|
||||
_int m_iParentBoneIndex = { -1 };
|
||||
_char m_szName[MAX_PATH] = {}; // 본의 이름
|
||||
_float4x4 m_TransformationMatrix = {}; // 본의 현재 로컬 매트릭스
|
||||
_float4x4 m_CombinedTransformationMatrix = {}; // 본의 루트노드로부터 상대적인 복합매트릭스 ( 부모노드는 PreTranformMatrix와 월드좌표로부터 상대적임 )
|
||||
_int m_iParentBoneIndex = { -1 }; // 부모본의 인덱스 ( 모델에 있는 본벡터의 인덱스 ) ( 부모는 인덱스 -1 고정 )
|
||||
_float4x4 m_matInitial = {};
|
||||
|
||||
private:
|
||||
HRESULT Initialize(HANDLE hFile, DWORD& dwByte);
|
||||
|
||||
public:
|
||||
static CBone* Create(const aiNode* pAINode, _int iParentIndex);
|
||||
static CBone* Create(HANDLE hFile, DWORD& dwByte);
|
||||
CBone* Clone();
|
||||
virtual void Free() override;
|
||||
|
||||
#ifdef EDITOR_PROJECT
|
||||
public:
|
||||
HRESULT SaveAsBinary(HANDLE hFile, DWORD& dwByte);
|
||||
static CBone* Create(const aiNode* pAINode, _int iParentIndex);
|
||||
private:
|
||||
HRESULT Initialize(const aiNode* pAINode, _int iParentIndex);
|
||||
#endif // EDITOR_PROJECT
|
||||
|
||||
};
|
||||
NS_END
|
||||
|
||||
NS_END
|
||||
@@ -4,29 +4,44 @@
|
||||
|
||||
NS_BEGIN(Engine)
|
||||
|
||||
class CChannel final : public CBase
|
||||
class ENGINE_DLL CChannel : public CBase
|
||||
{
|
||||
private:
|
||||
CChannel();
|
||||
virtual ~CChannel() = default;
|
||||
|
||||
public:
|
||||
HRESULT Initialize(const class CModel* pModel, const aiNodeAnim* pAIChannel);
|
||||
void Update_TransformationMatrix(_float fCurrentTrackPosition, vector<class CBone*>& Bones, _uint* pCurrentKeyFrameIndex);
|
||||
_matrix Get_BoneTransformationMatrix() { return m_BoneTransformationMatrix; }
|
||||
_int Get_BoneIndex() { return m_iBoneIndex; }
|
||||
#ifdef EDITOR_PROJECT
|
||||
private:
|
||||
_char m_szName[MAX_PATH] = {};
|
||||
_int m_iBoneIndex = { -1 };
|
||||
|
||||
_uint m_iNumKeyFrames = {};
|
||||
vector<KEYFRAME> m_KeyFrames;
|
||||
|
||||
_uint m_iCurrentKeyFrameIndex = { 0 };
|
||||
_matrix m_BoneTransformationMatrix = {};
|
||||
HRESULT Initialize(const vector<class CBone*>& Bones, const aiNodeAnim* pAIChannel);
|
||||
public:
|
||||
HRESULT SaveAsBinary(HANDLE hFile, DWORD& dwByte);
|
||||
static CChannel* Create(const vector<class CBone*>& Bones, const aiNodeAnim* pAIChannel);
|
||||
#endif // EDITOR_PROJECT
|
||||
|
||||
public:
|
||||
static CChannel* Create(const class CModel* pModel, const aiNodeAnim* pAIChannel);
|
||||
void Update_TransformationMatirx(const vector<class CBone*>& Bones, _float fCurrentTrackPosition, _uint* pCurrentKeyFrameIndex);
|
||||
_int Get_BoneIndex() { return { m_iBoneIndex }; }
|
||||
|
||||
|
||||
KEYFRAME* Get_Frame(_uint iIndex);
|
||||
void Set_Frame(_uint iIndex, KEYFRAME& kf);
|
||||
_bool Compare_Name(const _char* pChannelname) const {
|
||||
return !strcmp(pChannelname, m_szName);
|
||||
}
|
||||
private:
|
||||
HRESULT Initialize(HANDLE hFile, DWORD& dwByte);
|
||||
HRESULT Initialize(const vector<class CBone*>& Bones, _uint iIndex);
|
||||
|
||||
|
||||
private:
|
||||
_char m_szName[MAX_PATH] = {}; // 영향을 받을 본의 이름
|
||||
_int m_iBoneIndex = { -1 }; // 본 벡터에서 본의 인덱스
|
||||
_uint m_iNumKeyFrames = {}; // Animation의 m_fDuration동안 이 본이 취해야할 키프레임의 갯수
|
||||
vector<KEYFRAME> m_KeyFrames; // 키프레임 벡터
|
||||
|
||||
public:
|
||||
static CChannel* Create(const vector<class CBone*>& Bones, _uint iIndex); // 럴프전용
|
||||
static CChannel* Create(HANDLE hFile, DWORD& dwByte);
|
||||
virtual void Free() override;
|
||||
};
|
||||
|
||||
|
||||
@@ -12,6 +12,16 @@ typedef struct tagEngineDesc
|
||||
_uint iWinSizeX, iWinSizeY;
|
||||
}ENGINE_DESC;
|
||||
|
||||
typedef struct tagModelDesc {
|
||||
vector<class CMesh*>* pMeshes = { nullptr };
|
||||
vector<class CMaterial*>* pMaterials = { nullptr };
|
||||
vector<class CBone*>* pBones = { nullptr };
|
||||
vector<class CAnimation*>* pAnimations = { nullptr };
|
||||
MODEL eType = {};
|
||||
_float4x4 PreTransformMatrix = {};
|
||||
_uint iRootBoneIndex = {};
|
||||
}MODEL_DESC;
|
||||
|
||||
typedef struct tagKeyFrame
|
||||
{
|
||||
XMFLOAT3 vScale;
|
||||
@@ -21,6 +31,11 @@ typedef struct tagKeyFrame
|
||||
|
||||
}KEYFRAME;
|
||||
|
||||
struct LERPDESC {
|
||||
_int iSlot;
|
||||
tagKeyFrame tagKeyFrame;
|
||||
};
|
||||
|
||||
typedef struct tagLightDesc
|
||||
{
|
||||
LIGHT eType;
|
||||
@@ -50,6 +65,20 @@ typedef struct tagVertexInstance_Particle
|
||||
_float2 vLifeTime;
|
||||
}VTX_INSTANCE_PARTICLE;
|
||||
|
||||
typedef struct tagVertexBlock
|
||||
{
|
||||
_float3 vPosition;
|
||||
_float3 vNormal;
|
||||
_float3 vTexcoord;
|
||||
|
||||
static constexpr _uint iNumElements = { 3 };
|
||||
static constexpr D3D11_INPUT_ELEMENT_DESC Elements[] = {
|
||||
{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
|
||||
{ "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 },
|
||||
{ "TEXCOORD", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 24, D3D11_INPUT_PER_VERTEX_DATA, 0 },
|
||||
};
|
||||
|
||||
}VTXBLOCK;
|
||||
|
||||
typedef struct tagVertexPosition {
|
||||
_float3 vPosition;
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
#pragma once
|
||||
|
||||
#include "Base.h"
|
||||
|
||||
NS_BEGIN(Engine)
|
||||
|
||||
class ENGINE_DLL CLerpAnim : public CBase
|
||||
{
|
||||
private:
|
||||
CLerpAnim();
|
||||
virtual ~CLerpAnim() = default;
|
||||
public:
|
||||
_bool IsLerping() { return m_bLerping; }
|
||||
_bool Update_TransformationMatrices(const vector<class CBone*>& Bones, _float fTimeDelta);
|
||||
HRESULT Initialize(_uint iNumBone, _float fTickPerSecond, const vector<class CBone*>& Bones);
|
||||
void Begin(const vector<class CBone*>& Bones, vector<LERPDESC>& StartFrames, vector<LERPDESC>& EndFrames, _float fDuration, _uint iRootBoneIndex);
|
||||
|
||||
private:
|
||||
_float m_fCurrentTrackPosition = {}; // 현재 트랙 위치
|
||||
_float m_fTickPerSecond = {}; // 초당 트랙 이동 거리
|
||||
_uint m_iNumChannels = {}; // 영향을 받는 본의 수
|
||||
|
||||
vector<class CChannel*> m_Channels; // 이 애니메이션이 영향을 준 사전 계산된 본의 배열
|
||||
vector<KEYFRAME> m_InitialFrames; // 초기 프레임
|
||||
vector<_uint> m_CurrentKeyFrameIndices; // 각 본이 현재 애니메이션에서 취해야할 키프레임 왼쪽 인덱스
|
||||
vector<_bool> m_Movable; // 각 본이 럴프 도중 업데이트를 받아야할지 말아야할지 스위치
|
||||
_bool m_bLerping = { false }; // 럴프 확인 부울
|
||||
_float m_fDuration = { 0.25f }; // 럴프 주기
|
||||
|
||||
public:
|
||||
static CLerpAnim* Create(_uint iNumBone, _float fTickPerSecond, const vector<class CBone*>& Bones);
|
||||
virtual void Free() override;
|
||||
|
||||
};
|
||||
|
||||
NS_END
|
||||
@@ -4,23 +4,36 @@
|
||||
|
||||
NS_BEGIN(Engine)
|
||||
|
||||
class CMaterial final : public CBase
|
||||
class ENGINE_DLL CMaterial final : public CBase
|
||||
{
|
||||
private:
|
||||
CMaterial(ID3D11Device* pDevice, ID3D11DeviceContext* pContext);
|
||||
virtual ~CMaterial() = default;
|
||||
|
||||
public:
|
||||
HRESULT Initialize(const _char* pModelFilePath, const aiMaterial* pAIMaterial);
|
||||
HRESULT Bind_SRV(class CShader* pShader, const _char* pConstantName, aiTextureType eType, _uint iTextureIndex);
|
||||
HRESULT Bind_SRV(class CShader* pShader, const _char* pConstantName, _uint iType, _uint iTextureIndex);
|
||||
|
||||
private:
|
||||
class CGameInstance* m_pGameInstance = { nullptr };
|
||||
ID3D11Device* m_pDevice = { nullptr };
|
||||
ID3D11DeviceContext* m_pContext = { nullptr };
|
||||
|
||||
_uint m_iNumSRVs = {};
|
||||
vector<ID3D11ShaderResourceView*> m_SRVs[AI_TEXTURE_TYPE_MAX];
|
||||
|
||||
#ifdef EDITOR_PROJECT
|
||||
public:
|
||||
static CMaterial* Create(ID3D11Device* pDevice, ID3D11DeviceContext* pContext, const _char* pModelFilePath, const aiMaterial* pAIMaterial);
|
||||
HRESULT SaveAsBinary(HANDLE hFile, DWORD& dwByte);
|
||||
private:
|
||||
vector<string> m_strPath[AI_TEXTURE_TYPE_MAX];
|
||||
HRESULT Initialize(const _char* pModelFilePath, const aiMaterial* pAIMaterial);
|
||||
#endif // EDITOR_PROJECT
|
||||
|
||||
virtual HRESULT Initialize(const _char* pModelFilePath, HANDLE hFile, DWORD& dwByte);
|
||||
|
||||
|
||||
public:
|
||||
static CMaterial* Create(ID3D11Device* pDevice, ID3D11DeviceContext* pContext, const _char* pModelFilePath, HANDLE hFile, DWORD& dwByte);
|
||||
virtual void Free() override;
|
||||
};
|
||||
|
||||
|
||||
@@ -8,38 +8,47 @@ class ENGINE_DLL CMesh final : public CVIBuffer
|
||||
{
|
||||
private:
|
||||
CMesh(ID3D11Device* pDevice, ID3D11DeviceContext* pContext);
|
||||
CMesh(const CMesh& Prototype);
|
||||
CMesh(const CMesh& rhs);
|
||||
virtual ~CMesh() = default;
|
||||
|
||||
public:
|
||||
_uint Get_MaterialIndex() const {
|
||||
return m_iMaterialIndex;
|
||||
}
|
||||
public:
|
||||
virtual HRESULT Initialize_Prototype(MODEL eType, const class CModel* pModel, const aiMesh* pAIMesh, _fmatrix PreTransformMatrix);
|
||||
virtual HRESULT Initialize(void* pArg) override;
|
||||
|
||||
HRESULT Bind_BoneMatrices(const vector<class CBone*>& Bones, class CShader* pShader, const _char* pConstantName);
|
||||
|
||||
private:
|
||||
_char m_szName[MAX_PATH] = {};
|
||||
_uint m_iMaterialIndex = {};
|
||||
_uint m_iNumBones = { };
|
||||
_float4x4* m_pBoneMatrices = { nullptr };
|
||||
vector<_float4x4> m_OffsetMatrices;
|
||||
vector<_int> m_BoneIndices;
|
||||
vector<_uint> m_Indices;
|
||||
vector<_float3> m_Vertices;
|
||||
|
||||
HRESULT Bind_BoneMatrices(_float4x4* pCombinedMatrices, class CShader* pShader, const _char* pConstantName);
|
||||
HRESULT Render_Indexed(_uint IndexCount, _uint StartIndexLocation, _uint BaseVertexLocation);
|
||||
#ifdef EDITOR_PROJECT
|
||||
private:
|
||||
virtual HRESULT Initialize_Prototype(MODEL eType, vector<class CBone*>& Bones, const aiMesh* pAIMesh, _fmatrix& PreTransformMatrix);
|
||||
HRESULT Ready_VertexBuffer_For_NonAnim(const aiMesh* pAIMesh, _fmatrix PreTransformMatrix);
|
||||
HRESULT Ready_VertexBuffer_For_Anim(const class CModel* pModel, const aiMesh* pAIMesh);
|
||||
HRESULT Ready_VertexBuffer_For_Anim(vector<class CBone*>& Bones, const aiMesh* pAIMesh);
|
||||
public:
|
||||
static CMesh* Create(ID3D11Device* pDevice, ID3D11DeviceContext* pContext, MODEL eType, vector<class CBone*>& Bones, const aiMesh* pAIMesh, _fmatrix& PreTransformMatrix);
|
||||
HRESULT SaveAsBinary(HANDLE hFile, DWORD& dwByte);
|
||||
#endif // EDITOR_PROJECT
|
||||
|
||||
private:
|
||||
virtual HRESULT Initialize_Prototype(HANDLE hFile, DWORD& dwByte);
|
||||
virtual HRESULT Initialize(void* pArg) override;
|
||||
HRESULT Ready_VertexBuffer_For_NonAnim(HANDLE hFile, DWORD& dwByte);
|
||||
HRESULT Ready_VertexBuffer_For_Anim(HANDLE hFile, DWORD& dwByte);
|
||||
|
||||
private:
|
||||
_char m_szName[MAX_PATH] = {};
|
||||
_uint m_iMaterialIndex = {};
|
||||
_uint m_iNumBones = { };
|
||||
|
||||
vector<_int> m_BoneIndices;
|
||||
_float4x4* m_pBoneMatrices = { nullptr };
|
||||
vector<_float4x4> m_offsetMatrices;
|
||||
|
||||
public:
|
||||
static CMesh* Create(ID3D11Device* pDevice, ID3D11DeviceContext* pContext, MODEL eType, const class CModel* pModel, const aiMesh* pAIMesh, _fmatrix PreTransformMatrix);
|
||||
virtual CComponent* Clone(void* pArg, CGameObject* pOwner = nullptr)override;
|
||||
static CMesh* Create(ID3D11Device* pDevice, ID3D11DeviceContext* pContext, HANDLE hFile, DWORD& dwByte);
|
||||
virtual CMesh* Clone(void* pArg, class CGameObject* pOwner = nullptr) override;
|
||||
virtual void Free() override;
|
||||
virtual void Describe_Entity() override;
|
||||
void Describe_Entity() override;
|
||||
};
|
||||
|
||||
NS_END
|
||||
@@ -8,67 +8,88 @@ class ENGINE_DLL CModel final : public CComponent
|
||||
{
|
||||
private:
|
||||
CModel(ID3D11Device* pDevice, ID3D11DeviceContext* pContext);
|
||||
CModel(const CModel& Prototype);
|
||||
CModel(const CModel& rhs);
|
||||
virtual ~CModel() = default;
|
||||
|
||||
|
||||
public:
|
||||
_uint Get_NumMeshes() const {
|
||||
return m_iNumMeshes;
|
||||
}
|
||||
|
||||
_int Get_BoneIndex(const _char* pBoneName) const;
|
||||
static _int Get_BoneIndex(const _char* pBoneName, vector<class CBone*> Bones); // 본의 벡터와 이름을 넘겨주면 인덱스를 넘겨줌 ( n 순회 )
|
||||
void Set_RootBoneIndex(_int iIndex) { m_iRootBoneIndex = iIndex; }
|
||||
void Change_AnimationIndex(_int iAnimationIndex, _bool bIsLoop, _float fLerpDuration, _bool bIgnoreCurrentIndex = false); // 애니메이션을 다른 인덱스로 변경함
|
||||
_bool Play_Animation(_float fTimeDelta); // 애니메이션에 델타타임을 넣어줌
|
||||
void Stop_Animation(); // 애니메이션을 정지 (초기상태로)
|
||||
void Get_CurrentAnimationState();
|
||||
_bool IsFinishedAnim() const { return m_bIsFinishedAnim; }
|
||||
_bool IsFinishedLerp() const { return m_bIsFinishedLerp; }
|
||||
void RefreshAnim(); // 애님을 현재 애님의 초기상태로 되돌림
|
||||
_float Get_AnimProgressRatio();
|
||||
_int Get_AnimProgressPostion(const char* pAnimChannelName);
|
||||
_float Get_AnimEstimatedDuration();
|
||||
void Set_AnimProgressPostion(const _char* pChannelName, _uint iPosition);
|
||||
void Set_AnimPauseState(_bool bValue);// 애님을 현재상태로 정지
|
||||
void ReallocateResources(class CTransform* pTransform = nullptr); // 애님 이동의 대상 트랜스폼(이동시켜야할 트랜스폼)을 재지정함
|
||||
_int Get_RootBoneIndex() const { return m_iRootBoneIndex; }
|
||||
const _float4x4* Get_BoneMatrixPtr(const _char* pBoneName) const;
|
||||
const vector<class CMesh*>& Get_Meshes() const { return m_Meshes; }
|
||||
_uint Get_NumMeshes() const { return m_iNumMeshes; }
|
||||
MODEL Get_Type() const { return m_eType; }
|
||||
_matrix Get_BoneMatrix(_uint iBoneIndex);
|
||||
|
||||
_float4x4* Get_PreTransformMatrixPtr() { return &m_PreTransformMatrix; }
|
||||
void Get_BoneMatrices(_float4x4* pOut);
|
||||
_uint Get_BonesNum() const { return (_uint)m_Bones.size(); }
|
||||
|
||||
public:
|
||||
virtual HRESULT Initialize_Prototype(MODEL eType, const _char* pModelFilePath, _fmatrix PreTransformMatrix);
|
||||
virtual HRESULT Initialize(void* pArg) override;
|
||||
HRESULT Bind_BoneMatrices(_uint iMeshIndex, class CShader* pShader, const _char* pConstantName);
|
||||
HRESULT Bind_Material(_uint iMeshIndex, class CShader* pShader, const _char* pConstantName, aiTextureType eType, _uint iTextureIndex);
|
||||
_bool Play_Animation(_float fTimeDelta);
|
||||
void Set_AnimationIndex(_int iIndex, _bool isLoop = true);
|
||||
HRESULT Render(_uint iMeshIndex);
|
||||
HRESULT Bind_Material(_uint iMeshIndex, class CShader* pShader, const _char* pConstantName, _uint iType, _uint iTextureIndex);
|
||||
HRESULT Bind_BoneMatrices(_uint iMeshIndex, class CShader* pShader, const _char* pConstantName);
|
||||
virtual HRESULT Render(_uint iMeshIndex);
|
||||
virtual HRESULT Render_Indexed(_uint iMeshIndex, _uint IndexCount, _uint StartIndexLocation, _uint BaseVertexLocation);
|
||||
|
||||
private:
|
||||
const aiScene* m_pAIScene = { nullptr };
|
||||
Assimp::Importer m_Importer;
|
||||
|
||||
private:
|
||||
MODEL m_eType = {};
|
||||
_float4x4 m_PreTransformMatrix = {};
|
||||
|
||||
vector<class CMesh*> m_Meshes;
|
||||
_uint m_iNumMeshes = {};
|
||||
|
||||
vector<class CMaterial*> m_Materials;
|
||||
_uint m_iNumMaterials = {};
|
||||
|
||||
vector<class CBone*> m_Bones;
|
||||
|
||||
vector<class CAnimation*> m_Animations;
|
||||
_int m_iCurrentAnimIndex = { -1 };
|
||||
_int m_iPreAnimIndex = { 0 };
|
||||
_int m_iNumAnimations = {};
|
||||
_bool m_isLoop = { false };
|
||||
_bool m_isFinish = { false };
|
||||
|
||||
_float m_fBlendTime = { 0.f };
|
||||
_float m_fBlendDuration = { 0.3f };
|
||||
|
||||
private:
|
||||
HRESULT Ready_Meshes();
|
||||
HRESULT Ready_Materials(const _char* pModelFilePath);
|
||||
#ifdef EDITOR_PROJECT
|
||||
HRESULT Initialize_Prototype(const _char* pModelFilePath, MODEL eType, _fmatrix& PreTransformMatrix, _uint iRootBoneIndex);
|
||||
static CModel* Create(ID3D11Device* pDevice, ID3D11DeviceContext* pContext, const _char* pModelFilePath, MODEL eType, _fmatrix& PreTransformMatrix, _uint iRootBoneIndex);
|
||||
HRESULT Assimp_Model_Load(const _char* pModelFilePath, MODEL eType, _fmatrix& PreTransformMatrix, _uint iRootBoneIndex);
|
||||
HRESULT Ready_Meshes(MODEL eType, const aiScene* pAIScene, _fmatrix& PreTransformMatrix);
|
||||
HRESULT Ready_Materials(const aiScene* pAIScene, const _char* pModelFilePath);
|
||||
HRESULT Ready_Animations(const aiScene* pAIScene);
|
||||
HRESULT Ready_Bones(const aiNode* pAINode, _int iParentIndex);
|
||||
HRESULT Ready_Animations();
|
||||
#endif // EDITOR_PROJECT
|
||||
|
||||
|
||||
private:
|
||||
MODEL m_eType = {}; // 모델의 타입
|
||||
_float4x4 m_PreTransformMatrix = {}; // 사전에 루트본에 곱해줄 매트릭스
|
||||
|
||||
_uint m_iNumMeshes = {}; // 메쉬의 갯수
|
||||
vector<class CMesh*> m_Meshes; // 메쉬의 벡터
|
||||
|
||||
_uint m_iNumMaterials = {}; // 머테리얼의 갯수
|
||||
vector<class CMaterial*> m_Materials; // 머테리얼의 벡터
|
||||
|
||||
vector<class CBone*> m_Bones; // 본의 벡터, 정렬순서는 루트본부터 트리의 마지막 노드까지
|
||||
|
||||
_int m_iCurrentAnimIndex = { -1 }; // 현재 선택된 애니메이션 ( m_Animations의 인덱스 )
|
||||
_uint m_iNumAnimations = {}; // 애니메이션의 종류
|
||||
_bool m_bIsLoop = { false }; // 루프애니메이션인지
|
||||
_bool m_bIsFinishedAnim = { false }; // 대상 애니메이션이 끝났는지
|
||||
_bool m_bIsFinishedLerp = { false }; // 럴프 애니메이션이 끝났는지
|
||||
vector<class CAnimation*> m_Animations; // 애니메이션의 벡터,
|
||||
|
||||
class CLerpAnim* m_pLerpAnim = { nullptr }; // 럴프전용 애니메이션
|
||||
|
||||
_int m_iRootBoneIndex = { -1 }; // 루트본의 인덱스
|
||||
_matrix m_PrevAnimationMatrix = XMMatrixIdentity(); // 루트본의 이전 위치
|
||||
_matrix m_DeltaAnimationMatrix = {}; // 루트본의 델타애니메이션
|
||||
class CTransform* m_pTransform = { nullptr }; // 모델 대상의 트랜스폼
|
||||
|
||||
|
||||
private:
|
||||
virtual HRESULT Initialize_Prototype() override;
|
||||
virtual HRESULT Initialize(void* pArg) override;
|
||||
|
||||
public:
|
||||
static CModel* Create(ID3D11Device* pDevice, ID3D11DeviceContext* pContext, MODEL eType, const _char* pModelFilePath, _fmatrix PreTransformMatrix = XMMatrixIdentity());
|
||||
virtual CComponent* Clone(void* pArg, CGameObject* pOwner = nullptr)override;
|
||||
virtual void Free();
|
||||
#ifdef _DEBUG
|
||||
virtual void Describe_Entity() override;
|
||||
#endif
|
||||
|
||||
static CModel* Create(ID3D11Device* pDevice, ID3D11DeviceContext* pContext);
|
||||
virtual CComponent* Clone(void* pArg, class CGameObject* pOwner = nullptr);
|
||||
virtual void Free(); public:
|
||||
void Describe_Entity() override;
|
||||
};
|
||||
|
||||
NS_END
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
#include "Transform.h"
|
||||
#include "VIBuffer_Rect.h"
|
||||
#include "VIBuffer_Cube.h"
|
||||
#include "VIBuffer_Cell.h"
|
||||
#include "Shader.h"
|
||||
#include "Navigation.h"
|
||||
|
||||
@@ -1,38 +1,44 @@
|
||||
#pragma once
|
||||
|
||||
#include "Component.h"
|
||||
|
||||
NS_BEGIN(Engine)
|
||||
|
||||
class ENGINE_DLL CShader final :
|
||||
public CComponent
|
||||
class ENGINE_DLL CShader final : public CComponent
|
||||
{
|
||||
private:
|
||||
CShader(ID3D11Device* pDevice, ID3D11DeviceContext* pContext);
|
||||
CShader(const CShader& rhs);
|
||||
virtual ~CShader() = default;
|
||||
CShader(ID3D11Device* pDevice, ID3D11DeviceContext* pContext);
|
||||
CShader(const CShader& rhs);
|
||||
virtual ~CShader() = default;
|
||||
|
||||
public:
|
||||
HRESULT Bind_RawValue(const _char* pConstantName, const void* pData, _uint iLength);
|
||||
HRESULT Bind_Matrix(const _char* pConstantName, const _float4x4* pMatrix);
|
||||
HRESULT Bind_Matrices(const _char* pConstantName, const _float4x4* pMatrices, _uint iNumMatrices);
|
||||
HRESULT Bind_SRV(const _char* pConstantName, ID3D11ShaderResourceView* pSRV);
|
||||
HRESULT Bind_SRVs(const _char* pConstantName, ID3D11ShaderResourceView** pSRVs, _uint iOffset, _uint iCount);
|
||||
HRESULT Begin(_uint iPassIndex);
|
||||
|
||||
private:
|
||||
vector<ID3D11InputLayout*> m_pLayouts = { nullptr };
|
||||
ID3DX11Effect* m_pEffect = { nullptr };
|
||||
_uint m_iNumPasses = {};
|
||||
|
||||
private:
|
||||
virtual HRESULT Initialize_Prototype(const _tchar* pShaderFilePath, const D3D11_INPUT_ELEMENT_DESC* pElements, _uint iNumElements);
|
||||
virtual HRESULT Initialize(void* pArg);
|
||||
virtual HRESULT Initialize_Prototype(const _tchar* pShaderFilePath, const D3D11_INPUT_ELEMENT_DESC* pElements, _uint iNumElements);
|
||||
virtual HRESULT Initialize(void* pArg) override;
|
||||
|
||||
public:
|
||||
static CShader* Create(ID3D11Device* pDevice, ID3D11DeviceContext* pContext, const _tchar* pShaderFilePath, const D3D11_INPUT_ELEMENT_DESC* pElements, _uint iNumElements);
|
||||
virtual CComponent* Clone(void* pArg, class CGameObject* pOwner) override;
|
||||
virtual void Free() override;
|
||||
void Describe_Entity() override;
|
||||
HRESULT Bind_RawValue(const _char* pConstantName, const void* pData, _uint iLength);
|
||||
HRESULT Bind_Matrix(const _char* pConstantName, const _float4x4* pMatrix);
|
||||
HRESULT Bind_Matrices(const _char* pConstantName, const _float4x4* pMatrix, _uint iNumMatrices);
|
||||
|
||||
HRESULT Bind_SRV(const _char* pConstantName, ID3D11ShaderResourceView* pSRV);
|
||||
HRESULT Bind_SRVs(const _char* pConstantName, ID3D11ShaderResourceView** ppSRV, _uint iNumSRVs);
|
||||
|
||||
public:
|
||||
HRESULT Begin(_uint iPassIndex);
|
||||
|
||||
private:
|
||||
ID3DX11Effect* m_pEffect = { nullptr };
|
||||
_uint m_iNumPasses = {};
|
||||
vector<ID3D11InputLayout*> m_InputLayouts;
|
||||
|
||||
|
||||
public:
|
||||
static CShader* Create(ID3D11Device* pDevice, ID3D11DeviceContext* pContext, const _tchar* pShaderFilePath, const D3D11_INPUT_ELEMENT_DESC* pElements, _uint iNumElements);
|
||||
virtual CComponent* Clone(void* pArg, class CGameObject* pOwner) override;
|
||||
virtual void Free() override;
|
||||
|
||||
// CComponentÀ»(¸¦) ÅëÇØ »ó¼ÓµÊ
|
||||
void Describe_Entity() override;
|
||||
};
|
||||
|
||||
NS_END
|
||||
@@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
#include "VIBuffer.h"
|
||||
|
||||
NS_BEGIN(Engine)
|
||||
|
||||
class ENGINE_DLL CVIBuffer_Cube final :
|
||||
public CVIBuffer
|
||||
{
|
||||
protected:
|
||||
CVIBuffer_Cube(ID3D11Device* pDevice, ID3D11DeviceContext* pContext);
|
||||
CVIBuffer_Cube(const CVIBuffer_Cube& rhs);
|
||||
virtual ~CVIBuffer_Cube() = default;
|
||||
|
||||
public:
|
||||
HRESULT Bind_Resources();
|
||||
HRESULT Bind_Resources(_uint iStartSlot, _uint iNumBuffer, vector<ID3D11Buffer*>& pBuffer, vector<_uint>& strides, vector<_uint>& offsets);
|
||||
pair<_float3*, _uint*> Get_VIPair() { return { m_pVertexPositions, m_pIndices }; }
|
||||
|
||||
private:
|
||||
virtual HRESULT Initialize_Prototype() override;
|
||||
virtual HRESULT Initialize(void* pArg) override;
|
||||
|
||||
public:
|
||||
static CVIBuffer_Cube* Create(ID3D11Device* pDevice, ID3D11DeviceContext* pContext);
|
||||
virtual CVIBuffer_Cube* Clone(void* pArg, class CGameObject* pOwner = nullptr) override;
|
||||
virtual void Free() override;
|
||||
virtual void Describe_Entity() override;
|
||||
};
|
||||
|
||||
NS_END
|
||||
Reference in New Issue
Block a user