1 from __future__
import division
73 from builtins
import object
74 from builtins
import next
76 import manipulatorMath
77 import maya.OpenMaya
as OpenMaya
78 import maya.OpenMayaUI
as OpenMayaUI
79 import maya.OpenMayaMPx
as OpenMayaMPx
80 import maya.OpenMayaRender
as OpenMayaRender
83 contextCmdName =
"spFilmMoveManipCtxCmd"
84 nodeName =
"spFilmMoveManip"
87 class manipulatorGeometry(object):
89 def horizontalStart(self):
93 def horizontalEnd(self):
97 def verticalStart(self):
101 def verticalEnd(self):
107 class filmMoveManip(OpenMayaMPx.MPxManipulatorNode):
122 glRenderer = OpenMayaRender.MHardwareRenderer.theRenderer()
123 glFT = glRenderer.glFunctionTable()
126 OpenMayaMPx.MPxManipulatorNode.__init__(self)
128 def postConstructor(self):
130 su = OpenMaya.MScriptUtil(0)
132 self.addDoubleValue(
"horizontalValue", 0, iptr )
133 self.horizontalIndex = su.getInt(iptr)
135 sys.stderr.write(
"Failed to add horizontal double value\n")
139 su = OpenMaya.MScriptUtil(0)
141 self.addDoubleValue(
"verticalValue", 0, iptr )
142 self.verticalIndex = su.getInt(iptr)
144 sys.stderr.write(
"Failed to add vertical double value\n")
147 def draw(self,view,dagpath,displayStyle,displayStatus):
150 mo = manipulatorGeometry()
151 vs = mo.verticalStart()
152 ve = mo.verticalEnd()
153 hs = mo.horizontalStart()
154 he = mo.horizontalEnd()
158 self.glFT.glPushMatrix()
159 self.glFT.glTranslated(self.translation.x,self.translation.y,self.translation.z)
162 su = OpenMaya.MScriptUtil(0)
163 iptr = su.asUintPtr()
164 self.glFirstHandle( iptr )
165 startIndex = su.getUint(iptr)
168 self.glHorizontalName = startIndex
169 self.colorAndName( view, self.glHorizontalName,
True, self.mainColor() )
170 self.glFT.glBegin( OpenMayaRender.MGL_LINES )
171 self.glFT.glVertex3d( hs.x, hs.y, hs.z )
172 self.glFT.glVertex3d( he.x, he.y, he.z )
175 self.glVerticalName = self.glHorizontalName + 1
176 self.colorAndName( view, self.glVerticalName,
True, self.mainColor() )
177 self.glFT.glBegin( OpenMayaRender.MGL_LINES )
178 self.glFT.glVertex3d( vs.x, vs.y, vs.z )
179 self.glFT.glVertex3d( ve.x, ve.y, ve.z )
183 self.glFT.glPopMatrix()
186 def doPress(self,view):
188 self.updateDragInformation(view)
190 def doDrag(self,view):
191 self.updateDragInformation(view)
193 def doRelease(self,view):
195 self.updateDragInformation(view,
True)
197 def getPlaneForView(self,view):
198 mo = manipulatorGeometry()
199 vs = mo.verticalStart()
200 ve = mo.verticalEnd()
201 hs = mo.horizontalStart()
202 he = mo.horizontalEnd()
208 plane = manipulatorMath.planeMath()
209 plane.setPlane( vs, normal )
213 def updateDragInformation(self,view,updateAttribute = False):
217 self.mouseRay( localMousePoint, localMouseDirection )
220 plane = self.getPlaneForView( view )
224 (worked,mouseIntersect) = plane.intersect( localMousePoint, localMouseDirection )
226 print(
"Failed to intersect plane")
230 su = OpenMaya.MScriptUtil(0)
231 uintptr = su.asUintPtr()
232 self.glActiveName( uintptr )
233 active = su.getUint(uintptr)
235 mo = manipulatorGeometry()
239 if active == self.glHorizontalName:
240 start = mo.horizontalStart()
241 end = mo.horizontalEnd()
242 elif active == self.glVerticalName:
243 start = mo.verticalStart()
244 end = mo.verticalEnd()
246 raise "Unknown GL active component"
248 vstart_end = start - end
249 line = manipulatorMath.lineMath()
250 line.setLine( start, vstart_end )
253 (worked,closestPoint) = line.closestPoint( mouseIntersect )
255 print(
"Failed to find closest point to line")
258 self.translation = closestPoint
262 m = manipulatorMath.maxOfAbsThree(closestPoint.x,closestPoint.y,closestPoint.z)
264 if active == self.glHorizontalName:
265 self.setDoubleValue(self.horizontalIndex,m)
266 elif active == self.glVerticalName:
267 self.setDoubleValue(self.verticalIndex,m)
269 def connectToDependNode(self, node):
273 hPlug = nodeFn.findPlug(
"filmTranslateH")
274 vPlug = nodeFn.findPlug(
"filmTranslateV")
276 su = OpenMaya.MScriptUtil(0)
278 self.connectPlugToValue( hPlug, self.horizontalIndex, iptr )
279 self.connectPlugToValue( vPlug, self.verticalIndex, iptr )
282 self.addDependentPlug(hPlug)
283 self.addDependentPlug(vPlug)
285 sys.stderr.write(
"Error finding and connecting plugs\n" )
289 OpenMayaMPx.MPxManipulatorNode.finishAddingManips(self)
290 OpenMayaMPx.MPxManipulatorNode.connectToDependNode(self,node)
292 sys.stderr.write(
"Error when finishing node connection\n" )
296 def filmMoveManipCreator():
297 return OpenMayaMPx.asMPxPtr( filmMoveManip() )
299 def filmMoveManipInitialize():
300 print(
"Initializing film move manipulator")
302 class filmMoveManipContext(OpenMayaMPx.MPxSelectionContext):
304 OpenMayaMPx.MPxSelectionContext.__init__(self)
306 def toolOnSetup(self,event):
307 updateManipulators(self)
310 def updateManipulators(clientData):
311 clientData.deleteManipulators()
318 while not selectionIter.isDone():
320 selectionIter.getDependNode(dependNode)
321 if dependNode.isNull()
or not dependNode.hasFn(OpenMaya.MFn.kCamera):
322 print(
"depend node is null or not a camera")
327 hPlug = dependNodeFn.findPlug(
"filmTranslateH",
False)
328 vPlug = dependNodeFn.findPlug(
"filmTranslateV",
False)
329 if hPlug.isNull()
or vPlug.isNull():
330 print(
"One of filmTranslate H,V plugs are null")
335 manipulator = OpenMayaMPx.MPxManipulatorNode.newManipulator(nodeName, manipObject)
336 if manipulator
is not None:
338 manipulator.dependentPlugsReset()
340 clientData.addManipulator(manipObject)
341 manipulator.connectToDependNode(dependNode)
345 class filmMoveManipCtxCmd(OpenMayaMPx.MPxContextCommand):
347 OpenMayaMPx.MPxContextCommand.__init__(self)
350 return OpenMayaMPx.asMPxPtr( filmMoveManipContext() )
353 def contextCmdCreator():
354 return OpenMayaMPx.asMPxPtr( filmMoveManipCtxCmd() )
358 def initializePlugin(mobject):
359 mplugin = OpenMayaMPx.MFnPlugin(mobject)
362 mplugin.registerContextCommand( contextCmdName, contextCmdCreator )
364 print(
"Failed to register context command: %s" % contextCmdName)
368 mplugin.registerNode(nodeName, filmMoveManipId, filmMoveManipCreator, filmMoveManipInitialize, OpenMayaMPx.MPxNode.kManipulatorNode)
370 print(
"Failed to register node: %s" % nodeName)
374 def uninitializePlugin(mobject):
375 mplugin = OpenMayaMPx.MFnPlugin(mobject)
377 mplugin.deregisterContextCommand(contextCmdName)
379 print(
"Failed to deregister context command: %s" % contextCmdName)
383 mplugin.deregisterNode(filmMoveManipId)
385 print(
"Failed to deregister node: %s" % nodeName)