Skip to content

Commit

Permalink
Merge pull request #5 from yamahigashi/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
yamahigashi authored Feb 27, 2018
2 parents 6a78a6a + 5659d65 commit 386946f
Showing 1 changed file with 32 additions and 19 deletions.
51 changes: 32 additions & 19 deletions plug-ins/sceneRenderOverride.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ def __init__(self, name):
def _initializeTemporalyVariables(self):
# type: () -> None

self.hiColor = om.MColor(om.MVector(1, 1, 0))

self.xcolor = om.MColor(om.MVector(1, 0, 0))
self.xmat = om.MMatrix((
(1, 0, 0, 0),
Expand Down Expand Up @@ -90,18 +92,18 @@ def execute(self, context):
def addUIDrawables(self, drawManager, frameContext):
# type: (omui.MUIDrawManager, omr.MFrameContext) -> bool

if not omani.MAnimControl.isPlaying():
if (not omani.MAnimControl.isPlaying() and not omani.MAnimControl.isScrubbing()):
return False

target = self._getTargetDagPath()
if not target:
return True

tool = self._getToolContext()
tool, axis = self._getToolContext()
if not tool:
return True

self._draw(drawManager, target, tool)
self._draw(drawManager, target, tool, axis)
return True

# ------------------------------------------------------------------------
Expand All @@ -119,22 +121,29 @@ def _getTargetDagPath(self):
return target

def _getToolContext(self):
# type: () -> Text
"""Return current current tool context as Text, "move" or "rotate"."""
# type: () -> Tuple[Text]
"""Return current current tool context and activeHandle as Text.
context: "move" or "rotate"
activeAxis: int [0: x, 1: y, 2:z, 3:not restricted]
"""

ctx = mel.eval("currentCtx;") # type: Text
if "move" in ctx.lower():
return "move"
activeHandle = mel.eval("manipMoveContext -q -currentActiveHandle Move;")
return "move", activeHandle

elif "rotate" in ctx.lower():
return "rotate"
activeHandle = mel.eval("manipRotateContext -q -currentActiveHandle Rotate;")
return "rotate", activeHandle

return ""
return "", None

# ------------------------------------------------------------------------

def _draw(self, manager, dagPath, tool):
# type: (omui.MUIDrawManager, om.MDagPath, Text) -> None
def _draw(self, manager, dagPath, tool, activeAxis):
# type: (omui.MUIDrawManager, om.MDagPath, Text, int) -> None
"""Draw manipulator shape using MUIDrawManager.
Depending the tool context, draw arrow gizmo or spherical gizmo.
Expand All @@ -153,19 +162,23 @@ def _draw(self, manager, dagPath, tool):
posz = worldMat.getElement(3, 2)
point = om.MPoint(posx, posy, posz)

manager.beginDrawable()
xcol = self.hiColor if activeAxis == 0 else self.xcolor
ycol = self.hiColor if activeAxis == 1 else self.ycolor
zcol = self.hiColor if activeAxis == 2 else self.zcolor

manager.beginDrawInXray()

if "move" == tool:
self._drawArrow(manager, point, worldMat, rotMat, self.xmat, self.xcolor)
self._drawArrow(manager, point, worldMat, rotMat, self.ymat, self.ycolor)
self._drawArrow(manager, point, worldMat, rotMat, self.zmat, self.zcolor)
self._drawArrow(manager, point, worldMat, rotMat, self.xmat, xcol)
self._drawArrow(manager, point, worldMat, rotMat, self.ymat, ycol)
self._drawArrow(manager, point, worldMat, rotMat, self.zmat, zcol)

elif "rotate" == tool:
self._drawCircle(manager, point, worldMat, rotMat, self.xmat, self.xcolor)
self._drawCircle(manager, point, worldMat, rotMat, self.ymat, self.ycolor)
self._drawCircle(manager, point, worldMat, rotMat, self.zmat, self.zcolor)
self._drawCircle(manager, point, worldMat, rotMat, self.xmat, xcol)
self._drawCircle(manager, point, worldMat, rotMat, self.ymat, ycol)
self._drawCircle(manager, point, worldMat, rotMat, self.zmat, zcol)

manager.endDrawable()
manager.endDrawInXray()

def _drawArrow(self, manager, basePoint, worldMat, rotMat, distanceMat, color):
# type: (omui.MUIDrawManager, om.MPoint, om.MMatrix, om.MMatrix, om.MMatrix, om.MColor) -> None
Expand Down Expand Up @@ -273,7 +286,7 @@ def cleanup(self):
super(DrawManipulatorOverride, self).cleanup()

def supportedDrawAPIs(self):
# type: () -> None
# type: () -> int
return omr.MRenderer.kAllDevices

def startOperationIterator(self):
Expand Down

0 comments on commit 386946f

Please sign in to comment.