sourceextensions/blender/demos/Td.xtl
1⍝│ Td.xtl -- the tower defense pieces of X_eTaL-games, described in
2⍝│ X_eTaL as Blender parts (Bpy.xtl): three towers at three levels --
3⍝│ arrow, cannon, frost -- and three creeps -- runner, brute, shield.
4⍝│ Each piece stands on a 1 by 1 tile at z 0, its front (and the part
5⍝│ that aims) toward -y, a tower's base about 0.8 wide, a creep's about
6⍝│ 0.5; flat colors, the frost crystals glowing. Each has its clips: idle
7⍝│ (2 s, a loop) for all, fire (0.4 s) for towers, walk (1 s, a loop)
8⍝│ and hit (0.3 s) for creeps. A part that moves in a clip hangs in a
9⍝│ group (bp:g_roup), so it turns about its own pivot.
10⍝│ Import: "td:" u_se< "Td"
11
12"bp:" u̲se< "Bpy"
13"dg:" u̲se< "Digest"
14
15⍝━━ Colors and keys
16
17wood ← 0.55 0.36 0.2
18darkwood ← 0.33 0.21 0.12
19stone ← 0.62 0.62 0.64
20darkstone ← 0.42 0.42 0.45
21iron ← 0.25 0.25 0.28
22black ← 0.1 0.1 0.11
23red ← 0.8 0.12 0.1
24brass ← 0.85 0.66 0.25
25ice ← 0.7 0.88 1.0
26silver ← 0.82 0.84 0.88
27green ← 0.35 0.85 0.25
28darkgreen ← 0.18 0.48 0.14
29brown ← 0.55 0.25 0.15
30darkbrown ← 0.3 0.15 0.1
31bone ← 0.9 0.85 0.7
32amber ← 1.0 0.8 0.2
33steel ← 0.35 0.5 0.72
34darksteel ← 0.22 0.3 0.42
35cyan ← 0.4 0.9 1.0
36white ← 0.95 0.95 0.95
37flat ← 0.0 0.0 0.0
38one ← 1.0 1.0 1.0
39
40⍝ the clips' times and how far along each key is: idle swings out and
41⍝ back each way (sway) or breathes once (breathe) or turns (turn) in 2
42⍝ s; fire and hit kick out and back; walk lifts one pair of feet, then
43⍝ the other
44idle ← 0.0 0.5 1.0 1.5 2.0
45sway ← 0.0 1.0 0.0 -1.0 0.0
46slow ← 0.0 1.0 2.0
47breathe ← 0.0 1.0 0.0
48turn ← 0.0 1.0 2.0
49fire ← 0.0 0.08 0.4
50hit ← 0.0 0.1 0.3
51kick ← 0.0 1.0 0.0
52walk ← 0.0 0.25 0.5 0.75 1.0
53stepa ← 0.0 1.0 0.0 0.0 0.0
54stepb ← 0.0 0.0 0.0 1.0 0.0
55bob ← 0.0 1.0 0.0 1.0 0.0
56
57⍝ keys from a part's rest: each key is rest + k * delta, for the k of
58⍝ each time
59ʰk̲ey ← { (part, clip, what, rest, delta, times, ks) z →
60 n ← t̲ally ks
61 (part, clip, what, times, ((n c̲at 3) r̲eshape rest) + ks '× t̲able delta) ᵇᵖk̲eys 0
62}
63
64⍝━━ Arrow towers
65
66⍝ a crossbow in a group, about its pivot: stock, limbs, a bolt
67ʰc̲rossbow ← { (p, x, len) z →
68 ((((p c̲at " stock", x c̲at -0.04 0.06, 0.07 c̲at len c̲at 0.07, flat, darkwood, 0.0) ᵇᵖb̲ox 0)) c̲at
69 (((p c̲at " limbs", x c̲at (-0.02 − len ÷ 2.0) c̲at 0.07, 0.44 0.05 0.04 × (len ÷ 0.44) c̲at 1.0 1.0, flat, wood, 0.0) ᵇᵖb̲ox 0)) c̲at
70 ((p c̲at " bolt", x c̲at (0.02 − len ÷ 2.0) c̲at 0.11, 0.015 0.015 c̲at len × 0.8, 90.0 0.0 0.0, iron, 0.0) ᵇᵖc̲ylinder 0))
71}
72
73⍝ idle sways the aim, fire kicks it back
74ʰa̲imKeys ← { (p, at, deg, back) z →
75 ((p c̲at " aim", "idle", "rotation", flat, 0.0 0.0 c̲at deg, idle, sway) ʰk̲ey 0) c̲at ((p c̲at " aim", "fire", "location", at, 0.0 c̲at back c̲at 0.0, fire, kick) ʰk̲ey 0)
76}
77
78⍝ the four merlons on a top at z, half a width w apart
79ʰm̲erlons ← { (p, w, z, rgb) z0 →
80 m̲k ← { (n, x, y) z1 → (p c̲at " merlon " c̲at n, x c̲at y c̲at z, 0.14 0.14 0.12, flat, rgb, 0.0) ᵇᵖb̲ox 0 }
81 (("1", w, w) m̲k 0) c̲at (("2", 0.0 − w, w) m̲k 0) c̲at (("3", w, 0.0 − w) m̲k 0) c̲at ("4", 0.0 − w, 0.0 − w) m̲k 0
82}
83
84ʰa̲rrow1 ← { z →
85 (((ᵇᵖp̲iece "arrow-1") c̲at (("arrow-1 base", 0.0 0.0 0.04, 0.8 0.8 0.08, flat, darkwood, 0.0) ᵇᵖb̲ox 0)) c̲at
86 ((("arrow-1 post", 0.0 0.0 0.36, 0.5 0.5 0.56, flat, wood, 0.0) ᵇᵖb̲ox 0) c̲at (("arrow-1 deck", 0.0 0.0 0.68, 0.66 0.66 0.08, flat, darkwood, 0.0) ᵇᵖb̲ox 0)) c̲at
87 ((("arrow-1 aim", 0.0 0.0 0.72, flat) ᵇᵖg̲roup 0) c̲at (("arrow-1", 0.0, 0.44) ʰc̲rossbow 0) c̲at ᵇᵖungroup) c̲at
88 ("arrow-1", 0.0 0.0 0.72, 12.0, 0.08) ʰa̲imKeys 0)
89}
90
91ʰa̲rrow2 ← { z →
92 (((ᵇᵖp̲iece "arrow-2") c̲at (("arrow-2 base", 0.0 0.0 0.05, 0.8 0.8 0.1, flat, darkstone, 0.0) ᵇᵖb̲ox 0)) c̲at
93 ((("arrow-2 tower", 0.0 0.0 0.5, 0.6 0.6 0.8, flat, stone, 0.0) ᵇᵖb̲ox 0) c̲at ("arrow-2", 0.23, 0.96, stone) ʰm̲erlons 0) c̲at
94 ((("arrow-2 aim", 0.0 0.0 0.92, flat) ᵇᵖg̲roup 0) c̲at (("arrow-2 left", -0.12, 0.36) ʰc̲rossbow 0) c̲at (("arrow-2 right", 0.12, 0.36) ʰc̲rossbow 0) c̲at ᵇᵖungroup) c̲at
95 ("arrow-2", 0.0 0.0 0.92, 12.0, 0.08) ʰa̲imKeys 0)
96}
97
98ʰa̲rrow3 ← { z →
99 t ← (((ᵇᵖp̲iece "arrow-3") c̲at (("arrow-3 base", 0.0 0.0 0.05, 0.8 0.8 0.1, flat, darkstone, 0.0) ᵇᵖb̲ox 0)) c̲at
100 ((("arrow-3 tower", 0.0 0.0 0.65, 0.56 0.56 1.1, flat, stone, 0.0) ᵇᵖb̲ox 0) c̲at (("arrow-3 ledge", 0.0 0.0 1.2, 0.66 0.66 0.06, flat, darkstone, 0.0) ᵇᵖb̲ox 0)) c̲at
101 (("arrow-3", 0.26, 1.29, stone) ʰm̲erlons 0) c̲at
102 ((("arrow-3 aim", 0.0 0.0 1.26, flat) ᵇᵖg̲roup 0) c̲at (("arrow-3 frame", 0.0 -0.02 0.07, 0.16 0.5 0.1, flat, darkwood, 0.0) ᵇᵖb̲ox 0)) c̲at
103 (("arrow-3 limbs", 0.0 -0.24 0.1, 0.62 0.06 0.05, flat, wood, 0.0) ᵇᵖb̲ox 0) c̲at (("arrow-3 drum", 0.0 0.12 0.16, 0.08 0.08 0.16, 0.0 90.0 0.0, iron, 0.0) ᵇᵖc̲ylinder 0))
104 b̲olt ← { (n, x) z1 → ("arrow-3 bolt " c̲at n, x c̲at -0.12 0.15, 0.015 0.015 0.4, 90.0 0.0 0.0, iron, 0.0) ᵇᵖc̲ylinder 0 }
105 ((t c̲at (("1", -0.05) b̲olt 0) c̲at (("2", 0.0) b̲olt 0) c̲at (("3", 0.05) b̲olt 0) c̲at ᵇᵖungroup) c̲at
106 ((("arrow-3 banner", -0.26 0.26 1.35, flat) ᵇᵖg̲roup 0) c̲at (("arrow-3 pole", 0.0 0.0 0.25, 0.015 0.015 0.5, flat, iron, 0.0) ᵇᵖc̲ylinder 0)) c̲at
107 ((("arrow-3 flag", 0.13 0.0 0.4, 0.24 0.02 0.16, flat, red, 0.0) ᵇᵖb̲ox 0) c̲at ᵇᵖungroup) c̲at
108 (("arrow-3", 0.0 0.0 1.26, 10.0, 0.1) ʰa̲imKeys 0) c̲at
109 ("arrow-3 banner", "idle", "rotation", flat, 0.0 0.0 25.0, idle, sway) ʰk̲ey 0)
110}
111
112⍝━━ Cannon towers
113
114ʰc̲annon1 ← { z →
115 (((ᵇᵖp̲iece "cannon-1") c̲at (("cannon-1 base", 0.0 0.0 0.14, 0.34 0.34 0.28, flat, stone, 0.0) ᵇᵖc̲ylinder 0)) c̲at
116 ((("cannon-1 rim", 0.0 0.0 0.28, 0.32 0.03, flat, darkstone, 0.0) ᵇᵖt̲orus 0)) c̲at
117 ((("cannon-1 aim", 0.0 0.0 0.28, flat) ᵇᵖg̲roup 0) c̲at (("cannon-1 mount", 0.0 0.0 0.07, 0.22 0.22 0.14, flat, darkwood, 0.0) ᵇᵖb̲ox 0)) c̲at
118 ((("cannon-1 barrel", 0.0 -0.16 0.12, 0.07 0.07 0.34, 90.0 0.0 0.0, black, 0.0) ᵇᵖc̲ylinder 0) c̲at (("cannon-1 muzzle", 0.0 -0.33 0.12, 0.07 0.02, 90.0 0.0 0.0, black, 0.0) ᵇᵖt̲orus 0)) c̲at
119 ᵇᵖungroup c̲at ("cannon-1", 0.0 0.0 0.28, 8.0, 0.1) ʰa̲imKeys 0)
120}
121
122ʰc̲annon2 ← { z →
123 (((ᵇᵖp̲iece "cannon-2") c̲at (("cannon-2 base", 0.0 0.0 0.17, 0.4 0.4 0.34, flat, stone, 0.0) ᵇᵖc̲ylinder 0)) c̲at
124 ((("cannon-2 rim", 0.0 0.0 0.34, 0.38 0.035, flat, darkstone, 0.0) ᵇᵖt̲orus 0)) c̲at
125 ((("cannon-2 aim", 0.0 0.0 0.34, flat) ᵇᵖg̲roup 0) c̲at (("cannon-2 mount", 0.0 0.02 0.08, 0.28 0.26 0.16, flat, darkwood, 0.0) ᵇᵖb̲ox 0)) c̲at
126 ((("cannon-2 barrel", 0.0 -0.22 0.15, 0.08 0.08 0.52, 90.0 0.0 0.0, black, 0.0) ᵇᵖc̲ylinder 0)) c̲at
127 ((("cannon-2 band 1", 0.0 -0.1 0.15, 0.085 0.022, 90.0 0.0 0.0, iron, 0.0) ᵇᵖt̲orus 0) c̲at (("cannon-2 band 2", 0.0 -0.42 0.15, 0.085 0.022, 90.0 0.0 0.0, iron, 0.0) ᵇᵖt̲orus 0)) c̲at
128 ᵇᵖungroup c̲at ("cannon-2", 0.0 0.0 0.34, 8.0, 0.12) ʰa̲imKeys 0)
129}
130
131ʰc̲annon3 ← { z →
132 base ← 6 2 r̲eshape 0.0 0.0 0.4 0.0 0.4 0.1 0.33 0.16 0.31 0.36 0.0 0.36
133 t ← (((ᵇᵖp̲iece "cannon-3") c̲at (("cannon-3 base", 0.0 0.0 0.0, base, 16, flat, stone, 0.0) ᵇᵖl̲athe 0)) c̲at
134 ((("cannon-3 ring", 0.0 0.0 0.38, 0.3 0.04, flat, brass, 0.0) ᵇᵖt̲orus 0)) c̲at
135 (("cannon-3 aim", 0.0 0.0 0.4, flat) ᵇᵖg̲roup 0) c̲at (("cannon-3 dome", 0.0 0.0 0.04, 0.26 0.26 0.18, flat, darkstone, 0.0) ᵇᵖs̲phere 0))
136 b̲arrel ← { (n, x) z1 →
137 a ← (("cannon-3 barrel " c̲at n, x c̲at -0.26 0.1, 0.06 0.06 0.5, 90.0 0.0 0.0, black, 0.0) ᵇᵖc̲ylinder 0)
138 a c̲at (("cannon-3 trim " c̲at n, x c̲at -0.5 0.1, 0.065 0.02, 90.0 0.0 0.0, brass, 0.0) ᵇᵖt̲orus 0)
139 }
140 withBarrels ← t c̲at (("1", -0.1) b̲arrel 0) c̲at (("2", 0.1) b̲arrel 0) c̲at (("cannon-3 hatch", 0.0 0.05 0.2, 0.08 0.08 0.03, flat, brass, 0.0) ᵇᵖc̲ylinder 0)
141 withBarrels c̲at ᵇᵖungroup c̲at ("cannon-3", 0.0 0.0 0.4, 15.0, 0.1) ʰa̲imKeys 0
142}
143
144⍝━━ Frost towers
145
146⍝ the crystal turns once round in idle and swells in fire
147ʰc̲rystalKeys ← { (g, at, swell) z →
148 ((g, "idle", "rotation", flat, 0.0 0.0 180.0, slow, turn) ʰk̲ey 0) c̲at ((g, "fire", "scale", one, swell c̲at swell c̲at swell, fire, kick) ʰk̲ey 0)
149}
150
151ʰf̲rost1 ← { z →
152 ped ← 7 2 r̲eshape 0.0 0.0 0.3 0.0 0.3 0.08 0.17 0.14 0.13 0.38 0.2 0.44 0.0 0.44
153 (((ᵇᵖp̲iece "frost-1") c̲at (("frost-1 pedestal", 0.0 0.0 0.0, ped, 12, flat, stone, 0.0) ᵇᵖl̲athe 0)) c̲at
154 ((("frost-1 aim", 0.0 0.0 0.66, flat) ᵇᵖg̲roup 0) c̲at (("frost-1 crystal", 0.0 0.0 0.0, 0.1 0.1 0.22, flat, ice, 0.4) ᵇᵖo̲ctahedron 0)) c̲at
155 ᵇᵖungroup c̲at ("frost-1 aim", 0.0 0.0 0.66, 0.35) ʰc̲rystalKeys 0)
156}
157
158ʰf̲rost2 ← { z →
159 ped ← 7 2 r̲eshape 0.0 0.0 0.34 0.0 0.34 0.1 0.2 0.16 0.15 0.55 0.22 0.62 0.0 0.62
160 (((ᵇᵖp̲iece "frost-2") c̲at (("frost-2 pedestal", 0.0 0.0 0.0, ped, 12, flat, stone, 0.0) ᵇᵖl̲athe 0)) c̲at
161 ((("frost-2 ring", 0.0 0.0 0.72, 0.2 0.022, flat, silver, 0.0) ᵇᵖt̲orus 0)) c̲at
162 ((("frost-2 aim", 0.0 0.0 0.86, flat) ᵇᵖg̲roup 0) c̲at (("frost-2 crystal", 0.0 0.0 0.0, 0.1 0.1 0.24, flat, ice, 0.6) ᵇᵖo̲ctahedron 0)) c̲at
163 ((("frost-2 shard 1", -0.1 0.0 -0.06, 0.06 0.06 0.15, 0.0 -25.0 0.0, ice, 0.6) ᵇᵖo̲ctahedron 0) c̲at (("frost-2 shard 2", 0.1 0.0 -0.06, 0.06 0.06 0.15, 0.0 25.0 0.0, ice, 0.6) ᵇᵖo̲ctahedron 0)) c̲at
164 ((("frost-2 shard 3", 0.0 0.09 -0.08, 0.05 0.05 0.12, 25.0 0.0 0.0, ice, 0.6) ᵇᵖo̲ctahedron 0)) c̲at
165 ᵇᵖungroup c̲at ("frost-2 aim", 0.0 0.0 0.86, 0.3) ʰc̲rystalKeys 0)
166}
167
168ʰf̲rost3 ← { z →
169 ped ← 7 2 r̲eshape 0.0 0.0 0.38 0.0 0.38 0.1 0.24 0.18 0.17 0.6 0.26 0.68 0.0 0.68
170 t ← (((ᵇᵖp̲iece "frost-3") c̲at (("frost-3 pedestal", 0.0 0.0 0.0, ped, 12, flat, stone, 0.0) ᵇᵖl̲athe 0)) c̲at
171 (("frost-3 aim", 0.0 0.0 1.0, flat) ᵇᵖg̲roup 0) c̲at (("frost-3 crystal", 0.0 0.0 0.0, 0.13 0.13 0.3, flat, ice, 2.5) ᵇᵖo̲ctahedron 0) c̲at ᵇᵖungroup)
172 s̲hard ← { (n, x, y) z1 → ("frost-3 shard " c̲at n, x c̲at y c̲at 0.0, 0.04 0.04 0.09, flat, ice, 1.5) ᵇᵖo̲ctahedron 0 }
173 ((t c̲at (("frost-3 shards", 0.0 0.0 0.96, flat) ᵇᵖg̲roup 0) c̲at (("1", 0.26, 0.0) s̲hard 0) c̲at (("2", -0.26, 0.0) s̲hard 0) c̲at (("3", 0.0, 0.26) s̲hard 0) c̲at (("4", 0.0, -0.26) s̲hard 0) c̲at ᵇᵖungroup) c̲at
174 (("frost-3 aim", 0.0 0.0 1.0, 0.4) ʰc̲rystalKeys 0) c̲at
175 (("frost-3 aim", "idle", "location", 0.0 0.0 1.0, 0.0 0.0 0.05, slow, breathe) ʰk̲ey 0) c̲at
176 (("frost-3 shards", "idle", "rotation", flat, 0.0 0.0 -90.0, slow, turn) ʰk̲ey 0) c̲at
177 ("frost-3 shards", "fire", "scale", one, 0.6 0.6 0.6, fire, kick) ʰk̲ey 0)
178}
179
180⍝━━ Creeps
181
182⍝ idle breathes the body; walk bobs it; hit throws it back and squashes
183⍝ it
184ʰb̲odyKeys ← { (p, at) z →
185 b ← p c̲at " body"
186 t ← ((b, "idle", "scale", one, 0.0 0.0 0.06, slow, breathe) ʰk̲ey 0) c̲at ((b, "walk", "location", at, 0.0 0.0 0.02, walk, bob) ʰk̲ey 0)
187 t c̲at ((b, "hit", "rotation", flat, -20.0 0.0 0.0, hit, kick) ʰk̲ey 0) c̲at ((b, "hit", "scale", one, 0.08 0.08 -0.12, hit, kick) ʰk̲ey 0)
188}
189
190⍝ a foot lifted in walk when its pair is (stepa or stepb)
191ʰf̲oot ← { (name, at, ks) z → (name, "walk", "location", at, 0.0 0.0 0.05, walk, ks) ʰk̲ey 0 }
192
193ʰr̲unner ← { z →
194 v ← 8 3 r̲eshape -0.2 -0.25 0.0 0.2 -0.25 0.0 0.2 0.25 0.0 -0.2 0.25 0.0 -0.2 0.25 0.24 0.2 0.25 0.24 -0.2 -0.25 0.06 0.2 -0.25 0.06
195 f ← 6 4 r̲eshape 0 1 2 3 3 2 5 4 7 6 4 5 0 1 7 6 0 6 4 3 1 2 5 7
196 t ← (ᵇᵖp̲iece "runner") c̲at (("runner body", 0.0 0.0 0.12, flat) ᵇᵖg̲roup 0) c̲at (("runner shell", 0.0 0.0 0.0, v, f, flat, green, 0.0) ᵇᵖm̲esh 0)
197 e̲ye ← { (n, x) z1 → (("runner eye " c̲at n, x c̲at -0.16 0.12, 0.055 0.055 0.055, flat, white, 0.0) ᵇᵖs̲phere 0) c̲at (("runner pupil " c̲at n, x c̲at -0.205 0.125, 0.025 0.025 0.025, flat, black, 0.0) ᵇᵖs̲phere 0) }
198 withEyes ← t c̲at (("1", -0.09) e̲ye 0) c̲at (("2", 0.09) e̲ye 0) c̲at ᵇᵖungroup
199 l̲eg ← { (n, at) z1 → ("runner foot " c̲at n, at, 0.07 0.07 0.14, flat, darkgreen, 0.0) ᵇᵖb̲ox 0 }
200 ((withEyes c̲at (("1", -0.14 -0.16 0.07) l̲eg 0) c̲at (("2", 0.14 -0.16 0.07) l̲eg 0) c̲at (("3", -0.14 0.16 0.07) l̲eg 0) c̲at (("4", 0.14 0.16 0.07) l̲eg 0)) c̲at
201 (("runner", 0.0 0.0 0.12) ʰb̲odyKeys 0) c̲at
202 ((("runner foot 1", -0.14 -0.16 0.07, stepa) ʰf̲oot 0) c̲at (("runner foot 4", 0.14 0.16 0.07, stepa) ʰf̲oot 0)) c̲at
203 (("runner foot 2", 0.14 -0.16 0.07, stepb) ʰf̲oot 0) c̲at ("runner foot 3", -0.14 0.16 0.07, stepb) ʰf̲oot 0)
204}
205
206ʰb̲rute ← { z →
207 (((ᵇᵖp̲iece "brute") c̲at (("brute body", 0.0 0.0 0.2, flat) ᵇᵖg̲roup 0) c̲at (("brute torso", 0.0 0.02 0.18, 0.5 0.42 0.36, flat, brown, 0.0) ᵇᵖb̲ox 0)) c̲at
208 ((("brute head", 0.0 -0.26 0.22, 0.3 0.2 0.22, flat, darkbrown + 0.15, 0.0) ᵇᵖb̲ox 0)) c̲at
209 ((("brute horn 1", -0.12 -0.3 0.4, 0.05 0.0 0.2, 0.0 -25.0 0.0, bone, 0.0) ᵇᵖc̲one 0) c̲at (("brute horn 2", 0.12 -0.3 0.4, 0.05 0.0 0.2, 0.0 25.0 0.0, bone, 0.0) ᵇᵖc̲one 0)) c̲at
210 ((("brute eye 1", -0.07 -0.365 0.25, 0.03 0.03 0.03, flat, amber, 0.3) ᵇᵖs̲phere 0) c̲at (("brute eye 2", 0.07 -0.365 0.25, 0.03 0.03 0.03, flat, amber, 0.3) ᵇᵖs̲phere 0) c̲at ᵇᵖungroup) c̲at
211 ((("brute foot 1", -0.15 0.0 0.1, 0.16 0.22 0.2, flat, darkbrown, 0.0) ᵇᵖb̲ox 0) c̲at (("brute foot 2", 0.15 0.0 0.1, 0.16 0.22 0.2, flat, darkbrown, 0.0) ᵇᵖb̲ox 0)) c̲at
212 (("brute", 0.0 0.0 0.2) ʰb̲odyKeys 0) c̲at
213 (("brute body", "walk", "rotation", flat, 0.0 4.0 0.0, walk, sway) ʰk̲ey 0) c̲at
214 (("brute foot 1", -0.15 0.0 0.1, stepa) ʰf̲oot 0) c̲at ("brute foot 2", 0.15 0.0 0.1, stepb) ʰf̲oot 0)
215}
216
217ʰs̲hield ← { z →
218 dome ← 7 2 r̲eshape 0.0 0.0 0.27 0.0 0.26 0.08 0.235 0.14 0.19 0.2 0.12 0.245 0.0 0.26
219 t ← (ᵇᵖp̲iece "shield") c̲at (("shield body", 0.0 0.0 0.06, flat) ᵇᵖg̲roup 0) c̲at (("shield shell", 0.0 0.0 0.0, dome, 16, flat, steel, 0.0) ᵇᵖl̲athe 0)
220 p̲late ← { (n, at, deg) z1 → ("shield plate " c̲at n, at, 0.2 0.04 0.1, 0.0 0.0 c̲at deg, darksteel, 0.0) ᵇᵖb̲ox 0 }
221 withPlates ← ((t c̲at (("1", 0.0 -0.255 0.06, 0.0) p̲late 0) c̲at (("2", 0.0 0.255 0.06, 0.0) p̲late 0) c̲at (("3", -0.255 0.0 0.06, 90.0) p̲late 0) c̲at (("4", 0.255 0.0 0.06, 90.0) p̲late 0)) c̲at
222 (("shield eye 1", -0.06 -0.215 0.15, 0.03 0.03 0.03, flat, cyan, 0.5) ᵇᵖs̲phere 0) c̲at (("shield eye 2", 0.06 -0.215 0.15, 0.03 0.03 0.03, flat, cyan, 0.5) ᵇᵖs̲phere 0) c̲at ᵇᵖungroup)
223 f̲t ← { (n, at) z1 → ("shield foot " c̲at n, at, 0.05 0.05 0.06, flat, darksteel, 0.0) ᵇᵖc̲ylinder 0 }
224 ((withPlates c̲at (("1", -0.15 -0.15 0.03) f̲t 0) c̲at (("2", 0.15 -0.15 0.03) f̲t 0) c̲at (("3", -0.15 0.15 0.03) f̲t 0) c̲at (("4", 0.15 0.15 0.03) f̲t 0)) c̲at
225 (("shield", 0.0 0.0 0.06) ʰb̲odyKeys 0) c̲at
226 ((("shield foot 1", -0.15 -0.15 0.03, stepa) ʰf̲oot 0) c̲at (("shield foot 4", 0.15 0.15 0.03, stepa) ʰf̲oot 0)) c̲at
227 (("shield foot 2", 0.15 -0.15 0.03, stepb) ʰf̲oot 0) c̲at ("shield foot 3", -0.15 0.15 0.03, stepb) ʰf̲oot 0)
228}
229
230⍝━━ The pieces
231
232⍝│ the twelve pieces' names, as X_eTaL-games asked for them, a space
233⍝│ between: the files are NAME.glb
234ˡnames ← "arrow-1 arrow-2 arrow-3 cannon-1 cannon-2 cannon-3 frost-1 frost-2 frost-3 runner brute shield"
235
236⍝│ td:m_odel name: Python making the piece NAME (one of td:names) and
237⍝│ keying its clips; "" for another name
238ˡm̲odel ← { name →
239 name m̲atch "arrow-1" ? ʰa̲rrow1 0
240 name m̲atch "arrow-2" ? ʰa̲rrow2 0
241 name m̲atch "arrow-3" ? ʰa̲rrow3 0
242 name m̲atch "cannon-1" ? ʰc̲annon1 0
243 name m̲atch "cannon-2" ? ʰc̲annon2 0
244 name m̲atch "cannon-3" ? ʰc̲annon3 0
245 name m̲atch "frost-1" ? ʰf̲rost1 0
246 name m̲atch "frost-2" ? ʰf̲rost2 0
247 name m̲atch "frost-3" ? ʰf̲rost3 0
248 name m̲atch "runner" ? ʰr̲unner 0
249 name m̲atch "brute" ? ʰb̲rute 0
250 name m̲atch "shield" ? ʰs̲hield 0
251 ""
252}
253
254⍝│ the most triangles a piece's low-poly mesh (NAME-mesh.toml) has: the
255⍝│ ask's "a few hundred"; the cannons, over it, are decimated
256ˡmeshMost ← 500
257
258⍝│ td:e_xport name: Python making the piece NAME, writing it as
259⍝│ out/NAME.glb with its clips, reading its clips back into
260⍝│ out/NAME-clips.txt, and writing its low-poly mesh at rest as
261⍝│ out/NAME-mesh.toml (bp:m_eshToml)
262ˡe̲xport ← { name → (ˡm̲odel name) c̲at (ᵇᵖe̲xportPiece name) c̲at (ᵇᵖc̲lips name) c̲at (name, ˡmeshMost) ᵇᵖm̲eshToml 0 }
263
264⍝│ td:clips: Python joining the pieces' clip files into out/clips.txt,
265⍝│ each piece's name, then its clips
266ˡclips ← "with open(os.path.join(out, \"clips.txt\"), \"w\") as f:\n for n in \"" c̲at ˡnames c̲at "\".split():\n f.write(n + \"\\n\" + open(os.path.join(out, n + \"-clips.txt\")).read())\n"
267
268⍝│ td:all: Python making every piece and writing its .glb (td:e_xport),
269⍝│ then out/clips.txt
270ˡall ← (ˡe̲xport "arrow-1") c̲at (ˡe̲xport "arrow-2") c̲at (ˡe̲xport "arrow-3") c̲at (ˡe̲xport "cannon-1") c̲at (ˡe̲xport "cannon-2") c̲at (ˡe̲xport "cannon-3") c̲at (ˡe̲xport "frost-1") c̲at (ˡe̲xport "frost-2") c̲at (ˡe̲xport "frost-3") c̲at (ˡe̲xport "runner") c̲at (ˡe̲xport "brute") c̲at (ˡe̲xport "shield") c̲at ˡclips
271
272⍝━━ Showing them
273
274⍝│ td:show: Python helpers for showing the pieces: td_stills renders
275⍝│ each alone; td_closeups shows them one after another, close, each
276⍝│ turning once round and playing its clips, captioned; td_film lines
277⍝│ them up (towers by kind and level, the creeps in a fourth column),
278⍝│ each turning once round, playing idle, then fire or walk. A video
279⍝│ keeps each part's rest on a track under its clips (Blender's NLA puts
280⍝│ a property no playing strip keys at zero, not at its rest).
281ˡshow ← "td_names = \"" c̲at ˡnames c̲at "\".split()\ntd_creeps = [\"runner\", \"brute\", \"shield\"]\ntd_saved = {}\ntd_seconds = {\"idle\": 2.0, \"walk\": 1.0, \"fire\": 0.4, \"hit\": 0.3}\n\ndef td_parts():\n return [c for n in td_names for c in bpy.data.objects[n].children_recursive]\n\ndef td_prepare():\n if td_saved:\n return\n for p in td_parts():\n ad = p.animation_data\n clips = [(t.name, t.strips[0].action) for t in ad.nla_tracks if len(t.strips)] if ad else []\n td_saved[p.name] = (tuple(p.location), tuple(p.rotation_euler), tuple(p.scale), clips)\n\ndef td_reset():\n td_prepare()\n for o in [o for o in scene.objects if o.name.startswith(\"closeup \")]:\n bpy.data.objects.remove(o)\n for n in td_names:\n o = bpy.data.objects[n]\n o.animation_data_clear()\n o.hide_render = False\n o.location = (0.0, 0.0, 0.0)\n o.rotation_euler = (0.0, 0.0, 0.0)\n for p in td_parts():\n loc, rot, scale, clips = td_saved[p.name]\n p.hide_render = False\n if not clips:\n p.animation_data_clear()\n continue\n ad = p.animation_data\n ad.action = None\n while len(ad.nla_tracks):\n ad.nla_tracks.remove(ad.nla_tracks[0])\n p.location, p.rotation_euler, p.scale = loc, rot, scale\n rest = bpy.data.actions.new(p.name + \" rest\")\n ad.action = rest\n for path in (\"location\", \"rotation_euler\", \"scale\"):\n p.keyframe_insert(data_path=path, frame=1)\n ad.action = None\n base = ad.nla_tracks.new()\n base.name = \"rest\"\n base.strips.new(\"rest\", 1, rest).extrapolation = \"HOLD\"\n\ndef td_frames(clip):\n return int(round(td_seconds[clip] * scene.render.fps))\n\ndef td_play(n, clip, starts):\n for p in bpy.data.objects[n].children_recursive:\n for name, act in td_saved[p.name][3]:\n if name != clip:\n continue\n ad = p.animation_data\n tr = ad.nla_tracks.get(clip)\n if tr is None:\n tr = ad.nla_tracks.new()\n tr.name = clip\n for s0 in starts:\n tr.strips.new(clip + \" \" + str(s0), int(s0), act).extrapolation = \"NOTHING\"\n\ndef td_loop(clip, a, b):\n k = td_frames(clip)\n return range(a, b - k + 2, k)\n\ndef td_turn(o, a, b):\n o.rotation_euler = (0.0, 0.0, 0.0)\n o.keyframe_insert(\"rotation_euler\", index=2, frame=a)\n o.rotation_euler = (0.0, 0.0, 2 * math.pi)\n o.keyframe_insert(\"rotation_euler\", index=2, frame=b + 1)\n\ndef td_shown(x, a, b):\n if a > 1:\n x.hide_render = True\n x.keyframe_insert(\"hide_render\", frame=a - 1)\n x.hide_render = False\n x.keyframe_insert(\"hide_render\", frame=a)\n x.hide_render = True\n x.keyframe_insert(\"hide_render\", frame=b + 1)\n\ndef td_hide(o, h):\n o.hide_render = h\n for c in o.children_recursive:\n c.hide_render = h\n\ndef td_camera(at, scale, dist, up, side):\n aim = bpy.data.objects.new(\"aim\", None)\n aim.location = at\n scene.collection.objects.link(aim)\n cam = bpy.data.objects.new(\"camera\", bpy.data.cameras.new(\"camera\"))\n cam.data.type = \"ORTHO\"\n cam.data.ortho_scale = scale\n cam.data.clip_end = 1000\n a, e = math.radians(side), math.radians(up)\n cam.location = (at[0] + dist * math.sin(a) * math.cos(e), at[1] - dist * math.cos(a) * math.cos(e), at[2] + dist * math.sin(e))\n look = cam.constraints.new(\"TRACK_TO\")\n look.target = aim\n look.track_axis = \"TRACK_NEGATIVE_Z\"\n look.up_axis = \"UP_Y\"\n scene.collection.objects.link(cam)\n scene.camera = cam\n return cam\n\ndef td_text(name, body, size, rgb):\n c = bpy.data.curves.new(name, type=\"FONT\")\n c.body = body\n c.size = size\n t = bpy.data.objects.new(name, c)\n scene.collection.objects.link(t)\n t.data.materials.append(material(name, rgb, 0.6))\n return t\n\ndef td_height(o):\n import mathutils\n bpy.context.view_layer.update()\n return max((c.matrix_world @ mathutils.Vector(k)).z for c in o.children_recursive if c.type == \"MESH\" for k in c.bound_box)\n\ndef td_render_settings(w, h):\n scene.render.engine = \"BLENDER_EEVEE\"\n scene.view_settings.view_transform = \"Standard\"\n scene.render.use_freestyle = False\n scene.render.resolution_x = w\n scene.render.resolution_y = h\n scene.render.resolution_percentage = 100\n\ndef td_stills(size):\n td_prepare()\n td_render_settings(size, size)\n scene.render.film_transparent = True\n td_camera((0.0, 0.0, 0.85), 2.3, 8.0, 25, 25)\n scene.render.image_settings.media_type = \"IMAGE\"\n scene.render.image_settings.file_format = \"PNG\"\n scene.render.image_settings.color_mode = \"RGBA\"\n scene.frame_set(0)\n for n in td_names:\n for m in td_names:\n td_hide(bpy.data.objects[m], m != n)\n scene.render.filepath = os.path.join(out, n + \".png\")\n bpy.ops.render.render(write_still=True)\n for m in td_names:\n td_hide(bpy.data.objects[m], False)\n scene.render.film_transparent = False\n\ndef td_radius(o):\n import mathutils\n bpy.context.view_layer.update()\n return max(math.hypot(*(c.matrix_world @ mathutils.Vector(k)).xy) for c in o.children_recursive if c.type == \"MESH\" for k in c.bound_box)\n\ndef td_join(frames, cols, size, path):\n import numpy as np\n rows = (len(frames) + cols - 1) // cols\n sheet = np.zeros((rows * size, cols * size, 4), dtype=np.float32)\n for i, f in enumerate(frames):\n img = bpy.data.images.load(f)\n a = np.array(img.pixels[:], dtype=np.float32).reshape(size, size, 4)\n r, c = divmod(i, cols)\n y = (rows - 1 - r) * size\n sheet[y:y + size, c * size:(c + 1) * size] = a\n bpy.data.images.remove(img)\n out = bpy.data.images.new(os.path.basename(path), cols * size, rows * size, alpha=True)\n out.pixels = sheet.ravel()\n out.filepath_raw = path\n out.file_format = \"PNG\"\n out.save()\n bpy.data.images.remove(out)\n\ntd_map_px = 32.0 * math.sqrt(2.0)\ntd_map_up = 30\ntd_map_anchor = 82 / 96\n\ndef td_spin(o, size, angles, prefix):\n o.animation_data_clear()\n for k, a in enumerate(angles):\n o.rotation_euler = (0.0, 0.0, math.radians(a))\n o.keyframe_insert(\"rotation_euler\", index=2, frame=k + 1)\n scene.frame_start = 1\n scene.frame_end = len(angles)\n td_render_settings(size, size)\n scene.render.filepath = prefix\n bpy.ops.render.render(animation=True)\n o.animation_data_clear()\n o.rotation_euler = (0.0, 0.0, 0.0)\n return [prefix + \"%04d.png\" % (k + 1) for k in range(len(angles))]\n\ndef td_sheets(turn, mapsize):\n import tempfile\n td_prepare()\n scene.frame_set(0)\n muted = []\n for p in td_parts():\n if p.animation_data:\n for t in p.animation_data.nla_tracks:\n if not t.mute:\n t.mute = True\n muted.append(t)\n scene.render.film_transparent = True\n scene.render.image_settings.media_type = \"IMAGE\"\n scene.render.image_settings.file_format = \"PNG\"\n scene.render.image_settings.color_mode = \"RGBA\"\n tmp = tempfile.mkdtemp()\n for n in td_names:\n o = bpy.data.objects[n]\n for m in td_names:\n td_hide(bpy.data.objects[m], m != n)\n top, r = td_height(o), td_radius(o)\n td_camera((0.0, 0.0, top * 0.5), 1.12 * max(2 * r, top * 0.95 + 2 * r * math.sin(math.radians(20))), 10.0, 20, 0)\n frames = td_spin(o, turn, [22.5 * k for k in range(16)], os.path.join(tmp, n + \"-turn-\"))\n td_join(frames, 4, turn, os.path.join(out, n + \"-turn.png\"))\n cam = td_camera((0.0, 0.0, 0.0), 96 / td_map_px, 10.0, td_map_up, 0)\n cam.data.shift_y = td_map_anchor - 0.5\n frames = td_spin(o, mapsize, [90 - 45 * k for k in range(8)], os.path.join(tmp, n + \"-map-\"))\n td_join(frames, 8, mapsize, os.path.join(out, n + \"-map.png\"))\n for m in td_names:\n td_hide(bpy.data.objects[m], False)\n for t in muted:\n t.mute = False\n scene.render.film_transparent = False\n\ndef td_closeups(w, h, seg):\n td_reset()\n td_render_settings(w, h)\n scene.frame_start = 1\n scene.frame_end = seg * len(td_names)\n cam = td_camera((0.0, 0.0, 0.75), 3.4, 8.0, 22, 25)\n aim = cam.constraints[0].target\n for i, n in enumerate(td_names):\n a = i * seg + 1\n b = a + seg - 1\n o = bpy.data.objects[n]\n top = td_height(o)\n s = max(1.4, top * 1.25 + 0.3) * 16 / 9\n for f in (a, b):\n aim.location = (0.0, 0.0, top * 0.45)\n aim.keyframe_insert(\"location\", frame=f)\n cam.data.ortho_scale = s\n cam.data.keyframe_insert(\"ortho_scale\", frame=f)\n for x in [o] + list(o.children_recursive):\n td_shown(x, a, b)\n td_turn(o, a, b)\n half = a + seg // 2 - 1\n td_play(n, \"idle\", td_loop(\"idle\", a, half))\n if n in td_creeps:\n third = (b - half) // 2\n phases = [(\"idle\", a, half), (\"walk\", half + 1, half + third), (\"hit\", half + third + 1, b)]\n td_play(n, \"walk\", td_loop(\"walk\", half + 1, half + third))\n td_play(n, \"hit\", range(half + third + 3, b - td_frames(\"hit\") + 1, td_frames(\"hit\") + 10))\n else:\n phases = [(\"idle\", a, half), (\"fire\", half + 1, b)]\n td_play(n, \"fire\", range(half + 3, b - td_frames(\"fire\") + 1, td_frames(\"fire\") + 10))\n for clip, pa, pb in phases:\n t = td_text(\"closeup \" + n + \" \" + clip, n + \" \" + clip, 0.05 * s, (1.0, 1.0, 1.0))\n t.parent = cam\n t.location = (-0.46 * s, 0.22 * s, -2.0)\n td_shown(t, pa, pb)\n\ndef td_place(n):\n if n in td_creeps:\n return 3, td_creeps.index(n)\n return [\"arrow\", \"cannon\", \"frost\"].index(n.split(\"-\")[0]), int(n[-1]) - 1\n\ndef td_film(w, h, frames):\n td_reset()\n td_render_settings(w, h)\n scene.frame_start = 1\n scene.frame_end = frames\n half = frames // 2\n for n in td_names:\n o = bpy.data.objects[n]\n col, row = td_place(n)\n o.location = ((col - 1.5) * 1.9, (row - 1) * 2.5, 0.0)\n td_turn(o, 1, frames)\n t = td_text(\"label \" + n, n, 0.22, (0.9, 0.9, 0.85))\n t.data.align_x = \"CENTER\"\n t.location = (o.location[0], o.location[1] - 0.72, 0.01)\n td_play(n, \"idle\", td_loop(\"idle\", 1, half))\n if n in td_creeps:\n td_play(n, \"walk\", td_loop(\"walk\", half + 1, frames))\n else:\n td_play(n, \"fire\", range(half + 1, frames - td_frames(\"fire\") + 1, scene.render.fps))\n td_camera((0.0, 0.3, 0.5), 10.0, 20.0, 40, 0)\n\n"
282
283⍝│ td:s_tills size: Python rendering each piece alone as out/NAME.png,
284⍝│ size pixels square on a transparent ground, from the front a little
285⍝│ to the right and above (all at one scale, so their sizes compare)
286ˡs̲tills ← { size → "td_stills(" c̲at (f̲ormat size) c̲at ")\n" }
287
288⍝│ (turn, map) td:s_heets 0: Python rendering each piece's fallback
289⍝│ sheets for a game without 3D, joined in Blender (transparent PNGs):
290⍝│ out/NAME-turn.png, 16 frames turn pixels square in a 4 by 4 sheet
291⍝│ (row by row), the piece turned 22.5 degrees counterclockwise (seen
292⍝│ from above) each frame from its front, the camera 20 degrees up,
293⍝│ each piece framed to its size; out/NAME-map.png, 8 frames map pixels
294⍝│ square in a row, the piece facing east, then each 45 degrees turned
295⍝│ clockwise on screen (east, southeast, south, ... northeast), an
296⍝│ orthographic camera 30 degrees up -- the game's board: tiles 64
297⍝│ pixels wide and 32 high in a 96-pixel frame -- the tile's middle at
298⍝│ (48, 82) of the frame
299ˡs̲heets ← { (turn, map) z → "td_sheets(" c̲at (f̲ormat turn) c̲at ", " c̲at (f̲ormat map) c̲at ")\n" }
300
301⍝│ (width, height, frames) td:c_loseups 0: Python showing the pieces
302⍝│ one after another for a video of that size, frames for each (at 30
303⍝│ a second): each alone and close, turning once round, idle for the
304⍝│ first half, then fire (towers) or walk and hit (creeps), a caption
305⍝│ naming the piece and the clip. bp:v_ideo renders it.
306ˡc̲loseups ← { (w, h, seg) z → "td_closeups(" c̲at (f̲ormat w) c̲at ", " c̲at (f̲ormat h) c̲at ", " c̲at (f̲ormat seg) c̲at ")\n" }
307
308⍝│ (width, height, frames) td:f_ilm 0: Python lining the pieces up on
309⍝│ the ground for a video of that size and length (at 30 frames a
310⍝│ second, the clips' rate): each turns once round, idle in the first
311⍝│ half, then the towers fire each second and the creeps walk; a label
312⍝│ in front of each. bp:v_ideo renders it.
313ˡf̲ilm ← { (w, h, frames) z → "td_film(" c̲at (f̲ormat w) c̲at ", " c̲at (f̲ormat h) c̲at ", " c̲at (f̲ormat frames) c̲at ")\n" }
314
315⍝━━ Publishing them
316
317⍝ 1 for a creep, 0 for a tower
318ʰc̲reep ← { name → (name m̲atch "runner") + (name m̲atch "brute") + (name m̲atch "shield") × 1 }
319
320⍝ what kind a piece is, and its clips as TOML
321ʰk̲ind ← { c → c ? "creep"
322 "tower"
323}
324ʰc̲lipsOf ← { c → c ? "{ idle = 2.0, walk = 1.0, hit = 0.3 }"
325 "{ idle = 2.0, fire = 0.4 }"
326}
327
328⍝ a piece's table in the manifest: its kind, files and their SHA-256s,
329⍝ its clips
330ʰe̲ntry ← { (dir, name) z →
331 c ← ʰc̲reep name
332 (("\n[pieces." c̲at name c̲at "]\nkind = \"" c̲at (ʰk̲ind c) c̲at "\"\nglb = \"" c̲at name c̲at ".glb\"\nglb-sha256 = \"" c̲at (ᵈᵍs̲ha256File dir c̲at "/" c̲at name c̲at ".glb") c̲at "\"\n") c̲at
333 ("preview = \"" c̲at name c̲at ".png\"\npreview-sha256 = \"" c̲at (ᵈᵍs̲ha256File dir c̲at "/" c̲at name c̲at ".png") c̲at "\"\n") c̲at
334 ("turn = \"" c̲at name c̲at "-turn.png\"\nturn-sha256 = \"" c̲at (ᵈᵍs̲ha256File dir c̲at "/" c̲at name c̲at "-turn.png") c̲at "\"\n") c̲at
335 ("map = \"" c̲at name c̲at "-map.png\"\nmap-sha256 = \"" c̲at (ᵈᵍs̲ha256File dir c̲at "/" c̲at name c̲at "-map.png") c̲at "\"\n") c̲at
336 ("mesh = \"" c̲at name c̲at "-mesh.toml\"\nmesh-sha256 = \"" c̲at (ᵈᵍs̲ha256File dir c̲at "/" c̲at name c̲at "-mesh.toml") c̲at "\"\n") c̲at
337 "clips = " c̲at (ʰc̲lipsOf c) c̲at "\n")
338}
339
340⍝│ (dir, blender) td:m_anifest 0: manifest.toml for the pieces in dir
341⍝│ (their .glb and .png files, hashed by the digest extension): what
342⍝│ made them (the program, the commit -- "unpublished" until the files
343⍝│ are published -- and Blender, its version line), the license, the
344⍝│ conventions (units, up, front, the clips' rate, the sheets, the
345⍝│ low-poly mesh's format), then each piece: its kind, files (.glb,
346⍝│ preview, sheets, mesh), SHA-256s and clips with their lengths in
347⍝│ seconds
348ˡm̲anifest ← { (dir, blender) z →
349 t ← ("# Tower defense pieces for X_eTaL-games, made by X_eTaL driving Blender.\ntitle = \"Tower defense pieces\"\nprogram = \"extensions/blender/demos/game-assets.xtl\"\npieces-library = \"extensions/blender/demos/Td.xtl\"\n" c̲at
350 ("repository = \"https://github.com/softwarewrighter/X_eTaL-extensions\"\ncommit = \"unpublished\"\nlicense = \"MIT\"\nblender = \"" c̲at blender c̲at "\"\n") c̲at
351 "format = \"glTF 2.0, binary (.glb)\"\nunits = \"meters: one tile is 1 by 1; the origin at the middle of the base, on the ground\"\nup = \"+Y in glTF (+Z in Blender)\"\nfront = \"+Z in glTF, glTF's own front (-Y in Blender)\"\nclip-rate = 30\n" c̲at
352 "preview = \"PIECE.png: 320 by 320, RGBA, transparent, the piece at rest from the front a little right and above, every preview at one scale\"\n" c̲at
353 "turn-sheet = { file = \"PIECE-turn.png\", frame = 256, frames = 16, columns = 4, order = \"row by row\", turn = \"22.5 degrees counterclockwise seen from above each frame, frame 0 the front\", camera = \"20 degrees above the horizon\", scale = \"each piece framed to its size\" }\n" c̲at
354 "map-sheet = { file = \"PIECE-map.png\", frame = 96, frames = 8, columns = 8, facing = [\"east\", \"southeast\", \"south\", \"southwest\", \"west\", \"northwest\", \"north\", \"northeast\"], camera = \"orthographic, 30 degrees above the horizon (the board's 2:1 tiles; the ask said 35)\", tile = \"64 by 32 pixels\", pixels-per-meter = 45.25, anchor = [48, 82] }\n" c̲at
355 "mesh-format = { file = \"PIECE-mesh.toml\", pose = \"at rest\", vertices = \"x y z per string, meters, Z up, front -Y, the origin at the middle of the base\", faces = \"three vertex numbers per string, from 1\", colors = \"#rrggbb per face, sRGB\", most-triangles = " c̲at (f̲ormat ˡmeshMost) c̲at " }\n")
356 e̲nt ← { name → (dir, name) ʰe̲ntry 0 }
357 t c̲at (e̲nt "arrow-1") c̲at (e̲nt "arrow-2") c̲at (e̲nt "arrow-3") c̲at (e̲nt "cannon-1") c̲at (e̲nt "cannon-2") c̲at (e̲nt "cannon-3") c̲at (e̲nt "frost-1") c̲at (e̲nt "frost-2") c̲at (e̲nt "frost-3") c̲at (e̲nt "runner") c̲at (e̲nt "brute") c̲at e̲nt "shield"
358}
359
360⍝ a piece's card on the page: the model turning in a viewer (its
361⍝ preview until it loads), its name, a button for each clip, its file
362ʰc̲ard ← { name →
363 c ← ʰc̲reep name
364 t ← "<div class='card'><model-viewer src='" c̲at name c̲at ".glb' poster='" c̲at name c̲at ".png' alt='the " c̲at name c̲at " piece' camera-controls autoplay animation-name='idle' camera-orbit='25deg 70deg auto' shadow-intensity='1' interaction-prompt='none'></model-viewer>"
365 t c̲at "<h2>" c̲at name c̲at "</h2><p>" c̲at (ʰb̲uttons c) c̲at " <a href='" c̲at name c̲at ".glb'>.glb</a> <a href='" c̲at name c̲at ".png'>.png</a> <a href='" c̲at name c̲at "-turn.png'>turn</a> <a href='" c̲at name c̲at "-map.png'>map</a> <a href='" c̲at name c̲at "-mesh.toml'>mesh</a></p></div>\n"
366}
367ʰb̲uttons ← { c → c ? "<button data-clip='idle'>idle</button><button data-clip='walk'>walk</button><button data-clip='hit'>hit</button>"
368 "<button data-clip='idle'>idle</button><button data-clip='fire'>fire</button>"
369}
370
371ʰp̲ageHead ← { z →
372 ("<!doctype html>\n<html lang='en'>\n<head>\n<meta charset='utf-8'>\n<meta name='viewport' content='width=device-width, initial-scale=1'>\n<title>Tower defense pieces -- X_eTaL Extensions</title>\n<link rel='icon' href='../../favicon.ico'>\n" c̲at
373 "<script type='module' src='https://cdn.jsdelivr.net/npm/@google/model-viewer@4/dist/model-viewer.min.js'></script>\n" c̲at
374 "<style>\nbody { margin: 0 auto; max-width: 1100px; padding: 16px; background: #14161a; color: #e4e4e4; font: 16px/1.5 system-ui, sans-serif; }\na { color: #8cc8ff; }\nheader a { display: flex; align-items: center; gap: 12px; text-decoration: none; }\nheader span { color: #ff3b30; font-size: 28px; font-weight: 700; }\n" c̲at
375 ".grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }\n.card { background: #1d2026; border-radius: 8px; padding: 8px; }\nmodel-viewer { width: 100%; height: 240px; background: #3a7d44; border-radius: 6px; }\n" c̲at
376 "h2 { margin: 6px 0 0; font-size: 18px; }\n.card p { margin: 4px 0; }\nbutton { margin: 0 4px 4px 0; background: #2b3038; color: #e4e4e4; border: 1px solid #444b55; border-radius: 4px; padding: 2px 10px; cursor: pointer; }\n</style>\n</head>\n<body>\n" c̲at
377 "<header><a href='../../'><img src='../../xetal-logo-red.png' alt='X_eTaL' height='48'><span>X_eTaL Extensions</span></a></header>\n<h1>Tower defense pieces</h1>\n" c̲at
378 "<p>The twelve pieces <a href='https://softwarewrighter.github.io/X_eTaL-games/tower-defense/'>X_eTaL-games' tower defense</a> asked for, each made by an X_eTaL program driving Blender (<a href='https://github.com/softwarewrighter/X_eTaL-extensions/blob/main/extensions/blender/demos/game-assets.xtl'>game-assets.xtl</a>, the pieces in <a href='https://github.com/softwarewrighter/X_eTaL-extensions/blob/main/extensions/blender/demos/Td.xtl'>Td.xtl</a>). " c̲at
379 "Drag a piece to turn it; the buttons play its clips. Each is a .glb (glTF 2.0) with its clips, a preview .png and two sheets for a game without 3D (turn: 16 views; map: 8 facings on the isometric board) and a low-poly mesh in TOML for a renderer written in X_eTaL; <a href='manifest.toml'>manifest.toml</a> lists them with their SHA-256s, the license (MIT) and the commit that made them.</p>\n<main class='grid'>\n")
380}
381
382ʰp̲ageEnd ← { z → "</main>\n<script>\ndocument.querySelectorAll('button[data-clip]').forEach(function (b) {\n b.onclick = function () {\n var mv = b.closest('.card').querySelector('model-viewer');\n var loop = b.dataset.clip === 'idle' || b.dataset.clip === 'walk';\n mv.animationName = b.dataset.clip;\n mv.currentTime = 0;\n mv.play({repetitions: loop ? Infinity : 1});\n };\n});\ndocument.querySelectorAll('model-viewer').forEach(function (mv) {\n mv.addEventListener('finished', function () { mv.animationName = 'idle'; mv.play(); });\n});\n</script>\n</body>\n</html>\n" }
383
384⍝│ td:page: the pieces' page (index.html beside the files): each piece
385⍝│ in a 3D viewer (model-viewer, from a CDN) to turn with the mouse,
386⍝│ its clips on buttons, its files; links to the manifest, the program
387⍝│ and the game
388ˡpage ← (ʰp̲ageHead 0) c̲at (ʰc̲ard "arrow-1") c̲at (ʰc̲ard "arrow-2") c̲at (ʰc̲ard "arrow-3") c̲at (ʰc̲ard "cannon-1") c̲at (ʰc̲ard "cannon-2") c̲at (ʰc̲ard "cannon-3") c̲at (ʰc̲ard "frost-1") c̲at (ʰc̲ard "frost-2") c̲at (ʰc̲ard "frost-3") c̲at (ʰc̲ard "runner") c̲at (ʰc̲ard "brute") c̲at (ʰc̲ard "shield") c̲at ʰp̲ageEnd 0