OSDN Git Service

fix for vc2008
authorousttrue <ousttrue@gmail.com>
Tue, 3 May 2011 16:36:07 +0000 (01:36 +0900)
committerousttrue <ousttrue@gmail.com>
Tue, 3 May 2011 16:36:07 +0000 (01:36 +0900)
src/mqo.h
src/pmd.cpp
src/pmd.h
src/text.h
swig/pmd.i
swig/python/setup.py

index 6324b1b..f468552 100644 (file)
--- a/src/mqo.h
+++ b/src/mqo.h
@@ -47,13 +47,13 @@ namespace meshio {
     //! Scene\83`\83\83\83\93\83N
     struct Scene
     {
-      Vector3 pos;
-      Vector3 lookat;
+      meshio::Vector3 pos;
+      meshio::Vector3 lookat;
       float head;
       float pitch;
       int ortho;
       float zoom2;
-      Vector3 ambient;
+      meshio::Vector3 ambient;
       Scene()
         : head(0), pitch(0), ortho(false), zoom2(2)
       {}
@@ -79,7 +79,7 @@ namespace meshio {
     {
       std::string name;
       int shader;
-      fRGBA color;
+      meshio::fRGBA color;
       float diffuse;
       float ambient;
       float emit;
@@ -121,8 +121,8 @@ namespace meshio {
       unsigned int index_count;
       unsigned int indices[4];
       unsigned int material_index;
-      Vector2 uv[4];
-      fRGBA color[4];
+      meshio::Vector2 uv[4];
+      meshio::fRGBA color[4];
       Face()
         : index_count(0), material_index(0)
       {
@@ -195,18 +195,18 @@ namespace meshio {
       std::string name;
       int depth;
       int folding;
-      Vector3 scale;
-      Vector3 rotation;
-      Vector3 translation;
+      meshio::Vector3 scale;
+      meshio::Vector3 rotation;
+      meshio::Vector3 translation;
       int visible;
       int locking;
       int shading;
       float smoothing;
-      Vector3 color;
+      meshio::Vector3 color;
       int color_type;
       int mirror;
 
-      std::vector<Vector3> vertices;
+      std::vector<meshio::Vector3> vertices;
       std::vector<Face> faces;
 
       Object()
@@ -233,9 +233,9 @@ namespace meshio {
       std::vector<Material> materials;
       std::vector<Object> objects;
 
-      bool read(binary::IReader &reader);
+      bool read(meshio::binary::IReader &reader);
       bool read(const char *path);
-      bool write(binary::IWriter &writer);
+      bool write(meshio::binary::IWriter &writer);
       bool write(const char *path);
     };
 
index cc0459f..e04b0d6 100644 (file)
@@ -408,12 +408,11 @@ namespace meshio {
     IO::IO()
       : version(0)
     {
-        int i=1;
-        for(auto it=toon_textures.begin(); it!=toon_textures.end(); ++it){
-            char toon[100];
-            sprintf(toon, "toon%02d.bmp", i);
-            *it=toon;
-        }
+      for(int i=0; i<10; ++i){
+        char toon[100];
+        sprintf(toon, "toon%02d.bmp", i+1);
+        toon_textures[i]=toon;
+      }
     }
 
     bool IO::read(binary::IReader &input)
index 3a41a19..af9bb27 100644 (file)
--- a/src/pmd.h
+++ b/src/pmd.h
 #include "binary.h"
 #include <ostream>
 #include <vector>
+#ifdef _MSC_VER
+#include <boost/array.hpp>
+namespace std {
+  using boost::array;
+}
+#else
 #include <array>
+#endif
 
 namespace meshio {
   namespace pmd {
@@ -48,11 +55,11 @@ namespace meshio {
     struct Vertex
     {
       //! \8dÀ\95W
-      Vector3 pos;
+      meshio::Vector3 pos;
       //! \96@\90ü\83x\83N\83g\83\8b
-      Vector3 normal;
+      meshio::Vector3 normal;
       //! \83e\83N\83X\83`\83\83UV
-      Vector2 uv;
+      meshio::Vector2 uv;
       //! \83u\83\8c\83\93\83f\83B\83\93\83O\83{\81[\83\931
       unsigned short bone0;
       //! \83u\83\8c\83\93\83f\83B\83\93\83O\83{\81[\83\932
@@ -62,6 +69,7 @@ namespace meshio {
       //! \94ñ\83G\83b\83W
       unsigned char edge_flag;
     };
+#ifndef SWIG
     inline std::ostream &operator<<(std::ostream &os, const Vertex &rhs)
     {
       os
@@ -77,6 +85,7 @@ namespace meshio {
         ;
       return os;
     }
+#endif
 
     ////////////////////////////////////////////////////////////
     //! \8dÞ\8e¿
@@ -84,13 +93,13 @@ namespace meshio {
     struct Material
     {
       //! Diffuse
-      fRGBA diffuse;
+      meshio::fRGBA diffuse;
       //! Shinness
       float shinness;
       //! Specular
-      fRGB specular;
+      meshio::fRGB specular;
       //! Ambient
-      fRGB ambient;
+      meshio::fRGB ambient;
       //! \83g\83D\81[\83\93\83e\83N\83X\83`\83\83
       unsigned char toon_index;
       //! \97Ö\8as/\89e
@@ -98,8 +107,9 @@ namespace meshio {
       //! \96Ê\92¸\93_\90\94
       unsigned int vertex_count;
       //! \83e\83N\83X\83`\83\83
-      fixed_string<20> texture;
+      meshio::fixed_string<20> texture;
     };
+#ifndef SWIG
     inline std::ostream &operator<<(std::ostream &os,
         const Material &rhs)
     {
@@ -114,6 +124,7 @@ namespace meshio {
         ;
       return os;
     }
+#endif
 
     ////////////////////////////////////////////////////////////
     //! \83{\81[\83\93 
@@ -145,7 +156,7 @@ namespace meshio {
     struct Bone
     {
       //! \96¼\91O
-      fixed_string<20> name;
+      meshio::fixed_string<20> name;
       //! \90e\83{\81[\83\93
       unsigned short parent_index;
       //! \8eq\83{\81[\83\93
@@ -155,12 +166,12 @@ namespace meshio {
       //! \89e\8b¿IK\83{\81[\83\93
       unsigned short ik_index;
       // \83{\81[\83\93\8dÀ\95W
-      Vector3 pos;
+      meshio::Vector3 pos;
       //! \89p\8cê\96¼
-      fixed_string<20> english_name;
+      meshio::fixed_string<20> english_name;
       //! \83{\81[\83\93\8aK\91w\8d\\92z\97p
       Bone* parent;
-      Vector3 tail;
+      meshio::Vector3 tail;
       std::vector<Bone*> children;
       unsigned short index;
 
@@ -168,6 +179,7 @@ namespace meshio {
         : parent_index(-1), tail_index(-1), type(BONE_UNKNOWN), ik_index(-1), parent(0), index(-1)
       {}
     };
+#ifndef SWIG
     inline std::ostream &operator<<(std::ostream &os,
         const Bone &rhs)
     {
@@ -178,6 +190,7 @@ namespace meshio {
         ;
       return os;
     }
+#endif
 
     ////////////////////////////////////////////////////////////
     //! IK
@@ -197,6 +210,7 @@ namespace meshio {
       //! \83G\83t\83F\83N\83^\82É\98A\93®\82·\82é\83{\81[\83\93(\8aî\96{\93I\82É\90e\83{\81[\83\93\82É\91k\82é)
       std::vector<unsigned short> children;
     };
+#ifndef SWIG
     inline std::ostream &operator<<(std::ostream &os, const IK &rhs)
     {
       os
@@ -205,6 +219,7 @@ namespace meshio {
         ;
       return os;
     }
+#endif
 
     ////////////////////////////////////////////////////////////
     //! \95\\8fî
@@ -226,7 +241,7 @@ namespace meshio {
     struct Morph
     {
       //! \95\\8fî\96¼
-      fixed_string<20> name;
+      meshio::fixed_string<20> name;
       //! \8eg\97p\82·\82é\92¸\93_\90\94
       unsigned int vertex_count;
       //! \95ª\97Þ
@@ -234,10 +249,11 @@ namespace meshio {
       //! \92¸\93_Index
       std::vector<unsigned int> indices;
       //! \88Ú\93®\97Ê
-      std::vector<Vector3> pos_list;
+      std::vector<meshio::Vector3> pos_list;
       //! \89p\8cê\96¼
-      fixed_string<20> english_name;
+      meshio::fixed_string<20> english_name;
     };
+#ifndef SWIG
     inline std::ostream &operator<<(std::ostream &os, const Morph &rhs)
     {
       os
@@ -247,14 +263,15 @@ namespace meshio {
         ;
       return os;
     }
+#endif
 
     ////////////////////////////////////////////////////////////
     //! \83{\81[\83\93\95\\8e¦\98g
     ////////////////////////////////////////////////////////////
     struct BoneGroup
     {
-      fixed_string<50> name;
-      fixed_string<50> english_name;
+      meshio::fixed_string<50> name;
+      meshio::fixed_string<50> english_name;
     };
 
     ////////////////////////////////////////////////////////////
@@ -284,7 +301,7 @@ namespace meshio {
     struct RigidBody
     {
       //! \8d\84\91Ì\96¼
-      fixed_string<20> name;
+      meshio::fixed_string<20> name;
       //! \8aÖ\98A\83{\81[\83\93(\83{\81[\83\93\92Ç\8f]\82Æ\83{\81[\83\93\88Ê\92u\8d\87\82í\82¹\82Å\95K\97v)
       unsigned short boneIndex;
       //! \83O\83\8b\81[\83v
@@ -298,8 +315,8 @@ namespace meshio {
       float h;
       float d;
       //! \8ep\90¨
-      Vector3 position;
-      Vector3 rotation;
+      meshio::Vector3 position;
+      meshio::Vector3 rotation;
       //! \8e¿\97Ê
       float weight;
       //! \95¨\97\9d\89\89\8eZ\83p\83\89\83\81\81[\83^(bullet)
@@ -315,24 +332,24 @@ namespace meshio {
     struct Constraint
     {
       //! Joint\96¼
-      fixed_string<20> name;
+      meshio::fixed_string<20> name;
       //! \90Ú\91±\8d\84\91ÌA
       unsigned int rigidA;
       //! \90Ú\91±\8d\84\91ÌB
       unsigned int rigidB;
       //! \88Ê\92u
-      Vector3 pos;
+      meshio::Vector3 pos;
       //! \89ñ\93]
-      Vector3 rot;
+      meshio::Vector3 rot;
       //! \88Ú\93®\90§\8cÀ
-      Vector3 constraintPosMin;
-      Vector3 constraintPosMax;
+      meshio::Vector3 constraintPosMin;
+      meshio::Vector3 constraintPosMax;
       //! \89ñ\93]\90§\8cÀ
-      Vector3 constraintRotMin;
-      Vector3 constraintRotMax;
+      meshio::Vector3 constraintRotMin;
+      meshio::Vector3 constraintRotMax;
       //! \82Î\82Ë
-      Vector3 springPos;
-      Vector3 springRot;
+      meshio::Vector3 springPos;
+      meshio::Vector3 springRot;
     };
 
 
@@ -340,8 +357,8 @@ namespace meshio {
     struct IO
     {
       float version;
-      fixed_string<20> name;
-      fixed_string<256> comment;
+      meshio::fixed_string<20> name;
+      meshio::fixed_string<256> comment;
       std::vector<Vertex> vertices;
       std::vector<unsigned short> indices;
       std::vector<Material> materials;
@@ -351,19 +368,20 @@ namespace meshio {
       std::vector<unsigned short> face_list;
       std::vector<BoneGroup> bone_group_list;
       std::vector<std::pair<unsigned short, unsigned char> > bone_display_list;
-      std::array<fixed_string<100>, 10> toon_textures;
+      std::array<meshio::fixed_string<100>, 10> toon_textures;
       std::vector<RigidBody> rigidbodies;
       std::vector<Constraint> constraints;
 
-      fixed_string<20> english_name;
-      fixed_string<256> english_comment;
+      meshio::fixed_string<20> english_name;
+      meshio::fixed_string<256> english_comment;
 
       IO();
       bool read(const char *path);
       bool write(const char *path);
-      bool read(binary::IReader &reader);
-      bool write(binary::IWriter &writer);
+      bool read(meshio::binary::IReader &reader);
+      bool write(meshio::binary::IWriter &writer);
     };
+#ifndef SWIG
     inline std::ostream &operator<<(std::ostream &os, const IO &rhs)
     {
       os
@@ -401,6 +419,7 @@ namespace meshio {
         ;
       return os;
     }
+#endif
 
 
   } // namespace pmd
index 4921d0a..7f59869 100644 (file)
@@ -95,10 +95,12 @@ namespace meshio {
         return *this;
       }
   };
+#ifndef SWIG
   inline std::ostream &operator<<(std::ostream &os, const cstr &rhs)
   {
     return os << rhs.str();
   }
+#endif
 
   template<int LENGTH>
     class fixed_string
@@ -126,15 +128,17 @@ namespace meshio {
         if(src.empty()){
           return;
         }
-        auto it=src.begin();
-        for(int i=0; i<LENGTH && *it; ++i, ++it, ++end_){
+        std::string::const_iterator it=src.begin();
+        int i;
+        for(i=0; 
+            i<LENGTH && it!=src.end(); 
+            ++i, ++it)
+        {
           begin_[i]=*it;
         }
-        if(std::distance(
-              static_cast<char*>(begin_), 
-              static_cast<char*>(end_))<LENGTH)
+        if(i<LENGTH)
         {
-          *end_='\0';
+          begin_[i]='\0';
         }
       }
       size_t size()const { return LENGTH; }
@@ -142,7 +146,7 @@ namespace meshio {
       const char *begin() const { return begin_; }
       std::string str() const
       {
-        auto end=begin_;
+        const char *end=begin_;
         for(; end!=end_ && *end!='\0'; ++end){
         }
         return std::string(
@@ -150,13 +154,15 @@ namespace meshio {
             static_cast<const char*>(end));
       }
     };
+#ifndef SWIG
   template<int LENGTH>
     inline std::ostream &operator<<(std::ostream &os, const fixed_string<LENGTH> &rhs)
     {
       return os << rhs.str();
     }
+#endif
 
-#ifdef _WIN32
+#if defined(_WIN32) || defined(_MSC_VER)
   inline std::wstring to_WideChar(UINT uCodePage, const std::string &text)
   {
     int size=MultiByteToWideChar(uCodePage, 0, text.c_str(), -1, NULL, 0);
@@ -224,7 +230,6 @@ namespace meshio {
   {
     return to_unicode(text.c_str(), "CP932");
   }
-
 #endif
 
   inline std::wstring trim(const std::wstring &src){
index 30c49f9..bc2ec4e 100644 (file)
@@ -3,9 +3,10 @@
 %{
 #include <pmd.h>
 %}
+%include "../../src/pmd.h"
 %include "../../src/color.h"
 %include "../../src/la.h"
-%include "../../src/pmd.h"
+%include "../../src/text.h"
 
 %include "std_pair.i"
 %include "std_vector.i"
@@ -23,4 +24,5 @@
 %template(BoneGroupVector) std::vector<meshio::pmd::BoneGroup>;
 %template(DisplayPair) std::pair<unsigned short, unsigned char>;
 %template(BoneDisplayVector) std::vector<std::pair<unsigned short, unsigned char> >;
+%template(fixed_string_20) meshio::fixed_string<20>;
 
index 482997f..f40825a 100644 (file)
@@ -1,34 +1,41 @@
+BOOST_ROOT='C:/boost/boost_1_46_1'
+
 # swig -c++ -python -o mqo_wrap.cxx ../mqo.i
 # swig -c++ -python -o pmd_wrap.cxx ../pmd.i
 import os
 from distutils.core import setup, Extension
 
 if os.name=='nt':
-    extra_compile_args=[]
+    # for vc
+    extra_compile_args=["/EHsc", "/wd4996"]
+    libraries=[]
+    include_dirs=['../../src', BOOST_ROOT]
 else:
     extra_compile_args=['-std=c++0x']
+    libraries=["iconv"]
+    include_dirs=['../../src']
 
 setup(
         name='meshio',
         version='1.0',
         description='3D mesh IO library',
         py_modules=["__init__", "mqo", "pmd"],
+
         ext_modules = [
             Extension("_mqo", 
                 language="c++",
-                sources=["mqo_wrap.cxx"], 
-                include_dirs=["../../src"],
+                sources=["mqo_wrap.cxx", "../../src/mqo.cpp", "../../src/binary.cpp"], 
+                include_dirs=include_dirs,
                 extra_compile_args=extra_compile_args,
-                library_dirs=["../../debug"],
-                libraries=["meshio"]
+                libraries=libraries
                 ),
+
             Extension("_pmd", 
                 language="c++",
-                sources=["pmd_wrap.cxx"], 
-                include_dirs=["../../src"],
+                sources=["pmd_wrap.cxx", "../../src/pmd.cpp", "../../src/binary.cpp"], 
+                include_dirs=include_dirs,
                 extra_compile_args=extra_compile_args,
-                library_dirs=["../../debug"],
-                libraries=["meshio"]
+                libraries=libraries
                 ),
             ]
         )