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;
}
virtual maxon::Result<void> InitSampling(FieldLayer& layer, const FieldInfo& info, FieldShared& shared)
{
// store data for faster access during sampling
const BaseContainer& layerBc = layer.GetDataInstanceRef();
GeData data;
if (layerBc.GetParameter(FIELDLAYER_HUESHIFT_OFFSET, data) == false)
return maxon::UnexpectedError(MAXON_SOURCE_LOCATION);
_offset = data.GetFloat();
return maxon::OK;
}
virtual maxon::Result<void> Sample(const FieldLayer& layer, const FieldInput& inputs, FieldOutputBlock& outputs, const FieldInfo& info) 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(FieldLayer& layer, const FieldInfo& info, FieldShared& shared)
{
// free internal data after sampling
}
virtual Bool IsEqual(const FieldLayer& layer, const FieldLayerData& comp) const
{
return true;
}
private:
Float _offset = 0.0_f;
};
// 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);

Further Reading

RegisterFieldLayerPlugin
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)
DebugStop
#define DebugStop(...)
Definition: debugdiagnostics.h:230
FieldLayer
Definition: c4d_fielddata.h:1124
FieldLayerData
Definition: c4d_fieldplugin.h:104
FieldLayerData::FreeSampling
virtual void FreeSampling(FieldLayer &layer, const FieldInfo &info, FieldShared &shared)
Definition: c4d_fieldplugin.h:158
Int
maxon::Int Int
Definition: ge_sys_math.h:49
FieldLayerData::InitSampling
virtual maxon::Result< void > InitSampling(FieldLayer &layer, const FieldInfo &info, FieldShared &shared)
Definition: c4d_fieldplugin.h:122
FIELDLAYER_NOVALUEOUT
#define FIELDLAYER_NOVALUEOUT
The FieldLayer doesn't calculate values.
Definition: ge_prepass.h:919
FIELDLAYER_NOROTATIONOUT
#define FIELDLAYER_NOROTATIONOUT
The FieldLayer doesn't calculate rotational velocities.
Definition: ge_prepass.h:925
FieldOutputBlock
Definition: c4d_fielddata.h:338
FieldLayerData::IsEqual
virtual Bool IsEqual(const FieldLayer &layer, const FieldLayerData &comp) const
Definition: c4d_fieldplugin.h:167
Float
maxon::Float Float
Definition: ge_sys_math.h:51
FMod
Float32 FMod(Float32 v1, Float32 v2)
Definition: apibasemath.h:207
FIELDLAYER_PREMULTIPLIED
#define FIELDLAYER_PREMULTIPLIED
The FieldLayer will receive FieldOutputBlock data premultiplied by alpha values.
Definition: ge_prepass.h:924
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
FieldLayerData::Sample
virtual maxon::Result< void > Sample(const FieldLayer &layer, const FieldInput &inputs, FieldOutputBlock &outputs, const FieldInfo &info) const =0
MAXON_SOURCE_LOCATION
#define MAXON_SOURCE_LOCATION
Definition: memoryallocationbase.h:66
HSVToRGB
Vector HSVToRGB(const Vector &col)
FieldInfo
Thread local information for this field sample invocation.
Definition: c4d_fielddata.h:887
NodeData
Definition: c4d_nodedata.h:34
maxon::Result< void >
BaseContainer::GetParameter
Bool GetParameter(const DescID &id, GeData &t_data) const
Definition: c4d_basecontainer.h:624
maxon::Vec3< maxon::Float64, 1 >
BaseList2D::GetDataInstanceRef
const BaseContainer & GetDataInstanceRef() const
Definition: c4d_baselist.h:2293
maxon::Vec3::x
T x
Definition: vec.h:32
RGBToHSV
Vector RGBToHSV(const Vector &col)
FieldShared
Definition: c4d_fielddata.h:474
GeData
Definition: c4d_gedata.h:77
INSTANCEOF
#define INSTANCEOF(X, Y)
Definition: c4d_baselist.h:26
FieldInput
Definition: c4d_fielddata.h:533
NewObj
#define NewObj(T,...)
Definition: newobj.h:108
iferr
#define iferr(...)
Definition: errorbase.h:380
FieldOutputBlock::_color
maxon::Block< Vector > _color
The alpha value for color and direction at this point in space, only available when color or directio...
Definition: c4d_fielddata.h:459
Bool
maxon::Bool Bool
Definition: ge_sys_math.h:40
FIELDLAYER_NODIRECTIONOUT
#define FIELDLAYER_NODIRECTIONOUT
The FieldLayer doesn't calculate directions.
Definition: ge_prepass.h:921
BaseContainer
Definition: c4d_basecontainer.h:42
FIELDLAYER_DIRECT
#define FIELDLAYER_DIRECT
The FieldLayer will have access to directly manipulate the 'result' data in ModifyValues rather than ...
Definition: ge_prepass.h:917
GeData::GetFloat
Float GetFloat(void) const
Definition: c4d_gedata.h:423