Home Technical Talk

New tool for Maya -- AutoHighPoly! (beta)

polycounter lvl 14
Offline / Send Message
artquest polycounter lvl 14

Auto High Poly (maya 2016 EXT 2 ONLY!)



Hi everyone! So after a loong time of messing around with mel I've finally gotten the time to put this together to share with the community! Just take my script and make it a button on your shelf! After that the rest is easy, just follow the instructions below (animated gif!). 

Notes:
- Preview mode button works like a toggle, turn it on and off whenever you like.
- the script relies on the new bevel node introduced in maya 2016 EXT 2. You can still play with the bevel node settings after pressing the finalize button.  I may add a way to expose those settings from the script later. Not sure yet.

- Works on multiple selected objects.

- ops! For now you'll have to edit the temp file import/export because I forgot to make sure it's not hard coded. change "C:/Users/Joel/Documents/temp.mb"; to your username in 2 places and you should be good to go. EDIT: this is now fixed.

Disclaimer: This is a beta and to be honest some of the code is pretty janky right now. I've had the Revert button sometimes delete the entire model from the scene and not replace it with the low poly. This will be fixed soon but just so you're aware... save early and often! Please feel free to report bugs here as well! use at your own risk. :)

Animated Gif Instructions:




Known Bugs and limitations:



* if you have multiple objects in your scene and you select only one to finalize, selecting another mesh in the scene and clicking revert will delete the selected mesh and import the last finalized mesh and not the currently selected mesh.

* using smooth on the mesh preview version will clear all of your hard/soft edges.

* you can use the preview button and then finalize for a "3" display version of your model with holding edges added. But pressing preview after finalizing will cause smoothing errors.

* using finalize breaks undo at the moment  -- will be fixed soon.

* Preview will work on multiple meshes but using the finalize button on multiple meshes will not work and it will lock you into only being able to select hard edges. Select a single mesh and run the finalize again to fix this.  -- FIXED!



And Here's the code!

// a function to be called when the button gets clicked.

proc highPolyPreview() {

string $sel[] = `ls -sl`;

string $shape[] = `listRelatives -type mesh $sel`;

int $currentCrease = `getAttr ($shape[0]+".smoothLevel")`;



// TURN ON

if ($currentCrease == 0 || $currentCrease == 2)

{

for ($i=0; $i<(size($shape)); $i++)

{

if ($sel[$i]==""){break;}

select $sel[$i];

polySelectConstraint -m 3 -t 0x8000 -sm 1; // to get hard edges

polyCrease -value 3.0;

displaySmoothness -divisionsU 3 -divisionsV 3 -pointsWire 16 -pointsShaded 4 -polygonObject 3;

setAttr ($shape[$i]+".smoothLevel") 4;

polySelectConstraint -sm 0; // turn off edge smoothness constraint

select $sel;

}

}

//TURN OFF

//Toggle off high poly preview

else

{

for ($i=0; $i<(size($shape)); $i++)

{

if ($sel[$i]==""){break;}

select $sel[$i];

displaySmoothness -divisionsU 0 -divisionsV 0 -pointsWire 4 -pointsShaded 1 -polygonObject 1;

PolyRemoveAllCrease;

setAttr ($shape[$i]+".smoothLevel") 2;

select $sel;

}

}



}







// a function to be called when the button gets clicked.

proc finalizeMesh() {

//EXPORT

file -force -options "v=0" -typ "mayaBinary" -pr -es "Documents/temp.mb";



string $sel[] = `ls -sl`;

for ($x in $sel)

{

select $x;

polySelectConstraint -m 3 -t 0x8000 -sm 1; // to get hard edges

polyBevel3 -fraction 0.5 -offsetAsFraction 1 -autoFit 1 -depth 1 -mitering 0 -miterAlong 0 -chamfer 0 -segments 1 -worldSpace 1 -smoothingAngle 30 -subdivideNgons 1 -mergeVertices 1 -mergeVertexTolerance 0.0001 -miteringAngle 180 -angleTolerance 180 ;

polySelectConstraint -sm 0; // turn off edge smoothness constraint

}

}



proc revertMesh() {

ls -sl;

delete;



ls -sl;

delete;



//IMPORT

file -import -type "mayaBinary" -rpr "temp" -options "v=0" -pr -loadReferenceDepth "all" "Documents/temp.mb";



}



// create a window

window;

if (`window -exists autoHighPoly`) deleteUI autoHighPoly;

window -title "autoHighPoly" -widthHeight 300 194 autoHighPoly;

if (`windowPref -exists autoHighPoly`) windowPref -remove autoHighPoly;

showWindow autoHighPoly;

// define the layout of controls added

// to the window.

columnLayout;

columnLayout -adjustableColumn true;





setParent ..;

columnLayout -h 62 -cat "both" 0 -cal "center" -cw 300;

// create a button

button -label "Preview" -h 60 -w 300 -command "highPolyPreview" ;



setParent ..;

columnLayout -h 62 -cat "both" 0 -cal "center" -cw 300;

// create a button

button -label "Finalize" -h 60 -w 300 -command "finalizeMesh" ;



setParent ..;

columnLayout -cat "both" 0 -cal "center" -cw 300;



// create a button

button -label "Revert " -h 60 -w 300 -command "revertMesh" ;

// show the window we last created

showWindow autoHighPoly;





Replies

  • SwdPwnzDggr
    Offline / Send Message
    SwdPwnzDggr polycounter lvl 7
    Looks potentially amazing.
  • vickgaza
    Offline / Send Message
    vickgaza polycounter lvl 6
    I`ll give this a try, thanks for sharing ! 
  • Seehr
    Offline / Send Message
    Seehr polycounter lvl 10
    Nice. I always love maya tools. This looks promising.
  • Seehr
    Offline / Send Message
    Seehr polycounter lvl 10
    Nice. I always love maya tools. This looks promising.
  • Rav3
    Offline / Send Message
    Rav3 interpolator
    There's same technique in max just bind group autosmooth to hotkey and this macro :)

    (Max script)

    macroScript chamferEdges
    category:"User group"
    toolTip:"Quad chamfer edges"
    (
    a = $
    b = Chamfer()
    addmodifier a b
    $.modifiers[#Chamfer].smoothingoption = 2
    $.modifiers[#Chamfer].tension = 0
    $.modifiers[#Chamfer].amount = 0.2
    $.modifiers[#Chamfer].smooth = off

    --another version
    -- a = $
    -- addmodifier a (Chamfer smoothingoption:2 tension:0 amount:0.2)


    )
  • Hany13
    Offline / Send Message
    Hany13 polycounter lvl 4
    Awesome script , the preview works 10/10 !!
    But as a feedback when pressing finalize i am getting this error : 
    // Error: line 57: Invalid flag '-depth'



    but thanks a lot for the script <span>:smiley:</span>
  • pasha_sevez
    Offline / Send Message
    pasha_sevez polycounter lvl 13
    Hany13 said:
    Awesome script , the preview works 10/10 !!
    But as a feedback when pressing finalize i am getting this error : 
    // Error: line 57: Invalid flag '-depth'



    but thanks a lot for the script <span>:smiley:</span>
    Because this script works only in Maya 2016 Extension 2, but not in Maya 2016!
  • toby.rutter
    Offline / Send Message
    toby.rutter polycounter lvl 7
    Looks super nice, now time to pull down 2016 Extension 2
  • artquest
    Offline / Send Message
    artquest polycounter lvl 14
    Fixed a few things and updated the code! You now no longer need to edit anything in the code, just make it a button and go go go! I've also added a bug list to the first post.
  • beefaroni
    Offline / Send Message
    beefaroni sublime tool
    Woah woah woah! Going to test this weekend!
  • Oniram
    Offline / Send Message
    Oniram polycounter lvl 17
    amazing dude! Im so happy about this!!!
  • dkorch
    Offline / Send Message
    dkorch polycounter lvl 17
    Hopefully you dont mind, but I made a fix for you so that it will work in 2015.   The function for polybevel had different attr names that was causing errors. Also I added two lines in it to turn off the smooth display after finalize and to smooth out the normals after finalize.

    Code below.

    // a function to be called when the button gets clicked.
        proc highPolyPreview() {
        
        string $sel[] = `ls -sl`;
    string $shape[] = `listRelatives -type mesh $sel`;
    int $currentCrease = `getAttr ($shape[0]+".smoothLevel")`;


    // TURN ON
    if ($currentCrease == 0 || $currentCrease == 2)
    {
        for ($i=0; $i<(size($shape)); $i++)
        {
           if ($sel[$i]==""){break;}
           select $sel[$i];
           polySelectConstraint -m 3 -t 0x8000 -sm 1; // to get hard edges
           polyCrease -value 3.0;
           displaySmoothness -divisionsU 3 -divisionsV 3 -pointsWire 16 -pointsShaded 4 -polygonObject 3;
           setAttr ($shape[$i]+".smoothLevel") 4;
           polySelectConstraint -sm 0; // turn off edge smoothness constraint
           select $sel;
        }
    }
    //TURN OFF
    //Toggle off high poly preview
    else
    {
        for ($i=0; $i<(size($shape)); $i++)
        {
            if ($sel[$i]==""){break;}
            select $sel[$i];
            displaySmoothness -divisionsU 0 -divisionsV 0 -pointsWire 4 -pointsShaded 1 -polygonObject 1;
            PolyRemoveAllCrease;
            setAttr ($shape[$i]+".smoothLevel") 2;
            select $sel;
        }
    }


        }






    // a function to be called when the button gets clicked.
        proc finalizeMesh() {
    //EXPORT
    file -force -options  "v=0" -typ "mayaBinary" -pr -es  "Documents/temp.mb";




    string $sel[] = `ls -sl`;
    polySelectConstraint -m 3 -t 0x8000 -sm 1; // to get hard edges
    //polyBevel -fraction 0.5 -offsetAsFraction 1 -autoFit 1 -depth 1 -mitering 0 -miterAlong 0 -chamfer 0 -segments 1 -worldSpace 1 -smoothingAngle 30 -subdivideNgons 1 -mergeVertices 1 -mergeVertexTolerance 0.0001 -miteringAngle 180 -angleTolerance 180 ;  NEW MAYA CALL, BELOW LINE IS OLD MAYA CALL
    polyBevel  -com 0 -fraction 0.5 -offsetAsFraction 1 -autoFit 1 -segments 1 -worldSpace 1 -uvAssignment 0 -smoothingAngle 30 -fillNgons 1 -mergeVertices 1 -mergeVertexTolerance 0.0001 -miteringAngle 180 -angleTolerance 180 -ch 1;


    polySelectConstraint -sm 0; // turn off edge smoothness constraint
    displaySmoothness -divisionsU 0 -divisionsV 0 -pointsWire 4 -pointsShaded 1 -polygonObject 1; //turning off smooth display function

    polySoftEdge -a 180 -ch 1;
            
    }



    proc revertMesh() {
            ls -sl;
    delete;


    ls -sl;
    delete;


    //IMPORT
    file -import -type "mayaBinary" -rpr "temp" -options "v=0" -pr -loadReferenceDepth "all" "Documents/temp.mb";


        }


        // create a window
        window;
    if (`window -exists autoHighPoly`) deleteUI autoHighPoly;
    window -title "autoHighPoly" -widthHeight 300 194 autoHighPoly;
    if (`windowPref -exists autoHighPoly`) windowPref -remove autoHighPoly;
    showWindow autoHighPoly;
            // define the layout of controls added
            // to the window.
            columnLayout;
    columnLayout -adjustableColumn true;




    setParent ..;
    columnLayout -h 62 -cat "both" 0 -cal "center" -cw 300;
                // create a button
                button -label "Preview" -h 60 -w 300 -command "highPolyPreview" ;
                


    setParent ..;
    columnLayout -h 62 -cat "both" 0 -cal "center" -cw 300;
                
                    // create a button
                button -label "Finalize" -h 60 -w 300 -command "finalizeMesh" ;


    setParent ..;
    columnLayout -cat "both" 0 -cal "center" -cw 300;


        // create a button
                button -label "Revert " -h 60 -w 300 -command "revertMesh" ;
                
                
        // show the window we last created
    showWindow autoHighPoly;


  • artquest
    Offline / Send Message
    artquest polycounter lvl 14
    dkorch said:
    Hopefully you dont mind, but I made a fix for you so that it will work in 2015.   The function for polybevel had different attr names that was causing errors. Also I added two lines in it to turn off the smooth display after finalize and to smooth out the normals after finalize.


    Yeah, totally feel free to test it out in 2015. But I will warn you that the bevel in 2015 may not produce very good results!
  • tkvtoons
    Offline / Send Message
    tkvtoons vertex
    artquest said:
    Known Bugs and limitations:

    * Preview will work on multiple meshes but using the finalize button on multiple meshes will not work and it will lock you into only being able to select hard edges. Select a single mesh and run the finalize again to fix this.

    Try this for finalizing multiple meshes:
    string $sel[] = `ls -sl`;
    for ($x in $sel)
    {
        select $x;
        polySelectConstraint -m 3 -t 0x8000 -sm 1; // to get hard edges
        polyBevel3 -fraction 0.5 -offsetAsFraction 1 -autoFit 1 -depth 1 -mitering 0 -miterAlong 0 -chamfer 0 -segments 1 -worldSpace 1 -smoothingAngle 30 -subdivideNgons 1 -mergeVertices 1 -mergeVertexTolerance 0.0001 -miteringAngle 180 -angleTolerance 180 ;
        polySelectConstraint -sm 0; // turn off edge smoothness constraint
    }


  • artquest
    Offline / Send Message
    artquest polycounter lvl 14
    That works beautifully! Thanks TKV!
  • dkorch
    Offline / Send Message
    dkorch polycounter lvl 17
    I forgot to say, great tool/idea btw. this will help me alot.
  • Puzzledust
    Offline / Send Message
    Puzzledust polycounter lvl 4
    I just wanted to say thanks for doing this.  I can't wait to see how this tool progresses.  
  • Jaston3D
    Offline / Send Message
    Jaston3D polycounter lvl 8
    Wait Maya doesn't have any type of quad chamfer based on smoothing tool already?!
  • CreativeSheep
    Offline / Send Message
    CreativeSheep polycounter lvl 8
    Maybe he will expand on this tool.
  • cid_carlos
    Offline / Send Message
    cid_carlos polycounter lvl 2
    looks really cool, thanks!!
  • artquest
    Offline / Send Message
    artquest polycounter lvl 14
    Maybe he will expand on this tool.
    I just added automatic UVs based on hard edges as well. The only use case it fails on so far is a cylinder since it's kind of rare that you want to bevel anything but the caps. 
  • kosmoski
    Offline / Send Message
    kosmoski polycounter lvl 12
    What sorcery is this!  Really cool. :)
  • ericktjoe
    Offline / Send Message
    ericktjoe polycounter lvl 4
    Thanks, works nicely. Too much fun and I overdid it with complex geo plus lots of n-gons and it crashed  :D
  • Shanteez
    Offline / Send Message
    Shanteez polycounter lvl 5
    Thanks this is pretty handy :smile:
  • artquest
    Offline / Send Message
    artquest polycounter lvl 14
    ericktjoe said:
    Thanks, works nicely. Too much fun and I overdid it with complex geo plus lots of n-gons and it crashed  :D
    I need to update the script. I think in the first version it keeps smooth preview turned on when adding bevels. Which is a very bad idea and an oversight. I'll fix that up soon.
  • CarlK3D
    Offline / Send Message
    CarlK3D polycounter lvl 7
    Would love to try this out on 2016 SP5. really cool script so far
  • mannyn
    Offline / Send Message
    mannyn null
    Wow, that looks super. Looking forward to trying that out! Keep up the great work :smiley:
  • pixelpatron
    Offline / Send Message
    pixelpatron polycounter
    So there is no control on the crispness of the edges it generates?
    This could be amazing.....if we had control over that.
  • artquest
    Offline / Send Message
    artquest polycounter lvl 14
    So there is no control on the crispness of the edges it generates?
    This could be amazing.....if we had control over that.
    There is control, it just isn't exposed yet. If you want a tight edge just go to the maya bevel node after clicking finalize and adjust the fraction parameter.

  • CarlK3D
    Offline / Send Message
    CarlK3D polycounter lvl 7
    I switched to 2016 SP2 and it says // Error: line 111: Invalid flag '-depth' when I click Finalize
    Ideas?
  • Ryan Spinney
    Offline / Send Message
    Ryan Spinney polycounter lvl 5
    Great tool, I really love it and use it every day!

    Some feedback:

    Issues
    - Pressing 'Revert' on a 'Preview' mesh (that's not been 'Finalized') will cause problems.
    - Pressing 'Revert' when 'Isolate Selection' is enabled: The reverted mesh will not be automatically loaded into the current isolated selection. The user will have to toggle out of isolate selection in order to see the mesh again.

    Suggestions
    - Make the 'Preview' button function even if the user is in component mode (automatically convert selection to mesh before running the 'Preview' operation?) 
    - Add 'Bevel Size' input setting to the UI
    - Add 'Smooth Resolution' input setting to the UI (allow for control of smooth mesh divisons on finalized meshes)
    - Add 'display hard edges colour' toggle button to the UI


    Cheers
  • pixelpatron
    Offline / Send Message
    pixelpatron polycounter
    artquest said:
    So there is no control on the crispness of the edges it generates?
    This could be amazing.....if we had control over that.
    There is control, it just isn't exposed yet. If you want a tight edge just go to the maya bevel node after clicking finalize and adjust the fraction parameter.

    Sorry artquest I don't see the value your trying to describe. I checked the channel box and bevel options and I don't see it. (Maya 2014) Please screenshot or offer me a better description? Much appreciated. (or are you talking about editing something in your script?)
  • artquest
    Offline / Send Message
    artquest polycounter lvl 14
    artquest said:
    So there is no control on the crispness of the edges it generates?
    This could be amazing.....if we had control over that.
    There is control, it just isn't exposed yet. If you want a tight edge just go to the maya bevel node after clicking finalize and adjust the fraction parameter.

    Sorry artquest I don't see the value your trying to describe. I checked the channel box and bevel options and I don't see it. (Maya 2014) Please screenshot or offer me a better description? Much appreciated. (or are you talking about editing something in your script?)

    The bevel options are only available in maya 2016.5 or higher
  • mark lautenbach
    Offline / Send Message
    mark lautenbach polycounter lvl 10
    Bummer. Is there a value in the MEL that I can adjust this manually. Similarly, is there a manual way I can adjust how dense it makes the subdivisions (my comp is kinda wimpy and some of those meshes are a bit dense for it.
Sign In or Register to comment.