[add] 스테틱 메시 피직스 띄움
This commit is contained in:
Binary file not shown.
Binary file not shown.
File diff suppressed because one or more lines are too long
@@ -24,6 +24,7 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
|
||||
//_CrtSetBreakAlloc(1157440);
|
||||
#endif
|
||||
UNREFERENCED_PARAMETER(hPrevInstance);
|
||||
UNREFERENCED_PARAMETER(lpCmdLine);
|
||||
|
||||
@@ -89,17 +89,16 @@ HRESULT CDummy_PhysXMesh::Ready_Components(void* pArg)
|
||||
m_pTransformCom->Rotation(pBox->vRotRPY.x, pBox->vRotRPY.y, pBox->vRotRPY.z);
|
||||
|
||||
|
||||
CModel* pModel = (CModel*)m_pGameInstance->Find_Asset_Prototype(g_iStaticLevel, TEXT("Prototype_Component_River_Col_Model"));
|
||||
_uint iNumMesh = pModel->Get_NumMeshes();
|
||||
|
||||
CRigidBody::RIGIDBODY_DESC Desc{};
|
||||
Desc.eType = ACTOR::TRIANGLEMESH;
|
||||
for (_uint i = 0; i< iNumMesh; ++i)
|
||||
{ // RIGID_BODY
|
||||
CRigidBody::RIGIDBODY_DESC Desc{};
|
||||
Desc.tRigidStaticDesc.pMeshKey = TEXT("PhysX_Plane");
|
||||
Desc.tRigidStaticDesc.szMeshName = pModel->Get_MeshName(i);
|
||||
|
||||
if (FAILED(Add_Asset_Component(g_iStaticLevel, TEXT("PHYSX_Static_Object"), (CComponent**)&m_pRigidBody, &Desc))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
m_pActor = m_pGameInstance->Add_StaticActor(*m_pRigidBody);
|
||||
if (nullptr == m_pActor) {
|
||||
assert(false);
|
||||
if (FAILED(Add_Asset_Component(g_iStaticLevel, CMyTools::ToWstring(pModel->Get_MeshName(i)).c_str(), nullptr, &Desc))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
}
|
||||
@@ -155,7 +154,6 @@ void CDummy_PhysXMesh::Free()
|
||||
{
|
||||
__super::Free();
|
||||
|
||||
SAFE_RELEASE(m_pRigidBody);
|
||||
//SAFE_RELEASE(m_pModelCom);
|
||||
//SAFE_RELEASE(m_pShaderCom);
|
||||
}
|
||||
|
||||
@@ -130,6 +130,8 @@ CGameObject* CDummy_PhysXPlayable::Clone(void* pArg, CGameObject* pOwner)
|
||||
void CDummy_PhysXPlayable::Free()
|
||||
{
|
||||
__super::Free();
|
||||
|
||||
SAFE_RELEASE(m_pCharacter_Controller);
|
||||
}
|
||||
|
||||
void CDummy_PhysXPlayable::Describe_Entity()
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "Terrain.h"
|
||||
#include "Dummy_PhysXBox.h"
|
||||
#include "Dummy_PhysXPlayable.h"
|
||||
#include "Dummy_PhysXMesh.h"
|
||||
|
||||
CLevel_PhysXLab::CLevel_PhysXLab(ID3D11Device* pDevice, ID3D11DeviceContext* pContext, LEVEL eLevelID)
|
||||
: CLevel{ pDevice, pContext, ENUM_CLASS(eLevelID) }
|
||||
@@ -99,13 +100,23 @@ HRESULT CLevel_PhysXLab::Ready_Layer_PhysXObjects(const _wstring& strLayerTag)
|
||||
}
|
||||
}
|
||||
|
||||
CDummy_PhysXPlayable::BOXSTARTPOS_DESC Desc{};
|
||||
Desc.vPos = { 0.f, 10.f, 0.f };
|
||||
Desc.vRotRPY = { 0.f, 0.f, 0.f };
|
||||
if (FAILED(m_pGameInstance->Add_GameObject_ToLayer<CDummy_PhysXPlayable>(g_iStaticLevel, NEXT_LEVEL, LAYER_PLAYER, &Desc))) {
|
||||
return E_FAIL;
|
||||
{
|
||||
CDummy_PhysXPlayable::BOXSTARTPOS_DESC Desc{};
|
||||
Desc.vPos = { 0.f, 10.f, 0.f };
|
||||
Desc.vRotRPY = { 0.f, 0.f, 0.f };
|
||||
if (FAILED(m_pGameInstance->Add_GameObject_ToLayer<CDummy_PhysXPlayable>(g_iStaticLevel, NEXT_LEVEL, LAYER_PLAYER, &Desc))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
CDummy_PhysXMesh::BOXSTARTPOS_DESC Desc{};
|
||||
Desc.vPos = { 0.f, 10.f, 0.f };
|
||||
Desc.vRotRPY = { 0.f, 0.f, 0.f };
|
||||
if (FAILED(m_pGameInstance->Add_GameObject_ToLayer<CDummy_PhysXMesh>(g_iStaticLevel, NEXT_LEVEL, LAYER_CHUNK, &Desc))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -491,13 +491,26 @@ HRESULT CLoader::Loading_For_PhysXLevel()
|
||||
m_pGameInstance->Add_Asset_Prototype(g_iStaticLevel, TEXT("PHYSX_DYNAMIC_BOX"), CRigidBody::Create(m_pDevice, m_pContext, Desc));
|
||||
}
|
||||
|
||||
|
||||
if (FAILED(m_pGameInstance->Add_Asset_Prototype(g_iStaticLevel, TEXT("Prototype_Component_River_Col_Model"),
|
||||
//CModel::Create(m_pDevice, m_pContext, MODEL::ENVIROMENT, "../Bin/Resources/Models/River/River.fbx", XMMatrixScaling(0.001f, 0.001f, 0.001f) * XMMatrixIdentity())))){
|
||||
CModel::Create(m_pDevice, m_pContext, MODEL::ENVIROMENT, "../Bin/Resources/Models/River/River.bin", XMMatrixScaling(0.001f, 0.001f, 0.001f) * XMMatrixIdentity())))){
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
{
|
||||
CModel* pModel = (CModel*)m_pGameInstance->Find_Asset_Prototype(g_iStaticLevel, TEXT("Prototype_Component_River_Col_Model"));
|
||||
_uint iNumMesh = pModel->Get_NumMeshes();
|
||||
|
||||
CRigidBody::RIGIDBODY_PROTOTYPEDESC Desc{};
|
||||
Desc.tRigidStaticDesc.pMeshKey = TEXT("PhysX_Plane");
|
||||
Desc.tRigidStaticDesc.vMatInfo = _float3(0.5f, 0.5f, 0.6f);
|
||||
Desc.tRigidStaticDesc.pMesh = ;
|
||||
|
||||
m_pGameInstance->Add_Asset_Prototype(g_iStaticLevel, TEXT("PHYSX_DYNAMIC_BOX"), CRigidBody::Create(m_pDevice, m_pContext, Desc));
|
||||
for (_uint i = 0; i < iNumMesh; ++i) {
|
||||
Desc.eType = ACTOR::TRIANGLEMESH;
|
||||
Desc.tRigidStaticDesc.szMeshName = pModel->Get_MeshName(i);
|
||||
Desc.tRigidStaticDesc.vMatInfo = _float3(0.5f, 0.5f, 0.6f);
|
||||
if (FAILED(m_pGameInstance->Add_Asset_Prototype(g_iStaticLevel, CMyTools::ToWstring(Desc.tRigidStaticDesc.szMeshName).c_str(), CRigidBody::Create(m_pDevice, m_pContext, Desc)))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
}
|
||||
}
|
||||
{
|
||||
m_pGameInstance->Add_Asset_Prototype(g_iStaticLevel, TEXT("PHYSX_CCT_CAPSULE"), CCharacter_Controller::Create(m_pDevice, m_pContext));
|
||||
|
||||
@@ -31,8 +31,6 @@ class CDummy_PhysXMesh final : public CGameObject
|
||||
virtual HRESULT Render() override;
|
||||
|
||||
private:
|
||||
CRigidBody* m_pRigidBody = { nullptr };
|
||||
const PSX::PxRigidStatic* m_pActor = { nullptr };
|
||||
|
||||
private:
|
||||
virtual HRESULT Initialize_Prototype() override;
|
||||
|
||||
@@ -204,10 +204,6 @@ CComponent* CCharacter_Controller::Clone(void* pArg, class CGameObject* pOwner)
|
||||
void CCharacter_Controller::Free()
|
||||
{
|
||||
__super::Free();
|
||||
|
||||
if (nullptr != m_pController) {
|
||||
m_pController->release();
|
||||
}
|
||||
}
|
||||
|
||||
void CCharacter_Controller::Describe_Entity()
|
||||
|
||||
@@ -541,10 +541,12 @@ PSX::PxMaterial* CGameInstance::Get_Material(_float3& vMatInfo)
|
||||
{
|
||||
return m_pPhysX_Manager->Get_Material(vMatInfo);
|
||||
}
|
||||
HRESULT CGameInstance::Create_TriangleMesh(const _wstring& wstrMeshKey, CMesh* pMesh)
|
||||
|
||||
void CGameInstance::RegistTriMesh(const _char* pName, PSX::PxTriangleMesh* pPxTriMesh)
|
||||
{
|
||||
return m_pPhysX_Manager->Create_TriangleMesh(wstrMeshKey, pMesh);
|
||||
return m_pPhysX_Manager->RegistTriMesh(pName, pPxTriMesh);
|
||||
}
|
||||
|
||||
PSX::PxShape* CGameInstance::Create_Shape(ACTOR eType, _float3& vhalfGeometryInfo, PSX::PxMaterial& pxMaterial, _bool bExclusive, PSX::PxShapeFlags ePxShapeFlag)
|
||||
{
|
||||
return m_pPhysX_Manager->Create_Shape(eType, vhalfGeometryInfo, pxMaterial, bExclusive, ePxShapeFlag);
|
||||
@@ -573,6 +575,18 @@ void CGameInstance::ReleaseController(_uint iControllerIndex)
|
||||
{
|
||||
m_pPhysX_Manager->ReleaseController(iControllerIndex);
|
||||
}
|
||||
HRESULT CGameInstance::ConvertToTriMeshes(vector<class CMesh*>& Meshes, vector<class PSX::PxTriangleMesh*>& pxTriMeshes)
|
||||
{
|
||||
return m_pPhysX_Manager->ConvertToTriMeshes(Meshes, pxTriMeshes);
|
||||
}
|
||||
_bool CGameInstance::SaveTriMeshes(const _char* pPath, vector<PSX::PxTriangleMesh*>& TriMeshes)
|
||||
{
|
||||
return m_pPhysX_Manager->SaveTriMeshes(pPath, TriMeshes);
|
||||
}
|
||||
_bool CGameInstance::LoadTriMeshes(const _char* pPath, vector<PSX::PxTriangleMesh*>& TriMeshes)
|
||||
{
|
||||
return m_pPhysX_Manager->LoadTriMeshes(pPath, TriMeshes);
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
bool CGameInstance::Key_Pressing(int _iKey)
|
||||
|
||||
@@ -90,14 +90,16 @@ HRESULT CMesh::Initialize_Prototype(MODEL eType, vector<class CBone*>& Bones, co
|
||||
_uint* pIndices = new _uint[m_iNumIndices];
|
||||
ZeroMemory(pIndices, sizeof(_uint) * m_iNumIndices);
|
||||
|
||||
m_pIndices = new _uint[m_iNumIndices];
|
||||
ZeroMemory(m_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];
|
||||
pIndices[iNumIndices++] = m_pIndices[iNumIndices] = pAIMesh->mFaces[i].mIndices[0];
|
||||
pIndices[iNumIndices++] = m_pIndices[iNumIndices] = pAIMesh->mFaces[i].mIndices[1];
|
||||
pIndices[iNumIndices++] = m_pIndices[iNumIndices] = pAIMesh->mFaces[i].mIndices[2];
|
||||
}
|
||||
|
||||
|
||||
@@ -352,7 +354,7 @@ HRESULT CMesh::Ready_VertexBuffer_For_Anim(HANDLE hFile, DWORD& dwByte)
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CMesh::Ready_VertexBuffer_For_NonAnim(SaveMesh* _SaveMesh, _fmatrix PreTransformMatrix)
|
||||
HRESULT CMesh::Ready_VertexBuffer_For_NonAnim(SaveMesh* SaveMesh, _fmatrix PreTransformMatrix)
|
||||
{
|
||||
m_iVertexStride = sizeof(VTXMESH);
|
||||
D3D11_BUFFER_DESC VBDesc{};
|
||||
@@ -371,23 +373,23 @@ HRESULT CMesh::Ready_VertexBuffer_For_NonAnim(SaveMesh* _SaveMesh, _fmatrix PreT
|
||||
|
||||
for (_uint i = 0; i < m_iNumVertices; ++i)
|
||||
{
|
||||
memcpy(&pVertices[i].vPosition, &_SaveMesh->Vertices[i].Pos, sizeof(_float3));
|
||||
memcpy(&pVertices[i].vPosition, &SaveMesh->Vertices[i].Pos, sizeof(_float3));
|
||||
XMStoreFloat3(&pVertices[i].vPosition,
|
||||
XMVector3TransformCoord(XMLoadFloat3(&pVertices[i].vPosition), PreTransformMatrix));
|
||||
|
||||
memcpy(&pVertices[i].vNormal, &_SaveMesh->Vertices[i].Normal, sizeof(_float3));
|
||||
memcpy(&pVertices[i].vNormal, &SaveMesh->Vertices[i].Normal, sizeof(_float3));
|
||||
XMStoreFloat3(&pVertices[i].vNormal,
|
||||
XMVector3Normalize(XMVector3TransformNormal(XMLoadFloat3(&pVertices[i].vNormal), PreTransformMatrix)));
|
||||
|
||||
memcpy(&pVertices[i].vTangent, &_SaveMesh->Vertices[i].Tan, sizeof(_float3));
|
||||
memcpy(&pVertices[i].vTangent, &SaveMesh->Vertices[i].Tan, sizeof(_float3));
|
||||
XMStoreFloat3(&pVertices[i].vTangent,
|
||||
XMVector3Normalize(XMVector3TransformNormal(XMLoadFloat3(&pVertices[i].vTangent), PreTransformMatrix)));
|
||||
|
||||
memcpy(&pVertices[i].vBinormal, &_SaveMesh->Vertices[i].BiNoraml, sizeof(_float3));
|
||||
memcpy(&pVertices[i].vBinormal, &SaveMesh->Vertices[i].BiNoraml, sizeof(_float3));
|
||||
XMStoreFloat3(&pVertices[i].vBinormal,
|
||||
XMVector3Normalize(XMVector3TransformNormal(XMLoadFloat3(&pVertices[i].vBinormal), PreTransformMatrix)));
|
||||
|
||||
pVertices[i].vTexcoord = _SaveMesh->Vertices[i].UV;
|
||||
pVertices[i].vTexcoord = SaveMesh->Vertices[i].UV;
|
||||
}
|
||||
|
||||
D3D11_SUBRESOURCE_DATA InitialVBData{};
|
||||
@@ -420,6 +422,7 @@ HRESULT CMesh::Ready_VertexBuffer_For_Anim(const CModel* pModel, SaveMesh* _Save
|
||||
|
||||
for (_uint i = 0; i < m_iNumVertices; ++i)
|
||||
{
|
||||
memcpy(&m_pVertexPositions[i], &_SaveMesh->Vertices[i].Pos, sizeof(_float3));
|
||||
memcpy(&pVertices[i].vPosition, &_SaveMesh->Vertices[i].Pos, sizeof(_float3));
|
||||
if (_SaveMesh->Vertices[i].bHasNormal)
|
||||
memcpy(&pVertices[i].vNormal, &_SaveMesh->Vertices[i].Normal, sizeof(_float3));
|
||||
@@ -604,26 +607,40 @@ HRESULT CMesh::SaveAsBinary(HANDLE hFile, DWORD& dwByte)
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
PSX::PxTriangleMesh* CMesh::ConvertToPxMesh(const PSX::PxCookingParams* pParam)
|
||||
PSX::PxTriangleMesh* CMesh::ConvertToPxMesh(const PSX::PxCookingParams* pParam, PSX::PxPhysics* pPhysX)
|
||||
{
|
||||
PSX::PxTriangleMeshDesc Desc;
|
||||
PSX::PxTriangleMeshDesc tMeshDesc;
|
||||
vector<PSX::PxVec3> Vertices;
|
||||
vector<PSX::PxU32> Triangles;
|
||||
{
|
||||
Desc.points.count = m_iNumVertices;
|
||||
Desc.points.stride = sizeof(PSX::PxVec3);
|
||||
tMeshDesc.points.count = m_iNumVertices;
|
||||
tMeshDesc.points.stride = sizeof(PSX::PxVec3);
|
||||
Vertices.resize(m_iNumVertices);
|
||||
memcpy_s(Vertices.data(), sizeof(PSX::PxVec3) * m_iNumVertices, m_pVertexPositions, sizeof(_float3) * m_iNumVertices);
|
||||
Desc.points.data = Vertices.data();
|
||||
tMeshDesc.points.data = Vertices.data();
|
||||
}
|
||||
{
|
||||
Desc.triangles.count = m_iNumIndices / 3;
|
||||
Desc.triangles.stride = sizeof(PSX::PxU32) * 3;
|
||||
tMeshDesc.triangles.count = m_iNumIndices / 3;
|
||||
tMeshDesc.triangles.stride = sizeof(PSX::PxU32) * 3;
|
||||
Triangles.resize(m_iNumIndices);
|
||||
memcpy_s(Triangles.data(), sizeof(PSX::PxU32) * m_iNumIndices, m_pIndices, sizeof(PSX::PxU32) * m_iNumIndices);
|
||||
Desc.triangles.data = Triangles.data();
|
||||
tMeshDesc.triangles.data = Triangles.data();
|
||||
}
|
||||
PSX::PxTriangleMesh* pTriangleMesh = PxCreateTriangleMesh(*pParam, Desc);
|
||||
PSX::PxDefaultMemoryOutputStream streamWriteBuffer = {};
|
||||
PSX::PxTriangleMeshCookingResult::Enum eCookResult = {};
|
||||
const _bool bCooked = PxCookTriangleMesh(*pParam, tMeshDesc, streamWriteBuffer, &eCookResult);
|
||||
if (false == bCooked) {
|
||||
assert(false);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
PSX::PxDefaultMemoryInputData readBuff(streamWriteBuffer.getData(), streamWriteBuffer.getSize());
|
||||
PSX::PxTriangleMesh* pTriangleMesh = pPhysX->createTriangleMesh(readBuff);
|
||||
if (nullptr == pTriangleMesh) {
|
||||
assert(false);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return pTriangleMesh;
|
||||
}
|
||||
|
||||
@@ -647,6 +664,7 @@ HRESULT CMesh::Ready_VertexBuffer_For_NonAnim(const aiMesh* pAIMesh, _fmatrix Pr
|
||||
for (_uint i = 0; i < m_iNumVertices; ++i)
|
||||
{
|
||||
memcpy(&pVertices[i].vPosition, &pAIMesh->mVertices[i], sizeof(_float3));
|
||||
memcpy(&m_pVertexPositions[i], &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)));
|
||||
@@ -688,6 +706,7 @@ HRESULT CMesh::Ready_VertexBuffer_For_Anim(vector<class CBone*>& Bones, const ai
|
||||
for (_uint i = 0; i < m_iNumVertices; ++i)
|
||||
{
|
||||
memcpy(&pVertices[i].vPosition, &pAIMesh->mVertices[i], sizeof(_float3));
|
||||
memcpy(&m_pVertexPositions[i], &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));
|
||||
|
||||
@@ -262,6 +262,11 @@ const _float4x4* CModel::Get_BoneMatrixPtr(const _char* pBoneName) const
|
||||
return (*iter)->Get_CombinedTransformationMatrixPtr();
|
||||
}
|
||||
|
||||
const _char* CModel::Get_MeshName(_uint iIndex)
|
||||
{
|
||||
return m_Meshes[iIndex]->Get_Name();
|
||||
}
|
||||
|
||||
|
||||
_matrix CModel::Get_BoneMatrix(_uint iBoneIndex)
|
||||
{
|
||||
@@ -340,6 +345,17 @@ HRESULT CModel::Ready_Meshes(MODEL eType, const aiScene* pAIScene, _fmatrix& Pre
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CModel::Ready_PhysXMeshes(MODEL eType)
|
||||
{
|
||||
m_iNumPhysXMeshes = m_iNumMeshes;
|
||||
|
||||
m_TriMeshes.reserve(m_iNumMeshes);
|
||||
|
||||
m_pGameInstance->ConvertToTriMeshes(m_Meshes, m_TriMeshes);
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CModel::Ready_Materials(const aiScene* pAIScene, const _char* pModelFilePath)
|
||||
{
|
||||
m_iNumMaterials = pAIScene->mNumMaterials;
|
||||
@@ -794,6 +810,9 @@ HRESULT CModel::Assimp_Model_Load(const _char* pModelFilePath, MODEL eType, _fma
|
||||
if (FAILED(Ready_Materials_FromFile(m_pAIScene, pModelFilePath))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
if (FAILED(Ready_PhysXMeshes(eType))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -836,7 +855,12 @@ HRESULT CModel::Initialize_Prototype(MODEL eType, const _char* pModelFilePath, _
|
||||
|
||||
if (strcmp(".bin", szEXT) == 0)
|
||||
{
|
||||
_char Temp[256];
|
||||
strcpy_s(Temp, szDir);
|
||||
strcat_s(Temp, szName);
|
||||
strcat_s(Temp, ".bin");
|
||||
LoadData(pModelFilePath);
|
||||
m_pGameInstance->LoadTriMeshes(pModelFilePath, m_TriMeshes);
|
||||
}
|
||||
else if (strcmp(".fbx", szEXT) == 0)
|
||||
{
|
||||
@@ -846,10 +870,15 @@ HRESULT CModel::Initialize_Prototype(MODEL eType, const _char* pModelFilePath, _
|
||||
strcat_s(Temp, ".bin");
|
||||
Assimp_Model_Load(pModelFilePath, eType, PreTransformMatrix, 0);
|
||||
SaveAssimpModel(Temp);
|
||||
m_pGameInstance->SaveTriMeshes(pModelFilePath, m_TriMeshes);
|
||||
|
||||
for (_uint i = 0; i < m_iNumMeshes; ++i) {
|
||||
m_pGameInstance->RegistTriMesh(m_Meshes[i]->Get_Name(), m_TriMeshes[i]);
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
m_pSaveModel = m_pGameInstance->Load_SaveModel(pModelFilePath);
|
||||
|
||||
|
||||
m_eType = eType;
|
||||
XMStoreFloat4x4(&m_PreTransformMatrix, PreTransformMatrix);
|
||||
@@ -868,6 +897,9 @@ HRESULT CModel::Initialize_Prototype(MODEL eType, const _char* pModelFilePath, _
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
for (_uint i = 0; i < m_iNumMeshes; ++i) {
|
||||
m_pGameInstance->RegistTriMesh(m_Meshes[i]->Get_Name(), m_TriMeshes[i]);
|
||||
}
|
||||
|
||||
|
||||
return S_OK;
|
||||
|
||||
@@ -79,7 +79,6 @@ const PSX::PxRigidStatic* CPhysX_Manager::Add_StaticActor(CRigidBody& RigidBody)
|
||||
pPxMeshGeometry = iter->second;
|
||||
}
|
||||
|
||||
|
||||
PSX::PxRigidStatic* pActor = m_pPhysics->createRigidStatic(pxWorldMatrix);
|
||||
PSX::PxShape* pShape = PSX::PxRigidActorExt::createExclusiveShape(*pActor, *pPxMeshGeometry, *RigidBody.Get_PxMaterial());
|
||||
|
||||
@@ -122,19 +121,100 @@ PSX::PxShape* CPhysX_Manager::Create_Shape(ACTOR eType, _float3& vhalfGeometryIn
|
||||
return pShape;
|
||||
}
|
||||
|
||||
HRESULT CPhysX_Manager::Create_TriangleMesh(const _wstring& wstrMeshKey, CMesh* pMesh)
|
||||
void CPhysX_Manager::RegistTriMesh(const _char* pName, PSX::PxTriangleMesh* pPxTriMesh) {
|
||||
m_TriangleMeshes.emplace(CMyTools::ToWstring(pName), pPxTriMesh);
|
||||
|
||||
PSX::PxTriangleMeshGeometry* pGeometry = new PSX::PxTriangleMeshGeometry(pPxTriMesh);
|
||||
pGeometry->meshFlags |= PSX::PxMeshGeometryFlag::eDOUBLE_SIDED;
|
||||
m_TriangleMeshGeometry.emplace(CMyTools::ToWstring(pName), pGeometry);
|
||||
}
|
||||
|
||||
HRESULT CPhysX_Manager::ConvertToTriMeshes(vector<class CMesh*>& Meshes, vector<PSX::PxTriangleMesh*>& pxTriMeshes)
|
||||
{
|
||||
|
||||
PSX::PxTriangleMesh* pTriangleMesh = pMesh->ConvertToPxMesh(m_pCookingParam);
|
||||
if (nullptr != pTriangleMesh) {
|
||||
m_TriangleMeshes.emplace(wstrMeshKey, pTriangleMesh);
|
||||
|
||||
PSX::PxTriangleMeshGeometry* pGeometry = new PSX::PxTriangleMeshGeometry(pTriangleMesh);
|
||||
pGeometry->meshFlags |= PSX::PxMeshGeometryFlag::eDOUBLE_SIDED;
|
||||
m_TriangleMeshGeometry.emplace(wstrMeshKey, pGeometry);
|
||||
return S_OK;
|
||||
for (size_t i = 0; i < Meshes.size(); ++i)
|
||||
{
|
||||
PSX::PxTriangleMesh* pTriangleMesh = Meshes[i]->ConvertToPxMesh(m_pCookingParam, m_pPhysics);
|
||||
if (nullptr == pTriangleMesh) {
|
||||
return E_FAIL;
|
||||
}
|
||||
pxTriMeshes.push_back(pTriangleMesh);
|
||||
}
|
||||
return E_FAIL;
|
||||
pxTriMeshes.shrink_to_fit();
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
_bool CPhysX_Manager::SaveTriMeshes(const _char* pPath, vector<PSX::PxTriangleMesh*>& TriMeshes)
|
||||
{
|
||||
filesystem::path pathPhysX = pPath;
|
||||
pathPhysX.replace_extension(".xml");
|
||||
if (TriMeshes.empty()){
|
||||
return false;
|
||||
}
|
||||
|
||||
filesystem::create_directories(pathPhysX.parent_path());
|
||||
|
||||
|
||||
PSX::PxSerializationRegistry* pSerializationRegistry = PSX::PxSerialization::createSerializationRegistry(*m_pPhysics);
|
||||
PSX::PxCollection* pCollections = PxCreateCollection();
|
||||
if (nullptr == pCollections) {
|
||||
pSerializationRegistry->release();
|
||||
assert(pCollections);
|
||||
return false;
|
||||
}
|
||||
|
||||
for (PSX::PxTriangleMesh* pTriMesh : TriMeshes) {
|
||||
pCollections->add(*pTriMesh);
|
||||
}
|
||||
|
||||
PSX::PxSerialization::complete(*pCollections, *pSerializationRegistry);
|
||||
PSX::PxDefaultFileOutputStream out(pathPhysX.string().c_str());
|
||||
PSX::PxCollection* extRefs = PxCreateCollection();
|
||||
const _bool ok = PSX::PxSerialization::serializeCollectionToXml(out, *pCollections, *pSerializationRegistry, m_pCookingParam, extRefs);
|
||||
//const _bool ok = PSX::PxSerialization::serializeCollectionToBinary(out, *pCollections, *pSerializationRegistry, extRefs);
|
||||
|
||||
extRefs->release();
|
||||
pCollections->release();
|
||||
pSerializationRegistry->release();
|
||||
assert(ok);
|
||||
return ok;
|
||||
}
|
||||
|
||||
_bool CPhysX_Manager::LoadTriMeshes(const _char* pPath, vector<PSX::PxTriangleMesh*>& TriMeshes)
|
||||
{
|
||||
filesystem::path pathPhysX = pPath;
|
||||
pathPhysX.replace_extension(".xml");
|
||||
|
||||
PSX::PxSerializationRegistry* pSerializationRegistry = PSX::PxSerialization::createSerializationRegistry(*m_pPhysics);
|
||||
|
||||
PSX::PxDefaultFileInputData InputData(pathPhysX.string().c_str());
|
||||
PSX::PxCollection* extRefs = PxCreateCollection();
|
||||
|
||||
//PSX::PxCollection* pCollections = PSX::PxSerialization::createCollectionFromBinary(&InputData, *pSerializationRegistry, extRefs);
|
||||
PSX::PxCollection* pCollections = PSX::PxSerialization::createCollectionFromXml(InputData, *m_pCookingParam, *pSerializationRegistry, extRefs);
|
||||
if (nullptr == pCollections) {
|
||||
extRefs->release();
|
||||
pSerializationRegistry->release();
|
||||
assert(pCollections);
|
||||
return false;
|
||||
}
|
||||
|
||||
const PSX::PxU32 iNumTriMeshes = pCollections->getNbObjects();
|
||||
TriMeshes.reserve(iNumTriMeshes);
|
||||
for (PSX::PxU32 i = 0; i < iNumTriMeshes; ++i) {
|
||||
PSX::PxBase& pObject = pCollections->getObject(i);
|
||||
|
||||
if (pObject.getConcreteType() == PSX::PxConcreteType::eTRIANGLE_MESH_BVH34) {
|
||||
PSX::PxTriangleMesh* pTriMesh = static_cast<PSX::PxTriangleMesh*>(&pObject);
|
||||
pTriMesh->acquireReference();
|
||||
TriMeshes.push_back(pTriMesh);
|
||||
}
|
||||
}
|
||||
|
||||
extRefs->release();
|
||||
pCollections->release();
|
||||
pSerializationRegistry->release();
|
||||
return true;
|
||||
}
|
||||
|
||||
PSX::PxTriangleMesh* CPhysX_Manager::Find_TriangleMesh(const _wstring& wstrMeshKey)
|
||||
@@ -314,27 +394,27 @@ HRESULT CPhysX_Manager::Initialize()
|
||||
|
||||
#ifdef ±â¹«¸®
|
||||
physx::PxMaterial* pMaterial = m_pPhysics->createMaterial(0.5f, 0.5f, 0.6f);
|
||||
physx::PxRigidStatic* pGroundPlane = PxCreatePlane(*m_pPhysics, physx::PxPlane(0, 1, 0, 0), *pMaterial);
|
||||
m_pScene->addActor(*pGroundPlane);
|
||||
//physx::PxRigidStatic* pGroundPlane = PxCreatePlane(*m_pPhysics, physx::PxPlane(0, 1, 0, 0), *pMaterial);
|
||||
//m_pScene->addActor(*pGroundPlane);
|
||||
|
||||
{
|
||||
float halfExtent = .5f;
|
||||
physx::PxShape* shape = m_pPhysics->createShape(physx::PxSphereGeometry(halfExtent), *pMaterial);
|
||||
physx::PxU32 size = 30;
|
||||
physx::PxTransform pxTransform(physx::PxVec3(0));
|
||||
//{
|
||||
// float halfExtent = .5f;
|
||||
// physx::PxShape* shape = m_pPhysics->createShape(physx::PxSphereGeometry(halfExtent), *pMaterial);
|
||||
// physx::PxU32 size = 30;
|
||||
// physx::PxTransform pxTransform(physx::PxVec3(0));
|
||||
|
||||
for (physx::PxU32 i = 0; i < size; i++) {
|
||||
for (physx::PxU32 j = 0; j < size - i; j++) {
|
||||
physx::PxTransform localTm(physx::PxVec3(physx::PxReal(j * 2) - physx::PxReal(size - i) + 100, physx::PxReal(i * 2 + 1), 0) * halfExtent);
|
||||
physx::PxRigidDynamic* body = m_pPhysics->createRigidDynamic(pxTransform.transform(localTm));
|
||||
body->attachShape(*shape);
|
||||
physx::PxRigidBodyExt::updateMassAndInertia(*body, 10.0f);
|
||||
m_pScene->addActor(*body);
|
||||
}
|
||||
}
|
||||
}
|
||||
// for (physx::PxU32 i = 0; i < size; i++) {
|
||||
// for (physx::PxU32 j = 0; j < size - i; j++) {
|
||||
// physx::PxTransform localTm(physx::PxVec3(physx::PxReal(j * 2) - physx::PxReal(size - i) + 100, physx::PxReal(i * 2 + 1), 0) * halfExtent);
|
||||
// physx::PxRigidDynamic* body = m_pPhysics->createRigidDynamic(pxTransform.transform(localTm));
|
||||
// body->attachShape(*shape);
|
||||
// physx::PxRigidBodyExt::updateMassAndInertia(*body, 10.0f);
|
||||
// m_pScene->addActor(*body);
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
#endif // ±â¹«¸®
|
||||
|
||||
pMaterial->release();
|
||||
|
||||
|
||||
return S_OK;
|
||||
@@ -386,6 +466,10 @@ void CPhysX_Manager::Free()
|
||||
if (nullptr != m_pCookingParam) {
|
||||
Safe_Delete(m_pCookingParam);
|
||||
}
|
||||
if (nullptr != m_pCCTManager) {
|
||||
m_pCCTManager->release();
|
||||
m_pCCTManager = nullptr;
|
||||
}
|
||||
|
||||
if (nullptr != m_pScene) {
|
||||
m_pScene->release(); m_pScene = nullptr;
|
||||
@@ -400,6 +484,7 @@ void CPhysX_Manager::Free()
|
||||
}
|
||||
|
||||
if (nullptr != m_pPvd) {
|
||||
m_pPvd->disconnect();
|
||||
m_pPvd->release(); m_pPvd = nullptr;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ CRigidBody::CRigidBody(const CRigidBody& rhs):
|
||||
m_eActorType(rhs.m_eActorType),
|
||||
m_vhalfGeometryInfo(rhs.m_vhalfGeometryInfo),
|
||||
m_pShape(rhs.m_pShape),
|
||||
m_pMeshKey(rhs.m_pMeshKey),
|
||||
m_wstrMeshKey(rhs.m_wstrMeshKey),
|
||||
m_bExclusive(rhs.m_bExclusive),
|
||||
m_bKinematic(rhs.m_bKinematic)
|
||||
{
|
||||
@@ -44,9 +44,8 @@ HRESULT CRigidBody::Initialize_Prototype(RIGIDBODY_PROTOTYPEDESC& Desc)
|
||||
break;
|
||||
case ACTOR::TRIANGLEMESH:
|
||||
{
|
||||
m_pGameInstance->Create_TriangleMesh(Desc.tRigidStaticDesc.pMeshKey, Desc.tRigidStaticDesc.pMesh);
|
||||
m_pMaterial = m_pGameInstance->Get_Material(Desc.tRigidDynamicDesc.vMatInfo);
|
||||
m_pMeshKey = Desc.tRigidStaticDesc.pMeshKey;
|
||||
m_wstrMeshKey = CMyTools::ToWstring(Desc.tRigidStaticDesc.szMeshName);
|
||||
}
|
||||
break;
|
||||
case ACTOR::HEIGHTFIELD:
|
||||
@@ -54,6 +53,7 @@ HRESULT CRigidBody::Initialize_Prototype(RIGIDBODY_PROTOTYPEDESC& Desc)
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return S_OK;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -178,16 +178,20 @@ class ENGINE_DLL CGameInstance final : public CBase
|
||||
#pragma endregion
|
||||
#pragma region PhysX_Manager
|
||||
PSX::PxMaterial* Get_Material(_float3& vMatInfo);
|
||||
HRESULT Create_TriangleMesh(const _wstring& wstrMeshKey, CMesh* pMesh);
|
||||
void RegistTriMesh(const _char* pName, PSX::PxTriangleMesh* pPxTriMesh);
|
||||
PSX::PxShape* Create_Shape(ACTOR eType, _float3& vhalfGeometryInfo, PSX::PxMaterial& pxMaterial, _bool bExclusive = false, PSX::PxShapeFlags ePxShapeFlag = PSX::PxShapeFlag::eVISUALIZATION | PSX::PxShapeFlag::eSCENE_QUERY_SHAPE | PSX::PxShapeFlag::eSIMULATION_SHAPE);
|
||||
const PSX::PxRigidDynamic* Add_DynamicActor(CRigidBody& RigidBody);
|
||||
const PSX::PxRigidStatic* Add_StaticActor(CRigidBody& RigidBody);
|
||||
|
||||
|
||||
PSX::PxController* Add_CapsuleController(PSX::PxCapsuleControllerDesc& Desc);
|
||||
PSX::PxController* Add_BoxController(PSX::PxBoxControllerDesc& Desc);
|
||||
PSX::PxController* Get_Controller(_uint iControllerIndex);
|
||||
PSX::PxController* Add_CapsuleController(PSX::PxCapsuleControllerDesc& Desc);
|
||||
PSX::PxController* Add_BoxController(PSX::PxBoxControllerDesc& Desc);
|
||||
PSX::PxController* Get_Controller(_uint iControllerIndex);
|
||||
void ReleaseController(_uint iControllerIndex);
|
||||
|
||||
HRESULT ConvertToTriMeshes(vector<class CMesh*>& Meshes, vector<class PSX::PxTriangleMesh*>& pxTriMeshes);
|
||||
_bool SaveTriMeshes(const _char* pPath, vector<PSX::PxTriangleMesh*>& TriMeshes);
|
||||
_bool LoadTriMeshes(const _char* pPath, vector<PSX::PxTriangleMesh*>& TriMeshes);
|
||||
#pragma endregion
|
||||
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ class ENGINE_DLL CMesh final : public CVIBuffer
|
||||
return m_iMaterialIndex;
|
||||
}
|
||||
|
||||
const _char* Get_Name() const { return m_szName; }
|
||||
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);
|
||||
@@ -27,7 +28,7 @@ class ENGINE_DLL CMesh final : public CVIBuffer
|
||||
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);
|
||||
PSX::PxTriangleMesh* ConvertToPxMesh(const PSX::PxCookingParams* pParam);
|
||||
PSX::PxTriangleMesh* ConvertToPxMesh(const PSX::PxCookingParams* pParam, PSX::PxPhysics* pPhysX);
|
||||
#endif // EDITOR_PROJECT
|
||||
|
||||
public:
|
||||
|
||||
@@ -31,6 +31,7 @@ class ENGINE_DLL CModel final : public CComponent
|
||||
_int Get_RootBoneIndex() const { return m_iRootBoneIndex; }
|
||||
const _float4x4* Get_BoneMatrixPtr(const _char* pBoneName) const;
|
||||
_uint Get_NumMeshes() const { return m_iNumMeshes; }
|
||||
const _char* Get_MeshName(_uint iIndex);
|
||||
MODEL Get_Type() const { return m_eType; }
|
||||
_matrix Get_BoneMatrix(_uint iBoneIndex);
|
||||
|
||||
@@ -60,12 +61,13 @@ class ENGINE_DLL CModel final : public CComponent
|
||||
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_PhysXMeshes(MODEL eType);
|
||||
HRESULT Ready_Materials(const aiScene* pAIScene, const _char* pModelFilePath);
|
||||
HRESULT Ready_Materials_FromFile(const aiScene* pAIScene, const _char* pModelFilePath);
|
||||
HRESULT Ready_Animations(const aiScene* pAIScene);
|
||||
HRESULT Ready_Bones(const aiNode* pAINode, _int iParentIndex);
|
||||
// 바이너리
|
||||
bool SaveAssimpModel(const _char* filename);
|
||||
_bool SaveAssimpModel(const _char* filename);
|
||||
_int SaveNodeRecursive(const aiNode* pAINode, std::vector<SaveNode>& outNodes, _int parentIndex);
|
||||
//
|
||||
#endif // EDITOR_PROJECT
|
||||
@@ -83,6 +85,8 @@ class ENGINE_DLL CModel final : public CComponent
|
||||
|
||||
_uint m_iNumMeshes = {}; // 메쉬의 갯수
|
||||
vector<class CMesh*> m_Meshes; // 메쉬의 벡터
|
||||
_uint m_iNumPhysXMeshes = {}; // 피직스 메쉬의 갯수
|
||||
vector<PSX::PxTriangleMesh*> m_TriMeshes = {}; // 피직스 메쉬의 갯수
|
||||
|
||||
_uint m_iNumMaterials = {}; // 머테리얼의 갯수
|
||||
vector<class CMaterial*> m_Materials; // 머테리얼의 벡터
|
||||
|
||||
@@ -22,11 +22,14 @@ class CPhysX_Manager final : public CBase
|
||||
|
||||
const PSX::PxRigidDynamic* Add_DynamicActor(CRigidBody& RigidBody);
|
||||
const PSX::PxRigidStatic* Add_StaticActor(CRigidBody& RigidBody);
|
||||
|
||||
|
||||
void RegistTriMesh(const _char* pName, PSX::PxTriangleMesh* pPxTriMesh);
|
||||
PSX::PxMaterial* Get_Material(_float3& vMatInfo);
|
||||
PSX::PxShape* Create_Shape(ACTOR eType, _float3& vhalfGeometryInfo, PSX::PxMaterial& pxMaterial, _bool bExclusive, PSX::PxShapeFlags ePxShapeFlag);
|
||||
|
||||
HRESULT Create_TriangleMesh(const _wstring& wstrMeshKey, CMesh* pMesh);
|
||||
HRESULT ConvertToTriMeshes(vector<class CMesh*>& Meshes, vector<class PSX::PxTriangleMesh*>& pxTriMeshes);
|
||||
_bool SaveTriMeshes(const _char* pPath, vector<PSX::PxTriangleMesh*>& TriMeshes);
|
||||
_bool LoadTriMeshes(const _char* pPath, vector<PSX::PxTriangleMesh*>& TriMeshes);
|
||||
PSX::PxTriangleMesh* Find_TriangleMesh(const _wstring& wstrMeshKey);
|
||||
|
||||
void Update(_float fTimeDelta);
|
||||
|
||||
@@ -16,8 +16,7 @@ class ENGINE_DLL CRigidBody final : public CComponent
|
||||
typedef struct tagRigidStatic_PrototypeDesc
|
||||
{
|
||||
_float3 vMatInfo;
|
||||
const _tchar* pMeshKey = { nullptr };
|
||||
CMesh* pMesh = { nullptr };
|
||||
const _char* szMeshName = { } ;
|
||||
}RIGID_STATIC_PROTOTYPEDESC;
|
||||
typedef struct tagRigidDynamic_PrototypeDesc
|
||||
{
|
||||
@@ -37,7 +36,7 @@ class ENGINE_DLL CRigidBody final : public CComponent
|
||||
};
|
||||
}RIGIDBODY_PROTOTYPEDESC;
|
||||
typedef struct tagRigidStatic_Desc {
|
||||
const _tchar* pMeshKey = { nullptr };
|
||||
const _char* szMeshName = { };
|
||||
}RIGID_STATIC_DESC;
|
||||
typedef struct tagRigidDynamic_Desc {
|
||||
_float fDensity = { 1000.f };
|
||||
@@ -68,7 +67,7 @@ class ENGINE_DLL CRigidBody final : public CComponent
|
||||
public:
|
||||
PSX::PxShape* Get_ShapePtr() const { return m_pShape; }
|
||||
CTransform* Get_PxTransformPtr() const { return m_pTransform; }
|
||||
const _tchar* Get_PxMeshKey() const { return m_pMeshKey; }
|
||||
const _tchar* Get_PxMeshKey() const { return m_wstrMeshKey.c_str(); }
|
||||
const PSX::PxMaterial* Get_PxMaterial() const { return m_pMaterial; }
|
||||
|
||||
_float Get_Density() const { return m_fDensity; }
|
||||
@@ -84,7 +83,7 @@ class ENGINE_DLL CRigidBody final : public CComponent
|
||||
_bool m_bKinematic = { false };
|
||||
_bool m_bExclusive = { false };
|
||||
_float m_fDensity = { 1000.f };
|
||||
const _tchar* m_pMeshKey = { nullptr };
|
||||
_wstring m_wstrMeshKey = { };
|
||||
|
||||
private:
|
||||
HRESULT Initialize_Prototype(RIGIDBODY_PROTOTYPEDESC& Desc);
|
||||
|
||||
Reference in New Issue
Block a user