73 import manipulatorMath
74 import maya.OpenMaya
as OpenMaya
75 import maya.OpenMayaUI
as OpenMayaUI
76 import maya.OpenMayaMPx
as OpenMayaMPx
77 import maya.OpenMayaRender
as OpenMayaRender
80 contextCmdName =
"spFilmMoveManipCtxCmd"
81 nodeName =
"spFilmMoveManip"
84 class manipulatorGeometry:
86 def horizontalStart(self):
90 def horizontalEnd(self):
94 def verticalStart(self):
98 def verticalEnd(self):
104 class filmMoveManip(OpenMayaMPx.MPxManipulatorNode):
119 glRenderer = OpenMayaRender.MHardwareRenderer.theRenderer()
120 glFT = glRenderer.glFunctionTable()
123 OpenMayaMPx.MPxManipulatorNode.__init__(self)
125 def postConstructor(self):
127 su = OpenMaya.MScriptUtil(0)
129 self.addDoubleValue(
"horizontalValue", 0, iptr )
130 self.horizontalIndex = su.getInt(iptr)
132 sys.stderr.write(
"Failed to add horizontal double value\n")
136 su = OpenMaya.MScriptUtil(0)
138 self.addDoubleValue(
"verticalValue", 0, iptr )
139 self.verticalIndex = su.getInt(iptr)
141 sys.stderr.write(
"Failed to add vertical double value\n")
144 def draw(self,view,dagpath,displayStyle,displayStatus):
147 mo = manipulatorGeometry()
148 vs = mo.verticalStart()
149 ve = mo.verticalEnd()
150 hs = mo.horizontalStart()
151 he = mo.horizontalEnd()
155 self.glFT.glPushMatrix()
156 self.glFT.glTranslated(self.translation.x,self.translation.y,self.translation.z)
159 su = OpenMaya.MScriptUtil(0)
160 iptr = su.asUintPtr()
161 self.glFirstHandle( iptr )
162 startIndex = su.getUint(iptr)
165 self.glHorizontalName = startIndex
166 self.colorAndName( view, self.glHorizontalName,
True, self.mainColor() )
167 self.glFT.glBegin( OpenMayaRender.MGL_LINES )
168 self.glFT.glVertex3d( hs.x, hs.y, hs.z )
169 self.glFT.glVertex3d( he.x, he.y, he.z )
172 self.glVerticalName = self.glHorizontalName + 1
173 self.colorAndName( view, self.glVerticalName,
True, self.mainColor() )
174 self.glFT.glBegin( OpenMayaRender.MGL_LINES )
175 self.glFT.glVertex3d( vs.x, vs.y, vs.z )
176 self.glFT.glVertex3d( ve.x, ve.y, ve.z )
180 self.glFT.glPopMatrix()
183 def doPress(self,view):
185 self.updateDragInformation(view)
187 def doDrag(self,view):
188 self.updateDragInformation(view)
190 def doRelease(self,view):
192 self.updateDragInformation(view,
True)
194 def getPlaneForView(self,view):
195 mo = manipulatorGeometry()
196 vs = mo.verticalStart()
197 ve = mo.verticalEnd()
198 hs = mo.horizontalStart()
199 he = mo.horizontalEnd()
205 plane = manipulatorMath.planeMath()
206 plane.setPlane( vs, normal )
210 def updateDragInformation(self,view,updateAttribute = False):
214 self.mouseRay( localMousePoint, localMouseDirection )
217 plane = self.getPlaneForView( view )
221 (worked,mouseIntersect) = plane.intersect( localMousePoint, localMouseDirection )
223 print "Failed to intersect plane"
227 su = OpenMaya.MScriptUtil(0)
228 uintptr = su.asUintPtr()
229 self.glActiveName( uintptr )
230 active = su.getUint(uintptr)
232 mo = manipulatorGeometry()
236 if active == self.glHorizontalName:
237 start = mo.horizontalStart()
238 end = mo.horizontalEnd()
239 elif active == self.glVerticalName:
240 start = mo.verticalStart()
241 end = mo.verticalEnd()
243 raise "Unknown GL active component"
245 vstart_end = start - end
246 line = manipulatorMath.lineMath()
247 line.setLine( start, vstart_end )
250 (worked,closestPoint) = line.closestPoint( mouseIntersect )
252 print "Failed to find closest point to line"
255 self.translation = closestPoint
259 m = manipulatorMath.maxOfAbsThree(closestPoint.x,closestPoint.y,closestPoint.z)
261 if active == self.glHorizontalName:
262 self.setDoubleValue(self.horizontalIndex,m)
263 elif active == self.glVerticalName:
264 self.setDoubleValue(self.verticalIndex,m)
266 def connectToDependNode(self, node):
270 hPlug = nodeFn.findPlug(
"filmTranslateH")
271 vPlug = nodeFn.findPlug(
"filmTranslateV")
273 su = OpenMaya.MScriptUtil(0)
275 self.connectPlugToValue( hPlug, self.horizontalIndex, iptr )
276 self.connectPlugToValue( vPlug, self.verticalIndex, iptr )
279 self.addDependentPlug(hPlug)
280 self.addDependentPlug(vPlug)
282 sys.stderr.write(
"Error finding and connecting plugs\n" )
286 OpenMayaMPx.MPxManipulatorNode.finishAddingManips(self)
287 OpenMayaMPx.MPxManipulatorNode.connectToDependNode(self,node)
289 sys.stderr.write(
"Error when finishing node connection\n" )
293 def filmMoveManipCreator():
294 return OpenMayaMPx.asMPxPtr( filmMoveManip() )
296 def filmMoveManipInitialize():
297 print "Initializing film move manipulator"
299 class filmMoveManipContext(OpenMayaMPx.MPxSelectionContext):
301 OpenMayaMPx.MPxSelectionContext.__init__(self)
303 def toolOnSetup(self,event):
304 updateManipulators(self)
307 def updateManipulators(clientData):
308 clientData.deleteManipulators()
315 while not selectionIter.isDone():
317 selectionIter.getDependNode(dependNode)
318 if dependNode.isNull()
or not dependNode.hasFn(OpenMaya.MFn.kCamera):
319 print "depend node is null or not a camera"
324 hPlug = dependNodeFn.findPlug(
"filmTranslateH",
False)
325 vPlug = dependNodeFn.findPlug(
"filmTranslateV",
False)
326 if hPlug.isNull()
or vPlug.isNull():
327 print "One of filmTranslate H,V plugs are null"
332 manipulator = OpenMayaMPx.MPxManipulatorNode.newManipulator(nodeName, manipObject)
333 if manipulator
is not None:
335 manipulator.dependentPlugsReset()
337 clientData.addManipulator(manipObject)
338 manipulator.connectToDependNode(dependNode)
342 class filmMoveManipCtxCmd(OpenMayaMPx.MPxContextCommand):
344 OpenMayaMPx.MPxContextCommand.__init__(self)
347 return OpenMayaMPx.asMPxPtr( filmMoveManipContext() )
350 def contextCmdCreator():
351 return OpenMayaMPx.asMPxPtr( filmMoveManipCtxCmd() )
355 def initializePlugin(mobject):
356 mplugin = OpenMayaMPx.MFnPlugin(mobject)
359 mplugin.registerContextCommand( contextCmdName, contextCmdCreator )
361 print "Failed to register context command: %s" % contextCmdName
365 mplugin.registerNode(nodeName, filmMoveManipId, filmMoveManipCreator, filmMoveManipInitialize, OpenMayaMPx.MPxNode.kManipulatorNode)
367 print "Failed to register node: %s" % nodeName
371 def uninitializePlugin(mobject):
372 mplugin = OpenMayaMPx.MFnPlugin(mobject)
374 mplugin.deregisterContextCommand(contextCmdName)
376 print "Failed to deregister context command: %s" % contextCmdName
380 mplugin.deregisterNode(filmMoveManipId)
382 print "Failed to deregister node: %s" % nodeName