SIApplyShader
 
 
 

SIApplyShader

Introduced

v1.0

Description

Applies a shader to the specified item. This could be an object, a group, a partition, a cluster, the scene root, material, a component, a light, a camera, or anything else that can support a shader.

Scripting Syntax

oReturn = SIApplyShader( PresetObj, InputObjs, [Name], [PropagationType] );

Return Value

Returns an XSICollection containing the Shader.

Parameters

Parameter Type Description
PresetObj String or a preset object (see SIGetPreset) Shader Presets
InputObjs String List of objects

Default Value: Current selection

Name String Name of the shader

Default Value: Default shader name

PropagationType siBranchFlag Propagation type of the shader, node or branch

Default Value: siUnspecified

Examples

VBScript Example

'
' This example creates a sphere, applies a lambert shader to it, prints out
' the list of connection points to that shader, disconnects the shadow and
' photon connection points from the shader and then prints the updated list.
'
' Create the sphere to which the shader will be connected
set oSphere = CreatePrim( "Sphere", "NurbsSurface" )
' Apply a default shader to instantiate the material
set oShader = SIApplyShader( InstallationPath( siFactoryPath ) _
                                & "\Data\DSPresets\Shaders\Material\Lambert.Preset", _
                                oSphere, "Christopher" )
' Convert the shader to a Shader object 
set oShader = oShader(0)
' Print shader info (before disconnecting)
printShaderInfo oShader
' For convenience, create a collection to hold the parameters
' to be disconnected (Shadow and Photon connection points).
set oCnxPoints = CreateObject( "XSI.Collection" )
oCnxPoints.Add oSphere & ".material.Shadow"
oCnxPoints.Add oSphere & ".material.Photon"
' Use that collection to disconnect the shader from the material 
RemoveShaderFromCnxPoint oShader, oCnxPoints
' Print shader info (after disconnecting)
printShaderInfo oShader
' This is a convenience routine that prints information about the shader
sub printShaderInfo( in_shader )
        ' From the shader object you can get the material it belongs to
        set oMaterial = in_shader.Owners(0)
        ' Use the material to return the parameters that are connected and
        ' print out their names
        for each p in oMaterial.Parameters
                if TypeName( p.Source ) <> "Nothing" then
                        LogMessage p.ScriptName & " is connected to " & p.Source.Name
                end if
        next
end sub
' Output of the above script:
' ...before disconnecting
'INFO : "surface is connected to Christopher"
'INFO : "shadow is connected to Christopher"
'INFO : "Photon is connected to Christopher"
'
' ...after disconnecting
'INFO : "surface is connected to Christopher"

See Also

AddObjectsToShader RemoveObjectsFromShader SIApplyShaderToCnxPoint SIConnectShaderToCnxPoint RemoveShaderFromCnxPoint RemoveAllShadersFromCnxPoint