Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ### zSlider 1.1 by heyw ###
- ###changes ####
- ### Updated to use matrix world space coordinates. This allows the script to work on parented or animated cameras.
- ### 1.1 ppdateby Mars ####
- # Usage:
- # 1. Use the following python command to load the script or add it to your userSetup.py and restart maya
- # import zSlider
- # 2. In the Hotkey Editor create 2 Runtime Commands with the start/stop
- # functions(the language should be set to python):
- # zSlider.start()
- # and
- # zSlider.stop()
- # set the entry with 'zSliderStop()' to 'On Release'
- # Assign both commands to the same key.
- # 3. Press and hold the hotkey while moving the mouse left to right to slide the
- # current selection towards/away from the camera.
- # 4. The start has function 3 optional flags, these are the default values
- # zSlider.start(slideMode=0, slideSpeed=1000, doScaling=0)
- # slideMode=0
- # the selection slides linearly with the amount of mouse movement
- # slideMode=1
- # the sliding has an exponential feel, as objects get closer they slide
- # slower, further they slide faster
- # 'slideSpeed' is the how many pixels the mouse must move to slide the selection
- # a given distance, larger values = slower sliding.
- # doScaling=0
- # scaling is disabled
- # doScaling=1
- # the object is scaled in proportion to the distance it's moved. The result is the
- # object maintains its apparent size from the camera's perspective as it slides.
- # These can be used to assign multiple hotkeys with different behavior. ie. for general use
- # assigning the 'a' key with:
- # zSlider.start(slideSpeed=500)
- # then for fine tuning assigning shift+a with:
- # zSlider.start(slideSpeed=4000)
- # IMPORTANT: If the tool gets stuck on use the following mel command to kill all script jobs:
- # scriptJob -ka;
- import maya.cmds as cmds
- import maya.mel as mel
- from ctypes import windll, Structure, c_long, byref
- class POINT(Structure):
- _fields_ = [("x", c_long), ("y", c_long)]
- def getCursorPos():
- pt = POINT()
- windll.user32.GetCursorPos(byref(pt))
- return([pt.x,pt.y])
- def start(slideMode=0, slideSpeed=8000, doScaling=0):
- # Find camera and get ws position
- panel = cmds.getPanel(underPointer=True)
- if panel not in cmds.getPanel(type='modelPanel'):
- print('model panel not found')
- return
- cam = cmds.modelPanel(panel,q=True,cam=True)
- camPos = cmds.getAttr(cam+'.worldMatrix')
- # Store current offset for selected objects
- sel = cmds.ls(sl=True)
- selOffsets = []
- for item in sel:
- pos = cmds.getAttr(item+'.worldMatrix')
- scale = cmds.xform(item,q=True,s=True,r=True)
- selOffsets.append([pos[12]-camPos[12],pos[13]-camPos[13],pos[14]-camPos[14], scale[0],scale[1],scale[2]])
- print selOffsets
- mouseX = getCursorPos()[0]
- cmds.undoInfo(openChunk=True)
- job = cmds.scriptJob(ie=('tick('+str(mouseX)+', '+str(camPos)+', '+str(map(lambda x: str(x), sel))+', '+str(selOffsets)+', '+str(slideMode)+', '+str(float(slideSpeed))+', '+str(doScaling)+')'));
- mel.eval('global int $zSliderJob='+str(job))
- def stop():
- job = mel.eval('$tempMelVar=$zSliderJob')
- cmds.scriptJob(kill=job)
- cmds.undoInfo(closeChunk=True)
- def tick(mouseX, camPos, sel, offsets, mode, speed, doScaling):
- slideMode = 0
- s = 1+((mouseX-getCursorPos()[0])/speed)
- if slideMode is 0: f = s
- if slideMode is 1: f = 1/s
- for x, offset in enumerate(offsets):
- newPos = [f*offset[0]+camPos[12],f*offset[1]+camPos[13],f*offset[2]+camPos[14]]
- newScale = [s*offset[3],s*offset[4],s*offset[5]]
- cmds.move(newPos[0],newPos[1],newPos[2], sel[x],ws=True,spr=True)
- if doScaling:
- cmds.scale(newScale[0],newScale[1],newScale[2], sel[x])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement