@threenative/terrain 0.1.11 → 0.1.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/bake-DJ5cxg0C.d.ts +82 -0
- package/dist/editor/index.d.ts +4 -4
- package/dist/editor/index.js +1 -1
- package/dist/editor/server.d.ts +2 -2
- package/dist/editor/worker.d.ts +1 -1
- package/dist/editor/worker.js +1 -1
- package/dist/export.d.ts +1 -1
- package/dist/index.d.ts +51 -222
- package/dist/index.js +111 -2
- package/dist/kit-world.d.ts +107 -0
- package/dist/kit-world.js +5134 -0
- package/dist/kit.d.ts +21 -4
- package/dist/kit.js +19 -4
- package/dist/mcp/cook-child.js +9 -6
- package/dist/mcp/server.js +14 -4
- package/dist/prop-package-Dwz0EWoB.d.ts +141 -0
- package/dist/{server-B5RdvEAC.d.ts → server-LnFwY8sr.d.ts} +1 -1
- package/dist/starter.d.ts +1141 -6
- package/dist/starter.js +1999 -17
- package/dist/{terrain-CAEaW0mQ.d.ts → terrain-DYCyAOCJ.d.ts} +1 -1
- package/dist/three.d.ts +1 -1
- package/dist/{types-BpH00qsx.d.ts → types-kpI0C4hW.d.ts} +1 -1
- package/dist/{world-package-B8QgHjAQ.d.ts → world-package-DqJC3-Nn.d.ts} +2 -2
- package/docs/authoring/new-environment.md +97 -0
- package/package.json +8 -8
- package/starter/alpine/README.md +22 -14
- package/starter/alpine/bake.mjs +14 -1
- package/starter/alpine/biome.data.json +187 -25
- package/starter/alpine/heightmap.r16 +0 -0
- package/starter/alpine/playerRig.ts +89 -0
- package/starter/alpine/recipe.json +169 -15
- package/starter/alpine/render/bakedFile.ts +17 -0
- package/starter/alpine/render/benchmark.ts +77 -0
- package/starter/alpine/render/biomeData.ts +14 -0
- package/starter/alpine/render/biomes.ts +687 -0
- package/starter/alpine/render/ground/cover.ts +565 -0
- package/starter/alpine/render/ground/horizon.ts +219 -0
- package/starter/alpine/render/ground/palette.d.ts +1 -0
- package/starter/alpine/render/ground/palette.js +11 -0
- package/starter/alpine/render/ground/scatter.ts +104 -0
- package/starter/alpine/render/ground/terrain.ts +1860 -0
- package/starter/alpine/render/kitAssets.ts +28 -0
- package/starter/alpine/render/loading.ts +354 -0
- package/starter/alpine/render/lookKnobs.ts +37 -0
- package/starter/alpine/render/orbitCamera.ts +155 -0
- package/starter/alpine/render/props/farForest.ts +94 -0
- package/starter/alpine/render/props/pack.ts +1114 -0
- package/starter/alpine/render/props/prepared.ts +225 -0
- package/starter/alpine/render/props/propMaterials.ts +1239 -0
- package/starter/alpine/render/props/propProgress.ts +2 -0
- package/starter/alpine/render/props/propWorld.ts +105 -0
- package/starter/alpine/render/props/props.ts +633 -0
- package/starter/alpine/render/props/spruce.ts +440 -0
- package/starter/alpine/render/sky/atmosphere.ts +329 -0
- package/starter/alpine/render/sky/sky.ts +382 -0
- package/starter/alpine/render/texturePreparation.ts +135 -0
- package/starter/alpine/render/water/river.ts +1132 -0
- package/starter/alpine/render/worldNames.ts +6 -0
- package/starter/alpine/scene.ts +715 -0
- package/starter/alpine/sceneProps.ts +561 -0
- package/starter/alpine/sceneState.ts +33 -0
- package/starter/alpine/world/terrainAssets.ts +145 -0
- package/starter/alpine/world/walkBand.ts +47 -0
- package/starter/alpine/world/water.ts +74 -0
- package/starter/alpine/worlds.ts +13 -0
- package/starter/coastal/README.md +26 -27
- package/starter/coastal/assets.json +10 -0
- package/starter/coastal/bake.mjs +14 -1
- package/starter/coastal/biome.data.json +18 -3
- package/starter/coastal/playerRig.ts +89 -0
- package/starter/coastal/recipe.json +220 -18
- package/starter/coastal/render/bakedFile.ts +17 -0
- package/starter/coastal/render/benchmark.ts +81 -0
- package/starter/coastal/render/biomeData.ts +14 -0
- package/starter/coastal/render/biomes.ts +678 -0
- package/starter/coastal/render/ground/cover.ts +565 -0
- package/starter/coastal/render/ground/horizon.ts +219 -0
- package/starter/coastal/render/ground/palette.d.ts +1 -0
- package/starter/coastal/render/ground/palette.js +11 -0
- package/starter/coastal/render/ground/scatter.ts +104 -0
- package/starter/coastal/render/ground/terrain.ts +1829 -0
- package/starter/coastal/render/kitAssets.ts +28 -0
- package/starter/coastal/render/loading.ts +354 -0
- package/starter/coastal/render/lookKnobs.ts +37 -0
- package/starter/coastal/render/orbitCamera.ts +155 -0
- package/starter/coastal/render/props/farForest.ts +94 -0
- package/starter/coastal/render/props/pack.ts +1109 -0
- package/starter/coastal/render/props/prepared.ts +225 -0
- package/starter/coastal/render/props/propMaterials.ts +1239 -0
- package/starter/coastal/render/props/propProgress.ts +2 -0
- package/starter/coastal/render/props/propWorld.ts +105 -0
- package/starter/coastal/render/props/props.ts +633 -0
- package/starter/coastal/render/props/spruce.ts +440 -0
- package/starter/coastal/render/sky/atmosphere.ts +329 -0
- package/starter/coastal/render/sky/sky.ts +382 -0
- package/starter/coastal/render/texturePreparation.ts +135 -0
- package/starter/coastal/render/water/ocean.ts +284 -0
- package/starter/coastal/render/water/river.ts +1132 -0
- package/starter/coastal/render/worldNames.ts +6 -0
- package/starter/coastal/scene.ts +740 -0
- package/starter/coastal/sceneProps.ts +559 -0
- package/starter/coastal/sceneState.ts +33 -0
- package/starter/coastal/world/terrainAssets.ts +151 -0
- package/starter/coastal/world/walkBand.ts +47 -0
- package/starter/coastal/world/water.ts +74 -0
- package/starter/coastal/worlds.ts +13 -0
- package/starter/desert/README.md +51 -25
- package/starter/desert/bake-flora.mjs +142 -0
- package/starter/desert/bake-rocks.mjs +291 -0
- package/starter/desert/bake.mjs +14 -1
- package/starter/desert/biome.data.json +24 -12
- package/starter/desert/playerRig.ts +89 -0
- package/starter/desert/recipe.json +63 -16
- package/starter/desert/render/bakedFile.ts +17 -0
- package/starter/desert/render/benchmark.ts +79 -0
- package/starter/desert/render/biomeData.ts +14 -0
- package/starter/desert/render/biomes.ts +660 -0
- package/starter/desert/render/ground/cover.ts +565 -0
- package/starter/desert/render/ground/debris.ts +136 -0
- package/starter/desert/render/ground/horizon.ts +219 -0
- package/starter/desert/render/ground/palette.d.ts +1 -0
- package/starter/desert/render/ground/palette.js +11 -0
- package/starter/desert/render/ground/scatter.ts +104 -0
- package/starter/desert/render/ground/terrain.ts +1854 -0
- package/starter/desert/render/kitAssets.ts +28 -0
- package/starter/desert/render/loading.ts +354 -0
- package/starter/desert/render/lookKnobs.ts +37 -0
- package/starter/desert/render/orbitCamera.ts +155 -0
- package/starter/desert/render/props/farForest.ts +96 -0
- package/starter/desert/render/props/formations.ts +630 -0
- package/starter/desert/render/props/pack.ts +1195 -0
- package/starter/desert/render/props/prepared.ts +225 -0
- package/starter/desert/render/props/propMaterials.ts +1255 -0
- package/starter/desert/render/props/propProgress.ts +2 -0
- package/starter/desert/render/props/propWorld.ts +105 -0
- package/starter/desert/render/props/props.ts +624 -0
- package/starter/desert/render/props/spruce.ts +440 -0
- package/starter/desert/render/sand.ts +581 -0
- package/starter/desert/render/sky/atmosphere.ts +329 -0
- package/starter/desert/render/sky/sky.ts +382 -0
- package/starter/desert/render/texturePreparation.ts +135 -0
- package/starter/desert/render/water/river.ts +1132 -0
- package/starter/desert/render/worldNames.ts +6 -0
- package/starter/desert/scene.ts +748 -0
- package/starter/desert/sceneProps.ts +562 -0
- package/starter/desert/sceneState.ts +33 -0
- package/starter/desert/world/terrainAssets.ts +162 -0
- package/starter/desert/world/walkBand.ts +47 -0
- package/starter/desert/world/water.ts +74 -0
- package/starter/desert/worlds.ts +13 -0
- package/starter/forest/README.md +8 -5
- package/starter/forest/bake.mjs +21 -413
- package/starter/forest/playerRig.ts +37 -171
- package/starter/forest/recipe.json +237 -47
- package/starter/forest/render/biomes.ts +2 -1
- package/starter/forest/render/ground/horizon.ts +4 -302
- package/starter/forest/render/ground/terrain.ts +14 -32
- package/starter/forest/render/kitAssets.ts +3 -2
- package/starter/forest/render/props/farForest.ts +2 -1
- package/starter/forest/render/props/pack.ts +4 -2
- package/starter/forest/render/props/prepared.ts +2 -1
- package/starter/forest/render/props/propProgress.ts +1 -11
- package/starter/forest/render/props/propWorld.ts +48 -662
- package/starter/forest/render/props/props.ts +64 -248
- package/starter/forest/render/sky/sky.ts +2 -1
- package/starter/forest/render/worldNames.ts +6 -2
- package/starter/forest/scene.ts +34 -25
- package/starter/forest/sceneProps.ts +2 -2
- package/starter/forest/sceneState.ts +5 -4
- package/starter/forest/surface.json +2 -2
- package/starter/forest/worlds.ts +3 -2
- package/starter/tundra/README.md +35 -16
- package/starter/tundra/bake.mjs +14 -1
- package/starter/tundra/biome.data.json +6 -6
- package/starter/tundra/playerRig.ts +89 -0
- package/starter/tundra/recipe.json +111 -110
- package/starter/tundra/render/bakedFile.ts +17 -0
- package/starter/tundra/render/benchmark.ts +79 -0
- package/starter/tundra/render/biomeData.ts +14 -0
- package/starter/tundra/render/biomes.ts +714 -0
- package/starter/tundra/render/ground/cover.ts +565 -0
- package/starter/tundra/render/ground/horizon.ts +219 -0
- package/starter/tundra/render/ground/palette.d.ts +1 -0
- package/starter/tundra/render/ground/palette.js +11 -0
- package/starter/tundra/render/ground/scatter.ts +104 -0
- package/starter/tundra/render/ground/terrain.ts +1874 -0
- package/starter/tundra/render/kitAssets.ts +28 -0
- package/starter/tundra/render/loading.ts +354 -0
- package/starter/tundra/render/lookKnobs.ts +37 -0
- package/starter/tundra/render/orbitCamera.ts +155 -0
- package/starter/tundra/render/props/farForest.ts +96 -0
- package/starter/tundra/render/props/pack.ts +1088 -0
- package/starter/tundra/render/props/prepared.ts +225 -0
- package/starter/tundra/render/props/propMaterials.ts +1247 -0
- package/starter/tundra/render/props/propProgress.ts +2 -0
- package/starter/tundra/render/props/propWorld.ts +105 -0
- package/starter/tundra/render/props/props.ts +624 -0
- package/starter/tundra/render/props/spruce.ts +440 -0
- package/starter/tundra/render/sky/atmosphere.ts +329 -0
- package/starter/tundra/render/sky/sky.ts +382 -0
- package/starter/tundra/render/texturePreparation.ts +135 -0
- package/starter/tundra/render/water/river.ts +1132 -0
- package/starter/tundra/render/worldNames.ts +6 -0
- package/starter/tundra/scene.ts +715 -0
- package/starter/tundra/sceneProps.ts +559 -0
- package/starter/tundra/sceneState.ts +33 -0
- package/starter/tundra/world/terrainAssets.ts +159 -0
- package/starter/tundra/world/walkBand.ts +47 -0
- package/starter/tundra/world/water.ts +74 -0
- package/starter/tundra/worlds.ts +13 -0
- package/starter-assets.json +4 -4
- package/starter-credits.json +613 -10
- package/starter/forest/diagnostics.ts +0 -1020
- package/starter/forest/render/sky/skyVisibility.ts +0 -121
- package/starter/forest/spawnGate.ts +0 -183
- package/starter/forest/viewStatistics.ts +0 -47
- package/starter/forest/world/streamedGround.ts +0 -139
|
@@ -0,0 +1,581 @@
|
|
|
1
|
+
// The desert's loose sand: the prints a walker's feet press into it, the spray a running step
|
|
2
|
+
// throws, and the sand the wind drives over the dunes in streamers. `SnowField`
|
|
3
|
+
// (`@threenative/core/world`) keeps the numbers of a pressed surface and `GPUParticles3D` pools the
|
|
4
|
+
// grains; every colour, size, depth and rate below is this file's.
|
|
5
|
+
import { GPUParticles3D, type IAssetLoader } from "@threenative/core";
|
|
6
|
+
import { Heightfield, SnowField } from "@threenative/core/world";
|
|
7
|
+
import {
|
|
8
|
+
BufferAttribute,
|
|
9
|
+
type BufferGeometry,
|
|
10
|
+
MathUtils,
|
|
11
|
+
Mesh,
|
|
12
|
+
type Object3D,
|
|
13
|
+
PlaneGeometry,
|
|
14
|
+
RepeatWrapping,
|
|
15
|
+
type Texture,
|
|
16
|
+
Vector2,
|
|
17
|
+
Vector3,
|
|
18
|
+
} from "three";
|
|
19
|
+
import {
|
|
20
|
+
Fn,
|
|
21
|
+
If,
|
|
22
|
+
attribute,
|
|
23
|
+
cos,
|
|
24
|
+
exp,
|
|
25
|
+
float,
|
|
26
|
+
hash,
|
|
27
|
+
instanceIndex,
|
|
28
|
+
mix,
|
|
29
|
+
mx_noise_float,
|
|
30
|
+
normalWorld,
|
|
31
|
+
positionLocal,
|
|
32
|
+
positionViewDirection,
|
|
33
|
+
positionWorld,
|
|
34
|
+
sin,
|
|
35
|
+
smoothstep,
|
|
36
|
+
step,
|
|
37
|
+
texture,
|
|
38
|
+
time,
|
|
39
|
+
uint,
|
|
40
|
+
uniform,
|
|
41
|
+
uv,
|
|
42
|
+
varying,
|
|
43
|
+
vec2,
|
|
44
|
+
vec3,
|
|
45
|
+
vec4,
|
|
46
|
+
} from "three/tsl";
|
|
47
|
+
import {
|
|
48
|
+
type ComputeNode,
|
|
49
|
+
MeshBasicNodeMaterial,
|
|
50
|
+
MeshStandardNodeMaterial,
|
|
51
|
+
type Node,
|
|
52
|
+
NormalBlending,
|
|
53
|
+
SpriteNodeMaterial,
|
|
54
|
+
type StorageBufferNode,
|
|
55
|
+
type UniformNode,
|
|
56
|
+
} from "three/webgpu";
|
|
57
|
+
import type { TerrainCtx } from "../sceneState.js";
|
|
58
|
+
import { GROUND_MAPS, GROUND_TILE } from "../world/terrainAssets.js";
|
|
59
|
+
import { loadSkyLight, skyIrradiance } from "./props/pack.js";
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* The pressed sand: a square of the ground round the walker, a sample every 4 cm (a foot is three
|
|
63
|
+
* samples wide), with `depth` metres of loose sand on it. A foot sinks into the loose sand only.
|
|
64
|
+
*/
|
|
65
|
+
const FIELD = { size: 16, samples: 401, depth: 0.09, hardness: 0.3 } as const;
|
|
66
|
+
/** The square moves with the walker once they stand this near its edge; its old prints go. */
|
|
67
|
+
const EDGE = 2.5;
|
|
68
|
+
/** The ground is read every `COARSE` samples and interpolated: a square is rebuilt in a frame. */
|
|
69
|
+
const COARSE = 8;
|
|
70
|
+
/** Wind fills a print: metres of sand a second, and how fast it wears the rim down. */
|
|
71
|
+
const DRIFT = { deposition: 0.0009, wind: 0.5, every: 0.25 } as const;
|
|
72
|
+
/** The walker's weight in newtons, the sole's half width in metres and its area in m². */
|
|
73
|
+
const FOOT = { load: 80 * 9.81, halfWidth: 0.05, area: 0.028 } as const;
|
|
74
|
+
/**
|
|
75
|
+
* A foot is down when its ball moves slower than `still` m/s within `low` metres of the ground,
|
|
76
|
+
* and up again past `swing` m/s or `high` metres.
|
|
77
|
+
*/
|
|
78
|
+
const PLANT = { still: 0.7, low: 0.13, swing: 1.6, high: 0.18 } as const;
|
|
79
|
+
/** The rig's ankle and ball bones, left then right: a print lies under the two of them. */
|
|
80
|
+
const FEET = [
|
|
81
|
+
["foot_l", "ball_l"],
|
|
82
|
+
["foot_r", "ball_r"],
|
|
83
|
+
] as const;
|
|
84
|
+
/** Metres a second over which a step throws sand. */
|
|
85
|
+
const RUNNING = 3;
|
|
86
|
+
/** The wind: where it blows to (x, z, unit length) and its speed near the ground in m/s. */
|
|
87
|
+
export const SAND_WIND = { to: [0.86, 0.5], speed: 6 } as const;
|
|
88
|
+
/** Sand a running step throws: grains per step and on a landing, and seconds they live. */
|
|
89
|
+
const KICK = { amount: 384, life: 0.7, run: 9, land: 34 } as const;
|
|
90
|
+
/**
|
|
91
|
+
* Sand on the wind: a sheet `size` metres across that lies `lift` metres over the ground round the
|
|
92
|
+
* walker and draws the streamers the wind drives across it.
|
|
93
|
+
*/
|
|
94
|
+
const STREAMERS = { size: 56, cells: 56, lift: 0.07, opacity: 0.5 } as const;
|
|
95
|
+
/** Sand in the air, lit: these are linear, and neither the grains nor the streamers take light. */
|
|
96
|
+
const DUST: readonly [number, number, number] = [0.46, 0.235, 0.115];
|
|
97
|
+
const STATE = "sand";
|
|
98
|
+
/** Metres the untouched part of the print square lies under the ground. */
|
|
99
|
+
const SUNK = 40;
|
|
100
|
+
|
|
101
|
+
interface IPrintSample {
|
|
102
|
+
readonly bank: number;
|
|
103
|
+
readonly coverage: number;
|
|
104
|
+
readonly disturbance: number;
|
|
105
|
+
readonly relief: number;
|
|
106
|
+
readonly shape: number;
|
|
107
|
+
}
|
|
108
|
+
const NOTHING: IPrintSample = { bank: 0, coverage: 0, disturbance: 0, relief: 0, shape: 0 };
|
|
109
|
+
const smooth = (edge0: number, edge1: number, value: number) =>
|
|
110
|
+
MathUtils.smoothstep((value - edge0) / (edge1 - edge0), 0, 1);
|
|
111
|
+
/**
|
|
112
|
+
* A foot in sand, local z from heel to toe, `half` metres from its middle to its toe: a rounded
|
|
113
|
+
* sole a little wider at the ball, a deeper heel, and the sand it pushed out as a thin rim.
|
|
114
|
+
*/
|
|
115
|
+
function footPrint(half: number) {
|
|
116
|
+
const corner = FOOT.halfWidth * 0.9;
|
|
117
|
+
return {
|
|
118
|
+
extent: (half + 0.07) * 2,
|
|
119
|
+
sample: (x: number, z: number): IPrintSample => {
|
|
120
|
+
const width = FOOT.halfWidth * (0.82 + smooth(-half, half * 0.5, z) * 0.26);
|
|
121
|
+
const qx = Math.abs(x) - (width - corner);
|
|
122
|
+
const qz = Math.abs(z) - (half - corner);
|
|
123
|
+
const sdf =
|
|
124
|
+
Math.hypot(Math.max(qx, 0), Math.max(qz, 0)) + Math.min(Math.max(qx, qz), 0) - corner;
|
|
125
|
+
if (sdf > 0.06) return NOTHING;
|
|
126
|
+
const rim = sdf > 0 ? Math.exp(-(((sdf - 0.02) / 0.018) ** 2)) : 0;
|
|
127
|
+
return {
|
|
128
|
+
bank: rim * 0.7,
|
|
129
|
+
coverage: 1 - smooth(-0.02, 0.008, sdf),
|
|
130
|
+
disturbance: rim * 0.5,
|
|
131
|
+
relief: 0.005 * smooth(half * 0.2, -half, z),
|
|
132
|
+
shape: 0.85 + 0.15 * smooth(half * 0.4, -half, z),
|
|
133
|
+
};
|
|
134
|
+
},
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
interface IBuffers {
|
|
139
|
+
readonly positions: StorageBufferNode<"vec3">;
|
|
140
|
+
readonly velocities: StorageBufferNode<"vec3">;
|
|
141
|
+
readonly births: StorageBufferNode<"float">;
|
|
142
|
+
}
|
|
143
|
+
interface IRequest {
|
|
144
|
+
readonly first: UniformNode<"uint", number>;
|
|
145
|
+
readonly count: UniformNode<"uint", number>;
|
|
146
|
+
readonly origin: UniformNode<"vec3", Vector3>;
|
|
147
|
+
readonly direction: UniformNode<"vec3", Vector3>;
|
|
148
|
+
readonly seed: UniformNode<"float", number>;
|
|
149
|
+
}
|
|
150
|
+
type Runtime = { readonly time: Node<"float">; readonly delta: Node<"float"> };
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* The sand a running foot throws: small grains that leave low and fall back within the step, not
|
|
154
|
+
* a cloud. A burst's `direction` is its shape: x the speed outward, y the speed upward, z the
|
|
155
|
+
* radius it starts in.
|
|
156
|
+
*/
|
|
157
|
+
function kickedSand() {
|
|
158
|
+
const material = new SpriteNodeMaterial({
|
|
159
|
+
blending: NormalBlending,
|
|
160
|
+
depthWrite: false,
|
|
161
|
+
transparent: true,
|
|
162
|
+
});
|
|
163
|
+
// The quad's empty corners write nothing to the depth and normal buffers, so AO skips them.
|
|
164
|
+
material.alphaTest = 0.01;
|
|
165
|
+
const bind = (born: Node<"float">): void => {
|
|
166
|
+
const age = time.sub(born);
|
|
167
|
+
const alive = varying(step(0, age).mul(step(age, KICK.life)));
|
|
168
|
+
const phase = varying(age.div(KICK.life).clamp(0, 1));
|
|
169
|
+
const jitter = hash(instanceIndex.add(7)).mul(0.7).add(0.6);
|
|
170
|
+
material.scaleNode = mix(float(0.05), float(0.3), phase.sqrt()).mul(jitter).mul(alive);
|
|
171
|
+
const round = float(1).sub(smoothstep(0.05, 0.5, uv().sub(0.5).length()));
|
|
172
|
+
material.colorNode = vec4(
|
|
173
|
+
vec3(...DUST),
|
|
174
|
+
round
|
|
175
|
+
.mul(round)
|
|
176
|
+
.mul(float(1).sub(smoothstep(0.3, 1, phase)))
|
|
177
|
+
.mul(0.5)
|
|
178
|
+
.mul(alive),
|
|
179
|
+
);
|
|
180
|
+
};
|
|
181
|
+
const spawn = ({ positions, velocities, births }: IBuffers, request: IRequest): ComputeNode => {
|
|
182
|
+
bind(births.toAttribute());
|
|
183
|
+
return Fn(() => {
|
|
184
|
+
If(instanceIndex.lessThan(request.count), () => {
|
|
185
|
+
const slot = request.first.add(instanceIndex).mod(uint(KICK.amount));
|
|
186
|
+
const key = instanceIndex.add(request.seed.mul(977).toUint());
|
|
187
|
+
const r = (salt: number) => hash(key.add(salt));
|
|
188
|
+
const angle = r(1).mul(Math.PI * 2);
|
|
189
|
+
const radius = r(2).sqrt().mul(request.direction.z);
|
|
190
|
+
const out = request.direction.x.mul(r(3).mul(0.7).add(0.3));
|
|
191
|
+
positions
|
|
192
|
+
.element(slot)
|
|
193
|
+
.assign(
|
|
194
|
+
request.origin.add(
|
|
195
|
+
vec3(cos(angle).mul(radius), r(4).mul(0.03), sin(angle).mul(radius)),
|
|
196
|
+
),
|
|
197
|
+
);
|
|
198
|
+
velocities
|
|
199
|
+
.element(slot)
|
|
200
|
+
.assign(
|
|
201
|
+
vec3(
|
|
202
|
+
cos(angle).mul(out),
|
|
203
|
+
request.direction.y.mul(r(5).mul(0.8).add(0.3)),
|
|
204
|
+
sin(angle).mul(out),
|
|
205
|
+
),
|
|
206
|
+
);
|
|
207
|
+
});
|
|
208
|
+
})().compute(KICK.amount);
|
|
209
|
+
};
|
|
210
|
+
const wind = vec3(SAND_WIND.to[0], 0, SAND_WIND.to[1]).mul(SAND_WIND.speed * 0.25);
|
|
211
|
+
const process = ({ positions, velocities, births }: IBuffers, runtime: Runtime): ComputeNode =>
|
|
212
|
+
Fn(() => {
|
|
213
|
+
const age = runtime.time.sub(births.element(instanceIndex));
|
|
214
|
+
If(age.greaterThanEqual(0).and(age.lessThan(KICK.life)), () => {
|
|
215
|
+
const velocity = velocities
|
|
216
|
+
.element(instanceIndex)
|
|
217
|
+
.mul(exp(float(-3).mul(runtime.delta)))
|
|
218
|
+
.add(vec3(0, -5, 0).mul(runtime.delta));
|
|
219
|
+
velocities.element(instanceIndex).assign(velocity);
|
|
220
|
+
positions
|
|
221
|
+
.element(instanceIndex)
|
|
222
|
+
.addAssign(velocity.add(wind.mul(age.div(KICK.life))).mul(runtime.delta));
|
|
223
|
+
});
|
|
224
|
+
})().compute(KICK.amount);
|
|
225
|
+
return { amount: KICK.amount, lifetime: KICK.life, material, process, spawn };
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Sand on the wind, as it looks on a dune: thin streamers that snake over the surface, come in
|
|
230
|
+
* gusts, and show most where the eye looks along the ground. One sheet a hand over the sand
|
|
231
|
+
* draws them; nothing floats in the air.
|
|
232
|
+
*/
|
|
233
|
+
function streamerMaterial(
|
|
234
|
+
gust: UniformNode<"float", number>,
|
|
235
|
+
centre: UniformNode<"vec2", Vector2>,
|
|
236
|
+
): MeshBasicNodeMaterial {
|
|
237
|
+
const material = new MeshBasicNodeMaterial({ depthWrite: false, transparent: true });
|
|
238
|
+
const [wx, wz] = SAND_WIND.to;
|
|
239
|
+
const along = positionWorld.x.mul(wx).add(positionWorld.z.mul(wz));
|
|
240
|
+
const across = positionWorld.z.mul(wx).sub(positionWorld.x.mul(wz));
|
|
241
|
+
const run = along.sub(time.mul(SAND_WIND.speed));
|
|
242
|
+
// A streamer is metres long and a hand wide; its line wanders as it runs.
|
|
243
|
+
const wander = mx_noise_float(vec2(run.mul(0.09), across.mul(0.12))).mul(1.6);
|
|
244
|
+
const thread = mx_noise_float(vec2(run.mul(0.055), across.add(wander).mul(1.7)));
|
|
245
|
+
const fine = mx_noise_float(vec2(run.mul(0.4), across.add(wander).mul(5.5)));
|
|
246
|
+
const strand = smoothstep(0.18, 0.62, thread.add(fine.mul(0.35)));
|
|
247
|
+
// The gusts: bands tens of metres across that cross the dunes with the wind.
|
|
248
|
+
const band = smoothstep(
|
|
249
|
+
-0.1,
|
|
250
|
+
0.55,
|
|
251
|
+
mx_noise_float(vec2(along.sub(time.mul(SAND_WIND.speed * 0.7)).mul(0.022), across.mul(0.03))),
|
|
252
|
+
);
|
|
253
|
+
// Seen from above a streamer is a few grains thick and vanishes; along the ground it is a veil.
|
|
254
|
+
const grazing = float(1).sub(positionViewDirection.dot(normalWorld).abs()).pow(1.6);
|
|
255
|
+
const reach = STREAMERS.size / 2;
|
|
256
|
+
const edge = float(1).sub(
|
|
257
|
+
smoothstep(reach * 0.55, reach * 0.95, positionWorld.xz.sub(centre).length()),
|
|
258
|
+
);
|
|
259
|
+
material.colorNode = vec3(...DUST).mul(strand.mul(0.25).add(0.9));
|
|
260
|
+
material.opacityNode = strand.mul(band).mul(grazing).mul(edge).mul(gust).mul(STREAMERS.opacity);
|
|
261
|
+
return material;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/** The print overlay: sand-coloured, drawn only where the field moved, dark in the hollow. */
|
|
265
|
+
function printMaterial(
|
|
266
|
+
map: Texture | undefined,
|
|
267
|
+
sky: Texture | undefined,
|
|
268
|
+
sandTint: readonly [number, number, number],
|
|
269
|
+
): MeshStandardNodeMaterial {
|
|
270
|
+
const material = new MeshStandardNodeMaterial({
|
|
271
|
+
depthWrite: false,
|
|
272
|
+
roughness: 0.96,
|
|
273
|
+
transparent: true,
|
|
274
|
+
});
|
|
275
|
+
material.polygonOffset = true;
|
|
276
|
+
material.polygonOffsetFactor = -2;
|
|
277
|
+
material.polygonOffsetUnits = -6;
|
|
278
|
+
// x: metres pressed in, y: metres of rim raised, z: 1 where the field wrote.
|
|
279
|
+
const state = attribute(STATE, "vec3" as const);
|
|
280
|
+
// The overlay keeps the pressed surface's normals and lies flat a centimetre over the ground it
|
|
281
|
+
// copies: a hollow under the ground the kit draws would lose the depth test. The untouched part
|
|
282
|
+
// of the square goes far under the ground, so it shades no pixel.
|
|
283
|
+
material.positionNode = positionLocal.add(
|
|
284
|
+
vec3(
|
|
285
|
+
0,
|
|
286
|
+
state.x
|
|
287
|
+
.sub(state.y)
|
|
288
|
+
.sub(FIELD.depth - 0.012)
|
|
289
|
+
.sub(float(1).sub(state.z).mul(SUNK)),
|
|
290
|
+
0,
|
|
291
|
+
),
|
|
292
|
+
);
|
|
293
|
+
const tint = vec3(...sandTint);
|
|
294
|
+
const sand = map
|
|
295
|
+
? texture(map, positionWorld.xz.div(GROUND_TILE.grass)).rgb.mul(tint)
|
|
296
|
+
: tint.mul(0.27);
|
|
297
|
+
// Pressed sand is darker than the loose, sun-bleached grains round it; the rim is those grains.
|
|
298
|
+
const hollow = smoothstep(0.004, 0.035, state.x);
|
|
299
|
+
const rim = smoothstep(0.004, 0.02, state.y);
|
|
300
|
+
material.colorNode = sand
|
|
301
|
+
.mul(mix(float(1), float(0.52), hollow))
|
|
302
|
+
.mul(mix(float(1), float(1.15), rim));
|
|
303
|
+
material.opacityNode = smoothstep(0.001, 0.008, state.x.add(state.y));
|
|
304
|
+
if (sky) {
|
|
305
|
+
const { up, down } = skyIrradiance(sky);
|
|
306
|
+
material.emissiveNode = (material.colorNode as Node<"vec3">)
|
|
307
|
+
.mul(mix(vec3(...down), vec3(...up), normalWorld.y.mul(0.5).add(0.5)))
|
|
308
|
+
.mul(0.6);
|
|
309
|
+
}
|
|
310
|
+
return material;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
export interface ISandWalker {
|
|
314
|
+
readonly position: { readonly x: number; readonly y: number; readonly z: number };
|
|
315
|
+
readonly velocity: { readonly x: number; readonly y: number; readonly z: number };
|
|
316
|
+
readonly grounded: boolean;
|
|
317
|
+
/** The rig the walker draws: its `foot_*` and `ball_*` bones say where each print lies. */
|
|
318
|
+
readonly figure: Object3D;
|
|
319
|
+
}
|
|
320
|
+
export interface ISand {
|
|
321
|
+
/** Once a frame, after the walker moved and its rig posed. */
|
|
322
|
+
update(dt: number, walker: ISandWalker): void;
|
|
323
|
+
/** Prints pressed and grains thrown since the scene began, for a playtest to read. */
|
|
324
|
+
readonly stats: { readonly prints: number; readonly grains: number };
|
|
325
|
+
dispose(): void;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
interface IFoot {
|
|
329
|
+
readonly ankle: Object3D;
|
|
330
|
+
readonly ball: Object3D;
|
|
331
|
+
readonly last: Vector3;
|
|
332
|
+
down: boolean;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
* The loose sand under and round one walker: prints where their feet land, sand off a running
|
|
337
|
+
* step, and streamers on the wind. `heightAt` is the ground the kit draws.
|
|
338
|
+
*/
|
|
339
|
+
export async function createSand(
|
|
340
|
+
ctx: TerrainCtx,
|
|
341
|
+
assets: IAssetLoader,
|
|
342
|
+
heightAt: (x: number, z: number) => number,
|
|
343
|
+
/** The tint the ground lays on its sand scan (`IBiome.grassTint`), so a print matches it. */
|
|
344
|
+
sandTint: readonly [number, number, number],
|
|
345
|
+
): Promise<ISand> {
|
|
346
|
+
const maps = GROUND_MAPS.grass;
|
|
347
|
+
const [map, sky] = await Promise.all([
|
|
348
|
+
maps?.diffuse
|
|
349
|
+
? assets
|
|
350
|
+
.texture(maps.diffuse, { anisotropy: 8, data: false, wrap: RepeatWrapping })
|
|
351
|
+
.catch(() => undefined)
|
|
352
|
+
: undefined,
|
|
353
|
+
loadSkyLight(assets),
|
|
354
|
+
]);
|
|
355
|
+
const material = printMaterial(map, sky, sandTint);
|
|
356
|
+
const kick = ctx.add(new GPUParticles3D(kickedSand()));
|
|
357
|
+
const stats = { grains: 0, prints: 0 };
|
|
358
|
+
|
|
359
|
+
// --- the streamers' sheet ---------------------------------------------------------------------
|
|
360
|
+
const gust = uniform(1);
|
|
361
|
+
const centre = uniform(new Vector2());
|
|
362
|
+
const sheet = new Mesh(
|
|
363
|
+
new PlaneGeometry(STREAMERS.size, STREAMERS.size, STREAMERS.cells, STREAMERS.cells).rotateX(
|
|
364
|
+
-Math.PI / 2,
|
|
365
|
+
),
|
|
366
|
+
streamerMaterial(gust, centre),
|
|
367
|
+
);
|
|
368
|
+
sheet.name = "sand-streamers";
|
|
369
|
+
sheet.frustumCulled = false;
|
|
370
|
+
ctx.add(sheet as Object3D);
|
|
371
|
+
let laid = false;
|
|
372
|
+
/** Lays the sheet on the ground round (`x`, `z`), on whole cells so the sand never swims. */
|
|
373
|
+
const drape = (x: number, z: number): void => {
|
|
374
|
+
const cell = STREAMERS.size / STREAMERS.cells;
|
|
375
|
+
const [ox, oz] = [Math.round(x / cell) * cell, Math.round(z / cell) * cell];
|
|
376
|
+
if (laid && sheet.position.x === ox && sheet.position.z === oz) return;
|
|
377
|
+
laid = true;
|
|
378
|
+
sheet.position.set(ox, 0, oz);
|
|
379
|
+
const at = sheet.geometry.getAttribute("position") as BufferAttribute;
|
|
380
|
+
for (let i = 0; i < at.count; i++)
|
|
381
|
+
at.setY(i, heightAt(ox + at.getX(i), oz + at.getZ(i)) + STREAMERS.lift);
|
|
382
|
+
at.needsUpdate = true;
|
|
383
|
+
sheet.geometry.computeVertexNormals();
|
|
384
|
+
};
|
|
385
|
+
|
|
386
|
+
// --- the pressed square ------------------------------------------------------------------------
|
|
387
|
+
let field: SnowField | undefined;
|
|
388
|
+
let mesh: Mesh | undefined;
|
|
389
|
+
let state: BufferAttribute | undefined;
|
|
390
|
+
let indents: Float32Array = new Float32Array(0);
|
|
391
|
+
let banks: Float32Array = new Float32Array(0);
|
|
392
|
+
/** Lays the square round (`x`, `z`), on the sample grid so its vertices never swim. */
|
|
393
|
+
const lay = (x: number, z: number): void => {
|
|
394
|
+
const n = FIELD.samples;
|
|
395
|
+
const cell = FIELD.size / (n - 1);
|
|
396
|
+
const origin = { x: Math.round(x / cell) * cell, z: Math.round(z / cell) * cell };
|
|
397
|
+
const [minX, minZ] = [origin.x - FIELD.size / 2, origin.z - FIELD.size / 2];
|
|
398
|
+
// The ground every `COARSE` samples, then straight lines between: 2 600 reads, not 160 000.
|
|
399
|
+
const knots = (n - 1) / COARSE + 1;
|
|
400
|
+
const coarse = new Float32Array(knots * knots);
|
|
401
|
+
for (let r = 0; r < knots; r++)
|
|
402
|
+
for (let c = 0; c < knots; c++)
|
|
403
|
+
coarse[r * knots + c] = heightAt(minX + c * COARSE * cell, minZ + r * COARSE * cell);
|
|
404
|
+
const heights = new Float32Array(n * n);
|
|
405
|
+
for (let r = 0; r < n; r++) {
|
|
406
|
+
const r0 = Math.min(knots - 2, Math.floor(r / COARSE));
|
|
407
|
+
const tr = r / COARSE - r0;
|
|
408
|
+
for (let c = 0; c < n; c++) {
|
|
409
|
+
const c0 = Math.min(knots - 2, Math.floor(c / COARSE));
|
|
410
|
+
const tc = c / COARSE - c0;
|
|
411
|
+
const a = coarse[r0 * knots + c0] as number;
|
|
412
|
+
const b = coarse[r0 * knots + c0 + 1] as number;
|
|
413
|
+
const d = coarse[(r0 + 1) * knots + c0] as number;
|
|
414
|
+
const e = coarse[(r0 + 1) * knots + c0 + 1] as number;
|
|
415
|
+
heights[r * n + c] = (a + (b - a) * tc) * (1 - tr) + (d + (e - d) * tc) * tr;
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
const ground = new Heightfield({
|
|
419
|
+
columns: n,
|
|
420
|
+
depth: FIELD.size,
|
|
421
|
+
heights,
|
|
422
|
+
origin,
|
|
423
|
+
rows: n,
|
|
424
|
+
width: FIELD.size,
|
|
425
|
+
});
|
|
426
|
+
// ponytail: a new square starts smooth, so the prints behind the walker go when it moves.
|
|
427
|
+
// Carry the channels across with a `SnowField` window copy when a trail must outlast 5 m.
|
|
428
|
+
field = new SnowField({ depth: FIELD.depth, field: ground, hardness: FIELD.hardness });
|
|
429
|
+
field.takeDirtyRegions();
|
|
430
|
+
const geometry: BufferGeometry = ground.toGeometry();
|
|
431
|
+
state = new BufferAttribute(new Float32Array(n * n * 3), 3);
|
|
432
|
+
geometry.setAttribute(STATE, state);
|
|
433
|
+
if (mesh) {
|
|
434
|
+
mesh.geometry.dispose();
|
|
435
|
+
mesh.geometry = geometry;
|
|
436
|
+
} else {
|
|
437
|
+
mesh = new Mesh(geometry, material);
|
|
438
|
+
mesh.name = "sand-prints";
|
|
439
|
+
// The untouched vertices are sunk out of its bounds.
|
|
440
|
+
mesh.frustumCulled = false;
|
|
441
|
+
mesh.receiveShadow = true;
|
|
442
|
+
ctx.add(mesh as Object3D);
|
|
443
|
+
}
|
|
444
|
+
mesh.position.set(origin.x, 0, origin.z);
|
|
445
|
+
};
|
|
446
|
+
/** Draws what the field wrote since the last frame: a print is a few hundred samples. */
|
|
447
|
+
const redraw = (): void => {
|
|
448
|
+
if (!field || !mesh || !state) return;
|
|
449
|
+
const { columns, rows } = field;
|
|
450
|
+
for (const written of field.takeDirtyRegions()) {
|
|
451
|
+
const column = Math.max(0, written.column - 1);
|
|
452
|
+
const row = Math.max(0, written.row - 1);
|
|
453
|
+
const bounds = {
|
|
454
|
+
column,
|
|
455
|
+
columns: Math.min(columns, written.column + written.columns + 1) - column,
|
|
456
|
+
row,
|
|
457
|
+
rows: Math.min(rows, written.row + written.rows + 1) - row,
|
|
458
|
+
};
|
|
459
|
+
field.field.refreshGeometry(mesh.geometry, bounds);
|
|
460
|
+
indents = field.copyChannel("indent", bounds, indents);
|
|
461
|
+
banks = field.copyChannel("bank", bounds, banks);
|
|
462
|
+
const values = state.array as Float32Array;
|
|
463
|
+
for (let r = 0; r < bounds.rows; r++)
|
|
464
|
+
for (let c = 0; c < bounds.columns; c++) {
|
|
465
|
+
const vertex = (bounds.row + r) * columns + bounds.column + c;
|
|
466
|
+
values[vertex * 3] = indents[r * bounds.columns + c] as number;
|
|
467
|
+
values[vertex * 3 + 1] = banks[r * bounds.columns + c] as number;
|
|
468
|
+
values[vertex * 3 + 2] = 1;
|
|
469
|
+
}
|
|
470
|
+
for (const name of ["position", "normal", STATE]) {
|
|
471
|
+
const buffer = mesh.geometry.getAttribute(name) as BufferAttribute;
|
|
472
|
+
for (let r = bounds.row; r < bounds.row + bounds.rows; r++)
|
|
473
|
+
buffer.addUpdateRange(
|
|
474
|
+
(r * columns + bounds.column) * buffer.itemSize,
|
|
475
|
+
bounds.columns * buffer.itemSize,
|
|
476
|
+
);
|
|
477
|
+
buffer.needsUpdate = true;
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
};
|
|
481
|
+
|
|
482
|
+
// --- the feet ----------------------------------------------------------------------------------
|
|
483
|
+
let feet: IFoot[] | undefined;
|
|
484
|
+
let print: ReturnType<typeof footPrint> | undefined;
|
|
485
|
+
const [ankle, ball] = [new Vector3(), new Vector3()];
|
|
486
|
+
const throwSand = (x: number, z: number, count: number, speed: number): void => {
|
|
487
|
+
kick.emitParticle({
|
|
488
|
+
count,
|
|
489
|
+
direction: { x: 0.4 + speed * 0.14, y: 0.6 + speed * 0.12, z: 0.06 },
|
|
490
|
+
origin: { x, y: heightAt(x, z) + 0.02, z },
|
|
491
|
+
});
|
|
492
|
+
stats.grains += count;
|
|
493
|
+
};
|
|
494
|
+
/** Presses one foot where its bones stand (`ankle`, `ball`), heel to toe along the foot. */
|
|
495
|
+
const press = (foot: IFoot, load: number): void => {
|
|
496
|
+
if (!field || !mesh) return;
|
|
497
|
+
const [dx, dz] = [ball.x - ankle.x, ball.z - ankle.z];
|
|
498
|
+
const length = Math.hypot(dx, dz);
|
|
499
|
+
if (length < 0.04) return;
|
|
500
|
+
// The sole runs from a little behind the ankle to the toes past the ball.
|
|
501
|
+
print ??= footPrint(MathUtils.clamp(length * 0.92, 0.1, 0.16));
|
|
502
|
+
const [x, z] = [ankle.x + dx * 0.62, ankle.z + dz * 0.62];
|
|
503
|
+
const half = FIELD.size / 2 - print.extent;
|
|
504
|
+
if (Math.abs(x - mesh.position.x) > half || Math.abs(z - mesh.position.z) > half) return;
|
|
505
|
+
const sunk = field.stamp({
|
|
506
|
+
area: FOOT.area,
|
|
507
|
+
footprint: print,
|
|
508
|
+
load,
|
|
509
|
+
rotation: Math.atan2(dx, dz),
|
|
510
|
+
x,
|
|
511
|
+
z,
|
|
512
|
+
});
|
|
513
|
+
if (sunk > 0) stats.prints += 1;
|
|
514
|
+
foot.down = true;
|
|
515
|
+
};
|
|
516
|
+
const bones = (figure: Object3D): IFoot[] =>
|
|
517
|
+
FEET.flatMap(([a, b]) => {
|
|
518
|
+
const [ankleBone, ballBone] = [figure.getObjectByName(a), figure.getObjectByName(b)];
|
|
519
|
+
return ankleBone && ballBone
|
|
520
|
+
? [{ ankle: ankleBone, ball: ballBone, down: false, last: new Vector3(Number.NaN) }]
|
|
521
|
+
: [];
|
|
522
|
+
});
|
|
523
|
+
|
|
524
|
+
let airborne = false;
|
|
525
|
+
let fall = 0;
|
|
526
|
+
let settle = 0;
|
|
527
|
+
let clock = 0;
|
|
528
|
+
return {
|
|
529
|
+
stats,
|
|
530
|
+
update(dt, walker) {
|
|
531
|
+
const { x, z } = walker.position;
|
|
532
|
+
const inner = FIELD.size / 2 - EDGE;
|
|
533
|
+
if (!mesh || Math.abs(x - mesh.position.x) > inner || Math.abs(z - mesh.position.z) > inner)
|
|
534
|
+
lay(x, z);
|
|
535
|
+
feet ??= bones(walker.figure);
|
|
536
|
+
const speed = Math.hypot(walker.velocity.x, walker.velocity.z);
|
|
537
|
+
const landed = walker.grounded && airborne && fall > 3;
|
|
538
|
+
for (const foot of feet) {
|
|
539
|
+
foot.ankle.getWorldPosition(ankle);
|
|
540
|
+
foot.ball.getWorldPosition(ball);
|
|
541
|
+
const pace =
|
|
542
|
+
Number.isNaN(foot.last.x) || dt <= 0
|
|
543
|
+
? 0
|
|
544
|
+
: Math.hypot(ball.x - foot.last.x, ball.z - foot.last.z) / dt;
|
|
545
|
+
const lift = ball.y - heightAt(ball.x, ball.z);
|
|
546
|
+
foot.last.copy(ball);
|
|
547
|
+
if (foot.down && (pace > PLANT.swing || lift > PLANT.high)) foot.down = false;
|
|
548
|
+
if (!walker.grounded) continue;
|
|
549
|
+
if (landed) {
|
|
550
|
+
foot.down = false;
|
|
551
|
+
press(foot, FOOT.load * 3);
|
|
552
|
+
} else if (!foot.down && pace < PLANT.still && lift < PLANT.low) {
|
|
553
|
+
press(foot, FOOT.load * (speed > RUNNING ? 1.7 : 1));
|
|
554
|
+
if (foot.down && speed > RUNNING) throwSand(ball.x, ball.z, KICK.run, speed);
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
if (landed) throwSand(x, z, KICK.land, fall);
|
|
558
|
+
airborne = !walker.grounded;
|
|
559
|
+
fall = walker.grounded ? 0 : Math.max(fall, -walker.velocity.y);
|
|
560
|
+
settle += dt;
|
|
561
|
+
if (field && settle >= DRIFT.every) {
|
|
562
|
+
field.recover(settle, DRIFT.deposition, DRIFT.wind);
|
|
563
|
+
settle = 0;
|
|
564
|
+
}
|
|
565
|
+
redraw();
|
|
566
|
+
clock += dt;
|
|
567
|
+
drape(x, z);
|
|
568
|
+
centre.value.set(x, z);
|
|
569
|
+
gust.value = 0.6 + 0.4 * Math.sin(clock * 0.23) * Math.sin(clock * 0.071 + 1.3);
|
|
570
|
+
},
|
|
571
|
+
dispose() {
|
|
572
|
+
kick.removeFromParent();
|
|
573
|
+
sheet.removeFromParent();
|
|
574
|
+
sheet.geometry.dispose();
|
|
575
|
+
sheet.material.dispose();
|
|
576
|
+
mesh?.removeFromParent();
|
|
577
|
+
mesh?.geometry.dispose();
|
|
578
|
+
material.dispose();
|
|
579
|
+
},
|
|
580
|
+
};
|
|
581
|
+
}
|