Exemple #1
0
    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]

            #speed up?
            system._faces = np.array([i for i in rawFaces])
            system._counts = np.array([i for i in rawCounts])

            print "Loading Verts"
            allVerts = getSampleArray(abcMesh)
            for shape, sample in zip(system.shapes, allVerts):
                shape.loadSMPX(sample)

        finally:
            del iarch

        return system
Exemple #2
0
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))
Exemple #3
0
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
Exemple #4
0
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()
    shapes = getSampleArray(abcMesh)

    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
Exemple #6
0
def unsubdivideSimplex(inPath, outPath, shapePrefix=None, pBar=None):
    iarch, imesh, jsString, xfoName, meshName = _openSmpx(inPath)
    jsString = _applyShapePrefix(shapePrefix, jsString)

    pbPrint(pBar, "Loading smpx")
    verts = getSampleArray(imesh).swapaxes(0, 1)
    faces = getMeshFaces(imesh)
    uvFaces = getUvFaces(imesh)
    uvs = getUvArray(imesh)
    uFaces, uVerts, uUVFaces, uUVs = _ussmpx(faces,
                                             verts,
                                             uvFaces,
                                             uvs,
                                             pBar=pBar)
    _exportUnsub(outPath,
                 xfoName,
                 meshName,
                 jsString,
                 uFaces,
                 uVerts.swapaxes(0, 1),
                 uUVFaces,
                 uUVs,
                 pBar=pBar)