4 * License : The MIT License
5 * Copyright(c) 2011 MikuToga Partners
8 package jp.sourceforge.mikutoga.vmd.model.xml;
10 import java.util.List;
11 import jp.sourceforge.mikutoga.math.MkPos3D;
12 import jp.sourceforge.mikutoga.vmd.model.BezierParam;
13 import jp.sourceforge.mikutoga.vmd.model.CameraMotion;
14 import jp.sourceforge.mikutoga.vmd.model.CameraRotation;
15 import jp.sourceforge.mikutoga.vmd.model.PosCurve;
16 import jp.sourceforge.mikutoga.vmd.model.VmdMotion;
17 import jp.sourceforge.mikutoga.xml.TogaXmlException;
18 import org.w3c.dom.Element;
21 * XMLによるカメラ制御データを読み取る。
23 final class XmlCameraLoader {
28 private XmlCameraLoader(){
30 throw new AssertionError();
36 * @param vmdMotionElem vmdMotion要素
37 * @param vmdMotion モーション
38 * @throws TogaXmlException 構文エラー
40 static void buildCameraSeq(Element vmdMotionElem, VmdMotion vmdMotion)
41 throws TogaXmlException{
42 List<CameraMotion> cameraList = vmdMotion.getCameraMotionList();
44 Element cameraSeqElem =
45 Xml.getChild(vmdMotionElem, "cameraSequence");
47 Iterable<Element> childs =
48 Xml.eachChild(cameraSeqElem, "cameraMotion");
49 for(Element cameraMotionElem : childs){
50 buildCameraMotion(cameraMotionElem, cameraList);
58 * @param cameraMotionElem cameraMotion要素
59 * @param cameraList カメラモーションリスト
60 * @throws TogaXmlException 構文エラー
62 private static void buildCameraMotion(Element cameraMotionElem,
63 List<CameraMotion> cameraList)
64 throws TogaXmlException{
65 CameraMotion cameraMotion = new CameraMotion();
67 int frameNo = Xml.getIntegerAttr(cameraMotionElem, "frame");
68 cameraMotion.setFrameNumber(frameNo);
70 if(cameraMotionElem.hasAttributeNS(Xml.NS_NULL, "hasPerspective")){
71 boolean hasPerspective =
72 Xml.getBooleanAttr(cameraMotionElem, "hasPerspective");
73 cameraMotion.setPerspectiveMode(hasPerspective);
76 buildCameraTarget(cameraMotionElem, cameraMotion);
77 buildCameraRotation(cameraMotionElem, cameraMotion);
78 buildCameraRange(cameraMotionElem, cameraMotion);
79 buildProjection(cameraMotionElem, cameraMotion);
81 cameraList.add(cameraMotion);
88 * @param cameraMotionElem cameraMotion要素
89 * @param cameraMotion カメラモーション
90 * @throws TogaXmlException 構文エラー
92 private static void buildCameraTarget(Element cameraMotionElem,
93 CameraMotion cameraMotion)
94 throws TogaXmlException{
95 Element cameraTargetElem =
96 Xml.getChild(cameraMotionElem, "cameraTarget");
97 MkPos3D targetPos = cameraMotion.getCameraTarget();
99 float xPos = Xml.getFloatAttr(cameraTargetElem, "xPos");
100 float yPos = Xml.getFloatAttr(cameraTargetElem, "yPos");
101 float zPos = Xml.getFloatAttr(cameraTargetElem, "zPos");
102 targetPos.setPosition(xPos, yPos, zPos);
104 PosCurve curve = cameraMotion.getTargetPosCurve();
105 Xml.buildPosCurve(cameraTargetElem, curve);
112 * @param cameraMotionElem cameraMotion要素
113 * @param cameraMotion カメラモーション
114 * @throws TogaXmlException 構文エラー
116 private static void buildCameraRotation(Element cameraMotionElem,
117 CameraMotion cameraMotion)
118 throws TogaXmlException{
119 Element cameraRotationElem =
120 Xml.getChild(cameraMotionElem, "cameraRotation");
121 CameraRotation cameraRotation = cameraMotion.getCameraRotation();
123 float latitude = Xml.getFloatAttr(cameraRotationElem, "xRad");
124 float longitude = Xml.getFloatAttr(cameraRotationElem, "yRad");
125 float roll = Xml.getFloatAttr(cameraRotationElem, "zRad");
126 cameraRotation.setLatitude(latitude);
127 cameraRotation.setLongitude(longitude);
128 cameraRotation.setRoll(roll);
130 BezierParam rotationCurve = cameraMotion.getIntpltRotation();
131 Xml.buildCurve(cameraRotationElem, rotationCurve);
138 * @param cameraMotionElem cameraMotion要素
139 * @param cameraMotion カメラモーション
140 * @throws TogaXmlException 構文エラー
142 private static void buildCameraRange(Element cameraMotionElem,
143 CameraMotion cameraMotion)
144 throws TogaXmlException{
145 Element cameraRangeElem =
146 Xml.getChild(cameraMotionElem, "cameraRange");
148 float range = Xml.getFloatAttr(cameraRangeElem, "range");
149 cameraMotion.setRange(range);
151 BezierParam rangeCurve = cameraMotion.getIntpltRange();
152 Xml.buildCurve(cameraRangeElem, rangeCurve);
159 * @param cameraMotionElem cameraMotion要素
160 * @param cameraMotion カメラモーション
161 * @throws TogaXmlException 構文エラー
163 private static void buildProjection(Element cameraMotionElem,
164 CameraMotion cameraMotion)
165 throws TogaXmlException{
166 Element projectionElem =
167 Xml.getChild(cameraMotionElem, "projection");
169 int vertDeg = Xml.getIntegerAttr(projectionElem, "vertDeg");
170 cameraMotion.setProjectionAngle(vertDeg);
172 BezierParam projCurve = cameraMotion.getIntpltProjection();
173 Xml.buildCurve(projectionElem, projCurve);