mirror of
https://github.com/aimrebirth/tools.git
synced 2026-04-15 01:43:25 +00:00
Switch tm converter from tga to bmp as ue4 hardly understands transparent tga. Or they just was incorrectly converted.
This commit is contained in:
parent
6ce917f5e8
commit
0efa83b097
6 changed files with 88 additions and 32 deletions
|
|
@ -39,6 +39,15 @@ public:
|
||||||
data.resize(width * height, T());
|
data.resize(width * height, T());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
T &operator()(int i)
|
||||||
|
{
|
||||||
|
return data[i];
|
||||||
|
}
|
||||||
|
const T &operator()(int i) const
|
||||||
|
{
|
||||||
|
return (*const_cast<mat *>(this))(i);
|
||||||
|
}
|
||||||
|
|
||||||
T &operator()(int row, int col)
|
T &operator()(int row, int col)
|
||||||
{
|
{
|
||||||
assert(!(row >= height || col >= width || row < 0 || col < 0));
|
assert(!(row >= height || col >= width || row < 0 || col < 0));
|
||||||
|
|
@ -62,28 +71,63 @@ public:
|
||||||
const std::vector<T> &getData() const { return data; }
|
const std::vector<T> &getData() const { return data; }
|
||||||
std::vector<T> &getData() { return data; }
|
std::vector<T> &getData() { return data; }
|
||||||
|
|
||||||
|
// left/right
|
||||||
|
mat mirror()
|
||||||
|
{
|
||||||
|
int cols = width;
|
||||||
|
int rows = height;
|
||||||
|
mat<uint32_t> m(width, height);
|
||||||
|
for (int row = 0; row < rows; row++)
|
||||||
|
{
|
||||||
|
for (int col = 0; col < cols; col++)
|
||||||
|
{
|
||||||
|
auto &o = operator()(row * cols + col);
|
||||||
|
auto &n = m(row * cols + (cols - 1 - col));
|
||||||
|
n = o;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return m;
|
||||||
|
}
|
||||||
|
|
||||||
|
// up/down
|
||||||
|
mat flip()
|
||||||
|
{
|
||||||
|
int cols = width;
|
||||||
|
int rows = height;
|
||||||
|
mat<uint32_t> m(width, height);
|
||||||
|
for (int row = 0; row < rows; row++)
|
||||||
|
{
|
||||||
|
for (int col = 0; col < cols; col++)
|
||||||
|
{
|
||||||
|
auto &o = operator()(row * cols + col);
|
||||||
|
auto &n = m((rows - 1 - row) * cols + col);
|
||||||
|
n = o;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return m;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<T> data;
|
std::vector<T> data;
|
||||||
int width;
|
int width;
|
||||||
int height;
|
int height;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<class T>
|
inline void write_mat_bmp(const std::string &filename, int width, int height, int bits, const uint8_t *b, size_t s)
|
||||||
void write_mat_bmp(const std::string &filename, const mat<T> &m)
|
|
||||||
{
|
{
|
||||||
FILE *f = fopen(filename.c_str(), "wb");
|
FILE *f = fopen(filename.c_str(), "wb");
|
||||||
if (f == nullptr)
|
if (f == nullptr)
|
||||||
return;
|
return;
|
||||||
BITMAPFILEHEADER h = { 0 };
|
BITMAPFILEHEADER h = { 0 };
|
||||||
h.bfType = 0x4D42;
|
h.bfType = 0x4D42;
|
||||||
h.bfSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + m.size() * sizeof(T);
|
h.bfSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + s;
|
||||||
h.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
|
h.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
|
||||||
BITMAPINFOHEADER i = { 0 };
|
BITMAPINFOHEADER i = { 0 };
|
||||||
i.biSize = sizeof(i);
|
i.biSize = sizeof(i);
|
||||||
i.biWidth = m.getWidth();
|
i.biWidth = width;
|
||||||
i.biHeight = m.getHeight();
|
i.biHeight = height;
|
||||||
i.biPlanes = 1;
|
i.biPlanes = 1;
|
||||||
i.biBitCount = sizeof(T) * 8;
|
i.biBitCount = bits;
|
||||||
i.biCompression = 0;
|
i.biCompression = 0;
|
||||||
i.biSizeImage = 0;
|
i.biSizeImage = 0;
|
||||||
i.biXPelsPerMeter = 0;
|
i.biXPelsPerMeter = 0;
|
||||||
|
|
@ -92,12 +136,18 @@ void write_mat_bmp(const std::string &filename, const mat<T> &m)
|
||||||
i.biClrImportant = 0;
|
i.biClrImportant = 0;
|
||||||
fwrite(&h, sizeof(BITMAPFILEHEADER), 1, f);
|
fwrite(&h, sizeof(BITMAPFILEHEADER), 1, f);
|
||||||
fwrite(&i, sizeof(BITMAPINFOHEADER), 1, f);
|
fwrite(&i, sizeof(BITMAPINFOHEADER), 1, f);
|
||||||
fwrite(&m(0, 0), m.size() * sizeof(T), 1, f);
|
fwrite(b, s, 1, f);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
void write_mat_tga(const std::string &filename, const mat<T> &m)
|
inline void write_mat_bmp(const std::string &filename, const mat<T> &m)
|
||||||
|
{
|
||||||
|
write_mat_bmp(filename, m.getWidth(), m.getHeight(), sizeof(T) * CHAR_BIT, (const uint8_t *)&m(0, 0), m.size() * sizeof(T));
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
inline void write_mat_tga(const std::string &filename, const mat<T> &m)
|
||||||
{
|
{
|
||||||
FILE *f = fopen(filename.c_str(), "wb");
|
FILE *f = fopen(filename.c_str(), "wb");
|
||||||
if (f == nullptr)
|
if (f == nullptr)
|
||||||
|
|
|
||||||
|
|
@ -344,7 +344,7 @@ bool CreateScene(model &model, const std::string &name, FbxManager* pSdkManager,
|
||||||
|
|
||||||
// Set texture properties.
|
// Set texture properties.
|
||||||
lTexture = FbxFileTexture::Create(pScene, "Diffuse Texture");
|
lTexture = FbxFileTexture::Create(pScene, "Diffuse Texture");
|
||||||
lTexture->SetFileName((b.tex_mask + ".TM.tga").c_str()); // Resource file is in current directory.
|
lTexture->SetFileName((b.tex_mask + texture_extension).c_str()); // Resource file is in current directory.
|
||||||
lTexture->SetTextureUse(FbxTexture::eStandard);
|
lTexture->SetTextureUse(FbxTexture::eStandard);
|
||||||
lTexture->SetMappingType(FbxTexture::eUV);
|
lTexture->SetMappingType(FbxTexture::eUV);
|
||||||
lTexture->SetMaterialUse(FbxFileTexture::eModelMaterial);
|
lTexture->SetMaterialUse(FbxFileTexture::eModelMaterial);
|
||||||
|
|
@ -354,7 +354,7 @@ bool CreateScene(model &model, const std::string &name, FbxManager* pSdkManager,
|
||||||
|
|
||||||
// Set texture properties.
|
// Set texture properties.
|
||||||
lTexture = FbxFileTexture::Create(pScene, "Ambient Texture");
|
lTexture = FbxFileTexture::Create(pScene, "Ambient Texture");
|
||||||
lTexture->SetFileName((b.tex_mask + ".TM.tga").c_str()); // Resource file is in current directory.
|
lTexture->SetFileName((b.tex_mask + texture_extension).c_str()); // Resource file is in current directory.
|
||||||
lTexture->SetTextureUse(FbxTexture::eStandard);
|
lTexture->SetTextureUse(FbxTexture::eStandard);
|
||||||
lTexture->SetMappingType(FbxTexture::eUV);
|
lTexture->SetMappingType(FbxTexture::eUV);
|
||||||
lTexture->SetMaterialUse(FbxFileTexture::eModelMaterial);
|
lTexture->SetMaterialUse(FbxFileTexture::eModelMaterial);
|
||||||
|
|
@ -364,7 +364,7 @@ bool CreateScene(model &model, const std::string &name, FbxManager* pSdkManager,
|
||||||
|
|
||||||
// Set texture properties.
|
// Set texture properties.
|
||||||
lTexture = FbxFileTexture::Create(pScene, "Specular Texture");
|
lTexture = FbxFileTexture::Create(pScene, "Specular Texture");
|
||||||
lTexture->SetFileName((b.tex_spec + ".TM.tga").c_str()); // Resource file is in current directory.
|
lTexture->SetFileName((b.tex_spec + texture_extension).c_str()); // Resource file is in current directory.
|
||||||
lTexture->SetTextureUse(FbxTexture::eStandard);
|
lTexture->SetTextureUse(FbxTexture::eStandard);
|
||||||
lTexture->SetMappingType(FbxTexture::eUV);
|
lTexture->SetMappingType(FbxTexture::eUV);
|
||||||
lTexture->SetMaterialUse(FbxFileTexture::eModelMaterial);
|
lTexture->SetMaterialUse(FbxFileTexture::eModelMaterial);
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,7 @@
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
const float scale_mult = 30.0f;
|
const float scale_mult = 30.0f;
|
||||||
|
const std::string texture_extension = ".TM.bmp";
|
||||||
|
|
||||||
const map<char, string> transliteration =
|
const map<char, string> transliteration =
|
||||||
{
|
{
|
||||||
|
|
@ -290,8 +291,6 @@ void animation::segment::loadData(const buffer &b)
|
||||||
|
|
||||||
std::string block::printMtl() const
|
std::string block::printMtl() const
|
||||||
{
|
{
|
||||||
static const string ext = ".TM.tga";
|
|
||||||
|
|
||||||
string s;
|
string s;
|
||||||
s += "newmtl " + name + "\n";
|
s += "newmtl " + name + "\n";
|
||||||
s += "\n";
|
s += "\n";
|
||||||
|
|
@ -303,13 +302,13 @@ std::string block::printMtl() const
|
||||||
// illum
|
// illum
|
||||||
s += "\n";
|
s += "\n";
|
||||||
if (string(tex_mask) != "_DEFAULT_")
|
if (string(tex_mask) != "_DEFAULT_")
|
||||||
s += "map_Ka " + string(tex_mask) + ext + "\n";
|
s += "map_Ka " + string(tex_mask) + texture_extension + "\n";
|
||||||
if (string(tex_mask) != "_DEFAULT_")
|
if (string(tex_mask) != "_DEFAULT_")
|
||||||
s += "map_Kd " + string(tex_mask) + ext + "\n";
|
s += "map_Kd " + string(tex_mask) + texture_extension + "\n";
|
||||||
if (string(tex_spec) != "_DEFAULT_")
|
if (string(tex_spec) != "_DEFAULT_")
|
||||||
s += "map_Ks " + string(tex_spec) + ext + "\n";
|
s += "map_Ks " + string(tex_spec) + texture_extension + "\n";
|
||||||
if (string(tex_spec) != "_DEFAULT_")
|
if (string(tex_spec) != "_DEFAULT_")
|
||||||
s += "map_Ns " + string(tex_spec) + ext + "\n";
|
s += "map_Ns " + string(tex_spec) + texture_extension + "\n";
|
||||||
s += "\n";
|
s += "\n";
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
extern const float scale_mult;
|
extern const float scale_mult;
|
||||||
|
extern const std::string texture_extension;
|
||||||
|
|
||||||
class buffer;
|
class buffer;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
@ -29,7 +30,7 @@
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
void convert_simple(buffer &dst, buffer &src, int width, int height)
|
void convert_simple(buffer &dst, const buffer &src, int width, int height)
|
||||||
{
|
{
|
||||||
int size = width * height * 2;
|
int size = width * height * 2;
|
||||||
for (int i = 0; i < size; i++)
|
for (int i = 0; i < size; i++)
|
||||||
|
|
@ -43,7 +44,7 @@ void convert_simple(buffer &dst, buffer &src, int width, int height)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void tm2tga(string fn)
|
void convert(string fn)
|
||||||
{
|
{
|
||||||
int width, height;
|
int width, height;
|
||||||
int dxt5_flag = 0;
|
int dxt5_flag = 0;
|
||||||
|
|
@ -55,27 +56,26 @@ void tm2tga(string fn)
|
||||||
src.read(&dxt5_flag, 1);
|
src.read(&dxt5_flag, 1);
|
||||||
src.seek(0x4C);
|
src.seek(0x4C);
|
||||||
|
|
||||||
|
fn = fn + ".bmp";
|
||||||
|
mat<uint32_t> m(width, height);
|
||||||
if (dxt5_flag)
|
if (dxt5_flag)
|
||||||
{
|
{
|
||||||
dxt5 d;
|
dxt5 d;
|
||||||
d.width = width;
|
d.width = width;
|
||||||
d.height = height;
|
d.height = height;
|
||||||
d.load_blocks(src);
|
d.load_blocks(src);
|
||||||
write_mat_tga(fn + ".tga", d.unpack_tm());
|
m = d.unpack_tm();
|
||||||
|
write_mat_bmp(fn, m);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
buffer dst;
|
buffer dst2;
|
||||||
tga t;
|
convert_simple(dst2, src, width, height);
|
||||||
t.width = width;
|
dst2.reset();
|
||||||
t.height = height;
|
memcpy(&m(0,0), dst2.getPtr(), dst2.size());
|
||||||
t.write(dst);
|
m = m.flip(); // flip tga (normal) to bmp (inverse)
|
||||||
|
|
||||||
convert_simple(dst, src, width, height);
|
|
||||||
transform(fn.begin(), fn.end(), fn.begin(), ::tolower);
|
|
||||||
fn = fn.substr(0, fn.rfind(".tm")) + ".tga";
|
|
||||||
writeFile(fn, dst.buf());
|
|
||||||
}
|
}
|
||||||
|
write_mat_bmp(fn, m);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
|
|
@ -86,7 +86,7 @@ try
|
||||||
printf("Usage: %s file.tm\n", argv[0]);
|
printf("Usage: %s file.tm\n", argv[0]);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
tm2tga(argv[1]);
|
convert(argv[1]);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
catch (std::exception &e)
|
catch (std::exception &e)
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
#include "decode.h"
|
#include "decode.h"
|
||||||
|
|
||||||
|
|
@ -104,7 +105,12 @@ void segment::load_segment()
|
||||||
auto f = file;
|
auto f = file;
|
||||||
|
|
||||||
fseek(f, offset, SEEK_SET);
|
fseek(f, offset, SEEK_SET);
|
||||||
assert(flags != 0);
|
if (flags == 0)
|
||||||
|
{
|
||||||
|
std::cerr << "Something is wrong. Maybe you trying to open aim2 files?\n";
|
||||||
|
std::cerr << "They can be opened with SDK extractor.\n";
|
||||||
|
throw std::runtime_error("error");
|
||||||
|
}
|
||||||
|
|
||||||
FREAD(size1);
|
FREAD(size1);
|
||||||
size2 = size1;
|
size2 = size1;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue