Skip to content

The VS Code of video editing, built for agents.

TypeScript

Enhance canvas interaction handling with scene coverage checks

konstantin-paulus5ea57654d6f2
diff --git a/apps/web/src/engine/input/interactions.ts b/apps/web/src/engine/input/interactions.ts
index ba98782d..f0ca5b62 100644
--- a/apps/web/src/engine/input/interactions.ts
+++ b/apps/web/src/engine/input/interactions.ts
@@ -24,7 +24,8 @@ import {
entityOffset, entityQuad, entityWorldMat, enterEntity,
findKeyframeTrackEntity, getParentEntity, getParentNode, getSceneAncestor,
getSelection, getSelectionMask, identity2D, invert2D, isPointerInEntity,
- multiply2D, quadCenter, quadsIntersect, rectToQuad, rotate2D, scale2D,
+ multiply2D, quadCenter, quadContainsQuad, quadsIntersect, rectToQuad,
+ rotate2D, scale2D,
store, syncInteractiveState, transformPoint, translate2D,
} from '@diffusionstudio/runtime';
import { Not, Or } from 'koota';
@@ -200,8 +201,26 @@ export function handleCanvasInteraction(world: World, event: DispatchedPointerEv
const marquee = getMarqueeQuad(world);
if (marquee) {
- editor.select([...world.query(Interactive, Or(Geometry, Group), Not(Culled))]
- .filter((entity) => quadsIntersect(marquee, entityQuad(world, entity))));
+ const computed = store(world, Computed);
+
+ const scenes = world.query(Scene, ChildOf(world.get(Root)!), Not(Interactive), Not(Culled))
+ .filter((scene) => quadContainsQuad(marquee, entityQuad(world, scene)));
+
+ const inCoveredScene = (entity: Entity): boolean => {
+ for (let scene = getSceneAncestor(entity); scene !== null; scene = getSceneAncestor(scene)) {
+ if (scenes.includes(scene)) return true;
+ }
+ return false;
+ };
+
+ const nodes = world.query(Interactive, Or(Geometry, Group), Not(Culled))
+ .filter((entity) => (
+ computed.visibility[entity.id()] !== 0
+ && quadsIntersect(marquee, entityQuad(world, entity))
+ && !inCoveredScene(entity)
+ ));
+
+ editor.select([...scenes, ...nodes]);
}
updateCursor(world, getToolCursor(world));
diff --git a/packages/runtime/src/math/aabb.ts b/packages/runtime/src/math/aabb.ts
index fdd71a42..7aafae11 100644
--- a/packages/runtime/src/math/aabb.ts
+++ b/packages/runtime/src/math/aabb.ts
@@ -99,7 +99,9 @@ export function pointInQuad(px: number, py: number, q: Quad): boolean {
return inside;
}
-/** Test whether two quads intersect (vertex containment check). */
+/**
+ * Test whether two quads intersect (vertex containment check).
+ */
export function quadsIntersect(a: Quad, b: Quad): boolean {
for (let i = 0; i < 4; i++) {
if (pointInQuad(a[i].x, a[i].y, b)) return true;
@@ -108,6 +110,17 @@ export function quadsIntersect(a: Quad, b: Quad): boolean {
return false;
}
+/**
+ * Test whether `outer` wholly contains `inner`. Quads are transformed rects,
+ * so both are convex and corner containment is containment.
+ */
+export function quadContainsQuad(outer: Quad, inner: Quad): boolean {
+ for (let i = 0; i < 4; i++) {
+ if (!pointInQuad(inner[i].x, inner[i].y, outer)) return false;
+ }
+ return true;
+}
+
/** Center point of a quad. */
export function quadCenter(q: Quad): Point {
return {