@zylem/behaviors 0.2.0 → 0.3.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/dist/{chunk-3PYGRHAL.js → chunk-23HQH3GJ.js} +1 -2
- package/dist/{chunk-EIWQM6U3.js → chunk-2HKY6WF7.js} +0 -1
- package/dist/{chunk-KS72RZHX.js → chunk-2HLZBWGD.js} +0 -1
- package/dist/{chunk-HZMY3TT4.js → chunk-4DVDFCVY.js} +0 -1
- package/dist/{chunk-LD5SMIB3.js → chunk-4EWASZHB.js} +0 -1
- package/dist/{chunk-4I6E6DGV.js → chunk-6UMC6BB5.js} +4 -5
- package/dist/{chunk-ARJWUNRE.js → chunk-6Y3GB76J.js} +3 -4
- package/dist/{chunk-FPTWVCPN.js → chunk-7IZ36Y5G.js} +2 -3
- package/dist/{chunk-ID5QJYF5.js → chunk-7U4WFBWM.js} +0 -1
- package/dist/{chunk-GCNRXAKH.js → chunk-7Y6JVZ5H.js} +1 -2
- package/dist/{chunk-2CLT36VB.js → chunk-BC3IJYS7.js} +4 -5
- package/dist/{chunk-XIJNE67Y.js → chunk-D53GNZXP.js} +3 -4
- package/dist/{chunk-XG2YMCJW.js → chunk-E4HTCQPK.js} +4 -5
- package/dist/{chunk-WOMHL23C.js → chunk-ERS6SNA5.js} +1 -2
- package/dist/{chunk-BXP4K7RF.js → chunk-F6LFX4V3.js} +2 -3
- package/dist/{chunk-DYLH6K7B.js → chunk-F7E23E26.js} +0 -1
- package/dist/{chunk-RTRVBEIB.js → chunk-FHDYJ5WP.js} +2 -3
- package/dist/{chunk-F3KRX2V4.js → chunk-FOOM42MK.js} +5 -6
- package/dist/{chunk-OYWFPIHF.js → chunk-HIBJDA5Z.js} +4 -5
- package/dist/{chunk-6C6NXNEW.js → chunk-IEA7F73P.js} +1 -2
- package/dist/{chunk-SS7ELMJ7.js → chunk-IQRG5BAZ.js} +4 -5
- package/dist/{chunk-K3UNLQ7W.js → chunk-J5XLB24H.js} +1 -2
- package/dist/{chunk-2C3Z5GE7.js → chunk-K4UBXSZL.js} +1 -2
- package/dist/{chunk-UYFOLI2X.js → chunk-K6CWKFHL.js} +0 -1
- package/dist/{chunk-STCCNLPC.js → chunk-L76JG73P.js} +3 -4
- package/dist/{chunk-KOZUNIIE.js → chunk-RD2YTTXY.js} +3 -4
- package/dist/{chunk-4URF65BR.js → chunk-RER2IDPW.js} +0 -1
- package/dist/{chunk-WWVD5DR5.js → chunk-RHW3IDQX.js} +0 -1
- package/dist/{chunk-RTVRUNYR.js → chunk-RQWWUML4.js} +0 -1
- package/dist/{chunk-YUO6SKJD.js → chunk-SBACY5SU.js} +5 -6
- package/dist/{chunk-JAN34G6S.js → chunk-T2P4JTQN.js} +2 -3
- package/dist/{chunk-SVLNF434.js → chunk-UFHYR2LV.js} +0 -1
- package/dist/{chunk-VAN4WW3F.js → chunk-VO5J64DG.js} +2 -3
- package/dist/{chunk-POZER3MQ.js → chunk-VPZ32CCD.js} +101 -96
- package/dist/{chunk-OHCPV2NT.js → chunk-WHKPWIQO.js} +0 -1
- package/dist/chunk-WSKD7GY3.js +2630 -0
- package/dist/{chunk-EZNCCO4L.js → chunk-YDLO5M7S.js} +0 -1
- package/dist/{chunk-Y6UJOUE5.js → chunk-YYJP62QD.js} +0 -1
- package/dist/{chunk-KDY5N6J4.js → chunk-ZHBD65AZ.js} +0 -1
- package/dist/cooldown.js +2 -3
- package/dist/coordinators/boundary-ricochet-3d.js +2 -3
- package/dist/coordinators/boundary-ricochet.js +2 -3
- package/dist/coordinators/first-person-shooter.js +3 -4
- package/dist/coordinators/multidirectional-space-shooter.js +4 -5
- package/dist/coordinators/top-down-shooter.js +4 -5
- package/dist/core.js +6 -7
- package/dist/destructible-3d.js +3 -4
- package/dist/destructible-prebake.js +1 -2
- package/dist/first-person.js +6 -7
- package/dist/index.d.ts +2 -2
- package/dist/index.js +38 -39
- package/dist/jumper-2d.js +5 -6
- package/dist/jumper-3d.js +6 -7
- package/dist/particle-emitter/presets.d.ts +2 -2
- package/dist/particle-emitter/presets.js +1 -2
- package/dist/particle-emitter.d.ts +9 -4
- package/dist/particle-emitter.js +4 -5
- package/dist/platformer-3d.js +3 -4
- package/dist/ricochet-2d.js +4 -5
- package/dist/ricochet-3d.js +4 -5
- package/dist/runtime-2d.js +2 -3
- package/dist/runtime-pong.js +2 -3
- package/dist/screen-visibility.js +2 -3
- package/dist/screen-wrap.js +4 -5
- package/dist/shooter-2d.js +4 -5
- package/dist/spark-Dx3cJbTW.d.ts +356 -0
- package/dist/thruster.js +5 -6
- package/dist/top-down-movement.js +5 -6
- package/dist/world-boundary-2d.js +5 -6
- package/dist/world-boundary-3d.js +5 -6
- package/package.json +158 -159
- package/dist/chunk-2C3Z5GE7.js.map +0 -1
- package/dist/chunk-2CLT36VB.js.map +0 -1
- package/dist/chunk-3PYGRHAL.js.map +0 -1
- package/dist/chunk-4I6E6DGV.js.map +0 -1
- package/dist/chunk-4URF65BR.js.map +0 -1
- package/dist/chunk-6C6NXNEW.js.map +0 -1
- package/dist/chunk-ARJWUNRE.js.map +0 -1
- package/dist/chunk-BXP4K7RF.js.map +0 -1
- package/dist/chunk-DYLH6K7B.js.map +0 -1
- package/dist/chunk-EIWQM6U3.js.map +0 -1
- package/dist/chunk-EZNCCO4L.js.map +0 -1
- package/dist/chunk-F3KRX2V4.js.map +0 -1
- package/dist/chunk-FPTWVCPN.js.map +0 -1
- package/dist/chunk-GCNRXAKH.js.map +0 -1
- package/dist/chunk-GYURWCIQ.js +0 -1985
- package/dist/chunk-GYURWCIQ.js.map +0 -1
- package/dist/chunk-HZMY3TT4.js.map +0 -1
- package/dist/chunk-ID5QJYF5.js.map +0 -1
- package/dist/chunk-JAN34G6S.js.map +0 -1
- package/dist/chunk-K3UNLQ7W.js.map +0 -1
- package/dist/chunk-KDY5N6J4.js.map +0 -1
- package/dist/chunk-KOZUNIIE.js.map +0 -1
- package/dist/chunk-KS72RZHX.js.map +0 -1
- package/dist/chunk-LD5SMIB3.js.map +0 -1
- package/dist/chunk-OHCPV2NT.js.map +0 -1
- package/dist/chunk-OYWFPIHF.js.map +0 -1
- package/dist/chunk-POZER3MQ.js.map +0 -1
- package/dist/chunk-RTRVBEIB.js.map +0 -1
- package/dist/chunk-RTVRUNYR.js.map +0 -1
- package/dist/chunk-SS7ELMJ7.js.map +0 -1
- package/dist/chunk-STCCNLPC.js.map +0 -1
- package/dist/chunk-SVLNF434.js.map +0 -1
- package/dist/chunk-UYFOLI2X.js.map +0 -1
- package/dist/chunk-VAN4WW3F.js.map +0 -1
- package/dist/chunk-WOMHL23C.js.map +0 -1
- package/dist/chunk-WWVD5DR5.js.map +0 -1
- package/dist/chunk-XG2YMCJW.js.map +0 -1
- package/dist/chunk-XIJNE67Y.js.map +0 -1
- package/dist/chunk-Y6UJOUE5.js.map +0 -1
- package/dist/chunk-YUO6SKJD.js.map +0 -1
- package/dist/cooldown.js.map +0 -1
- package/dist/coordinators/boundary-ricochet-3d.js.map +0 -1
- package/dist/coordinators/boundary-ricochet.js.map +0 -1
- package/dist/coordinators/first-person-shooter.js.map +0 -1
- package/dist/coordinators/multidirectional-space-shooter.js.map +0 -1
- package/dist/coordinators/top-down-shooter.js.map +0 -1
- package/dist/core.js.map +0 -1
- package/dist/destructible-3d.js.map +0 -1
- package/dist/destructible-prebake.js.map +0 -1
- package/dist/first-person.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/jumper-2d.js.map +0 -1
- package/dist/jumper-3d.js.map +0 -1
- package/dist/particle-emitter/presets.js.map +0 -1
- package/dist/particle-emitter.js.map +0 -1
- package/dist/platformer-3d.js.map +0 -1
- package/dist/ricochet-2d.js.map +0 -1
- package/dist/ricochet-3d.js.map +0 -1
- package/dist/runtime-2d.js.map +0 -1
- package/dist/runtime-pong.js.map +0 -1
- package/dist/screen-visibility.js.map +0 -1
- package/dist/screen-wrap.js.map +0 -1
- package/dist/shooter-2d.js.map +0 -1
- package/dist/spark-DDlIg1nM.d.ts +0 -148
- package/dist/thruster.js.map +0 -1
- package/dist/top-down-movement.js.map +0 -1
- package/dist/world-boundary-2d.js.map +0 -1
- package/dist/world-boundary-3d.js.map +0 -1
|
@@ -1,29 +1,23 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
createRangeValue,
|
|
4
|
-
createTextureSystemOptions,
|
|
2
|
+
Particles,
|
|
5
3
|
electricityPresets,
|
|
6
4
|
firePresets,
|
|
7
5
|
gasPresets,
|
|
8
6
|
magicPresets,
|
|
9
7
|
particleEffect,
|
|
10
|
-
toColorVector,
|
|
11
8
|
waterPresets
|
|
12
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-WSKD7GY3.js";
|
|
13
10
|
import {
|
|
14
11
|
VEC3_ZERO,
|
|
15
12
|
normalizeVec3,
|
|
16
13
|
toThreeVector3
|
|
17
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-RHW3IDQX.js";
|
|
18
15
|
import {
|
|
19
16
|
defineBehavior
|
|
20
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-YDLO5M7S.js";
|
|
21
18
|
|
|
22
19
|
// src/lib/behaviors/particle-emitter/particle-emitter.descriptor.ts
|
|
23
20
|
import { Group, Quaternion, Vector3 } from "three";
|
|
24
|
-
import {
|
|
25
|
-
BatchedRenderer
|
|
26
|
-
} from "three.quarks";
|
|
27
21
|
function getRefGlobals(ref) {
|
|
28
22
|
return ref.__getGlobals ?? null;
|
|
29
23
|
}
|
|
@@ -48,28 +42,26 @@ var defaultOptions = {
|
|
|
48
42
|
var ParticleRendererService = class {
|
|
49
43
|
constructor(sceneRoot) {
|
|
50
44
|
this.sceneRoot = sceneRoot;
|
|
51
|
-
this.renderer.name = "zylem-particle-batch-renderer";
|
|
52
|
-
this.sceneRoot.add(this.renderer);
|
|
53
45
|
}
|
|
54
46
|
sceneRoot;
|
|
55
|
-
renderer = new BatchedRenderer();
|
|
56
47
|
systems = /* @__PURE__ */ new Set();
|
|
48
|
+
/** Scene node that emitter anchors are parented to. */
|
|
49
|
+
get root() {
|
|
50
|
+
return this.sceneRoot;
|
|
51
|
+
}
|
|
57
52
|
register(system) {
|
|
58
|
-
if (this.systems.has(system)) {
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
this.renderer.addSystem(system);
|
|
62
53
|
this.systems.add(system);
|
|
63
54
|
}
|
|
64
55
|
forget(system) {
|
|
65
56
|
this.systems.delete(system);
|
|
66
57
|
}
|
|
67
58
|
update(delta) {
|
|
68
|
-
this.
|
|
59
|
+
for (const system of this.systems) {
|
|
60
|
+
system.update(delta);
|
|
61
|
+
}
|
|
69
62
|
}
|
|
70
63
|
destroy() {
|
|
71
64
|
this.systems.clear();
|
|
72
|
-
this.renderer.removeFromParent();
|
|
73
65
|
}
|
|
74
66
|
};
|
|
75
67
|
function getParticleControlState(ref) {
|
|
@@ -146,7 +138,15 @@ function applyRuntimeState(ref) {
|
|
|
146
138
|
}
|
|
147
139
|
if (state.pendingRestart) {
|
|
148
140
|
runtime.system.restart();
|
|
141
|
+
runtime.started = true;
|
|
149
142
|
state.pendingRestart = false;
|
|
143
|
+
if (state.desiredState === "paused") {
|
|
144
|
+
runtime.system.pause();
|
|
145
|
+
} else if (state.desiredState === "stopped") {
|
|
146
|
+
runtime.system.stop();
|
|
147
|
+
runtime.started = false;
|
|
148
|
+
}
|
|
149
|
+
return;
|
|
150
150
|
}
|
|
151
151
|
if (state.desiredState === "paused") {
|
|
152
152
|
runtime.system.pause();
|
|
@@ -154,9 +154,15 @@ function applyRuntimeState(ref) {
|
|
|
154
154
|
}
|
|
155
155
|
if (state.desiredState === "stopped") {
|
|
156
156
|
runtime.system.stop();
|
|
157
|
+
runtime.started = false;
|
|
157
158
|
return;
|
|
158
159
|
}
|
|
159
|
-
runtime.
|
|
160
|
+
if (!runtime.started) {
|
|
161
|
+
runtime.system.start();
|
|
162
|
+
runtime.started = true;
|
|
163
|
+
} else {
|
|
164
|
+
runtime.system.resume();
|
|
165
|
+
}
|
|
160
166
|
}
|
|
161
167
|
function releaseRuntime(ref, reason) {
|
|
162
168
|
const state = getParticleControlState(ref);
|
|
@@ -166,7 +172,6 @@ function releaseRuntime(ref, reason) {
|
|
|
166
172
|
}
|
|
167
173
|
state.runtime = null;
|
|
168
174
|
state.pendingRestart = false;
|
|
169
|
-
runtime.system.removeEventListener("destroy", runtime.onDestroy);
|
|
170
175
|
runtime.service.forget(runtime.system);
|
|
171
176
|
if (reason === "manual") {
|
|
172
177
|
runtime.system.dispose();
|
|
@@ -191,14 +196,12 @@ function createRuntime(entity, ref, service) {
|
|
|
191
196
|
service,
|
|
192
197
|
initialPosition: initialTransform.position.clone(),
|
|
193
198
|
initialQuaternion: initialTransform.quaternion.clone(),
|
|
194
|
-
|
|
199
|
+
started: false
|
|
195
200
|
};
|
|
196
201
|
anchor.name = `${entity.name || entity.uuid}:particle-anchor`;
|
|
197
|
-
system
|
|
198
|
-
anchor.add(system.emitter);
|
|
202
|
+
anchor.add(system);
|
|
199
203
|
service.register(system);
|
|
200
|
-
service.
|
|
201
|
-
system.addEventListener("destroy", runtime.onDestroy);
|
|
204
|
+
service.root.add(anchor);
|
|
202
205
|
syncRuntimeTransform(entity, ref, runtime);
|
|
203
206
|
return runtime;
|
|
204
207
|
}
|
|
@@ -237,7 +240,7 @@ function createParticleEmitterHandle(ref) {
|
|
|
237
240
|
if (!runtime) {
|
|
238
241
|
return getParticleControlState(ref).desiredState === "playing";
|
|
239
242
|
}
|
|
240
|
-
return
|
|
243
|
+
return runtime.system.running;
|
|
241
244
|
},
|
|
242
245
|
getSystem: () => getParticleControlState(ref).runtime?.system ?? null
|
|
243
246
|
};
|
|
@@ -287,6 +290,9 @@ var ParticleEmitterBehaviorSystem = class {
|
|
|
287
290
|
hasRuntime = true;
|
|
288
291
|
syncRuntimeTransform(entity, ref, state.runtime);
|
|
289
292
|
applyRuntimeState(ref);
|
|
293
|
+
if (ref.options.autoDestroy && state.runtime.started && state.desiredState === "playing" && state.runtime.system.isComplete()) {
|
|
294
|
+
handleSystemDestroyed(entity, ref);
|
|
295
|
+
}
|
|
290
296
|
}
|
|
291
297
|
if (hasRuntime && rendererService) {
|
|
292
298
|
rendererService.update(delta);
|
|
@@ -320,78 +326,78 @@ var ParticleEmitterBehavior = defineBehavior({
|
|
|
320
326
|
});
|
|
321
327
|
|
|
322
328
|
// src/lib/behaviors/particle-emitter/particle-effect.ts
|
|
323
|
-
import {
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
329
|
+
import { AdditiveBlending, Color } from "three";
|
|
330
|
+
function toRange(value, fallback) {
|
|
331
|
+
if (value === void 0) return fallback;
|
|
332
|
+
if (Array.isArray(value)) {
|
|
333
|
+
return [value[0] ?? fallback[0], value[1] ?? fallback[1]];
|
|
334
|
+
}
|
|
335
|
+
const single = value;
|
|
336
|
+
return [single, single];
|
|
337
|
+
}
|
|
338
|
+
function toHexColor(color) {
|
|
339
|
+
return `#${new Color(color).getHexString()}`;
|
|
340
|
+
}
|
|
341
|
+
function makeBurstConfig(options, defaults) {
|
|
342
|
+
const count = Math.max(1, Math.round(options.count ?? defaults.count));
|
|
343
|
+
const color = toHexColor(options.color ?? defaults.color);
|
|
344
|
+
const blending = options.blending ?? AdditiveBlending;
|
|
345
|
+
const particles = {
|
|
346
|
+
count,
|
|
347
|
+
intensity: options.opacity ?? defaults.intensity,
|
|
348
|
+
colors: [
|
|
349
|
+
[
|
|
350
|
+
{ color, stop: 0 },
|
|
351
|
+
{ color, stop: 1 }
|
|
352
|
+
]
|
|
353
|
+
],
|
|
354
|
+
fadeAlpha: [0.05, 0.7],
|
|
355
|
+
fadeSize: [0.1, 0.85]
|
|
356
|
+
};
|
|
357
|
+
if (options.texture) {
|
|
358
|
+
particles.alphaMapsStart = [options.texture];
|
|
359
|
+
}
|
|
360
|
+
return {
|
|
361
|
+
particles,
|
|
362
|
+
emitter: {
|
|
363
|
+
duration: options.duration ?? defaults.duration,
|
|
364
|
+
loop: false,
|
|
365
|
+
spawnMode: "burst",
|
|
366
|
+
rate: count,
|
|
367
|
+
static: 0,
|
|
368
|
+
lifetime: toRange(options.life, defaults.life),
|
|
369
|
+
speed: toRange(options.speed, defaults.speed),
|
|
370
|
+
size: toRange(options.size, defaults.size),
|
|
371
|
+
directionMin: [-1, -1, -1],
|
|
372
|
+
directionMax: [1, 1, 1]
|
|
373
|
+
},
|
|
374
|
+
render: { blendingMode: blending }
|
|
375
|
+
};
|
|
376
|
+
}
|
|
330
377
|
var particlePresets = {
|
|
331
378
|
burst(options = {}) {
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
),
|
|
343
|
-
emissionOverTime: new ConstantValue(0),
|
|
344
|
-
emissionBursts: [
|
|
345
|
-
{
|
|
346
|
-
time: 0,
|
|
347
|
-
count: new ConstantValue(options.count ?? 18),
|
|
348
|
-
cycle: 1,
|
|
349
|
-
interval: 0,
|
|
350
|
-
probability: 1
|
|
351
|
-
}
|
|
352
|
-
],
|
|
353
|
-
shape: new PointEmitter(),
|
|
354
|
-
material: createParticleMaterial(
|
|
355
|
-
options.color ?? "#ffffff",
|
|
356
|
-
options
|
|
357
|
-
),
|
|
358
|
-
...createTextureSystemOptions(options),
|
|
359
|
-
renderMode: RenderMode.BillBoard
|
|
360
|
-
})
|
|
361
|
-
);
|
|
379
|
+
const config = makeBurstConfig(options, {
|
|
380
|
+
duration: 0.25,
|
|
381
|
+
life: [0.3, 0.7],
|
|
382
|
+
speed: [1.5, 4],
|
|
383
|
+
size: [0.08, 0.18],
|
|
384
|
+
color: "#ffffff",
|
|
385
|
+
count: 18,
|
|
386
|
+
intensity: 1
|
|
387
|
+
});
|
|
388
|
+
return particleEffect(() => new Particles(config));
|
|
362
389
|
},
|
|
363
390
|
smoke(options = {}) {
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
),
|
|
375
|
-
emissionOverTime: new ConstantValue(0),
|
|
376
|
-
emissionBursts: [
|
|
377
|
-
{
|
|
378
|
-
time: 0,
|
|
379
|
-
count: new ConstantValue(options.count ?? 10),
|
|
380
|
-
cycle: 1,
|
|
381
|
-
interval: 0,
|
|
382
|
-
probability: 1
|
|
383
|
-
}
|
|
384
|
-
],
|
|
385
|
-
shape: new PointEmitter(),
|
|
386
|
-
material: createParticleMaterial(
|
|
387
|
-
options.color ?? "#999999",
|
|
388
|
-
options,
|
|
389
|
-
0.85
|
|
390
|
-
),
|
|
391
|
-
...createTextureSystemOptions(options),
|
|
392
|
-
renderMode: RenderMode.BillBoard
|
|
393
|
-
})
|
|
394
|
-
);
|
|
391
|
+
const config = makeBurstConfig(options, {
|
|
392
|
+
duration: 1.1,
|
|
393
|
+
life: [0.8, 1.6],
|
|
394
|
+
speed: [0.2, 0.8],
|
|
395
|
+
size: [0.2, 0.5],
|
|
396
|
+
color: "#999999",
|
|
397
|
+
count: 10,
|
|
398
|
+
intensity: 0.85
|
|
399
|
+
});
|
|
400
|
+
return particleEffect(() => new Particles(config));
|
|
395
401
|
},
|
|
396
402
|
fire: firePresets,
|
|
397
403
|
water: waterPresets,
|
|
@@ -404,4 +410,3 @@ export {
|
|
|
404
410
|
ParticleEmitterBehavior,
|
|
405
411
|
particlePresets
|
|
406
412
|
};
|
|
407
|
-
//# sourceMappingURL=chunk-POZER3MQ.js.map
|