@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 +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 +100 -3
- 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/tables.js
CHANGED
|
@@ -20,7 +20,7 @@ export function createTable(texelCount, rowCount) {
|
|
|
20
20
|
texture.generateMipmaps = false;
|
|
21
21
|
texture.needsUpdate = true;
|
|
22
22
|
const freeRows = [];
|
|
23
|
-
for (let
|
|
23
|
+
for (let rowIndex = rowCount - 1; rowIndex >= 0; rowIndex -= 1) freeRows.push(rowIndex);
|
|
24
24
|
|
|
25
25
|
return {
|
|
26
26
|
texture,
|
|
@@ -37,11 +37,11 @@ export function createTable(texelCount, rowCount) {
|
|
|
37
37
|
},
|
|
38
38
|
/** Writes one texel of a row. */
|
|
39
39
|
write(row, texelIndex, first, second, third, fourth) {
|
|
40
|
-
const
|
|
41
|
-
values[
|
|
42
|
-
values[
|
|
43
|
-
values[
|
|
44
|
-
values[
|
|
40
|
+
const floatIndex = (row * texelCount + texelIndex) * 4;
|
|
41
|
+
values[floatIndex] = first;
|
|
42
|
+
values[floatIndex + 1] = second;
|
|
43
|
+
values[floatIndex + 2] = third;
|
|
44
|
+
values[floatIndex + 3] = fourth;
|
|
45
45
|
texture.needsUpdate = true;
|
|
46
46
|
},
|
|
47
47
|
dispose() {
|
|
@@ -66,32 +66,32 @@ export function createSlotPool(slotCount) {
|
|
|
66
66
|
return freeCount;
|
|
67
67
|
},
|
|
68
68
|
/** The start of a free run of `count` slots (the first that fits), or -1. */
|
|
69
|
-
take(
|
|
69
|
+
take(wantedCount) {
|
|
70
70
|
for (let index = 0; index < freeRuns.length; index += 1) {
|
|
71
71
|
const run = freeRuns[index];
|
|
72
|
-
if (run.count <
|
|
73
|
-
const
|
|
74
|
-
run.start +=
|
|
75
|
-
run.count -=
|
|
72
|
+
if (run.count < wantedCount) continue;
|
|
73
|
+
const startIndex = run.start;
|
|
74
|
+
run.start += wantedCount;
|
|
75
|
+
run.count -= wantedCount;
|
|
76
76
|
if (run.count === 0) freeRuns.splice(index, 1);
|
|
77
|
-
freeCount -=
|
|
78
|
-
return
|
|
77
|
+
freeCount -= wantedCount;
|
|
78
|
+
return startIndex;
|
|
79
79
|
}
|
|
80
80
|
return -1;
|
|
81
81
|
},
|
|
82
82
|
/** The longest free run's length: the most one emitter can still take. */
|
|
83
83
|
longestFreeCount() {
|
|
84
|
-
let
|
|
85
|
-
for (const run of freeRuns) if (run.count >
|
|
86
|
-
return
|
|
84
|
+
let longestCount = 0;
|
|
85
|
+
for (const run of freeRuns) if (run.count > longestCount) longestCount = run.count;
|
|
86
|
+
return longestCount;
|
|
87
87
|
},
|
|
88
|
-
give(start,
|
|
88
|
+
give(start, givenCount) {
|
|
89
89
|
let index = 0;
|
|
90
90
|
while (index < freeRuns.length && freeRuns[index].start < start) index += 1;
|
|
91
|
-
freeRuns.splice(index, 0, { start, count });
|
|
92
|
-
freeCount +=
|
|
91
|
+
freeRuns.splice(index, 0, { start, count: givenCount });
|
|
92
|
+
freeCount += givenCount;
|
|
93
93
|
const next = freeRuns[index + 1];
|
|
94
|
-
if (next && start +
|
|
94
|
+
if (next && start + givenCount === next.start) {
|
|
95
95
|
freeRuns[index].count += next.count;
|
|
96
96
|
freeRuns.splice(index + 1, 1);
|
|
97
97
|
}
|
package/weather.js
CHANGED
|
@@ -91,7 +91,7 @@ void main() {
|
|
|
91
91
|
}`;
|
|
92
92
|
|
|
93
93
|
const easeToward = (current, target, share, snap) => (Math.abs(target - current) <= snap ? target : current + (target - current) * share);
|
|
94
|
-
const wrapInto = (
|
|
94
|
+
const wrapInto = (positionM, sizeM) => ((positionM % sizeM) + sizeM) % sizeM;
|
|
95
95
|
|
|
96
96
|
/**
|
|
97
97
|
* Makes the weather. Its layers are elements like any effect's: index.js gives each a row and writes it in the look
|
|
@@ -212,16 +212,16 @@ export function createWeather({ sprites, sharedUniforms, scene, renderer, playRo
|
|
|
212
212
|
*/
|
|
213
213
|
function update({ nowSec, frameSec, camera, target, changeDurationSec, groundHeightM, hasShelter }) {
|
|
214
214
|
// What's set as the effects are made is the weather at once; later changes are eased to.
|
|
215
|
-
const
|
|
215
|
+
const shareNumber = hasStarted && changeDurationSec > 0 ? Math.min((frameSec * 3) / changeDurationSec, 1) : 1;
|
|
216
216
|
hasStarted = true;
|
|
217
|
-
now.rainPct = easeToward(now.rainPct, target.rainPct,
|
|
218
|
-
now.snowPct = easeToward(now.snowPct, target.snowPct,
|
|
219
|
-
now.fogPct = easeToward(now.fogPct, target.fogPct,
|
|
220
|
-
now.windSpeedMPerSec = easeToward(now.windSpeedMPerSec, target.windSpeedMPerSec,
|
|
221
|
-
now.windGustPct = easeToward(now.windGustPct, target.windGustPct,
|
|
217
|
+
now.rainPct = easeToward(now.rainPct, target.rainPct, shareNumber, 0.5);
|
|
218
|
+
now.snowPct = easeToward(now.snowPct, target.snowPct, shareNumber, 0.5);
|
|
219
|
+
now.fogPct = easeToward(now.fogPct, target.fogPct, shareNumber, 0.5);
|
|
220
|
+
now.windSpeedMPerSec = easeToward(now.windSpeedMPerSec, target.windSpeedMPerSec, shareNumber, 0.05);
|
|
221
|
+
now.windGustPct = easeToward(now.windGustPct, target.windGustPct, shareNumber, 0.5);
|
|
222
222
|
// The wind turns the short way round.
|
|
223
223
|
const turnDeg = ((((target.windDirectionDeg - now.windDirectionDeg) % 360) + 540) % 360) - 180;
|
|
224
|
-
now.windDirectionDeg = Math.abs(turnDeg) <= 0.5 ? target.windDirectionDeg : wrapInto(now.windDirectionDeg + turnDeg *
|
|
224
|
+
now.windDirectionDeg = Math.abs(turnDeg) <= 0.5 ? target.windDirectionDeg : wrapInto(now.windDirectionDeg + turnDeg * shareNumber, 360);
|
|
225
225
|
now.isSettled = now.rainPct === target.rainPct && now.snowPct === target.snowPct && now.fogPct === target.fogPct && now.windSpeedMPerSec === target.windSpeedMPerSec && now.windGustPct === target.windGustPct && now.windDirectionDeg === target.windDirectionDeg;
|
|
226
226
|
|
|
227
227
|
windAt(now, nowSec, windM);
|
|
@@ -231,29 +231,29 @@ export function createWeather({ sprites, sharedUniforms, scene, renderer, playRo
|
|
|
231
231
|
camera.getWorldPosition(cameraPlace);
|
|
232
232
|
camera.getWorldDirection(cameraWay);
|
|
233
233
|
for (const layer of layers) {
|
|
234
|
-
const
|
|
235
|
-
if (
|
|
234
|
+
const layerShareNumber = shareOf(layer);
|
|
235
|
+
if (layerShareNumber <= 0) {
|
|
236
236
|
dropLayer(layer);
|
|
237
237
|
continue;
|
|
238
238
|
}
|
|
239
239
|
fillLayer(layer);
|
|
240
|
-
const [
|
|
240
|
+
const [widthM, heightM, depthM] = layer.boxM;
|
|
241
241
|
const index = layer.layerIndex;
|
|
242
|
-
sharedUniforms.uWrapShare.value[index] =
|
|
243
|
-
sharedUniforms.uWrapBox.value[index].set(
|
|
242
|
+
sharedUniforms.uWrapShare.value[index] = layerShareNumber;
|
|
243
|
+
sharedUniforms.uWrapBox.value[index].set(widthM, heightM, depthM);
|
|
244
244
|
if (index === LANDING_LAYER_INDEX) {
|
|
245
|
-
sharedUniforms.uWrapCenter.value[index].set(cameraPlace.x + cameraWay.x *
|
|
245
|
+
sharedUniforms.uWrapCenter.value[index].set(cameraPlace.x + cameraWay.x * widthM * 0.3, cameraPlace.y, cameraPlace.z + cameraWay.z * depthM * 0.3);
|
|
246
246
|
sharedUniforms.uWrapVelocity.value[index].set(LANDINGS_PER_SEC, 0, 0);
|
|
247
247
|
continue;
|
|
248
248
|
}
|
|
249
249
|
const velocityX = windM.x * layer.windShare;
|
|
250
250
|
const velocityZ = windM.z * layer.windShare;
|
|
251
|
-
layer.shift.set(wrapInto(layer.shift.x + velocityX * frameSec,
|
|
251
|
+
layer.shift.set(wrapInto(layer.shift.x + velocityX * frameSec, widthM), wrapInto(layer.shift.y - layer.fallMPerSec * frameSec, heightM), wrapInto(layer.shift.z + velocityZ * frameSec, depthM));
|
|
252
252
|
sharedUniforms.uWrapShift.value[index].copy(layer.shift);
|
|
253
253
|
sharedUniforms.uWrapVelocity.value[index].set(velocityX, -layer.fallMPerSec, velocityZ);
|
|
254
254
|
// The box sits a little ahead of the camera, so more of it is in view; fog lies on the ground.
|
|
255
|
-
const centerY = layer.layerName === "fog" ? groundHeightM +
|
|
256
|
-
sharedUniforms.uWrapCenter.value[index].set(cameraPlace.x + cameraWay.x *
|
|
255
|
+
const centerY = layer.layerName === "fog" ? groundHeightM + heightM * 0.5 : cameraPlace.y + heightM * 0.2;
|
|
256
|
+
sharedUniforms.uWrapCenter.value[index].set(cameraPlace.x + cameraWay.x * widthM * 0.25, centerY, cameraPlace.z + cameraWay.z * depthM * 0.25);
|
|
257
257
|
}
|
|
258
258
|
|
|
259
259
|
const isFalling = now.rainPct > 0 || now.snowPct > 0;
|