roamwright 0.61.5 → 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/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/examples/stage-kits.js +0 -172
package/examples/animals.js
CHANGED
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
buildCamel,
|
|
4
4
|
buildCanine,
|
|
5
5
|
buildCattle,
|
|
6
|
+
buildFenceRing,
|
|
6
7
|
caninePose,
|
|
7
8
|
createDaylightSky,
|
|
8
9
|
createHouseKit,
|
|
@@ -12,11 +13,12 @@ import {
|
|
|
12
13
|
GeometryBuilder,
|
|
13
14
|
horsePose,
|
|
14
15
|
rigHorse,
|
|
16
|
+
scatterTrees,
|
|
17
|
+
scatterTussocks,
|
|
15
18
|
} from 'roamwright';
|
|
16
19
|
import { sstep } from 'roamwright/math/scalar.js';
|
|
17
20
|
import { createProps } from 'roamwright/geometry/props.js';
|
|
18
21
|
import { initExample, makeRollingGround } from './stage.js';
|
|
19
|
-
import { buildCircularFence, scatterTrees, scatterTussocks } from './stage-kits.js';
|
|
20
22
|
|
|
21
23
|
const { canvas, renderer, camera, scene, worldGroup, seed, random, noise, hash, shapes } = initExample({
|
|
22
24
|
fallbackSeed: 42,
|
|
@@ -53,7 +55,7 @@ const ground = makeRollingGround({
|
|
|
53
55
|
worldGroup.add(ground);
|
|
54
56
|
|
|
55
57
|
// Timber post-and-rail paddock fence and watering trough.
|
|
56
|
-
|
|
58
|
+
buildFenceRing({ parent: worldGroup, groundAt, radius: 16.5, posts: 28, random, postHeight: 1.28, railHeights: [0.48, 0.92] });
|
|
57
59
|
|
|
58
60
|
// Haycock and farm well beside the back fence.
|
|
59
61
|
const houseKit = createHouseKit({ shapes });
|
|
@@ -71,7 +73,7 @@ hayMesh.position.set(8.8, 0, -6.2);
|
|
|
71
73
|
|
|
72
74
|
// Trees and meadow tussocks outside and along the fence line.
|
|
73
75
|
const { material: leafMat } = scatterTrees({
|
|
74
|
-
worldGroup,
|
|
76
|
+
parent: worldGroup,
|
|
75
77
|
noise,
|
|
76
78
|
hash,
|
|
77
79
|
seed,
|
|
@@ -90,7 +92,7 @@ const { material: leafMat } = scatterTrees({
|
|
|
90
92
|
});
|
|
91
93
|
|
|
92
94
|
scatterTussocks({
|
|
93
|
-
worldGroup,
|
|
95
|
+
parent: worldGroup,
|
|
94
96
|
seed: seed * 11,
|
|
95
97
|
random,
|
|
96
98
|
groundAt,
|
package/examples/crowds.js
CHANGED
|
@@ -11,13 +11,14 @@ import {
|
|
|
11
11
|
grazeRound,
|
|
12
12
|
planCampWalkers,
|
|
13
13
|
planTownsfolk,
|
|
14
|
+
scatterTrees,
|
|
15
|
+
scatterTussocks,
|
|
14
16
|
} from 'roamwright';
|
|
15
17
|
import { sharedFields } from 'roamwright/motion/crowd-camp.js';
|
|
16
18
|
import { sstep } from 'roamwright/math/scalar.js';
|
|
17
19
|
import { C } from 'roamwright/geometry/primitives.js';
|
|
18
20
|
import { createProps } from 'roamwright/geometry/props.js';
|
|
19
21
|
import { initExample, makeRollingGround } from './stage.js';
|
|
20
|
-
import { scatterTrees, scatterTussocks } from './stage-kits.js';
|
|
21
22
|
|
|
22
23
|
const {
|
|
23
24
|
canvas,
|
|
@@ -122,7 +123,7 @@ createHouseKitMeshes({ materials: createHouseKitMaterials({ doubleSide: true })
|
|
|
122
123
|
|
|
123
124
|
// Trees and grass tussocks framing the meadow, market backdrop and pasture.
|
|
124
125
|
const { material: leafMat } = scatterTrees({
|
|
125
|
-
worldGroup,
|
|
126
|
+
parent: worldGroup,
|
|
126
127
|
noise,
|
|
127
128
|
hash,
|
|
128
129
|
seed,
|
|
@@ -143,7 +144,7 @@ const { material: leafMat } = scatterTrees({
|
|
|
143
144
|
});
|
|
144
145
|
|
|
145
146
|
scatterTussocks({
|
|
146
|
-
worldGroup,
|
|
147
|
+
parent: worldGroup,
|
|
147
148
|
seed: seed * 13,
|
|
148
149
|
random: rng,
|
|
149
150
|
groundAt: groundHeight,
|
package/examples/effects.js
CHANGED
|
@@ -1,26 +1,27 @@
|
|
|
1
1
|
import * as THREE from 'three';
|
|
2
2
|
import {
|
|
3
|
+
createFireLightWatch,
|
|
3
4
|
createHouseKit,
|
|
4
5
|
createHouseKitMaterials,
|
|
5
6
|
createHouseKitMeshes,
|
|
6
7
|
createOrbitCamera,
|
|
8
|
+
createParticleNoiseTexture,
|
|
9
|
+
createParticleSystem,
|
|
10
|
+
createSiteSchedule,
|
|
7
11
|
createSkyPanorama,
|
|
8
12
|
GeometryBuilder,
|
|
13
|
+
scatterTrees,
|
|
9
14
|
} from 'roamwright';
|
|
10
15
|
import { sstep } from 'roamwright/math/scalar.js';
|
|
11
16
|
import { C, TRS } from 'roamwright/geometry/primitives.js';
|
|
12
17
|
import { createProps } from 'roamwright/geometry/props.js';
|
|
13
|
-
import { createParticleSystem } from 'roamwright/rendering/particles.js';
|
|
14
18
|
import { createParticleEmitters, shakeCamera } from 'roamwright/rendering/particle-emitters.js';
|
|
15
19
|
import { createParticleBursts } from 'roamwright/rendering/particle-bursts.js';
|
|
16
20
|
import { createGroundMarks } from 'roamwright/rendering/ground-marks.js';
|
|
17
21
|
import { createSmokeShadows } from 'roamwright/rendering/smoke-shadows.js';
|
|
18
22
|
import { FLAME_KINDS, createFlameSources } from 'roamwright/rendering/flame-sources.js';
|
|
19
|
-
import { createFireLightWatch } from 'roamwright/rendering/fire-light-watch.js';
|
|
20
23
|
import { perspectivePointScale } from 'roamwright/rendering/viewport.js';
|
|
21
|
-
import { createSiteSchedule } from 'roamwright/runtime/effect-sites.js';
|
|
22
24
|
import { initExample } from './stage.js';
|
|
23
|
-
import { makeParticleNoiseTexture, scatterTrees } from './stage-kits.js';
|
|
24
25
|
|
|
25
26
|
const { canvas, renderer, camera, scene, worldGroup, fxScene, seed, random, noise, hash, shapes } = initExample({
|
|
26
27
|
fallbackSeed: 3,
|
|
@@ -130,7 +131,7 @@ const rockMesh = rocks.mesh(new THREE.MeshStandardMaterial({ vertexColors: true,
|
|
|
130
131
|
rockMesh.castShadow = rockMesh.receiveShadow = true;
|
|
131
132
|
|
|
132
133
|
scatterTrees({
|
|
133
|
-
worldGroup,
|
|
134
|
+
parent: worldGroup,
|
|
134
135
|
noise,
|
|
135
136
|
hash,
|
|
136
137
|
seed,
|
|
@@ -152,7 +153,7 @@ scatterTrees({
|
|
|
152
153
|
});
|
|
153
154
|
|
|
154
155
|
// Particles, noise sheet, and effect systems.
|
|
155
|
-
const noiseTexture =
|
|
156
|
+
const noiseTexture = createParticleNoiseTexture({ noise, size: 128 });
|
|
156
157
|
|
|
157
158
|
const pointScale = { value: 600 },
|
|
158
159
|
particles = createParticleSystem({
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as THREE from 'three';
|
|
2
2
|
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
|
|
3
3
|
import {
|
|
4
|
+
buildFenceRing,
|
|
4
5
|
createDaylightSky,
|
|
5
6
|
createFigureAssembler,
|
|
6
7
|
createFigureBuilder,
|
|
@@ -8,11 +9,12 @@ import {
|
|
|
8
9
|
figureActor,
|
|
9
10
|
geometryOf,
|
|
10
11
|
rigHorse,
|
|
12
|
+
scatterTrees,
|
|
13
|
+
scatterTussocks,
|
|
11
14
|
} from 'roamwright';
|
|
12
15
|
import { sstep } from 'roamwright/math/scalar.js';
|
|
13
|
-
import { createWind } from '
|
|
16
|
+
import { createWind } from 'roamwright/motion/wind.js';
|
|
14
17
|
import { initExample, makeRollingGround } from './stage.js';
|
|
15
|
-
import { buildCircularFence, scatterTrees, scatterTussocks } from './stage-kits.js';
|
|
16
18
|
|
|
17
19
|
const doing = document.getElementById('doing');
|
|
18
20
|
const { canvas, renderer, camera, scene, worldGroup, seed, random, noise, hash } = initExample({
|
|
@@ -45,11 +47,11 @@ const meadow = makeRollingGround({
|
|
|
45
47
|
worldGroup.add(meadow);
|
|
46
48
|
|
|
47
49
|
// Timber post-and-rail paddock fence ringing the 20 m training ground.
|
|
48
|
-
|
|
50
|
+
buildFenceRing({ parent: worldGroup, groundAt, radius: 20.5, posts: 32, random, postHeight: 1.32, railHeights: [0.52, 0.96] });
|
|
49
51
|
|
|
50
52
|
// Trees and meadow tussocks framing the paddock.
|
|
51
53
|
const { material: leafMat } = scatterTrees({
|
|
52
|
-
worldGroup,
|
|
54
|
+
parent: worldGroup,
|
|
53
55
|
noise,
|
|
54
56
|
hash,
|
|
55
57
|
seed,
|
|
@@ -65,7 +67,7 @@ const { material: leafMat } = scatterTrees({
|
|
|
65
67
|
});
|
|
66
68
|
|
|
67
69
|
scatterTussocks({
|
|
68
|
-
worldGroup,
|
|
70
|
+
parent: worldGroup,
|
|
69
71
|
seed: seed * 17,
|
|
70
72
|
random,
|
|
71
73
|
groundAt,
|
package/examples/fliers.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as THREE from 'three';
|
|
2
|
-
import { createDaylightSky, createOrbitCamera, createStreetLamps } from 'roamwright';
|
|
2
|
+
import { createDaylightSky, createOrbitCamera, createStreetLamps, scatterTrees, scatterTussocks } from 'roamwright';
|
|
3
3
|
import { sstep } from 'roamwright/math/scalar.js';
|
|
4
4
|
import { GB } from 'roamwright/geometry/builder.js';
|
|
5
5
|
import { C, TRS } from 'roamwright/geometry/primitives.js';
|
|
@@ -14,7 +14,6 @@ import { createLongFlierCompany } from 'roamwright/rendering/flier-long-body-com
|
|
|
14
14
|
import { createFlierShapes, createSwarm } from 'roamwright/rendering/flier-swarm.js';
|
|
15
15
|
import { createFlock } from 'roamwright/rendering/flocks.js';
|
|
16
16
|
import { initExample, makeRollingGround } from './stage.js';
|
|
17
|
-
import { scatterTrees, scatterTussocks } from './stage-kits.js';
|
|
18
17
|
|
|
19
18
|
const { canvas, renderer, camera, scene, worldGroup, seed, random, noise, hash, shapes } = initExample({
|
|
20
19
|
fallbackSeed: 7,
|
|
@@ -83,7 +82,7 @@ worldGroup.add(lampLight);
|
|
|
83
82
|
|
|
84
83
|
// Trees and meadow tussocks framing the crag and distant ridge.
|
|
85
84
|
const { material: leafMat } = scatterTrees({
|
|
86
|
-
worldGroup,
|
|
85
|
+
parent: worldGroup,
|
|
87
86
|
noise,
|
|
88
87
|
hash,
|
|
89
88
|
seed,
|
|
@@ -105,7 +104,7 @@ const { material: leafMat } = scatterTrees({
|
|
|
105
104
|
});
|
|
106
105
|
|
|
107
106
|
scatterTussocks({
|
|
108
|
-
worldGroup,
|
|
107
|
+
parent: worldGroup,
|
|
109
108
|
seed: seed * 19,
|
|
110
109
|
random,
|
|
111
110
|
groundAt,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as THREE from 'three';
|
|
2
2
|
import {
|
|
3
3
|
buildPortalGateway,
|
|
4
|
+
createCityFortification,
|
|
4
5
|
createDaylightSky,
|
|
5
6
|
createHouseKit,
|
|
6
7
|
createHouseKitMaterials,
|
|
@@ -9,12 +10,12 @@ import {
|
|
|
9
10
|
createSimpleWater,
|
|
10
11
|
createSpaces,
|
|
11
12
|
mulberry32,
|
|
13
|
+
scatterTrees,
|
|
12
14
|
} from 'roamwright';
|
|
13
15
|
import { townFrame } from 'roamwright/geometry/land-town-ground.js';
|
|
14
16
|
import { C } from 'roamwright/geometry/primitives.js';
|
|
15
17
|
import { sstep } from 'roamwright/math/scalar.js';
|
|
16
18
|
import { initExample, makeRollingGround } from './stage.js';
|
|
17
|
-
import { createShowcaseFortification, scatterTrees } from './stage-kits.js';
|
|
18
19
|
|
|
19
20
|
const { canvas, renderer, camera, scene, worldGroup, seed, noise, hash, shapes } = initExample({
|
|
20
21
|
fallbackSeed: 11,
|
|
@@ -70,7 +71,7 @@ function ground(x, z) {
|
|
|
70
71
|
}
|
|
71
72
|
|
|
72
73
|
const { addBox } = createSpaces({ ground });
|
|
73
|
-
const fort =
|
|
74
|
+
const fort = createCityFortification({ ground, addBox, shapes, houseKit });
|
|
74
75
|
|
|
75
76
|
const plan = {
|
|
76
77
|
yaw: 0,
|
|
@@ -226,7 +227,7 @@ if (coastal) {
|
|
|
226
227
|
|
|
227
228
|
// Sparse cypress/cedar trees dotting the slopes outside the walls.
|
|
228
229
|
scatterTrees({
|
|
229
|
-
worldGroup,
|
|
230
|
+
parent: worldGroup,
|
|
230
231
|
noise,
|
|
231
232
|
hash,
|
|
232
233
|
seed,
|
package/examples/house-kit.js
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import * as THREE from 'three';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
createDaylightSky,
|
|
4
|
+
createHouseKit,
|
|
5
|
+
createHouseKitMaterials,
|
|
6
|
+
createHouseKitMeshes,
|
|
7
|
+
createOrbitCamera,
|
|
8
|
+
scatterTrees,
|
|
9
|
+
} from 'roamwright';
|
|
3
10
|
import { sstep } from 'roamwright/math/scalar.js';
|
|
4
11
|
import { createProps } from 'roamwright/geometry/props.js';
|
|
5
12
|
import { initExample, makeRollingGround } from './stage.js';
|
|
6
|
-
import { scatterTrees } from './stage-kits.js';
|
|
7
13
|
|
|
8
14
|
const { canvas, renderer, camera, scene, worldGroup, seed, random, noise, hash, shapes } = initExample({
|
|
9
15
|
fallbackSeed: 42,
|
|
@@ -130,7 +136,7 @@ kitStatic(propKit, houses);
|
|
|
130
136
|
|
|
131
137
|
// Trees framing the green hills behind the square.
|
|
132
138
|
scatterTrees({
|
|
133
|
-
worldGroup,
|
|
139
|
+
parent: worldGroup,
|
|
134
140
|
noise,
|
|
135
141
|
hash,
|
|
136
142
|
seed,
|
package/examples/pacing.js
CHANGED
|
@@ -14,12 +14,12 @@ import {
|
|
|
14
14
|
groundRenderOrder,
|
|
15
15
|
readDevice,
|
|
16
16
|
resolveDevicePresets,
|
|
17
|
+
scatterTrees,
|
|
17
18
|
} from 'roamwright';
|
|
18
19
|
import { sstep } from 'roamwright/math/scalar.js';
|
|
19
20
|
import { createDiagnosticLog } from 'roamwright/runtime/diagnostic-log.js';
|
|
20
21
|
import { estimateMemory } from 'roamwright/rendering/memory-estimate.js';
|
|
21
22
|
import { initExample, makeRollingGround } from './stage.js';
|
|
22
|
-
import { scatterTrees } from './stage-kits.js';
|
|
23
23
|
|
|
24
24
|
const { canvas, renderer, camera, scene, worldGroup, seed, random, noise, hash, shapes } = initExample({
|
|
25
25
|
fallbackSeed: 42,
|
|
@@ -141,7 +141,7 @@ createHouseKitMeshes({ materials: createHouseKitMaterials({ roughness: 0.9 }) })
|
|
|
141
141
|
const treeGroup = new THREE.Group();
|
|
142
142
|
worldGroup.add(treeGroup);
|
|
143
143
|
scatterTrees({
|
|
144
|
-
|
|
144
|
+
parent: treeGroup,
|
|
145
145
|
noise,
|
|
146
146
|
hash,
|
|
147
147
|
seed,
|
package/examples/rooms.js
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
import * as THREE from 'three';
|
|
2
2
|
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
import {
|
|
4
|
+
bindKeyboardOrbit,
|
|
5
|
+
createParticleNoiseTexture,
|
|
6
|
+
createParticleSystem,
|
|
7
|
+
createRoomKit,
|
|
8
|
+
createRoomMaterials,
|
|
9
|
+
createSiteSchedule,
|
|
10
|
+
finishRoom,
|
|
11
|
+
} from 'roamwright';
|
|
12
|
+
import { createParticleEmitters } from 'roamwright/rendering/particle-emitters.js';
|
|
13
|
+
import { updateRoomLight } from 'roamwright/rendering/room-light.js';
|
|
14
|
+
import { perspectivePointScale } from 'roamwright/rendering/viewport.js';
|
|
9
15
|
import { initExample } from './stage.js';
|
|
10
|
-
import { makeParticleNoiseTexture } from './stage-kits.js';
|
|
11
16
|
|
|
12
17
|
const { canvas, renderer, camera, scene, worldGroup, seed, noise, hash, shapes } = initExample({
|
|
13
18
|
fallbackSeed: 42,
|
|
@@ -145,7 +150,7 @@ const finish = (R, def) =>
|
|
|
145
150
|
const rooms = { small: await smallRoom(), hall: await hall() };
|
|
146
151
|
|
|
147
152
|
// Real engine fire inside the small room's hearth, using the fire site emitted by kit.hearth().
|
|
148
|
-
const noiseTexture =
|
|
153
|
+
const noiseTexture = createParticleNoiseTexture({ noise, size: 128 });
|
|
149
154
|
const pointScale = { value: 520 };
|
|
150
155
|
let fireClock = 0;
|
|
151
156
|
const particles = createParticleSystem({
|
package/examples/ships.js
CHANGED
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
createShipMeshes,
|
|
10
10
|
createSimpleWater,
|
|
11
11
|
GeometryBuilder,
|
|
12
|
+
scatterTrees,
|
|
12
13
|
SHIP_PRESETS,
|
|
13
14
|
} from 'roamwright';
|
|
14
15
|
import { sstep } from 'roamwright/math/scalar.js';
|
|
@@ -18,7 +19,6 @@ import { YARD_STOWED } from 'roamwright/geometry/ship-rig.js';
|
|
|
18
19
|
import { createBoatSailing, openWaterCourse } from 'roamwright/motion/boat-sailing.js';
|
|
19
20
|
import { createProps } from 'roamwright/geometry/props.js';
|
|
20
21
|
import { initExample, makeRollingGround } from './stage.js';
|
|
21
|
-
import { scatterTrees } from './stage-kits.js';
|
|
22
22
|
|
|
23
23
|
const { canvas, renderer, camera, scene, worldGroup, seed, random, noise, hash, shapes } = initExample({
|
|
24
24
|
fallbackSeed: 42,
|
|
@@ -141,7 +141,7 @@ kitStatic(propKit, portGroup);
|
|
|
141
141
|
|
|
142
142
|
// Coastal pines and cedars along the headland behind the warehouses.
|
|
143
143
|
scatterTrees({
|
|
144
|
-
worldGroup,
|
|
144
|
+
parent: worldGroup,
|
|
145
145
|
noise,
|
|
146
146
|
hash,
|
|
147
147
|
seed,
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import * as THREE from 'three';
|
|
2
|
-
import { createSimpleWater, GeometryBuilder, mulberry32 } from 'roamwright';
|
|
2
|
+
import { buildFenceRing, createSimpleWater, GeometryBuilder, mulberry32, scatterTrees, scatterTussocks } 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
6
|
import { makeRollingGround } from './stage.js';
|
|
7
|
-
import { buildCircularFence, scatterTrees, scatterTussocks } from './stage-kits.js';
|
|
8
7
|
|
|
9
8
|
/**
|
|
10
9
|
* Builds the coastal valley terrain, river mouth, bay water, stone harbour quay,
|
|
@@ -81,8 +80,8 @@ export function buildSmallWorldLand({ world, worldGroup, seed, rng, noise, hash,
|
|
|
81
80
|
quayMesh.castShadow = quayMesh.receiveShadow = true;
|
|
82
81
|
|
|
83
82
|
// Timber paddock fence enclosing the grazing pasture east of the town.
|
|
84
|
-
|
|
85
|
-
worldGroup,
|
|
83
|
+
buildFenceRing({
|
|
84
|
+
parent: worldGroup,
|
|
86
85
|
groundAt,
|
|
87
86
|
cx: world.pasture.x,
|
|
88
87
|
cz: world.pasture.z,
|
|
@@ -94,7 +93,7 @@ export function buildSmallWorldLand({ world, worldGroup, seed, rng, noise, hash,
|
|
|
94
93
|
|
|
95
94
|
// Woodland, meadow tussocks and swaying river reeds.
|
|
96
95
|
const { material: leafMat } = scatterTrees({
|
|
97
|
-
worldGroup,
|
|
96
|
+
parent: worldGroup,
|
|
98
97
|
noise,
|
|
99
98
|
hash,
|
|
100
99
|
seed,
|
|
@@ -117,7 +116,7 @@ export function buildSmallWorldLand({ world, worldGroup, seed, rng, noise, hash,
|
|
|
117
116
|
});
|
|
118
117
|
|
|
119
118
|
scatterTussocks({
|
|
120
|
-
worldGroup,
|
|
119
|
+
parent: worldGroup,
|
|
121
120
|
seed: seed * 13,
|
|
122
121
|
random: rng,
|
|
123
122
|
groundAt,
|
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import * as THREE from 'three';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
createCityFortification,
|
|
4
|
+
createHouseKit,
|
|
5
|
+
createHouseKitMaterials,
|
|
6
|
+
createHouseKitMeshes,
|
|
7
|
+
createStreetLamps,
|
|
8
|
+
GeometryBuilder,
|
|
9
|
+
} from 'roamwright';
|
|
3
10
|
import { townFrame } from 'roamwright/geometry/land-town-ground.js';
|
|
4
11
|
import { createProps } from 'roamwright/geometry/props.js';
|
|
5
|
-
import { createShowcaseFortification } from './stage-kits.js';
|
|
6
12
|
|
|
7
13
|
const STYLES = {
|
|
8
14
|
town: {
|
|
@@ -43,7 +49,7 @@ const ROOF_PALETTE = [0x8c4c38, 0x674b3d, 0x9b5f3d, 0x5c686a];
|
|
|
43
49
|
*/
|
|
44
50
|
export function buildSmallWorldTown({ world, worldGroup, seed, rng, noise, hash, shapes, groundAt, spaceKit }) {
|
|
45
51
|
const houseKit = createHouseKit({ shapes, styles: STYLES });
|
|
46
|
-
const fort =
|
|
52
|
+
const fort = createCityFortification({ ground: groundAt, addBox: spaceKit.addBox, shapes, houseKit });
|
|
47
53
|
const frame = townFrame({ ...world.town, water: -1.5 });
|
|
48
54
|
const townSpace = { id: world.town.id, decks: [], grid: new Map(), ground: groundAt };
|
|
49
55
|
const K = fort.cityKit(townSpace, frame);
|
package/examples/soundscape.js
CHANGED
|
@@ -8,14 +8,18 @@ import {
|
|
|
8
8
|
createHouseKitMaterials,
|
|
9
9
|
createHouseKitMeshes,
|
|
10
10
|
createOrbitCamera,
|
|
11
|
+
createScriptFoley,
|
|
11
12
|
createShipKit,
|
|
12
13
|
createShipMeshes,
|
|
13
14
|
createSimpleWater,
|
|
15
|
+
createSoundscape,
|
|
16
|
+
createStrideFoley,
|
|
14
17
|
figureActor,
|
|
15
18
|
GeometryBuilder,
|
|
16
19
|
geometryOf,
|
|
17
20
|
mulberry32,
|
|
18
21
|
rigHorse,
|
|
22
|
+
scatterTrees,
|
|
19
23
|
SHIP_PRESETS,
|
|
20
24
|
} from 'roamwright';
|
|
21
25
|
import { sstep } from 'roamwright/math/scalar.js';
|
|
@@ -23,12 +27,8 @@ import { C, TRS } from 'roamwright/geometry/primitives.js';
|
|
|
23
27
|
import { oneOf } from 'roamwright/geometry/ship-kit.js';
|
|
24
28
|
import { createProps } from 'roamwright/geometry/props.js';
|
|
25
29
|
import { createReeds } from 'roamwright/rendering/plant-reeds.js';
|
|
26
|
-
import { createWind } from '
|
|
27
|
-
import { createScriptFoley } from '../runtime/foley-script.js';
|
|
28
|
-
import { createStrideFoley } from '../runtime/foley-strides.js';
|
|
29
|
-
import { createSoundscape } from '../runtime/soundscape.js';
|
|
30
|
+
import { createWind } from 'roamwright/motion/wind.js';
|
|
30
31
|
import { initExample, makeRollingGround } from './stage.js';
|
|
31
|
-
import { scatterTrees } from './stage-kits.js';
|
|
32
32
|
|
|
33
33
|
const { canvas, renderer, camera, scene, worldGroup, seed, random, noise, hash, shapes } = initExample({
|
|
34
34
|
fallbackSeed: 42,
|
|
@@ -143,7 +143,7 @@ createHouseKitMeshes({ materials: createHouseKitMaterials({ doubleSide: true })
|
|
|
143
143
|
|
|
144
144
|
// Trees framing the lakeside meadow and swaying reeds along the water's edge.
|
|
145
145
|
scatterTrees({
|
|
146
|
-
worldGroup,
|
|
146
|
+
parent: worldGroup,
|
|
147
147
|
noise,
|
|
148
148
|
hash,
|
|
149
149
|
seed,
|
package/examples/towns.js
CHANGED
|
@@ -14,13 +14,13 @@ import {
|
|
|
14
14
|
GeometryBuilder,
|
|
15
15
|
layVillage,
|
|
16
16
|
mulberry32,
|
|
17
|
+
scatterTrees,
|
|
17
18
|
} from 'roamwright';
|
|
18
19
|
import { createPieceBatch, TIGHT } from 'roamwright/rendering/piece-batch.js';
|
|
19
20
|
import { C, TRS } from 'roamwright/geometry/primitives.js';
|
|
20
21
|
import { litShare } from 'roamwright/math/lit-share.js';
|
|
21
22
|
import { sstep } from 'roamwright/math/scalar.js';
|
|
22
23
|
import { initExample, makeRollingGround } from './stage.js';
|
|
23
|
-
import { scatterTrees } from './stage-kits.js';
|
|
24
24
|
|
|
25
25
|
const { canvas, renderer, camera, scene, worldGroup, seed, random, noise, hash, shapes } = initExample({
|
|
26
26
|
fallbackSeed: 7,
|
|
@@ -170,7 +170,7 @@ worldGroup.add(wallMesh);
|
|
|
170
170
|
|
|
171
171
|
// Trees framing the pastures around the village.
|
|
172
172
|
scatterTrees({
|
|
173
|
-
worldGroup,
|
|
173
|
+
parent: worldGroup,
|
|
174
174
|
noise,
|
|
175
175
|
hash,
|
|
176
176
|
seed,
|
|
@@ -53,10 +53,11 @@ const SOOT = [0.05, 0.045, 0.04];
|
|
|
53
53
|
* @param {(hex: number, jitter?: number, rng?: () => number) => number[]} [options.color] - Linear RGB colour helper.
|
|
54
54
|
* @param {Function} [options.transform] - Transform matrix helper (`TRS`).
|
|
55
55
|
* @param {typeof GB} [options.Builder] - Geometry builder class.
|
|
56
|
-
* @param {
|
|
57
|
-
* @param {Function} [options.
|
|
58
|
-
* @param {Function} [options.
|
|
59
|
-
* @param {Function} [options.
|
|
56
|
+
* @param {object} [options.houseKit] - Optional house kit (`createHouseKit`) supplying `archOpening`, `archRing`, `facePut`, and `kitNew` defaults.
|
|
57
|
+
* @param {Function} [options.archOpening] - House kit `archOpening` function (overrides `options.houseKit.archOpening`).
|
|
58
|
+
* @param {Function} [options.archRing] - House kit `archRing` function (overrides `options.houseKit.archRing`).
|
|
59
|
+
* @param {Function} [options.facePut] - House kit `facePut` function (overrides `options.houseKit.facePut`).
|
|
60
|
+
* @param {Function} [options.kitNew] - House kit `kitNew` factory for city sub-builders (overrides `options.houseKit.kitNew`).
|
|
60
61
|
* @param {Function} [options.greatWalls] - Walkable great-walls builder (defaults to `createGreatWalls`).
|
|
61
62
|
* @param {Function} [options.greatGateMouth] - Walkable great-wall gate mouth dimensions helper.
|
|
62
63
|
* @returns {{
|
|
@@ -79,12 +80,13 @@ export function createCityFortification(options = {}) {
|
|
|
79
80
|
const color = options.color ?? defaultColor;
|
|
80
81
|
const transform = options.transform ?? defaultTransform;
|
|
81
82
|
const Builder = options.Builder ?? GB;
|
|
83
|
+
const houseKit = options.houseKit ?? null;
|
|
82
84
|
let houseKitFallback = null;
|
|
83
85
|
const fallbackKit = () => (houseKitFallback ??= createHouseKit({ shapes }));
|
|
84
|
-
const archOpening = options.archOpening ?? fallbackKit().archOpening;
|
|
85
|
-
const archRing = options.archRing ?? fallbackKit().archRing;
|
|
86
|
-
const facePut = options.facePut ?? fallbackKit().facePut;
|
|
87
|
-
const kitNew = options.kitNew ?? fallbackKit().kitNew;
|
|
86
|
+
const archOpening = options.archOpening ?? houseKit?.archOpening ?? fallbackKit().archOpening;
|
|
87
|
+
const archRing = options.archRing ?? houseKit?.archRing ?? fallbackKit().archRing;
|
|
88
|
+
const facePut = options.facePut ?? houseKit?.facePut ?? fallbackKit().facePut;
|
|
89
|
+
const kitNew = options.kitNew ?? houseKit?.kitNew ?? fallbackKit().kitNew;
|
|
88
90
|
const defaultGreat = options.greatWalls && options.greatGateMouth ? null : createGreatWalls({ markWall, color });
|
|
89
91
|
const greatWalls = options.greatWalls ?? defaultGreat.greatWalls;
|
|
90
92
|
const greatGateMouth = options.greatGateMouth ?? defaultGreat.greatGateMouth;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Worker-safe instance placement planner: samples `(x, z)` points over a ground sampler and fills compact column-major
|
|
3
|
+
* 4×4 transform buffers per variant bucket with zero Three.js dependency or per-instance object allocation.
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { mulberry32 } from '../math/random.js';
|
|
8
|
+
import { TAU } from '../math/scalar.js';
|
|
9
|
+
|
|
10
|
+
const DEFAULT_SPREAD_METRES = 40;
|
|
11
|
+
const MATRIX_STRIDE = 16;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Samples candidate `(x, z)` placements across `attempts` iterations, distributes accepted points round-robin into
|
|
15
|
+
* `buckets` variant pools (`i % buckets`), grounds each at `groundAt(x, z) - sink`, applies a random Y-axis yaw and
|
|
16
|
+
* uniform scale `scaleRange[0] + random() * scaleRange[1]`, and writes column-major 4×4 transform matrices into compact
|
|
17
|
+
* `Float32Array` buffers ready for `THREE.InstancedMesh` or structured transfer from a worker.
|
|
18
|
+
*
|
|
19
|
+
* @param {object} [options] - Placement parameters.
|
|
20
|
+
* @param {number} [options.attempts=90] - Number of candidate samples to draw.
|
|
21
|
+
* @param {number} [options.maxPerBucket=32] - Maximum accepted instances per bucket.
|
|
22
|
+
* @param {number} [options.buckets=1] - Number of variant buckets (round-robin by attempt index `i % buckets`).
|
|
23
|
+
* @param {(attempt: number) => [number, number] | null | undefined} [options.sample] - Returns `[x, z]` in metres or a falsy value to reject the candidate. Defaults to uniform random points in a 40 m square.
|
|
24
|
+
* @param {(x: number, z: number) => number} [options.groundAt] - Terrain elevation sampler `(x, z) => y` in metres (defaults to flat `0`).
|
|
25
|
+
* @param {() => number} [options.random] - Deterministic PRNG in `[0, 1)` (defaults to `mulberry32(1)`).
|
|
26
|
+
* @param {[number, number]} [options.scaleRange=[1, 0]] - Uniform scale `[minScale, scaleSpan]`: each instance receives `scaleRange[0] + random() * scaleRange[1]`.
|
|
27
|
+
* @param {number} [options.sink=0] - Vertical sink below `groundAt(x, z)` in metres so trunks and roots seat cleanly on slopes.
|
|
28
|
+
* @param {boolean} [options.stopWhenFull=false] - When `true`, stops sampling once every bucket reaches `maxPerBucket`. Leave `false` when callers rely on a fixed `attempts` draw count against a shared PRNG.
|
|
29
|
+
* @returns {{ buckets: Array<{ count: number, matrices: Float32Array }>, total: number }} Per-bucket counts and tightly sized 4×4 transform buffers, plus total placed count.
|
|
30
|
+
*/
|
|
31
|
+
export function planScatterInstances({
|
|
32
|
+
attempts = 90,
|
|
33
|
+
maxPerBucket = 32,
|
|
34
|
+
buckets = 1,
|
|
35
|
+
sample,
|
|
36
|
+
groundAt = () => 0,
|
|
37
|
+
random = mulberry32(1),
|
|
38
|
+
scaleRange = [1, 0],
|
|
39
|
+
sink = 0,
|
|
40
|
+
stopWhenFull = false,
|
|
41
|
+
} = {}) {
|
|
42
|
+
if (!Number.isInteger(buckets) || buckets < 1) throw new RangeError('buckets must be a positive integer');
|
|
43
|
+
if (!Number.isInteger(maxPerBucket) || maxPerBucket < 0) throw new RangeError('maxPerBucket must be a non-negative integer');
|
|
44
|
+
if (!Number.isInteger(attempts) || attempts < 0) throw new RangeError('attempts must be a non-negative integer');
|
|
45
|
+
|
|
46
|
+
const samplePoint = sample ?? (() => [(random() - 0.5) * DEFAULT_SPREAD_METRES, (random() - 0.5) * DEFAULT_SPREAD_METRES]);
|
|
47
|
+
const buffers = Array.from({ length: buckets }, () => new Float32Array(maxPerBucket * MATRIX_STRIDE));
|
|
48
|
+
const counts = new Int32Array(buckets);
|
|
49
|
+
const maxTotal = buckets * maxPerBucket;
|
|
50
|
+
const minScale = scaleRange[0];
|
|
51
|
+
const scaleSpan = scaleRange[1];
|
|
52
|
+
let total = 0;
|
|
53
|
+
|
|
54
|
+
for (let i = 0; i < attempts; i++) {
|
|
55
|
+
if (stopWhenFull && total >= maxTotal) break;
|
|
56
|
+
const point = samplePoint(i);
|
|
57
|
+
if (!point) continue;
|
|
58
|
+
const bucketIndex = i % buckets;
|
|
59
|
+
const count = counts[bucketIndex];
|
|
60
|
+
if (count >= maxPerBucket) continue;
|
|
61
|
+
|
|
62
|
+
const tx = point[0];
|
|
63
|
+
const tz = point[1];
|
|
64
|
+
const ty = groundAt(tx, tz) - sink;
|
|
65
|
+
const yaw = random() * TAU;
|
|
66
|
+
const scale = minScale + random() * scaleSpan;
|
|
67
|
+
const cos = Math.cos(yaw);
|
|
68
|
+
const sin = Math.sin(yaw);
|
|
69
|
+
|
|
70
|
+
const matrices = buffers[bucketIndex];
|
|
71
|
+
const offset = count * MATRIX_STRIDE;
|
|
72
|
+
matrices[offset] = cos * scale;
|
|
73
|
+
matrices[offset + 1] = 0;
|
|
74
|
+
matrices[offset + 2] = -sin * scale;
|
|
75
|
+
matrices[offset + 3] = 0;
|
|
76
|
+
matrices[offset + 4] = 0;
|
|
77
|
+
matrices[offset + 5] = scale;
|
|
78
|
+
matrices[offset + 6] = 0;
|
|
79
|
+
matrices[offset + 7] = 0;
|
|
80
|
+
matrices[offset + 8] = sin * scale;
|
|
81
|
+
matrices[offset + 9] = 0;
|
|
82
|
+
matrices[offset + 10] = cos * scale;
|
|
83
|
+
matrices[offset + 11] = 0;
|
|
84
|
+
matrices[offset + 12] = tx;
|
|
85
|
+
matrices[offset + 13] = ty;
|
|
86
|
+
matrices[offset + 14] = tz;
|
|
87
|
+
matrices[offset + 15] = 1;
|
|
88
|
+
|
|
89
|
+
counts[bucketIndex] = count + 1;
|
|
90
|
+
total++;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return {
|
|
94
|
+
buckets: buffers.map((buffer, index) => {
|
|
95
|
+
const count = counts[index];
|
|
96
|
+
return {
|
|
97
|
+
count,
|
|
98
|
+
matrices: count === maxPerBucket ? buffer : buffer.slice(0, count * MATRIX_STRIDE),
|
|
99
|
+
};
|
|
100
|
+
}),
|
|
101
|
+
total,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
@@ -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/examples/stage-kits.js
DELETED
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
import * as THREE from 'three';
|
|
2
|
-
import { createCityFortification, createGreatWalls, GeometryBuilder, mulberry32 } from 'roamwright';
|
|
3
|
-
import { particleNoise } from '../math/particle-noise.js';
|
|
4
|
-
import { C } from '../geometry/primitives.js';
|
|
5
|
-
import { partsGeometry } from '../geometry/foliage.js';
|
|
6
|
-
import { createPlantTints } from '../geometry/plant-tints.js';
|
|
7
|
-
import { createTrees } from '../geometry/plant-trees.js';
|
|
8
|
-
import { PLAIN_GRASS, tussockGeometry } from '../geometry/plant-tussock.js';
|
|
9
|
-
|
|
10
|
-
// Shared fortification, foliage scatter, paddock fence, and particle-noise helpers for showcase examples.
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Binds createGreatWalls and createCityFortification to a houseKit and terrain sampler.
|
|
14
|
-
*/
|
|
15
|
-
export function createShowcaseFortification({ ground, addBox, shapes, houseKit }) {
|
|
16
|
-
const great = createGreatWalls();
|
|
17
|
-
return createCityFortification({
|
|
18
|
-
ground,
|
|
19
|
-
addBox,
|
|
20
|
-
shapes,
|
|
21
|
-
archOpening: houseKit.archOpening,
|
|
22
|
-
archRing: houseKit.archRing,
|
|
23
|
-
facePut: houseKit.facePut,
|
|
24
|
-
kitNew: houseKit.kitNew,
|
|
25
|
-
greatWalls: great.greatWalls,
|
|
26
|
-
greatGateMouth: great.greatGateMouth,
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Builds instanced trees from the engine plant kit using a caller-supplied placement sampler.
|
|
32
|
-
*/
|
|
33
|
-
export function scatterTrees({
|
|
34
|
-
worldGroup,
|
|
35
|
-
noise,
|
|
36
|
-
hash,
|
|
37
|
-
seed,
|
|
38
|
-
random,
|
|
39
|
-
groundAt,
|
|
40
|
-
attempts = 90,
|
|
41
|
-
maxPerSpecies = 32,
|
|
42
|
-
species = ['broadleaf', 'conifer', 'cedar'],
|
|
43
|
-
sample,
|
|
44
|
-
scaleRange = [0.85, 0.7],
|
|
45
|
-
sink = 0.12,
|
|
46
|
-
roughness = 0.88,
|
|
47
|
-
}) {
|
|
48
|
-
const tints = createPlantTints({ fbm: noise.fbm, vnoise: noise.vnoise, hash });
|
|
49
|
-
const treeKit = createTrees({ hash, ...tints, seed });
|
|
50
|
-
const material = new THREE.MeshStandardMaterial({ vertexColors: true, roughness, side: THREE.DoubleSide });
|
|
51
|
-
const builders = {
|
|
52
|
-
broadleaf: () => treeKit.broadleaf(),
|
|
53
|
-
conifer: () => treeKit.conifer(),
|
|
54
|
-
cedar: () => treeKit.cedar(0),
|
|
55
|
-
};
|
|
56
|
-
const geos = species.map(name => partsGeometry(builders[name]().near));
|
|
57
|
-
const pools = geos.map(geo => {
|
|
58
|
-
const mesh = new THREE.InstancedMesh(geo, material, maxPerSpecies);
|
|
59
|
-
mesh.castShadow = mesh.receiveShadow = true;
|
|
60
|
-
mesh.count = 0;
|
|
61
|
-
worldGroup.add(mesh);
|
|
62
|
-
return mesh;
|
|
63
|
-
});
|
|
64
|
-
const dummy = new THREE.Object3D();
|
|
65
|
-
for (let i = 0; i < attempts; i++) {
|
|
66
|
-
const pt = sample(i);
|
|
67
|
-
if (!pt) continue;
|
|
68
|
-
const pool = pools[i % pools.length];
|
|
69
|
-
if (pool.count >= maxPerSpecies) continue;
|
|
70
|
-
const [tx, tz] = pt;
|
|
71
|
-
dummy.position.set(tx, groundAt(tx, tz) - sink, tz);
|
|
72
|
-
dummy.rotation.set(0, random() * Math.PI * 2, 0);
|
|
73
|
-
dummy.scale.setScalar(scaleRange[0] + random() * scaleRange[1]);
|
|
74
|
-
dummy.updateMatrix();
|
|
75
|
-
pool.setMatrixAt(pool.count++, dummy.matrix);
|
|
76
|
-
}
|
|
77
|
-
for (const pool of pools) pool.instanceMatrix.needsUpdate = true;
|
|
78
|
-
return { pools, material };
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Scatters instanced grass tussocks across terrain points returned by sample(i).
|
|
83
|
-
*/
|
|
84
|
-
export function scatterTussocks({
|
|
85
|
-
worldGroup,
|
|
86
|
-
seed,
|
|
87
|
-
random,
|
|
88
|
-
groundAt,
|
|
89
|
-
count = 60,
|
|
90
|
-
attempts = 110,
|
|
91
|
-
sample,
|
|
92
|
-
scaleRange = [0.8, 0.55],
|
|
93
|
-
grass = PLAIN_GRASS,
|
|
94
|
-
material = null,
|
|
95
|
-
}) {
|
|
96
|
-
const mat = material ?? new THREE.MeshStandardMaterial({ vertexColors: true, roughness: 0.88, side: THREE.DoubleSide });
|
|
97
|
-
const geo = tussockGeometry(mulberry32(seed), false, grass);
|
|
98
|
-
const mesh = new THREE.InstancedMesh(geo, mat, count);
|
|
99
|
-
const dummy = new THREE.Object3D();
|
|
100
|
-
let placed = 0;
|
|
101
|
-
for (let i = 0; i < attempts && placed < count; i++) {
|
|
102
|
-
const pt = sample(i);
|
|
103
|
-
if (!pt) continue;
|
|
104
|
-
const [tx, tz] = pt;
|
|
105
|
-
dummy.position.set(tx, groundAt(tx, tz), tz);
|
|
106
|
-
dummy.rotation.set(0, random() * Math.PI * 2, 0);
|
|
107
|
-
dummy.scale.setScalar(scaleRange[0] + random() * scaleRange[1]);
|
|
108
|
-
dummy.updateMatrix();
|
|
109
|
-
mesh.setMatrixAt(placed++, dummy.matrix);
|
|
110
|
-
}
|
|
111
|
-
mesh.count = placed;
|
|
112
|
-
mesh.instanceMatrix.needsUpdate = true;
|
|
113
|
-
worldGroup.add(mesh);
|
|
114
|
-
return mesh;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Builds a circular timber post-and-rail paddock fence grounded on heightAt.
|
|
119
|
-
*/
|
|
120
|
-
export function buildCircularFence({
|
|
121
|
-
worldGroup,
|
|
122
|
-
groundAt,
|
|
123
|
-
cx = 0,
|
|
124
|
-
cz = 0,
|
|
125
|
-
radius = 16.5,
|
|
126
|
-
posts = 28,
|
|
127
|
-
random,
|
|
128
|
-
postHeight = 1.28,
|
|
129
|
-
railHeights = [0.48, 0.92],
|
|
130
|
-
}) {
|
|
131
|
-
const fence = new GeometryBuilder();
|
|
132
|
-
for (let i = 0; i < posts; i++) {
|
|
133
|
-
const a0 = (i / posts) * Math.PI * 2;
|
|
134
|
-
const a1 = ((i + 1) / posts) * Math.PI * 2;
|
|
135
|
-
const x0 = cx + Math.cos(a0) * radius;
|
|
136
|
-
const z0 = cz + Math.sin(a0) * radius;
|
|
137
|
-
const y0 = groundAt(x0, z0);
|
|
138
|
-
const x1 = cx + Math.cos(a1) * radius;
|
|
139
|
-
const z1 = cz + Math.sin(a1) * radius;
|
|
140
|
-
const y1 = groundAt(x1, z1);
|
|
141
|
-
fence.box(x0, y0 - 0.1, z0, 0.15, postHeight, 0.15, C(0x6d563f, 0.1, random));
|
|
142
|
-
const mx = (x0 + x1) / 2;
|
|
143
|
-
const mz = (z0 + z1) / 2;
|
|
144
|
-
const my = (y0 + y1) / 2;
|
|
145
|
-
const span = Math.hypot(x1 - x0, z1 - z0);
|
|
146
|
-
const yaw = Math.atan2(x1 - x0, z1 - z0);
|
|
147
|
-
for (const h of railHeights) fence.box(mx, my + h, mz, 0.07, 0.1, span, C(0x7e654b, 0.08, random), yaw);
|
|
148
|
-
}
|
|
149
|
-
return fence.mesh(new THREE.MeshStandardMaterial({ vertexColors: true, roughness: 0.92 }), worldGroup);
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Generates the seamless 4-channel procedural noise texture consumed by createParticleSystem.
|
|
154
|
-
*/
|
|
155
|
-
export function makeParticleNoiseTexture(noise, size = 128) {
|
|
156
|
-
const sheetAt = particleNoise({ size, noise });
|
|
157
|
-
const sheet = new Uint8Array(size * size * 4);
|
|
158
|
-
const texel = [0, 0, 0, 0];
|
|
159
|
-
for (let y = 0; y < size; y++) {
|
|
160
|
-
for (let x = 0; x < size; x++) {
|
|
161
|
-
sheetAt((x + 0.5) / size, (size - 1 - y + 0.5) / size, texel);
|
|
162
|
-
sheet.set(texel, (y * size + x) * 4);
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
const texture = new THREE.DataTexture(sheet, size, size);
|
|
166
|
-
texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
|
|
167
|
-
texture.magFilter = THREE.LinearFilter;
|
|
168
|
-
texture.minFilter = THREE.LinearMipmapLinearFilter;
|
|
169
|
-
texture.generateMipmaps = true;
|
|
170
|
-
texture.needsUpdate = true;
|
|
171
|
-
return texture;
|
|
172
|
-
}
|