@wildshard/sdk 0.3.0 → 0.3.1
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/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 +365 -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
|
@@ -9,7 +9,21 @@
|
|
|
9
9
|
"family": "pbr",
|
|
10
10
|
"vertexColours": true,
|
|
11
11
|
"metalness": 0,
|
|
12
|
-
"faceted": false
|
|
12
|
+
"faceted": false,
|
|
13
|
+
"detail": {
|
|
14
|
+
"scale": 0.7,
|
|
15
|
+
"mottle": 0.22,
|
|
16
|
+
"grain": 0.12,
|
|
17
|
+
"relief": 0.6,
|
|
18
|
+
"moss": {
|
|
19
|
+
"colour": [
|
|
20
|
+
0.32,
|
|
21
|
+
0.42,
|
|
22
|
+
0.2
|
|
23
|
+
],
|
|
24
|
+
"amount": 0.22
|
|
25
|
+
}
|
|
26
|
+
}
|
|
13
27
|
},
|
|
14
28
|
"mossgate.mushroom-cap": {
|
|
15
29
|
"family": "emissive",
|
|
@@ -24,19 +38,22 @@
|
|
|
24
38
|
"family": "emissive",
|
|
25
39
|
"colour": [
|
|
26
40
|
1,
|
|
27
|
-
0.
|
|
28
|
-
0.
|
|
41
|
+
0.6,
|
|
42
|
+
0.2
|
|
29
43
|
],
|
|
30
|
-
"intensity":
|
|
44
|
+
"intensity": 1.7,
|
|
45
|
+
"vertexColours": true
|
|
31
46
|
},
|
|
32
47
|
"mossgate.flame": {
|
|
33
48
|
"family": "emissive",
|
|
34
49
|
"colour": [
|
|
35
50
|
1,
|
|
36
|
-
|
|
37
|
-
|
|
51
|
+
1,
|
|
52
|
+
1
|
|
38
53
|
],
|
|
39
|
-
"intensity":
|
|
54
|
+
"intensity": 0.65,
|
|
55
|
+
"vertexColours": true,
|
|
56
|
+
"blend": "additive"
|
|
40
57
|
},
|
|
41
58
|
"mossgate.tell": {
|
|
42
59
|
"family": "emissive",
|
|
@@ -652,13 +669,19 @@
|
|
|
652
669
|
}
|
|
653
670
|
],
|
|
654
671
|
"grade": {
|
|
655
|
-
"exposure": 0,
|
|
672
|
+
"exposure": 0.07,
|
|
656
673
|
"saturation": 1.18,
|
|
657
674
|
"contrast": 1.03,
|
|
658
675
|
"lut": null,
|
|
659
676
|
"bloom": {
|
|
660
677
|
"intensity": 0.6,
|
|
661
|
-
"threshold": 0.9
|
|
678
|
+
"threshold": 0.9,
|
|
679
|
+
"radius": 0.55
|
|
680
|
+
},
|
|
681
|
+
"tone": "aces",
|
|
682
|
+
"vignette": {
|
|
683
|
+
"offset": 0.3,
|
|
684
|
+
"darkness": 0.4
|
|
662
685
|
}
|
|
663
686
|
},
|
|
664
687
|
"clock": "engine",
|
|
@@ -679,9 +702,9 @@
|
|
|
679
702
|
0.2232
|
|
680
703
|
],
|
|
681
704
|
"horizon": [
|
|
682
|
-
|
|
683
|
-
0.
|
|
684
|
-
0.
|
|
705
|
+
0.4342,
|
|
706
|
+
0.1559,
|
|
707
|
+
0.3613
|
|
685
708
|
]
|
|
686
709
|
},
|
|
687
710
|
"fog": {
|
|
@@ -713,7 +736,7 @@
|
|
|
713
736
|
0.1441,
|
|
714
737
|
0.0452
|
|
715
738
|
],
|
|
716
|
-
"intensity":
|
|
739
|
+
"intensity": 0.85
|
|
717
740
|
}
|
|
718
741
|
}
|
|
719
742
|
],
|
|
@@ -746,6 +769,111 @@
|
|
|
746
769
|
-8.3
|
|
747
770
|
]
|
|
748
771
|
]
|
|
772
|
+
},
|
|
773
|
+
"environment": {
|
|
774
|
+
"intensity": 0.4,
|
|
775
|
+
"ground": [
|
|
776
|
+
0.1946,
|
|
777
|
+
0.1441,
|
|
778
|
+
0.0452
|
|
779
|
+
]
|
|
780
|
+
},
|
|
781
|
+
"bounce": {
|
|
782
|
+
"colour": [
|
|
783
|
+
1,
|
|
784
|
+
0.3231,
|
|
785
|
+
0.2159
|
|
786
|
+
],
|
|
787
|
+
"intensity": 1.2,
|
|
788
|
+
"lift": 0.12
|
|
789
|
+
},
|
|
790
|
+
"shadow": {
|
|
791
|
+
"intensity": 0.62,
|
|
792
|
+
"radius": 3,
|
|
793
|
+
"normalBias": 0.03
|
|
794
|
+
},
|
|
795
|
+
"lamps": [
|
|
796
|
+
{
|
|
797
|
+
"at": [
|
|
798
|
+
-3.45,
|
|
799
|
+
2.0,
|
|
800
|
+
-10.8
|
|
801
|
+
],
|
|
802
|
+
"colour": [
|
|
803
|
+
1,
|
|
804
|
+
0.6,
|
|
805
|
+
0.25
|
|
806
|
+
],
|
|
807
|
+
"intensity": 4.5,
|
|
808
|
+
"distance": 7,
|
|
809
|
+
"decay": 1.6,
|
|
810
|
+
"halo": {
|
|
811
|
+
"size": 1.3,
|
|
812
|
+
"opacity": 0.55
|
|
813
|
+
},
|
|
814
|
+
"flicker": {
|
|
815
|
+
"rate": 6,
|
|
816
|
+
"amount": 0.12
|
|
817
|
+
}
|
|
818
|
+
},
|
|
819
|
+
{
|
|
820
|
+
"at": [
|
|
821
|
+
-3.2,
|
|
822
|
+
2.0,
|
|
823
|
+
-15.0
|
|
824
|
+
],
|
|
825
|
+
"colour": [
|
|
826
|
+
1,
|
|
827
|
+
0.55,
|
|
828
|
+
0.2
|
|
829
|
+
],
|
|
830
|
+
"intensity": 8,
|
|
831
|
+
"distance": 6.5,
|
|
832
|
+
"decay": 1.4,
|
|
833
|
+
"halo": {
|
|
834
|
+
"size": 0.9,
|
|
835
|
+
"opacity": 0.45
|
|
836
|
+
},
|
|
837
|
+
"flicker": {
|
|
838
|
+
"rate": 6,
|
|
839
|
+
"amount": 0.12
|
|
840
|
+
}
|
|
841
|
+
},
|
|
842
|
+
{
|
|
843
|
+
"at": [
|
|
844
|
+
-5.4,
|
|
845
|
+
1.5,
|
|
846
|
+
-15.6
|
|
847
|
+
],
|
|
848
|
+
"colour": [
|
|
849
|
+
1,
|
|
850
|
+
0.5,
|
|
851
|
+
0.18
|
|
852
|
+
],
|
|
853
|
+
"intensity": 3,
|
|
854
|
+
"distance": 4,
|
|
855
|
+
"decay": 1.5
|
|
856
|
+
}
|
|
857
|
+
],
|
|
858
|
+
"motes": {
|
|
859
|
+
"count": 160,
|
|
860
|
+
"min": [
|
|
861
|
+
-30,
|
|
862
|
+
0.3,
|
|
863
|
+
-18
|
|
864
|
+
],
|
|
865
|
+
"max": [
|
|
866
|
+
34,
|
|
867
|
+
2.4,
|
|
868
|
+
10
|
|
869
|
+
],
|
|
870
|
+
"colour": [
|
|
871
|
+
1,
|
|
872
|
+
0.644,
|
|
873
|
+
0.195
|
|
874
|
+
],
|
|
875
|
+
"gain": 2,
|
|
876
|
+
"size": 0.12
|
|
749
877
|
}
|
|
750
878
|
}
|
|
751
879
|
}
|
|
@@ -69,7 +69,7 @@
|
|
|
69
69
|
"range": 4,
|
|
70
70
|
"damage": 20,
|
|
71
71
|
"tags": [
|
|
72
|
-
"creature.
|
|
72
|
+
"creature.barrowWarden"
|
|
73
73
|
],
|
|
74
74
|
"weight": 3,
|
|
75
75
|
"speed": 0
|
|
@@ -200,7 +200,25 @@
|
|
|
200
200
|
"chargeDamage": 25,
|
|
201
201
|
"relentless": false
|
|
202
202
|
}
|
|
203
|
-
}
|
|
203
|
+
}
|
|
204
|
+
]
|
|
205
|
+
},
|
|
206
|
+
{
|
|
207
|
+
"id": "barrow-warden",
|
|
208
|
+
"kind": "barrowWarden",
|
|
209
|
+
"label": "Barrow Warden",
|
|
210
|
+
"aggressive": true,
|
|
211
|
+
"lockable": true,
|
|
212
|
+
"dims": {
|
|
213
|
+
"bodyY": 1.0,
|
|
214
|
+
"bodyHalfLen": 0.32,
|
|
215
|
+
"bodyRadius": 0.5,
|
|
216
|
+
"headRadius": 0.22,
|
|
217
|
+
"legLen": 0.47,
|
|
218
|
+
"feet": [],
|
|
219
|
+
"halfWidth": 0.7
|
|
220
|
+
},
|
|
221
|
+
"variants": [
|
|
204
222
|
{
|
|
205
223
|
"id": "warden",
|
|
206
224
|
"label": "Barrow Warden",
|
|
@@ -62,5 +62,37 @@
|
|
|
62
62
|
"critical": false
|
|
63
63
|
}
|
|
64
64
|
]
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
"species": "barrow-warden",
|
|
68
|
+
"look": "template.look.barrowWarden",
|
|
69
|
+
"skin": "3058c100bc477fd6fe8268f33b53756b8a2556e7e41c58b2216c703ca7b042c6",
|
|
70
|
+
"glb": "8a0440f392737a31cf0926a3c7dc011c320144972882945a5462c893e817d94a",
|
|
71
|
+
"files": [
|
|
72
|
+
{
|
|
73
|
+
"hash": "3058c100bc477fd6fe8268f33b53756b8a2556e7e41c58b2216c703ca7b042c6",
|
|
74
|
+
"kind": "json",
|
|
75
|
+
"compressed": 584,
|
|
76
|
+
"decoded": 1168,
|
|
77
|
+
"gpu": 0,
|
|
78
|
+
"triangles": 0,
|
|
79
|
+
"draws": 0,
|
|
80
|
+
"dependencies": [
|
|
81
|
+
"8a0440f392737a31cf0926a3c7dc011c320144972882945a5462c893e817d94a"
|
|
82
|
+
],
|
|
83
|
+
"critical": false
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
"hash": "8a0440f392737a31cf0926a3c7dc011c320144972882945a5462c893e817d94a",
|
|
87
|
+
"kind": "glb",
|
|
88
|
+
"compressed": 248316,
|
|
89
|
+
"decoded": 279584,
|
|
90
|
+
"gpu": 219096,
|
|
91
|
+
"triangles": 1232,
|
|
92
|
+
"draws": 6,
|
|
93
|
+
"dependencies": [],
|
|
94
|
+
"critical": false
|
|
95
|
+
}
|
|
96
|
+
]
|
|
65
97
|
}
|
|
66
98
|
]
|
|
@@ -135,6 +135,24 @@
|
|
|
135
135
|
-3.2
|
|
136
136
|
]
|
|
137
137
|
]
|
|
138
|
+
},
|
|
139
|
+
"surface": {
|
|
140
|
+
"reflect": "planar",
|
|
141
|
+
"tint": [
|
|
142
|
+
0.011,
|
|
143
|
+
0.009,
|
|
144
|
+
0.024
|
|
145
|
+
],
|
|
146
|
+
"fresnel": [
|
|
147
|
+
0.35,
|
|
148
|
+
3
|
|
149
|
+
],
|
|
150
|
+
"ripple": {
|
|
151
|
+
"scale": 3,
|
|
152
|
+
"amplitude": 0.0022,
|
|
153
|
+
"speed": 1
|
|
154
|
+
},
|
|
155
|
+
"resolution": 1024
|
|
138
156
|
}
|
|
139
157
|
}
|
|
140
158
|
]
|
|
@@ -44,6 +44,10 @@ const LF19_LIBRARY = { resident: 70_000, compressed: 36_000 } as const;
|
|
|
44
44
|
/** TEMPLATES-CLEANROOM M2: the switchable panels (moss gate, arena gate, pond stones) carry coursed masonry and weathered
|
|
45
45
|
* vertex colours now; their share of the resident library budget. */
|
|
46
46
|
const M2_MASONRY_RESIDENT = 300_000;
|
|
47
|
+
/** SHARD-SOURCE M4.10: the flame panels' layered additive tongues (braziers A and B, the rim and the row beacons), over
|
|
48
|
+
* LF1-9's five-cone flames. Measured on the build: passes at 15 000 resident and 8 000 compressed, refuses at 0; these
|
|
49
|
+
* leave a margin. */
|
|
50
|
+
const M410_FLAMES = { resident: 30_000, compressed: 16_000 } as const;
|
|
47
51
|
// The idle reserve retains three pairs of Wasm pages and six particle slots.
|
|
48
52
|
const TEMPLATE_ROWS = parseRows(rows);
|
|
49
53
|
/** LF1-5: every props GLB names its surface (templatePropsSource.ts). The stone draws in the look's plain `pbr` (M2: no measure layer); the red
|
|
@@ -90,7 +94,7 @@ const TERRAIN_DRAW = { shadow: { cast: true, receive: true }, follow: 5 } as con
|
|
|
90
94
|
// Retain the old producer's JSON boundary, including signed-zero normalization.
|
|
91
95
|
// oxlint-disable-next-line unicorn/prefer-structured-clone -- JSON wire normalization, not cloning: structuredClone retains forbidden signed zero.
|
|
92
96
|
return parseShardfile(JSON.parse(JSON.stringify({ ...base, accent: 'sand', manifest: CARD,
|
|
93
|
-
budgets: { library: { resident: 100_000 + TEMPLATE_SKIN_COST.resident + CLIENT_IDLE_RESIDENT + 2_633_280 + MH3_LIBRARY_RESIDENT + MH4_LIBRARY_RESIDENT + LF19_LIBRARY.resident + M2_MASONRY_RESIDENT, compressed: 100_000 + CLIENT_IDLE_BYTES + TEMPLATE_SKIN_COST.compressed + LF19_LIBRARY.compressed }, sim: { resident: 16_000_000, compressed: 1_000_000 - boss.compressed }, overlap: 0 },
|
|
97
|
+
budgets: { library: { resident: 100_000 + TEMPLATE_SKIN_COST.resident + CLIENT_IDLE_RESIDENT + 2_633_280 + MH3_LIBRARY_RESIDENT + MH4_LIBRARY_RESIDENT + LF19_LIBRARY.resident + M2_MASONRY_RESIDENT + M410_FLAMES.resident, compressed: 100_000 + CLIENT_IDLE_BYTES + TEMPLATE_SKIN_COST.compressed + LF19_LIBRARY.compressed + M410_FLAMES.compressed }, sim: { resident: 16_000_000, compressed: 1_000_000 - boss.compressed }, overlap: 0 },
|
|
94
98
|
serverBudget: { ...base.serverBudget, tickMicros: 5_000, memory: 16_000_000 },
|
|
95
99
|
look: TEMPLATE_LOOK, spawn: SPAWN, rows: { ...TEMPLATE_ROWS, looks: TEMPLATE_SKIN_LOOKS }, plumbing: TEMPLATE_PLUMBING, ui: TEMPLATE_UI,
|
|
96
100
|
terrain: { ...terrain.terrain, ...TERRAIN_DRAW }, tiles, files: [...terrain.files, ...props.files, ...TEMPLATE_SKIN_FILES, script, itemScript, clientScript], edge: terrain.edge,
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
import { Bone, BufferGeometry, Color, Euler, Float32BufferAttribute, MeshStandardMaterial, Quaternion, Skeleton, SkinnedMesh, Uint16BufferAttribute, Vector3 } from 'three';
|
|
2
|
+
import { sampleSkinClip, skinnedGlb, type SampledSkinClip } from '@wildshard/sdk/bake/export';
|
|
3
|
+
import { parseGlb } from '@wildshard/sdk/assets';
|
|
4
|
+
import { hashImmutableBytes } from '@wildshard/sdk/immutable';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Build-time only (SHARD-SOURCE M4.10, the Template look): the Barrow Warden's skin, a hulking golem of mossy stone blocks
|
|
8
|
+
* after the cleanroom's (mossgate-cleanroom `src/world.js` `warden()`): two block legs, hips, a broad torso with a glowing
|
|
9
|
+
* chest core and ivy, a block head with two glowing eyes under a moss cap, and two heavy block arms that rise into the
|
|
10
|
+
* tell and slam. It is written as an SF9c exported skin: one skinned mesh of flat-shaded chamfered blocks in vertex
|
|
11
|
+
* colours (stone, moss, ivy: the binding's `pbr` family material, one draw) plus two mapped parts (TE-ENG10), `Eyes` and
|
|
12
|
+
* `Core`, drawn in the look's emissive `mossgate.lamp` and `mossgate.tell`. Six joints, bound unrotated and unscaled:
|
|
13
|
+
* `body` (the hips), `head`, `armL`, `armR`, `legL`, `legR`; five sampled clips (idle, walk, attack, hit, die).
|
|
14
|
+
*
|
|
15
|
+
* `scripts/bake/template-warden.mjs` writes the GLB and its `{ row, binding }` skin file into `assets/` and the entry
|
|
16
|
+
* into `data/skins.json`; `warden.test.ts` re-bakes and checks the committed bytes are this function's.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/** The cleanroom golem's own units: its group stood at scale 1.45 against the Template spawn's scale 3; 0.88 of that, since
|
|
20
|
+
* the Template's Warden stands 1 m nearer the arena gate than the cleanroom's (24.5 against 25.5), so the cameras frame
|
|
21
|
+
* it as the cleanroom's (head and raised fists in shot 13). */
|
|
22
|
+
const UNIT = (1.45 / 3) * 0.88;
|
|
23
|
+
/** The body group's height in cleanroom units (its blocks sit on it) and the head's moss cap over it. */
|
|
24
|
+
const BODY_Y = 1.1, CAP_Y = 2.94, CAP_H = 0.18;
|
|
25
|
+
/** The top of the Warden's head (its moss cap) in metres at scale 1: what the open-core gem floats over (world.ts). */
|
|
26
|
+
export const WARDEN_CROWN = (BODY_Y + CAP_Y + CAP_H / 2) * UNIT;
|
|
27
|
+
/** GLB material names: the family surface, and the two look-material parts. */
|
|
28
|
+
export const WARDEN_PARTS = { Eyes: 'mossgate.lamp', Core: 'mossgate.tell' } as const;
|
|
29
|
+
const MATERIALS = ['Stone', 'Eyes', 'Core'] as const;
|
|
30
|
+
const JOINTS = ['body', 'head', 'armL', 'armR', 'legL', 'legR'] as const;
|
|
31
|
+
type Joint = typeof JOINTS[number];
|
|
32
|
+
/** Joint rest positions in world space (cleanroom units, feet at y 0, facing +z; the golem's left is +x). */
|
|
33
|
+
const REST: Record<Joint, readonly [number, number, number]> = {
|
|
34
|
+
body: [0, 1.1, 0], head: [0, 3.2, 0.1], armL: [1.45, 2.95, 0], armR: [-1.45, 2.95, 0], legL: [0.55, 1.1, 0], legR: [-0.55, 1.1, 0],
|
|
35
|
+
};
|
|
36
|
+
// `body` is the one root (the engine's factory hangs only `body` on the mesh), so the legs hang from it too
|
|
37
|
+
const PARENT: Record<Joint, Joint | null> = { body: null, head: 'body', armL: 'body', armR: 'body', legL: 'body', legR: 'body' };
|
|
38
|
+
|
|
39
|
+
const STONE = '#aba79a', STONE_DARK = '#87847a', MOSS = '#8fb33a', MOSS_DARK = '#6b8c2c', IVY = '#3f6a24', LEAF = '#5f8e2e';
|
|
40
|
+
const EYE = '#ffb040', CORE = '#ff9a30';
|
|
41
|
+
|
|
42
|
+
/** mulberry32: the golem's tints and moss are the same every bake. */
|
|
43
|
+
function random(seed: number): () => number {
|
|
44
|
+
let state = seed >>> 0;
|
|
45
|
+
return () => { state = (state + 0x6d2b79f5) >>> 0; let t = state; t = Math.imul(t ^ (t >>> 15), t | 1); t ^= t + Math.imul(t ^ (t >>> 7), t | 61); return ((t ^ (t >>> 14)) >>> 0) / 4294967296; };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
interface Polygon { readonly points: readonly Vector3[]; readonly colour: Color; readonly joint: number; readonly material: number }
|
|
49
|
+
/** The hull under construction: flat polygons per material, each vertex rigidly bound to one joint. */
|
|
50
|
+
class Hull {
|
|
51
|
+
readonly polygons: Polygon[] = [];
|
|
52
|
+
private readonly rand: () => number;
|
|
53
|
+
constructor(seed: number) { this.rand = random(seed); }
|
|
54
|
+
range(min: number, max: number): number { return min + (max - min) * this.rand(); }
|
|
55
|
+
/** A box with chamfered edges and corners (26 faces, 44 triangles), or a plain box at `chamfer: 0` (12), tilted about its centre. */
|
|
56
|
+
block(joint: Joint, centre: readonly [number, number, number], size: readonly [number, number, number], options: { chamfer?: number; rotation?: readonly [number, number, number]; colour?: (normal: Vector3, height: number) => Color; material?: number } = {}): void {
|
|
57
|
+
const [w, h, d] = size.map((value) => value / 2) as [number, number, number], c = Math.min(options.chamfer ?? 0.09, w * 0.45, h * 0.45, d * 0.45);
|
|
58
|
+
const turn = new Quaternion().setFromEuler(new Euler(...(options.rotation ?? [0, 0, 0]))), at = new Vector3(...centre);
|
|
59
|
+
const place = (x: number, y: number, z: number): Vector3 => new Vector3(x, y, z).applyQuaternion(turn).add(at);
|
|
60
|
+
const corner = (sx: number, sy: number, sz: number): { x: Vector3; y: Vector3; z: Vector3 } => ({
|
|
61
|
+
x: place(sx * w, sy * (h - c), sz * (d - c)), y: place(sx * (w - c), sy * h, sz * (d - c)), z: place(sx * (w - c), sy * (h - c), sz * d),
|
|
62
|
+
});
|
|
63
|
+
const k = (sx: number, sy: number, sz: number): ReturnType<typeof corner> => corner(sx, sy, sz);
|
|
64
|
+
const faces: Vector3[][] = [];
|
|
65
|
+
for (const s of [-1, 1]) {
|
|
66
|
+
faces.push([k(s, -1, -1).x, k(s, 1, -1).x, k(s, 1, 1).x, k(s, -1, 1).x]);
|
|
67
|
+
faces.push([k(-1, s, -1).y, k(1, s, -1).y, k(1, s, 1).y, k(-1, s, 1).y]);
|
|
68
|
+
faces.push([k(-1, -1, s).z, k(1, -1, s).z, k(1, 1, s).z, k(-1, 1, s).z]);
|
|
69
|
+
if (c > 0) for (const t of [-1, 1]) {
|
|
70
|
+
faces.push([k(-1, s, t).y, k(1, s, t).y, k(1, s, t).z, k(-1, s, t).z]); // edges along x
|
|
71
|
+
faces.push([k(s, -1, t).x, k(s, 1, t).x, k(s, 1, t).z, k(s, -1, t).z]); // edges along y
|
|
72
|
+
faces.push([k(s, t, -1).x, k(s, t, 1).x, k(s, t, 1).y, k(s, t, -1).y]); // edges along z
|
|
73
|
+
for (const u of [-1, 1]) { const q = k(s, t, u); faces.push([q.x, q.y, q.z]); }
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
const material = options.material ?? 0, index = JOINTS.indexOf(joint), tint = this.range(0.8, 1.0);
|
|
77
|
+
for (const points of faces) {
|
|
78
|
+
const centroid = points.reduce((sum, p) => sum.add(p), new Vector3()).multiplyScalar(1 / points.length);
|
|
79
|
+
const normal = new Vector3().subVectors(points[1] ?? at, points[0] ?? at).cross(new Vector3().subVectors(points[2] ?? at, points[0] ?? at)).normalize();
|
|
80
|
+
const ordered = normal.dot(new Vector3().subVectors(centroid, at)) < 0 ? [...points].reverse() : points;
|
|
81
|
+
if (normal.dot(new Vector3().subVectors(centroid, at)) < 0) normal.negate();
|
|
82
|
+
const height = (centroid.y - (at.y - h)) / (2 * h);
|
|
83
|
+
const colour = options.colour?.(normal, height) ?? stoneColour(normal, height, tint, this.rand());
|
|
84
|
+
this.polygons.push({ points: ordered, colour, joint: index, material });
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/** A moss cap: a soft green slab over a block's top, with a few drips down its faces. */
|
|
88
|
+
moss(joint: Joint, centre: readonly [number, number, number], size: readonly [number, number, number], drips: number, rotation: readonly [number, number, number] = [0, 0, 0]): void {
|
|
89
|
+
const [w, h, d] = size, tone = this.range(0.85, 1.05);
|
|
90
|
+
this.block(joint, centre, size, { chamfer: Math.min(h * 0.45, 0.16), rotation, colour: (normal) => colourOf(normal.y > 0.3 ? MOSS : MOSS_DARK, tone) });
|
|
91
|
+
for (let i = 0; i < drips; i++) {
|
|
92
|
+
const side = this.rand(), long = this.range(0.18, 0.5), across = this.range(-0.42, 0.42);
|
|
93
|
+
const [x, z] = side < 0.5 ? [across * w, (side < 0.25 ? 1 : -1) * (d / 2 - 0.02)] : [(side < 0.75 ? 1 : -1) * (w / 2 - 0.02), across * d];
|
|
94
|
+
const thin: [number, number, number] = side < 0.5 ? [this.range(0.14, 0.3), long, 0.08] : [0.08, long, this.range(0.14, 0.3)];
|
|
95
|
+
this.block(joint, [centre[0] + x, centre[1] - h / 2 - long / 2 + 0.06, centre[2] + z], thin, { chamfer: 0, rotation, colour: (normal) => colourOf(normal.y > 0.3 ? MOSS : MOSS_DARK, tone * 0.92) });
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/** An ivy vine hanging down a face at depth `z`: thin stem blocks wandering sideways, with leaf diamonds. */
|
|
99
|
+
ivy(joint: Joint, top: readonly [number, number, number], length: number, facing: 1 | -1 = 1): void {
|
|
100
|
+
let [x, y] = top; const z = top[2], steps = Math.max(2, Math.round(length / 0.4));
|
|
101
|
+
for (let i = 0; i < steps; i++) {
|
|
102
|
+
const dx = this.range(-0.12, 0.12), seg = length / steps, angle = Math.atan2(dx, seg);
|
|
103
|
+
this.block(joint, [x + dx / 2, y - seg / 2, z], [0.06, Math.hypot(seg, dx) + 0.03, 0.05], { chamfer: 0, rotation: [0, 0, angle], colour: () => colourOf(IVY, 1) });
|
|
104
|
+
if (this.rand() < 0.75) {
|
|
105
|
+
const side = this.rand() < 0.5 ? -1 : 1, lx = x + side * 0.1, ly = y - seg * 0.5, s = this.range(0.07, 0.11), tone = this.range(0.85, 1.1);
|
|
106
|
+
const leaf = [new Vector3(lx, ly + s, z + facing * 0.03), new Vector3(lx + side * s * 1.2, ly, z + facing * 0.04), new Vector3(lx, ly - s, z + facing * 0.03), new Vector3(lx - side * s * 0.6, ly, z + facing * 0.025)];
|
|
107
|
+
this.polygons.push({ points: facing * side > 0 ? [...leaf].reverse() : leaf, colour: colourOf(LEAF, tone), joint: JOINTS.indexOf(joint), material: 0 });
|
|
108
|
+
}
|
|
109
|
+
x += dx; y -= seg;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/** A glowing octahedron (the chest core), material 2. */
|
|
113
|
+
gem(joint: Joint, centre: readonly [number, number, number], radius: number, depth: number): void {
|
|
114
|
+
const [x, y, z] = centre, index = JOINTS.indexOf(joint), colour = colourOf(CORE, 1);
|
|
115
|
+
const tips = [new Vector3(x + radius, y, z), new Vector3(x, y + radius, z), new Vector3(x - radius, y, z), new Vector3(x, y - radius, z)];
|
|
116
|
+
const front = new Vector3(x, y, z + depth), back = new Vector3(x, y, z - depth * 0.4);
|
|
117
|
+
for (let i = 0; i < 4; i++) {
|
|
118
|
+
const a = tips[i] ?? front, b = tips[(i + 1) % 4] ?? front;
|
|
119
|
+
this.polygons.push({ points: [a, b, front], colour, joint: index, material: 2 }, { points: [b, a, back], colour, joint: index, material: 2 });
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function colourOf(hex: string, scale: number): Color { return new Color(hex).multiplyScalar(scale); }
|
|
125
|
+
/** Stone tinted per block, darker low on the block, with moss on most up-facing faces. */
|
|
126
|
+
function stoneColour(normal: Vector3, height: number, tint: number, roll: number): Color {
|
|
127
|
+
if (normal.y > 0.6 && roll < 0.7) return colourOf(MOSS, 0.9 + roll * 0.15);
|
|
128
|
+
const base = new Color(STONE).lerp(new Color(STONE_DARK), 0.5 - height * 0.5);
|
|
129
|
+
return base.multiplyScalar(tint * (0.88 + 0.12 * height));
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** The golem's blocks and dressing, after the cleanroom's (its body group sat at y 1.1). */
|
|
133
|
+
function buildHull(): Hull {
|
|
134
|
+
const hull = new Hull(437), b = BODY_Y;
|
|
135
|
+
for (const [s, joint] of [[1, 'legL'], [-1, 'legR']] as const) {
|
|
136
|
+
hull.block(joint, [s * 0.55, 0.62, 0], [0.75, 1.0, 0.8], { rotation: [0, hull.range(-0.06, 0.06), 0] });
|
|
137
|
+
hull.block(joint, [s * 0.55, 0.17, 0.08], [0.9, 0.35, 1.0], { chamfer: 0.07 });
|
|
138
|
+
}
|
|
139
|
+
hull.block('body', [0, b + 0.3, 0], [1.5, 0.6, 1.0], { rotation: [0, 0, 0.03] });
|
|
140
|
+
hull.block('body', [0, b + 1.35, 0], [2.3, 1.5, 1.35], { chamfer: 0.14 });
|
|
141
|
+
// the chest slab's cracks: two darker plates set into the torso front around the core
|
|
142
|
+
hull.block('body', [-0.55, b + 1.55, 0.66], [0.75, 0.62, 0.1], { chamfer: 0, rotation: [0, 0, 0.06], colour: (n, h) => stoneColour(n, h, 0.82, 1) });
|
|
143
|
+
hull.block('body', [0.52, b + 1.1, 0.66], [0.8, 0.55, 0.1], { chamfer: 0, rotation: [0, 0, -0.05], colour: (n, h) => stoneColour(n, h, 0.8, 1) });
|
|
144
|
+
hull.gem('body', [0, b + 1.35, 0.72], 0.24, 0.16);
|
|
145
|
+
hull.moss('body', [0, b + 2.12, 0], [2.42, 0.26, 1.45], 6);
|
|
146
|
+
for (const [x, length] of [[-0.85, 1.25], [-0.32, 0.8], [0.3, 1.05], [0.82, 1.35]] as const) hull.ivy('body', [x, b + 2.05, 0.71], length);
|
|
147
|
+
hull.block('head', [0, b + 2.5, 0.15], [0.95, 0.8, 0.9], { chamfer: 0.1 });
|
|
148
|
+
hull.block('head', [0, b + 2.36, 0.5], [0.7, 0.16, 0.22], { chamfer: 0.04, colour: (n, h) => stoneColour(n, h, 0.78, 1) }); // brow-less jaw ledge
|
|
149
|
+
for (const s of [-1, 1]) hull.block('head', [s * 0.2, b + 2.58, 0.61], [0.18, 0.09, 0.05], { chamfer: 0, material: 1, colour: () => colourOf(EYE, 1) });
|
|
150
|
+
hull.moss('head', [0, b + CAP_Y, 0.12], [1.02, CAP_H, 0.98], 3);
|
|
151
|
+
for (const [s, joint] of [[1, 'armL'], [-1, 'armR']] as const) {
|
|
152
|
+
const x = s * 1.45, y = b + 1.85;
|
|
153
|
+
hull.block(joint, [x, y, 0], [0.85, 0.8, 0.85]);
|
|
154
|
+
hull.moss(joint, [x, y + 0.45, 0], [0.95, 0.2, 0.95], 2);
|
|
155
|
+
hull.block(joint, [x, y - 0.85, 0], [0.65, 1.0, 0.65], { rotation: [0, hull.range(-0.1, 0.1), 0] });
|
|
156
|
+
hull.block(joint, [x, y - 1.75, 0.05], [0.9, 0.85, 0.9]);
|
|
157
|
+
hull.ivy(joint, [x + s * 0.1, y + 0.3, 0.44], 1.1);
|
|
158
|
+
}
|
|
159
|
+
return hull;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** The skinned mesh: polygons fanned into indexed triangles, grouped by material, each vertex on one joint. */
|
|
163
|
+
function buildMesh(hull: Hull): SkinnedMesh {
|
|
164
|
+
const positions: number[] = [], normals: number[] = [], uvs: number[] = [], colours: number[] = [], joints: number[] = [], weights: number[] = [], indices: number[] = [];
|
|
165
|
+
const geometry = new BufferGeometry();
|
|
166
|
+
MATERIALS.forEach((_name, material) => {
|
|
167
|
+
const start = indices.length;
|
|
168
|
+
for (const polygon of hull.polygons.filter((row) => row.material === material)) {
|
|
169
|
+
const [a, b2, c] = polygon.points; if (a === undefined || b2 === undefined || c === undefined) throw new Error('Warden polygon');
|
|
170
|
+
const normal = new Vector3().subVectors(b2, a).cross(new Vector3().subVectors(c, a)).normalize(), first = positions.length / 3;
|
|
171
|
+
const [u, v] = Math.abs(normal.y) > 0.7 ? ['x', 'z'] as const : Math.abs(normal.x) > 0.7 ? ['z', 'y'] as const : ['x', 'y'] as const;
|
|
172
|
+
for (const point of polygon.points) {
|
|
173
|
+
positions.push(point.x * UNIT, point.y * UNIT, point.z * UNIT); normals.push(normal.x, normal.y, normal.z); uvs.push(point[u] * UNIT, point[v] * UNIT);
|
|
174
|
+
colours.push(polygon.colour.r, polygon.colour.g, polygon.colour.b); joints.push(polygon.joint, 0, 0, 0); weights.push(1, 0, 0, 0);
|
|
175
|
+
}
|
|
176
|
+
for (let i = 1; i + 1 < polygon.points.length; i++) indices.push(first, first + i, first + i + 1);
|
|
177
|
+
}
|
|
178
|
+
geometry.addGroup(start, indices.length - start, material);
|
|
179
|
+
});
|
|
180
|
+
geometry.setAttribute('position', new Float32BufferAttribute(positions, 3)); geometry.setAttribute('normal', new Float32BufferAttribute(normals, 3));
|
|
181
|
+
geometry.setAttribute('uv', new Float32BufferAttribute(uvs, 2)); geometry.setAttribute('color', new Float32BufferAttribute(colours, 3));
|
|
182
|
+
geometry.setAttribute('skinIndex', new Uint16BufferAttribute(joints, 4)); geometry.setAttribute('skinWeight', new Float32BufferAttribute(weights, 4)); geometry.setIndex(indices);
|
|
183
|
+
const materials = MATERIALS.map((name) => { const material = new MeshStandardMaterial({ vertexColors: true, roughness: 0.9, metalness: 0 }); material.name = name; return material; });
|
|
184
|
+
const mesh = new SkinnedMesh(geometry, materials); mesh.name = 'barrow-warden'; mesh.castShadow = true;
|
|
185
|
+
const bones = new Map<Joint, Bone>();
|
|
186
|
+
for (const name of JOINTS) {
|
|
187
|
+
const bone = new Bone(); bone.name = name; const parent = PARENT[name], at = REST[name], from = parent === null ? [0, 0, 0] : REST[parent];
|
|
188
|
+
bone.position.set((at[0] - (from[0] ?? 0)) * UNIT, (at[1] - (from[1] ?? 0)) * UNIT, (at[2] - (from[2] ?? 0)) * UNIT);
|
|
189
|
+
(parent === null ? mesh : bones.get(parent))?.add(bone); bones.set(name, bone);
|
|
190
|
+
}
|
|
191
|
+
mesh.updateMatrixWorld(true); mesh.bind(new Skeleton(JOINTS.map((name) => bones.get(name) ?? new Bone())));
|
|
192
|
+
return mesh;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
const smooth = (t: number): number => { const x = Math.min(1, Math.max(0, t)); return x * x * (3 - 2 * x); };
|
|
196
|
+
/** 0 → 1 across [from, to], eased. */
|
|
197
|
+
const ease = (t: number, from: number, to: number): number => smooth((t - from) / (to - from));
|
|
198
|
+
const mix = (a: number, b: number, t: number): number => a + (b - a) * t;
|
|
199
|
+
interface Pose { body?: [number, number, number]; bodyY?: number; bodyZ?: number; head?: [number, number, number]; armL?: [number, number, number]; armR?: [number, number, number]; legL?: [number, number, number]; legR?: [number, number, number] }
|
|
200
|
+
/** Arms hang a touch outward at rest (the cleanroom's s * 0.12). */
|
|
201
|
+
const HANG = 0.12;
|
|
202
|
+
|
|
203
|
+
/** Set every joint from rest: Euler angles (XYZ) per joint, the body raised or pushed in cleanroom units. The legs' angles are
|
|
204
|
+
* world angles (they hang from the body, so its lean is taken back out of them and they stay planted). */
|
|
205
|
+
function apply(mesh: SkinnedMesh, rest: ReadonlyMap<string, Vector3>, pose: Pose): void {
|
|
206
|
+
for (const bone of mesh.skeleton.bones) {
|
|
207
|
+
const name = bone.name as Joint, base = rest.get(name); if (base === undefined) throw new Error('Warden rest');
|
|
208
|
+
bone.position.copy(base);
|
|
209
|
+
const angles = pose[name] ?? (name === 'armL' ? [0, 0, HANG] : name === 'armR' ? [0, 0, -HANG] : [0, 0, 0]);
|
|
210
|
+
bone.quaternion.setFromEuler(new Euler(angles[0], angles[1], angles[2], 'XYZ'));
|
|
211
|
+
}
|
|
212
|
+
const lean = new Quaternion().setFromEuler(new Euler(...(pose.body ?? [0, 0, 0]), 'XYZ')).invert();
|
|
213
|
+
for (const leg of mesh.skeleton.bones.filter((bone) => bone.name === 'legL' || bone.name === 'legR')) leg.quaternion.premultiply(lean);
|
|
214
|
+
const body = mesh.skeleton.bones.find((bone) => bone.name === 'body');
|
|
215
|
+
if (body !== undefined) { body.position.y += (pose.bodyY ?? 0) * UNIT; body.position.z += (pose.bodyZ ?? 0) * UNIT; }
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/** The five clips as pose closures over normalized time (idle 2 s, walk 1 s, attack 1 s at attackSpan 1, hit 0.6 s, die 2 s). */
|
|
219
|
+
function clipPose(name: string, t: number): Pose {
|
|
220
|
+
const tau = Math.PI * 2;
|
|
221
|
+
switch (name) {
|
|
222
|
+
case 'idle': { const w = Math.sin(t / 2 * tau);
|
|
223
|
+
return { bodyY: 0.02 * w, body: [0.015 * w, 0, 0], head: [-0.02 * w, 0.08 * Math.sin(t / 2 * tau + 1), 0], armL: [0.04 * w, 0, HANG + 0.03 * w], armR: [0.04 * w, 0, -HANG - 0.03 * w] }; }
|
|
224
|
+
case 'walk': { const p = t * tau, s = Math.sin(p);
|
|
225
|
+
return { bodyY: -0.05 + 0.05 * Math.abs(Math.cos(p)), body: [0.05, 0, 0.04 * s], head: [-0.03, -0.05 * s, 0], legL: [0.35 * s, 0, 0], legR: [-0.35 * s, 0, 0], armL: [-0.3 * s, 0, HANG + 0.05], armR: [0.3 * s, 0, -HANG - 0.05] }; }
|
|
226
|
+
case 'attack': {
|
|
227
|
+
// 0 → 0.5: both arms rise into the tell (the cleanroom's raised V); 0.5 → 0.58 they meet overhead; 0.58 → 0.64 the
|
|
228
|
+
// slam (fists to the ground before it, the body pitched over them); held to 0.78, then back to rest
|
|
229
|
+
const raise = ease(t, 0, 0.42), meet = ease(t, 0.5, 0.58), slam = ease(t, 0.58, 0.64), back = ease(t, 0.78, 1);
|
|
230
|
+
const arm = (s: 1 | -1): [number, number, number] => {
|
|
231
|
+
const x = mix(mix(0, -2.75, meet), -0.75, slam), z = mix(mix(s * HANG, s * 2.6, raise), s * 0.3, meet);
|
|
232
|
+
return [mix(x, 0, back), 0, mix(slam > 0 ? mix(z, s * 0.18, slam) : z, s * HANG, back)];
|
|
233
|
+
};
|
|
234
|
+
const lean = mix(mix(-0.14 * raise, 0.7, slam), 0, back), drop = mix(mix(0.04 * raise, 0, slam), 0, back);
|
|
235
|
+
return { body: [lean, 0, 0], bodyY: drop, head: [mix(-0.2 * raise * (1 - slam), 0.1 * slam, 1 - back), 0, 0], armL: arm(1), armR: arm(-1) }; }
|
|
236
|
+
case 'hit': { const k = Math.sin(Math.min(1, t / 0.6) * Math.PI) * (1 - t / 0.6 * 0.3);
|
|
237
|
+
return { body: [-0.16 * k, 0.06 * k, 0], bodyZ: -0.12 * k, head: [-0.12 * k, 0, 0.06 * k], armL: [0.25 * k, 0, HANG + 0.2 * k], armR: [0.25 * k, 0, -HANG - 0.2 * k] }; }
|
|
238
|
+
case 'die': {
|
|
239
|
+
// the legs give, the golem sinks and topples back, arms splayed, the head lolling (held on the last frame)
|
|
240
|
+
const sink = ease(t, 0, 0.7), fall = ease(t, 0.35, 1.3), settle = ease(t, 1.1, 1.5);
|
|
241
|
+
const y = -0.6 * sink - 0.3 * fall, z = -0.9 * fall;
|
|
242
|
+
return { bodyY: y, bodyZ: z, body: [-1.25 * fall, 0, 0.12 * sink], head: [-0.3 * fall - 0.15 * settle, 0.4 * settle, 0.25 * settle],
|
|
243
|
+
armL: [-0.4 * fall, 0, HANG + 1.1 * fall], armR: [-0.6 * fall, 0, -HANG - 0.9 * fall], legL: [-1.4 * sink, 0, 0.2 * sink], legR: [-1.3 * sink, 0, -0.25 * sink] }; }
|
|
244
|
+
default: throw new Error(`Warden clip ${name}`);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
const CLIPS = [['idle', 2], ['walk', 1], ['attack', 1], ['hit', 0.6], ['die', 2]] as const;
|
|
249
|
+
/** The skin's clip rate: 30 Hz linear samples, half the bytes of 60 Hz on slow stone. */
|
|
250
|
+
const RATE = 30;
|
|
251
|
+
|
|
252
|
+
/** One `data/skins.json` entry, as `product.ts` reads it. */
|
|
253
|
+
export interface WardenSkinEntry {
|
|
254
|
+
species: string; look: string; skin: string; glb: string;
|
|
255
|
+
files: { hash: string; kind: 'json' | 'glb'; compressed: number; decoded: number; gpu: number; triangles: number; draws: number; dependencies: string[]; critical: boolean }[];
|
|
256
|
+
}
|
|
257
|
+
/** Bake the Warden: the GLB, its `{ row, binding }` skin file and the skins.json entry, deterministic from this source. */
|
|
258
|
+
export async function bakeWardenSkin(): Promise<{ glb: Uint8Array; json: Uint8Array; entry: WardenSkinEntry }> {
|
|
259
|
+
const mesh = buildMesh(buildHull()), rest = new Map(mesh.skeleton.bones.map((bone) => [bone.name, bone.position.clone()]));
|
|
260
|
+
try {
|
|
261
|
+
const clips: SampledSkinClip[] = CLIPS.map(([name, duration]) => sampleSkinClip(mesh, name, duration, (time) => { apply(mesh, rest, clipPose(name, time)); }, RATE));
|
|
262
|
+
const glb = await skinnedGlb(mesh, clips, 'barrow-warden'), cost = parseGlb(glb), file = hashImmutableBytes(glb);
|
|
263
|
+
const row = { id: 'barrow-warden', file, family: 'pbr', rig: { skeleton: 'template.barrowWarden', joints: [[...JOINTS]], clips: CLIPS.map(([name]) => name), sockets: ['body', 'head'] },
|
|
264
|
+
cost: { decoded: cost.decoded, gpu: cost.gpu, triangles: cost.triangles, draws: cost.draws } };
|
|
265
|
+
const binding = { skin: 'barrow-warden', material: { family: 'pbr', roughness: 0.9, metalness: 0, occlusion: 0, envStrength: 0.7, vertexColours: true }, materials: { ...WARDEN_PARTS }, loops: ['idle', 'walk'] };
|
|
266
|
+
const json = new TextEncoder().encode(JSON.stringify({ row, binding })), skin = hashImmutableBytes(json);
|
|
267
|
+
return { glb, json, entry: { species: 'barrow-warden', look: 'template.look.barrowWarden', skin, glb: file, files: [
|
|
268
|
+
// the parsed rows: twice the text, over the plain JSON charge (as scripts/bake/template-skins.mjs declares the others)
|
|
269
|
+
{ hash: skin, kind: 'json', compressed: json.length, decoded: json.length * 2, gpu: 0, triangles: 0, draws: 0, dependencies: [file], critical: false },
|
|
270
|
+
{ hash: file, kind: 'glb', compressed: glb.length, decoded: cost.decoded, gpu: cost.gpu, triangles: cost.triangles, draws: cost.draws, dependencies: [], critical: false },
|
|
271
|
+
] } };
|
|
272
|
+
} finally { mesh.geometry.dispose(); for (const material of [mesh.material].flat()) material.dispose(); }
|
|
273
|
+
}
|