OSDN Git Service

fixed by @santarh
[meshio/meshio.git] / lua / lmeshio.pkg
1 $#include "pmd.h"
2 $#include "vmd.h"
3 $#include "mqo.h"
4 $#include "la.h"
5 $#include "color.h"
6
7 $using namespace meshio;
8
9 namespace meshio {
10
11   namespace pmd {
12
13     struct Vertex
14     {
15       //! 座標
16       Vector3 pos;
17       //! 法線ベクトル
18       Vector3 normal;
19       //! テクスチャUV
20       Vector2 uv;
21       //! ブレンディングボーン1
22       unsigned short bone0;
23       //! ブレンディングボーン2
24       unsigned short bone1;
25       //! ウェイト[0 - 100]
26       unsigned char weight0;
27       //! 非エッジ
28       unsigned char edge_flag;
29     };
30
31     struct Material
32     {
33       //! Diffuse
34       fRGBA diffuse;
35       //! Shinness
36       float shinness;
37       //! Specular
38       fRGB specular;
39       //! Ambient
40       fRGB ambient;
41       //! トゥーンテクスチャ
42       unsigned char toon_index;
43       //! 輪郭/影
44       unsigned char flag;
45       //! 面頂点数
46       unsigned int vertex_count;
47       //! テクスチャ
48       fixed_string<20> texture;
49     };
50
51     //! ボーンの種類
52     enum BONE_TYPE
53     {
54       // 回転
55       BONE_ROTATE=0,
56       // 回転と移動
57       BONE_ROTATE_MOVE,
58       // IK
59       BONE_IK,
60       // 不明
61       BONE_UNKNOWN,
62       // IK影響下
63       BONE_IK_INFLUENCED,
64       // 回転影響下
65       BONE_ROTATE_INFLUENCED,
66       // IK接続先
67       BONE_IK_CONNECT,
68       // 非表示
69       BONE_INVISIBLE,
70       // 捻り
71       BONE_TWIST,
72       // 回転連動
73       BONE_REVOLVE,
74     };
75
76     struct Bone
77     {
78       //! 名前
79       fixed_string<20> name;
80       //! 親ボーン
81       unsigned short parent_index;
82       //! 子ボーン
83       unsigned short tail_index;
84       //! ボーン種類
85       BONE_TYPE type;
86       //! 影響IKボーン
87       unsigned short ik_index;
88       // ボーン座標
89       Vector3 pos;
90       //! 英語名
91       fixed_string<20> english_name;
92       //! ボーン階層構築用
93       Bone* parent;
94       Vector3 tail;
95       std::vector<Bone*> children;
96       unsigned short index;
97
98       Bone();
99     };
100
101     struct IK
102     {
103       //! IK(IKターゲット)
104       unsigned short index;
105       //! Target(エフェクター)
106       unsigned short target;
107       //! エフェクタに連動するボーン数
108       unsigned char length;
109       //! IK値1。CCD-IK試行回数
110       unsigned short iterations;
111       //! IK値2。CCD-IK試行一回辺りの影響度
112       float weight;
113       //! エフェクタに連動するボーン(基本的に親ボーンに遡る)
114       std::vector<unsigned short> children;
115     };
116
117     //! 表情の種類
118     enum MORPH_TYPE
119     {
120       //! ベース表情
121       MORPH_BASE=0,
122       //! まゆ
123       MORPH_MAYU,
124       //! 目
125       MORPH_ME,
126       //! リップ
127       MORPH_LIP,
128       //! その他
129       MORPH_OTHER,
130     };
131     struct Morph
132     {
133       //! 表情名
134       fixed_string<20> name;
135       //! 使用する頂点数
136       unsigned int vertex_count;
137       //! 分類
138       unsigned char type;
139       //! 頂点Index
140       std::vector<unsigned int> indices;
141       //! 移動量
142       std::vector<Vector3> pos_list;
143       //! 英語名
144       fixed_string<20> english_name;
145     };
146
147     struct BoneGroup
148     {
149       fixed_string<50> name;
150       fixed_string<50> english_name;
151     };
152
153     //! 形状
154     enum SHAPE_TYPE
155     {
156       //! 球
157       SHAPE_SPHERE=0,
158       //! 箱
159       SHAPE_BOX,
160       //! カプセル
161       SHAPE_CAPSULE,
162     };
163
164     //! 剛体タイプ
165     enum PROCESS_TYPE
166     {
167       //! ボーンと同じ動き
168       RIGIDBODY_KINEMATICS=0,
169       //! 物理演算
170       RIGIDBODY_PHYSICS,
171       //! 物理演算結果をボーンに反映する
172       RIGIDBODY_PHYSICS_WITH_BONE,
173     };
174
175     struct RigidBody
176     {
177       //! 剛体名
178       fixed_string<20> name;
179       //! 関連ボーン(ボーン追従とボーン位置合わせで必要)
180       unsigned short boneIndex;
181       //! グループ
182       unsigned char group;
183       //! 非衝突グループ
184       unsigned short target;
185       //! 形状
186       SHAPE_TYPE shapeType;
187       //! サイズ
188       float w;
189       float h;
190       float d;
191       //! 姿勢
192       Vector3 position;
193       Vector3 rotation;
194       //! 質量
195       float weight;
196       //! 物理演算パラメータ(bullet)
197       float linearDamping;
198       float angularDamping;
199       float restitution;
200       float friction;
201       //! 剛体タイプ
202       PROCESS_TYPE processType;
203     };
204
205     //! Joint(物理演算でのJointとConstraintは同じ意味)
206     struct Constraint
207     {
208       //! Joint名
209       fixed_string<20> name;
210       //! 接続剛体A
211       unsigned int rigidA;
212       //! 接続剛体B
213       unsigned int rigidB;
214       //! 位置
215       Vector3 pos;
216       //! 回転
217       Vector3 rot;
218       //! 移動制限
219       Vector3 constraintPosMin;
220       Vector3 constraintPosMax;
221       //! 回転制限
222       Vector3 constraintRotMin;
223       Vector3 constraintRotMax;
224       //! ばね
225       Vector3 springPos;
226       Vector3 springRot;
227     };
228
229     // IO
230     struct IO
231     {
232       float version;
233       fixed_string<20> name;
234       fixed_string<256> comment;
235       std::vector<Vertex> vertices;
236       std::vector<unsigned short> indices;
237       std::vector<Material> materials;
238       std::vector<Bone> bones;
239       std::vector<IK> ik_list;
240       std::vector<Morph> morph_list;
241       std::vector<unsigned short> face_list;
242       std::vector<BoneGroup> bone_group_list;
243       std::vector<std::pair<unsigned short, unsigned char> > bone_display_list;
244       std::array<fixed_string<100>, 10> toon_textures;
245       std::vector<RigidBody> rigidbodies;
246       std::vector<Constraint> constraints;
247
248       fixed_string<20> english_name;
249       fixed_string<256> english_comment;
250
251       IO();
252       bool read(const char *path);
253       bool write(const char *path);
254     };
255
256     typedef std::vector<Vertex> VertexVector;
257
258   } // namespace pmd
259
260
261
262   namespace mqo {
263
264     struct Scene
265     {
266       Vector3 pos;
267       Vector3 lookat;
268       float head;
269       float pitch;
270       int ortho;
271       float zoom2;
272       Vector3 ambient;
273     };
274
275     struct Material
276     {
277       std::string name;
278       int shader;
279       fRGBA color;
280       float diffuse;
281       float ambient;
282       float emit;
283       float specular;
284       float power;
285       std::string texture;
286       std::string alphamap;
287       std::string bumpmap;
288       int vcol;
289     };
290
291     struct Face
292     {
293       unsigned int index_count;
294       unsigned int indices[4];
295       unsigned int material_index;
296       Vector2 uv[4];
297       fRGBA color[4];
298     };
299
300     struct Object
301     {
302       std::string name;
303       int depth;
304       int folding;
305       Vector3 scale;
306       Vector3 rotation;
307       Vector3 translation;
308       int visible;
309       int locking;
310       int shading;
311       float smoothing;
312       Vector3 color;
313       int color_type;
314       int mirror;
315
316       std::vector<Vector3> vertices;
317       std::vector<Face> faces;
318     };
319
320     struct IO
321     {
322       Scene scene;
323       std::vector<Material> materials;
324       std::vector<Object> objects;
325
326       IO();
327       bool read(const char *path);
328       bool write(const char *path);
329     };
330
331   }
332
333   struct Vector2
334   {
335     float x;
336     float y;
337
338     Vector2(float _x, float _y);
339   };
340
341   struct Vector3
342   {
343     float x;
344     float y;
345     float z;
346
347     Vector3(float _x, float _y, float _z);
348     bool operator==(const Vector3 &rhs)const;
349     Vector3 operator+(const Vector3 &rhs);
350     Vector3 operator-(const Vector3 &rhs);
351   };
352
353   struct Vector4
354   {
355     float x;
356     float y;
357     float z;
358     float w;
359
360     Vector4(float _x, float _y, float _z, float _w);
361   };
362
363   struct Quaternion
364   {
365     float x;
366     float y;
367     float z;
368     float w;
369
370     Quaternion(float _x, float _y, float _z, float _w);
371     float dot(const Quaternion &rhs);
372   };
373
374   struct fRGBA
375   {
376     float r;
377     float g;
378     float b;
379     float a;
380   };
381
382   class fixed_string
383   {
384       TOLUA_TEMPLATE_BIND(T, 20, 50, 100, 256);
385       std::string str() const;
386       void assign(const std::string &src);
387   };
388
389 }
390