def buildFromAbc(self, thing, abcPath, pBar=None): """ Load a system from an exported abc file onto the current system """ if pBar is not None: pBar.show() pBar.setMaximum(100) pBar.setValue(0) pBar.setLabelText("Loading Smpx") QApplication.processEvents() iarch = IArchive(str(abcPath)) # because alembic hates unicode try: top = iarch.getTop() par = top.children[0] par = IXform(top, par.getName()) abcMesh = par.children[0] abcMesh = IPolyMesh(par, abcMesh.getName()) systemSchema = par.getSchema() props = systemSchema.getUserProperties() prop = props.getProperty("simplex") jsString = prop.getValue() js = json.loads(jsString) system = self.buildFromDict(thing, js, True, pBar) self.DCC.loadABC(abcMesh, js, pBar) finally: del iarch return system
def getMesh(iarch): '''Load the static mesh data from an alembic archive Parameters ---------- iarch : IArchive The input alembic archive Returns ------- : imath.IntArray The Faces array : imath.IntArray The Counts array ''' top = iarch.getTop() par = top.children[0] par = IXform(top, par.getName()) abcMesh = par.children[0] abcMesh = IPolyMesh(par, abcMesh.getName()) sch = abcMesh.getSchema() faces = sch.getFaceIndicesProperty().samples[0] counts = sch.getFaceCountsProperty().samples[0] return faces, counts
def loadSmpx(iarch): '''Load the json and shape data from a .smpx file Parameters ---------- iarch : IArchive The input alembic archive Returns ------- : np.array The array of point positions for all the shapes ''' top = iarch.getTop() par = top.children[0] par = IXform(top, par.getName()) abcMesh = par.children[0] abcMesh = IPolyMesh(par, abcMesh.getName()) shapes = getSampleArray(abcMesh) print "Done Loading" return shapes
def loadSMPX(cls, smpx): iarch = IArchive(str(smpx)) # because alembic hates unicode try: top = iarch.getTop() par = top.children[0] par = IXform(top, par.getName()) abcMesh = par.children[0] abcMesh = IPolyMesh(par, abcMesh.getName()) systemSchema = par.getSchema() props = systemSchema.getUserProperties() prop = props.getProperty('simplex') jsString = prop.getValue() js = json.loads(jsString) system = cls.loadJSON(js) system._smpx = smpx meshSchema = abcMesh.getSchema() rawFaces = meshSchema.getFaceIndicesProperty().samples[0] rawCounts = meshSchema.getFaceCountsProperty().samples[0] system._faces = [i for i in rawFaces] system._counts = [i for i in rawCounts] for shape, sample in zip( system.shapes, meshSchema.getPositionsProperty().samples): shape.loadSMPX(sample) finally: del iarch return system
def exportUnsub(inPath, outPath, newFaces, kept, shapePrefix=None, pBar=None): ''' Export the unsubdivided simplex ''' iarch = IArchive(str(inPath)) # because alembic hates unicode top = iarch.getTop() ixfo = IXform(top, top.children[0].getName()) iprops = ixfo.getSchema().getUserProperties() iprop = iprops.getProperty("simplex") jsString = iprop.getValue() if shapePrefix is not None: d = json.loads(jsString) if d['encodingVersion'] > 1: for shape in d['shapes']: shape['name'] = shapePrefix + shape['name'] else: d['shapes'] = [shapePrefix + i for i in d['shapes']] jsString = json.dumps(d) imesh = IPolyMesh(ixfo, ixfo.children[0].getName()) verts = getSampleArray(imesh) verts = verts[:, kept] indices = [] counts = [] for f in newFaces: indices.extend(f) counts.append(len(f)) abcCounts = mkArray(IntArray, counts) abcIndices = mkArray(IntArray, indices) # `False` for HDF5 `True` for Ogawa oarch = OArchive(str(outPath), False) oxfo = OXform(oarch.getTop(), ixfo.getName()) oprops = oxfo.getSchema().getUserProperties() oprop = OStringProperty(oprops, "simplex") oprop.setValue(str(jsString)) omesh = OPolyMesh(oxfo, imesh.getName()) osch = omesh.getSchema() if pBar is not None: pBar.setValue(0) pBar.setMaximum(len(verts)) pBar.setLabelText("Exporting Unsubdivided Shapes") QApplication.processEvents() for i, v in enumerate(verts): if pBar is not None: pBar.setValue(i) QApplication.processEvents() else: print "Exporting Unsubdivided Shape {0: <4}\r".format(i + 1), sample = OPolyMeshSchemaSample(mkSampleVertexPoints(v), abcIndices, abcCounts) osch.set(sample) if pBar is None: print "Exporting Unsubdivided Shape {0: <4}".format(len(verts))
def getShapes(iarch): ''' Load the animated shape data from an alembic archive ''' top = iarch.getTop() ixfo = IXform(top, top.children[0].getName()) mesh = IPolyMesh(ixfo, ixfo.children[0].getName()) shapes = getSampleArray(mesh) return shapes
def _openSmpx(inPath): iarch = IArchive(str(inPath)) # because alembic hates unicode top = iarch.getTop() ixfo = IXform(top, top.children[0].getName()) iprops = ixfo.getSchema().getUserProperties() iprop = iprops.getProperty("simplex") jsString = iprop.getValue() imesh = IPolyMesh(ixfo, ixfo.children[0].getName()) return iarch, imesh, jsString, ixfo.getName(), imesh.getName()
def loadJSString(iarch): top = iarch.getTop() par = top.children[0] par = IXform(top, par.getName()) systemSchema = par.getSchema() props = systemSchema.getUserProperties() prop = props.getProperty("simplex") jsString = prop.getValue() return jsString
def _loadJSString(srcSmpxPath): ''' Get the json string out of a .smpx file ''' iarch = IArchive(str(srcSmpxPath)) top = iarch.getTop() par = top.children[0] parName = par.getName() par = IXform(top, parName) systemSchema = par.getSchema() props = systemSchema.getUserProperties() prop = props.getProperty("simplex") jsString = prop.getValue() return jsString, parName
def loadSmpx(iarch): ''' Load the json and shape data from a .smpx file ''' top = iarch.getTop() par = top.children[0] par = IXform(top, par.getName()) abcMesh = par.children[0] abcMesh = IPolyMesh(par, abcMesh.getName()) shapes = getSampleArray(abcMesh) print "Done Loading" return shapes
def loadMesh(iarch): top = iarch.getTop() par = top.children[0] par = IXform(top, par.getName()) abcMesh = par.children[0] abcMesh = IPolyMesh(par, abcMesh.getName()) sch = abcMesh.getSchema() faces = sch.getFaceIndicesProperty().samples[0] counts = sch.getFaceCountsProperty().samples[0] return faces, counts
def getMesh(iarch): ''' Load the static mesh data from an alembic archive ''' top = iarch.getTop() par = top.children[0] par = IXform(top, par.getName()) abcMesh = par.children[0] abcMesh = IPolyMesh(par, abcMesh.getName()) sch = abcMesh.getSchema() faces = sch.getFaceIndicesProperty().samples[0] counts = sch.getFaceCountsProperty().samples[0] return faces, counts
def loadSmpx(iarch): top = iarch.getTop() par = top.children[0] par = IXform(top, par.getName()) abcMesh = par.children[0] abcMesh = IPolyMesh(par, abcMesh.getName()) meshSchema = abcMesh.getSchema() posProp = meshSchema.getPositionsProperty() shapes = [] lpps = len(posProp.samples) for i, s in enumerate(posProp.samples): print "Reading {0: 3d} of {1}\r".format(i, lpps), shapes.append(s) print "Reading {0: 3d} of {1}".format(lpps, lpps) return shapes
def buildBaseAbc(self, abcPath): iarch = IArchive(str(abcPath)) # because alembic hates unicode try: top = iarch.getTop() par = top.children[0] par = IXform(top, par.getName()) abcMesh = par.children[0] abcMesh = IPolyMesh(par, abcMesh.getName()) systemSchema = par.getSchema() props = systemSchema.getUserProperties() prop = props.getProperty("simplex") jsString = prop.getValue() js = json.loads(jsString) obj = self.DCC.buildRestABC(abcMesh, js) finally: del iarch return obj
def loadSmpx(iarch): ''' Load the json and shape data from a .smpx file ''' top = iarch.getTop() par = top.children[0] par = IXform(top, par.getName()) abcMesh = par.children[0] abcMesh = IPolyMesh(par, abcMesh.getName()) meshSchema = abcMesh.getSchema() posProp = meshSchema.getPositionsProperty() print "Loading Verts" shapes = np.empty((len(posProp.samples), len(posProp.samples[0]), 3)) for i, s in enumerate(posProp.samples): shapes[i] = arrayToNumpy(s) print "Done Loading" return shapes
def getShapes(iarch): '''Load the animated shape data from an alembic archive Parameters ---------- iarch : IArchive The input alembic archive Returns ------- : np.array The shape points ''' top = iarch.getTop() ixfo = IXform(top, top.children[0].getName()) mesh = IPolyMesh(ixfo, ixfo.children[0].getName()) shapes = getSampleArray(mesh) return shapes
def getSmpxArchiveData(abcPath): '''Read and return the low level relevant data from a simplex alembic Parameters ---------- abcPath : str The path to the .smpx file Returns ------- : IArchive An opened Alembic IArchive object handle : IPolyMesh An Alembic Mesh handle : str The json definition string ''' if not os.path.isfile(str(abcPath)): raise IOError("File does not exist: " + str(abcPath)) iarch = IArchive(str(abcPath)) # because alembic hates unicode top, par, abcMesh = [None] * 3 try: top = iarch.getTop() par = top.children[0] par = IXform(top, par.getName()) abcMesh = par.children[0] abcMesh = IPolyMesh(par, abcMesh.getName()) # I *could* come up with a generic property reader # but it's useless for me at this time sch = par.getSchema() props = sch.getUserProperties() jsString = readStringProperty(props, "simplex") except Exception: #pylint: disable=broad-except # ensure that the .smpx file is released iarch, top, par, abcMesh = [None] * 4 raise # Must return the archive, otherwise it gets GC'd return iarch, abcMesh, jsString
def loadJSString(iarch): '''Get the json string out of a .smpx file Parameters ---------- iarch : IArchive The input alembic archive Returns ------- : str The simplex json string ''' top = iarch.getTop() par = top.children[0] par = IXform(top, par.getName()) systemSchema = par.getSchema() props = systemSchema.getUserProperties() prop = props.getProperty("simplex") jsString = prop.getValue() return jsString
def parseAbc(path): """ Read an .abc file and produce a Mesh object Args: path: The path to the .abc formatted file Returns: A list of vertices and the face connectivity Raises: IOError: If the file cannot be opened """ iarch = IArchive(str(path)) # because alembic hates unicode top = iarch.getTop() ixfo = IXform(top, top.children[0].getName()) mesh = IPolyMesh(ixfo, ixfo.children[0].getName()) sch = mesh.getSchema() rawVerts = sch.getPositionsProperty().samples[0] rawFaces = sch.getFaceIndicesProperty().samples[0] rawCounts = sch.getFaceCountsProperty().samples[0] faces = [] faceCounter = 0 for count in rawCounts: f = list(rawFaces[faceCounter: faceCounter+count]) # Ignoring UV/Normal data for now faces.append(f) faceCounter += count verts = [] for v in rawVerts: verts.append(list(v)) return verts, faces
def readFalloffData(abcPath): '''Load the relevant data from a simplex alembic Parameters ---------- abcPath : str Path to the .smpx file ''' if not os.path.isfile(str(abcPath)): raise IOError("File does not exist: " + str(abcPath)) iarch = IArchive(str(abcPath)) # because alembic hates unicode top, par, systemSchema, foPropPar, foProp = [None] * 5 try: top = iarch.getTop() par = top.children[0] par = IXform(top, par.getName()) systemSchema = par.getSchema() props = systemSchema.getUserProperties() foDict = {} try: foPropPar = props.getProperty("falloffs") except KeyError: pass else: nps = foPropPar.getNumProperties() for i in range(nps): foProp = foPropPar.getProperty(i) fon = foProp.getName() fov = foProp.getValue() # imath.FloatArray fov = list(fov) if np is None else np.array(fov) foDict[fon] = fov finally: iarch, top, par, systemSchema, foPropPar, foProp = [None] * 6 return foDict