Crescent Engine
Documentation

Spatial SDK for Python and C

Embed fixed-step simulation in your own program. Apply an action, step physics, and read synchronized entity or camera observations.

Install the standalone SDK

Use Apple silicon and macOS 26.1+. Extract the Spatial SDK. The archive includes libCrescentSpatial.dylib, SpatialRuntime.h, Python bindings and a sample task. Launch from the folder containing CSDK-Sim.

Step a task from Python

Terminal · Python 3.10+
PYTHONPATH="$PWD/CSDK-Sim/python" python3 - <<'PYTHON'
from crescent_spatial import Sim

with Sim("CSDK-Sim/lib/libCrescentSpatial.dylib") as sim:
    sim.reset(42)
    before = sim.entities()
    print("Initial:", before.step_index, "tick;", before.count, "bodies")
    sim.impulse(2, (1.5, 0.0, 0.0))
    result = sim.step(4)
    print("After action:", result.step_index, "ticks; reward", result.reward)
    print("Episode finished:", bool(result.episode_done))
PYTHON

The default example starts at tick 0 with two bodies. After the impulse and four steps the tick is 4. Reward and termination come from the task. To use your own task, pass scene="/path/to/MyTask.spatial.json" to Sim.

Author a task file

This is the reach-target task included in the Spatial SDK. Save a copy as MyTask.spatial.json and pass its path to Sim or ce_spatial_sim_create.

MyTask.spatial.json
{
  "version": 1,
  "gravity": [0, -9.81, 0],
  "max_episode_steps": 600,
  "bodies": [
    {"id": 1, "semantic_class": 1, "cell_id": 1, "position": [0, -0.5, 0], "half_extents": [10, 0.5, 10], "mass": 0},
    {"id": 2, "semantic_class": 2, "cell_id": 1, "position": [0, 1.5, 0], "half_extents": [0.25, 0.25, 0.25], "mass": 1, "spawn_jitter": 0.125}
  ],
  "goal": {"entity_id": 2, "position": [2, 0.25, 0], "radius": 0.5}
}

Body IDs identify targets of actions and feedback. A mass of zero gives a static body. half_extents measures half the width, height and depth of the box. spawn_jitter uses the reset seed. The task scores the center of body 2 against the goal position and radius, in meters.

Use feedback.episode_done to detect the end of an episode. The bundled reach-target sample gives 0 while running, +1 on arrival and −1 on timeout. The Editor and current Bench also support a forbidden-contact task that terminates with −1. The downloadable standalone SDK accepts version 1 and 2 box tasks. Use the matching Editor or Bench build for a version 3 task with forbidden-contact rules. Preserve the scene binding, camera metadata and entity IDs when moving a captured task.

Read observations

sim.entities() returns an engine-owned view. Read it before applying actions, stepping, resetting or closing. To retain values across steps, copy the fields you need into your own memory.

Python · add inside the with block
from crescent_spatial import CameraConfig

sim.set_camera(1, CameraConfig(width=128, height=128))
image = sim.camera(1)
print("Camera tick:", image.step_index, "row bytes:", image.row_stride)
with image.plane("color") as rgba:
    print("RGBA bytes:", len(rgba))
Color
RGBA8 with four unsigned bytes per pixel.
Depth
Float32 meters. Treat positive infinity as no geometry.
Semantic and instance
Unsigned 32-bit class and object IDs. Use row_stride to locate each row.
Camera backends
The standalone SDK raycasts collision geometry. Full-scene Metal camera capture is provided by Editor and Spatial Bench.

Link the C ABI

CMakeLists.txt
cmake_minimum_required(VERSION 3.24)
project(SpatialExample LANGUAGES C)
find_package(CrescentSpatial CONFIG REQUIRED)
add_executable(spatial_example main.c)
target_link_libraries(spatial_example PRIVATE Crescent::Spatial)
main.c
#include <Crescent/SpatialRuntime.h>
#include <stdio.h>

int main(void) {
    CESpatialSim sim = ce_spatial_sim_create(NULL, NULL);
    if (!sim) {
        fprintf(stderr, "%s\n", ce_spatial_last_error());
        return 1;
    }
    int status = ce_spatial_sim_reset(sim, 42);
    if (status == 0) status = ce_spatial_sim_step(sim, 4, 0, NULL);
    if (status != 0) fprintf(stderr, "%s\n", ce_spatial_last_error());
    ce_spatial_sim_destroy(sim);
    return status != 0;
}
Terminal
cmake -S . -B build -DCMAKE_PREFIX_PATH="/absolute/path/to/CSDK-Sim"
cmake --build build
./build/spatial_example

For calls with input or output records, initialize their size and version according to CSDK-Sim/include/Crescent/SpatialRuntime.h. Stop stepping after terminal feedback and call reset before the next episode.

API map

OperationPythonC ABI
Create and destroySim, closece_spatial_sim_create, ce_spatial_sim_destroy
Start episoderesetce_spatial_sim_reset
Act and stepimpulse, stepce_spatial_sim_apply_action, ce_spatial_sim_step
Inspect stateentities, feedbackce_spatial_sim_read_entities, ce_spatial_sim_read_feedback
Copy filtered entitiesNative C callce_spatial_sim_query_cell_entities
Configure and read cameraset_camera, camerace_spatial_sim_set_camera, ce_spatial_sim_read_camera
Measure copiestelemetry, camera_telemetryce_spatial_sim_read_telemetry, ce_spatial_sim_read_camera_telemetry
Read errorsSpatialErrorce_spatial_last_error

Typical physics steps use 1/60 s. Use the same build, config, seed and actions for repeatability. The state fingerprint describes observable state; replay and comparison also check terminal feedback.

Choose the right interface

The Spatial SDK exposes fixed-step simulation and its observations to your process. Spatial Bench adds model adapters, task suites, run archives and replay verification. Use Bench when you need reports or repeatable comparisons across controllers.

Use borrowed native views inside the process. Use the socket policy protocol or a model endpoint across process boundaries. Serialization and transfer costs are measured separately from physics and render capture.

For a model adapter, an authored Metal scene and reproducible evaluation across several seeds, follow Spatial Bench workflows.