rev |
line source |
nuclear@5
|
1 #include <stdio.h>
|
nuclear@5
|
2 #include <string.h>
|
nuclear@5
|
3 #include <errno.h>
|
nuclear@5
|
4 #include <windows.h>
|
nuclear@5
|
5 #include <shlobj.h>
|
nuclear@5
|
6 #include "max.h"
|
nuclear@5
|
7 #include "impexp.h" // SceneExport
|
nuclear@5
|
8 #include "iparamb2.h" // ClassDesc2
|
nuclear@5
|
9 #include "plugapi.h"
|
nuclear@5
|
10 #include "IGame.h"
|
nuclear@5
|
11 #include "IGameExport.h"
|
nuclear@5
|
12 #include "IConversionmanager.h"
|
nuclear@5
|
13
|
nuclear@5
|
14
|
nuclear@5
|
15 #pragma comment (lib, "core.lib")
|
nuclear@5
|
16 #pragma comment (lib, "geom.lib")
|
nuclear@5
|
17 #pragma comment (lib, "gfx.lib")
|
nuclear@5
|
18 #pragma comment (lib, "mesh.lib")
|
nuclear@5
|
19 #pragma comment (lib, "maxutil.lib")
|
nuclear@5
|
20 #pragma comment (lib, "maxscrpt.lib")
|
nuclear@5
|
21 #pragma comment (lib, "paramblk2.lib")
|
nuclear@5
|
22 #pragma comment (lib, "msxml2.lib")
|
nuclear@5
|
23 #pragma comment (lib, "igame.lib")
|
nuclear@5
|
24 #pragma comment (lib, "comctl32.lib")
|
nuclear@5
|
25
|
nuclear@5
|
26
|
nuclear@5
|
27 static FILE *logfile;
|
nuclear@5
|
28 static HINSTANCE hinst;
|
nuclear@5
|
29
|
nuclear@5
|
30 class GoatExporter : public SceneExport {
|
nuclear@5
|
31 public:
|
nuclear@5
|
32 IGameScene *igame;
|
nuclear@5
|
33
|
nuclear@5
|
34 int ExtCount();
|
nuclear@5
|
35 const TCHAR *Ext(int n);
|
nuclear@5
|
36 const TCHAR *LongDesc();
|
nuclear@5
|
37 const TCHAR *ShortDesc();
|
nuclear@5
|
38 const TCHAR *AuthorName();
|
nuclear@5
|
39 const TCHAR *CopyrightMessage();
|
nuclear@5
|
40 const TCHAR *OtherMessage1();
|
nuclear@5
|
41 const TCHAR *OtherMessage2();
|
nuclear@5
|
42 unsigned int Version();
|
nuclear@5
|
43 void ShowAbout(HWND win);
|
nuclear@5
|
44
|
nuclear@5
|
45 int DoExport(const MCHAR *name, ExpInterface *eiface, Interface *iface, BOOL silent = FALSE, DWORD opt = 0);
|
nuclear@5
|
46
|
nuclear@5
|
47 bool export_materials(FILE *fp);
|
nuclear@5
|
48 };
|
nuclear@5
|
49
|
nuclear@5
|
50
|
nuclear@5
|
51 int GoatExporter::ExtCount()
|
nuclear@5
|
52 {
|
nuclear@5
|
53 return 1;
|
nuclear@5
|
54 }
|
nuclear@5
|
55
|
nuclear@5
|
56 const TCHAR *GoatExporter::Ext(int n)
|
nuclear@5
|
57 {
|
nuclear@5
|
58 return L"txt";
|
nuclear@5
|
59 }
|
nuclear@5
|
60
|
nuclear@5
|
61 const TCHAR *GoatExporter::LongDesc()
|
nuclear@5
|
62 {
|
nuclear@5
|
63 return L"Goat3D scene file";
|
nuclear@5
|
64 }
|
nuclear@5
|
65
|
nuclear@5
|
66 const TCHAR *GoatExporter::ShortDesc()
|
nuclear@5
|
67 {
|
nuclear@5
|
68 return L"Goat3D";
|
nuclear@5
|
69 }
|
nuclear@5
|
70
|
nuclear@5
|
71 const TCHAR *GoatExporter::AuthorName()
|
nuclear@5
|
72 {
|
nuclear@5
|
73 return L"John Tsiombikas";
|
nuclear@5
|
74 }
|
nuclear@5
|
75
|
nuclear@5
|
76 const TCHAR *GoatExporter::CopyrightMessage()
|
nuclear@5
|
77 {
|
nuclear@5
|
78 return L"Copyright 2013 (C) John Tsiombikas - GNU General Public License v3, see COPYING for details.";
|
nuclear@5
|
79 }
|
nuclear@5
|
80
|
nuclear@5
|
81 const TCHAR *GoatExporter::OtherMessage1()
|
nuclear@5
|
82 {
|
nuclear@5
|
83 return L"other1";
|
nuclear@5
|
84 }
|
nuclear@5
|
85
|
nuclear@5
|
86 const TCHAR *GoatExporter::OtherMessage2()
|
nuclear@5
|
87 {
|
nuclear@5
|
88 return L"other2";
|
nuclear@5
|
89 }
|
nuclear@5
|
90
|
nuclear@5
|
91 unsigned int GoatExporter::Version()
|
nuclear@5
|
92 {
|
nuclear@5
|
93 return 10;
|
nuclear@5
|
94 }
|
nuclear@5
|
95
|
nuclear@5
|
96 void GoatExporter::ShowAbout(HWND win)
|
nuclear@5
|
97 {
|
nuclear@5
|
98 MessageBoxA(win, "Goat3D exporter plugin", "About this plugin", 0);
|
nuclear@5
|
99 }
|
nuclear@5
|
100
|
nuclear@5
|
101 int GoatExporter::DoExport(const MCHAR *name, ExpInterface *eiface, Interface *iface,
|
nuclear@5
|
102 BOOL non_interactive, DWORD opt)
|
nuclear@5
|
103 {
|
nuclear@5
|
104 char fname[512];
|
nuclear@5
|
105 wcstombs(fname, name, sizeof fname - 1);
|
nuclear@5
|
106
|
nuclear@5
|
107 FILE *fp = fopen(fname, "wb");
|
nuclear@5
|
108 if(!fp) {
|
nuclear@5
|
109 fprintf(logfile, "failed to open %s for writting: %s", fname, strerror(errno));
|
nuclear@5
|
110 return IMPEXP_FAIL;
|
nuclear@5
|
111 }
|
nuclear@5
|
112
|
nuclear@5
|
113 if(!(igame = GetIGameInterface())) {
|
nuclear@5
|
114 fprintf(logfile, "failed to get the igame interface\n");
|
nuclear@5
|
115 fclose(fp);
|
nuclear@5
|
116 return IMPEXP_FAIL;
|
nuclear@5
|
117 }
|
nuclear@5
|
118 IGameConversionManager *cm = GetConversionManager();
|
nuclear@5
|
119 cm->SetCoordSystem(IGameConversionManager::IGAME_OGL);
|
nuclear@5
|
120 igame->InitialiseIGame();
|
nuclear@5
|
121 igame->SetStaticFrame(0);
|
nuclear@5
|
122
|
nuclear@5
|
123 export_materials(fp);
|
nuclear@5
|
124
|
nuclear@5
|
125 fclose(fp);
|
nuclear@5
|
126
|
nuclear@5
|
127 return IMPEXP_SUCCESS;
|
nuclear@5
|
128 }
|
nuclear@5
|
129
|
nuclear@5
|
130 bool GoatExporter::export_materials(FILE *fp)
|
nuclear@5
|
131 {
|
nuclear@5
|
132 IGameProperty *prop;
|
nuclear@5
|
133
|
nuclear@5
|
134 int num_mtl = igame->GetRootMaterialCount();
|
nuclear@5
|
135 fprintf(fp, "number of materials: %d\n", num_mtl);
|
nuclear@5
|
136
|
nuclear@5
|
137 for(int i=0; i<num_mtl; i++) {
|
nuclear@5
|
138 IGameMaterial *mtl = igame->GetRootMaterial(i);
|
nuclear@5
|
139 if(mtl) {
|
nuclear@5
|
140 Point3 diffuse(1, 1, 1);
|
nuclear@5
|
141 Point3 specular(0, 0, 0);
|
nuclear@5
|
142 float shin = 1.0, sstr = 1.0;
|
nuclear@5
|
143 char name[512] = "unnamed";
|
nuclear@5
|
144
|
nuclear@5
|
145 const MCHAR *wname = mtl->GetMaterialName();
|
nuclear@5
|
146 if(wname) {
|
nuclear@5
|
147 wcstombs(name, wname, sizeof name - 1);
|
nuclear@5
|
148 }
|
nuclear@5
|
149
|
nuclear@5
|
150 if((prop = mtl->GetDiffuseData())) {
|
nuclear@5
|
151 prop->GetPropertyValue(diffuse);
|
nuclear@5
|
152 }
|
nuclear@5
|
153 if((prop = mtl->GetSpecularData())) {
|
nuclear@5
|
154 prop->GetPropertyValue(specular);
|
nuclear@5
|
155 }
|
nuclear@5
|
156 if((prop = mtl->GetSpecularLevelData())) {
|
nuclear@5
|
157 prop->GetPropertyValue(sstr);
|
nuclear@5
|
158 }
|
nuclear@5
|
159 if((prop = mtl->GetGlossinessData())) {
|
nuclear@5
|
160 prop->GetPropertyValue(shin);
|
nuclear@5
|
161 }
|
nuclear@5
|
162
|
nuclear@5
|
163 fprintf(fp, "Material %d (%s):\n", i, name);
|
nuclear@5
|
164 fprintf(fp, " diffuse: %f %f %f\n", diffuse[0], diffuse[1], diffuse[2]);
|
nuclear@5
|
165 fprintf(fp, " specular: %f %f %f\n", specular[0] * sstr, specular[1] * sstr, specular[2] * sstr);
|
nuclear@5
|
166 fprintf(fp, " shininess: %f\n", shin * 100.0);
|
nuclear@5
|
167
|
nuclear@5
|
168 for(int j=0; j<mtl->GetNumberOfTextureMaps(); j++) {
|
nuclear@5
|
169 IGameTextureMap *tex = mtl->GetIGameTextureMap(j);
|
nuclear@5
|
170 const MCHAR *wfname = tex->GetBitmapFileName();
|
nuclear@5
|
171 if(wfname) {
|
nuclear@5
|
172 char fname[512];
|
nuclear@5
|
173 wcstombs(fname, wfname, sizeof fname - 1);
|
nuclear@5
|
174 fprintf(fp, " texture%d: %s\n", j, fname);
|
nuclear@5
|
175 }
|
nuclear@5
|
176 }
|
nuclear@5
|
177 }
|
nuclear@5
|
178 }
|
nuclear@5
|
179
|
nuclear@5
|
180 return true;
|
nuclear@5
|
181 }
|
nuclear@5
|
182
|
nuclear@5
|
183 // ------------------------------------------
|
nuclear@5
|
184
|
nuclear@5
|
185 class GoatClassDesc : public ClassDesc2 {
|
nuclear@5
|
186 public:
|
nuclear@5
|
187 int IsPublic() { return TRUE; }
|
nuclear@5
|
188 void *Create(BOOL loading = FALSE) { return new GoatExporter; }
|
nuclear@5
|
189 const TCHAR *ClassName() { return L"GoatExporter"; }
|
nuclear@5
|
190 SClass_ID SuperClassID() { return SCENE_EXPORT_CLASS_ID; }
|
nuclear@5
|
191 Class_ID ClassID() { return Class_ID(0x77050f0d, 0x7d4c5ab5); }
|
nuclear@5
|
192 const TCHAR *Category() { return L"Mutant Stargoat"; }
|
nuclear@5
|
193
|
nuclear@5
|
194 const TCHAR *InternalName() { return L"GoatExporter"; }
|
nuclear@5
|
195 HINSTANCE HInstance() { return hinst; }
|
nuclear@5
|
196 };
|
nuclear@5
|
197
|
nuclear@5
|
198 static GoatClassDesc class_desc;
|
nuclear@5
|
199
|
nuclear@5
|
200 BOOL WINAPI DllMain(HINSTANCE inst_handle, ULONG reason, void *reserved)
|
nuclear@5
|
201 {
|
nuclear@5
|
202 if(reason == DLL_PROCESS_ATTACH) {
|
nuclear@5
|
203 hinst = inst_handle;
|
nuclear@5
|
204 DisableThreadLibraryCalls(hinst);
|
nuclear@5
|
205 }
|
nuclear@5
|
206 return TRUE;
|
nuclear@5
|
207 }
|
nuclear@5
|
208
|
nuclear@5
|
209 extern "C" {
|
nuclear@5
|
210
|
nuclear@5
|
211 __declspec(dllexport) const TCHAR *LibDescription()
|
nuclear@5
|
212 {
|
nuclear@5
|
213 return L"test exporter";
|
nuclear@5
|
214 }
|
nuclear@5
|
215
|
nuclear@5
|
216 __declspec(dllexport) int LibNumberClasses()
|
nuclear@5
|
217 {
|
nuclear@5
|
218 return 1;
|
nuclear@5
|
219 }
|
nuclear@5
|
220
|
nuclear@5
|
221 __declspec(dllexport) ClassDesc *LibClassDesc(int i)
|
nuclear@5
|
222 {
|
nuclear@5
|
223 return i == 0 ? &class_desc : 0;
|
nuclear@5
|
224 }
|
nuclear@5
|
225
|
nuclear@5
|
226 __declspec(dllexport) ULONG LibVersion()
|
nuclear@5
|
227 {
|
nuclear@5
|
228 return Get3DSMAXVersion();
|
nuclear@5
|
229 }
|
nuclear@5
|
230
|
nuclear@5
|
231 __declspec(dllexport) int LibInitialize()
|
nuclear@5
|
232 {
|
nuclear@5
|
233 static char path[1024];
|
nuclear@5
|
234
|
nuclear@5
|
235 SHGetFolderPathA(0, CSIDL_PERSONAL, 0, 0, path);
|
nuclear@5
|
236 strcat(path, "/testexp.log");
|
nuclear@5
|
237
|
nuclear@5
|
238 if((logfile = fopen(path, "w"))) {
|
nuclear@5
|
239 setvbuf(logfile, 0, _IONBF, 0);
|
nuclear@5
|
240 }
|
nuclear@5
|
241 return TRUE;
|
nuclear@5
|
242 }
|
nuclear@5
|
243
|
nuclear@5
|
244 __declspec(dllexport) int LibShutdown()
|
nuclear@5
|
245 {
|
nuclear@5
|
246 if(logfile) {
|
nuclear@5
|
247 fclose(logfile);
|
nuclear@5
|
248 logfile = 0;
|
nuclear@5
|
249 }
|
nuclear@5
|
250 return TRUE;
|
nuclear@5
|
251 }
|
nuclear@5
|
252
|
nuclear@5
|
253 } // extern "C" |