- std::string objFile = path.substr(0, path.length() -4) + ".obj";
- std::string mtlFile = path.substr(0, path.length() -4) + ".mtl";
-
- std::set<std::string> materials;
-
- TextFileOutputStream out(objFile.c_str());
-
- if(out.failed())
- {
- globalErrorStream() << "Unable to open file\n";
- return false;
- }
-
- out << "# Wavefront Objectfile exported with radiants brushexport plugin 3.0 by Thomas 'namespace' Nitschke, spam@codecreator.net\n\n";
-
- if(expmat)
- {
- size_t last = mtlFile.find_last_of("//");
- std::string mtllib = mtlFile.substr(last + 1, mtlFile.size() - last).c_str();
- out << "mtllib " << mtllib.c_str() << "\n";
- }
-
- unsigned int vertex_count = 0;
-
- const std::list<ExportData::group>::const_iterator gend(groups.end());
- for(std::list<ExportData::group>::const_iterator git(groups.begin()); git != gend; ++git)
- {
- typedef std::multimap<std::string, std::string> bm;
- bm brushMaterials;
- typedef std::pair<std::string, std::string> String_Pair;
-
- const std::list<const Face*>::const_iterator end(git->faces.end());
-
- // submesh starts here
- if(objs)
- {
- out << "\no ";
- } else {
- out << "\ng ";
- }
- out << git->name.c_str() << "\n";
-
- // material
- if(expmat && mode == COLLAPSE_ALL)
- {
- out << "usemtl material" << "\n\n";
- materials.insert("material");
- }
-
- for(std::list<const Face*>::const_iterator it(git->faces.begin()); it != end; ++it)
- {
- const Winding& w((*it)->getWinding());
-
- // vertices
- for(size_t i = 0; i < w.numpoints; ++i)
- out << "v " << FloatFormat(w[i].vertex.x(), 1, 6) << " " << FloatFormat(w[i].vertex.z(), 1, 6) << " " << FloatFormat(w[i].vertex.y(), 1, 6) << "\n";
- }
- out << "\n";
-
- for(std::list<const Face*>::const_iterator it(git->faces.begin()); it != end; ++it)
- {
- const Winding& w((*it)->getWinding());
-
- // texcoords
- for(size_t i = 0; i < w.numpoints; ++i)
- out << "vt " << FloatFormat(w[i].texcoord.x(), 1, 6) << " " << FloatFormat(w[i].texcoord.y(), 1, 6) << "\n";
- }
-
- for(std::list<const Face*>::const_iterator it(git->faces.begin()); it != end; ++it)
- {
- const Winding& w((*it)->getWinding());
-
- // faces
- StringOutputStream faceLine(256);
- faceLine << "\nf";
- for(size_t i = 0; i < w.numpoints; ++i, ++vertex_count)
- {
- faceLine << " " << vertex_count+1 << "/" << vertex_count+1;
- }
-
- if(mode != COLLAPSE_ALL)
- {
- materials.insert((*it)->getShader().getShader());
- brushMaterials.insert(String_Pair((*it)->getShader().getShader(), faceLine.c_str()));
- } else {
- out << faceLine.c_str();
- }
- }
-
- if(mode != COLLAPSE_ALL)
- {
- std::string lastMat;
- std::string mat;
- std::string faces;
-
- for(bm::iterator iter = brushMaterials.begin(); iter != brushMaterials.end(); iter++)
- {
- mat = (*iter).first.c_str();
- faces = (*iter).second.c_str();
-
- if(mat != lastMat)
- {
- if(limNames && mat.size() > MAX_MATERIAL_NAME)
- {
- out << "\nusemtl " << mat.substr(mat.size() - MAX_MATERIAL_NAME, mat.size()).c_str();
- } else {
- out << "\nusemtl " << mat.c_str();
- }
- }
-
- out << faces.c_str();
- lastMat = mat;
- }
- }
-
- out << "\n";
- }
-
- if(expmat)
- {
- TextFileOutputStream outMtl(mtlFile.c_str());
- if(outMtl.failed())
- {
- globalErrorStream() << "Unable to open material file\n";
- return false;
- }
-
- outMtl << "# Wavefront material file exported with NetRadiants brushexport plugin.\n";
- outMtl << "# Material Count: " << (const Unsigned)materials.size() << "\n\n";
- for(std::set<std::string>::const_iterator it(materials.begin()); it != materials.end(); ++it)
- {
- if(limNames && it->size() > MAX_MATERIAL_NAME)
- {
- outMtl << "newmtl " << it->substr(it->size() - MAX_MATERIAL_NAME, it->size()).c_str() << "\n";
- } else {
- outMtl << "newmtl " << it->c_str() << "\n";
- }
- }
- }
-
- return true;
+ std::string objFile = path;
+
+ if (path.compare(path.length() - 4, 4, ".obj") != 0) {
+ objFile += ".obj";
+ }
+
+ std::string mtlFile = objFile.substr(0, objFile.length() - 4) + ".mtl";
+
+ std::set<std::string> materials;
+
+ TextFileOutputStream out(objFile.c_str());
+
+ if (out.failed()) {
+ globalErrorStream() << "Unable to open file\n";
+ return false;
+ }
+
+ out
+ << "# Wavefront Objectfile exported with radiants brushexport plugin 3.0 by Thomas 'namespace' Nitschke, spam@codecreator.net\n\n";
+
+ if (expmat) {
+ size_t last = mtlFile.find_last_of("//");
+ std::string mtllib = mtlFile.substr(last + 1, mtlFile.size() - last).c_str();
+ out << "mtllib " << mtllib.c_str() << "\n";
+ }
+
+ unsigned int vertex_count = 0;
+
+ const std::list<ExportData::group>::const_iterator gend(groups.end());
+ for (std::list<ExportData::group>::const_iterator git(groups.begin()); git != gend; ++git) {
+ typedef std::multimap<std::string, std::string> bm;
+ bm brushMaterials;
+ typedef std::pair<std::string, std::string> String_Pair;
+
+ const std::list<const Face *>::const_iterator end(git->faces.end());
+
+ // submesh starts here
+ if (objs) {
+ out << "\no ";
+ } else {
+ out << "\ng ";
+ }
+ out << git->name.c_str() << "\n";
+
+ // material
+ if (expmat && mode == COLLAPSE_ALL) {
+ out << "usemtl material" << "\n\n";
+ materials.insert("material");
+ }
+
+ for (std::list<const Face *>::const_iterator it(git->faces.begin()); it != end; ++it) {
+ const Winding &w((*it)->getWinding());
+
+ // vertices
+ for (size_t i = 0; i < w.numpoints; ++i) {
+ out << "v " << FloatFormat(w[i].vertex.x(), 1, 6) << " " << FloatFormat(w[i].vertex.z(), 1, 6) << " "
+ << FloatFormat(w[i].vertex.y(), 1, 6) << "\n";
+ }
+ }
+ out << "\n";
+
+ for (std::list<const Face *>::const_iterator it(git->faces.begin()); it != end; ++it) {
+ const Winding &w((*it)->getWinding());
+
+ // texcoords
+ for (size_t i = 0; i < w.numpoints; ++i) {
+ out << "vt " << FloatFormat(w[i].texcoord.x(), 1, 6) << " " << FloatFormat(w[i].texcoord.y(), 1, 6)
+ << "\n";
+ }
+ }
+
+ for (std::list<const Face *>::const_iterator it(git->faces.begin()); it != end; ++it) {
+ const Winding &w((*it)->getWinding());
+
+ // faces
+ StringOutputStream faceLine(256);
+ faceLine << "\nf";
+ for (size_t i = 0; i < w.numpoints; ++i, ++vertex_count) {
+ faceLine << " " << vertex_count + 1 << "/" << vertex_count + 1;
+ }
+
+ if (mode != COLLAPSE_ALL) {
+ materials.insert((*it)->getShader().getShader());
+ brushMaterials.insert(String_Pair((*it)->getShader().getShader(), faceLine.c_str()));
+ } else {
+ out << faceLine.c_str();
+ }
+ }
+
+ if (mode != COLLAPSE_ALL) {
+ std::string lastMat;
+ std::string mat;
+ std::string faces;
+
+ for (bm::iterator iter = brushMaterials.begin(); iter != brushMaterials.end(); iter++) {
+ mat = (*iter).first.c_str();
+ faces = (*iter).second.c_str();
+
+ if (mat != lastMat) {
+ if (limNames && mat.size() > MAX_MATERIAL_NAME) {
+ out << "\nusemtl " << mat.substr(mat.size() - MAX_MATERIAL_NAME, mat.size()).c_str();
+ } else {
+ out << "\nusemtl " << mat.c_str();
+ }
+ }
+
+ out << faces.c_str();
+ lastMat = mat;
+ }
+ }
+
+ out << "\n";
+ }
+
+ if (expmat) {
+ TextFileOutputStream outMtl(mtlFile.c_str());
+ if (outMtl.failed()) {
+ globalErrorStream() << "Unable to open material file\n";
+ return false;
+ }
+
+ outMtl << "# Wavefront material file exported with NetRadiants brushexport plugin.\n";
+ outMtl << "# Material Count: " << (const Unsigned) materials.size() << "\n\n";
+ for (std::set<std::string>::const_iterator it(materials.begin()); it != materials.end(); ++it) {
+ if (limNames && it->size() > MAX_MATERIAL_NAME) {
+ outMtl << "newmtl " << it->substr(it->size() - MAX_MATERIAL_NAME, it->size()).c_str() << "\n";
+ } else {
+ outMtl << "newmtl " << it->c_str() << "\n";
+ }
+ }
+ }
+
+ return true;