@threenative/terrain 0.1.9 → 0.1.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +40 -59
- package/THIRD_PARTY_NOTICES.md +2 -1
- package/dist/bake-DJ5cxg0C.d.ts +82 -0
- package/dist/editor/index.d.ts +4 -4
- package/dist/editor/index.js +130 -128
- package/dist/editor/server.d.ts +2 -2
- package/dist/editor/server.js +38 -35
- package/dist/editor/worker.d.ts +1 -1
- package/dist/editor/worker.js +101 -101
- package/dist/export.d.ts +1 -1
- package/dist/index.d.ts +156 -273
- package/dist/index.js +562 -378
- package/dist/kit-world.d.ts +107 -0
- package/dist/kit-world.js +5134 -0
- package/dist/kit.d.ts +21 -4
- package/dist/kit.js +337 -223
- package/dist/mcp/cook-child.js +1963 -1543
- package/dist/mcp/server.js +716 -429
- package/dist/prop-package-Dwz0EWoB.d.ts +141 -0
- package/dist/{server-B5RdvEAC.d.ts → server-LnFwY8sr.d.ts} +1 -1
- package/dist/starter.d.ts +1142 -7
- package/dist/starter.js +2102 -120
- package/dist/{terrain-CAEaW0mQ.d.ts → terrain-DYCyAOCJ.d.ts} +1 -1
- package/dist/three.d.ts +1 -1
- package/dist/three.js +1 -1
- package/dist/{types-BpH00qsx.d.ts → types-kpI0C4hW.d.ts} +1 -1
- package/dist/{world-package-B8QgHjAQ.d.ts → world-package-DqJC3-Nn.d.ts} +2 -2
- package/docs/authoring/editor.md +73 -0
- package/docs/authoring/new-environment.md +97 -0
- package/docs/authoring/recipes.md +97 -0
- package/docs/authoring/world-export.md +66 -0
- package/package.json +24 -8
- package/starter/alpine/README.md +22 -12
- package/starter/alpine/bake.mjs +14 -1
- package/starter/alpine/biome.data.json +187 -25
- package/starter/alpine/heightmap.r16 +0 -0
- package/starter/alpine/playerRig.ts +89 -0
- package/starter/alpine/recipe.json +169 -15
- package/starter/alpine/render/bakedFile.ts +17 -0
- package/starter/alpine/render/benchmark.ts +77 -0
- package/starter/alpine/render/biomeData.ts +14 -0
- package/starter/alpine/render/biomes.ts +687 -0
- package/starter/alpine/render/ground/cover.ts +565 -0
- package/starter/alpine/render/ground/horizon.ts +219 -0
- package/starter/alpine/render/ground/palette.d.ts +1 -0
- package/starter/alpine/render/ground/palette.js +11 -0
- package/starter/alpine/render/ground/scatter.ts +104 -0
- package/starter/alpine/render/ground/terrain.ts +1860 -0
- package/starter/alpine/render/kitAssets.ts +28 -0
- package/starter/alpine/render/loading.ts +354 -0
- package/starter/alpine/render/lookKnobs.ts +37 -0
- package/starter/alpine/render/orbitCamera.ts +155 -0
- package/starter/alpine/render/props/farForest.ts +94 -0
- package/starter/alpine/render/props/pack.ts +1114 -0
- package/starter/alpine/render/props/prepared.ts +225 -0
- package/starter/alpine/render/props/propMaterials.ts +1239 -0
- package/starter/alpine/render/props/propProgress.ts +2 -0
- package/starter/alpine/render/props/propWorld.ts +105 -0
- package/starter/alpine/render/props/props.ts +633 -0
- package/starter/alpine/render/props/spruce.ts +440 -0
- package/starter/alpine/render/sky/atmosphere.ts +329 -0
- package/starter/alpine/render/sky/sky.ts +382 -0
- package/starter/alpine/render/texturePreparation.ts +135 -0
- package/starter/alpine/render/water/river.ts +1132 -0
- package/starter/alpine/render/worldNames.ts +6 -0
- package/starter/alpine/scene.ts +715 -0
- package/starter/alpine/sceneProps.ts +561 -0
- package/starter/alpine/sceneState.ts +33 -0
- package/starter/alpine/world/terrainAssets.ts +145 -0
- package/starter/alpine/world/walkBand.ts +47 -0
- package/starter/alpine/world/water.ts +74 -0
- package/starter/alpine/worlds.ts +13 -0
- package/starter/arbor/wind.ts +84 -0
- package/starter/coastal/README.md +26 -25
- package/starter/coastal/assets.json +10 -0
- package/starter/coastal/bake.mjs +14 -1
- package/starter/coastal/biome.data.json +18 -3
- package/starter/coastal/playerRig.ts +89 -0
- package/starter/coastal/recipe.json +220 -18
- package/starter/coastal/render/bakedFile.ts +17 -0
- package/starter/coastal/render/benchmark.ts +81 -0
- package/starter/coastal/render/biomeData.ts +14 -0
- package/starter/coastal/render/biomes.ts +678 -0
- package/starter/coastal/render/ground/cover.ts +565 -0
- package/starter/coastal/render/ground/horizon.ts +219 -0
- package/starter/coastal/render/ground/palette.d.ts +1 -0
- package/starter/coastal/render/ground/palette.js +11 -0
- package/starter/coastal/render/ground/scatter.ts +104 -0
- package/starter/coastal/render/ground/terrain.ts +1829 -0
- package/starter/coastal/render/kitAssets.ts +28 -0
- package/starter/coastal/render/loading.ts +354 -0
- package/starter/coastal/render/lookKnobs.ts +37 -0
- package/starter/coastal/render/orbitCamera.ts +155 -0
- package/starter/coastal/render/props/farForest.ts +94 -0
- package/starter/coastal/render/props/pack.ts +1109 -0
- package/starter/coastal/render/props/prepared.ts +225 -0
- package/starter/coastal/render/props/propMaterials.ts +1239 -0
- package/starter/coastal/render/props/propProgress.ts +2 -0
- package/starter/coastal/render/props/propWorld.ts +105 -0
- package/starter/coastal/render/props/props.ts +633 -0
- package/starter/coastal/render/props/spruce.ts +440 -0
- package/starter/coastal/render/sky/atmosphere.ts +329 -0
- package/starter/coastal/render/sky/sky.ts +382 -0
- package/starter/coastal/render/texturePreparation.ts +135 -0
- package/starter/coastal/render/water/ocean.ts +284 -0
- package/starter/coastal/render/water/river.ts +1132 -0
- package/starter/coastal/render/worldNames.ts +6 -0
- package/starter/coastal/scene.ts +740 -0
- package/starter/coastal/sceneProps.ts +559 -0
- package/starter/coastal/sceneState.ts +33 -0
- package/starter/coastal/world/terrainAssets.ts +151 -0
- package/starter/coastal/world/walkBand.ts +47 -0
- package/starter/coastal/world/water.ts +74 -0
- package/starter/coastal/worlds.ts +13 -0
- package/starter/desert/README.md +51 -23
- package/starter/desert/bake-flora.mjs +142 -0
- package/starter/desert/bake-rocks.mjs +291 -0
- package/starter/desert/bake.mjs +14 -1
- package/starter/desert/biome.data.json +24 -12
- package/starter/desert/playerRig.ts +89 -0
- package/starter/desert/recipe.json +63 -16
- package/starter/desert/render/bakedFile.ts +17 -0
- package/starter/desert/render/benchmark.ts +79 -0
- package/starter/desert/render/biomeData.ts +14 -0
- package/starter/desert/render/biomes.ts +660 -0
- package/starter/desert/render/ground/cover.ts +565 -0
- package/starter/desert/render/ground/debris.ts +136 -0
- package/starter/desert/render/ground/horizon.ts +219 -0
- package/starter/desert/render/ground/palette.d.ts +1 -0
- package/starter/desert/render/ground/palette.js +11 -0
- package/starter/desert/render/ground/scatter.ts +104 -0
- package/starter/desert/render/ground/terrain.ts +1854 -0
- package/starter/desert/render/kitAssets.ts +28 -0
- package/starter/desert/render/loading.ts +354 -0
- package/starter/desert/render/lookKnobs.ts +37 -0
- package/starter/desert/render/orbitCamera.ts +155 -0
- package/starter/desert/render/props/farForest.ts +96 -0
- package/starter/desert/render/props/formations.ts +630 -0
- package/starter/desert/render/props/pack.ts +1195 -0
- package/starter/desert/render/props/prepared.ts +225 -0
- package/starter/desert/render/props/propMaterials.ts +1255 -0
- package/starter/desert/render/props/propProgress.ts +2 -0
- package/starter/desert/render/props/propWorld.ts +105 -0
- package/starter/desert/render/props/props.ts +624 -0
- package/starter/desert/render/props/spruce.ts +440 -0
- package/starter/desert/render/sand.ts +581 -0
- package/starter/desert/render/sky/atmosphere.ts +329 -0
- package/starter/desert/render/sky/sky.ts +382 -0
- package/starter/desert/render/texturePreparation.ts +135 -0
- package/starter/desert/render/water/river.ts +1132 -0
- package/starter/desert/render/worldNames.ts +6 -0
- package/starter/desert/scene.ts +748 -0
- package/starter/desert/sceneProps.ts +562 -0
- package/starter/desert/sceneState.ts +33 -0
- package/starter/desert/world/terrainAssets.ts +162 -0
- package/starter/desert/world/walkBand.ts +47 -0
- package/starter/desert/world/water.ts +74 -0
- package/starter/desert/worlds.ts +13 -0
- package/starter/forest/README.md +59 -116
- package/starter/forest/assets.json +14 -14
- package/starter/forest/bake.mjs +26 -4
- package/starter/forest/playerRig.ts +89 -0
- package/starter/forest/recipe.json +233 -43
- package/starter/forest/render/bakedFile.ts +17 -0
- package/starter/forest/render/benchmark.ts +77 -0
- package/starter/forest/render/biomeData.ts +14 -0
- package/starter/forest/render/biomes.ts +637 -0
- package/starter/forest/render/ground/cover.ts +565 -0
- package/starter/forest/render/ground/horizon.ts +219 -0
- package/starter/forest/render/ground/palette.d.ts +1 -0
- package/starter/forest/render/ground/palette.js +11 -0
- package/starter/forest/render/ground/scatter.ts +104 -0
- package/starter/forest/render/ground/terrain.ts +1796 -0
- package/starter/forest/render/kitAssets.ts +28 -0
- package/starter/forest/render/loading.ts +354 -0
- package/starter/forest/render/lookKnobs.ts +37 -0
- package/starter/forest/render/orbitCamera.ts +155 -0
- package/starter/forest/render/props/farForest.ts +94 -0
- package/starter/forest/render/props/pack.ts +1078 -0
- package/starter/forest/render/props/prepared.ts +226 -0
- package/starter/forest/render/props/propMaterials.ts +1247 -0
- package/starter/forest/render/props/propProgress.ts +2 -0
- package/starter/forest/render/props/propWorld.ts +105 -0
- package/starter/forest/render/props/props.ts +624 -0
- package/starter/forest/render/props/spruce.ts +440 -0
- package/starter/forest/render/sky/atmosphere.ts +329 -0
- package/starter/forest/render/sky/sky.ts +382 -0
- package/starter/forest/render/texturePreparation.ts +135 -0
- package/starter/forest/render/water/river.ts +1132 -0
- package/starter/forest/render/worldNames.ts +6 -0
- package/starter/forest/scene.ts +715 -0
- package/starter/forest/sceneProps.ts +559 -0
- package/starter/forest/sceneState.ts +33 -0
- package/starter/forest/surface.json +2 -2
- package/starter/forest/world/terrainAssets.ts +158 -0
- package/starter/forest/world/walkBand.ts +47 -0
- package/starter/forest/world/water.ts +74 -0
- package/starter/forest/worlds.ts +13 -0
- package/starter/tundra/README.md +35 -14
- package/starter/tundra/bake.mjs +14 -1
- package/starter/tundra/biome.data.json +6 -6
- package/starter/tundra/playerRig.ts +89 -0
- package/starter/tundra/recipe.json +111 -110
- package/starter/tundra/render/bakedFile.ts +17 -0
- package/starter/tundra/render/benchmark.ts +79 -0
- package/starter/tundra/render/biomeData.ts +14 -0
- package/starter/tundra/render/biomes.ts +714 -0
- package/starter/tundra/render/ground/cover.ts +565 -0
- package/starter/tundra/render/ground/horizon.ts +219 -0
- package/starter/tundra/render/ground/palette.d.ts +1 -0
- package/starter/tundra/render/ground/palette.js +11 -0
- package/starter/tundra/render/ground/scatter.ts +104 -0
- package/starter/tundra/render/ground/terrain.ts +1874 -0
- package/starter/tundra/render/kitAssets.ts +28 -0
- package/starter/tundra/render/loading.ts +354 -0
- package/starter/tundra/render/lookKnobs.ts +37 -0
- package/starter/tundra/render/orbitCamera.ts +155 -0
- package/starter/tundra/render/props/farForest.ts +96 -0
- package/starter/tundra/render/props/pack.ts +1088 -0
- package/starter/tundra/render/props/prepared.ts +225 -0
- package/starter/tundra/render/props/propMaterials.ts +1247 -0
- package/starter/tundra/render/props/propProgress.ts +2 -0
- package/starter/tundra/render/props/propWorld.ts +105 -0
- package/starter/tundra/render/props/props.ts +624 -0
- package/starter/tundra/render/props/spruce.ts +440 -0
- package/starter/tundra/render/sky/atmosphere.ts +329 -0
- package/starter/tundra/render/sky/sky.ts +382 -0
- package/starter/tundra/render/texturePreparation.ts +135 -0
- package/starter/tundra/render/water/river.ts +1132 -0
- package/starter/tundra/render/worldNames.ts +6 -0
- package/starter/tundra/scene.ts +715 -0
- package/starter/tundra/sceneProps.ts +559 -0
- package/starter/tundra/sceneState.ts +33 -0
- package/starter/tundra/world/terrainAssets.ts +159 -0
- package/starter/tundra/world/walkBand.ts +47 -0
- package/starter/tundra/world/water.ts +74 -0
- package/starter/tundra/worlds.ts +13 -0
- package/starter-assets.json +4 -4
- package/starter-credits.json +901 -15
- package/AGENT_GUIDE.md +0 -209
- package/starter/forest/sky.ts +0 -38
- package/starter/forest/water.ts +0 -257
- package/starter/forest/world.ts +0 -182
|
@@ -0,0 +1,565 @@
|
|
|
1
|
+
// Weathered boulders and the meadow's ground cover: grass clumps and poppy clusters.
|
|
2
|
+
//
|
|
3
|
+
// Rocks use smooth weathering, fracture planes and a flattened contact base.
|
|
4
|
+
//
|
|
5
|
+
// Grass is the other thing a cone cannot be. A blade is a tapered curved strip, dark at the root
|
|
6
|
+
// and light at the tip, and a clump is a handful of them at different angles — which is what makes
|
|
7
|
+
// a lawn read as depth rather than as a green plane with a texture on it.
|
|
8
|
+
import { createRandom } from "@threenative/core";
|
|
9
|
+
import { Box3, BufferAttribute, BufferGeometry, IcosahedronGeometry, Vector3 } from "three";
|
|
10
|
+
import { ImprovedNoise } from "three/addons/math/ImprovedNoise.js";
|
|
11
|
+
import { mergeVertices } from "three/addons/utils/BufferGeometryUtils.js";
|
|
12
|
+
|
|
13
|
+
/** How the boulders read, in metres. Sized against a spruce's 12-17 m, not in the abstract. */
|
|
14
|
+
export const ROCK = {
|
|
15
|
+
/** Radius at the widest point of the biggest variant. */
|
|
16
|
+
radius: 1.9,
|
|
17
|
+
/** Flattening: a boulder is wider than it is tall, because it fell over. */
|
|
18
|
+
flatten: 0.62,
|
|
19
|
+
/** How much of the base sits below the placement point, as a share of its height. */
|
|
20
|
+
buried: 0.34,
|
|
21
|
+
/** Weathering amplitude as a share of the radius. */
|
|
22
|
+
rough: 0.26,
|
|
23
|
+
/** Three.js subdivision detail: 20 * (detail + 1)^2 = 500 triangles. */
|
|
24
|
+
facets: 4,
|
|
25
|
+
} as const;
|
|
26
|
+
|
|
27
|
+
/** Smooth weathered stone with two softened fracture planes and a broad, flat contact base. */
|
|
28
|
+
export function boulder(seed: number): BufferGeometry {
|
|
29
|
+
const random = createRandom(seed);
|
|
30
|
+
const source = new IcosahedronGeometry(ROCK.radius, ROCK.facets);
|
|
31
|
+
// UV seams and the source's per-face normals must not keep identical positions apart.
|
|
32
|
+
source.deleteAttribute("uv");
|
|
33
|
+
source.deleteAttribute("normal");
|
|
34
|
+
const geometry = mergeVertices(source);
|
|
35
|
+
source.dispose();
|
|
36
|
+
const position = geometry.getAttribute("position") as BufferAttribute;
|
|
37
|
+
const noise = new ImprovedNoise();
|
|
38
|
+
const offset = new Vector3(random() * 100, random() * 100, random() * 100);
|
|
39
|
+
const stretch = new Vector3(
|
|
40
|
+
0.85 + random() * 0.3,
|
|
41
|
+
ROCK.flatten * (0.92 + random() * 0.16),
|
|
42
|
+
0.85 + random() * 0.3,
|
|
43
|
+
);
|
|
44
|
+
const cuts = Array.from({ length: 2 }, () => ({
|
|
45
|
+
normal: new Vector3(random() * 2 - 1, 0.25 + random() * 0.65, random() * 2 - 1).normalize(),
|
|
46
|
+
distance: ROCK.radius * (0.85 + random() * 0.12),
|
|
47
|
+
}));
|
|
48
|
+
const point = new Vector3();
|
|
49
|
+
const direction = new Vector3();
|
|
50
|
+
const base = -ROCK.radius * stretch.y * 0.88;
|
|
51
|
+
for (let i = 0; i < position.count; i += 1) {
|
|
52
|
+
direction.fromBufferAttribute(position, i).normalize();
|
|
53
|
+
let weathering = 0;
|
|
54
|
+
for (let octave = 0; octave < 3; octave += 1) {
|
|
55
|
+
const frequency = 1.8 * 2 ** octave;
|
|
56
|
+
weathering +=
|
|
57
|
+
noise.noise(
|
|
58
|
+
direction.x * frequency + offset.x,
|
|
59
|
+
direction.y * frequency + offset.y,
|
|
60
|
+
direction.z * frequency + offset.z,
|
|
61
|
+
) *
|
|
62
|
+
0.62 ** octave;
|
|
63
|
+
}
|
|
64
|
+
point.copy(direction).multiplyScalar(ROCK.radius * (1 + weathering * ROCK.rough));
|
|
65
|
+
for (const cut of cuts) {
|
|
66
|
+
const excess = point.dot(cut.normal) - cut.distance;
|
|
67
|
+
// A rounded clamp keeps a fracture from ending in a knife edge.
|
|
68
|
+
const bevel = ROCK.radius * 0.12;
|
|
69
|
+
const rounded = Math.max(0, 1 - Math.abs(excess) / bevel);
|
|
70
|
+
point.addScaledVector(
|
|
71
|
+
cut.normal,
|
|
72
|
+
-(Math.max(0, excess) + (bevel * rounded * rounded) / 4) * 0.4,
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
point.multiply(stretch);
|
|
76
|
+
point.y = Math.max(base, point.y);
|
|
77
|
+
position.setXYZ(i, point.x, point.y, point.z);
|
|
78
|
+
}
|
|
79
|
+
// Keep the committed seed's envelope: weathering must not thin the river cluster.
|
|
80
|
+
const reference = new IcosahedronGeometry(ROCK.radius, 3);
|
|
81
|
+
const vertices = reference.getAttribute("position");
|
|
82
|
+
const bounds = new Box3();
|
|
83
|
+
const phase = offset.clone().multiplyScalar((Math.PI * 2) / 100);
|
|
84
|
+
for (let i = 0; i < vertices.count; i++) {
|
|
85
|
+
direction.fromBufferAttribute(vertices, i).normalize();
|
|
86
|
+
const swell = Math.sin(direction.x * 3 + phase.x) * 0.55;
|
|
87
|
+
const facet = Math.sin(direction.y * 3 * 2.3 + phase.y) * 0.3;
|
|
88
|
+
const chip = Math.sin(direction.z * 3 * 5.1 + phase.z) * 0.15;
|
|
89
|
+
point.copy(direction).multiplyScalar(ROCK.radius * (1 + (swell + facet + chip) * ROCK.rough));
|
|
90
|
+
point.y *= ROCK.flatten * (point.y > 0 ? 0.86 : 1);
|
|
91
|
+
bounds.expandByPoint(point);
|
|
92
|
+
}
|
|
93
|
+
reference.dispose();
|
|
94
|
+
geometry.computeBoundingBox();
|
|
95
|
+
const size = geometry.boundingBox?.getSize(new Vector3());
|
|
96
|
+
if (!size) throw new Error("Rock has no measured bounds");
|
|
97
|
+
const scale = bounds.getSize(point).divide(size);
|
|
98
|
+
geometry.scale(scale.x, scale.y, scale.z);
|
|
99
|
+
geometry.computeVertexNormals();
|
|
100
|
+
geometry.translate(0, -ROCK.radius * ROCK.flatten * ROCK.buried, 0);
|
|
101
|
+
geometry.computeBoundingBox();
|
|
102
|
+
geometry.computeBoundingSphere();
|
|
103
|
+
return geometry;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** Knee-high meadow grass: fourteen slender curved blades per clump. */
|
|
107
|
+
export const GRASS = {
|
|
108
|
+
blades: 14,
|
|
109
|
+
/** Height range of a clump, in metres. */
|
|
110
|
+
height: [0.5, 0.95],
|
|
111
|
+
/** Blade width range, in metres, capped against each blade's own height below. */
|
|
112
|
+
width: [0.006, 0.012],
|
|
113
|
+
/** How far a blade leans from vertical at its tip, as a share of its length. */
|
|
114
|
+
bend: 0.72,
|
|
115
|
+
/** Wind sway at the tip, in metres. */
|
|
116
|
+
sway: 0.09,
|
|
117
|
+
/**
|
|
118
|
+
* How dark the base of a blade is, as a share of its own colour. A clump's bottom is in its own
|
|
119
|
+
* shade; without this every blade starts as bright as its tip and the meadow has no floor.
|
|
120
|
+
*/
|
|
121
|
+
rootAo: 0.42,
|
|
122
|
+
} as const;
|
|
123
|
+
|
|
124
|
+
/** Positions, normals, UVs, vertex colours and the wind envelope, accumulated into one buffer. */
|
|
125
|
+
class CoverBuffer {
|
|
126
|
+
readonly color: number[] = [];
|
|
127
|
+
readonly index: number[] = [];
|
|
128
|
+
readonly normal: number[] = [];
|
|
129
|
+
readonly position: number[] = [];
|
|
130
|
+
readonly sway: number[] = [];
|
|
131
|
+
readonly uv: number[] = [];
|
|
132
|
+
|
|
133
|
+
vertex(
|
|
134
|
+
point: Vector3,
|
|
135
|
+
normal: Vector3,
|
|
136
|
+
color: Vector3,
|
|
137
|
+
weight: number,
|
|
138
|
+
at: readonly [number, number] = [0, 0],
|
|
139
|
+
): number {
|
|
140
|
+
this.position.push(point.x, point.y, point.z);
|
|
141
|
+
this.normal.push(normal.x, normal.y, normal.z);
|
|
142
|
+
this.color.push(color.x, color.y, color.z);
|
|
143
|
+
this.uv.push(at[0], at[1]);
|
|
144
|
+
this.sway.push(weight);
|
|
145
|
+
return this.sway.length - 1;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* One quad, with its own texture coordinates.
|
|
150
|
+
*
|
|
151
|
+
* The corners are pushed in the order (left-near, right-near, right-far, left-far), so a card that
|
|
152
|
+
* wants a texture gives the matching UVs in that order: a petal's U runs across its width and its V
|
|
153
|
+
* from its base to its tip.
|
|
154
|
+
*/
|
|
155
|
+
quad(
|
|
156
|
+
corners: readonly Vector3[],
|
|
157
|
+
normal: Vector3,
|
|
158
|
+
colors: readonly Vector3[],
|
|
159
|
+
weight: number | readonly [number, number, number, number],
|
|
160
|
+
uvs?: readonly (readonly [number, number])[],
|
|
161
|
+
): void {
|
|
162
|
+
const base = this.sway.length;
|
|
163
|
+
corners.forEach((point, i) =>
|
|
164
|
+
this.vertex(
|
|
165
|
+
point,
|
|
166
|
+
normal,
|
|
167
|
+
colors[i] as Vector3,
|
|
168
|
+
typeof weight === "number" ? weight : (weight[i] as number),
|
|
169
|
+
uvs?.[i],
|
|
170
|
+
),
|
|
171
|
+
);
|
|
172
|
+
this.index.push(base, base + 1, base + 2, base, base + 2, base + 3);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
build(): BufferGeometry {
|
|
176
|
+
const geometry = new BufferGeometry();
|
|
177
|
+
geometry.setAttribute("position", new BufferAttribute(new Float32Array(this.position), 3));
|
|
178
|
+
geometry.setAttribute("normal", new BufferAttribute(new Float32Array(this.normal), 3));
|
|
179
|
+
geometry.setAttribute("color", new BufferAttribute(new Float32Array(this.color), 3));
|
|
180
|
+
geometry.setAttribute("uv", new BufferAttribute(new Float32Array(this.uv), 2));
|
|
181
|
+
geometry.setAttribute("sway", new BufferAttribute(new Float32Array(this.sway), 1));
|
|
182
|
+
geometry.setIndex(this.index);
|
|
183
|
+
geometry.computeBoundingSphere();
|
|
184
|
+
return geometry;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* The four meadow greens a clump is drawn from, root to tip.
|
|
190
|
+
*
|
|
191
|
+
* A meadow is not one green and it is not two. Four here — a deep olive, the meadow's own green, a
|
|
192
|
+
* sun-bleached yellow and a dry straw — because the judges' complaint about the grass was that it
|
|
193
|
+
* read as a uniform sparse lattice, and a lattice is a *distribution* problem: a hundred identical
|
|
194
|
+
* green clumps at even spacing are a grid no matter how good the blade is. Mixing the hues and the
|
|
195
|
+
* heights is what breaks the grid, and it costs one table.
|
|
196
|
+
*
|
|
197
|
+
* Linear, not sRGB, for the same reason the two above are: a vertex colour is used as written.
|
|
198
|
+
*/
|
|
199
|
+
const MEADOW_GREENS = [
|
|
200
|
+
{ name: "olive", root: [0.09, 0.16, 0.06], tip: [0.16, 0.27, 0.06] },
|
|
201
|
+
{ name: "meadow", root: [0.1, 0.19, 0.07], tip: [0.18, 0.34, 0.06] },
|
|
202
|
+
{ name: "bleached", root: [0.14, 0.19, 0.06], tip: [0.34, 0.38, 0.1] },
|
|
203
|
+
{ name: "straw", root: [0.16, 0.17, 0.07], tip: [0.4, 0.36, 0.14] },
|
|
204
|
+
] as const;
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* One seeded grass clump: `GRASS.blades` tapered strips, each bent over in its own direction.
|
|
208
|
+
*
|
|
209
|
+
* A blade is three quads narrowing to a point, curving as it rises, with its colour graded root to
|
|
210
|
+
* tip. The bend is per blade and the direction is per blade, which is the entire difference between
|
|
211
|
+
* "grass" and "several identical green triangles".
|
|
212
|
+
*/
|
|
213
|
+
export function grassClump(seed: number, species = 0): BufferGeometry {
|
|
214
|
+
const random = createRandom(seed);
|
|
215
|
+
const buffer = new CoverBuffer();
|
|
216
|
+
const segments = 3;
|
|
217
|
+
// Meadow grass, fine arching fescue and upright sedge share one opaque material.
|
|
218
|
+
const habits = [
|
|
219
|
+
{ height: 1, width: 1, bend: 1, spread: 0.075 },
|
|
220
|
+
{ height: 0.85, width: 0.7, bend: 1.35, spread: 0.11 },
|
|
221
|
+
{ height: 0.95, width: 1.1, bend: 0.8, spread: 0.055 },
|
|
222
|
+
] as const;
|
|
223
|
+
const habit = habits[species % habits.length] ?? habits[0];
|
|
224
|
+
// Root occlusion: the bottom of a clump sits in its own shade, and a blade that starts at the same
|
|
225
|
+
// brightness as its tip looks pasted onto the ground. The fade runs over the first third of the
|
|
226
|
+
// blade, which is about as far down as the neighbours of a clump reach.
|
|
227
|
+
const rootAo = (at: number) => GRASS.rootAo + (1 - GRASS.rootAo) * Math.min(1, at / 0.34);
|
|
228
|
+
// This clump's own green: one of four, picked by seed, and every blade in it grades between that
|
|
229
|
+
// one's root and tip. A stand of clumps then has weather, age and dry patches in it, which is what
|
|
230
|
+
// a meadow has and a lattice does not.
|
|
231
|
+
const green = MEADOW_GREENS[
|
|
232
|
+
Math.floor(random() * MEADOW_GREENS.length)
|
|
233
|
+
] as (typeof MEADOW_GREENS)[number];
|
|
234
|
+
const shift = 0.86 + random() * 0.28;
|
|
235
|
+
const root = new Vector3(...green.root).multiplyScalar(shift);
|
|
236
|
+
const tip = new Vector3(...green.tip).multiplyScalar(shift);
|
|
237
|
+
// The clump's own height, as a share of the range: a meadow has knee-high grass and ankle-high
|
|
238
|
+
// grass in the same metre, and a clump that is always `GRASS.height`'s midpoint is the other half
|
|
239
|
+
// of the lattice.
|
|
240
|
+
const clumpHeight = 0.62 + random() * 0.62;
|
|
241
|
+
const phase = random() * Math.PI * 2;
|
|
242
|
+
for (let blade = 0; blade < GRASS.blades; blade += 1) {
|
|
243
|
+
const azimuth = phase + blade * 2.399963229728653 + (random() - 0.5) * 0.6;
|
|
244
|
+
// Per blade, not per clump: a clump whose blades are all one height is a fan, and the outer
|
|
245
|
+
// blades of a real clump are the ones that have fallen over.
|
|
246
|
+
const height =
|
|
247
|
+
(GRASS.height[0] + random() * (GRASS.height[1] - GRASS.height[0])) *
|
|
248
|
+
clumpHeight *
|
|
249
|
+
habit.height;
|
|
250
|
+
const bend = GRASS.bend * (0.35 + random() * 1.1) * habit.bend;
|
|
251
|
+
// Blades lean outward from the clump's own centre, so the clump is round, not a flat fan.
|
|
252
|
+
const outward = new Vector3(Math.cos(azimuth), 0, Math.sin(azimuth));
|
|
253
|
+
const width = Math.min(
|
|
254
|
+
(GRASS.width[0] + random() * (GRASS.width[1] - GRASS.width[0])) * habit.width,
|
|
255
|
+
height * 0.022,
|
|
256
|
+
);
|
|
257
|
+
const side = new Vector3(-Math.sin(azimuth), 0, Math.cos(azimuth));
|
|
258
|
+
const basal = habit.spread * Math.sqrt(random());
|
|
259
|
+
// The blade's spine at `at`: rising, and leaning over further the higher it goes.
|
|
260
|
+
const spine = (at: number) =>
|
|
261
|
+
new Vector3(
|
|
262
|
+
outward.x * (basal + height * bend * (0.2 * at + 0.8 * at * at)),
|
|
263
|
+
height * (at - 0.3 * at ** 3),
|
|
264
|
+
outward.z * (basal + height * bend * (0.2 * at + 0.8 * at * at)),
|
|
265
|
+
);
|
|
266
|
+
for (let i = 0; i < segments; i += 1) {
|
|
267
|
+
const at0 = i / segments;
|
|
268
|
+
const at1 = (i + 1) / segments;
|
|
269
|
+
const half0 = (width * (0.02 + 0.98 * (1 - at0) ** 1.3)) / 2;
|
|
270
|
+
const half1 = (width * (0.02 + 0.98 * (1 - at1) ** 1.3)) / 2;
|
|
271
|
+
const a = spine(at0).addScaledVector(side, -half0);
|
|
272
|
+
const b = spine(at0).addScaledVector(side, half0);
|
|
273
|
+
const c = spine(at1).addScaledVector(side, half1);
|
|
274
|
+
const d = spine(at1).addScaledVector(side, -half1);
|
|
275
|
+
// Face the blade's own normal outward and slightly up, so a clump lit from one side shades
|
|
276
|
+
// like a mass of blades rather than like a fan of paper.
|
|
277
|
+
const normal = outward
|
|
278
|
+
.clone()
|
|
279
|
+
.multiplyScalar(0.55)
|
|
280
|
+
.add(new Vector3(0, 1, 0).multiplyScalar(0.45))
|
|
281
|
+
.normalize();
|
|
282
|
+
buffer.quad(
|
|
283
|
+
[a, b, c, d],
|
|
284
|
+
normal,
|
|
285
|
+
[
|
|
286
|
+
root.clone().lerp(tip, at0).multiplyScalar(rootAo(at0)),
|
|
287
|
+
root.clone().lerp(tip, at0).multiplyScalar(rootAo(at0)),
|
|
288
|
+
root.clone().lerp(tip, at1).multiplyScalar(rootAo(at1)),
|
|
289
|
+
root.clone().lerp(tip, at1).multiplyScalar(rootAo(at1)),
|
|
290
|
+
],
|
|
291
|
+
[at0 * at0, at0 * at0, at1 * at1, at1 * at1],
|
|
292
|
+
);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
return buffer.build();
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* The fronds of Poly Haven's `fern_02` atlas, as `[u0, v0, u1, v1]` with the stalk at `v0`.
|
|
300
|
+
*
|
|
301
|
+
* Measured, not guessed: each rect is the bounding box of one connected frond in the 512 px alpha,
|
|
302
|
+
* so a card that samples one draws one whole frond and none of its neighbours.
|
|
303
|
+
*/
|
|
304
|
+
const FROND_RECTS = [
|
|
305
|
+
[0.082, 0.045, 0.293, 0.895],
|
|
306
|
+
[0.277, 0.23, 0.494, 0.982],
|
|
307
|
+
[0.502, 0.494, 0.691, 0.98],
|
|
308
|
+
[0.7, 0.05, 0.844, 0.898],
|
|
309
|
+
] as const;
|
|
310
|
+
|
|
311
|
+
/** How a fern clump reads, in metres. Bracken-sized: knee to thigh high, a metre and a half across. */
|
|
312
|
+
export const FERN = {
|
|
313
|
+
fronds: [7, 10] as const,
|
|
314
|
+
length: [0.55, 1.0] as const,
|
|
315
|
+
/** Frond width as a share of its length — the atlas fronds are about a quarter as wide as long. */
|
|
316
|
+
width: 0.3,
|
|
317
|
+
/** Vertical rise of the arch at its peak, as a share of the frond's length. */
|
|
318
|
+
rise: 0.55,
|
|
319
|
+
} as const;
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* One seeded fern: fronds rising out of a crown and arching over, each one card cut to one real frond.
|
|
323
|
+
*
|
|
324
|
+
* A frond leaves the crown steeply and droops as it reaches out, so its spine climbs then falls; the
|
|
325
|
+
* card lies across that spine, flat to the sky, which is how a fern presents its leaflets to the
|
|
326
|
+
* light. Seven to ten fronds at uneven angles is what reads as a clump rather than a rosette.
|
|
327
|
+
*/
|
|
328
|
+
export function fernClump(seed: number): BufferGeometry {
|
|
329
|
+
const random = createRandom(seed);
|
|
330
|
+
const buffer = new CoverBuffer();
|
|
331
|
+
const segments = 4;
|
|
332
|
+
const fronds = FERN.fronds[0] + Math.floor(random() * (FERN.fronds[1] - FERN.fronds[0] + 1));
|
|
333
|
+
const phase = random() * Math.PI * 2;
|
|
334
|
+
const white = new Vector3(1, 1, 1);
|
|
335
|
+
for (let f = 0; f < fronds; f += 1) {
|
|
336
|
+
const azimuth = phase + f * 2.399963229728653 + (random() - 0.5) * 0.35;
|
|
337
|
+
const length = FERN.length[0] + random() * (FERN.length[1] - FERN.length[0]);
|
|
338
|
+
const width = length * FERN.width * (0.8 + random() * 0.4);
|
|
339
|
+
const young = f / (fronds - 1);
|
|
340
|
+
const rise = FERN.rise * (0.7 + random() * 0.4 + young * 0.65);
|
|
341
|
+
const outward = new Vector3(Math.cos(azimuth), 0, Math.sin(azimuth));
|
|
342
|
+
const side = new Vector3(-Math.sin(azimuth), 0, Math.cos(azimuth));
|
|
343
|
+
const rect = FROND_RECTS[Math.floor(random() * FROND_RECTS.length)] as readonly number[];
|
|
344
|
+
const [u0, v0, u1, v1] = rect as [number, number, number, number];
|
|
345
|
+
// Up, then over: the spine's height is a parabola that peaks two thirds of the way out.
|
|
346
|
+
const spine = (at: number) =>
|
|
347
|
+
outward
|
|
348
|
+
.clone()
|
|
349
|
+
.multiplyScalar(length * (1 - young * 0.35) * (0.25 + 0.75 * at) * at)
|
|
350
|
+
.setY(length * rise * (2.2 * at - 1.6 * at * at));
|
|
351
|
+
// A frond's own twist: the outer half rolls a little, so the clump is not a set of flat paddles.
|
|
352
|
+
const roll = (random() - 0.5) * 0.6;
|
|
353
|
+
for (let i = 0; i < segments; i += 1) {
|
|
354
|
+
const at0 = i / segments;
|
|
355
|
+
const at1 = (i + 1) / segments;
|
|
356
|
+
const across0 = side.clone().applyAxisAngle(outward, roll * at0);
|
|
357
|
+
const across1 = side.clone().applyAxisAngle(outward, roll * at1);
|
|
358
|
+
// Narrow at the stalk, full in the middle, pointed at the tip — the atlas frond's own outline
|
|
359
|
+
// does the rest, so the card only has to not crop it.
|
|
360
|
+
const half = (at: number) => (width / 2) * Math.min(1, 0.35 + at * 1.6);
|
|
361
|
+
const a = spine(at0).addScaledVector(across0, -half(at0));
|
|
362
|
+
const b = spine(at0).addScaledVector(across0, half(at0));
|
|
363
|
+
const c = spine(at1).addScaledVector(across1, half(at1));
|
|
364
|
+
const d = spine(at1).addScaledVector(across1, -half(at1));
|
|
365
|
+
const normal = new Vector3()
|
|
366
|
+
.subVectors(b, a)
|
|
367
|
+
.cross(new Vector3().subVectors(d, a))
|
|
368
|
+
.normalize();
|
|
369
|
+
if (normal.y < 0) normal.negate();
|
|
370
|
+
const shade = (at: number) =>
|
|
371
|
+
white.clone().multiplyScalar(0.55 + 0.45 * Math.min(1, at / 0.4));
|
|
372
|
+
const va = v0 + (v1 - v0) * at0;
|
|
373
|
+
const vb = v0 + (v1 - v0) * at1;
|
|
374
|
+
buffer.quad(
|
|
375
|
+
[a, b, c, d],
|
|
376
|
+
normal,
|
|
377
|
+
[shade(at0), shade(at0), shade(at1), shade(at1)],
|
|
378
|
+
[at0 * at0, at0 * at0, at1 * at1, at1 * at1],
|
|
379
|
+
[
|
|
380
|
+
[u0, va],
|
|
381
|
+
[u1, va],
|
|
382
|
+
[u1, vb],
|
|
383
|
+
[u0, vb],
|
|
384
|
+
],
|
|
385
|
+
);
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
return buffer.build();
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
/** How a poppy cluster reads, in metres. */
|
|
392
|
+
export const POPPY = {
|
|
393
|
+
/** Stems per cluster. A patch is a colony, not a bouquet. */
|
|
394
|
+
stems: 5,
|
|
395
|
+
/**
|
|
396
|
+
* Stem height range, in metres. Taller than the grass on purpose: a poppy holds its head above the
|
|
397
|
+
* blades it grows through, and a flower at forty centimetres in grass that reaches a metre is a
|
|
398
|
+
* red disc buried in a green carpet.
|
|
399
|
+
*/
|
|
400
|
+
height: [0.62, 0.9],
|
|
401
|
+
/**
|
|
402
|
+
* Petals per head and the radius of the disc they make, in metres. Nine centimetres is a poppy at
|
|
403
|
+
* its widest, and the size decides whether a patch reads as flowers or as red dust: at half this
|
|
404
|
+
* the disc is two pixels wide at thirty metres, and a meadow of poppies is a meadow of specks.
|
|
405
|
+
*/
|
|
406
|
+
disc: 0.09,
|
|
407
|
+
petals: 5,
|
|
408
|
+
/**
|
|
409
|
+
* How far the petal tips lift out of the head's own plane, as a share of the disc radius, and how
|
|
410
|
+
* many segments the cup is built from.
|
|
411
|
+
*
|
|
412
|
+
* This is the difference between a flower and a red starfish. A poppy's petals are cupped: they
|
|
413
|
+
* rise from the centre and their outer third rolls outward and down, so the head is a shallow bowl
|
|
414
|
+
* seen from above and a shallow dome seen from the side. Flat petals are a disc, and a meadow of
|
|
415
|
+
* discs is what the judges called "flat red quads".
|
|
416
|
+
*/
|
|
417
|
+
cup: 0.42,
|
|
418
|
+
cupSegments: 3,
|
|
419
|
+
/** The dark disc at the centre of the head, as a share of the petal radius. */
|
|
420
|
+
centre: 0.34,
|
|
421
|
+
} as const;
|
|
422
|
+
|
|
423
|
+
/**
|
|
424
|
+
* The meadow's flowers where no imported flower draws, poppy and bloom alike. The game places them
|
|
425
|
+
* as densely as the Fab meadow's single flowers, so a five-stem colony with nine-centimetre heads
|
|
426
|
+
* per placement made a salmon carpet with 27 times the Fab meadow's flower coverage (PRD-870 judge,
|
|
427
|
+
* 2026-11-10): one low stem with a six-centimetre head per placement sits in the grass instead.
|
|
428
|
+
*/
|
|
429
|
+
export const WILDFLOWER = { stems: 1, height: [0.4, 0.58], disc: 0.06 } as const;
|
|
430
|
+
|
|
431
|
+
/**
|
|
432
|
+
* One seeded poppy cluster, as two buffers.
|
|
433
|
+
*
|
|
434
|
+
* Stems and petals are separate because they are separate materials — the petals are alpha-cutout
|
|
435
|
+
* cards sampling the atlas, the stems are opaque graded geometry — and one buffer can only carry one
|
|
436
|
+
* material's worth of channels. It costs one extra draw call for a patch of red in a meadow.
|
|
437
|
+
*
|
|
438
|
+
* Each head carries two crossed petal quads rather than one flat billboard: a poppy seen edge-on is
|
|
439
|
+
* a line, and a meadow full of red lines is not a meadow of poppies.
|
|
440
|
+
*/
|
|
441
|
+
export function poppyCluster(
|
|
442
|
+
seed: number,
|
|
443
|
+
/** The atlas cell one petal samples. */
|
|
444
|
+
cell: { u0: number; u1: number; v0: number; v1: number },
|
|
445
|
+
/** The colony's own size; the meadow's small wildflowers (`WILDFLOWER`) override the poppy's. */
|
|
446
|
+
shape: {
|
|
447
|
+
readonly stems: number;
|
|
448
|
+
readonly height: readonly [number, number];
|
|
449
|
+
readonly disc: number;
|
|
450
|
+
} = POPPY,
|
|
451
|
+
): { petals: BufferGeometry; stems: BufferGeometry } {
|
|
452
|
+
const petal = cell;
|
|
453
|
+
const random = createRandom(seed);
|
|
454
|
+
const stems = new CoverBuffer();
|
|
455
|
+
const heads = new CoverBuffer();
|
|
456
|
+
const stemGreen = new Vector3(0.16, 0.26, 0.1);
|
|
457
|
+
const stemLight = new Vector3(0.34, 0.44, 0.18);
|
|
458
|
+
const white = new Vector3(1, 1, 1);
|
|
459
|
+
const segments = 3;
|
|
460
|
+
for (let s = 0; s < shape.stems; s += 1) {
|
|
461
|
+
const azimuth = random() * Math.PI * 2;
|
|
462
|
+
const away = 0.02 + random() * 0.11;
|
|
463
|
+
const height = shape.height[0] + random() * (shape.height[1] - shape.height[0]);
|
|
464
|
+
const root = new Vector3(Math.cos(azimuth) * away * 0.4, 0, Math.sin(azimuth) * away * 0.4);
|
|
465
|
+
// The head leans out over the stem, further for the taller stems.
|
|
466
|
+
const lean = new Vector3(Math.cos(azimuth), 0, Math.sin(azimuth)).multiplyScalar(height * 0.22);
|
|
467
|
+
const spine = (at: number) =>
|
|
468
|
+
root
|
|
469
|
+
.clone()
|
|
470
|
+
.addScaledVector(lean, at * at)
|
|
471
|
+
.add(new Vector3(0, height * at, 0));
|
|
472
|
+
const halfWidth = (at: number) => 0.006 * (1 - at * 0.5);
|
|
473
|
+
for (let i = 0; i < segments; i += 1) {
|
|
474
|
+
const at0 = i / segments;
|
|
475
|
+
const at1 = (i + 1) / segments;
|
|
476
|
+
const a = spine(at0).add(new Vector3(-halfWidth(at0), 0, 0));
|
|
477
|
+
const b = spine(at0).add(new Vector3(halfWidth(at0), 0, 0));
|
|
478
|
+
const c = spine(at1).add(new Vector3(halfWidth(at1), 0, 0));
|
|
479
|
+
const d = spine(at1).add(new Vector3(-halfWidth(at1), 0, 0));
|
|
480
|
+
stems.quad(
|
|
481
|
+
[a, b, c, d],
|
|
482
|
+
new Vector3(0, 0, 1),
|
|
483
|
+
[
|
|
484
|
+
stemGreen.clone().lerp(stemLight, at0),
|
|
485
|
+
stemGreen.clone().lerp(stemLight, at0),
|
|
486
|
+
stemGreen.clone().lerp(stemLight, at1),
|
|
487
|
+
stemGreen.clone().lerp(stemLight, at1),
|
|
488
|
+
],
|
|
489
|
+
[at0 * at0 * 0.8, at0 * at0 * 0.8, at1 * at1 * 0.8, at1 * at1 * 0.8],
|
|
490
|
+
);
|
|
491
|
+
}
|
|
492
|
+
// Five cupped petals, each a small strip of quads rather than one flat quad. A poppy is a bowl:
|
|
493
|
+
// the petals rise from the dark centre and their outer third rolls outward and down, so the head
|
|
494
|
+
// reads as a flower from above *and* from the side. A flat quad reads as a red card from above
|
|
495
|
+
// and as a line from anywhere else, which is what the last captures showed.
|
|
496
|
+
const head = spine(1);
|
|
497
|
+
const twist = random() * Math.PI * 2;
|
|
498
|
+
const radius = shape.disc * (0.8 + random() * 0.4);
|
|
499
|
+
// The dark centre every poppy has: the ring of stamens around the ovary, which is nearly black
|
|
500
|
+
// and which is the single detail that makes a red disc read as a flower.
|
|
501
|
+
const centreR = radius * POPPY.centre;
|
|
502
|
+
const dark = new Vector3(0.09, 0.05, 0.05);
|
|
503
|
+
for (let i = 0; i < 6; i += 1) {
|
|
504
|
+
const a0 = (i / 6) * Math.PI * 2;
|
|
505
|
+
const a1 = ((i + 1) / 6) * Math.PI * 2;
|
|
506
|
+
heads.quad(
|
|
507
|
+
[
|
|
508
|
+
head.clone(),
|
|
509
|
+
head.clone().add(new Vector3(Math.cos(a0) * centreR, 0, Math.sin(a0) * centreR)),
|
|
510
|
+
head.clone().add(new Vector3(Math.cos(a1) * centreR, 0, Math.sin(a1) * centreR)),
|
|
511
|
+
head.clone().add(new Vector3(Math.cos(a1) * centreR, 0, Math.sin(a1) * centreR)),
|
|
512
|
+
],
|
|
513
|
+
new Vector3(0, 1, 0),
|
|
514
|
+
[dark, dark, dark, dark],
|
|
515
|
+
0.8,
|
|
516
|
+
);
|
|
517
|
+
}
|
|
518
|
+
for (let lobe = 0; lobe < POPPY.petals; lobe += 1) {
|
|
519
|
+
const angle = twist + (lobe / POPPY.petals) * Math.PI * 2 + (random() - 0.5) * 0.3;
|
|
520
|
+
const along = new Vector3(Math.cos(angle), 0, Math.sin(angle));
|
|
521
|
+
const across = new Vector3(-Math.sin(angle), 0, Math.cos(angle));
|
|
522
|
+
// Each petal's own width and cup, so no two heads in a patch are the same flower.
|
|
523
|
+
const petalLength = radius * (0.82 + random() * 0.36);
|
|
524
|
+
const petalWidth = petalLength * (0.62 + random() * 0.3);
|
|
525
|
+
const cup = POPPY.cup * (0.7 + random() * 0.6);
|
|
526
|
+
// The cup's profile as a fraction of its length: rising from the centre, peaking where the
|
|
527
|
+
// petals leave the ovary, then rolling down over the outer third.
|
|
528
|
+
const lift = (at: number) =>
|
|
529
|
+
cup * radius * (Math.sin(at * Math.PI * 0.85) * 1.1 - at * at * 0.85);
|
|
530
|
+
const segments = POPPY.cupSegments;
|
|
531
|
+
for (let i = 0; i < segments; i += 1) {
|
|
532
|
+
const at0 = i / segments;
|
|
533
|
+
const at1 = (i + 1) / segments;
|
|
534
|
+
// The petal narrows to a rounded tip rather than coming to a point: at `at` the half-width is
|
|
535
|
+
// the profile of the petal, sampled along its length.
|
|
536
|
+
const half = (at: number) => (petalWidth * Math.sin(Math.PI * at ** 0.62)) / 2;
|
|
537
|
+
const p = (at: number, side: number) =>
|
|
538
|
+
head
|
|
539
|
+
.clone()
|
|
540
|
+
.addScaledVector(along, petalLength * at)
|
|
541
|
+
.addScaledVector(across, half(at) * side)
|
|
542
|
+
.add(new Vector3(0, lift(at), 0));
|
|
543
|
+
// The normal follows the cup: it tips with the local slope of the petal, so the lit side of
|
|
544
|
+
// the bowl is brighter than the rim and the head has a direction.
|
|
545
|
+
const slope = (lift(at1) - lift(at0)) / (petalLength * (at1 - at0) + 1e-6);
|
|
546
|
+
const normal = new Vector3(-along.x * slope, 1, -along.z * slope).normalize();
|
|
547
|
+
const v0 = petal.v0 + (petal.v1 - petal.v0) * at0;
|
|
548
|
+
const v1 = petal.v0 + (petal.v1 - petal.v0) * at1;
|
|
549
|
+
heads.quad(
|
|
550
|
+
[p(at0, -1), p(at0, 1), p(at1, 1), p(at1, -1)],
|
|
551
|
+
normal,
|
|
552
|
+
[white, white, white, white],
|
|
553
|
+
0.8,
|
|
554
|
+
[
|
|
555
|
+
[petal.u0, v0],
|
|
556
|
+
[petal.u1, v0],
|
|
557
|
+
[petal.u1, v1],
|
|
558
|
+
[petal.u0, v1],
|
|
559
|
+
],
|
|
560
|
+
);
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
return { petals: heads.build(), stems: stems.build() };
|
|
565
|
+
}
|