Skip to content

armgit / fuobe

Public Imported from GitHub
0

The open creative studio on ComfyUI: images, video, 3D and audio on open weights, on your own GPU or the cloud. Camera motions, effects, apps, Cinema, Layers, Image to 3D and an AI agent.

Cinema 3D scene: a capture from behind the subject stays a back view

Claude866294ae57fc
diff --git a/src/lib/scene3d.ts b/src/lib/scene3d.ts
index 95100e4d..147980f7 100644
--- a/src/lib/scene3d.ts
+++ b/src/lib/scene3d.ts
@@ -437,20 +437,25 @@ export interface ScenePose {
/**
* The flown camera as angles around the scene's pivot (the photo's centre at its median depth `pivotDepth`),
- * averaging where the camera went with where it looks (each says half of a re-shot angle), and the zoom from how
- * much tighter the frame is than the photo's (lens and distance), as Qwen Multiple Angles reads them.
+ * averaging where the camera went with where it looks (each says half of a re-shot angle; the round angle is a
+ * circular mean), and the zoom from how much tighter the frame is than the photo's (lens and distance), as Qwen
+ * Multiple Angles reads them.
*/
export function scenePose(pose: FlyPose, lensMm: number, photoLensMm: number, pivotDepth: number): ScenePose {
const pivot: Vec3 = [0, 0, -pivotDepth];
const dx = pose.position[0] - pivot[0];
const dy = pose.position[1] - pivot[1];
const dz = pose.position[2] - pivot[2];
- const orbit = Math.atan2(dx, dz) / DEG;
+ const orbit = Math.atan2(dx, dz);
const level = Math.hypot(dx, dz);
const elevation = Math.atan2(dy, Math.max(level, 1e-6)) / DEG;
- const yaw = pose.yaw / DEG;
const pitch = pose.pitch / DEG;
- const horizontal = (((orbit + wrap180(yaw)) / 2) % 360 + 360) % 360;
+ // Averaged on the circle: from behind, 179° and −179° make 180°, not 0°. Looking straight away from the
+ // subject the two cancel out, and where the camera went decides.
+ const sx = Math.sin(orbit) + Math.sin(pose.yaw);
+ const cx = Math.cos(orbit) + Math.cos(pose.yaw);
+ const mean = (Math.hypot(sx, cx) > 1e-6 ? Math.atan2(sx, cx) : orbit) / DEG;
+ const horizontal = ((mean % 360) + 360) % 360;
const vertical = clamp((elevation - pitch) / 2, -30, 90);
const distance = Math.max(1e-3, Math.hypot(dx, dy, dz));
const tighter = (lensMm / Math.max(1, photoLensMm)) * (pivotDepth / distance);
@@ -458,8 +463,6 @@ export function scenePose(pose: FlyPose, lensMm: number, photoLensMm: number, pi
return { horizontal: round(horizontal, 1) % 360, vertical: round(vertical, 1), zoom: round(zoom, 0.1) };
}
-const wrap180 = (deg: number) => ((((deg + 180) % 360) + 360) % 360) - 180;
-
/** The Multiple-Angles LoRA's own words for a pose (the same lists as the Angles app). */
export const POSE_WORDS = {
horizontal: [
diff --git a/tests/scene3d.test.ts b/tests/scene3d.test.ts
index cc5930bd..d163825b 100644
--- a/tests/scene3d.test.ts
+++ b/tests/scene3d.test.ts
@@ -231,6 +231,26 @@ describe("the captured camera → a recomposition", () => {
expect(scenePose({ position: [-3, 0, -3], yaw: -Math.PI / 2, pitch: 0 }, 24, 24, 3).horizontal).toBeCloseTo(270, 0);
});
+ it("stays a back view right behind the subject, whichever side of 180° the camera looks", () => {
+ // 3 m behind the pivot, looking back at it: the orbit angle is ~179° and the yaw goes past ±180°.
+ for (const deg of [178, 180, 182]) {
+ const p = scenePose({ position: [0.05, 0, -6], yaw: (deg * Math.PI) / 180, pitch: 0 }, 24, 24, 3);
+ expect(p.horizontal).toBeGreaterThanOrEqual(178);
+ expect(p.horizontal).toBeLessThanOrEqual(181);
+ expect(poseWords(p)).toBe("back view eye-level shot medium shot");
+ }
+ // Either side of the front, the mean wraps through 0° and stays the front, not 180° away.
+ for (const [x, deg] of [
+ [0.05, -2],
+ [-0.05, 2],
+ [0.05, 2],
+ ]) {
+ const p = scenePose({ position: [x, 0, 0], yaw: (deg * Math.PI) / 180, pitch: 0 }, 24, 24, 3);
+ expect(Math.min(p.horizontal, 360 - p.horizontal)).toBeLessThanOrEqual(2);
+ expect(poseWords(p)).toBe("front view eye-level shot medium shot");
+ }
+ });
+
it("zooms with the lens and the distance, within 0–10", () => {
expect(scenePose(start, 48, 24, 3).zoom).toBeCloseTo(10);
expect(scenePose({ ...start, position: [0, 0, -1.5] }, 24, 24, 3).zoom).toBeCloseTo(10);