31 PStatCollector PhysxScene::_pcollector_fetch_results(
"App:PhysX:Fetch Results");
32 PStatCollector PhysxScene::_pcollector_update_transforms(
"App:PhysX:Update Transforms");
33 PStatCollector PhysxScene::_pcollector_debug_renderer(
"App:PhysX:Debug Renderer");
34 PStatCollector PhysxScene::_pcollector_simulate(
"App:PhysX:Simulate");
36 PStatCollector PhysxScene::_pcollector_softbody(
"App:PhysX:Softbody");
42 link(NxScene *scenePtr) {
46 _ptr->userData =
this;
50 _cm = NxCreateControllerManager(NxGetPhysicsSDKAllocator());
54 NxMaterial *materials[5];
57 while (NxU32 i=_ptr->getMaterialArray(materials, 5, iterator)) {
60 material->link(materials[i]);
72 for (
unsigned int i=0; i < _vehicles.size(); i++) {
73 _vehicles[i]->release();
77 NxU32 nControllers = _cm->getNbControllers();
79 for (NxU32 i=0; i < nControllers; i++) {
80 NxController *controllerPtr = _cm->getController(i);
86 NxActor **actors = _ptr->getActors();
87 NxU32 nActors = _ptr->getNbActors();
89 for (NxU32 i=0; i < nActors; i++) {
99 NxU32 nJoints = _ptr->getNbJoints();
101 _ptr->resetJointIterator();
102 for (NxU32 i=0; i < nJoints; i++) {
103 NxJoint *jointPtr = _ptr->getNextJoint();
109 NxForceField **fields = _ptr->getForceFields();
110 NxU32 nFields = _ptr->getNbForceFields();
112 for (NxU32 i=0; i < nFields; i++) {
118 NxU32 nGroups = _ptr->getNbForceFieldShapeGroups();
120 _ptr->resetForceFieldShapeGroupsIterator();
121 for (NxU32 i=0; i < nGroups; i++) {
122 NxForceFieldShapeGroup *groupPtr = _ptr->getNextForceFieldShapeGroup();
128 NxCloth **cloths = _ptr->getCloths();
129 NxU32 nCloths = _ptr->getNbCloths();
131 for (NxU32 i=0; i < nCloths; i++) {
137 NxSoftBody **softbodies = _ptr->getSoftBodies();
138 NxU32 nSoftbodies = _ptr->getNbSoftBodies();
140 for (NxU32 i=0; i < nSoftbodies; i++) {
146 NxMaterial *materials[5];
149 while (NxU32 i=_ptr->getMaterialArray(materials, 5, iterator)) {
157 _cm->purgeControllers();
158 NxReleaseControllerManager(_cm);
160 _ptr->userData =
nullptr;
161 _error_type = ET_released;
172 nassertv(_error_type == ET_ok);
175 NxPhysicsSDK *sdk = NxGetPhysicsSDK();
176 sdk->releaseScene(*_ptr);
191 nassertv(_error_type == ET_ok);
193 _pcollector_simulate.start();
196 for (
unsigned int i=0; i < _vehicles.size(); i++) {
198 vehicle->update_vehicle(dt);
202 for (NxU32 i=0; i < _cm->getNbControllers(); i++) {
203 NxController *controllerPtr = _cm->getController(i);
205 controller->update_controller(dt);
208 _cm->updateControllers();
214 _pcollector_simulate.stop();
228 nassertv(_error_type == ET_ok);
229 nassertv(_ptr !=
nullptr);
231 _pcollector_fetch_results.start();
232 _ptr->fetchResults(NX_RIGID_BODY_FINISHED,
true);
233 _pcollector_fetch_results.stop();
236 _pcollector_update_transforms.start();
238 NxU32 nbTransforms = 0;
239 NxActiveTransform *activeTransforms = _ptr->getActiveTransforms(nbTransforms);
241 if (nbTransforms && activeTransforms) {
242 for (NxU32 i=0; i<nbTransforms; ++i) {
246 void *userData = activeTransforms[i].userData;
254 _pcollector_update_transforms.stop();
257 _pcollector_debug_renderer.start();
258 _debugNode->update(_ptr);
259 _pcollector_debug_renderer.stop();
261 nassertv(_ptr->isWritable());
264 _pcollector_cloth.start();
266 NxCloth **cloths = _ptr->getCloths();
267 for (NxU32 i=0; i < _ptr->getNbCloths(); i++) {
272 _pcollector_cloth.stop();
275 _pcollector_softbody.start();
277 NxSoftBody **softbodies = _ptr->getSoftBodies();
278 for (NxU32 i=0; i < _ptr->getNbSoftBodies(); i++) {
283 _pcollector_softbody.stop();
292 nassertv(_error_type == ET_ok);
293 _ptr->setTiming(0, 0, NX_TIMESTEP_VARIABLE);
311 nassertv(_error_type == ET_ok);
312 _ptr->setTiming(maxTimestep, maxIter, NX_TIMESTEP_FIXED);
321 nassertv(_error_type == ET_ok);
322 nassertv_always(!gravity.is_nan());
333 nassertr(_error_type == ET_ok, LVector3f::zero());
336 _ptr->getGravity(gravity);
343 unsigned int PhysxScene::
344 get_num_actors()
const {
346 nassertr(_error_type == ET_ok,-1);
348 return _ptr->getNbActors();
357 nassertr(_error_type == ET_ok,
nullptr);
361 nassertr(actor,
nullptr);
363 NxActor *actorPtr = _ptr->createActor(desc._desc);
364 nassertr(actorPtr,
nullptr);
366 actor->link(actorPtr);
375 get_actor(
unsigned int idx)
const {
377 nassertr(_error_type == ET_ok,
nullptr);
378 nassertr_always(idx < _ptr->getNbActors(),
nullptr);
380 NxActor *actorPtr = _ptr->getActors()[idx];
398 nassertr(_error_type == ET_ok,
nullptr);
406 enable_contact_reporting(
bool enabled) {
408 nassertv(_error_type == ET_ok);
411 _ptr->setUserContactReport(&_contact_report);
412 _contact_report.enable();
415 _ptr->setUserContactReport(
nullptr);
416 _contact_report.disable();
424 is_contact_reporting_enabled()
const {
426 nassertr(_error_type == ET_ok,
false);
428 return _contact_report.is_enabled();
435 enable_trigger_reporting(
bool enabled) {
437 nassertv(_error_type == ET_ok);
440 _ptr->setUserTriggerReport(&_trigger_report);
441 _trigger_report.enable();
444 _ptr->setUserTriggerReport(
nullptr);
445 _trigger_report.disable();
453 is_trigger_reporting_enabled()
const {
455 nassertr(_error_type == ET_ok,
false);
457 return _trigger_report.is_enabled();
464 enable_controller_reporting(
bool enabled) {
466 nassertv(_error_type == ET_ok);
469 _controller_report.enable();
472 _controller_report.disable();
480 is_controller_reporting_enabled()
const {
482 nassertr(_error_type == ET_ok,
false);
484 return _controller_report.is_enabled();
498 nassertr(_error_type == ET_ok, -1);
499 return _ptr->getNbMaterials();
513 nassertr(_error_type == ET_ok,
nullptr);
517 nassertr(material,
nullptr);
519 NxMaterial *materialPtr = _ptr->createMaterial(desc._desc);
520 nassertr(materialPtr,
nullptr);
522 material->link(materialPtr);
534 nassertr(_error_type == ET_ok,
nullptr);
537 nassertr(material,
nullptr);
541 NxMaterial *materialPtr = _ptr->createMaterial(desc);
542 nassertr(materialPtr,
nullptr);
544 material->link(materialPtr);
558 nassertr(_error_type == ET_ok, -1);
559 return _ptr->getHighestMaterialIndex();
573 nassertr(_error_type == ET_ok,
nullptr);
575 NxMaterial *materialPtr = _ptr->getMaterialFromIndex(idx);
587 nassertr(_error_type == ET_ok,
nullptr);
588 nassertr_always(idx < _ptr->getNbMaterials(),
nullptr);
590 NxU32 n = _ptr->getNbMaterials();
591 NxMaterial **materials =
new NxMaterial *[n];
595 materialCount = _ptr->getMaterialArray(materials, n, iterator);
596 nassertr((materialCount == n),
nullptr);
598 NxMaterial *materialPtr = materials[idx];
610 nassertr(_error_type == ET_ok, -1);
611 return _cm->getNbControllers();
621 nassertr(_error_type == ET_ok,
nullptr);
622 nassertr(desc.is_valid(),
nullptr);
624 PhysxController *controller = PhysxController::factory(desc.ptr()->getType());
625 nassertr(controller,
nullptr);
627 desc.ptr()->callback = &_controller_report;
628 desc.ptr()->userData = controller;
630 NxController *controllerPtr = _cm->createController(_ptr,*desc.ptr());
631 nassertr(controllerPtr,
nullptr);
633 controller->link(controllerPtr);
645 nassertr(_error_type == ET_ok,
nullptr);
646 nassertr_always(idx < _cm->getNbControllers(),
nullptr);
648 NxController *controllerPtr = _cm->getController(idx);
661 nassertr(_error_type == ET_ok, -1);
662 return _ptr->getNbJoints();
671 nassertr(_error_type == ET_ok,
nullptr);
672 nassertr(desc.is_valid(),
nullptr);
674 PhysxJoint *joint = PhysxJoint::factory(desc.ptr()->getType());
675 nassertr(joint,
nullptr);
677 NxJoint *jointPtr = _ptr->createJoint(*desc.ptr());
678 nassertr(jointPtr,
nullptr);
680 joint->link(jointPtr);
691 nassertr(_error_type == ET_ok,
nullptr);
692 nassertr_always(idx < _ptr->getNbJoints(),
nullptr);
695 NxU32 nJoints = _ptr->getNbJoints();
697 _ptr->resetJointIterator();
698 for (NxU32 i=0; i <= idx; i++) {
699 jointPtr = _ptr->getNextJoint();
711 nassertr(_error_type == ET_ok, -1);
712 return _ptr->getNbForceFields();
721 nassertr(_error_type == ET_ok,
nullptr);
724 desc.create_kernel(_ptr);
729 nassertr(field,
nullptr);
731 NxForceField *fieldPtr = _ptr->createForceField(desc._desc);
732 nassertr(fieldPtr,
nullptr);
734 field->link(fieldPtr);
746 nassertr(_error_type == ET_ok,
nullptr);
747 nassertr_always(idx < _ptr->getNbForceFields(),
nullptr);
749 NxForceField **fields = _ptr->getForceFields();
750 NxForceField *fieldPtr = fields[idx];
761 nassertr(_error_type == ET_ok, -1);
762 return _ptr->getNbForceFieldShapeGroups();
771 nassertr(_error_type == ET_ok,
nullptr);
774 nassertr(group,
nullptr);
776 NxForceFieldShapeGroup *groupPtr = _ptr->createForceFieldShapeGroup(desc._desc);
777 nassertr(groupPtr,
nullptr);
779 group->link(groupPtr);
790 nassertr(_error_type == ET_ok,
nullptr);
791 nassertr_always(idx < _ptr->getNbForceFieldShapeGroups(),
nullptr);
793 _ptr->resetForceFieldShapeGroupsIterator();
794 NxForceFieldShapeGroup *groupPtr =
nullptr;
797 groupPtr = _ptr->getNextForceFieldShapeGroup();
809 nassertr(_error_type == ET_ok, -1);
810 return _ptr->getNbCloths();
819 nassertr(_error_type == ET_ok,
nullptr);
822 nassertr(cloth,
nullptr);
824 NxCloth *clothPtr = _ptr->createCloth(desc._desc);
825 nassertr(clothPtr,
nullptr);
827 cloth->link(clothPtr);
838 nassertr(_error_type == ET_ok,
nullptr);
839 nassertr_always(idx < _ptr->getNbCloths(),
nullptr);
841 NxCloth **cloths = _ptr->getCloths();
842 NxCloth *clothPtr = cloths[idx];
853 nassertr(_error_type == ET_ok, -1);
854 return _ptr->getNbSoftBodies();
863 nassertr(_error_type == ET_ok,
nullptr);
866 nassertr(softbody,
nullptr);
868 NxSoftBody *softbodyPtr = _ptr->createSoftBody(desc._desc);
869 nassertr(softbodyPtr,
nullptr);
871 softbody->link(softbodyPtr);
883 nassertr(_error_type == ET_ok,
nullptr);
884 nassertr_always(idx < _ptr->getNbSoftBodies(),
nullptr);
886 NxSoftBody **softbodies = _ptr->getSoftBodies();
887 NxSoftBody *softbodyPtr = softbodies[idx];
898 nassertr(_error_type == ET_ok, -1);
899 return _vehicles.size();
908 nassertr(_error_type == ET_ok,
nullptr);
912 nassertr(vehicle,
nullptr);
914 vehicle->create(
this, desc);
925 nassertr(_error_type == ET_ok,
nullptr);
926 nassertr_always(idx < _vehicles.size(),
nullptr);
928 return _vehicles[idx];
937 nassertr(_error_type == ET_ok,
nullptr);
946 PhysxShapesType shapesType,
950 nassertr(_error_type == ET_ok,
false);
952 NxGroupsMask *groupsPtr = groups ? &(groups->_mask) :
nullptr;
954 return _ptr->raycastAnyShape(ray._ray, (NxShapesType)shapesType,
955 mask.get_mask(), ray._length, groupsPtr);
964 PhysxShapesType shapesType,
970 nassertr(_error_type == ET_ok, hit);
972 NxGroupsMask *groupsPtr = groups ? &(groups->_mask) :
nullptr;
974 NxU32 hints = NX_RAYCAST_SHAPE | NX_RAYCAST_IMPACT | NX_RAYCAST_DISTANCE;
975 if (smoothNormal ==
true) {
976 hints |= NX_RAYCAST_NORMAL;
979 hints |= NX_RAYCAST_FACE_NORMAL;
982 _ptr->raycastClosestShape(ray._ray, (NxShapesType)shapesType, hit,
983 mask.get_mask(), ray._length, hints, groupsPtr);
995 PhysxShapesType shapesType,
1001 nassertr(_error_type == ET_ok, report);
1003 NxGroupsMask *groupsPtr = groups ? &(groups->_mask) :
nullptr;
1005 NxU32 hints = NX_RAYCAST_SHAPE | NX_RAYCAST_IMPACT | NX_RAYCAST_DISTANCE;
1006 if (smoothNormal ==
true) {
1007 hints |= NX_RAYCAST_NORMAL;
1010 hints |= NX_RAYCAST_FACE_NORMAL;
1013 _ptr->raycastAllShapes(ray._ray, report, (NxShapesType)shapesType,
1014 mask.get_mask(), ray._length, hints, groupsPtr);
1025 PhysxShapesType shapesType,
1029 nassertr(_error_type == ET_ok,
false);
1031 NxGroupsMask *groupsPtr = groups ? &(groups->_mask) :
nullptr;
1033 return _ptr->raycastAnyBounds(ray._ray, (NxShapesType)shapesType,
1034 mask.get_mask(), ray._length, groupsPtr);
1047 nassertr(_error_type == ET_ok, hit);
1049 NxGroupsMask *groupsPtr = groups ? &(groups->_mask) :
nullptr;
1051 NxU32 hints = NX_RAYCAST_SHAPE | NX_RAYCAST_IMPACT | NX_RAYCAST_DISTANCE;
1052 if (smoothNormal ==
true) {
1053 hints |= NX_RAYCAST_NORMAL;
1056 hints |= NX_RAYCAST_FACE_NORMAL;
1059 _ptr->raycastClosestBounds(ray._ray, (NxShapesType)shapesType, hit,
1060 mask.get_mask(), ray._length, hints, groupsPtr);
1073 PhysxShapesType shapesType,
1079 nassertr(_error_type == ET_ok, report);
1081 NxGroupsMask *groupsPtr = groups ? &(groups->_mask) :
nullptr;
1083 NxU32 hints = NX_RAYCAST_SHAPE | NX_RAYCAST_IMPACT | NX_RAYCAST_DISTANCE;
1084 if (smoothNormal ==
true) {
1085 hints |= NX_RAYCAST_NORMAL;
1088 hints |= NX_RAYCAST_FACE_NORMAL;
1091 _ptr->raycastAllBounds(ray._ray, report, (NxShapesType)shapesType,
1092 mask.get_mask(), ray._length, hints, groupsPtr);
1103 PhysxShapesType shapesType,
1104 PhysxMask mask,
bool accurateCollision)
const {
1108 nassertr(_error_type == ET_ok, report);
1112 _ptr->overlapSphereShapes(worldSphere, (NxShapesType)shapesType, 0,
nullptr, &report,
1113 mask.get_mask(),
nullptr, accurateCollision);
1124 PhysxShapesType shapesType,
1125 PhysxMask mask,
bool accurateCollision)
const {
1129 nassertr(_error_type == ET_ok, report);
1133 NxCapsule worldCapsule(segment, radius);
1135 _ptr->overlapCapsuleShapes(worldCapsule, (NxShapesType)shapesType, 0,
nullptr, &report,
1136 mask.get_mask(),
nullptr, accurateCollision);
1153 PhysxContactPairFlag flag,
bool value) {
1155 nassertv(_error_type == ET_ok);
1157 NxActor *ptrA = actorA.ptr();
1158 NxActor *ptrB = actorB.ptr();
1159 NxU32 flags = _ptr->getActorPairFlags(*ptrA, *ptrB);
1161 if (value ==
true) {
1168 _ptr->setActorPairFlags(*ptrA, *ptrB, flags);
1178 PhysxContactPairFlag flag) {
1180 nassertr(_error_type == ET_ok,
false);
1182 NxActor *ptrA = actorA.ptr();
1183 NxActor *ptrB = actorB.ptr();
1184 NxU32 flags = _ptr->getActorPairFlags(*ptrA, *ptrB);
1186 return (flags && flag) ? true :
false;
1197 nassertv(_error_type == ET_ok);
1199 NxShape *ptrA = shapeA.ptr();
1200 NxShape *ptrB = shapeB.ptr();
1201 NxU32 flags = _ptr->getShapePairFlags(*ptrA, *ptrB);
1203 if (value ==
true) {
1204 flags |= NX_IGNORE_PAIR;
1207 flags &= ~(NX_IGNORE_PAIR);
1210 _ptr->setShapePairFlags(*ptrA, *ptrB, flags);
1222 nassertr(_error_type == ET_ok,
false);
1224 NxShape *ptrA = shapeA.ptr();
1225 NxShape *ptrB = shapeB.ptr();
1226 NxU32 flags = _ptr->getShapePairFlags(*ptrA, *ptrB);
1228 return (flags && NX_IGNORE_PAIR) ? true :
false;
1250 PhysxContactPairFlag flag,
bool value) {
1252 nassertv(_error_type == ET_ok);
1254 NxU32 flags = _ptr->getActorGroupPairFlags(g1, g2);
1255 if (value ==
true) {
1261 _ptr->setActorGroupPairFlags(g1, g2, flags);
1269 PhysxContactPairFlag flag) {
1271 nassertr(_error_type == ET_ok,
false);
1272 NxU32 flags = _ptr->getActorGroupPairFlags(g1, g2);
1273 return (flags && flag) ? true :
false;
1280 set_filter_ops(PhysxFilterOp op0, PhysxFilterOp op1, PhysxFilterOp op2) {
1282 nassertv(_error_type == ET_ok);
1283 _ptr->setFilterOps((NxFilterOp)op0, (NxFilterOp)op1, (NxFilterOp)op2);
1292 nassertv(_error_type == ET_ok);
1293 _ptr->setFilterBool(flag);
1302 nassertv(_error_type == ET_ok);
1303 _ptr->setFilterConstant0(mask.get_mask());
1312 nassertv(_error_type == ET_ok);
1313 _ptr->setFilterConstant1(mask.get_mask());
1322 nassertr(_error_type == ET_ok,
false);
1323 return _ptr->getFilterBool();
1334 nassertr(_error_type == ET_ok, mask);
1336 NxGroupsMask _mask = ptr()->getFilterConstant0();
1337 mask.set_mask(_mask);
1350 nassertr(_error_type == ET_ok, mask);
1352 NxGroupsMask _mask = ptr()->getFilterConstant1();
1353 mask.set_mask(_mask);
1364 nassertr(_error_type == ET_ok, FO_and);
1370 _ptr->getFilterOps(op0, op1, op2);
1372 return (PhysxFilterOp)op0;
1381 nassertr(_error_type == ET_ok, FO_and);
1387 _ptr->getFilterOps(op0, op1, op2);
1389 return (PhysxFilterOp)op1;
1398 nassertr(_error_type == ET_ok, FO_and);
1404 _ptr->getFilterOps(op0, op1, op2);
1406 return (PhysxFilterOp)op2;
1424 nassertv(_error_type == ET_ok);
1425 nassertv(g1 >= 0 && g1 < 32);
1426 nassertv(g2 >= 0 && g2 < 32);
1428 _ptr->setGroupCollisionFlag((NxCollisionGroup)g1, (NxCollisionGroup)g2, enable);
1438 nassertr(_error_type == ET_ok,
false);
1439 nassertr(g1 >= 0 && g1 < 32,
false);
1440 nassertr(g2 >= 0 && g2 < 32,
false);
1442 return _ptr->getGroupCollisionFlag((NxCollisionGroup)g1, (NxCollisionGroup)g2);
1449 get_flag(PhysxSceneFlag flag)
const {
1451 nassertr(_error_type == ET_ok,
false);
1452 return (_ptr->getFlags() & flag) ? true :
false;
1462 nassertr(_error_type == ET_ok,
false);
1463 return (_ptr->getSimType() & NX_SIMULATION_HW) ? true :
false;
1508 nassertv(_error_type == ET_ok);
1512 NxConstraintDominance d = dominance.get_dominance();
1513 _ptr->setDominanceGroupPair((NxDominanceGroup)g1, (NxDominanceGroup)g2, d);
1524 nassertr(_error_type == ET_ok, result);
1525 nassertr(g1 < 32, result);
1526 nassertr(g2 < 32, result);
1528 result.set_dominance(_ptr->getDominanceGroupPair((NxDominanceGroup)g1, (NxDominanceGroup)g2));
1544 nassertr(_error_type == ET_ok,
nullptr);
1546 if (_wheelShapeMaterial ==
nullptr) {
1548 materialDesc.
set_flag(PhysxMaterialDesc::MF_disable_friction,
true);
1552 return _wheelShapeMaterial;