@galacean/engine-physics-physx 0.0.0-experimental-2.0-skill.0 → 0.0.0-experimental-2.0-migrate.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -21,6 +21,18 @@ export declare enum CollisionDetectionMode {
21
21
  export declare class PhysXDynamicCollider extends PhysXCollider implements IDynamicCollider {
22
22
  private static _tempTranslation;
23
23
  private static _tempRotation;
24
+ /**
25
+ * Whether actor is currently kinematic.
26
+ * PhysX 拒绝在 kinematic actor 上启用 CCD(会打印警告并忽略),
27
+ * 所以 setCollisionDetectionMode 在 kinematic 状态下只缓存目标值,
28
+ * 等切回 dynamic 时再真正写到 PhysX。
29
+ */
30
+ private _isKinematic;
31
+ /**
32
+ * Cached collision detection mode. Always reflects user's intent.
33
+ * 实际 PhysX CCD flag 可能跟这个不一致(kinematic 时强制 Discrete)。
34
+ */
35
+ private _collisionDetectionMode;
24
36
  constructor(physXPhysics: PhysXPhysics, position: Vector3, rotation: Quaternion);
25
37
  /**
26
38
  * {@inheritDoc IDynamicCollider.setLinearDamping }
@@ -80,7 +92,7 @@ export declare class PhysXDynamicCollider extends PhysXCollider implements IDyna
80
92
  setMaxDepenetrationVelocity(value: number): void;
81
93
  /**
82
94
  * {@inheritDoc IDynamicCollider.setSleepThreshold }
83
- * @default 1e-5f * PxTolerancesScale::speed * PxTolerancesScale::speed
95
+ * @default 5e-5f * PxTolerancesScale::speed * PxTolerancesScale::speed
84
96
  */
85
97
  setSleepThreshold(value: number): void;
86
98
  /**
@@ -89,6 +101,15 @@ export declare class PhysXDynamicCollider extends PhysXCollider implements IDyna
89
101
  setSolverIterations(value: number): void;
90
102
  /**
91
103
  * {@inheritDoc IDynamicCollider.setCollisionDetectionMode }
104
+ *
105
+ * PhysX 在 kinematic actor 上调用 setRigidBodyFlag(eENABLE_CCD, true) 会触发警告:
106
+ * "kinematic bodies with CCD enabled are not supported! CCD will be ignored"
107
+ * 虽然 PhysX 会忽略这次调用而非真的拒绝(切回 dynamic 时 flag 不会自动恢复),
108
+ * 但每次 setIsKinematic 切换都会让这个 warning 重复打印,污染日志,
109
+ * 同时让 actor 在 dynamic 状态下 CCD flag 状态不确定。
110
+ *
111
+ * 解决: 只在 dynamic 状态时立即 apply CCD flags。kinematic 时仅缓存到
112
+ * `_collisionDetectionMode`,等切回 dynamic 时由 setIsKinematic 重新 apply。
92
113
  */
93
114
  setCollisionDetectionMode(value: number): void;
94
115
  /**
@@ -97,14 +118,25 @@ export declare class PhysXDynamicCollider extends PhysXCollider implements IDyna
97
118
  setUseGravity(value: boolean): void;
98
119
  /**
99
120
  * {@inheritDoc IDynamicCollider.setIsKinematic }
121
+ *
122
+ * 切换 kinematic 状态时同步处理 CCD flag:
123
+ * - 切到 kinematic 前先关 CCD(避免 PhysX 警告 + 让状态显式)
124
+ * - 切回 dynamic 后恢复用户期望的 CCD mode(来自 `_collisionDetectionMode` 缓存)
100
125
  */
101
126
  setIsKinematic(value: boolean): void;
127
+ private _applyCollisionDetectionFlags;
102
128
  /**
103
129
  * {@inheritDoc IDynamicCollider.setConstraints }
104
130
  */
105
131
  setConstraints(flags: number): void;
106
132
  /**
107
133
  * {@inheritDoc IDynamicCollider.addForce }
134
+ *
135
+ * PhysX 在 kinematic actor 上调 addForce 是 no-op(doc: "kinematic bodies don't
136
+ * respond to forces")。提前 return 避免无意义的 wasm boundary cross。
137
+ *
138
+ * Sleeping actor 不需要显式 wakeUp — wasm binding 调用 `addForce(force, eFORCE,
139
+ * autowake=true)`,PhysX 自动唤醒(已通过 `applyForce on sleeping actor` 测试验证)。
108
140
  */
109
141
  addForce(force: Vector3): void;
110
142
  /**
@@ -113,10 +145,15 @@ export declare class PhysXDynamicCollider extends PhysXCollider implements IDyna
113
145
  addForceAtPosition(force: Vector3, position: Vector3): void;
114
146
  /**
115
147
  * {@inheritDoc IDynamicCollider.addTorque }
148
+ *
149
+ * 同 addForce — kinematic 提前 return,sleeping 由 PhysX autowake 自动处理。
116
150
  */
117
151
  addTorque(torque: Vector3): void;
118
152
  /**
119
153
  * {@inheritDoc IDynamicCollider.move }
154
+ *
155
+ * PhysX 要求 setKinematicTarget 的 rotation 是 normalized quaternion,否则会触发
156
+ * 内部 assertion / 警告,并把 actor 转到错误的姿态。所以在写入 wasm 边界前统一 normalize。
120
157
  */
121
158
  move(positionOrRotation: Vector3 | Quaternion, rotation?: Quaternion): void;
122
159
  /**
@@ -16,12 +16,17 @@ export declare class PhysXPhysics implements IPhysics {
16
16
  private _tolerancesScale;
17
17
  private _wasmSIMDModeUrl;
18
18
  private _wasmModeUrl;
19
+ private _tolerancesScaleOptions;
20
+ private _defaultContactOffset;
21
+ private _defaultSleepThreshold;
19
22
  /**
20
23
  * Create a PhysXPhysics instance.
21
24
  * @param runtimeMode - Runtime mode, `Auto` prefers WebAssembly SIMD if supported @see {@link PhysXRuntimeMode}
22
25
  * @param runtimeUrls - Manually specify the runtime URLs
26
+ * @param options - PhysX options.
23
27
  */
24
- constructor(runtimeMode?: PhysXRuntimeMode, runtimeUrls?: PhysXRuntimeUrls);
28
+ constructor(runtimeMode?: PhysXRuntimeMode, runtimeUrls?: PhysXRuntimeUrls, options?: PhysXPhysicsOptions);
29
+ constructor(options?: PhysXPhysicsOptions);
25
30
  /**
26
31
  * Initialize PhysXPhysics.
27
32
  * @param runtimeMode - Runtime mode
@@ -40,6 +45,14 @@ export declare class PhysXPhysics implements IPhysics {
40
45
  * {@inheritDoc IPhysics.createPhysicsScene }
41
46
  */
42
47
  createPhysicsScene(physicsManager: PhysXPhysicsManager): IPhysicsScene;
48
+ /**
49
+ * {@inheritDoc IPhysics.getDefaultContactOffset }
50
+ */
51
+ getDefaultContactOffset(): number;
52
+ /**
53
+ * {@inheritDoc IPhysics.getDefaultSleepThreshold }
54
+ */
55
+ getDefaultSleepThreshold(): number;
43
56
  /**
44
57
  * {@inheritDoc IPhysics.createStaticCollider }
45
58
  */
@@ -97,6 +110,10 @@ export declare class PhysXPhysics implements IPhysics {
97
110
  */
98
111
  setColliderLayerCollision(layer1: number, layer2: number, isCollide: boolean): void;
99
112
  private _init;
113
+ private _applyTolerancesScale;
114
+ private _assertPositiveFinite;
115
+ private _validateTolerancesScale;
116
+ private _updateScaledDefaults;
100
117
  }
101
118
  interface PhysXRuntimeUrls {
102
119
  /*** The URL of `PhysXRuntimeMode.WebAssembly` mode. */
@@ -104,4 +121,14 @@ interface PhysXRuntimeUrls {
104
121
  /*** The URL of `PhysXRuntimeMode.WebAssemblySIMD` mode. */
105
122
  wasmSIMDModeUrl?: string;
106
123
  }
124
+ export interface PhysXTolerancesScale {
125
+ /** Approximate object length in the simulation unit. PhysX default is 1. */
126
+ length?: number;
127
+ /** Typical object speed in the simulation unit. PhysX default is 10. */
128
+ speed?: number;
129
+ }
130
+ export interface PhysXPhysicsOptions {
131
+ /** PhysX world unit scale used before PxPhysics, PxSceneDesc and PxCookingParams are created. */
132
+ tolerancesScale?: PhysXTolerancesScale;
133
+ }
107
134
  export {};
@@ -29,6 +29,7 @@ export declare class PhysXPhysicsScene implements IPhysicsScene {
29
29
  private _activeTriggers;
30
30
  private _contactEvents;
31
31
  private _contactEventCount;
32
+ private _contactEventEnabled;
32
33
  private _triggerEvents;
33
34
  private _physicsEvents;
34
35
  private _triggerEventPool;
@@ -57,6 +58,10 @@ export declare class PhysXPhysicsScene implements IPhysicsScene {
57
58
  * {@inheritDoc IPhysicsScene.update }
58
59
  */
59
60
  update(elapsedTime: number): void;
61
+ /**
62
+ * {@inheritDoc IPhysicsScene.setContactEventEnabled }
63
+ */
64
+ setContactEventEnabled(enabled: boolean): void;
60
65
  /**
61
66
  * {@inheritDoc IPhysicsScene.updateEvents }
62
67
  */
package/types/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export { PhysXPhysics } from "./PhysXPhysics";
2
+ export type { PhysXPhysicsOptions, PhysXTolerancesScale } from "./PhysXPhysics";
2
3
  export { PhysXRuntimeMode } from "./enum/PhysXRuntimeMode";
3
4
  export declare const version = "__buildVersion";