-
Notifications
You must be signed in to change notification settings - Fork 47
/
PicoModelModule.h
121 lines (97 loc) · 2.49 KB
/
PicoModelModule.h
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#pragma once
#include "imodule.h"
#include "imodel.h"
#include "itextstream.h"
#include "ifilesystem.h"
#include <stdio.h>
#include "picomodel.h"
#include <boost/algorithm/string/case_conv.hpp>
#include "PicoModelLoader.h"
#include "AseExporter.h"
#include "Lwo2Exporter.h"
#include "WavefrontExporter.h"
typedef unsigned char byte;
void PicoPrintFunc(int level, const char *str)
{
if (str == 0)
return;
switch (level)
{
case PICO_NORMAL:
rMessage() << str << std::endl;
break;
case PICO_VERBOSE:
//rMessage() << "PICO_VERBOSE: " << str << std::endl;
break;
case PICO_WARNING:
rError() << "PICO_WARNING: " << str << std::endl;
break;
case PICO_ERROR:
rError() << "PICO_ERROR: " << str << std::endl;
break;
case PICO_FATAL:
rError() << "PICO_FATAL: " << str << std::endl;
break;
}
}
void PicoLoadFileFunc(char *name, byte **buffer, int *bufSize)
{
*bufSize = static_cast<int>(GlobalFileSystem().loadFile(name, (void**)buffer));
}
void PicoFreeFileFunc(void* file)
{
GlobalFileSystem().freeFile(file);
}
namespace model
{
class PicoModelModule :
public RegisterableModule
{
public:
// RegisterableModule implementation
const std::string& getName() const
{
static std::string _name("PicoModelModule");
return _name;
}
const StringSet& getDependencies() const
{
static StringSet _dependencies;
if (_dependencies.empty())
{
_dependencies.insert(MODULE_MODELFORMATMANAGER);
}
return _dependencies;
}
void initialiseModule(const ApplicationContext& ctx)
{
PicoInit();
PicoSetMallocFunc(malloc);
PicoSetFreeFunc(free);
PicoSetPrintFunc(PicoPrintFunc);
PicoSetLoadFileFunc(PicoLoadFileFunc);
PicoSetFreeFileFunc(PicoFreeFileFunc);
// Register all importers available through picomodel
const picoModule_t** modules = PicoModuleList(0);
while (*modules != nullptr)
{
const picoModule_t* module = *modules++;
if (module->canload && module->load)
{
for (char* const* ext = module->defaultExts; *ext != 0; ++ext)
{
// greebo: File extension is expected to be UPPERCASE
std::string extension(*ext);
boost::algorithm::to_upper(extension);
GlobalModelFormatManager().registerImporter(
std::make_shared<PicoModelLoader>(module, extension)
);
}
}
}
GlobalModelFormatManager().registerExporter(std::make_shared<AseExporter>());
GlobalModelFormatManager().registerExporter(std::make_shared<Lwo2Exporter>());
GlobalModelFormatManager().registerExporter(std::make_shared<WavefrontExporter>());
}
};
}