@zaisma/effects 1.0.1 → 1.2.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 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 FLOATS_PER_CHUNK = 12;
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 corner = 0; corner < Math.min(positions.count, CORNER_COUNT); corner += 3) {
36
- first.fromBufferAttribute(positions, corner);
37
- second.fromBufferAttribute(positions, corner + 1);
38
- third.fromBufferAttribute(positions, corner + 2);
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, offset) => {
41
- const placeAt = (shapeIndex * 2 * CORNER_COUNT + corner + offset) * 4;
42
- values.set([point.x, point.y, point.z, 1], placeAt);
43
- values.set([normal.x, normal.y, normal.z, 0], placeAt + CORNER_COUNT * 4);
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 * FLOATS_PER_CHUNK);
160
- const buffer = new THREE.InstancedInterleavedBuffer(values, FLOATS_PER_CHUNK);
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 dirtyStart = Infinity;
187
- let dirtyEnd = -1;
186
+ let dirtyStartIndex = Infinity;
187
+ let dirtyEndIndex = -1;
188
188
  let liveCount = 0;
189
189
 
190
- function markDirty(chunkIndex, count) {
191
- dirtyStart = Math.min(dirtyStart, chunkIndex);
192
- dirtyEnd = Math.max(dirtyEnd, chunkIndex + count);
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 count = Math.min(wantedCount, pool.longestFreeCount());
197
- if (count <= 0) return null;
198
- const slab = { start: pool.take(count), capacity: count, nextOffset: 0, liveCount: 0, lastEndSec: 0, owner };
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 from = slab.start * FLOATS_PER_CHUNK;
206
- values.fill(0, from, from + slab.capacity * FLOATS_PER_CHUNK);
207
- for (let offset = 0; offset < slab.capacity; offset += 1) values[from + offset * FLOATS_PER_CHUNK + 3] = 1e9;
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 at = chunkIndex * FLOATS_PER_CHUNK;
214
- values[at] = x;
215
- values[at + 1] = y;
216
- values[at + 2] = z;
217
- values[at + 3] = birthSec;
218
- values[at + 4] = velocityX;
219
- values[at + 5] = velocityY;
220
- values[at + 6] = velocityZ;
221
- values[at + 7] = lifeSec;
222
- values[at + 8] = seedNumber;
223
- values[at + 9] = elementRow;
224
- values[at + 10] = playRow;
225
- values[at + 11] = angleRad;
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 highest = 0;
245
+ let highestEndIndex = 0;
246
246
  liveCount = 0;
247
247
  for (const slab of slabs) {
248
248
  if (slab.lastEndSec <= nowSec) continue;
249
- highest = Math.max(highest, slab.start + slab.capacity);
250
- for (let offset = 0; offset < slab.capacity; offset += 1) if (endSec[slab.start + offset] > nowSec) liveCount += 1;
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 = highest;
253
- mesh.visible = highest > 0;
254
- if (dirtyEnd > dirtyStart) {
252
+ geometry.instanceCount = highestEndIndex;
253
+ mesh.visible = highestEndIndex > 0;
254
+ if (dirtyEndIndex > dirtyStartIndex) {
255
255
  buffer.clearUpdateRanges();
256
- buffer.addUpdateRange(dirtyStart * FLOATS_PER_CHUNK, (dirtyEnd - dirtyStart) * FLOATS_PER_CHUNK);
256
+ buffer.addUpdateRange(dirtyStartIndex * FLOAT_COUNT_PER_CHUNK, (dirtyEndIndex - dirtyStartIndex) * FLOAT_COUNT_PER_CHUNK);
257
257
  buffer.needsUpdate = true;
258
- dirtyStart = Infinity;
259
- dirtyEnd = -1;
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 at = 3; at < values.length; at += FLOATS_PER_CHUNK) values[at] -= spanSec;
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 FLOATS_PER_MARK = 20;
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 capacity = 0;
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
- capacity = newCapacity;
75
- values = new Float32Array(Math.max(capacity, 1) * FLOATS_PER_MARK);
76
- buffer = new THREE.InstancedInterleavedBuffer(values, FLOATS_PER_MARK);
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 (capacity === 0) return;
109
- const at = nextIndex * FLOATS_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], at);
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(at, FLOATS_PER_MARK);
112
+ buffer.addUpdateRange(floatIndex, FLOAT_COUNT_PER_MARK);
113
113
  buffer.needsUpdate = true;
114
- nextIndex = (nextIndex + 1) % capacity;
115
- writtenCount = Math.min(writtenCount + 1, capacity);
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 * FLOATS_PER_MARK + 8] -= spanSec;
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 * FLOATS_PER_MARK);
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(capacity);
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 capacity;
153
+ return capacityCount;
154
154
  },
155
155
  dispose() {
156
156
  geometry.dispose();
@@ -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 FLOATS_PER_CORNER = 9;
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 place = Math.min(Math.max(sharePct / 100, 0), 1) * (colors.length - 1);
49
- const index = Math.min(Math.floor(place), Math.max(colors.length - 2, 0));
50
- return into.copy(colors[index]).lerp(colors[Math.min(index + 1, colors.length - 1)], place - index);
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 * FLOATS_PER_CORNER);
56
- const buffer = new THREE.InterleavedBuffer(values, FLOATS_PER_CORNER);
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 at = cornerCount * FLOATS_PER_CORNER;
81
- values[at] = x;
82
- values[at + 1] = y;
83
- values[at + 2] = z;
84
- values[at + 3] = rgb.r;
85
- values[at + 4] = rgb.g;
86
- values[at + 5] = rgb.b;
87
- values[at + 6] = opacity;
88
- values[at + 7] = across;
89
- values[at + 8] = addShare;
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 last = cornerCount - 4;
96
- indices.set([last, last + 1, last + 2, last + 2, last + 1, last + 3], indexCount);
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 opacity = (valueOverLife(ribbon.opacityKeys, sharePct) / 100) * play.strengthShare;
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, opacity, -0.6, ribbon.addShare);
146
- corner(point.edgeX, point.edgeY, point.edgeZ, color, opacity, 0.6, ribbon.addShare);
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, opacity, -1, ribbon.addShare);
156
- corner(point.x + side.x, point.y + side.y, point.z + side.z, color, opacity, 1, ribbon.addShare);
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 opacity = (valueOverLife(beam.opacityKeys, sharePct) / 100) * beam.play.strengthShare;
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 cosTurn = 1 - next() * (1 - Math.cos(beam.spreadRad));
179
- const sinTurn = Math.sqrt(Math.max(1 - cosTurn * cosTurn, 0));
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(sinTurn * Math.cos(roundRad), cosTurn, sinTurn * Math.sin(roundRad)).applyQuaternion(beam.play.turn).multiplyScalar(beam.reachM * beam.play.scaleShare);
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 share = number / beam.segmentCount;
186
- head.copy(from).addScaledVector(along, share);
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) * share));
196
- corner(head.x - side.x, head.y - side.y, head.z - side.z, color, opacity, -1, beam.addShare);
197
- corner(head.x + side.x, head.y + side.y, head.z + side.z, color, opacity, 1, beam.addShare);
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 * FLOATS_PER_CORNER);
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 = (count, make) => Array.from({ length: count }, make);
12
+ const vectors = (vectorCount, make) => Array.from({ length: vectorCount }, make);
13
13
  return {
14
14
  uElements: { value: null },
15
15
  uPlays: { value: null },
@@ -33,10 +33,10 @@ export const ELEMENT_ROW = {
33
33
  tone: 12,
34
34
  };
35
35
 
36
- const FLOATS_PER_CORNER = 12;
37
- const CORNERS_PER_PARTICLE = 4;
38
- const FLOATS_PER_PARTICLE = FLOATS_PER_CORNER * CORNERS_PER_PARTICLE;
39
- const INDICES_PER_PARTICLE = 6;
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 * FLOATS_PER_PARTICLE);
284
- const buffer = new THREE.InterleavedBuffer(vertices, FLOATS_PER_CORNER);
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 * INDICES_PER_PARTICLE);
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 dirtyStart = Infinity;
316
- let dirtyEnd = -1;
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 count = Math.min(wantedCount, pool.longestFreeCount());
322
- if (count <= 0) return null;
323
- const slab = { start: pool.take(count), capacity: count, nextOffset: 0, liveStartOffset: 0, liveCount: 0, owner, distanceSquared: 0, isForever: false };
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 from = slab.start * FLOATS_PER_PARTICLE;
332
- vertices.fill(0, from, from + slab.capacity * FLOATS_PER_PARTICLE);
333
- for (let offset = 0; offset < slab.capacity * CORNERS_PER_PARTICLE; offset += 1) vertices[from + offset * FLOATS_PER_CORNER + 3] = 1e9;
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, count) {
339
- dirtyStart = Math.min(dirtyStart, particleIndex);
340
- dirtyEnd = Math.max(dirtyEnd, particleIndex + count);
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 at = particleIndex * FLOATS_PER_PARTICLE;
351
- for (let corner = 0; corner < CORNERS_PER_PARTICLE; corner += 1) {
352
- vertices[at] = x;
353
- vertices[at + 1] = y;
354
- vertices[at + 2] = z;
355
- vertices[at + 3] = birthSec;
356
- vertices[at + 4] = velocityX;
357
- vertices[at + 5] = velocityY;
358
- vertices[at + 6] = velocityZ;
359
- vertices[at + 7] = lifeSec;
360
- vertices[at + 8] = seedNumber;
361
- vertices[at + 9] = elementRow;
362
- vertices[at + 10] = playRow;
363
- vertices[at + 11] = corner;
364
- at += FLOATS_PER_CORNER;
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 step = 0; step < slab.liveCount; step += 1) {
391
- const corner = (slab.start + ((slab.liveStartOffset + step) % slab.capacity)) * CORNERS_PER_PARTICLE;
392
- indices[indexCount] = corner;
393
- indices[indexCount + 1] = corner + 1;
394
- indices[indexCount + 2] = corner + 2;
395
- indices[indexCount + 3] = corner + 2;
396
- indices[indexCount + 4] = corner + 1;
397
- indices[indexCount + 5] = corner + 3;
398
- indexCount += INDICES_PER_PARTICLE;
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 (dirtyEnd > dirtyStart) {
408
+ if (dirtyEndIndex > dirtyStartIndex) {
409
409
  buffer.clearUpdateRanges();
410
- buffer.addUpdateRange(dirtyStart * FLOATS_PER_PARTICLE, (dirtyEnd - dirtyStart) * FLOATS_PER_PARTICLE);
410
+ buffer.addUpdateRange(dirtyStartIndex * FLOAT_COUNT_PER_PARTICLE, (dirtyEndIndex - dirtyStartIndex) * FLOAT_COUNT_PER_PARTICLE);
411
411
  buffer.needsUpdate = true;
412
- dirtyStart = Infinity;
413
- dirtyEnd = -1;
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 at = 3; at < vertices.length; at += FLOATS_PER_CORNER) vertices[at] -= spanSec;
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 FLOATS_PER_WARP = 8;
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 * FLOATS_PER_WARP);
83
- const buffer = new THREE.InstancedInterleavedBuffer(values, FLOATS_PER_WARP);
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 count = 0;
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 at = count * FLOATS_PER_WARP;
167
- values[at] = place.x;
168
- values[at + 1] = place.y;
169
- values[at + 2] = place.z;
170
- values[at + 3] = valueOverLife(warp.radiusKeys, sharePct) * warp.play.scaleShare;
171
- values[at + 4] = (valueOverLife(warp.strengthKeys, sharePct) / 100) * warp.play.strengthShare;
172
- values[at + 5] = warp.thicknessShare;
173
- values[at + 6] = WARP_KIND_NUMBERS[warp.warpKind];
174
- values[at + 7] = warp.seedNumber;
175
- count += 1;
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 = count;
178
- mesh.visible = count > 0;
179
- if (count > 0) {
177
+ geometry.instanceCount = warpCount;
178
+ mesh.visible = warpCount > 0;
179
+ if (warpCount > 0) {
180
180
  buffer.clearUpdateRanges();
181
- buffer.addUpdateRange(0, count * FLOATS_PER_WARP);
181
+ buffer.addUpdateRange(0, warpCount * FLOAT_COUNT_PER_WARP);
182
182
  buffer.needsUpdate = true;
183
183
  }
184
184
  }