OSDN Git Service

add swig python extension.
[meshio/meshio.git] / include / mqo.h
1 /**
2  * MQO\8c`\8e®
3  * \83\81\83^\83Z\83R\83C\83A\82Ì\83\82\83f\83\8b\83f\81[\83^\81B\83e\83L\83X\83g\8c`\8e®\81B
4  * \83}\83e\83\8a\83A\83\8b\8fî\95ñ\82Æ\8c`\8fó\83f\81[\83^\82ð\95Û\8e\9d\82·\82é\81B
5  * \83\82\83f\83\8a\83\93\83O\8cü\82¯\82É\88Ù\82È\82é\92¸\93_\91®\90«\82ð\8e\9d\82Â\92¸\93_\82ð\82Ð\82Æ\82Â\82Ì\92¸\93_\82Æ\82µ\82Ä\88µ\82Á\82Ä\82¢\82é\82Ì\82Å\81A
6  * \83v\83\8d\83O\83\89\83\80\82Å\92¸\93_\94z\97ñ\82ð\8dì\82é\8fê\8d\87\82Í\83}\83e\83\8a\83A\83\8b\81AUV\82È\82Ç\82ª\88Ù\82È\82é\92l\82ð\8e\9d\82Â\92¸\93_\82ð
7  * \95Ê\82Ì\92¸\93_\82Æ\82µ\82Ä\95ª\97£\82·\82é\8dì\8bÆ\82ª\95K\97v\82É\82È\82é\81B
8  * \96@\90ü\82Í\8cv\8eZ\82µ\82Ä\8eZ\8fo\82·\82é\95K\97v\82ª\82 \82é\81B
9  *
10  * \8dÀ\95W\8cn
11  * \89E\8eè Y-UP
12  *
13  * \96Ê\82Ì\95\
14  * clock wise ?
15  *
16  * UV\8c´\93_
17  * left top ?
18  *
19  * \96@\90ü
20  * \83I\83u\83W\83F\83N\83g\82Ì\95Û\8e\9d\82·\82é\83X\83\80\81[\83W\83\93\83O\92l\82ð\8eQ\8fÆ\82µ\82Ä\96Ê\96@\90ü\82©\82ç\8cv\8eZ\82·\82é\81B
21  *
22  * \97 \96Ê\82Ì\88µ\82¢
23  * \83I\83\8a\83W\83i\83\8b\82Å\82Í\83o\83b\83N\83J\83\8a\83\93\83O\97L\8cø\81B
24  *
25  * MIKOTO\95û\8e®\82Ì\83{\81[\83\93
26  * MQO\82Í\95W\8f\80\82Å\83X\83L\83j\83\93\83O\8fî\95ñ\82ð\8e\9d\82½\82È\82¢\82ª\81A\93Á\92è\82Ì\83\8b\81[\83\8b\82Å\83}\83e\83\8a\83A\83\8b\82Æ\83I\83u\83W\83F\83N\83g
27  * \82ð\8dì\90¬\82·\82é\82±\82Æ\82Å\82±\82ê\82ð\8dì\90¬\82·\82é\81B
28  *
29  * \8eQ\8dl\83T\83C\83g
30  * http://www.metaseq.net/metaseq/format.html
31  */
32
33 #ifndef MESH_IO_MQO_H_INCLUDED
34 #define MESH_IO_MQO_H_INCLUDED 
35
36 #include <iosfwd>
37 #include <vector>
38 #include "la.h"
39 #include "color.h"
40 #include "text.h"
41
42 namespace meshio {
43 namespace mqo {
44
45 typedef ::meshio::la::Vector2 Vector2;
46 typedef ::meshio::la::Vector3 Vector3;
47 typedef ::meshio::la::Vector4 Vector4;
48 typedef ::meshio::color::fRGBA RGBA;
49
50 //! Scene\83`\83\83\83\93\83N
51 struct Scene
52 {
53         Vector3 pos;
54         Vector3 lookat;
55         float head;
56         float pitch;
57         int ortho;
58         float zoom2;
59         Vector3 ambient;
60         Scene()
61                 : head(0), pitch(0), ortho(false), zoom2(2)
62                 {}
63 };
64 inline std::ostream &operator<<(std::ostream &os, const Scene &rhs)
65 {
66         os
67                 << "<Scene"
68                 << " pos: " << rhs.pos
69                 << ", lookat: " << rhs.lookat
70                 << ", head: " << rhs.head
71                 << ", pitch: " << rhs.pitch
72                 << ", ortho: " << rhs.ortho
73                 << ", zoom2: " << rhs.zoom2
74                 << ", ambient: " << rhs.ambient
75                 << ">"
76                 ;
77         return os;
78 }
79
80 //! Material\83`\83\83\83\93\83N
81 struct Material
82 {
83         std::string name;
84         int shader;
85         RGBA color;
86         float diffuse;
87         float ambient;
88         float emmit;
89         float specular;
90         float power;
91         std::string texture;
92         std::string alphamap;
93         std::string bumpmap;
94         int vcol;
95
96         Material()
97                 : shader(0), diffuse(1), ambient(0), emmit(0), specular(0), power(0),
98                 vcol(0)
99                 {}
100 };
101 inline std::ostream &operator<<(std::ostream &os, const Material &rhs)
102 {
103         os
104                 << "<Material "
105                 << '"' << rhs.name << '"'
106                 << " shader:" << rhs.shader
107                 << ", color:" << rhs.color
108                 << ", diffuse:" << rhs.diffuse
109                 << ", ambient:" << rhs.ambient
110                 << ", emmit:" << rhs.emmit
111                 << ", specular:" << rhs.specular
112                 << ", power:" << rhs.power
113                 << ", texture:\"" << rhs.texture << '"'
114                 << ", alphamap:\"" << rhs.alphamap << '"'
115                 << ", bumpmap:\"" << rhs.bumpmap << '"'
116                 << ">"
117                 ;
118         return os;
119 }
120
121 //! face\83`\83\83\83\93\83N
122 struct Face
123 {
124         unsigned int index_count;
125         unsigned int indices[4];
126         unsigned int material_index;
127         Vector2 uv[4];
128         RGBA color[4];
129         Face()
130                 : index_count(0), material_index(0)
131                 {
132                         indices[0]=0;
133                         indices[1]=0;
134                         indices[2]=0;
135                         indices[3]=0;
136                         uv[0]=Vector2();
137                         uv[1]=Vector2();
138                         uv[2]=Vector2();
139                         uv[3]=Vector2();
140                 }
141         int getIndex(int i){ return indices[i]; }
142         Vector2 getUV(int i){ return uv[i]; }
143 };
144 inline std::ostream &operator<<(std::ostream &os, const Face &rhs)
145 {
146         switch(rhs.index_count)
147         {
148         case 2:
149                 os
150                         << "<Edge "
151                         << "indices:{" << rhs.indices[0] << ',' << rhs.indices[1] << "}"
152                         << ", material_index: " << rhs.material_index
153                         << ", uv:{" << rhs.uv[0] << ',' << rhs.uv[1] << "}"
154                         << ", color:{" << rhs.color[0] << ',' << rhs.color[1] << "}"
155                         << ">"
156                         ;
157                 break;
158
159         case 3:
160                 os
161                         << "<Triangle "
162                         << "indices:{" << rhs.indices[0] 
163                         << ',' << rhs.indices[1] 
164                         << ',' << rhs.indices[2] << "}"
165                         << ", material_index: " << rhs.material_index
166                         << ", uv:{" << rhs.uv[0] << ',' << rhs.uv[1] << ',' << rhs.uv[2] << "}"
167                         << ", color:{" 
168                         << rhs.color[0] << ',' << rhs.color[1] << ',' <<  rhs.color[2] << "}"
169                         << ">"
170                         ;
171                 break;
172
173         case 4:
174                 os
175                         << "<Rectangle "
176                         << "indices:{" << rhs.indices[0] 
177                         << ',' << rhs.indices[1] 
178                         << ',' << rhs.indices[2] 
179                         << ',' << rhs.indices[3] << "}"
180                         << ", material_index: " << rhs.material_index
181                         << ", uv:{" << rhs.uv[0] << ',' << rhs.uv[1] 
182                         << ',' <<  rhs.uv[2] << ',' << rhs.uv[3] << "}"
183                         << ", color:{" << rhs.color[0] 
184                         << ',' << rhs.color[1] 
185                         << ',' <<  rhs.color[2] 
186                         << ',' <<  rhs.color[3] << "}"
187                         << ">"
188                         ;
189                 break;
190         default:
191                 assert(false);
192         }
193
194         return os;
195 }
196
197 //! Object\83`\83\83\83\93\83N
198 struct Object
199 {
200         std::string name;
201         int depth;
202         int folding;
203         Vector3 scale;
204         Vector3 rotation;
205         Vector3 translation;
206         int visible;
207         int locking;
208         int shading;
209         float smoothing;
210         Vector3 color;
211         int color_type;
212         int mirror;
213
214         std::vector<Vector3> vertices;
215         std::vector<Face> faces;
216
217         Object()
218                 : mirror(0)
219         {}
220 };
221 inline std::ostream &operator<<(std::ostream &os, const Object &rhs)
222 {
223         os
224                 << "<Object "
225                 << '"' << rhs.name << '"'
226                 << " vertices:" << rhs.vertices.size()
227                 << ", faces:" << rhs.faces.size()
228                 << ">"
229                 ;
230         return os;
231 }
232
233 ///////////////////////////////////////////////////////////////////////////////
234 // IO
235 ///////////////////////////////////////////////////////////////////////////////
236 struct IO
237 {
238         Scene scene;
239         std::vector<Material> materials;
240         std::vector<Object> objects;
241
242         bool read(binary::IReader &reader);
243         bool read(const char *path);
244         bool write(std::ostream &os);
245 };
246
247 } // namespace mqo
248 } // namespace meshio
249
250 #endif // MESH_IO_MQO_H_INCLUDED