2#include "Engine/Attribute/AttributeHandle.h"
4#include "Engine/Expression/DasRuntime.h"
16class ExpressionContext;
44 static std::shared_ptr<PointScript>
compile(
const String& code, String& error);
47 const std::vector<AttributeBinding>&
getBindings()
const {
return bindings_; }
51 std::shared_ptr<PointScript>
clone()
const;
76 template <
typename Value>
struct BindingValues
78 std::deque<Value> values;
79 std::vector<std::optional<attr::AttributeHandleRO<Value>>> inputs;
80 std::vector<std::optional<attr::AttributeHandle<Value>>> outputs;
83 void loadFrom(
Offset point)
85 for (
size_t valueIndex = 0; valueIndex < values.size(); ++valueIndex)
87 const auto& input = inputs[valueIndex];
88 values[valueIndex] = input ? input->getValue(point) : Value{};
93 void storeTo(Offset point)
95 for (
size_t valueIndex = 0; valueIndex < values.size(); ++valueIndex)
97 auto& output = outputs[valueIndex];
98 if (output) output->setValue(point, values[valueIndex]);
103 PointScript(std::shared_ptr<CompiledScript> compiled, std::vector<AttributeBinding> bindings);
105 template <
typename Action>
void visitBindingValues(attr::AttributeType type, Action&& action);
106 template <
typename Action>
void visitAllBindingValues(Action&& action);
107 bool resolveAttributes(
const geo::Primitive& input, geo::Primitive& output, String& error);
109 std::shared_ptr<CompiledScript> compiled_;
110 std::vector<AttributeBinding> bindings_;
112 BindingValues<floatT> floats_;
113 BindingValues<intT> ints_;
114 BindingValues<Vector3> vectors_;
115 BindingValues<boolT> bools_;
118 std::vector<ScriptArgument> arguments_;
Basic attribute, parameter, and node types for Enzo.
size_t Offset
enzo::Offset is the internal discontinuous index of an element in a given AttributeOwner.
Definition Types.h:181
AttributeType
Data types available to store attribute values in.
Definition Types.h:37
The world a single expression evaluation reads and writes to.
Definition ExpressionContext.h:28
A compiled script that runs once per point and edits the point's attributes.
Definition PointScript.h:40
bool addWrittenAttributes(geo::Primitive &output, String &error) const
Adds every attribute the script writes to the output, filled with the default value.
Definition PointScript.cpp:433
static std::shared_ptr< PointScript > compile(const String &code, String &error)
Returns the compiled script for the user's code.
Definition PointScript.cpp:395
std::shared_ptr< PointScript > clone() const
Returns a copy that runs in its own context.
Definition PointScript.cpp:426
bool run(const geo::Primitive &input, geo::Primitive &output, Offset begin, Offset end, const ExpressionContext *context, String &error)
Runs the script for each valid point in a range.
Definition PointScript.cpp:489
const std::vector< AttributeBinding > & getBindings() const
Returns every attribute the code binds, in the order they first appear.
Definition PointScript.h:47
Base class for all primitive types in the engine.
A point attribute the script reads or writes as @name.
Definition PointScript.h:20