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 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))