@eva/plugin-renderer-particle 2.1.0-beta.1 → 2.1.0-beta.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eva/plugin-renderer-particle",
3
- "version": "2.1.0-beta.1",
3
+ "version": "2.1.0-beta.3",
4
4
  "description": "@eva/plugin-renderer-particle",
5
5
  "main": "index.js",
6
6
  "module": "dist/plugin-renderer-particle.esm.js",
@@ -20,8 +20,8 @@
20
20
  "homepage": "https://eva.js.org",
21
21
  "dependencies": {
22
22
  "@eva/inspector-decorator": "^2.0.0-beta.0",
23
- "@eva/eva.js": "2.1.0-beta.1",
24
- "@eva/plugin-renderer": "2.1.0-beta.1",
23
+ "@eva/eva.js": "2.1.0-beta.3",
24
+ "@eva/plugin-renderer": "2.1.0-beta.3",
25
25
  "pixi.js": "^8.6.3"
26
26
  }
27
27
  }
@@ -1,664 +0,0 @@
1
- function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
2
- globalThis.EVA = globalThis.EVA || {};
3
- globalThis.EVA.plugin = globalThis.EVA.plugin || {};
4
- globalThis.EVA.plugin.renderer = globalThis.EVA.plugin.renderer || {};
5
- var _EVA_IIFE_particle = function (exports, eva_js, pluginRenderer, pixi_js) {
6
- 'use strict';
7
- function __decorate(decorators, target, key, desc) {
8
- var c = arguments.length,
9
- r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
10
- d;
11
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);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;
12
- return c > 3 && r && Object.defineProperty(target, key, r), r;
13
- }
14
- function __metadata(metadataKey, metadataValue) {
15
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
16
- }
17
- function __awaiter(thisArg, _arguments, P, generator) {
18
- function adopt(value) {
19
- return value instanceof P ? value : new P(function (resolve) {
20
- resolve(value);
21
- });
22
- }
23
- return new (P || (P = Promise))(function (resolve, reject) {
24
- function fulfilled(value) {
25
- try {
26
- step(generator.next(value));
27
- } catch (e) {
28
- reject(e);
29
- }
30
- }
31
- function rejected(value) {
32
- try {
33
- step(generator["throw"](value));
34
- } catch (e) {
35
- reject(e);
36
- }
37
- }
38
- function step(result) {
39
- result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
40
- }
41
- step((generator = generator.apply(thisArg, _arguments || [])).next());
42
- });
43
- }
44
- function __rest(s, e) {
45
- var t = {};
46
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
47
- if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
48
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
49
- }
50
- return t;
51
- }
52
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
53
- var e = new Error(message);
54
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
55
- };
56
- class SymbolKeysNotSupportedError extends Error {
57
- constructor() {
58
- super('Symbol keys are not supported yet!');
59
- Object.setPrototypeOf(this, new.target.prototype);
60
- }
61
- }
62
- const IDE_PROPERTY_METADATA = 'IDE_PROPERTY_METADATA';
63
- function transformBasicType(type) {
64
- if (type === String) {
65
- return 'string';
66
- }
67
- if (type === Number) {
68
- return 'number';
69
- }
70
- if (type === Boolean) {
71
- return 'boolean';
72
- }
73
- return 'unknown';
74
- }
75
- function defineLegacyIDEProp(target, propertyKey, patch) {
76
- const constructor = target.constructor;
77
- const current = constructor.IDEProps || {};
78
- current[propertyKey] = _extends(_extends({
79
- key: propertyKey
80
- }, current[propertyKey]), patch);
81
- constructor.IDEProps = current;
82
- }
83
- function defineTypes(target, key, options, returnTypeFunction) {
84
- let type = Reflect.getMetadata('design:type', target, key);
85
- let isArray = type === Array;
86
- const str = transformBasicType(type);
87
- if (str !== 'unknown') {
88
- type = str;
89
- }
90
- if (returnTypeFunction) {
91
- const returnType = returnTypeFunction();
92
- if (Array.isArray(returnType)) {
93
- isArray = true;
94
- type = returnType[0];
95
- } else {
96
- type = returnType;
97
- }
98
- }
99
- const properties = Reflect.getMetadata(IDE_PROPERTY_METADATA, target.constructor) || {};
100
- const current = properties[key] || {};
101
- const property = _extends(_extends(_extends({}, current), {
102
- type,
103
- isArray: isArray
104
- }), options);
105
- properties[key] = property;
106
- Reflect.defineMetadata(IDE_PROPERTY_METADATA, properties, target.constructor);
107
- const legacyProperty = __rest(property, ["isArray"]);
108
- defineLegacyIDEProp(target, key, legacyProperty);
109
- }
110
- function type(type) {
111
- return Field({
112
- type
113
- });
114
- }
115
- function getTypeDecoratorParams(returnTypeFuncOrOptions, maybeOptions) {
116
- if (typeof returnTypeFuncOrOptions === 'function') {
117
- return {
118
- returnTypeFunc: returnTypeFuncOrOptions,
119
- options: maybeOptions || {}
120
- };
121
- }
122
- return {
123
- options: returnTypeFuncOrOptions || {}
124
- };
125
- }
126
- function Field(returnTypeFunction, maybeOptions) {
127
- return (target, propertyKey) => {
128
- if (typeof propertyKey === 'symbol') {
129
- throw new SymbolKeysNotSupportedError();
130
- }
131
- const {
132
- options,
133
- returnTypeFunc
134
- } = getTypeDecoratorParams(returnTypeFunction, maybeOptions);
135
- defineTypes(target, propertyKey, options, returnTypeFunc);
136
- };
137
- }
138
- var ExecuteMode;
139
- (function (ExecuteMode) {
140
- ExecuteMode[ExecuteMode["Edit"] = 2] = "Edit";
141
- ExecuteMode[ExecuteMode["Game"] = 4] = "Game";
142
- ExecuteMode[ExecuteMode["All"] = 6] = "All";
143
- })(ExecuteMode || (ExecuteMode = {}));
144
- class ParticleEmitter extends eva_js.Component {
145
- constructor() {
146
- super(...arguments);
147
- this.resource = '';
148
- this.auto = true;
149
- this.duration = -1;
150
- this.frequency = 250;
151
- this.quantity = 1;
152
- this.maxParticles = 500;
153
- this.lifespan = 1000;
154
- this.gravityX = 0;
155
- this.gravityY = 0;
156
- this.paused = false;
157
- }
158
- init(obj) {
159
- if (obj) _extends(this, obj);
160
- }
161
- stop() {
162
- this.paused = true;
163
- }
164
- start() {
165
- this.paused = false;
166
- }
167
- }
168
- ParticleEmitter.componentName = 'ParticleEmitter';
169
- __decorate([type('string'), __metadata("design:type", String)], ParticleEmitter.prototype, "resource", void 0);
170
- __decorate([type('boolean'), __metadata("design:type", Boolean)], ParticleEmitter.prototype, "auto", void 0);
171
- __decorate([type('number'), __metadata("design:type", Number)], ParticleEmitter.prototype, "duration", void 0);
172
- __decorate([type('number'), __metadata("design:type", Number)], ParticleEmitter.prototype, "frequency", void 0);
173
- __decorate([type('number'), __metadata("design:type", Number)], ParticleEmitter.prototype, "quantity", void 0);
174
- __decorate([type('number'), __metadata("design:type", Number)], ParticleEmitter.prototype, "maxParticles", void 0);
175
- __decorate([type('number'), __metadata("design:type", Number)], ParticleEmitter.prototype, "gravityX", void 0);
176
- __decorate([type('number'), __metadata("design:type", Number)], ParticleEmitter.prototype, "gravityY", void 0);
177
- const TAU = Math.PI * 2;
178
- const easings = {
179
- linear: t => t,
180
- 'sine.in': t => 1 - Math.cos(t * Math.PI / 2),
181
- 'sine.out': t => Math.sin(t * Math.PI / 2),
182
- 'sine.inout': t => -(Math.cos(Math.PI * t) - 1) / 2,
183
- 'quad.in': t => t * t,
184
- 'quad.out': t => 1 - (1 - t) * (1 - t),
185
- 'quad.inout': t => t < 0.5 ? 2 * t * t : 1 - Math.pow(-2 * t + 2, 2) / 2,
186
- 'cubic.in': t => t * t * t,
187
- 'cubic.out': t => 1 - Math.pow(1 - t, 3),
188
- 'expo.out': t => t === 1 ? 1 : 1 - Math.pow(2, -10 * t)
189
- };
190
- function resolveEase(name) {
191
- if (!name) return easings.linear;
192
- const k = name.toLowerCase();
193
- return easings[k] || easings.linear;
194
- }
195
- function rand(min, max) {
196
- return min + Math.random() * (max - min);
197
- }
198
- function sampleRange(value, fallback = 0) {
199
- if (value == null) return fallback;
200
- if (typeof value === 'number') return value;
201
- if (Array.isArray(value)) return value[Math.floor(Math.random() * value.length)];
202
- if ('min' in value && 'max' in value) return rand(value.min, value.max);
203
- if ('start' in value && 'end' in value) return value.start;
204
- return fallback;
205
- }
206
- function getRangeBounds(value) {
207
- if (value == null || typeof value === 'number' || Array.isArray(value)) return null;
208
- if ('start' in value && 'end' in value) return value;
209
- return null;
210
- }
211
- function samplePosition(zone) {
212
- if (!zone) return {
213
- x: 0,
214
- y: 0
215
- };
216
- return sampleShape(zone.shape, zone.type === 'edge');
217
- }
218
- function sampleShape(shape, edgeOnly) {
219
- var _a, _b, _c, _d, _e, _f, _g, _h;
220
- switch (shape.type) {
221
- case 'point':
222
- return {
223
- x: (_a = shape.x) !== null && _a !== void 0 ? _a : 0,
224
- y: (_b = shape.y) !== null && _b !== void 0 ? _b : 0
225
- };
226
- case 'rect':
227
- {
228
- const x0 = (_c = shape.x) !== null && _c !== void 0 ? _c : 0;
229
- const y0 = (_d = shape.y) !== null && _d !== void 0 ? _d : 0;
230
- if (edgeOnly) {
231
- const perim = 2 * (shape.width + shape.height);
232
- const t = Math.random() * perim;
233
- if (t < shape.width) return {
234
- x: x0 + t,
235
- y: y0
236
- };
237
- if (t < shape.width + shape.height) return {
238
- x: x0 + shape.width,
239
- y: y0 + (t - shape.width)
240
- };
241
- if (t < 2 * shape.width + shape.height) return {
242
- x: x0 + shape.width - (t - shape.width - shape.height),
243
- y: y0 + shape.height
244
- };
245
- return {
246
- x: x0,
247
- y: y0 + shape.height - (t - 2 * shape.width - shape.height)
248
- };
249
- }
250
- return {
251
- x: rand(x0, x0 + shape.width),
252
- y: rand(y0, y0 + shape.height)
253
- };
254
- }
255
- case 'circle':
256
- {
257
- const cx = (_e = shape.x) !== null && _e !== void 0 ? _e : 0;
258
- const cy = (_f = shape.y) !== null && _f !== void 0 ? _f : 0;
259
- const angle = Math.random() * TAU;
260
- const r = edgeOnly ? shape.radius : shape.radius * Math.sqrt(Math.random());
261
- return {
262
- x: cx + Math.cos(angle) * r,
263
- y: cy + Math.sin(angle) * r
264
- };
265
- }
266
- case 'ellipse':
267
- {
268
- const cx = (_g = shape.x) !== null && _g !== void 0 ? _g : 0;
269
- const cy = (_h = shape.y) !== null && _h !== void 0 ? _h : 0;
270
- const angle = Math.random() * TAU;
271
- const k = edgeOnly ? 1 : Math.sqrt(Math.random());
272
- return {
273
- x: cx + Math.cos(angle) * shape.rx * k,
274
- y: cy + Math.sin(angle) * shape.ry * k
275
- };
276
- }
277
- case 'line':
278
- {
279
- const t = Math.random();
280
- return {
281
- x: shape.x1 + (shape.x2 - shape.x1) * t,
282
- y: shape.y1 + (shape.y2 - shape.y1) * t
283
- };
284
- }
285
- }
286
- }
287
- function pointInShape(shape, px, py) {
288
- var _a, _b, _c, _d, _e, _f;
289
- switch (shape.type) {
290
- case 'rect':
291
- {
292
- const x0 = (_a = shape.x) !== null && _a !== void 0 ? _a : 0;
293
- const y0 = (_b = shape.y) !== null && _b !== void 0 ? _b : 0;
294
- return px >= x0 && px <= x0 + shape.width && py >= y0 && py <= y0 + shape.height;
295
- }
296
- case 'circle':
297
- {
298
- const dx = px - ((_c = shape.x) !== null && _c !== void 0 ? _c : 0);
299
- const dy = py - ((_d = shape.y) !== null && _d !== void 0 ? _d : 0);
300
- return dx * dx + dy * dy <= shape.radius * shape.radius;
301
- }
302
- case 'ellipse':
303
- {
304
- const dx = (px - ((_e = shape.x) !== null && _e !== void 0 ? _e : 0)) / shape.rx;
305
- const dy = (py - ((_f = shape.y) !== null && _f !== void 0 ? _f : 0)) / shape.ry;
306
- return dx * dx + dy * dy <= 1;
307
- }
308
- case 'point':
309
- case 'line':
310
- return false;
311
- }
312
- }
313
- class Emitter {
314
- constructor(params, container, texture) {
315
- this.frameTextures = null;
316
- this.particles = [];
317
- this.elapsed = 0;
318
- this.emittedTotal = 0;
319
- this.emitTimer = 0;
320
- this.explodeDone = false;
321
- this.params = params;
322
- this.container = container;
323
- this.texture = texture;
324
- }
325
- setTexture(texture) {
326
- this.texture = texture;
327
- }
328
- setFrameTextures(textures) {
329
- this.frameTextures = textures && textures.length > 0 ? textures : null;
330
- }
331
- setParams(params) {
332
- this.params = params;
333
- }
334
- destroy() {
335
- this.particles.length = 0;
336
- this.container.particleChildren.length = 0;
337
- this.container.update();
338
- }
339
- update(dt) {
340
- this.elapsed += dt;
341
- this.advanceParticles(dt);
342
- this.spawn(dt);
343
- this.container.update();
344
- }
345
- advanceParticles(dt) {
346
- var _a, _b;
347
- const dtSec = dt / 1000;
348
- const out = [];
349
- for (const lp of this.particles) {
350
- lp.age += dt;
351
- if (lp.age > lp.lifespan) {
352
- continue;
353
- }
354
- lp.vx += lp.ax * dtSec + ((_a = this.params.gravityX) !== null && _a !== void 0 ? _a : 0) * dtSec;
355
- lp.vy += lp.ay * dtSec + ((_b = this.params.gravityY) !== null && _b !== void 0 ? _b : 0) * dtSec;
356
- lp.particle.x += lp.vx * dtSec;
357
- lp.particle.y += lp.vy * dtSec;
358
- lp.particle.rotation += lp.rotateSpeed * dtSec;
359
- const t = lp.age / lp.lifespan;
360
- if (lp.scaleStart && lp.scaleEnd) {
361
- const k = (lp.scaleEase || easings.linear)(t);
362
- lp.particle.scaleX = lp.scaleStart.x + (lp.scaleEnd.x - lp.scaleStart.x) * k;
363
- lp.particle.scaleY = lp.scaleStart.y + (lp.scaleEnd.y - lp.scaleStart.y) * k;
364
- }
365
- if (lp.alphaStart != null && lp.alphaEnd != null) {
366
- const k = (lp.alphaEase || easings.linear)(t);
367
- lp.particle.alpha = lp.alphaStart + (lp.alphaEnd - lp.alphaStart) * k;
368
- }
369
- if (this.params.deathZone && this.shouldDie(lp.particle.x, lp.particle.y)) {
370
- continue;
371
- }
372
- out.push(lp);
373
- }
374
- this.particles = out;
375
- this.container.particleChildren.length = 0;
376
- for (const lp of this.particles) this.container.particleChildren.push(lp.particle);
377
- }
378
- shouldDie(x, y) {
379
- const dz = this.params.deathZone;
380
- if (!dz) return false;
381
- const inside = pointInShape(dz.shape, x, y);
382
- return dz.mode === 'onLeave' ? !inside : inside;
383
- }
384
- spawn(dt) {
385
- var _a, _b, _c;
386
- const p = this.params;
387
- if (p.duration != null && p.duration > 0 && this.elapsed > p.duration) return;
388
- if (p.stopAfter != null && this.emittedTotal >= p.stopAfter) return;
389
- if (p.paused) return;
390
- const max = (_a = p.maxParticles) !== null && _a !== void 0 ? _a : 500;
391
- if (this.particles.length >= max) return;
392
- if (p.explode != null && !this.explodeDone) {
393
- const n = Math.min(p.explode, max - this.particles.length);
394
- for (let i = 0; i < n; i++) this.emitOne();
395
- this.explodeDone = true;
396
- return;
397
- }
398
- if (p.explode != null) return;
399
- if (p.auto === false) return;
400
- this.emitTimer += dt;
401
- const freq = (_b = p.frequency) !== null && _b !== void 0 ? _b : 250;
402
- const quantity = (_c = p.quantity) !== null && _c !== void 0 ? _c : 1;
403
- while (this.emitTimer >= freq && this.particles.length < max) {
404
- for (let i = 0; i < quantity && this.particles.length < max; i++) {
405
- if (p.stopAfter != null && this.emittedTotal >= p.stopAfter) break;
406
- this.emitOne();
407
- }
408
- this.emitTimer -= freq;
409
- }
410
- }
411
- emitOne() {
412
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
413
- const p = this.params;
414
- const pos = samplePosition(p.emitZone);
415
- const speedScalar = sampleRange(p.speed, 0);
416
- let vx;
417
- let vy;
418
- if (p.moveTo) {
419
- const dx = p.moveTo.x - pos.x;
420
- const dy = p.moveTo.y - pos.y;
421
- const len = Math.hypot(dx, dy) || 1;
422
- vx = dx / len * (speedScalar || 100);
423
- vy = dy / len * (speedScalar || 100);
424
- } else if (p.speedX != null || p.speedY != null) {
425
- vx = sampleRange(p.speedX, 0);
426
- vy = sampleRange(p.speedY, 0);
427
- } else {
428
- const angleDeg = sampleRange(p.angle, 0);
429
- const angleRad = angleDeg * Math.PI / 180;
430
- vx = Math.cos(angleRad) * speedScalar;
431
- vy = Math.sin(angleRad) * speedScalar;
432
- }
433
- const ax = sampleRange(p.accelerationX, 0);
434
- const ay = sampleRange(p.accelerationY, 0);
435
- const scaleX = p.scaleX != null ? sampleRange(p.scaleX, 1) : sampleRange(p.scale, 1);
436
- const scaleY = p.scaleY != null ? sampleRange(p.scaleY, 1) : sampleRange(p.scale, 1);
437
- const alpha = sampleRange(p.alpha, 1);
438
- const rotation = sampleRange(p.rotate, 0);
439
- const tintNum = Array.isArray(p.tint) ? p.tint[Math.floor(Math.random() * p.tint.length)] : (_a = p.tint) !== null && _a !== void 0 ? _a : 0xffffff;
440
- const tex = this.frameTextures ? this.frameTextures[Math.floor(Math.random() * this.frameTextures.length)] : this.texture;
441
- const particle = new pixi_js.Particle({
442
- texture: tex,
443
- x: pos.x,
444
- y: pos.y,
445
- scaleX,
446
- scaleY,
447
- alpha,
448
- rotation,
449
- tint: tintNum,
450
- anchorX: 0.5,
451
- anchorY: 0.5
452
- });
453
- const lp = {
454
- particle,
455
- age: 0,
456
- lifespan: sampleRange(p.lifespan, 1000),
457
- vx,
458
- vy,
459
- ax,
460
- ay,
461
- rotateSpeed: 0
462
- };
463
- const scaleBounds = getRangeBounds(p.scale);
464
- const scaleXBounds = getRangeBounds(p.scaleX);
465
- const scaleYBounds = getRangeBounds(p.scaleY);
466
- if (scaleBounds || scaleXBounds || scaleYBounds) {
467
- const sxs = (_c = (_b = scaleXBounds === null || scaleXBounds === void 0 ? void 0 : scaleXBounds.start) !== null && _b !== void 0 ? _b : scaleBounds === null || scaleBounds === void 0 ? void 0 : scaleBounds.start) !== null && _c !== void 0 ? _c : scaleX;
468
- const sxe = (_e = (_d = scaleXBounds === null || scaleXBounds === void 0 ? void 0 : scaleXBounds.end) !== null && _d !== void 0 ? _d : scaleBounds === null || scaleBounds === void 0 ? void 0 : scaleBounds.end) !== null && _e !== void 0 ? _e : scaleX;
469
- const sys = (_g = (_f = scaleYBounds === null || scaleYBounds === void 0 ? void 0 : scaleYBounds.start) !== null && _f !== void 0 ? _f : scaleBounds === null || scaleBounds === void 0 ? void 0 : scaleBounds.start) !== null && _g !== void 0 ? _g : scaleY;
470
- const sye = (_j = (_h = scaleYBounds === null || scaleYBounds === void 0 ? void 0 : scaleYBounds.end) !== null && _h !== void 0 ? _h : scaleBounds === null || scaleBounds === void 0 ? void 0 : scaleBounds.end) !== null && _j !== void 0 ? _j : scaleY;
471
- lp.scaleStart = {
472
- x: sxs,
473
- y: sys
474
- };
475
- lp.scaleEnd = {
476
- x: sxe,
477
- y: sye
478
- };
479
- lp.scaleEase = resolveEase((_k = scaleXBounds === null || scaleXBounds === void 0 ? void 0 : scaleXBounds.ease) !== null && _k !== void 0 ? _k : scaleBounds === null || scaleBounds === void 0 ? void 0 : scaleBounds.ease);
480
- particle.scaleX = sxs;
481
- particle.scaleY = sys;
482
- }
483
- const alphaBounds = getRangeBounds(p.alpha);
484
- if (alphaBounds) {
485
- lp.alphaStart = alphaBounds.start;
486
- lp.alphaEnd = alphaBounds.end;
487
- lp.alphaEase = resolveEase(alphaBounds.ease);
488
- particle.alpha = alphaBounds.start;
489
- }
490
- this.particles.push(lp);
491
- this.container.particleChildren.push(particle);
492
- this.emittedTotal++;
493
- }
494
- }
495
- const SPRITE_KEY_SEP = '_s|r|c_';
496
- function isTexture(v) {
497
- return !!v && v.isTexture === true && !!v.orig && !!v.uvs;
498
- }
499
- function pickFrameTextures(instance, resourceName, frame) {
500
- if (isTexture(instance)) {
501
- return {
502
- texture: instance,
503
- frameTextures: null
504
- };
505
- }
506
- if (instance && typeof instance === 'object') {
507
- const lookup = name => {
508
- var _a;
509
- const fullKey = resourceName + SPRITE_KEY_SEP + name;
510
- const v = (_a = instance[fullKey]) !== null && _a !== void 0 ? _a : instance[name];
511
- return isTexture(v) ? v : null;
512
- };
513
- const frameNames = Array.isArray(frame) ? frame : frame ? [frame] : [];
514
- const frameTextures = [];
515
- for (const f of frameNames) {
516
- const t = lookup(f);
517
- if (t) frameTextures.push(t);
518
- }
519
- if (frameTextures.length > 0) {
520
- return {
521
- texture: frameTextures[0],
522
- frameTextures
523
- };
524
- }
525
- for (const k in instance) {
526
- const v = instance[k];
527
- if (isTexture(v)) return {
528
- texture: v,
529
- frameTextures: null
530
- };
531
- }
532
- }
533
- return {
534
- texture: null,
535
- frameTextures: null
536
- };
537
- }
538
- let ParticleEmitterSystem = class ParticleEmitterSystem extends pluginRenderer.Renderer {
539
- constructor() {
540
- super(...arguments);
541
- this.name = 'ParticleEmitter';
542
- this.records = {};
543
- this.lastDeltaTime = 1000 / 60;
544
- }
545
- init() {
546
- this.renderSystem = this.game.getSystem(pluginRenderer.RendererSystem);
547
- this.renderSystem.rendererManager.register(this);
548
- }
549
- update(e) {
550
- if (e === null || e === void 0 ? void 0 : e.deltaTime) this.lastDeltaTime = e.deltaTime;
551
- super.update(e);
552
- }
553
- rendererUpdate(gameObject) {
554
- const record = this.records[gameObject.id];
555
- if (!record) return;
556
- record.emitter.setParams(record.component);
557
- record.emitter.update(this.lastDeltaTime);
558
- }
559
- componentChanged(changed) {
560
- var _a, _b, _c, _d;
561
- return __awaiter(this, void 0, void 0, function* () {
562
- if (changed.componentName !== 'ParticleEmitter') return;
563
- const component = changed.component;
564
- const gameObjectId = changed.gameObject.id;
565
- if (changed.type === eva_js.OBSERVER_TYPE.ADD) {
566
- const asyncId = this.increaseAsyncId(gameObjectId);
567
- let texture = null;
568
- let frameTextures = null;
569
- if (component.resource) {
570
- const {
571
- instance
572
- } = yield eva_js.resource.getResource(component.resource);
573
- if (!this.validateAsyncId(gameObjectId, asyncId)) return;
574
- if (!instance) {
575
- console.error(`GameObject:${changed.gameObject.name}'s ParticleEmitter resource load error`);
576
- return;
577
- }
578
- const picked = pickFrameTextures(instance, component.resource, component.frame);
579
- texture = picked.texture;
580
- frameTextures = picked.frameTextures;
581
- }
582
- if (!texture) return;
583
- const pc = new pixi_js.ParticleContainer({
584
- dynamicProperties: {
585
- position: true,
586
- rotation: true,
587
- scale: true,
588
- color: true,
589
- uvs: true
590
- }
591
- });
592
- pc.texture = texture;
593
- this.containerManager.getContainer(gameObjectId).addChildAt(pc, 0);
594
- const emitter = new Emitter(component, pc, texture);
595
- emitter.setFrameTextures(frameTextures);
596
- this.records[gameObjectId] = {
597
- container: pc,
598
- emitter,
599
- component
600
- };
601
- } else if (changed.type === eva_js.OBSERVER_TYPE.CHANGE) {
602
- const record = this.records[gameObjectId];
603
- if (!record) return;
604
- if (((_b = (_a = changed.prop) === null || _a === void 0 ? void 0 : _a.prop) === null || _b === void 0 ? void 0 : _b[0]) === 'resource') {
605
- const asyncId = this.increaseAsyncId(gameObjectId);
606
- const {
607
- instance
608
- } = yield eva_js.resource.getResource(component.resource);
609
- if (!this.validateAsyncId(gameObjectId, asyncId)) return;
610
- if (instance) {
611
- const picked = pickFrameTextures(instance, component.resource, component.frame);
612
- if (picked.texture) {
613
- record.container.texture = picked.texture;
614
- record.emitter.setTexture(picked.texture);
615
- }
616
- record.emitter.setFrameTextures(picked.frameTextures);
617
- }
618
- }
619
- record.component = component;
620
- record.emitter.setParams(component);
621
- } else if (changed.type === eva_js.OBSERVER_TYPE.REMOVE) {
622
- this.increaseAsyncId(gameObjectId);
623
- const record = this.records[gameObjectId];
624
- if (!record) return;
625
- record.emitter.destroy();
626
- (_d = (_c = this.containerManager) === null || _c === void 0 ? void 0 : _c.getContainer(gameObjectId)) === null || _d === void 0 ? void 0 : _d.removeChild(record.container);
627
- record.container.destroy({
628
- children: true
629
- });
630
- delete this.records[gameObjectId];
631
- }
632
- });
633
- }
634
- destroy() {
635
- var _a, _b;
636
- for (const key in this.records) {
637
- const id = parseInt(key);
638
- const record = this.records[id];
639
- record.emitter.destroy();
640
- (_b = (_a = this.containerManager) === null || _a === void 0 ? void 0 : _a.getContainer(id)) === null || _b === void 0 ? void 0 : _b.removeChild(record.container);
641
- record.container.destroy({
642
- children: true
643
- });
644
- delete this.records[id];
645
- }
646
- }
647
- };
648
- ParticleEmitterSystem.systemName = 'ParticleEmitter';
649
- ParticleEmitterSystem = __decorate([eva_js.decorators.componentObserver({
650
- ParticleEmitter: [{
651
- prop: ['resource'],
652
- deep: false
653
- }]
654
- })], ParticleEmitterSystem);
655
- var ParticleEmitterSystem$1 = ParticleEmitterSystem;
656
- exports.Emitter = Emitter;
657
- exports.ParticleEmitter = ParticleEmitter;
658
- exports.ParticleEmitterSystem = ParticleEmitterSystem$1;
659
- Object.defineProperty(exports, '__esModule', {
660
- value: true
661
- });
662
- return exports;
663
- }({}, EVA, EVA.plugin.renderer, PIXI);
664
- globalThis.EVA.plugin.renderer.particle = globalThis.EVA.plugin.renderer.particle || _EVA_IIFE_particle;