webgpu-trees 0.0.0-stage → 0.2.0
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 +1547 -2
- package/assets/SOURCES.md +263 -0
- package/assets/bark/alder.albedo.avif +0 -0
- package/assets/bark/alder.normal.avif +0 -0
- package/assets/bark/aleppoPine.albedo.avif +0 -0
- package/assets/bark/aleppoPine.normal.avif +0 -0
- package/assets/bark/ash.albedo.avif +0 -0
- package/assets/bark/ash.normal.avif +0 -0
- package/assets/bark/aspen.albedo.avif +0 -0
- package/assets/bark/aspen.normal.avif +0 -0
- package/assets/bark/beech.albedo.avif +0 -0
- package/assets/bark/beech.normal.avif +0 -0
- package/assets/bark/birch.albedo.avif +0 -0
- package/assets/bark/birch.normal.avif +0 -0
- package/assets/bark/birchFoot.albedo.avif +0 -0
- package/assets/bark/birchFoot.normal.avif +0 -0
- package/assets/bark/corsicanPine.albedo.avif +0 -0
- package/assets/bark/corsicanPine.normal.avif +0 -0
- package/assets/bark/cypress.albedo.avif +0 -0
- package/assets/bark/cypress.normal.avif +0 -0
- package/assets/bark/douglas.albedo.avif +0 -0
- package/assets/bark/douglas.normal.avif +0 -0
- package/assets/bark/eucalyptus.albedo.avif +0 -0
- package/assets/bark/eucalyptus.normal.avif +0 -0
- package/assets/bark/eucalyptusUpper.albedo.avif +0 -0
- package/assets/bark/eucalyptusUpper.normal.avif +0 -0
- package/assets/bark/fibrous.albedo.avif +0 -0
- package/assets/bark/fibrous.normal.avif +0 -0
- package/assets/bark/hemlock.albedo.avif +0 -0
- package/assets/bark/hemlock.normal.avif +0 -0
- package/assets/bark/hornbeam.albedo.avif +0 -0
- package/assets/bark/hornbeam.normal.avif +0 -0
- package/assets/bark/larch.albedo.avif +0 -0
- package/assets/bark/larch.normal.avif +0 -0
- package/assets/bark/lime.albedo.avif +0 -0
- package/assets/bark/lime.normal.avif +0 -0
- package/assets/bark/liveOak.albedo.avif +0 -0
- package/assets/bark/liveOak.normal.avif +0 -0
- package/assets/bark/magnolia.albedo.avif +0 -0
- package/assets/bark/magnolia.normal.avif +0 -0
- package/assets/bark/maple.albedo.avif +0 -0
- package/assets/bark/maple.normal.avif +0 -0
- package/assets/bark/montereyPine.albedo.avif +0 -0
- package/assets/bark/montereyPine.normal.avif +0 -0
- package/assets/bark/norMaple.albedo.avif +0 -0
- package/assets/bark/norMaple.normal.avif +0 -0
- package/assets/bark/oak.albedo.avif +0 -0
- package/assets/bark/oak.normal.avif +0 -0
- package/assets/bark/palmLattice.albedo.avif +0 -0
- package/assets/bark/palmLattice.normal.avif +0 -0
- package/assets/bark/palmPineapple.albedo.avif +0 -0
- package/assets/bark/palmPineapple.normal.avif +0 -0
- package/assets/bark/palmRings.albedo.avif +0 -0
- package/assets/bark/palmRings.normal.avif +0 -0
- package/assets/bark/pine.albedo.avif +0 -0
- package/assets/bark/pine.normal.avif +0 -0
- package/assets/bark/pineFlakes.albedo.avif +0 -0
- package/assets/bark/pineFlakes.normal.avif +0 -0
- package/assets/bark/plane.albedo.avif +0 -0
- package/assets/bark/plane.normal.avif +0 -0
- package/assets/bark/poplar.albedo.avif +0 -0
- package/assets/bark/poplar.normal.avif +0 -0
- package/assets/bark/redAlder.albedo.avif +0 -0
- package/assets/bark/redAlder.normal.avif +0 -0
- package/assets/bark/redOak.albedo.avif +0 -0
- package/assets/bark/redOak.normal.avif +0 -0
- package/assets/bark/ridged.albedo.avif +0 -0
- package/assets/bark/ridged.normal.avif +0 -0
- package/assets/bark/sitkaSpruce.albedo.avif +0 -0
- package/assets/bark/sitkaSpruce.normal.avif +0 -0
- package/assets/bark/spruce.albedo.avif +0 -0
- package/assets/bark/spruce.normal.avif +0 -0
- package/assets/bark/stonePine.albedo.avif +0 -0
- package/assets/bark/stonePine.normal.avif +0 -0
- package/assets/bark/sweetgum.albedo.avif +0 -0
- package/assets/bark/sweetgum.normal.avif +0 -0
- package/assets/bark/sycMaple.albedo.avif +0 -0
- package/assets/bark/sycMaple.normal.avif +0 -0
- package/assets/bark/torreyPine.albedo.avif +0 -0
- package/assets/bark/torreyPine.normal.avif +0 -0
- package/assets/bark/whitePine.albedo.avif +0 -0
- package/assets/bark/whitePine.normal.avif +0 -0
- package/assets/bark/whiteSpruce.albedo.avif +0 -0
- package/assets/bark/whiteSpruce.normal.avif +0 -0
- package/assets/bark/whiteWillow.albedo.avif +0 -0
- package/assets/bark/whiteWillow.normal.avif +0 -0
- package/assets/bark/willow.albedo.avif +0 -0
- package/assets/bark/willow.normal.avif +0 -0
- package/assets/leaves/alder.albedo.avif +0 -0
- package/assets/leaves/alder.normal.avif +0 -0
- package/assets/leaves/ash.albedo.avif +0 -0
- package/assets/leaves/ash.normal.avif +0 -0
- package/assets/leaves/aspen.albedo.avif +0 -0
- package/assets/leaves/aspen.normal.avif +0 -0
- package/assets/leaves/beech.albedo.avif +0 -0
- package/assets/leaves/beech.normal.avif +0 -0
- package/assets/leaves/birch.albedo.avif +0 -0
- package/assets/leaves/birch.normal.avif +0 -0
- package/assets/leaves/blackthorn.albedo.avif +0 -0
- package/assets/leaves/blackthorn.normal.avif +0 -0
- package/assets/leaves/blade.albedo.avif +0 -0
- package/assets/leaves/blade.normal.avif +0 -0
- package/assets/leaves/broomSprig.albedo.avif +0 -0
- package/assets/leaves/broomSprig.normal.avif +0 -0
- package/assets/leaves/corsicanShoot.albedo.avif +0 -0
- package/assets/leaves/corsicanShoot.normal.avif +0 -0
- package/assets/leaves/cypress.albedo.avif +0 -0
- package/assets/leaves/cypress.normal.avif +0 -0
- package/assets/leaves/cypressPad.albedo.avif +0 -0
- package/assets/leaves/cypressPad.normal.avif +0 -0
- package/assets/leaves/deadFronds.albedo.avif +0 -0
- package/assets/leaves/deadFronds.normal.avif +0 -0
- package/assets/leaves/deltoid.albedo.avif +0 -0
- package/assets/leaves/deltoid.normal.avif +0 -0
- package/assets/leaves/douglasShoot.albedo.avif +0 -0
- package/assets/leaves/douglasShoot.normal.avif +0 -0
- package/assets/leaves/elderSprig.albedo.avif +0 -0
- package/assets/leaves/elderSprig.normal.avif +0 -0
- package/assets/leaves/elliptic.albedo.avif +0 -0
- package/assets/leaves/elliptic.normal.avif +0 -0
- package/assets/leaves/eucalyptus.albedo.avif +0 -0
- package/assets/leaves/eucalyptus.normal.avif +0 -0
- package/assets/leaves/fan.albedo.avif +0 -0
- package/assets/leaves/fan.normal.avif +0 -0
- package/assets/leaves/fanB.albedo.avif +0 -0
- package/assets/leaves/fanB.normal.avif +0 -0
- package/assets/leaves/fir.albedo.avif +0 -0
- package/assets/leaves/fir.normal.avif +0 -0
- package/assets/leaves/frond.albedo.avif +0 -0
- package/assets/leaves/frond.normal.avif +0 -0
- package/assets/leaves/gorse.albedo.avif +0 -0
- package/assets/leaves/gorse.normal.avif +0 -0
- package/assets/leaves/hawthorn.albedo.avif +0 -0
- package/assets/leaves/hawthorn.normal.avif +0 -0
- package/assets/leaves/hemlockShoot.albedo.avif +0 -0
- package/assets/leaves/hemlockShoot.normal.avif +0 -0
- package/assets/leaves/hornbeam.albedo.avif +0 -0
- package/assets/leaves/hornbeam.normal.avif +0 -0
- package/assets/leaves/lance.albedo.avif +0 -0
- package/assets/leaves/lance.normal.avif +0 -0
- package/assets/leaves/larchShoot.albedo.avif +0 -0
- package/assets/leaves/larchShoot.normal.avif +0 -0
- package/assets/leaves/lime.albedo.avif +0 -0
- package/assets/leaves/lime.normal.avif +0 -0
- package/assets/leaves/liveOak.albedo.avif +0 -0
- package/assets/leaves/liveOak.normal.avif +0 -0
- package/assets/leaves/londonPlane.albedo.avif +0 -0
- package/assets/leaves/londonPlane.normal.avif +0 -0
- package/assets/leaves/magnolia.albedo.avif +0 -0
- package/assets/leaves/magnolia.normal.avif +0 -0
- package/assets/leaves/maple.albedo.avif +0 -0
- package/assets/leaves/maple.normal.avif +0 -0
- package/assets/leaves/norMaple.albedo.avif +0 -0
- package/assets/leaves/norMaple.normal.avif +0 -0
- package/assets/leaves/oak.albedo.avif +0 -0
- package/assets/leaves/oak.normal.avif +0 -0
- package/assets/leaves/paintFan.albedo.avif +0 -0
- package/assets/leaves/paintFan.normal.avif +0 -0
- package/assets/leaves/paintFrond.albedo.avif +0 -0
- package/assets/leaves/paintFrond.normal.avif +0 -0
- package/assets/leaves/pine.albedo.avif +0 -0
- package/assets/leaves/pine.normal.avif +0 -0
- package/assets/leaves/pineClumpDark.albedo.avif +0 -0
- package/assets/leaves/pineClumpDark.normal.avif +0 -0
- package/assets/leaves/pineClumpLight.albedo.avif +0 -0
- package/assets/leaves/pineClumpLight.normal.avif +0 -0
- package/assets/leaves/poplar.albedo.avif +0 -0
- package/assets/leaves/poplar.normal.avif +0 -0
- package/assets/leaves/queenFrond.albedo.avif +0 -0
- package/assets/leaves/queenFrond.normal.avif +0 -0
- package/assets/leaves/redAlder.albedo.avif +0 -0
- package/assets/leaves/redAlder.normal.avif +0 -0
- package/assets/leaves/redOak.albedo.avif +0 -0
- package/assets/leaves/redOak.normal.avif +0 -0
- package/assets/leaves/round.albedo.avif +0 -0
- package/assets/leaves/round.normal.avif +0 -0
- package/assets/leaves/scale.albedo.avif +0 -0
- package/assets/leaves/scale.normal.avif +0 -0
- package/assets/leaves/scotsPineClump.albedo.avif +0 -0
- package/assets/leaves/scotsPineClump.normal.avif +0 -0
- package/assets/leaves/seaBuckthornSprig.albedo.avif +0 -0
- package/assets/leaves/seaBuckthornSprig.normal.avif +0 -0
- package/assets/leaves/serrate.albedo.avif +0 -0
- package/assets/leaves/serrate.normal.avif +0 -0
- package/assets/leaves/sitkaShoot.albedo.avif +0 -0
- package/assets/leaves/sitkaShoot.normal.avif +0 -0
- package/assets/leaves/stonePineCanopy.albedo.avif +0 -0
- package/assets/leaves/stonePineCanopy.normal.avif +0 -0
- package/assets/leaves/stonePineCushion.albedo.avif +0 -0
- package/assets/leaves/stonePineCushion.normal.avif +0 -0
- package/assets/leaves/sweetgum.albedo.avif +0 -0
- package/assets/leaves/sweetgum.normal.avif +0 -0
- package/assets/leaves/sycamore.albedo.avif +0 -0
- package/assets/leaves/sycamore.normal.avif +0 -0
- package/assets/leaves/torreyPine.albedo.avif +0 -0
- package/assets/leaves/torreyPine.normal.avif +0 -0
- package/assets/leaves/whitePine.albedo.avif +0 -0
- package/assets/leaves/whitePine.normal.avif +0 -0
- package/assets/leaves/whiteSpruceShoot.albedo.avif +0 -0
- package/assets/leaves/whiteSpruceShoot.normal.avif +0 -0
- package/assets/leaves/whiteWillow.albedo.avif +0 -0
- package/assets/leaves/whiteWillow.normal.avif +0 -0
- package/assets/leaves/willow.albedo.avif +0 -0
- package/assets/leaves/willow.normal.avif +0 -0
- package/assets/marks/marks.json +894 -0
- package/assets/marks/painterly.avif +0 -0
- package/assets/marks/sheets.avif +0 -0
- package/assets/scans.json +6406 -0
- package/lib/age.d.ts +36 -0
- package/lib/age.d.ts.map +1 -0
- package/lib/age.js +170 -0
- package/lib/age.js.map +1 -0
- package/lib/atmosphere.d.ts +64 -0
- package/lib/atmosphere.d.ts.map +1 -0
- package/lib/atmosphere.js +260 -0
- package/lib/atmosphere.js.map +1 -0
- package/lib/dabs.d.ts +4 -0
- package/lib/dabs.d.ts.map +1 -0
- package/lib/dabs.js +77 -0
- package/lib/dabs.js.map +1 -0
- package/lib/engine.d.ts +211 -0
- package/lib/engine.d.ts.map +1 -0
- package/lib/engine.js +3808 -0
- package/lib/engine.js.map +1 -0
- package/lib/genetics.d.ts +129 -0
- package/lib/genetics.d.ts.map +1 -0
- package/lib/genetics.js +721 -0
- package/lib/genetics.js.map +1 -0
- package/lib/geometry.d.ts +237 -0
- package/lib/geometry.d.ts.map +1 -0
- package/lib/geometry.js +1944 -0
- package/lib/geometry.js.map +1 -0
- package/lib/grow.d.ts +83 -0
- package/lib/grow.d.ts.map +1 -0
- package/lib/grow.js +3851 -0
- package/lib/grow.js.map +1 -0
- package/lib/hiz.d.ts +74 -0
- package/lib/hiz.d.ts.map +1 -0
- package/lib/hiz.js +161 -0
- package/lib/hiz.js.map +1 -0
- package/lib/impostor.d.ts +106 -0
- package/lib/impostor.d.ts.map +1 -0
- package/lib/impostor.js +450 -0
- package/lib/impostor.js.map +1 -0
- package/lib/index.d.ts +17 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +16 -0
- package/lib/index.js.map +1 -0
- package/lib/leaves.d.ts +30 -0
- package/lib/leaves.d.ts.map +1 -0
- package/lib/leaves.js +829 -0
- package/lib/leaves.js.map +1 -0
- package/lib/light.d.ts +110 -0
- package/lib/light.d.ts.map +1 -0
- package/lib/light.js +430 -0
- package/lib/light.js.map +1 -0
- package/lib/lobes.d.ts +25 -0
- package/lib/lobes.d.ts.map +1 -0
- package/lib/lobes.js +151 -0
- package/lib/lobes.js.map +1 -0
- package/lib/marks.d.ts +63 -0
- package/lib/marks.d.ts.map +1 -0
- package/lib/marks.js +553 -0
- package/lib/marks.js.map +1 -0
- package/lib/mips.d.ts +42 -0
- package/lib/mips.d.ts.map +1 -0
- package/lib/mips.js +220 -0
- package/lib/mips.js.map +1 -0
- package/lib/paintedMarks.d.ts +21 -0
- package/lib/paintedMarks.d.ts.map +1 -0
- package/lib/paintedMarks.js +53 -0
- package/lib/paintedMarks.js.map +1 -0
- package/lib/palm.d.ts +162 -0
- package/lib/palm.d.ts.map +1 -0
- package/lib/palm.js +779 -0
- package/lib/palm.js.map +1 -0
- package/lib/palmAtlas.d.ts +79 -0
- package/lib/palmAtlas.d.ts.map +1 -0
- package/lib/palmAtlas.js +335 -0
- package/lib/palmAtlas.js.map +1 -0
- package/lib/palmGeometry.d.ts +41 -0
- package/lib/palmGeometry.d.ts.map +1 -0
- package/lib/palmGeometry.js +309 -0
- package/lib/palmGeometry.js.map +1 -0
- package/lib/phenology.d.ts +21 -0
- package/lib/phenology.d.ts.map +1 -0
- package/lib/phenology.js +168 -0
- package/lib/phenology.js.map +1 -0
- package/lib/random.d.ts +34 -0
- package/lib/random.d.ts.map +1 -0
- package/lib/random.js +92 -0
- package/lib/random.js.map +1 -0
- package/lib/scans.d.ts +232 -0
- package/lib/scans.d.ts.map +1 -0
- package/lib/scans.js +397 -0
- package/lib/scans.js.map +1 -0
- package/lib/scatter.d.ts +70 -0
- package/lib/scatter.d.ts.map +1 -0
- package/lib/scatter.js +186 -0
- package/lib/scatter.js.map +1 -0
- package/lib/species.d.ts +369 -0
- package/lib/species.d.ts.map +1 -0
- package/lib/species.js +2978 -0
- package/lib/species.js.map +1 -0
- package/lib/sprays.d.ts +112 -0
- package/lib/sprays.d.ts.map +1 -0
- package/lib/sprays.js +1137 -0
- package/lib/sprays.js.map +1 -0
- package/lib/stand.d.ts +52 -0
- package/lib/stand.d.ts.map +1 -0
- package/lib/stand.js +279 -0
- package/lib/stand.js.map +1 -0
- package/lib/styles.d.ts +135 -0
- package/lib/styles.d.ts.map +1 -0
- package/lib/styles.js +79 -0
- package/lib/styles.js.map +1 -0
- package/lib/tree.d.ts +134 -0
- package/lib/tree.d.ts.map +1 -0
- package/lib/tree.js +57 -0
- package/lib/tree.js.map +1 -0
- package/lib/variants.d.ts +157 -0
- package/lib/variants.d.ts.map +1 -0
- package/lib/variants.js +532 -0
- package/lib/variants.js.map +1 -0
- package/lib/visibility.d.ts +105 -0
- package/lib/visibility.d.ts.map +1 -0
- package/lib/visibility.js +242 -0
- package/lib/visibility.js.map +1 -0
- package/package.json +62 -3
package/lib/palm.js
ADDED
|
@@ -0,0 +1,779 @@
|
|
|
1
|
+
// Palms, grown as palms: one stem from one growing tip, and a crown of a few dozen huge leaves.
|
|
2
|
+
//
|
|
3
|
+
// A palm is a monocot. It does not branch: its single stem grows from one tip and is about as thick at its
|
|
4
|
+
// top as near its foot (a fan palm's swells at its foot), and it carries the record of every leaf it has
|
|
5
|
+
// shed (a Canary palm's diamond lattice of leaf bases, a fan palm's rings). Its crown is its leaves, set
|
|
6
|
+
// round that tip one after another by the golden angle (137.5 degrees), each standing as its age has it: the
|
|
7
|
+
// unopened spear upright in the middle, young leaves rising, mature ones arching out, old ones drooping, and
|
|
8
|
+
// dead ones hanging against the stem (a Washingtonia's petticoat) until they fall or are cut.
|
|
9
|
+
//
|
|
10
|
+
// So a palm is not grown as the other trees are (grow.ts, a skeleton of branches hung with clumps). Its
|
|
11
|
+
// leaves are laid out here as data the drawing reads directly: each frond its rachis (a curve), the frame of
|
|
12
|
+
// its leaf along it, its length and width, its age and colour; a feather palm's leaflets in two rows along
|
|
13
|
+
// its rachis, folded up in a V (a Canary palm's stiff ones) or in several planes (a queen palm's soft
|
|
14
|
+
// plumose ones), and a fan palm's pleated fan at the end of its long stalk, its segments split and drooping
|
|
15
|
+
// at their tips. And what it is pruned to: on a course a Canary palm is mostly "pineapple cut" (its old leaf
|
|
16
|
+
// bases trimmed into a ball under the crown), a fan palm skinned clean, its dead skirt taken off.
|
|
17
|
+
//
|
|
18
|
+
// It is still a GrownTree (tree.ts): its stem and its fronds' rachises are the skeleton, and clumps strung
|
|
19
|
+
// along its leaves stand for them where the rest of the library needs clumps (its box of light, its lobes,
|
|
20
|
+
// its shade on the ground). And it keeps to its envelope: its height, its crown's radius and base, which are
|
|
21
|
+
// what a ball meets.
|
|
22
|
+
//
|
|
23
|
+
// Plain arithmetic, no three: the tests read it as it is.
|
|
24
|
+
import { Random } from "./random.js";
|
|
25
|
+
const DEG = Math.PI / 180;
|
|
26
|
+
/** The golden angle: each leaf of a palm's crown stands this far round from the one before it. */
|
|
27
|
+
export const GOLDEN_ANGLE = Math.PI * (3 - Math.sqrt(5));
|
|
28
|
+
export const PALM_LEAVES = ["feather", "fan"];
|
|
29
|
+
export const PRUNINGS = ["natural", "skirt", "skinned", "pineapple"];
|
|
30
|
+
export const FROND_CLASSES = ["spear", "young", "mature", "old", "dead"];
|
|
31
|
+
/** Which picture a frond, a fan or a skirt is drawn with (palmAtlas.ts lays them out). */
|
|
32
|
+
export const PALM_CELL = { feather: 0, queen: 1, skirt: 2, fan: 3, fanB: 4, fanFar: 5 };
|
|
33
|
+
export const STEM_BARK = 0;
|
|
34
|
+
export const STEM_PINEAPPLE = 2;
|
|
35
|
+
export const STEM_BOOTS = 3;
|
|
36
|
+
/**
|
|
37
|
+
* How far a skirt stands out from its stem's surface at a share `k` of the way down it (0 its top, 1 its foot):
|
|
38
|
+
* a rounded shoulder tucked in under the crown, widest a tenth of the way down, then tapering steadily, a
|
|
39
|
+
* carrot's, to its narrow foot.
|
|
40
|
+
*/
|
|
41
|
+
export function skirtOut(sk, k) {
|
|
42
|
+
const shoulder = 0.35 + 0.65 * Math.min(1, k / 0.1) * (2 - Math.min(1, k / 0.1));
|
|
43
|
+
const taper = Math.max(0, (k - 0.1) / 0.9);
|
|
44
|
+
return shoulder * (sk.outTop + (sk.outBottom - sk.outTop) * Math.pow(taper, 1.15));
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* How weathered a skirt's dead leaves are at a share `k` of the way down it, `tall` metres long: 0 freshly dead
|
|
48
|
+
* tan (its top metre or two: all of a skirt cut back short, the top tenth or so of a wild one), 1 old silver-grey.
|
|
49
|
+
*/
|
|
50
|
+
export function skirtWeathered(k, tall) {
|
|
51
|
+
const t = Math.min(1, Math.max(0, (k * tall - 0.6) / 1.5));
|
|
52
|
+
return t * t * (3 - 2 * t);
|
|
53
|
+
}
|
|
54
|
+
const FORMS = {
|
|
55
|
+
// (A Canary palm's leaves: arching, 3–6 m, leaflets to 40 cm each side in a V; the young near upright, the
|
|
56
|
+
// mature out level and arching, the old down to 100–130° from upright: MORPHOLOGY.md.)
|
|
57
|
+
feather: { reach: 1.02, width: 0.14, bare: 0.16, fold: 30 * DEG, arch: 62 * DEG, rise: [80, 58, 18, -32], knob: 0.22 },
|
|
58
|
+
// (A fan palm's: a long stalk, a blade at its end; held up and out, 20–60° from upright, old ones
|
|
59
|
+
// drooping, the dead hanging straight down.)
|
|
60
|
+
// (A blade 0.6–1.35 m across on a leaf 2–2.5 m long, its stalk about half of it (W. robusta; W. filifera's
|
|
61
|
+
// twice as long, its blade 1–1.8 m): MORPHOLOGY.md 23 and 31. The old green leaves hang 30–60 degrees below
|
|
62
|
+
// the level before they die.)
|
|
63
|
+
// (The owner's reference pictures of a course's W. robusta have its head a sunburst of fans held out, not up:
|
|
64
|
+
// its young leaves at 50 degrees over the level, its mature at 15, within the 20–60 degrees from upright of
|
|
65
|
+
// MORPHOLOGY.md 23 for the green crown, at its wide end; their feet down the top 2 m of its stem (SMM), round
|
|
66
|
+
// its collar of boots, not all from its tip.)
|
|
67
|
+
fan: { reach: 1.0, width: 0.31, bare: 0.55, fold: 9 * DEG, arch: 18 * DEG, rise: [84, 50, 15, -48], knob: 0.6 },
|
|
68
|
+
};
|
|
69
|
+
/** A species' palm leaf (feather unless it says fan). */
|
|
70
|
+
export function leafOf(sp) {
|
|
71
|
+
return sp.palmLeaf ?? "feather";
|
|
72
|
+
}
|
|
73
|
+
/** How a species' palms are kept unless a tree says otherwise: its own word, else a feather palm pineapple cut and a fan palm skinned (as on a course). */
|
|
74
|
+
export function pruningOf(sp, over) {
|
|
75
|
+
return over ?? sp.pruning ?? (leafOf(sp) === "fan" ? "skinned" : "pineapple");
|
|
76
|
+
}
|
|
77
|
+
/** Its elevation at its foot (radians) for its age, 0 the youngest to 1 the oldest green leaf. */
|
|
78
|
+
function riseAt(form, age) {
|
|
79
|
+
const [spear, young, mature, old] = form.rise;
|
|
80
|
+
const a = Math.min(1, Math.max(0, age));
|
|
81
|
+
const d = a < 0.15 ? spear + (young - spear) * (a / 0.15) : a < 0.6 ? young + (mature - young) * ((a - 0.15) / 0.45) : mature + (old - mature) * ((a - 0.6) / 0.4);
|
|
82
|
+
return d * DEG;
|
|
83
|
+
}
|
|
84
|
+
function classOf(age, spear) {
|
|
85
|
+
if (spear)
|
|
86
|
+
return "spear";
|
|
87
|
+
if (age > 1)
|
|
88
|
+
return "dead";
|
|
89
|
+
return age < 0.2 ? "young" : age < 0.62 ? "mature" : "old";
|
|
90
|
+
}
|
|
91
|
+
const norm = (v) => {
|
|
92
|
+
const l = Math.hypot(v[0], v[1], v[2]) || 1;
|
|
93
|
+
return [v[0] / l, v[1] / l, v[2] / l];
|
|
94
|
+
};
|
|
95
|
+
const cross = (a, b) => [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]];
|
|
96
|
+
/** `v` turned by `ang` about the unit axis `k` (Rodrigues). */
|
|
97
|
+
function rotate(v, k, ang) {
|
|
98
|
+
const c = Math.cos(ang);
|
|
99
|
+
const s = Math.sin(ang);
|
|
100
|
+
const kv = cross(k, v);
|
|
101
|
+
const d = k[0] * v[0] + k[1] * v[1] + k[2] * v[2];
|
|
102
|
+
return [v[0] * c + kv[0] * s + k[0] * d * (1 - c), v[1] * c + kv[1] * s + k[1] * d * (1 - c), v[2] * c + kv[2] * s + k[2] * d * (1 - c)];
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* A skinned fan palm's head less deep than this many of its radii may have its hanging green leaves cut
|
|
106
|
+
* (`growPalm`'s fit), at this cost to the fit for each share of them cut.
|
|
107
|
+
*/
|
|
108
|
+
const PALM_HANG_DEEP = 1.4;
|
|
109
|
+
const PALM_CUT_COST = 0.6;
|
|
110
|
+
/**
|
|
111
|
+
* A palm's leaves are its kind's size, whatever head a survey hands over: a Mexican fan palm's blade is 0.9–1.5 m
|
|
112
|
+
* across on a stalk of 1.2–1.8 m (UF/IFAS ENH-827; MORPHOLOGY.md 23), on a palm of 7 m as on one of 30. Fitted to
|
|
113
|
+
* its head alone, a head 1.4 m round (a skinned course palm's, much of it stalks lidar does not see) had leaves a
|
|
114
|
+
* third of its specimen's, a feather duster of small fans, and a head 4.7 m round leaves half as long again. So
|
|
115
|
+
* the fit keeps its leaves within PALM_LEAF_BAND of its specimen's (as its specimen's head grows them; a young
|
|
116
|
+
* palm's a little smaller, by its height to PALM_LEAF_YOUNG), at PALM_LEAF_COST by the square of how many e-folds
|
|
117
|
+
* past it, and fits a narrow head by holding them up (PALM_RAISE: each green leaf that share of the way from its
|
|
118
|
+
* rise to PALM_RAISE_TO, its rising ones, arching less), as a narrow head's leaves stand, at PALM_RAISE_COST by the square of the
|
|
119
|
+
* share raised: so a narrow head is a little of both, its leaves somewhat shorter and somewhat raised, and
|
|
120
|
+
* neither a feather duster of small fans nor a tight brush of full ones.
|
|
121
|
+
*/
|
|
122
|
+
const PALM_LEAF_BAND = 1.2;
|
|
123
|
+
const PALM_CUT_NARROW = 0.6;
|
|
124
|
+
const PALM_LEAF_YOUNG = 0.25;
|
|
125
|
+
const PALM_LEAF_COST = 6;
|
|
126
|
+
const PALM_RAISE = [0, 0.3, 0.55, 0.75, 0.9];
|
|
127
|
+
const PALM_RAISE_TO = 78 * DEG;
|
|
128
|
+
const PALM_RAISE_COST = 1.2;
|
|
129
|
+
/**
|
|
130
|
+
* A species' leaves' own length (m), by how it is kept: its longest green leaf on its specimen's head, grown from
|
|
131
|
+
* one seed of its own (NATURAL_SEED, so it is the same whichever tree asks first), worked out once a row.
|
|
132
|
+
*/
|
|
133
|
+
const NATURAL = new WeakMap();
|
|
134
|
+
const NATURAL_SEED = 1;
|
|
135
|
+
function naturalLength(sp, pruning) {
|
|
136
|
+
let byPruning = NATURAL.get(sp);
|
|
137
|
+
if (!byPruning)
|
|
138
|
+
NATURAL.set(sp, (byPruning = new Map()));
|
|
139
|
+
let L = byPruning.get(pruning);
|
|
140
|
+
if (L === undefined) {
|
|
141
|
+
const specimen = growPalm(sp, { height: sp.height, crownRadius: sp.crownRadius, crownBase: sp.crownBase, trunkRadius: sp.trunkRadius }, NATURAL_SEED, pruning, true);
|
|
142
|
+
L = 0;
|
|
143
|
+
for (const f of specimen.palm?.fronds ?? [])
|
|
144
|
+
if (f.cls === "young" || f.cls === "mature" || f.cls === "old")
|
|
145
|
+
L = Math.max(L, f.length);
|
|
146
|
+
byPruning.set(pruning, L);
|
|
147
|
+
}
|
|
148
|
+
return L;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* A palm's stem is its kind's girth at any height: a monocot has no secondary growth, so it does not thicken
|
|
152
|
+
* as it grows taller (it reaches its girth before it rises: a Mexican fan palm 0.6 m at its flared foot and
|
|
153
|
+
* 0.2–0.3 m up it, a Canary palm 0.5–1 m, docs/MORPHOLOGY.md 22, 23). A survey's trunk is not measured: the
|
|
154
|
+
* game's is 3 % of a tree's height, a 27 m Mexican fan palm's 1.2 m through, twice its kind's. So a size's
|
|
155
|
+
* trunk is kept within PALM_GIRTH of its species' (its specimen's trunk radius).
|
|
156
|
+
*/
|
|
157
|
+
export const PALM_GIRTH = [0.75, 1.3];
|
|
158
|
+
export function palmGirth(sp, trunkRadius) {
|
|
159
|
+
const own = sp.trunkRadius;
|
|
160
|
+
return Math.min(own * PALM_GIRTH[1], Math.max(own * PALM_GIRTH[0], Number.isFinite(trunkRadius) && trunkRadius > 0 ? trunkRadius : own));
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* A skinned fan palm's collar of boots, below its lowest green leaf's foot: "about 1–3 m deep (roughly 10–25
|
|
164
|
+
* rows of bases) below the lowest green petiole, ending in a fairly clean horizontal line" (docs/MORPHOLOGY.md
|
|
165
|
+
* 23): in metres, whatever the palm's height, BOOTS_PER_M of its height between BOOTS_DEPTH's least and most
|
|
166
|
+
* (a short young palm's the least). Its boots stand out from the stem, the more the nearer the crown, to
|
|
167
|
+
* BOOTS_OUT of the stem just under them at the most, and its crown shaft, its leaves' feet, as little: a
|
|
168
|
+
* collar about as wide as the trunk, not a bulge round it.
|
|
169
|
+
*/
|
|
170
|
+
export const BOOTS_DEPTH = [1.2, 2.2];
|
|
171
|
+
const BOOTS_PER_M = 0.1;
|
|
172
|
+
export const BOOTS_OUT = 1.25;
|
|
173
|
+
/** Points along a frond's rachis: POINTS pieces, the last ones shorter (a frond bends most towards its tip). */
|
|
174
|
+
const POINTS = 14;
|
|
175
|
+
/**
|
|
176
|
+
* Lay a frond out at length `L` from its foot: its rachis arching down from `rise` by `arch` (more towards its
|
|
177
|
+
* tip, and never past hanging), its leaf's frame turning about it by `twist` towards its tip.
|
|
178
|
+
*/
|
|
179
|
+
function layFrond(p, foot, L, form, sp) {
|
|
180
|
+
const ca = Math.cos(p.azimuth);
|
|
181
|
+
const sa = Math.sin(p.azimuth);
|
|
182
|
+
const points = [foot];
|
|
183
|
+
const s = [0];
|
|
184
|
+
const tangent = [];
|
|
185
|
+
const across = [];
|
|
186
|
+
const up = [];
|
|
187
|
+
const hang = -88 * DEG;
|
|
188
|
+
const frame = (e, k) => {
|
|
189
|
+
const t = [Math.cos(e) * ca, Math.sin(e), Math.cos(e) * sa];
|
|
190
|
+
const a0 = [-sa, 0, ca];
|
|
191
|
+
const n0 = cross(a0, t);
|
|
192
|
+
const tw = p.twist * k * k;
|
|
193
|
+
return { t, a: rotate(a0, t, tw), n: rotate(n0, t, tw) };
|
|
194
|
+
};
|
|
195
|
+
let at = foot;
|
|
196
|
+
for (let i = 0; i <= POINTS; i++) {
|
|
197
|
+
const k = i / POINTS;
|
|
198
|
+
const e = Math.max(hang, p.rise - p.arch * k ** 1.5);
|
|
199
|
+
const f = frame(e, k);
|
|
200
|
+
tangent.push(f.t);
|
|
201
|
+
across.push(f.a);
|
|
202
|
+
up.push(f.n);
|
|
203
|
+
if (i < POINTS) {
|
|
204
|
+
const kk = (i + 0.5) / POINTS;
|
|
205
|
+
const em = Math.max(hang, p.rise - p.arch * kk ** 1.5);
|
|
206
|
+
const step = L / POINTS;
|
|
207
|
+
// (A little wander sideways, as a real rachis has.)
|
|
208
|
+
const side = p.wander * Math.sin((i + 1) * 0.9 + p.own * 6) * step;
|
|
209
|
+
at = [at[0] + Math.cos(em) * ca * step - sa * side, at[1] + Math.sin(em) * step, at[2] + Math.cos(em) * sa * step + ca * side];
|
|
210
|
+
points.push(at);
|
|
211
|
+
s.push((i + 1) / POINTS);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
const fr = {
|
|
215
|
+
cls: p.cls,
|
|
216
|
+
age: p.age,
|
|
217
|
+
azimuth: p.azimuth,
|
|
218
|
+
points,
|
|
219
|
+
s,
|
|
220
|
+
tangent,
|
|
221
|
+
across,
|
|
222
|
+
up,
|
|
223
|
+
length: L,
|
|
224
|
+
bare: sp.palmLeaf === "fan" ? form.bare : Math.min(0.5, form.bare * (sp.plumose ? 1.6 : 1)),
|
|
225
|
+
width: L * form.width * (sp.frondWidth ?? 1) * p.widthK,
|
|
226
|
+
fold: p.fold,
|
|
227
|
+
plumose: p.plumose,
|
|
228
|
+
droop: p.droop,
|
|
229
|
+
dead: p.dead,
|
|
230
|
+
tone: p.tone,
|
|
231
|
+
flex: p.flex,
|
|
232
|
+
own: p.own,
|
|
233
|
+
cell: p.cell,
|
|
234
|
+
};
|
|
235
|
+
if (leafOf(sp) === "fan") {
|
|
236
|
+
// The blade at the stalk's end: held tilted up from the stalk's line (a dead one folded down), its stalk
|
|
237
|
+
// running on into it a little way (costapalmate).
|
|
238
|
+
const end = points.length - 1 - Math.round(POINTS * (1 - fr.bare));
|
|
239
|
+
const h = points[Math.max(1, end)];
|
|
240
|
+
const t = tangent[Math.max(1, end)];
|
|
241
|
+
const n = up[Math.max(1, end)];
|
|
242
|
+
const a = across[Math.max(1, end)];
|
|
243
|
+
const tilt = p.cls === "dead" ? -55 * DEG : p.cls === "spear" ? 5 * DEG : 12 * DEG - 26 * DEG * Math.max(0, p.age - 0.5);
|
|
244
|
+
fr.hastula = h;
|
|
245
|
+
fr.bladeDir = rotate(t, a, -tilt);
|
|
246
|
+
// (Each blade turned on its own about its line, held stiffly at whatever angle it opened: seen from below
|
|
247
|
+
// or across the crown, many stand edge-on.)
|
|
248
|
+
fr.bladeUp = rotate(rotate(n, a, -tilt), fr.bladeDir, p.roll);
|
|
249
|
+
}
|
|
250
|
+
return fr;
|
|
251
|
+
}
|
|
252
|
+
/** Every point of a frond's leaf a ball would meet: its rachis, its leaflets' edges, its fan's rim (for the envelope). */
|
|
253
|
+
export function frondSurface(f) {
|
|
254
|
+
const out = [];
|
|
255
|
+
if (f.hastula && f.bladeDir && f.bladeUp) {
|
|
256
|
+
for (let i = 0; i < f.points.length; i++)
|
|
257
|
+
if (f.s[i] <= f.bare + 1e-6)
|
|
258
|
+
out.push(f.points[i]);
|
|
259
|
+
const a = norm(cross(f.bladeUp, f.bladeDir));
|
|
260
|
+
for (let r = 1; r <= 3; r++)
|
|
261
|
+
for (let k = -6; k <= 6; k++) {
|
|
262
|
+
const th = (k / 6) * FAN_SPREAD;
|
|
263
|
+
const p = fanPoint(f, th, r / 3, a, 0);
|
|
264
|
+
out.push(p);
|
|
265
|
+
}
|
|
266
|
+
return out;
|
|
267
|
+
}
|
|
268
|
+
for (let i = 0; i < f.points.length; i++) {
|
|
269
|
+
out.push(f.points[i]);
|
|
270
|
+
if (f.s[i] < f.bare)
|
|
271
|
+
continue;
|
|
272
|
+
const w = f.width * leafletProfile(f.s[i]);
|
|
273
|
+
for (const side of [-1, 1]) {
|
|
274
|
+
const c = Math.cos(f.fold) * w * side;
|
|
275
|
+
const u = Math.sin(f.fold) * w;
|
|
276
|
+
out.push([f.points[i][0] + f.across[i][0] * c + f.up[i][0] * u, f.points[i][1] + f.across[i][1] * c + f.up[i][1] * u, f.points[i][2] + f.across[i][2] * c + f.up[i][2] * u]);
|
|
277
|
+
if (f.plumose > 0) {
|
|
278
|
+
const fd = -0.6 * f.fold - 25 * DEG;
|
|
279
|
+
const c2 = Math.cos(fd) * w * side * 0.9;
|
|
280
|
+
const u2 = Math.sin(fd) * w * 0.9;
|
|
281
|
+
out.push([f.points[i][0] + f.across[i][0] * c2 + f.up[i][0] * u2, f.points[i][1] + f.across[i][1] * c2 + f.up[i][1] * u2, f.points[i][2] + f.across[i][2] * c2 + f.up[i][2] * u2]);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
return out;
|
|
286
|
+
}
|
|
287
|
+
/** How far a feather frond's leaflets reach either side at a share of its length, over their widest: narrow at its foot and tip. */
|
|
288
|
+
export function leafletProfile(s) {
|
|
289
|
+
const k = Math.min(1, Math.max(0, s * 0.97 + 0.02));
|
|
290
|
+
return 0.32 + 0.68 * Math.sqrt(Math.sin(Math.PI * k));
|
|
291
|
+
}
|
|
292
|
+
/** A fan's blade spreads this far either side of its stalk's line (radians): the rest of the round is where the stalk comes in. */
|
|
293
|
+
export const FAN_SPREAD = 150 * DEG;
|
|
294
|
+
/** Where a fan's segments split, as a share of its radius: they droop beyond. */
|
|
295
|
+
export const FAN_SPLIT = 0.5;
|
|
296
|
+
/**
|
|
297
|
+
* A point of a fan's blade: `th` round from its stalk's line, `r` out (0..1 of its radius), pleated by `pleat`
|
|
298
|
+
* (+1 a ridge, -1 a valley, 0 none). Folded up along its costa, its segments drooping past where they split.
|
|
299
|
+
*/
|
|
300
|
+
export function fanPoint(f, th, r, across, pleat) {
|
|
301
|
+
const R = f.width;
|
|
302
|
+
const d = f.bladeDir;
|
|
303
|
+
const n = f.bladeUp;
|
|
304
|
+
const h = f.hastula;
|
|
305
|
+
const c = Math.cos(th);
|
|
306
|
+
const sn = Math.sin(th);
|
|
307
|
+
const dir = [d[0] * c + across[0] * sn, d[1] * c + across[1] * sn, d[2] * c + across[2] * sn];
|
|
308
|
+
// (Folded up either side of the costa, and pleated: each segment a shallow V.)
|
|
309
|
+
const lift = R * r * (Math.sin(f.fold) * Math.abs(sn) + 0.045 * pleat);
|
|
310
|
+
const past = Math.max(0, (r - FAN_SPLIT) / (1 - FAN_SPLIT));
|
|
311
|
+
const droop = R * 0.85 * f.droop * past ** 1.5;
|
|
312
|
+
return [h[0] + dir[0] * R * r + n[0] * lift, h[1] + dir[1] * R * r + n[1] * lift - droop, h[2] + dir[2] * R * r + n[2] * lift];
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* A palm of a species grown to a size (its height, crown radius and base; its trunk's radius at breast
|
|
316
|
+
* height), kept as `pruning` says (else as its species is). The same arguments give the same palm.
|
|
317
|
+
*/
|
|
318
|
+
export function growPalm(sp, size, seed, pruningOver, anyLength = false) {
|
|
319
|
+
const rng = new Random(seed ^ 0x5a1d);
|
|
320
|
+
const leaf = leafOf(sp);
|
|
321
|
+
const form = FORMS[leaf];
|
|
322
|
+
const pruning = pruningOf(sp, pruningOver);
|
|
323
|
+
const { height: H, crownRadius: R, crownBase: base } = size;
|
|
324
|
+
// (Its stem its kind's girth, not the survey's guess: `palmGirth`.)
|
|
325
|
+
const trunkRadius = palmGirth(sp, size.trunkRadius);
|
|
326
|
+
const live = Math.max(3, Math.round(sp.whorl));
|
|
327
|
+
const turn = rng.range(0, 2 * Math.PI);
|
|
328
|
+
const bend = Math.min(1, Math.max(-1, sp.bend));
|
|
329
|
+
// (A queen palm's soft leaves arch further; a stiff one's less: the species' bend, -1 all the way over.)
|
|
330
|
+
const archK = 1 - 0.55 * bend;
|
|
331
|
+
const plumose = sp.plumose ?? 0;
|
|
332
|
+
// ---- The leaves it carries, the youngest first: green, then (as it is kept) dead. ----
|
|
333
|
+
const spears = leaf === "feather" ? 2 : 1;
|
|
334
|
+
const keepDead = pruning === "natural" ? (leaf === "fan" ? 0.35 : 0.3) : pruning === "skirt" ? (leaf === "fan" ? 0.25 : 0.15) : 0;
|
|
335
|
+
const deadCount = Math.round(live * keepDead);
|
|
336
|
+
const plans = [];
|
|
337
|
+
for (let i = 0; i < live + deadCount; i++) {
|
|
338
|
+
const dead = i >= live;
|
|
339
|
+
const age = dead ? 1 + (i - live + 0.5) / Math.max(1, deadCount) * 0.5 : i / Math.max(1, live - 1);
|
|
340
|
+
const cls = classOf(age, !dead && i < spears);
|
|
341
|
+
const own = rng.next();
|
|
342
|
+
const g = rng.gauss();
|
|
343
|
+
let rise = riseAt(form, age) + 4 * DEG * g;
|
|
344
|
+
let arch = form.arch * archK * (cls === "spear" ? 0.08 : cls === "young" ? 0.35 + age * 2 : cls === "mature" ? 0.85 + 0.3 * age : 1.15) * (0.9 + 0.2 * rng.next());
|
|
345
|
+
if (dead) {
|
|
346
|
+
// (A dead leaf hangs from its foot, nearly straight down, against the stem.)
|
|
347
|
+
rise = -(74 + 12 * rng.next()) * DEG;
|
|
348
|
+
arch = 6 * DEG;
|
|
349
|
+
}
|
|
350
|
+
const young = Math.min(1, age / 0.2);
|
|
351
|
+
plans.push({
|
|
352
|
+
cls,
|
|
353
|
+
age,
|
|
354
|
+
azimuth: turn + i * GOLDEN_ANGLE + rng.range(-1, 1) * DEG,
|
|
355
|
+
drop: dead ? form.knob * (1.15 + 0.5 * (age - 1)) : form.knob * Math.pow(Math.min(1, age), 0.9),
|
|
356
|
+
rise,
|
|
357
|
+
arch,
|
|
358
|
+
twist: (cls === "spear" ? 0 : cls === "young" ? 8 : cls === "mature" ? 18 : cls === "old" ? 35 : 70) * DEG * (own < 0.5 ? -1 : 1) * (0.6 + 0.8 * rng.next()),
|
|
359
|
+
lengthK: cls === "spear" ? 0.62 + 0.1 * i : cls === "young" ? 0.78 + 0.22 * young : dead ? 0.92 : 1 - 0.04 * Math.max(0, age - 0.6),
|
|
360
|
+
widthK: cls === "spear" ? 0.12 : cls === "young" ? 0.7 + 0.3 * young : dead ? 0.6 : 1,
|
|
361
|
+
fold: cls === "spear" ? 72 * DEG : dead ? (leaf === "fan" ? 60 * DEG : -55 * DEG) : form.fold * (cls === "young" ? 1.35 : 1) * (0.9 + 0.2 * rng.next()),
|
|
362
|
+
plumose: dead || cls === "spear" ? 0 : plumose,
|
|
363
|
+
droop: leaf === "fan" ? (cls === "young" ? 0.3 : cls === "spear" ? 0 : dead ? 1.4 : 0.8 + 0.5 * Math.max(0, age - 0.5)) * (sp.fanDroop ?? 1) : 0,
|
|
364
|
+
// (A fan palm's freshly dead leaves, a brown tuft under its green: past 1, as a skirt's fresh top is.)
|
|
365
|
+
dead: dead ? (leaf === "fan" ? 1 + 0.06 * rng.next() : 0.85 + 0.15 * rng.next()) : cls === "old" ? Math.max(0, (age - 0.82) * 1.4) : 0,
|
|
366
|
+
tone: cls === "spear" ? 1.3 : cls === "young" ? 1.12 : cls === "old" ? 0.95 : 1,
|
|
367
|
+
flex: cls === "spear" ? 0.12 : cls === "young" ? 0.55 : cls === "mature" ? 1 : dead ? 1.5 : 1.2,
|
|
368
|
+
own,
|
|
369
|
+
cell: leaf === "fan" ? (rng.next() < 0.5 ? PALM_CELL.fan : PALM_CELL.fanB) : plumose > 0 ? PALM_CELL.queen : PALM_CELL.feather,
|
|
370
|
+
wander: 0.04 * sp.crooked,
|
|
371
|
+
roll: leaf === "fan" && !dead && cls !== "spear" ? (rng.next() - 0.5) * 110 * DEG : 0,
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
// (Pruned: a skinned palm loses its dead leaves and those hanging well below the level; a pineapple cut
|
|
375
|
+
// leaves only those above about the level, the classic cut back to "ten and two".)
|
|
376
|
+
const kept = plans.filter((p) => {
|
|
377
|
+
// (A fan palm skinned keeps all its green leaves, the old hanging ones too: only its dead skirt is cut.)
|
|
378
|
+
if (pruning === "skinned")
|
|
379
|
+
return p.cls !== "dead" && (leaf === "fan" || p.rise > -40 * DEG);
|
|
380
|
+
if (pruning === "pineapple")
|
|
381
|
+
return p.cls !== "dead" && p.rise > -6 * DEG;
|
|
382
|
+
return true;
|
|
383
|
+
});
|
|
384
|
+
// ---- The stem's shape: its radius up it (a feather palm's straight, a fan palm's tapering, both swollen at the foot). ----
|
|
385
|
+
const bh = Math.min(1.3, 0.1 * H);
|
|
386
|
+
const flare = 0.18 + 0.55 * (sp.buttress ?? 0);
|
|
387
|
+
const swell = (y) => 1 + flare * Math.exp(-Math.max(0, y) / (0.35 + 0.9 * (sp.buttress ?? 0)));
|
|
388
|
+
const taper = leaf === "fan" ? 0.2 : 0.04;
|
|
389
|
+
const lean = rng.range(0, 2 * Math.PI);
|
|
390
|
+
const bowK = 0.035 * sp.crooked;
|
|
391
|
+
// ---- How long its leaves are, and how far they droop, to fill its crown. ----
|
|
392
|
+
const stemR = (y, heartY) => {
|
|
393
|
+
const u = Math.min(1, Math.max(0, y / Math.max(heartY, 0.01)));
|
|
394
|
+
return ((trunkRadius * swell(y)) / swell(bh)) * (1 - taper * u);
|
|
395
|
+
};
|
|
396
|
+
const stemAt = (y, heartY) => {
|
|
397
|
+
const u = Math.min(1, Math.max(0, y / Math.max(heartY, 0.01)));
|
|
398
|
+
const b = bowK * heartY * (1 - (1 - u) * (1 - u));
|
|
399
|
+
return [b * Math.cos(lean), b * Math.sin(lean)];
|
|
400
|
+
};
|
|
401
|
+
// (Its leaves' feet round the stem's top: the youngest at the heart, the older lower, round the crown shaft.)
|
|
402
|
+
const footOf = (p, L, heartY) => {
|
|
403
|
+
const y = heartY - p.drop * L;
|
|
404
|
+
const [cx, cz] = stemAt(y, heartY);
|
|
405
|
+
const r = stemR(y, heartY) * (p.cls === "spear" ? 0.2 : 0.95);
|
|
406
|
+
return [cx + Math.cos(p.azimuth) * r, y, cz + Math.sin(p.azimuth) * r];
|
|
407
|
+
};
|
|
408
|
+
// (A crown wider than it is deep has its leaves held flatter; a deep narrow one, its leaves hanging further:
|
|
409
|
+
// `k` scales how far they arch over, and drops the old ones' feet' elevation with it.)
|
|
410
|
+
const drooped = (p, k) => p.cls === "dead" || p.cls === "spear" ? p : { ...p, arch: p.arch * k, rise: Math.max(-70 * DEG, p.rise - (k - 1) * 22 * DEG * Math.max(0, p.age - 0.35)) };
|
|
411
|
+
/**
|
|
412
|
+
* Its head closed in (PALM_RAISE): each green leaf over the level `u` of the way from its rise to PALM_RAISE_TO,
|
|
413
|
+
* arching less: a narrow head's leaves stand up. Its hanging ones hang as they do (swung up through the level,
|
|
414
|
+
* they reached further out; swung down, they hung apart from the rest, a second head under the first).
|
|
415
|
+
*/
|
|
416
|
+
const raised = (p, u) => {
|
|
417
|
+
if (u <= 0 || p.cls === "dead" || p.cls === "spear" || p.rise < 0)
|
|
418
|
+
return p;
|
|
419
|
+
return { ...p, rise: p.rise + Math.max(0, PALM_RAISE_TO - p.rise) * u, arch: p.arch * (1 - 0.5 * u) };
|
|
420
|
+
};
|
|
421
|
+
const r0 = 0.9 * trunkRadius;
|
|
422
|
+
// (Where its bowed stem's top is, about: the crown stands over it.)
|
|
423
|
+
const [bx, bz] = stemAt(0.82 * H, 0.82 * H);
|
|
424
|
+
/** Its leaves laid at length L with the heart at 0: how high over it they reach, how low under it the green go, how far out. */
|
|
425
|
+
const extent = (plans, L) => {
|
|
426
|
+
let top = 0;
|
|
427
|
+
let low = Infinity;
|
|
428
|
+
let reach = 0;
|
|
429
|
+
for (const p of plans) {
|
|
430
|
+
const f = layFrond(p, [bx + Math.cos(p.azimuth) * r0, -p.drop * L, bz + Math.sin(p.azimuth) * r0], L * p.lengthK, form, sp);
|
|
431
|
+
for (const q of frondSurface(f)) {
|
|
432
|
+
top = Math.max(top, q[1]);
|
|
433
|
+
reach = Math.max(reach, Math.hypot(q[0], q[2]));
|
|
434
|
+
if (f.cls !== "dead")
|
|
435
|
+
low = Math.min(low, q[1]);
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
return { top, low, reach };
|
|
439
|
+
};
|
|
440
|
+
/**
|
|
441
|
+
* Linear precompute for a candidate frond set: since `layFrond` and `frondSurface` scale strictly linearly
|
|
442
|
+
* in `L` around `[bx + cos(az)*r0, 0, bz + sin(az)*r0]`, laying fronds once at unit `L = 1` makes the 18-step
|
|
443
|
+
* binary search ~15x faster with identical geometry.
|
|
444
|
+
*/
|
|
445
|
+
const rulerOf = (plans) => {
|
|
446
|
+
let top1 = 0;
|
|
447
|
+
let low1 = Infinity;
|
|
448
|
+
const fxArr = [];
|
|
449
|
+
const fzArr = [];
|
|
450
|
+
const uxArr = [];
|
|
451
|
+
const uzArr = [];
|
|
452
|
+
for (const p of plans) {
|
|
453
|
+
const fx = bx + Math.cos(p.azimuth) * r0;
|
|
454
|
+
const fz = bz + Math.sin(p.azimuth) * r0;
|
|
455
|
+
const f1 = layFrond(p, [0, -p.drop, 0], p.lengthK, form, sp);
|
|
456
|
+
for (const q of frondSurface(f1)) {
|
|
457
|
+
top1 = Math.max(top1, q[1]);
|
|
458
|
+
if (f1.cls !== "dead")
|
|
459
|
+
low1 = Math.min(low1, q[1]);
|
|
460
|
+
fxArr.push(fx);
|
|
461
|
+
fzArr.push(fz);
|
|
462
|
+
uxArr.push(q[0]);
|
|
463
|
+
uzArr.push(q[2]);
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
const fx64 = Float64Array.from(fxArr);
|
|
467
|
+
const fz64 = Float64Array.from(fzArr);
|
|
468
|
+
const ux64 = Float64Array.from(uxArr);
|
|
469
|
+
const uz64 = Float64Array.from(uzArr);
|
|
470
|
+
const nPts = fx64.length;
|
|
471
|
+
return (L) => {
|
|
472
|
+
let reach2 = 0;
|
|
473
|
+
for (let i = 0; i < nPts; i++) {
|
|
474
|
+
const rx = fx64[i] + ux64[i] * L;
|
|
475
|
+
const rz = fz64[i] + uz64[i] * L;
|
|
476
|
+
const d2 = rx * rx + rz * rz;
|
|
477
|
+
if (d2 > reach2)
|
|
478
|
+
reach2 = d2;
|
|
479
|
+
}
|
|
480
|
+
return { top: top1 * L, low: low1 === Infinity ? Infinity : low1 * L, reach: Math.sqrt(reach2) };
|
|
481
|
+
};
|
|
482
|
+
};
|
|
483
|
+
/**
|
|
484
|
+
* The best leaves for a head (its radius, height and base): how long, and which of them, at what droop and raise.
|
|
485
|
+
* `natural` is its leaves' own length (m), to keep near; 0, any.
|
|
486
|
+
*/
|
|
487
|
+
const fitHead = (R, H, base, natural) => {
|
|
488
|
+
/** The longest its leaves may be at a droop: no wider than its crown, no deeper, its heart well over the ground. */
|
|
489
|
+
const longest = (measure) => {
|
|
490
|
+
const fits = (L) => {
|
|
491
|
+
const e = measure(L);
|
|
492
|
+
const heartY = H - e.top;
|
|
493
|
+
return e.reach <= R && heartY + e.low >= base - 0.02 && heartY > 0.35 * H;
|
|
494
|
+
};
|
|
495
|
+
let lo = 0.05;
|
|
496
|
+
let hi = natural > 0 ? Math.min(R * form.reach * 1.6, natural * PALM_LEAF_BAND) : R * form.reach * 1.6;
|
|
497
|
+
if (fits(hi))
|
|
498
|
+
return hi;
|
|
499
|
+
for (let k = 0; k < (leaf === "fan" ? 13 : 18); k++) {
|
|
500
|
+
const mid = 0.5 * (lo + hi);
|
|
501
|
+
if (fits(mid))
|
|
502
|
+
lo = mid;
|
|
503
|
+
else
|
|
504
|
+
hi = mid;
|
|
505
|
+
}
|
|
506
|
+
return lo;
|
|
507
|
+
};
|
|
508
|
+
let best = { score: Infinity, L: 0, plans: kept };
|
|
509
|
+
const depthBox = Math.max(0.01, H - base);
|
|
510
|
+
// (A skinned fan palm's crew may cut its green leaves that hang well below the level too, to "nine and three"
|
|
511
|
+
// (ANSI A300: none with its tip above the level). So a head too shallow for its leaves to hang (a survey's
|
|
512
|
+
// crown base high under its top: less deep than PALM_HANG_DEEP of its radius) may keep its leaves their
|
|
513
|
+
// length, out to its crown's radius, and lose its lowest instead (down to "ten and two" at the most), as
|
|
514
|
+
// the fit finds best. A head deep enough keeps them all.)
|
|
515
|
+
// (So too a head much narrower than its kind's leaves reach (under PALM_CUT_NARROW of its specimen's): one cut
|
|
516
|
+
// hard, its hanging leaves gone and the rest standing, as an over-pruned course palm's is.)
|
|
517
|
+
const shallow = (H - base) / R;
|
|
518
|
+
const narrow = natural > 0 && R < PALM_CUT_NARROW * sp.crownRadius;
|
|
519
|
+
const cuts = leaf !== "fan" || pruning !== "skinned" || (shallow >= PALM_HANG_DEEP && !narrow) ? [-90] : [-90, -30, -12, 5];
|
|
520
|
+
for (const cut of cuts) {
|
|
521
|
+
const green = cut <= -90 ? kept : kept.filter((p) => p.cls === "spear" || p.rise > cut * DEG);
|
|
522
|
+
if (green.length < 0.5 * kept.length)
|
|
523
|
+
continue;
|
|
524
|
+
const lost = 1 - green.length / kept.length;
|
|
525
|
+
for (const u of PALM_RAISE) {
|
|
526
|
+
// (Held up only when its leaves at their own pose come out short of their kind's: a narrow head.)
|
|
527
|
+
if (u > 0 && (natural <= 0 || best.L * PALM_LEAF_BAND >= natural))
|
|
528
|
+
break;
|
|
529
|
+
for (const k of leaf === "fan" ? [0.5, 0.75, 1, 1.3, 1.75] : pruning === "pineapple" ? [0.5, 0.7, 0.85, 1, 1.15, 1.3] : [0.45, 0.65, 0.85, 1, 1.2, 1.45, 1.8]) {
|
|
530
|
+
const plans = green.map((p) => raised(drooped(p, k), u));
|
|
531
|
+
const measure = rulerOf(plans);
|
|
532
|
+
const L = longest(measure);
|
|
533
|
+
const e = measure(L);
|
|
534
|
+
const heartY = H - e.top;
|
|
535
|
+
const fillR = e.reach / R;
|
|
536
|
+
const fillD = (H - (heartY + e.low)) / depthBox;
|
|
537
|
+
// (Leaves shorter or longer than their kind's, past the band, cost as much as a head unfilled.)
|
|
538
|
+
const off = natural > 0 ? Math.max(0, Math.abs(Math.log(L / natural)) - Math.log(PALM_LEAF_BAND)) : 0;
|
|
539
|
+
const score = 2 * (1 - fillR) + (1 - fillD) + 0.3 * Math.abs(Math.log(k)) + PALM_CUT_COST * lost + PALM_LEAF_COST * off * off + PALM_RAISE_COST * u * u;
|
|
540
|
+
if (score < best.score)
|
|
541
|
+
best = { score, L, plans };
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
return best;
|
|
546
|
+
};
|
|
547
|
+
// (Its leaves' own length: as its specimen's head grows them, a young palm's a little smaller.)
|
|
548
|
+
const natural = anyLength ? 0 : naturalLength(sp, pruning) * Math.min(1, H / sp.height) ** PALM_LEAF_YOUNG;
|
|
549
|
+
const best = fitHead(R, H, base, natural);
|
|
550
|
+
// (Laid on the stem as it is, and held in if the stem's own bow and girth carry it past its crown's radius.)
|
|
551
|
+
let L = best.L;
|
|
552
|
+
let heartY = H - extent(best.plans, L).top;
|
|
553
|
+
let fronds = best.plans.map((p) => layFrond(p, footOf(p, L, heartY), L * p.lengthK, form, sp));
|
|
554
|
+
for (let pass = 0; pass < 4; pass++) {
|
|
555
|
+
let reach = 0;
|
|
556
|
+
let top = 0;
|
|
557
|
+
for (const f of fronds)
|
|
558
|
+
for (const q of frondSurface(f)) {
|
|
559
|
+
reach = Math.max(reach, Math.hypot(q[0], q[2]));
|
|
560
|
+
top = Math.max(top, q[1]);
|
|
561
|
+
}
|
|
562
|
+
if (reach <= R && top <= H + 1e-3)
|
|
563
|
+
break;
|
|
564
|
+
L *= Math.min(R / reach, (H - heartY) / Math.max(1e-3, top - heartY)) * 0.995;
|
|
565
|
+
heartY = H - extent(best.plans, L).top;
|
|
566
|
+
fronds = best.plans.map((p) => layFrond(p, footOf(p, L, heartY), L * p.lengthK, form, sp));
|
|
567
|
+
}
|
|
568
|
+
// ---- What it is kept as, on its stem. ----
|
|
569
|
+
const knobLow = heartY - form.knob * L;
|
|
570
|
+
const rTop = stemR(heartY, heartY);
|
|
571
|
+
let ball = null;
|
|
572
|
+
let boots = null;
|
|
573
|
+
let skirt = null;
|
|
574
|
+
if (pruning === "pineapple") {
|
|
575
|
+
// (A ball of trimmed leaf bases, widest a third of the way down: 1.3–1.6 times the trunk across and 1.2–2
|
|
576
|
+
// times it tall (docs/MORPHOLOGY.md 22), so about one and a half times the stem across, and as tall again
|
|
577
|
+
// as it is wide or a little more.)
|
|
578
|
+
const radius = Math.min(1.5 * stemR(Math.max(0, heartY - 1.5), heartY), 0.4 * R);
|
|
579
|
+
const tall = Math.min(2.1 * radius, 0.45 * heartY);
|
|
580
|
+
ball = { y0: heartY - tall, y1: heartY + 0.15 * radius, radius };
|
|
581
|
+
}
|
|
582
|
+
else if (leaf === "fan" && pruning === "skinned") {
|
|
583
|
+
// (Leaf bases still firm on the stem are left when it is skinned: a collar of boots under the green,
|
|
584
|
+
// `BOOTS_DEPTH` metres below its lowest green leaf's foot.)
|
|
585
|
+
const deep = Math.min(BOOTS_DEPTH[1], Math.max(BOOTS_DEPTH[0], BOOTS_PER_M * H));
|
|
586
|
+
boots = { y0: Math.max(0.3 * heartY, knobLow - deep), y1: heartY };
|
|
587
|
+
}
|
|
588
|
+
else if (pruning === "skinned") {
|
|
589
|
+
// (A skinned feather palm keeps its firm leaf bases under the green as well: no deeper than a fan palm's.)
|
|
590
|
+
boots = { y0: Math.max(0.25 * heartY, knobLow - Math.min(BOOTS_DEPTH[1], 0.12 * H)), y1: heartY };
|
|
591
|
+
}
|
|
592
|
+
else {
|
|
593
|
+
// (Unskinned: old leaf bases all down the crown shaft and a way below it.)
|
|
594
|
+
boots = { y0: Math.max(0.25 * heartY, knobLow - (leaf === "fan" ? 0.25 : 0.12) * H), y1: heartY };
|
|
595
|
+
}
|
|
596
|
+
if (leaf === "fan" && (pruning === "natural" || pruning === "skirt")) {
|
|
597
|
+
// (A fan palm's dead leaves hang in a skirt from under its green ones: in the wild to near the ground; cut back, a few metres.)
|
|
598
|
+
// (From a little into the crown, under its hanging green leaves, so they overlap its fresh brown top.)
|
|
599
|
+
const top = knobLow + 0.04 * L;
|
|
600
|
+
const longest = pruning === "natural" ? Math.max(0.15, sp.skirt ?? 0.6) * top : Math.min(0.3 * top, 0.9 * L);
|
|
601
|
+
// (Carrot-shaped: its shoulder flared about as wide as its lowest green leaves reach, the dead leaves hanging
|
|
602
|
+
// from their whole length, then tapering steadily to a narrow ragged foot: `skirtOut`.)
|
|
603
|
+
const outTop = Math.min(0.6 * L + 0.1, 0.48 * R);
|
|
604
|
+
skirt = { top, bottom: Math.max(0.4, top - longest), outTop, outBottom: Math.min(0.3 * outTop, 0.15 + 0.03 * L) };
|
|
605
|
+
}
|
|
606
|
+
// ---- The stem, ring by ring, to the top of the crown shaft. ----
|
|
607
|
+
const stem = { x: [], y: [], z: [], radius: [], surface: [] };
|
|
608
|
+
const top = heartY + 0.25 * rTop;
|
|
609
|
+
const ringYs = [0, Math.min(0.12, 0.05 * H), Math.min(0.3, 0.1 * H), Math.min(0.6, 0.15 * H)];
|
|
610
|
+
const shaft = knobLow;
|
|
611
|
+
const along = Math.max(1, Math.ceil((shaft - ringYs[3]) / 0.9));
|
|
612
|
+
for (let k = 1; k <= along; k++)
|
|
613
|
+
ringYs.push(ringYs[3] + ((shaft - ringYs[3]) * k) / along);
|
|
614
|
+
const head = 8;
|
|
615
|
+
for (let k = 1; k <= head; k++)
|
|
616
|
+
ringYs.push(shaft + ((top - shaft) * k) / head);
|
|
617
|
+
if (ball)
|
|
618
|
+
for (let k = 0; k <= 10; k++)
|
|
619
|
+
ringYs.push(ball.y0 + ((ball.y1 - ball.y0) * k) / 10);
|
|
620
|
+
if (boots)
|
|
621
|
+
ringYs.push(boots.y0 - 0.05, boots.y0);
|
|
622
|
+
const ys = [...new Set(ringYs.map((y) => Math.round(y * 1000) / 1000))].filter((y) => y >= 0 && y <= top).sort((a, b) => a - b);
|
|
623
|
+
// (A fan palm's collar, its boots and its crown shaft, no wider than BOOTS_OUT of its stem just under it.)
|
|
624
|
+
const collarMost = leaf === "fan" && pruning !== "pineapple" ? BOOTS_OUT * stemR(boots ? boots.y0 : shaft, heartY) : Infinity;
|
|
625
|
+
for (const y of ys) {
|
|
626
|
+
const [cx, cz] = stemAt(Math.min(y, heartY), heartY);
|
|
627
|
+
let r = stemR(Math.min(y, heartY), heartY);
|
|
628
|
+
let surface = STEM_BARK;
|
|
629
|
+
// (The crown shaft: the leaves' bases wrapping the stem's top, swelling, rounding over at the heart; a fan
|
|
630
|
+
// palm's its collar of split boots on, a little wider than the stem under it: BOOTS_OUT.)
|
|
631
|
+
if (y > shaft) {
|
|
632
|
+
const u = (y - shaft) / Math.max(1e-3, top - shaft);
|
|
633
|
+
r *= (1 + (leaf === "fan" ? 0.22 : 0.35) * Math.sin(Math.PI * Math.min(1, u * 0.85 + 0.15))) * Math.sqrt(Math.max(0.04, 1 - Math.pow(Math.max(0, u - 0.55) / 0.45, 2)));
|
|
634
|
+
surface = STEM_BOOTS;
|
|
635
|
+
}
|
|
636
|
+
if (boots && y >= boots.y0 && y <= boots.y1) {
|
|
637
|
+
surface = STEM_BOOTS;
|
|
638
|
+
// (Boots stand out from the stem, the more the nearer the crown: a fan palm's collar of split leaf bases
|
|
639
|
+
// under its green, a fifth wider than its stem under them at the top.)
|
|
640
|
+
if (y <= shaft)
|
|
641
|
+
r *= 1.08 + (leaf === "fan" ? 0.14 * Math.pow(Math.max(0, (y - boots.y0) / Math.max(1e-3, shaft - boots.y0)), 1.5) : 0);
|
|
642
|
+
}
|
|
643
|
+
if (y >= (boots ? boots.y0 : shaft))
|
|
644
|
+
r = Math.min(r, collarMost);
|
|
645
|
+
if (ball && y >= ball.y0 - 1e-6 && y <= ball.y1 + 1e-6) {
|
|
646
|
+
const u = (y - ball.y0) / (ball.y1 - ball.y0);
|
|
647
|
+
// (Widest a third of the way down from its top, tapering into the stem below and into the leaves above.)
|
|
648
|
+
const shape = u < 0.67 ? Math.sin((u / 0.67) * Math.PI * 0.5) ** 0.7 : Math.cos(((u - 0.67) / 0.33) * Math.PI * 0.42);
|
|
649
|
+
r = Math.max(r, rTop + (ball.radius - rTop) * shape);
|
|
650
|
+
surface = STEM_PINEAPPLE;
|
|
651
|
+
}
|
|
652
|
+
stem.x.push(cx);
|
|
653
|
+
stem.y.push(y);
|
|
654
|
+
stem.z.push(cz);
|
|
655
|
+
stem.radius.push(r);
|
|
656
|
+
stem.surface.push(surface);
|
|
657
|
+
}
|
|
658
|
+
// ---- The skeleton: the stem's nodes, and each frond's rachis off the node at its foot. ----
|
|
659
|
+
const sx = [];
|
|
660
|
+
const sy = [];
|
|
661
|
+
const sz = [];
|
|
662
|
+
const sr = [];
|
|
663
|
+
const parent = [];
|
|
664
|
+
const order = [];
|
|
665
|
+
const limb = [];
|
|
666
|
+
const alongArr = [];
|
|
667
|
+
let lastStem = -1;
|
|
668
|
+
// (The skeleton's stem the stem's wood, never thicker than below it: its swellings, the crown shaft's and a
|
|
669
|
+
// pineapple's, are its leaf bases, drawn as its surface.)
|
|
670
|
+
let rMin = Infinity;
|
|
671
|
+
for (let k = 0; k < stem.y.length; k++) {
|
|
672
|
+
sx.push(stem.x[k]);
|
|
673
|
+
sy.push(stem.y[k]);
|
|
674
|
+
sz.push(stem.z[k]);
|
|
675
|
+
rMin = Math.min(rMin, Math.max(0.01, stemR(Math.min(stem.y[k], heartY), heartY)));
|
|
676
|
+
sr.push(rMin);
|
|
677
|
+
parent.push(lastStem);
|
|
678
|
+
order.push(0);
|
|
679
|
+
limb.push(0);
|
|
680
|
+
alongArr.push(stem.y[k]);
|
|
681
|
+
lastStem = k;
|
|
682
|
+
}
|
|
683
|
+
const stemNodeAt = (y) => {
|
|
684
|
+
let best = 0;
|
|
685
|
+
for (let k = 0; k < stem.y.length; k++)
|
|
686
|
+
if (Math.abs(stem.y[k] - y) < Math.abs(stem.y[best] - y))
|
|
687
|
+
best = k;
|
|
688
|
+
return best;
|
|
689
|
+
};
|
|
690
|
+
const clumps = { x: [], y: [], z: [], r: [], nx: [], ny: [], nz: [], node: [], depth: [], tx: [], ty: [], tz: [] };
|
|
691
|
+
let leafArea = 0;
|
|
692
|
+
const addClump = (c, r, n, t, node, f) => {
|
|
693
|
+
clumps.x.push(c[0]);
|
|
694
|
+
clumps.y.push(c[1]);
|
|
695
|
+
clumps.z.push(c[2]);
|
|
696
|
+
clumps.r.push(r);
|
|
697
|
+
clumps.nx.push(n[0]);
|
|
698
|
+
clumps.ny.push(n[1]);
|
|
699
|
+
clumps.nz.push(n[2]);
|
|
700
|
+
clumps.node.push(node);
|
|
701
|
+
clumps.depth.push(f.cls === "young" || f.cls === "spear" ? 0.55 : 0.25);
|
|
702
|
+
clumps.tx.push(t[0]);
|
|
703
|
+
clumps.ty.push(t[1]);
|
|
704
|
+
clumps.tz.push(t[2]);
|
|
705
|
+
};
|
|
706
|
+
for (const f of fronds) {
|
|
707
|
+
let prev = stemNodeAt(f.points[0][1]);
|
|
708
|
+
const footNode = sx.length;
|
|
709
|
+
const r0 = Math.min(0.5 * rTop, 0.022 * f.length);
|
|
710
|
+
// (A fan's rachis runs on into its blade as its costa: its skeleton ends at the blade, which its clumps stand for.)
|
|
711
|
+
const end = f.hastula ? f.s.findIndex((x) => x >= f.bare - 1e-6) : f.points.length - 1;
|
|
712
|
+
for (let i = 1; i <= end; i++) {
|
|
713
|
+
const q = f.points[i];
|
|
714
|
+
const node = sx.length;
|
|
715
|
+
sx.push(q[0]);
|
|
716
|
+
sy.push(q[1]);
|
|
717
|
+
sz.push(q[2]);
|
|
718
|
+
sr.push(Math.max(0.006, r0 * (1 - 0.8 * f.s[i])));
|
|
719
|
+
parent.push(prev);
|
|
720
|
+
order.push(1);
|
|
721
|
+
limb.push(footNode);
|
|
722
|
+
alongArr.push(alongArr[prev] + Math.hypot(q[0] - sx[prev], q[1] - sy[prev], q[2] - sz[prev]));
|
|
723
|
+
prev = node;
|
|
724
|
+
if (f.cls === "dead" || f.hastula || f.s[i] < f.bare)
|
|
725
|
+
continue;
|
|
726
|
+
// Clumps strung along its leaf, a leaf's width apart, standing for it where the library needs clumps.
|
|
727
|
+
const pq = f.points[i - 1];
|
|
728
|
+
const chord = norm([q[0] - pq[0], q[1] - pq[1], q[2] - pq[2]]);
|
|
729
|
+
addClump(q, Math.max(0.08, f.width * leafletProfile(f.s[i]) * 0.8), f.up[i], chord, node, f);
|
|
730
|
+
}
|
|
731
|
+
if (f.hastula && f.cls !== "dead") {
|
|
732
|
+
// (A fan's blade: three clumps across it.)
|
|
733
|
+
const a = norm(cross(f.bladeUp, f.bladeDir));
|
|
734
|
+
const h = [sx[prev], sy[prev], sz[prev]];
|
|
735
|
+
const pp = parent[prev];
|
|
736
|
+
const chord = norm([h[0] - sx[pp], h[1] - sy[pp], h[2] - sz[pp]]);
|
|
737
|
+
for (const th of [-0.45 * FAN_SPREAD, 0, 0.45 * FAN_SPREAD]) {
|
|
738
|
+
const c = fanPoint(f, th, 0.5, a, 0);
|
|
739
|
+
addClump(c, Math.max(0.45 * f.width, 1.01 * Math.hypot(c[0] - h[0], c[1] - h[1], c[2] - h[2])), f.bladeUp, chord, prev, f);
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
if (f.cls !== "dead") {
|
|
743
|
+
// (Its leaf's area, one side: a feather's leaflets about two thirds fill the band either side of the
|
|
744
|
+
// rachis; a fan's blade nearly fills its round, less its split tips.)
|
|
745
|
+
leafArea += f.hastula ? 0.75 * (FAN_SPREAD / Math.PI) * Math.PI * f.width ** 2 : 0.62 * 2 * f.width * 0.82 * f.length * (1 - f.bare) * (1 + 0.8 * f.plumose);
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
const n = sx.length;
|
|
749
|
+
const skeleton = {
|
|
750
|
+
count: n,
|
|
751
|
+
x: Float32Array.from(sx),
|
|
752
|
+
y: Float32Array.from(sy),
|
|
753
|
+
z: Float32Array.from(sz),
|
|
754
|
+
radius: Float32Array.from(sr),
|
|
755
|
+
parent: Int32Array.from(parent),
|
|
756
|
+
order: Uint8Array.from(order),
|
|
757
|
+
limb: Int32Array.from(limb),
|
|
758
|
+
along: Float32Array.from(alongArr),
|
|
759
|
+
};
|
|
760
|
+
const cc = clumps.x.length;
|
|
761
|
+
const cl = {
|
|
762
|
+
count: cc,
|
|
763
|
+
x: Float32Array.from(clumps.x),
|
|
764
|
+
y: Float32Array.from(clumps.y),
|
|
765
|
+
z: Float32Array.from(clumps.z),
|
|
766
|
+
radius: Float32Array.from(clumps.r),
|
|
767
|
+
nx: Float32Array.from(clumps.nx),
|
|
768
|
+
ny: Float32Array.from(clumps.ny),
|
|
769
|
+
nz: Float32Array.from(clumps.nz),
|
|
770
|
+
node: Int32Array.from(clumps.node),
|
|
771
|
+
depth: Float32Array.from(clumps.depth),
|
|
772
|
+
tx: Float32Array.from(clumps.tx),
|
|
773
|
+
ty: Float32Array.from(clumps.ty),
|
|
774
|
+
tz: Float32Array.from(clumps.tz),
|
|
775
|
+
};
|
|
776
|
+
const palm = { leaf, pruning, heart: [stemAt(heartY, heartY)[0], heartY, stemAt(heartY, heartY)[1]], fronds, stem, ball, boots, skirt, leafArea };
|
|
777
|
+
return { size, skeleton, clumps: cl, palm, leafArea, ...(sp.buttress ? { buttress: sp.buttress } : {}) };
|
|
778
|
+
}
|
|
779
|
+
//# sourceMappingURL=palm.js.map
|