コード例 #1
0
	def exportAbc(self, dccMesh, abcMesh, js, world=False, pBar=None):
		# export the data to alembic
		if dccMesh is None:
			dccMesh = self.mesh

		shapeDict = {i.name:i for i in self.simplex.shapes}

		shapeNames = js['shapes']
		if js['encodingVersion'] > 1:
			shapeNames = [i['name'] for i in shapeNames]
		shapes = [shapeDict[i] for i in shapeNames]

		schema = abcMesh.getSchema()

		if pBar is not None:
			pBar.show()
			pBar.setMaximum(len(shapes))
			spacerName = '_' * max(map(len, shapeNames))
			pBar.setLabelText('Exporting:\n{0}'.format(spacerName))
			QApplication.processEvents()

		for i, shape in enumerate(shapes):
			if pBar is not None:
				pBar.setLabelText('Exporting:\n{0}'.format(shape.name))
				pBar.setValue(i)
				QApplication.processEvents()
				if pBar.wasCanceled():
					return
			verts = mkSampleVertexPoints(self._shapes[shape.name])
			if self._uvs is not None:
				# Alembic doesn't allow for self._uvs=None for some reason
				abcSample = OPolyMeshSchemaSample(verts, self._faces, self._counts, self._uvs)
			else:
				abcSample = OPolyMeshSchemaSample(verts, self._faces, self._counts)
			schema.set(abcSample)
コード例 #2
0
ファイル: dummyInterface.py プロジェクト: hooplee5/Simplex
	def exportAbc(self, dccMesh, abcMesh, js, world=False, pBar=None):
		''' Export a .smpx file

		Parameters
		----------
		dccMesh : object
			The DCC Mesh to export
		abcMesh : OPolyMesh
			The Alembic output mesh
		js : dict
			The definition dictionary
		world : bool
			Do the export in worldspace (Default value = False)
		pBar : QProgressDialog, optional
			An optional progress dialog (Default value = None)

		'''
		# export the data to alembic
		if dccMesh is None:
			dccMesh = self.mesh

		shapeDict = {i.name: i for i in self.simplex.shapes}

		shapeNames = js['shapes']
		if js['encodingVersion'] > 1:
			shapeNames = [i['name'] for i in shapeNames]
		shapes = [shapeDict[i] for i in shapeNames]
		schema = abcMesh.getSchema()

		if pBar is not None:
			pBar.show()
			pBar.setMaximum(len(shapes))
			spacerName = '_' * max(map(len, shapeNames))
			pBar.setLabelText('Exporting:\n{0}'.format(spacerName))
			QApplication.processEvents()

		faces = mkSampleIntArray(self.mesh.faces)
		counts = mkSampleIntArray(self.mesh.counts)
		uvs = None
		if self.mesh.uvs is not None and self.mesh.uvFaces is not None:
			uvs = mkUvSample(self.mesh.uvs, self.mesh.uvFaces)

		for i, shape in enumerate(shapes):
			if pBar is not None:
				pBar.setLabelText('Exporting:\n{0}'.format(shape.name))
				pBar.setValue(i)
				QApplication.processEvents()
				if pBar.wasCanceled():
					return
			verts = mkSampleVertexPoints(shape.thing.points)
			if uvs is not None:
				# Alembic doesn't allow for uvs=None for some reason
				abcSample = OPolyMeshSchemaSample(verts, faces, counts, uvs)
			else:
				abcSample = OPolyMeshSchemaSample(verts, faces, counts)
			schema.set(abcSample)
コード例 #3
0
ファイル: simplexSplitter.py プロジェクト: iVerb/Simplex
    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
コード例 #4
0
def _exportAbc(arch, smpx, shapeArray, faces, counts, uvs):
    par = OXform(arch.getTop(), str(smpx.name))
    props = par.getSchema().getUserProperties()
    prop = OStringProperty(props, "simplex")
    prop.setValue(str(smpx.dump()))
    abcMesh = OPolyMesh(par, str(smpx.name))
    schema = abcMesh.getSchema()
    for i in range(len(smpx.shapes)):
        if uvs is not None:
            abcSample = OPolyMeshSchemaSample(
                mkSampleVertexPoints(shapeArray[i]), faces, counts, uvs)
        else:
            # can't just pass uvs as None because of how the Alembic API works
            abcSample = OPolyMeshSchemaSample(
                mkSampleVertexPoints(shapeArray[i]), faces, counts)
        schema.set(abcSample)
コード例 #5
0
ファイル: xsiInterface.py プロジェクト: phmongeau/Simplex
	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, "")
コード例 #6
0
ファイル: applyCorrectives.py プロジェクト: hyb1234hi/Simplex
def _writeSimplex(oarch, name, jsString, faces, counts, newShapes, pBar=None):
    ''' Separate the writer from oarch creation so garbage
	collection *hopefully* works as expected
	'''
    par = OXform(oarch.getTop(), name)
    props = par.getSchema().getUserProperties()
    prop = OStringProperty(props, "simplex")
    prop.setValue(str(jsString))
    abcMesh = OPolyMesh(par, name)
    schema = abcMesh.getSchema()

    if pBar is not None:
        pBar.setLabelText('Writing Corrected Simplex')
        pBar.setMaximum(len(newShapes))

    for i, newShape in enumerate(newShapes):
        if pBar is not None:
            pBar.setValue(i)
            QApplication.processEvents()
        else:
            print "Writing {0: 3d} of {1}\r".format(i, len(newShapes)),

        verts = mkSampleVertexPoints(newShape)
        abcSample = OPolyMeshSchemaSample(verts, faces, counts)
        schema.set(abcSample)
    if pBar is None:
        print "Writing {0: 3d} of {1}".format(len(newShapes), len(newShapes))
コード例 #7
0
	def exportABC(self, dccMesh, abcMesh, js, world=False, 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, world=world)
				abcSample = OPolyMeshSchemaSample(verts, faces, counts)
				schema.set(abcSample)
				cmds.setAttr(shape.thing, 0.0)
コード例 #8
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))
コード例 #9
0
ファイル: alembicCommon.py プロジェクト: hooplee5/Simplex
def setAlembicSample(omeshSch, points, faceCount, faceIndex, bounds=None, uvs=None, normals=None):
	""" Set an alembic sample to the output mesh with the given properties """
	# Do it this way because the defaults for these arguments are some value other than None
	kwargs = {}
	if uvs is not None:
		kwargs['iUVs'] = uvs
	if normals is not None:
		kwargs['iNormals'] = normals

	s = OPolyMeshSchemaSample(points, faceIndex, faceCount, **kwargs)
	if bounds is not None:
		omeshSch.getChildBoundsProperty().setValue(bounds)
	omeshSch.set(s)
コード例 #10
0
ファイル: hdf5Convert.py プロジェクト: rusn07/Simplex
def _writeSimplex(oarch, name, jsString, faces, counts, newShapes):
    par = OXform(oarch.getTop(), name)
    props = par.getSchema().getUserProperties()
    prop = OStringProperty(props, "simplex")
    prop.setValue(str(jsString))
    abcMesh = OPolyMesh(par, name)
    schema = abcMesh.getSchema()

    for i, newShape in enumerate(newShapes):
        print "Writing {0: 3d} of {1}\r".format(i, len(newShapes)),
        abcSample = OPolyMeshSchemaSample(newShape, faces, counts)
        schema.set(abcSample)
    print "Writing {0: 3d} of {1}".format(len(newShapes), len(newShapes))
コード例 #11
0
ファイル: mayaInterface.py プロジェクト: tws0002/Simplex
	def exportABC(self, abcMesh, js):
		# 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()
		with disconnected(self.shapeNode) as shapeCnx:
			for v in shapeCnx.itervalues():
				cmds.setAttr(v, 0.0)
			for shape in shapes:
				cmds.setAttr(shape.thing, 1.0)
				verts = self._exportABCVertices(self.mesh)
				abcSample = OPolyMeshSchemaSample(verts, faces, counts)
				schema.set(abcSample)
				cmds.setAttr(shape.thing, 0.0)
コード例 #12
0
ファイル: hdf5Convert.py プロジェクト: hyb1234hi/Simplex
def _writeSimplex(oarch, name, jsString, faces, counts, newShapes):
    ''' Separate the writer from oarch creation so garbage
	collection *hopefully* works as expected
	'''
    par = OXform(oarch.getTop(), name)
    props = par.getSchema().getUserProperties()
    prop = OStringProperty(props, "simplex")
    prop.setValue(str(jsString))
    abcMesh = OPolyMesh(par, name)
    schema = abcMesh.getSchema()

    for i, newShape in enumerate(newShapes):
        print "Writing {0: 3d} of {1}\r".format(i, len(newShapes)),
        abcSample = OPolyMeshSchemaSample(newShape, faces, counts)
        schema.set(abcSample)
    print "Writing {0: 3d} of {1}".format(len(newShapes), len(newShapes))
コード例 #13
0
ファイル: xsiInterface.py プロジェクト: iVerb/Simplex
	def exportABC(self, dccMesh, abcMesh, js):
		# 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()

		#deactivate evaluation above modeling to insure no deformations are present
		dcc.xsi.DeactivateAbove("%s.modelingmarker" %self.mesh.ActivePrimitive, True)

		for shape in shapes:
			verts = self._exportABCVertices(self.mesh, shape)
			abcSample = OPolyMeshSchemaSample(verts, faces, counts)
			schema.set(abcSample)

		dcc.xsi.DeactivateAbove("%s.modelingmarker" %self.mesh.ActivePrimitive, "")
コード例 #14
0
ファイル: simplexSplitter.py プロジェクト: phmongeau/Simplex
	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
コード例 #15
0
ファイル: unsubdivide.py プロジェクト: hyb1234hi/Simplex
def _exportUnsub(outPath,
                 xfoName,
                 meshName,
                 jsString,
                 faces,
                 verts,
                 uvFaces,
                 uvs,
                 pBar=None):
    oarch = OArchive(str(outPath), OGAWA)  # False for HDF5
    oxfo = OXform(oarch.getTop(), xfoName)
    oprops = oxfo.getSchema().getUserProperties()
    oprop = OStringProperty(oprops, "simplex")
    oprop.setValue(str(jsString))
    omesh = OPolyMesh(oxfo, meshName)
    osch = omesh.getSchema()

    if pBar is not None:
        pBar.setValue(0)
        pBar.setMaximum(len(verts))
        pBar.setLabelText("Exporting Unsubdivided Shapes")
        QApplication.processEvents()

    abcIndices = mkSampleIntArray(list(chain.from_iterable(faces)))
    abcCounts = mkSampleIntArray(map(len, faces))

    kwargs = {}
    if uvs is not None:
        # Alembic doesn't use None as the placeholder for un-passed kwargs
        # So I don't have to deal with that, I only set the kwarg dict if the uvs exist
        uvidx = None if uvFaces is None else list(chain.from_iterable(uvFaces))
        uvSample = mkUvSample(uvs, uvidx)
        kwargs['iUVs'] = uvSample

    for i, v in enumerate(verts):
        pbPrint(pBar, "Exporting Unsubdivided Shape", i)
        sample = OPolyMeshSchemaSample(mkSampleVertexPoints(v), abcIndices,
                                       abcCounts, **kwargs)
        osch.set(sample)

    pbPrint(pBar, "Done")