Search code examples
3dmaya

How can I flatten a selection of points


I need to flatten a selection of points on their LOCAL normal axis. I'm assuming that if the normals are correct, that this axis will always be the same regardless if they select points from any side of the object?

To visually represent what I'm trying to achieve, I'd like to turn this:

enter image description here

Into this programmatically:

enter image description here

If I set my scale tool to 'Normals Average', and manually scale them, I can flatten the points to a plane, however I need to calculate or do this by code.

I've looked at the polyMoveFacet command and it has a flag called localScaleZ, which even has 'Flattening' written in it's description, but I've had no luck. Any suggestions?


Solution

  • Easiest would be to just use the same thing your doing manually. The code for doing that in mel would look as follows:

    { // protect global namespace
         setToolTo Scale;
         manipScaleContext -e -mode 9 Scale;
         $oa = `manipScaleContext -q  -orientAxes Scale`;
         $p = `manipScaleContext -q  -position Scale`;
         scale -ws -r 
               -p ($p[0]) ($p[1]) ($p[2]) 
               -oa ($oa[0]+"rad") ($oa[1]+"rad") ($oa[2]+"rad") 
                0 1 1;
    }
    

    And Python:

    cmds.setToolTo('Scale')
    cmds.manipScaleContext("Scale", e=1, mode=9)
    p = cmds.manipScaleContext("Scale", q=1, p=1)
    oa = cmds.manipScaleContext("Scale", q=1, oa=1) 
    cmds.scale(0,1,1, 
               p=(p[0],p[1],p[2]),
               oa=("%srad"%oa[0],"%srad"%oa[1],"%srad"%oa[2]))