@cyclonium/physics-2d 0.1.0 → 1.0.0
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.
- package/lib/body-collider-link.js +1 -1
- package/lib/character-controller-2d.js +16 -16
- package/lib/collider-2d.d.ts +4 -4
- package/lib/collider-2d.js +15 -15
- package/lib/colliders/box-collider-2d.js +3 -3
- package/lib/colliders/capsule-collider-2d.js +3 -3
- package/lib/colliders/circle-collider-2d.js +2 -2
- package/lib/colliders/polygon-collider-2d.js +1 -2
- package/lib/collision-matrix.d.ts +2 -2
- package/lib/collision-matrix.js +12 -10
- package/lib/gizmo-headless.js +18 -6
- package/lib/physics-2d-debugger-headless.d.ts +0 -1
- package/lib/physics-2d-debugger-headless.js +2 -2
- package/lib/physics-2d-debugger.js +10 -10
- package/lib/physics-2d-settings.d.ts +2 -2
- package/lib/physics-2d-settings.js +17 -15
- package/lib/physics-component-2d-base.js +8 -4
- package/lib/physics-world-2d-scene-component.d.ts +1 -1
- package/lib/physics-world-2d-scene-component.js +6 -6
- package/lib/physics-world-2d.d.ts +1 -1
- package/lib/physics-world-2d.js +26 -26
- package/lib/px2-impl.js +3 -5
- package/lib/rigid-body-2d.d.ts +1 -1
- package/lib/rigid-body-2d.js +37 -37
- package/lib/scene-query-probe-2d.d.ts +4 -4
- package/lib/scene-query-probe-2d.js +18 -17
- package/lib/scene-query-probes/box-scene-query-probe-2d.d.ts +1 -1
- package/lib/scene-query-probes/box-scene-query-probe-2d.js +4 -4
- package/lib/scene-query-probes/capsule-scene-query-probe-2d.d.ts +2 -2
- package/lib/scene-query-probes/capsule-scene-query-probe-2d.js +5 -5
- package/lib/scene-query-probes/circle-scene-query-probe-2d.d.ts +1 -1
- package/lib/scene-query-probes/circle-scene-query-probe-2d.js +3 -3
- package/lib/scene-query.d.ts +1 -2
- package/lib/scene-query.js +4 -6
- package/lib/wasm-binary-helper.d.ts +1 -1
- package/lib/wasm-binary-helper.js +1 -2
- package/package.json +3 -3
|
@@ -22,7 +22,7 @@ export class BodyColliderLink {
|
|
|
22
22
|
this._colliders.length = 0;
|
|
23
23
|
}
|
|
24
24
|
linkCollider(collider) {
|
|
25
|
-
if (this._colliders.
|
|
25
|
+
if (this._colliders.includes(collider)) {
|
|
26
26
|
throw new Error(`Collider ${collider.name} already joined to body ${this._rigidBody?.name}.`);
|
|
27
27
|
}
|
|
28
28
|
this._colliders.push(collider);
|
|
@@ -4,7 +4,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
4
4
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
|
-
import { editable, idem, idemBy,
|
|
7
|
+
import { editable, idem, idemBy, stored } from '@cyclonium/core/legacy-decorator';
|
|
8
8
|
import { Vec2 } from '@cyclonium/core/math/vec2';
|
|
9
9
|
import { fromPx2ImplVec2, toPx2ImplVec2 } from './exchange.js';
|
|
10
10
|
import { px2Impl } from './px2-impl.js';
|
|
@@ -134,7 +134,7 @@ let KinematicCharacterController2D = class KinematicCharacterController2D extend
|
|
|
134
134
|
return;
|
|
135
135
|
}
|
|
136
136
|
const collider = Collider2D.ofOrNull(this);
|
|
137
|
-
if (!collider
|
|
137
|
+
if (!collider?.impl_internal) {
|
|
138
138
|
return;
|
|
139
139
|
}
|
|
140
140
|
const world = this.world;
|
|
@@ -145,7 +145,7 @@ let KinematicCharacterController2D = class KinematicCharacterController2D extend
|
|
|
145
145
|
const movement = fromPx2ImplVec2(impl.computedMovement());
|
|
146
146
|
Vec2.assign(this._lastMovement, movement);
|
|
147
147
|
const rigidBody = collider.attachedRigidBody;
|
|
148
|
-
if (!rigidBody
|
|
148
|
+
if (!rigidBody?.impl) {
|
|
149
149
|
const newPosition = fromPx2ImplVec2(collider.impl_internal.translation()).add(movement);
|
|
150
150
|
Transform2DComponent.of(collider).position = newPosition;
|
|
151
151
|
collider.impl_internal.setTranslation(toPx2ImplVec2(newPosition));
|
|
@@ -294,7 +294,7 @@ __decorate([
|
|
|
294
294
|
], KinematicCharacterController2D.prototype, "skinWidth", null);
|
|
295
295
|
__decorate([
|
|
296
296
|
editable,
|
|
297
|
-
idemBy(Vec2.strictEquals)
|
|
297
|
+
idemBy((left, right) => Vec2.strictEquals(left, right))
|
|
298
298
|
], KinematicCharacterController2D.prototype, "up", null);
|
|
299
299
|
__decorate([
|
|
300
300
|
editable,
|
|
@@ -337,40 +337,40 @@ __decorate([
|
|
|
337
337
|
idem
|
|
338
338
|
], KinematicCharacterController2D.prototype, "applyImpulsesToDynamicBodies", null);
|
|
339
339
|
__decorate([
|
|
340
|
-
|
|
340
|
+
stored
|
|
341
341
|
], KinematicCharacterController2D.prototype, "_skinWidth", void 0);
|
|
342
342
|
__decorate([
|
|
343
|
-
|
|
343
|
+
stored
|
|
344
344
|
], KinematicCharacterController2D.prototype, "_up", void 0);
|
|
345
345
|
__decorate([
|
|
346
|
-
|
|
346
|
+
stored
|
|
347
347
|
], KinematicCharacterController2D.prototype, "_slideEnabled", void 0);
|
|
348
348
|
__decorate([
|
|
349
|
-
|
|
349
|
+
stored
|
|
350
350
|
], KinematicCharacterController2D.prototype, "_minSlopeSlideAngle", void 0);
|
|
351
351
|
__decorate([
|
|
352
|
-
|
|
352
|
+
stored
|
|
353
353
|
], KinematicCharacterController2D.prototype, "_maxSlopeClimbAngle", void 0);
|
|
354
354
|
__decorate([
|
|
355
|
-
|
|
355
|
+
stored
|
|
356
356
|
], KinematicCharacterController2D.prototype, "_autoStepEnabled", void 0);
|
|
357
357
|
__decorate([
|
|
358
|
-
|
|
358
|
+
stored
|
|
359
359
|
], KinematicCharacterController2D.prototype, "_autoStepMaxHeight", void 0);
|
|
360
360
|
__decorate([
|
|
361
|
-
|
|
361
|
+
stored
|
|
362
362
|
], KinematicCharacterController2D.prototype, "_autoStepMinWidth", void 0);
|
|
363
363
|
__decorate([
|
|
364
|
-
|
|
364
|
+
stored
|
|
365
365
|
], KinematicCharacterController2D.prototype, "_autoStepIncludeDynamicBodies", void 0);
|
|
366
366
|
__decorate([
|
|
367
|
-
|
|
367
|
+
stored
|
|
368
368
|
], KinematicCharacterController2D.prototype, "_snapToGroundEnabled", void 0);
|
|
369
369
|
__decorate([
|
|
370
|
-
|
|
370
|
+
stored
|
|
371
371
|
], KinematicCharacterController2D.prototype, "_snapToGroundDistance", void 0);
|
|
372
372
|
__decorate([
|
|
373
|
-
|
|
373
|
+
stored
|
|
374
374
|
], KinematicCharacterController2D.prototype, "_applyImpulsesToDynamicBodies", void 0);
|
|
375
375
|
KinematicCharacterController2D = __decorate([
|
|
376
376
|
cycloBuiltinClass('KinematicCharacterController2D')
|
package/lib/collider-2d.d.ts
CHANGED
|
@@ -6,19 +6,20 @@ import { ColliderShapeCastHit, ColliderShapeIntersection, RayColliderIntersectio
|
|
|
6
6
|
import type { Ray2D } from '@cyclonium/core/math/ray';
|
|
7
7
|
import { Bounds2D } from '@cyclonium/core/math/bounds-2d';
|
|
8
8
|
export declare abstract class Collider2D extends PhysicsComponent2DBase {
|
|
9
|
+
onContactBegin: import("@cyclonium/event").ManagedEventEmitter<[Collider2D, Collider2D, Contact2DInfo]>;
|
|
10
|
+
onContactStay: import("@cyclonium/event").ManagedEventEmitter<[Collider2D, Collider2D, Contact2DInfo]>;
|
|
11
|
+
onContactEnd: import("@cyclonium/event").ManagedEventEmitter<[Collider2D, Collider2D, Contact2DInfo]>;
|
|
9
12
|
get attachedRigidBody(): import("./rigid-body-2d.js").RigidBody2D | null;
|
|
10
13
|
get isSensor(): boolean;
|
|
11
14
|
set isSensor(value: boolean);
|
|
12
15
|
get center(): Vec2;
|
|
13
16
|
set center(value: Vec2);
|
|
14
17
|
get bounds(): Bounds2D;
|
|
15
|
-
onContactBegin: import("@cyclonium/event").ManagedEventEmitter<[Collider2D, Collider2D, Contact2DInfo]>;
|
|
16
|
-
onContactStay: import("@cyclonium/event").ManagedEventEmitter<[Collider2D, Collider2D, Contact2DInfo]>;
|
|
17
|
-
onContactEnd: import("@cyclonium/event").ManagedEventEmitter<[Collider2D, Collider2D, Contact2DInfo]>;
|
|
18
18
|
intersect(opts: ShapeIntersectionQueryOptions): ColliderShapeIntersection | undefined;
|
|
19
19
|
cast(opts: ShapeCastQueryOptions): ColliderShapeCastHit | undefined;
|
|
20
20
|
castRay(ray: Ray2D, maxDistance: number, solid?: boolean): RayColliderIntersection | undefined;
|
|
21
21
|
protected get _implCollider(): px2Impl.Collider | undefined;
|
|
22
|
+
protected get sceneGraphScale(): Vec2;
|
|
22
23
|
protected recreateCollider(): void;
|
|
23
24
|
protected onAttachToWorld(): void;
|
|
24
25
|
protected onDetachFromWorld(): void;
|
|
@@ -27,7 +28,6 @@ export declare abstract class Collider2D extends PhysicsComponent2DBase {
|
|
|
27
28
|
protected onSyncTransforms(forceTransform: boolean, forceScale: boolean): void;
|
|
28
29
|
protected abstract getShape(): px2Impl.Shape | undefined;
|
|
29
30
|
protected abstract computeShapeBounds(out: Bounds2D): void;
|
|
30
|
-
protected get sceneGraphScale(): Vec2;
|
|
31
31
|
protected updateSceneGraphScale(): void;
|
|
32
32
|
private _isSensor;
|
|
33
33
|
private _center;
|
package/lib/collider-2d.js
CHANGED
|
@@ -5,7 +5,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
7
|
import { Transform2DComponent, TransformChangeFlagsObserver, TransformFlag } from '@cyclonium/core/2d';
|
|
8
|
-
import { editable, requiresComponent,
|
|
8
|
+
import { editable, requiresComponent, stored } from '@cyclonium/core/legacy-decorator';
|
|
9
9
|
import { cycloBuiltinClass } from '@cyclonium/core/internal';
|
|
10
10
|
import { Vec2 } from '@cyclonium/core/math/vec2';
|
|
11
11
|
import {} from './contact.js';
|
|
@@ -19,6 +19,15 @@ import { getZRotation } from './utils/3-to-2.js';
|
|
|
19
19
|
import { ColliderShapeCastHit, ColliderShapeIntersection, RayColliderIntersection } from './scene-query.js';
|
|
20
20
|
import { Bounds2D } from '@cyclonium/core/math/bounds-2d';
|
|
21
21
|
let Collider2D = class Collider2D extends PhysicsComponent2DBase {
|
|
22
|
+
onContactBegin = createCollisionEventEmitter((hasAnyListener) => {
|
|
23
|
+
this._updateListenerFlag(ContactEventListenerFlagIndex.begin, hasAnyListener);
|
|
24
|
+
});
|
|
25
|
+
onContactStay = createCollisionEventEmitter((hasAnyListener) => {
|
|
26
|
+
this._updateListenerFlag(ContactEventListenerFlagIndex.stay, hasAnyListener);
|
|
27
|
+
});
|
|
28
|
+
onContactEnd = createCollisionEventEmitter((hasAnyListener) => {
|
|
29
|
+
this._updateListenerFlag(ContactEventListenerFlagIndex.end, hasAnyListener);
|
|
30
|
+
});
|
|
22
31
|
get attachedRigidBody() {
|
|
23
32
|
return this._handle?.attachedRigidBody ?? null;
|
|
24
33
|
}
|
|
@@ -48,15 +57,6 @@ let Collider2D = class Collider2D extends PhysicsComponent2DBase {
|
|
|
48
57
|
get impl_internal() {
|
|
49
58
|
return this._implCollider;
|
|
50
59
|
}
|
|
51
|
-
onContactBegin = createCollisionEventEmitter((hasAnyListener) => {
|
|
52
|
-
this._updateListenerFlag(ContactEventListenerFlagIndex.begin, hasAnyListener);
|
|
53
|
-
});
|
|
54
|
-
onContactStay = createCollisionEventEmitter((hasAnyListener) => {
|
|
55
|
-
this._updateListenerFlag(ContactEventListenerFlagIndex.stay, hasAnyListener);
|
|
56
|
-
});
|
|
57
|
-
onContactEnd = createCollisionEventEmitter((hasAnyListener) => {
|
|
58
|
-
this._updateListenerFlag(ContactEventListenerFlagIndex.end, hasAnyListener);
|
|
59
|
-
});
|
|
60
60
|
intersect(opts) {
|
|
61
61
|
const world = this.world;
|
|
62
62
|
if (!world) {
|
|
@@ -167,6 +167,9 @@ let Collider2D = class Collider2D extends PhysicsComponent2DBase {
|
|
|
167
167
|
get _implCollider() {
|
|
168
168
|
return this._handle?.impl ?? undefined;
|
|
169
169
|
}
|
|
170
|
+
get sceneGraphScale() {
|
|
171
|
+
return this._transform.scale;
|
|
172
|
+
}
|
|
170
173
|
recreateCollider() {
|
|
171
174
|
this._destroyCollider();
|
|
172
175
|
const handle = this._handle;
|
|
@@ -219,9 +222,6 @@ let Collider2D = class Collider2D extends PhysicsComponent2DBase {
|
|
|
219
222
|
this._updateTransform();
|
|
220
223
|
}
|
|
221
224
|
}
|
|
222
|
-
get sceneGraphScale() {
|
|
223
|
-
return this._transform.scale;
|
|
224
|
-
}
|
|
225
225
|
updateSceneGraphScale() {
|
|
226
226
|
const implCollider = this._implCollider;
|
|
227
227
|
if (!implCollider) {
|
|
@@ -340,10 +340,10 @@ __decorate([
|
|
|
340
340
|
editable
|
|
341
341
|
], Collider2D.prototype, "center", null);
|
|
342
342
|
__decorate([
|
|
343
|
-
|
|
343
|
+
stored
|
|
344
344
|
], Collider2D.prototype, "_isSensor", void 0);
|
|
345
345
|
__decorate([
|
|
346
|
-
|
|
346
|
+
stored
|
|
347
347
|
], Collider2D.prototype, "_center", void 0);
|
|
348
348
|
__decorate([
|
|
349
349
|
requiresComponent(Transform2DComponent)
|
|
@@ -4,7 +4,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
4
4
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
|
-
import { editable, executeInEditMode, idem,
|
|
7
|
+
import { editable, executeInEditMode, idem, stored } from '@cyclonium/core/legacy-decorator';
|
|
8
8
|
import { Collider2D } from '../collider-2d.js';
|
|
9
9
|
import { px2Impl } from '../px2-impl.js';
|
|
10
10
|
import { EDITOR_NOT_IN_PREVIEW } from 'cc/env';
|
|
@@ -71,10 +71,10 @@ __decorate([
|
|
|
71
71
|
idem
|
|
72
72
|
], BoxCollider2D.prototype, "height", null);
|
|
73
73
|
__decorate([
|
|
74
|
-
|
|
74
|
+
stored
|
|
75
75
|
], BoxCollider2D.prototype, "_halfWidth", void 0);
|
|
76
76
|
__decorate([
|
|
77
|
-
|
|
77
|
+
stored
|
|
78
78
|
], BoxCollider2D.prototype, "_halfHeight", void 0);
|
|
79
79
|
BoxCollider2D = __decorate([
|
|
80
80
|
cycloBuiltinClass('BoxCollider2D'),
|
|
@@ -4,7 +4,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
4
4
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
|
-
import { editable, executeInEditMode, idem,
|
|
7
|
+
import { editable, executeInEditMode, idem, stored } from '@cyclonium/core/legacy-decorator';
|
|
8
8
|
import { Collider2D } from '../collider-2d.js';
|
|
9
9
|
import { px2Impl } from '../px2-impl.js';
|
|
10
10
|
import { EDITOR_NOT_IN_PREVIEW } from 'cc/env';
|
|
@@ -65,10 +65,10 @@ __decorate([
|
|
|
65
65
|
idem
|
|
66
66
|
], CapsuleCollider2D.prototype, "halfHeight", null);
|
|
67
67
|
__decorate([
|
|
68
|
-
|
|
68
|
+
stored
|
|
69
69
|
], CapsuleCollider2D.prototype, "_radius", void 0);
|
|
70
70
|
__decorate([
|
|
71
|
-
|
|
71
|
+
stored
|
|
72
72
|
], CapsuleCollider2D.prototype, "_halfHeight", void 0);
|
|
73
73
|
CapsuleCollider2D = __decorate([
|
|
74
74
|
cycloBuiltinClass('CapsuleCollider2D'),
|
|
@@ -4,7 +4,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
4
4
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
|
-
import { editable, executeInEditMode, idem,
|
|
7
|
+
import { editable, executeInEditMode, idem, stored } from '@cyclonium/core/legacy-decorator';
|
|
8
8
|
import { Collider2D } from '../collider-2d.js';
|
|
9
9
|
import { px2Impl } from '../px2-impl.js';
|
|
10
10
|
import { EDITOR_NOT_IN_PREVIEW } from 'cc/env';
|
|
@@ -49,7 +49,7 @@ __decorate([
|
|
|
49
49
|
idem
|
|
50
50
|
], CircleCollider2D.prototype, "radius", null);
|
|
51
51
|
__decorate([
|
|
52
|
-
|
|
52
|
+
stored
|
|
53
53
|
], CircleCollider2D.prototype, "_radius", void 0);
|
|
54
54
|
CircleCollider2D = __decorate([
|
|
55
55
|
cycloBuiltinClass('CircleCollider2D'),
|
|
@@ -28,8 +28,7 @@ let PolygonCollider2D = class PolygonCollider2D extends Collider2D {
|
|
|
28
28
|
const scale = this.sceneGraphScale;
|
|
29
29
|
out.setMinMax(Vec2.POSITIVE_INFINITY, Vec2.NEGATIVE_INFINITY);
|
|
30
30
|
const p = new Vec2();
|
|
31
|
-
for (
|
|
32
|
-
const point = this._points[i];
|
|
31
|
+
for (const point of this._points) {
|
|
33
32
|
out.extend(p.copyFrom(point).mulSelf(scale));
|
|
34
33
|
}
|
|
35
34
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
export declare class CollisionMatrix {
|
|
2
2
|
static readonly EXTENT = 16;
|
|
3
|
-
private get values();
|
|
4
|
-
private set values(value);
|
|
5
3
|
clone(): CollisionMatrix;
|
|
6
4
|
get(i: number, j: number): boolean;
|
|
7
5
|
set(i: number, j: number, value: boolean): void;
|
|
8
6
|
getCollisionsBitsOf(i: number): number;
|
|
9
7
|
private _values;
|
|
8
|
+
private get values();
|
|
9
|
+
private set values(value);
|
|
10
10
|
private _locate;
|
|
11
11
|
}
|
|
12
12
|
//# sourceMappingURL=collision-matrix.d.ts.map
|
package/lib/collision-matrix.js
CHANGED
|
@@ -5,19 +5,13 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
7
|
var CollisionMatrix_1;
|
|
8
|
-
import { editable,
|
|
8
|
+
import { editable, stored } from '@cyclonium/core/legacy-decorator';
|
|
9
9
|
import { cycloBuiltinClass } from '@cyclonium/core/internal';
|
|
10
10
|
import { dumpRaw } from '@cyclonium/core/utils';
|
|
11
11
|
const EXTENT = 16;
|
|
12
12
|
let CollisionMatrix = class CollisionMatrix {
|
|
13
13
|
static { CollisionMatrix_1 = this; }
|
|
14
14
|
static EXTENT = EXTENT;
|
|
15
|
-
get values() {
|
|
16
|
-
return this._values;
|
|
17
|
-
}
|
|
18
|
-
set values(values) {
|
|
19
|
-
this._values = [...values];
|
|
20
|
-
}
|
|
21
15
|
clone() {
|
|
22
16
|
const clone = new CollisionMatrix_1();
|
|
23
17
|
clone._values = this._values.slice();
|
|
@@ -45,6 +39,13 @@ let CollisionMatrix = class CollisionMatrix {
|
|
|
45
39
|
return bits;
|
|
46
40
|
}
|
|
47
41
|
_values = new Array(EXTENT * (EXTENT + 1) / 2).fill(false);
|
|
42
|
+
get values() {
|
|
43
|
+
return this._values;
|
|
44
|
+
}
|
|
45
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention -- The private accessor name is part of the serialized editor dump schema.
|
|
46
|
+
set values(values) {
|
|
47
|
+
this._values = [...values];
|
|
48
|
+
}
|
|
48
49
|
_locate(i, j) {
|
|
49
50
|
if (i < 0 || i >= EXTENT || j < 0 || j >= EXTENT) {
|
|
50
51
|
throw new Error(`Index out of range.`);
|
|
@@ -56,13 +57,14 @@ let CollisionMatrix = class CollisionMatrix {
|
|
|
56
57
|
return rowStart + j;
|
|
57
58
|
}
|
|
58
59
|
};
|
|
60
|
+
__decorate([
|
|
61
|
+
stored
|
|
62
|
+
], CollisionMatrix.prototype, "_values", void 0);
|
|
59
63
|
__decorate([
|
|
60
64
|
editable,
|
|
61
65
|
dumpRaw
|
|
66
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention -- The private accessor name is part of the serialized editor dump schema.
|
|
62
67
|
], CollisionMatrix.prototype, "values", null);
|
|
63
|
-
__decorate([
|
|
64
|
-
serializable
|
|
65
|
-
], CollisionMatrix.prototype, "_values", void 0);
|
|
66
68
|
CollisionMatrix = CollisionMatrix_1 = __decorate([
|
|
67
69
|
cycloBuiltinClass('CollisionMatrix')
|
|
68
70
|
], CollisionMatrix);
|
package/lib/gizmo-headless.js
CHANGED
|
@@ -1,7 +1,19 @@
|
|
|
1
|
-
export function drawBoxCollider2DGizmo() {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export function
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
export function drawBoxCollider2DGizmo() {
|
|
2
|
+
// Gizmos are intentionally disabled in headless builds.
|
|
3
|
+
}
|
|
4
|
+
export function drawCircleCollider2DGizmo() {
|
|
5
|
+
// Gizmos are intentionally disabled in headless builds.
|
|
6
|
+
}
|
|
7
|
+
export function drawCapsuleCollider2DGizmo() {
|
|
8
|
+
// Gizmos are intentionally disabled in headless builds.
|
|
9
|
+
}
|
|
10
|
+
export function drawBoxSceneQueryProbe2DGizmo() {
|
|
11
|
+
// Gizmos are intentionally disabled in headless builds.
|
|
12
|
+
}
|
|
13
|
+
export function drawCircleSceneQueryProbe2DGizmo() {
|
|
14
|
+
// Gizmos are intentionally disabled in headless builds.
|
|
15
|
+
}
|
|
16
|
+
export function drawCapsuleSceneQueryProbe2DGizmo() {
|
|
17
|
+
// Gizmos are intentionally disabled in headless builds.
|
|
18
|
+
}
|
|
7
19
|
//# sourceMappingURL=gizmo-headless.js.map
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export class Physics2DDebugger {
|
|
2
|
-
constructor() {
|
|
3
|
-
}
|
|
4
2
|
destroy() {
|
|
3
|
+
// No render resources exist in headless builds.
|
|
5
4
|
}
|
|
6
5
|
render() {
|
|
6
|
+
// Debug rendering is intentionally disabled in headless builds.
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
9
|
//# sourceMappingURL=physics-2d-debugger-headless.js.map
|
|
@@ -16,16 +16,6 @@ class Physics2DDebugRenderer extends Renderer {
|
|
|
16
16
|
this._material = material;
|
|
17
17
|
this._loadMaterial();
|
|
18
18
|
}
|
|
19
|
-
onEnable() {
|
|
20
|
-
if (this._renderRecord) {
|
|
21
|
-
this._renderRecord.model.enabled = true;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
onDisable() {
|
|
25
|
-
if (this._renderRecord) {
|
|
26
|
-
this._renderRecord.model.enabled = false;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
19
|
render(world) {
|
|
30
20
|
const { vertices, colors } = world.debugRender();
|
|
31
21
|
const vertexCount = vertices.length / 2;
|
|
@@ -42,6 +32,16 @@ class Physics2DDebugRenderer extends Renderer {
|
|
|
42
32
|
renderRecord.colorVertexBuffer.update(colors, colors.byteLength);
|
|
43
33
|
}
|
|
44
34
|
}
|
|
35
|
+
onEnable() {
|
|
36
|
+
if (this._renderRecord) {
|
|
37
|
+
this._renderRecord.model.enabled = true;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
onDisable() {
|
|
41
|
+
if (this._renderRecord) {
|
|
42
|
+
this._renderRecord.model.enabled = false;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
45
|
_material;
|
|
46
46
|
_materialLoaded = false;
|
|
47
47
|
_renderRecord;
|
|
@@ -4,11 +4,11 @@ export declare class Physics2DSettings extends Asset {
|
|
|
4
4
|
fps: number;
|
|
5
5
|
maxSubsteps: number;
|
|
6
6
|
get tags(): Record<string, number>;
|
|
7
|
-
private get tags_editor();
|
|
8
|
-
private set tags_editor(value);
|
|
9
7
|
get collisionMatrix(): CollisionMatrix;
|
|
10
8
|
findTagIndex(tag: string): number;
|
|
11
9
|
private _tags;
|
|
12
10
|
private _collisionMatrix;
|
|
11
|
+
private get tags_editor();
|
|
12
|
+
private set tags_editor(value);
|
|
13
13
|
}
|
|
14
14
|
//# sourceMappingURL=physics-2d-settings.d.ts.map
|
|
@@ -5,7 +5,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
7
|
import { Asset, CCInteger } from 'cc';
|
|
8
|
-
import { editable,
|
|
8
|
+
import { editable, stored } from '@cyclonium/core/legacy-decorator';
|
|
9
9
|
import { cycloBuiltinClass } from '@cyclonium/core/internal';
|
|
10
10
|
import { CollisionMatrix } from './collision-matrix.js';
|
|
11
11
|
import { dumpRaw } from '@cyclonium/core/utils';
|
|
@@ -15,12 +15,6 @@ let Physics2DSettings = class Physics2DSettings extends Asset {
|
|
|
15
15
|
get tags() {
|
|
16
16
|
return this._tags;
|
|
17
17
|
}
|
|
18
|
-
get tags_editor() {
|
|
19
|
-
return this._tags;
|
|
20
|
-
}
|
|
21
|
-
set tags_editor(value) {
|
|
22
|
-
this._tags = { ...value };
|
|
23
|
-
}
|
|
24
18
|
get collisionMatrix() {
|
|
25
19
|
return this._collisionMatrix;
|
|
26
20
|
}
|
|
@@ -29,28 +23,36 @@ let Physics2DSettings = class Physics2DSettings extends Asset {
|
|
|
29
23
|
}
|
|
30
24
|
_tags = {};
|
|
31
25
|
_collisionMatrix = new CollisionMatrix();
|
|
26
|
+
get tags_editor() {
|
|
27
|
+
return this._tags;
|
|
28
|
+
}
|
|
29
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention -- Cocos editor inspectors consume this serialized compatibility property by name.
|
|
30
|
+
set tags_editor(value) {
|
|
31
|
+
this._tags = { ...value };
|
|
32
|
+
}
|
|
32
33
|
};
|
|
33
34
|
__decorate([
|
|
34
|
-
|
|
35
|
+
stored,
|
|
35
36
|
editable({ min: 1 })
|
|
36
37
|
], Physics2DSettings.prototype, "fps", void 0);
|
|
37
38
|
__decorate([
|
|
38
|
-
|
|
39
|
+
stored,
|
|
39
40
|
editable({ type: CCInteger, min: 1, step: 1 })
|
|
40
41
|
], Physics2DSettings.prototype, "maxSubsteps", void 0);
|
|
41
|
-
__decorate([
|
|
42
|
-
editable,
|
|
43
|
-
dumpRaw
|
|
44
|
-
], Physics2DSettings.prototype, "tags_editor", null);
|
|
45
42
|
__decorate([
|
|
46
43
|
editable
|
|
47
44
|
], Physics2DSettings.prototype, "collisionMatrix", null);
|
|
48
45
|
__decorate([
|
|
49
|
-
|
|
46
|
+
stored
|
|
50
47
|
], Physics2DSettings.prototype, "_tags", void 0);
|
|
51
48
|
__decorate([
|
|
52
|
-
|
|
49
|
+
stored
|
|
53
50
|
], Physics2DSettings.prototype, "_collisionMatrix", void 0);
|
|
51
|
+
__decorate([
|
|
52
|
+
editable,
|
|
53
|
+
dumpRaw
|
|
54
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention -- Cocos editor inspectors consume this serialized compatibility property by name.
|
|
55
|
+
], Physics2DSettings.prototype, "tags_editor", null);
|
|
54
56
|
Physics2DSettings = __decorate([
|
|
55
57
|
cycloBuiltinClass('Physics2DSettings')
|
|
56
58
|
], Physics2DSettings);
|
|
@@ -20,8 +20,12 @@ let PhysicsComponent2DBase = class PhysicsComponent2DBase extends CycloComponent
|
|
|
20
20
|
get world() {
|
|
21
21
|
return this._physicsWorld;
|
|
22
22
|
}
|
|
23
|
-
onSyncTransforms(_forceTransform, _forceScale) {
|
|
24
|
-
|
|
23
|
+
onSyncTransforms(_forceTransform, _forceScale) {
|
|
24
|
+
// Optional synchronization hook for physics components.
|
|
25
|
+
}
|
|
26
|
+
onAfterPhysicsStep() {
|
|
27
|
+
// Optional post-step hook for physics components.
|
|
28
|
+
}
|
|
25
29
|
onAwake() {
|
|
26
30
|
if (!this._attached) {
|
|
27
31
|
this._tryAttach();
|
|
@@ -47,14 +51,14 @@ let PhysicsComponent2DBase = class PhysicsComponent2DBase extends CycloComponent
|
|
|
47
51
|
_physicsWorld = null;
|
|
48
52
|
_firstEnabled = true;
|
|
49
53
|
_attached = false;
|
|
50
|
-
_handleAncestorChange() {
|
|
54
|
+
_handleAncestorChange = () => {
|
|
51
55
|
if (this.node) {
|
|
52
56
|
this._tryAttach();
|
|
53
57
|
}
|
|
54
58
|
else {
|
|
55
59
|
this._tryDetach();
|
|
56
60
|
}
|
|
57
|
-
}
|
|
61
|
+
};
|
|
58
62
|
_tryAttach() {
|
|
59
63
|
const node = this.node;
|
|
60
64
|
const physicsWorld = getPhysicsWorld(node.scene);
|
|
@@ -6,10 +6,10 @@ export declare class PhysicsWorld2DSceneComponent extends CycloComponent {
|
|
|
6
6
|
set debug(v: boolean);
|
|
7
7
|
get settings(): Physics2DSettings | null;
|
|
8
8
|
set settings(value: Physics2DSettings | null);
|
|
9
|
+
get physicsWorld(): PhysicsWorld2D | null;
|
|
9
10
|
protected onAwake(): void;
|
|
10
11
|
protected onDestroy(): void;
|
|
11
12
|
protected onUpdate(deltaTime: number): void;
|
|
12
|
-
get physicsWorld(): PhysicsWorld2D | null;
|
|
13
13
|
private _physicsWorld;
|
|
14
14
|
private _physicsDebugger;
|
|
15
15
|
private _lastUpdateFrame;
|
|
@@ -5,7 +5,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
7
|
import { EDITOR_NOT_IN_PREVIEW } from 'cc/env';
|
|
8
|
-
import { editable, executionOrder, idem,
|
|
8
|
+
import { editable, executionOrder, idem, stored } from '@cyclonium/core/legacy-decorator';
|
|
9
9
|
import { CycloComponent, PredefinedExecutionOrder } from '@cyclonium/core/framework';
|
|
10
10
|
import { director } from 'cc';
|
|
11
11
|
import { cycloBuiltinClass, TimeAccumulator } from '@cyclonium/core/internal';
|
|
@@ -37,6 +37,9 @@ let PhysicsWorld2DSceneComponent = class PhysicsWorld2DSceneComponent extends Cy
|
|
|
37
37
|
set settings(value) {
|
|
38
38
|
this._settings = value;
|
|
39
39
|
}
|
|
40
|
+
get physicsWorld() {
|
|
41
|
+
return this._physicsWorld;
|
|
42
|
+
}
|
|
40
43
|
onAwake() {
|
|
41
44
|
if (!EDITOR_NOT_IN_PREVIEW) {
|
|
42
45
|
const settings = this._settings ?? getDefaultSettings();
|
|
@@ -79,9 +82,6 @@ let PhysicsWorld2DSceneComponent = class PhysicsWorld2DSceneComponent extends Cy
|
|
|
79
82
|
onUpdate(deltaTime) {
|
|
80
83
|
this._updateFrame(deltaTime);
|
|
81
84
|
}
|
|
82
|
-
get physicsWorld() {
|
|
83
|
-
return this._physicsWorld;
|
|
84
|
-
}
|
|
85
85
|
_physicsWorld = null;
|
|
86
86
|
_physicsDebugger = undefined;
|
|
87
87
|
_lastUpdateFrame = -1;
|
|
@@ -123,10 +123,10 @@ __decorate([
|
|
|
123
123
|
editable(Physics2DSettings)
|
|
124
124
|
], PhysicsWorld2DSceneComponent.prototype, "settings", null);
|
|
125
125
|
__decorate([
|
|
126
|
-
|
|
126
|
+
stored
|
|
127
127
|
], PhysicsWorld2DSceneComponent.prototype, "_debug", void 0);
|
|
128
128
|
__decorate([
|
|
129
|
-
|
|
129
|
+
stored
|
|
130
130
|
], PhysicsWorld2DSceneComponent.prototype, "_settings", void 0);
|
|
131
131
|
PhysicsWorld2DSceneComponent = __decorate([
|
|
132
132
|
cycloBuiltinClass('PhysicsWorld2DSceneComponent'),
|
|
@@ -42,7 +42,6 @@ export declare class PhysicsWorld2D {
|
|
|
42
42
|
get impl(): px2Impl.World;
|
|
43
43
|
destroy(): void;
|
|
44
44
|
step(deltaTime: number): void;
|
|
45
|
-
private _step;
|
|
46
45
|
setOutdated(): void;
|
|
47
46
|
getTagId(tag: string): number;
|
|
48
47
|
intersectionWithPoint(point: Vec2, filter: SceneQueryFilter): Generator<Collider2D, void, unknown>;
|
|
@@ -79,6 +78,7 @@ export declare class PhysicsWorld2D {
|
|
|
79
78
|
private _physicsComponents;
|
|
80
79
|
private _outDated;
|
|
81
80
|
private _emitterForWillDestroy;
|
|
81
|
+
private _step;
|
|
82
82
|
private _getTagBit;
|
|
83
83
|
private _createImplCollider;
|
|
84
84
|
private _removeImplCollider;
|
package/lib/physics-world-2d.js
CHANGED
|
@@ -79,30 +79,6 @@ export class PhysicsWorld2D {
|
|
|
79
79
|
this._step(stepFraction, remainingSubsteps === 1);
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
|
-
_step(stepFraction, isLastSubstep) {
|
|
83
|
-
const outdated = this._outDated;
|
|
84
|
-
this._outDated = false;
|
|
85
|
-
for (const component of this._physicsComponents) {
|
|
86
|
-
if (!component.enabled) {
|
|
87
|
-
continue;
|
|
88
|
-
}
|
|
89
|
-
invokeOnSyncTransforms(component, outdated, outdated);
|
|
90
|
-
}
|
|
91
|
-
for (const { component } of this._rigidBodies.values()) {
|
|
92
|
-
if (!component.enabled) {
|
|
93
|
-
continue;
|
|
94
|
-
}
|
|
95
|
-
component.applyKinematicTargetForStep_internal(stepFraction, isLastSubstep);
|
|
96
|
-
}
|
|
97
|
-
this._worldImpl.step(this._eventQueue);
|
|
98
|
-
for (const component of this._physicsComponents) {
|
|
99
|
-
if (!component.enabled) {
|
|
100
|
-
continue;
|
|
101
|
-
}
|
|
102
|
-
invokeOnAfterStep(component);
|
|
103
|
-
}
|
|
104
|
-
this._emitEvents();
|
|
105
|
-
}
|
|
106
82
|
setOutdated() {
|
|
107
83
|
this._outDated = true;
|
|
108
84
|
}
|
|
@@ -273,10 +249,10 @@ export class PhysicsWorld2D {
|
|
|
273
249
|
destroy(wakeUp) {
|
|
274
250
|
this.removeCollider(wakeUp);
|
|
275
251
|
if (!world._physicsComponents.delete(component)) {
|
|
276
|
-
logger.warn(`Collider ${component} not found in physics components`);
|
|
252
|
+
logger.warn(`Collider ${component.name} not found in physics components`);
|
|
277
253
|
}
|
|
278
254
|
if (!world._linkManager.removeCollider(component)) {
|
|
279
|
-
logger.warn(`Collider ${component} not found in link manager`);
|
|
255
|
+
logger.warn(`Collider ${component.name} not found in link manager`);
|
|
280
256
|
}
|
|
281
257
|
},
|
|
282
258
|
get attachedRigidBody() {
|
|
@@ -322,6 +298,30 @@ export class PhysicsWorld2D {
|
|
|
322
298
|
_physicsComponents = new Set();
|
|
323
299
|
_outDated = false;
|
|
324
300
|
_emitterForWillDestroy = new ManagedEventEmitter();
|
|
301
|
+
_step(stepFraction, isLastSubstep) {
|
|
302
|
+
const outdated = this._outDated;
|
|
303
|
+
this._outDated = false;
|
|
304
|
+
for (const component of this._physicsComponents) {
|
|
305
|
+
if (!component.enabled) {
|
|
306
|
+
continue;
|
|
307
|
+
}
|
|
308
|
+
invokeOnSyncTransforms(component, outdated, outdated);
|
|
309
|
+
}
|
|
310
|
+
for (const { component } of this._rigidBodies.values()) {
|
|
311
|
+
if (!component.enabled) {
|
|
312
|
+
continue;
|
|
313
|
+
}
|
|
314
|
+
component.applyKinematicTargetForStep_internal(stepFraction, isLastSubstep);
|
|
315
|
+
}
|
|
316
|
+
this._worldImpl.step(this._eventQueue);
|
|
317
|
+
for (const component of this._physicsComponents) {
|
|
318
|
+
if (!component.enabled) {
|
|
319
|
+
continue;
|
|
320
|
+
}
|
|
321
|
+
invokeOnAfterStep(component);
|
|
322
|
+
}
|
|
323
|
+
this._emitEvents();
|
|
324
|
+
}
|
|
325
325
|
_getTagBit(tag) {
|
|
326
326
|
return this._tags[tag] ?? -1;
|
|
327
327
|
}
|
package/lib/px2-impl.js
CHANGED
|
@@ -4,11 +4,9 @@ export { px2Impl };
|
|
|
4
4
|
export const initializePx2Impl = (() => {
|
|
5
5
|
let promise = null;
|
|
6
6
|
return async () => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
})();
|
|
11
|
-
}
|
|
7
|
+
promise ??= (async () => {
|
|
8
|
+
await px2Impl.__init__();
|
|
9
|
+
})();
|
|
12
10
|
await promise;
|
|
13
11
|
};
|
|
14
12
|
})();
|
package/lib/rigid-body-2d.d.ts
CHANGED
|
@@ -34,13 +34,13 @@ export declare class RigidBody2D extends PhysicsComponent2DBase {
|
|
|
34
34
|
set rotation(value: number);
|
|
35
35
|
get linearVelocity(): Vec2;
|
|
36
36
|
set linearVelocity(value: Vec2);
|
|
37
|
+
get impl(): px2Impl.RigidBody | undefined;
|
|
37
38
|
hasTag(tag: string): boolean;
|
|
38
39
|
addTag(tag: string): void;
|
|
39
40
|
/** Sets the position target reached across the next physics step batch. */
|
|
40
41
|
setNextKinematicPosition(position: Vec2): void;
|
|
41
42
|
/** Sets the rotation target reached across the next physics step batch. */
|
|
42
43
|
setNextKinematicRotation(rotation: number): void;
|
|
43
|
-
get impl(): px2Impl.RigidBody | undefined;
|
|
44
44
|
protected onDestroy(): void;
|
|
45
45
|
protected onAttachToWorld(world: PhysicsWorld2D): void;
|
|
46
46
|
protected onDetachFromWorld(_world: PhysicsWorld2D): void;
|
package/lib/rigid-body-2d.js
CHANGED
|
@@ -5,7 +5,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
7
|
import { Transform2DComponent, TransformChangeFlagsObserver, TransformFlag } from '@cyclonium/core/2d';
|
|
8
|
-
import { designType, editable, idem, requiresComponent,
|
|
8
|
+
import { designType, editable, idem, requiresComponent, stored } from '@cyclonium/core/legacy-decorator';
|
|
9
9
|
import { Vec2 } from '@cyclonium/core/math/vec2';
|
|
10
10
|
import { fromPx2ImplVec2, toPx2ImplVec2 } from './exchange.js';
|
|
11
11
|
import { px2Impl } from './px2-impl.js';
|
|
@@ -133,6 +133,9 @@ let RigidBody2D = class RigidBody2D extends PhysicsComponent2DBase {
|
|
|
133
133
|
}
|
|
134
134
|
}
|
|
135
135
|
}
|
|
136
|
+
get impl() {
|
|
137
|
+
return this._rigidBodyControlBlock?.impl;
|
|
138
|
+
}
|
|
136
139
|
hasTag(tag) {
|
|
137
140
|
return this._tags.includes(tag);
|
|
138
141
|
}
|
|
@@ -153,8 +156,34 @@ let RigidBody2D = class RigidBody2D extends PhysicsComponent2DBase {
|
|
|
153
156
|
this._hasKinematicRotationTarget = true;
|
|
154
157
|
this._rigidBodyControlBlock?.impl.setNextKinematicRotation(rotation);
|
|
155
158
|
}
|
|
156
|
-
|
|
157
|
-
|
|
159
|
+
/** @internal */
|
|
160
|
+
applyKinematicTargetForStep_internal(stepFraction, isLastSubstep) {
|
|
161
|
+
const implBody = this._rigidBodyControlBlock?.impl;
|
|
162
|
+
if (!implBody || this._type !== RigidBody2DType.kinematicPositionBased) {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
if (this._hasKinematicPositionTarget) {
|
|
166
|
+
const substepTarget = this._substepKinematicPositionTarget;
|
|
167
|
+
if (isLastSubstep) {
|
|
168
|
+
substepTarget.copyFrom(this._kinematicPositionTarget);
|
|
169
|
+
this._hasKinematicPositionTarget = false;
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
const position = this._physicsPosition;
|
|
173
|
+
const target = this._kinematicPositionTarget;
|
|
174
|
+
substepTarget.set(lerp(position.x, target.x, stepFraction), lerp(position.y, target.y, stepFraction));
|
|
175
|
+
}
|
|
176
|
+
implBody.setNextKinematicTranslation(substepTarget);
|
|
177
|
+
}
|
|
178
|
+
if (this._hasKinematicRotationTarget) {
|
|
179
|
+
const substepTarget = isLastSubstep
|
|
180
|
+
? this._kinematicRotationTarget
|
|
181
|
+
: lerpAngle(this._physicsRotation, this._kinematicRotationTarget, stepFraction);
|
|
182
|
+
if (isLastSubstep) {
|
|
183
|
+
this._hasKinematicRotationTarget = false;
|
|
184
|
+
}
|
|
185
|
+
implBody.setNextKinematicRotation(substepTarget);
|
|
186
|
+
}
|
|
158
187
|
}
|
|
159
188
|
onDestroy() {
|
|
160
189
|
super.onDestroy();
|
|
@@ -194,35 +223,6 @@ let RigidBody2D = class RigidBody2D extends PhysicsComponent2DBase {
|
|
|
194
223
|
onSyncTransforms(forceTransform, _forceScale) {
|
|
195
224
|
this._syncToPhysics(forceTransform);
|
|
196
225
|
}
|
|
197
|
-
/** @internal */
|
|
198
|
-
applyKinematicTargetForStep_internal(stepFraction, isLastSubstep) {
|
|
199
|
-
const implBody = this._rigidBodyControlBlock?.impl;
|
|
200
|
-
if (!implBody || this._type !== RigidBody2DType.kinematicPositionBased) {
|
|
201
|
-
return;
|
|
202
|
-
}
|
|
203
|
-
if (this._hasKinematicPositionTarget) {
|
|
204
|
-
const substepTarget = this._substepKinematicPositionTarget;
|
|
205
|
-
if (isLastSubstep) {
|
|
206
|
-
substepTarget.copyFrom(this._kinematicPositionTarget);
|
|
207
|
-
this._hasKinematicPositionTarget = false;
|
|
208
|
-
}
|
|
209
|
-
else {
|
|
210
|
-
const position = this._physicsPosition;
|
|
211
|
-
const target = this._kinematicPositionTarget;
|
|
212
|
-
substepTarget.set(lerp(position.x, target.x, stepFraction), lerp(position.y, target.y, stepFraction));
|
|
213
|
-
}
|
|
214
|
-
implBody.setNextKinematicTranslation(substepTarget);
|
|
215
|
-
}
|
|
216
|
-
if (this._hasKinematicRotationTarget) {
|
|
217
|
-
const substepTarget = isLastSubstep
|
|
218
|
-
? this._kinematicRotationTarget
|
|
219
|
-
: lerpAngle(this._physicsRotation, this._kinematicRotationTarget, stepFraction);
|
|
220
|
-
if (isLastSubstep) {
|
|
221
|
-
this._hasKinematicRotationTarget = false;
|
|
222
|
-
}
|
|
223
|
-
implBody.setNextKinematicRotation(substepTarget);
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
226
|
onAfterPhysicsStep() {
|
|
227
227
|
this._syncFromPhysics();
|
|
228
228
|
}
|
|
@@ -397,19 +397,19 @@ __decorate([
|
|
|
397
397
|
idem
|
|
398
398
|
], RigidBody2D.prototype, "linearVelocity", null);
|
|
399
399
|
__decorate([
|
|
400
|
-
|
|
400
|
+
stored
|
|
401
401
|
], RigidBody2D.prototype, "_tags", void 0);
|
|
402
402
|
__decorate([
|
|
403
|
-
|
|
403
|
+
stored
|
|
404
404
|
], RigidBody2D.prototype, "_type", void 0);
|
|
405
405
|
__decorate([
|
|
406
|
-
|
|
406
|
+
stored
|
|
407
407
|
], RigidBody2D.prototype, "_ccd", void 0);
|
|
408
408
|
__decorate([
|
|
409
|
-
|
|
409
|
+
stored
|
|
410
410
|
], RigidBody2D.prototype, "_gravityScale", void 0);
|
|
411
411
|
__decorate([
|
|
412
|
-
|
|
412
|
+
stored
|
|
413
413
|
], RigidBody2D.prototype, "_collisionTargetTypeFilter", void 0);
|
|
414
414
|
__decorate([
|
|
415
415
|
requiresComponent(Transform2DComponent)
|
|
@@ -84,10 +84,6 @@ export declare abstract class SceneQueryProbe2D extends PhysicsComponent2DBase {
|
|
|
84
84
|
protected onAttachToWorld(_world: PhysicsWorld2D): void;
|
|
85
85
|
protected onDetachFromWorld(_world: PhysicsWorld2D): void;
|
|
86
86
|
protected onUpdate(): void;
|
|
87
|
-
private _getFilter;
|
|
88
|
-
private _createFilter;
|
|
89
|
-
private _invalidateFilter;
|
|
90
|
-
private _clearFilterCache;
|
|
91
87
|
private _targetTags;
|
|
92
88
|
private _dynamics;
|
|
93
89
|
private _fixed;
|
|
@@ -98,5 +94,9 @@ export declare abstract class SceneQueryProbe2D extends PhysicsComponent2DBase {
|
|
|
98
94
|
private _filterWorld;
|
|
99
95
|
private _filterDirty;
|
|
100
96
|
private get _transform();
|
|
97
|
+
private _getFilter;
|
|
98
|
+
private _createFilter;
|
|
99
|
+
private _invalidateFilter;
|
|
100
|
+
private _clearFilterCache;
|
|
101
101
|
}
|
|
102
102
|
//# sourceMappingURL=scene-query-probe-2d.d.ts.map
|
|
@@ -7,7 +7,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
import { CCString } from 'cc';
|
|
8
8
|
import { EDITOR_NOT_IN_PREVIEW } from 'cc/env';
|
|
9
9
|
import { Transform2DComponent } from '@cyclonium/core/2d';
|
|
10
|
-
import { editable, idem, requiresComponent,
|
|
10
|
+
import { editable, idem, requiresComponent, stored } from '@cyclonium/core/legacy-decorator';
|
|
11
11
|
import { cycloBuiltinClass } from '@cyclonium/core/internal';
|
|
12
12
|
import { Vec2 } from '@cyclonium/core/math/vec2';
|
|
13
13
|
import { PhysicsComponent2DBase } from './physics-component-2d-base.js';
|
|
@@ -124,6 +124,7 @@ let SceneQueryProbe2D = class SceneQueryProbe2D extends PhysicsComponent2DBase {
|
|
|
124
124
|
return this._transform.scale;
|
|
125
125
|
}
|
|
126
126
|
onAttachToWorld(_world) {
|
|
127
|
+
// Scene query probes do not allocate simulation objects.
|
|
127
128
|
}
|
|
128
129
|
onDetachFromWorld(_world) {
|
|
129
130
|
this._clearFilterCache();
|
|
@@ -133,6 +134,16 @@ let SceneQueryProbe2D = class SceneQueryProbe2D extends PhysicsComponent2DBase {
|
|
|
133
134
|
this.drawGizmo();
|
|
134
135
|
}
|
|
135
136
|
}
|
|
137
|
+
_targetTags = [];
|
|
138
|
+
_dynamics = true;
|
|
139
|
+
_fixed = true;
|
|
140
|
+
_kinematics = true;
|
|
141
|
+
_sensors = true;
|
|
142
|
+
_solids = true;
|
|
143
|
+
_filterCache = undefined;
|
|
144
|
+
_filterWorld = undefined;
|
|
145
|
+
_filterDirty = true;
|
|
146
|
+
get _transform() { return undefined; }
|
|
136
147
|
_getFilter(world) {
|
|
137
148
|
if (!this._filterCache || this._filterWorld !== world || this._filterDirty) {
|
|
138
149
|
this._filterCache = this._createFilter(world);
|
|
@@ -161,16 +172,6 @@ let SceneQueryProbe2D = class SceneQueryProbe2D extends PhysicsComponent2DBase {
|
|
|
161
172
|
this._filterWorld = undefined;
|
|
162
173
|
this._filterDirty = true;
|
|
163
174
|
}
|
|
164
|
-
_targetTags = [];
|
|
165
|
-
_dynamics = true;
|
|
166
|
-
_fixed = true;
|
|
167
|
-
_kinematics = true;
|
|
168
|
-
_sensors = true;
|
|
169
|
-
_solids = true;
|
|
170
|
-
_filterCache = undefined;
|
|
171
|
-
_filterWorld = undefined;
|
|
172
|
-
_filterDirty = true;
|
|
173
|
-
get _transform() { return undefined; }
|
|
174
175
|
};
|
|
175
176
|
__decorate([
|
|
176
177
|
editable(CCString)
|
|
@@ -196,22 +197,22 @@ __decorate([
|
|
|
196
197
|
idem
|
|
197
198
|
], SceneQueryProbe2D.prototype, "solids", null);
|
|
198
199
|
__decorate([
|
|
199
|
-
|
|
200
|
+
stored
|
|
200
201
|
], SceneQueryProbe2D.prototype, "_targetTags", void 0);
|
|
201
202
|
__decorate([
|
|
202
|
-
|
|
203
|
+
stored
|
|
203
204
|
], SceneQueryProbe2D.prototype, "_dynamics", void 0);
|
|
204
205
|
__decorate([
|
|
205
|
-
|
|
206
|
+
stored
|
|
206
207
|
], SceneQueryProbe2D.prototype, "_fixed", void 0);
|
|
207
208
|
__decorate([
|
|
208
|
-
|
|
209
|
+
stored
|
|
209
210
|
], SceneQueryProbe2D.prototype, "_kinematics", void 0);
|
|
210
211
|
__decorate([
|
|
211
|
-
|
|
212
|
+
stored
|
|
212
213
|
], SceneQueryProbe2D.prototype, "_sensors", void 0);
|
|
213
214
|
__decorate([
|
|
214
|
-
|
|
215
|
+
stored
|
|
215
216
|
], SceneQueryProbe2D.prototype, "_solids", void 0);
|
|
216
217
|
__decorate([
|
|
217
218
|
requiresComponent(Transform2DComponent)
|
|
@@ -14,8 +14,8 @@ export declare class BoxSceneQueryProbe2D extends SceneQueryProbe2D {
|
|
|
14
14
|
protected intersectWithWorld(world: PhysicsWorld2D, filter: SceneQueryFilter): Generator<import("../collider-2d.js").Collider2D, void, unknown>;
|
|
15
15
|
protected sweepWithWorld(world: PhysicsWorld2D, transform: ShapeTransformDesc, direction: Vec2, maxDistance: number, opts: SceneQueryProbeSweepOptions, filter: SceneQueryFilter): import("../scene-query.js").ColliderShapeCastHit | undefined;
|
|
16
16
|
protected drawGizmo(): void;
|
|
17
|
-
private _getScaledHalfExtents;
|
|
18
17
|
private _halfExtents;
|
|
19
18
|
private _scaledHalfExtents;
|
|
19
|
+
private _getScaledHalfExtents;
|
|
20
20
|
}
|
|
21
21
|
//# sourceMappingURL=box-scene-query-probe-2d.d.ts.map
|
|
@@ -4,7 +4,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
4
4
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
|
-
import { editable, executeInEditMode, idem,
|
|
7
|
+
import { editable, executeInEditMode, idem, stored } from '@cyclonium/core/legacy-decorator';
|
|
8
8
|
import { cycloBuiltinClass } from '@cyclonium/core/internal';
|
|
9
9
|
import { Vec2 } from '@cyclonium/core/math/vec2';
|
|
10
10
|
import { drawBoxSceneQueryProbe2DGizmo } from '#gizmo';
|
|
@@ -40,19 +40,19 @@ let BoxSceneQueryProbe2D = class BoxSceneQueryProbe2D extends SceneQueryProbe2D
|
|
|
40
40
|
drawGizmo() {
|
|
41
41
|
drawBoxSceneQueryProbe2DGizmo(this);
|
|
42
42
|
}
|
|
43
|
+
_halfExtents = new Vec2(1, 1);
|
|
44
|
+
_scaledHalfExtents = new Vec2();
|
|
43
45
|
_getScaledHalfExtents() {
|
|
44
46
|
const scale = this.queryScale;
|
|
45
47
|
return Vec2.set(this._scaledHalfExtents, this._halfExtents.x * scale.x, this._halfExtents.y * scale.y);
|
|
46
48
|
}
|
|
47
|
-
_halfExtents = new Vec2(1, 1);
|
|
48
|
-
_scaledHalfExtents = new Vec2();
|
|
49
49
|
};
|
|
50
50
|
__decorate([
|
|
51
51
|
editable,
|
|
52
52
|
idem
|
|
53
53
|
], BoxSceneQueryProbe2D.prototype, "halfExtents", null);
|
|
54
54
|
__decorate([
|
|
55
|
-
|
|
55
|
+
stored
|
|
56
56
|
], BoxSceneQueryProbe2D.prototype, "_halfExtents", void 0);
|
|
57
57
|
BoxSceneQueryProbe2D = __decorate([
|
|
58
58
|
cycloBuiltinClass('BoxSceneQueryProbe2D'),
|
|
@@ -19,9 +19,9 @@ export declare class CapsuleSceneQueryProbe2D extends SceneQueryProbe2D {
|
|
|
19
19
|
protected intersectWithWorld(world: PhysicsWorld2D, filter: SceneQueryFilter): Generator<import("../collider-2d.js").Collider2D, void, unknown>;
|
|
20
20
|
protected sweepWithWorld(world: PhysicsWorld2D, transform: ShapeTransformDesc, direction: Vec2, maxDistance: number, opts: SceneQueryProbeSweepOptions, filter: SceneQueryFilter): import("../scene-query.js").ColliderShapeCastHit | undefined;
|
|
21
21
|
protected drawGizmo(): void;
|
|
22
|
-
private _getUniformScale;
|
|
23
|
-
private _getScaledShape;
|
|
24
22
|
private _radius;
|
|
25
23
|
private _halfHeight;
|
|
24
|
+
private _getUniformScale;
|
|
25
|
+
private _getScaledShape;
|
|
26
26
|
}
|
|
27
27
|
//# sourceMappingURL=capsule-scene-query-probe-2d.d.ts.map
|
|
@@ -4,7 +4,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
4
4
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
|
-
import { editable, executeInEditMode, idem,
|
|
7
|
+
import { editable, executeInEditMode, idem, stored } from '@cyclonium/core/legacy-decorator';
|
|
8
8
|
import { cycloBuiltinClass } from '@cyclonium/core/internal';
|
|
9
9
|
import { Vec2 } from '@cyclonium/core/math/vec2';
|
|
10
10
|
import { drawCapsuleSceneQueryProbe2DGizmo } from '#gizmo';
|
|
@@ -57,6 +57,8 @@ let CapsuleSceneQueryProbe2D = class CapsuleSceneQueryProbe2D extends SceneQuery
|
|
|
57
57
|
drawGizmo() {
|
|
58
58
|
drawCapsuleSceneQueryProbe2DGizmo(this);
|
|
59
59
|
}
|
|
60
|
+
_radius = 1;
|
|
61
|
+
_halfHeight = 1;
|
|
60
62
|
_getUniformScale() {
|
|
61
63
|
const scale = this.queryScale;
|
|
62
64
|
if (scale.x !== scale.y) {
|
|
@@ -71,8 +73,6 @@ let CapsuleSceneQueryProbe2D = class CapsuleSceneQueryProbe2D extends SceneQuery
|
|
|
71
73
|
radius: this._radius * scale,
|
|
72
74
|
};
|
|
73
75
|
}
|
|
74
|
-
_radius = 1;
|
|
75
|
-
_halfHeight = 1;
|
|
76
76
|
};
|
|
77
77
|
__decorate([
|
|
78
78
|
editable({ min: 0 }),
|
|
@@ -83,10 +83,10 @@ __decorate([
|
|
|
83
83
|
idem
|
|
84
84
|
], CapsuleSceneQueryProbe2D.prototype, "halfHeight", null);
|
|
85
85
|
__decorate([
|
|
86
|
-
|
|
86
|
+
stored
|
|
87
87
|
], CapsuleSceneQueryProbe2D.prototype, "_radius", void 0);
|
|
88
88
|
__decorate([
|
|
89
|
-
|
|
89
|
+
stored
|
|
90
90
|
], CapsuleSceneQueryProbe2D.prototype, "_halfHeight", void 0);
|
|
91
91
|
CapsuleSceneQueryProbe2D = __decorate([
|
|
92
92
|
cycloBuiltinClass('CapsuleSceneQueryProbe2D'),
|
|
@@ -14,7 +14,7 @@ export declare class CircleSceneQueryProbe2D extends SceneQueryProbe2D {
|
|
|
14
14
|
protected intersectWithWorld(world: PhysicsWorld2D, filter: SceneQueryFilter): Generator<import("../collider-2d.js").Collider2D, void, unknown>;
|
|
15
15
|
protected sweepWithWorld(world: PhysicsWorld2D, transform: ShapeTransformDesc, direction: Vec2, maxDistance: number, opts: SceneQueryProbeSweepOptions, filter: SceneQueryFilter): import("../scene-query.js").ColliderShapeCastHit | undefined;
|
|
16
16
|
protected drawGizmo(): void;
|
|
17
|
-
private _getScaledRadius;
|
|
18
17
|
private _radius;
|
|
18
|
+
private _getScaledRadius;
|
|
19
19
|
}
|
|
20
20
|
//# sourceMappingURL=circle-scene-query-probe-2d.d.ts.map
|
|
@@ -4,7 +4,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
4
4
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
|
-
import { editable, executeInEditMode, idem,
|
|
7
|
+
import { editable, executeInEditMode, idem, stored } from '@cyclonium/core/legacy-decorator';
|
|
8
8
|
import { cycloBuiltinClass } from '@cyclonium/core/internal';
|
|
9
9
|
import { Vec2 } from '@cyclonium/core/math/vec2';
|
|
10
10
|
import { drawCircleSceneQueryProbe2DGizmo } from '#gizmo';
|
|
@@ -40,6 +40,7 @@ let CircleSceneQueryProbe2D = class CircleSceneQueryProbe2D extends SceneQueryPr
|
|
|
40
40
|
drawGizmo() {
|
|
41
41
|
drawCircleSceneQueryProbe2DGizmo(this);
|
|
42
42
|
}
|
|
43
|
+
_radius = 1;
|
|
43
44
|
_getScaledRadius() {
|
|
44
45
|
const scale = this.queryScale;
|
|
45
46
|
if (scale.x !== scale.y) {
|
|
@@ -47,14 +48,13 @@ let CircleSceneQueryProbe2D = class CircleSceneQueryProbe2D extends SceneQueryPr
|
|
|
47
48
|
}
|
|
48
49
|
return this._radius * scale.x;
|
|
49
50
|
}
|
|
50
|
-
_radius = 1;
|
|
51
51
|
};
|
|
52
52
|
__decorate([
|
|
53
53
|
editable({ min: 0 }),
|
|
54
54
|
idem
|
|
55
55
|
], CircleSceneQueryProbe2D.prototype, "radius", null);
|
|
56
56
|
__decorate([
|
|
57
|
-
|
|
57
|
+
stored
|
|
58
58
|
], CircleSceneQueryProbe2D.prototype, "_radius", void 0);
|
|
59
59
|
CircleSceneQueryProbe2D = __decorate([
|
|
60
60
|
cycloBuiltinClass('CircleSceneQueryProbe2D'),
|
package/lib/scene-query.d.ts
CHANGED
|
@@ -2,7 +2,6 @@ import { Vec2 } from '@cyclonium/core/math/vec2';
|
|
|
2
2
|
import type { Collider2D } from './collider-2d.js';
|
|
3
3
|
import { px2Impl } from './px2-impl.js';
|
|
4
4
|
export declare class SceneQueryFilter {
|
|
5
|
-
constructor();
|
|
6
5
|
get dynamics(): boolean;
|
|
7
6
|
set dynamics(value: boolean);
|
|
8
7
|
get fixed(): boolean;
|
|
@@ -13,9 +12,9 @@ export declare class SceneQueryFilter {
|
|
|
13
12
|
set sensors(value: boolean);
|
|
14
13
|
get solids(): boolean;
|
|
15
14
|
set solids(value: boolean);
|
|
16
|
-
addTargetTag(tag: number): this;
|
|
17
15
|
get _filterFlags_internal(): number;
|
|
18
16
|
get _filterGroups_internal(): number;
|
|
17
|
+
addTargetTag(tag: number): this;
|
|
19
18
|
private _filterGroupFilter;
|
|
20
19
|
private _filterFlags;
|
|
21
20
|
private _getIncludesFlag;
|
package/lib/scene-query.js
CHANGED
|
@@ -2,8 +2,6 @@ import { Vec2 } from '@cyclonium/core/math/vec2';
|
|
|
2
2
|
import { px2Impl } from './px2-impl.js';
|
|
3
3
|
import { fromPx2ImplVec2 } from './exchange.js';
|
|
4
4
|
export class SceneQueryFilter {
|
|
5
|
-
constructor() {
|
|
6
|
-
}
|
|
7
5
|
get dynamics() {
|
|
8
6
|
return this._getIncludesFlag(px2Impl.QueryFilterFlags.EXCLUDE_DYNAMIC);
|
|
9
7
|
}
|
|
@@ -34,10 +32,6 @@ export class SceneQueryFilter {
|
|
|
34
32
|
set solids(value) {
|
|
35
33
|
this._setIncludesFlag(px2Impl.QueryFilterFlags.EXCLUDE_SOLIDS, value);
|
|
36
34
|
}
|
|
37
|
-
addTargetTag(tag) {
|
|
38
|
-
this._filterGroupFilter |= 1 << tag;
|
|
39
|
-
return this;
|
|
40
|
-
}
|
|
41
35
|
get _filterFlags_internal() {
|
|
42
36
|
return this._filterFlags;
|
|
43
37
|
}
|
|
@@ -46,6 +40,10 @@ export class SceneQueryFilter {
|
|
|
46
40
|
// return composeCollisionGroup(GROUP_MEMBERSHIP_ALLOW_SCENE_QUERY, this._filterGroupFilter);
|
|
47
41
|
return composeCollisionGroup(0xFFFF, this._filterGroupFilter);
|
|
48
42
|
}
|
|
43
|
+
addTargetTag(tag) {
|
|
44
|
+
this._filterGroupFilter |= 1 << tag;
|
|
45
|
+
return this;
|
|
46
|
+
}
|
|
49
47
|
_filterGroupFilter = 0;
|
|
50
48
|
_filterFlags = 0;
|
|
51
49
|
_getIncludesFlag(flag) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cyclonium/physics-2d",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/shrinktofit/cyclonium",
|
|
@@ -25,13 +25,13 @@
|
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@cyclonium/algorithm": "1.0.0",
|
|
28
|
-
"@cyclonium/debug-draw": "0.0
|
|
28
|
+
"@cyclonium/debug-draw": "1.0.0",
|
|
29
29
|
"@cyclonium/event": "0.0.103",
|
|
30
30
|
"@cyclonium/rapier2d": "0.0.102",
|
|
31
31
|
"@cyclonium/web-assembly": "0.0.102"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
|
-
"@cyclonium/core": "0.0
|
|
34
|
+
"@cyclonium/core": "1.0.0"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@types/fs-extra": "^11.0.4",
|