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 * 照明光源演出データと影演出データを含む。
19 * <p>古い版のVMDファイルには影演出データが記述されていない場合がある。
21 class VmdLightingParser extends ProxyParser {
23 private VmdLightingHandler handler = VmdUnifiedHandler.EMPTY;
28 * @param parser 委譲先パーサ
30 VmdLightingParser(BinParser parser){
37 * ライティング情報通知用ハンドラを登録する。
38 * @param lightingHandler ハンドラ
40 void setLightingHandler(VmdLightingHandler lightingHandler){
41 if(lightingHandler == null){
42 this.handler = VmdUnifiedHandler.EMPTY;
44 this.handler = lightingHandler;
53 * <p>影演出データが無ければ読みに行かない。
55 * @throws IOException IOエラー
56 * @throws MmdFormatException フォーマットエラー
58 void parse() throws IOException, MmdFormatException {
68 * @throws IOException IOエラー
69 * @throws MmdFormatException フォーマットエラー
71 private void parseVmdLighting() throws IOException, MmdFormatException{
72 int lightMotionNo = parseLeInt();
74 this.handler.loopStart(VmdLightingHandler.LUMINOUS_LIST,
77 for(int ct = 0; ct < lightMotionNo; ct++){
78 int keyFrameNo = parseLeInt();
79 this.handler.vmdLuminousMotion(keyFrameNo);
81 float rVal = parseLeFloat();
82 float gVal = parseLeFloat();
83 float bVal = parseLeFloat();
84 this.handler.vmdLuminousColor(rVal, gVal, bVal);
86 float xVec = parseLeFloat();
87 float yVec = parseLeFloat();
88 float zVec = parseLeFloat();
89 this.handler.vmdLuminousDirection(xVec, yVec, zVec);
91 this.handler.loopNext(VmdLightingHandler.LUMINOUS_LIST);
94 this.handler.loopEnd(VmdLightingHandler.LUMINOUS_LIST);
101 * @throws IOException IOエラー
102 * @throws MmdFormatException フォーマットエラー
104 private void parseVmdShadow() throws IOException, MmdFormatException{
105 int shadowMotionNo = parseLeInt();
107 this.handler.loopStart(VmdLightingHandler.SHADOW_LIST,
110 for(int ct = 0; ct < shadowMotionNo; ct++){
111 int keyFrameNo = parseLeInt();
112 this.handler.vmdShadowMotion(keyFrameNo);
114 byte shadowMode = parseByte();
115 this.handler.vmdShadowMode(shadowMode);
117 float shadowScope = parseLeFloat();
118 this.handler.vmdShadowScopeRaw(shadowScope);
120 this.handler.loopNext(VmdLightingHandler.SHADOW_LIST);
123 this.handler.loopEnd(VmdLightingHandler.SHADOW_LIST);