-
首页
-
C4D R23.110 C++ SDK
FieldData
Manual
内容表
关于
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
.
范例
// 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))
{
DebugStop
();
return
nullptr
;
}
return
result;
}
virtual
maxon::Result<void>
InitSampling
(
FieldObject
& op,
const
FieldInfo
& info,
FieldShared
& shared)
{
// 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
向量
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
{
return
FIELDOBJECT_FLAG::NONE
;
}
};
// 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 DebugStop(...)
定义:
debugdiagnostics.h:228
maxon::Int Int
定义:
ge_sys_math.h:62
constexpr T GetLength() const
Returns the length of the vector.
定义:
vec.h:405
maxon::Float Float
定义:
ge_sys_math.h:64
virtual maxon::Result< void > Sample(const FieldObject &op, const FieldInput &inputs, FieldOutputBlock &outputs, const FieldInfo &info) const =0
return OK
定义:
apibase.h:2532
#define MAXON_SOURCE_LOCATION
定义:
memoryallocationbase.h:66
Thread local information for this field sample invocation.
定义:
c4d_fielddata.h:904
virtual void FreeSampling(FieldObject &op, const FieldInfo &info, FieldShared &shared)
定义:
c4d_fieldplugin.h:82
FIELDOBJECT_FLAG
定义:
ge_prepass.h:5497
virtual maxon::Result< void > InitSampling(FieldObject &op, const FieldInfo &info, FieldShared &shared)
定义:
c4d_fieldplugin.h:74
Bool RegisterFieldPlugin(Int32 id, const maxon::String &name, const maxon::String &help, Int32 info, DataAllocator *g, const maxon::String &description, BaseBitmap *icon, Int32 disklevel)
#define INSTANCEOF(X, Y)
定义:
c4d_baselist.h:38
virtual FIELDOBJECT_FLAG GetFieldFlags(const FieldObject &op, BaseDocument *doc) const
定义:
c4d_fieldplugin.h:105
#define NewObj(T,...)
定义:
newobj.h:108
#define iferr(...)
定义:
errorbase.h:380
maxon::Bool Bool
定义:
ge_sys_math.h:53
maxon::Block< Float > _value
定义:
c4d_fielddata.h:461
定义:
c4d_basedocument.h:490