feat: add axis-aligned 3d camera views

This commit is contained in:
2026-08-30 11:40:21 +09:00
parent 51c7bbd859
commit 2a2e192196
12 changed files with 619 additions and 61 deletions
+36
View File
@@ -0,0 +1,36 @@
export const ORBIT_VIEW_DIRECTIONS = Object.freeze([
"iso",
"+x",
"-x",
"+y",
"-y",
"+z",
"-z",
]);
const ORBITS = Object.freeze({
iso: Object.freeze({
yaw: -Math.PI / 4,
pitch: Math.asin(1 / Math.sqrt(3)),
}),
"+x": Object.freeze({ yaw: -Math.PI / 2, pitch: 0 }),
"-x": Object.freeze({ yaw: Math.PI / 2, pitch: 0 }),
"+y": Object.freeze({ yaw: Math.PI, pitch: 0 }),
"-y": Object.freeze({ yaw: 0, pitch: 0 }),
"+z": Object.freeze({ yaw: 0, pitch: Math.PI / 2 }),
"-z": Object.freeze({ yaw: Math.PI, pitch: -Math.PI / 2 }),
});
/**
* Return the orthographic camera orbit for a view from the named axis toward
* the array origin. A fresh object prevents one view from mutating another.
*/
export function orbitForViewDirection(direction = "iso") {
const orbit = ORBITS[direction];
if (!orbit) {
throw new RangeError(
"view direction must be one of: " + ORBIT_VIEW_DIRECTIONS.join(", "),
);
}
return { ...orbit };
}