OSDN Git Service

MMD Ver7.40 対応 新スキーマ開発開始
[mikutoga/Vmd2XML.git] / src / main / java / jp / sfjp / mikutoga / vmd / model / binio / BoolExporter.java
1 /*
2  * boolean information exporter
3  *
4  * License : The MIT License
5  * Copyright(c) 2013 MikuToga Partners
6  */
7
8 package jp.sfjp.mikutoga.vmd.model.binio;
9
10 import java.io.IOException;
11 import java.io.OutputStream;
12 import java.util.List;
13 import jp.sfjp.mikutoga.bin.export.BinaryExporter;
14 import jp.sfjp.mikutoga.bin.export.IllegalTextExportException;
15 import jp.sfjp.mikutoga.vmd.VmdConst;
16 import jp.sfjp.mikutoga.vmd.model.IkSwitch;
17 import jp.sfjp.mikutoga.vmd.model.NumberedVmdFlag;
18 import jp.sfjp.mikutoga.vmd.model.VmdMotion;
19
20 /**
21  * フラグ情報のエクスポーター。
22  * <p>MikuMikuDance Ver7.40以降でサポート
23  */
24 class BoolExporter extends BinaryExporter{
25
26     private static final byte[] FDFILLER =
27         { (byte)0x00, (byte)0xfd };
28
29
30     /**
31      * コンストラクタ。
32      * @param stream 出力ストリーム
33      */
34     BoolExporter(OutputStream stream){
35         super(stream);
36         return;
37     }
38
39
40     /**
41      * フラグ情報を出力する。
42      * @param motion モーションデータ
43      * @throws IOException 出力エラー
44      * @throws IllegalTextExportException 不正な文字列が指定された。
45      */
46     void dumpNumberedFlagMotion(VmdMotion motion)
47             throws IOException, IllegalTextExportException {
48         List<NumberedVmdFlag> list = motion.getNumberedFlagList();
49
50         if(list.isEmpty()) return;
51
52         int count = list.size();
53         dumpLeInt(count);
54
55         for(NumberedVmdFlag flag : list){
56             int frameNo = flag.getFrameNumber();
57             dumpLeInt(frameNo);
58
59             byte showModel;
60             if(flag.isModelShown()) showModel = 0x01;
61             else                    showModel = 0x00;
62             dumpByte(showModel);
63
64             dumpIkSwitch(flag);
65         }
66
67
68         return;
69     }
70
71     /**
72      * IK有効フラグを出力する。
73      * @param flag フラグ情報
74      * @throws IOException 出力エラー
75      * @throws IllegalTextExportException 不正な文字列が指定された。
76      */
77     private void dumpIkSwitch(NumberedVmdFlag flag)
78             throws IOException, IllegalTextExportException {
79         List<IkSwitch> swList = flag.getIkSwitchList();
80         int swNo = swList.size();
81         dumpLeInt(swNo);
82
83         for(IkSwitch ikSwitch : swList){
84             String boneName = ikSwitch.getBoneName();
85             dumpFixedW31j(boneName, VmdConst.IKSWBONENAME_MAX, FDFILLER);
86
87             byte ikValid;
88             if(ikSwitch.isValid()) ikValid = 0x01;
89             else                   ikValid = 0x00;
90             dumpByte(ikValid);
91         }
92
93         return;
94     }
95
96 }