Call for Submission
NAB 2012 Best of the Best Show Reel
Submit your work today!
  • 1/3
You are here: Forum Home / Autodesk® Softimage® / XSI SDK / ApplyShader
  RSS 2.0 ATOM  

ApplyShader
Rate this thread
 
36486
 
Permlink of this thread   Subscribe to this thread
avatar
  • Total Posts: 9
  • Joined: 28 March 2009 07:01 PM

I’m attempting my first Jscripting project and I’ve gotten near the end and have come to a loss. I cannot find my answers in the SDK or on any of the usual boards.

In the shortest terms I’ve created an object done a bunch of stuff to it and now I want to apply a material and change that materials color.

//creates my material
ApplyShader("$XSI_DSPRESETS\\Shaders\\Material\\Blinn.Preset"""null""siLetLocalMaterialsOverlap)

// is not changing created materials color
SetValue("Sources.Materials.DefaultLib.Material.Blinn.diffuse.red"0.545null)
SetValue(
"Sources.Materials.DefaultLib.Material.Blinn.diffuse.green"0null)
SetValue(
"Sources.Materials.DefaultLib.Material.Blinn.diffuse.blue"0null)

The question is: what is the proper method of changing the color of a currently selected objects material with jscript?

Oh, one more thing I am having trouble finding: how to change the name of the material. Not just the material node (blinn, phong etc) but the whole material as it appears in the material manager.



Replies: 0
avatar

Assuming “sphere” is the name of the object with the material, and “Blinn” is the name of the shader:

oSphere Dictionary.GetObject( "Sphere" )

oBlinn 
oSphere.Material.Shaders( "Blinn" )
oBlinn
.diffuse.Parameters( "red" ).Value 0.50;
oBlinn.diffuse.Parameters( "green" ).Value 1.0;
oBlinn.ambient.Parameters( "blue" ).Value 0;

oMat oSphere.Material;
LogMessage( oMat.Name )


Replies: 2
/userdata/avatar/42xp5d97p_peterbilt+sm.gif

Thank you but, how would that be implemented no matter what the name of the object is?

Lets say there is 5 objects in your scene. Select any object click button in PPG and new material is assigned and color is as specified in the script. Select a different object ( this object obviously has a different name) click button in ppg and that object gets predefined material.

Does this make sense?

What is going on is my script creates an object with controls on it (blah blah) at the end of the script I want to add a meterial ApplyShader("$XSI_DSPRESETS\\Shaders\\Material\\Blinn.Preset", “”, null, “”, siLetLocalMaterialsOverlap[\code]. Next I will click the button in the ppg again and create anouther object and this one also needs the same material as the first. than create anouther and anouther, so on and so forth.

P.S. before anyone says it… CTRL+D isn’t going to do it.

Author: SamBilling

Replied: 09 November 2009 06:14 AM  
/userdata/avatar/42xp5d97p_peterbilt+sm.gif

My script isn’t ready for the world but, here is a good for instance.

FIE muscle system (at the very end):

//SIAddCustomParameter(muscleMesh + “.MuscleParameters”, “BellyScale”, siDouble, 1.00, -400, 400, null, 5, 0, 10, null, null)

CopyPaste(muscleMesh + “.MuscleParameters.FirstTendonScale”, null, firstClusterCenterModeling + “.kine.local.scl.sclx”, 1)
CopyPaste(muscleMesh + “.MuscleParameters.FirstTendonScale”, null, firstClusterCenterModeling + “.kine.local.scl.scly”, 1)
CopyPaste(muscleMesh + “.MuscleParameters.FirstTendonScale”, null, firstClusterCenterModeling + “.kine.local.scl.sclz”, 1)

CopyPaste(muscleMesh + “.MuscleParameters.SecondTendonScale”, null, secondClusterCenterModeling + “.kine.local.scl.sclx”, 1)
CopyPaste(muscleMesh + “.MuscleParameters.SecondTendonScale”, null, secondClusterCenterModeling + “.kine.local.scl.scly”, 1)
CopyPaste(muscleMesh + “.MuscleParameters.SecondTendonScale”, null, secondClusterCenterModeling + “.kine.local.scl.sclz”, 1)

CopyPaste(muscleMesh + “.MuscleParameters.BellyScale”, null, middleClusterCenterModeling + “.kine.local.scl.sclx”, 1)
CopyPaste(muscleMesh + “.MuscleParameters.BellyScale”, null, middleClusterCenterModeling + “.kine.local.scl.scly”, 1)
CopyPaste(muscleMesh + “.MuscleParameters.BellyScale”, null, middleClusterCenterModeling + “.kine.local.scl.sclz”, 1)

//rename muscle parts for convenience
SetValue(muscleMesh + “.Name”, “muscle”, null)

SetValue(firstClusterCenter + “.Name”, “firstTendonAnimation”, null)
SetValue(secondClusterCenter + “.Name”, “secondTendonAnimation”, null)
SetValue(middleClusterCenter + “.Name”, “muscleBellyAnimation”, null)

SetValue(firstClusterCenterModeling + “.Name”, “firstTendonModeling”, null)
SetValue(secondClusterCenterModeling + “.Name”, “secondTendonModeling”, null)
SetValue(middleClusterCenterModeling + “.Name”, “muscleBellyModeling”, null)

SetUserPref("SI3D_CONSTRAINT_COMPENSATION_MODE", consMode)

//add shader
ApplyShader("$XSI_DSPRESETS\\Shaders\\Material\\Blinn.Preset", “”, null, “”, siLetLocalMaterialsOverlap)
SetValue(NULL".Material.Blinn.diffuse.red", 0.545, null)
SetValue(NULL".Material.Blinn.diffuse.green", 0, null)
SetValue(NULL".Material.Blinn.diffuse.blue", 0, null)

//end of script
DeselectAll()
}

[\code]

Author: SamBilling

Replied: 09 November 2009 06:18 AM  
avatar

oSphere Dictionary.GetObject( "Sphere" )

// Loop over all shaders for the material
oEnum = new Enumerator( oSphere.Material.Shaders ) ;
for 
(!oEnum.atEnd()oEnum.moveNext() )
{
 
var oSelItem oEnum.item() ;
 
LogMessage( oSelItem.fullname )
}


// Get the Surface shader
oSurfaceShader oSphere.Material.Parameters("Surface").Source;
LogMessage( oSurfaceShader " : " classname(oSurfaceShader) )

See Scripting Shaders on xsi-blog.



Replies: 0
avatar

Ok, I got it. I moved the whole:

//add shader
 
ApplyShader("$XSI_DSPRESETS\\Shaders\\Material\\Blinn.Preset"""null""siLetLocalMaterialsOverlap)
 SetValue(muscleMesh 
".Material.Blinn.diffuse.green"0null)
 SetValue(muscleMesh 
".Material.Blinn.diffuse.blue"0null)
 SetValue(muscleMesh 
".Material.Blinn.diffuse.red"0.545null)


before the renaming:

CopyPaste(muscleMesh ".MuscleParameters.BellyScale"nullmiddleClusterCenterModeling ".kine.local.scl.sclz"1)

 
//add shader
 
ApplyShader("$XSI_DSPRESETS\\Shaders\\Material\\Blinn.Preset"""null""siLetLocalMaterialsOverlap)
 SetValue(muscleMesh 
".Material.Blinn.diffuse.green"0null)
 SetValue(muscleMesh 
".Material.Blinn.diffuse.blue"0null)
 SetValue(muscleMesh 
".Material.Blinn.diffuse.red"0.545null)
 

 
//rename muscle parts for convenience 
 
SetValue(muscleMesh ".Name""muscle"null)


Replies: 0




   
  Settings Choose Theme color: