カスタム ICENodes は、複数の類似種類の入力値を処理する必要があるノードを実装する場合に役立つ無制限の入力接続数で定義することができます。最大接続数は各ポート グループに ICENodeDef::AddPortGroup を使用して指定する必要があります。デフォルトでは、ポートグループは1つの入力接続を持つように作成されます。
以下のコードは、ポート グループの複数接続に Evaluate コールバックからアクセスする方法を示します。
/*
Register an input group with up to 10 connections
*/
CStatus RegisterMaxNode( PluginRegistrar& in_reg )
{
ICENodeDef nodeDef = Application().GetFactory().CreateICENodeDef(L"MaxNode");
// Define a port group with a maximum of 10 connections.
CStatus st = nodeDef.AddPortGroup(ID_G_100, 1, 10);
st.AssertSucceeded();
st = nodeDef.AddInputPort( ID_IN_PointPositions, ID_G_100, siICENodeDataVector3, siICENodeStructureSingle, siICENodeContextComponent0D, L"PointPositions", L"PointPositions" );
st.AssertSucceeded();
// Add output port.
st = nodeDef.AddOutputPort( ID_OUT_Max, siICENodeDataVector3, siICENodeStructureSingle, siICENodeContextSingleton, L"MaxPos", L"MaxPos" );
st.AssertSucceeded();
in_reg.RegisterICENode(nodeDef);
return CStatus::OK;
}
/*
Evaluate each instance's value to find the maximum value amongst all instances
*/
XSIPLUGINCALLBACK CStatus Max_Evaluate( ICENodeContext& in_ctxt )
{
ULONG nPortID = in_ctxt.GetEvaluatedOutputPortID();
switch (nPortID)
{
case ID_OUT_MaxPos:
{
Application xsi;
CDataArrayVector3f outData(in_ctxt);
CVector3f v3fMax(-FLT_MAX,-FLT_MAX,-FLT_MAX);
// Get the number of port instances defined for group ID_G_100
ULONG nInstCount;
in_ctxt.GetGroupInstanceCount(ID_G_100, nInstCount);
// Iterate over the number of instances to access the data buffer of each input connection
for (ULONG nInstID=0; nInstID<nInstCount; nInstID++)
{
CDataArrayVector3f posArray(in_ctxt, ID_IN_PointPositions, nInstID);
CIndexSet indexSet( in_ctxt );
for ( CIndexSet::Iterator it = indexSet.Begin(); it.HasNext(); it.Next() )
{
CVector3f& v3f = posArray[it];
if ( v3fMax.GetX() <= v3f.GetX() && v3fMax.GetY() <= v3f.GetY() && v3fMax.GetZ() <= v3f.GetZ() )
{
v3fMax = v3f;
}
}
}
// Output max value
outData[0] = v3fMax;
}
};
return CStatus::OK;
}