OSDN Git Service

export toon textures.
[meshio/meshio.git] / include / vmd.h
1 /**
2  * VMD\8c`\8e®
3  * MMD\82Ì\83\82\81[\83V\83\87\83\93\83f\81[\83^\81B
4  * \83o\83C\83i\83\8a\8c`\8e®\82Å\83{\81[\83\93\83\82\81[\83V\83\87\83\93\81A\95\\8fî\83\82\81[\83t\83B\83\93\83O\81A\8cõ\8c¹\81A\89e\82Ì\83L\81[\83t\83\8c\81[\83\80\82ª
5  * \8bL\98^\82³\82ê\82é\81B
6  *
7  * \8eQ\8dl\83T\83C\83g
8  * http://blog.goo.ne.jp/torisu_tetosuki/e/bc9f1c4d597341b394bd02b64597499d
9  * http://atupdate.web.fc2.com/vmd_format.htm
10  */
11
12 #ifndef MESH_IO_VMD_H_INCLUDED
13 #define MESH_IO_VMD_H_INCLUDED 
14
15 #include <ostream>
16 #include <vector>
17 #include <map>
18 #include "la.h"
19 #include "color.h"
20 #include "binary.h"
21
22 namespace meshio {
23 namespace vmd {
24
25 typedef ::meshio::la::Vector2 Vector2;
26 typedef ::meshio::la::Vector3 Vector3;
27 typedef ::meshio::la::Quaternion Quaternion;
28 typedef ::meshio::color::fRGB fRGB;
29
30 ////////////////////////////////////////////////////////////
31 //! \83\82\81[\83V\83\87\83\93
32 ////////////////////////////////////////////////////////////
33 struct BoneKey
34 {
35         Vector3 pos;
36         Quaternion q;
37         char interpolationX[16];
38         char interpolationY[16];
39         char interpolationZ[16];
40         char interpolationRot[16];
41 };
42 inline std::ostream& operator<<(std::ostream &os, const BoneKey &rhs)
43 {
44         return os
45                 << "<BoneKey: " << rhs.pos << rhs.q << ">" 
46                 ;
47 }
48
49 ////////////////////////////////////////////////////////////
50 //! \95\\8fî
51 ////////////////////////////////////////////////////////////
52 struct MorphKey
53 {
54         float weight;
55 };
56 inline std::ostream& operator<<(std::ostream &os, const MorphKey &rhs)
57 {
58         return os
59                 << "<MorphKey: " << rhs.weight << ">" 
60                 ;
61 }
62
63
64 ////////////////////////////////////////////////////////////
65 //! \83J\83\81\83\89
66 ////////////////////////////////////////////////////////////
67 struct CameraKey
68 {
69         //! \89½\82Ì\8b\97\97£\81H
70         float length;
71         //! \88Ê\92u
72         Vector3 pos;
73         //! \83I\83C\83\89\81[\8ap
74         Vector3 euler;
75         //! \95â\8aÔ
76         char interpolation[24];
77         //! \8e\8b\96ì\8ap
78         unsigned short viewAngle;
79         //! \89\93\8bß\8a´ 0\82ªon
80         unsigned char perspective;
81 };
82 inline std::ostream& operator<<(std::ostream &os, const CameraKey &rhs)
83 {
84         return os
85                 << "<CameraKey: " << rhs.length 
86                 << rhs.pos << rhs.euler << ">" 
87                 ;
88 }
89
90
91 ////////////////////////////////////////////////////////////
92 //! \8cõ\8c¹
93 ////////////////////////////////////////////////////////////
94 struct LightKey
95 {
96         fRGB color;
97         Vector3 pos;
98 };
99 inline std::ostream& operator<<(std::ostream &os, const LightKey &rhs)
100 {
101         return os
102                 << "<LightKey: " << rhs.color << rhs.pos << ">" 
103                 ;
104 }
105
106
107 ////////////////////////////////////////////////////////////
108 //! \83Z\83\8b\83t\83V\83\83\83h\83E
109 ////////////////////////////////////////////////////////////
110 struct SelfShadowKey
111 {
112 };
113
114 ////////////////////////////////////////////////////////////
115 //! KeyFrame
116 ////////////////////////////////////////////////////////////
117 template<typename T>
118 struct KeyFrame
119 {
120         typedef T VALUE_TYPE;
121
122         //! \83t\83\8c\81[\83\80\94Ô\8d\86
123         unsigned int frame;
124         //! \83L\81[
125         T key;
126
127         //! \83t\83\8c\81[\83\80\94Ô\8d\86\82Å\83L\81[\82ð\83\\81[\83g\82·\82é
128         bool operator<(const KeyFrame &rhs)const{ return frame<rhs.frame; }
129 };
130
131 ////////////////////////////////////////////////////////////
132 //! 1\83`\83\83\83\93\83l\83\8b\95ª\82Ì\83L\81[\83t\83\8c\81[\83\80\82Ì\83\8a\83X\83g\81B
133 //! \93Ç\82Ý\8d\9e\82ñ\82¾\8cã\82Å\83t\83\8c\81[\83\80\94Ô\8d\86\82Å\83\\81[\83g\82·\82é\81B
134 ////////////////////////////////////////////////////////////
135 template<typename T>
136 struct KeyFrameList
137 {
138         typedef T KEYFRAME_TYPE;
139
140         std::vector<KEYFRAME_TYPE> list;
141         void sort(){ std::sort(list.begin(), list.end()); }
142     KEYFRAME_TYPE& push(unsigned int frame)
143         {
144                 list.push_back(KEYFRAME_TYPE());
145                 KEYFRAME_TYPE &keyFrame=list.back();
146                 keyFrame.frame=frame;
147                 return keyFrame;
148         }
149         unsigned int getFrame(int index)
150         {
151                 return list[index].frame;
152         }
153         typename KEYFRAME_TYPE::VALUE_TYPE* getKey(int index)
154         {
155                 return &list[index].key;
156         }
157 };
158
159 ////////////////////////////////////////////////////////////
160 //! IO
161 ////////////////////////////////////////////////////////////
162 typedef KeyFrame<BoneKey> BoneKeyFrame;
163 typedef KeyFrameList<BoneKeyFrame> BoneKeyFrameList;
164
165 typedef KeyFrame<MorphKey> MorphKeyFrame;
166 typedef KeyFrameList<MorphKeyFrame> MorphKeyFrameList;
167
168 struct IO
169 {
170         std::string version;
171         char name[20];
172
173         //! \83\82\81[\83V\83\87\83\93
174         typedef std::map<std::wstring, BoneKeyFrameList*> BoneMap;
175         BoneMap boneMap;
176         std::vector<std::wstring> boneKeys;
177
178         //! \95\\8fî
179         typedef std::map<std::wstring, MorphKeyFrameList*> MorphMap;
180         MorphMap morphMap;
181         std::vector<std::wstring> morphKeys;
182
183         IO();
184         ~IO();
185         bool read(binary::IReader &reader);
186         bool read(const wchar_t *path);
187         bool read(const char *path);
188         bool write(std::ostream &os);
189
190         BoneKeyFrameList* getBoneKeyFrameList(const std::wstring &name);
191         MorphKeyFrameList* getMorphKeyFrameList(const std::wstring &name);
192 };
193 inline std::ostream& operator<<(std::ostream &os, const IO &rhs)
194 {
195         os
196                 << "<VMD " << rhs.name << std::endl
197                 << "[bones] " << rhs.boneMap.size() << std::endl
198                 << "[morphs] " << rhs.morphMap.size() << std::endl
199                 << ">"
200                 ;
201         return os;
202 }
203
204 } // namespace vmd
205 } // namespace meshio
206
207 #endif // MESH_IO_VMD_H_INCLUDED