From a6a712cd0c987fc98a62f1d9773e563cd4c68c59 Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Sat, 21 May 2022 17:50:55 -0400 Subject: [PATCH] When invoking the model compiler in "no ui" mode, specify absolute path This is going to be used in the future "asset pipeline" tool. The auto export animations and materials flags are also turned off in "no ui" mode. --- tools/modelcompiler/include/modeleditor.hpp | 2 +- tools/modelcompiler/src/modeleditor.cpp | 26 +++++++++++++++------ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/tools/modelcompiler/include/modeleditor.hpp b/tools/modelcompiler/include/modeleditor.hpp index b7877ed..71759be 100755 --- a/tools/modelcompiler/include/modeleditor.hpp +++ b/tools/modelcompiler/include/modeleditor.hpp @@ -17,5 +17,5 @@ public: std::string data_path, model_path; - void compile_model(); + void compile_model(std::string compiled_model_path); }; diff --git a/tools/modelcompiler/src/modeleditor.cpp b/tools/modelcompiler/src/modeleditor.cpp index 103075c..dd6e3a5 100755 --- a/tools/modelcompiler/src/modeleditor.cpp +++ b/tools/modelcompiler/src/modeleditor.cpp @@ -31,18 +31,23 @@ void app_main(prism::engine* engine) { {editor->getDefaultX(), editor->getDefaultY(), 300, 300}, WindowFlags::None); } else { + std::string compiled_model_path; + for(auto [i, argument] : utility::enumerate(engine->command_line_arguments)) { if(argument == "--model-path") editor->model_path = engine->command_line_arguments[i + 1]; - if(argument == "--data-path") - editor->data_path = engine->command_line_arguments[i + 1]; + if(argument == "--compiled-model-path") + compiled_model_path = engine->command_line_arguments[i + 1]; if(argument == "--compile-static") editor->flags.compile_static = true; } - editor->compile_model(); + editor->flags.export_animations = false; + editor->flags.export_materials = false; + + editor->compile_model(compiled_model_path); platform::force_quit(); } @@ -159,7 +164,7 @@ void write_string(FILE* file, const std::string& str) { } } -void ModelEditor::compile_model() { +void ModelEditor::compile_model(std::string compiled_model_path) { struct BoneWeight { unsigned int vertex_index = 0, bone_index = 0; float weight = 0.0f; @@ -209,7 +214,9 @@ void ModelEditor::compile_model() { auto name = model_path.substr(model_path.find_last_of("/") + 1, model_path.length()); name = name.substr(0, name.find_last_of(".")); - FILE* file = fopen((data_path + "/models/" + name + ".model").c_str(), "wb"); + FILE* file = fopen(compiled_model_path.c_str(), "wb"); + + fmt::print("Exporting to {}...\n", compiled_model_path); int version = 7; fwrite(&version, sizeof(int), 1, file); @@ -418,6 +425,8 @@ void ModelEditor::compile_model() { fclose(file); + fmt::print("Finished writing model!\n"); + if(flags.export_materials) { for(int i = 0; i < sc->mNumMaterials; i++) { auto path = data_path + "/materials/" + sc->mMaterials[i]->GetName().C_Str() + ".material"; @@ -538,8 +547,11 @@ void ModelEditor::drawUI() { if(!model_path.empty() && !data_path.empty()) { ImGui::Text("%s will be compiled for data path %s", model_path.c_str(), data_path.c_str()); - if(ImGui::Button("Compile")) - compile_model(); + if(ImGui::Button("Compile")) { + auto name = model_path.substr(model_path.find_last_of("/") + 1, model_path.length()); + name = name.substr(0, name.find_last_of(".")); + compile_model(data_path + "/models/" + name + ".model"); + } } else { ImGui::TextColored(ImVec4(1.0, 0.0, 0.0, 1.0), "Please select a path first before compiling!"); }