summaryrefslogtreecommitdiffhomepage
path: root/MagicEx/src/convert.inl.h
blob: 7bf29ee91c5e76e837d84946a36f7d1ecd9ad0e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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