Merge pull request #218 from SpicyGangjeong/MapTool

Map tool
This commit is contained in:
JinhoBa
2025-11-25 20:30:38 +09:00
committed by GitHub
24 changed files with 1319 additions and 12 deletions
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<Instance>
<SM_OakTree_MedA mesh="2">
<Mesh>
<Material>T_Oak_Leaves02_D</Material>
<Material>T_Oak_Leaves02_N</Material>
<Material>T_Oak_Leaves02_SRO</Material>
<Surface>SRO</Surface>
</Mesh>
<Mesh>
<Material>T_BogTree_Oak_BarkA_D</Material>
<Material>T_BogTree_Oak_BarkA_N</Material>
<Material>T_BogTree_Oak_BarkA_SROH</Material>
<Surface>SRO</Surface>
</Mesh>
</SM_OakTree_MedA>
</Instance>
@@ -0,0 +1,124 @@
#include "Engine_Shader_Defines.hlsli"
matrix g_WorldMatrix, g_ViewMatrix, g_ProjMatrix;
Texture2D g_DiffuseTexture;
Texture2D g_NormalTexture;
Texture2D g_SurfaceParamsTexture;
float4 g_vCamPosition;
float g_fFar;
float g_fUsingSurfaceParams;
struct VS_IN
{
float3 vPosition : POSITION;
float3 vNormal : NORMAL;
float3 vTangent : TANGENT;
float3 vBinormal : BINORMAL;
float2 vTexcoord : TEXCOORD0;
float4 vRight : TEXCOORD1;
float4 vUp : TEXCOORD2;
float4 vLook : TEXCOORD3;
float4 vTranslation : TEXCOORD4;
};
struct VS_OUT
{
float4 vPosition : SV_POSITION;
float4 vNormal : NORMAL;
float3 vTangent : TANGENT;
float3 vBinormal : BINORMAL;
float2 vTexcoord : TEXCOORD0;
float4 vWorldPos : TEXCOORD2;
float4 vProjPos : TEXCOORD3;
};
VS_OUT VS_MAIN(VS_IN In, uint iGPUIndex : SV_InstanceID)
{
VS_OUT Out = (VS_OUT) 0;
matrix matW, matWV, matWVP;
row_major matrix TransformMatrix = float4x4(In.vRight, In.vUp, In.vLook, In.vTranslation);
matW = TransformMatrix;
matWV = mul(matW, g_ViewMatrix);
matWVP = mul(matWV, g_ProjMatrix);
vector vPosition = mul(vector(In.vPosition, 1.f), matWVP);
Out.vPosition = vPosition;
Out.vNormal = normalize(mul(vector(In.vNormal, 0.f), matW));
Out.vTangent = normalize(mul(vector(In.vTangent, 0.f), matW)).xyz;
Out.vBinormal = normalize(mul(vector(In.vBinormal, 0.f), matW)).xyz;
Out.vTexcoord = In.vTexcoord;
Out.vWorldPos = mul(vector(In.vPosition, 1.f), matW);
Out.vProjPos = vPosition;
return Out;
}
struct PS_IN
{
float4 vPosition : SV_POSITION;
float4 vNormal : NORMAL;
float3 vTangent : TANGENT;
float3 vBinormal : BINORMAL;
float2 vTexcoord : TEXCOORD0;
float4 vWorldPos : TEXCOORD2;
float4 vProjPos : TEXCOORD3;
};
struct PS_OUT
{
float4 vAlbedo : SV_TARGET0;
float4 vNormal : SV_TARGET1;
float4 vDepth : SV_TARGET2;
float4 vColor : SV_Target3;
float4 vSurface : SV_Target4;
};
PS_OUT PS_MAIN(PS_IN In)
{
PS_OUT Out;
vector vMtrlDiffuse = g_DiffuseTexture.Sample(DefaultSampler, In.vTexcoord);
if (vMtrlDiffuse.a < 0.1f)
discard;
vector vMtrlNormal = g_NormalTexture.Sample(DefaultSampler, In.vTexcoord);
float3 vNormalDecoded = DecodeNormalFromRG(g_NormalTexture, DefaultSampler, In.vTexcoord);
float3x3 WorldMatrix = float3x3(In.vTangent, In.vBinormal * -1.f, In.vNormal.xyz);
float3 vNormal = normalize(mul(vNormalDecoded, WorldMatrix));
Out.vAlbedo = vMtrlDiffuse;
Out.vNormal = float4(vNormal.xyz * 0.5f + 0.5f, 0.f);
Out.vDepth = float4(In.vProjPos.z / In.vProjPos.w, In.vProjPos.w / g_fFar, 0.f, 0.0f);
Out.vColor = float4(0.f, 0.f, 0.f, 1.f);
Out.vSurface = g_SurfaceParamsTexture.Sample(DefaultSampler, In.vTexcoord);
return Out;
}
technique11 DefaultTechnique
{
pass Model
{
SetRasterizerState(RS_Default);
SetDepthStencilState(DSS_Default, 0);
SetBlendState(BS_None, float4(0.f, 0.f, 0.f, 0.f), 0xffffffff);
VertexShader = compile vs_5_0 VS_MAIN();
GeometryShader = NULL;
PixelShader = compile ps_5_0 PS_MAIN();
}
}
@@ -210,6 +210,7 @@
<ClInclude Include="..\Public\Dummy_PhysXPlayable.h" />
<ClInclude Include="..\public\HpBarBG.h" />
<ClInclude Include="..\Public\Bombard.h" />
<ClInclude Include="..\public\InstancedProp.h" />
<ClInclude Include="..\public\Magic_Icon.h" />
<ClInclude Include="..\public\Magic_Meter.h" />
<ClInclude Include="..\Public\NomalJap.h" />
@@ -347,6 +348,7 @@
<ClCompile Include="..\Private\Goblin_States.cpp" />
<ClCompile Include="..\private\HpBarBG.cpp" />
<ClCompile Include="..\Private\Bombard.cpp" />
<ClCompile Include="..\private\InstancedProp.cpp" />
<ClCompile Include="..\private\Magic_Icon.cpp" />
<ClCompile Include="..\private\Magic_Meter.cpp" />
<ClCompile Include="..\Private\NomalJap.cpp" />
@@ -483,6 +485,7 @@
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Effect</ShaderType>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|x64'">5.0</ShaderModel>
</FxCompile>
<FxCompile Include="..\Bin\Resources\ShaderFiles\Shader_VtxWorldModelInstance.hlsl" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
@@ -373,6 +373,9 @@
<Filter Include="02.GameObjects\Camera\CameraPosition\Player\Target">
<UniqueIdentifier>{1c4860c7-bc8a-4bed-b545-ed3ef0b02748}</UniqueIdentifier>
</Filter>
<Filter Include="02.GameObjects\Env\06.InstancedProp">
<UniqueIdentifier>{27dd1f59-44a7-4ecf-ad44-d72b2b4f9d34}</UniqueIdentifier>
</Filter>
<Filter Include="50.UI\GamePlay_Canvas\Action_Panel\Magic_Icon">
<UniqueIdentifier>{4967d007-a0d8-4d57-b259-7bb47b5cf9ea}</UniqueIdentifier>
</Filter>
@@ -735,6 +738,9 @@
<ClInclude Include="..\public\Magic_Meter.h">
<Filter>50.UI\GamePlay_Canvas\Action_Panel\Magic_Meter</Filter>
</ClInclude>
<ClInclude Include="..\public\InstancedProp.h">
<Filter>02.GameObjects\Env\06.InstancedProp</Filter>
</ClInclude>
<ClInclude Include="..\public\Magic_Icon.h">
<Filter>50.UI\GamePlay_Canvas\Action_Panel\Magic_Icon</Filter>
</ClInclude>
@@ -1093,6 +1099,9 @@
<ClCompile Include="..\Private\Player_States.cpp">
<Filter>02.GameObjects\Player</Filter>
</ClCompile>
<ClCompile Include="..\private\InstancedProp.cpp">
<Filter>02.GameObjects\Env\06.InstancedProp</Filter>
</ClCompile>
<ClCompile Include="..\private\Magic_Icon.cpp">
<Filter>50.UI\GamePlay_Canvas\Action_Panel\Magic_Icon</Filter>
</ClCompile>
@@ -1136,5 +1145,8 @@
<FxCompile Include="..\Bin\Resources\ShaderFiles\Shader_UI_Instance.hlsl">
<Filter>99.Define\SHADER</Filter>
</FxCompile>
<FxCompile Include="..\Bin\Resources\ShaderFiles\Shader_VtxWorldModelInstance.hlsl">
<Filter>99.Define\SHADER</Filter>
</FxCompile>
</ItemGroup>
</Project>
@@ -0,0 +1,312 @@
#include "pch.h"
#include "InstancedProp.h"
#include "VIBuffer_Model_Instance.h"
CInstancedProp::CInstancedProp(ID3D11Device* pDevice, ID3D11DeviceContext* pContext)
: CGameObject(pDevice, pContext)
{
}
CInstancedProp::CInstancedProp(const CInstancedProp& rhs)
:CGameObject(rhs)
{
}
void CInstancedProp::Priority_Update(_float fTimeDelta)
{
}
void CInstancedProp::Update(_float fTimeDelta)
{
if (m_pGameInstance->Mouse_Down(DIM_MBUTTON))
{
m_pVIBufferInstanceCom->Add_Instance(m_pTransformCom->Get_XMWorldMatrix());
_float4x4 WorldMatrix = {};
XMStoreFloat4x4(&WorldMatrix, m_pTransformCom->Get_XMWorldMatrix());
m_WorldMatrices.push_back(WorldMatrix);
m_pVIBufferInstanceCom->Update_Instance();
m_vRotation.y = m_pGameInstance->Random_Float(0.f, 360.f);
_float3 vPosition = {};
if (m_pGameInstance->isPicking(&vPosition))
{
memcpy(&m_vPosition, &vPosition, sizeof(_float3));
}
}
Describe_Entity();
}
void CInstancedProp::Late_Update(_float fTimeDelta)
{
m_pGameInstance->Add_RenderGroup(RENDER::NONBLEND, this);
}
HRESULT CInstancedProp::Render()
{
if(FAILED(Bind_ShaderResources()))
return E_FAIL;
_uint iNumMesh = m_pVIBufferInstanceCom->Get_NumMesh();
for (_uint i = 0; i < iNumMesh; i++)
{
if(FAILED(m_pVIBufferInstanceCom->Bind_Matrial(m_pShaderCom, i)))
return E_FAIL;
if (FAILED(m_pShaderCom->Begin(0)))
return E_FAIL;
m_pVIBufferInstanceCom->Render(i);
}
return S_OK;
}
HRESULT CInstancedProp::Initialize_Prototype()
{
return S_OK;
}
HRESULT CInstancedProp::Initialize(void* pArg)
{
if (FAILED(__super::Initialize(pArg)))
return E_FAIL;
if (FAILED(Ready_Components(pArg)))
return E_FAIL;
m_vPosition = _float4(0.f, 0.f, 0.f, 1.f);
m_vRotation = _float3(0.f, 0.f, 0.f);
m_vScale = _float3(1.f, 1.f, 1.f);
XMStoreFloat4x4(&m_WorldMatrixIdentity, XMMatrixIdentity());
return S_OK;
}
HRESULT CInstancedProp::Ready_Components(void* pArg)
{
if (FAILED(__super::Ready_Components(pArg)))
return E_FAIL;
/* Com_VIBuffer_Instance_Model */
if (FAILED(__super::Add_Asset_Component(g_iStaticLevel, TEXT("Prototype_Component_VIBuffer_Model_Instancel"),
reinterpret_cast<CComponent**>(&m_pVIBufferInstanceCom))))
return E_FAIL;
/* Com_Shader */
if (FAILED(__super::Add_Asset_Component(g_iStaticLevel, FX_INSTANCE_PROP_MODEL,
reinterpret_cast<CComponent**>(&m_pShaderCom))))
return E_FAIL;
CTexture* pTexture = { nullptr };
/* Com_Texture */
if (FAILED(Add_Asset_Component(g_iStaticLevel, TEXT("Terrain_Diffuse"), reinterpret_cast<CComponent**>(&pTexture), nullptr))) {
return E_FAIL;
}
m_pTextures.push_back(pTexture);
/* Com_Texture */
if (FAILED(Add_Asset_Component(g_iStaticLevel, TEXT("Terrain_Normal"), reinterpret_cast<CComponent**>(&pTexture), nullptr))) {
return E_FAIL;
}
m_pTextures.push_back(pTexture);
/* Com_Texture */
if (FAILED(Add_Asset_Component(g_iStaticLevel, TEXT("Terrain_MRO"), reinterpret_cast<CComponent**>(&pTexture), nullptr))) {
return E_FAIL;
}
m_pTextures.push_back(pTexture);
return S_OK;
}
HRESULT CInstancedProp::Bind_ShaderResources()
{
if (FAILED(m_pShaderCom->Bind_Matrix("g_WorldMatrix", &m_WorldMatrixIdentity))) {
return E_FAIL;
}
if (FAILED(m_pShaderCom->Bind_Matrix("g_ViewMatrix", m_pGameInstance->Get_Transform_Float4x4(D3DTS::VIEW)))) {
return E_FAIL;
}
if (FAILED(m_pShaderCom->Bind_Matrix("g_ProjMatrix", m_pGameInstance->Get_Transform_Float4x4(D3DTS::PROJ)))) {
return E_FAIL;
}
if (FAILED(m_pShaderCom->Bind_RawValue("g_fFar", m_pGameInstance->Get_CurrentCameraFar(), sizeof(_float)))) {
return E_FAIL;
}
return S_OK;
}
void CInstancedProp::Add_WorldMatrix()
{
_float4x4 WorldMatrix = {};
XMStoreFloat4x4(&WorldMatrix, XMMatrixIdentity());
m_WorldMatrices.push_back(WorldMatrix);
}
void CInstancedProp::Load_InstancedProp(const _char* pFilePath)
{
ifstream FileIn(pFilePath, ios::binary);
if (!FileIn.is_open())
{
MSG_BOX("Failed to Load InstancedProp File");
return;
}
m_WorldMatrices.clear();
_uint iNumWorldMatrix = 0;
FileIn.read(reinterpret_cast<char*>(&iNumWorldMatrix), sizeof(_uint));
m_WorldMatrices.reserve(iNumWorldMatrix);
for (_uint i = 0; i < iNumWorldMatrix; ++i)
{
_float4x4 WorldMatrix = {};
FileIn.read(reinterpret_cast<char*>(&WorldMatrix), sizeof(_float4x4));
m_WorldMatrices.push_back(WorldMatrix);
}
FileIn.close();
if (FAILED(m_pVIBufferInstanceCom->Load_WorldData(m_WorldMatrices)))
{
}
return;
}
#ifdef _DEBUG
void CInstancedProp::Save_InstancedProp(const _char* pFilePath)
{
ofstream FileOut(pFilePath, ios::binary);
if (!FileOut.is_open())
{
MSG_BOX("Failed to Save InstancedProp File");
return;
}
else
MSG_BOX("Successed to Save InstancedProp File");
_uint iNumWorldMatrix = static_cast<_uint>(m_WorldMatrices.size());
FileOut.write(reinterpret_cast<const char*>(&iNumWorldMatrix), sizeof(_uint));
for (_uint i = 0; i < iNumWorldMatrix; ++i)
{
FileOut.write(reinterpret_cast<const char*>(&m_WorldMatrices[i]), sizeof(_float4x4));
}
FileOut.close();
return;
}
#endif // _DEBUG
CInstancedProp* CInstancedProp::Create(ID3D11Device* pDevice, ID3D11DeviceContext* pContext)
{
CInstancedProp* pInstance = new CInstancedProp(pDevice, pContext);
if (FAILED(pInstance->Initialize_Prototype()))
{
MSG_BOX("Failed to Created : CInstancedProp");
SAFE_RELEASE(pInstance);
}
return pInstance;
}
CGameObject* CInstancedProp::Clone(void* pArg, CGameObject* pOwner)
{
CInstancedProp* pInstance = new CInstancedProp(*this);
pInstance->m_pOwner = pOwner;
if (FAILED(pInstance->Initialize(pArg)))
{
MSG_BOX("Failed to Cloned : CInstancedProp");
SAFE_RELEASE(pInstance);
}
return pInstance;
}
void CInstancedProp::Free()
{
__super::Free();
SAFE_RELEASE(m_pShaderCom);
SAFE_RELEASE(m_pVIBufferInstanceCom);
for (auto& pTexture : m_pTextures)
SAFE_RELEASE(pTexture);
m_pTextures.clear();
}
void CInstancedProp::Describe_Entity()
{
GUI::Begin("Instanced Prop");
m_pVIBufferInstanceCom->Describe_Entity();
GUI::Text("----- Transfrom ----");
GUI::InputFloat("X##Position", &m_vPosition.x, 0.1f, 1.f);
GUI::InputFloat("Y##Position", &m_vPosition.y, 0.1f, 1.f);
GUI::InputFloat("Z##Position", &m_vPosition.z, 0.1f, 1.f);
if (m_pGameInstance->Mouse_Down(DIM_LBUTTON) && m_pGameInstance->Key_Pressing(DIK_LSHIFT))
{
_float3 vPosition = {};
if (m_pGameInstance->isPicking(&vPosition))
{
memcpy(&m_vPosition, &vPosition, sizeof(_float3));
}
}
GUI::Text("----- Rotation ----");
GUI::InputFloat("X##Rotation", &m_vRotation.x, 10.f, 45.f);
GUI::InputFloat("Y##Rotation", &m_vRotation.y, 10.f, 45.f);
GUI::InputFloat("Z##Rotation", &m_vRotation.z, 10.f, 45.f);
GUI::Text("----- Scale ----");
GUI::InputFloat("X##Scale", &m_vScale.x, 0.1f, 1.f);
GUI::InputFloat("Y##Scale", &m_vScale.y, 0.1f, 1.f);
GUI::InputFloat("Z##Scale", &m_vScale.z, 0.1f, 1.f);
m_vScale.x = max(0.01f, m_vScale.x);
m_vScale.y = max(0.01f, m_vScale.y);
m_vScale.z = max(0.01f, m_vScale.z);
m_pTransformCom->Set_Scale(m_vScale);
m_pTransformCom->Set_State(STATE::POSITION, XMLoadFloat4(&m_vPosition));
m_pTransformCom->Rotation(XMConvertToRadians(m_vRotation.x), XMConvertToRadians(m_vRotation.y), XMConvertToRadians(m_vRotation.z));
m_pVIBufferInstanceCom->Fix_Instance(m_pTransformCom->Get_XMWorldMatrix());
if (GUI::Button("Delete", ImVec2(150.f, 30.f)))
{
m_pVIBufferInstanceCom->Delete_Instance();
}
GUI::InputText("File Name", m_szFileName, sizeof(m_szFileName));
if (GUI::Button("Save Instanced Prop", ImVec2(150.f, 30.f)))
{
Save_InstancedProp(("../Bin/Resources/Data/Map/Instance/" + string(m_szFileName)+ ".bin").c_str());
}
if (GUI::Button("Load Instanced Prop", ImVec2(150.f, 30.f)))
{
Load_InstancedProp(("../Bin/Resources/Data/Map/Instance/" + string(m_szFileName) + ".bin").c_str());
}
GUI::End();
}
@@ -10,6 +10,7 @@
#include "DummySkyBox.h"
#include "MainLight.h"
#include "Land.h"
#include "InstancedProp.h"
#include "Player.h"
CLevel_MapViewer::CLevel_MapViewer(ID3D11Device* pDevice, ID3D11DeviceContext* pContext, LEVEL eLevelID)
@@ -125,6 +126,9 @@ HRESULT CLevel_MapViewer::Ready_Layer_MapObjectManager(const _wstring& strLayerT
if (FAILED(m_pGameInstance->Add_GameObject_ToLayer<CMapObject_Manager>(g_iStaticLevel, NEXT_LEVEL, strLayerTag)))
return E_FAIL;
if (FAILED(m_pGameInstance->Add_GameObject_ToLayer<CInstancedProp>(g_iStaticLevel, NEXT_LEVEL, strLayerTag)))
return E_FAIL;
return S_OK;
}
+23
View File
@@ -81,6 +81,9 @@
#include "MapElement_Static.h"
#include "Land.h"
#include "Collider.h"
#include "VIBuffer_Model_Instance.h"
#include "Instance_Model.h"
#include "InstancedProp.h"
#pragma endregion
@@ -2125,6 +2128,12 @@ vector<vector<FOLDER_LOAD*>*> Contents(iLoadCount);
m_strMessage = TEXT("쉐이더를(을) 로딩 중 입니다.");
if (FAILED(m_pGameInstance->Add_Asset_Prototype(g_iStaticLevel, FX_INSTANCE_PROP_MODEL,
CShader::Create(m_pDevice, m_pContext, TEXT("../Bin/Resources/ShaderFiles/Shader_VtxWorldModelInstance.hlsl"),
VTX_MODEL_INSTANCE_MODEL::Elements, VTX_MODEL_INSTANCE_MODEL::iNumElements)))) {
return E_FAIL;
}
m_strMessage = TEXT("객체원형를(을) 로딩 중 입니다.");
@@ -2138,6 +2147,16 @@ vector<vector<FOLDER_LOAD*>*> Contents(iLoadCount);
CVIBuffer_Terrain::Create(m_pDevice, m_pContext, "../Bin/Resources/Data/Map/T_LandscapeStreamingProxy_0_LOD1_D.png", 512, 512))))
return E_FAIL;
CVIBuffer_Model_Instance::INSTANCE_DESC InstanceDesc = {};
InstanceDesc.iNum = 500;
/* For.Prototype_Component_VIBuffer_Model_Instancel */
if (FAILED(m_pGameInstance->Add_Asset_Prototype(g_iStaticLevel, TEXT("Prototype_Component_VIBuffer_Model_Instancel"),
CVIBuffer_Model_Instance::Create(m_pDevice, m_pContext, &InstanceDesc,
"../Bin/Resources/Models/InstanceProp/Tree/SM_OakTree_MedA.fbx", "../Bin/Resources/Data/Map/Instance/InstanceMaterial.xml"))))
return E_FAIL;
/* For.Prototype_GameObject_SkyBox */
if (FAILED(m_pGameInstance->Add_Prototype<CDummySkyBox>(g_iStaticLevel, CDummySkyBox::Create(m_pDevice, m_pContext)))) {
return E_FAIL;
@@ -2172,6 +2191,10 @@ vector<vector<FOLDER_LOAD*>*> Contents(iLoadCount);
if (FAILED(m_pGameInstance->Add_Prototype<CTerrain>(g_iStaticLevel, CTerrain::Create(m_pDevice, m_pContext))))
return E_FAIL;
/* For.Prototype_GameObject_InstancedProp */
if (FAILED(m_pGameInstance->Add_Prototype<CInstancedProp>(g_iStaticLevel, CInstancedProp::Create(m_pDevice, m_pContext))))
return E_FAIL;
/* For.Prototype_GameObject_MapObject_Manager */
if (FAILED(m_pGameInstance->Add_Prototype<CMapObject_Manager>(g_iStaticLevel, CMapObject_Manager::Create(m_pDevice, m_pContext, ModelPrototypeTags, ModelPrototypePath))))
return E_FAIL;
+10 -9
View File
@@ -10,15 +10,16 @@ namespace Editor {
#pragma region FX_NAME
#define FX_ANIMMESH TEXT("FX_ANIMMESH")
#define FX_MESH TEXT("FX_MESH")
#define FX_POSTEX TEXT("FX_POSTEX")
#define FX_NORTEX TEXT("FX_NORTEX")
#define FX_CELL TEXT("FX_CELL")
#define FX_PARTICLE TEXT("FX_PARTICLE")
#define FX_INSTANCE_MODEL TEXT("FX_INSTANCE_MODEL")
#define FX_UIEDITOR TEXT("FX_UIEDITOR")
#define FX_UIINSTANCE TEXT("FX_UIINSTANCE")
#define FX_ANIMMESH TEXT("FX_ANIMMESH")
#define FX_MESH TEXT("FX_MESH")
#define FX_POSTEX TEXT("FX_POSTEX")
#define FX_NORTEX TEXT("FX_NORTEX")
#define FX_CELL TEXT("FX_CELL")
#define FX_PARTICLE TEXT("FX_PARTICLE")
#define FX_INSTANCE_MODEL TEXT("FX_INSTANCE_MODEL")
#define FX_INSTANCE_PROP_MODEL TEXT("FX_INSTANCE_PROP_MODEL")
#define FX_UIEDITOR TEXT("FX_UIEDITOR")
#define FX_UIINSTANCE TEXT("FX_UIINSTANCE")
#pragma endregion
@@ -0,0 +1,68 @@
#pragma once
#include "Editor_Define.h"
#include "GameObject.h"
NS_BEGIN(Engine)
class CVIBuffer_Model_Instance;
class CShader;
class CTexture;
NS_END
NS_BEGIN(Editor)
class CInstancedProp final : public CGameObject
{
public:
typedef struct tagInstancedPropDesc
{
string strModelFilePath;
string strTextureFilePath;
}INSTANCE_PROP_DESC;
private:
CInstancedProp(ID3D11Device* pDevice, ID3D11DeviceContext* pContext);
CInstancedProp(const CInstancedProp& rhs);
virtual ~CInstancedProp() = default;
public:
virtual void Priority_Update(_float fTimeDelta) override;
virtual void Update(_float fTimeDelta) override;
virtual void Late_Update(_float fTimeDelta) override;
virtual HRESULT Render() override;
private:
CVIBuffer_Model_Instance* m_pVIBufferInstanceCom = { nullptr };
CShader* m_pShaderCom = { nullptr };
vector<CTexture*> m_pTextures = {};
vector<_float4x4> m_WorldMatrices = {};
_float4x4 m_WorldMatrixIdentity = {};
#ifdef _DEBUG
_char m_szFileName[MAX_PATH] = {};
_float4 m_vPosition = {};
_float3 m_vRotation = {};
_float3 m_vScale = {};
#endif // _DEBUG
private:
virtual HRESULT Initialize_Prototype() override;
virtual HRESULT Initialize(void* pArg) override;
virtual HRESULT Ready_Components(void* pArg) override;
virtual HRESULT Bind_ShaderResources() override;
void Add_WorldMatrix();
void Load_InstancedProp(const _char* pFilePath);
#ifdef _DEBUG
void Save_InstancedProp(const _char* pFilePath);
#endif // _DEBUG
public:
static CInstancedProp* Create(ID3D11Device* pDevice, ID3D11DeviceContext* pContext);
virtual CGameObject* Clone(void* pArg, class CGameObject* pOwner) override;
virtual void Free() override;
void Describe_Entity() override;
};
NS_END
@@ -316,6 +316,7 @@ call Update_Lib.bat
<ClCompile Include="..\Private\Instance_Model.cpp" />
<ClCompile Include="..\private\VIBuffer_Instance.cpp" />
<ClCompile Include="..\Private\Trail.cpp" />
<ClCompile Include="..\Private\VIBuffer_Model_Instance.cpp" />
<ClCompile Include="..\Private\VIBuffer_Rect.cpp" />
<ClCompile Include="..\private\VIBuffer_UI_Instance.cpp" />
<ClCompile Include="..\Private\VIBuffer_Terrain.cpp" />
@@ -560,6 +561,7 @@ call Update_Lib.bat
<ClInclude Include="..\Public\Instance_Model.h" />
<ClInclude Include="..\public\VIBuffer_Instance.h" />
<ClInclude Include="..\Public\Trail.h" />
<ClInclude Include="..\Public\VIBuffer_Model_Instance.h" />
<ClInclude Include="..\Public\VIBuffer_Rect.h" />
<ClInclude Include="..\public\VIBuffer_UI_Instance.h" />
<ClInclude Include="..\Public\VIBuffer_Terrain.h" />
@@ -286,6 +286,9 @@
<Filter Include="02.Element\02.Component\02.VIBuffer\Terrain\QuadTree">
<UniqueIdentifier>{d9f03f43-e9d1-4a50-b465-e1000462bd3e}</UniqueIdentifier>
</Filter>
<Filter Include="02.Element\02.Component\02.VIBuffer\Instance\Model_Instance">
<UniqueIdentifier>{d76a5d4a-1627-448d-9631-239540dd8eb2}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\Private\Base.cpp">
@@ -540,6 +543,9 @@
<ClCompile Include="..\Private\ThreadHolder.cpp">
<Filter>00.System\02.ThreadHolder</Filter>
</ClCompile>
<ClCompile Include="..\Private\VIBuffer_Model_Instance.cpp">
<Filter>02.Element\02.Component\02.VIBuffer\Instance\Model_Instance</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\Public\Base.h">
@@ -1163,6 +1169,9 @@
<ClInclude Include="..\Public\stb_image.h">
<Filter>99.Define\99.THIRDPARTY</Filter>
</ClInclude>
<ClInclude Include="..\Public\VIBuffer_Model_Instance.h">
<Filter>02.Element\02.Component\02.VIBuffer\Instance\Model_Instance</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\Public\Assimp\color4.inl">
@@ -0,0 +1,624 @@
#include "pch.h"
#include "VIBuffer_Model_Instance.h"
#include "Mesh.h"
#include "Bone.h"
#include "Model.h"
#include "Transform.h"
#include "Shader.h"
CVIBuffer_Model_Instance::CVIBuffer_Model_Instance(ID3D11Device* pDevice, ID3D11DeviceContext* pContext)
: CVIBuffer_Instance(pDevice, pContext)
, m_iNumBuffer{ 2 }
{
}
CVIBuffer_Model_Instance::CVIBuffer_Model_Instance(const CVIBuffer_Model_Instance& rhs)
: CVIBuffer_Instance(rhs)
, m_iNumBuffer(rhs.m_iNumBuffer)
, m_iCurrentNumInstance( rhs.m_iCurrentNumInstance )
, m_iNumMeshes(rhs.m_iNumMeshes)
, m_iMaxNumInstance(rhs.m_iMaxNumInstance)
, m_Meshes(rhs.m_Meshes)
, m_InstanceDesc(rhs.m_InstanceDesc)
, m_MeshMaterialsSRV(rhs.m_MeshMaterialsSRV)
, m_SurfaceMaterialFlag(rhs.m_SurfaceMaterialFlag)
#ifdef EDITOR_PROJECT
, m_pAIScene(rhs.m_pAIScene)
, m_MeshMaterialPathes(rhs.m_MeshMaterialPathes)
#endif // EDITOR_PROJECT
{
for (auto& pMesh : m_Meshes)
SAFE_ADDREF(pMesh);
for (auto& SRVs : m_MeshMaterialsSRV)
{
for (auto& pSRV : SRVs)
SAFE_ADDREF(pSRV);
}
}
HRESULT CVIBuffer_Model_Instance::Initialize_Prototype(const _char* pFileName)
{
SaveMesh SaveMesh_Desc = {};
CModel* pModel = { nullptr };
/* Read File */
ifstream in(pFileName, ios::binary);
if (!in.is_open())
{
MSG_BOX("Failed to Load : Instance Data");
return E_FAIL;
}
in.read(reinterpret_cast<_char*>(&SaveMesh_Desc.MeshNameSize), sizeof(_uint));
in.read(reinterpret_cast<_char*>(&SaveMesh_Desc.VertexCount), sizeof(_uint));
in.read(reinterpret_cast<_char*>(&SaveMesh_Desc.IndexCount), sizeof(_uint));
in.read(reinterpret_cast<_char*>(&SaveMesh_Desc.MaterialIndex), sizeof(_uint));
in.read(reinterpret_cast<_char*>(&SaveMesh_Desc.BoneCount), sizeof(_uint));
in.read(reinterpret_cast<_char*>(&SaveMesh_Desc.MeshName), sizeof(char) * SaveMesh_Desc.MeshNameSize);
in.read(reinterpret_cast<_char*>(SaveMesh_Desc.Vertices.data()), sizeof(SaveVertex) * SaveMesh_Desc.VertexCount);
in.read(reinterpret_cast<_char*>(SaveMesh_Desc.Indices.data()), sizeof(_uint) * SaveMesh_Desc.IndexCount);
SaveMesh_Desc.Bones.resize(SaveMesh_Desc.BoneCount);
in.read(reinterpret_cast<_char*>(&m_iNumMeshes), sizeof(_uint));
if (FAILED(Load_InstanceData(in)))
return E_FAIL;
for (_uint i = 0; i < m_iNumMeshes; ++i)
{
CMesh* pMesh = CMesh::Create(m_pDevice, m_pContext, MODEL::NONANIM, pModel, &SaveMesh_Desc, XMMatrixIdentity());
if (nullptr == pMesh)
return E_FAIL;
m_Meshes.push_back(pMesh);
}
in.close();
return S_OK;
}
HRESULT CVIBuffer_Model_Instance::Initialize(void* pArg)
{
if (FAILED(Load_InstanceData_Editor()))
return E_FAIL;
return S_OK;
}
HRESULT CVIBuffer_Model_Instance::Render(_uint iMeshIndex)
{
m_Meshes[iMeshIndex]->Bind_Resources_Instance(m_pVBInstance, m_iInstanceStride, m_iNumBuffer);
m_Meshes[iMeshIndex]->Render_Instance(m_iNumInstance);
return S_OK;
}
HRESULT CVIBuffer_Model_Instance::Bind_Matrial(CShader* pShader, _uint iMeshIndex)
{
if(FAILED(pShader->Bind_SRV("g_DiffuseTexture", m_MeshMaterialsSRV[iMeshIndex][0])))
return E_FAIL;
if(FAILED(pShader->Bind_SRV("g_NormalTexture", m_MeshMaterialsSRV[iMeshIndex][1])))
return E_FAIL;
if(FAILED(pShader->Bind_SRV("g_SurfaceParamsTexture", m_MeshMaterialsSRV[iMeshIndex][2])))
return E_FAIL;
_float fUsingSurfaceParams = ((_float)m_SurfaceMaterialFlag[iMeshIndex] / (_float)AI_TEXTURE_TYPE_MAX);
if (FAILED(pShader->Bind_RawValue("g_fUsingSurfaceParams", &fUsingSurfaceParams, sizeof(_float))))
return E_FAIL;
return S_OK;
}
HRESULT CVIBuffer_Model_Instance::Load_WorldData(vector<_float4x4>& WorldMatrices)
{
m_iCurrentNumInstance = (_uint)WorldMatrices.size();
if (m_iMaxNumInstance <= m_iCurrentNumInstance)
return E_FAIL;
D3D11_MAPPED_SUBRESOURCE SubResource{};
if (FAILED(m_pContext->Map(m_pVBInstance, 0, D3D11_MAP_WRITE_DISCARD, 0, &SubResource)))
return E_FAIL;
VTX_INSTANCE_MODEL* pData = static_cast<VTX_INSTANCE_MODEL*>(SubResource.pData);
for (_uint i = 0; i < m_iCurrentNumInstance; i++)
{
memcpy(&pData[i].vRight, &WorldMatrices[i].m[0], sizeof(_float4));
memcpy(&pData[i].vUp, &WorldMatrices[i].m[1], sizeof(_float4));
memcpy(&pData[i].vLook, &WorldMatrices[i].m[2], sizeof(_float4));
memcpy(&pData[i].vTranslation, &WorldMatrices[i].m[3], sizeof(_float4));
}
m_iNumInstance = m_iCurrentNumInstance;
m_pContext->Unmap(m_pVBInstance, 0);
return S_OK;
}
HRESULT CVIBuffer_Model_Instance::Reay_Instance_Buffer()
{
m_iNumInstance = m_InstanceDesc.iNum;
m_iInstanceStride = sizeof(VTX_INSTANCE_MODEL);
D3D11_BUFFER_DESC InstanceBufferDesc = {};
InstanceBufferDesc.ByteWidth = m_iInstanceStride * m_iNumInstance;
InstanceBufferDesc.Usage = D3D11_USAGE_DYNAMIC;
InstanceBufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
InstanceBufferDesc.StructureByteStride = m_iInstanceStride;
InstanceBufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
InstanceBufferDesc.MiscFlags = 0;
if (FAILED(m_pDevice->CreateBuffer(&InstanceBufferDesc, nullptr, &m_pVBInstance)))
return E_FAIL;
return S_OK;
}
HRESULT CVIBuffer_Model_Instance::Load_InstanceData(ifstream& in)
{
in.read(reinterpret_cast<_char*>(&m_iNumInstance), sizeof(_uint));
if (FAILED(Reay_Instance_Buffer()))
return E_FAIL;
/* Input Data */
D3D11_MAPPED_SUBRESOURCE SubResource{};
if (FAILED(m_pContext->Map(m_pVBInstance, 0, D3D11_MAP_WRITE_DISCARD, 0, &SubResource)))
{
in.close();
return E_FAIL;
}
VTX_INSTANCE_MODEL* pData = static_cast<VTX_INSTANCE_MODEL*>(SubResource.pData);
for (_uint i = 0; i < m_iNumInstance; ++i)
{
in.read(reinterpret_cast<_char*>(&pData[i]), sizeof(VTX_INSTANCE_MODEL));
}
m_pContext->Unmap(m_pVBInstance, 0);
return S_OK;
}
HRESULT CVIBuffer_Model_Instance::Ready_Materials()
{
for (_uint i = 0; i < m_iNumMeshes; ++i)
{
vector<ID3D11ShaderResourceView*> SRVs = {};
for (_uint j = 0; j < 3; ++j)
{
ID3D11ShaderResourceView* pSRV = { nullptr };
if (FAILED(CreateDDSTextureFromFile(m_pDevice, CMyTools::ToWstring(m_MeshMaterialPathes[i][j]).c_str(), nullptr, &pSRV)))
{
if (FAILED(CreateWICTextureFromFile(m_pDevice, CMyTools::ToWstring(m_MeshMaterialPathes[i][j]).c_str(), nullptr, &pSRV)))
return E_FAIL;
}
SRVs.push_back(pSRV);
}
m_MeshMaterialsSRV.push_back(SRVs);
}
return S_OK;
}
#ifdef EDITOR_PROJECT
HRESULT CVIBuffer_Model_Instance::Save_InstanceData(_char* pFileName)
{
#pragma region SAVE_MESH
SaveMesh saveMesh{};
if (SaveAssimpModel(saveMesh))
return E_FAIL;
ofstream out(pFileName, ios::binary);
if (!out.is_open())
{
MSG_BOX("Failed to Save : Instance Data");
return E_FAIL;
}
out.write(reinterpret_cast<_char*>(&saveMesh.MeshNameSize), sizeof(_uint));
out.write(reinterpret_cast<_char*>(&saveMesh.VertexCount), sizeof(_uint));
out.write(reinterpret_cast<_char*>(&saveMesh.IndexCount), sizeof(_uint));
out.write(reinterpret_cast<_char*>(&saveMesh.MaterialIndex), sizeof(_uint));
out.write(reinterpret_cast<_char*>(&saveMesh.BoneCount), sizeof(_uint));
out.write(reinterpret_cast<_char*>(&saveMesh.MeshName), sizeof(char) * saveMesh.MeshNameSize);
out.write(reinterpret_cast<_char*>(saveMesh.Vertices.data()), sizeof(SaveVertex) * saveMesh.VertexCount);
out.write(reinterpret_cast<_char*>(saveMesh.Indices.data()), sizeof(_uint) * saveMesh.IndexCount);
out.write(reinterpret_cast<const _char*>(&saveMesh.MeshNameSize), sizeof(_uint));
out.write(reinterpret_cast<_char*>(&m_iNumMeshes), sizeof(_uint));
#pragma endregion
#pragma region INSTANCE_DATA
out.write(reinterpret_cast<_char*>(&m_iCurrentNumInstance), sizeof(_uint));
D3D11_MAPPED_SUBRESOURCE SubResource{};
if (FAILED(m_pContext->Map(m_pVBInstance, 0, D3D11_MAP_READ, 0, &SubResource)))
{
out.close();
return E_FAIL;
}
VTX_INSTANCE_MODEL* pData = static_cast<VTX_INSTANCE_MODEL*>(SubResource.pData);
for (_uint i = 0; i < m_iCurrentNumInstance; ++i)
{
out.write(reinterpret_cast<_char*>(&pData[i]), sizeof(VTX_INSTANCE_MODEL));
}
m_pContext->Unmap(m_pVBInstance, 0);
#pragma endregion
out.close();
return S_OK;
}
_bool CVIBuffer_Model_Instance::SaveAssimpModel(SaveMesh& saveMesh)
{
if (!m_pAIScene) return false;
for (_uint i = 0; i < m_pAIScene->mNumMeshes; i++)
{
aiMesh* mesh = m_pAIScene->mMeshes[i];
saveMesh.MeshName = mesh->mName.C_Str();
saveMesh.MeshNameSize = (_int)saveMesh.MeshName.size() + 1;
saveMesh.VertexCount = mesh->mNumVertices;
saveMesh.IndexCount = mesh->mNumFaces * 3;
saveMesh.MaterialIndex = mesh->mMaterialIndex;
saveMesh.Vertices.resize(saveMesh.VertexCount);
for (_uint i = 0; i < mesh->mNumVertices; i++)
{
saveMesh.Vertices[i].Pos = XMFLOAT3{ mesh->mVertices[i].x , mesh->mVertices[i].y,mesh->mVertices[i].z };
if (mesh->HasNormals())
{
saveMesh.Vertices[i].Normal = XMFLOAT3{
mesh->mNormals[i].x,
mesh->mNormals[i].y,
mesh->mNormals[i].z
};
saveMesh.Vertices[i].bHasNormal = true;
}
else
{
saveMesh.Vertices[i].Normal = XMFLOAT3(0.f, 1.f, 0.f);
saveMesh.Vertices[i].bHasNormal = false;
}
if (mesh->HasTangentsAndBitangents())
{
saveMesh.Vertices[i].Tan = XMFLOAT3{
mesh->mTangents[i].x,
mesh->mTangents[i].y,
mesh->mTangents[i].z
};
saveMesh.Vertices[i].bHasTan = true;
}
else
{
saveMesh.Vertices[i].Tan = XMFLOAT3(1.f, 0.f, 0.f);
saveMesh.Vertices[i].bHasTan = false;
}
saveMesh.Vertices[i].BiNoraml = XMFLOAT3{
mesh->mBitangents[i].x,
mesh->mBitangents[i].y,
mesh->mBitangents[i].z
};
if (mesh->HasTextureCoords(0))
{
saveMesh.Vertices[i].UV = XMFLOAT2{
mesh->mTextureCoords[0][i].x,
mesh->mTextureCoords[0][i].y
};
saveMesh.Vertices[i].bHasUV = true;
}
else
{
saveMesh.Vertices[i].UV = XMFLOAT2(0.f, 0.f);
saveMesh.Vertices[i].bHasUV = false;
}
saveMesh.Vertices[i].BlendIndex = XMUINT4(0, 0, 0, 0);
saveMesh.Vertices[i].BlendWeight = XMFLOAT4(0.f, 0.f, 0.f, 0.f);
}
saveMesh.BoneCount = mesh->mNumBones;
saveMesh.Bones.resize(mesh->mNumBones);
for (size_t j = 0; j < mesh->mNumBones; j++)
{
saveMesh.Bones[j].BoneName = mesh->mBones[j]->mName.C_Str();
saveMesh.Bones[j].BoneNameSize = (_int)saveMesh.Bones[j].BoneName.size();
memcpy(&saveMesh.Bones[j].OffsetMatrix, &mesh->mBones[j]->mOffsetMatrix, sizeof(_float4x4));
XMStoreFloat4x4(&saveMesh.Bones[j].OffsetMatrix, XMMatrixTranspose(XMLoadFloat4x4(&saveMesh.Bones[j].OffsetMatrix)));
saveMesh.Bones[j].WeightsCount = mesh->mBones[j]->mNumWeights;
saveMesh.Bones[j].Weights.resize(mesh->mBones[j]->mNumWeights);
for (size_t k = 0; k < saveMesh.Bones[j].WeightsCount; k++)
{
saveMesh.Bones[j].Weights[k].VertexId = mesh->mBones[j]->mWeights[k].mVertexId;
saveMesh.Bones[j].Weights[k].Weight = mesh->mBones[j]->mWeights[k].mWeight;
}
}
saveMesh.Indices.reserve(saveMesh.IndexCount);
for (_uint i = 0; i < mesh->mNumFaces; i++)
{
aiFace& face = mesh->mFaces[i];
for (_uint idx = 0; idx < face.mNumIndices; idx++)
saveMesh.Indices.push_back(face.mIndices[idx]);
}
}
return true;
}
HRESULT CVIBuffer_Model_Instance::Initialize_Prototype(const INSTANCE_DESC* pDesc, const _char* pModelFilePath, const _char* pMatrialPath)
{
m_iNumBuffer = 2;
m_iMaxNumInstance = m_iNumInstance = pDesc->iNum;
if (FAILED(Assimp_Model_Load(pModelFilePath)))
return E_FAIL;
if (FAILED(Load_Material(pModelFilePath, pMatrialPath)))
return E_FAIL;
if(FAILED(Ready_Materials()))
return E_FAIL;
return S_OK;
}
void CVIBuffer_Model_Instance::Update_Instance()
{
m_iNumInstance = m_iCurrentNumInstance;
}
void CVIBuffer_Model_Instance::Add_Instance(_fmatrix WorldMatrix)
{
++m_iCurrentNumInstance;
if (m_iMaxNumInstance <= m_iCurrentNumInstance)
return;
D3D11_MAPPED_SUBRESOURCE SubResource{};
if (FAILED(m_pContext->Map(m_pVBInstance, 0, D3D11_MAP_WRITE_NO_OVERWRITE, 0, &SubResource)))
return;
VTX_INSTANCE_MODEL* pData = static_cast<VTX_INSTANCE_MODEL*>(SubResource.pData);
memcpy(&pData[m_iCurrentNumInstance - 1].vRight, &WorldMatrix.r[0], sizeof(_float4));
memcpy(&pData[m_iCurrentNumInstance - 1].vUp, &WorldMatrix.r[1], sizeof(_float4));
memcpy(&pData[m_iCurrentNumInstance - 1].vLook, &WorldMatrix.r[2], sizeof(_float4));
memcpy(&pData[m_iCurrentNumInstance - 1].vTranslation, &WorldMatrix.r[3], sizeof(_float4));
m_pContext->Unmap(m_pVBInstance, 0);
}
void CVIBuffer_Model_Instance::Delete_Instance()
{
if (0 != m_iCurrentNumInstance)
m_iCurrentNumInstance--;
return;
}
void CVIBuffer_Model_Instance::Fix_Instance(_fmatrix WorldMatrix)
{
if (0 == m_iCurrentNumInstance)
return;
D3D11_MAPPED_SUBRESOURCE SubResource{};
if (FAILED(m_pContext->Map(m_pVBInstance, 0, D3D11_MAP_WRITE_NO_OVERWRITE, 0, &SubResource)))
return;
VTX_INSTANCE_MODEL* pData = static_cast<VTX_INSTANCE_MODEL*>(SubResource.pData);
memcpy(&pData[m_iCurrentNumInstance - 1].vRight, &WorldMatrix.r[0], sizeof(_float4));
memcpy(&pData[m_iCurrentNumInstance - 1].vUp, &WorldMatrix.r[1], sizeof(_float4));
memcpy(&pData[m_iCurrentNumInstance - 1].vLook, &WorldMatrix.r[2], sizeof(_float4));
memcpy(&pData[m_iCurrentNumInstance - 1].vTranslation, &WorldMatrix.r[3], sizeof(_float4));
m_pContext->Unmap(m_pVBInstance, 0);
}
HRESULT CVIBuffer_Model_Instance::Assimp_Model_Load(const _char* pModelFilePath)
{
_uint iFlag = {};
iFlag = aiProcess_ConvertToLeftHanded | aiProcessPreset_TargetRealtime_Fast | aiProcess_PreTransformVertices;
Assimp::Importer Importer = {};
const aiScene* pAIScene = { nullptr };
pAIScene = Importer.ReadFile(pModelFilePath, iFlag);
if (nullptr == pAIScene) {
return E_FAIL;
}
m_iNumMeshes = pAIScene->mNumMeshes;
vector<class CBone*> bones;
for (_uint i = 0; i < m_iNumMeshes; ++i)
{
CMesh* pMesh = CMesh::Create(m_pDevice, m_pContext, MODEL::NONANIM, bones, pAIScene->mMeshes[i], XMMatrixIdentity());
if (nullptr == pMesh)
return E_FAIL;
m_Meshes.push_back(pMesh);
}
return S_OK;
}
CVIBuffer_Model_Instance* CVIBuffer_Model_Instance::Create(ID3D11Device* pDevice, ID3D11DeviceContext* pContext, const INSTANCE_DESC* pInstanceDesc, const _char* pModelFilePath, const _char* pMatrialPath)
{
CVIBuffer_Model_Instance* pInstance = new CVIBuffer_Model_Instance(pDevice, pContext);
if (FAILED(pInstance->Initialize_Prototype(pInstanceDesc, pModelFilePath, pMatrialPath)))
{
MSG_BOX("Failed to Created : CVIBuffer_Model_Instance");
SAFE_RELEASE(pInstance);
}
return pInstance;
}
HRESULT CVIBuffer_Model_Instance::Reay_Instance_Buffer_Editor()
{
m_iInstanceStride = sizeof(VTX_INSTANCE_MODEL);
D3D11_BUFFER_DESC InstanceBufferDesc = {};
InstanceBufferDesc.ByteWidth = m_iInstanceStride * m_iNumInstance;
InstanceBufferDesc.Usage = D3D11_USAGE_DYNAMIC;
InstanceBufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
InstanceBufferDesc.StructureByteStride = m_iInstanceStride;
InstanceBufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
InstanceBufferDesc.MiscFlags = 0;
if (FAILED(m_pDevice->CreateBuffer(&InstanceBufferDesc, nullptr, &m_pVBInstance)))
return E_FAIL;
return S_OK;
}
HRESULT CVIBuffer_Model_Instance::Load_InstanceData_Editor()
{
if (FAILED(Reay_Instance_Buffer_Editor()))
return E_FAIL;
return S_OK;
}
HRESULT CVIBuffer_Model_Instance::Load_Material(const _char* pModelFilePath, const _char* pMatrialPath)
{
tinyxml2::XMLDocument xmlDoc;
if ((tinyxml2::XML_SUCCESS != xmlDoc.LoadFile(pMatrialPath)))
return E_FAIL;
tinyxml2::XMLElement* root = xmlDoc.FirstChildElement("Instance");
_char szName[MAX_PATH] = {};
_splitpath_s(pModelFilePath, nullptr, 0, nullptr, 0, szName, MAX_PATH, nullptr, 0);
tinyxml2::XMLElement* Model = root->FirstChildElement(szName);
/* Check Mesh Num */
_uint iNumMesh = {};
Model->QueryUnsignedAttribute("mesh", &iNumMesh);
if (iNumMesh != m_iNumMeshes)
return E_FAIL;
for (auto* Mesh = Model->FirstChildElement("Mesh"); Mesh; Mesh = Mesh->NextSiblingElement("Mesh"))
{
vector<string> MaterialPathes = {};
for (auto* Material = Mesh->FirstChildElement("Material"); Material; Material = Material->NextSiblingElement("Material"))
{
MaterialPathes.push_back("../Bin/Resources/Models/InstanceProp/Textures/" + string(Material->GetText()) + ".dds");
}
m_MeshMaterialPathes.push_back(MaterialPathes);
auto* Surface = Mesh->FirstChildElement("Surface");
string strSurface = Surface->GetText();
if (string::npos != strSurface.find("SRO"))
m_SurfaceMaterialFlag.push_back(aiTextureType_SPECULAR);
else
m_SurfaceMaterialFlag.push_back(aiTextureType_METALNESS);
}
return S_OK;
}
#endif
CVIBuffer_Model_Instance* CVIBuffer_Model_Instance::Create(ID3D11Device* pDevice, ID3D11DeviceContext* pContext, const _char* pFileName)
{
CVIBuffer_Model_Instance* pInstance = new CVIBuffer_Model_Instance(pDevice, pContext);
if (FAILED(pInstance->Initialize_Prototype(pFileName)))
{
MSG_BOX("Failed to Created : CVIBuffer_Model_Instance");
SAFE_RELEASE(pInstance);
}
return pInstance;
}
CComponent* CVIBuffer_Model_Instance::Clone(void* pArg, CGameObject* pOwner)
{
CVIBuffer_Model_Instance* pInstance = new CVIBuffer_Model_Instance(*this);
pInstance->m_pOwner = pOwner;
if (FAILED(pInstance->Initialize(pArg)))
{
MSG_BOX("Failed to Cloned : CVIBuffer_Model_Instance");
SAFE_RELEASE(pInstance);
}
return pInstance;
}
void CVIBuffer_Model_Instance::Free()
{
__super::Free();
for (auto& pMesh : m_Meshes)
SAFE_RELEASE(pMesh);
m_Meshes.clear();
for (auto& Materials : m_MeshMaterialsSRV)
{
for(auto& pSRV : Materials)
SAFE_RELEASE(pSRV);
Materials.clear();
}
m_MeshMaterialsSRV.clear();
for (auto& Pathes : m_MeshMaterialPathes)
Pathes.clear();
m_MeshMaterialPathes.clear();
m_SurfaceMaterialFlag.clear();
}
void CVIBuffer_Model_Instance::Describe_Entity()
{
GUI::Text("Instance Count : %d / %d", m_iCurrentNumInstance, m_iMaxNumInstance);
}
+1 -1
View File
@@ -99,7 +99,7 @@ constexpr unsigned int g_iMaxShadowHeight = 9216;
#define KR_CSTR(str) reinterpret_cast<const char*>(u8##str)
#ifndef MSG_BOX
#define MSG_BOX(_message) MessageBox(NULL, TEXT(_message), L"System Message", MB_OK); assert(false)
#define MSG_BOX(_message) MessageBox(NULL, TEXT(_message), L"System Message", MB_OK)
#endif
#define NS_BEGIN(NAMESPACE) namespace NAMESPACE {
@@ -178,6 +178,14 @@ struct SaveModel
#pragma region VTX
typedef struct tagVertexInstance_Model
{
_float4 vRight = {};
_float4 vUp = {};
_float4 vLook = {};
_float4 vTranslation = {};
}VTX_INSTANCE_MODEL;
typedef struct tagVertexInstance_Particle
{
_float4 vRight = {};
@@ -320,6 +328,23 @@ typedef struct tagVertexModelInstanceParticleDesc
};
}VTX_MODEL_INSTANCE_PARTICLE;
typedef struct tagVertexModelInstanceModelDesc
{
static constexpr _uint iNumElements = { 9 };
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},
{ "TANGENT" , 0 , DXGI_FORMAT_R32G32B32_FLOAT , 0, 24, D3D11_INPUT_PER_VERTEX_DATA, 0},
{ "BINORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 36, D3D11_INPUT_PER_VERTEX_DATA, 0},
{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 48, D3D11_INPUT_PER_VERTEX_DATA, 0},
{ "TEXCOORD", 1, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, 0, D3D11_INPUT_PER_INSTANCE_DATA, 1 },
{ "TEXCOORD", 2, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, 16, D3D11_INPUT_PER_INSTANCE_DATA, 1 },
{ "TEXCOORD", 3, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, 32, D3D11_INPUT_PER_INSTANCE_DATA, 1 },
{ "TEXCOORD", 4, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, 48, D3D11_INPUT_PER_INSTANCE_DATA, 1 }
};
}VTX_MODEL_INSTANCE_MODEL;
#pragma endregion
typedef struct tagVertexInstance_UIDesc
@@ -13,7 +13,7 @@ class ENGINE_DLL CVIBuffer_Instance abstract : public CVIBuffer
_float2 vSize = {};
_float fPositionOffSetX{};
_float fPositionOffSetY{};
_float2 vPsition = {};
_float2 vPosition = {};
}INSTANCE_DESC;
protected:
CVIBuffer_Instance(ID3D11Device* pDevice, ID3D11DeviceContext* pContext);
@@ -27,7 +27,7 @@ class ENGINE_DLL CVIBuffer_Instance abstract : public CVIBuffer
virtual HRESULT Render() override;
protected:
ID3D11Buffer* m_pVBInstance = { nullptr };
ID3D11Buffer* m_pVBInstance = { nullptr };
D3D11_BUFFER_DESC m_InstanceBufferDesc = {};
D3D11_SUBRESOURCE_DATA m_InstanceInitialDesc = {};
_uint m_iInstanceStride = {};
@@ -0,0 +1,77 @@
#pragma once
#include "VIBuffer_Instance.h"
NS_BEGIN(Engine)
class ENGINE_DLL CVIBuffer_Model_Instance final : public CVIBuffer_Instance
{
private:
CVIBuffer_Model_Instance(ID3D11Device* pDevice, ID3D11DeviceContext* pContext);
CVIBuffer_Model_Instance(const CVIBuffer_Model_Instance& rhs);
virtual ~CVIBuffer_Model_Instance() = default;
public:
_uint Get_NumMesh() const { return m_iNumMeshes; }
public:
virtual HRESULT Initialize_Prototype(const _char* pModelFilePath);
virtual HRESULT Initialize(void* pArg) override;
virtual HRESULT Render(_uint iMeshIndex);
HRESULT Bind_Matrial(class CShader* pShader, _uint iMeshIndex);
HRESULT Load_WorldData(vector<_float4x4>& WorldMatrices);
private:
_uint m_iNumBuffer = {};
_uint m_iNumMeshes = {};
INSTANCE_DESC m_InstanceDesc = {};
vector<class CMesh*> m_Meshes = {};
vector<vector<ID3D11ShaderResourceView*>> m_MeshMaterialsSRV = {};
vector<aiTextureType> m_SurfaceMaterialFlag = {};
vector<vector<string>> m_MeshMaterialPathes = {};
private:
HRESULT Reay_Instance_Buffer();
HRESULT Load_InstanceData(ifstream& in);
HRESULT Ready_Materials();
#ifdef EDITOR_PROJECT
public:
void Update_Instance();
void Add_Instance(_fmatrix WorldMatrix);
void Delete_Instance();
void Fix_Instance(_fmatrix WorldMatrix);
virtual HRESULT Initialize_Prototype(const INSTANCE_DESC* pDesc, const _char* pFileName, const _char* pMatrialPath);
HRESULT Assimp_Model_Load(const _char* pModelFilePath);
HRESULT Save_InstanceData(_char* pFileName);
_bool SaveAssimpModel(SaveMesh& saveMesh);
HRESULT Reay_Instance_Buffer_Editor();
HRESULT Load_InstanceData_Editor();
HRESULT Load_Material(const _char* pModelFilePath, const _char* pMatrialPath);
public:
static CVIBuffer_Model_Instance* Create(ID3D11Device* pDevice, ID3D11DeviceContext* pContext, const INSTANCE_DESC* pInstanceDesc, const _char* pModelFilePath, const _char* pMatrialPath);
const aiScene* m_pAIScene = { nullptr };
Assimp::Importer m_Importer;
_uint m_iCurrentNumInstance = {};
_uint m_iMaxNumInstance = {};
#endif
public:
static CVIBuffer_Model_Instance* Create(ID3D11Device* pDevice, ID3D11DeviceContext* pContext, const _char* pFileName);
virtual CComponent* Clone(void* pArg, class CGameObject* pOwner = nullptr) override;
virtual void Free() override;
#ifdef _DEBUG
virtual void Describe_Entity() override;
#endif
};
NS_END