sdf: distance fields

To use this module, require it in a generator script (see Geometry modules):

require sdf

Signed distance fields: shapes, smooth blends, deforms and noise. solid meshes a Field into a csg Solid. The build time and the triangle count grow fast as the cell gets smaller: set cell on the final field.

Constants

SDF_UNION = 0

The kind of a union node; the module uses it inside.

SDF_SUBTRACT = 1

The kind of a subtraction node; the module uses it inside.

SDF_INTERSECT = 2

The kind of an intersection node; the module uses it inside.

SDF_SMOOTH_UNION = 3

The kind of a smooth union node; the module uses it inside.

SDF_SMOOTH_SUBTRACT = 4

The kind of a smooth subtraction node; the module uses it inside.

SDF_SMOOTH_INTERSECT = 5

The kind of a smooth intersection node; the module uses it inside.

SDF_XOR = 6

The kind of a symmetric difference node; the module uses it inside.

Structures

Field

A signed distance field: negative inside, in meters. solid meshes it into a csg Solid.

Fields:
  • id : int - The index of the expression in the model

Field2

A 2D signed distance field in a (u, v) plane; extrude and revolve make a 3D field of it.

Fields:
  • id : int - The index of the expression in the model

Shapes

sdf_box(size: float3): Field

A box of full sizes size meters, centered at the origin.

Arguments:
  • size : float3

sdf_box(sx: float; sy: float; sz: float): Field

A box of full sizes sx, sy, sz meters, centered at the origin.

Arguments:
  • sx : float

  • sy : float

  • sz : float

sdf_box_frame(size: float3; e: float): Field

The frame of a box: beams of width 2 e along the edges of a box of full sizes size; e under a quarter of the least size.

Arguments:
  • size : float3

  • e : float

sdf_capped_torus(R: float; r: float; angle: float): Field

An arc of a torus: ring radius R, tube radius r below R, half opening angle in degrees (above 0, below 180).

Arguments:
  • R : float

  • r : float

  • angle : float

sdf_capsule(r: float; h: float): Field

A capsule along Y centered at the origin: radius r, full height h with the domes, at least 2 r.

Arguments:
  • r : float

  • h : float

sdf_cone(rBottom: float; rTop: float; h: float): Field

A cone along Y centered at the origin: radii rBottom and rTop (one may be 0), full height h.

Arguments:
  • rBottom : float

  • rTop : float

  • h : float

sdf_cone_ab(a: float3; b: float3; ra: float; rb: float): Field

A capped cone from a (radius ra) to b (radius rb).

Arguments:
  • a : float3

  • b : float3

  • ra : float

  • rb : float

sdf_cone_inf(angle: float): Field

A cone with no end, apex at the origin, opening down, half angle angle degrees (above 0, below 180): intersect it with a bounded part.

Arguments:
  • angle : float

sdf_cut_hollow_sphere(r: float; h: float; t: float): Field

A spherical shell of radius r and half thickness t, cut at y = h; the part below stays.

Arguments:
  • r : float

  • h : float

  • t : float

sdf_cut_sphere(r: float; h: float): Field

The cap of a sphere of radius r above the plane y = h: the part below the plane is removed.

Arguments:
  • r : float

  • h : float

sdf_cylinder(r: float; h: float): Field

A cylinder along Y centered at the origin: radius r, full height h.

Arguments:
  • r : float

  • h : float

sdf_cylinder_ab(a: float3; b: float3; r: float): Field

A capped cylinder of radius r from a to b.

Arguments:
  • a : float3

  • b : float3

  • r : float

sdf_cylinder_inf(r: float): Field

A cylinder of radius r along Y with no ends: intersect it with a bounded part.

Arguments:
  • r : float

sdf_death_star(ra: float; rb: float; d: float): Field

A sphere of radius ra minus a sphere of radius rb at d along X.

Arguments:
  • ra : float

  • rb : float

  • d : float

sdf_ellipsoid(rx: float; ry: float; rz: float): Field

An ellipsoid with the radii rx, ry, rz at the origin; its distance is a lower bound.

Arguments:
  • rx : float

  • ry : float

  • rz : float

sdf_hex_prism(r: float; h: float): Field

A hexagonal prism along Y: apothem r, half height h.

Arguments:
  • r : float

  • h : float

A chain link: tube radius r2 on a ring of radius r1 above r2, with straight sides 2 le long along Z.

Arguments:
  • le : float

  • r1 : float

  • r2 : float

sdf_octahedron(s: float): Field

An octahedron of size s at the origin.

Arguments:
  • s : float

sdf_plane(n: float3; d: float): Field

A half space with no bounds that keeps dot(unit(n), p) <= d: intersect it with a bounded part.

Arguments:
  • n : float3

  • d : float

sdf_pyramid(h: float): Field

A pyramid with a unit square base at y = 0 and the height h.

Arguments:
  • h : float

sdf_quad(a: float3; b: float3; c: float3; d: float3; t: float): Field

A slab of half thickness t around the planar convex quad a, b, c, d, with round edges.

Arguments:
  • a : float3

  • b : float3

  • c : float3

  • d : float3

  • t : float

sdf_rbox(sx: float; sy: float; sz: float; r: float): Field

A box of full sizes sx, sy, sz meters with edges rounded by r, at most half the smallest size.

Arguments:
  • sx : float

  • sy : float

  • sz : float

  • r : float

sdf_rcylinder(r: float; rr: float; h: float): Field

A cylinder along Y: radius r, edges rounded by rr under r and h, half height h.

Arguments:
  • r : float

  • rr : float

  • h : float

sdf_rhombus(la: float; lb: float; h: float; ra: float): Field

A rhombus prism: half diagonals la and lb, half height h, edges rounded by ra.

Arguments:
  • la : float

  • lb : float

  • h : float

  • ra : float

sdf_round_cone(r1: float; r2: float; h: float): Field

A round cone along Y from radius r1 at the origin to radius r2 at the height h; abs(h) must be above abs(r1 - r2).

Arguments:
  • r1 : float

  • r2 : float

  • h : float

sdf_segment(a: float3; b: float3; r: float): Field

A capsule of radius r around the segment from a to b.

Arguments:
  • a : float3

  • b : float3

  • r : float

sdf_solid_angle(angle: float; r: float): Field

A cone of half angle angle degrees (above 0, below 180) cut by a sphere of radius r.

Arguments:
  • angle : float

  • r : float

sdf_sphere(r: float): Field

A sphere of radius r meters at the origin.

Arguments:
  • r : float

sdf_torus(R: float; r: float): Field

A torus around the Y axis at the origin: ring radius R, tube radius r below R.

Arguments:
  • R : float

  • r : float

sdf_tri_prism(r: float; h: float): Field

A triangular prism along Y: triangle scale r, half height h; its distance is a lower bound.

Arguments:
  • r : float

  • h : float

sdf_triangle(a: float3; b: float3; c: float3; t: float): Field

A slab of half thickness t around the triangle a, b, c, with round edges.

Arguments:
  • a : float3

  • b : float3

  • c : float3

  • t : float

sdf_tube(path: array<float3>; radii: array<float>): Field

Round cones between the path points, 2 to 65536, with a radius at each point; each segment must be longer than its radius change.

Arguments:
  • path : array<float3>

  • radii : array<float>

sdf_vesica(a: float3; b: float3; w: float): Field

A revolved vesica (a lens) from a to b with half width w below half the distance from a to b.

Arguments:
  • a : float3

  • b : float3

  • w : float

2D shapes

sdf2_arc(angle: float; ra: float; rb: float): Field2

A 2D arc of radius ra and half opening angle degrees (above 0, below 180), of half thickness rb below ra.

Arguments:
  • angle : float

  • ra : float

  • rb : float

sdf2_bezier(A: float2; B: float2; C: float2; r: float): Field2

A 2D capsule of radius r around the quadratic Bezier curve A, B, C.

Arguments:
  • A : float2

  • B : float2

  • C : float2

  • r : float

sdf2_blobby_cross(h: float): Field2

A 2D blobby cross; h, at most 1 / (2 sqrt 2) and not within 2^-20 of 0, sets its shape.

Arguments:
  • h : float

sdf2_box(w: float; h: float): Field2

A 2D box of the sizes w and h.

Arguments:
  • w : float

  • h : float

sdf2_chamfer_box(w: float; h: float; c: float): Field2

A 2D box of the sizes w and h with chamfered corners of size c under half the least size.

Arguments:
  • w : float

  • h : float

  • c : float

sdf2_circle(r: float): Field2

A 2D circle of radius r.

Arguments:
  • r : float

sdf2_circle_wave(tb: float; ra: float; r: float): Field2

A 2D wave of thickness 2 r along u, with no bounds: intersect it with a bounded part. tb (2^-100 to 1) sets the wave shape, ra its radius.

Arguments:
  • tb : float

  • ra : float

  • r : float

sdf2_cool_s(): Field2

The 2D ‘cool S’ of unit size.

sdf2_cross(w: float; h: float; r: float): Field2

A 2D plus sign of two bars of w by h meters, the longer side along the bar; r above 0 moves the outline in by r and rounds the inner corners, below 0 moves it out and rounds the outer corners.

Arguments:
  • w : float

  • h : float

  • r : float

sdf2_cut_disk(r: float; h: float): Field2

The 2D segment of a disk of radius r above v = h.

Arguments:
  • r : float

  • h : float

sdf2_egg(ra: float; rb: float): Field2

A 2D egg: the radius ra at the bottom, about the origin, and the tip rounded by rb, 0 (a sharp tip) or more and below ra.

Arguments:
  • ra : float

  • rb : float

sdf2_ellipse(a: float; b: float): Field2

A 2D ellipse with the half axes a and b.

Arguments:
  • a : float

  • b : float

sdf2_heart(): Field2

A 2D heart of unit size.

sdf2_hexagon(r: float): Field2

A 2D regular hexagon with the apothem r.

Arguments:
  • r : float

sdf2_hexagram(r: float): Field2

A 2D six-pointed star with the tips at 2 r.

Arguments:
  • r : float

sdf2_horseshoe(angle: float; r: float; w1: float; w2: float): Field2

A 2D horseshoe: radius r, half opening angle degrees (above 0, below 180), legs of length w1 and half thickness w2.

Arguments:
  • angle : float

  • r : float

  • w1 : float

  • w2 : float

sdf2_hyperbola(k: float; he: float): Field2

The 2D region beyond each branch of the hyperbola u^2 - v^2 = 2 k (k from 2^-200 to 2^200), cut at abs(v) = he, with no bounds: intersect it with a bounded part.

Arguments:
  • k : float

  • he : float

sdf2_moon(d: float; ra: float; rb: float): Field2

A 2D moon: a disk of radius ra minus a disk of radius rb at d.

Arguments:
  • d : float

  • ra : float

  • rb : float

sdf2_obox(a: float2; b: float2; th: float): Field2

A 2D oriented box from a to b of thickness th.

Arguments:
  • a : float2

  • b : float2

  • th : float

sdf2_octagon(r: float): Field2

A 2D regular octagon with the apothem r.

Arguments:
  • r : float

sdf2_ovesica(a: float2; b: float2; w: float): Field2

A 2D vesica from a to b with half width w below half the distance from a to b.

Arguments:
  • a : float2

  • b : float2

  • w : float

sdf2_parabola(k: float): Field2

The 2D region above the parabola v = k u^2 (k from 2^-200 to 2^200), with no bounds: intersect it with a bounded part.

Arguments:
  • k : float

sdf2_parabola_segment(w: float; h: float): Field2

The 2D region under a parabola arch through (+-w, 0) with the apex at h.

Arguments:
  • w : float

  • h : float

sdf2_parallelogram(wi: float; he: float; sk: float): Field2

A 2D parallelogram: half width wi, half height he, skew sk.

Arguments:
  • wi : float

  • he : float

  • sk : float

sdf2_pentagon(r: float): Field2

A 2D regular pentagon with the apothem r.

Arguments:
  • r : float

sdf2_pie(angle: float; r: float): Field2

A 2D circle sector of radius r with the half opening angle degrees (above 0, below 180).

Arguments:
  • angle : float

  • r : float

sdf2_polygon(points: array<float2>): Field2

A 2D simple polygon of 3 to 65536 points.

Arguments:
  • points : array<float2>

sdf2_qcircle(): Field2

A 2D closed curve of four parabola arcs through (+-1, 0) and (0, +-1), close to the unit circle.

sdf2_rbox(w: float; h: float; r0: float; r1: float; r2: float; r3: float): Field2

A 2D box of the sizes w and h with a radius per corner: r0 +u+v, r1 +u-v, r2 -u+v, r3 -u-v.

Arguments:
  • w : float

  • h : float

  • r0 : float

  • r1 : float

  • r2 : float

  • r3 : float

sdf2_rcross(h: float): Field2

A 2D cross with the tips at (+-1, 0) and (0, +-h), its sides concave circular arcs.

Arguments:
  • h : float

sdf2_rhombus(w: float; h: float): Field2

A 2D rhombus with the diagonals w and h.

Arguments:
  • w : float

  • h : float

sdf2_ring(angle: float; r: float; th: float): Field2

A 2D cut ring of radius r and thickness th with the half opening angle degrees (above 0, below 180).

Arguments:
  • angle : float

  • r : float

  • th : float

sdf2_rx(w: float; r: float): Field2

A 2D X of two round bars of radius r along the diagonals, their ends at u, v = +-w / 2.

Arguments:
  • w : float

  • r : float

sdf2_segment(a: float2; b: float2; r: float): Field2

A 2D capsule of radius r around the segment from a to b.

Arguments:
  • a : float2

  • b : float2

  • r : float

sdf2_stairs(w: float; h: float; n: int): Field2

2D stairs of n steps of width w and height h from the origin.

Arguments:
  • w : float

  • h : float

  • n : int

sdf2_star(r: float; n: int; m: float): Field2

A 2D star of n points (3 to 64): outer radius r, m from 2 to below n sets the depth (2 gives an n-gon).

Arguments:
  • r : float

  • n : int

  • m : float

sdf2_star5(r: float; rf: float): Field2

A 2D five-pointed star: outer radius r, inner ratio rf.

Arguments:
  • r : float

  • rf : float

sdf2_trapezoid(r1: float; r2: float; he: float): Field2

A 2D trapezoid: half widths r1 at v = -he and r2 at v = he.

Arguments:
  • r1 : float

  • r2 : float

  • he : float

sdf2_triangle(a: float2; b: float2; c: float2): Field2

A 2D triangle of three points.

Arguments:
  • a : float2

  • b : float2

  • c : float2

sdf2_triangle_eq(r: float): Field2

A 2D equilateral triangle; r is half the side.

Arguments:
  • r : float

sdf2_triangle_iso(w: float; h: float): Field2

A 2D isosceles triangle: apex at the origin, base of half width w at v = -h.

Arguments:
  • w : float

  • h : float

sdf2_tunnel(w: float; h: float): Field2

A 2D tunnel arch of half width w and wall height h, base at v = -h.

Arguments:
  • w : float

  • h : float

sdf2_uneven_capsule(r1: float; r2: float; h: float): Field2

A 2D capsule between a circle of radius r1 at the origin and one of radius r2 at v = h.

Arguments:
  • r1 : float

  • r2 : float

  • h : float

sdf2_vesica(r: float; d: float): Field2

A 2D vesica: two circles of radius r at +-d, intersected.

Arguments:
  • r : float

  • d : float

2D to 3D

extrude(f: Field2; h: float): Field

The 2D field in the XZ plane extruded along Y to +-h meters.

Arguments:
revolve(f: Field2; o: float): Field

The 2D field revolved around the Y axis at the offset o meters; the profile must have bounds and lie at u >= -o.

Arguments:

Booleans and blends

Field&(a: Field; b: Field): Field

The intersection of two fields.

Arguments:
Field&=(a: Field; b: Field)

Sets a to the intersection of a and b.

Arguments:
Field-(a: Field; b: Field): Field

The field a minus the field b.

Arguments:
Field-=(a: Field; b: Field)

Subtracts b from a in place.

Arguments:
Field2&(a: Field2; b: Field2): Field2

The intersection of two fields.

Arguments:
Field2&=(a: Field2; b: Field2)

Sets a to the intersection of a and b.

Arguments:
Field2-(a: Field2; b: Field2): Field2

The field a minus the field b.

Arguments:
Field2-=(a: Field2; b: Field2)

Subtracts b from a in place.

Arguments:
Field2|(a: Field2; b: Field2): Field2

The union of two fields.

Arguments:
Field2|=(a: Field2; b: Field2)

Sets a to the union of a and b.

Arguments:
Field|(a: Field; b: Field): Field

The union of two fields.

Arguments:
Field|=(a: Field; b: Field)

Sets a to the union of a and b.

Arguments:
offset(a: Field2; d: float): Field2

Moves the surface of the 2D field out by d meters, or in for a negative d.

Arguments:
offset(a: Field; d: float): Field

Moves the surface of the field out by d meters, or in for a negative d.

Arguments:
onion(a: Field2; t: float): Field2

A band of thickness 2 t around the outline of the 2D field.

Arguments:
round(a: Field2; r: float): Field2

Grows the 2D field by r meters, which rounds its convex edges.

Arguments:
round(a: Field; r: float): Field

Grows the field by r meters, which rounds its convex edges.

Arguments:
shell(a: Field; t: float): Field

A skin of thickness 2 t meters around the surface of the field.

Arguments:
smooth_intersect(a: Field2; b: Field2; k: float): Field2

The intersection of two fields, blended over a radius k meters above 0.

Arguments:
smooth_intersect(a: Field; b: Field; k: float): Field

The intersection of two fields, blended over a radius k meters above 0.

Arguments:
smooth_subtract(a: Field2; b: Field2; k: float): Field2

The field a minus b, blended over a radius k meters above 0.

Arguments:
smooth_subtract(a: Field; b: Field; k: float): Field

The field a minus b, blended over a radius k meters above 0.

Arguments:
smooth_union(a: Field2; b: Field2; k: float): Field2

The union of two fields, blended over a radius k meters above 0.

Arguments:
smooth_union(a: Field; b: Field; k: float): Field

The union of two fields, blended over a radius k meters above 0.

Arguments:
xor(a: Field; b: Field): Field

The symmetric difference of two fields: the volume inside one of them only.

Arguments:

Transforms and repeats

at(a: Field2; x: float; y: float): Field2

Moves the 2D field by (x, y) meters.

Arguments:
  • a : Field2

  • x : float

  • y : float

at(a: Field; p: float3): Field

Moves the field by p meters.

Arguments:
at(a: Field; x: float; y: float; z: float): Field

Moves the field by (x, y, z) meters.

Arguments:
  • a : Field

  • x : float

  • y : float

  • z : float

elongate(a: Field2; hx: float; hy: float): Field2

Cuts the 2D field at the lines u = 0 and v = 0 and moves the pieces out by hx and hy meters, so its size grows by twice these; the gaps repeat the section at each line.

Arguments:
  • a : Field2

  • hx : float

  • hy : float

elongate(a: Field; hx: float; hy: float; hz: float): Field

Cuts the field at the planes x = 0, y = 0 and z = 0 and moves the pieces out by hx, hy and hz meters, so its size grows by twice these; the gaps repeat the section at each plane.

Arguments:
  • a : Field

  • hx : float

  • hy : float

  • hz : float

frame(a: Field; x: float3; y: float3; z: float3; at: float3): Field

Places the field in a frame: the axes x, y, z and the origin at; exact when the frame is rigid.

Arguments:
  • a : Field

  • x : float3

  • y : float3

  • z : float3

  • at : float3

metric(a: Field; n: int): Field

Measures the distance of a sphere, rbox, torus or capsule field, straight from its sdf_* call, with the n-norm (6 or 8): a squarer shape.

Arguments:
mirror_x(a: Field): Field

The mirror image of the field across the plane x = 0.

Arguments:
mirror_x(a: Field2): Field2

The mirror image of the 2D field across the line u = 0.

Arguments:
mirror_y(a: Field): Field

The mirror image of the field across the plane y = 0.

Arguments:
mirror_y(a: Field2): Field2

The mirror image of the 2D field across the line v = 0.

Arguments:
mirror_z(a: Field): Field

The mirror image of the field across the plane z = 0.

Arguments:
repeat(a: Field2; count: int2; step: float2): Field2

Copies of the 2D field at 0, step, 2 step and on, count copies per axis; each step component above 0, also where the count is 1.

Arguments:
  • a : Field2

  • count : int2

  • step : float2

repeat(a: Field; count: int3; step: float3): Field

Copies of the field at 0, step, 2 step and on, count copies per axis; each step component above 0, also where the count is 1.

Arguments:
  • a : Field

  • count : int3

  • step : float3

repeat_inf(a: Field; step: float3): Field

Copies of the field every step meters with no end; the result has no bounds: intersect it with a bounded part, or give it bounds that cut no copy.

Arguments:
  • a : Field

  • step : float3

repeat_var(a: Field; count: int3; step: float3; seed: int; jitter: float; yawDeg: float): Field

Copies of the field as repeat gives them, each moved by up to jitter per axis and turned about Y by up to yawDeg degrees.

Arguments:
  • a : Field - the field

  • count : int3 - the copies per axis, 65536 at most in total

  • step : float3 - the distance between copies per axis, in meters, from 2^-100 to 2^100 on every axis

  • seed : int - the seed of the random moves

  • jitter : float - the largest move per axis in meters

  • yawDeg : float - the largest turn about Y in degrees, 0 to 180

rot(a: Field2; deg: float): Field2

Rotates the 2D field about the origin by deg degrees, from +u toward +v.

Arguments:
rot(a: Field; axis: float3; deg: float): Field

Rotates the field about an axis through the origin by deg degrees, by the right-hand rule.

Arguments:
  • a : Field

  • axis : float3

  • deg : float

rot_x(a: Field; deg: float): Field

Rotates the field about the X axis by deg degrees: rot_x(90.0) turns +Y to +Z.

Arguments:
rot_y(a: Field; deg: float): Field

Rotates the field about the Y axis by deg degrees: rot_y(90.0) turns +Z to +X.

Arguments:
rot_z(a: Field; deg: float): Field

Rotates the field about the Z axis by deg degrees: rot_z(90.0) turns +X to +Y.

Arguments:
scale(a: Field2; s: float): Field2

Scales the 2D field about the origin by s.

Arguments:
scale(a: Field; s: float): Field

Scales the field about the origin by s.

Arguments:
scale(a: Field; sx: float; sy: float; sz: float): Field

Scales the field about the origin, a factor per axis; a negative factor mirrors.

Arguments:
  • a : Field

  • sx : float

  • sy : float

  • sz : float

sym_x(a: Field): Field

Keeps the +x side of the field and mirrors it to the -x side.

Arguments:
sym_x(a: Field2): Field2

Keeps the +u side of the 2D field and mirrors it to the -u side.

Arguments:
sym_y(a: Field): Field

Keeps the +y side of the field and mirrors it to the -y side.

Arguments:
sym_y(a: Field2): Field2

Keeps the +v side of the 2D field and mirrors it to the -v side.

Arguments:
sym_z(a: Field): Field

Keeps the +z side of the field and mirrors it to the -z side.

Arguments:

Deforms and noise

bend(a: Field; degPerM: float): Field

Bends the field about the Z axis along X by degPerM degrees per meter; abs(degPerM) * pi / 180 times the distance from the Z axis to the far xy corner of the part’s box must stay under 1 - 2^-10.

Arguments:
  • a : Field

  • degPerM : float

cellular(a: Field; seed: int; amp: float; freq: float; rad: float = 1f; walls: bool = false): Field

Adds cell pits of depth amp meters, one per 1 / freq meters.

Arguments:
  • a : Field - the field

  • seed : int - the seed of the cells

  • amp : float - the depth of the pits in meters

  • freq : float - the cells per meter

  • rad : float - the reach of a pit in cells, above 0 and at most 1; 0.3 gives scattered pits

  • walls : bool - true makes plates with crests between the cells

displace(a: Field; g: Field; amp: float): Field

Adds amp times the field g, clamped to +-1, to the field a.

Arguments:
fbm(a: Field; seed: int; amp: float; freq: float; octaves: int; gain: float): Field

Adds octaves octaves (1 to 8) of gradient noise; octave o has the amplitude amp * gain``^o and the frequency ``freq * 1.99^o, with gain above 0 and below 1.

Arguments:
  • a : Field

  • seed : int

  • amp : float

  • freq : float

  • octaves : int

  • gain : float

noise(a: Field; seed: int; amp: float; freq: float): Field

Adds gradient noise within +-amp meters to the field, with the frequency freq per meter.

Arguments:
  • a : Field

  • seed : int

  • amp : float

  • freq : float

ridged(a: Field; seed: int; amp: float; freq: float): Field

Adds ridged noise to the field: crests where the noise is 0, amp meters high (a negative amp makes grooves).

Arguments:
  • a : Field

  • seed : int

  • amp : float

  • freq : float

ridged(a: Field; seed: int; amp: float; freq: float; octaves: int; gain: float): Field

Adds octaves octaves (1 to 8) of ridged noise; octave o has the amplitude amp * gain``^o and the frequency ``freq * 1.99^o, with gain above 0 and below 1.

Arguments:
  • a : Field

  • seed : int

  • amp : float

  • freq : float

  • octaves : int

  • gain : float

taper(a: Field; k: float): Field

Scales the section of the field at the height y by 1 + k y, which must stay above 2^-10 over the part’s box.

Arguments:
twist(a: Field; degPerM: float): Field

Twists the field about the Y axis by degPerM degrees per meter of height.

Arguments:
  • a : Field

  • degPerM : float

warp(a: Field; seed: int; amp: float; freq: float): Field

Moves each point of the field by gradient noise, up to amp meters per axis, with the frequency freq per meter. amp * freq stays under 0.0489, else the generation fails with the warp folds.

Arguments:
  • a : Field

  • seed : int

  • amp : float

  • freq : float

Attributes

color(a: Field; c: uint): Field

Sets the color of the field from 0xRRGGBB.

Arguments:
mat(a: Field; id: int): Field

Sets the material id of the field, 0 to 65535.

Arguments:
rgb(a: Field; r: float; g: float; b: float): Field

Sets the color of the field, linear RGB from 0 to 1; where parts join, the color of the nearer part wins.

Arguments:
  • a : Field

  • r : float

  • g : float

  • b : float

rgb_by(a: Field; g: Field; lo: float; hi: float; c0: float3; c1: float3): Field

Colors the field by the value of the field g: c0 at lo to c1 at hi (above lo); with no c0, from the color under it.

Arguments:
  • a : Field

  • g : Field

  • lo : float

  • hi : float

  • c0 : float3

  • c1 : float3

rgb_by(a: Field; g: Field; lo: float; hi: float; c0: uint; c1: uint): Field

Colors the field by the value of the field g: c0 at lo to c1 at hi (above lo); with no c0, from the color under it.

Arguments:
  • a : Field

  • g : Field

  • lo : float

  • hi : float

  • c0 : uint

  • c1 : uint

rgb_by(a: Field; g: Field; lo: float; hi: float; c1: float3): Field

Colors the field by the value of the field g: c0 at lo to c1 at hi (above lo); with no c0, from the color under it.

Arguments:
  • a : Field

  • g : Field

  • lo : float

  • hi : float

  • c1 : float3

rgb_by(a: Field; g: Field; lo: float; hi: float; c1: uint): Field

Colors the field by the value of the field g: c0 at lo to c1 at hi (above lo); with no c0, from the color under it.

Arguments:
  • a : Field

  • g : Field

  • lo : float

  • hi : float

  • c1 : uint

rgb_by_height(a: Field; lo: float; hi: float; c0: float3; c1: float3): Field

Colors the field by height: c0 at the height lo to c1 at hi (above lo); with no c0, from the color under it.

Arguments:
  • a : Field

  • lo : float

  • hi : float

  • c0 : float3

  • c1 : float3

rgb_by_height(a: Field; lo: float; hi: float; c0: uint; c1: uint): Field

Colors the field by height: c0 at the height lo to c1 at hi (above lo); with no c0, from the color under it.

Arguments:
  • a : Field

  • lo : float

  • hi : float

  • c0 : uint

  • c1 : uint

rgb_by_height(a: Field; lo: float; hi: float; c1: float3): Field

Colors the field by height: c0 at the height lo to c1 at hi (above lo); with no c0, from the color under it.

Arguments:
  • a : Field

  • lo : float

  • hi : float

  • c1 : float3

rgb_by_height(a: Field; lo: float; hi: float; c1: uint): Field

Colors the field by height: c0 at the height lo to c1 at hi (above lo); with no c0, from the color under it.

Arguments:
  • a : Field

  • lo : float

  • hi : float

  • c1 : uint

rgb_by_slope(a: Field; lo: float; hi: float; c0: float3; c1: float3): Field

Colors the field by slope, the y of the normal (1 on top, 0 on a wall): c0 at lo to c1 at hi (above lo); with no c0, from the color under it.

Arguments:
  • a : Field

  • lo : float

  • hi : float

  • c0 : float3

  • c1 : float3

rgb_by_slope(a: Field; lo: float; hi: float; c0: uint; c1: uint): Field

Colors the field by slope, the y of the normal (1 on top, 0 on a wall): c0 at lo to c1 at hi (above lo); with no c0, from the color under it.

Arguments:
  • a : Field

  • lo : float

  • hi : float

  • c0 : uint

  • c1 : uint

rgb_by_slope(a: Field; lo: float; hi: float; c1: float3): Field

Colors the field by slope, the y of the normal (1 on top, 0 on a wall): c0 at lo to c1 at hi (above lo); with no c0, from the color under it.

Arguments:
  • a : Field

  • lo : float

  • hi : float

  • c1 : float3

rgb_by_slope(a: Field; lo: float; hi: float; c1: uint): Field

Colors the field by slope, the y of the normal (1 on top, 0 on a wall): c0 at lo to c1 at hi (above lo); with no c0, from the color under it.

Arguments:
  • a : Field

  • lo : float

  • hi : float

  • c1 : uint

Meshing

bounds(a: Field; lo: float3; hi: float3): Field

Gives the field the box from lo to hi that a field with no bounds needs; it does not cut the field, so the surface must stay inside it.

Arguments:
  • a : Field

  • lo : float3

  • hi : float3

cell(a: Field; h: float): Field

Sets the cell size of the mesh of the final field in meters at quality 1; the mesher takes the largest power of two at or below it. Smaller cells keep finer detail and take more time and triangles.

Arguments:
error(a: Field; e: float): Field

Sets the distance e in meters that faces may move when they merge in the mesh of the final field; a face that stays merged moves up to 2 e.

Arguments:
name(a: Field; text: string): Field

Gives the field a name for the error messages; returns the same field.

Arguments:
  • a : Field

  • text : string

sdf_distance(f: Field; p: float3): float

The value of the field at the point p (negative inside), computed at once.

Arguments:
solid(f: Field): Solid

Meshes the field into a closed csg Solid, sharp edges kept.

Arguments: