Art and animation, written as code. Illustrations, loops, interactive web art, launch-videos and scored films in dozens of styles, identical on every render.
TypeScript agent-skillsanimationcanvasclaude-codeclaude-pluginclaude-skillscodex-plugincreative-codecreative-codingcreative-toolsdeterministicgenerative-arthand-drawnillustrationlaunch-videomotion-designmotion-graphicspluginprocedural-generationskill
probe3d: 3D objects report their screen box so framecheck catches 3D type cut by the frame edge
Alex Greenshpun72a8f415b67b
diff --git a/skills/anidoodle/engine/src/canvas-core/threeTypeDemo.ts b/skills/anidoodle/engine/src/canvas-core/threeTypeDemo.tsindex 69e1c38..799c5c7 100644--- a/skills/anidoodle/engine/src/canvas-core/threeTypeDemo.ts+++ b/skills/anidoodle/engine/src/canvas-core/threeTypeDemo.ts@@ -6,7 +6,7 @@import type { Ctx, Env } from "./core";import type { Film } from "./film";import * as THREE from "three";-import { draw3d, memo } from "../three-core/stage";+import { draw3d, memo, probe3d } from "../three-core/stage";import { ease, lerp, seg, spring, tween } from "../three-core/time";import { defaultFont, text3d, textPlane, type Letter } from "../three-core/type3d";import { contactShadow, grain, matte, outline, satin, studio, toon, vignette } from "../three-core/look";@@ -68,7 +68,7 @@ const sceneA = (ctx: Ctx, env: Env, f: number) => {letters.forEach((l, i) => drop(l, f, -6 + i * 3.2, i, shadows[i]));const t = tween(f, 0, 96, ease.outCubic);cam.position.set(lerp(-0.7, 0.5, t), lerp(2.9, 2.2, t), lerp(12.6, 11.2, t)); cam.lookAt(0, -0.05, 0);- draw3d(ctx, env, scene, cam, { clear: "#efe3d2" });+ draw3d(ctx, env, scene, cam, { clear: "#efe3d2" }); if (f >= 48) probe3d(ctx, env, letters[0].parent!, cam, "anidoodle"); /* the letters drop in from above the frame on purpose; the word must read whole once it has landed */};// ---------------------------------------------------------------- scene B: "now in 3D", toon and ink@@ -101,7 +101,7 @@ const sceneB = (ctx: Ctx, env: Env, f: number) => {word.rotation.y = lerp(-0.22, 0.16, tween(f, 0, 96, ease.inOutSine));const t = tween(f, 0, 96, ease.inOutSine);cam.position.set(lerp(0.8, -0.4, t), lerp(2.8, 2.1, t), lerp(12.2, 11.0, t)); cam.lookAt(0, -0.1, 0);- draw3d(ctx, env, scene, cam, { clear: "#2d3f8f" });+ draw3d(ctx, env, scene, cam, { clear: "#2d3f8f" }); probe3d(ctx, env, word, cam, "now in 3D");};// ---------------------------------------------------------------- scene C: the end card@@ -129,7 +129,7 @@ const sceneC = (ctx: Ctx, env: Env, f: number) => {(made.material as THREE.MeshBasicMaterial).opacity = pm; made.position.y = 1.3 + (1 - pm) * 0.12;const t = tween(f, 0, 48, ease.outCubic);cam.position.set(0, lerp(0.7, 0.55, t), lerp(9.2, 8.6, t)); cam.lookAt(0, 0.2, 0);- draw3d(ctx, env, scene, cam, { clear: "#efe3d2" });+ draw3d(ctx, env, scene, cam, { clear: "#efe3d2" }); probe3d(ctx, env, letters[0].parent!, cam, "anidoodle");};// ---------------------------------------------------------------- finish and shotsdiff --git a/skills/anidoodle/engine/src/three-core/stage.ts b/skills/anidoodle/engine/src/three-core/stage.tsindex c76ac1f..ab971dd 100644--- a/skills/anidoodle/engine/src/three-core/stage.ts+++ b/skills/anidoodle/engine/src/three-core/stage.ts@@ -13,6 +13,7 @@// esbuild then drops the parts a film never uses (the file loaders that could fetch, among them).import * as THREE from "three";import type { Ctx, Env } from "../canvas-core/core";+import { probeRect } from "../canvas-core/core";// Hosts see this string in the page bundle and start Chrome with WebGL on (adapters/playwright.mjs).export const WEBGL_MARKER = "__ANIDOODLE_WEBGL__";@@ -92,3 +93,28 @@ export const rand = (seed: number) => {let a = seed >>> 0;return () => { a = (a + 0x6d2b79f5) >>> 0; let t = a; t = Math.imul(t ^ (t >>> 15), t | 1); t ^= t + Math.imul(t ^ (t >>> 7), t | 61); return ((t ^ (t >>> 14)) >>> 0) / 4294967296; };};++/**+ * Report a 3D object's on-screen box to the frame probe, so framecheck.mjs catches 3D type or a+ * hero object cut by the frame edge (the 2D drawing code reports its boxes the same way). Call it+ * after positioning the camera, for anything the viewer must see whole. No cost unless framecheck+ * is running. The box is the projected corners of the object's world bounding box.+ */+const _box = new THREE.Box3(), _v = new THREE.Vector3();+export const probe3d = (ctx: Ctx, env: Env, object: THREE.Object3D, camera: THREE.Camera, label: string, kind: "text" | "box" = "text") => {+ if (!(globalThis as { __ANIDOODLE_PROBE__?: unknown }).__ANIDOODLE_PROBE__) return;+ if ((camera as THREE.PerspectiveCamera).isPerspectiveCamera) { const c = camera as THREE.PerspectiveCamera; c.aspect = env.W / env.H; c.updateProjectionMatrix(); }+ object.updateWorldMatrix(true, true); camera.updateMatrixWorld();+ _box.setFromObject(object); if (_box.isEmpty()) return;+ let x0 = Infinity, y0 = Infinity, x1 = -Infinity, y1 = -Infinity;+ for (let i = 0; i < 8; i++) {+ _v.set(i & 1 ? _box.max.x : _box.min.x, i & 2 ? _box.max.y : _box.min.y, i & 4 ? _box.max.z : _box.min.z).project(camera);+ if (_v.z > 1) continue; // behind the camera: not on screen+ const x = ((_v.x + 1) / 2) * env.W, y = ((1 - _v.y) / 2) * env.H;+ x0 = Math.min(x0, x); y0 = Math.min(y0, y); x1 = Math.max(x1, x); y1 = Math.max(y1, y);+ }+ if (!Number.isFinite(x0)) return;+ ctx.save(); ctx.setTransform(env.scale, 0, 0, env.scale, 0, 0); ctx.globalAlpha = 1;+ probeRect(ctx, env, x0, y0, x1 - x0, y1 - y0, label, kind);+ ctx.restore();+};