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