Generated from the source docstrings by docs/gen_api.py (jolt docs); do
not edit by hand. Guides: getting started,
building scenes, game logic,
releasing, architecture,
troubleshooting.
Functions that touch Blender or the game (bpy, bridge, nodes, game,
bge, audio) marshal onto the host thread themselves, so they can be
called from any nREPL session and from game frame handlers alike.
Namespaces: upbge-jolt.bpy, upbge-jolt.bridge, upbge-jolt.nodes, upbge-jolt.game, upbge-jolt.bge, upbge-jolt.audio, upbge-jolt.core
The ergonomic REPL surface over upbge-jolt.bridge: keyword access, object lookup by name, transform helpers — the shape of bpy from Clojure. Shapes and names track bpy where the mock's toy surface allows.
(scene)
The root scene pointer.
(objects)
All objects in the scene, as pointer maps.
(name-of obj)
The name property of obj.
(object nm)
Look up an object by name; nil when absent.
(get p k)
Read property k (keyword or string) on p.
(put! p k v)
Write property k on p.
(get-in p ks)
Nested property read: (get-in obj [:data :vertices]) walks pointer properties then reads the final key.
(pos obj)
Location vector of obj.
(move! obj xyz)
Set the world location of obj to xyz.
(translate! obj dxyz)
Add dxyz to the current location.
(add-mesh! name verts faces)
Create a mesh named name from vertex positions (a seq of [x y z]
triples) and faces (a seq of vertex-index seqs); returns the mesh.
(add-object! name data)
Create an object named name carrying data (a mesh pointer, or nil);
returns the object.
(link! obj)
Link obj into the scene's objects collection; returns it.
(unlink! obj)
Unlink obj from the scene's objects collection; returns it.
(add! name verts faces)
Create a mesh object and link it into the scene in one step. Returns the object.
(ops opname) (ops opname props) (ops opname props opts)
Run the named operator (the bpy.ops equivalent), optionally with
properties and an editor area to run in:
(ops "mesh.primitive_cube_add" {:size 2 :location [0 0 1]})
(ops "view3d.view_all" {} {:area "VIEW_3D"}). Returns true.
(data)
bpy.data.
(context)
bpy.context.
(save! path)
Save the open file to path (wm.save_as_mainfile).
(open! path)
Open the .blend file at path (wm.open_mainfile).
(delete! obj)
Remove obj from the file entirely (bpy.data.objects.remove).
(viewport! {:keys [shading camera?] :or {shading "RENDERED"}})
Set every 3D viewport's display, so REPL work is visible as it happens: :shading "RENDERED" (EEVEE: materials, world sky, displacement, lights), "MATERIAL" or "SOLID"; :camera? true looks through the scene camera. Returns the number of viewports changed.
Typed access to the host's RNA-style property surface, over the ujs_* C ABI (native/upbge_shim.h). The bindings resolve from the mock shim dylib (tests) or from the host process (a UPBGE build carrying the real shim).
Pointers cross as flat maps {:owner :type :data} rather than raw addresses so they print, compare, and survive as REPL values. Strings returned by the host are valid only until the next ujs_* call, so every get copies into a jolt string immediately.
(reset-host!)
Test hook: reset the mock host state.
(root)
The root pointer (editor: context scene data / Main; mock: the Scene).
(prop-find p name)
Describe property name on p, or nil when absent.
(props p)
All property descriptors of p.
(get-float-array-n p name)
Read a dynamic-length float array property; returns a vector of doubles.
(set-float-array-n! p name xs)
Write a dynamic-length float array property from a seq of doubles.
(coll-count p name)
Length of collection property name on p.
(coll p name)
Vector of collection name's members on p. Errors when name is not a
collection property. Realized inside (the iterator handle is freed before
returning), so members stay valid independent of later host calls.
(id-new type name)
Create a new ID datablock of type (e.g. "Object", "Mesh"), named
name. Returns the pointer map.
(object-new name data)
Create an Object named name carrying data (a mesh or other obdata
pointer; nil makes an Empty), typed from its data like
bpy.data.objects.new. Use this rather than (id-new "Object" ...), which
makes an Empty that ignores a later data assignment.
(mesh-from-pydata! mesh verts faces)
Build mesh geometry from verts (a seq of [x y z] triples) and faces
(a seq of vertex-index seqs), like bpy's Mesh.from_pydata. Returns the mesh.
(coll-add! coll name member)
Link member into collection name on coll (e.g. the scene's
"objects"). Idempotent.
(coll-remove! coll name member)
Unlink member from collection name on coll. No-op when absent.
(operator! opname)
Run the named operator (the bpy.ops equivalent, e.g.
"mesh.primitive_cube_add") with its default arguments. Returns true when
the operator finished.
(kx-objects)
All KX objects in the running game, as pointer maps. Empty when no game is running.
(kx-object name)
Find a KX object by name; nil when absent.
(kx-name obj)
The name of a KX object.
(kx-position obj)
World position of a KX object, as [x y z].
(kx-move! obj xyz)
Set the world position of a KX object.
(data)
bpy.data: the Main database (materials, meshes, images, objects, ...).
(context)
bpy.context.
(call p fname) (call p fname kwargs)
Call RNA function fname on p with keyword arguments, like bpy:
(call (coll-of (data) "materials") "new" {:name "Teak"}).
Returns the function's result (pointer map, number, string, vector) or nil.
(op! opname) (op! opname props) (op! opname props {:keys [area]})
Run operator opname with keyword properties, optionally in an editor
area: (op! "wm.save_as_mainfile" {:filepath "/tmp/x.blend"})
(op! "view3d.view_all" {} {:area "VIEW_3D"}). Returns true.
(coll-ptr p name)
The function-carrying struct of collection name on p -- the self for
(call ...) on things like bpy.data.materials.new or node_tree.links.new.
(lookup p name k)
Collection item by name or index: (lookup (data) "objects" "Cube"), (lookup mesh "vertices" 0). nil when absent.
(foreach-get p name attr n)
Bulk-read attribute attr across collection name (foreach_get); n is
the total value count (items x attr width). Returns a double-array.
(foreach-set! p name attr xs)
Bulk-write attribute attr across collection name (foreach_set) from a
double-array or seq of numbers, item-major.
(get p name)
Read property name on p. Float/int/bool arrays return vectors, enums
{:value n :idname "..."}, pointers maps or nil, collections their
function struct (for call).
(set! p name v)
Write property name on p. Arrays accept seqs; enums accept identifier
strings/keywords (a set or seq for flag enums) or numbers; pointers a map
or nil.
(kx-running?)
Whether a game is running.
(kx-end-game!)
End the running game.
(kx-vec obj what)
Read a KX vector: :position :scale :linear-velocity :angular-velocity :local-linear-velocity :local-angular-velocity.
(kx-set-vec! obj what xyz)
Write a KX vector (see kx-vec).
(kx-orientation obj)
World orientation as a row-major 3x3 vector of 9 doubles.
(kx-set-orientation! obj m9)
Set world orientation from a row-major 3x3 (9 doubles).
(kx-apply! obj what v & {:keys [at local?]})
Apply :force, :torque or :impulse (at world point at) to obj.
(kx-mass obj)
(kx-set-mass! obj m)
(kx-set-damping! obj linear angular)
(kx-suspend-dynamics! obj suspend?)
(kx-raycast from to ignore)
First physics hit from from to to, skipping ignore (or nil):
{:object kx-obj :point [x y z] :normal [x y z]} or nil on a miss.
(kx-parent obj)
(kx-set-parent! obj parent)
Parent obj to parent (nil removes the parent).
(kx-spawn! name) (kx-spawn! name at lifespan)
Spawn a copy of object name (typically one kept in an excluded/hidden
collection) at at's transform (nil = the original's), living lifespan
seconds (0 = forever).
(kx-remove! obj)
(kx-set-camera! cam)
(kx-set-visible! obj visible? recursive?)
(kx-blender-object obj)
The Blender Object (RNA pointer) a KX object came from: change its lights, materials and other data through get/set!/call while the game runs.
(kx-input k)
Input state for a bge event name ("WKEY", :LEFTSHIFTKEY, "LEFTMOUSE"): #{:active :activated :released} subset.
(kx-mouse)
Mouse position, normalized [x y] in 0..1.
(kx-set-mouse! x y)
Warp the mouse to normalized [x y]; true when the warp took effect (the host ignores it while the game window is not active).
(kx-show-mouse! visible?)
(kx-pointer-lock! lock?)
Lock (hide and grab) or release the pointer for mouse look.
(kx-screenshot! path)
Save the game canvas to path (PNG).
(kx-frame-info)
{:fps average :clock engine-seconds :frame-time last-timestep}.
(kx-canvas-size)
(kx-set-text! obj text)
Set the string a game text object shows.
(kx-add-filter! index type) (kx-add-filter! index type glsl)
Add 2D filter pass index of type (a keyword from filter-types, or
:custom with a GLSL fragment program).
(kx-remove-filter! index)
(kx-filter-uniform! index name v)
Set float uniform name (1-4 components) on filter pass index.
Building node trees (materials, worlds, geometry nodes) from the REPL.
(def mat (nodes/material! "Sea")) (def nt (nodes/tree mat)) (def noise (nodes/node! nt "ShaderNodeTexNoise" {:inputs {"Scale" 4.0}})) (nodes/link! nt noise "Fac" (nodes/find nt "Principled BSDF") "Roughness")
Sockets are named ("Base Color") or indexed (0, 1 — needed for Math
nodes, whose inputs share the name "Value"). Game logic feeds shaders
through object-params! (the object's color, set every frame: wave time,
hull masks, time of day). Setting a Value node (value!) every frame also
works but makes EEVEE regenerate the material each frame, which is costly
for large node trees; use it for values that change rarely.
(material! name)
A new node-based material named name.
(tree owner)
The node tree of a material, world or light.
(find nt name)
The node named name in tree nt, or nil.
(socket node dir k)
Socket k (name or index) of node; dir is :in or :out.
(set-input! node k v)
Set an unlinked input's default value.
(node! nt type) (node! nt type {:keys [name props inputs]})
Add a node of type (e.g. "ShaderNodeMath"). Options: :name, :props
(node properties such as {"operation" "MULTIPLY"}), :inputs (default
values by socket name or index).
(link! nt from out to in)
Link output out of from to input in of to.
(math! nt op & consts)
A Math node doing op ("ADD" "MULTIPLY" "SINE" ...), with constant
inputs given positionally (nil leaves an input for a link).
(value! nt name v)
A Value node named name (a shader parameter game code can drive);
returns its output socket, whose "default_value" is set per frame.
(assign! obj mat)
Put material mat on object obj's first slot (adding a slot if empty).
(object-params! nt)
Four shader parameters read from the rendered object's color property
(RGBA), the cheap way to feed per-frame game state into a material:
returns {:r :g :b :a} output sockets to link from. Drive them from game
code with (b/set! (bge/blender-object obj) "color" [r g b a]). Unlike
setting a Value node every frame, this does not invalidate the compiled
material, so EEVEE does not regenerate it each frame.
Game sessions and per-frame logic, and the game's code stored in the .blend file.
A game's jolt code lives in a Text datablock named "main.clj" inside the
.blend, so saving the scene saves its logic. When a game starts (from the
viewport, the REPL, host/play.sh, or a release), main.clj is evaluated
before the first frame's handlers run. Develop it at the REPL, then store it with
set-main! (or set-main-file!) and save the file.
Handlers registered with on-frame! run every game frame on the host
thread, with the frame's delta time in seconds, and are dropped when the
game ends, so nothing outlives the KX objects it captured. A handler that
throws is removed and its error kept in errors.
(running?)
Whether a game session is in progress (as seen at the last tick).
(on-frame! k f)
Run (f dt) every frame of the current game under k (replacing any handler
with that key). Cleared when the game ends.
(off-frame! k)
(on-start! k f)
Run (f) when each game starts, after main.clj loads. Persists across runs.
(on-stop! k f)
Run (f) after each game ends. KX objects are gone by then; use it to reset jolt-side state.
(errors)
Errors from game handlers and main.clj, oldest first.
(clear-errors!)
(main-text)
The "main.clj" Text datablock, or nil.
(main-source)
The game's stored code, or nil.
(set-main! code)
Store code as the game's main.clj (creating the Text if needed). Save the
.blend to keep it.
(set-main-file! path)
Store the contents of the source file at path as main.clj.
(load-main!)
Evaluate the stored main.clj, if any. Returns the last value.
(start!)
Start the game in the 3D viewport. Returns immediately; the game runs on
the host thread until it ends (Esc, or stop!).
(stop!)
End the running game (as Esc does).
(install!)
Hook the game driver into the host tick (idempotent). The library does this at startup.
The running game engine (KX) surface — the bge equivalent. KX objects
exist only while a game is running and carry runtime state (world
transforms, physics, input). The RNA bridge (upbge-jolt.bpy) sees the
editor-side data; blender-object crosses from a KX object to it, so
lights, materials and node values can be changed while the game runs.
KX object handles are validated on every call: one from a removed object or an earlier game run raises instead of touching freed memory. Per-frame game logic belongs in upbge-jolt.game/on-frame!.
(running?)
Whether a game is running.
(objects)
All KX objects in the running game, as pointer maps.
(object name)
The KX object named name, or nil.
(name obj)
The name of KX object obj.
(position obj)
World position of obj, as [x y z].
(move! obj xyz)
Set the world position of obj.
(orientation obj)
World orientation of obj as a row-major 3x3 (9 doubles).
(orient! obj m9)
Set the world orientation of obj from a row-major 3x3 (9 doubles).
(euler->matrix [x y z])
Row-major 3x3 for XYZ euler angles (radians), Blender's default order.
(rotate-to! obj xyz)
Set the world orientation of obj from XYZ euler angles (radians).
(axis obj ax)
World direction of obj's local axis :x, :y or :z (a column of its
orientation).
(scale obj)
World scale of obj.
(scale! obj xyz)
Set the world scale of obj.
(velocity obj) (velocity obj frame)
Linear velocity (world, or local with :local).
(velocity! obj v) (velocity! obj v frame)
Set linear velocity (world, or local with :local).
(angular-velocity obj) (angular-velocity obj frame)
(angular-velocity! obj v) (angular-velocity! obj v frame)
(force! obj f) (force! obj f frame)
Apply a force this frame (world, or local with :local).
(torque! obj t) (torque! obj t frame)
(impulse! obj impulse at)
Apply an impulse at world point at (e.g. buoyancy at a hull sample).
(mass obj)
(mass! obj m)
(damping! obj linear angular)
(suspend-dynamics! obj)
(restore-dynamics! obj)
(raycast from to) (raycast from to ignore)
First hit from from to to, skipping ignore:
{:object :point :normal} or nil.
(parent obj)
(parent! obj p)
Parent obj to p (it then moves with it); nil unparents.
(spawn! name) (spawn! name at) (spawn! name at lifespan)
Spawn a copy of object name (kept in an excluded collection, or any
object) at at's transform, living lifespan seconds (0 = forever).
(remove! obj)
Remove a KX object at the end of the frame.
(camera! cam)
Make camera cam the active one.
(visible! obj v?) (visible! obj v? recursive?)
(blender-object obj)
The Blender Object behind obj, for RNA access while the game runs.
(key-down? k)
Whether input k (bge event name: "WKEY", :LEFTSHIFTKEY, :LEFTMOUSE)
is held.
(key-pressed? k)
Whether input k went down this frame.
(key-released? k)
Whether input k went up this frame.
(mouse)
Normalized mouse position [x y] (0..1, origin top-left).
(mouse! x y)
Warp the mouse to normalized [x y]. Returns whether the warp took effect:
the host ignores it when the game window is not the active window. The
new position is read back from the next frame on. For mouse look use
mouse-look, which handles both.
(mouse-look-step st pos warped?)
Pure mouse-look transition. st is the previous state (nil at first),
pos this frame's normalized mouse position, warped? whether the warp
to the centre issued after reading it took effect. Returns [st' [dx dy]]:
movement since last frame, measured from where the cursor was last put
(the centre after a warp that took effect, else where it was), so a still
mouse reads zero whether or not the window holds the cursor.
(pointer-lock! lock?)
Lock (hide and grab) or release the pointer. While locked, mouse positions keep moving past the window edges, so differences between frames are pure mouse motion. Released automatically when the game ends.
(mouse-look)
Mouse movement this frame as normalized [dx dy] (x right, y down), for
first-person look. Call once per frame from a game/on-frame! handler. The
first call locks the pointer (pointer-lock!); release it with
(pointer-lock! false) (Esc, menus), and the next call locks it again. A
still mouse always reads [0 0].
(release-mouse-look!)
Release the pointer (show the cursor); mouse-look re-locks on its next call.
(show-mouse! visible?)
(screenshot! path)
Save the game view to path (PNG), written at the end of the frame.
(frame-info)
{:fps :clock :frame-time}.
(canvas-size)
[width height] in pixels.
(text! obj s)
Set the string a game text object shows (HUD labels, instrument readouts; parent text objects to the camera to keep them on screen).
(add-filter! index type) (add-filter! index type glsl)
Add 2D filter pass index (passes run in index order): a built-in type
(:blur :sharpen :grayscale :sepia :invert :sobel :prewitt :laplacian
:dilation :erosion) or :custom with a GLSL fragment program that writes
fragColor from bgl_RenderedTexture and bgl_DepthTexture at
bgl_TexCoord.xy. See docs/game-logic.md.
(remove-filter! index)
(filter-uniform! index name v)
Set a float uniform (1-4 components) on a custom filter pass.
Procedural and file audio on Blender's output device (audaspace).
Sounds are recipes: build them from tones, noise or files, shape them with
filters, and play one to get a handle whose pitch and volume can be driven
every frame (an engine note rising with RPM, water rush growing with
speed). Sounds and handles own native memory; free! them when done.
(def engine (audio/play (audio/lowpass (audio/tone :sawtooth 55) 400 1) {:loop? true})) (audio/pitch! engine 1.8) (audio/stop! engine)
(tone wave freq)
An endless tone: wave is :sine :sawtooth :square or :triangle.
(noise) (noise seconds)
White noise, seconds long (loop it with {:loop? true}).
(file path)
A sound file (wav, ogg, flac, mp3).
(lowpass s freq q)
(highpass s freq q)
(volume s v)
(mix a c)
(free! s)
Release a sound (playing handles keep their own reference).
(play s) (play s {:keys [loop? volume pitch]})
Play s; {:loop? true} loops forever. Returns a handle.
(pitch! h v)
Playback speed factor (1 = original).
(volume! h v)
Gain (1 = original).
(pause! h)
(resume! h)
(stop! h)
Stop and release a playing handle.
The embedded runtime's own machinery: the op queue the host drains from its frame loop (uj_tick), and the nREPL server lifecycle (uj_start_repl / uj_stop_repl). This namespace must be loadable with NO host shim present — it is what jolt_library_init brings up first.
(enqueue! f)
Queue f to run on the host thread at the next tick. Safe from any
thread.
(tick)
Drain the op queue. Runs on the host's calling thread — the only consumer, so peek-then-pop needs no lock (enqueue! is many-producer, tick is one-consumer). Ops enqueued during a tick wait for the next one. After the drain, notifies every frame emitter with the new tick count.
(after-ticks! n f)
Run f on the host thread once n more ticks have run (n >= 1). For host
startup work that needs the window drawn first. A throwing f is reported
like a failed op.
(on-host-thread?)
Whether the current thread is the host's tick/frame thread (inside a tick-drained op).
(marshal f)
Run f on the host's tick thread and return its value, blocking the caller
until it runs. Called from the tick thread itself (reentrantly) it runs
inline. Errors thrown by f are re-thrown on the calling thread.
Contract: the host must be ticking — draining the op queue — for a blocking caller to return. If the host is not ticking, the caller blocks until it resumes (the editor-side WM timer and the game-side frame loop are the two pumps that guarantee this).
(tick-count)
Number of ticks run. Exposed for tests and for repl sessions to poll.
(frame-flow)
An ebb discrete flow emitting the tick count each time tick runs (every
host frame). Each subscription registers an emitter that tick notifies; the
returned cleanup (run by ebb on cancellation) deregisters it. This is the
engine-layer seam: drive per-frame logic from the REPL with
(m/reduce f nil (frame-flow)).
(pending-ops)
Ops currently queued. For tests.
(eval-string s)
Evaluate s and return its printed value, or the printed error. Never
throws.
(start-repl! port) (start-repl! port middleware)
Start the embedded nREPL server. port 0 asks the OS for a free one.
Returns the stop fn from jolt.nrepl/start (its meta carries :port). No
port file is written — embedded mode; the host decides where to surface
the port.
(stop-repl!)
Stop the running nREPL server, if any.
(eval-via-socket port code)
Eval code against the running server as an editor client would — an
nREPL client connect, session, eval, response-values. Test helper.