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;
}
{
}
};
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:498
Definition: c4d_fieldplugin.h:21
virtual FIELDOBJECT_FLAG GetFieldFlags(const FieldObject &op, BaseDocument *doc) const
Definition: c4d_fieldplugin.h:105
virtual maxon::Result< void > InitSampling(FieldObject &op, const FieldInfo &info, FieldShared &shared)
Definition: c4d_fieldplugin.h:74
virtual maxon::Result< void > Sample(const FieldObject &op, const FieldInput &inputs, FieldOutputBlock &outputs, const FieldInfo &info) const =0
virtual void FreeSampling(FieldObject &op, const FieldInfo &info, FieldShared &shared)
Definition: c4d_fieldplugin.h:82
Definition: c4d_fielddata.h:1083
Definition: c4d_nodedata.h:39
PyObject PyObject * result
Definition: abstract.h:43
void Py_ssize_t * pos
Definition: dictobject.h:50
maxon::Float Float
Definition: ge_sys_math.h:66
maxon::Int Int
Definition: ge_sys_math.h:64
return OK
Definition: apibase.h:2667
FIELDOBJECT_FLAG
Definition: ge_prepass.h:5773
@ NONE
No flags.
#define iferr(...)
Definition: errorbase.h:388
#define DebugStop(...)
Definition: debugdiagnostics.h:231
#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:901
Definition: c4d_fielddata.h:534
Int _blockCount
The number of elements in the array to be processed (for this processing block, this should be treate...
Definition: c4d_fielddata.h:705
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:702
Definition: c4d_fielddata.h:339
maxon::Block< Float > _value
Definition: c4d_fielddata.h:457
Definition: c4d_fielddata.h:475
// 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:55
#define MAXON_SOURCE_LOCATION
Definition: memoryallocationbase.h:67

Further Reading