[Closed] Assign Renderer depending on kind of Material used in scene [SOLVED]
Hello Guys !
I need a little help with a script which will assign the right Renderer according to the materials used in the scene.
Here’s what I have so far :
mats = for m in scenematerials collect m
for i= 1 to 24 do (
if mats[i] != undefined then meditMaterials[i] = mats[i]
)
for m in scenematerials do (
if ((matchPattern (isKindOf m as string) pattern:“VRay*”))== true then renderers.current = Vray()
if ((matchPattern (isKindOf m as string) pattern:“Corona*”))== true then renderers.current = CoronaRenderer()
)
Thank you for helping
(
mats = for m in scenematerials collect m
stopLoop = false
for m in scenematerials while stopLoop== false do
(
matStr = m as string
if ((matchPattern matStr pattern:"VRay*")) == true do
(
renderers.current = Vray()
stopLoop = true
)
if ((matchPattern matStr pattern:"Corona*")) == true do
(
renderers.current = CoronaRenderer()
stopLoop = true
)
if ((matchPattern matStr pattern:"Standard*")) == true do
(
renderers.current = Default_Scanline_Renderer()
stopLoop = true
)
)
)
Hello miauu !
Thank you for the hint but unfortunately it doesn’t work, the renderer doesn’t change
I think you’re missing the “isKindOf” part.
It works for me. When I set the rendererr to MentalRay and there are only standard materials in the scene the script change the rendere to Scanline and there is no need of “isKindOf”.
What is your 3ds max version and are you sure that “Vray()” and “CoronaRenderer()” are the proper commands to set set the renderer to Vray or Corona?
I’m using Max 2016, Vray 3.6 and Corona 1.7.
Yes I’m sure, I just tested those commands in the console :
renderers.current = Vray()
renderers.current = CoronaRenderer()
They do their job. It sounds weird that it works for you.
To make things clear, I’d like the script to list the materials in the Mat Editor, and if (at least) one of them is Vray material, it assigns Vray as the scene renderer ( for example).
EDIT : I found the solution and now your script works fine, we needed this :
matStr = (classof m) as string
However there is another issue now, it’s about going through Multimaterial and Multi/Sub-object Materials.
Do you have an idea to solve this ?
You can also iterate over all scene materials (not only applied)
for material_class in material.classes where material_class.Creatable do
(
local mtls = getClassInstances material_class
local renderer_is_set = false
if mtls.count > 0 do
(
category = material_class.category
case of
(
(category == #Corona): ( renderers.current = CoronaRenderer(); renderer_is_set = true )
(category == #mental_ray): ( renderers.current = mental_ray_renderer(); renderer_is_set = true )
(category == #standard and matchpattern (material_class as string) pattern:"VRay*") : ( renderers.current = Vray(); renderer_is_set = true )
)
)
if renderer_is_set do exit
)
Well I didn’t think I could do it, but I did
Here it is :
mats = for m in scenematerials collect m
for i= 1 to 24 do (
if mats[i] != undefined then meditMaterials[i] = mats[i]
)
(
mats = for m in scenematerials collect m
stopLoop = false
for m in scenematerials while stopLoop== false do
(
matStr = (classof m) as string
if ((matchPattern matStr pattern:"Multi*")) == true do
(
-- This is a multi-sub material, so loop through all submaterials
for j in m.materialList while stopLoop== false do
(
submatStr = (classof j) as string
if ((matchPattern submatStr pattern:"VRay*")) == true do
(
renderers.current = Vray()
stopLoop = true
)
if ((matchPattern submatStr pattern:"Corona*")) == true do
(
renderers.current = CoronaRenderer()
stopLoop = true
)
if ((matchPattern submatStr pattern:"Standard*")) == true do
(
renderers.current = Default_Scanline_Renderer()
stopLoop = true
)
)
)
if ((matchPattern matStr pattern:"VRay*")) == true do
(
renderers.current = Vray()
stopLoop = true
)
if ((matchPattern matStr pattern:"Corona*")) == true do
(
renderers.current = CoronaRenderer()
stopLoop = true
)
if ((matchPattern matStr pattern:"Standard*")) == true do
(
renderers.current = Default_Scanline_Renderer()
stopLoop = true
)
)
)
Thank you guys !