Home Technical Talk

[Maxscript] Making UV mapping suck a bit less.

Hello all.

I've been working on a tool to help me save some time unwrapping by eliminating the time spent changing modes, aligning faces, etc. Namely, it's to get UVs done right where automatic methods such as box, cylinder, unwrap/normal, etc. tend to fail. I spent a little bit of time recording a demo of it in use [ame="http://www.youtube.com/watch?v=lvZtIepbt_0"]here[/ame] (four minutes in is where the tool's use begins). I've gotten the core mechanics of the tool worked out and am beginning to look at how to implement it for regular use in a workflow. As I continue using this tool, I've come to realize that being able to bind buttons to keyboard commands would be absolutely amazing for such a monotonous task. I looked into macro-scripts, but I'm not entirely sure if it'll work that way because of the variables involved.

The three buttons used to record the face(s) and edges each store node IDs and locations to variables. I only have a button to move face(s) for stitching for now, but I'll have many more when the thing is done. Before I move on, I'd like to see how far I can control a UI.

From what I understand, macro-scripts are meant for simple copy/pasting from the Listener. Would variables outside of system globals still work as a macro-script? How would I go about having each individual macro-script pull a variable out of other macro-scripts?
I also cant seem to find the /UserMacros folder mentioned in the Maxscript Help. Is it in a hidden folder somewhere or do you have to create it yourself? If you have to create

Replies

  • zeph483
    Options
    Offline / Send Message
    Bump. In the time it took this first post of mine to become verified, it's moved over to the third page. Pushing it back to the top so it might find people who know about macro-scripts.
  • Ott
    Options
    Offline / Send Message
    Ott polycounter lvl 13
    I don't want to derail you or be a dick, but you could have unwrapped all of the non-planar pieces with Unfold mapping. No stitching, aligning, etc. needed. Make a hotkey for Unfold Mapping.

    All of the planar could have been done with Quick Planar along the Z-axis.

    Also, bind a hotkey to Stitch Selected. If you get a set of pieces that don't unfold perfect, flatten map, then hotkey Stitch edges for ubar fast unwrapping.

    I would also turn "By Angle" selection on in your default settings for face mode. All of the faces along a flat surface could be selected with one click.

    I see a LOT of clicks and a 6 minute unwrap of something that could be done in about 10 clicks and 20 seconds if you know the default tools. THAT is what makes unwrapping suck less ;)
  • Mark Dygert
    Options
    Offline / Send Message
    I haven't checked out the video (I don't have the 13 min to spare sorry) but I can kind of help you with some pointers about maxscript.

    You can trigger another script with the "fileIn" command.

    You can package your scripts up in a .mzp fiile which is just a renamed zip. With a little work and research you can get a .mzp file to install multiple scripts and folders to multiple places. Then inside the scripts you call out to each other. The best way to research it is to pull apart other scripts and do some checking with the maxscript help file.

    The "usermacros" folder is burred pretty deep, its probably easier to find if you search for it. For me its found in:
    C:\Users\YourName\AppData\Local\Autodesk\3dsMax\2011 - 64bit\enu\UI\usermacros
    But different versions of windows and 3dsmax have it in different places. But you don't nessesarily have to install scripts there you can put them pretty much anywhere you want as long as the paths are valid in your scripts. I prefer to dump my scripts in the max directory under "scripts/vigTools"

    As far as navigating to and from external folders via maxscript, the help file covers that under "External File Methods".

    Hope that helps!
  • monster
    Options
    Offline / Send Message
    monster polycounter
    If you want to create hotkeys from the Dialog buttons you created there's two things you can do.

    1. The best way, I think, is to make each button into a MacroScript, and have the button and hotkey execute the same MacroScript.

    2. The other way, is to create a MacroScript that looks for the dialog and executes the button press. I don't like this way as much because it requires the dialog to be open in order for the action to take place.

    To answer your other questions:

    Would variables outside of system globals still work as a macro-script? How would I go about having each individual macro-script pull a variable out of other macro-scripts?

    A global variable can be accessed from any script. If you create global variables try to give them extremely unique names, this can help prevent conflicts with other scripts a user might install.


    I also cant seem to find the /UserMacros folder mentioned in the Maxscript Help. Is it in a hidden folder somewhere or do you have to create it yourself?

    Because Microsoft and Autodesk are purposely trying to make life harder for everyone with each new software release: (For Windows XP)

    C: \Users\[username]\AppData\Local\Autodesk\3dsMax\2011 - 64bit\enu\UI\usermacros\

    You can change this if you go to: Customize | Configure System Paths... | System | Additional Macros | Modify
  • MattLichy
    Options
    Offline / Send Message
    Yeah, Ott said what I was thinking. It's great your learning maxscript, but honestly you can do all of that stuff with hotkeys and Quick Planar map or flatten mapping.

    For something like that, I'd just personally flatten map, then I had stitch set to Shift + S, and I just quickly select edges and run that shortcut and get it all stitched up , then relax or relax before hand and I'm done.
  • renderhjs
    Options
    Offline / Send Message
    renderhjs sublime tool
    idea...
    I was once working on a similar script that would rotate flattend UV clusters to readable directions, because often they appear flipped (180 turn or 90 or just random). It happened to many times that I stitched wrong verts because things looked right but were actually turned wrong or flipped on a axis. For that I guess it would be worth to write a script that aligns shells in a readable order.

    Variables in MXS
    variables are accessible once they are initialed, you can work with global variables but I personally I am not a fan of them as they should only be used if there is no other way. You could initialize the variables by placing a *.ms file (your script) in the userScript/starup folder which would run the script every time you start max. With that variables that you declare outside of function should be accessible from anywhere else likewise. Same of course with the function names, once they are in memory (like the script was run before) they are accessible later on, this lasts as long as your 3dsMax session runs.

    MacroScripts
    The way I do things with macroscripts is to just place the methods at the end of the functions in my script to create the macroscripts. It won't reset any settings of shortcut assignments as they are preserved but it makes sure that functions, variables are in place with the macroscripts so that booth can communicate with each other for sure. This also results in just mascript (*.ms) file which is clean and easier to catch up with later on.


    if you are into it, why not share the code you have, we might be able to give you some advice on how to clean up things and what good strategies are to make things readable and easy to work with (code wise) ;)
  • zeph483
    Options
    Offline / Send Message
    Yeah, I understand that there are other ways to get this done and this does look like a waste of time and effort without context. What's spurred me into making this is the discrepancy in scale with the different methods. The environment I'm making for a game will end up with a large amount of brick and stone textures on buildings and landscaping. If you use unfold mapping on one side of a building, a cylindrical on a second side, and a best planar map on a third, you end up with three differently scaled nodes. Not a big deal independently, but a good problem if a player stops at a corner and noticeably sees two differently sized bricks meeting at the edge. A bigger problem if that person so happens to be a person I've sent my portfolio to hoping to get a job.

    There are ways to get around that, and is definitely in the plan, but the biggest problem would be the framework of moving nodes to where they should be and putting them together. Scaling a node to match the size of another node based on the discrepancy of two shared edges is simple algebra. Rotating nodes so two shared edges line up, as well, is simple algebra. Getting the tool set up so something like pressing control+shift+z/x/c (for example) after selecting some faces and two edges will automatically start a script to check for inverted normals in the selection, assure that edges are properly aligned, make sure the texel density for both nodes is going to be the same, etc., and then automatically align/stitch is where the real magic is.

    Chugging through something like in that video lets me see what a workflow where everything is already mapped and just needs to be put together is like. For instance, with all the monotony of aligning faces out of the way, I realized moving the mouse around after making selections was a time and accuracy sink. Thus, I started looking into macroscript hotkeys :p. I don't have the time, or a completed tool, for a pretty tech demo yet.
    I would also turn "By Angle" selection on in your default settings for face mode. All of the faces along a flat surface could be selected with one click.
    Where is this? For ages I've looked for a 'select parallel' equivalent.
    If you want to create hotkeys from the Dialog buttons you created there's two things you can do.

    1. The best way, I think, is to make each button into a MacroScript, and have the button and hotkey execute the same MacroScript.

    2. The other way, is to create a MacroScript that looks for the dialog and executes the button press. I don't like this way as much because it requires the dialog to be open in order for the action to take place.
    I like the idea of option 1 as it's more idiot proof, but when it comes down to it, I'll have to go with option 2. When selecting both the edge that needs to be moved and the destination edge, I have no way of determining which is which unless different code is executed.
    The best way to research it is to pull apart other scripts and do some checking with the maxscript help file.
    I was going through TexTools looking for info on stitching (thought there had to be an edge equivalent of stitchVertsNoParams) and saw they used filein for nearly everything. I'll reference that for fileins. Now that I know the variables will hold over between macros, I'll run a check to see if the variables I use are defined when the tool is used. If not, I'll declare them and have the script move along.


    As for key combinations, any suggestions?
  • sprunghunt
    Options
    Offline / Send Message
    sprunghunt polycounter
    zeph483 wrote: »
    If you use unfold mapping on one side of a building, a cylindrical on a second side, and a best planar map on a third, you end up with three differently scaled nodes.

    Relax by face angle fixes this ^^^^ It'll scale any two faces until they're the same proportions as they are on the model.

    Stitch selected handles the rotation and alignment. Alignment tools can still be useful though.
    zeph483 wrote: »
    Where is this? For ages I've looked for a 'select parallel' equivalent.

    Select by planar angle is in the modify menu of the object.

    While it might be useful to do this as a learning exercise I agree with Ott that these things are not really improving on the existing tools in max.
  • Mark Dygert
    Options
    Offline / Send Message
    zeph483 wrote: »
    If you use unfold mapping on one side of a building, a cylindrical on a second side, and a best planar map on a third, you end up with three differently scaled nodes.
    Also check out the Normalize function of TexTools lowest left button. It will scale or Normalize the UV shells to more or less match in scale. Which is something the relax feature does but with Normalize it's not going to relax the faces as it normalizes.

    zeph483 wrote: »
    I would also turn "By Angle" selection on in your default settings for face mode. All of the faces along a flat surface could be selected with one click.
    Where is this? For ages I've looked for a 'select parallel' equivalent.
    It's in the main UI command panel under the modifier stack in "Selection Parameters", down under "Ignore Backfacing" and "Select by Element", it is not in the UV editor window. You will need to be in face mode for it to activate, then you can turn it on and specify the planar angle.

    As for stitching its best done in edge mode and you can select multiple edges, as in select a edge click loop and stitch to sew a long seam. Or click an edge, and grow the selection a few edges then stitch (it grows along the edge not like in edit poly where it just expands the selection regardless). You can also stitch every other edge to close gaps a little faster.

    With the UV editor keyboard shortcuts get a little confusing at first because it is a sub-menu and shares many of the shortcuts with the main max menu. To activate them you need to turn on Keyboard Shortcut Override in the main max menu. This will tell max to override the main max shortcuts with those of the UV editor.
    3dsmax_KBOS.jpg

    You can also get around having to turn this on by unbinding the shortcuts from all other menus. Main Menu > Customize > Customize UI and in the "Hotkey box" type the shortcut you wish to unbind and click remove until it says <Not Assigned> then go bind the command you want.

    Also when customizing shortcuts you want to change the "Group" to "Unwrap UVW". If you change the Category to "UVW Unwrap" you'll be changing the shortcuts for an entirely different modifier and not much will seem to change even with KBSO on.

    So "Group: Unwrap UVW" not "Category: UVW Unwrap"

    Some people like renderhjs (author of TexTools if you haven't guesses yet) get around this by launching the UV Editor from a script and define their custom parameters then, such as turn on KBSO.

    My shortcuts look like this:
    (mind you they are mix of logical ie b=break and convenient T,Y,U.)
    S = Stitch
    B = Break
    R = Relax
    Ctrl+R = Relax dialog
    T = Cylindrical Map
    Y = Box Map
    U = Quick Planar

    Right Click Quad Menu:
    Normalize (triggers MoP's Normalize script, its included with some upgrades textools, I'm too lazy to redo the bind)
    Pack
Sign In or Register to comment.