15 #include "physxManager.h"
16 #include "physxScene.h"
17 #include "physxSceneDesc.h"
20 PhysxManager::PhysxOutputStream PhysxManager::_outputStream;
31 NxSDKCreateError error;
32 NxPhysicsSDKDesc desc = NxPhysicsSDKDesc();
34 _sdk = NxCreatePhysicsSDK(NX_PHYSICS_SDK_VERSION, NULL, &_outputStream, desc, &error);
36 if (error == NXCE_NO_ERROR) {
37 physx_cat.info() <<
"PhysX subsystem initialized. Number of PPUs="
38 << _sdk->getNbPPUs() << endl;
41 physx_cat.error() <<
"Error when setting up the PhysX subsystem: "
42 << get_sdk_error_string(error) << endl;
46 nassertv_always(error == NXCE_NO_ERROR);
47 nassertv_always(_sdk);
50 _sdk->setParameter(NX_VISUALIZATION_SCALE, 0.0f);
51 _sdk->setParameter(NX_VISUALIZE_COLLISION_SHAPES,
true);
52 _sdk->setParameter(NX_VISUALIZE_ACTOR_AXES,
true);
53 _sdk->setParameter(NX_VISUALIZE_BODY_LIN_VELOCITY,
true);
54 _sdk->setParameter(NX_VISUALIZE_COLLISION_AABBS,
false);
55 _sdk->setParameter(NX_VISUALIZE_COLLISION_VNORMALS,
false);
56 _sdk->setParameter(NX_VISUALIZE_COLLISION_FNORMALS,
false);
57 _sdk->setParameter(NX_VISUALIZE_FORCE_FIELDS,
false);
61 physx_cat.info() <<
"Connecting to visual remote debugger at ("
62 << physx_vrd_host <<
":"
63 << physx_vrd_port <<
")" << endl;
65 NxRemoteDebugger *debugger = _sdk->getFoundationSDK().getRemoteDebugger();
67 debugger->connect(physx_vrd_host.c_str(),
70 if (!debugger->isConnected()) {
71 physx_cat.warning() <<
"Could not connect to visual remot debugger!" << endl;
87 NxRemoteDebugger *debugger = _sdk->getFoundationSDK().getRemoteDebugger();
88 if (!debugger->isConnected()) {
89 debugger->disconnect();
94 NxReleasePhysicsSDK(_sdk);
110 if (_global_ptr->_sdk == NULL) {
123 unsigned int PhysxManager::
124 get_num_scenes()
const {
126 return _sdk->getNbScenes();
137 nassertr(sceneDesc.
is_valid(),NULL);
143 sceneDesc._desc.flags |= NX_SF_ENABLE_ACTIVETRANSFORMS;
144 sceneDesc._desc.flags |= NX_SF_SIMULATE_SEPARATE_THREAD;
146 if (physx_internal_threads > 0) {
147 sceneDesc._desc.flags |= NX_SF_ENABLE_MULTITHREAD;
148 sceneDesc._desc.threadMask=0xfffffffe;
149 sceneDesc._desc.internalThreadCount = physx_internal_threads;
150 physx_cat.info() <<
"Multithreading enabled. "
151 <<
"Additional threads: " << physx_internal_threads << endl;
155 nassertr(scene, NULL);
157 NxScene *scenePtr = _sdk->createScene(sceneDesc._desc);
158 nassertr(scenePtr, NULL);
160 scene->link(scenePtr);
171 get_scene(
unsigned int idx)
const {
173 nassertr_always(idx < _sdk->getNbScenes(), NULL);
175 NxScene *scenePtr = _sdk->getScene(idx);
186 unsigned int PhysxManager::
187 get_num_height_fields() {
189 return _sdk->getNbHeightFields();
205 NxHeightField *hfPtr = _sdk->createHeightField(desc._desc);
206 nassertr(hfPtr, NULL);
219 get_height_field(
unsigned int idx) {
221 nassertr_always(idx < _sdk->getNbHeightFields(), NULL);
231 unsigned int PhysxManager::
232 get_num_convex_meshes() {
234 return _sdk->getNbConvexMeshes();
243 get_convex_mesh(
unsigned int idx) {
245 nassertr_always(idx < _sdk->getNbConvexMeshes(), NULL);
255 unsigned int PhysxManager::
256 get_num_triangle_meshes() {
258 return _sdk->getNbTriangleMeshes();
267 get_triangle_mesh(
unsigned int idx) {
269 nassertr_always(idx < _sdk->getNbTriangleMeshes(), NULL);
279 unsigned int PhysxManager::
280 get_num_cloth_meshes() {
282 return _sdk->getNbClothMeshes();
291 get_cloth_mesh(
unsigned int idx) {
293 nassertr_always(idx < _sdk->getNbClothMeshes(), NULL);
303 unsigned int PhysxManager::
304 get_num_soft_body_meshes() {
306 return _sdk->getNbSoftBodyMeshes();
315 get_soft_body_mesh(
unsigned int idx) {
317 nassertr_always(idx < _sdk->getNbSoftBodyMeshes(), NULL);
327 unsigned int PhysxManager::
328 get_num_ccd_skeletons() {
330 return _sdk->getNbCCDSkeletons();
342 nassertr(desc.get_desc().numVertices < 64, NULL);
345 nassertr(skel, NULL);
347 NxCCDSkeleton *skelPtr = _sdk->createCCDSkeleton(desc.get_desc());
348 nassertr(skelPtr, NULL);
361 get_ccd_skeleton(
unsigned int idx) {
363 nassertr_always(idx < _sdk->getNbCCDSkeletons(), NULL);
377 return _sdk->getHWVersion() != NX_HW_VERSION_NONE;
389 return _sdk->getNbPPUs();
403 return _sdk->getHWVersion();
419 v = _sdk->getInternalVersion(apiRev, descRev, branchId);
422 version <<
"version:" << (
unsigned int)v
423 <<
" apiRef:" << (
unsigned int)apiRev
424 <<
" descRev:" << (
unsigned int)descRev
425 <<
" branchId: " << (
unsigned int)branchId;
427 return version.str().c_str();
436 set_parameter(PhysxParameter param,
float value) {
438 _sdk->setParameter((NxParameter)param, value);
447 get_parameter(PhysxParameter param) {
449 return _sdk->getParameter((NxParameter)param);
457 const char *PhysxManager::
458 get_sdk_error_string(
const NxSDKCreateError &error) {
461 case NXCE_NO_ERROR:
return "NXCE_NO_ERROR";
break;
462 case NXCE_PHYSX_NOT_FOUND:
return "NXCE_PHYSX_NOT_FOUND";
break;
463 case NXCE_WRONG_VERSION:
return "NXCE_WRONG_VERSION";
break;
464 case NXCE_DESCRIPTOR_INVALID:
return "NXCE_DESCRIPTOR_INVALID";
break;
465 case NXCE_CONNECTION_ERROR:
return "NXCE_CONNECTION_ERROR";
break;
466 case NXCE_RESET_ERROR:
return "NXCE_RESET_ERROR";
break;
467 case NXCE_IN_USE_ERROR:
return "NXCE_IN_USE_ERROR";
break;
468 case NXCE_BUNDLE_ERROR:
return "NXCE_BUNDLE_ERROR";
break;
469 default:
return "Unknown error";
break;
478 void PhysxManager::PhysxOutputStream::
479 reportError(NxErrorCode code,
const char *message,
const char *file,
int line) {
481 physx_cat.error() << get_error_code_string(code) <<
": "
490 const char *PhysxManager::PhysxOutputStream::
491 get_error_code_string(NxErrorCode code) {
494 case NXE_NO_ERROR:
return "NO_ERROR";
break;
495 case NXE_INVALID_PARAMETER:
return "INVALID_PARAMETER";
break;
496 case NXE_INVALID_OPERATION:
return "INVALID_OPERATION";
break;
497 case NXE_OUT_OF_MEMORY:
return "OUT_OF_MEMORY";
break;
498 case NXE_INTERNAL_ERROR:
return "INTERNAL_ERROR";
break;
499 case NXE_ASSERTION:
return "ASSERTION";
break;
500 case NXE_DB_INFO:
return "DB_INFO";
break;
501 case NXE_DB_WARNING:
return "DB_WARNING";
break;
502 case NXE_DB_PRINT:
return "DB_PRINT";
break;
503 default:
return "";
break;
512 NxAssertResponse PhysxManager::PhysxOutputStream::
513 reportAssertViolation(
const char *message,
const char *file,
int line) {
515 physx_cat.error() <<
"AssertViolation: " << message << endl;
517 return NX_AR_CONTINUE;
525 void PhysxManager::PhysxOutputStream::
526 print(
const char *message) {
Descriptor for PhysxScene.
The central interface to the PhysX subsystem.
static PhysxManager * get_global_ptr()
Returns a pointer to the global PhysxManager object.
A scene is a collection of bodies, constraints, and effectors which can interact. ...
bool is_hardware_available()
Returns TRUE if a physcis hardware is available on the host system.
unsigned int get_hw_version()
Reports the available revision of the PhysX Hardware.
Descriptor class for height fields.
bool is_valid() const
Returns true if the descriptor is valid.
unsigned int get_num_ppus()
Reports the number of PPUs installed in the host system.
bool is_valid() const
Returns true if the descriptor is valid.
bool is_valid() const
Returns true if the descriptor is valid.
const char * get_internal_version()
Reports the internal API version number of the SDK.