@zaisma/effects 1.0.0 → 1.1.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/batches/chunks.js +45 -45
- package/batches/marks.js +15 -15
- package/batches/ribbons.js +33 -33
- package/batches/shared.js +1 -1
- package/batches/sprites.js +47 -47
- package/batches/warps.js +18 -18
- package/budget.js +17 -17
- package/debris.js +33 -33
- package/emit.js +35 -35
- package/flashes.js +7 -7
- package/format.js +39 -39
- package/index.d.ts +5 -5
- package/index.js +75 -73
- package/looks.js +3 -3
- package/motion.js +23 -23
- package/package.json +1 -1
- package/partners.js +30 -30
- package/piece.json +3 -3
- package/piece.json.js +3 -3
- package/shapes.js +5 -5
- package/sync.js +113 -113
- package/tables.js +20 -20
- package/weather.js +17 -17
package/batches/chunks.js
CHANGED
|
@@ -13,7 +13,7 @@ import { ELEMENT_ROW } from "./sprites.js";
|
|
|
13
13
|
import { SHARED_VERTEX_GLSL, fogUniforms } from "./shared.js";
|
|
14
14
|
|
|
15
15
|
const CORNER_COUNT = 60;
|
|
16
|
-
const
|
|
16
|
+
const FLOAT_COUNT_PER_CHUNK = 12;
|
|
17
17
|
|
|
18
18
|
function makeShapeTable() {
|
|
19
19
|
const solids = {
|
|
@@ -32,15 +32,15 @@ function makeShapeTable() {
|
|
|
32
32
|
CHUNK_SHAPE_NAMES.forEach((shapeName, shapeIndex) => {
|
|
33
33
|
const flat = solids[shapeName].index ? solids[shapeName].toNonIndexed() : solids[shapeName];
|
|
34
34
|
const positions = flat.getAttribute("position");
|
|
35
|
-
for (let
|
|
36
|
-
first.fromBufferAttribute(positions,
|
|
37
|
-
second.fromBufferAttribute(positions,
|
|
38
|
-
third.fromBufferAttribute(positions,
|
|
35
|
+
for (let cornerIndex = 0; cornerIndex < Math.min(positions.count, CORNER_COUNT); cornerIndex += 3) {
|
|
36
|
+
first.fromBufferAttribute(positions, cornerIndex);
|
|
37
|
+
second.fromBufferAttribute(positions, cornerIndex + 1);
|
|
38
|
+
third.fromBufferAttribute(positions, cornerIndex + 2);
|
|
39
39
|
normal.subVectors(second, first).cross(third.clone().sub(first)).normalize();
|
|
40
|
-
[first, second, third].forEach((point,
|
|
41
|
-
const
|
|
42
|
-
values.set([point.x, point.y, point.z, 1],
|
|
43
|
-
values.set([normal.x, normal.y, normal.z, 0],
|
|
40
|
+
[first, second, third].forEach((point, pointIndex) => {
|
|
41
|
+
const placeIndex = (shapeIndex * 2 * CORNER_COUNT + cornerIndex + pointIndex) * 4;
|
|
42
|
+
values.set([point.x, point.y, point.z, 1], placeIndex);
|
|
43
|
+
values.set([normal.x, normal.y, normal.z, 0], placeIndex + CORNER_COUNT * 4);
|
|
44
44
|
});
|
|
45
45
|
}
|
|
46
46
|
solids[shapeName].dispose();
|
|
@@ -156,8 +156,8 @@ void main() {
|
|
|
156
156
|
|
|
157
157
|
/** Makes the batch. Answers { mesh, takeSlab, giveSlab, write, rewrite, update, liveCount, capacity, dispose }. */
|
|
158
158
|
export function createChunkBatch({ chunkCount, sharedUniforms }) {
|
|
159
|
-
const values = new Float32Array(chunkCount *
|
|
160
|
-
const buffer = new THREE.InstancedInterleavedBuffer(values,
|
|
159
|
+
const values = new Float32Array(chunkCount * FLOAT_COUNT_PER_CHUNK);
|
|
160
|
+
const buffer = new THREE.InstancedInterleavedBuffer(values, FLOAT_COUNT_PER_CHUNK);
|
|
161
161
|
buffer.setUsage(THREE.DynamicDrawUsage);
|
|
162
162
|
const geometry = new THREE.InstancedBufferGeometry();
|
|
163
163
|
// Sixty corners with nothing of their own: each reads its place from the shape table by its number.
|
|
@@ -183,46 +183,46 @@ export function createChunkBatch({ chunkCount, sharedUniforms }) {
|
|
|
183
183
|
const pool = createSlotPool(chunkCount);
|
|
184
184
|
const endSec = new Float32Array(chunkCount);
|
|
185
185
|
const slabs = new Set();
|
|
186
|
-
let
|
|
187
|
-
let
|
|
186
|
+
let dirtyStartIndex = Infinity;
|
|
187
|
+
let dirtyEndIndex = -1;
|
|
188
188
|
let liveCount = 0;
|
|
189
189
|
|
|
190
|
-
function markDirty(chunkIndex,
|
|
191
|
-
|
|
192
|
-
|
|
190
|
+
function markDirty(chunkIndex, dirtyCount) {
|
|
191
|
+
dirtyStartIndex = Math.min(dirtyStartIndex, chunkIndex);
|
|
192
|
+
dirtyEndIndex = Math.max(dirtyEndIndex, chunkIndex + dirtyCount);
|
|
193
193
|
}
|
|
194
194
|
|
|
195
195
|
function takeSlab(wantedCount, owner) {
|
|
196
|
-
const
|
|
197
|
-
if (
|
|
198
|
-
const slab = { start: pool.take(
|
|
196
|
+
const takenCount = Math.min(wantedCount, pool.longestFreeCount());
|
|
197
|
+
if (takenCount <= 0) return null;
|
|
198
|
+
const slab = { start: pool.take(takenCount), capacity: takenCount, nextOffset: 0, liveCount: 0, lastEndSec: 0, owner };
|
|
199
199
|
slabs.add(slab);
|
|
200
200
|
return slab;
|
|
201
201
|
}
|
|
202
202
|
|
|
203
203
|
function giveSlab(slab) {
|
|
204
204
|
if (!slabs.delete(slab)) return;
|
|
205
|
-
const
|
|
206
|
-
values.fill(0,
|
|
207
|
-
for (let
|
|
205
|
+
const fromIndex = slab.start * FLOAT_COUNT_PER_CHUNK;
|
|
206
|
+
values.fill(0, fromIndex, fromIndex + slab.capacity * FLOAT_COUNT_PER_CHUNK);
|
|
207
|
+
for (let slotIndex = 0; slotIndex < slab.capacity; slotIndex += 1) values[fromIndex + slotIndex * FLOAT_COUNT_PER_CHUNK + 3] = 1e9;
|
|
208
208
|
markDirty(slab.start, slab.capacity);
|
|
209
209
|
pool.give(slab.start, slab.capacity);
|
|
210
210
|
}
|
|
211
211
|
|
|
212
212
|
function writeAt(chunkIndex, x, y, z, velocityX, velocityY, velocityZ, birthSec, lifeSec, seedNumber, elementRow, playRow, angleRad) {
|
|
213
|
-
const
|
|
214
|
-
values[
|
|
215
|
-
values[
|
|
216
|
-
values[
|
|
217
|
-
values[
|
|
218
|
-
values[
|
|
219
|
-
values[
|
|
220
|
-
values[
|
|
221
|
-
values[
|
|
222
|
-
values[
|
|
223
|
-
values[
|
|
224
|
-
values[
|
|
225
|
-
values[
|
|
213
|
+
const floatIndex = chunkIndex * FLOAT_COUNT_PER_CHUNK;
|
|
214
|
+
values[floatIndex] = x;
|
|
215
|
+
values[floatIndex + 1] = y;
|
|
216
|
+
values[floatIndex + 2] = z;
|
|
217
|
+
values[floatIndex + 3] = birthSec;
|
|
218
|
+
values[floatIndex + 4] = velocityX;
|
|
219
|
+
values[floatIndex + 5] = velocityY;
|
|
220
|
+
values[floatIndex + 6] = velocityZ;
|
|
221
|
+
values[floatIndex + 7] = lifeSec;
|
|
222
|
+
values[floatIndex + 8] = seedNumber;
|
|
223
|
+
values[floatIndex + 9] = elementRow;
|
|
224
|
+
values[floatIndex + 10] = playRow;
|
|
225
|
+
values[floatIndex + 11] = angleRad;
|
|
226
226
|
endSec[chunkIndex] = birthSec + lifeSec;
|
|
227
227
|
markDirty(chunkIndex, 1);
|
|
228
228
|
}
|
|
@@ -242,27 +242,27 @@ export function createChunkBatch({ chunkCount, sharedUniforms }) {
|
|
|
242
242
|
}
|
|
243
243
|
|
|
244
244
|
function update(nowSec) {
|
|
245
|
-
let
|
|
245
|
+
let highestEndIndex = 0;
|
|
246
246
|
liveCount = 0;
|
|
247
247
|
for (const slab of slabs) {
|
|
248
248
|
if (slab.lastEndSec <= nowSec) continue;
|
|
249
|
-
|
|
250
|
-
for (let
|
|
249
|
+
highestEndIndex = Math.max(highestEndIndex, slab.start + slab.capacity);
|
|
250
|
+
for (let slotIndex = 0; slotIndex < slab.capacity; slotIndex += 1) if (endSec[slab.start + slotIndex] > nowSec) liveCount += 1;
|
|
251
251
|
}
|
|
252
|
-
geometry.instanceCount =
|
|
253
|
-
mesh.visible =
|
|
254
|
-
if (
|
|
252
|
+
geometry.instanceCount = highestEndIndex;
|
|
253
|
+
mesh.visible = highestEndIndex > 0;
|
|
254
|
+
if (dirtyEndIndex > dirtyStartIndex) {
|
|
255
255
|
buffer.clearUpdateRanges();
|
|
256
|
-
buffer.addUpdateRange(
|
|
256
|
+
buffer.addUpdateRange(dirtyStartIndex * FLOAT_COUNT_PER_CHUNK, (dirtyEndIndex - dirtyStartIndex) * FLOAT_COUNT_PER_CHUNK);
|
|
257
257
|
buffer.needsUpdate = true;
|
|
258
|
-
|
|
259
|
-
|
|
258
|
+
dirtyStartIndex = Infinity;
|
|
259
|
+
dirtyEndIndex = -1;
|
|
260
260
|
}
|
|
261
261
|
}
|
|
262
262
|
|
|
263
263
|
/** Moves every time written here back by a span, as the effects' clock starts over: see index.js. */
|
|
264
264
|
function shiftTime(spanSec) {
|
|
265
|
-
for (let
|
|
265
|
+
for (let floatIndex = 3; floatIndex < values.length; floatIndex += FLOAT_COUNT_PER_CHUNK) values[floatIndex] -= spanSec;
|
|
266
266
|
for (let index = 0; index < endSec.length; index += 1) endSec[index] -= spanSec;
|
|
267
267
|
for (const slab of slabs) slab.lastEndSec -= spanSec;
|
|
268
268
|
markDirty(0, chunkCount);
|
package/batches/marks.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import * as THREE from "three";
|
|
5
5
|
import { BLEND_END_GLSL, ONE_BLEND, SHARED_VERTEX_GLSL, fogUniforms } from "./shared.js";
|
|
6
6
|
|
|
7
|
-
const
|
|
7
|
+
const FLOAT_COUNT_PER_MARK = 20;
|
|
8
8
|
|
|
9
9
|
const MARK_VERTEX = /* glsl */ `
|
|
10
10
|
attribute vec4 aPlace;
|
|
@@ -65,15 +65,15 @@ export function createMarkBatch({ markCount, sharedUniforms }) {
|
|
|
65
65
|
geometry.setIndex([0, 1, 2, 2, 1, 3]);
|
|
66
66
|
let values;
|
|
67
67
|
let buffer;
|
|
68
|
-
let
|
|
68
|
+
let capacityCount = 0;
|
|
69
69
|
let nextIndex = 0;
|
|
70
70
|
let writtenCount = 0;
|
|
71
71
|
const endSec = [];
|
|
72
72
|
|
|
73
73
|
function setCapacity(newCapacity) {
|
|
74
|
-
|
|
75
|
-
values = new Float32Array(Math.max(
|
|
76
|
-
buffer = new THREE.InstancedInterleavedBuffer(values,
|
|
74
|
+
capacityCount = newCapacity;
|
|
75
|
+
values = new Float32Array(Math.max(capacityCount, 1) * FLOAT_COUNT_PER_MARK);
|
|
76
|
+
buffer = new THREE.InstancedInterleavedBuffer(values, FLOAT_COUNT_PER_MARK);
|
|
77
77
|
buffer.setUsage(THREE.DynamicDrawUsage);
|
|
78
78
|
["aPlace", "aFacing", "aLife", "aTint", "aGlow"].forEach((name, index) => geometry.setAttribute(name, new THREE.InterleavedBufferAttribute(buffer, 4, index * 4)));
|
|
79
79
|
nextIndex = 0;
|
|
@@ -105,14 +105,14 @@ export function createMarkBatch({ markCount, sharedUniforms }) {
|
|
|
105
105
|
* opacityShare, glowColor: Color, glowDurationSec }.
|
|
106
106
|
*/
|
|
107
107
|
function add(mark) {
|
|
108
|
-
if (
|
|
109
|
-
const
|
|
110
|
-
values.set([mark.x, mark.y, mark.z, mark.sizeM, mark.normalX, mark.normalY, mark.normalZ, mark.turnRad, mark.birthSec, mark.lifeSec, mark.cellU, mark.cellV, mark.color.r, mark.color.g, mark.color.b, mark.opacityShare, mark.glowColor.r, mark.glowColor.g, mark.glowColor.b, mark.glowDurationSec],
|
|
108
|
+
if (capacityCount === 0) return;
|
|
109
|
+
const floatIndex = nextIndex * FLOAT_COUNT_PER_MARK;
|
|
110
|
+
values.set([mark.x, mark.y, mark.z, mark.sizeM, mark.normalX, mark.normalY, mark.normalZ, mark.turnRad, mark.birthSec, mark.lifeSec, mark.cellU, mark.cellV, mark.color.r, mark.color.g, mark.color.b, mark.opacityShare, mark.glowColor.r, mark.glowColor.g, mark.glowColor.b, mark.glowDurationSec], floatIndex);
|
|
111
111
|
endSec[nextIndex] = mark.birthSec + mark.lifeSec;
|
|
112
|
-
buffer.addUpdateRange(
|
|
112
|
+
buffer.addUpdateRange(floatIndex, FLOAT_COUNT_PER_MARK);
|
|
113
113
|
buffer.needsUpdate = true;
|
|
114
|
-
nextIndex = (nextIndex + 1) %
|
|
115
|
-
writtenCount = Math.min(writtenCount + 1,
|
|
114
|
+
nextIndex = (nextIndex + 1) % capacityCount;
|
|
115
|
+
writtenCount = Math.min(writtenCount + 1, capacityCount);
|
|
116
116
|
geometry.instanceCount = writtenCount;
|
|
117
117
|
}
|
|
118
118
|
|
|
@@ -126,12 +126,12 @@ export function createMarkBatch({ markCount, sharedUniforms }) {
|
|
|
126
126
|
/** Moves every time written here back by a span, as the effects' clock starts over: see index.js. */
|
|
127
127
|
function shiftTime(spanSec) {
|
|
128
128
|
for (let index = 0; index < writtenCount; index += 1) {
|
|
129
|
-
values[index *
|
|
129
|
+
values[index * FLOAT_COUNT_PER_MARK + 8] -= spanSec;
|
|
130
130
|
endSec[index] -= spanSec;
|
|
131
131
|
}
|
|
132
132
|
if (writtenCount > 0) {
|
|
133
133
|
buffer.clearUpdateRanges();
|
|
134
|
-
buffer.addUpdateRange(0, writtenCount *
|
|
134
|
+
buffer.addUpdateRange(0, writtenCount * FLOAT_COUNT_PER_MARK);
|
|
135
135
|
buffer.needsUpdate = true;
|
|
136
136
|
}
|
|
137
137
|
}
|
|
@@ -143,14 +143,14 @@ export function createMarkBatch({ markCount, sharedUniforms }) {
|
|
|
143
143
|
update,
|
|
144
144
|
shiftTime,
|
|
145
145
|
clear() {
|
|
146
|
-
setCapacity(
|
|
146
|
+
setCapacity(capacityCount);
|
|
147
147
|
mesh.visible = false;
|
|
148
148
|
},
|
|
149
149
|
get liveCount() {
|
|
150
150
|
return liveCount;
|
|
151
151
|
},
|
|
152
152
|
get capacity() {
|
|
153
|
-
return
|
|
153
|
+
return capacityCount;
|
|
154
154
|
},
|
|
155
155
|
dispose() {
|
|
156
156
|
geometry.dispose();
|
package/batches/ribbons.js
CHANGED
|
@@ -6,7 +6,7 @@ import * as THREE from "three";
|
|
|
6
6
|
import { hashNumbers, randomFrom, valueOverLife } from "../format.js";
|
|
7
7
|
import { BLEND_END_GLSL, ONE_BLEND, fogUniforms } from "./shared.js";
|
|
8
8
|
|
|
9
|
-
const
|
|
9
|
+
const FLOAT_COUNT_PER_CORNER = 9;
|
|
10
10
|
const MAXIMUM_CORNER_COUNT = 8192;
|
|
11
11
|
const MAXIMUM_POINT_COUNT = 64;
|
|
12
12
|
|
|
@@ -45,15 +45,15 @@ const side = new THREE.Vector3();
|
|
|
45
45
|
const color = new THREE.Color();
|
|
46
46
|
|
|
47
47
|
function colorOverLength(colors, sharePct, into) {
|
|
48
|
-
const
|
|
49
|
-
const index = Math.min(Math.floor(
|
|
50
|
-
return into.copy(colors[index]).lerp(colors[Math.min(index + 1, colors.length - 1)],
|
|
48
|
+
const placeNumber = Math.min(Math.max(sharePct / 100, 0), 1) * (colors.length - 1);
|
|
49
|
+
const index = Math.min(Math.floor(placeNumber), Math.max(colors.length - 2, 0));
|
|
50
|
+
return into.copy(colors[index]).lerp(colors[Math.min(index + 1, colors.length - 1)], placeNumber - index);
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
/** Makes the batch. Answers { mesh, addRibbon, addBeam, update, liveCount, dispose }. */
|
|
54
54
|
export function createRibbonBatch() {
|
|
55
|
-
const values = new Float32Array(MAXIMUM_CORNER_COUNT *
|
|
56
|
-
const buffer = new THREE.InterleavedBuffer(values,
|
|
55
|
+
const values = new Float32Array(MAXIMUM_CORNER_COUNT * FLOAT_COUNT_PER_CORNER);
|
|
56
|
+
const buffer = new THREE.InterleavedBuffer(values, FLOAT_COUNT_PER_CORNER);
|
|
57
57
|
buffer.setUsage(THREE.DynamicDrawUsage);
|
|
58
58
|
const geometry = new THREE.BufferGeometry();
|
|
59
59
|
geometry.setAttribute("position", new THREE.InterleavedBufferAttribute(buffer, 3, 0));
|
|
@@ -77,23 +77,23 @@ export function createRibbonBatch() {
|
|
|
77
77
|
let indexCount = 0;
|
|
78
78
|
|
|
79
79
|
function corner(x, y, z, rgb, opacity, across, addShare) {
|
|
80
|
-
const
|
|
81
|
-
values[
|
|
82
|
-
values[
|
|
83
|
-
values[
|
|
84
|
-
values[
|
|
85
|
-
values[
|
|
86
|
-
values[
|
|
87
|
-
values[
|
|
88
|
-
values[
|
|
89
|
-
values[
|
|
80
|
+
const floatIndex = cornerCount * FLOAT_COUNT_PER_CORNER;
|
|
81
|
+
values[floatIndex] = x;
|
|
82
|
+
values[floatIndex + 1] = y;
|
|
83
|
+
values[floatIndex + 2] = z;
|
|
84
|
+
values[floatIndex + 3] = rgb.r;
|
|
85
|
+
values[floatIndex + 4] = rgb.g;
|
|
86
|
+
values[floatIndex + 5] = rgb.b;
|
|
87
|
+
values[floatIndex + 6] = opacity;
|
|
88
|
+
values[floatIndex + 7] = across;
|
|
89
|
+
values[floatIndex + 8] = addShare;
|
|
90
90
|
cornerCount += 1;
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
/** Joins the last two pairs of corners written with two triangles. */
|
|
94
94
|
function joinLastPairs() {
|
|
95
|
-
const
|
|
96
|
-
indices.set([
|
|
95
|
+
const lastCornerIndex = cornerCount - 4;
|
|
96
|
+
indices.set([lastCornerIndex, lastCornerIndex + 1, lastCornerIndex + 2, lastCornerIndex + 2, lastCornerIndex + 1, lastCornerIndex + 3], indexCount);
|
|
97
97
|
indexCount += 6;
|
|
98
98
|
}
|
|
99
99
|
|
|
@@ -139,11 +139,11 @@ export function createRibbonBatch() {
|
|
|
139
139
|
for (let number = 0; number < points.length; number += 1) {
|
|
140
140
|
const point = points[number];
|
|
141
141
|
const sharePct = ((nowSec - point.bornSec) / ribbon.lifeSec) * 100;
|
|
142
|
-
const
|
|
142
|
+
const opacityNumber = (valueOverLife(ribbon.opacityKeys, sharePct) / 100) * play.strengthShare;
|
|
143
143
|
colorOverLength(ribbon.colors, sharePct, color).multiply(play.tint).multiplyScalar(ribbon.glowShare);
|
|
144
144
|
if (ribbon.isBlade) {
|
|
145
|
-
corner(point.x, point.y, point.z, color,
|
|
146
|
-
corner(point.edgeX, point.edgeY, point.edgeZ, color,
|
|
145
|
+
corner(point.x, point.y, point.z, color, opacityNumber, -0.6, ribbon.addShare);
|
|
146
|
+
corner(point.edgeX, point.edgeY, point.edgeZ, color, opacityNumber, 0.6, ribbon.addShare);
|
|
147
147
|
} else {
|
|
148
148
|
const neighbour = points[Math.min(number + 1, points.length - 1)];
|
|
149
149
|
const earlier = points[Math.max(number - 1, 0)];
|
|
@@ -152,8 +152,8 @@ export function createRibbonBatch() {
|
|
|
152
152
|
side.crossVectors(along, toCamera);
|
|
153
153
|
if (side.lengthSq() < 1e-10) side.set(1, 0, 0);
|
|
154
154
|
side.normalize().multiplyScalar(valueOverLife(ribbon.widthKeys, sharePct) * 0.5 * play.scaleShare);
|
|
155
|
-
corner(point.x - side.x, point.y - side.y, point.z - side.z, color,
|
|
156
|
-
corner(point.x + side.x, point.y + side.y, point.z + side.z, color,
|
|
155
|
+
corner(point.x - side.x, point.y - side.y, point.z - side.z, color, opacityNumber, -1, ribbon.addShare);
|
|
156
|
+
corner(point.x + side.x, point.y + side.y, point.z + side.z, color, opacityNumber, 1, ribbon.addShare);
|
|
157
157
|
}
|
|
158
158
|
if (number > 0) joinLastPairs();
|
|
159
159
|
}
|
|
@@ -167,7 +167,7 @@ export function createRibbonBatch() {
|
|
|
167
167
|
const pointCount = beam.segmentCount + 1;
|
|
168
168
|
if (cornerCount + pointCount * 2 > MAXIMUM_CORNER_COUNT) return true;
|
|
169
169
|
const sharePct = (sinceSec / beam.lifeSec) * 100;
|
|
170
|
-
const
|
|
170
|
+
const opacityNumber = (valueOverLife(beam.opacityKeys, sharePct) / 100) * beam.play.strengthShare;
|
|
171
171
|
colorOverLength(beam.colors, sharePct, color).multiply(beam.play.tint).multiplyScalar(beam.glowShare);
|
|
172
172
|
// Its jagged path follows from its seed and which path it's on, so every player sees the same bolt.
|
|
173
173
|
const next = randomFrom(hashNumbers(beam.seedNumber, Math.floor(sinceSec * beam.rejitterPerSec)));
|
|
@@ -175,15 +175,15 @@ export function createRibbonBatch() {
|
|
|
175
175
|
if (beam.play.hasEnd) along.subVectors(beam.to, from);
|
|
176
176
|
else {
|
|
177
177
|
// A direction inside the cone, evenly over its area, from the same seed as the path.
|
|
178
|
-
const
|
|
179
|
-
const
|
|
178
|
+
const cosTurnNumber = 1 - next() * (1 - Math.cos(beam.spreadRad));
|
|
179
|
+
const sinTurnNumber = Math.sqrt(Math.max(1 - cosTurnNumber * cosTurnNumber, 0));
|
|
180
180
|
const roundRad = next() * Math.PI * 2;
|
|
181
|
-
along.set(
|
|
181
|
+
along.set(sinTurnNumber * Math.cos(roundRad), cosTurnNumber, sinTurnNumber * Math.sin(roundRad)).applyQuaternion(beam.play.turn).multiplyScalar(beam.reachM * beam.play.scaleShare);
|
|
182
182
|
}
|
|
183
183
|
const halfWidthM = beam.widthM * 0.5 * beam.play.scaleShare;
|
|
184
184
|
for (let number = 0; number < pointCount; number += 1) {
|
|
185
|
-
const
|
|
186
|
-
head.copy(from).addScaledVector(along,
|
|
185
|
+
const shareNumber = number / beam.segmentCount;
|
|
186
|
+
head.copy(from).addScaledVector(along, shareNumber);
|
|
187
187
|
if (beam.jitterM > 0 && number > 0 && number < beam.segmentCount) {
|
|
188
188
|
head.x += (next() - 0.5) * 2 * beam.jitterM;
|
|
189
189
|
head.y += (next() - 0.5) * 2 * beam.jitterM;
|
|
@@ -192,9 +192,9 @@ export function createRibbonBatch() {
|
|
|
192
192
|
toCamera.subVectors(cameraPosition, head);
|
|
193
193
|
side.crossVectors(along, toCamera);
|
|
194
194
|
if (side.lengthSq() < 1e-10) side.set(1, 0, 0);
|
|
195
|
-
side.normalize().multiplyScalar(halfWidthM * (1 - (1 - beam.tipWidthShare) *
|
|
196
|
-
corner(head.x - side.x, head.y - side.y, head.z - side.z, color,
|
|
197
|
-
corner(head.x + side.x, head.y + side.y, head.z + side.z, color,
|
|
195
|
+
side.normalize().multiplyScalar(halfWidthM * (1 - (1 - beam.tipWidthShare) * shareNumber));
|
|
196
|
+
corner(head.x - side.x, head.y - side.y, head.z - side.z, color, opacityNumber, -1, beam.addShare);
|
|
197
|
+
corner(head.x + side.x, head.y + side.y, head.z + side.z, color, opacityNumber, 1, beam.addShare);
|
|
198
198
|
if (number > 0) joinLastPairs();
|
|
199
199
|
}
|
|
200
200
|
return true;
|
|
@@ -209,7 +209,7 @@ export function createRibbonBatch() {
|
|
|
209
209
|
mesh.visible = indexCount > 0;
|
|
210
210
|
if (indexCount > 0) {
|
|
211
211
|
buffer.clearUpdateRanges();
|
|
212
|
-
buffer.addUpdateRange(0, cornerCount *
|
|
212
|
+
buffer.addUpdateRange(0, cornerCount * FLOAT_COUNT_PER_CORNER);
|
|
213
213
|
buffer.needsUpdate = true;
|
|
214
214
|
index.clearUpdateRanges();
|
|
215
215
|
index.addUpdateRange(0, indexCount);
|
package/batches/shared.js
CHANGED
|
@@ -9,7 +9,7 @@ export const WRAP_LAYER_COUNT = 4;
|
|
|
9
9
|
export const LANDING_LAYER_INDEX = 3;
|
|
10
10
|
|
|
11
11
|
export function createSharedUniforms() {
|
|
12
|
-
const vectors = (
|
|
12
|
+
const vectors = (vectorCount, make) => Array.from({ length: vectorCount }, make);
|
|
13
13
|
return {
|
|
14
14
|
uElements: { value: null },
|
|
15
15
|
uPlays: { value: null },
|
package/batches/sprites.js
CHANGED
|
@@ -33,10 +33,10 @@ export const ELEMENT_ROW = {
|
|
|
33
33
|
tone: 12,
|
|
34
34
|
};
|
|
35
35
|
|
|
36
|
-
const
|
|
37
|
-
const
|
|
38
|
-
const
|
|
39
|
-
const
|
|
36
|
+
const FLOAT_COUNT_PER_CORNER = 12;
|
|
37
|
+
const CORNER_COUNT_PER_PARTICLE = 4;
|
|
38
|
+
const FLOAT_COUNT_PER_PARTICLE = FLOAT_COUNT_PER_CORNER * CORNER_COUNT_PER_PARTICLE;
|
|
39
|
+
const INDEX_COUNT_PER_PARTICLE = 6;
|
|
40
40
|
|
|
41
41
|
const SPRITE_VERTEX = /* glsl */ `
|
|
42
42
|
attribute vec4 aBirth;
|
|
@@ -280,14 +280,14 @@ void main() {
|
|
|
280
280
|
* liveCount, capacity, dispose }.
|
|
281
281
|
*/
|
|
282
282
|
export function createSpriteBatch({ particleCount, sharedUniforms }) {
|
|
283
|
-
const vertices = new Float32Array(particleCount *
|
|
284
|
-
const buffer = new THREE.InterleavedBuffer(vertices,
|
|
283
|
+
const vertices = new Float32Array(particleCount * FLOAT_COUNT_PER_PARTICLE);
|
|
284
|
+
const buffer = new THREE.InterleavedBuffer(vertices, FLOAT_COUNT_PER_CORNER);
|
|
285
285
|
buffer.setUsage(THREE.DynamicDrawUsage);
|
|
286
286
|
const geometry = new THREE.BufferGeometry();
|
|
287
287
|
geometry.setAttribute("aBirth", new THREE.InterleavedBufferAttribute(buffer, 4, 0));
|
|
288
288
|
geometry.setAttribute("aVelocity", new THREE.InterleavedBufferAttribute(buffer, 4, 4));
|
|
289
289
|
geometry.setAttribute("aSeed", new THREE.InterleavedBufferAttribute(buffer, 4, 8));
|
|
290
|
-
const indices = new Uint32Array(particleCount *
|
|
290
|
+
const indices = new Uint32Array(particleCount * INDEX_COUNT_PER_PARTICLE);
|
|
291
291
|
const index = new THREE.BufferAttribute(indices, 1);
|
|
292
292
|
index.setUsage(THREE.DynamicDrawUsage);
|
|
293
293
|
geometry.setIndex(index);
|
|
@@ -312,15 +312,15 @@ export function createSpriteBatch({ particleCount, sharedUniforms }) {
|
|
|
312
312
|
/** When each particle's life ends, on the effects' clock: what moves a slab's live part on. */
|
|
313
313
|
const endSec = new Float32Array(particleCount);
|
|
314
314
|
const slabs = new Set();
|
|
315
|
-
let
|
|
316
|
-
let
|
|
315
|
+
let dirtyStartIndex = Infinity;
|
|
316
|
+
let dirtyEndIndex = -1;
|
|
317
317
|
let liveCount = 0;
|
|
318
318
|
let drawnOrder = [];
|
|
319
319
|
|
|
320
320
|
function takeSlab(wantedCount, owner) {
|
|
321
|
-
const
|
|
322
|
-
if (
|
|
323
|
-
const slab = { start: pool.take(
|
|
321
|
+
const takenCount = Math.min(wantedCount, pool.longestFreeCount());
|
|
322
|
+
if (takenCount <= 0) return null;
|
|
323
|
+
const slab = { start: pool.take(takenCount), capacity: takenCount, nextOffset: 0, liveStartOffset: 0, liveCount: 0, owner, distanceSquared: 0, isForever: false };
|
|
324
324
|
slabs.add(slab);
|
|
325
325
|
return slab;
|
|
326
326
|
}
|
|
@@ -328,16 +328,16 @@ export function createSpriteBatch({ particleCount, sharedUniforms }) {
|
|
|
328
328
|
function giveSlab(slab) {
|
|
329
329
|
if (!slabs.delete(slab)) return;
|
|
330
330
|
// Its particles are written as never born, so a later owner of these slots starts clean.
|
|
331
|
-
const
|
|
332
|
-
vertices.fill(0,
|
|
333
|
-
for (let
|
|
331
|
+
const fromIndex = slab.start * FLOAT_COUNT_PER_PARTICLE;
|
|
332
|
+
vertices.fill(0, fromIndex, fromIndex + slab.capacity * FLOAT_COUNT_PER_PARTICLE);
|
|
333
|
+
for (let cornerSlotIndex = 0; cornerSlotIndex < slab.capacity * CORNER_COUNT_PER_PARTICLE; cornerSlotIndex += 1) vertices[fromIndex + cornerSlotIndex * FLOAT_COUNT_PER_CORNER + 3] = 1e9;
|
|
334
334
|
markDirty(slab.start, slab.capacity);
|
|
335
335
|
pool.give(slab.start, slab.capacity);
|
|
336
336
|
}
|
|
337
337
|
|
|
338
|
-
function markDirty(particleIndex,
|
|
339
|
-
|
|
340
|
-
|
|
338
|
+
function markDirty(particleIndex, dirtyCount) {
|
|
339
|
+
dirtyStartIndex = Math.min(dirtyStartIndex, particleIndex);
|
|
340
|
+
dirtyEndIndex = Math.max(dirtyEndIndex, particleIndex + dirtyCount);
|
|
341
341
|
}
|
|
342
342
|
|
|
343
343
|
/** Writes one particle into a slab's ring, over its oldest when it's full. */
|
|
@@ -347,21 +347,21 @@ export function createSpriteBatch({ particleCount, sharedUniforms }) {
|
|
|
347
347
|
if (slab.liveCount < slab.capacity) slab.liveCount += 1;
|
|
348
348
|
else slab.liveStartOffset = (slab.liveStartOffset + 1) % slab.capacity;
|
|
349
349
|
endSec[particleIndex] = birthSec + lifeSec;
|
|
350
|
-
let
|
|
351
|
-
for (let
|
|
352
|
-
vertices[
|
|
353
|
-
vertices[
|
|
354
|
-
vertices[
|
|
355
|
-
vertices[
|
|
356
|
-
vertices[
|
|
357
|
-
vertices[
|
|
358
|
-
vertices[
|
|
359
|
-
vertices[
|
|
360
|
-
vertices[
|
|
361
|
-
vertices[
|
|
362
|
-
vertices[
|
|
363
|
-
vertices[
|
|
364
|
-
|
|
350
|
+
let floatIndex = particleIndex * FLOAT_COUNT_PER_PARTICLE;
|
|
351
|
+
for (let cornerIndex = 0; cornerIndex < CORNER_COUNT_PER_PARTICLE; cornerIndex += 1) {
|
|
352
|
+
vertices[floatIndex] = x;
|
|
353
|
+
vertices[floatIndex + 1] = y;
|
|
354
|
+
vertices[floatIndex + 2] = z;
|
|
355
|
+
vertices[floatIndex + 3] = birthSec;
|
|
356
|
+
vertices[floatIndex + 4] = velocityX;
|
|
357
|
+
vertices[floatIndex + 5] = velocityY;
|
|
358
|
+
vertices[floatIndex + 6] = velocityZ;
|
|
359
|
+
vertices[floatIndex + 7] = lifeSec;
|
|
360
|
+
vertices[floatIndex + 8] = seedNumber;
|
|
361
|
+
vertices[floatIndex + 9] = elementRow;
|
|
362
|
+
vertices[floatIndex + 10] = playRow;
|
|
363
|
+
vertices[floatIndex + 11] = cornerIndex;
|
|
364
|
+
floatIndex += FLOAT_COUNT_PER_CORNER;
|
|
365
365
|
}
|
|
366
366
|
markDirty(particleIndex, 1);
|
|
367
367
|
}
|
|
@@ -387,15 +387,15 @@ export function createSpriteBatch({ particleCount, sharedUniforms }) {
|
|
|
387
387
|
drawnOrder.sort((first, second) => (first.isForever !== second.isForever ? (first.isForever ? 1 : -1) : second.distanceSquared - first.distanceSquared));
|
|
388
388
|
let indexCount = 0;
|
|
389
389
|
for (const slab of drawnOrder) {
|
|
390
|
-
for (let
|
|
391
|
-
const
|
|
392
|
-
indices[indexCount] =
|
|
393
|
-
indices[indexCount + 1] =
|
|
394
|
-
indices[indexCount + 2] =
|
|
395
|
-
indices[indexCount + 3] =
|
|
396
|
-
indices[indexCount + 4] =
|
|
397
|
-
indices[indexCount + 5] =
|
|
398
|
-
indexCount +=
|
|
390
|
+
for (let stepIndex = 0; stepIndex < slab.liveCount; stepIndex += 1) {
|
|
391
|
+
const cornerIndex = (slab.start + ((slab.liveStartOffset + stepIndex) % slab.capacity)) * CORNER_COUNT_PER_PARTICLE;
|
|
392
|
+
indices[indexCount] = cornerIndex;
|
|
393
|
+
indices[indexCount + 1] = cornerIndex + 1;
|
|
394
|
+
indices[indexCount + 2] = cornerIndex + 2;
|
|
395
|
+
indices[indexCount + 3] = cornerIndex + 2;
|
|
396
|
+
indices[indexCount + 4] = cornerIndex + 1;
|
|
397
|
+
indices[indexCount + 5] = cornerIndex + 3;
|
|
398
|
+
indexCount += INDEX_COUNT_PER_PARTICLE;
|
|
399
399
|
}
|
|
400
400
|
}
|
|
401
401
|
geometry.setDrawRange(0, indexCount);
|
|
@@ -405,18 +405,18 @@ export function createSpriteBatch({ particleCount, sharedUniforms }) {
|
|
|
405
405
|
index.addUpdateRange(0, indexCount);
|
|
406
406
|
index.needsUpdate = true;
|
|
407
407
|
}
|
|
408
|
-
if (
|
|
408
|
+
if (dirtyEndIndex > dirtyStartIndex) {
|
|
409
409
|
buffer.clearUpdateRanges();
|
|
410
|
-
buffer.addUpdateRange(
|
|
410
|
+
buffer.addUpdateRange(dirtyStartIndex * FLOAT_COUNT_PER_PARTICLE, (dirtyEndIndex - dirtyStartIndex) * FLOAT_COUNT_PER_PARTICLE);
|
|
411
411
|
buffer.needsUpdate = true;
|
|
412
|
-
|
|
413
|
-
|
|
412
|
+
dirtyStartIndex = Infinity;
|
|
413
|
+
dirtyEndIndex = -1;
|
|
414
414
|
}
|
|
415
415
|
}
|
|
416
416
|
|
|
417
417
|
/** Moves every time written here back by a span, as the effects' clock starts over: see index.js. */
|
|
418
418
|
function shiftTime(spanSec) {
|
|
419
|
-
for (let
|
|
419
|
+
for (let floatIndex = 3; floatIndex < vertices.length; floatIndex += FLOAT_COUNT_PER_CORNER) vertices[floatIndex] -= spanSec;
|
|
420
420
|
for (let index = 0; index < endSec.length; index += 1) endSec[index] -= spanSec;
|
|
421
421
|
markDirty(0, particleCount);
|
|
422
422
|
}
|
package/batches/warps.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
import * as THREE from "three";
|
|
9
9
|
import { valueOverLife } from "../format.js";
|
|
10
10
|
|
|
11
|
-
const
|
|
11
|
+
const FLOAT_COUNT_PER_WARP = 8;
|
|
12
12
|
const MAXIMUM_WARP_COUNT = 32;
|
|
13
13
|
const WARP_KIND_NUMBERS = { ripple: 0, pulse: 1, haze: 2 };
|
|
14
14
|
// three took the picture first and the texture second until r165.
|
|
@@ -79,8 +79,8 @@ const place = new THREE.Vector3();
|
|
|
79
79
|
|
|
80
80
|
/** Makes the batch. Answers { mesh, add, update, drawOnScreen, liveCount, dispose }. */
|
|
81
81
|
export function createWarpBatch({ sharedUniforms }) {
|
|
82
|
-
const values = new Float32Array(MAXIMUM_WARP_COUNT *
|
|
83
|
-
const buffer = new THREE.InstancedInterleavedBuffer(values,
|
|
82
|
+
const values = new Float32Array(MAXIMUM_WARP_COUNT * FLOAT_COUNT_PER_WARP);
|
|
83
|
+
const buffer = new THREE.InstancedInterleavedBuffer(values, FLOAT_COUNT_PER_WARP);
|
|
84
84
|
buffer.setUsage(THREE.DynamicDrawUsage);
|
|
85
85
|
const geometry = new THREE.InstancedBufferGeometry();
|
|
86
86
|
geometry.setAttribute("position", new THREE.BufferAttribute(new Float32Array([-1, -1, 0, 1, -1, 0, -1, 1, 0, 1, 1, 0]), 3));
|
|
@@ -145,7 +145,7 @@ export function createWarpBatch({ sharedUniforms }) {
|
|
|
145
145
|
}
|
|
146
146
|
|
|
147
147
|
function update(nowSec, isEnabled) {
|
|
148
|
-
let
|
|
148
|
+
let warpCount = 0;
|
|
149
149
|
for (const warp of warps) {
|
|
150
150
|
let sinceSec = nowSec - warp.startSec;
|
|
151
151
|
const isHeld = warp.loopDurationSec > 0;
|
|
@@ -163,22 +163,22 @@ export function createWarpBatch({ sharedUniforms }) {
|
|
|
163
163
|
if (sharePct >= 100) continue;
|
|
164
164
|
}
|
|
165
165
|
place.copy(warp.play.place);
|
|
166
|
-
const
|
|
167
|
-
values[
|
|
168
|
-
values[
|
|
169
|
-
values[
|
|
170
|
-
values[
|
|
171
|
-
values[
|
|
172
|
-
values[
|
|
173
|
-
values[
|
|
174
|
-
values[
|
|
175
|
-
|
|
166
|
+
const floatIndex = warpCount * FLOAT_COUNT_PER_WARP;
|
|
167
|
+
values[floatIndex] = place.x;
|
|
168
|
+
values[floatIndex + 1] = place.y;
|
|
169
|
+
values[floatIndex + 2] = place.z;
|
|
170
|
+
values[floatIndex + 3] = valueOverLife(warp.radiusKeys, sharePct) * warp.play.scaleShare;
|
|
171
|
+
values[floatIndex + 4] = (valueOverLife(warp.strengthKeys, sharePct) / 100) * warp.play.strengthShare;
|
|
172
|
+
values[floatIndex + 5] = warp.thicknessShare;
|
|
173
|
+
values[floatIndex + 6] = WARP_KIND_NUMBERS[warp.warpKind];
|
|
174
|
+
values[floatIndex + 7] = warp.seedNumber;
|
|
175
|
+
warpCount += 1;
|
|
176
176
|
}
|
|
177
|
-
geometry.instanceCount =
|
|
178
|
-
mesh.visible =
|
|
179
|
-
if (
|
|
177
|
+
geometry.instanceCount = warpCount;
|
|
178
|
+
mesh.visible = warpCount > 0;
|
|
179
|
+
if (warpCount > 0) {
|
|
180
180
|
buffer.clearUpdateRanges();
|
|
181
|
-
buffer.addUpdateRange(0,
|
|
181
|
+
buffer.addUpdateRange(0, warpCount * FLOAT_COUNT_PER_WARP);
|
|
182
182
|
buffer.needsUpdate = true;
|
|
183
183
|
}
|
|
184
184
|
}
|