Merge pull request #221 from SpicyGangjeong/MapTool

Map tool
This commit is contained in:
JinhoBa
2025-11-26 11:14:12 +09:00
committed by GitHub
11 changed files with 253 additions and 285 deletions
@@ -18,23 +18,27 @@ void CInstancedProp::Priority_Update(_float fTimeDelta)
void CInstancedProp::Update(_float fTimeDelta)
{
if (m_pGameInstance->Mouse_Down(DIM_MBUTTON))
if(m_bEditMode)
{
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))
if (m_pGameInstance->Mouse_Down(DIM_MBUTTON))
{
memcpy(&m_vPosition, &vPosition, sizeof(_float3));
}
}
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);
Describe_Entity();
_float3 vPosition = {};
if (m_pGameInstance->isPicking(&vPosition))
{
memcpy(&m_vPosition, &vPosition, sizeof(_float3));
}
}
#ifdef _DEBUG
Describe_Entity();
#endif
}
}
void CInstancedProp::Late_Update(_float fTimeDelta)
@@ -59,7 +63,6 @@ HRESULT CInstancedProp::Render()
m_pVIBufferInstanceCom->Render(i);
}
return S_OK;
}
@@ -71,9 +74,14 @@ HRESULT CInstancedProp::Initialize_Prototype()
HRESULT CInstancedProp::Initialize(void* pArg)
{
INSTANCE_PROP_DESC* pDesc = static_cast<INSTANCE_PROP_DESC*>(pArg);
if (FAILED(__super::Initialize(pArg)))
return E_FAIL;
m_bEditMode = pDesc->bEditMode;
m_strPrototypeTag = pDesc->strPrototypeTag;
if (FAILED(Ready_Components(pArg)))
return E_FAIL;
@@ -83,6 +91,9 @@ HRESULT CInstancedProp::Initialize(void* pArg)
XMStoreFloat4x4(&m_WorldMatrixIdentity, XMMatrixIdentity());
if(!m_bEditMode)
Load_InstancedProp(pDesc->strInstanceDataPath.c_str());
return S_OK;
}
@@ -92,7 +103,7 @@ HRESULT CInstancedProp::Ready_Components(void* pArg)
return E_FAIL;
/* Com_VIBuffer_Instance_Model */
if (FAILED(__super::Add_Asset_Component(g_iStaticLevel, TEXT("Prototype_Component_VIBuffer_Model_Instancel"),
if (FAILED(__super::Add_Asset_Component(g_iStaticLevel, m_strPrototypeTag,
reinterpret_cast<CComponent**>(&m_pVIBufferInstanceCom))))
return E_FAIL;
@@ -101,26 +112,6 @@ HRESULT CInstancedProp::Ready_Components(void* pArg)
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;
}
@@ -246,18 +237,14 @@ void CInstancedProp::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");
#ifdef _DEBUG
m_pVIBufferInstanceCom->Describe_Entity();
#endif // _DEBUG
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);
@@ -307,6 +294,7 @@ void CInstancedProp::Describe_Entity()
{
Load_InstancedProp(("../Bin/Resources/Data/Map/Instance/" + string(m_szFileName) + ".bin").c_str());
}
GUI::End();
}
@@ -47,6 +47,10 @@ HRESULT CLevel_MapViewer::Initialize()
return E_FAIL;
}
if (FAILED(Ready_Layer_InstanceProp(TEXT("Layer_InstanceProp")))) {
return E_FAIL;
}
if (FAILED(Ready_Layer_BuildingContainer(TEXT("Layer_Building")))) {
return E_FAIL;
}
@@ -113,6 +117,20 @@ HRESULT CLevel_MapViewer::Ready_Layer_Terrain(const _wstring& strLayerTag)
return S_OK;
}
HRESULT CLevel_MapViewer::Ready_Layer_InstanceProp(const _wstring& strLayerTag)
{
CInstancedProp::INSTANCE_PROP_DESC Desc = {};
Desc.bEditMode = false;
Desc.strPrototypeTag = L"Prototype_Component_VIBuffer_Model_Instancel_SM_OakTree_MedA";
Desc.strInstanceDataPath = "../Bin/Resources/Data/Map/Instance/OakTree_MedA.bin";
/* Oak_Tree */
if (FAILED(m_pGameInstance->Add_GameObject_ToLayer<CInstancedProp>(g_iStaticLevel, NEXT_LEVEL, strLayerTag, &Desc)))
return E_FAIL;
return S_OK;
}
HRESULT CLevel_MapViewer::Ready_Layer_BuildingContainer(const _wstring& strLayerTag)
{
//if (FAILED(m_pGameInstance->Add_GameObject_ToLayer<CBuildingContainer>(g_iStaticLevel, NEXT_LEVEL, strLayerTag)))
@@ -126,8 +144,7 @@ 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;
}
+10 -13
View File
@@ -1568,20 +1568,11 @@ HRESULT CLoader::Loading_For_MapViewer()
{
m_strMessage = TEXT("텍스쳐를(을) 로딩 중 입니다.");
//if (FAILED(m_pGameInstance->Add_Asset_Prototype(g_iStaticLevel, TEXT("TerrainTest"),
// CTexture::Create(m_pDevice, m_pContext, TEXTURE_LOAD_TYPE::SINGLE, TEXT("../Bin/Resources/Textures/T_C_Dun_Moss_D.png"), 0)))) {
// return E_FAIL;
//}
if (FAILED(m_pGameInstance->Add_Asset_Prototype(g_iStaticLevel, TEXT("TerrainTest"),
CTexture::Create(m_pDevice, m_pContext, TEXTURE_LOAD_TYPE::SINGLE, TEXT("../Bin/Resources/Textures//T_LandscapeStreamingProxy_0_LOD1_Summer_D.png"), 0)))) {
return E_FAIL;
}
/* Terrain_Mask */
if (FAILED(m_pGameInstance->Add_Asset_Prototype(g_iStaticLevel, TEXT("Terrain_Mask"),
CTexture::Create(m_pDevice, m_pContext, TEXTURE_LOAD_TYPE::SINGLE, TEXT("../Bin/Resources/Data/Map/T_OL_GrassBlend_Mask_D.dds"), 0)))) {
@@ -2151,10 +2142,16 @@ vector<vector<FOLDER_LOAD*>*> Contents(iLoadCount);
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"))))
///* 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/SM_OakTree_MedA.fbx", "../Bin/Resources/Data/Map/Instance/InstanceMaterial.xml"))))
// return E_FAIL;
/* For.Prototype_Component_VIBuffer_Model_Instancel_SM_OakTree_MedA */
if (FAILED(m_pGameInstance->Add_Asset_Prototype(g_iStaticLevel, TEXT("Prototype_Component_VIBuffer_Model_Instancel_SM_OakTree_MedA"),
CVIBuffer_Model_Instance::Create(m_pDevice, m_pContext,
"../Bin/Resources/Models/InstanceProp/SM_OakTree_MedA.bin", "../Bin/Resources/Data/Map/Instance/InstanceMaterial.xml"))))
return E_FAIL;
/* For.Prototype_GameObject_SkyBox */
+11 -6
View File
@@ -16,8 +16,9 @@ class CInstancedProp final : public CGameObject
public:
typedef struct tagInstancedPropDesc
{
string strModelFilePath;
string strTextureFilePath;
_bool bEditMode{};
_wstring strPrototypeTag;
string strInstanceDataPath;
}INSTANCE_PROP_DESC;
private:
CInstancedProp(ID3D11Device* pDevice, ID3D11DeviceContext* pContext);
@@ -31,17 +32,20 @@ class CInstancedProp final : public CGameObject
virtual HRESULT Render() override;
private:
_bool m_bEditMode = {};
CVIBuffer_Model_Instance* m_pVIBufferInstanceCom = { nullptr };
CShader* m_pShaderCom = { nullptr };
vector<CTexture*> m_pTextures = {};
vector<_float4x4> m_WorldMatrices = {};
_float4x4 m_WorldMatrixIdentity = {};
_wstring m_strPrototypeTag;
_float4 m_vPosition = {};
_float3 m_vRotation = {};
_float3 m_vScale = {};
#ifdef _DEBUG
_char m_szFileName[MAX_PATH] = {};
_float4 m_vPosition = {};
_float3 m_vRotation = {};
_float3 m_vScale = {};
#endif // _DEBUG
@@ -63,6 +67,7 @@ class CInstancedProp final : public CGameObject
virtual CGameObject* Clone(void* pArg, class CGameObject* pOwner) override;
virtual void Free() override;
void Describe_Entity() override;
};
NS_END
@@ -1,4 +1,4 @@
#pragma once
#pragma once
#include "Editor_Define.h"
#include "Level.h"
@@ -21,6 +21,7 @@ class CLevel_MapViewer final : public CLevel
HRESULT Ready_Layer_Camera(const _wstring& strLayerTag);
HRESULT Ready_Layer_Background(const _wstring& strLayerTag);
HRESULT Ready_Layer_Terrain(const _wstring& strLayerTag);
HRESULT Ready_Layer_InstanceProp(const _wstring& strLayerTag);
HRESULT Ready_Layer_BuildingContainer(const _wstring& strLayerTag);
HRESULT Ready_Layer_MapObjectManager(const _wstring& strLayerTag);
@@ -31,4 +32,4 @@ class CLevel_MapViewer final : public CLevel
virtual void Free() override;
};
NS_END
NS_END
@@ -28,6 +28,7 @@ CInstance_Model::CInstance_Model(const CInstance_Model& rhs)
SAFE_ADDREF(m_pVBInstance);
}
HRESULT CInstance_Model::Initialize_Prototype(const _char* pModelFilePath, MODEL eType, _fmatrix& PreTransformMatrix, _uint iRootBoneIndex)
{
if (FAILED(__super::Initialize_Prototype()))
@@ -50,6 +51,7 @@ HRESULT CInstance_Model::Initialize_Prototype(const _char* pModelFilePath, MODEL
{
LoadData(pModelFilePath);
}
#ifdef EDITOR_PROJECT
else if (strcmp(".fbx", szEXT) == 0)
{
_char Temp[256];
@@ -64,7 +66,7 @@ HRESULT CInstance_Model::Initialize_Prototype(const _char* pModelFilePath, MODEL
SaveAssimpModel(Temp , m_pAIScene);
return S_OK;
}
#endif
#pragma region Mesh
if (FAILED(Ready_Meshes())) {
return E_FAIL;
@@ -74,7 +76,7 @@ HRESULT CInstance_Model::Initialize_Prototype(const _char* pModelFilePath, MODEL
return S_OK;
}
#ifdef EDITOR_PROJECT
HRESULT CInstance_Model::Assimp_Model_Load(const _char* pModelFilePath, MODEL eType, _fmatrix& PreTransformMatrix, _uint iRootBoneIndex)
{
_uint iFlag = {};
@@ -104,7 +106,6 @@ HRESULT CInstance_Model::Assimp_Model_Load(const _char* pModelFilePath, MODEL eT
#pragma endregion
}
#ifdef EDITOR_PROJECT
HRESULT CInstance_Model::Ready_Meshes(MODEL eType, const aiScene* pAIScene, _fmatrix& PreTransformMatrix)
{
XMStoreFloat4x4(&m_PreTransformMatrix, PreTransformMatrix);
@@ -37,56 +37,23 @@ CVIBuffer_Model_Instance::CVIBuffer_Model_Instance(const CVIBuffer_Model_Instanc
}
}
HRESULT CVIBuffer_Model_Instance::Initialize_Prototype(const _char* pFileName)
HRESULT CVIBuffer_Model_Instance::Initialize_Prototype(const _char* pModelFilePath, const _char* pMatrialPath)
{
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)))
if (FAILED(Load_ModelData(pModelFilePath)))
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 (FAILED(Load_Material(pModelFilePath, pMatrialPath)))
return E_FAIL;
if (nullptr == pMesh)
return E_FAIL;
m_Meshes.push_back(pMesh);
}
in.close();
if (FAILED(Ready_Materials()))
return E_FAIL;
return S_OK;
}
HRESULT CVIBuffer_Model_Instance::Initialize(void* pArg)
{
if (FAILED(Load_InstanceData_Editor()))
if (FAILED(Reay_Instance_Buffer()))
return E_FAIL;
return S_OK;
@@ -150,8 +117,6 @@ HRESULT CVIBuffer_Model_Instance::Load_WorldData(vector<_float4x4>& WorldMatrice
HRESULT CVIBuffer_Model_Instance::Reay_Instance_Buffer()
{
m_iNumInstance = m_InstanceDesc.iNum;
m_iInstanceStride = sizeof(VTX_INSTANCE_MODEL);
D3D11_BUFFER_DESC InstanceBufferDesc = {};
@@ -198,6 +163,102 @@ HRESULT CVIBuffer_Model_Instance::Load_InstanceData(ifstream& in)
return S_OK;
}
HRESULT CVIBuffer_Model_Instance::Load_ModelData(const _char* pModelFilePath)
{
ifstream In(pModelFilePath, ios::binary);
if (!In.is_open())
{
MSG_BOX("Failed to Load : Model Data");
return E_FAIL;
}
In.read(reinterpret_cast<_char*>(&m_iNumMeshes), sizeof(_uint));
for (_uint i = 0; i < m_iNumMeshes; ++i)
{
SaveMesh mesh{};
In.read(reinterpret_cast<_char*>(&mesh.MeshNameSize), sizeof(_uint));
mesh.MeshName.resize(mesh.MeshNameSize);
In.read(reinterpret_cast<_char*>(mesh.MeshName.data()), mesh.MeshNameSize);
In.read(reinterpret_cast<_char*>(&mesh.VertexCount), sizeof(_uint));
In.read(reinterpret_cast<_char*>(&mesh.IndexCount), sizeof(_uint));
In.read(reinterpret_cast<_char*>(&mesh.MaterialIndex), sizeof(_uint));
In.read(reinterpret_cast<_char*>(&mesh.BoneCount), sizeof(_uint));
mesh.Vertices.resize(mesh.VertexCount);
In.read(reinterpret_cast<_char*>(mesh.Vertices.data()), sizeof(SaveVertex) * mesh.VertexCount);
mesh.Indices.resize(mesh.IndexCount);
In.read(reinterpret_cast<_char*>(mesh.Indices.data()), sizeof(_uint) * mesh.IndexCount);
CModel* pModel = { nullptr };
CMesh* pMesh = CMesh::Create(m_pDevice, m_pContext, MODEL::NONANIM, pModel, &mesh, XMMatrixIdentity());
if (nullptr == pMesh)
return E_FAIL;
m_Meshes.push_back(pMesh);
}
In.read(reinterpret_cast<_char*>(&m_iNumInstance), sizeof(_uint));
m_iMaxNumInstance = m_iNumInstance;
In.close();
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;
}
HRESULT CVIBuffer_Model_Instance::Ready_Materials()
{
for (_uint i = 0; i < m_iNumMeshes; ++i)
@@ -222,70 +283,15 @@ HRESULT CVIBuffer_Model_Instance::Ready_Materials()
}
#ifdef EDITOR_PROJECT
HRESULT CVIBuffer_Model_Instance::Save_InstanceData(_char* pFileName)
HRESULT CVIBuffer_Model_Instance::SaveAssimpModel(const _char* pModelFilePath)
{
#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;
if (!m_pAIScene) return E_FAIL;
for (_uint i = 0; i < m_pAIScene->mNumMeshes; i++)
{
SaveMesh saveMesh{};
aiMesh* mesh = m_pAIScene->mMeshes[i];
saveMesh.MeshName = mesh->mName.C_Str();
@@ -351,23 +357,6 @@ _bool CVIBuffer_Model_Instance::SaveAssimpModel(SaveMesh& saveMesh)
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++)
@@ -376,9 +365,45 @@ _bool CVIBuffer_Model_Instance::SaveAssimpModel(SaveMesh& saveMesh)
for (_uint idx = 0; idx < face.mNumIndices; idx++)
saveMesh.Indices.push_back(face.mIndices[idx]);
}
m_SaveMeshDesc.push_back(saveMesh);
}
return true;
#pragma region SAVE_MESH
filesystem::path ModelPath = pModelFilePath;
string pFileName = ModelPath.parent_path().string() + "/" + ModelPath.stem().string() + ".bin";
ofstream out(pFileName, ios::binary);
if (!out.is_open())
{
MSG_BOX("Failed to Save : Instance Data");
return E_FAIL;
}
out.write(reinterpret_cast<_char*>(&m_iNumMeshes), sizeof(_uint));
for (auto& mesh : m_SaveMeshDesc)
{
out.write(reinterpret_cast<_char*>(&mesh.MeshNameSize), sizeof(_uint));
out.write(reinterpret_cast<_char*>(mesh.MeshName.data()), mesh.MeshNameSize);
out.write(reinterpret_cast<_char*>(&mesh.VertexCount), sizeof(_uint));
out.write(reinterpret_cast<_char*>(&mesh.IndexCount), sizeof(_uint));
out.write(reinterpret_cast<_char*>(&mesh.MaterialIndex), sizeof(_uint));
out.write(reinterpret_cast<_char*>(&mesh.BoneCount), sizeof(_uint));
out.write(reinterpret_cast<_char*>(mesh.Vertices.data()), sizeof(SaveVertex) * mesh.VertexCount);
out.write(reinterpret_cast<_char*>(mesh.Indices.data()), sizeof(_uint) * mesh.IndexCount);
}
out.write(reinterpret_cast<_char*>(&m_iMaxNumInstance), sizeof(_uint));
#pragma endregion
out.close();
return S_OK;
}
HRESULT CVIBuffer_Model_Instance::Initialize_Prototype(const INSTANCE_DESC* pDesc, const _char* pModelFilePath, const _char* pMatrialPath)
@@ -395,6 +420,8 @@ HRESULT CVIBuffer_Model_Instance::Initialize_Prototype(const INSTANCE_DESC* pDes
if(FAILED(Ready_Materials()))
return E_FAIL;
return S_OK;
}
@@ -459,21 +486,18 @@ 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) {
m_pAIScene = m_Importer.ReadFile(pModelFilePath, iFlag);
if (nullptr == m_pAIScene) {
return E_FAIL;
}
m_iNumMeshes = pAIScene->mNumMeshes;
m_iNumMeshes = m_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());
CMesh* pMesh = CMesh::Create(m_pDevice, m_pContext, MODEL::NONANIM, bones, m_pAIScene->mMeshes[i], XMMatrixIdentity());
if (nullptr == pMesh)
return E_FAIL;
@@ -481,6 +505,9 @@ HRESULT CVIBuffer_Model_Instance::Assimp_Model_Load(const _char* pModelFilePath)
m_Meshes.push_back(pMesh);
}
if (FAILED(SaveAssimpModel(pModelFilePath)))
return E_FAIL;
return S_OK;
}
@@ -498,82 +525,13 @@ CVIBuffer_Model_Instance* CVIBuffer_Model_Instance::Create(ID3D11Device* pDevice
}
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* CVIBuffer_Model_Instance::Create(ID3D11Device* pDevice, ID3D11DeviceContext* pContext, const _char* pModelFilePath, const _char* pMatrialPath)
{
CVIBuffer_Model_Instance* pInstance = new CVIBuffer_Model_Instance(pDevice, pContext);
if (FAILED(pInstance->Initialize_Prototype(pFileName)))
if (FAILED(pInstance->Initialize_Prototype(pModelFilePath, pMatrialPath)))
{
MSG_BOX("Failed to Created : CVIBuffer_Model_Instance");
SAFE_RELEASE(pInstance);
@@ -617,8 +575,9 @@ void CVIBuffer_Model_Instance::Free()
m_SurfaceMaterialFlag.clear();
}
#ifdef _DEBUG
void CVIBuffer_Model_Instance::Describe_Entity()
{
GUI::Text("Instance Count : %d / %d", m_iCurrentNumInstance, m_iMaxNumInstance);
}
#endif
@@ -14,20 +14,22 @@ class ENGINE_DLL CVIBuffer_Model_Instance final : public CVIBuffer_Instance
_uint Get_NumMesh() const { return m_iNumMeshes; }
public:
virtual HRESULT Initialize_Prototype(const _char* pModelFilePath);
virtual HRESULT Initialize_Prototype(const _char* pModelFilePath, const _char* pMatrialPath);
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 = {};
_uint m_iNumBuffer = {};
_uint m_iNumMeshes = {};
_uint m_iCurrentNumInstance = {};
_uint m_iMaxNumInstance = {};
INSTANCE_DESC m_InstanceDesc = {};
INSTANCE_DESC m_InstanceDesc = {};
vector<class CMesh*> m_Meshes = {};
vector<class CMesh*> m_Meshes = {};
vector<vector<ID3D11ShaderResourceView*>> m_MeshMaterialsSRV = {};
vector<aiTextureType> m_SurfaceMaterialFlag = {};
@@ -36,6 +38,8 @@ class ENGINE_DLL CVIBuffer_Model_Instance final : public CVIBuffer_Instance
private:
HRESULT Reay_Instance_Buffer();
HRESULT Load_InstanceData(ifstream& in);
HRESULT Load_ModelData(const _char* pModelFilePath);
HRESULT Load_Material(const _char* pModelFilePath, const _char* pMatrialPath);
HRESULT Ready_Materials();
#ifdef EDITOR_PROJECT
@@ -47,25 +51,18 @@ class ENGINE_DLL CVIBuffer_Model_Instance final : public CVIBuffer_Instance
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);
HRESULT SaveAssimpModel(const _char* pModelFilePath);
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 = {};
vector<SaveMesh> m_SaveMeshDesc = {};
#endif
public:
static CVIBuffer_Model_Instance* Create(ID3D11Device* pDevice, ID3D11DeviceContext* pContext, const _char* pFileName);
static CVIBuffer_Model_Instance* Create(ID3D11Device* pDevice, ID3D11DeviceContext* pContext, const _char* pModelFilePath, const _char* pMatrialPath);
virtual CComponent* Clone(void* pArg, class CGameObject* pOwner = nullptr) override;
virtual void Free() override;
#ifdef _DEBUG