Home Technical Talk

MEL Script ordering issues

polycounter lvl 11
Offline / Send Message
MattyWS polycounter lvl 11
Hello all! I'm taking my first steps into MEL scripting for work, I've done things in other languages before but new to MEL. I only needed some basic stuff and it seemed as I was testing each line of this code separately, they all work fine, but I run the whole script and it seems to either do things in the wrong order or just ignores setting the pivot points to 0,0,0. Would anyone know why this is? And if so, how would I make these commands run in the order that they are in the script? Thanks!

EDIT:: Scratch that! I found that it's not setting the World Scale Pivot or Local Scale Pivot to 0. How would one do that?
//Selects everything in the scene
select -all;

//Sets pivots to 0
xform -ws -a -rp 0 0 0;

//Freezes all transforms to 0
performFreezeTransformations(0);


//Scales to 0.01 on all axis
scale -xyz 0.01 0.01 0.01;

//Freezes all transforms to 0
performFreezeTransformations(0);

Replies

  • JohnnyRaptor
    Options
    Offline / Send Message
    JohnnyRaptor polycounter lvl 15
    use this xform instead,

    xform -ws -a -piv 0 0 0;


    the -piv does rotation and scale pivot in one go,
  • Bartalon
    Options
    Offline / Send Message
    Bartalon polycounter lvl 12
    You can also use makeIdentity instead of performFreezeTransformations. It gives better control, so if you ever need to make it ignore translation, rotation, scale, joints, and/or normals you can do that by switching some values/flags.

    You should also be able to remove one of those Freeze Transformation commands by making your scale of .01 relative (ignoring current scale values). Assuming this is just to scale down all your models, I'd also recommend deleting history or you could get some funky results when transforming things you might have missed deleting history on; using a select -all command will also select history nodes.
    //Clears construction history, do not use if you have weighted skins in your scene
    DeleteAllHistory;
    
    //Selects everything in the scene 
    select -all;  
    
    //Sets pivots to 0 
    xform -ws -a -piv 0 0 0;  
    
    //Scales down to 0.01% on all axis 
    scale -r -dph 1 -xyz 0.01 .01 .01;
    
    //Freezes all transforms to 0 
    makeIdentity -apply true -t 1 -r 1 -s 1 -n 0;
    
    
  • MattyWS
    Options
    Offline / Send Message
    MattyWS polycounter lvl 11
    use this xform instead,

    xform -ws -a -piv 0 0 0;


    the -piv does rotation and scale pivot in one go,
    That worked perfectly thank you! I still have a lot to learn.. I haven't found an amazing amount of documentation on MEL and what all of the different commands do (had no idea about -piv for example) Is there a decent place where all of this info is in one area? =S

    Thanks for the suggestions Bartalon, I'll have to try things out and see what does what. At the moment the reason for this simple script is because most people where I work use Max and our game engine of choice is Unity, but I prefer models being clean and at the correct scale which is seemingly hard to do when going from Max to Unity. So I open up the .FBX and do this process quite regularly to make sure everything is at the right scale and no random rotations/pivot locations etc. They're all static assets so there's no worry of joints and history but I can imagine I'll need to look into it for another time.

    I've even written a C# script for importing models in Unity for the first time setting scalefactor and material folder locations and other settings~ Automating as much as I can. :)

    Thanks again for the help guys!
Sign In or Register to comment.