mirror of
https://github.com/aimrebirth/tools.git
synced 2026-04-15 01:43:25 +00:00
Initial .obj model creation.
This commit is contained in:
parent
e1f8b3b260
commit
ef6cd29915
4 changed files with 128 additions and 19 deletions
|
|
@ -4,6 +4,10 @@ set(output_dir ${CMAKE_BINARY_DIR}/bin)
|
||||||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${output_dir})
|
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${output_dir})
|
||||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${output_dir})
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${output_dir})
|
||||||
|
|
||||||
|
# Use solution folders.
|
||||||
|
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
|
||||||
|
set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER "CMake Targets")
|
||||||
|
|
||||||
project(aim_tools)
|
project(aim_tools)
|
||||||
|
|
||||||
if (MSVC)
|
if (MSVC)
|
||||||
|
|
@ -18,4 +22,13 @@ endif(MSVC)
|
||||||
include_directories(dep/dbmgr/include)
|
include_directories(dep/dbmgr/include)
|
||||||
add_subdirectory(dep/dbmgr)
|
add_subdirectory(dep/dbmgr)
|
||||||
|
|
||||||
|
add_custom_target(version ALL
|
||||||
|
COMMAND git rev-list HEAD --count > ${CMAKE_CURRENT_BINARY_DIR}/version.h_
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_BINARY_DIR}/version.h_ ${CMAKE_CURRENT_BINARY_DIR}/version.h.in
|
||||||
|
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
|
)
|
||||||
|
set_target_properties(version PROPERTIES FOLDER Helpers)
|
||||||
|
|
||||||
|
include_directories(${CMAKE_CURRENT_BINARY_DIR})
|
||||||
|
|
||||||
add_subdirectory(src)
|
add_subdirectory(src)
|
||||||
|
|
@ -16,11 +16,7 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <algorithm>
|
#include <sstream>
|
||||||
#include <fstream>
|
|
||||||
#include <iostream>
|
|
||||||
#include <map>
|
|
||||||
#include <set>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
@ -29,32 +25,51 @@ using namespace std;
|
||||||
|
|
||||||
#include "model.h"
|
#include "model.h"
|
||||||
|
|
||||||
model read_model(string fn)
|
const int build_version =
|
||||||
|
#include <version.h.in>
|
||||||
|
;
|
||||||
|
|
||||||
|
std::string version()
|
||||||
|
{
|
||||||
|
string s;
|
||||||
|
s = to_string(0) + "." +
|
||||||
|
to_string(1) + "." +
|
||||||
|
to_string(0) + "." +
|
||||||
|
to_string(build_version);
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
void convert_model(string fn)
|
||||||
{
|
{
|
||||||
model m;
|
model m;
|
||||||
FILE *f = fopen(fn.c_str(), "rb");
|
FILE *f = fopen(fn.c_str(), "rb");
|
||||||
if (!f)
|
if (!f)
|
||||||
return m;
|
return;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
m.load(f);
|
m.load(f);
|
||||||
|
|
||||||
|
auto p = ftell(f);
|
||||||
|
fseek(f, 0, SEEK_END);
|
||||||
|
auto end = ftell(f);
|
||||||
|
fclose(f);
|
||||||
|
|
||||||
|
if (p != end)
|
||||||
|
{
|
||||||
|
stringstream ss;
|
||||||
|
ss << hex << p << " != " << hex << end;
|
||||||
|
throw std::logic_error(ss.str());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (std::exception &e)
|
catch (std::exception &e)
|
||||||
{
|
{
|
||||||
printf("error: %s\n", fn.c_str());
|
printf("error: %s\n", fn.c_str());
|
||||||
printf("%s\n", e.what());
|
printf("%s\n", e.what());
|
||||||
return m;
|
fclose(f);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
auto p = ftell(f);
|
|
||||||
fseek(f, 0, SEEK_END);
|
m.writeObj(fn + ".obj");
|
||||||
auto end = ftell(f);
|
|
||||||
if (p != ftell(f))
|
|
||||||
{
|
|
||||||
printf("error: %s\n", fn.c_str());
|
|
||||||
printf(" : %x != %x\n", p, end);
|
|
||||||
}
|
|
||||||
fclose(f);
|
|
||||||
return m;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
|
|
@ -67,6 +82,20 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
read_model(argv[1]);
|
read_model(argv[1]);
|
||||||
#else
|
#else
|
||||||
|
convert_model("h:\\Games\\AIM\\data\\res0.pak.dir\\Data\\Models\\MOD_GL_M1_A_ATTACKER");
|
||||||
|
convert_model("h:\\Games\\AIM\\data\\res0.pak.dir\\Data\\Models\\MOD_GL_M1_B_BASE");
|
||||||
|
|
||||||
|
convert_model("h:\\Games\\AIM\\data\\res0.pak.dir\\Data\\Models\\MOD_BLD_BASE1");
|
||||||
|
convert_model("h:\\Games\\AIM\\data\\res0.pak.dir\\Data\\Models\\MOD_GL_S4_SINIGR");
|
||||||
|
|
||||||
|
convert_model("h:\\Games\\AIM\\data\\res0.pak.dir\\Data\\Models\\MOD_GL_FIRE");
|
||||||
|
convert_model("h:\\Games\\AIM\\data\\res0.pak.dir\\Data\\Models\\MOD_GL_FARA");
|
||||||
|
|
||||||
|
convert_model("h:\\Games\\AIM\\data\\res0.pak.dir\\Data\\Models\\MOD_FX_ANTI_MATER_GUN");
|
||||||
|
convert_model("h:\\Games\\AIM\\data\\res0.pak.dir\\Data\\Models\\MOD_UNFL_STONE01");
|
||||||
|
convert_model("h:\\Games\\AIM\\data\\res0.pak.dir\\Data\\Models\\MOD_L1_KUST");
|
||||||
|
convert_model("h:\\Games\\AIM\\data\\res0.pak.dir\\Data\\Models\\MOD_L6_KUST_12");
|
||||||
|
convert_model("h:\\Games\\AIM\\data\\res0.pak.dir\\Data\\Models\\MOD_GL_M1_A_ATTACKER_DAMAGED");
|
||||||
#endif
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -18,7 +18,13 @@
|
||||||
|
|
||||||
#include "model.h"
|
#include "model.h"
|
||||||
|
|
||||||
|
#include <fstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
std::string version();
|
||||||
|
|
||||||
#define FREAD(var) fread(&var, 1, sizeof(var), f)
|
#define FREAD(var) fread(&var, 1, sizeof(var), f)
|
||||||
#define SREAD(var) s.read(&var, sizeof(var))
|
#define SREAD(var) s.read(&var, sizeof(var))
|
||||||
|
|
@ -41,6 +47,27 @@ void vertex::load(s_file &s, uint32_t flags)
|
||||||
SREAD(t2);
|
SREAD(t2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string vertex::printVertex() const
|
||||||
|
{
|
||||||
|
string s;
|
||||||
|
s = "v " + to_string(-vX) + " " + to_string(vY) + " " + to_string(-vZ);
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string vertex::printNormal() const
|
||||||
|
{
|
||||||
|
string s;
|
||||||
|
s = "vn " + to_string(-nX) + " " + to_string(nY) + " " + to_string(-nZ);
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string vertex::printTex() const
|
||||||
|
{
|
||||||
|
string s;
|
||||||
|
s = "vt " + to_string(t1) + " " + to_string(1 - t2) + " " + to_string(0);
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
void fragment::load(FILE *f)
|
void fragment::load(FILE *f)
|
||||||
{
|
{
|
||||||
FREAD(type);
|
FREAD(type);
|
||||||
|
|
@ -189,3 +216,37 @@ void model::load(FILE *f)
|
||||||
throw std::logic_error("extraction error: fragment #" + std::to_string(i));
|
throw std::logic_error("extraction error: fragment #" + std::to_string(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void model::writeObj(std::string fn)
|
||||||
|
{
|
||||||
|
ofstream o(fn);
|
||||||
|
o << "# " << "\n";
|
||||||
|
o << "# A.I.M. Model Converter (ver. " << version() << ")\n";
|
||||||
|
o << "# " << "\n";
|
||||||
|
o << "\n";
|
||||||
|
|
||||||
|
if (fragments.empty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
const auto &f = fragments[0];
|
||||||
|
for (auto &v : f.vertices)
|
||||||
|
o << v.printVertex() << "\n";
|
||||||
|
o << "\n";
|
||||||
|
for (auto &v : f.vertices)
|
||||||
|
o << v.printNormal() << "\n";
|
||||||
|
o << "\n";
|
||||||
|
for (auto &v : f.vertices)
|
||||||
|
o << v.printTex() << "\n";
|
||||||
|
o << "\n";
|
||||||
|
|
||||||
|
for (int i = 0; i <= f.n_triangles - 3; i += 3)
|
||||||
|
{
|
||||||
|
auto x = to_string(f.triangles[i] + 1);
|
||||||
|
auto y = to_string(f.triangles[i + 2] + 1);
|
||||||
|
auto z = to_string(f.triangles[i + 1] + 1);
|
||||||
|
x += "/" + x;
|
||||||
|
y += "/" + y;
|
||||||
|
z += "/" + z;
|
||||||
|
o << "f " << x << " " << y << " " << z << "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
struct s_file
|
struct s_file
|
||||||
|
|
@ -74,6 +75,10 @@ struct vertex
|
||||||
float t2;
|
float t2;
|
||||||
|
|
||||||
void load(s_file &s, uint32_t flags);
|
void load(s_file &s, uint32_t flags);
|
||||||
|
|
||||||
|
std::string printVertex() const;
|
||||||
|
std::string printNormal() const;
|
||||||
|
std::string printTex() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef uint16_t triangle;
|
typedef uint16_t triangle;
|
||||||
|
|
@ -185,4 +190,5 @@ struct model
|
||||||
std::vector<fragment> fragments;
|
std::vector<fragment> fragments;
|
||||||
|
|
||||||
void load(FILE *f);
|
void load(FILE *f);
|
||||||
|
void writeObj(std::string fn);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue