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

DebugStop
#define DebugStop(...)
Definition: debugdiagnostics.h:230
FieldObject
Definition: c4d_fielddata.h:1059
maxon::Vec3::GetLength
T GetLength() const
Returns the length of the vector.
Definition: vec.h:405
Int
maxon::Int Int
Definition: ge_sys_math.h:49
FieldOutputBlock
Definition: c4d_fielddata.h:338
Float
maxon::Float Float
Definition: ge_sys_math.h:51
FieldData::Sample
virtual maxon::Result< void > Sample(const FieldObject &op, const FieldInput &inputs, FieldOutputBlock &outputs, const FieldInfo &info) const =0
maxon::OK
return OK
Definition: apibase.h:2485
FieldInput::_blockCount
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_SOURCE_LOCATION
#define MAXON_SOURCE_LOCATION
Definition: memoryallocationbase.h:66
FieldInfo
Thread local information for this field sample invocation.
Definition: c4d_fielddata.h:887
NodeData
Definition: c4d_nodedata.h:34
FieldInput::_position
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
FIELDOBJECT_FLAG::NONE
@ NONE
No flags.
FieldData::FreeSampling
virtual void FreeSampling(FieldObject &op, const FieldInfo &info, FieldShared &shared)
Definition: c4d_fieldplugin.h:78
maxon::Result< void >
maxon::Vec3< maxon::Float64, 1 >
FIELDOBJECT_FLAG
FIELDOBJECT_FLAG
Definition: ge_prepass.h:5452
FieldData::InitSampling
virtual maxon::Result< void > InitSampling(FieldObject &op, const FieldInfo &info, FieldShared &shared)
Definition: c4d_fieldplugin.h:70
FieldShared
Definition: c4d_fielddata.h:474
RegisterFieldPlugin
Bool RegisterFieldPlugin(Int32 id, const maxon::String &name, const maxon::String &help, Int32 info, DataAllocator *g, const maxon::String &description, BaseBitmap *icon, Int32 disklevel)
INSTANCEOF
#define INSTANCEOF(X, Y)
Definition: c4d_baselist.h:26
FieldData::GetFieldFlags
virtual FIELDOBJECT_FLAG GetFieldFlags(const FieldObject &op, BaseDocument *doc) const
Definition: c4d_fieldplugin.h:101
FieldInput
Definition: c4d_fielddata.h:533
NewObj
#define NewObj(T,...)
Definition: newobj.h:108
iferr
#define iferr(...)
Definition: errorbase.h:380
Bool
maxon::Bool Bool
Definition: ge_sys_math.h:40
FieldOutputBlock::_value
maxon::Block< Float > _value
Definition: c4d_fielddata.h:457
BaseDocument
Definition: c4d_basedocument.h:479
FieldData
Definition: c4d_fieldplugin.h:16