ScriptSpot

Forum topic · General Scripting

Instance a Material to slot?

By JokerMartini · 2011-01-08

Description

If the checkbox for display in material editor is checked True how do I make it an instance of the Material placed in the Material Override for Vray?


--http://vray.us/vray_documentation/index.shtml
-- renderers.current.adaptiveSubdivision_maxRate = 10

rollout rlAORender "AO Render"
(
local VDirt = undefined

groupbox gpbxVrayDirt "VRay Dirt Parameters" width:150 height:100 pos:[5,2]
label lbVDRadius "Radius:" pos:[12,20]
spinner spnVDRadius "" fieldwidth:45 range:[0,9999999,10] type:#worldunits pos:[92,20]
label lbVDDistribution "Distribution:" pos:[12,40]
spinner spnVDDistribution "" fieldwidth:45 range:[0,9999999,1.5] type:#float pos:[92,40]
label lbVDFallOff "FallOff:" pos:[12,60]
spinner spnVDFallOff "" fieldwidth:45 range:[0,9999999,1] type:#float pos:[92,60]
label lbVDSubdivisions "Subdivisions:" pos:[12,80]
spinner spnVDSubdivisions "" fieldwidth:45 range:[1,1000,24] type:#float pos:[92,80]
groupbox gpbxSelType "" width:150 height:30 pos:[5,95]
radiobuttons rbtnType labels:#("Override Mtl", "Shader") columns:2 default:1 pos:[9,106]
groupbox gpbxDisplay "" width:150 height:30 pos:[5,118]
checkbox ckbxDisplay "Display in Material Editor" pos:[10,129] checked:false enabled:true
button btnApply "Apply" width:150 height:24 pos:[5,154]

fn AOShaderCreation =
(
VDirt = StandardMaterial()
VDirt.name = "AO-VRayDirt"
VDirt.Selfillumination = 100
VDirt.diffuseMap = VRayDirt radius:(spnVDRadius.value) distribution:(spnVDDistribution.value) falloff:(spnVDFallOff.value) subdivs:(spnVDSubdivisions.value)
if ckbxDisplay.checked == true do meditmaterials[1] = VDirt
)

on rbtnType changed state do
(

case rbtnType.state of
(
1: -- Material Override
(
ckbxDisplay.enabled = true
)
2: -- Shader Option
(
ckbxDisplay.checked = true
ckbxDisplay.enabled = false
)
)
)
on btnApply pressed do
(
case rbtnType.state of
(
1:
(
Print "Override Mtl"
VR = renderers.current = VRay()
AOShaderCreation()
VR.options_overrideMtl_on = true
VR.options_overrideMtl_mtl = VDirt
)

2: -- Shader Option
(
Print "Shader"
AOShaderCreation()
)
)
)
)
createDialog rlAORender 160 184

Comments (4)

You're welcome. Shorter version:

Garp · 2011-01-13


try meditMaterials[1]=renderers.current.options_overrideMtl_mtl catch()

Garp

JokerMartini · 2011-01-13

Hey Garp thanks for the help!

Something like this?

Garp · 2011-01-12

(
    local rend = renderers.current
    
    if subString (classOf rend as string) 1 5 == "V_Ray" AND
    rend.options_overrideMtl_on AND
    (local mtl = rend.options_overrideMtl_mtl) != undefined do
        meditMaterials[1] = mtl
)

Instance

JokerMartini · 2011-01-12

How do I instance a material from the Material Override slot in the render settings dialog to the material editor slot 1?