Changeset 172
- Timestamp:
- 06/28/07 12:01:18 (1 year ago)
- Files:
-
- GtkRadiant/trunk/CHANGES (modified) (1 diff)
- GtkRadiant/trunk/contrib/brushexport/callbacks.cpp (modified) (3 diffs)
- GtkRadiant/trunk/contrib/brushexport/callbacks.h (modified) (1 diff)
- GtkRadiant/trunk/contrib/brushexport/export.cpp (modified) (12 diffs)
- GtkRadiant/trunk/contrib/brushexport/export.h (modified) (1 diff)
- GtkRadiant/trunk/contrib/brushexport/interface.cpp (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
GtkRadiant/trunk/CHANGES
r166 r172 1 1 This is the changelog for developers, != changelog for the end user 2 2 that we distribute with the binaries. (see changelog) 3 4 28/06/2007 5 - Added material-support to brushexport-plugin (Shaderman) 3 6 4 7 26/04/2007 GtkRadiant/trunk/contrib/brushexport/callbacks.cpp
r143 r172 23 23 GtkWidget* window = lookup_widget(GTK_WIDGET(button), "w_plugplug2"); 24 24 ASSERT_NOTNULL(window); 25 const char* path = GlobalRadiant().m_pfnFileDialog(window, false, "Save as Obj", 0, 0);26 if(! path)25 const char* cpath = GlobalRadiant().m_pfnFileDialog(window, false, "Save as Obj", 0, 0); 26 if(!cpath) 27 27 return; 28 28 29 std::string path(cpath); 30 29 31 // get ignore list from ui 30 32 std::set<std::string> ignore; … … 70 72 } 71 73 } 74 75 // export materials? 76 GtkWidget* toggle = lookup_widget(GTK_WIDGET(button), "t_exportmaterials"); 77 ASSERT_NOTNULL(toggle); 78 79 bool exportmat = FALSE; 80 81 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toggle))) 82 exportmat = TRUE; 83 84 // limit material names? 85 toggle = lookup_widget(GTK_WIDGET(button), "t_limitmatnames"); 86 ASSERT_NOTNULL(toggle); 87 88 bool limitMatNames = FALSE; 89 90 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toggle)) && exportmat) 91 limitMatNames = TRUE; 92 93 // create objects instead of groups? 94 toggle = lookup_widget(GTK_WIDGET(button), "t_objects"); 95 ASSERT_NOTNULL(toggle); 96 97 bool objects = FALSE; 98 99 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toggle)) && exportmat) 100 objects = TRUE; 72 101 73 102 // export 74 ExportSelection(ignore, mode, path);103 ExportSelection(ignore, mode, exportmat, path, limitMatNames, objects); 75 104 } 76 105 … … 102 131 } 103 132 133 void OnExportMatClicked(GtkButton* button, gpointer user_data) 134 { 135 GtkWidget* toggleLimit = lookup_widget(GTK_WIDGET(button), "t_limitmatnames"); 136 GtkWidget* toggleObject = lookup_widget(GTK_WIDGET(button), "t_objects"); 137 138 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button))) 139 { 140 gtk_widget_set_sensitive(GTK_WIDGET(toggleLimit), TRUE); 141 gtk_widget_set_sensitive(GTK_WIDGET(toggleObject), TRUE); 142 } else { 143 gtk_widget_set_sensitive(GTK_WIDGET(toggleLimit), FALSE); 144 gtk_widget_set_sensitive(GTK_WIDGET(toggleObject), FALSE); 145 } 146 } 147 104 148 }// callbacks GtkRadiant/trunk/contrib/brushexport/callbacks.h
r128 r172 8 8 void OnAddMaterial(GtkButton*, gpointer); 9 9 void OnRemoveMaterial(GtkButton*, gpointer); 10 void OnExportMatClicked(GtkButton* button, gpointer); 10 11 11 12 }// callbacks GtkRadiant/trunk/contrib/brushexport/export.cpp
r162 r172 7 7 #include "stream/textfilestream.h" 8 8 9 #include <map> 10 9 11 // this is very evil, but right now there is no better way 10 12 #include "../../radiant/brush.h" … … 18 20 { 19 21 public: 20 ExportData(const std::set<std::string>& ignorelist, collapsemode mode );22 ExportData(const std::set<std::string>& ignorelist, collapsemode mode, bool limNames, bool objs); 21 23 virtual ~ExportData(void); 22 24 … … 25 27 virtual void EndBrush(void); 26 28 27 virtual bool WriteToFile(const std::string& path ) const = 0;29 virtual bool WriteToFile(const std::string& path, collapsemode mode) const = 0; 28 30 29 31 protected: … … 49 51 }; 50 52 51 ExportData::ExportData(const std::set<std::string>& _ignorelist, collapsemode _mode )53 ExportData::ExportData(const std::set<std::string>& _ignorelist, collapsemode _mode, bool _limNames, bool _objs) 52 54 : mode(_mode), 53 55 ignorelist(_ignorelist) … … 102 104 GetShaderNameFromShaderPath(f.GetShader(), shadername); 103 105 104 // faces mit materials auf der ignoreliste ignorieren106 // ignore faces from ignore list 105 107 if(ignorelist.find(shadername) != ignorelist.end()) 106 108 return; … … 146 148 else 147 149 name = tmp.substr(last_slash + 1, tmp.length() - last_slash); 148 149 globalOutputStream() << "Last: " << last_slash << " " << "lenght: " << (const unsigned int)tmp.length() << "Name: " << name.c_str() << "\n"; 150 151 #ifdef _DEBUG 152 globalOutputStream() << "Last: " << last_slash << " " << "length: " << (const unsigned int)tmp.length() << "Name: " << name.c_str() << "\n"; 153 #endif 150 154 } 151 155 … … 155 159 class ExportDataAsWavefront : public ExportData 156 160 { 161 private: 162 bool expmat; 163 bool limNames; 164 bool objs; 165 157 166 public: 158 ExportDataAsWavefront(const std::set<std::string>& _ignorelist, collapsemode _mode) 159 : ExportData(_ignorelist, _mode) 160 { 161 } 162 163 bool WriteToFile(const std::string& path) const; 167 ExportDataAsWavefront(const std::set<std::string>& _ignorelist, collapsemode _mode, bool _expmat, bool _limNames, bool _objs) 168 : ExportData(_ignorelist, _mode, _limNames, _objs) 169 { 170 expmat = _expmat; 171 limNames = _limNames; 172 objs = _objs; 173 } 174 175 bool WriteToFile(const std::string& path, collapsemode mode) const; 164 176 }; 165 177 166 bool ExportDataAsWavefront::WriteToFile(const std::string& path) const 167 { 168 TextFileOutputStream out(path.c_str()); 178 bool ExportDataAsWavefront::WriteToFile(const std::string& path, collapsemode mode) const 179 { 180 std::string objFile = path.substr(0, path.length() -4) + ".obj"; 181 std::string mtlFile = path.substr(0, path.length() -4) + ".mtl"; 182 183 std::set<std::string> materials; 184 185 TextFileOutputStream out(objFile.c_str()); 169 186 170 187 if(out.failed()) … … 174 191 } 175 192 176 out << "# Wavefront Objectfile exported with radiants brushexport plugin 2.0 by Thomas 'namespace' Nitschke, spam@codecreator.net\n\n"; 193 out << "# Wavefront Objectfile exported with radiants brushexport plugin 3.0 by Thomas 'namespace' Nitschke, spam@codecreator.net\n\n"; 194 195 if(expmat) 196 { 197 size_t last = mtlFile.find_last_of("//"); 198 std::string mtllib = mtlFile.substr(last + 1, mtlFile.size() - last).c_str(); 199 out << "mtllib " << mtllib.c_str() << "\n"; 200 } 177 201 178 202 unsigned int vertex_count = 0; … … 181 205 for(std::list<ExportData::group>::const_iterator git(groups.begin()); git != gend; ++git) 182 206 { 207 typedef std::multimap<std::string, std::string> bm; 208 bm brushMaterials; 209 typedef std::pair<std::string, std::string> String_Pair; 210 183 211 const std::list<const Face*>::const_iterator end(git->faces.end()); 184 212 185 213 // submesh starts here 186 out << "\ng " << git->name.c_str() << "\n"; 187 214 if(objs) 215 { 216 out << "\no "; 217 } else { 218 out << "\ng "; 219 } 220 out << git->name.c_str() << "\n"; 221 222 // material 223 if(expmat && mode == COLLAPSE_ALL) 224 { 225 out << "usemtl material" << "\n\n"; 226 materials.insert("material"); 227 } 228 188 229 for(std::list<const Face*>::const_iterator it(git->faces.begin()); it != end; ++it) 189 230 { … … 192 233 // vertices 193 234 for(size_t i = 0; i < w.numpoints; ++i) 194 out << "v " << FloatFormat(w[i].vertex.x(), 1, 6) << " " << FloatFormat(w[i].vertex.y(), 1, 6) << " " << FloatFormat(w[i].vertex.z(), 1, 6) << "\n";235 out << "v " << FloatFormat(w[i].vertex.x(), 1, 6) << " " << FloatFormat(w[i].vertex.z(), 1, 6) << " " << FloatFormat(w[i].vertex.y(), 1, 6) << "\n"; 195 236 } 196 237 out << "\n"; … … 210 251 211 252 // faces 212 out << "\nf"; 253 StringOutputStream faceLine(256); 254 faceLine << "\nf"; 213 255 for(size_t i = 0; i < w.numpoints; ++i, ++vertex_count) 214 256 { 215 out<< " " << vertex_count+1 << "/" << vertex_count+1;257 faceLine << " " << vertex_count+1 << "/" << vertex_count+1; 216 258 } 217 } 259 260 if(mode != COLLAPSE_ALL) 261 { 262 materials.insert((*it)->getShader().getShader()); 263 brushMaterials.insert(String_Pair((*it)->getShader().getShader(), faceLine.c_str())); 264 } else { 265 out << faceLine.c_str(); 266 } 267 } 268 269 if(mode != COLLAPSE_ALL) 270 { 271 std::string lastMat; 272 std::string mat; 273 std::string faces; 274 275 for(bm::iterator iter = brushMaterials.begin(); iter != brushMaterials.end(); iter++) 276 { 277 mat = (*iter).first.c_str(); 278 faces = (*iter).second.c_str(); 279 280 if(mat != lastMat) 281 { 282 if(limNames && mat.size() > 20) 283 { 284 out << "\nusemtl " << mat.substr(mat.size() - 20, mat.size()).c_str(); 285 } else { 286 out << "\nusemtl " << mat.c_str(); 287 } 288 } 289 290 out << faces.c_str(); 291 lastMat = mat; 292 } 293 } 294 218 295 out << "\n"; 296 } 297 298 if(expmat) 299 { 300 TextFileOutputStream outMtl(mtlFile.c_str()); 301 if(outMtl.failed()) 302 { 303 globalErrorStream() << "Unable to open material file\n"; 304 return false; 305 } 306 307 outMtl << "# Wavefront material file exported with GtkRadiants brushexport plugin.\n"; 308 outMtl << "# Material Count: " << (const Unsigned)materials.size() << "\n\n"; 309 for(std::set<std::string>::const_iterator it(materials.begin()); it != materials.end(); ++it) 310 { 311 if(limNames && it->size() > 20) 312 { 313 outMtl << "newmtl " << it->substr(it->size() - 20, it->size()).c_str() << "\n"; 314 } else { 315 outMtl << "newmtl " << it->c_str() << "\n"; 316 } 317 } 219 318 } 220 319 … … 264 363 }; 265 364 266 bool ExportSelection(const std::set<std::string>& ignorelist, collapsemode m, const std::string& path)267 { 268 ExportDataAsWavefront exporter(ignorelist, m );365 bool ExportSelection(const std::set<std::string>& ignorelist, collapsemode m, bool exmat, const std::string& path, bool limNames, bool objs) 366 { 367 ExportDataAsWavefront exporter(ignorelist, m, exmat, limNames, objs); 269 368 270 369 ForEachSelected vis(exporter); 271 370 GlobalSelectionSystem().foreachSelected(vis); 272 371 273 return exporter.WriteToFile(path );274 } 372 return exporter.WriteToFile(path, m); 373 } GtkRadiant/trunk/contrib/brushexport/export.h
r128 r172 11 11 }; 12 12 13 bool ExportSelection(const std::set<std::string>& ignorelist, collapsemode m, const std::string& path);13 bool ExportSelection(const std::set<std::string>& ignorelist, collapsemode m, bool exmat, const std::string& path, bool limitMatNames, bool objects); 14 14 15 15 #endif GtkRadiant/trunk/contrib/brushexport/interface.cpp
r128 r172 36 36 GtkWidget *b_addmaterial; 37 37 GtkWidget *b_removematerial; 38 GtkWidget *t_exportmaterials; 39 GtkWidget *t_limitmatnames; 40 GtkWidget *t_objects; 41 GtkTooltips *tooltips; 42 43 tooltips = gtk_tooltips_new(); 38 44 39 45 w_plugplug2 = gtk_window_new (GTK_WINDOW_TOPLEVEL); 40 46 gtk_widget_set_name (w_plugplug2, "w_plugplug2"); 41 gtk_window_set_title (GTK_WINDOW (w_plugplug2), "BrushExport-Plugin 2.0 by namespace");47 gtk_window_set_title (GTK_WINDOW (w_plugplug2), "BrushExport-Plugin 3.0 by namespace"); 42 48 gtk_window_set_position (GTK_WINDOW (w_plugplug2), GTK_WIN_POS_CENTER); 43 49 gtk_window_set_destroy_with_parent (GTK_WINDOW (w_plugplug2), TRUE); … … 62 68 r_collapse = gtk_radio_button_new_with_mnemonic (NULL, "Collapse mesh"); 63 69 gtk_widget_set_name (r_collapse, "r_collapse"); 70 gtk_tooltips_set_tip (GTK_TOOLTIPS(tooltips), r_collapse, "Collapse all brushes into a single group", "Collapse all brushes into a single group"); 64 71 gtk_widget_show (r_collapse); 65 72 gtk_box_pack_start (GTK_BOX (vbox4), r_collapse, FALSE, FALSE, 0); … … 69 76 r_collapsebymaterial = gtk_radio_button_new_with_mnemonic (NULL, "Collapse by material"); 70 77 gtk_widget_set_name (r_collapsebymaterial, "r_collapsebymaterial"); 78 gtk_tooltips_set_tip (GTK_TOOLTIPS(tooltips), r_collapsebymaterial, "Collapse into groups by material", "Collapse into groups by material"); 71 79 gtk_widget_show (r_collapsebymaterial); 72 80 gtk_box_pack_start (GTK_BOX (vbox4), r_collapsebymaterial, FALSE, FALSE, 0); … … 76 84 r_nocollapse = gtk_radio_button_new_with_mnemonic (NULL, "Don't collapse"); 77 85 gtk_widget_set_name (r_nocollapse, "r_nocollapse"); 86 gtk_tooltips_set_tip (GTK_TOOLTIPS(tooltips), r_nocollapse, "Every brush is stored in its own group", "Every brush is stored in its own group"); 78 87 gtk_widget_show (r_nocollapse); 79 88 gtk_box_pack_start (GTK_BOX (vbox4), r_nocollapse, FALSE, FALSE, 0); … … 142 151 gtk_widget_show (b_removematerial); 143 152 gtk_box_pack_start (GTK_BOX (hbox1), b_removematerial, FALSE, FALSE, 0); 153 154 t_limitmatnames = gtk_check_button_new_with_mnemonic ("Use short material names (max. 20 chars)"); 155 gtk_widget_set_name (t_limitmatnames, "t_limitmatnames"); 156 gtk_widget_show (t_limitmatnames); 157 gtk_box_pack_end (GTK_BOX (vbox2), t_limitmatnames, FALSE, FALSE, 0); 158 159 t_objects = gtk_check_button_new_with_mnemonic ("Create (o)bjects instead of (g)roups"); 160 gtk_widget_set_name (t_objects, "t_objects"); 161 gtk_widget_show (t_objects); 162 gtk_box_pack_end (GTK_BOX (vbox2), t_objects, FALSE, FALSE, 0); 163 164 t_exportmaterials = gtk_check_button_new_with_mnemonic ("Create material information (.mtl file)"); 165 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(t_exportmaterials), true); 166 gtk_widget_set_name (t_exportmaterials, "t_exportmaterials"); 167 gtk_widget_show (t_exportmaterials); 168 gtk_box_pack_end (GTK_BOX (vbox2), t_exportmaterials, FALSE, FALSE, 10); 144 169 145 170 using namespace callbacks; … … 150 175 g_signal_connect ((gpointer) b_addmaterial, "clicked", G_CALLBACK (OnAddMaterial), NULL); 151 176 g_signal_connect ((gpointer) b_removematerial, "clicked", G_CALLBACK (OnRemoveMaterial), NULL); 177 g_signal_connect ((gpointer) t_exportmaterials, "clicked", G_CALLBACK (OnExportMatClicked), NULL); 152 178 153 179 /* Store pointers to all widgets, for use by lookup_widget(). */ … … 170 196 GLADE_HOOKUP_OBJECT (w_plugplug2, b_addmaterial, "b_addmaterial"); 171 197 GLADE_HOOKUP_OBJECT (w_plugplug2, b_removematerial, "b_removematerial"); 198 GLADE_HOOKUP_OBJECT (w_plugplug2, t_exportmaterials, "t_exportmaterials"); 199 GLADE_HOOKUP_OBJECT (w_plugplug2, t_limitmatnames, "t_limitmatnames"); 200 GLADE_HOOKUP_OBJECT (w_plugplug2, t_objects, "t_objects"); 172 201 173 202 return w_plugplug2;
