JannisX11 / blockbench

Blockbench - A low poly 3D model editor
https://www.blockbench.net
GNU General Public License v3.0
3.4k stars 294 forks source link

[Suggestion] Export textures as TGA #2343

Open BlueBatSamurai opened 6 months ago

BlueBatSamurai commented 6 months ago

Detailed description of your suggestion

Screenshot (145) zugeschnitten

Could you please add an option to save a texture as a TGA file instead of PNG? (For example as a second option in the "file typ" dropdown in the save dialog?)

When I made a Bedrock Edition resource pack with TGA textures, I had to save them as PNG and then convert them to TGA with Paint.NET.

Why can you open a TGA file in Blockbench but then only save it as PNG?

pmatyja commented 5 months ago

@JannisX11

If that help, I can offer the code I have laying around written in C# to write uncompressed TGA image in 32-bit format.

Sidenote: If possible, it would be also nice to be able to choose which texture format to use during the "Create Texture" action. If you prefer separate issue for that I can create one :)

writer.Write((byte)0);              // IdLength
writer.Write((byte)0);              // ColorMap Type
writer.Write((byte)2);              // DataType Code (2 = uncompressed)

writer.Write((short)0);             // ColorMap Origin
writer.Write((short)0);             // ColorMap Length
writer.Write((byte)0);              // ColorMap Depth

writer.Write((short)0);             // Origin X
writer.Write((short)0);             // Origin Y
writer.Write((short)data.Width);    // Width
writer.Write((short)data.Height);   // Height

writer.Write((byte)32);             // Bits Per Pixel
writer.Write((byte)(1 << 5));       // Image Descriptor

var index = 0;

for (var y = 0; y < data.Height; ++y)
{
    for (var x = 0; x < data.Width; ++x)
    {
        writer.Write(data.Bytes[index + 2]); // B
        writer.Write(data.Bytes[index + 1]); // G
        writer.Write(data.Bytes[index + 0]); // R
        writer.Write(data.Bytes[index + 3]); // A

        index += 4;
    }
}

writer.Write((uint)0);          // Extension Area
writer.Write((uint)0);          // Developer Directory

// Signature
writer.Write("TRUEVISION-XFILE.\0"); // string must be null-terminated hence \0 at the end
BlueBatSamurai commented 5 months ago

@pmatyja

Sidenote: If possible, it would be also nice to be able to choose which texture format to use during the "Create Texture" action.

Yes, that would probably be useful. Maybe there should be a setting of each texture, whether it's PNG or TGA, which is also shown in the texture properties. And then there should also be an image action to convert a texture to the other type.

BlueBatSamurai commented 5 months ago

Or would it be easier if all textures were PNG in the model data and only converted to TGA when saved?

Hmm, no, that probably wouldn't work when you have a TGA texture linked to a file...

BlueBatSamurai commented 5 months ago

Sorry, but I don't really know about the differences of PNG and TGA file codings…

Actually, when I started creating Bedrock resource packs, I thought that you could simply "convert" a texture by changing the extension in the file name... (But I soon learned that it's not that easy.)

Ozzuneoj commented 4 months ago

Would love to see this implemented. My kid wants to get into making texture packs and she's pretty sharp with this stuff but having to mess with file conversion is a pain when the rest of the program makes creating and exporting skins and textures so easy.