Maya.API2.0速度テスト

MayaPythonScriptを比較してみる http://www.dfx.co.jp/dftalk/?p=12128 @DF_Inc
に触発されて簡単な実験、デコレータは参考元からのコピペ(すみません)
既に結果が出ているのを自分の環境でやってみただけですので目新しさは無いですが、体感するとやっぱり違うな~としみじみ。

以下ソースです

from maya.api import OpenMaya
from maya import cmds
import pymel.core
#---------------------------------------------------------------------
# 速度計算処理
# デコレータ定義
#---------------------------------------------------------------------
import time
def testTime(func):
    def start(*args):
        print '--'*14
        print args[1] + ' >> ' + args[0]
        st = time.time()
        posAry = func(args[0])
        ed = time.time() - st
        print 'total : ' + str(ed)
        print '--'*14
        return posAry
    return start

class PointPosition(object):
    def __init__(self, nodes=None):
        self.positions = []
        self.SelectionList = None
        if nodes:
            self.SelectionList = OpenMaya.MSelectionList()
            if not isinstance(nodes, list):
                nodes = [nodes]
            for node in nodes:
                try:
                    self.SelectionList.add(node)
                except RuntimeError:
                    print ('# add Object Not Found : %s ' % node)
        else:
            ActiveSelectionList = OpenMaya.MGlobal.getActiveSelectionList()
            self.SelectionList = OpenMaya.MSelectionList(ActiveSelectionList)

        for i in range(self.SelectionList.length()):
            DagPath = self.SelectionList.getDagPath(i)
            Mesh = OpenMaya.MFnMesh(DagPath)

            positions = Mesh.getPoints(OpenMaya.MSpace.kWorld)
            for position in positions:
                self.positions.append([position.x, position.y, position.z])
@testTime
def test_cmds(obj):
    for vtx in cmds.ls(obj+'.vtx[*]',fl=1):
        cmds.xform(vtx,q=1,t=1,ws=1)

@testTime
def test_API2_Wrapper(obj):
    pp = PointPosition(obj)

@testTime
def test_PyMel(obj):
    for vtx in pymel.core.ls(obj+'.vtx[*]',fl=1):
        pymel.core.xform(vtx,q=1,t=1,ws=1)

if __name__ == '__main__':
    name = 'pShere_getPoint_TEST'
    cmds.polySphere(r=1, sx=200, sy=200, ax=[0,1,0], cuv=2, ch=1, name=name);
    test_PyMel(name, 'test_PyMel')
    test_cmds(name, 'test_cmds')
    test_API2_Wrapper(name, 'test_API2_Wrapper')

結果:
----------------------------
test_PyMel >> pShere_getPoint_TEST
total : 19.371999979
----------------------------
----------------------------
test_cmds >> pShere_getPoint_TEST
total : 2.02399992943
----------------------------
----------------------------
test_API2_Wrapper >> pShere_getPoint_TEST
total : 0.029000043869
----------------------------


この記事が気に入ったらサポートをしてみませんか?