roamwright 0.61.19 → 0.61.21
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 +13 -12
- package/examples/scenes.html +54 -0
- package/examples/scenes.js +594 -0
- package/geometry/primitives.js +13 -0
- package/geometry/projectile-shapes.js +85 -0
- package/index.js +52 -1
- package/motion/fallen-mount.js +63 -0
- package/motion/melee-combat.js +328 -0
- package/motion/melee-cuts.js +395 -0
- package/motion/melee-duels.js +142 -0
- package/motion/melee-exchange-creatures.js +86 -0
- package/motion/melee-exchange.js +498 -0
- package/motion/melee-reactions.js +147 -0
- package/motion/prop-contact.js +87 -0
- package/motion/triangle-height-field.js +177 -0
- package/package.json +1 -1
- package/rendering/blade-trails.js +128 -0
- package/rendering/scene-beams.js +486 -0
- package/rendering/scene-coverage.js +500 -0
- package/rendering/scene-markers.js +421 -0
- package/rendering/scene-projectiles.js +395 -0
- package/rendering/scene-props.js +383 -0
- package/rendering/scene-shots.js +199 -0
- package/runtime/foley-surface.js +79 -0
- package/runtime/scene-script.js +137 -0
- package/runtime/scene-zones.js +117 -0
package/README.md
CHANGED
|
@@ -30,7 +30,7 @@ npm resolves the Three.js peer in a new project. Roamwright targets Three.js **0
|
|
|
30
30
|
|
|
31
31
|
## Examples
|
|
32
32
|
|
|
33
|
-
Browse all twenty examples on the [live showcase](https://enestaylan.github.io/roamwright/).
|
|
33
|
+
Browse all twenty-one examples on the [live showcase](https://enestaylan.github.io/roamwright/).
|
|
34
34
|
|
|
35
35
|
| Live example | What the example shows | Source |
|
|
36
36
|
| --------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------- |
|
|
@@ -54,6 +54,7 @@ Browse all twenty examples on the [live showcase](https://enestaylan.github.io/r
|
|
|
54
54
|
| [Island](https://enestaylan.github.io/roamwright/examples/island.html?seed=42) | Fractal terrain shapes a coastline, sandy coves, weathered boulders and coastal pines in turquoise shallows. | [island.js](examples/island.js) |
|
|
55
55
|
| [Pacing and measuring](https://enestaylan.github.io/roamwright/examples/pacing.html?seed=42) | Device-aware presets, ground render order, frame-pacing watch and a live performance box over a coastal valley. | [pacing.js](examples/pacing.js) |
|
|
56
56
|
| [World map and wayfinding](https://enestaylan.github.io/roamwright/examples/world-map.html?seed=42) | Shaded atlas relief, baked terrain sheets, collision-free lettering, interactive pan/zoom/tap and a live compass strip. | [world-map.js](examples/world-map.js) |
|
|
57
|
+
| [Scenes](https://enestaylan.github.io/roamwright/examples/scenes.html?seed=42) | Melee duels with blade trails, flying bolts, energy beams, props, instanced scene markers and automated camera cuts. | [scenes.js](examples/scenes.js) |
|
|
57
58
|
|
|
58
59
|
### Run locally
|
|
59
60
|
|
|
@@ -94,17 +95,17 @@ renderer.render(scene, camera);
|
|
|
94
95
|
|
|
95
96
|
Import modules by path, for example `roamwright/geometry/builder.js`. Browse the [API reference](https://enestaylan.github.io/roamwright/docs/) for signatures, usage notes and source links.
|
|
96
97
|
|
|
97
|
-
| Area | Main modules
|
|
98
|
-
| ------------------------ |
|
|
99
|
-
| Seeded generation | `math/noise.js`, `math/random.js`
|
|
100
|
-
| Geometry and terrain | `geometry/builder.js`, `geometry/heightfield.js`, `geometry/terrain-chunks.js`
|
|
101
|
-
| Static geometry assembly | `geometry/builder-frame.js`, `geometry/builder-cells.js`, `geometry/part-ranges.js`
|
|
102
|
-
| Rendering | `rendering/context.js`, `rendering/sky.js`, `rendering/water-material.js`
|
|
103
|
-
| Interiors | `geometry/room-kit.js`, `rendering/room-materials.js`, `rendering/room-space.js`, `rendering/room-light.js`
|
|
104
|
-
| Movement | `motion/player.js`, `motion/biped-stride.js`
|
|
105
|
-
| Scene playback | `runtime/cue-cursor.js`, `rendering/camera-track.js`
|
|
106
|
-
| Background jobs | `runtime/pool.js`, `runtime/worker.js`, `runtime/grid-rows.js`
|
|
107
|
-
| A world's toolchain | `scripts/world.mk` (make recipes), `scripts/serve.py` (local server), `scripts/dev-engine.py` (unreleased engine)
|
|
98
|
+
| Area | Main modules |
|
|
99
|
+
| ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
100
|
+
| Seeded generation | `math/noise.js`, `math/random.js` |
|
|
101
|
+
| Geometry and terrain | `geometry/builder.js`, `geometry/heightfield.js`, `geometry/terrain-chunks.js` |
|
|
102
|
+
| Static geometry assembly | `geometry/builder-frame.js`, `geometry/builder-cells.js`, `geometry/part-ranges.js` |
|
|
103
|
+
| Rendering | `rendering/context.js`, `rendering/sky.js`, `rendering/water-material.js` |
|
|
104
|
+
| Interiors | `geometry/room-kit.js`, `rendering/room-materials.js`, `rendering/room-space.js`, `rendering/room-light.js` |
|
|
105
|
+
| Movement | `motion/player.js`, `motion/biped-stride.js` |
|
|
106
|
+
| Scene playback | `runtime/cue-cursor.js`, `runtime/scene-script.js`, `motion/melee-combat.js`, `rendering/camera-track.js`, `rendering/scene-shots.js`, `rendering/scene-markers.js` |
|
|
107
|
+
| Background jobs | `runtime/pool.js`, `runtime/worker.js`, `runtime/grid-rows.js` |
|
|
108
|
+
| A world's toolchain | `scripts/world.mk` (make recipes), `scripts/serve.py` (local server), `scripts/dev-engine.py` (unreleased engine) |
|
|
108
109
|
|
|
109
110
|
## Contributing and license
|
|
110
111
|
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
6
|
+
<meta name="theme-color" content="#1e2a30" />
|
|
7
|
+
<title>Scenes · Roamwright</title>
|
|
8
|
+
<link rel="stylesheet" href="./showcase.css" />
|
|
9
|
+
<script type="importmap">
|
|
10
|
+
{
|
|
11
|
+
"imports": {
|
|
12
|
+
"three": "../node_modules/three/build/three.module.js",
|
|
13
|
+
"three/addons/": "../node_modules/three/examples/jsm/",
|
|
14
|
+
"roamwright": "../index.js",
|
|
15
|
+
"roamwright/": "../"
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
</script>
|
|
19
|
+
</head>
|
|
20
|
+
<body>
|
|
21
|
+
<canvas
|
|
22
|
+
tabindex="0"
|
|
23
|
+
aria-label="A sunlit stone courtyard with two dueling figures, a crossbow bolt, an energy beam, a gilded prop and a glowing scene marker"
|
|
24
|
+
></canvas>
|
|
25
|
+
<header>
|
|
26
|
+
<a class="back" href="../index.html"><span aria-hidden="true">←</span> Roamwright</a>
|
|
27
|
+
<div class="meta">
|
|
28
|
+
<a class="source" href="https://github.com/enestaylan/roamwright/blob/main/examples/scenes.js">Source</a>
|
|
29
|
+
<form method="get">
|
|
30
|
+
<label for="seed">Seed</label>
|
|
31
|
+
<input id="seed" name="seed" type="number" step="1" min="-2147483648" max="2147483647" value="42" required />
|
|
32
|
+
<button type="submit" title="Rebuild courtyard with this seed" aria-label="Rebuild courtyard with this seed">→</button>
|
|
33
|
+
</form>
|
|
34
|
+
</div>
|
|
35
|
+
</header>
|
|
36
|
+
<footer>
|
|
37
|
+
<div class="caption">
|
|
38
|
+
<h1>Scenes</h1>
|
|
39
|
+
<p>Melee duels with blade trails, flying bolts, energy beams, props, scene markers and automated camera cuts.</p>
|
|
40
|
+
<span class="status-pill" id="beat" aria-live="polite">Wide courtyard · duel</span>
|
|
41
|
+
</div>
|
|
42
|
+
<div class="tools">
|
|
43
|
+
<div class="views" role="group" aria-label="Camera views">
|
|
44
|
+
<button type="button" data-view="auto" aria-pressed="true">Auto scene</button>
|
|
45
|
+
<button type="button" data-view="wide" aria-pressed="false">Wide courtyard</button>
|
|
46
|
+
<button type="button" data-view="duel" aria-pressed="false">Duel close-up</button>
|
|
47
|
+
<button type="button" data-view="marker" aria-pressed="false">Marker & beam</button>
|
|
48
|
+
<button type="button" data-do="replay">Replay</button>
|
|
49
|
+
</div>
|
|
50
|
+
</div>
|
|
51
|
+
</footer>
|
|
52
|
+
<script type="module" src="./scenes.js"></script>
|
|
53
|
+
</body>
|
|
54
|
+
</html>
|
|
@@ -0,0 +1,594 @@
|
|
|
1
|
+
import * as THREE from 'three';
|
|
2
|
+
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
|
|
3
|
+
import {
|
|
4
|
+
createDaylightSky,
|
|
5
|
+
createEnergyBeams,
|
|
6
|
+
createFigureAssembler,
|
|
7
|
+
createFigureBuilder,
|
|
8
|
+
createFigurePose,
|
|
9
|
+
createParticleNoiseTexture,
|
|
10
|
+
createParticleSystem,
|
|
11
|
+
createPavedGroundMaterial,
|
|
12
|
+
createProjectilePool,
|
|
13
|
+
createSceneCombat,
|
|
14
|
+
createSceneCoverage,
|
|
15
|
+
createSceneMarkers,
|
|
16
|
+
createSceneProps,
|
|
17
|
+
createSceneShots,
|
|
18
|
+
figureActor,
|
|
19
|
+
GeometryBuilder,
|
|
20
|
+
geometryOf,
|
|
21
|
+
scatterTrees,
|
|
22
|
+
scatterTussocks,
|
|
23
|
+
} from 'roamwright';
|
|
24
|
+
import { sstep } from 'roamwright/math/scalar.js';
|
|
25
|
+
import { createWind } from 'roamwright/motion/wind.js';
|
|
26
|
+
import { createHeightfieldMesh } from 'roamwright/geometry/heightfield.js';
|
|
27
|
+
import { createLabelRange } from 'roamwright/rendering/label-range.js';
|
|
28
|
+
import { createWaypointBeacons } from 'roamwright/rendering/waypoint-beacons.js';
|
|
29
|
+
import { initExample } from './stage.js';
|
|
30
|
+
|
|
31
|
+
const beatEl = document.getElementById('beat');
|
|
32
|
+
const { canvas, renderer, camera, scene, worldGroup, seed, random, noise, hash } = initExample({
|
|
33
|
+
fallbackSeed: 42,
|
|
34
|
+
fov: 38,
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
// Flat cobbled stone terrace rising gently into wooded hills around the courtyard.
|
|
38
|
+
function groundAt(x, z) {
|
|
39
|
+
const r = Math.hypot(x, z);
|
|
40
|
+
return sstep(16, 62, r) * (9.5 * noise.fbm(x * 0.019, z * 0.019, 4, 13) + 3.4 * noise.ridged(x * 0.013, z * 0.013, 3, 5));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const stoneCol = new THREE.Color(0x9a9180);
|
|
44
|
+
const mossCol = new THREE.Color(0x637546);
|
|
45
|
+
const dirtCol = new THREE.Color(0x837660);
|
|
46
|
+
const ground = createHeightfieldMesh({
|
|
47
|
+
size: 240,
|
|
48
|
+
segs: 150,
|
|
49
|
+
heightAt: groundAt,
|
|
50
|
+
colorAt: (x, _y, z, _up, out) => {
|
|
51
|
+
const r = Math.hypot(x, z);
|
|
52
|
+
const yard = 1 - sstep(11.6, 13.8, r);
|
|
53
|
+
out.copy(mossCol).lerp(dirtCol, noise.fbm(x * 0.055, z * 0.055, 3, 7) * 0.65);
|
|
54
|
+
out.lerp(stoneCol, yard);
|
|
55
|
+
out.multiplyScalar(0.88 + 0.16 * noise.vnoise(x * 0.24, z * 0.24, 19));
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
ground.material = createPavedGroundMaterial({
|
|
59
|
+
origin: { x: 0, z: 0 },
|
|
60
|
+
rings: [{ x: 0, z: 0, r: 12.2, ring: 1.3 }],
|
|
61
|
+
cobble: 0.22,
|
|
62
|
+
});
|
|
63
|
+
worldGroup.add(ground);
|
|
64
|
+
|
|
65
|
+
// Grounded circular stone courtyard parapet, stepped plinth, carved standing stone, and timber archery butt.
|
|
66
|
+
// Note: GeometryBuilder.box(x, y, z, sx, sy, sz, color, ry) places the box bottom at y.
|
|
67
|
+
const masonry = new GeometryBuilder();
|
|
68
|
+
const wallCol = [0.64, 0.6, 0.52];
|
|
69
|
+
const capCol = [0.74, 0.7, 0.61];
|
|
70
|
+
const plinthCol = [0.58, 0.55, 0.49];
|
|
71
|
+
const pillarCol = [0.54, 0.52, 0.48];
|
|
72
|
+
const RING_SEGS = 24;
|
|
73
|
+
const RING_R = 11.8;
|
|
74
|
+
for (let i = 0; i < RING_SEGS; i++) {
|
|
75
|
+
const a0 = (i / RING_SEGS) * Math.PI * 2;
|
|
76
|
+
// Keep the south (camera) entrance open.
|
|
77
|
+
if (Math.sin(a0) > 0.52 && Math.abs(Math.cos(a0)) < 0.82) continue;
|
|
78
|
+
const x = Math.cos(a0) * RING_R;
|
|
79
|
+
const z = Math.sin(a0) * RING_R;
|
|
80
|
+
const ry = -a0 + Math.PI * 0.5;
|
|
81
|
+
const segW = ((2 * Math.PI * RING_R) / RING_SEGS) * 1.04;
|
|
82
|
+
masonry.box(x, -0.05, z, segW, 1.02, 0.58, wallCol, ry);
|
|
83
|
+
masonry.box(x, 0.97, z, segW + 0.08, 0.14, 0.72, capCol, ry);
|
|
84
|
+
if (i % 3 === 0) {
|
|
85
|
+
masonry.box(x, -0.05, z, 0.88, 1.72, 0.88, plinthCol, ry);
|
|
86
|
+
masonry.box(x, 1.67, z, 1.02, 0.16, 1.02, capCol, ry);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Stepped stone plinth on the left foreground for the gilded casket prop (top surface at y = 0.92).
|
|
91
|
+
const PLINTH_X = -4.2;
|
|
92
|
+
const PLINTH_Z = 1.1;
|
|
93
|
+
masonry.box(PLINTH_X, 0, PLINTH_Z, 1.48, 0.18, 1.48, plinthCol);
|
|
94
|
+
masonry.box(PLINTH_X, 0.18, PLINTH_Z, 1.06, 0.62, 1.06, wallCol);
|
|
95
|
+
masonry.box(PLINTH_X, 0.8, PLINTH_Z, 1.24, 0.12, 1.24, capCol);
|
|
96
|
+
|
|
97
|
+
// Carved standing stone on the back-right receiving the energy beam.
|
|
98
|
+
const OBELISK_X = 4.4;
|
|
99
|
+
const OBELISK_Z = -4.6;
|
|
100
|
+
masonry.box(OBELISK_X, 0, OBELISK_Z, 1.6, 0.24, 1.6, plinthCol);
|
|
101
|
+
masonry.box(OBELISK_X, 0.24, OBELISK_Z, 1.16, 0.28, 1.16, wallCol);
|
|
102
|
+
masonry.box(OBELISK_X, 0.52, OBELISK_Z, 0.82, 2.35, 0.82, pillarCol);
|
|
103
|
+
masonry.box(OBELISK_X, 2.87, OBELISK_Z, 0.56, 0.45, 0.56, capCol);
|
|
104
|
+
|
|
105
|
+
// Timber-trestle archery butt placed on the front-right, well clear of the marker ring.
|
|
106
|
+
const BUTT_X = 2.6;
|
|
107
|
+
const BUTT_Z = 3.4;
|
|
108
|
+
const woodCol = [0.38, 0.27, 0.17];
|
|
109
|
+
const strawCol = [0.76, 0.66, 0.42];
|
|
110
|
+
const ringRed = [0.64, 0.2, 0.16];
|
|
111
|
+
const buttYaw = -0.35;
|
|
112
|
+
const bc = Math.cos(buttYaw);
|
|
113
|
+
const bs = Math.sin(buttYaw);
|
|
114
|
+
const buttPt = (lx, ly, lz, sx, sy, sz, col, rx = 0, rz = 0) =>
|
|
115
|
+
masonry.box(BUTT_X + lx * bc + lz * bs, ly, BUTT_Z - lx * bs + lz * bc, sx, sy, sz, col, buttYaw, rx, rz);
|
|
116
|
+
buttPt(-0.46, 0, 0.08, 0.1, 1.75, 0.1, woodCol, 0.12, 0);
|
|
117
|
+
buttPt(0.46, 0, 0.08, 0.1, 1.75, 0.1, woodCol, 0.12, 0);
|
|
118
|
+
buttPt(0, 0, -0.58, 0.1, 1.62, 0.1, woodCol, -0.34, 0);
|
|
119
|
+
buttPt(0, 0.66, 0.06, 1.12, 0.1, 0.14, woodCol);
|
|
120
|
+
buttPt(0, 0.72, 0.02, 1.06, 1.06, 0.28, strawCol);
|
|
121
|
+
buttPt(0, 0.92, 0.15, 0.66, 0.66, 0.05, ringRed);
|
|
122
|
+
buttPt(0, 1.1, 0.18, 0.3, 0.3, 0.05, strawCol);
|
|
123
|
+
|
|
124
|
+
masonry.mesh(new THREE.MeshStandardMaterial({ vertexColors: true, roughness: 0.9 }), worldGroup, true);
|
|
125
|
+
|
|
126
|
+
const { material: leafMat } = scatterTrees({
|
|
127
|
+
parent: worldGroup,
|
|
128
|
+
noise,
|
|
129
|
+
hash,
|
|
130
|
+
seed,
|
|
131
|
+
random,
|
|
132
|
+
groundAt,
|
|
133
|
+
attempts: 64,
|
|
134
|
+
maxPerSpecies: 22,
|
|
135
|
+
sample: () => {
|
|
136
|
+
const a = random() * Math.PI * 2;
|
|
137
|
+
const r = 17 + random() * 44;
|
|
138
|
+
return [Math.cos(a) * r, Math.sin(a) * r];
|
|
139
|
+
},
|
|
140
|
+
});
|
|
141
|
+
scatterTussocks({
|
|
142
|
+
parent: worldGroup,
|
|
143
|
+
seed: seed * 13,
|
|
144
|
+
random,
|
|
145
|
+
groundAt,
|
|
146
|
+
count: 48,
|
|
147
|
+
attempts: 48,
|
|
148
|
+
material: leafMat,
|
|
149
|
+
sample: () => {
|
|
150
|
+
const a = random() * Math.PI * 2;
|
|
151
|
+
const r = 12.8 + random() * 18;
|
|
152
|
+
return [Math.cos(a) * r, Math.sin(a) * r];
|
|
153
|
+
},
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
const { sun } = createDaylightSky({
|
|
157
|
+
scene,
|
|
158
|
+
renderer,
|
|
159
|
+
noise,
|
|
160
|
+
sky: { sunDir: [-0.62, 0.44, 0.64] },
|
|
161
|
+
sunPosition: [-14, 22, 14],
|
|
162
|
+
shadowRadius: 15,
|
|
163
|
+
shadowFar: 60,
|
|
164
|
+
normalBias: 0.025,
|
|
165
|
+
fogColor: 0xd6dfe4,
|
|
166
|
+
fogDensity: 0.0036,
|
|
167
|
+
});
|
|
168
|
+
scene.add(sun.target);
|
|
169
|
+
|
|
170
|
+
// Seed-varied palettes so ?seed= visibly refreshes the cast and beam tint.
|
|
171
|
+
const CLOAKS = [0x6e2b2b, 0x294c60, 0x35583a, 0x5c3a66];
|
|
172
|
+
const TUNICS = [0x3d4b5c, 0x614732, 0x465239, 0x593940];
|
|
173
|
+
const sIdx = Math.abs(seed);
|
|
174
|
+
const figMat = new THREE.MeshStandardMaterial({ vertexColors: true, roughness: 0.82 });
|
|
175
|
+
const { kit, buildBody } = createFigureBuilder();
|
|
176
|
+
const { assembleFigure } = createFigureAssembler({ material: figMat, holds: kit.holds });
|
|
177
|
+
|
|
178
|
+
function spawnActor(id, look, x, z, yaw) {
|
|
179
|
+
const mk = level => {
|
|
180
|
+
const built = buildBody(look, seed + id.length * 17, level);
|
|
181
|
+
return { ...built, geo: geometryOf(built.parts) };
|
|
182
|
+
};
|
|
183
|
+
const figure = assembleFigure(look, 'human', mk(1), mk(0));
|
|
184
|
+
figure.lo.visible = false;
|
|
185
|
+
figure.group.traverse(o => {
|
|
186
|
+
if (o.isMesh) o.castShadow = true;
|
|
187
|
+
});
|
|
188
|
+
worldGroup.add(figure.group);
|
|
189
|
+
const a = figureActor(figure, { id, look, seed: (sIdx % 97) / 100 + id.length * 0.07, phase: id.length * 0.8 });
|
|
190
|
+
a.x = x;
|
|
191
|
+
a.y = groundAt(x, z);
|
|
192
|
+
a.z = z;
|
|
193
|
+
a.yaw = yaw;
|
|
194
|
+
a.active = true;
|
|
195
|
+
a.inScene = true;
|
|
196
|
+
a.built = true;
|
|
197
|
+
a.height = 1.82;
|
|
198
|
+
a.def = { look };
|
|
199
|
+
return a;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
const duelistA = spawnActor(
|
|
203
|
+
'warden',
|
|
204
|
+
{
|
|
205
|
+
h: 1.02,
|
|
206
|
+
w: 1.02,
|
|
207
|
+
skin: 0xc9a382,
|
|
208
|
+
hair: 0x2f2318,
|
|
209
|
+
hairStyle: 'short',
|
|
210
|
+
garb: 'armour',
|
|
211
|
+
c1: TUNICS[sIdx % TUNICS.length],
|
|
212
|
+
c2: 0x2b2520,
|
|
213
|
+
cloak: CLOAKS[sIdx % CLOAKS.length],
|
|
214
|
+
item: 'sword',
|
|
215
|
+
shield: true,
|
|
216
|
+
beard: 1,
|
|
217
|
+
},
|
|
218
|
+
-1.15,
|
|
219
|
+
0.5,
|
|
220
|
+
Math.PI * 0.5,
|
|
221
|
+
);
|
|
222
|
+
const duelistB = spawnActor(
|
|
223
|
+
'challenger',
|
|
224
|
+
{
|
|
225
|
+
h: 1.0,
|
|
226
|
+
w: 0.98,
|
|
227
|
+
skin: 0xb98d6c,
|
|
228
|
+
hair: 0x3b2c1e,
|
|
229
|
+
hairStyle: 'long',
|
|
230
|
+
garb: 'leather',
|
|
231
|
+
c1: TUNICS[(sIdx + 1) % TUNICS.length],
|
|
232
|
+
c2: 0x22201e,
|
|
233
|
+
cloak: CLOAKS[(sIdx + 2) % CLOAKS.length],
|
|
234
|
+
item: 'sword',
|
|
235
|
+
beard: 0,
|
|
236
|
+
},
|
|
237
|
+
1.15,
|
|
238
|
+
0.5,
|
|
239
|
+
-Math.PI * 0.5,
|
|
240
|
+
);
|
|
241
|
+
const caster = spawnActor(
|
|
242
|
+
'channeler',
|
|
243
|
+
{
|
|
244
|
+
h: 0.98,
|
|
245
|
+
w: 0.95,
|
|
246
|
+
skin: 0xd0af90,
|
|
247
|
+
hair: 0x5c5349,
|
|
248
|
+
hairStyle: 'long',
|
|
249
|
+
garb: 'robe',
|
|
250
|
+
c1: TUNICS[(sIdx + 2) % TUNICS.length],
|
|
251
|
+
c2: 0x2a2433,
|
|
252
|
+
cloak: CLOAKS[(sIdx + 1) % CLOAKS.length],
|
|
253
|
+
item: 'staff',
|
|
254
|
+
beard: 1,
|
|
255
|
+
},
|
|
256
|
+
-5.4,
|
|
257
|
+
-4.1,
|
|
258
|
+
Math.PI * 0.52,
|
|
259
|
+
);
|
|
260
|
+
const actorMap = { warden: duelistA, challenger: duelistB, channeler: caster };
|
|
261
|
+
const actorList = [duelistA, duelistB, caster];
|
|
262
|
+
|
|
263
|
+
const clock = { t: 0, sceneT: 0 };
|
|
264
|
+
const { wind, update: updateWind } = createWind({ speed: 2.2, direction: 0.4 });
|
|
265
|
+
const motion = createFigurePose({ ground: groundAt, wind, clock: () => clock.t });
|
|
266
|
+
|
|
267
|
+
// Particles for clash sparks, bolt impacts, and beam splashes.
|
|
268
|
+
const pointScale = { value: 400 };
|
|
269
|
+
const noiseTex = createParticleNoiseTexture({ noise, size: 64 });
|
|
270
|
+
const particles = createParticleSystem({
|
|
271
|
+
scene,
|
|
272
|
+
pointScale,
|
|
273
|
+
sceneDepth: { uDepth: { value: null }, uDepthPx: { value: new THREE.Vector2(1, 1) }, uSoft: { value: 0 } },
|
|
274
|
+
elapsed: () => clock.t,
|
|
275
|
+
noiseTexture: noiseTex,
|
|
276
|
+
});
|
|
277
|
+
const sparks = particles.makeParticles(220, true);
|
|
278
|
+
function emitSparks(x, y, z, col, count = 14) {
|
|
279
|
+
for (let i = 0; i < count; i++) {
|
|
280
|
+
const a = random() * Math.PI * 2;
|
|
281
|
+
const sp = 1.4 + random() * 3.0;
|
|
282
|
+
Object.assign(particles.spawn, {
|
|
283
|
+
x,
|
|
284
|
+
y,
|
|
285
|
+
z,
|
|
286
|
+
vx: Math.cos(a) * sp,
|
|
287
|
+
vy: 1.1 + random() * 2.4,
|
|
288
|
+
vz: Math.sin(a) * sp,
|
|
289
|
+
life: 0.25 + random() * 0.22,
|
|
290
|
+
size: 0.22 + random() * 0.16,
|
|
291
|
+
r: col.r,
|
|
292
|
+
g: col.g,
|
|
293
|
+
b: col.b,
|
|
294
|
+
drag: 1.8,
|
|
295
|
+
grav: 6,
|
|
296
|
+
});
|
|
297
|
+
particles.pSpawn(sparks);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
const SPARK_COL = new THREE.Color(1, 0.82, 0.35);
|
|
301
|
+
const BEAM_COLS = [new THREE.Color(0.28, 0.72, 1.0), new THREE.Color(1.0, 0.56, 0.2), new THREE.Color(0.72, 0.38, 1.0)];
|
|
302
|
+
const beamTint = BEAM_COLS[sIdx % BEAM_COLS.length];
|
|
303
|
+
|
|
304
|
+
// Scene combat (duels, cuts, recoil, blade trails).
|
|
305
|
+
const combat = createSceneCombat({
|
|
306
|
+
scene,
|
|
307
|
+
actors: actorMap,
|
|
308
|
+
actorList,
|
|
309
|
+
getSpaceId: () => 'yard',
|
|
310
|
+
getElapsed: () => clock.t,
|
|
311
|
+
groundAt,
|
|
312
|
+
hash,
|
|
313
|
+
trailLayer: 0,
|
|
314
|
+
onParry: (x, y, z) => emitSparks(x, y, z, SPARK_COL, 18),
|
|
315
|
+
onHit: (x, y, z) => emitSparks(x, y, z, SPARK_COL, 12),
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
// Projectiles (crossbow bolts lodging in the timber archery butt).
|
|
319
|
+
function resolvePos(spec, out) {
|
|
320
|
+
if (typeof spec === 'string' && actorMap[spec]) {
|
|
321
|
+
const a = actorMap[spec];
|
|
322
|
+
return out.set(a.x, a.y + 1.35, a.z);
|
|
323
|
+
}
|
|
324
|
+
return out.set(spec[0], spec[1], spec[2]);
|
|
325
|
+
}
|
|
326
|
+
const projectiles = createProjectilePool({
|
|
327
|
+
scene,
|
|
328
|
+
actors: actorMap,
|
|
329
|
+
resolvePos,
|
|
330
|
+
groundAt,
|
|
331
|
+
layer: 0,
|
|
332
|
+
onGroundHit: p => emitSparks(p.x, p.y, p.z, SPARK_COL, 8),
|
|
333
|
+
onShieldHit: p => emitSparks(p.x, p.y, p.z, SPARK_COL, 10),
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
// Energy beams (ribbon pool + gather/stream/splash lifecycle).
|
|
337
|
+
const beams = createEnergyBeams({
|
|
338
|
+
scene,
|
|
339
|
+
actors: actorMap,
|
|
340
|
+
resolvePos,
|
|
341
|
+
groundAt,
|
|
342
|
+
colors: { arcane: [beamTint.r, beamTint.g, beamTint.b] },
|
|
343
|
+
styles: { arcane: { speed: 70, arc: 0.035, writhe: 0.42 } },
|
|
344
|
+
onSplashParticle: (x, y, z, _vx, _vy, _vz, _life, _size, r, g, b) => {
|
|
345
|
+
emitSparks(x, y, z, { r, g, b }, 2);
|
|
346
|
+
},
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
// Sculpted gilded chest prop resting cleanly on the stone plinth (bottom at y = 0 in local space).
|
|
350
|
+
const propCasket = new GeometryBuilder();
|
|
351
|
+
propCasket.box(0, 0, 0, 0.62, 0.34, 0.4, [0.56, 0.39, 0.16]);
|
|
352
|
+
propCasket.box(0, 0.34, 0, 0.66, 0.09, 0.44, [0.85, 0.68, 0.24]);
|
|
353
|
+
propCasket.box(0, 0.12, 0.2, 0.14, 0.14, 0.04, [0.92, 0.78, 0.3]);
|
|
354
|
+
const propMat = new THREE.MeshStandardMaterial({ vertexColors: true, roughness: 0.4, metalness: 0.55 });
|
|
355
|
+
const props = createSceneProps({
|
|
356
|
+
scene,
|
|
357
|
+
groundAt,
|
|
358
|
+
makers: {
|
|
359
|
+
casket: () => {
|
|
360
|
+
const m = new THREE.Mesh(geometryOf(propCasket.parts()), propMat);
|
|
361
|
+
m.castShadow = true;
|
|
362
|
+
return m;
|
|
363
|
+
},
|
|
364
|
+
},
|
|
365
|
+
});
|
|
366
|
+
|
|
367
|
+
// Scene marker (light shaft, instanced ground ring, bobbing gem, pill label) placed cleanly on the right.
|
|
368
|
+
const beaconTime = { value: 0 };
|
|
369
|
+
const beacons = createWaypointBeacons({
|
|
370
|
+
camera,
|
|
371
|
+
ground: groundAt,
|
|
372
|
+
heightProbe: (x, z) => Promise.resolve(groundAt(x, z)),
|
|
373
|
+
time: beaconTime,
|
|
374
|
+
night: { value: 0.15 },
|
|
375
|
+
});
|
|
376
|
+
const labelRange = createLabelRange(4, 34, 8, 5);
|
|
377
|
+
const vp = { width: 1280, height: 720 };
|
|
378
|
+
const markers = createSceneMarkers({
|
|
379
|
+
camera,
|
|
380
|
+
defaultParent: worldGroup,
|
|
381
|
+
getViewport: () => vp,
|
|
382
|
+
labelRange,
|
|
383
|
+
createBeam: (color, roof) => beacons.beacon(color, roof),
|
|
384
|
+
beamMaterial: color => beacons.beaconMaterial(color),
|
|
385
|
+
labelText: ev => ev.title,
|
|
386
|
+
});
|
|
387
|
+
markers.addMarkers([
|
|
388
|
+
{
|
|
389
|
+
ev: { id: 'skirmish', title: 'Courtyard Skirmish' },
|
|
390
|
+
spaceId: 'yard',
|
|
391
|
+
parent: worldGroup,
|
|
392
|
+
x: 5.0,
|
|
393
|
+
y: groundAt(5.0, -0.3),
|
|
394
|
+
z: -0.3,
|
|
395
|
+
roof: null,
|
|
396
|
+
inside: false,
|
|
397
|
+
},
|
|
398
|
+
]);
|
|
399
|
+
markers.refresh({ shown: true, isDone: () => false, isEligible: () => true });
|
|
400
|
+
|
|
401
|
+
// Automated camera shots and coverage.
|
|
402
|
+
const yardSpace = { id: 'yard', indoors: false, lowLens: false, ground: groundAt };
|
|
403
|
+
const coverage = createSceneCoverage({
|
|
404
|
+
actorList,
|
|
405
|
+
getSpace: () => yardSpace,
|
|
406
|
+
getFrame: () => frameNum,
|
|
407
|
+
});
|
|
408
|
+
const shots = createSceneShots({
|
|
409
|
+
camera,
|
|
410
|
+
actorList,
|
|
411
|
+
actors: actorMap,
|
|
412
|
+
getSpace: () => yardSpace,
|
|
413
|
+
getElapsed: () => clock.t,
|
|
414
|
+
getFrame: () => frameNum,
|
|
415
|
+
coverShot: coverage.coverShot,
|
|
416
|
+
setFov: fov => {
|
|
417
|
+
if (Math.abs(camera.fov - fov) > 0.05) {
|
|
418
|
+
camera.fov = fov;
|
|
419
|
+
camera.updateProjectionMatrix();
|
|
420
|
+
}
|
|
421
|
+
},
|
|
422
|
+
});
|
|
423
|
+
|
|
424
|
+
const SCENE_LEN = 12;
|
|
425
|
+
const sceneDef = {
|
|
426
|
+
dur: SCENE_LEN,
|
|
427
|
+
coverage: false,
|
|
428
|
+
cam: [
|
|
429
|
+
[0, -0.4, 3.8, 12.2, 0.5, 1.35, -0.8, 1, 38],
|
|
430
|
+
[4.4, 0.8, 3.5, 11.6, 0.5, 1.35, -0.8, 0, 38],
|
|
431
|
+
[4.6, 0.1, 1.9, 5.2, 0.0, 1.25, 0.4, 1, 34],
|
|
432
|
+
[8.2, 1.8, 2.0, 4.9, 0.0, 1.25, 0.4, 0, 34],
|
|
433
|
+
[8.4, 2.6, 3.1, 10.2, 2.1, 1.5, -1.6, 1, 38],
|
|
434
|
+
[12.0, -0.4, 3.8, 12.2, 0.5, 1.35, -0.8, 0, 38],
|
|
435
|
+
],
|
|
436
|
+
};
|
|
437
|
+
const directorState = {
|
|
438
|
+
t: 0,
|
|
439
|
+
A: { x: 0, y: 0, z: 0 },
|
|
440
|
+
p: new THREE.Vector3(),
|
|
441
|
+
l: new THREE.Vector3(),
|
|
442
|
+
rig: new THREE.PerspectiveCamera(),
|
|
443
|
+
blend: 0,
|
|
444
|
+
fromPos: new THREE.Vector3(),
|
|
445
|
+
fromQuat: new THREE.Quaternion(),
|
|
446
|
+
};
|
|
447
|
+
|
|
448
|
+
const controls = new OrbitControls(camera, canvas);
|
|
449
|
+
controls.enableDamping = true;
|
|
450
|
+
controls.maxPolarAngle = Math.PI * 0.485;
|
|
451
|
+
controls.minDistance = 2.5;
|
|
452
|
+
controls.maxDistance = 28;
|
|
453
|
+
controls.enabled = false;
|
|
454
|
+
|
|
455
|
+
let viewMode = 'auto';
|
|
456
|
+
const VIEWS = {
|
|
457
|
+
wide: { eye: [-0.4, 3.8, 12.2], target: [0.5, 1.35, -0.8] },
|
|
458
|
+
duel: { eye: [0.1, 1.9, 5.2], target: [0.0, 1.25, 0.45] },
|
|
459
|
+
marker: { eye: [2.4, 3.0, 9.0], target: [3.2, 1.65, -2.0] },
|
|
460
|
+
};
|
|
461
|
+
function setView(mode) {
|
|
462
|
+
viewMode = mode;
|
|
463
|
+
for (const btn of document.querySelectorAll('[data-view]')) {
|
|
464
|
+
btn.setAttribute('aria-pressed', String(btn.dataset.view === mode));
|
|
465
|
+
}
|
|
466
|
+
if (mode === 'auto') {
|
|
467
|
+
controls.enabled = false;
|
|
468
|
+
} else {
|
|
469
|
+
const v = VIEWS[mode];
|
|
470
|
+
camera.fov = 38;
|
|
471
|
+
camera.updateProjectionMatrix();
|
|
472
|
+
camera.position.set(v.eye[0], v.eye[1], v.eye[2]);
|
|
473
|
+
controls.target.set(v.target[0], v.target[1], v.target[2]);
|
|
474
|
+
controls.enabled = true;
|
|
475
|
+
controls.update();
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
for (const btn of document.querySelectorAll('[data-view]')) {
|
|
479
|
+
btn.addEventListener('click', () => setView(btn.dataset.view));
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
let frameNum = 0;
|
|
483
|
+
let boltFired = false;
|
|
484
|
+
let propHidden = false;
|
|
485
|
+
let beamFired2 = false;
|
|
486
|
+
|
|
487
|
+
function startCycle() {
|
|
488
|
+
clock.sceneT = 0;
|
|
489
|
+
boltFired = false;
|
|
490
|
+
propHidden = false;
|
|
491
|
+
beamFired2 = false;
|
|
492
|
+
combat.clearCombat();
|
|
493
|
+
projectiles.clear();
|
|
494
|
+
beams.clear();
|
|
495
|
+
props.clear();
|
|
496
|
+
|
|
497
|
+
duelistA.x = -1.15;
|
|
498
|
+
duelistA.z = 0.5;
|
|
499
|
+
duelistA.yaw = Math.PI * 0.5;
|
|
500
|
+
duelistA.pose = 'guard';
|
|
501
|
+
duelistB.x = 1.15;
|
|
502
|
+
duelistB.z = 0.5;
|
|
503
|
+
duelistB.yaw = -Math.PI * 0.5;
|
|
504
|
+
duelistB.pose = 'guard';
|
|
505
|
+
caster.pose = 'cast';
|
|
506
|
+
|
|
507
|
+
combat.startDuel(duelistA, duelistB, SCENE_LEN - 0.5, 'parry', 'a', seed);
|
|
508
|
+
beams.start('arcane', 'channeler', [OBELISK_X, 2.35, OBELISK_Z], 5.6);
|
|
509
|
+
projectiles.launch('quarrel', [-4.6, 1.55, 2.4], [BUTT_X - 0.05, 1.28, BUTT_Z + 0.12], 0.52);
|
|
510
|
+
props.show('casket', PLINTH_X - 0.14, 0.92, PLINTH_Z, 1);
|
|
511
|
+
props.moveTo('casket', PLINTH_X + 0.14, 0.92, PLINTH_Z, 1, 2.8);
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
document.querySelector('[data-do="replay"]')?.addEventListener('click', () => {
|
|
515
|
+
startCycle();
|
|
516
|
+
setView('auto');
|
|
517
|
+
});
|
|
518
|
+
|
|
519
|
+
function resize() {
|
|
520
|
+
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
|
|
521
|
+
renderer.setSize(canvas.clientWidth, canvas.clientHeight, false);
|
|
522
|
+
vp.width = Math.max(1, canvas.clientWidth);
|
|
523
|
+
vp.height = Math.max(1, canvas.clientHeight);
|
|
524
|
+
camera.aspect = vp.width / vp.height;
|
|
525
|
+
pointScale.value = vp.height * 0.5 * Math.min(devicePixelRatio, 2);
|
|
526
|
+
camera.updateProjectionMatrix();
|
|
527
|
+
}
|
|
528
|
+
window.addEventListener('resize', resize);
|
|
529
|
+
resize();
|
|
530
|
+
|
|
531
|
+
startCycle();
|
|
532
|
+
|
|
533
|
+
function stepScene(dt) {
|
|
534
|
+
frameNum++;
|
|
535
|
+
clock.t += dt;
|
|
536
|
+
clock.sceneT += dt;
|
|
537
|
+
if (clock.sceneT >= SCENE_LEN) startCycle();
|
|
538
|
+
|
|
539
|
+
if (!boltFired && clock.sceneT > 4.2) {
|
|
540
|
+
boltFired = true;
|
|
541
|
+
projectiles.launch('quarrel', [-4.6, 1.55, 2.6], [BUTT_X + 0.08, 1.15, BUTT_Z + 0.12], 0.5);
|
|
542
|
+
}
|
|
543
|
+
if (!propHidden && clock.sceneT > 7.6) {
|
|
544
|
+
propHidden = true;
|
|
545
|
+
props.hide('casket');
|
|
546
|
+
}
|
|
547
|
+
if (!beamFired2 && clock.sceneT > 6.5) {
|
|
548
|
+
beamFired2 = true;
|
|
549
|
+
beams.start('arcane', 'channeler', [OBELISK_X, 2.35, OBELISK_Z], 5.2);
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
beaconTime.value = clock.t;
|
|
553
|
+
updateWind(clock.t, 0);
|
|
554
|
+
combat.updateCombat(dt);
|
|
555
|
+
for (let i = 0; i < actorList.length; i++) {
|
|
556
|
+
motion.travel(actorList[i], dt);
|
|
557
|
+
motion.poseActor(actorList[i], 0, dt, clock.t);
|
|
558
|
+
}
|
|
559
|
+
combat.applyMeleeContactIK();
|
|
560
|
+
projectiles.update(dt);
|
|
561
|
+
beams.update(dt);
|
|
562
|
+
props.update(dt);
|
|
563
|
+
particles.fxU.uTime.value = clock.t;
|
|
564
|
+
particles.pFlush(sparks);
|
|
565
|
+
markers.update({ time: clock.t, spaceId: 'yard' });
|
|
566
|
+
beacons.updateBeacons();
|
|
567
|
+
|
|
568
|
+
if (viewMode === 'auto') {
|
|
569
|
+
directorState.t = clock.sceneT;
|
|
570
|
+
shots.shoot(directorState, sceneDef, dt);
|
|
571
|
+
const label =
|
|
572
|
+
clock.sceneT < 4.6
|
|
573
|
+
? 'Shot 1 · wide courtyard, duel & beam'
|
|
574
|
+
: clock.sceneT < 8.4
|
|
575
|
+
? 'Shot 2 · duel close-up & crossbow bolt'
|
|
576
|
+
: 'Shot 3 · marker, beam & prop reset';
|
|
577
|
+
if (beatEl.textContent !== label) beatEl.textContent = label;
|
|
578
|
+
} else {
|
|
579
|
+
controls.update();
|
|
580
|
+
const label = viewMode === 'wide' ? 'Orbit · wide courtyard' : viewMode === 'duel' ? 'Orbit · duel close-up' : 'Orbit · marker & beam';
|
|
581
|
+
if (beatEl.textContent !== label) beatEl.textContent = label;
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
// Advance slightly so the opening frame already shows mid-swing duelists, streaming energy ribbon, and lodged bolt.
|
|
586
|
+
for (let i = 0; i < 18; i++) stepScene(0.035);
|
|
587
|
+
|
|
588
|
+
let last = performance.now();
|
|
589
|
+
renderer.setAnimationLoop(now => {
|
|
590
|
+
const dt = Math.min(0.05, (now - last) / 1000);
|
|
591
|
+
last = now;
|
|
592
|
+
stepScene(dt);
|
|
593
|
+
renderer.render(scene, camera);
|
|
594
|
+
});
|