44 lines
1.0 KiB
C++
44 lines
1.0 KiB
C++
#pragma once
|
|
|
|
#if _DEBUG
|
|
|
|
#include "../src/Lib/mt/mt.h"
|
|
#include <sstream>
|
|
#include <string>
|
|
|
|
class Mesh;
|
|
|
|
class ObjExporter
|
|
{
|
|
public:
|
|
static void Export(mt::Mesh* mesh, const std::string& filePath);
|
|
|
|
ObjExporter(mt::Mesh* mesh);
|
|
void Export(const std::string& filePath);
|
|
void WriteFaceGroups(std::ostringstream& builder, std::ostringstream& mtlBuilder);
|
|
void WriteFaces(std::ostringstream& builder, const mt::FaceList& faces);
|
|
void WritePositions(std::ostringstream& builder);
|
|
void WriteNormals(std::ostringstream& builder);
|
|
void WriteUVs(std::ostringstream& builder);
|
|
|
|
private:
|
|
std::string replace(const std::string &input, const std::string &search, const std::string &replace)
|
|
{
|
|
auto s = input;
|
|
for (size_t pos = 0;; pos += replace.length())
|
|
{
|
|
// Locate the substring to replace
|
|
pos = s.find(search, pos);
|
|
if (pos == std::string::npos) break;
|
|
// Replace by erasing and inserting
|
|
s.erase(pos, search.length());
|
|
s.insert(pos, replace);
|
|
}
|
|
|
|
return s;
|
|
}
|
|
private:
|
|
mt::Mesh* mesh;
|
|
};
|
|
|
|
#endif |