summaryrefslogtreecommitdiffhomepage
path: root/MagicEx/src/convert.inl.h
diff options
context:
space:
mode:
Diffstat (limited to 'MagicEx/src/convert.inl.h')
-rw-r--r--MagicEx/src/convert.inl.h42
1 files changed, 42 insertions, 0 deletions
diff --git a/MagicEx/src/convert.inl.h b/MagicEx/src/convert.inl.h
new file mode 100644
index 0000000..4dbe771
--- /dev/null
+++ b/MagicEx/src/convert.inl.h
@@ -0,0 +1,42 @@
+/* Starshatter: The Open Source Project
+ Copyright (c) 2021-2024, Starshatter: The Open Source Project Contributors
+ Copyright (c) 2011-2012, Starshatter OpenSource Distribution Contributors
+ Copyright (c) 1997-2006, Destroyer Studios LLC.
+*/
+
+#include <memory>
+#include <string>
+
+#include <Clock.h>
+#include <DataLoader.h>
+#include <Solid.h>
+
+#include <MagicLoad.h>
+
+
+namespace starshatter
+{
+
+
+template <typename Input, typename Output>
+int
+convert(const std::string& input, const std::string& output)
+{
+ Clock::Init();
+ DataLoader::Initialize();
+ auto solid = std::make_unique<Solid>();
+ if (!ImportInto<Input>(input.c_str(), solid.get()))
+ return 1;
+ Output exporter {output.c_str()};
+ auto* model = solid->GetModel();
+ if (model == nullptr)
+ return 1;
+ if (!exporter.Save(model))
+ return 1;
+ DataLoader::Close();
+ Clock::Close();
+ return 0;
+}
+
+
+} // namespace starshatter