OSDN Git Service

Merge release/v2.103.2
[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  *
23  * <p>MikuMikuDance Ver7.40以降でサポート
24  */
25 class BoolExporter extends BinaryExporter{
26
27     private static final byte[] FDFILLER =
28         { (byte)0x00, (byte)0xfd };
29
30
31     /**
32      * コンストラクタ。
33      *
34      * @param stream 出力ストリーム
35      */
36     BoolExporter(OutputStream stream){
37         super(stream);
38         return;
39     }
40
41
42     /**
43      * フラグ情報を出力する。
44      *
45      * @param motion モーションデータ
46      * @throws IOException 出力エラー
47      * @throws IllegalTextExportException 不正な文字列が指定された。
48      */
49     void dumpNumberedFlagMotion(VmdMotion motion)
50             throws IOException, IllegalTextExportException {
51         List<NumberedVmdFlag> list = motion.getNumberedFlagList();
52
53         if(list.isEmpty()) return;
54
55         int count = list.size();
56         dumpLeInt(count);
57
58         for(NumberedVmdFlag flag : list){
59             int frameNo = flag.getFrameNumber();
60             dumpLeInt(frameNo);
61
62             byte showModel;
63             if(flag.isModelShown()) showModel = 0x01;
64             else                    showModel = 0x00;
65             dumpByte(showModel);
66
67             dumpIkSwitch(flag);
68         }
69
70
71         return;
72     }
73
74     /**
75      * IK有効フラグを出力する。
76      *
77      * @param flag フラグ情報
78      * @throws IOException 出力エラー
79      * @throws IllegalTextExportException 不正な文字列が指定された。
80      */
81     private void dumpIkSwitch(NumberedVmdFlag flag)
82             throws IOException, IllegalTextExportException {
83         List<IkSwitch> swList = flag.getIkSwitchList();
84         int swNo = swList.size();
85         dumpLeInt(swNo);
86
87         for(IkSwitch ikSwitch : swList){
88             String boneName = ikSwitch.getBoneName();
89             dumpFixedW31j(boneName, VmdConst.IKSWBONENAME_MAX, FDFILLER);
90
91             byte ikValid;
92             if(ikSwitch.isValid()) ikValid = 0x01;
93             else                   ikValid = 0x00;
94             dumpByte(ikValid);
95         }
96
97         return;
98     }
99
100 }