laymur 0.27.1 → 0.28.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +46 -1
- package/dist/core/constraints/UIAspectConstraint/UIAspectConstraint.js +2 -1
- package/dist/core/constraints/UICustomConstraint.js +1 -1
- package/dist/core/constraints/UIHeightConstraint/UIHeightConstraint.js +2 -1
- package/dist/core/constraints/UIHorizontalDistanceConstraint/UIHorizontalDistanceConstraint.js +2 -1
- package/dist/core/constraints/UIHorizontalInterpolationConstraint/UIHorizontalInterpolationConstraint.js +2 -1
- package/dist/core/constraints/UIHorizontalProportionConstraint/UIHorizontalProportionConstraint.js +2 -1
- package/dist/core/constraints/UIVerticalDistanceConstraint/UIVerticalDistanceConstraint.js +2 -1
- package/dist/core/constraints/UIVerticalInterpolationConstraint/UIVerticalInterpolationConstraint.js +2 -1
- package/dist/core/constraints/UIVerticalProportionConstraint/UIVerticalProportionConstraint.js +2 -1
- package/dist/core/constraints/UIWidthConstraint/UIWidthConstraint.js +2 -1
- package/dist/core/constraints/constraintAsserts.d.ts +41 -0
- package/dist/core/constraints/constraintAsserts.js +171 -0
- package/dist/core/elements/UIDummy/UIDummy.d.ts +8 -5
- package/dist/core/elements/UIDummy/UIDummy.js +21 -10
- package/dist/core/elements/UIElement/UIElement.Internal.d.ts +6 -5
- package/dist/core/elements/UIElement/UIElement.Internal.js +0 -4
- package/dist/core/elements/UIElement/UIElement.d.ts +12 -6
- package/dist/core/elements/UIElement/UIElement.js +14 -7
- package/dist/core/elements/UIText/UIText.d.ts +6 -1
- package/dist/core/elements/UIText/UIText.js +22 -12
- package/dist/core/layers/UIViewportLayer/UIViewportLayer.js +1 -1
- package/dist/core/miscellaneous/UIBlendMode.d.ts +5 -0
- package/dist/core/miscellaneous/UIBlendMode.js +7 -0
- package/dist/core/miscellaneous/asserts.d.ts +0 -41
- package/dist/core/miscellaneous/asserts.js +0 -170
- package/dist/core/miscellaneous/mask-function/UIProgressMaskFunctionCircular.d.ts +10 -7
- package/dist/core/miscellaneous/mask-function/UIProgressMaskFunctionCircular.js +11 -8
- package/dist/core/miscellaneous/text-style/UITextStyle.Internal.d.ts +4 -1
- package/dist/core/miscellaneous/text-style/UITextStyle.d.ts +4 -1
- package/dist/core/miscellaneous/text-style/UITextStyle.js +4 -1
- package/dist/core/shaders/UIProgressMaskFunctionCircular.js +1 -2
- package/dist/core/wrappers/UIInputWrapper/UIInputWrapper.Internal.d.ts +6 -2
- package/dist/core/wrappers/UIInputWrapper/UIInputWrapper.d.ts +1 -0
- package/dist/core/wrappers/UIInputWrapper/UIInputWrapper.js +18 -9
- package/dist/particles/behaviorModules/UIBehaviorAlignToVelocity.d.ts +44 -0
- package/dist/particles/behaviorModules/UIBehaviorAlignToVelocity.js +75 -0
- package/dist/particles/behaviorModules/UIBehaviorBounce.d.ts +51 -0
- package/dist/particles/behaviorModules/UIBehaviorBounce.js +107 -0
- package/dist/particles/behaviorModules/UIBehaviorOrbit.d.ts +39 -0
- package/dist/particles/behaviorModules/UIBehaviorOrbit.js +73 -0
- package/dist/particles/behaviorModules/UIBehaviorScaleOverLife.d.ts +7 -2
- package/dist/particles/behaviorModules/UIBehaviorScaleOverLife.js +9 -5
- package/dist/particles/behaviorModules/UIBehaviorSeek.d.ts +38 -0
- package/dist/particles/behaviorModules/UIBehaviorSeek.js +75 -0
- package/dist/particles/elements/UIEmitter.Internal.d.ts +45 -1
- package/dist/particles/elements/UIEmitter.Internal.js +25 -1
- package/dist/particles/elements/UIEmitter.Schedule.d.ts +31 -0
- package/dist/particles/elements/UIEmitter.Schedule.js +81 -0
- package/dist/particles/elements/UIEmitter.d.ts +79 -9
- package/dist/particles/elements/UIEmitter.js +239 -82
- package/dist/particles/index.d.ts +13 -1
- package/dist/particles/index.js +11 -1
- package/dist/particles/instancedParticle/UIInstancedParticle.Internal.d.ts +6 -0
- package/dist/particles/instancedParticle/UIInstancedParticle.Internal.js +27 -0
- package/dist/particles/instancedParticle/UIInstancedParticle.d.ts +7 -1
- package/dist/particles/instancedParticle/UIInstancedParticle.js +12 -1
- package/dist/particles/miscellaneous/miscellaneous.d.ts +22 -0
- package/dist/particles/miscellaneous/miscellaneous.js +38 -0
- package/dist/particles/renderingModules/UIRenderingFlipbook.d.ts +41 -0
- package/dist/particles/renderingModules/UIRenderingFlipbook.js +70 -0
- package/dist/particles/renderingModules/UIRenderingModule.d.ts +2 -1
- package/dist/particles/renderingModules/UIRenderingModule.js +2 -1
- package/dist/particles/renderingModules/UIRenderingRandomColor.d.ts +19 -0
- package/dist/particles/renderingModules/UIRenderingRandomColor.js +28 -0
- package/dist/particles/renderingModules/UIRenderingShape.d.ts +31 -0
- package/dist/particles/renderingModules/UIRenderingShape.js +54 -0
- package/dist/particles/renderingModules/UIRenderingTexture.d.ts +1 -1
- package/dist/particles/renderingModules/UIRenderingTexture.js +4 -28
- package/dist/particles/shaders/UIRenderingFlipbook.d.ts +5 -0
- package/dist/particles/shaders/UIRenderingFlipbook.js +19 -0
- package/dist/particles/shaders/UIRenderingRandomColor.d.ts +2 -0
- package/dist/particles/shaders/UIRenderingRandomColor.js +10 -0
- package/dist/particles/shaders/UIRenderingShape.d.ts +6 -0
- package/dist/particles/shaders/UIRenderingShape.js +15 -0
- package/dist/particles/shaders/UIRenderingTexture.d.ts +4 -2
- package/dist/particles/shaders/UIRenderingTexture.js +27 -2
- package/dist/particles/spawnModules/UISpawnCircle.d.ts +44 -0
- package/dist/particles/spawnModules/UISpawnCircle.js +81 -0
- package/dist/particles/spawnModules/UISpawnRadialVelocity.d.ts +37 -0
- package/dist/particles/spawnModules/UISpawnRadialVelocity.js +75 -0
- package/package.json +1 -1
|
@@ -1,12 +1,15 @@
|
|
|
1
|
+
import { Ferrsign2 } from "ferrsign";
|
|
1
2
|
import { Vector2 } from "three";
|
|
2
3
|
import { UIAnchor } from "../../core/elements/UIAnchor/UIAnchor.js";
|
|
3
|
-
import { assertValidNumber, assertValidPositiveNumber } from "../../core/miscellaneous/asserts.js";
|
|
4
|
+
import { assertValidNonNegativeNumber, assertValidNumber, assertValidPositiveNumber, } from "../../core/miscellaneous/asserts.js";
|
|
4
5
|
import { resolveGLSLTypeInfo } from "../../core/miscellaneous/generic-plane/shared.js";
|
|
6
|
+
import { blendModeToFactor } from "../../core/miscellaneous/UIBlendMode.js";
|
|
5
7
|
import { isUIModeVisible } from "../../core/miscellaneous/UIMode.js";
|
|
6
|
-
import { collectProperties, collectRenderingUniforms, } from "../instancedParticle/UIInstancedParticle.Internal.js";
|
|
8
|
+
import { assignRenderingRandomValues, collectProperties, collectRenderingUniforms, } from "../instancedParticle/UIInstancedParticle.Internal.js";
|
|
7
9
|
import { UIInstancedParticle } from "../instancedParticle/UIInstancedParticle.js";
|
|
8
|
-
import { assertValidNonNegativeInteger, BUILTIN_OFFSET_AGE, BUILTIN_OFFSET_LIFETIME, BUILTIN_OFFSET_POSITION_X, BUILTIN_OFFSET_POSITION_Y, BUILTIN_OFFSET_RANDOM_A, BUILTIN_OFFSET_RANDOM_B, BUILTIN_OFFSET_RANDOM_C, BUILTIN_OFFSET_RANDOM_D, BUILTIN_OFFSET_RANDOM_E,
|
|
9
|
-
import { EMITTER_BEHAVIOR_SALT_BASE, EMITTER_DEFAULT_AUTOMATICALLY_DESTROY_MODULES, EMITTER_DEFAULT_CAPACITY_STEP, EMITTER_DEFAULT_EXPECTED_CAPACITY, EMITTER_DEFAULT_LIFETIME, EMITTER_DEFAULT_MAX_DELTA_TIME, EMITTER_DEFAULT_MODE, EMITTER_SHADER_SALT, EMITTER_SPAWN_SALT_BASE, ignoreInput, } from "./UIEmitter.Internal.js";
|
|
10
|
+
import { assertValidNonNegativeInteger, BUILTIN_OFFSET_AGE, BUILTIN_OFFSET_LIFETIME, BUILTIN_OFFSET_POSITION_X, BUILTIN_OFFSET_POSITION_Y, BUILTIN_OFFSET_RANDOM_A, BUILTIN_OFFSET_RANDOM_B, BUILTIN_OFFSET_RANDOM_C, BUILTIN_OFFSET_RANDOM_D, BUILTIN_OFFSET_RANDOM_E, BUILTIN_OFFSET_SCALE_X, BUILTIN_OFFSET_SCALE_Y, computeParticleSeed, particleRandom, particleRandomStream, writeParticleSeed, } from "../miscellaneous/miscellaneous.js";
|
|
11
|
+
import { advanceParticle, EMITTER_BEHAVIOR_SALT_BASE, EMITTER_DEFAULT_AUTOMATICALLY_DESTROY_MODULES, EMITTER_DEFAULT_BLEND_MODE, EMITTER_DEFAULT_CAPACITY_STEP, EMITTER_DEFAULT_EXPECTED_CAPACITY, EMITTER_DEFAULT_LIFETIME, EMITTER_DEFAULT_MAX_DELTA_TIME, EMITTER_DEFAULT_MODE, EMITTER_DEFAULT_PREWARM_STEP, EMITTER_DEFAULT_SPACE, EMITTER_SHADER_SALT, EMITTER_SPAWN_SALT_BASE, ignoreInput, UIEmitterSpace, } from "./UIEmitter.Internal.js";
|
|
12
|
+
import { UIEmissionSchedule } from "./UIEmitter.Schedule.js";
|
|
10
13
|
/** Builtin slots of the random values the shaders read, each with its stream */
|
|
11
14
|
const SHADER_RANDOM_SLOTS = [
|
|
12
15
|
BUILTIN_OFFSET_RANDOM_A,
|
|
@@ -21,7 +24,9 @@ const SHADER_RANDOM_SLOTS = [
|
|
|
21
24
|
/**
|
|
22
25
|
* Particle emitter element.
|
|
23
26
|
*
|
|
24
|
-
* Spawns, updates, and renders particles using modular spawn/behavior/rendering pipeline.
|
|
27
|
+
* Spawns, updates, and renders particles using modular spawn/behavior/rendering pipeline. Each
|
|
28
|
+
* frame ages the particles and removes the dead ones, spawns the particles due, runs the behavior
|
|
29
|
+
* modules and moves the particles along their velocity.
|
|
25
30
|
*/
|
|
26
31
|
export class UIEmitter extends UIAnchor {
|
|
27
32
|
/**
|
|
@@ -36,58 +41,34 @@ export class UIEmitter extends UIAnchor {
|
|
|
36
41
|
this.spawnSequence = spawnSequence;
|
|
37
42
|
this.behaviorSequence = behaviorSequence;
|
|
38
43
|
this.renderingSequence = renderingSequence;
|
|
39
|
-
this.
|
|
40
|
-
|
|
41
|
-
this.
|
|
42
|
-
|
|
44
|
+
this.emission = new UIEmissionSchedule();
|
|
45
|
+
/** Path of the emitter over the current frame, along which emission places particles */
|
|
46
|
+
this.framePath = { time: 0, fromX: 0, fromY: 0, toX: 0, toY: 0 };
|
|
47
|
+
/** Path of a single point and moment, for bursts */
|
|
48
|
+
this.pointPath = { time: 0, fromX: 0, fromY: 0, toX: 0, toY: 0 };
|
|
49
|
+
/** Layer positions of the particles that died this frame, x and y in turn */
|
|
50
|
+
this.deadPositions = [];
|
|
51
|
+
this.signalParticleDiedInternal = new Ferrsign2();
|
|
43
52
|
/** Particles spawned since the seed was set; picks the seed of the next particle */
|
|
44
53
|
this.spawnedCount = 0;
|
|
54
|
+
/** Whether `play` was called since the last frame: its emission starts at the current position */
|
|
55
|
+
this.emissionStarted = false;
|
|
56
|
+
/** Spawns the particles the emission schedule hands out, along the frame path */
|
|
57
|
+
this.spawnDue = (count, firstMoment, interval) => {
|
|
58
|
+
this.spawnParticles(count, firstMoment, interval, this.framePath);
|
|
59
|
+
};
|
|
60
|
+
/** Records the layer position of a dead particle */
|
|
61
|
+
this.collectDeadParticle = (array, itemOffset) => {
|
|
62
|
+
this.deadPositions.push(array[itemOffset + BUILTIN_OFFSET_POSITION_X] + this.originX, array[itemOffset + BUILTIN_OFFSET_POSITION_Y] + this.originY);
|
|
63
|
+
};
|
|
45
64
|
this.onRendering = (renderer, rawDeltaTime) => {
|
|
46
65
|
this.layer.sceneWrapper.setOrderedObjectDepth(this.mesh, this.layer.inputWrapper.getDepth(this.catcherHandler));
|
|
47
|
-
|
|
48
|
-
if (this.mesh.instanceCount > 0) {
|
|
49
|
-
const { array, itemSize } = this.mesh.propertyBuffers.builtin;
|
|
50
|
-
for (let i = 0; i < this.mesh.instanceCount; i++) {
|
|
51
|
-
array[i * itemSize + BUILTIN_OFFSET_AGE] += deltaTime;
|
|
52
|
-
}
|
|
53
|
-
this.mesh.removeDeadParticles();
|
|
54
|
-
}
|
|
55
|
-
if (this.emissionRate > 0) {
|
|
56
|
-
const emittedBefore = this.emissionElapsed;
|
|
57
|
-
this.emissionElapsed += deltaTime;
|
|
58
|
-
this.emissionAccumulator +=
|
|
59
|
-
this.emissionRate * (Math.min(this.emissionElapsed, this.emissionDuration) - emittedBefore);
|
|
60
|
-
const particlesToSpawn = Math.floor(this.emissionAccumulator);
|
|
61
|
-
if (particlesToSpawn > 0) {
|
|
62
|
-
this.burst(particlesToSpawn);
|
|
63
|
-
this.emissionAccumulator -= particlesToSpawn;
|
|
64
|
-
}
|
|
65
|
-
if (this.emissionElapsed >= this.emissionDuration) {
|
|
66
|
-
this.stop();
|
|
67
|
-
}
|
|
68
|
-
}
|
|
66
|
+
this.simulate(Math.min(rawDeltaTime, this.maxDeltaTimeInternal));
|
|
69
67
|
if (this.mesh.instanceCount === 0) {
|
|
70
68
|
return;
|
|
71
69
|
}
|
|
72
|
-
this.mesh.setOrigin(this.
|
|
73
|
-
|
|
74
|
-
const { propertyBuffers, instanceCount } = this.mesh;
|
|
75
|
-
for (let index = 0; index < this.behaviorSequence.length; index++) {
|
|
76
|
-
this.behaviorSequence[index].update(propertyBuffers, instanceCount, deltaTime, EMITTER_BEHAVIOR_SALT_BASE + index);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
const { builtin } = this.mesh.propertyBuffers;
|
|
80
|
-
const { array, itemSize } = builtin;
|
|
81
|
-
for (let i = 0; i < this.mesh.instanceCount; i++) {
|
|
82
|
-
const itemOffset = i * itemSize;
|
|
83
|
-
array[itemOffset + BUILTIN_OFFSET_POSITION_X] +=
|
|
84
|
-
array[itemOffset + BUILTIN_OFFSET_VELOCITY_X] * deltaTime;
|
|
85
|
-
array[itemOffset + BUILTIN_OFFSET_POSITION_Y] +=
|
|
86
|
-
array[itemOffset + BUILTIN_OFFSET_VELOCITY_Y] * deltaTime;
|
|
87
|
-
array[itemOffset + BUILTIN_OFFSET_ROTATION] +=
|
|
88
|
-
array[itemOffset + BUILTIN_OFFSET_TORQUE] * deltaTime;
|
|
89
|
-
}
|
|
90
|
-
builtin.needsUpdate = true;
|
|
70
|
+
this.mesh.setOrigin(this.originX, this.originY);
|
|
71
|
+
// The only upload of a frame: bursts and prewarm between frames are drawn by the next one.
|
|
91
72
|
this.mesh.limitUploadToLiveInstances();
|
|
92
73
|
};
|
|
93
74
|
const collectedProperties = {
|
|
@@ -103,10 +84,15 @@ export class UIEmitter extends UIAnchor {
|
|
|
103
84
|
collectProperties(collectedProperties, spawnSequence, "UIEmitter.constructor.spawnSequence");
|
|
104
85
|
collectProperties(collectedProperties, behaviorSequence, "UIEmitter.constructor.behaviorSequence");
|
|
105
86
|
collectProperties(collectedProperties, renderingSequence, "UIEmitter.constructor.renderingSequence");
|
|
87
|
+
this.blendModeInternal = options.blendMode ?? EMITTER_DEFAULT_BLEND_MODE;
|
|
106
88
|
const collectedUniforms = {
|
|
107
89
|
origin: { value: new Vector2(), glslTypeInfo: resolveGLSLTypeInfo("Vector2") },
|
|
90
|
+
blendFactor: {
|
|
91
|
+
value: blendModeToFactor(this.blendModeInternal),
|
|
92
|
+
glslTypeInfo: resolveGLSLTypeInfo("number"),
|
|
93
|
+
},
|
|
108
94
|
};
|
|
109
|
-
const renderingSources = collectRenderingUniforms(collectedUniforms, renderingSequence, "UIEmitter.constructor.renderingSequence");
|
|
95
|
+
const renderingSources = assignRenderingRandomValues(collectRenderingUniforms(collectedUniforms, renderingSequence, "UIEmitter.constructor.renderingSequence"), "UIEmitter.constructor.renderingSequence");
|
|
110
96
|
const zIndex = 0;
|
|
111
97
|
this.catcherHandler = this.layer.inputWrapper.createInputCatcher({
|
|
112
98
|
catchPointerDown: ignoreInput,
|
|
@@ -121,11 +107,21 @@ export class UIEmitter extends UIAnchor {
|
|
|
121
107
|
options.automaticallyDestroyModules ?? EMITTER_DEFAULT_AUTOMATICALLY_DESTROY_MODULES;
|
|
122
108
|
this.modeInternal = options.mode ?? EMITTER_DEFAULT_MODE;
|
|
123
109
|
this.mesh.visible = isUIModeVisible(this.modeInternal);
|
|
110
|
+
this.spaceInternal = options.space ?? EMITTER_DEFAULT_SPACE;
|
|
111
|
+
this.previousX = this.x;
|
|
112
|
+
this.previousY = this.y;
|
|
124
113
|
this.maxDeltaTimeInternal = options.maxDeltaTime ?? EMITTER_DEFAULT_MAX_DELTA_TIME;
|
|
125
114
|
assertValidPositiveNumber(this.maxDeltaTimeInternal, "UIEmitter.constructor.maxDeltaTime");
|
|
126
115
|
this.seedInternal = options.seed ?? Math.floor(Math.random() * 0x100000000);
|
|
127
116
|
assertValidNonNegativeInteger(this.seedInternal, "UIEmitter.constructor.seed");
|
|
128
117
|
}
|
|
118
|
+
/**
|
|
119
|
+
* Fires for every particle that dies, with its position in layer coordinates. Fires after the
|
|
120
|
+
* frame removed its dead particles, so a callback may spawn particles, also on this emitter.
|
|
121
|
+
*/
|
|
122
|
+
get signalParticleDied() {
|
|
123
|
+
return this.signalParticleDiedInternal;
|
|
124
|
+
}
|
|
129
125
|
/** Seed of the random values */
|
|
130
126
|
get seed() {
|
|
131
127
|
return this.seedInternal;
|
|
@@ -138,6 +134,14 @@ export class UIEmitter extends UIAnchor {
|
|
|
138
134
|
get mode() {
|
|
139
135
|
return this.modeInternal;
|
|
140
136
|
}
|
|
137
|
+
/** Color blending of the particles with what is drawn under them */
|
|
138
|
+
get blendMode() {
|
|
139
|
+
return this.blendModeInternal;
|
|
140
|
+
}
|
|
141
|
+
/** Coordinate space of particle positions */
|
|
142
|
+
get space() {
|
|
143
|
+
return this.spaceInternal;
|
|
144
|
+
}
|
|
141
145
|
/**
|
|
142
146
|
* Rendering order among the elements of the layer. Higher values on top; elements with equal
|
|
143
147
|
* values keep the order of creation, a later one on top.
|
|
@@ -145,6 +149,16 @@ export class UIEmitter extends UIAnchor {
|
|
|
145
149
|
get zIndex() {
|
|
146
150
|
return this.layer.inputWrapper.getZIndex(this.catcherHandler);
|
|
147
151
|
}
|
|
152
|
+
/**
|
|
153
|
+
* Layer point particle positions are relative to: the emitter in LOCAL space, where live
|
|
154
|
+
* particles move with it, the layer origin in WORLD space
|
|
155
|
+
*/
|
|
156
|
+
get originX() {
|
|
157
|
+
return this.spaceInternal === UIEmitterSpace.WORLD ? 0 : this.x;
|
|
158
|
+
}
|
|
159
|
+
get originY() {
|
|
160
|
+
return this.spaceInternal === UIEmitterSpace.WORLD ? 0 : this.y;
|
|
161
|
+
}
|
|
148
162
|
/** Visibility mode */
|
|
149
163
|
set mode(value) {
|
|
150
164
|
this.assertNotDestroyed("UIEmitter.mode");
|
|
@@ -153,6 +167,31 @@ export class UIEmitter extends UIAnchor {
|
|
|
153
167
|
this.mesh.visible = isUIModeVisible(value);
|
|
154
168
|
}
|
|
155
169
|
}
|
|
170
|
+
/** Color blending of the particles with what is drawn under them */
|
|
171
|
+
set blendMode(value) {
|
|
172
|
+
this.assertNotDestroyed("UIEmitter.blendMode");
|
|
173
|
+
this.blendModeInternal = value;
|
|
174
|
+
this.mesh.setBlendFactor(blendModeToFactor(value));
|
|
175
|
+
}
|
|
176
|
+
/** Coordinate space of particle positions. Live particles keep their place on the layer. */
|
|
177
|
+
set space(value) {
|
|
178
|
+
this.assertNotDestroyed("UIEmitter.space");
|
|
179
|
+
if (this.spaceInternal === value) {
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
const previousOriginX = this.originX;
|
|
183
|
+
const previousOriginY = this.originY;
|
|
184
|
+
this.spaceInternal = value;
|
|
185
|
+
const shiftX = previousOriginX - this.originX;
|
|
186
|
+
const shiftY = previousOriginY - this.originY;
|
|
187
|
+
const { builtin } = this.mesh.propertyBuffers;
|
|
188
|
+
const { array, itemSize } = builtin;
|
|
189
|
+
for (let i = 0; i < this.mesh.instanceCount; i++) {
|
|
190
|
+
array[i * itemSize + BUILTIN_OFFSET_POSITION_X] += shiftX;
|
|
191
|
+
array[i * itemSize + BUILTIN_OFFSET_POSITION_Y] += shiftY;
|
|
192
|
+
}
|
|
193
|
+
builtin.needsUpdate = true;
|
|
194
|
+
}
|
|
156
195
|
/** Longest frame step in seconds; longer frames are clamped */
|
|
157
196
|
set maxDeltaTime(value) {
|
|
158
197
|
this.assertNotDestroyed("UIEmitter.maxDeltaTime");
|
|
@@ -190,28 +229,40 @@ export class UIEmitter extends UIAnchor {
|
|
|
190
229
|
if (count === 0) {
|
|
191
230
|
return;
|
|
192
231
|
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
232
|
+
this.spawnParticles(count, 0, 0, this.setPointPath(this.x, this.y));
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Spawns particles immediately as if the emitter stood at a point, such as where a particle of
|
|
236
|
+
* another emitter died
|
|
237
|
+
*
|
|
238
|
+
* @param count - Number of particles to create, a non-negative integer
|
|
239
|
+
* @param x - Point in layer coordinates
|
|
240
|
+
* @param y - Point in layer coordinates
|
|
241
|
+
*/
|
|
242
|
+
burstAt(count, x, y) {
|
|
243
|
+
this.assertNotDestroyed("UIEmitter.burstAt");
|
|
244
|
+
assertValidNonNegativeInteger(count, "UIEmitter.burstAt.count");
|
|
245
|
+
assertValidNumber(x, "UIEmitter.burstAt.x");
|
|
246
|
+
assertValidNumber(y, "UIEmitter.burstAt.y");
|
|
247
|
+
if (count === 0) {
|
|
248
|
+
return;
|
|
210
249
|
}
|
|
211
|
-
|
|
212
|
-
|
|
250
|
+
this.spawnParticles(count, 0, 0, this.setPointPath(x, y));
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Runs the simulation ahead without drawing, so that an emission started with `play` shows
|
|
254
|
+
* its particles in full from the first frame. The emitter stays where it is meanwhile.
|
|
255
|
+
*
|
|
256
|
+
* @param duration - Seconds to simulate
|
|
257
|
+
* @param step - Simulation step in seconds; the last step is shorter if needed
|
|
258
|
+
*/
|
|
259
|
+
prewarm(duration, step = EMITTER_DEFAULT_PREWARM_STEP) {
|
|
260
|
+
this.assertNotDestroyed("UIEmitter.prewarm");
|
|
261
|
+
assertValidNonNegativeNumber(duration, "UIEmitter.prewarm.duration");
|
|
262
|
+
assertValidPositiveNumber(step, "UIEmitter.prewarm.step");
|
|
263
|
+
for (let elapsed = 0; elapsed < duration; elapsed += step) {
|
|
264
|
+
this.simulate(Math.min(step, duration - elapsed));
|
|
213
265
|
}
|
|
214
|
-
this.mesh.limitUploadToLiveInstances();
|
|
215
266
|
}
|
|
216
267
|
/** Removes all active particles */
|
|
217
268
|
clear() {
|
|
@@ -219,25 +270,21 @@ export class UIEmitter extends UIAnchor {
|
|
|
219
270
|
this.mesh.drop();
|
|
220
271
|
}
|
|
221
272
|
/**
|
|
222
|
-
* Starts
|
|
273
|
+
* Starts particle emission: a stream by time and by distance moved, and bursts. Particles due
|
|
274
|
+
* within a frame are spread over it.
|
|
223
275
|
*
|
|
224
276
|
* @param rate - Particles per second
|
|
225
|
-
* @param options -
|
|
277
|
+
* @param options - Duration, particles per distance and bursts
|
|
226
278
|
*/
|
|
227
279
|
play(rate, options = {}) {
|
|
228
280
|
this.assertNotDestroyed("UIEmitter.play");
|
|
229
|
-
this.
|
|
230
|
-
this.
|
|
231
|
-
this.emissionDuration = options.duration ?? Infinity;
|
|
232
|
-
this.emissionElapsed = 0;
|
|
281
|
+
this.emission.start(rate, options);
|
|
282
|
+
this.emissionStarted = true;
|
|
233
283
|
}
|
|
234
|
-
/** Stops
|
|
284
|
+
/** Stops particle emission; live particles play out */
|
|
235
285
|
stop() {
|
|
236
286
|
this.assertNotDestroyed("UIEmitter.stop");
|
|
237
|
-
this.
|
|
238
|
-
this.emissionAccumulator = 0;
|
|
239
|
-
this.emissionDuration = Infinity;
|
|
240
|
-
this.emissionElapsed = 0;
|
|
287
|
+
this.emission.stop();
|
|
241
288
|
}
|
|
242
289
|
/** Frees the particles and the input catcher, optionally destroys modules */
|
|
243
290
|
destroyInternal() {
|
|
@@ -258,4 +305,114 @@ export class UIEmitter extends UIAnchor {
|
|
|
258
305
|
}
|
|
259
306
|
super.destroyInternal();
|
|
260
307
|
}
|
|
308
|
+
/** Sets the point path to a point at the end of the last frame */
|
|
309
|
+
setPointPath(x, y) {
|
|
310
|
+
const path = this.pointPath;
|
|
311
|
+
path.time = 0;
|
|
312
|
+
path.fromX = path.toX = x;
|
|
313
|
+
path.fromY = path.toY = y;
|
|
314
|
+
return path;
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Spawns particles at moments `firstMoment + k * interval` seconds from the start of a frame.
|
|
318
|
+
* Spawn modules write a particle relative to the emitter; it is then placed at the point of the
|
|
319
|
+
* path at its moment and aged by the rest of the frame.
|
|
320
|
+
*/
|
|
321
|
+
spawnParticles(count, firstMoment, interval, path) {
|
|
322
|
+
const instanceBegin = this.mesh.instanceCount;
|
|
323
|
+
this.mesh.createInstances(count);
|
|
324
|
+
const instanceEnd = this.mesh.instanceCount;
|
|
325
|
+
// A slot may hold a dead particle's values.
|
|
326
|
+
this.mesh.resetInstances(instanceBegin, instanceEnd);
|
|
327
|
+
const { array, itemSize } = this.mesh.propertyBuffers.builtin;
|
|
328
|
+
for (let i = instanceBegin; i < instanceEnd; i++) {
|
|
329
|
+
const itemOffset = i * itemSize;
|
|
330
|
+
array[itemOffset + BUILTIN_OFFSET_SCALE_X] = 1;
|
|
331
|
+
array[itemOffset + BUILTIN_OFFSET_SCALE_Y] = 1;
|
|
332
|
+
array[itemOffset + BUILTIN_OFFSET_LIFETIME] = EMITTER_DEFAULT_LIFETIME;
|
|
333
|
+
writeParticleSeed(array, itemOffset, computeParticleSeed(this.seedInternal, this.spawnedCount++));
|
|
334
|
+
for (const { offset, stream } of SHADER_RANDOM_SLOTS) {
|
|
335
|
+
array[itemOffset + offset] = particleRandom(array, itemOffset, stream);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
for (let index = 0; index < this.spawnSequence.length; index++) {
|
|
339
|
+
this.spawnSequence[index].spawn(this.mesh.propertyBuffers, instanceBegin, instanceEnd, EMITTER_SPAWN_SALT_BASE + index);
|
|
340
|
+
}
|
|
341
|
+
const { time: frameTime, fromX, fromY, toX, toY } = path;
|
|
342
|
+
const { originX, originY } = this;
|
|
343
|
+
for (let i = instanceBegin; i < instanceEnd; i++) {
|
|
344
|
+
const itemOffset = i * itemSize;
|
|
345
|
+
// Rounding can put the last moment just past the frame, and the age below 0.
|
|
346
|
+
const moment = Math.min(firstMoment + (i - instanceBegin) * interval, frameTime);
|
|
347
|
+
const t = frameTime > 0 ? moment / frameTime : 1;
|
|
348
|
+
array[itemOffset + BUILTIN_OFFSET_POSITION_X] += fromX + (toX - fromX) * t - originX;
|
|
349
|
+
array[itemOffset + BUILTIN_OFFSET_POSITION_Y] += fromY + (toY - fromY) * t - originY;
|
|
350
|
+
// Moved back by its moment, the particle is advanced by the whole frame with the live
|
|
351
|
+
// ones and ends it at p + v * (frameTime - moment), with that age.
|
|
352
|
+
advanceParticle(array, itemOffset, -moment);
|
|
353
|
+
array[itemOffset + BUILTIN_OFFSET_AGE] = frameTime - moment;
|
|
354
|
+
}
|
|
355
|
+
this.mesh.propertyBuffers.builtin.needsUpdate = true;
|
|
356
|
+
}
|
|
357
|
+
/** Spawns the particles of the emission due within a frame of `deltaTime` seconds */
|
|
358
|
+
emit(deltaTime) {
|
|
359
|
+
if (!this.emission.isPlaying) {
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
const x = this.x;
|
|
363
|
+
const y = this.y;
|
|
364
|
+
const started = this.emissionStarted;
|
|
365
|
+
this.emissionStarted = false;
|
|
366
|
+
const path = this.framePath;
|
|
367
|
+
path.time = deltaTime;
|
|
368
|
+
path.toX = x;
|
|
369
|
+
path.toY = y;
|
|
370
|
+
// In LOCAL space live particles move with the emitter, so its path is not traced.
|
|
371
|
+
if (started || this.spaceInternal === UIEmitterSpace.LOCAL) {
|
|
372
|
+
path.fromX = x;
|
|
373
|
+
path.fromY = y;
|
|
374
|
+
}
|
|
375
|
+
else {
|
|
376
|
+
path.fromX = this.previousX;
|
|
377
|
+
path.fromY = this.previousY;
|
|
378
|
+
}
|
|
379
|
+
const distance = started ? 0 : Math.hypot(x - this.previousX, y - this.previousY);
|
|
380
|
+
this.emission.advance(deltaTime, distance, this.spawnDue);
|
|
381
|
+
}
|
|
382
|
+
/** Removes the dead particles and reports them through the signal */
|
|
383
|
+
removeDeadParticles() {
|
|
384
|
+
const positions = this.deadPositions;
|
|
385
|
+
positions.length = 0;
|
|
386
|
+
this.mesh.removeDeadParticles(this.collectDeadParticle);
|
|
387
|
+
// After the removal: a callback may spawn particles, which would disturb it.
|
|
388
|
+
for (let i = 0; i < positions.length; i += 2) {
|
|
389
|
+
this.signalParticleDiedInternal.emit(positions[i], positions[i + 1]);
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
/** Advances the particles and the emission by `deltaTime` seconds */
|
|
393
|
+
simulate(deltaTime) {
|
|
394
|
+
if (this.mesh.instanceCount > 0) {
|
|
395
|
+
const { array, itemSize } = this.mesh.propertyBuffers.builtin;
|
|
396
|
+
for (let i = 0; i < this.mesh.instanceCount; i++) {
|
|
397
|
+
array[i * itemSize + BUILTIN_OFFSET_AGE] += deltaTime;
|
|
398
|
+
}
|
|
399
|
+
this.removeDeadParticles();
|
|
400
|
+
}
|
|
401
|
+
this.emit(deltaTime);
|
|
402
|
+
this.previousX = this.x;
|
|
403
|
+
this.previousY = this.y;
|
|
404
|
+
const { propertyBuffers, instanceCount } = this.mesh;
|
|
405
|
+
if (instanceCount === 0) {
|
|
406
|
+
return;
|
|
407
|
+
}
|
|
408
|
+
for (let index = 0; index < this.behaviorSequence.length; index++) {
|
|
409
|
+
this.behaviorSequence[index].update(propertyBuffers, instanceCount, deltaTime, EMITTER_BEHAVIOR_SALT_BASE + index);
|
|
410
|
+
}
|
|
411
|
+
const { builtin } = propertyBuffers;
|
|
412
|
+
const { array, itemSize } = builtin;
|
|
413
|
+
for (let i = 0; i < instanceCount; i++) {
|
|
414
|
+
advanceParticle(array, i * itemSize, deltaTime);
|
|
415
|
+
}
|
|
416
|
+
builtin.needsUpdate = true;
|
|
417
|
+
}
|
|
261
418
|
}
|
|
@@ -1,23 +1,35 @@
|
|
|
1
|
+
export { UIBehaviorAlignToVelocity } from "./behaviorModules/UIBehaviorAlignToVelocity.js";
|
|
2
|
+
export { UIBehaviorBounce } from "./behaviorModules/UIBehaviorBounce.js";
|
|
1
3
|
export { UIBehaviorDirectionalGravity } from "./behaviorModules/UIBehaviorDirectionalGravity.js";
|
|
2
4
|
export { UIBehaviorModule } from "./behaviorModules/UIBehaviorModule.js";
|
|
5
|
+
export { UIBehaviorOrbit } from "./behaviorModules/UIBehaviorOrbit.js";
|
|
3
6
|
export { UIBehaviorPointGravity } from "./behaviorModules/UIBehaviorPointGravity.js";
|
|
4
7
|
export type { UIScaleOscillationAxis } from "./behaviorModules/UIBehaviorScaleOscillation.js";
|
|
5
8
|
export { UIBehaviorScaleOscillation } from "./behaviorModules/UIBehaviorScaleOscillation.js";
|
|
6
9
|
export { UIBehaviorScaleOverLife } from "./behaviorModules/UIBehaviorScaleOverLife.js";
|
|
10
|
+
export { UIBehaviorSeek } from "./behaviorModules/UIBehaviorSeek.js";
|
|
7
11
|
export { UIBehaviorTorqueDamping } from "./behaviorModules/UIBehaviorTorqueDamping.js";
|
|
8
12
|
export { UIBehaviorTorqueNoise } from "./behaviorModules/UIBehaviorTorqueNoise.js";
|
|
9
13
|
export { UIBehaviorVelocityDamping } from "./behaviorModules/UIBehaviorVelocityDamping.js";
|
|
10
14
|
export { UIBehaviorVelocityNoise } from "./behaviorModules/UIBehaviorVelocityNoise.js";
|
|
11
15
|
export type { UIEmitterMode, UIEmitterOptions, UIEmitterPlayOptions, } from "./elements/UIEmitter.Internal.js";
|
|
16
|
+
export { UIEmitterSpace } from "./elements/UIEmitter.Internal.js";
|
|
12
17
|
export { UIEmitter } from "./elements/UIEmitter.js";
|
|
13
18
|
export type { UIAspectConfig, UIRange, UIRangeConfig, UIVector2Config, } from "./miscellaneous/miscellaneous.js";
|
|
14
|
-
export { particleRandom, particleRandomStream } from "./miscellaneous/miscellaneous.js";
|
|
19
|
+
export { particleRandom, particleRandomStream, UIEasing } from "./miscellaneous/miscellaneous.js";
|
|
15
20
|
export { UIRenderingColorOverLife } from "./renderingModules/UIRenderingColorOverLife.js";
|
|
16
21
|
export { UIRenderingColorOverVelocity } from "./renderingModules/UIRenderingColorOverVelocity.js";
|
|
22
|
+
export type { UIRenderingFlipbookOptions } from "./renderingModules/UIRenderingFlipbook.js";
|
|
23
|
+
export { UIFlipbookMode, UIRenderingFlipbook } from "./renderingModules/UIRenderingFlipbook.js";
|
|
17
24
|
export { UIRenderingModule } from "./renderingModules/UIRenderingModule.js";
|
|
25
|
+
export { UIRenderingRandomColor } from "./renderingModules/UIRenderingRandomColor.js";
|
|
26
|
+
export type { UIRenderingShapeOptions } from "./renderingModules/UIRenderingShape.js";
|
|
27
|
+
export { UIParticleShape, UIRenderingShape } from "./renderingModules/UIRenderingShape.js";
|
|
18
28
|
export { UIRenderingTexture } from "./renderingModules/UIRenderingTexture.js";
|
|
29
|
+
export { UICircleDistribution, UISpawnCircle } from "./spawnModules/UISpawnCircle.js";
|
|
19
30
|
export { UISpawnModule } from "./spawnModules/UISpawnModule.js";
|
|
20
31
|
export { UISpawnOffset } from "./spawnModules/UISpawnOffset.js";
|
|
32
|
+
export { UISpawnRadialVelocity } from "./spawnModules/UISpawnRadialVelocity.js";
|
|
21
33
|
export { UISpawnRandomLifetime } from "./spawnModules/UISpawnRandomLifetime.js";
|
|
22
34
|
export { UISpawnRandomRotation } from "./spawnModules/UISpawnRandomRotation.js";
|
|
23
35
|
export { UISpawnRandomScale } from "./spawnModules/UISpawnRandomScale.js";
|
package/dist/particles/index.js
CHANGED
|
@@ -1,20 +1,30 @@
|
|
|
1
|
+
export { UIBehaviorAlignToVelocity } from "./behaviorModules/UIBehaviorAlignToVelocity.js";
|
|
2
|
+
export { UIBehaviorBounce } from "./behaviorModules/UIBehaviorBounce.js";
|
|
1
3
|
export { UIBehaviorDirectionalGravity } from "./behaviorModules/UIBehaviorDirectionalGravity.js";
|
|
2
4
|
export { UIBehaviorModule } from "./behaviorModules/UIBehaviorModule.js";
|
|
5
|
+
export { UIBehaviorOrbit } from "./behaviorModules/UIBehaviorOrbit.js";
|
|
3
6
|
export { UIBehaviorPointGravity } from "./behaviorModules/UIBehaviorPointGravity.js";
|
|
4
7
|
export { UIBehaviorScaleOscillation } from "./behaviorModules/UIBehaviorScaleOscillation.js";
|
|
5
8
|
export { UIBehaviorScaleOverLife } from "./behaviorModules/UIBehaviorScaleOverLife.js";
|
|
9
|
+
export { UIBehaviorSeek } from "./behaviorModules/UIBehaviorSeek.js";
|
|
6
10
|
export { UIBehaviorTorqueDamping } from "./behaviorModules/UIBehaviorTorqueDamping.js";
|
|
7
11
|
export { UIBehaviorTorqueNoise } from "./behaviorModules/UIBehaviorTorqueNoise.js";
|
|
8
12
|
export { UIBehaviorVelocityDamping } from "./behaviorModules/UIBehaviorVelocityDamping.js";
|
|
9
13
|
export { UIBehaviorVelocityNoise } from "./behaviorModules/UIBehaviorVelocityNoise.js";
|
|
14
|
+
export { UIEmitterSpace } from "./elements/UIEmitter.Internal.js";
|
|
10
15
|
export { UIEmitter } from "./elements/UIEmitter.js";
|
|
11
|
-
export { particleRandom, particleRandomStream } from "./miscellaneous/miscellaneous.js";
|
|
16
|
+
export { particleRandom, particleRandomStream, UIEasing } from "./miscellaneous/miscellaneous.js";
|
|
12
17
|
export { UIRenderingColorOverLife } from "./renderingModules/UIRenderingColorOverLife.js";
|
|
13
18
|
export { UIRenderingColorOverVelocity } from "./renderingModules/UIRenderingColorOverVelocity.js";
|
|
19
|
+
export { UIFlipbookMode, UIRenderingFlipbook } from "./renderingModules/UIRenderingFlipbook.js";
|
|
14
20
|
export { UIRenderingModule } from "./renderingModules/UIRenderingModule.js";
|
|
21
|
+
export { UIRenderingRandomColor } from "./renderingModules/UIRenderingRandomColor.js";
|
|
22
|
+
export { UIParticleShape, UIRenderingShape } from "./renderingModules/UIRenderingShape.js";
|
|
15
23
|
export { UIRenderingTexture } from "./renderingModules/UIRenderingTexture.js";
|
|
24
|
+
export { UICircleDistribution, UISpawnCircle } from "./spawnModules/UISpawnCircle.js";
|
|
16
25
|
export { UISpawnModule } from "./spawnModules/UISpawnModule.js";
|
|
17
26
|
export { UISpawnOffset } from "./spawnModules/UISpawnOffset.js";
|
|
27
|
+
export { UISpawnRadialVelocity } from "./spawnModules/UISpawnRadialVelocity.js";
|
|
18
28
|
export { UISpawnRandomLifetime } from "./spawnModules/UISpawnRandomLifetime.js";
|
|
19
29
|
export { UISpawnRandomRotation } from "./spawnModules/UISpawnRandomRotation.js";
|
|
20
30
|
export { UISpawnRandomScale } from "./spawnModules/UISpawnRandomScale.js";
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { InstancedBufferGeometry, ShaderMaterial } from "three";
|
|
2
2
|
import type { GLProperty, GLTypeInfo, UIProperty, UIPropertyName } from "../../core/miscellaneous/generic-plane/shared.js";
|
|
3
3
|
export declare const INSTANCED_PARTICLE_GEOMETRY: InstancedBufferGeometry;
|
|
4
|
+
/**
|
|
5
|
+
* Gives each rendering module that reads `PARTICLE_RANDOM` a random value of its own, the next of
|
|
6
|
+
* `PARTICLE_RANDOM_A`-`E` in module order, so two modules do not pick alike
|
|
7
|
+
* @returns Sources with `PARTICLE_RANDOM` renamed accordingly
|
|
8
|
+
*/
|
|
9
|
+
export declare function assignRenderingRandomValues(sources: string[], debugContext: string): string[];
|
|
4
10
|
export declare function collectProperties(keeper: Record<string, GLTypeInfo>, modules: readonly {
|
|
5
11
|
requiredProperties?: Record<string, UIPropertyName>;
|
|
6
12
|
}[], debugContext: string): void;
|
|
@@ -34,6 +34,31 @@ const PARTICLE_BUILTIN_MACROS = [
|
|
|
34
34
|
["PARTICLE_RANDOM_E", BUILTIN_OFFSET_RANDOM_E],
|
|
35
35
|
["PARTICLE_RANDOM_F", BUILTIN_OFFSET_RANDOM_F],
|
|
36
36
|
];
|
|
37
|
+
/** Builtin random values handed out to rendering modules that read `PARTICLE_RANDOM`, in order */
|
|
38
|
+
const RENDERING_RANDOM_MACROS = [
|
|
39
|
+
"PARTICLE_RANDOM_A",
|
|
40
|
+
"PARTICLE_RANDOM_B",
|
|
41
|
+
"PARTICLE_RANDOM_C",
|
|
42
|
+
"PARTICLE_RANDOM_D",
|
|
43
|
+
"PARTICLE_RANDOM_E",
|
|
44
|
+
];
|
|
45
|
+
/**
|
|
46
|
+
* Gives each rendering module that reads `PARTICLE_RANDOM` a random value of its own, the next of
|
|
47
|
+
* `PARTICLE_RANDOM_A`-`E` in module order, so two modules do not pick alike
|
|
48
|
+
* @returns Sources with `PARTICLE_RANDOM` renamed accordingly
|
|
49
|
+
*/
|
|
50
|
+
export function assignRenderingRandomValues(sources, debugContext) {
|
|
51
|
+
let next = 0;
|
|
52
|
+
return sources.map((source, index) => {
|
|
53
|
+
if (!isIdentifierReferenced(source, "PARTICLE_RANDOM")) {
|
|
54
|
+
return source;
|
|
55
|
+
}
|
|
56
|
+
if (next === RENDERING_RANDOM_MACROS.length) {
|
|
57
|
+
throw new Error(`${debugContext}[${index}]: more than ${RENDERING_RANDOM_MACROS.length} rendering modules read PARTICLE_RANDOM`);
|
|
58
|
+
}
|
|
59
|
+
return source.replace(/\bPARTICLE_RANDOM\b/g, RENDERING_RANDOM_MACROS[next++]);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
37
62
|
export function collectProperties(keeper, modules, debugContext) {
|
|
38
63
|
for (const module of modules) {
|
|
39
64
|
if (module.requiredProperties === undefined) {
|
|
@@ -163,6 +188,7 @@ export function buildParticleFragmentShader(uniformDeclarations, fieldDeclaratio
|
|
|
163
188
|
discard;
|
|
164
189
|
}
|
|
165
190
|
gl_FragColor = linearToOutputTexel(diffuseColor);
|
|
191
|
+
gl_FragColor = vec4(gl_FragColor.rgb * gl_FragColor.a, gl_FragColor.a * p_blendFactor);
|
|
166
192
|
}
|
|
167
193
|
`;
|
|
168
194
|
}
|
|
@@ -239,6 +265,7 @@ export function buildParticleMaterial(sources, uniformProperties, varyingPropert
|
|
|
239
265
|
forceSinglePass: true,
|
|
240
266
|
depthWrite: false,
|
|
241
267
|
depthTest: true,
|
|
268
|
+
premultipliedAlpha: true,
|
|
242
269
|
});
|
|
243
270
|
return { material, varyingRowCount: packed.rowCount };
|
|
244
271
|
}
|
|
@@ -20,7 +20,13 @@ export declare class UIInstancedParticle extends Mesh {
|
|
|
20
20
|
*/
|
|
21
21
|
limitUploadToLiveInstances(): void;
|
|
22
22
|
setOrigin(x: number, y: number): void;
|
|
23
|
-
|
|
23
|
+
/** Output-alpha multiplier of the premultiplied shader, see `blendModeToFactor` */
|
|
24
|
+
setBlendFactor(value: number): void;
|
|
25
|
+
/**
|
|
26
|
+
* Removes the particles whose age reached their lifetime, keeping the order of the others
|
|
27
|
+
* @param onDead Called for each dead particle before its slot is reused
|
|
28
|
+
*/
|
|
29
|
+
removeDeadParticles(onDead: (builtinArray: ArrayLike<number>, itemOffset: number) => void): void;
|
|
24
30
|
drop(): void;
|
|
25
31
|
destroy(): void;
|
|
26
32
|
private ensureCapacity;
|
|
@@ -81,7 +81,15 @@ export class UIInstancedParticle extends Mesh {
|
|
|
81
81
|
const uniform = resolvePropertyUniform("origin", this.shaderMaterial);
|
|
82
82
|
uniform.value.set(x, y);
|
|
83
83
|
}
|
|
84
|
-
|
|
84
|
+
/** Output-alpha multiplier of the premultiplied shader, see `blendModeToFactor` */
|
|
85
|
+
setBlendFactor(value) {
|
|
86
|
+
resolvePropertyUniform("blendFactor", this.shaderMaterial).value = value;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Removes the particles whose age reached their lifetime, keeping the order of the others
|
|
90
|
+
* @param onDead Called for each dead particle before its slot is reused
|
|
91
|
+
*/
|
|
92
|
+
removeDeadParticles(onDead) {
|
|
85
93
|
const builtinBuffer = this.propertyBuffers.builtin;
|
|
86
94
|
if (builtinBuffer === undefined) {
|
|
87
95
|
return;
|
|
@@ -104,6 +112,9 @@ export class UIInstancedParticle extends Mesh {
|
|
|
104
112
|
}
|
|
105
113
|
writeIndex++;
|
|
106
114
|
}
|
|
115
|
+
else {
|
|
116
|
+
onDead(builtinArray, offset);
|
|
117
|
+
}
|
|
107
118
|
}
|
|
108
119
|
this.instancedGeometry.instanceCount = writeIndex;
|
|
109
120
|
}
|
|
@@ -11,8 +11,30 @@ export interface UIRange {
|
|
|
11
11
|
export type UIRangeConfig = UIRange | [number, number] | number;
|
|
12
12
|
export type UIVector2Config = Vector2Like | Vector2Tuple | number;
|
|
13
13
|
export type UIAspectConfig = number | UITextureConfig;
|
|
14
|
+
/** Easing of an interpolation between two values */
|
|
15
|
+
export declare enum UIEasing {
|
|
16
|
+
/** Constant rate */
|
|
17
|
+
LINEAR = 0,
|
|
18
|
+
/** Starts slow, quadratic */
|
|
19
|
+
IN = 1,
|
|
20
|
+
/** Ends slow, quadratic */
|
|
21
|
+
OUT = 2,
|
|
22
|
+
/** Starts and ends slow, smoothstep */
|
|
23
|
+
IN_OUT = 3
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Eases an interpolation factor
|
|
27
|
+
* @param t Factor in [0, 1]
|
|
28
|
+
* @returns Eased factor, 0 at t = 0 and 1 at t = 1
|
|
29
|
+
*/
|
|
30
|
+
export declare function applyEasing(easing: UIEasing, t: number): number;
|
|
14
31
|
/** Formats a number as a GLSL float literal */
|
|
15
32
|
export declare function toGLSLFloat(value: number): string;
|
|
33
|
+
/**
|
|
34
|
+
* GLSL expression of a whole float in [0, count) from a fraction in [0, 1]: the index of the cell
|
|
35
|
+
* the fraction falls in, the last cell taking 1
|
|
36
|
+
*/
|
|
37
|
+
export declare function buildIndexExpression(fraction: string, count: number): string;
|
|
16
38
|
/** GLSL expression of the u that samples a gradient texture of `size` texels at t in [0, 1] */
|
|
17
39
|
export declare function buildGradientCoordinate(t: string, size: number): string;
|
|
18
40
|
export declare function resolveUIRangeConfig(config: UIRangeConfig): UIRange;
|