21PhysxManager::PhysxOutputStream PhysxManager::_outputStream;
30 NxSDKCreateError error;
31 NxPhysicsSDKDesc desc = NxPhysicsSDKDesc();
33 _sdk = NxCreatePhysicsSDK(NX_PHYSICS_SDK_VERSION,
nullptr, &_outputStream, desc, &error);
35 if (error == NXCE_NO_ERROR) {
36 physx_cat.info() <<
"PhysX subsystem initialized. Number of PPUs="
37 << _sdk->getNbPPUs() << endl;
40 physx_cat.error() <<
"Error when setting up the PhysX subsystem: "
41 << get_sdk_error_string(error) << endl;
45 nassertv_always(error == NXCE_NO_ERROR);
46 nassertv_always(_sdk);
49 _sdk->setParameter(NX_VISUALIZATION_SCALE, 0.0f);
50 _sdk->setParameter(NX_VISUALIZE_COLLISION_SHAPES,
true);
51 _sdk->setParameter(NX_VISUALIZE_ACTOR_AXES,
true);
52 _sdk->setParameter(NX_VISUALIZE_BODY_LIN_VELOCITY,
true);
53 _sdk->setParameter(NX_VISUALIZE_COLLISION_AABBS,
false);
54 _sdk->setParameter(NX_VISUALIZE_COLLISION_VNORMALS,
false);
55 _sdk->setParameter(NX_VISUALIZE_COLLISION_FNORMALS,
false);
56 _sdk->setParameter(NX_VISUALIZE_FORCE_FIELDS,
false);
60 physx_cat.info() <<
"Connecting to visual remote debugger at ("
61 << physx_vrd_host <<
":"
62 << physx_vrd_port <<
")" << endl;
64 NxRemoteDebugger *debugger = _sdk->getFoundationSDK().getRemoteDebugger();
66 debugger->connect(physx_vrd_host.c_str(),
69 if (!debugger->isConnected()) {
70 physx_cat.warning() <<
"Could not connect to visual remot debugger!" << endl;
84 NxRemoteDebugger *debugger = _sdk->getFoundationSDK().getRemoteDebugger();
85 if (!debugger->isConnected()) {
86 debugger->disconnect();
91 NxReleasePhysicsSDK(_sdk);
100 if (_global_ptr ==
nullptr) {
104 if (_global_ptr->_sdk ==
nullptr) {
115unsigned int PhysxManager::
116get_num_scenes()
const {
118 return _sdk->getNbScenes();
127 nassertr(sceneDesc.
is_valid(),
nullptr);
132 sceneDesc._desc.flags |= NX_SF_ENABLE_ACTIVETRANSFORMS;
133 sceneDesc._desc.flags |= NX_SF_SIMULATE_SEPARATE_THREAD;
135 if (physx_internal_threads > 0) {
136 sceneDesc._desc.flags |= NX_SF_ENABLE_MULTITHREAD;
137 sceneDesc._desc.threadMask=0xfffffffe;
138 sceneDesc._desc.internalThreadCount = physx_internal_threads;
139 physx_cat.info() <<
"Multithreading enabled. "
140 <<
"Additional threads: " << physx_internal_threads << endl;
144 nassertr(scene,
nullptr);
146 NxScene *scenePtr = _sdk->createScene(sceneDesc._desc);
147 nassertr(scenePtr,
nullptr);
149 scene->link(scenePtr);
158get_scene(
unsigned int idx)
const {
160 nassertr_always(idx < _sdk->getNbScenes(),
nullptr);
162 NxScene *scenePtr = _sdk->getScene(idx);
171unsigned int PhysxManager::
172get_num_height_fields() {
174 return _sdk->getNbHeightFields();
186 nassertr(hf,
nullptr);
188 NxHeightField *hfPtr = _sdk->createHeightField(desc._desc);
189 nassertr(hfPtr,
nullptr);
200get_height_field(
unsigned int idx) {
202 nassertr_always(idx < _sdk->getNbHeightFields(),
nullptr);
210unsigned int PhysxManager::
211get_num_convex_meshes() {
213 return _sdk->getNbConvexMeshes();
220get_convex_mesh(
unsigned int idx) {
222 nassertr_always(idx < _sdk->getNbConvexMeshes(),
nullptr);
230unsigned int PhysxManager::
231get_num_triangle_meshes() {
233 return _sdk->getNbTriangleMeshes();
240get_triangle_mesh(
unsigned int idx) {
242 nassertr_always(idx < _sdk->getNbTriangleMeshes(),
nullptr);
250unsigned int PhysxManager::
251get_num_cloth_meshes() {
253 return _sdk->getNbClothMeshes();
260get_cloth_mesh(
unsigned int idx) {
262 nassertr_always(idx < _sdk->getNbClothMeshes(),
nullptr);
270unsigned int PhysxManager::
271get_num_soft_body_meshes() {
273 return _sdk->getNbSoftBodyMeshes();
280get_soft_body_mesh(
unsigned int idx) {
282 nassertr_always(idx < _sdk->getNbSoftBodyMeshes(),
nullptr);
290unsigned int PhysxManager::
291get_num_ccd_skeletons() {
293 return _sdk->getNbCCDSkeletons();
303 nassertr(desc.get_desc().numVertices < 64,
nullptr);
306 nassertr(skel,
nullptr);
308 NxCCDSkeleton *skelPtr = _sdk->createCCDSkeleton(desc.get_desc());
309 nassertr(skelPtr,
nullptr);
320get_ccd_skeleton(
unsigned int idx) {
322 nassertr_always(idx < _sdk->getNbCCDSkeletons(),
nullptr);
333 return _sdk->getHWVersion() != NX_HW_VERSION_NONE;
342 return _sdk->getNbPPUs();
353 return _sdk->getHWVersion();
367 v = _sdk->getInternalVersion(apiRev, descRev, branchId);
369 std::stringstream version;
370 version <<
"version:" << (
unsigned int)v
371 <<
" apiRef:" << (
unsigned int)apiRev
372 <<
" descRev:" << (
unsigned int)descRev
373 <<
" branchId: " << (
unsigned int)branchId;
375 return version.str().c_str();
382set_parameter(PhysxParameter param,
float value) {
384 _sdk->setParameter((NxParameter)param, value);
391get_parameter(PhysxParameter param) {
393 return _sdk->getParameter((NxParameter)param);
399const char *PhysxManager::
400get_sdk_error_string(
const NxSDKCreateError &error) {
403 case NXCE_NO_ERROR:
return "NXCE_NO_ERROR";
break;
404 case NXCE_PHYSX_NOT_FOUND:
return "NXCE_PHYSX_NOT_FOUND";
break;
405 case NXCE_WRONG_VERSION:
return "NXCE_WRONG_VERSION";
break;
406 case NXCE_DESCRIPTOR_INVALID:
return "NXCE_DESCRIPTOR_INVALID";
break;
407 case NXCE_CONNECTION_ERROR:
return "NXCE_CONNECTION_ERROR";
break;
408 case NXCE_RESET_ERROR:
return "NXCE_RESET_ERROR";
break;
409 case NXCE_IN_USE_ERROR:
return "NXCE_IN_USE_ERROR";
break;
410 case NXCE_BUNDLE_ERROR:
return "NXCE_BUNDLE_ERROR";
break;
411 default:
return "Unknown error";
break;
418void PhysxManager::PhysxOutputStream::
419reportError(NxErrorCode code,
const char *message,
const char *file,
int line) {
421 physx_cat.error() << get_error_code_string(code) <<
": "
428const char *PhysxManager::PhysxOutputStream::
429get_error_code_string(NxErrorCode code) {
432 case NXE_NO_ERROR:
return "NO_ERROR";
break;
433 case NXE_INVALID_PARAMETER:
return "INVALID_PARAMETER";
break;
434 case NXE_INVALID_OPERATION:
return "INVALID_OPERATION";
break;
435 case NXE_OUT_OF_MEMORY:
return "OUT_OF_MEMORY";
break;
436 case NXE_INTERNAL_ERROR:
return "INTERNAL_ERROR";
break;
437 case NXE_ASSERTION:
return "ASSERTION";
break;
438 case NXE_DB_INFO:
return "DB_INFO";
break;
439 case NXE_DB_WARNING:
return "DB_WARNING";
break;
440 case NXE_DB_PRINT:
return "DB_PRINT";
break;
441 default:
return "";
break;
448NxAssertResponse PhysxManager::PhysxOutputStream::
449reportAssertViolation(
const char *message,
const char *file,
int line) {
451 physx_cat.error() <<
"AssertViolation: " << message << endl;
453 return NX_AR_CONTINUE;
459void PhysxManager::PhysxOutputStream::
460print(
const char *message) {
bool is_valid() const
Returns true if the descriptor is valid.
Descriptor class for height fields.
bool is_valid() const
Returns true if the descriptor is valid.
The central interface to the PhysX subsystem.
unsigned int get_hw_version()
Reports the available revision of the PhysX Hardware.
const char * get_internal_version()
Reports the internal API version number of the SDK.
static PhysxManager * get_global_ptr()
Returns a pointer to the global PhysxManager object.
bool is_hardware_available()
Returns TRUE if a physcis hardware is available on the host system.
unsigned int get_num_ppus()
Reports the number of PPUs installed in the host system.
Descriptor for PhysxScene.
bool is_valid() const
Returns true if the descriptor is valid.
A scene is a collection of bodies, constraints, and effectors which can interact.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.