[Closed] Material Controlled by Script
Hello,
I am trying to set up a script controller that changes an object’s material based on it’s position. I have a script that basically says:
if x > 0 then $Box001.material = green
Where green is the name of a vray material in my scene. However, when I evaluate this script I get an error that says:
Unable to convert: green:VRayMTL to type: Float
I’m unfortunately not enough of a programmer to figure out how to get this to work, but i feel like the answer is simple. Any help would be greatly appreciated.
Thanks
Just saying
$Box001.material = green
will produce error because you are telling max to assign a material called “green” to a node. Maybe you mean something like <Node>.material.diffuse = green, and of course this supposes that the Node has a material assigned to it that supports the diffuse channel (like StandardMaterial).
Although I dont use vray, there must be something similar to VRayMTL.diffuse…
If you don’t need to use a material you can easily change the wirecolor of your object.
This way you don’t have to deal with a specific renderer material syntax.
if x > 0 then $Box001.wirecolor = green
But with vrayMaterial you can do this :
$Box001.material=VRayMtl() -- first assign a default vrayMtl
if x > 0 then $Box001.material.diffuse=(color 0 255 0)
Thank you Alexandros and Eric, but unfortunately I can’t simply change the color of the mesh or change the color in the diffuse map. Basically what I have is a tree with 6 or 7 material ID’s for the leaves plus the bark. I then have several different materials with variations on those 6 or 7 leaves and bark. I’m looking for a way to assign different materials to these trees to introduce variety. I have the simple script with the “green” material to test if I can get the script to work, but once it does it will get more complicated.
The long term goal is to basically have a tree randomly assign a material to itself so that hundred of these trees can be populated and be assigned a random material (from a list).
Sort of, but the ID’s of the elements of the trees are always the same. The trunk, for example, is always 1. I then have a multisub where 1 is a brown bark, and another where 1 is a grayer bark. Each multisub for each variation of tree has 7 ID’s. I could try to set something up where the ID’s changed, but to get the variations I need, I would need to have a multisub with something like 56 ID’s in it. I’d rather just have several different materials with 7 ID’s each, but if there is a way to set things up so that each material was random along a pattern (say that the trunk would be ID 1, 8, 15, or 22), that would work.
Maybe
Neil Blevins’s :
Can help you
Takes a set of materials and randomly applies them to your current scene selection.
This way you can apply variation on your selection with many materials (within submaterials) and keep face IDs.