@catchlight/editor-web 0.0.0 → 0.5.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/LICENSE-APACHE +201 -0
- package/LICENSE-MIT +21 -0
- package/README.md +26 -2
- package/THIRD-PARTY-NOTICES.md +331 -0
- package/dist/editor/CatchlightEditor.d.ts +21 -0
- package/dist/editor/CatchlightEditor.js +720 -0
- package/dist/editor/dialogs.d.ts +18 -0
- package/dist/editor/dialogs.js +71 -0
- package/dist/editor/import-panel.d.ts +6 -0
- package/dist/editor/import-panel.js +98 -0
- package/dist/editor/logo.svg +11 -0
- package/dist/editor/notification.d.ts +4 -0
- package/dist/editor/notification.js +24 -0
- package/dist/editor/stage.d.ts +13 -0
- package/dist/editor/stage.js +24 -0
- package/dist/editor/test/setup.d.ts +5 -0
- package/dist/editor/test/setup.js +5 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +10 -0
- package/dist/lib/animations-panel.d.ts +10 -0
- package/dist/lib/animations-panel.js +48 -0
- package/dist/lib/authoring.d.ts +17 -0
- package/dist/lib/authoring.js +116 -0
- package/dist/lib/binding-grid.d.ts +19 -0
- package/dist/lib/binding-grid.js +92 -0
- package/dist/lib/bindings.d.ts +21 -0
- package/dist/lib/bindings.js +100 -0
- package/dist/lib/camera.d.ts +21 -0
- package/dist/lib/camera.js +61 -0
- package/dist/lib/controls-panel.d.ts +36 -0
- package/dist/lib/controls-panel.js +201 -0
- package/dist/lib/controls.d.ts +103 -0
- package/dist/lib/controls.js +162 -0
- package/dist/lib/editing.d.ts +126 -0
- package/dist/lib/editing.js +415 -0
- package/dist/lib/editor-context.d.ts +9 -0
- package/dist/lib/editor-context.js +13 -0
- package/dist/lib/expressions-panel.d.ts +10 -0
- package/dist/lib/expressions-panel.js +120 -0
- package/dist/lib/file-open.d.ts +11 -0
- package/dist/lib/file-open.js +25 -0
- package/dist/lib/file-save.d.ts +29 -0
- package/dist/lib/file-save.js +68 -0
- package/dist/lib/gizmo.d.ts +13 -0
- package/dist/lib/gizmo.js +247 -0
- package/dist/lib/image-markup.d.ts +12 -0
- package/dist/lib/image-markup.js +153 -0
- package/dist/lib/index.d.ts +71 -0
- package/dist/lib/index.js +44 -0
- package/dist/lib/inspector.d.ts +19 -0
- package/dist/lib/inspector.js +161 -0
- package/dist/lib/latest.d.ts +3 -0
- package/dist/lib/latest.js +9 -0
- package/dist/lib/layer-import.d.ts +38 -0
- package/dist/lib/layer-import.js +187 -0
- package/dist/lib/mesh-editor.d.ts +13 -0
- package/dist/lib/mesh-editor.js +337 -0
- package/dist/lib/model-panels.d.ts +23 -0
- package/dist/lib/model-panels.js +180 -0
- package/dist/lib/node-actions.d.ts +42 -0
- package/dist/lib/node-actions.js +115 -0
- package/dist/lib/node-drag.d.ts +18 -0
- package/dist/lib/node-drag.js +65 -0
- package/dist/lib/node-patch.d.ts +8 -0
- package/dist/lib/node-patch.js +10 -0
- package/dist/lib/node-tree.d.ts +36 -0
- package/dist/lib/node-tree.js +221 -0
- package/dist/lib/official.d.ts +82 -0
- package/dist/lib/official.js +197 -0
- package/dist/lib/param-actions.d.ts +48 -0
- package/dist/lib/param-actions.js +106 -0
- package/dist/lib/param-list.d.ts +36 -0
- package/dist/lib/param-list.js +73 -0
- package/dist/lib/param-slider.d.ts +44 -0
- package/dist/lib/param-slider.js +149 -0
- package/dist/lib/pose.d.ts +13 -0
- package/dist/lib/pose.js +32 -0
- package/dist/lib/posing-panel.d.ts +40 -0
- package/dist/lib/posing-panel.js +154 -0
- package/dist/lib/presence.d.ts +27 -0
- package/dist/lib/presence.js +98 -0
- package/dist/lib/properties-panel.d.ts +13 -0
- package/dist/lib/properties-panel.js +63 -0
- package/dist/lib/recording-panel.d.ts +4 -0
- package/dist/lib/recording-panel.js +161 -0
- package/dist/lib/replica.d.ts +18 -0
- package/dist/lib/replica.js +34 -0
- package/dist/lib/review.d.ts +113 -0
- package/dist/lib/review.js +529 -0
- package/dist/lib/rigging.d.ts +10 -0
- package/dist/lib/rigging.js +116 -0
- package/dist/lib/selection.d.ts +3 -0
- package/dist/lib/selection.js +2 -0
- package/dist/lib/session-list.d.ts +16 -0
- package/dist/lib/session-list.js +7 -0
- package/dist/lib/sessions.d.ts +8 -0
- package/dist/lib/sessions.js +29 -0
- package/dist/lib/test/harness.d.ts +32 -0
- package/dist/lib/test/harness.js +139 -0
- package/dist/lib/test/setup.d.ts +4 -0
- package/dist/lib/test/setup.js +5 -0
- package/dist/lib/versions.d.ts +69 -0
- package/dist/lib/versions.js +250 -0
- package/dist/lib/viewport.d.ts +57 -0
- package/dist/lib/viewport.js +315 -0
- package/dist/lib/workspace-layout.d.ts +24 -0
- package/dist/lib/workspace-layout.js +145 -0
- package/dist/lib/workspace.d.ts +29 -0
- package/dist/lib/workspace.js +263 -0
- package/dist/theme.css +4573 -0
- package/package.json +32 -6
|
@@ -0,0 +1,720 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
/** A close moves the screen to a live session before an effect frees the old replica. */
|
|
3
|
+
import { opensLayers, opensModel } from "@catchlight/editor-core";
|
|
4
|
+
import { AnimationsPanel, AssetsPanel, EditingProvider, useEditing, WorkspaceModes, EditingBar, MeshTools, MeshInspector, RecordingInspector, RecordingKeys, meshBounds, fitCamera, BindingsPanel, ControlsPanel, Disclosure, EditorProvider, EmptyState, ExpressionsPanel, ExtensionsPanel, FileOpen, FileSave, Icon, IconButton, Modal, ModelHealth, NodeTree, MotionToggle, ParamsPanel, PresenceProvider, PropertiesPanel, ReviewPanel, ReviewProvider, ReviewStatus, useReview, SearchField, SessionList, WeldsPanel, downloadName, kindIcons, kindLabels, useEditor, useFileSave, useLayerImport, useParams, usePosePublisher, usePlayingClip, usePoseSweep, useSelection, useSessions, useViewportCamera, useWorkspaceActions, usePanelSize, useDismissMenus, usePreviewExport, captureCanvas, useVersions, useVersionView, VersionBanner, VersionSelect, } from "../lib/index.js";
|
|
5
|
+
import { useCallback, useEffect, useId, useRef, useState } from "react";
|
|
6
|
+
import { Stage, Environment } from "./stage.js";
|
|
7
|
+
import { CommandPalette, Shortcuts } from "./dialogs.js";
|
|
8
|
+
import { ImportPanel } from "./import-panel.js";
|
|
9
|
+
import { Notification } from "./notification.js";
|
|
10
|
+
const logoUrl = new URL("./logo.svg", import.meta.url)
|
|
11
|
+
.href;
|
|
12
|
+
/** The Model tab lists them all. */
|
|
13
|
+
function migrated(warnings) {
|
|
14
|
+
const [first] = warnings;
|
|
15
|
+
if (first === undefined)
|
|
16
|
+
return undefined;
|
|
17
|
+
const more = warnings.length - 1;
|
|
18
|
+
return more === 0 ? first : `${first} (${more} more in the Model tab.)`;
|
|
19
|
+
}
|
|
20
|
+
export function CatchlightEditor({ editor, className, onOpenStarter, agentConnect, reviewer, }) {
|
|
21
|
+
return (_jsx("div", { className: className ? `catchlight ${className}` : "catchlight", children: _jsx(EditorProvider, { editor: editor, children: _jsx(Shell, { ...(onOpenStarter ? { onOpenStarter } : {}), ...(agentConnect ? { agentConnect } : {}), ...(reviewer ? { reviewer } : {}) }) }) }));
|
|
22
|
+
}
|
|
23
|
+
function Shell({ onOpenStarter, agentConnect, reviewer, }) {
|
|
24
|
+
const editor = useEditor();
|
|
25
|
+
const listed = useSessions().sessions;
|
|
26
|
+
// A version open for viewing is shown in place of its model, never as a tab.
|
|
27
|
+
const sessions = listed.filter((s) => !s.viewing);
|
|
28
|
+
const [session, setSession] = useState();
|
|
29
|
+
const [problem, setProblem] = useState();
|
|
30
|
+
const [notice, setNotice] = useState();
|
|
31
|
+
/** What opening an older file changed; stays until dismissed. */
|
|
32
|
+
const [migration, setMigration] = useState();
|
|
33
|
+
const [closing, setClosing] = useState();
|
|
34
|
+
const [confirmClose, setConfirmClose] = useState();
|
|
35
|
+
const [reviewAsked, setReviewAsked] = useState(0);
|
|
36
|
+
const askReview = useCallback(() => setReviewAsked((n) => n + 1), []);
|
|
37
|
+
const dismissed = useRef(new Set());
|
|
38
|
+
/** Sessions whose migration notice this page has already shown. */
|
|
39
|
+
const warned = useRef(new Set());
|
|
40
|
+
/**
|
|
41
|
+
* The first time this page shows `next`, tells what opening it changed. A
|
|
42
|
+
* notice already up for `next` stays, since the page's own open and the
|
|
43
|
+
* attach that follows a close can both arrive for one session.
|
|
44
|
+
*/
|
|
45
|
+
const showMigration = useCallback((next) => {
|
|
46
|
+
const text = warned.current.has(next.id) ? undefined : migrated(next.openWarnings);
|
|
47
|
+
if (text)
|
|
48
|
+
warned.current.add(next.id);
|
|
49
|
+
setMigration((shown) => text ? { session: next.id, text } : shown?.session === next.id ? shown : undefined);
|
|
50
|
+
}, []);
|
|
51
|
+
const request = useRef(0);
|
|
52
|
+
const failed = useCallback((cause) => setProblem(cause instanceof Error ? cause.message : String(cause)), []);
|
|
53
|
+
const opened = useCallback((next) => {
|
|
54
|
+
++request.current;
|
|
55
|
+
setProblem(undefined);
|
|
56
|
+
setNotice(undefined);
|
|
57
|
+
showMigration(next);
|
|
58
|
+
setSession(next);
|
|
59
|
+
}, [showMigration]);
|
|
60
|
+
const choose = useCallback((info) => {
|
|
61
|
+
const generation = ++request.current;
|
|
62
|
+
void editor.attachSession(info).then((next) => {
|
|
63
|
+
if (generation === request.current)
|
|
64
|
+
opened(next);
|
|
65
|
+
}, failed);
|
|
66
|
+
}, [editor, opened, failed]);
|
|
67
|
+
const create = useCallback(() => {
|
|
68
|
+
void editor.newSession().then(opened, failed);
|
|
69
|
+
}, [editor, opened, failed]);
|
|
70
|
+
const close = useCallback((info) => {
|
|
71
|
+
setConfirmClose(undefined);
|
|
72
|
+
if (session?.id !== info.session) {
|
|
73
|
+
void editor.closeSession(info.session).catch(failed);
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
const next = sessions.find((s) => s.session !== info.session && !dismissed.current.has(s.session));
|
|
77
|
+
const finish = (attached) => {
|
|
78
|
+
dismissed.current.add(info.session);
|
|
79
|
+
++request.current;
|
|
80
|
+
setSession(attached);
|
|
81
|
+
setNotice(undefined);
|
|
82
|
+
setMigration(undefined);
|
|
83
|
+
setClosing(info.session);
|
|
84
|
+
};
|
|
85
|
+
if (next)
|
|
86
|
+
void editor.attachSession(next).then(finish, failed);
|
|
87
|
+
else
|
|
88
|
+
finish();
|
|
89
|
+
}, [session, sessions, editor, failed]);
|
|
90
|
+
const latestClose = useRef(close);
|
|
91
|
+
latestClose.current = close;
|
|
92
|
+
const requestClose = useCallback((info) => {
|
|
93
|
+
// Applying a guarded mesh draft can dirty the model before this runs.
|
|
94
|
+
void editor.listSessions().then((listed) => {
|
|
95
|
+
const current = listed.find((s) => s.session === info.session);
|
|
96
|
+
if (!current)
|
|
97
|
+
return;
|
|
98
|
+
if (current.dirty)
|
|
99
|
+
setConfirmClose(current);
|
|
100
|
+
else
|
|
101
|
+
latestClose.current(current);
|
|
102
|
+
}, failed);
|
|
103
|
+
}, [editor, failed]);
|
|
104
|
+
useEffect(() => {
|
|
105
|
+
if (closing === undefined)
|
|
106
|
+
return;
|
|
107
|
+
setClosing(undefined);
|
|
108
|
+
void editor.closeSession(closing).catch(failed);
|
|
109
|
+
}, [closing, editor, failed]);
|
|
110
|
+
useEffect(() => {
|
|
111
|
+
if (session)
|
|
112
|
+
return;
|
|
113
|
+
const first = sessions.find((s) => !dismissed.current.has(s.session));
|
|
114
|
+
if (!first)
|
|
115
|
+
return;
|
|
116
|
+
let live = true;
|
|
117
|
+
const generation = request.current;
|
|
118
|
+
void editor.attachSession(first).then((next) => {
|
|
119
|
+
if (!live || generation !== request.current)
|
|
120
|
+
return;
|
|
121
|
+
showMigration(next);
|
|
122
|
+
setSession(next);
|
|
123
|
+
}, failed);
|
|
124
|
+
return () => {
|
|
125
|
+
live = false;
|
|
126
|
+
};
|
|
127
|
+
}, [session, sessions, editor, failed, showMigration]);
|
|
128
|
+
const versions = useVersions(session, failed, reviewer);
|
|
129
|
+
const view = useVersionView(session, versions, failed);
|
|
130
|
+
const shown = view.viewing?.session ?? session;
|
|
131
|
+
const openVersion = useCallback((number) => {
|
|
132
|
+
const version = versions.versions.find((v) => v.version === number);
|
|
133
|
+
if (version)
|
|
134
|
+
view.open(version);
|
|
135
|
+
else
|
|
136
|
+
failed(new Error(`Version ${number} is not among this model's versions.`));
|
|
137
|
+
}, [versions.versions, view, failed]);
|
|
138
|
+
useEffect(() => session?.onError(failed), [session, failed]);
|
|
139
|
+
useEffect(() => (shown !== session ? shown?.onError(failed) : undefined), [shown, session, failed]);
|
|
140
|
+
useEffect(() => {
|
|
141
|
+
const before = (e) => {
|
|
142
|
+
if (sessions.some((s) => s.dirty)) {
|
|
143
|
+
e.preventDefault();
|
|
144
|
+
e.returnValue = "";
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
window.addEventListener("beforeunload", before);
|
|
148
|
+
return () => window.removeEventListener("beforeunload", before);
|
|
149
|
+
}, [sessions]);
|
|
150
|
+
useEffect(() => {
|
|
151
|
+
if (!notice)
|
|
152
|
+
return;
|
|
153
|
+
const timer = setTimeout(() => setNotice(undefined), 4500);
|
|
154
|
+
return () => clearTimeout(timer);
|
|
155
|
+
}, [notice]);
|
|
156
|
+
return (_jsxs(PresenceProvider, { session: shown, children: [_jsx(EditingProvider, { session: shown, onError: failed, onNotice: setNotice, children: _jsx(ReviewProvider, { session: session, onError: failed, onAttention: askReview, onOpenVersion: openVersion, ...(reviewer ? { reviewer } : {}), children: _jsx(Workspace, { session: shown, live: session, versions: versions, versionView: view, reviewer: reviewer, reviewAsked: reviewAsked, info: sessions.find((s) => s.session === session?.id), onOpened: opened, onNew: create, onChoose: choose, onClose: requestClose, onError: failed, onNotice: setNotice, ...(onOpenStarter ? { onOpenStarter } : {}), ...(agentConnect ? { agentConnect } : {}) }) }) }), (problem || notice || migration) && (_jsx(Notification, { children: _jsxs("div", { "data-catchlight-toast": "", "data-error": problem ? "" : undefined, role: problem ? "alert" : "status", children: [_jsx(Icon, { name: problem || !notice ? "warning" : "check" }), _jsx("span", { ...(problem
|
|
157
|
+
? { "data-catchlight-problem": "" }
|
|
158
|
+
: { "data-catchlight-notice": "" }), children: problem ?? notice ?? migration?.text }), _jsx(IconButton, { icon: "close", label: "Dismiss notification", onClick: () => {
|
|
159
|
+
setProblem(undefined);
|
|
160
|
+
setNotice(undefined);
|
|
161
|
+
setMigration(undefined);
|
|
162
|
+
} })] }) })), confirmClose && (_jsx(CloseDialog, { info: confirmClose, onCancel: () => setConfirmClose(undefined), onClose: () => close(confirmClose), onError: failed }))] }));
|
|
163
|
+
}
|
|
164
|
+
function CloseDialog({ info, onCancel, onClose, onError, }) {
|
|
165
|
+
const editor = useEditor();
|
|
166
|
+
const [session, setSession] = useState();
|
|
167
|
+
useEffect(() => {
|
|
168
|
+
let live = true;
|
|
169
|
+
void editor.attachSession(info).then((s) => {
|
|
170
|
+
if (live)
|
|
171
|
+
setSession(s);
|
|
172
|
+
}, onError);
|
|
173
|
+
return () => {
|
|
174
|
+
live = false;
|
|
175
|
+
};
|
|
176
|
+
}, [editor, info, onError]);
|
|
177
|
+
return (_jsxs(Modal, { title: "Save your changes?", onClose: onCancel, children: [_jsxs("p", { children: ["\u201C", info.title, "\u201D has changes that haven\u2019t been saved."] }), session && (_jsx(FileSave.Root, { session: session, defaultName: downloadName(info.file ?? info.title), onSaved: onClose, onError: onError, children: "Save and close" })), _jsxs("div", { "data-catchlight-dialog-actions": "", children: [_jsx("button", { type: "button", onClick: onCancel, children: "Keep editing" }), _jsx("button", { type: "button", "data-catchlight-danger": "", onClick: onClose, children: "Close without saving" })] })] }));
|
|
178
|
+
}
|
|
179
|
+
function Workspace({ session, live, versions, versionView, reviewer, reviewAsked, info, onOpened, onNew, onChoose, onClose, onError, onNotice, onOpenStarter, agentConnect, }) {
|
|
180
|
+
const editor = useEditor();
|
|
181
|
+
const { node, select } = useSelection();
|
|
182
|
+
const editing = useEditing();
|
|
183
|
+
const actions = useWorkspaceActions(session, onError);
|
|
184
|
+
const modelView = useViewportCamera();
|
|
185
|
+
const meshView = useViewportCamera();
|
|
186
|
+
const view = editing.mode === "mesh" ? meshView : modelView;
|
|
187
|
+
const { save } = useFileSave(session);
|
|
188
|
+
const [tool, setTool] = useState("select");
|
|
189
|
+
const mesh = editing.mode === "mesh";
|
|
190
|
+
const setMesh = (next) => editing.requestMode(next ? "mesh" : "arrange");
|
|
191
|
+
const [grid, setGrid] = useState(false);
|
|
192
|
+
const [left, setLeft] = useState("structure");
|
|
193
|
+
const [right, setRight] = useState("properties");
|
|
194
|
+
const review = useReview();
|
|
195
|
+
const [dock, setDock] = useState("params");
|
|
196
|
+
const [dockOpen, setDockOpen] = useState(true);
|
|
197
|
+
const [focus, setFocus] = useState(false);
|
|
198
|
+
const [search, setSearch] = useState("");
|
|
199
|
+
const { param, selectParam: setParam } = editing;
|
|
200
|
+
const [dialog, setDialog] = useState();
|
|
201
|
+
const viewing = versionView.viewing;
|
|
202
|
+
const [saveVersionAsked, setSaveVersionAsked] = useState(0);
|
|
203
|
+
const askSaveVersion = () => {
|
|
204
|
+
if (live && !viewing)
|
|
205
|
+
setSaveVersionAsked((n) => n + 1);
|
|
206
|
+
};
|
|
207
|
+
const [dragOver, setDragOver] = useState(false);
|
|
208
|
+
const [mobilePanel, setMobilePanel] = useState();
|
|
209
|
+
const structurePanelId = useId();
|
|
210
|
+
const propertiesPanelId = useId();
|
|
211
|
+
const panelTrigger = useRef(null);
|
|
212
|
+
const togglePanel = (panel, trigger) => {
|
|
213
|
+
panelTrigger.current = trigger;
|
|
214
|
+
setMobilePanel((open) => open === panel ? undefined : panel);
|
|
215
|
+
};
|
|
216
|
+
const file = useRef(null);
|
|
217
|
+
const art = useRef(null);
|
|
218
|
+
const canvas = useRef(null);
|
|
219
|
+
const workspace = useRef(null);
|
|
220
|
+
const focusCanvas = useCallback(() => {
|
|
221
|
+
const meshCanvas = workspace.current?.querySelector("[data-catchlight-mesh-canvas] > svg");
|
|
222
|
+
(meshCanvas ?? canvas.current)?.focus();
|
|
223
|
+
}, []);
|
|
224
|
+
const closePanel = useCallback(() => {
|
|
225
|
+
setMobilePanel(undefined);
|
|
226
|
+
if (document.querySelector("dialog[open]"))
|
|
227
|
+
return;
|
|
228
|
+
const trigger = panelTrigger.current;
|
|
229
|
+
if (trigger?.getClientRects().length && !trigger.matches(":disabled") &&
|
|
230
|
+
!trigger.closest("[inert]") && getComputedStyle(trigger).visibility !== "hidden")
|
|
231
|
+
trigger.focus();
|
|
232
|
+
else
|
|
233
|
+
focusCanvas();
|
|
234
|
+
}, [focusCanvas]);
|
|
235
|
+
useDismissMenus(workspace);
|
|
236
|
+
useEffect(() => {
|
|
237
|
+
if (mesh && document.activeElement === canvas.current)
|
|
238
|
+
focusCanvas();
|
|
239
|
+
}, [mesh, focusCanvas]);
|
|
240
|
+
useEffect(() => {
|
|
241
|
+
if (mobilePanel === "structure" && (mesh || editing.busy))
|
|
242
|
+
closePanel();
|
|
243
|
+
}, [mobilePanel, mesh, editing.busy, closePanel]);
|
|
244
|
+
useEffect(() => {
|
|
245
|
+
const queries = [matchMedia("(max-width: 1000px)"), matchMedia("(max-width: 600px)")];
|
|
246
|
+
const close = () => { if (mobilePanel)
|
|
247
|
+
closePanel(); };
|
|
248
|
+
queries.forEach((query) => query.addEventListener("change", close));
|
|
249
|
+
return () => queries.forEach((query) => query.removeEventListener("change", close));
|
|
250
|
+
}, [mobilePanel, closePanel]);
|
|
251
|
+
useEffect(() => {
|
|
252
|
+
if (!mobilePanel)
|
|
253
|
+
return;
|
|
254
|
+
const id = mobilePanel === "structure" ? structurePanelId : propertiesPanelId;
|
|
255
|
+
const panel = document.getElementById(id);
|
|
256
|
+
if (!panel)
|
|
257
|
+
return;
|
|
258
|
+
const controls = () => [...panel.querySelectorAll('button, input, select, textarea, summary, a[href], [tabindex]')].filter((element) => element.tabIndex >= 0 && !element.matches(":disabled") &&
|
|
259
|
+
!element.closest("[inert]") && element.getClientRects().length > 0 &&
|
|
260
|
+
getComputedStyle(element).visibility !== "hidden");
|
|
261
|
+
controls()[0]?.focus();
|
|
262
|
+
const keydown = (event) => {
|
|
263
|
+
if (event.defaultPrevented || document.querySelector("dialog[open]"))
|
|
264
|
+
return;
|
|
265
|
+
if (event.key === "Escape") {
|
|
266
|
+
event.preventDefault();
|
|
267
|
+
closePanel();
|
|
268
|
+
}
|
|
269
|
+
else if (event.key === "Tab") {
|
|
270
|
+
const items = controls();
|
|
271
|
+
const first = items[0], last = items[items.length - 1];
|
|
272
|
+
if (!panel.contains(document.activeElement) ||
|
|
273
|
+
document.activeElement === (event.shiftKey ? first : last)) {
|
|
274
|
+
event.preventDefault();
|
|
275
|
+
(event.shiftKey ? last : first)?.focus();
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
};
|
|
279
|
+
document.addEventListener("keydown", keydown);
|
|
280
|
+
return () => document.removeEventListener("keydown", keydown);
|
|
281
|
+
}, [mobilePanel, structurePanelId, propertiesPanelId, closePanel]);
|
|
282
|
+
useEffect(() => {
|
|
283
|
+
// Threads stay where they were read while the selection moves under them.
|
|
284
|
+
if (right === "review")
|
|
285
|
+
return;
|
|
286
|
+
workspace.current
|
|
287
|
+
?.querySelector('[data-catchlight-panel="right"] [data-catchlight-panel-scroll]')
|
|
288
|
+
?.scrollTo({ top: 0 });
|
|
289
|
+
}, [node, session, right, editing.mode]);
|
|
290
|
+
const showReview = useCallback(() => {
|
|
291
|
+
setRight("review");
|
|
292
|
+
setFocus(false);
|
|
293
|
+
if (matchMedia("(max-width: 600px)").matches)
|
|
294
|
+
setMobilePanel("properties");
|
|
295
|
+
}, []);
|
|
296
|
+
useEffect(() => {
|
|
297
|
+
if (reviewAsked > 0)
|
|
298
|
+
showReview();
|
|
299
|
+
}, [reviewAsked, showReview]);
|
|
300
|
+
const commentOnSelection = () => review?.compose(node ? { kind: "node", node } : { kind: "model" });
|
|
301
|
+
const structureSize = usePanelSize("structure", 248, 180, 400, "x");
|
|
302
|
+
const propertiesSize = usePanelSize("properties", 304, 256, 460, "x", -1);
|
|
303
|
+
const dockSize = usePanelSize("posing tools", 220, 110, 420, "y", -1);
|
|
304
|
+
const capture = usePreviewExport(canvas);
|
|
305
|
+
const captureStage = useCallback(() => captureCanvas(canvas.current), []);
|
|
306
|
+
const sweep = usePoseSweep(session, param);
|
|
307
|
+
const playingClip = usePlayingClip(session);
|
|
308
|
+
const fit = useCallback(() => {
|
|
309
|
+
if (editing.mesh) {
|
|
310
|
+
const element = workspace.current?.querySelector("[data-catchlight-mesh-canvas]");
|
|
311
|
+
if (element) {
|
|
312
|
+
const bounds = meshBounds(editing.mesh);
|
|
313
|
+
const next = fitCamera(bounds, { width: element.clientWidth, height: element.clientHeight });
|
|
314
|
+
if (next) {
|
|
315
|
+
view.setCamera(next);
|
|
316
|
+
view.onFit(next, bounds);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
else if (session)
|
|
321
|
+
view.fit(session);
|
|
322
|
+
}, [session, view, editing.mesh]);
|
|
323
|
+
useEffect(() => {
|
|
324
|
+
sweep.setPlaying(false);
|
|
325
|
+
if (editing.mode === "record") {
|
|
326
|
+
setDock("bindings");
|
|
327
|
+
setDockOpen(true);
|
|
328
|
+
}
|
|
329
|
+
else if (editing.mode === "arrange")
|
|
330
|
+
setDock("params");
|
|
331
|
+
}, [editing.mode]);
|
|
332
|
+
const saved = useCallback((outcome) => {
|
|
333
|
+
onNotice(outcome.downloaded
|
|
334
|
+
? `Downloaded ${downloadName(outcome.key)}`
|
|
335
|
+
: `Saved ${downloadName(outcome.key)}`);
|
|
336
|
+
setDialog(undefined);
|
|
337
|
+
}, [onNotice]);
|
|
338
|
+
const quickSave = useCallback(() => {
|
|
339
|
+
if (viewing)
|
|
340
|
+
return;
|
|
341
|
+
const run = () => {
|
|
342
|
+
if (session)
|
|
343
|
+
void save(info?.file ? undefined : info?.title).then(saved, onError);
|
|
344
|
+
};
|
|
345
|
+
if (editing.mesh?.dirty)
|
|
346
|
+
editing.guard(run);
|
|
347
|
+
else
|
|
348
|
+
run();
|
|
349
|
+
}, [session, info, save, saved, onError, editing, viewing]);
|
|
350
|
+
useEffect(() => {
|
|
351
|
+
setSearch("");
|
|
352
|
+
}, [session]);
|
|
353
|
+
const zoom = (factor) => view.setCamera({
|
|
354
|
+
...view.camera,
|
|
355
|
+
height: Math.min(1e7, Math.max(0.001, view.camera.height / factor)),
|
|
356
|
+
});
|
|
357
|
+
const exportPng = () => editing.guard(() => void capture(downloadName(info?.title ?? "model")).then(() => onNotice("Preview exported as PNG"), onError));
|
|
358
|
+
const openModel = () => editing.guard(() => file.current?.click());
|
|
359
|
+
const layerImport = useLayerImport();
|
|
360
|
+
const importLayers = () => editing.guard(() => setDialog("layers"));
|
|
361
|
+
const latestEditing = useRef(editing);
|
|
362
|
+
latestEditing.current = editing;
|
|
363
|
+
const startImport = () => editing.guard(() => {
|
|
364
|
+
void layerImport.start().then((imported) => {
|
|
365
|
+
if (!imported)
|
|
366
|
+
return;
|
|
367
|
+
setDialog((open) => (open === "layers" ? undefined : open));
|
|
368
|
+
const { mesh, busy } = latestEditing.current;
|
|
369
|
+
if (mesh?.dirty || busy)
|
|
370
|
+
onNotice("The import is ready in its own tab.");
|
|
371
|
+
else
|
|
372
|
+
onOpened(imported);
|
|
373
|
+
});
|
|
374
|
+
});
|
|
375
|
+
const newModel = () => editing.guard(onNew);
|
|
376
|
+
const importImages = () => editing.guard(() => art.current?.click());
|
|
377
|
+
const saveCopy = () => editing.guard(() => setDialog("save"));
|
|
378
|
+
const commands = [
|
|
379
|
+
{
|
|
380
|
+
name: "Open model…",
|
|
381
|
+
detail: "Load a .clm file",
|
|
382
|
+
icon: "group",
|
|
383
|
+
key: "⌘ O",
|
|
384
|
+
run: openModel,
|
|
385
|
+
},
|
|
386
|
+
{
|
|
387
|
+
name: "New model",
|
|
388
|
+
detail: "Start with an empty canvas",
|
|
389
|
+
icon: "plus",
|
|
390
|
+
run: newModel,
|
|
391
|
+
},
|
|
392
|
+
{
|
|
393
|
+
name: "Save model",
|
|
394
|
+
detail: "Download a .clm file",
|
|
395
|
+
icon: "save",
|
|
396
|
+
key: "⌘ S",
|
|
397
|
+
run: quickSave,
|
|
398
|
+
disabled: !session,
|
|
399
|
+
},
|
|
400
|
+
{
|
|
401
|
+
name: "Import from layers…",
|
|
402
|
+
detail: "Rig a See-through PSD or folder",
|
|
403
|
+
icon: "spark",
|
|
404
|
+
run: importLayers,
|
|
405
|
+
},
|
|
406
|
+
{
|
|
407
|
+
name: "Import artwork…",
|
|
408
|
+
detail: "PNG or TGA images",
|
|
409
|
+
icon: "upload",
|
|
410
|
+
run: importImages,
|
|
411
|
+
disabled: !session,
|
|
412
|
+
},
|
|
413
|
+
{
|
|
414
|
+
name: "Export preview",
|
|
415
|
+
detail: "Save the current view as PNG",
|
|
416
|
+
icon: "download",
|
|
417
|
+
run: () => void exportPng(),
|
|
418
|
+
disabled: !session,
|
|
419
|
+
},
|
|
420
|
+
{
|
|
421
|
+
name: "Fit model in view",
|
|
422
|
+
detail: "Frame the complete model",
|
|
423
|
+
icon: "fit",
|
|
424
|
+
key: "F",
|
|
425
|
+
run: fit,
|
|
426
|
+
disabled: !session,
|
|
427
|
+
},
|
|
428
|
+
{
|
|
429
|
+
name: "Reset pose",
|
|
430
|
+
detail: "Restore every param to its default",
|
|
431
|
+
icon: "reset",
|
|
432
|
+
run: actions.resetPose,
|
|
433
|
+
disabled: !session || mesh,
|
|
434
|
+
},
|
|
435
|
+
{
|
|
436
|
+
name: "Undo",
|
|
437
|
+
detail: "Undo the last model edit",
|
|
438
|
+
icon: "undo",
|
|
439
|
+
key: "⌘ Z",
|
|
440
|
+
run: actions.undo,
|
|
441
|
+
disabled: !actions.canUndo,
|
|
442
|
+
},
|
|
443
|
+
{
|
|
444
|
+
name: "Redo",
|
|
445
|
+
detail: "Restore an undone edit",
|
|
446
|
+
icon: "redo",
|
|
447
|
+
key: "⇧ ⌘ Z",
|
|
448
|
+
run: actions.redo,
|
|
449
|
+
disabled: !actions.canRedo,
|
|
450
|
+
},
|
|
451
|
+
{
|
|
452
|
+
name: "Edit mesh on artwork",
|
|
453
|
+
detail: "Place vertices without stretching the image",
|
|
454
|
+
icon: "mesh",
|
|
455
|
+
key: "M",
|
|
456
|
+
run: () => setMesh(!mesh),
|
|
457
|
+
disabled: !session ||
|
|
458
|
+
(!mesh && (editing.info?.kind !== "part" || !editing.info.texture)),
|
|
459
|
+
},
|
|
460
|
+
{
|
|
461
|
+
name: node ? "Comment on selection" : "Comment on the model",
|
|
462
|
+
detail: "Start a review thread for your agent",
|
|
463
|
+
icon: "comment",
|
|
464
|
+
key: "C",
|
|
465
|
+
run: commentOnSelection,
|
|
466
|
+
disabled: !session,
|
|
467
|
+
},
|
|
468
|
+
{
|
|
469
|
+
name: "Send review to agent",
|
|
470
|
+
detail: review?.unsent ? `${review.unsent} unsent` : "Nothing new to send",
|
|
471
|
+
icon: "send",
|
|
472
|
+
run: () => void review?.send(),
|
|
473
|
+
disabled: !review?.unsent,
|
|
474
|
+
},
|
|
475
|
+
{
|
|
476
|
+
name: "Show review",
|
|
477
|
+
detail: "Threads and agent status",
|
|
478
|
+
icon: "comment",
|
|
479
|
+
run: showReview,
|
|
480
|
+
disabled: !session,
|
|
481
|
+
},
|
|
482
|
+
{
|
|
483
|
+
name: "Save version…",
|
|
484
|
+
detail: "Keep the model as it is now, to come back to",
|
|
485
|
+
icon: "history",
|
|
486
|
+
key: "⌥ ⌘ S",
|
|
487
|
+
run: askSaveVersion,
|
|
488
|
+
disabled: !live || !!viewing,
|
|
489
|
+
},
|
|
490
|
+
...(viewing
|
|
491
|
+
? [
|
|
492
|
+
{
|
|
493
|
+
name: "Back to current",
|
|
494
|
+
detail: "Stop viewing the saved version",
|
|
495
|
+
icon: "history",
|
|
496
|
+
run: versionView.back,
|
|
497
|
+
},
|
|
498
|
+
{
|
|
499
|
+
name: "Restore this version",
|
|
500
|
+
detail: "Replace the model with it, as one undoable edit",
|
|
501
|
+
icon: "history",
|
|
502
|
+
run: () => void versionView.restore(),
|
|
503
|
+
},
|
|
504
|
+
]
|
|
505
|
+
: []),
|
|
506
|
+
{
|
|
507
|
+
name: "Toggle focus mode",
|
|
508
|
+
detail: "Make room for the canvas",
|
|
509
|
+
icon: "panel",
|
|
510
|
+
key: "⇧ F",
|
|
511
|
+
run: () => setFocus(!focus),
|
|
512
|
+
},
|
|
513
|
+
];
|
|
514
|
+
useEffect(() => {
|
|
515
|
+
const handler = (e) => {
|
|
516
|
+
if (e.defaultPrevented)
|
|
517
|
+
return;
|
|
518
|
+
const target = e.target;
|
|
519
|
+
const typing = target?.matches("input,textarea,select") || target?.isContentEditable;
|
|
520
|
+
const mod = e.ctrlKey || e.metaKey;
|
|
521
|
+
const key = e.key.toLowerCase();
|
|
522
|
+
if (dialog || document.querySelector("dialog[open]"))
|
|
523
|
+
return;
|
|
524
|
+
if (mod && key === "k") {
|
|
525
|
+
e.preventDefault();
|
|
526
|
+
setDialog("commands");
|
|
527
|
+
return;
|
|
528
|
+
}
|
|
529
|
+
// By code: Option+S types "ß" on a Mac.
|
|
530
|
+
if (mod && e.altKey && e.code === "KeyS") {
|
|
531
|
+
e.preventDefault();
|
|
532
|
+
askSaveVersion();
|
|
533
|
+
return;
|
|
534
|
+
}
|
|
535
|
+
if (mod && key === "s") {
|
|
536
|
+
e.preventDefault();
|
|
537
|
+
if (e.shiftKey)
|
|
538
|
+
saveCopy();
|
|
539
|
+
else
|
|
540
|
+
quickSave();
|
|
541
|
+
return;
|
|
542
|
+
}
|
|
543
|
+
if (mod && key === "o") {
|
|
544
|
+
e.preventDefault();
|
|
545
|
+
openModel();
|
|
546
|
+
return;
|
|
547
|
+
}
|
|
548
|
+
if (typing)
|
|
549
|
+
return;
|
|
550
|
+
if (mod && key === "z") {
|
|
551
|
+
e.preventDefault();
|
|
552
|
+
void (e.shiftKey ? actions.redo() : actions.undo());
|
|
553
|
+
}
|
|
554
|
+
else if (mod && key === "d") {
|
|
555
|
+
e.preventDefault();
|
|
556
|
+
void actions.duplicate();
|
|
557
|
+
}
|
|
558
|
+
else if (key === "delete" || key === "backspace") {
|
|
559
|
+
e.preventDefault();
|
|
560
|
+
void actions.remove();
|
|
561
|
+
}
|
|
562
|
+
else if (key === "v")
|
|
563
|
+
setTool("select");
|
|
564
|
+
else if (key === "h")
|
|
565
|
+
setTool("hand");
|
|
566
|
+
else if (key === "f") {
|
|
567
|
+
e.preventDefault();
|
|
568
|
+
if (e.shiftKey)
|
|
569
|
+
setFocus(!focus);
|
|
570
|
+
else
|
|
571
|
+
fit();
|
|
572
|
+
}
|
|
573
|
+
else if (key === "m")
|
|
574
|
+
setMesh(!mesh);
|
|
575
|
+
else if (key === "r") {
|
|
576
|
+
if (editing.mode !== "record")
|
|
577
|
+
editing.requestMode("record");
|
|
578
|
+
else if (editing.recording)
|
|
579
|
+
editing.stop();
|
|
580
|
+
else
|
|
581
|
+
editing.arm();
|
|
582
|
+
}
|
|
583
|
+
else if (key === "g")
|
|
584
|
+
setGrid(!grid);
|
|
585
|
+
else if (key === "c" && !mod && session) {
|
|
586
|
+
e.preventDefault();
|
|
587
|
+
commentOnSelection();
|
|
588
|
+
}
|
|
589
|
+
else if (key === "?")
|
|
590
|
+
setDialog("help");
|
|
591
|
+
else if (key === "escape") {
|
|
592
|
+
if (mesh)
|
|
593
|
+
editing.requestMode("arrange");
|
|
594
|
+
else if (editing.recording)
|
|
595
|
+
editing.stop();
|
|
596
|
+
else
|
|
597
|
+
select(undefined);
|
|
598
|
+
setMobilePanel(undefined);
|
|
599
|
+
}
|
|
600
|
+
else if (key === "+" || key === "=") {
|
|
601
|
+
e.preventDefault();
|
|
602
|
+
zoom(1.2);
|
|
603
|
+
}
|
|
604
|
+
else if (key === "-") {
|
|
605
|
+
e.preventDefault();
|
|
606
|
+
zoom(1 / 1.2);
|
|
607
|
+
}
|
|
608
|
+
else if (node && target?.closest("[data-catchlight-stage]")) {
|
|
609
|
+
const n = e.shiftKey ? 10 : 1;
|
|
610
|
+
const delta = {
|
|
611
|
+
arrowleft: [-n, 0],
|
|
612
|
+
arrowright: [n, 0],
|
|
613
|
+
arrowup: [0, n],
|
|
614
|
+
arrowdown: [0, -n],
|
|
615
|
+
};
|
|
616
|
+
if (delta[key]) {
|
|
617
|
+
e.preventDefault();
|
|
618
|
+
void actions.nudge(...delta[key]);
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
};
|
|
622
|
+
window.addEventListener("keydown", handler);
|
|
623
|
+
return () => window.removeEventListener("keydown", handler);
|
|
624
|
+
});
|
|
625
|
+
const menuItem = (label, icon, action, disabled = false, shortcut) => (_jsxs("button", { type: "button", disabled: disabled, onClick: (e) => {
|
|
626
|
+
e.currentTarget.closest("details")?.removeAttribute("open");
|
|
627
|
+
action();
|
|
628
|
+
}, children: [_jsx(Icon, { name: icon }), _jsx("span", { children: label }), shortcut && _jsx("kbd", { children: shortcut })] }));
|
|
629
|
+
return (_jsxs("div", { ref: workspace, style: {
|
|
630
|
+
"--cl-panel-width": `${structureSize.size}px`,
|
|
631
|
+
"--cl-properties-width": `${propertiesSize.size}px`,
|
|
632
|
+
"--cl-dock-height": `${dockSize.size}px`,
|
|
633
|
+
}, "data-catchlight-workspace": "", "data-viewing": viewing ? "" : undefined, "data-mode": editing.mode, "data-recording": editing.recording ? "" : undefined, "data-focus": focus ? "" : undefined, "data-dock-open": dockOpen ? "" : undefined, "data-mobile-panel": mobilePanel, children: [_jsxs("header", { "data-catchlight-toolbar": "", children: [_jsxs("a", { "data-catchlight-brand": "", href: "#", "aria-label": "Catchlight home", onClick: (e) => {
|
|
634
|
+
e.preventDefault();
|
|
635
|
+
setDialog("commands");
|
|
636
|
+
}, children: [_jsx("img", { "data-catchlight-logo": "", src: logoUrl, alt: "", width: "20", height: "20" }), _jsx("span", { "data-catchlight-wordmark": "", children: "catchlight" })] }), _jsxs("div", { "data-catchlight-main-menus": "", children: [_jsxs("details", { "data-catchlight-menu": "", children: [_jsxs("summary", { children: ["File", _jsx(Icon, { name: "down", width: "11", height: "11" })] }), _jsxs("div", { role: "group", "aria-label": "File actions", children: [menuItem("New model", "plus", newModel), menuItem("Open model…", "group", openModel, false, "⌘ O"), menuItem("Import from layers…", "spark", importLayers), menuItem("Import artwork…", "upload", importImages, !session), _jsx("hr", {}), menuItem("Save", "save", quickSave, !session, "⌘ S"), menuItem("Save as…", "save", saveCopy, !session), menuItem("Export preview…", "download", () => void exportPng(), !session)] })] }), _jsxs("details", { "data-catchlight-menu": "", children: [_jsxs("summary", { children: ["Edit", _jsx(Icon, { name: "down", width: "11", height: "11" })] }), _jsxs("div", { children: [menuItem("Undo", "undo", actions.undo, !actions.canUndo, "⌘ Z"), menuItem("Redo", "redo", actions.redo, !actions.canRedo, "⇧ ⌘ Z"), _jsx("hr", {}), menuItem("Duplicate", "duplicate", actions.duplicate, !actions.canDuplicate, "⌘ D"), menuItem("Delete", "trash", actions.remove, !actions.canRemove, "⌫")] })] })] }), _jsxs("nav", { "data-catchlight-model-tabs": "", "aria-label": "Open models", children: [_jsx(SessionList.Root, { current: live?.id, onSelect: (s) => editing.guard(() => onChoose(s)), onClose: (s) => editing.guard(() => onClose(s)) }), _jsx(IconButton, { "data-catchlight-new": "", icon: "plus", label: "New model", onClick: newModel })] }), live && (_jsx(VersionSelect, { versions: versions, current: viewing?.version.version, onSelect: (version) => (version ? versionView.open(version) : versionView.back()), reviewer: reviewer, saveRequested: saveVersionAsked })), _jsxs("div", { "data-catchlight-history-tools": "", children: [_jsx(IconButton, { icon: "undo", label: "Undo (Ctrl/\u2318 Z)", disabled: !actions.canUndo || actions.busy || editing.busy || !!viewing, onClick: actions.undo }), _jsx(IconButton, { icon: "redo", label: "Redo (Ctrl/\u2318 Shift Z)", disabled: !actions.canRedo || actions.busy || editing.busy || !!viewing, onClick: actions.redo })] }), _jsxs("button", { type: "button", "data-catchlight-command-trigger": "", onClick: () => setDialog("commands"), children: [_jsx(Icon, { name: "search", width: "15", height: "15" }), _jsx("span", { children: "Search" }), _jsx("kbd", { children: "\u2318 K" })] }), _jsx(ReviewStatus, { onOpen: showReview }), _jsxs("span", { "data-catchlight-save-state": "", children: [_jsx("i", { "data-dirty": info?.dirty || editing.mesh?.dirty ? "" : undefined }), viewing
|
|
637
|
+
? "Viewing a saved version"
|
|
638
|
+
: session
|
|
639
|
+
? editing.mesh?.dirty
|
|
640
|
+
? "Mesh draft · not applied"
|
|
641
|
+
: info?.dirty
|
|
642
|
+
? "Unsaved changes"
|
|
643
|
+
: "All changes saved"
|
|
644
|
+
: "No model open"] }), _jsxs("button", { type: "button", "data-catchlight-save": "", disabled: !session || !!viewing, onClick: quickSave, children: [_jsx(Icon, { name: "save", width: "15", height: "15" }), "Save", _jsx("span", { "data-catchlight-save-label": "", children: " model" })] }), _jsx("label", { "data-catchlight-hidden-file": "", children: _jsx(FileOpen.Root, { ref: file, onOpened: onOpened, onError: onError }) }), _jsx("input", { ref: art, type: "file", accept: ".png,.tga", multiple: true, "aria-label": "Import artwork", "data-catchlight-hidden-file": "", onChange: (e) => {
|
|
645
|
+
const files = Array.from(e.currentTarget.files ?? []);
|
|
646
|
+
e.currentTarget.value = "";
|
|
647
|
+
editing.guard(() => {
|
|
648
|
+
void actions.importImages(files);
|
|
649
|
+
});
|
|
650
|
+
} })] }), mobilePanel && (_jsx("button", { type: "button", "data-catchlight-panel-scrim": "", "aria-label": "Dismiss side panel", onClick: closePanel })), _jsxs("aside", { id: structurePanelId, "data-catchlight-panel": "left", inert: mesh || editing.busy || !!viewing, role: mobilePanel === "structure" ? "dialog" : undefined, "aria-modal": mobilePanel === "structure" ? true : undefined, "aria-label": "Structure", children: [_jsx("div", { "data-catchlight-resize": "left", ...structureSize.handle }), _jsxs("div", { "data-catchlight-panel-tabs": "", children: [_jsx("button", { type: "button", "data-active": left === "structure" ? "" : undefined, onClick: () => setLeft("structure"), children: "Structure" }), _jsx("button", { type: "button", "data-active": left === "assets" ? "" : undefined, onClick: () => setLeft("assets"), children: "Artwork" }), _jsx(IconButton, { icon: "close", label: "Close structure panel", "data-catchlight-mobile-only": "", onClick: closePanel })] }), left === "structure" ? (_jsxs(_Fragment, { children: [_jsxs("div", { "data-catchlight-tree-tools": "", children: [_jsx(SearchField, { label: "Search nodes", placeholder: "Find a node\u2026", value: search, onValueChange: setSearch }), _jsxs("details", { "data-catchlight-menu": "", children: [_jsx("summary", { "aria-label": "Add node", children: _jsx(Icon, { name: "plus" }) }), _jsx("div", { children: [
|
|
651
|
+
"group",
|
|
652
|
+
"part",
|
|
653
|
+
"composite",
|
|
654
|
+
"mesh_group",
|
|
655
|
+
"motion_response",
|
|
656
|
+
].map((kind) => (_jsxs("button", { type: "button", disabled: !session, onClick: (e) => {
|
|
657
|
+
e.currentTarget
|
|
658
|
+
.closest("details")
|
|
659
|
+
?.removeAttribute("open");
|
|
660
|
+
void actions.add(kind);
|
|
661
|
+
}, children: [_jsx(Icon, { name: kindIcons[kind] }), _jsx("span", { children: kindLabels[kind] })] }, kind))) })] })] }), _jsx("div", { "data-catchlight-tree-scroll": "", children: session ? (_jsx(NodeTree.Root, { session: session, filter: search, onError: onError })) : (_jsx(EmptyState, { icon: "group", title: "No model open", children: "Open or create a model to inspect its node tree." })) }), _jsxs("div", { "data-catchlight-tree-footer": "", children: [_jsxs("button", { type: "button", "data-catchlight-import-artwork": "", onClick: importImages, disabled: !session, children: [_jsx(Icon, { name: "upload", width: "15", height: "15" }), "Import artwork"] }), _jsx(IconButton, { icon: "duplicate", label: "Duplicate selected node", disabled: !actions.canDuplicate, onClick: actions.duplicate }), _jsx(IconButton, { icon: "trash", label: "Delete selected node", disabled: !actions.canRemove, onClick: actions.remove })] })] })) : (_jsxs("div", { "data-catchlight-panel-scroll": "", children: [session ? (_jsx(AssetsPanel, { session: session })) : (_jsx(EmptyState, { icon: "part", title: "No artwork yet", children: "Open a model or create a new one to import your images." })), _jsxs("button", { type: "button", "data-catchlight-action": "", "data-catchlight-import-artwork": "", disabled: !session, onClick: importImages, children: [_jsx(Icon, { name: "upload" }), "Import artwork"] })] }))] }), _jsxs("main", { "data-catchlight-center": "", children: [_jsx(EditingBar, {}), mesh && _jsx(MeshTools, {}), _jsxs("div", { "data-catchlight-stage-wrap": "", "data-drop": dragOver ? "" : undefined, onDragOver: (e) => {
|
|
662
|
+
if (e.dataTransfer.types.includes("Files")) {
|
|
663
|
+
e.preventDefault();
|
|
664
|
+
setDragOver(true);
|
|
665
|
+
}
|
|
666
|
+
}, onDragLeave: (e) => {
|
|
667
|
+
if (!e.currentTarget.contains(e.relatedTarget))
|
|
668
|
+
setDragOver(false);
|
|
669
|
+
}, onDrop: (e) => {
|
|
670
|
+
e.preventDefault();
|
|
671
|
+
setDragOver(false);
|
|
672
|
+
const files = Array.from(e.dataTransfer.files);
|
|
673
|
+
editing.guard(() => {
|
|
674
|
+
const model = opensModel(files);
|
|
675
|
+
if (model)
|
|
676
|
+
void model
|
|
677
|
+
.arrayBuffer()
|
|
678
|
+
.then((bytes) => editor.openFile(new Uint8Array(bytes), model.name))
|
|
679
|
+
.then(onOpened, onError);
|
|
680
|
+
else if (opensLayers(files)) {
|
|
681
|
+
setDialog("layers");
|
|
682
|
+
if (!layerImport.busy)
|
|
683
|
+
void layerImport.chooseLayers(files);
|
|
684
|
+
}
|
|
685
|
+
else if (session)
|
|
686
|
+
void actions.importImages(files);
|
|
687
|
+
else
|
|
688
|
+
onError(new Error("Create a model first, then drop your artwork here."));
|
|
689
|
+
});
|
|
690
|
+
}, children: [_jsxs("div", { "data-catchlight-canvas-toolbar": "", children: [_jsx(WorkspaceModes, {}), _jsxs("div", { "data-catchlight-canvas-actions": "", children: [_jsxs("button", { type: "button", "data-catchlight-panel-toggle": "structure", "aria-label": "Toggle structure panel", "aria-expanded": mobilePanel === "structure", "aria-controls": structurePanelId, disabled: mesh || editing.busy, onClick: (event) => togglePanel("structure", event.currentTarget), children: [_jsx(Icon, { name: "group" }), _jsx("span", { children: "Parts" })] }), _jsxs("button", { type: "button", "data-catchlight-panel-toggle": "properties", "aria-label": "Toggle properties panel", "aria-expanded": mobilePanel === "properties", "aria-controls": propertiesPanelId, onClick: (event) => togglePanel("properties", event.currentTarget), children: [_jsx(Icon, { name: "settings" }), _jsx("span", { children: "Properties" })] }), _jsxs("div", { "data-catchlight-tool-group": "", children: [_jsx(IconButton, { icon: "grid", label: "Show grid (G)", "aria-pressed": grid, disabled: mesh, onClick: () => setGrid(!grid) }), _jsx(IconButton, { icon: "panel", label: "Focus mode (Shift F)", "aria-pressed": focus, onClick: () => setFocus(!focus) })] })] })] }), viewing && (_jsx(VersionBanner, { version: viewing.version, busy: versions.busy, onRestore: () => void versionView.restore(), onBack: versionView.back })), _jsx(Stage, { session: session, view: modelView, meshView: meshView, tool: tool, grid: grid, canvas: canvas, onError: onError }), session && !mesh && (_jsxs(_Fragment, { children: [_jsxs("div", { "data-catchlight-scene-label": "", children: [_jsx("span", { children: "SCENE" }), _jsx("span", { children: "/" }), editing.info?.name ?? info?.title] }), _jsxs("div", { "data-catchlight-canvas-tools": "", children: [_jsx(IconButton, { icon: "select", label: "Select and move (V)", "aria-pressed": tool === "select", onClick: () => setTool("select") }), _jsx(IconButton, { icon: "hand", label: "Pan (H)", "aria-pressed": tool === "hand", onClick: () => setTool("hand") })] })] })), _jsxs("div", { "data-catchlight-zoom-tools": "", children: [_jsx(IconButton, { icon: "minus", label: "Zoom out", onClick: () => zoom(1 / 1.2) }), _jsx("button", { type: "button", "data-catchlight-zoom": "", onClick: fit, title: "Fit model in view", children: view.zoom === undefined
|
|
691
|
+
? "100%"
|
|
692
|
+
: `${Math.round(view.zoom * 100)}%` }), _jsx(IconButton, { icon: "plus", label: "Zoom in", onClick: () => zoom(1.2) }), _jsx(IconButton, { "data-catchlight-fit": "", icon: "fit", label: "Fit model (F)", onClick: fit, disabled: !session })] }), !session && (_jsxs("div", { "data-catchlight-welcome": "", children: [_jsx("span", { "data-catchlight-welcome-symbol": "", children: _jsx("img", { "data-catchlight-logo": "", src: logoUrl, alt: "", width: "56", height: "56" }) }), _jsx("p", { "data-catchlight-eyebrow": "", children: "REAL-TIME 2.5D CHARACTER ENGINE" }), _jsxs("h1", { children: ["Your characters,", _jsx("br", {}), _jsx("em", { children: "brought to life." })] }), _jsxs("div", { children: [_jsxs("button", { type: "button", "data-primary": "", onClick: newModel, children: [_jsx(Icon, { name: "plus" }), "Create a model"] }), _jsxs("button", { type: "button", onClick: openModel, children: [_jsx(Icon, { name: "group" }), "Open a model"] }), _jsxs("button", { type: "button", onClick: importLayers, children: [_jsx(Icon, { name: "spark" }), "Import from layers"] })] }), onOpenStarter && (_jsxs("button", { type: "button", "data-catchlight-text-button": "", onClick: () => void onOpenStarter().then(onOpened, onError), children: ["Open starter model", " ", _jsx(Icon, { name: "arrow", width: "14", height: "14" })] })), _jsx("small", { children: "Or drop a .clm file or a See-through PSD anywhere on the canvas" })] })), dragOver && (_jsxs("div", { "data-catchlight-drop-hint": "", children: [_jsx(Icon, { name: "upload", width: "30", height: "30" }), _jsx("strong", { children: "Drop files to open or import" }), _jsx("span", { children: "Model files, See-through layers or PNG / TGA artwork" })] })), session && (_jsxs("div", { "data-catchlight-canvas-hint": "", children: [_jsx("kbd", { children: "Space" }), " + drag to pan", _jsx("span", { children: "\u00B7" }), "Scroll to zoom"] }))] }), _jsxs("section", { "data-catchlight-dock": "", "data-open": dockOpen ? "" : undefined, "aria-label": "Posing tools", children: [dockOpen && (_jsx("div", { "data-catchlight-resize": "dock", ...dockSize.handle })), _jsxs("div", { "data-catchlight-dock-header": "", children: [_jsxs("div", { "data-catchlight-panel-tabs": "", children: [_jsxs("button", { type: "button", "data-active": dock === "params" ? "" : undefined, onClick: () => {
|
|
693
|
+
setDock("params");
|
|
694
|
+
setDockOpen(true);
|
|
695
|
+
}, children: [_jsx(Icon, { name: "settings", width: "14", height: "14" }), "Params"] }), _jsxs("button", { type: "button", "data-active": dock === "bindings" ? "" : undefined, onClick: () => {
|
|
696
|
+
setDock("bindings");
|
|
697
|
+
setDockOpen(true);
|
|
698
|
+
}, children: [_jsx(Icon, { name: "link", width: "14", height: "14" }), editing.mode === "record" ? "Keypoints" : "Bindings"] }), editing.mode !== "record" && (_jsxs(_Fragment, { children: [_jsxs("button", { type: "button", "data-active": dock === "controls" ? "" : undefined, onClick: () => {
|
|
699
|
+
setDock("controls");
|
|
700
|
+
setDockOpen(true);
|
|
701
|
+
}, children: [_jsx(Icon, { name: "control", width: "14", height: "14" }), "Controls"] }), _jsxs("button", { type: "button", "data-active": dock === "expressions" ? "" : undefined, onClick: () => {
|
|
702
|
+
setDock("expressions");
|
|
703
|
+
setDockOpen(true);
|
|
704
|
+
}, children: [_jsx(Icon, { name: "face", width: "14", height: "14" }), "Expressions"] }), _jsxs("button", { type: "button", "data-active": dock === "animations" ? "" : undefined, onClick: () => {
|
|
705
|
+
setDock("animations");
|
|
706
|
+
setDockOpen(true);
|
|
707
|
+
}, children: [_jsx(Icon, { name: "film", width: "14", height: "14" }), "Animations"] })] }))] }), _jsxs("div", { "data-catchlight-dock-actions": "", children: [_jsxs("button", { type: "button", disabled: !session || !param || editing.mode !== "arrange" || sweep.held, title: sweep.held ? "A motion response moves this param. Pause motion to sweep it." : undefined, "aria-pressed": sweep.playing, onClick: () => sweep.setPlaying(!sweep.playing), children: [_jsx(Icon, { name: sweep.playing ? "pause" : "play", width: "13", height: "13" }), sweep.playing ? "Stop sweep" : "Play sweep"] }), playingClip !== undefined && (_jsxs("button", { type: "button", "data-catchlight-clip-stop": "", title: `Stop the animation “${playingClip}”`, onClick: () => session?.stop(), children: [_jsx(Icon, { name: "stop", width: "13", height: "13" }), _jsxs("span", { children: ["Stop ", playingClip] })] })), session && (_jsx(DrivenMotionToggle, { session: session, editing: editing.mode !== "arrange" })), _jsx(IconButton, { "data-catchlight-pose-reset": "", icon: "reset", label: "Reset pose", disabled: !session || mesh, onClick: actions.resetPose }), _jsx(IconButton, { icon: dockOpen ? "down" : "chevron", label: dockOpen ? "Collapse posing tools" : "Expand posing tools", onClick: () => setDockOpen(!dockOpen) })] })] }), dockOpen && (_jsx("div", { "data-catchlight-dock-body": "", children: mesh ? (_jsx("p", { "data-catchlight-mesh-pose-held": "", children: "Pose held while editing topology. Apply or cancel your mesh to return." })) : session ? (dock === "params" ? (_jsx(ParamsPanel, { session: session, selected: param, onSelect: setParam, onSelectNode: select, onError: onError }, session.id)) : editing.mode === "record" ? (_jsx(RecordingKeys, {})) : dock === "controls" ? (_jsx(ControlsPanel, { session: session, onError: onError, selected: node, onSelectNode: select }, session.id)) : dock === "expressions" ? (_jsx(ExpressionsPanel, { session: session, onError: onError }, session.id)) : dock === "animations" ? (_jsx(AnimationsPanel, { session: session, onError: onError }, session.id)) : (_jsx(BindingsPanel, { session: session, node: node, param: param, onError: onError }))) : (_jsx("p", { "data-catchlight-empty": "", children: "Open a model to edit params, bindings, and controls." })) }))] })] }), _jsxs("aside", { id: propertiesPanelId, "data-catchlight-panel": "right", role: mobilePanel === "properties" ? "dialog" : undefined, "aria-modal": mobilePanel === "properties" ? true : undefined, "aria-label": "Properties", children: [_jsx("div", { "data-catchlight-resize": "right", ...propertiesSize.handle }), _jsxs("div", { "data-catchlight-panel-tabs": "", children: [_jsx("button", { type: "button", "data-active": right === "properties" ||
|
|
708
|
+
(right === "model" && editing.mode !== "arrange")
|
|
709
|
+
? ""
|
|
710
|
+
: undefined, onClick: () => setRight("properties"), children: "Properties" }), _jsx("button", { type: "button", disabled: editing.mode !== "arrange", "data-active": right === "model" && editing.mode === "arrange" ? "" : undefined, onClick: () => setRight("model"), children: "Model" }), _jsxs("button", { type: "button", "data-catchlight-review-tab": "", "data-active": right === "review" ? "" : undefined, "data-attention": review?.replied ? "" : undefined, onClick: () => setRight("review"), children: ["Review", !!review && review.replied + review.unsent > 0 && (_jsx("small", { children: review.replied + review.unsent }))] }), _jsx(IconButton, { icon: "close", label: "Close properties panel", "data-catchlight-mobile-only": "", onClick: closePanel })] }), _jsx("div", { "data-catchlight-panel-scroll": "", inert: !!viewing && right !== "review", children: session && live ? (right === "review" ? (_jsx(ReviewPanel, { session: live, connect: agentConnect?.(live), capture: captureStage })) : mesh ? (_jsx(MeshInspector, {})) : editing.mode === "record" ? (_jsx(RecordingInspector, {})) : right === "properties" ? (_jsxs(_Fragment, { children: [!!editing.emptiedSlots.length && (_jsxs("div", { "data-catchlight-warning": "", role: "status", children: ["Mesh applied. Reassign slots:", " ", editing.emptiedSlots.join(", "), ". Open the Slots section below."] })), _jsx(PropertiesPanel, { session: session, onError: onError })] })) : (_jsxs(_Fragment, { children: [_jsx(ModelHealth, { session: session }), _jsx(Disclosure, { title: "Connections", children: _jsx(WeldsPanel, { session: session, onError: onError }) }), _jsx(Disclosure, { title: "Extensions", defaultOpen: false, children: _jsx(ExtensionsPanel, { session: session, onError: onError }) })] }))) : (_jsx(EmptyState, { title: "No model open", children: "Node properties and model diagnostics appear here." })) })] }), _jsxs("footer", { "data-catchlight-status": "", children: [_jsxs("div", { children: [_jsx("span", { "data-catchlight-status-title": "", children: info?.title ?? "No model open" }), _jsx("span", { "data-catchlight-status-selection": "", children: node ? `selected ${node.split("/").pop()}` : "Nothing selected" })] }), _jsxs("div", { children: [_jsx(Environment, {}), _jsx(IconButton, { icon: "help", label: "Keyboard shortcuts (?)", onClick: () => setDialog("help") })] })] }), session && _jsx(PosePublisher, { session: session }), dialog === "save" && session && (_jsxs(Modal, { title: "Save a copy", onClose: () => setDialog(undefined), children: [_jsx("p", { "data-catchlight-hint": "", children: "Your .clm file contains the complete model and its artwork." }), _jsx(FileSave.Root, { session: session, defaultName: downloadName(info?.file ?? info?.title ?? "untitled.clm"), onSaved: saved, onError: onError, children: "Save model" })] })), dialog === "layers" && (_jsx(ImportPanel, { layerImport: layerImport, onImport: startImport, onClose: () => setDialog(undefined) })), dialog === "commands" && (_jsx(CommandPalette, { session: session, actions: commands, onClose: () => setDialog(undefined) })), dialog === "help" && _jsx(Shortcuts, { onClose: () => setDialog(undefined) })] }));
|
|
711
|
+
}
|
|
712
|
+
function PosePublisher({ session }) {
|
|
713
|
+
usePosePublisher(session);
|
|
714
|
+
return null;
|
|
715
|
+
}
|
|
716
|
+
/** Shown only for a model with a param a motion response drives. */
|
|
717
|
+
function DrivenMotionToggle({ session, editing }) {
|
|
718
|
+
const driven = useParams(session).some((p) => p.driven_by);
|
|
719
|
+
return driven ? _jsx(MotionToggle, { session: session, editing: editing }) : null;
|
|
720
|
+
}
|