FieldLayerData Manual

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:

  • FieldLayerData::InitSampling(): Prepares data for sampling.
  • FieldLayerData::Sample(): Samples the layer.
  • FieldLayerData::Aggregate(): Called after each thread/block if FIELDLAYER_AGGREGATE is set.
  • FieldLayerData::FreeSampling(): Frees data after sampling.
  • FieldLayerData::IsEqual(): Returns true if the layer is equal to the given layer.
  • FieldLayerData::GetLinkedObject(): Returns a referenced object.
  • FieldLayerData::SetLinkedObject(): Sets a referenced object.
  • FieldLayerData::CheckDirty(): Updates the dirtiness.

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<maxon::Tuple<maxon::GenericData, Int32>> InitSampling(const FieldLayer& layer, const FieldInfo& info) const
{
// 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:49
Definition: resultbase.h:766
PyObject PyObject * result
Definition: abstract.h:43
return OK
Definition: apibase.h:2740
MAXON_ATTRIBUTE_FORCE_INLINE Bool IsEqual(PREDICATE &&predicate, const T1 &a, const T2 &b)
Definition: collection.h:102
#define MAXON_SOURCE_LOCATION
Definition: memoryallocationbase.h:69
#define iferr(...)
Definition: errorbase.h:388
#define DebugStop(...)
Definition: debugdiagnostics.h:225
#define ConstDescID(...)
Definition: lib_description.h:592
Float32 FMod(Float32 v1, Float32 v2)
Definition: apibasemath.h:192
Vector RGBToHSV(const Vector &col)
maxon::Bool Bool
Definition: ge_sys_math.h:46
maxon::Float Float
Definition: ge_sys_math.h:57
maxon::Int Int
Definition: ge_sys_math.h:55
Vector HSVToRGB(const Vector &col)
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
_Py_clock_info_t * info
Definition: pytime.h:197
// 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);
#define FIELDLAYER_PREMULTIPLIED
The FieldLayer will receive FieldOutputBlock data premultiplied by alpha values.
Definition: ge_prepass.h:987
#define FIELDLAYER_NOROTATIONOUT
The FieldLayer doesn't calculate rotational velocities.
Definition: ge_prepass.h:988
#define FIELDLAYER_DIRECT
The FieldLayer will have access to directly manipulate the 'result' data in ModifyValues rather than ...
Definition: ge_prepass.h:980
#define FIELDLAYER_NOVALUEOUT
The FieldLayer doesn't calculate values.
Definition: ge_prepass.h:982
#define FIELDLAYER_NODIRECTIONOUT
The FieldLayer doesn't calculate directions.
Definition: ge_prepass.h:984
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)

Further Reading