Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

geometry renderer macro in physx #16396

Merged
merged 2 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions native/cocos/physics/physx/PhysXWorld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand Down
37 changes: 22 additions & 15 deletions native/cocos/physics/physx/PhysXWorld.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@
#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"
#include "physics/physx/PhysXRigidBody.h"
#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 {
Expand All @@ -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<RaycastResult> &sweepResult() override;
RaycastResult &sweepClosestResult() override;

Expand All @@ -86,7 +86,7 @@ class PhysXWorld final : virtual public IPhysicsWorld {
inline ccstd::vector<std::shared_ptr<ContactEventPair>> &getContactEventPairs() override {
return _mEventMgr->getConatctPairs();
}
inline ccstd::vector<std::shared_ptr<CCTShapeEventPair>>& getCCTShapeEventPairs() override {
inline ccstd::vector<std::shared_ptr<CCTShapeEventPair>> &getCCTShapeEventPairs() override {
return _mEventMgr->getCCTShapePairs();
}
inline ccstd::vector<std::shared_ptr<CCTTriggerEventPair>> &getCCTTriggerEventPairs() override {
Expand All @@ -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);
Expand All @@ -125,17 +125,24 @@ class PhysXWorld final : virtual public IPhysicsWorld {
float getFixedTimeStep() const override { return _fixedTimeStep; }
void setFixedTimeStep(float fixedTimeStep) override { _fixedTimeStep = fixedTimeStep; }

virtual void setDebugDrawFlags(EPhysicsDrawFlags flags) override;
virtual EPhysicsDrawFlags getDebugDrawFlags() override;
#if CC_USE_GEOMETRY_RENDERER
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();
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;
Expand Down
Loading