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#include <string>
15#include <vector>
16#include <map>
17#include <cstdint>
18#include <functional>
19#include <tiny_gltf.h>
20#include "wows-assets-bin.h"
21
23extern bool wows_stitch_verbose;
24
31
37#define wows_stitch_vlog(...) \
38 do { \
39 if (wows_stitch_verbose) \
40 fprintf(stderr, __VA_ARGS__); \
41 } while (0)
42
44using wows_mat16d = std::vector<double>;
45
58 std::string gameparams_path;
62 std::vector<uint8_t> gameparams_data;
64 std::vector<uint8_t> assets_bin_data;
65 std::string hull_upgrade;
66 bool with_turrets = true;
67 bool with_propellers = true;
68 bool with_textures = true;
69 int max_tex_size = 2048;
70 int lod_level = -1;
71 bool exclude_damage = true;
74 std::function<void(int)> progress_cb;
75};
76
81 std::string hp_name;
82 std::string model_path;
83};
84
89 std::string hull_model;
90 std::vector<wows_mount_entry> mounts;
91};
92
97 tinygltf::Model model;
98 std::string mesh_name;
99 std::string geom_path;
101};
102
124bool wows_stitch_export_ship(const std::string &game_dir, const std::string &ship_name, const std::string &output_path,
125 const wows_ship_export_options &opts = {});
126
133using wows_file_provider_t = std::function<std::vector<uint8_t>(const std::string &)>;
134
153bool wows_stitch_export_ship_to_glb_mem(const std::string &game_dir, const std::string &ship_name,
154 std::vector<uint8_t> &glb_out, const wows_ship_export_options &opts = {},
155 wows_file_provider_t file_provider = nullptr);
156
164std::string wows_stitch_path_basename(const std::string &p);
165
167std::string wows_stitch_path_dirname(const std::string &p);
168
170std::string wows_stitch_stem(const std::string &filename);
171
173std::string wows_stitch_normalize_slashes(std::string s);
174
176bool wows_stitch_file_exists(const std::string &p);
177
185std::string wows_stitch_model_to_geom_path(const std::string &model, const std::string &game_dir);
186
196std::string wows_stitch_geom_to_visual_suffix(const std::string &geom_path);
197
208std::vector<std::string> wows_stitch_find_hull_geoms(const std::string &hull_model, const std::string &game_dir);
209
221std::vector<std::string> wows_stitch_find_propeller_geoms(const std::string &hull_model, const std::string &game_dir);
222
230std::string wows_stitch_find_game_file(const std::string &game_dir, const std::string &filename);
231
246
254
268bool wows_stitch_geom_to_model(const std::string &geom_path, tinygltf::Model &model_out);
269
278bool wows_stitch_geom_to_model_from_memory(const uint8_t *data, size_t size, tinygltf::Model &model_out);
279
289tinygltf::Model wows_stitch_merge_parts(std::vector<wows_glb_part> &parts);
290
308std::vector<uint8_t> wows_stitch_decode_dds(const uint8_t *d, size_t sz, int *W, int *H);
309
319std::vector<uint8_t> wows_stitch_dds_to_png(const std::string &path, int max_sz);
320
332std::vector<uint8_t> wows_stitch_dds_to_png_from_memory(const uint8_t *data, size_t size, int max_sz);
333
354void wows_stitch_apply_textures(tinygltf::Model &model, const std::vector<std::string> &geom_order,
355 wows_assets_bin_pdb_t *pdb, const std::string &game_dir, int lod_level,
356 bool excl_damage, int max_tex, std::function<void(int)> progress_cb = nullptr,
357 wows_file_provider_t file_provider = nullptr);
358
366void wows_stitch_apply_default_material(tinygltf::Model &model);
367
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:133
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:96
wows_mat16d matrix
Definition wows-model-exporter.h:100
std::string geom_path
Definition wows-model-exporter.h:99
tinygltf::Model model
Definition wows-model-exporter.h:97
std::string mesh_name
Definition wows-model-exporter.h:98
Aggregated hull information for one ship hull variant.
Definition wows-model-exporter.h:88
std::vector< wows_mount_entry > mounts
Definition wows-model-exporter.h:90
std::string hull_model
Definition wows-model-exporter.h:89
A turret or module mount point, pairing a hardpoint name with a model path.
Definition wows-model-exporter.h:80
std::string model_path
Definition wows-model-exporter.h:82
std::string hp_name
Definition wows-model-exporter.h:81
Options controlling a full-ship GLB export.
Definition wows-model-exporter.h:57
int lod_level
Definition wows-model-exporter.h:70
bool with_turrets
Definition wows-model-exporter.h:66
int max_tex_size
Definition wows-model-exporter.h:69
bool with_textures
Definition wows-model-exporter.h:68
std::vector< uint8_t > gameparams_data
Definition wows-model-exporter.h:62
std::string wows_assets_bin_path
Definition wows-model-exporter.h:59
std::function< void(int)> progress_cb
Definition wows-model-exporter.h:74
std::string gameparams_path
Definition wows-model-exporter.h:58
bool exclude_damage
Definition wows-model-exporter.h:71
std::string hull_upgrade
Definition wows-model-exporter.h:65
bool with_propellers
Definition wows-model-exporter.h:67
std::vector< uint8_t > assets_bin_data
Definition wows-model-exporter.h:64
void wows_stitch_set_verbose(bool v)
Enable or disable verbose diagnostic output.
bool wows_stitch_verbose
Set to true before calling any stitch function to enable verbose logging to stderr.
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:44