[add] PhysxHeightMap

This commit is contained in:
kimnuri
2025-11-28 16:48:56 +09:00
parent 7c46dacf97
commit affa50b96e
15 changed files with 143 additions and 30 deletions
+21 -3
View File
@@ -763,9 +763,27 @@ HRESULT CLoader::Loading_For_GamePlay()
#pragma region MAP PROTOTYPE
/* For.Prototype_Component_VIBuffer_Terrain */
if (FAILED(m_pGameInstance->Add_Asset_Prototype(g_iStaticLevel, TEXT("Prototype_Component_VIBuffer_Terrain"),
CVIBuffer_Terrain::Create(m_pDevice, m_pContext, "Hogsmeade_HeightMap.bin", 512, 512))))
return E_FAIL;
{
CVIBuffer_Terrain* pTerrain = CVIBuffer_Terrain::Create(m_pDevice, m_pContext, "Hogsmeade_HeightMap.bin", 512, 512);
if (FAILED(m_pGameInstance->Add_Asset_Prototype(g_iStaticLevel, TEXT("Prototype_Component_VIBuffer_Terrain"), pTerrain))) {
return E_FAIL;
}
pTerrain->ConvertToHeightField(TEXT("Hogsmeade_HeightMap"));
CRigidBody_Static::RIGIDBODY_STATIC_PROTOTYPEDESC Desc{}; // 터레인 리지드 지형 추가
{
Desc.eType = ACTOR::HEIGHTFIELD;
Desc.ePxRigidBodyFlags = {};
Desc.ePxShapeFlags = { PSX::PxShapeFlag::eVISUALIZATION | PSX::PxShapeFlag::eSCENE_QUERY_SHAPE | PSX::PxShapeFlag::eSIMULATION_SHAPE };
Desc.ePxMaterialTypes = PXMATERIAL::DEFAULT;
Desc.vMatInfo = _float3(0.5f, 0.5f, 0.6f);
Desc.fContactOffset = 0.f;
}
CRigidBody_Static* pRigid = CRigidBody_Static::Create(m_pDevice, m_pContext, Desc);
if (FAILED(m_pGameInstance->Add_Asset_Prototype(g_iStaticLevel, TEXT("Prototype_Component_RigidBody_Static_Terrain_Hogsmeade"), pRigid))) {
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"),
+1 -2
View File
@@ -63,7 +63,7 @@ HRESULT CMonster::Render_OutLine()
if (FAILED(Bind_ShaderResources())) {
return E_FAIL;
}
GUI::Begin("OutLine");
GUI::SetNextItemWidth(80.f);
static _float3 vOutLineColor = _float3(1.f, 0.960784376f, 0.933333397f);
static _float fOutLineThickness = { 1.f }; // 카메라로부터 거리가 멀어지면 늘어나게끔 바꾸는걸 추천함
@@ -73,7 +73,6 @@ HRESULT CMonster::Render_OutLine()
GUI::SliderFloat("Thickness", &fOutLineThickness, 0.1f, 2.f, "%.1f");
GUI::SliderFloat("Scale", &fOutLineScale, 0.1f, 2.f, "%.1f");
GUI::SliderFloat("Power", &fOutLinePower, 0.1f, 2.f, "%.1f");
GUI::End();
if (FAILED(m_pShaderCom->Bind_RawValue("g_vOutLineColor", &vOutLineColor, sizeof(_float3)))) {
return E_FAIL;
}
+13 -1
View File
@@ -35,6 +35,15 @@ HRESULT CTerrain::Initialize(void* pArg)
m_pTransformCom->Set_State(STATE::POSITION, XMVectorSetW(XMLoadFloat3(&pDesc->vPosition), 1.f));
CRigidBody_Static::RIGIDBODY_STATIC_DESC Desc{};
Desc.pMeshName = TEXT("Hogsmeade_HeightMap");
Desc.iSubKind = 998;
/* Com_RigidBody */
if (FAILED(__super::Add_Asset_Component(g_iStaticLevel, TEXT("Prototype_Component_RigidBody_Static_Terrain_Hogsmeade"),
reinterpret_cast<CComponent**>(&m_pRigidBody), &Desc))) {
return E_FAIL;
}
return S_OK;
}
@@ -106,8 +115,10 @@ HRESULT CTerrain::Ready_Components(void* pArg)
/* Com_VIBuffer */
if (FAILED(__super::Add_Asset_Component(g_iStaticLevel, TEXT("Prototype_Component_VIBuffer_Terrain"),
reinterpret_cast<CComponent**>(&m_pVIBufferCom))))
reinterpret_cast<CComponent**>(&m_pVIBufferCom)))){
return E_FAIL;
}
/* Com_Shader */
if (FAILED(__super::Add_Asset_Component(g_iStaticLevel, FX_NORTEX,
@@ -205,6 +216,7 @@ void CTerrain::Free()
SAFE_RELEASE(m_pShaderCom);
SAFE_RELEASE(m_pVIBufferCom);
SAFE_RELEASE(m_pRigidBody);
SAFE_RELEASE(m_pDiffuseTextureCom);
SAFE_RELEASE(m_pNormalTextureCom);
SAFE_RELEASE(m_pMROTextureCom);
+1
View File
@@ -38,6 +38,7 @@ class CTerrain final : public CGameObject
private:
CShader* m_pShaderCom = { nullptr };
CVIBuffer_Terrain* m_pVIBufferCom = { nullptr };
CRigidBody_Static* m_pRigidBody = { nullptr };
CTexture* m_pDiffuseTextureCom = { nullptr };
CTexture* m_pNormalTextureCom = { nullptr };
CTexture* m_pMROTextureCom = { nullptr };
@@ -361,6 +361,7 @@ void CMapObject_LOD::Describe_Entity()
{ // RIGID_BODY
_wstring dest = CMyTools::ToWstring(m_pModelComs[iModelIndex]->Get_MeshName(iMeshIndex) + to_string(iMeshIndex)).c_str();
Desc.pMeshName = dest.c_str();
Desc.iSubKind = 998;
if (FAILED(Add_Asset_Component(g_iStaticLevel, Desc.pMeshName, nullptr, &Desc))) {
assert(false);
@@ -652,6 +652,11 @@ void CGameInstance::RegistTriMesh(const _char* pName, PSX::PxTriangleMesh* pPxTr
return m_pPhysX_Manager->RegistTriMesh(pName, pPxTriMesh);
}
void CGameInstance::RegistHeight(const _tchar* pName, PSX::PxHeightFieldDesc& Desc)
{
return m_pPhysX_Manager->RegistHeight(pName, Desc);
}
PSX::PxRigidDynamic* CGameInstance::Add_DynamicActor(CRigidBody_Dynamic& RigidBody)
{
return m_pPhysX_Manager->Add_DynamicActor(RigidBody);
@@ -77,15 +77,17 @@ PSX::PxRigidStatic* CPhysX_Manager::Add_StaticActor(CRigidBody_Static& RigidBody
// PxRigidStatic 씬의 정적 바디 인터페이스
PSX::PxRigidStatic* pActor = m_pPhysics->createRigidStatic(pxWorldMatrix);
PSX::PxShape* pShape = { nullptr };
PSX::PxTriangleMesh* pPxMesh = Find_TriangleMesh(RigidBody.Get_PxMeshKey());
PSX::PxTriangleMeshGeometry* pPxMeshGeometry = { nullptr };
PSX::PxGeometry* pGeometry = { nullptr };
switch (RigidBody.Get_Type())
{
case ACTOR::PLANE:
break;
case ACTOR::TRIANGLEMESH:
{ // SetUp Geometry
PSX::PxTriangleMesh* pPxMesh = Find_TriangleMesh(RigidBody.Get_PxMeshKey());
PSX::PxTriangleMeshGeometry* pPxMeshGeometry = { nullptr };
_vector vPos, vRotq, vScale;
XMMatrixDecompose(&vScale, &vRotq, &vPos, WorldMatrix);
vRotq = XMQuaternionNormalize(vRotq);
@@ -103,17 +105,41 @@ PSX::PxRigidStatic* CPhysX_Manager::Add_StaticActor(CRigidBody_Static& RigidBody
// pPxMeshGeometry->meshFlags |= PSX::PxMeshGeometryFlag::eDOUBLE_SIDED;
// 유효성 체크
PX_ASSERT(pPxMeshGeometry->isValid());
pGeometry = pPxMeshGeometry;
m_TriangleMeshGeometry.emplace(RigidBody.Get_PxMeshKey(), pPxMeshGeometry);
}
break;
case ACTOR::HEIGHTFIELD:
{ // SetUp HeightField
PSX::PxHeightField* pHeightField = Find_HeightField(RigidBody.Get_PxMeshKey());
PSX::PxHeightFieldGeometry* pPxHeightGeometry = { nullptr };
_vector vPos, vRotq, vScale;
XMMatrixDecompose(&vScale, &vRotq, &vPos, WorldMatrix);
vRotq = XMQuaternionNormalize(vRotq);
PSX::PxTransform out;
XMStoreFloat3((_float3*)&out.p, vPos);
XMStoreFloat4((_float4*)&out.q, vRotq);
PSX::PxMeshScale meshScale(
PSX::PxVec3(fabsf(vScale.m128_f32[0]), fabsf(vScale.m128_f32[1]), fabsf(vScale.m128_f32[2])),
PSX::PxQuat(PSX::PxIdentity) // 스케일 축은 로컬 기준
);
pPxHeightGeometry = new PSX::PxHeightFieldGeometry(pHeightField);
// 유효성 체크
PX_ASSERT(pPxHeightGeometry->isValid());
pGeometry = pPxHeightGeometry;
m_HeightFieldGeometry.emplace(RigidBody.Get_PxMeshKey(), pPxHeightGeometry);
}
break;
break;
default:
assert(false);
break;
}
pShape = PSX::PxRigidActorExt::createExclusiveShape(*pActor, *pPxMeshGeometry, *m_pMaterials[ENUM_CLASS(RigidBody.Get_MaterialType())]);
pShape = PSX::PxRigidActorExt::createExclusiveShape(*pActor, *pGeometry, *m_pMaterials[ENUM_CLASS(RigidBody.Get_MaterialType())]);
pShape->setFlags(RigidBody.Get_ShapeFlags());
pShape->setContactOffset(RigidBody.Get_ContactOffset());
@@ -144,6 +170,17 @@ void CPhysX_Manager::RegistTriMesh(const _char* pName, PSX::PxTriangleMesh* pPxT
{
m_TriangleMeshes.emplace(CMyTools::ToWstring(pName), pPxTriMesh);
}
void CPhysX_Manager::RegistHeight(const _tchar* pName, PSX::PxHeightFieldDesc& Desc)
{
PSX::PxHeightField* pHeightField = PxCreateHeightField(Desc);
if (nullptr == pHeightField) {
assert(false);
}
else {
m_HeightFields.emplace(pName, pHeightField);
}
}
#ifdef EDITOR_PROJECT
HRESULT CPhysX_Manager::ConvertToTriMeshes(vector<class CMesh*>& Meshes, vector<PSX::PxTriangleMesh*>& pxTriMeshes, _fmatrix WorldMatrix)
@@ -243,6 +280,15 @@ PSX::PxTriangleMesh* CPhysX_Manager::Find_TriangleMesh(const _tchar* pMeshName)
return nullptr;
}
PSX::PxHeightField* CPhysX_Manager::Find_HeightField(const _tchar* pFieldName)
{
map<_wstring, PSX::PxHeightField*>::iterator iter = m_HeightFields.find(pFieldName);
if (iter != m_HeightFields.end()) {
return iter->second;
}
return nullptr;
}
void CPhysX_Manager::Update_Kinematic()
{
for (auto& pBody : m_pActiveBodys) {
@@ -30,6 +30,8 @@ HRESULT CRigidBody_Static::Initialize(void* pArg)
if (FAILED(__super::Initialize(pArg))) {
return E_FAIL;
}
RIGIDBODY_STATIC_DESC* pDesc = static_cast<RIGIDBODY_STATIC_DESC*>(pArg);
m_pMeshName = pDesc->pMeshName;
m_tagData.pOwner = m_pOwner;
XMStoreFloat4x4(&m_tagData.BeforeMatrix, m_pTransform->Get_XMWorldMatrix());
m_tagData.pBody = this;
@@ -389,6 +389,43 @@ HRESULT CVIBuffer_Terrain::Initialize(void* pArg)
return S_OK;
}
void CVIBuffer_Terrain::ConvertToHeightField(const _tchar* pStaticKey)
{
vector<PSX::PxHeightFieldSample> pxSamples = {};
pxSamples.resize(m_iNumVerticesZ * m_iNumVerticesX);
for (_uint iRow = 0; iRow < m_iNumVerticesZ; ++iRow) {
for (_uint iCol = 0; iCol < m_iNumVerticesX; ++iCol) {
_uint iIndex = iRow * m_iNumVerticesZ + iCol;
_float fRealHeight = m_HeigthValues[iIndex];
PSX::PxI16 iClampHeight = (PSX::PxI16)(PSX::PxClamp(fRealHeight, -32767.f, 32767.f));
PSX::PxHeightFieldSample& pxSample = pxSamples[iIndex];
pxSample.height = iClampHeight;
pxSample.materialIndex0 = pxSample.materialIndex1 = 0;
pxSample.clearTessFlag();
}
}
PSX::PxHeightFieldDesc Desc{};
Desc.format = PSX::PxHeightFieldFormat::eS16_TM;
Desc.nbRows = m_iNumVerticesZ;
Desc.nbColumns = m_iNumVerticesX;
Desc.samples.data = pxSamples.data();
Desc.samples.stride = sizeof(PSX::PxHeightFieldSample);
Desc.convexEdgeThreshold = 0;
if (false == Desc.isValid()) {
assert(false);
}
else {
m_pGameInstance->RegistHeight(pStaticKey, Desc);
}
}
_bool CVIBuffer_Terrain::Picking(_fmatrix WorldMatrix, _float3* pOut)
{
_matrix WorldInv = XMMatrixInverse(nullptr, WorldMatrix);
@@ -193,6 +193,7 @@ class ENGINE_DLL CGameInstance final : public CBase
#pragma region PhysX_Manager
PSX::PxMaterial* Create_Material(_float3* vMatInfo);
void RegistTriMesh(const _char* pName, PSX::PxTriangleMesh* pPxTriMesh);
void RegistHeight(const _tchar* pName, PSX::PxHeightFieldDesc& Desc);
PSX::PxRigidDynamic* Add_DynamicActor(CRigidBody_Dynamic& RigidBody);
PSX::PxRigidStatic* Add_StaticActor(CRigidBody_Static& RigidBody);
PSX::PxRevoluteJoint* Create_PxRevoluteJoint(PSX::PxRigidActor* pActorFrame, PSX::PxTransform& pxLocalWallFrame, PSX::PxRigidActor* pActorObject, PSX::PxTransform& pxLocalActorFrame);
@@ -1,4 +1,4 @@
// Redistribution and use in source and binary forms, with or without
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// * Redistributions of source code must retain the above copyright
@@ -1,4 +1,4 @@
// Redistribution and use in source and binary forms, with or without
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// * Redistributions of source code must retain the above copyright
+7 -17
View File
@@ -27,6 +27,7 @@ class CPhysX_Manager final : public CBase
PSX::PxRevoluteJoint* Create_PxRevoluteJoint(PSX::PxRigidActor* pActorFrame, PSX::PxTransform& pxLocalWallFrame, PSX::PxRigidActor* pActorObject, PSX::PxTransform& pxLocalActorFrame);
void RegistTriMesh(const _char* pName, PSX::PxTriangleMesh* pPxTriMesh);
void RegistHeight(const _tchar* pName, PSX::PxHeightFieldDesc& Desc);
PSX::PxMaterial* Create_Material(const _float3* vMatInfo);
#ifdef EDITOR_PROJECT
@@ -36,6 +37,7 @@ class CPhysX_Manager final : public CBase
HRESULT LoadTriMeshes(const _char* pPath, vector<PSX::PxTriangleMesh*>& TriMeshes);
//HRESULT LoadTriMeshes_Binary(const _char* pPath, vector<PSX::PxTriangleMesh*>& TriMeshes);
PSX::PxTriangleMesh* Find_TriangleMesh(const _tchar* pMeshName);
PSX::PxHeightField* Find_HeightField(const _tchar* pFieldName);
void Update(_float fTimeDelta);
void ClearScene();
@@ -80,27 +82,15 @@ class CPhysX_Manager final : public CBase
unordered_set<PSX::PxActor*> m_pActiveBodys = { };
unordered_set<PSX::PxActor*> m_pRestBodies = { }; // 피직스의 액터로 구별되기 때문에 피직스액터 포인터를 키로 사용함
map<_wstring, PSX::PxTriangleMesh*> m_TriangleMeshes = {};
map<_wstring, PSX::PxTriangleMeshGeometry*> m_TriangleMeshGeometry = {};
#ifdef 기무리
map<_wstring, PSX::PxHeightField*> m_HeightFields = {};
map<_wstring, PSX::PxHeightFieldGeometry*> m_HeightFieldGeometry = {};
PhsXUserData PlaneData = {};
#endif // 기무리
#ifdef 진우
PhsXUserData PlaneData = {};
#endif // 기무리
#ifdef gimch
PhsXUserData PlaneData = {};
#endif // 기무리
#ifdef Bin
PhsXUserData PlaneData = {};
#endif // 기무리
vector<PSX::PxMaterial*> m_pMaterials = { };
_uint m_iNumLevel = {};
private:
@@ -14,7 +14,7 @@ class ENGINE_DLL CRigidBody_Static : public CRigidBody
}RIGIDBODY_STATIC_PROTOTYPEDESC;
typedef struct tagRigidBody_STATIC_Desc : public CRigidBody::RIGIDBODY_PROTOTYPEDESC
typedef struct tagRigidBody_STATIC_Desc : public CRigidBody::RIGIDBODY_DESC
{
const _tchar* pMeshName = { nullptr };
}RIGIDBODY_STATIC_DESC;
@@ -24,6 +24,7 @@ class ENGINE_DLL CVIBuffer_Terrain final : public CVIBuffer
#endif // EDITOR_PROJECT
virtual HRESULT Initialize_Prototype(const _char* pFilePath, _uint iSizeX, _uint iSizeZ);
virtual HRESULT Initialize(void* pArg);
void ConvertToHeightField(const _tchar* pStaticKey);
_bool Picking(_fmatrix WorldMatrix, _float3* pOut);
void Culling(_fmatrix WorldMatrix);