2 * lighting information builder
4 * License : The MIT License
5 * Copyright(c) 2011 MikuToga Partners
8 package jp.sourceforge.mikutoga.vmd.model.binio;
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;
24 class LightingLoader implements VmdLightingHandler {
26 private final List<LuminousMotion> luminousMotionList;
27 private final List<ShadowMotion> shadowMotionList;
29 private LuminousMotion currentLuminousMotion;
30 private ShadowMotion currentShadowMotion;
35 * @param vmdMotion モーションデータ。
37 LightingLoader(VmdMotion vmdMotion){
40 this.luminousMotionList = vmdMotion.getLuminousMotionList();
41 this.shadowMotionList = vmdMotion.getShadowMotionList();
43 this.currentLuminousMotion = null;
44 this.currentShadowMotion = null;
55 private static boolean isLuminousList(ParseStage stage){
56 if(stage == VmdLightingHandler.LUMINOUS_LIST) return true;
63 * @return シャドウループならtrue
65 private static boolean isShadowList(ParseStage stage){
66 if(stage == VmdLightingHandler.SHADOW_LIST) return true;
73 * @param stage {@inheritDoc}
74 * @param loops {@inheritDoc}
75 * @throws MmdFormatException {@inheritDoc}
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();
91 * @param stage {@inheritDoc}
92 * @throws MmdFormatException {@inheritDoc}
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();
109 * @param stage {@inheritDoc}
110 * @throws MmdFormatException {@inheritDoc}
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;
125 * @param keyFrameNo {@inheritDoc}
126 * @throws MmdFormatException {@inheritDoc}
129 public void vmdLuminousMotion(int keyFrameNo) throws MmdFormatException{
130 this.currentLuminousMotion.setFrameNumber(keyFrameNo);
136 * @param rVal {@inheritDoc}
137 * @param gVal {@inheritDoc}
138 * @param bVal {@inheritDoc}
139 * @throws MmdFormatException {@inheritDoc}
142 public void vmdLuminousColor(float rVal, float gVal, float bVal)
143 throws MmdFormatException{
144 LuminousColor color = this.currentLuminousMotion.getColor();
153 * @param xVec {@inheritDoc}
154 * @param yVec {@inheritDoc}
155 * @param zVec {@inheritDoc}
156 * @throws MmdFormatException {@inheritDoc}
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);
170 * @param keyFrameNo {@inheritDoc}
171 * @throws MmdFormatException {@inheritDoc}
174 public void vmdShadowMotion(int keyFrameNo) throws MmdFormatException{
175 this.currentShadowMotion.setFrameNumber(keyFrameNo);
181 * @param shadowMode {@inheritDoc}
182 * @throws MmdFormatException {@inheritDoc}
185 public void vmdShadowMode(byte shadowMode) throws MmdFormatException{
186 ShadowMode mode = ShadowMode.decode(shadowMode);
187 this.currentShadowMotion.setShadowMode(mode);
193 * @param shadowScope {@inheritDoc}
194 * @throws MmdFormatException {@inheritDoc}
197 public void vmdShadowScopeRaw(float shadowScope)
198 throws MmdFormatException{
199 this.currentShadowMotion.setRawScopeParam(shadowScope);