def startDrag(self, o, e): if self._dragStart is None: self._dragStart = e.pos() dtop = QApplication.desktop() sn = dtop.screenNumber(o.mapToGlobal(e.pos())) self._screen = dtop.availableGeometry(sn) if abs(e.x() - self._dragStart.x()) > self.startSensitivity: self._dragType = self.DRAG_HORIZONTAL elif abs(e.y() - self._dragStart.y()) > self.startSensitivity: self._dragType = self.DRAG_VERTICAL if self._dragType: self._leftover = 0 self._lastPos = e.pos() self._firstDrag = True self.dragPressed.emit() self.doOverrideCursor() if self.isSpinbox: if e.buttons() & self.dragButton: # Send mouseRelease to spin buttons when dragging # otherwise the spinbox will keep ticking. @longClickFix # There's gotta be a better way to do this :-/ mouseup = QMouseEvent(QEvent.MouseButtonRelease, e.pos(), self.dragButton, e.buttons(), e.modifiers()) QApplication.sendEvent(o, mouseup)
def exportABC(self, dccMesh, abcMesh, js, pBar=None): # dccMesh doesn't work in XSI, so just ignore it # export the data to alembic shapeDict = {i.name: i for i in self.simplex.shapes} shapes = [shapeDict[i] for i in js["shapes"]] faces, counts = self._exportABCFaces(self.mesh) schema = abcMesh.getSchema() if pBar is not None: pBar.show() pBar.setMaximum(len(shapes)) #deactivate evaluation above modeling to insure no deformations are present dcc.xsi.DeactivateAbove( "%s.modelingmarker" % self.mesh.ActivePrimitive, True) for i, shape in enumerate(shapes): if pBar is not None: pBar.setValue(i) QApplication.processEvents() if pBar.wasCanceled(): return verts = self._exportABCVertices(self.mesh, shape) abcSample = OPolyMeshSchemaSample(verts, faces, counts) schema.set(abcSample) dcc.xsi.DeactivateAbove( "%s.modelingmarker" % self.mesh.ActivePrimitive, "")
def exportABC(self, dccMesh, abcMesh, js, pBar=None): # export the data to alembic if dccMesh is None: dccMesh = self.mesh shapeDict = {i.name:i for i in self.simplex.shapes} shapes = [shapeDict[i] for i in js["shapes"]] faces, counts = self._exportABCFaces(dccMesh) schema = abcMesh.getSchema() if pBar is not None: pBar.show() pBar.setMaximum(len(shapes)) with disconnected(self.shapeNode) as cnx: shapeCnx = cnx[self.shapeNode] for v in shapeCnx.itervalues(): cmds.setAttr(v, 0.0) for i, shape in enumerate(shapes): if pBar is not None: pBar.setValue(i) QApplication.processEvents() if pBar.wasCanceled(): return cmds.setAttr(shape.thing, 1.0) verts = self._exportABCVertices(dccMesh) abcSample = OPolyMeshSchemaSample(verts, faces, counts) schema.set(abcSample) cmds.setAttr(shape.thing, 0.0)
def loadABC(self, abcMesh, js, pBar=None): # UGH, I *REALLY* hate that this is faster # But if I want to be "pure" about it, I should just bite the bullet # and do the direct alembic manipulation in C++ abcPath = str(abcMesh.getArchive()) abcNode = cmds.createNode('AlembicNode') cmds.setAttr(abcNode + ".abc_File", abcPath, type="string") cmds.setAttr(abcNode + ".speed", 24) shapes = js["shapes"] shapeDict = {i.name:i for i in self.simplex.shapes} importHead = cmds.polySphere(name='importHead', constructionHistory=False)[0] importHeadShape = [i for i in cmds.listRelatives(importHead, shapes=True)][0] cmds.connectAttr(abcNode+".outPolyMesh[0]", importHeadShape+".inMesh") vertCount = cmds.polyEvaluate(importHead, vertex=True) # force update cmds.disconnectAttr(abcNode+".outPolyMesh[0]", importHeadShape+".inMesh") importBS = cmds.blendShape(self.mesh, importHead)[0] cmds.blendShape(importBS, edit=True, weight=[(0, 1.0)]) # Maybe get shapeNode from self.mesh?? cmds.disconnectAttr(self.mesh+'.worldMesh[0]', importBS+'.inputTarget[0].inputTargetGroup[0].inputTargetItem[6000].inputGeomTarget') importOrig = [i for i in cmds.listRelatives(importHead, shapes=True) if i.endswith('Orig')][0] cmds.connectAttr(abcNode+".outPolyMesh[0]", importOrig+".inMesh") if pBar is not None: pBar.show() pBar.setMaximum(len(shapes)) longName = max(shapes, key=len) pBar.setValue(1) pBar.setLabelText("Loading:\n{0}".format("_"*len(longName))) for i, shapeName in enumerate(shapes): if pBar is not None: pBar.setValue(i) pBar.setLabelText("Loading:\n{0}".format(shapeName)) QApplication.processEvents() if pBar.wasCanceled(): return index = self._getShapeIndex(shapeDict[shapeName]) cmds.setAttr(abcNode + ".time", i) outAttr = "{0}.worldMesh[0]".format(importHead) tgn = "{0}.inputTarget[0].inputTargetGroup[{1}]".format(self.shapeNode, index) inAttr = "{0}.inputTargetItem[6000].inputGeomTarget".format(tgn) cmds.connectAttr(outAttr, inAttr, force=True) cmds.disconnectAttr(outAttr, inAttr) cmds.delete(abcNode) cmds.delete(importHead)
def rootWindow(): """ Returns the currently active QT main window Only works for QT UI's like Maya """ # for MFC apps there should be no root window window = None if QApplication.instance(): inst = QApplication.instance() window = inst.activeWindow() # Ignore QSplashScreen's, they should never be considered the root window. if isinstance(window, QSplashScreen): return None # If the application does not have focus try to find A top level widget # that doesn't have a parent and is a QMainWindow or QDialog if window == None: windows = [] dialogs = [] for w in QApplication.instance().topLevelWidgets(): if w.parent() == None: if isinstance(w, QMainWindow): windows.append(w) elif isinstance(w, QDialog): dialogs.append(w) if windows: window = windows[0] elif dialogs: window = dialogs[0] # grab the root window if window: while True: parent = window.parent() if not parent: break if isinstance(parent, QSplashScreen): break window = parent return window
def doOverrideCursor(self): if self._overridden: return if self.dragCursor == self.CURSOR_BLANK: QApplication.setOverrideCursor(Qt.BlankCursor) elif self.dragCursor == self.CURSOR_ARROWS: if self._dragType == self.DRAG_VERTICAL: QApplication.setOverrideCursor(Qt.SizeVerCursor) elif self._dragType == self.DRAG_HORIZONTAL: QApplication.setOverrideCursor(Qt.SizeHorCursor) self._overridden = True
def loadABC(self, abcMesh, js, pBar=False): meshSchema = abcMesh.getSchema() rawFaces = meshSchema.getFaceIndicesProperty().samples[0] rawCounts = meshSchema.getFaceCountsProperty().samples[0] rawPos = meshSchema.getPositionsProperty().samples[0] shapes = js["shapes"] shapeDict = {i.name: i for i in self.simplex.shapes} numVerts = len(rawPos) numFaces = len(rawCounts) faces = [] ptr = 0 for i in rawCounts: faces.append(i) for j in reversed(rawFaces[ptr:ptr + i]): faces.append(j) ptr += i xferDeltas = [] restPos = self._getMeshVertices(self.mesh) for i, j in zip(restPos, rawPos): xferDeltas.append((i[0] - j[0], i[1] - j[1], i[2] - j[2])) if pBar is not None: pBar.show() pBar.setMaximum(len(shapes)) longName = max(shapes, key=len) pBar.setValue(1) pBar.setLabelText("Loading:\n{0}".format("_" * len(longName))) posProp = meshSchema.getPositionsProperty() tempVertArray, tempFaceArray = self.mesh.ActivePrimitive.Geometry.Get2( ) for i, shapeName in enumerate(shapes): if pBar is not None: pBar.setValue(i) pBar.setLabelText("Loading:\n{0}".format(shapeName)) QApplication.processEvents() if pBar.wasCanceled(): return verts = posProp.samples[i] vertexArray = [] for j in xrange(numVerts): fp = [ verts[j][0] + xferDeltas[j][0], verts[j][1] + xferDeltas[j][1], verts[j][2] + xferDeltas[j][2] ] vertexArray.append(fp) vertexArray = zip(*vertexArray) # Create temporary mesh matching shape cName = "{0}_AbcConnect".format(shapeName) temp = dcc.xsi.ActiveSceneRoot.AddPolygonMesh( vertexArray, faces, cName) # Finally connect the blendshape self.connectShape(shapeDict[shapeName], cName, live=False, delete=True, deleteCombiner=False) self.deleteShapeCombiner() # Force a rebuild of the Icetree self.recreateShapeNode() if pBar is not None: pBar.setValue(len(shapes))
def restoreOverrideCursor(self): if not self._overridden: return QApplication.restoreOverrideCursor() self._overridden = False