speeding up the shrinkwrap process

61 views
Skip to first unread message

s...@weacceptyou.com

unread,
Oct 20, 2016, 3:52:05 PM10/20/16
to Python Programming for Autodesk Maya
hello,

i am using some code to shrinkwrap curves to a large mesh. i have written an example test scene which generates a sphere with a large number of subdivisions and a nearby curve. Then the next chunk of code shrinkwraps the curve to the sphere.

################################################################
import pymel.core as pm

cmds.polySphere(n='sphere',sx=400, sy=400)

curve=cmds.curve( d=3,ep=[(3, 3, 0), (4, -2, 0), (1, 3, 2), (1, 3, 4)] )

shrinkWrapNode = pm.deformer(curve, type='shrinkWrap')[0]
pm.PyNode("sphere").worldMesh[0] >> shrinkWrapNode.targetGeom
shrinkWrapNode.projection.set(4) # closest
shrinkWrapNode.closestIfNoIntersection.set(True)
################################################################

As the mesh is large it takes a second or two i guess to load the mesh and then shrinkwrap the curve. But as i have a large number of curves that i need to shrinkwrap one by one, it has to reload the mesh every time the shrinkwrapping happens. and therefore takes a long time.

i was wondering if there was a way of adding a line or something which makes the shrinkwrap node remember the mesh from the previous shrinkwrapping and so it only loads the mesh once and then is super fast for the rest of the curves

thanks alot,
Sam

Neil Roche

unread,
Oct 21, 2016, 7:55:41 AM10/21/16
to Python Programming for Autodesk Maya, s...@weacceptyou.com
You can use just one piece of geo and one shrinkWrap node for multiple pieces of geometry.

If you select all your curves and the geo and shrinkWrap there is a flag in the options to use one shrinkWrap node.  In the code you just parse in a list of curve as an argument to the deformer command

This code will work if you have all your curves selected. Also if you create the sphere using pymel and assign it to a variable you don't need to use the PyNode class when connecting the worldMesh attribute.


##############################################
import pymel.core as pm

curves = pm.selected()
sphere = pm.polySphere(n='sphere',sx=400, sy=400)[0]
shrinkWrapNode = pm.deformer(curves, type='shrinkWrap')[0]
   
sphere.worldMesh[0] >> shrinkWrapNode.targetGeom

s...@weacceptyou.com

unread,
Oct 21, 2016, 9:02:03 AM10/21/16
to Python Programming for Autodesk Maya, s...@weacceptyou.com
wow thanks Neil, this is just what i was after.

Though what if there is a loop and on each iteration a new curve is generated and needs to be shrinkwrapped and then on the next iteration another curve is generated and gets shrinkwrapped, one after another. Is it possible to use the same shrinkwrap node for individual curve selection and shrinkwraps?

thanks,
Sam

Neil Roche

unread,
Oct 21, 2016, 9:56:04 AM10/21/16
to Python Programming for Autodesk Maya, s...@weacceptyou.com
Maybe.  You might be able to use the deformer command but in edit mode.  If you have already created your shrinkwrap node and assigned it to a variable you should be able to use the edit keyword argument and add the curve using the geometry keyword argument  to the shrinkwrap node.

Something like:
for crv in curves:
    pm.deformer( shrinkWrapNode, e=True,  g =  crv)

I've not been able to test this out though...


s...@weacceptyou.com

unread,
Oct 21, 2016, 10:44:43 AM10/21/16
to Python Programming for Autodesk Maya, s...@weacceptyou.com
thanks, will try this tonight

cheers,
Sam
Reply all
Reply to author
Forward
0 new messages