Jump to content

.mbm Texture File Converter


Zeblote

Recommended Posts

This is a handy script I made today that will convert those silly .mbm textures to handy .png ones.

Since every KSP modder is supposed to have unity anyways, you'll need it for this too.

Just plop the script somewhere in an Editor folder in your project, and then use it with Tools>MBM Converter (I put it in the same top menu as the Part Tools)

You'll be granted by a gui where you can select files.

Click "Set" or enter the path yourself, then click "Convert Texture".

2db4.png

Or if you're too lazy to do this with every file manually, select a Directory using the second "Set" button and hit "Convert All Textures".

It will then go and create a png file for every mbm file it finds in that directory and subdirectories.

1p86.png

Download: http://file.zeblote.com/?f=MBMConverter.zip

NOTE:

Use this for educational or reference purposes only.

Don't use it to steal other modders artwork. I shall not be responsible if you do so.

Edited by Zeblote
Link to comment
Share on other sites

  • 2 weeks later...

Reply with Quote isn't working for some reason.

Found out an Editor folder isn't even required for editor scripts. Woops

Just unzip the file somewhere, start Unity, go to Assets->Import new Asset... and select it.

Then go to Tools->MBM Converter to use it.

Link to comment
Share on other sites

  • 3 weeks later...
Reply with Quote isn't working for some reason.

Found out an Editor folder isn't even required for editor scripts. Woops

Just unzip the file somewhere, start Unity, go to Assets->Import new Asset... and select it.

Then go to Tools->MBM Converter to use it.

I assume this utility needs Unity to run? Is there any way to use it "stand alone"?

Link to comment
Share on other sites

Lol, I didn't find that when I was searching for it.

I assume this utility needs Unity to run? Is there any way to use it "stand alone"?

Yeah, you do need unity for this. However, if you don't have unity, then you (wild assumption) have no intention to create KSP mods. Why would you want to have other peoples textures then? You could try out the tool sirkut posted and see if it works.

Link to comment
Share on other sites

Does anyone know if there has been a final ruling in the mbm vs png battle for performance issues in KSP? The png files are much smaller than the mbm files, but is that because they are compressed? Will Unity spend more time processing the png textures because of that?

Link to comment
Share on other sites

Does anyone know if there has been a final ruling in the mbm vs png battle for performance issues in KSP? The png files are much smaller than the mbm files, but is that because they are compressed? Will Unity spend more time processing the png textures because of that?

The textures are being loaded into memory in an uncompressed format, no matter what file format you use. I don't know whether .mbm or .png take longer to load, however.

Link to comment
Share on other sites

  • 3 weeks later...
Lol, I didn't find that when I was searching for it.

Yeah, you do need unity for this. However, if you don't have unity, then you (wild assumption) have no intention to create KSP mods. Why would you want to have other peoples textures then? You could try out the tool sirkut posted and see if it works.

I already wrote my own MBM to PNG converter program.

To create KSP mods, I'm using Blender to create .DAE files and using .PNG for the textures.

As far as taking stock KSP textures and converting them to PNG, what one can do here is modify a texture and improve (or just change) how a part looks.

See this post: http://forum.kerbalspaceprogram.com/threads/36302-Editing-textures-when-they-are-MBM-files?p=658039&viewfull=1#post658039

Link to comment
Share on other sites

The textures are being loaded into memory in an uncompressed format, no matter what file format you use. I don't know whether .mbm or .png take longer to load, however.

MBM files should load quicker because they don't need to be decompressed.

Link to comment
Share on other sites

  • 3 months later...
  • 1 month later...

Is there a way to do the reverse? make those PNGs into .mbm files? Without having to resort to unity, would be nice for tweaking of mod files without adding load time.

Also I can't get muedit.exe to work, output is always

"usage: muedit filename [find] [replace]

note: find and replace are optional"

Doesn't matter how I do it, shortcut, CMD, .bat etc, .mu file in same folder, I've tried supplying full path and just filename, adding [find]/[replace] after the file, I've tried with or without .mu extension etc, same result.

Edited by K3|Chris
Link to comment
Share on other sites

Is there a way to do the reverse? make those PNGs into .mbm files? Without having to resort to unity, would be nice for tweaking of mod files without adding load time.

Also I can't get muedit.exe to work, output is always

"usage: muedit filename [find] [replace]

note: find and replace are optional"

Doesn't matter how I do it, shortcut, CMD, .bat etc, .mu file in same folder, I've tried supplying full path and just filename, adding [find]/[replace] after the file, I've tried with or without .mu extension etc, same result.

I'm working on the reverse program. Wait a little while!

Link to comment
Share on other sites

  • 2 weeks later...
Yeah, you do need unity for this. However, if you don't have unity, then you (wild assumption) have no intention to create KSP mods. Why would you want to have other peoples textures then?

For little old me with no coding/modeling/texturing experience, I want to rescale and reskin a stock part to make a beefed up radial decoupler for my Jool V revival

Link to comment
Share on other sites

  • 6 months later...
Sorry for the necro, but how do I get this to work?

The converter is a console mode program (that is, it runs in a CMD window). To use it in Windows, do this:

(1) Click START

(2) Click RUN

(3) Type in CMD.EXE, then click OK or press ENTER

A screen with a black background and white letters appears. This is the "CMD prompt".

Now, go to the directory (folder) that has the KSP texture(s) that you want to convert. The converter program (mbm2png.exe) should be in your executable path. If you don't know what that is, just copy or move it to your C:\Windows folder.

Change directories by using the "cd" command, like this example:

cd "c:\Program Files\KSP_win\GameData\Parts\Blah\Blah"

Be sure you enclose the directory path in quotes if it contains a space (like "Program Files" does).

Now, assume you want to convert a texture file named "model000.mbm" into a PNG file. Type this in the CMD prompt window:

mbm2png model000.mbm

The program will run, generate a new file named "model000.png" and print out a small status report.

Convert any more files in the same manner.

When done, type exit <enter> to close and get rid of the CMD prompt window.

Note that the "mu" file (typically "model.mu") must also be edited in order to have KSP use the PNG file instead of the MBM file.

Right near the end of the mu file is the name(s) of the texture files. In a hex editor, it looks like this:

0000F960 00 80 3F 00 00 80 3F 00 00 80 3F 18 00 00 00 08 ..?...?...?.....

0000F970 55 6E 74 61 67 67 65 64 00 00 00 00 01 00 00 00 Untagged........

0000F980 01 00 00 00 0A 00 00 00 02 00 00 00 06 65 6E 67 .............eng

0000F990 69 6E 65 01 00 00 00 00 00 00 00 00 00 80 3F 00 ine...........?.

0000F9A0 00 80 3F 00 00 00 00 00 00 00 00 0F 67 6C 6F 77 ..?.........glow

0000F9B0 20 28 49 6E 73 74 61 6E 63 65 29 0D 00 00 00 00 (Instance).....

0000F9C0 00 00 00 00 00 80 3F 00 00 80 3F 00 00 00 00 00 ......?...?.....

0000F9D0 00 00 00 F2 B1 00 3F 13 A3 66 3F 38 2F 7D 3F 00 ......?..f?8/}?.

0000F9E0 00 80 3F 0C 6D 6F 64 65 6C 30 30 30 2E 6D 62 6D ..?.model000.mbm

0000F9F0 00 00 00 00

You would need to change (hexedit) the string shown in red from "model000.mbm" to "model000.png".

My other program (muedit.exe) does this for you automatically. I assume you also have that program?

Hope this helps.

-- Roger

Link to comment
Share on other sites

Hi Krupski,

What about the inverse? I understand that using png files will be worst since they need to be decompressed, so, could we use somthing like http://www.xnview.com/en/xnconvert/ to converte them back? Or is not working well?

I have a program that does the reverse (PNG -> MBM). I just haven't uploaded it anywhere yet.

Sorry I don't know anything about "xnconvert"... don't know if it would work or not. I do know that the one I wrote does work! :)

Link to comment
Share on other sites

You don't need to edit mu at all; extension in an mu is ignored by KSP.

(textures are not referenced as filenames, but as GameDatabase URLs, i.e. Squad/Parts/Category/foo/model000 rather than model000.mbm ) so if model000 is now a png rather than an mbm, it'll still get picked.

(This is why you should never have, in the same folder, two textures differing only in extension: KSP will load them both [memory use goes up] but only be able to reference one of them.)

Link to comment
Share on other sites

You don't need to edit mu at all; extension in an mu is ignored by KSP.

(textures are not referenced as filenames, but as GameDatabase URLs, i.e. Squad/Parts/Category/foo/model000 rather than model000.mbm ) so if model000 is now a png rather than an mbm, it'll still get picked.

(This is why you should never have, in the same folder, two textures differing only in extension: KSP will load them both [memory use goes up] but only be able to reference one of them.)

Is this something new in v0.25? Because in the past I had to edit the texture filenames (usually located near the end of the model.mu file) and change the extension.

I can't imagine how any code could open a file without a complete path name...

I tested this quite some time ago.

If I converted a model00x.mbm file to a PNG, then edited the PNG file (for example, change it's color - just so I could tell that it was the PNG and not the MBM), the old original texture would load.

Then if I edited the MU file and changed the extension(s) to ".png", the part loaded, and with the edits that I made visible.

I don't know the inner workings of the game, but maybe it uses a list of extensions and tries them in turn (maybe something like this - pseudo-code):


FILE *fp = NULL;
char namebuf[32];
int x;
const char *exts[] = {
"mbm", "png", "tga", "whatever"
};
for (x = 0; x < (sizeof (exts) / sizeof (*exts)); x++) {
sprintf (namebuf, "model000.%s", exts[x]); // build filename
tp = fopen (namebuf, "rb");
if (tp) { // if open success, then break and continue
break;
}
}

If something like the above were being done, then I could see how the program would "favor" the MBM extension over PNG because it succeeds with MBM first.

But, code like this would only load ONE texture (the first one it found), not every one.

By the way, let me ask you this... if you know... in an MBM file there is the "magic number" (03KSP), the bitmap width, height, bit depth and "type" where "type" is either 0 or 1.

It seems like only 32 bit textures MAY have the "type" field set to 1 (but not always).

In the newest version of my MBM2PNG code, I embed the type (0 or 1) in the PNG file (appended after the last byte so as not to mess up the PNG checksum).

The reason I do this is so that my PNG2MBM converter can properly restore that flag when it makes an MBM file.

I don't know if this is NECESSARY, nor do I know what that flag means (I'm guessing it has something to do with the alpha channel)?

Do you know what that flag means (btw, it's a 32 bit number at offset 0x0C in the MBM file - therefore located at 0x0C, 0x0D, 0x0E and 0x0F - little endian).

If you (or anyone else) knows what this flag means, I would greatly appreciate knowing. Thanks!

-- Roger

Edited by Krupski
fixed address error
Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...