Last active
August 29, 2015 14:12
-
-
Save ruby0x1/6406b194105fdf8374ff to your computer and use it in GitHub Desktop.
modo area light to polygon
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# python | |
import lx | |
import traceback | |
from math import atan2, sqrt, pi | |
# WIP, will tidy when it's done | |
# Modo Area light -> Polygon | |
# https://github.com/underscorediscovery | |
# To install, see the modo docs, but in short: | |
# - System -> Open User Scripts Folder -> copy file into folder | |
# - in the "command panel" (tiny edit field bottom right) type @alp.py and hit enter or assign it to a key/command combo | |
# todo: | |
# - round area lights | |
# - suggestions? | |
#fetch the actual selections | |
items = lx.evalN("query sceneservice selection ? locator") | |
#complain if there are none | |
if not items: | |
lx.eval('dialog.setup style:error') | |
lx.eval('dialog.title "Need lights"') | |
lx.eval('dialog.msg "Please select area lights first before calling the script"') | |
lx.eval('dialog.open') | |
sys.exit() | |
for item in items: | |
#make sure we aren't using the last created selected polylight | |
#by selecting the actual item in the selected list | |
lx.eval('select.item ' + item) | |
pos = lx.evalN('query sceneservice item.worldPos ? ' + item) | |
rot = lx.evalN('query sceneservice item.worldRot ? ' + item) | |
scale = lx.evalN('query sceneservice item.scale ? ' + item) | |
#extract position | |
posx = str(pos[0]) | |
posy = str(pos[1]) | |
posz = str(pos[2]) | |
#extract scale | |
scalex = scale[0] | |
scaley = scale[1] | |
scalez = scale[2] | |
#extract rotation in degrees from the radians | |
xr = str(lx.eval1('item.channel rot.X ?') * (180/pi)) | |
yr = str(lx.eval1('item.channel rot.Y ?') * (180/pi)) | |
zr = str(lx.eval1('item.channel rot.Z ?') * (180/pi)) | |
#extract the area light width height | |
ww = lx.eval1('item.channel areaLight$width ?') | |
hh = lx.eval1('item.channel areaLight$height ?') | |
#account for the scale values by affecting the w and h | |
ww = str(ww * scalex) | |
hh = str(hh * scaley) | |
#create a mesh to contain the polygon | |
lx.eval('item.create mesh') | |
#create a cube polygon with the same size in x/y (local inside the parent item) | |
lx.eval('tool.set prim.cube on') | |
lx.eval('tool.setAttr prim.cube flip true') | |
lx.eval('tool.setAttr prim.cube cenX 0.0') | |
lx.eval('tool.setAttr prim.cube cenY 0.0') | |
lx.eval('tool.setAttr prim.cube cenZ 0.0') | |
lx.eval('tool.setAttr prim.cube sizeX ' + ww) | |
lx.eval('tool.setAttr prim.cube sizeY ' + hh) | |
lx.eval('tool.setAttr prim.cube sizeZ 0.0') | |
lx.eval('tool.doApply') | |
#set the position and rotation to the extracted values | |
#rotation should be first to preserve transform order | |
lx.eval('transform.channel rot.X ' + xr) | |
lx.eval('transform.channel rot.Y ' + yr) | |
lx.eval('transform.channel rot.Z ' + zr) | |
lx.eval('item.setPosition x:'+ posx +' y:'+ posy +' z:'+ posz +' mode:world') | |
#name it for easy finding | |
lx.eval('item.name polylight') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment