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.
@@ -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
- }