From 433b80be4f85e9301d07f2006def12f7259f376b Mon Sep 17 00:00:00 2001 From: Zeqiang Li Date: Tue, 10 Oct 2023 14:20:14 +0800 Subject: [PATCH 1/2] geometry renderer macro in physx --- native/cocos/physics/physx/PhysXWorld.cpp | 4 ++++ native/cocos/physics/physx/PhysXWorld.h | 29 ++++++++++++++--------- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/native/cocos/physics/physx/PhysXWorld.cpp b/native/cocos/physics/physx/PhysXWorld.cpp index bc19ec27eb2..a962ab35629 100644 --- a/native/cocos/physics/physx/PhysXWorld.cpp +++ b/native/cocos/physics/physx/PhysXWorld.cpp @@ -125,9 +125,12 @@ void PhysXWorld::step(float fixedTimeStep) { _mScene->simulate(fixedTimeStep); _mScene->fetchResults(true); syncPhysicsToScene(); +#if CC_USE_GEOMETRY_RENDERER debugDraw(); +#endif } +#if CC_USE_GEOMETRY_RENDERER pipeline::GeometryRenderer* PhysXWorld::getDebugRenderer () { auto cameras = Root::getInstance()->getMainWindow()->getCameras(); scene::Camera* camera = nullptr; @@ -222,6 +225,7 @@ void PhysXWorld::setDebugDrawConstraintSize(float size) { float PhysXWorld::getDebugDrawConstraintSize() { return _debugConstraintSize; } +#endif void PhysXWorld::setGravity(float x, float y, float z) { _mScene->setGravity(physx::PxVec3(x, y, z)); diff --git a/native/cocos/physics/physx/PhysXWorld.h b/native/cocos/physics/physx/PhysXWorld.h index 561fde2efaf..2e521bf2796 100644 --- a/native/cocos/physics/physx/PhysXWorld.h +++ b/native/cocos/physics/physx/PhysXWorld.h @@ -28,7 +28,6 @@ #include "base/Macros.h" #include "base/std/container/vector.h" #include "core/scene-graph/Node.h" -#include "renderer/pipeline/GeometryRenderer.h" #include "physics/physx/PhysXEventManager.h" #include "physics/physx/PhysXFilterShader.h" #include "physics/physx/PhysXInc.h" @@ -36,6 +35,7 @@ #include "physics/physx/PhysXSharedBody.h" #include "physics/physx/character-controllers/PhysXCharacterController.h" #include "physics/spec/IWorld.h" +#include "renderer/pipeline/GeometryRenderer.h" namespace cc { namespace physics { @@ -61,17 +61,17 @@ class PhysXWorld final : virtual public IPhysicsWorld { RaycastResult &raycastClosestResult() override; bool sweep(RaycastOptions &opt, const physx::PxGeometry &geometry, const physx::PxQuat &orientation); - bool sweepClosest(RaycastOptions& opt, const physx::PxGeometry& geometry, const physx::PxQuat& orientation); + bool sweepClosest(RaycastOptions &opt, const physx::PxGeometry &geometry, const physx::PxQuat &orientation); bool sweepBox(RaycastOptions &opt, float halfExtentX, float halfExtentY, float halfExtentZ, - float orientationW, float orientationX, float orientationY, float orientationZ) override; + float orientationW, float orientationX, float orientationY, float orientationZ) override; bool sweepBoxClosest(RaycastOptions &opt, float halfExtentX, float halfExtentY, float halfExtentZ, - float orientationW, float orientationX, float orientationY, float orientationZ) override; + float orientationW, float orientationX, float orientationY, float orientationZ) override; bool sweepSphere(RaycastOptions &opt, float radius) override; bool sweepSphereClosest(RaycastOptions &opt, float radius) override; bool sweepCapsule(RaycastOptions &opt, float radius, float height, - float orientationW, float orientationX, float orientationY, float orientationZ) override; + float orientationW, float orientationX, float orientationY, float orientationZ) override; bool sweepCapsuleClosest(RaycastOptions &opt, float radius, float height, - float orientationW, float orientationX, float orientationY, float orientationZ) override; + float orientationW, float orientationX, float orientationY, float orientationZ) override; ccstd::vector &sweepResult() override; RaycastResult &sweepClosestResult() override; @@ -86,7 +86,7 @@ class PhysXWorld final : virtual public IPhysicsWorld { inline ccstd::vector> &getContactEventPairs() override { return _mEventMgr->getConatctPairs(); } - inline ccstd::vector>& getCCTShapeEventPairs() override { + inline ccstd::vector> &getCCTShapeEventPairs() override { return _mEventMgr->getCCTShapePairs(); } inline ccstd::vector> &getCCTTriggerEventPairs() override { @@ -109,13 +109,13 @@ class PhysXWorld final : virtual public IPhysicsWorld { void removeActor(const PhysXSharedBody &sb); void addCCT(const PhysXCharacterController &cct); void removeCCT(const PhysXCharacterController &cct); - - //Mapping PhysX Object ID and Pointer + + // Mapping PhysX Object ID and Pointer uint32_t addPXObject(uintptr_t PXObjectPtr); void removePXObject(uint32_t pxObjectID); uintptr_t getPXPtrWithPXObjectID(uint32_t pxObjectID); - //Mapping Wrapper PhysX Object ID and Pointer + // Mapping Wrapper PhysX Object ID and Pointer uint32_t addWrapperObject(uintptr_t wrapperObjectPtr); void removeWrapperObject(uint32_t wrapperObjectID); uintptr_t getWrapperPtrWithObjectID(uint32_t wrapperObjectID); @@ -125,6 +125,7 @@ class PhysXWorld final : virtual public IPhysicsWorld { float getFixedTimeStep() const override { return _fixedTimeStep; } void setFixedTimeStep(float fixedTimeStep) override { _fixedTimeStep = fixedTimeStep; } +#if CC_USE_GEOMETRY_RENDERER virtual void setDebugDrawFlags(EPhysicsDrawFlags flags) override; virtual EPhysicsDrawFlags getDebugDrawFlags() override; @@ -132,10 +133,16 @@ class PhysXWorld final : virtual public IPhysicsWorld { virtual float getDebugDrawConstraintSize() override; private: - pipeline::GeometryRenderer* getDebugRenderer(); + pipeline::GeometryRenderer *getDebugRenderer(); void debugDraw(); void setDebugDrawMode(); +#else + void setDebugDrawFlags(EPhysicsDrawFlags flags) override{}; + EPhysicsDrawFlags getDebugDrawFlags() override { return EPhysicsDrawFlags::NONE; }; + void setDebugDrawConstraintSize(float size) override{}; + float getDebugDrawConstraintSize() override { return 0.0; }; +#endif private: static PhysXWorld *instance; physx::PxFoundation *_mFoundation; From f36d85a06294f513e86a767adbfa10d948acfd08 Mon Sep 17 00:00:00 2001 From: Zeqiang Li Date: Tue, 10 Oct 2023 14:33:42 +0800 Subject: [PATCH 2/2] remove virtual as override exists --- native/cocos/physics/physx/PhysXWorld.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/native/cocos/physics/physx/PhysXWorld.h b/native/cocos/physics/physx/PhysXWorld.h index 2e521bf2796..3315a4550fd 100644 --- a/native/cocos/physics/physx/PhysXWorld.h +++ b/native/cocos/physics/physx/PhysXWorld.h @@ -126,11 +126,11 @@ class PhysXWorld final : virtual public IPhysicsWorld { void setFixedTimeStep(float fixedTimeStep) override { _fixedTimeStep = fixedTimeStep; } #if CC_USE_GEOMETRY_RENDERER - virtual void setDebugDrawFlags(EPhysicsDrawFlags flags) override; - virtual EPhysicsDrawFlags getDebugDrawFlags() override; + void setDebugDrawFlags(EPhysicsDrawFlags flags) override; + EPhysicsDrawFlags getDebugDrawFlags() override; - virtual void setDebugDrawConstraintSize(float size) override; - virtual float getDebugDrawConstraintSize() override; + void setDebugDrawConstraintSize(float size) override; + float getDebugDrawConstraintSize() override; private: pipeline::GeometryRenderer *getDebugRenderer();