Softimage SDK Programmer's Guide > Customizing with the SDK > Custom ICENodes > Custom ICENode Processing >

# CustomVector3ToScalar Example

This summarizes the ICENode processing topic with a custom version of the built-in Vector3ToScalar ICENode.

    #include <xsi_application.h>
    #include <xsi_context.h>
    #include <xsi_pluginregistrar.h>
    #include <xsi_status.h>

    #include <xsi_mdnodecontext.h>
    #include <xsi_mdnodedef.h>
    #include <xsi_factory.h>
    #include <xsi_math.h>
    #include <xsi_vector2f.h>
    #include <xsi_vector3f.h>
    #include <xsi_vector4f.h>
    #include <xsi_matrix3f.h>
    #include <xsi_matrix4f.h>
    #include <xsi_rotationf.h>
    #include <xsi_quaternionf.h>
    #include <xsi_color4f.h>
    #include <xsi_shape.h>
    #include <xsi_indexset.h>
    #include <xsi_dataarray.h>
    #include <xsi_dataarray2D.h>

    // Defines port, group and map identifiers used for registering the ICENode
    enum IDs
    {
    	ID_IN_v3 = 0,
    	ID_G_100 = 100,
    	ID_OUT_x = 200,
    	ID_OUT_y = 201,
    	ID_OUT_z = 202,
    	ID_TMAP = 400,
    	ID_SMAP,
    	ID_CMAP,
    	ID_UNDEF = ULONG_MAX
    };

    XSI::CStatus RegisterCustomVector3ToScalar( XSI::PluginRegistrar& in_reg );

    using namespace XSI;

    XSIPLUGINCALLBACK CStatus XSILoadPlugin( PluginRegistrar& in_reg )
    {
    	in_reg.PutAuthor(L"Softimage");
    	in_reg.PutName(L"CustomVector3ToScalar Plugin");
    	in_reg.PutEmail(L"");
    	in_reg.PutURL(L"");
    	in_reg.PutVersion(1,0);

    	RegisterCustomVector3ToScalar( in_reg );

    	//RegistrationInsertionPoint - do not remove this line

    	return CStatus::OK;
    }

    CStatus RegisterCustomVector3ToScalar( PluginRegistrar& in_reg )
    {
    	ICENodeDef nodeOpDef;
    	nodeOpDef = Application().GetFactory().CreateICENodeDef(L"CustomVector3ToScalar");

    	CStatus st;

    	// Add input ports and groups.
    	st = nodeOpDef.AddPortGroup(ID_G_100);
    	st.AssertSucceeded( ) ;

    	st = nodeOpDef.AddInputPort(
    		ID_IN_v3, // port index
    		ID_G_100, // group index
    		siICENodeDataVector3, // data type
    		siICENodePortStructureSingle, // structure type
    		siICENodeEvaluationContextComponent0D, // context type
    		L"v3",					// port name
    		L"v3",					// port scripting name
    		MATH::CVector3f(1.0,1.0,1.0), // default value
    		ID_UNDEF, // data type constraint
    		ID_SMAP, // structure type constraint
    		ID_CMAP					// context type contraint
    	);
    	st.AssertSucceeded( ) ;

    	// Add output ports
    	st = nodeOpDef.AddOutputPort(
    		ID_OUT_x, // port index
    		siICENodePortDataFloat, // data type
    		siICENodePortStructureSingle, // structure type
    		siICENodeEvaluationContextComponent0D, // context type
    		L"x",					// port name
    		L"x",					// port scripting name
    		ID_UNDEF, // data type constraint
    		ID_SMAP, // structure type constraint
    		ID_CMAP					// context type contraint
    	);
    	st.AssertSucceeded( ) ;

    	st = nodeOpDef.AddOutputPort(
    		ID_OUT_y, // port index
    		siICENodePortDataFloat, // data type
    		siICENodePortStructureSingle, // structure type
    		siICENodeEvaluationContextComponent0D, // context type
    		L"y",					// port name
    		L"y",					// port scripting name
    		ID_UNDEF, // data type constraint
    		ID_SMAP, // structure type constraint
    		ID_CMAP					// context type contraint
    	);
    	st.AssertSucceeded( ) ;

    	st = nodeOpDef.AddOutputPort(
    		ID_OUT_z, // port index
    		siICENodePortDataFloat, // data type
    		siICENodePortStructureSingle, // structure type
    		siICENodeEvaluationContextComponent0D, // context type
    		L"z",					// port name
    		L"z",					// port scripting name
    		ID_UNDEF, // data type constraint
    		ID_SMAP, // structure type constraint
    		ID_CMAP					// context type contraint
    	);
    	st.AssertSucceeded( ) ;

    	PluginItem nodeItem = in_reg.RegisterICENode(nodeOpDef);
    	nodeItem.PutCategories(L"Custom ICENode Sample");

    	return CStatus::OK;

    }

    XSIPLUGINCALLBACK CStatus CustomVector3ToScalar_Evaluate( ICENodeContext& in_ctxt )
    {
    	// Get the output data array
    	CDataArrayFloat outData( in_ctxt );

    	// .. and the input array
    	CDataArrayVector3f inputData( in_ctxt, ID_IN_v3 );

    	// And the index set
    	CIndexSet indexSet( in_ctxt );

    	// Set the output data
    	ULONG outport_uniqid = in_ctxt.GetEvaluatedOutputPortID( );

    	switch( outport_uniqid )
    	{
    		case ID_OUT_x:
    		{
    			for(CIndexSet::Iterator it = indexSet.Begin(); it.HasNext(); it.Next())
    			{
    				outData[it] = inputData[it].GetX();
    			}
    		}
    		break;

    		case ID_OUT_y:
    		{
    			for(CIndexSet::Iterator it = indexSet.Begin(); it.HasNext(); it.Next())
    			{
    				outData[it] = inputData[it].GetY();
    			}
    		}
    		break;

    		case ID_OUT_z:
    		{
    			for(CIndexSet::Iterator it = indexSet.Begin(); it.HasNext(); it.Next())
    			{
    				outData[it] = inputData[it].GetZ();
    			}
    		}
    		break;
    	};

    	return CStatus::OK;
    }