Skip to content

Instantly share code, notes, and snippets.

@FryPotato893
Created August 29, 2018 16:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FryPotato893/59124f64eb6986c4fec702ffdca29f4f to your computer and use it in GitHub Desktop.
Save FryPotato893/59124f64eb6986c4fec702ffdca29f4f to your computer and use it in GitHub Desktop.
【Maya Python】選択した頂点の軌跡をカーブで作成。選択しているのがオブジェクトの場合、ピボット位置にカーブ作成。
# -*- coding:utf-8 -*-
import maya.cmds as cmds
def createCurveOfVertexTrail(startF, endF):
u"""
概要:
選択した頂点の軌跡をカーブで作成。
選択しているのがオブジェクトの場合、ピボット位置にカーブ作成。
引数:
startF(int) : 開始フレーム。
endF(int) : 終了フレーム。
戻り値:
string : 作成されたカーブのグループ名。
"""
allCurve = []
sel = cmds.ls(sl=True, fl=True)
selName = sel[0].split(".")[0]
crtTime = cmds.currentTime(q=True)
if sel == []:
cmds.error("Please select vertex.")
vertex = cmds.polyEvaluate(sel[0], vc=True)
for sels in sel:
cv = []
for i in range(endF - startF):
cmds.currentTime(startF + i)
if vertex != 0:
pos = cmds.pointPosition(sels, w=True)
elif vertex == 0:
pos = cmds.xform(sels, q=True, t=True, ws=True)
cv.append((pos[0], pos[1], pos[2]))
curves = cmds.curve(p=cv, n="%s_curve" % sels)
reCurves = curves.replace("__", "_")
cmds.rename(curves, reCurves)
allCurve.append(reCurves)
cmds.currentTime(crtTime)
return cmds.group(allCurve, n="%s_curve_GP" % selName)
createCurveOfVertexTrail(1, 30)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment