summaryrefslogtreecommitdiffhomepage
path: root/MagicEx/src
diff options
context:
space:
mode:
Diffstat (limited to 'MagicEx/src')
-rw-r--r--MagicEx/src/3ds2mag.cpp23
-rw-r--r--MagicEx/src/convert.h22
-rw-r--r--MagicEx/src/convert.inl.h39
-rw-r--r--MagicEx/src/mag2obj.cpp18
-rw-r--r--MagicEx/src/obj2mag.cpp18
5 files changed, 98 insertions, 22 deletions
diff --git a/MagicEx/src/3ds2mag.cpp b/MagicEx/src/3ds2mag.cpp
new file mode 100644
index 0000000..3bf9460
--- /dev/null
+++ b/MagicEx/src/3ds2mag.cpp
@@ -0,0 +1,23 @@
+/* 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 <string>
+
+#include <ModelFile3DS.h>
+#include <ModelFileMAG.h>
+
+#include "convert.h"
+
+
+int
+main(int argc, char* argv[])
+{
+ if (argc < 2)
+ return 2;
+ const std::string input {argv[1]};
+ const auto output = input + ".mag";
+ return starshatter::convert<ModelFile3DS, ModelFileMAG>(input, output);
+}
diff --git a/MagicEx/src/convert.h b/MagicEx/src/convert.h
new file mode 100644
index 0000000..9bba5b8
--- /dev/null
+++ b/MagicEx/src/convert.h
@@ -0,0 +1,22 @@
+/* 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.
+*/
+
+#pragma once
+
+#include <string>
+
+
+namespace starshatter
+{
+
+
+template <typename Input, typename Output> int convert(const std::string& input, const std::string& output);
+
+
+} // namespace starshatter
+
+
+#include "convert.inl.h"
diff --git a/MagicEx/src/convert.inl.h b/MagicEx/src/convert.inl.h
new file mode 100644
index 0000000..7bf29ee
--- /dev/null
+++ b/MagicEx/src/convert.inl.h
@@ -0,0 +1,39 @@
+/* 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 <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)
+{
+ 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();
+ return 0;
+}
+
+
+} // namespace starshatter
diff --git a/MagicEx/src/mag2obj.cpp b/MagicEx/src/mag2obj.cpp
index a8ba386..1439ac7 100644
--- a/MagicEx/src/mag2obj.cpp
+++ b/MagicEx/src/mag2obj.cpp
@@ -4,24 +4,20 @@
Copyright (c) 1997-2006, Destroyer Studios LLC.
*/
-#include <memory>
+#include <string>
-#include <Solid.h>
-
-#include <MagicLoad.h>
#include <ModelFileMAG.h>
#include <ModelFileOBJ.h>
+#include "convert.h"
+
int
main(int argc, char* argv[])
{
if (argc < 2)
- return 1;
- std::string pathname {argv[1]};
- auto solid = std::make_unique<Solid>();
- if (!ImportInto<ModelFileMAG>(pathname.c_str(), solid.get()))
- return 1;
- ModelFileOBJ exporter {(pathname + ".obj").c_str()};
- exporter.Save(solid->GetModel());
+ return 2;
+ const std::string input {argv[1]};
+ const auto output = input + ".obj";
+ return starshatter::convert<ModelFileMAG, ModelFileOBJ>(input, output);
}
diff --git a/MagicEx/src/obj2mag.cpp b/MagicEx/src/obj2mag.cpp
index c9d22e0..5b71bb5 100644
--- a/MagicEx/src/obj2mag.cpp
+++ b/MagicEx/src/obj2mag.cpp
@@ -4,24 +4,20 @@
Copyright (c) 1997-2006, Destroyer Studios LLC.
*/
-#include <memory>
+#include <string>
-#include <Solid.h>
-
-#include <MagicLoad.h>
#include <ModelFileMAG.h>
#include <ModelFileOBJ.h>
+#include "convert.h"
+
int
main(int argc, char* argv[])
{
if (argc < 2)
- return 1;
- std::string pathname {argv[1]};
- auto solid = std::make_unique<Solid>();
- if (!ImportInto<ModelFileOBJ>(pathname.c_str(), solid.get()))
- return 1;
- ModelFileMAG exporter {(pathname + ".mag").c_str()};
- exporter.Save(solid->GetModel());
+ return 2;
+ const std::string input {argv[1]};
+ const auto output = input + ".mag";
+ return starshatter::convert<ModelFileOBJ, ModelFileMAG>(input, output);
}