mirror of
https://github.com/cocos/cocos-engine.git
synced 2026-10-01 13:10:05 +08:00
native physx (#3409)
This commit is contained in:
@@ -136,6 +136,7 @@ set_if_undefined(USE_MIDDLEWARE ON)
|
||||
set_if_undefined(USE_DRAGONBONES ON)
|
||||
set_if_undefined(USE_SPINE ON)
|
||||
set_if_undefined(USE_WEBSOCKET_SERVER OFF)
|
||||
set_if_undefined(USE_PHYSICS_PHYSX OFF)
|
||||
|
||||
if(ANDROID OR WINDOWS)
|
||||
set_if_undefined(CC_USE_GLES3 ON)
|
||||
@@ -149,6 +150,13 @@ elseif(MACOSX OR IOS)
|
||||
set_if_undefined(CC_USE_GLES2 OFF)
|
||||
endif()
|
||||
|
||||
if(USE_PHYSICS_PHYSX)
|
||||
if (ANDROID AND CMAKE_ANDROID_ARCH_ABI MATCHES x86)
|
||||
set(USE_PHYSICS_PHYSX OFF)
|
||||
message(AUTHOR_WARNING "Native PhysX does not support Google Android X86")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(USE_SE_JSC)
|
||||
set(USE_SE_V8 OFF)
|
||||
set(USE_V8_DEBUGGER OFF)
|
||||
@@ -194,6 +202,7 @@ inspect_values(
|
||||
USE_WEBSOCKET_SERVER
|
||||
USE_SE_V8
|
||||
USE_V8_DEBUGGER
|
||||
USE_PHYSICS_PHYSX
|
||||
)
|
||||
|
||||
################################# external source code ################################
|
||||
@@ -1053,6 +1062,68 @@ cocos_source_files(
|
||||
cocos/renderer/frame-graph/VirtualResource.h
|
||||
)
|
||||
|
||||
##### physics
|
||||
|
||||
if(USE_PHYSICS_PHYSX)
|
||||
cocos_source_files(
|
||||
cocos/physics/PhysicsSDK.h
|
||||
cocos/physics/PhysicsSelector.h
|
||||
cocos/physics/sdk/World.h
|
||||
cocos/physics/sdk/World.cpp
|
||||
cocos/physics/sdk/Shape.h
|
||||
cocos/physics/sdk/Shape.cpp
|
||||
cocos/physics/sdk/RigidBody.h
|
||||
cocos/physics/sdk/RigidBody.cpp
|
||||
cocos/physics/sdk/Joint.h
|
||||
cocos/physics/sdk/Joint.cpp
|
||||
cocos/physics/spec/IBody.h
|
||||
cocos/physics/spec/IJoint.h
|
||||
cocos/physics/spec/ILifecycle.h
|
||||
cocos/physics/spec/IShape.h
|
||||
cocos/physics/spec/IWorld.h
|
||||
cocos/physics/physx/PhysX.h
|
||||
cocos/physics/physx/PhysXInc.h
|
||||
cocos/physics/physx/PhysXUtils.h
|
||||
cocos/physics/physx/PhysXUtils.cpp
|
||||
cocos/physics/physx/PhysXWorld.h
|
||||
cocos/physics/physx/PhysXWorld.cpp
|
||||
cocos/physics/physx/PhysXFilterShader.h
|
||||
cocos/physics/physx/PhysXFilterShader.cpp
|
||||
cocos/physics/physx/PhysXEventManager.h
|
||||
cocos/physics/physx/PhysXEventManager.cpp
|
||||
cocos/physics/physx/PhysXSharedBody.h
|
||||
cocos/physics/physx/PhysXSharedBody.cpp
|
||||
cocos/physics/physx/PhysXRigidBody.h
|
||||
cocos/physics/physx/PhysXRigidBody.cpp
|
||||
cocos/physics/physx/shapes/PhysXShape.h
|
||||
cocos/physics/physx/shapes/PhysXShape.cpp
|
||||
cocos/physics/physx/shapes/PhysXSphere.h
|
||||
cocos/physics/physx/shapes/PhysXSphere.cpp
|
||||
cocos/physics/physx/shapes/PhysXBox.h
|
||||
cocos/physics/physx/shapes/PhysXBox.cpp
|
||||
cocos/physics/physx/shapes/PhysXPlane.h
|
||||
cocos/physics/physx/shapes/PhysXPlane.cpp
|
||||
cocos/physics/physx/shapes/PhysXCapsule.h
|
||||
cocos/physics/physx/shapes/PhysXCapsule.cpp
|
||||
cocos/physics/physx/shapes/PhysXCone.h
|
||||
cocos/physics/physx/shapes/PhysXCone.cpp
|
||||
cocos/physics/physx/shapes/PhysXCylinder.h
|
||||
cocos/physics/physx/shapes/PhysXCylinder.cpp
|
||||
cocos/physics/physx/shapes/PhysXTerrain.h
|
||||
cocos/physics/physx/shapes/PhysXTerrain.cpp
|
||||
cocos/physics/physx/shapes/PhysXTrimesh.h
|
||||
cocos/physics/physx/shapes/PhysXTrimesh.cpp
|
||||
cocos/physics/physx/joints/PhysXJoint.h
|
||||
cocos/physics/physx/joints/PhysXJoint.cpp
|
||||
cocos/physics/physx/joints/PhysXRevolute.h
|
||||
cocos/physics/physx/joints/PhysXRevolute.cpp
|
||||
cocos/physics/physx/joints/PhysXDistance.h
|
||||
cocos/physics/physx/joints/PhysXDistance.cpp
|
||||
cocos/bindings/auto/jsb_physics_auto.cpp
|
||||
cocos/bindings/auto/jsb_physics_auto.h
|
||||
)
|
||||
endif()
|
||||
|
||||
##### script bindings
|
||||
######## dop
|
||||
cocos_source_files(
|
||||
@@ -1668,6 +1739,7 @@ target_compile_definitions(cocos2d PUBLIC
|
||||
$<IF:$<BOOL:${USE_MIDDLEWARE}>,USE_MIDDLEWARE=1,USE_MIDDLEWARE=0>
|
||||
$<IF:$<BOOL:${USE_SPINE}>,USE_SPINE=1,USE_SPINE=0>
|
||||
$<IF:$<BOOL:${USE_DRAGONBONES}>,USE_DRAGONBONES=1,USE_DRAGONBONES=0>
|
||||
$<IF:$<BOOL:${USE_PHYSICS_PHYSX}>,USE_PHYSICS_PHYSX=1,USE_PHYSICS_PHYSX=0>
|
||||
$<$<BOOL:${USE_SE_JSC}>:SCRIPT_ENGINE_TYPE=3>
|
||||
$<$<CONFIG:Debug>:CC_DEBUG=1>
|
||||
)
|
||||
|
||||
4835
native/cocos/bindings/auto/jsb_physics_auto.cpp
Normal file
4835
native/cocos/bindings/auto/jsb_physics_auto.cpp
Normal file
File diff suppressed because it is too large
Load Diff
324
native/cocos/bindings/auto/jsb_physics_auto.h
Normal file
324
native/cocos/bindings/auto/jsb_physics_auto.h
Normal file
@@ -0,0 +1,324 @@
|
||||
#pragma once
|
||||
#include "base/Config.h"
|
||||
#include <type_traits>
|
||||
#include "cocos/bindings/jswrapper/SeApi.h"
|
||||
#include "cocos/bindings/manual/jsb_conversions.h"
|
||||
#include "cocos/physics/PhysicsSDK.h"
|
||||
|
||||
extern se::Object* __jsb_cc_physics_World_proto;
|
||||
extern se::Class* __jsb_cc_physics_World_class;
|
||||
|
||||
bool js_register_cc_physics_World(se::Object* obj);
|
||||
bool register_all_physics(se::Object* obj);
|
||||
|
||||
JSB_REGISTER_OBJECT_TYPE(cc::physics::World);
|
||||
SE_DECLARE_FUNC(js_physics_World_createConvex);
|
||||
SE_DECLARE_FUNC(js_physics_World_createHeightField);
|
||||
SE_DECLARE_FUNC(js_physics_World_createMaterial);
|
||||
SE_DECLARE_FUNC(js_physics_World_createTrimesh);
|
||||
SE_DECLARE_FUNC(js_physics_World_destroy);
|
||||
SE_DECLARE_FUNC(js_physics_World_emitEvents);
|
||||
SE_DECLARE_FUNC(js_physics_World_getContactEventPairs);
|
||||
SE_DECLARE_FUNC(js_physics_World_getTriggerEventPairs);
|
||||
SE_DECLARE_FUNC(js_physics_World_raycast);
|
||||
SE_DECLARE_FUNC(js_physics_World_raycastClosest);
|
||||
SE_DECLARE_FUNC(js_physics_World_raycastClosestResult);
|
||||
SE_DECLARE_FUNC(js_physics_World_raycastResult);
|
||||
SE_DECLARE_FUNC(js_physics_World_setAllowSleep);
|
||||
SE_DECLARE_FUNC(js_physics_World_setCollisionMatrix);
|
||||
SE_DECLARE_FUNC(js_physics_World_setGravity);
|
||||
SE_DECLARE_FUNC(js_physics_World_step);
|
||||
SE_DECLARE_FUNC(js_physics_World_syncSceneToPhysics);
|
||||
SE_DECLARE_FUNC(js_physics_World_syncSceneWithCheck);
|
||||
SE_DECLARE_FUNC(js_physics_World_World);
|
||||
|
||||
extern se::Object* __jsb_cc_physics_RigidBody_proto;
|
||||
extern se::Class* __jsb_cc_physics_RigidBody_class;
|
||||
|
||||
bool js_register_cc_physics_RigidBody(se::Object* obj);
|
||||
bool register_all_physics(se::Object* obj);
|
||||
|
||||
JSB_REGISTER_OBJECT_TYPE(cc::physics::RigidBody);
|
||||
SE_DECLARE_FUNC(js_physics_RigidBody_applyForce);
|
||||
SE_DECLARE_FUNC(js_physics_RigidBody_applyImpulse);
|
||||
SE_DECLARE_FUNC(js_physics_RigidBody_applyLocalForce);
|
||||
SE_DECLARE_FUNC(js_physics_RigidBody_applyLocalImpulse);
|
||||
SE_DECLARE_FUNC(js_physics_RigidBody_applyLocalTorque);
|
||||
SE_DECLARE_FUNC(js_physics_RigidBody_applyTorque);
|
||||
SE_DECLARE_FUNC(js_physics_RigidBody_clearForces);
|
||||
SE_DECLARE_FUNC(js_physics_RigidBody_clearState);
|
||||
SE_DECLARE_FUNC(js_physics_RigidBody_clearVelocity);
|
||||
SE_DECLARE_FUNC(js_physics_RigidBody_getAngularVelocity);
|
||||
SE_DECLARE_FUNC(js_physics_RigidBody_getGroup);
|
||||
SE_DECLARE_FUNC(js_physics_RigidBody_getImpl);
|
||||
SE_DECLARE_FUNC(js_physics_RigidBody_getLinearVelocity);
|
||||
SE_DECLARE_FUNC(js_physics_RigidBody_getMask);
|
||||
SE_DECLARE_FUNC(js_physics_RigidBody_getNodeHandle);
|
||||
SE_DECLARE_FUNC(js_physics_RigidBody_getSleepThreshold);
|
||||
SE_DECLARE_FUNC(js_physics_RigidBody_initialize);
|
||||
SE_DECLARE_FUNC(js_physics_RigidBody_isAwake);
|
||||
SE_DECLARE_FUNC(js_physics_RigidBody_isSleeping);
|
||||
SE_DECLARE_FUNC(js_physics_RigidBody_isSleepy);
|
||||
SE_DECLARE_FUNC(js_physics_RigidBody_onDestroy);
|
||||
SE_DECLARE_FUNC(js_physics_RigidBody_onDisable);
|
||||
SE_DECLARE_FUNC(js_physics_RigidBody_onEnable);
|
||||
SE_DECLARE_FUNC(js_physics_RigidBody_setAllowSleep);
|
||||
SE_DECLARE_FUNC(js_physics_RigidBody_setAngularDamping);
|
||||
SE_DECLARE_FUNC(js_physics_RigidBody_setAngularFactor);
|
||||
SE_DECLARE_FUNC(js_physics_RigidBody_setAngularVelocity);
|
||||
SE_DECLARE_FUNC(js_physics_RigidBody_setGroup);
|
||||
SE_DECLARE_FUNC(js_physics_RigidBody_setLinearDamping);
|
||||
SE_DECLARE_FUNC(js_physics_RigidBody_setLinearFactor);
|
||||
SE_DECLARE_FUNC(js_physics_RigidBody_setLinearVelocity);
|
||||
SE_DECLARE_FUNC(js_physics_RigidBody_setMask);
|
||||
SE_DECLARE_FUNC(js_physics_RigidBody_setMass);
|
||||
SE_DECLARE_FUNC(js_physics_RigidBody_setSleepThreshold);
|
||||
SE_DECLARE_FUNC(js_physics_RigidBody_setType);
|
||||
SE_DECLARE_FUNC(js_physics_RigidBody_sleep);
|
||||
SE_DECLARE_FUNC(js_physics_RigidBody_useGravity);
|
||||
SE_DECLARE_FUNC(js_physics_RigidBody_wakeUp);
|
||||
SE_DECLARE_FUNC(js_physics_RigidBody_RigidBody);
|
||||
|
||||
extern se::Object* __jsb_cc_physics_SphereShape_proto;
|
||||
extern se::Class* __jsb_cc_physics_SphereShape_class;
|
||||
|
||||
bool js_register_cc_physics_SphereShape(se::Object* obj);
|
||||
bool register_all_physics(se::Object* obj);
|
||||
|
||||
JSB_REGISTER_OBJECT_TYPE(cc::physics::SphereShape);
|
||||
SE_DECLARE_FUNC(js_physics_SphereShape_getAABB);
|
||||
SE_DECLARE_FUNC(js_physics_SphereShape_getBoundingSphere);
|
||||
SE_DECLARE_FUNC(js_physics_SphereShape_getGroup);
|
||||
SE_DECLARE_FUNC(js_physics_SphereShape_getImpl);
|
||||
SE_DECLARE_FUNC(js_physics_SphereShape_getMask);
|
||||
SE_DECLARE_FUNC(js_physics_SphereShape_initialize);
|
||||
SE_DECLARE_FUNC(js_physics_SphereShape_onDestroy);
|
||||
SE_DECLARE_FUNC(js_physics_SphereShape_onDisable);
|
||||
SE_DECLARE_FUNC(js_physics_SphereShape_onEnable);
|
||||
SE_DECLARE_FUNC(js_physics_SphereShape_setAsTrigger);
|
||||
SE_DECLARE_FUNC(js_physics_SphereShape_setCenter);
|
||||
SE_DECLARE_FUNC(js_physics_SphereShape_setGroup);
|
||||
SE_DECLARE_FUNC(js_physics_SphereShape_setMask);
|
||||
SE_DECLARE_FUNC(js_physics_SphereShape_setMaterial);
|
||||
SE_DECLARE_FUNC(js_physics_SphereShape_setRadius);
|
||||
SE_DECLARE_FUNC(js_physics_SphereShape_updateEventListener);
|
||||
SE_DECLARE_FUNC(js_physics_SphereShape_SphereShape);
|
||||
|
||||
extern se::Object* __jsb_cc_physics_BoxShape_proto;
|
||||
extern se::Class* __jsb_cc_physics_BoxShape_class;
|
||||
|
||||
bool js_register_cc_physics_BoxShape(se::Object* obj);
|
||||
bool register_all_physics(se::Object* obj);
|
||||
|
||||
JSB_REGISTER_OBJECT_TYPE(cc::physics::BoxShape);
|
||||
SE_DECLARE_FUNC(js_physics_BoxShape_getAABB);
|
||||
SE_DECLARE_FUNC(js_physics_BoxShape_getBoundingSphere);
|
||||
SE_DECLARE_FUNC(js_physics_BoxShape_getGroup);
|
||||
SE_DECLARE_FUNC(js_physics_BoxShape_getImpl);
|
||||
SE_DECLARE_FUNC(js_physics_BoxShape_getMask);
|
||||
SE_DECLARE_FUNC(js_physics_BoxShape_initialize);
|
||||
SE_DECLARE_FUNC(js_physics_BoxShape_onDestroy);
|
||||
SE_DECLARE_FUNC(js_physics_BoxShape_onDisable);
|
||||
SE_DECLARE_FUNC(js_physics_BoxShape_onEnable);
|
||||
SE_DECLARE_FUNC(js_physics_BoxShape_setAsTrigger);
|
||||
SE_DECLARE_FUNC(js_physics_BoxShape_setCenter);
|
||||
SE_DECLARE_FUNC(js_physics_BoxShape_setGroup);
|
||||
SE_DECLARE_FUNC(js_physics_BoxShape_setMask);
|
||||
SE_DECLARE_FUNC(js_physics_BoxShape_setMaterial);
|
||||
SE_DECLARE_FUNC(js_physics_BoxShape_setSize);
|
||||
SE_DECLARE_FUNC(js_physics_BoxShape_updateEventListener);
|
||||
SE_DECLARE_FUNC(js_physics_BoxShape_BoxShape);
|
||||
|
||||
extern se::Object* __jsb_cc_physics_CapsuleShape_proto;
|
||||
extern se::Class* __jsb_cc_physics_CapsuleShape_class;
|
||||
|
||||
bool js_register_cc_physics_CapsuleShape(se::Object* obj);
|
||||
bool register_all_physics(se::Object* obj);
|
||||
|
||||
JSB_REGISTER_OBJECT_TYPE(cc::physics::CapsuleShape);
|
||||
SE_DECLARE_FUNC(js_physics_CapsuleShape_getAABB);
|
||||
SE_DECLARE_FUNC(js_physics_CapsuleShape_getBoundingSphere);
|
||||
SE_DECLARE_FUNC(js_physics_CapsuleShape_getGroup);
|
||||
SE_DECLARE_FUNC(js_physics_CapsuleShape_getImpl);
|
||||
SE_DECLARE_FUNC(js_physics_CapsuleShape_getMask);
|
||||
SE_DECLARE_FUNC(js_physics_CapsuleShape_initialize);
|
||||
SE_DECLARE_FUNC(js_physics_CapsuleShape_onDestroy);
|
||||
SE_DECLARE_FUNC(js_physics_CapsuleShape_onDisable);
|
||||
SE_DECLARE_FUNC(js_physics_CapsuleShape_onEnable);
|
||||
SE_DECLARE_FUNC(js_physics_CapsuleShape_setAsTrigger);
|
||||
SE_DECLARE_FUNC(js_physics_CapsuleShape_setCenter);
|
||||
SE_DECLARE_FUNC(js_physics_CapsuleShape_setCylinderHeight);
|
||||
SE_DECLARE_FUNC(js_physics_CapsuleShape_setDirection);
|
||||
SE_DECLARE_FUNC(js_physics_CapsuleShape_setGroup);
|
||||
SE_DECLARE_FUNC(js_physics_CapsuleShape_setMask);
|
||||
SE_DECLARE_FUNC(js_physics_CapsuleShape_setMaterial);
|
||||
SE_DECLARE_FUNC(js_physics_CapsuleShape_setRadius);
|
||||
SE_DECLARE_FUNC(js_physics_CapsuleShape_updateEventListener);
|
||||
SE_DECLARE_FUNC(js_physics_CapsuleShape_CapsuleShape);
|
||||
|
||||
extern se::Object* __jsb_cc_physics_PlaneShape_proto;
|
||||
extern se::Class* __jsb_cc_physics_PlaneShape_class;
|
||||
|
||||
bool js_register_cc_physics_PlaneShape(se::Object* obj);
|
||||
bool register_all_physics(se::Object* obj);
|
||||
|
||||
JSB_REGISTER_OBJECT_TYPE(cc::physics::PlaneShape);
|
||||
SE_DECLARE_FUNC(js_physics_PlaneShape_getAABB);
|
||||
SE_DECLARE_FUNC(js_physics_PlaneShape_getBoundingSphere);
|
||||
SE_DECLARE_FUNC(js_physics_PlaneShape_getGroup);
|
||||
SE_DECLARE_FUNC(js_physics_PlaneShape_getImpl);
|
||||
SE_DECLARE_FUNC(js_physics_PlaneShape_getMask);
|
||||
SE_DECLARE_FUNC(js_physics_PlaneShape_initialize);
|
||||
SE_DECLARE_FUNC(js_physics_PlaneShape_onDestroy);
|
||||
SE_DECLARE_FUNC(js_physics_PlaneShape_onDisable);
|
||||
SE_DECLARE_FUNC(js_physics_PlaneShape_onEnable);
|
||||
SE_DECLARE_FUNC(js_physics_PlaneShape_setAsTrigger);
|
||||
SE_DECLARE_FUNC(js_physics_PlaneShape_setCenter);
|
||||
SE_DECLARE_FUNC(js_physics_PlaneShape_setConstant);
|
||||
SE_DECLARE_FUNC(js_physics_PlaneShape_setGroup);
|
||||
SE_DECLARE_FUNC(js_physics_PlaneShape_setMask);
|
||||
SE_DECLARE_FUNC(js_physics_PlaneShape_setMaterial);
|
||||
SE_DECLARE_FUNC(js_physics_PlaneShape_setNormal);
|
||||
SE_DECLARE_FUNC(js_physics_PlaneShape_updateEventListener);
|
||||
SE_DECLARE_FUNC(js_physics_PlaneShape_PlaneShape);
|
||||
|
||||
extern se::Object* __jsb_cc_physics_TrimeshShape_proto;
|
||||
extern se::Class* __jsb_cc_physics_TrimeshShape_class;
|
||||
|
||||
bool js_register_cc_physics_TrimeshShape(se::Object* obj);
|
||||
bool register_all_physics(se::Object* obj);
|
||||
|
||||
JSB_REGISTER_OBJECT_TYPE(cc::physics::TrimeshShape);
|
||||
SE_DECLARE_FUNC(js_physics_TrimeshShape_getAABB);
|
||||
SE_DECLARE_FUNC(js_physics_TrimeshShape_getBoundingSphere);
|
||||
SE_DECLARE_FUNC(js_physics_TrimeshShape_getGroup);
|
||||
SE_DECLARE_FUNC(js_physics_TrimeshShape_getImpl);
|
||||
SE_DECLARE_FUNC(js_physics_TrimeshShape_getMask);
|
||||
SE_DECLARE_FUNC(js_physics_TrimeshShape_initialize);
|
||||
SE_DECLARE_FUNC(js_physics_TrimeshShape_onDestroy);
|
||||
SE_DECLARE_FUNC(js_physics_TrimeshShape_onDisable);
|
||||
SE_DECLARE_FUNC(js_physics_TrimeshShape_onEnable);
|
||||
SE_DECLARE_FUNC(js_physics_TrimeshShape_setAsTrigger);
|
||||
SE_DECLARE_FUNC(js_physics_TrimeshShape_setCenter);
|
||||
SE_DECLARE_FUNC(js_physics_TrimeshShape_setGroup);
|
||||
SE_DECLARE_FUNC(js_physics_TrimeshShape_setMask);
|
||||
SE_DECLARE_FUNC(js_physics_TrimeshShape_setMaterial);
|
||||
SE_DECLARE_FUNC(js_physics_TrimeshShape_setMesh);
|
||||
SE_DECLARE_FUNC(js_physics_TrimeshShape_updateEventListener);
|
||||
SE_DECLARE_FUNC(js_physics_TrimeshShape_useConvex);
|
||||
SE_DECLARE_FUNC(js_physics_TrimeshShape_TrimeshShape);
|
||||
|
||||
extern se::Object* __jsb_cc_physics_CylinderShape_proto;
|
||||
extern se::Class* __jsb_cc_physics_CylinderShape_class;
|
||||
|
||||
bool js_register_cc_physics_CylinderShape(se::Object* obj);
|
||||
bool register_all_physics(se::Object* obj);
|
||||
|
||||
JSB_REGISTER_OBJECT_TYPE(cc::physics::CylinderShape);
|
||||
SE_DECLARE_FUNC(js_physics_CylinderShape_getAABB);
|
||||
SE_DECLARE_FUNC(js_physics_CylinderShape_getBoundingSphere);
|
||||
SE_DECLARE_FUNC(js_physics_CylinderShape_getGroup);
|
||||
SE_DECLARE_FUNC(js_physics_CylinderShape_getImpl);
|
||||
SE_DECLARE_FUNC(js_physics_CylinderShape_getMask);
|
||||
SE_DECLARE_FUNC(js_physics_CylinderShape_initialize);
|
||||
SE_DECLARE_FUNC(js_physics_CylinderShape_onDestroy);
|
||||
SE_DECLARE_FUNC(js_physics_CylinderShape_onDisable);
|
||||
SE_DECLARE_FUNC(js_physics_CylinderShape_onEnable);
|
||||
SE_DECLARE_FUNC(js_physics_CylinderShape_setAsTrigger);
|
||||
SE_DECLARE_FUNC(js_physics_CylinderShape_setCenter);
|
||||
SE_DECLARE_FUNC(js_physics_CylinderShape_setConvex);
|
||||
SE_DECLARE_FUNC(js_physics_CylinderShape_setCylinder);
|
||||
SE_DECLARE_FUNC(js_physics_CylinderShape_setGroup);
|
||||
SE_DECLARE_FUNC(js_physics_CylinderShape_setMask);
|
||||
SE_DECLARE_FUNC(js_physics_CylinderShape_setMaterial);
|
||||
SE_DECLARE_FUNC(js_physics_CylinderShape_updateEventListener);
|
||||
SE_DECLARE_FUNC(js_physics_CylinderShape_CylinderShape);
|
||||
|
||||
extern se::Object* __jsb_cc_physics_ConeShape_proto;
|
||||
extern se::Class* __jsb_cc_physics_ConeShape_class;
|
||||
|
||||
bool js_register_cc_physics_ConeShape(se::Object* obj);
|
||||
bool register_all_physics(se::Object* obj);
|
||||
|
||||
JSB_REGISTER_OBJECT_TYPE(cc::physics::ConeShape);
|
||||
SE_DECLARE_FUNC(js_physics_ConeShape_getAABB);
|
||||
SE_DECLARE_FUNC(js_physics_ConeShape_getBoundingSphere);
|
||||
SE_DECLARE_FUNC(js_physics_ConeShape_getGroup);
|
||||
SE_DECLARE_FUNC(js_physics_ConeShape_getImpl);
|
||||
SE_DECLARE_FUNC(js_physics_ConeShape_getMask);
|
||||
SE_DECLARE_FUNC(js_physics_ConeShape_initialize);
|
||||
SE_DECLARE_FUNC(js_physics_ConeShape_onDestroy);
|
||||
SE_DECLARE_FUNC(js_physics_ConeShape_onDisable);
|
||||
SE_DECLARE_FUNC(js_physics_ConeShape_onEnable);
|
||||
SE_DECLARE_FUNC(js_physics_ConeShape_setAsTrigger);
|
||||
SE_DECLARE_FUNC(js_physics_ConeShape_setCenter);
|
||||
SE_DECLARE_FUNC(js_physics_ConeShape_setCone);
|
||||
SE_DECLARE_FUNC(js_physics_ConeShape_setConvex);
|
||||
SE_DECLARE_FUNC(js_physics_ConeShape_setGroup);
|
||||
SE_DECLARE_FUNC(js_physics_ConeShape_setMask);
|
||||
SE_DECLARE_FUNC(js_physics_ConeShape_setMaterial);
|
||||
SE_DECLARE_FUNC(js_physics_ConeShape_updateEventListener);
|
||||
SE_DECLARE_FUNC(js_physics_ConeShape_ConeShape);
|
||||
|
||||
extern se::Object* __jsb_cc_physics_TerrainShape_proto;
|
||||
extern se::Class* __jsb_cc_physics_TerrainShape_class;
|
||||
|
||||
bool js_register_cc_physics_TerrainShape(se::Object* obj);
|
||||
bool register_all_physics(se::Object* obj);
|
||||
|
||||
JSB_REGISTER_OBJECT_TYPE(cc::physics::TerrainShape);
|
||||
SE_DECLARE_FUNC(js_physics_TerrainShape_getAABB);
|
||||
SE_DECLARE_FUNC(js_physics_TerrainShape_getBoundingSphere);
|
||||
SE_DECLARE_FUNC(js_physics_TerrainShape_getGroup);
|
||||
SE_DECLARE_FUNC(js_physics_TerrainShape_getImpl);
|
||||
SE_DECLARE_FUNC(js_physics_TerrainShape_getMask);
|
||||
SE_DECLARE_FUNC(js_physics_TerrainShape_initialize);
|
||||
SE_DECLARE_FUNC(js_physics_TerrainShape_onDestroy);
|
||||
SE_DECLARE_FUNC(js_physics_TerrainShape_onDisable);
|
||||
SE_DECLARE_FUNC(js_physics_TerrainShape_onEnable);
|
||||
SE_DECLARE_FUNC(js_physics_TerrainShape_setAsTrigger);
|
||||
SE_DECLARE_FUNC(js_physics_TerrainShape_setCenter);
|
||||
SE_DECLARE_FUNC(js_physics_TerrainShape_setGroup);
|
||||
SE_DECLARE_FUNC(js_physics_TerrainShape_setMask);
|
||||
SE_DECLARE_FUNC(js_physics_TerrainShape_setMaterial);
|
||||
SE_DECLARE_FUNC(js_physics_TerrainShape_setTerrain);
|
||||
SE_DECLARE_FUNC(js_physics_TerrainShape_updateEventListener);
|
||||
SE_DECLARE_FUNC(js_physics_TerrainShape_TerrainShape);
|
||||
|
||||
extern se::Object* __jsb_cc_physics_RevoluteJoint_proto;
|
||||
extern se::Class* __jsb_cc_physics_RevoluteJoint_class;
|
||||
|
||||
bool js_register_cc_physics_RevoluteJoint(se::Object* obj);
|
||||
bool register_all_physics(se::Object* obj);
|
||||
|
||||
JSB_REGISTER_OBJECT_TYPE(cc::physics::RevoluteJoint);
|
||||
SE_DECLARE_FUNC(js_physics_RevoluteJoint_getImpl);
|
||||
SE_DECLARE_FUNC(js_physics_RevoluteJoint_initialize);
|
||||
SE_DECLARE_FUNC(js_physics_RevoluteJoint_onDestroy);
|
||||
SE_DECLARE_FUNC(js_physics_RevoluteJoint_onDisable);
|
||||
SE_DECLARE_FUNC(js_physics_RevoluteJoint_onEnable);
|
||||
SE_DECLARE_FUNC(js_physics_RevoluteJoint_setAxis);
|
||||
SE_DECLARE_FUNC(js_physics_RevoluteJoint_setConnectedBody);
|
||||
SE_DECLARE_FUNC(js_physics_RevoluteJoint_setEnableCollision);
|
||||
SE_DECLARE_FUNC(js_physics_RevoluteJoint_setPivotA);
|
||||
SE_DECLARE_FUNC(js_physics_RevoluteJoint_setPivotB);
|
||||
SE_DECLARE_FUNC(js_physics_RevoluteJoint_RevoluteJoint);
|
||||
|
||||
extern se::Object* __jsb_cc_physics_DistanceJoint_proto;
|
||||
extern se::Class* __jsb_cc_physics_DistanceJoint_class;
|
||||
|
||||
bool js_register_cc_physics_DistanceJoint(se::Object* obj);
|
||||
bool register_all_physics(se::Object* obj);
|
||||
|
||||
JSB_REGISTER_OBJECT_TYPE(cc::physics::DistanceJoint);
|
||||
SE_DECLARE_FUNC(js_physics_DistanceJoint_getImpl);
|
||||
SE_DECLARE_FUNC(js_physics_DistanceJoint_initialize);
|
||||
SE_DECLARE_FUNC(js_physics_DistanceJoint_onDestroy);
|
||||
SE_DECLARE_FUNC(js_physics_DistanceJoint_onDisable);
|
||||
SE_DECLARE_FUNC(js_physics_DistanceJoint_onEnable);
|
||||
SE_DECLARE_FUNC(js_physics_DistanceJoint_setConnectedBody);
|
||||
SE_DECLARE_FUNC(js_physics_DistanceJoint_setEnableCollision);
|
||||
SE_DECLARE_FUNC(js_physics_DistanceJoint_setPivotA);
|
||||
SE_DECLARE_FUNC(js_physics_DistanceJoint_setPivotB);
|
||||
SE_DECLARE_FUNC(js_physics_DistanceJoint_DistanceJoint);
|
||||
|
||||
@@ -853,7 +853,7 @@ bool sevalue_to_native(const se::Value &from, std::array<uint8_t, CNT> *to, se::
|
||||
se::Value tmp;
|
||||
assert(len >= CNT);
|
||||
for (size_t i = 0; i < CNT; i++) {
|
||||
array->getArrayElement(i, &tmp);
|
||||
array->getArrayElement((uint)i, &tmp);
|
||||
sevalue_to_native(tmp, &(*to)[i], ctx);
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -92,6 +92,10 @@
|
||||
|
||||
#endif // USE_MIDDLEWARE
|
||||
|
||||
#if USE_PHYSICS_PHYSX
|
||||
#include "cocos/bindings/auto/jsb_physics_auto.h"
|
||||
#endif
|
||||
|
||||
using namespace cc;
|
||||
|
||||
bool jsb_register_all_modules() {
|
||||
@@ -156,6 +160,10 @@ bool jsb_register_all_modules() {
|
||||
|
||||
#endif // USE_MIDDLEWARE
|
||||
|
||||
#if USE_PHYSICS_PHYSX
|
||||
se->addRegisterCallback(register_all_physics);
|
||||
#endif
|
||||
|
||||
#if (CC_PLATFORM == CC_PLATFORM_MAC_IOS || CC_PLATFORM == CC_PLATFORM_ANDROID)
|
||||
|
||||
#if USE_VIDEO
|
||||
|
||||
31
native/cocos/physics/PhysicsSDK.h
Normal file
31
native/cocos/physics/PhysicsSDK.h
Normal file
@@ -0,0 +1,31 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2020-2021 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "physics/sdk/World.h"
|
||||
#include "physics/sdk/RigidBody.h"
|
||||
#include "physics/sdk/Shape.h"
|
||||
#include "physics/sdk/Joint.h"
|
||||
44
native/cocos/physics/PhysicsSelector.h
Normal file
44
native/cocos/physics/PhysicsSelector.h
Normal file
@@ -0,0 +1,44 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2020-2021 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#if defined(USE_PHYSICS_BULLET)
|
||||
#include "physics/bullet/Bullet.h"
|
||||
#else
|
||||
#include "physics/physx/PhysX.h"
|
||||
#define WrappedWorld PhysXWorld
|
||||
#define WrappedRigidBody PhysXRigidBody
|
||||
#define WrappedSphereShape PhysXSphere
|
||||
#define WrappedBoxShape PhysXBox
|
||||
#define WrappedPlaneShape PhysXPlane
|
||||
#define WrappedCapsuleShape PhysXCapsule
|
||||
#define WrappedTrimeshShape PhysXTrimesh
|
||||
#define WrappedTerrainShape PhysXTerrain
|
||||
#define WrappedConeShape PhysXCone
|
||||
#define WrappedCylinderShape PhysXCylinder
|
||||
#define WrappedRevoluteJoint PhysXRevolute
|
||||
#define WrappedDistanceJoint PhysXDistance
|
||||
#endif
|
||||
42
native/cocos/physics/physx/PhysX.h
Normal file
42
native/cocos/physics/physx/PhysX.h
Normal file
@@ -0,0 +1,42 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2020-2021 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "physics/physx/PhysXWorld.h"
|
||||
|
||||
#include "physics/physx/PhysXRigidBody.h"
|
||||
|
||||
#include "physics/physx/shapes/PhysXBox.h"
|
||||
#include "physics/physx/shapes/PhysXCapsule.h"
|
||||
#include "physics/physx/shapes/PhysXCone.h"
|
||||
#include "physics/physx/shapes/PhysXCylinder.h"
|
||||
#include "physics/physx/shapes/PhysXPlane.h"
|
||||
#include "physics/physx/shapes/PhysXSphere.h"
|
||||
#include "physics/physx/shapes/PhysXTerrain.h"
|
||||
#include "physics/physx/shapes/PhysXTrimesh.h"
|
||||
|
||||
#include "physics/physx/joints/PhysXDistance.h"
|
||||
#include "physics/physx/joints/PhysXRevolute.h"
|
||||
132
native/cocos/physics/physx/PhysXEventManager.cpp
Normal file
132
native/cocos/physics/physx/PhysXEventManager.cpp
Normal file
@@ -0,0 +1,132 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2020-2021 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "physics/physx/PhysXInc.h"
|
||||
#include "physics/physx/PhysXEventManager.h"
|
||||
#include "physics/spec/IWorld.h"
|
||||
#include "physics/physx/PhysXUtils.h"
|
||||
#include "physics/physx/shapes/PhysXShape.h"
|
||||
#include <algorithm>
|
||||
|
||||
namespace cc {
|
||||
namespace physics {
|
||||
|
||||
void PhysXEventManager::SimulationEventCallback::onTrigger(physx::PxTriggerPair *pairs, physx::PxU32 count) {
|
||||
for (physx::PxU32 i = 0; i < count; i++) {
|
||||
const physx::PxTriggerPair &tp = pairs[i];
|
||||
if (tp.flags & (physx::PxTriggerPairFlag::eREMOVED_SHAPE_TRIGGER | physx::PxTriggerPairFlag::eREMOVED_SHAPE_OTHER)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const auto &selfIter = getPxShapeMap().find(reinterpret_cast<uintptr_t>(tp.triggerShape));
|
||||
const auto &otherIter = getPxShapeMap().find(reinterpret_cast<uintptr_t>(tp.otherShape));
|
||||
if (selfIter == getPxShapeMap().end() || otherIter == getPxShapeMap().end()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const auto &self = selfIter->second;
|
||||
const auto &other = otherIter->second;
|
||||
auto & pairs = mManager->getTriggerPairs();
|
||||
const auto &iter = std::find_if(pairs.begin(), pairs.end(), [self, other](std::shared_ptr<TriggerEventPair> &pair) {
|
||||
return (pair->shapeA == self || pair->shapeA == other) && (pair->shapeB == self || pair->shapeB == other);
|
||||
});
|
||||
if (tp.status & physx::PxPairFlag::eNOTIFY_TOUCH_FOUND) {
|
||||
if (iter == pairs.end()) pairs.push_back(std::shared_ptr<TriggerEventPair>(new TriggerEventPair{self, other}));
|
||||
} else if (tp.status & physx::PxPairFlag::eNOTIFY_TOUCH_LOST) {
|
||||
if (iter != pairs.end()) iter->get()->state = ETouchState::EXIT;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PhysXEventManager::SimulationEventCallback::onContact(const physx::PxContactPairHeader & /*header*/, const physx::PxContactPair *pairs, physx::PxU32 count) {
|
||||
for (physx::PxU32 i = 0; i < count; i++) {
|
||||
const physx::PxContactPair &cp = pairs[i];
|
||||
if (cp.flags & (physx::PxContactPairFlag::eREMOVED_SHAPE_0 | physx::PxContactPairFlag::eREMOVED_SHAPE_1)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const auto &selfIter = getPxShapeMap().find(reinterpret_cast<uintptr_t>(cp.shapes[0]));
|
||||
const auto &otherIter = getPxShapeMap().find(reinterpret_cast<uintptr_t>(cp.shapes[1]));
|
||||
if (selfIter == getPxShapeMap().end() || otherIter == getPxShapeMap().end()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const auto &self = selfIter->second;
|
||||
const auto &other = otherIter->second;
|
||||
auto & pairs = mManager->getConatctPairs();
|
||||
auto iter = std::find_if(pairs.begin(), pairs.end(), [self, other](std::shared_ptr<ContactEventPair> &pair) {
|
||||
return (pair->shapeA == self || pair->shapeA == other) && (pair->shapeB == self || pair->shapeB == other);
|
||||
});
|
||||
|
||||
if (cp.events & physx::PxPairFlag::eNOTIFY_TOUCH_PERSISTS) {
|
||||
if (iter != pairs.end()) iter->get()->state = ETouchState::STAY;
|
||||
} else if (cp.events & physx::PxPairFlag::eNOTIFY_TOUCH_FOUND) {
|
||||
if (iter == pairs.end()) {
|
||||
pairs.push_back(std::shared_ptr<ContactEventPair>(new ContactEventPair{self, other}));
|
||||
iter = pairs.end() - 1;
|
||||
}
|
||||
} else if (cp.events & physx::PxPairFlag::eNOTIFY_TOUCH_LOST) {
|
||||
if (iter != pairs.end()) iter->get()->state = ETouchState::EXIT;
|
||||
}
|
||||
|
||||
if (iter != pairs.end()) {
|
||||
const physx::PxU8 &contactCount = cp.contactCount;
|
||||
iter->get()->contacts.resize(contactCount);
|
||||
if (contactCount > 0) {
|
||||
cp.extractContacts(reinterpret_cast<physx::PxContactPairPoint *>(&iter->get()->contacts[0]), contactCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PhysXEventManager::refreshPairs() {
|
||||
for (auto iter = getTriggerPairs().begin(); iter != getTriggerPairs().end();) {
|
||||
const auto &selfIter = getPxShapeMap().find(reinterpret_cast<uintptr_t>(&(reinterpret_cast<PhysXShape *>(iter->get()->shapeA)->getShape())));
|
||||
const auto &otherIter = getPxShapeMap().find(reinterpret_cast<uintptr_t>(&(reinterpret_cast<PhysXShape *>(iter->get()->shapeB)->getShape())));
|
||||
if (selfIter == getPxShapeMap().end() || otherIter == getPxShapeMap().end()) {
|
||||
iter = getTriggerPairs().erase(iter);
|
||||
} else if (iter->get()->state == ETouchState::EXIT) {
|
||||
iter = getTriggerPairs().erase(iter);
|
||||
} else {
|
||||
iter->get()->state = ETouchState::STAY;
|
||||
iter++;
|
||||
}
|
||||
}
|
||||
|
||||
for (auto iter = getConatctPairs().begin(); iter != getConatctPairs().end();) {
|
||||
const auto &selfIter = getPxShapeMap().find(reinterpret_cast<uintptr_t>(&(reinterpret_cast<PhysXShape *>(iter->get()->shapeA)->getShape())));
|
||||
const auto &otherIter = getPxShapeMap().find(reinterpret_cast<uintptr_t>(&(reinterpret_cast<PhysXShape *>(iter->get()->shapeB)->getShape())));
|
||||
if (selfIter == getPxShapeMap().end() || otherIter == getPxShapeMap().end()) {
|
||||
iter = getConatctPairs().erase(iter);
|
||||
} else if (iter->get()->state == ETouchState::EXIT) {
|
||||
iter = getConatctPairs().erase(iter);
|
||||
} else {
|
||||
iter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace physics
|
||||
} // namespace cc
|
||||
72
native/cocos/physics/physx/PhysXEventManager.h
Normal file
72
native/cocos/physics/physx/PhysXEventManager.h
Normal file
@@ -0,0 +1,72 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2020-2021 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "physics/spec/IWorld.h"
|
||||
#include "physics/physx/PhysXInc.h"
|
||||
#include "base/Macros.h"
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
namespace cc {
|
||||
namespace physics {
|
||||
|
||||
class PhysXEventManager final {
|
||||
public:
|
||||
PhysXEventManager() {
|
||||
_mCallback = new SimulationEventCallback(this);
|
||||
}
|
||||
|
||||
~PhysXEventManager() {
|
||||
delete _mCallback;
|
||||
}
|
||||
|
||||
struct SimulationEventCallback : public physx::PxSimulationEventCallback {
|
||||
void onConstraintBreak(physx::PxConstraintInfo * /*constraints*/, physx::PxU32 /*count*/) override{};
|
||||
void onWake(physx::PxActor ** /*actors*/, physx::PxU32 /*count*/) override{};
|
||||
void onSleep(physx::PxActor ** /*actors*/, physx::PxU32 /*count*/) override{};
|
||||
void onTrigger(physx::PxTriggerPair * /*pairs*/, physx::PxU32 /*count*/) override;
|
||||
void onContact(const physx::PxContactPairHeader & /*pairHeader*/, const physx::PxContactPair * /*pairs*/, physx::PxU32 /*nbPairs*/) override;
|
||||
void onAdvance(const physx::PxRigidBody *const * /*bodyBuffer*/, const physx::PxTransform * /*poseBuffer*/, const physx::PxU32 /*count*/) override{};
|
||||
PhysXEventManager *mManager;
|
||||
|
||||
public:
|
||||
explicit SimulationEventCallback(PhysXEventManager *m) : mManager(m) {}
|
||||
};
|
||||
|
||||
CC_INLINE SimulationEventCallback &getEventCallback() { return *_mCallback; }
|
||||
CC_INLINE std::vector<std::shared_ptr<TriggerEventPair>> &getTriggerPairs() { return _mTriggerPairs; }
|
||||
CC_INLINE std::vector<std::shared_ptr<ContactEventPair>> &getConatctPairs() { return _mConatctPairs; }
|
||||
void refreshPairs();
|
||||
|
||||
private:
|
||||
std::vector<std::shared_ptr<TriggerEventPair>> _mTriggerPairs;
|
||||
std::vector<std::shared_ptr<ContactEventPair>> _mConatctPairs;
|
||||
SimulationEventCallback *_mCallback;
|
||||
};
|
||||
|
||||
} // namespace physics
|
||||
} // namespace cc
|
||||
115
native/cocos/physics/physx/PhysXFilterShader.cpp
Normal file
115
native/cocos/physics/physx/PhysXFilterShader.cpp
Normal file
@@ -0,0 +1,115 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2020-2021 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "physics/physx/PhysXInc.h"
|
||||
#include "physics/physx/PhysXFilterShader.h"
|
||||
|
||||
namespace cc {
|
||||
namespace physics {
|
||||
|
||||
physx::PxFilterFlags simpleFilterShader(
|
||||
physx::PxFilterObjectAttributes attributes0, physx::PxFilterData fd0,
|
||||
physx::PxFilterObjectAttributes attributes1, physx::PxFilterData fd1,
|
||||
physx::PxPairFlags &pairFlags, const void* constantBlock, physx::PxU32 constantBlockSize){
|
||||
PX_UNUSED(constantBlock);
|
||||
PX_UNUSED(constantBlockSize);
|
||||
// group mask filter
|
||||
if (!(fd0.word0 & fd1.word1) || !(fd0.word1 & fd1.word0)) {
|
||||
return physx::PxFilterFlag::eSUPPRESS;
|
||||
}
|
||||
|
||||
if (physx::PxFilterObjectIsTrigger(attributes0) || physx::PxFilterObjectIsTrigger(attributes1)) {
|
||||
pairFlags |= physx::PxPairFlag::eTRIGGER_DEFAULT | physx::PxPairFlag::eNOTIFY_TOUCH_CCD;
|
||||
return physx::PxFilterFlag::eDEFAULT;
|
||||
}
|
||||
if (!physx::PxFilterObjectIsKinematic(attributes0) || !physx::PxFilterObjectIsKinematic(attributes1)) {
|
||||
pairFlags |= physx::PxPairFlag::eSOLVE_CONTACT;
|
||||
}
|
||||
pairFlags |= physx::PxPairFlag::eDETECT_DISCRETE_CONTACT |
|
||||
physx::PxPairFlag::eNOTIFY_TOUCH_FOUND | physx::PxPairFlag::eNOTIFY_TOUCH_LOST | physx::PxPairFlag::eNOTIFY_TOUCH_PERSISTS |
|
||||
physx::PxPairFlag::eDETECT_CCD_CONTACT | physx::PxPairFlag::eNOTIFY_CONTACT_POINTS;
|
||||
return physx::PxFilterFlag::eDEFAULT;
|
||||
}
|
||||
|
||||
physx::PxFilterFlags advanceFilterShader(
|
||||
physx::PxFilterObjectAttributes attributes0, physx::PxFilterData fd0,
|
||||
physx::PxFilterObjectAttributes attributes1, physx::PxFilterData fd1,
|
||||
physx::PxPairFlags &pairFlags, const void* constantBlock, physx::PxU32 constantBlockSize){
|
||||
PX_UNUSED(constantBlock);
|
||||
PX_UNUSED(constantBlockSize);
|
||||
// group mask filter
|
||||
if (!(fd0.word0 & fd1.word1) || !(fd0.word1 & fd1.word0)) {
|
||||
return physx::PxFilterFlag::eSUPPRESS;
|
||||
}
|
||||
|
||||
pairFlags = physx::PxPairFlags(0);
|
||||
|
||||
// trigger filter
|
||||
if (physx::PxFilterObjectIsTrigger(attributes0) || physx::PxFilterObjectIsTrigger(attributes1)) {
|
||||
pairFlags |= physx::PxPairFlag::eDETECT_DISCRETE_CONTACT;
|
||||
|
||||
// need trigger event?
|
||||
const physx::PxU16 needTriggerEvent = (fd0.word3 & DETECT_TRIGGER_EVENT) | (fd1.word3 & DETECT_TRIGGER_EVENT);
|
||||
if (needTriggerEvent) {
|
||||
pairFlags |= physx::PxPairFlag::eNOTIFY_TOUCH_FOUND | physx::PxPairFlag::eNOTIFY_TOUCH_LOST;
|
||||
return physx::PxFilterFlag::eDEFAULT;
|
||||
}
|
||||
return physx::PxFilterFlag::eSUPPRESS;
|
||||
}
|
||||
|
||||
// need detect ccd contact?
|
||||
const physx::PxU16 needDetectCCD = (fd0.word3 & DETECT_CONTACT_CCD) | (fd1.word3 & DETECT_CONTACT_CCD);
|
||||
if (needDetectCCD) pairFlags |= physx::PxPairFlag::eDETECT_CCD_CONTACT;
|
||||
|
||||
if (!physx::PxFilterObjectIsKinematic(attributes0) || !physx::PxFilterObjectIsKinematic(attributes1)) {
|
||||
pairFlags |= physx::PxPairFlag::eSOLVE_CONTACT;
|
||||
}
|
||||
|
||||
// simple collision process
|
||||
pairFlags |= physx::PxPairFlag::eDETECT_DISCRETE_CONTACT;
|
||||
|
||||
// need contact event?
|
||||
const physx::PxU16 needContactEvent = (fd0.word3 & DETECT_CONTACT_EVENT) | (fd1.word3 & DETECT_CONTACT_EVENT);
|
||||
if (needContactEvent) pairFlags |= physx::PxPairFlag::eNOTIFY_TOUCH_FOUND | physx::PxPairFlag::eNOTIFY_TOUCH_LOST | physx::PxPairFlag::eNOTIFY_TOUCH_PERSISTS;
|
||||
|
||||
// need contact point?
|
||||
const physx::PxU16 needContactPoint = (fd0.word3 & DETECT_CONTACT_POINT) | (fd1.word3 & DETECT_CONTACT_POINT);
|
||||
if (needContactPoint) pairFlags |= physx::PxPairFlag::eNOTIFY_CONTACT_POINTS;
|
||||
|
||||
return physx::PxFilterFlag::eDEFAULT;
|
||||
}
|
||||
|
||||
physx::PxQueryHitType::Enum QueryFilterShader::preFilter(const physx::PxFilterData& filterData, const physx::PxShape* shape,
|
||||
const physx::PxRigidActor* actor, physx::PxHitFlags& queryFlags) {
|
||||
PX_UNUSED(actor);
|
||||
PX_UNUSED(queryFlags);
|
||||
if ((filterData.word3 & QUERY_CHECK_TRIGGER) && shape->getFlags().isSet(physx::PxShapeFlag::eTRIGGER_SHAPE)) {
|
||||
return physx::PxQueryHitType::eNONE;
|
||||
}
|
||||
return filterData.word3 & QUERY_SINGLE_HIT ? physx::PxQueryHitType::eBLOCK : physx::PxQueryHitType::eTOUCH;
|
||||
}
|
||||
|
||||
} // namespace physics
|
||||
} // namespace cc
|
||||
63
native/cocos/physics/physx/PhysXFilterShader.h
Normal file
63
native/cocos/physics/physx/PhysXFilterShader.h
Normal file
@@ -0,0 +1,63 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2020-2021 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "physics/physx/PhysXInc.h"
|
||||
|
||||
namespace cc {
|
||||
namespace physics {
|
||||
|
||||
constexpr physx::PxU32 QUERY_FILTER = 1 << 0;
|
||||
constexpr physx::PxU32 QUERY_CHECK_TRIGGER = 1 << 1;
|
||||
constexpr physx::PxU32 QUERY_SINGLE_HIT = 1 << 2;
|
||||
constexpr physx::PxU32 DETECT_TRIGGER_EVENT = 1 << 3;
|
||||
constexpr physx::PxU32 DETECT_CONTACT_EVENT = 1 << 4;
|
||||
constexpr physx::PxU32 DETECT_CONTACT_POINT = 1 << 5;
|
||||
constexpr physx::PxU32 DETECT_CONTACT_CCD = 1 << 6;
|
||||
|
||||
physx::PxFilterFlags simpleFilterShader(
|
||||
physx::PxFilterObjectAttributes attributes0, physx::PxFilterData fd0,
|
||||
physx::PxFilterObjectAttributes attributes1, physx::PxFilterData fd1,
|
||||
physx::PxPairFlags &pairFlags, const void* constantBlock, physx::PxU32 constantBlockSize);
|
||||
|
||||
physx::PxFilterFlags advanceFilterShader(
|
||||
physx::PxFilterObjectAttributes attributes0, physx::PxFilterData fd0,
|
||||
physx::PxFilterObjectAttributes attributes1, physx::PxFilterData fd1,
|
||||
physx::PxPairFlags &pairFlags, const void* constantBlock, physx::PxU32 constantBlockSize);
|
||||
|
||||
class QueryFilterShader : public physx::PxSceneQueryFilterCallback {
|
||||
public:
|
||||
physx::PxQueryHitType::Enum preFilter(const physx::PxFilterData &filterData, const physx::PxShape *shape,
|
||||
const physx::PxRigidActor *actor, physx::PxHitFlags &queryFlags) override;
|
||||
physx::PxQueryHitType::Enum postFilter(const physx::PxFilterData & filterData, const physx::PxQueryHit & hit) override {
|
||||
PX_UNUSED(filterData);
|
||||
PX_UNUSED(hit);
|
||||
return physx::PxQueryHitType::eNONE;
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace physics
|
||||
} // namespace cc
|
||||
46
native/cocos/physics/physx/PhysXInc.h
Normal file
46
native/cocos/physics/physx/PhysXInc.h
Normal file
@@ -0,0 +1,46 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2020-2021 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(disable : 4250)
|
||||
#pragma warning(disable : 4996)
|
||||
#endif
|
||||
|
||||
#include "base/Macros.h"
|
||||
|
||||
#if !defined(NDEBUG) ^ defined(_DEBUG)
|
||||
#ifdef CC_DEBUG
|
||||
#define _DEBUG
|
||||
#else
|
||||
#define NDEBUG
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <PxConfig.h>
|
||||
#include <PxPhysicsAPI.h>
|
||||
#include <extensions/PxDefaultAllocator.h>
|
||||
#include <extensions/PxDefaultErrorCallback.h>
|
||||
258
native/cocos/physics/physx/PhysXRigidBody.cpp
Normal file
258
native/cocos/physics/physx/PhysXRigidBody.cpp
Normal file
@@ -0,0 +1,258 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2020-2021 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "physics/physx/PhysXInc.h"
|
||||
#include "physics/physx/PhysXRigidBody.h"
|
||||
#include "physics/physx/PhysXUtils.h"
|
||||
#include "physics/physx/PhysXWorld.h"
|
||||
|
||||
using physx::PxReal;
|
||||
using physx::PxVec3;
|
||||
using physx::PxTransform;
|
||||
using physx::PxForceMode;
|
||||
using physx::PxActorFlag;
|
||||
|
||||
namespace cc {
|
||||
namespace physics {
|
||||
|
||||
PhysXRigidBody::PhysXRigidBody() : _mEnabled(false),
|
||||
_mGroup(1) {}
|
||||
|
||||
void PhysXRigidBody::initialize(uint h, ERigidBodyType t, uint32_t g) {
|
||||
_mGroup = g;
|
||||
PhysXWorld &ins = PhysXWorld::getInstance();
|
||||
_mSharedBody = ins.getSharedBody(h, this);
|
||||
getSharedBody().reference(true);
|
||||
getSharedBody().setType(t);
|
||||
}
|
||||
|
||||
void PhysXRigidBody::onEnable() {
|
||||
_mEnabled = true;
|
||||
getSharedBody().enabled(true);
|
||||
}
|
||||
|
||||
void PhysXRigidBody::onDisable() {
|
||||
_mEnabled = false;
|
||||
getSharedBody().enabled(false);
|
||||
}
|
||||
|
||||
void PhysXRigidBody::onDestroy() {
|
||||
getSharedBody().reference(false);
|
||||
}
|
||||
|
||||
bool PhysXRigidBody::isAwake() {
|
||||
if (getSharedBody().isStatic()) return false;
|
||||
return !getSharedBody().getImpl().rigidDynamic->isSleeping();
|
||||
}
|
||||
|
||||
bool PhysXRigidBody::isSleepy() {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool PhysXRigidBody::isSleeping() {
|
||||
if (getSharedBody().isStatic()) return true;
|
||||
return getSharedBody().getImpl().rigidDynamic->isSleeping();
|
||||
}
|
||||
|
||||
void PhysXRigidBody::setType(ERigidBodyType v) {
|
||||
getSharedBody().setType(v);
|
||||
}
|
||||
|
||||
void PhysXRigidBody::setMass(float v) {
|
||||
getSharedBody().setMass(v);
|
||||
}
|
||||
|
||||
void PhysXRigidBody::setLinearDamping(float v) {
|
||||
if (getSharedBody().isStatic()) return;
|
||||
getSharedBody().getImpl().rigidDynamic->setLinearDamping(v);
|
||||
}
|
||||
|
||||
void PhysXRigidBody::setAngularDamping(float v) {
|
||||
if (getSharedBody().isStatic()) return;
|
||||
getSharedBody().getImpl().rigidDynamic->setAngularDamping(v);
|
||||
}
|
||||
|
||||
void PhysXRigidBody::useGravity(bool v) {
|
||||
if (getSharedBody().isStatic()) return;
|
||||
getSharedBody().getImpl().rigidDynamic->setActorFlag(PxActorFlag::eDISABLE_GRAVITY, !v);
|
||||
}
|
||||
|
||||
void PhysXRigidBody::setLinearFactor(float x, float y, float z) {
|
||||
if (getSharedBody().isStatic()) return;
|
||||
getSharedBody().getImpl().rigidDynamic->setRigidDynamicLockFlag(physx::PxRigidDynamicLockFlag::eLOCK_LINEAR_X, x == 0.);
|
||||
getSharedBody().getImpl().rigidDynamic->setRigidDynamicLockFlag(physx::PxRigidDynamicLockFlag::eLOCK_LINEAR_Y, y == 0.);
|
||||
getSharedBody().getImpl().rigidDynamic->setRigidDynamicLockFlag(physx::PxRigidDynamicLockFlag::eLOCK_LINEAR_Z, z == 0.);
|
||||
}
|
||||
|
||||
void PhysXRigidBody::setAngularFactor(float x, float y, float z) {
|
||||
if (getSharedBody().isStatic()) return;
|
||||
getSharedBody().getImpl().rigidDynamic->setRigidDynamicLockFlag(physx::PxRigidDynamicLockFlag::eLOCK_ANGULAR_X, x == 0.);
|
||||
getSharedBody().getImpl().rigidDynamic->setRigidDynamicLockFlag(physx::PxRigidDynamicLockFlag::eLOCK_ANGULAR_Y, y == 0.);
|
||||
getSharedBody().getImpl().rigidDynamic->setRigidDynamicLockFlag(physx::PxRigidDynamicLockFlag::eLOCK_ANGULAR_Z, z == 0.);
|
||||
}
|
||||
|
||||
void PhysXRigidBody::setAllowSleep(bool v) {
|
||||
if (!getSharedBody().isDynamic()) return;
|
||||
PxReal st = getSharedBody().getImpl().rigidDynamic->getSleepThreshold();
|
||||
PxReal wc = v ? std::max(0.F, st - 0.001F) : FLT_MAX;
|
||||
getSharedBody().getImpl().rigidDynamic->setWakeCounter(wc);
|
||||
}
|
||||
|
||||
void PhysXRigidBody::wakeUp() {
|
||||
if (getSharedBody().isStatic()) return;
|
||||
getSharedBody().getImpl().rigidDynamic->wakeUp();
|
||||
}
|
||||
|
||||
void PhysXRigidBody::sleep() {
|
||||
if (getSharedBody().isStatic()) return;
|
||||
getSharedBody().getImpl().rigidDynamic->putToSleep();
|
||||
}
|
||||
|
||||
void PhysXRigidBody::clearState() {
|
||||
clearForces();
|
||||
clearVelocity();
|
||||
}
|
||||
|
||||
void PhysXRigidBody::clearForces() {
|
||||
getSharedBody().clearForces();
|
||||
}
|
||||
|
||||
void PhysXRigidBody::clearVelocity() {
|
||||
getSharedBody().clearVelocity();
|
||||
}
|
||||
|
||||
void PhysXRigidBody::setSleepThreshold(float v) {
|
||||
if (getSharedBody().isStatic()) return;
|
||||
getSharedBody().getImpl().rigidDynamic->setSleepThreshold(v);
|
||||
}
|
||||
|
||||
float PhysXRigidBody::getSleepThreshold() {
|
||||
return getSharedBody().getImpl().rigidDynamic->getSleepThreshold();
|
||||
}
|
||||
|
||||
cc::Vec3 PhysXRigidBody::getLinearVelocity() {
|
||||
if (getSharedBody().isStatic()) return cc::Vec3::ZERO;
|
||||
cc::Vec3 cv;
|
||||
pxSetVec3Ext(cv, getSharedBody().getImpl().rigidDynamic->getLinearVelocity());
|
||||
return cv;
|
||||
}
|
||||
|
||||
void PhysXRigidBody::setLinearVelocity(float x, float y, float z) {
|
||||
if (getSharedBody().isStatic()) return;
|
||||
getSharedBody().getImpl().rigidDynamic->setLinearVelocity(PxVec3{x, y, z});
|
||||
}
|
||||
|
||||
cc::Vec3 PhysXRigidBody::getAngularVelocity() {
|
||||
if (getSharedBody().isStatic()) return cc::Vec3::ZERO;
|
||||
cc::Vec3 cv;
|
||||
pxSetVec3Ext(cv, getSharedBody().getImpl().rigidDynamic->getAngularVelocity());
|
||||
return cv;
|
||||
}
|
||||
|
||||
void PhysXRigidBody::setAngularVelocity(float x, float y, float z) {
|
||||
if (getSharedBody().isStatic()) return;
|
||||
getSharedBody().getImpl().rigidDynamic->setAngularVelocity(PxVec3{x, y, z});
|
||||
}
|
||||
|
||||
void PhysXRigidBody::applyForce(float x, float y, float z, float rx, float ry, float rz) {
|
||||
if (getSharedBody().isStatic()) return;
|
||||
const PxVec3 force{x, y, z};
|
||||
if (force.isZero()) return;
|
||||
auto *body = getSharedBody().getImpl().rigidDynamic;
|
||||
body->addForce(force, PxForceMode::eFORCE, true);
|
||||
const PxVec3 torque = (PxVec3{rx, ry, rz}).cross(force);
|
||||
if (!torque.isZero()) body->addTorque(torque, PxForceMode::eFORCE, true);
|
||||
}
|
||||
|
||||
void PhysXRigidBody::applyLocalForce(float x, float y, float z, float rx, float ry, float rz) {
|
||||
if (getSharedBody().isStatic()) return;
|
||||
const PxVec3 force{x, y, z};
|
||||
if (force.isZero()) return;
|
||||
auto *body = getSharedBody().getImpl().rigidDynamic;
|
||||
const PxTransform bodyPose = body->getGlobalPose();
|
||||
const PxVec3 worldForce = bodyPose.rotate(force);
|
||||
const PxVec3 worldPos = bodyPose.rotate(PxVec3{rx, ry, rz});
|
||||
body->addForce(worldForce, PxForceMode::eFORCE, true);
|
||||
const PxVec3 torque = worldPos.cross(worldForce);
|
||||
if (!torque.isZero()) body->addTorque(torque, PxForceMode::eFORCE, true);
|
||||
}
|
||||
|
||||
void PhysXRigidBody::applyImpulse(float x, float y, float z, float rx, float ry, float rz) {
|
||||
if (getSharedBody().isStatic()) return;
|
||||
const PxVec3 impulse{x, y, z};
|
||||
if (impulse.isZero()) return;
|
||||
auto *body = getSharedBody().getImpl().rigidDynamic;
|
||||
const PxVec3 torque = (PxVec3{rx, ry, rz}).cross(impulse);
|
||||
body->addForce(impulse, PxForceMode::eIMPULSE, true);
|
||||
if (!torque.isZero()) body->addTorque(torque, PxForceMode::eIMPULSE, true);
|
||||
}
|
||||
|
||||
void PhysXRigidBody::applyLocalImpulse(float x, float y, float z, float rx, float ry, float rz) {
|
||||
if (getSharedBody().isStatic()) return;
|
||||
const PxVec3 impulse{x, y, z};
|
||||
if (impulse.isZero()) return;
|
||||
auto *body = getSharedBody().getImpl().rigidDynamic;
|
||||
const PxTransform bodyPose = body->getGlobalPose();
|
||||
const PxVec3 worldImpulse = bodyPose.rotate(impulse);
|
||||
const PxVec3 worldPos = bodyPose.rotate(PxVec3{rx, ry, rz});
|
||||
body->addForce(worldImpulse, PxForceMode::eIMPULSE, true);
|
||||
const PxVec3 torque = worldPos.cross(worldImpulse);
|
||||
if (!torque.isZero()) body->addTorque(torque, PxForceMode::eIMPULSE, true);
|
||||
}
|
||||
|
||||
void PhysXRigidBody::applyTorque(float x, float y, float z) {
|
||||
if (getSharedBody().isStatic()) return;
|
||||
PxVec3 torque{x, y, z};
|
||||
if (torque.isZero()) return;
|
||||
getSharedBody().getImpl().rigidDynamic->addTorque(torque, PxForceMode::eFORCE, true);
|
||||
}
|
||||
|
||||
void PhysXRigidBody::applyLocalTorque(float x, float y, float z) {
|
||||
if (getSharedBody().isStatic()) return;
|
||||
PxVec3 torque{x, y, z};
|
||||
if (torque.isZero()) return;
|
||||
auto *body = getSharedBody().getImpl().rigidDynamic;
|
||||
const PxTransform bodyPose = body->getGlobalPose();
|
||||
body->addTorque(bodyPose.rotate(PxVec3{x, y, z}), PxForceMode::eFORCE, true);
|
||||
}
|
||||
|
||||
uint32_t PhysXRigidBody::getGroup() {
|
||||
return getSharedBody().getGroup();
|
||||
}
|
||||
|
||||
void PhysXRigidBody::setGroup(uint32_t g) {
|
||||
getSharedBody().setGroup(g);
|
||||
}
|
||||
|
||||
uint32_t PhysXRigidBody::getMask() {
|
||||
return getSharedBody().getMask();
|
||||
}
|
||||
|
||||
void PhysXRigidBody::setMask(uint32_t m) {
|
||||
getSharedBody().setMask(m);
|
||||
}
|
||||
|
||||
} // namespace physics
|
||||
} // namespace cc
|
||||
91
native/cocos/physics/physx/PhysXRigidBody.h
Normal file
91
native/cocos/physics/physx/PhysXRigidBody.h
Normal file
@@ -0,0 +1,91 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2020-2021 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "physics/spec/IBody.h"
|
||||
#include "physics/physx//PhysXInc.h"
|
||||
#include "base/Macros.h"
|
||||
#include "physics/physx/PhysXSharedBody.h"
|
||||
|
||||
namespace cc {
|
||||
namespace physics {
|
||||
|
||||
class PhysXRigidBody final : public IRigidBody {
|
||||
public:
|
||||
PhysXRigidBody();
|
||||
~PhysXRigidBody() override = default;
|
||||
CC_INLINE bool isEnabled() const { return _mEnabled; }
|
||||
CC_INLINE const PhysXSharedBody &getSharedBody() const { return *_mSharedBody; }
|
||||
CC_INLINE PhysXSharedBody &getSharedBody() { return *_mSharedBody; }
|
||||
CC_INLINE uintptr_t getImpl() override { return reinterpret_cast<uintptr_t>(this); }
|
||||
CC_INLINE uint getNodeHandle() override { return _mSharedBody->getNodeHandle(); }
|
||||
void initialize(uint h, ERigidBodyType t, uint32_t g) override;
|
||||
void onEnable() override;
|
||||
void onDisable() override;
|
||||
void onDestroy() override;
|
||||
bool isAwake() override;
|
||||
bool isSleepy() override;
|
||||
bool isSleeping() override;
|
||||
void setType(ERigidBodyType v) override;
|
||||
void setMass(float v) override;
|
||||
void setLinearDamping(float v) override;
|
||||
void setAngularDamping(float v) override;
|
||||
void useGravity(bool v) override;
|
||||
void setLinearFactor(float x, float y, float z) override;
|
||||
void setAngularFactor(float x, float y, float z) override;
|
||||
void setAllowSleep(bool v) override;
|
||||
void wakeUp() override;
|
||||
void sleep() override;
|
||||
void clearState() override;
|
||||
void clearForces() override;
|
||||
void clearVelocity() override;
|
||||
void setSleepThreshold(float v) override;
|
||||
float getSleepThreshold() override;
|
||||
cc::Vec3 getLinearVelocity() override;
|
||||
void setLinearVelocity(float x, float y, float z) override;
|
||||
cc::Vec3 getAngularVelocity() override;
|
||||
void setAngularVelocity(float x, float y, float z) override;
|
||||
void applyForce(float x, float y, float z, float rx, float ry, float rz) override;
|
||||
void applyLocalForce(float x, float y, float z, float rx, float ry, float rz) override;
|
||||
void applyImpulse(float x, float y, float z, float rx, float ry, float rz) override;
|
||||
void applyLocalImpulse(float x, float y, float z, float rx, float ry, float rz) override;
|
||||
void applyTorque(float x, float y, float z) override;
|
||||
void applyLocalTorque(float x, float y, float z) override;
|
||||
uint32_t getGroup() override;
|
||||
uint32_t getMask() override;
|
||||
void setGroup(uint32_t g) override;
|
||||
void setMask(uint32_t m) override;
|
||||
CC_INLINE uint32_t getInitialGroup() const { return _mGroup; }
|
||||
|
||||
protected:
|
||||
// physx::PhysXWorld* mWrappedWorld;
|
||||
PhysXSharedBody *_mSharedBody;
|
||||
uint32_t _mGroup;
|
||||
bool _mEnabled;
|
||||
};
|
||||
|
||||
} // namespace physics
|
||||
} // namespace cc
|
||||
355
native/cocos/physics/physx/PhysXSharedBody.cpp
Normal file
355
native/cocos/physics/physx/PhysXSharedBody.cpp
Normal file
@@ -0,0 +1,355 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2020-2021 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "physics/physx/PhysXInc.h"
|
||||
#include "physics/physx/PhysXSharedBody.h"
|
||||
#include "physics/physx/PhysXUtils.h"
|
||||
#include "physics/physx/PhysXWorld.h"
|
||||
#include "physics/physx/shapes/PhysXShape.h"
|
||||
#include "physics/physx/joints/PhysXJoint.h"
|
||||
#include <cmath>
|
||||
|
||||
using physx::PxVec3;
|
||||
using physx::PxQuat;
|
||||
using physx::PxIdentity;
|
||||
using physx::PxPhysics;
|
||||
using physx::PxFilterData;
|
||||
using physx::PxJointActorIndex;
|
||||
using physx::PxTransform;
|
||||
using physx::PxForceMode;
|
||||
using physx::PxRigidBodyFlag;
|
||||
using physx::PxRigidActor;
|
||||
using physx::PxRigidBodyExt;
|
||||
|
||||
namespace cc {
|
||||
namespace physics {
|
||||
std::map<uint, PhysXSharedBody *> PhysXSharedBody::sharedBodesMap = std::map<uint, PhysXSharedBody *>();
|
||||
|
||||
static int idCounter = 0;
|
||||
PhysXSharedBody::PhysXSharedBody(
|
||||
const uint & handle,
|
||||
PhysXWorld *const world,
|
||||
PhysXRigidBody *const body) : _mID(idCounter++),
|
||||
_mRef(0),
|
||||
_mType(ERigidBodyType::STATIC),
|
||||
_mIsStatic(true),
|
||||
_mIndex(-1),
|
||||
_mFilterData(1, 1, 0, 0),
|
||||
_mNodeHandle(handle),
|
||||
_mStaticActor(nullptr),
|
||||
_mDynamicActor(nullptr),
|
||||
_mWrappedWorld(world),
|
||||
_mWrappedBody(body) {
|
||||
_mImpl.ptr = 0;
|
||||
_mNode = cc::pipeline::SharedMemory::getBuffer<cc::pipeline::Node>(_mNodeHandle);
|
||||
};
|
||||
|
||||
PhysXSharedBody *PhysXSharedBody::getSharedBody(const uint handle, PhysXWorld *const world, PhysXRigidBody *const body) {
|
||||
auto iter = sharedBodesMap.find(handle);
|
||||
PhysXSharedBody *newSB;
|
||||
if (iter != sharedBodesMap.end()) {
|
||||
newSB = iter->second;
|
||||
} else {
|
||||
newSB = new PhysXSharedBody(handle, world, body);
|
||||
newSB->_mFilterData.word0 = 1;
|
||||
newSB->_mFilterData.word1 = world->getMaskByIndex(0);
|
||||
sharedBodesMap.insert(std::pair<uint, PhysXSharedBody *>(handle, newSB));
|
||||
}
|
||||
if (body != nullptr) {
|
||||
auto g = body->getInitialGroup();
|
||||
newSB->_mFilterData.word0 = g;
|
||||
newSB->_mFilterData.word1 = world->getMaskByIndex(static_cast<uint32_t>(log2(g)));
|
||||
}
|
||||
return newSB;
|
||||
}
|
||||
|
||||
PhysXSharedBody::~PhysXSharedBody() {
|
||||
if (_mStaticActor != nullptr) PX_RELEASE(_mStaticActor);
|
||||
if (_mDynamicActor != nullptr) PX_RELEASE(_mDynamicActor);
|
||||
}
|
||||
|
||||
PhysXSharedBody::UActor PhysXSharedBody::getImpl() {
|
||||
initActor();
|
||||
_mImpl.ptr = isStatic() ? reinterpret_cast<uintptr_t>(_mStaticActor) : reinterpret_cast<uintptr_t>(_mDynamicActor);
|
||||
return _mImpl;
|
||||
}
|
||||
|
||||
void PhysXSharedBody::setType(ERigidBodyType v) {
|
||||
if (_mType == v) return;
|
||||
_mType = v;
|
||||
initActor();
|
||||
_mImpl.ptr = isStatic() ? reinterpret_cast<uintptr_t>(_mStaticActor) : reinterpret_cast<uintptr_t>(_mDynamicActor);
|
||||
}
|
||||
|
||||
void PhysXSharedBody::reference(bool v) {
|
||||
v ? _mRef++ : _mRef--;
|
||||
if (_mRef == 0) delete this;
|
||||
}
|
||||
|
||||
void PhysXSharedBody::enabled(bool v) {
|
||||
if (v) {
|
||||
if (_mIndex < 0) {
|
||||
_mIndex = 1;
|
||||
_mWrappedWorld->addActor(*this);
|
||||
}
|
||||
} else {
|
||||
auto *wb = _mWrappedBody;
|
||||
auto ws = _mWrappedShapes;
|
||||
auto isRemove = ws.empty() && (wb == nullptr || (wb != nullptr && !wb->isEnabled()));
|
||||
if (isRemove) {
|
||||
_mIndex = -1;
|
||||
_mWrappedWorld->removeActor(*this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PhysXSharedBody::initActor() {
|
||||
const bool temp = _mIsStatic;
|
||||
if (isStatic()) {
|
||||
_mIsStatic = true;
|
||||
initStaticActor();
|
||||
} else {
|
||||
_mIsStatic = false;
|
||||
initDynamicActor();
|
||||
}
|
||||
if (temp != _mIsStatic) switchActor(temp);
|
||||
}
|
||||
|
||||
void PhysXSharedBody::switchActor(const bool isStaticBefore) {
|
||||
if (_mStaticActor == nullptr || _mDynamicActor == nullptr) return;
|
||||
PxRigidActor &a0 = isStaticBefore ? *reinterpret_cast<PxRigidActor *>(_mStaticActor) : *reinterpret_cast<PxRigidActor *>(_mDynamicActor);
|
||||
PxRigidActor &a1 = !isStaticBefore ? *reinterpret_cast<PxRigidActor *>(_mStaticActor) : *reinterpret_cast<PxRigidActor *>(_mDynamicActor);
|
||||
if (_mIndex >= 0) {
|
||||
_mWrappedWorld->getScene().removeActor(a0, false);
|
||||
_mWrappedWorld->getScene().addActor(a1);
|
||||
}
|
||||
for (auto const &ws : _mWrappedShapes) {
|
||||
a0.detachShape(ws->getShape(), false);
|
||||
a1.attachShape(ws->getShape());
|
||||
}
|
||||
if (isStaticBefore) {
|
||||
if (isDynamic()) _mDynamicActor->wakeUp();
|
||||
_mDynamicActor->setRigidBodyFlag(PxRigidBodyFlag::eKINEMATIC, isKinematic());
|
||||
PxRigidBodyExt::setMassAndUpdateInertia(*_mDynamicActor, _mMass);
|
||||
PxTransform com{PxIdentity};
|
||||
for (auto const &ws : _mWrappedShapes) {
|
||||
if (!ws->isTrigger()) com.p -= ws->getCenter();
|
||||
}
|
||||
_mDynamicActor->setCMassLocalPose(com);
|
||||
}
|
||||
}
|
||||
|
||||
void PhysXSharedBody::initStaticActor() {
|
||||
if (_mStaticActor == nullptr) {
|
||||
PxTransform transform{PxIdentity};
|
||||
pxSetVec3Ext(transform.p, getNode().worldPosition);
|
||||
pxSetQuatExt(transform.q, getNode().worldRotation);
|
||||
if (!transform.p.isFinite()) transform.p = PxVec3{PxIdentity};
|
||||
if (!transform.q.isUnit()) transform.q = PxQuat{PxIdentity};
|
||||
PxPhysics &phy = PxGetPhysics();
|
||||
_mStaticActor = phy.createRigidStatic(transform);
|
||||
}
|
||||
}
|
||||
|
||||
void PhysXSharedBody::initDynamicActor() {
|
||||
if (_mDynamicActor == nullptr) {
|
||||
PxTransform transform{PxIdentity};
|
||||
pxSetVec3Ext(transform.p, getNode().worldPosition);
|
||||
pxSetQuatExt(transform.q, getNode().worldRotation);
|
||||
if (!transform.p.isFinite()) transform.p = PxVec3{PxIdentity};
|
||||
if (!transform.q.isUnit()) transform.q = PxQuat{PxIdentity};
|
||||
PxPhysics &phy = PxGetPhysics();
|
||||
_mDynamicActor = phy.createRigidDynamic(transform);
|
||||
_mDynamicActor->setRigidBodyFlag(PxRigidBodyFlag::eKINEMATIC, isKinematic());
|
||||
}
|
||||
}
|
||||
|
||||
void PhysXSharedBody::updateCenterOfMass() {
|
||||
initActor();
|
||||
if (isStatic()) return;
|
||||
PxTransform com{PxIdentity};
|
||||
for (auto const &ws : _mWrappedShapes) {
|
||||
if (!ws->isTrigger()) com.p -= ws->getCenter();
|
||||
}
|
||||
_mDynamicActor->setCMassLocalPose(com);
|
||||
}
|
||||
|
||||
void PhysXSharedBody::syncScale() {
|
||||
for (auto const &sb : _mWrappedShapes) {
|
||||
sb->updateScale();
|
||||
}
|
||||
|
||||
for (auto const &sb : _mWrappedJoints0) {
|
||||
sb->updateScale0();
|
||||
}
|
||||
|
||||
for (auto const &sb : _mWrappedJoints1) {
|
||||
sb->updateScale1();
|
||||
}
|
||||
}
|
||||
|
||||
void PhysXSharedBody::syncSceneToPhysics() {
|
||||
if (getNode().flagsChanged) {
|
||||
if (getNode().flagsChanged & static_cast<uint32_t>(TransformBit::SCALE)) syncScale();
|
||||
auto wp = getImpl().rigidActor->getGlobalPose();
|
||||
if (getNode().flagsChanged & static_cast<uint32_t>(TransformBit::POSITION)) {
|
||||
pxSetVec3Ext(wp.p, getNode().worldPosition);
|
||||
}
|
||||
if (getNode().flagsChanged & static_cast<uint32_t>(TransformBit::ROTATION)) {
|
||||
pxSetQuatExt(wp.q, getNode().worldRotation);
|
||||
}
|
||||
|
||||
if (isKinematic()) {
|
||||
getImpl().rigidDynamic->setKinematicTarget(wp);
|
||||
} else {
|
||||
getImpl().rigidActor->setGlobalPose(wp, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PhysXSharedBody::syncSceneWithCheck() {
|
||||
if (getNode().flagsChanged & static_cast<uint32_t>(TransformBit::SCALE)) syncScale();
|
||||
auto wp = getImpl().rigidActor->getGlobalPose();
|
||||
bool needUpdate = false;
|
||||
if (wp.p != getNode().worldPosition) {
|
||||
pxSetVec3Ext(wp.p, getNode().worldPosition);
|
||||
needUpdate = true;
|
||||
}
|
||||
if (wp.q != getNode().worldRotation) {
|
||||
pxSetQuatExt(wp.q, getNode().worldRotation);
|
||||
needUpdate = true;
|
||||
}
|
||||
if (needUpdate) {
|
||||
getImpl().rigidActor->setGlobalPose(wp, true);
|
||||
}
|
||||
}
|
||||
|
||||
void PhysXSharedBody::syncPhysicsToScene() {
|
||||
if (isStaticOrKinematic()) return;
|
||||
if (_mDynamicActor->isSleeping()) return;
|
||||
const PxTransform &wp = getImpl().rigidActor->getGlobalPose();
|
||||
pxSetVec3Ext(getNode().worldPosition, wp.p);
|
||||
pxSetQuatExt(getNode().worldRotation, wp.q);
|
||||
getNode().flagsChanged |= static_cast<uint32_t>(TransformBit::POSITION) | static_cast<uint32_t>(TransformBit::ROTATION);
|
||||
}
|
||||
|
||||
void PhysXSharedBody::addShape(PhysXShape &shape) {
|
||||
auto beg = _mWrappedShapes.begin();
|
||||
auto end = _mWrappedShapes.end();
|
||||
auto iter = find(beg, end, &shape);
|
||||
if (iter == end) {
|
||||
shape.getShape().setSimulationFilterData(_mFilterData);
|
||||
shape.getShape().setQueryFilterData(_mFilterData);
|
||||
getImpl().rigidActor->attachShape(shape.getShape());
|
||||
_mWrappedShapes.push_back(&shape);
|
||||
if (!shape.isTrigger()) {
|
||||
if (!shape.getCenter().isZero()) updateCenterOfMass();
|
||||
if (isDynamic()) PxRigidBodyExt::setMassAndUpdateInertia(*getImpl().rigidDynamic, _mMass);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PhysXSharedBody::removeShape(PhysXShape &shape) {
|
||||
auto beg = _mWrappedShapes.begin();
|
||||
auto end = _mWrappedShapes.end();
|
||||
auto iter = find(beg, end, &shape);
|
||||
if (iter != end) {
|
||||
_mWrappedShapes.erase(iter);
|
||||
getImpl().rigidActor->detachShape(shape.getShape(), true);
|
||||
if (!shape.isTrigger()) {
|
||||
if (!shape.getCenter().isZero()) updateCenterOfMass();
|
||||
if (isDynamic()) PxRigidBodyExt::setMassAndUpdateInertia(*getImpl().rigidDynamic, _mMass);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PhysXSharedBody::addJoint(PhysXJoint &joint, const PxJointActorIndex::Enum index) {
|
||||
if (index == PxJointActorIndex::eACTOR1) {
|
||||
auto beg = _mWrappedJoints1.begin();
|
||||
auto end = _mWrappedJoints1.end();
|
||||
auto iter = find(beg, end, &joint);
|
||||
if (iter == end) _mWrappedJoints1.push_back(&joint);
|
||||
} else {
|
||||
auto beg = _mWrappedJoints0.begin();
|
||||
auto end = _mWrappedJoints0.end();
|
||||
auto iter = find(beg, end, &joint);
|
||||
if (iter == end) _mWrappedJoints0.push_back(&joint);
|
||||
}
|
||||
}
|
||||
|
||||
void PhysXSharedBody::removeJoint(PhysXJoint &joint, const PxJointActorIndex::Enum index) {
|
||||
if (index == PxJointActorIndex::eACTOR1) {
|
||||
auto beg = _mWrappedJoints1.begin();
|
||||
auto end = _mWrappedJoints1.end();
|
||||
auto iter = find(beg, end, &joint);
|
||||
if (iter != end) _mWrappedJoints1.erase(iter);
|
||||
} else {
|
||||
auto beg = _mWrappedJoints0.begin();
|
||||
auto end = _mWrappedJoints0.end();
|
||||
auto iter = find(beg, end, &joint);
|
||||
if (iter != end) _mWrappedJoints0.erase(iter);
|
||||
}
|
||||
}
|
||||
|
||||
void PhysXSharedBody::setMass(float v) {
|
||||
if (v <= 0) v = 1e-7F;
|
||||
_mMass = v;
|
||||
if (isDynamic()) PxRigidBodyExt::setMassAndUpdateInertia(*getImpl().rigidDynamic, _mMass);
|
||||
}
|
||||
|
||||
void PhysXSharedBody::setGroup(uint32_t v) {
|
||||
_mFilterData.word0 = v;
|
||||
setCollisionFilter(_mFilterData);
|
||||
}
|
||||
|
||||
void PhysXSharedBody::setMask(uint32_t v) {
|
||||
_mFilterData.word1 = v;
|
||||
setCollisionFilter(_mFilterData);
|
||||
}
|
||||
|
||||
void PhysXSharedBody::setCollisionFilter(PxFilterData &data) {
|
||||
if (isDynamic()) _mDynamicActor->wakeUp();
|
||||
for (auto const &ws : _mWrappedShapes) {
|
||||
ws->getShape().setQueryFilterData(data);
|
||||
ws->getShape().setSimulationFilterData(data);
|
||||
}
|
||||
}
|
||||
|
||||
void PhysXSharedBody::clearForces() {
|
||||
if (isStaticOrKinematic()) return;
|
||||
_mDynamicActor->clearForce(PxForceMode::eFORCE);
|
||||
_mDynamicActor->clearForce(PxForceMode::eIMPULSE);
|
||||
_mDynamicActor->clearTorque(PxForceMode::eFORCE);
|
||||
_mDynamicActor->clearTorque(PxForceMode::eIMPULSE);
|
||||
}
|
||||
|
||||
void PhysXSharedBody::clearVelocity() {
|
||||
if (isStaticOrKinematic()) return;
|
||||
_mDynamicActor->setLinearVelocity(PxVec3{PxIdentity}, false);
|
||||
_mDynamicActor->setAngularVelocity(PxVec3{PxIdentity}, false);
|
||||
}
|
||||
|
||||
} // namespace physics
|
||||
} // namespace cc
|
||||
123
native/cocos/physics/physx/PhysXSharedBody.h
Normal file
123
native/cocos/physics/physx/PhysXSharedBody.h
Normal file
@@ -0,0 +1,123 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2020-2021 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "physics/spec/IBody.h"
|
||||
#include "physics/physx/PhysXInc.h"
|
||||
#include "base/Macros.h"
|
||||
#include "renderer/pipeline/helper/SharedMemory.h"
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
namespace cc {
|
||||
|
||||
enum class TransformBit {
|
||||
NONE = 0,
|
||||
POSITION = (1 << 0),
|
||||
ROTATION = (1 << 1),
|
||||
SCALE = (1 << 2),
|
||||
RS = TransformBit::ROTATION | TransformBit::SCALE,
|
||||
TRS = TransformBit::POSITION | TransformBit::ROTATION | TransformBit::SCALE,
|
||||
TRS_MASK = ~TransformBit::TRS,
|
||||
};
|
||||
|
||||
namespace physics {
|
||||
|
||||
class PhysXWorld;
|
||||
class PhysXShape;
|
||||
class PhysXJoint;
|
||||
class PhysXRigidBody;
|
||||
|
||||
class PhysXSharedBody final {
|
||||
public:
|
||||
static PhysXSharedBody *getSharedBody(uint handle, PhysXWorld *world, PhysXRigidBody *body);
|
||||
PhysXSharedBody() = delete;
|
||||
PhysXSharedBody(PhysXSharedBody &other) = delete;
|
||||
PhysXSharedBody(PhysXSharedBody &&other) = delete;
|
||||
void reference(bool v);
|
||||
void enabled(bool v);
|
||||
CC_INLINE bool isStatic() { return static_cast<int>(_mType) & static_cast<int>(ERigidBodyType::STATIC); }
|
||||
CC_INLINE bool isKinematic() { return static_cast<int>(_mType) & static_cast<int>(ERigidBodyType::KINEMATIC); }
|
||||
CC_INLINE bool isStaticOrKinematic() { return static_cast<int>(_mType) & static_cast<int>(ERigidBodyType::STATIC) || static_cast<int>(_mType) & static_cast<int>(ERigidBodyType::KINEMATIC); }
|
||||
CC_INLINE bool isDynamic() { return !isStaticOrKinematic(); }
|
||||
CC_INLINE uint getNodeHandle() const { return _mNodeHandle; }
|
||||
CC_INLINE cc::pipeline::Node &getNode() const { return *_mNode; }
|
||||
CC_INLINE PhysXWorld &getWorld() const { return *_mWrappedWorld; }
|
||||
union UActor {
|
||||
uintptr_t ptr;
|
||||
physx::PxRigidActor * rigidActor;
|
||||
physx::PxRigidStatic * rigidStatic;
|
||||
physx::PxRigidDynamic *rigidDynamic;
|
||||
};
|
||||
UActor getImpl();
|
||||
void setType(ERigidBodyType v);
|
||||
void setMass(float v);
|
||||
void syncScale();
|
||||
void syncSceneToPhysics();
|
||||
void syncSceneWithCheck();
|
||||
void syncPhysicsToScene();
|
||||
void updateCenterOfMass();
|
||||
void addShape(PhysXShape &shape);
|
||||
void removeShape(PhysXShape &shape);
|
||||
void addJoint(PhysXJoint &joint, physx::PxJointActorIndex::Enum index);
|
||||
void removeJoint(PhysXJoint &joint, physx::PxJointActorIndex::Enum index);
|
||||
void setCollisionFilter(physx::PxFilterData &data);
|
||||
void clearForces();
|
||||
void clearVelocity();
|
||||
void setGroup(uint32_t v);
|
||||
void setMask(uint32_t v);
|
||||
CC_INLINE uint32_t getGroup() const { return _mFilterData.word0; }
|
||||
CC_INLINE uint32_t getMask() const { return _mFilterData.word1; }
|
||||
|
||||
private:
|
||||
static std::map<uint, PhysXSharedBody *> sharedBodesMap;
|
||||
const uint32_t _mID;
|
||||
const uint _mNodeHandle;
|
||||
uint8_t _mRef;
|
||||
bool _mIsStatic;
|
||||
ERigidBodyType _mType;
|
||||
float _mMass;
|
||||
int _mIndex;
|
||||
physx::PxFilterData _mFilterData;
|
||||
cc::pipeline::Node * _mNode;
|
||||
UActor _mImpl;
|
||||
physx::PxRigidStatic * _mStaticActor;
|
||||
physx::PxRigidDynamic * _mDynamicActor;
|
||||
PhysXWorld * _mWrappedWorld;
|
||||
PhysXRigidBody * _mWrappedBody;
|
||||
std::vector<PhysXShape *> _mWrappedShapes;
|
||||
std::vector<PhysXJoint *> _mWrappedJoints0;
|
||||
std::vector<PhysXJoint *> _mWrappedJoints1;
|
||||
PhysXSharedBody(const uint &handle, PhysXWorld *world, PhysXRigidBody *body);
|
||||
~PhysXSharedBody();
|
||||
void initActor();
|
||||
void switchActor(bool isStaticBefore);
|
||||
void initStaticActor();
|
||||
void initDynamicActor();
|
||||
};
|
||||
|
||||
} // namespace physics
|
||||
} // namespace cc
|
||||
56
native/cocos/physics/physx/PhysXUtils.cpp
Normal file
56
native/cocos/physics/physx/PhysXUtils.cpp
Normal file
@@ -0,0 +1,56 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2020-2021 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "physics/physx/PhysXUtils.h"
|
||||
|
||||
namespace cc {
|
||||
namespace physics {
|
||||
|
||||
void pxSetFromTwoVectors(physx::PxQuat &out, const physx::PxVec3 &a, const physx::PxVec3 &b) {
|
||||
float dot = a.dot(b);
|
||||
if (dot < -0.999999) {
|
||||
physx::PxVec3 c = (physx::PxVec3{1., 0., 0.}).cross(a);
|
||||
if (c.magnitude() < 0.000001) c = (physx::PxVec3{0., 1., 0.}).cross(a);
|
||||
c.normalize();
|
||||
out = physx::PxQuat(physx::PxPi, c);
|
||||
} else if (dot > 0.999999) {
|
||||
out = physx::PxQuat{physx::PxIdentity};
|
||||
} else {
|
||||
physx::PxVec3 c = a.cross(b);
|
||||
out = physx::PxQuat{c.x, c.y, c.z, 1 + dot};
|
||||
out.normalize();
|
||||
}
|
||||
}
|
||||
|
||||
physx::PxRigidActor &getTempRigidActor() {
|
||||
static physx::PxRigidActor *tempRigidActor = nullptr;
|
||||
if (!tempRigidActor) {
|
||||
tempRigidActor = PxGetPhysics().createRigidDynamic(physx::PxTransform{physx::PxIdentity});
|
||||
}
|
||||
return *tempRigidActor;
|
||||
}
|
||||
|
||||
} // namespace physics
|
||||
} // namespace cc
|
||||
154
native/cocos/physics/physx/PhysXUtils.h
Normal file
154
native/cocos/physics/physx/PhysXUtils.h
Normal file
@@ -0,0 +1,154 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2020-2021 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "physics/physx/PhysXInc.h"
|
||||
#include "physics/physx/PhysXFilterShader.h"
|
||||
#include "base/Macros.h"
|
||||
#include "math/Vec3.h"
|
||||
#include "math/Vec4.h"
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
|
||||
#define PX_RELEASE(x) \
|
||||
if (x) { \
|
||||
(x)->release(); \
|
||||
(x) = NULL; \
|
||||
}
|
||||
|
||||
namespace cc {
|
||||
namespace physics {
|
||||
|
||||
CC_INLINE bool operator!=(const physx::PxVec3 &a, const cc::Vec3 &b) {
|
||||
return a.x != b.x || a.y == b.y || a.z == b.z;
|
||||
}
|
||||
|
||||
CC_INLINE bool operator!=(const cc::Vec3 &a, const physx::PxVec3 &b) {
|
||||
return a.x != b.x || a.y == b.y || a.z == b.z;
|
||||
}
|
||||
|
||||
CC_INLINE bool operator==(const physx::PxVec3 &a, const cc::Vec3 &b) {
|
||||
return a.x == b.x && a.y == b.y && a.z == b.z;
|
||||
}
|
||||
|
||||
CC_INLINE bool operator==(const cc::Vec3 &a, const physx::PxVec3 &b) {
|
||||
return a.x == b.x && a.y == b.y && a.z == b.z;
|
||||
}
|
||||
|
||||
CC_INLINE physx::PxVec3 operator*(const physx::PxVec3 &a, const cc::Vec3 &b) {
|
||||
return physx::PxVec3{a.x * b.x, a.y * b.y, a.z * b.z};
|
||||
}
|
||||
|
||||
CC_INLINE cc::Vec3 operator*(const cc::Vec3 &a, const physx::PxVec3 &b) {
|
||||
return cc::Vec3{a.x * b.x, a.y * b.y, a.z * b.z};
|
||||
}
|
||||
|
||||
CC_INLINE physx::PxVec3 operator+(const physx::PxVec3 &a, const cc::Vec3 &b) {
|
||||
return physx::PxVec3{a.x + b.x, a.y + b.y, a.z + b.z};
|
||||
}
|
||||
|
||||
CC_INLINE cc::Vec3 operator+(const cc::Vec3 &a, const physx::PxVec3 &b) {
|
||||
return cc::Vec3{a.x + b.x, a.y + b.y, a.z + b.z};
|
||||
}
|
||||
|
||||
CC_INLINE physx::PxVec3 &operator*=(physx::PxVec3 &a, const cc::Vec3 &b) {
|
||||
a.x *= b.x;
|
||||
a.y *= b.y;
|
||||
a.z *= b.z;
|
||||
return a;
|
||||
}
|
||||
|
||||
CC_INLINE cc::Vec3 &operator*=(cc::Vec3 &a, const physx::PxVec3 &b) {
|
||||
a.x *= b.x;
|
||||
a.y *= b.y;
|
||||
a.z *= b.z;
|
||||
return a;
|
||||
}
|
||||
|
||||
CC_INLINE bool operator!=(const physx::PxQuat &a, const cc::Vec4 &b) {
|
||||
return a.x != b.x || a.y == b.y || a.z == b.z || a.w == b.w;
|
||||
}
|
||||
|
||||
CC_INLINE bool operator!=(const cc::Vec4 &a, const physx::PxQuat &b) {
|
||||
return a.x != b.x || a.y == b.y || a.z == b.z || a.w == b.w;
|
||||
}
|
||||
|
||||
CC_INLINE bool operator==(const physx::PxQuat &a, const cc::Vec4 &b) {
|
||||
return a.x == b.x && a.y == b.y && a.z == b.z && a.w == b.w;
|
||||
}
|
||||
|
||||
CC_INLINE bool operator==(const cc::Vec4 &a, const physx::PxQuat &b) {
|
||||
return a.x == b.x && a.y == b.y && a.z == b.z && a.w == b.w;
|
||||
}
|
||||
|
||||
CC_INLINE void pxSetVec3Ext(physx::PxVec3 &v, const cc::Vec3 &cv) {
|
||||
v = physx::PxVec3(cv.x, cv.y, cv.z);
|
||||
}
|
||||
|
||||
CC_INLINE void pxSetVec3Ext(cc::Vec3 &v, const physx::PxVec3 &cv) {
|
||||
v = cc::Vec3(cv.x, cv.y, cv.z);
|
||||
}
|
||||
|
||||
template <typename T1 = physx::PxQuat, typename T2 = cc::Vec4>
|
||||
CC_INLINE void pxSetQuatExt(T1 &p, const T2 &cp) {
|
||||
p = T1(cp.x, cp.y, cp.z, cp.w);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
CC_INLINE T pxAbsMax(const T &a, const T &b) {
|
||||
return physx::PxAbs(a) > physx::PxAbs(b) ? a : b;
|
||||
}
|
||||
|
||||
void pxSetFromTwoVectors(physx::PxQuat &out, const physx::PxVec3 &a, const physx::PxVec3 &b);
|
||||
|
||||
CC_INLINE std::unordered_map<uintptr_t, uintptr_t> &getPxShapeMap() {
|
||||
static std::unordered_map<uintptr_t, uintptr_t> m;
|
||||
return m;
|
||||
}
|
||||
|
||||
CC_INLINE std::unordered_map<uint16_t, uintptr_t> &getPxMaterialMap() {
|
||||
static std::unordered_map<uint16_t, uintptr_t> m;
|
||||
return m;
|
||||
}
|
||||
|
||||
CC_INLINE physx::PxMaterial &getDefaultMaterial() {
|
||||
return *(reinterpret_cast<physx::PxMaterial *>(getPxMaterialMap()[0]));
|
||||
}
|
||||
|
||||
CC_INLINE std::vector<physx::PxRaycastHit> &getPxRaycastHitBuffer() {
|
||||
static std::vector<physx::PxRaycastHit> m{12};
|
||||
return m;
|
||||
}
|
||||
|
||||
CC_INLINE QueryFilterShader &getQueryFilterShader() {
|
||||
static QueryFilterShader shader;
|
||||
return shader;
|
||||
}
|
||||
|
||||
physx::PxRigidActor &getTempRigidActor();
|
||||
|
||||
} // namespace physics
|
||||
} // namespace cc
|
||||
309
native/cocos/physics/physx/PhysXWorld.cpp
Normal file
309
native/cocos/physics/physx/PhysXWorld.cpp
Normal file
@@ -0,0 +1,309 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2020-2021 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "physics/physx/PhysXInc.h"
|
||||
#include "physics/physx/PhysXWorld.h"
|
||||
#include "physics/spec/IWorld.h"
|
||||
#include "physics/physx/PhysXUtils.h"
|
||||
#include "physics/physx/PhysXFilterShader.h"
|
||||
|
||||
namespace cc {
|
||||
namespace physics {
|
||||
|
||||
PhysXWorld *PhysXWorld::instance = nullptr;
|
||||
PhysXWorld &PhysXWorld::getInstance() {
|
||||
return *instance;
|
||||
}
|
||||
|
||||
physx::PxFoundation &PhysXWorld::getFundation() {
|
||||
return *getInstance()._mFoundation;
|
||||
}
|
||||
|
||||
physx::PxCooking &PhysXWorld::getCooking() {
|
||||
return *getInstance()._mCooking;
|
||||
}
|
||||
|
||||
physx::PxPhysics &PhysXWorld::getPhysics() {
|
||||
return *getInstance()._mPhysics;
|
||||
}
|
||||
|
||||
PhysXWorld::PhysXWorld() {
|
||||
instance = this;
|
||||
static physx::PxDefaultAllocator gAllocator;
|
||||
static physx::PxDefaultErrorCallback gErrorCallback;
|
||||
_mFoundation = PxCreateFoundation(PX_PHYSICS_VERSION, gAllocator, gErrorCallback);
|
||||
physx::PxTolerancesScale scale{};
|
||||
_mCooking = PxCreateCooking(PX_PHYSICS_VERSION, *_mFoundation, physx::PxCookingParams(scale));
|
||||
|
||||
physx::PxPvd *pvd = nullptr;
|
||||
#ifdef CC_DEBUG
|
||||
pvd = _mPvd = physx::PxCreatePvd(*_mFoundation);
|
||||
physx::PxPvdTransport *transport = physx::PxDefaultPvdSocketTransportCreate("127.0.0.1", 5425, 10);
|
||||
_mPvd->connect(*transport, physx::PxPvdInstrumentationFlag::eALL);
|
||||
#endif
|
||||
_mPhysics = PxCreatePhysics(PX_PHYSICS_VERSION, *_mFoundation, scale, true, pvd);
|
||||
PxInitExtensions(*_mPhysics, pvd);
|
||||
_mDispatcher = physx::PxDefaultCpuDispatcherCreate(0);
|
||||
|
||||
_mEventMgr = new PhysXEventManager();
|
||||
|
||||
physx::PxSceneDesc sceneDesc(_mPhysics->getTolerancesScale());
|
||||
sceneDesc.gravity = physx::PxVec3(0.0F, -10.0F, 0.0F);
|
||||
sceneDesc.cpuDispatcher = _mDispatcher;
|
||||
sceneDesc.kineKineFilteringMode = physx::PxPairFilteringMode::eKEEP;
|
||||
sceneDesc.staticKineFilteringMode = physx::PxPairFilteringMode::eKEEP;
|
||||
sceneDesc.flags |= physx::PxSceneFlag::eENABLE_CCD;
|
||||
sceneDesc.filterShader = simpleFilterShader;
|
||||
sceneDesc.simulationEventCallback = &_mEventMgr->getEventCallback();
|
||||
_mScene = _mPhysics->createScene(sceneDesc);
|
||||
|
||||
_mCollisionMatrix[0] = 1;
|
||||
|
||||
createMaterial(0, 0.6F, 0.6F, 0.1F, 2, 2);
|
||||
}
|
||||
|
||||
PhysXWorld::~PhysXWorld() {
|
||||
delete _mEventMgr;
|
||||
PX_RELEASE(_mScene);
|
||||
PX_RELEASE(_mDispatcher);
|
||||
PX_RELEASE(_mPhysics);
|
||||
#ifdef CC_DEBUG
|
||||
physx::PxPvdTransport *transport = _mPvd->getTransport();
|
||||
PX_RELEASE(_mPvd);
|
||||
PX_RELEASE(transport);
|
||||
#endif
|
||||
PxCloseExtensions();
|
||||
PX_RELEASE(_mFoundation);
|
||||
}
|
||||
|
||||
void PhysXWorld::step(float fixedTimeStep) {
|
||||
_mScene->simulate(fixedTimeStep);
|
||||
_mScene->fetchResults(true);
|
||||
syncPhysicsToScene();
|
||||
}
|
||||
|
||||
void PhysXWorld::setGravity(float x, float y, float z) {
|
||||
_mScene->setGravity(physx::PxVec3(x, y, z));
|
||||
}
|
||||
|
||||
void PhysXWorld::destroy() {
|
||||
}
|
||||
|
||||
void PhysXWorld::setCollisionMatrix(uint32_t index, uint32_t mask) {
|
||||
if (index > 31) return;
|
||||
_mCollisionMatrix[index] = mask;
|
||||
}
|
||||
|
||||
uintptr_t PhysXWorld::createConvex(ConvexDesc &desc) {
|
||||
physx::PxConvexMeshDesc convexDesc;
|
||||
convexDesc.points.count = desc.positionLength;
|
||||
convexDesc.points.stride = sizeof(physx::PxVec3);
|
||||
convexDesc.points.data = static_cast<physx::PxVec3 *>(desc.positions);
|
||||
convexDesc.flags = physx::PxConvexFlag::eCOMPUTE_CONVEX;
|
||||
physx::PxConvexMesh *convexMesh = getCooking().createConvexMesh(convexDesc, PxGetPhysics().getPhysicsInsertionCallback());
|
||||
return reinterpret_cast<uintptr_t>(convexMesh);
|
||||
}
|
||||
|
||||
uintptr_t PhysXWorld::createTrimesh(TrimeshDesc &desc) {
|
||||
physx::PxTriangleMeshDesc meshDesc;
|
||||
meshDesc.points.count = desc.positionLength;
|
||||
meshDesc.points.stride = sizeof(physx::PxVec3);
|
||||
meshDesc.points.data = static_cast<physx::PxVec3 *>(desc.positions);
|
||||
meshDesc.triangles.count = desc.triangleLength;
|
||||
if (desc.isU16) {
|
||||
meshDesc.triangles.stride = 3 * sizeof(physx::PxU16);
|
||||
meshDesc.triangles.data = static_cast<physx::PxU16 *>(desc.triangles);
|
||||
meshDesc.flags = physx::PxMeshFlag::e16_BIT_INDICES;
|
||||
} else {
|
||||
meshDesc.triangles.stride = 3 * sizeof(physx::PxU32);
|
||||
meshDesc.triangles.data = static_cast<physx::PxU32 *>(desc.triangles);
|
||||
}
|
||||
physx::PxTriangleMesh *triangleMesh = getCooking().createTriangleMesh(meshDesc, PxGetPhysics().getPhysicsInsertionCallback());
|
||||
return reinterpret_cast<uintptr_t>(triangleMesh);
|
||||
}
|
||||
|
||||
uintptr_t PhysXWorld::createHeightField(HeightFieldDesc &desc) {
|
||||
const auto rows = desc.rows;
|
||||
const auto columns = desc.columns;
|
||||
const physx::PxU32 counts = rows * columns;
|
||||
auto *samples = new physx::PxHeightFieldSample[counts];
|
||||
for (physx::PxU32 r = 0; r < rows; r++) {
|
||||
for (physx::PxU32 c = 0; c < columns; c++) {
|
||||
const auto index = c + r * columns;
|
||||
auto v = (static_cast<int16_t *>(desc.samples))[index];
|
||||
samples[index].height = v;
|
||||
}
|
||||
}
|
||||
physx::PxHeightFieldDesc hfDesc;
|
||||
hfDesc.nbRows = rows;
|
||||
hfDesc.nbColumns = columns;
|
||||
hfDesc.samples.data = samples;
|
||||
hfDesc.samples.stride = sizeof(physx::PxHeightFieldSample);
|
||||
physx::PxHeightField *hf = getCooking().createHeightField(hfDesc, PxGetPhysics().getPhysicsInsertionCallback());
|
||||
delete[] samples;
|
||||
return reinterpret_cast<uintptr_t>(hf);
|
||||
}
|
||||
|
||||
uintptr_t PhysXWorld::createMaterial(uint16_t id, float f, float df, float r,
|
||||
uint8_t m0, uint8_t m1) {
|
||||
physx::PxMaterial *mat;
|
||||
auto &m = getPxMaterialMap();
|
||||
if (m.find(id) == m.end()) {
|
||||
mat = PxGetPhysics().createMaterial(f, df, r);
|
||||
m[id] = reinterpret_cast<uintptr_t>(mat);
|
||||
mat->setFrictionCombineMode(physx::PxCombineMode::Enum(m0));
|
||||
mat->setRestitutionCombineMode(physx::PxCombineMode::Enum(m1));
|
||||
} else {
|
||||
mat = reinterpret_cast<physx::PxMaterial *>(m[id]);
|
||||
mat->setStaticFriction(f);
|
||||
mat->setDynamicFriction(df);
|
||||
mat->setRestitution(r);
|
||||
mat->setFrictionCombineMode(physx::PxCombineMode::Enum(m0));
|
||||
mat->setRestitutionCombineMode(physx::PxCombineMode::Enum(m1));
|
||||
}
|
||||
return uintptr_t(mat);
|
||||
}
|
||||
|
||||
void PhysXWorld::emitEvents() {
|
||||
_mEventMgr->refreshPairs();
|
||||
}
|
||||
|
||||
void PhysXWorld::syncSceneToPhysics() {
|
||||
for (auto const &sb : _mSharedBodies) {
|
||||
sb->syncSceneToPhysics();
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t PhysXWorld::getMaskByIndex(uint32_t i) {
|
||||
if (i > 31) i = 0;
|
||||
return _mCollisionMatrix[i];
|
||||
}
|
||||
|
||||
void PhysXWorld::syncPhysicsToScene() {
|
||||
for (auto const &sb : _mSharedBodies) {
|
||||
sb->syncPhysicsToScene();
|
||||
}
|
||||
}
|
||||
|
||||
void PhysXWorld::syncSceneWithCheck() {
|
||||
for (auto const &sb : _mSharedBodies) {
|
||||
sb->syncSceneWithCheck();
|
||||
}
|
||||
}
|
||||
|
||||
void PhysXWorld::setAllowSleep(bool val) {
|
||||
}
|
||||
|
||||
void PhysXWorld::addActor(PhysXSharedBody &sb) {
|
||||
auto beg = _mSharedBodies.begin();
|
||||
auto end = _mSharedBodies.end();
|
||||
auto iter = find(beg, end, &sb);
|
||||
if (iter == end) {
|
||||
_mScene->addActor(*sb.getImpl().rigidActor);
|
||||
_mSharedBodies.push_back(&sb);
|
||||
}
|
||||
}
|
||||
|
||||
void PhysXWorld::removeActor(PhysXSharedBody &sb) {
|
||||
auto beg = _mSharedBodies.begin();
|
||||
auto end = _mSharedBodies.end();
|
||||
auto iter = find(beg, end, &sb);
|
||||
if (iter != end) {
|
||||
_mScene->removeActor(*sb.getImpl().rigidActor, true);
|
||||
_mSharedBodies.erase(iter);
|
||||
}
|
||||
}
|
||||
|
||||
bool PhysXWorld::raycast(RaycastOptions &opt) {
|
||||
physx::PxQueryCache *cache = nullptr;
|
||||
const auto o = opt.origin;
|
||||
const auto ud = opt.unitDir;
|
||||
physx::PxVec3 origin{o.x, o.y, o.z};
|
||||
physx::PxVec3 unitDir{ud.x, ud.y, ud.z};
|
||||
unitDir.normalize();
|
||||
physx::PxHitFlags flags = physx::PxHitFlag::ePOSITION | physx::PxHitFlag::eNORMAL;
|
||||
physx::PxSceneQueryFilterData filterData;
|
||||
filterData.data.word0 = opt.mask;
|
||||
filterData.data.word3 = QUERY_FILTER | (opt.queryTrigger ? 0 : QUERY_CHECK_TRIGGER);
|
||||
filterData.flags = physx::PxQueryFlag::eSTATIC | physx::PxQueryFlag::eDYNAMIC | physx::PxQueryFlag::ePREFILTER;
|
||||
auto &hitBuffer = getPxRaycastHitBuffer();
|
||||
bool result = false;
|
||||
const auto nbTouches = physx::PxSceneQueryExt::raycastMultiple(
|
||||
getScene(), origin, unitDir, opt.distance, flags, hitBuffer.data(),
|
||||
static_cast<physx::PxU32>(hitBuffer.size()), result, filterData, &getQueryFilterShader(), cache);
|
||||
if (nbTouches == 0 || nbTouches == -1) return false;
|
||||
auto &r = raycastResult();
|
||||
r.resize(nbTouches);
|
||||
for (physx::PxI32 i = 0; i < nbTouches; i++) {
|
||||
const auto &shapeIter = getPxShapeMap().find(reinterpret_cast<uintptr_t>(hitBuffer[i].shape));
|
||||
if (shapeIter == getPxShapeMap().end()) return false;
|
||||
r[i].shape = shapeIter->second;
|
||||
r[i].distance = hitBuffer[i].distance;
|
||||
pxSetVec3Ext(r[i].hitNormal, hitBuffer[i].normal);
|
||||
pxSetVec3Ext(r[i].hitPoint, hitBuffer[i].position);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
std::vector<RaycastResult> &PhysXWorld::raycastResult() {
|
||||
static std::vector<RaycastResult> hits;
|
||||
return hits;
|
||||
}
|
||||
|
||||
bool PhysXWorld::raycastClosest(RaycastOptions &opt) {
|
||||
physx::PxRaycastHit hit;
|
||||
physx::PxQueryCache *cache = nullptr;
|
||||
const auto o = opt.origin;
|
||||
const auto ud = opt.unitDir;
|
||||
physx::PxVec3 origin{o.x, o.y, o.z};
|
||||
physx::PxVec3 unitDir{ud.x, ud.y, ud.z};
|
||||
unitDir.normalize();
|
||||
physx::PxHitFlags flags = physx::PxHitFlag::ePOSITION | physx::PxHitFlag::eNORMAL;
|
||||
physx::PxSceneQueryFilterData filterData;
|
||||
filterData.data.word0 = opt.mask;
|
||||
filterData.data.word3 = QUERY_FILTER | (opt.queryTrigger ? 0 : QUERY_CHECK_TRIGGER) | QUERY_SINGLE_HIT;
|
||||
filterData.flags = physx::PxQueryFlag::eSTATIC | physx::PxQueryFlag::eDYNAMIC | physx::PxQueryFlag::ePREFILTER;
|
||||
const auto result = physx::PxSceneQueryExt::raycastSingle(
|
||||
getScene(), origin, unitDir, opt.distance, flags,
|
||||
hit, filterData, &getQueryFilterShader(), cache);
|
||||
if (result) {
|
||||
auto &r = raycastClosestResult();
|
||||
const auto &shapeIter = getPxShapeMap().find(reinterpret_cast<uintptr_t>(hit.shape));
|
||||
if (shapeIter == getPxShapeMap().end()) return false;
|
||||
r.shape = shapeIter->second;
|
||||
r.distance = hit.distance;
|
||||
pxSetVec3Ext(r.hitPoint, hit.position);
|
||||
pxSetVec3Ext(r.hitNormal, hit.normal);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
RaycastResult &PhysXWorld::raycastClosestResult() {
|
||||
static RaycastResult hit;
|
||||
return hit;
|
||||
}
|
||||
|
||||
} // namespace physics
|
||||
} // namespace cc
|
||||
100
native/cocos/physics/physx/PhysXWorld.h
Normal file
100
native/cocos/physics/physx/PhysXWorld.h
Normal file
@@ -0,0 +1,100 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2020-2021 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "physics/physx/PhysXInc.h"
|
||||
#include "physics/spec/IWorld.h"
|
||||
#include "physics/physx/PhysXEventManager.h"
|
||||
#include "physics/physx/PhysXFilterShader.h"
|
||||
#include "physics/physx/PhysXRigidBody.h"
|
||||
#include "physics/physx/PhysXSharedBody.h"
|
||||
#include "base/Macros.h"
|
||||
#include <memory>
|
||||
|
||||
namespace cc {
|
||||
namespace physics {
|
||||
|
||||
class PhysXWorld final : virtual public IPhysicsWorld {
|
||||
public:
|
||||
static PhysXWorld &getInstance();
|
||||
static physx::PxFoundation &getFundation();
|
||||
static physx::PxCooking &getCooking();
|
||||
static physx::PxPhysics &getPhysics();
|
||||
PhysXWorld();
|
||||
~PhysXWorld() override;
|
||||
void step(float fixedTimeStep) override;
|
||||
void setGravity(float x, float y, float z) override;
|
||||
void setAllowSleep(bool v) override;
|
||||
void emitEvents() override;
|
||||
void setCollisionMatrix(uint32_t index, uint32_t mask) override;
|
||||
bool raycast(RaycastOptions &opt) override;
|
||||
bool raycastClosest(RaycastOptions &opt) override;
|
||||
std::vector<RaycastResult> &raycastResult() override;
|
||||
RaycastResult &raycastClosestResult() override;
|
||||
uintptr_t createConvex(ConvexDesc &desc) override;
|
||||
uintptr_t createTrimesh(TrimeshDesc &desc) override;
|
||||
uintptr_t createHeightField(HeightFieldDesc &desc) override;
|
||||
uintptr_t createMaterial(uint16_t id, float f, float df, float r,
|
||||
uint8_t m0, uint8_t m1) override;
|
||||
CC_INLINE std::vector<std::shared_ptr<TriggerEventPair>> &getTriggerEventPairs() override {
|
||||
return _mEventMgr->getTriggerPairs();
|
||||
}
|
||||
CC_INLINE std::vector<std::shared_ptr<ContactEventPair>> &getContactEventPairs() override {
|
||||
return _mEventMgr->getConatctPairs();
|
||||
}
|
||||
void syncSceneToPhysics() override;
|
||||
void syncSceneWithCheck() override;
|
||||
void destroy() override;
|
||||
|
||||
CC_INLINE PhysXSharedBody *getSharedBody(
|
||||
const uint handle,
|
||||
PhysXRigidBody *const body = nullptr) {
|
||||
return PhysXSharedBody::getSharedBody(handle, this, body);
|
||||
}
|
||||
|
||||
CC_INLINE physx::PxScene &getScene() const { return *_mScene; }
|
||||
uint32_t getMaskByIndex(uint32_t i);
|
||||
void syncPhysicsToScene();
|
||||
void addActor(PhysXSharedBody &sb);
|
||||
void removeActor(PhysXSharedBody &sb);
|
||||
|
||||
private:
|
||||
static PhysXWorld *instance;
|
||||
physx::PxFoundation *_mFoundation;
|
||||
physx::PxCooking *_mCooking;
|
||||
physx::PxPhysics *_mPhysics;
|
||||
#ifdef CC_DEBUG
|
||||
physx::PxPvd *_mPvd;
|
||||
#endif
|
||||
physx::PxDefaultCpuDispatcher *_mDispatcher;
|
||||
physx::PxScene *_mScene;
|
||||
PhysXEventManager *_mEventMgr;
|
||||
uint32_t _mCollisionMatrix[31];
|
||||
std::vector<PhysXSharedBody *> _mSharedBodies;
|
||||
};
|
||||
|
||||
} // namespace physics
|
||||
} // namespace cc
|
||||
78
native/cocos/physics/physx/joints/PhysXDistance.cpp
Normal file
78
native/cocos/physics/physx/joints/PhysXDistance.cpp
Normal file
@@ -0,0 +1,78 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2020-2021 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "physics/physx/joints/PhysXDistance.h"
|
||||
#include "physics/physx/PhysXSharedBody.h"
|
||||
#include "physics/physx/PhysXUtils.h"
|
||||
#include "math/Quaternion.h"
|
||||
|
||||
namespace cc {
|
||||
namespace physics {
|
||||
|
||||
PhysXDistance::PhysXDistance() : _mPivotA(physx::PxZero),
|
||||
_mPivotB(physx::PxZero) {}
|
||||
|
||||
void PhysXDistance::onComponentSet() {
|
||||
_mJoint = PxDistanceJointCreate(PxGetPhysics(), &getTempRigidActor(), physx::PxTransform{physx::PxIdentity}, nullptr, physx::PxTransform{physx::PxIdentity});
|
||||
}
|
||||
|
||||
void PhysXDistance::setPivotA(float x, float y, float z) {
|
||||
_mPivotA = physx::PxVec3{x, y, z};
|
||||
updatePose();
|
||||
}
|
||||
|
||||
void PhysXDistance::setPivotB(float x, float y, float z) {
|
||||
_mPivotB = physx::PxVec3{x, y, z};
|
||||
updatePose();
|
||||
}
|
||||
|
||||
void PhysXDistance::updateScale0() {
|
||||
updatePose();
|
||||
}
|
||||
|
||||
void PhysXDistance::updateScale1() {
|
||||
updatePose();
|
||||
}
|
||||
|
||||
void PhysXDistance::updatePose() {
|
||||
physx::PxTransform pose0{physx::PxIdentity};
|
||||
physx::PxTransform pose1{physx::PxIdentity};
|
||||
auto &node0 = _mSharedBody->getNode();
|
||||
pose0.p = _mPivotA * node0.worldScale;
|
||||
_mJoint->setLocalPose(physx::PxJointActorIndex::eACTOR0, pose0);
|
||||
if (_mConnectedBody) {
|
||||
auto &node1 = _mConnectedBody->getNode();
|
||||
pose1.p = _mPivotB * node1.worldScale;
|
||||
} else {
|
||||
pose1.p = _mPivotA * node0.worldScale;
|
||||
pose1.p += _mPivotB + node0.worldPosition;
|
||||
const auto &wr = node0.worldRotation;
|
||||
pose1.q *= physx::PxQuat{wr.x, wr.y, wr.z, wr.w};
|
||||
}
|
||||
_mJoint->setLocalPose(physx::PxJointActorIndex::eACTOR1, pose1);
|
||||
}
|
||||
|
||||
} // namespace physics
|
||||
} // namespace cc
|
||||
50
native/cocos/physics/physx/joints/PhysXDistance.h
Normal file
50
native/cocos/physics/physx/joints/PhysXDistance.h
Normal file
@@ -0,0 +1,50 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2020-2021 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "physics/physx/joints/PhysXJoint.h"
|
||||
|
||||
namespace cc {
|
||||
namespace physics {
|
||||
|
||||
class PhysXDistance final : public PhysXJoint, public IDistanceJoint {
|
||||
public:
|
||||
PhysXDistance();
|
||||
~PhysXDistance() override = default;
|
||||
void setPivotA(float x, float y, float z) override;
|
||||
void setPivotB(float x, float y, float z) override;
|
||||
void updateScale0() override;
|
||||
void updateScale1() override;
|
||||
|
||||
private:
|
||||
void onComponentSet() override;
|
||||
void updatePose();
|
||||
physx::PxVec3 _mPivotA;
|
||||
physx::PxVec3 _mPivotB;
|
||||
};
|
||||
|
||||
} // namespace physics
|
||||
} // namespace cc
|
||||
81
native/cocos/physics/physx/joints/PhysXJoint.cpp
Normal file
81
native/cocos/physics/physx/joints/PhysXJoint.cpp
Normal file
@@ -0,0 +1,81 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2020-2021 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "physics/physx/joints/PhysXJoint.h"
|
||||
#include "physics/physx/PhysXSharedBody.h"
|
||||
#include "physics/physx/PhysXUtils.h"
|
||||
#include "physics/physx/PhysXWorld.h"
|
||||
|
||||
namespace cc {
|
||||
namespace physics {
|
||||
|
||||
void PhysXJoint::initialize(const uint handle) {
|
||||
auto &ins = PhysXWorld::getInstance();
|
||||
_mSharedBody = ins.getSharedBody(handle);
|
||||
_mSharedBody->reference(true);
|
||||
onComponentSet();
|
||||
}
|
||||
|
||||
void PhysXJoint::onEnable() {
|
||||
_mSharedBody->addJoint(*this, physx::PxJointActorIndex::eACTOR0);
|
||||
if (_mConnectedBody) {
|
||||
_mConnectedBody->addJoint(*this, physx::PxJointActorIndex::eACTOR1);
|
||||
_mJoint->setActors(_mSharedBody->getImpl().rigidActor, _mConnectedBody->getImpl().rigidActor);
|
||||
} else {
|
||||
_mJoint->setActors(_mSharedBody->getImpl().rigidActor, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
void PhysXJoint::onDisable() {
|
||||
_mJoint->setActors(&getTempRigidActor(), nullptr);
|
||||
_mSharedBody->removeJoint(*this, physx::PxJointActorIndex::eACTOR0);
|
||||
if (_mConnectedBody) _mConnectedBody->removeJoint(*this, physx::PxJointActorIndex::eACTOR1);
|
||||
}
|
||||
|
||||
void PhysXJoint::onDestroy() {
|
||||
_mSharedBody->reference(false);
|
||||
}
|
||||
|
||||
void PhysXJoint::setConnectedBody(const uint handle) {
|
||||
if (handle) {
|
||||
auto &ins = PhysXWorld::getInstance();
|
||||
_mConnectedBody = ins.getSharedBody(handle);
|
||||
} else {
|
||||
_mConnectedBody = nullptr;
|
||||
}
|
||||
if (_mJoint) {
|
||||
_mJoint->setActors(_mSharedBody->getImpl().rigidActor, _mConnectedBody ? _mConnectedBody->getImpl().rigidActor : nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
void PhysXJoint::setEnableCollision(const bool v) {
|
||||
_mEnableCollision = v;
|
||||
if (_mJoint) {
|
||||
_mJoint->setConstraintFlag(physx::PxConstraintFlag::eCOLLISION_ENABLED, _mEnableCollision);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace physics
|
||||
} // namespace cc
|
||||
61
native/cocos/physics/physx/joints/PhysXJoint.h
Normal file
61
native/cocos/physics/physx/joints/PhysXJoint.h
Normal file
@@ -0,0 +1,61 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2020-2021 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "physics/physx/PhysXInc.h"
|
||||
#include "physics/spec/IJoint.h"
|
||||
#include "base/Macros.h"
|
||||
|
||||
namespace cc {
|
||||
namespace physics {
|
||||
class PhysXSharedBody;
|
||||
|
||||
class PhysXJoint : virtual public IBaseJoint {
|
||||
PX_NOCOPY(PhysXJoint)
|
||||
PhysXJoint() = default;
|
||||
|
||||
public:
|
||||
~PhysXJoint() override = default;
|
||||
CC_INLINE uintptr_t getImpl() override { return reinterpret_cast<uintptr_t>(this); }
|
||||
void initialize(uint handle) override;
|
||||
void onEnable() override;
|
||||
void onDisable() override;
|
||||
void onDestroy() override;
|
||||
void setConnectedBody(uint handle) override;
|
||||
void setEnableCollision(bool v) override;
|
||||
virtual void updateScale0() = 0;
|
||||
virtual void updateScale1() = 0;
|
||||
|
||||
protected:
|
||||
physx::PxJoint *_mJoint{nullptr};
|
||||
PhysXSharedBody *_mSharedBody{nullptr};
|
||||
PhysXSharedBody *_mConnectedBody{nullptr};
|
||||
bool _mEnableCollision{false};
|
||||
virtual void onComponentSet() = 0;
|
||||
};
|
||||
|
||||
} // namespace physics
|
||||
} // namespace cc
|
||||
86
native/cocos/physics/physx/joints/PhysXRevolute.cpp
Normal file
86
native/cocos/physics/physx/joints/PhysXRevolute.cpp
Normal file
@@ -0,0 +1,86 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2020-2021 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "physics/physx/joints/PhysXRevolute.h"
|
||||
#include "physics/physx/PhysXSharedBody.h"
|
||||
#include "physics/physx/PhysXUtils.h"
|
||||
#include "math/Quaternion.h"
|
||||
|
||||
namespace cc {
|
||||
namespace physics {
|
||||
|
||||
PhysXRevolute::PhysXRevolute() : _mPivotA(physx::PxZero),
|
||||
_mPivotB(physx::PxZero),
|
||||
_mAxis(physx::PxZero) {}
|
||||
|
||||
void PhysXRevolute::onComponentSet() {
|
||||
_mJoint = PxRevoluteJointCreate(PxGetPhysics(), &getTempRigidActor(), physx::PxTransform{physx::PxIdentity}, nullptr, physx::PxTransform{physx::PxIdentity});
|
||||
}
|
||||
|
||||
void PhysXRevolute::setPivotA(float x, float y, float z) {
|
||||
_mPivotA = physx::PxVec3{x, y, z};
|
||||
updatePose();
|
||||
}
|
||||
|
||||
void PhysXRevolute::setPivotB(float x, float y, float z) {
|
||||
_mPivotB = physx::PxVec3{x, y, z};
|
||||
updatePose();
|
||||
}
|
||||
|
||||
void PhysXRevolute::setAxis(float x, float y, float z) {
|
||||
_mAxis = physx::PxVec3{x, y, z};
|
||||
updatePose();
|
||||
}
|
||||
|
||||
void PhysXRevolute::updateScale0() {
|
||||
updatePose();
|
||||
}
|
||||
|
||||
void PhysXRevolute::updateScale1() {
|
||||
updatePose();
|
||||
}
|
||||
|
||||
void PhysXRevolute::updatePose() {
|
||||
physx::PxTransform pose0{physx::PxIdentity};
|
||||
physx::PxTransform pose1{physx::PxIdentity};
|
||||
auto &node0 = _mSharedBody->getNode();
|
||||
pose0.p = _mPivotA * node0.worldScale;
|
||||
pxSetFromTwoVectors(pose0.q, physx::PxVec3{1.F, 0.F, 0.F}, _mAxis);
|
||||
_mJoint->setLocalPose(physx::PxJointActorIndex::eACTOR0, pose0);
|
||||
pose1.q = pose0.q;
|
||||
if (_mConnectedBody) {
|
||||
auto &node1 = _mConnectedBody->getNode();
|
||||
pose1.p = _mPivotB * node1.worldScale;
|
||||
} else {
|
||||
pose1.p = _mPivotA * node0.worldScale;
|
||||
pose1.p += _mPivotB + node0.worldPosition;
|
||||
const auto &wr = node0.worldRotation;
|
||||
pose1.q *= physx::PxQuat{wr.x, wr.y, wr.z, wr.w};
|
||||
}
|
||||
_mJoint->setLocalPose(physx::PxJointActorIndex::eACTOR1, pose1);
|
||||
}
|
||||
|
||||
} // namespace physics
|
||||
} // namespace cc
|
||||
52
native/cocos/physics/physx/joints/PhysXRevolute.h
Normal file
52
native/cocos/physics/physx/joints/PhysXRevolute.h
Normal file
@@ -0,0 +1,52 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2020-2021 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "physics/physx/joints/PhysXJoint.h"
|
||||
|
||||
namespace cc {
|
||||
namespace physics {
|
||||
|
||||
class PhysXRevolute final : public PhysXJoint, public IRevoluteJoint {
|
||||
public:
|
||||
PhysXRevolute();
|
||||
~PhysXRevolute() override = default;
|
||||
void setPivotA(float x, float y, float z) override;
|
||||
void setPivotB(float x, float y, float z) override;
|
||||
void setAxis(float x, float y, float z) override;
|
||||
void updateScale0() override;
|
||||
void updateScale1() override;
|
||||
|
||||
private:
|
||||
void onComponentSet() override;
|
||||
void updatePose();
|
||||
physx::PxVec3 _mPivotA;
|
||||
physx::PxVec3 _mPivotB;
|
||||
physx::PxVec3 _mAxis;
|
||||
};
|
||||
|
||||
} // namespace physics
|
||||
} // namespace cc
|
||||
66
native/cocos/physics/physx/shapes/PhysXBox.cpp
Normal file
66
native/cocos/physics/physx/shapes/PhysXBox.cpp
Normal file
@@ -0,0 +1,66 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2020-2021 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "physics/physx/shapes/PhysXShape.h"
|
||||
#include "physics/physx/shapes/PhysXBox.h"
|
||||
#include "physics/physx/PhysXUtils.h"
|
||||
#include "physics/physx/PhysXWorld.h"
|
||||
|
||||
namespace cc {
|
||||
namespace physics {
|
||||
|
||||
PhysXBox::PhysXBox() : _mHalfExtents(0.5),
|
||||
PhysXShape(){};
|
||||
|
||||
void PhysXBox::setSize(float x, float y, float z) {
|
||||
_mHalfExtents = physx::PxVec3{x / 2, y / 2, z / 2};
|
||||
updateGeometry();
|
||||
getShape().setGeometry(getPxGeometry<physx::PxBoxGeometry>());
|
||||
}
|
||||
|
||||
void PhysXBox::onComponentSet() {
|
||||
updateGeometry();
|
||||
_mShape = PxGetPhysics().createShape(getPxGeometry<physx::PxBoxGeometry>(), getDefaultMaterial(), true);
|
||||
}
|
||||
|
||||
void PhysXBox::updateScale() {
|
||||
updateGeometry();
|
||||
getShape().setGeometry(getPxGeometry<physx::PxBoxGeometry>());
|
||||
updateCenter();
|
||||
}
|
||||
|
||||
void PhysXBox::updateGeometry() {
|
||||
auto &node = getSharedBody().getNode();
|
||||
auto &geo = getPxGeometry<physx::PxBoxGeometry>();
|
||||
geo.halfExtents = _mHalfExtents;
|
||||
geo.halfExtents *= node.worldScale;
|
||||
geo.halfExtents = geo.halfExtents.abs();
|
||||
if (geo.halfExtents.minElement() <= 0.0) {
|
||||
geo.halfExtents = geo.halfExtents.maximum(physx::PxVec3{PX_NORMALIZATION_EPSILON});
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace physics
|
||||
} // namespace cc
|
||||
47
native/cocos/physics/physx/shapes/PhysXBox.h
Normal file
47
native/cocos/physics/physx/shapes/PhysXBox.h
Normal file
@@ -0,0 +1,47 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2020-2021 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "physics/physx/shapes/PhysXShape.h"
|
||||
|
||||
namespace cc {
|
||||
namespace physics {
|
||||
|
||||
class PhysXBox final : public PhysXShape, public IBoxShape {
|
||||
public:
|
||||
PhysXBox();
|
||||
~PhysXBox() override = default;
|
||||
void setSize(float x, float y, float z) override;
|
||||
void updateScale() override;
|
||||
|
||||
private:
|
||||
physx::PxVec3 _mHalfExtents;
|
||||
void updateGeometry();
|
||||
void onComponentSet() override;
|
||||
};
|
||||
|
||||
} // namespace physics
|
||||
} // namespace cc
|
||||
96
native/cocos/physics/physx/shapes/PhysXCapsule.cpp
Normal file
96
native/cocos/physics/physx/shapes/PhysXCapsule.cpp
Normal file
@@ -0,0 +1,96 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2020-2021 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "physics/physx/shapes/PhysXShape.h"
|
||||
#include "physics/physx/shapes/PhysXCapsule.h"
|
||||
#include "physics/physx/PhysXUtils.h"
|
||||
#include "physics/physx/PhysXWorld.h"
|
||||
|
||||
namespace cc {
|
||||
namespace physics {
|
||||
|
||||
PhysXCapsule::PhysXCapsule() : _mRadius(0.5F),
|
||||
_mCylinderHeight(1.0F),
|
||||
_mDirection(EAxisDirection::Y_AXIS)
|
||||
{};
|
||||
|
||||
void PhysXCapsule::setRadius(float r) {
|
||||
_mRadius = r;
|
||||
updateGeometry();
|
||||
getShape().setGeometry(getPxGeometry<physx::PxCapsuleGeometry>());
|
||||
}
|
||||
|
||||
void PhysXCapsule::setCylinderHeight(float v) {
|
||||
_mCylinderHeight = v;
|
||||
updateGeometry();
|
||||
getShape().setGeometry(getPxGeometry<physx::PxCapsuleGeometry>());
|
||||
}
|
||||
|
||||
void PhysXCapsule::setDirection(EAxisDirection v) {
|
||||
_mDirection = v;
|
||||
updateGeometry();
|
||||
getShape().setGeometry(getPxGeometry<physx::PxCapsuleGeometry>());
|
||||
}
|
||||
|
||||
void PhysXCapsule::onComponentSet() {
|
||||
updateGeometry();
|
||||
_mShape = PxGetPhysics().createShape(getPxGeometry<physx::PxCapsuleGeometry>(), getDefaultMaterial(), true);
|
||||
}
|
||||
|
||||
void PhysXCapsule::updateScale() {
|
||||
updateGeometry();
|
||||
getShape().setGeometry(getPxGeometry<physx::PxCapsuleGeometry>());
|
||||
updateCenter();
|
||||
}
|
||||
|
||||
void PhysXCapsule::updateGeometry() {
|
||||
auto &node = getSharedBody().getNode();
|
||||
auto &geo = getPxGeometry<physx::PxCapsuleGeometry>();
|
||||
float rs = 1.F;
|
||||
float hs = 1.F;
|
||||
switch (_mDirection) {
|
||||
case EAxisDirection::X_AXIS:
|
||||
hs = physx::PxAbs(node.worldScale.x);
|
||||
rs = pxAbsMax(node.worldScale.y, node.worldScale.z);
|
||||
_mRotation = physx::PxQuat{physx::PxIdentity};
|
||||
break;
|
||||
case EAxisDirection::Z_AXIS:
|
||||
hs = physx::PxAbs(node.worldScale.z);
|
||||
rs = pxAbsMax(node.worldScale.x, node.worldScale.y);
|
||||
_mRotation = physx::PxQuat(physx::PxPiDivTwo, physx::PxVec3{0.F, 1.F, 0.F});
|
||||
break;
|
||||
case EAxisDirection::Y_AXIS:
|
||||
default:
|
||||
hs = physx::PxAbs(node.worldScale.y);
|
||||
rs = pxAbsMax(node.worldScale.x, node.worldScale.z);
|
||||
_mRotation = physx::PxQuat(physx::PxPiDivTwo, physx::PxVec3{0.F, 0.F, 1.F});
|
||||
break;
|
||||
}
|
||||
geo.radius = physx::PxMax(physx::PxAbs(_mRadius * rs), PX_NORMALIZATION_EPSILON);
|
||||
geo.halfHeight = physx::PxMax(physx::PxAbs(_mCylinderHeight / 2 * hs), PX_NORMALIZATION_EPSILON);
|
||||
}
|
||||
|
||||
} // namespace physics
|
||||
} // namespace cc
|
||||
51
native/cocos/physics/physx/shapes/PhysXCapsule.h
Normal file
51
native/cocos/physics/physx/shapes/PhysXCapsule.h
Normal file
@@ -0,0 +1,51 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2020-2021 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "physics/physx/shapes/PhysXShape.h"
|
||||
|
||||
namespace cc {
|
||||
namespace physics {
|
||||
|
||||
class PhysXCapsule final : public PhysXShape, public ICapsuleShape {
|
||||
public:
|
||||
PhysXCapsule();
|
||||
~PhysXCapsule() override = default;
|
||||
void setRadius(float r) override;
|
||||
void setCylinderHeight(float v) override;
|
||||
void setDirection(EAxisDirection v) override;
|
||||
void updateScale() override;
|
||||
|
||||
private:
|
||||
float _mRadius;
|
||||
float _mCylinderHeight;
|
||||
EAxisDirection _mDirection;
|
||||
void updateGeometry();
|
||||
void onComponentSet() override;
|
||||
};
|
||||
|
||||
} // namespace physics
|
||||
} // namespace cc
|
||||
101
native/cocos/physics/physx/shapes/PhysXCone.cpp
Normal file
101
native/cocos/physics/physx/shapes/PhysXCone.cpp
Normal file
@@ -0,0 +1,101 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2020-2021 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "physics/physx/shapes/PhysXShape.h"
|
||||
#include "physics/physx/shapes/PhysXCone.h"
|
||||
#include "physics/physx/PhysXUtils.h"
|
||||
#include "physics/physx/PhysXWorld.h"
|
||||
#include "math/Quaternion.h"
|
||||
#include "renderer/pipeline/helper/SharedMemory.h"
|
||||
#include <algorithm>
|
||||
|
||||
namespace cc {
|
||||
namespace physics {
|
||||
|
||||
PhysXCone::PhysXCone() : _mMesh(nullptr)
|
||||
{};
|
||||
|
||||
void PhysXCone::setConvex(uintptr_t handle) {
|
||||
if (reinterpret_cast<uintptr_t>(_mMesh) == handle) return;
|
||||
_mMesh = reinterpret_cast<physx::PxConvexMesh *>(handle);
|
||||
if (_mShape) {
|
||||
}
|
||||
}
|
||||
|
||||
void PhysXCone::onComponentSet() {
|
||||
if (_mMesh) {
|
||||
physx::PxConvexMeshGeometry geom;
|
||||
geom.convexMesh = _mMesh;
|
||||
// geom.meshFlags = PxConvexMeshGeometryFlags::eTIGHT_BOUNDS;
|
||||
_mShape = PxGetPhysics().createShape(geom, getDefaultMaterial(), true);
|
||||
updateGeometry();
|
||||
}
|
||||
}
|
||||
|
||||
void PhysXCone::setCone(float r, float h, EAxisDirection d) {
|
||||
_mData.radius = r;
|
||||
_mData.height = h;
|
||||
_mData.direction = d;
|
||||
updateGeometry();
|
||||
}
|
||||
|
||||
void PhysXCone::updateGeometry() {
|
||||
if (!_mShape) return;
|
||||
static physx::PxMeshScale scale;
|
||||
pxSetVec3Ext(scale.scale, getSharedBody().getNode().worldScale);
|
||||
scale.scale.y *= std::max(0.0001F, _mData.height / 2);
|
||||
const auto xz = std::max(0.0001F, _mData.radius * 2);
|
||||
scale.scale.x *= xz;
|
||||
scale.scale.z *= xz;
|
||||
Quaternion quat;
|
||||
switch (_mData.direction) {
|
||||
case EAxisDirection::X_AXIS:
|
||||
quat.set(Vec3::UNIT_Z, physx::PxPiDivTwo);
|
||||
pxSetQuatExt(scale.rotation, quat);
|
||||
break;
|
||||
case EAxisDirection::Y_AXIS:
|
||||
default:
|
||||
scale.rotation = physx::PxQuat{physx::PxIdentity};
|
||||
break;
|
||||
case EAxisDirection::Z_AXIS:
|
||||
quat.set(Vec3::UNIT_X, physx::PxPiDivTwo);
|
||||
pxSetQuatExt(scale.rotation, quat);
|
||||
break;
|
||||
}
|
||||
physx::PxConvexMeshGeometry geom;
|
||||
if (getShape().getConvexMeshGeometry(geom)) {
|
||||
geom.scale = scale;
|
||||
getShape().setGeometry(geom);
|
||||
}
|
||||
pxSetQuatExt(_mRotation, quat);
|
||||
}
|
||||
|
||||
void PhysXCone::updateScale() {
|
||||
updateGeometry();
|
||||
updateCenter();
|
||||
}
|
||||
|
||||
} // namespace physics
|
||||
} // namespace cc
|
||||
55
native/cocos/physics/physx/shapes/PhysXCone.h
Normal file
55
native/cocos/physics/physx/shapes/PhysXCone.h
Normal file
@@ -0,0 +1,55 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2020-2021 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "physics/physx/shapes/PhysXShape.h"
|
||||
|
||||
namespace cc {
|
||||
namespace physics {
|
||||
|
||||
class PhysXCone final : public PhysXShape, public IConeShape {
|
||||
public:
|
||||
PhysXCone();
|
||||
~PhysXCone() override = default;
|
||||
void setConvex(uintptr_t handle) override;
|
||||
void setCone(float r, float h, EAxisDirection d) override;
|
||||
void updateScale() override;
|
||||
|
||||
struct Cone {
|
||||
float radius;
|
||||
float height;
|
||||
EAxisDirection direction;
|
||||
};
|
||||
|
||||
private:
|
||||
physx::PxConvexMesh *_mMesh;
|
||||
Cone _mData;
|
||||
void updateGeometry();
|
||||
void onComponentSet() override;
|
||||
};
|
||||
|
||||
} // namespace physics
|
||||
} // namespace cc
|
||||
101
native/cocos/physics/physx/shapes/PhysXCylinder.cpp
Normal file
101
native/cocos/physics/physx/shapes/PhysXCylinder.cpp
Normal file
@@ -0,0 +1,101 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2020-2021 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "physics/physx/shapes/PhysXShape.h"
|
||||
#include "physics/physx/shapes/PhysXCylinder.h"
|
||||
#include "physics/physx/PhysXUtils.h"
|
||||
#include "physics/physx/PhysXWorld.h"
|
||||
#include "math/Quaternion.h"
|
||||
#include "renderer/pipeline/helper/SharedMemory.h"
|
||||
#include <algorithm>
|
||||
|
||||
namespace cc {
|
||||
namespace physics {
|
||||
|
||||
PhysXCylinder::PhysXCylinder() : _mMesh(nullptr){};
|
||||
|
||||
void PhysXCylinder::setConvex(uintptr_t handle) {
|
||||
if (reinterpret_cast<uintptr_t>(_mMesh) == handle) return;
|
||||
_mMesh = reinterpret_cast<physx::PxConvexMesh *>(handle);
|
||||
if (_mShape) {
|
||||
// TODO(Administrator): ...
|
||||
}
|
||||
}
|
||||
|
||||
void PhysXCylinder::onComponentSet() {
|
||||
if (_mMesh) {
|
||||
physx::PxConvexMeshGeometry geom;
|
||||
geom.convexMesh = _mMesh;
|
||||
// geom.meshFlags = PxConvexMeshGeometryFlags::eTIGHT_BOUNDS;
|
||||
_mShape = PxGetPhysics().createShape(geom, getDefaultMaterial(), true);
|
||||
updateGeometry();
|
||||
}
|
||||
}
|
||||
|
||||
void PhysXCylinder::setCylinder(float r, float h, EAxisDirection d) {
|
||||
_mData.radius = r;
|
||||
_mData.height = h;
|
||||
_mData.direction = d;
|
||||
updateGeometry();
|
||||
}
|
||||
|
||||
void PhysXCylinder::updateGeometry() {
|
||||
if (!_mShape) return;
|
||||
static physx::PxMeshScale scale;
|
||||
pxSetVec3Ext(scale.scale, getSharedBody().getNode().worldScale);
|
||||
scale.scale.y *= std::max(0.0001F, _mData.height / 2);
|
||||
const auto xz = std::max(0.0001F, _mData.radius * 2);
|
||||
scale.scale.x *= xz;
|
||||
scale.scale.z *= xz;
|
||||
Quaternion quat;
|
||||
switch (_mData.direction) {
|
||||
case EAxisDirection::X_AXIS:
|
||||
quat.set(Vec3::UNIT_Z, physx::PxPiDivTwo);
|
||||
pxSetQuatExt(scale.rotation, quat);
|
||||
break;
|
||||
case EAxisDirection::Y_AXIS:
|
||||
default:
|
||||
scale.rotation = physx::PxQuat{physx::PxIdentity};
|
||||
break;
|
||||
case EAxisDirection::Z_AXIS:
|
||||
quat.set(Vec3::UNIT_X, physx::PxPiDivTwo);
|
||||
pxSetQuatExt(scale.rotation, quat);
|
||||
break;
|
||||
}
|
||||
physx::PxConvexMeshGeometry geom;
|
||||
if (getShape().getConvexMeshGeometry(geom)) {
|
||||
geom.scale = scale;
|
||||
getShape().setGeometry(geom);
|
||||
}
|
||||
pxSetQuatExt(_mRotation, quat);
|
||||
}
|
||||
|
||||
void PhysXCylinder::updateScale() {
|
||||
updateGeometry();
|
||||
updateCenter();
|
||||
}
|
||||
|
||||
} // namespace physics
|
||||
} // namespace cc
|
||||
55
native/cocos/physics/physx/shapes/PhysXCylinder.h
Normal file
55
native/cocos/physics/physx/shapes/PhysXCylinder.h
Normal file
@@ -0,0 +1,55 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2020-2021 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "physics/physx/shapes/PhysXShape.h"
|
||||
|
||||
namespace cc {
|
||||
namespace physics {
|
||||
|
||||
class PhysXCylinder final : public PhysXShape, public ICylinderShape {
|
||||
public:
|
||||
PhysXCylinder();
|
||||
~PhysXCylinder() override = default;
|
||||
void setConvex(uintptr_t handle) override;
|
||||
void setCylinder(float r, float h, EAxisDirection d) override;
|
||||
void updateScale() override;
|
||||
|
||||
struct Cylinder {
|
||||
float radius;
|
||||
float height;
|
||||
EAxisDirection direction;
|
||||
};
|
||||
|
||||
private:
|
||||
physx::PxConvexMesh *_mMesh;
|
||||
Cylinder _mData;
|
||||
void updateGeometry();
|
||||
void onComponentSet() override;
|
||||
};
|
||||
|
||||
} // namespace physics
|
||||
} // namespace cc
|
||||
67
native/cocos/physics/physx/shapes/PhysXPlane.cpp
Normal file
67
native/cocos/physics/physx/shapes/PhysXPlane.cpp
Normal file
@@ -0,0 +1,67 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2020-2021 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "physics/physx/shapes/PhysXShape.h"
|
||||
#include "physics/physx/shapes/PhysXPlane.h"
|
||||
#include "physics/physx/PhysXUtils.h"
|
||||
#include "physics/physx/PhysXWorld.h"
|
||||
|
||||
namespace cc {
|
||||
namespace physics {
|
||||
|
||||
PhysXPlane::PhysXPlane() : _mConstant(0.F),
|
||||
_mNormal(0.F, 1.F, 0.F)
|
||||
{};
|
||||
|
||||
void PhysXPlane::setConstant(float x) {
|
||||
_mConstant = x;
|
||||
updateCenter();
|
||||
}
|
||||
|
||||
void PhysXPlane::setNormal(float x, float y, float z) {
|
||||
_mNormal = physx::PxVec3{x, y, z};
|
||||
updateCenter();
|
||||
}
|
||||
|
||||
void PhysXPlane::onComponentSet() {
|
||||
_mShape = PxGetPhysics().createShape(getPxGeometry<physx::PxPlaneGeometry>(), getDefaultMaterial(), true);
|
||||
updateCenter();
|
||||
}
|
||||
|
||||
void PhysXPlane::updateScale() {
|
||||
updateCenter();
|
||||
}
|
||||
|
||||
void PhysXPlane::updateCenter() {
|
||||
auto &node = getSharedBody().getNode();
|
||||
auto &geo = getPxGeometry<physx::PxPlaneGeometry>();
|
||||
physx::PxTransform local;
|
||||
pxSetFromTwoVectors(local.q, physx::PxVec3{1.F, 0.F, 0.F}, _mNormal);
|
||||
local.p = _mNormal * _mConstant + _mCenter;
|
||||
getShape().setLocalPose(local);
|
||||
}
|
||||
|
||||
} // namespace physics
|
||||
} // namespace cc
|
||||
49
native/cocos/physics/physx/shapes/PhysXPlane.h
Normal file
49
native/cocos/physics/physx/shapes/PhysXPlane.h
Normal file
@@ -0,0 +1,49 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2020-2021 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "physics/physx/shapes/PhysXShape.h"
|
||||
|
||||
namespace cc {
|
||||
namespace physics {
|
||||
|
||||
class PhysXPlane final : public PhysXShape, public IPlaneShape {
|
||||
public:
|
||||
PhysXPlane();
|
||||
~PhysXPlane() override = default;
|
||||
void setConstant(float x) override;
|
||||
void setNormal(float x, float y, float z) override;
|
||||
void updateScale() override;
|
||||
|
||||
private:
|
||||
physx::PxVec3 _mNormal;
|
||||
physx::PxReal _mConstant;
|
||||
void updateCenter() override;
|
||||
void onComponentSet() override;
|
||||
};
|
||||
|
||||
} // namespace physics
|
||||
} // namespace cc
|
||||
126
native/cocos/physics/physx/shapes/PhysXShape.cpp
Normal file
126
native/cocos/physics/physx/shapes/PhysXShape.cpp
Normal file
@@ -0,0 +1,126 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2020-2021 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "physics/physx/shapes/PhysXShape.h"
|
||||
#include "physics/physx/PhysXSharedBody.h"
|
||||
#include "physics/physx/PhysXUtils.h"
|
||||
#include "physics/physx/PhysXWorld.h"
|
||||
#include <unordered_map>
|
||||
|
||||
namespace cc {
|
||||
namespace physics {
|
||||
|
||||
void PhysXShape::initialize(uint handle) {
|
||||
PhysXWorld &ins = PhysXWorld::getInstance();
|
||||
_mSharedBody = ins.getSharedBody(handle);
|
||||
getSharedBody().reference(true);
|
||||
onComponentSet();
|
||||
getPxShapeMap().insert(std::pair<uintptr_t, uintptr_t>(reinterpret_cast<uintptr_t>(&getShape()), getImpl()));
|
||||
}
|
||||
|
||||
void PhysXShape::onEnable() {
|
||||
_mEnabled = true;
|
||||
getSharedBody().addShape(*this);
|
||||
getSharedBody().enabled(true);
|
||||
}
|
||||
|
||||
void PhysXShape::onDisable() {
|
||||
_mEnabled = false;
|
||||
getSharedBody().removeShape(*this);
|
||||
getSharedBody().enabled(false);
|
||||
}
|
||||
|
||||
void PhysXShape::onDestroy() {
|
||||
getSharedBody().reference(false);
|
||||
getPxShapeMap().erase(reinterpret_cast<uintptr_t>(&getShape()));
|
||||
}
|
||||
|
||||
void PhysXShape::setMaterial(uint16_t id, float f, float df, float r,
|
||||
uint8_t m0, uint8_t m1) {
|
||||
auto *mat = reinterpret_cast<physx::PxMaterial *>(getSharedBody().getWorld().createMaterial(id, f, df, r, m0, m1));
|
||||
getShape().setMaterials(&mat, 1);
|
||||
}
|
||||
|
||||
void PhysXShape::setAsTrigger(bool v) {
|
||||
if (v) {
|
||||
getShape().setFlag(physx::PxShapeFlag::eSIMULATION_SHAPE, !v);
|
||||
getShape().setFlag(physx::PxShapeFlag::eTRIGGER_SHAPE, v);
|
||||
} else {
|
||||
getShape().setFlag(physx::PxShapeFlag::eTRIGGER_SHAPE, v);
|
||||
getShape().setFlag(physx::PxShapeFlag::eSIMULATION_SHAPE, !v);
|
||||
}
|
||||
if (_mIndex >= 0) {
|
||||
getSharedBody().removeShape(*this);
|
||||
getSharedBody().addShape(*this);
|
||||
}
|
||||
}
|
||||
|
||||
void PhysXShape::setCenter(float x, float y, float z) {
|
||||
_mCenter = physx::PxVec3{x, y, z};
|
||||
updateCenter();
|
||||
}
|
||||
|
||||
uint32_t PhysXShape::getGroup() {
|
||||
return getSharedBody().getGroup();
|
||||
}
|
||||
|
||||
void PhysXShape::setGroup(uint32_t g) {
|
||||
getSharedBody().setGroup(g);
|
||||
}
|
||||
|
||||
uint32_t PhysXShape::getMask() {
|
||||
return getSharedBody().getMask();
|
||||
}
|
||||
|
||||
void PhysXShape::setMask(uint32_t m) {
|
||||
getSharedBody().setMask(m);
|
||||
}
|
||||
|
||||
void PhysXShape::updateEventListener(EShapeFilterFlag flag) {
|
||||
}
|
||||
|
||||
cc::pipeline::AABB& PhysXShape::getAABB() {
|
||||
static cc::pipeline::AABB aabb;
|
||||
return aabb;
|
||||
}
|
||||
|
||||
cc::pipeline::Sphere& PhysXShape::getBoundingSphere() {
|
||||
static cc::pipeline::Sphere s;
|
||||
return s;
|
||||
}
|
||||
|
||||
void PhysXShape::updateFilterData(physx::PxFilterData &data) {
|
||||
}
|
||||
|
||||
void PhysXShape::updateCenter() {
|
||||
auto &sb = getSharedBody();
|
||||
auto &node = sb.getNode();
|
||||
physx::PxTransform local{_mCenter * node.worldScale, _mRotation};
|
||||
getShape().setLocalPose(local);
|
||||
if (_mEnabled && !isTrigger()) sb.updateCenterOfMass();
|
||||
}
|
||||
|
||||
} // namespace physics
|
||||
} // namespace cc
|
||||
87
native/cocos/physics/physx/shapes/PhysXShape.h
Normal file
87
native/cocos/physics/physx/shapes/PhysXShape.h
Normal file
@@ -0,0 +1,87 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2020-2021 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "physics/physx/PhysXInc.h"
|
||||
#include "physics/spec/IShape.h"
|
||||
#include "base/Macros.h"
|
||||
|
||||
namespace cc {
|
||||
namespace physics {
|
||||
class PhysXSharedBody;
|
||||
|
||||
template <typename T>
|
||||
CC_INLINE T &getPxGeometry() {
|
||||
static T geo;
|
||||
return geo;
|
||||
}
|
||||
|
||||
class PhysXShape : virtual public IBaseShape {
|
||||
PX_NOCOPY(PhysXShape)
|
||||
PhysXShape() : _mCenter(physx::PxIdentity),
|
||||
_mRotation(physx::PxIdentity){};
|
||||
|
||||
public:
|
||||
~PhysXShape() override = default;
|
||||
CC_INLINE uintptr_t getImpl() override { return reinterpret_cast<uintptr_t>(this); }
|
||||
void initialize(uint handle) override;
|
||||
void onEnable() override;
|
||||
void onDisable() override;
|
||||
void onDestroy() override;
|
||||
void setMaterial(uint16_t id, float f, float df, float r,
|
||||
uint8_t m0, uint8_t m1) override;
|
||||
void setAsTrigger(bool v) override;
|
||||
void setCenter(float x, float y, float z) override;
|
||||
cc::pipeline::AABB & getAABB() override;
|
||||
cc::pipeline::Sphere &getBoundingSphere() override;
|
||||
void updateEventListener(EShapeFilterFlag flag) override;
|
||||
uint32_t getGroup() override;
|
||||
void setGroup(uint32_t g) override;
|
||||
uint32_t getMask() override;
|
||||
void setMask(uint32_t m) override;
|
||||
virtual void updateScale() = 0;
|
||||
CC_INLINE physx::PxVec3 &getCenter() { return _mCenter; }
|
||||
CC_INLINE physx::PxShape &getShape() const { return *_mShape; }
|
||||
CC_INLINE PhysXSharedBody &getSharedBody() const { return *_mSharedBody; }
|
||||
CC_INLINE bool isTrigger() const {
|
||||
return getShape().getFlags().isSet(physx::PxShapeFlag::eTRIGGER_SHAPE);
|
||||
}
|
||||
void updateFilterData(physx::PxFilterData &data);
|
||||
|
||||
protected:
|
||||
PhysXSharedBody *_mSharedBody{nullptr};
|
||||
physx::PxShape * _mShape{nullptr};
|
||||
physx::PxVec3 _mCenter;
|
||||
physx::PxQuat _mRotation;
|
||||
int8_t _mIndex{-1};
|
||||
uint8_t _mFlag{0};
|
||||
bool _mEnabled{false};
|
||||
virtual void updateCenter();
|
||||
virtual void onComponentSet() = 0;
|
||||
};
|
||||
|
||||
} // namespace physics
|
||||
} // namespace cc
|
||||
62
native/cocos/physics/physx/shapes/PhysXSphere.cpp
Normal file
62
native/cocos/physics/physx/shapes/PhysXSphere.cpp
Normal file
@@ -0,0 +1,62 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2020-2021 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "physics/physx/shapes/PhysXShape.h"
|
||||
#include "physics/physx/shapes/PhysXSphere.h"
|
||||
#include "physics/physx/PhysXUtils.h"
|
||||
#include "physics/physx/PhysXWorld.h"
|
||||
|
||||
namespace cc {
|
||||
namespace physics {
|
||||
|
||||
PhysXSphere::PhysXSphere() : _mRadius(0.5F),
|
||||
PhysXShape(){};
|
||||
|
||||
void PhysXSphere::setRadius(float r) {
|
||||
_mRadius = r;
|
||||
updateGeometry();
|
||||
getShape().setGeometry(getPxGeometry<physx::PxSphereGeometry>());
|
||||
}
|
||||
|
||||
void PhysXSphere::onComponentSet() {
|
||||
updateGeometry();
|
||||
_mShape = PxGetPhysics().createShape(getPxGeometry<physx::PxSphereGeometry>(), getDefaultMaterial(), true);
|
||||
}
|
||||
|
||||
void PhysXSphere::updateScale() {
|
||||
updateGeometry();
|
||||
getShape().setGeometry(getPxGeometry<physx::PxSphereGeometry>());
|
||||
updateCenter();
|
||||
}
|
||||
|
||||
void PhysXSphere::updateGeometry() {
|
||||
physx::PxVec3 scale;
|
||||
pxSetVec3Ext(scale, getSharedBody().getNode().worldScale);
|
||||
auto &geo = getPxGeometry<physx::PxSphereGeometry>();
|
||||
geo.radius = physx::PxMax(_mRadius * scale.abs().maxElement(), PX_NORMALIZATION_EPSILON);
|
||||
}
|
||||
|
||||
} // namespace physics
|
||||
} // namespace cc
|
||||
47
native/cocos/physics/physx/shapes/PhysXSphere.h
Normal file
47
native/cocos/physics/physx/shapes/PhysXSphere.h
Normal file
@@ -0,0 +1,47 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2020-2021 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "physics/physx/shapes/PhysXShape.h"
|
||||
|
||||
namespace cc {
|
||||
namespace physics {
|
||||
|
||||
class PhysXSphere final : public PhysXShape, public ISphereShape {
|
||||
public:
|
||||
PhysXSphere();
|
||||
~PhysXSphere() override = default;
|
||||
void setRadius(float r) override;
|
||||
void updateScale() override;
|
||||
|
||||
private:
|
||||
float _mRadius;
|
||||
void updateGeometry();
|
||||
void onComponentSet() override;
|
||||
};
|
||||
|
||||
} // namespace physics
|
||||
} // namespace cc
|
||||
70
native/cocos/physics/physx/shapes/PhysXTerrain.cpp
Normal file
70
native/cocos/physics/physx/shapes/PhysXTerrain.cpp
Normal file
@@ -0,0 +1,70 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2020-2021 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "physics/physx/shapes/PhysXShape.h"
|
||||
#include "physics/physx/shapes/PhysXTerrain.h"
|
||||
#include "physics/physx/PhysXUtils.h"
|
||||
#include "physics/physx/PhysXWorld.h"
|
||||
#include "renderer/pipeline/helper/SharedMemory.h"
|
||||
|
||||
namespace cc {
|
||||
namespace physics {
|
||||
|
||||
PhysXTerrain::PhysXTerrain() : _mTerrain(nullptr),
|
||||
_mRowScale(1.F),
|
||||
_mColScale(1.F),
|
||||
_mHeightScale(1.F){};
|
||||
|
||||
void PhysXTerrain::setTerrain(uintptr_t handle, float rs, float cs, float hs) {
|
||||
if (reinterpret_cast<uintptr_t>(_mTerrain) == handle) return;
|
||||
_mTerrain = reinterpret_cast<physx::PxHeightField *>(handle);
|
||||
_mRowScale = rs;
|
||||
_mColScale = cs;
|
||||
_mHeightScale = hs;
|
||||
if (_mShape) {
|
||||
}
|
||||
}
|
||||
|
||||
void PhysXTerrain::onComponentSet() {
|
||||
if (_mTerrain) {
|
||||
physx::PxHeightFieldGeometry geom;
|
||||
geom.rowScale = _mRowScale;
|
||||
geom.columnScale = _mColScale;
|
||||
geom.heightScale = _mHeightScale;
|
||||
geom.heightField = _mTerrain;
|
||||
_mShape = PxGetPhysics().createShape(geom, getDefaultMaterial(), true);
|
||||
}
|
||||
}
|
||||
|
||||
void PhysXTerrain::updateScale() {
|
||||
// updateCenter(); needed?
|
||||
}
|
||||
|
||||
void PhysXTerrain::updateCenter() {
|
||||
getShape().setLocalPose(physx::PxTransform{_mCenter, _mRotation});
|
||||
}
|
||||
|
||||
} // namespace physics
|
||||
} // namespace cc
|
||||
50
native/cocos/physics/physx/shapes/PhysXTerrain.h
Normal file
50
native/cocos/physics/physx/shapes/PhysXTerrain.h
Normal file
@@ -0,0 +1,50 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2020-2021 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "physics/physx/shapes/PhysXShape.h"
|
||||
|
||||
namespace cc {
|
||||
namespace physics {
|
||||
|
||||
class PhysXTerrain final : public PhysXShape, public ITerrainShape {
|
||||
public:
|
||||
PhysXTerrain();
|
||||
~PhysXTerrain() override = default;
|
||||
void setTerrain(uintptr_t handle, float rs, float cs, float hs) override;
|
||||
void updateScale() override;
|
||||
void updateCenter() override;
|
||||
|
||||
private:
|
||||
physx::PxHeightField *_mTerrain;
|
||||
float _mRowScale;
|
||||
float _mColScale;
|
||||
float _mHeightScale;
|
||||
void onComponentSet() override;
|
||||
};
|
||||
|
||||
} // namespace physics
|
||||
} // namespace cc
|
||||
96
native/cocos/physics/physx/shapes/PhysXTrimesh.cpp
Normal file
96
native/cocos/physics/physx/shapes/PhysXTrimesh.cpp
Normal file
@@ -0,0 +1,96 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2020-2021 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "physics/physx/shapes/PhysXShape.h"
|
||||
#include "physics/physx/shapes/PhysXTrimesh.h"
|
||||
#include "physics/physx/PhysXUtils.h"
|
||||
#include "physics/physx/PhysXWorld.h"
|
||||
#include "renderer/pipeline/helper/SharedMemory.h"
|
||||
|
||||
namespace cc {
|
||||
namespace physics {
|
||||
|
||||
PhysXTrimesh::PhysXTrimesh() : _mMeshHandle(0),
|
||||
_mConvex(false){};
|
||||
|
||||
void PhysXTrimesh::setMesh(uintptr_t handle) {
|
||||
if (_mMeshHandle == handle) return;
|
||||
_mMeshHandle = handle;
|
||||
if (_mShape) {
|
||||
}
|
||||
}
|
||||
|
||||
void PhysXTrimesh::useConvex(bool v) {
|
||||
if (_mConvex == v) return;
|
||||
_mConvex = v;
|
||||
if (_mShape) {
|
||||
}
|
||||
}
|
||||
|
||||
void PhysXTrimesh::onComponentSet() {
|
||||
if (_mMeshHandle) {
|
||||
const auto &mat = getDefaultMaterial();
|
||||
if (_mConvex) {
|
||||
physx::PxConvexMeshGeometry geom;
|
||||
geom.convexMesh = reinterpret_cast<physx::PxConvexMesh *>(_mMeshHandle);
|
||||
// geom.meshFlags = PxConvexMeshGeometryFlags::eTIGHT_BOUNDS;
|
||||
_mShape = PxGetPhysics().createShape(geom, mat, true);
|
||||
} else {
|
||||
physx::PxTriangleMeshGeometry geom;
|
||||
geom.triangleMesh = reinterpret_cast<physx::PxTriangleMesh *>(_mMeshHandle);
|
||||
// geom.meshFlags = PxMeshGeometryFlag::eDOUBLE_SIDED;
|
||||
_mShape = PxGetPhysics().createShape(geom, mat, true);
|
||||
}
|
||||
updateGeometry();
|
||||
}
|
||||
}
|
||||
|
||||
void PhysXTrimesh::updateScale() {
|
||||
updateGeometry();
|
||||
updateCenter();
|
||||
}
|
||||
|
||||
void PhysXTrimesh::updateGeometry() {
|
||||
static physx::PxMeshScale scale;
|
||||
scale.rotation = physx::PxQuat{physx::PxIdentity};
|
||||
pxSetVec3Ext(scale.scale, getSharedBody().getNode().worldScale);
|
||||
const auto &type = _mShape->getGeometryType();
|
||||
if (type == physx::PxGeometryType::eCONVEXMESH) {
|
||||
physx::PxConvexMeshGeometry geom;
|
||||
if (getShape().getConvexMeshGeometry(geom)) {
|
||||
geom.scale = scale;
|
||||
getShape().setGeometry(geom);
|
||||
}
|
||||
} else if (type == physx::PxGeometryType::eTRIANGLEMESH) {
|
||||
physx::PxTriangleMeshGeometry geom;
|
||||
if (getShape().getTriangleMeshGeometry(geom)) {
|
||||
geom.scale = scale;
|
||||
getShape().setGeometry(geom);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace physics
|
||||
} // namespace cc
|
||||
49
native/cocos/physics/physx/shapes/PhysXTrimesh.h
Normal file
49
native/cocos/physics/physx/shapes/PhysXTrimesh.h
Normal file
@@ -0,0 +1,49 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2020-2021 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "physics/physx/shapes/PhysXShape.h"
|
||||
|
||||
namespace cc {
|
||||
namespace physics {
|
||||
|
||||
class PhysXTrimesh final : public PhysXShape, public ITrimeshShape {
|
||||
public:
|
||||
PhysXTrimesh();
|
||||
~PhysXTrimesh() override = default;
|
||||
void setMesh(uintptr_t handle) override;
|
||||
void useConvex(bool v) override;
|
||||
void updateScale() override;
|
||||
|
||||
private:
|
||||
bool _mConvex;
|
||||
uintptr_t _mMeshHandle;
|
||||
void updateGeometry();
|
||||
void onComponentSet() override;
|
||||
};
|
||||
|
||||
} // namespace physics
|
||||
} // namespace cc
|
||||
98
native/cocos/physics/sdk/Joint.cpp
Normal file
98
native/cocos/physics/sdk/Joint.cpp
Normal file
@@ -0,0 +1,98 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2020-2021 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "physics/PhysicsSelector.h"
|
||||
#include "physics/sdk/Joint.h"
|
||||
|
||||
#define CC_PHYSICS_JOINT_DEFINITION(CLASS, WRAPPED) \
|
||||
\
|
||||
CLASS::CLASS() { \
|
||||
_impl.reset(new WRAPPED()); \
|
||||
} \
|
||||
\
|
||||
CLASS::~CLASS() { \
|
||||
_impl.reset(nullptr); \
|
||||
} \
|
||||
\
|
||||
uintptr_t CLASS::getImpl() { \
|
||||
return _impl->getImpl(); \
|
||||
} \
|
||||
\
|
||||
void CLASS::initialize(uint h) { \
|
||||
_impl->initialize(h); \
|
||||
} \
|
||||
\
|
||||
void CLASS::onEnable() { \
|
||||
_impl->onEnable(); \
|
||||
} \
|
||||
\
|
||||
void CLASS::onDisable() { \
|
||||
_impl->onDisable(); \
|
||||
} \
|
||||
\
|
||||
void CLASS::onDestroy() { \
|
||||
_impl->onDestroy(); \
|
||||
} \
|
||||
\
|
||||
void CLASS::setConnectedBody(uint v) { \
|
||||
_impl->setConnectedBody(v); \
|
||||
} \
|
||||
\
|
||||
void CLASS::setEnableCollision(bool v) { \
|
||||
_impl->setEnableCollision(v); \
|
||||
}
|
||||
|
||||
namespace cc {
|
||||
namespace physics {
|
||||
|
||||
/// COMMON ///
|
||||
|
||||
CC_PHYSICS_JOINT_DEFINITION(DistanceJoint, WrappedDistanceJoint)
|
||||
CC_PHYSICS_JOINT_DEFINITION(RevoluteJoint, WrappedRevoluteJoint)
|
||||
|
||||
/// EXTRAS ///
|
||||
|
||||
void DistanceJoint::setPivotA(float x, float y, float z) {
|
||||
_impl->setPivotA(x, y, z);
|
||||
}
|
||||
|
||||
void DistanceJoint::setPivotB(float x, float y, float z) {
|
||||
_impl->setPivotB(x, y, z);
|
||||
}
|
||||
|
||||
void RevoluteJoint::setPivotA(float x, float y, float z) {
|
||||
_impl->setPivotA(x, y, z);
|
||||
}
|
||||
|
||||
void RevoluteJoint::setPivotB(float x, float y, float z) {
|
||||
_impl->setPivotB(x, y, z);
|
||||
}
|
||||
|
||||
void RevoluteJoint::setAxis(float x, float y, float z) {
|
||||
_impl->setAxis(x, y, z);
|
||||
}
|
||||
|
||||
} // namespace physics
|
||||
} // namespace cc
|
||||
65
native/cocos/physics/sdk/Joint.h
Normal file
65
native/cocos/physics/sdk/Joint.h
Normal file
@@ -0,0 +1,65 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2020-2021 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "physics/spec/IJoint.h"
|
||||
#include "base/Macros.h"
|
||||
#include "renderer/pipeline/helper/SharedMemory.h"
|
||||
#include <memory>
|
||||
#include <cstdint>
|
||||
|
||||
#define CC_PHYSICS_JOINT_CLASS(CLASS) \
|
||||
class CC_DLL CLASS final : virtual public I##CLASS { \
|
||||
protected: \
|
||||
std::unique_ptr<I##CLASS> _impl; \
|
||||
\
|
||||
public: \
|
||||
CLASS(); \
|
||||
~CLASS() override; \
|
||||
uintptr_t getImpl() override; \
|
||||
void initialize(uint h) override; \
|
||||
void onEnable() override; \
|
||||
void onDisable() override; \
|
||||
void onDestroy() override; \
|
||||
void setEnableCollision(bool v) override; \
|
||||
void setConnectedBody(uint v) override;
|
||||
|
||||
namespace cc {
|
||||
namespace physics {
|
||||
|
||||
CC_PHYSICS_JOINT_CLASS(RevoluteJoint)
|
||||
void setPivotA(float x, float y, float z) override;
|
||||
void setPivotB(float x, float y, float z) override;
|
||||
void setAxis(float x, float y, float z) override;
|
||||
};
|
||||
|
||||
CC_PHYSICS_JOINT_CLASS(DistanceJoint)
|
||||
void setPivotA(float x, float y, float z) override;
|
||||
void setPivotB(float x, float y, float z) override;
|
||||
};
|
||||
|
||||
} // namespace physics
|
||||
} // namespace cc
|
||||
186
native/cocos/physics/sdk/RigidBody.cpp
Normal file
186
native/cocos/physics/sdk/RigidBody.cpp
Normal file
@@ -0,0 +1,186 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2020-2021 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "physics/PhysicsSelector.h"
|
||||
#include "physics/sdk/RigidBody.h"
|
||||
#include <memory>
|
||||
|
||||
namespace cc {
|
||||
namespace physics {
|
||||
|
||||
RigidBody::RigidBody() {
|
||||
_impl = std::make_unique<WrappedRigidBody>();
|
||||
}
|
||||
|
||||
RigidBody::~RigidBody() {
|
||||
_impl.reset(nullptr);
|
||||
}
|
||||
|
||||
void RigidBody::initialize(const uint h, const ERigidBodyType t, const uint32_t g) {
|
||||
_impl->initialize(h, t, g);
|
||||
}
|
||||
|
||||
void RigidBody::onEnable() {
|
||||
_impl->onEnable();
|
||||
}
|
||||
|
||||
void RigidBody::onDisable() {
|
||||
_impl->onDisable();
|
||||
}
|
||||
|
||||
void RigidBody::onDestroy() {
|
||||
_impl->onDestroy();
|
||||
}
|
||||
|
||||
bool RigidBody::isAwake() {
|
||||
return _impl->isAwake();
|
||||
}
|
||||
|
||||
bool RigidBody::isSleepy() {
|
||||
return _impl->isSleepy();
|
||||
}
|
||||
|
||||
bool RigidBody::isSleeping() {
|
||||
return _impl->isSleeping();
|
||||
}
|
||||
|
||||
void RigidBody::setType(ERigidBodyType v) {
|
||||
_impl->setType(v);
|
||||
}
|
||||
|
||||
void RigidBody::setMass(float v) {
|
||||
_impl->setMass(v);
|
||||
}
|
||||
|
||||
void RigidBody::setLinearDamping(float v) {
|
||||
_impl->setLinearDamping(v);
|
||||
}
|
||||
|
||||
void RigidBody::setAngularDamping(float v) {
|
||||
_impl->setAngularDamping(v);
|
||||
}
|
||||
|
||||
void RigidBody::useGravity(bool v) {
|
||||
_impl->useGravity(v);
|
||||
}
|
||||
|
||||
void RigidBody::setLinearFactor(float x, float y, float z) {
|
||||
_impl->setLinearFactor(x, y, z);
|
||||
}
|
||||
|
||||
void RigidBody::setAngularFactor(float x, float y, float z) {
|
||||
_impl->setAngularFactor(x, y, z);
|
||||
}
|
||||
|
||||
void RigidBody::setAllowSleep(bool v) {
|
||||
_impl->setAllowSleep(v);
|
||||
}
|
||||
|
||||
void RigidBody::wakeUp() {
|
||||
_impl->wakeUp();
|
||||
}
|
||||
|
||||
void RigidBody::sleep() {
|
||||
_impl->sleep();
|
||||
}
|
||||
|
||||
void RigidBody::clearState() {
|
||||
_impl->clearState();
|
||||
}
|
||||
|
||||
void RigidBody::clearForces() {
|
||||
_impl->clearForces();
|
||||
}
|
||||
|
||||
void RigidBody::clearVelocity() {
|
||||
_impl->clearVelocity();
|
||||
}
|
||||
|
||||
void RigidBody::setSleepThreshold(float v) {
|
||||
_impl->setSleepThreshold(v);
|
||||
}
|
||||
|
||||
float RigidBody::getSleepThreshold() {
|
||||
return _impl->getSleepThreshold();
|
||||
}
|
||||
|
||||
cc::Vec3 RigidBody::getLinearVelocity() {
|
||||
return _impl->getLinearVelocity();
|
||||
}
|
||||
|
||||
void RigidBody::setLinearVelocity(float x, float y, float z) {
|
||||
_impl->setLinearVelocity(x, y, z);
|
||||
}
|
||||
|
||||
cc::Vec3 RigidBody::getAngularVelocity() {
|
||||
return _impl->getAngularVelocity();
|
||||
}
|
||||
|
||||
void RigidBody::setAngularVelocity(float x, float y, float z) {
|
||||
_impl->setAngularVelocity(x, y, z);
|
||||
}
|
||||
|
||||
void RigidBody::applyForce(float x, float y, float z, float rx, float ry, float rz) {
|
||||
_impl->applyForce(x, y, z, rx, ry, rz);
|
||||
}
|
||||
|
||||
void RigidBody::applyLocalForce(float x, float y, float z, float rx, float ry, float rz) {
|
||||
_impl->applyLocalForce(x, y, z, rx, ry, rz);
|
||||
}
|
||||
|
||||
void RigidBody::applyImpulse(float x, float y, float z, float rx, float ry, float rz) {
|
||||
_impl->applyImpulse(x, y, z, rx, ry, rz);
|
||||
}
|
||||
|
||||
void RigidBody::applyLocalImpulse(float x, float y, float z, float rx, float ry, float rz) {
|
||||
_impl->applyLocalImpulse(x, y, z, rx, ry, rz);
|
||||
}
|
||||
|
||||
void RigidBody::applyTorque(float x, float y, float z) {
|
||||
_impl->applyTorque(x, y, z);
|
||||
}
|
||||
|
||||
void RigidBody::applyLocalTorque(float x, float y, float z) {
|
||||
_impl->applyLocalTorque(x, y, z);
|
||||
}
|
||||
|
||||
uint32_t RigidBody::getGroup() {
|
||||
return _impl->getGroup();
|
||||
}
|
||||
|
||||
void RigidBody::setGroup(uint32_t g) {
|
||||
_impl->setGroup(g);
|
||||
}
|
||||
|
||||
uint32_t RigidBody::getMask() {
|
||||
return _impl->getMask();
|
||||
}
|
||||
|
||||
void RigidBody::setMask(uint32_t m) {
|
||||
_impl->setMask(m);
|
||||
}
|
||||
|
||||
} // namespace physics
|
||||
} // namespace cc
|
||||
81
native/cocos/physics/sdk/RigidBody.h
Normal file
81
native/cocos/physics/sdk/RigidBody.h
Normal file
@@ -0,0 +1,81 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2020-2021 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "physics/spec/IBody.h"
|
||||
#include "base/Macros.h"
|
||||
#include <memory>
|
||||
|
||||
namespace cc {
|
||||
namespace physics {
|
||||
class CC_DLL RigidBody final : public IRigidBody {
|
||||
public:
|
||||
RigidBody();
|
||||
~RigidBody() override;
|
||||
CC_INLINE uintptr_t getImpl() override { return _impl->getImpl(); };
|
||||
CC_INLINE uint getNodeHandle() override { return _impl->getNodeHandle(); }
|
||||
void initialize(uint h, ERigidBodyType t, uint32_t g) override;
|
||||
void onEnable() override;
|
||||
void onDisable() override;
|
||||
void onDestroy() override;
|
||||
bool isAwake() override;
|
||||
bool isSleepy() override;
|
||||
bool isSleeping() override;
|
||||
void setType(ERigidBodyType v) override;
|
||||
void setMass(float v) override;
|
||||
void setLinearDamping(float v) override;
|
||||
void setAngularDamping(float v) override;
|
||||
void useGravity(bool v) override;
|
||||
void setLinearFactor(float x, float y, float z) override;
|
||||
void setAngularFactor(float x, float y, float z) override;
|
||||
void setAllowSleep(bool v) override;
|
||||
void wakeUp() override;
|
||||
void sleep() override;
|
||||
void clearState() override;
|
||||
void clearForces() override;
|
||||
void clearVelocity() override;
|
||||
void setSleepThreshold(float v) override;
|
||||
float getSleepThreshold() override;
|
||||
cc::Vec3 getLinearVelocity() override;
|
||||
void setLinearVelocity(float x, float y, float z) override;
|
||||
cc::Vec3 getAngularVelocity() override;
|
||||
void setAngularVelocity(float x, float y, float z) override;
|
||||
void applyForce(float x, float y, float z, float rx, float ry, float rz) override;
|
||||
void applyLocalForce(float x, float y, float z, float rx, float ry, float rz) override;
|
||||
void applyImpulse(float x, float y, float z, float rx, float ry, float rz) override;
|
||||
void applyLocalImpulse(float x, float y, float z, float rx, float ry, float rz) override;
|
||||
void applyTorque(float x, float y, float z) override;
|
||||
void applyLocalTorque(float x, float y, float z) override;
|
||||
uint32_t getGroup() override;
|
||||
void setGroup(uint32_t g) override;
|
||||
uint32_t getMask() override;
|
||||
void setMask(uint32_t m) override;
|
||||
|
||||
private:
|
||||
std::unique_ptr<IRigidBody> _impl;
|
||||
};
|
||||
} // namespace physics
|
||||
} // namespace cc
|
||||
174
native/cocos/physics/sdk/Shape.cpp
Normal file
174
native/cocos/physics/sdk/Shape.cpp
Normal file
@@ -0,0 +1,174 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2020-2021 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "physics/PhysicsSelector.h"
|
||||
#include "physics/sdk/Shape.h"
|
||||
|
||||
|
||||
#define CC_PHYSICS_SHAPE_DEFINITION(CLASS, WRAPPED) \
|
||||
\
|
||||
CLASS::CLASS() { \
|
||||
_impl.reset(new WRAPPED()); \
|
||||
} \
|
||||
\
|
||||
CLASS::~CLASS() { \
|
||||
_impl.reset(nullptr); \
|
||||
} \
|
||||
\
|
||||
uintptr_t CLASS::getImpl() { \
|
||||
return _impl->getImpl(); \
|
||||
} \
|
||||
\
|
||||
void CLASS::initialize(uint uuid) { \
|
||||
_impl->initialize(uuid); \
|
||||
} \
|
||||
\
|
||||
void CLASS::onEnable() { \
|
||||
_impl->onEnable(); \
|
||||
} \
|
||||
\
|
||||
void CLASS::onDisable() { \
|
||||
_impl->onDisable(); \
|
||||
} \
|
||||
\
|
||||
void CLASS::onDestroy() { \
|
||||
_impl->onDestroy(); \
|
||||
} \
|
||||
\
|
||||
void CLASS::setMaterial(uint16_t ID, float f, float df, float r, \
|
||||
uint8_t m0, uint8_t m1) { \
|
||||
_impl->setMaterial(ID, f, df, r, m0, m1); \
|
||||
} \
|
||||
\
|
||||
void CLASS::setAsTrigger(bool v) { \
|
||||
_impl->setAsTrigger(v); \
|
||||
} \
|
||||
\
|
||||
void CLASS::setCenter(float x, float y, float z) { \
|
||||
_impl->setCenter(x, y, z); \
|
||||
} \
|
||||
\
|
||||
void CLASS::setGroup(uint32_t g) { \
|
||||
_impl->setGroup(g); \
|
||||
} \
|
||||
\
|
||||
uint32_t CLASS::getGroup() { \
|
||||
return _impl->getGroup(); \
|
||||
} \
|
||||
\
|
||||
void CLASS::setMask(uint32_t m) { \
|
||||
_impl->setMask(m); \
|
||||
} \
|
||||
\
|
||||
uint32_t CLASS::getMask() { \
|
||||
return _impl->getMask(); \
|
||||
} \
|
||||
\
|
||||
void CLASS::updateEventListener(EShapeFilterFlag v) { \
|
||||
_impl->updateEventListener(v); \
|
||||
} \
|
||||
\
|
||||
cc::pipeline::AABB& CLASS::getAABB() { \
|
||||
return _impl->getAABB(); \
|
||||
} \
|
||||
\
|
||||
cc::pipeline::Sphere& CLASS::getBoundingSphere() { \
|
||||
return _impl->getBoundingSphere(); \
|
||||
}
|
||||
|
||||
namespace cc {
|
||||
namespace physics {
|
||||
|
||||
/// COMMON ///
|
||||
|
||||
CC_PHYSICS_SHAPE_DEFINITION(SphereShape, WrappedSphereShape)
|
||||
CC_PHYSICS_SHAPE_DEFINITION(BoxShape, WrappedBoxShape)
|
||||
CC_PHYSICS_SHAPE_DEFINITION(PlaneShape, WrappedPlaneShape)
|
||||
CC_PHYSICS_SHAPE_DEFINITION(CapsuleShape, WrappedCapsuleShape)
|
||||
CC_PHYSICS_SHAPE_DEFINITION(CylinderShape, WrappedCylinderShape)
|
||||
CC_PHYSICS_SHAPE_DEFINITION(ConeShape, WrappedConeShape)
|
||||
CC_PHYSICS_SHAPE_DEFINITION(TrimeshShape, WrappedTrimeshShape)
|
||||
CC_PHYSICS_SHAPE_DEFINITION(TerrainShape, WrappedTerrainShape)
|
||||
|
||||
/// EXTRAS ///
|
||||
|
||||
void SphereShape::setRadius(float v) {
|
||||
_impl->setRadius(v);
|
||||
}
|
||||
|
||||
void BoxShape::setSize(float x, float y, float z) {
|
||||
_impl->setSize(x, y, z);
|
||||
}
|
||||
|
||||
void CapsuleShape::setRadius(float v) {
|
||||
_impl->setRadius(v);
|
||||
}
|
||||
|
||||
void CapsuleShape::setCylinderHeight(float v) {
|
||||
_impl->setCylinderHeight(v);
|
||||
}
|
||||
|
||||
void CapsuleShape::setDirection(EAxisDirection v) {
|
||||
_impl->setDirection(v);
|
||||
}
|
||||
|
||||
void PlaneShape::setConstant(float v) {
|
||||
_impl->setConstant(v);
|
||||
}
|
||||
|
||||
void PlaneShape::setNormal(float x, float y, float z) {
|
||||
_impl->setNormal(x, y, z);
|
||||
}
|
||||
|
||||
void TrimeshShape::setMesh(uintptr_t v) {
|
||||
_impl->setMesh(v);
|
||||
}
|
||||
|
||||
void TrimeshShape::useConvex(bool v) {
|
||||
_impl->useConvex(v);
|
||||
}
|
||||
|
||||
void TerrainShape::setTerrain(uintptr_t v, float rs, float cs, float hs) {
|
||||
_impl->setTerrain(v, rs, cs, hs);
|
||||
}
|
||||
|
||||
void CylinderShape::setConvex(uintptr_t v) {
|
||||
_impl->setConvex(v);
|
||||
}
|
||||
|
||||
void CylinderShape::setCylinder(float r, float h, EAxisDirection d) {
|
||||
_impl->setCylinder(r, h, d);
|
||||
}
|
||||
|
||||
void ConeShape::setConvex(uintptr_t v) {
|
||||
_impl->setConvex(v);
|
||||
}
|
||||
|
||||
void ConeShape::setCone(float r, float h, EAxisDirection d) {
|
||||
_impl->setCone(r, h, d);
|
||||
}
|
||||
|
||||
} // namespace physics
|
||||
} // namespace cc
|
||||
101
native/cocos/physics/sdk/Shape.h
Normal file
101
native/cocos/physics/sdk/Shape.h
Normal file
@@ -0,0 +1,101 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2020-2021 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "physics/spec/IShape.h"
|
||||
#include "base/Macros.h"
|
||||
#include "renderer/pipeline/helper/SharedMemory.h"
|
||||
#include <memory>
|
||||
#include <cstdint>
|
||||
|
||||
#define CC_PHYSICS_SHAPE_CLASS(CLASS) \
|
||||
class CC_DLL CLASS final : public I##CLASS { \
|
||||
protected: \
|
||||
std::unique_ptr<I##CLASS> _impl; \
|
||||
\
|
||||
public: \
|
||||
CLASS(); \
|
||||
~CLASS() override; \
|
||||
uintptr_t getImpl() override; \
|
||||
void initialize(uint uuid) override; \
|
||||
void onEnable() override; \
|
||||
void onDisable() override; \
|
||||
void onDestroy() override; \
|
||||
void setMaterial(uint16_t ID, float f, float df, float r, \
|
||||
uint8_t m0, uint8_t m1) override; \
|
||||
void setAsTrigger(bool v) override; \
|
||||
void setCenter(float x, float y, float z) override; \
|
||||
void updateEventListener(EShapeFilterFlag v) override; \
|
||||
cc::pipeline::AABB& getAABB() override; \
|
||||
cc::pipeline::Sphere& getBoundingSphere() override; \
|
||||
uint32_t getGroup() override; \
|
||||
void setGroup(uint32_t g) override; \
|
||||
uint32_t getMask() override; \
|
||||
void setMask(uint32_t m) override;
|
||||
|
||||
namespace cc {
|
||||
namespace physics {
|
||||
|
||||
CC_PHYSICS_SHAPE_CLASS(SphereShape)
|
||||
void setRadius(float v) override;
|
||||
};
|
||||
|
||||
CC_PHYSICS_SHAPE_CLASS(BoxShape)
|
||||
void setSize(float x, float y, float z) override;
|
||||
};
|
||||
|
||||
CC_PHYSICS_SHAPE_CLASS(CapsuleShape)
|
||||
void setRadius(float v) override;
|
||||
void setCylinderHeight(float v) override;
|
||||
void setDirection(EAxisDirection v) override;
|
||||
};
|
||||
|
||||
CC_PHYSICS_SHAPE_CLASS(PlaneShape)
|
||||
void setConstant(float v) override;
|
||||
void setNormal(float x, float y, float z) override;
|
||||
};
|
||||
|
||||
CC_PHYSICS_SHAPE_CLASS(TrimeshShape)
|
||||
void setMesh(uintptr_t v) override;
|
||||
void useConvex(bool v) override;
|
||||
};
|
||||
|
||||
CC_PHYSICS_SHAPE_CLASS(CylinderShape)
|
||||
void setConvex(uintptr_t v) override;
|
||||
void setCylinder(float r, float h, EAxisDirection d) override;
|
||||
};
|
||||
|
||||
CC_PHYSICS_SHAPE_CLASS(ConeShape)
|
||||
void setConvex(uintptr_t v) override;
|
||||
void setCone(float r, float h, EAxisDirection d) override;
|
||||
};
|
||||
|
||||
CC_PHYSICS_SHAPE_CLASS(TerrainShape)
|
||||
void setTerrain(uintptr_t v, float rs, float cs, float hs) override;
|
||||
};
|
||||
|
||||
} // namespace physics
|
||||
} // namespace cc
|
||||
115
native/cocos/physics/sdk/World.cpp
Normal file
115
native/cocos/physics/sdk/World.cpp
Normal file
@@ -0,0 +1,115 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2020-2021 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "physics/PhysicsSelector.h"
|
||||
#include "physics/sdk/World.h"
|
||||
#include <memory>
|
||||
|
||||
namespace cc {
|
||||
namespace physics {
|
||||
|
||||
World::World() {
|
||||
_impl = std::make_unique<WrappedWorld>();
|
||||
}
|
||||
|
||||
World::~World() {
|
||||
_impl.reset(nullptr);
|
||||
}
|
||||
|
||||
void World::emitEvents() {
|
||||
_impl->emitEvents();
|
||||
}
|
||||
|
||||
void World::step(float fixedTimeStep) {
|
||||
_impl->step(fixedTimeStep);
|
||||
}
|
||||
|
||||
void World::setAllowSleep(bool v) {
|
||||
_impl->setAllowSleep(v);
|
||||
}
|
||||
|
||||
void World::setGravity(float x, float y, float z) {
|
||||
_impl->setGravity(x, y, z);
|
||||
}
|
||||
|
||||
uintptr_t World::createMaterial(uint16_t id, float f, float df, float r,
|
||||
uint8_t m0, uint8_t m1) {
|
||||
return _impl->createMaterial(id, f, df, r, m0, m1);
|
||||
}
|
||||
|
||||
void World::syncSceneToPhysics() {
|
||||
_impl->syncSceneToPhysics();
|
||||
}
|
||||
|
||||
void World::syncSceneWithCheck() {
|
||||
_impl->syncSceneWithCheck();
|
||||
}
|
||||
|
||||
void World::destroy() {
|
||||
_impl->destroy();
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<TriggerEventPair>> &World::getTriggerEventPairs() {
|
||||
return _impl->getTriggerEventPairs();
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<ContactEventPair>> &World::getContactEventPairs() {
|
||||
return _impl->getContactEventPairs();
|
||||
}
|
||||
|
||||
void World::setCollisionMatrix(uint32_t i, uint32_t m) {
|
||||
_impl->setCollisionMatrix(i, m);
|
||||
}
|
||||
|
||||
uintptr_t World::createConvex(ConvexDesc &desc) {
|
||||
return _impl->createConvex(desc);
|
||||
}
|
||||
|
||||
uintptr_t World::createTrimesh(TrimeshDesc &desc) {
|
||||
return _impl->createTrimesh(desc);
|
||||
}
|
||||
|
||||
uintptr_t World::createHeightField(HeightFieldDesc &desc) {
|
||||
return _impl->createHeightField(desc);
|
||||
}
|
||||
|
||||
bool World::raycast(RaycastOptions &opt) {
|
||||
return _impl->raycast(opt);
|
||||
}
|
||||
|
||||
std::vector<RaycastResult> &World::raycastResult() {
|
||||
return _impl->raycastResult();
|
||||
}
|
||||
|
||||
bool World::raycastClosest(RaycastOptions &opt) {
|
||||
return _impl->raycastClosest(opt);
|
||||
}
|
||||
|
||||
RaycastResult &World::raycastClosestResult() {
|
||||
return _impl->raycastClosestResult();
|
||||
}
|
||||
|
||||
} // namespace physics
|
||||
} // namespace cc
|
||||
62
native/cocos/physics/sdk/World.h
Normal file
62
native/cocos/physics/sdk/World.h
Normal file
@@ -0,0 +1,62 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2020-2021 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "physics/spec/IWorld.h"
|
||||
#include "base/Macros.h"
|
||||
#include <memory>
|
||||
|
||||
namespace cc {
|
||||
namespace physics {
|
||||
class CC_DLL World final : public IPhysicsWorld {
|
||||
public:
|
||||
World();
|
||||
~World() override;
|
||||
void setGravity(float x, float y, float z) override;
|
||||
void setAllowSleep(bool v) override;
|
||||
void step(float fixedTimeStep) override;
|
||||
void emitEvents() override;
|
||||
void syncSceneToPhysics() override;
|
||||
void syncSceneWithCheck() override;
|
||||
void setCollisionMatrix(uint32_t i, uint32_t m) override;
|
||||
std::vector<std::shared_ptr<TriggerEventPair>> &getTriggerEventPairs() override;
|
||||
std::vector<std::shared_ptr<ContactEventPair>> &getContactEventPairs() override;
|
||||
bool raycast(RaycastOptions &opt) override;
|
||||
bool raycastClosest(RaycastOptions &opt) override;
|
||||
std::vector<RaycastResult> &raycastResult() override;
|
||||
RaycastResult &raycastClosestResult() override;
|
||||
uintptr_t createConvex(ConvexDesc &desc) override;
|
||||
uintptr_t createTrimesh(TrimeshDesc &desc) override;
|
||||
uintptr_t createHeightField(HeightFieldDesc &desc) override;
|
||||
uintptr_t createMaterial(uint16_t id, float f, float df, float r,
|
||||
uint8_t m0, uint8_t m1) override;
|
||||
void destroy() override;
|
||||
|
||||
private:
|
||||
std::unique_ptr<IPhysicsWorld> _impl;
|
||||
};
|
||||
} // namespace physics
|
||||
} // namespace cc
|
||||
81
native/cocos/physics/spec/IBody.h
Normal file
81
native/cocos/physics/spec/IBody.h
Normal file
@@ -0,0 +1,81 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2020-2021 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "physics/spec/ILifecycle.h"
|
||||
#include "math/Vec3.h"
|
||||
|
||||
namespace cc {
|
||||
namespace physics {
|
||||
|
||||
enum class ERigidBodyType : uint8_t {
|
||||
DYNAMIC = 1,
|
||||
STATIC = 2,
|
||||
KINEMATIC = 4,
|
||||
};
|
||||
|
||||
class IRigidBody : public ILifecycle {
|
||||
public:
|
||||
~IRigidBody() override = default;
|
||||
virtual uintptr_t getImpl() = 0;
|
||||
virtual uint getNodeHandle() = 0;
|
||||
virtual void initialize(uint h, ERigidBodyType t, uint32_t g) = 0;
|
||||
virtual bool isAwake() = 0;
|
||||
virtual bool isSleepy() = 0;
|
||||
virtual bool isSleeping() = 0;
|
||||
virtual void setType(ERigidBodyType v) = 0;
|
||||
virtual void setMass(float v) = 0;
|
||||
virtual void setLinearDamping(float v) = 0;
|
||||
virtual void setAngularDamping(float v) = 0;
|
||||
virtual void useGravity(bool v) = 0;
|
||||
virtual void setLinearFactor(float x, float y, float z) = 0;
|
||||
virtual void setAngularFactor(float x, float y, float z) = 0;
|
||||
virtual void setAllowSleep(bool v) = 0;
|
||||
virtual void wakeUp() = 0;
|
||||
virtual void sleep() = 0;
|
||||
virtual void clearState() = 0;
|
||||
virtual void clearForces() = 0;
|
||||
virtual void clearVelocity() = 0;
|
||||
virtual void setSleepThreshold(float v) = 0;
|
||||
virtual float getSleepThreshold() = 0;
|
||||
virtual cc::Vec3 getLinearVelocity() = 0;
|
||||
virtual void setLinearVelocity(float x, float y, float z) = 0;
|
||||
virtual cc::Vec3 getAngularVelocity() = 0;
|
||||
virtual void setAngularVelocity(float x, float y, float z) = 0;
|
||||
virtual void applyForce(float x, float y, float z, float rx, float ry, float rz) = 0;
|
||||
virtual void applyLocalForce(float x, float y, float z, float rx, float ry, float rz) = 0;
|
||||
virtual void applyImpulse(float x, float y, float z, float rx, float ry, float rz) = 0;
|
||||
virtual void applyLocalImpulse(float x, float y, float z, float rx, float ry, float rz) = 0;
|
||||
virtual void applyTorque(float x, float y, float z) = 0;
|
||||
virtual void applyLocalTorque(float x, float y, float z) = 0;
|
||||
virtual uint32_t getGroup() = 0;
|
||||
virtual void setGroup(uint32_t g) = 0;
|
||||
virtual uint32_t getMask() = 0;
|
||||
virtual void setMask(uint32_t m) = 0;
|
||||
};
|
||||
|
||||
} // namespace physics
|
||||
} // namespace cc
|
||||
60
native/cocos/physics/spec/IJoint.h
Normal file
60
native/cocos/physics/spec/IJoint.h
Normal file
@@ -0,0 +1,60 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2020-2021 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "physics/spec/ILifecycle.h"
|
||||
#include "renderer/pipeline/helper/SharedMemory.h"
|
||||
#include <cstdint>
|
||||
|
||||
namespace cc {
|
||||
namespace physics {
|
||||
|
||||
class IBaseJoint : virtual public ILifecycle {
|
||||
public:
|
||||
~IBaseJoint() override = default;
|
||||
virtual void initialize(uint h) = 0;
|
||||
virtual uintptr_t getImpl() = 0;
|
||||
virtual void setEnableCollision(bool v) = 0;
|
||||
virtual void setConnectedBody(uint v) = 0;
|
||||
};
|
||||
|
||||
class IDistanceJoint : virtual public IBaseJoint {
|
||||
public:
|
||||
~IDistanceJoint() override = default;
|
||||
virtual void setPivotA(float x, float y, float z) = 0;
|
||||
virtual void setPivotB(float x, float y, float z) = 0;
|
||||
};
|
||||
|
||||
class IRevoluteJoint : virtual public IBaseJoint {
|
||||
public:
|
||||
~IRevoluteJoint() override = default;
|
||||
virtual void setPivotA(float x, float y, float z) = 0;
|
||||
virtual void setPivotB(float x, float y, float z) = 0;
|
||||
virtual void setAxis(float x, float y, float z) = 0;
|
||||
};
|
||||
|
||||
} // namespace physics
|
||||
} // namespace cc
|
||||
41
native/cocos/physics/spec/ILifecycle.h
Normal file
41
native/cocos/physics/spec/ILifecycle.h
Normal file
@@ -0,0 +1,41 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2020-2021 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "base/TypeDef.h"
|
||||
#include <cstdint>
|
||||
|
||||
namespace cc {
|
||||
namespace physics {
|
||||
class ILifecycle {
|
||||
public:
|
||||
virtual ~ILifecycle() = default;
|
||||
virtual void onEnable() = 0;
|
||||
virtual void onDisable() = 0;
|
||||
virtual void onDestroy() = 0;
|
||||
};
|
||||
} // namespace physics
|
||||
} // namespace cc
|
||||
142
native/cocos/physics/spec/IShape.h
Normal file
142
native/cocos/physics/spec/IShape.h
Normal file
@@ -0,0 +1,142 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2020-2021 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "bindings/manual/jsb_conversions.h"
|
||||
#include "physics/spec/ILifecycle.h"
|
||||
#include "renderer/pipeline/helper/SharedMemory.h"
|
||||
#include <cstdint>
|
||||
|
||||
namespace cc {
|
||||
namespace physics {
|
||||
|
||||
enum class EAxisDirection : uint8_t {
|
||||
X_AXIS,
|
||||
Y_AXIS,
|
||||
Z_AXIS,
|
||||
};
|
||||
|
||||
enum class EShapeFilterFlag : uint8_t {
|
||||
NONE = 0,
|
||||
IS_TRIGGER = 1 << 0,
|
||||
NEED_EVENT = 1 << 1,
|
||||
NEED_CONTACT_DATA = 1 << 2,
|
||||
DETECT_CONTACT_CCD = 1 << 3,
|
||||
};
|
||||
|
||||
class IBaseShape : virtual public ILifecycle {
|
||||
public:
|
||||
~IBaseShape() override= default;;
|
||||
virtual void initialize(uint h) = 0;
|
||||
virtual uintptr_t getImpl() = 0;
|
||||
virtual void setMaterial(uint16_t id, float f, float df, float r,
|
||||
uint8_t m0, uint8_t m1) = 0;
|
||||
virtual void setAsTrigger(bool v) = 0;
|
||||
virtual void setCenter(float x, float y, float z) = 0;
|
||||
virtual cc::pipeline::AABB& getAABB() = 0;
|
||||
virtual cc::pipeline::Sphere& getBoundingSphere() = 0;
|
||||
virtual void updateEventListener(EShapeFilterFlag flag) = 0;
|
||||
virtual uint32_t getGroup() = 0;
|
||||
virtual void setGroup(uint32_t g) = 0;
|
||||
virtual uint32_t getMask() = 0;
|
||||
virtual void setMask(uint32_t m) = 0;
|
||||
};
|
||||
|
||||
class ISphereShape : virtual public IBaseShape {
|
||||
public:
|
||||
~ISphereShape() override= default;;
|
||||
virtual void setRadius(float v) = 0;
|
||||
};
|
||||
|
||||
class IBoxShape : virtual public IBaseShape {
|
||||
public:
|
||||
~IBoxShape() override= default;;
|
||||
virtual void setSize(float x, float y, float z) = 0;
|
||||
};
|
||||
|
||||
class ICapsuleShape : virtual public IBaseShape {
|
||||
public:
|
||||
~ICapsuleShape() override= default;;
|
||||
virtual void setRadius(float v) = 0;
|
||||
virtual void setCylinderHeight(float v) = 0;
|
||||
virtual void setDirection(EAxisDirection v) = 0;
|
||||
};
|
||||
|
||||
class ICylinderShape : virtual public IBaseShape {
|
||||
public:
|
||||
~ICylinderShape() override= default;;
|
||||
virtual void setConvex(uintptr_t v) = 0;
|
||||
virtual void setCylinder(float r, float h, EAxisDirection d) = 0;
|
||||
};
|
||||
|
||||
class IConeShape : virtual public IBaseShape {
|
||||
public:
|
||||
~IConeShape() override= default;;
|
||||
virtual void setConvex(uintptr_t v) = 0;
|
||||
virtual void setCone(float r, float h, EAxisDirection d) = 0;
|
||||
};
|
||||
|
||||
class IPlaneShape : virtual public IBaseShape {
|
||||
public:
|
||||
~IPlaneShape() override= default;;
|
||||
virtual void setConstant(float v) = 0;
|
||||
virtual void setNormal(float x, float y, float z) = 0;
|
||||
};
|
||||
|
||||
class ITrimeshShape : virtual public IBaseShape {
|
||||
public:
|
||||
~ITrimeshShape() override= default;;
|
||||
virtual void setMesh(uintptr_t v) = 0;
|
||||
virtual void useConvex(bool v) = 0;
|
||||
};
|
||||
|
||||
class ITerrainShape : virtual public IBaseShape {
|
||||
public:
|
||||
virtual void setTerrain(uintptr_t v, float rs, float cs, float hs) = 0;
|
||||
};
|
||||
|
||||
} // namespace physics
|
||||
} // namespace cc
|
||||
|
||||
template <>
|
||||
inline bool nativevalue_to_se(const cc::pipeline::AABB &from, se::Value &to, se::Object *ctx) {
|
||||
se::HandleObject obj(se::Object::createPlainObject());
|
||||
se::Value tmp;
|
||||
if (nativevalue_to_se(from.center, tmp, ctx)) obj->setProperty("center", tmp);
|
||||
if (nativevalue_to_se(from.halfExtents, tmp, ctx)) obj->setProperty("halfExtents", tmp);
|
||||
to.setObject(obj);
|
||||
return true;
|
||||
}
|
||||
|
||||
template <>
|
||||
inline bool nativevalue_to_se(const cc::pipeline::Sphere &from, se::Value &to, se::Object *ctx) {
|
||||
se::HandleObject obj(se::Object::createPlainObject());
|
||||
se::Value tmp(from.radius);
|
||||
obj->setProperty("radius", tmp);
|
||||
if (nativevalue_to_se(from.center, tmp, ctx)) obj->setProperty("center", tmp);
|
||||
to.setObject(obj);
|
||||
return true;
|
||||
}
|
||||
341
native/cocos/physics/spec/IWorld.h
Normal file
341
native/cocos/physics/spec/IWorld.h
Normal file
@@ -0,0 +1,341 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2020-2021 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "bindings/manual/jsb_conversions.h"
|
||||
#include "base/TypeDef.h"
|
||||
#include <memory>
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
namespace cc {
|
||||
namespace physics {
|
||||
|
||||
enum class ETouchState : uint8_t {
|
||||
ENTER = 0,
|
||||
STAY = 1,
|
||||
EXIT = 2,
|
||||
};
|
||||
|
||||
struct TriggerEventPair {
|
||||
uintptr_t shapeA;
|
||||
uintptr_t shapeB;
|
||||
ETouchState state;
|
||||
static constexpr uint8_t COUNT = 3;
|
||||
TriggerEventPair(const uintptr_t a, const uintptr_t b)
|
||||
: shapeA(a),
|
||||
shapeB(b),
|
||||
state(ETouchState::ENTER) {}
|
||||
};
|
||||
|
||||
struct ContactPoint {
|
||||
Vec3 position;
|
||||
float separation;
|
||||
Vec3 normal;
|
||||
uint32_t internalFaceIndex0;
|
||||
Vec3 impulse;
|
||||
uint32_t internalFaceIndex1;
|
||||
static constexpr uint8_t COUNT = 12;
|
||||
};
|
||||
|
||||
struct ContactEventPair {
|
||||
uintptr_t shapeA;
|
||||
uintptr_t shapeB;
|
||||
ETouchState state;
|
||||
std::vector<ContactPoint> contacts;
|
||||
static constexpr uint8_t COUNT = 4;
|
||||
ContactEventPair(const uintptr_t a, const uintptr_t b)
|
||||
: shapeA(a),
|
||||
shapeB(b),
|
||||
state(ETouchState::ENTER) {}
|
||||
};
|
||||
|
||||
struct ConvexDesc {
|
||||
void *positions;
|
||||
uint32_t positionLength;
|
||||
};
|
||||
|
||||
struct TrimeshDesc : ConvexDesc {
|
||||
void *triangles;
|
||||
uint32_t triangleLength;
|
||||
bool isU16;
|
||||
};
|
||||
|
||||
struct HeightFieldDesc {
|
||||
uint32_t rows;
|
||||
uint32_t columns;
|
||||
void *samples;
|
||||
};
|
||||
|
||||
struct RaycastOptions {
|
||||
cc::Vec3 origin;
|
||||
float distance;
|
||||
cc::Vec3 unitDir;
|
||||
uint32_t mask;
|
||||
bool queryTrigger;
|
||||
};
|
||||
|
||||
struct RaycastResult {
|
||||
uintptr_t shape{0};
|
||||
cc::Vec3 hitPoint;
|
||||
float distance;
|
||||
cc::Vec3 hitNormal;
|
||||
RaycastResult() = default;
|
||||
};
|
||||
|
||||
class IPhysicsWorld {
|
||||
public:
|
||||
virtual ~IPhysicsWorld()= default;;
|
||||
virtual void setGravity(float x, float y, float z) = 0;
|
||||
virtual void setAllowSleep(bool v) = 0;
|
||||
virtual void step(float s) = 0;
|
||||
virtual void emitEvents() = 0;
|
||||
virtual void syncSceneToPhysics() = 0;
|
||||
virtual void syncSceneWithCheck() = 0;
|
||||
virtual void destroy() = 0;
|
||||
virtual void setCollisionMatrix(uint32_t i, uint32_t m) = 0;
|
||||
virtual std::vector<std::shared_ptr<TriggerEventPair>> &getTriggerEventPairs() = 0;
|
||||
virtual std::vector<std::shared_ptr<ContactEventPair>> &getContactEventPairs() = 0;
|
||||
virtual bool raycast(RaycastOptions &opt) = 0;
|
||||
virtual bool raycastClosest(RaycastOptions &opt) = 0;
|
||||
virtual std::vector<RaycastResult> &raycastResult() = 0;
|
||||
virtual RaycastResult &raycastClosestResult() = 0;
|
||||
virtual uintptr_t createConvex(ConvexDesc &desc) = 0;
|
||||
virtual uintptr_t createTrimesh(TrimeshDesc &desc) = 0;
|
||||
virtual uintptr_t createHeightField(HeightFieldDesc &desc) = 0;
|
||||
virtual uintptr_t createMaterial(uint16_t id, float f, float df, float r,
|
||||
uint8_t m0, uint8_t m1) = 0;
|
||||
};
|
||||
|
||||
} // namespace physics
|
||||
} // namespace cc
|
||||
|
||||
template <>
|
||||
inline bool nativevalue_to_se(const std::vector<std::shared_ptr<cc::physics::TriggerEventPair>> &from, se::Value &to, se::Object * /*ctx*/) {
|
||||
se::HandleObject array(se::Object::createArrayObject(from.size() * cc::physics::TriggerEventPair::COUNT));
|
||||
for (size_t i = 0; i < from.size(); i++) {
|
||||
auto t = i * cc::physics::TriggerEventPair::COUNT;
|
||||
array->setArrayElement(static_cast<uint>(t + 0), se::Value(from[i]->shapeA));
|
||||
array->setArrayElement(static_cast<uint>(t + 1), se::Value(from[i]->shapeB));
|
||||
array->setArrayElement(static_cast<uint>(t + 2), se::Value(static_cast<uint8_t>(from[i]->state)));
|
||||
}
|
||||
to.setObject(array);
|
||||
return true;
|
||||
}
|
||||
|
||||
template <>
|
||||
inline bool nativevalue_to_se(const std::vector<cc::physics::ContactPoint> &from, se::Value &to, se::Object * /*ctx*/) {
|
||||
const auto contactCount = from.size();
|
||||
se::HandleObject array(se::Object::createArrayObject(contactCount));
|
||||
for (size_t i = 0; i < contactCount; i++) {
|
||||
auto t = i * cc::physics::ContactPoint::COUNT;
|
||||
uint32_t j = 0;
|
||||
array->setArrayElement(static_cast<uint>(t + j++), se::Value(from[i].position.x));
|
||||
array->setArrayElement(static_cast<uint>(t + j++), se::Value(from[i].position.y));
|
||||
array->setArrayElement(static_cast<uint>(t + j++), se::Value(from[i].position.z));
|
||||
array->setArrayElement(static_cast<uint>(t + j++), se::Value(from[i].normal.x));
|
||||
array->setArrayElement(static_cast<uint>(t + j++), se::Value(from[i].normal.y));
|
||||
array->setArrayElement(static_cast<uint>(t + j++), se::Value(from[i].normal.z));
|
||||
array->setArrayElement(static_cast<uint>(t + j++), se::Value(from[i].impulse.x));
|
||||
array->setArrayElement(static_cast<uint>(t + j++), se::Value(from[i].impulse.y));
|
||||
array->setArrayElement(static_cast<uint>(t + j++), se::Value(from[i].impulse.z));
|
||||
array->setArrayElement(static_cast<uint>(t + j++), se::Value(from[i].separation));
|
||||
array->setArrayElement(static_cast<uint>(t + j++), se::Value(from[i].internalFaceIndex0));
|
||||
array->setArrayElement(static_cast<uint>(t + j++), se::Value(from[i].internalFaceIndex1));
|
||||
}
|
||||
to.setObject(array);
|
||||
return true;
|
||||
}
|
||||
|
||||
template <>
|
||||
inline bool nativevalue_to_se(const std::vector<std::shared_ptr<cc::physics::ContactEventPair>> &from, se::Value &to, se::Object *ctx) {
|
||||
se::HandleObject array(se::Object::createArrayObject(from.size() * cc::physics::ContactEventPair::COUNT));
|
||||
for (size_t i = 0; i < from.size(); i++) {
|
||||
auto t = i * cc::physics::ContactEventPair::COUNT;
|
||||
array->setArrayElement(static_cast<uint>(t + 0), se::Value(from[i]->shapeA));
|
||||
array->setArrayElement(static_cast<uint>(t + 1), se::Value(from[i]->shapeB));
|
||||
array->setArrayElement(static_cast<uint>(t + 2), se::Value(static_cast<uint8_t>(from[i]->state)));
|
||||
array->setArrayElement(static_cast<uint>(t + 3), [&]() -> se::Value {
|
||||
auto obj = se::Value();
|
||||
nativevalue_to_se(from[i]->contacts, obj, ctx);
|
||||
return obj;
|
||||
}());
|
||||
}
|
||||
to.setObject(array);
|
||||
return true;
|
||||
}
|
||||
|
||||
template <>
|
||||
inline bool nativevalue_to_se(const cc::physics::RaycastResult &from, se::Value &to, se::Object *ctx) {
|
||||
se::HandleObject obj(se::Object::createPlainObject());
|
||||
obj->setProperty("shape", se::Value(from.shape));
|
||||
obj->setProperty("distance", se::Value(from.distance));
|
||||
se::Value tmp;
|
||||
if (nativevalue_to_se(from.hitPoint, tmp, ctx)) obj->setProperty("hitPoint", tmp);
|
||||
if (nativevalue_to_se(from.hitNormal, tmp, ctx)) obj->setProperty("hitNormal", tmp);
|
||||
to.setObject(obj);
|
||||
return true;
|
||||
}
|
||||
|
||||
template <>
|
||||
inline bool sevalue_to_native(const se::Value &from, cc::physics::ConvexDesc *to, se::Object *ctx) {
|
||||
assert(from.isObject());
|
||||
se::Object *json = from.toObject();
|
||||
auto *data = static_cast<cc::physics::ConvexDesc *>(json->getPrivateData());
|
||||
if (data) {
|
||||
*to = *data;
|
||||
return true;
|
||||
}
|
||||
|
||||
se::Value field;
|
||||
bool ok = true;
|
||||
|
||||
json->getProperty("positionLength", &field);
|
||||
if (!field.isNullOrUndefined()) ok &= sevalue_to_native(field, &to->positionLength, ctx);
|
||||
|
||||
CC_UNUSED size_t dataLength = 0;
|
||||
json->getProperty("positions", &field);
|
||||
if (!field.isNullOrUndefined()) {
|
||||
se::Object *obj = field.toObject();
|
||||
if (obj->isArrayBuffer()) {
|
||||
ok &= obj->getArrayBufferData(reinterpret_cast<uint8_t **>(&to->positions), &dataLength);
|
||||
SE_PRECONDITION2(ok, false, "getArrayBufferData failed!");
|
||||
} else if (obj->isTypedArray()) {
|
||||
ok &= obj->getTypedArrayData(reinterpret_cast<uint8_t **>(&to->positions), &dataLength);
|
||||
SE_PRECONDITION2(ok, false, "getTypedArrayData failed!");
|
||||
} else {
|
||||
ok &= false;
|
||||
}
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
template <>
|
||||
inline bool sevalue_to_native(const se::Value &from, cc::physics::TrimeshDesc *to, se::Object *ctx) {
|
||||
if (!sevalue_to_native(from, reinterpret_cast<cc::physics::ConvexDesc *>(to), ctx)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
assert(from.isObject());
|
||||
se::Object *json = from.toObject();
|
||||
auto *data = static_cast<cc::physics::TrimeshDesc *>(json->getPrivateData());
|
||||
if (data) {
|
||||
*to = *data;
|
||||
return true;
|
||||
}
|
||||
se::Value field;
|
||||
bool ok = true;
|
||||
|
||||
json->getProperty("triangleLength", &field);
|
||||
if (!field.isNullOrUndefined()) ok &= sevalue_to_native(field, &(to->triangleLength), ctx);
|
||||
|
||||
json->getProperty("isU16", &field);
|
||||
if (!field.isNullOrUndefined()) ok &= sevalue_to_native(field, &(to->isU16), ctx);
|
||||
|
||||
CC_UNUSED size_t dataLength = 0;
|
||||
json->getProperty("triangles", &field);
|
||||
if (!field.isNullOrUndefined()) {
|
||||
se::Object *obj = field.toObject();
|
||||
if (obj->isArrayBuffer()) {
|
||||
ok &= obj->getArrayBufferData(reinterpret_cast<uint8_t **>(&to->triangles), &dataLength);
|
||||
SE_PRECONDITION2(ok, false, "getArrayBufferData failed!");
|
||||
} else if (obj->isTypedArray()) {
|
||||
ok &= obj->getTypedArrayData(reinterpret_cast<uint8_t **>(&to->triangles), &dataLength);
|
||||
SE_PRECONDITION2(ok, false, "getTypedArrayData failed!");
|
||||
} else {
|
||||
ok &= false;
|
||||
}
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
template <>
|
||||
inline bool sevalue_to_native(const se::Value &from, cc::physics::HeightFieldDesc *to, se::Object *ctx) {
|
||||
assert(from.isObject());
|
||||
se::Object *json = from.toObject();
|
||||
auto *data = static_cast<cc::physics::HeightFieldDesc *>(json->getPrivateData());
|
||||
if (data) {
|
||||
*to = *data;
|
||||
return true;
|
||||
}
|
||||
|
||||
se::Value field;
|
||||
bool ok = true;
|
||||
|
||||
json->getProperty("rows", &field);
|
||||
if (!field.isNullOrUndefined()) ok &= sevalue_to_native(field, &to->rows, ctx);
|
||||
|
||||
json->getProperty("columns", &field);
|
||||
if (!field.isNullOrUndefined()) ok &= sevalue_to_native(field, &to->columns, ctx);
|
||||
|
||||
CC_UNUSED size_t dataLength = 0;
|
||||
json->getProperty("samples", &field);
|
||||
if (!field.isNullOrUndefined()) {
|
||||
se::Object *obj = field.toObject();
|
||||
if (obj->isArrayBuffer()) {
|
||||
ok &= obj->getArrayBufferData(reinterpret_cast<uint8_t **>(&to->samples), &dataLength);
|
||||
SE_PRECONDITION2(ok, false, "getArrayBufferData failed!");
|
||||
} else if (obj->isTypedArray()) {
|
||||
ok &= obj->getTypedArrayData(reinterpret_cast<uint8_t **>(&to->samples), &dataLength);
|
||||
SE_PRECONDITION2(ok, false, "getTypedArrayData failed!");
|
||||
} else {
|
||||
ok &= false;
|
||||
}
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
template <>
|
||||
inline bool sevalue_to_native(const se::Value &from, cc::physics::RaycastOptions *to, se::Object *ctx) {
|
||||
assert(from.isObject());
|
||||
se::Object *json = from.toObject();
|
||||
auto *data = static_cast<cc::physics::RaycastOptions *>(json->getPrivateData());
|
||||
if (data) {
|
||||
*to = *data;
|
||||
return true;
|
||||
}
|
||||
|
||||
se::Value field;
|
||||
bool ok = true;
|
||||
|
||||
json->getProperty("origin", &field);
|
||||
if (!field.isNullOrUndefined()) ok &= seval_to_Vec3(field, &to->origin);
|
||||
|
||||
json->getProperty("unitDir", &field);
|
||||
if (!field.isNullOrUndefined()) ok &= seval_to_Vec3(field, &to->unitDir);
|
||||
|
||||
json->getProperty("mask", &field);
|
||||
if (!field.isNullOrUndefined()) ok &= sevalue_to_native(field, &to->mask, ctx);
|
||||
|
||||
json->getProperty("distance", &field);
|
||||
if (!field.isNullOrUndefined()) ok &= sevalue_to_native(field, &to->distance, ctx);
|
||||
|
||||
json->getProperty("queryTrigger", &field);
|
||||
if (!field.isNullOrUndefined()) ok &= sevalue_to_native(field, &to->queryTrigger, ctx);
|
||||
|
||||
return ok;
|
||||
}
|
||||
@@ -24,7 +24,7 @@
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
#include "gfx-base/GFXDef.h"
|
||||
#include "renderer/gfx-base/GFXDef.h"
|
||||
|
||||
#include "bindings/dop/BufferAllocator.h"
|
||||
#include "bindings/dop/BufferPool.h"
|
||||
|
||||
@@ -26,6 +26,10 @@
|
||||
#ifndef __COCOS2D_EXT_H__
|
||||
#define __COCOS2D_EXT_H__
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(disable:4996)
|
||||
#endif
|
||||
|
||||
#include "ExtensionMacros.h"
|
||||
|
||||
#include "assets-manager/AssetsManagerEx.h"
|
||||
|
||||
4
native/external/config.json
vendored
4
native/external/config.json
vendored
@@ -1,9 +1,9 @@
|
||||
{
|
||||
"version": "v3d-gfx-42",
|
||||
"version": "v3d-gfx-43",
|
||||
"from": {
|
||||
"type": "github",
|
||||
"owner": "cocos-creator",
|
||||
"name": "engine-native-external",
|
||||
"checkout": "v3d-gfx-42"
|
||||
"checkout": "v3d-gfx-43"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ option(USE_MIDDLEWARE "Enable Middleware" ON)
|
||||
option(USE_DRAGONBONES "Enable Dragonbones" ON)
|
||||
option(USE_SPINE "Enable Spine" ON)
|
||||
option(USE_WEBSOCKET_SERVER "Enable WebSocket Server" OFF)
|
||||
option(USE_PHYSICS_PHYSX "USE PhysX Physics" ON)
|
||||
|
||||
if(NOT RES_DIR)
|
||||
message(FATAL_ERROR "RES_DIR is not set!")
|
||||
|
||||
@@ -20,6 +20,7 @@ option(USE_WEBVIEW "Enable WebView Component" OFF)
|
||||
option(USE_MIDDLEWARE "Enable Middleware" ON)
|
||||
option(USE_DRAGONBONES "Enable Dragonbones" ON)
|
||||
option(USE_SPINE "Enable Spine" ON)
|
||||
option(USE_PHYSICS_PHYSX "USE PhysX Physics" ON)
|
||||
|
||||
if(USE_SE_JSC AND APPLE)
|
||||
set(USE_SE_V8 OFF)
|
||||
|
||||
@@ -154,7 +154,8 @@ def main():
|
||||
'pipeline.ini': ('pipeline', 'jsb_pipeline_auto'),
|
||||
'spine.ini': ('spine','jsb_spine_auto'),
|
||||
'editor_support.ini': ('editor_support','jsb_editor_support_auto'),
|
||||
'dragonbones.ini': ('dragonbones','jsb_dragonbones_auto')
|
||||
'dragonbones.ini': ('dragonbones','jsb_dragonbones_auto'),
|
||||
'physics.ini': ('physics','jsb_physics_auto')
|
||||
}
|
||||
|
||||
target = 'spidermonkey'
|
||||
|
||||
66
native/tools/tojs/physics.ini
Normal file
66
native/tools/tojs/physics.ini
Normal file
@@ -0,0 +1,66 @@
|
||||
[physics]
|
||||
# the prefix to be added to the generated functions. You might or might not use this in your own
|
||||
# templates
|
||||
prefix = physics
|
||||
|
||||
# create a target namespace (in javascript, this would create some code like the equiv. to `ns = ns || {}`)
|
||||
# all classes will be embedded in that namespace
|
||||
target_namespace = jsb.physics
|
||||
|
||||
macro_judgement =
|
||||
|
||||
android_headers =
|
||||
|
||||
android_flags = -target armv7-none-linux-androideabi -D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS -DANDROID -D__ANDROID_API__=14 -gcc-toolchain %(gcc_toolchain_dir)s --sysroot=%(androidndkdir)s/platforms/android-14/arch-arm -idirafter %(androidndkdir)s/sources/android/support/include -idirafter %(androidndkdir)s/sysroot/usr/include -idirafter %(androidndkdir)s/sysroot/usr/include/arm-linux-androideabi -idirafter %(clangllvmdir)s/lib64/clang/5.0/include -I%(androidndkdir)s/sources/cxx-stl/llvm-libc++/include
|
||||
|
||||
clang_headers =
|
||||
clang_flags = -nostdinc -x c++ -std=c++14 -fsigned-char -U__SSE__
|
||||
|
||||
cocos_headers = -I%(cocosdir)s -I%(cocosdir)s/cocos -I%(cocosdir)s/cocos/platform/android -I%(cocosdir)s/external/sources -I%(cocosdir)s/external/android/armeabi-v7a/include/v8
|
||||
cocos_flags = -DANDROID -DCC_PLATFORM=3 -DCC_PLATFORM_MAC_IOS=1 -DCC_PLATFORM_MAC_OSX=4 -DCC_PLATFORM_WINDOWS=2 -DCC_PLATFORM_ANDROID=3
|
||||
|
||||
|
||||
cxxgenerator_headers =
|
||||
|
||||
# extra arguments for clang
|
||||
extra_arguments = %(android_headers)s %(clang_headers)s %(cxxgenerator_headers)s %(cocos_headers)s %(android_flags)s %(clang_flags)s %(cocos_flags)s %(extra_flags)s
|
||||
|
||||
# what headers to parse
|
||||
headers = %(cocosdir)s/cocos/physics/PhysicsSDK.h
|
||||
|
||||
replace_headers =
|
||||
|
||||
# what classes to produce code for. You can use regular expressions here. When testing the regular
|
||||
# expression, it will be enclosed in "^$", like this: "^Menu*$".
|
||||
classes = PhysXBindings World RigidBody SphereShape BoxShape PlaneShape CapsuleShape TrimeshShape TerrainShape CylinderShape ConeShape RevoluteJoint DistanceJoint
|
||||
|
||||
# what should we skip? in the format ClassName::[function function]
|
||||
# ClassName is a regular expression, but will be used like this: "^ClassName$" functions are also
|
||||
# regular expressions, they will not be surrounded by "^$". If you want to skip a whole class, just
|
||||
# add a single "*" as functions. See bellow for several examples. A special class name is "*", which
|
||||
# will apply to all class names. This is a convenience wildcard to be able to skip similar named
|
||||
# functions from all classes.
|
||||
|
||||
skip =
|
||||
|
||||
field =
|
||||
|
||||
rename_functions =
|
||||
|
||||
rename_classes =
|
||||
|
||||
# for all class names, should we remove something when registering in the target VM?
|
||||
remove_prefix =
|
||||
|
||||
# classes for which there will be no "parent" lookup
|
||||
classes_have_no_parents = PhysXBindings World RigidBody SphereShape BoxShape PlaneShape CapsuleShape TrimeshShape TerrainShape CylinderShape ConeShape RevoluteJoint DistanceJoint
|
||||
|
||||
# base classes which will be skipped when their sub-classes found them.
|
||||
base_classes_to_skip =
|
||||
|
||||
# classes that create no constructor
|
||||
# Set is special and we will use a hand-written constructor
|
||||
abstract_classes =
|
||||
|
||||
classes_owned_by_cpp =
|
||||
|
||||
@@ -137,15 +137,14 @@ function build_macosx()
|
||||
|
||||
RES_DIR=$COCOS2DX_ROOT/templates/mac/build-mac
|
||||
cd build-mac
|
||||
cmake ../ -G"Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DCC_USE_GLES3=ON -DCMAKE_OSX_ARCHITECTURES=x86_64 -DRES_DIR=$RES_DIR -DCOCOS_X_PATH=$COCOS2DX_ROOT
|
||||
cmake --build . -- -j $NUM_OF_CORES
|
||||
echo "Compile MacOSX X86_64 Release Done!"
|
||||
cd ..
|
||||
mkdir build-mac-apple-silicon
|
||||
cd build-mac-apple-silicon
|
||||
cmake ../ -GXcode -DCC_USE_GLES3=OFF -DCMAKE_OSX_ARCHITECTURES=arm64 -DRES_DIR=$RES_DIR -DCOCOS_X_PATH=$COCOS2DX_ROOT
|
||||
cmake --build . --config Release -- -quiet -jobs $NUM_OF_CORES -arch arm64
|
||||
echo "Compile MacOSX ARM64 Release Done!"
|
||||
cmake ../ -GXcode -DCC_USE_GLES3=ON -DCMAKE_OSX_ARCHITECTURES=x86_64 -DRES_DIR=$RES_DIR -DCOCOS_X_PATH=$COCOS2DX_ROOT
|
||||
cmake --build . --config Release -- -quiet -jobs $NUM_OF_CORES -arch x86_64
|
||||
# cd ..
|
||||
# mkdir build-mac-apple-silicon
|
||||
# cd build-mac-apple-silicon
|
||||
# cmake ../ -GXcode -DCC_USE_GLES3=OFF -DCMAKE_OSX_ARCHITECTURES=arm64 -DRES_DIR=$RES_DIR -DCOCOS_X_PATH=$COCOS2DX_ROOT
|
||||
# cmake --build . --config Release -- -quiet -jobs $NUM_OF_CORES -arch arm64
|
||||
# echo "Compile MacOSX ARM64 Release Done!"
|
||||
}
|
||||
|
||||
function build_ios()
|
||||
|
||||
Reference in New Issue
Block a user