Esempio n. 1
0
def getAbcFaces(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 = []
    #uvArray = []
    uvIdxArray = []
    vIdx = om.MIntArray()

    util = om.MScriptUtil()
    util.createFromInt(0)
    uvIdxPtr = util.asIntPtr()
    uArray = om.MFloatArray()
    vArray = om.MFloatArray()
    meshFn.getUVs(uArray, vArray)
    hasUvs = uArray.length() > 0

    for i in range(meshFn.numPolygons()):
        meshFn.getPolygonVertices(i, vIdx)
        face = []
        for j in reversed(xrange(vIdx.length())):
            face.append(vIdx[j])
            if hasUvs:
                meshFn.getPolygonUVid(i, j, uvIdxPtr)
                uvIdx = util.getInt(uvIdxPtr)
                if uvIdx >= uArray.length() or uvIdx < 0:
                    uvIdx = 0
                uvIdxArray.append(uvIdx)

        face = [vIdx[j] for j in reversed(xrange(vIdx.length()))]
        faces.extend(face)
        faceCounts.append(vIdx.length())

    abcFaceIndices = IntArray(len(faces))
    for i in xrange(len(faces)):
        abcFaceIndices[i] = faces[i]

    abcFaceCounts = IntArray(len(faceCounts))
    for i in xrange(len(faceCounts)):
        abcFaceCounts[i] = faceCounts[i]

    if hasUvs:
        abcUVArray = V2fArray(len(uArray))
        for i in xrange(len(uArray)):
            abcUVArray[i] = (uArray[i], vArray[i])
        abcUVIdxArray = UnsignedIntArray(len(uvIdxArray))
        for i in xrange(len(uvIdxArray)):
            abcUVIdxArray[i] = uvIdxArray[i]
        uv = OV2fGeomParamSample(abcUVArray, abcUVIdxArray,
                                 GeometryScope.kFacevaryingScope)
    else:
        uv = None

    return abcFaceIndices, abcFaceCounts, uv
Esempio n. 2
0
def mkSampleUvArray(uvs):
    """ Makes the alembic-usable c++ typed arrays """
    array = V2fArray(len(uvs))
    setter = V2f(0, 0)
    for i in xrange(len(uvs)):
        setter.setValue(uvs[i][0], uvs[i][1])
        array[i] = setter
    return array
Esempio n. 3
0
def mkSampleUvArray(uvs):
	''' Make an imath array of uvs

	Parameters
	----------
	uvs : list or np.array
		The input uvs

	Returns
	-------
	: V2fArray
		The output list
	'''
	array = V2fArray(len(uvs))
	setter = V2f(0, 0)
	for i in xrange(len(uvs)):
		setter.setValue(uvs[i][0], uvs[i][1])
		array[i] = setter
	return array