Panda3D
maxEggImport.cxx
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file maxEggImport.cxx
10  * @author jyelon
11  * @date 2005-07-15
12  *
13  * This is the wrapper code for the max importer plugin.
14  * It includes:
15  *
16  * - user interface dialogs and popups
17  * - plugin initialization/registration
18  *
19  * It does not include the actual code to traverse the EggData.
20  */
21 
22 // Include this before everything
23 #include "pandatoolbase.h"
24 
25 using std::min;
26 using std::max;
27 
28 // local includes
29 #include "maxEggLoader.h"
30 #include "maxImportRes.h"
31 
32 // MAX includes
33 #include <Max.h>
34 #include <istdplug.h>
35 
36 // panda includes.
37 #include "notifyCategoryProxy.h"
38 
39 #include <iostream>
40 #include <sstream>
41 
42 class MaxEggImporter : public SceneImport
43 {
44 public:
45  // GUI-related methods
46  MaxEggImporter();
47  ~MaxEggImporter();
48  int ExtCount(); // Number of extensions supported
49  const TCHAR * Ext(int n); // Extension #n (i.e. "EGG")
50  const TCHAR * LongDesc(); // Long ASCII description (i.e. "Egg Importer")
51  const TCHAR * ShortDesc(); // Short ASCII description (i.e. "Egg")
52  const TCHAR * AuthorName(); // ASCII Author name
53  const TCHAR * CopyrightMessage();// ASCII Copyright message
54  const TCHAR * OtherMessage1(); // Other message #1
55  const TCHAR * OtherMessage2(); // Other message #2
56  unsigned int Version(); // Version number * 100 (i.e. v3.01 = 301)
57  void ShowAbout(HWND hWnd); // Show DLL's "About..." box
58  int DoImport(const TCHAR *name,ImpInterface *ei,Interface *i, BOOL suppressPrompts);
59 
60 public:
61  // GUI-related fields
62  static BOOL _merge;
63  static BOOL _importmodel;
64  static BOOL _importanim;
65 };
66 
67 BOOL MaxEggImporter::_merge = TRUE;
68 BOOL MaxEggImporter::_importmodel = TRUE;
69 BOOL MaxEggImporter::_importanim = FALSE;
70 
71 MaxEggImporter::MaxEggImporter()
72 {
73 }
74 
75 MaxEggImporter::~MaxEggImporter()
76 {
77 }
78 
79 int MaxEggImporter::ExtCount()
80 {
81  // Number of different extensions handled by this importer.
82  return 1;
83 }
84 
85 const TCHAR * MaxEggImporter::Ext(int n)
86 {
87  // Fetch the extensions handled by this importer.
88  switch(n) {
89  case 0: return _T("egg");
90  default: return _T("");
91  }
92 }
93 
94 const TCHAR * MaxEggImporter::LongDesc()
95 {
96  return _T("Panda3D Egg Importer");
97 }
98 
99 const TCHAR * MaxEggImporter::ShortDesc()
100 {
101  return _T("Panda3D Egg");
102 }
103 
104 const TCHAR * MaxEggImporter::AuthorName()
105 {
106  return _T("Joshua Yelon");
107 }
108 
109 const TCHAR * MaxEggImporter::CopyrightMessage()
110 {
111  return _T("Copyight (c) 2005 Josh Yelon");
112 }
113 
114 const TCHAR * MaxEggImporter::OtherMessage1()
115 {
116  return _T("");
117 }
118 
119 const TCHAR * MaxEggImporter::OtherMessage2()
120 {
121  return _T("");
122 }
123 
124 unsigned int MaxEggImporter::Version()
125 {
126  return 100;
127 }
128 
129 static INT_PTR CALLBACK AboutBoxDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
130 {
131  switch (msg) {
132  case WM_INITDIALOG:
133  CenterWindow(hWnd, GetParent(hWnd));
134  break;
135  case WM_COMMAND:
136  switch (LOWORD(wParam)) {
137  case IDOK:
138  EndDialog(hWnd, 1);
139  break;
140  }
141  break;
142  default:
143  return FALSE;
144  }
145  return TRUE;
146 }
147 
148 void MaxEggImporter::ShowAbout(HWND hWnd)
149 {
150  DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_ABOUTBOX),
151  hWnd, AboutBoxDlgProc, 0);
152 }
153 
154 
155 static INT_PTR CALLBACK ImportDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
156 {
157  MaxEggImporter *imp = (MaxEggImporter*) GetWindowLongPtr(hWnd, GWLP_USERDATA);
158  switch (msg) {
159  case WM_INITDIALOG:
160  imp = (MaxEggImporter*)lParam;
161  SetWindowLongPtr(hWnd, GWLP_USERDATA, lParam);
162  CenterWindow(hWnd, GetParent(hWnd));
163  CheckDlgButton(hWnd, IDC_MERGE, imp->_merge);
164  CheckDlgButton(hWnd, IDC_IMPORTMODEL, imp->_importmodel);
165  CheckDlgButton(hWnd, IDC_IMPORTANIM, imp->_importanim);
166  break;
167  case WM_COMMAND:
168  switch (LOWORD(wParam)) {
169  case IDOK:
170  imp->_merge = IsDlgButtonChecked(hWnd, IDC_MERGE);
171  imp->_importmodel = IsDlgButtonChecked(hWnd, IDC_IMPORTMODEL);
172  imp->_importanim = IsDlgButtonChecked(hWnd, IDC_IMPORTANIM);
173  EndDialog(hWnd, 1);
174  break;
175  case IDCANCEL:
176  EndDialog(hWnd, 0);
177  break;
178  }
179  break;
180  default:
181  return FALSE;
182  }
183  return TRUE;
184 }
185 
186 int MaxEggImporter::
187 DoImport(const TCHAR *name, ImpInterface *ii, Interface *i, BOOL suppressPrompts) {
188  // Prompt the user with our dialogbox.
189  if (!DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_IMPORT_DLG),
190  i->GetMAXHWnd(), ImportDlgProc, (LPARAM)this)) {
191  return 1;
192  }
193 
194  std::ostringstream log;
195  Notify::ptr()->set_ostream_ptr(&log, false);
196 
197 #ifdef _UNICODE
198  char sname[2048];
199  sname[2047] = 0;
200  wcstombs(sname, name, 2047);
201  bool ok = MaxLoadEggFile(sname, _merge ? true:false, _importmodel ? true:false, _importanim ? true:false);
202 #else
203  bool ok = MaxLoadEggFile(name, _merge ? true:false, _importmodel ? true:false, _importanim ? true:false);
204 #endif
205 
206  std::string txt = log.str();
207  if (txt != "") {
208  MessageBoxA(nullptr, txt.c_str(), "Panda3D Importer", MB_OK);
209  } else if (!ok) {
210  MessageBoxA(nullptr, "Import Failed, unknown reason\n", "Panda3D Importer", MB_OK);
211  }
212 
213  Notify::ptr()->set_ostream_ptr(nullptr, false);
214  return 1;
215 }
216 
217 // Plugin Initialization The following code enables Max to load this DLL, get
218 // a list of the classes defined in this DLL, and provides a means for Max to
219 // create instances of those classes.
220 
221 HINSTANCE hInstance;
222 
223 BOOL WINAPI DllMain(HINSTANCE hinstDLL,ULONG fdwReason,LPVOID lpvReserved) {
224  static int controlsInit = FALSE;
225  hInstance = hinstDLL;
226 
227  if (!controlsInit) {
228  controlsInit = TRUE;
229  // It appears that InitCustomControls is deprecated in 2012. I'm not sure
230  // if we can just remove it like this, but I've heard that it seems to
231  // work, so let's do it like this.
232 #if MAX_VERSION_MAJOR < 14
233  InitCustomControls(hInstance);
234 #endif
235  InitCommonControls();
236  }
237 
238  return (TRUE);
239 }
240 
241 #define PANDAEGGIMP_CLASS_ID1 0x377193ab
242 #define PANDAEGGIMP_CLASS_ID2 0x897afe12
243 
244 class MaxEggImporterClassDesc: public ClassDesc {
245 public:
246  int IsPublic() {return 1;}
247  void *Create(BOOL loading = FALSE) {return new MaxEggImporter;}
248  const TCHAR *ClassName() {return _T("MaxEggImporter");}
249  SClass_ID SuperClassID() {return SCENE_IMPORT_CLASS_ID;}
250  Class_ID ClassID() {return Class_ID(PANDAEGGIMP_CLASS_ID1,PANDAEGGIMP_CLASS_ID2);}
251  const TCHAR *Category() {return _T("Chrutilities");}
252 };
253 
254 static MaxEggImporterClassDesc MaxEggImporterDesc;
255 
256 __declspec( dllexport ) const TCHAR* LibDescription()
257 {
258  return _T("Panda3D Egg Importer");
259 }
260 
261 __declspec( dllexport ) int LibNumberClasses()
262 {
263  return 1;
264 }
265 
266 __declspec( dllexport ) ClassDesc* LibClassDesc(int i)
267 {
268  switch(i) {
269  case 0: return &MaxEggImporterDesc;
270  default: return 0;
271  }
272 }
273 
274 __declspec( dllexport ) ULONG LibVersion()
275 {
276  return VERSION_3DSMAX;
277 }
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
static Notify * ptr()
Returns the pointer to the global Notify object.
Definition: notify.cxx:289
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void set_ostream_ptr(std::ostream *ostream_ptr, bool delete_later)
Changes the ostream that all subsequent Notify messages will be written to.
Definition: notify.cxx:71