New tool for Maya -- AutoHighPoly! (beta)

polycounter lvl 6
Offline / Send Message
artquest polycounter lvl 6

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

Sign In or Register to comment.