OSDN Git Service

modify javadoc format.
[mikutoga/TogaGem.git] / src / main / java / jp / sfjp / mikutoga / vmd / parser / VmdBoolParser.java
1 /*
2  * VMD boolean data parser
3  *
4  * License : The MIT License
5  * Copyright(c) 2013 MikuToga Partners
6  */
7
8 package jp.sfjp.mikutoga.vmd.parser;
9
10 import java.io.IOException;
11 import jp.sfjp.mikutoga.bin.parser.BinParser;
12 import jp.sfjp.mikutoga.bin.parser.MmdFormatException;
13 import jp.sfjp.mikutoga.bin.parser.ProxyParser;
14 import jp.sfjp.mikutoga.bin.parser.TextDecoder;
15 import jp.sfjp.mikutoga.vmd.VmdConst;
16
17 /**
18  * VMDモーションファイルの各種ON/OFF情報(モデル表示・IK有効無効)
19  * パーサ。
20  *
21  * <p>MikuMikuDance Ver7.40以降でサポート
22  */
23 class VmdBoolParser extends ProxyParser {
24
25     private final TextDecoder decoderWin31j =
26             new TextDecoder(VmdBasicParser.CS_WIN31J);
27
28     private VmdBoolHandler handler = VmdUnifiedHandler.EMPTY;
29
30
31     /**
32      * コンストラクタ。
33      * @param parser 委譲先パーサ
34      */
35     VmdBoolParser(BinParser parser){
36         super(parser);
37         this.decoderWin31j.setZeroChopMode(true);
38         return;
39     }
40
41
42     /**
43      * ON/OFF情報通知用ハンドラを登録する。
44      * @param boolHandler ハンドラ
45      */
46     void setBoolHandler(VmdBoolHandler boolHandler){
47         if(boolHandler == null){
48             this.handler = VmdUnifiedHandler.EMPTY;
49         }else{
50             this.handler = boolHandler;
51         }
52
53         return;
54     }
55
56     /**
57      * データのパースと通知。
58      * @throws IOException IOエラー
59      * @throws MmdFormatException フォーマットエラー
60      */
61     void parse() throws IOException, MmdFormatException {
62         if( ! hasMore() ) return;
63
64         parseVmdModelSight();
65
66         return;
67     }
68
69     /**
70      * モデル表示フラグデータのパースと通知。
71      * @throws IOException IOエラー
72      * @throws MmdFormatException フォーマットエラー
73      */
74     private void parseVmdModelSight()
75             throws IOException, MmdFormatException{
76         int modelSightNo = parseLeInt();
77
78         this.handler.loopStart(VmdBoolHandler.MODELSIGHT_LIST,
79                                modelSightNo );
80
81         for(int ct = 0; ct < modelSightNo; ct++){
82             int keyFrameNo = parseLeInt();
83             boolean show = parseBoolean();
84             this.handler.vmdModelSight(show, keyFrameNo);
85
86             parseVmdIkSwitch(keyFrameNo);
87
88             this.handler.loopNext(VmdBoolHandler.MODELSIGHT_LIST);
89         }
90
91         this.handler.loopEnd(VmdBoolHandler.MODELSIGHT_LIST);
92
93         return;
94     }
95
96     /**
97      * IK有効スイッチデータのパースと通知。
98      * @param keyFrameNo キーフレーム番号
99      * @throws IOException IOエラー
100      * @throws MmdFormatException フォーマットエラー
101      */
102     private void parseVmdIkSwitch(int keyFrameNo)
103             throws IOException, MmdFormatException{
104         int ikSwitchNo = parseLeInt();
105
106         this.handler.loopStart(VmdBoolHandler.IKSW_LIST, ikSwitchNo);
107
108         for(int ct = 0; ct < ikSwitchNo; ct++){
109             String boneName = parseString(this.decoderWin31j,
110                                           VmdConst.IKSWBONENAME_MAX );
111             boolean valid = parseBoolean();
112             this.handler.vmdIkSwitch(boneName, valid, keyFrameNo);
113
114             this.handler.loopNext(VmdBoolHandler.IKSW_LIST);
115         }
116
117         this.handler.loopEnd(VmdBoolHandler.IKSW_LIST);
118
119         return;
120     }
121
122 }