1. Are you planning to upload your awesome tool to Hive? Please review the rules here.
    July 9, 2018: The rules for the Tool Section have been revised. Please be sure to read the revisions.
    Dismiss Notice
  2. The Aftermath has been revealed for the 19th Terraining Contest! Be sure to check out the Results and see what came out of it.
    Dismiss Notice
  3. Melee Mapping Contest #3 - Results are out! Congratulate the winners and check plenty of new 4v4 melee maps designed for this competition!
    Dismiss Notice
  4. The winners of our cinematic soundtrack competition have been decided! Step by the Music Contest #11 - Results to check the entries and congratulate the winners!
    Dismiss Notice

MDX/M3 Optimizer

Submitted by GhostWolf
This bundle is marked as approved. It works and satisfies the submission rules.
This tool originates from here

This tool minifies MDX and M3 files.

For MDX files, it does the following:
  • Changes the precision of all the big floating point data sequences (VRTX, NRMS, UVBS, PIVT, all chunks of the form K***).
  • Removes useless key frames.
  • Changes all bezier and hermite keyframes to linear keyframes.

For M3 files, it does the following:
  • Changes the precision of all the big floating point data sequences (vertex positions, REAL, VEC2, VEC3, VEC4, QUAT, BNDS, IREF).

This tool is a command-line tool, meaning there is no graphical user interface.
You can either run it through a console (cmd), which gives you full control over the options (run it with no arguments to see the list of options), or simply grab files or directories and drop them into it, which will use the default values.

The default values are:
  • Floating point precision: 16.
  • Threshold: 0.001.
  • Force linear keyframes: false.

Floating point precision goes from 10 to 32, where 32 does nothing, and 10 will probably make your model useless.
Note that this wont directly reduce the size of the file, however any map that imports that file will be smaller than the same map importing the original file.
This idea was taken from MDX Squisher.

The threshold is used to compare keyframes, you can make it bigger to remove more keyframes, at the risk of getting bad animation data.

Forcing keyframes to be linear means deleting their in/out tangents, which makes every hermite/bezier keyframe take a third of the original size.
This can cause gigantic size reductions for models with many hermite/bezier keyframes, at the cost of a lower quality animation (though in most cases our eyes can't really see the difference).

The zip has three files, copt_win, copt_lin, and copt_mac, for Windows, Linux, and Macintosh respectively.

Keywords:
mdx, m3, squish, compress, minify, optimize
Contents

MDX/M3 Optimizer (Binary)

Reviews
Moderator
21:28, 13th Nov 2013 PurgeandFire: Approved. A great step-up from mdx squisher with its extra options. Useful for any sc2 modder as well.
  1. 21:28, 13th Nov 2013
    PurgeandFire: Approved. A great step-up from mdx squisher with its extra options. Useful for any sc2 modder as well.
     
  2. Statharas

    Statharas

    Joined:
    Jul 9, 2008
    Messages:
    2,337
    Resources:
    14
    Tools:
    1
    StarCraft II Resources:
    5
    Tutorials:
    8
    Resources:
    14
    Baneling compressed, 72.6kb saved :p
     
  3. PurgeandFire

    PurgeandFire

    Code Moderator

    Joined:
    Nov 11, 2006
    Messages:
    7,418
    Resources:
    18
    Icons:
    1
    Spells:
    4
    Tutorials:
    9
    JASS:
    4
    Resources:
    18
    Haven't tested it but it sounds good.

    Does this delete unused bones (ones that aren't connected with vertices)? edit: nvm that may not be the best idea.

    And I haven't checked if it does this already, but does this support batch conversions (e.g. input a folder)? If so, it would be a nice addition and make it far more preferable to Guesst's mdx squisher.
     
  4. GhostWolf

    GhostWolf

    Joined:
    Jul 29, 2007
    Messages:
    4,836
    Resources:
    2
    Tools:
    1
    Tutorials:
    1
    Resources:
    2
    You can input as many files as you want.
    I thought about adding directories as valid inputs, but it would require adding some filesystem library. I'll see if it isn't too annoying.

    /Edit
    Directories are now valid inputs.
    It will search for MDX/M3 files recursively in any directory you specify (meaning it will look also in inner directories). You can grab a directory into it like you can do with files.

    Also added a Linux executable.
     
    Last edited: Nov 2, 2013
  5. GhostWolf

    GhostWolf

    Joined:
    Jul 29, 2007
    Messages:
    4,836
    Resources:
    2
    Tools:
    1
    Tutorials:
    1
    Resources:
    2
    Rewrote it all in C++, so it should be much faster (and the executables are smaller!).

    Also removed the chunk table from being printed, since there is nothing to print for M3 files (their size never changes). Should I put it for MDX files anyway?

    /Edit
    Added a Mac executable, thanks to Magtheridon96 for compiling it.
     
    Last edited: Nov 6, 2013
  6. PurgeandFire

    PurgeandFire

    Code Moderator

    Joined:
    Nov 11, 2006
    Messages:
    7,418
    Resources:
    18
    Icons:
    1
    Spells:
    4
    Tutorials:
    9
    JASS:
    4
    Resources:
    18
    I tried running it on a mac for a directory, and it gave "Oops, Deadeye is not a valid mdx file".

    When I ran it directly on the mdx file, it worked. What method do you use to detect if it is a valid mdx file? I assume you would read the MDX header, but since it works for the direct input and not the directory input I'm guessing it is just a mistake in the directory-related code.

    Code I ran:
    Code (Text):
    exec "$HOME/Downloads/copt/copt_mac" -p 16 -t 0.001 -l true "$HOME/Downloads/UArcherLPFK"
    Here is the model in case it is relevant (although it likely isn't):
    http://www.hiveworkshop.com/forums/models-530/deadeye-113615/
     
  7. GhostWolf

    GhostWolf

    Joined:
    Jul 29, 2007
    Messages:
    4,836
    Resources:
    2
    Tools:
    1
    Tutorials:
    1
    Resources:
    2
    Files without mdx/m3 extensions are blatantly ignored, and for files with either, the first 4 bytes are checked for the magic identifiers (MDLX / MD34).

    I can't test it on Mac because I don't have one. Magtheridon96 did say he made a few changes to make it compile there, though I don't think it's anything that should make the code fail.
    Can't really fix this without being able to compile and run it.
    Does dropping a directory on the executable result in the same error?

    As a side note, specifying -l makes it true, the "true" after it becomes a file input that is ignored because it doesn't have mdx/m3 as an extension.
     
  8. PurgeandFire

    PurgeandFire

    Code Moderator

    Joined:
    Nov 11, 2006
    Messages:
    7,418
    Resources:
    18
    Icons:
    1
    Spells:
    4
    Tutorials:
    9
    JASS:
    4
    Resources:
    18
    Do you have the source on a public repo e.g. github/launchpad?

    edit: Off the top of my head, perhaps it is an endianness issue. OS X is big endian. Maybe Mag made the conversion for direct input reading function but not for the directory reading function? It might explain why the same mdx file is accepted as direct input but not accepted when read from a directory.
     
    Last edited: Nov 12, 2013
  9. GhostWolf

    GhostWolf

    Joined:
    Jul 29, 2007
    Messages:
    4,836
    Resources:
    2
    Tools:
    1
    Tutorials:
    1
    Resources:
    2
    Macs are big endian?
    The code only handles small endian, so even if it does work, it will probably mess the models.

    Here's the source.

    The older code printed the "Oops" message also when it failed to open the file, so that might be the real reason you are getting it.
     
    Last edited: Nov 12, 2013
  10. PurgeandFire

    PurgeandFire

    Code Moderator

    Joined:
    Nov 11, 2006
    Messages:
    7,418
    Resources:
    18
    Icons:
    1
    Spells:
    4
    Tutorials:
    9
    JASS:
    4
    Resources:
    18
    Yeah, could be. Perhaps you should remove copt_mac from it until it is updated. I'll run some quick tests on my Windows comp and then it should be approvable.

    If you're still interested in having a mac-friendly version, I'd do something like this:
    Code (C++):
    #ifdef __BIG_ENDIAN__

        #ifdef __APPLE__ && __MACH__

            #include <CoreFoundation/CFByteOrder.h>

            #define swapInt16(x) CFSwapInt16HostToLittle(x)
            #define swapInt32(x) CFSwapInt32HostToLittle(x)

        #else
            #error unsupported operating system
        #endif

    #else
       
        #define swapInt16(x) (x)
        #define swapInt32(x) (x)

    #endif
     


    And write functions to swap the struct members after you've read them from the file, or however you want to do it really. Although, it obviously will be difficult to implement without having a Mac yourself. Pester Mag about it. :thumbs_up:
     
  11. PurgeandFire

    PurgeandFire

    Code Moderator

    Joined:
    Nov 11, 2006
    Messages:
    7,418
    Resources:
    18
    Icons:
    1
    Spells:
    4
    Tutorials:
    9
    JASS:
    4
    Resources:
    18
    Sorry for the double post, but the directory input isn't working for me on Windows either. It just shows that all the mdx files are invalid.

    Code (Text):
    cd "C:/Program Files/Warcraft III/Tools"

    copt_win -p 16 -t 0.001 "%USERPROFILE%\Downloads\Models\Plants"
     
    Same thing happens when I drag and drop the folder onto the exe. I tried the tool on these:
    http://www.wc3c.net/showthread.php?t=82781
    (not for any particular reason, just as a quick test).
     
  12. GhostWolf

    GhostWolf

    Joined:
    Jul 29, 2007
    Messages:
    4,836
    Resources:
    2
    Tools:
    1
    Tutorials:
    1
    Resources:
    2
    Oh, my bad!
    I kept testing with the "." path, so in fact I wasn't testing directories at all.
    Seems like I completely forgot to concatenate them to the path.

    The models you linked also don't have a sequence chunk, which caused a crash.
    I didn't know models without sequences are even valid, fixed the code (it ignores the keyframe optimization if there are no sequences).

    Thanks!

    I'll compile for Linux soon, and we'll see about Mac...

    Added the Linux binary.
     
    Last edited: Nov 12, 2013
  13. PurgeandFire

    PurgeandFire

    Code Moderator

    Joined:
    Nov 11, 2006
    Messages:
    7,418
    Resources:
    18
    Icons:
    1
    Spells:
    4
    Tutorials:
    9
    JASS:
    4
    Resources:
    18
  14. GhostWolf

    GhostWolf

    Joined:
    Jul 29, 2007
    Messages:
    4,836
    Resources:
    2
    Tools:
    1
    Tutorials:
    1
    Resources:
    2
    I was doing a case-sensitive check for the extension against "m3" and "mdx", changed it to case-insensitive.

    /Edit
    Added support for big-endian machines (as few of them as there are).
    Thanks to PurgeandFire for compiling the new Mac executable.
     
    Last edited: Nov 15, 2013
  15. BlueSaint

    BlueSaint

    Joined:
    Jun 18, 2012
    Messages:
    2,726
    Resources:
    3
    Tools:
    1
    Spells:
    2
    Resources:
    3
    It cut ~260 kilobytes from my map, which had 50 custom models. Pretty nice tool, I will include you in the credits :)
     
  16. Ice Snake

    Ice Snake

    Joined:
    Oct 13, 2009
    Messages:
    28
    Resources:
    0
    Resources:
    0
    Hi GhostWolf, I created a GUI version for your software, here it is:

    https://www.dropbox.com/s/jossftpc6ieiopc/copt_GUI.rar

    Image
    [​IMG]

    Just "Browse..." and select MDX, MDL file and then "Process"

    It is simple with only 7-8 lines of code but it (may) make(s) life easier..
     

    Attached Files:

    • copt.jpg
      copt.jpg
      File size:
      82.4 KB
      Views:
      994
  17. GhostWolf

    GhostWolf

    Joined:
    Jul 29, 2007
    Messages:
    4,836
    Resources:
    2
    Tools:
    1
    Tutorials:
    1
    Resources:
    2
    You should probably post the source.

    I don't like GUIs for these sort of things, since grabbing files/folders into the executable is faster than opening a select file menu, but if people want to use it, go for it.
     
  18. Ice Snake

    Ice Snake

    Joined:
    Oct 13, 2009
    Messages:
    28
    Resources:
    0
    Resources:
    0
    Okay, I will improve it and post the source code, please wait :D

    Okay, I reuploaded it includes source code, this update support Drag and Drop file to the GUI: https://www.dropbox.com/s/jossftpc6ieiopc/copt_GUI.rar
     
  19. Warcraft_3

    Warcraft_3

    Joined:
    Dec 4, 2014
    Messages:
    94
    Resources:
    0
    Resources:
    0


    Thanks alot its a very good tool :)

    does this tool also work for blp ?
     
    Last edited by a moderator: Oct 22, 2015