roamwright 0.61.12 → 0.61.14

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 CHANGED
@@ -30,7 +30,7 @@ npm resolves the Three.js peer in a new project. Roamwright targets Three.js **0
30
30
 
31
31
  ## Examples
32
32
 
33
- Browse all eighteen examples on the [live showcase](https://enestaylan.github.io/roamwright/).
33
+ Browse all nineteen examples on the [live showcase](https://enestaylan.github.io/roamwright/).
34
34
 
35
35
  | Live example | What the example shows | Source |
36
36
  | -------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------ | --------------------------------------------------- |
@@ -52,6 +52,7 @@ Browse all eighteen examples on the [live showcase](https://enestaylan.github.io
52
52
  | [A baked land](https://enestaylan.github.io/roamwright/examples/land.html?seed=7) | One height sheet baked row by row with erosion, coast, river ford, banked road, cliff-faced tel, quarry and upland mere. | [land.js](examples/land.js) |
53
53
  | [Island](https://enestaylan.github.io/roamwright/examples/island.html?seed=42) | Fractal terrain shapes a coastline, sandy coves, weathered boulders and coastal pines in turquoise shallows. | [island.js](examples/island.js) |
54
54
  | [Pacing and measuring](https://enestaylan.github.io/roamwright/examples/pacing.html?seed=42) | Device-aware presets, ground render order, frame-pacing watch and a live performance box over a coastal valley. | [pacing.js](examples/pacing.js) |
55
+ | [Ruins, rocks & paved roads](https://enestaylan.github.io/roamwright/examples/ruins.html?seed=42) | Hilltop ruins, buried-town mounds, bedded outcrops, a paved arch highway with cedar avenue and a flagstone plaza. | [ruins.js](examples/ruins.js) |
55
56
 
56
57
  ### Run locally
57
58
 
@@ -18,7 +18,8 @@ import {
18
18
  } from 'roamwright';
19
19
  import { sstep } from 'roamwright/math/scalar.js';
20
20
  import { createProps } from 'roamwright/geometry/props.js';
21
- import { initExample, makeRollingGround } from './stage.js';
21
+ import { createHeightfieldMesh } from 'roamwright/geometry/heightfield.js';
22
+ import { initExample } from './stage.js';
22
23
 
23
24
  const { canvas, renderer, camera, scene, worldGroup, seed, random, noise, hash, shapes } = initExample({
24
25
  fallbackSeed: 42,
@@ -39,7 +40,7 @@ function groundAt(x, z) {
39
40
  const grassCol = new THREE.Color(0x6c7e4a),
40
41
  meadowCol = new THREE.Color(0x88945b),
41
42
  wornCol = new THREE.Color(0xa69873);
42
- const ground = makeRollingGround({
43
+ const ground = createHeightfieldMesh({
43
44
  size: 260,
44
45
  segs: 140,
45
46
  heightAt: groundAt,
@@ -18,7 +18,8 @@ import { sharedFields } from 'roamwright/motion/crowd-camp.js';
18
18
  import { sstep } from 'roamwright/math/scalar.js';
19
19
  import { C } from 'roamwright/geometry/primitives.js';
20
20
  import { createProps } from 'roamwright/geometry/props.js';
21
- import { initExample, makeRollingGround } from './stage.js';
21
+ import { createHeightfieldMesh } from 'roamwright/geometry/heightfield.js';
22
+ import { initExample } from './stage.js';
22
23
 
23
24
  const {
24
25
  canvas,
@@ -56,7 +57,7 @@ const grassCol = new THREE.Color(0x6d7d4b),
56
57
  meadowCol = new THREE.Color(0x88935b),
57
58
  plazaCol = new THREE.Color(0xb8a885),
58
59
  campCol = new THREE.Color(0x9a8c6b);
59
- const terrain = makeRollingGround({
60
+ const terrain = createHeightfieldMesh({
60
61
  size: 460,
61
62
  segs: 140,
62
63
  heightAt: groundHeight,
@@ -14,7 +14,8 @@ import {
14
14
  } from 'roamwright';
15
15
  import { sstep } from 'roamwright/math/scalar.js';
16
16
  import { createWind } from 'roamwright/motion/wind.js';
17
- import { initExample, makeRollingGround } from './stage.js';
17
+ import { createHeightfieldMesh } from 'roamwright/geometry/heightfield.js';
18
+ import { initExample } from './stage.js';
18
19
 
19
20
  const doing = document.getElementById('doing');
20
21
  const { canvas, renderer, camera, scene, worldGroup, seed, random, noise, hash } = initExample({
@@ -32,7 +33,7 @@ function groundAt(x, z) {
32
33
  const grassCol = new THREE.Color(0x6d7f4b),
33
34
  meadowCol = new THREE.Color(0x88945c),
34
35
  trackCol = new THREE.Color(0xa69772);
35
- const meadow = makeRollingGround({
36
+ const meadow = createHeightfieldMesh({
36
37
  size: 260,
37
38
  segs: 150,
38
39
  heightAt: groundAt,
@@ -8,16 +8,15 @@ import {
8
8
  createRenderContext,
9
9
  createUnitShapes,
10
10
  GeometryBuilder,
11
+ scatterTrees,
11
12
  geometryOf,
12
13
  mulberry32,
13
14
  } from 'roamwright';
14
15
  import { createHash } from 'roamwright/math/random.js';
15
16
  import { sstep } from 'roamwright/math/scalar.js';
16
17
  import { C, TRS } from 'roamwright/geometry/primitives.js';
17
- import { partsGeometry } from 'roamwright/geometry/foliage.js';
18
- import { createPlantTints } from 'roamwright/geometry/plant-tints.js';
19
- import { createTrees } from 'roamwright/geometry/plant-trees.js';
20
- import { makeRollingGround, readSeed } from './stage.js';
18
+ import { createHeightfieldMesh } from 'roamwright/geometry/heightfield.js';
19
+ import { readSeed } from './stage.js';
21
20
 
22
21
  const canvas = document.querySelector('canvas');
23
22
  const { renderer, camera, scene, worldGroup } = createRenderContext(canvas, { fov: 36 });
@@ -56,7 +55,7 @@ function ground(x, z) {
56
55
  const stoneCol = new THREE.Color(0xb8ad97),
57
56
  grassCol = new THREE.Color(0x6e7d4b),
58
57
  meadowCol = new THREE.Color(0x88925a);
59
- const terrain = makeRollingGround({
58
+ const terrain = createHeightfieldMesh({
60
59
  size: 240,
61
60
  segs: 120,
62
61
  heightAt: ground,
@@ -93,33 +92,26 @@ const wallMesh = masonry.mesh(new THREE.MeshStandardMaterial({ vertexColors: tru
93
92
  wallMesh.castShadow = wallMesh.receiveShadow = true;
94
93
 
95
94
  // Broadleaf and cedar trees framing the hills behind the terrace.
96
- const tints = createPlantTints({ fbm: noise.fbm, vnoise: noise.vnoise, hash });
97
- const treeKit = createTrees({ hash, ...tints, seed });
98
- const leafMat = new THREE.MeshStandardMaterial({ vertexColors: true, roughness: 0.88, side: THREE.DoubleSide });
99
- const treeGeos = [treeKit.broadleaf(), treeKit.cedar(0), treeKit.conifer()].map(t => partsGeometry(t.near));
100
- const treePools = treeGeos.map(geo => {
101
- const m = new THREE.InstancedMesh(geo, leafMat, 22);
102
- m.castShadow = m.receiveShadow = true;
103
- m.count = 0;
104
- worldGroup.add(m);
105
- return m;
95
+ scatterTrees({
96
+ parent: worldGroup,
97
+ seed,
98
+ noise,
99
+ hash,
100
+ random,
101
+ groundAt: ground,
102
+ attempts: 55,
103
+ maxPerSpecies: 22,
104
+ species: ['broadleaf', 'cedar', 'conifer'],
105
+ sample: () => {
106
+ const a = random() * Math.PI * 2,
107
+ r = 14 + random() * 48,
108
+ x = Math.cos(a) * r,
109
+ z = Math.sin(a) * r;
110
+ return z > 1.5 && Math.abs(x) < 10 ? null : [x, z];
111
+ },
112
+ scaleRange: [0.85, 0.6],
113
+ sink: 0.1,
106
114
  });
107
- const dummy = new THREE.Object3D();
108
- for (let i = 0; i < 55; i++) {
109
- const a = random() * Math.PI * 2,
110
- r = 14 + random() * 48;
111
- const tx = Math.cos(a) * r,
112
- tz = Math.sin(a) * r;
113
- if (tz > 1.5 && Math.abs(tx) < 10) continue;
114
- const pool = treePools[i % treePools.length];
115
- if (pool.count >= 22) continue;
116
- dummy.position.set(tx, ground(tx, tz) - 0.1, tz);
117
- dummy.rotation.set(0, random() * Math.PI * 2, 0);
118
- dummy.scale.setScalar(0.85 + random() * 0.6);
119
- dummy.updateMatrix();
120
- pool.setMatrixAt(pool.count++, dummy.matrix);
121
- }
122
- for (const pool of treePools) pool.instanceMatrix.needsUpdate = true;
123
115
 
124
116
  // Six varied characters arranged in a gentle arc facing the warm sun.
125
117
  const looks = [
@@ -14,7 +14,8 @@ import { createCorvidFigure } from 'roamwright/rendering/flier-corvid-figure.js'
14
14
  import { createLongFlierCompany } from 'roamwright/rendering/flier-long-body-company.js';
15
15
  import { createFlierShapes, createSwarm } from 'roamwright/rendering/flier-swarm.js';
16
16
  import { createFlock } from 'roamwright/rendering/flocks.js';
17
- import { initExample, makeRollingGround } from './stage.js';
17
+ import { createHeightfieldMesh } from 'roamwright/geometry/heightfield.js';
18
+ import { initExample } from './stage.js';
18
19
 
19
20
  const { canvas, renderer, camera, scene, worldGroup, seed, random, noise, hash, shapes } = initExample({
20
21
  fallbackSeed: 7,
@@ -33,7 +34,7 @@ const grassCol = new THREE.Color(0x667746),
33
34
  meadowCol = new THREE.Color(0x838f57),
34
35
  pathCol = new THREE.Color(0xa29572),
35
36
  rockCol = new THREE.Color(0x7c786e);
36
- const terrain = makeRollingGround({
37
+ const terrain = createHeightfieldMesh({
37
38
  size: 420,
38
39
  segs: 150,
39
40
  heightAt: groundAt,
@@ -15,7 +15,8 @@ import {
15
15
  import { townFrame } from 'roamwright/geometry/land-town-ground.js';
16
16
  import { C } from 'roamwright/geometry/primitives.js';
17
17
  import { sstep } from 'roamwright/math/scalar.js';
18
- import { initExample, makeRollingGround } from './stage.js';
18
+ import { createHeightfieldMesh } from 'roamwright/geometry/heightfield.js';
19
+ import { initExample } from './stage.js';
19
20
 
20
21
  const { canvas, renderer, camera, scene, worldGroup, seed, noise, hash, shapes } = initExample({
21
22
  fallbackSeed: 11,
@@ -191,7 +192,7 @@ const earthCol = new THREE.Color(0xbca881),
191
192
  plazaCol = new THREE.Color(0xcabca0),
192
193
  rockCol = new THREE.Color(0x8c8172),
193
194
  sandCol = new THREE.Color(0xd5c49b);
194
- const terrain = makeRollingGround({
195
+ const terrain = createHeightfieldMesh({
195
196
  size: 1600,
196
197
  segs: 180,
197
198
  heightAt: ground,
@@ -9,7 +9,8 @@ import {
9
9
  } from 'roamwright';
10
10
  import { sstep } from 'roamwright/math/scalar.js';
11
11
  import { createProps } from 'roamwright/geometry/props.js';
12
- import { initExample, makeRollingGround } from './stage.js';
12
+ import { createHeightfieldMesh } from 'roamwright/geometry/heightfield.js';
13
+ import { initExample } from './stage.js';
13
14
 
14
15
  const { canvas, renderer, camera, scene, worldGroup, seed, random, noise, hash, shapes } = initExample({
15
16
  fallbackSeed: 42,
@@ -60,7 +61,7 @@ const grassCol = new THREE.Color(0x6f7f4e),
60
61
  meadowCol = new THREE.Color(0x88935c),
61
62
  cobbleCol = new THREE.Color(0xb7aa91),
62
63
  laneEdge = new THREE.Color(0x9a8f74);
63
- const terrain = makeRollingGround({
64
+ const terrain = createHeightfieldMesh({
64
65
  size: 460,
65
66
  segs: 140,
66
67
  heightAt: ground,
@@ -7,15 +7,14 @@ import {
7
7
  createSimpleWater,
8
8
  createUnitShapes,
9
9
  GeometryBuilder,
10
+ scatterTrees,
10
11
  mulberry32,
11
12
  } from 'roamwright';
12
13
  import { createHash } from 'roamwright/math/random.js';
13
14
  import { sstep } from 'roamwright/math/scalar.js';
14
15
  import { C, TRS } from 'roamwright/geometry/primitives.js';
15
- import { partsGeometry } from 'roamwright/geometry/foliage.js';
16
- import { createPlantTints } from 'roamwright/geometry/plant-tints.js';
17
- import { createTrees } from 'roamwright/geometry/plant-trees.js';
18
- import { makeRollingGround, readSeed } from './stage.js';
16
+ import { createHeightfieldMesh } from 'roamwright/geometry/heightfield.js';
17
+ import { readSeed } from './stage.js';
19
18
 
20
19
  const canvas = document.querySelector('canvas');
21
20
  const { renderer, camera, scene, worldGroup } = createRenderContext(canvas, { fov: 40 });
@@ -38,7 +37,7 @@ const sandCol = new THREE.Color(0xd9c79b),
38
37
  forestCol = new THREE.Color(0x526b44),
39
38
  rockCol = new THREE.Color(0x7c7a72),
40
39
  peakCol = new THREE.Color(0x9a958b);
41
- const island = makeRollingGround({
40
+ const island = createHeightfieldMesh({
42
41
  size: 130,
43
42
  segs: 180,
44
43
  heightAt: height,
@@ -68,32 +67,25 @@ const rockMesh = stones.mesh(new THREE.MeshStandardMaterial({ vertexColors: true
68
67
  rockMesh.castShadow = rockMesh.receiveShadow = true;
69
68
 
70
69
  // Coastal pines and cedars clustered on the sheltered green slopes.
71
- const tints = createPlantTints({ fbm, vnoise, hash });
72
- const treeKit = createTrees({ hash, ...tints, seed });
73
- const leafMat = new THREE.MeshStandardMaterial({ vertexColors: true, roughness: 0.88, side: THREE.DoubleSide });
74
- const treeGeos = [treeKit.conifer(), treeKit.cedar(0)].map(t => partsGeometry(t.near));
75
- const treePools = treeGeos.map(geo => {
76
- const m = new THREE.InstancedMesh(geo, leafMat, 60);
77
- m.castShadow = m.receiveShadow = true;
78
- m.count = 0;
79
- worldGroup.add(m);
80
- return m;
70
+ scatterTrees({
71
+ parent: worldGroup,
72
+ seed,
73
+ noise: { fbm, vnoise },
74
+ hash,
75
+ random,
76
+ groundAt: height,
77
+ attempts: 240,
78
+ maxPerSpecies: 60,
79
+ species: ['conifer', 'cedar'],
80
+ sample: () => {
81
+ const x = (random() - 0.5) * 76,
82
+ z = (random() - 0.5) * 76,
83
+ y = height(x, z);
84
+ return y < 2.2 || y > 13.5 ? null : [x, z];
85
+ },
86
+ scaleRange: [0.32, 0.32],
87
+ sink: 0.2,
81
88
  });
82
- const dummy = new THREE.Object3D();
83
- for (let i = 0; i < 240; i++) {
84
- const tx = (random() - 0.5) * 76,
85
- tz = (random() - 0.5) * 76;
86
- const ty = height(tx, tz);
87
- if (ty < 2.2 || ty > 13.5) continue;
88
- const pool = treePools[i % treePools.length];
89
- if (pool.count >= 60) continue;
90
- dummy.position.set(tx, ty - 0.2, tz);
91
- dummy.rotation.set(0, random() * Math.PI * 2, 0);
92
- dummy.scale.setScalar(0.32 + random() * 0.32);
93
- dummy.updateMatrix();
94
- pool.setMatrixAt(pool.count++, dummy.matrix);
95
- }
96
- for (const pool of treePools) pool.instanceMatrix.needsUpdate = true;
97
89
 
98
90
  // Shimmering ocean water with shallow turquoise shoals grading into deep sea blue.
99
91
  const { mesh: water, timeUniform: waterTime } = createSimpleWater({
@@ -19,7 +19,8 @@ import {
19
19
  import { sstep } from 'roamwright/math/scalar.js';
20
20
  import { createDiagnosticLog } from 'roamwright/runtime/diagnostic-log.js';
21
21
  import { estimateMemory } from 'roamwright/rendering/memory-estimate.js';
22
- import { initExample, makeRollingGround } from './stage.js';
22
+ import { createHeightfieldMesh } from 'roamwright/geometry/heightfield.js';
23
+ import { initExample } from './stage.js';
23
24
 
24
25
  const { canvas, renderer, camera, scene, worldGroup, seed, random, noise, hash, shapes } = initExample({
25
26
  fallbackSeed: 42,
@@ -50,7 +51,7 @@ const sandCol = new THREE.Color(0xd5c49c),
50
51
  grassCol = new THREE.Color(0x6d7f4f),
51
52
  meadowCol = new THREE.Color(0x8a9560),
52
53
  rockCol = new THREE.Color(0x7c796f);
53
- const terrain = makeRollingGround({
54
+ const terrain = createHeightfieldMesh({
54
55
  size: 420,
55
56
  segs: 150,
56
57
  heightAt: ground,
@@ -22,7 +22,8 @@ import { createShrubs } from 'roamwright/geometry/plant-shrub.js';
22
22
  import { createTrees } from 'roamwright/geometry/plant-trees.js';
23
23
  import { PLAIN_GRASS, tussockGeometry } from 'roamwright/geometry/plant-tussock.js';
24
24
  import { createReeds } from 'roamwright/rendering/plant-reeds.js';
25
- import { makeRollingGround, readSeed } from './stage.js';
25
+ import { createHeightfieldMesh } from 'roamwright/geometry/heightfield.js';
26
+ import { readSeed } from './stage.js';
26
27
 
27
28
  const canvas = document.querySelector('canvas');
28
29
  const { renderer, camera, scene, worldGroup } = createRenderContext(canvas, { fov: 40 });
@@ -50,7 +51,7 @@ const grassCol = new THREE.Color(0x6d7d4a),
50
51
  meadowCol = new THREE.Color(0x88925b),
51
52
  pathCol = new THREE.Color(0xb1a07a),
52
53
  mudCol = new THREE.Color(0x6c654d);
53
- const terrain = makeRollingGround({
54
+ const terrain = createHeightfieldMesh({
54
55
  size: 420,
55
56
  segs: 160,
56
57
  heightAt: ground,
@@ -0,0 +1,60 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
6
+ <meta name="theme-color" content="#152c2c" />
7
+ <title>Ruins, rocks &amp; paved roads · Roamwright</title>
8
+ <link rel="stylesheet" href="./showcase.css" />
9
+ <script type="importmap">
10
+ {
11
+ "imports": {
12
+ "three": "../node_modules/three/build/three.module.js",
13
+ "three/addons/": "../node_modules/three/examples/jsm/",
14
+ "roamwright": "../index.js",
15
+ "roamwright/": "../"
16
+ }
17
+ }
18
+ </script>
19
+ </head>
20
+ <body>
21
+ <canvas
22
+ tabindex="0"
23
+ aria-label="A paved stone highway and arch passing bedded outcrops, a ringed plaza, a ruined hilltop and a buried-town mound"
24
+ ></canvas>
25
+ <header>
26
+ <a class="back" href="../index.html"><span aria-hidden="true">←</span> Roamwright</a>
27
+ <div class="meta">
28
+ <a class="source" href="https://github.com/enestaylan/roamwright/blob/main/examples/ruins.js">Source</a>
29
+ <form method="get">
30
+ <label for="seed">Seed</label>
31
+ <input id="seed" name="seed" type="number" step="1" min="-2147483648" max="2147483647" value="42" required />
32
+ <button type="submit" title="Rebuild landscape with this seed" aria-label="Rebuild landscape with this seed">→</button>
33
+ </form>
34
+ </div>
35
+ </header>
36
+ <footer>
37
+ <div class="caption">
38
+ <h1>Ruins, rocks &amp; paved roads</h1>
39
+ <p>
40
+ A paved highway with kerbs, milestones, spanning arch and cedar avenue beside a ruined hill, a buried-town mound, bedded outcrops
41
+ and a flagstone plaza.
42
+ </p>
43
+ </div>
44
+ <div class="tools">
45
+ <div class="views" role="group" aria-label="Camera viewpoint">
46
+ <button type="button" data-view="overview" aria-pressed="true">Overview</button>
47
+ <button type="button" data-view="hill" aria-pressed="false">Hill ruin</button>
48
+ <button type="button" data-view="arch" aria-pressed="false">Road &amp; arch</button>
49
+ <button type="button" data-view="plaza" aria-pressed="false">Paved plaza</button>
50
+ <button type="button" data-view="mound" aria-pressed="false">Mound &amp; rocks</button>
51
+ </div>
52
+ <div class="views" role="group" aria-label="Plaza surface">
53
+ <button type="button" data-wet="0" aria-pressed="true">Dry stone</button>
54
+ <button type="button" data-wet="1" aria-pressed="false">After rain</button>
55
+ </div>
56
+ </div>
57
+ </footer>
58
+ <script type="module" src="./ruins.js"></script>
59
+ </body>
60
+ </html>