Skip to content

Instantly share code, notes, and snippets.

@FryPotato893
Last active August 29, 2018 16:20
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/bdc667038f42ad2caf16e4ac644e8cee to your computer and use it in GitHub Desktop.
Save FryPotato893/bdc667038f42ad2caf16e4ac644e8cee to your computer and use it in GitHub Desktop.
【Maya Python】 選択したパーティクルの軌跡をカーブで作成。
# -*- coding:utf-8 -*-
import maya.cmds as cmds
def createCurveOfParticleTrail(startF, endF):
u"""
概要:
選択したパーティクルの軌跡をカーブで作成。
particle, nParticle どちらでもOK。
引数:
startF(int) : 開始フレーム。
endF(int) : 終了フレーム。
戻り値:
string : 作成されたカーブのグループ名。
"""
sel = cmds.ls(sl=True)
nodeType = cmds.nodeType(cmds.listRelatives(sel[0], s=True))
if nodeType != "particle":
cmds.error("Please select a particle node.")
ptkey = {}
for i in range(endF - startF + 1):
cmds.currentTime(startF + i)
ptnum = cmds.getAttr(sel[0] + ".count")
if ptnum == 0:
pass
else:
for ptnums in range(ptnum):
if sel[0] + ".pt[%d]" % ptnums in ptkey.keys():
ptkey[sel[0] + ".pt[%d]" % ptnums].append(
cmds.pointPosition(sel[0] + ".pt[%d]" % ptnums, w=True))
else:
ptkey[sel[0] + ".pt[%d]" %ptnums] = [cmds.pointPosition(sel[0] + ".pt[%d]" % ptnums, w=True)]
curveList = []
for curves in range(len(ptkey.keys())):
curve = cmds.curve(
p=ptkey[sel[0] + ".pt[%d]" % curves], d=1, n="%s_curve%d" % (sel[0], curves + 1))
curveList.append(curve)
return cmds.group(curveList, n="%s_curveGrp" % sel[0])
createCurveOfParticleTrail(1, 50)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment