About

FieldLayerData is the base class for custom field layers (FieldLayer)

A new FieldLayerData based class is registered with RegisterFieldLayerPlugin().

FieldLayerData

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

Register

A FieldLayerData based class has to be registered with RegisterFieldLayerPlugin(). The flags are:

Note
Modifier layers are registered with FIELDLAYER_DIRECT.

Example

// This example shows the implementation of a custom field layer.
// ------------------------------------------------------------------------------
// This example field layer shifts the hue of the sample color.
// ------------------------------------------------------------------------------
class HueShiftFieldLayer : public FieldLayerData
{
INSTANCEOF(HueShiftFieldLayer, FieldLayerData)
public:
// ------------------------------------------------------------------------------
// Allocation of a new instance
// @return New HueShiftFieldLayer instance or nullptr.
// ------------------------------------------------------------------------------
static NodeData* Alloc()
{
iferr (NodeData * const result = NewObj(HueShiftFieldLayer))
{
return nullptr;
}
return result;
}
{
// store data for faster access during sampling
const BaseContainer& layerBc = layer.GetDataInstanceRef();
GeData data;
if (layerBc.GetParameter(ConstDescID(DescLevel(FIELDLAYER_HUESHIFT_OFFSET)), data) == false)
return maxon::UnexpectedError(MAXON_SOURCE_LOCATION);
MAXON_REMOVE_CONST(this)->_offset = data.GetFloat();
return {};
}
virtual maxon::Result<void> Sample(const FieldLayer& layer, 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 the color hue
const Vector color = outputs._color[i];
Vector hsv = RGBToHSV(color);
Float hue = hsv.x;
// hue shift
hue = FMod(hue + _offset, 1.0);
// store new color
hsv.x = hue;
outputs._color[i] = HSVToRGB(hsv);
}
return maxon::OK;
}
virtual void FreeSampling(const FieldLayer& layer, const FieldInfo& info, maxon::GenericData& extraData) const
{
// free internal data after sampling
}
virtual Bool IsEqual(const FieldLayer& layer, const FieldLayerData& comp) const
{
return true;
}
private:
Float _offset = 0.0_f;
};
Py_ssize_t i
Definition: abstract.h:645
#define INSTANCEOF(X, Y)
Definition: c4d_baselist.h:38
Vector HSVToRGB(const Vector &col)
Vector RGBToHSV(const Vector &col)
Definition: c4d_basecontainer.h:48
Bool GetParameter(const DescID &id, GeData &t_data) const
Definition: c4d_basecontainer.h:716
const BaseContainer & GetDataInstanceRef() const
Definition: c4d_baselist.h:2518
Definition: c4d_fieldplugin.h:107
virtual Bool IsEqual(const FieldLayer &layer, const FieldLayerData &comp) const
Definition: c4d_fieldplugin.h:167
virtual void FreeSampling(const FieldLayer &layer, const FieldInfo &info, maxon::GenericData &extraData) const
Definition: c4d_fieldplugin.h:158
virtual maxon::Result< maxon::Tuple< maxon::GenericData, Int32 > > InitSampling(const FieldLayer &layer, const FieldInfo &info) const
Definition: c4d_fieldplugin.h:123
virtual maxon::Result< void > Sample(const FieldLayer &layer, const FieldInput &inputs, FieldOutputBlock &outputs, const FieldInfo &info, const maxon::GenericData &extraData) const =0
Definition: c4d_fielddata.h:1093
Definition: c4d_gedata.h:83
Float GetFloat() const
Definition: c4d_gedata.h:468
Definition: c4d_nodedata.h:40
Definition: resultbase.h:766
PyObject PyObject * result
Definition: abstract.h:43
maxon::Bool Bool
Definition: ge_sys_math.h:51
maxon::Float Float
Definition: ge_sys_math.h:62
maxon::Int Int
Definition: ge_sys_math.h:60
return OK
Definition: apibase.h:2735
#define MAXON_SOURCE_LOCATION
Definition: memoryallocationbase.h:67
#define iferr(...)
Definition: errorbase.h:388
#define DebugStop(...)
Definition: debugdiagnostics.h:225
#define ConstDescID(...)
Definition: lib_description.h:594
Float32 FMod(Float32 v1, Float32 v2)
Definition: apibasemath.h:192
#define NewObj(T,...)
Definition: newobj.h:108
_Py_clock_info_t * info
Definition: pytime.h:197
Represents a level within a DescID.
Definition: lib_description.h:298
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
Definition: c4d_fielddata.h:347
maxon::Block< BVector > _color
The alpha value for color and direction at this point in space, only available when color or directio...
Definition: c4d_fielddata.h:457
T x
Definition: vec.h:39
// This example registeres the given FieldLayerData plugin.
const Bool registerFieldLayerSuccess = RegisterFieldLayerPlugin(fieldLayerPluginID,
"Hue Shift Layer"_s,
"Changes the color hue."_s,
"Hue Shift Layer"_s,
HueShiftFieldLayer::Alloc,
"Flhueshift"_s,
nullptr,
0,
nullptr);
if (registerFieldLayerSuccess == false)
return maxon::UnknownError(MAXON_SOURCE_LOCATION);
Bool RegisterFieldLayerPlugin(Int32 id, const maxon::String &name, const maxon::String &help, const maxon::String &pickInstruction, Int32 info, DataAllocator *g, const maxon::String &description, BaseBitmap *icon, Int32 disklevel, FieldLayerAcceptDragFunction *dragFunc=nullptr)
#define FIELDLAYER_PREMULTIPLIED
The FieldLayer will receive FieldOutputBlock data premultiplied by alpha values.
Definition: ge_prepass.h:988
#define FIELDLAYER_NOROTATIONOUT
The FieldLayer doesn't calculate rotational velocities.
Definition: ge_prepass.h:989
#define FIELDLAYER_DIRECT
The FieldLayer will have access to directly manipulate the 'result' data in ModifyValues rather than ...
Definition: ge_prepass.h:981
#define FIELDLAYER_NOVALUEOUT
The FieldLayer doesn't calculate values.
Definition: ge_prepass.h:983
#define FIELDLAYER_NODIRECTIONOUT
The FieldLayer doesn't calculate directions.
Definition: ge_prepass.h:985

Further Reading