#include "qerplugin.h"\r
\r
#include <gtk/gtk.h>\r
+#include <gtk/gtktreeview.h>\r
\r
#include "debugging/debugging.h"\r
#include "string/string.h"\r
#include "ifilesystem.h"\r
#include "ifiletypes.h"\r
\r
-#include "../../radiant/brush.h"\r
+#include "support.h"\r
+\r
+#include "typesystem.h"\r
+\r
+void CreateWindow (void);\r
+void DestroyWindow(void);\r
+bool IsWindowOpen(void);\r
\r
namespace BrushExport\r
-{ \r
+{\r
GtkWindow* g_mainwnd;\r
\r
- class CExportFormatWavefront : public BrushVisitor\r
- {\r
- TextFileOutputStream& m_file;\r
-\r
- StringOutputStream vertexbuffer;\r
- StringOutputStream texcoordbuffer;\r
- StringOutputStream facebuffer;\r
- \r
- size_t vertices;\r
- size_t exported;\r
- \r
- public:\r
- \r
- CExportFormatWavefront(TextFileOutputStream& file)\r
- : m_file(file)\r
- {\r
- exported = 0;\r
- vertices = 0;\r
- }\r
- \r
- virtual ~CExportFormatWavefront(void) {}\r
- \r
- void visit(scene::Instance& instance)\r
- {\r
- BrushInstance* bptr = InstanceTypeCast<BrushInstance>::cast(instance);\r
- if(bptr)\r
- {\r
- Brush& brush(bptr->getBrush());\r
- \r
- m_file << "\ng " << brush.name() << exported << "\n";\r
- \r
- brush.forEachFace(*this);\r
- \r
- m_file << vertexbuffer.c_str() << "\n";\r
- m_file << texcoordbuffer.c_str();\r
- m_file << facebuffer.c_str() << "\n";\r
- \r
- vertexbuffer.clear();\r
- texcoordbuffer.clear();\r
- facebuffer.clear();\r
- ++exported;\r
- }\r
- }\r
- \r
- void visit(Face& face) const\r
- {\r
- // cast the stupid const away\r
- const_cast<CExportFormatWavefront*>(this)->visit(face);\r
- }\r
- \r
- void visit(Face& face)\r
- {\r
- size_t v_start = vertices;\r
- const Winding& w(face.getWinding());\r
- for(size_t i = 0; i < w.numpoints; ++i)\r
- {\r
- vertexbuffer << "v " << w[i].vertex.x() << " " << w[i].vertex.y() << " " << w[i].vertex.z() << "\n";\r
- texcoordbuffer << "vt " << w[i].texcoord.x() << " " << w[i].texcoord.y() << "\n";\r
- ++vertices;\r
- }\r
- \r
- facebuffer << "\nf";\r
- for(size_t i = v_start; i < vertices; ++i)\r
- facebuffer << " " << i+1 << "/" << i+1;\r
- }\r
- };\r
- \r
- /**\r
- Exporterclass which will pass every visit-call\r
- to a special formatexporter.\r
- */\r
- template<class TExporterFormat>\r
- class CExporter : public SelectionSystem::Visitor\r
- {\r
- public:\r
- CExporter(TextFileOutputStream& file)\r
- : m_exporter(file)\r
- {}\r
- \r
- virtual ~CExporter(void) {}\r
- \r
- void visit(scene::Instance& instance) const\r
- {\r
- m_exporter.visit(instance);\r
- }\r
- \r
- private:\r
- mutable TExporterFormat m_exporter;\r
- };\r
- \r
- template<class T>\r
- void export_selected(TextFileOutputStream& file)\r
- {\r
- CExporter<T> exporter(file);\r
- GlobalSelectionSystem().foreachSelected(exporter);\r
- }\r
-\r
const char* init(void* hApp, void* pMainWidget)\r
{\r
g_mainwnd = (GtkWindow*)pMainWidget;\r
{\r
if(string_equal(command, "About"))\r
{\r
- GlobalRadiant().m_pfnMessageBox(GTK_WIDGET(g_mainwnd), "Brushexport plugin v 1.0 by namespace (www.codecreator.net)\n"\r
+ GlobalRadiant().m_pfnMessageBox(GTK_WIDGET(g_mainwnd), "Brushexport plugin v 2.0 by namespace (www.codecreator.net)\n"\r
"Enjoy!\n\nSend feedback to spam@codecreator.net", "About me...",\r
eMB_OK,\r
eMB_ICONDEFAULT);\r
}\r
else if(string_equal(command, "Export selected as Wavefront Object"))\r
{\r
- if(const char* path = GlobalRadiant().m_pfnFileDialog(GTK_WIDGET(g_mainwnd), false, "Save as Obj", 0, 0))\r
- {\r
- TextFileOutputStream file(path); \r
- if(file.failed())\r
- {\r
- GlobalRadiant().m_pfnMessageBox(GTK_WIDGET(g_mainwnd), "Unable to write to file", "Error",\r
- eMB_OK,\r
- eMB_ICONERROR);\r
- }\r
- else\r
- {\r
- export_selected<CExportFormatWavefront>(file);\r
- }\r
- }\r
+ if(IsWindowOpen())\r
+ DestroyWindow();\r
+ CreateWindow();\r
}\r
}\r
- \r
-} // namespace\r
+}\r
\r
class BrushExportDependencies :\r
public GlobalRadiantModuleRef,\r
_QERPluginTable m_plugin;\r
public:\r
typedef _QERPluginTable Type;\r
- STRING_CONSTANT(Name, "brushexport");\r
+ STRING_CONSTANT(Name, "brushexport2");\r
\r
BrushExportModule()\r
{\r