Skip to content
Headless Automation

Headless Automation

Run SpatialEngine without a GPU for data processing and other workflows that use statements without a rendered viewport.

Native engine

SpatialEngine --no-gpu

Connect through the Python SDK. This engine runs statements without drawing or streaming a viewport. Rendering and GPU-dependent work require a GPU-enabled engine.

Node.js

Use Node.js 22 or newer. Install the npm package, save this as automation.mjs, and run node automation.mjs.

Read the WebAssembly from the installed package. The engine starts with no coordinate reference systems. Statements that place things on a map need the EPSG and OGC registry files, which geodata.loadRegistryFile reads from the package’s geodata folder through Node’s filesystem. The OGC file defines OGC:CRS84, the longitude and latitude an Earth map is read in.

import { readFile } from "node:fs/promises";
import init, { Client, geodata } from "@fslabs/spatialengine";

try {
  const packageUrl = import.meta.resolve("@fslabs/spatialengine");
  const wasm = await readFile(new URL("./spatialengine.wasm", packageUrl));
  await init({ module_or_path: wasm, noGpu: true });
  await geodata.loadRegistryFile("epsg.bin");
  await geodata.loadRegistryFile("ogc.bin");
  const client = await Client.connect();
  console.log(await client.print({ message: "Automation ready" }));
  process.exit(0);
} catch (error) {
  console.error(error);
  process.exit(1);
}

The engine keeps Node’s event loop alive. Exit after all required statements finish, including when a statement fails.

Web workers

In a web worker, pass the served WebAssembly and geodata manifest URLs to initialization:

import init, { Client, geodata } from "@fslabs/spatialengine";

await init({
  module_or_path: new URL("./spatialengine.wasm", import.meta.url),
  geodataUrl: new URL("./geodata/manifest.json", import.meta.url),
  noGpu: true,
});
await geodata.loadRegistryFile("epsg.bin");
await geodata.loadRegistryFile("ogc.bin");
const client = await Client.connect();
console.log(await client.print({ message: "Automation ready" }));

Serve spatialengine.wasm and the geodata folder from the same release beside the worker module, or use their actual URLs. noGpu defaults to true when the host has no document.

Ordering and completion

Await dependent statements in sequence. After project edits, use project.wait_for_scene_sync in Python or project.waitForSceneSync in TypeScript before reading scene state that depends on those edits.

Wait for all submitted transaction operations before committing. Independent calls can run concurrently.

Background pages

An in-page engine reduces updates when its page is inactive. Set continuousUpdates: true in init when background work needs subsequent frames to complete. This keeps the engine updating while the page is hidden.