PDA

View Full Version : modifying / adding-destroying rollouts?


osanzpont
02-12-2009, 09:06 PM
hello there,

I'm coding a script to have a custom shader to export to my game and there's something I need to do but can't.

what I want is to be able to hide/show rollouts based on a dropdown box selection. I need to have different parameters depending on the shader type (very much like what happens if you change from Blinn to anything else in the shader type)
the problem is that since it's a material plugin it only expects Plugin clauses which prevents me from using if/else or addRollout/removeRollout to get this done.

I'm basing my script on this tutorial:
http://www.cgcookie.com/articles/2008/11/22/custom-scripted-shader-in-3d-studio-max

here's the code of the script:
---------------------------------------------------------
-- Plugin declaration
plugin material Elium_Material
name: "Elium Material"
classID:#(0x82b4cdc2, 0x4f77873e)
extends:Standard replaceUI:true
(

-- Interface design params
parameters main rollout:params
(
-- Parameters definition and interface linking
Shadertype type:#integer default:1 ui:eshad

-- Interface action management
--on Shadertype selected i do delegate.filterMap.name = eshad.items[i]
on Shadertype set i do delegate.filterMap.name = i as string
)

parameters main2 rollout:shaderparams
(
-- Parameters definition and interface linking
Color_Dif type:#color default:[128,128,128] ui:col_dif
Color_Amb type:#color default:[0,0,0] ui:col_amb

-- Interface action management
on Color_Dif set val do delegate.diffuse = val
on Color_Amb set val do delegate.selfIllumColor = val
)
-- Rollout and buttons definition
rollout params "Elium Material"
(
group "General Settings"
(
dropdownlist eshad "Shader" items:#("static", "static_spec", "tree") width:150
)
)

rollout shaderparams "Shader Parameters"
(
group "Shader Parameters"
(
colorpicker col_dif "Diffuse Color:" align:#left offset:[0,0] visible:true
colorpicker col_amb "Ambient Color:" align:#left offset:[0,0] enabled:true
)
)
-- Shader creation in the material editor
on create do
(
-- Shader type definition and parameters
delegate.useSelfIllumColor = true
delegate.filterMap = BitMapTexture()
delegate.filterMap.name = "name"
)

)

thanks!

ZeBoxx2
02-12-2009, 09:28 PM
you might be able to use subRollouts? can't say I've tried, but that should give you a control in which you can add/remove other rollouts. Won't fit exactly with the rest of the medit UI and workflow, but...

Otherwise, maybe you can just collapse/expand the rollouts as required and/or disable/enable the controls within (for c in <rollout>.controls do ( c.enabled = <boolean> -- make sure you don't enable controls that shouldn't be ))

Edit: sample code for the former... (ick)

global currentElium = undefined

rollout roll_test "test" (
label lbl_test "test"
button btn_test "press me to get current elium"
on btn_test pressed do (
if (currentElium != undefined) do (
lbl_test.text = currentElium as string
)
)
)

plugin material Elium_Material
name: "Elium Material"
classID:#(0x82b4cdc2, 0x4f77873e)
extends:Standard replaceUI:true
(

parameters main rollout:params
(

)

rollout params "Elium Material"
(
checkbutton ckb_showroll "show rollout"
subrollout sub_rollouts "sub_rollouts" height:300

on params open do ( currentElium = this )
on params reload do ( currentElium = this )

on ckb_showroll changed state do (
if (state) then (
addSubRollout sub_rollouts roll_test
)
else (
removeSubRollout sub_rollouts roll_test
)
)
)
)


Edit2: And the latter

plugin material Elium_Material
name: "Elium Material"
classID:#(0x82b4cdc2, 0x4f77873e)
extends:Standard replaceUI:true
(

parameters main rollout:params
(

)

rollout params "Elium Material"
(
checkbutton ckb_showroll "show rollout"


on ckb_showroll changed state do (
if (state) then (
this.roll_test.height = 300
this.roll_test.title = "Some other parameters"
this.roll_test.open = true
)
else (
this.roll_test.open = false
this.roll_test.title = "-- disabled --"
this.roll_test.height = 0
)
)
)
rollout roll_test "-- disabled --" rolledup:true height:0 (
label lbl_tadaa "ta-daaaaaa"

on roll_test rolledup state do (
if ((state) AND (roll_test.title == "-- disabled --")) then (
roll_test.open = false
)
)
)
)

osanzpont
02-12-2009, 10:15 PM
hey thanks for the fast reply!

I tried the former but it didn't work because "parameters main2" requires that the rollout on which it will operate, already exists
so I tried the latter and that one did work. however instead of creating multiple rollouts and disabling them (and end up having 20 disabled rollouts) what I'm doing is have a single rollout and just edit the controls inside them, by enabling/disabling or hiding/showing those parameters

so in the end it really is exactly what I wanted, a different set of parameters based on the selection of the shader type rollout :)
thanks for your help, you really solved it

ZeBoxx2
02-12-2009, 11:07 PM
cool - glad to be of assistance :)

as for the first one - correct.. that's why in the example it's a rollout defined outside of the scope of the scripted plugin. As a result, that rollout doesn't know what plugin instance it is used in, so there's a global variable that gets assigned the plugin instance, and that global variable is then referenced within that rollout. It's pretty messy :)

CGTalk Moderation
02-12-2009, 11:07 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.