OSDN Git Service

fix setup.py.
[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         // for python3 unicode
102         std::wstring getName()const;
103         std::wstring getTexture()const;
104 };
105 inline std::ostream &operator<<(std::ostream &os, const Material &rhs)
106 {
107         os
108                 << "<Material "
109                 << '"' << rhs.name << '"'
110                 << " shader:" << rhs.shader
111                 << ", color:" << rhs.color
112                 << ", diffuse:" << rhs.diffuse
113                 << ", ambient:" << rhs.ambient
114                 << ", emmit:" << rhs.emmit
115                 << ", specular:" << rhs.specular
116                 << ", power:" << rhs.power
117                 << ", texture:\"" << rhs.texture << '"'
118                 << ", alphamap:\"" << rhs.alphamap << '"'
119                 << ", bumpmap:\"" << rhs.bumpmap << '"'
120                 << ">"
121                 ;
122         return os;
123 }
124
125 //! face\83`\83\83\83\93\83N
126 struct Face
127 {
128         unsigned int index_count;
129         unsigned int indices[4];
130         unsigned int material_index;
131         Vector2 uv[4];
132         RGBA color[4];
133         Face()
134                 : index_count(0), material_index(0)
135                 {
136                         indices[0]=0;
137                         indices[1]=0;
138                         indices[2]=0;
139                         indices[3]=0;
140                         uv[0]=Vector2();
141                         uv[1]=Vector2();
142                         uv[2]=Vector2();
143                         uv[3]=Vector2();
144                 }
145         int getIndex(int i){ return indices[i]; }
146         Vector2 getUV(int i){ return uv[i]; }
147 };
148 inline std::ostream &operator<<(std::ostream &os, const Face &rhs)
149 {
150         switch(rhs.index_count)
151         {
152         case 2:
153                 os
154                         << "<Edge "
155                         << "indices:{" << rhs.indices[0] << ',' << rhs.indices[1] << "}"
156                         << ", material_index: " << rhs.material_index
157                         << ", uv:{" << rhs.uv[0] << ',' << rhs.uv[1] << "}"
158                         << ", color:{" << rhs.color[0] << ',' << rhs.color[1] << "}"
159                         << ">"
160                         ;
161                 break;
162
163         case 3:
164                 os
165                         << "<Triangle "
166                         << "indices:{" << rhs.indices[0] 
167                         << ',' << rhs.indices[1] 
168                         << ',' << rhs.indices[2] << "}"
169                         << ", material_index: " << rhs.material_index
170                         << ", uv:{" << rhs.uv[0] << ',' << rhs.uv[1] << ',' << rhs.uv[2] << "}"
171                         << ", color:{" 
172                         << rhs.color[0] << ',' << rhs.color[1] << ',' <<  rhs.color[2] << "}"
173                         << ">"
174                         ;
175                 break;
176
177         case 4:
178                 os
179                         << "<Rectangle "
180                         << "indices:{" << rhs.indices[0] 
181                         << ',' << rhs.indices[1] 
182                         << ',' << rhs.indices[2] 
183                         << ',' << rhs.indices[3] << "}"
184                         << ", material_index: " << rhs.material_index
185                         << ", uv:{" << rhs.uv[0] << ',' << rhs.uv[1] 
186                         << ',' <<  rhs.uv[2] << ',' << rhs.uv[3] << "}"
187                         << ", color:{" << rhs.color[0] 
188                         << ',' << rhs.color[1] 
189                         << ',' <<  rhs.color[2] 
190                         << ',' <<  rhs.color[3] << "}"
191                         << ">"
192                         ;
193                 break;
194         default:
195                 assert(false);
196         }
197
198         return os;
199 }
200
201 //! Object\83`\83\83\83\93\83N
202 struct Object
203 {
204         std::string name;
205         int depth;
206         int folding;
207         Vector3 scale;
208         Vector3 rotation;
209         Vector3 translation;
210         int visible;
211         int locking;
212         int shading;
213         float smoothing;
214         Vector3 color;
215         int color_type;
216         int mirror;
217
218         std::vector<Vector3> vertices;
219         std::vector<Face> faces;
220
221         Object()
222                 : depth(0), folding(0), visible(1), locking(0), shading(0), 
223                 smoothing(60.0f), color_type(0), mirror(0)
224         {}
225
226         std::wstring getName()const;
227 };
228 inline std::ostream &operator<<(std::ostream &os, const Object &rhs)
229 {
230         os
231                 << "<Object "
232                 << '"' << rhs.name << '"'
233                 << " vertices:" << rhs.vertices.size()
234                 << ", faces:" << rhs.faces.size()
235                 << ">"
236                 ;
237         return os;
238 }
239
240 ///////////////////////////////////////////////////////////////////////////////
241 // IO
242 ///////////////////////////////////////////////////////////////////////////////
243 struct IO
244 {
245         Scene scene;
246         std::vector<Material> materials;
247         std::vector<Object> objects;
248
249         bool read(binary::IReader &reader);
250         bool read(const char *path);
251 //#ifdef _WIN32
252         bool read(const wchar_t *path);
253 //#endif
254         bool write(binary::IWriter &writer);
255         bool write(const char *path);
256 };
257
258 } // namespace mqo
259 } // namespace meshio
260
261 #endif // MESH_IO_MQO_H_INCLUDED