agentcut 0.2.25 → 0.2.27

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 (127) hide show
  1. package/README.md +177 -148
  2. package/dist/config.d.ts +0 -1
  3. package/dist/config.js +0 -5
  4. package/dist/config.js.map +1 -1
  5. package/dist/studio/agents/claude.js +3 -2
  6. package/dist/studio/agents/claude.js.map +1 -1
  7. package/dist/studio/chat.js +1 -1
  8. package/dist/studio/chat.js.map +1 -1
  9. package/dist/studio/cli.js +40 -21
  10. package/dist/studio/cli.js.map +1 -1
  11. package/dist/studio/download.d.ts +24 -0
  12. package/dist/studio/download.js +234 -0
  13. package/dist/studio/download.js.map +1 -0
  14. package/dist/studio/host.d.ts +1 -2
  15. package/dist/studio/host.js +36 -8
  16. package/dist/studio/host.js.map +1 -1
  17. package/dist/studio/housekeeping.d.ts +2 -2
  18. package/dist/studio/housekeeping.js +18 -17
  19. package/dist/studio/housekeeping.js.map +1 -1
  20. package/dist/studio/mcp-guides.js +1 -18
  21. package/dist/studio/mcp-guides.js.map +1 -1
  22. package/dist/studio/proc.js +16 -6
  23. package/dist/studio/proc.js.map +1 -1
  24. package/dist/studio/proxies.d.ts +4 -0
  25. package/dist/studio/proxies.js +15 -6
  26. package/dist/studio/proxies.js.map +1 -1
  27. package/dist/studio/release-cursor.js +21 -21
  28. package/dist/studio/release-video.js +10 -10
  29. package/dist/studio/schema.d.ts +0 -1
  30. package/dist/studio/schema.js +0 -1
  31. package/dist/studio/schema.js.map +1 -1
  32. package/dist/studio/tools.d.ts +0 -4
  33. package/dist/studio/tools.js +32 -31
  34. package/dist/studio/tools.js.map +1 -1
  35. package/dist/studio/voice/kokoro-catalog.d.ts +56 -28
  36. package/dist/studio/voice/kokoro-catalog.js +56 -28
  37. package/dist/studio/voice/kokoro-catalog.js.map +1 -1
  38. package/dist/studio/voice/ming-catalog.d.ts +19 -0
  39. package/dist/studio/voice/ming-catalog.js +40 -0
  40. package/dist/studio/voice/ming-catalog.js.map +1 -0
  41. package/dist/studio/voice/ming.d.ts +12 -0
  42. package/dist/studio/voice/ming.js +397 -0
  43. package/dist/studio/voice/ming.js.map +1 -0
  44. package/dist/studio/voice/previews.d.ts +5 -0
  45. package/dist/studio/voice/previews.js +50 -0
  46. package/dist/studio/voice/previews.js.map +1 -0
  47. package/dist/studio/voice/registry.js +2 -0
  48. package/dist/studio/voice/registry.js.map +1 -1
  49. package/dist/studio/voice.d.ts +1 -1
  50. package/dist/studio/voice.js +5 -6
  51. package/dist/studio/voice.js.map +1 -1
  52. package/package.json +56 -56
  53. package/template/AGENTS.md +14 -14
  54. package/template/components/README.md +70 -70
  55. package/template/components/before-after/BeforeAfter.tsx +89 -89
  56. package/template/components/catalog.ts +107 -107
  57. package/template/components/cinematic/Device3D.tsx +324 -324
  58. package/template/components/cinematic/devices3d/display-model.ts +184 -184
  59. package/template/components/cinematic/devices3d/iphone-model.ts +643 -643
  60. package/template/components/cinematic/devices3d/macbook-model.ts +608 -608
  61. package/template/components/cinematic/devices3d/models.ts +657 -657
  62. package/template/components/cinematic/devices3d/runtime.ts +267 -267
  63. package/template/components/cinematic/math.ts +100 -100
  64. package/template/components/color/grade-effect.ts +650 -650
  65. package/template/components/color/grade.ts +512 -512
  66. package/template/components/color/looks.ts +154 -154
  67. package/template/components/countdown/Countdown.tsx +166 -166
  68. package/template/components/dot-trace-title/DotTraceTitle.tsx +181 -181
  69. package/template/components/dot-trace-title/meta.json +51 -51
  70. package/template/components/generate/GenerateReveal.tsx +381 -381
  71. package/template/components/hook-card/HookCard.tsx +554 -554
  72. package/template/components/index.ts +199 -199
  73. package/template/components/lib.ts +191 -191
  74. package/template/components/line-diagram/LineDiagram.tsx +205 -205
  75. package/template/components/line-diagram/meta.json +215 -215
  76. package/template/components/list-card/ListCard.tsx +104 -104
  77. package/template/components/live-clip.ts +75 -75
  78. package/template/components/looks.tsx +1447 -1447
  79. package/template/components/loops/LoopCanvas.tsx +132 -132
  80. package/template/components/loops/engine.ts +184 -184
  81. package/template/components/loops/library.ts +667 -667
  82. package/template/components/loops/library2.ts +777 -777
  83. package/template/components/motion-loop/MotionLoop.tsx +37 -37
  84. package/template/components/motion-loop/meta.json +311 -311
  85. package/template/components/props.ts +73 -73
  86. package/template/components/quote-card/QuoteCard.tsx +71 -71
  87. package/template/components/style-layer.tsx +233 -233
  88. package/template/components/styles.ts +113 -113
  89. package/template/components/types.ts +66 -66
  90. package/template/components/word-pop/WordPop.tsx +59 -59
  91. package/template/components/word-stack/WordStack.tsx +122 -122
  92. package/template/presets/charcoal-sketch/PROMPT.md +48 -48
  93. package/template/presets/charcoal-sketch/scripts/duck_music.py +34 -34
  94. package/template/presets/punk-cut-paper/scenes/Motif.tsx +376 -376
  95. package/template/presets/punk-cut-paper/scenes/Photo.tsx +73 -73
  96. package/template/presets/punk-cut-paper/scenes/Ransom.tsx +119 -119
  97. package/template/runtime/composition.tsx +1189 -1185
  98. package/template/runtime/helpers.tsx +230 -230
  99. package/template/runtime/index.tsx +22 -22
  100. package/template/runtime/types.ts +315 -315
  101. package/template/skill/SKILL.md +186 -351
  102. package/template/skill/references/broll.md +44 -44
  103. package/template/skill/references/browser-export.md +61 -61
  104. package/template/skill/references/cinematic.md +206 -206
  105. package/template/skill/references/color.md +79 -79
  106. package/template/skill/references/craft.md +54 -10
  107. package/template/skill/references/editing-styles.md +57 -57
  108. package/template/skill/references/feature-launch.md +5 -1
  109. package/template/skill/references/footage.md +72 -72
  110. package/template/skill/references/format.md +142 -142
  111. package/template/skill/references/how-to.md +0 -15
  112. package/template/skill/references/launch-direction.md +89 -0
  113. package/template/skill/references/loops.md +151 -151
  114. package/template/skill/references/mcp-external.md +19 -0
  115. package/template/skill/references/performance.md +93 -93
  116. package/template/skill/references/person-cutout.md +19 -19
  117. package/template/skill/references/presets.md +60 -60
  118. package/template/skill/references/product-launch.md +4 -1
  119. package/template/skill/references/release-capture.md +53 -0
  120. package/template/skill/references/sound.md +167 -155
  121. package/template/skill/references/style-spy.md +160 -160
  122. package/template/skill/references/website-howto.md +45 -45
  123. package/template/starter/.studio/chat.json +1 -1
  124. package/template/starter/layers.json +46 -46
  125. package/template/starter/notes.md +4 -4
  126. package/template/starter/project.json +13 -13
  127. package/template/starter/scenes/Title.tsx +38 -38
@@ -1,643 +1,643 @@
1
- import * as THREE from "three";
2
- import { SVGLoader } from "three/examples/jsm/loaders/SVGLoader.js";
3
-
4
- export interface IphoneVideoMockupOptions {
5
- screenMaterial?: THREE.Material;
6
- finishColor?: THREE.ColorRepresentation;
7
- }
8
-
9
- export interface IphoneVideoMockupRuntime {
10
- nodes: Record<string, THREE.Object3D>;
11
- meshes: Record<string, THREE.Mesh>;
12
- sockets: Record<string, THREE.Object3D>;
13
- colliders: Record<string, unknown>;
14
- destructionGroups: Record<string, THREE.Object3D[]>;
15
- }
16
-
17
- type IphoneVideoMockupGroup = THREE.Group & {
18
- userData: THREE.Group["userData"] & {
19
- sculptRuntime: IphoneVideoMockupRuntime;
20
- };
21
- };
22
-
23
- const PHONE_WIDTH = 0.695;
24
- const PHONE_HEIGHT = 1.455;
25
- // 149.6 × 71.5 × 7.95 mm, normalized to the model's 1.455-unit height.
26
- const PHONE_DEPTH = 0.065;
27
- const BODY_BEVEL_SIZE = 0.005;
28
- const BODY_BEVEL_THICKNESS = 0.006;
29
- const FRONT_Z = PHONE_DEPTH / 2 + BODY_BEVEL_THICKNESS + 0.003;
30
- const BACK_Z = -PHONE_DEPTH / 2 - BODY_BEVEL_THICKNESS - 0.003;
31
- const SIDE_RAIL_X = PHONE_WIDTH / 2 + BODY_BEVEL_SIZE;
32
- const SIDE_BUTTON_X = SIDE_RAIL_X + 0.0035;
33
-
34
- export function roundedRectPath(
35
- target: THREE.Shape | THREE.Path,
36
- width: number,
37
- height: number,
38
- radius: number,
39
- ) {
40
- const x = -width / 2;
41
- const y = -height / 2;
42
- const clampedRadius = Math.min(radius, width / 2, height / 2);
43
-
44
- target.moveTo(x + clampedRadius, y);
45
- target.lineTo(x + width - clampedRadius, y);
46
- target.quadraticCurveTo(x + width, y, x + width, y + clampedRadius);
47
- target.lineTo(x + width, y + height - clampedRadius);
48
- target.quadraticCurveTo(
49
- x + width,
50
- y + height,
51
- x + width - clampedRadius,
52
- y + height,
53
- );
54
- target.lineTo(x + clampedRadius, y + height);
55
- target.quadraticCurveTo(x, y + height, x, y + height - clampedRadius);
56
- target.lineTo(x, y + clampedRadius);
57
- target.quadraticCurveTo(x, y, x + clampedRadius, y);
58
- target.closePath();
59
- }
60
-
61
- export function createRoundedPlaneGeometry(
62
- width: number,
63
- height: number,
64
- radius: number,
65
- ) {
66
- const shape = new THREE.Shape();
67
- roundedRectPath(shape, width, height, radius);
68
- const geometry = new THREE.ShapeGeometry(shape, 48);
69
- geometry.computeBoundingBox();
70
- const bounds = geometry.boundingBox;
71
- const position = geometry.getAttribute("position");
72
- const uv = geometry.getAttribute("uv");
73
- if (bounds && position && uv) {
74
- const spanX = Math.max(0.0001, bounds.max.x - bounds.min.x);
75
- const spanY = Math.max(0.0001, bounds.max.y - bounds.min.y);
76
- for (let index = 0; index < position.count; index += 1) {
77
- uv.setXY(
78
- index,
79
- (position.getX(index) - bounds.min.x) / spanX,
80
- (position.getY(index) - bounds.min.y) / spanY,
81
- );
82
- }
83
- uv.needsUpdate = true;
84
- }
85
- return geometry;
86
- }
87
-
88
- export function createRoundedExtrudedGeometry(
89
- width: number,
90
- height: number,
91
- radius: number,
92
- depth: number,
93
- bevelSize = 0.005,
94
- bevelThickness = 0.005,
95
- ) {
96
- const shape = new THREE.Shape();
97
- roundedRectPath(shape, width, height, radius);
98
- const geometry = new THREE.ExtrudeGeometry(shape, {
99
- depth,
100
- steps: 1,
101
- curveSegments: 48,
102
- bevelEnabled: true,
103
- bevelSegments: 4,
104
- bevelSize,
105
- bevelThickness,
106
- });
107
- geometry.center();
108
- geometry.computeVertexNormals();
109
- return geometry;
110
- }
111
-
112
- function createSideButtonGeometry(height: number) {
113
- const geometry = createRoundedExtrudedGeometry(
114
- 0.03,
115
- height,
116
- 0.015,
117
- 0.007,
118
- 0.0015,
119
- 0.0015,
120
- );
121
- geometry.rotateY(Math.PI / 2);
122
- return geometry;
123
- }
124
-
125
- export function createRoundedRingGeometry(
126
- outerWidth: number,
127
- outerHeight: number,
128
- outerRadius: number,
129
- innerWidth: number,
130
- innerHeight: number,
131
- innerRadius: number,
132
- ) {
133
- const shape = new THREE.Shape();
134
- roundedRectPath(shape, outerWidth, outerHeight, outerRadius);
135
- const hole = new THREE.Path();
136
- roundedRectPath(hole, innerWidth, innerHeight, innerRadius);
137
- shape.holes.push(hole);
138
- return new THREE.ShapeGeometry(shape, 56);
139
- }
140
-
141
- export const APPLE_MARK_SVG = `<svg viewBox="0 0 814 1000" xmlns="http://www.w3.org/2000/svg"><path d="M788.1 340.9c-5.8 4.5-108.2 62.2-108.2 190.5 0 148.4 130.3 200.9 134.2 202.2-.6 3.2-20.7 71.9-68.7 141.9-42.8 61.6-87.5 123.1-155.5 123.1s-85.5-39.5-164-39.5c-76.5 0-103.7 40.8-165.9 40.8s-105.6-57-155.5-127C46.7 790.7 0 663 0 541.8c0-194.4 126.4-297.5 250.8-297.5 66.1 0 121.2 43.4 162.7 43.4 39.5 0 101.1-46 176.3-46 28.5 0 130.9 2.6 198.3 99.2zm-234-181.5c31.1-36.9 53.1-88.1 53.1-139.3 0-7.1-.6-14.3-1.9-20.1-50.6 1.9-110.8 33.7-147.1 75.8-28.5 32.4-55.1 83.6-55.1 135.5 0 7.8 1.3 15.6 1.9 18.1 3.2.6 8.4 1.3 13.6 1.3 45.4 0 102.5-30.4 135.5-71.3z"/></svg>`;
142
-
143
- function createRearMarkGeometry() {
144
- const svg = new SVGLoader().parse(APPLE_MARK_SVG);
145
- const shapes = svg.paths.flatMap((path) => SVGLoader.createShapes(path));
146
- const geometry = new THREE.ShapeGeometry(shapes, 48);
147
- geometry.center();
148
- // SVG coordinates grow downward; invert Y so the leaf sits above the mark.
149
- geometry.scale(0.00019, -0.00019, 1);
150
- return geometry;
151
- }
152
-
153
- function createFinishPalette(finishColor: THREE.ColorRepresentation) {
154
- const base = new THREE.Color(finishColor);
155
- const black = new THREE.Color(0x000000);
156
- const { l: lightness, s: saturation } = base.getHSL({ h: 0, s: 0, l: 0 });
157
- const isDark = lightness < 0.48;
158
- const logoColorByFinish: Partial<Record<number, number>> = {
159
- 0xc5a4df: 0xddcbe7,
160
- 0x829dce: 0xa9b9d9,
161
- 0xd9dad6: 0xc9cac6,
162
- 0x6a6a6a: 0x555657,
163
- };
164
- const calibratedLogoColor = logoColorByFinish[base.getHex()];
165
-
166
- return {
167
- frame: base.clone().lerp(black, isDark ? 0.08 : 0.12),
168
- rearGlass: isDark
169
- ? base.clone().lerp(black, 0.58)
170
- : base.clone().offsetHSL(0, 0.12, -0.025),
171
- camera: base.clone().lerp(black, isDark ? 0.68 : 0.22),
172
- seam: base.clone().lerp(black, isDark ? 0.62 : 0.38),
173
- logo:
174
- calibratedLogoColor !== undefined
175
- ? new THREE.Color(calibratedLogoColor)
176
- : isDark
177
- ? base.clone().lerp(black, 0.35)
178
- : saturation < 0.08
179
- ? base.clone().lerp(black, 0.12)
180
- : base.clone().offsetHSL(0, -0.04, -0.04),
181
- };
182
- }
183
-
184
- function createPhysicalMaterials(finishColor: THREE.ColorRepresentation) {
185
- const finish = createFinishPalette(finishColor);
186
-
187
- return {
188
- frame: new THREE.MeshPhysicalMaterial({
189
- color: finish.frame,
190
- roughness: 0.27,
191
- metalness: 0.86,
192
- clearcoat: 0.18,
193
- clearcoatRoughness: 0.22,
194
- }),
195
- bezel: new THREE.MeshPhysicalMaterial({
196
- color: 0x07080a,
197
- roughness: 0.18,
198
- metalness: 0.06,
199
- clearcoat: 0.45,
200
- clearcoatRoughness: 0.12,
201
- side: THREE.DoubleSide,
202
- }),
203
- screen: new THREE.MeshPhysicalMaterial({
204
- color: 0x252b35,
205
- roughness: 0.1,
206
- metalness: 0,
207
- clearcoat: 0.85,
208
- clearcoatRoughness: 0.06,
209
- side: THREE.DoubleSide,
210
- }),
211
- rearGlass: new THREE.MeshPhysicalMaterial({
212
- color: finish.rearGlass,
213
- roughness: 0.38,
214
- metalness: 0.08,
215
- clearcoat: 0.25,
216
- clearcoatRoughness: 0.3,
217
- side: THREE.DoubleSide,
218
- }),
219
- camera: new THREE.MeshPhysicalMaterial({
220
- color: finish.camera,
221
- roughness: 0.2,
222
- metalness: 0.52,
223
- clearcoat: 0.32,
224
- clearcoatRoughness: 0.12,
225
- }),
226
- lensRing: new THREE.MeshPhysicalMaterial({
227
- color: 0x77787c,
228
- roughness: 0.2,
229
- metalness: 0.82,
230
- clearcoat: 0.22,
231
- clearcoatRoughness: 0.12,
232
- }),
233
- lensHousing: new THREE.MeshPhysicalMaterial({
234
- color: 0x0d0e11,
235
- roughness: 0.16,
236
- metalness: 0.28,
237
- clearcoat: 0.48,
238
- clearcoatRoughness: 0.08,
239
- side: THREE.DoubleSide,
240
- }),
241
- cameraShadow: new THREE.MeshBasicMaterial({
242
- color: 0x000000,
243
- transparent: true,
244
- opacity: 0.16,
245
- depthWrite: false,
246
- side: THREE.DoubleSide,
247
- }),
248
- lens: new THREE.MeshPhysicalMaterial({
249
- color: 0x090d1a,
250
- roughness: 0.035,
251
- metalness: 0.12,
252
- clearcoat: 1,
253
- clearcoatRoughness: 0.025,
254
- iridescence: 0.32,
255
- iridescenceIOR: 1.45,
256
- side: THREE.DoubleSide,
257
- }),
258
- lensDome: new THREE.MeshPhysicalMaterial({
259
- color: 0x111a31,
260
- roughness: 0.025,
261
- metalness: 0,
262
- transmission: 0.32,
263
- thickness: 0.022,
264
- ior: 1.52,
265
- clearcoat: 1,
266
- clearcoatRoughness: 0.012,
267
- iridescence: 0.48,
268
- iridescenceIOR: 1.42,
269
- transparent: true,
270
- opacity: 0.72,
271
- depthWrite: false,
272
- }),
273
- opticalHighlight: new THREE.MeshBasicMaterial({
274
- color: 0xb7c9ff,
275
- transparent: true,
276
- opacity: 0.62,
277
- depthWrite: false,
278
- side: THREE.DoubleSide,
279
- }),
280
- flash: new THREE.MeshPhysicalMaterial({
281
- color: 0xd8d6d0,
282
- emissive: 0x55534f,
283
- emissiveIntensity: 0.015,
284
- roughness: 0.11,
285
- transmission: 0.25,
286
- thickness: 0.012,
287
- ior: 1.46,
288
- clearcoat: 1,
289
- clearcoatRoughness: 0.025,
290
- transparent: true,
291
- opacity: 0.9,
292
- side: THREE.DoubleSide,
293
- }),
294
- flashHighlight: new THREE.MeshBasicMaterial({
295
- color: 0xffffff,
296
- transparent: true,
297
- opacity: 0.9,
298
- depthWrite: false,
299
- side: THREE.DoubleSide,
300
- }),
301
- seam: new THREE.MeshStandardMaterial({
302
- color: finish.seam,
303
- roughness: 0.6,
304
- metalness: 0.25,
305
- }),
306
- logo: new THREE.MeshBasicMaterial({
307
- color: finish.logo,
308
- side: THREE.DoubleSide,
309
- toneMapped: false,
310
- }),
311
- };
312
- }
313
-
314
- export function createIphoneVideoMockupModel(
315
- options: IphoneVideoMockupOptions = {},
316
- ): IphoneVideoMockupGroup {
317
- const root = new THREE.Group() as IphoneVideoMockupGroup;
318
- root.name = "Blank-screen iPhone video mockup";
319
-
320
- const nodes: Record<string, THREE.Object3D> = { root };
321
- const meshes: Record<string, THREE.Mesh> = {};
322
- const sockets: Record<string, THREE.Object3D> = {};
323
- const materials = createPhysicalMaterials(
324
- options.finishColor ?? new THREE.Color(0x6a6a6a),
325
- );
326
-
327
- const registerMesh = (
328
- id: string,
329
- mesh: THREE.Mesh,
330
- parent: THREE.Object3D = root,
331
- ) => {
332
- mesh.name = id;
333
- mesh.castShadow = true;
334
- mesh.receiveShadow = true;
335
- parent.add(mesh);
336
- meshes[id] = mesh;
337
- nodes[id] = mesh;
338
- return mesh;
339
- };
340
-
341
- const body = registerMesh(
342
- "phone-body",
343
- new THREE.Mesh(
344
- createRoundedExtrudedGeometry(
345
- PHONE_WIDTH,
346
- PHONE_HEIGHT,
347
- 0.13,
348
- PHONE_DEPTH,
349
- BODY_BEVEL_SIZE,
350
- BODY_BEVEL_THICKNESS,
351
- ),
352
- materials.frame,
353
- ),
354
- );
355
-
356
- const rearPanel = registerMesh(
357
- "rear-glass-panel",
358
- new THREE.Mesh(
359
- createRoundedPlaneGeometry(0.688, 1.442, 0.125),
360
- materials.rearGlass,
361
- ),
362
- );
363
- rearPanel.position.z = BACK_Z;
364
- rearPanel.rotation.y = Math.PI;
365
-
366
- const screenSurface = registerMesh(
367
- "display-surface",
368
- new THREE.Mesh(
369
- createRoundedPlaneGeometry(0.655, 1.395, 0.096),
370
- options.screenMaterial ?? materials.screen,
371
- ),
372
- );
373
- screenSurface.position.z = FRONT_Z + 0.001;
374
-
375
- const screenSocket = new THREE.Object3D();
376
- screenSocket.name = "video-texture-socket";
377
- screenSocket.position.copy(screenSurface.position);
378
- root.add(screenSocket);
379
- sockets.videoSurface = screenSocket;
380
- nodes[screenSocket.name] = screenSocket;
381
-
382
- const bezel = registerMesh(
383
- "screen-bezel",
384
- new THREE.Mesh(
385
- createRoundedRingGeometry(0.683, 1.427, 0.112, 0.655, 1.395, 0.096),
386
- materials.bezel,
387
- ),
388
- );
389
- bezel.position.z = FRONT_Z + 0.004;
390
-
391
- const island = registerMesh(
392
- "sensor-island",
393
- new THREE.Mesh(
394
- createRoundedPlaneGeometry(0.17, 0.052, 0.026),
395
- materials.bezel,
396
- ),
397
- );
398
- island.position.set(0, 0.605, FRONT_Z + 0.006);
399
-
400
- const cameraAssembly = new THREE.Group();
401
- cameraAssembly.name = "camera-assembly";
402
- // Positive model X reads as the viewer's left when the phone is inspected
403
- // from behind, matching the reference camera placement.
404
- cameraAssembly.position.set(0.22, 0.529, BACK_Z - 0.004);
405
- root.add(cameraAssembly);
406
- nodes[cameraAssembly.name] = cameraAssembly;
407
-
408
- for (const [index, shadow] of [
409
- { width: 0.18, height: 0.324, opacity: 0.2 },
410
- { width: 0.19, height: 0.336, opacity: 0.09 },
411
- ].entries()) {
412
- const shadowMaterial = materials.cameraShadow.clone();
413
- shadowMaterial.opacity = shadow.opacity;
414
- const cameraHalo = registerMesh(
415
- `camera-module-shadow-${index + 1}`,
416
- new THREE.Mesh(
417
- createRoundedPlaneGeometry(
418
- shadow.width,
419
- shadow.height,
420
- shadow.width / 2,
421
- ),
422
- shadowMaterial,
423
- ),
424
- cameraAssembly,
425
- );
426
- cameraHalo.position.set(
427
- -0.009 - index * 0.007,
428
- -0.012 - index * 0.008,
429
- 0.007 + index * 0.001,
430
- );
431
- cameraHalo.rotation.y = Math.PI;
432
- cameraHalo.renderOrder = -2 - index;
433
- }
434
-
435
- const cameraPlateau = registerMesh(
436
- "camera-plateau",
437
- new THREE.Mesh(
438
- createRoundedExtrudedGeometry(0.162, 0.31, 0.081, 0.012),
439
- materials.camera,
440
- ),
441
- cameraAssembly,
442
- );
443
-
444
- const lensRingGeometry = new THREE.TorusGeometry(0.0605, 0.0035, 24, 72);
445
- const lensHousingGeometry = new THREE.RingGeometry(0.0435, 0.057, 64);
446
- const lensGlassGeometry = new THREE.CircleGeometry(0.043, 64);
447
- const lensDomeGeometry = new THREE.SphereGeometry(0.042, 48, 24);
448
- lensDomeGeometry.scale(1, 1, 0.18);
449
- const lensHighlightGeometry = new THREE.TorusGeometry(
450
- 0.031,
451
- 0.0021,
452
- 8,
453
- 36,
454
- Math.PI * 0.62,
455
- );
456
-
457
- for (const [index, localY] of [0.076, -0.076].entries()) {
458
- const lensModule = new THREE.Group();
459
- lensModule.name = `lens-module-${index + 1}`;
460
- lensModule.position.set(0, localY, -0.017);
461
- cameraAssembly.add(lensModule);
462
- nodes[lensModule.name] = lensModule;
463
-
464
- const outerRing = registerMesh(
465
- `lens-${index + 1}-outer-ring`,
466
- new THREE.Mesh(lensRingGeometry, materials.lensRing),
467
- lensModule,
468
- );
469
- const innerRing = registerMesh(
470
- `lens-${index + 1}-inner-ring`,
471
- new THREE.Mesh(lensHousingGeometry, materials.lensHousing),
472
- lensModule,
473
- );
474
- innerRing.position.z = -0.003;
475
- const lensGlass = registerMesh(
476
- `lens-${index + 1}-glass`,
477
- new THREE.Mesh(lensGlassGeometry, materials.lens),
478
- lensModule,
479
- );
480
- lensGlass.position.z = -0.006;
481
- const lensDome = registerMesh(
482
- `lens-${index + 1}-glass-dome`,
483
- new THREE.Mesh(lensDomeGeometry, materials.lensDome),
484
- lensModule,
485
- );
486
- lensDome.position.z = -0.009;
487
- const lensHighlight = registerMesh(
488
- `lens-${index + 1}-reflection-arc`,
489
- new THREE.Mesh(lensHighlightGeometry, materials.opticalHighlight),
490
- lensModule,
491
- );
492
- lensHighlight.position.z = -0.014;
493
- lensHighlight.rotation.z = 2.18;
494
- lensHighlight.renderOrder = 4;
495
- outerRing.renderOrder = 2;
496
- }
497
-
498
- const flashAssembly = new THREE.Group();
499
- flashAssembly.name = "rear-flash-assembly";
500
- flashAssembly.position.set(0.055, 0.529, BACK_Z - 0.008);
501
- root.add(flashAssembly);
502
- nodes[flashAssembly.name] = flashAssembly;
503
-
504
- const flashShadow = registerMesh(
505
- "rear-flash-shadow",
506
- new THREE.Mesh(new THREE.CircleGeometry(0.03, 48), materials.cameraShadow),
507
- flashAssembly,
508
- );
509
- flashShadow.position.z = 0.004;
510
- flashShadow.rotation.y = Math.PI;
511
-
512
- const flash = registerMesh(
513
- "rear-flash",
514
- new THREE.Mesh(new THREE.CircleGeometry(0.027, 48), materials.flash),
515
- flashAssembly,
516
- );
517
- flash.position.z = -0.009;
518
- flash.rotation.y = Math.PI;
519
-
520
- const flashHighlight = registerMesh(
521
- "rear-flash-reflection",
522
- new THREE.Mesh(
523
- new THREE.CircleGeometry(0.008, 24),
524
- materials.flashHighlight,
525
- ),
526
- flashAssembly,
527
- );
528
- flashHighlight.position.set(0.008, 0.009, -0.012);
529
- flashHighlight.scale.set(0.58, 1, 1);
530
- flashHighlight.rotation.y = Math.PI;
531
- flashHighlight.renderOrder = 4;
532
-
533
- const rearMark = registerMesh(
534
- "rear-logo",
535
- new THREE.Mesh(createRearMarkGeometry(), materials.logo),
536
- );
537
- rearMark.position.set(0, -0.015, BACK_Z - 0.004);
538
- rearMark.rotation.y = Math.PI;
539
-
540
- const addButton = (
541
- id: string,
542
- side: "left" | "right",
543
- y: number,
544
- height: number,
545
- ) => {
546
- const button = registerMesh(
547
- id,
548
- new THREE.Mesh(createSideButtonGeometry(height), materials.frame),
549
- );
550
- button.position.set(side === "left" ? -SIDE_BUTTON_X : SIDE_BUTTON_X, y, 0);
551
- return button;
552
- };
553
-
554
- addButton("left-action-button", "left", 0.44, 0.052);
555
- addButton("left-volume-up", "left", 0.285, 0.082);
556
- addButton("left-volume-down", "left", 0.155, 0.082);
557
- addButton("right-power-button", "right", 0.34, 0.122);
558
- addButton("right-camera-control", "right", -0.125, 0.086);
559
-
560
- const bottomHardwareY = -PHONE_HEIGHT / 2 - BODY_BEVEL_SIZE - 0.001;
561
- const portRimGeometry = createRoundedRingGeometry(
562
- 0.108,
563
- 0.03,
564
- 0.015,
565
- 0.086,
566
- 0.014,
567
- 0.007,
568
- );
569
- portRimGeometry.rotateX(Math.PI / 2);
570
- const portRim = registerMesh(
571
- "bottom-usb-c-rim",
572
- new THREE.Mesh(portRimGeometry, materials.camera),
573
- );
574
- portRim.position.y = bottomHardwareY;
575
-
576
- const portCavityGeometry = createRoundedPlaneGeometry(0.086, 0.014, 0.007);
577
- portCavityGeometry.rotateX(Math.PI / 2);
578
- const portCavity = registerMesh(
579
- "bottom-usb-c-cavity",
580
- new THREE.Mesh(portCavityGeometry, materials.bezel),
581
- );
582
- portCavity.position.y = bottomHardwareY - 0.0005;
583
-
584
- const speakerHoleGeometry = new THREE.CircleGeometry(0.0052, 20);
585
- speakerHoleGeometry.rotateX(Math.PI / 2);
586
- const bottomHolePositions = [
587
- -0.22, -0.193, -0.166, -0.139, 0.105, 0.128, 0.151, 0.174, 0.197, 0.22,
588
- ];
589
- for (const [index, x] of bottomHolePositions.entries()) {
590
- const speakerHole = registerMesh(
591
- `bottom-speaker-hole-${index + 1}`,
592
- new THREE.Mesh(speakerHoleGeometry, materials.bezel),
593
- );
594
- speakerHole.position.set(x, bottomHardwareY - 0.0005, 0);
595
- }
596
-
597
- for (const [index, y] of [0.58, -0.61].entries()) {
598
- for (const side of [-1, 1]) {
599
- const seam = registerMesh(
600
- `antenna-seam-${index}-${side}`,
601
- new THREE.Mesh(
602
- new THREE.BoxGeometry(0.0015, 0.004, 0.054),
603
- materials.seam,
604
- ),
605
- );
606
- seam.position.set(side * (SIDE_RAIL_X - 0.0004), y, 0);
607
- }
608
- }
609
-
610
- root.userData.sculptRuntime = {
611
- nodes,
612
- meshes,
613
- sockets,
614
- colliders: {
615
- body: {
616
- type: "rounded-box",
617
- size: [PHONE_WIDTH, PHONE_HEIGHT, PHONE_DEPTH],
618
- },
619
- screen: {
620
- type: "rounded-plane",
621
- size: [0.655, 1.395],
622
- },
623
- },
624
- destructionGroups: {
625
- body: [body],
626
- frontGlass: [screenSurface, bezel, island],
627
- camera: [cameraAssembly, cameraPlateau],
628
- },
629
- };
630
-
631
- return root;
632
- }
633
-
634
- export function setIphoneVideoMockupScreenMaterial(
635
- model: THREE.Group,
636
- material: THREE.Material,
637
- ) {
638
- const runtime = model.userData.sculptRuntime as
639
- | IphoneVideoMockupRuntime
640
- | undefined;
641
- const screen = runtime?.meshes["display-surface"];
642
- if (screen) screen.material = material;
643
- }
1
+ import * as THREE from "three";
2
+ import { SVGLoader } from "three/examples/jsm/loaders/SVGLoader.js";
3
+
4
+ export interface IphoneVideoMockupOptions {
5
+ screenMaterial?: THREE.Material;
6
+ finishColor?: THREE.ColorRepresentation;
7
+ }
8
+
9
+ export interface IphoneVideoMockupRuntime {
10
+ nodes: Record<string, THREE.Object3D>;
11
+ meshes: Record<string, THREE.Mesh>;
12
+ sockets: Record<string, THREE.Object3D>;
13
+ colliders: Record<string, unknown>;
14
+ destructionGroups: Record<string, THREE.Object3D[]>;
15
+ }
16
+
17
+ type IphoneVideoMockupGroup = THREE.Group & {
18
+ userData: THREE.Group["userData"] & {
19
+ sculptRuntime: IphoneVideoMockupRuntime;
20
+ };
21
+ };
22
+
23
+ const PHONE_WIDTH = 0.695;
24
+ const PHONE_HEIGHT = 1.455;
25
+ // 149.6 × 71.5 × 7.95 mm, normalized to the model's 1.455-unit height.
26
+ const PHONE_DEPTH = 0.065;
27
+ const BODY_BEVEL_SIZE = 0.005;
28
+ const BODY_BEVEL_THICKNESS = 0.006;
29
+ const FRONT_Z = PHONE_DEPTH / 2 + BODY_BEVEL_THICKNESS + 0.003;
30
+ const BACK_Z = -PHONE_DEPTH / 2 - BODY_BEVEL_THICKNESS - 0.003;
31
+ const SIDE_RAIL_X = PHONE_WIDTH / 2 + BODY_BEVEL_SIZE;
32
+ const SIDE_BUTTON_X = SIDE_RAIL_X + 0.0035;
33
+
34
+ export function roundedRectPath(
35
+ target: THREE.Shape | THREE.Path,
36
+ width: number,
37
+ height: number,
38
+ radius: number,
39
+ ) {
40
+ const x = -width / 2;
41
+ const y = -height / 2;
42
+ const clampedRadius = Math.min(radius, width / 2, height / 2);
43
+
44
+ target.moveTo(x + clampedRadius, y);
45
+ target.lineTo(x + width - clampedRadius, y);
46
+ target.quadraticCurveTo(x + width, y, x + width, y + clampedRadius);
47
+ target.lineTo(x + width, y + height - clampedRadius);
48
+ target.quadraticCurveTo(
49
+ x + width,
50
+ y + height,
51
+ x + width - clampedRadius,
52
+ y + height,
53
+ );
54
+ target.lineTo(x + clampedRadius, y + height);
55
+ target.quadraticCurveTo(x, y + height, x, y + height - clampedRadius);
56
+ target.lineTo(x, y + clampedRadius);
57
+ target.quadraticCurveTo(x, y, x + clampedRadius, y);
58
+ target.closePath();
59
+ }
60
+
61
+ export function createRoundedPlaneGeometry(
62
+ width: number,
63
+ height: number,
64
+ radius: number,
65
+ ) {
66
+ const shape = new THREE.Shape();
67
+ roundedRectPath(shape, width, height, radius);
68
+ const geometry = new THREE.ShapeGeometry(shape, 48);
69
+ geometry.computeBoundingBox();
70
+ const bounds = geometry.boundingBox;
71
+ const position = geometry.getAttribute("position");
72
+ const uv = geometry.getAttribute("uv");
73
+ if (bounds && position && uv) {
74
+ const spanX = Math.max(0.0001, bounds.max.x - bounds.min.x);
75
+ const spanY = Math.max(0.0001, bounds.max.y - bounds.min.y);
76
+ for (let index = 0; index < position.count; index += 1) {
77
+ uv.setXY(
78
+ index,
79
+ (position.getX(index) - bounds.min.x) / spanX,
80
+ (position.getY(index) - bounds.min.y) / spanY,
81
+ );
82
+ }
83
+ uv.needsUpdate = true;
84
+ }
85
+ return geometry;
86
+ }
87
+
88
+ export function createRoundedExtrudedGeometry(
89
+ width: number,
90
+ height: number,
91
+ radius: number,
92
+ depth: number,
93
+ bevelSize = 0.005,
94
+ bevelThickness = 0.005,
95
+ ) {
96
+ const shape = new THREE.Shape();
97
+ roundedRectPath(shape, width, height, radius);
98
+ const geometry = new THREE.ExtrudeGeometry(shape, {
99
+ depth,
100
+ steps: 1,
101
+ curveSegments: 48,
102
+ bevelEnabled: true,
103
+ bevelSegments: 4,
104
+ bevelSize,
105
+ bevelThickness,
106
+ });
107
+ geometry.center();
108
+ geometry.computeVertexNormals();
109
+ return geometry;
110
+ }
111
+
112
+ function createSideButtonGeometry(height: number) {
113
+ const geometry = createRoundedExtrudedGeometry(
114
+ 0.03,
115
+ height,
116
+ 0.015,
117
+ 0.007,
118
+ 0.0015,
119
+ 0.0015,
120
+ );
121
+ geometry.rotateY(Math.PI / 2);
122
+ return geometry;
123
+ }
124
+
125
+ export function createRoundedRingGeometry(
126
+ outerWidth: number,
127
+ outerHeight: number,
128
+ outerRadius: number,
129
+ innerWidth: number,
130
+ innerHeight: number,
131
+ innerRadius: number,
132
+ ) {
133
+ const shape = new THREE.Shape();
134
+ roundedRectPath(shape, outerWidth, outerHeight, outerRadius);
135
+ const hole = new THREE.Path();
136
+ roundedRectPath(hole, innerWidth, innerHeight, innerRadius);
137
+ shape.holes.push(hole);
138
+ return new THREE.ShapeGeometry(shape, 56);
139
+ }
140
+
141
+ export const APPLE_MARK_SVG = `<svg viewBox="0 0 814 1000" xmlns="http://www.w3.org/2000/svg"><path d="M788.1 340.9c-5.8 4.5-108.2 62.2-108.2 190.5 0 148.4 130.3 200.9 134.2 202.2-.6 3.2-20.7 71.9-68.7 141.9-42.8 61.6-87.5 123.1-155.5 123.1s-85.5-39.5-164-39.5c-76.5 0-103.7 40.8-165.9 40.8s-105.6-57-155.5-127C46.7 790.7 0 663 0 541.8c0-194.4 126.4-297.5 250.8-297.5 66.1 0 121.2 43.4 162.7 43.4 39.5 0 101.1-46 176.3-46 28.5 0 130.9 2.6 198.3 99.2zm-234-181.5c31.1-36.9 53.1-88.1 53.1-139.3 0-7.1-.6-14.3-1.9-20.1-50.6 1.9-110.8 33.7-147.1 75.8-28.5 32.4-55.1 83.6-55.1 135.5 0 7.8 1.3 15.6 1.9 18.1 3.2.6 8.4 1.3 13.6 1.3 45.4 0 102.5-30.4 135.5-71.3z"/></svg>`;
142
+
143
+ function createRearMarkGeometry() {
144
+ const svg = new SVGLoader().parse(APPLE_MARK_SVG);
145
+ const shapes = svg.paths.flatMap((path) => SVGLoader.createShapes(path));
146
+ const geometry = new THREE.ShapeGeometry(shapes, 48);
147
+ geometry.center();
148
+ // SVG coordinates grow downward; invert Y so the leaf sits above the mark.
149
+ geometry.scale(0.00019, -0.00019, 1);
150
+ return geometry;
151
+ }
152
+
153
+ function createFinishPalette(finishColor: THREE.ColorRepresentation) {
154
+ const base = new THREE.Color(finishColor);
155
+ const black = new THREE.Color(0x000000);
156
+ const { l: lightness, s: saturation } = base.getHSL({ h: 0, s: 0, l: 0 });
157
+ const isDark = lightness < 0.48;
158
+ const logoColorByFinish: Partial<Record<number, number>> = {
159
+ 0xc5a4df: 0xddcbe7,
160
+ 0x829dce: 0xa9b9d9,
161
+ 0xd9dad6: 0xc9cac6,
162
+ 0x6a6a6a: 0x555657,
163
+ };
164
+ const calibratedLogoColor = logoColorByFinish[base.getHex()];
165
+
166
+ return {
167
+ frame: base.clone().lerp(black, isDark ? 0.08 : 0.12),
168
+ rearGlass: isDark
169
+ ? base.clone().lerp(black, 0.58)
170
+ : base.clone().offsetHSL(0, 0.12, -0.025),
171
+ camera: base.clone().lerp(black, isDark ? 0.68 : 0.22),
172
+ seam: base.clone().lerp(black, isDark ? 0.62 : 0.38),
173
+ logo:
174
+ calibratedLogoColor !== undefined
175
+ ? new THREE.Color(calibratedLogoColor)
176
+ : isDark
177
+ ? base.clone().lerp(black, 0.35)
178
+ : saturation < 0.08
179
+ ? base.clone().lerp(black, 0.12)
180
+ : base.clone().offsetHSL(0, -0.04, -0.04),
181
+ };
182
+ }
183
+
184
+ function createPhysicalMaterials(finishColor: THREE.ColorRepresentation) {
185
+ const finish = createFinishPalette(finishColor);
186
+
187
+ return {
188
+ frame: new THREE.MeshPhysicalMaterial({
189
+ color: finish.frame,
190
+ roughness: 0.27,
191
+ metalness: 0.86,
192
+ clearcoat: 0.18,
193
+ clearcoatRoughness: 0.22,
194
+ }),
195
+ bezel: new THREE.MeshPhysicalMaterial({
196
+ color: 0x07080a,
197
+ roughness: 0.18,
198
+ metalness: 0.06,
199
+ clearcoat: 0.45,
200
+ clearcoatRoughness: 0.12,
201
+ side: THREE.DoubleSide,
202
+ }),
203
+ screen: new THREE.MeshPhysicalMaterial({
204
+ color: 0x252b35,
205
+ roughness: 0.1,
206
+ metalness: 0,
207
+ clearcoat: 0.85,
208
+ clearcoatRoughness: 0.06,
209
+ side: THREE.DoubleSide,
210
+ }),
211
+ rearGlass: new THREE.MeshPhysicalMaterial({
212
+ color: finish.rearGlass,
213
+ roughness: 0.38,
214
+ metalness: 0.08,
215
+ clearcoat: 0.25,
216
+ clearcoatRoughness: 0.3,
217
+ side: THREE.DoubleSide,
218
+ }),
219
+ camera: new THREE.MeshPhysicalMaterial({
220
+ color: finish.camera,
221
+ roughness: 0.2,
222
+ metalness: 0.52,
223
+ clearcoat: 0.32,
224
+ clearcoatRoughness: 0.12,
225
+ }),
226
+ lensRing: new THREE.MeshPhysicalMaterial({
227
+ color: 0x77787c,
228
+ roughness: 0.2,
229
+ metalness: 0.82,
230
+ clearcoat: 0.22,
231
+ clearcoatRoughness: 0.12,
232
+ }),
233
+ lensHousing: new THREE.MeshPhysicalMaterial({
234
+ color: 0x0d0e11,
235
+ roughness: 0.16,
236
+ metalness: 0.28,
237
+ clearcoat: 0.48,
238
+ clearcoatRoughness: 0.08,
239
+ side: THREE.DoubleSide,
240
+ }),
241
+ cameraShadow: new THREE.MeshBasicMaterial({
242
+ color: 0x000000,
243
+ transparent: true,
244
+ opacity: 0.16,
245
+ depthWrite: false,
246
+ side: THREE.DoubleSide,
247
+ }),
248
+ lens: new THREE.MeshPhysicalMaterial({
249
+ color: 0x090d1a,
250
+ roughness: 0.035,
251
+ metalness: 0.12,
252
+ clearcoat: 1,
253
+ clearcoatRoughness: 0.025,
254
+ iridescence: 0.32,
255
+ iridescenceIOR: 1.45,
256
+ side: THREE.DoubleSide,
257
+ }),
258
+ lensDome: new THREE.MeshPhysicalMaterial({
259
+ color: 0x111a31,
260
+ roughness: 0.025,
261
+ metalness: 0,
262
+ transmission: 0.32,
263
+ thickness: 0.022,
264
+ ior: 1.52,
265
+ clearcoat: 1,
266
+ clearcoatRoughness: 0.012,
267
+ iridescence: 0.48,
268
+ iridescenceIOR: 1.42,
269
+ transparent: true,
270
+ opacity: 0.72,
271
+ depthWrite: false,
272
+ }),
273
+ opticalHighlight: new THREE.MeshBasicMaterial({
274
+ color: 0xb7c9ff,
275
+ transparent: true,
276
+ opacity: 0.62,
277
+ depthWrite: false,
278
+ side: THREE.DoubleSide,
279
+ }),
280
+ flash: new THREE.MeshPhysicalMaterial({
281
+ color: 0xd8d6d0,
282
+ emissive: 0x55534f,
283
+ emissiveIntensity: 0.015,
284
+ roughness: 0.11,
285
+ transmission: 0.25,
286
+ thickness: 0.012,
287
+ ior: 1.46,
288
+ clearcoat: 1,
289
+ clearcoatRoughness: 0.025,
290
+ transparent: true,
291
+ opacity: 0.9,
292
+ side: THREE.DoubleSide,
293
+ }),
294
+ flashHighlight: new THREE.MeshBasicMaterial({
295
+ color: 0xffffff,
296
+ transparent: true,
297
+ opacity: 0.9,
298
+ depthWrite: false,
299
+ side: THREE.DoubleSide,
300
+ }),
301
+ seam: new THREE.MeshStandardMaterial({
302
+ color: finish.seam,
303
+ roughness: 0.6,
304
+ metalness: 0.25,
305
+ }),
306
+ logo: new THREE.MeshBasicMaterial({
307
+ color: finish.logo,
308
+ side: THREE.DoubleSide,
309
+ toneMapped: false,
310
+ }),
311
+ };
312
+ }
313
+
314
+ export function createIphoneVideoMockupModel(
315
+ options: IphoneVideoMockupOptions = {},
316
+ ): IphoneVideoMockupGroup {
317
+ const root = new THREE.Group() as IphoneVideoMockupGroup;
318
+ root.name = "Blank-screen iPhone video mockup";
319
+
320
+ const nodes: Record<string, THREE.Object3D> = { root };
321
+ const meshes: Record<string, THREE.Mesh> = {};
322
+ const sockets: Record<string, THREE.Object3D> = {};
323
+ const materials = createPhysicalMaterials(
324
+ options.finishColor ?? new THREE.Color(0x6a6a6a),
325
+ );
326
+
327
+ const registerMesh = (
328
+ id: string,
329
+ mesh: THREE.Mesh,
330
+ parent: THREE.Object3D = root,
331
+ ) => {
332
+ mesh.name = id;
333
+ mesh.castShadow = true;
334
+ mesh.receiveShadow = true;
335
+ parent.add(mesh);
336
+ meshes[id] = mesh;
337
+ nodes[id] = mesh;
338
+ return mesh;
339
+ };
340
+
341
+ const body = registerMesh(
342
+ "phone-body",
343
+ new THREE.Mesh(
344
+ createRoundedExtrudedGeometry(
345
+ PHONE_WIDTH,
346
+ PHONE_HEIGHT,
347
+ 0.13,
348
+ PHONE_DEPTH,
349
+ BODY_BEVEL_SIZE,
350
+ BODY_BEVEL_THICKNESS,
351
+ ),
352
+ materials.frame,
353
+ ),
354
+ );
355
+
356
+ const rearPanel = registerMesh(
357
+ "rear-glass-panel",
358
+ new THREE.Mesh(
359
+ createRoundedPlaneGeometry(0.688, 1.442, 0.125),
360
+ materials.rearGlass,
361
+ ),
362
+ );
363
+ rearPanel.position.z = BACK_Z;
364
+ rearPanel.rotation.y = Math.PI;
365
+
366
+ const screenSurface = registerMesh(
367
+ "display-surface",
368
+ new THREE.Mesh(
369
+ createRoundedPlaneGeometry(0.655, 1.395, 0.096),
370
+ options.screenMaterial ?? materials.screen,
371
+ ),
372
+ );
373
+ screenSurface.position.z = FRONT_Z + 0.001;
374
+
375
+ const screenSocket = new THREE.Object3D();
376
+ screenSocket.name = "video-texture-socket";
377
+ screenSocket.position.copy(screenSurface.position);
378
+ root.add(screenSocket);
379
+ sockets.videoSurface = screenSocket;
380
+ nodes[screenSocket.name] = screenSocket;
381
+
382
+ const bezel = registerMesh(
383
+ "screen-bezel",
384
+ new THREE.Mesh(
385
+ createRoundedRingGeometry(0.683, 1.427, 0.112, 0.655, 1.395, 0.096),
386
+ materials.bezel,
387
+ ),
388
+ );
389
+ bezel.position.z = FRONT_Z + 0.004;
390
+
391
+ const island = registerMesh(
392
+ "sensor-island",
393
+ new THREE.Mesh(
394
+ createRoundedPlaneGeometry(0.17, 0.052, 0.026),
395
+ materials.bezel,
396
+ ),
397
+ );
398
+ island.position.set(0, 0.605, FRONT_Z + 0.006);
399
+
400
+ const cameraAssembly = new THREE.Group();
401
+ cameraAssembly.name = "camera-assembly";
402
+ // Positive model X reads as the viewer's left when the phone is inspected
403
+ // from behind, matching the reference camera placement.
404
+ cameraAssembly.position.set(0.22, 0.529, BACK_Z - 0.004);
405
+ root.add(cameraAssembly);
406
+ nodes[cameraAssembly.name] = cameraAssembly;
407
+
408
+ for (const [index, shadow] of [
409
+ { width: 0.18, height: 0.324, opacity: 0.2 },
410
+ { width: 0.19, height: 0.336, opacity: 0.09 },
411
+ ].entries()) {
412
+ const shadowMaterial = materials.cameraShadow.clone();
413
+ shadowMaterial.opacity = shadow.opacity;
414
+ const cameraHalo = registerMesh(
415
+ `camera-module-shadow-${index + 1}`,
416
+ new THREE.Mesh(
417
+ createRoundedPlaneGeometry(
418
+ shadow.width,
419
+ shadow.height,
420
+ shadow.width / 2,
421
+ ),
422
+ shadowMaterial,
423
+ ),
424
+ cameraAssembly,
425
+ );
426
+ cameraHalo.position.set(
427
+ -0.009 - index * 0.007,
428
+ -0.012 - index * 0.008,
429
+ 0.007 + index * 0.001,
430
+ );
431
+ cameraHalo.rotation.y = Math.PI;
432
+ cameraHalo.renderOrder = -2 - index;
433
+ }
434
+
435
+ const cameraPlateau = registerMesh(
436
+ "camera-plateau",
437
+ new THREE.Mesh(
438
+ createRoundedExtrudedGeometry(0.162, 0.31, 0.081, 0.012),
439
+ materials.camera,
440
+ ),
441
+ cameraAssembly,
442
+ );
443
+
444
+ const lensRingGeometry = new THREE.TorusGeometry(0.0605, 0.0035, 24, 72);
445
+ const lensHousingGeometry = new THREE.RingGeometry(0.0435, 0.057, 64);
446
+ const lensGlassGeometry = new THREE.CircleGeometry(0.043, 64);
447
+ const lensDomeGeometry = new THREE.SphereGeometry(0.042, 48, 24);
448
+ lensDomeGeometry.scale(1, 1, 0.18);
449
+ const lensHighlightGeometry = new THREE.TorusGeometry(
450
+ 0.031,
451
+ 0.0021,
452
+ 8,
453
+ 36,
454
+ Math.PI * 0.62,
455
+ );
456
+
457
+ for (const [index, localY] of [0.076, -0.076].entries()) {
458
+ const lensModule = new THREE.Group();
459
+ lensModule.name = `lens-module-${index + 1}`;
460
+ lensModule.position.set(0, localY, -0.017);
461
+ cameraAssembly.add(lensModule);
462
+ nodes[lensModule.name] = lensModule;
463
+
464
+ const outerRing = registerMesh(
465
+ `lens-${index + 1}-outer-ring`,
466
+ new THREE.Mesh(lensRingGeometry, materials.lensRing),
467
+ lensModule,
468
+ );
469
+ const innerRing = registerMesh(
470
+ `lens-${index + 1}-inner-ring`,
471
+ new THREE.Mesh(lensHousingGeometry, materials.lensHousing),
472
+ lensModule,
473
+ );
474
+ innerRing.position.z = -0.003;
475
+ const lensGlass = registerMesh(
476
+ `lens-${index + 1}-glass`,
477
+ new THREE.Mesh(lensGlassGeometry, materials.lens),
478
+ lensModule,
479
+ );
480
+ lensGlass.position.z = -0.006;
481
+ const lensDome = registerMesh(
482
+ `lens-${index + 1}-glass-dome`,
483
+ new THREE.Mesh(lensDomeGeometry, materials.lensDome),
484
+ lensModule,
485
+ );
486
+ lensDome.position.z = -0.009;
487
+ const lensHighlight = registerMesh(
488
+ `lens-${index + 1}-reflection-arc`,
489
+ new THREE.Mesh(lensHighlightGeometry, materials.opticalHighlight),
490
+ lensModule,
491
+ );
492
+ lensHighlight.position.z = -0.014;
493
+ lensHighlight.rotation.z = 2.18;
494
+ lensHighlight.renderOrder = 4;
495
+ outerRing.renderOrder = 2;
496
+ }
497
+
498
+ const flashAssembly = new THREE.Group();
499
+ flashAssembly.name = "rear-flash-assembly";
500
+ flashAssembly.position.set(0.055, 0.529, BACK_Z - 0.008);
501
+ root.add(flashAssembly);
502
+ nodes[flashAssembly.name] = flashAssembly;
503
+
504
+ const flashShadow = registerMesh(
505
+ "rear-flash-shadow",
506
+ new THREE.Mesh(new THREE.CircleGeometry(0.03, 48), materials.cameraShadow),
507
+ flashAssembly,
508
+ );
509
+ flashShadow.position.z = 0.004;
510
+ flashShadow.rotation.y = Math.PI;
511
+
512
+ const flash = registerMesh(
513
+ "rear-flash",
514
+ new THREE.Mesh(new THREE.CircleGeometry(0.027, 48), materials.flash),
515
+ flashAssembly,
516
+ );
517
+ flash.position.z = -0.009;
518
+ flash.rotation.y = Math.PI;
519
+
520
+ const flashHighlight = registerMesh(
521
+ "rear-flash-reflection",
522
+ new THREE.Mesh(
523
+ new THREE.CircleGeometry(0.008, 24),
524
+ materials.flashHighlight,
525
+ ),
526
+ flashAssembly,
527
+ );
528
+ flashHighlight.position.set(0.008, 0.009, -0.012);
529
+ flashHighlight.scale.set(0.58, 1, 1);
530
+ flashHighlight.rotation.y = Math.PI;
531
+ flashHighlight.renderOrder = 4;
532
+
533
+ const rearMark = registerMesh(
534
+ "rear-logo",
535
+ new THREE.Mesh(createRearMarkGeometry(), materials.logo),
536
+ );
537
+ rearMark.position.set(0, -0.015, BACK_Z - 0.004);
538
+ rearMark.rotation.y = Math.PI;
539
+
540
+ const addButton = (
541
+ id: string,
542
+ side: "left" | "right",
543
+ y: number,
544
+ height: number,
545
+ ) => {
546
+ const button = registerMesh(
547
+ id,
548
+ new THREE.Mesh(createSideButtonGeometry(height), materials.frame),
549
+ );
550
+ button.position.set(side === "left" ? -SIDE_BUTTON_X : SIDE_BUTTON_X, y, 0);
551
+ return button;
552
+ };
553
+
554
+ addButton("left-action-button", "left", 0.44, 0.052);
555
+ addButton("left-volume-up", "left", 0.285, 0.082);
556
+ addButton("left-volume-down", "left", 0.155, 0.082);
557
+ addButton("right-power-button", "right", 0.34, 0.122);
558
+ addButton("right-camera-control", "right", -0.125, 0.086);
559
+
560
+ const bottomHardwareY = -PHONE_HEIGHT / 2 - BODY_BEVEL_SIZE - 0.001;
561
+ const portRimGeometry = createRoundedRingGeometry(
562
+ 0.108,
563
+ 0.03,
564
+ 0.015,
565
+ 0.086,
566
+ 0.014,
567
+ 0.007,
568
+ );
569
+ portRimGeometry.rotateX(Math.PI / 2);
570
+ const portRim = registerMesh(
571
+ "bottom-usb-c-rim",
572
+ new THREE.Mesh(portRimGeometry, materials.camera),
573
+ );
574
+ portRim.position.y = bottomHardwareY;
575
+
576
+ const portCavityGeometry = createRoundedPlaneGeometry(0.086, 0.014, 0.007);
577
+ portCavityGeometry.rotateX(Math.PI / 2);
578
+ const portCavity = registerMesh(
579
+ "bottom-usb-c-cavity",
580
+ new THREE.Mesh(portCavityGeometry, materials.bezel),
581
+ );
582
+ portCavity.position.y = bottomHardwareY - 0.0005;
583
+
584
+ const speakerHoleGeometry = new THREE.CircleGeometry(0.0052, 20);
585
+ speakerHoleGeometry.rotateX(Math.PI / 2);
586
+ const bottomHolePositions = [
587
+ -0.22, -0.193, -0.166, -0.139, 0.105, 0.128, 0.151, 0.174, 0.197, 0.22,
588
+ ];
589
+ for (const [index, x] of bottomHolePositions.entries()) {
590
+ const speakerHole = registerMesh(
591
+ `bottom-speaker-hole-${index + 1}`,
592
+ new THREE.Mesh(speakerHoleGeometry, materials.bezel),
593
+ );
594
+ speakerHole.position.set(x, bottomHardwareY - 0.0005, 0);
595
+ }
596
+
597
+ for (const [index, y] of [0.58, -0.61].entries()) {
598
+ for (const side of [-1, 1]) {
599
+ const seam = registerMesh(
600
+ `antenna-seam-${index}-${side}`,
601
+ new THREE.Mesh(
602
+ new THREE.BoxGeometry(0.0015, 0.004, 0.054),
603
+ materials.seam,
604
+ ),
605
+ );
606
+ seam.position.set(side * (SIDE_RAIL_X - 0.0004), y, 0);
607
+ }
608
+ }
609
+
610
+ root.userData.sculptRuntime = {
611
+ nodes,
612
+ meshes,
613
+ sockets,
614
+ colliders: {
615
+ body: {
616
+ type: "rounded-box",
617
+ size: [PHONE_WIDTH, PHONE_HEIGHT, PHONE_DEPTH],
618
+ },
619
+ screen: {
620
+ type: "rounded-plane",
621
+ size: [0.655, 1.395],
622
+ },
623
+ },
624
+ destructionGroups: {
625
+ body: [body],
626
+ frontGlass: [screenSurface, bezel, island],
627
+ camera: [cameraAssembly, cameraPlateau],
628
+ },
629
+ };
630
+
631
+ return root;
632
+ }
633
+
634
+ export function setIphoneVideoMockupScreenMaterial(
635
+ model: THREE.Group,
636
+ material: THREE.Material,
637
+ ) {
638
+ const runtime = model.userData.sculptRuntime as
639
+ | IphoneVideoMockupRuntime
640
+ | undefined;
641
+ const screen = runtime?.meshes["display-surface"];
642
+ if (screen) screen.material = material;
643
+ }