castle-web-cli 0.4.229 → 0.4.230

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.
Files changed (232) hide show
  1. package/dist/agent-prompts.d.ts +2 -0
  2. package/dist/agent-prompts.js +16 -8
  3. package/dist/agent.d.ts +2 -0
  4. package/dist/agent.js +21 -21
  5. package/dist/api.d.ts +28 -2
  6. package/dist/api.js +74 -16
  7. package/dist/castle-host/host.d.ts +91 -0
  8. package/dist/castle-host/host.js +779 -3
  9. package/dist/castleJson.d.ts +44 -0
  10. package/dist/castleJson.js +131 -0
  11. package/dist/check.js +27 -1
  12. package/dist/contentPack.d.ts +49 -0
  13. package/dist/contentPack.js +273 -0
  14. package/dist/devExperiments.d.ts +21 -0
  15. package/dist/devExperiments.js +139 -0
  16. package/dist/devHub.d.ts +55 -0
  17. package/dist/devHub.js +187 -0
  18. package/dist/devSessionChild.js +3 -1
  19. package/dist/devSessionServer.d.ts +14 -1
  20. package/dist/devSessionServer.js +229 -44
  21. package/dist/experimentAssignment.d.ts +15 -0
  22. package/dist/experimentAssignment.js +41 -0
  23. package/dist/importCheckHook.d.ts +40 -0
  24. package/dist/importCheckHook.js +171 -0
  25. package/dist/importRegression.d.ts +15 -0
  26. package/dist/importRegression.js +100 -0
  27. package/dist/importTrust.d.ts +2 -0
  28. package/dist/importTrust.js +27 -0
  29. package/dist/importUpdateHook.d.ts +18 -0
  30. package/dist/importUpdateHook.js +31 -8
  31. package/dist/importUpdateHookRunner.js +19 -7
  32. package/dist/imports.d.ts +16 -0
  33. package/dist/imports.js +141 -31
  34. package/dist/index.js +3 -1
  35. package/dist/init.d.ts +3 -0
  36. package/dist/init.js +125 -8
  37. package/dist/install.js +4 -1
  38. package/dist/localPaths.js +4 -0
  39. package/dist/login.js +2 -2
  40. package/dist/platformDoc.js +3 -8
  41. package/dist/playPagePolicy.js +3 -1
  42. package/dist/remix.js +5 -0
  43. package/dist/routerTaskReport.d.ts +28 -0
  44. package/dist/routerTaskReport.js +56 -0
  45. package/dist/save-deck.d.ts +18 -0
  46. package/dist/save-deck.js +142 -6
  47. package/dist/serve.d.ts +8 -0
  48. package/dist/serve.js +94 -13
  49. package/dist/serverBundle.d.ts +1 -1
  50. package/dist/serverBundle.js +5 -1
  51. package/dist/webSourceSync.d.ts +2 -0
  52. package/dist/webSourceSync.js +2 -0
  53. package/kits/base/CLAUDE.md +2 -3
  54. package/kits/base/castle.json +1 -1
  55. package/kits/base/sdk/README.md +258 -52
  56. package/kits/base/sdk/agent.js +4 -4
  57. package/kits/base/sdk/avatar.d.ts +12 -0
  58. package/kits/base/sdk/avatar.js +23 -0
  59. package/kits/base/sdk/castle.d.ts +5 -0
  60. package/kits/base/sdk/castle.js +3 -0
  61. package/kits/base/sdk/commands.d.ts +208 -0
  62. package/kits/base/sdk/commands.js +16 -0
  63. package/kits/base/sdk/context.d.ts +6 -0
  64. package/kits/base/sdk/experiments.d.ts +15 -0
  65. package/kits/base/sdk/experiments.js +83 -0
  66. package/kits/base/sdk/hub.d.ts +85 -0
  67. package/kits/base/sdk/hub.js +107 -0
  68. package/kits/base/sdk/multiplayer.d.ts +45 -1
  69. package/kits/base/sdk/multiplayer.js +106 -4
  70. package/kits/base/sdk/server/hub.d.ts +169 -0
  71. package/kits/base/sdk/server/hub.js +125 -0
  72. package/kits/base/sdk/server/platformHandle.d.ts +42 -1
  73. package/kits/base/sdk/server/storage.d.ts +55 -2
  74. package/kits/base/sdk/server/wrapper.d.ts +32 -2
  75. package/kits/base/sdk/server/wrapper.js +90 -11
  76. package/kits/base/sdk/transport.d.ts +2 -1
  77. package/kits/base/sdk/transport.js +13 -1
  78. package/kits/hub-game/.prettierrc +5 -0
  79. package/kits/hub-game/CLAUDE.md +146 -0
  80. package/kits/hub-game/blueprints/avatar-0.scene +28 -0
  81. package/kits/hub-game/blueprints/avatar-1.scene +28 -0
  82. package/kits/hub-game/blueprints/avatar-2.scene +28 -0
  83. package/kits/hub-game/blueprints/avatar-3.scene +28 -0
  84. package/kits/hub-game/blueprints/bean/avatar-0.scene +28 -0
  85. package/kits/hub-game/blueprints/bean/avatar-1.scene +28 -0
  86. package/kits/hub-game/blueprints/bean/avatar-2.scene +28 -0
  87. package/kits/hub-game/blueprints/bean/avatar-3.scene +28 -0
  88. package/kits/hub-game/blueprints/blocky/avatar-0.scene +28 -0
  89. package/kits/hub-game/blueprints/blocky/avatar-1.scene +28 -0
  90. package/kits/hub-game/blueprints/blocky/avatar-2.scene +28 -0
  91. package/kits/hub-game/blueprints/blocky/avatar-3.scene +28 -0
  92. package/kits/hub-game/blueprints/pixel/avatar-0.scene +28 -0
  93. package/kits/hub-game/blueprints/pixel/avatar-1.scene +28 -0
  94. package/kits/hub-game/blueprints/pixel/avatar-2.scene +28 -0
  95. package/kits/hub-game/blueprints/pixel/avatar-3.scene +28 -0
  96. package/kits/hub-game/castle.json +96 -0
  97. package/kits/hub-game/code/client/attention.js +133 -0
  98. package/kits/hub-game/code/client/avatar.js +288 -0
  99. package/kits/hub-game/code/client/cabinets.js +90 -0
  100. package/kits/hub-game/code/client/chat.js +135 -0
  101. package/kits/hub-game/code/client/chrome.js +1001 -0
  102. package/kits/hub-game/code/client/doorFrame.js +15 -0
  103. package/kits/hub-game/code/client/firstJoin.js +14 -0
  104. package/kits/hub-game/code/client/grab.js +241 -0
  105. package/kits/hub-game/code/client/hookLayer.js +230 -0
  106. package/kits/hub-game/code/client/idle.js +326 -0
  107. package/kits/hub-game/code/client/keys.js +48 -0
  108. package/kits/hub-game/code/client/pack.js +232 -0
  109. package/kits/hub-game/code/client/packFormat.js +397 -0
  110. package/kits/hub-game/code/client/say.js +127 -0
  111. package/kits/hub-game/code/client/sha256.js +80 -0
  112. package/kits/hub-game/code/client/sound.js +147 -0
  113. package/kits/hub-game/code/client/state.js +131 -0
  114. package/kits/hub-game/code/client/talk.js +259 -0
  115. package/kits/hub-game/code/client/together.js +365 -0
  116. package/kits/hub-game/code/client/wear.js +149 -0
  117. package/kits/hub-game/code/server/actors.js +627 -0
  118. package/kits/hub-game/code/server/blocks.js +103 -0
  119. package/kits/hub-game/code/server/cabinets.js +309 -0
  120. package/kits/hub-game/code/server/game.js +137 -0
  121. package/kits/hub-game/code/server/grab.js +247 -0
  122. package/kits/hub-game/code/server/history.js +96 -0
  123. package/kits/hub-game/code/server/hub.js +1904 -0
  124. package/kits/hub-game/code/server/idle.js +412 -0
  125. package/kits/hub-game/code/server/index.js +64 -0
  126. package/kits/hub-game/code/server/labels.js +59 -0
  127. package/kits/hub-game/code/server/manifest.js +527 -0
  128. package/kits/hub-game/code/server/npcs.js +745 -0
  129. package/kits/hub-game/code/server/party.js +381 -0
  130. package/kits/hub-game/code/server/place.js +43 -0
  131. package/kits/hub-game/code/server/say.js +83 -0
  132. package/kits/hub-game/code/server/wear.js +142 -0
  133. package/kits/hub-game/code/systems/hub.js +2230 -0
  134. package/kits/hub-game/docs/content-pack.md +151 -0
  135. package/kits/hub-game/docs/contract.md +1139 -0
  136. package/kits/hub-game/docs/style.md +137 -0
  137. package/kits/hub-game/drawings/blocky/castle-eye.sprite +58 -0
  138. package/kits/hub-game/drawings/blocky/dash.sprite +59 -0
  139. package/kits/hub-game/drawings/blocky/pom.sprite +59 -0
  140. package/kits/hub-game/drawings/blocky/tabby.sprite +59 -0
  141. package/kits/hub-game/drawings/pixel/castle-arm.sprite +13 -0
  142. package/kits/hub-game/drawings/pixel/castle-body.sprite +23 -0
  143. package/kits/hub-game/drawings/pixel/castle-leg.sprite +12 -0
  144. package/kits/hub-game/drawings/pixel/kai-arm.sprite +14 -0
  145. package/kits/hub-game/drawings/pixel/kai-head.sprite +24 -0
  146. package/kits/hub-game/drawings/pixel/kai-leg.sprite +15 -0
  147. package/kits/hub-game/drawings/pixel/kai-torso.sprite +18 -0
  148. package/kits/hub-game/drawings/pixel/mimi-arm.sprite +13 -0
  149. package/kits/hub-game/drawings/pixel/mimi-head.sprite +23 -0
  150. package/kits/hub-game/drawings/pixel/mimi-leg.sprite +15 -0
  151. package/kits/hub-game/drawings/pixel/mimi-torso.sprite +18 -0
  152. package/kits/hub-game/drawings/pixel/nox-arm.sprite +13 -0
  153. package/kits/hub-game/drawings/pixel/nox-head.sprite +21 -0
  154. package/kits/hub-game/drawings/pixel/nox-leg.sprite +14 -0
  155. package/kits/hub-game/drawings/pixel/nox-torso.sprite +18 -0
  156. package/kits/hub-game/eslint.config.js +20 -0
  157. package/kits/hub-game/fonts.generated.js +9 -0
  158. package/kits/hub-game/index.html +22 -0
  159. package/kits/hub-game/main.jsx +6 -0
  160. package/kits/hub-game/models/avatar-0.pxmodel +21 -0
  161. package/kits/hub-game/models/avatar-1.pxmodel +24 -0
  162. package/kits/hub-game/models/avatar-2.pxmodel +27 -0
  163. package/kits/hub-game/models/avatar-3.pxmodel +22 -0
  164. package/kits/hub-game/models/bean/avatar-0.pxmodel +19 -0
  165. package/kits/hub-game/models/bean/avatar-1.pxmodel +24 -0
  166. package/kits/hub-game/models/bean/avatar-2.pxmodel +22 -0
  167. package/kits/hub-game/models/bean/avatar-3.pxmodel +24 -0
  168. package/kits/hub-game/models/blocky/avatar-0.pxmodel +21 -0
  169. package/kits/hub-game/models/blocky/avatar-1.pxmodel +30 -0
  170. package/kits/hub-game/models/blocky/avatar-2.pxmodel +28 -0
  171. package/kits/hub-game/models/blocky/avatar-3.pxmodel +27 -0
  172. package/kits/hub-game/models/pixel/avatar-0.pxmodel +24 -0
  173. package/kits/hub-game/models/pixel/avatar-1.pxmodel +16 -0
  174. package/kits/hub-game/models/pixel/avatar-2.pxmodel +19 -0
  175. package/kits/hub-game/models/pixel/avatar-3.pxmodel +23 -0
  176. package/kits/hub-game/package-lock.json +365 -0
  177. package/kits/hub-game/package.json +32 -0
  178. package/kits/hub-game/scenes/main.scene +318 -0
  179. package/kits/hub-game/scripts/check.mjs +339 -0
  180. package/kits/hub-game/scripts/fixtures/sdk-stub.mjs +3 -0
  181. package/kits/hub-game/scripts/gen-avatars-bean.mjs +748 -0
  182. package/kits/hub-game/scripts/gen-avatars-blocky.mjs +607 -0
  183. package/kits/hub-game/scripts/gen-avatars-pixel.mjs +771 -0
  184. package/kits/hub-game/scripts/gen-avatars.mjs +621 -0
  185. package/kits/hub-game/scripts/pack.mjs +192 -0
  186. package/kits/hub-game/scripts/test-actors.mjs +666 -0
  187. package/kits/hub-game/scripts/test-attention.mjs +103 -0
  188. package/kits/hub-game/scripts/test-avatar.mjs +472 -0
  189. package/kits/hub-game/scripts/test-ban-join.mjs +194 -0
  190. package/kits/hub-game/scripts/test-blocks.mjs +351 -0
  191. package/kits/hub-game/scripts/test-chat.mjs +98 -0
  192. package/kits/hub-game/scripts/test-classic.mjs +590 -0
  193. package/kits/hub-game/scripts/test-door-jump.mjs +131 -0
  194. package/kits/hub-game/scripts/test-door.mjs +56 -0
  195. package/kits/hub-game/scripts/test-grab.mjs +331 -0
  196. package/kits/hub-game/scripts/test-hub-ops.mjs +835 -0
  197. package/kits/hub-game/scripts/test-hub-trip.mjs +1310 -0
  198. package/kits/hub-game/scripts/test-idle.mjs +518 -0
  199. package/kits/hub-game/scripts/test-interest.mjs +413 -0
  200. package/kits/hub-game/scripts/test-keys.mjs +50 -0
  201. package/kits/hub-game/scripts/test-manifest.mjs +224 -0
  202. package/kits/hub-game/scripts/test-no-forms.mjs +16 -0
  203. package/kits/hub-game/scripts/test-npcs.mjs +714 -0
  204. package/kits/hub-game/scripts/test-pack.mjs +424 -0
  205. package/kits/hub-game/scripts/test-party.mjs +286 -0
  206. package/kits/hub-game/scripts/test-say.mjs +149 -0
  207. package/kits/hub-game/scripts/test-together.mjs +183 -0
  208. package/kits/hub-game/theme.style +3 -0
  209. package/kits/multiplayer-3d/castle.json +5 -5
  210. package/kits/multiplayer-3d/code/client/avatars.js +101 -1
  211. package/kits/multiplayer-3d/code/server/players.js +4 -1
  212. package/kits/multiplayer-3d/code/server/sceneBodies.js +27 -6
  213. package/kits/multiplayer-3d/code/server/world.js +20 -7
  214. package/kits/multiplayer-3d/code/systems/multiplayer.js +222 -11
  215. package/kits/physics-2d/castle.json +2 -2
  216. package/kits/physics-2d/engine/art.js +13 -0
  217. package/kits/physics-2d/engine/assets.js +4 -2
  218. package/kits/physics-2d/engine/scene.js +25 -5
  219. package/kits/physics-3d/CLAUDE.md +6 -1
  220. package/kits/physics-3d/castle.json +3 -3
  221. package/kits/physics-3d/engine3d/Scene3DPlayer.jsx +32 -4
  222. package/kits/physics-3d/engine3d/artobjects.js +2 -2
  223. package/kits/physics-3d/engine3d/materials.js +29 -1
  224. package/kits/physics-3d/engine3d/world3d.js +65 -1
  225. package/kits/physics-3d/systems/physics3d.js +5 -2
  226. package/kits/real-time/castle.json +2 -2
  227. package/kits/real-time/code/client/connection.js +77 -7
  228. package/kits/real-time/code/client/gameHooks.js +63 -3
  229. package/kits/real-time/code/client/messages.js +7 -0
  230. package/kits/real-time/code/server/gameHooks.js +24 -0
  231. package/kits/real-time/code/server/session.js +390 -22
  232. package/package.json +2 -2
@@ -0,0 +1,621 @@
1
+ // Writes the kit's four player avatars, `models/avatar-0.pxmodel` to
2
+ // `avatar-3.pxmodel`: the Castle mascot, Petal, Beat and Star, in the hub's
3
+ // toon style. Run from the kit: `node scripts/gen-avatars.mjs` (or with a
4
+ // directory to write into instead of `models/`). The model files are this
5
+ // script's output; change a character here and run it again.
6
+ //
7
+ // What every avatar keeps, because the kit and the phone budget depend on it:
8
+ // - part ids `torso`, `head`, `legL`, `legR`, `armL`, `armR` (the walk moves
9
+ // them), head and arms under `torso`, feet on y = 0, facing +z;
10
+ // - at most 1,500 triangles with the outline pass and 8 draw calls: six
11
+ // batches (torso, head, two legs, two arms) plus an outline on the torso and
12
+ // the head only. The limbs are ink-coloured and unoutlined, since an outline
13
+ // on each would be four more draw calls;
14
+ // - flat colours: no textures and no glow.
15
+
16
+ import fs from 'node:fs';
17
+ import path from 'node:path';
18
+ import { fileURLToPath } from 'node:url';
19
+
20
+ const KIT_DIR = path.dirname(path.dirname(fileURLToPath(import.meta.url)));
21
+ const OUT_DIR = process.argv[2] ? path.resolve(process.argv[2]) : path.join(KIT_DIR, 'models');
22
+
23
+ const INK = '#241a2e';
24
+ const WHITE = '#ffffff';
25
+ const LOOK = { outline: 0.03, outlineColor: INK, rim: 0, ao: 0.12 };
26
+ const NO_LINE = { outline: 0 };
27
+ // Colours come out darker than written under the engine's lights; this
28
+ // multiplies every colour but the ink.
29
+ const BRIGHT = 2;
30
+ // The mascot is near-black on a darker line than the others' ink, so its edge
31
+ // still shows.
32
+ const MASCOT_BRIGHT = 1.6;
33
+ const MASCOT_LINE = '#0d0b11';
34
+ // The parts the walk moves; each is its own batch with everything under it.
35
+ const ANCHORS = ['torso', 'head', 'legL', 'legR', 'armL', 'armR'];
36
+
37
+ // The leg pivot, and where the torso's own pivot sits, above the feet.
38
+ const HIP = 0.34;
39
+
40
+ const round = (n) => Math.round(n * 1000) / 1000;
41
+ const rad = (d) => (d * Math.PI) / 180;
42
+ const deg = (r) => (r * 180) / Math.PI;
43
+
44
+ function mat(part, color, bright = BRIGHT) {
45
+ part.color = color;
46
+ part.roughness = 1;
47
+ if (color !== INK && bright !== 1) {
48
+ part.brightness = bright;
49
+ }
50
+ return part;
51
+ }
52
+
53
+ // Rubber-hose legs and arms in ink, with a big shoe and a mitten ball, the
54
+ // same on all four. `shoulder` is [x, y] from the torso pivot.
55
+ function limbs({
56
+ shoe,
57
+ mitt = WHITE,
58
+ shoulder = [0.2, 0.28],
59
+ legX = 0.11,
60
+ armTilt = 24,
61
+ bright = BRIGHT,
62
+ }) {
63
+ const armLen = 0.28;
64
+ const parts = [];
65
+ for (const [side, sx] of [
66
+ ['L', 1],
67
+ ['R', -1],
68
+ ]) {
69
+ parts.push(
70
+ mat(
71
+ {
72
+ id: `leg${side}`,
73
+ kind: 'cylinder',
74
+ position: [sx * legX, HIP, 0],
75
+ offset: [0, -0.13, 0],
76
+ radius: 0.05,
77
+ height: 0.28,
78
+ segments: 6,
79
+ look: NO_LINE,
80
+ },
81
+ INK,
82
+ ),
83
+ mat(
84
+ {
85
+ id: `shoe${side}`,
86
+ parent: `leg${side}`,
87
+ kind: 'sphere',
88
+ radius: 0.105,
89
+ position: [sx * 0.01, 0.07 - HIP, 0.055],
90
+ scale: [1, 0.68, 1.5],
91
+ segments: 8,
92
+ look: NO_LINE,
93
+ },
94
+ shoe,
95
+ bright,
96
+ ),
97
+ );
98
+ }
99
+ for (const [side, sx] of [
100
+ ['L', 1],
101
+ ['R', -1],
102
+ ]) {
103
+ parts.push(
104
+ mat(
105
+ {
106
+ id: `arm${side}`,
107
+ parent: 'torso',
108
+ kind: 'cylinder',
109
+ position: [sx * shoulder[0], shoulder[1], 0],
110
+ rotation: [0, 0, sx * armTilt],
111
+ offset: [0, -armLen / 2, 0],
112
+ radius: 0.042,
113
+ height: armLen,
114
+ segments: 6,
115
+ look: NO_LINE,
116
+ },
117
+ INK,
118
+ ),
119
+ mat(
120
+ {
121
+ id: `hand${side}`,
122
+ parent: `arm${side}`,
123
+ kind: 'sphere',
124
+ radius: 0.085,
125
+ position: [0, -armLen - 0.03, 0.01],
126
+ segments: 6,
127
+ look: NO_LINE,
128
+ },
129
+ mitt,
130
+ bright,
131
+ ),
132
+ );
133
+ }
134
+ return parts;
135
+ }
136
+
137
+ function torso(profile, color) {
138
+ return mat({ id: 'torso', kind: 'lathe', position: [0, HIP, 0], profile, segments: 8 }, color);
139
+ }
140
+
141
+ // Where a face detail goes on a head that is a sphere of `radius` stretched by
142
+ // `scale`: the surface point in front of [x, y], pushed `lift` along the
143
+ // normal, and the turn that lays a +z-facing shape flat on it.
144
+ function onHead({ radius, scale }, x, y, lift = 0) {
145
+ const [sx, sy, sz] = scale.map((s) => s * radius);
146
+ const z = sz * Math.sqrt(Math.max(0, 1 - (x / sx) ** 2 - (y / sy) ** 2));
147
+ const normal = [x / sx ** 2, y / sy ** 2, z / sz ** 2];
148
+ const length = Math.hypot(...normal);
149
+ const [nx, ny, nz] = normal.map((n) => n / length);
150
+ return {
151
+ position: [round(x + nx * lift), round(y + ny * lift), round(z + nz * lift)],
152
+ rotation: [round(-deg(Math.asin(ny))), round(deg(Math.atan2(nx, nz))), 0],
153
+ };
154
+ }
155
+
156
+ // A round patch lying on the face, +z before `at` turns it: an eye, a glint,
157
+ // a cheek. A squashed sphere, not a disc: a disc's outline hull shows as a
158
+ // ring round it, while a sphere's only thickens its edge.
159
+ function patch(id, at, { r, wide = 1, tall = 1, segments = 6, mirror = true }, color) {
160
+ const part = {
161
+ id,
162
+ parent: 'head',
163
+ kind: 'sphere',
164
+ radius: r,
165
+ position: at.position,
166
+ rotation: at.rotation,
167
+ scale: [wide, tall, 0.3],
168
+ segments,
169
+ };
170
+ if (mirror) {
171
+ part.mirror = 'x';
172
+ }
173
+ return mat(part, color);
174
+ }
175
+
176
+ // Two ink ovals with a white glint each. `at(x, y, lift)` places a point on
177
+ // the face.
178
+ function eyes(at, { x, y, r, wide = 1, tall = 1, glint = 0.036 }) {
179
+ return [
180
+ patch('eye', at(x, y, 0), { r, wide, tall, segments: 8 }, INK),
181
+ patch(
182
+ 'glint',
183
+ at(x + r * wide * 0.3, y + r * tall * 0.4, r * 0.3),
184
+ { r: glint, segments: 4 },
185
+ WHITE,
186
+ ),
187
+ ];
188
+ }
189
+
190
+ // A regular outline of `count` points, alternating between two radii when
191
+ // `inner` is given: a star.
192
+ function starOutline(count, outer, inner) {
193
+ const points = [];
194
+ for (let k = 0; k < count * 2; k++) {
195
+ const t = Math.PI / 2 + (k * Math.PI) / count;
196
+ const r = k % 2 === 0 ? outer : inner;
197
+ points.push([round(r * Math.cos(t)), round(r * Math.sin(t))]);
198
+ }
199
+ return points;
200
+ }
201
+
202
+ //
203
+ // 0: the Castle mascot. One black body rounded on top, one almond eye, and
204
+ // the logo's white sheen down its side.
205
+ //
206
+
207
+ const MASCOT_R = 0.39;
208
+ // The straight side ends and the dome begins this far above the torso pivot.
209
+ const MASCOT_DOME_Y = 0.65;
210
+
211
+ function mascotBody(color, bright) {
212
+ const profile = [
213
+ [0, -0.06],
214
+ [0.33, -0.05],
215
+ [MASCOT_R, 0.02],
216
+ [MASCOT_R, MASCOT_DOME_Y],
217
+ ];
218
+ for (const elevation of [25, 48, 70]) {
219
+ const at = rad(elevation);
220
+ profile.push([round(MASCOT_R * Math.cos(at)), round(MASCOT_DOME_Y + MASCOT_R * Math.sin(at))]);
221
+ }
222
+ profile.push([0, round(MASCOT_DOME_Y + MASCOT_R)]);
223
+ return mat(
224
+ { id: 'torso', kind: 'lathe', position: [0, HIP, 0], profile, segments: 12 },
225
+ color,
226
+ bright,
227
+ );
228
+ }
229
+
230
+ // The eye is the `head`: an almond wrapped round the front of the body, so the
231
+ // idle look-around slides it (and the sheen) round the body as one face. Its
232
+ // pivot is on the body's axis, `y` above the torso pivot.
233
+ function mascotEye(y) {
234
+ const columns = 8;
235
+ const halfWidth = 0.27;
236
+ const halfHeight = 0.13;
237
+ const outer = MASCOT_R + 0.025;
238
+ const inner = MASCOT_R - 0.04;
239
+ const vertices = [];
240
+ const faces = [];
241
+ // Per column: top and bottom on the outer shell, then the same on the inner.
242
+ for (let i = 0; i <= columns; i++) {
243
+ const u = -halfWidth + (2 * halfWidth * i) / columns;
244
+ const angle = u / outer;
245
+ const h = halfHeight * (1 - (u / halfWidth) ** 2);
246
+ for (const r of [outer, inner]) {
247
+ vertices.push([round(r * Math.sin(angle)), round(h), round(r * Math.cos(angle))]);
248
+ vertices.push([round(r * Math.sin(angle)), round(-h), round(r * Math.cos(angle))]);
249
+ }
250
+ }
251
+ for (let i = 0; i < columns; i++) {
252
+ const a = i * 4;
253
+ const b = a + 4;
254
+ faces.push([a + 1, b + 1, b, a], [a, b, b + 2, a + 2], [b + 1, a + 1, a + 3, b + 3]);
255
+ }
256
+ return mat(
257
+ { id: 'head', parent: 'torso', kind: 'mesh', position: [0, y, 0], vertices, faces },
258
+ WHITE,
259
+ );
260
+ }
261
+
262
+ // The logo's sheen: a sliver on the body's surface down its right side,
263
+ // pointed at the top where it follows the dome. `headY` is the head pivot it
264
+ // hangs from.
265
+ function mascotSheen(headY) {
266
+ const lift = 0.014;
267
+ const edge = rad(-64);
268
+ // Each row is a height above the torso pivot, or an elevation on the dome,
269
+ // and the sliver's width there, both in degrees round the body.
270
+ const rows = [
271
+ { y: 0.1, width: 0 },
272
+ { y: 0.13, width: 14 },
273
+ { y: 0.2, width: 20 },
274
+ { y: 0.44, width: 20 },
275
+ { y: MASCOT_DOME_Y, width: 18 },
276
+ { elevation: 22, width: 15 },
277
+ { elevation: 42, width: 11 },
278
+ { elevation: 56, width: 5 },
279
+ { elevation: 66, width: 0 },
280
+ ];
281
+ const vertices = [];
282
+ const faces = [];
283
+ for (const row of rows) {
284
+ const elevation = rad(row.elevation ?? 0);
285
+ const r = (MASCOT_R + lift) * Math.cos(elevation);
286
+ const y = (row.y ?? MASCOT_DOME_Y + (MASCOT_R + lift) * Math.sin(elevation)) - headY;
287
+ // The dome narrows, so a width there is widened to hold its size.
288
+ const width = rad(row.width) / Math.max(0.35, Math.cos(elevation));
289
+ for (const angle of [edge, edge + width]) {
290
+ vertices.push([round(r * Math.sin(angle)), round(y), round(r * Math.cos(angle))]);
291
+ }
292
+ }
293
+ for (let j = 0; j < rows.length - 1; j++) {
294
+ const a = j * 2;
295
+ faces.push([a, a + 1, a + 3, a + 2]);
296
+ }
297
+ return mat({ id: 'sheen', parent: 'head', kind: 'mesh', vertices, faces }, WHITE);
298
+ }
299
+
300
+ function mascot() {
301
+ const body = '#3a3644';
302
+ const headY = 0.52;
303
+ const front = MASCOT_R + 0.025;
304
+ const flatOn = (x, y, lift) => ({ position: [x, y, round(front + lift)], rotation: [0, 0, 0] });
305
+ const parts = limbs({
306
+ shoe: body,
307
+ shoulder: [0.385, 0.34],
308
+ legX: 0.14,
309
+ armTilt: 16,
310
+ bright: MASCOT_BRIGHT,
311
+ });
312
+ parts.push(
313
+ mascotBody(body, MASCOT_BRIGHT),
314
+ mascotEye(headY),
315
+ mascotSheen(headY),
316
+ patch('pupil', flatOn(0, 0, -0.01), { r: 0.108, segments: 10, mirror: false }, INK),
317
+ patch('glint', flatOn(0.042, 0.046, 0.016), { r: 0.038, mirror: false }, WHITE),
318
+ );
319
+ return { name: 'Castle', look: { ...LOOK, outlineColor: MASCOT_LINE }, parts };
320
+ }
321
+
322
+ //
323
+ // 1: Petal, a flower head.
324
+ //
325
+
326
+ function petal() {
327
+ const pink = '#ff5fa2';
328
+ const head = { radius: 0.3, scale: [1.05, 0.95, 1] };
329
+ const at = (x, y, lift) => onHead(head, x, y, lift);
330
+ const count = 6;
331
+ const steps = count * 5;
332
+ const outline = [];
333
+ for (let k = 0; k < steps; k++) {
334
+ const t = Math.PI / 2 + (2 * Math.PI * k) / steps;
335
+ const lobe = Math.abs(Math.cos((count / 2) * (t - Math.PI / 2))) ** 0.6;
336
+ const r = 0.33 + 0.15 * lobe;
337
+ outline.push([round(r * Math.cos(t)), round(r * Math.sin(t))]);
338
+ }
339
+ const parts = limbs({ shoe: pink });
340
+ parts.push(
341
+ torso(
342
+ [
343
+ [0, -0.07],
344
+ [0.19, -0.02],
345
+ [0.24, 0.12],
346
+ [0.2, 0.28],
347
+ [0.12, 0.39],
348
+ [0, 0.42],
349
+ ],
350
+ '#35c46a',
351
+ ),
352
+ mat(
353
+ {
354
+ id: 'head',
355
+ parent: 'torso',
356
+ kind: 'sphere',
357
+ position: [0, 0.68, 0],
358
+ ...head,
359
+ segments: 10,
360
+ },
361
+ '#fff1cf',
362
+ ),
363
+ // The ring sits behind the face like a collar, so the arms swing in front.
364
+ mat(
365
+ {
366
+ id: 'petals',
367
+ parent: 'head',
368
+ kind: 'extrude',
369
+ outline,
370
+ depth: 0.1,
371
+ flat: false,
372
+ position: [0, 0, -0.1],
373
+ },
374
+ pink,
375
+ ),
376
+ ...eyes(at, { x: 0.115, y: 0.035, r: 0.075, wide: 0.85, tall: 1.25 }),
377
+ patch('cheek', at(0.205, -0.075, 0), { r: 0.048, tall: 0.7, segments: 5 }, pink),
378
+ mat(
379
+ {
380
+ id: 'mouth',
381
+ parent: 'head',
382
+ kind: 'torus',
383
+ radius: 0.045,
384
+ tube: 0.016,
385
+ arc: 180,
386
+ ...at(0, -0.07, 0.004),
387
+ segments: 6,
388
+ },
389
+ INK,
390
+ ),
391
+ // Two leaves on the back, like a sprout's.
392
+ mat(
393
+ {
394
+ id: 'leaf',
395
+ parent: 'torso',
396
+ kind: 'extrude',
397
+ outline: [
398
+ [0, 0],
399
+ [0.11, 0.13],
400
+ [0.07, 0.26],
401
+ [0, 0.34],
402
+ [-0.07, 0.26],
403
+ [-0.11, 0.13],
404
+ ],
405
+ depth: 0.05,
406
+ flat: false,
407
+ position: [0.07, 0.13, -0.16],
408
+ rotation: [-28, 0, -48],
409
+ mirror: 'x',
410
+ },
411
+ '#8fe04a',
412
+ ),
413
+ );
414
+ parts.find((part) => part.id === 'mouth').rotation[2] = 180;
415
+ return { name: 'Petal', parts };
416
+ }
417
+
418
+ //
419
+ // 2: Beat, headphones.
420
+ //
421
+
422
+ function beat() {
423
+ const orange = '#ff6a2b';
424
+ const navy = '#2b62e3';
425
+ const head = { radius: 0.3, scale: [1, 0.93, 0.98] };
426
+ const at = (x, y, lift) => onHead(head, x, y, lift);
427
+ const grin = [];
428
+ for (let k = 0; k <= 6; k++) {
429
+ const t = Math.PI + (Math.PI * k) / 6;
430
+ grin.push([round(0.09 * Math.cos(t)), round(0.075 * Math.sin(t))]);
431
+ }
432
+ // The crest runs from the crown down the back of the head, behind the band.
433
+ const crest = [10, 45, 80].map((lean, k) =>
434
+ mat(
435
+ {
436
+ id: `crest${k}`,
437
+ parent: 'head',
438
+ kind: 'cone',
439
+ radius: 0.075,
440
+ height: 0.2,
441
+ position: [0, round(0.33 * Math.cos(rad(lean))), round(-0.33 * Math.sin(rad(lean)))],
442
+ rotation: [-lean - 14, 0, 0],
443
+ segments: 5,
444
+ },
445
+ navy,
446
+ ),
447
+ );
448
+ const parts = limbs({ shoe: orange });
449
+ parts.push(
450
+ torso(
451
+ [
452
+ [0, -0.07],
453
+ [0.2, -0.03],
454
+ [0.23, 0.13],
455
+ [0.21, 0.29],
456
+ [0.13, 0.39],
457
+ [0, 0.42],
458
+ ],
459
+ navy,
460
+ ),
461
+ mat(
462
+ {
463
+ id: 'head',
464
+ parent: 'torso',
465
+ kind: 'sphere',
466
+ position: [0, 0.66, 0],
467
+ ...head,
468
+ segments: 10,
469
+ },
470
+ '#38b6ff',
471
+ ),
472
+ mat(
473
+ {
474
+ id: 'cup',
475
+ parent: 'head',
476
+ kind: 'cylinder',
477
+ radius: 0.155,
478
+ height: 0.13,
479
+ position: [0.31, -0.02, 0],
480
+ rotation: [0, 0, 90],
481
+ segments: 8,
482
+ mirror: 'x',
483
+ },
484
+ orange,
485
+ ),
486
+ mat(
487
+ {
488
+ id: 'band',
489
+ parent: 'head',
490
+ kind: 'torus',
491
+ radius: 0.32,
492
+ tube: 0.042,
493
+ arc: 180,
494
+ position: [0, -0.02, 0],
495
+ segments: 6,
496
+ },
497
+ INK,
498
+ ),
499
+ ...crest,
500
+ ...eyes(at, { x: 0.12, y: 0.035, r: 0.075, tall: 1.05 }),
501
+ mat(
502
+ {
503
+ id: 'mouth',
504
+ parent: 'head',
505
+ kind: 'extrude',
506
+ outline: grin,
507
+ depth: 0.04,
508
+ flat: false,
509
+ ...at(0, -0.06, 0),
510
+ },
511
+ INK,
512
+ ),
513
+ patch('tongue', at(0, -0.118, 0.012), { r: 0.045, tall: 0.5, mirror: false }, '#ff5fa2'),
514
+ );
515
+ return { name: 'Beat', parts };
516
+ }
517
+
518
+ //
519
+ // 3: Star, a star-shaped head.
520
+ //
521
+
522
+ function star() {
523
+ const purple = '#8a4dff';
524
+ const orange = '#ff9a2e';
525
+ const depth = 0.2;
526
+ // A bevel rounds the edge by growing the outline and both faces by its size.
527
+ const bevel = 0.07;
528
+ const face = depth / 2 + bevel;
529
+ const at = (x, y, lift) => ({
530
+ position: [round(x), round(y), round(face + lift)],
531
+ rotation: [0, 0, 0],
532
+ });
533
+ const parts = limbs({ shoe: purple, shoulder: [0.2, 0.24] });
534
+ parts.push(
535
+ torso(
536
+ [
537
+ [0, -0.07],
538
+ [0.18, -0.03],
539
+ [0.22, 0.1],
540
+ [0.19, 0.25],
541
+ [0.11, 0.36],
542
+ [0, 0.39],
543
+ ],
544
+ orange,
545
+ ),
546
+ mat(
547
+ {
548
+ id: 'head',
549
+ parent: 'torso',
550
+ kind: 'extrude',
551
+ outline: starOutline(5, 0.4, 0.22),
552
+ depth,
553
+ bevel,
554
+ flat: false,
555
+ position: [0, 0.72, 0],
556
+ },
557
+ '#ffd21f',
558
+ ),
559
+ ...eyes(at, { x: 0.105, y: 0.02, r: 0.07, tall: 1.1 }),
560
+ patch('mouth', at(0, -0.115, 0), { r: 0.05, tall: 1.1, segments: 8, mirror: false }, INK),
561
+ // A smaller star on the back.
562
+ mat(
563
+ {
564
+ id: 'badge',
565
+ parent: 'head',
566
+ kind: 'extrude',
567
+ outline: starOutline(5, 0.2, 0.1),
568
+ depth: 0.06,
569
+ flat: false,
570
+ position: [0, 0, -face],
571
+ },
572
+ orange,
573
+ ),
574
+ );
575
+ return { name: 'Star', parts };
576
+ }
577
+
578
+ //
579
+ // Writing
580
+ //
581
+
582
+ // A lathe or an extrude draws both sides, and a batch splits where its parts
583
+ // differ in that, so every part sharing a batch with one is drawn two-sided
584
+ // too.
585
+ function evenBatches(parts) {
586
+ const byId = new Map(parts.map((part) => [part.id, part]));
587
+ const anchorOf = (part) => {
588
+ let at = part;
589
+ while (!ANCHORS.includes(at.id)) {
590
+ at = byId.get(at.parent);
591
+ }
592
+ return at.id;
593
+ };
594
+ const twoSided = (part) => part.kind === 'lathe' || part.kind === 'extrude';
595
+ const both = new Set(parts.filter(twoSided).map(anchorOf));
596
+ for (const part of parts) {
597
+ if (both.has(anchorOf(part)) && !twoSided(part)) {
598
+ part.doubleSided = true;
599
+ }
600
+ }
601
+ }
602
+
603
+ function write(index, { name, look = LOOK, parts }) {
604
+ evenBatches(parts);
605
+ const lines = [
606
+ '{',
607
+ ' "format": "pxmodel",',
608
+ ` "name": ${JSON.stringify(name)},`,
609
+ ' "triangles": 1500,',
610
+ ` "look": ${JSON.stringify(look)},`,
611
+ ' "parts": [',
612
+ parts.map((part) => ` ${JSON.stringify(part)}`).join(',\n'),
613
+ ' ]',
614
+ '}',
615
+ '',
616
+ ];
617
+ fs.writeFileSync(path.join(OUT_DIR, `avatar-${index}.pxmodel`), lines.join('\n'));
618
+ }
619
+
620
+ fs.mkdirSync(OUT_DIR, { recursive: true });
621
+ [mascot, petal, beat, star].forEach((make, index) => write(index, make()));