WoWs Model Exported
World of Warships 3D model Exporter
Loading...
Searching...
No Matches
wows-model-exporter.h
Go to the documentation of this file.
1
13#pragma once
14
15#if defined(_WIN32)
16# if defined(WOWS_GEOMETRY_BUILDING)
17# define WOWS_API __declspec(dllexport)
18# else
19# define WOWS_API __declspec(dllimport)
20# endif
21#else
22# define WOWS_API
23#endif
24
25#include <string>
26#include <vector>
27#include <map>
28#include <cstdint>
29#include <functional>
30#include <tiny_gltf.h>
31#include "wows-assets-bin.h"
32
35
42
48#define wows_stitch_vlog(...) \
49 do { \
50 if (wows_stitch_verbose) \
51 fprintf(stderr, __VA_ARGS__); \
52 } while (0)
53
55using wows_mat16d = std::vector<double>;
56
69 std::string gameparams_path;
73 std::vector<uint8_t> gameparams_data;
75 std::vector<uint8_t> assets_bin_data;
76 std::string hull_upgrade;
77 bool with_turrets = true;
78 bool with_propellers = true;
79 bool with_textures = true;
80 int max_tex_size = 2048;
81 int lod_level = -1;
82 bool exclude_damage = true;
85 std::function<void(int)> progress_cb;
86};
87
92 std::string hp_name;
93 std::string model_path;
94};
95
100 std::string hull_model;
101 std::vector<wows_mount_entry> mounts;
102};
103
108 tinygltf::Model model;
109 std::string mesh_name;
110 std::string geom_path;
112};
113
135bool wows_stitch_export_ship(const std::string &game_dir, const std::string &ship_name, const std::string &output_path,
136 const wows_ship_export_options &opts = {});
137
144using wows_file_provider_t = std::function<std::vector<uint8_t>(const std::string &)>;
145
164bool wows_stitch_export_ship_to_glb_mem(const std::string &game_dir, const std::string &ship_name,
165 std::vector<uint8_t> &glb_out, const wows_ship_export_options &opts = {},
166 wows_file_provider_t file_provider = nullptr);
167
175std::string wows_stitch_path_basename(const std::string &p);
176
178std::string wows_stitch_path_dirname(const std::string &p);
179
181std::string wows_stitch_stem(const std::string &filename);
182
184std::string wows_stitch_normalize_slashes(std::string s);
185
187bool wows_stitch_file_exists(const std::string &p);
188
196std::string wows_stitch_model_to_geom_path(const std::string &model, const std::string &game_dir);
197
207std::string wows_stitch_geom_to_visual_suffix(const std::string &geom_path);
208
219std::vector<std::string> wows_stitch_find_hull_geoms(const std::string &hull_model, const std::string &game_dir);
220
232std::vector<std::string> wows_stitch_find_propeller_geoms(const std::string &hull_model, const std::string &game_dir);
233
241std::string wows_stitch_find_game_file(const std::string &game_dir, const std::string &filename);
242
257
265
279bool wows_stitch_geom_to_model(const std::string &geom_path, tinygltf::Model &model_out);
280
289bool wows_stitch_geom_to_model_from_memory(const uint8_t *data, size_t size, tinygltf::Model &model_out);
290
300tinygltf::Model wows_stitch_merge_parts(std::vector<wows_glb_part> &parts);
301
319std::vector<uint8_t> wows_stitch_decode_dds(const uint8_t *d, size_t sz, int *W, int *H);
320
330std::vector<uint8_t> wows_stitch_dds_to_png(const std::string &path, int max_sz);
331
343std::vector<uint8_t> wows_stitch_dds_to_png_from_memory(const uint8_t *data, size_t size, int max_sz);
344
365void wows_stitch_apply_textures(tinygltf::Model &model, const std::vector<std::string> &geom_order,
366 wows_assets_bin_pdb_t *pdb, const std::string &game_dir, int lod_level,
367 bool excl_damage, int max_tex, std::function<void(int)> progress_cb = nullptr,
368 wows_file_provider_t file_provider = nullptr);
369
377void wows_stitch_apply_default_material(tinygltf::Model &model);
378
struct wows_assets_bin_pdb_s wows_assets_bin_pdb_t
Opaque handle to an open assets.bin database.
Definition wows-assets-bin.h:83
std::vector< uint8_t > wows_stitch_dds_to_png_from_memory(const uint8_t *data, size_t size, int max_sz)
Decode a DDS buffer in memory and encode it as a PNG byte buffer.
std::vector< uint8_t > wows_stitch_decode_dds(const uint8_t *d, size_t sz, int *W, int *H)
Decode a DDS texture buffer to raw RGBA pixels.
std::vector< uint8_t > wows_stitch_dds_to_png(const std::string &path, int max_sz)
Load a .dds file from disk and encode it as a PNG byte buffer.
std::function< std::vector< uint8_t >(const std::string &)> wows_file_provider_t
Callback type for reading a file from an arbitrary storage backend.
Definition wows-model-exporter.h:144
bool wows_stitch_export_ship(const std::string &game_dir, const std::string &ship_name, const std::string &output_path, const wows_ship_export_options &opts={})
Export a complete ship model to a binary glTF (GLB) file.
bool wows_stitch_export_ship_to_glb_mem(const std::string &game_dir, const std::string &ship_name, std::vector< uint8_t > &glb_out, const wows_ship_export_options &opts={}, wows_file_provider_t file_provider=nullptr)
Export a complete ship model to a binary glTF (GLB) buffer in memory.
tinygltf::Model wows_stitch_merge_parts(std::vector< wows_glb_part > &parts)
Merge a list of wows_glb_part objects into a single tinygltf scene.
bool wows_stitch_geom_to_model(const std::string &geom_path, tinygltf::Model &model_out)
Load a .geometry file and convert it to a tinygltf model.
bool wows_stitch_geom_to_model_from_memory(const uint8_t *data, size_t size, tinygltf::Model &model_out)
Load a .geometry file from a memory buffer and convert it to a tinygltf model.
wows_mat16d wows_stitch_float_to_double_mat(const float m[16])
Convert a float[16] column-major matrix to a double wows_mat16d.
wows_mat16d wows_stitch_mat4_mul_d(const wows_mat16d &a, const wows_mat16d &b)
Multiply two column-major 4×4 double matrices.
std::vector< std::string > wows_stitch_find_propeller_geoms(const std::string &hull_model, const std::string &game_dir)
Find propeller/screw .geometry files for a ship.
std::string wows_stitch_stem(const std::string &filename)
Return the stem of a filename (basename without the final extension).
bool wows_stitch_file_exists(const std::string &p)
Return true if the file at p exists and is readable.
std::string wows_stitch_model_to_geom_path(const std::string &model, const std::string &game_dir)
Resolve a .visual model path to the corresponding .geometry file path.
std::string wows_stitch_path_basename(const std::string &p)
Return the basename component of a path (everything after the last /).
std::string wows_stitch_geom_to_visual_suffix(const std::string &geom_path)
Convert a .geometry filesystem path to its .visual suffix form.
std::vector< std::string > wows_stitch_find_hull_geoms(const std::string &hull_model, const std::string &game_dir)
Find all .geometry files belonging to a hull model.
std::string wows_stitch_normalize_slashes(std::string s)
Replace all backslashes in s with forward slashes and return the result.
std::string wows_stitch_path_dirname(const std::string &p)
Return the directory component of a path (everything up to and including the last /).
std::string wows_stitch_find_game_file(const std::string &game_dir, const std::string &filename)
Search for a game asset file by name under game_dir.
void wows_stitch_apply_default_material(tinygltf::Model &model)
Apply a uniform grey default material to all primitives in a model.
void wows_stitch_apply_textures(tinygltf::Model &model, const std::vector< std::string > &geom_order, wows_assets_bin_pdb_t *pdb, const std::string &game_dir, int lod_level, bool excl_damage, int max_tex, std::function< void(int)> progress_cb=nullptr, wows_file_provider_t file_provider=nullptr)
Attach textures from assets.bin to the materials in a glTF model.
One resolved geometry part ready to be merged into a GLB scene.
Definition wows-model-exporter.h:107
wows_mat16d matrix
Definition wows-model-exporter.h:111
std::string geom_path
Definition wows-model-exporter.h:110
tinygltf::Model model
Definition wows-model-exporter.h:108
std::string mesh_name
Definition wows-model-exporter.h:109
Aggregated hull information for one ship hull variant.
Definition wows-model-exporter.h:99
std::vector< wows_mount_entry > mounts
Definition wows-model-exporter.h:101
std::string hull_model
Definition wows-model-exporter.h:100
A turret or module mount point, pairing a hardpoint name with a model path.
Definition wows-model-exporter.h:91
std::string model_path
Definition wows-model-exporter.h:93
std::string hp_name
Definition wows-model-exporter.h:92
Options controlling a full-ship GLB export.
Definition wows-model-exporter.h:68
int lod_level
Definition wows-model-exporter.h:81
bool with_turrets
Definition wows-model-exporter.h:77
int max_tex_size
Definition wows-model-exporter.h:80
bool with_textures
Definition wows-model-exporter.h:79
std::vector< uint8_t > gameparams_data
Definition wows-model-exporter.h:73
std::string wows_assets_bin_path
Definition wows-model-exporter.h:70
std::function< void(int)> progress_cb
Definition wows-model-exporter.h:85
std::string gameparams_path
Definition wows-model-exporter.h:69
bool exclude_damage
Definition wows-model-exporter.h:82
std::string hull_upgrade
Definition wows-model-exporter.h:76
bool with_propellers
Definition wows-model-exporter.h:78
std::vector< uint8_t > assets_bin_data
Definition wows-model-exporter.h:75
#define WOWS_API
Definition wows-model-exporter.h:22
void wows_stitch_set_verbose(bool v)
Enable or disable verbose diagnostic output.
std::vector< double > wows_mat16d
Column-major 4×4 transform matrix stored as a flat double vector of 16 elements.
Definition wows-model-exporter.h:55
WOWS_API bool wows_stitch_verbose
Set to true before calling any stitch function to enable verbose logging to stderr.