def toSMPX(self, path): defDict = self.toJSON() jsString = json.dumps(defDict) arch = OArchive(str(path)) # alembic does not like unicode filepaths try: par = OXform(arch.getTop(), str(self.name)) props = par.getSchema().getUserProperties() prop = OStringProperty(props, "simplex") prop.setValue(str(jsString)) mesh = OPolyMesh(par, str(self.name)) faces = Int32TPTraits.arrayType(len(self._faces)) for i, f in enumerate(self._faces): faces[i] = f counts = Int32TPTraits.arrayType(len(self._counts)) for i, c in enumerate(self._counts): counts[i] = c schema = mesh.getSchema() for shape in self.shapes: verts = shape.toSMPX() abcSample = OPolyMeshSchemaSample(verts, faces, counts) schema.set(abcSample) except: raise finally: del arch
def _exportABCFaces(self, mesh): geo = mesh.ActivePrimitive.Geometry vertArray, faceArray = geo.Get2() vertices = zip(*vertArray) ptr = 0 faces = [] faceCounts = [] while ptr < len(faceArray): count = faceArray[ptr] faceCounts.append(count) ptr += 1 indices = reversed(faceArray[ptr:ptr + count]) ptr += count faces.extend(indices) abcFaceIndices = Int32TPTraits.arrayType(len(faces)) for i in xrange(len(faces)): abcFaceIndices[i] = faces[i] abcFaceCounts = Int32TPTraits.arrayType(len(faceCounts)) for i in xrange(len(faceCounts)): abcFaceCounts[i] = faceCounts[i] return abcFaceIndices, abcFaceCounts
def _exportABCFaces(self, mesh): # Get the MDagPath from the name of the mesh sl = om.MSelectionList() sl.add(mesh) thing = om.MDagPath() sl.getDagPath(0, thing) meshFn = om.MFnMesh(thing) faces = [] faceCounts = [] vIdx = om.MIntArray() for i in range(meshFn.numPolygons()): meshFn.getPolygonVertices(i, vIdx) face = [vIdx[j] for j in reversed(xrange(vIdx.length()))] faces.extend(face) faceCounts.append(vIdx.length()) abcFaceIndices = Int32TPTraits.arrayType(len(faces)) for i in xrange(len(faces)): abcFaceIndices[i] = faces[i] abcFaceCounts = Int32TPTraits.arrayType(len(faceCounts)) for i in xrange(len(faceCounts)): abcFaceCounts[i] = faceCounts[i] return abcFaceIndices, abcFaceCounts
def toSMPX(self, path, pBar=None): defDict = self.toJSON() jsString = json.dumps(defDict) # `False` for HDF5 `True` for Ogawa arch = OArchive(str(path), False) # alembic does not like unicode filepaths try: par = OXform(arch.getTop(), str(self.name)) props = par.getSchema().getUserProperties() prop = OStringProperty(props, "simplex") prop.setValue(str(jsString)) mesh = OPolyMesh(par, str(self.name)) faces = Int32TPTraits.arrayType(len(self._faces)) for i, f in enumerate(self._faces): faces[i] = f counts = Int32TPTraits.arrayType(len(self._counts)) for i, c in enumerate(self._counts): counts[i] = c schema = mesh.getSchema() if pBar is not None: pBar.setMaximum(len(self.shapes)) pBar.setValue(0) pBar.setLabelText("Exporting Split Shapes") QApplication.processEvents() for i, shape in enumerate(self.shapes): if pBar is not None: pBar.setValue(i) QApplication.processEvents() else: print "Exporting Shape {0} of {1}\r".format(i+1, len(self.shapes)), verts = shape.toSMPX() abcSample = OPolyMeshSchemaSample(verts, faces, counts) schema.set(abcSample) if pBar is None: print except: raise finally: del arch