@needle-tools/engine 2.40.0-pre → 2.42.0-pre

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.
Files changed (80) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/needle-engine.d.ts +332 -126
  3. package/dist/needle-engine.js +401 -401
  4. package/dist/needle-engine.js.map +4 -4
  5. package/dist/needle-engine.min.js +53 -53
  6. package/dist/needle-engine.min.js.map +4 -4
  7. package/lib/engine/engine_element.js +1 -1
  8. package/lib/engine/engine_element.js.map +1 -1
  9. package/lib/engine/engine_element_loading.js +6 -1
  10. package/lib/engine/engine_element_loading.js.map +1 -1
  11. package/lib/engine/engine_gizmos.d.ts +8 -21
  12. package/lib/engine/engine_gizmos.js +51 -5
  13. package/lib/engine/engine_gizmos.js.map +1 -1
  14. package/lib/engine/engine_math.d.ts +9 -6
  15. package/lib/engine/engine_math.js +9 -0
  16. package/lib/engine/engine_math.js.map +1 -1
  17. package/lib/engine/engine_physics.js +14 -6
  18. package/lib/engine/engine_physics.js.map +1 -1
  19. package/lib/engine/engine_serialization_core.js +2 -0
  20. package/lib/engine/engine_serialization_core.js.map +1 -1
  21. package/lib/engine/engine_setup.d.ts +3 -0
  22. package/lib/engine/engine_setup.js +15 -0
  23. package/lib/engine/engine_setup.js.map +1 -1
  24. package/lib/engine/engine_three_utils.d.ts +16 -1
  25. package/lib/engine/engine_three_utils.js +94 -54
  26. package/lib/engine/engine_three_utils.js.map +1 -1
  27. package/lib/engine/engine_types.d.ts +6 -0
  28. package/lib/engine/engine_types.js.map +1 -1
  29. package/lib/engine/engine_utils.d.ts +1 -0
  30. package/lib/engine/engine_utils.js +3 -0
  31. package/lib/engine/engine_utils.js.map +1 -1
  32. package/lib/engine-components/AnimationCurve.js +20 -5
  33. package/lib/engine-components/AnimationCurve.js.map +1 -1
  34. package/lib/engine-components/BoxHelperComponent.js +9 -10
  35. package/lib/engine-components/BoxHelperComponent.js.map +1 -1
  36. package/lib/engine-components/Light.d.ts +2 -0
  37. package/lib/engine-components/Light.js +33 -9
  38. package/lib/engine-components/Light.js.map +1 -1
  39. package/lib/engine-components/ParticleSystem.d.ts +29 -26
  40. package/lib/engine-components/ParticleSystem.js +349 -187
  41. package/lib/engine-components/ParticleSystem.js.map +1 -1
  42. package/lib/engine-components/ParticleSystemModules.d.ts +243 -64
  43. package/lib/engine-components/ParticleSystemModules.js +722 -153
  44. package/lib/engine-components/ParticleSystemModules.js.map +1 -1
  45. package/lib/engine-components/ReflectionProbe.js +29 -11
  46. package/lib/engine-components/ReflectionProbe.js.map +1 -1
  47. package/lib/engine-components/Renderer.d.ts +1 -0
  48. package/lib/engine-components/Renderer.js +4 -2
  49. package/lib/engine-components/Renderer.js.map +1 -1
  50. package/lib/engine-components/WebXR.js +8 -3
  51. package/lib/engine-components/WebXR.js.map +1 -1
  52. package/lib/engine-components/codegen/components.d.ts +7 -0
  53. package/lib/engine-components/codegen/components.js +7 -0
  54. package/lib/engine-components/codegen/components.js.map +1 -1
  55. package/package.json +4 -2
  56. package/src/engine/codegen/register_types.js +28 -0
  57. package/src/engine/dist/engine_three_utils.js +279 -0
  58. package/src/engine/engine_element.ts +1 -1
  59. package/src/engine/engine_element_loading.ts +5 -1
  60. package/src/engine/engine_gizmos.ts +58 -6
  61. package/src/engine/engine_math.ts +19 -6
  62. package/src/engine/engine_physics.ts +17 -7
  63. package/src/engine/engine_serialization_core.ts +1 -0
  64. package/src/engine/engine_setup.ts +25 -2
  65. package/src/engine/engine_three_utils.ts +103 -62
  66. package/src/engine/engine_types.ts +8 -1
  67. package/src/engine/engine_utils.ts +5 -0
  68. package/src/engine-components/AnimationCurve.ts +25 -11
  69. package/src/engine-components/BoxHelperComponent.ts +12 -15
  70. package/src/engine-components/Light.ts +39 -8
  71. package/src/engine-components/ParticleSystem.ts +395 -199
  72. package/src/engine-components/ParticleSystemModules.ts +638 -152
  73. package/src/engine-components/ReflectionProbe.ts +37 -13
  74. package/src/engine-components/Renderer.ts +4 -2
  75. package/src/engine-components/WebXR.ts +11 -8
  76. package/src/engine-components/codegen/components.ts +7 -0
  77. package/src/engine/dist/engine_physics.js +0 -739
  78. package/src/engine/dist/engine_setup.js +0 -777
  79. package/src/engine-components/dist/CharacterController.js +0 -123
  80. package/src/engine-components/dist/RigidBody.js +0 -458
@@ -1,61 +1,470 @@
1
- import * as THREE from "three";
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { Matrix4, Vector3 } from "three";
8
+ import { Mathf } from "../engine/engine_math";
9
+ import { serializeable } from "../engine/engine_serialization";
10
+ import { RGBAColor } from "./js-extensions/RGBAColor";
11
+ import { AnimationCurve } from "./AnimationCurve";
12
+ export var ParticleSystemRenderMode;
13
+ (function (ParticleSystemRenderMode) {
14
+ ParticleSystemRenderMode[ParticleSystemRenderMode["Billboard"] = 0] = "Billboard";
15
+ // Stretch = 1,
16
+ // HorizontalBillboard = 2,
17
+ // VerticalBillboard = 3,
18
+ ParticleSystemRenderMode[ParticleSystemRenderMode["Mesh"] = 4] = "Mesh";
19
+ // None = 5,
20
+ })(ParticleSystemRenderMode || (ParticleSystemRenderMode = {}));
21
+ export class Gradient {
22
+ alphaKeys;
23
+ colorKeys;
24
+ get duration() {
25
+ return 1;
26
+ }
27
+ evaluate(time, target) {
28
+ // target.r = this.colorKeys[0].color.r;
29
+ // target.g = this.colorKeys[0].color.g;
30
+ // target.b = this.colorKeys[0].color.b;
31
+ // target.alpha = this.alphaKeys[0].alpha;
32
+ // return;
33
+ let closestAlpha = undefined;
34
+ let closestAlphaIndex = 0;
35
+ let closestColor = null;
36
+ let closestColorIndex = 0;
37
+ for (let i = 0; i < this.alphaKeys.length; i++) {
38
+ const key = this.alphaKeys[i];
39
+ if (key.time < time || !closestAlpha) {
40
+ closestAlpha = key;
41
+ closestAlphaIndex = i;
42
+ }
43
+ }
44
+ for (let i = 0; i < this.colorKeys.length; i++) {
45
+ const key = this.colorKeys[i];
46
+ if (key.time < time || !closestColor) {
47
+ closestColor = key;
48
+ closestColorIndex = i;
49
+ }
50
+ }
51
+ if (closestColor) {
52
+ const hasNextColor = closestColorIndex + 1 < this.colorKeys.length;
53
+ if (hasNextColor) {
54
+ const nextColor = this.colorKeys[closestColorIndex + 1];
55
+ const t = Mathf.remap(time, closestColor.time, nextColor.time, 0, 1);
56
+ target.r = Mathf.lerp(closestColor.color.r, nextColor.color.r, t);
57
+ target.g = Mathf.lerp(closestColor.color.g, nextColor.color.g, t);
58
+ target.b = Mathf.lerp(closestColor.color.b, nextColor.color.b, t);
59
+ }
60
+ else {
61
+ target.r = closestColor.color.r;
62
+ target.g = closestColor.color.g;
63
+ target.b = closestColor.color.b;
64
+ }
65
+ }
66
+ if (closestAlpha) {
67
+ const hasNextAlpha = closestAlphaIndex + 1 < this.alphaKeys.length;
68
+ if (hasNextAlpha) {
69
+ const nextAlpha = this.alphaKeys[closestAlphaIndex + 1];
70
+ const t = Mathf.remap(time, closestAlpha.time, nextAlpha.time, 0, 1);
71
+ target.alpha = Mathf.lerp(closestAlpha.alpha, nextAlpha.alpha, t);
72
+ }
73
+ else {
74
+ target.alpha = closestAlpha.alpha;
75
+ }
76
+ }
77
+ return target;
78
+ }
79
+ }
80
+ __decorate([
81
+ serializeable()
82
+ ], Gradient.prototype, "alphaKeys", void 0);
83
+ __decorate([
84
+ serializeable()
85
+ ], Gradient.prototype, "colorKeys", void 0);
86
+ export var ParticleSystemCurveMode;
87
+ (function (ParticleSystemCurveMode) {
88
+ ParticleSystemCurveMode[ParticleSystemCurveMode["Constant"] = 0] = "Constant";
89
+ ParticleSystemCurveMode[ParticleSystemCurveMode["Curve"] = 1] = "Curve";
90
+ ParticleSystemCurveMode[ParticleSystemCurveMode["TwoCurves"] = 2] = "TwoCurves";
91
+ ParticleSystemCurveMode[ParticleSystemCurveMode["TwoConstants"] = 3] = "TwoConstants";
92
+ })(ParticleSystemCurveMode || (ParticleSystemCurveMode = {}));
93
+ export var ParticleSystemGradientMode;
94
+ (function (ParticleSystemGradientMode) {
95
+ ParticleSystemGradientMode[ParticleSystemGradientMode["Color"] = 0] = "Color";
96
+ ParticleSystemGradientMode[ParticleSystemGradientMode["Gradient"] = 1] = "Gradient";
97
+ ParticleSystemGradientMode[ParticleSystemGradientMode["TwoColors"] = 2] = "TwoColors";
98
+ ParticleSystemGradientMode[ParticleSystemGradientMode["TwoGradients"] = 3] = "TwoGradients";
99
+ ParticleSystemGradientMode[ParticleSystemGradientMode["RandomColor"] = 4] = "RandomColor";
100
+ })(ParticleSystemGradientMode || (ParticleSystemGradientMode = {}));
101
+ export var ParticleSystemSimulationSpace;
102
+ (function (ParticleSystemSimulationSpace) {
103
+ ParticleSystemSimulationSpace[ParticleSystemSimulationSpace["Local"] = 0] = "Local";
104
+ ParticleSystemSimulationSpace[ParticleSystemSimulationSpace["World"] = 1] = "World";
105
+ ParticleSystemSimulationSpace[ParticleSystemSimulationSpace["Custom"] = 2] = "Custom";
106
+ })(ParticleSystemSimulationSpace || (ParticleSystemSimulationSpace = {}));
107
+ export var ParticleSystemShapeType;
108
+ (function (ParticleSystemShapeType) {
109
+ ParticleSystemShapeType[ParticleSystemShapeType["Sphere"] = 0] = "Sphere";
110
+ ParticleSystemShapeType[ParticleSystemShapeType["SphereShell"] = 1] = "SphereShell";
111
+ ParticleSystemShapeType[ParticleSystemShapeType["Hemisphere"] = 2] = "Hemisphere";
112
+ ParticleSystemShapeType[ParticleSystemShapeType["HemisphereShell"] = 3] = "HemisphereShell";
113
+ ParticleSystemShapeType[ParticleSystemShapeType["Cone"] = 4] = "Cone";
114
+ ParticleSystemShapeType[ParticleSystemShapeType["Box"] = 5] = "Box";
115
+ ParticleSystemShapeType[ParticleSystemShapeType["Mesh"] = 6] = "Mesh";
116
+ ParticleSystemShapeType[ParticleSystemShapeType["ConeShell"] = 7] = "ConeShell";
117
+ ParticleSystemShapeType[ParticleSystemShapeType["ConeVolume"] = 8] = "ConeVolume";
118
+ ParticleSystemShapeType[ParticleSystemShapeType["ConeVolumeShell"] = 9] = "ConeVolumeShell";
119
+ ParticleSystemShapeType[ParticleSystemShapeType["Circle"] = 10] = "Circle";
120
+ ParticleSystemShapeType[ParticleSystemShapeType["CircleEdge"] = 11] = "CircleEdge";
121
+ ParticleSystemShapeType[ParticleSystemShapeType["SingleSidedEdge"] = 12] = "SingleSidedEdge";
122
+ ParticleSystemShapeType[ParticleSystemShapeType["MeshRenderer"] = 13] = "MeshRenderer";
123
+ ParticleSystemShapeType[ParticleSystemShapeType["SkinnedMeshRenderer"] = 14] = "SkinnedMeshRenderer";
124
+ ParticleSystemShapeType[ParticleSystemShapeType["BoxShell"] = 15] = "BoxShell";
125
+ ParticleSystemShapeType[ParticleSystemShapeType["BoxEdge"] = 16] = "BoxEdge";
126
+ ParticleSystemShapeType[ParticleSystemShapeType["Donut"] = 17] = "Donut";
127
+ ParticleSystemShapeType[ParticleSystemShapeType["Rectangle"] = 18] = "Rectangle";
128
+ ParticleSystemShapeType[ParticleSystemShapeType["Sprite"] = 19] = "Sprite";
129
+ ParticleSystemShapeType[ParticleSystemShapeType["SpriteRenderer"] = 20] = "SpriteRenderer";
130
+ })(ParticleSystemShapeType || (ParticleSystemShapeType = {}));
131
+ export class MinMaxCurve {
132
+ mode;
133
+ constant;
134
+ constantMin;
135
+ constantMax;
136
+ curve;
137
+ curveMin;
138
+ curveMax;
139
+ curveMultiplier;
140
+ evaluate(t01, lerpFactor) {
141
+ const t = lerpFactor === undefined ? Math.random() : lerpFactor;
142
+ switch (this.mode) {
143
+ case ParticleSystemCurveMode.Constant:
144
+ return this.constant;
145
+ case ParticleSystemCurveMode.Curve:
146
+ t01 %= this.curve.duration;
147
+ return this.curve.evaluate(t01);
148
+ case ParticleSystemCurveMode.TwoCurves:
149
+ const t1 = t01 * this.curveMin.duration;
150
+ const t2 = t01 * this.curveMax.duration;
151
+ return Mathf.lerp(this.curveMin.evaluate(t1), this.curveMax.evaluate(t2), t % 1);
152
+ case ParticleSystemCurveMode.TwoConstants:
153
+ return Mathf.lerp(this.constantMin, this.constantMax, t % 1);
154
+ default:
155
+ this.curveMax.evaluate(t01) * this.curveMultiplier;
156
+ break;
157
+ }
158
+ return 0;
159
+ }
160
+ }
161
+ __decorate([
162
+ serializeable()
163
+ ], MinMaxCurve.prototype, "mode", void 0);
164
+ __decorate([
165
+ serializeable()
166
+ ], MinMaxCurve.prototype, "constant", void 0);
167
+ __decorate([
168
+ serializeable()
169
+ ], MinMaxCurve.prototype, "constantMin", void 0);
170
+ __decorate([
171
+ serializeable()
172
+ ], MinMaxCurve.prototype, "constantMax", void 0);
173
+ __decorate([
174
+ serializeable(AnimationCurve)
175
+ ], MinMaxCurve.prototype, "curve", void 0);
176
+ __decorate([
177
+ serializeable(AnimationCurve)
178
+ ], MinMaxCurve.prototype, "curveMin", void 0);
179
+ __decorate([
180
+ serializeable(AnimationCurve)
181
+ ], MinMaxCurve.prototype, "curveMax", void 0);
182
+ __decorate([
183
+ serializeable()
184
+ ], MinMaxCurve.prototype, "curveMultiplier", void 0);
185
+ export class MinMaxGradient {
186
+ mode;
187
+ color;
188
+ colorMin;
189
+ colorMax;
190
+ gradient;
191
+ gradientMin;
192
+ gradientMax;
193
+ static _temp = new RGBAColor(0, 0, 0, 1);
194
+ static _temp2 = new RGBAColor(0, 0, 0, 1);
195
+ evaluate(t01, lerpFactor) {
196
+ const t = lerpFactor === undefined ? Math.random() : lerpFactor;
197
+ switch (this.mode) {
198
+ case ParticleSystemGradientMode.Color:
199
+ return this.color;
200
+ case ParticleSystemGradientMode.Gradient:
201
+ this.gradient.evaluate(t01, MinMaxGradient._temp);
202
+ return MinMaxGradient._temp;
203
+ case ParticleSystemGradientMode.TwoColors:
204
+ return MinMaxGradient._temp.lerpColors(this.colorMin, this.colorMax, t);
205
+ case ParticleSystemGradientMode.TwoGradients:
206
+ const t2 = Math.random();
207
+ this.gradientMin.evaluate(t2, MinMaxGradient._temp);
208
+ this.gradientMax.evaluate(t2, MinMaxGradient._temp2);
209
+ return MinMaxGradient._temp.lerp(MinMaxGradient._temp2, t);
210
+ }
211
+ // console.warn("Not implemented", ParticleSystemGradientMode[this.mode]);
212
+ MinMaxGradient._temp.set(0xff00ff);
213
+ MinMaxGradient._temp.alpha = 1;
214
+ return MinMaxGradient._temp;
215
+ }
216
+ }
217
+ __decorate([
218
+ serializeable(RGBAColor)
219
+ ], MinMaxGradient.prototype, "color", void 0);
220
+ __decorate([
221
+ serializeable(RGBAColor)
222
+ ], MinMaxGradient.prototype, "colorMin", void 0);
223
+ __decorate([
224
+ serializeable(RGBAColor)
225
+ ], MinMaxGradient.prototype, "colorMax", void 0);
226
+ __decorate([
227
+ serializeable(Gradient)
228
+ ], MinMaxGradient.prototype, "gradient", void 0);
229
+ __decorate([
230
+ serializeable(Gradient)
231
+ ], MinMaxGradient.prototype, "gradientMin", void 0);
232
+ __decorate([
233
+ serializeable(Gradient)
234
+ ], MinMaxGradient.prototype, "gradientMax", void 0);
2
235
  export class MainModule {
3
- randomizeRotationDirection = 0;
4
- duration = 5;
5
- loop = true;
6
- prewarm = false;
7
- startDelay = undefined; // UnityEngine.ParticleSystem+MinMaxCurve
8
- startDelayMultiplier = 0;
9
- startLifetime = undefined; // UnityEngine.ParticleSystem+MinMaxCurve
10
- startLifetimeMultiplier = 5;
11
- startSpeed = undefined; // UnityEngine.ParticleSystem+MinMaxCurve
12
- startSpeedMultiplier = 5;
13
- startSize3D = false;
14
- startSize = undefined; // UnityEngine.ParticleSystem+MinMaxCurve
15
- startSizeMultiplier = 1;
16
- startSizeX = undefined; // UnityEngine.ParticleSystem+MinMaxCurve
17
- startSizeXMultiplier = 1;
18
- startSizeY = undefined; // UnityEngine.ParticleSystem+MinMaxCurve
19
- startSizeYMultiplier = 1;
20
- startSizeZ = undefined; // UnityEngine.ParticleSystem+MinMaxCurve
21
- startSizeZMultiplier = 1;
22
- startRotation3D = false;
23
- startRotation = undefined; // UnityEngine.ParticleSystem+MinMaxCurve
24
- startRotationMultiplier = 0;
25
- startRotationX = undefined; // UnityEngine.ParticleSystem+MinMaxCurve
26
- startRotationXMultiplier = 0;
27
- startRotationY = undefined; // UnityEngine.ParticleSystem+MinMaxCurve
28
- startRotationYMultiplier = 0;
29
- startRotationZ = undefined; // UnityEngine.ParticleSystem+MinMaxCurve
30
- startRotationZMultiplier = 0;
31
- flipRotation = 0;
32
- startColor = new THREE.Color(1, 1, 1);
33
- startColor1 = new THREE.Color(0, 0, 0); // this only exists in gradient mode
34
- gravityModifier = undefined; // UnityEngine.ParticleSystem+MinMaxCurve
35
- gravityModifierMultiplier = 0;
36
- simulationSpace = 0;
37
- customSimulationSpace = null;
38
- simulationSpeed = 1;
39
- useUnscaledTime = false;
40
- scalingMode = 1;
41
- playOnAwake = true;
42
- maxParticles = 1000;
43
- emitterVelocityMode = 1;
44
- stopAction = 0;
45
- ringBufferMode = 0;
46
- ringBufferLoopRange = new THREE.Vector2(0, 1);
47
- cullingMode = 0;
236
+ cullingMode;
237
+ duration;
238
+ emitterVelocityMode;
239
+ flipRotation;
240
+ gravityModifier;
241
+ gravityModifierMultiplier;
242
+ loop;
243
+ maxParticles;
244
+ playOnAwake;
245
+ prewarm;
246
+ ringBufferLoopRange;
247
+ ringBufferMode;
248
+ scalingMode;
249
+ simulationSpace;
250
+ simulationSpeed;
251
+ startColor;
252
+ startDelay;
253
+ startDelayMultiplier;
254
+ startLifetime;
255
+ startLifetimeMultiplier;
256
+ startRotation;
257
+ startRotationMultiplier;
258
+ startRotation3D;
259
+ startRotationX;
260
+ startRotationXMultiplier;
261
+ startRotationY;
262
+ startRotationYMultiplier;
263
+ startRotationZ;
264
+ startRotationZMultiplier;
265
+ startSize;
266
+ startSize3D;
267
+ startSizeMultiplier;
268
+ startSizeX;
269
+ startSizeXMultiplier;
270
+ startSizeY;
271
+ startSizeYMultiplier;
272
+ startSizeZ;
273
+ startSizeZMultiplier;
274
+ startSpeed;
275
+ startSpeedMultiplier;
276
+ stopAction;
277
+ useUnscaledTime;
278
+ }
279
+ __decorate([
280
+ serializeable(MinMaxCurve)
281
+ ], MainModule.prototype, "gravityModifier", void 0);
282
+ __decorate([
283
+ serializeable(MinMaxGradient)
284
+ ], MainModule.prototype, "startColor", void 0);
285
+ __decorate([
286
+ serializeable(MinMaxCurve)
287
+ ], MainModule.prototype, "startDelay", void 0);
288
+ __decorate([
289
+ serializeable(MinMaxCurve)
290
+ ], MainModule.prototype, "startLifetime", void 0);
291
+ __decorate([
292
+ serializeable(MinMaxCurve)
293
+ ], MainModule.prototype, "startRotation", void 0);
294
+ __decorate([
295
+ serializeable(MinMaxCurve)
296
+ ], MainModule.prototype, "startRotationX", void 0);
297
+ __decorate([
298
+ serializeable(MinMaxCurve)
299
+ ], MainModule.prototype, "startRotationY", void 0);
300
+ __decorate([
301
+ serializeable(MinMaxCurve)
302
+ ], MainModule.prototype, "startRotationZ", void 0);
303
+ __decorate([
304
+ serializeable(MinMaxCurve)
305
+ ], MainModule.prototype, "startSize", void 0);
306
+ __decorate([
307
+ serializeable(MinMaxCurve)
308
+ ], MainModule.prototype, "startSizeX", void 0);
309
+ __decorate([
310
+ serializeable(MinMaxCurve)
311
+ ], MainModule.prototype, "startSizeY", void 0);
312
+ __decorate([
313
+ serializeable(MinMaxCurve)
314
+ ], MainModule.prototype, "startSizeZ", void 0);
315
+ __decorate([
316
+ serializeable(MinMaxCurve)
317
+ ], MainModule.prototype, "startSpeed", void 0);
318
+ export class ParticleBurst {
319
+ cycleCount;
320
+ maxCount;
321
+ minCount;
322
+ probability;
323
+ repeatInterval;
324
+ time;
325
+ count;
326
+ _performed = 0;
327
+ reset() {
328
+ this._performed = 0;
329
+ }
330
+ run(time) {
331
+ if (time <= this.time) {
332
+ this.reset();
333
+ return 0;
334
+ }
335
+ let amount = 0;
336
+ if (this.cycleCount === 0 || this._performed < this.cycleCount) {
337
+ const nextTime = this.time + this.repeatInterval * this._performed;
338
+ if (time >= nextTime) {
339
+ this._performed += 1;
340
+ if (Math.random() < this.probability) {
341
+ switch (this.count.mode) {
342
+ case ParticleSystemCurveMode.Constant:
343
+ amount = this.count.constant;
344
+ break;
345
+ case ParticleSystemCurveMode.TwoConstants:
346
+ amount = Mathf.lerp(this.count.constantMin, this.count.constantMax, Math.random());
347
+ break;
348
+ case ParticleSystemCurveMode.Curve:
349
+ amount = this.count.curve.evaluate(Math.random());
350
+ break;
351
+ case ParticleSystemCurveMode.TwoCurves:
352
+ const t = Math.random();
353
+ amount = Mathf.lerp(this.count.curveMin.evaluate(t), this.count.curveMax.evaluate(t), Math.random());
354
+ break;
355
+ }
356
+ }
357
+ }
358
+ }
359
+ return amount;
360
+ }
48
361
  }
49
362
  export class EmissionModule {
50
- burstCount = 0;
51
- enabled = true;
52
- rate = 10;
53
- rateMutliplier = 1;
54
- rateOverDistance = 0;
55
- rateOverDistanceMultiplier = 0;
56
- rateOverTime = 0;
57
- rateOverTimeMultiplier = 0;
363
+ enabled;
364
+ get burstCount() {
365
+ return this.bursts?.length ?? 0;
366
+ }
367
+ bursts;
368
+ rateOverTime;
369
+ rateOverTimeMultiplier;
370
+ rateOverDistance;
371
+ rateOverDistanceMultiplier;
372
+ /** set from system */
373
+ system;
374
+ get time() { return this.system.time; }
375
+ _summed = 0;
376
+ // private _didEmit: boolean = false;
377
+ /** called by nebula */
378
+ init() {
379
+ }
380
+ /** called by nebula */
381
+ getValue(deltaTime) {
382
+ if (this.system.currentParticles >= this.system.maxParticles)
383
+ return 0;
384
+ if (!this.enabled)
385
+ return 0;
386
+ let count = this.rateOverTime.evaluate(this.time / this.system.duration, Math.random());
387
+ this._summed += count * deltaTime;
388
+ let amount = Math.floor(this._summed);
389
+ this._summed -= amount;
390
+ if (this.burstCount > 0) {
391
+ for (let i = 0; i < this.burstCount; i++) {
392
+ const burst = this.bursts[i];
393
+ if (burst.time >= this.time) {
394
+ burst.reset();
395
+ continue;
396
+ }
397
+ amount += Math.round(burst.run(this.time));
398
+ }
399
+ }
400
+ // dont emit more than we are allowed to
401
+ return amount; //Mathf.clamp(amount, 0, this.system.maxParticles - this.system.currentParticles);
402
+ }
58
403
  }
404
+ __decorate([
405
+ serializeable()
406
+ ], EmissionModule.prototype, "enabled", void 0);
407
+ __decorate([
408
+ serializeable()
409
+ ], EmissionModule.prototype, "bursts", void 0);
410
+ __decorate([
411
+ serializeable(MinMaxCurve)
412
+ ], EmissionModule.prototype, "rateOverTime", void 0);
413
+ __decorate([
414
+ serializeable()
415
+ ], EmissionModule.prototype, "rateOverTimeMultiplier", void 0);
416
+ __decorate([
417
+ serializeable(MinMaxCurve)
418
+ ], EmissionModule.prototype, "rateOverDistance", void 0);
419
+ __decorate([
420
+ serializeable()
421
+ ], EmissionModule.prototype, "rateOverDistanceMultiplier", void 0);
422
+ export class ColorOverLifetimeModule {
423
+ enabled;
424
+ color;
425
+ }
426
+ __decorate([
427
+ serializeable(MinMaxGradient)
428
+ ], ColorOverLifetimeModule.prototype, "color", void 0);
429
+ export class SizeOverLifetimeModule {
430
+ enabled;
431
+ separateAxes;
432
+ size;
433
+ sizeMultiplier;
434
+ sizeX;
435
+ sizeXMultiplier;
436
+ sizeY;
437
+ sizeYMultiplier;
438
+ sizeZ;
439
+ sizeZMultiplier;
440
+ _time = 0;
441
+ evaluate(t01, target) {
442
+ if (!this.separateAxes) {
443
+ const scale = this.size.evaluate(t01) * this.sizeMultiplier;
444
+ target.x = scale;
445
+ // target.y = scale;
446
+ // target.z = scale;
447
+ }
448
+ else {
449
+ target.x = this.sizeX.evaluate(this._time) * this.sizeXMultiplier;
450
+ // target.y = this.sizeY.evaluate(this._time) * this.sizeYMultiplier;
451
+ // target.z = this.sizeZ.evaluate(this._time) * this.sizeZMultiplier;
452
+ }
453
+ return target;
454
+ }
455
+ }
456
+ __decorate([
457
+ serializeable(MinMaxCurve)
458
+ ], SizeOverLifetimeModule.prototype, "size", void 0);
459
+ __decorate([
460
+ serializeable(MinMaxCurve)
461
+ ], SizeOverLifetimeModule.prototype, "sizeX", void 0);
462
+ __decorate([
463
+ serializeable(MinMaxCurve)
464
+ ], SizeOverLifetimeModule.prototype, "sizeY", void 0);
465
+ __decorate([
466
+ serializeable(MinMaxCurve)
467
+ ], SizeOverLifetimeModule.prototype, "sizeZ", void 0);
59
468
  export class ShapeModule {
60
469
  shapeType = ParticleSystemShapeType.Box;
61
470
  enabled = true;
@@ -64,104 +473,264 @@ export class ShapeModule {
64
473
  arc = 360;
65
474
  arcmode = 0; // TODO: enum?
66
475
  // arcSpeed, arcSpeedMult, arcSpread
67
- box = new THREE.Vector3(1, 1, 1);
68
- boxThickness = new THREE.Vector3(0, 0, 0);
69
- position = new THREE.Vector3(0, 0, 0);
70
- rotation = new THREE.Vector3(0, 0, 0);
71
- scale = new THREE.Vector3(1, 1, 1);
72
- radius = 1;
73
- sphericalDirectionAmount = 0;
476
+ // @serializeable(Vector3)
477
+ // box!: Vector3;
478
+ boxThickness;
479
+ position;
480
+ rotation;
481
+ scale;
482
+ radius;
483
+ radiusThickness;
484
+ sphericalDirectionAmount;
485
+ _space;
486
+ _worldSpacePosition = new Matrix4();
487
+ update(_context, simulationSpace, obj) {
488
+ this._space = simulationSpace;
489
+ if (simulationSpace === ParticleSystemSimulationSpace.World) {
490
+ this._worldSpacePosition.copy(obj.matrixWorld);
491
+ // set scale to 1
492
+ this._worldSpacePosition.elements[0] = 1;
493
+ this._worldSpacePosition.elements[5] = 1;
494
+ this._worldSpacePosition.elements[10] = 1;
495
+ }
496
+ }
497
+ /** nebula implementations: */
498
+ /** initializer implementation */
499
+ _vector = new Vector3(0, 0, 0);
500
+ _temp = new Vector3(0, 0, 0);
501
+ /** called by nebula on initialize */
502
+ get vector() {
503
+ return this._vector;
504
+ }
505
+ /** called by nebula */
506
+ getPosition() {
507
+ switch (this.shapeType) {
508
+ case ParticleSystemShapeType.Box:
509
+ this._vector.x = Math.random() * this.scale.x - this.scale.x / 2;
510
+ this._vector.y = Math.random() * this.scale.y - this.scale.y / 2;
511
+ this._vector.z = Math.random() * this.scale.z - this.scale.z / 2;
512
+ break;
513
+ case ParticleSystemShapeType.Sphere:
514
+ randomSpherePoint(this.position.x, this.position.y, this.position.z, this.radius, this.radiusThickness, this.arc, this._vector);
515
+ break;
516
+ // case ParticleSystemShapeType.Hemisphere:
517
+ // randomSpherePoint(this.position.x, this.position.y, this.position.z, this.radius, this.radiusThickness, 180, this._vector);
518
+ // break;
519
+ }
520
+ if (this._space === ParticleSystemSimulationSpace.World) {
521
+ this._vector.applyMatrix4(this._worldSpacePosition);
522
+ }
523
+ }
524
+ _dir = new Vector3();
525
+ getDirection(position) {
526
+ switch (this.shapeType) {
527
+ case ParticleSystemShapeType.Box:
528
+ return this._dir.set(0, 0, 1);
529
+ case ParticleSystemShapeType.Sphere:
530
+ const rx = position.x;
531
+ const ry = position.y;
532
+ const rz = position.z;
533
+ return this._dir.set(rx, ry, rz).normalize();
534
+ }
535
+ return this._dir.set(0, 1, 0);
536
+ }
74
537
  }
75
- /// <summary>
76
- /// <para>The emission shape.</para>
77
- /// </summary>
78
- export var ParticleSystemShapeType;
79
- (function (ParticleSystemShapeType) {
80
- /// <summary>
81
- /// <para>Emit from a sphere.</para>
82
- /// </summary>
83
- ParticleSystemShapeType[ParticleSystemShapeType["Sphere"] = 0] = "Sphere";
84
- /// <summary>
85
- /// <para>Emit from the surface of a sphere.</para>
86
- /// </summary>
87
- // [Obsolete("SphereShell is deprecated and does nothing. Please use ShapeModule.radiusThickness instead, to control edge emission.", false)] SphereShell,
88
- ParticleSystemShapeType[ParticleSystemShapeType["SphereShell"] = 1] = "SphereShell";
89
- /// <summary>
90
- /// <para>Emit from a half-sphere.</para>
91
- /// </summary>
92
- ParticleSystemShapeType[ParticleSystemShapeType["Hemisphere"] = 2] = "Hemisphere";
93
- // / <summary>
94
- // / <para>Emit from the surface of a half-sphere.</para>
95
- // / </summary>
96
- // [Obsolete("HemisphereShell is deprecated and does nothing. Please use ShapeModule.radiusThickness instead, to control edge emission.", false)] HemisphereShell,
97
- ParticleSystemShapeType[ParticleSystemShapeType["HemisphereShell"] = 3] = "HemisphereShell";
98
- /// <summary>
99
- /// <para>Emit from the base of a cone.</para>
100
- /// </summary>
101
- ParticleSystemShapeType[ParticleSystemShapeType["Cone"] = 4] = "Cone";
102
- /// <summary>
103
- /// <para>Emit from the volume of a box.</para>
104
- /// </summary>
105
- ParticleSystemShapeType[ParticleSystemShapeType["Box"] = 5] = "Box";
106
- /// <summary>
107
- /// <para>Emit from a mesh.</para>
108
- /// </summary>
109
- ParticleSystemShapeType[ParticleSystemShapeType["Mesh"] = 6] = "Mesh";
110
- /// <summary>
111
- /// <para>Emit from the base surface of a cone.</para>
112
- /// </summary>
113
- // [Obsolete("ConeShell is deprecated and does nothing. Please use ShapeModule.radiusThickness instead, to control edge emission.", false)] ConeShell,
114
- // /// <summary>
115
- // /// <para>Emit from a cone.</para>
116
- // /// </summary>
117
- ParticleSystemShapeType[ParticleSystemShapeType["ConeVolume"] = 7] = "ConeVolume";
118
- /// <summary>
119
- /// <para>Emit from the surface of a cone.</para>
120
- /// </summary>
121
- // [Obsolete("ConeVolumeShell is deprecated and does nothing. Please use ShapeModule.radiusThickness instead, to control edge emission.", false)] ConeVolumeShell,
122
- // /// <summary>
123
- // /// <para>Emit from a circle.</para>
124
- // /// </summary>
125
- ParticleSystemShapeType[ParticleSystemShapeType["Circle"] = 10] = "Circle";
126
- /// <summary>
127
- /// <para>Emit from the edge of a circle.</para>
128
- /// </summary>
129
- // [Obsolete("CircleEdge is deprecated and does nothing. Please use ShapeModule.radiusThickness instead, to control edge emission.", false)] CircleEdge,
130
- // /// <summary>
131
- // /// <para>Emit from an edge.</para>
132
- // /// </summary>
133
- ParticleSystemShapeType[ParticleSystemShapeType["SingleSidedEdge"] = 11] = "SingleSidedEdge";
134
- /// <summary>
135
- /// <para>Emit from a mesh renderer.</para>
136
- /// </summary>
137
- ParticleSystemShapeType[ParticleSystemShapeType["MeshRenderer"] = 12] = "MeshRenderer";
138
- /// <summary>
139
- /// <para>Emit from a skinned mesh renderer.</para>
140
- /// </summary>
141
- ParticleSystemShapeType[ParticleSystemShapeType["SkinnedMeshRenderer"] = 13] = "SkinnedMeshRenderer";
142
- /// <summary>
143
- /// <para>Emit from the surface of a box.</para>
144
- /// </summary>
145
- ParticleSystemShapeType[ParticleSystemShapeType["BoxShell"] = 14] = "BoxShell";
146
- /// <summary>
147
- /// <para>Emit from the edges of a box.</para>
148
- /// </summary>
149
- ParticleSystemShapeType[ParticleSystemShapeType["BoxEdge"] = 15] = "BoxEdge";
150
- /// <summary>
151
- /// <para>Emit from a Donut.</para>
152
- /// </summary>
153
- ParticleSystemShapeType[ParticleSystemShapeType["Donut"] = 16] = "Donut";
154
- /// <summary>
155
- /// <para>Emit from a rectangle.</para>
156
- /// </summary>
157
- ParticleSystemShapeType[ParticleSystemShapeType["Rectangle"] = 17] = "Rectangle";
158
- /// <summary>
159
- /// <para>Emit from a sprite.</para>
160
- /// </summary>
161
- ParticleSystemShapeType[ParticleSystemShapeType["Sprite"] = 18] = "Sprite";
162
- /// <summary>
163
- /// <para>Emit from a sprite renderer.</para>
164
- /// </summary>
165
- ParticleSystemShapeType[ParticleSystemShapeType["SpriteRenderer"] = 19] = "SpriteRenderer";
166
- })(ParticleSystemShapeType || (ParticleSystemShapeType = {}));
538
+ __decorate([
539
+ serializeable()
540
+ ], ShapeModule.prototype, "shapeType", void 0);
541
+ __decorate([
542
+ serializeable()
543
+ ], ShapeModule.prototype, "enabled", void 0);
544
+ __decorate([
545
+ serializeable()
546
+ ], ShapeModule.prototype, "alignToDirection", void 0);
547
+ __decorate([
548
+ serializeable()
549
+ ], ShapeModule.prototype, "angle", void 0);
550
+ __decorate([
551
+ serializeable()
552
+ ], ShapeModule.prototype, "arc", void 0);
553
+ __decorate([
554
+ serializeable()
555
+ ], ShapeModule.prototype, "arcmode", void 0);
556
+ __decorate([
557
+ serializeable(Vector3)
558
+ ], ShapeModule.prototype, "boxThickness", void 0);
559
+ __decorate([
560
+ serializeable(Vector3)
561
+ ], ShapeModule.prototype, "position", void 0);
562
+ __decorate([
563
+ serializeable(Vector3)
564
+ ], ShapeModule.prototype, "rotation", void 0);
565
+ __decorate([
566
+ serializeable(Vector3)
567
+ ], ShapeModule.prototype, "scale", void 0);
568
+ __decorate([
569
+ serializeable()
570
+ ], ShapeModule.prototype, "radius", void 0);
571
+ __decorate([
572
+ serializeable()
573
+ ], ShapeModule.prototype, "radiusThickness", void 0);
574
+ __decorate([
575
+ serializeable()
576
+ ], ShapeModule.prototype, "sphericalDirectionAmount", void 0);
577
+ function randomSpherePoint(x0, y0, z0, radius, thickness, arc, vec) {
578
+ const u = Math.random();
579
+ const v = Math.random();
580
+ const theta = 2 * Math.PI * u * (arc / 360);
581
+ const phi = Math.acos(2 * v - 1);
582
+ const r = Mathf.lerp(1, 1 - (Math.pow(1 - Math.random(), Math.PI)), thickness) * radius;
583
+ const x = x0 + (-r * Math.sin(phi) * Math.cos(theta));
584
+ const y = y0 + (r * Math.sin(phi) * Math.sin(theta));
585
+ const z = z0 + (r * Math.cos(phi));
586
+ vec.x = x;
587
+ vec.y = y;
588
+ vec.z = z;
589
+ }
590
+ import { createNoise4D } from 'simplex-noise';
591
+ import { Context } from "../engine/engine_setup";
592
+ export class NoiseModule {
593
+ damping;
594
+ enabled;
595
+ frequency;
596
+ octaveCount;
597
+ octaveMultiplier;
598
+ octaveScale;
599
+ positionAmount;
600
+ quality;
601
+ remap;
602
+ remapEnabled;
603
+ remapMultiplier;
604
+ remapX;
605
+ remapXMultiplier;
606
+ remapY;
607
+ remapYMultiplier;
608
+ remapZ;
609
+ remapZMultiplier;
610
+ scrollSpeedMultiplier;
611
+ separateAxes;
612
+ strengthMultiplier;
613
+ strengthX;
614
+ strengthXMultiplier;
615
+ strengthY;
616
+ strengthYMultiplier;
617
+ strengthZ;
618
+ strengthZMultiplier;
619
+ _noise;
620
+ _time = 0;
621
+ update(context) {
622
+ this._time += context.time.deltaTime * this.scrollSpeedMultiplier;
623
+ }
624
+ /** nebula implementations: */
625
+ _temp = new Vector3();
626
+ applyNoise(index, pos, vel, deltaTime, age, life) {
627
+ if (!this.enabled)
628
+ return;
629
+ if (!this._noise) {
630
+ this._noise = createNoise4D(() => 0);
631
+ }
632
+ const t = age / life;
633
+ const dt = Context.Current.time.deltaTime;
634
+ const temp = this._temp.set(pos.x, pos.y, pos.z).multiplyScalar(this.frequency);
635
+ const nx = this._noise(temp.x, temp.y, temp.z, this._time);
636
+ const ny = this._noise(temp.x, temp.y, temp.z, this._time + .2);
637
+ const nz = this._noise(temp.x, temp.y, temp.z, this._time + .5);
638
+ this._temp.set(nx, ny, nz).normalize();
639
+ let strengthFactor = this.positionAmount.evaluate(t);
640
+ if (!this.separateAxes) {
641
+ if (this.strengthX)
642
+ strengthFactor *= this.strengthX.evaluate(t, index * 1.1);
643
+ else
644
+ strengthFactor *= this.strengthMultiplier;
645
+ strengthFactor *= deltaTime;
646
+ this._temp.multiplyScalar(strengthFactor);
647
+ }
648
+ if (this.separateAxes) {
649
+ this._temp.x *= strengthFactor * deltaTime * this.strengthXMultiplier;
650
+ this._temp.y *= strengthFactor * deltaTime * this.strengthYMultiplier;
651
+ this._temp.z *= strengthFactor * deltaTime * this.strengthZMultiplier;
652
+ }
653
+ vel.x += this._temp.x;
654
+ vel.y += this._temp.y;
655
+ vel.z += this._temp.z;
656
+ }
657
+ }
658
+ __decorate([
659
+ serializeable()
660
+ ], NoiseModule.prototype, "damping", void 0);
661
+ __decorate([
662
+ serializeable()
663
+ ], NoiseModule.prototype, "enabled", void 0);
664
+ __decorate([
665
+ serializeable()
666
+ ], NoiseModule.prototype, "frequency", void 0);
667
+ __decorate([
668
+ serializeable()
669
+ ], NoiseModule.prototype, "octaveCount", void 0);
670
+ __decorate([
671
+ serializeable()
672
+ ], NoiseModule.prototype, "octaveMultiplier", void 0);
673
+ __decorate([
674
+ serializeable()
675
+ ], NoiseModule.prototype, "octaveScale", void 0);
676
+ __decorate([
677
+ serializeable(MinMaxCurve)
678
+ ], NoiseModule.prototype, "positionAmount", void 0);
679
+ __decorate([
680
+ serializeable()
681
+ ], NoiseModule.prototype, "quality", void 0);
682
+ __decorate([
683
+ serializeable(MinMaxCurve)
684
+ ], NoiseModule.prototype, "remap", void 0);
685
+ __decorate([
686
+ serializeable()
687
+ ], NoiseModule.prototype, "remapEnabled", void 0);
688
+ __decorate([
689
+ serializeable()
690
+ ], NoiseModule.prototype, "remapMultiplier", void 0);
691
+ __decorate([
692
+ serializeable(MinMaxCurve)
693
+ ], NoiseModule.prototype, "remapX", void 0);
694
+ __decorate([
695
+ serializeable()
696
+ ], NoiseModule.prototype, "remapXMultiplier", void 0);
697
+ __decorate([
698
+ serializeable(MinMaxCurve)
699
+ ], NoiseModule.prototype, "remapY", void 0);
700
+ __decorate([
701
+ serializeable()
702
+ ], NoiseModule.prototype, "remapYMultiplier", void 0);
703
+ __decorate([
704
+ serializeable(MinMaxCurve)
705
+ ], NoiseModule.prototype, "remapZ", void 0);
706
+ __decorate([
707
+ serializeable()
708
+ ], NoiseModule.prototype, "remapZMultiplier", void 0);
709
+ __decorate([
710
+ serializeable()
711
+ ], NoiseModule.prototype, "scrollSpeedMultiplier", void 0);
712
+ __decorate([
713
+ serializeable()
714
+ ], NoiseModule.prototype, "separateAxes", void 0);
715
+ __decorate([
716
+ serializeable()
717
+ ], NoiseModule.prototype, "strengthMultiplier", void 0);
718
+ __decorate([
719
+ serializeable(MinMaxCurve)
720
+ ], NoiseModule.prototype, "strengthX", void 0);
721
+ __decorate([
722
+ serializeable()
723
+ ], NoiseModule.prototype, "strengthXMultiplier", void 0);
724
+ __decorate([
725
+ serializeable(MinMaxCurve)
726
+ ], NoiseModule.prototype, "strengthY", void 0);
727
+ __decorate([
728
+ serializeable()
729
+ ], NoiseModule.prototype, "strengthYMultiplier", void 0);
730
+ __decorate([
731
+ serializeable(MinMaxCurve)
732
+ ], NoiseModule.prototype, "strengthZ", void 0);
733
+ __decorate([
734
+ serializeable()
735
+ ], NoiseModule.prototype, "strengthZMultiplier", void 0);
167
736
  //# sourceMappingURL=ParticleSystemModules.js.map