mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-20 18:22:25 +00:00
fix(blender-camera): match Director timing and harden the export CLI
Sample frames with Director's normalized shots and runtime timing, count frames with a tolerance bounded by float rounding, coerce legacy numeric text, open the input without blocking, strip a BOM, remove a partial output on failure, and escape control characters in errors.
This commit is contained in:
1 parent
68958bf34b
commit
7db4bb35f7
14 files changed
+908
-373
No files matched your search
+13
-10
@@ -4,17 +4,9 @@ CLI scripts for camera interchange and for fetching, rendering, and reprojecting
|
||||
geospatial imagery. The imagery tools read the Google Maps API key from `.env`
|
||||
automatically.
|
||||
|
||||
## Offline Blender camera interchange
|
||||
Imagery tool output files go to `output/` by default (gitignored).
|
||||
|
||||
`export-blender-camera.mjs` exports the cameras of a saved Director scene as a
|
||||
plain-text USD stage (`.usda`) that Blender opens with File > Import >
|
||||
Universal Scene Description. It requires no key, environment file, browser,
|
||||
network access or Blender add-on, and exports no imagery or geometry. Usage,
|
||||
format and lens units: [Blender cameras](../docs/BLENDER-CAMERAS.md).
|
||||
|
||||
Output files go to `output/` by default (gitignored).
|
||||
|
||||
When invoking these tools from a separate project, set `GEV_PROJECT_ROOT` to its
|
||||
When invoking the imagery tools from a separate project, set `GEV_PROJECT_ROOT` to its
|
||||
absolute directory. Environment files, dependencies and relative output paths
|
||||
resolve there; bundled rendering HTML stays with the tool. The same setting is
|
||||
supported by `dev-fresh.sh`, `dev-secure.sh`, `opensky-import-client.sh` and the
|
||||
@@ -196,3 +188,14 @@ node tools/streetview-headings.mjs --lat 30.266476 --lon -97.73719
|
||||
# 5. Render a 3D view of the same location from above
|
||||
node tools/cesium-render.mjs --lookat-lat 30.266476 --lookat-lon -97.73719 --pitch -90 --height 50 --fov 90 --width 2560 --height-px 1440
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## export-blender-camera.mjs
|
||||
|
||||
Exports the cameras of a saved Director scene as a plain-text USD stage
|
||||
(`.usda`) that Blender opens with File > Import > Universal Scene Description.
|
||||
It needs no key, environment file, browser, network access or Blender add-on,
|
||||
and exports no imagery or geometry. `--output` is required; paths are relative
|
||||
to the current directory and `GEV_PROJECT_ROOT` is not read. Usage, format and
|
||||
lens units: [Blender cameras](../docs/BLENDER-CAMERAS.md).
|
||||
@@ -1,6 +1,7 @@
|
||||
#!/usr/bin/env node
|
||||
/** Offline scene-to-USD camera CLI. Reads JSON only; never loads .env or a viewer. */
|
||||
import { open, writeFile } from 'node:fs/promises';
|
||||
import { constants } from 'node:fs';
|
||||
import { open, unlink } from 'node:fs/promises';
|
||||
import { parseArgs } from 'node:util';
|
||||
import {
|
||||
parseSceneDocument,
|
||||
@@ -10,7 +11,12 @@ 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');
|
||||
// Non-blocking, so a FIFO without a writer reaches the isFile check instead
|
||||
// of hanging in open(). Windows has no O_NONBLOCK.
|
||||
const file = await open(
|
||||
path,
|
||||
constants.O_RDONLY | (constants.O_NONBLOCK ?? 0),
|
||||
);
|
||||
try {
|
||||
if (!(await file.stat()).isFile())
|
||||
throw new Error('input must be a regular file');
|
||||
@@ -22,12 +28,12 @@ async function readSceneText(path) {
|
||||
length,
|
||||
buffer.length - length,
|
||||
);
|
||||
if (!bytesRead) break;
|
||||
// Decode at EOF, dropping a UTF-8 BOM as Director's File.text() does.
|
||||
if (!bytesRead)
|
||||
return new TextDecoder().decode(buffer.subarray(0, length));
|
||||
length += bytesRead;
|
||||
}
|
||||
if (length > SCENE_DOCUMENT_LIMITS.bytes)
|
||||
throw new Error('Scene exceeds 5 MiB');
|
||||
return buffer.toString('utf8', 0, length);
|
||||
throw new Error('Scene exceeds 5 MiB');
|
||||
} finally {
|
||||
await file.close();
|
||||
}
|
||||
@@ -91,12 +97,26 @@ try {
|
||||
horizontalFovDegrees: Number(values['horizontal-fov-deg']),
|
||||
sensorWidthMm: Number(values['sensor-width-mm']),
|
||||
});
|
||||
await writeFile(values.output, usda, { flag: 'wx' });
|
||||
const file = await open(values.output, 'wx', 0o600);
|
||||
try {
|
||||
await file.writeFile(usda);
|
||||
await file.close();
|
||||
} catch (error) {
|
||||
// Remove the partial stage this run created, so a retry can succeed.
|
||||
await file.close().catch(() => {});
|
||||
await unlink(values.output);
|
||||
throw error;
|
||||
}
|
||||
console.log(
|
||||
`CAMERA_EXPORT_OK: ${samples.shots.length} shots, ${samples.frames.length} frames`,
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`Camera export failed: ${error.message}`);
|
||||
// Field names and IDs come from the document: escape terminal control bytes.
|
||||
const message = String(error.message).replace(
|
||||
/[\x00-\x1f\x7f-\x9f]/g,
|
||||
(char) => `\\x${char.charCodeAt(0).toString(16).padStart(2, '0')}`,
|
||||
);
|
||||
console.error(`Camera export failed: ${message}`);
|
||||
process.exitCode = 1;
|
||||
}
|
||||
Reference in new issue
Block a user