Mag command running slow on Maya 2022, any alternatives?

Mag command running slow on Maya 2022, any alternatives?

malcolm_341
Collaborator Collaborator
854 Views
4 Replies
Message 1 of 5

Mag command running slow on Maya 2022, any alternatives?

malcolm_341
Collaborator
Collaborator

I have a script welds the selected verts to the closest vert on the same mesh, I use the mag command to calculate the distance between selected vert and the surrounding verts. On certain machines specifically in Maya 2022 only my script has a bit of a lag when merging the verts. I think I've tracked it down to the mag command. Is there any alternative to mag, or is it possible to write the mag command out by hand using regular mel script to test if that executes faster. Here's what I'm using mag for.

float $coseVertPOS[] = `pointPosition -w`;
           	
//Find the difference between the two positions
float $xValue = $coseVertPOS[0] - $vertToMovePOS[0];
float $yValue = $coseVertPOS[1] - $vertToMovePOS[1];
float $zValue = $coseVertPOS[2] - $vertToMovePOS[2];
vector $difference = <<$xValue, $yValue, $zValue>>;
		
//Find the distance between the two points
float $distance = `mag $difference`;

 

0 Likes
Accepted solutions (1)
855 Views
4 Replies
Replies (4)
Message 2 of 5

malcolm_341
Collaborator
Collaborator
Accepted solution

My wife helped me figure out the math once I found this other help page explaining mag better than the command reference, solution here. https://download.autodesk.com/global/docs/maya2014/en_us/index.html?url=files/Useful_functions_mag.h...

 

float $coseVertPOS[] = `pointPosition -w`;
           	
//Find the difference between the two positions
float $xValue = $coseVertPOS[0] - $vertToMovePOS[0];
float $yValue = $coseVertPOS[1] - $vertToMovePOS[1];
float $zValue = $coseVertPOS[2] - $vertToMovePOS[2];
		
//Power
$xValue = $xValue * $xValue;
$yValue = $yValue * $yValue;
$zValue = $zValue * $zValue;
float $xyzValue = $xValue + $yValue + $zValue;
		    
//Mag written out by hand
float $distance = `sqrt $xyzValue`;

 

0 Likes
Message 3 of 5

mcw0
Advisor
Advisor

So was "doing the math" faster than the "mag" function?

Message 4 of 5

malcolm_341
Collaborator
Collaborator

So on my machine I never had the problem, mag and hand written math both run the same speed, but on another person's machine they say it runs faster now that I updated the script to use the long hand math. That person sent me a bug report about the script being laggy on their machine, I couldn't repro it on my machine, but if they're happy with the new code then that's good enough for me.

0 Likes
Message 5 of 5

mcw0
Advisor
Advisor

Thank you for the feedback.  Good to know.

0 Likes