2 * basic information builder
4 * License : The MIT License
5 * Copyright(c) 2011 MikuToga Partners
8 package jp.sourceforge.mikutoga.vmd.model.binio;
10 import jp.sourceforge.mikutoga.math.MkPos3D;
11 import jp.sourceforge.mikutoga.math.MkQuat;
12 import jp.sourceforge.mikutoga.parser.MmdFormatException;
13 import jp.sourceforge.mikutoga.parser.ParseStage;
14 import jp.sourceforge.mikutoga.vmd.model.BezierParam;
15 import jp.sourceforge.mikutoga.vmd.model.BoneMotion;
16 import jp.sourceforge.mikutoga.vmd.model.MorphMotion;
17 import jp.sourceforge.mikutoga.vmd.model.PosCurve;
18 import jp.sourceforge.mikutoga.vmd.model.VmdMotion;
19 import jp.sourceforge.mikutoga.vmd.parser.VmdBasicHandler;
24 class BasicLoader implements VmdBasicHandler {
26 private final VmdMotion vmdMotion;
28 private BoneMotion currentBoneMotion;
29 private MorphMotion currentMorphMotion;
31 private boolean hasMoreData;
36 * @param vmdMotion モーション情報
38 BasicLoader(VmdMotion vmdMotion){
40 this.vmdMotion = vmdMotion;
42 this.currentBoneMotion = null;
43 this.currentMorphMotion = null;
45 this.hasMoreData = false;
54 * @return モーションループならtrue
56 private static boolean isBoneMotionList(ParseStage stage){
57 if(stage == VmdBasicHandler.BONEMOTION_LIST) return true;
64 * @return モーフループならtrue
66 private static boolean isMorphList(ParseStage stage){
67 if(stage == VmdBasicHandler.MORPH_LIST) return true;
74 * @throws MmdFormatException {@inheritDoc}
77 public void vmdParseStart() throws MmdFormatException{
84 * @param hasMoreDataArg {@inheritDoc}
85 * @throws MmdFormatException {@inheritDoc}
88 public void vmdParseEnd(boolean hasMoreDataArg)
89 throws MmdFormatException{
90 this.hasMoreData = hasMoreDataArg;
96 * @param stage {@inheritDoc}
97 * @param loops {@inheritDoc}
98 * @throws MmdFormatException {@inheritDoc}
101 public void loopStart(ParseStage stage, int loops)
102 throws MmdFormatException{
103 if(isBoneMotionList(stage)){
104 this.currentBoneMotion = new BoneMotion();
105 }else if(isMorphList(stage)){
106 this.currentMorphMotion = new MorphMotion();
113 * @param stage {@inheritDoc}
114 * @throws MmdFormatException {@inheritDoc}
117 public void loopNext(ParseStage stage)
118 throws MmdFormatException{
119 if(isBoneMotionList(stage)){
120 this.vmdMotion.addBoneMotion(this.currentBoneMotion);
121 this.currentBoneMotion = new BoneMotion();
122 }else if(isMorphList(stage)){
123 this.vmdMotion.addMorphMotion(this.currentMorphMotion);
124 this.currentMorphMotion = new MorphMotion();
131 * @param stage {@inheritDoc}
132 * @throws MmdFormatException {@inheritDoc}
135 public void loopEnd(ParseStage stage)
136 throws MmdFormatException{
137 if(isBoneMotionList(stage)){
138 this.currentBoneMotion = null;
139 }else if(isMorphList(stage)){
140 this.currentMorphMotion = null;
147 * @param header {@inheritDoc}
148 * @throws MmdFormatException {@inheritDoc}
151 public void vmdHeaderInfo(byte[] header) throws MmdFormatException{
158 * @param modelName {@inheritDoc}
159 * @throws MmdFormatException {@inheritDoc}
162 public void vmdModelName(String modelName) throws MmdFormatException{
163 this.vmdMotion.setModelName(modelName);
169 * @param boneName {@inheritDoc}
170 * @param keyFrameNo {@inheritDoc}
171 * @throws MmdFormatException {@inheritDoc}
174 public void vmdBoneMotion(String boneName, int keyFrameNo)
175 throws MmdFormatException{
176 this.currentBoneMotion.setBoneName(boneName);
177 this.currentBoneMotion.setFrameNumber(keyFrameNo);
183 * @param qx {@inheritDoc}
184 * @param qy {@inheritDoc}
185 * @param qz {@inheritDoc}
186 * @param qw {@inheritDoc}
187 * @throws MmdFormatException {@inheritDoc}
190 public void vmdBoneRotationQt(float qx, float qy, float qz, float qw)
191 throws MmdFormatException{
192 MkQuat rotation = this.currentBoneMotion.getRotation();
202 * @param xPos {@inheritDoc}
203 * @param yPos {@inheritDoc}
204 * @param zPos {@inheritDoc}
205 * @throws MmdFormatException {@inheritDoc}
208 public void vmdBonePosition(float xPos, float yPos, float zPos)
209 throws MmdFormatException{
210 MkPos3D position = this.currentBoneMotion.getPosition();
211 position.setPosition(xPos, yPos, zPos);
217 * @param rP1x {@inheritDoc}
218 * @param rP1y {@inheritDoc}
219 * @param rP2x {@inheritDoc}
220 * @param rP2y {@inheritDoc}
221 * @throws MmdFormatException {@inheritDoc}
224 public void vmdBoneIntpltRot(byte rP1x, byte rP1y,
225 byte rP2x, byte rP2y )
226 throws MmdFormatException{
227 BezierParam bezier = this.currentBoneMotion.getIntpltRotation();
228 bezier.setP1(rP1x, rP1y);
229 bezier.setP2(rP2x, rP2y);
235 * @param xP1x {@inheritDoc}
236 * @param xP1y {@inheritDoc}
237 * @param xP2x {@inheritDoc}
238 * @param xP2y {@inheritDoc}
239 * @throws MmdFormatException {@inheritDoc}
242 public void vmdBoneIntpltXpos(byte xP1x, byte xP1y,
243 byte xP2x, byte xP2y )
244 throws MmdFormatException{
245 PosCurve posCurve = this.currentBoneMotion.getPosCurve();
246 BezierParam bezier = posCurve.getIntpltXpos();
247 bezier.setP1(xP1x, xP1y);
248 bezier.setP2(xP2x, xP2y);
254 * @param yP1x {@inheritDoc}
255 * @param yP1y {@inheritDoc}
256 * @param yP2x {@inheritDoc}
257 * @param yP2y {@inheritDoc}
258 * @throws MmdFormatException {@inheritDoc}
261 public void vmdBoneIntpltYpos(byte yP1x, byte yP1y,
262 byte yP2x, byte yP2y )
263 throws MmdFormatException{
264 PosCurve posCurve = this.currentBoneMotion.getPosCurve();
265 BezierParam bezier = posCurve.getIntpltYpos();
266 bezier.setP1(yP1x, yP1y);
267 bezier.setP2(yP2x, yP2y);
273 * @param zP1x {@inheritDoc}
274 * @param zP1y {@inheritDoc}
275 * @param zP2x {@inheritDoc}
276 * @param zP2y {@inheritDoc}
277 * @throws MmdFormatException {@inheritDoc}
280 public void vmdBoneIntpltZpos(byte zP1x, byte zP1y,
281 byte zP2x, byte zP2y )
282 throws MmdFormatException{
283 PosCurve posCurve = this.currentBoneMotion.getPosCurve();
284 BezierParam bezier = posCurve.getIntpltZpos();
285 bezier.setP1(zP1x, zP1y);
286 bezier.setP2(zP2x, zP2y);
292 * @param morphName {@inheritDoc}
293 * @param keyFrameNo {@inheritDoc}
294 * @param flex {@inheritDoc}
295 * @throws MmdFormatException {@inheritDoc}
298 public void vmdMorphMotion(String morphName, int keyFrameNo, float flex)
299 throws MmdFormatException{
300 this.currentMorphMotion.setMorphName(morphName);
301 this.currentMorphMotion.setFrameNumber(keyFrameNo);
302 this.currentMorphMotion.setFlex(flex);
308 * @return 読み残したデータがあればtrue
310 boolean hasMoreData(){
311 return this.hasMoreData;