
v4.0
このメソッドは PPGLayout.AddItem に似ていますが、レイアウトにカラーウィジェットを追加する場合に役立ちます。Colorウィジェットには、siControlRGBA と siControlRGB の 2 つがあります。このコントロールでは、単一のパラメータではなく、カラーの各「チャンネル」ごとに個別のパラメータを読み書きします。
CustomProperty の RGBA カラーコントロールを作成するには、まず最初に siDouble または siFloat パラメータをコントロールに 4 つ追加します(例:"MyR"、"MyG"、"MyB"、"MyA")。命名方式は重要ではありませんが、パラメータは連続している必要があります。値は正規化形式で格納されるため、このパラメータの UI Range は 0~1 である必要があります。ただし、通常のカラースペース外のカラーに対応させる場合は、さらに広い実際の Range を使用できます(Parameter.SuggestedMax および Parameter.Max を参照)。
siDouble パラメータのデフォルトコントロールは siControlNumber ですが、このメソッドを呼び出して1 番目のパラメータの名前(例:"MyR")を指定することで、代わりにカラーウィジェットを表示できます。オブジェクトモデルからカラー値を読み取るには、単純に 4 つのパラメータの値を参照します。たとえば、"MyG"にはカラーの正規化された緑のコンポーネントが含まれます。
注:Shader では、カラーはネイティブの「強力な」型として直接サポートされます。したがって、siDoubleやsiFloat の複数パラメータではなく、単一のパラメータ"Color"が使用されます。
PPGItem PPGLayout.AddColor( String in_RedComponentParamName, String in_opt_Label, Boolean in_opt_Alpha ); |
oReturn = PPGLayout.AddColor( RedComponentParamName, [Label], [Alpha] ); |
| パラメータ | タイプ | 説明 |
|---|---|---|
| RedComponentParamName | String | カラーの Red コンポーネントを表す Parameter のスクリプト名。Redコンポーネントの後に続くパラメータが自動的に使用されるため、Green、Blue、および Alpha(オプション)の各パラメータの名前を指定する必要はありません。 |
| Label | String | カラーウィジェットの左側に表示されるテキストを指定します。指定しない場合には、パラメータの名前(SIObject.Name を参照)または赤コンポーネントのパラメータの Parameter.ScriptName が代わりに表示されます。 |
| アルファ | Boolean |
カラーにアルファチャンネルを含めるかどうかを指定します。この引数によって、siControlRGBA または siControlRBG が作成されるかどうかが決まります。
デフォルト値: false |
/*
Proxy Parameters are an useful way to centralize parameters from
different objects on the same property, or even to build a simplified
version of a property page.
This example demonstrates creation of a custom property set
that only shows a few items of the Shader that it controls,
but maintains a pleasing layout.
*/
NewScene( null, false ) ;
var oSphere = ActiveSceneRoot.AddGeometry( "Sphere", "MeshSurface" ) ;
oSphere.AddMaterial( "Phong" );
var oPhongShader = oSphere.Material.Shaders(0) ;
// This is a Boolean for enabling diffuse
var oDiffuseEnable = oPhongShader.Parameters( "diffuse_inuse" ) ;
// These are CompoundParameters, each with R,G,B sub-parameters
var oAmbientParam = oPhongShader.Parameters( "ambient" ) ;
var oDiffuseParam = oPhongShader.Parameters( "diffuse" ) ;
var oCustomProperty = oSphere.AddProperty("CustomProperty",false,"Proxies");
// We specify a name to avoid having a long one like "sphere_Material_Phong_diffuse_inuse"
oCustomProperty.AddProxyParameter( oDiffuseEnable, "Enable", "Enable" );
oCustomProperty.AddProxyParameter( oDiffuseParam.Parameters("red"), "Diffuse", "Diffuse" );
oCustomProperty.AddProxyParameter( oDiffuseParam.Parameters("green"));
oCustomProperty.AddProxyParameter( oDiffuseParam.Parameters("blue"));
oCustomProperty.AddProxyParameter( oAmbientParam.Parameters("red"), "Ambient", "Ambient" );
oCustomProperty.AddProxyParameter( oAmbientParam.Parameters("green"));
oCustomProperty.AddProxyParameter( oAmbientParam.Parameters("blue"));
// If we inspect the object now we would see 6 separate sliders,
// each controlling a different component of the colors
// We can create a custom layout to clean up the display
var oLayout = oCustomProperty.PPGLayout
oLayout.AddGroup( "Phong Diffuse" )
oLayout.AddItem( "Enable" ) ;
// Just for fun, show the ambient before the diffuse, which
// is the opposite of the normal Phong Property Page
oLayout.AddColor( "Ambient", "Ambient", false ) ;
oLayout.AddColor( "Diffuse", "Diffuse", false ) ;
oLayout.EndGroup() ;
oLayout.Logic = Enable_OnChanged.toString() ;
oLayout.Language = "JScript" ;
// Show both dialogs. You will see that both items
// are identical.
InspectObj ( oCustomProperty, null, null, siLock ) ;
InspectObj ( oPhongShader, null, null, siLock ) ;
function Enable_OnChanged()
{
// A little Property Page event code to properly
// grey out the color controls if the Disable checkbox is
// clicked
bEnable = PPG.Enable.Value ;
// To disable the color control we just disable the proxy
// parameter representing the "red" component
PPG.Ambient.Enable( bEnable ) ;
PPG.Diffuse.Enable( bEnable ) ;
} |