webgpu-grass 0.0.0-stage → 0.1.1
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/LICENSE +21 -0
- package/README.md +645 -2
- package/lib/distance.d.ts +63 -0
- package/lib/distance.d.ts.map +1 -0
- package/lib/distance.js +148 -0
- package/lib/distance.js.map +1 -0
- package/lib/engine.d.ts +402 -0
- package/lib/engine.d.ts.map +1 -0
- package/lib/engine.js +3253 -0
- package/lib/engine.js.map +1 -0
- package/lib/field.d.ts +133 -0
- package/lib/field.d.ts.map +1 -0
- package/lib/field.js +244 -0
- package/lib/field.js.map +1 -0
- package/lib/flowers.d.ts +138 -0
- package/lib/flowers.d.ts.map +1 -0
- package/lib/flowers.js +117 -0
- package/lib/flowers.js.map +1 -0
- package/lib/index.d.ts +11 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +14 -0
- package/lib/index.js.map +1 -0
- package/lib/mix.d.ts +17 -0
- package/lib/mix.d.ts.map +1 -0
- package/lib/mix.js +95 -0
- package/lib/mix.js.map +1 -0
- package/lib/mixshare.d.ts +42 -0
- package/lib/mixshare.d.ts.map +1 -0
- package/lib/mixshare.js +144 -0
- package/lib/mixshare.js.map +1 -0
- package/lib/noise.d.ts +4 -0
- package/lib/noise.d.ts.map +1 -0
- package/lib/noise.js +49 -0
- package/lib/noise.js.map +1 -0
- package/lib/placement.d.ts +39 -0
- package/lib/placement.d.ts.map +1 -0
- package/lib/placement.js +67 -0
- package/lib/placement.js.map +1 -0
- package/lib/rank.d.ts +36 -0
- package/lib/rank.d.ts.map +1 -0
- package/lib/rank.js +158 -0
- package/lib/rank.js.map +1 -0
- package/lib/species.d.ts +408 -0
- package/lib/species.d.ts.map +1 -0
- package/lib/species.js +672 -0
- package/lib/species.js.map +1 -0
- package/lib/transitions.d.ts +72 -0
- package/lib/transitions.d.ts.map +1 -0
- package/lib/transitions.js +123 -0
- package/lib/transitions.js.map +1 -0
- package/package.json +60 -3
package/lib/flowers.js
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
// A flower: what blooms among a species' grass, as plain data. Like a species, it is described and not
|
|
2
|
+
// programmed: the shaders name none, and adding one adds an entry.
|
|
3
|
+
//
|
|
4
|
+
// The way a head is built (each petal a small curved surface about the stem's tip, by how far it
|
|
5
|
+
// reaches, how it lifts and how broad it is, with nearer and further drawings of it) follows Inkwell's
|
|
6
|
+
// WebGPU flower field (github.com/siliconjungle/inkwell-webgpu-flowers, MIT). Nothing of its code or
|
|
7
|
+
// its painted flowers is here.
|
|
8
|
+
import * as THREE from "three/webgpu";
|
|
9
|
+
/** The most flowers one species has in it. */
|
|
10
|
+
export const MAX_BLOOMS = 4;
|
|
11
|
+
/** The most kinds of flower the grass draws at once, all its species' together. */
|
|
12
|
+
export const MAX_FLOWERS = 16;
|
|
13
|
+
/** The most petals a head is drawn with. */
|
|
14
|
+
export const MAX_PETALS = 16;
|
|
15
|
+
/** Four numbers to a slot, this many slots to a flower. */
|
|
16
|
+
export const FLOWER_SLOTS = 5;
|
|
17
|
+
/** A form's number in the flower table. */
|
|
18
|
+
export const FORM_CODE = { disc: 0, spike: 1, umbel: 2, bell: 3 };
|
|
19
|
+
/**
|
|
20
|
+
* Nineteen that grow in grass. Sizes from the floras (Stace; Clapham, Tutin and Moore).
|
|
21
|
+
*
|
|
22
|
+
* In mown grass: a daisy's head 16 to 25 mm across on a stalk 3 to 12 cm; a creeping buttercup's flower
|
|
23
|
+
* 2 to 3 cm, five glossy petals; a dandelion's head 25 to 40 mm of strap-shaped florets; white clover's a
|
|
24
|
+
* ball 15 to 20 mm across; slender speedwell, a pale blue flower 8 to 12 mm across, four petals, on a
|
|
25
|
+
* thread of a stalk; selfheal, a spike 1 to 3 cm of violet two-lipped flowers on dark calyces, on 5 to 30
|
|
26
|
+
* cm; kikuyu's own flowers, which are only their stamens, white threads about a centimetre long hanging
|
|
27
|
+
* out of the mat in the days after a mowing.
|
|
28
|
+
*
|
|
29
|
+
* In grass left long: ox-eye daisy, a head 25 to 50 mm across, on 20 to 70 cm; red clover, a ball 15 to
|
|
30
|
+
* 30 mm, pink-purple, on 10 to 40 cm; cat's-ear, a head 25 to 40 mm, on a branched stalk 20 to 60 cm;
|
|
31
|
+
* common knapweed, a brush of purple florets 2 to 4 cm across over a near-black knob of bracts, on 30 to
|
|
32
|
+
* 80 cm; yarrow, a flat top 4 to 10 cm across of white florets 4 to 6 mm, on 8 to 60 cm; harebell, a
|
|
33
|
+
* nodding blue bell 12 to 20 mm long on a hair-thin stalk 15 to 40 cm, in dry grassland, heath and
|
|
34
|
+
* dunes; bird's-foot trefoil, two to seven yellow pea flowers 10 to 16 mm in a head, on 10 to 40 cm;
|
|
35
|
+
* ribwort plantain, a dark brown spike 1 to 4 cm ringed with pale stamens, on 10 to 40 cm. And a grass's
|
|
36
|
+
* own: marram's, a dense pale spike 7 to 22 cm long and 1.5 to 2 cm thick, over its leaves.
|
|
37
|
+
*
|
|
38
|
+
* On a coastal meadow the sea reaches in winter, among red fescue and saltmarsh rush: thrift, a round
|
|
39
|
+
* pink head of small flowers 1.5 to 3 cm across on a bare stalk, the plant 20 to 30 cm (Flora of Victoria),
|
|
40
|
+
* its stalks up to 40 (drawn at 30); sea aster, a head 1 to 4 cm across (commonly 2) of pale violet rays round a
|
|
41
|
+
* yellow disc, on 15 to 60 cm, from July to September (iFlora; Flora Europaea's subsp. tripolium of the
|
|
42
|
+
* North Sea and the Baltic); sea plantain, a lax spike 3 to 7 cm long and 3 to 4 mm thick of greenish
|
|
43
|
+
* flowers with pale yellow stamens, on a stout stalk 5 to 20 cm (Flora Europaea; Gleason and Cronquist).
|
|
44
|
+
*
|
|
45
|
+
* Where they grow (`colony`, `light`). How far a plant creeps each year from Pladias (Kaplan et al. 2019,
|
|
46
|
+
* clonal traits from CLO-PLA; pladias.cz): white clover 27 cm, yarrow 14, speedwell 13, harebell 11,
|
|
47
|
+
* daisy 10, cat's-ear and meadow buttercup 2, knapweed 1; bird's-foot trefoil, red clover and the
|
|
48
|
+
* dandelion not at all, only by seed. Seed falls within a few metres of its plant: a grassland orchid's
|
|
49
|
+
* seedlings gather within 4 to 5 m of it (Jacquemyn et al. 2007, New Phytologist). No one has fitted the
|
|
50
|
+
* colonies of these flowers themselves, so their sizes are set from those: 1.2 m for one that only seeds,
|
|
51
|
+
* to 2.5 m for a creeper, and marram (its rhizomes run 2 m in half a year) and kikuyu 3 m. The least light
|
|
52
|
+
* from their Ellenberg values (Pladias): 8 for cat's-ear, daisy and knapweed, rarely in less than 0.4 of
|
|
53
|
+
* the open's light; 7 for most, 0.3; 6 for germander speedwell, 0.2 (slender speedwell taken as it).
|
|
54
|
+
* Marram's, kikuyu's, selfheal's and plantain's were not looked up: 0.4, 0.4, 0.3, 0.3; nor the coast's
|
|
55
|
+
* three, which grow in the open and are given 0.4. None of the three creeps far: thrift a cushion, sea aster
|
|
56
|
+
* by seed and a short rootstock, sea plantain a rosette: 1.2 to 1.4 m.
|
|
57
|
+
*
|
|
58
|
+
* Colours by eye. Each form is as near as so few surfaces come: a trefoil's pea flower is drawn as a
|
|
59
|
+
* cupped petal, a spike's florets as petals round a core, and a stalk has no branches or leaves.
|
|
60
|
+
*/
|
|
61
|
+
export const FLOWERS = {
|
|
62
|
+
daisy: { name: "Daisy", petals: 16, petalLength: 0.0085, petalWidth: 0.003, lift: 0.1, centre: 0.007, stem: 0.07, petalColor: "#f1f1ea", centreColor: "#e3bd1c", colony: 1.6, light: 0.4 },
|
|
63
|
+
buttercup: { name: "Creeping buttercup", petals: 5, petalLength: 0.0105, petalWidth: 0.0105, lift: 0.4, centre: 0.006, stem: 0.18, petalColor: "#f0cf12", centreColor: "#c7a90c", colony: 1.5, light: 0.3 },
|
|
64
|
+
dandelion: { name: "Dandelion", petals: 16, petalLength: 0.015, petalWidth: 0.0038, lift: 0.18, centre: 0.011, stem: 0.11, petalColor: "#f2c90f", centreColor: "#e8b70a", colony: 1.2, light: 0.3 },
|
|
65
|
+
clover: { name: "White clover", petals: 16, petalLength: 0.0075, petalWidth: 0.0034, lift: 0.95, centre: 0.006, stem: 0.06, petalColor: "#ece8dc", centreColor: "#d9d2bd", colony: 2.5, light: 0.3 },
|
|
66
|
+
speedwell: { name: "Slender speedwell", petals: 4, petalLength: 0.0045, petalWidth: 0.0042, lift: 0.12, centre: 0.0018, stem: 0.045, petalColor: "#93a6e4", centreColor: "#ecedf4", colony: 1.8, light: 0.2 },
|
|
67
|
+
selfheal: { name: "Selfheal", form: "spike", petals: 16, petalLength: 0.009, petalWidth: 0.005, lift: 0.4, centre: 0.007, length: 0.02, stem: 0.07, petalColor: "#7a62b8", centreColor: "#55394f", colony: 1.5, light: 0.3 },
|
|
68
|
+
kikuyu: { name: "Kikuyu's stamens", petals: 10, petalLength: 0.01, petalWidth: 0.0006, lift: -0.75, centre: 0.0012, stem: 0.01, petalColor: "#f3f0e2", centreColor: "#d8cfae", colony: 3.0, light: 0.4 },
|
|
69
|
+
oxeye: { name: "Ox-eye daisy", petals: 16, petalLength: 0.014, petalWidth: 0.0042, lift: 0.08, centre: 0.014, stem: 0.45, petalColor: "#f3f3ec", centreColor: "#e0b014", colony: 2.0, light: 0.3 },
|
|
70
|
+
redClover: { name: "Red clover", petals: 16, petalLength: 0.0095, petalWidth: 0.0038, lift: 0.95, centre: 0.008, stem: 0.22, petalColor: "#c45d8f", centreColor: "#a5487a", colony: 1.2, light: 0.3 },
|
|
71
|
+
catsear: { name: "Cat's-ear", petals: 16, petalLength: 0.0125, petalWidth: 0.003, lift: 0.22, centre: 0.008, stem: 0.32, petalColor: "#f0c41a", centreColor: "#d9a612", colony: 1.3, light: 0.4 },
|
|
72
|
+
knapweed: { name: "Common knapweed", petals: 16, petalLength: 0.008, petalWidth: 0.0022, lift: 0.75, centre: 0.014, centreTall: 0.9, stem: 0.5, petalColor: "#9a5aa2", centreColor: "#3b2a22", colony: 1.3, light: 0.4 },
|
|
73
|
+
yarrow: { name: "Yarrow", form: "umbel", petals: 16, petalLength: 0.004, petalWidth: 0.004, lift: 0.1, centre: 0, length: 0.025, stem: 0.35, petalColor: "#f4f2e8", centreColor: "#e6e2d2", colony: 2.2, light: 0.3 },
|
|
74
|
+
harebell: { name: "Harebell", form: "bell", petals: 5, petalLength: 0.011, petalWidth: 0.0065, lift: 0.95, centre: 0.003, stem: 0.28, petalColor: "#7d8ed6", centreColor: "#e9e9f2", colony: 1.8, light: 0.3 },
|
|
75
|
+
birdsfoot: { name: "Bird's-foot trefoil", form: "umbel", petals: 5, petalLength: 0.011, petalWidth: 0.007, lift: 0.55, centre: 0.002, length: 0.004, stem: 0.12, petalColor: "#f0c21a", centreColor: "#e0960f", colony: 1.2, light: 0.3 },
|
|
76
|
+
marram: { name: "Marram's spike", form: "spike", petals: 16, petalLength: 0.007, petalWidth: 0.004, lift: 0.85, centre: 0.014, length: 0.15, stem: 1, petalColor: "#d6cda2", centreColor: "#c9bf93", colony: 3.0, light: 0.4 },
|
|
77
|
+
plantain: { name: "Ribwort plantain", form: "spike", petals: 16, petalLength: 0.005, petalWidth: 0.0016, lift: 0.1, centre: 0.007, length: 0.025, stem: 0.3, petalColor: "#efe9d2", centreColor: "#4a3a28", colony: 1.2, light: 0.3 },
|
|
78
|
+
thrift: { name: "Thrift", petals: 16, petalLength: 0.009, petalWidth: 0.0042, lift: 0.9, centre: 0.008, stem: 0.3, petalColor: "#e49cbc", centreColor: "#c77898", colony: 1.2, light: 0.4 },
|
|
79
|
+
seaAster: { name: "Sea aster", petals: 16, petalLength: 0.0075, petalWidth: 0.0022, lift: 0.08, centre: 0.007, stem: 0.35, petalColor: "#ab9ed8", centreColor: "#e0b21c", colony: 1.4, light: 0.4 },
|
|
80
|
+
seaPlantain: { name: "Sea plantain", form: "spike", petals: 16, petalLength: 0.0035, petalWidth: 0.0013, lift: 0.15, centre: 0.0045, length: 0.05, stem: 0.15, petalColor: "#e6dca2", centreColor: "#5d5a38", colony: 1.2, light: 0.4 },
|
|
81
|
+
};
|
|
82
|
+
/** One uniform-array entry to a slot, a row to a flower: made once, then written into by `packFlowers`. */
|
|
83
|
+
export function makeFlowerTable() {
|
|
84
|
+
return Array.from({ length: MAX_FLOWERS * FLOWER_SLOTS }, () => new THREE.Vector4());
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Write the flowers `used` names into the table the shaders read, in that order, and say which row each
|
|
88
|
+
* is. The slots:
|
|
89
|
+
*
|
|
90
|
+
* 0 a petal's length and width, its lift, the centre's breadth
|
|
91
|
+
* 1 petals, how tall it stands, its form (`FORM_CODE`), length
|
|
92
|
+
* 2 the petals' colour (linear r, g, b), how far its colonies reach (m)
|
|
93
|
+
* 3 the centre's colour (linear r, g, b), how tall the centre is
|
|
94
|
+
* 4 the least light it flowers in, and three to spare
|
|
95
|
+
*/
|
|
96
|
+
export function packFlowers(used, table, flowers) {
|
|
97
|
+
const at = new Map();
|
|
98
|
+
const c = new THREE.Color();
|
|
99
|
+
for (const name of used) {
|
|
100
|
+
const f = flowers[name];
|
|
101
|
+
if (!f || at.has(name))
|
|
102
|
+
continue;
|
|
103
|
+
if (at.size >= MAX_FLOWERS)
|
|
104
|
+
throw new Error(`At most ${MAX_FLOWERS} kinds of flower, got more`);
|
|
105
|
+
const row = at.size * FLOWER_SLOTS;
|
|
106
|
+
table[row].set(f.petalLength, f.petalWidth, Math.min(1, Math.max(-1, f.lift)), f.centre);
|
|
107
|
+
table[row + 1].set(Math.min(MAX_PETALS, Math.max(3, Math.round(f.petals))), f.stem, FORM_CODE[f.form ?? "disc"] ?? 0, Math.max(0, f.length ?? 0));
|
|
108
|
+
c.set(f.petalColor);
|
|
109
|
+
table[row + 2].set(c.r, c.g, c.b, Math.max(0.1, f.colony ?? 1));
|
|
110
|
+
c.set(f.centreColor);
|
|
111
|
+
table[row + 3].set(c.r, c.g, c.b, Math.min(1, Math.max(0, f.centreTall ?? 0)));
|
|
112
|
+
table[row + 4].set(Math.min(0.95, Math.max(0, f.light ?? 0.3)), 0, 0, 0);
|
|
113
|
+
at.set(name, at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UAAU,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;QAC/E,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,IAAI,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;QACzE,EAAE,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC;IACxB,CAAC;IACD,OAAO,EAAE,CAAC;AACZ,CAAC","sourcesContent":["// A flower: what blooms among a species' grass, as plain data. Like a species, it is described and not\n// programmed: the shaders name none, and adding one adds an entry.\n//\n// The way a head is built (each petal a small curved surface about the stem's tip, by how far it\n// reaches, how it lifts and how broad it is, with nearer and further drawings of it) follows Inkwell's\n// WebGPU flower field (github.com/siliconjungle/inkwell-webgpu-flowers, MIT). Nothing of its code or\n// its painted flowers is here.\n\nimport * as THREE from \"three/webgpu\";\n\n/**\n * How a head is built. \"disc\": petals about a centre, a daisy's (and with lift, a clover's ball or a\n * buttercup's cup; with lift below 0, threads that hang). \"spike\": florets up a stalk's top, round a core\n * (selfheal, plantain). \"umbel\": florets spread over a domed flat top (yarrow; a few large ones, a trefoil's\n * pea flowers). \"bell\": a disc that hangs from its stalk, its petals a cup opening down (harebell).\n */\nexport type FlowerForm = \"disc\" | \"spike\" | \"umbel\" | \"bell\";\n\nexport interface Flower {\n name: string;\n /** How the head is built (none said: \"disc\"). */\n form?: FlowerForm;\n /** Petals to a head, as drawn, or florets to a spike or an umbel: up to `MAX_PETALS`. (A daisy has thirty-odd rays; half as many, a little broader, read the same from a stride off.) */\n petals: number;\n /** A petal's (or floret's) length and its breadth at its widest (m). */\n petalLength: number;\n petalWidth: number;\n /**\n * How far the petals rise from flat, 0 (a disc: a daisy open in the sun) to 1 (a ball: a clover's\n * head); below 0 they hang (-1: straight down, as a grass's stamens do). A spike's or an umbel's\n * florets, from lying out (0) to standing up (1).\n */\n lift: number;\n /** The breadth of the disc at the head's middle (m), or of a spike's core. */\n centre: number;\n /** A spike's length, or an umbel's breadth from its middle to its edge (m). Not used by a disc or a bell. */\n length?: number;\n /** How tall the centre is, 0 (a low dome: a daisy's) to 1 (a knob under the petals: a knapweed's). */\n centreTall?: number;\n /** How tall it stands (m). In grass taller than that it reaches up a little towards the light, and no more. */\n stem: number;\n /**\n * How far its colonies reach (m, the radius in which most of one's flowers stand): a plant that creeps\n * by runners or rhizomes (yarrow, creeping buttercup, white clover) makes broad ones; one that only\n * seeds near itself, small ones. Its colonies stand some three times this apart where they are many, a\n * few flowers stray between them, and none of it where the ground does not suit it. Left out: 1.\n */\n colony?: number;\n /**\n * The least of open ground's light it flowers in, 0..1 (by its Ellenberg light value: 8, rarely below\n * 0.4; 7, 0.3; 6, 0.2). Between that and the open it flowers less the less light it has. Left out: 0.3.\n */\n light?: number;\n /** Hex colours, sRGB. */\n petalColor: string;\n centreColor: string;\n}\n\n/**\n * One flower in a species' grass (`Species.blooms`): which, how many, on how much of the ground, and where.\n */\nexport interface Bloom {\n /** The flower, by its name in the flowers the grass was given (`FLOWERS`, and the host's own). */\n flower: string;\n /** Flowers to the square metre in the heart of one of its colonies (`Flower.colony`). All a species' blooms together come to at most about 40: further off a flower is a dot, and there are only so many dots. */\n perM2: number;\n /** The share of the stand's ground its colonies take, 0..1, where all the ground suited it (about half does): flowers come in colonies, not evenly, each of a species' flowers in colonies of its own. */\n cover: number;\n /**\n * Where on the ground they take, -1..1: in the hollows, where water gathers and stays (-1: creeping\n * buttercup), on the crowns and banks, which dry first (1: cat's-ear, clover on thin soil), or anywhere\n * (0). By the ground's own shape, as a species' patches are (`Species.patchSite`).\n */\n site: number;\n /**\n * \"drifts\" (in its own colonies, `cover` of the ground); \"patches\": it flowers only in the species'\n * patches, as white clover flowers where the clover is (`Species.patch`, which then says how much of\n * the ground that is; `cover` is not used); or \"tussocks\": in its colonies, but only on the species'\n * tussocks (`Species.tussock`), as a tussock grass's own flowering stems rise from its tussocks.\n */\n where: \"drifts\" | \"patches\" | \"tussocks\";\n}\n\n/** The most flowers one species has in it. */\nexport const MAX_BLOOMS = 4;\n/** The most kinds of flower the grass draws at once, all its species' together. */\nexport const MAX_FLOWERS = 16;\n/** The most petals a head is drawn with. */\nexport const MAX_PETALS = 16;\n/** Four numbers to a slot, this many slots to a flower. */\nexport const FLOWER_SLOTS = 5;\n/** A form's number in the flower table. */\nexport const FORM_CODE: Record<FlowerForm, number> = { disc: 0, spike: 1, umbel: 2, bell: 3 };\n\n/**\n * Nineteen that grow in grass. Sizes from the floras (Stace; Clapham, Tutin and Moore).\n *\n * In mown grass: a daisy's head 16 to 25 mm across on a stalk 3 to 12 cm; a creeping buttercup's flower\n * 2 to 3 cm, five glossy petals; a dandelion's head 25 to 40 mm of strap-shaped florets; white clover's a\n * ball 15 to 20 mm across; slender speedwell, a pale blue flower 8 to 12 mm across, four petals, on a\n * thread of a stalk; selfheal, a spike 1 to 3 cm of violet two-lipped flowers on dark calyces, on 5 to 30\n * cm; kikuyu's own flowers, which are only their stamens, white threads about a centimetre long hanging\n * out of the mat in the days after a mowing.\n *\n * In grass left long: ox-eye daisy, a head 25 to 50 mm across, on 20 to 70 cm; red clover, a ball 15 to\n * 30 mm, pink-purple, on 10 to 40 cm; cat's-ear, a head 25 to 40 mm, on a branched stalk 20 to 60 cm;\n * common knapweed, a brush of purple florets 2 to 4 cm across over a near-black knob of bracts, on 30 to\n * 80 cm; yarrow, a flat top 4 to 10 cm across of white florets 4 to 6 mm, on 8 to 60 cm; harebell, a\n * nodding blue bell 12 to 20 mm long on a hair-thin stalk 15 to 40 cm, in dry grassland, heath and\n * dunes; bird's-foot trefoil, two to seven yellow pea flowers 10 to 16 mm in a head, on 10 to 40 cm;\n * ribwort plantain, a dark brown spike 1 to 4 cm ringed with pale stamens, on 10 to 40 cm. And a grass's\n * own: marram's, a dense pale spike 7 to 22 cm long and 1.5 to 2 cm thick, over its leaves.\n *\n * On a coastal meadow the sea reaches in winter, among red fescue and saltmarsh rush: thrift, a round\n * pink head of small flowers 1.5 to 3 cm across on a bare stalk, the plant 20 to 30 cm (Flora of Victoria),\n * its stalks up to 40 (drawn at 30); sea aster, a head 1 to 4 cm across (commonly 2) of pale violet rays round a\n * yellow disc, on 15 to 60 cm, from July to September (iFlora; Flora Europaea's subsp. tripolium of the\n * North Sea and the Baltic); sea plantain, a lax spike 3 to 7 cm long and 3 to 4 mm thick of greenish\n * flowers with pale yellow stamens, on a stout stalk 5 to 20 cm (Flora Europaea; Gleason and Cronquist).\n *\n * Where they grow (`colony`, `light`). How far a plant creeps each year from Pladias (Kaplan et al. 2019,\n * clonal traits from CLO-PLA; pladias.cz): white clover 27 cm, yarrow 14, speedwell 13, harebell 11,\n * daisy 10, cat's-ear and meadow buttercup 2, knapweed 1; bird's-foot trefoil, red clover and the\n * dandelion not at all, only by seed. Seed falls within a few metres of its plant: a grassland orchid's\n * seedlings gather within 4 to 5 m of it (Jacquemyn et al. 2007, New Phytologist). No one has fitted the\n * colonies of these flowers themselves, so their sizes are set from those: 1.2 m for one that only seeds,\n * to 2.5 m for a creeper, and marram (its rhizomes run 2 m in half a year) and kikuyu 3 m. The least light\n * from their Ellenberg values (Pladias): 8 for cat's-ear, daisy and knapweed, rarely in less than 0.4 of\n * the open's light; 7 for most, 0.3; 6 for germander speedwell, 0.2 (slender speedwell taken as it).\n * Marram's, kikuyu's, selfheal's and plantain's were not looked up: 0.4, 0.4, 0.3, 0.3; nor the coast's\n * three, which grow in the open and are given 0.4. None of the three creeps far: thrift a cushion, sea aster\n * by seed and a short rootstock, sea plantain a rosette: 1.2 to 1.4 m.\n *\n * Colours by eye. Each form is as near as so few surfaces come: a trefoil's pea flower is drawn as a\n * cupped petal, a spike's florets as petals round a core, and a stalk has no branches or leaves.\n */\nexport const FLOWERS: Record<string, Flower> = {\n daisy: { name: \"Daisy\", petals: 16, petalLength: 0.0085, petalWidth: 0.003, lift: 0.1, centre: 0.007, stem: 0.07, petalColor: \"#f1f1ea\", centreColor: \"#e3bd1c\", colony: 1.6, light: 0.4 },\n buttercup: { name: \"Creeping buttercup\", petals: 5, petalLength: 0.0105, petalWidth: 0.0105, lift: 0.4, centre: 0.006, stem: 0.18, petalColor: \"#f0cf12\", centreColor: \"#c7a90c\", colony: 1.5, light: 0.3 },\n dandelion: { name: \"Dandelion\", petals: 16, petalLength: 0.015, petalWidth: 0.0038, lift: 0.18, centre: 0.011, stem: 0.11, petalColor: \"#f2c90f\", centreColor: \"#e8b70a\", colony: 1.2, light: 0.3 },\n clover: { name: \"White clover\", petals: 16, petalLength: 0.0075, petalWidth: 0.0034, lift: 0.95, centre: 0.006, stem: 0.06, petalColor: \"#ece8dc\", centreColor: \"#d9d2bd\", colony: 2.5, light: 0.3 },\n speedwell: { name: \"Slender speedwell\", petals: 4, petalLength: 0.0045, petalWidth: 0.0042, lift: 0.12, centre: 0.0018, stem: 0.045, petalColor: \"#93a6e4\", centreColor: \"#ecedf4\", colony: 1.8, light: 0.2 },\n selfheal: { name: \"Selfheal\", form: \"spike\", petals: 16, petalLength: 0.009, petalWidth: 0.005, lift: 0.4, centre: 0.007, length: 0.02, stem: 0.07, petalColor: \"#7a62b8\", centreColor: \"#55394f\", colony: 1.5, light: 0.3 },\n kikuyu: { name: \"Kikuyu's stamens\", petals: 10, petalLength: 0.01, petalWidth: 0.0006, lift: -0.75, centre: 0.0012, stem: 0.01, petalColor: \"#f3f0e2\", centreColor: \"#d8cfae\", colony: 3.0, light: 0.4 },\n oxeye: { name: \"Ox-eye daisy\", petals: 16, petalLength: 0.014, petalWidth: 0.0042, lift: 0.08, centre: 0.014, stem: 0.45, petalColor: \"#f3f3ec\", centreColor: \"#e0b014\", colony: 2.0, light: 0.3 },\n redClover: { name: \"Red clover\", petals: 16, petalLength: 0.0095, petalWidth: 0.0038, lift: 0.95, centre: 0.008, stem: 0.22, petalColor: \"#c45d8f\", centreColor: \"#a5487a\", colony: 1.2, light: 0.3 },\n catsear: { name: \"Cat's-ear\", petals: 16, petalLength: 0.0125, petalWidth: 0.003, lift: 0.22, centre: 0.008, stem: 0.32, petalColor: \"#f0c41a\", centreColor: \"#d9a612\", colony: 1.3, light: 0.4 },\n knapweed: { name: \"Common knapweed\", petals: 16, petalLength: 0.008, petalWidth: 0.0022, lift: 0.75, centre: 0.014, centreTall: 0.9, stem: 0.5, petalColor: \"#9a5aa2\", centreColor: \"#3b2a22\", colony: 1.3, light: 0.4 },\n yarrow: { name: \"Yarrow\", form: \"umbel\", petals: 16, petalLength: 0.004, petalWidth: 0.004, lift: 0.1, centre: 0, length: 0.025, stem: 0.35, petalColor: \"#f4f2e8\", centreColor: \"#e6e2d2\", colony: 2.2, light: 0.3 },\n harebell: { name: \"Harebell\", form: \"bell\", petals: 5, petalLength: 0.011, petalWidth: 0.0065, lift: 0.95, centre: 0.003, stem: 0.28, petalColor: \"#7d8ed6\", centreColor: \"#e9e9f2\", colony: 1.8, light: 0.3 },\n birdsfoot: { name: \"Bird's-foot trefoil\", form: \"umbel\", petals: 5, petalLength: 0.011, petalWidth: 0.007, lift: 0.55, centre: 0.002, length: 0.004, stem: 0.12, petalColor: \"#f0c21a\", centreColor: \"#e0960f\", colony: 1.2, light: 0.3 },\n marram: { name: \"Marram's spike\", form: \"spike\", petals: 16, petalLength: 0.007, petalWidth: 0.004, lift: 0.85, centre: 0.014, length: 0.15, stem: 1, petalColor: \"#d6cda2\", centreColor: \"#c9bf93\", colony: 3.0, light: 0.4 },\n plantain: { name: \"Ribwort plantain\", form: \"spike\", petals: 16, petalLength: 0.005, petalWidth: 0.0016, lift: 0.1, centre: 0.007, length: 0.025, stem: 0.3, petalColor: \"#efe9d2\", centreColor: \"#4a3a28\", colony: 1.2, light: 0.3 },\n thrift: { name: \"Thrift\", petals: 16, petalLength: 0.009, petalWidth: 0.0042, lift: 0.9, centre: 0.008, stem: 0.3, petalColor: \"#e49cbc\", centreColor: \"#c77898\", colony: 1.2, light: 0.4 },\n seaAster: { name: \"Sea aster\", petals: 16, petalLength: 0.0075, petalWidth: 0.0022, lift: 0.08, centre: 0.007, stem: 0.35, petalColor: \"#ab9ed8\", centreColor: \"#e0b21c\", colony: 1.4, light: 0.4 },\n seaPlantain: { name: \"Sea plantain\", form: \"spike\", petals: 16, petalLength: 0.0035, petalWidth: 0.0013, lift: 0.15, centre: 0.0045, length: 0.05, stem: 0.15, petalColor: \"#e6dca2\", centreColor: \"#5d5a38\", colony: 1.2, light: 0.4 },\n};\n\n/** One uniform-array entry to a slot, a row to a flower: made once, then written into by `packFlowers`. */\nexport function makeFlowerTable(): THREE.Vector4[] {\n return Array.from({ length: MAX_FLOWERS * FLOWER_SLOTS }, () => new THREE.Vector4());\n}\n\n/**\n * Write the flowers `used` names into the table the shaders read, in that order, and say which row each\n * is. The slots:\n *\n * 0 a petal's length and width, its lift, the centre's breadth\n * 1 petals, how tall it stands, its form (`FORM_CODE`), length\n * 2 the petals' colour (linear r, g, b), how far its colonies reach (m)\n * 3 the centre's colour (linear r, g, b), how tall the centre is\n * 4 the least light it flowers in, and three to spare\n */\nexport function packFlowers(used: readonly string[], table: THREE.Vector4[], flowers: Readonly<Record<string, Flower>>): Map<string, number> {\n const at = new Map<string, number>();\n const c = new THREE.Color();\n for (const name of used) {\n const f = flowers[name];\n if (!f || at.has(name)) continue;\n if (at.size >= MAX_FLOWERS) throw new Error(`At most ${MAX_FLOWERS} kinds of flower, got more`);\n const row = at.size * FLOWER_SLOTS;\n table[row].set(f.petalLength, f.petalWidth, Math.min(1, Math.max(-1, f.lift)), f.centre);\n table[row + 1].set(Math.min(MAX_PETALS, Math.max(3, Math.round(f.petals))), f.stem, FORM_CODE[f.form ?? \"disc\"] ?? 0, Math.max(0, f.length ?? 0));\n c.set(f.petalColor);\n table[row + 2].set(c.r, c.g, c.b, Math.max(0.1, f.colony ?? 1));\n c.set(f.centreColor);\n table[row + 3].set(c.r, c.g, c.b, Math.min(1, Math.max(0, f.centreTall ?? 0)));\n table[row + 4].set(Math.min(0.95, Math.max(0, f.light ?? 0.3)), 0, 0, 0);\n at.set(name, at.size);\n }\n return at;\n}\n"]}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { DEFAULT_LAYERS, type Grass, type GrassLayer, type GrassThing, MAX_THINGS, MAX_TRAIL, thingMiddleFor, standTone, type GrassLayers, type GrassOptions, type PlaceKnown, type WorldLight, MAX_LEAF_TEXTURES, type NearLayer, type Specimen, type SpecimenKind, createGrass } from "./engine.js";
|
|
2
|
+
export { DEFAULT_DISTANCE, type GrassDistance, frustumPlanesPad, hexTileWeights, inFrustumSphere, isHorizonOccluded, resolveDistance } from "./distance.js";
|
|
3
|
+
export { DEFAULT_TRANSITIONS, type GrassTransitions, clampTransitions, groundUnderFar, leafSeenShare, leavesAtShare, resolveTransitions, tuftHalfWidth, tuftWidth } from "./transitions.js";
|
|
4
|
+
export { type FieldMap, type GrassMap, type HeightGrid, type HeightSource, type MapSource, type MowSource, type MowStripes, NO_GRASS, type SpeciesMapSource, heightAt, fieldMap, heightGrid, mowStripes, speciesMap } from "./field.js";
|
|
5
|
+
export { GRASSES, type GrassName, MAX_SPECIES, MORE_GRASSES, MORE_PLANTS, MORE_TURF, NATIVE_GRASSES, type PatchKind, STARTER_SPECIES, TURF_SPECIES, type Species, type TextureMode, type TipShape, checkSpecies, cloneSpecies, parseSpecies } from "./species.js";
|
|
6
|
+
export { type Bloom, FLOWERS, type Flower, MAX_BLOOMS, MAX_FLOWERS, MAX_PETALS } from "./flowers.js";
|
|
7
|
+
export { mixedMap } from "./mix.js";
|
|
8
|
+
export { type GrassMix, type MixMember, mixAt, mixChances, mostCover } from "./mixshare.js";
|
|
9
|
+
export { probePlacement } from "./placement.js";
|
|
10
|
+
export { RANK_SIDE, finePlace, grassRanks, rankMatrix, rankOf } from "./rank.js";
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+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E,KAAK,MAAM,EAAE,UAAU,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AACrG,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACpC,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,SAAS,EAAE,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC5F,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC"}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// The package's public face. The lab (../lab) imports from here and from
|
|
2
|
+
// nowhere else in the package, and nothing in the package imports from the
|
|
3
|
+
// game: scripts/grass-boundary.test.mjs holds both.
|
|
4
|
+
export { DEFAULT_LAYERS, MAX_THINGS, MAX_TRAIL, thingMiddleFor, standTone, MAX_LEAF_TEXTURES, createGrass } from "./engine.js";
|
|
5
|
+
export { DEFAULT_DISTANCE, frustumPlanesPad, hexTileWeights, inFrustumSphere, isHorizonOccluded, resolveDistance } from "./distance.js";
|
|
6
|
+
export { DEFAULT_TRANSITIONS, clampTransitions, groundUnderFar, leafSeenShare, leavesAtShare, resolveTransitions, tuftHalfWidth, tuftWidth } from "./transitions.js";
|
|
7
|
+
export { NO_GRASS, heightAt, fieldMap, heightGrid, mowStripes, speciesMap } from "./field.js";
|
|
8
|
+
export { GRASSES, MAX_SPECIES, MORE_GRASSES, MORE_PLANTS, MORE_TURF, NATIVE_GRASSES, STARTER_SPECIES, TURF_SPECIES, checkSpecies, cloneSpecies, parseSpecies } from "./species.js";
|
|
9
|
+
export { FLOWERS, MAX_BLOOMS, MAX_FLOWERS, MAX_PETALS } from "./flowers.js";
|
|
10
|
+
export { mixedMap } from "./mix.js";
|
|
11
|
+
export { mixAt, mixChances, mostCover } from "./mixshare.js";
|
|
12
|
+
export { probePlacement } from "./placement.js";
|
|
13
|
+
export { RANK_SIDE, finePlace, grassRanks, rankMatrix, rankOf } from "./rank.js";
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,2EAA2E;AAC3E,oDAAoD;AAEpD,OAAO,EAAE,cAAc,EAAgD,UAAU,EAAE,SAAS,EAAE,cAAc,EAAE,SAAS,EAAyE,iBAAiB,EAAoD,WAAW,EAAE,MAAM,aAAa,CAAC;AACtS,OAAO,EAAE,gBAAgB,EAAsB,gBAAgB,EAAE,cAAc,EAAE,eAAe,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAC5J,OAAO,EAAE,mBAAmB,EAAyB,gBAAgB,EAAE,cAAc,EAAE,aAAa,EAAE,aAAa,EAAE,kBAAkB,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC5L,OAAO,EAAqH,QAAQ,EAAyB,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxO,OAAO,EAAE,OAAO,EAAkB,WAAW,EAAE,YAAY,EAAE,WAAW,EAAE,SAAS,EAAE,cAAc,EAAkB,eAAe,EAAE,YAAY,EAAiD,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAClQ,OAAO,EAAc,OAAO,EAAe,UAAU,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AACrG,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACpC,OAAO,EAAiC,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC5F,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC","sourcesContent":["// The package's public face. The lab (../lab) imports from here and from\n// nowhere else in the package, and nothing in the package imports from the\n// game: scripts/grass-boundary.test.mjs holds both.\n\nexport { DEFAULT_LAYERS, type Grass, type GrassLayer, type GrassThing, MAX_THINGS, MAX_TRAIL, thingMiddleFor, standTone, type GrassLayers, type GrassOptions, type PlaceKnown, type WorldLight, MAX_LEAF_TEXTURES, type NearLayer, type Specimen, type SpecimenKind, createGrass } from \"./engine.ts\";\nexport { DEFAULT_DISTANCE, type GrassDistance, frustumPlanesPad, hexTileWeights, inFrustumSphere, isHorizonOccluded, resolveDistance } from \"./distance.ts\";\nexport { DEFAULT_TRANSITIONS, type GrassTransitions, clampTransitions, groundUnderFar, leafSeenShare, leavesAtShare, resolveTransitions, tuftHalfWidth, tuftWidth } from \"./transitions.ts\";\nexport { type FieldMap, type GrassMap, type HeightGrid, type HeightSource, type MapSource, type MowSource, type MowStripes, NO_GRASS, type SpeciesMapSource, heightAt, fieldMap, heightGrid, mowStripes, speciesMap } from \"./field.ts\";\nexport { GRASSES, type GrassName, MAX_SPECIES, MORE_GRASSES, MORE_PLANTS, MORE_TURF, NATIVE_GRASSES, type PatchKind, STARTER_SPECIES, TURF_SPECIES, type Species, type TextureMode, type TipShape, checkSpecies, cloneSpecies, parseSpecies } from \"./species.ts\";\nexport { type Bloom, FLOWERS, type Flower, MAX_BLOOMS, MAX_FLOWERS, MAX_PETALS } from \"./flowers.ts\";\nexport { mixedMap } from \"./mix.ts\";\nexport { type GrassMix, type MixMember, mixAt, mixChances, mostCover } from \"./mixshare.ts\";\nexport { probePlacement } from \"./placement.ts\";\nexport { RANK_SIDE, finePlace, grassRanks, rankMatrix, rankOf } from \"./rank.ts\";\n"]}
|
package/lib/mix.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type MapSource } from "./field.js";
|
|
2
|
+
import { type GrassMix } from "./mixshare.js";
|
|
3
|
+
/**
|
|
4
|
+
* A map whose stands are mixes: where `source` says a mix's lead (`GrassMix.species`), the place is the
|
|
5
|
+
* member's whose colony it is in, if any, and the lead's if none. How far a place is from another stand
|
|
6
|
+
* (`edge`) is the source's: a patch is part of its stand, so tufts, flowers and an edge's straying go by
|
|
7
|
+
* the stand's edge, not by the patches'. (Two grasses of a stand do still run into each other at a patch's
|
|
8
|
+
* edge, as far as each lets its edge stray: `Species.edgeBlend`.)
|
|
9
|
+
*
|
|
10
|
+
* A member may be `NO_GRASS`: bare ground in the stand, in patches (sandy scrapes on a links, thin ground
|
|
11
|
+
* on a heath), where the host's own ground shows.
|
|
12
|
+
*
|
|
13
|
+
* Each member's chance of a colony is worked out here, once (`mixChances`): it throws on shares a mix cannot
|
|
14
|
+
* have. A member costs nine looks at a hash for each place the grass asks about.
|
|
15
|
+
*/
|
|
16
|
+
export declare function mixedMap(source: MapSource, mixes: readonly GrassMix[]): MapSource;
|
|
17
|
+
//# sourceMappingURL=mix.d.ts.map
|
package/lib/mix.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mix.d.ts","sourceRoot":"","sources":["../src/mix.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,SAAS,EAAY,MAAM,YAAY,CAAC;AACtD,OAAO,EAAE,KAAK,QAAQ,EAA0B,MAAM,eAAe,CAAC;AAsCtE;;;;;;;;;;;;GAYG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,QAAQ,EAAE,GAAG,SAAS,CAyCjF"}
|
package/lib/mix.js
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
// A map of mixes: a host's map says where its stands are, and this says which of each stand's grasses grows
|
|
2
|
+
// at a place in it (the arithmetic, and why, is mixshare.ts, the twin of what is worked out here).
|
|
3
|
+
import { Fn, If, cos, dot, exp, float, floor, length, max, mod, normalize, sin, step, vec2 } from "three/tsl";
|
|
4
|
+
import { NO_GRASS } from "./field.js";
|
|
5
|
+
import { memberSalt, mixChances } from "./mixshare.js";
|
|
6
|
+
import { hashCell } from "./placement.js";
|
|
7
|
+
import { MAX_SPECIES } from "./species.js";
|
|
8
|
+
/** 1 where a place is in one of a member's colonies (`inColony` in mixshare.ts, its twin). */
|
|
9
|
+
function inColony(xz, size, kept, salt) {
|
|
10
|
+
const home = floor(xz.div(size));
|
|
11
|
+
// (The edge's grain is the place's, whichever colony it is the edge of.)
|
|
12
|
+
const grain = hashCell(xz.mul(29.7)).mul(2).sub(1).mul(0.16);
|
|
13
|
+
const inside = float(0).toVar();
|
|
14
|
+
for (let dz = -1; dz <= 1; dz++) {
|
|
15
|
+
for (let dx = -1; dx <= 1; dx++) {
|
|
16
|
+
const cell = home.add(vec2(dx, dz));
|
|
17
|
+
const hc = mod(cell, float(1024)).add(vec2(salt * 0.731, salt * 0.317));
|
|
18
|
+
// (Most squares have no colony: for those none of the rest is worked out.)
|
|
19
|
+
If(hashCell(hc.add(2.9)).lessThan(kept), () => {
|
|
20
|
+
const centre = cell.add(vec2(hashCell(hc.add(1.3)), hashCell(hc.add(7.9))).mul(0.7).add(0.15)).mul(size);
|
|
21
|
+
const reach = exp(hashCell(hc.add(4.1)).sub(0.5).mul(0.8)).mul(size * 0.5);
|
|
22
|
+
// (Its ragged edge: mixshare.ts `edgeAt`, its twin.)
|
|
23
|
+
const off = xz.sub(centre);
|
|
24
|
+
const n = normalize(off.add(vec2(1e-6, 0)));
|
|
25
|
+
const a = hashCell(hc.add(5.3)).mul(6.2832);
|
|
26
|
+
const b = hashCell(hc.add(6.7)).mul(6.2832);
|
|
27
|
+
const along = dot(n, vec2(cos(a), sin(a)));
|
|
28
|
+
const edge = float(1)
|
|
29
|
+
.add(along.mul(along).mul(2).sub(1).mul(0.2))
|
|
30
|
+
.add(dot(n, vec2(cos(b), sin(b))).mul(0.12))
|
|
31
|
+
.add(grain);
|
|
32
|
+
inside.assign(max(inside, step(length(off), reach.mul(edge))));
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return inside;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* A map whose stands are mixes: where `source` says a mix's lead (`GrassMix.species`), the place is the
|
|
40
|
+
* member's whose colony it is in, if any, and the lead's if none. How far a place is from another stand
|
|
41
|
+
* (`edge`) is the source's: a patch is part of its stand, so tufts, flowers and an edge's straying go by
|
|
42
|
+
* the stand's edge, not by the patches'. (Two grasses of a stand do still run into each other at a patch's
|
|
43
|
+
* edge, as far as each lets its edge stray: `Species.edgeBlend`.)
|
|
44
|
+
*
|
|
45
|
+
* A member may be `NO_GRASS`: bare ground in the stand, in patches (sandy scrapes on a links, thin ground
|
|
46
|
+
* on a heath), where the host's own ground shows.
|
|
47
|
+
*
|
|
48
|
+
* Each member's chance of a colony is worked out here, once (`mixChances`): it throws on shares a mix cannot
|
|
49
|
+
* have. A member costs nine looks at a hash for each place the grass asks about.
|
|
50
|
+
*/
|
|
51
|
+
export function mixedMap(source, mixes) {
|
|
52
|
+
const worked = mixes.map((m) => {
|
|
53
|
+
for (const row of [m.species, ...m.members.map((x) => x.species)]) {
|
|
54
|
+
const bare = row === NO_GRASS && row !== m.species;
|
|
55
|
+
if (!bare && !(row >= 0 && row < MAX_SPECIES && Number.isInteger(row)))
|
|
56
|
+
throw new Error(`A mix's rows are whole numbers below ${MAX_SPECIES} (or a member's NO_GRASS), not ${row}`);
|
|
57
|
+
}
|
|
58
|
+
return { mix: m, chances: mixChances(m) };
|
|
59
|
+
});
|
|
60
|
+
return {
|
|
61
|
+
bounds: source.bounds,
|
|
62
|
+
edgeReach: source.edgeReach,
|
|
63
|
+
sample(xz) {
|
|
64
|
+
const here = source.sample(xz);
|
|
65
|
+
// (A place is in one stand at most: only that stand's mix is worked out there, and none where the
|
|
66
|
+
// stand is not a mix's.)
|
|
67
|
+
const species = Fn(() => {
|
|
68
|
+
const out = float(here.species).toVar();
|
|
69
|
+
for (const { mix: m, chances } of worked) {
|
|
70
|
+
If(here.species.greaterThan(m.species - 0.5).and(here.species.lessThan(m.species + 0.5)), () => {
|
|
71
|
+
// (The first member listed has a place two of them cover: once one has it, the rest are not asked.)
|
|
72
|
+
const taken = float(0).toVar();
|
|
73
|
+
for (let j = 0; j < m.members.length; j++) {
|
|
74
|
+
if (!(chances[j] > 0))
|
|
75
|
+
continue;
|
|
76
|
+
const member = m.members[j];
|
|
77
|
+
If(taken.lessThan(0.5), () => {
|
|
78
|
+
If(inColony(xz, member.patchSize, chances[j], memberSalt(j)).greaterThan(0.5), () => {
|
|
79
|
+
out.assign(float(member.species));
|
|
80
|
+
taken.assign(1);
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
return out;
|
|
87
|
+
})();
|
|
88
|
+
return { species, edge: here.edge };
|
|
89
|
+
},
|
|
90
|
+
dispose() {
|
|
91
|
+
source.dispose();
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=mix.js.map
|
package/lib/mix.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mix.js","sourceRoot":"","sources":["../src/mix.ts"],"names":[],"mappings":"AAAA,4GAA4G;AAC5G,mGAAmG;AAGnG,OAAO,EAAE,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC9G,OAAO,EAAkB,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtD,OAAO,EAAiB,UAAU,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AACtE,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,WAAW,EA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ACH,CAAC,CAAC,CAAC;gBACL,CAAC;gBACD,OAAO,GAAG,CAAC;YACb,CAAC,CAAC,EAAsB,CAAC;YACzB,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC;QACtC,CAAC;QACD,OAAO;YACL,MAAM,CAAC,OAAO,EAAE,CAAC;QACnB,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["// A map of mixes: a host's map says where its stands are, and this says which of each stand's grasses grows\n// at a place in it (the arithmetic, and why, is mixshare.ts, the twin of what is worked out here).\n\nimport * as THREE from \"three/webgpu\";\nimport { Fn, If, cos, dot, exp, float, floor, length, max, mod, normalize, sin, step, vec2 } from \"three/tsl\";\nimport { type MapSource, NO_GRASS } from \"./field.ts\";\nimport { type GrassMix, memberSalt, mixChances } from \"./mixshare.ts\";\nimport { hashCell } from \"./placement.ts\";\nimport { MAX_SPECIES } from \"./species.ts\";\n\ntype Vec2 = THREE.Node<\"vec2\">;\ntype Float = THREE.Node<\"float\">;\n\n/** 1 where a place is in one of a member's colonies (`inColony` in mixshare.ts, its twin). */\nfunction inColony(xz: Vec2, size: number, kept: number, salt: number): Float {\n const home = floor(xz.div(size));\n // (The edge's grain is the place's, whichever colony it is the edge of.)\n const grain = hashCell(xz.mul(29.7)).mul(2).sub(1).mul(0.16);\n const inside = float(0).toVar();\n for (let dz = -1; dz <= 1; dz++) {\n for (let dx = -1; dx <= 1; dx++) {\n const cell = home.add(vec2(dx, dz));\n const hc = mod(cell, float(1024)).add(vec2(salt * 0.731, salt * 0.317));\n // (Most squares have no colony: for those none of the rest is worked out.)\n If(hashCell(hc.add(2.9)).lessThan(kept), () => {\n const centre = cell.add(vec2(hashCell(hc.add(1.3)), hashCell(hc.add(7.9))).mul(0.7).add(0.15)).mul(size);\n const reach = exp(hashCell(hc.add(4.1)).sub(0.5).mul(0.8)).mul(size * 0.5);\n // (Its ragged edge: mixshare.ts `edgeAt`, its twin.)\n const off = xz.sub(centre);\n const n = normalize(off.add(vec2(1e-6, 0)));\n const a = hashCell(hc.add(5.3)).mul(6.2832);\n const b = hashCell(hc.add(6.7)).mul(6.2832);\n const along = dot(n, vec2(cos(a), sin(a)));\n const edge = float(1)\n .add(along.mul(along).mul(2).sub(1).mul(0.2))\n .add(dot(n, vec2(cos(b), sin(b))).mul(0.12))\n .add(grain);\n inside.assign(max(inside, step(length(off), reach.mul(edge))));\n });\n }\n }\n return inside;\n}\n\n/**\n * A map whose stands are mixes: where `source` says a mix's lead (`GrassMix.species`), the place is the\n * member's whose colony it is in, if any, and the lead's if none. How far a place is from another stand\n * (`edge`) is the source's: a patch is part of its stand, so tufts, flowers and an edge's straying go by\n * the stand's edge, not by the patches'. (Two grasses of a stand do still run into each other at a patch's\n * edge, as far as each lets its edge stray: `Species.edgeBlend`.)\n *\n * A member may be `NO_GRASS`: bare ground in the stand, in patches (sandy scrapes on a links, thin ground\n * on a heath), where the host's own ground shows.\n *\n * Each member's chance of a colony is worked out here, once (`mixChances`): it throws on shares a mix cannot\n * have. A member costs nine looks at a hash for each place the grass asks about.\n */\nexport function mixedMap(source: MapSource, mixes: readonly GrassMix[]): MapSource {\n const worked = mixes.map((m) => {\n for (const row of [m.species, ...m.members.map((x) => x.species)]) {\n const bare = row === NO_GRASS && row !== m.species;\n if (!bare && !(row >= 0 && row < MAX_SPECIES && Number.isInteger(row))) throw new Error(`A mix's rows are whole numbers below ${MAX_SPECIES} (or a member's NO_GRASS), not ${row}`);\n }\n return { mix: m, chances: mixChances(m) };\n });\n return {\n bounds: source.bounds,\n edgeReach: source.edgeReach,\n sample(xz) {\n const here = source.sample(xz);\n // (A place is in one stand at most: only that stand's mix is worked out there, and none where the\n // stand is not a mix's.)\n const species = Fn(() => {\n const out = float(here.species).toVar();\n for (const { mix: m, chances } of worked) {\n If(here.species.greaterThan(m.species - 0.5).and(here.species.lessThan(m.species + 0.5)), () => {\n // (The first member listed has a place two of them cover: once one has it, the rest are not asked.)\n const taken = float(0).toVar();\n for (let j = 0; j < m.members.length; j++) {\n if (!(chances[j] > 0)) continue;\n const member = m.members[j];\n If(taken.lessThan(0.5), () => {\n If(inColony(xz, member.patchSize, chances[j], memberSalt(j)).greaterThan(0.5), () => {\n out.assign(float(member.species));\n taken.assign(1);\n });\n });\n }\n });\n }\n return out;\n })() as unknown as Float;\n return { species, edge: here.edge };\n },\n dispose() {\n source.dispose();\n },\n };\n}\n"]}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/** One of a mix's grasses after its lead: its row in the species table (or `NO_GRASS`, 255, for bare ground), its share of the stand, how far across its patches are (m). */
|
|
2
|
+
export interface MixMember {
|
|
3
|
+
species: number;
|
|
4
|
+
share: number;
|
|
5
|
+
patchSize: number;
|
|
6
|
+
/**
|
|
7
|
+
* The chance that a square of its has a colony, if the host knows it already: from a twin of this
|
|
8
|
+
* arithmetic elsewhere (a physics that plays the same patches, say), so both have the very same
|
|
9
|
+
* colonies and not two numbers a rounding apart. Left out: worked out here from `share` (`mixChances`).
|
|
10
|
+
*/
|
|
11
|
+
chance?: number;
|
|
12
|
+
}
|
|
13
|
+
/** A stand of several grasses: where the map says `species` (the lead), its members take their shares of the ground in patches. */
|
|
14
|
+
export interface GrassMix {
|
|
15
|
+
species: number;
|
|
16
|
+
members: MixMember[];
|
|
17
|
+
}
|
|
18
|
+
/** Salts that keep each member's squares apart from the others': the shaders' are the same. */
|
|
19
|
+
export declare function memberSalt(j: number): number;
|
|
20
|
+
/**
|
|
21
|
+
* Whether a place is in one of a member's colonies, given the chance that a square has one (`kept`): the
|
|
22
|
+
* twin of the shaders' `inColony` (mix.ts). The shaders' numbers are 32-bit; these are rounded to them where
|
|
23
|
+
* the hash reads them, which is where a difference would move a colony.
|
|
24
|
+
*/
|
|
25
|
+
export declare function inColony(x: number, z: number, size: number, kept: number, salt: number): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* How far a colony's edge is from its middle in a direction (`nx`, `nz`, of length one), as a share of its
|
|
28
|
+
* reach, its lobes and bulge turned by its own two numbers (`a`, `b`, 0..1), frayed by the place itself.
|
|
29
|
+
*/
|
|
30
|
+
export declare function edgeAt(x: number, z: number, nx: number, nz: number, a: number, b: number): number;
|
|
31
|
+
/** The most of the ground the `j`th member's colonies can cover: every square with one. About 0.6. */
|
|
32
|
+
export declare function mostCover(j: number, size?: number): number;
|
|
33
|
+
/**
|
|
34
|
+
* Each member's chance that a square has a colony, so that the member takes its share of the stand: a member
|
|
35
|
+
* has the ground its colonies cover that no member before it has, so it needs its share of what is left.
|
|
36
|
+
* Worked out by halving on the twin itself. Throws on shares that cannot be had: more than the whole stand
|
|
37
|
+
* between them, or more of what is left than a member's colonies can cover.
|
|
38
|
+
*/
|
|
39
|
+
export declare function mixChances(mix: GrassMix): number[];
|
|
40
|
+
/** Which grass of a mix grows at a place: the twin of what `mixedMap` says there. */
|
|
41
|
+
export declare function mixAt(mix: GrassMix, chances: readonly number[], x: number, z: number): number;
|
|
42
|
+
//# sourceMappingURL=mixshare.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mixshare.d.ts","sourceRoot":"","sources":["../src/mixshare.ts"],"names":[],"mappings":"AAcA,6KAA6K;AAC7K,MAAM,WAAW,SAAS;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,mIAAmI;AACnI,MAAM,WAAW,QAAQ;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,SAAS,EAAE,CAAC;CACtB;AAsBD,+FAA+F;AAC/F,wBAAgB,UAAU,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAE5C;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAsBhG;AAED;;;GAGG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAKjG;AAWD,sGAAsG;AACtG,wBAAgB,SAAS,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,SAAI,GAAG,MAAM,CAErD;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,QAAQ,GAAG,MAAM,EAAE,CA0BlD;AAKD,qFAAqF;AACrF,wBAAgB,KAAK,CAAC,GAAG,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAM7F"}
|
package/lib/mixshare.js
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
// A mix's arithmetic, with no three.js in it: where each of a mix's grasses grows, as plain numbers, so a
|
|
2
|
+
// test can run it and a host can ask it (the shaders' half is `mixedMap` in mix.ts, kept in step with this).
|
|
3
|
+
//
|
|
4
|
+
// No stand of grass nobody mows is one grass. One grass is the stand's body (the mix's lead) and the others
|
|
5
|
+
// grow in patches in it, each in patches of its own size: sheep's fescue in tufts a stride across in a red
|
|
6
|
+
// fescue, Yorkshire fog in drifts a few strides across in a meadow. A patch is a colony grown out from where a
|
|
7
|
+
// seed landed or a runner rooted, roughly round (as the library's own patches are, `Species.patchKind`):
|
|
8
|
+
// the ground is squared off at a member's patch size, each square has at most one colony somewhere in its
|
|
9
|
+
// middle, of a size drawn so that most are about the patch size and a few half or half again as big, and
|
|
10
|
+
// whether a square has one at all goes by a chance worked out so that the member takes its share of the
|
|
11
|
+
// stand. Where colonies of two members overlap, the one listed first has the place.
|
|
12
|
+
import { hashCell } from "./rank.js";
|
|
13
|
+
/** A colony's reach as a share of its square, at its middle size; and how much the sizes spread (its exponent's span). */
|
|
14
|
+
const REACH = 0.5;
|
|
15
|
+
const SIZE_SPREAD = 0.8;
|
|
16
|
+
/** Where in its square a colony stands: from this share in from each side, over the rest. */
|
|
17
|
+
const INSET = 0.15;
|
|
18
|
+
/** Squares hash their numbers within a repeat of this many: the hash loses its evenness on large ones. */
|
|
19
|
+
const REPEAT = 1024;
|
|
20
|
+
/**
|
|
21
|
+
* A colony is not a disc: its edge goes in and out round it (two lobes and a bulge, each turned its own
|
|
22
|
+
* way: shares of its reach), and plant by plant at its edge some stand in and some out (`FRAY`, a share of
|
|
23
|
+
* its reach either way), as a patch grown from runners and seed has a ragged edge.
|
|
24
|
+
*/
|
|
25
|
+
const LOBES = 0.2;
|
|
26
|
+
const BULGE = 0.12;
|
|
27
|
+
const FRAY = 0.16;
|
|
28
|
+
/** The scale of the fray's noise: finer than a plant's spacing, so it is a plant's own. */
|
|
29
|
+
const FRAY_SCALE = 29.7;
|
|
30
|
+
const f = Math.fround;
|
|
31
|
+
/** Salts that keep each member's squares apart from the others': the shaders' are the same. */
|
|
32
|
+
export function memberSalt(j) {
|
|
33
|
+
return 11 + j * 17;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Whether a place is in one of a member's colonies, given the chance that a square has one (`kept`): the
|
|
37
|
+
* twin of the shaders' `inColony` (mix.ts). The shaders' numbers are 32-bit; these are rounded to them where
|
|
38
|
+
* the hash reads them, which is where a difference would move a colony.
|
|
39
|
+
*/
|
|
40
|
+
export function inColony(x, z, size, kept, salt) {
|
|
41
|
+
const gx = Math.floor(x / size);
|
|
42
|
+
const gz = Math.floor(z / size);
|
|
43
|
+
for (let dz = -1; dz <= 1; dz++) {
|
|
44
|
+
for (let dx = -1; dx <= 1; dx++) {
|
|
45
|
+
const cx = gx + dx;
|
|
46
|
+
const cz = gz + dz;
|
|
47
|
+
const hx = f(f(((cx % REPEAT) + REPEAT) % REPEAT) + f(salt * 0.731));
|
|
48
|
+
const hz = f(f(((cz % REPEAT) + REPEAT) % REPEAT) + f(salt * 0.317));
|
|
49
|
+
if (hashCell(f(hx + f(2.9)), f(hz + f(2.9))) >= kept)
|
|
50
|
+
continue;
|
|
51
|
+
const ox = hashCell(f(hx + f(1.3)), f(hz + f(1.3)));
|
|
52
|
+
const oz = hashCell(f(hx + f(7.9)), f(hz + f(7.9)));
|
|
53
|
+
const centreX = (cx + INSET + ox * (1 - 2 * INSET)) * size;
|
|
54
|
+
const centreZ = (cz + INSET + oz * (1 - 2 * INSET)) * size;
|
|
55
|
+
const reach = size * REACH * Math.exp((hashCell(f(hx + f(4.1)), f(hz + f(4.1))) - 0.5) * SIZE_SPREAD);
|
|
56
|
+
const d = Math.hypot(x - centreX, z - centreZ);
|
|
57
|
+
if (d > reach * (1 + LOBES + BULGE + FRAY))
|
|
58
|
+
continue;
|
|
59
|
+
if (d <= reach * (1 - LOBES - BULGE - FRAY))
|
|
60
|
+
return true;
|
|
61
|
+
if (edgeAt(x, z, (x - centreX) / d, (z - centreZ) / d, hashCell(f(hx + f(5.3)), f(hz + f(5.3))), hashCell(f(hx + f(6.7)), f(hz + f(6.7)))) * reach >= d)
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* How far a colony's edge is from its middle in a direction (`nx`, `nz`, of length one), as a share of its
|
|
69
|
+
* reach, its lobes and bulge turned by its own two numbers (`a`, `b`, 0..1), frayed by the place itself.
|
|
70
|
+
*/
|
|
71
|
+
export function edgeAt(x, z, nx, nz, a, b) {
|
|
72
|
+
const lobes = 2 * (nx * Math.cos(a * 6.2832) + nz * Math.sin(a * 6.2832)) ** 2 - 1;
|
|
73
|
+
const bulge = nx * Math.cos(b * 6.2832) + nz * Math.sin(b * 6.2832);
|
|
74
|
+
const fray = hashCell(f(x * FRAY_SCALE), f(z * FRAY_SCALE)) * 2 - 1;
|
|
75
|
+
return 1 + LOBES * lobes + BULGE * bulge + FRAY * fray;
|
|
76
|
+
}
|
|
77
|
+
/** The share of the ground a member's colonies cover for a chance `kept`, over a fixed spread of places. */
|
|
78
|
+
function coverFor(size, kept, salt) {
|
|
79
|
+
const n = 96;
|
|
80
|
+
let hit = 0;
|
|
81
|
+
// (Places on a grid 2.37 squares apart, over 96 by 96 of them: far more squares than any colony touches twice.)
|
|
82
|
+
for (let j = 0; j < n; j++)
|
|
83
|
+
for (let i = 0; i < n; i++)
|
|
84
|
+
if (inColony((i * 2.37 + 0.11) * size, (j * 2.37 + 0.53) * size, size, kept, salt))
|
|
85
|
+
hit++;
|
|
86
|
+
return hit / (n * n);
|
|
87
|
+
}
|
|
88
|
+
/** The most of the ground the `j`th member's colonies can cover: every square with one. About 0.6. */
|
|
89
|
+
export function mostCover(j, size = 1) {
|
|
90
|
+
return coverFor(size, 1.01, memberSalt(j));
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Each member's chance that a square has a colony, so that the member takes its share of the stand: a member
|
|
94
|
+
* has the ground its colonies cover that no member before it has, so it needs its share of what is left.
|
|
95
|
+
* Worked out by halving on the twin itself. Throws on shares that cannot be had: more than the whole stand
|
|
96
|
+
* between them, or more of what is left than a member's colonies can cover.
|
|
97
|
+
*/
|
|
98
|
+
export function mixChances(mix) {
|
|
99
|
+
// (Some 70 ms a member: once for each mix a page asks about.)
|
|
100
|
+
const key = JSON.stringify(mix.members.map((m) => [m.share, m.patchSize, m.chance ?? null]));
|
|
101
|
+
const known = worked.get(key);
|
|
102
|
+
if (known)
|
|
103
|
+
return known.slice();
|
|
104
|
+
let left = 1;
|
|
105
|
+
const chances = mix.members.map((m, j) => {
|
|
106
|
+
if (!(m.share >= 0) || !(m.patchSize > 0))
|
|
107
|
+
throw new Error(`A mix's member wants a share of 0 or more and a patch size over 0, not ${m.share} and ${m.patchSize}`);
|
|
108
|
+
const want = m.share / left;
|
|
109
|
+
const most = mostCover(j, m.patchSize);
|
|
110
|
+
if (left - m.share < -1e-9)
|
|
111
|
+
throw new Error(`The members of a mix take more than the whole stand`);
|
|
112
|
+
if (want > most)
|
|
113
|
+
throw new Error(`A member can take at most ${Math.round(most * 100)}% of what the members before it leave; this one wants ${Math.round(want * 100)}%`);
|
|
114
|
+
left -= m.share;
|
|
115
|
+
if (m.chance !== undefined)
|
|
116
|
+
return Math.min(1.01, Math.max(0, m.chance));
|
|
117
|
+
if (want <= 0)
|
|
118
|
+
return 0;
|
|
119
|
+
let lo = 0;
|
|
120
|
+
let hi = 1.01;
|
|
121
|
+
for (let k = 0; k < 14; k++) {
|
|
122
|
+
const mid = (lo + hi) / 2;
|
|
123
|
+
if (coverFor(m.patchSize, mid, memberSalt(j)) < want)
|
|
124
|
+
lo = mid;
|
|
125
|
+
else
|
|
126
|
+
hi = mid;
|
|
127
|
+
}
|
|
128
|
+
return (lo + hi) / 2;
|
|
129
|
+
});
|
|
130
|
+
worked.set(key, chances);
|
|
131
|
+
return chances.slice();
|
|
132
|
+
}
|
|
133
|
+
/** The chances worked out so far, by their members' shares and sizes. */
|
|
134
|
+
const worked = new Map();
|
|
135
|
+
/** Which grass of a mix grows at a place: the twin of what `mixedMap` says there. */
|
|
136
|
+
export function mixAt(mix, chances, x, z) {
|
|
137
|
+
for (let j = 0; j < mix.members.length; j++) {
|
|
138
|
+
const m = mix.members[j];
|
|
139
|
+
if (chances[j] > 0 && inColony(x, z, m.patchSize, chances[j], memberSalt(j)))
|
|
140
|
+
return m.species;
|
|
141
|
+
}
|
|
142
|
+
return mix.species;
|
|
143
|
+
}
|
|
144
|
+
//# sourceMappingURL=mixshare.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mixshare.js","sourceRoot":"","sources":["../src/mixshare.ts"],"names":[],"mappings":"AAAA,0GAA0G;AAC1G,6GAA6G;AAC7G,EAAE;AACF,4GAA4G;AAC5G,2GAA2G;AAC3G,+GAA+G;AAC/G,yGAAyG;AACzG,0GAA0G;AA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SAAS,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC;YAAE,OAAO,CAAC,CAAC,OAAO,CAAC;IACjG,CAAC;IACD,OAAO,GAAG,CAAC,OAAO,CAAC;AACrB,CAAC","sourcesContent":["// A mix's arithmetic, with no three.js in it: where each of a mix's grasses grows, as plain numbers, so a\n// test can run it and a host can ask it (the shaders' half is `mixedMap` in mix.ts, kept in step with this).\n//\n// No stand of grass nobody mows is one grass. One grass is the stand's body (the mix's lead) and the others\n// grow in patches in it, each in patches of its own size: sheep's fescue in tufts a stride across in a red\n// fescue, Yorkshire fog in drifts a few strides across in a meadow. A patch is a colony grown out from where a\n// seed landed or a runner rooted, roughly round (as the library's own patches are, `Species.patchKind`):\n// the ground is squared off at a member's patch size, each square has at most one colony somewhere in its\n// middle, of a size drawn so that most are about the patch size and a few half or half again as big, and\n// whether a square has one at all goes by a chance worked out so that the member takes its share of the\n// stand. Where colonies of two members overlap, the one listed first has the place.\n\nimport { hashCell } from \"./rank.ts\";\n\n/** One of a mix's grasses after its lead: its row in the species table (or `NO_GRASS`, 255, for bare ground), its share of the stand, how far across its patches are (m). */\nexport interface MixMember {\n species: number;\n share: number;\n patchSize: number;\n /**\n * The chance that a square of its has a colony, if the host knows it already: from a twin of this\n * arithmetic elsewhere (a physics that plays the same patches, say), so both have the very same\n * colonies and not two numbers a rounding apart. Left out: worked out here from `share` (`mixChances`).\n */\n chance?: number;\n}\n\n/** A stand of several grasses: where the map says `species` (the lead), its members take their shares of the ground in patches. */\nexport interface GrassMix {\n species: number;\n members: MixMember[];\n}\n\n/** A colony's reach as a share of its square, at its middle size; and how much the sizes spread (its exponent's span). */\nconst REACH = 0.5;\nconst SIZE_SPREAD = 0.8;\n/** Where in its square a colony stands: from this share in from each side, over the rest. */\nconst INSET = 0.15;\n/** Squares hash their numbers within a repeat of this many: the hash loses its evenness on large ones. */\nconst REPEAT = 1024;\n/**\n * A colony is not a disc: its edge goes in and out round it (two lobes and a bulge, each turned its own\n * way: shares of its reach), and plant by plant at its edge some stand in and some out (`FRAY`, a share of\n * its reach either way), as a patch grown from runners and seed has a ragged edge.\n */\nconst LOBES = 0.2;\nconst BULGE = 0.12;\nconst FRAY = 0.16;\n/** The scale of the fray's noise: finer than a plant's spacing, so it is a plant's own. */\nconst FRAY_SCALE = 29.7;\n\nconst f = Math.fround;\n\n/** Salts that keep each member's squares apart from the others': the shaders' are the same. */\nexport function memberSalt(j: number): number {\n return 11 + j * 17;\n}\n\n/**\n * Whether a place is in one of a member's colonies, given the chance that a square has one (`kept`): the\n * twin of the shaders' `inColony` (mix.ts). The shaders' numbers are 32-bit; these are rounded to them where\n * the hash reads them, which is where a difference would move a colony.\n */\nexport function inColony(x: number, z: number, size: number, kept: number, salt: number): boolean {\n const gx = Math.floor(x / size);\n const gz = Math.floor(z / size);\n for (let dz = -1; dz <= 1; dz++) {\n for (let dx = -1; dx <= 1; dx++) {\n const cx = gx + dx;\n const cz = gz + dz;\n const hx = f(f(((cx % REPEAT) + REPEAT) % REPEAT) + f(salt * 0.731));\n const hz = f(f(((cz % REPEAT) + REPEAT) % REPEAT) + f(salt * 0.317));\n if (hashCell(f(hx + f(2.9)), f(hz + f(2.9))) >= kept) continue;\n const ox = hashCell(f(hx + f(1.3)), f(hz + f(1.3)));\n const oz = hashCell(f(hx + f(7.9)), f(hz + f(7.9)));\n const centreX = (cx + INSET + ox * (1 - 2 * INSET)) * size;\n const centreZ = (cz + INSET + oz * (1 - 2 * INSET)) * size;\n const reach = size * REACH * Math.exp((hashCell(f(hx + f(4.1)), f(hz + f(4.1))) - 0.5) * SIZE_SPREAD);\n const d = Math.hypot(x - centreX, z - centreZ);\n if (d > reach * (1 + LOBES + BULGE + FRAY)) continue;\n if (d <= reach * (1 - LOBES - BULGE - FRAY)) return true;\n if (edgeAt(x, z, (x - centreX) / d, (z - centreZ) / d, hashCell(f(hx + f(5.3)), f(hz + f(5.3))), hashCell(f(hx + f(6.7)), f(hz + f(6.7)))) * reach >= d) return true;\n }\n }\n return false;\n}\n\n/**\n * How far a colony's edge is from its middle in a direction (`nx`, `nz`, of length one), as a share of its\n * reach, its lobes and bulge turned by its own two numbers (`a`, `b`, 0..1), frayed by the place itself.\n */\nexport function edgeAt(x: number, z: number, nx: number, nz: number, a: number, b: number): number {\n const lobes = 2 * (nx * Math.cos(a * 6.2832) + nz * Math.sin(a * 6.2832)) ** 2 - 1;\n const bulge = nx * Math.cos(b * 6.2832) + nz * Math.sin(b * 6.2832);\n const fray = hashCell(f(x * FRAY_SCALE), f(z * FRAY_SCALE)) * 2 - 1;\n return 1 + LOBES * lobes + BULGE * bulge + FRAY * fray;\n}\n\n/** The share of the ground a member's colonies cover for a chance `kept`, over a fixed spread of places. */\nfunction coverFor(size: number, kept: number, salt: number): number {\n const n = 96;\n let hit = 0;\n // (Places on a grid 2.37 squares apart, over 96 by 96 of them: far more squares than any colony touches twice.)\n for (let j = 0; j < n; j++) for (let i = 0; i < n; i++) if (inColony((i * 2.37 + 0.11) * size, (j * 2.37 + 0.53) * size, size, kept, salt)) hit++;\n return hit / (n * n);\n}\n\n/** The most of the ground the `j`th member's colonies can cover: every square with one. About 0.6. */\nexport function mostCover(j: number, size = 1): number {\n return coverFor(size, 1.01, memberSalt(j));\n}\n\n/**\n * Each member's chance that a square has a colony, so that the member takes its share of the stand: a member\n * has the ground its colonies cover that no member before it has, so it needs its share of what is left.\n * Worked out by halving on the twin itself. Throws on shares that cannot be had: more than the whole stand\n * between them, or more of what is left than a member's colonies can cover.\n */\nexport function mixChances(mix: GrassMix): number[] {\n // (Some 70 ms a member: once for each mix a page asks about.)\n const key = JSON.stringify(mix.members.map((m) => [m.share, m.patchSize, m.chance ?? null]));\n const known = worked.get(key);\n if (known) return known.slice();\n let left = 1;\n const chances = mix.members.map((m, j) => {\n if (!(m.share >= 0) || !(m.patchSize > 0)) throw new Error(`A mix's member wants a share of 0 or more and a patch size over 0, not ${m.share} and ${m.patchSize}`);\n const want = m.share / left;\n const most = mostCover(j, m.patchSize);\n if (left - m.share < -1e-9) throw new Error(`The members of a mix take more than the whole stand`);\n if (want > most) throw new Error(`A member can take at most ${Math.round(most * 100)}% of what the members before it leave; this one wants ${Math.round(want * 100)}%`);\n left -= m.share;\n if (m.chance !== undefined) return Math.min(1.01, Math.max(0, m.chance));\n if (want <= 0) return 0;\n let lo = 0;\n let hi = 1.01;\n for (let k = 0; k < 14; k++) {\n const mid = (lo + hi) / 2;\n if (coverFor(m.patchSize, mid, memberSalt(j)) < want) lo = mid;\n else hi = mid;\n }\n return (lo + hi) / 2;\n });\n worked.set(key, chances);\n return chances.slice();\n}\n\n/** The chances worked out so far, by their members' shares and sizes. */\nconst worked = new Map<string, number[]>();\n\n/** Which grass of a mix grows at a place: the twin of what `mixedMap` says there. */\nexport function mixAt(mix: GrassMix, chances: readonly number[], x: number, z: number): number {\n for (let j = 0; j < mix.members.length; j++) {\n const m = mix.members[j];\n if (chances[j] > 0 && inColony(x, z, m.patchSize, chances[j], memberSalt(j))) return m.species;\n }\n return mix.species;\n}\n"]}
|
package/lib/noise.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"noise.d.ts","sourceRoot":"","sources":["../src/noise.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AAgCtC,+EAA+E;AAC/E,wBAAgB,gBAAgB,IAAI,KAAK,CAAC,WAAW,CAapD"}
|