@cyclonium/physics-2d 0.0.100
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.d.ts +32 -0
- package/lib/body-collider-link.js +164 -0
- package/lib/character-controller-2d.d.ts +69 -0
- package/lib/character-controller-2d.js +399 -0
- package/lib/collider-2d.d.ts +81 -0
- package/lib/collider-2d.js +364 -0
- package/lib/colliders/box-collider-2d.d.ts +20 -0
- package/lib/colliders/box-collider-2d.js +84 -0
- package/lib/colliders/capsule-collider-2d.d.ts +17 -0
- package/lib/colliders/capsule-collider-2d.js +78 -0
- package/lib/colliders/circle-collider-2d.d.ts +14 -0
- package/lib/colliders/circle-collider-2d.js +59 -0
- package/lib/colliders/polygon-collider-2d.d.ts +17 -0
- package/lib/colliders/polygon-collider-2d.js +77 -0
- package/lib/collision-matrix.d.ts +12 -0
- package/lib/collision-matrix.js +70 -0
- package/lib/contact.d.ts +7 -0
- package/lib/contact.js +2 -0
- package/lib/exchange.d.ts +5 -0
- package/lib/exchange.js +23 -0
- package/lib/gizmo-headless.d.ts +7 -0
- package/lib/gizmo-headless.js +7 -0
- package/lib/gizmo.d.ts +13 -0
- package/lib/gizmo.js +122 -0
- package/lib/index.d.ts +20 -0
- package/lib/index.js +20 -0
- package/lib/physics-2d-debugger-headless.d.ts +6 -0
- package/lib/physics-2d-debugger-headless.js +9 -0
- package/lib/physics-2d-debugger.d.ts +11 -0
- package/lib/physics-2d-debugger.js +146 -0
- package/lib/physics-2d-settings.d.ts +13 -0
- package/lib/physics-2d-settings.js +53 -0
- package/lib/physics-component-2d-base.d.ts +22 -0
- package/lib/physics-component-2d-base.js +85 -0
- package/lib/physics-world-2d-scene-component.d.ts +20 -0
- package/lib/physics-world-2d-scene-component.js +107 -0
- package/lib/physics-world-2d.d.ts +103 -0
- package/lib/physics-world-2d.js +506 -0
- package/lib/physics-world-registry.d.ts +6 -0
- package/lib/physics-world-registry.js +26 -0
- package/lib/px2-impl.d.ts +4 -0
- package/lib/px2-impl.js +18 -0
- package/lib/rigid-body-2d.d.ts +72 -0
- package/lib/rigid-body-2d.js +391 -0
- package/lib/scene-query-probe-2d.d.ts +102 -0
- package/lib/scene-query-probe-2d.js +223 -0
- package/lib/scene-query-probes/box-scene-query-probe-2d.d.ts +21 -0
- package/lib/scene-query-probes/box-scene-query-probe-2d.js +62 -0
- package/lib/scene-query-probes/capsule-scene-query-probe-2d.d.ts +27 -0
- package/lib/scene-query-probes/capsule-scene-query-probe-2d.js +96 -0
- package/lib/scene-query-probes/circle-scene-query-probe-2d.d.ts +20 -0
- package/lib/scene-query-probes/circle-scene-query-probe-2d.js +64 -0
- package/lib/scene-query.d.ts +67 -0
- package/lib/scene-query.js +128 -0
- package/lib/shared.d.ts +9 -0
- package/lib/shared.js +42 -0
- package/lib/utils/3-to-2.d.ts +3 -0
- package/lib/utils/3-to-2.js +12 -0
- package/lib/wasm-binary-helper/index.d.ts +6 -0
- package/lib/wasm-binary-helper/index.js +14 -0
- package/lib/wasm-binary-helper/wasm-binary-id.d.ts +2 -0
- package/lib/wasm-binary-helper/wasm-binary-id.js +2 -0
- package/lib/wasm-binary-helper.d.ts +6 -0
- package/lib/wasm-binary-helper.js +6 -0
- package/package.json +50 -0
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { Vec2 } from '@cyclonium/core/math/vec2';
|
|
2
|
+
import { type Contact2DInfo } from './contact.js';
|
|
3
|
+
import { px2Impl } from './px2-impl.js';
|
|
4
|
+
import { PhysicsComponent2DBase } from './physics-component-2d-base.js';
|
|
5
|
+
import { ColliderShapeCastHit, ColliderShapeIntersection, RayColliderIntersection, type ShapeCastQueryOptions, type ShapeIntersectionQueryOptions } from './scene-query.js';
|
|
6
|
+
import type { Ray2D } from '@cyclonium/core/math/ray';
|
|
7
|
+
import { Bounds2D } from '@cyclonium/core/math/bounds-2d';
|
|
8
|
+
export declare abstract class Collider2D extends PhysicsComponent2DBase {
|
|
9
|
+
get attachedRigidBody(): import("./rigid-body-2d.js").RigidBody2D | null;
|
|
10
|
+
get isSensor(): boolean;
|
|
11
|
+
set isSensor(value: boolean);
|
|
12
|
+
get center(): Vec2;
|
|
13
|
+
set center(value: Vec2);
|
|
14
|
+
get bounds(): Bounds2D;
|
|
15
|
+
/**
|
|
16
|
+
* Test only.
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
get impl_internal(): px2Impl.Collider | undefined;
|
|
20
|
+
onContactBegin: import("@cyclonium/event").ManagedEventEmitter<[Collider2D, Collider2D, Contact2DInfo]>;
|
|
21
|
+
onContactStay: import("@cyclonium/event").ManagedEventEmitter<[Collider2D, Collider2D, Contact2DInfo]>;
|
|
22
|
+
onContactEnd: import("@cyclonium/event").ManagedEventEmitter<[Collider2D, Collider2D, Contact2DInfo]>;
|
|
23
|
+
intersect(opts: ShapeIntersectionQueryOptions): ColliderShapeIntersection | undefined;
|
|
24
|
+
cast(opts: ShapeCastQueryOptions): ColliderShapeCastHit | undefined;
|
|
25
|
+
castRay(ray: Ray2D, maxDistance: number, solid?: boolean): RayColliderIntersection | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* @internal
|
|
28
|
+
*/
|
|
29
|
+
_enableCollisionEventsSinceBody(value: boolean): void;
|
|
30
|
+
/**
|
|
31
|
+
* @internal
|
|
32
|
+
*/
|
|
33
|
+
_responseToBodyActiveCollisionTypes(value: number): void;
|
|
34
|
+
/**
|
|
35
|
+
* @internal
|
|
36
|
+
*/
|
|
37
|
+
_responseToBodyCollisionGroups(value: number): void;
|
|
38
|
+
/**
|
|
39
|
+
* @internal
|
|
40
|
+
*/
|
|
41
|
+
_responseToBodySolverGroups(value: number): void;
|
|
42
|
+
/**
|
|
43
|
+
* @internal
|
|
44
|
+
*/
|
|
45
|
+
_responseToAttachedRigidBodyChanged(): void;
|
|
46
|
+
protected get _implCollider(): px2Impl.Collider | undefined;
|
|
47
|
+
protected recreateCollider(): void;
|
|
48
|
+
protected onAttachToWorld(): void;
|
|
49
|
+
protected onDetachFromWorld(): void;
|
|
50
|
+
protected onEnabled(): void;
|
|
51
|
+
protected onDisabled(): void;
|
|
52
|
+
protected onSyncTransforms(forceTransform: boolean, forceScale: boolean): void;
|
|
53
|
+
protected abstract getShape(): px2Impl.Shape | undefined;
|
|
54
|
+
protected abstract computeShapeBounds(out: Bounds2D): void;
|
|
55
|
+
protected get sceneGraphScale(): Vec2;
|
|
56
|
+
protected updateSceneGraphScale(): void;
|
|
57
|
+
private _isSensor;
|
|
58
|
+
private _center;
|
|
59
|
+
private _handle;
|
|
60
|
+
private _listenerFlags;
|
|
61
|
+
private _bodyActiveCollisionTypes;
|
|
62
|
+
private _bodyCollisionGroups;
|
|
63
|
+
private _bodySolverGroups;
|
|
64
|
+
private _transformChangeFlagsObserver;
|
|
65
|
+
private _sceneGraphScaleCache;
|
|
66
|
+
private _shape;
|
|
67
|
+
/**
|
|
68
|
+
* `false` if we acquired the shape but the shape is invalid,
|
|
69
|
+
* otherwise either we have not acquired the shape or the shape is valid.
|
|
70
|
+
*/
|
|
71
|
+
private _shapeAcquired;
|
|
72
|
+
private _boundsCache;
|
|
73
|
+
private get _transform();
|
|
74
|
+
private _destroyCollider;
|
|
75
|
+
private _updateListenerFlag;
|
|
76
|
+
private _getActiveEvents;
|
|
77
|
+
private _acquireShape;
|
|
78
|
+
private _updateTransform;
|
|
79
|
+
private _computeBounds;
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=collider-2d.d.ts.map
|
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
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
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { Transform2DComponent, TransformChangeFlagsObserver, TransformFlag } from '@cyclonium/core/2d';
|
|
8
|
+
import { editable, requiresComponent, serializable } from '@cyclonium/core/legacy-decorator';
|
|
9
|
+
import { cycloBuiltinClass } from '@cyclonium/core/internal';
|
|
10
|
+
import { Vec2 } from '@cyclonium/core/math/vec2';
|
|
11
|
+
import {} from './contact.js';
|
|
12
|
+
import { fromPx2ImplVec2, toPx2ImplVec2 } from './exchange.js';
|
|
13
|
+
import { px2Impl } from './px2-impl.js';
|
|
14
|
+
import { PhysicsComponent2DBase } from './physics-component-2d-base.js';
|
|
15
|
+
import { ContactEventListenerFlagIndex, createCollisionEventEmitter } from './shared.js';
|
|
16
|
+
import {} from './physics-world-2d.js';
|
|
17
|
+
import { assert } from '@cyclonium/core/utils';
|
|
18
|
+
import { getZRotation } from './utils/3-to-2.js';
|
|
19
|
+
import { ColliderShapeCastHit, ColliderShapeIntersection, RayColliderIntersection } from './scene-query.js';
|
|
20
|
+
import { Bounds2D } from '@cyclonium/core/math/bounds-2d';
|
|
21
|
+
let Collider2D = class Collider2D extends PhysicsComponent2DBase {
|
|
22
|
+
get attachedRigidBody() {
|
|
23
|
+
return this._handle?.attachedRigidBody ?? null;
|
|
24
|
+
}
|
|
25
|
+
get isSensor() {
|
|
26
|
+
return this._isSensor;
|
|
27
|
+
}
|
|
28
|
+
set isSensor(value) {
|
|
29
|
+
this._isSensor = value;
|
|
30
|
+
if (this._implCollider) {
|
|
31
|
+
this._implCollider.setSensor(value);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
get center() {
|
|
35
|
+
return this._center;
|
|
36
|
+
}
|
|
37
|
+
set center(value) {
|
|
38
|
+
Vec2.assign(this._center, value);
|
|
39
|
+
this._updateTransform();
|
|
40
|
+
}
|
|
41
|
+
get bounds() {
|
|
42
|
+
return this._computeBounds();
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Test only.
|
|
46
|
+
* @internal
|
|
47
|
+
*/
|
|
48
|
+
get impl_internal() {
|
|
49
|
+
return this._implCollider;
|
|
50
|
+
}
|
|
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
|
+
intersect(opts) {
|
|
61
|
+
const world = this.world;
|
|
62
|
+
if (!world) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
const implCollider = this._implCollider;
|
|
66
|
+
if (!implCollider) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const collierImpl = world.impl.intersectionWithShape(implCollider.translation(), implCollider.rotation(), implCollider.shape, opts.filter?._filterFlags_internal, opts.filter?._filterGroups_internal, undefined, undefined);
|
|
70
|
+
if (!collierImpl) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const collider = world.getColliderWithWarn_internal(collierImpl);
|
|
74
|
+
if (!collider) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
return new ColliderShapeIntersection(collider);
|
|
78
|
+
}
|
|
79
|
+
cast(opts) {
|
|
80
|
+
const world = this.world;
|
|
81
|
+
if (!world) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
const implCollider = this._implCollider;
|
|
85
|
+
if (!implCollider) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
const directionNormalized = opts.direction.normalize();
|
|
89
|
+
const shapePosition = implCollider.translation();
|
|
90
|
+
let filterPredicate;
|
|
91
|
+
if (opts.excludeColliders) {
|
|
92
|
+
const excludedColliderHandles = new Set();
|
|
93
|
+
for (const collider of opts.excludeColliders) {
|
|
94
|
+
const excludedImplCollider = collider.impl_internal;
|
|
95
|
+
if (excludedImplCollider) {
|
|
96
|
+
excludedColliderHandles.add(excludedImplCollider.handle);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (excludedColliderHandles.size > 0) {
|
|
100
|
+
filterPredicate = (collider) => !excludedColliderHandles.has(collider.handle);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
const hit = world.impl.castShape(shapePosition, implCollider.rotation(), toPx2ImplVec2(directionNormalized), implCollider.shape, opts.targetDistance ?? 1e-6, opts.maxDistance, false, opts.filter?._filterFlags_internal, opts.filter?._filterGroups_internal, undefined, undefined, filterPredicate);
|
|
104
|
+
if (!hit) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
const hitCollider = world.getColliderWithWarn_internal(hit.collider);
|
|
108
|
+
if (!hitCollider) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
return new ColliderShapeCastHit(hit, fromPx2ImplVec2(shapePosition), directionNormalized, hitCollider);
|
|
112
|
+
}
|
|
113
|
+
castRay(ray, maxDistance, solid) {
|
|
114
|
+
const world = this.world;
|
|
115
|
+
if (!world) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
const implCollider = this._implCollider;
|
|
119
|
+
if (!implCollider) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
const hit = implCollider.castRayAndGetNormal(new px2Impl.Ray(toPx2ImplVec2(ray.origin), toPx2ImplVec2(ray.direction)), maxDistance, solid ?? true);
|
|
123
|
+
if (!hit) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
return new RayColliderIntersection(this, hit.timeOfImpact, fromPx2ImplVec2(hit.normal));
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* @internal
|
|
130
|
+
*/
|
|
131
|
+
_enableCollisionEventsSinceBody(value) {
|
|
132
|
+
this._updateListenerFlag(ContactEventListenerFlagIndex.body, value);
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* @internal
|
|
136
|
+
*/
|
|
137
|
+
_responseToBodyActiveCollisionTypes(value) {
|
|
138
|
+
this._bodyActiveCollisionTypes = value;
|
|
139
|
+
if (this._implCollider) {
|
|
140
|
+
this._implCollider.setActiveCollisionTypes(this._bodyActiveCollisionTypes);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* @internal
|
|
145
|
+
*/
|
|
146
|
+
_responseToBodyCollisionGroups(value) {
|
|
147
|
+
this._bodyCollisionGroups = value;
|
|
148
|
+
if (this._implCollider) {
|
|
149
|
+
this._implCollider.setCollisionGroups(value);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* @internal
|
|
154
|
+
*/
|
|
155
|
+
_responseToBodySolverGroups(value) {
|
|
156
|
+
this._bodySolverGroups = value;
|
|
157
|
+
if (this._implCollider) {
|
|
158
|
+
this._implCollider.setSolverGroups(value);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* @internal
|
|
163
|
+
*/
|
|
164
|
+
_responseToAttachedRigidBodyChanged() {
|
|
165
|
+
this.recreateCollider();
|
|
166
|
+
}
|
|
167
|
+
get _implCollider() {
|
|
168
|
+
return this._handle?.impl ?? undefined;
|
|
169
|
+
}
|
|
170
|
+
recreateCollider() {
|
|
171
|
+
this._destroyCollider();
|
|
172
|
+
const handle = this._handle;
|
|
173
|
+
if (!handle) {
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
const shape = this._acquireShape();
|
|
177
|
+
if (!shape) {
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
const desc = new px2Impl.ColliderDesc(shape);
|
|
181
|
+
desc.setSensor(this._isSensor);
|
|
182
|
+
desc.setActiveEvents(this._getActiveEvents());
|
|
183
|
+
const collider = handle.createCollider(desc);
|
|
184
|
+
collider.setActiveCollisionTypes(this._bodyActiveCollisionTypes);
|
|
185
|
+
collider.setCollisionGroups(this._bodyCollisionGroups);
|
|
186
|
+
collider.setSolverGroups(this._bodySolverGroups);
|
|
187
|
+
this._updateTransform();
|
|
188
|
+
collider.setEnabled(this.enabledInHierarchy);
|
|
189
|
+
}
|
|
190
|
+
onAttachToWorld() {
|
|
191
|
+
if (!this.world) {
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
this._transformChangeFlagsObserver.observe(this._transform);
|
|
195
|
+
this._sceneGraphScaleCache.copyFrom(this.sceneGraphScale);
|
|
196
|
+
this._handle = this.world._addColliderHandle(this);
|
|
197
|
+
this.recreateCollider();
|
|
198
|
+
}
|
|
199
|
+
onDetachFromWorld() {
|
|
200
|
+
this._handle?.destroy(true);
|
|
201
|
+
this._handle = null;
|
|
202
|
+
}
|
|
203
|
+
onEnabled() {
|
|
204
|
+
super.onEnabled();
|
|
205
|
+
this._implCollider?.setEnabled(true);
|
|
206
|
+
}
|
|
207
|
+
onDisabled() {
|
|
208
|
+
this._implCollider?.setEnabled(false);
|
|
209
|
+
}
|
|
210
|
+
onSyncTransforms(forceTransform, forceScale) {
|
|
211
|
+
const changeFlags = this._transformChangeFlagsObserver.sync();
|
|
212
|
+
const currentScale = this.sceneGraphScale;
|
|
213
|
+
const scaleChanged = forceScale || !!(changeFlags & TransformFlag.scale) || !Vec2.equals(currentScale, this._sceneGraphScaleCache);
|
|
214
|
+
if (scaleChanged) {
|
|
215
|
+
this._sceneGraphScaleCache.copyFrom(currentScale);
|
|
216
|
+
this.updateSceneGraphScale();
|
|
217
|
+
}
|
|
218
|
+
if (forceTransform || scaleChanged || !!(changeFlags & (TransformFlag.position | TransformFlag.rotation))) {
|
|
219
|
+
this._updateTransform();
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
get sceneGraphScale() {
|
|
223
|
+
return this._transform.scale;
|
|
224
|
+
}
|
|
225
|
+
updateSceneGraphScale() {
|
|
226
|
+
const implCollider = this._implCollider;
|
|
227
|
+
if (!implCollider) {
|
|
228
|
+
this.recreateCollider();
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
const shape = this.getShape();
|
|
232
|
+
if (!shape) {
|
|
233
|
+
this.recreateCollider();
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
implCollider.setShape(shape);
|
|
237
|
+
}
|
|
238
|
+
_isSensor = false;
|
|
239
|
+
_center = new Vec2();
|
|
240
|
+
_handle = null;
|
|
241
|
+
_listenerFlags = 0;
|
|
242
|
+
_bodyActiveCollisionTypes = 0;
|
|
243
|
+
_bodyCollisionGroups = 0;
|
|
244
|
+
_bodySolverGroups = 0;
|
|
245
|
+
_transformChangeFlagsObserver = new TransformChangeFlagsObserver();
|
|
246
|
+
_sceneGraphScaleCache = new Vec2(1, 1);
|
|
247
|
+
_shape = undefined;
|
|
248
|
+
/**
|
|
249
|
+
* `false` if we acquired the shape but the shape is invalid,
|
|
250
|
+
* otherwise either we have not acquired the shape or the shape is valid.
|
|
251
|
+
*/
|
|
252
|
+
_shapeAcquired = false;
|
|
253
|
+
_boundsCache = new Bounds2D();
|
|
254
|
+
get _transform() { return undefined; }
|
|
255
|
+
_destroyCollider() {
|
|
256
|
+
this._shape = undefined;
|
|
257
|
+
this._shapeAcquired = false;
|
|
258
|
+
this._handle?.removeCollider(true);
|
|
259
|
+
}
|
|
260
|
+
_updateListenerFlag(index, hasAnyListener) {
|
|
261
|
+
if (hasAnyListener) {
|
|
262
|
+
this._listenerFlags |= 1 << index;
|
|
263
|
+
}
|
|
264
|
+
else {
|
|
265
|
+
this._listenerFlags &= ~(1 << index);
|
|
266
|
+
}
|
|
267
|
+
if (this._implCollider) {
|
|
268
|
+
this._implCollider.setActiveEvents(this._getActiveEvents());
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
_getActiveEvents() {
|
|
272
|
+
return this._listenerFlags === 0
|
|
273
|
+
? px2Impl.ActiveEvents.NONE
|
|
274
|
+
: px2Impl.ActiveEvents.COLLISION_EVENTS;
|
|
275
|
+
}
|
|
276
|
+
_acquireShape() {
|
|
277
|
+
if (this._shapeAcquired) {
|
|
278
|
+
return undefined;
|
|
279
|
+
}
|
|
280
|
+
if (!this._shape) {
|
|
281
|
+
this._shape = this.getShape();
|
|
282
|
+
if (!this._shape) {
|
|
283
|
+
this._shapeAcquired = true;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
return this._shape;
|
|
287
|
+
}
|
|
288
|
+
_updateTransform() {
|
|
289
|
+
const handle = this._handle;
|
|
290
|
+
if (!handle) {
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
const implCollider = handle.impl;
|
|
294
|
+
if (!implCollider) {
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
const parentRigidBody = handle.attachedRigidBody;
|
|
298
|
+
const pivot = this._center.clone();
|
|
299
|
+
const colliderTransform = this._transform;
|
|
300
|
+
pivot.x *= colliderTransform.scale.x;
|
|
301
|
+
pivot.y *= colliderTransform.scale.y;
|
|
302
|
+
if (parentRigidBody) {
|
|
303
|
+
assert(implCollider.parent());
|
|
304
|
+
if (parentRigidBody.node === this.node) {
|
|
305
|
+
// our parent rigid body already handled the scene graph transform
|
|
306
|
+
// only need the collider self's transform.
|
|
307
|
+
implCollider.setTranslationWrtParent(toPx2ImplVec2(pivot));
|
|
308
|
+
}
|
|
309
|
+
else {
|
|
310
|
+
const { position, rotation } = computeRelativeTransform(colliderTransform.node, parentRigidBody.node);
|
|
311
|
+
pivot.addSelf(position);
|
|
312
|
+
implCollider.setTranslationWrtParent(toPx2ImplVec2(pivot));
|
|
313
|
+
implCollider.setRotationWrtParent(rotation);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
else {
|
|
317
|
+
pivot.addSelf(colliderTransform.position);
|
|
318
|
+
implCollider.setTranslation(toPx2ImplVec2(pivot));
|
|
319
|
+
implCollider.setRotation(colliderTransform.rotation);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
_computeBounds() {
|
|
323
|
+
const bounds = this._boundsCache;
|
|
324
|
+
this.computeShapeBounds(bounds);
|
|
325
|
+
const pivot = this._center.clone();
|
|
326
|
+
const colliderTransform = this._transform;
|
|
327
|
+
pivot.x *= colliderTransform.scale.x;
|
|
328
|
+
pivot.y *= colliderTransform.scale.y;
|
|
329
|
+
const center = pivot;
|
|
330
|
+
center.rotateSelf(colliderTransform.rotation);
|
|
331
|
+
center.addSelf(colliderTransform.position);
|
|
332
|
+
bounds.center = center;
|
|
333
|
+
return bounds;
|
|
334
|
+
}
|
|
335
|
+
};
|
|
336
|
+
__decorate([
|
|
337
|
+
editable
|
|
338
|
+
], Collider2D.prototype, "isSensor", null);
|
|
339
|
+
__decorate([
|
|
340
|
+
editable
|
|
341
|
+
], Collider2D.prototype, "center", null);
|
|
342
|
+
__decorate([
|
|
343
|
+
serializable
|
|
344
|
+
], Collider2D.prototype, "_isSensor", void 0);
|
|
345
|
+
__decorate([
|
|
346
|
+
serializable
|
|
347
|
+
], Collider2D.prototype, "_center", void 0);
|
|
348
|
+
__decorate([
|
|
349
|
+
requiresComponent(Transform2DComponent)
|
|
350
|
+
], Collider2D.prototype, "_transform", null);
|
|
351
|
+
Collider2D = __decorate([
|
|
352
|
+
cycloBuiltinClass({ abstract: true })
|
|
353
|
+
], Collider2D);
|
|
354
|
+
export { Collider2D };
|
|
355
|
+
function computeRelativeTransform(child, parent) {
|
|
356
|
+
const parentRotation = getZRotation(parent.worldRotation);
|
|
357
|
+
const childPosition = child.worldPosition;
|
|
358
|
+
const parentPosition = parent.worldPosition;
|
|
359
|
+
return {
|
|
360
|
+
position: new Vec2(childPosition.x - parentPosition.x, childPosition.y - parentPosition.y).rotateSelf(-parentRotation),
|
|
361
|
+
rotation: getZRotation(child.worldRotation) - parentRotation,
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
//# sourceMappingURL=collider-2d.js.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Collider2D } from '../collider-2d.js';
|
|
2
|
+
import { px2Impl } from '../px2-impl.js';
|
|
3
|
+
import { Vec2 } from '@cyclonium/core/math/vec2';
|
|
4
|
+
import type { Bounds2D } from '@cyclonium/core/math/bounds-2d';
|
|
5
|
+
export declare class BoxCollider2D extends Collider2D {
|
|
6
|
+
get width(): number;
|
|
7
|
+
set width(value: number);
|
|
8
|
+
get height(): number;
|
|
9
|
+
set height(value: number);
|
|
10
|
+
get halfExtents(): Vec2;
|
|
11
|
+
set halfExtents(value: Vec2);
|
|
12
|
+
protected getShape(): px2Impl.Shape | undefined;
|
|
13
|
+
protected computeShapeBounds(out: Bounds2D): void;
|
|
14
|
+
protected onUpdate(): void;
|
|
15
|
+
protected updateSceneGraphScale(): void;
|
|
16
|
+
private _halfWidth;
|
|
17
|
+
private _halfHeight;
|
|
18
|
+
private _updateExtents;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=box-collider-2d.d.ts.map
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
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
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { editable, executeInEditMode, idem, serializable } from '@cyclonium/core/legacy-decorator';
|
|
8
|
+
import { Collider2D } from '../collider-2d.js';
|
|
9
|
+
import { px2Impl } from '../px2-impl.js';
|
|
10
|
+
import { EDITOR_NOT_IN_PREVIEW } from 'cc/env';
|
|
11
|
+
import { drawBoxCollider2DGizmo } from '#gizmo';
|
|
12
|
+
import { cycloBuiltinClass } from '@cyclonium/core/internal';
|
|
13
|
+
import { Vec2 } from '@cyclonium/core/math/vec2';
|
|
14
|
+
let BoxCollider2D = class BoxCollider2D extends Collider2D {
|
|
15
|
+
get width() {
|
|
16
|
+
return this._halfWidth * 2;
|
|
17
|
+
}
|
|
18
|
+
set width(value) {
|
|
19
|
+
this._halfWidth = value / 2;
|
|
20
|
+
this._updateExtents();
|
|
21
|
+
}
|
|
22
|
+
get height() {
|
|
23
|
+
return this._halfHeight * 2;
|
|
24
|
+
}
|
|
25
|
+
set height(value) {
|
|
26
|
+
this._halfHeight = value / 2;
|
|
27
|
+
this._updateExtents();
|
|
28
|
+
}
|
|
29
|
+
get halfExtents() {
|
|
30
|
+
return new Vec2(this._halfWidth, this._halfHeight);
|
|
31
|
+
}
|
|
32
|
+
set halfExtents(value) {
|
|
33
|
+
this._halfWidth = value.x;
|
|
34
|
+
this._halfHeight = value.y;
|
|
35
|
+
this._updateExtents();
|
|
36
|
+
}
|
|
37
|
+
getShape() {
|
|
38
|
+
const scale = this.sceneGraphScale;
|
|
39
|
+
return new px2Impl.Cuboid(this._halfWidth * scale.x, this._halfHeight * scale.y);
|
|
40
|
+
}
|
|
41
|
+
computeShapeBounds(out) {
|
|
42
|
+
const hw = this._halfWidth;
|
|
43
|
+
const hh = this._halfHeight;
|
|
44
|
+
const scale = this.sceneGraphScale;
|
|
45
|
+
out.setCenterSize(Vec2.ZERO, new Vec2(hw * scale.x * 2, hh * scale.y * 2));
|
|
46
|
+
}
|
|
47
|
+
onUpdate() {
|
|
48
|
+
if (EDITOR_NOT_IN_PREVIEW) {
|
|
49
|
+
drawBoxCollider2DGizmo(this);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
updateSceneGraphScale() {
|
|
53
|
+
this._updateExtents();
|
|
54
|
+
}
|
|
55
|
+
_halfWidth = 1;
|
|
56
|
+
_halfHeight = 1;
|
|
57
|
+
_updateExtents() {
|
|
58
|
+
if (!this._implCollider) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
const scale = this.sceneGraphScale;
|
|
62
|
+
this._implCollider.setHalfExtents(new px2Impl.Vector2(this._halfWidth * scale.x, this._halfHeight * scale.y));
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
__decorate([
|
|
66
|
+
editable({ min: 0 }),
|
|
67
|
+
idem
|
|
68
|
+
], BoxCollider2D.prototype, "width", null);
|
|
69
|
+
__decorate([
|
|
70
|
+
editable({ min: 0 }),
|
|
71
|
+
idem
|
|
72
|
+
], BoxCollider2D.prototype, "height", null);
|
|
73
|
+
__decorate([
|
|
74
|
+
serializable
|
|
75
|
+
], BoxCollider2D.prototype, "_halfWidth", void 0);
|
|
76
|
+
__decorate([
|
|
77
|
+
serializable
|
|
78
|
+
], BoxCollider2D.prototype, "_halfHeight", void 0);
|
|
79
|
+
BoxCollider2D = __decorate([
|
|
80
|
+
cycloBuiltinClass('BoxCollider2D'),
|
|
81
|
+
executeInEditMode
|
|
82
|
+
], BoxCollider2D);
|
|
83
|
+
export { BoxCollider2D };
|
|
84
|
+
//# sourceMappingURL=box-collider-2d.js.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Collider2D } from '../collider-2d.js';
|
|
2
|
+
import { px2Impl } from '../px2-impl.js';
|
|
3
|
+
import type { Bounds2D } from '@cyclonium/core/math/bounds-2d';
|
|
4
|
+
export declare class CapsuleCollider2D extends Collider2D {
|
|
5
|
+
get radius(): number;
|
|
6
|
+
set radius(value: number);
|
|
7
|
+
get halfHeight(): number;
|
|
8
|
+
set halfHeight(value: number);
|
|
9
|
+
protected getShape(): px2Impl.Capsule;
|
|
10
|
+
protected computeShapeBounds(out: Bounds2D): void;
|
|
11
|
+
protected onUpdate(): void;
|
|
12
|
+
protected updateSceneGraphScale(): void;
|
|
13
|
+
private _radius;
|
|
14
|
+
private _halfHeight;
|
|
15
|
+
private _getRadius;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=capsule-collider-2d.d.ts.map
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
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
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { editable, executeInEditMode, idem, serializable } from '@cyclonium/core/legacy-decorator';
|
|
8
|
+
import { Collider2D } from '../collider-2d.js';
|
|
9
|
+
import { px2Impl } from '../px2-impl.js';
|
|
10
|
+
import { EDITOR_NOT_IN_PREVIEW } from 'cc/env';
|
|
11
|
+
import { drawCapsuleCollider2DGizmo } from '#gizmo';
|
|
12
|
+
import { cycloBuiltinClass } from '@cyclonium/core/internal';
|
|
13
|
+
import { Vec2 } from '@cyclonium/core/math/vec2';
|
|
14
|
+
let CapsuleCollider2D = class CapsuleCollider2D extends Collider2D {
|
|
15
|
+
get radius() {
|
|
16
|
+
return this._radius;
|
|
17
|
+
}
|
|
18
|
+
set radius(value) {
|
|
19
|
+
this._radius = value;
|
|
20
|
+
this._implCollider?.setRadius(this._getRadius());
|
|
21
|
+
}
|
|
22
|
+
get halfHeight() {
|
|
23
|
+
return this._halfHeight;
|
|
24
|
+
}
|
|
25
|
+
set halfHeight(value) {
|
|
26
|
+
this._halfHeight = value;
|
|
27
|
+
this._implCollider?.setHalfHeight(this._halfHeight);
|
|
28
|
+
}
|
|
29
|
+
getShape() {
|
|
30
|
+
return new px2Impl.Capsule(this._halfHeight, this._getRadius());
|
|
31
|
+
}
|
|
32
|
+
computeShapeBounds(out) {
|
|
33
|
+
const scale = this.sceneGraphScale;
|
|
34
|
+
const uniformScale = scale.x;
|
|
35
|
+
out.setCenterSize(Vec2.ZERO, new Vec2(this._radius * 2, this._halfHeight + this._radius * 2).mulSelfScalar(uniformScale));
|
|
36
|
+
}
|
|
37
|
+
onUpdate() {
|
|
38
|
+
if (EDITOR_NOT_IN_PREVIEW) {
|
|
39
|
+
drawCapsuleCollider2DGizmo(this);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
updateSceneGraphScale() {
|
|
43
|
+
this._implCollider?.setRadius(this._getRadius());
|
|
44
|
+
}
|
|
45
|
+
_radius = 1;
|
|
46
|
+
_halfHeight = 1;
|
|
47
|
+
_getRadius() {
|
|
48
|
+
const scale = this.sceneGraphScale;
|
|
49
|
+
if (scale.x !== scale.y) {
|
|
50
|
+
console.warn('CapsuleCollider2D should have uniform scale');
|
|
51
|
+
}
|
|
52
|
+
return this._radius * scale.x;
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
__decorate([
|
|
56
|
+
editable({
|
|
57
|
+
min: 0,
|
|
58
|
+
}),
|
|
59
|
+
idem
|
|
60
|
+
], CapsuleCollider2D.prototype, "radius", null);
|
|
61
|
+
__decorate([
|
|
62
|
+
editable({
|
|
63
|
+
min: 0,
|
|
64
|
+
}),
|
|
65
|
+
idem
|
|
66
|
+
], CapsuleCollider2D.prototype, "halfHeight", null);
|
|
67
|
+
__decorate([
|
|
68
|
+
serializable
|
|
69
|
+
], CapsuleCollider2D.prototype, "_radius", void 0);
|
|
70
|
+
__decorate([
|
|
71
|
+
serializable
|
|
72
|
+
], CapsuleCollider2D.prototype, "_halfHeight", void 0);
|
|
73
|
+
CapsuleCollider2D = __decorate([
|
|
74
|
+
cycloBuiltinClass('CapsuleCollider2D'),
|
|
75
|
+
executeInEditMode
|
|
76
|
+
], CapsuleCollider2D);
|
|
77
|
+
export { CapsuleCollider2D };
|
|
78
|
+
//# sourceMappingURL=capsule-collider-2d.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Collider2D } from '../collider-2d.js';
|
|
2
|
+
import { px2Impl } from '../px2-impl.js';
|
|
3
|
+
import type { Bounds2D } from '@cyclonium/core/math/bounds-2d';
|
|
4
|
+
export declare class CircleCollider2D extends Collider2D {
|
|
5
|
+
get radius(): number;
|
|
6
|
+
set radius(value: number);
|
|
7
|
+
protected getShape(): px2Impl.Ball;
|
|
8
|
+
protected computeShapeBounds(out: Bounds2D): void;
|
|
9
|
+
protected onUpdate(): void;
|
|
10
|
+
protected updateSceneGraphScale(): void;
|
|
11
|
+
private _radius;
|
|
12
|
+
private _getRadius;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=circle-collider-2d.d.ts.map
|