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 {};
}
virtual void FreeSampling(const FieldObject& op, const FieldInfo& info, maxon::GenericData& extraData) const
{
// freeing internal data after sampling
}
virtual maxon::Result<void> Sample(const FieldObject& op, const FieldInput& inputs, FieldOutputBlock& outputs, const FieldInfo& info, const maxon::GenericData& extraData) 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;
}
{
}
};
Py_ssize_t i
Definition: abstract.h:645
PyObject * value
Definition: abstract.h:715
#define INSTANCEOF(X, Y)
Definition: c4d_baselist.h:38
Definition: c4d_basedocument.h:497
Definition: c4d_fieldplugin.h:21
virtual maxon::Result< void > Sample(const FieldObject &op, const FieldInput &inputs, FieldOutputBlock &outputs, const FieldInfo &info, const maxon::GenericData &extraData) const =0
virtual void FreeSampling(const FieldObject &op, const FieldInfo &info, maxon::GenericData &extraData) const
Definition: c4d_fieldplugin.h:80
virtual maxon::Result< maxon::GenericData > InitSampling(const FieldObject &op, const FieldInfo &info) const
Definition: c4d_fieldplugin.h:73
virtual FIELDOBJECT_FLAG GetFieldFlags(const FieldObject &op, const BaseDocument *doc) const
Definition: c4d_fieldplugin.h:103
Definition: c4d_fielddata.h:1024
Definition: c4d_nodedata.h:40
Definition: resultbase.h:766
PyObject PyObject * result
Definition: abstract.h:43
void Py_ssize_t * pos
Definition: dictobject.h:50
maxon::Float Float
Definition: ge_sys_math.h:62
maxon::Int Int
Definition: ge_sys_math.h:60
return OK
Definition: apibase.h:2735
FIELDOBJECT_FLAG
Definition: ge_prepass.h:5797
@ NONE
No flags.
#define iferr(...)
Definition: errorbase.h:388
#define DebugStop(...)
Definition: debugdiagnostics.h:225
#define NewObj(T,...)
Definition: newobj.h:108
const char * doc
Definition: pyerrors.h:226
_Py_clock_info_t * info
Definition: pytime.h:197
PyObject * op
Definition: object.h:520
Thread local information for this field sample invocation.
Definition: c4d_fielddata.h:842
Definition: c4d_fielddata.h:474
Int _blockCount
The number of elements in the array to be processed (for this processing block, this should be treate...
Definition: c4d_fielddata.h:645
maxon::Block< const Vector > _position
The position values for the array of points, if this is a sub-block then element 0 is at _blockOffset...
Definition: c4d_fielddata.h:642
Definition: c4d_fielddata.h:347
maxon::Block< BFloat > _value
Definition: c4d_fielddata.h:455
// 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);
Bool RegisterFieldPlugin(Int32 id, const maxon::String &name, const maxon::String &help, Int32 info, DataAllocator *g, const maxon::String &description, BaseBitmap *icon, Int32 disklevel)
maxon::Bool Bool
Definition: ge_sys_math.h:51
#define MAXON_SOURCE_LOCATION
Definition: memoryallocationbase.h:67

Further Reading