@wildshard/sdk 0.3.0 → 0.3.2
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/GUIDE.md +10 -2
- package/docs/api/EXPORT-TIERS.md +7 -4
- package/lint/export-tiers.json +3 -0
- package/lint/host-callbacks.mjs +1 -1
- package/package.json +9 -5
- package/scripts/bake/template-skins.mjs +6 -3
- package/scripts/bake/template-warden.mjs +25 -0
- package/scripts/export-ci21-guests.mjs +89 -0
- package/scripts/scratch-sweep.mjs +3 -1
- package/src/cli/hero/hero.ts +45 -2
- package/src/sharddev/as/prelude.ts +67 -0
- package/src/sharddev/authorLint.ts +45 -0
- package/src/sharddev/bake/compileScript.ts +6 -0
- package/src/sharddev/bake/terrain.ts +11 -2
- package/src/sharddev/checkProject.ts +7 -18
- package/src/sharddev/engineMusic.ts +23 -0
- package/src/sharddev/materials.ts +7 -3
- package/src/sharddev/project.ts +5 -0
- package/src/sharddev/refusals.ts +1 -1
- package/src/sharddev/scene/author.ts +116 -11
- package/src/sharddev/scene/canvas.ts +2 -3
- package/src/sharddev/scene/description.ts +55 -2
- package/src/sharddev/scene/lower.ts +144 -29
- package/src/sharddev/scene/shard.ts +5 -2
- package/src/sharddev/scene/shardfile.ts +385 -72
- package/src/sharddev/watch/page.ts +116 -29
- package/src/sharddev/watch/pageEntry.ts +38 -2
- package/src/sharddev/watch/parity-baseline.json +22 -0
- package/src/sharddev/watch/parity.mjs +168 -0
- package/src/sharddev/watch/proof.mjs +129 -22
- package/src/sharddev/watch/protocol.ts +66 -8
- package/src/sharddev/watch/watch.ts +215 -51
- package/src/shards/_template/assets/3058c100bc477fd6fe8268f33b53756b8a2556e7e41c58b2216c703ca7b042c6 +1 -0
- package/src/shards/_template/assets/8a0440f392737a31cf0926a3c7dc011c320144972882945a5462c893e817d94a +0 -0
- package/src/shards/_template/behaviour/door.as +16 -26
- package/src/shards/_template/card/landscape.jpg +0 -0
- package/src/shards/_template/card/portrait.jpg +0 -0
- package/src/shards/_template/card/thumb.jpg +0 -0
- package/src/shards/_template/data/clientScripts.json +43 -43
- package/src/shards/_template/data/creatures.json +2 -2
- package/src/shards/_template/data/look.json +141 -13
- package/src/shards/_template/data/rows.json +20 -2
- package/src/shards/_template/data/skins.json +32 -0
- package/src/shards/_template/data/water.json +18 -0
- package/src/shards/_template/generators/product.ts +5 -1
- package/src/shards/_template/generators/warden.ts +273 -0
- package/src/shards/_template/generators/world.ts +52 -21
- package/src/shards/_template/hero.json +6 -6
- package/src/shards/authoring-slice/generators/shard.ts +9 -1
- package/src/shards/authoring-slice/generators/sky.ts +64 -0
- package/src/shards/authoring-slice/generators/template-sky.ts +27 -0
- package/src/shards/authoring-slice/generators/textures.ts +59 -0
- package/src/shards/authoring-slice/generators/world.ts +108 -5
- package/src/shards/mossgate/generators/shard.ts +6 -0
- package/src/shards/mossgate/generators/sky.ts +64 -0
- package/src/shards/mossgate/generators/textures.ts +249 -0
- package/src/shards/mossgate/generators/world.ts +998 -0
- package/src/shards/mossgate/shard.config.ts +7 -0
- package/scripts/shard-output-report.d.mts +0 -9
- package/scripts/shard-output-report.mjs +0 -85
- package/scripts/shard-platform-cli.mjs +0 -93
|
@@ -128,10 +128,11 @@ export function buildTemplateWorld(ctx: TemplateWorldPorts, propCount: number):
|
|
|
128
128
|
ctx.root.add(gate.vines); ctx.piece({ id: 'template.mossgate-vines', name: 'Moss gate vines', category: 'nature', file, object: gate.vines });
|
|
129
129
|
ctx.root.add(gate.panel); ctx.piece({ id: 'template.mossgate', name: 'Moss gate', category: 'nature', file, object: gate.panel, colliders: gate.panelColliders, active: () => true });
|
|
130
130
|
// Mossgate Hollow v3 (MH-3): brazier B's field raises the pond's stones out of the water, and brazier C's takes away the
|
|
131
|
-
// bars across the arena's one way in. The
|
|
131
|
+
// bars across the arena's one way in. The sunk slabs are static and have no collider on purpose: before B the walk ends in
|
|
132
|
+
// the water (MG10's proof swims across), so B is what makes the crossing dry (the M4.10 review asked; this stays the design).
|
|
132
133
|
const stones = pondStones();
|
|
133
134
|
ctx.root.add(stones.raised); ctx.piece({ id: 'template.pond-stones', name: 'Pond stepping stones', category: 'nature', file, object: stones.raised, colliders: stones.colliders, active: () => false });
|
|
134
|
-
ctx.root.add(stones.sunk); ctx.piece({ id: 'template.pond-stones-sunk', name: 'Sunken pond stones', category: 'nature', file, object: stones.sunk
|
|
135
|
+
ctx.root.add(stones.sunk); ctx.piece({ id: 'template.pond-stones-sunk', name: 'Sunken pond stones', category: 'nature', file, object: stones.sunk });
|
|
135
136
|
const planting = pondPlanting(heightAt);
|
|
136
137
|
ctx.root.add(planting); ctx.piece({ id: 'template.pond-planting', name: 'Pond reeds, lily pads and lip', category: 'nature', file, object: planting });
|
|
137
138
|
const arena = arenaRing(heightAt);
|
|
@@ -444,7 +445,10 @@ export function hutLamp(heightAt: (x: number, z: number) => number): { mesh: Mes
|
|
|
444
445
|
// M2: and the hut room's hanging lamp over the table, in the same whole (one draw)
|
|
445
446
|
const room = new BoxGeometry(0.3, 0.38, 0.3).translate(layout.HUT.x + 0.8 - x, heightAt(layout.HUT.x, layout.HUT.z) + 2.15 - y, layout.HUT.z - 0.5 - z);
|
|
446
447
|
const geometry = mergeGeometries([new BoxGeometry(0.36, 0.48, 0.36), room]).toNonIndexed(); geometry.deleteAttribute('uv');
|
|
447
|
-
|
|
448
|
+
// M4.10: warm glass, brightest low where the wick burns (the cleanroom's lamp glass gradient), dimmer under the lid
|
|
449
|
+
const p = geometry.getAttribute('position'), colour = new Float32Array(p.count * 3);
|
|
450
|
+
for (let i = 0; i < p.count; i++) { const k = p.getY(i) > 0.1 ? 0.62 : 1; colour.set([k, k * (0.9 + 0.1 * k), k * (0.8 + 0.2 * k)], i * 3); }
|
|
451
|
+
geometry.setAttribute('color', new Float32BufferAttribute(colour, 3));
|
|
448
452
|
const mesh = new Mesh(geometry, new MeshStandardMaterial({ color: 0xffffff, vertexColors: true })); mesh.castShadow = false;
|
|
449
453
|
return { mesh, transform: new Matrix4().makeTranslation(x, y, z) };
|
|
450
454
|
}
|
|
@@ -460,11 +464,28 @@ export function brazierFlame(heightAt: (x: number, z: number) => number, which =
|
|
|
460
464
|
if (which === 1) { const [bx = 0, bz = 0] = layout.ROW[0] ?? []; flameCones(flame, bx, heightAt(bx, bz) + 1.5, bz); }
|
|
461
465
|
return flame;
|
|
462
466
|
}
|
|
463
|
-
/**
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
467
|
+
/**
|
|
468
|
+
* M4.10 (the cleanroom's layered flame cards, MG textures.js and world.js:338): one flame tongue, a cone whose vertex
|
|
469
|
+
* colours run from `base` at its foot to `tip`, fading to dark at its point. The flame look entry is additive and reads the
|
|
470
|
+
* vertex colours, so a tongue fades out where it is dark and the tongues overlapping in the bowl add up to a hot core.
|
|
471
|
+
*/
|
|
472
|
+
const FLAME_OUTER: readonly [readonly [number, number, number], readonly [number, number, number]] = [[1, 0.42, 0.07], [0.22, 0.03, 0]];
|
|
473
|
+
const FLAME_INNER: readonly [readonly [number, number, number], readonly [number, number, number]] = [[1, 0.78, 0.32], [0.45, 0.13, 0.01]];
|
|
474
|
+
function tongue(r: number, h: number, [base, tip]: typeof FLAME_OUTER): Mesh {
|
|
475
|
+
const geometry = foliageUv(new CylinderGeometry(0, r, h, 6, 1, true), 1), p = geometry.getAttribute('position'), colour = new Float32Array(p.count * 3);
|
|
476
|
+
for (let i = 0; i < p.count; i++) {
|
|
477
|
+
const t = Math.min(1, Math.max(0, p.getY(i) / h + 0.5)), k = t * t;
|
|
478
|
+
for (let c = 0; c < 3; c++) colour[i * 3 + c] = (base[c] ?? 0) * (1 - k) + (tip[c] ?? 0) * k;
|
|
479
|
+
}
|
|
480
|
+
geometry.setAttribute('color', new Float32BufferAttribute(colour, 3));
|
|
481
|
+
return new Mesh(geometry, foliageMaterial(0xffffff));
|
|
482
|
+
}
|
|
483
|
+
/** Five outer tongues and three inner ones in a bowl whose rim is at y (M4.10: was five opaque faceted cones). */
|
|
484
|
+
function flameCones(flame: Group, x: number, y: number, z: number, s = 1): void {
|
|
485
|
+
const outer: [number, number, number, number][] = [[0, 0, 0.42, 1.3], [0.24, 0.12, 0.24, 0.8], [-0.22, 0.16, 0.26, 0.9], [0.08, -0.25, 0.22, 0.75], [-0.14, -0.18, 0.2, 0.65]];
|
|
486
|
+
const inner: [number, number, number, number][] = [[0.02, 0.01, 0.24, 0.95], [0.12, -0.08, 0.15, 0.6], [-0.1, 0.07, 0.15, 0.55]];
|
|
487
|
+
for (const [layer, cones, seed] of [[FLAME_OUTER, outer, 110], [FLAME_INNER, inner, 112]] as const) cones.forEach(([dx, dz, r, h], i) => {
|
|
488
|
+
const cone = tongue(r * s, h * s, layer); cone.position.set(x + dx * s, y + (h * s) / 2 - 0.05, z + dz * s); cone.rotation.set(jitter(i, seed + 1) * 0.12, jitter(i, seed) * 1.2, jitter(i, seed + 2) * 0.12); flame.add(cone);
|
|
468
489
|
});
|
|
469
490
|
}
|
|
470
491
|
|
|
@@ -581,19 +602,26 @@ export function mossGate(heightAt: (x: number, z: number) => number): { frame: G
|
|
|
581
602
|
}
|
|
582
603
|
|
|
583
604
|
/**
|
|
584
|
-
* The moss bridge (MH-3):
|
|
585
|
-
* `raised` stands their moss-capped tops 0.
|
|
586
|
-
* same pillars, a little thinner
|
|
605
|
+
* The moss bridge (MH-3): six stone pillars across the pond at `layout.POND` (radius 5, bed −3, water at 0), west to east.
|
|
606
|
+
* `raised` stands their moss-capped tops 0.3 m over the water, with colliders, for brazier B's field to show; `sunk` is the
|
|
607
|
+
* same pillars, a little thinner, as wet slabs awash at the surface (M4.10, the cleanroom's look) with no collider, so before
|
|
608
|
+
* B the walk ends in the water.
|
|
587
609
|
*/
|
|
610
|
+
/** The raised bridge stones' top over the water, the sunk slabs' top, and their wet stone. */
|
|
611
|
+
const STONE_TOP = 0.3, SUNK_TOP = 0.05, WET_STONE = 0x5a524a;
|
|
588
612
|
export function pondStones(): { raised: Group; sunk: Group; colliders: Colliders } {
|
|
589
613
|
const { x: cx, z: cz } = layout.POND, raised = new Group(), sunk = new Group(), colliders: Colliders = [], BED = -3, w = 1.75;
|
|
590
614
|
for (let i = 0; i < BRIDGE_STONES; i++) {
|
|
591
615
|
const x = cx - BRIDGE_REACH + i * ((BRIDGE_REACH * 2) / (BRIDGE_STONES - 1)), z = cz + jitter(i, 80) * 0.12, yaw = jitter(i, 81) * 0.1;
|
|
592
|
-
|
|
616
|
+
// M4.10: the sunk stones are the cleanroom's stepping slabs, a hand over the water (the mirror pond hides anything under
|
|
617
|
+
// it); the raised bridge stands a step (under the motor's 0.35 m autostep) above them once brazier B burns
|
|
618
|
+
for (const [root, top, s] of [[raised, STONE_TOP, w], [sunk, SUNK_TOP, w - 0.2]] as const) {
|
|
593
619
|
const h = top - BED - 0.1;
|
|
594
|
-
|
|
620
|
+
// the slabs read as wet dark stone, as the cleanroom's sunk blocks do (not the bridge's moss caps)
|
|
621
|
+
const wet = root === sunk ? WET_STONE : undefined;
|
|
622
|
+
root.add(block(s, h, s, 1, x, BED + h / 2, z, yaw, 0, wet), block(s + 0.1, 0.1, s + 0.1, wet === undefined ? 2 : 1, x, top - 0.05, z, yaw, 0, wet));
|
|
595
623
|
}
|
|
596
|
-
colliders.push(stoneBox(x, (
|
|
624
|
+
colliders.push(stoneBox(x, (STONE_TOP + BED) / 2, z, w / 2, (STONE_TOP - BED) / 2, w / 2, yaw));
|
|
597
625
|
}
|
|
598
626
|
return { raised, sunk, colliders };
|
|
599
627
|
}
|
|
@@ -719,8 +747,12 @@ export function arenaRing(heightAt: (x: number, z: number) => number): { wall: G
|
|
|
719
747
|
export const SLATE = 0x4f4d52, FLOOR_MOSS = 0x4e6a2a, ARENA_CELL = 1.5;
|
|
720
748
|
/** LF1-9: the three braziers on the arena rim, as angles round `layout.ARENA` from the way in (across from it and either side). */
|
|
721
749
|
export const RIM_BRAZIERS: readonly number[] = [Math.PI - 0.72, Math.PI, Math.PI + 0.72];
|
|
722
|
-
/**
|
|
723
|
-
|
|
750
|
+
/**
|
|
751
|
+
* The open-core gem's centre over the Warden's feet: just over its crown (warden.ts `WARDEN_CROWN`, 1.76 m at scale 1, so
|
|
752
|
+
* 5.27 m at the spawn's scale 3) by its own half height (0.76 m) and a 0.2 m gap. It was 4.6, inside the golem's head
|
|
753
|
+
* (M4.10 review); the panel is fixed, so over the crown it reads whichever way the Warden turns.
|
|
754
|
+
*/
|
|
755
|
+
export const WARDEN_CORE = 6.2;
|
|
724
756
|
/** LF1-9: the Warden's slam tell, a ring this far round `layout.BOSS` (MH-4's twelve anchors stood 3.5 m out). */
|
|
725
757
|
export const TELL_RADIUS = 3.5;
|
|
726
758
|
/** A rim brazier's centre, on the wall cap's top. */
|
|
@@ -764,12 +796,11 @@ export function rimFlames(heightAt: (x: number, z: number) => number): Group {
|
|
|
764
796
|
const flames = new Group();
|
|
765
797
|
RIM_BRAZIERS.forEach((_, k) => {
|
|
766
798
|
const [x, y, z] = rimBrazier(heightAt, k);
|
|
767
|
-
|
|
768
|
-
const cone = new Mesh(foliageUv(new CylinderGeometry(0, rr, h, 5), 1), foliageMaterial(0xffffff)); cone.position.set(x + dx, y + 0.94 + h / 2, z + dz); cone.rotation.y = jitter(k * 3 + i, 170) * 1.2; flames.add(cone);
|
|
769
|
-
}
|
|
799
|
+
flameCones(flames, x, y + 0.99, z, 0.8);
|
|
770
800
|
});
|
|
771
|
-
// M2: brazier C's field also lights the row's C beacon at the back of the yard
|
|
772
|
-
const [bx = 0, bz = 0] = layout.ROW[1] ?? []
|
|
801
|
+
// M2: brazier C's field also lights the row's C beacon at the back of the yard; M4.10: and brazier C's own bowl
|
|
802
|
+
const [bx = 0, bz = 0] = layout.ROW[1] ?? [], [cx = 0, cz = 0] = layout.BRAZIERS[2] ?? [];
|
|
803
|
+
flameCones(flames, bx, heightAt(bx, bz) + 1.5, bz); flameCones(flames, cx, heightAt(cx, cz) + 1.5, cz);
|
|
773
804
|
return flames;
|
|
774
805
|
}
|
|
775
806
|
/**
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
|
-
"content": "
|
|
3
|
-
"captured": "2026-11-
|
|
4
|
-
"base": "http://127.0.0.1:
|
|
2
|
+
"content": "a3f16dec276836f29a0164f9f37dae5f29eab523307beffee71133e3541f33aa",
|
|
3
|
+
"captured": "2026-11-15T19:17:50.686Z",
|
|
4
|
+
"base": "http://127.0.0.1:4878",
|
|
5
5
|
"card": {
|
|
6
|
-
"card/thumb.jpg": "
|
|
7
|
-
"card/portrait.jpg": "
|
|
8
|
-
"card/landscape.jpg": "
|
|
6
|
+
"card/thumb.jpg": "3ab250eab85cafffd077e67aa24a7c3608a043ff1b64baeb2714c9eb3d6c04d7",
|
|
7
|
+
"card/portrait.jpg": "2f3574e0e9e5f20360cffa9529a7246afdd3fe1d3a792ee9d80271332002214b",
|
|
8
|
+
"card/landscape.jpg": "45bb2d038f2a00a9d7f904303e3d59354854f5a77acd5ea21fa54a4469663841"
|
|
9
9
|
}
|
|
10
10
|
}
|
|
@@ -3,4 +3,12 @@
|
|
|
3
3
|
import { defineShard } from '@wildshard/sdk/scene/shard';
|
|
4
4
|
import { buildSlice } from './world';
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
/** SHARD-SOURCE AP19: one quest, so a gameplay edit has something to show (`proof.mjs --edit quest` rewrites its objective). */
|
|
7
|
+
export const SLICE_QUESTS = {
|
|
8
|
+
flags: ['slice.pond', 'slice.walk'], triggers: [{ id: 'slice.pond', kind: 'region' as const, flag: 'slice.pond', x: -10.4, z: 0.3, radius: 4 }], dialogue: [],
|
|
9
|
+
quests: [{ id: 'slice.walk', title: 'A walk to the pond', completeFlag: 'slice.walk',
|
|
10
|
+
steps: [{ id: 'pond', objective: 'Walk down to the pond', done: { all: ['slice.pond'] } }] }],
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export const slice = defineShard({ slug: 'authoring-slice', name: 'Authoring Slice', author: 'Wildshard', revision: 1, seed: 357 }, buildSlice,
|
|
14
|
+
{ extend: (shard) => ({ ...shard, quests: SLICE_QUESTS }) });
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// The cleanroom's sunset sky dome (mossgate-cleanroom src/sky.js `makeSky`, 9cb4dc6) in TSL, line for line (SHARD-SOURCE
|
|
2
|
+
// AP14): periwinkle zenith, mauve, rose, a wide peach horizon glow, the low sun, small puffy clouds lit coral from below
|
|
3
|
+
// and a few stars. `world.sky(...)` compiles it to the dome's graph; the same value noise as the cleanroom's GLSL, so the
|
|
4
|
+
// clouds sit where the cleanroom's do. The detail and underside noise drop their finest octaves (weights 0.012 and 0.03 of
|
|
5
|
+
// the cloud shape) to fit the sky's budget (format look-sky, 1,024 instructions). Its `dusk` is 0 (the slice is the golden hour), so the night mix drops out.
|
|
6
|
+
import * as THREE from 'three';
|
|
7
|
+
import { dot, floor, fract, max, mix, normalize, pow, sin, smoothstep, step, vec2, vec3 } from 'three/tsl';
|
|
8
|
+
import { skyRay } from '@wildshard/sdk/scene/author';
|
|
9
|
+
import type { GraphValue } from '@wildshard/sdk/materials';
|
|
10
|
+
|
|
11
|
+
type V = ReturnType<typeof vec3>;
|
|
12
|
+
type F = ReturnType<typeof dot>;
|
|
13
|
+
type P = ReturnType<typeof vec2>;
|
|
14
|
+
|
|
15
|
+
/** The cleanroom's SKY colours (linear, as its uniforms hold them). */
|
|
16
|
+
const SKY = { zenith: '#2c3282', upper: '#5652a2', mid: '#b06ea2', low: '#f88c80', horizon: '#ffb878', sun: '#ffe6b0' };
|
|
17
|
+
const lin = (hex: string): V => { const c = new THREE.Color(hex); return vec3(c.r, c.g, c.b); };
|
|
18
|
+
/** Where the sun sits: just over the skyline behind the hut (cleanroom main.js `sunVisible`). */
|
|
19
|
+
export const SUN_DIRECTION = new THREE.Vector3(0.32, 0.035, -1).normalize();
|
|
20
|
+
|
|
21
|
+
const hash = (p: P): F => fract(sin(dot(p, vec2(127.1, 311.7))).mul(43758.5453));
|
|
22
|
+
function noise(p: P): F {
|
|
23
|
+
const i = floor(p), f = fract(p), u = f.mul(f).mul(f.mul(-2).add(3));
|
|
24
|
+
return mix(mix(hash(i), hash(i.add(vec2(1, 0))), u.x), mix(hash(i.add(vec2(0, 1))), hash(i.add(vec2(1, 1))), u.x), u.y);
|
|
25
|
+
}
|
|
26
|
+
/** The cleanroom's five-octave fbm; `octaves` below 5 drops the finest (each is half the weight of the one before). */
|
|
27
|
+
function fbm(start: P, octaves = 5): F {
|
|
28
|
+
let sum: F = noise(start).mul(0.5), p = start, a = 0.5;
|
|
29
|
+
for (let octave = 1; octave < octaves; octave++) { p = p.mul(2.07).add(13.1); a *= 0.5; sum = sum.add(noise(p).mul(a)); }
|
|
30
|
+
return sum;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** The sky colour along the view ray. */
|
|
34
|
+
export function sunsetSky(): GraphValue {
|
|
35
|
+
const d = skyRay, h = d.y, e = max(h, 0);
|
|
36
|
+
const sun = vec3(SUN_DIRECTION.x, SUN_DIRECTION.y, SUN_DIRECTION.z);
|
|
37
|
+
// the glow toward the sun's side is wider and warmer
|
|
38
|
+
const sd = max(dot(d, sun), 0);
|
|
39
|
+
const az = pow(max(dot(normalize(d.xz.add(1e-4)), normalize(vec2(SUN_DIRECTION.x, SUN_DIRECTION.z))), 0), 2);
|
|
40
|
+
const lift = az.mul(0.06).add(0.06); // the peach band climbs higher on the sun side
|
|
41
|
+
let col: V = lin(SKY.horizon);
|
|
42
|
+
col = mix(col, lin(SKY.low), smoothstep(lift.sub(0.02), lift.add(0.1), e));
|
|
43
|
+
col = mix(col, lin(SKY.mid), smoothstep(lift.add(0.06), 0.26, e));
|
|
44
|
+
col = mix(col, lin(SKY.upper), smoothstep(0.22, 0.42, e));
|
|
45
|
+
col = mix(col, lin(SKY.zenith), smoothstep(0.4, 0.75, e));
|
|
46
|
+
col = mix(col, lin(SKY.horizon).mul(0.92), smoothstep(0, -0.08, h)); // under the skyline: haze
|
|
47
|
+
// sun: wide warm wash, halo, disc sitting on the horizon
|
|
48
|
+
col = col.add(vec3(1, 0.62, 0.36).mul(pow(sd, 6).mul(0.4).mul(smoothstep(0, 0.4, e).oneMinus())));
|
|
49
|
+
col = col.add(lin(SKY.sun).mul(pow(sd, 120).mul(0.35)));
|
|
50
|
+
col = col.add(vec3(1, 0.85, 0.6).mul(smoothstep(0.99935, 0.9997, sd).mul(0.9)));
|
|
51
|
+
// puffy clouds: a plane projection, small cumulus clumps in a band
|
|
52
|
+
const cp = d.xz.div(max(h.add(0.08), 0.04)).mul(1.6);
|
|
53
|
+
const band = smoothstep(0.04, 0.1, h).mul(smoothstep(0.3, 0.5, h).oneMinus());
|
|
54
|
+
const shape = fbm(cp.mul(0.55).add(4)).mul(0.75).add(fbm(cp.mul(2.4).add(9), 4).mul(0.38));
|
|
55
|
+
const cloud = smoothstep(0.57, 0.68, shape).mul(band);
|
|
56
|
+
const underside = smoothstep(0.2, 0.75, fbm(cp.mul(2.4).add(vec2(0, 0.6)).add(9), 3)); // lit from below
|
|
57
|
+
const lit = mix(vec3(1, 0.46, 0.46), vec3(1, 0.56, 0.32), pow(sd, 2)).mul(0.86);
|
|
58
|
+
const shade = mix(lin(SKY.mid), lin(SKY.upper), 0.45).mul(0.95);
|
|
59
|
+
const cloudCol = mix(lit, shade, underside.mul(0.35)).mul(mix(1, 0.72, smoothstep(0.14, 0.45, e))); // high clouds sit in shade
|
|
60
|
+
col = mix(col, cloudCol, cloud.mul(0.92));
|
|
61
|
+
// stars, faint at the golden hour (dusk 0)
|
|
62
|
+
const st = step(0.9965, hash(floor(d.xz.div(max(h, 0.15)).mul(260)))).mul(smoothstep(0.35, 0.8, e));
|
|
63
|
+
return col.add(vec3(st, st, st).mul(0.15)).mul(0.95);
|
|
64
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { dot, max, mix, screenUV, smoothstep, vec3 } from 'three/tsl';
|
|
2
|
+
import { graph, graphInputs, noise, sceneDepth } from '@wildshard/sdk/materials';
|
|
3
|
+
import type { GraphIr } from '@wildshard/format/materialGraph';
|
|
4
|
+
|
|
5
|
+
// The Template's sky post pass, kept here so the Template's own hero stamp stays true (data/look.json post[0], 77 graph nodes) as TSL (SHARD-SOURCE AP13): a five-band dusk,
|
|
6
|
+
// a sun glow, halo and disc, three octaves of cloud, the vignette. `graph()` compiles it to the same graph.
|
|
7
|
+
export function templateSky(): GraphIr {
|
|
8
|
+
const { sceneColour, viewRay } = graphInputs;
|
|
9
|
+
const rgb = sceneColour.xyz.toVar('rgb'), sky = smoothstep(400, 480, sceneDepth().toVar('depth')).toVar('sky');
|
|
10
|
+
const ray = viewRay.toVar('ray'), h = ray.y.toVar('h'), e = max(h, 0).toVar('e');
|
|
11
|
+
const sd = max(dot(ray, vec3(0.30461, 0.03332, -0.9519)), 0).toVar('sd');
|
|
12
|
+
const band = (from: ReturnType<typeof mix>, to: [number, number, number], a: number, b: number): ReturnType<typeof mix> => mix(from, vec3(...to), smoothstep(a, b, e));
|
|
13
|
+
const bands = band(band(band(mix(vec3(1, 0.4793, 0.1878), vec3(0.9387, 0.2623, 0.2159), smoothstep(0.07, 0.19, e)),
|
|
14
|
+
[0.4342, 0.1559, 0.3613], 0.15, 0.26), [0.0931, 0.0844, 0.3613], 0.22, 0.42), [0.0252, 0.0319, 0.2232], 0.4, 0.75);
|
|
15
|
+
const glow = vec3(1, 0.62, 0.36).mul(sd.pow(6).mul(0.4).mul(smoothstep(0, 0.4, e).oneMinus()));
|
|
16
|
+
const halo = vec3(1, 0.7913, 0.4342).mul(sd.pow(120).mul(0.35));
|
|
17
|
+
const disc = vec3(1, 0.85, 0.6).mul(smoothstep(0.99935, 0.9997, sd).mul(0.9));
|
|
18
|
+
const p = ray.xz.div(max(h.add(0.08), 0.04)).mul(1.6);
|
|
19
|
+
const n3 = noise(p.mul(2.4).add(9));
|
|
20
|
+
const octaves = noise(p.mul(0.55).add(4)).mul(0.6).add(noise(p.mul(1.15).add(17)).mul(0.3)).add(n3.mul(0.22));
|
|
21
|
+
const cloud = smoothstep(0.1, 0.24, octaves).mul(smoothstep(0.04, 0.1, h).mul(smoothstep(0.3, 0.5, h).oneMinus())).toVar('cloud');
|
|
22
|
+
const lit = mix(mix(vec3(1, 0.46, 0.46), vec3(1, 0.56, 0.32), sd.mul(sd)).mul(0.86), vec3(0.2667, 0.1175, 0.3432), smoothstep(-0.2, 0.4, n3).mul(0.35));
|
|
23
|
+
const skyCol = mix(bands.add(glow).add(halo).add(disc), lit.mul(mix(1, 0.72, smoothstep(0.14, 0.45, e))), cloud.mul(0.92)).mul(0.95).toVar('skyCol');
|
|
24
|
+
const vd = screenUV.toVar('uv').sub(0.5).toVar('vd');
|
|
25
|
+
const vig = smoothstep(0.2, 0.75, dot(vd, vd).toVar('vr')).mul(0.22).oneMinus().toVar('vig');
|
|
26
|
+
return graph({ kind: 'post', post: { colour: mix(rgb, skyCol, sky).toVar('scene').mul(vig).toVar('out') } });
|
|
27
|
+
}
|
|
@@ -171,3 +171,62 @@ export function hangingMoss(): DataTexture {
|
|
|
171
171
|
ctx.fillStyle = 'rgb(84,104,36)'; ctx.fillRect(0, 0, 256, 10);
|
|
172
172
|
});
|
|
173
173
|
}
|
|
174
|
+
|
|
175
|
+
// Fern frond: a tapered stem with paired leaflets, root at the bottom.
|
|
176
|
+
export function frond(): DataTexture {
|
|
177
|
+
return paintCanvas(128, 512, (ctx) => {
|
|
178
|
+
ctx.clearRect(0, 0, 128, 512);
|
|
179
|
+
const grad = ctx.createLinearGradient(0, 512, 0, 0);
|
|
180
|
+
grad.addColorStop(0, '#3e5a1c');
|
|
181
|
+
grad.addColorStop(1, '#8fae3c');
|
|
182
|
+
ctx.fillStyle = grad;
|
|
183
|
+
ctx.strokeStyle = grad;
|
|
184
|
+
ctx.lineWidth = 4;
|
|
185
|
+
ctx.beginPath(); ctx.moveTo(64, 512); ctx.lineTo(64, 10); ctx.stroke();
|
|
186
|
+
for (let y = 40; y < 500; y += 16) {
|
|
187
|
+
const len = 54 * Math.sin(((y - 20) / 490) * Math.PI) + 4;
|
|
188
|
+
for (const s of [-1, 1]) {
|
|
189
|
+
ctx.beginPath();
|
|
190
|
+
ctx.ellipse(64 + s * len * 0.5, y - 6, len * 0.5, 6, s * -0.35, 0, Math.PI * 2);
|
|
191
|
+
ctx.fill();
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// Grass blade card: a fan of tapered blades.
|
|
198
|
+
export function grassCard(): DataTexture {
|
|
199
|
+
return paintCanvas(128, 128, (ctx) => {
|
|
200
|
+
ctx.clearRect(0, 0, 128, 128);
|
|
201
|
+
const r = rng(4);
|
|
202
|
+
for (let i = 0; i < 14; i++) {
|
|
203
|
+
const x = 20 + r() * 88, h = 60 + r() * 64, lean = (r() - 0.5) * 40;
|
|
204
|
+
const g = ctx.createLinearGradient(0, 128, 0, 128 - h);
|
|
205
|
+
g.addColorStop(0, '#6a8a2e'); g.addColorStop(1, r() < 0.3 ? '#c6cc6a' : '#a4c04c');
|
|
206
|
+
ctx.fillStyle = g;
|
|
207
|
+
ctx.beginPath(); ctx.moveTo(x - 3, 128); ctx.quadraticCurveTo(x + lean * 0.4, 128 - h * 0.6, x + lean, 128 - h); ctx.lineTo(x + 3, 128); ctx.fill();
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// Flame sprite: five pointed tongues in three layers, red-orange outside, orange, then a yellow-white core.
|
|
213
|
+
export function flameSprite(): DataTexture {
|
|
214
|
+
return paintCanvas(128, 256, (ctx) => {
|
|
215
|
+
ctx.clearRect(0, 0, 128, 256);
|
|
216
|
+
const tongue = (cx: number, top: number, w: number, col: string): void => {
|
|
217
|
+
ctx.fillStyle = col;
|
|
218
|
+
ctx.beginPath(); ctx.moveTo(cx - w, 236);
|
|
219
|
+
ctx.bezierCurveTo(cx - w * 1.1, 170, cx - w * 0.2, 120, cx + w * 0.15, top);
|
|
220
|
+
ctx.bezierCurveTo(cx + w * 0.5, 120, cx + w * 1.2, 170, cx + w, 236);
|
|
221
|
+
ctx.closePath(); ctx.fill();
|
|
222
|
+
};
|
|
223
|
+
const base = (r: number, col: string): void => { ctx.fillStyle = col; ctx.beginPath(); ctx.ellipse(64, 222, r, r * 0.5, 0, 0, Math.PI * 2); ctx.fill(); };
|
|
224
|
+
base(46, 'rgba(232,74,22,0.95)');
|
|
225
|
+
for (const [x, t, w] of [[38, 92, 24], [58, 18, 30], [82, 60, 26], [100, 120, 18], [24, 140, 16]] as const) tongue(x, t, w, 'rgba(232,74,22,0.95)');
|
|
226
|
+
base(36, 'rgba(255,140,30,1)');
|
|
227
|
+
for (const [x, t, w] of [[44, 110, 18], [62, 50, 22], [80, 96, 18]] as const) tongue(x, t, w, 'rgba(255,140,30,1)');
|
|
228
|
+
base(24, 'rgba(255,214,90,1)');
|
|
229
|
+
for (const [x, t, w] of [[56, 120, 13], [70, 104, 13]] as const) tongue(x, t, w, 'rgba(255,214,90,1)');
|
|
230
|
+
base(12, 'rgba(255,248,214,1)');
|
|
231
|
+
});
|
|
232
|
+
}
|
|
@@ -6,8 +6,9 @@
|
|
|
6
6
|
import * as THREE from 'three';
|
|
7
7
|
import { RoundedBoxGeometry } from 'three/examples/jsm/geometries/RoundedBoxGeometry.js';
|
|
8
8
|
import { mergeGeometries } from 'three/examples/jsm/utils/BufferGeometryUtils.js';
|
|
9
|
-
import { solid, Water, type ShardWorld } from '@wildshard/sdk/scene/author';
|
|
9
|
+
import { animate, drift, flicker, pulse, rise, solid, sway, Water, type ShardWorld } from '@wildshard/sdk/scene/author';
|
|
10
10
|
import * as T from './textures';
|
|
11
|
+
import { sunsetSky } from './sky';
|
|
11
12
|
|
|
12
13
|
export const LAYOUT = {
|
|
13
14
|
SPAWN: { x: 0, z: 0, yaw: 0 },
|
|
@@ -50,7 +51,7 @@ export function groundColour(x: number, z: number): [number, number, number] {
|
|
|
50
51
|
|
|
51
52
|
/** The textures and materials every part shares (`buildWorld`'s `tex` and `M`). */
|
|
52
53
|
function materials(): { M: Record<string, THREE.MeshStandardMaterial>; tex: Record<string, THREE.Texture> } {
|
|
53
|
-
const tex = { stone: T.stone(3, { moss: 0.32 }), stoneClean: T.stone(8, { moss: 0.12 }), slab: T.slab(), wood: T.wood(), shingle: T.shingle(), glow: T.glow(), ivy: T.ivy(), drape: T.hangingMoss() };
|
|
54
|
+
const tex = { stone: T.stone(3, { moss: 0.32 }), stoneClean: T.stone(8, { moss: 0.12 }), slab: T.slab(), wood: T.wood(), shingle: T.shingle(), glow: T.glow(), ivy: T.ivy(), drape: T.hangingMoss(), frond: T.frond(), grass: T.grassCard(), flame: T.flameSprite() };
|
|
54
55
|
const M = {
|
|
55
56
|
stone: new THREE.MeshStandardMaterial({ map: tex.stone, roughness: 0.93 }),
|
|
56
57
|
stoneClean: new THREE.MeshStandardMaterial({ map: tex.stoneClean, roughness: 0.9 }),
|
|
@@ -69,6 +70,12 @@ function materials(): { M: Record<string, THREE.MeshStandardMaterial>; tex: Reco
|
|
|
69
70
|
return { M, tex };
|
|
70
71
|
}
|
|
71
72
|
|
|
73
|
+
// The cleanroom's update(t), said as data (AP12): every lamp's intensity * (0.92 + 0.05 sin 7t + 0.03 sin 17.3t), a flame
|
|
74
|
+
// tongue's height * (0.85 + 0.12 sin 9t + 0.06 sin 23t), foliage in the wind.
|
|
75
|
+
const LAMP_FLICKER = flicker({ rate: 1.1, amount: 0.08 });
|
|
76
|
+
const FLAME_PULSE = pulse({ rate: 1.4, amount: 0.14 });
|
|
77
|
+
const FOLIAGE_SWAY = sway({ rate: 0.5, amount: 0.06 });
|
|
78
|
+
|
|
72
79
|
interface Block { x: number; y: number; z: number; sx: number; sy: number; sz: number; rotY: number; tint: number }
|
|
73
80
|
/** One part's builders: the cleanroom's accumulators (`addBlock`, `addCap`, `drape`, `ivy`) and its lamp helpers. */
|
|
74
81
|
function kit(part: THREE.Group, seed: number, M: Record<string, THREE.MeshStandardMaterial>, tex: Record<string, THREE.Texture>) {
|
|
@@ -126,7 +133,7 @@ function kit(part: THREE.Group, seed: number, M: Record<string, THREE.MeshStanda
|
|
|
126
133
|
if (on) {
|
|
127
134
|
if (light) {
|
|
128
135
|
const l = new THREE.PointLight('#ffa850', 3.4 * scale, 6, 1.7);
|
|
129
|
-
l.position.set(x, y, z); part.add(l);
|
|
136
|
+
l.position.set(x, y, z); part.add(animate(l, LAMP_FLICKER));
|
|
130
137
|
}
|
|
131
138
|
const s = new THREE.Sprite(new THREE.SpriteMaterial({ map: tex.glow, color: '#ffb466', blending: THREE.AdditiveBlending, depthWrite: false, transparent: true, opacity: 0.5, fog: false }));
|
|
132
139
|
s.scale.setScalar(1.1 * scale); s.position.set(x, y, z); part.add(s);
|
|
@@ -302,8 +309,8 @@ export function hut(part: THREE.Group, M: Record<string, THREE.MeshStandardMater
|
|
|
302
309
|
for (const [cx, cz, s] of [[-1.85, -0.6, 0.6], [-1.85, 0.05, 0.5], [-1.8, -0.3, 0.42]] as const) { const cr = new THREE.Mesh(new RoundedBoxGeometry(s, s, s, 1, 0.03), M.wood); cr.position.set(hx + cx, s / 2 + (s < 0.45 ? 0.6 : 0), iz + cz); cr.rotation.y = R(-0.3, 0.3); part.add(cr); }
|
|
303
310
|
barrel(part, M, hx + 1.95, iz - 1.4);
|
|
304
311
|
lantern(hx + 0.6, 1.95, iz - 0.3, { on: true, scale: 0.9, light: false });
|
|
305
|
-
const inLight = new THREE.PointLight('#ffa040', 7, 6.5, 1.4); inLight.position.set(hx + 0.4, 1.8, iz + 0.2); part.add(inLight);
|
|
306
|
-
const inLight2 = new THREE.PointLight('#ff9a40', 3, 4, 1.5); inLight2.position.set(hx - 1.5, 1.5, iz - 1.0); part.add(inLight2);
|
|
312
|
+
const inLight = new THREE.PointLight('#ffa040', 7, 6.5, 1.4); inLight.position.set(hx + 0.4, 1.8, iz + 0.2); part.add(animate(inLight, LAMP_FLICKER));
|
|
313
|
+
const inLight2 = new THREE.PointLight('#ff9a40', 3, 4, 1.5); inLight2.position.set(hx - 1.5, 1.5, iz - 1.0); part.add(animate(inLight2, LAMP_FLICKER));
|
|
307
314
|
// outside: bench, barrels, crates
|
|
308
315
|
const bench = new THREE.Mesh(new RoundedBoxGeometry(1.5, 0.12, 0.44, 2, 0.03), M.wood); bench.position.set(hx - 2.15, 0.48, z0 + 0.95); bench.castShadow = true; part.add(bench);
|
|
309
316
|
for (const bx of [-0.58, 0.58]) { const l = new THREE.Mesh(new THREE.BoxGeometry(0.12, 0.45, 0.38), M.darkWood); l.position.set(hx - 2.15 + bx, 0.22, z0 + 0.95); part.add(l); }
|
|
@@ -389,8 +396,103 @@ export function pond(part: THREE.Group, M: Record<string, THREE.MeshStandardMate
|
|
|
389
396
|
flush();
|
|
390
397
|
}
|
|
391
398
|
|
|
399
|
+
/** The yard (cleanroom world.js 375-430 and 891-1030, AP10 to AP12): brazier A lit, its flame cards, sparks and light;
|
|
400
|
+
* ferns and grass cards round the hut, swaying; fireflies over the slice. The cleanroom moved these in `update(t)`; here
|
|
401
|
+
* each says its motion once with `animate`, and the engine plays it. */
|
|
402
|
+
export function yard(part: THREE.Group, M: Record<string, THREE.MeshStandardMaterial>, tex: Record<string, THREE.Texture>): void {
|
|
403
|
+
const rand = T.rng(877);
|
|
404
|
+
const R = (a: number, b: number): number => a + (b - a) * rand();
|
|
405
|
+
// brazier A: a stone plinth, a lathe bowl, a fire
|
|
406
|
+
const [bx, bz] = [5.9, -12.8], gy = groundHeight(bx, bz);
|
|
407
|
+
const pad = new THREE.Mesh(new RoundedBoxGeometry(2.1, 0.12, 2.1, 2, 0.05), M.slab);
|
|
408
|
+
pad.position.set(bx, gy + 0.02, bz); pad.receiveShadow = true; part.add(pad);
|
|
409
|
+
decal(part, 'A', bx, gy + 0.09, bz + 0.68, 0, 0.9, true);
|
|
410
|
+
const g = new THREE.Group();
|
|
411
|
+
const plinth = new THREE.Mesh(new RoundedBoxGeometry(0.78, 0.5, 0.78, 2, 0.05), M.stone); plinth.position.y = 0.25;
|
|
412
|
+
const step = new THREE.Mesh(new RoundedBoxGeometry(0.98, 0.14, 0.98, 2, 0.04), M.stone); step.position.y = 0.07;
|
|
413
|
+
const stem = new THREE.Mesh(new THREE.CylinderGeometry(0.2, 0.3, 0.32, 8), M.stone); stem.position.y = 0.66;
|
|
414
|
+
const prof = [new THREE.Vector2(0, 0)];
|
|
415
|
+
for (let i = 0; i <= 10; i++) { const t = i / 10; prof.push(new THREE.Vector2(0.22 + 0.42 * Math.sin(t * Math.PI / 2), t * 0.4)); }
|
|
416
|
+
prof.push(new THREE.Vector2(0.72, 0.42), new THREE.Vector2(0.7, 0.46), new THREE.Vector2(0.6, 0.42), new THREE.Vector2(0.0, 0.32));
|
|
417
|
+
const bowl = new THREE.Mesh(new THREE.LatheGeometry(prof, 8), M.stone); bowl.position.y = 0.8;
|
|
418
|
+
g.add(plinth, step, stem, bowl);
|
|
419
|
+
g.traverse((o) => { if (o instanceof THREE.Mesh) { o.castShadow = true; o.receiveShadow = true; } });
|
|
420
|
+
solid(plinth); g.position.set(bx, gy, bz); part.add(g);
|
|
421
|
+
// the fire: three flame cards breathing (normal blending, so overlapping tongues stay orange), a flickering light
|
|
422
|
+
const top = gy + 1.18, fire = animate(new THREE.Group(), FLAME_PULSE);
|
|
423
|
+
const flame = new THREE.SpriteMaterial({ map: tex.flame, color: new THREE.Color(1.5, 1.3, 1.15), depthWrite: false, transparent: true, fog: false, alphaTest: 0.05 });
|
|
424
|
+
for (let i = 0; i < 3; i++) {
|
|
425
|
+
const h = [1.9, 1.5, 1.3][i] ?? 1, s = new THREE.Sprite(flame);
|
|
426
|
+
// the cleanroom's mean frame (k = 0.85): the pulse breathes round it
|
|
427
|
+
s.center.set(0.5, 0.1); s.scale.set(h * 0.62 * 1.05, h * 0.85, 1); s.position.set([0, -0.24, 0.26][i] ?? 0, -0.02, [0, 0.12, -0.14][i] ?? 0);
|
|
428
|
+
fire.add(s);
|
|
429
|
+
}
|
|
430
|
+
fire.position.set(bx, top, bz); part.add(fire);
|
|
431
|
+
// its halo (the cleanroom's instanced glows row: 2.6 m, #ff8a40 at 0.18, additive)
|
|
432
|
+
const halo = new THREE.Sprite(new THREE.SpriteMaterial({ map: tex.glow, color: '#ff8a40', blending: THREE.AdditiveBlending, depthWrite: false, transparent: true, opacity: 0.18, fog: false }));
|
|
433
|
+
halo.scale.setScalar(2.6); halo.position.set(bx, top + 0.55, bz); part.add(halo);
|
|
434
|
+
const l = new THREE.PointLight('#ff9a3a', 16, 12, 1.5); l.position.set(bx, top + 0.7, bz); part.add(animate(l, LAMP_FLICKER));
|
|
435
|
+
// sparks: 36 seats round the bowl, each climbing 2.6 m and fading (the cleanroom's (s0 + t sp 0.4) % 1)
|
|
436
|
+
const sparks = new Float32Array(36 * 3);
|
|
437
|
+
for (let i = 0; i < 36; i++) sparks.set([bx + R(-0.35, 0.35), top + 0.4, bz + R(-0.35, 0.35)], i * 3);
|
|
438
|
+
const sparkCloud = new THREE.Points(new THREE.BufferGeometry().setAttribute('position', new THREE.BufferAttribute(sparks, 3)),
|
|
439
|
+
new THREE.PointsMaterial({ map: tex.glow, color: new THREE.Color('#ffc060').multiplyScalar(3), size: 0.07, transparent: true, depthWrite: false, blending: THREE.AdditiveBlending }));
|
|
440
|
+
part.add(animate(sparkCloud, rise({ rate: 0.3, height: 2.6, spread: 0.5 })));
|
|
441
|
+
// ferns: nine fronds a clump, round the hut and the yard
|
|
442
|
+
const fernSpots: [number, number][] = [[-1.6, -12.4], [-6.8, -12.6], [-6.6, -12.0], [-2.2, -5.4], [3.1, -6.2], [1.6, -11.8], [4.4, -10.6], [-8.4, -9.2], [7.6, -14.6]];
|
|
443
|
+
{
|
|
444
|
+
const fg = new THREE.PlaneGeometry(0.3, 1.05, 1, 6); fg.translate(0, 0.52, 0);
|
|
445
|
+
const p = fg.attributes.position;
|
|
446
|
+
if (p !== undefined) for (let i = 0; i < p.count; i++) { const y = p.getY(i); p.setZ(i, y * y * 0.55); p.setY(i, y * (1 - y * 0.25)); }
|
|
447
|
+
fg.computeVertexNormals();
|
|
448
|
+
const im = new THREE.InstancedMesh(fg, new THREE.MeshStandardMaterial({ map: tex.frond, alphaTest: 0.4, side: THREE.DoubleSide, roughness: 0.8 }), fernSpots.length * 9);
|
|
449
|
+
const o = new THREE.Object3D();
|
|
450
|
+
let k = 0;
|
|
451
|
+
for (const [x, z] of fernSpots) {
|
|
452
|
+
const s = R(0.75, 1.25);
|
|
453
|
+
for (let f = 0; f < 9; f++) {
|
|
454
|
+
o.position.set(x, groundHeight(x, z), z); o.rotation.set(0, (f / 9) * Math.PI * 2 + R(-0.2, 0.2), 0); o.rotateX(R(-0.55, -0.25));
|
|
455
|
+
o.scale.set(s, s * R(0.8, 1.1), s); o.updateMatrix(); im.setMatrixAt(k++, o.matrix);
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
im.castShadow = true; part.add(animate(im, FOLIAGE_SWAY));
|
|
459
|
+
}
|
|
460
|
+
// grass cards: the cleanroom's crossed card, scattered within 24 m of the yard
|
|
461
|
+
{
|
|
462
|
+
const card = new THREE.PlaneGeometry(0.38, 0.28); card.translate(0, 0.13, 0);
|
|
463
|
+
const cross = mergeGeometries([card, card.clone().rotateY(Math.PI / 2)]);
|
|
464
|
+
const nrm = cross.attributes.normal;
|
|
465
|
+
if (nrm !== undefined) for (let i = 0; i < nrm.count; i++) nrm.setXYZ(i, 0, 1, 0);
|
|
466
|
+
const N = 1400, im = new THREE.InstancedMesh(cross, new THREE.MeshStandardMaterial({ map: tex.grass, alphaTest: 0.35, side: THREE.DoubleSide, roughness: 0.9 }), N);
|
|
467
|
+
const o = new THREE.Object3D(), c = new THREE.Color(), H = LAYOUT.HUT;
|
|
468
|
+
let k = 0, tries = 0;
|
|
469
|
+
while (k < N && tries < N * 5) {
|
|
470
|
+
tries++;
|
|
471
|
+
const r = Math.sqrt(rand()) * 24, a = R(0, Math.PI * 2), x = Math.cos(a) * r - 6, z = Math.sin(a) * r - 6;
|
|
472
|
+
if (x > H.x - H.w / 2 - 0.3 && x < H.x + H.w / 2 + 0.3 && z < H.z + H.d / 2 + 0.3 && z > H.z - H.d / 2 - 0.3) continue;
|
|
473
|
+
if (pondSDF(x, z) < 0.3) continue;
|
|
474
|
+
if (Math.hypot(x - bx, z - bz) < 1.3) continue;
|
|
475
|
+
if (noise.fbm(x * 0.25, z * 0.25, 2) < 0.42 && rand() < 0.75) continue;
|
|
476
|
+
o.position.set(x, groundHeight(x, z) - 0.02, z); o.rotation.set(0, R(0, Math.PI), 0); o.scale.setScalar(R(0.5, 1.1));
|
|
477
|
+
o.updateMatrix(); im.setMatrixAt(k, o.matrix); im.setColorAt(k, c.setRGB(R(0.82, 1.0), R(0.82, 1.0), R(0.62, 0.85)));
|
|
478
|
+
k++;
|
|
479
|
+
}
|
|
480
|
+
im.count = k; part.add(animate(im, FOLIAGE_SWAY));
|
|
481
|
+
}
|
|
482
|
+
// fireflies: 60 seats over the slice, each wandering 0.6 m round itself
|
|
483
|
+
const flies = new Float32Array(60 * 3);
|
|
484
|
+
for (let i = 0; i < 60; i++) flies.set([R(-24, 10), R(0.3, 2.4), R(-18, 6)], i * 3);
|
|
485
|
+
const flyCloud = new THREE.Points(new THREE.BufferGeometry().setAttribute('position', new THREE.BufferAttribute(flies, 3)),
|
|
486
|
+
new THREE.PointsMaterial({ map: tex.glow, color: new THREE.Color('#ffd27a').multiplyScalar(2), size: 0.12, transparent: true, depthWrite: false, blending: THREE.AdditiveBlending }));
|
|
487
|
+
part.add(animate(flyCloud, drift({ rate: 0.3, radius: 0.6 })));
|
|
488
|
+
}
|
|
489
|
+
|
|
392
490
|
/** The sunset light (cleanroom main.js 40-66): hemisphere, the key sun, the rim, the haze, the composer. */
|
|
393
491
|
export function sunset(world: ShardWorld): void {
|
|
492
|
+
// the sky dome (cleanroom sky.js) and the environment PMREM'd from it at 0.4 (main.js 63-70); under the skyline the
|
|
493
|
+
// cleanroom's environment sees the dome's haze, so the ground the engine filters with is that haze
|
|
494
|
+
const haze = new THREE.Color('#ffb878').multiplyScalar(0.92);
|
|
495
|
+
world.sky(sunsetSky(), { environment: { intensity: 0.4, ground: [haze.r, haze.g, haze.b] } });
|
|
394
496
|
world.scene.fog = new THREE.FogExp2(new THREE.Color('#d898a0'), 0.0062);
|
|
395
497
|
world.part('light', (part) => {
|
|
396
498
|
part.add(new THREE.HemisphereLight(new THREE.Color('#c4b0e4'), new THREE.Color('#7a6a3c'), 0.85));
|
|
@@ -411,5 +513,6 @@ export function buildSlice(world: ShardWorld): void {
|
|
|
411
513
|
world.ground(groundHeight, { colourAt: groundColour });
|
|
412
514
|
world.part('hut', (part) => { hut(part, M, tex); });
|
|
413
515
|
world.part('pond', (part) => { pond(part, M, tex); });
|
|
516
|
+
world.part('yard', (part) => { yard(part, M, tex); });
|
|
414
517
|
world.spawn(-3.9, 0, -5.6, 0.03);
|
|
415
518
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// SHARD-SOURCE AP15: Mossgate Hollow whole, as one scene module. `wildshard build` runs this as the shard's generator (the
|
|
2
|
+
// shardfile back end); `wildshard watch` calls its describe() and streams the parts to a running page.
|
|
3
|
+
import { defineShard } from '@wildshard/sdk/scene/shard';
|
|
4
|
+
import { buildMossgate } from './world';
|
|
5
|
+
|
|
6
|
+
export const mossgate = defineShard({ slug: 'mossgate', name: 'Mossgate Hollow', author: 'Wildshard', revision: 1, seed: 357 }, buildMossgate);
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// The cleanroom's sunset sky dome (mossgate-cleanroom src/sky.js `makeSky`, 9cb4dc6) in TSL, line for line (SHARD-SOURCE
|
|
2
|
+
// AP14): periwinkle zenith, mauve, rose, a wide peach horizon glow, the low sun, small puffy clouds lit coral from below
|
|
3
|
+
// and a few stars. `world.sky(...)` compiles it to the dome's graph; the same value noise as the cleanroom's GLSL, so the
|
|
4
|
+
// clouds sit where the cleanroom's do. The detail and underside noise drop their finest octaves (weights 0.012 and 0.03 of
|
|
5
|
+
// the cloud shape) to fit the sky's budget (format look-sky, 1,024 instructions). Its `dusk` is 0 (the slice is the golden hour), so the night mix drops out.
|
|
6
|
+
import * as THREE from 'three';
|
|
7
|
+
import { dot, floor, fract, max, mix, normalize, pow, sin, smoothstep, step, vec2, vec3 } from 'three/tsl';
|
|
8
|
+
import { skyRay } from '@wildshard/sdk/scene/author';
|
|
9
|
+
import type { GraphValue } from '@wildshard/sdk/materials';
|
|
10
|
+
|
|
11
|
+
type V = ReturnType<typeof vec3>;
|
|
12
|
+
type F = ReturnType<typeof dot>;
|
|
13
|
+
type P = ReturnType<typeof vec2>;
|
|
14
|
+
|
|
15
|
+
/** The cleanroom's SKY colours (linear, as its uniforms hold them). */
|
|
16
|
+
const SKY = { zenith: '#2c3282', upper: '#5652a2', mid: '#b06ea2', low: '#f88c80', horizon: '#ffb878', sun: '#ffe6b0' };
|
|
17
|
+
const lin = (hex: string): V => { const c = new THREE.Color(hex); return vec3(c.r, c.g, c.b); };
|
|
18
|
+
/** Where the sun sits: just over the skyline behind the hut (cleanroom main.js `sunVisible`). */
|
|
19
|
+
export const SUN_DIRECTION = new THREE.Vector3(0.32, 0.035, -1).normalize();
|
|
20
|
+
|
|
21
|
+
const hash = (p: P): F => fract(sin(dot(p, vec2(127.1, 311.7))).mul(43758.5453));
|
|
22
|
+
function noise(p: P): F {
|
|
23
|
+
const i = floor(p), f = fract(p), u = f.mul(f).mul(f.mul(-2).add(3));
|
|
24
|
+
return mix(mix(hash(i), hash(i.add(vec2(1, 0))), u.x), mix(hash(i.add(vec2(0, 1))), hash(i.add(vec2(1, 1))), u.x), u.y);
|
|
25
|
+
}
|
|
26
|
+
/** The cleanroom's five-octave fbm; `octaves` below 5 drops the finest (each is half the weight of the one before). */
|
|
27
|
+
function fbm(start: P, octaves = 5): F {
|
|
28
|
+
let sum: F = noise(start).mul(0.5), p = start, a = 0.5;
|
|
29
|
+
for (let octave = 1; octave < octaves; octave++) { p = p.mul(2.07).add(13.1); a *= 0.5; sum = sum.add(noise(p).mul(a)); }
|
|
30
|
+
return sum;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** The sky colour along the view ray. */
|
|
34
|
+
export function sunsetSky(): GraphValue {
|
|
35
|
+
const d = skyRay, h = d.y, e = max(h, 0);
|
|
36
|
+
const sun = vec3(SUN_DIRECTION.x, SUN_DIRECTION.y, SUN_DIRECTION.z);
|
|
37
|
+
// the glow toward the sun's side is wider and warmer
|
|
38
|
+
const sd = max(dot(d, sun), 0);
|
|
39
|
+
const az = pow(max(dot(normalize(d.xz.add(1e-4)), normalize(vec2(SUN_DIRECTION.x, SUN_DIRECTION.z))), 0), 2);
|
|
40
|
+
const lift = az.mul(0.06).add(0.06); // the peach band climbs higher on the sun side
|
|
41
|
+
let col: V = lin(SKY.horizon);
|
|
42
|
+
col = mix(col, lin(SKY.low), smoothstep(lift.sub(0.02), lift.add(0.1), e));
|
|
43
|
+
col = mix(col, lin(SKY.mid), smoothstep(lift.add(0.06), 0.26, e));
|
|
44
|
+
col = mix(col, lin(SKY.upper), smoothstep(0.22, 0.42, e));
|
|
45
|
+
col = mix(col, lin(SKY.zenith), smoothstep(0.4, 0.75, e));
|
|
46
|
+
col = mix(col, lin(SKY.horizon).mul(0.92), smoothstep(0, -0.08, h)); // under the skyline: haze
|
|
47
|
+
// sun: wide warm wash, halo, disc sitting on the horizon
|
|
48
|
+
col = col.add(vec3(1, 0.62, 0.36).mul(pow(sd, 6).mul(0.4).mul(smoothstep(0, 0.4, e).oneMinus())));
|
|
49
|
+
col = col.add(lin(SKY.sun).mul(pow(sd, 120).mul(0.35)));
|
|
50
|
+
col = col.add(vec3(1, 0.85, 0.6).mul(smoothstep(0.99935, 0.9997, sd).mul(0.9)));
|
|
51
|
+
// puffy clouds: a plane projection, small cumulus clumps in a band
|
|
52
|
+
const cp = d.xz.div(max(h.add(0.08), 0.04)).mul(1.6);
|
|
53
|
+
const band = smoothstep(0.04, 0.1, h).mul(smoothstep(0.3, 0.5, h).oneMinus());
|
|
54
|
+
const shape = fbm(cp.mul(0.55).add(4)).mul(0.75).add(fbm(cp.mul(2.4).add(9), 4).mul(0.38));
|
|
55
|
+
const cloud = smoothstep(0.57, 0.68, shape).mul(band);
|
|
56
|
+
const underside = smoothstep(0.2, 0.75, fbm(cp.mul(2.4).add(vec2(0, 0.6)).add(9), 3)); // lit from below
|
|
57
|
+
const lit = mix(vec3(1, 0.46, 0.46), vec3(1, 0.56, 0.32), pow(sd, 2)).mul(0.86);
|
|
58
|
+
const shade = mix(lin(SKY.mid), lin(SKY.upper), 0.45).mul(0.95);
|
|
59
|
+
const cloudCol = mix(lit, shade, underside.mul(0.35)).mul(mix(1, 0.72, smoothstep(0.14, 0.45, e))); // high clouds sit in shade
|
|
60
|
+
col = mix(col, cloudCol, cloud.mul(0.92));
|
|
61
|
+
// stars, faint at the golden hour (dusk 0)
|
|
62
|
+
const st = step(0.9965, hash(floor(d.xz.div(max(h, 0.15)).mul(260)))).mul(smoothstep(0.35, 0.8, e));
|
|
63
|
+
return col.add(vec3(st, st, st).mul(0.15)).mul(0.95);
|
|
64
|
+
}
|