shapeField
The signed-distance function of the shape a swarm lives in, for force.containment.
shapeField: { analyticExtruded, svgExtruded, analytic3d, svgLifted3d }
Import sim from shaders/std and use sim.shapeFields.shapeField.
Four builders, one per shape source. Each returns a ShapeField3: a GPU function from a shape-local 3D point to a signed distance, negative inside. analyticExtruded takes a flat shape (circle, polygon, star…) and gives it a depth from params.halfDepth. svgExtruded does the same for an SVG outline uploaded as a distance texture. analytic3d wraps a true 3D solid so it rotates under the swarm. svgLifted3d wraps an SVG lifted into 3D.
Example
force.containment(simLayout, {field: shapeField.analyticExtruded(simLayout, buildAnalyticSdfFn(shapeType)), gradEps: 0.02, wall: {featherFrom: -0.1, featherTo: 0.01, base: 1.1, springK: 22}, recall: {from: 1.5, to: 1.9, k: 9}, homing: {from: 0.12, to: 0.45, k: 5}, entrainment: {featherHalf: 0.05}})
Tip. Pick the builder at bake time from the shape props and hand ONE field to the integrator. The swarm never needs to know which kind it is.
Members
shapeField.analyticExtruded— A flat shape given depth: the 2D distance of a circle, polygon or star, extruded in z byparams.halfDepth.shapeField.svgExtruded— An SVG outline given depth: the outline's distance texture, extruded in z byparams.halfDepth.shapeField.analytic3d— A true 3D solid (sphere, torus, knot…) from its baked distance function, rotated by the shape's live rotation so the swarm follows the surface as it turns.shapeField.svgLifted3d— An SVG outline lifted into a 3D solid, rotated by the shape's live rotation.
See also
force— The pushes an agent can feel.integrator— The update step of an agent simulation: one per kind of agent.