Difference between revisions of "Python"

From cgwiki
Line 12: Line 12:
 
</code>
 
</code>
  
---++ Set decay region on spotlights, move each light back 200 units on its own axis
+
== Set decay region on spotlights, move each light back 200 units on its own axis==
 
Was doing a searchlights style shot, the vray volume fog went crazy at the base of the lights. figured it was cos it was crazy high intensity at a single point, so if i could use the light decay region to offset the light intensity away from its center, then offset the translation of the light to compensate, it'd help. It did. :)
 
Was doing a searchlights style shot, the vray volume fog went crazy at the base of the lights. figured it was cos it was crazy high intensity at a single point, so if i could use the light decay region to offset the light intensity away from its center, then offset the translation of the light to compensate, it'd help. It did. :)

Revision as of 00:19, 26 February 2014

Realised I haven't updated this page in ages, and I've written loads of little python scripts in the iterim. I'm a total convert to pymel, I suggest you all do the same. As such, I'll make this a dumping ground of little scripts I write as I go, just so I have a place to find them, and examples are always a handy way to learn.

Random scale/rotate of lots of trees

I'd instance-duplicated out a bunch of vray proxy trees, needed a little randomising. This set of 3 list comprehensions gives a random rotation in y between 0 and 360, a random y scale between 0.8 and 1.2, and shuffles their translation 15 units in x and z.

from pymel.core import * import random [ x.rotate.set( 0, random.randrange(0,360),0) for x in ls(selection=True) ] [ x.scale.set( 1, random.uniform(0.8,1.2) ,1) for x in ls(selection=True) ] [ x.translate.set( x.translate.get() + (random.randrange(-15,15),0,random.randrange(-15,15) )) for x in ls(selection=True) ]

Set decay region on spotlights, move each light back 200 units on its own axis

Was doing a searchlights style shot, the vray volume fog went crazy at the base of the lights. figured it was cos it was crazy high intensity at a single point, so if i could use the light decay region to offset the light intensity away from its center, then offset the translation of the light to compensate, it'd help. It did. :)