Exemple #1
0
def uvTransferLoad(srcPath, tarPath, srcUvSet='default', tarUvSet='default', tol=0.0001, pBar=None):
	'''Transfer the shape from the source to the target through uv space
		Return the data needed to write out the result

	Parameters
	----------
	srcPath : str
		The source mesh path (obj, abc, or smpx)
	tarPath : str
		The target mesh path (obj, abc, or smpx)
	srcUvSet : str
		The name of the uv set to use on the source
	tarUvSet : str
		The name of the uv set to use on the target
	tol : float
		A small tolerance value, defaulting to the global EPS
	pBar : QProgressDialog, optional
		An optional progress dialog

	Returns
	-------
	: np.array
		The target vertex positions
	: list
		The target vertex faces
	: np.array
		The target uvs
	: list
		The target uv faces

	'''
	from blur3d.api.classes.mesh import Mesh
	from blur3d.api.classes import abc
	if srcPath.endswith('.abc') or srcPath.endswith('.smpx'):
		src = Mesh.loadAbc(srcPath, ensureWinding=False)
		srcVerts = abc.getSampleArray(abc.getMesh(srcPath))
	elif srcPath.endswith('.obj'):
		src = Mesh.loadObj(srcPath, ensureWinding=False)
		srcVerts = np.array(src.vertArray)

	if tarPath.endswith('.abc'):
		tar = Mesh.loadAbc(tarPath, ensureWinding=False)
	elif tarPath.endswith('.obj'):
		tar = Mesh.loadObj(tarPath, ensureWinding=False)

	srcFaces = src.faceVertArray
	srcUvFaces = src.uvFaceMap[srcUvSet]
	srcUvs = np.array(src.uvMap[srcUvSet])

	tarFaces = tar.faceVertArray
	tarUvFaces = tar.uvFaceMap[tarUvSet]
	tarUvs = np.array(tar.uvMap[tarUvSet])
	oldTarVerts = np.array(tar.vertArray)
	tarVerts = uvTransfer(
		srcFaces, srcUvFaces, srcVerts, srcUvs, tarFaces,
		tarUvFaces, oldTarVerts, tarUvs, tol=tol, pBar=pBar
	)

	return tarVerts, tarFaces, tarUvs, tarUvFaces
Exemple #2
0
def uvTransferLoad(srcPath,
                   tarPath,
                   srcUvSet='default',
                   tarUvSet='default',
                   tol=0.0001,
                   pBar=None):
    ''' Transfer the shape from the source to the target through uv space
	Return the data needed to write out the result

	Arguments:
		srcPath(str): The filepath to the source object
		tarPath(str): The filepath to the target object

	Returns:
		tarVerts(np.array): The target vertex positions
		tarFaces(list): The target vertex faces
		tarUvs(np.array): The target uvs
		tarUvFaces(list): The target uv faces
	'''
    from blur3d.api.classes.mesh import Mesh
    from blur3d.api.classes import abc
    if srcPath.endswith('.abc') or srcPath.endswith('.smpx'):
        src = Mesh.loadAbc(srcPath, ensureWinding=False)
        srcVerts = abc.getSampleArray(abc.getMesh(srcPath))
    elif srcPath.endswith('.obj'):
        src = Mesh.loadObj(srcPath, ensureWinding=False)
        srcVerts = np.array(src.vertArray)

    if tarPath.endswith('.abc'):
        tar = Mesh.loadAbc(tarPath, ensureWinding=False)
    elif tarPath.endswith('.obj'):
        tar = Mesh.loadObj(tarPath, ensureWinding=False)

    srcFaces = src.faceVertArray
    srcUvFaces = src.uvFaceMap[srcUvSet]
    srcUvs = np.array(src.uvMap[srcUvSet])

    tarFaces = tar.faceVertArray
    tarUvFaces = tar.uvFaceMap[tarUvSet]
    tarUvs = np.array(tar.uvMap[tarUvSet])
    oldTarVerts = np.array(tar.vertArray)
    tarVerts = uvTransfer(srcFaces,
                          srcUvFaces,
                          srcVerts,
                          srcUvs,
                          tarFaces,
                          tarUvFaces,
                          oldTarVerts,
                          tarUvs,
                          tol=tol,
                          pBar=pBar)

    return tarVerts, tarFaces, tarUvs, tarUvFaces
Exemple #3
0
def simplexUvTransfer(srcSmpxPath,
                      tarPath,
                      outPath,
                      srcUvPath=None,
                      tol=0.0001,
                      pBar=None):
    """ Transfer a simplex system onto a mesh through UV space

	Arguments:
		srcSmpxPath (str): The path to the source .smpx file
		tarPath (str): The path to the mesh to recieve the blendshapes
		outPath (str): The .smpx path that will be written
		srcUvPath (str): If the .smpx file doesn't have UV's, then the UV's
			from this mesh wil be used. Defaults to None
		tol (float): The tolerance for checking if a UV is outside of a poly
		pBar (QProgressDialog): Optional progress bar
	"""
    if pBar is not None:
        pBar.setLabelText("Loading Source Mesh")
        from Qt.QtWidgets import QApplication
        QApplication.processEvents()

    srcUvPath = srcUvPath or srcSmpxPath
    if srcUvPath.endswith('.abc') or srcUvPath.endswith('.smpx'):
        src = Mesh.loadAbc(srcUvPath, ensureWinding=False)
    elif srcUvPath.endswith('.obj'):
        src = Mesh.loadObj(srcUvPath, ensureWinding=False)
    srcVerts = abc.getSampleArray(abc.getMesh(srcSmpxPath))

    if pBar is not None:
        pBar.setLabelText("Loading Target Mesh")
        from Qt.QtWidgets import QApplication
        QApplication.processEvents()
    if tarPath.endswith('.abc'):
        tar = Mesh.loadAbc(tarPath, ensureWinding=False)
    elif tarPath.endswith('.obj'):
        tar = Mesh.loadObj(tarPath, ensureWinding=False)

    srcFaces = src.faceVertArray
    srcUvFaces = src.uvFaceMap['default']
    srcUvs = np.array(src.uvMap['default'])

    tarFaces = tar.faceVertArray
    tarUvFaces = tar.uvFaceMap['default']
    tarUvs = np.array(tar.uvMap['default'])
    oldTarVerts = np.array(tar.vertArray)

    corr = getVertCorrelation(srcUvFaces,
                              srcUvs,
                              tarFaces,
                              tarUvFaces,
                              tarUvs,
                              tol=tol,
                              pBar=pBar)
    tarVerts = applyTransfer(srcVerts, srcFaces, corr, len(oldTarVerts))

    # Apply as a delta
    deltas = tarVerts - tarVerts[0][None, ...]
    writeVerts = oldTarVerts[None, ...] + deltas

    jsString, name = _loadJSString(srcSmpxPath)
    oarch = OArchive(str(outPath), OGAWA)  # false for HDF5
    abc.buildAbc(oarch,
                 writeVerts,
                 tarFaces,
                 uvs=tarUvs,
                 uvFaces=tarUvFaces,
                 name=name,
                 shapeSuffix='',
                 propDict=dict(simplex=jsString))