def __init__(self): ompx.MPxToolCommand.__init__(self) self.setCommandString(K_TOOL_CMD_NAME) K_TRACKING_DICTIONARY[ompx.asHashable(self)] = self self.brush_state = None self.instance_data = None self.last_brush_position = None self.last_undo_journal = '' self.position = om.MVectorArray() self.scale = om.MVectorArray() self.rotation = om.MVectorArray() self.instance_id = om.MIntArray() self.visibility = om.MIntArray() self.normal = om.MVectorArray() self.tangent = om.MVectorArray() self.u_coord = om.MDoubleArray() self.v_coord = om.MDoubleArray() self.poly_id = om.MIntArray() self.color = om.MVectorArray() self.point_id = om.MIntArray() self.initial_rotation = om.MVectorArray() self.initial_scale = om.MVectorArray() self.initial_offset = om.MDoubleArray() self.initial_id = om.MIntArray() self.spray_coords = []
def __init__(self): OpenMayaMPx.MPxData.__init__(self) self.__fValue = 0.0 fValueDictionary[OpenMayaMPx.asHashable(self)] = self.__fValue
def readBinary(self, inStream, numBytesToRead): """Read in 4 byte packs to cStringIO, unpickle from there :note: this method is more complicated than it needs be since asCharPtr does not work ! It returns a string of a single char ... which is not the same :) ! :note: YES, this is a CUMBERSOME way to deal with bytes ... terrible, thanks maya :), thanks python""" sio = cStringIO.StringIO() scriptutil = api.MScriptUtil() scriptutil.createFromInt(0) intptr = scriptutil.asIntPtr() # require multiple of 4 ! if numBytesToRead % 4 != 0: raise AssertionError( "Require multiple of for for number of bytes to be read, but is %i" % numBytesToRead) bitmask = 255 # mask the lower 8 bit shiftlist = [0, 8, 16, 24] # used to shift bits by respective values for i in xrange(numBytesToRead / 4): api.MStreamUtils.readInt(inStream, intptr, True) intval = scriptutil.getInt(intptr) # convert to chars - endianess should be taken care of by python for shift in shiftlist: sio.write(chr((intval >> shift) & bitmask)) # END for each byte # END for all 4 bytes to read self.__data = cPickle.loads(binascii.a2b_base64(sio.getvalue())) sys._maya_pyPickleData_trackingDict[mpx.asHashable(self)] = self.__data
def readBinary(self, inStream, numBytesToRead): """Read in 4 byte packs to cStringIO, unpickle from there :note: this method is more complicated than it needs be since asCharPtr does not work ! It returns a string of a single char ... which is not the same :) ! :note: YES, this is a CUMBERSOME way to deal with bytes ... terrible, thanks maya :), thanks python""" sio = cStringIO.StringIO() scriptutil = api.MScriptUtil() scriptutil.createFromInt(0) intptr = scriptutil.asIntPtr() # require multiple of 4 ! if numBytesToRead % 4 != 0: raise AssertionError("Require multiple of for for number of bytes to be read, but is %i" % numBytesToRead) bitmask = 255 # mask the lower 8 bit shiftlist = [0, 8, 16, 24] # used to shift bits by respective values for i in xrange(numBytesToRead / 4): api.MStreamUtils.readInt(inStream, intptr, True) intval = scriptutil.getInt(intptr) # convert to chars - endianess should be taken care of by python for shift in shiftlist: sio.write(chr((intval >> shift) & bitmask)) # END for each byte # END for all 4 bytes to read self.__data = cPickle.loads(binascii.a2b_base64(sio.getvalue())) sys._maya_pyPickleData_trackingDict[mpx.asHashable(self)] = self.__data
def copy(self, other): # Cannot convert other to self. Use a dictionary # to hold the information we need. self.__fValue = fValueDictionary[OpenMayaMPx.asHashable(other)]
def __init__(self): OpenMayaMPx.MPxToolCommand.__init__(self) self.setCommandString(kPluginCmdName) self.__delta = OpenMaya.MVector() kTrackingDictionary[OpenMayaMPx.asHashable(self)] = self
def readASCII(self, args, lastParsedElement): try: if args.length() > 0: parsedIndex = OpenMaya.MScriptUtil.getUint(lastParsedElement) self.__fValue = args.asDouble( parsedIndex ) parsedIndex += 1 OpenMaya.MScriptUtil.setUint(lastParsedElement,parsedIndex) fValueDictionary[OpenMayaMPx.asHashable(self)]=self.__fValue except: sys.stderr.write("Failed to read ASCII value.") raise
def readASCII(self, args, lastParsedElement): """Read base64 element and decode to cStringIO, then unpickle""" parsedIndex = api.MScriptUtil.getUint(lastParsedElement) base64encodedstring = args.asString(parsedIndex) self.__data = cPickle.loads(binascii.a2b_base64(base64encodedstring)) parsedIndex += 1 api.MScriptUtil.setUint(lastParsedElement,parsedIndex) # proceed the index # update tracking dict sys._maya_pyPickleData_trackingDict[mpx.asHashable(self)] = self.__data
def readASCII(self, args, lastParsedElement): """Read base64 element and decode to cStringIO, then unpickle""" parsedIndex = api.MScriptUtil.getUint(lastParsedElement) base64encodedstring = args.asString(parsedIndex) self.__data = cPickle.loads(binascii.a2b_base64(base64encodedstring)) parsedIndex += 1 api.MScriptUtil.setUint(lastParsedElement, parsedIndex) # proceed the index # update tracking dict sys._maya_pyPickleData_trackingDict[mpx.asHashable(self)] = self.__data
def __del__(self): """Remove ourselves from the dictionary to prevent flooding :note: we can be called even if maya is already unloaded or shutting down""" if mpx.asHashable is not None: del(sys._maya_pyPickleData_trackingDict[mpx.asHashable(self)]) # call super just to be on the safe side in future, currently it appears # not to be required try: super(PyPickleData, self).__del__() except AttributeError: # Maya 2008 and following do not require this anymore as they # do not have a del method implemented apparently pass
def __del__(self): """Remove ourselves from the dictionary to prevent flooding :note: we can be called even if maya is already unloaded or shutting down""" if mpx.asHashable is not None: del (sys._maya_pyPickleData_trackingDict[mpx.asHashable(self)]) # call super just to be on the safe side in future, currently it appears # not to be required try: super(PyPickleData, self).__del__() except AttributeError: # Maya 2008 and following do not require this anymore as they # do not have a del method implemented apparently pass
def doEditFlags(self): theParser = self._parser() theControl = kPythonPtrTable.get(OpenMayaMPx.asHashable(self._control()), None) if theParser.isFlagSet(kNopFlag): theControl.setOperation(kNop) elif theParser.isFlagSet(kMultFlag): theControl.setOperation(kMult) elif theParser.isFlagSet(kAddFlag): theControl.setOperation(kAdd) elif theParser.isFlagSet(kRedrawFlag): theControl.redrawCells() theControl.redrawLabels() else: OpenMayaMPx.MPxControlCommand.doEditFlags(self)
def doEditFlags(self): theParser = self._parser() theControl = kPythonPtrTable.get( OpenMayaMPx.asHashable(self._control()), None) if theParser.isFlagSet(kNopFlag): theControl.setOperation(kNop) elif theParser.isFlagSet(kMultFlag): theControl.setOperation(kMult) elif theParser.isFlagSet(kAddFlag): theControl.setOperation(kAdd) elif theParser.isFlagSet(kRedrawFlag): theControl.redrawCells() theControl.redrawLabels() else: OpenMayaMPx.MPxControlCommand.doEditFlags(self)
def doPress(self, event): OpenMayaMPx.MPxSelectionContext.doPress(self, event) spc = OpenMaya.MSpace.kWorld # If we are not in selecting mode (i.e. an object has been selected) # then set up for the translation. # if not self._isSelecting(): argX = OpenMaya.MScriptUtil() argX.createFromInt(0) argXPtr = argX.asShortPtr() argY = OpenMaya.MScriptUtil() argY.createFromInt(0) argYPtr = argY.asShortPtr() event.getPosition(argXPtr, argYPtr) self.__startPos_x = OpenMaya.MScriptUtil(argXPtr).asShort() self.__startPos_y = OpenMaya.MScriptUtil(argYPtr).asShort() self.__view = OpenMayaUI.M3dView.active3dView() camera = OpenMaya.MDagPath() self.__view.getCamera(camera) fnCamera = OpenMaya.MFnCamera(camera) upDir = fnCamera.upDirection(spc) rightDir = fnCamera.rightDirection(spc) # Determine the camera used in the current view # if fnCamera.isOrtho(): if upDir.isEquivalent(OpenMaya.MVector.zNegAxis, kVectorEpsilon): self.__currWin = MoveContext.kTop elif rightDir.isEquivalent(OpenMaya.MVector.xAxis, kVectorEpsilon): self.__currWin = MoveContext.kFront else: self.__currWin = MoveContext.kSide else: self.__currWin = MoveContext.kPersp # Create an instance of the move tool command. # newCmd = self._newToolCommand() self.__cmd = kTrackingDictionary.get( OpenMayaMPx.asHashable(newCmd), None) self.__cmd.setVector(0.0, 0.0, 0.0)
def doPress(self, event): OpenMayaMPx.MPxSelectionContext.doPress(self, event) spc = OpenMaya.MSpace.kWorld # If we are not in selecting mode (i.e. an object has been selected) # then set up for the translation. # if not self._isSelecting(): argX = OpenMaya.MScriptUtil() argX.createFromInt(0) argXPtr = argX.asShortPtr() argY = OpenMaya.MScriptUtil() argY.createFromInt(0) argYPtr = argY.asShortPtr() event.getPosition(argXPtr, argYPtr) self.__startPos_x = OpenMaya.MScriptUtil(argXPtr).asShort() self.__startPos_y = OpenMaya.MScriptUtil(argYPtr).asShort() self.__view = OpenMayaUI.M3dView.active3dView() camera = OpenMaya.MDagPath() self.__view.getCamera(camera) fnCamera = OpenMaya.MFnCamera(camera) upDir = fnCamera.upDirection(spc) rightDir = fnCamera.rightDirection(spc) # Determine the camera used in the current view # if fnCamera.isOrtho(): if upDir.isEquivalent(OpenMaya.MVector.zNegAxis, kVectorEpsilon): self.__currWin = MoveContext.kTop elif rightDir.isEquivalent(OpenMaya.MVector.xAxis, kVectorEpsilon): self.__currWin = MoveContext.kFront else: self.__currWin = MoveContext.kSide else: self.__currWin = MoveContext.kPersp # Create an instance of the move tool command. # newCmd = self._newToolCommand() self.__cmd = kTrackingDictionary.get(OpenMayaMPx.asHashable(newCmd), None) self.__cmd.setVector(0.0, 0.0, 0.0)
def __del__(self): del kPythonPtrTable[OpenMayaMPx.asHashable(self)]
def __init__(self, command): OpenMayaMPx.MPxUITableControl.__init__(self, command) self.__myOperation = None kPythonPtrTable[OpenMayaMPx.asHashable(self)] = self
def copy(self, other): """Copy other into self - allows copy pointers as maya copies the data each time you retrieve it""" otherdata = sys._maya_pyPickleData_trackingDict[mpx.asHashable(other)] self.__data = otherdata sys._maya_pyPickleData_trackingDict[mpx.asHashable(self)] = self.__data
def __del__(self): try: del K_TRACKING_DICTIONARY[ompx.asHashable(self)] except KeyError: pass
def __del__(self): del kTrackingDictionary[OpenMayaMPx.asHashable(self)]
def getRockingTransformationMatrix(self): baseXform = self.transformationMatrixPtr() return kTrackingDictionary[OpenMayaMPx.asHashable(baseXform)]
def __init__(self): OpenMayaMPx.MPxTransformationMatrix.__init__(self) kTrackingDictionary[OpenMayaMPx.asHashable(self)] = self self.rockXValue = 0.0
def __init__(self): mpx.MPxData.__init__(self) self.__data = dict() sys._maya_pyPickleData_trackingDict[mpx.asHashable(self)] = self.__data
def __del__(self): del kTrackingDictionary[ompx.asHashable(self)]
def __init__(self): ompx.MPxTransformationMatrix.__init__(self) kTrackingDictionary[ompx.asHashable(self)] = self self.pivotX = 0.0 self.pivotY = 0.0 self.pivotZ = 0.0
def getPivotTransformationMatrix(self): baseXform = self.transformationMatrixPtr() return kTrackingDictionary[ompx.asHashable(baseXform)]
def create_tool_command(self): """ create a new instance of the command associated with the context """ tool_cmd = self._newToolCommand() self.tool_cmd = K_TRACKING_DICTIONARY.get(ompx.asHashable(tool_cmd)) self.tool_cmd.initialize_tool_cmd(self.state, self.instance_data)
def __init__(self): OpenMayaMPx.MPxData.__init__(self) self.__fValue = 0.0 fValueDictionary[OpenMayaMPx.asHashable(self)]=self.__fValue