]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - plugins/md3model/plugin.cpp
patch from mattn2 (of the UFO: Alien Invasion team) which adds support
[xonotic/netradiant.git] / plugins / md3model / plugin.cpp
1 /*
2 Copyright (C) 2001-2006, William Joseph.
3 All Rights Reserved.
4
5 This file is part of GtkRadiant.
6
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 GtkRadiant is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20 */
21
22 #include "plugin.h"
23
24 #include "iscenegraph.h"
25 #include "irender.h"
26 #include "iselection.h"
27 #include "iimage.h"
28 #include "imodel.h"
29 #include "igl.h"
30 #include "ifilesystem.h"
31 #include "iundo.h"
32 #include "ifiletypes.h"
33 #include "iscriplib.h"
34
35 #include "modulesystem/singletonmodule.h"
36 #include "typesystem.h"
37
38 #include "md3.h"
39 #include "mdl.h"
40 #include "md2.h"
41 #include "mdc.h"
42 #include "mdlimage.h"
43 #include "md5.h"
44
45
46 class MD3ModelLoader : public ModelLoader
47 {
48 public:
49   scene::Node& loadModel(ArchiveFile& file)
50   {
51     return loadMD3Model(file);
52   }
53 };
54
55 class ModelDependencies :
56   public GlobalFileSystemModuleRef,
57   public GlobalOpenGLModuleRef,
58   public GlobalUndoModuleRef,
59   public GlobalSceneGraphModuleRef,
60   public GlobalShaderCacheModuleRef,
61   public GlobalSelectionModuleRef,
62   public GlobalFiletypesModuleRef
63 {
64 };
65
66 class ModelMD3API : public TypeSystemRef
67 {
68   MD3ModelLoader m_modelmd3;
69 public:
70   typedef ModelLoader Type;
71   STRING_CONSTANT(Name, "md3");
72
73   ModelMD3API()
74   {
75     GlobalFiletypesModule::getTable().addType(Type::Name(), Name(), filetype_t("md3 models", "*.md3"));
76   }
77   ModelLoader* getTable()
78   {
79     return &m_modelmd3;
80   }
81 };
82
83 typedef SingletonModule<ModelMD3API, ModelDependencies> ModelMD3Module;
84
85 ModelMD3Module g_ModelMD3Module;
86
87
88
89 class MD2ModelLoader : public ModelLoader
90 {
91 public:
92   scene::Node& loadModel(ArchiveFile& file)
93   {
94     return loadMD2Model(file);
95   }
96 };
97
98 class ModelMD2API : public TypeSystemRef
99 {
100   MD2ModelLoader m_modelmd2;
101 public:
102   typedef ModelLoader Type;
103   STRING_CONSTANT(Name, "md2");
104
105   ModelMD2API()
106   {
107     GlobalFiletypesModule::getTable().addType(Type::Name(), Name(), filetype_t("md2 models", "*.md2"));
108   }
109   ModelLoader* getTable()
110   {
111     return &m_modelmd2;
112   }
113 };
114
115 typedef SingletonModule<ModelMD2API, ModelDependencies> ModelMD2Module;
116
117 ModelMD2Module g_ModelMD2Module;
118
119 class MDLModelLoader : public ModelLoader
120 {
121 public:
122   scene::Node& loadModel(ArchiveFile& file)
123   {
124     return loadMDLModel(file);
125   }
126 };
127
128 class ModelMDLAPI : public TypeSystemRef
129 {
130   MDLModelLoader m_modelmdl;
131 public:
132   typedef ModelLoader Type;
133   STRING_CONSTANT(Name, "mdl");
134
135   ModelMDLAPI()
136   {
137     GlobalFiletypesModule::getTable().addType(Type::Name(), Name(), filetype_t("mdl models", "*.mdl"));
138   }
139   ModelLoader* getTable()
140   {
141     return &m_modelmdl;
142   }
143 };
144
145 typedef SingletonModule<ModelMDLAPI, ModelDependencies> ModelMDLModule;
146
147 ModelMDLModule g_ModelMDLModule;
148
149 class MDCModelLoader : public ModelLoader
150 {
151 public:
152   scene::Node& loadModel(ArchiveFile& file)
153   {
154     return loadMDCModel(file);
155   }
156 };
157
158 class ModelMDCAPI : public TypeSystemRef
159 {
160   MDCModelLoader m_modelmdc;
161 public:
162   typedef ModelLoader Type;
163   STRING_CONSTANT(Name, "mdc");
164
165   ModelMDCAPI()
166   {
167     GlobalFiletypesModule::getTable().addType(Type::Name(), Name(), filetype_t("mdc models", "*.mdc"));
168   }
169   ModelLoader* getTable()
170   {
171     return &m_modelmdc;
172   }
173 };
174
175 typedef SingletonModule<ModelMDCAPI, ModelDependencies> ModelMDCModule;
176
177 ModelMDCModule g_ModelMDCModule;
178
179
180 class ImageMDLAPI
181 {
182   _QERPlugImageTable m_imagemdl;
183 public:
184   typedef _QERPlugImageTable Type;
185   STRING_CONSTANT(Name, "mdl");
186
187   ImageMDLAPI()
188   {
189     m_imagemdl.loadImage = &LoadMDLImage;
190   }
191   _QERPlugImageTable* getTable()
192   {
193     return &m_imagemdl;
194   }
195 };
196
197 typedef SingletonModule<ImageMDLAPI, GlobalFileSystemModuleRef> ImageMDLModule;
198
199 ImageMDLModule g_ImageMDLModule;
200
201
202 class MD5ModelLoader : public ModelLoader
203 {
204 public:
205   scene::Node& loadModel(ArchiveFile& file)
206   {
207     return loadMD5Model(file);
208   }
209 };
210
211 class ModelMD5Dependencies : public ModelDependencies, public GlobalScripLibModuleRef
212 {
213 };
214
215 class ModelMD5API : public TypeSystemRef
216 {
217   MD5ModelLoader m_modelmd5;
218 public:
219   typedef ModelLoader Type;
220   STRING_CONSTANT(Name, "md5mesh");
221
222   ModelMD5API()
223   {
224     GlobalFiletypesModule::getTable().addType(Type::Name(), Name(), filetype_t("md5 meshes", "*.md5mesh"));
225   }
226   ModelLoader* getTable()
227   {
228     return &m_modelmd5;
229   }
230 };
231
232 typedef SingletonModule<ModelMD5API, ModelMD5Dependencies> ModelMD5Module;
233
234 ModelMD5Module g_ModelMD5Module;
235
236
237 extern "C" void RADIANT_DLLEXPORT Radiant_RegisterModules(ModuleServer& server)
238 {
239   initialiseModule(server);
240
241   g_ModelMD3Module.selfRegister();
242   g_ModelMD2Module.selfRegister();
243   g_ModelMDLModule.selfRegister();
244   g_ModelMDCModule.selfRegister();
245   g_ImageMDLModule.selfRegister();
246   g_ModelMD5Module.selfRegister();
247 }