-/*\r
-Copyright (C) 2006, Thomas Nitschke.\r
-All Rights Reserved.\r
-\r
-This file is part of GtkRadiant.\r
-\r
-GtkRadiant is free software; you can redistribute it and/or modify\r
-it under the terms of the GNU General Public License as published by\r
-the Free Software Foundation; either version 2 of the License, or\r
-(at your option) any later version.\r
-\r
-GtkRadiant is distributed in the hope that it will be useful,\r
-but WITHOUT ANY WARRANTY; without even the implied warranty of\r
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
-GNU General Public License for more details.\r
-\r
-You should have received a copy of the GNU General Public License\r
-along with GtkRadiant; if not, write to the Free Software\r
-Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA\r
-*/\r
-#include "plugin.h"\r
-\r
-#include "iplugin.h"\r
-#include "qerplugin.h"\r
-\r
-#include <gtk/gtk.h>\r
-\r
-#include "debugging/debugging.h"\r
-#include "string/string.h"\r
-#include "modulesystem/singletonmodule.h"\r
-#include "stream/textfilestream.h"\r
-#include "stream/stringstream.h"\r
-#include "gtkutil/messagebox.h"\r
-#include "gtkutil/filechooser.h"\r
-\r
-#include "ibrush.h"\r
-#include "iscenegraph.h"\r
-#include "iselection.h"\r
-#include "ifilesystem.h"\r
-#include "ifiletypes.h"\r
-\r
-#include "../../radiant/brush.h"\r
-\r
-namespace BrushExport\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
- ASSERT_NOTNULL(g_mainwnd);\r
- return "";\r
- }\r
- const char* getName()\r
- {\r
- return "Brush export Plugin";\r
- }\r
- const char* getCommandList()\r
- {\r
- return "Export selected as Wavefront Object;About";\r
- }\r
- const char* getCommandTitleList()\r
- {\r
- return "";\r
- }\r
- \r
- void dispatch(const char* command, float* vMin, float* vMax, bool bSingleBrush)\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
- "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
- }\r
- }\r
- \r
-} // namespace\r
-\r
-class BrushExportDependencies :\r
- public GlobalRadiantModuleRef,\r
- public GlobalFiletypesModuleRef,\r
- public GlobalBrushModuleRef,\r
- public GlobalFileSystemModuleRef,\r
- public GlobalSceneGraphModuleRef,\r
- public GlobalSelectionModuleRef\r
-{\r
-public:\r
- BrushExportDependencies(void)\r
- : GlobalBrushModuleRef(GlobalRadiant().getRequiredGameDescriptionKeyValue("brushtypes"))\r
- {}\r
-};\r
-\r
-class BrushExportModule : public TypeSystemRef\r
-{\r
- _QERPluginTable m_plugin;\r
-public:\r
- typedef _QERPluginTable Type;\r
- STRING_CONSTANT(Name, "brushexport");\r
-\r
- BrushExportModule()\r
- {\r
- m_plugin.m_pfnQERPlug_Init = &BrushExport::init;\r
- m_plugin.m_pfnQERPlug_GetName = &BrushExport::getName;\r
- m_plugin.m_pfnQERPlug_GetCommandList = &BrushExport::getCommandList;\r
- m_plugin.m_pfnQERPlug_GetCommandTitleList = &BrushExport::getCommandTitleList;\r
- m_plugin.m_pfnQERPlug_Dispatch = &BrushExport::dispatch;\r
- }\r
- _QERPluginTable* getTable()\r
- {\r
- return &m_plugin;\r
- }\r
-};\r
-\r
-typedef SingletonModule<BrushExportModule, BrushExportDependencies> SingletonBrushExportModule;\r
-SingletonBrushExportModule g_BrushExportModule;\r
-\r
-extern "C" void RADIANT_DLLEXPORT Radiant_RegisterModules(ModuleServer& server)\r
-{\r
- initialiseModule(server);\r
- g_BrushExportModule.selfRegister();\r
-}\r
+/*
+ Copyright (C) 2006, Thomas Nitschke.
+ All Rights Reserved.
+
+ This file is part of GtkRadiant.
+
+ GtkRadiant is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ GtkRadiant is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GtkRadiant; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+#include "plugin.h"
+
+#include "iplugin.h"
+#include "qerplugin.h"
+
+#include <gtk/gtk.h>
+
+#include "debugging/debugging.h"
+#include "string/string.h"
+#include "modulesystem/singletonmodule.h"
+#include "stream/textfilestream.h"
+#include "stream/stringstream.h"
+#include "gtkutil/messagebox.h"
+#include "gtkutil/filechooser.h"
+
+#include "ibrush.h"
+#include "iscenegraph.h"
+#include "iselection.h"
+#include "ifilesystem.h"
+#include "ifiletypes.h"
+
+#include "support.h"
+
+#include "typesystem.h"
+
+#define CMD_ABOUT "About..."
+
+void CreateWindow( ui::Window main_window );
+void DestroyWindow( void );
+bool IsWindowOpen( void );
+
+ui::Widget g_pRadiantWnd{ui::null};
+
+namespace BrushExport
+{
+ui::Window g_mainwnd{ui::null};
+
+const char* init( void* hApp, void* pMainWidget ){
+ g_mainwnd = ui::Window::from(pMainWidget);
+ g_pRadiantWnd = ui::Window::from(pMainWidget);
+ ASSERT_TRUE( g_mainwnd );
+ return "";
+}
+const char* getName(){
+ return "Brush export Plugin";
+}
+const char* getCommandList(){
+ return CMD_ABOUT ";-;Export selected as Wavefront Object";
+}
+const char* getCommandTitleList(){
+ return "";
+}
+
+void dispatch( const char* command, float* vMin, float* vMax, bool bSingleBrush ){
+ if ( string_equal( command, CMD_ABOUT ) ) {
+ const char *label_text =
+ PLUGIN_NAME " " PLUGIN_VERSION " for "
+ RADIANT_NAME " " RADIANT_VERSION "\n\n"
+ "Written by namespace <spam@codecreator.net>\n\n"
+// 20200404 dead link
+// "http://www.codecreator.net"
+ "Built against "
+ RADIANT_NAME " " RADIANT_VERSION_STRING "\n"
+ __DATE__;
+
+ GlobalRadiant().m_pfnMessageBox( g_mainwnd, label_text,
+ "About " PLUGIN_NAME,
+ eMB_OK,
+ eMB_ICONDEFAULT );
+ }
+ else if ( string_equal( command, "Export selected as Wavefront Object" ) ) {
+ if ( IsWindowOpen() ) {
+ DestroyWindow();
+ }
+ CreateWindow( g_mainwnd );
+ }
+}
+}
+
+class BrushExportDependencies :
+ public GlobalRadiantModuleRef,
+ public GlobalFiletypesModuleRef,
+ public GlobalBrushModuleRef,
+ public GlobalFileSystemModuleRef,
+ public GlobalSceneGraphModuleRef,
+ public GlobalSelectionModuleRef
+{
+public:
+BrushExportDependencies( void )
+ : GlobalBrushModuleRef( GlobalRadiant().getRequiredGameDescriptionKeyValue( "brushtypes" ) )
+{}
+};
+
+class BrushExportModule : public TypeSystemRef
+{
+_QERPluginTable m_plugin;
+public:
+typedef _QERPluginTable Type;
+STRING_CONSTANT( Name, PLUGIN_NAME );
+
+BrushExportModule(){
+ m_plugin.m_pfnQERPlug_Init = &BrushExport::init;
+ m_plugin.m_pfnQERPlug_GetName = &BrushExport::getName;
+ m_plugin.m_pfnQERPlug_GetCommandList = &BrushExport::getCommandList;
+ m_plugin.m_pfnQERPlug_GetCommandTitleList = &BrushExport::getCommandTitleList;
+ m_plugin.m_pfnQERPlug_Dispatch = &BrushExport::dispatch;
+}
+_QERPluginTable* getTable(){
+ return &m_plugin;
+}
+};
+
+typedef SingletonModule<BrushExportModule, BrushExportDependencies> SingletonBrushExportModule;
+SingletonBrushExportModule g_BrushExportModule;
+
+extern "C" void RADIANT_DLLEXPORT Radiant_RegisterModules( ModuleServer& server ){
+ initialiseModule( server );
+ g_BrushExportModule.selfRegister();
+}