roamwright 0.61.16 → 0.61.18
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 +25 -24
- package/examples/land-features.js +130 -9
- package/examples/land.html +2 -1
- package/examples/land.js +17 -2
- package/examples/ruins.html +3 -2
- package/examples/ruins.js +184 -37
- package/examples/world-map.html +162 -0
- package/examples/world-map.js +475 -0
- package/geometry/farm-props.js +59 -0
- package/geometry/field-map.js +147 -0
- package/geometry/instances.js +40 -0
- package/geometry/plant-tuft.js +138 -0
- package/geometry/ruins-breach.js +329 -0
- package/geometry/ruins-crater.js +269 -0
- package/geometry/ruins-masonry.js +323 -0
- package/geometry/ruins-walls.js +272 -0
- package/geometry/strata-mesa.js +114 -0
- package/geometry/strata-rocks.js +73 -2
- package/index.js +109 -1
- package/package.json +1 -1
- package/rendering/contact-shadows.js +56 -0
- package/rendering/crowd-lifecycle.js +80 -0
- package/rendering/farm-plough.js +145 -0
- package/rendering/map-glyphs.js +494 -0
- package/rendering/map-input.js +143 -0
- package/rendering/map-labels.js +181 -0
- package/rendering/map-relief.js +330 -0
- package/rendering/map-signs.js +124 -0
- package/rendering/place-names.js +408 -0
- package/rendering/plant-tuft.js +190 -0
- package/rendering/portrait-studio.js +213 -0
- package/rendering/ruins-fittings.js +199 -0
- package/rendering/ruins-mound.js +103 -0
- package/rendering/screen-pick.js +75 -0
- package/runtime/build-freshness.js +133 -0
- package/runtime/compass-strip.js +232 -0
- package/runtime/context-lost.js +108 -0
- package/runtime/doorways.js +98 -0
- package/runtime/hud-frame.js +74 -0
- package/runtime/map-relief.js +236 -0
- package/runtime/map-spot.js +120 -0
- package/runtime/map-view.js +229 -0
- package/runtime/panel-shell.js +90 -0
- package/runtime/relation-graph.js +163 -0
- package/runtime/stage-frame.js +263 -0
- package/runtime/url-router.js +162 -0
- package/runtime/way-back.js +71 -0
- package/runtime/whereabouts.js +210 -0
- package/runtime/world-controls.js +265 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as THREE from 'three';
|
|
2
|
+
import { sstep } from '../math/scalar.js';
|
|
2
3
|
|
|
3
4
|
// Soft contact shadows on horizontal receivers. Supply the height of the receiving
|
|
4
5
|
// surface in mesh-local coordinates. One quad per contact, in one draw.
|
|
@@ -80,3 +81,58 @@ export class ContactShadows {
|
|
|
80
81
|
this.mesh.material.dispose();
|
|
81
82
|
}
|
|
82
83
|
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Create a distance-culled and smoothly faded contact-shadow collector for feet, hooves, paws and
|
|
87
|
+
* supine bodies, backed by a single {@link ContactShadows} draw call.
|
|
88
|
+
*
|
|
89
|
+
* @param {object} [options]
|
|
90
|
+
* @param {THREE.Object3D | null} [options.scene=null] - Optional scene or group receiving the shadow mesh.
|
|
91
|
+
* @param {number} [options.capacity=512] - Maximum contact quads per frame.
|
|
92
|
+
* @param {number} [options.opacity=0.42] - Peak contact darkening opacity.
|
|
93
|
+
* @param {number} [options.lift=0.03] - Vertical offset above the receiver surface in metres.
|
|
94
|
+
* @param {number} [options.reach=42] - Distance in metres beyond which contacts are omitted.
|
|
95
|
+
* @param {number} [options.fadeFrom=0.7] - Fraction of `reach` where distance fade begins.
|
|
96
|
+
* @param {number} [options.renderOrder=2] - Three.js `renderOrder` for the contact shadow mesh.
|
|
97
|
+
* @param {number | null} [options.layer=1] - Render layer index assigned to the mesh (`null` leaves default layer 0).
|
|
98
|
+
* @param {string} [options.name='Foot shade'] - Scene-graph name for the contact shadow mesh.
|
|
99
|
+
* @returns {{
|
|
100
|
+
* add: (x: number, y: number, z: number, size: number, distanceSquared: number, intensityScale?: number) => void,
|
|
101
|
+
* begin: () => void,
|
|
102
|
+
* end: () => void,
|
|
103
|
+
* batch: ContactShadows,
|
|
104
|
+
* mesh: THREE.Mesh,
|
|
105
|
+
* dispose: () => void,
|
|
106
|
+
* }}
|
|
107
|
+
*/
|
|
108
|
+
export function createFootShadows({
|
|
109
|
+
scene = null,
|
|
110
|
+
capacity = 512,
|
|
111
|
+
opacity = 0.42,
|
|
112
|
+
lift = 0.03,
|
|
113
|
+
reach = 42,
|
|
114
|
+
fadeFrom = 0.7,
|
|
115
|
+
renderOrder = 2,
|
|
116
|
+
layer = 1,
|
|
117
|
+
name = 'Foot shade',
|
|
118
|
+
} = {}) {
|
|
119
|
+
const batch = new ContactShadows({ capacity, opacity, lift });
|
|
120
|
+
batch.mesh.name = name;
|
|
121
|
+
batch.mesh.renderOrder = renderOrder;
|
|
122
|
+
if (layer !== null) batch.mesh.layers.set(layer);
|
|
123
|
+
if (scene) scene.add(batch.mesh);
|
|
124
|
+
const reachSq = reach * reach;
|
|
125
|
+
const fadeStart = reach * fadeFrom;
|
|
126
|
+
return {
|
|
127
|
+
add(x, y, z, size, distanceSquared, intensityScale = 1) {
|
|
128
|
+
if (distanceSquared >= reachSq) return;
|
|
129
|
+
const strength = (1 - sstep(fadeStart, reach, Math.sqrt(distanceSquared))) * intensityScale;
|
|
130
|
+
batch.add(x, y, z, size * 0.5, strength);
|
|
131
|
+
},
|
|
132
|
+
begin: () => batch.begin(),
|
|
133
|
+
end: () => batch.end(),
|
|
134
|
+
batch,
|
|
135
|
+
mesh: batch.mesh,
|
|
136
|
+
dispose: () => batch.dispose(),
|
|
137
|
+
};
|
|
138
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Crowd prepare-and-batch lifecycle around `createCrowdBatches`: registers crowd groups,
|
|
3
|
+
* caches shared distant/remote walk geometries, bakes their walk textures when the walker rig is
|
|
4
|
+
* ready, and rebuilds instanced batches whenever the registered crowd count changes.
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { farCrowdFigure } from '../geometry/crowd-far.js';
|
|
9
|
+
import { registerCrowd } from './crowd-update.js';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Create a page-scoped crowd prepare-and-batch lifecycle bound to a crowd batch manager and list.
|
|
13
|
+
*
|
|
14
|
+
* @param {object} config
|
|
15
|
+
* @param {ReturnType<import('./crowd-batches.js').createCrowdBatches>} config.batchManager - Crowd batch manager holding pose and walk textures.
|
|
16
|
+
* @param {object[]} [config.crowds=[]] - Mutable crowd registry populated by `addCrowd` and batched by `batchCrowds`.
|
|
17
|
+
* @param {object} [config.head] - Optional head profile passed to `farCrowdFigure('distant'|'remote', { head })`.
|
|
18
|
+
* @param {(spaceId: string, x: number, z: number) => number} [config.groundAt] - Ground elevation sampler by space id.
|
|
19
|
+
* @param {(x: number, y: number, salt?: number) => number} [config.hash] - Seeded 2D hash forwarded to `registerCrowd`.
|
|
20
|
+
* @param {string} [config.defaultSpace='world'] - Default space id for `addCrowd`.
|
|
21
|
+
* @returns {{
|
|
22
|
+
* addCrowd: (list: object[], tones: number[], cx: number, cz: number, range: number, kind: string, beasts?: object | null, space?: string) => object,
|
|
23
|
+
* prepareCrowds: () => import('three').BufferGeometry[],
|
|
24
|
+
* prepareWhenReady: (walkerOrdered?: () => Promise<unknown> | null | undefined) => Promise<import('three').BufferGeometry[]> | null,
|
|
25
|
+
* batchCrowds: () => object,
|
|
26
|
+
* clearFarFigures: () => void,
|
|
27
|
+
* }}
|
|
28
|
+
*/
|
|
29
|
+
export function createCrowdLifecycle({
|
|
30
|
+
batchManager,
|
|
31
|
+
crowds = [],
|
|
32
|
+
head = undefined,
|
|
33
|
+
groundAt = () => 0,
|
|
34
|
+
hash = undefined,
|
|
35
|
+
defaultSpace = 'world',
|
|
36
|
+
}) {
|
|
37
|
+
let farFigures = null;
|
|
38
|
+
|
|
39
|
+
function addCrowd(list, tones, cx, cz, range, kind, beasts = null, space = defaultSpace) {
|
|
40
|
+
return registerCrowd(crowds, list, tones, cx, cz, range, kind, {
|
|
41
|
+
beasts,
|
|
42
|
+
space,
|
|
43
|
+
groundAt,
|
|
44
|
+
...(hash ? { hash } : {}),
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function prepareCrowds() {
|
|
49
|
+
const farOptions = head ? { head } : undefined;
|
|
50
|
+
farFigures ??= [farCrowdFigure('distant', farOptions), farCrowdFigure('remote', farOptions)];
|
|
51
|
+
batchManager.bakeWalksOnce(farFigures);
|
|
52
|
+
return farFigures;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function prepareWhenReady(walkerOrdered = () => batchManager.walkerOrdered?.()) {
|
|
56
|
+
const ordered = walkerOrdered();
|
|
57
|
+
if (ordered) return ordered.then(prepareCrowds);
|
|
58
|
+
prepareCrowds();
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function batchCrowds() {
|
|
63
|
+
if (batchManager.batches?.groupCount === crowds.length) return batchManager.batches;
|
|
64
|
+
prepareCrowds();
|
|
65
|
+
const built = batchManager.buildCrowdBatches(
|
|
66
|
+
farFigures.map(f => f.clone()),
|
|
67
|
+
crowds,
|
|
68
|
+
);
|
|
69
|
+
batchManager.setBatches(built);
|
|
70
|
+
return built;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function clearFarFigures() {
|
|
74
|
+
if (!farFigures) return;
|
|
75
|
+
for (const geo of farFigures) geo.dispose();
|
|
76
|
+
farFigures = null;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return { addCrowd, batchCrowds, clearFarFigures, prepareCrowds, prepareWhenReady };
|
|
80
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plough team and ploughman assembly: pairs two yoked oxen (`THREE.InstancedMesh`) with timber
|
|
3
|
+
* plough gear (`geometry/prop-plough.js`) and lazily sculpts and poses the ploughman behind the
|
|
4
|
+
* stilts when the camera first approaches within visibility range.
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import * as THREE from 'three';
|
|
9
|
+
import { GB } from '../geometry/builder.js';
|
|
10
|
+
import { TRS, createUnitShapes } from '../geometry/primitives.js';
|
|
11
|
+
import { ploughGear } from '../geometry/prop-plough.js';
|
|
12
|
+
|
|
13
|
+
const _coat = new THREE.Color();
|
|
14
|
+
|
|
15
|
+
/** Default sRGB hex coat tones for the left and right yoked oxen. */
|
|
16
|
+
export const DEFAULT_OX_COATS = Object.freeze([0x96684a, 0xc4a57e]);
|
|
17
|
+
|
|
18
|
+
/** Default camera distance in metres within which the ploughman figure is lazily built. */
|
|
19
|
+
export const PLOUGHMAN_SEEN_DISTANCE = 180;
|
|
20
|
+
|
|
21
|
+
/** Default human look descriptor for a farm ploughman. */
|
|
22
|
+
export const DEFAULT_PLOUGHMAN_LOOK = Object.freeze({
|
|
23
|
+
h: 0.98,
|
|
24
|
+
w: 1.08,
|
|
25
|
+
skin: 0xb48a64,
|
|
26
|
+
hair: 0x4a3a2a,
|
|
27
|
+
garb: 'tunic',
|
|
28
|
+
c1: 0x7c6a48,
|
|
29
|
+
c2: 0x4c4234,
|
|
30
|
+
hairStyle: 'cropped',
|
|
31
|
+
beard: true,
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Mid-stride ploughman pose leaning into the plough stilts with both hands lowered onto the handles
|
|
36
|
+
* (positions in metres, joint rotations in radians).
|
|
37
|
+
*/
|
|
38
|
+
export const PLOUGHMAN_STANCE = Object.freeze({
|
|
39
|
+
z: -1.02,
|
|
40
|
+
rootX: 0.14,
|
|
41
|
+
armX: -0.28,
|
|
42
|
+
foreX: -0.8,
|
|
43
|
+
legLX: -0.42,
|
|
44
|
+
legRX: 0.3,
|
|
45
|
+
shinRX: 0.35,
|
|
46
|
+
headX: 0.12,
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Apply the ploughman's mid-stride leaning pose to an assembled figure rig.
|
|
51
|
+
*
|
|
52
|
+
* @param {object} figure - Assembled figure containing `group`, `root`, `armL`, `armR`, `foreL`, `foreR`, `legL`, `legR`, `shinR`, `head`.
|
|
53
|
+
* @param {typeof PLOUGHMAN_STANCE} [stance=PLOUGHMAN_STANCE] - Joint angles and Z offset behind the plough.
|
|
54
|
+
* @returns {THREE.Object3D} The posed `figure.group`.
|
|
55
|
+
*/
|
|
56
|
+
export function posePloughman(figure, stance = PLOUGHMAN_STANCE) {
|
|
57
|
+
figure.group.position.set(0, 0, stance.z);
|
|
58
|
+
figure.root.rotation.x = stance.rootX;
|
|
59
|
+
figure.armL.rotation.x = figure.armR.rotation.x = stance.armX;
|
|
60
|
+
figure.foreL.rotation.x = figure.foreR.rotation.x = stance.foreX;
|
|
61
|
+
figure.legL.rotation.x = stance.legLX;
|
|
62
|
+
figure.legR.rotation.x = stance.legRX;
|
|
63
|
+
figure.shinR.rotation.x = stance.shinRX;
|
|
64
|
+
figure.head.rotation.x = stance.headX;
|
|
65
|
+
return figure.group;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Build and pose a ploughman figure using a caller-supplied figure builder.
|
|
70
|
+
*
|
|
71
|
+
* @param {object} options
|
|
72
|
+
* @param {(look: object, seed: number) => object} options.buildFigure - Figure builder returning a posed-rig handle.
|
|
73
|
+
* @param {object} [options.look=DEFAULT_PLOUGHMAN_LOOK] - Figure look descriptor.
|
|
74
|
+
* @param {number} [options.seed=3587] - Deterministic figure seed.
|
|
75
|
+
* @param {typeof PLOUGHMAN_STANCE} [options.stance=PLOUGHMAN_STANCE] - Joint pose overrides.
|
|
76
|
+
* @returns {THREE.Object3D}
|
|
77
|
+
*/
|
|
78
|
+
export function buildPloughman({ buildFigure, look = DEFAULT_PLOUGHMAN_LOOK, seed = 3587, stance = PLOUGHMAN_STANCE }) {
|
|
79
|
+
return posePloughman(buildFigure(look, seed), stance);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Assemble a yoked two-ox plough team facing `+z` from the returned group's origin, with timber
|
|
84
|
+
* plough gear and an optional lazy-built ploughman sculpted on the first near render.
|
|
85
|
+
*
|
|
86
|
+
* @param {object} options
|
|
87
|
+
* @param {THREE.BufferGeometry} options.oxen - Standing ox geometry facing `+z` on `y = 0`.
|
|
88
|
+
* @param {() => number} [options.random=Math.random] - Deterministic PRNG in `[0, 1)` for plough timber tinting.
|
|
89
|
+
* @param {THREE.Material} [options.oxMaterial] - Material for the instanced oxen pair.
|
|
90
|
+
* @param {THREE.Material} [options.woodMaterial] - Material for the timber plough gear.
|
|
91
|
+
* @param {THREE.Camera | null} [options.camera=null] - Active camera checked against `seenDistance` before building the ploughman.
|
|
92
|
+
* @param {((look: object, seed: number) => object) | null} [options.buildFigure=null] - Figure builder for the ploughman (omit for unmanned team).
|
|
93
|
+
* @param {readonly [number, number]} [options.oxCoats=DEFAULT_OX_COATS] - sRGB hex coat tones for the two oxen.
|
|
94
|
+
* @param {object} [options.ploughmanLook=DEFAULT_PLOUGHMAN_LOOK] - Look descriptor passed to `buildFigure`.
|
|
95
|
+
* @param {number} [options.ploughmanSeed=3587] - Seed passed to `buildFigure`.
|
|
96
|
+
* @param {typeof PLOUGHMAN_STANCE} [options.ploughmanStance=PLOUGHMAN_STANCE] - Stance angles for the ploughman.
|
|
97
|
+
* @param {number} [options.seenDistance=PLOUGHMAN_SEEN_DISTANCE] - Camera distance in metres at which the ploughman is built (`0` builds immediately).
|
|
98
|
+
* @param {object} [options.shapes] - Unit shapes passed to `ploughGear` (defaults to `createUnitShapes()`).
|
|
99
|
+
* @param {number | null} [options.layer=1] - Render layer index for gear and oxen (`null` leaves default layer 0).
|
|
100
|
+
* @returns {THREE.Group}
|
|
101
|
+
*/
|
|
102
|
+
export function createPloughTeam({
|
|
103
|
+
oxen,
|
|
104
|
+
random = Math.random,
|
|
105
|
+
oxMaterial = new THREE.MeshStandardMaterial({ vertexColors: true, roughness: 0.9 }),
|
|
106
|
+
woodMaterial = new THREE.MeshStandardMaterial({ vertexColors: true, roughness: 0.92 }),
|
|
107
|
+
camera = null,
|
|
108
|
+
buildFigure = null,
|
|
109
|
+
oxCoats = DEFAULT_OX_COATS,
|
|
110
|
+
ploughmanLook = DEFAULT_PLOUGHMAN_LOOK,
|
|
111
|
+
ploughmanSeed = 3587,
|
|
112
|
+
ploughmanStance = PLOUGHMAN_STANCE,
|
|
113
|
+
seenDistance = PLOUGHMAN_SEEN_DISTANCE,
|
|
114
|
+
shapes = createUnitShapes(),
|
|
115
|
+
layer = 1,
|
|
116
|
+
}) {
|
|
117
|
+
const team = new THREE.Group();
|
|
118
|
+
const builder = new GB();
|
|
119
|
+
const pair = new THREE.InstancedMesh(oxen, oxMaterial, 2);
|
|
120
|
+
[-1, 1].forEach((side, i) => {
|
|
121
|
+
pair.setMatrixAt(i, TRS(side * 0.62, 0, 3.3, 1.04, 1.04, 1.04, side * -0.03));
|
|
122
|
+
pair.setColorAt(i, _coat.setHex(oxCoats[i]));
|
|
123
|
+
});
|
|
124
|
+
pair.castShadow = pair.receiveShadow = true;
|
|
125
|
+
ploughGear(builder, random, shapes);
|
|
126
|
+
const gear = builder.mesh(woodMaterial, team);
|
|
127
|
+
if (layer !== null) {
|
|
128
|
+
gear.layers.set(layer);
|
|
129
|
+
pair.layers.set(layer);
|
|
130
|
+
}
|
|
131
|
+
team.add(pair);
|
|
132
|
+
if (buildFigure) {
|
|
133
|
+
const mount = () => team.add(buildPloughman({ buildFigure, look: ploughmanLook, seed: ploughmanSeed, stance: ploughmanStance }));
|
|
134
|
+
if (seenDistance <= 0 || !camera) {
|
|
135
|
+
mount();
|
|
136
|
+
} else {
|
|
137
|
+
gear.onBeforeRender = () => {
|
|
138
|
+
if (team.position.distanceTo(camera.position) > seenDistance) return;
|
|
139
|
+
gear.onBeforeRender = () => {};
|
|
140
|
+
mount();
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return team;
|
|
145
|
+
}
|