OSDN Git Service

modify javadoc format.
[mikutoga/TogaGem.git] / src / main / java / jp / sfjp / mikutoga / vmd / parser / VmdLightingParser.java
1 /*
2  * VMD lighting data parser
3  *
4  * License : The MIT License
5  * Copyright(c) 2011 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
15 /**
16  * VMDモーションファイルのライティング情報パーサ。
17  * 照明光源演出データと影演出データを含む。
18  *
19  * <p>古い版のVMDファイルには影演出データが記述されていない場合がある。
20  */
21 class VmdLightingParser extends ProxyParser {
22
23     private VmdLightingHandler handler = VmdUnifiedHandler.EMPTY;
24
25
26     /**
27      * コンストラクタ。
28      * @param parser 委譲先パーサ
29      */
30     VmdLightingParser(BinParser parser){
31         super(parser);
32         return;
33     }
34
35
36     /**
37      * ライティング情報通知用ハンドラを登録する。
38      * @param lightingHandler ハンドラ
39      */
40     void setLightingHandler(VmdLightingHandler lightingHandler){
41         if(lightingHandler == null){
42             this.handler = VmdUnifiedHandler.EMPTY;
43         }else{
44             this.handler = lightingHandler;
45         }
46
47         return;
48     }
49
50     /**
51      * ライティングデータのパースと通知。
52      *
53      * <p>影演出データが無ければ読みに行かない。
54      *
55      * @throws IOException IOエラー
56      * @throws MmdFormatException フォーマットエラー
57      */
58     void parse() throws IOException, MmdFormatException {
59         parseVmdLighting();
60         if(hasMore()){
61             parseVmdShadow();
62         }
63         return;
64     }
65
66     /**
67      * 光源モーションデータのパースと通知。
68      * @throws IOException IOエラー
69      * @throws MmdFormatException フォーマットエラー
70      */
71     private void parseVmdLighting() throws IOException, MmdFormatException{
72         int lightMotionNo = parseLeInt();
73
74         this.handler.loopStart(VmdLightingHandler.LUMINOUS_LIST,
75                 lightMotionNo);
76
77         for(int ct = 0; ct < lightMotionNo; ct++){
78             int keyFrameNo = parseLeInt();
79             this.handler.vmdLuminousMotion(keyFrameNo);
80
81             float rVal = parseLeFloat();
82             float gVal = parseLeFloat();
83             float bVal = parseLeFloat();
84             this.handler.vmdLuminousColor(rVal, gVal, bVal);
85
86             float xVec = parseLeFloat();
87             float yVec = parseLeFloat();
88             float zVec = parseLeFloat();
89             this.handler.vmdLuminousDirection(xVec, yVec, zVec);
90
91             this.handler.loopNext(VmdLightingHandler.LUMINOUS_LIST);
92         }
93
94         this.handler.loopEnd(VmdLightingHandler.LUMINOUS_LIST);
95
96         return;
97     }
98
99     /**
100      * 影演出データのパースと通知。
101      * @throws IOException IOエラー
102      * @throws MmdFormatException フォーマットエラー
103      */
104     private void parseVmdShadow() throws IOException, MmdFormatException{
105         int shadowMotionNo = parseLeInt();
106
107         this.handler.loopStart(VmdLightingHandler.SHADOW_LIST,
108                 shadowMotionNo);
109
110         for(int ct = 0; ct < shadowMotionNo; ct++){
111             int keyFrameNo = parseLeInt();
112             this.handler.vmdShadowMotion(keyFrameNo);
113
114             byte shadowMode = parseByte();
115             this.handler.vmdShadowMode(shadowMode);
116
117             float shadowScope = parseLeFloat();
118             this.handler.vmdShadowScopeRaw(shadowScope);
119
120             this.handler.loopNext(VmdLightingHandler.SHADOW_LIST);
121         }
122
123         this.handler.loopEnd(VmdLightingHandler.SHADOW_LIST);
124
125         return;
126     }
127
128 }