zbw_curveTools.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:zTools 作者: zethwillie 项目源码 文件源码
def curve_through_selection(*args):
    """
    creates a curve through the selection, hopefully in order
    Args:
        None
    Returns:
        string, name of curve created
    """
    sel = cmds.ls(sl=True, fl=True)
    if not sel or len(sel)==1:
        cmds.warning("You need to select multiple things to create curve through!")
        return()

    pList = []
    crvType = cmds.radioButtonGrp(widgets["crvSelRBG"], q=True, sl=True)

    for obj in sel:
        if cmds.objectType(obj) in ["transform"]:
            pos = cmds.xform(obj, q=True, ws=True, rp=True)
            pList.append(pos)
        elif obj in cmds.filterExpand(sm=[28, 30, 31, 32, 34, 46]):
            pos = cmds.pointPosition(obj)
            pList.append(pos)

    #add points if only 2 (cv, ep) or 3 (cv) are given, and create the curve
    if crvType == 1:
        if len(pList) == 2:
            f = [float(sum(x)/2) for x in zip(*pList)]
            pList.insert(1, f)
            vec1 = [pList[1][0]-pList[0][0], pList[1][1]-pList[0][1], pList[1][2]-pList[0][2]]
            newPt1 =[pList[0][0] + (vec1[0]*0.05), pList[0][1] + (vec1[1]*0.05), pList[0][2] + (vec1[2]*0.05)]
            vec2 = [pList[1][0] - pList[2][0], pList[1][1] - pList[2][1], pList[1][2] - pList[2][2]]
            newPt2= [pList[2][0] + (vec2[0]*0.05), pList[2][1] + (vec2[1]*0.05), pList[2][2] + (vec2[2]*0.05)]
            pList.insert(1, newPt1)
            pList.insert(3, newPt2)
        if len(pList) == 3:
            vec1 = [pList[1][0]-pList[0][0], pList[1][1]-pList[0][1], pList[1][2]-pList[0][2]]
            newPt1 =[pList[0][0] + (vec1[0]*0.05), pList[0][1] + (vec1[1]*0.05), pList[0][2] + (vec1[2]*0.05)]
            vec2 = [pList[1][0] - pList[2][0], pList[1][1] - pList[2][1], pList[1][2] - pList[2][2]]
            newPt2= [pList[2][0] + (vec2[0]*0.05), pList[2][1] + (vec2[1]*0.05), pList[2][2] + (vec2[2]*0.05)]
            pList.insert(1, newPt1)
            pList.insert(3, newPt2)
        crv = cmds.curve(d=3, p=pList, name="newCurve")

    if crvType == 2:
        if len(pList) == 2:
            f = [float(sum(x)/2) for x in zip(*pList)]
            pList.insert(1, f)
        crv = cmds.curve(d=3, ep=pList, name="newCurve")

    return(crv)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号