OSDN Git Service

fixed by @santarh
[meshio/meshio.git] / src / 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 <assert.h>
39 #include "la.h"
40 #include "color.h"
41 #include "text.h"
42 #include "binary.h"
43
44 namespace meshio {
45   namespace mqo {
46
47     //! Scene\83`\83\83\83\93\83N
48     struct Scene
49     {
50       meshio::Vector3 pos;
51       meshio::Vector3 lookat;
52       float head;
53       float pitch;
54       int ortho;
55       float zoom2;
56       meshio::Vector3 ambient;
57       Scene()
58         : head(0), pitch(0), ortho(false), zoom2(2)
59       {}
60     };
61     inline std::ostream &operator<<(std::ostream &os, const Scene &rhs)
62     {
63       os
64         << "<Scene"
65         << " pos: " << rhs.pos
66         << ", lookat: " << rhs.lookat
67         << ", head: " << rhs.head
68         << ", pitch: " << rhs.pitch
69         << ", ortho: " << rhs.ortho
70         << ", zoom2: " << rhs.zoom2
71         << ", ambient: " << rhs.ambient
72         << ">"
73         ;
74       return os;
75     }
76
77     //! Material\83`\83\83\83\93\83N
78     struct Material
79     {
80       std::string name;
81       int shader;
82       meshio::fRGBA color;
83       float diffuse;
84       float ambient;
85       float emit;
86       float specular;
87       float power;
88       std::string texture;
89       std::string alphamap;
90       std::string bumpmap;
91       int vcol;
92
93       Material()
94         : shader(0), diffuse(1), ambient(0), emit(0), specular(0), power(0),
95         vcol(0)
96       {}
97     };
98     inline std::ostream &operator<<(std::ostream &os, const Material &rhs)
99     {
100       os
101         << "<Material "
102         << '"' << rhs.name << '"'
103         << " shader:" << rhs.shader
104         << ", color:" << rhs.color
105         << ", diffuse:" << rhs.diffuse
106         << ", ambient:" << rhs.ambient
107         << ", emit:" << rhs.emit
108         << ", specular:" << rhs.specular
109         << ", power:" << rhs.power
110         << ", texture:\"" << rhs.texture << '"'
111         << ", alphamap:\"" << rhs.alphamap << '"'
112         << ", bumpmap:\"" << rhs.bumpmap << '"'
113         << ">"
114         ;
115       return os;
116     }
117
118     //! face\83`\83\83\83\93\83N
119     struct Face
120     {
121       unsigned int index_count;
122       unsigned int indices[4];
123       unsigned int material_index;
124       meshio::Vector2 uv[4];
125       meshio::fRGBA color[4];
126       Face()
127         : index_count(0), material_index(0)
128       {
129         indices[0]=0;
130         indices[1]=0;
131         indices[2]=0;
132         indices[3]=0;
133         uv[0]=Vector2();
134         uv[1]=Vector2();
135         uv[2]=Vector2();
136         uv[3]=Vector2();
137       }
138     };
139     inline std::ostream &operator<<(std::ostream &os, const Face &rhs)
140     {
141       switch(rhs.index_count)
142       {
143         case 2:
144           os
145             << "<Edge "
146             << "indices:{" << rhs.indices[0] << ',' << rhs.indices[1] << "}"
147             << ", material_index: " << rhs.material_index
148             << ", uv:{" << rhs.uv[0] << ',' << rhs.uv[1] << "}"
149             << ", color:{" << rhs.color[0] << ',' << rhs.color[1] << "}"
150             << ">"
151             ;
152           break;
153
154         case 3:
155           os
156             << "<Triangle "
157             << "indices:{" << rhs.indices[0] 
158             << ',' << rhs.indices[1] 
159             << ',' << rhs.indices[2] << "}"
160             << ", material_index: " << rhs.material_index
161             << ", uv:{" << rhs.uv[0] << ',' << rhs.uv[1] << ',' << rhs.uv[2] << "}"
162             << ", color:{" 
163             << rhs.color[0] << ',' << rhs.color[1] << ',' <<  rhs.color[2] << "}"
164             << ">"
165             ;
166           break;
167
168         case 4:
169           os
170             << "<Rectangle "
171             << "indices:{" << rhs.indices[0] 
172             << ',' << rhs.indices[1] 
173             << ',' << rhs.indices[2] 
174             << ',' << rhs.indices[3] << "}"
175             << ", material_index: " << rhs.material_index
176             << ", uv:{" << rhs.uv[0] << ',' << rhs.uv[1] 
177             << ',' <<  rhs.uv[2] << ',' << rhs.uv[3] << "}"
178             << ", color:{" << rhs.color[0] 
179             << ',' << rhs.color[1] 
180             << ',' <<  rhs.color[2] 
181             << ',' <<  rhs.color[3] << "}"
182             << ">"
183             ;
184           break;
185         default:
186           assert(false);
187       }
188
189       return os;
190     }
191
192     //! Object\83`\83\83\83\93\83N
193     struct Object
194     {
195       std::string name;
196       int depth;
197       int folding;
198       meshio::Vector3 scale;
199       meshio::Vector3 rotation;
200       meshio::Vector3 translation;
201       int visible;
202       int locking;
203       int shading;
204       float smoothing;
205       meshio::Vector3 color;
206       int color_type;
207       int mirror;
208
209       std::vector<meshio::Vector3> vertices;
210       std::vector<Face> faces;
211
212       Object()
213         : depth(0), folding(0), visible(1), locking(0), shading(0), 
214         smoothing(60.0f), color_type(0), mirror(0)
215       {}
216     };
217     inline std::ostream &operator<<(std::ostream &os, const Object &rhs)
218     {
219       os
220         << "<Object "
221         << '"' << rhs.name << '"'
222         << " vertices:" << rhs.vertices.size()
223         << ", faces:" << rhs.faces.size()
224         << ">"
225         ;
226       return os;
227     }
228
229     // IO
230     struct IO
231     {
232       Scene scene;
233       std::vector<Material> materials;
234       std::vector<Object> objects;
235
236       bool read(meshio::binary::IReader &reader);
237       bool read(const char *path);
238       bool write(meshio::binary::IWriter &writer);
239       bool write(const char *path);
240     };
241
242   } // namespace mqo
243 } // namespace meshio
244
245 #endif // MESH_IO_MQO_H_INCLUDED