Skip to content

Instantly share code, notes, and snippets.

@taikomatsu
Created July 3, 2015 09:03
Show Gist options
  • Save taikomatsu/0dbacd5701764af999e0 to your computer and use it in GitHub Desktop.
Save taikomatsu/0dbacd5701764af999e0 to your computer and use it in GitHub Desktop.
pymel vs OpenMaya speed test
# 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