2 * VMD lighting data parser
4 * License : The MIT License
5 * Copyright(c) 2011 MikuToga Partners
8 package jp.sfjp.mikutoga.vmd.parser;
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;
16 * VMDモーションファイルのライティング情報パーサ。
17 * 照明光源演出データと影演出データを含む。
18 * <p>古い版のVMDファイルには影演出データが記述されていない場合がある。
20 class VmdLightingParser extends ProxyParser {
22 private VmdLightingHandler handler = VmdUnifiedHandler.EMPTY;
27 * @param parser 委譲先パーサ
29 VmdLightingParser(BinParser parser){
36 * ライティング情報通知用ハンドラを登録する。
37 * @param lightingHandler ハンドラ
39 void setLightingHandler(VmdLightingHandler lightingHandler){
40 if(lightingHandler == null){
41 this.handler = VmdUnifiedHandler.EMPTY;
43 this.handler = lightingHandler;
51 * <p>影演出データが無ければ読みに行かない。
52 * @throws IOException IOエラー
53 * @throws MmdFormatException フォーマットエラー
55 void parse() throws IOException, MmdFormatException {
65 * @throws IOException IOエラー
66 * @throws MmdFormatException フォーマットエラー
68 private void parseVmdLighting() throws IOException, MmdFormatException{
69 int lightMotionNo = parseLeInt();
71 this.handler.loopStart(VmdLightingHandler.LUMINOUS_LIST,
74 for(int ct = 0; ct < lightMotionNo; ct++){
75 int keyFrameNo = parseLeInt();
76 this.handler.vmdLuminousMotion(keyFrameNo);
78 float rVal = parseLeFloat();
79 float gVal = parseLeFloat();
80 float bVal = parseLeFloat();
81 this.handler.vmdLuminousColor(rVal, gVal, bVal);
83 float xVec = parseLeFloat();
84 float yVec = parseLeFloat();
85 float zVec = parseLeFloat();
86 this.handler.vmdLuminousDirection(xVec, yVec, zVec);
88 this.handler.loopNext(VmdLightingHandler.LUMINOUS_LIST);
91 this.handler.loopEnd(VmdLightingHandler.LUMINOUS_LIST);
98 * @throws IOException IOエラー
99 * @throws MmdFormatException フォーマットエラー
101 private void parseVmdShadow() throws IOException, MmdFormatException{
102 int shadowMotionNo = parseLeInt();
104 this.handler.loopStart(VmdLightingHandler.SHADOW_LIST,
107 for(int ct = 0; ct < shadowMotionNo; ct++){
108 int keyFrameNo = parseLeInt();
109 this.handler.vmdShadowMotion(keyFrameNo);
111 byte shadowMode = parseByte();
112 this.handler.vmdShadowMode(shadowMode);
114 float shadowScope = parseLeFloat();
115 this.handler.vmdShadowScopeRaw(shadowScope);
117 this.handler.loopNext(VmdLightingHandler.SHADOW_LIST);
120 this.handler.loopEnd(VmdLightingHandler.SHADOW_LIST);