Created
July 3, 2015 09:03
-
-
Save taikomatsu/0dbacd5701764af999e0 to your computer and use it in GitHub Desktop.
pymel vs OpenMaya speed test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# this test executed on 80,000 vertices sphere and 6 faces box | |
from pymel.core import * | |
from time import time | |
from maya import OpenMaya | |
def calc_time(f): | |
def fn(*args, **kwargs): | |
s = time() | |
r = f(*args, **kwargs) | |
e = time() | |
print('[TIME] %f sec' % (e - s)) | |
return r | |
return fn | |
# [TIME] 16.788000 sec | |
@calc_time | |
def stick_pts_pymel(dst, target): | |
d = PyNode(dst).getShape() | |
t = PyNode(target).getShape() | |
s = 'world' | |
pts = d.getPoints(space=s) | |
for i, p in enumerate(pts): | |
pts[i] = t.getClosestPoint(p, space=s)[0] | |
d.setPoints(pts, space=s) | |
stick_pts_pymel('pSphere1', 'pCube1') | |
# [TIME] 0.294000 sec | |
# 57.1 times faster than pymel version of it!! | |
@calc_time | |
def stick_pts_openmaya(dst, target): | |
d = api.toMDagPath(dst) | |
t = api.toMDagPath(target) | |
d.extendToShape() | |
t.extendToShape() | |
dmfn = OpenMaya.MFnMesh(d) | |
tmfn = OpenMaya.MFnMesh(t) | |
s = OpenMaya.MSpace.kWorld | |
pts = OpenMaya.MPointArray() | |
dmfn.getPoints(pts, s) | |
p = OpenMaya.MPoint() | |
for i in xrange(pts.length()): | |
tmfn.getClosestPoint(pts[i], p, s) | |
pts.set(p, i) | |
dmfn.setPoints(pts) | |
stick_pts_openmaya('pSphere1', 'pCube1') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment