/*
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 ) ;
} |