FieldData Manual

About

FieldData is the base class for custom field objects (see FieldObject Manual).

A new FieldData based class is registered with RegisterFieldPlugin().

FieldData

In a FieldData based class the following functions can be implemented:

For related data types see FieldObject Manual.

Example

// This example shows the implementation of a custom field object.
// ------------------------------------------------------------------------------
// This example field defines the field value based on the global space position.
// ------------------------------------------------------------------------------
class ExampleField : public FieldData
{
INSTANCEOF(ExampleField, FieldData)
public:
// ------------------------------------------------------------------------------
// Allocation of a new instance
// @return New ExampleField instance or nullptr.
// ------------------------------------------------------------------------------
static NodeData* Alloc()
{
iferr (NodeData * const result = NewObj(ExampleField))
{
return nullptr;
}
return result;
}
{
// calculation done before sampling
return maxon::OK;
}
virtual void FreeSampling(FieldObject& op, const FieldInfo& info, FieldShared& shared)
{
// freeing internal data after sampling
}
virtual maxon::Result<void> Sample(const FieldObject& op, const FieldInput& inputs, FieldOutputBlock& outputs, const FieldInfo& info) const
{
// handle each input position
for (Int i = inputs._blockCount - 1; i >= 0; --i)
{
// get position
const Vector pos = inputs._position[i];
// calculate value
const Float distance = pos.GetLength();
const Float value = distance / 1000.0;
// set value
outputs._value[i] = value;
}
return maxon::OK;
}
virtual FIELDOBJECT_FLAG GetFieldFlags(const FieldObject& op, BaseDocument* doc) const
{
}
};
// This example registeres the given FieldData plugin.
const Bool registerFieldSuccess = RegisterFieldPlugin(fieldPluginID, "Example Field"_s, "Global Falloff"_s, 0, ExampleField::Alloc, "fexample"_s, nullptr, 0);
if (registerFieldSuccess == false)
return maxon::UnknownError(MAXON_SOURCE_LOCATION);

Further Reading