roamwright 0.55.1 → 0.57.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/README.md +2 -1
  2. package/examples/animals.js +27 -15
  3. package/examples/crowds.js +28 -18
  4. package/examples/effects.js +13 -11
  5. package/examples/figure-motion.js +17 -5
  6. package/examples/figure.js +12 -8
  7. package/examples/fliers.js +16 -12
  8. package/examples/fortification.js +31 -18
  9. package/examples/house-kit.js +17 -10
  10. package/examples/island.js +25 -12
  11. package/examples/land.js +14 -8
  12. package/examples/pacing.html +100 -0
  13. package/examples/pacing.js +305 -0
  14. package/examples/props-and-plants.js +21 -32
  15. package/examples/rooms.js +2 -2
  16. package/examples/ships.js +33 -15
  17. package/examples/small-world-land.js +3 -3
  18. package/examples/small-world-life.js +13 -5
  19. package/examples/small-world-town.js +8 -11
  20. package/examples/small-world.js +26 -19
  21. package/examples/soundscape.js +18 -18
  22. package/examples/stage-kits.js +5 -133
  23. package/examples/stage.js +1 -324
  24. package/examples/towns.js +25 -18
  25. package/examples/viaduct-landscape.js +1 -1
  26. package/examples/viaduct.js +3 -4
  27. package/geometry/builder.js +8 -18
  28. package/geometry/plant-broadleaf.js +10 -4
  29. package/geometry/plant-trees.js +15 -9
  30. package/geometry/still-mesh.js +35 -0
  31. package/index.js +19 -2
  32. package/motion/figure-mount.js +1 -0
  33. package/package.json +1 -1
  34. package/rendering/crowd-system.js +239 -0
  35. package/rendering/daylight-sky.js +212 -0
  36. package/rendering/house-kit-meshes.js +65 -16
  37. package/rendering/orbit-camera.js +216 -0
  38. package/rendering/perf-box-worker.js +95 -0
  39. package/rendering/perf-box.js +94 -0
  40. package/rendering/perf-probe-passes.js +333 -0
  41. package/rendering/perf-probe.js +406 -0
  42. package/rendering/water-simple.js +112 -0
  43. package/runtime/device-quality.js +75 -4
  44. package/runtime/perf-box-text.js +50 -0
  45. package/runtime/perf-probe.js +145 -0
  46. package/runtime/perf-watch.js +158 -0
  47. package/runtime/quality-fit.js +25 -5
  48. package/runtime/quality-store.js +37 -9
package/examples/ships.js CHANGED
@@ -1,13 +1,24 @@
1
1
  import * as THREE from 'three';
2
- import { createHouseKit, createShipKit, createShipMeshes, GeometryBuilder, SHIP_PRESETS } from 'roamwright';
2
+ import {
3
+ createDaylightSky,
4
+ createHouseKit,
5
+ createHouseKitMaterials,
6
+ createHouseKitMeshes,
7
+ createOrbitCamera,
8
+ createShipKit,
9
+ createShipMeshes,
10
+ createSimpleWater,
11
+ GeometryBuilder,
12
+ SHIP_PRESETS,
13
+ } from 'roamwright';
3
14
  import { sstep } from 'roamwright/math/scalar.js';
4
15
  import { C, TRS } from 'roamwright/geometry/primitives.js';
5
16
  import { oneOf } from 'roamwright/geometry/ship-kit.js';
6
17
  import { YARD_STOWED } from 'roamwright/geometry/ship-rig.js';
7
18
  import { createBoatSailing, openWaterCourse } from 'roamwright/motion/boat-sailing.js';
8
19
  import { createProps } from 'roamwright/geometry/props.js';
9
- import { createOrbitRig, initExample, makeRollingGround, makeSky, makeWaterMesh, setupSun } from './stage.js';
10
- import { buildKitGroup, createShowcaseHouseMaterials, scatterTrees } from './stage-kits.js';
20
+ import { initExample, makeRollingGround } from './stage.js';
21
+ import { scatterTrees } from './stage-kits.js';
11
22
 
12
23
  const { canvas, renderer, camera, scene, worldGroup, seed, random, noise, hash, shapes } = initExample({
13
24
  fallbackSeed: 42,
@@ -45,7 +56,7 @@ const coast = makeRollingGround({
45
56
  worldGroup.add(coast);
46
57
 
47
58
  // Shimmering harbour water grading from turquoise coastal shallows to deep sea blue.
48
- const { mesh: water, timeUniform: waterTime } = makeWaterMesh({
59
+ const { mesh: water, timeUniform: waterTime } = createSimpleWater({
49
60
  width: 1600,
50
61
  depth: 1600,
51
62
  segs: 128,
@@ -111,8 +122,11 @@ const quayHouses = [
111
122
  party: [0, 0, 0],
112
123
  seed: seed * 19 + i,
113
124
  }));
114
- const houseMats = createShowcaseHouseMaterials(houseKit.KIT_KEYS, { doubleSide: true, roughness: 0.9 });
115
- const portGroup = buildKitGroup({ kits: houseKit.housesFromSpecs(quayHouses).kits, materials: houseMats, parent: worldGroup });
125
+ const houseMats = createHouseKitMaterials({ doubleSide: true, roughness: 0.9 });
126
+ const { kitMeshes, kitStatic } = createHouseKitMeshes({ materials: houseMats });
127
+ const portGroup = new THREE.Group();
128
+ kitMeshes(houseKit.housesFromSpecs(quayHouses).kits, portGroup);
129
+ worldGroup.add(portGroup);
116
130
  const propKit = houseKit.kitNew();
117
131
  for (const [px, pz, ry, fn] of [
118
132
  [-28, 25, 0.2, props.propCrates],
@@ -123,7 +137,7 @@ for (const [px, pz, ry, fn] of [
123
137
  ]) {
124
138
  houseKit.kitAt(propKit, px, 1.65, pz, ry, false, fn, random);
125
139
  }
126
- buildKitGroup({ kitKeys: houseKit.KIT_KEYS, kit: propKit, materials: houseMats, parent: portGroup });
140
+ kitStatic(propKit, portGroup);
127
141
 
128
142
  // Coastal pines and cedars along the headland behind the warehouses.
129
143
  scatterTrees({
@@ -185,17 +199,21 @@ for (const [i, spec, top] of [
185
199
  sailing.add(Object.assign(boat, sailing.keeping(null, c, top, random)));
186
200
  }
187
201
 
188
- scene.background = makeSky(noise, {
189
- zenith: [0.24, 0.48, 0.72],
190
- horizon: [0.85, 0.88, 0.86],
191
- sunDir: [-0.72, 0.34, -0.6],
192
- });
193
- scene.fog = new THREE.FogExp2(0xcfdcd9, 0.0014);
194
- setupSun(scene, renderer, {
202
+ createDaylightSky({
203
+ scene,
204
+ renderer,
205
+ noise,
206
+ sky: {
207
+ zenith: [0.24, 0.48, 0.72],
208
+ horizon: [0.85, 0.88, 0.86],
209
+ sunDir: [-0.72, 0.34, -0.6],
210
+ },
195
211
  sunPosition: [-75, 48, -62],
196
212
  shadowRadius: 85,
197
213
  shadowFar: 260,
198
214
  normalBias: 0.05,
215
+ fogColor: 0xcfdcd9,
216
+ fogDensity: 0.0014,
199
217
  });
200
218
 
201
219
  const views = {
@@ -204,7 +222,7 @@ const views = {
204
222
  sailing: { eye: [36, 12, -16], target: [-8, 4, -56] },
205
223
  };
206
224
 
207
- const rig = createOrbitRig({
225
+ const rig = createOrbitCamera({
208
226
  camera,
209
227
  canvas,
210
228
  renderer,
@@ -1,9 +1,9 @@
1
1
  import * as THREE from 'three';
2
- import { GeometryBuilder, mulberry32 } from 'roamwright';
2
+ import { createSimpleWater, GeometryBuilder, mulberry32 } from 'roamwright';
3
3
  import { sstep } from 'roamwright/math/scalar.js';
4
4
  import { C, TRS } from 'roamwright/geometry/primitives.js';
5
5
  import { createReeds } from 'roamwright/rendering/plant-reeds.js';
6
- import { makeRollingGround, makeWaterMesh } from './stage.js';
6
+ import { makeRollingGround } from './stage.js';
7
7
  import { buildCircularFence, scatterTrees, scatterTussocks } from './stage-kits.js';
8
8
 
9
9
  /**
@@ -48,7 +48,7 @@ export function buildSmallWorldLand({ world, worldGroup, seed, rng, noise, hash,
48
48
  });
49
49
  worldGroup.add(terrain);
50
50
 
51
- const { mesh: seaMesh, timeUniform: waterTime } = makeWaterMesh({
51
+ const { mesh: seaMesh, timeUniform: waterTime } = createSimpleWater({
52
52
  width: 1400,
53
53
  depth: 1400,
54
54
  segs: 140,
@@ -1,11 +1,19 @@
1
1
  import * as THREE from 'three';
2
- import { createShipKit, createShipMeshes, farCrowdFigure, grazeRound, horsePose, planTownsfolk, rigHorse, SHIP_PRESETS } from 'roamwright';
2
+ import {
3
+ createCrowdSystem,
4
+ createShipKit,
5
+ createShipMeshes,
6
+ grazeRound,
7
+ horsePose,
8
+ planTownsfolk,
9
+ rigHorse,
10
+ SHIP_PRESETS,
11
+ } from 'roamwright';
3
12
  import { oneOf } from 'roamwright/geometry/ship-kit.js';
4
13
  import { YARD_STOWED } from 'roamwright/geometry/ship-rig.js';
5
14
  import { createBoatSailing, openWaterCourse } from 'roamwright/motion/boat-sailing.js';
6
15
  import { BIRD_LOOKS } from 'roamwright/rendering/flier-bird-looks.js';
7
16
  import { createFlock } from 'roamwright/rendering/flocks.js';
8
- import { setupShowcaseCrowd } from './stage-kits.js';
9
17
 
10
18
  /**
11
19
  * Builds the living cast of the Small World showcase: walking market crowd,
@@ -13,8 +21,8 @@ import { setupShowcaseCrowd } from './stage-kits.js';
13
21
  * and coastal gulls.
14
22
  */
15
23
  export function buildSmallWorldLife({ world, worldGroup, rng, noise, hash, groundAt, spaceKit, camera, renderer }) {
16
- const crowdSystem = setupShowcaseCrowd({ worldGroup, groundAt, spaceKit, camera, renderer });
17
- const { crowds, addCrowd, herdSkins, streetBeasts, batches } = crowdSystem;
24
+ const crowdSystem = createCrowdSystem({ scene: worldGroup, groundAt, spaceKit, camera, renderer });
25
+ const { addCrowd, herdSkins, streetBeasts } = crowdSystem;
18
26
 
19
27
  const marketFolk = planTownsfolk({
20
28
  rng,
@@ -64,7 +72,7 @@ export function buildSmallWorldLife({ world, worldGroup, rng, noise, hash, groun
64
72
  return grazeRound(rng, world.pasture.x - 8 + Math.cos(a) * r, world.pasture.z + 7 + Math.sin(a) * r, 0.7, 0.12);
65
73
  });
66
74
  addCrowd(sheep, [0xf2ece0, 0xe6dfd0], world.pasture.x - 8, world.pasture.z + 7, 340, 'herd', herdSkins.herdLook('sheep'));
67
- batches.buildCrowdBatches([farCrowdFigure('distant'), farCrowdFigure('remote')], crowds);
75
+ crowdSystem.build();
68
76
 
69
77
  // Two rigged horses grazing in the pasture.
70
78
  const horseSkin = new THREE.MeshStandardMaterial({ vertexColors: true, roughness: 0.85 });
@@ -1,8 +1,8 @@
1
1
  import * as THREE from 'three';
2
- import { createHouseKit, createStreetLamps, GeometryBuilder } from 'roamwright';
2
+ import { createHouseKit, createHouseKitMaterials, createHouseKitMeshes, createStreetLamps, GeometryBuilder } from 'roamwright';
3
3
  import { townFrame } from 'roamwright/geometry/land-town-ground.js';
4
4
  import { createProps } from 'roamwright/geometry/props.js';
5
- import { buildKitGroup, createShowcaseFortification, createShowcaseHouseMaterials } from './stage-kits.js';
5
+ import { createShowcaseFortification } from './stage-kits.js';
6
6
 
7
7
  const STYLES = {
8
8
  town: {
@@ -81,15 +81,14 @@ export function buildSmallWorldTown({ world, worldGroup, seed, rng, noise, hash,
81
81
  streetLit: true,
82
82
  }));
83
83
 
84
- const houseMats = createShowcaseHouseMaterials(houseKit.KIT_KEYS, { roughness: 0.9 });
84
+ const houseMats = createHouseKitMaterials({ roughness: 0.9 });
85
85
  const glass = new THREE.MeshStandardMaterial({ vertexColors: true, roughness: 0.2, emissive: 0xffb25a, emissiveIntensity: 0 });
86
86
  houseMats.glass = glass;
87
+ const { kitMeshes, kitStatic } = createHouseKitMeshes({ materials: houseMats });
87
88
 
88
- const townGroup = buildKitGroup({
89
- kits: houseKit.housesFromSpecs(houseSpecs).kits,
90
- materials: houseMats,
91
- parent: worldGroup,
92
- });
89
+ const townGroup = new THREE.Group();
90
+ kitMeshes(houseKit.housesFromSpecs(houseSpecs).kits, townGroup);
91
+ worldGroup.add(townGroup);
93
92
 
94
93
  // Market stalls, well, cart, quay cargo and pasture haycock.
95
94
  const props = createProps({ houseKit, shapes, vnoise: noise.vnoise, hash, horse: () => {} });
@@ -101,14 +100,12 @@ export function buildSmallWorldTown({ world, worldGroup, seed, rng, noise, hash,
101
100
  houseKit.kitAt(propKit, 11, groundAt(11, -10), -10, -0.4, false, props.propCart, rng);
102
101
  houseKit.kitAt(propKit, -16, 1.95, 22, 0.3, false, props.propCrates, rng);
103
102
  houseKit.kitAt(propKit, 20, 1.95, 22, -0.2, false, props.propCrates, rng);
104
- buildKitGroup({ kitKeys: houseKit.KIT_KEYS, kit: propKit, materials: houseMats, parent: townGroup });
103
+ kitStatic(propKit, townGroup);
105
104
 
106
105
  const hayBuilder = new GeometryBuilder();
107
106
  props.haycock(hayBuilder, false);
108
107
  const hayMesh = hayBuilder.mesh(new THREE.MeshStandardMaterial({ vertexColors: true, roughness: 0.9 }), townGroup);
109
108
  hayMesh.position.set(world.pasture.x + 14, groundAt(world.pasture.x + 14, world.pasture.z - 10), world.pasture.z - 10);
110
- hayMesh.updateMatrix();
111
- hayMesh.castShadow = hayMesh.receiveShadow = true;
112
109
 
113
110
  // Street lamps along the quay and market square.
114
111
  const lampUniforms = { night: { value: 0 }, time: { value: 0 }, sky: { value: new THREE.Color(0x223344) } };
@@ -1,8 +1,8 @@
1
1
  import * as THREE from 'three';
2
- import { createSpaces } from 'roamwright';
2
+ import { createDaylightSky, createOrbitCamera, createSkyPanorama, createSpaces } from 'roamwright';
3
3
  import { litShare } from 'roamwright/math/lit-share.js';
4
4
  import { createSunMoonCycle } from 'roamwright/rendering/daylight.js';
5
- import { createOrbitRig, initExample, makeSky, setupSun } from './stage.js';
5
+ import { initExample } from './stage.js';
6
6
  import { buildSmallWorldLand } from './small-world-land.js';
7
7
  import { buildSmallWorldTown } from './small-world-town.js';
8
8
  import { buildSmallWorldLife } from './small-world-life.js';
@@ -94,14 +94,30 @@ const { glass, lampUniforms } = buildSmallWorldTown({ world: WORLD, worldGroup,
94
94
  const life = buildSmallWorldLife({ world: WORLD, worldGroup, rng, noise, hash, groundAt, spaceKit, camera, renderer });
95
95
 
96
96
  // Sky, daylight cycle, crowd updater and camera.
97
- const daySky = makeSky(noise, {
98
- zenith: [0.22, 0.46, 0.72],
99
- horizon: [0.88, 0.84, 0.76],
100
- cloudColor: [1.0, 0.94, 0.84],
101
- sunGlow: [1.0, 0.8, 0.52],
102
- sunDir: [-0.74, 0.26, 0.61],
97
+ const {
98
+ sky: daySky,
99
+ sun,
100
+ hemi,
101
+ lightDir,
102
+ } = createDaylightSky({
103
+ scene,
104
+ renderer,
105
+ noise,
106
+ sky: {
107
+ zenith: [0.22, 0.46, 0.72],
108
+ horizon: [0.88, 0.84, 0.76],
109
+ cloudColor: [1.0, 0.94, 0.84],
110
+ sunGlow: [1.0, 0.8, 0.52],
111
+ sunDir: [-0.74, 0.26, 0.61],
112
+ },
113
+ sunPosition: [-120, 56, 95],
114
+ shadowRadius: 140,
115
+ shadowFar: 420,
116
+ normalBias: 0.07,
117
+ fogColor: 0xd8ddd6,
118
+ fogDensity: 0.0011,
103
119
  });
104
- const nightSky = makeSky(noise, {
120
+ const nightSky = createSkyPanorama(noise, {
105
121
  zenith: [0.03, 0.06, 0.14],
106
122
  horizon: [0.09, 0.14, 0.24],
107
123
  ground: [0.05, 0.07, 0.11],
@@ -111,15 +127,6 @@ const nightSky = makeSky(noise, {
111
127
  cloudCover: 0.58,
112
128
  stars: 0.9,
113
129
  });
114
-
115
- scene.fog = new THREE.FogExp2(0xd8ddd6, 0.0011);
116
- const { sun, hemi } = setupSun(scene, renderer, {
117
- sunPosition: [-120, 56, 95],
118
- shadowRadius: 140,
119
- shadowFar: 420,
120
- normalBias: 0.07,
121
- });
122
- const lightDir = sun.position.clone().normalize();
123
130
  const sunMoon = createSunMoonCycle({ sunRise: 0.85, sunOffset: 0.48, sunTilt: 0.22 });
124
131
  const sunVec = new THREE.Vector3(),
125
132
  moonVec = new THREE.Vector3();
@@ -186,7 +193,7 @@ const updater = life.createUpdater({
186
193
  shadowFar: 420,
187
194
  });
188
195
 
189
- const rig = createOrbitRig({
196
+ const rig = createOrbitCamera({
190
197
  camera,
191
198
  canvas,
192
199
  renderer,
@@ -1,11 +1,16 @@
1
1
  import * as THREE from 'three';
2
2
  import {
3
+ createDaylightSky,
3
4
  createFigureAssembler,
4
5
  createFigureBuilder,
5
6
  createFigurePose,
6
7
  createHouseKit,
8
+ createHouseKitMaterials,
9
+ createHouseKitMeshes,
10
+ createOrbitCamera,
7
11
  createShipKit,
8
12
  createShipMeshes,
13
+ createSimpleWater,
9
14
  figureActor,
10
15
  GeometryBuilder,
11
16
  geometryOf,
@@ -22,8 +27,8 @@ import { createWind } from '../motion/wind.js';
22
27
  import { createScriptFoley } from '../runtime/foley-script.js';
23
28
  import { createStrideFoley } from '../runtime/foley-strides.js';
24
29
  import { createSoundscape } from '../runtime/soundscape.js';
25
- import { createOrbitRig, initExample, makeRollingGround, makeSky, makeWaterMesh, setupSun } from './stage.js';
26
- import { buildKitGroup, createShowcaseHouseMaterials, scatterTrees } from './stage-kits.js';
30
+ import { initExample, makeRollingGround } from './stage.js';
31
+ import { scatterTrees } from './stage-kits.js';
27
32
 
28
33
  const { canvas, renderer, camera, scene, worldGroup, seed, random, noise, hash, shapes } = initExample({
29
34
  fallbackSeed: 42,
@@ -79,7 +84,7 @@ const terrain = makeRollingGround({
79
84
  worldGroup.add(terrain);
80
85
 
81
86
  // Shimmering lake water covering the western shore.
82
- const { mesh: lakeMesh, timeUniform: waterTime } = makeWaterMesh({
87
+ const { mesh: lakeMesh, timeUniform: waterTime } = createSimpleWater({
83
88
  width: 240,
84
89
  depth: 280,
85
90
  segs: 80,
@@ -134,12 +139,7 @@ houseKit.kitAt(propKit, 7.5, groundAt(7.5, -5.5), -5.5, -0.45, false, (B, R) =>
134
139
  houseKit.kitAt(propKit, 3.2, groundAt(3.2, -3.5), -3.5, 0.2, false, (B, R) => props.propBrazier(B, R), random);
135
140
  houseKit.kitAt(propKit, 5.2, groundAt(5.2, -2.2), -2.2, 0.5, false, (B, R) => props.propWoodpile(B, R), random);
136
141
  houseKit.kitAt(propKit, -6.5, groundAt(-6.5, -5.5), -5.5, 0.2, false, props.propCrates, random);
137
- buildKitGroup({
138
- kitKeys: houseKit.KIT_KEYS,
139
- kit: propKit,
140
- materials: createShowcaseHouseMaterials(houseKit.KIT_KEYS, { doubleSide: true }),
141
- parent: worldGroup,
142
- });
142
+ createHouseKitMeshes({ materials: createHouseKitMaterials({ doubleSide: true }) }).kitStatic(propKit, worldGroup);
143
143
 
144
144
  // Trees framing the lakeside meadow and swaying reeds along the water's edge.
145
145
  scatterTrees({
@@ -211,8 +211,6 @@ const { wind, update: updateWind } = createWind({ speed: 2.0, direction: 0.5 });
211
211
  let simTime = 0;
212
212
  const motion = createFigurePose({ ground: groundAt, wind, clock: () => simTime });
213
213
  motion.setAfoot(walker, 'beside');
214
- // Keep the horse's world matrix current before the initial poseActor call so stepRig sees zero velocity.
215
- worldGroup.updateMatrixWorld(true);
216
214
 
217
215
  // Visual acoustic rings expanding where voices or footsteps fire.
218
216
  const ringGeo = new THREE.RingGeometry(0.32, 0.42, 32).rotateX(-Math.PI / 2);
@@ -395,10 +393,8 @@ function crossShore(mounted) {
395
393
  walker.x = -15.5;
396
394
  walker.z = 1.5;
397
395
  walker.yaw = Math.PI / 2;
398
- if (mounted && !walker.mount) motion.setMounted(walker);
396
+ if (mounted && !walker.mount) motion.setAfoot(walker, false);
399
397
  else if (!mounted && walker.mount) motion.setAfoot(walker, 'beside');
400
- // Keep the horse's world matrix current before the initial poseActor call so stepRig sees zero velocity.
401
- worldGroup.updateMatrixWorld(true);
402
398
  const pace = mounted ? 6.5 : 1.9;
403
399
  walker.move = motion.newMove(walker, 7.5, 1.5, 23 / pace);
404
400
  foley.begin();
@@ -408,16 +404,20 @@ function crossShore(mounted) {
408
404
  $('walk').addEventListener('click', () => crossShore(false));
409
405
  $('ride').addEventListener('click', () => crossShore(true));
410
406
 
411
- scene.background = makeSky(noise, { sunDir: [-0.62, 0.42, -0.66] });
412
- scene.fog = new THREE.FogExp2(0xd2ddd8, 0.0028);
413
- setupSun(scene, renderer, {
407
+ createDaylightSky({
408
+ scene,
409
+ renderer,
410
+ noise,
411
+ sky: { sunDir: [-0.62, 0.42, -0.66] },
414
412
  sunPosition: [-38, 38, -28],
415
413
  shadowRadius: 48,
416
414
  shadowFar: 160,
417
415
  normalBias: 0.035,
416
+ fogColor: 0xd2ddd8,
417
+ fogDensity: 0.0028,
418
418
  });
419
419
 
420
- const rig = createOrbitRig({
420
+ const rig = createOrbitCamera({
421
421
  camera,
422
422
  canvas,
423
423
  renderer,
@@ -1,79 +1,13 @@
1
1
  import * as THREE from 'three';
2
- import {
3
- createCityFortification,
4
- createCrowdBatches,
5
- createCrowdLookBuilder,
6
- createCrowdPoser,
7
- createCrowdUpdater,
8
- createCrowdVisibility,
9
- createFigureAssembler,
10
- createFigureBuilder,
11
- createGreatWalls,
12
- createHerdRenderer,
13
- createHerdSkins,
14
- createHouseKitMeshes,
15
- createStreetBeasts,
16
- GeometryBuilder,
17
- geometryOf,
18
- mulberry32,
19
- registerCrowd,
20
- } from 'roamwright';
2
+ import { createCityFortification, createGreatWalls, GeometryBuilder, mulberry32 } from 'roamwright';
21
3
  import { particleNoise } from '../math/particle-noise.js';
22
4
  import { C } from '../geometry/primitives.js';
23
5
  import { partsGeometry } from '../geometry/foliage.js';
24
- import { createBroadleaf } from '../geometry/plant-broadleaf.js';
25
6
  import { createPlantTints } from '../geometry/plant-tints.js';
26
7
  import { createTrees } from '../geometry/plant-trees.js';
27
8
  import { PLAIN_GRASS, tussockGeometry } from '../geometry/plant-tussock.js';
28
- import { createCrowdAlarms } from '../motion/crowd-alarms.js';
29
9
 
30
- // Shared kit, foliage, fence, crowd and particle-noise builders for the showcase examples.
31
-
32
- /**
33
- * Synchronous hand-over adapter for building showcase kit meshes on the main thread.
34
- */
35
- export const SYNC_HAND_OVER = {
36
- paced: steps => Promise.resolve(steps),
37
- drain: steps => steps,
38
- heldBytes: () => 0,
39
- };
40
-
41
- /**
42
- * Default vertex-colored material map for synchronous house-kit and prop-kit showcase meshes.
43
- */
44
- export function createShowcaseHouseMaterials(kitKeys, { doubleSide = false, roughness = 0.9 } = {}) {
45
- const solid = doubleSide ? { vertexColors: true, roughness, side: THREE.DoubleSide } : { vertexColors: true, roughness };
46
- const materials = {};
47
- for (const key of kitKeys) {
48
- if (key === 'stain') {
49
- materials[key] = new THREE.MeshStandardMaterial({ vertexColors: true, transparent: true, opacity: 0.25, depthWrite: false });
50
- } else if (key === 'glass' && !doubleSide) {
51
- materials[key] = new THREE.MeshStandardMaterial({ vertexColors: true, roughness: 0.25 });
52
- } else if (key === 'cloth') {
53
- materials[key] = new THREE.MeshStandardMaterial({ vertexColors: true, roughness, side: THREE.DoubleSide });
54
- } else {
55
- materials[key] = new THREE.MeshStandardMaterial(solid);
56
- }
57
- }
58
- return materials;
59
- }
60
-
61
- /**
62
- * Uploads an array of kit buffers into a shadow-casting group and attaches it to parent.
63
- */
64
- export function buildKitGroup({ kitKeys, kit, kits, materials, parent, castShadow = true, receiveShadow = true }) {
65
- const { kitMeshes } = createHouseKitMeshes({ materials, PieceBatch: null, handOver: SYNC_HAND_OVER });
66
- const group = new THREE.Group();
67
- kitMeshes(kits ?? kitKeys.map(k => kit[k].parts(true)), group);
68
- group.traverse(o => {
69
- if (o.isMesh) {
70
- o.castShadow = castShadow;
71
- o.receiveShadow = receiveShadow;
72
- }
73
- });
74
- parent.add(group);
75
- return group;
76
- }
10
+ // Shared fortification, foliage scatter, paddock fence, and particle-noise helpers for showcase examples.
77
11
 
78
12
  /**
79
13
  * Binds createGreatWalls and createCityFortification to a houseKit and terrain sampler.
@@ -113,17 +47,13 @@ export function scatterTrees({
113
47
  }) {
114
48
  const tints = createPlantTints({ fbm: noise.fbm, vnoise: noise.vnoise, hash });
115
49
  const treeKit = createTrees({ hash, ...tints, seed });
116
- const { broadleaf } = createBroadleaf(tints);
117
50
  const material = new THREE.MeshStandardMaterial({ vertexColors: true, roughness, side: THREE.DoubleSide });
118
51
  const builders = {
119
- broadleaf: () => broadleaf(),
52
+ broadleaf: () => treeKit.broadleaf(),
120
53
  conifer: () => treeKit.conifer(),
121
54
  cedar: () => treeKit.cedar(0),
122
55
  };
123
- const geos = species.map(name => {
124
- const built = builders[name]();
125
- return partsGeometry(built.near ?? built);
126
- });
56
+ const geos = species.map(name => partsGeometry(builders[name]().near));
127
57
  const pools = geos.map(geo => {
128
58
  const mesh = new THREE.InstancedMesh(geo, material, maxPerSpecies);
129
59
  mesh.castShadow = mesh.receiveShadow = true;
@@ -216,9 +146,7 @@ export function buildCircularFence({
216
146
  const yaw = Math.atan2(x1 - x0, z1 - z0);
217
147
  for (const h of railHeights) fence.box(mx, my + h, mz, 0.07, 0.1, span, C(0x7e654b, 0.08, random), yaw);
218
148
  }
219
- const mesh = fence.mesh(new THREE.MeshStandardMaterial({ vertexColors: true, roughness: 0.92 }), worldGroup);
220
- mesh.castShadow = mesh.receiveShadow = true;
221
- return mesh;
149
+ return fence.mesh(new THREE.MeshStandardMaterial({ vertexColors: true, roughness: 0.92 }), worldGroup);
222
150
  }
223
151
 
224
152
  /**
@@ -242,59 +170,3 @@ export function makeParticleNoiseTexture(noise, size = 128) {
242
170
  texture.needsUpdate = true;
243
171
  return texture;
244
172
  }
245
-
246
- /**
247
- * Wires figure builders, instanced crowd batches, herd skins, alarms, visibility and updater for showcase scenes.
248
- */
249
- export function setupShowcaseCrowd({ worldGroup, groundAt, spaceKit, camera, renderer }) {
250
- const { buildBody, kit } = createFigureBuilder();
251
- const { assembleFigure } = createFigureAssembler({
252
- material: () => new THREE.MeshStandardMaterial({ vertexColors: true, roughness: 0.88, side: THREE.DoubleSide }),
253
- holds: kit.holds,
254
- });
255
- const buildFigure = (look, lookSeed, _near, bodies) => {
256
- const far = bodies?.[0] || buildBody(look, lookSeed, 1);
257
- return assembleFigure(look, 'human', { ...far, geo: geometryOf(far.parts) }, null);
258
- };
259
- const crowdPose = createCrowdPoser();
260
- const batches = createCrowdBatches({
261
- scene: worldGroup,
262
- buildFigure,
263
- buildCrowdLook: createCrowdLookBuilder({ buildBody }),
264
- crowdPose,
265
- });
266
- const herdSkins = createHerdSkins();
267
- const herdRenderer = createHerdRenderer({
268
- scene: worldGroup,
269
- material: () => new THREE.MeshStandardMaterial({ vertexColors: true, roughness: 0.9 }),
270
- herdPoses: herdSkins.herdPoses,
271
- });
272
- const crowds = [];
273
- const addCrowd = (list, tones, cx, cz, range, kind, beasts = null, sp = 'world') =>
274
- registerCrowd(crowds, list, tones, cx, cz, range, kind, { beasts, space: sp, groundAt: (_s, x, z) => groundAt(x, z) });
275
- const { streetBeasts, beastsAbout } = createStreetBeasts({ addCrowd, herdLook: herdSkins.herdLook });
276
- const visibility = createCrowdVisibility();
277
- const alarms = createCrowdAlarms({ steer: spaceKit.steer });
278
-
279
- function createUpdater({ getTime, getFrame, getLightDir, shadowRange = 120, shadowFar = 320 }) {
280
- return createCrowdUpdater({
281
- camera,
282
- renderer,
283
- getTime,
284
- getFrame,
285
- getShadowsEnabled: () => true,
286
- getLightDir,
287
- getShadowRange: () => shadowRange,
288
- getShadowFar: () => shadowFar,
289
- getSpace: () => spaceKit.worldSpace,
290
- crowds,
291
- batches,
292
- visibility,
293
- alarms,
294
- crowdPose,
295
- herds: { ...herdRenderer, orderHerd: herdSkins.orderHerd },
296
- });
297
- }
298
-
299
- return { crowds, addCrowd, herdSkins, streetBeasts, beastsAbout, alarms, batches, createUpdater };
300
- }