OSDN Git Service

fixed by @santarh
[meshio/meshio.git] / src / mqo.h
index 1878689..f468552 100644 (file)
--- a/src/mqo.h
+++ b/src/mqo.h
 
 #include <iosfwd>
 #include <vector>
+#include <assert.h>
 #include "la.h"
 #include "color.h"
 #include "text.h"
+#include "binary.h"
 
 namespace meshio {
-namespace mqo {
-
-typedef ::meshio::la::Vector2 Vector2;
-typedef ::meshio::la::Vector3 Vector3;
-typedef ::meshio::la::Vector4 Vector4;
-typedef ::meshio::color::fRGBA RGBA;
-
-//! Scene\83`\83\83\83\93\83N
-struct Scene
-{
-       Vector3 pos;
-       Vector3 lookat;
-       float head;
-       float pitch;
-       int ortho;
-       float zoom2;
-       Vector3 ambient;
-       Scene()
-               : head(0), pitch(0), ortho(false), zoom2(2)
-               {}
-};
-inline std::ostream &operator<<(std::ostream &os, const Scene &rhs)
-{
-       os
-               << "<Scene"
-               << " pos: " << rhs.pos
-               << ", lookat: " << rhs.lookat
-               << ", head: " << rhs.head
-               << ", pitch: " << rhs.pitch
-               << ", ortho: " << rhs.ortho
-               << ", zoom2: " << rhs.zoom2
-               << ", ambient: " << rhs.ambient
-               << ">"
-               ;
-       return os;
-}
-
-//! Material\83`\83\83\83\93\83N
-struct Material
-{
-       std::string name;
-       int shader;
-       RGBA color;
-       float diffuse;
-       float ambient;
-       float emit;
-       float specular;
-       float power;
-       std::string texture;
-       std::string alphamap;
-       std::string bumpmap;
-       int vcol;
-
-       Material()
-               : shader(0), diffuse(1), ambient(0), emit(0), specular(0), power(0),
-               vcol(0)
-               {}
-
-       // for python3 unicode
-       std::wstring getName()const;
-       std::wstring getTexture()const;
-};
-inline std::ostream &operator<<(std::ostream &os, const Material &rhs)
-{
-       os
-               << "<Material "
-               << '"' << rhs.name << '"'
-               << " shader:" << rhs.shader
-               << ", color:" << rhs.color
-               << ", diffuse:" << rhs.diffuse
-               << ", ambient:" << rhs.ambient
-               << ", emit:" << rhs.emit
-               << ", specular:" << rhs.specular
-               << ", power:" << rhs.power
-               << ", texture:\"" << rhs.texture << '"'
-               << ", alphamap:\"" << rhs.alphamap << '"'
-               << ", bumpmap:\"" << rhs.bumpmap << '"'
-               << ">"
-               ;
-       return os;
-}
-
-//! face\83`\83\83\83\93\83N
-struct Face
-{
-       unsigned int index_count;
-       unsigned int indices[4];
-       unsigned int material_index;
-       Vector2 uv[4];
-       RGBA color[4];
-       Face()
-               : index_count(0), material_index(0)
-               {
-                       indices[0]=0;
-                       indices[1]=0;
-                       indices[2]=0;
-                       indices[3]=0;
-                       uv[0]=Vector2();
-                       uv[1]=Vector2();
-                       uv[2]=Vector2();
-                       uv[3]=Vector2();
-               }
-       int getIndex(int i){ return indices[i]; }
-       Vector2 getUV(int i){ return uv[i]; }
-};
-inline std::ostream &operator<<(std::ostream &os, const Face &rhs)
-{
-       switch(rhs.index_count)
-       {
-       case 2:
-               os
-                       << "<Edge "
-                       << "indices:{" << rhs.indices[0] << ',' << rhs.indices[1] << "}"
-                       << ", material_index: " << rhs.material_index
-                       << ", uv:{" << rhs.uv[0] << ',' << rhs.uv[1] << "}"
-                       << ", color:{" << rhs.color[0] << ',' << rhs.color[1] << "}"
-                       << ">"
-                       ;
-               break;
-
-       case 3:
-               os
-                       << "<Triangle "
-                       << "indices:{" << rhs.indices[0] 
-                       << ',' << rhs.indices[1] 
-                       << ',' << rhs.indices[2] << "}"
-                       << ", material_index: " << rhs.material_index
-                       << ", uv:{" << rhs.uv[0] << ',' << rhs.uv[1] << ',' << rhs.uv[2] << "}"
-                       << ", color:{" 
-                       << rhs.color[0] << ',' << rhs.color[1] << ',' <<  rhs.color[2] << "}"
-                       << ">"
-                       ;
-               break;
-
-       case 4:
-               os
-                       << "<Rectangle "
-                       << "indices:{" << rhs.indices[0] 
-                       << ',' << rhs.indices[1] 
-                       << ',' << rhs.indices[2] 
-                       << ',' << rhs.indices[3] << "}"
-                       << ", material_index: " << rhs.material_index
-                       << ", uv:{" << rhs.uv[0] << ',' << rhs.uv[1] 
-                       << ',' <<  rhs.uv[2] << ',' << rhs.uv[3] << "}"
-                       << ", color:{" << rhs.color[0] 
-                       << ',' << rhs.color[1] 
-                       << ',' <<  rhs.color[2] 
-                       << ',' <<  rhs.color[3] << "}"
-                       << ">"
-                       ;
-               break;
-       default:
-               assert(false);
-       }
-
-       return os;
-}
-
-//! Object\83`\83\83\83\93\83N
-struct Object
-{
-       std::string name;
-       int depth;
-       int folding;
-       Vector3 scale;
-       Vector3 rotation;
-       Vector3 translation;
-       int visible;
-       int locking;
-       int shading;
-       float smoothing;
-       Vector3 color;
-       int color_type;
-       int mirror;
-
-       std::vector<Vector3> vertices;
-       std::vector<Face> faces;
-
-       Object()
-               : depth(0), folding(0), visible(1), locking(0), shading(0), 
-               smoothing(60.0f), color_type(0), mirror(0)
-       {}
-
-       std::wstring getName()const;
-};
-inline std::ostream &operator<<(std::ostream &os, const Object &rhs)
-{
-       os
-               << "<Object "
-               << '"' << rhs.name << '"'
-               << " vertices:" << rhs.vertices.size()
-               << ", faces:" << rhs.faces.size()
-               << ">"
-               ;
-       return os;
-}
-
-///////////////////////////////////////////////////////////////////////////////
-// IO
-///////////////////////////////////////////////////////////////////////////////
-struct IO
-{
-       Scene scene;
-       std::vector<Material> materials;
-       std::vector<Object> objects;
-
-       bool read(binary::IReader &reader);
-       bool read(const char *path);
-#ifdef _WIN32
-       bool read(const wchar_t *path);
-#endif
-       bool write(binary::IWriter &writer);
-       bool write(const char *path);
-};
-
-} // namespace mqo
+  namespace mqo {
+
+    //! Scene\83`\83\83\83\93\83N
+    struct Scene
+    {
+      meshio::Vector3 pos;
+      meshio::Vector3 lookat;
+      float head;
+      float pitch;
+      int ortho;
+      float zoom2;
+      meshio::Vector3 ambient;
+      Scene()
+        : head(0), pitch(0), ortho(false), zoom2(2)
+      {}
+    };
+    inline std::ostream &operator<<(std::ostream &os, const Scene &rhs)
+    {
+      os
+        << "<Scene"
+        << " pos: " << rhs.pos
+        << ", lookat: " << rhs.lookat
+        << ", head: " << rhs.head
+        << ", pitch: " << rhs.pitch
+        << ", ortho: " << rhs.ortho
+        << ", zoom2: " << rhs.zoom2
+        << ", ambient: " << rhs.ambient
+        << ">"
+        ;
+      return os;
+    }
+
+    //! Material\83`\83\83\83\93\83N
+    struct Material
+    {
+      std::string name;
+      int shader;
+      meshio::fRGBA color;
+      float diffuse;
+      float ambient;
+      float emit;
+      float specular;
+      float power;
+      std::string texture;
+      std::string alphamap;
+      std::string bumpmap;
+      int vcol;
+
+      Material()
+        : shader(0), diffuse(1), ambient(0), emit(0), specular(0), power(0),
+        vcol(0)
+      {}
+    };
+    inline std::ostream &operator<<(std::ostream &os, const Material &rhs)
+    {
+      os
+        << "<Material "
+        << '"' << rhs.name << '"'
+        << " shader:" << rhs.shader
+        << ", color:" << rhs.color
+        << ", diffuse:" << rhs.diffuse
+        << ", ambient:" << rhs.ambient
+        << ", emit:" << rhs.emit
+        << ", specular:" << rhs.specular
+        << ", power:" << rhs.power
+        << ", texture:\"" << rhs.texture << '"'
+        << ", alphamap:\"" << rhs.alphamap << '"'
+        << ", bumpmap:\"" << rhs.bumpmap << '"'
+        << ">"
+        ;
+      return os;
+    }
+
+    //! face\83`\83\83\83\93\83N
+    struct Face
+    {
+      unsigned int index_count;
+      unsigned int indices[4];
+      unsigned int material_index;
+      meshio::Vector2 uv[4];
+      meshio::fRGBA color[4];
+      Face()
+        : index_count(0), material_index(0)
+      {
+        indices[0]=0;
+        indices[1]=0;
+        indices[2]=0;
+        indices[3]=0;
+        uv[0]=Vector2();
+        uv[1]=Vector2();
+        uv[2]=Vector2();
+        uv[3]=Vector2();
+      }
+    };
+    inline std::ostream &operator<<(std::ostream &os, const Face &rhs)
+    {
+      switch(rhs.index_count)
+      {
+        case 2:
+          os
+            << "<Edge "
+            << "indices:{" << rhs.indices[0] << ',' << rhs.indices[1] << "}"
+            << ", material_index: " << rhs.material_index
+            << ", uv:{" << rhs.uv[0] << ',' << rhs.uv[1] << "}"
+            << ", color:{" << rhs.color[0] << ',' << rhs.color[1] << "}"
+            << ">"
+            ;
+          break;
+
+        case 3:
+          os
+            << "<Triangle "
+            << "indices:{" << rhs.indices[0] 
+            << ',' << rhs.indices[1] 
+            << ',' << rhs.indices[2] << "}"
+            << ", material_index: " << rhs.material_index
+            << ", uv:{" << rhs.uv[0] << ',' << rhs.uv[1] << ',' << rhs.uv[2] << "}"
+            << ", color:{" 
+            << rhs.color[0] << ',' << rhs.color[1] << ',' <<  rhs.color[2] << "}"
+            << ">"
+            ;
+          break;
+
+        case 4:
+          os
+            << "<Rectangle "
+            << "indices:{" << rhs.indices[0] 
+            << ',' << rhs.indices[1] 
+            << ',' << rhs.indices[2] 
+            << ',' << rhs.indices[3] << "}"
+            << ", material_index: " << rhs.material_index
+            << ", uv:{" << rhs.uv[0] << ',' << rhs.uv[1] 
+            << ',' <<  rhs.uv[2] << ',' << rhs.uv[3] << "}"
+            << ", color:{" << rhs.color[0] 
+            << ',' << rhs.color[1] 
+            << ',' <<  rhs.color[2] 
+            << ',' <<  rhs.color[3] << "}"
+            << ">"
+            ;
+          break;
+        default:
+          assert(false);
+      }
+
+      return os;
+    }
+
+    //! Object\83`\83\83\83\93\83N
+    struct Object
+    {
+      std::string name;
+      int depth;
+      int folding;
+      meshio::Vector3 scale;
+      meshio::Vector3 rotation;
+      meshio::Vector3 translation;
+      int visible;
+      int locking;
+      int shading;
+      float smoothing;
+      meshio::Vector3 color;
+      int color_type;
+      int mirror;
+
+      std::vector<meshio::Vector3> vertices;
+      std::vector<Face> faces;
+
+      Object()
+        : depth(0), folding(0), visible(1), locking(0), shading(0), 
+        smoothing(60.0f), color_type(0), mirror(0)
+      {}
+    };
+    inline std::ostream &operator<<(std::ostream &os, const Object &rhs)
+    {
+      os
+        << "<Object "
+        << '"' << rhs.name << '"'
+        << " vertices:" << rhs.vertices.size()
+        << ", faces:" << rhs.faces.size()
+        << ">"
+        ;
+      return os;
+    }
+
+    // IO
+    struct IO
+    {
+      Scene scene;
+      std::vector<Material> materials;
+      std::vector<Object> objects;
+
+      bool read(meshio::binary::IReader &reader);
+      bool read(const char *path);
+      bool write(meshio::binary::IWriter &writer);
+      bool write(const char *path);
+    };
+
+  } // namespace mqo
 } // namespace meshio
 
 #endif // MESH_IO_MQO_H_INCLUDED