Jump to content

Editing textures when they are .MBM files


Recommended Posts

I'm trying to edit the textures of Structuralpanel2, which are MBM files.

After messing with converting it to a .PBM with HxD and trying to open it with GIMP, this is the best I could get.

http://i.imgur.com/Mz6p7JR.png

Could someone provide directions on how to do this properly? I was using the directions provided by the KSP wiki.

Link to comment
Share on other sites

  • 2 months later...
Update/Bump: A helpful redditor gave me some instructions here, but following them still gave me an unopenable, corrupted file. He doesn't post very frequently, unfortunately.

Here's the wiki post I initially tried

Does anyone have a method for converting .MBM files to an editable format?

I've been working on this. The header that you throw away contains a lot of important info.

The first 4 bytes are 0x03, then ascii "KSP" as you know.

The next 4 bytes are the width of the image in 32 bit format (i.e. 0x00020000 == 512)

The next 4 bytes are the height of the image in 32 bit format (i.e. 0x00040000 == 1024)

The next 4 bytes are a 32 bit number that seems to be either a 0 or a 1 (that is, 0x00000000 or 0x01000000).

The next 4 bytes are a 32 bit number denoting the color depth (usually 0x00180000 or 0x00200000) which is 24 or 32 bit color respectively.

The 24 bit textures are 8 bits of each color (i.e. RGB color). The 32 bit textures are RGBA (RGB with an alpha channel).

What has me stumped is that the field which is either a 0 or a 1 doesn't seem to correspond to anything that makes sense.

At first I thought it was an "8 or 16 bit" flag, meaning that a 32 bit color could be 4 bytes of 8 bits or 2 words of 16 bits, but it doesn't always work out that way.

In fact, it really doesn't matter. All you need (to load the textures into Photoshop or Paintshop Pro or GIMP is the width, height and color depth.)

If you can compile C code, try out this utility I made to display the header info:


/////////////////////////////////////////////////////////
// res.c quick and dirty code to read .mbm file info
// free software - use, distribute freely
/////////////////////////////////////////////////////////

#include <stdio.h>
#include <string.h>
#include <inttypes.h>

union {
char c[4];
uint32_t i;
} width;

union {
char c[4];
uint32_t i;
} height;

union {
char c[4];
uint32_t i;
} type;

union {
char c[4];
uint32_t i;
} bits;


void tabber (uint8_t maxlen, uint8_t len)
{
len = maxlen-len;

while (len--) {
fprintf (stdout, " ");
}

return;
}

int main (int argc, char *argv[])
{
FILE *fp;
char header[5];
uint8_t x;
uint8_t maxlen;
uint32_t fsize;


if (argc < 2) {
fprintf (stderr, "At least one filename required\n");
return 1;
}

maxlen = 0;

/* space out for the longest filename so it reads lined up */
for (x = 1; x < argc; x++) {
if (maxlen < strlen (argv[x])) {
maxlen = strlen (argv[x]);
}
}

for (x = 1; x < argc; x++) {

fp = fopen (argv[x], "rb");

if (!fp) {
fprintf (stderr, "open %s for read failed\n", argv[x]);
continue;
}

fseek (fp, 0, SEEK_END);
fsize = ftell (fp);
fseek (fp, 0, SEEK_SET);

if (fsize < 20) {
fprintf (stderr, "%s is less than 20 bytes!!\n", argv[x]);
fclose (fp);
continue;
}

/* read the header */

fread (header, sizeof (char), 4, fp);
header[4] = 0; // null terminate
fread (width.c, sizeof (char), 4, fp);
fread (height.c, sizeof (char), 4, fp);
fread (type.c, sizeof (char), 4, fp);
fread (bits.c, sizeof (char), 4, fp);
fclose (fp);

/* check for KSP */
if (strncmp (header+1, "KSP", 3) != 0) {
fprintf (stderr, "%s is not a KSP texture file!\n", argv[x]);

/* display header info */

} else {
fprintf (stdout, "%s ", argv[x]);
tabber (maxlen, strlen (argv[x]));
fprintf (stdout, "- width: %4u, height: %4u, type: %u, bits: %2u\n", width.i, height.i, type.i, bits.i);
}

}

return 0;
}

(edit to add): The header info (especially the width and height) is very important because not all texture files are square!

For example: GameData/Squad/Parts/Utility/stackDecouplerMini/model000.mbm - width: 256, height: 64, type: 0, bits: 24

Edited by Krupski
Link to comment
Share on other sites

If you're using PS you can open it as RAW and tell it how big the header is; when you've finished editing it'll write the header back out again. I don't know if Gimp has a similar feature but it's worth a look.

Yes, GIMP can open them as raw (I do it in Linux).

Easier, safer method:

.mbm texture file converter

Thanks!

Link to comment
Share on other sites

  • 2 weeks later...
Hi all,

I've had lots of fun modifying some of the part textures in KSP and I found that the biggest "pain" was converting the MBM files into PNG files. So I wrote a little utility to do it.

Check it out: http://kerbalspaceprogram.com/mbm-to-png-file-converter

Hope this is of some use to someone.......

-- Roger

This.

This is a tool that all modders should really have. Just like the .mu converter for Blender. It really lets us use the stock assets Squad gives us to their max.

Link to comment
Share on other sites

Hi all,

I've had lots of fun modifying some of the part textures in KSP and I found that the biggest "pain" was converting the MBM files into PNG files. So I wrote a little utility to do it.

Check it out: http://kerbalspaceprogram.com/mbm-to-png-file-converter

Hope this is of some use to someone.......

-- Roger

I can't use it. I've downloaded it, but when i try to open the Win32 or Win64 applications, the window quickly opens then closes again, before I'm even able to see anything in it.

Link to comment
Share on other sites

I have not used this yet, but the read me gives instructions on how to use it. (I had to use notepad++ to open the read me)

README            - This document
mbm2png_linux32 - precompiled for your convenience (Linux 32 bit)
mbm2png_linux64 - precompiled for your convenience (Linux 64 bit)
mbm2png_win32.exe - precompiled for your convenience (Windows console 32 bit)
mbm2png_win64.exe - precompiled for your convenience (Windows console 64 bit)

Sorry, I don't have a MAC, so I wasn't able to provide a precompiled executable
for you Apple users. Maybe someone with a MAC can compile this and upload it?


Quick start
=====================================
This program converts Kerbal Space Program texture files (i.e. "model000.mbm")
into PNG files suitable for editing and use in the KSP game.

To use, simply copy the appropriate executable to your computer, then type

C:\> mbm2png model000.mbm (press enter)

The program will run, generate the PNG file, then print small report:

Converting model000.mbm to model000.png... writing PNG file... Done!
Width: 512, Height: 1024, Bits: 24, MBM size: 1572884, PNG size: 131126

Note: Wildcards are supported. To convert all the MBM files in a directory to
PNG images, simply type:

C:\> mbm2png *.mbm (press enter)


Using PNG textures in the game
=====================================
In order to make the game utilize the textures in PNG format, you need to edit
the "model.mu" file in the part folder that you want to modify, and, near the
bottom change the file extensions from "mbm" to "png". In a hex editor, it would
look something like this:

Before editing
=====================================
0002B820 00 00 00 00 00 00 06 65 6E 67 69 6E 65 07 00 00 .......engine...
0002B830 00 02 00 00 00 00 00 80 3F 00 00 80 3F 00 00 00 ........?...?...
0002B840 00 00 00 00 00 03 00 00 00 00 00 80 3F 00 00 80 ............?...
0002B850 3F 00 00 00 00 00 00 00 00 C0 AF C6 3D C0 AF C6 ?...........=...
0002B860 3D C0 AF C6 3D 00 00 80 3F BF CC EB 3E 04 00 00 =...=...?...>...
0002B870 00 00 00 80 3F 00 00 80 3F 00 00 00 00 00 00 00 ....?...?.......
0002B880 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 80 ................
0002B890 3F 0C 00 00 00 05 00 00 00 0C 6D 6F 64 65 6C 30 ?.........model0 \
0002B8A0 30 30 2E 6D 62 6D 00 00 00 00 0C 6D 6F 64 65 6C 00.mbm.....model \
0002B8B0 30 30 31 2E 6D 62 6D 01 00 00 00 0C 6D 6F 64 65 001.mbm.....mode \ <-- note
0002B8C0 6C 30 30 32 2E 6D 62 6D 00 00 00 00 0C 6D 6F 64 l002.mbm.....mod / .mbm
0002B8D0 65 6C 30 30 33 2E 6D 62 6D 01 00 00 00 0C 6D 6F el003.mbm.....mo /
0002B8E0 64 65 6C 30 30 34 2E 6D 62 6D 00 00 00 00 del004.mbm.... /

After editing
=====================================
0002B820 00 00 00 00 00 00 06 65 6E 67 69 6E 65 07 00 00 .......engine...
0002B830 00 02 00 00 00 00 00 80 3F 00 00 80 3F 00 00 00 ........?...?...
0002B840 00 00 00 00 00 03 00 00 00 00 00 80 3F 00 00 80 ............?...
0002B850 3F 00 00 00 00 00 00 00 00 C0 AF C6 3D C0 AF C6 ?...........=...
0002B860 3D C0 AF C6 3D 00 00 80 3F BF CC EB 3E 04 00 00 =...=...?...>...
0002B870 00 00 00 80 3F 00 00 80 3F 00 00 00 00 00 00 00 ....?...?.......
0002B880 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 80 ................
0002B890 3F 0C 00 00 00 05 00 00 00 0C 6D 6F 64 65 6C 30 ?.........model0 \
0002B8A0 30 30 2E 70 6E 67 00 00 00 00 0C 6D 6F 64 65 6C 00.png.....model \
0002B8B0 30 30 31 2E 70 63 67 01 00 00 00 0C 6D 6F 64 65 001.png.....mode \ <-- changed
0002B8C0 6C 30 30 32 2E 70 6E 67 00 00 00 00 0C 6D 6F 64 l002.png.....mod / to .png
0002B8D0 65 6C 30 30 33 2E 70 6E 67 01 00 00 00 0C 6D 6F el003.png.....mo /
0002B8E0 64 65 6C 30 30 34 2E 70 6E 67 00 00 00 00 del004.png.... /


What the program does (and does not do)
=====================================
(1) It will NOT modify the original MBM file.
(2) It will check for a valid MBM file by looking for the "3KSP" magic number.
(3) It will create a PNG image file with the same base name as the MBM file.
(4) It will NOT overwrite the PNG image file if run again. Delete the PNG to recreate it.


In any case, always make a backup copy of files before you edit them


Copyright information - mbm2png
=====================================
mbm2png - Converts Kerbal Space Program texture files to png image files
(c) 2013 Roger A. Krupski <rakrupski@verizon.net>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.



Copyright information - lodepng
=====================================
LodePNG version 20130831
Copyright (c) 2005-2013 Lode Vandevenne

This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.

Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:

1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.

2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.

3. This notice may not be removed or altered from any source
distribution.


########################################
# One of these BANG, ZOOM! #
# days Alice... Straight to #
# ^ the Mun! #
# /_\ #
# /___\ #
# | | #
# | | #
# |---| #
# | K | #
# | S | #
# | P | #
# | | #
# | | #
# /--|--\ #
# /- #|#- \ #
# ___ ### ___ #
# ||_| ### |_|| #
# || # || #
# || # || #
# || # || #
# || || #
# || || #
# ================== #
########################################

Enjoy!! -- Roger

edit : after a little experimenting, I got this to work. I could only convert 1 mbm at a time however. When I tried to convert all mbm's in a file it give me : open *.mbm for read failed.

Edited by Otis
Link to comment
Share on other sites

I have not used this yet, but the read me gives instructions on how to use it. (I had to use notepad++ to open the read me)

README            - This document
mbm2png_linux32 - precompiled for your convenience (Linux 32 bit)
mbm2png_linux64 - precompiled for your convenience (Linux 64 bit)
mbm2png_win32.exe - precompiled for your convenience (Windows console 32 bit)
mbm2png_win64.exe - precompiled for your convenience (Windows console 64 bit)

Sorry, I don't have a MAC, so I wasn't able to provide a precompiled executable
for you Apple users. Maybe someone with a MAC can compile this and upload it?


Quick start
=====================================
This program converts Kerbal Space Program texture files (i.e. "model000.mbm")
into PNG files suitable for editing and use in the KSP game.

To use, simply copy the appropriate executable to your computer, then type

C:\> mbm2png model000.mbm (press enter)

The program will run, generate the PNG file, then print small report:

Converting model000.mbm to model000.png... writing PNG file... Done!
Width: 512, Height: 1024, Bits: 24, MBM size: 1572884, PNG size: 131126

Note: Wildcards are supported. To convert all the MBM files in a directory to
PNG images, simply type:

C:\> mbm2png *.mbm (press enter)


Using PNG textures in the game
=====================================
In order to make the game utilize the textures in PNG format, you need to edit
the "model.mu" file in the part folder that you want to modify, and, near the
bottom change the file extensions from "mbm" to "png". In a hex editor, it would
look something like this:

Before editing
=====================================
0002B820 00 00 00 00 00 00 06 65 6E 67 69 6E 65 07 00 00 .......engine...
0002B830 00 02 00 00 00 00 00 80 3F 00 00 80 3F 00 00 00 ........?...?...
0002B840 00 00 00 00 00 03 00 00 00 00 00 80 3F 00 00 80 ............?...
0002B850 3F 00 00 00 00 00 00 00 00 C0 AF C6 3D C0 AF C6 ?...........=...
0002B860 3D C0 AF C6 3D 00 00 80 3F BF CC EB 3E 04 00 00 =...=...?...>...
0002B870 00 00 00 80 3F 00 00 80 3F 00 00 00 00 00 00 00 ....?...?.......
0002B880 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 80 ................
0002B890 3F 0C 00 00 00 05 00 00 00 0C 6D 6F 64 65 6C 30 ?.........model0 \
0002B8A0 30 30 2E 6D 62 6D 00 00 00 00 0C 6D 6F 64 65 6C 00.mbm.....model \
0002B8B0 30 30 31 2E 6D 62 6D 01 00 00 00 0C 6D 6F 64 65 001.mbm.....mode \ <-- note
0002B8C0 6C 30 30 32 2E 6D 62 6D 00 00 00 00 0C 6D 6F 64 l002.mbm.....mod / .mbm
0002B8D0 65 6C 30 30 33 2E 6D 62 6D 01 00 00 00 0C 6D 6F el003.mbm.....mo /
0002B8E0 64 65 6C 30 30 34 2E 6D 62 6D 00 00 00 00 del004.mbm.... /

After editing
=====================================
0002B820 00 00 00 00 00 00 06 65 6E 67 69 6E 65 07 00 00 .......engine...
0002B830 00 02 00 00 00 00 00 80 3F 00 00 80 3F 00 00 00 ........?...?...
0002B840 00 00 00 00 00 03 00 00 00 00 00 80 3F 00 00 80 ............?...
0002B850 3F 00 00 00 00 00 00 00 00 C0 AF C6 3D C0 AF C6 ?...........=...
0002B860 3D C0 AF C6 3D 00 00 80 3F BF CC EB 3E 04 00 00 =...=...?...>...
0002B870 00 00 00 80 3F 00 00 80 3F 00 00 00 00 00 00 00 ....?...?.......
0002B880 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 80 ................
0002B890 3F 0C 00 00 00 05 00 00 00 0C 6D 6F 64 65 6C 30 ?.........model0 \
0002B8A0 30 30 2E 70 6E 67 00 00 00 00 0C 6D 6F 64 65 6C 00.png.....model \
0002B8B0 30 30 31 2E 70 63 67 01 00 00 00 0C 6D 6F 64 65 001.png.....mode \ <-- changed
0002B8C0 6C 30 30 32 2E 70 6E 67 00 00 00 00 0C 6D 6F 64 l002.png.....mod / to .png
0002B8D0 65 6C 30 30 33 2E 70 6E 67 01 00 00 00 0C 6D 6F el003.png.....mo /
0002B8E0 64 65 6C 30 30 34 2E 70 6E 67 00 00 00 00 del004.png.... /


What the program does (and does not do)
=====================================
(1) It will NOT modify the original MBM file.
(2) It will check for a valid MBM file by looking for the "3KSP" magic number.
(3) It will create a PNG image file with the same base name as the MBM file.
(4) It will NOT overwrite the PNG image file if run again. Delete the PNG to recreate it.


In any case, always make a backup copy of files before you edit them


Copyright information - mbm2png
=====================================
mbm2png - Converts Kerbal Space Program texture files to png image files
(c) 2013 Roger A. Krupski <rakrupski@verizon.net>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.



Copyright information - lodepng
=====================================
LodePNG version 20130831
Copyright (c) 2005-2013 Lode Vandevenne

This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.

Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:

1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.

2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.

3. This notice may not be removed or altered from any source
distribution.


########################################
# One of these BANG, ZOOM! #
# days Alice... Straight to #
# ^ the Mun! #
# /_\ #
# /___\ #
# | | #
# | | #
# |---| #
# | K | #
# | S | #
# | P | #
# | | #
# | | #
# /--|--\ #
# /- #|#- \ #
# ___ ### ___ #
# ||_| ### |_|| #
# || # || #
# || # || #
# || # || #
# || || #
# || || #
# ================== #
########################################

Enjoy!! -- Roger

edit : after a little experimenting, I got this to work. I could only convert 1 mbm at a time however. When I tried to convert all mbm's in a file it give me : open *.mbm for read failed.

Yup. I discovered a bug in the Windows version... the wildcards don't expand properly. I'll fix that and upload it. Don't worry though, the converted PNG images are OK... it's just the wildcards that fail in Windows. Sorry. :(

I'll also fix the README file. I did all this work in Linux and as you (may) know, Linux/Unix uses a LF for line endings. Windows uses CR/LF, so the readme file might look like gibberish in a Windows text editor. I'll convert the README to use Windows style line endings (since Linux doesn't care about that.... much). :)

Edited by Krupski
Link to comment
Share on other sites

I can't use it. I've downloaded it, but when i try to open the Win32 or Win64 applications, the window quickly opens then closes again, before I'm even able to see anything in it.

Are you trying to click on it from Windows explorer? If so, what you are doing is just running the program with no filenames to convert and it gives you a brief message, then quits.

Instead, do it this way:

(1) Go to START button

(2) Click "RUN"

(3) Type in "cmd.exe" (no quotes, just cmd.exe)

(4) A black window with white text will appear.

(5) Find the utility, then type in the command to convert an MBM file:

C:\> mbm2png model000.mbm (press enter)

The program should run and show you what it did. You should also have one new file named "model000.png".

Of course, you need to be in the proper directory (that is, where the game texture files are). Typically "KSP_win/GameData/Squad/Parts/(whatever part)".

When finished, you can either type the command "exit" (again, without quotes) to close the black CMD window. Like this:

C:\> exit (press enter)

The CMD window closes.

Hope this helps.

Link to comment
Share on other sites

Here's an example of what can be done.

First I went into the directory "KSP_xxx/GameData/Squad/Parts/Engine/liquidEngine1-2" (the Rockomax "Mainsail" engine).

Then I converted all the modelxxx.mbm files to PNG files.

I edited "model002.png" which is the texture for the exterior of the engine. Here's what I did to it in Photoshop:

model002.png

Notice the nozzle now has regenerative cooling tubes rather than being plain grey and has stiffening bands.

I also did the inside of the nozzle to show the tubing, erosion streaks from firing and the injector plate in the center.

Lastly I made a new logo for the engine "Rockets R-Us" :)

Using a hex editor, I edited the file "model.mu" and near the bottom, changed all the texture filenames from "modelxxx.mbm" to "modelxxx.png". Here's what the text editor looks like after the edit:


0002B7F0 00 08 66 61 69 72 69 6E 67 31 03 00 00 00 00 00 ..fairing1......
0002B800 00 00 00 00 80 3F 00 00 80 3F 00 00 00 00 00 00 .....?...?......
0002B810 00 00 01 00 00 00 00 00 80 3F 00 00 80 3F 00 00 .........?...?..
0002B820 00 00 00 00 00 00 06 65 6E 67 69 6E 65 07 00 00 .......engine...
0002B830 00 02 00 00 00 00 00 80 3F 00 00 80 3F 00 00 00 ........?...?...
0002B840 00 00 00 00 00 03 00 00 00 00 00 80 3F 00 00 80 ............?...
0002B850 3F 00 00 00 00 00 00 00 00 C0 AF C6 3D C0 AF C6 ?...........=...
0002B860 3D C0 AF C6 3D 00 00 80 3F BF CC EB 3E 04 00 00 =...=...?...>...
0002B870 00 00 00 80 3F 00 00 80 3F 00 00 00 00 00 00 00 ....?...?.......
0002B880 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 80 ................
0002B890 3F 0C 00 00 00 05 00 00 00 0C 6D 6F 64 65 6C 30 ?.........model0
0002B8A0 30 30 2E 70 6E 67 00 00 00 00 0C 6D 6F 64 65 6C 00.png.....model
0002B8B0 30 30 31 2E 70 6E 67 01 00 00 00 0C 6D 6F 64 65 001.png.....mode
0002B8C0 6C 30 30 32 2E 70 6E 67 00 00 00 00 0C 6D 6F 64 l002.png.....mod
0002B8D0 65 6C 30 30 33 2E 70 6E 67 01 00 00 00 0C 6D 6F el003.png.....mo
0002B8E0 64 65 6C 30 30 34 2E 70 6E 67 00 00 00 00 del004.png....
0002B8F0
--- model.mu --0x2B780/0x2B8EE------------------------------------------

So how did it turn out? Here's a few screenshots from the game with the edited texture:

mainsail_01.jpg

mainsail_02.jpg

(do not stand here when engine is running!)

mainsail_03.jpg

BTW, the original image I used for the nozzle interior is a picture of the XLR-99 engine used in the X-15 project.

This image: http://airpigz.com/storage/hi-res/2012/North-American-X-15-66671-Air-Force-Museum-Looking-Inside-Exhaust.jpg

A quick online search yields all kinds of great stuff to use in editing your textures. For example, you can make the FL-T800 fuel tank look very much like a Saturn S1-C simply by adding a few decals... like these:

http://www.ninfinger.org/models/vault/est2001sw.jpg

Neat, huh?

Edited by Krupski
added another pic
Link to comment
Share on other sites

This.

This is a tool that all modders should really have. Just like the .mu converter for Blender. It really lets us use the stock assets Squad gives us to their max.

Glad you can use it! Please check to see if you have the latest version: I uploaded one one update since the original.

http://kerbalspaceprogram.com/mbm-to-png-file-converter

And, if you find any bug(s) (which of course there aren't! LOL) please let me know.

-- Roger

(edit to add): I updated the upload. It now contains two utilities... the original "mbm2png" converter and a new one "muedit".

What "muedit" does is change the filename extensions inside "model.mu" files from ".mbm" to ".png" (the thing that had to be done before with a hex editor).

Also, "muedit" makes a backup copy of the original file (just in case!), it checks for a valid signature (won't edit the wrong files) and will refuse to overwrite an existing backup (prevents trashing an original backup with a modified one).

Of course, full documentation and C source code are included.

Enjoy! Hope this is of some use to someone!

Edited by Krupski
Link to comment
Share on other sites

  • 1 month later...
So I can convert MBMs to PNGs to edit them more easily - now how would I reduce a files RAM imprint? Simply open it in any editor and save it at a lower resolution?

Not really. If you convert a texture to a PNG, it's compressed and takes up less space ON DISK, but when KSP loads it, it's decompressed back into a bitmap. Not only does this take more time (load times get longer), but also no IN MEMORY (IN GAME) savings are achieved.

The point of converting to PNG is to be able to easily edit a texture with almost any graphics editor program. Ideally, you would convert a texture from .MBM to .PNG, edit it, then convert it back to .MBM (in fact, I plan to write a companion program for MBM2PNG called, of course, PNG2MBM which does this very thing).

Another obscure problem is a bug in 64 bit Linux (and POSSIBLY MacOS - not sure here). If you have PNG textures in KSP 64 bit linux, there is a bug in the program that can cause a texture to cross a memory boundary during decompression back into a bitmap and this results in a processor exception (a core dump and crash). The fix is to patch two bytes in KSP.x86_64 (and ONLY that file). The thing is these crashes are random. If a bitmap decompression doesn't happen to cross a memory boundary, KSP will load just fine. Also, depending on the order modules are loaded, KSP may or may not crash during PNG loads.

Here's the patch data (again, ONLY for Linux and ONLY on the file KSP.x86_64). BE SURE TO MAKE A BACKUP FIRST!!!


root@michael:/usr/share/KSP_linux# fcmp KSP.x86_64 KSP.x86_64_Patched
Reading KSP.x86_64 (17930928 of 17930928 bytes)
Reading KSP.x86_64_Patched (17930928 of 17930928 bytes)
007CEBC7: 01 00
007CEBCC: 01 00

fcmp: 2 mismatches encountered

In case the above is confusing, it means:

Change the byte at address 0x007CEBC7 from one to zero and also change the byte at address 0x007CEBCC from one to zero.

BTW, these addresses are valid for KSP 0.21.1 and 0.22.0 (not sure about older versions).

Here's a copy of "fcmp" (with a README file, C source code and pre-compiled executables for Windows and Linux) if you wish to use it: DOWNLOAD LINK

Again, please be sure to make a backup copy of any file before editing it!

Lastly, here's the link to the original info about the bug: http://bugs.kerbalspaceprogram.com/issues/752

-- Roger

Edited by Krupski
added info
Link to comment
Share on other sites

Not really. If you convert a texture to a PNG, it's compressed and takes up less space ON DISK, but when KSP loads it, it's decompressed back into a bitmap. Not only does this take more time (load times get longer), but also no IN MEMORY (IN GAME) savings are achieved.

The point of converting to PNG is to be able to easily edit a texture with almost any graphics editor program. Ideally, you would convert a texture from .MBM to .PNG, edit it, then convert it back to .MBM (in fact, I plan to write a companion program for MBM2PNG called, of course, PNG2MBM which does this very thing).

No memory savings even if I use the Resample/Resize option from IrfanView to change it from 2048x2048 to 1024x1024 and save it?

Now know about the longer loadtimes of PNGs, I am eagerly awaiting your MBM2PNG tool! :)

Link to comment
Share on other sites

No memory savings even if I use the Resample/Resize option from IrfanView to change it from 2048x2048 to 1024x1024 and save it?

Now know about the longer loadtimes of PNGs, I am eagerly awaiting your MBM2PNG tool! :)

The MBM2PNG tool already exists: http://kerbalspaceprogram.com/mbm-to-png-file-converter/

It's the PNG to MBM converter that I need to write! :)

As for your question, I honestly don't know what would happen if you downsized a texture. The game may wrap the texture properly (albeit with less detail) or it may only cover part of the mesh. Never tried it, so I don't know.

Why not try it? Convert a texture to a PNG, resize it and save it. You also will have to edit the "model.mu" file to use the PNG file instead of the MBM file (that utility is also in my package). If it works, cool. If not, restore from your backup.

Link to comment
Share on other sites

I have a science lab part that already used PNGs, I resampled the files.

What I do not know of course, is if the files now take up less memory, but the part was textured correctly.

Sadly did not take any screens for a before-after.

Link to comment
Share on other sites

Hi Krupski, I love the mbm2png tool, it's extremely handy. Would you be able to put up some examples of .BAT files to convert multiple files at the same time? I couldn't get it to work.

Cheers

EDIT: Also, is it possible to select all mbm files in the same folder e.g: "mbm2png *.mbm" doesn't seem to work.

Edited by scottholio
Link to comment
Share on other sites

I have a science lab part that already used PNGs, I resampled the files.

What I do not know of course, is if the files now take up less memory, but the part was textured correctly.

Sadly did not take any screens for a before-after.

Converting an MBM texture to PNG saves DISK space, but in the game the texture bitmap is exactly the same size. A PNG file is decompressed into it's full size while an MBM file is already full size and loaded as-is.

Hi Krupski, I love the mbm2png tool, it's extremely handy. Would you be able to put up some examples of .BAT files to convert multiple files at the same time? I couldn't get it to work.

Cheers

EDIT: Also, is it possible to select all mbm files in the same folder e.g: "mbm2png *.mbm" doesn't seem to work.

Well, the original version of the code I wrote allowed using wildcards, but then I discovered that the Windows version failed if a wildcard was used.

For example, typing mbm2png *.mbm in Linux worked just fine. In Windows it failed. It's a problem with Windows, not the program.

So, I just removed the wildcard code and made it convert only one file.

To do a bunch via a batch file, you could probably use at the command prompt:

C:\> dir *.mbm /s /b > all.bat

...to generate a listing of all the files ending in .MBM, then edit "all.bat" by adding the "mbm2png" command to each line, then finally run the batch file.

For example, when you generate the batch file, it may look like this:

c:\program files\KSP_win\GameData\Squad\Parts\Engine\liquidEngine1-2\model000.mbm

c:\program files\KSP_win\GameData\Squad\Parts\Engine\liquidEngine1-2\model001.mbm

c:\program files\KSP_win\GameData\Squad\Parts\Engine\liquidEngine1-2\model002.mbm

........ etc.....

then open the file in Notepad and add the mbm2png command to each line, so it ends up looking like this:

mbm2png "c:\program files\KSP_win\GameData\Squad\Parts\Engine\liquidEngine1-2\model000.mbm"

mbm2png "c:\program files\KSP_win\GameData\Squad\Parts\Engine\liquidEngine1-2\model001.mbm"

mbm2png "c:\program files\KSP_win\GameData\Squad\Parts\Engine\liquidEngine1-2\model002.mbm"

........ etc.....

Then just type "all.bat" (or whatever you named it).

Hope this helps.

-- Roger

Link to comment
Share on other sites

That works brilliantly, not much work to paste in the mbm2png command. Thanks.

I noticed that it doesn't work for the muedit. I follow the same step but with

C:\> dir *.mu /s /b > muall.bat

then add muedit to each line in the bat file. It only converts the first mu, the rest get errors. If I put pause between each line, it still only converts the first mu. Strange.

Thanks for your reply though, converting multiple mbm's is so easy now :)

Link to comment
Share on other sites

That works brilliantly, not much work to paste in the mbm2png command. Thanks.

I noticed that it doesn't work for the muedit. I follow the same step but with

C:\> dir *.mu /s /b > muall.bat

then add muedit to each line in the bat file. It only converts the first mu, the rest get errors. If I put pause between each line, it still only converts the first mu. Strange.

Thanks for your reply though, converting multiple mbm's is so easy now :)

Be sure to put quotes around the filenames. Windows gets all confused with spaces. For example:

C:\Program Files\KSP_win\GameData....

will be seen as:

C:\Program

Files\KSP_win\GameData

Because the space between "Program" and "Files" is seen as a delimiter.

But if you do this:

"C:\Program Files\KSP_win\GameData...." (note the quotes surrounding the string)

Then the OS will know that the string is all one line (i.e. one filename).

When you say you get "errors", what exactly is the error? If you can tell me the text of the error, I will (probably) be able to figure out what's causing it.

-- Roger

Link to comment
Share on other sites

Ok, so here is an example of what I write in my bat file:


muedit "F:\LazTekSpaceXLaunchPack_2.0.1\GameData\LazTek\Parts\LazTekDragon2NoseCone\model.mu"
muedit "F:\LazTekSpaceXLaunchPack_2.0.1\GameData\LazTek\Parts\LazTekDragon2NoseConeExt\model.mu"
pause

and the result:


F:\LazTekSpaceXLaunchPack_2.0.1\GameData\LazTek\Parts>muedit "F:\LazTekSpaceXLau
nchPack_2.0.1\GameData\LazTek\Parts\LazTekDragon2NoseCone\model.mu"

muedit: Report:
==================================================
Checked the signature of F:\LazTekSpaceXLaunchPack_2.0.1\GameData\LazTek\Parts\L
azTekDragon2NoseCone\model.mu (correct)
Backed up the original file F:\LazTekSpaceXLaunchPack_2.0.1\GameData\LazTek\Part
s\LazTekDragon2NoseCone\model.mu to F:\LazTekSpaceXLaunchPack_2.0.1\GameData\Laz
Tek\Parts\LazTekDragon2NoseCone\model.mu.bak
Changed 0 occurrences of .mbm to .png in file F:\LazTekSpaceXLaunchPack_2.0.1\Ga
meData\LazTek\Parts\LazTekDragon2NoseCone\model.mu
Wrote updated file F:\LazTekSpaceXLaunchPack_2.0.1\GameData\LazTek\Parts\LazTekD
ragon2NoseCone\model.mu to disk
No errors were encountered


F:\LazTekSpaceXLaunchPack_2.0.1\GameData\LazTek\Parts>muedit F:\LazTekSpaceXLaun
chPack_2.0.1\GameData\LazTek\Parts\LazTekDragon2NoseConeExt\model.mu

muedit: open F:\LazTekSpaceXLaunchPack_2.0.1\GameData\LazTek\Parts\LazTekDragon2
NoseConeExt\model.muToolkit\;C:\Program Files (x86)\GtkSharp\2.12\bin;C:\Program
Files\Common Files\Autodesk Shared\;C:\Program Files (x86)\Autodesk\Backburner\
;C:\Program Files\FileBot\.bak for write failed

F:\LazTekSpaceXLaunchPack_2.0.1\GameData\LazTek\Parts>pause
Press any key to continue . . .

Edited by scottholio
Link to comment
Share on other sites

Ok, so here is an example of what I write in my bat file:

F:\LazTekSpaceXLaunchPack_2.0.1\GameData\LazTek\Parts>muedit F:\LazTekSpaceXLaunchPack_2.0.1\GameData\LazTek\Parts\LazTekDragon2NoseConeExt\model.mu

muedit: open F:\LazTekSpaceXLaunchPack_2.0.1\GameData\LazTek\Parts\LazTekDragon2NoseConeExt\model.muToolkit\;C:\Program Files (x86)\GtkSharp\2.12\bin;C:\Program Files\Common Files\Autodesk Shared\;C:\Program Files (x86)\Autodesk\Backburner\;C:\Program Files\FileBot\.bak for write failed

F:\LazTekSpaceXLaunchPack_2.0.1\GameData\LazTek\Parts>pause

I unwrapped the text to see it more clearly. Notice that the second command (as seen in "result") does not have the filename in quotes.

It seems like you have both filenames in quotes in the BAT file, but it's not coming through when you run the program.

The second line (the one which is a mess) looks to me like a PATH (because it's separated with semicolons) is appended to the desired filename. The filename is the bold part, the extra junk (path maybe?) is the blue part.

I'm not sure why this is happening, but I don't think it's a problem with MUEDIT. For some reason, your computer is passing a bad string (as a filename) to MUEDIT and of course MUEDIT is choking on it.

Try these things:

(1) In a command window, type "path" and see if your path resembles (or is equal to) the text shown in blue.

(2) Try having a blank line between commands. That is, instead of this:

muedit "file1.mu"

muedit "file2.mu"

Try:

muedit "file1.mu"

(blank line)

muedit "file2.mu"

(blank line)

(3) Try forcing Windows to create a separate process each time it runs muedit. In the BAT file, instead of simply muedit "filename.mu", try call muedit "filename.mu".

(4) Maybe the "pause" command in your batch file is messing things up. Try two or three file conversions WITHOUT "pause".

Try these things and let me know how it works.

-- Roger

(edit to add): This is strange... I noticed in the quote that the word "Parts" is split. On my end it looks like "Pa rts". Is there maybe an extraneous character in that filename?

Edited by Krupski
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...