roamwright 0.61.27 → 0.61.29
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 +2 -1
- package/examples/set-pieces.html +52 -0
- package/examples/set-pieces.js +284 -0
- package/geometry/builder.js +7 -12
- package/geometry/camp-layout.js +150 -0
- package/geometry/cavern-rock.js +309 -0
- package/geometry/cliff-sheets.js +457 -0
- package/geometry/creased-sheet.js +39 -0
- package/geometry/curtain-sheets.js +67 -0
- package/geometry/ice-cliff.js +339 -0
- package/geometry/ice-shards.js +247 -0
- package/geometry/index.js +35 -3
- package/geometry/instances.js +50 -1
- package/geometry/part-ops.js +152 -0
- package/geometry/plant-roots.js +115 -0
- package/geometry/primitives.js +4 -0
- package/geometry/rock-sheets.js +259 -0
- package/geometry/strata-rocks.js +4 -3
- package/math/index.js +1 -0
- package/math/scalar.js +3 -1
- package/package.json +1 -1
- package/rendering/camp-layout.js +55 -0
- package/rendering/curtain-sheets.js +271 -0
- package/rendering/flame-sources.js +105 -0
- package/rendering/flier-long-body-company.js +2 -0
- package/rendering/flocks.js +27 -22
- package/rendering/height-probe.js +7 -4
- package/rendering/house-kit-meshes.js +15 -10
- package/rendering/ice-material.js +143 -0
- package/rendering/index.js +24 -1
- package/rendering/lamp-wash.js +2 -0
- package/rendering/material-lod.js +50 -26
- package/rendering/rock-materials.js +27 -0
- package/rendering/ruins-fittings.js +110 -17
- package/rendering/scene-projectiles.js +3 -0
- package/rendering/settlement-town.js +6 -1
- package/rendering/ship-meshes.js +10 -7
- package/rendering/street-lamps.js +4 -1
- package/rendering/surface-material.js +60 -24
- package/rendering/surface-snippets.js +83 -45
- package/rendering/vehicle-train.js +1 -0
- package/rendering/water-material.js +9 -0
- package/runtime/index.js +1 -1
- package/runtime/lazy-sets.js +24 -0
- package/scripts/build.py +5 -3
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Camp and road-march rendering helpers: instanced fallen draught beasts rolled onto their sides
|
|
3
|
+
* along a route or halt using {@link placeInstances}.
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { placeInstances } from '../geometry/instances.js';
|
|
8
|
+
import { TRS as defaultTransform } from '../geometry/primitives.js';
|
|
9
|
+
|
|
10
|
+
/** Default hide sRGB palette, roll angle and ribcage barrel height (metres) for fallen draught beasts. */
|
|
11
|
+
export const FALLEN_BEAST_DEFAULTS = Object.freeze({
|
|
12
|
+
hides: Object.freeze([0x8a6a4a, 0xa89878, 0x5a4636]),
|
|
13
|
+
rollAngle: Math.PI / 2,
|
|
14
|
+
barrelHeight: 0.3,
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Place instanced fallen beasts laid on their sides at each `[x, z, yaw]` entry of `spots` within a
|
|
19
|
+
* local spot frame, cycling through `hides` for per-instance coat tinting.
|
|
20
|
+
*
|
|
21
|
+
* @param {object} options
|
|
22
|
+
* @param {import('three').BufferGeometry} options.geometry - Beast geometry (e.g. from `cattleGeometry`).
|
|
23
|
+
* @param {import('three').Material} options.material - Tinted instanced material.
|
|
24
|
+
* @param {import('three').Object3D | null} [options.parent=null] - Destination group.
|
|
25
|
+
* @param {{ x0: number, z0: number, Y: (x: number, z: number) => number }} options.spot - Local spot frame (`createSpotFrame`).
|
|
26
|
+
* @param {Array<[number, number, number]>} options.spots - Placement tuples `[localX, localZ, yaw]`.
|
|
27
|
+
* @param {readonly number[]} [options.hides=FALLEN_BEAST_DEFAULTS.hides] - Coat sRGB hex tones cycled across instances.
|
|
28
|
+
* @param {number} [options.barrelHeight=FALLEN_BEAST_DEFAULTS.barrelHeight] - Vertical centre offset above ground in metres.
|
|
29
|
+
* @param {number} [options.rollAngle=FALLEN_BEAST_DEFAULTS.rollAngle] - Roll angle in radians (`PI / 2` lies on the left side).
|
|
30
|
+
* @param {Function} [options.transform] - Transform matrix helper (`TRS`).
|
|
31
|
+
* @returns {import('three').InstancedMesh}
|
|
32
|
+
*/
|
|
33
|
+
export function placeFallenBeasts({
|
|
34
|
+
geometry,
|
|
35
|
+
material,
|
|
36
|
+
parent = null,
|
|
37
|
+
spot,
|
|
38
|
+
spots,
|
|
39
|
+
hides = FALLEN_BEAST_DEFAULTS.hides,
|
|
40
|
+
barrelHeight = FALLEN_BEAST_DEFAULTS.barrelHeight,
|
|
41
|
+
rollAngle = FALLEN_BEAST_DEFAULTS.rollAngle,
|
|
42
|
+
transform = defaultTransform,
|
|
43
|
+
}) {
|
|
44
|
+
return placeInstances({
|
|
45
|
+
geometry,
|
|
46
|
+
material,
|
|
47
|
+
capacity: spots.length,
|
|
48
|
+
parent,
|
|
49
|
+
place(put) {
|
|
50
|
+
spots.forEach(([x, z, turn], i) => {
|
|
51
|
+
put(transform(spot.x0 + x, spot.Y(x, z) + barrelHeight, spot.z0 + z, 1, 1, 1, turn, 0, rollAngle), hides[i % hides.length]);
|
|
52
|
+
});
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
}
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Animated dust and falling-water curtain sheets:
|
|
3
|
+
* 1) Concentric rising billowing dust curtains (`dustCurtainGeometry`, `createDustCurtainMaterial`,
|
|
4
|
+
* `createDustCurtain`) shaded with 3D value-noise fBm, silhouette grazing fade, and directional
|
|
5
|
+
* near-side thinning.
|
|
6
|
+
* 2) Glossy streaked falling-water curtains (`createFallingWaterMaterial`, `createFallingWaterSheets`)
|
|
7
|
+
* for fountains, spillways and cascades.
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import * as THREE from 'three';
|
|
12
|
+
import { DUST_CURTAIN_SHAPE, dustCurtainArrays } from '../geometry/curtain-sheets.js';
|
|
13
|
+
|
|
14
|
+
/** Small 3D hash-based value noise and 3-octave fBm GLSL snippet for local-space volumetric sheets. */
|
|
15
|
+
export const VALUE_NOISE_3D_GLSL = /* glsl */ `
|
|
16
|
+
float fh(vec3 p){ p = fract(p * 0.3183099 + 0.1); p *= 17.0; return fract(p.x * p.y * p.z * (p.x + p.y + p.z)); }
|
|
17
|
+
float fn3(vec3 x){
|
|
18
|
+
vec3 i = floor(x), f = fract(x); f = f * f * (3.0 - 2.0 * f);
|
|
19
|
+
return mix(mix(mix(fh(i), fh(i + vec3(1, 0, 0)), f.x), mix(fh(i + vec3(0, 1, 0)), fh(i + vec3(1, 1, 0)), f.x), f.y),
|
|
20
|
+
mix(mix(fh(i + vec3(0, 0, 1)), fh(i + vec3(1, 0, 1)), f.x), mix(fh(i + vec3(0, 1, 1)), fh(i + vec3(1, 1, 1)), f.x), f.y), f.z);
|
|
21
|
+
}
|
|
22
|
+
float ffbm(vec3 p){ return 0.5 * fn3(p) + 0.3 * fn3(p * 2.03 + 7.1) + 0.2 * fn3(p * 4.1 + 3.7); }
|
|
23
|
+
`;
|
|
24
|
+
|
|
25
|
+
/** Default parameters for {@link createDustCurtainMaterial} and {@link createDustCurtain}. */
|
|
26
|
+
export const DUST_CURTAIN_DEFAULTS = Object.freeze({
|
|
27
|
+
...DUST_CURTAIN_SHAPE,
|
|
28
|
+
beforeOpacity: 0.3,
|
|
29
|
+
renderOrder: 8,
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
/** Default parameters for {@link createFallingWaterMaterial}. */
|
|
33
|
+
export const FALLING_WATER_DEFAULTS = Object.freeze({
|
|
34
|
+
color: 0xe4f0f2,
|
|
35
|
+
roughness: 0.1,
|
|
36
|
+
metalness: 0,
|
|
37
|
+
opacity: 0.42,
|
|
38
|
+
cacheKey: 'falling-water',
|
|
39
|
+
renderOrder: 6,
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Build a Three.js `BufferGeometry` for concentric rising dust curtains using {@link dustCurtainArrays}.
|
|
44
|
+
*
|
|
45
|
+
* @param {Parameters<typeof dustCurtainArrays>[0]} [options]
|
|
46
|
+
* @returns {THREE.BufferGeometry}
|
|
47
|
+
*/
|
|
48
|
+
export function dustCurtainGeometry(options = {}) {
|
|
49
|
+
const { position, uv, index } = dustCurtainArrays(options);
|
|
50
|
+
const geo = new THREE.BufferGeometry();
|
|
51
|
+
geo.setAttribute('position', new THREE.BufferAttribute(position, 3));
|
|
52
|
+
geo.setAttribute('uv', new THREE.BufferAttribute(uv, 2));
|
|
53
|
+
geo.setIndex(new THREE.BufferAttribute(index, 1));
|
|
54
|
+
return geo;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Create the animated billowing dust curtain `THREE.ShaderMaterial`. Callers may supply shared
|
|
59
|
+
* `{ value }` uniform handles (`show`, `time`, `light`, `ahead`) to drive multiple storm elements
|
|
60
|
+
* in lockstep with zero per-frame allocations.
|
|
61
|
+
*
|
|
62
|
+
* @param {object} [options]
|
|
63
|
+
* @param {{ value: number }} [options.show] - Curtain rise/opacity uniform (`0..1`).
|
|
64
|
+
* @param {{ value: number }} [options.time] - Elapsed time uniform in seconds.
|
|
65
|
+
* @param {{ value: THREE.Color }} [options.light] - Ambient tint colour uniform.
|
|
66
|
+
* @param {{ value: THREE.Vector2 }} [options.ahead] - Horizontal unit vector toward the viewer/reference point.
|
|
67
|
+
* @param {number} [options.beforeOpacity=DUST_CURTAIN_DEFAULTS.beforeOpacity] - Opacity multiplier on the near side facing `ahead`.
|
|
68
|
+
* @returns {THREE.ShaderMaterial}
|
|
69
|
+
*/
|
|
70
|
+
export function createDustCurtainMaterial({
|
|
71
|
+
show = { value: 1 },
|
|
72
|
+
time = { value: 0 },
|
|
73
|
+
light = { value: new THREE.Color(1, 0.84, 0.66) },
|
|
74
|
+
ahead = { value: new THREE.Vector2(1, 0) },
|
|
75
|
+
beforeOpacity = DUST_CURTAIN_DEFAULTS.beforeOpacity,
|
|
76
|
+
} = {}) {
|
|
77
|
+
return new THREE.ShaderMaterial({
|
|
78
|
+
side: THREE.DoubleSide,
|
|
79
|
+
transparent: true,
|
|
80
|
+
depthWrite: false,
|
|
81
|
+
fog: true,
|
|
82
|
+
uniforms: {
|
|
83
|
+
...THREE.UniformsUtils.clone(THREE.UniformsLib.fog),
|
|
84
|
+
uShow: show,
|
|
85
|
+
uTime: time,
|
|
86
|
+
uLight: light,
|
|
87
|
+
uAhead: ahead,
|
|
88
|
+
uBefore: { value: beforeOpacity },
|
|
89
|
+
},
|
|
90
|
+
vertexShader: /* glsl */ `
|
|
91
|
+
#include <common>
|
|
92
|
+
#include <fog_pars_vertex>
|
|
93
|
+
uniform vec2 uAhead;
|
|
94
|
+
varying vec2 vSt; varying float vFace, vNear;
|
|
95
|
+
void main(){
|
|
96
|
+
vSt = uv;
|
|
97
|
+
vec3 out_ = normalize(vec3(position.x, 0.0, position.z));
|
|
98
|
+
vNear = dot(out_.xz, uAhead); // +1 on the side toward the spring
|
|
99
|
+
vec4 mvPosition = modelViewMatrix * vec4(position, 1.0);
|
|
100
|
+
vFace = abs(dot(normalize(normalMatrix * out_), normalize(-mvPosition.xyz)));
|
|
101
|
+
gl_Position = projectionMatrix * mvPosition;
|
|
102
|
+
#include <fog_vertex>
|
|
103
|
+
}`,
|
|
104
|
+
fragmentShader: /* glsl */ `
|
|
105
|
+
#include <common>
|
|
106
|
+
#include <fog_pars_fragment>
|
|
107
|
+
uniform float uShow, uTime, uBefore; uniform vec3 uLight;
|
|
108
|
+
varying vec2 vSt; varying float vFace, vNear;
|
|
109
|
+
${VALUE_NOISE_3D_GLSL}
|
|
110
|
+
void main(){
|
|
111
|
+
vec3 p = vec3(vSt.x - uTime * 0.25, vSt.y * 3.2 - uTime * 0.45, uTime * 0.05);
|
|
112
|
+
float n = ffbm(p), fine = fn3(p * 3.7 + n * 2.0), h = vSt.y / (0.35 + 0.65 * uShow); // the storm stands up as it rises
|
|
113
|
+
float crest = 1.0 - smoothstep(0.45 + 0.35 * n, 0.95 + 0.1 * fine, h); // torn into plumes at the top
|
|
114
|
+
float body = smoothstep(0.42, 0.78, n * 0.75 + fine * 0.25 + (1.0 - h) * 0.3); // billows, thicker low
|
|
115
|
+
float a = body * crest * uShow * 0.42 * smoothstep(0.08, 0.5, vFace) * mix(1.0, uBefore, smoothstep(-0.2, 0.5, vNear));
|
|
116
|
+
float lit = smoothstep(0.3, 0.85, n + h * 0.25 - fine * 0.15); // the billows' tops catch the light
|
|
117
|
+
vec3 col = mix(vec3(0.3, 0.19, 0.1), vec3(0.95, 0.72, 0.46), lit) * (0.85 + 0.3 * fine) * uLight;
|
|
118
|
+
gl_FragColor = vec4(col, a);
|
|
119
|
+
#include <tonemapping_fragment>
|
|
120
|
+
#include <colorspace_fragment>
|
|
121
|
+
#include <fog_fragment>
|
|
122
|
+
}`,
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Convenience builder creating a positioned dust-curtain mesh, geometry, material and zero-allocation
|
|
128
|
+
* `update(time, show, day)` helper.
|
|
129
|
+
*
|
|
130
|
+
* @param {object} [options]
|
|
131
|
+
* @param {THREE.Object3D | null} [options.parent=null] - Optional parent group.
|
|
132
|
+
* @param {number} [options.x=0] - World X position in metres.
|
|
133
|
+
* @param {number} [options.y=0] - Base elevation in metres.
|
|
134
|
+
* @param {number} [options.z=0] - World Z position in metres.
|
|
135
|
+
* @param {number} [options.renderOrder=DUST_CURTAIN_DEFAULTS.renderOrder] - Mesh `renderOrder`.
|
|
136
|
+
* @returns {{ mesh: THREE.Mesh, geometry: THREE.BufferGeometry, material: THREE.ShaderMaterial, update: (time: number, show?: number, day?: number) => void, dispose: () => void }}
|
|
137
|
+
*/
|
|
138
|
+
export function createDustCurtain(options = {}) {
|
|
139
|
+
const { parent = null, x = 0, y = 0, z = 0, renderOrder = DUST_CURTAIN_DEFAULTS.renderOrder } = options;
|
|
140
|
+
const geometry = dustCurtainGeometry(options);
|
|
141
|
+
const material = createDustCurtainMaterial(options);
|
|
142
|
+
const mesh = new THREE.Mesh(geometry, material);
|
|
143
|
+
mesh.position.set(x, y, z);
|
|
144
|
+
mesh.renderOrder = renderOrder;
|
|
145
|
+
if (parent) parent.add(mesh);
|
|
146
|
+
const u = material.uniforms;
|
|
147
|
+
return {
|
|
148
|
+
mesh,
|
|
149
|
+
geometry,
|
|
150
|
+
material,
|
|
151
|
+
update(time, show = 1, day = 1) {
|
|
152
|
+
u.uTime.value = time;
|
|
153
|
+
u.uShow.value = show;
|
|
154
|
+
u.uLight.value.setRGB(1, 0.84, 0.66).multiplyScalar(0.35 + 0.65 * day);
|
|
155
|
+
mesh.visible = show > 0.002;
|
|
156
|
+
},
|
|
157
|
+
dispose() {
|
|
158
|
+
mesh.removeFromParent();
|
|
159
|
+
geometry.dispose();
|
|
160
|
+
material.dispose();
|
|
161
|
+
},
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Create a glossy, transparent falling-water `MeshStandardMaterial` whose alpha breaks into downward
|
|
167
|
+
* streaming strands driven by `time.value` (seconds).
|
|
168
|
+
*
|
|
169
|
+
* @param {object} [options]
|
|
170
|
+
* @param {{ value: number }} [options.time] - Elapsed time uniform handle in seconds.
|
|
171
|
+
* @param {number} [options.color=FALLING_WATER_DEFAULTS.color] - Base water sRGB hex colour.
|
|
172
|
+
* @param {number} [options.roughness=FALLING_WATER_DEFAULTS.roughness] - Surface roughness.
|
|
173
|
+
* @param {number} [options.metalness=FALLING_WATER_DEFAULTS.metalness] - Metallic factor.
|
|
174
|
+
* @param {number} [options.opacity=FALLING_WATER_DEFAULTS.opacity] - Base sheet opacity.
|
|
175
|
+
* @param {string} [options.cacheKey=FALLING_WATER_DEFAULTS.cacheKey] - `customProgramCacheKey` value.
|
|
176
|
+
* @returns {THREE.MeshStandardMaterial}
|
|
177
|
+
*/
|
|
178
|
+
export function createFallingWaterMaterial({
|
|
179
|
+
time = { value: 0 },
|
|
180
|
+
color = FALLING_WATER_DEFAULTS.color,
|
|
181
|
+
roughness = FALLING_WATER_DEFAULTS.roughness,
|
|
182
|
+
metalness = FALLING_WATER_DEFAULTS.metalness,
|
|
183
|
+
opacity = FALLING_WATER_DEFAULTS.opacity,
|
|
184
|
+
cacheKey = FALLING_WATER_DEFAULTS.cacheKey,
|
|
185
|
+
} = {}) {
|
|
186
|
+
const mat = new THREE.MeshStandardMaterial({
|
|
187
|
+
color,
|
|
188
|
+
roughness,
|
|
189
|
+
metalness,
|
|
190
|
+
transparent: true,
|
|
191
|
+
opacity,
|
|
192
|
+
depthWrite: false,
|
|
193
|
+
side: THREE.DoubleSide,
|
|
194
|
+
});
|
|
195
|
+
mat.onBeforeCompile = sh => {
|
|
196
|
+
sh.uniforms.uFall = time;
|
|
197
|
+
sh.vertexShader = sh.vertexShader
|
|
198
|
+
.replace('#include <common>', '#include <common>\nvarying vec2 vFall;')
|
|
199
|
+
.replace('#include <begin_vertex>', '#include <begin_vertex>\nvFall = uv;');
|
|
200
|
+
sh.fragmentShader = sh.fragmentShader
|
|
201
|
+
.replace('#include <common>', '#include <common>\nvarying vec2 vFall;\nuniform float uFall;')
|
|
202
|
+
.replace(
|
|
203
|
+
'#include <alphatest_fragment>',
|
|
204
|
+
`/* glsl */
|
|
205
|
+
float strand = smoothstep(0.2, 0.95, 0.5 + 0.5 * sin(vFall.x * 211.0 + sin(vFall.x * 37.0) * 3.0));
|
|
206
|
+
float run = fract(vFall.y * 2.6 + uFall * 1.7 + sin(vFall.x * 91.0) * 0.4);
|
|
207
|
+
diffuseColor.a *= (0.2 + 0.8 * strand) * (0.4 + 0.6 * smoothstep(0.0, 0.6, run));
|
|
208
|
+
#include <alphatest_fragment>`,
|
|
209
|
+
);
|
|
210
|
+
};
|
|
211
|
+
mat.customProgramCacheKey = () => cacheKey;
|
|
212
|
+
return mat;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Assemble animated falling-water fountain curtains and foam splash rings sharing one
|
|
217
|
+
* {@link createFallingWaterMaterial} under `parent`.
|
|
218
|
+
*
|
|
219
|
+
* @param {THREE.Object3D | null} parent - Destination group (or `null`).
|
|
220
|
+
* @param {object} options
|
|
221
|
+
* @param {{ x: number, y?: number, z: number }} [options.origin={ x: 0, y: 0, z: 0 }] - World placement offset in metres.
|
|
222
|
+
* @param {Array<{ topRadius: number, bottomRadius: number, height: number, y: number, segments?: number }>} [options.cylinders=[]] - Open-ended conical fall curtains.
|
|
223
|
+
* @param {Array<{ innerRadius: number, outerRadius: number, y: number, segments?: number }>} [options.rings=[]] - Horizontal landing-foam rings.
|
|
224
|
+
* @param {number} [options.renderOrder=FALLING_WATER_DEFAULTS.renderOrder] - Mesh `renderOrder`.
|
|
225
|
+
* @param {string} [options.cacheKey=FALLING_WATER_DEFAULTS.cacheKey] - Shader program cache key.
|
|
226
|
+
* @returns {{ meshes: THREE.Mesh[], material: THREE.MeshStandardMaterial, setTime: (t: number) => void, dispose: () => void }}
|
|
227
|
+
*/
|
|
228
|
+
export function createFallingWaterSheets(
|
|
229
|
+
parent,
|
|
230
|
+
{
|
|
231
|
+
origin = { x: 0, y: 0, z: 0 },
|
|
232
|
+
cylinders = [],
|
|
233
|
+
rings = [],
|
|
234
|
+
renderOrder = FALLING_WATER_DEFAULTS.renderOrder,
|
|
235
|
+
cacheKey = FALLING_WATER_DEFAULTS.cacheKey,
|
|
236
|
+
color,
|
|
237
|
+
roughness,
|
|
238
|
+
metalness,
|
|
239
|
+
opacity,
|
|
240
|
+
} = {},
|
|
241
|
+
) {
|
|
242
|
+
const time = { value: 0 };
|
|
243
|
+
const material = createFallingWaterMaterial({ time, color, roughness, metalness, opacity, cacheKey });
|
|
244
|
+
const geometries = [
|
|
245
|
+
...cylinders.map(({ topRadius, bottomRadius, height, y, segments = 32 }) =>
|
|
246
|
+
new THREE.CylinderGeometry(topRadius, bottomRadius, height, segments, 1, true).translate(0, y, 0),
|
|
247
|
+
),
|
|
248
|
+
...rings.map(({ innerRadius, outerRadius, y, segments = 32 }) =>
|
|
249
|
+
new THREE.RingGeometry(innerRadius, outerRadius, segments).rotateX(-Math.PI / 2).translate(0, y, 0),
|
|
250
|
+
),
|
|
251
|
+
];
|
|
252
|
+
const meshes = geometries.map(geo => {
|
|
253
|
+
const m = new THREE.Mesh(geo, material);
|
|
254
|
+
m.position.set(origin.x, origin.y ?? 0, origin.z);
|
|
255
|
+
m.renderOrder = renderOrder;
|
|
256
|
+
if (parent) parent.add(m);
|
|
257
|
+
return m;
|
|
258
|
+
});
|
|
259
|
+
return {
|
|
260
|
+
meshes,
|
|
261
|
+
material,
|
|
262
|
+
setTime: t => {
|
|
263
|
+
time.value = t;
|
|
264
|
+
},
|
|
265
|
+
dispose() {
|
|
266
|
+
for (const m of meshes) m.removeFromParent();
|
|
267
|
+
for (const geo of geometries) geo.dispose();
|
|
268
|
+
material.dispose();
|
|
269
|
+
},
|
|
270
|
+
};
|
|
271
|
+
}
|
|
@@ -84,3 +84,108 @@ export function createFlameSources({ kinds = FLAME_KINDS, poolSpread = 1.3, ligh
|
|
|
84
84
|
|
|
85
85
|
return { sourceOf, flicker, hourShare };
|
|
86
86
|
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Create a fire effect-site record consumed by `createFlameSources` and particle emitters.
|
|
90
|
+
* Only optional keys that are explicitly provided are attached to the returned object.
|
|
91
|
+
*
|
|
92
|
+
* @param {object} options
|
|
93
|
+
* @param {string} [options.space='world'] - Host space id.
|
|
94
|
+
* @param {number} options.x - World X in metres.
|
|
95
|
+
* @param {number} options.y - World Y in metres.
|
|
96
|
+
* @param {number} options.z - World Z in metres.
|
|
97
|
+
* @param {string} [options.kind] - Optional flame kind override (e.g. `'brazier'`).
|
|
98
|
+
* @param {number} [options.rate=6] - Particle emission rate per second.
|
|
99
|
+
* @param {number} [options.size=0.45] - Flame size in metres.
|
|
100
|
+
* @param {number} [options.hot=1] - Heat buoyancy factor.
|
|
101
|
+
* @param {number} [options.soot=0.15] - Soot share.
|
|
102
|
+
* @param {number} [options.lift] - Optional light elevation override in metres.
|
|
103
|
+
* @param {number} [options.light] - Optional light strength override in `lightUnit`s.
|
|
104
|
+
* @returns {object} Fire site record.
|
|
105
|
+
*/
|
|
106
|
+
export function createFireSite({ space = 'world', x, y, z, kind, rate = 6, size = 0.45, hot = 1, soot = 0.15, lift, light }) {
|
|
107
|
+
const site = { space, type: 'fire', x, y, z, rate, size, hot, soot };
|
|
108
|
+
if (kind !== undefined) site.kind = kind;
|
|
109
|
+
if (lift !== undefined) site.lift = lift;
|
|
110
|
+
if (light !== undefined) site.light = light;
|
|
111
|
+
return site;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Create a rising smoke effect-site record paired with a fire or chimney.
|
|
116
|
+
*
|
|
117
|
+
* @param {object} options
|
|
118
|
+
* @param {string} [options.space='world'] - Host space id.
|
|
119
|
+
* @param {number} options.x - World X in metres.
|
|
120
|
+
* @param {number} options.y - World Y in metres.
|
|
121
|
+
* @param {number} options.z - World Z in metres.
|
|
122
|
+
* @param {number} [options.rate=0.8] - Puff emission rate per second.
|
|
123
|
+
* @param {number} [options.size=2] - Puff size in metres.
|
|
124
|
+
* @param {number} [options.heat=0.4] - Rise speed factor.
|
|
125
|
+
* @param {number} [options.dark=0.4] - Smoke darkness factor.
|
|
126
|
+
* @param {number} [options.thin] - Optional opacity multiplier.
|
|
127
|
+
* @returns {object} Smoke site record.
|
|
128
|
+
*/
|
|
129
|
+
export function createSmokeSite({ space = 'world', x, y, z, rate = 0.8, size = 2, heat = 0.4, dark = 0.4, thin }) {
|
|
130
|
+
const site = { space, type: 'smoke', x, y, z, rate, size, heat, dark };
|
|
131
|
+
if (thin !== undefined) site.thin = thin;
|
|
132
|
+
return site;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Append a fire effect site (and an optional paired smoke plume site) to `sites`.
|
|
137
|
+
*
|
|
138
|
+
* @param {object[]} sites - Mutable effect-sites array.
|
|
139
|
+
* @param {object} options
|
|
140
|
+
* @param {string} [options.space='world'] - Host space id.
|
|
141
|
+
* @param {number} options.x - World X in metres.
|
|
142
|
+
* @param {number} options.y - Base ground/hearth elevation in metres.
|
|
143
|
+
* @param {number} options.z - World Z in metres.
|
|
144
|
+
* @param {number} [options.fireY=0.15] - Vertical offset of the fire site above `y` in metres.
|
|
145
|
+
* @param {number} [options.size=0.5] - Flame size in metres.
|
|
146
|
+
* @param {number} [options.rate] - Fire emission rate (defaults to `4 + size * 10`).
|
|
147
|
+
* @param {string} [options.kind] - Optional flame kind override.
|
|
148
|
+
* @param {number} [options.hot=1] - Fire buoyancy factor.
|
|
149
|
+
* @param {number} [options.soot=0.15] - Fire soot share.
|
|
150
|
+
* @param {number} [options.lift] - Optional light height override.
|
|
151
|
+
* @param {number} [options.light] - Optional light strength override.
|
|
152
|
+
* @param {number | false | { y?: number, rate?: number, size?: number, heat?: number, dark?: number }} [options.smoke=1]
|
|
153
|
+
* - Smoke scale (`> 0`), explicit smoke config object, or `false` / `0` for no smoke site.
|
|
154
|
+
* @returns {{ fire: object, smoke: object | null }}
|
|
155
|
+
*/
|
|
156
|
+
export function addFireSites(
|
|
157
|
+
sites,
|
|
158
|
+
{ space = 'world', x, y, z, fireY = 0.15, size = 0.5, rate = 4 + size * 10, kind, hot = 1, soot = 0.15, lift, light, smoke = 1 },
|
|
159
|
+
) {
|
|
160
|
+
const fire = createFireSite({ space, x, y: y + fireY, z, kind, rate, size, hot, soot, lift, light });
|
|
161
|
+
sites.push(fire);
|
|
162
|
+
let smokeSite = null;
|
|
163
|
+
if (smoke !== false && smoke !== null && smoke !== 0) {
|
|
164
|
+
if (typeof smoke === 'number') {
|
|
165
|
+
smokeSite = createSmokeSite({
|
|
166
|
+
space,
|
|
167
|
+
x,
|
|
168
|
+
y: y + 1.2,
|
|
169
|
+
z,
|
|
170
|
+
rate: 0.8 * smoke,
|
|
171
|
+
size: 1.6 + size * 2 * smoke,
|
|
172
|
+
heat: 0.4,
|
|
173
|
+
dark: 0.4,
|
|
174
|
+
});
|
|
175
|
+
} else {
|
|
176
|
+
smokeSite = createSmokeSite({
|
|
177
|
+
space,
|
|
178
|
+
x,
|
|
179
|
+
y: y + (smoke.y ?? 1.2),
|
|
180
|
+
z,
|
|
181
|
+
rate: smoke.rate ?? 0.8,
|
|
182
|
+
size: smoke.size ?? 1.6 + size * 2,
|
|
183
|
+
heat: smoke.heat ?? 0.4,
|
|
184
|
+
dark: smoke.dark ?? 0.4,
|
|
185
|
+
thin: smoke.thin,
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
sites.push(smokeSite);
|
|
189
|
+
}
|
|
190
|
+
return { fire, smoke: smokeSite };
|
|
191
|
+
}
|
|
@@ -109,6 +109,8 @@ export function createLongFlierCompany({
|
|
|
109
109
|
opacity: 0.3,
|
|
110
110
|
depthWrite: false,
|
|
111
111
|
side: THREE.DoubleSide,
|
|
112
|
+
// Flat translucent wing blades have no closed back/front overlap, so one pass avoids a duplicate FLIP_SIDED program.
|
|
113
|
+
forceSinglePass: true,
|
|
112
114
|
}),
|
|
113
115
|
key + ':wings',
|
|
114
116
|
time,
|
package/rendering/flocks.js
CHANGED
|
@@ -179,46 +179,51 @@ export function createFlock({
|
|
|
179
179
|
}) {
|
|
180
180
|
const bird = !!look,
|
|
181
181
|
geometry = bird ? birdGeometry(look) : plainBirdGeometry(),
|
|
182
|
-
|
|
183
|
-
|
|
182
|
+
verts = geometry.attributes.position.count,
|
|
183
|
+
flap = new THREE.InstancedBufferAttribute(new Float32Array(n * 2), 2);
|
|
184
|
+
if (bird) flap.setUsage(THREE.DynamicDrawUsage);
|
|
185
|
+
geometry.setAttribute('aFlap', flap);
|
|
186
|
+
if (!geometry.attributes.color) geometry.setAttribute('color', new THREE.Float32BufferAttribute(new Float32Array(verts * 3).fill(1), 3));
|
|
187
|
+
if (!geometry.attributes.aUnder) geometry.setAttribute('aUnder', new THREE.Float32BufferAttribute(new Float32Array(verts * 4), 4));
|
|
184
188
|
const coloured = bird && !!look.colours,
|
|
185
|
-
under = bird && !!look.under,
|
|
186
189
|
material = new THREE.MeshStandardMaterial({
|
|
187
190
|
color: coloured ? 0xffffff : bird ? plumage(color, least) : color,
|
|
188
|
-
vertexColors:
|
|
191
|
+
vertexColors: true,
|
|
189
192
|
roughness: (bird && look.gloss) || roughness,
|
|
190
193
|
side: THREE.DoubleSide,
|
|
191
194
|
flatShading: true,
|
|
192
195
|
});
|
|
193
196
|
material.onBeforeCompile = sh => {
|
|
194
197
|
sh.uniforms.uTime = time;
|
|
195
|
-
|
|
198
|
+
sh.uniforms.uBeat = { value: bird ? look.beat * TAU : 0 };
|
|
199
|
+
sh.uniforms.uPlain = { value: bird ? 0 : 1 };
|
|
196
200
|
sh.vertexShader = sh.vertexShader
|
|
197
201
|
.replace(
|
|
198
202
|
'#include <common>',
|
|
199
|
-
'#include <common>\nattribute float aW; uniform float uTime;' +
|
|
200
|
-
|
|
201
|
-
(under ? UNDER_HEAD : ''),
|
|
203
|
+
'#include <common>\nattribute float aW; uniform float uTime; attribute vec2 aFlap; uniform float uBeat; uniform float uPlain;' +
|
|
204
|
+
UNDER_HEAD,
|
|
202
205
|
)
|
|
203
206
|
.replace(
|
|
204
207
|
'#include <begin_vertex>',
|
|
205
|
-
|
|
206
|
-
? '#include <begin_vertex>' + BEAT + (under ? '\n vUnder = aUnder;' : '')
|
|
207
|
-
: `/* glsl */
|
|
208
|
+
`/* glsl */
|
|
208
209
|
#include <begin_vertex>
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
210
|
+
if (uPlain > 0.5) {
|
|
211
|
+
#ifdef USE_INSTANCING
|
|
212
|
+
float ph = instanceMatrix[3].x * 0.31 + instanceMatrix[3].z * 0.17;
|
|
213
|
+
#else
|
|
214
|
+
float ph = 0.0;
|
|
215
|
+
#endif
|
|
216
|
+
transformed.y += aW * sin(uTime * 5.5 + ph) * 0.75;
|
|
217
|
+
} else {${BEAT}
|
|
218
|
+
}
|
|
219
|
+
vUnder = aUnder;`,
|
|
215
220
|
);
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
.replace('#include <color_fragment>', '#include <color_fragment>' + UNDER);
|
|
221
|
+
sh.fragmentShader = sh.fragmentShader
|
|
222
|
+
.replace('#include <common>', '#include <common>\nvarying vec4 vUnder;')
|
|
223
|
+
.replace('#include <color_fragment>', '#include <color_fragment>' + UNDER);
|
|
220
224
|
};
|
|
221
|
-
|
|
225
|
+
const cacheKey = key === 'bird' || key === 'plain' ? 'flock' : 'flock:' + key;
|
|
226
|
+
material.customProgramCacheKey = () => cacheKey;
|
|
222
227
|
const mesh = new THREE.InstancedMesh(geometry, material, n);
|
|
223
228
|
mesh.frustumCulled = false;
|
|
224
229
|
const birds = [];
|
|
@@ -51,16 +51,16 @@ export function createHeightProbe(renderer, scene, { layer, size, above, below,
|
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
function depth() {
|
|
54
|
-
return (depthMaterial ??= new THREE.MeshDepthMaterial({ depthPacking: THREE.RGBADepthPacking }));
|
|
54
|
+
return (depthMaterial ??= new THREE.MeshDepthMaterial({ depthPacking: THREE.RGBADepthPacking, side: THREE.DoubleSide }));
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
// Prepare the same depth override as a measurement
|
|
58
|
-
//
|
|
57
|
+
// Prepare the same depth override as a measurement (double-sided and without fog so depth
|
|
58
|
+
// programs are shared with sky-occlusion passes).
|
|
59
59
|
function warm(root, warmStandIns) {
|
|
60
60
|
const previous = view.layers.mask;
|
|
61
61
|
view.layers.enableAll();
|
|
62
62
|
try {
|
|
63
|
-
const geometry = warmStandIns(root, object => solidMesh(object) && depth(), view, undefined,
|
|
63
|
+
const geometry = warmStandIns(root, object => solidMesh(object) && depth(), view, undefined, null, true);
|
|
64
64
|
return useQueries ? Promise.all([geometry, depthResult().warm()]) : geometry;
|
|
65
65
|
} finally {
|
|
66
66
|
view.layers.mask = previous;
|
|
@@ -80,6 +80,7 @@ export function createHeightProbe(renderer, scene, { layer, size, above, below,
|
|
|
80
80
|
mip = renderer.getActiveMipmapLevel();
|
|
81
81
|
const alpha = renderer.getClearAlpha(),
|
|
82
82
|
background = scene.background,
|
|
83
|
+
fog = scene.fog,
|
|
83
84
|
override = scene.overrideMaterial;
|
|
84
85
|
const { autoUpdate, needsUpdate } = renderer.shadowMap;
|
|
85
86
|
renderer.getClearColor(clear);
|
|
@@ -88,6 +89,7 @@ export function createHeightProbe(renderer, scene, { layer, size, above, below,
|
|
|
88
89
|
scene.traverse(select);
|
|
89
90
|
scene.overrideMaterial = depth();
|
|
90
91
|
scene.background = null;
|
|
92
|
+
scene.fog = null;
|
|
91
93
|
renderer.shadowMap.autoUpdate = renderer.shadowMap.needsUpdate = false;
|
|
92
94
|
renderer.setRenderTarget(target);
|
|
93
95
|
renderer.setClearColor(0xffffff, 1);
|
|
@@ -99,6 +101,7 @@ export function createHeightProbe(renderer, scene, { layer, size, above, below,
|
|
|
99
101
|
renderer.setClearColor(clear, alpha);
|
|
100
102
|
scene.overrideMaterial = override;
|
|
101
103
|
scene.background = background;
|
|
104
|
+
scene.fog = fog;
|
|
102
105
|
renderer.shadowMap.autoUpdate = autoUpdate;
|
|
103
106
|
renderer.shadowMap.needsUpdate = needsUpdate;
|
|
104
107
|
for (let i = 0; i < prevLayers.length; i += 2) prevLayers[i].layers.mask = prevLayers[i + 1];
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
// A house kit's arrays as meshes: one mesh to a kind, instanced copies of them, or the cells of a cut kit as batches that
|
|
2
2
|
// cull cell by cell and are written to the graphics card a frame's share at a time.
|
|
3
3
|
import * as THREE from 'three';
|
|
4
|
-
import { geometryOf } from '../geometry/builder.js';
|
|
4
|
+
import { geometryOf, padParts } from '../geometry/builder.js';
|
|
5
5
|
import { KIT_KEYS } from '../geometry/house-kit-frame.js';
|
|
6
6
|
import { markStill } from './still-casters.js';
|
|
7
|
+
import { whiteInstanceColor } from './material-lod.js';
|
|
7
8
|
import { createHandOver } from '../runtime/hand-over.js';
|
|
8
9
|
|
|
9
10
|
const SYNC_HAND_OVER = createHandOver({ painted: () => Promise.resolve(), frameShare: () => Infinity });
|
|
@@ -63,7 +64,8 @@ export function createHouseKitMaterials({
|
|
|
63
64
|
* @param {() => boolean} [o.worldDrawn] Whether the world has been drawn yet: until it has, steps written to the card
|
|
64
65
|
* run all at once (behind a loading bar) rather than paced.
|
|
65
66
|
* @param {object} [o.handOver] The renderer's hand-over (`createHandOver`): `paced`, `drain` and `heldBytes`; defaults to a synchronous hand-over.
|
|
66
|
-
* @
|
|
67
|
+
* @param {boolean} [o.padded=false] Pad three-byte compact normal and colour arrays of static kit meshes and cells to four bytes per vertex, matching padded settlement-quarter blocks so both share one WebGL program per material.
|
|
68
|
+
* @returns {object} `materials` (the resolved material map), `kitStatic(kit, parent, materialOf, pad)`, `kitMeshes(parts, parent, materialOf, pad)`,
|
|
67
69
|
* `instancedOf(meshes, n, group)`, `kitInstanced(kit, n, group)`, `cellPieces(cellsOfKinds, parent, far, detail, materialOf)`,
|
|
68
70
|
* `pieceSwitch(batch, id)`, and `toCard(steps, signal)`.
|
|
69
71
|
*/
|
|
@@ -73,23 +75,25 @@ export function createHouseKitMeshes({
|
|
|
73
75
|
instancedMaterial = m => m,
|
|
74
76
|
worldDrawn = () => true,
|
|
75
77
|
handOver = SYNC_HAND_OVER,
|
|
78
|
+
padded = false,
|
|
79
|
+
tinted = false,
|
|
76
80
|
} = {}) {
|
|
77
81
|
const { drain, heldBytes, paced } = handOver,
|
|
78
82
|
ownMaterial = k => materials[k];
|
|
79
83
|
|
|
80
84
|
// A filled kit as meshes, one to a kind, and the kit let go; materialOf(kind) gives each kind's material, where a place has
|
|
81
85
|
// stone of its own.
|
|
82
|
-
function kitStatic(B, parent, materialOf) {
|
|
83
|
-
const parts = KIT_KEYS.map(k => B[k].parts(true));
|
|
86
|
+
function kitStatic(B, parent, materialOf, pad = padded) {
|
|
87
|
+
const parts = KIT_KEYS.map(k => B[k].parts(true, pad));
|
|
84
88
|
for (const k of KIT_KEYS) B[k].release();
|
|
85
|
-
return kitMeshes(parts, parent, materialOf);
|
|
89
|
+
return kitMeshes(parts, parent, materialOf, pad);
|
|
86
90
|
}
|
|
87
91
|
// A kit's arrays (GB.parts, a kind to each of KIT_KEYS) as meshes, one to a kind that has any.
|
|
88
|
-
function kitMeshes(parts, parent, materialOf = ownMaterial) {
|
|
92
|
+
function kitMeshes(parts, parent, materialOf = ownMaterial, pad = padded) {
|
|
89
93
|
const out = [];
|
|
90
94
|
KIT_KEYS.forEach((k, kind) => {
|
|
91
95
|
if (!parts[kind].position.length) return;
|
|
92
|
-
const m = new THREE.Mesh(geometryOf(parts[kind]), materialOf(k));
|
|
96
|
+
const m = new THREE.Mesh(geometryOf(pad ? padParts(parts[kind]) : parts[kind]), materialOf(k));
|
|
93
97
|
m.castShadow = k !== 'glass' && k !== 'trim' && k !== 'stain';
|
|
94
98
|
if (m.castShadow) markStill(m); // put in place once (still-casters.js)
|
|
95
99
|
m.receiveShadow = k !== 'stain';
|
|
@@ -105,6 +109,7 @@ export function createHouseKitMeshes({
|
|
|
105
109
|
function instancedOf(meshes, n, group) {
|
|
106
110
|
return meshes.map(mesh => {
|
|
107
111
|
const many = new THREE.InstancedMesh(mesh.geometry, instancedMaterial(mesh.material), n);
|
|
112
|
+
if (tinted) whiteInstanceColor(many);
|
|
108
113
|
many.frustumCulled = false;
|
|
109
114
|
many.castShadow = many.receiveShadow = true;
|
|
110
115
|
many.count = 0;
|
|
@@ -114,8 +119,8 @@ export function createHouseKitMeshes({
|
|
|
114
119
|
return many;
|
|
115
120
|
});
|
|
116
121
|
}
|
|
117
|
-
// A filled kit as instanced meshes of up to n under group (instancedOf);
|
|
118
|
-
const kitInstanced = (B, n, group) => instancedOf(kitStatic(B, new THREE.Group()), n, group);
|
|
122
|
+
// A filled kit as instanced meshes of up to n under group (instancedOf); kept unpadded so instanced props share 3-byte colour programs with other instanced meshes.
|
|
123
|
+
const kitInstanced = (B, n, group) => instancedOf(kitStatic(B, new THREE.Group(), undefined, false), n, group);
|
|
119
124
|
// Runs steps that write to the card (cellPieces, or a place's near detail made of them): no faster than the hand-over lets a
|
|
120
125
|
// frame take once the world is drawn, and all at once while the page is still loading behind its bar, where pacing would
|
|
121
126
|
// only lengthen the wait. The promise gives what the steps return.
|
|
@@ -147,7 +152,7 @@ export function createHouseKitMeshes({
|
|
|
147
152
|
batches[small] = batch;
|
|
148
153
|
}
|
|
149
154
|
for (const c of cells) {
|
|
150
|
-
const geometry = geometryOf(c.parts, c.sphere),
|
|
155
|
+
const geometry = geometryOf(padded ? padParts(c.parts) : c.parts, c.sphere),
|
|
151
156
|
bytes = bytesOf(geometry),
|
|
152
157
|
batch = batches[c.small],
|
|
153
158
|
id = batch.add(geometry);
|