18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-01 22:07:55 +01:00
Files
maszyna/export_e3d_standalone.cpp
T
Hirek 0426a44f71 fix(e3d): the -e3d export no longer crashes on a submodel without a matrix
A submodel whose definition breaks off before its transform (no "type:"
in its header) is still attached to the tree, without a matrix, and
TSubModel::serialize dereferenced that matrix. It is written as -1 now,
which the binary loader reads back as no matrix, so the .e3d holds the
same tree the .t3d gives.

The -e3d mode also runs the log service now. Without it nothing logged
during the conversion came out, neither the included files the
conversion scripts read from the standard output nor the error that
names the broken submodel. A model that loaded nothing ends with exit
code 1 and a message instead of a crash.
2026-11-30 15:42:51 +01:00

40 lines
1.1 KiB
C++

#include "stdafx.h"
#include <thread>
#include "model/Model3d.h"
#include "utilities/Globals.h"
#include "utilities/Logs.h"
#include "rendering/renderer.h"
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();
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;
}