mirror of
https://git.mirrors.martin98.com/https://github.com/syoyo/tinygltf.git
synced 2025-08-11 08:19:03 +08:00
Can select image file format with -f argument in gltf util
Signed-off-by: Arthur Brainville (Ybalrid) <ybalrid@ybalrid.info>
This commit is contained in:
parent
4ba01f5968
commit
2960379eba
@ -4,6 +4,8 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include "texture_dumper.h"
|
||||||
|
|
||||||
namespace gltfutil {
|
namespace gltfutil {
|
||||||
|
|
||||||
enum class ui_mode { cli, interactive };
|
enum class ui_mode { cli, interactive };
|
||||||
@ -45,6 +47,9 @@ struct configuration {
|
|||||||
std::string input_path, output_dir;
|
std::string input_path, output_dir;
|
||||||
ui_mode mode;
|
ui_mode mode;
|
||||||
cli_action action = cli_action::not_set;
|
cli_action action = cli_action::not_set;
|
||||||
|
texture_dumper::texture_output_format requested_format =
|
||||||
|
texture_dumper::texture_output_format::not_specified;
|
||||||
|
|
||||||
bool has_output_dir;
|
bool has_output_dir;
|
||||||
bool is_valid() {
|
bool is_valid() {
|
||||||
// TODO impl check
|
// TODO impl check
|
||||||
|
@ -16,10 +16,12 @@ int usage(int ret = 0) {
|
|||||||
using std::cout;
|
using std::cout;
|
||||||
cout << "gltfutil: tool for manipulating gltf files\n"
|
cout << "gltfutil: tool for manipulating gltf files\n"
|
||||||
<< " usage information:\n\n"
|
<< " usage information:\n\n"
|
||||||
<< "\t gltfutil (-d|-h) [path to .gltf/glb] (-o [path to output "
|
<< "\t gltfutil (-d|-h|) (-f [png|bmp|tga]) [path to .gltf/glb] (-o "
|
||||||
"directory])\n\n"
|
"[path to output directory])\n\n"
|
||||||
//<< "\t\t -i: start in interactive mode\n"
|
//<< "\t\t -i: start in interactive mode\n"
|
||||||
<< "\t\t -d: dump enclosed content (image assets)\n"
|
<< "\t\t -d: dump enclosed content (image assets)\n"
|
||||||
|
<< "\t\t -f: file format for image output"
|
||||||
|
<< "\t\t -o: ouptput directory path"
|
||||||
<< "\t\t -h: print this help\n";
|
<< "\t\t -h: print this help\n";
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -49,6 +51,11 @@ int parse_args(int argc, char** argv) {
|
|||||||
i++;
|
i++;
|
||||||
config.output_dir = argv[i];
|
config.output_dir = argv[i];
|
||||||
break;
|
break;
|
||||||
|
case 'f':
|
||||||
|
i++;
|
||||||
|
config.requested_format =
|
||||||
|
texture_dumper::get_fromat_from_string(argv[i]);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
return arg_error();
|
return arg_error();
|
||||||
}
|
}
|
||||||
@ -85,12 +92,19 @@ int parse_args(int argc, char** argv) {
|
|||||||
switch (config.action) {
|
switch (config.action) {
|
||||||
case cli_action::help:
|
case cli_action::help:
|
||||||
return usage();
|
return usage();
|
||||||
|
break;
|
||||||
|
|
||||||
case cli_action::dump: {
|
case cli_action::dump: {
|
||||||
texture_dumper dumper(model);
|
texture_dumper dumper(model);
|
||||||
|
if (config.requested_format !=
|
||||||
|
texture_dumper::texture_output_format::not_specified)
|
||||||
|
dumper.set_output_format(config.requested_format);
|
||||||
|
|
||||||
if (config.output_dir.empty())
|
if (config.output_dir.empty())
|
||||||
dumper.dump_to_folder();
|
dumper.dump_to_folder();
|
||||||
else
|
else
|
||||||
dumper.dump_to_folder(config.output_dir);
|
dumper.dump_to_folder(config.output_dir);
|
||||||
|
|
||||||
} break;
|
} break;
|
||||||
default:
|
default:
|
||||||
return arg_error();
|
return arg_error();
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
#include "stb_image_write.h"
|
#include "stb_image_write.h"
|
||||||
#include "texture_dumper.h"
|
#include "texture_dumper.h"
|
||||||
|
|
||||||
|
#include <tiny_gltf.h>
|
||||||
|
|
||||||
using namespace gltfutil;
|
using namespace gltfutil;
|
||||||
using namespace tinygltf;
|
using namespace tinygltf;
|
||||||
using std::cout;
|
using std::cout;
|
||||||
@ -15,7 +17,8 @@ texture_dumper::texture_dumper(const Model& input)
|
|||||||
void texture_dumper::dump_to_folder(const std::string& path) {
|
void texture_dumper::dump_to_folder(const std::string& path) {
|
||||||
cout << "dumping to folder " << path << '\n';
|
cout << "dumping to folder " << path << '\n';
|
||||||
cout << "model file has " << model.textures.size() << " textures.\n";
|
cout << "model file has " << model.textures.size() << " textures.\n";
|
||||||
size_t index;
|
size_t index = 0;
|
||||||
|
|
||||||
for (const auto& texture : model.textures) {
|
for (const auto& texture : model.textures) {
|
||||||
index++;
|
index++;
|
||||||
const auto& image = model.images[texture.source];
|
const auto& image = model.images[texture.source];
|
||||||
@ -23,6 +26,7 @@ void texture_dumper::dump_to_folder(const std::string& path) {
|
|||||||
cout << "image size is: " << image.width << 'x' << image.height << '\n';
|
cout << "image size is: " << image.width << 'x' << image.height << '\n';
|
||||||
cout << "pixel channel count :" << image.component << '\n';
|
cout << "pixel channel count :" << image.component << '\n';
|
||||||
std::string name = image.name.empty() ? std::to_string(index) : image.name;
|
std::string name = image.name.empty() ? std::to_string(index) : image.name;
|
||||||
|
|
||||||
switch (configured_format) {
|
switch (configured_format) {
|
||||||
case texture_output_format::png:
|
case texture_output_format::png:
|
||||||
name = path + "/" + name + ".png";
|
name = path + "/" + name + ".png";
|
||||||
@ -45,3 +49,19 @@ void texture_dumper::dump_to_folder(const std::string& path) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void texture_dumper::set_output_format(texture_output_format format) {
|
||||||
|
configured_format = format;
|
||||||
|
}
|
||||||
|
|
||||||
|
texture_dumper::texture_output_format texture_dumper::get_fromat_from_string(
|
||||||
|
const std::string& str) {
|
||||||
|
std::string type = str;
|
||||||
|
std::transform(str.begin(), str.end(), type.begin(), ::tolower);
|
||||||
|
|
||||||
|
if (type == "png") return texture_output_format::png;
|
||||||
|
if (type == "bmp") return texture_output_format::bmp;
|
||||||
|
if (type == "tga") return texture_output_format::tga;
|
||||||
|
|
||||||
|
return texture_output_format::not_specified;
|
||||||
|
}
|
||||||
|
@ -16,5 +16,8 @@ class texture_dumper {
|
|||||||
public:
|
public:
|
||||||
texture_dumper(const tinygltf::Model& inputModel);
|
texture_dumper(const tinygltf::Model& inputModel);
|
||||||
void dump_to_folder(const std::string& path = "./");
|
void dump_to_folder(const std::string& path = "./");
|
||||||
|
void set_output_format(texture_output_format format);
|
||||||
|
|
||||||
|
static texture_output_format get_fromat_from_string(const std::string& str);
|
||||||
};
|
};
|
||||||
} // namespace gltfutil
|
} // namespace gltfutil
|
||||||
|
Loading…
x
Reference in New Issue
Block a user