Merge branch 'Develope' into UI
This commit is contained in:
@@ -151,7 +151,9 @@
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\Private\Animation.cpp" />
|
||||
<ClCompile Include="..\Private\Base.cpp" />
|
||||
<ClCompile Include="..\Private\Bone.cpp" />
|
||||
<ClCompile Include="..\Private\Bounding.cpp" />
|
||||
<ClCompile Include="..\Private\Bounding_AABB.cpp" />
|
||||
<ClCompile Include="..\Private\Bounding_OBB.cpp" />
|
||||
@@ -169,6 +171,7 @@
|
||||
</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\Private\Cell.cpp" />
|
||||
<ClCompile Include="..\Private\Channel.cpp" />
|
||||
<ClCompile Include="..\Private\Collider.cpp" />
|
||||
<ClCompile Include="..\Private\Component.cpp" />
|
||||
<ClCompile Include="..\Private\ContainerObject.cpp" />
|
||||
@@ -226,10 +229,13 @@
|
||||
</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" />
|
||||
<ClCompile Include="..\Private\Light_Manager.cpp" />
|
||||
<ClCompile Include="..\Private\Material.cpp" />
|
||||
<ClCompile Include="..\Private\Mesh.cpp" />
|
||||
<ClCompile Include="..\Private\Model.cpp" />
|
||||
<ClCompile Include="..\Private\Mouse_Manager.cpp" />
|
||||
<ClCompile Include="..\Private\MyTools.cpp" />
|
||||
@@ -256,9 +262,11 @@
|
||||
<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>
|
||||
<ClInclude Include="..\Public\Animation.h" />
|
||||
<ClInclude Include="..\Public\Assimp\aabb.h" />
|
||||
<ClInclude Include="..\Public\Assimp\ai_assert.h" />
|
||||
<ClInclude Include="..\Public\Assimp\anim.h" />
|
||||
@@ -344,6 +352,7 @@
|
||||
<ClInclude Include="..\Public\Assimp\XMLTools.h" />
|
||||
<ClInclude Include="..\Public\Assimp\ZipArchiveIOSystem.h" />
|
||||
<ClInclude Include="..\Public\Base.h" />
|
||||
<ClInclude Include="..\Public\Bone.h" />
|
||||
<ClInclude Include="..\Public\Bounding.h" />
|
||||
<ClInclude Include="..\Public\Bounding_AABB.h" />
|
||||
<ClInclude Include="..\Public\Bounding_OBB.h" />
|
||||
@@ -361,6 +370,7 @@
|
||||
</ExcludedFromBuild>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\Public\Cell.h" />
|
||||
<ClInclude Include="..\Public\Channel.h" />
|
||||
<ClInclude Include="..\Public\Collider.h" />
|
||||
<ClInclude Include="..\Public\Component.h" />
|
||||
<ClInclude Include="..\Public\ContainerObject.h" />
|
||||
@@ -421,10 +431,13 @@
|
||||
<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" />
|
||||
<ClInclude Include="..\Public\Light_Manager.h" />
|
||||
<ClInclude Include="..\Public\Material.h" />
|
||||
<ClInclude Include="..\Public\Mesh.h" />
|
||||
<ClInclude Include="..\Public\Model.h" />
|
||||
<ClInclude Include="..\Public\Mouse_Manager.h" />
|
||||
<ClInclude Include="..\Public\MyTools.h" />
|
||||
@@ -446,6 +459,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>
|
||||
|
||||
@@ -7,36 +7,6 @@
|
||||
<Filter Include="00.System\99.Base">
|
||||
<UniqueIdentifier>{0c9df74d-79e3-4ca1-87cd-22b0789afc1c}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="99.Define">
|
||||
<UniqueIdentifier>{2cb454c9-e390-4f2e-8cf5-b5c6325543ed}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="99.Define\00.DEFAULT">
|
||||
<UniqueIdentifier>{0e35cd1b-88f6-46b9-b72e-b46eeaacd4e0}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="99.Define\99.THIRDPARTY">
|
||||
<UniqueIdentifier>{32ca0c26-d3e2-49c5-8dc6-cc67e5291214}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="99.Define\99.THIRDPARTY\IMGUI">
|
||||
<UniqueIdentifier>{17dcadfe-e4cd-46c6-8122-e5e02bb73e57}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="99.Define\99.THIRDPARTY\FX11">
|
||||
<UniqueIdentifier>{c3e7b75b-ec8b-4071-8b52-e5c356febfa6}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="99.Define\99.THIRDPARTY\FMOD">
|
||||
<UniqueIdentifier>{57dd171f-f788-4918-aae2-85c20794b3cb}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="99.Define\99.THIRDPARTY\DXTK">
|
||||
<UniqueIdentifier>{40758cb1-0f91-4db9-bad7-7c77eb8002da}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="99.Define\99.THIRDPARTY\ASSIMP">
|
||||
<UniqueIdentifier>{bbf3ec67-56f5-4e67-b6cf-8eb1eb4400ff}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="99.Define\01.SHADER">
|
||||
<UniqueIdentifier>{30c382b4-2ac9-4355-b3a5-c1b3622c2982}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="99.Define\70.NS_SOUND">
|
||||
<UniqueIdentifier>{1622af23-8aca-43cd-8250-b289e363e613}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="00.System\01.Timer">
|
||||
<UniqueIdentifier>{de88c47e-55e3-4c50-8b4c-7dd94c0c837f}</UniqueIdentifier>
|
||||
</Filter>
|
||||
@@ -205,6 +175,45 @@
|
||||
<Filter Include="99.Define\TINYXML2">
|
||||
<UniqueIdentifier>{d93660eb-4bf9-43d2-902e-8ecbefd02481}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="99.Define">
|
||||
<UniqueIdentifier>{2cb454c9-e390-4f2e-8cf5-b5c6325543ed}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="99.Define\00.DEFAULT">
|
||||
<UniqueIdentifier>{0e35cd1b-88f6-46b9-b72e-b46eeaacd4e0}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="99.Define\99.THIRDPARTY">
|
||||
<UniqueIdentifier>{32ca0c26-d3e2-49c5-8dc6-cc67e5291214}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="99.Define\99.THIRDPARTY\IMGUI">
|
||||
<UniqueIdentifier>{17dcadfe-e4cd-46c6-8122-e5e02bb73e57}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="99.Define\99.THIRDPARTY\FX11">
|
||||
<UniqueIdentifier>{c3e7b75b-ec8b-4071-8b52-e5c356febfa6}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="99.Define\99.THIRDPARTY\FMOD">
|
||||
<UniqueIdentifier>{57dd171f-f788-4918-aae2-85c20794b3cb}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="99.Define\99.THIRDPARTY\DXTK">
|
||||
<UniqueIdentifier>{40758cb1-0f91-4db9-bad7-7c77eb8002da}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="99.Define\99.THIRDPARTY\ASSIMP">
|
||||
<UniqueIdentifier>{bbf3ec67-56f5-4e67-b6cf-8eb1eb4400ff}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="99.Define\01.SHADER">
|
||||
<UniqueIdentifier>{30c382b4-2ac9-4355-b3a5-c1b3622c2982}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="99.Define\70.NS_SOUND">
|
||||
<UniqueIdentifier>{1622af23-8aca-43cd-8250-b289e363e613}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<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">
|
||||
@@ -360,6 +369,27 @@
|
||||
<ClCompile Include="..\Private\tinyxml2.cpp">
|
||||
<Filter>99.Define\TINYXML2</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\Private\Mesh.cpp">
|
||||
<Filter>02.Element\02.Component\06.Model\Mesh</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\Private\Material.cpp">
|
||||
<Filter>02.Element\02.Component\06.Model\Material</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\Private\Bone.cpp">
|
||||
<Filter>02.Element\02.Component\06.Model\Bone</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\Private\Animation.cpp">
|
||||
<Filter>02.Element\02.Component\06.Model\Animation</Filter>
|
||||
</ClCompile>
|
||||
<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">
|
||||
@@ -881,6 +911,27 @@
|
||||
<ClInclude Include="..\Public\tinyxml2.h">
|
||||
<Filter>99.Define\TINYXML2</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\Public\Mesh.h">
|
||||
<Filter>02.Element\02.Component\06.Model\Mesh</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\Public\Material.h">
|
||||
<Filter>02.Element\02.Component\06.Model\Material</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\Public\Bone.h">
|
||||
<Filter>02.Element\02.Component\06.Model\Bone</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\Public\Animation.h">
|
||||
<Filter>02.Element\02.Component\06.Model\Animation</Filter>
|
||||
</ClInclude>
|
||||
<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">
|
||||
|
||||
@@ -0,0 +1,230 @@
|
||||
#include "pch.h"
|
||||
|
||||
#include "Animation.h"
|
||||
#include "Channel.h"
|
||||
|
||||
CAnimation::CAnimation()
|
||||
{
|
||||
/*XMMatrixDecompose();*/
|
||||
}
|
||||
|
||||
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 }
|
||||
{
|
||||
memcpy_s(m_TickPerSeconds, sizeof(_float) * 2, rhs.m_TickPerSeconds, sizeof(_float) * 2);
|
||||
|
||||
for (auto& pChannel : m_Channels) {
|
||||
SAFE_ADDREF(pChannel);
|
||||
}
|
||||
}
|
||||
_bool CAnimation::Update_TransformationMatrices(const vector<class CBone*>& Bones, _bool bIsLoop, _float fTimeDelta)
|
||||
{
|
||||
m_fCurrentTrackPosition += m_TickPerSeconds[m_bPause] * fTimeDelta;
|
||||
|
||||
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 = {};
|
||||
for (auto& pChannel : m_Channels) {
|
||||
pChannel->Update_TransformationMatirx(Bones, m_fCurrentTrackPosition, &m_CurrentKeyFrameIndices[iIndex++]);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void CAnimation::Depart_Animation()
|
||||
{
|
||||
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];
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
void CAnimation::Set_AnimProgressPostion(const _char* pChannelName, _uint iPosition)
|
||||
{
|
||||
Depart_Animation();
|
||||
|
||||
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);
|
||||
|
||||
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(hFile, dwByte)))
|
||||
{
|
||||
MSG_BOX("Failed to Created : CAnimation");
|
||||
SAFE_RELEASE(pInstance);
|
||||
}
|
||||
|
||||
return pInstance;
|
||||
}
|
||||
|
||||
CAnimation* CAnimation::Clone()
|
||||
{
|
||||
return new CAnimation(*this);
|
||||
}
|
||||
|
||||
void CAnimation::Free()
|
||||
{
|
||||
__super::Free();
|
||||
|
||||
for (auto& pChannel : m_Channels) {
|
||||
SAFE_RELEASE(pChannel);
|
||||
}
|
||||
m_Channels.clear();
|
||||
|
||||
m_CurrentKeyFrameIndices.clear();
|
||||
}
|
||||
;
|
||||
void CAnimation::Describe_Entity()
|
||||
{
|
||||
//if (GUI::CollapsingHeader(m_strName.c_str())) {
|
||||
//
|
||||
//}
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
#include "pch.h"
|
||||
#include "Bone.h"
|
||||
|
||||
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)
|
||||
{
|
||||
strcpy_s(m_szName, pAINode->mName.data);
|
||||
|
||||
m_iParentBoneIndex = 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;
|
||||
}
|
||||
|
||||
CBone* CBone::Create(HANDLE hFile, DWORD& dwByte)
|
||||
{
|
||||
CBone* pInstance = new CBone();
|
||||
|
||||
if (FAILED(pInstance->Initialize(hFile, dwByte)))
|
||||
{
|
||||
MSG_BOX("Failed to Created : CBone");
|
||||
SAFE_RELEASE(pInstance);
|
||||
}
|
||||
|
||||
return pInstance;
|
||||
}
|
||||
|
||||
CBone* CBone::Clone()
|
||||
{
|
||||
return new CBone(*this);
|
||||
}
|
||||
|
||||
void CBone::Free()
|
||||
{
|
||||
__super::Free();
|
||||
}
|
||||
@@ -0,0 +1,217 @@
|
||||
#include "pch.h"
|
||||
|
||||
#include "Channel.h"
|
||||
#include "Model.h"
|
||||
#include "Bone.h"
|
||||
|
||||
CChannel::CChannel()
|
||||
{
|
||||
}
|
||||
#ifdef EDITOR_PROJECT
|
||||
HRESULT CChannel::Initialize(const vector<CBone*>& Bones, const aiNodeAnim* pAIChannel)
|
||||
{
|
||||
strcpy_s(m_szName, pAIChannel->mNodeName.data);
|
||||
|
||||
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, (_uint)pAIChannel->mNumPositionKeys);
|
||||
|
||||
_float3 vScale = { };
|
||||
_float4 vRotation{};
|
||||
_float3 vTranslation{};
|
||||
for (size_t i = 0; i < m_iNumKeyFrames; i++)
|
||||
{
|
||||
KEYFRAME KeyFrame{};
|
||||
|
||||
if (i < pAIChannel->mNumScalingKeys)
|
||||
{
|
||||
memcpy(&vScale, &pAIChannel->mScalingKeys[i].mValue, sizeof(_float3));
|
||||
KeyFrame.fTrackPosition = (_float)pAIChannel->mScalingKeys[i].mTime;
|
||||
}
|
||||
|
||||
if (i < pAIChannel->mNumRotationKeys)
|
||||
{
|
||||
vRotation.x = pAIChannel->mRotationKeys[i].mValue.x;
|
||||
vRotation.y = pAIChannel->mRotationKeys[i].mValue.y;
|
||||
vRotation.z = pAIChannel->mRotationKeys[i].mValue.z;
|
||||
vRotation.w = pAIChannel->mRotationKeys[i].mValue.w;
|
||||
|
||||
KeyFrame.fTrackPosition = (_float)pAIChannel->mRotationKeys[i].mTime;
|
||||
}
|
||||
|
||||
if (i < pAIChannel->mNumPositionKeys)
|
||||
{
|
||||
memcpy(&vTranslation, &pAIChannel->mPositionKeys[i].mValue, sizeof(_float3));
|
||||
KeyFrame.fTrackPosition = (_float)pAIChannel->mPositionKeys[i].mTime;
|
||||
}
|
||||
|
||||
KeyFrame.vScale = vScale;
|
||||
KeyFrame.vRotation = vRotation;
|
||||
KeyFrame.vTranslation = vTranslation;
|
||||
|
||||
m_KeyFrames.push_back(KeyFrame);
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
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_TransformationMatirx(const vector<CBone*>& Bones, _float fCurrentTrackPosition, _uint* pCurrentKeyFrameIndex)
|
||||
|
||||
{
|
||||
if (0.f == fCurrentTrackPosition) {
|
||||
*pCurrentKeyFrameIndex = 0;
|
||||
}
|
||||
KEYFRAME LastKeyFrame = m_KeyFrames.back();
|
||||
|
||||
_vector vScale = {};
|
||||
_vector vRotation = {};
|
||||
_vector vTranslation = {};
|
||||
|
||||
if (fCurrentTrackPosition >= LastKeyFrame.fTrackPosition)
|
||||
{
|
||||
vScale = XMLoadFloat3(&LastKeyFrame.vScale);
|
||||
vRotation = XMLoadFloat4(&LastKeyFrame.vRotation);
|
||||
vTranslation = XMVectorSetW(XMLoadFloat3(&LastKeyFrame.vTranslation), 1.f);
|
||||
}
|
||||
else {
|
||||
while (fCurrentTrackPosition >= m_KeyFrames[*pCurrentKeyFrameIndex + 1].fTrackPosition) {
|
||||
++*pCurrentKeyFrameIndex;
|
||||
}
|
||||
|
||||
_float3 vSrcScale = {}, vDstScale = {};
|
||||
_float4 vSrcRotation = {}, vDstRotation = {};
|
||||
_float3 vSrcTranslation = {}, vDstTranslation = {};
|
||||
|
||||
vSrcScale = m_KeyFrames[*pCurrentKeyFrameIndex].vScale;
|
||||
vDstScale = m_KeyFrames[*pCurrentKeyFrameIndex + 1].vScale;
|
||||
|
||||
vSrcRotation = m_KeyFrames[*pCurrentKeyFrameIndex].vRotation;
|
||||
vDstRotation = m_KeyFrames[*pCurrentKeyFrameIndex + 1].vRotation;
|
||||
|
||||
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(&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);
|
||||
|
||||
Bones[m_iBoneIndex]->Set_TransformationMatrix(BoneTransformationMatrix);
|
||||
}
|
||||
|
||||
|
||||
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(Bones, iIndex)))
|
||||
{
|
||||
MSG_BOX("Failed to Created : CChannel");
|
||||
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;
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
;
|
||||
@@ -0,0 +1,243 @@
|
||||
#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_pGameInstance);
|
||||
}
|
||||
#ifdef EDITOR_PROJECT
|
||||
HRESULT CMaterial::Initialize(const _char* pModelFilePath, const aiMaterial* pAIMaterial)
|
||||
{
|
||||
for (size_t i = 0; i < AI_TEXTURE_TYPE_MAX; i++)
|
||||
{
|
||||
_uint iNumSRVs = pAIMaterial->GetTextureCount(static_cast<aiTextureType>(i));
|
||||
|
||||
m_SRVs[i].reserve(iNumSRVs);
|
||||
|
||||
ID3D11ShaderResourceView* pSRV = { nullptr };
|
||||
|
||||
HRESULT hr = {};
|
||||
|
||||
for (size_t j = 0; j < iNumSRVs; j++)
|
||||
{
|
||||
aiString strTexturePath;
|
||||
|
||||
if (FAILED(pAIMaterial->GetTexture(static_cast<aiTextureType>(i), (_uint)j, &strTexturePath))) {
|
||||
continue;
|
||||
}
|
||||
_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.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);
|
||||
|
||||
{
|
||||
_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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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::SaveAsBinary(HANDLE hFile, DWORD& dwByte)
|
||||
{
|
||||
// 실제 값을 저장하지 않고 파일이름.확장자명의 문자열을 저장해서 수정하기 편하게 만들기
|
||||
// 대신 리소스를 공유해야함
|
||||
// 텍스쳐를 저장하지 않고
|
||||
// 텍스쳐 경로만 ( "이름.확장자" ) 만 저장함
|
||||
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 S_OK;
|
||||
}
|
||||
CMaterial* CMaterial::Create(ID3D11Device* pDevice, ID3D11DeviceContext* pContext, const _char* pModelFilePath, const aiMaterial* pAIMaterial)
|
||||
{
|
||||
CMaterial* pInstance = new CMaterial(pDevice, pContext);
|
||||
|
||||
if (FAILED(pInstance->Initialize(pModelFilePath, pAIMaterial)))
|
||||
{
|
||||
MSG_BOX("Failed to Created : CMaterial");
|
||||
SAFE_RELEASE(pInstance);
|
||||
}
|
||||
|
||||
return pInstance;
|
||||
}
|
||||
#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_pGameInstance);
|
||||
SAFE_RELEASE(m_pDevice);
|
||||
SAFE_RELEASE(m_pContext);
|
||||
|
||||
for (auto& SRVs : m_SRVs)
|
||||
{
|
||||
for (auto& pSRV : SRVs) {
|
||||
SAFE_RELEASE(pSRV);
|
||||
}
|
||||
SRVs.clear();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,515 @@
|
||||
#include "pch.h"
|
||||
#include "Mesh.h"
|
||||
#include "Model.h"
|
||||
#include "Bone.h"
|
||||
#include "Shader.h"
|
||||
|
||||
CMesh::CMesh(ID3D11Device* pDevice, ID3D11DeviceContext* pContext)
|
||||
: CVIBuffer{ pDevice, pContext }
|
||||
{
|
||||
}
|
||||
|
||||
CMesh::CMesh(const CMesh& rhs)
|
||||
: CVIBuffer(rhs)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
m_iMaterialIndex = pAIMesh->mMaterialIndex;
|
||||
m_iNumVertexBuffers = 1;
|
||||
m_iNumVertices = pAIMesh->mNumVertices;
|
||||
|
||||
m_iNumIndices = pAIMesh->mNumFaces * 3;
|
||||
m_iIndexStride = 4;
|
||||
|
||||
m_eIndexFormat = DXGI_FORMAT_R32_UINT;
|
||||
m_ePrimitive = D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST;
|
||||
|
||||
#pragma region VERTEX_BUFFER
|
||||
|
||||
HRESULT hr = (eType == MODEL::NONANIM) ?
|
||||
Ready_VertexBuffer_For_NonAnim(pAIMesh, PreTransformMatrix) :
|
||||
Ready_VertexBuffer_For_Anim(Bones, pAIMesh);
|
||||
|
||||
#pragma endregion
|
||||
|
||||
#pragma region INDEX_BUFFER
|
||||
D3D11_BUFFER_DESC IBDesc{};
|
||||
IBDesc.ByteWidth = m_iIndexStride * m_iNumIndices;
|
||||
IBDesc.Usage = D3D11_USAGE_DEFAULT;
|
||||
IBDesc.BindFlags = D3D11_BIND_INDEX_BUFFER;
|
||||
IBDesc.StructureByteStride = m_iIndexStride;
|
||||
IBDesc.CPUAccessFlags = 0;
|
||||
IBDesc.MiscFlags = 0;
|
||||
|
||||
|
||||
_uint* pIndices = new _uint[m_iNumIndices];
|
||||
ZeroMemory(pIndices, sizeof(_uint) * m_iNumIndices);
|
||||
|
||||
_uint iNumIndices = {};
|
||||
|
||||
for (size_t i = 0; i < pAIMesh->mNumFaces; i++)
|
||||
{
|
||||
|
||||
pIndices[iNumIndices++] = pAIMesh->mFaces[i].mIndices[0];
|
||||
pIndices[iNumIndices++] = pAIMesh->mFaces[i].mIndices[1];
|
||||
pIndices[iNumIndices++] = pAIMesh->mFaces[i].mIndices[2];
|
||||
}
|
||||
|
||||
|
||||
D3D11_SUBRESOURCE_DATA InitialIBData{};
|
||||
InitialIBData.pSysMem = pIndices;
|
||||
|
||||
if (FAILED(m_pDevice->CreateBuffer(&IBDesc, &InitialIBData, &m_pIB)))
|
||||
return E_FAIL;
|
||||
|
||||
Safe_Delete_Array(pIndices);
|
||||
|
||||
#pragma endregion
|
||||
|
||||
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
#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;
|
||||
}
|
||||
|
||||
HRESULT CMesh::Initialize(void* pArg)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
#ifdef EDITOR_PROJECT
|
||||
CMesh* CMesh::Create(ID3D11Device* pDevice, ID3D11DeviceContext* pContext, MODEL eType, vector<class CBone*>& Bones, const aiMesh* pAIMesh, _fmatrix& PreTransformMatrix)
|
||||
{
|
||||
CMesh* pInstance = new CMesh(pDevice, pContext);
|
||||
|
||||
if (FAILED(pInstance->Initialize_Prototype(eType, Bones, pAIMesh, PreTransformMatrix)))
|
||||
{
|
||||
MSG_BOX("Failed to Created : CMesh");
|
||||
SAFE_RELEASE(pInstance);
|
||||
}
|
||||
|
||||
return pInstance;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
m_iVertexStride = sizeof(VTXMESH);
|
||||
D3D11_BUFFER_DESC VBDesc{};
|
||||
VBDesc.ByteWidth = m_iVertexStride * m_iNumVertices;
|
||||
VBDesc.Usage = D3D11_USAGE_DEFAULT;
|
||||
VBDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
|
||||
VBDesc.StructureByteStride = m_iVertexStride;
|
||||
VBDesc.CPUAccessFlags = 0;
|
||||
VBDesc.MiscFlags = 0;
|
||||
|
||||
VTXMESH* pVertices = new VTXMESH[m_iNumVertices];
|
||||
ZeroMemory(pVertices, sizeof(VTXMESH) * m_iNumVertices);
|
||||
|
||||
m_pVertexPositions = new _float3[m_iNumVertices];
|
||||
ZeroMemory(m_pVertexPositions, sizeof(_float3) * m_iNumVertices);
|
||||
|
||||
for (_uint i = 0; i < m_iNumVertices; ++i)
|
||||
{
|
||||
memcpy(&pVertices[i].vPosition, &pAIMesh->mVertices[i], sizeof(_float3));
|
||||
XMStoreFloat3(&pVertices[i].vPosition, XMVector3TransformCoord(XMLoadFloat3(&pVertices[i].vPosition), PreTransformMatrix));
|
||||
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{};
|
||||
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(vector<class CBone*>& Bones, const aiMesh* pAIMesh)
|
||||
{
|
||||
m_iVertexStride = sizeof(VTXANIMMESH);
|
||||
D3D11_BUFFER_DESC VBDesc{};
|
||||
VBDesc.ByteWidth = m_iVertexStride * m_iNumVertices;
|
||||
VBDesc.Usage = D3D11_USAGE_DEFAULT;
|
||||
VBDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
|
||||
VBDesc.StructureByteStride = m_iVertexStride;
|
||||
VBDesc.CPUAccessFlags = 0;
|
||||
VBDesc.MiscFlags = 0;
|
||||
|
||||
VTXANIMMESH* pVertices = new VTXANIMMESH[m_iNumVertices];
|
||||
ZeroMemory(pVertices, sizeof(VTXANIMMESH) * m_iNumVertices);
|
||||
|
||||
m_pVertexPositions = new _float3[m_iNumVertices];
|
||||
ZeroMemory(m_pVertexPositions, sizeof(_float3) * m_iNumVertices);
|
||||
|
||||
for (_uint i = 0; i < m_iNumVertices; ++i)
|
||||
{
|
||||
memcpy(&pVertices[i].vPosition, &pAIMesh->mVertices[i], sizeof(_float3));
|
||||
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_pBoneMatrices = new _float4x4[0 == m_iNumBones ? 1 : m_iNumBones];
|
||||
ZeroMemory(m_pBoneMatrices, sizeof(_float4x4) * m_iNumBones);
|
||||
|
||||
_float4x4 OffSetMatrix;
|
||||
XMStoreFloat4x4(&OffSetMatrix, XMMatrixIdentity());
|
||||
|
||||
for (_uint i = 0; i < m_iNumBones; ++i) {
|
||||
aiBone* pAIBone = pAIMesh->mBones[i];
|
||||
_uint iNumWeight = pAIBone->mNumWeights;
|
||||
|
||||
memcpy(&OffSetMatrix, &pAIBone->mOffsetMatrix, sizeof(_float4x4));
|
||||
XMStoreFloat4x4(&OffSetMatrix, XMMatrixTranspose(XMLoadFloat4x4(&OffSetMatrix)));
|
||||
|
||||
_int iBoneIndex = CModel::Get_BoneIndex(pAIBone->mName.data, Bones);
|
||||
|
||||
if (-1 == iBoneIndex) {
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
m_offsetMatrices.push_back(OffSetMatrix);
|
||||
m_BoneIndices.push_back(iBoneIndex);
|
||||
|
||||
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) {
|
||||
pVertices[AIWeight.mVertexId].vBlendIndex.y = i;
|
||||
pVertices[AIWeight.mVertexId].vBlendWeight.y = AIWeight.mWeight;
|
||||
}
|
||||
else if (0.f == pVertices[AIWeight.mVertexId].vBlendWeight.z) {
|
||||
pVertices[AIWeight.mVertexId].vBlendIndex.z = i;
|
||||
pVertices[AIWeight.mVertexId].vBlendWeight.z = AIWeight.mWeight;
|
||||
}
|
||||
else {
|
||||
pVertices[AIWeight.mVertexId].vBlendIndex.w = i;
|
||||
pVertices[AIWeight.mVertexId].vBlendWeight.w = AIWeight.mWeight;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (0 == m_iNumBones) {
|
||||
m_iNumBones = 1;
|
||||
m_BoneIndices.push_back(CModel::Get_BoneIndex(m_szName, Bones));
|
||||
m_offsetMatrices.push_back(OffSetMatrix);
|
||||
}
|
||||
|
||||
D3D11_SUBRESOURCE_DATA InitialVBData{};
|
||||
InitialVBData.pSysMem = pVertices;
|
||||
|
||||
if (FAILED(m_pDevice->CreateBuffer(&VBDesc, &InitialVBData, &m_pVB)))
|
||||
return E_FAIL;
|
||||
|
||||
Safe_Delete_Array(pVertices);
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
CMesh* CMesh::Create(ID3D11Device* pDevice, ID3D11DeviceContext* pContext, HANDLE hFile, DWORD& dwByte)
|
||||
{
|
||||
CMesh* pInstance = new CMesh(pDevice, pContext);
|
||||
|
||||
if (FAILED(pInstance->Initialize_Prototype(hFile, dwByte)))
|
||||
{
|
||||
MSG_BOX("Failed to Created : CMesh");
|
||||
SAFE_RELEASE(pInstance);
|
||||
}
|
||||
|
||||
return pInstance;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
return pInstance;
|
||||
}
|
||||
void CMesh::Free()
|
||||
{
|
||||
__super::Free();
|
||||
|
||||
Safe_Delete_Array(m_pBoneMatrices);
|
||||
}
|
||||
|
||||
void CMesh::Describe_Entity()
|
||||
{
|
||||
}
|
||||
@@ -1,2 +1,510 @@
|
||||
#include "pch.h"
|
||||
#include "Model.h"
|
||||
#include "Model.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 }
|
||||
{
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
_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, vector<class CBone*> Bones)
|
||||
{
|
||||
_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()) {
|
||||
|
||||
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
|
||||
{
|
||||
vector<CBone*>::const_iterator iter = find_if(m_Bones.begin(), m_Bones.end(), [&](CBone* pBone)->_bool
|
||||
{
|
||||
if (true == pBone->Compare_Name(pBoneName))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
|
||||
return (*iter)->Get_CombinedTransformationMatrixPtr();
|
||||
}
|
||||
|
||||
|
||||
_matrix CModel::Get_BoneMatrix(_uint iBoneIndex)
|
||||
{
|
||||
return m_Bones[iBoneIndex]->Get_CombinedTransformationMatrix();
|
||||
}
|
||||
|
||||
void CModel::Get_BoneMatrices(_float4x4* pOut)
|
||||
{
|
||||
if (0 == m_Bones.size()) {
|
||||
return;
|
||||
}
|
||||
for (_uint i = 0; i < m_Bones.size(); ++i) {
|
||||
pOut[i] = *m_Bones[i]->Get_CombinedTransformationMatrixPtr();
|
||||
}
|
||||
}
|
||||
|
||||
HRESULT CModel::Render(_uint iMeshIndex)
|
||||
{
|
||||
m_Meshes[iMeshIndex]->Bind_Resources();
|
||||
m_Meshes[iMeshIndex]->Render();
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CModel::Render_Indexed(_uint iMeshIndex, _uint IndexCount, _uint StartIndexLocation, _uint BaseVertexLocation)
|
||||
{
|
||||
m_Meshes[iMeshIndex]->Bind_Resources();
|
||||
m_Meshes[iMeshIndex]->Render_Indexed(IndexCount, StartIndexLocation, BaseVertexLocation);
|
||||
|
||||
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, 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 aiScene* pAIScene, const _char* pModelFilePath)
|
||||
{
|
||||
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_Animations(const aiScene* pAIScene)
|
||||
{
|
||||
m_iNumAnimations = pAIScene->mNumAnimations;
|
||||
m_Animations.reserve(m_iNumAnimations);
|
||||
for (size_t i = 0; i < m_iNumAnimations; i++)
|
||||
{
|
||||
CAnimation* pAnimation = CAnimation::Create(m_Bones, pAIScene->mAnimations[i]);
|
||||
if (nullptr == pAnimation)
|
||||
return E_FAIL;
|
||||
|
||||
m_Animations.push_back(pAnimation);
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CModel::Ready_Bones(const aiNode* pAINode, _int iParentIndex)
|
||||
{
|
||||
CBone* pBone = CBone::Create(pAINode, iParentIndex);
|
||||
if (nullptr == pBone) {
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
m_Bones.push_back(pBone);
|
||||
|
||||
_int iParent = (_int)(m_Bones.size() - 1);
|
||||
|
||||
for (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(pModelFilePath, eType, PreTransformMatrix, iRootBoneIndex)))
|
||||
{
|
||||
MSG_BOX("Failed to Created : CModel");
|
||||
SAFE_RELEASE(pInstance);
|
||||
}
|
||||
|
||||
return pInstance;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
return pInstance;
|
||||
}
|
||||
|
||||
|
||||
void CModel::Free()
|
||||
{
|
||||
__super::Free();
|
||||
|
||||
for (auto& pAnimation : m_Animations) {
|
||||
SAFE_RELEASE(pAnimation);
|
||||
}
|
||||
m_Animations.clear();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -33,11 +33,11 @@ void CRenderer::Refresh_Renderer()
|
||||
XMStoreFloat3(&m_CubeViewFrustum[i], XMVector3TransformCoord(XMVectorSet(m_CubeViewFrustum[i].x, m_CubeViewFrustum[i].y, m_CubeViewFrustum[i].z, 1.f), matProjInv));
|
||||
XMStoreFloat3(&m_CubeViewFrustum[i], XMVector3TransformCoord(XMVectorSet(m_CubeViewFrustum[i].x, m_CubeViewFrustum[i].y, m_CubeViewFrustum[i].z, 1.f), matViewInv));
|
||||
}
|
||||
// 0(1, 3, 4), 6(2, 5, 7) ( 법선벡터 후보 )
|
||||
// 0, 6( 한 점 후보)
|
||||
// 0(1, 3, 4), 6(2, 5, 7) ( 법선벡터 후보 )
|
||||
// 0, 6( 한 점 후보)
|
||||
//_float3 m_CubeNDC[8] = {
|
||||
// 근 좌하 우하 우상 좌상
|
||||
// 원 좌하 우하 우상 좌상
|
||||
// 근 좌하 우하 우상 좌상
|
||||
// 원 좌하 우하 우상 좌상
|
||||
// 0, 1, 2, 3
|
||||
// 4, 5, 6, 7
|
||||
//{ -1.f, -1.f, 0.f }, { 1.f, -1.f, 0.f }, { 1.f, 1.f, 0.f }, { -1.f, 1.f, 0.f },
|
||||
@@ -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);
|
||||
@@ -112,7 +112,7 @@ void CRenderer::Render()
|
||||
Render_NonLight();
|
||||
Render_Blend();
|
||||
Render_UI();
|
||||
//
|
||||
|
||||
//#ifdef _DEBUG
|
||||
// Render_Debug();
|
||||
//#endif
|
||||
@@ -388,7 +388,7 @@ void CRenderer::Render_UI()
|
||||
XMStoreFloat3(&vSrcPos, pSrc->Get_WorldPostion());
|
||||
|
||||
return vDstPos.z > vSrcPos.z;
|
||||
}); // z 소팅
|
||||
}); // z 소팅
|
||||
|
||||
for (auto& pRenderObject : m_RenderObjects[ENUM_CLASS(RENDER::UI)])
|
||||
{
|
||||
@@ -463,7 +463,7 @@ void CRenderer::Render_Debug()
|
||||
return;
|
||||
}
|
||||
|
||||
/* 렌더타겟을 디버그로 직교투영을 통해 그려라. */
|
||||
/* 렌더타겟을 디버그로 직교투영을 통해 그려라. */
|
||||
if (FAILED(m_pGameInstance->Render_RenderTarget_Debug(TEXT("MRT_GameObjects"), m_pShader, m_pVIBuffer))) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -25,8 +25,8 @@ HRESULT CTexture::Bind_ShaderResource(CShader* pShader, const _char* pConstantNa
|
||||
HRESULT CTexture::Bind_ShaderResources(CShader* pShader, const _char* pConstantName, _uint iOffset, _uint iCount)
|
||||
{
|
||||
|
||||
_uint iCnt = (iCount == UINT_MAX) ? (_uint)m_SRVs.size() : iCount;
|
||||
return pShader->Bind_SRVs(pConstantName, m_SRVs.data(), 0, iCnt);
|
||||
_uint iCnt = (iCount == UINT_MAX) ? (_uint)m_pSRVs.size() : iCount;
|
||||
return pShader->Bind_SRVs(pConstantName, m_pSRVs.data(), iCnt);
|
||||
}
|
||||
|
||||
ID3D11ShaderResourceView* CTexture::Get_SRV(_uint iTextureIndex)
|
||||
@@ -92,9 +92,9 @@ HRESULT CTexture::Load_SRV(const _char* szPath, ID3D11ShaderResourceView** ppSRV
|
||||
|
||||
HRESULT hr = {};
|
||||
|
||||
hr = CreateDDSTextureFromFile(m_pDevice, CMyTools::ToWstring(szTextureFilePath).c_str(), nullptr, ppSRV); // 일단 dds로 시도하고
|
||||
hr = CreateDDSTextureFromFile(m_pDevice, CMyTools::ToWstring(szTextureFilePath).c_str(), nullptr, ppSRV); // 일단 dds로 시도하고
|
||||
if (FAILED(hr)) {
|
||||
memset(szTextureFilePath, 0, sizeof(_char) * MAX_PATH); // 실패하면 원래 확장자로 다시 시도
|
||||
memset(szTextureFilePath, 0, sizeof(_char) * MAX_PATH); // 실패하면 원래 확장자로 다시 시도
|
||||
strcat_s(szTextureFilePath, szTextureFileName);
|
||||
strcat_s(szTextureFilePath, szEXT);
|
||||
|
||||
@@ -148,7 +148,7 @@ HRESULT CTexture::ParseTexturePathToSRVs(const _tchar* pTextureFolderPath)
|
||||
files.reserve(128);
|
||||
do {
|
||||
if (fileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
|
||||
continue; // ..폴더 무시
|
||||
continue; // ..폴더 무시
|
||||
}
|
||||
_wstring wstrName = fileData.cFileName;
|
||||
_wstring wstrFull = wstrFolder + L"\\" + wstrName;
|
||||
|
||||
@@ -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()
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
#pragma once
|
||||
|
||||
#include "Base.h"
|
||||
|
||||
NS_BEGIN(Engine)
|
||||
|
||||
class ENGINE_DLL CAnimation : public CBase
|
||||
{
|
||||
private:
|
||||
CAnimation();
|
||||
CAnimation(const CAnimation& rhs);
|
||||
virtual ~CAnimation() = default;
|
||||
public:
|
||||
_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:
|
||||
HRESULT Initialize(HANDLE hFile, DWORD& dwByte);
|
||||
HRESULT Combined_Initialize();
|
||||
_uint Get_BoneIndex(const char* pChannelName);
|
||||
|
||||
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; // 이 애니메이션이 영향을 준 사전 계산된 본의 배열
|
||||
vector<_uint> m_CurrentKeyFrameIndices; // 각 본이 현재 애니메이션에서 취해야할 키프레임 왼쪽 인덱스
|
||||
|
||||
vector<_int> m_DestBones; // 이 애니메이션에서 영향을 받는 본들의 집합
|
||||
vector<LERPDESC> m_StartKeyFrames; // 이 애니메이션의 영향을 받는 본들의 초기값
|
||||
|
||||
public:
|
||||
static CAnimation* Create(HANDLE hFile, DWORD& dwByte);
|
||||
CAnimation* Clone();
|
||||
virtual void Free() override;
|
||||
void Describe_Entity();
|
||||
};
|
||||
|
||||
NS_END
|
||||
@@ -0,0 +1,56 @@
|
||||
#pragma once
|
||||
|
||||
#include "Base.h"
|
||||
|
||||
NS_BEGIN(Engine)
|
||||
|
||||
class ENGINE_DLL CBone final : public CBase
|
||||
{
|
||||
private:
|
||||
CBone();
|
||||
virtual ~CBone() = default;
|
||||
public:
|
||||
_matrix Get_CombinedTransformationMatrix() const {
|
||||
return XMLoadFloat4x4(&m_CombinedTransformationMatrix);
|
||||
}
|
||||
_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);
|
||||
}
|
||||
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 = {}; // 본의 루트노드로부터 상대적인 복합매트릭스 ( 부모노드는 PreTranformMatrix와 월드좌표로부터 상대적임 )
|
||||
_int m_iParentBoneIndex = { -1 }; // 부모본의 인덱스 ( 모델에 있는 본벡터의 인덱스 ) ( 부모는 인덱스 -1 고정 )
|
||||
_float4x4 m_matInitial = {};
|
||||
|
||||
private:
|
||||
HRESULT Initialize(HANDLE hFile, DWORD& dwByte);
|
||||
|
||||
public:
|
||||
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
|
||||
@@ -0,0 +1,48 @@
|
||||
#pragma once
|
||||
|
||||
#include "Base.h"
|
||||
|
||||
NS_BEGIN(Engine)
|
||||
|
||||
class ENGINE_DLL CChannel : public CBase
|
||||
{
|
||||
private:
|
||||
CChannel();
|
||||
virtual ~CChannel() = default;
|
||||
|
||||
#ifdef EDITOR_PROJECT
|
||||
private:
|
||||
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:
|
||||
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;
|
||||
};
|
||||
|
||||
NS_END
|
||||
@@ -12,6 +12,30 @@ 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;
|
||||
XMFLOAT4 vRotation;
|
||||
XMFLOAT3 vTranslation;
|
||||
float fTrackPosition;
|
||||
|
||||
}KEYFRAME;
|
||||
|
||||
struct LERPDESC {
|
||||
_int iSlot;
|
||||
tagKeyFrame tagKeyFrame;
|
||||
};
|
||||
|
||||
typedef struct tagLightDesc
|
||||
{
|
||||
LIGHT eType;
|
||||
@@ -41,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;
|
||||
|
||||
@@ -42,7 +42,7 @@ class ENGINE_DLL CGameObject abstract
|
||||
const CGameObject* Get_Owner() const { return m_pOwner; }
|
||||
|
||||
public:
|
||||
HRESULT Add_Asset_Component(_uint iTargetLevel, const _wstring strPrototypeTag, CComponent** ppOut, void* pArg);
|
||||
HRESULT Add_Asset_Component(_uint iTargetLevel, const _wstring strPrototypeTag, CComponent** ppOut, void* pArg = nullptr);
|
||||
template<typename T>
|
||||
HRESULT Add_Component(_uint iPrototypeLevelIndex, T** ppOut, void* pArg = nullptr) {
|
||||
T* pComponent = m_pGameInstance->Clone_Prototype<T>(iPrototypeLevelIndex, pArg, this);
|
||||
|
||||
@@ -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
|
||||
@@ -0,0 +1,40 @@
|
||||
#pragma once
|
||||
|
||||
#include "Base.h"
|
||||
|
||||
NS_BEGIN(Engine)
|
||||
|
||||
class ENGINE_DLL CMaterial final : public CBase
|
||||
{
|
||||
private:
|
||||
CMaterial(ID3D11Device* pDevice, ID3D11DeviceContext* pContext);
|
||||
virtual ~CMaterial() = default;
|
||||
|
||||
public:
|
||||
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 };
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
NS_END
|
||||
@@ -0,0 +1,54 @@
|
||||
#pragma once
|
||||
|
||||
#include "VIBuffer.h"
|
||||
|
||||
NS_BEGIN(Engine)
|
||||
|
||||
class ENGINE_DLL CMesh final : public CVIBuffer
|
||||
{
|
||||
private:
|
||||
CMesh(ID3D11Device* pDevice, ID3D11DeviceContext* pContext);
|
||||
CMesh(const CMesh& rhs);
|
||||
virtual ~CMesh() = default;
|
||||
|
||||
public:
|
||||
_uint Get_MaterialIndex() const {
|
||||
return m_iMaterialIndex;
|
||||
}
|
||||
|
||||
HRESULT Bind_BoneMatrices(const vector<class CBone*>& Bones, class CShader* pShader, const _char* pConstantName);
|
||||
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(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, HANDLE hFile, DWORD& dwByte);
|
||||
virtual CMesh* Clone(void* pArg, class CGameObject* pOwner = nullptr) override;
|
||||
virtual void Free() override;
|
||||
void Describe_Entity() override;
|
||||
};
|
||||
|
||||
NS_END
|
||||
@@ -6,6 +6,90 @@ NS_BEGIN(Engine)
|
||||
|
||||
class ENGINE_DLL CModel final : public CComponent
|
||||
{
|
||||
private:
|
||||
CModel(ID3D11Device* pDevice, ID3D11DeviceContext* pContext);
|
||||
CModel(const CModel& rhs);
|
||||
virtual ~CModel() = default;
|
||||
|
||||
public:
|
||||
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;
|
||||
_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:
|
||||
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);
|
||||
|
||||
#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);
|
||||
#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);
|
||||
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
|
||||
@@ -28,7 +28,7 @@ class ENGINE_DLL CTexture final :
|
||||
HRESULT ParseTexturePathToSRVs(const _tchar* pTextureFolderPath);
|
||||
|
||||
private:
|
||||
vector<ID3D11ShaderResourceView*> m_SRVs = { };
|
||||
vector<ID3D11ShaderResourceView*> m_pSRVs = { };
|
||||
|
||||
public:
|
||||
static CTexture* Create(ID3D11Device* pDevice, ID3D11DeviceContext* pContext, TEXTURE_LOAD_TYPE eType, const _tchar* pTextureFilePath, const _wstring& wstrTextureKey, _uint iNumTextures);
|
||||
|
||||
@@ -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