cozyclay 1.0.0 → 1.2.0

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 (94) hide show
  1. package/README.md +59 -24
  2. package/THIRD_PARTY_NOTICES.md +31 -0
  3. package/bin/cozyclay.mjs +105 -11
  4. package/dist/CNAME +1 -0
  5. package/dist/app/index.html +57 -0
  6. package/dist/assets/app-Cgpk2hwX.js +4803 -0
  7. package/dist/assets/app-DgZvaAE1.css +1 -0
  8. package/dist/favicon.ico +0 -0
  9. package/dist/icons/apple-touch-icon.png +0 -0
  10. package/dist/icons/icon-192.png +0 -0
  11. package/dist/icons/icon-32.png +0 -0
  12. package/dist/icons/icon-512.png +0 -0
  13. package/dist/icons/icon-maskable-512.png +0 -0
  14. package/dist/index.html +406 -5
  15. package/dist/manifest.webmanifest +42 -0
  16. package/dist/media/cozyclay-demo-poster.jpg +0 -0
  17. package/dist/media/cozyclay-logo.png +0 -0
  18. package/dist/robots.txt +4 -0
  19. package/dist/sitemap.xml +9 -0
  20. package/dist/sw.js +127 -0
  21. package/package.json +15 -3
  22. package/src/App.jsx +1393 -648
  23. package/src/ardy/client.js +5 -4
  24. package/src/ardy/mp4-duration.js +102 -0
  25. package/src/ardy/timeline-coordinates.js +11 -0
  26. package/src/ardy/timeline.jsx +528 -67
  27. package/src/ardy/waypoints.js +14 -9
  28. package/src/camera-block.js +60 -0
  29. package/src/camera-follow.js +49 -10
  30. package/src/camera-rail-schedule.js +176 -0
  31. package/src/controls.jsx +16 -2
  32. package/src/cuts.js +184 -0
  33. package/src/generation/client.js +56 -0
  34. package/src/generation/session.js +47 -0
  35. package/src/generation/shot-spec.js +40 -0
  36. package/src/generation/use-generation.js +55 -0
  37. package/src/hierarchy-model.js +9 -17
  38. package/src/hierarchy-panel.jsx +170 -23
  39. package/src/locale-toggle.jsx +18 -0
  40. package/src/locale.js +34 -0
  41. package/src/main.jsx +5 -0
  42. package/src/object-catalog.jsx +32 -3
  43. package/src/planview.jsx +174 -66
  44. package/src/pose-extract/browser.js +42 -0
  45. package/src/pose-extract/fit.js +194 -0
  46. package/src/pose-extract/index.js +53 -0
  47. package/src/pose-extract/keyframes.js +74 -0
  48. package/src/pose-extract/landmarks.js +162 -0
  49. package/src/poses.js +114 -0
  50. package/src/posestudio.jsx +75 -13
  51. package/src/pwa.js +42 -0
  52. package/src/result-modal.jsx +124 -0
  53. package/src/scenes.js +223 -0
  54. package/src/shot-authoring.js +204 -77
  55. package/src/shot.js +8 -4
  56. package/src/styles.css +839 -38
  57. package/src/ui.jsx +54 -5
  58. package/tools/ardy/BRIDGE.md +70 -4
  59. package/tools/ardy/README.md +55 -0
  60. package/tools/ardy/bridge.mjs +89 -389
  61. package/tools/ardy/cclay_constrained_generate.py +449 -0
  62. package/tools/ardy/cclay_motion_edit.py +74 -9
  63. package/tools/ardy/cclay_sequence_generate.py +68 -7
  64. package/tools/ardy/cclay_worker.py +304 -0
  65. package/tools/ardy/merge-text-encoder.py +160 -0
  66. package/tools/ardy/run-local.mjs +233 -0
  67. package/tools/ardy/runners/index.mjs +23 -0
  68. package/tools/ardy/runners/local.mjs +452 -0
  69. package/tools/ardy/runners/proc.mjs +125 -0
  70. package/tools/ardy/runners/remote.mjs +246 -0
  71. package/tools/ardy/setup-local.mjs +189 -0
  72. package/tools/ardy/setup-text-encoder-on-box.sh +93 -0
  73. package/tools/ardy/setup-text-encoder.py +296 -0
  74. package/tools/generation/README.md +29 -0
  75. package/tools/generation/bridge.mjs +149 -0
  76. package/tools/generation/job-store.mjs +51 -0
  77. package/tools/generation/providers/kling.mjs +76 -0
  78. package/tools/generation/providers/runway.mjs +101 -0
  79. package/tools/generation/providers/seedance.mjs +87 -0
  80. package/tools/generation/providers/shared.mjs +49 -0
  81. package/tools/generation/providers/veo.mjs +84 -0
  82. package/tools/metrics/archive-traffic.mjs +138 -0
  83. package/dist/assets/index-BW_S1YRy.js +0 -4395
  84. package/dist/assets/index-nRmmJgap.css +0 -1
  85. package/tools/ardy/__pycache__/cclay_sequence_generate.cpython-313.pyc +0 -0
  86. package/tools/ardy/out/gen-1786443326924-c6019e-generated.npz +0 -0
  87. package/tools/ardy/out/gen-1786443609325-0053db-generated.npz +0 -0
  88. package/tools/ardy/out/gen-1786443835628-749ed1-generated.npz +0 -0
  89. package/tools/ardy/out/gen-1786462605247-03cb19-generated.npz +0 -0
  90. package/tools/qa-browser.mjs +0 -84
  91. package/tools/qa-crop3.mjs +0 -22
  92. package/tools/qa-playview.mjs +0 -49
  93. package/tools/qa-screenshot.mjs +0 -24
  94. package/tools/qa-visual.mjs +0 -51
package/src/planview.jsx CHANGED
@@ -1,10 +1,12 @@
1
1
  import { useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
2
2
  import { useFrame } from "@react-three/fiber";
3
- import { Text } from "@react-three/drei";
3
+ import { Line, Text } from "@react-three/drei";
4
4
  import * as THREE from "three";
5
5
  import { aimAt } from "./controls.jsx";
6
6
  import { PLAN_LAYER } from "./dualview.jsx";
7
7
  import { objectSize } from "./scene-objects.js";
8
+ import { displayObjectLabel } from "./object-catalog.jsx";
9
+ import { ko } from "./locale.js";
8
10
 
9
11
  const ROOM_LIMIT = 11; // stay inside the set walls
10
12
  const ACTOR_LIMIT = 4; // matches the Subject sliders' range
@@ -13,6 +15,11 @@ const GRAB_R = 1.0; // the pick radius, well beyond the drawn disc
13
15
  const HANDLE_DIST = 1.25; // how far the facing handle sits from the centre
14
16
  const HANDLE_R = 0.14;
15
17
  const HANDLE_GRAB = 0.5;
18
+ const CAMERA_COLOR = "#007f9e";
19
+ const SUBJECT_ONE_COLOR = "#2457d6";
20
+ const SUBJECT_TWO_COLOR = "#d63b55";
21
+ const OBJECT_COLOR = "#c14f2c";
22
+ const SELECTED_COLOR = "#b77900";
16
23
 
17
24
  /** yaw that makes the character's local +Z face the given direction */
18
25
  const yawToward = (dx, dz) => Math.atan2(dx, dz);
@@ -56,9 +63,9 @@ function FrustumWedge({ fovDeg, active }) {
56
63
  return (
57
64
  <mesh geometry={geometry} position={[0, 0.02, 0]} renderOrder={8}>
58
65
  <meshBasicMaterial
59
- color="#4e9fb3"
66
+ color={CAMERA_COLOR}
60
67
  transparent
61
- opacity={active ? 0.32 : 0.18}
68
+ opacity={active ? 0.46 : 0.28}
62
69
  side={THREE.DoubleSide}
63
70
  depthWrite={false}
64
71
  depthTest={false}
@@ -109,11 +116,11 @@ function Puck({ color, dragging, turning, showBody = true, handleDist = HANDLE_D
109
116
 
110
117
  {/* stem: makes the handle read as attached to the puck, not as debris */}
111
118
  <mesh position={[0, 0.035, handleDist / 2]} rotation={[-Math.PI / 2, 0, 0]} renderOrder={9}>
112
- <planeGeometry args={[0.045, handleDist]} />
119
+ <planeGeometry args={[0.07, handleDist]} />
113
120
  <meshBasicMaterial
114
121
  color={color}
115
122
  transparent
116
- opacity={turning ? 0.9 : 0.35}
123
+ opacity={turning ? 1 : 0.68}
117
124
  depthWrite={false}
118
125
  depthTest={false}
119
126
  />
@@ -127,7 +134,7 @@ function Puck({ color, dragging, turning, showBody = true, handleDist = HANDLE_D
127
134
  <meshBasicMaterial
128
135
  color={color}
129
136
  transparent
130
- opacity={turning ? 0.85 : 0.38}
137
+ opacity={turning ? 1 : 0.72}
131
138
  depthWrite={false}
132
139
  depthTest={false}
133
140
  />
@@ -147,13 +154,13 @@ function PlanLabel({ text, color, offset = -0.72 }) {
147
154
  <Text
148
155
  position={[0, 0.05, offset]}
149
156
  rotation={[-Math.PI / 2, 0, 0]}
150
- fontSize={0.3}
157
+ fontSize={0.32}
151
158
  color={color}
152
159
  anchorX="center"
153
160
  anchorY="middle"
154
- outlineWidth={0.025}
161
+ outlineWidth={0.045}
155
162
  outlineColor="#0e0d10"
156
- outlineOpacity={0.72}
163
+ outlineOpacity={0.92}
157
164
  renderOrder={12}
158
165
  depthOffset={-1}
159
166
  >
@@ -164,6 +171,7 @@ function PlanLabel({ text, color, offset = -0.72 }) {
164
171
 
165
172
  function SceneObjectFootprint({ object, selected, dragging, turning }) {
166
173
  const { width, depth } = objectSize(object);
174
+ const objectLabel = displayObjectLabel(object.name).slice(0, 8);
167
175
  const handleDist = depth / 2 + 0.65;
168
176
  const rotation = (object.rot * Math.PI) / 180;
169
177
  return (
@@ -171,31 +179,98 @@ function SceneObjectFootprint({ object, selected, dragging, turning }) {
171
179
  <mesh position={[0, 0.032, 0]} rotation={[-Math.PI / 2, 0, 0]} renderOrder={10}>
172
180
  <planeGeometry args={[width, depth]} />
173
181
  <meshBasicMaterial
174
- color={selected ? "#e7b557" : "#c7836f"}
182
+ color={selected ? SELECTED_COLOR : OBJECT_COLOR}
175
183
  transparent
176
- opacity={selected ? 0.46 : 0.24}
184
+ opacity={selected ? 0.58 : 0.34}
177
185
  depthWrite={false}
178
186
  depthTest={false}
179
187
  />
180
188
  </mesh>
181
189
  <mesh position={[0, 0.04, 0]} renderOrder={11}>
182
190
  <boxGeometry args={[width, 0.02, depth]} />
183
- <meshBasicMaterial color={selected ? "#d99725" : "#9b695a"} wireframe depthTest={false} />
191
+ <meshBasicMaterial color={selected ? SELECTED_COLOR : OBJECT_COLOR} wireframe depthTest={false} />
184
192
  </mesh>
185
193
  <group position={[0, 0, depth / 2 + 0.45]} rotation={[0, -rotation, 0]}>
186
194
  <PlanLabel
187
- text={object.name.slice(0, 8).toUpperCase()}
188
- color={selected ? "#b37610" : "#7c574d"}
195
+ text={objectLabel}
196
+ color={selected ? SELECTED_COLOR : OBJECT_COLOR}
189
197
  offset={0}
190
198
  />
191
199
  </group>
192
- {selected && <Puck color="#e7b557" showBody={false} handleDist={handleDist} dragging={dragging} turning={turning} />}
200
+ {selected && <Puck color={SELECTED_COLOR} showBody={false} handleDist={handleDist} dragging={dragging} turning={turning} />}
193
201
  </group>
194
202
  );
195
203
  }
196
204
 
197
- const WAYPOINT_COLOR = "#6f9f86";
198
- const RAIL_COLOR = "#a78bfa"; // the camera's violet, same identity as its timeline lane
205
+ const WAYPOINT_COLOR = "#078267";
206
+ const RAIL_COLOR = "#7137c8"; // saturated violet, same identity as its timeline lane
207
+ const SUBJECT_PATH_COLOR = "#008f83";
208
+
209
+ function directionTriangle(from, to, distance = 0.26) {
210
+ const dx = to.x - from.x;
211
+ const dz = to.z - from.z;
212
+ const length = Math.hypot(dx, dz);
213
+ if (length < 0.03) return null;
214
+ const ux = dx / length;
215
+ const uz = dz / length;
216
+ const px = -uz;
217
+ const pz = ux;
218
+ const tip = to;
219
+ const base = { x: tip.x - ux * distance, z: tip.z - uz * distance };
220
+ const width = distance * 0.55;
221
+ const geometry = new THREE.BufferGeometry();
222
+ geometry.setAttribute("position", new THREE.Float32BufferAttribute([
223
+ tip.x, 0.052, tip.z,
224
+ base.x + px * width, 0.052, base.z + pz * width,
225
+ base.x - px * width, 0.052, base.z - pz * width,
226
+ ], 3));
227
+ return geometry;
228
+ }
229
+
230
+ /** ARDY movement endpoints shown while composing a camera rail. The direct
231
+ * start-to-end vector gives the operator one unambiguous travel direction. */
232
+ function SubjectMovementGuide({ track }) {
233
+ const guide = useMemo(() => {
234
+ if (!track?.length) return null;
235
+ const start = track[0];
236
+ const end = track[track.length - 1];
237
+ const moving = Math.hypot(end.x - start.x, end.z - start.z) > 0.05;
238
+ return { start, end, moving, arrow: moving ? directionTriangle(start, end, 0.34) : null };
239
+ }, [track]);
240
+ useEffect(() => () => {
241
+ guide?.arrow?.dispose();
242
+ }, [guide]);
243
+ if (!guide) return null;
244
+ return (
245
+ <group>
246
+ <Line points={[[guide.start.x, 0.041, guide.start.z], [guide.end.x, 0.041, guide.end.z]]} color={SUBJECT_PATH_COLOR} lineWidth={3} transparent opacity={guide.moving ? 0.95 : 0.55} depthWrite={false} depthTest={false} renderOrder={9} />
247
+ {guide.arrow && (
248
+ <mesh geometry={guide.arrow} renderOrder={11}>
249
+ <meshBasicMaterial color={SUBJECT_PATH_COLOR} depthWrite={false} depthTest={false} side={THREE.DoubleSide} />
250
+ </mesh>
251
+ )}
252
+ {[
253
+ { point: guide.start, label: ko("ARDY START", "ARDY 시작") },
254
+ { point: guide.end, label: ko("ARDY END", "ARDY 끝") },
255
+ ].map(({ point, label }) => (
256
+ <group key={label} position={[point.x, 0, point.z]}>
257
+ <mesh position={[0, 0.055, 0]} rotation={[-Math.PI / 2, 0, 0]} renderOrder={11}>
258
+ <ringGeometry args={[0.12, 0.18, 18]} />
259
+ <meshBasicMaterial color={SUBJECT_PATH_COLOR} depthWrite={false} depthTest={false} />
260
+ </mesh>
261
+ <Text position={[0, 0.06, 0.38]} rotation={[-Math.PI / 2, 0, 0]} fontSize={0.2} color={SUBJECT_PATH_COLOR} anchorX="center" anchorY="middle" outlineWidth={0.035} outlineColor="#0e0d10" outlineOpacity={0.82} renderOrder={12} depthOffset={-1}>
262
+ {`${label} (${point.x.toFixed(1)}, ${point.z.toFixed(1)})`}
263
+ </Text>
264
+ </group>
265
+ ))}
266
+ {!guide.moving && (
267
+ <Text position={[guide.start.x, 0.06, guide.start.z - 0.42]} rotation={[-Math.PI / 2, 0, 0]} fontSize={0.24} color={SUBJECT_PATH_COLOR} anchorX="center" anchorY="middle" outlineWidth={0.035} outlineColor="#0e0d10" outlineOpacity={0.82} renderOrder={12} depthOffset={-1}>
268
+ {ko("PLAYER STILL", "플레이어 정지")}
269
+ </Text>
270
+ )}
271
+ </group>
272
+ );
273
+ }
199
274
 
200
275
  /**
201
276
  * The drawn camera rail (and the live stroke while drawing): a flat violet
@@ -203,33 +278,74 @@ const RAIL_COLOR = "#a78bfa"; // the camera's violet, same identity as its timel
203
278
  * handlers, exactly like the pucks.
204
279
  */
205
280
  function CameraRailLine({ points, live = false }) {
206
- const geometry = useMemo(() => {
207
- if (!points || points.length < 2) return null;
208
- const positions = new Float32Array(points.length * 3);
209
- points.forEach((p, i) => {
210
- positions[i * 3] = p.x;
211
- positions[i * 3 + 1] = 0.03;
212
- positions[i * 3 + 2] = p.z;
213
- });
214
- const g = new THREE.BufferGeometry();
215
- g.setAttribute("position", new THREE.BufferAttribute(positions, 3));
216
- return g;
217
- }, [points]);
218
- useEffect(() => () => geometry?.dispose(), [geometry]);
219
- if (!geometry) return null;
281
+ const directionGeometry = useMemo(() => {
282
+ if (live || !points || points.length < 2) return null;
283
+ const head = points[0];
284
+ const next = points.find((p) => Math.hypot(p.x - head.x, p.z - head.z) > 0.01);
285
+ if (!next) return null;
286
+ const dx = next.x - head.x;
287
+ const dz = next.z - head.z;
288
+ const length = Math.hypot(dx, dz);
289
+ const ux = dx / length;
290
+ const uz = dz / length;
291
+ const px = -uz;
292
+ const pz = ux;
293
+ const tipDistance = Math.min(0.9, length * 0.72);
294
+ const arrowLength = Math.min(0.34, tipDistance * 0.6);
295
+ const arrowWidth = Math.min(0.18, arrowLength * 0.55);
296
+ const tip = { x: head.x + ux * tipDistance, z: head.z + uz * tipDistance };
297
+ const base = { x: tip.x - ux * arrowLength, z: tip.z - uz * arrowLength };
298
+ const arrow = new THREE.BufferGeometry();
299
+ arrow.setAttribute("position", new THREE.Float32BufferAttribute([
300
+ tip.x, 0.045, tip.z,
301
+ base.x + px * arrowWidth, 0.045, base.z + pz * arrowWidth,
302
+ base.x - px * arrowWidth, 0.045, base.z - pz * arrowWidth,
303
+ ], 3));
304
+ return arrow;
305
+ }, [live, points]);
306
+ useEffect(() => () => directionGeometry?.dispose(), [directionGeometry]);
307
+ if (!points || points.length < 2) return null;
220
308
  const first = points[0];
221
309
  const last = points[points.length - 1];
222
310
  return (
223
311
  <group>
224
- <line geometry={geometry} renderOrder={9}>
225
- <lineBasicMaterial color={RAIL_COLOR} transparent opacity={live ? 0.5 : 0.85} depthWrite={false} depthTest={false} />
226
- </line>
227
- {!live && [first, last].map((p, i) => (
228
- <mesh key={i} position={[p.x, 0.04, p.z]} rotation={[-Math.PI / 2, 0, 0]} renderOrder={10}>
229
- <circleGeometry args={[0.14, 16]} />
230
- <meshBasicMaterial color={RAIL_COLOR} depthWrite={false} depthTest={false} />
231
- </mesh>
232
- ))}
312
+ <Line points={points.map((point) => [point.x, 0.03, point.z])} color={RAIL_COLOR} lineWidth={live ? 2.5 : 3.5} transparent opacity={live ? 0.72 : 0.96} depthWrite={false} depthTest={false} renderOrder={9} />
313
+ {!live && (
314
+ <>
315
+ <mesh position={[first.x, 0.04, first.z]} rotation={[-Math.PI / 2, 0, 0]} renderOrder={11}>
316
+ <circleGeometry args={[0.22, 20]} />
317
+ <meshBasicMaterial color={RAIL_COLOR} depthWrite={false} depthTest={false} />
318
+ </mesh>
319
+ <mesh position={[first.x, 0.039, first.z]} rotation={[-Math.PI / 2, 0, 0]} renderOrder={10}>
320
+ <ringGeometry args={[0.27, 0.32, 20]} />
321
+ <meshBasicMaterial color={RAIL_COLOR} transparent opacity={0.72} depthWrite={false} depthTest={false} />
322
+ </mesh>
323
+ <Text
324
+ position={[first.x, 0.05, first.z + 0.48]}
325
+ rotation={[-Math.PI / 2, 0, 0]}
326
+ fontSize={0.24}
327
+ color={RAIL_COLOR}
328
+ anchorX="center"
329
+ anchorY="middle"
330
+ outlineWidth={0.035}
331
+ outlineColor="#0e0d10"
332
+ outlineOpacity={0.85}
333
+ renderOrder={12}
334
+ depthOffset={-1}
335
+ >
336
+ {ko("START", "시작")}
337
+ </Text>
338
+ {directionGeometry && (
339
+ <mesh geometry={directionGeometry} renderOrder={11}>
340
+ <meshBasicMaterial color={RAIL_COLOR} depthWrite={false} depthTest={false} side={THREE.DoubleSide} />
341
+ </mesh>
342
+ )}
343
+ <mesh position={[last.x, 0.04, last.z]} rotation={[-Math.PI / 2, 0, 0]} renderOrder={10}>
344
+ <ringGeometry args={[0.1, 0.15, 16]} />
345
+ <meshBasicMaterial color={RAIL_COLOR} depthWrite={false} depthTest={false} />
346
+ </mesh>
347
+ </>
348
+ )}
233
349
  </group>
234
350
  );
235
351
  }
@@ -240,26 +356,12 @@ function CameraRailLine({ points, live = false }) {
240
356
  * reads from straight above and never enters shot-camera exports.
241
357
  */
242
358
  function WaypointPath({ waypoints, start, activeWaypointFrame }) {
243
- const line = useMemo(() => {
244
- if (waypoints.length < 1) return null;
245
- const pathPoints = [{ x: start.x, z: start.z }, ...waypoints];
246
- const positions = new Float32Array(pathPoints.length * 3);
247
- pathPoints.forEach((w, i) => {
248
- positions[i * 3] = w.x;
249
- positions[i * 3 + 1] = 0.02;
250
- positions[i * 3 + 2] = w.z;
251
- });
252
- const geometry = new THREE.BufferGeometry();
253
- geometry.setAttribute("position", new THREE.BufferAttribute(positions, 3));
254
- return geometry;
255
- }, [start.x, start.z, waypoints]);
359
+ const pathPoints = useMemo(() => [{ x: start.x, z: start.z }, ...waypoints], [start.x, start.z, waypoints]);
256
360
 
257
361
  return (
258
362
  <group>
259
- {line && (
260
- <line geometry={line} renderOrder={9}>
261
- <lineBasicMaterial color={WAYPOINT_COLOR} transparent opacity={0.55} depthWrite={false} depthTest={false} />
262
- </line>
363
+ {pathPoints.length > 1 && (
364
+ <Line points={pathPoints.map((point) => [point.x, 0.02, point.z])} color={WAYPOINT_COLOR} lineWidth={2.5} transparent opacity={0.9} depthWrite={false} depthTest={false} renderOrder={9} />
263
365
  )}
264
366
  {waypoints.map((w, i) => {
265
367
  const active = w.frame === activeWaypointFrame;
@@ -303,7 +405,7 @@ function WaypointPath({ waypoints, start, activeWaypointFrame }) {
303
405
  * reports moves that still hit it, so a fast drag off the edge silently strands
304
406
  * the puck.
305
407
  */
306
- export function PlanBoard({ hostRef, planCamRef, shotCamRef, look, fovDeg, charA, setCharA, charB, setCharB, showB, waypoints, activeWaypointFrame, onSelectWaypoint, onMoveWaypoint, onSelectEntity, sceneObjects = [], selectedSceneObjectId, onMoveSceneObject, onObjectMoveStart, onObjectMoveEnd, cameraRailPoints = null, railDraw = false, onRailStroke }) {
408
+ export function PlanBoard({ hostRef, planCamRef, shotCamRef, look, fovDeg, charA, setCharA, charB, setCharB, showB, waypoints, activeWaypointFrame, onSelectWaypoint, onMoveWaypoint, onSelectEntity, sceneObjects = [], selectedSceneObjectId, onMoveSceneObject, onObjectMoveStart, onObjectMoveEnd, cameraRailPoints = null, railDraw = false, onRailStroke, subjectTrack = null, onCameraChange }) {
307
409
  const [drag, setDrag] = useState(null); // { id, mode }
308
410
  // live stroke while the rail is being drawn; world XZ, display only
309
411
  const [railStroke, setRailStroke] = useState(null);
@@ -333,8 +435,8 @@ export function PlanBoard({ hostRef, planCamRef, shotCamRef, look, fovDeg, charA
333
435
  // clears dragRef, so a dep that changes while dragging (charA.x does, on the
334
436
  // very first move) would kill the drag after one frame. Read live values
335
437
  // through a ref and keep the effect's deps stable.
336
- const latest = useRef({ charA, charB, showB, waypoints, onSelectWaypoint, onMoveWaypoint, onSelectEntity, sceneObjects, selectedSceneObjectId, onMoveSceneObject, onObjectMoveStart, onObjectMoveEnd, railDraw, onRailStroke });
337
- latest.current = { charA, charB, showB, waypoints, onSelectWaypoint, onMoveWaypoint, onSelectEntity, sceneObjects, selectedSceneObjectId, onMoveSceneObject, onObjectMoveStart, onObjectMoveEnd, railDraw, onRailStroke };
438
+ const latest = useRef({ charA, charB, showB, waypoints, onSelectWaypoint, onMoveWaypoint, onSelectEntity, sceneObjects, selectedSceneObjectId, onMoveSceneObject, onObjectMoveStart, onObjectMoveEnd, railDraw, onRailStroke, onCameraChange });
439
+ latest.current = { charA, charB, showB, waypoints, onSelectWaypoint, onMoveWaypoint, onSelectEntity, sceneObjects, selectedSceneObjectId, onMoveSceneObject, onObjectMoveStart, onObjectMoveEnd, railDraw, onRailStroke, onCameraChange };
338
440
 
339
441
  const targets = () => {
340
442
  const { charA: a, charB: b, showB: two } = latest.current;
@@ -511,6 +613,7 @@ export function PlanBoard({ hostRef, planCamRef, shotCamRef, look, fovDeg, charA
511
613
  if (grip.id === "cam") {
512
614
  // a manual aim; the operator has decided to point off-subject
513
615
  look.current.yaw = yaw;
616
+ latest.current.onCameraChange?.();
514
617
  return;
515
618
  }
516
619
  // 5° detents, because actors are blocked to clean angles
@@ -530,6 +633,7 @@ export function PlanBoard({ hostRef, planCamRef, shotCamRef, look, fovDeg, charA
530
633
  const angles = aimAt(cam.position, aimTarget());
531
634
  look.current.yaw = angles.yaw;
532
635
  look.current.pitch = angles.pitch;
636
+ latest.current.onCameraChange?.();
533
637
  return;
534
638
  }
535
639
  const next = { x: snap(p.x, ACTOR_LIMIT), z: snap(p.z, ACTOR_LIMIT) };
@@ -569,6 +673,7 @@ export function PlanBoard({ hostRef, planCamRef, shotCamRef, look, fovDeg, charA
569
673
  }
570
674
  const token = grip.token;
571
675
  teardownDrag(grip);
676
+ if (commit && grip.id === "cam") latest.current.onCameraChange?.();
572
677
  if (token != null) latest.current.onObjectMoveEnd?.(token, { commit });
573
678
  };
574
679
 
@@ -613,25 +718,27 @@ export function PlanBoard({ hostRef, planCamRef, shotCamRef, look, fovDeg, charA
613
718
  return (
614
719
  <group ref={rootRef}>
615
720
  <group ref={camPos}>
616
- <PlanLabel text="CAM" color="#247da0" />
721
+ <PlanLabel text={ko("CAM", "카메라")} color={CAMERA_COLOR} />
617
722
  <group ref={camRot}>
618
723
  <FrustumWedge fovDeg={fovDeg} active={drag?.id === "cam"} />
619
- <Puck color="#4e9fb3" {...state("cam")} />
724
+ <Puck color={CAMERA_COLOR} {...state("cam")} />
620
725
  </group>
621
726
  </group>
622
727
 
623
728
  <group position={[charA.x, 0, charA.z]}>
624
- <PlanLabel text="S1" color="#273849" />
729
+ <PlanLabel text={ko("S1", "인물 1")} color={SUBJECT_ONE_COLOR} />
625
730
  <group rotation={[0, (charA.rot * Math.PI) / 180, 0]}>
626
- <Puck color="#273849" {...state("a")} />
731
+ {/* The real character mesh already renders in Top-View. Keep only
732
+ its facing stem/handle instead of covering it with a hex puck. */}
733
+ <Puck color={SUBJECT_ONE_COLOR} showBody={false} {...state("a")} />
627
734
  </group>
628
735
  </group>
629
736
 
630
737
  {showB && (
631
738
  <group position={[charB.x, 0, charB.z]}>
632
- <PlanLabel text="S2" color="#d65f55" />
739
+ <PlanLabel text={ko("S2", "인물 2")} color={SUBJECT_TWO_COLOR} />
633
740
  <group rotation={[0, (charB.rot * Math.PI) / 180, 0]}>
634
- <Puck color="#d65f55" {...state("b")} />
741
+ <Puck color={SUBJECT_TWO_COLOR} showBody={false} {...state("b")} />
635
742
  </group>
636
743
  </group>
637
744
  )}
@@ -646,6 +753,7 @@ export function PlanBoard({ hostRef, planCamRef, shotCamRef, look, fovDeg, charA
646
753
  ))}
647
754
 
648
755
  {waypoints.length > 0 && <WaypointPath waypoints={waypoints} start={charA} activeWaypointFrame={activeWaypointFrame} />}
756
+ {(railDraw || cameraRailPoints) && <SubjectMovementGuide track={subjectTrack} />}
649
757
  {cameraRailPoints && cameraRailPoints.length > 1 && <CameraRailLine points={cameraRailPoints} />}
650
758
  {railStroke && railStroke.length > 1 && <CameraRailLine points={railStroke} live />}
651
759
  </group>
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Browser extraction boundary shared by uploaded video and webcam frames.
3
+ * The UI supplies an async iterable of `{ image, timeS }` and an already
4
+ * configured detector (for MediaPipe: `detectForVideo(image, timeS * 1000)`).
5
+ * Keeping model creation outside this module makes model URL/revision,
6
+ * telemetry gating and first-use caching explicit at the App integration site.
7
+ */
8
+
9
+ function confidenceOf(landmarks) {
10
+ if (!Array.isArray(landmarks) || landmarks.length === 0) return -Infinity;
11
+ return landmarks.reduce((sum, point) =>
12
+ sum + (Number.isFinite(point?.visibility) ? point.visibility : 1), 0
13
+ ) / landmarks.length;
14
+ }
15
+
16
+ export function selectMostConfidentPerson(result) {
17
+ const candidates = result?.worldLandmarks ?? result?.landmarks ?? [];
18
+ if (!Array.isArray(candidates) || candidates.length === 0) return null;
19
+ return candidates.reduce((best, candidate) =>
20
+ confidenceOf(candidate) > confidenceOf(best) ? candidate : best
21
+ , null);
22
+ }
23
+
24
+ export async function collectLandmarkTrack({ frames, detect, onProgress = () => {} }) {
25
+ if (!frames || typeof frames[Symbol.asyncIterator] !== "function") {
26
+ throw new Error("collectLandmarkTrack: frames must be an async iterable");
27
+ }
28
+ if (typeof detect !== "function") throw new Error("collectLandmarkTrack: detect must be a function");
29
+ const samples = [];
30
+ let processed = 0;
31
+ for await (const frame of frames) {
32
+ if (!frame || !Number.isFinite(frame.timeS) || frame.timeS < 0 || !("image" in frame)) {
33
+ throw new Error("collectLandmarkTrack: each frame needs image and non-negative timeS");
34
+ }
35
+ const result = await detect(frame.image, frame.timeS * 1000);
36
+ const landmarks = selectMostConfidentPerson(result);
37
+ if (landmarks) samples.push({ timeS: frame.timeS, landmarks });
38
+ processed += 1;
39
+ onProgress({ processed, accepted: samples.length, timeS: frame.timeS });
40
+ }
41
+ return samples;
42
+ }
@@ -0,0 +1,194 @@
1
+ /** Landmark directions -> ordinary cozyclay.pose.v1 keys, with no runtime UI dependency. */
2
+
3
+ import { COZYCLAY_BONES, CSKEL27_JOINTS } from "../ardy/cskel27.js";
4
+ import { CSKEL27_NEUTRAL } from "../ardy/cskel27-neutral.js";
5
+ import { localToBasis, matMul, matToQuat, matTranspose } from "../ardy/convert.js";
6
+ import { POSE_LANDMARK as L } from "./landmarks.js";
7
+
8
+ function add(a, b) { return [a[0] + b[0], a[1] + b[1], a[2] + b[2]]; }
9
+ function sub(a, b) { return [a[0] - b[0], a[1] - b[1], a[2] - b[2]]; }
10
+ function scale(v, amount) { return [v[0] * amount, v[1] * amount, v[2] * amount]; }
11
+ function dot(a, b) { return a[0] * b[0] + a[1] * b[1] + a[2] * b[2]; }
12
+ function cross(a, b) {
13
+ return [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]];
14
+ }
15
+ function norm(v) { return Math.hypot(v[0], v[1], v[2]); }
16
+ function unit(v) { const n = norm(v); return n > 1e-8 ? scale(v, 1 / n) : null; }
17
+ function lerp(a, b, t) { return add(a, scale(sub(b, a), t)); }
18
+
19
+ function averageLandmarks(landmarks, indices) {
20
+ const available = indices.map((index) => landmarks[index]).filter(Boolean);
21
+ if (available.length === 0) return null;
22
+ const weight = available.reduce((sum, entry) => sum + entry.visibility, 0);
23
+ if (!(weight > 0)) return null;
24
+ return available.reduce(
25
+ (sum, entry) => add(sum, scale(entry.position, entry.visibility / weight)),
26
+ [0, 0, 0]
27
+ );
28
+ }
29
+
30
+ function landmarkPoint(landmarks, index) {
31
+ return landmarks[index]?.position?.slice() ?? null;
32
+ }
33
+
34
+ function buildTargetPoints(landmarks) {
35
+ const leftHip = landmarkPoint(landmarks, L.LEFT_HIP);
36
+ const rightHip = landmarkPoint(landmarks, L.RIGHT_HIP);
37
+ const leftShoulder = landmarkPoint(landmarks, L.LEFT_SHOULDER);
38
+ const rightShoulder = landmarkPoint(landmarks, L.RIGHT_SHOULDER);
39
+ if (!leftHip || !rightHip || !leftShoulder || !rightShoulder) return null;
40
+ const hips = scale(add(leftHip, rightHip), 0.5);
41
+ const shoulders = scale(add(leftShoulder, rightShoulder), 0.5);
42
+ const head = averageLandmarks(landmarks, [L.NOSE, L.LEFT_EYE, L.RIGHT_EYE, L.LEFT_EAR, L.RIGHT_EAR]);
43
+ return {
44
+ Hips: hips,
45
+ Spine: lerp(hips, shoulders, 0.25),
46
+ Spine1: lerp(hips, shoulders, 0.5),
47
+ Spine2: lerp(hips, shoulders, 0.75),
48
+ Spine3: shoulders,
49
+ Neck: shoulders,
50
+ Head: head,
51
+ LeftShoulder: shoulders,
52
+ LeftArm: leftShoulder,
53
+ LeftForeArm: landmarkPoint(landmarks, L.LEFT_ELBOW),
54
+ LeftHand: landmarkPoint(landmarks, L.LEFT_WRIST),
55
+ LeftHandEnd: averageLandmarks(landmarks, [L.LEFT_PINKY, L.LEFT_INDEX]),
56
+ RightShoulder: shoulders,
57
+ RightArm: rightShoulder,
58
+ RightForeArm: landmarkPoint(landmarks, L.RIGHT_ELBOW),
59
+ RightHand: landmarkPoint(landmarks, L.RIGHT_WRIST),
60
+ RightHandEnd: averageLandmarks(landmarks, [L.RIGHT_PINKY, L.RIGHT_INDEX]),
61
+ LeftUpLeg: leftHip,
62
+ LeftLeg: landmarkPoint(landmarks, L.LEFT_KNEE),
63
+ LeftFoot: landmarkPoint(landmarks, L.LEFT_ANKLE),
64
+ LeftToeBase: landmarkPoint(landmarks, L.LEFT_FOOT_INDEX),
65
+ RightUpLeg: rightHip,
66
+ RightLeg: landmarkPoint(landmarks, L.RIGHT_KNEE),
67
+ RightFoot: landmarkPoint(landmarks, L.RIGHT_ANKLE),
68
+ RightToeBase: landmarkPoint(landmarks, L.RIGHT_FOOT_INDEX),
69
+ _faceForward: head && averageLandmarks(landmarks, [L.LEFT_EAR, L.RIGHT_EAR])
70
+ ? sub(landmarkPoint(landmarks, L.NOSE) ?? head, averageLandmarks(landmarks, [L.LEFT_EAR, L.RIGHT_EAR]))
71
+ : null,
72
+ };
73
+ }
74
+
75
+ function buildNeutralPoints() {
76
+ return Object.fromEntries(CSKEL27_JOINTS.map((name, index) => [name, CSKEL27_NEUTRAL[index].slice()]));
77
+ }
78
+
79
+ const CHILD = {
80
+ Hips: "Spine", Spine: "Spine1", Spine1: "Spine2", Neck: "Head",
81
+ LeftShoulder: "LeftArm", LeftArm: "LeftForeArm", LeftForeArm: "LeftHand", LeftHand: "LeftHandEnd",
82
+ RightShoulder: "RightArm", RightArm: "RightForeArm", RightForeArm: "RightHand", RightHand: "RightHandEnd",
83
+ LeftUpLeg: "LeftLeg", LeftLeg: "LeftFoot", LeftFoot: "LeftToeBase",
84
+ RightUpLeg: "RightLeg", RightLeg: "RightFoot", RightFoot: "RightToeBase",
85
+ };
86
+
87
+ const EFFECTIVE_PARENT = {
88
+ Hips: null, Spine: "Hips", Spine1: "Spine", Neck: "Spine1", Head: "Neck",
89
+ LeftShoulder: "Spine1", LeftArm: "LeftShoulder", LeftForeArm: "LeftArm", LeftHand: "LeftForeArm",
90
+ RightShoulder: "Spine1", RightArm: "RightShoulder", RightForeArm: "RightArm", RightHand: "RightForeArm",
91
+ LeftUpLeg: "Hips", LeftLeg: "LeftUpLeg", LeftFoot: "LeftLeg",
92
+ RightUpLeg: "Hips", RightLeg: "RightUpLeg", RightFoot: "RightLeg",
93
+ };
94
+
95
+ function bodyAxes(points) {
96
+ const lateral = points.LeftUpLeg && points.RightUpLeg ? unit(sub(points.LeftUpLeg, points.RightUpLeg)) : null;
97
+ const up = points.Spine3 && points.Hips ? unit(sub(points.Spine3, points.Hips)) : null;
98
+ const forward = lateral && up ? unit(cross(lateral, up)) : null;
99
+ return { lateral, up, forward };
100
+ }
101
+
102
+ function frameFrom(primary, secondary) {
103
+ const x = unit(primary);
104
+ if (!x || !secondary) return null;
105
+ let y = sub(secondary, scale(x, dot(secondary, x)));
106
+ y = unit(y);
107
+ if (!y) {
108
+ const fallback = Math.abs(x[1]) < 0.9 ? [0, 1, 0] : [0, 0, 1];
109
+ y = unit(sub(fallback, scale(x, dot(fallback, x))));
110
+ }
111
+ if (!y) return null;
112
+ const z = unit(cross(x, y));
113
+ if (!z) return null;
114
+ y = unit(cross(z, x));
115
+ return [
116
+ [x[0], y[0], z[0]],
117
+ [x[1], y[1], z[1]],
118
+ [x[2], y[2], z[2]],
119
+ ];
120
+ }
121
+
122
+ function jointFrame(name, points, axes) {
123
+ let primary;
124
+ if (name === "Head") primary = points.Head && points.Neck ? sub(points.Head, points.Neck) : null;
125
+ else {
126
+ const child = CHILD[name];
127
+ primary = child && points[name] && points[child] ? sub(points[child], points[name]) : null;
128
+ }
129
+ if (!primary) return null;
130
+ let secondary = axes.forward;
131
+ if (["Hips", "Spine", "Spine1", "Neck"].includes(name)) secondary = axes.lateral;
132
+ else if (name === "Head") secondary = points._faceForward ?? axes.forward;
133
+ else if (name.endsWith("Shoulder") || name.endsWith("Foot")) secondary = axes.up;
134
+ return frameFrom(primary, secondary);
135
+ }
136
+
137
+ function restByName(rest) {
138
+ if (!rest || !Array.isArray(rest.joints)) {
139
+ throw new Error("fitLandmarksToPose: rest must be parsed cskel27-rest.json");
140
+ }
141
+ return new Map(rest.joints.map((entry) => [entry.name, entry.rest]));
142
+ }
143
+
144
+ function meanConfidence(landmarks) {
145
+ const visible = landmarks.filter(Boolean);
146
+ return visible.length ? visible.reduce((sum, entry) => sum + entry.visibility, 0) / visible.length : 0;
147
+ }
148
+
149
+ /** Fit one normalised landmark sample into the exact pose schema consumed by poseToCskel27. */
150
+ export function fitLandmarksToPose({ sample, rest, createdMs = 0 }) {
151
+ if (!sample?.valid || !Array.isArray(sample.landmarks)) {
152
+ throw new Error("fitLandmarksToPose: sample must be a valid normalized landmark sample");
153
+ }
154
+ const targetPoints = buildTargetPoints(sample.landmarks);
155
+ if (!targetPoints) throw new Error("fitLandmarksToPose: shoulders and hips must be visible");
156
+ const neutralPoints = buildNeutralPoints();
157
+ const targetAxes = bodyAxes(targetPoints);
158
+ const neutralAxes = bodyAxes(neutralPoints);
159
+ const rests = restByName(rest);
160
+ const desiredGlobal = new Map();
161
+ const bones = {};
162
+ const releasedBones = [];
163
+ const identity = [[1, 0, 0], [0, 1, 0], [0, 0, 1]];
164
+
165
+ for (const name of COZYCLAY_BONES) {
166
+ const targetFrame = jointFrame(name, targetPoints, targetAxes);
167
+ const neutralFrame = jointFrame(name, neutralPoints, neutralAxes);
168
+ const parentName = EFFECTIVE_PARENT[name];
169
+ const parentGlobal = parentName ? desiredGlobal.get(parentName) : identity;
170
+ let global = parentGlobal;
171
+ let local = identity;
172
+ if (targetFrame && neutralFrame) {
173
+ global = matMul(targetFrame, matTranspose(neutralFrame));
174
+ local = matMul(matTranspose(parentGlobal), global);
175
+ } else {
176
+ releasedBones.push(name);
177
+ }
178
+ desiredGlobal.set(name, global);
179
+ const restRotation = rests.get(name);
180
+ if (!restRotation) throw new Error(`fitLandmarksToPose: rest rotation missing for ${name}`);
181
+ bones[name] = matToQuat(localToBasis(local, restRotation));
182
+ }
183
+
184
+ return {
185
+ pose: {
186
+ schema: "cozyclay.pose.v1",
187
+ created_ms: createdMs,
188
+ source: { app: "cozyclay", rig: "cskel27-video-fit", time_s: sample.timeS },
189
+ bones,
190
+ },
191
+ releasedBones,
192
+ confidence: meanConfidence(sample.landmarks),
193
+ };
194
+ }