@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,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Publishes the pose from the repaint channel, so sliders only pose the
|
|
3
|
+
* replica. Values are read at send time, never per repaint.
|
|
4
|
+
*/
|
|
5
|
+
import type { ParamInfo, ParamPose, Session } from "@catchlight/editor-core";
|
|
6
|
+
/** Call once per session, anywhere under the `PresenceProvider`. */
|
|
7
|
+
export declare function usePosePublisher(session: Session): void;
|
|
8
|
+
export declare function readPose(session: Session, params?: ParamInfo[]): ParamPose[];
|
|
9
|
+
/**
|
|
10
|
+
* Poses only; the publisher hears the repaints. Clears the live inputs too,
|
|
11
|
+
* and leaves a playing clip playing.
|
|
12
|
+
*/
|
|
13
|
+
export declare function useResetPose(session: Session): () => void;
|
package/dist/lib/pose.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Publishes the pose from the repaint channel, so sliders only pose the
|
|
3
|
+
* replica. Values are read at send time, never per repaint.
|
|
4
|
+
*/
|
|
5
|
+
import { useCallback, useEffect } from "react";
|
|
6
|
+
import { useLatest } from "./latest.js";
|
|
7
|
+
import { usePose } from "./presence.js";
|
|
8
|
+
import { useParams } from "./replica.js";
|
|
9
|
+
/** Call once per session, anywhere under the `PresenceProvider`. */
|
|
10
|
+
export function usePosePublisher(session) {
|
|
11
|
+
const { publish } = usePose();
|
|
12
|
+
const params = useParams(session);
|
|
13
|
+
const latest = useLatest(params);
|
|
14
|
+
useEffect(() => session.onInvalidate(() => publish(() => readPose(session, latest.current))), [session, publish, latest]);
|
|
15
|
+
}
|
|
16
|
+
export function readPose(session, params = session.params()) {
|
|
17
|
+
return params.map((param) => ({
|
|
18
|
+
param: param.id,
|
|
19
|
+
value: session.paramValue(param.id) ?? param.default,
|
|
20
|
+
}));
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Poses only; the publisher hears the repaints. Clears the live inputs too,
|
|
24
|
+
* and leaves a playing clip playing.
|
|
25
|
+
*/
|
|
26
|
+
export function useResetPose(session) {
|
|
27
|
+
return useCallback(() => {
|
|
28
|
+
session.clearInputs();
|
|
29
|
+
for (const param of session.params())
|
|
30
|
+
session.setParam(param.id, param.default);
|
|
31
|
+
}, [session]);
|
|
32
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { BindingParams, NodeId, ParamId, Session } from "@catchlight/editor-core";
|
|
2
|
+
import type { ComponentProps } from "react";
|
|
3
|
+
import { type ErrorHandler } from "./authoring.js";
|
|
4
|
+
export declare function ParamsPanel({ session, selected, onSelect, onSelectNode, onError, }: {
|
|
5
|
+
session: Session;
|
|
6
|
+
selected: ParamId | undefined;
|
|
7
|
+
onSelect: (id: ParamId) => void;
|
|
8
|
+
/** Selects the motion response that drives a param. */
|
|
9
|
+
onSelectNode: (id: NodeId) => void;
|
|
10
|
+
onError: ErrorHandler;
|
|
11
|
+
}): import("react").JSX.Element;
|
|
12
|
+
/**
|
|
13
|
+
* Pauses this tab's motion responses, never an edit. An editing mode pauses
|
|
14
|
+
* them on its own; `editing` keeps the button from offering a resume then.
|
|
15
|
+
*/
|
|
16
|
+
export declare function MotionToggle({ session, editing, ...rest }: {
|
|
17
|
+
session: Session;
|
|
18
|
+
editing?: boolean;
|
|
19
|
+
} & Omit<ComponentProps<"button">, "onClick" | "children">): import("react").JSX.Element;
|
|
20
|
+
export declare function BindingsPanel({ session, node, param, onError, }: {
|
|
21
|
+
session: Session;
|
|
22
|
+
node: NodeId | undefined;
|
|
23
|
+
param: ParamId | undefined;
|
|
24
|
+
onError: ErrorHandler;
|
|
25
|
+
}): import("react").JSX.Element;
|
|
26
|
+
/**
|
|
27
|
+
* A sweep through the range, never authored. Stopping restores the
|
|
28
|
+
* pre-playback value. A param a running motion response holds is never swept.
|
|
29
|
+
*/
|
|
30
|
+
export declare function usePoseSweep(session: Session | undefined, param: ParamId | undefined): {
|
|
31
|
+
playing: boolean;
|
|
32
|
+
setPlaying: import("react").Dispatch<import("react").SetStateAction<boolean>>;
|
|
33
|
+
held: boolean;
|
|
34
|
+
};
|
|
35
|
+
export declare function DeformPanel({ session, node, params, onError, }: {
|
|
36
|
+
session: Session;
|
|
37
|
+
node: NodeId;
|
|
38
|
+
params: BindingParams;
|
|
39
|
+
onError: ErrorHandler;
|
|
40
|
+
}): import("react").JSX.Element | null;
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useBindings } from "./bindings.js";
|
|
3
|
+
import { ReviewBadge, ReviewCommentButton } from "./review.js";
|
|
4
|
+
import { useEffect, useId, useMemo, useState } from "react";
|
|
5
|
+
import { useNodeInfo, useParams, useTree } from "./replica.js";
|
|
6
|
+
import { flattenTree } from "./authoring.js";
|
|
7
|
+
import { useParamActions } from "./param-actions.js";
|
|
8
|
+
import { ParamSliderRoot, ParamKeysRoot, useHeldByMotion, useMotionPaused, useMotionRunning, useParamValue, } from "./param-slider.js";
|
|
9
|
+
import { ParamFieldsRoot } from "./param-list.js";
|
|
10
|
+
import { BindingGridRoot } from "./binding-grid.js";
|
|
11
|
+
import { Disclosure, EmptyState, Field, Icon, IconButton, Modal, NumberField, SearchField, round, } from "./controls.js";
|
|
12
|
+
import { useCommand } from "./authoring.js";
|
|
13
|
+
export function ParamsPanel({ session, selected, onSelect, onSelectNode, onError, }) {
|
|
14
|
+
const params = useParams(session);
|
|
15
|
+
const tree = useTree(session);
|
|
16
|
+
const names = useMemo(() => new Map(flattenTree(tree).map((n) => [n.id, n.name])), [tree]);
|
|
17
|
+
const running = useMotionRunning(session);
|
|
18
|
+
const drivenHeading = useId();
|
|
19
|
+
const [search, setSearch] = useState("");
|
|
20
|
+
const [adding, setAdding] = useState(false);
|
|
21
|
+
const [settings, setSettings] = useState();
|
|
22
|
+
const showing = params.filter((p) => p.name.toLocaleLowerCase().includes(search.trim().toLocaleLowerCase()));
|
|
23
|
+
const posed = showing.filter((p) => !p.driven_by);
|
|
24
|
+
const driven = showing.filter((p) => p.driven_by);
|
|
25
|
+
const card = (param) => (_jsx(ParamCard, { session: session, param: param, driver: param.driven_by ? (names.get(param.driven_by) ?? param.driven_by) : undefined, selected: selected === param.id, onSelect: () => onSelect(param.id), onSelectDriver: () => param.driven_by && onSelectNode(param.driven_by), onSettings: () => setSettings(param.id) }, param.id));
|
|
26
|
+
const edit = params.find((p) => p.id === settings);
|
|
27
|
+
return (_jsxs("div", { "data-catchlight-params-panel": "", children: [_jsxs("div", { "data-catchlight-panel-tools": "", children: [_jsx(SearchField, { label: "Search params", placeholder: "Find a param\u2026", value: search, onValueChange: setSearch }), _jsxs("button", { type: "button", onClick: () => setAdding(true), children: [_jsx(Icon, { name: "plus" }), "New param"] })] }), !!posed.length && _jsx("div", { "data-catchlight-param-cards": "", children: posed.map(card) }), !!driven.length && (_jsxs("section", { "data-catchlight-driven-params": "", "aria-labelledby": drivenHeading, children: [_jsxs("div", { "data-catchlight-driven-params-head": "", children: [_jsx("h3", { id: drivenHeading, children: "Driven by motion" }), _jsx("p", { "data-catchlight-hint": "", children: running
|
|
28
|
+
? "Motion responses move these. Pause motion to pose them by hand."
|
|
29
|
+
: "Motion is paused, so these pose like any param." })] }), _jsx("div", { "data-catchlight-param-cards": "", children: driven.map(card) })] })), !params.length && (_jsx(EmptyState, { icon: "settings", title: "No params", children: "Create a param to drive transforms, opacity, tint, or mesh deform bindings." })), !!params.length && !showing.length && (_jsx(EmptyState, { icon: "search", title: "No matching params", children: "Try a different name or clear the search to see all params." })), adding && (_jsx(NewParamDialog, { session: session, onError: onError, onClose: () => setAdding(false), onAdded: onSelect })), edit && (_jsxs(Modal, { title: "Param settings", onClose: () => setSettings(undefined), children: [_jsx(ParamFieldsRoot, { session: session, param: edit, onError: onError }), _jsxs("div", { "data-catchlight-param-key-editor": "", children: [_jsx("p", { "data-catchlight-hint": "", children: "Preview the range and default value. Edit key positions on each binding." }), _jsx(ParamSliderRoot, { session: session, param: edit }), _jsx(ParamKeysRoot, { session: session, param: edit, onError: onError })] })] }))] }));
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Pauses this tab's motion responses, never an edit. An editing mode pauses
|
|
33
|
+
* them on its own; `editing` keeps the button from offering a resume then.
|
|
34
|
+
*/
|
|
35
|
+
export function MotionToggle({ session, editing = false, ...rest }) {
|
|
36
|
+
const paused = useMotionPaused(session);
|
|
37
|
+
const running = useMotionRunning(session);
|
|
38
|
+
const held = editing || (!paused && !running);
|
|
39
|
+
const label = held ? "Motion paused" : paused ? "Resume motion" : "Pause motion";
|
|
40
|
+
return (_jsxs("button", { type: "button", "data-catchlight-motion-toggle": "", "aria-label": label, "data-active": paused || held ? "" : undefined, disabled: held, title: held
|
|
41
|
+
? "Motion responses are paused while you edit"
|
|
42
|
+
: paused
|
|
43
|
+
? "Let motion responses move their params again"
|
|
44
|
+
: "Stop motion responses so you can pose their params by hand", onClick: () => session.setMotionPaused(!paused), ...rest, children: [_jsx(Icon, { name: "response", width: "13", height: "13" }), _jsx("span", { children: label })] }));
|
|
45
|
+
}
|
|
46
|
+
function ParamCard({ session, param, driver, selected, onSelect, onSelectDriver, onSettings, }) {
|
|
47
|
+
const value = useParamValue(session, param);
|
|
48
|
+
const held = useHeldByMotion(session, param);
|
|
49
|
+
return (_jsxs("div", { "data-catchlight-param-card": "", "data-selected": selected ? "" : undefined, "data-driven": driver !== undefined ? "" : undefined, "data-held": held ? "" : undefined, onPointerDown: onSelect, children: [_jsxs("div", { "data-catchlight-param-card-head": "", children: [_jsxs("button", { type: "button", "data-catchlight-param-name": "", onClick: onSelect, children: [_jsx(Icon, { name: "key", width: "13", height: "13" }), param.name] }), _jsx(ReviewBadge, { target: { kind: "param", param: param.id }, label: param.name }), _jsx(ReviewCommentButton, { target: { kind: "param", param: param.id }, label: param.name }), _jsx(IconButton, { icon: "settings", label: `Edit ${param.name}`, onClick: onSettings })] }), driver !== undefined && (_jsx("div", { "data-catchlight-param-driver": "", children: _jsxs("button", { type: "button", title: `Select the motion response “${driver}”`, onPointerDown: (event) => event.stopPropagation(), onClick: onSelectDriver, children: [_jsx(Icon, { name: "response", width: "12", height: "12" }), _jsxs("span", { children: ["Driven by ", _jsx("strong", { children: driver })] })] }) })), _jsxs("div", { "data-catchlight-param-value-row": "", children: [_jsx(ParamSliderRoot, { session: session, param: param }), _jsx(NumberField, { label: `${param.name} value`, value: value, min: param.min, max: param.max, disabled: held, onCommit: (v) => session.setParam(param.id, v) })] }), _jsxs("div", { "data-catchlight-param-range": "", children: [_jsx("span", { children: round(param.min) }), _jsx("button", { type: "button", title: "Restore default pose", disabled: held, onClick: () => session.setParam(param.id, param.default), children: Math.abs(value - param.default) < 0.0001 ? "Default" : "Reset" }), _jsx("span", { children: round(param.max) })] })] }));
|
|
50
|
+
}
|
|
51
|
+
function NewParamDialog({ session, onError, onClose, onAdded, }) {
|
|
52
|
+
const actions = useParamActions(session);
|
|
53
|
+
const [busy, setBusy] = useState(false);
|
|
54
|
+
const [name, setName] = useState("");
|
|
55
|
+
const [min, setMin] = useState(-1);
|
|
56
|
+
const [max, setMax] = useState(1);
|
|
57
|
+
const [value, setValue] = useState(0);
|
|
58
|
+
const valid = name.trim() && min < max && value >= min && value <= max;
|
|
59
|
+
return (_jsx(Modal, { title: "Create a param", onClose: onClose, children: _jsxs("form", { onSubmit: (e) => {
|
|
60
|
+
e.preventDefault();
|
|
61
|
+
if (!valid)
|
|
62
|
+
return;
|
|
63
|
+
setBusy(true);
|
|
64
|
+
void actions
|
|
65
|
+
.add({
|
|
66
|
+
name: name.trim(),
|
|
67
|
+
min,
|
|
68
|
+
max,
|
|
69
|
+
default: value,
|
|
70
|
+
})
|
|
71
|
+
.then((id) => {
|
|
72
|
+
onAdded(id);
|
|
73
|
+
onClose();
|
|
74
|
+
}, onError)
|
|
75
|
+
.finally(() => setBusy(false));
|
|
76
|
+
}, children: [_jsxs("label", { "data-catchlight-form-label": "", children: ["Name", _jsx("input", { autoFocus: true, required: true, placeholder: "e.g. Head turn", value: name, onChange: (e) => setName(e.currentTarget.value) })] }), _jsxs(Field, { label: "Range", children: [_jsx(NumberField, { label: "Minimum", value: min, unit: "Min", onCommit: setMin }), _jsx(NumberField, { label: "Maximum", value: max, unit: "Max", onCommit: setMax })] }), _jsx(Field, { label: "Default", children: _jsx(NumberField, { label: "Default value", value: value, min: min, max: max, onCommit: setValue }) }), _jsx("p", { "data-catchlight-hint": "", children: "Each binding owns its key positions. Recording adds keys where you edit." }), min >= max || value < min || value > max ? (_jsx("p", { role: "alert", "data-catchlight-hint": "", children: min >= max
|
|
77
|
+
? "Maximum must be greater than minimum."
|
|
78
|
+
: "Default must be inside the param’s range." })) : null, _jsxs("div", { "data-catchlight-dialog-actions": "", children: [_jsx("button", { type: "button", onClick: onClose, children: "Cancel" }), _jsx("button", { type: "submit", "data-primary": "", disabled: !valid || busy, children: busy ? "Creating…" : "Create param" })] })] }) }));
|
|
79
|
+
}
|
|
80
|
+
export function BindingsPanel({ session, node, param, onError, }) {
|
|
81
|
+
const params = useParams(session);
|
|
82
|
+
const [chosen, setChosen] = useState();
|
|
83
|
+
const info = useNodeInfo(session, node);
|
|
84
|
+
useEffect(() => setChosen(param), [param]);
|
|
85
|
+
const showing = params.some((p) => p.id === chosen) ? chosen : (param ?? params[0]?.id);
|
|
86
|
+
if (!node)
|
|
87
|
+
return (_jsx(EmptyState, { icon: "link", title: "No node selected", children: "Select a node on the canvas or in the tree to edit its bindings." }));
|
|
88
|
+
if (!params.length)
|
|
89
|
+
return (_jsx(EmptyState, { icon: "key", title: "No params", children: "Create a param first to bind node properties or motion responses." }));
|
|
90
|
+
return (_jsxs("div", { "data-catchlight-bindings-panel": "", children: [_jsxs(Field, { label: "Driven by", children: [_jsx("select", { "aria-label": "Param", value: showing ?? "", onChange: (e) => setChosen(e.currentTarget.value), children: params.map((p) => (_jsx("option", { value: p.id, children: p.name }, p.id))) }), _jsx("small", { children: info?.name })] }), _jsx(BindingGridRoot, { session: session, node: node, param: showing, onError: onError }, `${node}:${showing}`), showing && info?.vertex_count ? (_jsxs(Disclosure, { title: "Author a mesh deform", defaultOpen: false, children: [_jsx("p", { "data-catchlight-hint": "", children: "Apply an offset, rotation, or scale to the rest mesh at a key. This replaces the deform at that key." }), _jsx(DeformPanel, { session: session, node: node, params: { param: showing }, onError: onError }, `${node}:${showing}`)] })) : null] }));
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* A sweep through the range, never authored. Stopping restores the
|
|
94
|
+
* pre-playback value. A param a running motion response holds is never swept.
|
|
95
|
+
*/
|
|
96
|
+
export function usePoseSweep(session, param) {
|
|
97
|
+
const [playing, setPlaying] = useState(false);
|
|
98
|
+
const running = useMotionRunning(session);
|
|
99
|
+
const held = running && !!session?.params().find((p) => p.id === param)?.driven_by;
|
|
100
|
+
useEffect(() => {
|
|
101
|
+
if (!playing || !session || !param || held)
|
|
102
|
+
return;
|
|
103
|
+
const p = session.params().find((p) => p.id === param);
|
|
104
|
+
if (!p)
|
|
105
|
+
return;
|
|
106
|
+
const before = session.paramValue(param) ?? p.default;
|
|
107
|
+
let frame = 0;
|
|
108
|
+
const start = performance.now();
|
|
109
|
+
const tick = (now) => {
|
|
110
|
+
const value = p.min + (Math.sin((now - start) / 1300) + 1) * 0.5 * (p.max - p.min);
|
|
111
|
+
session.setParam(param, value);
|
|
112
|
+
frame = requestAnimationFrame(tick);
|
|
113
|
+
};
|
|
114
|
+
frame = requestAnimationFrame(tick);
|
|
115
|
+
return () => {
|
|
116
|
+
cancelAnimationFrame(frame);
|
|
117
|
+
if (!session.closed)
|
|
118
|
+
session.setParam(param, before);
|
|
119
|
+
};
|
|
120
|
+
}, [session, param, playing, held]);
|
|
121
|
+
useEffect(() => setPlaying(false), [session, param, held]);
|
|
122
|
+
return { playing, setPlaying, held };
|
|
123
|
+
}
|
|
124
|
+
export function DeformPanel({ session, node, params, onError, }) {
|
|
125
|
+
const { run, busy } = useCommand(session, onError);
|
|
126
|
+
const all = useParams(session);
|
|
127
|
+
const p = all.find((p) => p.id === params.param);
|
|
128
|
+
const binding = useBindings(session, node).find((b) => b.target === "deform" && b.param === params.param && b.param_y == params.param_y);
|
|
129
|
+
const positions = binding?.key_positions[0] ?? p?.initial_positions ?? [];
|
|
130
|
+
const [cell, setCell] = useState(0);
|
|
131
|
+
const [x, setX] = useState(0);
|
|
132
|
+
const [y, setY] = useState(0);
|
|
133
|
+
const [rotate, setRotate] = useState(0);
|
|
134
|
+
const [scale, setScale] = useState(1);
|
|
135
|
+
if (!p)
|
|
136
|
+
return null;
|
|
137
|
+
return (_jsxs("fieldset", { disabled: busy, children: [_jsx(Field, { label: "Key position", children: _jsx("select", { "aria-label": "Deform key", value: cell, onChange: (e) => {
|
|
138
|
+
const i = Number(e.currentTarget.value);
|
|
139
|
+
setCell(i);
|
|
140
|
+
session.setParam(p.id, p.min + (positions[i] ?? 0) * (p.max - p.min));
|
|
141
|
+
}, children: positions.map((k, i) => (_jsx("option", { value: i, children: round(p.min + k * (p.max - p.min)) }, i))) }) }), _jsxs(Field, { label: "Move", children: [_jsx(NumberField, { label: "Deform X", value: x, prefix: "X", onCommit: setX }), _jsx(NumberField, { label: "Deform Y", value: y, prefix: "Y", onCommit: setY })] }), _jsx(Field, { label: "Rotate", children: _jsx(NumberField, { label: "Deform rotation", value: rotate, unit: "\u00B0", onCommit: setRotate }) }), _jsx(Field, { label: "Scale", children: _jsx(NumberField, { label: "Deform scale", value: scale, onCommit: setScale }) }), _jsx("button", { type: "button", onClick: () => void (() => {
|
|
142
|
+
const mesh = session.mesh(node);
|
|
143
|
+
const radians = rotate * Math.PI / 180;
|
|
144
|
+
const cosine = Math.cos(radians) * scale, sine = Math.sin(radians) * scale;
|
|
145
|
+
const offsets = mesh.verts.map(([vx, vy]) => {
|
|
146
|
+
const dx = vx - mesh.origin[0], dy = vy - mesh.origin[1];
|
|
147
|
+
return [dx * cosine - dy * sine - dx + x, dx * sine + dy * cosine - dy + y];
|
|
148
|
+
});
|
|
149
|
+
return run({
|
|
150
|
+
cmd: "binding_cells_set", node, ...params, target: "deform",
|
|
151
|
+
if_rev: session.getRevision(), cells: [{ cell: [cell, 0], value: { offsets } }],
|
|
152
|
+
});
|
|
153
|
+
})(), children: "Set deform key" })] }));
|
|
154
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This client's selection and pose, published as one presence record.
|
|
3
|
+
*
|
|
4
|
+
* `presence_set` replaces the record whole, so every publish carries both
|
|
5
|
+
* selection and pose. A selection goes out at once; a pose is coalesced to one
|
|
6
|
+
* send per [`POSE_INTERVAL_MS`]. An existing record is adopted when a session
|
|
7
|
+
* is taken up, so a tab joins rather than overwrites it.
|
|
8
|
+
*/
|
|
9
|
+
import type { NodeId, ParamPose, Session } from "@catchlight/editor-core";
|
|
10
|
+
import type { ReactNode } from "react";
|
|
11
|
+
export declare const POSE_INTERVAL_MS = 150;
|
|
12
|
+
export interface Selection {
|
|
13
|
+
node: NodeId | undefined;
|
|
14
|
+
select(node: NodeId | undefined): void;
|
|
15
|
+
}
|
|
16
|
+
export type PoseSource = ParamPose[] | (() => ParamPose[]);
|
|
17
|
+
export interface Pose {
|
|
18
|
+
publish(pose: PoseSource): void;
|
|
19
|
+
}
|
|
20
|
+
export interface PresenceProviderProps {
|
|
21
|
+
session: Session | undefined;
|
|
22
|
+
children?: ReactNode;
|
|
23
|
+
}
|
|
24
|
+
export declare function PresenceProvider({ session, children }: PresenceProviderProps): ReactNode;
|
|
25
|
+
export declare function useSelection(): Selection;
|
|
26
|
+
/** Stable for the provider's life. */
|
|
27
|
+
export declare function usePose(): Pose;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
|
|
3
|
+
export const POSE_INTERVAL_MS = 150;
|
|
4
|
+
const SelectionContext = createContext(undefined);
|
|
5
|
+
const PoseContext = createContext(undefined);
|
|
6
|
+
function fresh(session) {
|
|
7
|
+
return { session, node: undefined, pose: [], timer: undefined, sent: undefined };
|
|
8
|
+
}
|
|
9
|
+
function clearTimer(held) {
|
|
10
|
+
if (held.timer === undefined)
|
|
11
|
+
return;
|
|
12
|
+
clearTimeout(held.timer);
|
|
13
|
+
held.timer = undefined;
|
|
14
|
+
}
|
|
15
|
+
export function PresenceProvider({ session, children }) {
|
|
16
|
+
// Keyed by session so a model switch shows no stale selection on the very
|
|
17
|
+
// render that switches.
|
|
18
|
+
const [chosen, setChosen] = useState({ session, node: undefined });
|
|
19
|
+
const node = chosen.session === session ? chosen.node : undefined;
|
|
20
|
+
const held = useRef(fresh(session));
|
|
21
|
+
const send = useCallback(() => {
|
|
22
|
+
const box = held.current;
|
|
23
|
+
box.timer = undefined;
|
|
24
|
+
if (!box.session || box.session.closed)
|
|
25
|
+
return;
|
|
26
|
+
const pose = typeof box.pose === "function" ? box.pose() : box.pose;
|
|
27
|
+
box.pose = pose;
|
|
28
|
+
const command = {
|
|
29
|
+
cmd: "presence_set",
|
|
30
|
+
pose,
|
|
31
|
+
selection: box.node ?? null,
|
|
32
|
+
};
|
|
33
|
+
const key = JSON.stringify(command);
|
|
34
|
+
if (key === box.sent)
|
|
35
|
+
return;
|
|
36
|
+
box.sent = key;
|
|
37
|
+
// Presence is a courtesy; a failed publish must not fail the gesture.
|
|
38
|
+
void box.session.sendPresence(command).catch((cause) => {
|
|
39
|
+
console.warn("catchlight: publishing presence failed", cause);
|
|
40
|
+
});
|
|
41
|
+
}, []);
|
|
42
|
+
const select = useCallback((next) => {
|
|
43
|
+
const box = held.current;
|
|
44
|
+
box.node = next;
|
|
45
|
+
setChosen({ session: box.session, node: next });
|
|
46
|
+
clearTimer(box);
|
|
47
|
+
send();
|
|
48
|
+
}, [send]);
|
|
49
|
+
const publish = useCallback((pose) => {
|
|
50
|
+
const box = held.current;
|
|
51
|
+
box.pose = pose;
|
|
52
|
+
if (box.timer === undefined)
|
|
53
|
+
box.timer = setTimeout(send, POSE_INTERVAL_MS);
|
|
54
|
+
}, [send]);
|
|
55
|
+
useEffect(() => {
|
|
56
|
+
const box = fresh(session);
|
|
57
|
+
held.current = box;
|
|
58
|
+
if (!session)
|
|
59
|
+
return () => clearTimer(box);
|
|
60
|
+
let live = true;
|
|
61
|
+
void session
|
|
62
|
+
.queryServer({ cmd: "presence_get" })
|
|
63
|
+
.then((body) => {
|
|
64
|
+
if (!live || body.result !== "presence" || !body.presence)
|
|
65
|
+
return;
|
|
66
|
+
const { pose, selection } = body.presence;
|
|
67
|
+
for (const { param, value } of pose)
|
|
68
|
+
session.setParam(param, value);
|
|
69
|
+
if (selection !== undefined && selection !== null) {
|
|
70
|
+
box.node = selection;
|
|
71
|
+
setChosen({ session, node: selection });
|
|
72
|
+
}
|
|
73
|
+
})
|
|
74
|
+
.catch((cause) => {
|
|
75
|
+
console.warn("catchlight: reading presence failed", cause);
|
|
76
|
+
});
|
|
77
|
+
return () => {
|
|
78
|
+
live = false;
|
|
79
|
+
clearTimer(box);
|
|
80
|
+
};
|
|
81
|
+
}, [session]);
|
|
82
|
+
const selection = useMemo(() => ({ node, select }), [node, select]);
|
|
83
|
+
const poseValue = useMemo(() => ({ publish }), [publish]);
|
|
84
|
+
return (_jsx(SelectionContext.Provider, { value: selection, children: _jsx(PoseContext.Provider, { value: poseValue, children: children }) }));
|
|
85
|
+
}
|
|
86
|
+
export function useSelection() {
|
|
87
|
+
const selection = useContext(SelectionContext);
|
|
88
|
+
if (!selection)
|
|
89
|
+
throw new Error("no <PresenceProvider> above this component");
|
|
90
|
+
return selection;
|
|
91
|
+
}
|
|
92
|
+
/** Stable for the provider's life. */
|
|
93
|
+
export function usePose() {
|
|
94
|
+
const pose = useContext(PoseContext);
|
|
95
|
+
if (!pose)
|
|
96
|
+
throw new Error("no <PresenceProvider> above this component");
|
|
97
|
+
return pose;
|
|
98
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Session } from "@catchlight/editor-core";
|
|
2
|
+
import { type ErrorHandler } from "./authoring.js";
|
|
3
|
+
export declare function PropertiesPanel({ session, onError }: {
|
|
4
|
+
session: Session;
|
|
5
|
+
onError: ErrorHandler;
|
|
6
|
+
}): import("react").JSX.Element;
|
|
7
|
+
export declare function AssetsPanel({ session }: {
|
|
8
|
+
session: Session;
|
|
9
|
+
}): import("react").JSX.Element;
|
|
10
|
+
export declare function TextureThumbnail({ session, texture }: {
|
|
11
|
+
session: Session;
|
|
12
|
+
texture: string;
|
|
13
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { ReviewCommentButton } from "./review.js";
|
|
3
|
+
import { useEffect, useRef, useState } from "react";
|
|
4
|
+
import { useSelection } from "./selection.js";
|
|
5
|
+
import { useNodeInfo, useReplica } from "./replica.js";
|
|
6
|
+
import { InspectorRoot } from "./inspector.js";
|
|
7
|
+
import { Disclosure, EmptyState, Icon, IconButton, SearchField } from "./controls.js";
|
|
8
|
+
import { flattenTree, kindLabels, kindIcons, useCommand } from "./authoring.js";
|
|
9
|
+
import { MaskPanel, SlotsPanel } from "./model-panels.js";
|
|
10
|
+
import { MeshPanel, MotionResponsePanel } from "./rigging.js";
|
|
11
|
+
export function PropertiesPanel({ session, onError }) {
|
|
12
|
+
const { node } = useSelection();
|
|
13
|
+
const info = useNodeInfo(session, node);
|
|
14
|
+
if (!info)
|
|
15
|
+
return (_jsx(EmptyState, { title: "No node selected", children: "Select a node on the canvas or in the tree to inspect its properties." }));
|
|
16
|
+
return (_jsxs("div", { "data-catchlight-properties": "", children: [_jsxs("div", { "data-catchlight-selection-heading": "", children: [_jsx(Icon, { name: kindIcons[info.kind] }), _jsxs("div", { children: [_jsx("strong", { children: info.name }), _jsx("small", { children: kindLabels[info.kind] })] }), _jsx(ReviewCommentButton, { target: { kind: "node", node: info.id }, label: info.name })] }), _jsx(InspectorRoot, { session: session, onError: onError }), info.kind === "part" && _jsx(ArtworkUpload, { session: session, node: info.id, onError: onError }), _jsx(MaskPanel, { session: session, info: info, onError: onError }), _jsx(MeshPanel, { session: session, info: info, onError: onError }), _jsx(MotionResponsePanel, { session: session, info: info, onError: onError }), info.kind === "part" && _jsx(SlotsPanel, { session: session, info: info, onError: onError }), _jsxs(Disclosure, { title: "Identity", defaultOpen: false, children: [_jsx("p", { "data-catchlight-hint": "", children: "Node ID" }), _jsx("code", { "data-catchlight-id": "", children: info.id }), info.parent && (_jsxs(_Fragment, { children: [_jsx("p", { "data-catchlight-hint": "", children: "Parent" }), _jsx("code", { "data-catchlight-id": "", children: info.parent })] }))] })] }, info.id));
|
|
17
|
+
}
|
|
18
|
+
function ArtworkUpload({ session, node, onError, }) {
|
|
19
|
+
const { run, busy } = useCommand(session, onError);
|
|
20
|
+
return (_jsxs("label", { "data-catchlight-upload-art": "", children: [_jsx(Icon, { name: "upload" }), "Replace artwork", _jsx("input", { type: "file", accept: ".png,.tga", "aria-label": "Replace artwork", disabled: busy, onChange: (e) => {
|
|
21
|
+
const file = e.currentTarget.files?.[0];
|
|
22
|
+
e.currentTarget.value = "";
|
|
23
|
+
if (!file)
|
|
24
|
+
return;
|
|
25
|
+
void file.arrayBuffer().then((bytes) => run({
|
|
26
|
+
cmd: "texture_add",
|
|
27
|
+
node,
|
|
28
|
+
encoding: /\.tga$/i.test(file.name) ? "tga" : "png",
|
|
29
|
+
}, [["texture", new Uint8Array(bytes)]]), onError);
|
|
30
|
+
} })] }));
|
|
31
|
+
}
|
|
32
|
+
export function AssetsPanel({ session }) {
|
|
33
|
+
const textures = useReplica(session, (s) => s.textures());
|
|
34
|
+
const parts = useReplica(session, (s) => flattenTree(s.tree())
|
|
35
|
+
.filter((n) => n.kind === "part")
|
|
36
|
+
.map((n) => s.nodeInfo(n.id)));
|
|
37
|
+
const { node, select } = useSelection();
|
|
38
|
+
const [search, setSearch] = useState("");
|
|
39
|
+
const needle = search.trim().toLocaleLowerCase();
|
|
40
|
+
const showing = textures
|
|
41
|
+
.map((texture) => ({ texture, owners: parts.filter((part) => part.texture === texture.id) }))
|
|
42
|
+
.filter(({ texture, owners }) => `${texture.id} ${owners.map((part) => part.name).join(" ")}`
|
|
43
|
+
.toLocaleLowerCase()
|
|
44
|
+
.includes(needle));
|
|
45
|
+
return (_jsxs(_Fragment, { children: [_jsx(SearchField, { label: "Search textures", placeholder: "Find artwork\u2026", value: search, onValueChange: setSearch }), !textures.length ? (_jsx(EmptyState, { icon: "part", title: "No textures", children: "Import PNG or TGA images to add part textures." })) : !showing.length ? (_jsx(EmptyState, { icon: "search", title: "No matching artwork", children: "Try a part name or clear the search to see all artwork." })) : (_jsx("div", { "data-catchlight-asset-list": "", children: showing.map(({ texture: t, owners }) => (_jsxs("button", { type: "button", "data-catchlight-asset": "", "aria-pressed": owners.some((owner) => owner.id === node), onClick: () => select(owners.find((owner) => owner.id === node)?.id ?? owners[0]?.id), title: owners.map((p) => p.name).join(", ") || t.id, children: [_jsx("span", { "data-catchlight-asset-thumb": "", children: _jsx(TextureThumbnail, { session: session, texture: t.id }) }), _jsxs("span", { children: [_jsx("strong", { children: owners[0]?.name ?? t.id }), _jsxs("small", { children: [t.width, " \u00D7 ", t.height, " px"] })] })] }, t.id))) }))] }));
|
|
46
|
+
}
|
|
47
|
+
export function TextureThumbnail({ session, texture }) {
|
|
48
|
+
const ref = useRef(null);
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
const canvas = ref.current;
|
|
51
|
+
if (!canvas)
|
|
52
|
+
return;
|
|
53
|
+
const pixels = session.textureThumbnail(texture);
|
|
54
|
+
if (!pixels)
|
|
55
|
+
return;
|
|
56
|
+
canvas.width = pixels.width;
|
|
57
|
+
canvas.height = pixels.height;
|
|
58
|
+
canvas
|
|
59
|
+
.getContext("2d")
|
|
60
|
+
?.putImageData(new ImageData(new Uint8ClampedArray(pixels.rgba), pixels.width, pixels.height), 0, 0);
|
|
61
|
+
}, [session, texture]);
|
|
62
|
+
return _jsx("canvas", { ref: ref, "aria-hidden": "true" });
|
|
63
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare function WorkspaceModes(): import("react").JSX.Element;
|
|
2
|
+
export declare function EditingBar(): import("react").JSX.Element | null;
|
|
3
|
+
export declare function RecordingInspector(): import("react").JSX.Element;
|
|
4
|
+
export declare function RecordingKeys(): import("react").JSX.Element;
|