agentcut 0.2.4 → 0.2.6
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/studio/workspace.js +4 -0
- package/dist/studio/workspace.js.map +1 -1
- package/package.json +1 -1
- package/template/components/CATALOG.md +52 -0
- package/template/components/README.md +70 -61
- package/template/components/STYLES.md +2 -0
- package/template/components/catalog.json +477 -0
- package/template/components/catalog.ts +4 -0
- package/template/components/cinematic/Cinematic.tsx +1093 -0
- package/template/components/cinematic/Device3D.tsx +324 -0
- package/template/components/cinematic/devices3d/display-model.ts +184 -0
- package/template/components/cinematic/devices3d/iphone-model.ts +643 -0
- package/template/components/cinematic/devices3d/macbook-model.ts +604 -0
- package/template/components/cinematic/devices3d/models.ts +657 -0
- package/template/components/cinematic/devices3d/runtime.ts +267 -0
- package/template/components/cinematic/math.ts +100 -0
- package/template/components/dot-trace-title/DotTraceTitle.tsx +181 -0
- package/template/components/dot-trace-title/meta.json +51 -0
- package/template/components/generate/GenerateReveal.tsx +381 -0
- package/template/components/index.ts +36 -0
- package/template/components/lib.ts +18 -6
- package/template/components/loops/LoopCanvas.tsx +132 -0
- package/template/components/loops/engine.ts +184 -0
- package/template/components/loops/library.ts +667 -0
- package/template/components/loops/library2.ts +777 -0
- package/template/components/motion-loop/MotionLoop.tsx +37 -0
- package/template/components/motion-loop/meta.json +312 -0
- package/template/skill/SKILL.md +16 -1
- package/template/skill/references/browser-export.md +61 -61
- package/template/skill/references/cinematic.md +184 -0
- package/template/skill/references/loops.md +151 -0
|
@@ -0,0 +1,604 @@
|
|
|
1
|
+
import * as THREE from "three";
|
|
2
|
+
import { RoundedBoxGeometry } from "three/examples/jsm/geometries/RoundedBoxGeometry.js";
|
|
3
|
+
import { SVGLoader } from "three/examples/jsm/loaders/SVGLoader.js";
|
|
4
|
+
import { mergeGeometries } from "three/examples/jsm/utils/BufferGeometryUtils.js";
|
|
5
|
+
import {
|
|
6
|
+
APPLE_MARK_SVG,
|
|
7
|
+
createRoundedExtrudedGeometry,
|
|
8
|
+
createRoundedPlaneGeometry,
|
|
9
|
+
} from "./iphone-model";
|
|
10
|
+
const DEFAULT_LAPTOP_LID_ANGLE = 110;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Procedural 13-inch laptop in the spirit of a MacBook Air. Built from real
|
|
14
|
+
* millimetre proportions, then scaled so the deck is 2 scene units wide.
|
|
15
|
+
*
|
|
16
|
+
* Axes: +x right, +y up, +z toward the viewer. The deck's top surface sits at
|
|
17
|
+
* y = 0 and the lid hinges along its back edge.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
const MM = 2 / 312.6;
|
|
21
|
+
const mm = (value: number) => value * MM;
|
|
22
|
+
|
|
23
|
+
const BASE = { w: 312.6, d: 221.2, t: 10.4, corner: 10.5 };
|
|
24
|
+
const LID = {
|
|
25
|
+
h: 221.2,
|
|
26
|
+
t: 4.8,
|
|
27
|
+
corner: 10.5,
|
|
28
|
+
glassInset: 1.1,
|
|
29
|
+
bezelSide: 5.6,
|
|
30
|
+
bezelTop: 5.6,
|
|
31
|
+
bezelBottom: 7.6,
|
|
32
|
+
notch: { w: 31, h: 6.4 },
|
|
33
|
+
};
|
|
34
|
+
const KEYBOARD = { pitch: 18.55, gap: 2.35, back: 13, corner: 1.6 };
|
|
35
|
+
const TRACKPAD = { w: 140, h: 82, gap: 10, corner: 7.5 };
|
|
36
|
+
|
|
37
|
+
export const MACBOOK_SCREEN_ASPECT =
|
|
38
|
+
(BASE.w - LID.bezelSide * 2) / (LID.h - LID.bezelTop - LID.bezelBottom);
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
type KeySpec = [label: string, width: number, kind?: "mod" | "half"];
|
|
42
|
+
|
|
43
|
+
const U = 1;
|
|
44
|
+
const KEY_ROWS: KeySpec[][] = [
|
|
45
|
+
[
|
|
46
|
+
["esc", 1.5, "mod"],
|
|
47
|
+
...Array.from(
|
|
48
|
+
{ length: 12 },
|
|
49
|
+
(_, index): KeySpec => [`F${index + 1}`, U, "mod"],
|
|
50
|
+
),
|
|
51
|
+
["", U],
|
|
52
|
+
],
|
|
53
|
+
[
|
|
54
|
+
...["`", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "-", "="].map(
|
|
55
|
+
(label): KeySpec => [label, U],
|
|
56
|
+
),
|
|
57
|
+
["delete", 1.5, "mod"],
|
|
58
|
+
],
|
|
59
|
+
[
|
|
60
|
+
["tab", 1.5, "mod"],
|
|
61
|
+
...[..."QWERTYUIOP", "[", "]", "\\"].map((label): KeySpec => [label, U]),
|
|
62
|
+
],
|
|
63
|
+
[
|
|
64
|
+
["caps lock", 1.8, "mod"],
|
|
65
|
+
...[..."ASDFGHJKL", ";", "'"].map((label): KeySpec => [label, U]),
|
|
66
|
+
["return", 1.7, "mod"],
|
|
67
|
+
],
|
|
68
|
+
[
|
|
69
|
+
["shift", 2.35, "mod"],
|
|
70
|
+
...[..."ZXCVBNM", ",", ".", "/"].map((label): KeySpec => [label, U]),
|
|
71
|
+
["shift", 2.15, "mod"],
|
|
72
|
+
],
|
|
73
|
+
[
|
|
74
|
+
["fn", U, "mod"],
|
|
75
|
+
["control", U, "mod"],
|
|
76
|
+
["option", U, "mod"],
|
|
77
|
+
["command", 1.25, "mod"],
|
|
78
|
+
["", 5],
|
|
79
|
+
["command", 1.25, "mod"],
|
|
80
|
+
["option", U, "mod"],
|
|
81
|
+
["◀", U, "half"],
|
|
82
|
+
["▲▼", U, "half"],
|
|
83
|
+
["▶", U, "half"],
|
|
84
|
+
],
|
|
85
|
+
];
|
|
86
|
+
|
|
87
|
+
interface KeyRect {
|
|
88
|
+
label: string;
|
|
89
|
+
kind?: "mod" | "half";
|
|
90
|
+
x: number;
|
|
91
|
+
z: number;
|
|
92
|
+
w: number;
|
|
93
|
+
d: number;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function layoutKeys() {
|
|
97
|
+
const { pitch, gap, back } = KEYBOARD;
|
|
98
|
+
const rowWidth = 14.5 * pitch - gap;
|
|
99
|
+
const keys: KeyRect[] = [];
|
|
100
|
+
let z = -BASE.d / 2 + back;
|
|
101
|
+
KEY_ROWS.forEach((row, rowIndex) => {
|
|
102
|
+
const rowDepth = rowIndex === 0 ? pitch * 0.55 : pitch;
|
|
103
|
+
let x = -rowWidth / 2;
|
|
104
|
+
for (const [label, width, kind] of row) {
|
|
105
|
+
const keyWidth = width * pitch - gap;
|
|
106
|
+
const keyDepth = rowDepth - gap;
|
|
107
|
+
if (kind === "half") {
|
|
108
|
+
if (label === "▲▼") {
|
|
109
|
+
const half = (keyDepth - gap * 0.5) / 2;
|
|
110
|
+
keys.push({ label: "▲", kind, x, z, w: keyWidth, d: half });
|
|
111
|
+
keys.push({
|
|
112
|
+
label: "▼",
|
|
113
|
+
kind,
|
|
114
|
+
x,
|
|
115
|
+
z: z + half + gap * 0.5,
|
|
116
|
+
w: keyWidth,
|
|
117
|
+
d: half,
|
|
118
|
+
});
|
|
119
|
+
} else {
|
|
120
|
+
const half = (keyDepth - gap * 0.5) / 2;
|
|
121
|
+
keys.push({
|
|
122
|
+
label,
|
|
123
|
+
kind,
|
|
124
|
+
x,
|
|
125
|
+
z: z + half + gap * 0.5,
|
|
126
|
+
w: keyWidth,
|
|
127
|
+
d: half,
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
} else {
|
|
131
|
+
keys.push({ label, kind, x, z, w: keyWidth, d: keyDepth });
|
|
132
|
+
}
|
|
133
|
+
x += width * pitch;
|
|
134
|
+
}
|
|
135
|
+
z += rowDepth;
|
|
136
|
+
});
|
|
137
|
+
return { keys, rowWidth, depth: z - (-BASE.d / 2 + back) };
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function createCanvas(width: number, height: number) {
|
|
141
|
+
if (typeof OffscreenCanvas !== "undefined") {
|
|
142
|
+
return new OffscreenCanvas(width, height);
|
|
143
|
+
}
|
|
144
|
+
if (typeof document !== "undefined") {
|
|
145
|
+
const canvas = document.createElement("canvas");
|
|
146
|
+
canvas.width = width;
|
|
147
|
+
canvas.height = height;
|
|
148
|
+
return canvas;
|
|
149
|
+
}
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** Key legends painted once into a texture laid over the keycaps. */
|
|
154
|
+
function createLegendTexture(
|
|
155
|
+
keys: KeyRect[],
|
|
156
|
+
bounds: { x: number; z: number; w: number; d: number },
|
|
157
|
+
) {
|
|
158
|
+
// Dense enough that the legends stay crisp in close-ups.
|
|
159
|
+
const pxPerMm = 14;
|
|
160
|
+
const width = Math.ceil(bounds.w * pxPerMm);
|
|
161
|
+
const height = Math.ceil(bounds.d * pxPerMm);
|
|
162
|
+
const canvas = createCanvas(width, height);
|
|
163
|
+
const context = canvas?.getContext("2d") as
|
|
164
|
+
| CanvasRenderingContext2D
|
|
165
|
+
| OffscreenCanvasRenderingContext2D
|
|
166
|
+
| null
|
|
167
|
+
| undefined;
|
|
168
|
+
if (!canvas || !context) return null;
|
|
169
|
+
context.clearRect(0, 0, width, height);
|
|
170
|
+
// Bright, slightly bold legends: backlit-key white that reads against the black caps.
|
|
171
|
+
context.fillStyle = "#ffffff";
|
|
172
|
+
context.textBaseline = "middle";
|
|
173
|
+
for (const key of keys) {
|
|
174
|
+
if (!key.label) continue;
|
|
175
|
+
const left = (key.x - bounds.x) * pxPerMm;
|
|
176
|
+
const top = (key.z - bounds.z) * pxPerMm;
|
|
177
|
+
const keyWidth = key.w * pxPerMm;
|
|
178
|
+
const keyDepth = key.d * pxPerMm;
|
|
179
|
+
if (key.kind === "mod") {
|
|
180
|
+
context.font = `600 ${Math.round(2.5 * pxPerMm)}px -apple-system, "SF Pro Text", "Helvetica Neue", Arial, sans-serif`;
|
|
181
|
+
context.textAlign = "left";
|
|
182
|
+
context.fillText(
|
|
183
|
+
key.label,
|
|
184
|
+
left + 1.6 * pxPerMm,
|
|
185
|
+
top + keyDepth - 2.4 * pxPerMm,
|
|
186
|
+
keyWidth - 3 * pxPerMm,
|
|
187
|
+
);
|
|
188
|
+
} else {
|
|
189
|
+
const fontSize = key.kind === "half" ? 2.6 : 3.9;
|
|
190
|
+
context.font = `600 ${Math.round(fontSize * pxPerMm)}px -apple-system, "SF Pro Text", "Helvetica Neue", Arial, sans-serif`;
|
|
191
|
+
context.textAlign = "center";
|
|
192
|
+
context.fillText(
|
|
193
|
+
key.label,
|
|
194
|
+
left + keyWidth / 2,
|
|
195
|
+
top + keyDepth / 2,
|
|
196
|
+
keyWidth - 2 * pxPerMm,
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
const texture = new THREE.CanvasTexture(canvas as HTMLCanvasElement);
|
|
201
|
+
texture.colorSpace = THREE.SRGBColorSpace;
|
|
202
|
+
texture.anisotropy = 8;
|
|
203
|
+
return texture;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/** Speaker grille: a fine field of dark perforations on a transparent texture. */
|
|
207
|
+
function createGrilleTexture(widthMm: number, depthMm: number) {
|
|
208
|
+
const pxPerMm = 12;
|
|
209
|
+
const width = Math.ceil(widthMm * pxPerMm);
|
|
210
|
+
const height = Math.ceil(depthMm * pxPerMm);
|
|
211
|
+
const canvas = createCanvas(width, height);
|
|
212
|
+
const context = canvas?.getContext("2d") as CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D | null | undefined;
|
|
213
|
+
if (!canvas || !context) return null;
|
|
214
|
+
context.clearRect(0, 0, width, height);
|
|
215
|
+
context.fillStyle = "rgba(6, 6, 8, 0.85)";
|
|
216
|
+
const pitch = 1.15 * pxPerMm;
|
|
217
|
+
for (let y = pitch / 2, row = 0; y < height; y += pitch * 0.87, row++) {
|
|
218
|
+
for (let x = pitch / 2 + (row % 2) * (pitch / 2); x < width; x += pitch) {
|
|
219
|
+
context.beginPath();
|
|
220
|
+
context.arc(x, y, 0.32 * pxPerMm, 0, Math.PI * 2);
|
|
221
|
+
context.fill();
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
const texture = new THREE.CanvasTexture(canvas as HTMLCanvasElement);
|
|
225
|
+
texture.colorSpace = THREE.SRGBColorSpace;
|
|
226
|
+
texture.anisotropy = 8;
|
|
227
|
+
return texture;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
function createFlatRoundedRect(width: number, depth: number, radius: number) {
|
|
231
|
+
const geometry = createRoundedPlaneGeometry(width, depth, radius);
|
|
232
|
+
geometry.rotateX(-Math.PI / 2);
|
|
233
|
+
return geometry;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
function createLogoGeometry(width: number) {
|
|
237
|
+
const svg = new SVGLoader().parse(APPLE_MARK_SVG);
|
|
238
|
+
const shapes = svg.paths.flatMap((path) => SVGLoader.createShapes(path));
|
|
239
|
+
const geometry = new THREE.ShapeGeometry(shapes, 32);
|
|
240
|
+
geometry.center();
|
|
241
|
+
const scale = width / 814;
|
|
242
|
+
geometry.scale(scale, -scale, 1);
|
|
243
|
+
return geometry;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
function createMaterials(finishColor: THREE.ColorRepresentation) {
|
|
247
|
+
const finish = new THREE.Color(finishColor);
|
|
248
|
+
const { l: lightness } = finish.getHSL({ h: 0, s: 0, l: 0 });
|
|
249
|
+
const isDark = lightness < 0.35;
|
|
250
|
+
return {
|
|
251
|
+
// Bead-blasted anodised aluminium: soft, wide highlights, the finish's own colour in the shadows.
|
|
252
|
+
aluminum: new THREE.MeshPhysicalMaterial({
|
|
253
|
+
color: finish,
|
|
254
|
+
metalness: 0.85,
|
|
255
|
+
roughness: 0.34,
|
|
256
|
+
clearcoat: 0.18,
|
|
257
|
+
clearcoatRoughness: 0.4,
|
|
258
|
+
envMapIntensity: 0.75,
|
|
259
|
+
}),
|
|
260
|
+
edge: new THREE.MeshPhysicalMaterial({
|
|
261
|
+
color: finish.clone().lerp(new THREE.Color(0xffffff), isDark ? 0.08 : 0.2),
|
|
262
|
+
metalness: 1,
|
|
263
|
+
roughness: 0.22,
|
|
264
|
+
}),
|
|
265
|
+
trackpad: new THREE.MeshPhysicalMaterial({
|
|
266
|
+
color: finish.clone().lerp(new THREE.Color(0x000000), 0.06),
|
|
267
|
+
metalness: 0.5,
|
|
268
|
+
roughness: 0.28,
|
|
269
|
+
clearcoat: 0.6,
|
|
270
|
+
clearcoatRoughness: 0.18,
|
|
271
|
+
envMapIntensity: 0.6,
|
|
272
|
+
}),
|
|
273
|
+
well: new THREE.MeshStandardMaterial({
|
|
274
|
+
color: 0x050506,
|
|
275
|
+
roughness: 0.85,
|
|
276
|
+
metalness: 0,
|
|
277
|
+
envMapIntensity: 0.06,
|
|
278
|
+
}),
|
|
279
|
+
key: new THREE.MeshPhysicalMaterial({
|
|
280
|
+
color: 0x0a0a0c,
|
|
281
|
+
roughness: 0.7,
|
|
282
|
+
metalness: 0.05,
|
|
283
|
+
clearcoat: 0.05,
|
|
284
|
+
envMapIntensity: 0.16,
|
|
285
|
+
}),
|
|
286
|
+
grille: new THREE.MeshBasicMaterial({ transparent: true, depthWrite: false }),
|
|
287
|
+
legends: new THREE.MeshBasicMaterial({
|
|
288
|
+
transparent: true,
|
|
289
|
+
depthWrite: false,
|
|
290
|
+
toneMapped: false,
|
|
291
|
+
}),
|
|
292
|
+
glass: new THREE.MeshBasicMaterial({ color: 0x030405 }),
|
|
293
|
+
notch: new THREE.MeshBasicMaterial({ color: 0x030304 }),
|
|
294
|
+
lens: new THREE.MeshPhysicalMaterial({
|
|
295
|
+
color: 0x10162a,
|
|
296
|
+
roughness: 0.05,
|
|
297
|
+
metalness: 0.3,
|
|
298
|
+
clearcoat: 1,
|
|
299
|
+
}),
|
|
300
|
+
hinge: new THREE.MeshPhysicalMaterial({
|
|
301
|
+
color: finish.clone().lerp(new THREE.Color(0x000000), 0.45),
|
|
302
|
+
metalness: 0.8,
|
|
303
|
+
roughness: 0.35,
|
|
304
|
+
}),
|
|
305
|
+
rubber: new THREE.MeshStandardMaterial({ color: 0x18181a, roughness: 0.9, envMapIntensity: 0.2 }),
|
|
306
|
+
logo: new THREE.MeshPhysicalMaterial({
|
|
307
|
+
color: finish
|
|
308
|
+
.clone()
|
|
309
|
+
.lerp(new THREE.Color(isDark ? 0xffffff : 0x000000), isDark ? 0.2 : 0.45),
|
|
310
|
+
metalness: 1,
|
|
311
|
+
roughness: 0.05,
|
|
312
|
+
side: THREE.DoubleSide,
|
|
313
|
+
}),
|
|
314
|
+
screenOff: new THREE.MeshBasicMaterial({ color: 0x050608 }),
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
export interface MacbookModelOptions {
|
|
319
|
+
screenMaterial?: THREE.Material;
|
|
320
|
+
finishColor?: THREE.ColorRepresentation;
|
|
321
|
+
lidAngle?: number;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
export function createMacbookModel(options: MacbookModelOptions = {}) {
|
|
325
|
+
const root = new THREE.Group();
|
|
326
|
+
root.name = "procedural-macbook";
|
|
327
|
+
const materials = createMaterials(options.finishColor ?? 0xcfd1d3);
|
|
328
|
+
const add = (
|
|
329
|
+
name: string,
|
|
330
|
+
mesh: THREE.Mesh,
|
|
331
|
+
parent: THREE.Object3D = root,
|
|
332
|
+
) => {
|
|
333
|
+
mesh.name = name;
|
|
334
|
+
mesh.castShadow = true;
|
|
335
|
+
mesh.receiveShadow = true;
|
|
336
|
+
parent.add(mesh);
|
|
337
|
+
return mesh;
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
// ── Deck ─────────────────────────────────────────────────────────────
|
|
341
|
+
const baseGeometry = createRoundedExtrudedGeometry(
|
|
342
|
+
mm(BASE.w),
|
|
343
|
+
mm(BASE.d),
|
|
344
|
+
mm(BASE.corner),
|
|
345
|
+
mm(BASE.t - 1.2),
|
|
346
|
+
mm(0.6),
|
|
347
|
+
mm(0.6),
|
|
348
|
+
);
|
|
349
|
+
baseGeometry.rotateX(-Math.PI / 2);
|
|
350
|
+
const base = add("laptop-base", new THREE.Mesh(baseGeometry, materials.aluminum));
|
|
351
|
+
base.position.y = -mm(BASE.t) / 2;
|
|
352
|
+
|
|
353
|
+
// Chamfered rim catching a bright highlight around the deck.
|
|
354
|
+
const rim = add(
|
|
355
|
+
"laptop-deck-rim",
|
|
356
|
+
new THREE.Mesh(
|
|
357
|
+
createFlatRoundedRect(mm(BASE.w - 0.8), mm(BASE.d - 0.8), mm(BASE.corner)),
|
|
358
|
+
materials.edge,
|
|
359
|
+
),
|
|
360
|
+
);
|
|
361
|
+
rim.position.y = mm(0.12);
|
|
362
|
+
const deckTop = add(
|
|
363
|
+
"laptop-deck-top",
|
|
364
|
+
new THREE.Mesh(
|
|
365
|
+
createFlatRoundedRect(mm(BASE.w - 2.2), mm(BASE.d - 2.2), mm(BASE.corner - 1)),
|
|
366
|
+
materials.aluminum,
|
|
367
|
+
),
|
|
368
|
+
);
|
|
369
|
+
deckTop.position.y = mm(0.24);
|
|
370
|
+
|
|
371
|
+
// ── Keyboard ─────────────────────────────────────────────────────────
|
|
372
|
+
const { keys, rowWidth, depth } = layoutKeys();
|
|
373
|
+
const keyboardBounds = {
|
|
374
|
+
x: -rowWidth / 2 - 1.2,
|
|
375
|
+
z: -BASE.d / 2 + KEYBOARD.back - 1.2,
|
|
376
|
+
w: rowWidth + 2.4,
|
|
377
|
+
d: depth - KEYBOARD.gap + 2.4,
|
|
378
|
+
};
|
|
379
|
+
const well = add(
|
|
380
|
+
"laptop-keyboard-well",
|
|
381
|
+
new THREE.Mesh(
|
|
382
|
+
createFlatRoundedRect(
|
|
383
|
+
mm(keyboardBounds.w),
|
|
384
|
+
mm(keyboardBounds.d),
|
|
385
|
+
mm(2.4),
|
|
386
|
+
),
|
|
387
|
+
materials.well,
|
|
388
|
+
),
|
|
389
|
+
);
|
|
390
|
+
well.position.set(
|
|
391
|
+
mm(keyboardBounds.x + keyboardBounds.w / 2),
|
|
392
|
+
mm(0.4),
|
|
393
|
+
mm(keyboardBounds.z + keyboardBounds.d / 2),
|
|
394
|
+
);
|
|
395
|
+
|
|
396
|
+
const keyHeight = 0.9;
|
|
397
|
+
const keyGeometries = keys.map((key) => {
|
|
398
|
+
const geometry = new RoundedBoxGeometry(
|
|
399
|
+
mm(key.w),
|
|
400
|
+
mm(keyHeight),
|
|
401
|
+
mm(key.d),
|
|
402
|
+
2,
|
|
403
|
+
mm(Math.min(KEYBOARD.corner, key.d / 2.2, key.w / 2.2)),
|
|
404
|
+
);
|
|
405
|
+
geometry.translate(
|
|
406
|
+
mm(key.x + key.w / 2),
|
|
407
|
+
mm(keyHeight / 2 + 0.45),
|
|
408
|
+
mm(key.z + key.d / 2),
|
|
409
|
+
);
|
|
410
|
+
return geometry;
|
|
411
|
+
});
|
|
412
|
+
const keysGeometry = mergeGeometries(keyGeometries, false);
|
|
413
|
+
keyGeometries.forEach((geometry) => geometry.dispose());
|
|
414
|
+
if (keysGeometry) add("laptop-keys", new THREE.Mesh(keysGeometry, materials.key));
|
|
415
|
+
|
|
416
|
+
const legendTexture = createLegendTexture(keys, keyboardBounds);
|
|
417
|
+
if (legendTexture) {
|
|
418
|
+
materials.legends.map = legendTexture;
|
|
419
|
+
const legends = add(
|
|
420
|
+
"laptop-key-legends",
|
|
421
|
+
new THREE.Mesh(
|
|
422
|
+
new THREE.PlaneGeometry(mm(keyboardBounds.w), mm(keyboardBounds.d)).rotateX(
|
|
423
|
+
-Math.PI / 2,
|
|
424
|
+
),
|
|
425
|
+
materials.legends,
|
|
426
|
+
),
|
|
427
|
+
);
|
|
428
|
+
legends.castShadow = false;
|
|
429
|
+
legends.position.set(
|
|
430
|
+
mm(keyboardBounds.x + keyboardBounds.w / 2),
|
|
431
|
+
mm(keyHeight + 0.6),
|
|
432
|
+
mm(keyboardBounds.z + keyboardBounds.d / 2),
|
|
433
|
+
);
|
|
434
|
+
legends.renderOrder = 2;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
// ── Speaker grilles either side of the keyboard ─────────────────────
|
|
438
|
+
const sideRoom = (BASE.w - keyboardBounds.w) / 2;
|
|
439
|
+
const grilleW = Math.min(12, sideRoom - 6);
|
|
440
|
+
const grilleTexture = grilleW > 3 ? createGrilleTexture(grilleW, keyboardBounds.d) : null;
|
|
441
|
+
if (grilleTexture) {
|
|
442
|
+
materials.grille.map = grilleTexture;
|
|
443
|
+
for (const side of [-1, 1]) {
|
|
444
|
+
const grille = add(
|
|
445
|
+
"laptop-speaker-grille",
|
|
446
|
+
new THREE.Mesh(new THREE.PlaneGeometry(mm(grilleW), mm(keyboardBounds.d)).rotateX(-Math.PI / 2), materials.grille),
|
|
447
|
+
);
|
|
448
|
+
grille.castShadow = false;
|
|
449
|
+
grille.position.set(
|
|
450
|
+
side * mm(keyboardBounds.w / 2 + sideRoom / 2),
|
|
451
|
+
mm(0.3),
|
|
452
|
+
mm(keyboardBounds.z + keyboardBounds.d / 2),
|
|
453
|
+
);
|
|
454
|
+
grille.renderOrder = 2;
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
// ── Trackpad and front lip ──────────────────────────────────────────
|
|
459
|
+
const trackpadCenterZ =
|
|
460
|
+
keyboardBounds.z + keyboardBounds.d + TRACKPAD.gap + TRACKPAD.h / 2;
|
|
461
|
+
const trackpad = add(
|
|
462
|
+
"laptop-trackpad",
|
|
463
|
+
new THREE.Mesh(
|
|
464
|
+
createFlatRoundedRect(mm(TRACKPAD.w), mm(TRACKPAD.h), mm(TRACKPAD.corner)),
|
|
465
|
+
materials.trackpad,
|
|
466
|
+
),
|
|
467
|
+
);
|
|
468
|
+
trackpad.position.set(0, mm(0.4), mm(trackpadCenterZ));
|
|
469
|
+
|
|
470
|
+
const notchGeometry = new THREE.CylinderGeometry(
|
|
471
|
+
mm(14),
|
|
472
|
+
mm(14),
|
|
473
|
+
mm(1.4),
|
|
474
|
+
48,
|
|
475
|
+
1,
|
|
476
|
+
false,
|
|
477
|
+
Math.PI / 2,
|
|
478
|
+
Math.PI,
|
|
479
|
+
);
|
|
480
|
+
notchGeometry.scale(1, 1, 0.22);
|
|
481
|
+
const thumbNotch = add(
|
|
482
|
+
"laptop-thumb-notch",
|
|
483
|
+
new THREE.Mesh(notchGeometry, materials.hinge),
|
|
484
|
+
);
|
|
485
|
+
thumbNotch.position.set(0, -mm(0.6), mm(BASE.d / 2 + 0.25));
|
|
486
|
+
|
|
487
|
+
// ── Feet ─────────────────────────────────────────────────────────────
|
|
488
|
+
const footGeometry = new THREE.CylinderGeometry(mm(6), mm(6.5), mm(1.3), 32);
|
|
489
|
+
for (const x of [-1, 1]) {
|
|
490
|
+
for (const z of [-1, 1]) {
|
|
491
|
+
const foot = add("laptop-foot", new THREE.Mesh(footGeometry, materials.rubber));
|
|
492
|
+
foot.position.set(
|
|
493
|
+
x * mm(BASE.w / 2 - 24),
|
|
494
|
+
-mm(BASE.t) - mm(0.5),
|
|
495
|
+
z * mm(BASE.d / 2 - 24),
|
|
496
|
+
);
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
// ── Hinge and lid ───────────────────────────────────────────────────
|
|
501
|
+
const hingeZ = -mm(BASE.d / 2) + mm(3.2);
|
|
502
|
+
const hingeY = mm(1.2);
|
|
503
|
+
const hinge = add(
|
|
504
|
+
"laptop-hinge",
|
|
505
|
+
new THREE.Mesh(
|
|
506
|
+
new THREE.CylinderGeometry(mm(3.4), mm(3.4), mm(BASE.w - 72), 32).rotateZ(
|
|
507
|
+
Math.PI / 2,
|
|
508
|
+
),
|
|
509
|
+
materials.hinge,
|
|
510
|
+
),
|
|
511
|
+
);
|
|
512
|
+
hinge.position.set(0, -mm(1.8), hingeZ - mm(1.4));
|
|
513
|
+
|
|
514
|
+
const lid = new THREE.Group();
|
|
515
|
+
lid.name = "laptop-lid-pivot";
|
|
516
|
+
lid.position.set(0, hingeY, hingeZ);
|
|
517
|
+
root.add(lid);
|
|
518
|
+
|
|
519
|
+
const lidBevel = mm(0.5);
|
|
520
|
+
const lidGeometry = createRoundedExtrudedGeometry(
|
|
521
|
+
mm(BASE.w),
|
|
522
|
+
mm(LID.h),
|
|
523
|
+
mm(LID.corner),
|
|
524
|
+
mm(LID.t) - lidBevel * 2,
|
|
525
|
+
lidBevel,
|
|
526
|
+
lidBevel,
|
|
527
|
+
);
|
|
528
|
+
const lidShell = add(
|
|
529
|
+
"laptop-lid",
|
|
530
|
+
new THREE.Mesh(lidGeometry, materials.aluminum),
|
|
531
|
+
lid,
|
|
532
|
+
);
|
|
533
|
+
lidShell.position.set(0, mm(LID.h / 2), -mm(LID.t / 2));
|
|
534
|
+
|
|
535
|
+
const glass = add(
|
|
536
|
+
"laptop-display-glass",
|
|
537
|
+
new THREE.Mesh(
|
|
538
|
+
createRoundedPlaneGeometry(
|
|
539
|
+
mm(BASE.w - LID.glassInset * 2),
|
|
540
|
+
mm(LID.h - LID.glassInset * 2),
|
|
541
|
+
mm(LID.corner - LID.glassInset),
|
|
542
|
+
),
|
|
543
|
+
materials.glass,
|
|
544
|
+
),
|
|
545
|
+
lid,
|
|
546
|
+
);
|
|
547
|
+
glass.position.set(0, mm(LID.h / 2), mm(0.25));
|
|
548
|
+
|
|
549
|
+
const screenWidth = BASE.w - LID.bezelSide * 2;
|
|
550
|
+
const screenHeight = LID.h - LID.bezelTop - LID.bezelBottom;
|
|
551
|
+
const screen = add(
|
|
552
|
+
"display-surface",
|
|
553
|
+
new THREE.Mesh(
|
|
554
|
+
createRoundedPlaneGeometry(mm(screenWidth), mm(screenHeight), mm(4.2)),
|
|
555
|
+
options.screenMaterial ?? materials.screenOff,
|
|
556
|
+
),
|
|
557
|
+
lid,
|
|
558
|
+
);
|
|
559
|
+
screen.position.set(0, mm(LID.bezelBottom + screenHeight / 2), mm(0.5));
|
|
560
|
+
screen.castShadow = false;
|
|
561
|
+
|
|
562
|
+
const notch = add(
|
|
563
|
+
"laptop-camera-notch",
|
|
564
|
+
new THREE.Mesh(
|
|
565
|
+
createRoundedPlaneGeometry(mm(LID.notch.w), mm(LID.notch.h + 4), mm(2.6)),
|
|
566
|
+
materials.notch,
|
|
567
|
+
),
|
|
568
|
+
lid,
|
|
569
|
+
);
|
|
570
|
+
notch.position.set(
|
|
571
|
+
0,
|
|
572
|
+
mm(LID.bezelBottom + screenHeight - LID.notch.h / 2 + 2),
|
|
573
|
+
mm(0.75),
|
|
574
|
+
);
|
|
575
|
+
const lens = add(
|
|
576
|
+
"laptop-camera-lens",
|
|
577
|
+
new THREE.Mesh(new THREE.CircleGeometry(mm(1.1), 24), materials.lens),
|
|
578
|
+
lid,
|
|
579
|
+
);
|
|
580
|
+
lens.position.set(0, mm(LID.bezelBottom + screenHeight + 2), mm(0.85));
|
|
581
|
+
|
|
582
|
+
const logo = add(
|
|
583
|
+
"laptop-lid-logo",
|
|
584
|
+
new THREE.Mesh(createLogoGeometry(mm(26)), materials.logo),
|
|
585
|
+
lid,
|
|
586
|
+
);
|
|
587
|
+
logo.rotation.y = Math.PI;
|
|
588
|
+
logo.position.set(0, mm(LID.h * 0.53), -mm(LID.t) - mm(0.3));
|
|
589
|
+
|
|
590
|
+
setMacbookLidAngle(root, options.lidAngle ?? DEFAULT_LAPTOP_LID_ANGLE);
|
|
591
|
+
return root;
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
/** Works on clones too, since it looks the hinge up by name. */
|
|
595
|
+
export function setMacbookLidAngle(root: THREE.Object3D, degrees: number) {
|
|
596
|
+
const lid = root.getObjectByName("laptop-lid-pivot");
|
|
597
|
+
if (!lid) return;
|
|
598
|
+
const clamped = THREE.MathUtils.clamp(degrees, 0, 140);
|
|
599
|
+
lid.rotation.x = THREE.MathUtils.degToRad(90 - clamped);
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
export function isMacbookModel(root: THREE.Object3D) {
|
|
603
|
+
return Boolean(root.getObjectByName("laptop-lid-pivot"));
|
|
604
|
+
}
|