-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathConvexMeshResource.cpp
More file actions
47 lines (38 loc) · 1.49 KB
/
Copy pathConvexMeshResource.cpp
File metadata and controls
47 lines (38 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "ConvexMeshResource.h"
#include "PhysicsMathAdapter.h"
#include <vector>
ConvexMeshResource::ConvexMeshResource(physx::PxPhysics* physics, math::vector3* vertices, int vertexSize, int polygonLimit) : ResourceBase(EResourceType::CONVRX_MESH)
{
std::vector<physx::PxVec3> pxVertices;
pxVertices.reserve(static_cast<size_t>(vertexSize));
for (int index = 0; index < vertexSize; ++index)
{
pxVertices.push_back(PhysicsMath::ToPx(vertices[index]));
}
//컨벡스 매쉬 생성
physx::PxConvexMeshDesc convexDesc;
convexDesc.points.count = vertexSize;
convexDesc.points.stride = sizeof(physx::PxVec3);
convexDesc.vertexLimit = 255;
convexDesc.points.data = pxVertices.data();
convexDesc.polygonLimit = polygonLimit;
convexDesc.flags = physx::PxConvexFlag::eCOMPUTE_CONVEX;
physx::PxTolerancesScale scale;
physx::PxCookingParams params(scale);
params.meshPreprocessParams |= physx::PxMeshPreprocessingFlag::eDISABLE_CLEAN_MESH;
params.meshPreprocessParams |= physx::PxMeshPreprocessingFlag::eDISABLE_ACTIVE_EDGES_PRECOMPUTE;
physx::PxDefaultMemoryOutputStream writeBuffer;
physx::PxConvexMeshCookingResult::Enum result;
PxCookConvexMesh(params, convexDesc, writeBuffer, &result);
delete[] vertices; //할당된 버텍스 메모리 해제
physx::PxDefaultMemoryInputData Input(writeBuffer.getData(), writeBuffer.getSize());
m_convexMesh = physics->createConvexMesh(Input);
}
ConvexMeshResource::~ConvexMeshResource()
{
if (m_convexMesh != nullptr)
{
m_convexMesh->release();
m_convexMesh = nullptr;
}
}