• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

MDX/M3 Optimizer

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
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.

Moderator

M

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.
 
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.
 
Level 29
Joined
Jul 29, 2007
Messages
5,174
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:
Level 29
Joined
Jul 29, 2007
Messages
5,174
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:
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:
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/
 
Level 29
Joined
Jul 29, 2007
Messages
5,174
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.
 
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:
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:
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:
 
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:
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).
 
Level 29
Joined
Jul 29, 2007
Messages
5,174
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:
Level 29
Joined
Jul 29, 2007
Messages
5,174
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:

Deleted member 219079

D

Deleted member 219079

It cut ~260 kilobytes from my map, which had 50 custom models. Pretty nice tool, I will include you in the credits :)
 
Level 3
Joined
Oct 13, 2009
Messages
29
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.

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
 
Level 14
Joined
Oct 18, 2013
Messages
710
Hmm..Perhaps the models i tried to optimize have already been optimized, because I used this and Mdx Squisher and it reduced the size of my map by 1194 bytes :p
 
Level 29
Joined
Jul 29, 2007
Messages
5,174
does this tool also work for blp ?

Does it say BLP anywhere in the description or title?

Hmm..Perhaps the models i tried to optimize have already been optimized, because I used this and Mdx Squisher and it reduced the size of my map by 1194 bytes :p

A big part of this optimizer is essentially the same thing as Mdx Squisher (but this tool does it a little better).
You can also experiment with the keyframe threshold and interpolations if you'd like, where the latter can cause big size reductions (at the price of quality of course) for some models.
It's all in the description.
 
Level 29
Joined
Jul 29, 2007
Messages
5,174
I removed the output because there was nothing to actually write about M3 models (at first they also had keyframes removed, but it turned out Starcraft 2 doesn't allow that).
Either way, though, the statistics were only for keyframes and changing interpolations, not for the floating point optimization, since it doesn't actually change the file size.
You can just look at the difference between the input file and the output file, but if you want to see how big it will be in an actual map (MPQ), the only way is to put it in one.
 
Level 14
Joined
Oct 18, 2013
Messages
710
You can also experiment with the keyframe threshold and interpolations if you'd like, where the latter can cause big size reductions (at the price of quality of course) for some models.

Yeah I was going to try to do that, however I don't know how to change the settings. Tried running it through cmd or whatever you instructed in your desc. but I don't know how to. I typed start + the path and name of executable and it just closes immediately. I had to use someone's GUI they made of this. So how do you run it without using default settings?
 
Level 29
Joined
Jul 29, 2007
Messages
5,174
Run the optimizer with the console to get instructions:
Code:
copt_win

For example, to force linear interpolations:
Code:
copt_win -l some_mdx_file.mdx

You can have multiple inputs, where every input can be an MDX file, or a folder (in which case all MDX files in it, and recursively in folders in it, will be taken as inputs).

E.g.
Code:
copt_win some_mdx_file.mdx folder_with_lots_of_mdx_files
 
Level 24
Joined
Feb 17, 2019
Messages
350
Hay dude! I tried to change the value of the "Floating point precision" option to " 32 " to disable it.
Using the " bat " file, but I don't get anything
Code:
copt_win -p 32

How can I make a working bat file with the parameters I need so that I can also drag and drop them as in "EXE"?

P.S. if you add the path to the file, everything works.
Code:
copt_win -p 32 "\%USERPROFILE%\Desktop\MDXM3 Optimizer\Sorcerer.mdx

Edit: Hell, I just had to delete the file name. Everything works!
Code:
copt_win -p 32 "\%USERPROFILE%\Desktop\MDXM3 Optimizer
Thank you for the program, it helped me a lot.

Edit: Provided that the file to be optimized is located in the folder where the program and the "bat" file are installed.
 
Last edited:
Level 5
Joined
Mar 24, 2023
Messages
51
So if i was to use this and input the directory of my current maps War3mapimported folder - would it optimise all the MDX files in that folder and all its sub folders?? Also just so i understand :

-Will this make my total map size smaller afterward?
-Does this effect the actual visual appearance of any of the models in the map when playing?
-All im trying to do is sort of optimise the imported MDX, Audio and BLP files in the map to reduce total size - i have used BLP Lab for the BLPs and compressed the audio files in another programme successfully, is this programme the right thing to use for the MDX files or am i looking at this wrong?

thanks in advance
 
Top