@zaisma/effects 0.0.0-stage → 1.0.1
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/EFFECT-FILES.md +301 -0
- package/LICENSE.txt +93 -0
- package/README.md +63 -2
- package/batches/chunks.js +294 -0
- package/batches/marks.js +160 -0
- package/batches/ribbons.js +233 -0
- package/batches/shared.js +155 -0
- package/batches/sprites.js +447 -0
- package/batches/warps.js +222 -0
- package/budget.js +115 -0
- package/debris.js +173 -0
- package/emit.js +143 -0
- package/flashes.js +113 -0
- package/format.js +365 -0
- package/index.d.ts +373 -0
- package/index.js +1168 -0
- package/library/bubbles_rising.json +47 -0
- package/library/bullet_impact.json +588 -0
- package/library/campfire.json +235 -0
- package/library/candle_flame.json +100 -0
- package/library/confetti.json +165 -0
- package/library/dash_burst.json +73 -0
- package/library/debris_glass.json +96 -0
- package/library/debris_metal.json +106 -0
- package/library/debris_stone.json +106 -0
- package/library/debris_wood.json +101 -0
- package/library/dust_motes.json +51 -0
- package/library/dust_puff.json +49 -0
- package/library/electric_sparks.json +175 -0
- package/library/embers_drift.json +55 -0
- package/library/exhaust_puff.json +62 -0
- package/library/explosion_air.json +232 -0
- package/library/explosion_large.json +373 -0
- package/library/explosion_magic.json +266 -0
- package/library/explosion_medium.json +289 -0
- package/library/explosion_small.json +289 -0
- package/library/explosion_water.json +177 -0
- package/library/falling_leaves.json +54 -0
- package/library/fire_burst.json +185 -0
- package/library/fire_large.json +279 -0
- package/library/fireball.json +288 -0
- package/library/fireflies.json +51 -0
- package/library/firework_burst.json +127 -0
- package/library/footstep.json +270 -0
- package/library/fountain_spray.json +80 -0
- package/library/frost_burst.json +202 -0
- package/library/ground_mist.json +50 -0
- package/library/ground_slam.json +122 -0
- package/library/heat_haze.json +24 -0
- package/library/hit_blade.json +150 -0
- package/library/hit_block.json +157 -0
- package/library/hit_critical.json +293 -0
- package/library/hit_heavy.json +211 -0
- package/library/hit_light.json +122 -0
- package/library/hit_magic.json +114 -0
- package/library/impact.json +417 -0
- package/library/impact_heavy.json +279 -0
- package/library/index.json +464 -0
- package/library/jump_puff.json +46 -0
- package/library/landing_heavy.json +105 -0
- package/library/landing_puff.json +75 -0
- package/library/level_up.json +164 -0
- package/library/lightning_arc.json +90 -0
- package/library/lightning_strike.json +387 -0
- package/library/magic_aura.json +127 -0
- package/library/magic_bolt.json +107 -0
- package/library/magic_bolt_impact.json +181 -0
- package/library/magic_cast.json +115 -0
- package/library/magic_charge.json +91 -0
- package/library/magic_heal.json +123 -0
- package/library/magic_shield.json +89 -0
- package/library/magic_teleport.json +177 -0
- package/library/mark_bullet_hole.json +20 -0
- package/library/mark_crack.json +18 -0
- package/library/mark_footprint.json +20 -0
- package/library/mark_frost.json +18 -0
- package/library/mark_puddle.json +18 -0
- package/library/mark_scorch.json +18 -0
- package/library/mark_slash.json +18 -0
- package/library/mark_splat.json +18 -0
- package/library/pickup_collect.json +117 -0
- package/library/pickup_glow.json +76 -0
- package/library/poison_cloud.json +107 -0
- package/library/portal.json +328 -0
- package/library/shockwave_air.json +71 -0
- package/library/shockwave_ground.json +95 -0
- package/library/slide_dust.json +48 -0
- package/library/smoke_column.json +93 -0
- package/library/smoke_puff.json +48 -0
- package/library/smoke_screen.json +87 -0
- package/library/sparks_burst.json +85 -0
- package/library/sparks_fountain.json +93 -0
- package/library/sparks_shower.json +89 -0
- package/library/splash_large.json +181 -0
- package/library/splash_small.json +111 -0
- package/library/steam_vent.json +64 -0
- package/library/summon_circle.json +494 -0
- package/library/swim_splash.json +77 -0
- package/library/torch_flame.json +219 -0
- package/library/trail_blade.json +39 -0
- package/library/trail_blade_fire.json +90 -0
- package/library/trail_dash.json +80 -0
- package/library/trail_magic.json +94 -0
- package/library/trail_projectile.json +31 -0
- package/library/trail_smoke.json +125 -0
- package/library/warp_pulse.json +22 -0
- package/library/warp_ripple.json +23 -0
- package/library/water_ripple.json +69 -0
- package/library/waterfall_mist.json +95 -0
- package/looks.js +162 -0
- package/motion.js +145 -0
- package/online.d.ts +79 -0
- package/online.js +32 -0
- package/package.json +69 -4
- package/partners.js +255 -0
- package/piece.json +415 -0
- package/piece.json.js +416 -0
- package/server.d.ts +55 -0
- package/server.js +26 -0
- package/shapes.js +269 -0
- package/sync.js +528 -0
- package/tables.js +109 -0
- package/weather.js +289 -0
package/weather.js
ADDED
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
// Weather: rain, snow, drifting fog and the wind. Each is a fixed crowd of particles in a box that follows the
|
|
2
|
+
// camera, wrapped back in as they leave it, so a whole storm is written once and costs the page nothing while it
|
|
3
|
+
// falls. What a game sets (how hard it rains, how fast the wind blows) is eased to, never jumped to.
|
|
4
|
+
//
|
|
5
|
+
// Rain and snow stay out from under roofs by a small picture of the level seen from above (the shelter map): each
|
|
6
|
+
// texel holds the height of the highest thing there, and a drop below that height isn't drawn. Rain's splashes
|
|
7
|
+
// land on the same heights. The picture is drawn again only when the camera has moved or a moment has passed.
|
|
8
|
+
import * as THREE from "three";
|
|
9
|
+
import { completeEffect, randomFrom } from "./format.js";
|
|
10
|
+
import { windAt } from "./motion.js";
|
|
11
|
+
import { canRendererDraw } from "./shapes.js";
|
|
12
|
+
import { LANDING_LAYER_INDEX } from "./batches/shared.js";
|
|
13
|
+
|
|
14
|
+
/** How many particles each layer holds at each quality level, before the game's own budget scale. */
|
|
15
|
+
const LAYER_COUNTS = {
|
|
16
|
+
rain: { low: 700, medium: 1800, high: 5000 },
|
|
17
|
+
snow: { low: 600, medium: 1500, high: 4000 },
|
|
18
|
+
fog: { low: 24, medium: 48, high: 96 },
|
|
19
|
+
landing: { low: 0, medium: 300, high: 800 },
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const particles = (material, shape, move, fade) => ({ element_kind: "particles", material, shape, emit: { burst_count: 1 }, move, fade });
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The weather's layers. Each is drawn from an element like any effect's, so the look in use draws rain and snow its
|
|
26
|
+
* own way. boxM: the box that follows the camera. fallMPerSec: how fast it falls; windShare: how much of the wind
|
|
27
|
+
* carries it.
|
|
28
|
+
*/
|
|
29
|
+
export const WEATHER_LAYERS = [
|
|
30
|
+
{
|
|
31
|
+
layerName: "rain",
|
|
32
|
+
boxM: [24, 16, 24],
|
|
33
|
+
fallMPerSec: 9.5,
|
|
34
|
+
windShare: 0.9,
|
|
35
|
+
element: particles("water", "streak", {}, { size_over_life_m: [0.04, 0.04], size_variation_pct: 30, colors_over_life: ["#d4e0ee"], opacity_over_life_pct: [62, 62], facing_kind: "velocity", streak_duration_sec: 0.065 }),
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
layerName: "snow",
|
|
39
|
+
boxM: [20, 12, 20],
|
|
40
|
+
fallMPerSec: 1.3,
|
|
41
|
+
windShare: 1,
|
|
42
|
+
element: particles("snow", null, { turbulence_m: 0.35, turbulence_per_sec: 0.6 }, { size_over_life_m: [0.055, 0.055], size_variation_pct: 45, colors_over_life: ["#f4f8ff"], opacity_over_life_pct: [90, 90], spin_deg_per_sec: 60 }),
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
layerName: "fog",
|
|
46
|
+
boxM: [56, 5, 56],
|
|
47
|
+
fallMPerSec: 0,
|
|
48
|
+
windShare: 0.5,
|
|
49
|
+
element: particles("mist", null, { turbulence_m: 1.5, turbulence_per_sec: 0.08 }, { size_over_life_m: [11, 11], size_variation_pct: 35, colors_over_life: ["#c8d0d8"], opacity_over_life_pct: [13, 13] }),
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
layerName: "landing",
|
|
53
|
+
boxM: [22, 1, 22],
|
|
54
|
+
fallMPerSec: 0,
|
|
55
|
+
windShare: 0,
|
|
56
|
+
element: particles("water", "ring", {}, { size_over_life_m: [0.04, 0.3], size_variation_pct: 30, colors_over_life: ["#c4d4e4"], opacity_over_life_pct: [60, 0], facing_kind: "ground" }),
|
|
57
|
+
},
|
|
58
|
+
];
|
|
59
|
+
const LAYER_ELEMENTS = completeEffect({ effect_format_version_number: 1, name: "weather", elements: WEATHER_LAYERS.map((layer) => layer.element) }).elements;
|
|
60
|
+
/** How many times a second a place where rain lands shows a new splash. */
|
|
61
|
+
const LANDINGS_PER_SEC = 2.6;
|
|
62
|
+
const SHELTER_SIZE_PX = 256;
|
|
63
|
+
const SHELTER_WIDTH_M = 48;
|
|
64
|
+
/** How far above and below the camera the shelter map sees, in metres. */
|
|
65
|
+
const SHELTER_ABOVE_M = 60;
|
|
66
|
+
const SHELTER_BELOW_M = 40;
|
|
67
|
+
const SHELTER_REDRAW_DISTANCE_M = 3;
|
|
68
|
+
const SHELTER_REDRAW_INTERVAL_SEC = 1.5;
|
|
69
|
+
|
|
70
|
+
const SHELTER_VERTEX = /* glsl */ `
|
|
71
|
+
#include <common>
|
|
72
|
+
#include <skinning_pars_vertex>
|
|
73
|
+
varying float vHeightM;
|
|
74
|
+
void main() {
|
|
75
|
+
#include <skinbase_vertex>
|
|
76
|
+
#include <begin_vertex>
|
|
77
|
+
#include <skinning_vertex>
|
|
78
|
+
vec4 worldPlace = vec4(transformed, 1.0);
|
|
79
|
+
#ifdef USE_INSTANCING
|
|
80
|
+
worldPlace = instanceMatrix * worldPlace;
|
|
81
|
+
#endif
|
|
82
|
+
worldPlace = modelMatrix * worldPlace;
|
|
83
|
+
vHeightM = worldPlace.y;
|
|
84
|
+
gl_Position = projectionMatrix * viewMatrix * worldPlace;
|
|
85
|
+
}`;
|
|
86
|
+
const SHELTER_FRAGMENT = /* glsl */ `
|
|
87
|
+
uniform float uBaseM;
|
|
88
|
+
varying float vHeightM;
|
|
89
|
+
void main() {
|
|
90
|
+
gl_FragColor = vec4(vHeightM - uBaseM, 0.0, 0.0, 1.0);
|
|
91
|
+
}`;
|
|
92
|
+
|
|
93
|
+
const easeToward = (current, target, share, snap) => (Math.abs(target - current) <= snap ? target : current + (target - current) * share);
|
|
94
|
+
const wrapInto = (value, size) => ((value % size) + size) % size;
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Makes the weather. Its layers are elements like any effect's: index.js gives each a row and writes it in the look
|
|
98
|
+
* in use. Answers { elements, rebuild, update, setHidden, now, windM, dispose }.
|
|
99
|
+
*/
|
|
100
|
+
export function createWeather({ sprites, sharedUniforms, scene, renderer, playRow }) {
|
|
101
|
+
const layers = WEATHER_LAYERS.map((stated, layerIndex) => ({ ...stated, layerIndex, slab: null, elementRow: -1, shift: new THREE.Vector3(), count: 0 }));
|
|
102
|
+
/** What the weather is right now, eased toward the settings. */
|
|
103
|
+
const now = { rainPct: 0, snowPct: 0, fogPct: 0, windSpeedMPerSec: 0, windDirectionDeg: 0, windGustPct: 0, isSettled: true };
|
|
104
|
+
const windM = new THREE.Vector3();
|
|
105
|
+
let hasStarted = false;
|
|
106
|
+
let batch = sprites;
|
|
107
|
+
|
|
108
|
+
// ---- The shelter map ----
|
|
109
|
+
const canDraw = canRendererDraw(renderer);
|
|
110
|
+
let shelterTarget = null;
|
|
111
|
+
const shelterMaterial = new THREE.ShaderMaterial({ name: "zaisma_effect_shelter", vertexShader: SHELTER_VERTEX, fragmentShader: SHELTER_FRAGMENT, uniforms: { uBaseM: { value: 0 } }, toneMapped: false, fog: false, side: THREE.DoubleSide });
|
|
112
|
+
const shelterCamera = new THREE.OrthographicCamera(-SHELTER_WIDTH_M / 2, SHELTER_WIDTH_M / 2, SHELTER_WIDTH_M / 2, -SHELTER_WIDTH_M / 2, 0.1, SHELTER_ABOVE_M + SHELTER_BELOW_M);
|
|
113
|
+
shelterCamera.up.set(0, 0, -1);
|
|
114
|
+
const shelterCenter = new THREE.Vector3(Infinity, 0, 0);
|
|
115
|
+
let shelterDrawnSec = -Infinity;
|
|
116
|
+
let hiddenObjects = [];
|
|
117
|
+
const earlierClearColor = new THREE.Color();
|
|
118
|
+
const cameraPlace = new THREE.Vector3();
|
|
119
|
+
const cameraWay = new THREE.Vector3();
|
|
120
|
+
|
|
121
|
+
function drawShelter(nowSec) {
|
|
122
|
+
if (!shelterTarget) {
|
|
123
|
+
shelterTarget = new THREE.WebGLRenderTarget(SHELTER_SIZE_PX, SHELTER_SIZE_PX, { type: THREE.HalfFloatType, minFilter: THREE.NearestFilter, magFilter: THREE.NearestFilter, depthBuffer: true, generateMipmaps: false, colorSpace: THREE.NoColorSpace });
|
|
124
|
+
sharedUniforms.uShelter.value = shelterTarget.texture;
|
|
125
|
+
}
|
|
126
|
+
// Whole texels, so the map doesn't shimmer as the camera moves.
|
|
127
|
+
const texelM = SHELTER_WIDTH_M / SHELTER_SIZE_PX;
|
|
128
|
+
shelterCenter.set(Math.round(cameraPlace.x / texelM) * texelM, cameraPlace.y, Math.round(cameraPlace.z / texelM) * texelM);
|
|
129
|
+
shelterDrawnSec = nowSec;
|
|
130
|
+
const baseM = shelterCenter.y - SHELTER_BELOW_M - 1;
|
|
131
|
+
shelterCamera.position.set(shelterCenter.x, shelterCenter.y + SHELTER_ABOVE_M, shelterCenter.z);
|
|
132
|
+
shelterCamera.lookAt(shelterCenter.x, shelterCenter.y, shelterCenter.z);
|
|
133
|
+
shelterCamera.updateMatrixWorld();
|
|
134
|
+
shelterMaterial.uniforms.uBaseM.value = baseM;
|
|
135
|
+
|
|
136
|
+
const hidden = [];
|
|
137
|
+
for (const object of hiddenObjects) {
|
|
138
|
+
if (object?.visible) {
|
|
139
|
+
object.visible = false;
|
|
140
|
+
hidden.push(object);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
const earlierTarget = renderer.getRenderTarget();
|
|
144
|
+
const earlierOverride = scene.overrideMaterial;
|
|
145
|
+
const earlierBackground = scene.background;
|
|
146
|
+
const earlierShadowUpdate = renderer.shadowMap.autoUpdate;
|
|
147
|
+
const earlierXr = renderer.xr.enabled;
|
|
148
|
+
const earlierClearAlpha = renderer.getClearAlpha();
|
|
149
|
+
renderer.getClearColor(earlierClearColor);
|
|
150
|
+
scene.overrideMaterial = shelterMaterial;
|
|
151
|
+
scene.background = null;
|
|
152
|
+
renderer.shadowMap.autoUpdate = false;
|
|
153
|
+
renderer.xr.enabled = false;
|
|
154
|
+
renderer.setRenderTarget(shelterTarget);
|
|
155
|
+
renderer.setClearColor(0x000000, 0);
|
|
156
|
+
renderer.clear();
|
|
157
|
+
try {
|
|
158
|
+
renderer.render(scene, shelterCamera);
|
|
159
|
+
} finally {
|
|
160
|
+
renderer.setRenderTarget(earlierTarget);
|
|
161
|
+
renderer.setClearColor(earlierClearColor, earlierClearAlpha);
|
|
162
|
+
renderer.xr.enabled = earlierXr;
|
|
163
|
+
renderer.shadowMap.autoUpdate = earlierShadowUpdate;
|
|
164
|
+
scene.background = earlierBackground;
|
|
165
|
+
scene.overrideMaterial = earlierOverride;
|
|
166
|
+
for (const object of hidden) object.visible = true;
|
|
167
|
+
}
|
|
168
|
+
sharedUniforms.uShelterBox.value.set(shelterCenter.x, shelterCenter.z, SHELTER_WIDTH_M, 1);
|
|
169
|
+
sharedUniforms.uShelterBaseM.value = baseM;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// ---- The layers ----
|
|
173
|
+
|
|
174
|
+
function dropLayer(layer) {
|
|
175
|
+
if (!layer.slab) return;
|
|
176
|
+
batch.giveSlab(layer.slab);
|
|
177
|
+
layer.slab = null;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function fillLayer(layer) {
|
|
181
|
+
if (layer.slab || layer.count === 0 || layer.elementRow < 0) return;
|
|
182
|
+
const slab = batch.takeSlab(layer.count, null);
|
|
183
|
+
if (!slab) return;
|
|
184
|
+
slab.isForever = true;
|
|
185
|
+
layer.slab = slab;
|
|
186
|
+
const next = randomFrom(977 + layer.layerIndex);
|
|
187
|
+
for (let number = 0; number < slab.capacity; number += 1) {
|
|
188
|
+
batch.write(slab, next() * layer.boxM[0], next() * layer.boxM[1], next() * layer.boxM[2], 0, 0, 0, 0, 1, next(), layer.elementRow, playRow);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Starts every layer over: after the look, the quality level or the batch changed. rows: each layer's element
|
|
194
|
+
* row. countShare: the game's budget scale.
|
|
195
|
+
*/
|
|
196
|
+
function rebuild({ sprites: newBatch, rows, qualityLevel, countShare }) {
|
|
197
|
+
// A batch made anew has nothing of the old one's, so there's nothing to give back to it.
|
|
198
|
+
if (newBatch !== batch) for (const layer of layers) layer.slab = null;
|
|
199
|
+
batch = newBatch;
|
|
200
|
+
layers.forEach((layer, index) => {
|
|
201
|
+
dropLayer(layer);
|
|
202
|
+
layer.elementRow = rows[index];
|
|
203
|
+
layer.count = Math.round(LAYER_COUNTS[layer.layerName][qualityLevel] * countShare);
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
const shareOf = (layer) => (layer.layerName === "snow" ? now.snowPct : layer.layerName === "fog" ? now.fogPct : now.rainPct) / 100;
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Once a frame. target: what the settings ask for ({ rainPct, snowPct, fogPct, windSpeedMPerSec, windDirectionDeg,
|
|
211
|
+
* windGustPct }). Answers true while the weather is still turning.
|
|
212
|
+
*/
|
|
213
|
+
function update({ nowSec, frameSec, camera, target, changeDurationSec, groundHeightM, hasShelter }) {
|
|
214
|
+
// What's set as the effects are made is the weather at once; later changes are eased to.
|
|
215
|
+
const share = hasStarted && changeDurationSec > 0 ? Math.min((frameSec * 3) / changeDurationSec, 1) : 1;
|
|
216
|
+
hasStarted = true;
|
|
217
|
+
now.rainPct = easeToward(now.rainPct, target.rainPct, share, 0.5);
|
|
218
|
+
now.snowPct = easeToward(now.snowPct, target.snowPct, share, 0.5);
|
|
219
|
+
now.fogPct = easeToward(now.fogPct, target.fogPct, share, 0.5);
|
|
220
|
+
now.windSpeedMPerSec = easeToward(now.windSpeedMPerSec, target.windSpeedMPerSec, share, 0.05);
|
|
221
|
+
now.windGustPct = easeToward(now.windGustPct, target.windGustPct, share, 0.5);
|
|
222
|
+
// The wind turns the short way round.
|
|
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 * share, 360);
|
|
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
|
+
|
|
227
|
+
windAt(now, nowSec, windM);
|
|
228
|
+
sharedUniforms.uWind.value.copy(windM);
|
|
229
|
+
sharedUniforms.uWeatherTime.value = nowSec % 100000;
|
|
230
|
+
|
|
231
|
+
camera.getWorldPosition(cameraPlace);
|
|
232
|
+
camera.getWorldDirection(cameraWay);
|
|
233
|
+
for (const layer of layers) {
|
|
234
|
+
const layerShare = shareOf(layer);
|
|
235
|
+
if (layerShare <= 0) {
|
|
236
|
+
dropLayer(layer);
|
|
237
|
+
continue;
|
|
238
|
+
}
|
|
239
|
+
fillLayer(layer);
|
|
240
|
+
const [width, height, depth] = layer.boxM;
|
|
241
|
+
const index = layer.layerIndex;
|
|
242
|
+
sharedUniforms.uWrapShare.value[index] = layerShare;
|
|
243
|
+
sharedUniforms.uWrapBox.value[index].set(width, height, depth);
|
|
244
|
+
if (index === LANDING_LAYER_INDEX) {
|
|
245
|
+
sharedUniforms.uWrapCenter.value[index].set(cameraPlace.x + cameraWay.x * width * 0.3, cameraPlace.y, cameraPlace.z + cameraWay.z * depth * 0.3);
|
|
246
|
+
sharedUniforms.uWrapVelocity.value[index].set(LANDINGS_PER_SEC, 0, 0);
|
|
247
|
+
continue;
|
|
248
|
+
}
|
|
249
|
+
const velocityX = windM.x * layer.windShare;
|
|
250
|
+
const velocityZ = windM.z * layer.windShare;
|
|
251
|
+
layer.shift.set(wrapInto(layer.shift.x + velocityX * frameSec, width), wrapInto(layer.shift.y - layer.fallMPerSec * frameSec, height), wrapInto(layer.shift.z + velocityZ * frameSec, depth));
|
|
252
|
+
sharedUniforms.uWrapShift.value[index].copy(layer.shift);
|
|
253
|
+
sharedUniforms.uWrapVelocity.value[index].set(velocityX, -layer.fallMPerSec, velocityZ);
|
|
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 + height * 0.5 : cameraPlace.y + height * 0.2;
|
|
256
|
+
sharedUniforms.uWrapCenter.value[index].set(cameraPlace.x + cameraWay.x * width * 0.25, centerY, cameraPlace.z + cameraWay.z * depth * 0.25);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
const isFalling = now.rainPct > 0 || now.snowPct > 0;
|
|
260
|
+
if (hasShelter && isFalling && canDraw) {
|
|
261
|
+
const movedM = Math.hypot(cameraPlace.x - shelterCenter.x, cameraPlace.z - shelterCenter.z, cameraPlace.y - shelterCenter.y);
|
|
262
|
+
if (movedM > SHELTER_REDRAW_DISTANCE_M || nowSec - shelterDrawnSec > SHELTER_REDRAW_INTERVAL_SEC) drawShelter(nowSec);
|
|
263
|
+
} else if (sharedUniforms.uShelterBox.value.w !== 0) {
|
|
264
|
+
sharedUniforms.uShelterBox.value.w = 0;
|
|
265
|
+
shelterCenter.x = Infinity;
|
|
266
|
+
}
|
|
267
|
+
return !now.isSettled;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
return {
|
|
271
|
+
rebuild,
|
|
272
|
+
update,
|
|
273
|
+
/** The elements the layers are drawn from, complete, in the layers' order. */
|
|
274
|
+
elements: LAYER_ELEMENTS,
|
|
275
|
+
/** What's left out of the shelter map: the effects' own meshes, the sky. */
|
|
276
|
+
setHidden(objects) {
|
|
277
|
+
hiddenObjects = objects;
|
|
278
|
+
},
|
|
279
|
+
now,
|
|
280
|
+
windM,
|
|
281
|
+
dispose() {
|
|
282
|
+
for (const layer of layers) dropLayer(layer);
|
|
283
|
+
shelterTarget?.dispose();
|
|
284
|
+
shelterMaterial.dispose();
|
|
285
|
+
sharedUniforms.uShelter.value = null;
|
|
286
|
+
sharedUniforms.uShelterBox.value.w = 0;
|
|
287
|
+
},
|
|
288
|
+
};
|
|
289
|
+
}
|