跳转到内容
查看源码

场景语法自动生成

.esn 场景中的节点、绑定、输入、包,以及 domain = 可以调用的函数。

名称 类别 写法
async graph async = true;
fill graph node zeros: Rows<Float> { domain = 65; value = 0.5; }
font graph node g: font "fonts/x.ttf" { codes <- wanted.result; }
graph graph node name: graph "other.esn" { source <- src; param = 2; }
inline graph node name: kernel { ... input x: Image <- src; ... }
node graph node name: fx.glow@1 { port <- source.result; param = 2; domain = vec2(w, h); }
package document package name@1 { language = 1; ir = 1; }
previous graph port <~ node.output from initial [migrate id@v];
qualified document let n = random::fbm2(p); let m = ui_panel::Mark { b: 1 }; input marks: Rows<ui_panel::Mark>;
require graph require cells: columns * rows <= 1 << bits;
times graph times = 5; carry port <- output;
use document use "kernels/"; use "name.entpkg";
ceil domain ceil(x)
count domain count(port)
floor domain floor(x)
max domain max(a, b)
min domain min(a, b)
scale domain scale()
size domain size(port)
value domain value(port) value(port, i)
vec2 domain vec2(w, h)
vec3 domain vec3(w, h, d)
window domain window()
async = true;

The node runs off the frame: the evaluation starts it on a thread and goes on, its readers taking the last output until the run lands.


node zeros: Rows<Float> { domain = 65; value = 0.5; }

A node that is a Field rather than a Kernel: its element’s zero, or the value given, over the domain. Its element is a Float, Int, Bool, Vec2, Vec3 or Vec4 (a pixel for Image), or an alias of one; a struct is filled by a Kernel.


node g: font "fonts/x.ttf" { codes <- wanted.result; }

A font file’s glyphs as the Host reads them, for the characters codes (a Rows<Int> of code points) held when last evaluated, so a frame later: g.glyphs a row a code in order (code: Int; advance: Int; first: Int; count: Int; lo: Vec2; hi: Vec2, the advance in the font’s units, the box in ems; a code the font lacks -1), g.outlines their outlines’ line segments in ems, y up (Rows<Vec4>), g.metrics one row (units: Int; ascent: Float; descent: Float; gap: Float). Read again when codes or the file changes.


node name: graph "other.esn" { source <- src; param = 2; }

Another document placed as a node: its nodes join under name., its inputs take the wiring, its outputs are read as name.output.


node name: kernel { ... input x: Image <- src; ... }

A Kernel written in place; its inputs carry their wiring, <- or <~ with its initial source (input s: Rows<Float> <~ name.result from start.result;), a param whose default names a scene param follows that param (param gain: Float = amount;), and the session publishes it under the document’s name.


node name: fx.glow@1 { port <- source.result; param = 2; domain = vec2(w, h); }

A node runs a Kernel: its inputs wired at the consumer, its parameters set, its extent explicit or the first input’s.


package name@1 { language = 1; ir = 1; }

The manifest of a package directory: what it is called and the least language and IR it needs.


port <~ node.output from initial [migrate id@v];

State: the port reads what the last evaluation committed, the initial source before the first, and a migration carries it when a republished Kernel changes its layout; the Kernels reading the port are republished for the new layout with it.


let n = random::fbm2(p); let m = ui_panel::Mark { b: 1 }; input marks: Rows<ui_panel::Mark>;

A name a used package declares, written with the package’s name before it: the one declaration of that name in that package. Two packages a document uses may declare one name; the document names each by its package. A name declared or bound here is a plain word.


require cells: columns * rows <= 1 << bits;

What the scene’s parameters must hold to run: two counts over its params, numbers, window() and scale(), compared. It is checked as the scene loads (check and compose refuse one the given params break) and before every evaluation, which stops before anything runs; each says what the sides came to. A placed graph’s come with it, under its node’s name.


times = 5; carry port <- output;

A node written once and placed N times, each wired as written, carry feeding a port from the previous time’s output; at N = 0, a carried output is what its port is first bound to.


use "kernels/"; use "name.entpkg";

The documents whose Kernels and declarations this one brings in: a file, a directory, or a package; what those use in turn is theirs.


ceil(x)

A measure made whole, rounding up.

示例

domain = ceil(size(map) / 2);

count(port)

How many elements an input port of this node holds.

示例

domain = count(faces) * 4;

floor(x)

A measure made whole, rounding down.

示例

domain = floor(window() / 2);

max(a, b)

The larger, componentwise.

示例

domain = max(count(items), 1);

min(a, b)

The smaller, componentwise.

示例

domain = min(count(items), 64);

scale()

The window’s pixels per logical pixel.

示例

domain = window() / scale();

size(port)

An input port’s extent: a count, a pair or a triple.

示例

domain = size(map) * vec2(2, 1);

value(port) value(port, i)

A number a Kernel wrote: element i (0 when not given) of an input port of this node, read as the node binds.

示例

domain = value(count) * 3;

vec2(w, h)

A grid’s extent.

示例

domain = vec2(160, 120);

vec3(w, h, d)

A volume’s extent.

示例

domain = vec3(32, 32, 32);

window()

The window’s size in pixels; the node runs again at the new extent when it changes.

示例

domain = window();