1 | /* |
---|
2 | ----------------------------------------------------------------------------- |
---|
3 | This source file is part of OGRE |
---|
4 | (Object-oriented Graphics Rendering Engine) |
---|
5 | For the latest info, see http://www.ogre3d.org/ |
---|
6 | |
---|
7 | Copyright (c) 2000-2006 Torus Knot Software Ltd |
---|
8 | Also see acknowledgements in Readme.html |
---|
9 | |
---|
10 | This program is free software; you can redistribute it and/or modify it under |
---|
11 | the terms of the GNU Lesser General Public License as published by the Free Software |
---|
12 | Foundation; either version 2 of the License, or (at your option) any later |
---|
13 | version. |
---|
14 | |
---|
15 | This program is distributed in the hope that it will be useful, but WITHOUT |
---|
16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
---|
17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
---|
18 | |
---|
19 | You should have received a copy of the GNU Lesser General Public License along with |
---|
20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple |
---|
21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to |
---|
22 | http://www.gnu.org/copyleft/lesser.txt. |
---|
23 | |
---|
24 | You may alternatively use this source under the terms of a specific version of |
---|
25 | the OGRE Unrestricted License provided you have obtained such a license from |
---|
26 | Torus Knot Software Ltd. |
---|
27 | ----------------------------------------------------------------------------- |
---|
28 | */ |
---|
29 | |
---|
30 | #include "OgreExport.h" |
---|
31 | |
---|
32 | #include "windows.h" |
---|
33 | #include "resource.h" |
---|
34 | |
---|
35 | #include <string> |
---|
36 | #include <fstream> |
---|
37 | #include <list> |
---|
38 | #include <queue> |
---|
39 | |
---|
40 | #include "max.h" |
---|
41 | #include "plugapi.h" |
---|
42 | #include "stdmat.h" |
---|
43 | #include "impexp.h" |
---|
44 | #include "CS/BipedApi.h" |
---|
45 | #include "CS/KeyTrack.h" |
---|
46 | #include "CS/phyexp.h" |
---|
47 | #include "iparamb2.h" |
---|
48 | #include "iskin.h" |
---|
49 | |
---|
50 | static OgreMaxExport* _exp = 0; |
---|
51 | |
---|
52 | OgreMaxExport::OgreMaxExport(HINSTANCE hInst) : |
---|
53 | m_meshExporter(m_config), |
---|
54 | m_meshXMLExporter(m_config, m_materialMap), |
---|
55 | m_materialExporter(m_config, m_materialMap), |
---|
56 | m_tabGeneral(m_config, this), |
---|
57 | m_tabMesh(m_config, this), |
---|
58 | m_tabSkeletalAnimation(m_config, this), |
---|
59 | m_tabVertexAnimation(m_config, this), |
---|
60 | m_tabMaterial(m_config, this) |
---|
61 | { |
---|
62 | |
---|
63 | m_hInstance = hInst; |
---|
64 | m_hWndDlgExport = 0; |
---|
65 | m_tabDisplay = NULL; |
---|
66 | } |
---|
67 | |
---|
68 | OgreMaxExport::~OgreMaxExport() { |
---|
69 | } |
---|
70 | |
---|
71 | int OgreMaxExport::DoExport(const TCHAR *name,ExpInterface *ei,Interface *i, BOOL suppressPrompts, DWORD options) { |
---|
72 | |
---|
73 | // this sets the export path as well |
---|
74 | m_config.setExportFilename(name); |
---|
75 | m_config.load(); // can only do this after the export fname has been set and parsed out into its parts |
---|
76 | |
---|
77 | // if material and skeleton filenames are not set, do so now |
---|
78 | if (m_config.getMaterialFilename() == "") |
---|
79 | m_config.setMaterialFilename(m_config.getExportBasename() + ".material"); |
---|
80 | |
---|
81 | if (m_config.getSkeletonFilename() == "") |
---|
82 | m_config.setSkeletonFilename(m_config.getExportBasename() + ".skeleton"); |
---|
83 | |
---|
84 | m_meshExporter.setMaxInterface(ei, i); |
---|
85 | m_meshXMLExporter.setMaxInterface(ei, i); |
---|
86 | |
---|
87 | m_tabGeneral.setExportInterface(ei, i); |
---|
88 | m_tabMesh.setExportInterface(ei, i); |
---|
89 | m_tabSkeletalAnimation.setExportInterface(ei, i); |
---|
90 | m_tabVertexAnimation.setExportInterface(ei, i); |
---|
91 | m_tabMaterial.setExportInterface(ei, i); |
---|
92 | |
---|
93 | // Max will supply a nonzero (specifically, SCENE_EXPORT_SELECTED) value for options if the user |
---|
94 | // chose "Export Selected..." instead of "Export..." from the File menu |
---|
95 | //m_meshExporter.setExportSelected(options == SCENE_EXPORT_SELECTED); |
---|
96 | //m_meshXMLExporter.setExportSelected(options == SCENE_EXPORT_SELECTED); |
---|
97 | m_config.setExportSelected(options == SCENE_EXPORT_SELECTED); |
---|
98 | |
---|
99 | int result = DialogBoxParam(m_hInstance, |
---|
100 | MAKEINTRESOURCE(IDD_BINARY_EXPORT), |
---|
101 | GetActiveWindow(), |
---|
102 | ExportPropertiesDialogProc, |
---|
103 | (LPARAM) this); |
---|
104 | |
---|
105 | switch (result) { |
---|
106 | case 0: |
---|
107 | return IMPEXP_CANCEL; |
---|
108 | break; |
---|
109 | case 1: |
---|
110 | MessageBox(GetActiveWindow(), "Export Succeeded", "Sucessful Export", MB_ICONINFORMATION); |
---|
111 | return IMPEXP_SUCCESS; |
---|
112 | break; |
---|
113 | default: |
---|
114 | return IMPEXP_FAIL; |
---|
115 | break; |
---|
116 | } |
---|
117 | } |
---|
118 | |
---|
119 | INT_PTR CALLBACK ExportPropertiesDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { |
---|
120 | |
---|
121 | switch(message) { |
---|
122 | case WM_INITDIALOG: |
---|
123 | _exp = (OgreMaxExport*) lParam; |
---|
124 | |
---|
125 | if (_exp == 0) { |
---|
126 | MessageBox(NULL, "Error: Cannot initialize exporter options dialog, aborting", "Error", MB_ICONEXCLAMATION); |
---|
127 | EndDialog(hDlg, 0); |
---|
128 | return TRUE; |
---|
129 | } |
---|
130 | |
---|
131 | _exp->m_hWndDlgExport = hDlg; |
---|
132 | |
---|
133 | return _exp->setupExportProperties(); |
---|
134 | break; |
---|
135 | case WM_COMMAND: |
---|
136 | switch(LOWORD(wParam)) { |
---|
137 | case IDOK: |
---|
138 | case IDC_EXPORT: |
---|
139 | if (_exp->export()) |
---|
140 | EndDialog(hDlg, 1); |
---|
141 | else |
---|
142 | EndDialog(hDlg, 2); |
---|
143 | return TRUE; |
---|
144 | case IDCANCEL: |
---|
145 | EndDialog(hDlg, 0); |
---|
146 | return TRUE; |
---|
147 | } |
---|
148 | break; |
---|
149 | case WM_NOTIFY: |
---|
150 | switch(wParam) { |
---|
151 | case IDC_TABCONTROL: |
---|
152 | switch(((LPNMHDR)lParam)->code) { |
---|
153 | case TCN_SELCHANGE: |
---|
154 | _exp->onTabSelectChange(((LPNMHDR)lParam)->hwndFrom, ((LPNMHDR)lParam)->idFrom); |
---|
155 | break; |
---|
156 | } |
---|
157 | break; |
---|
158 | } |
---|
159 | break; |
---|
160 | } |
---|
161 | return FALSE; |
---|
162 | |
---|
163 | } |
---|
164 | |
---|
165 | bool OgreMaxExport::export() { |
---|
166 | |
---|
167 | // do mesh export -- either/both of XML and binary |
---|
168 | if (m_config.getExportXMLMesh()) { |
---|
169 | |
---|
170 | if (m_tabDisplay != 0) |
---|
171 | m_tabDisplay->update(); |
---|
172 | |
---|
173 | OgreMax::MeshXMLExporter::OutputMap output; |
---|
174 | |
---|
175 | if (m_meshXMLExporter.buildMeshXML(output)) { |
---|
176 | m_config.save(); |
---|
177 | |
---|
178 | // write each of the files and their contents |
---|
179 | OgreMax::MeshXMLExporter::OutputMap::iterator it = output.begin(); |
---|
180 | |
---|
181 | while (it != output.end()) { |
---|
182 | std::ofstream of; |
---|
183 | of.open(it->first.c_str(), std::ios::out); |
---|
184 | of << it->second; |
---|
185 | of.close(); |
---|
186 | it++; |
---|
187 | } |
---|
188 | |
---|
189 | // export material for this (these) mesh(es) |
---|
190 | /* |
---|
191 | if (m_config.getExportMaterial()) { |
---|
192 | |
---|
193 | std::string materialScript; |
---|
194 | |
---|
195 | std::ofstream of; |
---|
196 | if (m_materialExporter.buildMaterial(materialScript)) { |
---|
197 | of.open((m_config.getExportPath() + "\\" + m_config.getMaterialFilename()).c_str(), std::ios::out); |
---|
198 | |
---|
199 | if (of.is_open()) { |
---|
200 | of << materialScript; |
---|
201 | of.close(); |
---|
202 | } |
---|
203 | } |
---|
204 | } |
---|
205 | */ |
---|
206 | } |
---|
207 | else { |
---|
208 | } |
---|
209 | } |
---|
210 | |
---|
211 | return true; |
---|
212 | } |
---|
213 | |
---|
214 | void OgreMaxExport::onTabSelectChange(HWND hWnd, INT id) { |
---|
215 | int iSel = TabCtrl_GetCurSel(hWnd); |
---|
216 | |
---|
217 | // clear any existing property page |
---|
218 | if (m_tabDisplay != NULL) { |
---|
219 | m_tabDisplay->update(); |
---|
220 | DestroyWindow(m_tabDisplay->getDialogHandle()); |
---|
221 | } |
---|
222 | |
---|
223 | // create a new property page |
---|
224 | switch(iSel) { |
---|
225 | case 0: |
---|
226 | CreateDialogParam( |
---|
227 | m_hInstance, |
---|
228 | MAKEINTRESOURCE(IDD_TAB_GENERAL), |
---|
229 | hWnd, |
---|
230 | GeneralTabDialogProc, |
---|
231 | (LPARAM)&m_tabGeneral); |
---|
232 | m_tabDisplay = &m_tabGeneral; |
---|
233 | break; |
---|
234 | case 1: |
---|
235 | CreateDialogParam( |
---|
236 | m_hInstance, |
---|
237 | MAKEINTRESOURCE(IDD_TAB_MESH), |
---|
238 | hWnd, |
---|
239 | MeshTabDialogProc, |
---|
240 | (LPARAM)&m_tabMesh); |
---|
241 | m_tabDisplay = &m_tabMesh; |
---|
242 | break; |
---|
243 | case 2: |
---|
244 | CreateDialogParam( |
---|
245 | m_hInstance, |
---|
246 | MAKEINTRESOURCE(IDD_TAB_SKELETAL_ANIMATION), |
---|
247 | hWnd, |
---|
248 | SkeletalAnimationTabDialogProc, |
---|
249 | (LPARAM)&m_tabSkeletalAnimation); |
---|
250 | m_tabDisplay = &m_tabSkeletalAnimation; |
---|
251 | break; |
---|
252 | case 3: |
---|
253 | CreateDialogParam( |
---|
254 | m_hInstance, |
---|
255 | MAKEINTRESOURCE(IDD_TAB_VERTEX_ANIMATION), |
---|
256 | hWnd, |
---|
257 | VertexAnimationTabDialogProc, |
---|
258 | (LPARAM)&m_tabVertexAnimation); |
---|
259 | m_tabDisplay = &m_tabVertexAnimation; |
---|
260 | break; |
---|
261 | case 4: |
---|
262 | CreateDialogParam( |
---|
263 | m_hInstance, |
---|
264 | MAKEINTRESOURCE(IDD_TAB_MATERIAL), |
---|
265 | hWnd, |
---|
266 | MaterialTabDialogProc, |
---|
267 | (LPARAM)&m_tabMaterial); |
---|
268 | m_tabDisplay = &m_tabMaterial; |
---|
269 | break; |
---|
270 | } |
---|
271 | } |
---|
272 | |
---|
273 | BOOL OgreMaxExport::setupExportProperties() { |
---|
274 | |
---|
275 | // add tabs to the tab control |
---|
276 | TCITEM tci; |
---|
277 | HWND tabCtrl = GetDlgItem(m_hWndDlgExport, IDC_TABCONTROL); |
---|
278 | |
---|
279 | tci.mask = TCIF_TEXT; |
---|
280 | tci.pszText = "General"; |
---|
281 | TabCtrl_InsertItem(tabCtrl, 0, &tci); |
---|
282 | tci.pszText = "Mesh"; |
---|
283 | TabCtrl_InsertItem(tabCtrl, 1, &tci); |
---|
284 | tci.pszText = "Skeletal Animation"; |
---|
285 | TabCtrl_InsertItem(tabCtrl, 2, &tci); |
---|
286 | tci.pszText = "Vertex Animation"; |
---|
287 | TabCtrl_InsertItem(tabCtrl, 3, &tci); |
---|
288 | tci.pszText = "Material"; |
---|
289 | TabCtrl_InsertItem(tabCtrl, 4, &tci); |
---|
290 | |
---|
291 | // simulate tab select |
---|
292 | onTabSelectChange(tabCtrl, IDC_TABCONTROL); |
---|
293 | |
---|
294 | std::string filename; |
---|
295 | |
---|
296 | CenterWindow(m_hWndDlgExport,GetParent(m_hWndDlgExport)); |
---|
297 | |
---|
298 | return TRUE; |
---|
299 | } |
---|
300 | |
---|
301 | int OgreMaxExport::ExtCount() { |
---|
302 | // support .xml, .mesh, .material, .skeleton |
---|
303 | return 4; |
---|
304 | } |
---|
305 | |
---|
306 | const TCHAR * OgreMaxExport::Ext(int n) { |
---|
307 | switch (n) { |
---|
308 | case 0: |
---|
309 | return _T("xml"); |
---|
310 | break; |
---|
311 | case 1: |
---|
312 | return _T("mesh"); |
---|
313 | break; |
---|
314 | case 2: |
---|
315 | return _T("skeleton"); |
---|
316 | break; |
---|
317 | case 3: |
---|
318 | return _T("material"); |
---|
319 | break; |
---|
320 | default: |
---|
321 | return 0; |
---|
322 | break; |
---|
323 | } |
---|
324 | } |
---|
325 | |
---|
326 | const TCHAR * OgreMaxExport::LongDesc() { |
---|
327 | return _T("OGRE 3D Mesh/Animation/Material Exporter"); |
---|
328 | } |
---|
329 | |
---|
330 | const TCHAR * OgreMaxExport::ShortDesc() { |
---|
331 | return _T("OGRE 3D Exporter"); |
---|
332 | } |
---|
333 | |
---|
334 | const TCHAR * OgreMaxExport::AuthorName() { |
---|
335 | return _T("Gregory 'Xavier' Junker"); |
---|
336 | } |
---|
337 | |
---|
338 | const TCHAR * OgreMaxExport::CopyrightMessage() { |
---|
339 | return _T("The OGRE 3D Team (c) 2006"); |
---|
340 | } |
---|
341 | |
---|
342 | const TCHAR * OgreMaxExport::OtherMessage1() { |
---|
343 | return 0; |
---|
344 | } |
---|
345 | |
---|
346 | const TCHAR * OgreMaxExport::OtherMessage2() { |
---|
347 | return 0; |
---|
348 | } |
---|
349 | |
---|
350 | unsigned int OgreMaxExport::Version() { |
---|
351 | return 122; |
---|
352 | } |
---|
353 | |
---|
354 | void OgreMaxExport::ShowAbout(HWND hWnd) { |
---|
355 | MessageBox(hWnd, "OGRE 3D Mesh, Material and Animation Exporter", "About", 0); |
---|
356 | } |
---|
357 | |
---|
358 | BOOL OgreMaxExport::SupportsOptions(int ext, DWORD options) { |
---|
359 | |
---|
360 | // currently, only SCENE_EXPORT_SELECTED is passed to this; we support exporting |
---|
361 | // of selected files only, so return TRUE (if they ever add anything later, we'll |
---|
362 | // either support it too, or check what they are asking and return accordingly). |
---|
363 | return TRUE; |
---|
364 | } |
---|
365 | |
---|