roamwright 0.61.12 → 0.61.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.
@@ -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,
package/examples/ships.js CHANGED
@@ -18,7 +18,8 @@ import { oneOf } from 'roamwright/geometry/ship-kit.js';
18
18
  import { YARD_STOWED } from 'roamwright/geometry/ship-rig.js';
19
19
  import { createBoatSailing, openWaterCourse } from 'roamwright/motion/boat-sailing.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,
@@ -40,7 +41,7 @@ const grassCol = new THREE.Color(0x6d7d4d),
40
41
  rockCol = new THREE.Color(0x888175),
41
42
  sandCol = new THREE.Color(0xcab993),
42
43
  plazaCol = new THREE.Color(0xb2a58c);
43
- const coast = makeRollingGround({
44
+ const coast = createHeightfieldMesh({
44
45
  size: 1200,
45
46
  segs: 160,
46
47
  heightAt: groundAt,
@@ -3,7 +3,7 @@ import { buildFenceRing, createSimpleWater, GeometryBuilder, mulberry32, scatter
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 } from './stage.js';
6
+ import { createHeightfieldMesh } from 'roamwright/geometry/heightfield.js';
7
7
 
8
8
  /**
9
9
  * Builds the coastal valley terrain, river mouth, bay water, stone harbour quay,
@@ -29,7 +29,7 @@ export function buildSmallWorldLand({ world, worldGroup, seed, rng, noise, hash,
29
29
  rockCol = new THREE.Color(0x7c7970),
30
30
  plazaCol = new THREE.Color(0xc2b599),
31
31
  bedCol = new THREE.Color(0x5c6d64);
32
- const terrain = makeRollingGround({
32
+ const terrain = createHeightfieldMesh({
33
33
  size: 960,
34
34
  segs: 200,
35
35
  heightAt: groundAt,
@@ -28,7 +28,8 @@ import { oneOf } from 'roamwright/geometry/ship-kit.js';
28
28
  import { createProps } from 'roamwright/geometry/props.js';
29
29
  import { createReeds } from 'roamwright/rendering/plant-reeds.js';
30
30
  import { createWind } from 'roamwright/motion/wind.js';
31
- import { initExample, makeRollingGround } from './stage.js';
31
+ import { createHeightfieldMesh } from 'roamwright/geometry/heightfield.js';
32
+ import { initExample } from './stage.js';
32
33
 
33
34
  const { canvas, renderer, camera, scene, worldGroup, seed, random, noise, hash, shapes } = initExample({
34
35
  fallbackSeed: 42,
@@ -59,7 +60,7 @@ const mudCol = new THREE.Color(0x645a49),
59
60
  grassCol = new THREE.Color(0x6d7e4c),
60
61
  meadowCol = new THREE.Color(0x849059),
61
62
  turfCol = new THREE.Color();
62
- const terrain = makeRollingGround({
63
+ const terrain = createHeightfieldMesh({
63
64
  size: 280,
64
65
  segs: 160,
65
66
  heightAt: groundAt,
package/examples/stage.js CHANGED
@@ -1,6 +1,5 @@
1
- import * as THREE from 'three';
2
1
  import { createNoise, createRenderContext, createUnitShapes, mulberry32 } from 'roamwright';
3
- import { createHash } from '../math/random.js';
2
+ import { createHash } from 'roamwright/math/random.js';
4
3
 
5
4
  // Shared seed reading, example context bootstrap, and rolling ground helper for the example pages.
6
5
 
@@ -32,20 +31,5 @@ export function initExample({ fallbackSeed = 42, fov = 42 } = {}) {
32
31
  /**
33
32
  * Vertex-colored rolling terrain mesh with natural variation.
34
33
  */
35
- export function makeRollingGround({ size = 400, segs = 160, heightAt, colorAt, roughness = 0.95 }) {
36
- const geo = new THREE.PlaneGeometry(size, size, segs, segs).rotateX(-Math.PI / 2);
37
- const pos = geo.attributes.position;
38
- for (let i = 0; i < pos.count; i++) pos.setY(i, heightAt(pos.getX(i), pos.getZ(i)));
39
- geo.computeVertexNormals();
40
- const norm = geo.attributes.normal;
41
- const colors = new Float32Array(pos.count * 3);
42
- const tint = new THREE.Color();
43
- for (let i = 0; i < pos.count; i++) {
44
- colorAt(pos.getX(i), pos.getY(i), pos.getZ(i), norm.getY(i), tint);
45
- tint.toArray(colors, i * 3);
46
- }
47
- geo.setAttribute('color', new THREE.BufferAttribute(colors, 3));
48
- const mesh = new THREE.Mesh(geo, new THREE.MeshStandardMaterial({ vertexColors: true, roughness }));
49
- mesh.receiveShadow = true;
50
- return mesh;
51
- }
34
+ // the examples' old name for the engine's rolling ground, kept for pages that still import it from here
35
+ export { createHeightfieldMesh as makeRollingGround } from 'roamwright/geometry/heightfield.js';
package/examples/towns.js CHANGED
@@ -20,7 +20,8 @@ import { createPieceBatch, TIGHT } from 'roamwright/rendering/piece-batch.js';
20
20
  import { C, TRS } from 'roamwright/geometry/primitives.js';
21
21
  import { litShare } from 'roamwright/math/lit-share.js';
22
22
  import { sstep } from 'roamwright/math/scalar.js';
23
- import { initExample, makeRollingGround } from './stage.js';
23
+ import { createHeightfieldMesh } from 'roamwright/geometry/heightfield.js';
24
+ import { initExample } from './stage.js';
24
25
 
25
26
  const { canvas, renderer, camera, scene, worldGroup, seed, random, noise, hash, shapes } = initExample({
26
27
  fallbackSeed: 7,
@@ -51,7 +52,7 @@ const grassCol = new THREE.Color(0x6d7c4c),
51
52
  meadowCol = new THREE.Color(0x88915c),
52
53
  vergeCol = new THREE.Color(0xa69874),
53
54
  hillCol = new THREE.Color(0x5b6b45);
54
- const groundMesh = makeRollingGround({
55
+ const groundMesh = createHeightfieldMesh({
55
56
  size: 1600,
56
57
  segs: 200,
57
58
  heightAt: ground,
@@ -1,7 +1,37 @@
1
1
  /**
2
- * Sample and refine regular terrain grids in local X/Z coordinates. Heights follow the triangles used to render the surface.
2
+ * Build, sample and refine regular terrain grids in local X/Z coordinates. Heights follow the triangles used to render the surface.
3
3
  * @module
4
4
  */
5
+ import * as THREE from 'three';
6
+
7
+ /**
8
+ * A square of rolling ground: a regular grid lifted by a height function and painted per vertex, lit and taking shadows.
9
+ * @param {object} options
10
+ * @param {number} [options.size=400] - Side of the square in metres, centred on the origin.
11
+ * @param {number} [options.segs=160] - Grid cells along each side.
12
+ * @param {(x: number, z: number) => number} options.heightAt - Ground height at a local X/Z.
13
+ * @param {(x: number, y: number, z: number, upness: number, out: THREE.Color) => void} options.colorAt - Paints a vertex into
14
+ * `out` from its place and the Y of its normal (1 on the flat, less on a slope).
15
+ * @param {number} [options.roughness=0.95] - The standard material's roughness.
16
+ * @returns {THREE.Mesh} The ground, with vertex colours and `receiveShadow` set; sample it with {@link heightfieldSampler}.
17
+ */
18
+ export function createHeightfieldMesh({ size = 400, segs = 160, heightAt, colorAt, roughness = 0.95 }) {
19
+ const geo = new THREE.PlaneGeometry(size, size, segs, segs).rotateX(-Math.PI / 2);
20
+ const pos = geo.attributes.position;
21
+ for (let i = 0; i < pos.count; i++) pos.setY(i, heightAt(pos.getX(i), pos.getZ(i)));
22
+ geo.computeVertexNormals();
23
+ const norm = geo.attributes.normal;
24
+ const colors = new Float32Array(pos.count * 3);
25
+ const tint = new THREE.Color();
26
+ for (let i = 0; i < pos.count; i++) {
27
+ colorAt(pos.getX(i), pos.getY(i), pos.getZ(i), norm.getY(i), tint);
28
+ tint.toArray(colors, i * 3);
29
+ }
30
+ geo.setAttribute('color', new THREE.BufferAttribute(colors, 3));
31
+ const mesh = new THREE.Mesh(geo, new THREE.MeshStandardMaterial({ vertexColors: true, roughness }));
32
+ mesh.receiveShadow = true;
33
+ return mesh;
34
+ }
5
35
 
6
36
  /**
7
37
  * Interpolate height on the same triangle that the renderer draws.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "roamwright",
3
- "version": "0.61.12",
3
+ "version": "0.61.13",
4
4
  "description": "A procedural worldbuilding engine built on top of Three.js. Generate landscapes with rivers and changing weather, animate crowds, and explore on foot or in flight.",
5
5
  "keywords": [
6
6
  "threejs",