The VS Code of video editing, built for agents.
TypeScript
Refactor object mask handling and enhance effects inspector functionality
konstantin-paulus5c685e15b00b
diff --git a/apps/web/src/components/sidebar-right/inspector/effects-inspector.tsx b/apps/web/src/components/sidebar-right/inspector/effects-inspector.tsxindex 705d30d8..1da718c9 100644--- a/apps/web/src/components/sidebar-right/inspector/effects-inspector.tsx+++ b/apps/web/src/components/sidebar-right/inspector/effects-inspector.tsx@@ -37,7 +37,7 @@ import {import { SliderInput } from "@/components/ui/slider-input";import { ControlledTextField } from "@/components/ui/text-field";import { useHas, useTrait, useWorld } from "@diffusionstudio/koota-solid";-import { Cache, Computed, Effect, Hidden } from "@diffusionstudio/runtime";+import { Cache, Computed, Effect, Hidden, getParentNode } from "@diffusionstudio/runtime";import { useDerived, useEditor } from "@/engine/hooks";import { removeKeyframeTrack, syncKeyframe } from "@/engine/keyframes";import { copyObjectMask, useObjectMasks } from "@/engine/object-mask";@@ -81,7 +81,7 @@ export function EffectsInspector(props: EffectsInspectorProps) {const value = useDerived(() => props.effect.get(Computed)?.value ?? 0);const masks = useDerived(() => props.effect.get(Cache)?.masks ?? NO_MASKS);- const groups = useObjectMasks();+ const groups = useObjectMasks(() => getParentNode(props.effect));const editingMask = createMemo(() => {const mask = pickedMask();diff --git a/apps/web/src/components/sidebar-right/inspector/object-mask.tsx b/apps/web/src/components/sidebar-right/inspector/object-mask.tsxindex 7bc113a9..eaf2db66 100644--- a/apps/web/src/components/sidebar-right/inspector/object-mask.tsx+++ b/apps/web/src/components/sidebar-right/inspector/object-mask.tsx@@ -29,7 +29,7 @@ import { SliderInput } from "@/components/ui/slider-input";import { Switch, SwitchControl, SwitchInput, SwitchThumb } from "@/components/ui/switch";import { ControlledTextField } from "@/components/ui/text-field";import { useHas, useTrait, useWorld } from "@diffusionstudio/koota-solid";-import { AssetId, Computed, Hidden, Library, Mask, VideoDecoderHandle } from "@diffusionstudio/runtime";+import { AssetId, Computed, Hidden, Library, Mask, VideoDecoderHandle, getParentNode } from "@diffusionstudio/runtime";import { useDerived, useEditor } from "@/engine/hooks";import { syncKeyframe } from "@/engine/keyframes";import {@@ -117,8 +117,8 @@ export function ObjectMaskInspector(props: ObjectMaskInspectorProps) {const name = useDerived(() => objectMaskName(world, props.mask));- // Every mask in the library, by folder: the header picks which of them this mask is.- const groups = useObjectMasks();+ // Every mask in the library, the clip's own first: the header picks which of them this mask is.+ const groups = useObjectMasks(() => getParentNode(getParentNode(props.mask)));const source = () =>groups().flatMap((group) => group.masks)diff --git a/apps/web/src/engine/object-mask/copy.tsx b/apps/web/src/engine/object-mask/copy.tsxindex 0a54acf5..4cff8707 100644--- a/apps/web/src/engine/object-mask/copy.tsx+++ b/apps/web/src/engine/object-mask/copy.tsx@@ -2,7 +2,7 @@* License, v. 2.0. If a copy of the MPL was not distributed with this* file, You can obtain one at http://mozilla.org/MPL/2.0/. */-import { assetFolder, assetName, basename } from '@diffusionstudio/assets';+import { assetName } from '@diffusionstudio/assets';import { Mask } from '@diffusionstudio/reconciler';import { AssetId, Blur, Cache, Library, Mask as MaskTrait, getParentNode } from '@diffusionstudio/runtime';@@ -21,37 +21,36 @@ export type ObjectMaskSource = {sourceIn: number;};-/** The masks of one library folder, under the folder's name: a section of the mask menus. */+/** A section of the mask menus: a heading and the masks under it. */export type ObjectMaskGroup = {- /** What to call the section: the folder's own name. */+ /** What to call the section. */name: string;masks: ObjectMaskSource[];};/**- * Every mask in `library`, grouped by the folder it is in — a mask is not- * tied to the clip it was tracked on, so any effect can take any of them.- * Folders keep the library's order. It reads the library's asset list, a- * signal, so a memo over it runs again only when the library changes (see- * `useObjectMasks`).+ * Every mask in `library`, the ones tracked on the video `footage` (its asset+ * id, the clip's own footage) first, under that video's name, and all the+ * others after them as "Others" — any effect can take any mask, but the+ * clip's own are the likely pick. Empty sections are left out. It reads the+ * library's asset list, a signal, so a memo over it runs again only when the+ * library changes (see `useObjectMasks`).*/-export function objectMaskGroups(library: AssetLibrary): ObjectMaskGroup[] {- const groups = new Map<string, ObjectMaskGroup>();+export function objectMaskGroups(library: AssetLibrary, footage: string | null): ObjectMaskGroup[] {+ const video = footage ? library.get(footage) : undefined;+ const own: ObjectMaskGroup = { name: video ? assetName(video).replace(/\.[^.]+$/, '') : '', masks: [] };+ const others: ObjectMaskGroup = { name: 'Others', masks: [] };+for (const asset of library.list()) {if (asset.type !== 'MASK') continue;- const folder = assetFolder(asset);- let group = groups.get(folder);- if (!group) {- group = { name: basename(folder) || 'Library', masks: [] };- groups.set(folder, group);- }+ const group = video && asset.recipe?.source === video.id ? own : others;group.masks.push({asset,name: assetName(asset).replace(/\.[^.]+$/, ''),sourceIn: asset.recipe ? asset.recipe.first / asset.frameRate : 0,});}- return [...groups.values()];+ return [own, others].filter((group) => group.masks.length > 0);}/**diff --git a/apps/web/src/engine/object-mask/use-object-masks.ts b/apps/web/src/engine/object-mask/use-object-masks.tsindex 2b9cfd2c..e6499871 100644--- a/apps/web/src/engine/object-mask/use-object-masks.ts+++ b/apps/web/src/engine/object-mask/use-object-masks.ts@@ -2,22 +2,35 @@* License, v. 2.0. If a copy of the MPL was not distributed with this* file, You can obtain one at http://mozilla.org/MPL/2.0/. */+import { findGeometryAsset } from '@diffusionstudio/runtime';+import { useWorld } from '@diffusionstudio/koota-solid';import { createMemo } from 'solid-js';+import { useDerived } from '../hooks';import { useLibrary } from '../library';import { objectMaskGroups } from './copy';import type { Accessor } from 'solid-js';+import type { Entity } from 'koota';import type { ObjectMaskGroup } from './copy';/**- * Every mask in the library, grouped by its folder (see `objectMaskGroups`),- * reactively: scanned again only when the library's asset list changes.+ * Every mask in the library, `clip`'s own first (see `objectMaskGroups`),+ * reactively. Which video the clip plays is sampled per tick as an id — a+ * lookup, compared by value — and the library is scanned only when that id+ * or the library's asset list changes, not every frame.*/-export function useObjectMasks(): Accessor<ObjectMaskGroup[]> {+export function useObjectMasks(clip: () => Entity | null | undefined): Accessor<ObjectMaskGroup[]> {+ const world = useWorld();const library = useLibrary();++ const footage = useDerived(() => {+ const node = clip();+ const asset = node ? findGeometryAsset(world, node) : null;+ return asset?.type === 'VIDEO' ? asset.id : null;+ });return createMemo(() => {const current = library();- return current ? objectMaskGroups(current) : [];+ return current ? objectMaskGroups(current, footage()) : [];});}