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:

  • FieldData::GetFieldFlags(): Returns the flags defining the behaviour of the field object (::FIELDOBJECT_FLAG).
  • FieldData::InitSampling(): Initializes the sampling process.
  • FieldData::Sample(): Samples the object.
  • FieldData::FreeSampling(): Clears internal data.

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;
}
virtual maxon::Result<maxon::GenericData> InitSampling(const FieldObject& op, const FieldInfo& info) const
{
// 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;
}
virtual FIELDOBJECT_FLAG GetFieldFlags(const FieldObject& op, const BaseDocument* doc) const
{
}
};
Py_ssize_t i
Definition: abstract.h:645
PyObject * value
Definition: abstract.h:715
NONE
Definition: asset_browser.h:1
#define INSTANCEOF(X, Y)
Definition: c4d_baselist.h:49
Definition: resultbase.h:766
PyObject PyObject * result
Definition: abstract.h:43
void Py_ssize_t * pos
Definition: dictobject.h:50
return OK
Definition: apibase.h:2740
FIELDOBJECT_FLAG
Definition: ge_prepass.h:5819
#define iferr(...)
Definition: errorbase.h:388
#define DebugStop(...)
Definition: debugdiagnostics.h:225
maxon::Float Float
Definition: ge_sys_math.h:57
maxon::Int Int
Definition: ge_sys_math.h:55
FieldOutputBlockTemplate< false > FieldOutputBlock
Definition: operatingsystem.h:300
maxon::Vec3< maxon::Float64, 1 > Vector
Definition: ge_math.h:140
#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
// 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);
#define MAXON_SOURCE_LOCATION
Definition: memoryallocationbase.h:69
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:46

Further Reading