castle-web-cli 0.4.229 → 0.4.231
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/dist/agent-prompts.d.ts +2 -0
- package/dist/agent-prompts.js +16 -8
- package/dist/agent.d.ts +2 -0
- package/dist/agent.js +21 -21
- package/dist/api.d.ts +28 -2
- package/dist/api.js +74 -16
- package/dist/castle-host/host.d.ts +91 -0
- package/dist/castle-host/host.js +860 -3
- package/dist/castleJson.d.ts +44 -0
- package/dist/castleJson.js +131 -0
- package/dist/check.js +27 -1
- package/dist/contentPack.d.ts +49 -0
- package/dist/contentPack.js +273 -0
- package/dist/devExperiments.d.ts +21 -0
- package/dist/devExperiments.js +139 -0
- package/dist/devHub.d.ts +55 -0
- package/dist/devHub.js +187 -0
- package/dist/devSaveStorage.d.ts +36 -0
- package/dist/devSaveStorage.js +469 -0
- package/dist/devSessionChild.js +25 -13
- package/dist/devSessionServer.d.ts +14 -1
- package/dist/devSessionServer.js +237 -46
- package/dist/devSessionStorage.d.ts +9 -0
- package/dist/devSessionStorage.js +66 -1
- package/dist/experimentAssignment.d.ts +15 -0
- package/dist/experimentAssignment.js +41 -0
- package/dist/importCheckHook.d.ts +40 -0
- package/dist/importCheckHook.js +171 -0
- package/dist/importRegression.d.ts +15 -0
- package/dist/importRegression.js +100 -0
- package/dist/importTrust.d.ts +2 -0
- package/dist/importTrust.js +27 -0
- package/dist/importUpdateHook.d.ts +18 -0
- package/dist/importUpdateHook.js +31 -8
- package/dist/importUpdateHookRunner.js +19 -7
- package/dist/imports.d.ts +16 -0
- package/dist/imports.js +141 -31
- package/dist/index.js +3 -1
- package/dist/init.d.ts +3 -0
- package/dist/init.js +126 -9
- package/dist/install.js +4 -1
- package/dist/localPaths.js +4 -0
- package/dist/login.js +2 -2
- package/dist/platformDoc.js +3 -8
- package/dist/playPagePolicy.js +3 -1
- package/dist/remix.js +5 -0
- package/dist/routerTaskReport.d.ts +28 -0
- package/dist/routerTaskReport.js +56 -0
- package/dist/save-deck.d.ts +18 -0
- package/dist/save-deck.js +142 -6
- package/dist/serve.d.ts +8 -0
- package/dist/serve.js +99 -14
- package/dist/serverBundle.d.ts +1 -1
- package/dist/serverBundle.js +5 -1
- package/dist/webSourceSync.d.ts +2 -0
- package/dist/webSourceSync.js +2 -0
- package/kits/base/CLAUDE.md +2 -3
- package/kits/base/castle.json +1 -1
- package/kits/base/sdk/README.md +406 -53
- package/kits/base/sdk/agent.js +4 -4
- package/kits/base/sdk/avatar.d.ts +12 -0
- package/kits/base/sdk/avatar.js +23 -0
- package/kits/base/sdk/castle.d.ts +9 -0
- package/kits/base/sdk/castle.js +5 -0
- package/kits/base/sdk/commands.d.ts +223 -0
- package/kits/base/sdk/commands.js +16 -0
- package/kits/base/sdk/context.d.ts +6 -0
- package/kits/base/sdk/experiments.d.ts +15 -0
- package/kits/base/sdk/experiments.js +83 -0
- package/kits/base/sdk/hub.d.ts +85 -0
- package/kits/base/sdk/hub.js +107 -0
- package/kits/base/sdk/multiplayer.d.ts +45 -1
- package/kits/base/sdk/multiplayer.js +158 -8
- package/kits/base/sdk/save.d.ts +197 -0
- package/kits/base/sdk/save.js +525 -0
- package/kits/base/sdk/saveCoordinator.d.ts +39 -0
- package/kits/base/sdk/saveCoordinator.js +252 -0
- package/kits/base/sdk/server/hub.d.ts +169 -0
- package/kits/base/sdk/server/hub.js +125 -0
- package/kits/base/sdk/server/platformHandle.d.ts +42 -1
- package/kits/base/sdk/server/storage.d.ts +58 -4
- package/kits/base/sdk/server/storage.js +25 -5
- package/kits/base/sdk/server/wrapper.d.ts +36 -2
- package/kits/base/sdk/server/wrapper.js +92 -11
- package/kits/base/sdk/store.d.ts +3 -2
- package/kits/base/sdk/store.js +5 -0
- package/kits/base/sdk/transport.d.ts +2 -1
- package/kits/base/sdk/transport.js +13 -1
- package/kits/hub-game/.prettierrc +5 -0
- package/kits/hub-game/CLAUDE.md +149 -0
- package/kits/hub-game/blueprints/avatar-0.scene +28 -0
- package/kits/hub-game/blueprints/avatar-1.scene +28 -0
- package/kits/hub-game/blueprints/avatar-2.scene +28 -0
- package/kits/hub-game/blueprints/avatar-3.scene +28 -0
- package/kits/hub-game/blueprints/bean/avatar-0.scene +28 -0
- package/kits/hub-game/blueprints/bean/avatar-1.scene +28 -0
- package/kits/hub-game/blueprints/bean/avatar-2.scene +28 -0
- package/kits/hub-game/blueprints/bean/avatar-3.scene +28 -0
- package/kits/hub-game/blueprints/blocky/avatar-0.scene +28 -0
- package/kits/hub-game/blueprints/blocky/avatar-1.scene +28 -0
- package/kits/hub-game/blueprints/blocky/avatar-2.scene +28 -0
- package/kits/hub-game/blueprints/blocky/avatar-3.scene +28 -0
- package/kits/hub-game/blueprints/pixel/avatar-0.scene +28 -0
- package/kits/hub-game/blueprints/pixel/avatar-1.scene +28 -0
- package/kits/hub-game/blueprints/pixel/avatar-2.scene +28 -0
- package/kits/hub-game/blueprints/pixel/avatar-3.scene +28 -0
- package/kits/hub-game/castle.json +96 -0
- package/kits/hub-game/code/client/attention.js +133 -0
- package/kits/hub-game/code/client/avatar.js +288 -0
- package/kits/hub-game/code/client/cabinets.js +90 -0
- package/kits/hub-game/code/client/chat.js +135 -0
- package/kits/hub-game/code/client/chrome.js +1035 -0
- package/kits/hub-game/code/client/doorFrame.js +15 -0
- package/kits/hub-game/code/client/firstJoin.js +14 -0
- package/kits/hub-game/code/client/grab.js +376 -0
- package/kits/hub-game/code/client/hookLayer.js +236 -0
- package/kits/hub-game/code/client/idle.js +326 -0
- package/kits/hub-game/code/client/keys.js +48 -0
- package/kits/hub-game/code/client/pack.js +232 -0
- package/kits/hub-game/code/client/packFormat.js +397 -0
- package/kits/hub-game/code/client/say.js +127 -0
- package/kits/hub-game/code/client/sha256.js +80 -0
- package/kits/hub-game/code/client/sound.js +147 -0
- package/kits/hub-game/code/client/state.js +143 -0
- package/kits/hub-game/code/client/talk.js +233 -0
- package/kits/hub-game/code/client/tiers.js +480 -0
- package/kits/hub-game/code/client/together.js +440 -0
- package/kits/hub-game/code/client/wear.js +149 -0
- package/kits/hub-game/code/server/actors.js +627 -0
- package/kits/hub-game/code/server/blocks.js +103 -0
- package/kits/hub-game/code/server/cabinets.js +309 -0
- package/kits/hub-game/code/server/game.js +137 -0
- package/kits/hub-game/code/server/grab.js +248 -0
- package/kits/hub-game/code/server/history.js +96 -0
- package/kits/hub-game/code/server/hub.js +1998 -0
- package/kits/hub-game/code/server/idle.js +412 -0
- package/kits/hub-game/code/server/index.js +64 -0
- package/kits/hub-game/code/server/labels.js +59 -0
- package/kits/hub-game/code/server/manifest.js +554 -0
- package/kits/hub-game/code/server/npcs.js +733 -0
- package/kits/hub-game/code/server/party.js +439 -0
- package/kits/hub-game/code/server/place.js +43 -0
- package/kits/hub-game/code/server/say.js +83 -0
- package/kits/hub-game/code/server/wear.js +142 -0
- package/kits/hub-game/code/systems/hub.js +2347 -0
- package/kits/hub-game/docs/content-pack.md +151 -0
- package/kits/hub-game/docs/contract.md +1209 -0
- package/kits/hub-game/docs/style.md +137 -0
- package/kits/hub-game/drawings/blocky/castle-eye.sprite +58 -0
- package/kits/hub-game/drawings/blocky/dash.sprite +59 -0
- package/kits/hub-game/drawings/blocky/pom.sprite +59 -0
- package/kits/hub-game/drawings/blocky/tabby.sprite +59 -0
- package/kits/hub-game/drawings/pixel/castle-arm.sprite +13 -0
- package/kits/hub-game/drawings/pixel/castle-body.sprite +23 -0
- package/kits/hub-game/drawings/pixel/castle-leg.sprite +12 -0
- package/kits/hub-game/drawings/pixel/kai-arm.sprite +14 -0
- package/kits/hub-game/drawings/pixel/kai-head.sprite +24 -0
- package/kits/hub-game/drawings/pixel/kai-leg.sprite +15 -0
- package/kits/hub-game/drawings/pixel/kai-torso.sprite +18 -0
- package/kits/hub-game/drawings/pixel/mimi-arm.sprite +13 -0
- package/kits/hub-game/drawings/pixel/mimi-head.sprite +23 -0
- package/kits/hub-game/drawings/pixel/mimi-leg.sprite +15 -0
- package/kits/hub-game/drawings/pixel/mimi-torso.sprite +18 -0
- package/kits/hub-game/drawings/pixel/nox-arm.sprite +13 -0
- package/kits/hub-game/drawings/pixel/nox-head.sprite +21 -0
- package/kits/hub-game/drawings/pixel/nox-leg.sprite +14 -0
- package/kits/hub-game/drawings/pixel/nox-torso.sprite +18 -0
- package/kits/hub-game/eslint.config.js +20 -0
- package/kits/hub-game/fonts.generated.js +9 -0
- package/kits/hub-game/index.html +22 -0
- package/kits/hub-game/main.jsx +6 -0
- package/kits/hub-game/models/avatar-0.pxmodel +21 -0
- package/kits/hub-game/models/avatar-1.pxmodel +24 -0
- package/kits/hub-game/models/avatar-2.pxmodel +27 -0
- package/kits/hub-game/models/avatar-3.pxmodel +22 -0
- package/kits/hub-game/models/bean/avatar-0.pxmodel +19 -0
- package/kits/hub-game/models/bean/avatar-1.pxmodel +24 -0
- package/kits/hub-game/models/bean/avatar-2.pxmodel +22 -0
- package/kits/hub-game/models/bean/avatar-3.pxmodel +24 -0
- package/kits/hub-game/models/blocky/avatar-0.pxmodel +21 -0
- package/kits/hub-game/models/blocky/avatar-1.pxmodel +30 -0
- package/kits/hub-game/models/blocky/avatar-2.pxmodel +28 -0
- package/kits/hub-game/models/blocky/avatar-3.pxmodel +27 -0
- package/kits/hub-game/models/pixel/avatar-0.pxmodel +24 -0
- package/kits/hub-game/models/pixel/avatar-1.pxmodel +16 -0
- package/kits/hub-game/models/pixel/avatar-2.pxmodel +19 -0
- package/kits/hub-game/models/pixel/avatar-3.pxmodel +23 -0
- package/kits/hub-game/package-lock.json +365 -0
- package/kits/hub-game/package.json +32 -0
- package/kits/hub-game/scenes/main.scene +318 -0
- package/kits/hub-game/scripts/check.mjs +339 -0
- package/kits/hub-game/scripts/fixtures/sdk-stub.mjs +3 -0
- package/kits/hub-game/scripts/gen-avatars-bean.mjs +748 -0
- package/kits/hub-game/scripts/gen-avatars-blocky.mjs +607 -0
- package/kits/hub-game/scripts/gen-avatars-pixel.mjs +771 -0
- package/kits/hub-game/scripts/gen-avatars.mjs +621 -0
- package/kits/hub-game/scripts/pack.mjs +192 -0
- package/kits/hub-game/scripts/test-actors.mjs +666 -0
- package/kits/hub-game/scripts/test-attention.mjs +103 -0
- package/kits/hub-game/scripts/test-avatar.mjs +472 -0
- package/kits/hub-game/scripts/test-ban-join.mjs +194 -0
- package/kits/hub-game/scripts/test-blocks.mjs +351 -0
- package/kits/hub-game/scripts/test-chat.mjs +98 -0
- package/kits/hub-game/scripts/test-classic.mjs +590 -0
- package/kits/hub-game/scripts/test-door-jump.mjs +131 -0
- package/kits/hub-game/scripts/test-door.mjs +56 -0
- package/kits/hub-game/scripts/test-grab-client.mjs +328 -0
- package/kits/hub-game/scripts/test-grab.mjs +331 -0
- package/kits/hub-game/scripts/test-hub-ops.mjs +835 -0
- package/kits/hub-game/scripts/test-hub-trip.mjs +1518 -0
- package/kits/hub-game/scripts/test-idle.mjs +518 -0
- package/kits/hub-game/scripts/test-interest.mjs +413 -0
- package/kits/hub-game/scripts/test-keys.mjs +50 -0
- package/kits/hub-game/scripts/test-manifest.mjs +270 -0
- package/kits/hub-game/scripts/test-no-forms.mjs +16 -0
- package/kits/hub-game/scripts/test-npcs.mjs +724 -0
- package/kits/hub-game/scripts/test-pack.mjs +424 -0
- package/kits/hub-game/scripts/test-party.mjs +369 -0
- package/kits/hub-game/scripts/test-say.mjs +149 -0
- package/kits/hub-game/scripts/test-tiers.mjs +666 -0
- package/kits/hub-game/scripts/test-together.mjs +215 -0
- package/kits/hub-game/theme.style +3 -0
- package/kits/multiplayer-3d/castle.json +5 -5
- package/kits/multiplayer-3d/code/client/avatars.js +101 -1
- package/kits/multiplayer-3d/code/server/players.js +4 -1
- package/kits/multiplayer-3d/code/server/sceneBodies.js +27 -6
- package/kits/multiplayer-3d/code/server/world.js +20 -7
- package/kits/multiplayer-3d/code/systems/multiplayer.js +222 -11
- package/kits/physics-2d/CLAUDE.md +2 -0
- package/kits/physics-2d/castle.json +2 -2
- package/kits/physics-2d/engine/art.js +13 -0
- package/kits/physics-2d/engine/assets.js +4 -2
- package/kits/physics-2d/engine/scene.js +117 -5
- package/kits/physics-2d/package.json +1 -1
- package/kits/physics-2d/scripts/test-skip-unchanged.mjs +254 -0
- package/kits/physics-3d/CLAUDE.md +285 -1
- package/kits/physics-3d/behaviors/Player.jsx +74 -1
- package/kits/physics-3d/castle.json +3 -3
- package/kits/physics-3d/engine3d/Scene3DPlayer.jsx +33 -5
- package/kits/physics-3d/engine3d/actornode.js +253 -0
- package/kits/physics-3d/engine3d/artobjects.js +2 -2
- package/kits/physics-3d/engine3d/materials.js +29 -1
- package/kits/physics-3d/engine3d/nearshadows.js +600 -0
- package/kits/physics-3d/engine3d/unchanged.js +153 -0
- package/kits/physics-3d/engine3d/world3d.js +527 -5
- package/kits/physics-3d/package.json +1 -1
- package/kits/physics-3d/scripts/test-camera-follow.mjs +533 -0
- package/kits/physics-3d/scripts/test-near-shadows.mjs +1073 -0
- package/kits/physics-3d/scripts/test-static-actors.mjs +662 -0
- package/kits/physics-3d/scripts/test-static-passes.mjs +459 -0
- package/kits/physics-3d/scripts/test-static-physics.mjs +128 -0
- package/kits/physics-3d/systems/physics3d.js +187 -5
- package/kits/real-time/castle.json +2 -2
- package/kits/real-time/code/client/connection.js +77 -7
- package/kits/real-time/code/client/gameHooks.js +63 -3
- package/kits/real-time/code/client/messages.js +7 -0
- package/kits/real-time/code/server/gameHooks.js +24 -0
- package/kits/real-time/code/server/session.js +390 -22
- package/package.json +2 -2
|
@@ -0,0 +1,748 @@
|
|
|
1
|
+
// Writes the kit's four `bean` avatars, `models/bean/avatar-0.pxmodel` to
|
|
2
|
+
// `avatar-3.pxmodel`: the Castle mascot, Miso the cat, Sprout and Pip the
|
|
3
|
+
// chick. Run from the kit: `node scripts/gen-avatars-bean.mjs` (or with a
|
|
4
|
+
// directory to write into instead of `models/bean/`). The model files are this
|
|
5
|
+
// script's output; change a character here and run it again.
|
|
6
|
+
//
|
|
7
|
+
// A bean is one rounded body spun round its own axis, with no separate head:
|
|
8
|
+
// the `head` part is the face, hung from a pivot on that axis, so the idle
|
|
9
|
+
// look-around slides the face (and whatever sits on top) round the body. The
|
|
10
|
+
// body has to stay round for that, so it is never stretched in x or z.
|
|
11
|
+
//
|
|
12
|
+
// What every avatar keeps, because the kit and the phone budget depend on it:
|
|
13
|
+
// - part ids `torso`, `head`, `legL`, `legR`, `armL`, `armR` (the walk moves
|
|
14
|
+
// them), head and arms under `torso`, feet on y = 0, facing +z;
|
|
15
|
+
// - at most 1,500 triangles and 8 draw calls: six batches (torso, head, two
|
|
16
|
+
// legs, two arms) and a seventh for the eyes, which blink. There is no
|
|
17
|
+
// outline, which would draw each outlined batch a second time;
|
|
18
|
+
// - flat colours: no textures and no glow.
|
|
19
|
+
|
|
20
|
+
import fs from 'node:fs';
|
|
21
|
+
import path from 'node:path';
|
|
22
|
+
import { fileURLToPath } from 'node:url';
|
|
23
|
+
|
|
24
|
+
const KIT_DIR = path.dirname(path.dirname(fileURLToPath(import.meta.url)));
|
|
25
|
+
const OUT_DIR = process.argv[2]
|
|
26
|
+
? path.resolve(process.argv[2])
|
|
27
|
+
: path.join(KIT_DIR, 'models', 'bean');
|
|
28
|
+
|
|
29
|
+
const INK = '#241a2e';
|
|
30
|
+
const WHITE = '#ffffff';
|
|
31
|
+
const LOOK = { outline: 0, rim: 0.3, ao: 0.15 };
|
|
32
|
+
// Colours come out darker than written under the engine's lights; this
|
|
33
|
+
// multiplies every colour but the ink.
|
|
34
|
+
const BRIGHT = 2;
|
|
35
|
+
// The mascot is near-black, lifted less so it stays black.
|
|
36
|
+
const MASCOT_BRIGHT = 1.6;
|
|
37
|
+
// The parts the walk and the idle move; each is its own batch with everything
|
|
38
|
+
// under it.
|
|
39
|
+
const ANCHORS = ['torso', 'head', 'legL', 'legR', 'armL', 'armR', 'tail'];
|
|
40
|
+
|
|
41
|
+
// The body's underside, and the torso's pivot, above the feet.
|
|
42
|
+
const FLOOR = 0.2;
|
|
43
|
+
// The leg pivot above the feet, inside the body.
|
|
44
|
+
const HIP = 0.3;
|
|
45
|
+
const ARM = 0.3;
|
|
46
|
+
// A part under 3.5 cm in radius is drawn apart from larger ones, so a glint is
|
|
47
|
+
// no smaller.
|
|
48
|
+
const GLINT = 0.036;
|
|
49
|
+
|
|
50
|
+
const round = (n) => Math.round(n * 1000) / 1000;
|
|
51
|
+
const rad = (d) => (d * Math.PI) / 180;
|
|
52
|
+
const deg = (r) => (r * 180) / Math.PI;
|
|
53
|
+
|
|
54
|
+
function mat(part, color, bright = BRIGHT) {
|
|
55
|
+
part.color = color;
|
|
56
|
+
part.roughness = 1;
|
|
57
|
+
if (color !== INK && bright !== 1) {
|
|
58
|
+
part.brightness = bright;
|
|
59
|
+
}
|
|
60
|
+
return part;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// A body's outline from the bottom of its axis to the top, as [radius, y]
|
|
64
|
+
// above the torso pivot: a flat sole `sole` wide, a corner `corner` tall, a
|
|
65
|
+
// side that narrows to `top` times the radius, and a dome `dome` tall.
|
|
66
|
+
function beanProfile({ height, radius, sole = 0, corner, top = 1, dome }) {
|
|
67
|
+
const profile = [[0, 0]];
|
|
68
|
+
for (const turn of [0, 30, 60, 90]) {
|
|
69
|
+
const at = rad(turn);
|
|
70
|
+
profile.push([sole + (radius - sole) * Math.sin(at), corner * (1 - Math.cos(at))]);
|
|
71
|
+
}
|
|
72
|
+
const shoulder = height - dome;
|
|
73
|
+
for (const elevation of [0, 20, 40, 58, 74]) {
|
|
74
|
+
const at = rad(elevation);
|
|
75
|
+
profile.push([radius * top * Math.cos(at), shoulder + dome * Math.sin(at)]);
|
|
76
|
+
}
|
|
77
|
+
profile.push([0, height]);
|
|
78
|
+
return profile.filter(([r], k) => k === 0 || r > 0 || k === profile.length - 1);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function body(profile, color, { bright = BRIGHT, segments = 16 } = {}) {
|
|
82
|
+
return mat(
|
|
83
|
+
{
|
|
84
|
+
id: 'torso',
|
|
85
|
+
kind: 'lathe',
|
|
86
|
+
position: [0, FLOOR, 0],
|
|
87
|
+
profile: profile.map(([r, y]) => [round(r), round(y)]),
|
|
88
|
+
segments,
|
|
89
|
+
},
|
|
90
|
+
color,
|
|
91
|
+
bright,
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Places things on a body. `at(angle, y, lift)` is the point on its surface
|
|
96
|
+
// `angle` degrees round from the front and `y` above the torso pivot, pushed
|
|
97
|
+
// `lift` along the normal, with the turn that lays a +z-facing shape flat on
|
|
98
|
+
// it. Positions are measured from the head pivot, `headY` up the axis.
|
|
99
|
+
function surface(profile, headY) {
|
|
100
|
+
return (angle, y, lift = 0) => {
|
|
101
|
+
const k = Math.max(
|
|
102
|
+
1,
|
|
103
|
+
profile.findIndex(([, top], i) => i > 0 && top >= y),
|
|
104
|
+
);
|
|
105
|
+
const [r0, y0] = profile[k - 1];
|
|
106
|
+
const [r1, y1] = profile[k];
|
|
107
|
+
const r = r0 + ((r1 - r0) * (y - y0)) / (y1 - y0 || 1);
|
|
108
|
+
const length = Math.hypot(y1 - y0, r1 - r0);
|
|
109
|
+
const out = (y1 - y0) / length;
|
|
110
|
+
const up = -(r1 - r0) / length;
|
|
111
|
+
const a = rad(angle);
|
|
112
|
+
const reach = r + lift * out;
|
|
113
|
+
const normal = [out * Math.sin(a), up, out * Math.cos(a)];
|
|
114
|
+
return {
|
|
115
|
+
position: [
|
|
116
|
+
round(reach * Math.sin(a)),
|
|
117
|
+
round(y - headY + lift * up),
|
|
118
|
+
round(reach * Math.cos(a)),
|
|
119
|
+
],
|
|
120
|
+
rotation: [
|
|
121
|
+
round(deg(Math.atan2(-normal[1], normal[2]))),
|
|
122
|
+
round(deg(Math.asin(normal[0]))),
|
|
123
|
+
0,
|
|
124
|
+
],
|
|
125
|
+
};
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// Stub legs and mitten arms, the same on all four. `radius` is the body's,
|
|
130
|
+
// where the arms hang; `shoulder` their height above the torso pivot.
|
|
131
|
+
function limbs({ color, feet = color, radius, shoulder, legX = 0.165, bright = BRIGHT }) {
|
|
132
|
+
const leg = [
|
|
133
|
+
[0, -HIP],
|
|
134
|
+
[0.085, -HIP + 0.01],
|
|
135
|
+
[0.118, -HIP + 0.06],
|
|
136
|
+
[0.112, -0.08],
|
|
137
|
+
[0.07, 0],
|
|
138
|
+
];
|
|
139
|
+
const arm = [
|
|
140
|
+
[0, -ARM],
|
|
141
|
+
[0.058, -ARM + 0.01],
|
|
142
|
+
[0.092, -ARM + 0.042],
|
|
143
|
+
[0.102, -ARM + 0.1],
|
|
144
|
+
[0.088, -0.06],
|
|
145
|
+
[0.05, 0],
|
|
146
|
+
];
|
|
147
|
+
const parts = [];
|
|
148
|
+
for (const [side, sx] of [
|
|
149
|
+
['L', 1],
|
|
150
|
+
['R', -1],
|
|
151
|
+
]) {
|
|
152
|
+
parts.push(
|
|
153
|
+
mat(
|
|
154
|
+
{
|
|
155
|
+
id: `leg${side}`,
|
|
156
|
+
kind: 'lathe',
|
|
157
|
+
position: [sx * legX, HIP, 0],
|
|
158
|
+
profile: leg,
|
|
159
|
+
segments: 10,
|
|
160
|
+
},
|
|
161
|
+
feet,
|
|
162
|
+
bright,
|
|
163
|
+
),
|
|
164
|
+
// The toe, so a foot points the way the bean faces.
|
|
165
|
+
mat(
|
|
166
|
+
{
|
|
167
|
+
id: `toe${side}`,
|
|
168
|
+
parent: `leg${side}`,
|
|
169
|
+
kind: 'sphere',
|
|
170
|
+
radius: 0.1,
|
|
171
|
+
position: [0, -HIP + 0.068, 0.06],
|
|
172
|
+
scale: [1.05, 0.68, 1.25],
|
|
173
|
+
segments: 6,
|
|
174
|
+
},
|
|
175
|
+
feet,
|
|
176
|
+
bright,
|
|
177
|
+
),
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
for (const [side, sx] of [
|
|
181
|
+
['L', 1],
|
|
182
|
+
['R', -1],
|
|
183
|
+
]) {
|
|
184
|
+
parts.push(
|
|
185
|
+
mat(
|
|
186
|
+
{
|
|
187
|
+
id: `arm${side}`,
|
|
188
|
+
parent: 'torso',
|
|
189
|
+
kind: 'lathe',
|
|
190
|
+
position: [sx * round(radius + 0.005), shoulder, 0.02],
|
|
191
|
+
rotation: [0, 0, sx * 20],
|
|
192
|
+
profile: arm,
|
|
193
|
+
segments: 8,
|
|
194
|
+
},
|
|
195
|
+
color,
|
|
196
|
+
bright,
|
|
197
|
+
),
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
return parts;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// A round patch lying on the body, +z before `at` turns it: a cheek, a nose.
|
|
204
|
+
// A squashed sphere, so its edge sinks into the curve of the body.
|
|
205
|
+
function patch(id, parent, at, { r, wide = 1, tall = 1, segments = 8, mirror = true }, color) {
|
|
206
|
+
const part = {
|
|
207
|
+
id,
|
|
208
|
+
parent,
|
|
209
|
+
kind: 'sphere',
|
|
210
|
+
radius: r,
|
|
211
|
+
position: at.position,
|
|
212
|
+
rotation: at.rotation,
|
|
213
|
+
scale: [wide, tall, 0.3],
|
|
214
|
+
segments,
|
|
215
|
+
};
|
|
216
|
+
if (mirror) {
|
|
217
|
+
part.mirror = 'x';
|
|
218
|
+
}
|
|
219
|
+
return mat(part, color);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// Two eyes that blink together, `angle` degrees either side of the front and
|
|
223
|
+
// `y` above the torso pivot. With `white` each is a white oval carrying an ink
|
|
224
|
+
// pupil; without, an ink oval. `look` shifts the pupil inside the white. They
|
|
225
|
+
// hang from an empty part at their own height, which is what blinks: a mirror
|
|
226
|
+
// copy of a part that moves is drawn apart, a copy under one is not.
|
|
227
|
+
function eyes(at, headY, { angle, y, r, wide = 1, tall = 1, white = 0, look = [0, 0], every = 4 }) {
|
|
228
|
+
const outer = white || r;
|
|
229
|
+
const placed = at(angle, y, -0.004);
|
|
230
|
+
placed.position[1] = 0;
|
|
231
|
+
const parts = [
|
|
232
|
+
{
|
|
233
|
+
id: 'eyes',
|
|
234
|
+
parent: 'head',
|
|
235
|
+
kind: 'model',
|
|
236
|
+
position: [0, round(y - headY), 0],
|
|
237
|
+
motion: { blink: every },
|
|
238
|
+
},
|
|
239
|
+
patch('eye', 'eyes', placed, { r: outer, wide, tall }, white ? WHITE : INK),
|
|
240
|
+
];
|
|
241
|
+
let lift = outer * 0.3;
|
|
242
|
+
if (white) {
|
|
243
|
+
parts.push(
|
|
244
|
+
mat(
|
|
245
|
+
{
|
|
246
|
+
id: 'pupil',
|
|
247
|
+
parent: 'eye',
|
|
248
|
+
kind: 'sphere',
|
|
249
|
+
radius: r,
|
|
250
|
+
position: [look[0], look[1], round(lift * 0.55)],
|
|
251
|
+
scale: [wide, tall, 0.3],
|
|
252
|
+
segments: 6,
|
|
253
|
+
},
|
|
254
|
+
INK,
|
|
255
|
+
),
|
|
256
|
+
);
|
|
257
|
+
lift = lift * 0.55 + r * 0.3;
|
|
258
|
+
}
|
|
259
|
+
parts.push(
|
|
260
|
+
mat(
|
|
261
|
+
{
|
|
262
|
+
id: 'glint',
|
|
263
|
+
parent: 'eye',
|
|
264
|
+
kind: 'sphere',
|
|
265
|
+
radius: GLINT,
|
|
266
|
+
position: [
|
|
267
|
+
round(look[0] + r * wide * 0.28),
|
|
268
|
+
round(look[1] + r * tall * 0.36),
|
|
269
|
+
round(lift * 0.8),
|
|
270
|
+
],
|
|
271
|
+
scale: [1, 1, 0.4],
|
|
272
|
+
segments: 6,
|
|
273
|
+
},
|
|
274
|
+
WHITE,
|
|
275
|
+
),
|
|
276
|
+
);
|
|
277
|
+
return parts;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
//
|
|
281
|
+
// 0: the Castle mascot. A flat-bottomed black body with a domed top, one
|
|
282
|
+
// almond eye with a big pupil, and the logo's white sheen down its side.
|
|
283
|
+
//
|
|
284
|
+
|
|
285
|
+
const MASCOT = { height: 1.17, radius: 0.4, sole: 0.33, corner: 0.07, dome: 0.4 };
|
|
286
|
+
// Where the eye looks out, above the torso pivot.
|
|
287
|
+
const MASCOT_EYE_Y = 0.65;
|
|
288
|
+
|
|
289
|
+
// The logo's sheen is the `head`: a sliver on the body's surface down its
|
|
290
|
+
// right side, round at the foot and pointed where it follows the dome. The
|
|
291
|
+
// eye hangs from it, so the idle look-around slides both round the body as
|
|
292
|
+
// one face.
|
|
293
|
+
function mascotSheen() {
|
|
294
|
+
const { height, radius, dome } = MASCOT;
|
|
295
|
+
const shoulder = height - dome;
|
|
296
|
+
const lift = 0.012;
|
|
297
|
+
const edge = -76;
|
|
298
|
+
// Each row is a height above the torso pivot, or an elevation on the dome,
|
|
299
|
+
// and where the sliver starts and how wide it is there, in degrees round
|
|
300
|
+
// the body.
|
|
301
|
+
const rows = [
|
|
302
|
+
{ y: 0.12, from: 9, width: 0 },
|
|
303
|
+
{ y: 0.14, from: 3, width: 14 },
|
|
304
|
+
{ y: 0.19, from: 0, width: 22 },
|
|
305
|
+
{ y: 0.3, from: 0, width: 25 },
|
|
306
|
+
{ y: 0.5, from: 0, width: 25 },
|
|
307
|
+
{ y: shoulder, from: 0, width: 24 },
|
|
308
|
+
{ elevation: 20, from: 1, width: 22 },
|
|
309
|
+
{ elevation: 38, from: 4, width: 18 },
|
|
310
|
+
{ elevation: 54, from: 9, width: 11 },
|
|
311
|
+
{ elevation: 66, from: 15, width: 0 },
|
|
312
|
+
];
|
|
313
|
+
const vertices = [];
|
|
314
|
+
const faces = [];
|
|
315
|
+
for (const row of rows) {
|
|
316
|
+
const elevation = rad(row.elevation ?? 0);
|
|
317
|
+
const r = (radius + lift) * Math.cos(elevation);
|
|
318
|
+
const y = (row.y ?? shoulder + (dome + lift) * Math.sin(elevation)) - MASCOT_EYE_Y;
|
|
319
|
+
// The dome narrows, so a width there is widened to hold its size.
|
|
320
|
+
const widen = 1 / Math.max(0.4, Math.cos(elevation));
|
|
321
|
+
for (const turn of [row.from, row.from + row.width * widen]) {
|
|
322
|
+
const angle = rad(edge + turn);
|
|
323
|
+
vertices.push([round(r * Math.sin(angle)), round(y), round(r * Math.cos(angle))]);
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
for (let j = 0; j < rows.length - 1; j++) {
|
|
327
|
+
const a = j * 2;
|
|
328
|
+
faces.push([a, a + 1, a + 3, a + 2]);
|
|
329
|
+
}
|
|
330
|
+
return mat(
|
|
331
|
+
{
|
|
332
|
+
id: 'head',
|
|
333
|
+
parent: 'torso',
|
|
334
|
+
kind: 'mesh',
|
|
335
|
+
position: [0, MASCOT_EYE_Y, 0],
|
|
336
|
+
vertices,
|
|
337
|
+
faces,
|
|
338
|
+
},
|
|
339
|
+
WHITE,
|
|
340
|
+
);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
// An almond wrapped round the front of the body. Its pivot is the head's, on
|
|
344
|
+
// the body's axis at the eye's height, so a blink closes it top to bottom.
|
|
345
|
+
function mascotEye() {
|
|
346
|
+
const columns = 10;
|
|
347
|
+
const halfWidth = 0.285;
|
|
348
|
+
const halfHeight = 0.15;
|
|
349
|
+
const outer = MASCOT.radius + 0.022;
|
|
350
|
+
const inner = MASCOT.radius - 0.05;
|
|
351
|
+
const vertices = [];
|
|
352
|
+
const faces = [];
|
|
353
|
+
// Per column: top and bottom on the outer shell, then the same on the inner.
|
|
354
|
+
for (let i = 0; i <= columns; i++) {
|
|
355
|
+
const u = -halfWidth + (2 * halfWidth * i) / columns;
|
|
356
|
+
const angle = u / outer;
|
|
357
|
+
const h = halfHeight * (1 - Math.abs(u / halfWidth) ** 2.2);
|
|
358
|
+
for (const r of [outer, inner]) {
|
|
359
|
+
vertices.push([round(r * Math.sin(angle)), round(h), round(r * Math.cos(angle))]);
|
|
360
|
+
vertices.push([round(r * Math.sin(angle)), round(-h), round(r * Math.cos(angle))]);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
for (let i = 0; i < columns; i++) {
|
|
364
|
+
const a = i * 4;
|
|
365
|
+
const b = a + 4;
|
|
366
|
+
faces.push([a + 1, b + 1, b, a], [a, b, b + 2, a + 2], [b + 1, a + 1, a + 3, b + 3]);
|
|
367
|
+
}
|
|
368
|
+
const eye = mat({ id: 'eye', parent: 'head', kind: 'mesh', vertices, faces }, WHITE);
|
|
369
|
+
eye.motion = { blink: 5 };
|
|
370
|
+
return eye;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
function mascot() {
|
|
374
|
+
const black = '#3a3644';
|
|
375
|
+
const front = MASCOT.radius + 0.022;
|
|
376
|
+
const parts = limbs({
|
|
377
|
+
color: black,
|
|
378
|
+
radius: MASCOT.radius,
|
|
379
|
+
shoulder: 0.52,
|
|
380
|
+
legX: 0.17,
|
|
381
|
+
bright: MASCOT_BRIGHT,
|
|
382
|
+
});
|
|
383
|
+
parts.push(
|
|
384
|
+
body(beanProfile(MASCOT), black, { bright: MASCOT_BRIGHT, segments: 20 }),
|
|
385
|
+
mascotSheen(),
|
|
386
|
+
mascotEye(),
|
|
387
|
+
mat(
|
|
388
|
+
{
|
|
389
|
+
id: 'pupil',
|
|
390
|
+
parent: 'eye',
|
|
391
|
+
kind: 'sphere',
|
|
392
|
+
radius: 0.125,
|
|
393
|
+
position: [0, 0, round(front - 0.012)],
|
|
394
|
+
scale: [1, 1, 0.3],
|
|
395
|
+
segments: 12,
|
|
396
|
+
},
|
|
397
|
+
INK,
|
|
398
|
+
),
|
|
399
|
+
mat(
|
|
400
|
+
{
|
|
401
|
+
id: 'glint',
|
|
402
|
+
parent: 'eye',
|
|
403
|
+
kind: 'sphere',
|
|
404
|
+
radius: 0.042,
|
|
405
|
+
position: [0.048, 0.052, round(front + 0.02)],
|
|
406
|
+
scale: [1, 1, 0.4],
|
|
407
|
+
segments: 6,
|
|
408
|
+
},
|
|
409
|
+
WHITE,
|
|
410
|
+
),
|
|
411
|
+
);
|
|
412
|
+
return { name: 'Castle', parts };
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
//
|
|
416
|
+
// 1: Miso, a cat: two ears, two tall eyes, and a tail with a cream tip.
|
|
417
|
+
//
|
|
418
|
+
|
|
419
|
+
function miso() {
|
|
420
|
+
const pink = '#ff4f86';
|
|
421
|
+
const deep = '#d93a70';
|
|
422
|
+
const cream = '#fff1cf';
|
|
423
|
+
const shape = { height: 1.1, radius: 0.385, corner: 0.26, top: 0.9, dome: 0.4 };
|
|
424
|
+
const profile = beanProfile(shape);
|
|
425
|
+
const headY = 0.67;
|
|
426
|
+
const at = surface(profile, headY);
|
|
427
|
+
const parts = limbs({ color: pink, feet: deep, radius: 0.375, shoulder: 0.53 });
|
|
428
|
+
const ear = [
|
|
429
|
+
[0.15, 0],
|
|
430
|
+
[0.13, 0.09],
|
|
431
|
+
[0.085, 0.19],
|
|
432
|
+
[0.035, 0.255],
|
|
433
|
+
[0, 0.27],
|
|
434
|
+
];
|
|
435
|
+
// The tail leaves the back, curls up and leans to one side, so it shows as
|
|
436
|
+
// a tail from straight behind. Its id makes it sway, as its own batch. It is
|
|
437
|
+
// bent into an arc, and the tip sits on the end of that.
|
|
438
|
+
const tail = { length: 0.52, curl: 95 };
|
|
439
|
+
const tailProfile = [[0.055, 0]];
|
|
440
|
+
for (let k = 1; k <= 6; k++) {
|
|
441
|
+
tailProfile.push([0.07, round((tail.length * k) / 6)]);
|
|
442
|
+
}
|
|
443
|
+
const curl = rad(tail.curl);
|
|
444
|
+
const tailEnd = [
|
|
445
|
+
0,
|
|
446
|
+
round((tail.length * Math.sin(curl)) / curl),
|
|
447
|
+
round((tail.length * (1 - Math.cos(curl))) / curl),
|
|
448
|
+
];
|
|
449
|
+
parts.push(
|
|
450
|
+
body(profile, pink),
|
|
451
|
+
// The nose is the `head`: its pivot is on the axis and the nose sits out
|
|
452
|
+
// on the surface.
|
|
453
|
+
mat(
|
|
454
|
+
{
|
|
455
|
+
id: 'head',
|
|
456
|
+
parent: 'torso',
|
|
457
|
+
kind: 'sphere',
|
|
458
|
+
radius: 0.042,
|
|
459
|
+
position: [0, headY, 0],
|
|
460
|
+
offset: [0, -0.085, 0.372],
|
|
461
|
+
scale: [1.25, 0.8, 0.6],
|
|
462
|
+
segments: 6,
|
|
463
|
+
},
|
|
464
|
+
deep,
|
|
465
|
+
),
|
|
466
|
+
...eyes(at, headY, {
|
|
467
|
+
angle: 22,
|
|
468
|
+
y: headY + 0.02,
|
|
469
|
+
white: 0.1,
|
|
470
|
+
r: 0.068,
|
|
471
|
+
wide: 0.9,
|
|
472
|
+
tall: 1.3,
|
|
473
|
+
look: [-0.012, -0.012],
|
|
474
|
+
}),
|
|
475
|
+
mat(
|
|
476
|
+
{
|
|
477
|
+
id: 'ear',
|
|
478
|
+
parent: 'head',
|
|
479
|
+
kind: 'lathe',
|
|
480
|
+
position: [0.205, 0.29, 0],
|
|
481
|
+
rotation: [0, 0, -22],
|
|
482
|
+
scale: [1, 1, 0.6],
|
|
483
|
+
profile: ear,
|
|
484
|
+
segments: 8,
|
|
485
|
+
mirror: 'x',
|
|
486
|
+
},
|
|
487
|
+
pink,
|
|
488
|
+
),
|
|
489
|
+
mat(
|
|
490
|
+
{
|
|
491
|
+
id: 'earIn',
|
|
492
|
+
parent: 'ear',
|
|
493
|
+
kind: 'lathe',
|
|
494
|
+
position: [0, 0.03, 0.045],
|
|
495
|
+
scale: [1, 1, 0.45],
|
|
496
|
+
profile: ear.map(([r, y]) => [round(r * 0.6), round(y * 0.62)]),
|
|
497
|
+
segments: 6,
|
|
498
|
+
},
|
|
499
|
+
cream,
|
|
500
|
+
),
|
|
501
|
+
mat(
|
|
502
|
+
{
|
|
503
|
+
id: 'tail',
|
|
504
|
+
parent: 'torso',
|
|
505
|
+
kind: 'lathe',
|
|
506
|
+
position: [0, 0.2, -0.3],
|
|
507
|
+
rotation: [-75, 0, 28],
|
|
508
|
+
bend: tail.curl,
|
|
509
|
+
profile: tailProfile,
|
|
510
|
+
segments: 8,
|
|
511
|
+
},
|
|
512
|
+
pink,
|
|
513
|
+
),
|
|
514
|
+
mat(
|
|
515
|
+
{
|
|
516
|
+
id: 'tailTip',
|
|
517
|
+
parent: 'tail',
|
|
518
|
+
kind: 'sphere',
|
|
519
|
+
radius: 0.1,
|
|
520
|
+
position: tailEnd,
|
|
521
|
+
segments: 10,
|
|
522
|
+
},
|
|
523
|
+
cream,
|
|
524
|
+
),
|
|
525
|
+
);
|
|
526
|
+
return { name: 'Miso', parts };
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
//
|
|
530
|
+
// 2: Sprout, a tall bulb with two leaves growing from its top.
|
|
531
|
+
//
|
|
532
|
+
|
|
533
|
+
function sprout() {
|
|
534
|
+
const blue = '#2f7dff';
|
|
535
|
+
const deep = '#2460d6';
|
|
536
|
+
const leaf = '#5fdc4a';
|
|
537
|
+
const shape = { height: 1.15, radius: 0.35, corner: 0.3, top: 0.74, dome: 0.34 };
|
|
538
|
+
const profile = beanProfile(shape);
|
|
539
|
+
const headY = 0.68;
|
|
540
|
+
const at = surface(profile, headY);
|
|
541
|
+
const top = shape.height - headY;
|
|
542
|
+
const blade = [
|
|
543
|
+
[0, 0],
|
|
544
|
+
[0.075, 0.05],
|
|
545
|
+
[0.12, 0.15],
|
|
546
|
+
[0.105, 0.27],
|
|
547
|
+
[0.045, 0.36],
|
|
548
|
+
[0, 0.385],
|
|
549
|
+
];
|
|
550
|
+
const parts = limbs({ color: blue, feet: deep, radius: 0.34, shoulder: 0.54, legX: 0.15 });
|
|
551
|
+
parts.push(
|
|
552
|
+
body(profile, blue, { segments: 20 }),
|
|
553
|
+
// The stem is the `head`, so the leaves turn with the face.
|
|
554
|
+
mat(
|
|
555
|
+
{
|
|
556
|
+
id: 'head',
|
|
557
|
+
parent: 'torso',
|
|
558
|
+
kind: 'cylinder',
|
|
559
|
+
radius: 0.034,
|
|
560
|
+
height: 0.16,
|
|
561
|
+
position: [0, headY, 0],
|
|
562
|
+
offset: [0, round(top + 0.04), 0],
|
|
563
|
+
segments: 6,
|
|
564
|
+
},
|
|
565
|
+
leaf,
|
|
566
|
+
),
|
|
567
|
+
mat(
|
|
568
|
+
{
|
|
569
|
+
id: 'smile',
|
|
570
|
+
parent: 'head',
|
|
571
|
+
kind: 'torus',
|
|
572
|
+
radius: 0.05,
|
|
573
|
+
tube: 0.017,
|
|
574
|
+
arc: 180,
|
|
575
|
+
...at(0, headY - 0.03, 0.002),
|
|
576
|
+
segments: 8,
|
|
577
|
+
},
|
|
578
|
+
INK,
|
|
579
|
+
),
|
|
580
|
+
...eyes(at, headY, { angle: 25, y: headY + 0.03, r: 0.07, tall: 1.2 }),
|
|
581
|
+
mat(
|
|
582
|
+
{
|
|
583
|
+
id: 'leafBig',
|
|
584
|
+
parent: 'head',
|
|
585
|
+
kind: 'lathe',
|
|
586
|
+
position: [0.01, round(top + 0.09), 0],
|
|
587
|
+
rotation: [0, 0, -52],
|
|
588
|
+
scale: [1, 1, 0.3],
|
|
589
|
+
profile: blade,
|
|
590
|
+
segments: 8,
|
|
591
|
+
},
|
|
592
|
+
leaf,
|
|
593
|
+
),
|
|
594
|
+
mat(
|
|
595
|
+
{
|
|
596
|
+
id: 'leafSmall',
|
|
597
|
+
parent: 'head',
|
|
598
|
+
kind: 'lathe',
|
|
599
|
+
position: [-0.01, round(top + 0.09), 0],
|
|
600
|
+
rotation: [0, 0, 58],
|
|
601
|
+
scale: [1, 1, 0.3],
|
|
602
|
+
profile: blade.map(([r, y]) => [round(r * 0.78), round(y * 0.74)]),
|
|
603
|
+
segments: 8,
|
|
604
|
+
},
|
|
605
|
+
leaf,
|
|
606
|
+
),
|
|
607
|
+
);
|
|
608
|
+
parts.find((part) => part.id === 'smile').rotation[2] = 180;
|
|
609
|
+
return { name: 'Sprout', parts };
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
//
|
|
613
|
+
// 3: Pip, a chick in a backwards cap.
|
|
614
|
+
//
|
|
615
|
+
|
|
616
|
+
function pip() {
|
|
617
|
+
const yellow = '#ffc61a';
|
|
618
|
+
const orange = '#ff7a1f';
|
|
619
|
+
const purple = '#8a4dff';
|
|
620
|
+
const pinkish = '#ff7d8e';
|
|
621
|
+
const shape = { height: 1.03, radius: 0.43, corner: 0.3, top: 0.94, dome: 0.42 };
|
|
622
|
+
const profile = beanProfile(shape);
|
|
623
|
+
const headY = 0.52;
|
|
624
|
+
const at = surface(profile, headY);
|
|
625
|
+
const rim = 0.71;
|
|
626
|
+
// The cap is the body's own dome, a little larger, from the rim up.
|
|
627
|
+
const cap = [[round(at(0, rim).position[2] - 0.01), rim - 0.03]];
|
|
628
|
+
for (const [r, y] of profile) {
|
|
629
|
+
if (y > rim) {
|
|
630
|
+
cap.push([round(r === 0 ? 0 : r + 0.03), round(y + 0.03)]);
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
cap.splice(1, 0, [round(at(0, rim).position[2] + 0.032), rim]);
|
|
634
|
+
const parts = limbs({ color: yellow, feet: orange, radius: 0.42, shoulder: 0.47, legX: 0.18 });
|
|
635
|
+
parts.push(
|
|
636
|
+
body(profile, yellow),
|
|
637
|
+
mat({ id: 'cap', parent: 'torso', kind: 'lathe', profile: cap, segments: 16 }, purple),
|
|
638
|
+
mat(
|
|
639
|
+
{
|
|
640
|
+
id: 'button',
|
|
641
|
+
parent: 'torso',
|
|
642
|
+
kind: 'sphere',
|
|
643
|
+
radius: 0.06,
|
|
644
|
+
position: [0, shape.height + 0.04, 0],
|
|
645
|
+
scale: [1, 0.7, 1],
|
|
646
|
+
segments: 6,
|
|
647
|
+
},
|
|
648
|
+
yellow,
|
|
649
|
+
),
|
|
650
|
+
mat(
|
|
651
|
+
{
|
|
652
|
+
id: 'tuft',
|
|
653
|
+
parent: 'torso',
|
|
654
|
+
kind: 'sphere',
|
|
655
|
+
radius: 0.1,
|
|
656
|
+
position: [0, 0.22, -0.42],
|
|
657
|
+
rotation: [-35, 0, 0],
|
|
658
|
+
scale: [0.9, 0.75, 1.5],
|
|
659
|
+
segments: 8,
|
|
660
|
+
},
|
|
661
|
+
yellow,
|
|
662
|
+
),
|
|
663
|
+
// The beak is the `head`.
|
|
664
|
+
mat(
|
|
665
|
+
{
|
|
666
|
+
id: 'head',
|
|
667
|
+
parent: 'torso',
|
|
668
|
+
kind: 'sphere',
|
|
669
|
+
radius: 0.085,
|
|
670
|
+
position: [0, headY, 0],
|
|
671
|
+
offset: [0, -0.04, 0.43],
|
|
672
|
+
scale: [1.15, 0.62, 0.9],
|
|
673
|
+
segments: 8,
|
|
674
|
+
},
|
|
675
|
+
orange,
|
|
676
|
+
),
|
|
677
|
+
...eyes(at, headY, { angle: 27, y: headY + 0.02, r: 0.064, tall: 1.1 }),
|
|
678
|
+
patch(
|
|
679
|
+
'cheek',
|
|
680
|
+
'head',
|
|
681
|
+
at(40, headY - 0.07, -0.006),
|
|
682
|
+
{ r: 0.06, tall: 0.7, segments: 6 },
|
|
683
|
+
pinkish,
|
|
684
|
+
),
|
|
685
|
+
// The cap is on backwards: the brim shows from behind, where a player
|
|
686
|
+
// sees their own bean, and leaves the face clear from above.
|
|
687
|
+
mat(
|
|
688
|
+
{
|
|
689
|
+
id: 'brim',
|
|
690
|
+
parent: 'torso',
|
|
691
|
+
kind: 'sphere',
|
|
692
|
+
radius: 0.24,
|
|
693
|
+
position: [0, rim - 0.005, -0.34],
|
|
694
|
+
rotation: [-10, 0, 0],
|
|
695
|
+
scale: [1.2, 0.16, 1],
|
|
696
|
+
segments: 10,
|
|
697
|
+
},
|
|
698
|
+
purple,
|
|
699
|
+
),
|
|
700
|
+
);
|
|
701
|
+
return { name: 'Pip', parts };
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
//
|
|
705
|
+
// Writing
|
|
706
|
+
//
|
|
707
|
+
|
|
708
|
+
// A lathe draws both sides, and a batch splits where its parts differ in
|
|
709
|
+
// that, so every part sharing a batch with one is drawn two-sided too. A
|
|
710
|
+
// batch is a walk part, or a part with a motion of its own, and everything
|
|
711
|
+
// under it.
|
|
712
|
+
function evenBatches(parts) {
|
|
713
|
+
const byId = new Map(parts.map((part) => [part.id, part]));
|
|
714
|
+
const anchorOf = (part) => {
|
|
715
|
+
let at = part;
|
|
716
|
+
while (!ANCHORS.includes(at.id) && !at.motion) {
|
|
717
|
+
at = byId.get(at.parent);
|
|
718
|
+
}
|
|
719
|
+
return at.id;
|
|
720
|
+
};
|
|
721
|
+
const twoSided = (part) => part.kind === 'lathe';
|
|
722
|
+
const both = new Set(parts.filter(twoSided).map(anchorOf));
|
|
723
|
+
for (const part of parts) {
|
|
724
|
+
if (both.has(anchorOf(part)) && !twoSided(part)) {
|
|
725
|
+
part.doubleSided = true;
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
function write(index, { name, parts }) {
|
|
731
|
+
evenBatches(parts);
|
|
732
|
+
const lines = [
|
|
733
|
+
'{',
|
|
734
|
+
' "format": "pxmodel",',
|
|
735
|
+
` "name": ${JSON.stringify(name)},`,
|
|
736
|
+
' "triangles": 1500,',
|
|
737
|
+
` "look": ${JSON.stringify(LOOK)},`,
|
|
738
|
+
' "parts": [',
|
|
739
|
+
parts.map((part) => ` ${JSON.stringify(part)}`).join(',\n'),
|
|
740
|
+
' ]',
|
|
741
|
+
'}',
|
|
742
|
+
'',
|
|
743
|
+
];
|
|
744
|
+
fs.writeFileSync(path.join(OUT_DIR, `avatar-${index}.pxmodel`), lines.join('\n'));
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
fs.mkdirSync(OUT_DIR, { recursive: true });
|
|
748
|
+
[mascot, miso, sprout, pip].forEach((make, index) => write(index, make()));
|