OSDN Git Service

モデルデータ不備の異常系を別パッケージに
[mikutoga/TogaGem.git] / src / main / java / jp / sourceforge / mikutoga / vmd / model / binio / LightingLoader.java
1 /*
2  * lighting information builder
3  *
4  * License : The MIT License
5  * Copyright(c) 2011 MikuToga Partners
6  */
7
8 package jp.sourceforge.mikutoga.vmd.model.binio;
9
10 import java.util.List;
11 import jp.sourceforge.mikutoga.parser.MmdFormatException;
12 import jp.sourceforge.mikutoga.parser.ParseStage;
13 import jp.sourceforge.mikutoga.vmd.model.LuminousColor;
14 import jp.sourceforge.mikutoga.vmd.model.LuminousMotion;
15 import jp.sourceforge.mikutoga.vmd.model.LuminousVector;
16 import jp.sourceforge.mikutoga.vmd.model.ShadowMode;
17 import jp.sourceforge.mikutoga.vmd.model.ShadowMotion;
18 import jp.sourceforge.mikutoga.vmd.model.VmdMotion;
19 import jp.sourceforge.mikutoga.vmd.parser.VmdLightingHandler;
20
21 /**
22  * ライティング情報のビルダ。
23  */
24 class LightingLoader implements VmdLightingHandler {
25
26     private final List<LuminousMotion> luminousMotionList;
27     private final List<ShadowMotion> shadowMotionList;
28
29     private LuminousMotion currentLuminousMotion;
30     private ShadowMotion currentShadowMotion;
31
32
33     /**
34      * コンストラクタ。
35      * @param vmdMotion モーションデータ。
36      */
37     LightingLoader(VmdMotion vmdMotion){
38         super();
39
40         this.luminousMotionList = vmdMotion.getLuminousMotionList();
41         this.shadowMotionList   = vmdMotion.getShadowMotionList();
42
43         this.currentLuminousMotion = null;
44         this.currentShadowMotion = null;
45
46         return;
47     }
48
49
50     /**
51      * 照明ループか否か判定する。
52      * @param stage 判定対象
53      * @return 照明ループならtrue
54      */
55     private static boolean isLuminousList(ParseStage stage){
56         if(stage == VmdLightingHandler.LUMINOUS_LIST) return true;
57         return false;
58     }
59
60     /**
61      * シャドウループか否か判定する。
62      * @param stage 判定対象
63      * @return シャドウループならtrue
64      */
65     private static boolean isShadowList(ParseStage stage){
66         if(stage == VmdLightingHandler.SHADOW_LIST) return true;
67         return false;
68     }
69
70
71     /**
72      * {@inheritDoc}
73      * @param stage {@inheritDoc}
74      * @param loops {@inheritDoc}
75      * @throws MmdFormatException {@inheritDoc}
76      */
77     @Override
78     public void loopStart(ParseStage stage, int loops)
79             throws MmdFormatException{
80         if(isLuminousList(stage)){
81             this.currentLuminousMotion = new LuminousMotion();
82         }else if(isShadowList(stage)){
83             this.currentShadowMotion = new ShadowMotion();
84         }
85
86         return;
87     }
88
89     /**
90      * {@inheritDoc}
91      * @param stage {@inheritDoc}
92      * @throws MmdFormatException {@inheritDoc}
93      */
94     @Override
95     public void loopNext(ParseStage stage)
96             throws MmdFormatException{
97         if(isLuminousList(stage)){
98             this.luminousMotionList.add(this.currentLuminousMotion);
99             this.currentLuminousMotion = new LuminousMotion();
100         }else if(isShadowList(stage)){
101             this.shadowMotionList.add(this.currentShadowMotion);
102             this.currentShadowMotion = new ShadowMotion();
103         }
104         return;
105     }
106
107     /**
108      * {@inheritDoc}
109      * @param stage {@inheritDoc}
110      * @throws MmdFormatException {@inheritDoc}
111      */
112     @Override
113     public void loopEnd(ParseStage stage)
114             throws MmdFormatException{
115         if(isLuminousList(stage)){
116             this.currentLuminousMotion = null;
117         }else if(isShadowList(stage)){
118             this.currentShadowMotion = null;
119         }
120         return;
121     }
122
123     /**
124      * {@inheritDoc}
125      * @param keyFrameNo {@inheritDoc}
126      * @throws MmdFormatException {@inheritDoc}
127      */
128     @Override
129     public void vmdLuminousMotion(int keyFrameNo) throws MmdFormatException{
130         this.currentLuminousMotion.setFrameNumber(keyFrameNo);
131         return;
132     }
133
134     /**
135      * {@inheritDoc}
136      * @param rVal {@inheritDoc}
137      * @param gVal {@inheritDoc}
138      * @param bVal {@inheritDoc}
139      * @throws MmdFormatException {@inheritDoc}
140      */
141     @Override
142     public void vmdLuminousColor(float rVal, float gVal, float bVal)
143             throws MmdFormatException{
144         LuminousColor color = this.currentLuminousMotion.getColor();
145         color.setColR(rVal);
146         color.setColG(gVal);
147         color.setColB(bVal);
148         return;
149     }
150
151     /**
152      * {@inheritDoc}
153      * @param xVec {@inheritDoc}
154      * @param yVec {@inheritDoc}
155      * @param zVec {@inheritDoc}
156      * @throws MmdFormatException {@inheritDoc}
157      */
158     @Override
159     public void vmdLuminousDirection(float xVec, float yVec, float zVec)
160             throws MmdFormatException{
161         LuminousVector direction = this.currentLuminousMotion.getDirection();
162         direction.setVecX(xVec);
163         direction.setVecY(yVec);
164         direction.setVecZ(zVec);
165         return;
166     }
167
168     /**
169      * {@inheritDoc}
170      * @param keyFrameNo {@inheritDoc}
171      * @throws MmdFormatException {@inheritDoc}
172      */
173     @Override
174     public void vmdShadowMotion(int keyFrameNo) throws MmdFormatException{
175         this.currentShadowMotion.setFrameNumber(keyFrameNo);
176         return;
177     }
178
179     /**
180      * {@inheritDoc}
181      * @param shadowMode {@inheritDoc}
182      * @throws MmdFormatException {@inheritDoc}
183      */
184     @Override
185     public void vmdShadowMode(byte shadowMode) throws MmdFormatException{
186         ShadowMode mode = ShadowMode.decode(shadowMode);
187         this.currentShadowMotion.setShadowMode(mode);
188         return;
189     }
190
191     /**
192      * {@inheritDoc}
193      * @param shadowScope {@inheritDoc}
194      * @throws MmdFormatException {@inheritDoc}
195      */
196     @Override
197     public void vmdShadowScopeRaw(float shadowScope)
198             throws MmdFormatException{
199         this.currentShadowMotion.setRawScopeParam(shadowScope);
200         return;
201     }
202
203 }