diff --git a/EU07.cpp b/EU07.cpp index 19703dbe1..6b7ed17b9 100644 --- a/EU07.cpp +++ b/EU07.cpp @@ -48,7 +48,7 @@ Stele, firleju, szociu, hunter, ZiomalCl, OLI_EU and others #endif #endif -void export_e3d_standalone(std::string in, std::string out, int flags, bool dynamic); +int export_e3d_standalone(std::string in, std::string out, int flags, bool dynamic); int export_btf_standalone(std::string in, std::string out); int generate_nodebank_previews(int Argc, char *Argv[]); @@ -144,7 +144,7 @@ int main(int argc, char *argv[]) std::string out(argv[3]); int flags = std::stoi(std::string(argv[4])); int dynamic = std::stoi(std::string(argv[5])); - export_e3d_standalone(in, out, flags, dynamic); + exitcode = export_e3d_standalone(in, out, flags, dynamic); } // standalone generation of preview images of the node bank models: -generate-nodebank-previews [options] else if (argc >= 2 && std::string(argv[1]) == "-generate-nodebank-previews") diff --git a/export_e3d_standalone.cpp b/export_e3d_standalone.cpp index ecdd4ab9c..6a1ae29fc 100644 --- a/export_e3d_standalone.cpp +++ b/export_e3d_standalone.cpp @@ -1,17 +1,39 @@ #include "stdafx.h" +#include + #include "model/Model3d.h" #include "utilities/Globals.h" +#include "utilities/Logs.h" #include "rendering/renderer.h" -void export_e3d_standalone(std::string in, std::string out, int flags, bool dynamic) +int export_e3d_standalone(std::string in, std::string out, int flags, bool dynamic) { Global.iConvertModels = flags; Global.iWriteLogEnabled = 2; Global.ParserLogIncludes = true; + // the log goes to the standard output only, where the conversion scripts read the included files from, so it is + // written from the start. without the log service nothing logged here would come out at all + OpenLogFiles(); + std::jthread logservice(LogService); + GfxRenderer = gfx_renderer_factory::get_instance()->create("null"); TModel3d model; model.LoadFromTextFile(in, dynamic); model.Init(); - model.SaveToBinFile(out); -} \ No newline at end of file + auto result{0}; + if (model.GetSMRoot() == nullptr) + { + ErrorLog("Bad model: failed to load 3d model \"" + in + "\""); + result = 1; + } + else + { + model.SaveToBinFile(out); + } + + // the process ends without destructors, so the log service writes out what's left before it goes + StopLogService(); + logservice.join(); + return result; +} diff --git a/model/Model3d.cpp b/model/Model3d.cpp index f3ddbc4a5..7f60b0bc8 100644 --- a/model/Model3d.cpp +++ b/model/Model3d.cpp @@ -1943,7 +1943,12 @@ void TSubModel::serialize(std::ostream &s, std::vector &models, std if (m_material > 0 && Global.iConvertModels & 16) flags &= ~0x30; // don't save phase information, will be guessed on binary load from material sn_utils::ls_uint32(s, flags); - sn_utils::ls_int32(s, (int32_t)get_container_pos(transforms, *fMatrix)); + // a submodel whose definition broke off before its transform (see Load()) has no matrix. -1 is what the binary + // loader reads back as no matrix + if (fMatrix != nullptr) + sn_utils::ls_int32(s, (int32_t)get_container_pos(transforms, *fMatrix)); + else + sn_utils::ls_int32(s, -1); sn_utils::ls_int32(s, m_geometry.vertex_count); sn_utils::ls_int32(s, m_geometry.vertex_offset);