roamwright 0.61.26 → 0.61.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -1
- package/examples/set-pieces.html +52 -0
- package/examples/set-pieces.js +284 -0
- package/examples/troops.html +56 -0
- package/examples/troops.js +309 -0
- package/geometry/camp-layout.js +150 -0
- package/geometry/cavern-rock.js +309 -0
- package/geometry/cliff-sheets.js +457 -0
- package/geometry/creased-sheet.js +39 -0
- package/geometry/curtain-sheets.js +67 -0
- package/geometry/ice-cliff.js +339 -0
- package/geometry/ice-shards.js +247 -0
- package/geometry/index.js +203 -0
- package/geometry/instances.js +50 -1
- package/geometry/plant-roots.js +115 -0
- package/geometry/primitives.js +4 -0
- package/geometry/rock-sheets.js +259 -0
- package/geometry/strata-rocks.js +4 -3
- package/index.js +6 -469
- package/math/index.js +9 -0
- package/math/scalar.js +3 -1
- package/motion/index.js +100 -0
- package/motion/troop-director.js +482 -0
- package/motion/troop-volleys.js +197 -0
- package/package.json +1 -1
- package/rendering/camp-layout.js +55 -0
- package/rendering/curtain-sheets.js +271 -0
- package/rendering/flame-sources.js +105 -0
- package/rendering/ice-material.js +143 -0
- package/rendering/index.js +201 -0
- package/rendering/rock-materials.js +27 -0
- package/rendering/ruins-fittings.js +110 -17
- package/rendering/troop-director.js +374 -0
- package/rendering/troop-mounts.js +326 -0
- package/rendering/troop-standards.js +259 -0
- package/rendering/troop-volleys.js +143 -0
- package/runtime/index.js +95 -0
- package/runtime/lazy-sets.js +24 -0
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Roamwright's public geometry builders and kits, grouped by subsystem. Re-exported whole from `roamwright`.
|
|
3
|
+
* @module
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// ── Context, math & core geometry ────────────────────────────────────────
|
|
7
|
+
export { GB as GeometryBuilder, geometryOf } from './builder.js';
|
|
8
|
+
export { stillMesh } from './still-mesh.js';
|
|
9
|
+
export { createUnitShapes, createFigureUnitShapes } from './primitives.js';
|
|
10
|
+
|
|
11
|
+
// ── Terrain & land baking ────────────────────────────────────────────────
|
|
12
|
+
export { createLandSheet } from './land-sheet.js';
|
|
13
|
+
export { createLandWaters } from './land-waters.js';
|
|
14
|
+
export { createEarthworks } from './land-earthworks.js';
|
|
15
|
+
export { createDitchedGround } from './land-ditches.js';
|
|
16
|
+
export { createMoundFaces } from './land-mound-faces.js';
|
|
17
|
+
export { createTownGround } from './land-town-ground.js';
|
|
18
|
+
export { createDryBasin } from './land-dry-basin.js';
|
|
19
|
+
export { landEdgeGrid } from './land-edge.js';
|
|
20
|
+
export { rockSheet, sampleRockSheet } from './creased-sheet.js';
|
|
21
|
+
export { OUTCROP_DUST, OUTCROP_SANDSTONE, buildOutcrop, buildTalusApron, outcropReach } from './rock-sheets.js';
|
|
22
|
+
export {
|
|
23
|
+
CAVERN_ROCK_PALETTE,
|
|
24
|
+
CRYSTAL_PALETTE,
|
|
25
|
+
buildCavernCrystal,
|
|
26
|
+
buildCrystalCluster,
|
|
27
|
+
buildRockDome,
|
|
28
|
+
buildRockRoof,
|
|
29
|
+
buildRockWall,
|
|
30
|
+
domeReach,
|
|
31
|
+
} from './cavern-rock.js';
|
|
32
|
+
export { BEDDED_BUTTE_DEFAULTS, ESCARPMENT_CLIFF_DEFAULTS, createBeddedButte, createEscarpmentCliff } from './cliff-sheets.js';
|
|
33
|
+
export {
|
|
34
|
+
ICE_CLIFF_DEFAULTS,
|
|
35
|
+
buildIceCliffSheet,
|
|
36
|
+
buildIceHollow,
|
|
37
|
+
computeGridNormals,
|
|
38
|
+
createIceCliffField,
|
|
39
|
+
emitGridCell,
|
|
40
|
+
iceFacet,
|
|
41
|
+
} from './ice-cliff.js';
|
|
42
|
+
export {
|
|
43
|
+
buildBurstIceBlocks,
|
|
44
|
+
buildFallenIceBlocks,
|
|
45
|
+
buildFrozenFigure,
|
|
46
|
+
buildFrozenFigures,
|
|
47
|
+
buildIceBlock,
|
|
48
|
+
buildPuddleIce,
|
|
49
|
+
} from './ice-shards.js';
|
|
50
|
+
export { ROOT_TIP_SHARE, buildRootTube, growRootBranch, rootRadius } from './plant-roots.js';
|
|
51
|
+
export { planTalusStones } from './strata-talus.js';
|
|
52
|
+
export {
|
|
53
|
+
OUTCROP_SEEDS,
|
|
54
|
+
OUTCROP_SHAPE,
|
|
55
|
+
SCREE_STONE_FORMS,
|
|
56
|
+
WORN_STONE_FOOT,
|
|
57
|
+
WORN_STONE_FORMS,
|
|
58
|
+
beddedOutcrop,
|
|
59
|
+
cragRock,
|
|
60
|
+
createCragLibrary,
|
|
61
|
+
createRockShapes,
|
|
62
|
+
fallenStone,
|
|
63
|
+
flatQuad,
|
|
64
|
+
jointed,
|
|
65
|
+
wornStone,
|
|
66
|
+
} from './strata-rocks.js';
|
|
67
|
+
export { MESA_CLIFF, buildMesaCliff } from './strata-mesa.js';
|
|
68
|
+
export { HILL_RUIN, buildHillRuin } from './ruins-hill.js';
|
|
69
|
+
export { MOUND_RUINS, buildMoundRuins, buildMoundSherds, buildMoundWalls, createMoundRuins } from './ruins-mound.js';
|
|
70
|
+
export { RUBBLE_HEAP, RUBBLE_SCATTER, buildRubbleHeap, createRubbleStone, scatterRubble } from './ruins-rubble.js';
|
|
71
|
+
export { RUIN_WALL, buildRuinWall, coursedWall, tumbleBlock } from './ruins-walls.js';
|
|
72
|
+
export {
|
|
73
|
+
ASHLAR_COURSE,
|
|
74
|
+
COLUMN_DRUM,
|
|
75
|
+
MASONRY_METAL,
|
|
76
|
+
buildAshlarWall,
|
|
77
|
+
buildColumnDrum,
|
|
78
|
+
buildFlagstones,
|
|
79
|
+
buildLampStandGeometry,
|
|
80
|
+
buildWallLanternGeometry,
|
|
81
|
+
} from './ruins-masonry.js';
|
|
82
|
+
export { DEFAULT_SCORCH_PALETTE, addEmberSkin, buildBreachFan, buildRubbleMound } from './ruins-breach.js';
|
|
83
|
+
export { CRATER_PALETTE, buildCraterBowl, buildFallenBoulder, craterDip } from './ruins-crater.js';
|
|
84
|
+
export {
|
|
85
|
+
GROUND_PATCH_DEFAULTS,
|
|
86
|
+
GROUND_PATCH_KINDS,
|
|
87
|
+
buildDrapePebbleGeometry,
|
|
88
|
+
createGroundPatchData,
|
|
89
|
+
drapeGroundPatch,
|
|
90
|
+
scatterPatchBits,
|
|
91
|
+
} from './ground-drape.js';
|
|
92
|
+
export { createShapeBatches, placeInstances } from './instances.js';
|
|
93
|
+
export { planStreamBanks } from './stream-banks.js';
|
|
94
|
+
export { SPRING_COLOURS, SPRING_HEAD, planSpringRocks, planSprings, springFrame, springWetGround } from './stream-springs.js';
|
|
95
|
+
export { planShoreReeds } from './shore-reeds.js';
|
|
96
|
+
export { roadRibbon } from './road-ribbon.js';
|
|
97
|
+
export { bridgeSpanPath, bridgeSpanPaths, planBridgeFrame, planRoadBridges } from './road-bridges.js';
|
|
98
|
+
export {
|
|
99
|
+
AVENUE_CEDAR,
|
|
100
|
+
PAVED_ROAD,
|
|
101
|
+
avenueBoleRadius,
|
|
102
|
+
buildAvenueCedar,
|
|
103
|
+
buildFarRoadPaving,
|
|
104
|
+
buildRoadArch,
|
|
105
|
+
buildRoadMilestones,
|
|
106
|
+
buildRoadPaving,
|
|
107
|
+
planRoadAvenue,
|
|
108
|
+
roadLine,
|
|
109
|
+
} from './paved-road.js';
|
|
110
|
+
export { createFieldSurvey, FIELD_SURVEY, FIELD_USE } from './field-survey.js';
|
|
111
|
+
export { FIELD_BITS, NO_PATH_DISTANCE, createFieldCoverCache, packFieldBits, packSparsePlain } from './field-map.js';
|
|
112
|
+
export {
|
|
113
|
+
DEFAULT_DRIFT_SCALE,
|
|
114
|
+
DEFAULT_FLOWER_DRIFTS,
|
|
115
|
+
DEFAULT_FLOWER_LOOKS,
|
|
116
|
+
FLOWER_KINDS,
|
|
117
|
+
TUFT_SHAPE,
|
|
118
|
+
createFlowerDrift,
|
|
119
|
+
tuftGeometry,
|
|
120
|
+
} from './plant-tuft.js';
|
|
121
|
+
export { LAND_TRAILS, LAND_TRAIL_MARKS, boundsOverlap, createLandTrails, rasterizeTrailMarks } from './land-trails.js';
|
|
122
|
+
export { createIrrigatedFields, IRRIGATED_FIELDS } from './irrigated-fields.js';
|
|
123
|
+
export { DEFAULT_CROP_STANDS, FARM_CROPS, createCropPlacer } from './farm-crops.js';
|
|
124
|
+
export { DRYSTONE_WALL, FIELD_STONE, drystoneStone, planDrystoneWall } from './drystone-wall.js';
|
|
125
|
+
export { DEFAULT_FENCE_STYLE, addFenceRing, buildFenceRing } from './timber-fence.js';
|
|
126
|
+
export { TREE_GROVE, planScatterInstances, planTreeGrove } from './scatter-instances.js';
|
|
127
|
+
export { FARM_BOUNDARIES, planFieldBoundaries } from './farm-boundaries.js';
|
|
128
|
+
export { DEFAULT_FARM_HERDS, FARM_LIFE, herdPlaces, parcelPlaces, planFarmLife, ploughSite } from './farm-life.js';
|
|
129
|
+
export { STOOK, createStook } from './prop-stook.js';
|
|
130
|
+
export { PLOUGH, ploughGear } from './prop-plough.js';
|
|
131
|
+
export { FARM_BARN_DOORS, FARM_HAYSTACK, FARM_STONE_PILE, buildBarnDoors, buildHaystacks, buildStonePile } from './farm-props.js';
|
|
132
|
+
|
|
133
|
+
// ── Settlements, houses, fortifications & interiors ──────────────────────
|
|
134
|
+
export { createHouseKit } from './house-kit.js';
|
|
135
|
+
export { createPooledKit } from './house-kit-pool.js';
|
|
136
|
+
export { layVillage } from './village-layout.js';
|
|
137
|
+
export { TOWN_CELL, districtAt, layTown, rectFree, stampArea, stampDisc, stampLine, stampRect, townPlan } from './town-plan.js';
|
|
138
|
+
export { townLots } from './town-lots.js';
|
|
139
|
+
export { paintTown } from './town-ground.js';
|
|
140
|
+
export { createTownHouses } from './town-houses.js';
|
|
141
|
+
export { ARCADE_BAY, ARCADE_WALK, createTownWorks, townFacing } from './town-works.js';
|
|
142
|
+
export { createTownLights, distantTownLights } from './town-lights.js';
|
|
143
|
+
export { createCourtyardInn } from './town-courtyard-inn.js';
|
|
144
|
+
export { alongRim, createTownGarden } from './town-garden.js';
|
|
145
|
+
export { createGardenPlantShapes, createPlantList, GARDEN_PLANT_LOBES, GARDEN_PLANT_SEEN } from './plant-garden.js';
|
|
146
|
+
export { createWallRuns } from './wall-runs.js';
|
|
147
|
+
export { addBattlement, addMerlonRow, addPortcullis, addRadialMerlons, addRampDeck, addRoundTower, wallGateFrames } from './fort-parts.js';
|
|
148
|
+
export { createGreatWalls, greatGateMouth } from './fort-great-walls.js';
|
|
149
|
+
export { createCityFortification } from './fort-city-walls.js';
|
|
150
|
+
export { buildPortalGateway, portalGatewayLights } from './fort-portal.js';
|
|
151
|
+
export {
|
|
152
|
+
addCrenelRun,
|
|
153
|
+
addDressedSlit,
|
|
154
|
+
buildArchedKeepDoor,
|
|
155
|
+
buildFlaggedWallWalk,
|
|
156
|
+
buildFlaredRoundTower,
|
|
157
|
+
buildKeepCitadel,
|
|
158
|
+
buildKeepTowers,
|
|
159
|
+
} from './fort-keep.js';
|
|
160
|
+
export { buildRingCurtain, buildRingFortification, buildRingGate, buildRingTower } from './fort-ring-wall.js';
|
|
161
|
+
export { buildPolylineWall, buildWallCulverts } from './fort-polyline.js';
|
|
162
|
+
export { buildGateApron, buildGateCauseway } from './fort-gate-approach.js';
|
|
163
|
+
export { createSeawall } from './fort-seawall.js';
|
|
164
|
+
export { TERRACE_DEFAULTS, createTerraceFrame, planTerrace, wallAt } from './fort-terrace-plan.js';
|
|
165
|
+
export { createTerraceWall } from './fort-terrace-wall.js';
|
|
166
|
+
export { createTerraceGates } from './fort-terrace-gates.js';
|
|
167
|
+
export { createRoomKit } from './room-kit.js';
|
|
168
|
+
export { HALL_OLD_STONE_TONE, HALL_STONE_TONE, HALL_WALL_THICKNESS, createStoneHalls } from './room-halls.js';
|
|
169
|
+
|
|
170
|
+
// ── Vessels ──────────────────────────────────────────────────────────────
|
|
171
|
+
export { CRANE_EDGE, HARBOUR_WATERFRONT, craneX, createHarbourKit, quayDeck } from './harbour-kit.js';
|
|
172
|
+
export { createShipKit } from './ship-kit.js';
|
|
173
|
+
export { SHIP_PRESETS } from './ship-presets.js';
|
|
174
|
+
|
|
175
|
+
// ── Figures, animals & fliers ────────────────────────────────────────────
|
|
176
|
+
export { createFigureBuilder } from './figure-body.js';
|
|
177
|
+
export { catBodies, catRig } from './animal-cat-body.js';
|
|
178
|
+
export { FLY_LOOK, flyShape } from './flier-shapes.js';
|
|
179
|
+
export {
|
|
180
|
+
ANT_LOOK,
|
|
181
|
+
BEETLE_LOOK,
|
|
182
|
+
RAT_LOOK,
|
|
183
|
+
SNAKE_LOOK,
|
|
184
|
+
SPIDER_LOOK,
|
|
185
|
+
antGeometry,
|
|
186
|
+
beetleGeometry,
|
|
187
|
+
ratGeometry,
|
|
188
|
+
snakeGeometry,
|
|
189
|
+
spiderGeometry,
|
|
190
|
+
} from './crawl-shapes.js';
|
|
191
|
+
export { GIANT_SPIDER_GAIT, GIANT_SPIDER_LOOK, giantSpiderMoment, giantSpiderMoments } from './crawler-giant-spider.js';
|
|
192
|
+
|
|
193
|
+
// ── Crowds ───────────────────────────────────────────────────────────────
|
|
194
|
+
export { buildCrowdLook, createCrowdLookBuilder } from './crowd-look.js';
|
|
195
|
+
export { farCrowdFigure } from './crowd-far.js';
|
|
196
|
+
|
|
197
|
+
// ── Effects, audio, pacing & runtime ─────────────────────────────────────
|
|
198
|
+
export { STORM_WALL_DEFAULTS, stormWallArrays } from './storm-wall.js';
|
|
199
|
+
export { DUST_CURTAIN_SHAPE, dustCurtainArrays } from './curtain-sheets.js';
|
|
200
|
+
export { CAMP_DEFAULTS, buildTentLines, buildWagonLine } from './camp-layout.js';
|
|
201
|
+
|
|
202
|
+
// ── Scene playback, melee, projectiles, beams, props & markers ───────────
|
|
203
|
+
export { buildArrowGeometry, buildKnifeGeometry, buildQuarrelGeometry } from './projectile-shapes.js';
|
package/geometry/instances.js
CHANGED
|
@@ -73,7 +73,56 @@ class Copies {
|
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
export { Copies, instanceArrays, instancedMesh, instancedTwin, putInstance };
|
|
76
|
+
export { Copies, instanceArrays, instancedMesh, instancedTwin, placeInstances, putInstance };
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Create a static `THREE.InstancedMesh` populated through a callback `place(put, scratchColor)`
|
|
80
|
+
* that emits each instance with `put(matrix, optionalTint)`. Sets `mesh.count` to the actual
|
|
81
|
+
* number placed, configures shadow flags, computes the bounding sphere, and attaches to `parent`.
|
|
82
|
+
*
|
|
83
|
+
* @param {object} options
|
|
84
|
+
* @param {THREE.BufferGeometry} options.geometry - Instanced geometry.
|
|
85
|
+
* @param {THREE.Material} options.material - Instanced material.
|
|
86
|
+
* @param {number} options.capacity - Maximum number of instances to allocate.
|
|
87
|
+
* @param {(put: (matrix: THREE.Matrix4, tint?: number | THREE.Color | readonly [number, number, number]) => void, color: THREE.Color) => void} options.place
|
|
88
|
+
* - Callback invoking `put(matrix, tint)` once per placed instance.
|
|
89
|
+
* @param {THREE.Object3D | null} [options.parent=null] - Optional scene or group to attach the mesh to.
|
|
90
|
+
* @param {boolean} [options.castShadow=true] - Whether the instanced mesh casts shadows.
|
|
91
|
+
* @param {boolean} [options.receiveShadow=true] - Whether the instanced mesh receives shadows.
|
|
92
|
+
* @param {boolean} [options.computeBounds=true] - Whether to call `computeBoundingSphere()` after filling.
|
|
93
|
+
* @returns {THREE.InstancedMesh}
|
|
94
|
+
*/
|
|
95
|
+
function placeInstances({
|
|
96
|
+
geometry,
|
|
97
|
+
material,
|
|
98
|
+
capacity,
|
|
99
|
+
place,
|
|
100
|
+
parent = null,
|
|
101
|
+
castShadow = true,
|
|
102
|
+
receiveShadow = true,
|
|
103
|
+
computeBounds = true,
|
|
104
|
+
}) {
|
|
105
|
+
const mesh = new THREE.InstancedMesh(geometry, material, capacity);
|
|
106
|
+
const color = new THREE.Color();
|
|
107
|
+
let count = 0;
|
|
108
|
+
const put = (matrix, tint) => {
|
|
109
|
+
mesh.setMatrixAt(count, matrix);
|
|
110
|
+
if (tint !== undefined && tint !== null) {
|
|
111
|
+
if (typeof tint === 'number') color.setHex(tint);
|
|
112
|
+
else if (Array.isArray(tint)) color.setRGB(tint[0], tint[1], tint[2]);
|
|
113
|
+
else color.copy(tint);
|
|
114
|
+
mesh.setColorAt(count, color);
|
|
115
|
+
}
|
|
116
|
+
count++;
|
|
117
|
+
};
|
|
118
|
+
place(put, color);
|
|
119
|
+
mesh.count = count;
|
|
120
|
+
mesh.castShadow = castShadow;
|
|
121
|
+
mesh.receiveShadow = receiveShadow;
|
|
122
|
+
if (computeBounds && count > 0) mesh.computeBoundingSphere();
|
|
123
|
+
if (parent) parent.add(mesh);
|
|
124
|
+
return mesh;
|
|
125
|
+
}
|
|
77
126
|
|
|
78
127
|
/**
|
|
79
128
|
* Round-robin instanced batch builder over an array of variant geometries: distributes added
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Living tapering root and limb tubes with recursive branching along wandering 3D paths:
|
|
3
|
+
* smooth twist-free swept tubes that sink gently into ground surfaces and sprout thinner
|
|
4
|
+
* side roots along the parent's path. Pure geometry assembly into a `GB` builder; worker-safe.
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { TAU } from '../math/scalar.js';
|
|
9
|
+
import { wanderingPath } from '../math/wandering-path.js';
|
|
10
|
+
import { sweepTube } from './swept-tube.js';
|
|
11
|
+
|
|
12
|
+
/** Default tip radius as a fraction of the base radius so roots taper to a whip. */
|
|
13
|
+
export const ROOT_TIP_SHARE = 0.08;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Compute the tapered root radius at normalized distance `fraction` (`0..1`) from the foot.
|
|
17
|
+
*
|
|
18
|
+
* @param {number} base - Foot radius in metres.
|
|
19
|
+
* @param {number} fraction - Normalized position along the root in `[0, 1]`.
|
|
20
|
+
* @param {number} [tipShare=ROOT_TIP_SHARE] - Tip radius as a share of `base`.
|
|
21
|
+
* @returns {number} Radius in metres.
|
|
22
|
+
*/
|
|
23
|
+
export function rootRadius(base, fraction, tipShare = ROOT_TIP_SHARE) {
|
|
24
|
+
return base * (1 - (1 - tipShare) * Math.pow(fraction, 0.8));
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Sweep one tapering, variably shaded bark tube along `points` into `builder`. When `ground` is
|
|
29
|
+
* supplied, centres crossing below terrain lift to sit half their local radius embedded in soil.
|
|
30
|
+
*
|
|
31
|
+
* @param {import('./builder.js').GB} builder - Destination geometry builder.
|
|
32
|
+
* @param {number[][]} points - Ordered `[x, y, z]` path points in local metres.
|
|
33
|
+
* @param {number} baseRadius - Foot radius in metres.
|
|
34
|
+
* @param {[number, number, number]} color - Linear RGB bark colour.
|
|
35
|
+
* @param {number} sides - Radial segments per ring (at least 3).
|
|
36
|
+
* @param {() => number} random - Deterministic PRNG in `[0, 1)`.
|
|
37
|
+
* @param {((x: number, z: number) => number) | null} [ground=null] - Optional local ground elevation sampler `(x, z) => y` in metres.
|
|
38
|
+
*/
|
|
39
|
+
export function buildRootTube(builder, points, baseRadius, color, sides, random, ground = null) {
|
|
40
|
+
sweepTube(builder, points, {
|
|
41
|
+
sides,
|
|
42
|
+
clockwise: true,
|
|
43
|
+
radius: fraction => rootRadius(baseRadius, fraction),
|
|
44
|
+
color,
|
|
45
|
+
shade: () => 0.86 + 0.28 * random(),
|
|
46
|
+
centerY: ground ? (point, radius) => Math.max(point[1], ground(point[0], point[2]) - radius * 0.5) : null,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Grow a wandering tapering root or limb from `from` along `direction` for `length` metres,
|
|
52
|
+
* recursively sprouting `branches` thinner side roots up to `depth` generations deep.
|
|
53
|
+
*
|
|
54
|
+
* @param {import('./builder.js').GB} builder - Destination geometry builder.
|
|
55
|
+
* @param {() => number} random - Deterministic PRNG in `[0, 1)`.
|
|
56
|
+
* @param {[number, number, number]} from - Start position `[x, y, z]` in local metres.
|
|
57
|
+
* @param {[number, number, number]} direction - Initial heading vector `[dx, dy, dz]`.
|
|
58
|
+
* @param {number} length - Path length in metres.
|
|
59
|
+
* @param {number} radius - Foot radius in metres.
|
|
60
|
+
* @param {[number, number, number]} color - Linear RGB bark colour.
|
|
61
|
+
* @param {object} [options]
|
|
62
|
+
* @param {number} [options.step=1] - Step length in metres between path samples.
|
|
63
|
+
* @param {number} [options.curl=0.5] - Lateral wander amplitude per step.
|
|
64
|
+
* @param {((point: number[], fraction: number) => number[]) | null} [options.pull=null] - Optional steering bias vector callback.
|
|
65
|
+
* @param {number} [options.sides=6] - Radial segments for thicker roots.
|
|
66
|
+
* @param {number} [options.branches=0] - Number of child branches sprouting from this stem.
|
|
67
|
+
* @param {number} [options.share=0.5] - Child length share of remaining parent length.
|
|
68
|
+
* @param {number} [options.depth=1] - Remaining recursion depth.
|
|
69
|
+
* @param {((x: number, z: number) => number) | null} [options.ground=null] - Optional ground elevation sampler `(x, z) => y` in metres.
|
|
70
|
+
* @param {number} [options.minR=0.03] - Minimum child foot radius in metres.
|
|
71
|
+
* @param {number} [options.rise=0] - Upward bias added to child branch headings.
|
|
72
|
+
* @param {number[][] | null} [options.tips=null] - Optional array collecting every root tip `[x, y, z]`.
|
|
73
|
+
* @returns {number[][]} Main stem path points.
|
|
74
|
+
*/
|
|
75
|
+
export function growRootBranch(builder, random, from, direction, length, radius, color, options = {}) {
|
|
76
|
+
const {
|
|
77
|
+
step = 1,
|
|
78
|
+
curl = 0.5,
|
|
79
|
+
pull = null,
|
|
80
|
+
sides = 6,
|
|
81
|
+
branches = 0,
|
|
82
|
+
share = 0.5,
|
|
83
|
+
depth = 1,
|
|
84
|
+
ground = null,
|
|
85
|
+
minR = 0.03,
|
|
86
|
+
rise = 0,
|
|
87
|
+
} = options;
|
|
88
|
+
const pts = wanderingPath(random, from, direction, length, { step, curl, pull, persistence: 0.6, verticalScale: 0.6 });
|
|
89
|
+
buildRootTube(builder, pts, radius, color, radius < 0.12 ? Math.max(4, sides - 2) : sides, random, ground);
|
|
90
|
+
if (options.tips) options.tips.push(pts[pts.length - 1]);
|
|
91
|
+
if (depth <= 0) return pts;
|
|
92
|
+
for (let k = 0; k < branches; k++) {
|
|
93
|
+
const i = 1 + Math.floor((0.15 + 0.6 * random()) * (pts.length - 2));
|
|
94
|
+
const f = i / (pts.length - 1);
|
|
95
|
+
const rr = rootRadius(radius, f) * (0.5 + 0.2 * random());
|
|
96
|
+
if (rr < minR || i >= pts.length - 1) continue;
|
|
97
|
+
const p = pts[i];
|
|
98
|
+
const q = pts[i + 1];
|
|
99
|
+
const hl = Math.hypot(q[0] - p[0], q[1] - p[1], q[2] - p[2]) || 1;
|
|
100
|
+
const [hx, hy, hz] = [(q[0] - p[0]) / hl, (q[1] - p[1]) / hl, (q[2] - p[2]) / hl];
|
|
101
|
+
const [ax, ay, az] = Math.abs(hy) < 0.9 ? [-hz, 0, hx] : [1, 0, 0];
|
|
102
|
+
const al = Math.hypot(ax, ay, az);
|
|
103
|
+
const [bx, by, bz] = [hy * az - hz * ay, hz * ax - hx * az, hx * ay - hy * ax];
|
|
104
|
+
const turn = random() * TAU;
|
|
105
|
+
const c = Math.cos(turn) / al;
|
|
106
|
+
const s = Math.sin(turn) / al;
|
|
107
|
+
const d = [hx * 0.8 + (ax * c + bx * s) * 0.9, hy * 0.8 + (ay * c + by * s) * 0.9 + rise, hz * 0.8 + (az * c + bz * s) * 0.9];
|
|
108
|
+
growRootBranch(builder, random, p, d, length * (1 - f) * share * (0.7 + 0.6 * random()), rr, color, {
|
|
109
|
+
...options,
|
|
110
|
+
depth: depth - 1,
|
|
111
|
+
branches: Math.max(0, branches - 1),
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
return pts;
|
|
115
|
+
}
|
package/geometry/primitives.js
CHANGED
|
@@ -240,4 +240,8 @@ function stick(builder, start, end, radius, color, geometry = cyl6) {
|
|
|
240
240
|
builder.add(geometry, color, m.compose(at.set(start[0], start[1], start[2]), turn, size.set(radius, len, radius)));
|
|
241
241
|
}
|
|
242
242
|
|
|
243
|
+
let sharedUnitShapes = null;
|
|
244
|
+
/** Return a lazily created shared library of default unit scenery shapes. */
|
|
245
|
+
export const defaultUnitShapes = () => (sharedUnitShapes ??= createUnitShapes());
|
|
246
|
+
|
|
243
247
|
export { box, C, TRS, lump, stick, without };
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Standing wind-carved rock outcrops, tors, buttes and sea stacks wrapped as one creased sheet
|
|
3
|
+
* with horizontal sedimentary beds, vertical joint fissures, wind-scoured basal notches, desert
|
|
4
|
+
* varnish streaks, dusty crowns and surrounding talus aprons with fallen blocks.
|
|
5
|
+
* Pure geometry assembly into a `GB` builder; worker-safe.
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { clamp, lerp, sstep, TAU } from '../math/scalar.js';
|
|
10
|
+
import { defaultRockHash as defaultHash, defaultRockNoise as defaultNoise, rockSheet } from './creased-sheet.js';
|
|
11
|
+
import { C as defaultColor, TRS as defaultTransform, defaultUnitShapes } from './primitives.js';
|
|
12
|
+
import { jointed } from './strata-rocks.js';
|
|
13
|
+
|
|
14
|
+
/** Default weathered desert sandstone sRGB tones for bedded rock outcrops. */
|
|
15
|
+
export const OUTCROP_SANDSTONE = Object.freeze([0x8f6548, 0xa57856, 0x86593f, 0xae825e, 0x94694a]);
|
|
16
|
+
|
|
17
|
+
/** Default sRGB dust colour lying on horizontal ledges, rounded crowns and talus aprons. */
|
|
18
|
+
export const OUTCROP_DUST = 0xa98462;
|
|
19
|
+
|
|
20
|
+
const VARNISH = Object.freeze([0.2, 0.15, 0.12]);
|
|
21
|
+
const NOTCH = Object.freeze([0.02, 0.09, 0.16]);
|
|
22
|
+
const CAP = 0.86;
|
|
23
|
+
const CROWN = Object.freeze([0.8, 0.55, 0.3]);
|
|
24
|
+
const FACE_SHADE = 0.93;
|
|
25
|
+
const ROW_METRES = 1.1;
|
|
26
|
+
const COLUMN_METRES = 2.2;
|
|
27
|
+
const APRON = Object.freeze([0.16, 0.55]);
|
|
28
|
+
const BLOCK_EVERY = 4;
|
|
29
|
+
|
|
30
|
+
const defaultRock = () => defaultUnitShapes().rock;
|
|
31
|
+
|
|
32
|
+
const keyOf = seed => Math.abs(Math.round(seed)) % 97;
|
|
33
|
+
const outlineAt = (a, key, vnoise) => 0.66 + 0.68 * jointed(vnoise(Math.cos(a) * 1.9 + key * 3.1, Math.sin(a) * 1.9 + 5.3, 942), 3);
|
|
34
|
+
const chippedAt = (a, bed, key, vnoise) => 0.3 * (jointed(vnoise(Math.cos(a) * 3.7 + bed * 7.7, Math.sin(a) * 3.7 + key, 943), 2) - 0.5);
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Compute how far the foot of a bedded outcrop of `seed` stands from its centre at `bearing`
|
|
38
|
+
* (radians, before yaw rotation), as a fraction of its half-width along that bearing. Useful for
|
|
39
|
+
* placing props or structures flush against an outcrop face.
|
|
40
|
+
*
|
|
41
|
+
* @param {number} seed - Integer outcrop seed.
|
|
42
|
+
* @param {number} bearing - Unrotated polar bearing in radians.
|
|
43
|
+
* @param {object} [options]
|
|
44
|
+
* @param {(x: number, z: number, salt: number) => number} [options.noise] - Value noise sampler in `[0, 1)`.
|
|
45
|
+
* @returns {number} Fractional radial reach at ground level.
|
|
46
|
+
*/
|
|
47
|
+
export function outcropReach(seed, bearing, options = {}) {
|
|
48
|
+
const vnoise = options.noise ?? defaultNoise();
|
|
49
|
+
const key = keyOf(seed);
|
|
50
|
+
return outlineAt(bearing, key, vnoise) + chippedAt(bearing, 0, key, vnoise);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Build the concave talus apron and scattered fallen blocks ringing the foot of an outcrop.
|
|
55
|
+
*
|
|
56
|
+
* @param {import('./builder.js').GB} builder - Destination geometry builder.
|
|
57
|
+
* @param {(x: number, z: number) => number} ground - World ground elevation sampler `(x, z) => y` in metres.
|
|
58
|
+
* @param {object} spec - Outcrop specification (`x`, `z`, optional `dust` and `tones`).
|
|
59
|
+
* @param {number[][]} foot - Ring of world `[x, y, z]` foot points around the outcrop perimeter.
|
|
60
|
+
* @param {number} height - Effective talus height scale in metres (`h * talus`).
|
|
61
|
+
* @param {number} key - Reduced integer seed key (`Math.abs(Math.round(seed)) % 97`).
|
|
62
|
+
* @param {((angle: number, up: number) => number) | undefined} gap - Optional recess callback returning indentation depth in metres.
|
|
63
|
+
* @param {object} [options]
|
|
64
|
+
* @param {(x: number, z: number, salt: number) => number} [options.noise] - Value noise sampler in `[0, 1)`.
|
|
65
|
+
* @param {(x: number, y: number, salt: number) => number} [options.hash] - Deterministic 2D hash in `[0, 1)`.
|
|
66
|
+
* @param {import('three').BufferGeometry} [options.rock] - Unit rock shape for fallen blocks.
|
|
67
|
+
* @param {Function} [options.color] - Linear RGB colour helper (`C`).
|
|
68
|
+
* @param {Function} [options.transform] - Transform matrix helper (`TRS`).
|
|
69
|
+
*/
|
|
70
|
+
export function buildTalusApron(builder, ground, spec, foot, height, key, gap, options = {}) {
|
|
71
|
+
const vnoise = options.noise ?? defaultNoise();
|
|
72
|
+
const hash2 = options.hash ?? defaultHash();
|
|
73
|
+
const rock = options.rock ?? defaultRock();
|
|
74
|
+
const color = options.color ?? defaultColor;
|
|
75
|
+
const transform = options.transform ?? defaultTransform;
|
|
76
|
+
const { x, z, dust = OUTCROP_DUST, tones = OUTCROP_SANDSTONE } = spec;
|
|
77
|
+
const n = foot.length;
|
|
78
|
+
const dustTone = color(dust);
|
|
79
|
+
const rings = [0, 0.35, 0.7, 1].map(() => []);
|
|
80
|
+
for (let k = 0; k < n; k++) {
|
|
81
|
+
const a = (k / n) * TAU;
|
|
82
|
+
const open = gap && gap(a, 0.05) > 0;
|
|
83
|
+
const [fx, , fz] = foot[k];
|
|
84
|
+
const dx = fx - x;
|
|
85
|
+
const dz = fz - z;
|
|
86
|
+
const d = Math.hypot(dx, dz) || 1;
|
|
87
|
+
const tall = open ? 0 : height * APRON[0] * (0.6 + 0.8 * vnoise(Math.cos(a) * 3 + key, Math.sin(a) * 3, 952));
|
|
88
|
+
const spread = height * APRON[1] * (0.7 + 0.6 * vnoise(Math.cos(a) * 2.3 - key, Math.sin(a) * 2.3, 953));
|
|
89
|
+
[0, 0.35, 0.7, 1].forEach((f, i) => {
|
|
90
|
+
const px = fx + (dx / d) * spread * f;
|
|
91
|
+
const pz = fz + (dz / d) * spread * f;
|
|
92
|
+
const y = ground(px, pz) + tall * (1 - f) ** 1.8 - (f === 1 ? 0.15 : 0);
|
|
93
|
+
rings[i].push([px - (dx / d) * 0.3 * (1 - f), y, pz - (dz / d) * 0.3 * (1 - f)]);
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
const shades = rings.map((ring, r) =>
|
|
97
|
+
ring.map(p => {
|
|
98
|
+
const pick = vnoise(p[0] * 0.21 + key, p[2] * 0.21, 959) * tones.length;
|
|
99
|
+
const stone = color(tones[(Math.floor(pick) + key) % tones.length]);
|
|
100
|
+
const mix = 0.6 + 0.35 * (r / (rings.length - 1));
|
|
101
|
+
return [0, 1, 2].map(i => lerp(stone[i] * 0.85, dustTone[i], mix) * 0.95);
|
|
102
|
+
}),
|
|
103
|
+
);
|
|
104
|
+
rockSheet(builder, [...rings].reverse(), shades.reverse(), { wrap: true, inside: true });
|
|
105
|
+
const blocks = Math.round((n * COLUMN_METRES) / BLOCK_EVERY);
|
|
106
|
+
for (let i = 0; i < blocks; i++) {
|
|
107
|
+
const k = Math.floor(hash2(i, key, 954) * n);
|
|
108
|
+
const f = hash2(i, key, 955) ** 1.5;
|
|
109
|
+
const p = [0, 1, 2].map(j => lerp(rings[0][k][j], rings[3][k][j], f * 0.9));
|
|
110
|
+
const s = (0.4 + 1.8 * hash2(i, key, 956) ** 2) * Math.min(1, height / 8 + 0.3);
|
|
111
|
+
builder.add(
|
|
112
|
+
rock,
|
|
113
|
+
color(tones[i % tones.length], 0.12, () => hash2(i, key, 957)),
|
|
114
|
+
transform(
|
|
115
|
+
p[0] - builder.ox,
|
|
116
|
+
ground(p[0], p[2]) - s * 0.25 - builder.oy,
|
|
117
|
+
p[2] - builder.oz,
|
|
118
|
+
s * 1.4,
|
|
119
|
+
s * 0.85,
|
|
120
|
+
s,
|
|
121
|
+
hash2(i, key, 958) * TAU,
|
|
122
|
+
),
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Build a wind-carved bedded rock outcrop (tor, butte or sea stack) at `(spec.x, spec.z)` resting
|
|
129
|
+
* on `ground(x, z)`: stepped sedimentary beds, vertical joint fissures, basal wind-scour notch,
|
|
130
|
+
* rounded dusty cap, vertical varnish streaks, optional carved recess `gap(angle, up)`, and an
|
|
131
|
+
* optional talus apron with fallen blocks.
|
|
132
|
+
*
|
|
133
|
+
* @param {import('./builder.js').GB} builder - Destination geometry builder.
|
|
134
|
+
* @param {(x: number, z: number) => number} ground - World ground elevation sampler `(x, z) => y` in metres.
|
|
135
|
+
* @param {object} spec
|
|
136
|
+
* @param {number} spec.x - Outcrop centre world X in metres.
|
|
137
|
+
* @param {number} spec.z - Outcrop centre world Z in metres.
|
|
138
|
+
* @param {number} spec.rx - Half-width along local X in metres.
|
|
139
|
+
* @param {number} [spec.rz=spec.rx] - Half-width along local Z in metres.
|
|
140
|
+
* @param {number} spec.h - Height above ground in metres.
|
|
141
|
+
* @param {number} [spec.beds=4] - Number of horizontal rock beds.
|
|
142
|
+
* @param {number} [spec.yaw=0] - Rotation around Y in radians.
|
|
143
|
+
* @param {number} [spec.seed=1] - Integer seed controlling outline, joints and bedding.
|
|
144
|
+
* @param {number} [spec.step=0.07] - Fractional inward setback per bed.
|
|
145
|
+
* @param {number} [spec.taper=0.25] - Fractional top taper.
|
|
146
|
+
* @param {number} [spec.soft=0.06] - Fractional basal wind-scour notch depth.
|
|
147
|
+
* @param {readonly number[]} [spec.tones=OUTCROP_SANDSTONE] - Bed sRGB hex palette.
|
|
148
|
+
* @param {number} [spec.dust=OUTCROP_DUST] - Ledge, cap and talus dust sRGB colour.
|
|
149
|
+
* @param {number} [spec.slide=1] - Lateral offset scale between successive beds.
|
|
150
|
+
* @param {number} [spec.talus=1] - Talus apron spread factor (`0` disables the apron).
|
|
151
|
+
* @param {(angle: number, up: number) => number} [spec.gap] - Optional recess depth in metres at polar bearing `angle` and normalized height `up`.
|
|
152
|
+
* @param {object} [options]
|
|
153
|
+
* @param {(x: number, z: number, salt: number) => number} [options.noise] - Value noise sampler in `[0, 1)`.
|
|
154
|
+
* @param {(x: number, y: number, salt: number) => number} [options.hash] - Deterministic 2D hash in `[0, 1)`.
|
|
155
|
+
* @param {import('three').BufferGeometry} [options.rock] - Unit rock shape for fallen blocks.
|
|
156
|
+
* @param {Function} [options.color] - Linear RGB colour helper (`C`).
|
|
157
|
+
* @param {Function} [options.transform] - Transform matrix helper (`TRS`).
|
|
158
|
+
*/
|
|
159
|
+
export function buildOutcrop(builder, ground, spec, options = {}) {
|
|
160
|
+
const vnoise = options.noise ?? defaultNoise();
|
|
161
|
+
const hash2 = options.hash ?? defaultHash();
|
|
162
|
+
const color = options.color ?? defaultColor;
|
|
163
|
+
const {
|
|
164
|
+
x,
|
|
165
|
+
z,
|
|
166
|
+
rx,
|
|
167
|
+
rz = rx,
|
|
168
|
+
h,
|
|
169
|
+
beds = 4,
|
|
170
|
+
yaw = 0,
|
|
171
|
+
seed = 1,
|
|
172
|
+
step = 0.07,
|
|
173
|
+
taper = 0.25,
|
|
174
|
+
soft = 0.06,
|
|
175
|
+
tones = OUTCROP_SANDSTONE,
|
|
176
|
+
dust = OUTCROP_DUST,
|
|
177
|
+
slide = 1,
|
|
178
|
+
talus = 1,
|
|
179
|
+
gap,
|
|
180
|
+
} = spec;
|
|
181
|
+
const reach = Math.max(rx, rz);
|
|
182
|
+
const columns = clamp(Math.round((TAU * reach) / COLUMN_METRES), 16, 150);
|
|
183
|
+
const bury = Math.min(2, 0.4 + h * 0.08);
|
|
184
|
+
const cy = Math.cos(yaw);
|
|
185
|
+
const sy = Math.sin(yaw);
|
|
186
|
+
const dustTone = color(dust);
|
|
187
|
+
const key = keyOf(seed);
|
|
188
|
+
const heads = [];
|
|
189
|
+
let sum = 0;
|
|
190
|
+
for (let b = 0; b < beds; b++) heads.push((sum += 0.6 + hash2(b, Math.abs(seed), 941)));
|
|
191
|
+
for (let b = 0; b < beds; b++) heads[b] /= sum;
|
|
192
|
+
const bedAt = up => {
|
|
193
|
+
let b = 0;
|
|
194
|
+
while (b < beds - 1 && up > heads[b]) b++;
|
|
195
|
+
return b;
|
|
196
|
+
};
|
|
197
|
+
const hard = b => hash2(b, key, 948) > 0.45;
|
|
198
|
+
const outline = a => outlineAt(a, key, vnoise);
|
|
199
|
+
const joints = a => 0.07 * sstep(0.74, 0.9, vnoise(Math.cos(a) * 5.3 + key, Math.sin(a) * 5.3 - key, 949));
|
|
200
|
+
const chipped = (a, b) => 0.05 * (jointed(vnoise(Math.cos(a) * 3.7 + b * 7.7, Math.sin(a) * 3.7 + key, 943), 2) - 0.5);
|
|
201
|
+
const shift = (b, axis) => (b ? (hash2(b + axis * 31, key, 947) - 0.5) * 0.06 * slide : 0);
|
|
202
|
+
const girthAt = up => {
|
|
203
|
+
const b = bedAt(up);
|
|
204
|
+
const from = b ? heads[b - 1] : 0;
|
|
205
|
+
const t = (up - from) / Math.max(1e-3, heads[b] - from);
|
|
206
|
+
const ledge = sstep(0.82, 1, t) * step;
|
|
207
|
+
const relief = (hard(b) ? 0.008 : -0.012) * Math.sin(Math.PI * Math.min(1, t * 1.15));
|
|
208
|
+
const notch = soft * 2.2 * (sstep(NOTCH[0], NOTCH[1], up) - sstep(NOTCH[1], NOTCH[2], up));
|
|
209
|
+
const cap = up > CAP ? 1 - Math.sqrt(Math.max(0, 1 - ((up - CAP) / (1 - CAP)) ** 2)) : 0;
|
|
210
|
+
return { b, girth: (1 - step * b - ledge) * (1 - taper * up) * (1 + relief - notch) * (1 - 0.22 * cap) };
|
|
211
|
+
};
|
|
212
|
+
const local = (px, pz) => [x + px * cy + pz * sy, z - px * sy + pz * cy];
|
|
213
|
+
const point = (k, up) => {
|
|
214
|
+
const a = (k / columns) * TAU;
|
|
215
|
+
const { b, girth } = girthAt(Math.max(0, up));
|
|
216
|
+
const press = gap ? gap(a, Math.max(0, up)) : 0;
|
|
217
|
+
const r = Math.max(0.05, (outline(a) - joints(a) + chipped(a, b)) * girth - press / reach);
|
|
218
|
+
const [wx, wz] = local((Math.cos(a) * r + shift(b, 0)) * rx, (Math.sin(a) * r + shift(b, 1)) * rz);
|
|
219
|
+
return [wx, ground(wx, wz) + h * up, wz];
|
|
220
|
+
};
|
|
221
|
+
const ups = [-bury / h];
|
|
222
|
+
for (let b = 0; b < beds; b++) {
|
|
223
|
+
const from = b ? heads[b - 1] : 0;
|
|
224
|
+
const rows = Math.max(3, Math.ceil(((heads[b] - from) * h) / ROW_METRES));
|
|
225
|
+
for (let r = 1; r <= rows; r++) ups.push(lerp(from, heads[b], r / rows));
|
|
226
|
+
}
|
|
227
|
+
for (const u of [NOTCH[0], NOTCH[1], NOTCH[2], CAP + (1 - CAP) * 0.5, CAP + (1 - CAP) * 0.85]) ups.push(u);
|
|
228
|
+
ups.sort((p, q) => p - q);
|
|
229
|
+
const rings = ups.map(up => Array.from({ length: columns }, (_, k) => point(k, up)));
|
|
230
|
+
const faceTone = (p, up, k) => {
|
|
231
|
+
const bedTone = color(tones[(bedAt(Math.max(0, up)) + key) % tones.length]);
|
|
232
|
+
const bearing = (k / columns) * TAU;
|
|
233
|
+
const band = 0.9 + 0.2 * vnoise(p[1] * 0.35 + key, bearing * 0.3, 950);
|
|
234
|
+
const grain = 0.88 + 0.24 * vnoise(p[0] * 0.23 + p[2] * 0.19, p[1] * 0.3, 944 + key);
|
|
235
|
+
const streak = sstep(0.62, 0.86, vnoise(Math.cos(bearing) * 11 + key, Math.sin(bearing) * 11, 951)) * (0.35 + 0.65 * up);
|
|
236
|
+
const under = sstep(NOTCH[0] - 0.03, NOTCH[0] + 0.02, up) * sstep(NOTCH[2] + 0.02, NOTCH[1], up);
|
|
237
|
+
const shade = FACE_SHADE * (1 - 0.12 * under);
|
|
238
|
+
return [0, 1, 2].map(i => lerp(bedTone[i] * band * grain, VARNISH[i], streak * 0.75) * shade);
|
|
239
|
+
};
|
|
240
|
+
const brow = rings[rings.length - 1];
|
|
241
|
+
const top = brow.reduce((s, p) => s + p[1], 0) / columns;
|
|
242
|
+
const lumps = (px, pz) => vnoise(px * 0.09 + key, pz * 0.09, 945) - 0.35;
|
|
243
|
+
const crown = CROWN.map(f =>
|
|
244
|
+
brow.map(([px, , pz]) => {
|
|
245
|
+
const cx = lerp(x, px, f);
|
|
246
|
+
const cz = lerp(z, pz, f);
|
|
247
|
+
return [cx, top + h * (0.05 * (1 - f * f) + 0.03 * lumps(cx, cz)), cz];
|
|
248
|
+
}),
|
|
249
|
+
);
|
|
250
|
+
const middle = [x, top + h * 0.05, z];
|
|
251
|
+
const crownTone = p => {
|
|
252
|
+
const shade = 0.84 + 0.26 * vnoise(p[0] * 0.15 - key, p[2] * 0.15, 946);
|
|
253
|
+
return [dustTone[0] * shade, dustTone[1] * shade, dustTone[2] * shade];
|
|
254
|
+
};
|
|
255
|
+
const rows = [...rings, ...crown, brow.map(() => middle)];
|
|
256
|
+
const shades = rows.map((row, r) => row.map((p, k) => (r < rings.length ? faceTone(p, ups[r], k) : crownTone(p))));
|
|
257
|
+
rockSheet(builder, rows, shades, { wrap: true, inside: true, dust: dustTone });
|
|
258
|
+
if (talus > 0) buildTalusApron(builder, ground, spec, rings[ups.indexOf(NOTCH[0])], h * talus, key, gap, options);
|
|
259
|
+
}
|
package/geometry/strata-rocks.js
CHANGED
|
@@ -110,16 +110,17 @@ export function flatQuad(builder, a, b, c, d, low, high) {
|
|
|
110
110
|
|
|
111
111
|
/**
|
|
112
112
|
* Quantize a noise value `n` in `[0, 1]` into `steps` flat plateaus joined by steep ramps,
|
|
113
|
-
* modelling rock fractured cleanly along geological joints.
|
|
113
|
+
* modelling rock or ice fractured cleanly along geological joints.
|
|
114
114
|
*
|
|
115
115
|
* @param {number} n - Input noise value in `[0, 1]`.
|
|
116
116
|
* @param {number} steps - Number of fracture steps.
|
|
117
|
+
* @param {number} [ramp=0.7] - Fractional start of the smoothstep ramp within each step.
|
|
117
118
|
* @returns {number} Stepped value in `[0, 1]`.
|
|
118
119
|
*/
|
|
119
|
-
export function jointed(n, steps) {
|
|
120
|
+
export function jointed(n, steps, ramp = 0.7) {
|
|
120
121
|
const u = n * steps;
|
|
121
122
|
const k = Math.floor(u);
|
|
122
|
-
return (k + sstep(
|
|
123
|
+
return (k + sstep(ramp, 1, u - k)) / steps;
|
|
123
124
|
}
|
|
124
125
|
|
|
125
126
|
/**
|