プロパティ ページのイベント ハンドラの命名規則は、SPDL ベース、ランタイムおよびプラグインの各プロパティで若干異なります。
デフォルトでは、プラグイン ベース(自己インストール)のプロパティは、プロパティの名前をプリフィックスとして使用します。 たとえば、MyProp プロパティの OnInit コールバックは MyProp_OnInit になります。
デフォルトでは、SPDL ベースのプロパティとランタイム ベースのプロパティは、プリフィックスを使用しません。 たとえば、MyProp プロパティの OnInit コールバックは、SPDL ファイルで定義されるか処理中に定義されるかに関わらず、単に OnInit となります。
ただし、プリフィックスが指定されている場合は、プロパティの名前やその実装方法に関わらず、そのプリフィックスがイベント ハンドラ コールバック全体で使用されます。 たとえば、プリフィックスが FooBar として定義された MyProp プロパティの場合、OnInit コールバックは、SPDL ベース、ランタイムベース、プラグイン ベースのカスタム プロパティで同じように FooBar_OnInit になります。
ランタイムプロパティおよびプラグイン プロパティの場合は、PPGLayout.SetAttribute または PPGLayout::PutAttribute 一方、SPDL ベースのプロパティの場合は、SPDL ファイルの Logic ブロックでスクリプトを介して、または LogicPrefix 設定を介して、プリフィックスを定義することができます。
この例では、プリフィックス FooBar を使用して、処理中に単純なカスタム プロパティを作成します。このプリフィックスは、このページのロジックのイベント ハンドラにある必要があります。
// Define an on-the-fly property with a single boolean parameter
var root = Application.ActiveSceneRoot;
var prop = root.AddCustomProperty( "RuntimePropertyDemo" );
prop.AddParameter3( "BooParam", siBool );
// Access the logic via the layout and simply add the handlers
// specified below via the JScript toString() function
var ppglay = prop.PPGLayout;
ppglay.Logic = FooBar_OnInit.toString() + FooBar_BooParam_OnChanged.toString();
// Specify the new prefix and set the language to JScript
ppglay.Language = "JScript";
ppglay.SetAttribute( siUILogicPrefix, "FooBar_" ); // explicitly specify the underscore
//
// Event handlers: for demo, these just log their names when called
//
// INFO : OnInit handler called
function FooBar_OnInit() // specify the prefix before 'OnInit'
{
Application.LogMessage( "OnInit handler called" );
}
// INFO : Parameter_OnChanged handler called
function FooBar_BooParam_OnChanged() // specify the prefix before 'Parameter_OnChanged'
{
Application.LogMessage( "Parameter_OnChanged handler called" );
}この例は、ランタイム プロパティの例と非常によく似ていますが、スクリプト プラグインである点が異なります。 これをテストするには、以下の手順に従います。
以下のサンプル コードをファイルにコピー アンド ペーストし、ユーザ ディレクトリの Applications/Plugins フォルダに保存します(ファイル名は PluginPropertyDemoPlugin.js とします)。
Script Editor で以下のコードを実行することによって、プロパティをシーン ルートに適用します。
Application.ActiveSceneRoot.AddProperty( "PluginPropertyDemo" );
新しいプロパティを調べます(OnInit イベント ハンドラがメッセージを記録します)。
[BooParam] のチェック ボックスを切り替えると、イベント ハンドラが画面にメッセージを記録するのを確認することができます。
この例では、OnInit および OnChanged コールバックだけでなく、Define および DefineLayout コールバックでもプリフィックスが使用されます。
// Define a plug-in based property with a single boolean parameter
//
// Notice that the Define and DefineLayout callbacks use the
// property name; only the event handlers use the prefix
function XSILoadPlugin( in_reg )
{
in_reg.Name = "PluginPropertyDemoPlugin";
in_reg.RegisterProperty( "PluginPropertyDemo" );
return true;
}
// Add parameters in this callback
function PluginPropertyDemo_Define( in_ctxt )
{
var prop = in_ctxt.Source; // Get the CustomProperty
prop.AddParameter3( "BooParam", siBool );
return true;
}
// Set the language and prefix in this callback (the logic is automatically
// provided by the event handler callbacks specified at the bottom of the file)
function PluginPropertyDemo_DefineLayout( in_ctxt )
{
var ppglay = in_ctxt.Source; // Get the PPGLayout
// Set the language to JScript and specify the new prefix
ppglay.Language = "JScript";
ppglay.SetAttribute( siUILogicPrefix, "FooBar_" ); // explicitly specify the underscore
return true;
}
//
// Event handlers: for demo, these just log their names when called
//
// INFO : OnInit handler called
function FooBar_OnInit() // specify the prefix before 'OnInit'
{
Application.LogMessage( "OnInit handler called" );
}
// INFO : Parameter_OnChanged handler called
function FooBar_BooParam_OnChanged() // specify the prefix before 'Parameter_OnChanged'
{
Application.LogMessage( "Parameter_OnChanged handler called" );
}この例では、LogicPrefix 設定を使用してプリフィックスを設定する方法を示します。 これは、完全に機能する SPDL ファイルです。ただし、シェーダとしては、何らかのライブラリ ファイルがなければ明らかにエラーになります。 これをテストするには、以下の手順に従います。
以下のコードをファイルにコピー アンド ペーストし、ユーザ ディレクトリの Applications/spdl フォルダに保存します(ファイル名は SPDLPropertyDemo.spdl とします)。
Softimage のプラグイン ツリーで、新しい spdl ファイルを右クリックし(spdl ファイルが表示されていない場合は、[すべて更新](Update All)をクリック)、[プリセットの再生成](Regenerate Preset)を選択します。
Script Editor で以下のコードを実行することによって、Softimage シーンでシェーダを立方体に適用します。
var obj = Application.ActiveSceneRoot.AddGeometry( "Cube", "NurbsSurface" ); var shaderpreset = XSIUtils.BuildPath( Application.InstallationPath( siUserPath ), "Data", "DSPresets", "Shaders", "Texture", "SPDLPropertyDemo.Preset" ); CreateShaderFromPreset( shaderpreset, "Sources.Materials.DefaultLib.Material" ); SIConnectShaderToCnxPoint( "Sources.Materials.DefaultLib.Material.SPDLPropertyDemo", "Sources.Materials.DefaultLib.Scene_Material.Phong.ambient", false );
新しいシェーダ プロパティを調べます(OnInit イベント ハンドラがメッセージを記録します)。
[BooParam] のチェック ボックスを切り替えると、イベント ハンドラが画面にメッセージを記録するのを確認することができます。
この SPDL コードでは、プリフィックスがランタイムおよびプラグインベースの例にあるものと同様に指定されており、イベントハンドラが同一です。
SPDL
Version = "2.0.0.0";
Reference = "{0DEC8359-4327-42E4-AE1B-A9504FF4047C}";
PropertySet "SPDLPropertyDemo_pset"
{
Parameter "out" output
{
GUID = "{248FCEFE-DBA6-412A-9A8F-17A96D97F1E3}";
Type = color;
}
Parameter "BooParam" input
{
GUID = "{4F5EE6C2-D219-4986-B455-EFAA6C538FC7}";
Type = boolean;
Value = off;
}
}
MetaShader "SPDLPropertyDemo_meta"
{
Name = "SPDL Property Demo Shader";
Type = texture;
Renderer "mental ray"
{
Name = "SPDLPropertyDemo";
FileName = "SPDLPropertyDemo";
Options
{
"version" = 1;
}
}
}
Layout "Default"
{
BooParam;
}
Language = "JScript";
LogicPrefix = "FooBar_";
# Alternatively you could copy the code between the BeginScript and EndScript
# keywords and save them in the following file (and uncomment the next line):
#LogicFile = "$XSI_USERHOME/Application/spdl/lib/SPDLPropertyDemo.js";
BeginScript
//
// Event handlers: for demo, these just log their names when called
//
// INFO : OnInit handler called
function FooBar_OnInit() // specify the prefix before 'OnInit'
{
Application.LogMessage( "OnInit handler called" );
}
// INFO : Parameter_OnChanged handler called
function FooBar_BooParam_OnChanged() // specify the prefix before 'Parameter_OnChanged'
{
Application.LogMessage( "Parameter_OnChanged handler called" );
}
EndScript
Plugin = Shader
{
FileName = "SPDLPropertyDemo";
}