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

+35 -4
View File
@@ -1,6 +1,6 @@
#!/usr/bin/env node
/** Offline scene-to-USD camera CLI. Reads JSON only; never loads .env or a viewer. */
import { readFile, writeFile, stat } from 'node:fs/promises';
import { open, writeFile } from 'node:fs/promises';
import { parseArgs } from 'node:util';
import {
parseSceneDocument,
@@ -8,8 +8,41 @@ import {
} from '../src/director/document.js';
import { exportCameraUsda } from '../src/tooling/blenderCamera.js';
/** Read a regular file through one descriptor, at most one byte past the scene limit. */
async function readSceneText(path) {
const file = await open(path, 'r');
try {
if (!(await file.stat()).isFile())
throw new Error('input must be a regular file');
const buffer = Buffer.alloc(SCENE_DOCUMENT_LIMITS.bytes + 1);
let length = 0;
while (length < buffer.length) {
const { bytesRead } = await file.read(
buffer,
length,
buffer.length - length,
);
if (!bytesRead) break;
length += bytesRead;
}
if (length > SCENE_DOCUMENT_LIMITS.bytes)
throw new Error('Scene exceeds 5 MiB');
return buffer.toString('utf8', 0, length);
} finally {
await file.close();
}
}
try {
// parseArgs reads a value starting with "-" as a missing argument, so join a
// southern-hemisphere `--origin -33.86,151.21,0` into `--origin=...` first.
const args = process.argv.slice(2);
for (let i = args.length - 2; i >= 0; i -= 1) {
if (args[i] === '--origin' && /^-[\d.]/.test(args[i + 1]))
args.splice(i, 2, `--origin=${args[i + 1]}`);
}
const { values } = parseArgs({
args,
options: {
input: { type: 'string' },
output: { type: 'string' },
@@ -46,9 +79,7 @@ try {
const originParts = values.origin.split(',');
if (originParts.length !== 3 || originParts.some((part) => !part.trim()))
throw new Error('origin must be lat,lon,ellipsoidHeight');
if ((await stat(values.input)).size > SCENE_DOCUMENT_LIMITS.bytes)
throw new Error('Scene exceeds 5 MiB');
const document = parseSceneDocument(await readFile(values.input, 'utf8'));
const document = parseSceneDocument(await readSceneText(values.input));
const [numerator, denominator = 1] = values.fps.split('/').map(Number);
const [lat, lon, height] = originParts.map(Number);
const { usda, samples } = exportCameraUsda(document, {