Revisiting the Past, Again


Last night while working on an assignment I came across a problem. I needed to make a shelf full of books that were all different colors but I didn’t want to sit there and make a bunch of different colored materials. Not only would it be a waste of time, but it would also clutter my hypershade window. Now, as many of my readers know I made a script awhile back that pretty much addresses this problem for me. It creates random colored materials within a given range and applies them to the selected objects. It even was so kind as to put the materials into a single bin for you. But when I went to go use my trusty MEL script I realized it could be made better.

So I sat down (ok, I admit, I was already sitting) and started work on a new script, Randomizer V2. The first, and largest change to the script I made was not reusing anything at all from the old one. In fact, I didn’t even use the same scripting language. No, for this version I decided to bust out my Python skills. I didn’t just do this for fun, however. Python is a more robust language and is easier to work with (in my opinion). It’s also more widely used, especially considering it’s not proprietary to one program like MEL is. This means there is more reference available and there are more people who I would be able to turn to for help, should I have needed any.

I also made another pretty drastic change to the functionality of the script. Instead of having it create a new material for every object, the script now creates one material and changes the value per-object using single switch nodes. Each object is given an extra attribute (or multiple, depending on whether or not multiple material attributes are randomized) set to a random value that is plugged into the V coordinate of  a ramp node. There is one ramp node for every attribute of the material that is to be randomized. This allows the user to go back and change the randomization to suit their needs at any time. It also means that the randomization ratio can be adjusted. Want randomization between two colors with a 75% bias towards one of them? Or maybe you want to randomize between file textures? Or how about random animated textures? Thanks to ramps, it’s all completely possible and easy! And if you want to tweak the material for a single object you can simply edit the extra attributes to your liking (they can be animated, too)!

Using the script is very simple. Simply select your desired objects, check the attributes you’d like to be randomized, enter a material name and type, and press the big “Color my world!” button. After that you can edit the ramp nodes that are feeding into your shader as well as the extra attributes (“Color Coord,” “Transparency Coord,” and “Specular Color Coord”) to change how the material behaves.

Download the script here.

If you encounter any errors or would like to give suggestions/feedback feel free to let me know!

Revisiting the Past, Again

Python and Fractals


Slowly but surely I have been learning more of the programmatic side of computing. First was the extreme basics with HTML and CSS, next came MEL, and now I have reached Python. I have attempted to learn Python a few times in the past but a combination of heavy schedules and lack of commitment caused those attempts to fail quickly. But not this time. I am making noticeable progress and even have work to show for it.

Continue reading “Python and Fractals”

Python and Fractals