physx 5.x fix
This commit is contained in:
parent
a168f51fbd
commit
48405abaff
@ -11,8 +11,10 @@ PxDefaultAllocator Physics::s_default_allocator_cb;
|
||||
|
||||
PxFoundation* Physics::s_foundation = nullptr;
|
||||
PxPhysics* Physics::s_physics = nullptr;
|
||||
PxCooking* Physics::s_cooking = nullptr;
|
||||
//PxCooking* Physics::s_cooking = nullptr;
|
||||
PxPvd* Physics::s_pvd = nullptr;
|
||||
PxTolerancesScale Physics::s_scale;
|
||||
PxCookingParams Physics::s_cooking_params(s_scale);
|
||||
|
||||
void Physics::Init() {
|
||||
// PHYSX init
|
||||
@ -29,29 +31,36 @@ void Physics::Init() {
|
||||
//PxPvdTransport* transport = PxDefaultPvdSocketTransportCreate("localhost", 5425, 10);
|
||||
//mPvd->connect(*transport, PxPvdInstrumentationFlag::eALL);
|
||||
|
||||
PxTolerancesScale scale;
|
||||
//PxTolerancesScale scale;
|
||||
|
||||
s_physics = PxCreatePhysics(PX_PHYSICS_VERSION, *s_foundation, scale, recordMemoryAllocations, nullptr);
|
||||
s_physics = PxCreatePhysics(PX_PHYSICS_VERSION, *s_foundation, s_scale, recordMemoryAllocations, nullptr);
|
||||
if (!s_physics)
|
||||
Throw("(PX) PxCreatePhysics failed!");
|
||||
|
||||
s_cooking = PxCreateCooking(PX_PHYSICS_VERSION, *s_foundation, PxCookingParams(scale));
|
||||
if (!s_cooking)
|
||||
Throw("(PX) PxCreateCooking failed!");
|
||||
//s_cooking = PxCreateCooking(PX_PHYSICS_VERSION, *s_foundation, PxCookingParams(scale));
|
||||
//if (!s_cooking)
|
||||
// Throw("(PX) PxCreateCooking failed!");
|
||||
|
||||
PxCookingParams params(scale);
|
||||
s_cooking->setParams(params);
|
||||
//PxCookingParams params(scale);
|
||||
//s_cooking->setParams(params);
|
||||
|
||||
PxInitVehicleSDK(*s_physics);
|
||||
PxVehicleSetBasisVectors(PxVec3(0, 1, 0), PxVec3(0, 0, 1));
|
||||
PxVehicleSetUpdateMode(PxVehicleUpdateMode::eVELOCITY_CHANGE);
|
||||
}
|
||||
|
||||
void Physics::Close() {
|
||||
if (s_cooking)
|
||||
s_cooking->release();
|
||||
PxCloseVehicleSDK();
|
||||
|
||||
//if (s_cooking)
|
||||
// s_cooking->release();
|
||||
|
||||
if (s_physics)
|
||||
s_physics->release();
|
||||
|
||||
if (s_foundation)
|
||||
s_foundation->release();
|
||||
|
||||
}
|
||||
|
||||
PhysicsScene::PhysicsScene() {
|
||||
@ -178,14 +187,24 @@ PhysicsTriangleMesh::PhysicsTriangleMesh(const std::string& path) {
|
||||
mesh_desc.triangles.stride = 3 * sizeof(PxU32);
|
||||
mesh_desc.triangles.data = mia3.indices_ptr;
|
||||
|
||||
#ifdef _DEBUG
|
||||
// mesh should be validated before cooked without the mesh cleaning
|
||||
bool res = Physics::GetCooking()->validateTriangleMesh(mesh_desc);
|
||||
PX_ASSERT(res);
|
||||
#endif
|
||||
//#ifdef _DEBUG
|
||||
// // mesh should be validated before cooked without the mesh cleaning
|
||||
// bool res = Physics::GetCooking()->validateTriangleMesh(mesh_desc);
|
||||
// PX_ASSERT(res);
|
||||
//#endif
|
||||
|
||||
m_mesh = Physics::GetCooking()->createTriangleMesh(mesh_desc, Physics::GetPhysics()->getPhysicsInsertionCallback());
|
||||
}
|
||||
//m_mesh = Physics::GetCooking()->createTriangleMesh(mesh_desc, Physics::GetPhysics()->getPhysicsInsertionCallback());
|
||||
//PxCookTriangleMesh(Physics::GetCookingParams(), mesh_desc, Physics::GetPhysics()->getPhysicsInsertionCallback());
|
||||
|
||||
PxDefaultMemoryOutputStream writeBuffer;
|
||||
PxTriangleMeshCookingResult::Enum result;
|
||||
bool status = PxCookTriangleMesh(Physics::GetCookingParams(), mesh_desc, writeBuffer, &result);
|
||||
if (!status)
|
||||
Throw("Cant cook triangle mesh");
|
||||
|
||||
PxDefaultMemoryInputData readBuffer(writeBuffer.getData(), writeBuffer.getSize());
|
||||
m_mesh = Physics::GetPhysics()->createTriangleMesh(readBuffer);
|
||||
};
|
||||
|
||||
PhysicsTriangleMesh::~PhysicsTriangleMesh() {
|
||||
m_mesh->release();
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
#pragma once
|
||||
#include <PxPhysics.h>
|
||||
#include <PxFoundation.h>
|
||||
#include <PxConfig.h>
|
||||
#include <PxPhysicsAPI.h>
|
||||
#include <PxFiltering.h>
|
||||
#include <physx/PxPhysics.h>
|
||||
//#include <physx/PxFoundation.h>
|
||||
#include <physx/PxConfig.h>
|
||||
#include <physx/PxPhysicsAPI.h>
|
||||
#include <physx/PxFiltering.h>
|
||||
#include "tsr.hpp"
|
||||
#include "assets.hpp"
|
||||
#include "renderer.hpp"
|
||||
@ -18,14 +18,18 @@ namespace TSR {
|
||||
|
||||
static PxFoundation* s_foundation;
|
||||
static PxPhysics* s_physics;
|
||||
static PxCooking* s_cooking;
|
||||
//static PxCooking* s_cooking;
|
||||
static PxPvd* s_pvd;
|
||||
|
||||
static PxTolerancesScale s_scale;
|
||||
static PxCookingParams s_cooking_params;
|
||||
public:
|
||||
static void Init();
|
||||
static void Close();
|
||||
|
||||
static PxPhysics* GetPhysics() { return s_physics; }
|
||||
static PxCooking* GetCooking() { return s_cooking; }
|
||||
static const PxCookingParams& GetCookingParams() { return s_cooking_params; }
|
||||
//static PxCooking* GetCooking() { return s_cooking; }
|
||||
};
|
||||
|
||||
class PhysicsScene {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user