X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=src%2Fmqo.cpp;h=ee304cd806e2a288932c18cfe4a4034d8108abf3;hb=8093d81853548bc573586ee41f84f26971bc8acb;hp=0389326e9645b5dbb68b2a83b580a4df7ca86f02;hpb=e4f3c8212f19802eaa3a2aa66c12304b5ecdb75b;p=meshio%2Fmeshio.git diff --git a/src/mqo.cpp b/src/mqo.cpp index 0389326..ee304cd 100644 --- a/src/mqo.cpp +++ b/src/mqo.cpp @@ -1,61 +1,31 @@ #include "mqo.h" #include #include +#include +#include #include -#include - -static std::wstring to_WideChar(UINT uCodePage, const std::string &text) -{ - int size=MultiByteToWideChar(uCodePage, 0, text.c_str(), -1, NULL, 0); - std::vector buf(size); - size=MultiByteToWideChar(uCodePage, 0, text.c_str(), -1, &buf[0], buf.size()); - return std::wstring(buf.begin(), buf.begin()+size); -} - -static std::string to_MultiByte(UINT uCodePage, const std::wstring &text) -{ - int size=WideCharToMultiByte(uCodePage, 0, text.c_str(), -1, NULL, 0, 0, NULL); - std::vector buf(size); - size=WideCharToMultiByte(uCodePage, 0, text.c_str(), -1, &buf[0], buf.size(), 0, NULL); - return std::string(buf.begin(), buf.begin()+size); -} - -static std::string cp932_to_utf8(const std::string &text) -{ - return to_MultiByte(CP_UTF8, to_WideChar(CP_OEMCP, text)); -} +#include "text.h" namespace meshio { namespace mqo { -static std::wstring trim(const std::wstring &src){ - std::wstring::const_iterator end=src.begin(); - for(; end!=src.end(); ++end){ - if(*end==L'\0'){ - break; - } - } - return std::wstring(src.begin(), end); -} - -// for python3 unicode std::wstring Material::getName()const { - return trim(to_WideChar(CP_OEMCP, name)); + return text::trim(text::to_WideChar(CP_OEMCP, name)); } std::wstring Material::getTexture()const { - return trim(to_WideChar(CP_OEMCP, texture)); + return text::trim(text::to_WideChar(CP_OEMCP, texture)); } std::wstring Object::getName()const { - return trim(to_WideChar(CP_OEMCP, name)); + return text::trim(text::to_WideChar(CP_OEMCP, name)); } //! Tokenizer @@ -116,7 +86,7 @@ public: else if(key=="Eof"){ if(materials.empty()){ // fallback - materials.push_back(Material()); + //materials.push_back(Material()); } return true; } @@ -469,11 +439,102 @@ bool IO::read(const wchar_t *path) } #endif -bool IO::write(std::ostream &os) +bool IO::write(binary::IWriter &writer) { - return false; + // header + writer.printLn("Metasequoia Document"); + writer.printLn("Format Text Ver 1.0"); + writer.printLn(""); + + // scene + writer.printLn("Scene {"); + writer.printLn("\tpos 0.0000 0.0000 1500.0000"); + writer.printLn("\tlookat 0.0000 0.0000 0.0000"); + writer.printLn("\thead -0.5236"); + writer.printLn("\tpich 0.5236"); + writer.printLn("\tortho 0"); + writer.printLn("\tzoom2 5.0000"); + writer.printLn("\tamb 0.250 0.250 0.250"); + writer.printLn("}"); + + // materials + if(materials.size()>0){ + writer.printLn("Material %d {", materials.size()); + for(size_t i=0; i