3D model(pmd, mqo...) IO library using C++.
Revision | a57cac49a7130353d7be72eed3039236c425ad11 (tree) |
---|---|
Time | 2011-05-04 01:36:07 |
Author | ousttrue <ousttrue@gmai...> |
Commiter | ousttrue |
fix for vc2008
@@ -47,13 +47,13 @@ namespace meshio { | ||
47 | 47 | //! Sceneチャンク |
48 | 48 | struct Scene |
49 | 49 | { |
50 | - Vector3 pos; | |
51 | - Vector3 lookat; | |
50 | + meshio::Vector3 pos; | |
51 | + meshio::Vector3 lookat; | |
52 | 52 | float head; |
53 | 53 | float pitch; |
54 | 54 | int ortho; |
55 | 55 | float zoom2; |
56 | - Vector3 ambient; | |
56 | + meshio::Vector3 ambient; | |
57 | 57 | Scene() |
58 | 58 | : head(0), pitch(0), ortho(false), zoom2(2) |
59 | 59 | {} |
@@ -79,7 +79,7 @@ namespace meshio { | ||
79 | 79 | { |
80 | 80 | std::string name; |
81 | 81 | int shader; |
82 | - fRGBA color; | |
82 | + meshio::fRGBA color; | |
83 | 83 | float diffuse; |
84 | 84 | float ambient; |
85 | 85 | float emit; |
@@ -121,8 +121,8 @@ namespace meshio { | ||
121 | 121 | unsigned int index_count; |
122 | 122 | unsigned int indices[4]; |
123 | 123 | unsigned int material_index; |
124 | - Vector2 uv[4]; | |
125 | - fRGBA color[4]; | |
124 | + meshio::Vector2 uv[4]; | |
125 | + meshio::fRGBA color[4]; | |
126 | 126 | Face() |
127 | 127 | : index_count(0), material_index(0) |
128 | 128 | { |
@@ -195,18 +195,18 @@ namespace meshio { | ||
195 | 195 | std::string name; |
196 | 196 | int depth; |
197 | 197 | int folding; |
198 | - Vector3 scale; | |
199 | - Vector3 rotation; | |
200 | - Vector3 translation; | |
198 | + meshio::Vector3 scale; | |
199 | + meshio::Vector3 rotation; | |
200 | + meshio::Vector3 translation; | |
201 | 201 | int visible; |
202 | 202 | int locking; |
203 | 203 | int shading; |
204 | 204 | float smoothing; |
205 | - Vector3 color; | |
205 | + meshio::Vector3 color; | |
206 | 206 | int color_type; |
207 | 207 | int mirror; |
208 | 208 | |
209 | - std::vector<Vector3> vertices; | |
209 | + std::vector<meshio::Vector3> vertices; | |
210 | 210 | std::vector<Face> faces; |
211 | 211 | |
212 | 212 | Object() |
@@ -233,9 +233,9 @@ namespace meshio { | ||
233 | 233 | std::vector<Material> materials; |
234 | 234 | std::vector<Object> objects; |
235 | 235 | |
236 | - bool read(binary::IReader &reader); | |
236 | + bool read(meshio::binary::IReader &reader); | |
237 | 237 | bool read(const char *path); |
238 | - bool write(binary::IWriter &writer); | |
238 | + bool write(meshio::binary::IWriter &writer); | |
239 | 239 | bool write(const char *path); |
240 | 240 | }; |
241 | 241 |
@@ -408,12 +408,11 @@ namespace meshio { | ||
408 | 408 | IO::IO() |
409 | 409 | : version(0) |
410 | 410 | { |
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 | + } | |
417 | 416 | } |
418 | 417 | |
419 | 418 | bool IO::read(binary::IReader &input) |
@@ -37,7 +37,14 @@ | ||
37 | 37 | #include "binary.h" |
38 | 38 | #include <ostream> |
39 | 39 | #include <vector> |
40 | +#ifdef _MSC_VER | |
41 | +#include <boost/array.hpp> | |
42 | +namespace std { | |
43 | + using boost::array; | |
44 | +} | |
45 | +#else | |
40 | 46 | #include <array> |
47 | +#endif | |
41 | 48 | |
42 | 49 | namespace meshio { |
43 | 50 | namespace pmd { |
@@ -48,11 +55,11 @@ namespace meshio { | ||
48 | 55 | struct Vertex |
49 | 56 | { |
50 | 57 | //! 座標 |
51 | - Vector3 pos; | |
58 | + meshio::Vector3 pos; | |
52 | 59 | //! 法線ベクトル |
53 | - Vector3 normal; | |
60 | + meshio::Vector3 normal; | |
54 | 61 | //! テクスチャUV |
55 | - Vector2 uv; | |
62 | + meshio::Vector2 uv; | |
56 | 63 | //! ブレンディングボーン1 |
57 | 64 | unsigned short bone0; |
58 | 65 | //! ブレンディングボーン2 |
@@ -62,6 +69,7 @@ namespace meshio { | ||
62 | 69 | //! 非エッジ |
63 | 70 | unsigned char edge_flag; |
64 | 71 | }; |
72 | +#ifndef SWIG | |
65 | 73 | inline std::ostream &operator<<(std::ostream &os, const Vertex &rhs) |
66 | 74 | { |
67 | 75 | os |
@@ -77,6 +85,7 @@ namespace meshio { | ||
77 | 85 | ; |
78 | 86 | return os; |
79 | 87 | } |
88 | +#endif | |
80 | 89 | |
81 | 90 | //////////////////////////////////////////////////////////// |
82 | 91 | //! 材質 |
@@ -84,13 +93,13 @@ namespace meshio { | ||
84 | 93 | struct Material |
85 | 94 | { |
86 | 95 | //! Diffuse |
87 | - fRGBA diffuse; | |
96 | + meshio::fRGBA diffuse; | |
88 | 97 | //! Shinness |
89 | 98 | float shinness; |
90 | 99 | //! Specular |
91 | - fRGB specular; | |
100 | + meshio::fRGB specular; | |
92 | 101 | //! Ambient |
93 | - fRGB ambient; | |
102 | + meshio::fRGB ambient; | |
94 | 103 | //! トゥーンテクスチャ |
95 | 104 | unsigned char toon_index; |
96 | 105 | //! 輪郭/影 |
@@ -98,8 +107,9 @@ namespace meshio { | ||
98 | 107 | //! 面頂点数 |
99 | 108 | unsigned int vertex_count; |
100 | 109 | //! テクスチャ |
101 | - fixed_string<20> texture; | |
110 | + meshio::fixed_string<20> texture; | |
102 | 111 | }; |
112 | +#ifndef SWIG | |
103 | 113 | inline std::ostream &operator<<(std::ostream &os, |
104 | 114 | const Material &rhs) |
105 | 115 | { |
@@ -114,6 +124,7 @@ namespace meshio { | ||
114 | 124 | ; |
115 | 125 | return os; |
116 | 126 | } |
127 | +#endif | |
117 | 128 | |
118 | 129 | //////////////////////////////////////////////////////////// |
119 | 130 | //! ボーン |
@@ -145,7 +156,7 @@ namespace meshio { | ||
145 | 156 | struct Bone |
146 | 157 | { |
147 | 158 | //! 名前 |
148 | - fixed_string<20> name; | |
159 | + meshio::fixed_string<20> name; | |
149 | 160 | //! 親ボーン |
150 | 161 | unsigned short parent_index; |
151 | 162 | //! 子ボーン |
@@ -155,12 +166,12 @@ namespace meshio { | ||
155 | 166 | //! 影響IKボーン |
156 | 167 | unsigned short ik_index; |
157 | 168 | // ボーン座標 |
158 | - Vector3 pos; | |
169 | + meshio::Vector3 pos; | |
159 | 170 | //! 英語名 |
160 | - fixed_string<20> english_name; | |
171 | + meshio::fixed_string<20> english_name; | |
161 | 172 | //! ボーン階層構築用 |
162 | 173 | Bone* parent; |
163 | - Vector3 tail; | |
174 | + meshio::Vector3 tail; | |
164 | 175 | std::vector<Bone*> children; |
165 | 176 | unsigned short index; |
166 | 177 |
@@ -168,6 +179,7 @@ namespace meshio { | ||
168 | 179 | : parent_index(-1), tail_index(-1), type(BONE_UNKNOWN), ik_index(-1), parent(0), index(-1) |
169 | 180 | {} |
170 | 181 | }; |
182 | +#ifndef SWIG | |
171 | 183 | inline std::ostream &operator<<(std::ostream &os, |
172 | 184 | const Bone &rhs) |
173 | 185 | { |
@@ -178,6 +190,7 @@ namespace meshio { | ||
178 | 190 | ; |
179 | 191 | return os; |
180 | 192 | } |
193 | +#endif | |
181 | 194 | |
182 | 195 | //////////////////////////////////////////////////////////// |
183 | 196 | //! IK |
@@ -197,6 +210,7 @@ namespace meshio { | ||
197 | 210 | //! エフェクタに連動するボーン(基本的に親ボーンに遡る) |
198 | 211 | std::vector<unsigned short> children; |
199 | 212 | }; |
213 | +#ifndef SWIG | |
200 | 214 | inline std::ostream &operator<<(std::ostream &os, const IK &rhs) |
201 | 215 | { |
202 | 216 | os |
@@ -205,6 +219,7 @@ namespace meshio { | ||
205 | 219 | ; |
206 | 220 | return os; |
207 | 221 | } |
222 | +#endif | |
208 | 223 | |
209 | 224 | //////////////////////////////////////////////////////////// |
210 | 225 | //! 表情 |
@@ -226,7 +241,7 @@ namespace meshio { | ||
226 | 241 | struct Morph |
227 | 242 | { |
228 | 243 | //! 表情名 |
229 | - fixed_string<20> name; | |
244 | + meshio::fixed_string<20> name; | |
230 | 245 | //! 使用する頂点数 |
231 | 246 | unsigned int vertex_count; |
232 | 247 | //! 分類 |
@@ -234,10 +249,11 @@ namespace meshio { | ||
234 | 249 | //! 頂点Index |
235 | 250 | std::vector<unsigned int> indices; |
236 | 251 | //! 移動量 |
237 | - std::vector<Vector3> pos_list; | |
252 | + std::vector<meshio::Vector3> pos_list; | |
238 | 253 | //! 英語名 |
239 | - fixed_string<20> english_name; | |
254 | + meshio::fixed_string<20> english_name; | |
240 | 255 | }; |
256 | +#ifndef SWIG | |
241 | 257 | inline std::ostream &operator<<(std::ostream &os, const Morph &rhs) |
242 | 258 | { |
243 | 259 | os |
@@ -247,14 +263,15 @@ namespace meshio { | ||
247 | 263 | ; |
248 | 264 | return os; |
249 | 265 | } |
266 | +#endif | |
250 | 267 | |
251 | 268 | //////////////////////////////////////////////////////////// |
252 | 269 | //! ボーン表示枠 |
253 | 270 | //////////////////////////////////////////////////////////// |
254 | 271 | struct BoneGroup |
255 | 272 | { |
256 | - fixed_string<50> name; | |
257 | - fixed_string<50> english_name; | |
273 | + meshio::fixed_string<50> name; | |
274 | + meshio::fixed_string<50> english_name; | |
258 | 275 | }; |
259 | 276 | |
260 | 277 | //////////////////////////////////////////////////////////// |
@@ -284,7 +301,7 @@ namespace meshio { | ||
284 | 301 | struct RigidBody |
285 | 302 | { |
286 | 303 | //! 剛体名 |
287 | - fixed_string<20> name; | |
304 | + meshio::fixed_string<20> name; | |
288 | 305 | //! 関連ボーン(ボーン追従とボーン位置合わせで必要) |
289 | 306 | unsigned short boneIndex; |
290 | 307 | //! グループ |
@@ -298,8 +315,8 @@ namespace meshio { | ||
298 | 315 | float h; |
299 | 316 | float d; |
300 | 317 | //! 姿勢 |
301 | - Vector3 position; | |
302 | - Vector3 rotation; | |
318 | + meshio::Vector3 position; | |
319 | + meshio::Vector3 rotation; | |
303 | 320 | //! 質量 |
304 | 321 | float weight; |
305 | 322 | //! 物理演算パラメータ(bullet) |
@@ -315,24 +332,24 @@ namespace meshio { | ||
315 | 332 | struct Constraint |
316 | 333 | { |
317 | 334 | //! Joint名 |
318 | - fixed_string<20> name; | |
335 | + meshio::fixed_string<20> name; | |
319 | 336 | //! 接続剛体A |
320 | 337 | unsigned int rigidA; |
321 | 338 | //! 接続剛体B |
322 | 339 | unsigned int rigidB; |
323 | 340 | //! 位置 |
324 | - Vector3 pos; | |
341 | + meshio::Vector3 pos; | |
325 | 342 | //! 回転 |
326 | - Vector3 rot; | |
343 | + meshio::Vector3 rot; | |
327 | 344 | //! 移動制限 |
328 | - Vector3 constraintPosMin; | |
329 | - Vector3 constraintPosMax; | |
345 | + meshio::Vector3 constraintPosMin; | |
346 | + meshio::Vector3 constraintPosMax; | |
330 | 347 | //! 回転制限 |
331 | - Vector3 constraintRotMin; | |
332 | - Vector3 constraintRotMax; | |
348 | + meshio::Vector3 constraintRotMin; | |
349 | + meshio::Vector3 constraintRotMax; | |
333 | 350 | //! ばね |
334 | - Vector3 springPos; | |
335 | - Vector3 springRot; | |
351 | + meshio::Vector3 springPos; | |
352 | + meshio::Vector3 springRot; | |
336 | 353 | }; |
337 | 354 | |
338 | 355 |
@@ -340,8 +357,8 @@ namespace meshio { | ||
340 | 357 | struct IO |
341 | 358 | { |
342 | 359 | float version; |
343 | - fixed_string<20> name; | |
344 | - fixed_string<256> comment; | |
360 | + meshio::fixed_string<20> name; | |
361 | + meshio::fixed_string<256> comment; | |
345 | 362 | std::vector<Vertex> vertices; |
346 | 363 | std::vector<unsigned short> indices; |
347 | 364 | std::vector<Material> materials; |
@@ -351,19 +368,20 @@ namespace meshio { | ||
351 | 368 | std::vector<unsigned short> face_list; |
352 | 369 | std::vector<BoneGroup> bone_group_list; |
353 | 370 | 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; | |
355 | 372 | std::vector<RigidBody> rigidbodies; |
356 | 373 | std::vector<Constraint> constraints; |
357 | 374 | |
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; | |
360 | 377 | |
361 | 378 | IO(); |
362 | 379 | bool read(const char *path); |
363 | 380 | 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); | |
366 | 383 | }; |
384 | +#ifndef SWIG | |
367 | 385 | inline std::ostream &operator<<(std::ostream &os, const IO &rhs) |
368 | 386 | { |
369 | 387 | os |
@@ -401,6 +419,7 @@ namespace meshio { | ||
401 | 419 | ; |
402 | 420 | return os; |
403 | 421 | } |
422 | +#endif | |
404 | 423 | |
405 | 424 | |
406 | 425 | } // namespace pmd |
@@ -95,10 +95,12 @@ namespace meshio { | ||
95 | 95 | return *this; |
96 | 96 | } |
97 | 97 | }; |
98 | +#ifndef SWIG | |
98 | 99 | inline std::ostream &operator<<(std::ostream &os, const cstr &rhs) |
99 | 100 | { |
100 | 101 | return os << rhs.str(); |
101 | 102 | } |
103 | +#endif | |
102 | 104 | |
103 | 105 | template<int LENGTH> |
104 | 106 | class fixed_string |
@@ -126,15 +128,17 @@ namespace meshio { | ||
126 | 128 | if(src.empty()){ |
127 | 129 | return; |
128 | 130 | } |
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 | + { | |
131 | 137 | begin_[i]=*it; |
132 | 138 | } |
133 | - if(std::distance( | |
134 | - static_cast<char*>(begin_), | |
135 | - static_cast<char*>(end_))<LENGTH) | |
139 | + if(i<LENGTH) | |
136 | 140 | { |
137 | - *end_='\0'; | |
141 | + begin_[i]='\0'; | |
138 | 142 | } |
139 | 143 | } |
140 | 144 | size_t size()const { return LENGTH; } |
@@ -142,7 +146,7 @@ namespace meshio { | ||
142 | 146 | const char *begin() const { return begin_; } |
143 | 147 | std::string str() const |
144 | 148 | { |
145 | - auto end=begin_; | |
149 | + const char *end=begin_; | |
146 | 150 | for(; end!=end_ && *end!='\0'; ++end){ |
147 | 151 | } |
148 | 152 | return std::string( |
@@ -150,13 +154,15 @@ namespace meshio { | ||
150 | 154 | static_cast<const char*>(end)); |
151 | 155 | } |
152 | 156 | }; |
157 | +#ifndef SWIG | |
153 | 158 | template<int LENGTH> |
154 | 159 | inline std::ostream &operator<<(std::ostream &os, const fixed_string<LENGTH> &rhs) |
155 | 160 | { |
156 | 161 | return os << rhs.str(); |
157 | 162 | } |
163 | +#endif | |
158 | 164 | |
159 | -#ifdef _WIN32 | |
165 | +#if defined(_WIN32) || defined(_MSC_VER) | |
160 | 166 | inline std::wstring to_WideChar(UINT uCodePage, const std::string &text) |
161 | 167 | { |
162 | 168 | int size=MultiByteToWideChar(uCodePage, 0, text.c_str(), -1, NULL, 0); |
@@ -224,7 +230,6 @@ namespace meshio { | ||
224 | 230 | { |
225 | 231 | return to_unicode(text.c_str(), "CP932"); |
226 | 232 | } |
227 | - | |
228 | 233 | #endif |
229 | 234 | |
230 | 235 | inline std::wstring trim(const std::wstring &src){ |
@@ -3,9 +3,10 @@ | ||
3 | 3 | %{ |
4 | 4 | #include <pmd.h> |
5 | 5 | %} |
6 | +%include "../../src/pmd.h" | |
6 | 7 | %include "../../src/color.h" |
7 | 8 | %include "../../src/la.h" |
8 | -%include "../../src/pmd.h" | |
9 | +%include "../../src/text.h" | |
9 | 10 | |
10 | 11 | %include "std_pair.i" |
11 | 12 | %include "std_vector.i" |
@@ -23,4 +24,5 @@ | ||
23 | 24 | %template(BoneGroupVector) std::vector<meshio::pmd::BoneGroup>; |
24 | 25 | %template(DisplayPair) std::pair<unsigned short, unsigned char>; |
25 | 26 | %template(BoneDisplayVector) std::vector<std::pair<unsigned short, unsigned char> >; |
27 | +%template(fixed_string_20) meshio::fixed_string<20>; | |
26 | 28 |
@@ -1,34 +1,41 @@ | ||
1 | +BOOST_ROOT='C:/boost/boost_1_46_1' | |
2 | + | |
1 | 3 | # swig -c++ -python -o mqo_wrap.cxx ../mqo.i |
2 | 4 | # swig -c++ -python -o pmd_wrap.cxx ../pmd.i |
3 | 5 | import os |
4 | 6 | from distutils.core import setup, Extension |
5 | 7 | |
6 | 8 | 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] | |
8 | 13 | else: |
9 | 14 | extra_compile_args=['-std=c++0x'] |
15 | + libraries=["iconv"] | |
16 | + include_dirs=['../../src'] | |
10 | 17 | |
11 | 18 | setup( |
12 | 19 | name='meshio', |
13 | 20 | version='1.0', |
14 | 21 | description='3D mesh IO library', |
15 | 22 | py_modules=["__init__", "mqo", "pmd"], |
23 | + | |
16 | 24 | ext_modules = [ |
17 | 25 | Extension("_mqo", |
18 | 26 | 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, | |
21 | 29 | extra_compile_args=extra_compile_args, |
22 | - library_dirs=["../../debug"], | |
23 | - libraries=["meshio"] | |
30 | + libraries=libraries | |
24 | 31 | ), |
32 | + | |
25 | 33 | Extension("_pmd", |
26 | 34 | 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, | |
29 | 37 | extra_compile_args=extra_compile_args, |
30 | - library_dirs=["../../debug"], | |
31 | - libraries=["meshio"] | |
38 | + libraries=libraries | |
32 | 39 | ), |
33 | 40 | ] |
34 | 41 | ) |