• R/O
  • HTTP
  • SSH
  • HTTPS

meshio: Commit

3D model(pmd, mqo...) IO library using C++.


Commit MetaInfo

Revisiona57cac49a7130353d7be72eed3039236c425ad11 (tree)
Time2011-05-04 01:36:07
Authorousttrue <ousttrue@gmai...>
Commiterousttrue

Log Message

fix for vc2008

Change Summary

Incremental Difference

--- a/src/mqo.h
+++ b/src/mqo.h
@@ -47,13 +47,13 @@ namespace meshio {
4747 //! Sceneチャンク
4848 struct Scene
4949 {
50- Vector3 pos;
51- Vector3 lookat;
50+ meshio::Vector3 pos;
51+ meshio::Vector3 lookat;
5252 float head;
5353 float pitch;
5454 int ortho;
5555 float zoom2;
56- Vector3 ambient;
56+ meshio::Vector3 ambient;
5757 Scene()
5858 : head(0), pitch(0), ortho(false), zoom2(2)
5959 {}
@@ -79,7 +79,7 @@ namespace meshio {
7979 {
8080 std::string name;
8181 int shader;
82- fRGBA color;
82+ meshio::fRGBA color;
8383 float diffuse;
8484 float ambient;
8585 float emit;
@@ -121,8 +121,8 @@ namespace meshio {
121121 unsigned int index_count;
122122 unsigned int indices[4];
123123 unsigned int material_index;
124- Vector2 uv[4];
125- fRGBA color[4];
124+ meshio::Vector2 uv[4];
125+ meshio::fRGBA color[4];
126126 Face()
127127 : index_count(0), material_index(0)
128128 {
@@ -195,18 +195,18 @@ namespace meshio {
195195 std::string name;
196196 int depth;
197197 int folding;
198- Vector3 scale;
199- Vector3 rotation;
200- Vector3 translation;
198+ meshio::Vector3 scale;
199+ meshio::Vector3 rotation;
200+ meshio::Vector3 translation;
201201 int visible;
202202 int locking;
203203 int shading;
204204 float smoothing;
205- Vector3 color;
205+ meshio::Vector3 color;
206206 int color_type;
207207 int mirror;
208208
209- std::vector<Vector3> vertices;
209+ std::vector<meshio::Vector3> vertices;
210210 std::vector<Face> faces;
211211
212212 Object()
@@ -233,9 +233,9 @@ namespace meshio {
233233 std::vector<Material> materials;
234234 std::vector<Object> objects;
235235
236- bool read(binary::IReader &reader);
236+ bool read(meshio::binary::IReader &reader);
237237 bool read(const char *path);
238- bool write(binary::IWriter &writer);
238+ bool write(meshio::binary::IWriter &writer);
239239 bool write(const char *path);
240240 };
241241
--- a/src/pmd.cpp
+++ b/src/pmd.cpp
@@ -408,12 +408,11 @@ namespace meshio {
408408 IO::IO()
409409 : version(0)
410410 {
411- int i=1;
412- for(auto it=toon_textures.begin(); it!=toon_textures.end(); ++it){
413- char toon[100];
414- sprintf(toon, "toon%02d.bmp", i);
415- *it=toon;
416- }
411+ for(int i=0; i<10; ++i){
412+ char toon[100];
413+ sprintf(toon, "toon%02d.bmp", i+1);
414+ toon_textures[i]=toon;
415+ }
417416 }
418417
419418 bool IO::read(binary::IReader &input)
--- a/src/pmd.h
+++ b/src/pmd.h
@@ -37,7 +37,14 @@
3737 #include "binary.h"
3838 #include <ostream>
3939 #include <vector>
40+#ifdef _MSC_VER
41+#include <boost/array.hpp>
42+namespace std {
43+ using boost::array;
44+}
45+#else
4046 #include <array>
47+#endif
4148
4249 namespace meshio {
4350 namespace pmd {
@@ -48,11 +55,11 @@ namespace meshio {
4855 struct Vertex
4956 {
5057 //! 座標
51- Vector3 pos;
58+ meshio::Vector3 pos;
5259 //! 法線ベクトル
53- Vector3 normal;
60+ meshio::Vector3 normal;
5461 //! テクスチャUV
55- Vector2 uv;
62+ meshio::Vector2 uv;
5663 //! ブレンディングボーン1
5764 unsigned short bone0;
5865 //! ブレンディングボーン2
@@ -62,6 +69,7 @@ namespace meshio {
6269 //! 非エッジ
6370 unsigned char edge_flag;
6471 };
72+#ifndef SWIG
6573 inline std::ostream &operator<<(std::ostream &os, const Vertex &rhs)
6674 {
6775 os
@@ -77,6 +85,7 @@ namespace meshio {
7785 ;
7886 return os;
7987 }
88+#endif
8089
8190 ////////////////////////////////////////////////////////////
8291 //! 材質
@@ -84,13 +93,13 @@ namespace meshio {
8493 struct Material
8594 {
8695 //! Diffuse
87- fRGBA diffuse;
96+ meshio::fRGBA diffuse;
8897 //! Shinness
8998 float shinness;
9099 //! Specular
91- fRGB specular;
100+ meshio::fRGB specular;
92101 //! Ambient
93- fRGB ambient;
102+ meshio::fRGB ambient;
94103 //! トゥーンテクスチャ
95104 unsigned char toon_index;
96105 //! 輪郭/影
@@ -98,8 +107,9 @@ namespace meshio {
98107 //! 面頂点数
99108 unsigned int vertex_count;
100109 //! テクスチャ
101- fixed_string<20> texture;
110+ meshio::fixed_string<20> texture;
102111 };
112+#ifndef SWIG
103113 inline std::ostream &operator<<(std::ostream &os,
104114 const Material &rhs)
105115 {
@@ -114,6 +124,7 @@ namespace meshio {
114124 ;
115125 return os;
116126 }
127+#endif
117128
118129 ////////////////////////////////////////////////////////////
119130 //! ボーン
@@ -145,7 +156,7 @@ namespace meshio {
145156 struct Bone
146157 {
147158 //! 名前
148- fixed_string<20> name;
159+ meshio::fixed_string<20> name;
149160 //! 親ボーン
150161 unsigned short parent_index;
151162 //! 子ボーン
@@ -155,12 +166,12 @@ namespace meshio {
155166 //! 影響IKボーン
156167 unsigned short ik_index;
157168 // ボーン座標
158- Vector3 pos;
169+ meshio::Vector3 pos;
159170 //! 英語名
160- fixed_string<20> english_name;
171+ meshio::fixed_string<20> english_name;
161172 //! ボーン階層構築用
162173 Bone* parent;
163- Vector3 tail;
174+ meshio::Vector3 tail;
164175 std::vector<Bone*> children;
165176 unsigned short index;
166177
@@ -168,6 +179,7 @@ namespace meshio {
168179 : parent_index(-1), tail_index(-1), type(BONE_UNKNOWN), ik_index(-1), parent(0), index(-1)
169180 {}
170181 };
182+#ifndef SWIG
171183 inline std::ostream &operator<<(std::ostream &os,
172184 const Bone &rhs)
173185 {
@@ -178,6 +190,7 @@ namespace meshio {
178190 ;
179191 return os;
180192 }
193+#endif
181194
182195 ////////////////////////////////////////////////////////////
183196 //! IK
@@ -197,6 +210,7 @@ namespace meshio {
197210 //! エフェクタに連動するボーン(基本的に親ボーンに遡る)
198211 std::vector<unsigned short> children;
199212 };
213+#ifndef SWIG
200214 inline std::ostream &operator<<(std::ostream &os, const IK &rhs)
201215 {
202216 os
@@ -205,6 +219,7 @@ namespace meshio {
205219 ;
206220 return os;
207221 }
222+#endif
208223
209224 ////////////////////////////////////////////////////////////
210225 //! 表情
@@ -226,7 +241,7 @@ namespace meshio {
226241 struct Morph
227242 {
228243 //! 表情名
229- fixed_string<20> name;
244+ meshio::fixed_string<20> name;
230245 //! 使用する頂点数
231246 unsigned int vertex_count;
232247 //! 分類
@@ -234,10 +249,11 @@ namespace meshio {
234249 //! 頂点Index
235250 std::vector<unsigned int> indices;
236251 //! 移動量
237- std::vector<Vector3> pos_list;
252+ std::vector<meshio::Vector3> pos_list;
238253 //! 英語名
239- fixed_string<20> english_name;
254+ meshio::fixed_string<20> english_name;
240255 };
256+#ifndef SWIG
241257 inline std::ostream &operator<<(std::ostream &os, const Morph &rhs)
242258 {
243259 os
@@ -247,14 +263,15 @@ namespace meshio {
247263 ;
248264 return os;
249265 }
266+#endif
250267
251268 ////////////////////////////////////////////////////////////
252269 //! ボーン表示枠
253270 ////////////////////////////////////////////////////////////
254271 struct BoneGroup
255272 {
256- fixed_string<50> name;
257- fixed_string<50> english_name;
273+ meshio::fixed_string<50> name;
274+ meshio::fixed_string<50> english_name;
258275 };
259276
260277 ////////////////////////////////////////////////////////////
@@ -284,7 +301,7 @@ namespace meshio {
284301 struct RigidBody
285302 {
286303 //! 剛体名
287- fixed_string<20> name;
304+ meshio::fixed_string<20> name;
288305 //! 関連ボーン(ボーン追従とボーン位置合わせで必要)
289306 unsigned short boneIndex;
290307 //! グループ
@@ -298,8 +315,8 @@ namespace meshio {
298315 float h;
299316 float d;
300317 //! 姿勢
301- Vector3 position;
302- Vector3 rotation;
318+ meshio::Vector3 position;
319+ meshio::Vector3 rotation;
303320 //! 質量
304321 float weight;
305322 //! 物理演算パラメータ(bullet)
@@ -315,24 +332,24 @@ namespace meshio {
315332 struct Constraint
316333 {
317334 //! Joint名
318- fixed_string<20> name;
335+ meshio::fixed_string<20> name;
319336 //! 接続剛体A
320337 unsigned int rigidA;
321338 //! 接続剛体B
322339 unsigned int rigidB;
323340 //! 位置
324- Vector3 pos;
341+ meshio::Vector3 pos;
325342 //! 回転
326- Vector3 rot;
343+ meshio::Vector3 rot;
327344 //! 移動制限
328- Vector3 constraintPosMin;
329- Vector3 constraintPosMax;
345+ meshio::Vector3 constraintPosMin;
346+ meshio::Vector3 constraintPosMax;
330347 //! 回転制限
331- Vector3 constraintRotMin;
332- Vector3 constraintRotMax;
348+ meshio::Vector3 constraintRotMin;
349+ meshio::Vector3 constraintRotMax;
333350 //! ばね
334- Vector3 springPos;
335- Vector3 springRot;
351+ meshio::Vector3 springPos;
352+ meshio::Vector3 springRot;
336353 };
337354
338355
@@ -340,8 +357,8 @@ namespace meshio {
340357 struct IO
341358 {
342359 float version;
343- fixed_string<20> name;
344- fixed_string<256> comment;
360+ meshio::fixed_string<20> name;
361+ meshio::fixed_string<256> comment;
345362 std::vector<Vertex> vertices;
346363 std::vector<unsigned short> indices;
347364 std::vector<Material> materials;
@@ -351,19 +368,20 @@ namespace meshio {
351368 std::vector<unsigned short> face_list;
352369 std::vector<BoneGroup> bone_group_list;
353370 std::vector<std::pair<unsigned short, unsigned char> > bone_display_list;
354- std::array<fixed_string<100>, 10> toon_textures;
371+ std::array<meshio::fixed_string<100>, 10> toon_textures;
355372 std::vector<RigidBody> rigidbodies;
356373 std::vector<Constraint> constraints;
357374
358- fixed_string<20> english_name;
359- fixed_string<256> english_comment;
375+ meshio::fixed_string<20> english_name;
376+ meshio::fixed_string<256> english_comment;
360377
361378 IO();
362379 bool read(const char *path);
363380 bool write(const char *path);
364- bool read(binary::IReader &reader);
365- bool write(binary::IWriter &writer);
381+ bool read(meshio::binary::IReader &reader);
382+ bool write(meshio::binary::IWriter &writer);
366383 };
384+#ifndef SWIG
367385 inline std::ostream &operator<<(std::ostream &os, const IO &rhs)
368386 {
369387 os
@@ -401,6 +419,7 @@ namespace meshio {
401419 ;
402420 return os;
403421 }
422+#endif
404423
405424
406425 } // namespace pmd
--- a/src/text.h
+++ b/src/text.h
@@ -95,10 +95,12 @@ namespace meshio {
9595 return *this;
9696 }
9797 };
98+#ifndef SWIG
9899 inline std::ostream &operator<<(std::ostream &os, const cstr &rhs)
99100 {
100101 return os << rhs.str();
101102 }
103+#endif
102104
103105 template<int LENGTH>
104106 class fixed_string
@@ -126,15 +128,17 @@ namespace meshio {
126128 if(src.empty()){
127129 return;
128130 }
129- auto it=src.begin();
130- for(int i=0; i<LENGTH && *it; ++i, ++it, ++end_){
131+ std::string::const_iterator it=src.begin();
132+ int i;
133+ for(i=0;
134+ i<LENGTH && it!=src.end();
135+ ++i, ++it)
136+ {
131137 begin_[i]=*it;
132138 }
133- if(std::distance(
134- static_cast<char*>(begin_),
135- static_cast<char*>(end_))<LENGTH)
139+ if(i<LENGTH)
136140 {
137- *end_='\0';
141+ begin_[i]='\0';
138142 }
139143 }
140144 size_t size()const { return LENGTH; }
@@ -142,7 +146,7 @@ namespace meshio {
142146 const char *begin() const { return begin_; }
143147 std::string str() const
144148 {
145- auto end=begin_;
149+ const char *end=begin_;
146150 for(; end!=end_ && *end!='\0'; ++end){
147151 }
148152 return std::string(
@@ -150,13 +154,15 @@ namespace meshio {
150154 static_cast<const char*>(end));
151155 }
152156 };
157+#ifndef SWIG
153158 template<int LENGTH>
154159 inline std::ostream &operator<<(std::ostream &os, const fixed_string<LENGTH> &rhs)
155160 {
156161 return os << rhs.str();
157162 }
163+#endif
158164
159-#ifdef _WIN32
165+#if defined(_WIN32) || defined(_MSC_VER)
160166 inline std::wstring to_WideChar(UINT uCodePage, const std::string &text)
161167 {
162168 int size=MultiByteToWideChar(uCodePage, 0, text.c_str(), -1, NULL, 0);
@@ -224,7 +230,6 @@ namespace meshio {
224230 {
225231 return to_unicode(text.c_str(), "CP932");
226232 }
227-
228233 #endif
229234
230235 inline std::wstring trim(const std::wstring &src){
--- a/swig/pmd.i
+++ b/swig/pmd.i
@@ -3,9 +3,10 @@
33 %{
44 #include <pmd.h>
55 %}
6+%include "../../src/pmd.h"
67 %include "../../src/color.h"
78 %include "../../src/la.h"
8-%include "../../src/pmd.h"
9+%include "../../src/text.h"
910
1011 %include "std_pair.i"
1112 %include "std_vector.i"
@@ -23,4 +24,5 @@
2324 %template(BoneGroupVector) std::vector<meshio::pmd::BoneGroup>;
2425 %template(DisplayPair) std::pair<unsigned short, unsigned char>;
2526 %template(BoneDisplayVector) std::vector<std::pair<unsigned short, unsigned char> >;
27+%template(fixed_string_20) meshio::fixed_string<20>;
2628
--- a/swig/python/setup.py
+++ b/swig/python/setup.py
@@ -1,34 +1,41 @@
1+BOOST_ROOT='C:/boost/boost_1_46_1'
2+
13 # swig -c++ -python -o mqo_wrap.cxx ../mqo.i
24 # swig -c++ -python -o pmd_wrap.cxx ../pmd.i
35 import os
46 from distutils.core import setup, Extension
57
68 if os.name=='nt':
7- extra_compile_args=[]
9+ # for vc
10+ extra_compile_args=["/EHsc", "/wd4996"]
11+ libraries=[]
12+ include_dirs=['../../src', BOOST_ROOT]
813 else:
914 extra_compile_args=['-std=c++0x']
15+ libraries=["iconv"]
16+ include_dirs=['../../src']
1017
1118 setup(
1219 name='meshio',
1320 version='1.0',
1421 description='3D mesh IO library',
1522 py_modules=["__init__", "mqo", "pmd"],
23+
1624 ext_modules = [
1725 Extension("_mqo",
1826 language="c++",
19- sources=["mqo_wrap.cxx"],
20- include_dirs=["../../src"],
27+ sources=["mqo_wrap.cxx", "../../src/mqo.cpp", "../../src/binary.cpp"],
28+ include_dirs=include_dirs,
2129 extra_compile_args=extra_compile_args,
22- library_dirs=["../../debug"],
23- libraries=["meshio"]
30+ libraries=libraries
2431 ),
32+
2533 Extension("_pmd",
2634 language="c++",
27- sources=["pmd_wrap.cxx"],
28- include_dirs=["../../src"],
35+ sources=["pmd_wrap.cxx", "../../src/pmd.cpp", "../../src/binary.cpp"],
36+ include_dirs=include_dirs,
2937 extra_compile_args=extra_compile_args,
30- library_dirs=["../../debug"],
31- libraries=["meshio"]
38+ libraries=libraries
3239 ),
3340 ]
3441 )
Show on old repository browser