Notifications
Clear all

[Closed] Scripted Material Rollouts

Hi,

I wrote a Scripted Material plugin (extending the standard Material) with 3 rollouts

Works fine, but it doesn’t remember the rolled state when closing/opening the Material editor, or when I go to aother slot and back. Other rollouts do (Mental Ray, or Direct X rollouts)

is there anything I should declare to enable remembering the rolledup state of rollouts in the material editor ?

Here’s a sample code to try:

plugin Material MyMaterial
name:"MyMaterial"
classID:#(0x3437e730, 0x2664411e)
extends:standard
replaceUI:true
version:1
(
rollout Diffuse_Rollout "Color"
(
colorPicker cp1
)
 
rollout Spec_Rollout "Specular"
(
colorPicker cp1
)
 
rollout Bump_Rollout "Specular" width:312 height:72
(
checkbox ckb1 "" pos:[13,7] width:10
label lbl1 "Bump.............................." pos:[32,8]
mapButton map1 "" pos:[150,7] width:160 height:18
)
 
parameters Diffuse_Params rollout:Diffuse_Rollout
(
DiffuseColor type:#color ui:cp1
on DiffuseColor set val do delegate.Diffuse=val
)
 
parameters Spec_Params rollout:Spec_Rollout
(
SpecColor type:#color ui:cp1
on SpecColor set val do delegate.Specular=val
)
 
parameters Bump_Params rollout:Bump_Rollout
(
BumpMapOn type:#boolean ui:ckb1
BumpMap type:#TextureMap ui:map1
 
on BumpMapOn set val do delegate.bumpMapEnable=val
on BumpMap set map do
(
delegate.BumpMap=map
Bump_Rollout.ckb1.state=delegate.bumpMapEnable = if map != undefined then true else false
)
)
)
6 Replies

mmm… there’s gotta be better ways (I swear I saw a rollout ‘flags’ thing somewhere sometime in the past*), but this is one flexible way…

  • Edit: Found it – initialRollupState:<flags> ; but it doesn’t look like that actually applies here.

 plugin Material MyMaterial
 	name:"MyMaterial"
 	classID:#(0x3437e730, 0x2664411e)
 	extends:standard
 	replaceUI:true
 	version:1 (
 	local rollupState = false
 	rollout Diffuse_Rollout "Color" (
 		colorPicker cp1
 		
 		on Diffuse_Rollout open do (
 			Diffuse_Rollout.open = rollupState
 		)
 		on Diffuse_Rollout rolledup state do (
 			rollupState = state
 		)
 	)
 
 	parameters main rollout:Diffuse_Rollout ( )
 )
 

That rollupState variable is pretty important. You use it to set the initial state with the true/false value – it then gets used -per material- for the open/closed state for -that material’s- rollout open/close state.
If you want it more like max’s – where the same materials re-use the same open/closed states for rollouts – make the variables global (or as part of a global struct, at least) instead.
You can’t move the variable into the rollout clause as that gets destroyed when you ‘close’ the plugin (i.e. select a different material).

You’ll want 1 variable for each rollout, or you could track them in an array/a bitarray.

Thanks a lot Richard, works fine

Another question that puzzles me, how to setup a Point3 parameter to be linked to 3 spinners ?

 plugin Material MyMaterial
  name:"MyMaterial"
  classID:#(0x3437e730, 0x2664411e)
  extends:standard
  replaceUI:true
  version:1 (
  rollout Diffuse_Rollout "Color" 
  (
   spinner spn1 "X" range:[-999999,999999,0]
   spinner spn2 "Y" range:[-999999,999999,0]
   spinner spn3 "Z" range:[-999999,999999,0]
   
  )
 
  parameters main rollout:Diffuse_Rollout
 (
  XYZ type:#point3 default:[0,0,0] ui:(spn1,spn2,spn3)
  on XYZ set val do (print val)
 )
 )

i rather doubt you can, but I might be mistaken.

If I’m not, then… you’d either have to use a floatTab (which supports the multiple UI items), and thus use an array to set/get values, or you have to set the parameter value from the UI control’s changed event directly, taking care that in the parameter’s ‘on … set’ event you update the UI if it’s open (so that if somebody sets the value via scripting, and the UI is open, the UI shows the scripted change immediately).

Thx again

I ended up using a floatTab here is the code for anyone interested:

plugin Material MyMaterial
name:"MyMaterial"
classID:#(0x3437e730, 0x2664411e)
extends:standard
replaceUI:true
version:1 (
rollout Diffuse_Rollout "Color"
(
spinner spn1 "X" range:[-999999,999999,0]
spinner spn2 "Y" range:[-999999,999999,0]
spinner spn3 "Z" range:[-999999,999999,0]
)
parameters main rollout:Diffuse_Rollout
(
XYZ type:#foatTab Tabsize:3 default:[0,0,0] ui:(spn1,spn2,spn3)
on XYZ set val index do (print [XYZ[1], XYZ[2], XYZ[3]])
)
)


boxsize		type:#point3


size type:#float  ui:amount default:40.0

on size set val do ( boxsize = [val, val, val] )

ect...

hope it helps

edit: ohkay didn’t read the last post ^^ :shrug:
but still an example for not using floatTabs hehe

just to complete the set, then…

plugin Material MyMaterial name:"MyMaterial" classID:#(0x3437e730, 0x2664411e) extends:standard replaceUI:true version:1 (
	rollout Diffuse_Rollout "Color" (
		spinner spn1 "X" range:[-999999,999999,0]
		spinner spn2 "Y" range:[-999999,999999,0]
		spinner spn3 "Z" range:[-999999,999999,0]

		on spn1 changed val do ( this.xyz.x = val )
		on spn2 changed val do ( this.xyz.y = val )
		on spn3 changed val do ( this.xyz.z = val )

		on Diffuse_Rollout open do (
			spn1.value = this.xyz.x
			spn2.value = this.xyz.y
			spn3.value = this.xyz.z
		)
	)
	parameters main rollout:Diffuse_Rollout (
		XYZ type:#point3 default:[0,0,0]
		on XYZ set val do (
			ui = Diffuse_Rollout
			if (ui.open) then (
				ui.spn1.value = val.x
				ui.spn2.value = val.y
				ui.spn3.value = val.z
			)
		)
	)
)

Note, however, that the Macro Recorder won’t capture the changes made by the user in the UI.