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.
- package/README.md +59 -24
- package/THIRD_PARTY_NOTICES.md +31 -0
- package/bin/cozyclay.mjs +105 -11
- package/dist/CNAME +1 -0
- package/dist/app/index.html +57 -0
- package/dist/assets/app-Cgpk2hwX.js +4803 -0
- package/dist/assets/app-DgZvaAE1.css +1 -0
- package/dist/favicon.ico +0 -0
- package/dist/icons/apple-touch-icon.png +0 -0
- package/dist/icons/icon-192.png +0 -0
- package/dist/icons/icon-32.png +0 -0
- package/dist/icons/icon-512.png +0 -0
- package/dist/icons/icon-maskable-512.png +0 -0
- package/dist/index.html +406 -5
- package/dist/manifest.webmanifest +42 -0
- package/dist/media/cozyclay-demo-poster.jpg +0 -0
- package/dist/media/cozyclay-logo.png +0 -0
- package/dist/robots.txt +4 -0
- package/dist/sitemap.xml +9 -0
- package/dist/sw.js +127 -0
- package/package.json +15 -3
- package/src/App.jsx +1393 -648
- package/src/ardy/client.js +5 -4
- package/src/ardy/mp4-duration.js +102 -0
- package/src/ardy/timeline-coordinates.js +11 -0
- package/src/ardy/timeline.jsx +528 -67
- package/src/ardy/waypoints.js +14 -9
- package/src/camera-block.js +60 -0
- package/src/camera-follow.js +49 -10
- package/src/camera-rail-schedule.js +176 -0
- package/src/controls.jsx +16 -2
- package/src/cuts.js +184 -0
- package/src/generation/client.js +56 -0
- package/src/generation/session.js +47 -0
- package/src/generation/shot-spec.js +40 -0
- package/src/generation/use-generation.js +55 -0
- package/src/hierarchy-model.js +9 -17
- package/src/hierarchy-panel.jsx +170 -23
- package/src/locale-toggle.jsx +18 -0
- package/src/locale.js +34 -0
- package/src/main.jsx +5 -0
- package/src/object-catalog.jsx +32 -3
- package/src/planview.jsx +174 -66
- package/src/pose-extract/browser.js +42 -0
- package/src/pose-extract/fit.js +194 -0
- package/src/pose-extract/index.js +53 -0
- package/src/pose-extract/keyframes.js +74 -0
- package/src/pose-extract/landmarks.js +162 -0
- package/src/poses.js +114 -0
- package/src/posestudio.jsx +75 -13
- package/src/pwa.js +42 -0
- package/src/result-modal.jsx +124 -0
- package/src/scenes.js +223 -0
- package/src/shot-authoring.js +204 -77
- package/src/shot.js +8 -4
- package/src/styles.css +839 -38
- package/src/ui.jsx +54 -5
- package/tools/ardy/BRIDGE.md +70 -4
- package/tools/ardy/README.md +55 -0
- package/tools/ardy/bridge.mjs +89 -389
- package/tools/ardy/cclay_constrained_generate.py +449 -0
- package/tools/ardy/cclay_motion_edit.py +74 -9
- package/tools/ardy/cclay_sequence_generate.py +68 -7
- package/tools/ardy/cclay_worker.py +304 -0
- package/tools/ardy/merge-text-encoder.py +160 -0
- package/tools/ardy/run-local.mjs +233 -0
- package/tools/ardy/runners/index.mjs +23 -0
- package/tools/ardy/runners/local.mjs +452 -0
- package/tools/ardy/runners/proc.mjs +125 -0
- package/tools/ardy/runners/remote.mjs +246 -0
- package/tools/ardy/setup-local.mjs +189 -0
- package/tools/ardy/setup-text-encoder-on-box.sh +93 -0
- package/tools/ardy/setup-text-encoder.py +296 -0
- package/tools/generation/README.md +29 -0
- package/tools/generation/bridge.mjs +149 -0
- package/tools/generation/job-store.mjs +51 -0
- package/tools/generation/providers/kling.mjs +76 -0
- package/tools/generation/providers/runway.mjs +101 -0
- package/tools/generation/providers/seedance.mjs +87 -0
- package/tools/generation/providers/shared.mjs +49 -0
- package/tools/generation/providers/veo.mjs +84 -0
- package/tools/metrics/archive-traffic.mjs +138 -0
- package/dist/assets/index-BW_S1YRy.js +0 -4395
- package/dist/assets/index-nRmmJgap.css +0 -1
- package/tools/ardy/__pycache__/cclay_sequence_generate.cpython-313.pyc +0 -0
- package/tools/ardy/out/gen-1786443326924-c6019e-generated.npz +0 -0
- package/tools/ardy/out/gen-1786443609325-0053db-generated.npz +0 -0
- package/tools/ardy/out/gen-1786443835628-749ed1-generated.npz +0 -0
- package/tools/ardy/out/gen-1786462605247-03cb19-generated.npz +0 -0
- package/tools/qa-browser.mjs +0 -84
- package/tools/qa-crop3.mjs +0 -22
- package/tools/qa-playview.mjs +0 -49
- package/tools/qa-screenshot.mjs +0 -24
- package/tools/qa-visual.mjs +0 -51
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { ko, isKo } from "./locale.js";
|
|
2
|
+
|
|
3
|
+
export default function ResultModal({ result, generation, copied, recordedVideoName, onClose, onCopy, onDownload, onCancelGeneration }) {
|
|
4
|
+
const isVideo = result.mode === "video";
|
|
5
|
+
const modelLabel = result.modelLabel ?? (isVideo ? ko("your selected video model", "선택한 영상 모델") : ko("your selected image model", "선택한 이미지 모델"));
|
|
6
|
+
const hasFrame = Boolean(result.frame);
|
|
7
|
+
|
|
8
|
+
let nextStep;
|
|
9
|
+
if (isVideo && result.frameB) {
|
|
10
|
+
nextStep = (
|
|
11
|
+
<p>
|
|
12
|
+
{ko(`Paste the prompt into ${modelLabel}, set `, `${modelLabel}에 프롬프트를 붙여 넣고 `)}
|
|
13
|
+
<code>blocking-frame-A-start.png</code>
|
|
14
|
+
{ko(" as the start frame, and ", "를 시작 프레임으로, ")}
|
|
15
|
+
<code>blocking-frame-B-end.png</code>
|
|
16
|
+
{ko(" as the end frame.", "를 끝 프레임으로 설정하세요.")}
|
|
17
|
+
</p>
|
|
18
|
+
);
|
|
19
|
+
} else if (isVideo && hasFrame) {
|
|
20
|
+
nextStep = (
|
|
21
|
+
<p>
|
|
22
|
+
{ko(`Paste the prompt into ${modelLabel} and attach `, `${modelLabel}에 프롬프트를 붙여 넣고 `)}
|
|
23
|
+
<code>blocking-frame.png</code>
|
|
24
|
+
{ko(" as the reference frame.", "를 참고 프레임으로 첨부하세요.")}
|
|
25
|
+
</p>
|
|
26
|
+
);
|
|
27
|
+
} else if (hasFrame) {
|
|
28
|
+
nextStep = (
|
|
29
|
+
<p>
|
|
30
|
+
{ko(`Paste the prompt into ${modelLabel} and attach `, `${modelLabel}에 프롬프트를 붙여 넣고 `)}
|
|
31
|
+
<code>blocking-frame.png</code>
|
|
32
|
+
{ko(" as the reference image.", "를 참고 이미지로 첨부하세요.")}
|
|
33
|
+
</p>
|
|
34
|
+
);
|
|
35
|
+
} else {
|
|
36
|
+
nextStep = <p>{ko(`Paste the copied prompt into ${modelLabel} to create the scene.`, `복사한 프롬프트를 ${modelLabel}에 붙여 넣어 장면을 만드세요.`)}</p>;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
<div className="modal-overlay" onClick={onClose}>
|
|
41
|
+
<div className="modal result-modal" role="dialog" aria-modal="true" aria-labelledby="result-title" onClick={(event) => event.stopPropagation()}>
|
|
42
|
+
<div className="modal-head">
|
|
43
|
+
<h3 id="result-title">{ko("Your shot is ready", "장면이 준비됐어요")}</h3>
|
|
44
|
+
<button type="button" className="x" onClick={onClose} aria-label={ko("Close the result", "결과 닫기")}>
|
|
45
|
+
✕
|
|
46
|
+
</button>
|
|
47
|
+
</div>
|
|
48
|
+
{result.frameB ? (
|
|
49
|
+
<div className="move-frames">
|
|
50
|
+
<figure>
|
|
51
|
+
<img className="preview" src={result.frame} alt={ko("Camera move start frame", "카메라 움직임 시작 프레임")} />
|
|
52
|
+
<figcaption>A · {ko("Start", "시작")}</figcaption>
|
|
53
|
+
</figure>
|
|
54
|
+
<figure>
|
|
55
|
+
<img className="preview" src={result.frameB} alt={ko("Camera move end frame", "카메라 움직임 끝 프레임")} />
|
|
56
|
+
<figcaption>B · {ko("End", "끝")}</figcaption>
|
|
57
|
+
</figure>
|
|
58
|
+
</div>
|
|
59
|
+
) : (
|
|
60
|
+
result.frame && <img className="preview" src={result.frame} alt={ko("Finished scene frame", "완성된 장면 프레임")} />
|
|
61
|
+
)}
|
|
62
|
+
{result.move && (
|
|
63
|
+
<div className="move-slate result-move-slate">
|
|
64
|
+
<span>{result.move.displaySlate ?? result.move.slate} · {isKo ? `${result.move.spanS}초` : `${result.move.spanS}s`}</span>
|
|
65
|
+
<small>{ko("Camera move made from timeline keyframes", "타임라인 키프레임으로 만든 카메라 움직임")}</small>
|
|
66
|
+
</div>
|
|
67
|
+
)}
|
|
68
|
+
<label className="modal-label">{ko("Prompt", "프롬프트")} {copied && <em>· {ko("copied", "복사됨")}</em>}</label>
|
|
69
|
+
<div className="promptbox">{result.prompt}</div>
|
|
70
|
+
{isVideo && generation?.status !== "idle" && (
|
|
71
|
+
<div className="result-generation" aria-live="polite">
|
|
72
|
+
{generation.status === "succeeded" && generation.job?.outputUrl ? (
|
|
73
|
+
<video className="preview" src={generation.job.outputUrl} controls playsInline />
|
|
74
|
+
) : (
|
|
75
|
+
<p>{generation.error || ko(`Video generation: ${generation.status}`, `영상 생성: ${generation.status}`)}</p>
|
|
76
|
+
)}
|
|
77
|
+
{["validating", "submitting", "processing"].includes(generation.status) && (
|
|
78
|
+
<button type="button" className="btn" onClick={onCancelGeneration}>{ko("Cancel generation", "생성 취소")}</button>
|
|
79
|
+
)}
|
|
80
|
+
</div>
|
|
81
|
+
)}
|
|
82
|
+
<div className="modal-actions">
|
|
83
|
+
<button type="button" className="btn" onClick={onCopy}>
|
|
84
|
+
{copied ? ko("Copied ✓", "복사됨 ✓") : ko("Copy prompt", "프롬프트 복사")}
|
|
85
|
+
</button>
|
|
86
|
+
{result.frame && (
|
|
87
|
+
<button type="button" className="btn" onClick={onDownload}>
|
|
88
|
+
{result.frameB ? ko("Download start and end frames", "시작·끝 프레임 다운로드") : ko("Download frame", "프레임 다운로드")}
|
|
89
|
+
</button>
|
|
90
|
+
)}
|
|
91
|
+
</div>
|
|
92
|
+
|
|
93
|
+
<section className="result-next" aria-labelledby="result-next-title">
|
|
94
|
+
<span className="result-next-kicker">{ko(`Next · ${modelLabel}`, `다음 · ${modelLabel}`)}</span>
|
|
95
|
+
<h4 id="result-next-title">{ko("Handing off to your AI", "AI에 넣는 순서")}</h4>
|
|
96
|
+
<div className="result-next-intro">{nextStep}</div>
|
|
97
|
+
<ol className="result-handoff-steps">
|
|
98
|
+
<li>
|
|
99
|
+
<strong>{ko("Copy the prompt", "프롬프트 복사")}</strong>
|
|
100
|
+
<span>{copied ? ko("Copied. Paste it into your AI service's prompt box.", "복사됐어요. AI 서비스의 입력창에 붙여 넣으세요.") : ko("Press “Copy prompt” above, then paste it into your AI service.", "위의 ‘프롬프트 복사’를 누른 뒤 AI 서비스 입력창에 붙여 넣으세요.")}</span>
|
|
101
|
+
</li>
|
|
102
|
+
<li>
|
|
103
|
+
<strong>{ko("Download the frame", "프레임 다운로드")}</strong>
|
|
104
|
+
<span>{result.frameB ? ko("Press “Download start and end frames” to save both PNGs.", "‘시작·끝 프레임 다운로드’를 눌러 두 PNG를 저장하세요.") : hasFrame ? ko("Press “Download frame” to save the PNG.", "‘프레임 다운로드’를 눌러 PNG를 저장하세요.") : ko("This result has no frame to download.", "이 결과에는 내려받을 프레임이 없어요.")}</span>
|
|
105
|
+
</li>
|
|
106
|
+
<li>
|
|
107
|
+
<strong>{ko("Attach the image to your AI", "AI에 이미지 첨부")}</strong>
|
|
108
|
+
<span>{result.frameB ? ko("Use your AI service's image attach button to upload the start and end frames together.", "AI 서비스의 이미지 첨부 버튼에서 시작 프레임과 끝 프레임을 함께 올리세요.") : ko("Use your AI service's image attach button to upload blocking-frame.png.", "AI 서비스의 이미지 첨부 버튼에서 blocking-frame.png를 올리세요.")}</span>
|
|
109
|
+
</li>
|
|
110
|
+
</ol>
|
|
111
|
+
<p className="result-handoff-note">
|
|
112
|
+
{ko("The prompt describes the scene's content and mood; the frame shows the camera framing. Use both to reproduce this scene as closely as possible.", "프롬프트는 장면의 내용과 분위기를 설명하고, 프레임은 카메라 구도를 보여줘요. 둘을 함께 넣어야 이 장면을 가장 가깝게 재현할 수 있어요.")}
|
|
113
|
+
</p>
|
|
114
|
+
{recordedVideoName && (
|
|
115
|
+
<p className="result-reference-video">
|
|
116
|
+
<strong>{ko("Optional · Reference video", "선택 사항 · 참고 영상")}</strong>
|
|
117
|
+
{ko("A video recorded with the recording feature: ", "녹화 기능으로 만든 ")}<code>{recordedVideoName}</code>{ko(" file. Use it separately from the reference frame in the prompt above.", " 파일이에요. 위의 프롬프트 참고 프레임과는 별도로 활용하세요.")}
|
|
118
|
+
</p>
|
|
119
|
+
)}
|
|
120
|
+
</section>
|
|
121
|
+
</div>
|
|
122
|
+
</div>
|
|
123
|
+
);
|
|
124
|
+
}
|
package/src/scenes.js
ADDED
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
// Pure multi-scene document model. No three.js, no React.
|
|
2
|
+
// A Scene is the set; shotDocument and stage are sealed department envelopes.
|
|
3
|
+
// This module stores and copies those envelopes but never opens or validates them.
|
|
4
|
+
|
|
5
|
+
export const SCENES_VERSION = 2;
|
|
6
|
+
export const SCENES_STORAGE_KEY = "cozyclay.scenes.v2";
|
|
7
|
+
export const SCENES_QUARANTINE_KEY = "cozyclay.scenes.v2.quarantine";
|
|
8
|
+
export const PREVIOUS_SCENES_STORAGE_KEY = "cozyclay.scenes.v1";
|
|
9
|
+
export const LEGACY_SCENE_STORAGE_KEY = "cozyclay.scene.v1";
|
|
10
|
+
|
|
11
|
+
export const DEFAULT_SCENE_STAGE = Object.freeze({
|
|
12
|
+
charA: Object.freeze({ x: 0, z: 0, rot: 0 }),
|
|
13
|
+
charB: Object.freeze({ x: 1.15, z: 0.1, rot: -14 }),
|
|
14
|
+
showB: false,
|
|
15
|
+
poseA: null,
|
|
16
|
+
poseB: null,
|
|
17
|
+
hasCharSheet: false,
|
|
18
|
+
subject: "a young woman in a tan coat",
|
|
19
|
+
subject2: "a man in a dark coat",
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
let sceneSequence = 1;
|
|
23
|
+
|
|
24
|
+
const plainObject = (value) => !!value && typeof value === "object" && !Array.isArray(value);
|
|
25
|
+
|
|
26
|
+
// Persistence values are JSON-shaped. Recursing here keeps duplicateScene
|
|
27
|
+
// independent without borrowing the shot document's schema or runtime types.
|
|
28
|
+
function cloneValue(value, copies = new WeakMap()) {
|
|
29
|
+
if (value === null || typeof value === "string" || typeof value === "boolean") return value;
|
|
30
|
+
if (typeof value === "number") return Number.isFinite(value) ? value : null;
|
|
31
|
+
if (typeof value !== "object") return null;
|
|
32
|
+
if (copies.has(value)) return copies.get(value);
|
|
33
|
+
if (Array.isArray(value)) {
|
|
34
|
+
const copy = [];
|
|
35
|
+
copies.set(value, copy);
|
|
36
|
+
for (const entry of value) copy.push(cloneValue(entry, copies));
|
|
37
|
+
return copy;
|
|
38
|
+
}
|
|
39
|
+
const copy = {};
|
|
40
|
+
copies.set(value, copy);
|
|
41
|
+
for (const [key, entry] of Object.entries(value)) {
|
|
42
|
+
Object.defineProperty(copy, key, {
|
|
43
|
+
value: cloneValue(entry, copies),
|
|
44
|
+
enumerable: true,
|
|
45
|
+
writable: true,
|
|
46
|
+
configurable: true,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
return copy;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function createSceneStage(stage = null) {
|
|
53
|
+
const source = plainObject(stage) ? stage : {};
|
|
54
|
+
return {
|
|
55
|
+
...cloneValue(DEFAULT_SCENE_STAGE),
|
|
56
|
+
...cloneValue(source),
|
|
57
|
+
charA: { ...cloneValue(DEFAULT_SCENE_STAGE.charA), ...cloneValue(plainObject(source.charA) ? source.charA : {}) },
|
|
58
|
+
charB: { ...cloneValue(DEFAULT_SCENE_STAGE.charB), ...cloneValue(plainObject(source.charB) ? source.charB : {}) },
|
|
59
|
+
showB: source.showB === true,
|
|
60
|
+
hasCharSheet: source.hasCharSheet === true,
|
|
61
|
+
subject: typeof source.subject === "string" ? source.subject : DEFAULT_SCENE_STAGE.subject,
|
|
62
|
+
subject2: typeof source.subject2 === "string" ? source.subject2 : DEFAULT_SCENE_STAGE.subject2,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function uniqueId(existing) {
|
|
67
|
+
const ids = new Set(existing.map((scene) => scene?.id));
|
|
68
|
+
let id;
|
|
69
|
+
do id = `scene-${Date.now().toString(36)}-${sceneSequence++}`;
|
|
70
|
+
while (ids.has(id));
|
|
71
|
+
return id;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function uniqueName(requested, existing) {
|
|
75
|
+
const nameKey = (name) => typeof name === "string" ? name.normalize("NFKC").toLowerCase() : "";
|
|
76
|
+
const names = new Set(existing.map((scene) => nameKey(scene?.name)));
|
|
77
|
+
const hasName = (name) => names.has(nameKey(name));
|
|
78
|
+
const base = typeof requested === "string" && requested.trim() ? requested.trim() : "SCENE 01";
|
|
79
|
+
if (!hasName(base)) return base;
|
|
80
|
+
const numbered = base.match(/^(.*?)(\d+)$/);
|
|
81
|
+
if (numbered) {
|
|
82
|
+
const [, prefix, digits] = numbered;
|
|
83
|
+
for (let number = Number(digits) + 1; ; number += 1) {
|
|
84
|
+
const candidate = `${prefix}${String(number).padStart(digits.length, "0")}`;
|
|
85
|
+
if (!hasName(candidate)) return candidate;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
for (let number = 2; ; number += 1) {
|
|
89
|
+
const candidate = `${base} ${number}`;
|
|
90
|
+
if (!hasName(candidate)) return candidate;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function createScene(name = "SCENE 01", existing = []) {
|
|
95
|
+
return { id: uniqueId(existing), name: uniqueName(name, existing), objects: [], shotDocument: null, stage: createSceneStage() };
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export function addScene(scenes, name = "SCENE 01") {
|
|
99
|
+
const list = Array.isArray(scenes) ? scenes : [];
|
|
100
|
+
return [...list, createScene(name, list)];
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export function duplicateScene(scenes, index) {
|
|
104
|
+
if (!Array.isArray(scenes) || index < 0 || index >= scenes.length) return scenes;
|
|
105
|
+
const source = scenes[index];
|
|
106
|
+
const duplicate = createScene(source.name, scenes);
|
|
107
|
+
duplicate.objects = cloneValue(source.objects);
|
|
108
|
+
duplicate.shotDocument = cloneValue(source.shotDocument);
|
|
109
|
+
duplicate.stage = createSceneStage(source.stage);
|
|
110
|
+
return [...scenes.slice(0, index + 1), duplicate, ...scenes.slice(index + 1)];
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export function renameScene(scenes, index, name) {
|
|
114
|
+
if (!Array.isArray(scenes) || index < 0 || index >= scenes.length || typeof name !== "string" || !name.trim()) return scenes;
|
|
115
|
+
const others = scenes.filter((_, sceneIndex) => sceneIndex !== index);
|
|
116
|
+
const nextName = uniqueName(name, others);
|
|
117
|
+
if (nextName === scenes[index].name) return scenes;
|
|
118
|
+
return scenes.map((scene, sceneIndex) => sceneIndex === index ? { ...scene, name: nextName } : scene);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export function removeScene(scenes, index) {
|
|
122
|
+
if (!Array.isArray(scenes) || scenes.length <= 1 || index < 0 || index >= scenes.length) return scenes;
|
|
123
|
+
return scenes.filter((_, sceneIndex) => sceneIndex !== index);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export function activeSceneIndex(scenes, activeSceneId) {
|
|
127
|
+
if (!Array.isArray(scenes) || !scenes.length) return -1;
|
|
128
|
+
const index = scenes.findIndex((scene) => scene.id === activeSceneId);
|
|
129
|
+
return index < 0 ? 0 : index;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export function activeScene(scenes, activeSceneId) {
|
|
133
|
+
const index = activeSceneIndex(scenes, activeSceneId);
|
|
134
|
+
return index < 0 ? null : scenes[index];
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export function createSceneDocument() {
|
|
138
|
+
const scene = createScene();
|
|
139
|
+
return { version: SCENES_VERSION, activeSceneId: scene.id, scenes: [scene] };
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function repairScene(record, existing, fallbackNumber, fallbackStage) {
|
|
143
|
+
if (!plainObject(record) || typeof record.id !== "string" || !record.id || !Array.isArray(record.objects)) return null;
|
|
144
|
+
if (existing.some((scene) => scene.id === record.id)) return null;
|
|
145
|
+
return {
|
|
146
|
+
id: record.id,
|
|
147
|
+
name: uniqueName(typeof record.name === "string" ? record.name : `SCENE ${String(fallbackNumber).padStart(2, "0")}`, existing),
|
|
148
|
+
objects: record.objects.filter(plainObject).map((object) => cloneValue(object)),
|
|
149
|
+
shotDocument: cloneValue(record.shotDocument ?? null),
|
|
150
|
+
stage: cloneValue(plainObject(record.stage) ? record.stage : fallbackStage),
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function repairDocument(payload, fallbackStage = DEFAULT_SCENE_STAGE) {
|
|
155
|
+
const scenes = [];
|
|
156
|
+
let dropped = 0;
|
|
157
|
+
for (const record of payload.scenes) {
|
|
158
|
+
const scene = repairScene(record, scenes, scenes.length + 1, fallbackStage);
|
|
159
|
+
if (scene) scenes.push(scene);
|
|
160
|
+
else dropped += 1;
|
|
161
|
+
}
|
|
162
|
+
if (!scenes.length) scenes.push(createScene());
|
|
163
|
+
const index = activeSceneIndex(scenes, payload.activeSceneId);
|
|
164
|
+
return { document: { version: SCENES_VERSION, activeSceneId: scenes[index].id, scenes }, dropped };
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function parse(raw) {
|
|
168
|
+
try {
|
|
169
|
+
return JSON.parse(raw);
|
|
170
|
+
} catch {
|
|
171
|
+
return null;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/** Tagged, side-effect-free reader. The caller decides when quarantine bytes
|
|
176
|
+
* are written; future payloads are deliberately returned without a document. */
|
|
177
|
+
export function readSceneDocument(raw, legacyRaw = null) {
|
|
178
|
+
if (raw === null || raw === undefined || raw === "") {
|
|
179
|
+
if (legacyRaw !== null && legacyRaw !== undefined && legacyRaw !== "") {
|
|
180
|
+
const legacy = parse(legacyRaw);
|
|
181
|
+
if (!plainObject(legacy) || legacy.version !== 1 || !Array.isArray(legacy.objects)) {
|
|
182
|
+
return { status: "corrupt", document: createSceneDocument(), dropped: 0, quarantineRaw: legacyRaw };
|
|
183
|
+
}
|
|
184
|
+
const document = createSceneDocument();
|
|
185
|
+
document.scenes[0].objects = legacy.objects.filter(plainObject).map((object) => cloneValue(object));
|
|
186
|
+
return { status: "migrated", document, dropped: legacy.objects.length - document.scenes[0].objects.length };
|
|
187
|
+
}
|
|
188
|
+
return { status: "absent", document: createSceneDocument(), dropped: 0 };
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
const payload = parse(raw);
|
|
192
|
+
if (!plainObject(payload) || !Number.isInteger(payload.version) || payload.version < 1) {
|
|
193
|
+
return { status: "corrupt", document: createSceneDocument(), dropped: 0, quarantineRaw: raw };
|
|
194
|
+
}
|
|
195
|
+
if (payload.version > SCENES_VERSION) return { status: "future", document: null, dropped: 0 };
|
|
196
|
+
if (!Array.isArray(payload.scenes)) {
|
|
197
|
+
return { status: "corrupt", document: createSceneDocument(), dropped: 0, quarantineRaw: raw };
|
|
198
|
+
}
|
|
199
|
+
const migrating = payload.version < SCENES_VERSION;
|
|
200
|
+
const repaired = repairDocument(payload, createSceneStage(payload.stage));
|
|
201
|
+
return { status: migrating ? "migrated" : "valid", ...repaired };
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export function serializeSceneDocument(document) {
|
|
205
|
+
return JSON.stringify({ version: SCENES_VERSION, activeSceneId: document.activeSceneId, scenes: document.scenes });
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/** Storage adapter: quarantine corrupt bytes, persist successful migration,
|
|
209
|
+
* and never write over a future document. The legacy key remains as a backup. */
|
|
210
|
+
export function loadSceneDocumentFromStorage(storage) {
|
|
211
|
+
const currentRaw = storage.getItem(SCENES_STORAGE_KEY);
|
|
212
|
+
const previousRaw = currentRaw ? null : storage.getItem(PREVIOUS_SCENES_STORAGE_KEY);
|
|
213
|
+
const raw = currentRaw || previousRaw;
|
|
214
|
+
const legacyRaw = raw ? null : storage.getItem(LEGACY_SCENE_STORAGE_KEY);
|
|
215
|
+
const result = readSceneDocument(raw, legacyRaw);
|
|
216
|
+
if (result.status === "corrupt" && result.quarantineRaw !== undefined) {
|
|
217
|
+
storage.setItem(SCENES_QUARANTINE_KEY, result.quarantineRaw);
|
|
218
|
+
}
|
|
219
|
+
if (result.status === "migrated") {
|
|
220
|
+
storage.setItem(SCENES_STORAGE_KEY, serializeSceneDocument(result.document));
|
|
221
|
+
}
|
|
222
|
+
return result;
|
|
223
|
+
}
|
package/src/shot-authoring.js
CHANGED
|
@@ -1,71 +1,66 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Shot-authoring persistence
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* deliberately not stored — a refresh should reopen the authored shot, not
|
|
6
|
-
* resume a half-played preview.
|
|
2
|
+
* Shot-authoring persistence. Like the scene store, the version lives in the
|
|
3
|
+
* key and body. Bad bytes are identified for quarantine by the caller, while
|
|
4
|
+
* future bytes are left in place for the newer app that understands them.
|
|
7
5
|
*/
|
|
8
6
|
|
|
9
|
-
|
|
7
|
+
import { createShot } from "./cuts.js";
|
|
8
|
+
|
|
9
|
+
export const SHOT_AUTHORING_VERSION = 3;
|
|
10
|
+
export const SHOT_AUTHORING_KEY = "cozyclay.shot-authoring.v3";
|
|
11
|
+
// The single-key alias points at the newest legacy body for older callers.
|
|
12
|
+
// New readers should walk the list so a user can still arrive directly from v1.
|
|
13
|
+
export const SHOT_AUTHORING_LEGACY_KEY = "cozyclay.shot-authoring.v2";
|
|
14
|
+
export const SHOT_AUTHORING_LEGACY_KEYS = Object.freeze([
|
|
15
|
+
SHOT_AUTHORING_LEGACY_KEY,
|
|
16
|
+
"cozyclay.shot-authoring.v1",
|
|
17
|
+
]);
|
|
18
|
+
export const SHOT_AUTHORING_QUARANTINE_KEY = "cozyclay.shot-authoring.v3.quarantine";
|
|
10
19
|
|
|
11
20
|
/** clip length sanity bounds, frames @ 20 fps: 1 s .. 20 min */
|
|
12
21
|
const FRAME_COUNT_MIN = 20;
|
|
13
22
|
const FRAME_COUNT_MAX = 24000;
|
|
14
|
-
|
|
23
|
+
const DEFAULT_FRAME_COUNT = 120;
|
|
24
|
+
const RAIL_MAX_POINTS = 512;
|
|
15
25
|
const finite = Number.isFinite;
|
|
16
26
|
|
|
17
|
-
/** framing = { pos: {x,y,z}, yaw, pitch, fovDeg }, all finite numbers */
|
|
18
|
-
function validFraming(framing) {
|
|
19
|
-
return (
|
|
20
|
-
!!framing &&
|
|
21
|
-
typeof framing === "object" &&
|
|
22
|
-
!!framing.pos &&
|
|
23
|
-
finite(framing.pos.x) &&
|
|
24
|
-
finite(framing.pos.y) &&
|
|
25
|
-
finite(framing.pos.z) &&
|
|
26
|
-
finite(framing.yaw) &&
|
|
27
|
-
finite(framing.pitch) &&
|
|
28
|
-
finite(framing.fovDeg)
|
|
29
|
-
);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/** follow-cam parameter bounds: anything outside is a corrupt write, clamp */
|
|
33
27
|
const FOLLOW_BOUNDS = {
|
|
34
28
|
distance: [0.5, 15],
|
|
35
29
|
height: [0.2, 6],
|
|
36
30
|
response: [0.1, 3],
|
|
37
31
|
lead: [0, 1],
|
|
32
|
+
maxDollySpeed: [0.2, 8],
|
|
33
|
+
pitchOffsetDeg: [-30, 30],
|
|
38
34
|
};
|
|
39
|
-
const
|
|
35
|
+
const FOLLOW_DEFAULTS = {
|
|
36
|
+
distance: 3,
|
|
37
|
+
height: 1.6,
|
|
38
|
+
response: 0.7,
|
|
39
|
+
lead: 0.25,
|
|
40
|
+
railStartMode: "head",
|
|
41
|
+
maxDollySpeed: 4,
|
|
42
|
+
pitchOffsetDeg: 0,
|
|
43
|
+
};
|
|
44
|
+
const CAMERA_MODES = new Set(["keys", "follow", "rail"]);
|
|
40
45
|
|
|
41
|
-
|
|
42
|
-
return
|
|
46
|
+
function validFraming(framing) {
|
|
47
|
+
return (
|
|
48
|
+
!!framing && typeof framing === "object" && !!framing.pos &&
|
|
49
|
+
finite(framing.pos.x) && finite(framing.pos.y) && finite(framing.pos.z) &&
|
|
50
|
+
finite(framing.yaw) && finite(framing.pitch) && finite(framing.fovDeg)
|
|
51
|
+
);
|
|
43
52
|
}
|
|
44
53
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
return null;
|
|
56
|
-
}
|
|
57
|
-
if (!parsed || typeof parsed !== "object") return null;
|
|
58
|
-
|
|
59
|
-
const frameCount = finite(parsed.frameCount)
|
|
60
|
-
? Math.max(FRAME_COUNT_MIN, Math.min(FRAME_COUNT_MAX, Math.round(parsed.frameCount)))
|
|
61
|
-
: null;
|
|
62
|
-
|
|
63
|
-
const keysByFrame = new Map();
|
|
64
|
-
for (const key of Array.isArray(parsed.cameraKeys) ? parsed.cameraKeys : []) {
|
|
65
|
-
if (!key || !finite(key.frame) || key.frame < 0 || !validFraming(key.framing)) continue;
|
|
66
|
-
const frame = Math.round(key.frame);
|
|
67
|
-
// duplicate frames keep the later entry, matching re-key semantics
|
|
68
|
-
keysByFrame.set(frame, {
|
|
54
|
+
function repairFrameCount(value) {
|
|
55
|
+
return finite(value) ? Math.max(FRAME_COUNT_MIN, Math.min(FRAME_COUNT_MAX, Math.round(value))) : null;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function repairKeys(entries, minFrame, maxFrame) {
|
|
59
|
+
const byFrame = new Map();
|
|
60
|
+
for (const key of Array.isArray(entries) ? entries : []) {
|
|
61
|
+
if (!key || !finite(key.frame) || !validFraming(key.framing)) continue;
|
|
62
|
+
const frame = Math.max(minFrame, Math.min(maxFrame, Math.round(key.frame)));
|
|
63
|
+
byFrame.set(frame, {
|
|
69
64
|
frame,
|
|
70
65
|
framing: {
|
|
71
66
|
pos: { x: key.framing.pos.x, y: key.framing.pos.y, z: key.framing.pos.z },
|
|
@@ -75,39 +70,171 @@ export function loadShotAuthoring(raw) {
|
|
|
75
70
|
},
|
|
76
71
|
});
|
|
77
72
|
}
|
|
78
|
-
|
|
73
|
+
return [...byFrame.values()].sort((a, b) => a.frame - b.frame);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function repairShots(entries, frameCount, inheritedCamera = null) {
|
|
77
|
+
const candidates = [];
|
|
78
|
+
for (const entry of Array.isArray(entries) ? entries : []) {
|
|
79
|
+
if (!entry || typeof entry !== "object" || !finite(entry.startFrame)) continue;
|
|
80
|
+
const startFrame = Math.max(0, Math.min(frameCount - 1, Math.round(entry.startFrame)));
|
|
81
|
+
candidates.push({ entry, startFrame });
|
|
82
|
+
}
|
|
83
|
+
candidates.sort((a, b) => a.startFrame - b.startFrame);
|
|
84
|
+
if (!candidates.length) return [];
|
|
79
85
|
|
|
80
|
-
|
|
81
|
-
|
|
86
|
+
// One boundary per frame. The later stored entry wins, just like re-keying.
|
|
87
|
+
const byStart = new Map(candidates.map((candidate) => [candidate.startFrame, candidate.entry]));
|
|
88
|
+
const ordered = [...byStart.entries()].sort((a, b) => a[0] - b[0]);
|
|
89
|
+
const seenIds = new Set();
|
|
90
|
+
return ordered.map(([startFrame, entry], index) => {
|
|
91
|
+
const nextStart = ordered[index + 1]?.[0] ?? frameCount;
|
|
92
|
+
// Pre-overlay v3 bodies had no endFrame and were gapless by definition.
|
|
93
|
+
// Infer their old boundary exactly; new bodies persist an explicit end.
|
|
94
|
+
const storedEnd = finite(entry.endFrame) ? Math.round(entry.endFrame) : nextStart - 1;
|
|
95
|
+
const endFrame = Math.max(startFrame, Math.min(frameCount - 1, nextStart - 1, storedEnd));
|
|
96
|
+
const fallback = createShot(`Shot ${index + 1}`, startFrame, endFrame);
|
|
97
|
+
const storedId = typeof entry.id === "string" && entry.id.trim() && !seenIds.has(entry.id) ? entry.id : fallback.id;
|
|
98
|
+
seenIds.add(storedId);
|
|
99
|
+
return {
|
|
100
|
+
id: storedId,
|
|
101
|
+
name: typeof entry.name === "string" && entry.name.trim() ? entry.name.trim() : `Shot ${index + 1}`,
|
|
102
|
+
startFrame,
|
|
103
|
+
endFrame,
|
|
104
|
+
cameraKeys: repairKeys(entry.cameraKeys, startFrame, endFrame),
|
|
105
|
+
camera: repairCamera(inheritedCamera ?? entry.camera),
|
|
106
|
+
};
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function repairWaypoints(entries) {
|
|
111
|
+
const byFrame = new Map();
|
|
112
|
+
for (const waypoint of Array.isArray(entries) ? entries : []) {
|
|
82
113
|
if (!waypoint || !finite(waypoint.frame) || waypoint.frame < 0 || !finite(waypoint.x) || !finite(waypoint.z)) continue;
|
|
83
114
|
const frame = Math.round(waypoint.frame);
|
|
84
|
-
|
|
85
|
-
frame,
|
|
86
|
-
x: waypoint.x,
|
|
87
|
-
z: waypoint.z,
|
|
88
|
-
heading: finite(waypoint.heading) ? waypoint.heading : null,
|
|
89
|
-
});
|
|
115
|
+
byFrame.set(frame, { frame, x: waypoint.x, z: waypoint.z, heading: finite(waypoint.heading) ? waypoint.heading : null });
|
|
90
116
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
117
|
+
return [...byFrame.values()].sort((a, b) => a.frame - b.frame);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function repairFollowCam(value) {
|
|
121
|
+
const source = value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
122
|
+
const followCam = { ...FOLLOW_DEFAULTS };
|
|
123
|
+
followCam.railStartMode = source.railStartMode === "nearest" ? "nearest" : FOLLOW_DEFAULTS.railStartMode;
|
|
124
|
+
for (const [key, [min, max]] of Object.entries(FOLLOW_BOUNDS)) {
|
|
125
|
+
if (finite(source[key])) followCam[key] = Math.max(min, Math.min(max, source[key]));
|
|
126
|
+
}
|
|
127
|
+
return followCam;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function repairRail(value) {
|
|
131
|
+
if (!Array.isArray(value)) return null;
|
|
132
|
+
const points = value.filter((point) => point && finite(point.x) && finite(point.z))
|
|
133
|
+
.slice(0, RAIL_MAX_POINTS).map((point) => ({ x: point.x, z: point.z }));
|
|
134
|
+
return points.length >= 2 ? points : null;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function repairRailFollow(value) {
|
|
138
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return null;
|
|
139
|
+
if (value.mode === "off") return { mode: "off" };
|
|
140
|
+
if (value.mode !== "range" || !finite(value.startFrame) || !finite(value.endFrame)) return null;
|
|
141
|
+
const startFrame = Math.max(0, Math.round(value.startFrame));
|
|
142
|
+
const endFrame = Math.max(0, Math.round(value.endFrame));
|
|
143
|
+
return startFrame <= endFrame ? { mode: "range", startFrame, endFrame } : null;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function repairCamera(value) {
|
|
147
|
+
const source = value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
148
|
+
const cameraRail = repairRail(source.cameraRail);
|
|
149
|
+
let mode = CAMERA_MODES.has(source.mode) ? source.mode : "keys";
|
|
150
|
+
// A rail block without a usable two-point rail behaves like ordinary
|
|
151
|
+
// follow, never like a mysteriously enabled but motionless dolly.
|
|
152
|
+
if (mode === "rail" && !cameraRail) mode = "follow";
|
|
153
|
+
return { mode, followCam: repairFollowCam(source.followCam), cameraRail, railFollow: repairRailFollow(source.railFollow) };
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function migratedCamera(followCam, cameraRail, railFollow = null) {
|
|
157
|
+
const rail = repairRail(cameraRail);
|
|
158
|
+
const enabled = followCam?.enabled === true;
|
|
159
|
+
return repairCamera({
|
|
160
|
+
mode: enabled ? (rail ? "rail" : "follow") : "keys",
|
|
161
|
+
followCam,
|
|
162
|
+
cameraRail: rail,
|
|
163
|
+
railFollow,
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function repairShared(parsed, frameCount) {
|
|
168
|
+
return {
|
|
169
|
+
frameCount,
|
|
170
|
+
waypoints: repairWaypoints(parsed.waypoints),
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Build a transport-neutral shot document. It can live at the root today or
|
|
176
|
+
* be nested under a future Scene document without changing its schema.
|
|
177
|
+
*/
|
|
178
|
+
export function createShotAuthoringDocument({ shots = [], waypoints = [], frameCount = null } = {}) {
|
|
179
|
+
const repairedFrameCount = repairFrameCount(frameCount);
|
|
180
|
+
const effectiveFrameCount = repairedFrameCount ?? DEFAULT_FRAME_COUNT;
|
|
181
|
+
return {
|
|
182
|
+
version: SHOT_AUTHORING_VERSION,
|
|
183
|
+
frameCount: repairedFrameCount,
|
|
184
|
+
shots: repairShots(shots, effectiveFrameCount),
|
|
185
|
+
waypoints: repairWaypoints(waypoints),
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/** Pure object reader; storage adapters decide how bytes become this object. */
|
|
190
|
+
export function readShotAuthoringDocument(parsed) {
|
|
191
|
+
if (parsed === undefined) return { status: "absent", state: null };
|
|
192
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return { status: "corrupt", state: null };
|
|
193
|
+
const version = parsed.version === undefined ? 1 : parsed.version;
|
|
194
|
+
if (!Number.isInteger(version) || version < 1) return { status: "corrupt", state: null };
|
|
195
|
+
if (version > SHOT_AUTHORING_VERSION) return { status: "future", state: null };
|
|
196
|
+
|
|
197
|
+
const frameCount = repairFrameCount(parsed.frameCount);
|
|
198
|
+
const effectiveFrameCount = frameCount ?? DEFAULT_FRAME_COUNT;
|
|
199
|
+
if (version === 1) {
|
|
200
|
+
const keys = repairKeys(parsed.cameraKeys, 0, effectiveFrameCount - 1);
|
|
201
|
+
const camera = migratedCamera(parsed.followCam, parsed.cameraRail, parsed.railFollow);
|
|
202
|
+
// v1 was one whole-timeline camera roll even when it had no keys.
|
|
203
|
+
const shots = [createShot("Shot 1", 0, effectiveFrameCount - 1, keys, repairCamera(camera))];
|
|
204
|
+
return {
|
|
205
|
+
status: "migrated",
|
|
206
|
+
state: { ...repairShared(parsed, frameCount), shots },
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
if (!Array.isArray(parsed.shots)) return { status: "corrupt", state: null };
|
|
210
|
+
if (version === 2) {
|
|
211
|
+
const camera = migratedCamera(parsed.followCam, parsed.cameraRail, parsed.railFollow);
|
|
212
|
+
return {
|
|
213
|
+
status: "migrated",
|
|
214
|
+
state: { ...repairShared(parsed, frameCount), shots: repairShots(parsed.shots, effectiveFrameCount, camera) },
|
|
215
|
+
};
|
|
100
216
|
}
|
|
217
|
+
return {
|
|
218
|
+
status: "valid",
|
|
219
|
+
state: { ...repairShared(parsed, frameCount), shots: repairShots(parsed.shots, effectiveFrameCount) },
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/** JSON compatibility adapters used by App and older model callers. */
|
|
224
|
+
export function serializeShotAuthoring(state) {
|
|
225
|
+
return JSON.stringify(createShotAuthoringDocument(state));
|
|
226
|
+
}
|
|
101
227
|
|
|
102
|
-
|
|
103
|
-
if (
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
// one point is not a rail; keep null so the app falls back to free follow
|
|
109
|
-
if (points.length >= 2) cameraRail = points;
|
|
228
|
+
export function readShotAuthoring(raw) {
|
|
229
|
+
if (raw === null || raw === undefined || raw === "") return { status: "absent", state: null };
|
|
230
|
+
try {
|
|
231
|
+
return readShotAuthoringDocument(JSON.parse(raw));
|
|
232
|
+
} catch {
|
|
233
|
+
return { status: "corrupt", state: null };
|
|
110
234
|
}
|
|
235
|
+
}
|
|
111
236
|
|
|
112
|
-
|
|
237
|
+
/** Compatibility-shaped convenience for model callers and tests. */
|
|
238
|
+
export function loadShotAuthoring(raw) {
|
|
239
|
+
return readShotAuthoring(raw).state;
|
|
113
240
|
}
|