@cyclonium/physics-2d 0.0.104 → 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 +17 -18
- package/lib/collider-2d.d.ts +4 -29
- 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 +3 -2
- package/lib/physics-2d-settings.js +22 -15
- package/lib/physics-component-2d-base.js +8 -4
- package/lib/physics-world-2d-scene-component.d.ts +5 -2
- package/lib/physics-world-2d-scene-component.js +43 -14
- package/lib/physics-world-2d.d.ts +2 -1
- package/lib/physics-world-2d.js +39 -18
- package/lib/px2-impl.js +3 -5
- package/lib/rigid-body-2d.d.ts +8 -1
- package/lib/rigid-body-2d.js +52 -10
- 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
|
@@ -5,14 +5,18 @@ 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,
|
|
9
|
-
import { CycloComponent } from '@cyclonium/core/framework';
|
|
10
|
-
import { PhysicsWorld2D } from './physics-world-2d.js';
|
|
11
|
-
import { Physics2DDebugger } from '#physics-2d-debugger';
|
|
12
|
-
import { PredefinedExecutionOrder } from '@cyclonium/core/framework';
|
|
8
|
+
import { editable, executionOrder, idem, stored } from '@cyclonium/core/legacy-decorator';
|
|
9
|
+
import { CycloComponent, PredefinedExecutionOrder } from '@cyclonium/core/framework';
|
|
13
10
|
import { director } from 'cc';
|
|
14
|
-
import { cycloBuiltinClass } from '@cyclonium/core/internal';
|
|
11
|
+
import { cycloBuiltinClass, TimeAccumulator } from '@cyclonium/core/internal';
|
|
12
|
+
import { logger } from '@cyclonium/core/log';
|
|
13
|
+
import { Physics2DDebugger } from '#physics-2d-debugger';
|
|
15
14
|
import { Physics2DSettings } from './physics-2d-settings.js';
|
|
15
|
+
import { PhysicsWorld2D } from './physics-world-2d.js';
|
|
16
|
+
const getDefaultSettings = (() => {
|
|
17
|
+
let defaultSettings;
|
|
18
|
+
return () => defaultSettings ??= new Physics2DSettings();
|
|
19
|
+
})();
|
|
16
20
|
let PhysicsWorld2DSceneComponent = class PhysicsWorld2DSceneComponent extends CycloComponent {
|
|
17
21
|
get debug() {
|
|
18
22
|
return this._debug;
|
|
@@ -33,9 +37,24 @@ let PhysicsWorld2DSceneComponent = class PhysicsWorld2DSceneComponent extends Cy
|
|
|
33
37
|
set settings(value) {
|
|
34
38
|
this._settings = value;
|
|
35
39
|
}
|
|
40
|
+
get physicsWorld() {
|
|
41
|
+
return this._physicsWorld;
|
|
42
|
+
}
|
|
36
43
|
onAwake() {
|
|
37
44
|
if (!EDITOR_NOT_IN_PREVIEW) {
|
|
38
|
-
const settings = this._settings ??
|
|
45
|
+
const settings = this._settings ?? getDefaultSettings();
|
|
46
|
+
let fps = settings.fps;
|
|
47
|
+
let maxSubsteps = settings.maxSubsteps;
|
|
48
|
+
if (!Number.isFinite(fps) || fps <= 0) {
|
|
49
|
+
logger.error(`Invalid Physics2DSettings.fps (${fps});`);
|
|
50
|
+
fps = getDefaultSettings().fps;
|
|
51
|
+
}
|
|
52
|
+
if (!Number.isInteger(maxSubsteps) || maxSubsteps <= 0) {
|
|
53
|
+
logger.error(`Invalid Physics2DSettings.maxSubsteps (${maxSubsteps});`);
|
|
54
|
+
maxSubsteps = getDefaultSettings().maxSubsteps;
|
|
55
|
+
}
|
|
56
|
+
this._timeAccumulator = new TimeAccumulator(1 / fps);
|
|
57
|
+
this._maxSubsteps = maxSubsteps;
|
|
39
58
|
this._physicsWorld = new PhysicsWorld2D({
|
|
40
59
|
scene: this.node.scene,
|
|
41
60
|
tags: settings.tags,
|
|
@@ -63,15 +82,15 @@ let PhysicsWorld2DSceneComponent = class PhysicsWorld2DSceneComponent extends Cy
|
|
|
63
82
|
onUpdate(deltaTime) {
|
|
64
83
|
this._updateFrame(deltaTime);
|
|
65
84
|
}
|
|
66
|
-
get physicsWorld() {
|
|
67
|
-
return this._physicsWorld;
|
|
68
|
-
}
|
|
69
85
|
_physicsWorld = null;
|
|
70
86
|
_physicsDebugger = undefined;
|
|
71
87
|
_lastUpdateFrame = -1;
|
|
88
|
+
_maxSubsteps = 4;
|
|
89
|
+
_timeAccumulator = new TimeAccumulator(1 / 60);
|
|
90
|
+
_overloading = false;
|
|
72
91
|
_debug = false;
|
|
73
92
|
_settings = null;
|
|
74
|
-
_updateFrame(
|
|
93
|
+
_updateFrame(deltaTime) {
|
|
75
94
|
const world = this._physicsWorld;
|
|
76
95
|
if (!world) {
|
|
77
96
|
return;
|
|
@@ -82,7 +101,17 @@ let PhysicsWorld2DSceneComponent = class PhysicsWorld2DSceneComponent extends Cy
|
|
|
82
101
|
this._lastUpdateFrame = actualFrame;
|
|
83
102
|
world.setOutdated();
|
|
84
103
|
}
|
|
85
|
-
|
|
104
|
+
const timeAccumulator = this._timeAccumulator;
|
|
105
|
+
const fixedDeltaTime = timeAccumulator.timeStep;
|
|
106
|
+
const maxSubsteps = this._maxSubsteps;
|
|
107
|
+
const actualSubsteps = timeAccumulator.advance(deltaTime, maxSubsteps);
|
|
108
|
+
const maximumDeltaTime = maxSubsteps * fixedDeltaTime;
|
|
109
|
+
const overloading = deltaTime > maximumDeltaTime;
|
|
110
|
+
if (overloading && !this._overloading) {
|
|
111
|
+
logger.warn(`PhysicsWorld2D clamped an update to the ${maxSubsteps}-substep limit.`);
|
|
112
|
+
}
|
|
113
|
+
this._overloading = overloading;
|
|
114
|
+
world.advanceSubsteps_internal(fixedDeltaTime, actualSubsteps);
|
|
86
115
|
this._physicsDebugger?.render();
|
|
87
116
|
}
|
|
88
117
|
};
|
|
@@ -94,10 +123,10 @@ __decorate([
|
|
|
94
123
|
editable(Physics2DSettings)
|
|
95
124
|
], PhysicsWorld2DSceneComponent.prototype, "settings", null);
|
|
96
125
|
__decorate([
|
|
97
|
-
|
|
126
|
+
stored
|
|
98
127
|
], PhysicsWorld2DSceneComponent.prototype, "_debug", void 0);
|
|
99
128
|
__decorate([
|
|
100
|
-
|
|
129
|
+
stored
|
|
101
130
|
], PhysicsWorld2DSceneComponent.prototype, "_settings", void 0);
|
|
102
131
|
PhysicsWorld2DSceneComponent = __decorate([
|
|
103
132
|
cycloBuiltinClass('PhysicsWorld2DSceneComponent'),
|
|
@@ -41,7 +41,7 @@ export declare class PhysicsWorld2D {
|
|
|
41
41
|
get listenersOnWillDestroy(): import("@cyclonium/event").EventListenerRegistry<[]>;
|
|
42
42
|
get impl(): px2Impl.World;
|
|
43
43
|
destroy(): void;
|
|
44
|
-
step(
|
|
44
|
+
step(deltaTime: number): void;
|
|
45
45
|
setOutdated(): void;
|
|
46
46
|
getTagId(tag: string): number;
|
|
47
47
|
intersectionWithPoint(point: Vec2, filter: SceneQueryFilter): Generator<Collider2D, void, unknown>;
|
|
@@ -78,6 +78,7 @@ export declare class PhysicsWorld2D {
|
|
|
78
78
|
private _physicsComponents;
|
|
79
79
|
private _outDated;
|
|
80
80
|
private _emitterForWillDestroy;
|
|
81
|
+
private _step;
|
|
81
82
|
private _getTagBit;
|
|
82
83
|
private _createImplCollider;
|
|
83
84
|
private _removeImplCollider;
|
package/lib/physics-world-2d.js
CHANGED
|
@@ -64,23 +64,20 @@ export class PhysicsWorld2D {
|
|
|
64
64
|
this._worldImpl.free();
|
|
65
65
|
this._worldImpl = null;
|
|
66
66
|
}
|
|
67
|
-
step(
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}
|
|
81
|
-
invokeOnAfterStep(component);
|
|
67
|
+
step(deltaTime) {
|
|
68
|
+
this.advanceSubsteps_internal(deltaTime, 1);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Advances a batch of physics steps where `deltaTime` is the length of each substep.
|
|
72
|
+
* @internal
|
|
73
|
+
*/
|
|
74
|
+
advanceSubsteps_internal(deltaTime, substepCount) {
|
|
75
|
+
this._worldImpl.timestep = deltaTime;
|
|
76
|
+
for (let i = 0; i < substepCount; i++) {
|
|
77
|
+
const remainingSubsteps = substepCount - i;
|
|
78
|
+
const stepFraction = 1 / remainingSubsteps;
|
|
79
|
+
this._step(stepFraction, remainingSubsteps === 1);
|
|
82
80
|
}
|
|
83
|
-
this._emitEvents();
|
|
84
81
|
}
|
|
85
82
|
setOutdated() {
|
|
86
83
|
this._outDated = true;
|
|
@@ -252,10 +249,10 @@ export class PhysicsWorld2D {
|
|
|
252
249
|
destroy(wakeUp) {
|
|
253
250
|
this.removeCollider(wakeUp);
|
|
254
251
|
if (!world._physicsComponents.delete(component)) {
|
|
255
|
-
logger.warn(`Collider ${component} not found in physics components`);
|
|
252
|
+
logger.warn(`Collider ${component.name} not found in physics components`);
|
|
256
253
|
}
|
|
257
254
|
if (!world._linkManager.removeCollider(component)) {
|
|
258
|
-
logger.warn(`Collider ${component} not found in link manager`);
|
|
255
|
+
logger.warn(`Collider ${component.name} not found in link manager`);
|
|
259
256
|
}
|
|
260
257
|
},
|
|
261
258
|
get attachedRigidBody() {
|
|
@@ -301,6 +298,30 @@ export class PhysicsWorld2D {
|
|
|
301
298
|
_physicsComponents = new Set();
|
|
302
299
|
_outDated = false;
|
|
303
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
|
+
}
|
|
304
325
|
_getTagBit(tag) {
|
|
305
326
|
return this._tags[tag] ?? -1;
|
|
306
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,11 +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;
|
|
40
|
+
/** Sets the position target reached across the next physics step batch. */
|
|
39
41
|
setNextKinematicPosition(position: Vec2): void;
|
|
42
|
+
/** Sets the rotation target reached across the next physics step batch. */
|
|
40
43
|
setNextKinematicRotation(rotation: number): void;
|
|
41
|
-
get impl(): px2Impl.RigidBody | undefined;
|
|
42
44
|
protected onDestroy(): void;
|
|
43
45
|
protected onAttachToWorld(world: PhysicsWorld2D): void;
|
|
44
46
|
protected onDetachFromWorld(_world: PhysicsWorld2D): void;
|
|
@@ -56,6 +58,11 @@ export declare class RigidBody2D extends PhysicsComponent2DBase {
|
|
|
56
58
|
private _physicsPosition;
|
|
57
59
|
private _physicsRotation;
|
|
58
60
|
private _linearVelocity;
|
|
61
|
+
private _kinematicPositionTarget;
|
|
62
|
+
private _substepKinematicPositionTarget;
|
|
63
|
+
private _kinematicRotationTarget;
|
|
64
|
+
private _hasKinematicPositionTarget;
|
|
65
|
+
private _hasKinematicRotationTarget;
|
|
59
66
|
private _listenerFlags;
|
|
60
67
|
private _transformChangeFlagsObserver;
|
|
61
68
|
private get _transform();
|
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';
|
|
@@ -15,8 +15,8 @@ import { createCollisionEventEmitter, ContactEventListenerFlagIndex } from './sh
|
|
|
15
15
|
import { CCString } from 'cc';
|
|
16
16
|
import { EDITOR_NOT_IN_PREVIEW } from 'cc/env';
|
|
17
17
|
import { cycloBuiltinClass } from '@cyclonium/core/internal';
|
|
18
|
-
import { approxEqual } from '@cyclonium/core/math/number';
|
|
19
|
-
import { to0ToPI2 } from '@cyclonium/core/math/trigonometry';
|
|
18
|
+
import { approxEqual, lerp } from '@cyclonium/core/math/number';
|
|
19
|
+
import { lerpAngle, to0ToPI2 } from '@cyclonium/core/math/trigonometry';
|
|
20
20
|
export var RigidBody2DType;
|
|
21
21
|
(function (RigidBody2DType) {
|
|
22
22
|
RigidBody2DType["fixed"] = "fixed";
|
|
@@ -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
|
}
|
|
@@ -141,14 +144,46 @@ let RigidBody2D = class RigidBody2D extends PhysicsComponent2DBase {
|
|
|
141
144
|
this._tags.push(tag);
|
|
142
145
|
}
|
|
143
146
|
}
|
|
147
|
+
/** Sets the position target reached across the next physics step batch. */
|
|
144
148
|
setNextKinematicPosition(position) {
|
|
149
|
+
this._kinematicPositionTarget.copyFrom(position);
|
|
150
|
+
this._hasKinematicPositionTarget = true;
|
|
145
151
|
this._rigidBodyControlBlock?.impl.setNextKinematicTranslation(position);
|
|
146
152
|
}
|
|
153
|
+
/** Sets the rotation target reached across the next physics step batch. */
|
|
147
154
|
setNextKinematicRotation(rotation) {
|
|
155
|
+
this._kinematicRotationTarget = rotation;
|
|
156
|
+
this._hasKinematicRotationTarget = true;
|
|
148
157
|
this._rigidBodyControlBlock?.impl.setNextKinematicRotation(rotation);
|
|
149
158
|
}
|
|
150
|
-
|
|
151
|
-
|
|
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
|
+
}
|
|
152
187
|
}
|
|
153
188
|
onDestroy() {
|
|
154
189
|
super.onDestroy();
|
|
@@ -200,6 +235,11 @@ let RigidBody2D = class RigidBody2D extends PhysicsComponent2DBase {
|
|
|
200
235
|
_physicsPosition = new Vec2();
|
|
201
236
|
_physicsRotation = 0.0;
|
|
202
237
|
_linearVelocity = new Vec2();
|
|
238
|
+
_kinematicPositionTarget = new Vec2();
|
|
239
|
+
_substepKinematicPositionTarget = new Vec2();
|
|
240
|
+
_kinematicRotationTarget = 0;
|
|
241
|
+
_hasKinematicPositionTarget = false;
|
|
242
|
+
_hasKinematicRotationTarget = false;
|
|
203
243
|
_listenerFlags = 0;
|
|
204
244
|
_transformChangeFlagsObserver = new TransformChangeFlagsObserver();
|
|
205
245
|
get _transform() { return undefined; }
|
|
@@ -275,6 +315,8 @@ let RigidBody2D = class RigidBody2D extends PhysicsComponent2DBase {
|
|
|
275
315
|
this._rigidBodyControlBlock = null;
|
|
276
316
|
this._physicsPosition.set(0, 0);
|
|
277
317
|
this._physicsRotation = 0.0;
|
|
318
|
+
this._hasKinematicPositionTarget = false;
|
|
319
|
+
this._hasKinematicRotationTarget = false;
|
|
278
320
|
}
|
|
279
321
|
_setPhysicsPosition(position) {
|
|
280
322
|
this._physicsPosition.copyFrom(position);
|
|
@@ -355,19 +397,19 @@ __decorate([
|
|
|
355
397
|
idem
|
|
356
398
|
], RigidBody2D.prototype, "linearVelocity", null);
|
|
357
399
|
__decorate([
|
|
358
|
-
|
|
400
|
+
stored
|
|
359
401
|
], RigidBody2D.prototype, "_tags", void 0);
|
|
360
402
|
__decorate([
|
|
361
|
-
|
|
403
|
+
stored
|
|
362
404
|
], RigidBody2D.prototype, "_type", void 0);
|
|
363
405
|
__decorate([
|
|
364
|
-
|
|
406
|
+
stored
|
|
365
407
|
], RigidBody2D.prototype, "_ccd", void 0);
|
|
366
408
|
__decorate([
|
|
367
|
-
|
|
409
|
+
stored
|
|
368
410
|
], RigidBody2D.prototype, "_gravityScale", void 0);
|
|
369
411
|
__decorate([
|
|
370
|
-
|
|
412
|
+
stored
|
|
371
413
|
], RigidBody2D.prototype, "_collisionTargetTypeFilter", void 0);
|
|
372
414
|
__decorate([
|
|
373
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) {
|