Created
March 31, 2016 10:27
-
-
Save tokejepsen/974b9833897fe56e13722c85acfb999e to your computer and use it in GitHub Desktop.
Maya: Closest Transform
This file contains hidden or 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
import pymel.core as pm | |
def ctr_dist(objA, objB): | |
Ax, Ay, Az = objA.getRotatePivot(space="world") | |
Bx, By, Bz = objB.getRotatePivot(space="world") | |
return ((Ax-Bx)**2 + (Ay-By)**2 + (Az-Bz)**2 )**0.5 | |
def get_closest_node(src, nodes): | |
dists = [] | |
for node in nodes: | |
dists.append(ctr_dist(src, node)) | |
index = dists.index(min(dists)) | |
return nodes[index] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment