code nodes
2 node types in the code category.
script#
aliases: python js javascript python_sop
Arbitrary JS over the whole geometry with the engine library (builder, math, noise, BVH, manifold, lib.run any node). Return a Geometry.
The body of async function(geo, inputs, lib). geo is a writable clone of input 0; inputs[i] are the raw inputs. lib: Geometry, GeoBuilder, math, topology, random, noise, KDTree, TriBVH, manifold, merge(geos), run(type, params, ...inputs), warn(msg), frame, time, fps, timeInc (reading them makes the script re-cook per frame). Graph vars by their bare name, read-only, as in "=expr" params (e.g. lib.run('box', { size: height })). Must return a Geometry (e.g. return geo;).
Inputs
| # | name | description |
|---|---|---|
| 0 | geo | main input (optional) (optional) |
| 1 | input1 | extra input (optional) |
| 2 | input2 | extra input (optional) |
| 3 | input3 | extra input (optional) |
Parameters
| name | type | default | range | description |
|---|---|---|---|---|
code | code | "return geo;" | async function body; may use await lib.run(...) |
Example
{
"type": "script",
"params": {
"code": "const parts = [];\nfor (let i = 0; i < 5; i++) parts.push(await lib.run('box', { size: [1, i + 1, 1], center: [i * 1.5, (i + 1) / 2, 0] }));\nreturn lib.merge(parts);"
}
}
wrangle#
aliases: attribwrangle pointwrangle primwrangle vex snippet attribute_wrangle
Run a JS snippet per point / prim / vertex (or once) with VEX-style @attributes. The universal escape hatch.
Code runs once per element with @attr bound to the current element. Read/write any attribute: @P, @N, @Cd, @pscale, @orient... New attributes are created on write (type from prefix f@ i@ v@ p@ u@ s@, a known name, or the first assigned value). Vectors are arrays with .x/.y/.z accessors; use add/sub/mul/div/dot/cross/normalize/length/lerp/fit (no operator overloading). Element numbers: @ptnum @primnum @vtxnum @numpt @numprim @elemnum. Groups: @group_name = 1. Time: @Frame @Time @TimeInc (the wrangle re-cooks per frame only when the code uses them). Read graph vars by bare name or with ch("lift"). Graph vars are read-only. Inputs 1-3 are readable with point(1, "P", i), nearpoint(1, pos), xyzdist(1, pos)… Create/delete with addpoint, addprim, removepoint, removeprim (applied after the run). See help topic "wrangle" for the full function list.
Inputs
| # | name | description |
|---|---|---|
| 0 | geo | geometry to process |
| 1 | input1 | extra input readable as 1 (optional) |
| 2 | input2 | extra input readable as 2 (optional) |
| 3 | input3 | extra input readable as 3 (optional) |
Parameters
| name | type | default | range | description |
|---|---|---|---|---|
code | code | "" | JS statements. Start directly with the code, for example "@P.y += noise(@P) * 0.2; @Cd = [@P.y, 0.5, 1];" aliases: snippet vexpression vex | |
run_over | enum | "points" | element class to iterate options: points prims vertices detailaliases: class runover | |
group | group | "" | only run on elements in this group (point, prim or vertex pattern, matching run_over) |
Example
{
"type": "wrangle",
"params": {
"run_over": "points",
"code": "@P.y += sin(@P.x * 4) * 0.2;\n@Cd = hsv2rgb(fit(@P.y, -0.2, 0.2, 0.6, 0), 0.7, 1);"
}
}
Used in the examples asset_cleanup, blob_creature, cloth_drape, eroded_valley, forest_on_terrain, fracture_settle, growth, guided_town, image_cutouts, lsystem_tree, market_street, ocean_surface, rail_along_curve, scifi_panel, sparks, terrain_tiles, town_from_lots, unreal_landscape, worn_machine.