From 3cc6b923edb69907794c3dc6daa61a445b3a56c0 Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 8 Apr 2024 01:21:41 +0200 Subject: Added 3ds2mag converter Solidified the converters a bit to prevent selected segvs/page faults. --- MagicEx/src/3ds2mag.cpp | 23 +++++++++++++++++++++++ MagicEx/src/convert.h | 22 ++++++++++++++++++++++ MagicEx/src/convert.inl.h | 39 +++++++++++++++++++++++++++++++++++++++ MagicEx/src/mag2obj.cpp | 18 +++++++----------- MagicEx/src/obj2mag.cpp | 18 +++++++----------- 5 files changed, 98 insertions(+), 22 deletions(-) create mode 100644 MagicEx/src/3ds2mag.cpp create mode 100644 MagicEx/src/convert.h create mode 100644 MagicEx/src/convert.inl.h (limited to 'MagicEx/src') 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 + +#include +#include + +#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(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 + + +namespace starshatter +{ + + +template 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 +#include + +#include +#include + +#include + + +namespace starshatter +{ + + +template +int +convert(const std::string& input, const std::string& output) +{ + DataLoader::Initialize(); + auto solid = std::make_unique(); + if (!ImportInto(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 +#include -#include - -#include #include #include +#include "convert.h" + int main(int argc, char* argv[]) { if (argc < 2) - return 1; - std::string pathname {argv[1]}; - auto solid = std::make_unique(); - if (!ImportInto(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(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 +#include -#include - -#include #include #include +#include "convert.h" + int main(int argc, char* argv[]) { if (argc < 2) - return 1; - std::string pathname {argv[1]}; - auto solid = std::make_unique(); - if (!ImportInto(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(input, output); } -- cgit v1.1