OSDN Git Service

vmdパッケージ導入
[mikutoga/TogaGem.git] / src / main / java / jp / sourceforge / mikutoga / vmd / model / xml / XmlLightingLoader.java
1 /*
2  * xml lighting loader
3  *
4  * License : The MIT License
5  * Copyright(c) 2011 MikuToga Partners
6  */
7
8 package jp.sourceforge.mikutoga.vmd.model.xml;
9
10 import java.util.List;
11 import jp.sourceforge.mikutoga.vmd.model.LuminousColor;
12 import jp.sourceforge.mikutoga.vmd.model.LuminousMotion;
13 import jp.sourceforge.mikutoga.vmd.model.LuminousVector;
14 import jp.sourceforge.mikutoga.vmd.model.ShadowMode;
15 import jp.sourceforge.mikutoga.vmd.model.ShadowMotion;
16 import jp.sourceforge.mikutoga.vmd.model.VmdMotion;
17 import jp.sourceforge.mikutoga.xml.TogaXmlException;
18 import org.w3c.dom.Element;
19
20 /**
21  * XMLによるカメラ制御データを読み取る。
22  */
23 final class XmlLightingLoader {
24
25     /**
26      * 隠しコンストラクタ。
27      */
28     private XmlLightingLoader(){
29         assert false;
30         throw new AssertionError();
31     }
32
33
34     /**
35      * 照明シーケンスを読み込む。
36      * @param vmdMotionElem vmdMotion要素
37      * @param vmdMotion モーション
38      * @throws TogaXmlException 構文エラー
39      */
40     static void buildLuminousSeq(Element vmdMotionElem, VmdMotion vmdMotion)
41             throws TogaXmlException{
42         List<LuminousMotion> luminousList =
43                 vmdMotion.getLuminousMotionList();
44
45         Element luminousSeqElem =
46                 Xml.getChild(vmdMotionElem, "luminousSequence");
47
48         Iterable<Element> childs =
49                 Xml.eachChild(luminousSeqElem, "luminousAct");
50         for(Element luminousActElem : childs){
51             buildLuminousAct(luminousActElem, luminousList);
52         }
53
54         return;
55     }
56
57     /**
58      * 照明モーションを読み込む。
59      * @param luminousActElem luminousAct要素
60      * @param luminousList 照明モーションリスト
61      * @throws TogaXmlException 構文エラー
62      */
63     private static void buildLuminousAct(Element luminousActElem,
64                                          List<LuminousMotion> luminousList)
65             throws TogaXmlException{
66         LuminousMotion luminousMotion = new LuminousMotion();
67
68         int frameNo = Xml.getIntegerAttr(luminousActElem, "frame");
69         luminousMotion.setFrameNumber(frameNo);
70
71         Element lumiColorElem = Xml.getChild(luminousActElem, "lumiColor");
72         LuminousColor color = luminousMotion.getColor();
73         float rCol = Xml.getFloatAttr(lumiColorElem, "rCol");
74         float gCol = Xml.getFloatAttr(lumiColorElem, "gCol");
75         float bCol = Xml.getFloatAttr(lumiColorElem, "bCol");
76         color.setColR(rCol);
77         color.setColG(gCol);
78         color.setColB(bCol);
79
80         Element lumiDirectionElem =
81                 Xml.getChild(luminousActElem, "lumiDirection");
82         LuminousVector vec = luminousMotion.getDirection();
83         float xVec = Xml.getFloatAttr(lumiDirectionElem, "xVec");
84         float yVec = Xml.getFloatAttr(lumiDirectionElem, "yVec");
85         float zVec = Xml.getFloatAttr(lumiDirectionElem, "zVec");
86         vec.setVecX(xVec);
87         vec.setVecY(yVec);
88         vec.setVecZ(zVec);
89
90         luminousList.add(luminousMotion);
91
92         return;
93     }
94
95     /**
96      * シャドウシーケンスを読み込む。
97      * @param vmdMotionElem vmdMotion要素
98      * @param vmdMotion モーション
99      * @throws TogaXmlException 構文エラー
100      */
101     static void buildShadowSeq(Element vmdMotionElem,
102                                VmdMotion vmdMotion)
103             throws TogaXmlException{
104         List<ShadowMotion> shadowMotionList =
105                 vmdMotion.getShadowMotionList();
106
107         Element shadowSeqElem =
108                 Xml.getChild(vmdMotionElem, "shadowSequence");
109
110         for(Element shadowActElem :
111                 Xml.eachChild(shadowSeqElem, "shadowAct")){
112             buildShadowAct(shadowActElem, shadowMotionList);
113         }
114
115         return;
116     }
117
118     /**
119      * シャドウモーションを読み込む。
120      * @param shadowActElem shadowAct要素
121      * @param shadowMotionList シャドウモーションリスト
122      * @throws TogaXmlException 構文エラー
123      */
124     private static void buildShadowAct(Element shadowActElem,
125                                        List<ShadowMotion> shadowMotionList)
126             throws TogaXmlException{
127         ShadowMotion shadowMotion = new ShadowMotion();
128
129         int frameNo = Xml.getIntegerAttr(shadowActElem, "frame");
130         shadowMotion.setFrameNumber(frameNo);
131
132         float rawParam = Xml.getFloatAttr(shadowActElem, "rawParam");
133         shadowMotion.setRawScopeParam(rawParam);
134
135         String modeAttr = Xml.getStringAttr(shadowActElem, "mode");
136         ShadowMode mode = ShadowMode.valueOf(modeAttr);
137         shadowMotion.setShadowMode(mode);
138
139         shadowMotionList.add(shadowMotion);
140
141         return;
142     }
143
144 }