2 * VMD lighting data parser
4 * License : The MIT License
5 * Copyright(c) 2011 MikuToga Partners
8 package jp.sourceforge.mikutoga.vmd.parser;
10 import java.io.IOException;
11 import java.io.InputStream;
12 import jp.sfjp.mikutoga.bin.parser.CommonParser;
13 import jp.sfjp.mikutoga.bin.parser.MmdFormatException;
14 import jp.sourceforge.mikutoga.vmd.VmdConst;
17 * VMDモーションファイルのライティング情報パーサ。
18 * 照明光源演出データと影演出データを含む。
19 * <p>古い版のVMDファイルには影演出データが記述されていない場合がある。
21 class VmdLightingParser extends CommonParser {
23 private VmdLightingHandler handler = null;
30 VmdLightingParser(InputStream source){
37 * ライティング情報通知用ハンドラを登録する。
38 * @param lightingHandler ハンドラ
40 void setLightingHandler(VmdLightingHandler lightingHandler){
41 this.handler = lightingHandler;
47 * <p>影演出データが無ければ読みに行かない。
48 * @throws IOException IOエラー
49 * @throws MmdFormatException フォーマットエラー
51 void parse() throws IOException, MmdFormatException {
61 * @throws IOException IOエラー
62 * @throws MmdFormatException フォーマットエラー
64 private void parseVmdLighting() throws IOException, MmdFormatException{
65 int lightMotionNo = parseLeInt();
67 if(this.handler == null){
68 skip(VmdConst.LUMINOUS_DATA_SZ * lightMotionNo);
72 this.handler.loopStart(VmdLightingHandler.LUMINOUS_LIST,
75 for(int ct = 0; ct < lightMotionNo; ct++){
76 int keyFrameNo = parseLeInt();
77 this.handler.vmdLuminousMotion(keyFrameNo);
79 float rVal = parseLeFloat();
80 float gVal = parseLeFloat();
81 float bVal = parseLeFloat();
82 this.handler.vmdLuminousColor(rVal, gVal, bVal);
84 float xVec = parseLeFloat();
85 float yVec = parseLeFloat();
86 float zVec = parseLeFloat();
87 this.handler.vmdLuminousDirection(xVec, yVec, zVec);
89 this.handler.loopNext(VmdLightingHandler.LUMINOUS_LIST);
92 this.handler.loopEnd(VmdLightingHandler.LUMINOUS_LIST);
99 * @throws IOException IOエラー
100 * @throws MmdFormatException フォーマットエラー
102 private void parseVmdShadow() throws IOException, MmdFormatException{
103 int shadowMotionNo = parseLeInt();
105 if(this.handler == null){
106 skip(VmdConst.SHADOW_DATA_SZ * shadowMotionNo);
110 this.handler.loopStart(VmdLightingHandler.SHADOW_LIST,
113 for(int ct = 0; ct < shadowMotionNo; ct++){
114 int keyFrameNo = parseLeInt();
115 this.handler.vmdShadowMotion(keyFrameNo);
117 byte shadowMode = parseByte();
118 this.handler.vmdShadowMode(shadowMode);
120 float shadowScope = parseLeFloat();
121 this.handler.vmdShadowScopeRaw(shadowScope);
123 this.handler.loopNext(VmdLightingHandler.SHADOW_LIST);
126 this.handler.loopEnd(VmdLightingHandler.SHADOW_LIST);