/*
This example illustrates how to use the OutputPort.Value property within
the context of the _Update function of a runtime scripted operator
*/
NewScene( null, false );
var oObject = Application.ActiveSceneRoot.AddGeometry( "Sphere", "MeshSurface" );
apply_taper( oObject );
// This is the _Update callback used for the 'MyTaper' runtime operator
function MyTaper_Update( ctx, Out, InGeom )
{
// Get the taper factor.
var dFactor = ctx.Parameters("Factor").Value
// Get the array of point positions.
var aPnts = InGeom.Value.Geometry.Points.PositionArray.toArray();
// Taper
for ( var i = 0; i < aPnts.length / 3; i++ )
{
var dTaper = (1 - ( aPnts[1 + (i*3)] * dFactor ))
aPnts[0 + (i*3)] = aPnts[0 + (i*3)] * dTaper;
aPnts[1 + (i*3)] = aPnts[1 + (i*3)];
aPnts[2 + (i*3)] = aPnts[2 + (i*3)] * dTaper;
}
// Set the points by accessing the geometry via
// the OutputPort.Value property
Out.Value.Geometry.Points.PositionArray = aPnts;
}
// This function creates the 'MyTaper' operator on the fly and then connects it
// immediately to the input object.
function apply_taper( oObject )
{
var op = XSIFactory.CreateScriptedOp( "MyTaper", MyTaper_Update.toString(), "JScript" );
// Define connections
var ioport = op.AddIOPort( oObject.ActivePrimitive, "Geom" );
// Define parameters
var pdef = XSIFactory.CreateParamDef2( "Factor", siDouble, 0.5, 0, 1 );
op.AddParameter( pdef );
// Connect operator
op.Connect( oObject );
} |