fix(blender-camera): accept southern origins and bound the scene read

- Join a space-separated negative latitude to --origin before parseArgs,
  so `--origin -33.86,151.21,0` works as the usage and docs show.
- Read the input through one descriptor, regular files only, at most one
  byte past the 5 MiB scene limit.
- Use geodetic ENU axes at the origin (ellipsoid normal at its lat/lon,
  raised to its height) instead of Cesium's frame at the raised point.
- Reuse the shots already resolved, serialize the sampled shot table
  directly, and drop the typeof-only export test.
- Docs: timing matches Director seeking, with the playback differences;
  add a manual OpenUSD/Blender check; shorten the overview and test list.
This commit is contained in:
German Khokhlov committed 2026-11-19 18:24:55 +04:00
1 parent 4668f26e0e
commit 235938e19b
6 files changed
+116 -66

No files matched your search

+12 -35
View File
@@ -68,13 +68,17 @@ export function cameraPoseToEnu(pose, origin) {
);
if (C.Cartesian3.distance(xyz, anchor) > 100000)
throw new RangeError('Camera exceeds the 100 km local-origin limit');
// Geodetic ENU (as in PROJ): axes from the ellipsoid normal at the origin's
// lat/lon, origin raised along it. Cesium's frame at a raised point tilts.
const frame = C.Transforms.eastNorthUpToFixedFrame(
C.Cartesian3.fromDegrees(origin.lon, origin.lat, 0, C.Ellipsoid.WGS84),
);
const inverse = C.Matrix4.inverseTransformation(
C.Transforms.eastNorthUpToFixedFrame(anchor),
C.Matrix4.setTranslation(frame, anchor, frame),
new C.Matrix4(),
);
const local = C.Matrix4.multiplyByPoint(inverse, xyz, new C.Cartesian3());
// Same basis as Cesium Camera.setView3D, including its heading - PI/2 offset.
// This is the coordinate math retained from the staged ENU camera prototype.
const rotation = C.Matrix3.fromQuaternion(
C.Quaternion.fromHeadingPitchRoll(
new C.HeadingPitchRoll(
@@ -117,7 +121,7 @@ function identity(value, label) {
return value;
}
/** Resolve the flight-plus-hold seconds and holds that Director playback and seeking use.
/** Resolve the flight-plus-hold seconds and holds that Director seeking uses.
* Both come from shotPresentation.js, so registered pack overrides, minimum holds and
* evidence-sequence durations match the app instead of the saved holdSec alone.
*/
@@ -146,7 +150,7 @@ export function sceneRuntimeTiming(
};
}
/** Sample one saved scene with Director seek interpolation and runtime playback timing.
/** Sample one saved scene with Director seek interpolation and runtime seek timing.
* Projection is explicit because scene documents do not store viewport lenses.
* Frame 1 samples time zero; the final sample precedes the exclusive end time.
*/
@@ -205,11 +209,10 @@ export function sampleSceneCameras(
),
move: resolveCameraMove(scene, shot),
}));
const shots = scene.shots.map((shot) => {
const shots = scene.shots.map((shot, index) => {
identity(shot.id, 'Shot');
const camera = resolveCameraPose(scene, shot.camera);
const { target: camera, move } = resolved[index];
position(camera);
const move = resolveCameraMove(scene, shot);
if (move) position(move.from);
cameraPoseToEnu(camera, origin);
if (move) cameraPoseToEnu(move.from, origin);
@@ -340,7 +343,7 @@ export function sampleSceneCameras(
};
}
/** Shortest decimal for a finite double, without signed zero or 17-digit noise. */
/** Round a finite double to 15 significant digits and normalize signed zero. */
function usdNumber(value) {
const rounded = Number(value.toPrecision(15));
return Object.is(rounded, -0) ? '0' : String(rounded);
@@ -378,32 +381,6 @@ function usdMatrix({ position: p, basisColumns: [right, up, back] }) {
export function cameraSamplesToUsda(samples) {
const { source, coordinates, camera, timeline, shots, frames } = samples;
const rate = timeline.fps.numerator / timeline.fps.denominator;
const shotTable = shots.map(
({
id,
title,
sourcePackId,
sourcePackVersion,
startTimeSec,
endTimeSec,
flightDurationSec,
authoredHoldSec,
runtimeHoldSec,
frameStart,
frameEndExclusive,
}) => ({
id,
title,
...(sourcePackId ? { sourcePackId, sourcePackVersion } : {}),
startTimeSec,
endTimeSec,
flightDurationSec,
authoredHoldSec,
runtimeHoldSec,
frameStart,
frameEndExclusive,
}),
);
const json = (value) => usdString(JSON.stringify(value));
const out = [
'#usda 1.0',
@@ -412,7 +389,7 @@ export function cameraSamplesToUsda(samples) {
` string gevCamera = ${json(camera)}`,
` string gevCoordinates = ${json(coordinates)}`,
` string gevSchema = ${usdString(CAMERA_USD_SCHEMA)}`,
` string gevShots = ${json(shotTable)}`,
` string gevShots = ${json(shots)}`,
` string gevSource = ${json(source)}`,
` string gevTimeline = ${json(timeline)}`,
' }',
+46 -5
View File
@@ -21,10 +21,6 @@ import { createDefaultScenePacks } from '../scenes/packs/defaults.js';
import { createScenePackRegistry } from '../scenes/packs/registry.js';
const adapter = await import('./blenderCamera.js');
test('a portable USD camera exporter exists', () => {
assert.equal(typeof adapter.sampleSceneCameras, 'function');
assert.equal(typeof adapter.exportCameraUsda, 'function');
});
const origin = { lat: 0, lon: 0, height: 0 };
const pose = (changes = {}) => ({
@@ -76,6 +72,14 @@ test('cardinal cameras use Blender X right, Y up, negative Z forward', () => {
test('ENU translation uses WGS84 meters and ellipsoid heights', () => {
near(camera({ alt: 100 }).position, [0, 0, 100]);
near(
camera(
{ lat: 39.7, lon: -105, alt: 2600 },
{ origin: { lat: 39.7, lon: -105, height: 1600 } },
).position,
[0, 0, 1000],
1e-6,
);
const east = camera({ lon: 0.001 }).position;
assert.ok(Math.abs(east[0] - 111.3194907876) < 1e-6);
assert.ok(Math.abs(east[2] + 0.0009714458) < 1e-6);
@@ -107,7 +111,7 @@ test('changed tangent frames and nonzero roll match an independent Cesium Camera
});
const inverse = Cesium.Matrix4.inverseTransformation(
Cesium.Transforms.eastNorthUpToFixedFrame(
Cesium.Cartesian3.fromDegrees(anchor.lon, anchor.lat, anchor.height),
Cesium.Cartesian3.fromDegrees(anchor.lon, anchor.lat, 0),
),
new Cesium.Matrix4(),
);
@@ -340,6 +344,43 @@ test('CLI works in paths with spaces and refuses overwrites or invalid projectio
}
});
test('CLI accepts a negative latitude passed as --origin <value>', () => {
const directory = mkdtempSync(join(tmpdir(), 'gev origin '));
try {
const script = fileURLToPath(
new URL('../../tools/export-blender-camera.mjs', import.meta.url),
);
const result = spawnSync(
process.execPath,
[
script,
'--input',
join(directory, 'missing scene.json'),
'--output',
join(directory, 'cameras.usda'),
'--origin',
'-33.8568,151.2153,0',
'--fps',
'30',
'--width',
'1920',
'--height',
'1080',
'--horizontal-fov-deg',
'60',
],
{ encoding: 'utf8' },
);
// The input file does not exist, so the run still fails, but only after
// argument parsing: the error must be about the input, not about --origin.
assert.equal(result.status, 1);
assert.doesNotMatch(result.stderr, /ambiguous|--origin/);
assert.match(result.stderr, /ENOENT|no such file/i);
} finally {
rmSync(directory, { recursive: true, force: true });
}
});
test('ordinary submillisecond shots retain the Director seek duration floor', () => {
const p = project([
{ id: 'start', camera: pose(), durationSec: 0.033, holdSec: 0 },