v4.0
ブランクの「ランタイム」スクリプトオペレータを指定されたコードで作成します。これにより、スクリプトオペレータエディタを使用せずに、処理中にオペレータを作成できるようになります。これらのオペレータには、シーン ファイルに埋め込まれたコードと、自己インストール CustomOperator とは異なるコールバック変換が定義されます。
スクリプト オペレータは次のコールバックを定義します。オペレータがユーザ定義の名前を持つ場合、その名前には次のように Init、Term、および Update コールバックのプリフィックスを付与する必要があります:
CustomOperator_Init (ctx)
CustomOperator_Init (ctx)
CustomOperator_Update (ctx, out, in1, inN)
更新機能には、入力ポートごとに引数が 1 つあります。オペレータが 2 つの入力ポートを持つ 2 つのグループを定義する場合、Update メソッドには 4 つの入力引数が渡されます。入力ポートの名前は引数の名前として使用されるので、ユニークでなくてはなりません。名前「in」という名前は、VBScript などのスクリプティング言語の予約語でもあるので、有効なポート名として認識されません。
バージョン 3.51 では、Init および Term は予約済みの関数名であると考えられていました。Softimage はスクリプトオペレータエディタまたは Init(ctx)および Init(ctx)および Term(ctx)コールバックの SPDL ファイルを使用して作成されたスクリプトオペレータのヘルパコードをチェックします。関数名が見つかっても指定されている引数の数が間違っている場合、Softimage は警告メッセージを表示します。バージョン 3.51 以前で作成したスクリプトオペレータで定義された Init または Term ヘルパー関数で、コールバックと同じシグネチャのあるものは、コールバックが実行されたときにランタイムエラーを発生する場合があります。この問題を解決するには、オペレータのコードを修正し、それらのヘルパー関数の名前を他の名前に変更します。
CustomOperator XSIFactory.CreateScriptedOp( String Name, String scriptcode, String Language ); |
oReturn = XSIFactory.CreateScriptedOp( Name, [ScriptCode], [Language] ); |
| パラメータ | タイプ | 説明 |
|---|---|---|
| Name | String |
新しいスクリプトオペレータの名前 デフォルト値: "" |
| ScriptCode | String |
スクリプトオペレータを実装するロジック デフォルト値: "" |
| Language | String |
ロジックに使用するスクリプト言語(たとえば"JScript"など) デフォルト値:ユーザプリファレンスに設定されている現在のスクリプト言語 |
/*
This example illustrates how to use the XSIFactory to create a multi-output operator
which constrains the posx position of a number of objects to a single object.
*/
NewScene( null, false );
var null1 = GetPrim( "Null" );
var null2 = GetPrim( "Null" );
var polymsh1 = CreatePrim( "sphere", "MeshSurface" );
var op = XSIFactory.CreateScriptedOp( "myCns", myCns_Update.toString(), "JScript" );
// Allow a maximum of 2 nulls to be connected to the main group
var group1 = op.AddPortGroup( "mainoutputgroup", 1, 2, siNullFilter );
// You only need to add 1 port to control 2 objects since the portgroup definition takes
// care of that. The only thing you need to do here is to define what type of object/parameter
// you would like to be connected to.
op.AddOutputPort( null1.posx, "", group1.Index );
// Define the second input group that will accept only 1 polygon mesh as input
var group2 = op.AddPortGroup( "inputgroup", 1, 1, siPolyMeshFilter );
op.AddInputPort( polymsh1.posx, "", group2.Index );
// Create a connection string. Use the semi-colon to delimit where the first group ends and
// the second port group begins.
var cnxstr = null1 + "," + null2 + ";" + polymsh1;
// connect operator
op.Connect( cnxstr );
function myCns_Update( ctx, out, inposx )
{
out.Value = inposx.Value;
} |
// The following code illustrates how to create a scripted operator
// entirely from the COM API
NewScene( null, false );
var oObject = ActiveSceneRoot.AddGeometry("Sphere","MeshSurface");
apply_splatter( oObject );
var oSplatterOperator = oObject.ActivePrimitive.ConstructionHistory.Find( "MySplatter" );
var oPort = oSplatterOperator.Port( "InGeom", "MainGroup", 0 );
var oInputGeometry = oPort.Target2;
Application.LogMessage( "splatter is reading from the " + oInputGeometry.Parent.Name );
function apply_splatter( oObject )
{
var op = XSIFactory.CreateScriptedOp( "MySplatter", MySplatter_Update.toString(), "JScript" );
// Define connections
var group = op.AddPortGroup( "MainGroup" );
var ioport = op.AddIOPort( oObject.ActivePrimitive, "Geom", group.Index );
var inport = op.AddInputPort( oObject.kinematics.global.posy, "InGPosY", group.Index );
// Define parameters
var pdef = XSIFactory.CreateParamDef2( "SquishFactor", siDouble, 0.5, 0, 1 );
op.AddParameter( pdef );
// Connect operator
op.Connect(oObject);
}
function MySplatter_Update( ctx, out, InGeom, InGPosY )
{
// Declare variables.
var dSquishPnt, i;
// Get the squish factor.
var dSquish = ctx.Parameters("SquishFactor").Value
// Get the array of point positions.
var aPnts = InGeom.Value.Geometry.Points.PositionArray.toArray();
// Get the object//s global Y position.
var dGPosYObj = InGPosY.Value;
// For each point...
for ( var i = 0; i < aPnts.length / 3; i++ )
{
// Compute the point's global Y position.
var dGPosYPnt = aPnts[1 + (i*3)] + dGPosYObj;
// If the point is below the Y=0 plane...
if ( dGPosYPnt < 0 )
{
// Compute the squish factor for the point.
var dSquishPnt = 1.0 - dGPosYPnt * dSquish;
// Squish the point.
aPnts[0 + (i*3)] = aPnts[0 + (i*3)] * dSquishPnt;
aPnts[1 + (i*3)] = - dGPosYObj;
aPnts[2 + (i*3)] = aPnts[2 + (i*3)] * dSquishPnt;
}
}
// Update the object//s point positions.
out.Value.Geometry.Points.PositionArray = aPnts;
return;
}
// |