Enzo
Loading...
Searching...
No Matches
enzo::script::PointScript Class Reference

A compiled script that runs once per point and edits the point's attributes. More...

#include <PointScript.h>

Public Member Functions

const std::vector< AttributeBinding > & getBindings () const
 Returns every attribute the code binds, in the order they first appear.
 
std::shared_ptr< PointScript > clone () const
 Returns a copy that runs in its own context.
 
bool addWrittenAttributes (geo::Primitive &output, String &error) const
 Adds every attribute the script writes to the output, filled with the default value.
 
bool run (const ScriptContext &context, size_t primitiveIndex, geo::Primitive &output, Offset begin, Offset end, String &error)
 Runs the script on the points in an offset range.
 

Static Public Member Functions

static std::shared_ptr< PointScript > compile (const String &code, String &error)
 Returns the compiled script for the user's code.
 

Detailed Description

A compiled script that runs once per point and edits the point's attributes.

The user's code is the body of a function that reads and writes the point's attributes as @name. curPt() returns the point's index among the live points and ptCount() returns how many live points there are. Functions like pointAttr() read any element of the input by index.

@Position.y += sin(@Position.x) * prm("amplitude")
i@id = curPt()
@height = pointAttr("height", curPt() + 1l)
Note
Each thread runs its own clone over its own range of points.

Member Function Documentation

◆ addWrittenAttributes()

bool enzo::script::PointScript::addWrittenAttributes ( geo::Primitive & output,
String & error ) const

Adds every attribute the script writes to the output, filled with the default value.

Returns
False when the output cannot hold one of them.

◆ clone()

std::shared_ptr< PointScript > enzo::script::PointScript::clone ( ) const

Returns a copy that runs in its own context.

Returns
The copy, or null when its globals fail to initialise.

◆ compile()

std::shared_ptr< PointScript > enzo::script::PointScript::compile ( const String & code,
String & error )
static

Returns the compiled script for the user's code.

Returns
The compiled script, or null when the code fails to compile.

◆ run()

bool enzo::script::PointScript::run ( const ScriptContext & context,
size_t primitiveIndex,
geo::Primitive & output,
Offset begin,
Offset end,
String & error )

Runs the script on the points in an offset range.

Reads bindings from the context's input mesh at primitiveIndex and stores written ones to the output.

Returns
False when the script fails on a point.
Note
The output needs the written attributes added first.

The documentation for this class was generated from the following files: