roamwright 0.61.4 → 0.61.6
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/examples/animals.js +6 -4
- package/examples/crowds.js +4 -3
- package/examples/effects.js +7 -6
- package/examples/figure-motion.js +7 -5
- package/examples/fliers.js +3 -4
- package/examples/fortification.js +4 -3
- package/examples/house-kit.js +9 -3
- package/examples/pacing.js +2 -2
- package/examples/rooms.js +13 -8
- package/examples/ships.js +2 -2
- package/examples/small-world-land.js +5 -6
- package/examples/small-world-town.js +9 -3
- package/examples/soundscape.js +6 -6
- package/examples/towns.js +2 -2
- package/geometry/animal-canine-breeds.js +152 -7
- package/geometry/animal-canine-head.js +66 -9
- package/geometry/animal-ear.js +74 -12
- package/geometry/fort-city-walls.js +10 -8
- package/geometry/scatter-instances.js +103 -0
- package/geometry/timber-fence.js +117 -0
- package/index.js +4 -0
- package/package.json +1 -1
- package/rendering/particles.js +78 -1
- package/rendering/scatter-instances.js +246 -0
- package/tools/README.md +1 -0
- package/tools/beasts-near.cjs +498 -0
- package/tools/beasts-near.test.cjs +105 -0
- package/examples/stage-kits.js +0 -172
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Timber post-and-rail paddock fence builder: constructs circular post-and-rail enclosures grounded on arbitrary
|
|
3
|
+
* terrain heights into a `GeometryBuilder` (worker-safe) or directly as a static `THREE.Mesh`.
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import * as THREE from 'three';
|
|
8
|
+
import { mulberry32 } from '../math/random.js';
|
|
9
|
+
import { TAU } from '../math/scalar.js';
|
|
10
|
+
import { GB } from './builder.js';
|
|
11
|
+
import { C } from './primitives.js';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Default dimensions, vertical rail offsets (metres), timber sRGB colours, colour jitter and material roughness
|
|
15
|
+
* for post-and-rail timber fences.
|
|
16
|
+
*/
|
|
17
|
+
export const DEFAULT_FENCE_STYLE = Object.freeze({
|
|
18
|
+
postWidth: 0.15,
|
|
19
|
+
postHeight: 1.28,
|
|
20
|
+
postSink: 0.1,
|
|
21
|
+
railWidth: 0.07,
|
|
22
|
+
railHeight: 0.1,
|
|
23
|
+
railHeights: Object.freeze([0.48, 0.92]),
|
|
24
|
+
postColor: 0x6d563f,
|
|
25
|
+
postJitter: 0.1,
|
|
26
|
+
railColor: 0x7e654b,
|
|
27
|
+
railJitter: 0.08,
|
|
28
|
+
roughness: 0.92,
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Appends a circular timber post-and-rail fence grounded on `groundAt(x, z)` into a `GeometryBuilder`. Worker-safe:
|
|
33
|
+
* creates no Three.js meshes or materials.
|
|
34
|
+
*
|
|
35
|
+
* @param {GB} builder - Geometry builder receiving the posts and rails.
|
|
36
|
+
* @param {object} [options] - Ring placement, dimensions and timber tint options.
|
|
37
|
+
* @param {(x: number, z: number) => number} [options.groundAt] - Terrain elevation sampler `(x, z) => y` in metres (defaults to flat `0`).
|
|
38
|
+
* @param {number} [options.cx=0] - Ring centre X coordinate in metres.
|
|
39
|
+
* @param {number} [options.cz=0] - Ring centre Z coordinate in metres.
|
|
40
|
+
* @param {number} [options.radius=16.5] - Ring radius in metres.
|
|
41
|
+
* @param {number} [options.posts=28] - Number of perimeter posts (and rail spans) around the ring.
|
|
42
|
+
* @param {() => number} [options.random] - Deterministic PRNG in `[0, 1)` for subtle timber tint jitter (defaults to `mulberry32(1)`).
|
|
43
|
+
* @param {number} [options.postHeight=1.28] - Total post height in metres (including buried footing `postSink`).
|
|
44
|
+
* @param {number} [options.postWidth=0.15] - Post square cross-section width in metres.
|
|
45
|
+
* @param {number} [options.postSink=0.1] - Depth each post foot sinks below `groundAt(x, z)` in metres.
|
|
46
|
+
* @param {readonly number[]} [options.railHeights=[0.48, 0.92]] - Rail elevations above the midpoint ground height in metres.
|
|
47
|
+
* @param {number} [options.railWidth=0.07] - Rail thickness in metres.
|
|
48
|
+
* @param {number} [options.railHeight=0.1] - Rail vertical height in metres.
|
|
49
|
+
* @param {number} [options.postColor=0x6d563f] - Base sRGB hex colour for posts.
|
|
50
|
+
* @param {number} [options.postJitter=0.1] - Timber colour variation amplitude for posts.
|
|
51
|
+
* @param {number} [options.railColor=0x7e654b] - Base sRGB hex colour for rails.
|
|
52
|
+
* @param {number} [options.railJitter=0.08] - Timber colour variation amplitude for rails.
|
|
53
|
+
* @returns {GB} The supplied `builder` for chaining.
|
|
54
|
+
*/
|
|
55
|
+
export function addFenceRing(
|
|
56
|
+
builder,
|
|
57
|
+
{
|
|
58
|
+
groundAt = () => 0,
|
|
59
|
+
cx = 0,
|
|
60
|
+
cz = 0,
|
|
61
|
+
radius = 16.5,
|
|
62
|
+
posts = 28,
|
|
63
|
+
random = mulberry32(1),
|
|
64
|
+
postHeight = DEFAULT_FENCE_STYLE.postHeight,
|
|
65
|
+
postWidth = DEFAULT_FENCE_STYLE.postWidth,
|
|
66
|
+
postSink = DEFAULT_FENCE_STYLE.postSink,
|
|
67
|
+
railHeights = DEFAULT_FENCE_STYLE.railHeights,
|
|
68
|
+
railWidth = DEFAULT_FENCE_STYLE.railWidth,
|
|
69
|
+
railHeight = DEFAULT_FENCE_STYLE.railHeight,
|
|
70
|
+
postColor = DEFAULT_FENCE_STYLE.postColor,
|
|
71
|
+
postJitter = DEFAULT_FENCE_STYLE.postJitter,
|
|
72
|
+
railColor = DEFAULT_FENCE_STYLE.railColor,
|
|
73
|
+
railJitter = DEFAULT_FENCE_STYLE.railJitter,
|
|
74
|
+
} = {},
|
|
75
|
+
) {
|
|
76
|
+
if (!Number.isInteger(posts) || posts < 3) throw new RangeError('posts must be an integer >= 3');
|
|
77
|
+
if (!(radius > 0)) throw new RangeError('radius must be positive');
|
|
78
|
+
|
|
79
|
+
for (let i = 0; i < posts; i++) {
|
|
80
|
+
const a0 = (i / posts) * TAU;
|
|
81
|
+
const a1 = ((i + 1) / posts) * TAU;
|
|
82
|
+
const x0 = cx + Math.cos(a0) * radius;
|
|
83
|
+
const z0 = cz + Math.sin(a0) * radius;
|
|
84
|
+
const y0 = groundAt(x0, z0);
|
|
85
|
+
const x1 = cx + Math.cos(a1) * radius;
|
|
86
|
+
const z1 = cz + Math.sin(a1) * radius;
|
|
87
|
+
const y1 = groundAt(x1, z1);
|
|
88
|
+
|
|
89
|
+
builder.box(x0, y0 - postSink, z0, postWidth, postHeight, postWidth, C(postColor, postJitter, random));
|
|
90
|
+
|
|
91
|
+
const mx = (x0 + x1) / 2;
|
|
92
|
+
const mz = (z0 + z1) / 2;
|
|
93
|
+
const my = (y0 + y1) / 2;
|
|
94
|
+
const span = Math.hypot(x1 - x0, z1 - z0);
|
|
95
|
+
const yaw = Math.atan2(x1 - x0, z1 - z0);
|
|
96
|
+
for (let r = 0; r < railHeights.length; r++) {
|
|
97
|
+
builder.box(mx, my + railHeights[r], mz, railWidth, railHeight, span, C(railColor, railJitter, random), yaw);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return builder;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Builds a circular timber post-and-rail paddock fence grounded on `groundAt(x, z)` and returns the resulting static
|
|
105
|
+
* `THREE.Mesh`, optionally attaching it to `parent`.
|
|
106
|
+
*
|
|
107
|
+
* @param {object} [options] - All {@link addFenceRing} options plus optional `parent`, `material` and `roughness`.
|
|
108
|
+
* @param {THREE.Object3D | null} [options.parent=null] - Optional scene or group to attach the fence mesh to.
|
|
109
|
+
* @param {THREE.Material | null} [options.material=null] - Optional timber material (defaults to vertex-coloured `MeshStandardMaterial`).
|
|
110
|
+
* @param {number} [options.roughness=0.92] - Material roughness when `material` is omitted.
|
|
111
|
+
* @returns {THREE.Mesh} The built fence mesh.
|
|
112
|
+
*/
|
|
113
|
+
export function buildFenceRing({ parent = null, material = null, roughness = DEFAULT_FENCE_STYLE.roughness, ...ringOptions } = {}) {
|
|
114
|
+
const fence = addFenceRing(new GB(), ringOptions);
|
|
115
|
+
const mat = material ?? new THREE.MeshStandardMaterial({ vertexColors: true, roughness });
|
|
116
|
+
return fence.mesh(mat, parent);
|
|
117
|
+
}
|
package/index.js
CHANGED
|
@@ -61,6 +61,9 @@ export { createLandTrails, LAND_TRAILS } from './geometry/land-trails.js';
|
|
|
61
61
|
export { createIrrigatedFields, IRRIGATED_FIELDS } from './geometry/irrigated-fields.js';
|
|
62
62
|
export { createIrrigatedFieldSurface, IRRIGATED_FIELD_KIND, IRRIGATED_FIELD_SURFACE } from './rendering/irrigated-field-surface.js';
|
|
63
63
|
export { DRYSTONE_WALL, FIELD_STONE, drystoneStone, planDrystoneWall } from './geometry/drystone-wall.js';
|
|
64
|
+
export { DEFAULT_FENCE_STYLE, addFenceRing, buildFenceRing } from './geometry/timber-fence.js';
|
|
65
|
+
export { planScatterInstances } from './geometry/scatter-instances.js';
|
|
66
|
+
export { scatterInstances, scatterTrees, scatterTussocks } from './rendering/scatter-instances.js';
|
|
64
67
|
export { FARM_BOUNDARIES, planFieldBoundaries } from './geometry/farm-boundaries.js';
|
|
65
68
|
export { meshFarmCells, scatterFarmLots } from './rendering/farm-cells.js';
|
|
66
69
|
export { DEFAULT_LIVESTOCK_CASTS, createLivestockCache } from './rendering/farm-livestock.js';
|
|
@@ -186,6 +189,7 @@ export { createCrowdUpdater, registerCrowd } from './rendering/crowd-update.js';
|
|
|
186
189
|
export { createCrowdSystem } from './rendering/crowd-system.js';
|
|
187
190
|
|
|
188
191
|
// ── Effects, audio, pacing & runtime ─────────────────────────────────────
|
|
192
|
+
export { DEFAULT_PARTICLE_LOOK, createParticleNoiseTexture, createParticleSystem } from './rendering/particles.js';
|
|
189
193
|
export { createFireLightWatch } from './rendering/fire-light-watch.js';
|
|
190
194
|
export { createEffectsFrame, syncEffectsUniforms } from './rendering/effects-frame.js';
|
|
191
195
|
export { createRippleRingMaterial, createWaterRises, fishGeometry } from './rendering/effects-water-rises.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "roamwright",
|
|
3
|
-
"version": "0.61.
|
|
3
|
+
"version": "0.61.6",
|
|
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",
|
package/rendering/particles.js
CHANGED
|
@@ -1,7 +1,52 @@
|
|
|
1
1
|
import * as THREE from 'three';
|
|
2
|
+
import { createNoise } from '../math/noise.js';
|
|
3
|
+
import { particleNoise } from '../math/particle-noise.js';
|
|
2
4
|
import { ATMOSPHERE_GLSL } from './atmosphere.js';
|
|
3
5
|
import { glslFloat, glslVec3 } from './glsl-literal.js';
|
|
4
6
|
|
|
7
|
+
const DEFAULT_PARTICLE_NOISE_SIZE = 128;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Generates the seamless 4-channel procedural noise `DataTexture` consumed by `createParticleSystem` and its ember
|
|
11
|
+
* shaders: `R` carries billowing ridge height, `G`/`B` carry its horizontal/vertical slope for relief shading, and `A`
|
|
12
|
+
* carries soft cloud turbulence that frays smoke edges and drives flame flicker.
|
|
13
|
+
*
|
|
14
|
+
* @param {object} [options] - Noise sheet options.
|
|
15
|
+
* @param {{ tfbm: Function, tnoise: Function }} [options.noise] - Seeded noise (`createNoise()` by default).
|
|
16
|
+
* @param {number} [options.size=128] - Square texture width and height in pixels (positive integer).
|
|
17
|
+
* @param {number} [options.ridgeSeed=311] - Seed for the billowing ridge channel.
|
|
18
|
+
* @param {number} [options.cloudSeed=733] - Seed for the alpha turbulence channel.
|
|
19
|
+
* @returns {THREE.DataTexture} Seamless repeating RGBA `DataTexture` with mipmaps enabled.
|
|
20
|
+
*/
|
|
21
|
+
export function createParticleNoiseTexture({
|
|
22
|
+
noise = createNoise(),
|
|
23
|
+
size = DEFAULT_PARTICLE_NOISE_SIZE,
|
|
24
|
+
ridgeSeed = 311,
|
|
25
|
+
cloudSeed = 733,
|
|
26
|
+
} = {}) {
|
|
27
|
+
if (!Number.isInteger(size) || size < 1) throw new RangeError('size must be a positive integer');
|
|
28
|
+
const sheetAt = particleNoise({ size, ridgeSeed, cloudSeed, noise });
|
|
29
|
+
const sheet = new Uint8Array(size * size * 4);
|
|
30
|
+
const texel = [0, 0, 0, 0];
|
|
31
|
+
for (let y = 0; y < size; y++) {
|
|
32
|
+
for (let x = 0; x < size; x++) {
|
|
33
|
+
sheetAt((x + 0.5) / size, (size - 1 - y + 0.5) / size, texel);
|
|
34
|
+
const offset = (y * size + x) * 4;
|
|
35
|
+
sheet[offset] = texel[0];
|
|
36
|
+
sheet[offset + 1] = texel[1];
|
|
37
|
+
sheet[offset + 2] = texel[2];
|
|
38
|
+
sheet[offset + 3] = texel[3];
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
const texture = new THREE.DataTexture(sheet, size, size);
|
|
42
|
+
texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
|
|
43
|
+
texture.magFilter = THREE.LinearFilter;
|
|
44
|
+
texture.minFilter = THREE.LinearMipmapLinearFilter;
|
|
45
|
+
texture.generateMipmaps = true;
|
|
46
|
+
texture.needsUpdate = true;
|
|
47
|
+
return texture;
|
|
48
|
+
}
|
|
49
|
+
|
|
5
50
|
/**
|
|
6
51
|
* Default visual and motion parameters for `createParticleSystem`:
|
|
7
52
|
* `wind` (`[wx, wz]` horizontal drift in m/s), `hazeNear` (`{ offset, start, end }` distance fade in metres),
|
|
@@ -14,12 +59,38 @@ export const DEFAULT_PARTICLE_LOOK = Object.freeze({
|
|
|
14
59
|
fireColors: { tip: [1.0, 0.5, 0.22], core: [1.0, 0.8, 0.4], underglow: [1.0, 0.35, 0.08] },
|
|
15
60
|
});
|
|
16
61
|
|
|
62
|
+
/**
|
|
63
|
+
* Creates a GPU-animated instanced particle and ember material system (alpha smoke/dust/shadow pool and additive
|
|
64
|
+
* glow/flame/ember pool). When `noiseTexture` is omitted, a seamless noise `DataTexture` is generated on first pool
|
|
65
|
+
* creation via {@link createParticleNoiseTexture}.
|
|
66
|
+
*
|
|
67
|
+
* @param {object} options - Scene, clock, depth, noise and visual look bindings.
|
|
68
|
+
* @param {THREE.Object3D} options.scene - Scene or group receiving the particle pool meshes.
|
|
69
|
+
* @param {{ value: number }} options.pointScale - Uniform holding viewport height-derived sprite scale.
|
|
70
|
+
* @param {{ uDepth: { value: THREE.Texture | null }, uDepthPx: { value: THREE.Vector2 }, uSoft: { value: number } }} options.sceneDepth - Soft-particle depth uniforms.
|
|
71
|
+
* @param {() => number} options.elapsed - Current simulation time in seconds.
|
|
72
|
+
* @param {THREE.Texture | (() => THREE.Texture)} [options.noiseTexture] - 4-channel particle noise texture or lazy factory; defaults to `createParticleNoiseTexture({ noise, size: noiseSize })`.
|
|
73
|
+
* @param {{ tfbm: Function, tnoise: Function }} [options.noise] - Seeded noise used when creating the default noise texture.
|
|
74
|
+
* @param {number} [options.noiseSize=128] - Resolution in pixels of the default noise texture when `noiseTexture` is omitted.
|
|
75
|
+
* @param {(particle: object, out: THREE.Vector2) => boolean} [options.verticalBounds] - Optional enclosure sampler writing `[floorY, ceilingY]` in metres.
|
|
76
|
+
* @param {() => number} [options.random=Math.random] - PRNG for per-particle seed attributes.
|
|
77
|
+
* @param {number} [options.layer=0] - Render layer assigned to particle pool meshes.
|
|
78
|
+
* @param {number} [options.alphaOrder=0] - `renderOrder` for alpha-blended pools.
|
|
79
|
+
* @param {number} [options.additiveOrder=1] - `renderOrder` for additive-blended pools.
|
|
80
|
+
* @param {[number, number]} [options.wind] - Horizontal wind drift `[wx, wz]` in m/s.
|
|
81
|
+
* @param {{ offset?: number, start?: number, end?: number }} [options.hazeNear] - Near-distance haze fade in metres.
|
|
82
|
+
* @param {{ glow?: number[], core?: number[] }} [options.emberColors] - Linear RGB colours for ember shaders.
|
|
83
|
+
* @param {{ tip?: number[], core?: number[], underglow?: number[] }} [options.fireColors] - Linear RGB colours for flame shaders.
|
|
84
|
+
* @returns {{ emberMaterial: Function, fxU: object, makeParticles: Function, pFlush: Function, pSpawn: Function, spawn: object }}
|
|
85
|
+
*/
|
|
17
86
|
export function createParticleSystem({
|
|
18
87
|
scene,
|
|
19
88
|
pointScale,
|
|
20
89
|
sceneDepth,
|
|
21
90
|
elapsed,
|
|
22
91
|
noiseTexture,
|
|
92
|
+
noise,
|
|
93
|
+
noiseSize = DEFAULT_PARTICLE_NOISE_SIZE,
|
|
23
94
|
// Optional sampler at emission. Write absolute floor and ceiling heights (metres) to out.x/y
|
|
24
95
|
// and return true for an enclosed particle. Returning false leaves its flight unrestricted.
|
|
25
96
|
verticalBounds,
|
|
@@ -32,6 +103,12 @@ export function createParticleSystem({
|
|
|
32
103
|
emberColors = DEFAULT_PARTICLE_LOOK.emberColors,
|
|
33
104
|
fireColors = DEFAULT_PARTICLE_LOOK.fireColors,
|
|
34
105
|
}) {
|
|
106
|
+
const resolveNoiseTexture =
|
|
107
|
+
typeof noiseTexture === 'function'
|
|
108
|
+
? noiseTexture
|
|
109
|
+
: noiseTexture
|
|
110
|
+
? () => noiseTexture
|
|
111
|
+
: () => createParticleNoiseTexture({ noise, size: noiseSize });
|
|
35
112
|
const haze = { ...DEFAULT_PARTICLE_LOOK.hazeNear, ...hazeNear };
|
|
36
113
|
const embers = { ...DEFAULT_PARTICLE_LOOK.emberColors, ...emberColors };
|
|
37
114
|
const fire = { ...DEFAULT_PARTICLE_LOOK.fireColors, ...fireColors };
|
|
@@ -102,7 +179,7 @@ export function createParticleSystem({
|
|
|
102
179
|
// flame tongues that stand upright and lick upward (kind 1) and embers (kind 2).
|
|
103
180
|
function makeParticles(capacity, additive) {
|
|
104
181
|
if (!Number.isInteger(capacity) || capacity < 1) throw new RangeError('Particle capacity must be a positive integer');
|
|
105
|
-
if (!fxU.uNoise.value) fxU.uNoise.value =
|
|
182
|
+
if (!fxU.uNoise.value) fxU.uNoise.value = resolveNoiseTexture();
|
|
106
183
|
const particleGeometry = new THREE.InstancedBufferGeometry(),
|
|
107
184
|
quadGeometry = new THREE.PlaneGeometry(1, 1);
|
|
108
185
|
particleGeometry.setIndex(quadGeometry.index);
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Instanced foliage and scenery scattering: binds worker-safe placements from `planScatterInstances` into
|
|
3
|
+
* `THREE.InstancedMesh` pools for arbitrary geometries, plant-kit trees, and grass tussocks.
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import * as THREE from 'three';
|
|
8
|
+
import { createNoise } from '../math/noise.js';
|
|
9
|
+
import { createHash, mulberry32 } from '../math/random.js';
|
|
10
|
+
import { partsGeometry } from '../geometry/foliage.js';
|
|
11
|
+
import { createPlantTints } from '../geometry/plant-tints.js';
|
|
12
|
+
import { createTrees } from '../geometry/plant-trees.js';
|
|
13
|
+
import { PLAIN_GRASS, tussockGeometry } from '../geometry/plant-tussock.js';
|
|
14
|
+
import { planScatterInstances } from '../geometry/scatter-instances.js';
|
|
15
|
+
|
|
16
|
+
const DEFAULT_ROUGHNESS = 0.88;
|
|
17
|
+
const DEFAULT_TREE_SPECIES = Object.freeze(['broadleaf', 'conifer', 'cedar']);
|
|
18
|
+
|
|
19
|
+
function createDefaultFoliageMaterial(roughness) {
|
|
20
|
+
return new THREE.MeshStandardMaterial({ vertexColors: true, roughness, side: THREE.DoubleSide });
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Scatters one or more geometries as `THREE.InstancedMesh` pools using `planScatterInstances`.
|
|
25
|
+
*
|
|
26
|
+
* @param {object} options - Geometry, placement, material and scene-graph options.
|
|
27
|
+
* @param {THREE.BufferGeometry[]} options.geometries - Variant geometries, one instanced mesh per entry.
|
|
28
|
+
* @param {THREE.Object3D | null} [options.parent=null] - Optional scene or group to attach the created meshes to.
|
|
29
|
+
* @param {THREE.Material | null} [options.material=null] - Shared material (defaults to double-sided vertex-coloured `MeshStandardMaterial`).
|
|
30
|
+
* @param {number} [options.roughness=0.88] - Roughness for the default material when `material` is omitted.
|
|
31
|
+
* @param {number} [options.attempts=90] - Candidate samples passed to `planScatterInstances`.
|
|
32
|
+
* @param {number} [options.maxPerBucket=32] - Maximum instances per geometry variant.
|
|
33
|
+
* @param {(attempt: number) => [number, number] | null | undefined} [options.sample] - Candidate `[x, z]` sampler in metres.
|
|
34
|
+
* @param {(x: number, z: number) => number} [options.groundAt] - Terrain elevation sampler `(x, z) => y` in metres.
|
|
35
|
+
* @param {() => number} [options.random] - Deterministic PRNG in `[0, 1)`.
|
|
36
|
+
* @param {[number, number]} [options.scaleRange=[1, 0]] - Uniform scale `[minScale, scaleSpan]`.
|
|
37
|
+
* @param {number} [options.sink=0] - Vertical sink below `groundAt(x, z)` in metres.
|
|
38
|
+
* @param {boolean} [options.castShadow=true] - Whether each instanced mesh casts shadows.
|
|
39
|
+
* @param {boolean} [options.receiveShadow=true] - Whether each instanced mesh receives shadows.
|
|
40
|
+
* @param {boolean} [options.stopWhenFull=false] - Stop sampling early once every variant bucket is full.
|
|
41
|
+
* @returns {{ meshes: THREE.InstancedMesh[], material: THREE.Material, total: number, dispose: () => void }}
|
|
42
|
+
*/
|
|
43
|
+
export function scatterInstances({
|
|
44
|
+
geometries,
|
|
45
|
+
parent = null,
|
|
46
|
+
material = null,
|
|
47
|
+
roughness = DEFAULT_ROUGHNESS,
|
|
48
|
+
attempts = 90,
|
|
49
|
+
maxPerBucket = 32,
|
|
50
|
+
sample,
|
|
51
|
+
groundAt = () => 0,
|
|
52
|
+
random = mulberry32(1),
|
|
53
|
+
scaleRange = [1, 0],
|
|
54
|
+
sink = 0,
|
|
55
|
+
castShadow = true,
|
|
56
|
+
receiveShadow = true,
|
|
57
|
+
stopWhenFull = false,
|
|
58
|
+
} = {}) {
|
|
59
|
+
if (!Array.isArray(geometries) || geometries.length === 0) {
|
|
60
|
+
throw new RangeError('geometries must be a non-empty array of BufferGeometry');
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const ownsMaterial = !material;
|
|
64
|
+
const mat = material ?? createDefaultFoliageMaterial(roughness);
|
|
65
|
+
const plan = planScatterInstances({
|
|
66
|
+
attempts,
|
|
67
|
+
maxPerBucket,
|
|
68
|
+
buckets: geometries.length,
|
|
69
|
+
sample,
|
|
70
|
+
groundAt,
|
|
71
|
+
random,
|
|
72
|
+
scaleRange,
|
|
73
|
+
sink,
|
|
74
|
+
stopWhenFull,
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
const meshes = geometries.map((geometry, index) => {
|
|
78
|
+
const { count, matrices } = plan.buckets[index];
|
|
79
|
+
const mesh = new THREE.InstancedMesh(geometry, mat, 0);
|
|
80
|
+
mesh.instanceMatrix = new THREE.InstancedBufferAttribute(matrices, 16);
|
|
81
|
+
mesh.count = count;
|
|
82
|
+
mesh.castShadow = castShadow;
|
|
83
|
+
mesh.receiveShadow = receiveShadow;
|
|
84
|
+
if (count > 0) mesh.computeBoundingSphere();
|
|
85
|
+
if (parent) parent.add(mesh);
|
|
86
|
+
return mesh;
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
return {
|
|
90
|
+
meshes,
|
|
91
|
+
material: mat,
|
|
92
|
+
total: plan.total,
|
|
93
|
+
dispose() {
|
|
94
|
+
for (const mesh of meshes) mesh.removeFromParent();
|
|
95
|
+
if (ownsMaterial) mat.dispose();
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Builds instanced trees from the engine plant kit (`createTrees`) over a caller-supplied placement sampler.
|
|
102
|
+
*
|
|
103
|
+
* @param {object} [options] - Plant kit, placement and rendering options.
|
|
104
|
+
* @param {THREE.Object3D | null} [options.parent=null] - Optional scene or group receiving the tree meshes.
|
|
105
|
+
* @param {number} [options.seed=0] - World seed for tree builders and default noise/hash/PRNG.
|
|
106
|
+
* @param {{ fbm: Function, vnoise: Function }} [options.noise] - Seeded noise (`createNoise(seed)` by default).
|
|
107
|
+
* @param {Function} [options.hash] - Seeded integer hash (`createHash(seed)` by default).
|
|
108
|
+
* @param {() => number} [options.random] - Deterministic PRNG in `[0, 1)` (`mulberry32(seed)` by default).
|
|
109
|
+
* @param {(x: number, z: number) => number} [options.groundAt] - Terrain elevation sampler `(x, z) => y` in metres.
|
|
110
|
+
* @param {number} [options.attempts=90] - Candidate samples to draw.
|
|
111
|
+
* @param {number} [options.maxPerSpecies=32] - Maximum placed instances per species.
|
|
112
|
+
* @param {Array<'broadleaf' | 'conifer' | 'cedar' | 'burntTree' | 'thornTree' | 'acacia'>} [options.species=['broadleaf', 'conifer', 'cedar']] - Tree species to instance.
|
|
113
|
+
* @param {(attempt: number) => [number, number] | null | undefined} [options.sample] - Candidate `[x, z]` sampler in metres.
|
|
114
|
+
* @param {[number, number]} [options.scaleRange=[0.85, 0.7]] - Uniform scale `[minScale, scaleSpan]`.
|
|
115
|
+
* @param {number} [options.sink=0.12] - Vertical sink below `groundAt(x, z)` in metres.
|
|
116
|
+
* @param {number} [options.roughness=0.88] - Roughness for the default foliage material when `material` is omitted.
|
|
117
|
+
* @param {THREE.Material | null} [options.material=null] - Optional shared foliage material.
|
|
118
|
+
* @param {boolean} [options.castShadow=true] - Whether tree meshes cast shadows.
|
|
119
|
+
* @param {boolean} [options.receiveShadow=true] - Whether tree meshes receive shadows.
|
|
120
|
+
* @returns {{ meshes: THREE.InstancedMesh[], material: THREE.Material, total: number, dispose: () => void }}
|
|
121
|
+
*/
|
|
122
|
+
export function scatterTrees({
|
|
123
|
+
parent = null,
|
|
124
|
+
seed = 0,
|
|
125
|
+
noise = createNoise(seed),
|
|
126
|
+
hash = createHash(seed),
|
|
127
|
+
random = mulberry32(seed),
|
|
128
|
+
groundAt = () => 0,
|
|
129
|
+
attempts = 90,
|
|
130
|
+
maxPerSpecies = 32,
|
|
131
|
+
species = DEFAULT_TREE_SPECIES,
|
|
132
|
+
sample,
|
|
133
|
+
scaleRange = [0.85, 0.7],
|
|
134
|
+
sink = 0.12,
|
|
135
|
+
roughness = DEFAULT_ROUGHNESS,
|
|
136
|
+
material = null,
|
|
137
|
+
castShadow = true,
|
|
138
|
+
receiveShadow = true,
|
|
139
|
+
} = {}) {
|
|
140
|
+
const tints = createPlantTints({ fbm: noise.fbm, vnoise: noise.vnoise, hash });
|
|
141
|
+
const treeKit = createTrees({ hash, ...tints, seed });
|
|
142
|
+
const builders = {
|
|
143
|
+
broadleaf: () => treeKit.broadleaf(),
|
|
144
|
+
conifer: () => treeKit.conifer(),
|
|
145
|
+
cedar: () => treeKit.cedar(0),
|
|
146
|
+
burntTree: () => treeKit.burntTree(),
|
|
147
|
+
thornTree: () => treeKit.thornTree(),
|
|
148
|
+
acacia: () => treeKit.acacia(),
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
const geometries = species.map(name => {
|
|
152
|
+
const build = builders[name];
|
|
153
|
+
if (!build) throw new RangeError(`Unknown tree species "${name}". Expected one of: ${Object.keys(builders).join(', ')}`);
|
|
154
|
+
return partsGeometry(build().near);
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
const scattered = scatterInstances({
|
|
158
|
+
parent,
|
|
159
|
+
geometries,
|
|
160
|
+
material,
|
|
161
|
+
roughness,
|
|
162
|
+
attempts,
|
|
163
|
+
maxPerBucket: maxPerSpecies,
|
|
164
|
+
sample,
|
|
165
|
+
groundAt,
|
|
166
|
+
random,
|
|
167
|
+
scaleRange,
|
|
168
|
+
sink,
|
|
169
|
+
castShadow,
|
|
170
|
+
receiveShadow,
|
|
171
|
+
stopWhenFull: false,
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
return {
|
|
175
|
+
meshes: scattered.meshes,
|
|
176
|
+
material: scattered.material,
|
|
177
|
+
total: scattered.total,
|
|
178
|
+
dispose() {
|
|
179
|
+
scattered.dispose();
|
|
180
|
+
for (const geometry of geometries) geometry.dispose();
|
|
181
|
+
},
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Scatters instanced grass tussocks (`tussockGeometry`) across terrain points returned by `sample(attempt)`.
|
|
187
|
+
*
|
|
188
|
+
* @param {object} [options] - Tussock, placement and rendering options.
|
|
189
|
+
* @param {THREE.Object3D | null} [options.parent=null] - Optional scene or group receiving the tussock mesh.
|
|
190
|
+
* @param {number} [options.seed=0] - Seed for the tussock geometry (`mulberry32(seed)`).
|
|
191
|
+
* @param {() => number} [options.random] - Deterministic PRNG in `[0, 1)` for placement yaw and scale (`mulberry32(seed)` by default).
|
|
192
|
+
* @param {(x: number, z: number) => number} [options.groundAt] - Terrain elevation sampler `(x, z) => y` in metres.
|
|
193
|
+
* @param {number} [options.count=60] - Maximum number of tussocks to place.
|
|
194
|
+
* @param {number} [options.attempts=110] - Candidate samples to draw before stopping.
|
|
195
|
+
* @param {(attempt: number) => [number, number] | null | undefined} [options.sample] - Candidate `[x, z]` sampler in metres.
|
|
196
|
+
* @param {[number, number]} [options.scaleRange=[0.8, 0.55]] - Uniform scale `[minScale, scaleSpan]`.
|
|
197
|
+
* @param {object} [options.grass=PLAIN_GRASS] - Grass form descriptor passed to `tussockGeometry`.
|
|
198
|
+
* @param {number} [options.roughness=0.88] - Roughness for the default material when `material` is omitted.
|
|
199
|
+
* @param {THREE.Material | null} [options.material=null] - Optional shared foliage material.
|
|
200
|
+
* @param {boolean} [options.castShadow=false] - Whether the tussock mesh casts shadows.
|
|
201
|
+
* @param {boolean} [options.receiveShadow=false] - Whether the tussock mesh receives shadows.
|
|
202
|
+
* @returns {{ mesh: THREE.InstancedMesh, material: THREE.Material, count: number, dispose: () => void }}
|
|
203
|
+
*/
|
|
204
|
+
export function scatterTussocks({
|
|
205
|
+
parent = null,
|
|
206
|
+
seed = 0,
|
|
207
|
+
random = mulberry32(seed),
|
|
208
|
+
groundAt = () => 0,
|
|
209
|
+
count = 60,
|
|
210
|
+
attempts = 110,
|
|
211
|
+
sample,
|
|
212
|
+
scaleRange = [0.8, 0.55],
|
|
213
|
+
grass = PLAIN_GRASS,
|
|
214
|
+
roughness = DEFAULT_ROUGHNESS,
|
|
215
|
+
material = null,
|
|
216
|
+
castShadow = false,
|
|
217
|
+
receiveShadow = false,
|
|
218
|
+
} = {}) {
|
|
219
|
+
const geometry = tussockGeometry(mulberry32(seed), false, grass);
|
|
220
|
+
const scattered = scatterInstances({
|
|
221
|
+
parent,
|
|
222
|
+
geometries: [geometry],
|
|
223
|
+
material,
|
|
224
|
+
roughness,
|
|
225
|
+
attempts,
|
|
226
|
+
maxPerBucket: count,
|
|
227
|
+
sample,
|
|
228
|
+
groundAt,
|
|
229
|
+
random,
|
|
230
|
+
scaleRange,
|
|
231
|
+
sink: 0,
|
|
232
|
+
castShadow,
|
|
233
|
+
receiveShadow,
|
|
234
|
+
stopWhenFull: true,
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
return {
|
|
238
|
+
mesh: scattered.meshes[0],
|
|
239
|
+
material: scattered.material,
|
|
240
|
+
count: scattered.total,
|
|
241
|
+
dispose() {
|
|
242
|
+
scattered.dispose();
|
|
243
|
+
geometry.dispose();
|
|
244
|
+
},
|
|
245
|
+
};
|
|
246
|
+
}
|
package/tools/README.md
CHANGED
|
@@ -14,6 +14,7 @@ const { renewShaders, renewalFlags, saltFor } = require('roamwright/tools/shader
|
|
|
14
14
|
| --------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
15
15
|
| `page-driver.cjs` | What every tool that opens a world's built page starts from: finds Playwright and a headless Chrome shell, launches on the graphics card, enters the world (`enter`), builds route URLs (`routeUrl`), clears camera collisions (`clearView`), seeds prefixed `localStorage` (`applyStorage`), prints the page's own log (`window[debug].log()`) and WebGL warnings on close, installs shader switches (`installCuts`), and guards against hung runs (`longRun`). |
|
|
16
16
|
| `stills.cjs` | Generic headless capture and inspection runners built on `page-driver.cjs`: single stills (`takeShot`), settled expression evaluation (`evalInPage`), hand-placed camera tours (`captureViews`), headless phone layout checks (`emulatePhone`), four-height land sweeps (`sweepLand`), scene motion strips (`captureStrip`), and labelled contact sheets (`writeContactSheet`). |
|
|
17
|
+
| `beasts-near.cjs` | Generic close-up animal inspector built on `page-driver.cjs` and `scene-run.cjs`: raises nearby herds and scene figures at once, freezes daylight, frames sunlit eye-height side/front/three-quarter close-ups (`frameBeastView`, `runBeastsNear`), and supports explicit `--scene <id> --at <seconds>` beats. |
|
|
17
18
|
| `contact-sheet.cjs` | Renders arrays of captured frames into labelled JPEG contact sheets on disk (`writeContactSheet`, `sheetDimensions`). |
|
|
18
19
|
| `look-guard.cjs` | Runs a world's fixed-camera and scene-beat look suites, writes `look.yaml` and contact sheets (`runLookGuard`), and compares measured stats against a kept YAML baseline (`compareLookFiles`). |
|
|
19
20
|
| `look-compare.cjs` | Single-page A/B frame diffing (`runAB`, `diffRgbaFrames`) and multi-frame temporal steadiness / flicker measurement (`runSteady`, `measureFrameSteadiness`). |
|