roamwright 0.61.26 → 0.61.27
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 +2 -1
- package/examples/troops.html +56 -0
- package/examples/troops.js +309 -0
- package/geometry/index.js +171 -0
- package/index.js +6 -469
- package/math/index.js +8 -0
- 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/index.js +178 -0
- 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
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Instanced arrow/javelin volley pool bound to `createVolleyState`, warming its shader
|
|
3
|
+
* asynchronously before drawing and firing optional impact-dust and launch-foley callbacks
|
|
4
|
+
* with zero per-frame allocations.
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import * as THREE from 'three';
|
|
9
|
+
import { geometryView } from '../geometry/builder.js';
|
|
10
|
+
import { TRS } from '../geometry/primitives.js';
|
|
11
|
+
import { TROOP_VOLLEY_DEFAULTS, createVolleyState } from '../motion/troop-volleys.js';
|
|
12
|
+
|
|
13
|
+
const _shaftColor = new THREE.Color(0xcab58a);
|
|
14
|
+
const _darkShaftColor = new THREE.Color(0x9a8260);
|
|
15
|
+
const VOLLEY_IMPACT_DIST2 = 115 * 115;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Builds an instanced arrow/javelin volley pool bound to `createVolleyState`.
|
|
19
|
+
*
|
|
20
|
+
* @param {object} config
|
|
21
|
+
* @param {THREE.Object3D} config.group Parent group receiving the instanced volley mesh.
|
|
22
|
+
* @param {() => THREE.Material} [config.material] Tinted material factory for volley shafts.
|
|
23
|
+
* @param {(mesh: THREE.Object3D) => Promise<void>} [config.warmShaders] Async shader warmer.
|
|
24
|
+
* @param {(x: number, y: number, z: number, radius: number, nearOnly?: boolean, casts?: boolean) => boolean} [config.inView] Frustum visibility check.
|
|
25
|
+
* @param {{ position: { x: number, z: number } }} [config.camera] Camera for impact-dust distance gating.
|
|
26
|
+
* @param {() => number} [config.getFxShare] Returns `[0, 1]` particle-effect budget share.
|
|
27
|
+
* @param {((x: number, y: number, z: number, count: number, size: number, speed: number) => void)|null} [config.onDust] Optional dust puff callback.
|
|
28
|
+
* @param {((x: number, y: number, z: number, count: number) => void)|null} [config.onVolley] Optional volley audio callback.
|
|
29
|
+
* @param {number} [config.pool=96] Maximum simultaneous projectiles.
|
|
30
|
+
* @param {number} [config.gravity=16.5] Arc gravity (m/s^2).
|
|
31
|
+
* @param {number} [config.speed=24] Nominal horizontal flight speed (m/s).
|
|
32
|
+
* @param {number} [config.stick=1.6] Seconds a landed shaft stays visible.
|
|
33
|
+
* @param {number} [config.saddle=1.2] Mounted shooter height offset (metres).
|
|
34
|
+
* @param {number} [config.unseen=-1] Hidden `home` sentinel.
|
|
35
|
+
* @param {string} [config.meshName='host-volleys'] Mesh name assigned to the instanced volley pool.
|
|
36
|
+
* @returns {{ mesh: THREE.InstancedMesh, reset: () => void, launch: Function, draw: Function }}
|
|
37
|
+
*/
|
|
38
|
+
export function createTroopVolleys({
|
|
39
|
+
group,
|
|
40
|
+
material = () => new THREE.MeshStandardMaterial({ vertexColors: true, roughness: 0.9 }),
|
|
41
|
+
warmShaders = () => Promise.resolve(),
|
|
42
|
+
inView = () => true,
|
|
43
|
+
camera = { position: { x: 0, z: 0 } },
|
|
44
|
+
getFxShare = () => 1,
|
|
45
|
+
onDust = null,
|
|
46
|
+
onVolley = null,
|
|
47
|
+
pool = TROOP_VOLLEY_DEFAULTS.pool,
|
|
48
|
+
gravity = TROOP_VOLLEY_DEFAULTS.gravity,
|
|
49
|
+
speed = TROOP_VOLLEY_DEFAULTS.speed,
|
|
50
|
+
stick = TROOP_VOLLEY_DEFAULTS.stick,
|
|
51
|
+
saddle = 1.2,
|
|
52
|
+
unseen = -1,
|
|
53
|
+
meshName = 'host-volleys',
|
|
54
|
+
}) {
|
|
55
|
+
const shaft = new THREE.CylinderGeometry(0.02, 0.026, 1.32, 4);
|
|
56
|
+
const posAttr = shaft.attributes.position;
|
|
57
|
+
// Orient along +Z (flight axis) with dark steel tip, weathered shaft, and pale fletching.
|
|
58
|
+
shaft.rotateX(Math.PI / 2);
|
|
59
|
+
const colors = new Float32Array(posAttr.count * 3);
|
|
60
|
+
for (let i = 0; i < posAttr.count; i++) {
|
|
61
|
+
const z = posAttr.getZ(i);
|
|
62
|
+
if (z > 0.45) {
|
|
63
|
+
colors[i * 3] = 0.25;
|
|
64
|
+
colors[i * 3 + 1] = 0.27;
|
|
65
|
+
colors[i * 3 + 2] = 0.3;
|
|
66
|
+
} else if (z < -0.35) {
|
|
67
|
+
colors[i * 3] = 0.98;
|
|
68
|
+
colors[i * 3 + 1] = 0.95;
|
|
69
|
+
colors[i * 3 + 2] = 0.88;
|
|
70
|
+
} else {
|
|
71
|
+
colors[i * 3] = 0.32;
|
|
72
|
+
colors[i * 3 + 1] = 0.24;
|
|
73
|
+
colors[i * 3 + 2] = 0.16;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
shaft.setAttribute('color', new THREE.BufferAttribute(colors, 3));
|
|
77
|
+
const mesh = new THREE.InstancedMesh(geometryView(shaft), material(), pool);
|
|
78
|
+
mesh.name = meshName;
|
|
79
|
+
mesh.frustumCulled = false;
|
|
80
|
+
mesh.castShadow = false;
|
|
81
|
+
mesh.receiveShadow = false;
|
|
82
|
+
mesh.count = 0;
|
|
83
|
+
mesh.visible = false;
|
|
84
|
+
mesh.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
|
|
85
|
+
mesh.setColorAt(0, _shaftColor);
|
|
86
|
+
mesh.instanceColor.setUsage(THREE.DynamicDrawUsage);
|
|
87
|
+
group.add(mesh);
|
|
88
|
+
|
|
89
|
+
let ready = false;
|
|
90
|
+
warmShaders(mesh).then(() => (ready = true));
|
|
91
|
+
|
|
92
|
+
const state = createVolleyState({ pool, gravity, speed, stick, saddle, unseen });
|
|
93
|
+
let curGround = null,
|
|
94
|
+
curCamX = 0,
|
|
95
|
+
curCamZ = 0;
|
|
96
|
+
|
|
97
|
+
function handleImpact(i, x, _y, z) {
|
|
98
|
+
if ((i & 3) === 0 && getFxShare() > 0 && onDust) {
|
|
99
|
+
const d2 = (x - curCamX) * (x - curCamX) + (z - curCamZ) * (z - curCamZ);
|
|
100
|
+
if (d2 < VOLLEY_IMPACT_DIST2) onDust(x, curGround(x, z) + 0.08, z, 1, 0.55, 0.65);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function handleDraw(i, px, py, pz, yaw, pitch) {
|
|
105
|
+
if (!inView(px, py, pz, 1.2, false, false)) return;
|
|
106
|
+
mesh.setMatrixAt(mesh.count, TRS(px, py, pz, 1, 1, 1, yaw, pitch, 0));
|
|
107
|
+
mesh.setColorAt(mesh.count++, (i & 1) === 0 ? _shaftColor : _darkShaftColor);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return {
|
|
111
|
+
mesh,
|
|
112
|
+
reset() {
|
|
113
|
+
state.reset();
|
|
114
|
+
mesh.count = 0;
|
|
115
|
+
mesh.visible = false;
|
|
116
|
+
},
|
|
117
|
+
launch(fromTroop, toTroop, spaceOrGround, t, rng) {
|
|
118
|
+
if (!ready) return;
|
|
119
|
+
const groundAt = typeof spaceOrGround === 'function' ? spaceOrGround : spaceOrGround.ground;
|
|
120
|
+
const res = state.launch(fromTroop, toTroop, groundAt, t, rng);
|
|
121
|
+
if (res.fired > 0 && onVolley) onVolley(res.x, res.y, res.z, res.fired);
|
|
122
|
+
},
|
|
123
|
+
draw(t, spaceOrGround) {
|
|
124
|
+
if (!ready || !state.getLiveCount()) {
|
|
125
|
+
if (mesh.visible) {
|
|
126
|
+
mesh.count = 0;
|
|
127
|
+
mesh.visible = false;
|
|
128
|
+
}
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
mesh.count = 0;
|
|
132
|
+
curGround = typeof spaceOrGround === 'function' ? spaceOrGround : spaceOrGround.ground;
|
|
133
|
+
curCamX = camera.position.x;
|
|
134
|
+
curCamZ = camera.position.z;
|
|
135
|
+
state.sample(t, handleImpact, handleDraw);
|
|
136
|
+
mesh.visible = mesh.count > 0;
|
|
137
|
+
if (mesh.count > 0) {
|
|
138
|
+
mesh.instanceMatrix.needsUpdate = true;
|
|
139
|
+
mesh.instanceColor.needsUpdate = true;
|
|
140
|
+
}
|
|
141
|
+
},
|
|
142
|
+
};
|
|
143
|
+
}
|
package/runtime/index.js
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Roamwright's public runtime, interface and pacing helpers, grouped by subsystem. Re-exported whole from `roamwright`.
|
|
3
|
+
* @module
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// ── Context, math & core geometry ────────────────────────────────────────
|
|
7
|
+
export { createNextTask } from './next-task.js';
|
|
8
|
+
|
|
9
|
+
// ── Terrain & land baking ────────────────────────────────────────────────
|
|
10
|
+
export { createLandBake } from './land-bake.js';
|
|
11
|
+
|
|
12
|
+
// ── Settlements, houses, fortifications & interiors ──────────────────────
|
|
13
|
+
export { createRegionPass } from './region-pass.js';
|
|
14
|
+
export { createRegionPasses } from './region-pass-lay.js';
|
|
15
|
+
|
|
16
|
+
// ── Figures, animals & fliers ────────────────────────────────────────────
|
|
17
|
+
export { createBodyOrders } from './figure-orders.js';
|
|
18
|
+
|
|
19
|
+
// ── Effects, audio, pacing & runtime ─────────────────────────────────────
|
|
20
|
+
export { createSiteSchedule } from './effect-sites.js';
|
|
21
|
+
export { createSoundscape } from './soundscape.js';
|
|
22
|
+
export { createStrideFoley } from './foley-strides.js';
|
|
23
|
+
export { createScriptFoley } from './foley-script.js';
|
|
24
|
+
export { createPool } from './pool.js';
|
|
25
|
+
export { createBreather, createLazySets, createSetFrame } from './lazy-sets.js';
|
|
26
|
+
export { describeDevice, readDevice } from './device.js';
|
|
27
|
+
export { choosePostPipeline, createDeviceQuality, groundRenderOrder, resolveDevicePresets } from './device-quality.js';
|
|
28
|
+
export { LEVELS, createQualityStore } from './quality-store.js';
|
|
29
|
+
export { createQualityFit } from './quality-fit.js';
|
|
30
|
+
export { createSteadyFrames } from './steady-frames.js';
|
|
31
|
+
export { createFramePacingMonitor } from './frame-pacing.js';
|
|
32
|
+
export { createPerfWatch, formatLongFrameAttribution, formatLongFrameMessage } from './perf-watch.js';
|
|
33
|
+
export { createPerfBoxState, formatPerfBoxLines } from './perf-box-text.js';
|
|
34
|
+
export { createFrameSampler } from './perf-probe.js';
|
|
35
|
+
|
|
36
|
+
// ── Scene playback, melee, projectiles, beams, props & markers ───────────
|
|
37
|
+
export { applyBurstWear, resolveScenePos, resolveSceneY, stepRidesProp, stepWalksOn } from './scene-script.js';
|
|
38
|
+
export { DEFAULT_ZONE_STRIDE, captionIndexAt, collectSceneZones, prepareSceneZones, resolveSceneAnchor } from './scene-zones.js';
|
|
39
|
+
export { createSurfaceClassifier } from './foley-surface.js';
|
|
40
|
+
|
|
41
|
+
// ── Map kit ──────────────────────────────────────────────────────────────
|
|
42
|
+
export {
|
|
43
|
+
clampViewCenter,
|
|
44
|
+
clusterMapPoints,
|
|
45
|
+
fitMapDimensions,
|
|
46
|
+
frameMapSheet,
|
|
47
|
+
pickMapHit,
|
|
48
|
+
rectUnionOutline,
|
|
49
|
+
sheetMaxZoom,
|
|
50
|
+
sheetMinZoom,
|
|
51
|
+
} from './map-view.js';
|
|
52
|
+
export { COMPASS_WINDS, describeMapSpot, findLandAtAtlas, formatSpotCard, isOnLand, landOffCentre } from './map-spot.js';
|
|
53
|
+
export {
|
|
54
|
+
brokenCoast,
|
|
55
|
+
buildAtlasMarks,
|
|
56
|
+
rangePeaks,
|
|
57
|
+
routeLength,
|
|
58
|
+
routeMidpoint,
|
|
59
|
+
scatterReliefMarks,
|
|
60
|
+
shadeTerrainPixel,
|
|
61
|
+
} from './map-relief.js';
|
|
62
|
+
|
|
63
|
+
// ── Controls, HUD & wayfinding ───────────────────────────────────────────
|
|
64
|
+
export { createStageFrame } from './stage-frame.js';
|
|
65
|
+
export { createWorldControls } from './world-controls.js';
|
|
66
|
+
export { COMPASS_POINTS, compassStripHtml, createCompassStrip } from './compass-strip.js';
|
|
67
|
+
export { createWayBack } from './way-back.js';
|
|
68
|
+
export { createHudFrame, formatDayClock } from './hud-frame.js';
|
|
69
|
+
export { createHudRoom } from './hud-room.js';
|
|
70
|
+
export {
|
|
71
|
+
ARTICLE_LINK,
|
|
72
|
+
collectArticleLinks,
|
|
73
|
+
createArticleCatalog,
|
|
74
|
+
formatArticleText,
|
|
75
|
+
parseArticle,
|
|
76
|
+
plainArticleParagraph,
|
|
77
|
+
} from './articles.js';
|
|
78
|
+
export { createArticlePageRenderer, escapeHtml, renderArticleParagraph } from './article-page.js';
|
|
79
|
+
export { createJourneyStore } from './journey.js';
|
|
80
|
+
export { createSitePages, slugify } from './site-pages.js';
|
|
81
|
+
export {
|
|
82
|
+
COMPASS_CARDINALS,
|
|
83
|
+
DEFAULT_PLACE_KINDS,
|
|
84
|
+
bearingOf,
|
|
85
|
+
createWhereabouts,
|
|
86
|
+
distanceText,
|
|
87
|
+
inSentence,
|
|
88
|
+
roundedDistance,
|
|
89
|
+
} from './whereabouts.js';
|
|
90
|
+
export { createUrlRouter, defaultSlug, normalizeSlash, parseRoutePath } from './url-router.js';
|
|
91
|
+
export { createPanelShell, scrollItemIntoView } from './panel-shell.js';
|
|
92
|
+
export { boxesOverlapOBB, placeLinkLabel, renderRelationGraph } from './relation-graph.js';
|
|
93
|
+
export { lowerQualityLevel, watchContextLost } from './context-lost.js';
|
|
94
|
+
export { extractBuildId, watchBuildFreshness } from './build-freshness.js';
|
|
95
|
+
export { findClearExit, stepDoorwayTrigger } from './doorways.js';
|