From f583159a1358b23ec87c233497608a3fe727d163 Mon Sep 17 00:00:00 2001 From: Olyutorskii Date: Sun, 19 May 2013 23:05:43 +0900 Subject: [PATCH] =?utf8?q?Pmd2XML=E3=81=A8=E3=81=AE=E5=85=B1=E9=80=9A?= =?utf8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- CHANGELOG.txt | 1 + pom.xml | 4 +- .../mikutoga/vmd/model/BezierParam.java | 27 +- .../mikutoga/vmd/model/BoneMotion.java | 31 +- .../mikutoga/vmd/model/CameraMotion.java | 51 +- .../mikutoga/vmd/model/CameraRotation.java | 47 +- .../mikutoga/vmd/model/LuminousColor.java | 21 +- .../jp/sfjp/mikutoga/vmd/model/LuminousMotion.java | 81 +++ .../mikutoga/vmd/model/MorphMotion.java | 20 +- .../mikutoga/vmd/model/PosCurve.java | 62 ++- .../mikutoga/vmd/model/ShadowMode.java | 2 +- .../mikutoga/vmd/model/ShadowMotion.java | 46 +- .../mikutoga/vmd/model/VmdMotion.java | 124 +++-- .../mikutoga/vmd/model/binio/BasicExporter.java | 161 +++--- .../mikutoga/vmd/model/binio/BasicLoader.java | 26 +- .../mikutoga/vmd/model/binio/CameraExporter.java | 20 +- .../mikutoga/vmd/model/binio/CameraLoader.java | 21 +- .../mikutoga/vmd/model/binio/LightingExporter.java | 24 +- .../mikutoga/vmd/model/binio/LightingLoader.java | 26 +- .../sfjp/mikutoga/vmd/model/binio/VmdExporter.java | 82 +++ .../sfjp/mikutoga/vmd/model/binio/VmdLoader.java | 116 ++++ .../mikutoga/vmd/model/binio/package-info.java | 2 +- .../mikutoga/vmd/model/package-info.java | 3 +- .../java/jp/sfjp/mikutoga/vmd2xml/CmdLine.java | 101 ++++ .../jp/sfjp/mikutoga/vmd2xml/CmdLineException.java | 25 + .../mikutoga/vmd2xml/MotionFileType.java | 2 +- .../java/jp/sfjp/mikutoga/vmd2xml/OptInfo.java | 389 ++++++++++++++ .../java/jp/sfjp/mikutoga/vmd2xml/OptSwitch.java | 120 +++++ .../java/jp/sfjp/mikutoga/vmd2xml/Vmd2Xml.java | 392 ++++++++++++++ .../mikutoga/vmd2xml/Vmd2XmlConv.java | 57 +- .../jp/sfjp/mikutoga/vmd2xml/package-info.java | 15 + .../mikutoga/vmd/model/LuminousMotion.java | 61 --- .../mikutoga/vmd/model/LuminousVector.java | 111 ---- .../mikutoga/vmd/model/NamedListMap.java | 111 ---- .../mikutoga/vmd/model/binio/VmdExporter.java | 128 ----- .../mikutoga/vmd/model/binio/VmdLoader.java | 60 --- .../mikutoga/vmd/model/xml/CameraXmlExporter.java | 255 +++++++++ .../mikutoga/vmd/model/xml/LightingXmlExpoter.java | 165 ++++++ .../mikutoga/vmd/model/xml/Schema110820.java | 17 +- .../mikutoga/vmd/model/xml/VmdXmlExporter.java | 563 +++++--------------- .../mikutoga/vmd/model/xml/VmdXmlResources.java | 163 ------ .../jp/sourceforge/mikutoga/vmd/model/xml/Xml.java | 23 +- .../mikutoga/vmd/model/xml/Xml2VmdLoader.java | 37 +- .../mikutoga/vmd/model/xml/XmlCameraLoader.java | 10 +- .../mikutoga/vmd/model/xml/XmlLightingLoader.java | 20 +- .../mikutoga/vmd/model/xml/XmlSyms.java | 117 ++++ .../jp/sourceforge/mikutoga/vmd2xml/ArgInfo.java | 312 ----------- .../mikutoga/vmd2xml/ValidationHandler.java | 63 --- .../jp/sourceforge/mikutoga/vmd2xml/Vmd2Xml.java | 587 --------------------- .../sourceforge/mikutoga/vmd2xml/package-info.java | 14 - .../mikutoga/vmd2xml/resources/version.properties | 0 .../sfjp/mikutoga/vmd/model/BezierParamTest.java | 225 ++++++++ .../jp/sfjp/mikutoga/vmd/model/BoneMotionTest.java | 204 +++++++ .../sfjp/mikutoga/vmd/model/CameraMotionTest.java | 226 ++++++++ .../mikutoga/vmd/model/CameraRotationTest.java | 84 +++ .../sfjp/mikutoga/vmd/model/LuminousColorTest.java | 80 +++ .../mikutoga/vmd/model/LuminousMotionTest.java | 97 ++++ .../sfjp/mikutoga/vmd/model/MorphMotionTest.java | 95 ++++ .../jp/sfjp/mikutoga/vmd/model/PosCurveTest.java | 155 ++++++ .../jp/sfjp/mikutoga/vmd/model/ShadowModeTest.java | 116 ++++ .../sfjp/mikutoga/vmd/model/ShadowMotionTest.java | 138 +++++ .../jp/sfjp/mikutoga/vmd/model/VmdMotionTest.java | 426 +++++++++++++++ src/test/java/testdata/CnvAssert.java | 4 +- .../java/testdata/vmd110820/morph/MorphTest.java | 56 ++ .../java/testdata/vmd110820/motion/MotionTest.java | 56 ++ .../resources/testdata/vmd110820/camera/camera.xml | 20 +- .../testdata/vmd110820/luminous/luminous.xml | 21 - .../testdata/vmd110820/minimum/mincam.xml | 21 - .../testdata/vmd110820/minimum/minmotion.xml | 13 +- .../resources/testdata/vmd110820/morph/morph.vmd | Bin 0 -> 208 bytes .../resources/testdata/vmd110820/morph/morph.xml | 43 ++ .../resources/testdata/vmd110820/motion/motion.vmd | Bin 0 -> 403 bytes .../resources/testdata/vmd110820/motion/motion.xml | 85 +++ .../testdata/vmd110820/shadow/allShadow.xml | 13 - .../testdata/vmd110820/small/onlyBone.xml | 4 +- .../testdata/vmd110820/small/onlyCamera.xml | 20 +- .../testdata/vmd110820/small/onlyLuminous.xml | 21 - .../testdata/vmd110820/small/onlyMorph.xml | 11 - .../testdata/vmd110820/small/onlyShadow.xml | 13 - 79 files changed, 4583 insertions(+), 2580 deletions(-) rename src/main/java/jp/{sourceforge => sfjp}/mikutoga/vmd/model/BezierParam.java (91%) rename src/main/java/jp/{sourceforge => sfjp}/mikutoga/vmd/model/BoneMotion.java (82%) rename src/main/java/jp/{sourceforge => sfjp}/mikutoga/vmd/model/CameraMotion.java (78%) rename src/main/java/jp/{sourceforge => sfjp}/mikutoga/vmd/model/CameraRotation.java (71%) rename src/main/java/jp/{sourceforge => sfjp}/mikutoga/vmd/model/LuminousColor.java (86%) create mode 100644 src/main/java/jp/sfjp/mikutoga/vmd/model/LuminousMotion.java rename src/main/java/jp/{sourceforge => sfjp}/mikutoga/vmd/model/MorphMotion.java (77%) rename src/main/java/jp/{sourceforge => sfjp}/mikutoga/vmd/model/PosCurve.java (59%) rename src/main/java/jp/{sourceforge => sfjp}/mikutoga/vmd/model/ShadowMode.java (98%) rename src/main/java/jp/{sourceforge => sfjp}/mikutoga/vmd/model/ShadowMotion.java (75%) rename src/main/java/jp/{sourceforge => sfjp}/mikutoga/vmd/model/VmdMotion.java (55%) rename src/main/java/jp/{sourceforge => sfjp}/mikutoga/vmd/model/binio/BasicExporter.java (56%) rename src/main/java/jp/{sourceforge => sfjp}/mikutoga/vmd/model/binio/BasicLoader.java (93%) rename src/main/java/jp/{sourceforge => sfjp}/mikutoga/vmd/model/binio/CameraExporter.java (85%) rename src/main/java/jp/{sourceforge => sfjp}/mikutoga/vmd/model/binio/CameraLoader.java (92%) rename src/main/java/jp/{sourceforge => sfjp}/mikutoga/vmd/model/binio/LightingExporter.java (75%) rename src/main/java/jp/{sourceforge => sfjp}/mikutoga/vmd/model/binio/LightingLoader.java (88%) create mode 100644 src/main/java/jp/sfjp/mikutoga/vmd/model/binio/VmdExporter.java create mode 100644 src/main/java/jp/sfjp/mikutoga/vmd/model/binio/VmdLoader.java rename src/main/java/jp/{sourceforge => sfjp}/mikutoga/vmd/model/binio/package-info.java (82%) rename src/main/java/jp/{sourceforge => sfjp}/mikutoga/vmd/model/package-info.java (64%) create mode 100644 src/main/java/jp/sfjp/mikutoga/vmd2xml/CmdLine.java create mode 100644 src/main/java/jp/sfjp/mikutoga/vmd2xml/CmdLineException.java rename src/main/java/jp/{sourceforge => sfjp}/mikutoga/vmd2xml/MotionFileType.java (96%) create mode 100644 src/main/java/jp/sfjp/mikutoga/vmd2xml/OptInfo.java create mode 100644 src/main/java/jp/sfjp/mikutoga/vmd2xml/OptSwitch.java create mode 100644 src/main/java/jp/sfjp/mikutoga/vmd2xml/Vmd2Xml.java rename src/main/java/jp/{sourceforge => sfjp}/mikutoga/vmd2xml/Vmd2XmlConv.java (86%) create mode 100644 src/main/java/jp/sfjp/mikutoga/vmd2xml/package-info.java delete mode 100644 src/main/java/jp/sourceforge/mikutoga/vmd/model/LuminousMotion.java delete mode 100644 src/main/java/jp/sourceforge/mikutoga/vmd/model/LuminousVector.java delete mode 100644 src/main/java/jp/sourceforge/mikutoga/vmd/model/NamedListMap.java delete mode 100644 src/main/java/jp/sourceforge/mikutoga/vmd/model/binio/VmdExporter.java delete mode 100644 src/main/java/jp/sourceforge/mikutoga/vmd/model/binio/VmdLoader.java create mode 100644 src/main/java/jp/sourceforge/mikutoga/vmd/model/xml/CameraXmlExporter.java create mode 100644 src/main/java/jp/sourceforge/mikutoga/vmd/model/xml/LightingXmlExpoter.java delete mode 100644 src/main/java/jp/sourceforge/mikutoga/vmd/model/xml/VmdXmlResources.java create mode 100644 src/main/java/jp/sourceforge/mikutoga/vmd/model/xml/XmlSyms.java delete mode 100644 src/main/java/jp/sourceforge/mikutoga/vmd2xml/ArgInfo.java delete mode 100644 src/main/java/jp/sourceforge/mikutoga/vmd2xml/ValidationHandler.java delete mode 100644 src/main/java/jp/sourceforge/mikutoga/vmd2xml/Vmd2Xml.java delete mode 100644 src/main/java/jp/sourceforge/mikutoga/vmd2xml/package-info.java rename src/main/resources/jp/{sourceforge => sfjp}/mikutoga/vmd2xml/resources/version.properties (100%) create mode 100644 src/test/java/jp/sfjp/mikutoga/vmd/model/BezierParamTest.java create mode 100644 src/test/java/jp/sfjp/mikutoga/vmd/model/BoneMotionTest.java create mode 100644 src/test/java/jp/sfjp/mikutoga/vmd/model/CameraMotionTest.java create mode 100644 src/test/java/jp/sfjp/mikutoga/vmd/model/CameraRotationTest.java create mode 100644 src/test/java/jp/sfjp/mikutoga/vmd/model/LuminousColorTest.java create mode 100644 src/test/java/jp/sfjp/mikutoga/vmd/model/LuminousMotionTest.java create mode 100644 src/test/java/jp/sfjp/mikutoga/vmd/model/MorphMotionTest.java create mode 100644 src/test/java/jp/sfjp/mikutoga/vmd/model/PosCurveTest.java create mode 100644 src/test/java/jp/sfjp/mikutoga/vmd/model/ShadowModeTest.java create mode 100644 src/test/java/jp/sfjp/mikutoga/vmd/model/ShadowMotionTest.java create mode 100644 src/test/java/jp/sfjp/mikutoga/vmd/model/VmdMotionTest.java create mode 100644 src/test/java/testdata/vmd110820/morph/MorphTest.java create mode 100644 src/test/java/testdata/vmd110820/motion/MotionTest.java create mode 100644 src/test/resources/testdata/vmd110820/morph/morph.vmd create mode 100644 src/test/resources/testdata/vmd110820/morph/morph.xml create mode 100644 src/test/resources/testdata/vmd110820/motion/motion.vmd create mode 100644 src/test/resources/testdata/vmd110820/motion/motion.xml diff --git a/CHANGELOG.txt b/CHANGELOG.txt index f78b222..960b724 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -8,6 +8,7 @@ X.XXX.X (20XX-XX_XX) ・Maven3対応。 ・オイラー角出力時の精度を向上させた。 ・ベジェ補間パラメータ冗長部がMMDの版により異なるため、検査をやめた。 + ・プロセス終了コードの変更。 1.101.2 (2011-08-25) ・初回リリース。 diff --git a/pom.xml b/pom.xml index c99a02b..f06b8f0 100644 --- a/pom.xml +++ b/pom.xml @@ -16,7 +16,7 @@ jp.sourceforge.mikutoga vmd2xml - 1.101.3-SNAPSHOT + 1.101.5-SNAPSHOT jar Vmd2XML @@ -112,7 +112,7 @@ jp.sourceforge.mikutoga togagem - 2.102.3-SNAPSHOT + 2.102.5-SNAPSHOT compile diff --git a/src/main/java/jp/sourceforge/mikutoga/vmd/model/BezierParam.java b/src/main/java/jp/sfjp/mikutoga/vmd/model/BezierParam.java similarity index 91% rename from src/main/java/jp/sourceforge/mikutoga/vmd/model/BezierParam.java rename to src/main/java/jp/sfjp/mikutoga/vmd/model/BezierParam.java index f90e88a..7bf5d22 100644 --- a/src/main/java/jp/sourceforge/mikutoga/vmd/model/BezierParam.java +++ b/src/main/java/jp/sfjp/mikutoga/vmd/model/BezierParam.java @@ -1,11 +1,13 @@ /* - * 3D bezier intaerpolation curve params + * 3D bezier interpolation curve params * * License : The MIT License * Copyright(c) 2011 MikuToga Partners */ -package jp.sourceforge.mikutoga.vmd.model; +package jp.sfjp.mikutoga.vmd.model; + +import java.text.MessageFormat; /** * 三次ベジェ曲線による補間カーブを記述する。 @@ -50,15 +52,17 @@ public class BezierParam { public static final byte EIO_P2Y = 127; /** - * 制御点空間最小値。 + * 制御点空間各軸最小値。 */ public static final byte MIN_VAL = 0; /** - * 制御点空間最大値。 + * 制御点空間各軸最大値。 */ public static final byte MAX_VAL = 127; + private static final String MSG_TXT = "P1=({0}, {1}) P2=({2}, {3})"; + private byte p1x = DEF_P1X; private byte p1y = DEF_P1Y; @@ -187,8 +191,6 @@ public class BezierParam { if(this.p2x != DEF_P2X) return false; if(this.p2y != DEF_P2Y) return false; - assert isLinear(); - return true; } @@ -234,15 +236,10 @@ public class BezierParam { */ @Override public String toString(){ - StringBuilder result = new StringBuilder(); - - String delim = ", "; - result.append("P1=(") - .append(this.p1x).append(delim).append(this.p1y).append(") "); - result.append("P2=(") - .append(this.p2x).append(delim).append(this.p2y).append(")"); - - return result.toString(); + String msg = MessageFormat.format(MSG_TXT, + this.p1x, this.p1y, + this.p2x, this.p2y ); + return msg; } } diff --git a/src/main/java/jp/sourceforge/mikutoga/vmd/model/BoneMotion.java b/src/main/java/jp/sfjp/mikutoga/vmd/model/BoneMotion.java similarity index 82% rename from src/main/java/jp/sourceforge/mikutoga/vmd/model/BoneMotion.java rename to src/main/java/jp/sfjp/mikutoga/vmd/model/BoneMotion.java index 42e5afb..cea04e5 100644 --- a/src/main/java/jp/sourceforge/mikutoga/vmd/model/BoneMotion.java +++ b/src/main/java/jp/sfjp/mikutoga/vmd/model/BoneMotion.java @@ -5,11 +5,12 @@ * Copyright(c) 2011 MikuToga Partners */ -package jp.sourceforge.mikutoga.vmd.model; +package jp.sfjp.mikutoga.vmd.model; +import java.text.MessageFormat; import jp.sfjp.mikutoga.math.MkPos3D; import jp.sfjp.mikutoga.math.MkQuat; -import jp.sourceforge.mikutoga.vmd.AbstractNumbered; +import jp.sfjp.mikutoga.vmd.AbstractNumbered; /** * ボーンのモーション情報。 @@ -17,6 +18,13 @@ import jp.sourceforge.mikutoga.vmd.AbstractNumbered; */ public class BoneMotion extends AbstractNumbered { + private static final String MSG_TXT = + "bone name : [{0}] #{1}\n" + + "rotation {2} R-Bezier {3}\n" + + "position {4}\n" + + "{5}"; + + private String boneName; private final MkQuat rotation = new MkQuat(); @@ -107,18 +115,13 @@ public class BoneMotion extends AbstractNumbered { */ @Override public String toString(){ - StringBuilder result = new StringBuilder(); - - result.append("bone name : [").append(this.boneName); - result.append("] #").append(getFrameNumber()).append('\n'); - - result.append("rotation ").append(this.rotation); - result.append(" R-Bezier ").append(this.intpltRotation).append('\n'); - - result.append("position ").append(this.position).append('\n'); - result.append(this.posCurve); - - return result.toString(); + String msg; + msg = MessageFormat.format(MSG_TXT, + this.boneName, + getFrameNumber(), + this.rotation, this.intpltRotation, + this.position, this.posCurve ); + return msg; } } diff --git a/src/main/java/jp/sourceforge/mikutoga/vmd/model/CameraMotion.java b/src/main/java/jp/sfjp/mikutoga/vmd/model/CameraMotion.java similarity index 78% rename from src/main/java/jp/sourceforge/mikutoga/vmd/model/CameraMotion.java rename to src/main/java/jp/sfjp/mikutoga/vmd/model/CameraMotion.java index 46017b7..68d2f40 100644 --- a/src/main/java/jp/sourceforge/mikutoga/vmd/model/CameraMotion.java +++ b/src/main/java/jp/sfjp/mikutoga/vmd/model/CameraMotion.java @@ -5,10 +5,11 @@ * Copyright(c) 2011 MikuToga Partners */ -package jp.sourceforge.mikutoga.vmd.model; +package jp.sfjp.mikutoga.vmd.model; +import java.text.MessageFormat; import jp.sfjp.mikutoga.math.MkPos3D; -import jp.sourceforge.mikutoga.vmd.AbstractNumbered; +import jp.sfjp.mikutoga.vmd.AbstractNumbered; /** * カメラモーション情報。 @@ -22,13 +23,22 @@ import jp.sourceforge.mikutoga.vmd.AbstractNumbered; */ public class CameraMotion extends AbstractNumbered { + private static final String MSG_TXT = + "#{0} {1} Rot-Bezier {2}\n" + + "range : {3} Range-Bezier {4}\n" + + "target-pos : {5}\n" + + "{6}\n" + + "perspective : {7}\n" + + "projection angle : {8}deg Bezier {9}"; + + private final MkPos3D cameraTarget = new MkPos3D(); private final PosCurve posCurve = new PosCurve(); private final CameraRotation cameraRotation = new CameraRotation(); private final BezierParam intpltRotation = new BezierParam(); - private float range; + private double range; private final BezierParam intpltRange = new BezierParam(); private boolean hasPerspective; @@ -81,7 +91,7 @@ public class CameraMotion extends AbstractNumbered { * カメラ-ターゲット間の距離を返す。 * @return カメラ-ターゲット間の距離 */ - public float getRange(){ + public double getRange(){ return this.range; } @@ -89,7 +99,7 @@ public class CameraMotion extends AbstractNumbered { * カメラ-ターゲット間の距離を設定する。 * @param range カメラ-ターゲット間の距離 */ - public void setRange(float range){ + public void setRange(double range){ this.range = range; return; } @@ -150,28 +160,15 @@ public class CameraMotion extends AbstractNumbered { */ @Override public String toString(){ - StringBuilder result = new StringBuilder(); - - result.append("#").append(getFrameNumber()).append(' '); - result.append(this.cameraRotation); - result.append(" Rot-Bezier ") - .append(this.intpltRotation).append('\n'); - - result.append("range : ").append(this.range); - result.append(" Range-Bezier ").append(this.intpltRange).append('\n'); - - result.append("target-pos : ").append(this.cameraTarget).append('\n'); - result.append(this.posCurve).append('\n'); - - result.append("perspective : "); - if(this.hasPerspective) result.append("ON"); - else result.append("OFF"); - result.append('\n'); - - result.append("projection angle : ").append(this.projectionAngle); - result.append("deg Bezier ").append(this.intpltProjection); - - return result.toString(); + String msg; + msg = MessageFormat.format(MSG_TXT, + getFrameNumber(), + this.cameraRotation, this.intpltRotation, + this.range, this.intpltRange, + this.cameraTarget, this.posCurve, + this.hasPerspective, + this.projectionAngle, this.intpltProjection ); + return msg; } } diff --git a/src/main/java/jp/sourceforge/mikutoga/vmd/model/CameraRotation.java b/src/main/java/jp/sfjp/mikutoga/vmd/model/CameraRotation.java similarity index 71% rename from src/main/java/jp/sourceforge/mikutoga/vmd/model/CameraRotation.java rename to src/main/java/jp/sfjp/mikutoga/vmd/model/CameraRotation.java index 958e87b..c200306 100644 --- a/src/main/java/jp/sourceforge/mikutoga/vmd/model/CameraRotation.java +++ b/src/main/java/jp/sfjp/mikutoga/vmd/model/CameraRotation.java @@ -1,33 +1,43 @@ /* - * VMD camerawork handler + * camera rotation * * License : The MIT License * Copyright(c) 2011 MikuToga Partners */ -package jp.sourceforge.mikutoga.vmd.model; +package jp.sfjp.mikutoga.vmd.model; + +import java.text.MessageFormat; /** - * カメラの回転情報。 + * 左手系空間でターゲットの周りを回るカメラの回転情報。 + * いずれもカメラ姿勢ではなくカメラ運動量を示すため、 + * 回転量0と2Πの区別には意味がある。 *

latitudeはターゲットから見たカメラの仰俯角(≒緯度)。 * 単位はラジアン。 * Y軸回転量が0の時のZ正軸がY正軸へ倒れる方向が正回転。 * (MMDのUIとは符号が逆になるので注意) * 仰俯角が0の場合、 * カメラはターゲットに対しXZ平面(水平)と平行な箇所に位置する。 - *

longitudeはY軸周りの回転量(≒経度)。単位はラジアン。 + *

longitudeはY軸周りの回転量(≒経度)。 + * 単位はラジアン。 * X正軸がZ正軸へ倒れる方向が正回転。(ボーン回転と逆) * 仰俯角およびY軸回転量が0の場合、 * カメラレンズはZ軸-∞方向からZ軸+∞方向を向く。 *

rollはレンズをターゲットを向けたカメラのロール回転量。 + * 単位はラジアン。 * 仰俯角とY軸回転量が0の時にY正軸がX正軸に倒れる方向が正回転。 * 仰俯角およびロール回転量が0の場合、カメラ上部はY軸+∞の方を向く。 */ public class CameraRotation { - private float latitude; - private float longitude; - private float roll; + private static final String MSG_TXT = + "latitude={0} longitude={1} roll={2}"; + + + private double latitude; + private double longitude; + private double roll; /** @@ -43,7 +53,7 @@ public class CameraRotation { * ターゲットから見たカメラの仰俯角(≒緯度)を返す。 * @return ターゲットから見たカメラの仰俯角(≒緯度) */ - public float getLatitude(){ + public double getLatitude(){ return this.latitude; } @@ -51,7 +61,7 @@ public class CameraRotation { * ターゲットから見たカメラの仰俯角(≒緯度)を設定する。 * @param latitude ターゲットから見たカメラの仰俯角(≒緯度) */ - public void setLatitude(float latitude){ + public void setLatitude(double latitude){ this.latitude = latitude; return; } @@ -60,7 +70,7 @@ public class CameraRotation { * Y軸周りの回転量(≒経度)を返す。 * @return Y軸周りの回転量(≒経度) */ - public float getLongitude(){ + public double getLongitude(){ return this.longitude; } @@ -68,7 +78,7 @@ public class CameraRotation { * Y軸周りの回転量(≒経度)を設定する。 * @param longitude Y軸周りの回転量(≒経度) */ - public void setLongitude(float longitude){ + public void setLongitude(double longitude){ this.longitude = longitude; return; } @@ -77,7 +87,7 @@ public class CameraRotation { * レンズをターゲットを向けたカメラのロール回転量を返す。 * @return レンズをターゲットを向けたカメラのロール回転量 */ - public float getRoll(){ + public double getRoll(){ return this.roll; } @@ -85,7 +95,7 @@ public class CameraRotation { * レンズをターゲットを向けたカメラのロール回転量を設定する。 * @param roll レンズをターゲットを向けたカメラのロール回転量 */ - public void setRoll(float roll){ + public void setRoll(double roll){ this.roll = roll; return; } @@ -96,13 +106,10 @@ public class CameraRotation { */ @Override public String toString(){ - StringBuilder result = new StringBuilder(); - - result.append("latitude=").append(this.latitude); - result.append(" longitude=").append(this.longitude); - result.append(" roll=").append(this.roll); - - return result.toString(); + String msg; + msg = MessageFormat.format(MSG_TXT, + this.latitude, this.longitude, this.roll ); + return msg; } } diff --git a/src/main/java/jp/sourceforge/mikutoga/vmd/model/LuminousColor.java b/src/main/java/jp/sfjp/mikutoga/vmd/model/LuminousColor.java similarity index 86% rename from src/main/java/jp/sourceforge/mikutoga/vmd/model/LuminousColor.java rename to src/main/java/jp/sfjp/mikutoga/vmd/model/LuminousColor.java index b28b7c6..9133931 100644 --- a/src/main/java/jp/sourceforge/mikutoga/vmd/model/LuminousColor.java +++ b/src/main/java/jp/sfjp/mikutoga/vmd/model/LuminousColor.java @@ -5,7 +5,9 @@ * Copyright(c) 2011 MikuToga Partners */ -package jp.sourceforge.mikutoga.vmd.model; +package jp.sfjp.mikutoga.vmd.model; + +import java.text.MessageFormat; /** * 光源の色設定。 @@ -23,6 +25,12 @@ public class LuminousColor { /** デフォルトの成分値。 */ public static final float DEF_BRIGHT = 0.602f; // ≒ (154.0 / 256.0) + private static final String MSG_TXT = "r={0} g={1} b={2}"; + + static{ + assert 0.602f != 0.602; + } + private float colR = DEF_BRIGHT; private float colG = DEF_BRIGHT; @@ -96,13 +104,10 @@ public class LuminousColor { */ @Override public String toString(){ - StringBuilder result = new StringBuilder(); - - result.append("r=").append(this.colR); - result.append(" g=").append(this.colG); - result.append(" b=").append(this.colB); - - return result.toString(); + String msg; + msg = MessageFormat.format(MSG_TXT, + this.colR, this.colG, this.colB ); + return msg; } } diff --git a/src/main/java/jp/sfjp/mikutoga/vmd/model/LuminousMotion.java b/src/main/java/jp/sfjp/mikutoga/vmd/model/LuminousMotion.java new file mode 100644 index 0000000..ea05d46 --- /dev/null +++ b/src/main/java/jp/sfjp/mikutoga/vmd/model/LuminousMotion.java @@ -0,0 +1,81 @@ +/* + * luminous motion + * + * License : The MIT License + * Copyright(c) 2011 MikuToga Partners + */ + +package jp.sfjp.mikutoga.vmd.model; + +import java.text.MessageFormat; +import jp.sfjp.mikutoga.math.MkVec3D; +import jp.sfjp.mikutoga.vmd.AbstractNumbered; + +/** + * 光源演出情報。 + *

照明方向は、 + * ワールド座標原点から伸びる方向ベクトルとして記述される。 + * この方向ベクトルに向けて、無限遠の光源から照明が当たる。 + *

MMDのスライダUI上では + * 方向ベクトル各軸成分の定義域は-1.0以上+1.0以下だが、 + * さらに絶対値の大きな値を指定することも可能。 + *

方向ベクトルの長さは演出上の意味を持たないが、 + * キーフレーム間の照明方向の補間に影響を及ぼすかもしれない。 + *

方向ベクトルが零ベクトル(0,0,0)の場合、MMDでは全ポリゴンに影が落ちる。 + */ +public class LuminousMotion extends AbstractNumbered { + + /** デフォルトのX成分。 */ + public static final double DEF_VECX = -0.5; + /** デフォルトのY成分。 */ + public static final double DEF_VECY = -1.0; + /** デフォルトのZ成分。 */ + public static final double DEF_VECZ = +0.5; + + private static final String MSG_TXT = + "#{0} luminous color : {1} direction : {2}"; + + + private final LuminousColor color = new LuminousColor(); + private final MkVec3D direction = new MkVec3D(); + + + /** + * コンストラクタ。 + */ + public LuminousMotion(){ + super(); + this.direction.setVector(DEF_VECX, DEF_VECY, DEF_VECZ); + return; + } + + + /** + * 光源の色情報を返す。 + * @return 光源の色情報 + */ + public LuminousColor getColor(){ + return this.color; + } + + /** + * 光源からの照射方向情報を返す。 + * @return 光源からの照射方向情報 + */ + public MkVec3D getDirection(){ + return this.direction; + } + + /** + * {@inheritDoc} + * @return {@inheritDoc} + */ + @Override + public String toString(){ + String msg; + msg = MessageFormat.format(MSG_TXT, + getFrameNumber(), this.color, this.direction ); + return msg; + } + +} diff --git a/src/main/java/jp/sourceforge/mikutoga/vmd/model/MorphMotion.java b/src/main/java/jp/sfjp/mikutoga/vmd/model/MorphMotion.java similarity index 77% rename from src/main/java/jp/sourceforge/mikutoga/vmd/model/MorphMotion.java rename to src/main/java/jp/sfjp/mikutoga/vmd/model/MorphMotion.java index fe77f0d..1cb028c 100644 --- a/src/main/java/jp/sourceforge/mikutoga/vmd/model/MorphMotion.java +++ b/src/main/java/jp/sfjp/mikutoga/vmd/model/MorphMotion.java @@ -5,9 +5,10 @@ * Copyright(c) 2011 MikuToga Partners */ -package jp.sourceforge.mikutoga.vmd.model; +package jp.sfjp.mikutoga.vmd.model; -import jp.sourceforge.mikutoga.vmd.AbstractNumbered; +import java.text.MessageFormat; +import jp.sfjp.mikutoga.vmd.AbstractNumbered; /** * モーフ情報。 @@ -15,6 +16,10 @@ import jp.sourceforge.mikutoga.vmd.AbstractNumbered; */ public class MorphMotion extends AbstractNumbered { + private static final String MSG_TXT = + "morph name : [{0}] #{1} flex = {2}"; + + private String morphName = ""; private float flex = 0.0f; @@ -68,13 +73,10 @@ public class MorphMotion extends AbstractNumbered { */ @Override public String toString(){ - StringBuilder result = new StringBuilder(); - - result.append("morph name : [").append(this.morphName); - result.append("] #").append(getFrameNumber()); - result.append(" flex = ").append(this.flex); - - return result.toString(); + String msg; + msg = MessageFormat.format(MSG_TXT, + this.morphName, getFrameNumber(), this.flex ); + return msg; } } diff --git a/src/main/java/jp/sourceforge/mikutoga/vmd/model/PosCurve.java b/src/main/java/jp/sfjp/mikutoga/vmd/model/PosCurve.java similarity index 59% rename from src/main/java/jp/sourceforge/mikutoga/vmd/model/PosCurve.java rename to src/main/java/jp/sfjp/mikutoga/vmd/model/PosCurve.java index 6cf489c..e695d8e 100644 --- a/src/main/java/jp/sourceforge/mikutoga/vmd/model/PosCurve.java +++ b/src/main/java/jp/sfjp/mikutoga/vmd/model/PosCurve.java @@ -1,17 +1,27 @@ /* - * position curve + * position interpolation curve * * License : The MIT License * Copyright(c) 2011 MikuToga Partners */ -package jp.sourceforge.mikutoga.vmd.model; +package jp.sfjp.mikutoga.vmd.model; + +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; /** - * 3次元位置移動の補間情報。 + * 3次元位置移動のモーション補間曲線情報。 *

XYZ3軸それぞれに対応するベジェ曲線を3本持つ。 */ -public class PosCurve { +public class PosCurve implements Iterable { + + private static final int IT_SZ = 3; + private static final String MSG_TXT = + "X-Bezier {0}\n" + "Y-Bezier {1}\n" + "Z-Bezier {2}"; + private final BezierParam intpltXpos = new BezierParam(); private final BezierParam intpltYpos = new BezierParam(); @@ -28,6 +38,21 @@ public class PosCurve { /** + * {@inheritDoc} + * X軸、Y軸、Z軸の順で補間曲線情報を列挙する。 + * @return {@inheritDoc} 3要素を返す列挙子 + */ + @Override + public Iterator iterator(){ + List list; + list = new ArrayList(IT_SZ); + list.add(this.intpltXpos); + list.add(this.intpltYpos); + list.add(this.intpltZpos); + return list.iterator(); + } + + /** * ボーンX軸移動の補間曲線情報を返す。 * @return ボーンX軸移動の補間曲線情報 */ @@ -52,25 +77,6 @@ public class PosCurve { } /** - * インデックス指定された各軸の補間曲線情報を返す。 - *

インデックス値0がX軸、1がY軸、2がZ軸に対応する。 - * @param no インデックス値[0-2] - * @return 各軸の補間曲線情報 - * @throws IllegalArgumentException インデックス値が範囲外 - */ - public BezierParam item(int no) throws IllegalArgumentException { - BezierParam result; - switch(no){ - case 0: result = this.intpltXpos; break; - case 1: result = this.intpltYpos; break; - case 2: result = this.intpltZpos; break; - default: - throw new IllegalArgumentException(); - } - return result; - } - - /** * 3軸ともMMDデフォルトの直線補間か判定する。 * @return 3軸ともMMDデフォルトの直線補間ならtrue */ @@ -88,13 +94,11 @@ public class PosCurve { */ @Override public String toString(){ - StringBuilder result = new StringBuilder(); - - result.append("X-Bezier ").append(this.intpltXpos).append('\n'); - result.append("Y-Bezier ").append(this.intpltYpos).append('\n'); - result.append("Z-Bezier ").append(this.intpltZpos); + String msg; + msg = MessageFormat.format(MSG_TXT, + this.intpltXpos, this.intpltYpos, this.intpltZpos ); - return result.toString(); + return msg; } } diff --git a/src/main/java/jp/sourceforge/mikutoga/vmd/model/ShadowMode.java b/src/main/java/jp/sfjp/mikutoga/vmd/model/ShadowMode.java similarity index 98% rename from src/main/java/jp/sourceforge/mikutoga/vmd/model/ShadowMode.java rename to src/main/java/jp/sfjp/mikutoga/vmd/model/ShadowMode.java index 2cac757..06076e7 100644 --- a/src/main/java/jp/sourceforge/mikutoga/vmd/model/ShadowMode.java +++ b/src/main/java/jp/sfjp/mikutoga/vmd/model/ShadowMode.java @@ -5,7 +5,7 @@ * Copyright(c) 2011 MikuToga Partners */ -package jp.sourceforge.mikutoga.vmd.model; +package jp.sfjp.mikutoga.vmd.model; /** * セルフシャドウ描画モード。 diff --git a/src/main/java/jp/sourceforge/mikutoga/vmd/model/ShadowMotion.java b/src/main/java/jp/sfjp/mikutoga/vmd/model/ShadowMotion.java similarity index 75% rename from src/main/java/jp/sourceforge/mikutoga/vmd/model/ShadowMotion.java rename to src/main/java/jp/sfjp/mikutoga/vmd/model/ShadowMotion.java index 85c502f..6d5eb43 100644 --- a/src/main/java/jp/sourceforge/mikutoga/vmd/model/ShadowMotion.java +++ b/src/main/java/jp/sfjp/mikutoga/vmd/model/ShadowMotion.java @@ -5,9 +5,10 @@ * Copyright(c) 2011 MikuToga Partners */ -package jp.sourceforge.mikutoga.vmd.model; +package jp.sfjp.mikutoga.vmd.model; -import jp.sourceforge.mikutoga.vmd.AbstractNumbered; +import java.text.MessageFormat; +import jp.sfjp.mikutoga.vmd.AbstractNumbered; /** * 影(セルフシャドウ)演出情報。 @@ -17,7 +18,7 @@ import jp.sourceforge.mikutoga.vmd.AbstractNumbered; * 「 0.1 - (S / 1.0E+5) 」 * となる。 */ -public class ShadowMotion extends AbstractNumbered { +public strictfp class ShadowMotion extends AbstractNumbered { /** * デフォルトの影描画モード。 @@ -28,14 +29,22 @@ public class ShadowMotion extends AbstractNumbered { * デフォルトの範囲指定生パラメータ。 *

MMDのスライダUI値「8875」にほぼ相当。 */ - public static final float DEF_SCOPE = 0.01125f; + public static final double DEF_SCOPE = 0.01125; + private static final int DEF_UIVAL = 8875; private static final double OFFSET = 0.1; private static final double SCALE = 1.0E+5; + private static final String MSG_TXT = + "#{0} shadow mode : {1} rawparam={2}"; + + static{ + assert (float)(OFFSET - (DEF_UIVAL / SCALE)) == (float)DEF_SCOPE; + } + private ShadowMode shadowMode = DEF_MODE; - private float rawScopeParam = DEF_SCOPE; + private double rawScopeParam = DEF_SCOPE; /** @@ -53,7 +62,7 @@ public class ShadowMotion extends AbstractNumbered { * @param param 生パラメータ * @return MMDのスライダUI上の距離情報 */ - public static double rawParamToScope(float param){ + public static double rawParamToScope(double param){ double result; result = OFFSET - param; result *= SCALE; @@ -66,11 +75,11 @@ public class ShadowMotion extends AbstractNumbered { * @param scope MMDのスライダUI上の距離情報 * @return 生パラメータ */ - public static float scopeToRawParam(double scope){ + public static double scopeToRawParam(double scope){ double result; result = scope / SCALE; result = OFFSET - result; - return (float) result; + return result; } @@ -78,7 +87,7 @@ public class ShadowMotion extends AbstractNumbered { * 影演出の範囲指定の生パラメータを設定する。 * @param rawScopeParam 生パラメータ */ - public void setRawScopeParam(float rawScopeParam) { + public void setRawScopeParam(double rawScopeParam) { this.rawScopeParam = rawScopeParam; return; } @@ -87,7 +96,7 @@ public class ShadowMotion extends AbstractNumbered { * 影演出の範囲指定の生パラメータを返す。 * @return 生パラメータ */ - public float getRawScopeParam() { + public double getRawScopeParam() { return this.rawScopeParam; } @@ -96,7 +105,7 @@ public class ShadowMotion extends AbstractNumbered { * @param scope スライダUI値 */ public void setScope(double scope){ - float rawVal = scopeToRawParam(scope); + float rawVal = (float) scopeToRawParam(scope); setRawScopeParam(rawVal); return; } @@ -106,7 +115,7 @@ public class ShadowMotion extends AbstractNumbered { * @return スライダUI値 */ public double getScope(){ - float rawVal = getRawScopeParam(); + double rawVal = getRawScopeParam(); double scope = rawParamToScope(rawVal); return scope; } @@ -137,13 +146,12 @@ public class ShadowMotion extends AbstractNumbered { */ @Override public String toString(){ - StringBuilder result = new StringBuilder(); - - result.append("#").append(getFrameNumber()); - result.append(" shadow mode : ").append(this.shadowMode); - result.append(" rawparam=").append(this.rawScopeParam); - - return result.toString(); + String msg; + msg = MessageFormat.format(MSG_TXT, + getFrameNumber(), + this.shadowMode, + Double.toString(this.rawScopeParam) ); + return msg; } } diff --git a/src/main/java/jp/sourceforge/mikutoga/vmd/model/VmdMotion.java b/src/main/java/jp/sfjp/mikutoga/vmd/model/VmdMotion.java similarity index 55% rename from src/main/java/jp/sourceforge/mikutoga/vmd/model/VmdMotion.java rename to src/main/java/jp/sfjp/mikutoga/vmd/model/VmdMotion.java index 36812ff..a006061 100644 --- a/src/main/java/jp/sourceforge/mikutoga/vmd/model/VmdMotion.java +++ b/src/main/java/jp/sfjp/mikutoga/vmd/model/VmdMotion.java @@ -5,23 +5,31 @@ * Copyright(c) 2011 MikuToga Partners */ -package jp.sourceforge.mikutoga.vmd.model; +package jp.sfjp.mikutoga.vmd.model; +import java.text.MessageFormat; import java.util.Collections; +import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; -import jp.sourceforge.mikutoga.vmd.FrameNumbered; -import jp.sourceforge.mikutoga.vmd.VmdConst; +import java.util.Map; +import jp.sfjp.mikutoga.vmd.FrameNumbered; +import jp.sfjp.mikutoga.vmd.VmdUniq; /** * モーション及び演出情報。 */ public class VmdMotion { - private String modelName = VmdConst.MODELNAME_STAGEACT; + private static final String MSG_TXT = + "model name : {0}\n" + + "bone#{1} morph#{2} camera#{3} luminous#{4} shadow#{5}"; - private final NamedListMap bonePartMap; - private final NamedListMap morphPartMap; + + private String modelName = VmdUniq.MODELNAME_STAGEACT; + + private final Map> bonePartMap; + private final Map> morphPartMap; private final List cameraMotionList; private final List luminousMotionList; @@ -34,8 +42,8 @@ public class VmdMotion { public VmdMotion(){ super(); - this.bonePartMap = new NamedListMap(); - this.morphPartMap = new NamedListMap(); + this.bonePartMap = new LinkedHashMap>(); + this.morphPartMap = new LinkedHashMap>(); this.cameraMotionList = new LinkedList(); this.luminousMotionList = new LinkedList(); @@ -59,6 +67,7 @@ public class VmdMotion { * このモデル名で判別される。 * @param modelName モデル名 * @throws NullPointerException 引数がnull + * @see jp.sfjp.mikutoga.vmd.VmdUniq#MODELNAME_STAGEACT */ public void setModelName(String modelName) throws NullPointerException{ if(modelName == null) throw new NullPointerException(); @@ -70,9 +79,10 @@ public class VmdMotion { * モデルモーションか否か判別する。 *

判別は特殊なモデル名を持つか否かで決定される。 * @return モデルモーションならtrue + * @see jp.sfjp.mikutoga.vmd.VmdUniq#MODELNAME_STAGEACT */ public boolean isModelMotion(){ - if(VmdConst.isStageActName(this.modelName)){ + if(VmdUniq.isStageActName(this.modelName)){ return false; } @@ -80,18 +90,20 @@ public class VmdMotion { } /** - * 名前付きボーンモーションマップを返す。 - * @return 名前付きボーンモーションマップ + * 順序保証されたボーンモーションマップを返す。 + * @return ボーンモーションマップ + * @see java.util.LinkedHashMap */ - public NamedListMap getBonePartMap(){ + public Map> getBonePartMap(){ return this.bonePartMap; } /** - * 名前付きモーフモーションマップを返す。 - * @return 名前付きモーフモーションマップ + * 順序保証されたモーフモーションマップを返す。 + * @return モーフモーションマップ + * @see java.util.LinkedHashMap */ - public NamedListMap getMorphPartMap(){ + public Map> getMorphPartMap(){ return this.morphPartMap; } @@ -121,21 +133,41 @@ public class VmdMotion { /** * ボーンモーションを追加する。 + * 追加順は保持される。 * @param motion ボーンモーション + * @see java.util.LinkedHashMap */ public void addBoneMotion(BoneMotion motion){ String name = motion.getBoneName(); - this.bonePartMap.addNamedElement(name, motion); + + List list = this.bonePartMap.get(name); + if(list == null){ + list = new LinkedList(); + this.bonePartMap.put(name, list); + } + + list.add(motion); + return; } /** * モーフモーションを追加する。 + * 追加順は保持される。 * @param motion モーフモーション + * @see java.util.LinkedHashMap */ public void addMorphMotion(MorphMotion motion){ String name = motion.getMorphName(); - this.morphPartMap.addNamedElement(name, motion); + + List list = this.morphPartMap.get(name); + if(list == null){ + list = new LinkedList(); + this.morphPartMap.put(name, list); + } + + list.add(motion); + return; } @@ -143,16 +175,12 @@ public class VmdMotion { * 各データをフレーム番号順に昇順ソートする。 */ public void frameSort(){ - for(String name : this.bonePartMap.getNames()){ - List motionList = - this.bonePartMap.getNamedList(name); - Collections.sort(motionList, FrameNumbered.COMPARATOR); + for(List list : this.bonePartMap.values()){ + Collections.sort(list, FrameNumbered.COMPARATOR); } - for(String name : this.morphPartMap.getNames()){ - List motionList = - this.morphPartMap.getNamedList(name); - Collections.sort(motionList, FrameNumbered.COMPARATOR); + for(List list : this.morphPartMap.values()){ + Collections.sort(list, FrameNumbered.COMPARATOR); } Collections.sort(this.cameraMotionList, FrameNumbered.COMPARATOR); @@ -168,44 +196,26 @@ public class VmdMotion { */ @Override public String toString(){ - String dash = "---"; - - StringBuilder result = new StringBuilder(); - - result.append("model name : ").append(this.modelName).append('\n'); - - for(String boneName : this.bonePartMap.getNames()){ - List motionList = - this.bonePartMap.getNamedList(boneName); - for(BoneMotion motion : motionList){ - result.append(dash).append('\n'); - result.append(motion.toString()).append('\n'); - } + int boneNo = 0; + for(List motionList : this.bonePartMap.values()){ + boneNo += motionList.size(); } - for(String morphName : this.morphPartMap.getNames()){ - if(VmdConst.isBaseMorphName(morphName)) continue; - List motionList = - this.morphPartMap.getNamedList(morphName); - for(MorphMotion morph : motionList){ - result.append(morph.toString()).append('\n'); - } + int morphNo = 0; + for(List motionList : this.morphPartMap.values()){ + morphNo += motionList.size(); } - for(CameraMotion camera : this.cameraMotionList){ - result.append(dash).append('\n'); - result.append(camera.toString()).append('\n'); - } - - for(LuminousMotion luminous : this.luminousMotionList){ - result.append(luminous.toString()).append('\n'); - } + int cameraNo = this.cameraMotionList .size(); + int luminousNo = this.luminousMotionList.size(); + int shadowNo = this.shadowMotionList .size(); - for(ShadowMotion shadow : this.shadowMotionList){ - result.append(shadow.toString()).append('\n'); - } + String msg; + msg = MessageFormat.format(MSG_TXT, + this.modelName, + boneNo, morphNo, cameraNo, luminousNo, shadowNo ); - return result.toString(); + return msg; } } diff --git a/src/main/java/jp/sourceforge/mikutoga/vmd/model/binio/BasicExporter.java b/src/main/java/jp/sfjp/mikutoga/vmd/model/binio/BasicExporter.java similarity index 56% rename from src/main/java/jp/sourceforge/mikutoga/vmd/model/binio/BasicExporter.java rename to src/main/java/jp/sfjp/mikutoga/vmd/model/binio/BasicExporter.java index 2e5be19..6567d65 100644 --- a/src/main/java/jp/sourceforge/mikutoga/vmd/model/binio/BasicExporter.java +++ b/src/main/java/jp/sfjp/mikutoga/vmd/model/binio/BasicExporter.java @@ -5,23 +5,26 @@ * Copyright(c) 2011 MikuToga Partners */ -package jp.sourceforge.mikutoga.vmd.model.binio; +package jp.sfjp.mikutoga.vmd.model.binio; import java.io.IOException; import java.io.OutputStream; +import java.nio.ByteBuffer; +import java.nio.charset.Charset; import java.util.LinkedList; import java.util.List; +import java.util.Map; import jp.sfjp.mikutoga.bin.export.BinaryExporter; import jp.sfjp.mikutoga.bin.export.IllegalTextExportException; import jp.sfjp.mikutoga.math.MkPos3D; import jp.sfjp.mikutoga.math.MkQuat; -import jp.sourceforge.mikutoga.vmd.VmdConst; -import jp.sourceforge.mikutoga.vmd.model.BezierParam; -import jp.sourceforge.mikutoga.vmd.model.BoneMotion; -import jp.sourceforge.mikutoga.vmd.model.MorphMotion; -import jp.sourceforge.mikutoga.vmd.model.NamedListMap; -import jp.sourceforge.mikutoga.vmd.model.PosCurve; -import jp.sourceforge.mikutoga.vmd.model.VmdMotion; +import jp.sfjp.mikutoga.vmd.VmdConst; +import jp.sfjp.mikutoga.vmd.VmdUniq; +import jp.sfjp.mikutoga.vmd.model.BezierParam; +import jp.sfjp.mikutoga.vmd.model.BoneMotion; +import jp.sfjp.mikutoga.vmd.model.MorphMotion; +import jp.sfjp.mikutoga.vmd.model.PosCurve; +import jp.sfjp.mikutoga.vmd.model.VmdMotion; /** * ボーンモーション及びモーフ情報のエクスポーター。 @@ -33,11 +36,20 @@ class BasicExporter extends BinaryExporter { private static final int BZ_REDUNDANT = 4; // redundant spare private static final int BZTOTAL_SIZE = BZXYZR_SIZE * BZ_REDUNDANT; + private static final Charset CS_ASCII = Charset.forName("US-ASCII"); + private static final String HEADFILLER = "\u0000" + "JKLM"; private static final byte[] FDFILLER = { (byte)0x00, (byte)0xfd }; + private static final byte[] INTPLT_FILLER = { + (byte) 0x01, // 0x00の版もあり。 + (byte) 0x00, + (byte) 0x00, + }; private final byte[] motionIntplt = new byte[BZTOTAL_SIZE]; + private final ByteBuffer intpltBuf; + private final ByteBuffer rdBuf; /** @@ -46,9 +58,47 @@ class BasicExporter extends BinaryExporter { */ BasicExporter(OutputStream stream){ super(stream); + + this.intpltBuf = ByteBuffer.wrap(this.motionIntplt); + ByteBuffer buf = ByteBuffer.wrap(this.motionIntplt, 0, BZXYZR_SIZE); + this.rdBuf = buf.asReadOnlyBuffer(); + + return; + } + + + /** + * ヘッダ情報を出力する。 + * @throws IOException 出力エラー + */ + void dumpHeader() throws IOException{ + byte[] header = (VmdConst.MAGIC_TXT + HEADFILLER).getBytes(CS_ASCII); + assert header.length == VmdConst.HEADER_LENGTH; + + dumpByteArray(header); + return; } + /** + * モデル名を出力する。 + *

演出データのモデル名には + * 便宜的に + * {@link jp.sfjp.mikutoga.vmd.VmdUniq#MODELNAME_STAGEACT} + * が使われる。 + * @param motion モーションデータ + * @throws IOException 出力エラー + * @throws IllegalTextExportException 不正なモデル名の出現 + */ + void dumpModelName(VmdMotion motion) + throws IOException, IllegalTextExportException{ + String modelName = motion.getModelName(); + if(modelName == null) modelName = VmdUniq.MODELNAME_STAGEACT; + + dumpFixedW31j(modelName, VmdConst.MODELNAME_MAX, FDFILLER); + + return; + } /** * ボーンモーション情報を出力する。 @@ -58,20 +108,13 @@ class BasicExporter extends BinaryExporter { */ void dumpBoneMotion(VmdMotion motion) throws IOException, IllegalTextExportException{ - NamedListMap map = motion.getBonePartMap(); - List nameList = map.getNames(); + Map> map = motion.getBonePartMap(); List bmotionList = new LinkedList(); - - int count = 0; - for(String name : nameList){ - List namedList = map.getNamedList(name); - for(BoneMotion boneMotion : namedList){ - bmotionList.add(boneMotion); - count++; - } + for(List eachList : map.values()){ + bmotionList.addAll(eachList); } - dumpLeInt(count); + dumpLeInt(bmotionList.size()); for(BoneMotion boneMotion : bmotionList){ String boneName = boneMotion.getBoneName(); @@ -143,29 +186,29 @@ class BasicExporter extends BinaryExporter { BezierParam zCurve = posCurve.getIntpltZpos(); BezierParam rCurve = boneMotion.getIntpltRotation(); - int idx = 0; + this.intpltBuf.clear(); - this.motionIntplt[idx++] = xCurve.getP1x(); - this.motionIntplt[idx++] = yCurve.getP1x(); - this.motionIntplt[idx++] = zCurve.getP1x(); - this.motionIntplt[idx++] = rCurve.getP1x(); + this.intpltBuf.put(xCurve.getP1x()); + this.intpltBuf.put(yCurve.getP1x()); + this.intpltBuf.put(zCurve.getP1x()); + this.intpltBuf.put(rCurve.getP1x()); - this.motionIntplt[idx++] = xCurve.getP1y(); - this.motionIntplt[idx++] = yCurve.getP1y(); - this.motionIntplt[idx++] = zCurve.getP1y(); - this.motionIntplt[idx++] = rCurve.getP1y(); + this.intpltBuf.put(xCurve.getP1y()); + this.intpltBuf.put(yCurve.getP1y()); + this.intpltBuf.put(zCurve.getP1y()); + this.intpltBuf.put(rCurve.getP1y()); - this.motionIntplt[idx++] = xCurve.getP2x(); - this.motionIntplt[idx++] = yCurve.getP2x(); - this.motionIntplt[idx++] = zCurve.getP2x(); - this.motionIntplt[idx++] = rCurve.getP2x(); + this.intpltBuf.put(xCurve.getP2x()); + this.intpltBuf.put(yCurve.getP2x()); + this.intpltBuf.put(zCurve.getP2x()); + this.intpltBuf.put(rCurve.getP2x()); - this.motionIntplt[idx++] = xCurve.getP2y(); - this.motionIntplt[idx++] = yCurve.getP2y(); - this.motionIntplt[idx++] = zCurve.getP2y(); - this.motionIntplt[idx++] = rCurve.getP2y(); + this.intpltBuf.put(xCurve.getP2y()); + this.intpltBuf.put(yCurve.getP2y()); + this.intpltBuf.put(zCurve.getP2y()); + this.intpltBuf.put(rCurve.getP2y()); - assert idx == BZXYZR_SIZE; + assert this.intpltBuf.position() == BZXYZR_SIZE; redundantCopy(); @@ -176,30 +219,19 @@ class BasicExporter extends BinaryExporter { /** * 補間情報冗長部の組み立て。 + *

※ MMDの版によって若干出力内容が異なる。 */ private void redundantCopy(){ - int lack = 1; - for(int ct = 1; ct < BZ_REDUNDANT; ct++){ - int sourceIdx = 0 + lack; - int targetIdx = BZXYZR_SIZE * ct; - int span = BZXYZR_SIZE - lack; - - System.arraycopy(this.motionIntplt, sourceIdx, - this.motionIntplt, targetIdx, - span ); - - int onePos = targetIdx + span; - this.motionIntplt[onePos] = (byte) 0x01; - - int zeroPosStart = onePos + 1; - int zeroPosEnd = targetIdx + BZXYZR_SIZE; - for(int idx = zeroPosStart; idx < zeroPosEnd; idx++){ - this.motionIntplt[idx] = (byte) 0x00; - } - - lack++; + this.intpltBuf.position(BZXYZR_SIZE); + + for(int lack = 1; lack < BZ_REDUNDANT; lack++){ + this.rdBuf.position(lack); + this.intpltBuf.put(this.rdBuf); + this.intpltBuf.put(INTPLT_FILLER, 0, lack); } + assert this.intpltBuf.position() == BZTOTAL_SIZE; + return; } @@ -211,20 +243,13 @@ class BasicExporter extends BinaryExporter { */ void dumpMorphMotion(VmdMotion motion) throws IOException, IllegalTextExportException{ - NamedListMap map = motion.getMorphPartMap(); - List nameList = map.getNames(); + Map> map = motion.getMorphPartMap(); List morphList = new LinkedList(); - - int count = 0; - for(String name : nameList){ - List namedList = map.getNamedList(name); - for(MorphMotion morphMotion : namedList){ - morphList.add(morphMotion); - count++; - } + for(List eachList : map.values()){ + morphList.addAll(eachList); } - dumpLeInt(count); + dumpLeInt(morphList.size()); for(MorphMotion morphMotion : morphList){ String morphName = morphMotion.getMorphName(); diff --git a/src/main/java/jp/sourceforge/mikutoga/vmd/model/binio/BasicLoader.java b/src/main/java/jp/sfjp/mikutoga/vmd/model/binio/BasicLoader.java similarity index 93% rename from src/main/java/jp/sourceforge/mikutoga/vmd/model/binio/BasicLoader.java rename to src/main/java/jp/sfjp/mikutoga/vmd/model/binio/BasicLoader.java index f92ce45..48069e5 100644 --- a/src/main/java/jp/sourceforge/mikutoga/vmd/model/binio/BasicLoader.java +++ b/src/main/java/jp/sfjp/mikutoga/vmd/model/binio/BasicLoader.java @@ -5,18 +5,18 @@ * Copyright(c) 2011 MikuToga Partners */ -package jp.sourceforge.mikutoga.vmd.model.binio; +package jp.sfjp.mikutoga.vmd.model.binio; import jp.sfjp.mikutoga.bin.parser.MmdFormatException; import jp.sfjp.mikutoga.bin.parser.ParseStage; import jp.sfjp.mikutoga.math.MkPos3D; import jp.sfjp.mikutoga.math.MkQuat; -import jp.sourceforge.mikutoga.vmd.model.BezierParam; -import jp.sourceforge.mikutoga.vmd.model.BoneMotion; -import jp.sourceforge.mikutoga.vmd.model.MorphMotion; -import jp.sourceforge.mikutoga.vmd.model.PosCurve; -import jp.sourceforge.mikutoga.vmd.model.VmdMotion; -import jp.sourceforge.mikutoga.vmd.parser.VmdBasicHandler; +import jp.sfjp.mikutoga.vmd.model.BezierParam; +import jp.sfjp.mikutoga.vmd.model.BoneMotion; +import jp.sfjp.mikutoga.vmd.model.MorphMotion; +import jp.sfjp.mikutoga.vmd.model.PosCurve; +import jp.sfjp.mikutoga.vmd.model.VmdMotion; +import jp.sfjp.mikutoga.vmd.parser.VmdBasicHandler; /** * ボーンモーション、モーフ情報のビルダ。 @@ -33,7 +33,7 @@ class BasicLoader implements VmdBasicHandler { /** * コンストラクタ。 - * @param vmdMotion モーション情報 + * @param vmdMotion モーションデータの格納先 */ BasicLoader(VmdMotion vmdMotion){ super(); @@ -75,7 +75,9 @@ class BasicLoader implements VmdBasicHandler { */ @Override public void vmdParseStart() throws MmdFormatException{ - // NOTHING + assert this.currentBoneMotion == null; + assert this.currentMorphMotion == null; + return; } @@ -88,6 +90,10 @@ class BasicLoader implements VmdBasicHandler { public void vmdParseEnd(boolean hasMoreDataArg) throws MmdFormatException{ this.hasMoreData = hasMoreDataArg; + + assert this.currentBoneMotion == null; + assert this.currentMorphMotion == null; + return; } @@ -149,7 +155,7 @@ class BasicLoader implements VmdBasicHandler { */ @Override public void vmdHeaderInfo(byte[] header) throws MmdFormatException{ - // NOTHING + assert header != null; return; } diff --git a/src/main/java/jp/sourceforge/mikutoga/vmd/model/binio/CameraExporter.java b/src/main/java/jp/sfjp/mikutoga/vmd/model/binio/CameraExporter.java similarity index 85% rename from src/main/java/jp/sourceforge/mikutoga/vmd/model/binio/CameraExporter.java rename to src/main/java/jp/sfjp/mikutoga/vmd/model/binio/CameraExporter.java index 0c00cdc..e8594ee 100644 --- a/src/main/java/jp/sourceforge/mikutoga/vmd/model/binio/CameraExporter.java +++ b/src/main/java/jp/sfjp/mikutoga/vmd/model/binio/CameraExporter.java @@ -5,18 +5,18 @@ * Copyright(c) 2011 MikuToga Partners */ -package jp.sourceforge.mikutoga.vmd.model.binio; +package jp.sfjp.mikutoga.vmd.model.binio; import java.io.IOException; import java.io.OutputStream; import java.util.List; import jp.sfjp.mikutoga.bin.export.BinaryExporter; import jp.sfjp.mikutoga.math.MkPos3D; -import jp.sourceforge.mikutoga.vmd.model.BezierParam; -import jp.sourceforge.mikutoga.vmd.model.CameraMotion; -import jp.sourceforge.mikutoga.vmd.model.CameraRotation; -import jp.sourceforge.mikutoga.vmd.model.PosCurve; -import jp.sourceforge.mikutoga.vmd.model.VmdMotion; +import jp.sfjp.mikutoga.vmd.model.BezierParam; +import jp.sfjp.mikutoga.vmd.model.CameraMotion; +import jp.sfjp.mikutoga.vmd.model.CameraRotation; +import jp.sfjp.mikutoga.vmd.model.PosCurve; +import jp.sfjp.mikutoga.vmd.model.VmdMotion; /** * カメラ情報のエクスポーター。 @@ -48,7 +48,7 @@ class CameraExporter extends BinaryExporter { int frame = cameraMotion.getFrameNumber(); dumpLeInt(frame); - float range = cameraMotion.getRange(); + float range = (float) cameraMotion.getRange(); dumpLeFloat(range); MkPos3D targetPos = cameraMotion.getCameraTarget(); @@ -57,9 +57,9 @@ class CameraExporter extends BinaryExporter { dumpLeFloat((float) targetPos.getZpos()); CameraRotation rotation = cameraMotion.getCameraRotation(); - dumpLeFloat(rotation.getLatitude()); - dumpLeFloat(rotation.getLongitude()); - dumpLeFloat(rotation.getRoll()); + dumpLeFloat((float) rotation.getLatitude()); + dumpLeFloat((float) rotation.getLongitude()); + dumpLeFloat((float) rotation.getRoll()); dumpCameraCurve(cameraMotion); diff --git a/src/main/java/jp/sourceforge/mikutoga/vmd/model/binio/CameraLoader.java b/src/main/java/jp/sfjp/mikutoga/vmd/model/binio/CameraLoader.java similarity index 92% rename from src/main/java/jp/sourceforge/mikutoga/vmd/model/binio/CameraLoader.java rename to src/main/java/jp/sfjp/mikutoga/vmd/model/binio/CameraLoader.java index 5efa609..36e7eb0 100644 --- a/src/main/java/jp/sourceforge/mikutoga/vmd/model/binio/CameraLoader.java +++ b/src/main/java/jp/sfjp/mikutoga/vmd/model/binio/CameraLoader.java @@ -5,17 +5,18 @@ * Copyright(c) 2011 MikuToga Partners */ -package jp.sourceforge.mikutoga.vmd.model.binio; +package jp.sfjp.mikutoga.vmd.model.binio; import java.util.List; import jp.sfjp.mikutoga.bin.parser.MmdFormatException; import jp.sfjp.mikutoga.bin.parser.ParseStage; -import jp.sourceforge.mikutoga.vmd.model.BezierParam; -import jp.sourceforge.mikutoga.vmd.model.CameraMotion; -import jp.sourceforge.mikutoga.vmd.model.CameraRotation; -import jp.sourceforge.mikutoga.vmd.model.PosCurve; -import jp.sourceforge.mikutoga.vmd.model.VmdMotion; -import jp.sourceforge.mikutoga.vmd.parser.VmdCameraHandler; +import jp.sfjp.mikutoga.math.MkPos3D; +import jp.sfjp.mikutoga.vmd.model.BezierParam; +import jp.sfjp.mikutoga.vmd.model.CameraMotion; +import jp.sfjp.mikutoga.vmd.model.CameraRotation; +import jp.sfjp.mikutoga.vmd.model.PosCurve; +import jp.sfjp.mikutoga.vmd.model.VmdMotion; +import jp.sfjp.mikutoga.vmd.parser.VmdCameraHandler; /** * カメラ情報のビルダ。 @@ -29,7 +30,7 @@ class CameraLoader implements VmdCameraHandler { /** * コンストラクタ。 - * @param vmdMotion モーションデータ。 + * @param vmdMotion モーションデータの格納先。 */ CameraLoader(VmdMotion vmdMotion){ super(); @@ -98,8 +99,8 @@ class CameraLoader implements VmdCameraHandler { @Override public void vmdCameraPosition(float xPos, float yPos, float zPos) throws MmdFormatException{ - this.currentCameraMotion.getCameraTarget() - .setPosition(xPos, yPos, zPos); + MkPos3D cameraPos = this.currentCameraMotion.getCameraTarget(); + cameraPos.setPosition(xPos, yPos, zPos); return; } diff --git a/src/main/java/jp/sourceforge/mikutoga/vmd/model/binio/LightingExporter.java b/src/main/java/jp/sfjp/mikutoga/vmd/model/binio/LightingExporter.java similarity index 75% rename from src/main/java/jp/sourceforge/mikutoga/vmd/model/binio/LightingExporter.java rename to src/main/java/jp/sfjp/mikutoga/vmd/model/binio/LightingExporter.java index ec9746f..c77f663 100644 --- a/src/main/java/jp/sourceforge/mikutoga/vmd/model/binio/LightingExporter.java +++ b/src/main/java/jp/sfjp/mikutoga/vmd/model/binio/LightingExporter.java @@ -5,18 +5,18 @@ * Copyright(c) 2011 MikuToga Partners */ -package jp.sourceforge.mikutoga.vmd.model.binio; +package jp.sfjp.mikutoga.vmd.model.binio; import java.io.IOException; import java.io.OutputStream; import java.util.List; import jp.sfjp.mikutoga.bin.export.BinaryExporter; -import jp.sourceforge.mikutoga.vmd.model.LuminousColor; -import jp.sourceforge.mikutoga.vmd.model.LuminousMotion; -import jp.sourceforge.mikutoga.vmd.model.LuminousVector; -import jp.sourceforge.mikutoga.vmd.model.ShadowMode; -import jp.sourceforge.mikutoga.vmd.model.ShadowMotion; -import jp.sourceforge.mikutoga.vmd.model.VmdMotion; +import jp.sfjp.mikutoga.math.MkVec3D; +import jp.sfjp.mikutoga.vmd.model.LuminousColor; +import jp.sfjp.mikutoga.vmd.model.LuminousMotion; +import jp.sfjp.mikutoga.vmd.model.ShadowMode; +import jp.sfjp.mikutoga.vmd.model.ShadowMotion; +import jp.sfjp.mikutoga.vmd.model.VmdMotion; /** * ライティング情報のエクスポーター。 @@ -53,10 +53,10 @@ class LightingExporter extends BinaryExporter { dumpLeFloat(color.getColG()); dumpLeFloat(color.getColB()); - LuminousVector vector = luminousMotion.getDirection(); - dumpLeFloat(vector.getVecX()); - dumpLeFloat(vector.getVecY()); - dumpLeFloat(vector.getVecZ()); + MkVec3D vector = luminousMotion.getDirection(); + dumpLeFloat((float) vector.getXVal()); + dumpLeFloat((float) vector.getYVal()); + dumpLeFloat((float) vector.getZVal()); } return; @@ -81,7 +81,7 @@ class LightingExporter extends BinaryExporter { byte shadowType = mode.getEncodedByte(); dumpByte(shadowType); - float rawParam = shadowMotion.getRawScopeParam(); + float rawParam = (float) shadowMotion.getRawScopeParam(); dumpLeFloat(rawParam); } diff --git a/src/main/java/jp/sourceforge/mikutoga/vmd/model/binio/LightingLoader.java b/src/main/java/jp/sfjp/mikutoga/vmd/model/binio/LightingLoader.java similarity index 88% rename from src/main/java/jp/sourceforge/mikutoga/vmd/model/binio/LightingLoader.java rename to src/main/java/jp/sfjp/mikutoga/vmd/model/binio/LightingLoader.java index 0c9c5e4..9d34d2f 100644 --- a/src/main/java/jp/sourceforge/mikutoga/vmd/model/binio/LightingLoader.java +++ b/src/main/java/jp/sfjp/mikutoga/vmd/model/binio/LightingLoader.java @@ -5,18 +5,18 @@ * Copyright(c) 2011 MikuToga Partners */ -package jp.sourceforge.mikutoga.vmd.model.binio; +package jp.sfjp.mikutoga.vmd.model.binio; import java.util.List; import jp.sfjp.mikutoga.bin.parser.MmdFormatException; import jp.sfjp.mikutoga.bin.parser.ParseStage; -import jp.sourceforge.mikutoga.vmd.model.LuminousColor; -import jp.sourceforge.mikutoga.vmd.model.LuminousMotion; -import jp.sourceforge.mikutoga.vmd.model.LuminousVector; -import jp.sourceforge.mikutoga.vmd.model.ShadowMode; -import jp.sourceforge.mikutoga.vmd.model.ShadowMotion; -import jp.sourceforge.mikutoga.vmd.model.VmdMotion; -import jp.sourceforge.mikutoga.vmd.parser.VmdLightingHandler; +import jp.sfjp.mikutoga.math.MkVec3D; +import jp.sfjp.mikutoga.vmd.model.LuminousColor; +import jp.sfjp.mikutoga.vmd.model.LuminousMotion; +import jp.sfjp.mikutoga.vmd.model.ShadowMode; +import jp.sfjp.mikutoga.vmd.model.ShadowMotion; +import jp.sfjp.mikutoga.vmd.model.VmdMotion; +import jp.sfjp.mikutoga.vmd.parser.VmdLightingHandler; /** * ライティング情報のビルダ。 @@ -32,7 +32,7 @@ class LightingLoader implements VmdLightingHandler { /** * コンストラクタ。 - * @param vmdMotion モーションデータ。 + * @param vmdMotion モーションデータの格納先。 */ LightingLoader(VmdMotion vmdMotion){ super(); @@ -158,10 +158,10 @@ class LightingLoader implements VmdLightingHandler { @Override public void vmdLuminousDirection(float xVec, float yVec, float zVec) throws MmdFormatException{ - LuminousVector direction = this.currentLuminousMotion.getDirection(); - direction.setVecX(xVec); - direction.setVecY(yVec); - direction.setVecZ(zVec); + MkVec3D direction = this.currentLuminousMotion.getDirection(); + direction.setXVal(xVec); + direction.setYVal(yVec); + direction.setZVal(zVec); return; } diff --git a/src/main/java/jp/sfjp/mikutoga/vmd/model/binio/VmdExporter.java b/src/main/java/jp/sfjp/mikutoga/vmd/model/binio/VmdExporter.java new file mode 100644 index 0000000..dd377e7 --- /dev/null +++ b/src/main/java/jp/sfjp/mikutoga/vmd/model/binio/VmdExporter.java @@ -0,0 +1,82 @@ +/* + * vmd exporter + * + * License : The MIT License + * Copyright(c) 2011 MikuToga Partners + */ + +package jp.sfjp.mikutoga.vmd.model.binio; + +import java.io.IOException; +import java.io.OutputStream; +import jp.sfjp.mikutoga.bin.export.IllegalTextExportException; +import jp.sfjp.mikutoga.vmd.IllegalVmdDataException; +import jp.sfjp.mikutoga.vmd.model.VmdMotion; + +/** + * VMDファイルのエクスポーター。 + */ +public class VmdExporter { + + private BasicExporter basicExporter; + private CameraExporter cameraExporter; + private LightingExporter lightingExporter; + + + /** + * コンストラクタ。 + */ + public VmdExporter(){ + super(); + return; + } + + /** + * モーションデータをVMDファイル形式で出力する。 + *

異常時には出力データのフラッシュが試みられる。 + * @param motion モーションデータ + * @param ostream 出力先ストリーム + * @throws IOException 出力エラー + * @throws IllegalVmdDataException モーションデータに不備が発見された + */ + public void dumpVmdMotion(VmdMotion motion, OutputStream ostream) + throws IOException, IllegalVmdDataException{ + this.basicExporter = new BasicExporter(ostream); + this.cameraExporter = new CameraExporter(ostream); + this.lightingExporter = new LightingExporter(ostream); + + try{ + dumpVmdMotionImpl(motion); + }finally{ + ostream.flush(); + } + + return; + } + + /** + * モーションデータをVMDファイル形式で出力する。 + * @param motion モーションデータ + * @throws IOException 出力エラー + * @throws IllegalVmdDataException モーションデータに不備が発見された + */ + private void dumpVmdMotionImpl(VmdMotion motion) + throws IOException, IllegalVmdDataException{ + this.basicExporter.dumpHeader(); + + try{ + this.basicExporter.dumpModelName(motion); + this.basicExporter.dumpBoneMotion(motion); + this.basicExporter.dumpMorphMotion(motion); + }catch(IllegalTextExportException e){ + throw new IllegalVmdDataException(e); + } + + this.cameraExporter.dumpCameraMotion(motion); + this.lightingExporter.dumpLuminousMotion(motion); + this.lightingExporter.dumpShadowMotion(motion); + + return; + } + +} diff --git a/src/main/java/jp/sfjp/mikutoga/vmd/model/binio/VmdLoader.java b/src/main/java/jp/sfjp/mikutoga/vmd/model/binio/VmdLoader.java new file mode 100644 index 0000000..be7d841 --- /dev/null +++ b/src/main/java/jp/sfjp/mikutoga/vmd/model/binio/VmdLoader.java @@ -0,0 +1,116 @@ +/* + * VMD file loader + * + * License : The MIT License + * Copyright(c) 2011 MikuToga Partners + */ + +package jp.sfjp.mikutoga.vmd.model.binio; + +import java.io.IOException; +import java.io.InputStream; +import jp.sfjp.mikutoga.bin.parser.MmdFormatException; +import jp.sfjp.mikutoga.vmd.model.VmdMotion; +import jp.sfjp.mikutoga.vmd.parser.VmdParser; + +/** + * VMDモーションファイルを読み込むためのバイナリローダ。 + */ +public class VmdLoader { + + private static final String ERR_TRYLOAD = "try loading first."; + private static final String ERR_LOADED = "has been loaded."; + + + private boolean loaded = false; + private boolean hasMoreData = true; + + private boolean ignoreName = true; + private boolean redundantCheck = false; + + + /** + * コンストラクタ。 + */ + public VmdLoader(){ + super(); + return; + } + + + /** + * 正常パース時に読み残したデータがあったか判定する。 + * @return 読み残したデータがあればtrue + * @throws IllegalStateException まだパースを試みていない。 + */ + public boolean hasMoreData() throws IllegalStateException{ + if( ! this.loaded ) throw new IllegalStateException(ERR_TRYLOAD); + return this.hasMoreData; + } + + /** + * カメラ・ライティングデータのパースを試みるか否かの判断で、 + * 特殊モデル名判定を無視するか否か設定する。 + * デフォルトではモデル名を無視。 + *

※MMDVer7.30前後のVMD出力不具合を回避したい場合は、 + * オフにするとパースに成功する場合がある。 + * @param mode モデル名を無視してパースを強行するならtrue + */ + public void setIgnoreName(boolean mode){ + this.ignoreName = mode; + return; + } + + /** + * ボーンモーション補間情報冗長部のチェックを行うか否か設定する。 + * デフォルトではチェックを行わない。 + *

※MMDVer7.30前後のVMD出力不具合を回避したい場合は、 + * オフにするとパースに成功する場合がある。 + * @param mode チェックさせたければtrue + */ + public void setRedundantCheck(boolean mode){ + this.redundantCheck = mode; + return; + } + + /** + * VMDファイルの読み込みを行いモーション情報を返す。 + * 1インスタンスにつき一度しかロードできない。 + * @param source VMDファイル入力ソース + * @return モーション情報 + * @throws IOException 入力エラー + * @throws MmdFormatException VMDファイルフォーマットの異常を検出 + * @throws IllegalStateException このインスタンスで再度のロードを試みた。 + */ + public VmdMotion load(InputStream source) + throws IOException, + MmdFormatException, + IllegalStateException { + if(this.loaded) throw new IllegalStateException(ERR_LOADED); + + VmdMotion motion = new VmdMotion(); + + VmdParser parser = new VmdParser(source); + + parser.setIgnoreName(this.ignoreName); + parser.setRedundantCheck(this.redundantCheck); + + BasicLoader basicBuilder = new BasicLoader(motion); + CameraLoader cameraBuilder = new CameraLoader(motion); + LightingLoader lightingBuilder = new LightingLoader(motion); + + parser.setBasicHandler(basicBuilder); + parser.setCameraHandler(cameraBuilder); + parser.setLightingHandler(lightingBuilder); + + try{ + parser.parseVmd(); + this.hasMoreData = basicBuilder.hasMoreData(); + }finally{ + this.loaded = true; + } + + return motion; + } + +} diff --git a/src/main/java/jp/sourceforge/mikutoga/vmd/model/binio/package-info.java b/src/main/java/jp/sfjp/mikutoga/vmd/model/binio/package-info.java similarity index 82% rename from src/main/java/jp/sourceforge/mikutoga/vmd/model/binio/package-info.java rename to src/main/java/jp/sfjp/mikutoga/vmd/model/binio/package-info.java index 616da2a..401bf5c 100644 --- a/src/main/java/jp/sourceforge/mikutoga/vmd/model/binio/package-info.java +++ b/src/main/java/jp/sfjp/mikutoga/vmd/model/binio/package-info.java @@ -9,6 +9,6 @@ * 独自データモデル向けVMDモーションファイル(*.vmd)用入出力ライブラリ。 */ -package jp.sourceforge.mikutoga.vmd.model.binio; +package jp.sfjp.mikutoga.vmd.model.binio; /* EOF */ diff --git a/src/main/java/jp/sourceforge/mikutoga/vmd/model/package-info.java b/src/main/java/jp/sfjp/mikutoga/vmd/model/package-info.java similarity index 64% rename from src/main/java/jp/sourceforge/mikutoga/vmd/model/package-info.java rename to src/main/java/jp/sfjp/mikutoga/vmd/model/package-info.java index c8ae7fa..1de77d4 100644 --- a/src/main/java/jp/sourceforge/mikutoga/vmd/model/package-info.java +++ b/src/main/java/jp/sfjp/mikutoga/vmd/model/package-info.java @@ -7,9 +7,8 @@ /** * VMDモーションファイル内の各要素に相当するオブジェクト各種。 - *

VMDを正確に記述するのが主目的。使い勝手は二の次。 */ -package jp.sourceforge.mikutoga.vmd.model; +package jp.sfjp.mikutoga.vmd.model; /* EOF */ diff --git a/src/main/java/jp/sfjp/mikutoga/vmd2xml/CmdLine.java b/src/main/java/jp/sfjp/mikutoga/vmd2xml/CmdLine.java new file mode 100644 index 0000000..fca5b6c --- /dev/null +++ b/src/main/java/jp/sfjp/mikutoga/vmd2xml/CmdLine.java @@ -0,0 +1,101 @@ +/* + * command line parser + * + * License : The MIT License + * Copyright(c) 2013 MikuToga Partners + */ + +package jp.sfjp.mikutoga.vmd2xml; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; + +/** + * コマンドラインの1オプションとその引数群に相当。 + */ +final class CmdLine { + + private OptSwitch opt; + private List optArgs; + + + /** + * コンストラクタ。 + */ + private CmdLine() { + super(); + return; + } + + + /** + * コマンドライン解析を行う。 + * @param args コマンドライン + * @return 解析されたコマンドライン並び + */ + static List parse(String... args){ + List list = Arrays.asList(args); + return parse(list); + } + + /** + * コマンドライン解析を行う。 + * @param argList コマンドライン + * @return 解析されたコマンドライン並び + */ + static List parse(List argList){ + List result = new LinkedList(); + + Iterator it = argList.iterator(); + while (it.hasNext()) { + String arg = it.next(); + + CmdLine info = new CmdLine(); + result.add(info); + + info.opt = OptSwitch.parse(arg); + + int exArgNum = 0; + if (info.opt != null) { + exArgNum = info.opt.getExArgNum(); + } + info.optArgs = new ArrayList(exArgNum + 1); + + info.optArgs.add(arg); + + for (int argCt = 0; argCt < exArgNum; argCt++) { + if ( ! it.hasNext()) { + break; + } + String exarg = it.next(); + info.optArgs.add(exarg); + } + } + + return result; + } + + + /** + * オプション識別子を返す。 + * @return オプション識別子。 + * オプションを伴わない単純なコマンドライン引数の場合はnullを返す。 + */ + OptSwitch getOptSwitch() { + return this.opt; + } + + /** + * オプションに付随する引数群を返す。 + * @return オプションに付随する引数群。 + * 先頭要素はオプション識別子。 + * 単純なコマンドライン引数の場合は自身が1要素のみを占める。 + */ + List getOptArgs() { + return this.optArgs; + } + +} diff --git a/src/main/java/jp/sfjp/mikutoga/vmd2xml/CmdLineException.java b/src/main/java/jp/sfjp/mikutoga/vmd2xml/CmdLineException.java new file mode 100644 index 0000000..6a3f727 --- /dev/null +++ b/src/main/java/jp/sfjp/mikutoga/vmd2xml/CmdLineException.java @@ -0,0 +1,25 @@ +/* + * command line exception + * + * License : The MIT License + * Copyright(c) 2013 MikuToga Partners + */ + +package jp.sfjp.mikutoga.vmd2xml; + +/** + * コマンドライン引数の不備による異常系。 + */ +@SuppressWarnings("serial") +class CmdLineException extends Exception{ + + /** + * コンストラクタ。 + * @param message {@inheritDoc} + */ + public CmdLineException(String message) { + super(message); + return; + } + +} diff --git a/src/main/java/jp/sourceforge/mikutoga/vmd2xml/MotionFileType.java b/src/main/java/jp/sfjp/mikutoga/vmd2xml/MotionFileType.java similarity index 96% rename from src/main/java/jp/sourceforge/mikutoga/vmd2xml/MotionFileType.java rename to src/main/java/jp/sfjp/mikutoga/vmd2xml/MotionFileType.java index 7e85869..a72e81b 100644 --- a/src/main/java/jp/sourceforge/mikutoga/vmd2xml/MotionFileType.java +++ b/src/main/java/jp/sfjp/mikutoga/vmd2xml/MotionFileType.java @@ -5,7 +5,7 @@ * Copyright(c) 2013 MikuToga Partners */ -package jp.sourceforge.mikutoga.vmd2xml; +package jp.sfjp.mikutoga.vmd2xml; /** * モーションファイル種別。 diff --git a/src/main/java/jp/sfjp/mikutoga/vmd2xml/OptInfo.java b/src/main/java/jp/sfjp/mikutoga/vmd2xml/OptInfo.java new file mode 100644 index 0000000..ce87b4c --- /dev/null +++ b/src/main/java/jp/sfjp/mikutoga/vmd2xml/OptInfo.java @@ -0,0 +1,389 @@ +/* + * command line argument info + * + * License : The MIT License + * Copyright(c) 2013 MikuToga Partners + */ + +package jp.sfjp.mikutoga.vmd2xml; + +import java.text.MessageFormat; +import java.util.List; +import java.util.Locale; + +/** + * コマンドラインオプション情報。 + */ +final class OptInfo { + + private static final String EOL_LF = "\n"; + private static final String EOL_CRLF = "\r\n"; + private static final String EOL_DEFAULT = EOL_LF; + + private static final String FORMAT_VMD = "vmd"; + private static final String FORMAT_XML = "xml"; + private static final String FORMAT_XML110820 = "xml110820"; + + private static final String SFX_VMD = ".vmd"; + private static final String SFX_XML = ".xml"; + + private static final String NL_LF = "lf"; + private static final String NL_CRLF = "crlf"; + + private static final String GENERATOR = + Vmd2Xml.APPNAME + ' ' + Vmd2Xml.APPVER; + + private static final String ERRMSG_UNKNOWN = + "Unknown option : {0}"; + private static final String ERRMSG_MOREARG = + "You need option arg with : {0}"; + private static final String ERRMSG_INTYPE = + "You must specify input format with -iform."; + private static final String ERRMSG_OUTTYPE = + "You must specify output format with -oform."; + private static final String ERRMSG_NOINFILE = + "You must specify input file with -i."; + private static final String ERRMSG_NOOUTFILE = + "You must specify output file with -o."; + private static final String ERRMSG_INVFORM = + "Unknown format : \"{0}\" must be \"vmd\" or \"xml\" " + + "or \"xml110820\""; + private static final String ERRMSG_INVNL = + "Unknown newline : \"{0}\" must be \"lf\" or \"crlf\""; + private static final String ERRMSG_INVBOOL = + "Unknown switch : \"{0}\" must be \"on\" or \"off\""; + + + private boolean needHelp = false; + private MotionFileType inTypes = MotionFileType.NONE; + private MotionFileType outTypes = MotionFileType.NONE; + private String inFilename = null; + private String outFilename = null; + private boolean overwrite = false; + private String newline = EOL_DEFAULT; + private String generator = GENERATOR; + private boolean isQuaternionMode = true; + + + /** + * コンストラクタ。 + */ + private OptInfo(){ + super(); + return; + } + + + /** + * フォーマット種別指定子をデコードする。 + * @param arg 文字列 + * @return デコード結果。 + * @throws CmdLineException 不正なフォーマット種別 + */ + private static MotionFileType decodeFormatType(String arg) + throws CmdLineException{ + MotionFileType result; + + if (FORMAT_VMD.equals(arg)){ + result = MotionFileType.VMD; + }else if(FORMAT_XML.equals(arg)){ + result = MotionFileType.XML_110820; + }else if(FORMAT_XML110820.equals(arg)){ + result = MotionFileType.XML_110820; + }else{ + String errMsg = MessageFormat.format(ERRMSG_INVFORM, arg); + throw new CmdLineException(errMsg); + } + + return result; + } + + /** + * 改行文字指定子をデコードする。 + * @param arg 文字列 + * @return デコード結果。 + * @throws CmdLineException 不正なフォーマット種別 + */ + private static String decodeNewline(String arg) + throws CmdLineException{ + String result; + + if (NL_LF.equals(arg)){ + result = EOL_LF; + }else if(NL_CRLF.equals(arg)){ + result = EOL_CRLF; + }else{ + String errMsg = MessageFormat.format(ERRMSG_INVNL, arg); + throw new CmdLineException(errMsg); + } + + return result; + } + + /** + * ブール指定子をデコードする。 + * @param arg 文字列 + * @return デコード結果。 + * @throws CmdLineException 不正なフォーマット種別 + */ + private static boolean decodeBoolean(String arg) + throws CmdLineException{ + boolean result; + + if( "on" .equals(arg) + || "true".equals(arg) + || "yes" .equals(arg) ){ + result = true; + }else if( "off" .equals(arg) + || "false".equals(arg) + || "no" .equals(arg) ){ + result = false; + }else{ + String errMsg = MessageFormat.format(ERRMSG_INVBOOL, arg); + throw new CmdLineException(errMsg); + } + + return result; + } + + /** + * ファイル名からファイル種別を類推する。 + *

拡張子が「.vmd」ならVMDファイル、「.xml」ならXMLファイル。 + * @param fileName ファイル名 + * @return ファイル種別。識別不可ならNONE。 + */ + private static MotionFileType getFileType(String fileName){ + MotionFileType result = MotionFileType.NONE; + if(fileName == null) return result; + + String lower = fileName.toLowerCase(Locale.ROOT); + if (lower.endsWith(SFX_VMD)) result = MotionFileType.VMD; + else if(lower.endsWith(SFX_XML)) result = MotionFileType.XML_110820; + + return result; + } + + /** + * コマンドラインを解析する。 + * @param args コマンドライン + * @return オプション情報 + * @throws CmdLineException 不正なコマンドライン + */ + static OptInfo parseOption(String... args) throws CmdLineException{ + OptInfo result = new OptInfo(); + + List cmdLines = CmdLine.parse(args); + for(CmdLine cmd : cmdLines){ + OptSwitch opt = cmd.getOptSwitch(); + if(opt == OptSwitch.OPT_HELP){ + result.needHelp = true; + return result; + } + } + + checkCmdLineList(cmdLines); + + for(CmdLine cmd : cmdLines){ + List optArgs = cmd.getOptArgs(); + String exArg1 = null; + if(optArgs.size() >= 2){ + exArg1 = optArgs.get(1); + } + + OptSwitch opt = cmd.getOptSwitch(); + switch(opt){ + case OPT_HELP: + break; + case OPT_FORCE: + result.overwrite = true; + break; + case OPT_INFILE: + result.inFilename = exArg1; + break; + case OPT_OUTFILE: + result.outFilename = exArg1; + break; + case OPT_NEWLINE: + result.newline = decodeNewline(exArg1); + break; + case OPT_GENOUT: + boolean genout = decodeBoolean(exArg1); + if(genout) result.generator = GENERATOR; + else result.generator = null; + break; + case OPT_QUAT: + result.isQuaternionMode = true; + break; + case OPT_EYXZ: + result.isQuaternionMode = false; + break; + case OPT_IFORM: + MotionFileType itype = decodeFormatType(exArg1); + result.inTypes = itype; + break; + case OPT_OFORM: + MotionFileType otype = decodeFormatType(exArg1); + result.outTypes = otype; + break; + default: + assert false; + throw new AssertionError(); + } + } + + fixFormat(result); + + checkResult(result); + + return result; + } + + /** + * 単純なコマンドラインエラーを検出する。 + *

検出項目は未知のオプションおよび不正な引数の個数 + * @param cmdLines コマンドライン + * @throws CmdLineException 異常系 + */ + private static void checkCmdLineList(List cmdLines) + throws CmdLineException{ + for(CmdLine cmd : cmdLines){ + List optArgs = cmd.getOptArgs(); + assert ! optArgs.isEmpty(); + + String optTxt = optArgs.get(0); + assert optTxt != null; + + OptSwitch opt = cmd.getOptSwitch(); + if(opt == null){ + String errMsg = + MessageFormat.format(ERRMSG_UNKNOWN, optTxt); + throw new CmdLineException(errMsg); + } + + int exArgNum = opt.getExArgNum(); + if(optArgs.size() != 1 + exArgNum){ + String errMsg = + MessageFormat.format(ERRMSG_MOREARG, optTxt); + throw new CmdLineException(errMsg); + } + } + + return; + } + + /** + * ファイルフォーマット情報の推測を行う。 + * @param result オプション情報 + */ + private static void fixFormat(OptInfo result){ + if(result.inTypes == MotionFileType.NONE){ + result.inTypes = getFileType(result.inFilename); + } + + if(result.outTypes == MotionFileType.NONE){ + result.outTypes = getFileType(result.outFilename); + } + + return; + } + + /** + * オプション整合性の事後検査。 + * @param result オプション情報 + * @throws CmdLineException 不正なオプション設定 + */ + private static void checkResult(OptInfo result) + throws CmdLineException{ + if(result.getInFilename() == null){ + throw new CmdLineException(ERRMSG_NOINFILE); + } + + if(result.getOutFilename() == null){ + throw new CmdLineException(ERRMSG_NOOUTFILE); + } + + if(result.getInFileType() == MotionFileType.NONE){ + throw new CmdLineException(ERRMSG_INTYPE); + } + + if(result.getOutFileType() == MotionFileType.NONE){ + throw new CmdLineException(ERRMSG_OUTTYPE); + } + + return; + } + + + /** + * ヘルプ表示が必要か否か判定する。 + * @return 必要ならtrue + */ + boolean needHelp(){ + return this.needHelp; + } + + /** + * 入力ファイル種別を返す。 + * @return 入力ファイル種別 + */ + MotionFileType getInFileType(){ + return this.inTypes; + } + + /** + * 出力ファイル種別を返す。 + * @return 出力ファイル種別 + */ + MotionFileType getOutFileType(){ + return this.outTypes; + } + + /** + * 入力ファイル名を返す。 + * @return 入力ファイル名 + */ + String getInFilename(){ + return this.inFilename; + } + + /** + * 出力ファイル名を返す。 + * @return 出力ファイル名 + */ + String getOutFilename(){ + return this.outFilename; + } + + /** + * 上書きモードか否か返す。 + * @return 上書きモードならtrue + */ + boolean overwriteMode(){ + return this.overwrite; + } + + /** + * XML改行文字を返す。 + * @return 改行文字 + */ + String getNewline(){ + return this.newline; + } + + /** + * ジェネレータ名を返す。 + * @return ジェネレータ名。表示したくない時はnull + */ + String getGenerator(){ + return this.generator; + } + + /** + * 回転情報のXML出力形式を得る。 + * @return クォータニオン形式ならtrue、YXZオイラー角形式ならfalse。 + */ + boolean isQuaterniomMode(){ + return this.isQuaternionMode; + } + +} diff --git a/src/main/java/jp/sfjp/mikutoga/vmd2xml/OptSwitch.java b/src/main/java/jp/sfjp/mikutoga/vmd2xml/OptSwitch.java new file mode 100644 index 0000000..de39e1d --- /dev/null +++ b/src/main/java/jp/sfjp/mikutoga/vmd2xml/OptSwitch.java @@ -0,0 +1,120 @@ +/* + * command line option definition + * + * License : The MIT License + * Copyright(c) 2013 MikuToga Partners + */ + +package jp.sfjp.mikutoga.vmd2xml; + +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * オプションスイッチ群定義。 + */ +enum OptSwitch { + + OPT_HELP (0, "-h", "-help", "-?"), + OPT_INFILE (1, "-i"), + OPT_OUTFILE (1, "-o"), + OPT_FORCE (0, "-f"), + OPT_NEWLINE (1, "-nl"), + OPT_GENOUT (1, "-genout"), + OPT_IFORM (1, "-iform"), + OPT_OFORM (1, "-oform"), + OPT_QUAT (0, "-quat"), + OPT_EYXZ (0, "-eyxz"), + ; + + private static final String HELP_CONSOLE = + "-h : put help message\n\n" + + "-i : specify input file\n" + + "-o : specify output file\n" + + "-f : force overwriting\n\n" + + "-nl : specify XML-newline character" + + " (default:lf)\n" + + "-genout : mark generator-name to XML" + + " (default:on)\n\n" + + "-quat : Quaternion form rotation (default)\n" + + "-eyxz : Euler-YXZ form rotation\n\n" + + "-iform : specify input format explicitly\n" + + "-oform : specify output format explicitly\n\n" + + " bool : \"on\" or \"off\"" + + " or \"true\" or \"false\"" + + " or \"yes\" or \"no\"\n" + + " format : \"vmd\" or \"xml\" or" + + " \"xml110820\"\n" + + " newline : \"lf\" or \"crlf\"\n" + ; + + private static final Map MAP_OPT; + + static{ + Map map = new HashMap(); + + for(OptSwitch opt : values()){ + for(String cmdarg : opt.cmdopts){ + map.put(cmdarg, opt); + } + } + + map = Collections.unmodifiableMap(map); + MAP_OPT = map; + } + + + private final int exArgNum; + private final List cmdopts; + + + /** + * コンストラクタ。 + * @param argnum 必要な引数の数 + * @param cmdopts オプションスイッチパターン群 + */ + private OptSwitch(int argnum, String... cmdopts) { + this.exArgNum = argnum; + + List optlist; + optlist = Arrays.asList(cmdopts); + optlist = Collections.unmodifiableList(optlist); + this.cmdopts = optlist; + + return; + } + + + /** + * コンソール提示用ヘルプ出力文字列を返す。 + * @return オプションヘルプ文字列 + */ + static String getConsoleHelp(){ + return HELP_CONSOLE; + } + + /** + * 文字列に合致するオプションを返す。 + *

一つのオプションが複数の表記に合致する場合がある。 + * @param cmd 文字列 + * @return オプション種別。合致する物が見つからなければnull + */ + static OptSwitch parse(String cmd){ + OptSwitch result = MAP_OPT.get(cmd); + return result; + } + + + /** + * 各オプションに後続する引数の数を返す。 + *

引数をとらないオプションは0を返す。 + * @return 引数の数 + */ + int getExArgNum(){ + return this.exArgNum; + } + +} diff --git a/src/main/java/jp/sfjp/mikutoga/vmd2xml/Vmd2Xml.java b/src/main/java/jp/sfjp/mikutoga/vmd2xml/Vmd2Xml.java new file mode 100644 index 0000000..5fff72f --- /dev/null +++ b/src/main/java/jp/sfjp/mikutoga/vmd2xml/Vmd2Xml.java @@ -0,0 +1,392 @@ +/* + * vmd to xml converter main entry + * + * License : The MIT License + * Copyright(c) 2011 MikuToga Partners + */ + +package jp.sfjp.mikutoga.vmd2xml; + +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.PrintStream; +import java.nio.channels.FileChannel; +import java.text.MessageFormat; +import java.util.Properties; +import jp.sfjp.mikutoga.bin.parser.MmdFormatException; +import jp.sfjp.mikutoga.vmd.IllegalVmdDataException; +import jp.sourceforge.mikutoga.xml.TogaXmlException; +import org.xml.sax.SAXException; + + +/** + * VMDモーションファイルとXMLとの間で変換を行うアプリケーション。 + */ +public final class Vmd2Xml { + + /** 正常系。 */ + public static final int EXIT_OK = 0; + /** 内部エラー。 */ + public static final int EXIT_INTERR = 1; + /** 実行環境に起因するエラー。 */ + public static final int EXIT_ENVERR = 2; + /** オプション指定に起因するエラー。 */ + public static final int EXIT_OPTERR = 3; + /** ファイル入出力に起因するエラー。 */ + public static final int EXIT_IOERR = 4; + /** XMLフォーマットに起因するエラー。 */ + public static final int EXIT_XMLERR = 5; + /** VMDフォーマットに起因するエラー。 */ + public static final int EXIT_VMDERR = 7; + + /** アプリ名。 */ + public static final String APPNAME; + /** バージョン識別子。 */ + public static final String APPVER; + /** ライセンス種別。 */ + public static final String APPLICENSE; + /** 開発元URL。 */ + public static final String APPURL; + + private static final Class THISCLASS; + private static final String RES_VER = "resources/version.properties"; + + private static final PrintStream ERROUT = System.err; + private static final String MSG_ERR = "ERROR:\n{0}\n(-h for help)"; + private static final String MSG_HELP = + "{0} {1}\n" + + "\u0020\u0020License\u0020:\u0020{2}\n" + + "\u0020\u0020{3}\n"; + private static final String MSG_NOINFILE = "Can't find input file:{0}"; + private static final String MSG_ABNFILE = "{0} is not file."; + private static final String MSG_OWOUTFILE = + "{0} already exists.\n" + + "If you want to overwrite, use -f."; + + private static final String MSG_OLDJRE = "You need JRE {0} or later."; + private static final String REQUIRED_JRE = "1.6"; + + static{ + THISCLASS = Vmd2Xml.class; + InputStream ver = THISCLASS.getResourceAsStream(RES_VER); + Properties verProps = new Properties(); + try{ + try{ + verProps.load(ver); + }finally{ + ver.close(); + } + }catch(IOException e){ + throw new ExceptionInInitializerError(e); + } + + APPNAME = verProps.getProperty("app.name"); + APPVER = verProps.getProperty("app.version"); + APPLICENSE = verProps.getProperty("app.license"); + APPURL = verProps.getProperty("app.url"); + + new Vmd2Xml().hashCode(); + } + + + /** + * ダミーコンストラクタ。 + */ + private Vmd2Xml(){ + super(); + assert this.getClass().equals(THISCLASS); + return; + } + + + /** + * VMを終了させる。 + * @param code 終了コード + * @see java.lang.System#exit(int) + */ + private static void exit(int code){ + System.exit(code); + assert false; + throw new AssertionError(); + } + + /** + * 共通エラーメッセージを出力する。 + * @param text 個別メッセージ + */ + private static void errMsg(String text){ + String msg = MessageFormat.format(MSG_ERR, text); + ERROUT.println(msg); + return; + } + + /** + * 標準エラー出力へ例外情報出力。 + * @param ex 例外 + * @param dumpStack スタックトレースを出力するならtrue + */ + private static void thPrintln(Throwable ex, boolean dumpStack){ + if(dumpStack){ + ex.printStackTrace(ERROUT); + }else{ + String text = ex.toString(); + ERROUT.println(text); + } + + return; + } + + /** + * 標準エラー出力へ例外情報出力。 + * @param ex 例外 + */ + private static void thPrintln(Throwable ex){ + thPrintln(ex, false); + return; + } + + /** + * 入出力エラー処理。 + * 例外を出力してVM終了する。 + * @param ex 例外 + */ + private static void ioError(IOException ex){ + thPrintln(ex); + exit(EXIT_IOERR); + } + + /** + * XML構文エラー処理。 + * 例外を出力してVM終了する。 + * @param ex 例外 + */ + private static void xmlError(Throwable ex){ + thPrintln(ex); + exit(EXIT_XMLERR); + } + + /** + * VMDファイルフォーマットエラー処理。 + * 例外を出力してVM終了する。 + * @param ex 例外 + */ + private static void vmdError(MmdFormatException ex){ + thPrintln(ex, true); + exit(EXIT_VMDERR); + } + + /** + * 内部エラー処理。 + * 例外を出力してVM終了する。 + * @param ex 例外 + */ + private static void internalError(Throwable ex){ + thPrintln(ex, true); + exit(EXIT_INTERR); + } + + /** + * JREのバージョン判定を行う。 + * 不適切ならVMごと終了。 + */ + private static void checkJRE(){ + Package jrePackage = java.lang.Object.class.getPackage(); + if( ! jrePackage.isCompatibleWith(REQUIRED_JRE)){ + String msg = MessageFormat.format(MSG_OLDJRE, REQUIRED_JRE); + ERROUT.println(msg); + exit(EXIT_ENVERR); + } + return; + } + + /** + * ヘルプメッセージを出力する。 + */ + private static void putHelp(){ + String msg = + MessageFormat.format(MSG_HELP, + APPNAME, APPVER, APPLICENSE, APPURL); + ERROUT.println(msg); + ERROUT.println(OptSwitch.getConsoleHelp()); + return; + } + + /** + * ファイルサイズを0に切り詰める。 + *

ファイルが存在しなければなにもしない。 + *

通常ファイルでなければなにもしない。 + * @param file ファイル + * @throws IOException 入出力エラー + */ + private static void trunc(File file) throws IOException{ + if( ! file.exists() ) return; + if( ! file.isFile() ) return; + + if(file.length() <= 0L) return; + + FileOutputStream foStream = new FileOutputStream(file); + try{ + FileChannel channnel = foStream.getChannel(); + try{ + channnel.truncate(0L); + }finally{ + channnel.close(); + } + }finally{ + foStream.close(); + } + + return; + } + + /** + * 入力ストリームを準備する。 + *

入力ファイルが通常ファイルとして存在しなければエラー終了。 + * @param fileName 入力ファイル名 + * @return 入力ストリーム + */ + private static InputStream openInfile(String fileName){ + File inFile = new File(fileName); + + if( (! inFile.exists()) || (! inFile.isFile()) ){ + String absPath = inFile.getAbsolutePath(); + String msg = MessageFormat.format(MSG_NOINFILE, absPath); + errMsg(msg); + exit(EXIT_IOERR); + } + + InputStream is; + try{ + is = new FileInputStream(inFile); + }catch(FileNotFoundException e){ + ioError(e); + assert false; + throw new AssertionError(e); + } + + is = new BufferedInputStream(is); + + return is; + } + + /** + * 出力ストリームを準備する。 + *

出力ファイルが通常ファイルでない場合はエラー終了。 + *

既存の出力ファイルに上書き指示が伴っていなければエラー終了。 + * @param fileName 出力ファイル名 + * @param overWrite 頭から上書きして良ければtrue + * @return 出力ストリーム + */ + private static OutputStream openOutfile(String fileName, + boolean overWrite) { + File outFile = new File(fileName); + + if(outFile.exists()){ + String absPath = outFile.getAbsolutePath(); + if( ! outFile.isFile() ){ + String msg = MessageFormat.format(MSG_ABNFILE, absPath); + errMsg(msg); + exit(EXIT_IOERR); + }else if( ! overWrite ){ + String msg = MessageFormat.format(MSG_OWOUTFILE, absPath); + errMsg(msg); + exit(EXIT_IOERR); + } + } + + try{ + trunc(outFile); + }catch(IOException e){ + ioError(e); + } + + OutputStream os; + try{ + os = new FileOutputStream(outFile); + }catch(FileNotFoundException e){ + ioError(e); + assert false; + throw new AssertionError(e); + } + + os = new BufferedOutputStream(os); + + return os; + } + + /** + * Mainエントリ。 + * @param args コマンドパラメータ + */ + public static void main(String[] args){ + checkJRE(); + + OptInfo optInfo; + try{ + optInfo = OptInfo.parseOption(args); + }catch(CmdLineException e){ + String optErrMsg = e.getLocalizedMessage(); + errMsg(optErrMsg); + exit(EXIT_OPTERR); + return; + } + + if(optInfo.needHelp()){ + putHelp(); + exit(EXIT_OK); + } + + String inputFile = optInfo.getInFilename(); + String outputFile = optInfo.getOutFilename(); + boolean overwrite = optInfo.overwriteMode(); + + InputStream is = openInfile(inputFile); + OutputStream os = openOutfile(outputFile, overwrite); + + Vmd2XmlConv converter = new Vmd2XmlConv(); + + converter.setInType (optInfo.getInFileType()); + converter.setOutType(optInfo.getOutFileType()); + + converter.setNewline(optInfo.getNewline()); + converter.setGenerator(optInfo.getGenerator()); + converter.setQuaterniomMode(optInfo.isQuaterniomMode()); + + try{ + converter.convert(is, os); + }catch(IOException e){ + ioError(e); + }catch(IllegalVmdDataException e){ + internalError(e); + }catch(MmdFormatException e){ + vmdError(e); + }catch(TogaXmlException e){ + xmlError(e); + }catch(SAXException e){ + xmlError(e); + } + + try{ + is.close(); + try{ + os.close(); + }catch(IOException e){ + ioError(e); + } + }catch(IOException e){ + ioError(e); + } + + exit(EXIT_OK); + + return; + } + +} diff --git a/src/main/java/jp/sourceforge/mikutoga/vmd2xml/Vmd2XmlConv.java b/src/main/java/jp/sfjp/mikutoga/vmd2xml/Vmd2XmlConv.java similarity index 86% rename from src/main/java/jp/sourceforge/mikutoga/vmd2xml/Vmd2XmlConv.java rename to src/main/java/jp/sfjp/mikutoga/vmd2xml/Vmd2XmlConv.java index 32936f5..1d9a491 100644 --- a/src/main/java/jp/sourceforge/mikutoga/vmd2xml/Vmd2XmlConv.java +++ b/src/main/java/jp/sfjp/mikutoga/vmd2xml/Vmd2XmlConv.java @@ -5,7 +5,7 @@ * Copyright(c) 2013 MikuToga Partners */ -package jp.sourceforge.mikutoga.vmd2xml; +package jp.sfjp.mikutoga.vmd2xml; import java.io.IOException; import java.io.InputStream; @@ -15,15 +15,15 @@ import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import javax.xml.validation.Schema; import jp.sfjp.mikutoga.bin.parser.MmdFormatException; -import jp.sourceforge.mikutoga.vmd.IllegalVmdDataException; -import jp.sourceforge.mikutoga.vmd.model.VmdMotion; -import jp.sourceforge.mikutoga.vmd.model.binio.VmdExporter; -import jp.sourceforge.mikutoga.vmd.model.binio.VmdLoader; +import jp.sfjp.mikutoga.vmd.IllegalVmdDataException; +import jp.sfjp.mikutoga.vmd.model.VmdMotion; +import jp.sfjp.mikutoga.vmd.model.binio.VmdExporter; +import jp.sfjp.mikutoga.vmd.model.binio.VmdLoader; import jp.sourceforge.mikutoga.vmd.model.xml.Schema110820; import jp.sourceforge.mikutoga.vmd.model.xml.VmdXmlExporter; import jp.sourceforge.mikutoga.vmd.model.xml.Xml2VmdLoader; import jp.sourceforge.mikutoga.xml.BotherHandler; -import jp.sourceforge.mikutoga.xml.LocalSchema; +import jp.sourceforge.mikutoga.xml.SchemaUtil; import jp.sourceforge.mikutoga.xml.TogaXmlException; import jp.sourceforge.mikutoga.xml.XmlResourceResolver; import org.xml.sax.InputSource; @@ -38,6 +38,7 @@ public class Vmd2XmlConv { private MotionFileType outTypes = MotionFileType.NONE; private String newLine = "\r\n"; private String generator = null; + private boolean isQuaternionMode = true; /** @@ -77,7 +78,7 @@ public class Vmd2XmlConv { XmlResourceResolver resolver = new XmlResourceResolver(); Schema schema; - schema = LocalSchema.newSchema(resolver, new Schema110820()); + schema = SchemaUtil.newSchema(resolver, Schema110820.SINGLETON); DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); @@ -102,7 +103,8 @@ public class Vmd2XmlConv { * @param type ファイル種別 * @throws IllegalArgumentException 具体的な種別を渡さなかった */ - public void setInType(MotionFileType type){ + public void setInType(MotionFileType type) + throws IllegalArgumentException { if(type == null) throw new NullPointerException(); if(type == MotionFileType.NONE) throw new IllegalArgumentException(); this.inTypes = type; @@ -122,7 +124,8 @@ public class Vmd2XmlConv { * @param type ファイル種別 * @throws IllegalArgumentException 具体的な種別を渡さなかった */ - public void setOutType(MotionFileType type){ + public void setOutType(MotionFileType type) + throws IllegalArgumentException { if(type == null) throw new NullPointerException(); if(type == MotionFileType.NONE) throw new IllegalArgumentException(); this.outTypes = type; @@ -150,7 +153,7 @@ public class Vmd2XmlConv { * XML出力用改行文字列を返す。 * @return 改行文字 */ - public String getNewLine(){ + public String getNewline(){ return this.newLine; } @@ -172,6 +175,24 @@ public class Vmd2XmlConv { } /** + * 回転情報をクォータニオン形式でXML出力するか設定する。 + * @param sw クォータニオン形式ならtrue、 + * YXZオイラー角で出力したければfalse。 + */ + public void setQuaterniomMode(boolean sw){ + this.isQuaternionMode = sw; + return; + } + + /** + * 回転情報のXML出力形式を得る。 + * @return クォータニオン形式ならtrue、YXZオイラー角形式ならfalse。 + */ + public boolean isQuaterniomMode(){ + return this.isQuaternionMode; + } + + /** * ファイル変換を行う。 * @param is 入力ストリーム * @param os 出力ストリーム @@ -188,6 +209,7 @@ public class Vmd2XmlConv { TogaXmlException, IllegalVmdDataException { VmdMotion motion = readMotion(is); + motion.frameSort(); writeMotion(motion, os); return; } @@ -200,7 +222,6 @@ public class Vmd2XmlConv { * @throws MmdFormatException フォーマットエラー * @throws SAXException XMLエラー * @throws TogaXmlException XMLエラー - * @throws IllegalStateException ファイル種別がまた指定されていない */ public VmdMotion readMotion(InputStream is) throws IOException, @@ -226,7 +247,6 @@ public class Vmd2XmlConv { * @param os 出力ストリーム * @throws IOException 出力エラー * @throws IllegalVmdDataException データの不備 - * @throws IllegalStateException ファイル種別がまた指定されていない */ public void writeMotion(VmdMotion motion, OutputStream os) throws IOException, @@ -251,7 +271,13 @@ public class Vmd2XmlConv { */ private VmdMotion vmdRead(InputStream is) throws IOException, MmdFormatException{ - VmdMotion motion = VmdLoader.load(is); + VmdLoader loader = new VmdLoader(); + + loader.setIgnoreName(true); + loader.setRedundantCheck(false); + + VmdMotion motion = loader.load(is); + return motion; } @@ -299,8 +325,8 @@ public class Vmd2XmlConv { */ private void vmdOut(VmdMotion motion, OutputStream ostream) throws IOException, IllegalVmdDataException{ - VmdExporter exporter = new VmdExporter(ostream); - exporter.dumpVmdMotion(motion); + VmdExporter exporter = new VmdExporter(); + exporter.dumpVmdMotion(motion, ostream); ostream.close(); return; } @@ -318,6 +344,7 @@ public class Vmd2XmlConv { exporter.setNewLine(this.newLine); exporter.setGenerator(this.generator); + exporter.setQuaternionMode(this.isQuaternionMode); exporter.putVmdXml(motion); diff --git a/src/main/java/jp/sfjp/mikutoga/vmd2xml/package-info.java b/src/main/java/jp/sfjp/mikutoga/vmd2xml/package-info.java new file mode 100644 index 0000000..b1076b4 --- /dev/null +++ b/src/main/java/jp/sfjp/mikutoga/vmd2xml/package-info.java @@ -0,0 +1,15 @@ +/* + * package information for Javadoc + * + * License : The MIT License + * Copyright(c) 2011 MikuToga Partners + */ + +/** + * VMDモーションデータとXML間でのデータ交換を行うアプリケーション。 + * Mainエントリは、クラスVmd2Xml。 + */ + +package jp.sfjp.mikutoga.vmd2xml; + +/* EOF */ diff --git a/src/main/java/jp/sourceforge/mikutoga/vmd/model/LuminousMotion.java b/src/main/java/jp/sourceforge/mikutoga/vmd/model/LuminousMotion.java deleted file mode 100644 index b2eb05c..0000000 --- a/src/main/java/jp/sourceforge/mikutoga/vmd/model/LuminousMotion.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * luminous motion - * - * License : The MIT License - * Copyright(c) 2011 MikuToga Partners - */ - -package jp.sourceforge.mikutoga.vmd.model; - -import jp.sourceforge.mikutoga.vmd.AbstractNumbered; - -/** - * 光源演出情報。 - */ -public class LuminousMotion extends AbstractNumbered { - - private final LuminousColor color = new LuminousColor(); - private final LuminousVector direction = new LuminousVector(); - - - /** - * コンストラクタ。 - */ - public LuminousMotion(){ - super(); - return; - } - - - /** - * 光源の色情報を返す。 - * @return 光源の色情報 - */ - public LuminousColor getColor(){ - return this.color; - } - - /** - * 光源からの照射方向情報を返す。 - * @return 光源からの照射方向情報 - */ - public LuminousVector getDirection(){ - return this.direction; - } - - /** - * {@inheritDoc} - * @return {@inheritDoc} - */ - @Override - public String toString(){ - StringBuilder result = new StringBuilder(); - - result.append("#").append(getFrameNumber()); - result.append(" luminous color : ").append(this.color); - result.append(" direction : ").append(this.direction); - - return result.toString(); - } - -} diff --git a/src/main/java/jp/sourceforge/mikutoga/vmd/model/LuminousVector.java b/src/main/java/jp/sourceforge/mikutoga/vmd/model/LuminousVector.java deleted file mode 100644 index 78f2a7f..0000000 --- a/src/main/java/jp/sourceforge/mikutoga/vmd/model/LuminousVector.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * luminous direction vector - * - * License : The MIT License - * Copyright(c) 2011 MikuToga Partners - */ - -package jp.sourceforge.mikutoga.vmd.model; - -/** - * 光源からの照射方向を表す方向ベクトル。 - *

照明方向は、 - * ワールド座標原点から伸びる方向ベクトルとして記述される。 - * この方向ベクトルに向けて、無限遠の光源から照明が当たる。 - *

MMDのスライダUI上では各軸成分の定義域は-1.0以上+1.0以下だが、 - * さらに絶対値の大きな値を指定することも可能。 - *

方向ベクトルの長さは演出上の意味を持たないが、 - * キーフレーム間の照明方向の補間に影響を及ぼすかもしれない。 - *

方向ベクトルが零ベクトル(0,0,0)の場合、MMDでは全ポリゴンに影が落ちる。 - */ -public class LuminousVector { - - /** デフォルトのX成分。 */ - public static final float DEF_VECX = -0.5f; - /** デフォルトのY成分。 */ - public static final float DEF_VECY = -1.0f; - /** デフォルトのZ成分。 */ - public static final float DEF_VECZ = +0.5f; - - - private float vecX = DEF_VECX; - private float vecY = DEF_VECY; - private float vecZ = DEF_VECZ; - - - /** - * コンストラクタ。 - */ - public LuminousVector(){ - super(); - return; - } - - - /** - * 照射方向ベクトルのX成分を設定する。 - * @param vecX ベクトルのX成分 - */ - public void setVecX(float vecX) { - this.vecX = vecX; - return; - } - - /** - * 照射方向ベクトルのY成分を設定する。 - * @param vecY ベクトルのY成分 - */ - public void setVecY(float vecY) { - this.vecY = vecY; - return; - } - - /** - * 照射方向ベクトルのZ成分を設定する。 - * @param vecZ ベクトルのZ成分 - */ - public void setVecZ(float vecZ) { - this.vecZ = vecZ; - return; - } - - /** - * 照射方向ベクトルのX成分を返す。 - * @return 方向ベクトルX成分 - */ - public float getVecX() { - return this.vecX; - } - - /** - * 照射方向ベクトルのY成分を返す。 - * @return 方向ベクトルY成分 - */ - public float getVecY() { - return this.vecY; - } - - /** - * 照射方向ベクトルのZ成分を返す。 - * @return 方向ベクトルZ成分 - */ - public float getVecZ() { - return this.vecZ; - } - - /** - * {@inheritDoc} - * @return {@inheritDoc} - */ - @Override - public String toString(){ - StringBuilder result = new StringBuilder(); - - result.append("x=").append(this.vecX); - result.append(" y=").append(this.vecY); - result.append(" z=").append(this.vecZ); - - return result.toString(); - } - -} diff --git a/src/main/java/jp/sourceforge/mikutoga/vmd/model/NamedListMap.java b/src/main/java/jp/sourceforge/mikutoga/vmd/model/NamedListMap.java deleted file mode 100644 index 01aedfc..0000000 --- a/src/main/java/jp/sourceforge/mikutoga/vmd/model/NamedListMap.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * string named list map - * - * License : The MIT License - * Copyright(c) 2011 MikuToga Partners - */ - -package jp.sourceforge.mikutoga.vmd.model; - -import java.util.Collections; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; - -/** - * 名前付けされたリストのマップ。 - * 登録名の追加順が保持される。 - * @param リスト要素の型 - */ -public class NamedListMap { - - private final List nameList; - private final Map> listMap; - - - /** - * コンストラクタ。 - */ - public NamedListMap(){ - super(); - this.nameList = new LinkedList(); - this.listMap = new HashMap>(); - return; - } - - - /** - * マップをクリアする。 - */ - public void clear(){ - this.nameList.clear(); - this.listMap.clear(); - return; - } - - /** - * マップが空か否か判定する。 - * @return 空ならtrue - */ - public boolean isEmpty(){ - if(this.listMap.isEmpty()) return true; - return false; - } - - /** - * 名前一覧を返す。 - *

名前は登録順に並ぶ。 - *

ここで返されるListへの修正操作は不可能。 - * @return 名前一覧のリスト - */ - public List getNames(){ - List result = Collections.unmodifiableList(this.nameList); - return result; - } - - /** - * 名前付けされたリストを返す。 - * @param name 名前 - * @return 名前付けされたリスト。リストが存在しなければnull。 - */ - public List getNamedList(String name){ - List result = this.listMap.get(name); - return result; - } - - /** - * 名前付けされたリストを削除する。 - * 存在しない名前が渡された場合、何もしない。 - * @param name 名前 - */ - public void removeNamedList(String name){ - if(this.listMap.remove(name) == null) return; - this.nameList.remove(name); - return; - } - - /** - * 名前付けされたリストに新要素を追加する。 - * 未登録の名前であれば新たにリストが作成される。 - * @param name 名前 - * @param elem 新要素 - * @throws NullPointerException 引数がnull - */ - public void addNamedElement(String name, E elem) - throws NullPointerException{ - if(name == null || elem == null) throw new NullPointerException(); - - List list = this.listMap.get(name); - if(list == null){ - list = new LinkedList(); - this.listMap.put(name, list); - this.nameList.add(name); - } - - list.add(elem); - - return; - } - -} diff --git a/src/main/java/jp/sourceforge/mikutoga/vmd/model/binio/VmdExporter.java b/src/main/java/jp/sourceforge/mikutoga/vmd/model/binio/VmdExporter.java deleted file mode 100644 index d4670ed..0000000 --- a/src/main/java/jp/sourceforge/mikutoga/vmd/model/binio/VmdExporter.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * vmd exporter - * - * License : The MIT License - * Copyright(c) 2011 MikuToga Partners - */ - -package jp.sourceforge.mikutoga.vmd.model.binio; - -import java.io.IOException; -import java.io.OutputStream; -import jp.sfjp.mikutoga.bin.export.BinaryExporter; -import jp.sfjp.mikutoga.bin.export.IllegalTextExportException; -import jp.sourceforge.mikutoga.vmd.IllegalVmdDataException; -import jp.sourceforge.mikutoga.vmd.VmdConst; -import jp.sourceforge.mikutoga.vmd.model.VmdMotion; - -/** - * VMDファイルのエクスポーター。 - */ -public class VmdExporter extends BinaryExporter { - - private static final byte[] HEADFILLER = { - (byte)'J', - (byte)'K', - (byte)'L', - (byte)'M', - }; - - private static final byte[] FDFILLER = - { (byte)0x00, (byte)0xfd }; - - - private final BasicExporter basicExporter; - private final CameraExporter cameraExporter; - private final LightingExporter lightingExporter; - - - /** - * コンストラクタ。 - * @param stream 出力ストリーム - */ - public VmdExporter(OutputStream stream){ - super(stream); - - this.basicExporter = new BasicExporter(stream); - this.cameraExporter = new CameraExporter(stream); - this.lightingExporter = new LightingExporter(stream); - - return; - } - - /** - * モーションデータをVMDファイル形式で出力する。 - *

異常時には出力データのフラッシュが試みられる。 - * @param motion モーションデータ - * @throws IOException 出力エラー - * @throws IllegalVmdDataException モーションデータに不備が発見された - */ - public void dumpVmdMotion(VmdMotion motion) - throws IOException, IllegalVmdDataException{ - try{ - dumpVmdMotionImpl(motion); - }finally{ - flush(); - } - - return; - } - - /** - * モーションデータをVMDファイル形式で出力する。 - * @param motion モーションデータ - * @throws IOException 出力エラー - * @throws IllegalVmdDataException モーションデータに不備が発見された - */ - private void dumpVmdMotionImpl(VmdMotion motion) - throws IOException, IllegalVmdDataException{ - dumpHeader(); - - try{ - dumpModelName(motion); - this.basicExporter.dumpBoneMotion(motion); - this.basicExporter.dumpMorphMotion(motion); - }catch(IllegalTextExportException e){ - throw new IllegalVmdDataException(e); - } - - this.cameraExporter.dumpCameraMotion(motion); - this.lightingExporter.dumpLuminousMotion(motion); - this.lightingExporter.dumpShadowMotion(motion); - - return; - } - - /** - * ヘッダ情報を出力する。 - * @throws IOException 出力エラー - */ - private void dumpHeader() throws IOException{ - byte[] header = VmdConst.createMagicHeader(); - dumpByteArray(header); - dumpByteArray(HEADFILLER); - - assert header.length + HEADFILLER.length == VmdConst.HEADER_LENGTH; - - return; - } - - /** - * モデル名を出力する。 - *

演出データのモデル名には - * 便宜的に{@link VmdConst.MODELNAME_STAGEACT}が使われる。 - * @param motion モーションデータ - * @throws IOException 出力エラー - * @throws IllegalTextExportException 不正なモデル名の出現 - */ - private void dumpModelName(VmdMotion motion) - throws IOException, IllegalTextExportException{ - String modelName = motion.getModelName(); - if(modelName == null) modelName = VmdConst.MODELNAME_STAGEACT; - - dumpFixedW31j(modelName, VmdConst.MODELNAME_MAX, FDFILLER); - - return; - } - -} diff --git a/src/main/java/jp/sourceforge/mikutoga/vmd/model/binio/VmdLoader.java b/src/main/java/jp/sourceforge/mikutoga/vmd/model/binio/VmdLoader.java deleted file mode 100644 index 35c8f51..0000000 --- a/src/main/java/jp/sourceforge/mikutoga/vmd/model/binio/VmdLoader.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * VMD loader - * - * License : The MIT License - * Copyright(c) 2011 MikuToga Partners - */ - -package jp.sourceforge.mikutoga.vmd.model.binio; - -import java.io.IOException; -import java.io.InputStream; -import jp.sfjp.mikutoga.bin.parser.MmdFormatException; -import jp.sourceforge.mikutoga.vmd.model.VmdMotion; -import jp.sourceforge.mikutoga.vmd.parser.VmdParser; - -/** - * VMDモーションファイルを読み込むためのバイナリローダ。 - */ -public final class VmdLoader { - - /** - * コンストラクタ。 - */ - private VmdLoader(){ - super(); - assert false; - throw new AssertionError(); - } - - - /** - * VMDファイルの読み込みを行いモーション情報を返す。 - * @param source 入力ソース - * @return モーション情報 - * @throws IOException 入力エラー - * @throws MmdFormatException VMDファイルフォーマットの異常を検出 - */ - public static VmdMotion load(InputStream source) - throws IOException, - MmdFormatException { - VmdParser parser = new VmdParser(source); - - VmdMotion result = new VmdMotion(); - - BasicLoader basicBuilder = new BasicLoader(result); - CameraLoader cameraBuilder = new CameraLoader(result); - LightingLoader lightingBuilder = new LightingLoader(result); - - parser.setBasicHandler(basicBuilder); - parser.setCameraHandler(cameraBuilder); - parser.setLightingHandler(lightingBuilder); - - parser.setStrictMode(false); - - parser.parseVmd(); - - return result; - } - -} diff --git a/src/main/java/jp/sourceforge/mikutoga/vmd/model/xml/CameraXmlExporter.java b/src/main/java/jp/sourceforge/mikutoga/vmd/model/xml/CameraXmlExporter.java new file mode 100644 index 0000000..bcc55d0 --- /dev/null +++ b/src/main/java/jp/sourceforge/mikutoga/vmd/model/xml/CameraXmlExporter.java @@ -0,0 +1,255 @@ +/* + * camera xml exporter + * + * License : The MIT License + * Copyright(c) 2013 MikuToga Partners + */ + +package jp.sourceforge.mikutoga.vmd.model.xml; + +import java.io.IOException; +import java.util.List; +import jp.sfjp.mikutoga.math.MkPos3D; +import jp.sfjp.mikutoga.vmd.model.BezierParam; +import jp.sfjp.mikutoga.vmd.model.CameraMotion; +import jp.sfjp.mikutoga.vmd.model.CameraRotation; +import jp.sfjp.mikutoga.vmd.model.PosCurve; +import jp.sfjp.mikutoga.vmd.model.VmdMotion; +import jp.sourceforge.mikutoga.xml.ProxyXmlExporter; + +/** + *カメラ情報のXMLエクスポーター。 + */ +class CameraXmlExporter extends ProxyXmlExporter{ + + + /** + * コンストラクタ。 + * @param proxy 委譲先 + */ + CameraXmlExporter(VmdXmlExporter proxy) { + super(proxy); + return; + } + + + /** + * カメラ演出データを出力する。 + * @param vmdMotion 演出データ + * @throws IOException 出力エラー + */ + void putCameraSequence(VmdMotion vmdMotion) + throws IOException{ + List list = vmdMotion.getCameraMotionList(); + if( ! list.isEmpty() ){ + ind().putBlockComment(XmlSyms.CAMERA_COMMENT); + ind().putBlockComment(XmlSyms.BEZIER_COMMENT); + } + + ind().putSimpleSTag(XmlSyms.TAG_CAMERA_SEQUENCE).ln(); + + pushNest(); + if( ! list.isEmpty() ) ln(); + for(CameraMotion camera : list){ + putCameraMotion(camera); + } + popNest(); + + ind().putETag(XmlSyms.TAG_CAMERA_SEQUENCE).ln(2); + + return; + } + + /** + * カメラモーションを出力する。 + * @param cameraMotion カメラモーション + * @throws IOException 出力エラー + */ + private void putCameraMotion(CameraMotion cameraMotion) + throws IOException{ + ind().putOpenSTag(XmlSyms.TAG_CAMERA_MOTION).sp(); + int frameNo = cameraMotion.getFrameNumber(); + putIntAttr(XmlSyms.ATTR_FRAME, frameNo).sp(); + if( ! cameraMotion.hasPerspective() ){ + putAttr(XmlSyms.ATTR_HAS_PERSPECTIVE, "false").sp(); + } + putCloseSTag().ln(); + + pushNest(); + putCameraTarget(cameraMotion); + putCameraRotation(cameraMotion); + putCameraRange(cameraMotion); + putProjection(cameraMotion); + popNest(); + + ind().putETag(XmlSyms.TAG_CAMERA_MOTION).ln(2); + + return; + } + + /** + * カメラターゲット情報を出力する。 + * @param cameraMotion カメラモーション + * @throws IOException 出力エラー + */ + private void putCameraTarget(CameraMotion cameraMotion) + throws IOException{ + ind().putOpenSTag(XmlSyms.TAG_CAMERA_TARGET).sp(); + MkPos3D position = cameraMotion.getCameraTarget(); + putFloatAttr(XmlSyms.ATTR_X_POS, (float) position.getXpos()).sp(); + putFloatAttr(XmlSyms.ATTR_Y_POS, (float) position.getYpos()).sp(); + putFloatAttr(XmlSyms.ATTR_Z_POS, (float) position.getZpos()).sp(); + + PosCurve posCurve = cameraMotion.getTargetPosCurve(); + if(posCurve.isDefaultLinear()){ + putCloseEmpty().ln(); + }else{ + putCloseSTag().ln(); + + pushNest(); + putPositionCurve(posCurve); + popNest(); + + ind().putETag(XmlSyms.TAG_CAMERA_TARGET).ln(); + } + + return; + } + + /** + * 位置移動補間カーブを出力する。 + * @param posCurve 移動補間情報 + * @throws IOException 出力エラー + */ + private void putPositionCurve(PosCurve posCurve) + throws IOException{ + BezierParam xCurve = posCurve.getIntpltXpos(); + BezierParam yCurve = posCurve.getIntpltYpos(); + BezierParam zCurve = posCurve.getIntpltZpos(); + + ind().putLineComment("X-Y-Z interpolation *3").ln(); + + ind(); + putBezierCurve(xCurve); + ln(); + + ind(); + putBezierCurve(yCurve); + ln(); + + ind(); + putBezierCurve(zCurve); + ln(); + + return; + } + + /** + * カメラ回転情報を出力する。 + * @param cameraMotion カメラモーション + * @throws IOException 出力エラー + */ + private void putCameraRotation(CameraMotion cameraMotion) + throws IOException{ + ind().putOpenSTag(XmlSyms.TAG_CAMERA_ROTATION).sp(); + CameraRotation rotation = cameraMotion.getCameraRotation(); + float latitude = (float) rotation.getLatitude(); + float longitude = (float) rotation.getLongitude(); + float roll = (float) rotation.getRoll(); + putFloatAttr(XmlSyms.ATTR_X_RAD, latitude).sp(); + putFloatAttr(XmlSyms.ATTR_Y_RAD, longitude).sp(); + putFloatAttr(XmlSyms.ATTR_Z_RAD, roll).sp(); + + BezierParam rotCurve = cameraMotion.getIntpltRotation(); + if(rotCurve.isDefaultLinear()){ + putCloseEmpty().ln(); + }else{ + putCloseSTag().ln(); + pushNest(); + ind(); + putBezierCurve(rotCurve); + ln(); + popNest(); + ind().putETag(XmlSyms.TAG_CAMERA_ROTATION).ln(); + } + + return; + } + + /** + * カメラ距離情報を出力する。 + * @param cameraMotion カメラモーション + * @throws IOException 出力エラー + */ + private void putCameraRange(CameraMotion cameraMotion) + throws IOException{ + ind().putOpenSTag(XmlSyms.TAG_CAMERA_RANGE).sp(); + float range = (float) cameraMotion.getRange(); + putFloatAttr(XmlSyms.ATTR_RANGE, range).sp(); + + BezierParam rangeCurve = cameraMotion.getIntpltRange(); + if(rangeCurve.isDefaultLinear()){ + putCloseEmpty().ln(); + }else{ + putCloseSTag().ln(); + pushNest(); + ind(); + putBezierCurve(rangeCurve); + ln(); + popNest(); + ind().putETag(XmlSyms.TAG_CAMERA_RANGE).ln(); + } + + return; + } + + /** + * スクリーン投影情報を出力する。 + * @param cameraMotion カメラモーション + * @throws IOException 出力エラー + */ + private void putProjection(CameraMotion cameraMotion) + throws IOException{ + ind().putOpenSTag(XmlSyms.TAG_PROJECTION).sp(); + int angle = cameraMotion.getProjectionAngle(); + putIntAttr(XmlSyms.ATTR_VERT_DEG, angle).sp(); + + BezierParam projCurve = cameraMotion.getIntpltProjection(); + if(projCurve.isDefaultLinear()){ + putCloseEmpty().ln(); + }else{ + putCloseSTag().ln(); + pushNest(); + ind(); + putBezierCurve(projCurve); + ln(); + popNest(); + ind().putETag(XmlSyms.TAG_PROJECTION).ln(); + } + + return; + } + + /** + * ベジェ曲線による補間曲線情報を出力する。 + * @param bezier ベジェ曲線 + * @throws IOException 出力エラー + */ + private void putBezierCurve(BezierParam bezier) + throws IOException{ + if(bezier.isDefaultLinear()){ + putSimpleEmpty(XmlSyms.TAG_DEF_LINEAR); + }else if(bezier.isDefaultEaseInOut()){ + putSimpleEmpty(XmlSyms.TAG_DEF_EASE_IN_OUT); + }else{ + putOpenSTag(XmlSyms.TAG_BEZIER).sp(); + putIntAttr(XmlSyms.ATTR_P1X, bezier.getP1x()).sp(); + putIntAttr(XmlSyms.ATTR_P1Y, bezier.getP1y()).sp(); + putIntAttr(XmlSyms.ATTR_P2X, bezier.getP2x()).sp(); + putIntAttr(XmlSyms.ATTR_P2Y, bezier.getP2y()).sp(); + putCloseEmpty(); + } + return; + } + +} diff --git a/src/main/java/jp/sourceforge/mikutoga/vmd/model/xml/LightingXmlExpoter.java b/src/main/java/jp/sourceforge/mikutoga/vmd/model/xml/LightingXmlExpoter.java new file mode 100644 index 0000000..9f1f1d8 --- /dev/null +++ b/src/main/java/jp/sourceforge/mikutoga/vmd/model/xml/LightingXmlExpoter.java @@ -0,0 +1,165 @@ +/* + * lighting xml exporter + * + * License : The MIT License + * Copyright(c) 2013 MikuToga Partners + */ + +package jp.sourceforge.mikutoga.vmd.model.xml; + +import java.io.IOException; +import java.util.List; +import jp.sfjp.mikutoga.math.MkVec3D; +import jp.sfjp.mikutoga.vmd.model.LuminousColor; +import jp.sfjp.mikutoga.vmd.model.LuminousMotion; +import jp.sfjp.mikutoga.vmd.model.ShadowMode; +import jp.sfjp.mikutoga.vmd.model.ShadowMotion; +import jp.sfjp.mikutoga.vmd.model.VmdMotion; +import jp.sourceforge.mikutoga.xml.ProxyXmlExporter; +import jp.sourceforge.mikutoga.xml.XmlExporter; + +/** + * ライティング情報のXMLエクスポーター。 + */ +class LightingXmlExpoter extends ProxyXmlExporter { + + /** + * コンストラクタ。 + * @param proxy 委譲先 + */ + LightingXmlExpoter(XmlExporter proxy) { + super(proxy); + return; + } + + /** + * 照明演出データを出力する。 + * @param vmdMotion 演出データ + * @throws IOException 出力エラー + */ + void putLuminousSequence(VmdMotion vmdMotion) + throws IOException{ + ind().putSimpleSTag(XmlSyms.TAG_LUMI_SEQUENCE).ln(); + + pushNest(); + List list = vmdMotion.getLuminousMotionList(); + if( ! list.isEmpty() ) ln(); + for(LuminousMotion luminous : list){ + putLuminousMotion(luminous); + } + popNest(); + + ind().putETag(XmlSyms.TAG_LUMI_SEQUENCE).ln(2); + + return; + } + + /** + * 照明モーションを出力する。 + * @param luminousMotion 照明モーション + * @throws IOException 出力エラー + */ + private void putLuminousMotion(LuminousMotion luminousMotion) + throws IOException{ + ind().putOpenSTag(XmlSyms.TAG_LUMINOUS_ACT).sp(); + int frameNo = luminousMotion.getFrameNumber(); + putIntAttr(XmlSyms.ATTR_FRAME, frameNo).sp(); + putCloseSTag().ln(); + + LuminousColor color = luminousMotion.getColor(); + MkVec3D vector = luminousMotion.getDirection(); + + pushNest(); + putLuminousColor(color); + putLuminousDirection(vector); + popNest(); + + ind().putETag(XmlSyms.TAG_LUMINOUS_ACT).ln(2); + + return; + } + + /** + * 光源色情報を出力する。 + * @param color 光源色 + * @throws IOException 出力エラー + */ + private void putLuminousColor(LuminousColor color) + throws IOException{ + ind().putOpenSTag(XmlSyms.TAG_LUMI_COLOR).sp(); + putFloatAttr(XmlSyms.ATTR_R_COL, color.getColR()).sp(); + putFloatAttr(XmlSyms.ATTR_G_COL, color.getColG()).sp(); + putFloatAttr(XmlSyms.ATTR_B_COL, color.getColB()).sp(); + putCloseEmpty().ln(); + + return; + } + + /** + * 照明方向情報を出力する。 + * @param vector 照明方向 + * @throws IOException 出力エラー + */ + private void putLuminousDirection(MkVec3D vector) + throws IOException{ + ind().putOpenSTag(XmlSyms.TAG_LUMI_DIRECTION).sp(); + putFloatAttr(XmlSyms.ATTR_X_VEC, (float) vector.getXVal()).sp(); + putFloatAttr(XmlSyms.ATTR_Y_VEC, (float) vector.getYVal()).sp(); + putFloatAttr(XmlSyms.ATTR_Z_VEC, (float) vector.getZVal()).sp(); + putCloseEmpty().ln(); + + return; + } + + /** + * シャドウ演出データを出力する。 + * @param vmdMotion 演出データ + * @throws IOException 出力エラー + */ + void putShadowSequence(VmdMotion vmdMotion) + throws IOException{ + List list = vmdMotion.getShadowMotionList(); + if( ! list.isEmpty() ){ + ind().putBlockComment(XmlSyms.SHADOW_COMMENT); + } + + ind().putSimpleSTag(XmlSyms.TAG_SHADOW_SEQUENCE).ln(); + + pushNest(); + for(ShadowMotion shadow : list){ + putShadowMotion(shadow); + } + popNest(); + + ind().putETag(XmlSyms.TAG_SHADOW_SEQUENCE).ln(2); + + return; + } + + /** + * シャドウモーションを出力する。 + * @param shadowMotion シャドウモーション + * @throws IOException 出力エラー + */ + private void putShadowMotion(ShadowMotion shadowMotion) + throws IOException{ + ind().putOpenSTag(XmlSyms.TAG_SHADOW_ACT).sp(); + + int frameNo = shadowMotion.getFrameNumber(); + ShadowMode mode = shadowMotion.getShadowMode(); + float rawParam = (float) shadowMotion.getRawScopeParam(); + + putIntAttr(XmlSyms.ATTR_FRAME, frameNo).sp(); + putAttr(XmlSyms.ATTR_MODE, mode.name()).sp(); + putFloatAttr(XmlSyms.ATTR_RAW_PARAM, rawParam).sp(); + + putCloseEmpty(); + + double uiVal = ShadowMotion.rawParamToScope(rawParam); + long lVal = Math.round(uiVal); + sp().putLineComment("UI:" + lVal).ln(); + + return; + } + +} diff --git a/src/main/java/jp/sourceforge/mikutoga/vmd/model/xml/Schema110820.java b/src/main/java/jp/sourceforge/mikutoga/vmd/model/xml/Schema110820.java index bd07298..8d3a755 100644 --- a/src/main/java/jp/sourceforge/mikutoga/vmd/model/xml/Schema110820.java +++ b/src/main/java/jp/sourceforge/mikutoga/vmd/model/xml/Schema110820.java @@ -9,12 +9,15 @@ package jp.sourceforge.mikutoga.vmd.model.xml; import java.net.URI; import java.net.URISyntaxException; -import jp.sourceforge.mikutoga.xml.LocalSchema; +import jp.sourceforge.mikutoga.xml.LocalXmlResource; /** * 110820形式XML各種リソースの定義。 */ -public class Schema110820 extends LocalSchema{ +public final class Schema110820 implements LocalXmlResource{ + + /** 唯一のシングルトン。 */ + public static final Schema110820 SINGLETON; /** XML名前空間識別子。 */ public static final String NS_VMDXML = @@ -41,13 +44,15 @@ public class Schema110820 extends LocalSchema{ }catch(URISyntaxException e){ throw new ExceptionInInitializerError(e); } + + SINGLETON = new Schema110820(); } /** - * 隠しコンストラクタ。 + * コンストラクタ。 */ - public Schema110820(){ + private Schema110820(){ super(); assert this.getClass() == THISCLASS; return; @@ -59,7 +64,7 @@ public class Schema110820 extends LocalSchema{ * @return {@inheritDoc} */ @Override - public URI getOriginalSchema(){ + public URI getOriginalResource(){ return URI_SCHEMA_VMDXML; } @@ -68,7 +73,7 @@ public class Schema110820 extends LocalSchema{ * @return {@inheritDoc} */ @Override - public URI getLocalSchema(){ + public URI getLocalResource(){ return RES_SCHEMA_VMDXML; } diff --git a/src/main/java/jp/sourceforge/mikutoga/vmd/model/xml/VmdXmlExporter.java b/src/main/java/jp/sourceforge/mikutoga/vmd/model/xml/VmdXmlExporter.java index 1918012..2a8622d 100644 --- a/src/main/java/jp/sourceforge/mikutoga/vmd/model/xml/VmdXmlExporter.java +++ b/src/main/java/jp/sourceforge/mikutoga/vmd/model/xml/VmdXmlExporter.java @@ -10,26 +10,19 @@ package jp.sourceforge.mikutoga.vmd.model.xml; import java.io.IOException; import java.io.OutputStream; import java.util.List; +import java.util.Map; import jp.sfjp.mikutoga.math.EulerYXZ; import jp.sfjp.mikutoga.math.MkPos3D; import jp.sfjp.mikutoga.math.MkQuat; import jp.sfjp.mikutoga.typical.TypicalBone; import jp.sfjp.mikutoga.typical.TypicalMorph; -import jp.sourceforge.mikutoga.vmd.IllegalVmdDataException; -import jp.sourceforge.mikutoga.vmd.VmdConst; -import jp.sourceforge.mikutoga.vmd.model.BezierParam; -import jp.sourceforge.mikutoga.vmd.model.BoneMotion; -import jp.sourceforge.mikutoga.vmd.model.CameraMotion; -import jp.sourceforge.mikutoga.vmd.model.CameraRotation; -import jp.sourceforge.mikutoga.vmd.model.LuminousColor; -import jp.sourceforge.mikutoga.vmd.model.LuminousMotion; -import jp.sourceforge.mikutoga.vmd.model.LuminousVector; -import jp.sourceforge.mikutoga.vmd.model.MorphMotion; -import jp.sourceforge.mikutoga.vmd.model.NamedListMap; -import jp.sourceforge.mikutoga.vmd.model.PosCurve; -import jp.sourceforge.mikutoga.vmd.model.ShadowMode; -import jp.sourceforge.mikutoga.vmd.model.ShadowMotion; -import jp.sourceforge.mikutoga.vmd.model.VmdMotion; +import jp.sfjp.mikutoga.vmd.IllegalVmdDataException; +import jp.sfjp.mikutoga.vmd.VmdUniq; +import jp.sfjp.mikutoga.vmd.model.BezierParam; +import jp.sfjp.mikutoga.vmd.model.BoneMotion; +import jp.sfjp.mikutoga.vmd.model.MorphMotion; +import jp.sfjp.mikutoga.vmd.model.PosCurve; +import jp.sfjp.mikutoga.vmd.model.VmdMotion; import jp.sourceforge.mikutoga.xml.BasicXmlExporter; import jp.sourceforge.mikutoga.xml.XmlResourceResolver; @@ -38,51 +31,28 @@ import jp.sourceforge.mikutoga.xml.XmlResourceResolver; */ public class VmdXmlExporter extends BasicXmlExporter { - private static final String XSINS = "xsi"; + private static final String XML_DECL = + ""; - private static final String TOP_COMMENT = - " MikuMikuDance\n motion-data(*.vmd) on XML"; - - private static final String QUATERNION_COMMENT = - " bone-rotation has Quaternion parameters [boneRotQuat]\n" - + " or YXZ-Euler angles [boneRotEyxz].\n" - + " Quaternion is strongly recommended" - + " if you are data-exchanging."; - - private static final String BEZIER_COMMENT = - " motion interpolation is defined by Bezier-cubic-curve.\n" - + " implicit bezier curve point : P0=(0,0) P3=(127,127)\n" - + " defLinear : MMD default linear curve." - + " P1=(20,20) P2=(107,107) [DEFAULT]\n" - + " defEaseInOut : MMD default ease-in-out curve." - + " P1=(64,0) P2=(64,127)"; - - private static final String CAMERA_COMMENT = - " camera-rotation has polar-coordinates parameters.\n" - + " xRad = -radian(UI_X) [latitude]\n" - + " yRad = radian(UI_Y) [longitude]\n" - + " zRad = radian(UI_Z) [roll]\n" - + " range = -(UI_RANGE)"; - - private static final String SHADOW_COMMENT = - " UI_VALUE = EFFECTIVE_RANGE * 100 ???\n" - +" rawParam = 0.1 - (UI_VALUE / 1.0E+5)\n\n" - +" NONE : no self-shadow\n" - +" MODE_1 : reduce shadow-quality suddenly at range\n" - +" MODE_2 : reduce shadow-quality gradually with range"; + private static final String XSINS = "xsi"; private boolean isQuaternionMode = true; private String generator = ""; + private final CameraXmlExporter cameraXmlExporter; + private final LightingXmlExpoter lightingExporter; + /** * コンストラクタ。 * 文字エンコーディングはUTF-8が用いられる。 - * @param stream 出力ストリーム + * @param ostream 出力ストリーム */ - public VmdXmlExporter(OutputStream stream){ - super(stream); + public VmdXmlExporter(OutputStream ostream){ + super(ostream); + this.cameraXmlExporter = new CameraXmlExporter(this); + this.lightingExporter = new LightingXmlExpoter(this); return; } @@ -97,8 +67,16 @@ public class VmdXmlExporter extends BasicXmlExporter { } /** + * ボーン回転量をクォータニオンで出力するか否か返す。 + * @return クォータニオンで出力するならtrue + */ + public boolean isQuaternionMode(){ + return this.isQuaternionMode; + } + + /** * Generatorメタ情報を設定する。 - * @param generatorArg Generatorメタ情報 + * @param generatorArg Generatorメタ情報。nullならXML出力しない。 */ public void setGenerator(String generatorArg){ this.generator = generatorArg; @@ -106,8 +84,15 @@ public class VmdXmlExporter extends BasicXmlExporter { } /** + * Generatorメタ情報を取得する。 + * @return Generatorメタ情報。XML出力しないならnullを返す。 + */ + public String getGenerator(){ + return this.generator; + } + + /** * VMDモーションデータをXML形式で出力する。 - *

モーションデータと演出データで振り分けられる。 * @param vmdMotion VMDモーションデータ * @throws IOException 出力エラー * @throws IllegalVmdDataException 不正なモーションデータを検出 @@ -124,39 +109,37 @@ public class VmdXmlExporter extends BasicXmlExporter { /** * VMDモーションデータをXML形式で出力する。 - *

モーションデータと演出データで振り分けられる。 * @param vmdMotion VMDモーションデータ * @throws IOException 出力エラー * @throws IllegalVmdDataException 不正なモーションデータを検出 */ private void putVmdXmlImpl(VmdMotion vmdMotion) throws IOException, IllegalVmdDataException{ - ind().putRawText("") - .ln(2); + ind().putRawText(XML_DECL).ln(2); - ind().putBlockComment(TOP_COMMENT).ln(2); + ind().putBlockComment(XmlSyms.TOP_COMMENT).ln(2); - ind().putRawText("").ln(2); + putCloseSTag().ln(2); if(this.generator != null && this.generator.length() > 0){ - ind().putRawText("").ln(2); + ind().putOpenSTag(XmlSyms.TAG_META).sp(); + putAttr(XmlSyms.ATTR_NAME, "generator").sp(); + putAttr(XmlSyms.ATTR_CONTENT, this.generator).sp(); + putCloseEmpty().ln(2); } if(vmdMotion.isModelMotion()){ @@ -164,13 +147,13 @@ public class VmdXmlExporter extends BasicXmlExporter { putBoneMotionSequence(vmdMotion); putMorphSequence(vmdMotion); }else{ - putCameraSequence(vmdMotion); - putLuminousSequence(vmdMotion); - putShadowSequence(vmdMotion); + this.cameraXmlExporter.putCameraSequence(vmdMotion); + this.lightingExporter.putLuminousSequence(vmdMotion); + this.lightingExporter.putShadowSequence(vmdMotion); } - ind().putRawText("").ln(2); - ind().putRawText("").ln(); + ind().putETag(XmlSyms.TAG_VMD_MOTION).ln(2); + ind().putLineComment("EOF").ln(); return; } @@ -211,16 +194,16 @@ public class VmdXmlExporter extends BasicXmlExporter { private void putBezierCurve(BezierParam bezier) throws IOException{ if(bezier.isDefaultLinear()){ - putRawText(""); + putSimpleEmpty(XmlSyms.TAG_DEF_LINEAR); }else if(bezier.isDefaultEaseInOut()){ - putRawText(""); + putSimpleEmpty(XmlSyms.TAG_DEF_EASE_IN_OUT); }else{ - putRawText(""); + putOpenSTag(XmlSyms.TAG_BEZIER).sp(); + putIntAttr(XmlSyms.ATTR_P1X, bezier.getP1x()).sp(); + putIntAttr(XmlSyms.ATTR_P1Y, bezier.getP1y()).sp(); + putIntAttr(XmlSyms.ATTR_P2X, bezier.getP2x()).sp(); + putIntAttr(XmlSyms.ATTR_P2Y, bezier.getP2y()).sp(); + putCloseEmpty(); } return; } @@ -234,10 +217,17 @@ public class VmdXmlExporter extends BasicXmlExporter { throws IOException{ String modelName = vmdMotion.getModelName(); - ind().putLineComment(modelName).ln(); - ind().putRawText("").ln(2); + String modelComm; + if(modelName != null && modelName.length() > 0){ + modelComm = modelName; + }else{ + modelComm = "[NAMELESS]"; + } + + ind().putLineComment(modelComm).ln(); + ind().putOpenSTag(XmlSyms.TAG_MODEL_NAME).sp(); + putAttr(XmlSyms.ATTR_NAME, modelName).sp(); + putCloseEmpty().ln(2); return; } @@ -249,21 +239,23 @@ public class VmdXmlExporter extends BasicXmlExporter { */ private void putBoneMotionSequence(VmdMotion vmdMotion) throws IOException{ - ind().putBlockComment(QUATERNION_COMMENT); - ind().putBlockComment(BEZIER_COMMENT); + Map> boneMap = vmdMotion.getBonePartMap(); - ind().putRawText("").ln(); + if( ! boneMap.isEmpty() ){ + ind().putBlockComment(XmlSyms.QUATERNION_COMMENT); + ind().putBlockComment(XmlSyms.BEZIER_COMMENT); + } + + ind().putSimpleSTag(XmlSyms.TAG_BONE_M_SEQUENCE).ln(); pushNest(); - NamedListMap listmap = vmdMotion.getBonePartMap(); - if( ! listmap.isEmpty() ) ln(); - for(String boneName : listmap.getNames()){ - List list = listmap.getNamedList(boneName); - putBonePart(boneName, list); + if( ! boneMap.isEmpty() ) ln(); + for(Map.Entry> entry : boneMap.entrySet()){ + putBonePart(entry.getKey(), entry.getValue()); } popNest(); - ind().putRawText("").ln(2); + ind().putETag(XmlSyms.TAG_BONE_M_SEQUENCE).ln(2); return; } @@ -283,9 +275,9 @@ public class VmdXmlExporter extends BasicXmlExporter { } ln(); - ind().putRawText("").ln(2); + ind().putOpenSTag(XmlSyms.TAG_BONE_PART).sp(); + putAttr(XmlSyms.ATTR_NAME, boneName).sp(); + putCloseSTag().ln(2); pushNest(); for(BoneMotion bone : list){ @@ -293,7 +285,7 @@ public class VmdXmlExporter extends BasicXmlExporter { } popNest(); - ind().putRawText("").ln(2); + ind().putETag(XmlSyms.TAG_BONE_PART).ln(2); return; } @@ -305,10 +297,10 @@ public class VmdXmlExporter extends BasicXmlExporter { */ private void putBoneMotion(BoneMotion boneMotion) throws IOException{ - ind().putRawText("").ln(); + putIntAttr(XmlSyms.ATTR_FRAME, frameNo).sp(); + putCloseSTag().ln(); pushNest(); putBonePosition(boneMotion); @@ -319,7 +311,7 @@ public class VmdXmlExporter extends BasicXmlExporter { } popNest(); - ind().putRawText("").ln(2); + ind().putETag(XmlSyms.TAG_BONE_MOTION).ln(2); return; } @@ -335,26 +327,26 @@ public class VmdXmlExporter extends BasicXmlExporter { return; } - ind().putRawText("").ln(); + putCloseEmpty().ln(); }else{ - putRawText(">").ln(); + putCloseSTag().ln(); pushNest(); putPositionCurve(posCurve); popNest(); - ind().putRawText("").ln(); + ind().putETag(XmlSyms.TAG_BONE_POSITION).ln(); } return; @@ -370,25 +362,25 @@ public class VmdXmlExporter extends BasicXmlExporter { MkQuat rotation = boneMotion.getRotation(); BezierParam rotCurve = boneMotion.getIntpltRotation(); - ind().putRawText("").ln(); + putCloseEmpty().ln(); }else{ - putRawText(">").ln(); + putCloseSTag().ln(); pushNest(); ind(); putBezierCurve(rotCurve); ln(); popNest(); - ind().putRawText("").ln(); + ind().putETag(XmlSyms.TAG_BONE_ROT_QUAT).ln(); } return; @@ -410,24 +402,24 @@ public class VmdXmlExporter extends BasicXmlExporter { float yDeg = (float)StrictMath.toDegrees(euler.getYRot()); float zDeg = (float)StrictMath.toDegrees(euler.getZRot()); - ind().putRawText("").ln(); + putCloseEmpty().ln(); }else{ - putRawText(">").ln(); + putCloseSTag().ln(); pushNest(); ind(); putBezierCurve(rotCurve); ln(); popNest(); - ind().putRawText("").ln(); + ind().putETag(XmlSyms.TAG_BONE_ROT_EYXZ).ln(); } return; @@ -440,28 +432,31 @@ public class VmdXmlExporter extends BasicXmlExporter { */ private void putMorphSequence(VmdMotion vmdMotion) throws IOException{ - ind().putRawText("").ln(); + ind().putSimpleSTag(XmlSyms.TAG_MORPH_SEQUENCE).ln(); pushNest(); - NamedListMap listmap = vmdMotion.getMorphPartMap(); - if( ! listmap.isEmpty() ) ln(); - putMorphPartList(listmap); + Map> listMap = vmdMotion.getMorphPartMap(); + if( ! listMap.isEmpty() ) ln(); + putMorphPartList(listMap); popNest(); - ind().putRawText("").ln(2); + ind().putETag(XmlSyms.TAG_MORPH_SEQUENCE).ln(2); return; } /** * 箇所別モーフデータを出力する。 - * @param listmap モーフデータの名前付きリストマップ + * @param listMap モーフデータの名前付きリストマップ * @throws IOException 出力エラー */ - private void putMorphPartList(NamedListMap listmap) + private void putMorphPartList(Map> listMap) throws IOException{ - for(String morphName : listmap.getNames()){ - if(VmdConst.isBaseMorphName(morphName)) continue; + for(Map.Entry> entry : listMap.entrySet()){ + String morphName = entry.getKey(); + List list = entry.getValue(); + + if(VmdUniq.isBaseMorphName(morphName)) continue; ind().putLineComment(morphName); String globalName = TypicalMorph.primary2global(morphName); @@ -470,18 +465,17 @@ public class VmdXmlExporter extends BasicXmlExporter { } ln(); - ind().putRawText("").ln(); + ind().putOpenSTag(XmlSyms.TAG_MORPH_PART).sp(); + putAttr(XmlSyms.ATTR_NAME, morphName).sp(); + putCloseSTag().ln(); pushNest(); - List list = listmap.getNamedList(morphName); for(MorphMotion morph : list){ putMorphMotion(morph); } popNest(); - ind().putRawText("").ln(2); + ind().putETag(XmlSyms.TAG_MORPH_PART).ln(2); } return; @@ -494,306 +488,15 @@ public class VmdXmlExporter extends BasicXmlExporter { */ private void putMorphMotion(MorphMotion morphMotion) throws IOException{ - ind().putRawText("").ln(); - - return; - } - - /** - * カメラ演出データを出力する。 - * @param vmdMotion 演出データ - * @throws IOException 出力エラー - */ - private void putCameraSequence(VmdMotion vmdMotion) - throws IOException{ - ind().putBlockComment(BEZIER_COMMENT); - ind().putBlockComment(CAMERA_COMMENT); - - ind().putRawText("").ln(); - - pushNest(); - List list = vmdMotion.getCameraMotionList(); - if( ! list.isEmpty() ) ln(); - for(CameraMotion camera : list){ - putCameraMotion(camera); - } - popNest(); - - ind().putRawText("").ln(2); - - return; - } - - /** - * カメラモーションを出力する。 - * @param cameraMotion カメラモーション - * @throws IOException 出力エラー - */ - private void putCameraMotion(CameraMotion cameraMotion) - throws IOException{ - ind().putRawText("").ln(); - - pushNest(); - putCameraTarget(cameraMotion); - putCameraRotation(cameraMotion); - putCameraRange(cameraMotion); - putProjection(cameraMotion); - popNest(); - - ind().putRawText("").ln(2); - - return; - } - - /** - * カメラターゲット情報を出力する。 - * @param cameraMotion カメラモーション - * @throws IOException 出力エラー - */ - private void putCameraTarget(CameraMotion cameraMotion) - throws IOException{ - ind().putRawText("").ln(); - }else{ - putRawText(">").ln(); - - pushNest(); - putPositionCurve(posCurve); - popNest(); - - ind().putRawText("").ln(); - } - - return; - } - - /** - * カメラ回転情報を出力する。 - * @param cameraMotion カメラモーション - * @throws IOException 出力エラー - */ - private void putCameraRotation(CameraMotion cameraMotion) - throws IOException{ - ind().putRawText("").ln(); - }else{ - putRawText(">").ln(); - pushNest(); - ind(); - putBezierCurve(rotCurve); - ln(); - popNest(); - ind().putRawText("").ln(); - } - - return; - } - - /** - * カメラ距離情報を出力する。 - * @param cameraMotion カメラモーション - * @throws IOException 出力エラー - */ - private void putCameraRange(CameraMotion cameraMotion) - throws IOException{ - ind().putRawText("").ln(); - }else{ - putRawText(">").ln(); - pushNest(); - ind(); - putBezierCurve(rangeCurve); - ln(); - popNest(); - ind().putRawText("").ln(); - } - - return; - } - - /** - * スクリーン投影情報を出力する。 - * @param cameraMotion カメラモーション - * @throws IOException 出力エラー - */ - private void putProjection(CameraMotion cameraMotion) - throws IOException{ - ind().putRawText("").ln(); - }else{ - putRawText(">").ln(); - pushNest(); - ind(); - putBezierCurve(projCurve); - ln(); - popNest(); - ind().putRawText("").ln(); - } - - return; - } - - /** - * 照明演出データを出力する。 - * @param vmdMotion 演出データ - * @throws IOException 出力エラー - */ - private void putLuminousSequence(VmdMotion vmdMotion) - throws IOException{ - ind().putRawText("").ln(); - - pushNest(); - List list = vmdMotion.getLuminousMotionList(); - if( ! list.isEmpty() ) ln(); - for(LuminousMotion luminous : list){ - putLuminousMotion(luminous); - } - popNest(); - - ind().putRawText("").ln(2); - - return; - } - - /** - * 照明モーションを出力する。 - * @param luminousMotion 照明モーション - * @throws IOException 出力エラー - */ - private void putLuminousMotion(LuminousMotion luminousMotion) - throws IOException{ - ind().putRawText("").ln(); - - LuminousColor color = luminousMotion.getColor(); - LuminousVector vector = luminousMotion.getDirection(); - - pushNest(); - putLuminousColor(color); - putLuminousDirection(vector); - popNest(); - - ind().putRawText("").ln(2); - - return; - } - - /** - * 光源色情報を出力する。 - * @param color 光源色 - * @throws IOException 出力エラー - */ - private void putLuminousColor(LuminousColor color) - throws IOException{ - ind().putRawText("").ln(); - - return; - } - - /** - * 照明方向情報を出力する。 - * @param vector 照明方向 - * @throws IOException 出力エラー - */ - private void putLuminousDirection(LuminousVector vector) - throws IOException{ - ind().putRawText("").ln(); - - return; - } - - /** - * シャドウ演出データを出力する。 - * @param vmdMotion 演出データ - * @throws IOException 出力エラー - */ - private void putShadowSequence(VmdMotion vmdMotion) - throws IOException{ - ind().putBlockComment(SHADOW_COMMENT); - - ind().putRawText("").ln(); - - pushNest(); - List list = vmdMotion.getShadowMotionList(); - for(ShadowMotion shadow : list){ - putShadowMotion(shadow); - } - popNest(); - - ind().putRawText("").ln(2); - - return; - } - - /** - * シャドウモーションを出力する。 - * @param shadowMotion シャドウモーション - * @throws IOException 出力エラー - */ - private void putShadowMotion(ShadowMotion shadowMotion) - throws IOException{ - ind().putRawText(""); + putIntAttr(XmlSyms.ATTR_FRAME, frameNo).sp(); + putFloatAttr(XmlSyms.ATTR_FLEX, flex).sp(); - double uiVal = ShadowMotion.rawParamToScope(rawParam); - long lVal = Math.round(uiVal); - sp().putLineComment("UI:" + lVal).ln(); + putCloseEmpty().ln(); return; } diff --git a/src/main/java/jp/sourceforge/mikutoga/vmd/model/xml/VmdXmlResources.java b/src/main/java/jp/sourceforge/mikutoga/vmd/model/xml/VmdXmlResources.java deleted file mode 100644 index b8db958..0000000 --- a/src/main/java/jp/sourceforge/mikutoga/vmd/model/xml/VmdXmlResources.java +++ /dev/null @@ -1,163 +0,0 @@ -/* - * xml resources for VMD-XML - * - * License : The MIT License - * Copyright(c) 2011 MikuToga Partners - */ - -package jp.sourceforge.mikutoga.vmd.model.xml; - -import java.net.MalformedURLException; -import java.net.URI; -import java.net.URISyntaxException; -import java.net.URL; -import javax.xml.XMLConstants; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.validation.Schema; -import javax.xml.validation.SchemaFactory; -import jp.sourceforge.mikutoga.xml.XmlResourceResolver; -import org.w3c.dom.ls.LSResourceResolver; -import org.xml.sax.ErrorHandler; -import org.xml.sax.SAXException; - -/** - * モーションデータ用各種XMLリソースの定義。 - */ -public final class VmdXmlResources { - - /** 定義の版数。 */ - public static final String VER_VMDXML = - "110820"; - /** XML名前空間識別子。 */ - public static final String NS_VMDXML = - "http://mikutoga.sourceforge.jp/xml/ns/vmdxml/110820"; - /** XMLスキーマURI名。 */ - public static final String SCHEMAURI_VMDXML = - "http://mikutoga.sourceforge.jp/xml/xsd/vmdxml-110820.xsd"; - /** ローカルなスキーマファイル名。 */ - public static final String LOCAL_SCHEMA_VMDXML = - "resources/vmdxml-110820.xsd"; - - /** XMLスキーマURI。 */ - public static final URI URI_SCHEMA_VMDXML; - /** XMLスキーマのローカルリソース。 */ - public static final URI RES_SCHEMA_VMDXML; - - - private static final Class THISCLASS = VmdXmlResources.class; - - - static{ - try{ - URI_SCHEMA_VMDXML = URI.create(SCHEMAURI_VMDXML); - RES_SCHEMA_VMDXML = - THISCLASS.getResource(LOCAL_SCHEMA_VMDXML).toURI(); - }catch(URISyntaxException e){ - throw new ExceptionInInitializerError(e); - } - - new VmdXmlResources().hashCode(); - } - - - /** - * 隠しコンストラクタ。 - */ - private VmdXmlResources(){ - super(); - assert this.getClass().equals(THISCLASS); - return; - } - - - /** - * ビルダの生成。 - * @param handler エラーハンドラ - * @return ビルダ - */ - public static DocumentBuilder newBuilder(ErrorHandler handler){ - XmlResourceResolver resolver = createResolver(); - - Schema schema = createSchema(resolver); - - DocumentBuilderFactory builderFactory = createBuilderFactory(); - builderFactory.setSchema(schema); - - DocumentBuilder builder; - try{ - builder = builderFactory.newDocumentBuilder(); - }catch(ParserConfigurationException e){ - assert false; - throw new AssertionError(e); - } - builder.setEntityResolver(resolver); - builder.setErrorHandler(handler); - - return builder; - } - - /** - * URI参照をローカルなリソースアクセスへとリダイレクトするリゾルバを生成する。 - * @return リゾルバ - */ - private static XmlResourceResolver createResolver(){ - XmlResourceResolver resolver = new XmlResourceResolver(); - resolver.putRedirected(URI_SCHEMA_VMDXML, RES_SCHEMA_VMDXML); -// resolver.putRedirected(URI_DTD_VMDXML, RES_DTD_VMDXML); - - return resolver; - } - - /** - * 検証用スキーマ(XML schema)を生成する。 - * @param resolver リゾルバ - * @return スキーマ - */ - private static Schema createSchema(LSResourceResolver resolver){ - SchemaFactory schemaFactory = - SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); - schemaFactory.setResourceResolver(resolver); - - URL localXsd; - try{ - localXsd = RES_SCHEMA_VMDXML.toURL(); - }catch(MalformedURLException e){ - assert false; - throw new AssertionError(e); - } - - Schema schema; - try{ - schema = schemaFactory.newSchema(localXsd); - }catch(SAXException e){ - assert false; - throw new AssertionError(e); - } - - return schema; - } - - /** - * DocumentBuilderFavtoryを生成する。 - * @return ファクトリ - */ - private static DocumentBuilderFactory createBuilderFactory(){ - DocumentBuilderFactory builderFactory = - DocumentBuilderFactory.newInstance(); - - builderFactory.setNamespaceAware(true); - builderFactory.setValidating(false); // DTD validation off - builderFactory.setIgnoringComments(true); - try{ - builderFactory.setXIncludeAware(true); - }catch(UnsupportedOperationException e){ - // NOTHING - assert true; - } - - return builderFactory; - } - -} diff --git a/src/main/java/jp/sourceforge/mikutoga/vmd/model/xml/Xml.java b/src/main/java/jp/sourceforge/mikutoga/vmd/model/xml/Xml.java index 5bd1e72..cb4e3f8 100644 --- a/src/main/java/jp/sourceforge/mikutoga/vmd/model/xml/Xml.java +++ b/src/main/java/jp/sourceforge/mikutoga/vmd/model/xml/Xml.java @@ -8,8 +8,8 @@ package jp.sourceforge.mikutoga.vmd.model.xml; import java.util.Iterator; -import jp.sourceforge.mikutoga.vmd.model.BezierParam; -import jp.sourceforge.mikutoga.vmd.model.PosCurve; +import jp.sfjp.mikutoga.vmd.model.BezierParam; +import jp.sfjp.mikutoga.vmd.model.PosCurve; import jp.sourceforge.mikutoga.xml.DomNsUtils; import jp.sourceforge.mikutoga.xml.SiblingElemIterator; import jp.sourceforge.mikutoga.xml.TogaXmlException; @@ -46,7 +46,7 @@ final class Xml { static boolean hasNsLocalNameElem(Element elem, String localName ){ return DomNsUtils.hasNsLocalNameElem(elem, - VmdXmlResources.NS_VMDXML, + Schema110820.NS_VMDXML, localName ); } @@ -58,7 +58,7 @@ final class Xml { */ static Element pickChild(Element parent, String localName){ return DomNsUtils.pickFirstChild(parent, - VmdXmlResources.NS_VMDXML, + Schema110820.NS_VMDXML, localName ); } @@ -73,7 +73,7 @@ final class Xml { static Element getChild(Element parent, String localName) throws TogaXmlException{ return DomNsUtils.getFirstChild(parent, - VmdXmlResources.NS_VMDXML, + Schema110820.NS_VMDXML, localName ); } @@ -85,7 +85,7 @@ final class Xml { */ static Iterable eachChild(Element parent, String localName){ return DomNsUtils.getEachChild(parent, - VmdXmlResources.NS_VMDXML, + Schema110820.NS_VMDXML, localName ); } @@ -214,14 +214,15 @@ final class Xml { */ static void buildPosCurve(Element positionElem, PosCurve curve) throws TogaXmlException{ - Iterator it = + Iterator itElem = new SiblingElemIterator(positionElem, - VmdXmlResources.NS_VMDXML, null); + Schema110820.NS_VMDXML, null); + Iterator itBez = curve.iterator(); int ct = 0; - while(it.hasNext()){ - Element curveElem = it.next(); - BezierParam bz = curve.item(ct); + while(itElem.hasNext()){ + Element curveElem = itElem.next(); + BezierParam bz = itBez.next(); setBezier(curveElem, bz); ct++; } diff --git a/src/main/java/jp/sourceforge/mikutoga/vmd/model/xml/Xml2VmdLoader.java b/src/main/java/jp/sourceforge/mikutoga/vmd/model/xml/Xml2VmdLoader.java index ce5912c..d7a6d46 100644 --- a/src/main/java/jp/sourceforge/mikutoga/vmd/model/xml/Xml2VmdLoader.java +++ b/src/main/java/jp/sourceforge/mikutoga/vmd/model/xml/Xml2VmdLoader.java @@ -12,12 +12,11 @@ import java.text.MessageFormat; import javax.xml.parsers.DocumentBuilder; import jp.sfjp.mikutoga.math.MkPos3D; import jp.sfjp.mikutoga.math.MkQuat; -import jp.sourceforge.mikutoga.vmd.model.BezierParam; -import jp.sourceforge.mikutoga.vmd.model.BoneMotion; -import jp.sourceforge.mikutoga.vmd.model.MorphMotion; -import jp.sourceforge.mikutoga.vmd.model.NamedListMap; -import jp.sourceforge.mikutoga.vmd.model.PosCurve; -import jp.sourceforge.mikutoga.vmd.model.VmdMotion; +import jp.sfjp.mikutoga.vmd.model.BezierParam; +import jp.sfjp.mikutoga.vmd.model.BoneMotion; +import jp.sfjp.mikutoga.vmd.model.MorphMotion; +import jp.sfjp.mikutoga.vmd.model.PosCurve; +import jp.sfjp.mikutoga.vmd.model.VmdMotion; import jp.sourceforge.mikutoga.xml.TogaXmlException; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -73,7 +72,7 @@ public class Xml2VmdLoader { * @throws TogaXmlException 構文エラー */ private static void buildModelName(Element vmdMotionElem, - VmdMotion vmdMotion) + VmdMotion vmdMotion) throws TogaXmlException{ Element modelNameElem = Xml.getChild(vmdMotionElem, "modelName"); String modelName = Xml.getStringAttr(modelNameElem, "name"); @@ -88,15 +87,13 @@ public class Xml2VmdLoader { * @throws TogaXmlException 構文エラー */ private static void buildBoneSeq(Element vmdMotionElem, - VmdMotion vmdMotion ) + VmdMotion vmdMotion ) throws TogaXmlException{ - NamedListMap boneMap = vmdMotion.getBonePartMap(); - Element boneSeqElem = Xml.getChild(vmdMotionElem, "boneMotionSequence"); for(Element bonePartElem : Xml.eachChild(boneSeqElem, "bonePart")){ - buildBonePart(bonePartElem, boneMap); + buildBonePart(bonePartElem, vmdMotion); } return; @@ -105,11 +102,11 @@ public class Xml2VmdLoader { /** * ボーンパートを読み込む。 * @param bonePartElem bonePart要素 - * @param boneMap 名前マップ + * @param vmdMotion モーション * @throws TogaXmlException 構文エラー */ private static void buildBonePart(Element bonePartElem, - NamedListMap boneMap ) + VmdMotion vmdMotion ) throws TogaXmlException{ String boneName = Xml.getStringAttr(bonePartElem, "name"); @@ -117,7 +114,7 @@ public class Xml2VmdLoader { Xml.eachChild(bonePartElem, "boneMotion")){ BoneMotion boneMotion = buildBoneMotion(boneMotionElem); boneMotion.setBoneName(boneName); - boneMap.addNamedElement(boneName, boneMotion); + vmdMotion.addBoneMotion(boneMotion); } return; @@ -236,15 +233,13 @@ public class Xml2VmdLoader { * @throws TogaXmlException 構文エラー */ private static void buildMorphSeq(Element vmdMotionElem, - VmdMotion vmdMotion ) + VmdMotion vmdMotion ) throws TogaXmlException{ - NamedListMap morphMap = vmdMotion.getMorphPartMap(); - Element morphSeqElem = Xml.getChild(vmdMotionElem, "morphSequence"); for(Element morphPartElem : Xml.eachChild(morphSeqElem, "morphPart")){ - buildMorphPart(morphPartElem, morphMap); + buildMorphPart(morphPartElem, vmdMotion); } return; @@ -253,11 +248,11 @@ public class Xml2VmdLoader { /** * モーフパートを読み込む。 * @param morphPartElem morphPart要素 - * @param morphMap 名前マップ + * @param vmdMotion モーション * @throws TogaXmlException 構文エラー */ private static void buildMorphPart(Element morphPartElem, - NamedListMap morphMap ) + VmdMotion vmdMotion ) throws TogaXmlException{ String morphName = Xml.getStringAttr(morphPartElem, "name"); @@ -266,7 +261,7 @@ public class Xml2VmdLoader { for(Element morphMotionElem : childs){ MorphMotion morphMotion = buildMorphMotion(morphMotionElem); morphMotion.setMorphName(morphName); - morphMap.addNamedElement(morphName, morphMotion); + vmdMotion.addMorphMotion(morphMotion); } return; diff --git a/src/main/java/jp/sourceforge/mikutoga/vmd/model/xml/XmlCameraLoader.java b/src/main/java/jp/sourceforge/mikutoga/vmd/model/xml/XmlCameraLoader.java index c9e30b0..d2af098 100644 --- a/src/main/java/jp/sourceforge/mikutoga/vmd/model/xml/XmlCameraLoader.java +++ b/src/main/java/jp/sourceforge/mikutoga/vmd/model/xml/XmlCameraLoader.java @@ -9,11 +9,11 @@ package jp.sourceforge.mikutoga.vmd.model.xml; import java.util.List; import jp.sfjp.mikutoga.math.MkPos3D; -import jp.sourceforge.mikutoga.vmd.model.BezierParam; -import jp.sourceforge.mikutoga.vmd.model.CameraMotion; -import jp.sourceforge.mikutoga.vmd.model.CameraRotation; -import jp.sourceforge.mikutoga.vmd.model.PosCurve; -import jp.sourceforge.mikutoga.vmd.model.VmdMotion; +import jp.sfjp.mikutoga.vmd.model.BezierParam; +import jp.sfjp.mikutoga.vmd.model.CameraMotion; +import jp.sfjp.mikutoga.vmd.model.CameraRotation; +import jp.sfjp.mikutoga.vmd.model.PosCurve; +import jp.sfjp.mikutoga.vmd.model.VmdMotion; import jp.sourceforge.mikutoga.xml.TogaXmlException; import org.w3c.dom.Element; diff --git a/src/main/java/jp/sourceforge/mikutoga/vmd/model/xml/XmlLightingLoader.java b/src/main/java/jp/sourceforge/mikutoga/vmd/model/xml/XmlLightingLoader.java index 49cb91b..df7cfc5 100644 --- a/src/main/java/jp/sourceforge/mikutoga/vmd/model/xml/XmlLightingLoader.java +++ b/src/main/java/jp/sourceforge/mikutoga/vmd/model/xml/XmlLightingLoader.java @@ -8,12 +8,12 @@ package jp.sourceforge.mikutoga.vmd.model.xml; import java.util.List; -import jp.sourceforge.mikutoga.vmd.model.LuminousColor; -import jp.sourceforge.mikutoga.vmd.model.LuminousMotion; -import jp.sourceforge.mikutoga.vmd.model.LuminousVector; -import jp.sourceforge.mikutoga.vmd.model.ShadowMode; -import jp.sourceforge.mikutoga.vmd.model.ShadowMotion; -import jp.sourceforge.mikutoga.vmd.model.VmdMotion; +import jp.sfjp.mikutoga.math.MkVec3D; +import jp.sfjp.mikutoga.vmd.model.LuminousColor; +import jp.sfjp.mikutoga.vmd.model.LuminousMotion; +import jp.sfjp.mikutoga.vmd.model.ShadowMode; +import jp.sfjp.mikutoga.vmd.model.ShadowMotion; +import jp.sfjp.mikutoga.vmd.model.VmdMotion; import jp.sourceforge.mikutoga.xml.TogaXmlException; import org.w3c.dom.Element; @@ -79,13 +79,13 @@ final class XmlLightingLoader { Element lumiDirectionElem = Xml.getChild(luminousActElem, "lumiDirection"); - LuminousVector vec = luminousMotion.getDirection(); + MkVec3D vec = luminousMotion.getDirection(); float xVec = Xml.getFloatAttr(lumiDirectionElem, "xVec"); float yVec = Xml.getFloatAttr(lumiDirectionElem, "yVec"); float zVec = Xml.getFloatAttr(lumiDirectionElem, "zVec"); - vec.setVecX(xVec); - vec.setVecY(yVec); - vec.setVecZ(zVec); + vec.setXVal(xVec); + vec.setYVal(yVec); + vec.setZVal(zVec); luminousList.add(luminousMotion); diff --git a/src/main/java/jp/sourceforge/mikutoga/vmd/model/xml/XmlSyms.java b/src/main/java/jp/sourceforge/mikutoga/vmd/model/xml/XmlSyms.java new file mode 100644 index 0000000..c8e2ff6 --- /dev/null +++ b/src/main/java/jp/sourceforge/mikutoga/vmd/model/xml/XmlSyms.java @@ -0,0 +1,117 @@ +/* + * xml symbols + * + * License : The MIT License + * Copyright(c) 2013 MikuToga Partners + */ + +package jp.sourceforge.mikutoga.vmd.model.xml; + +/** + * XML 各種シンボル名。 + */ +final class XmlSyms { + + static final String TOP_COMMENT = + " MikuMikuDance\n motion-data(*.vmd) on XML"; + + static final String QUATERNION_COMMENT = + " bone-rotation has Quaternion parameters [boneRotQuat]\n" + + " or YXZ-Euler angles [boneRotEyxz].\n" + + " Quaternion form is strongly recommended" + + " if you are data-exchanging."; + + static final String BEZIER_COMMENT = + " motion-interpolation is described with Bezier-cubic-curve.\n" + + " implicit bezier curve point : P0=(0,0) P3=(127,127)\n" + + " defLinear : MMD default linear curve." + + " P1=(20,20) P2=(107,107) [DEFAULT]\n" + + " defEaseInOut : MMD default ease-in-out curve." + + " P1=(64,0) P2=(64,127)"; + + static final String CAMERA_COMMENT = + " camera-rotation has polar-coordinates parameters.\n" + + " xRad = -radian(UI_X) [latitude]\n" + + " yRad = radian(UI_Y) [longitude]\n" + + " zRad = radian(UI_Z) [roll]\n" + + " range = -(UI_RANGE)"; + + static final String SHADOW_COMMENT = + " UI_VALUE = EFFECTIVE_RANGE * 100 ???\n" + +" rawParam = 0.1 - (UI_VALUE / 1.0E+5)\n\n" + +" NONE : no self-shadow\n" + +" MODE_1 : reduce shadow-quality suddenly at range\n" + +" MODE_2 : reduce shadow-quality gradually with range"; + + static final String TAG_VMD_MOTION = "vmdMotion"; + static final String TAG_META = "meta"; + static final String TAG_MODEL_NAME = "modelName"; + static final String TAG_BONE_M_SEQUENCE = "boneMotionSequence"; + static final String TAG_BONE_PART = "bonePart"; + static final String TAG_BONE_MOTION = "boneMotion"; + static final String TAG_BONE_POSITION = "bonePosition"; + static final String TAG_BONE_ROT_QUAT = "boneRotQuat"; + static final String TAG_BONE_ROT_EYXZ = "boneRotEyxz"; + static final String TAG_BEZIER = "bezier"; + static final String TAG_DEF_LINEAR = "defLinear"; + static final String TAG_DEF_EASE_IN_OUT = "defEaseInOut"; + static final String TAG_MORPH_SEQUENCE = "morphSequence"; + static final String TAG_MORPH_PART = "morphPart"; + static final String TAG_MORPH_MOTION = "morphMotion"; + static final String TAG_CAMERA_SEQUENCE = "cameraSequence"; + static final String TAG_CAMERA_MOTION = "cameraMotion"; + static final String TAG_CAMERA_TARGET = "cameraTarget"; + static final String TAG_CAMERA_ROTATION = "cameraRotation"; + static final String TAG_CAMERA_RANGE = "cameraRange"; + static final String TAG_PROJECTION = "projection"; + static final String TAG_LUMI_SEQUENCE = "luminousSequence"; + static final String TAG_LUMINOUS_ACT = "luminousAct"; + static final String TAG_LUMI_COLOR = "lumiColor"; + static final String TAG_LUMI_DIRECTION = "lumiDirection"; + static final String TAG_SHADOW_SEQUENCE = "shadowSequence"; + static final String TAG_SHADOW_ACT = "shadowAct"; + + static final String ATTR_VERSION = "version"; + static final String ATTR_CONTENT = "content"; + static final String ATTR_FRAME = "frame"; + static final String ATTR_NAME = "name"; + static final String ATTR_P1X = "p1x"; + static final String ATTR_P1Y = "p1y"; + static final String ATTR_P2X = "p2x"; + static final String ATTR_P2Y = "p2y"; + static final String ATTR_QX = "qx"; + static final String ATTR_QY = "qy"; + static final String ATTR_QZ = "qz"; + static final String ATTR_QW = "qw"; + static final String ATTR_X_DEG = "xDeg"; + static final String ATTR_Y_DEG = "yDeg"; + static final String ATTR_Z_DEG = "zDeg"; + static final String ATTR_X_POS = "xPos"; + static final String ATTR_Y_POS = "yPos"; + static final String ATTR_Z_POS = "zPos"; + static final String ATTR_FLEX = "flex"; + static final String ATTR_RANGE = "range"; + static final String ATTR_X_RAD = "xRad"; + static final String ATTR_Y_RAD = "yRad"; + static final String ATTR_Z_RAD = "zRad"; + static final String ATTR_VERT_DEG = "vertDeg"; + static final String ATTR_HAS_PERSPECTIVE = "hasPerspective"; + static final String ATTR_X_VEC = "xVec"; + static final String ATTR_Y_VEC = "yVec"; + static final String ATTR_Z_VEC = "zVec"; + static final String ATTR_R_COL = "rCol"; + static final String ATTR_G_COL = "gCol"; + static final String ATTR_B_COL = "bCol"; + static final String ATTR_MODE = "mode"; + static final String ATTR_RAW_PARAM = "rawParam"; + + + /** + * 隠しコンストラクタ。 + */ + private XmlSyms(){ + assert false; + throw new AssertionError(); + } + +} diff --git a/src/main/java/jp/sourceforge/mikutoga/vmd2xml/ArgInfo.java b/src/main/java/jp/sourceforge/mikutoga/vmd2xml/ArgInfo.java deleted file mode 100644 index 53dabe0..0000000 --- a/src/main/java/jp/sourceforge/mikutoga/vmd2xml/ArgInfo.java +++ /dev/null @@ -1,312 +0,0 @@ -/* - * command argument information - * - * License : The MIT License - * Copyright(c) 2011 MikuToga Partners - */ - -package jp.sourceforge.mikutoga.vmd2xml; - -import java.util.Arrays; -import java.util.Iterator; - -/** - * コマンドライン引数情報。 - */ -final class ArgInfo { - - /** ヘルプ文字列。 */ - public static final String CMD_HELP = - "-h : put help massage\n\n" - + "-vmd2xml : convert *.vmd to *.xml\n" - + "-xml2vmd : convert *.xml to *.vmd\n\n" - + "-i file : specify input file\n" - + "-o file : specify output file\n" - + "-f : force overwriting\n\n" - + "-quat : Quaternion output mode [default]\n" - + "-eyxz : YXZ-Euler output mode\n"; - - private static final String ERRMSG_UNKNOWN = "Unknown option : "; - private static final String ERRMSG_INCOMP_I = "You need -i argument."; - private static final String ERRMSG_INCOMP_O = "You need -o argument."; - private static final String ERRMSG_EXCLUSIVE = - "You must specify -vmd2xml or -xml2vmd."; - private static final String ERRMSG_NOINPUT = - "You must specify input file with -i."; - private static final String ERRMSG_NOOUTPUT = - "You must specify output file with -o."; - - - private String inputFile = null; - private String outputFile = null; - private boolean vmd2xml = false; - private boolean xml2vmd = false; - private boolean force = false; - private boolean helpMode = false; - private boolean quaternionMode = true; - - private boolean hasOptionError = false; - private String errorMessage = null; - - - /** - * コンストラクタ。 - */ - private ArgInfo(){ - super(); - return; - } - - - /** - * コマンドライン引数を解析する。 - * @param args コマンドライン引数 - * @return 解析結果 - */ - public static ArgInfo buildArgInfo(String[] args){ - return buildArgInfo(Arrays.asList(args)); - } - - /** - * コマンドライン引数を解析する。 - * @param args コマンドライン引数 - * @return 解析結果 - */ - public static ArgInfo buildArgInfo(Iterable args){ - return buildArgInfo(args.iterator()); - } - - /** - * コマンドライン引数を解析する。 - * @param argIter コマンドライン引数 - * @return 解析結果 - */ - public static ArgInfo buildArgInfo(Iterator argIter){ - ArgInfo result = new ArgInfo(); - - while(argIter.hasNext()){ - String arg = argIter.next(); - OptSwitch option = OptSwitch.parse(arg); - if(option == null){ - result.setOptionError(ERRMSG_UNKNOWN + arg); - break; - } - - result.parseOption(option, argIter); - - if(result.hasOptionError()) break; - if(result.isHelpMode()) break; - } - - result.checkOptionError(); - - return result; - } - - /** - * 単一もしくは引数を持つオプション種別を解析する。 - * @param argIter コマンドライン引数 - * @param option オプション種別 - */ - private void parseOption(OptSwitch option, Iterator argIter){ - switch(option){ - case HELP: - this.helpMode = true; - break; - case VMD2XML: - this.vmd2xml = true; - this.xml2vmd = false; - break; - case XML2VMD: - this.vmd2xml = false; - this.xml2vmd = true; - break; - case FORCE: - this.force = true; - break; - case INPUTFILE: - if( ! argIter.hasNext() ){ - this.setOptionError(ERRMSG_INCOMP_I); - break; - } - this.inputFile = argIter.next(); - break; - case OUTPUTFILE: - if( ! argIter.hasNext() ){ - this.setOptionError(ERRMSG_INCOMP_O); - break; - } - this.outputFile = argIter.next(); - break; - case QUATERNION: - this.quaternionMode = true; - break; - case EULERYXZ: - this.quaternionMode = false; - break; - default: - assert false; - throw new AssertionError(); - } - - return; - } - - /** - * オプション指定の整合性をチェックする。 - *

必要に応じてエラーの有無とメッセージが登録される。 - */ - private void checkOptionError(){ - if( hasOptionError() || isHelpMode() ) return; - - if( ( ! isVmd2XmlMode() ) && ( ! isXml2VmdMode() ) ){ - setOptionError(ERRMSG_EXCLUSIVE); - }else if(getInputFile() == null){ - setOptionError(ERRMSG_NOINPUT); - }else if(getOutputFile() == null){ - setOptionError(ERRMSG_NOOUTPUT); - } - - return; - } - - /** - * オプションエラーを設定する。 - * @param text メッセージ - */ - private void setOptionError(CharSequence text){ - if(text == null){ - this.errorMessage = null; - this.hasOptionError = false; - }else{ - this.errorMessage = text.toString(); - this.hasOptionError = true; - } - - return; - } - - /** - * 入力ファイル名を返す。 - * @return 入力ファイル名 - */ - public String getInputFile(){ - return this.inputFile; - } - - /** - * 出力ファイル名を返す。 - * @return 出力ファイル名 - */ - public String getOutputFile(){ - return this.outputFile; - } - - /** - * 強制上書きモードか判定を返す。 - * @return 強制上書きモードならtrue - */ - public boolean isForceMode(){ - return this.force; - } - - /** - * VMD-XML変換モードか判定を返す。 - * @return VMD-XML変換モードならtrue - */ - public boolean isVmd2XmlMode(){ - return this.vmd2xml; - } - - /** - * XML-VMD変換モードか判定を返す。 - * @return XML-VMD変換モードならtrue - */ - public boolean isXml2VmdMode(){ - return this.xml2vmd; - } - - /** - * ヘルプモードか否か判定を返す。 - * @return ヘルプモードならtrue - */ - public boolean isHelpMode(){ - return this.helpMode; - } - - /** - * クォータニオン出力モードか否か判定を返す。 - * @return クォータニオン出力モードならtrue - */ - public boolean isQuaternionMode(){ - return this.quaternionMode; - } - - /** - * コマンドライン解析中にエラーが検出されたか判定する。 - * @return エラーが検出されればtrue - */ - public boolean hasOptionError(){ - return this.hasOptionError; - } - - /** - * コマンドライン解析中のエラーメッセージを返す。 - * @return エラーメッセージ。エラーが無ければnull - */ - public String getErrorMessage(){ - return this.errorMessage; - } - - /** - * オプション列挙子。 - */ - private static enum OptSwitch implements Iterable { - - HELP ("-h", "-help", "-?"), - VMD2XML ("-vmd2xml"), - XML2VMD ("-xml2vmd"), - FORCE ("-f"), - INPUTFILE ("-i"), - OUTPUTFILE ("-o"), - QUATERNION ("-quat"), - EULERYXZ ("-eyxz"), - ; - - private final Iterable optLines; - - /** - * コンストラクタ。 - * @param optLines オプション文字列候補群。 - */ - private OptSwitch(String... optLines){ - this.optLines = Arrays.asList(optLines); - return; - } - - /** - * 文字列候補群を返す。 - * @return 文字列候補群 - */ - @Override - public Iterator iterator(){ - return this.optLines.iterator(); - } - - /** - * 文字列に合致する列挙子を返す。 - * @param arg 文字列 - * @return 列挙子。見つからなければnull - */ - private static OptSwitch parse(String arg){ - for(OptSwitch opt : values()){ - for(String optLine : opt){ - if(optLine.equals(arg)) return opt; - } - } - return null; - } - - } - -} diff --git a/src/main/java/jp/sourceforge/mikutoga/vmd2xml/ValidationHandler.java b/src/main/java/jp/sourceforge/mikutoga/vmd2xml/ValidationHandler.java deleted file mode 100644 index 5174077..0000000 --- a/src/main/java/jp/sourceforge/mikutoga/vmd2xml/ValidationHandler.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * custom error-handler for validation - * - * License : The MIT License - * Copyright(c) 2011 MikuToga Partners - */ - -package jp.sourceforge.mikutoga.vmd2xml; - -import org.xml.sax.ErrorHandler; -import org.xml.sax.SAXException; -import org.xml.sax.SAXParseException; - -/** - * 妥当性検証用エラーハンドラ。 - *

XML SchemaによるXML文書検証を目的とするエラーハンドラ。 - */ -final class ValidationHandler implements ErrorHandler { - - /** - * 唯一のシングルトン。 - */ - static final ErrorHandler HANDLER = new ValidationHandler(); - - /** - * 隠しコンストラクタ。 - */ - private ValidationHandler(){ - super(); - return; - } - - /** - * {@inheritDoc} - * @param exception {@inheritDoc} - * @throws SAXException {@inheritDoc} - */ - @Override - public void error(SAXParseException exception) throws SAXException{ - throw exception; - } - - /** - * {@inheritDoc} - * @param exception {@inheritDoc} - * @throws SAXException {@inheritDoc} - */ - @Override - public void fatalError(SAXParseException exception) throws SAXException{ - throw exception; - } - - /** - * {@inheritDoc} - * @param exception {@inheritDoc} - * @throws SAXException {@inheritDoc} - */ - @Override - public void warning(SAXParseException exception) throws SAXException{ - throw exception; - } - -} diff --git a/src/main/java/jp/sourceforge/mikutoga/vmd2xml/Vmd2Xml.java b/src/main/java/jp/sourceforge/mikutoga/vmd2xml/Vmd2Xml.java deleted file mode 100644 index d8f3773..0000000 --- a/src/main/java/jp/sourceforge/mikutoga/vmd2xml/Vmd2Xml.java +++ /dev/null @@ -1,587 +0,0 @@ -/* - * vmd to xml converter main entry - * - * License : The MIT License - * Copyright(c) 2011 MikuToga Partners - */ - -package jp.sourceforge.mikutoga.vmd2xml; - -import java.io.BufferedInputStream; -import java.io.BufferedOutputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.PrintStream; -import java.nio.channels.FileChannel; -import java.text.MessageFormat; -import java.util.Properties; -import javax.xml.parsers.DocumentBuilder; -import jp.sfjp.mikutoga.bin.parser.MmdFormatException; -import jp.sourceforge.mikutoga.vmd.IllegalVmdDataException; -import jp.sourceforge.mikutoga.vmd.model.VmdMotion; -import jp.sourceforge.mikutoga.vmd.model.binio.VmdExporter; -import jp.sourceforge.mikutoga.vmd.model.binio.VmdLoader; -import jp.sourceforge.mikutoga.vmd.model.xml.VmdXmlExporter; -import jp.sourceforge.mikutoga.vmd.model.xml.VmdXmlResources; -import jp.sourceforge.mikutoga.vmd.model.xml.Xml2VmdLoader; -import jp.sourceforge.mikutoga.xml.TogaXmlException; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; -import org.xml.sax.SAXParseException; - - -/** - * VMDモーションファイルとXMLとの間で変換を行うアプリケーション。 - */ -public final class Vmd2Xml { - - private static final int EXIT_OK = 0; - private static final int EXIT_IOERR = 1; - private static final int EXIT_ENVERR = 4; - private static final int EXIT_OPTERR = 5; - private static final int EXIT_INTERR = 6; - private static final int EXIT_VMDERR = 7; - private static final int EXIT_XMLERR = 8; - - /** アプリ名。 */ - public static final String APPNAME; - /** バージョン識別子。 */ - public static final String APPVER; - /** ライセンス種別。 */ - public static final String APPLICENSE; - - private static final String APPURL; - - private static final Class THISCLASS; - - private static final String ERRMSG_TXTONLY = - "ERROR : {0}\n"; - private static final String ERRMSG_SAXPARSE = - "ERROR : {0}\nline={1}, columun={2}\n"; - - private static final PrintStream ERROUT = System.err; - - static{ - THISCLASS = Vmd2Xml.class; - InputStream ver = - THISCLASS.getResourceAsStream("resources/version.properties"); - Properties verProps = new Properties(); - try{ - try{ - verProps.load(ver); - }finally{ - ver.close(); - } - }catch(IOException e){ - throw new ExceptionInInitializerError(e); - } - - APPNAME = verProps.getProperty("app.name"); - APPVER = verProps.getProperty("app.version"); - APPLICENSE = verProps.getProperty("app.license"); - APPURL = verProps.getProperty("app.url"); - - new Vmd2Xml().hashCode(); - } - - - /** - * ダミーコンストラクタ。 - */ - private Vmd2Xml(){ - super(); - assert this.getClass().equals(THISCLASS); - return; - } - - - /** - * VMを終了させる。 - * @param code 終了コード - */ - private static void exit(int code){ - System.exit(code); - assert false; - throw new AssertionError(); - } - - /** - * 標準エラー出力に文字列出力を行う。 - * @param obj 文字列 - */ - @SuppressWarnings("PMD.SystemPrintln") - private static void errprint(Object obj){ - ERROUT.print(obj.toString()); - return; - } - - /** - * エラーを表示した後VMを終了させる。 - * @param code 終了コード - * @param text メッセージ - */ - private static void errExit(int code, CharSequence text){ - errprint("ERROR:\n"); - errprint(text); - exit(code); - return; - } - - /** - * 入出力エラー処理。 - * 例外を出力してVM終了する。 - * @param ex 例外 - */ - private static void ioError(IOException ex){ - errprint(ex); - errprint('\n'); - exit(EXIT_IOERR); - - return; - } - - /** - * XML構文エラー処理。 - * 例外を出力してVM終了する。 - * @param ex 例外 - */ - private static void xmlError(SAXException ex){ - if(ex instanceof SAXParseException){ - xmlError((SAXParseException)ex); - } - - String txt = ex.getLocalizedMessage(); - String message = MessageFormat.format(ERRMSG_TXTONLY, txt); - errprint(message); - - exit(EXIT_XMLERR); - - return; - } - - /** - * XML構文エラー処理。 - * 例外を出力してVM終了する。 - * @param ex 例外 - */ - private static void xmlError(SAXParseException ex){ - String txt = ex.getLocalizedMessage(); - int line = ex.getLineNumber(); - int col = ex.getColumnNumber(); - - String message = - MessageFormat.format(ERRMSG_SAXPARSE, txt, line, col); - errprint(message); - - exit(EXIT_XMLERR); - - return; - } - - /** - * XML構文エラー処理。 - * 例外を出力してVM終了する。 - * @param ex 例外 - */ - private static void xmlError(TogaXmlException ex){ - String txt = ex.getLocalizedMessage(); - String message = MessageFormat.format(ERRMSG_TXTONLY, txt); - errprint(message); - - exit(EXIT_XMLERR); - - return; - } - - /** - * VMDファイルフォーマットエラー処理。 - * 例外を出力してVM終了する。 - * @param ex 例外 - */ - private static void vmdError(MmdFormatException ex){ - errprint(ex); - errprint('\n'); - ex.printStackTrace(ERROUT); - exit(EXIT_VMDERR); - - return; - } - - /** - * 内部エラー処理。 - * 例外を出力してVM終了する。 - * @param ex 例外 - */ - private static void internalError(Throwable ex){ - errprint(ex); - errprint('\n'); - ex.printStackTrace(ERROUT); - exit(EXIT_INTERR); - - return; - } - - /** - * JREのバージョン判定を行う。 - * 不適切ならVMごと終了。 - */ - private static void checkJRE(){ - Package jrePackage = java.lang.Object.class.getPackage(); - if( ! jrePackage.isCompatibleWith("1.6")){ - errExit(EXIT_ENVERR, "You need JRE 1.6 or later.\n"); - } - return; - } - - /** - * ヘルプメッセージを出力する。 - */ - private static void putHelp(){ - StringBuilder text = new StringBuilder(); - - text.append(APPNAME).append(' ').append(APPVER).append('\n'); - text.append(" License : ").append(APPLICENSE).append('\n'); - text.append(" ").append(APPURL).append('\n'); - text.append('\n'); - text.append(ArgInfo.CMD_HELP); - - errprint(text); - - return; - } - - /** - * ファイルサイズを0に切り詰める。 - * @param file ファイル - * @throws IOException 入出力エラー - */ - private static void trunc(File file) throws IOException{ - if( ! file.exists() ) return; - if( ! file.isFile() ) return; - - if(file.length() <= 0L) return; - - FileOutputStream foStream = new FileOutputStream(file); - try{ - FileChannel channnel = foStream.getChannel(); - try{ - channnel.truncate(0L); - }finally{ - channnel.close(); - } - }finally{ - foStream.close(); - } - - return; - } - - /** - * 入力ストリームを得る。 - * @param fileName 入力ファイル名 - * @return 入力ストリーム - * @throws FileNotFoundException 入力ファイルが見つからない。 - */ - private static InputStream openInputStream(String fileName) - throws FileNotFoundException { - File file = new File(fileName); - InputStream result = new FileInputStream(file); - result = new BufferedInputStream(result); - return result; - } - - /** - * 出力ストリームを得る。 - * @param fileName 出力ファイル名 - * @return 出力ストリーム - * @throws FileNotFoundException 出力ファイルが見つからない - * @throws IOException 出力エラー - */ - private static OutputStream openTruncatedOutputStream(String fileName) - throws FileNotFoundException, IOException { - File file = new File(fileName); - trunc(file); - OutputStream result = new FileOutputStream(file, false); - result = new BufferedOutputStream(result); - return result; - } - - /** - * Mainエントリ。 - * @param args コマンドパラメータ - */ - public static void main(String[] args){ - checkJRE(); - - ArgInfo argInfo = ArgInfo.buildArgInfo(args); - if(argInfo.hasOptionError()){ - String message = argInfo.getErrorMessage() + "\n" - + "(-h for help)\n"; - errExit(EXIT_OPTERR, message); - } - - if(argInfo.isHelpMode()){ - putHelp(); - exit(EXIT_OK); - } - - checkFiles(argInfo); - - String input = argInfo.getInputFile(); - String output = argInfo.getOutputFile(); - - InputStream is = null; - OutputStream os = null; - try{ - is = openInputStream(input); - os = openTruncatedOutputStream(output); - }catch(FileNotFoundException e){ - ioError(e); - }catch(IOException e){ - ioError(e); - } - - if(argInfo.isVmd2XmlMode()) vmd2xml(is, os, argInfo); - else xml2vmd(is, os); - - exit(EXIT_OK); - - return; - } - - /** - * 既に存在する通常ファイルか否か判定する。 - * @param file 判定対象 - * @return 既に存在する通常ファイルならtrue - */ - private static boolean isExistsNormalFile(File file){ - if( ! file.exists() ) return false; - if( ! file.isFile() ) return false; - return true; - } - - /** - * 既に存在する特殊ファイルか否か判定する。 - * @param file 判定対象 - * @return 既に存在する特殊ファイルならtrue - */ - private static boolean isExistsUnnormalFile(File file){ - if( ! file.exists() ) return false; - if( file.isFile() ) return false; - return true; - } - - /** - * ファイルの各種状態を事前にチェックする。 - * @param argInfo コマンドライン引数 - */ - private static void checkFiles(ArgInfo argInfo){ - String input = argInfo.getInputFile(); - String output = argInfo.getOutputFile(); - File iFile = new File(input); - File oFile = new File(output); - - if( ! isExistsNormalFile(iFile) ){ - errExit(EXIT_IOERR, "Can't find input file:" - + iFile.getAbsolutePath() + '\n'); - } - - if(argInfo.isForceMode()){ - if(isExistsUnnormalFile(oFile)){ - errExit(EXIT_IOERR, oFile.getAbsolutePath() - + " is not file.\n"); - } - }else if(oFile.exists()){ - errExit(EXIT_IOERR, oFile.getAbsolutePath() - + " already exists.\n" - + "If you want to overwrite, use -f.\n"); - } - - return; - } - - /** - * VMD->XML変換を行う。 - * @param istream 入力ストリーム - * @param ostream 出力ストリーム - * @param argInfo オプション設定 - */ - private static void vmd2xml(InputStream istream, OutputStream ostream, - ArgInfo argInfo ){ - try{ - vmd2xmlImpl(istream, ostream, argInfo); - }catch(IOException e){ - ioError(e); - }catch(MmdFormatException e){ - vmdError(e); - }catch(IllegalVmdDataException e){ - internalError(e); - } - - return; - } - - /** - * VMD->XML変換を行う。 - * @param istream 入力ストリーム - * @param ostream 出力ストリーム - * @param argInfo オプション設定 - * @throws IOException 入出力エラー - * @throws MmdFormatException 不正なVMDファイル - * @throws IllegalVmdDataException 不正なモーションデータ - */ - private static void vmd2xmlImpl(InputStream istream, OutputStream ostream, - ArgInfo argInfo ) - throws IOException, MmdFormatException, IllegalVmdDataException{ - VmdMotion motion; - try{ - motion = vmdRead(istream); - }finally{ - istream.close(); - } - - motion.frameSort(); - - try{ - xmlOut(motion, ostream, argInfo); - }finally{ - ostream.close(); - } - - return; - } - - /** - * XML->VMD変換を行う。 - * @param istream 入力ストリーム - * @param ostream 出力ストリーム - */ - private static void xml2vmd(InputStream istream, OutputStream ostream){ - try{ - xml2vmdImpl(istream, ostream); - }catch(IOException e){ - ioError(e); - }catch(SAXException e){ - xmlError(e); - }catch(TogaXmlException e){ - xmlError(e); - }catch(IllegalVmdDataException e){ - internalError(e); - } - - return; - } - - /** - * XML->VMD変換を行う。 - * @param istream 入力ストリーム - * @param ostream 出力ストリーム - * @throws IOException 入出力エラー - * @throws SAXException 不正なXMLファイル - * @throws TogaXmlException 不正なXMLファイル - * @throws IllegalVmdDataException 不正なVMDモーションデータ - */ - private static void xml2vmdImpl(InputStream istream, OutputStream ostream) - throws IOException, - SAXException, - TogaXmlException, - IllegalVmdDataException { - InputSource source = new InputSource(istream); - VmdMotion motion; - try{ - motion = xmlRead(source); - }finally{ - istream.close(); - } - - motion.frameSort(); - - try{ - vmdOut(motion, ostream); - }finally{ - ostream.close(); - } - - return; - } - - /** - * VMDファイルからモーションデータを読み込む。 - * @param is 入力ストリーム - * @return モーションデータ - * @throws IOException 入力エラー - * @throws MmdFormatException 不正なVMDファイルフォーマット - */ - private static VmdMotion vmdRead(InputStream is) - throws IOException, MmdFormatException{ - VmdMotion vmdMotion = VmdLoader.load(is); - return vmdMotion; - } - - /** - * モーションデータをXMLファイルに出力する。 - * @param motion モーションデータ - * @param ostream 出力ストリーム - * @param argInfo オプション設定 - * @throws IOException 出力エラー - * @throws IllegalVmdDataException 不正なモーションデータ - */ - private static void xmlOut(VmdMotion motion, OutputStream ostream, - ArgInfo argInfo) - throws IOException, IllegalVmdDataException{ - VmdXmlExporter exporter = new VmdXmlExporter(ostream); - - exporter.setNewLine("\r\n"); - exporter.setGenerator(APPNAME + ' ' + APPVER); - - boolean isQuaternionMode = argInfo.isQuaternionMode(); - exporter.setQuaternionMode(isQuaternionMode); - - exporter.putVmdXml(motion); - exporter.close(); - - return; - } - - /** - * XMLファイルからモーションデータを読み込む。 - * @param source 入力ソース - * @return モーションデータ - * @throws IOException 入力エラー - * @throws SAXException XML構文エラー - * @throws TogaXmlException 不正なXMLデータ - */ - private static VmdMotion xmlRead(InputSource source) - throws IOException, - SAXException, - TogaXmlException { - DocumentBuilder builder = - VmdXmlResources.newBuilder(ValidationHandler.HANDLER); - Xml2VmdLoader loader = new Xml2VmdLoader(builder); - - VmdMotion motion = loader.parse(source); - - return motion; - } - - /** - * モーションデータをVMDファイルに出力する。 - * @param motion モーションデータ - * @param ostream 出力ストリーム - * @throws IOException 出力エラー - * @throws IllegalVmdDataException 不正なモーションデータ - */ - private static void vmdOut(VmdMotion motion, OutputStream ostream) - throws IOException, IllegalVmdDataException{ - VmdExporter exporter = new VmdExporter(ostream); - exporter.dumpVmdMotion(motion); - ostream.close(); - return; - } - -} diff --git a/src/main/java/jp/sourceforge/mikutoga/vmd2xml/package-info.java b/src/main/java/jp/sourceforge/mikutoga/vmd2xml/package-info.java deleted file mode 100644 index 0029933..0000000 --- a/src/main/java/jp/sourceforge/mikutoga/vmd2xml/package-info.java +++ /dev/null @@ -1,14 +0,0 @@ -/* - * package information for Javadoc - * - * License : The MIT License - * Copyright(c) 2011 MikuToga Partners - */ - -/** - * VMD-XML変換ユーティリティ、およびそのmainエントリ。 - */ - -package jp.sourceforge.mikutoga.vmd2xml; - -/* EOF */ diff --git a/src/main/resources/jp/sourceforge/mikutoga/vmd2xml/resources/version.properties b/src/main/resources/jp/sfjp/mikutoga/vmd2xml/resources/version.properties similarity index 100% rename from src/main/resources/jp/sourceforge/mikutoga/vmd2xml/resources/version.properties rename to src/main/resources/jp/sfjp/mikutoga/vmd2xml/resources/version.properties diff --git a/src/test/java/jp/sfjp/mikutoga/vmd/model/BezierParamTest.java b/src/test/java/jp/sfjp/mikutoga/vmd/model/BezierParamTest.java new file mode 100644 index 0000000..478885f --- /dev/null +++ b/src/test/java/jp/sfjp/mikutoga/vmd/model/BezierParamTest.java @@ -0,0 +1,225 @@ +/* + */ + +package jp.sfjp.mikutoga.vmd.model; + +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import static org.junit.Assert.*; + +/** + * + */ +public class BezierParamTest { + + public BezierParamTest() { + } + + @BeforeClass + public static void setUpClass() { + } + + @AfterClass + public static void tearDownClass() { + } + + @Before + public void setUp() { + } + + @After + public void tearDown() { + } + + /** + * Test of setP2 method, of class BezierParam. + */ + @Test + public void testSetP() { + System.out.println("getsetP"); + + BezierParam bez; + + bez = new BezierParam(); + assertEquals(20, bez.getP1x()); + assertEquals(20, bez.getP1y()); + assertEquals(107, bez.getP2x()); + assertEquals(107, bez.getP2y()); + + bez.setP1x((byte)21); + assertEquals(21, bez.getP1x()); + assertEquals(20, bez.getP1y()); + assertEquals(107, bez.getP2x()); + assertEquals(107, bez.getP2y()); + + bez.setP1y((byte)22); + assertEquals(21, bez.getP1x()); + assertEquals(22, bez.getP1y()); + assertEquals(107, bez.getP2x()); + assertEquals(107, bez.getP2y()); + + bez.setP2x((byte)108); + assertEquals(21, bez.getP1x()); + assertEquals(22, bez.getP1y()); + assertEquals(108, bez.getP2x()); + assertEquals(107, bez.getP2y()); + + bez.setP2y((byte)109); + assertEquals(21, bez.getP1x()); + assertEquals(22, bez.getP1y()); + assertEquals(108, bez.getP2x()); + assertEquals(109, bez.getP2y()); + + bez.setP1((byte)23, (byte)24); + assertEquals(23, bez.getP1x()); + assertEquals(24, bez.getP1y()); + assertEquals(108, bez.getP2x()); + assertEquals(109, bez.getP2y()); + + bez.setP2((byte)110, (byte)111); + assertEquals(23, bez.getP1x()); + assertEquals(24, bez.getP1y()); + assertEquals(110, bez.getP2x()); + assertEquals(111, bez.getP2y()); + + return; + } + + /** + * Test of isLinear method, of class BezierParam. + */ + @Test + public void testIsLinear() { + System.out.println("isLinear"); + + BezierParam bez; + + bez = new BezierParam(); + assertTrue(bez.isLinear()); + + bez.setP1((byte)10, (byte)10); + assertTrue(bez.isLinear()); + + bez.setP2((byte)120, (byte)120); + assertTrue(bez.isLinear()); + + bez.setP1((byte)0, (byte)0); + assertTrue(bez.isLinear()); + + bez.setP2((byte)127, (byte)127); + assertTrue(bez.isLinear()); + + bez.setP1((byte)1, (byte)2); + assertFalse(bez.isLinear()); + + bez.setP1((byte)0, (byte)0); + bez.setP2((byte)126, (byte)127); + assertFalse(bez.isLinear()); + + return; + } + + /** + * Test of isDefaultLinear method, of class BezierParam. + */ + @Test + public void testIsDefaultLinear() { + System.out.println("isDefaultLinear"); + + BezierParam bez; + + bez = new BezierParam(); + assertTrue(bez.isDefaultLinear()); + assertTrue(bez.isLinear()); + + bez.setP1((byte)30, (byte)30); + assertFalse(bez.isDefaultLinear()); + assertTrue(bez.isLinear()); + + bez.setDefaultEaseInOut(); + assertFalse(bez.isDefaultLinear()); + + return; + } + + /** + * Test of isDefaultEaseInOut method, of class BezierParam. + */ + @Test + public void testIsDefaultEaseInOut() { + System.out.println("isDefaultEaseInOut"); + + BezierParam bez; + + bez = new BezierParam(); + assertFalse(bez.isDefaultEaseInOut()); + + bez.setDefaultEaseInOut(); + assertTrue(bez.isDefaultEaseInOut()); + + return; + } + + /** + * Test of setDefaultLinear method, of class BezierParam. + */ + @Test + public void testSetDefaultLinear() { + System.out.println("setDefaultLinear"); + + BezierParam bez; + + bez = new BezierParam(); + bez.setDefaultLinear(); + assertEquals(20, bez.getP1x()); + assertEquals(20, bez.getP1y()); + assertEquals(107, bez.getP2x()); + assertEquals(107, bez.getP2y()); + + return; + } + + /** + * Test of setDefaultEaseInOut method, of class BezierParam. + */ + @Test + public void testSetDefaultEaseInOut() { + System.out.println("setDefaultEaseInOut"); + + BezierParam bez; + + bez = new BezierParam(); + bez.setDefaultEaseInOut(); + assertEquals(64, bez.getP1x()); + assertEquals(0, bez.getP1y()); + assertEquals(64, bez.getP2x()); + assertEquals(127, bez.getP2y()); + + return; + } + + /** + * Test of toString method, of class BezierParam. + */ + @Test + public void testToString() { + System.out.println("toString"); + + BezierParam bez; + + bez = new BezierParam(); + assertEquals("P1=(20, 20) P2=(107, 107)", bez.toString()); + + bez.setP1((byte)0, (byte)0); + assertEquals("P1=(0, 0) P2=(107, 107)", bez.toString()); + + bez.setP2((byte)127, (byte)127); + assertEquals("P1=(0, 0) P2=(127, 127)", bez.toString()); + + return; + } + +} diff --git a/src/test/java/jp/sfjp/mikutoga/vmd/model/BoneMotionTest.java b/src/test/java/jp/sfjp/mikutoga/vmd/model/BoneMotionTest.java new file mode 100644 index 0000000..8ff1d03 --- /dev/null +++ b/src/test/java/jp/sfjp/mikutoga/vmd/model/BoneMotionTest.java @@ -0,0 +1,204 @@ +/* + */ + +package jp.sfjp.mikutoga.vmd.model; + +import jp.sfjp.mikutoga.math.MkPos3D; +import jp.sfjp.mikutoga.math.MkQuat; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import static org.junit.Assert.*; + +/** + * + */ +public class BoneMotionTest { + + public BoneMotionTest() { + } + + @BeforeClass + public static void setUpClass() { + } + + @AfterClass + public static void tearDownClass() { + } + + @Before + public void setUp() { + } + + @After + public void tearDown() { + } + + /** + * Test of get/setBoneName method, of class BoneMotion. + */ + @Test + public void testGetSetBoneName() { + System.out.println("getBoneName"); + + BoneMotion motion; + + motion = new BoneMotion(); + assertNull(motion.getBoneName()); + + motion.setBoneName(""); + assertEquals("", motion.getBoneName()); + + motion.setBoneName("bbbone"); + assertEquals("bbbone", motion.getBoneName()); + + motion.setBoneName(null); + assertNull(motion.getBoneName()); + + return; + } + + /** + * Test of getRotation method, of class BoneMotion. + */ + @Test + public void testGetRotation() { + System.out.println("getRotation"); + + BoneMotion motion; + MkQuat rot; + + motion = new BoneMotion(); + + rot = motion.getRotation(); + assertNotNull(rot); + + return; + } + + /** + * Test of getIntpltRotation method, of class BoneMotion. + */ + @Test + public void testGetIntpltRotation() { + System.out.println("getIntpltRotation"); + + BoneMotion motion; + BezierParam bez; + + motion = new BoneMotion(); + + bez = motion.getIntpltRotation(); + assertNotNull(bez); + + return; + } + + /** + * Test of getPosition method, of class BoneMotion. + */ + @Test + public void testGetPosition() { + System.out.println("getPosition"); + + BoneMotion motion; + MkPos3D pos; + + motion = new BoneMotion(); + + pos = motion.getPosition(); + assertNotNull(pos); + + return; + } + + /** + * Test of getPosCurve method, of class BoneMotion. + */ + @Test + public void testGetPosCurve() { + System.out.println("getPosCurve"); + + BoneMotion motion; + PosCurve curve; + + motion = new BoneMotion(); + + curve = motion.getPosCurve(); + assertNotNull(curve); + + return; + } + + /** + * Test of hasImplicitPosition method, of class BoneMotion. + */ + @Test + public void testHasImplicitPosition() { + System.out.println("hasImplicitPosition"); + + BoneMotion motion; + + motion = new BoneMotion(); + assertTrue(motion.hasImplicitPosition()); + + motion = new BoneMotion(); + motion.getPosition().setXpos(1.0); + assertFalse(motion.hasImplicitPosition()); + + motion = new BoneMotion(); + motion.getPosCurve().getIntpltYpos().setP1((byte)21, (byte)21); + assertFalse(motion.hasImplicitPosition()); + + return; + } + + /** + * Test of toString method, of class BoneMotion. + */ + @Test + public void testToString() { + System.out.println("toString"); + + BoneMotion motion; + + motion = new BoneMotion(); + assertEquals( + "bone name : [null] #0\n" + + "rotation q1=0.0 q2=0.0 q3=0.0 w=1.0" + + " R-Bezier P1=(20, 20) P2=(107, 107)\n" + + "position x=0.0 y=0.0 z=0.0\n" + + "X-Bezier P1=(20, 20) P2=(107, 107)\n" + + "Y-Bezier P1=(20, 20) P2=(107, 107)\n" + + "Z-Bezier P1=(20, 20) P2=(107, 107)" + , motion.toString() ); + + motion.setBoneName("bbbone"); + motion.setFrameNumber(99); + motion.getRotation().setQW(-1.0); + motion.getIntpltRotation().setP1((byte)1, (byte)2); + motion.getIntpltRotation().setP2((byte)3, (byte)4); + motion.getPosition().setPosition(1.0, 2.0, 3.0); + motion.getPosCurve().getIntpltXpos().setP1((byte)5, (byte)6); + motion.getPosCurve().getIntpltXpos().setP2((byte)7, (byte)8); + motion.getPosCurve().getIntpltYpos().setP1((byte)9, (byte)10); + motion.getPosCurve().getIntpltYpos().setP2((byte)11, (byte)12); + motion.getPosCurve().getIntpltZpos().setP1((byte)13, (byte)14); + motion.getPosCurve().getIntpltZpos().setP2((byte)15, (byte)16); + + assertEquals( + "bone name : [bbbone] #99\n" + + "rotation q1=0.0 q2=0.0 q3=0.0 w=-1.0" + + " R-Bezier P1=(1, 2) P2=(3, 4)\n" + + "position x=1.0 y=2.0 z=3.0\n" + + "X-Bezier P1=(5, 6) P2=(7, 8)\n" + + "Y-Bezier P1=(9, 10) P2=(11, 12)\n" + + "Z-Bezier P1=(13, 14) P2=(15, 16)" + , motion.toString() ); + + return; + } + +} diff --git a/src/test/java/jp/sfjp/mikutoga/vmd/model/CameraMotionTest.java b/src/test/java/jp/sfjp/mikutoga/vmd/model/CameraMotionTest.java new file mode 100644 index 0000000..7109f60 --- /dev/null +++ b/src/test/java/jp/sfjp/mikutoga/vmd/model/CameraMotionTest.java @@ -0,0 +1,226 @@ +/* + */ + +package jp.sfjp.mikutoga.vmd.model; + +import jp.sfjp.mikutoga.math.MkPos3D; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import static org.junit.Assert.*; + +/** + * + */ +public class CameraMotionTest { + + public CameraMotionTest() { + } + + @BeforeClass + public static void setUpClass() { + } + + @AfterClass + public static void tearDownClass() { + } + + @Before + public void setUp() { + } + + @After + public void tearDown() { + } + + /** + * Test of getCameraTarget method, of class CameraMotion. + */ + @Test + public void testGetCameraTarget() { + System.out.println("getCameraTarget"); + + CameraMotion motion; + + motion = new CameraMotion(); + + MkPos3D pos = motion.getCameraTarget(); + assertNotNull(pos); + + return; + } + + /** + * Test of getTargetPosCurve method, of class CameraMotion. + */ + @Test + public void testGetTargetPosCurve() { + System.out.println("getTargetPosCurve"); + + CameraMotion motion; + + motion = new CameraMotion(); + + PosCurve curve = motion.getTargetPosCurve(); + assertNotNull(curve); + + return; + } + + /** + * Test of getCameraRotation method, of class CameraMotion. + */ + @Test + public void testGetCameraRotation() { + System.out.println("getCameraRotation"); + + CameraMotion motion; + + motion = new CameraMotion(); + + CameraRotation rot = motion.getCameraRotation(); + assertNotNull(rot); + + return; + } + + /** + * Test of getIntpltRotation method, of class CameraMotion. + */ + @Test + public void testGetIntpltRotation() { + System.out.println("getIntpltRotation"); + + CameraMotion motion; + + motion = new CameraMotion(); + + BezierParam bez = motion.getIntpltRotation(); + assertNotNull(bez); + + return; + } + + /** + * Test of get/setRange method, of class CameraMotion. + */ + @Test + public void testGetSetRange() { + System.out.println("get/setRange"); + + CameraMotion motion; + + motion = new CameraMotion(); + + assertEquals(0.0, motion.getRange(), 0.0); + + motion.setRange(-35.0); + assertEquals(-35.0, motion.getRange(), 0.0); + + return; + } + + /** + * Test of getIntpltRange method, of class CameraMotion. + */ + @Test + public void testGetIntpltRange() { + System.out.println("getIntpltRange"); + + CameraMotion motion; + + motion = new CameraMotion(); + + BezierParam bez = motion.getIntpltRange(); + assertNotNull(bez); + + return; + } + + /** + * Test of has/setPerspective method, of class CameraMotion. + */ + @Test + public void testHasSetPerspective() { + System.out.println("has/setPerspective"); + + CameraMotion motion; + + motion = new CameraMotion(); + assertFalse(motion.hasPerspective()); + + motion.setPerspectiveMode(true); + assertTrue(motion.hasPerspective()); + + motion.setPerspectiveMode(false); + assertFalse(motion.hasPerspective()); + + return; + } + + /** + * Test of get/set ProjectionAngle method, of class CameraMotion. + */ + @Test + public void testGetSetProjectionAngle() { + System.out.println("get/setProjectionAngle"); + + CameraMotion motion; + int angle; + + motion = new CameraMotion(); + + angle = motion.getProjectionAngle(); + assertEquals(0, angle); + + motion.setProjectionAngle(25); + angle = motion.getProjectionAngle(); + assertEquals(25, angle); + + return; + } + + /** + * Test of getIntpltProjection method, of class CameraMotion. + */ + @Test + public void testGetIntpltProjection() { + System.out.println("getIntpltProjection"); + + CameraMotion motion; + + motion = new CameraMotion(); + BezierParam bez = motion.getIntpltProjection(); + assertNotNull(bez); + + return; + } + + /** + * Test of toString method, of class CameraMotion. + */ + @Test + public void testToString() { + System.out.println("toString"); + + CameraMotion motion; + + motion = new CameraMotion(); + + assertEquals( + "#0 latitude=0 longitude=0 roll=0 Rot-Bezier P1=(20, 20) P2=(107, 107)\n" + + "range : 0 Range-Bezier P1=(20, 20) P2=(107, 107)\n" + + "target-pos : x=0.0 y=0.0 z=0.0\n" + + "X-Bezier P1=(20, 20) P2=(107, 107)\n" + + "Y-Bezier P1=(20, 20) P2=(107, 107)\n" + + "Z-Bezier P1=(20, 20) P2=(107, 107)\n" + +"perspective : false\n" + +"projection angle : 0deg Bezier P1=(20, 20) P2=(107, 107)", + motion.toString() ); + + return; + } + +} diff --git a/src/test/java/jp/sfjp/mikutoga/vmd/model/CameraRotationTest.java b/src/test/java/jp/sfjp/mikutoga/vmd/model/CameraRotationTest.java new file mode 100644 index 0000000..1dde8bc --- /dev/null +++ b/src/test/java/jp/sfjp/mikutoga/vmd/model/CameraRotationTest.java @@ -0,0 +1,84 @@ +/* + */ + +package jp.sfjp.mikutoga.vmd.model; + +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import static org.junit.Assert.*; + +/** + * + */ +public class CameraRotationTest { + + public CameraRotationTest() { + } + + @BeforeClass + public static void setUpClass() { + } + + @AfterClass + public static void tearDownClass() { + } + + @Before + public void setUp() { + } + + @After + public void tearDown() { + } + + /** + * Test of get/set method, of class CameraRotation. + */ + @Test + public void testGetSetParams() { + System.out.println("getLatitude"); + + CameraRotation rotation; + + rotation = new CameraRotation(); + + assertEquals(0.0, rotation.getLatitude(), 0.0); + assertEquals(0.0, rotation.getLongitude(), 0.0); + assertEquals(0.0, rotation.getRoll(), 0.0); + + rotation.setLatitude(1.0); + rotation.setLongitude(2.0); + rotation.setRoll(3.0); + + assertEquals(1.0, rotation.getLatitude(), 0.0); + assertEquals(2.0, rotation.getLongitude(), 0.0); + assertEquals(3.0, rotation.getRoll(), 0.0); + + return; + } + + /** + * Test of toString method, of class CameraRotation. + */ + @Test + public void testToString() { + System.out.println("toString"); + + CameraRotation rotation; + + rotation = new CameraRotation(); + + assertEquals("latitude=0 longitude=0 roll=0", rotation.toString()); + + rotation.setLatitude(1.1f); + rotation.setLongitude(2.2f); + rotation.setRoll(3.3f); + assertEquals("latitude=1.1 longitude=2.2 roll=3.3", rotation.toString()); + + return; + } + +} diff --git a/src/test/java/jp/sfjp/mikutoga/vmd/model/LuminousColorTest.java b/src/test/java/jp/sfjp/mikutoga/vmd/model/LuminousColorTest.java new file mode 100644 index 0000000..1778153 --- /dev/null +++ b/src/test/java/jp/sfjp/mikutoga/vmd/model/LuminousColorTest.java @@ -0,0 +1,80 @@ +/* + */ + +package jp.sfjp.mikutoga.vmd.model; + +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import static org.junit.Assert.*; + +/** + * + */ +public class LuminousColorTest { + + public LuminousColorTest() { + } + + @BeforeClass + public static void setUpClass() { + } + + @AfterClass + public static void tearDownClass() { + } + + @Before + public void setUp() { + } + + @After + public void tearDown() { + } + + /** + * Test of get/setCol method, of class LuminousColor. + */ + @Test + public void testGetSetCol() { + System.out.println("get/setCol"); + + LuminousColor color; + + color = new LuminousColor(); + + assertEquals(0.602f, color.getColR(), 0.0f); + assertEquals(0.602f, color.getColG(), 0.0f); + assertEquals(0.602f, color.getColB(), 0.0f); + + color.setColR(0.5f); + assertEquals(0.5f, color.getColR(), 0.0f); + + color.setColG(0.5f); + assertEquals(0.5f, color.getColG(), 0.0f); + + color.setColB(0.5f); + assertEquals(0.5f, color.getColB(), 0.0f); + + return; + } + + /** + * Test of toString method, of class LuminousColor. + */ + @Test + public void testToString() { + System.out.println("toString"); + + LuminousColor color; + + color = new LuminousColor(); + + assertEquals("r=0.602 g=0.602 b=0.602", color.toString()); + + return; + } + +} diff --git a/src/test/java/jp/sfjp/mikutoga/vmd/model/LuminousMotionTest.java b/src/test/java/jp/sfjp/mikutoga/vmd/model/LuminousMotionTest.java new file mode 100644 index 0000000..a716148 --- /dev/null +++ b/src/test/java/jp/sfjp/mikutoga/vmd/model/LuminousMotionTest.java @@ -0,0 +1,97 @@ +/* + */ + +package jp.sfjp.mikutoga.vmd.model; + +import jp.sfjp.mikutoga.math.MkVec3D; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import static org.junit.Assert.*; + +/** + * + */ +public class LuminousMotionTest { + + public LuminousMotionTest() { + } + + @BeforeClass + public static void setUpClass() { + } + + @AfterClass + public static void tearDownClass() { + } + + @Before + public void setUp() { + } + + @After + public void tearDown() { + } + + /** + * Test of getColor method, of class LuminousMotion. + */ + @Test + public void testGetColor() { + System.out.println("getColor"); + + LuminousMotion motion; + + motion = new LuminousMotion(); + + LuminousColor color = motion.getColor(); + assertNotNull(color); + + assertEquals(0.602f, color.getColR(), 0.0f); + assertEquals(0.602f, color.getColG(), 0.0f); + assertEquals(0.602f, color.getColB(), 0.0f); + + return; + } + + /** + * Test of getDirection method, of class LuminousMotion. + */ + @Test + public void testGetDirection() { + System.out.println("getDirection"); + + LuminousMotion motion; + + motion = new LuminousMotion(); + + MkVec3D vec = motion.getDirection(); + assertNotNull(vec); + + assertEquals(-0.5, vec.getXVal(), 0.0); + assertEquals(-1.0, vec.getYVal(), 0.0); + assertEquals( 0.5, vec.getZVal(), 0.0); + + return; + } + + /** + * Test of toString method, of class LuminousMotion. + */ + @Test + public void testToString() { + System.out.println("toString"); + + LuminousMotion motion; + + motion = new LuminousMotion(); + + assertEquals("#0 luminous color : r=0.602 g=0.602 b=0.602 direction : vec=[-0.5, -1.0, 0.5]", + motion.toString()); + + return; + } + +} diff --git a/src/test/java/jp/sfjp/mikutoga/vmd/model/MorphMotionTest.java b/src/test/java/jp/sfjp/mikutoga/vmd/model/MorphMotionTest.java new file mode 100644 index 0000000..999f72e --- /dev/null +++ b/src/test/java/jp/sfjp/mikutoga/vmd/model/MorphMotionTest.java @@ -0,0 +1,95 @@ +/* + */ + +package jp.sfjp.mikutoga.vmd.model; + +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import static org.junit.Assert.*; + +/** + * + */ +public class MorphMotionTest { + + public MorphMotionTest() { + } + + @BeforeClass + public static void setUpClass() { + } + + @AfterClass + public static void tearDownClass() { + } + + @Before + public void setUp() { + } + + @After + public void tearDown() { + } + + /** + * Test of get/setMorphName method, of class MorphMotion. + */ + @Test + public void testGetSetMorphName() { + System.out.println("get/setMorphName"); + + MorphMotion motion; + + motion = new MorphMotion(); + assertEquals("", motion.getMorphName()); + + motion.setMorphName("mmmorph"); + assertEquals("mmmorph", motion.getMorphName()); + + return; + } + + /** + * Test of get/setFlex method, of class MorphMotion. + */ + @Test + public void testGetSetFlex() { + System.out.println("get/setFlex"); + + MorphMotion motion; + + motion = new MorphMotion(); + assertEquals(0.0f, motion.getFlex(), 0.0f); + + motion.setFlex(0.5f); + assertEquals(0.5f, motion.getFlex(), 0.0f); + + return; + } + + /** + * Test of toString method, of class MorphMotion. + */ + @Test + public void testToString() { + System.out.println("toString"); + + MorphMotion motion; + + motion = new MorphMotion(); + + assertEquals("morph name : [] #0 flex = 0", motion.toString()); + + motion.setMorphName("mmmorph"); + motion.setFrameNumber(99); + motion.setFlex(0.5f); + assertEquals("morph name : [mmmorph] #99 flex = 0.5", motion.toString()); + + + return; + } + +} diff --git a/src/test/java/jp/sfjp/mikutoga/vmd/model/PosCurveTest.java b/src/test/java/jp/sfjp/mikutoga/vmd/model/PosCurveTest.java new file mode 100644 index 0000000..2ac9914 --- /dev/null +++ b/src/test/java/jp/sfjp/mikutoga/vmd/model/PosCurveTest.java @@ -0,0 +1,155 @@ +/* + */ + +package jp.sfjp.mikutoga.vmd.model; + +import java.util.Iterator; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import static org.junit.Assert.*; + +/** + * + */ +public class PosCurveTest { + + public PosCurveTest() { + } + + @BeforeClass + public static void setUpClass() { + } + + @AfterClass + public static void tearDownClass() { + } + + @Before + public void setUp() { + } + + @After + public void tearDown() { + } + + /** + * Test of getIntplt method, of class PosCurve. + */ + @Test + public void testGetIntplt() { + System.out.println("getIntpltZpos"); + + PosCurve curve; + + curve = new PosCurve(); + + BezierParam xbz = curve.getIntpltXpos(); + BezierParam ybz = curve.getIntpltYpos(); + BezierParam zbz = curve.getIntpltZpos(); + + assertNotNull(xbz); + assertNotNull(ybz); + assertNotNull(zbz); + + assertNotSame(xbz, ybz); + assertNotSame(ybz, zbz); + assertNotSame(zbz, xbz); + + return; + } + + /** + * Test of isDefaultLinear method, of class PosCurve. + */ + @Test + public void testIsDefaultLinear() { + System.out.println("isDefaultLinear"); + + PosCurve curve; + + curve = new PosCurve(); + assertTrue(curve.isDefaultLinear()); + + curve = new PosCurve(); + curve.getIntpltXpos().setP1((byte)21, (byte)21); + assertFalse(curve.isDefaultLinear()); + curve.getIntpltXpos().setP1((byte)20, (byte)20); + assertTrue(curve.isDefaultLinear()); + + curve = new PosCurve(); + curve.getIntpltYpos().setP1((byte)21, (byte)21); + assertFalse(curve.isDefaultLinear()); + curve.getIntpltYpos().setP1((byte)20, (byte)20); + assertTrue(curve.isDefaultLinear()); + + curve = new PosCurve(); + curve.getIntpltZpos().setP1((byte)21, (byte)21); + assertFalse(curve.isDefaultLinear()); + curve.getIntpltZpos().setP1((byte)20, (byte)20); + assertTrue(curve.isDefaultLinear()); + + return; + } + + /** + * Test of toString method, of class PosCurve. + */ + @Test + public void testToString() { + System.out.println("toString"); + + PosCurve curve; + + curve = new PosCurve(); + assertEquals( + "X-Bezier P1=(20, 20) P2=(107, 107)\n" + + "Y-Bezier P1=(20, 20) P2=(107, 107)\n" + + "Z-Bezier P1=(20, 20) P2=(107, 107)", + curve.toString() ); + + curve.getIntpltXpos().setP1x((byte)1); + curve.getIntpltYpos().setP1x((byte)2); + curve.getIntpltZpos().setP1x((byte)3); + assertEquals( + "X-Bezier P1=(1, 20) P2=(107, 107)\n" + + "Y-Bezier P1=(2, 20) P2=(107, 107)\n" + + "Z-Bezier P1=(3, 20) P2=(107, 107)", + curve.toString() ); + + return; + } + + /** + * Test of iterator method, of class PosCurve. + */ + @Test + public void testIterator() { + System.out.println("iterator"); + PosCurve curve; + + curve = new PosCurve(); + + Iterator it = curve.iterator(); + + assertTrue(it.hasNext()); + BezierParam bz1 = it.next(); + + assertTrue(it.hasNext()); + BezierParam bz2 = it.next(); + + assertTrue(it.hasNext()); + BezierParam bz3 = it.next(); + + assertFalse(it.hasNext()); + + assertSame(curve.getIntpltXpos(), bz1); + assertSame(curve.getIntpltYpos(), bz2); + assertSame(curve.getIntpltZpos(), bz3); + + return; + } + +} diff --git a/src/test/java/jp/sfjp/mikutoga/vmd/model/ShadowModeTest.java b/src/test/java/jp/sfjp/mikutoga/vmd/model/ShadowModeTest.java new file mode 100644 index 0000000..d2512cf --- /dev/null +++ b/src/test/java/jp/sfjp/mikutoga/vmd/model/ShadowModeTest.java @@ -0,0 +1,116 @@ +/* + */ + +package jp.sfjp.mikutoga.vmd.model; + +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import static org.junit.Assert.*; + +/** + * + */ +public class ShadowModeTest { + + public ShadowModeTest() { + } + + @BeforeClass + public static void setUpClass() { + } + + @AfterClass + public static void tearDownClass() { + } + + @Before + public void setUp() { + } + + @After + public void tearDown() { + } + + /** + * Test of values method, of class ShadowMode. + */ + @Test + public void testValues() { + System.out.println("values"); + + ShadowMode[] result = ShadowMode.values(); + assertEquals(3, result.length); + + assertSame(ShadowMode.NONE, result[0]); + assertSame(ShadowMode.MODE_1, result[1]); + assertSame(ShadowMode.MODE_2, result[2]); + + return; + } + + /** + * Test of valueOf method, of class ShadowMode. + */ + @Test + public void testValueOf() { + System.out.println("valueOf"); + + assertSame(ShadowMode.NONE, ShadowMode.valueOf("NONE")); + assertSame(ShadowMode.MODE_1, ShadowMode.valueOf("MODE_1")); + assertSame(ShadowMode.MODE_2, ShadowMode.valueOf("MODE_2")); + + return; + } + + /** + * Test of getEncodedByte method, of class ShadowMode. + */ + @Test + public void testGetEncodedByte() { + System.out.println("getEncodedByte"); + + assertEquals((byte)0x00, ShadowMode.NONE.getEncodedByte()); + assertEquals((byte)0x01, ShadowMode.MODE_1.getEncodedByte()); + assertEquals((byte)0x02, ShadowMode.MODE_2.getEncodedByte()); + + return; + } + + /** + * Test of decode method, of class ShadowMode. + */ + @Test + public void testDecode_byte() { + System.out.println("decode"); + + assertSame(ShadowMode.NONE, ShadowMode.decode((byte)0x00)); + assertSame(ShadowMode.MODE_1, ShadowMode.decode((byte)0x01)); + assertSame(ShadowMode.MODE_2, ShadowMode.decode((byte)0x02)); + + assertNull(ShadowMode.decode((byte)-1)); + assertNull(ShadowMode.decode((byte)0x03)); + + return; + } + + /** + * Test of decode method, of class ShadowMode. + */ + @Test + public void testDecode_int() { + System.out.println("decode"); + + assertSame(ShadowMode.NONE, ShadowMode.decode(0x00)); + assertSame(ShadowMode.MODE_1, ShadowMode.decode(0x01)); + assertSame(ShadowMode.MODE_2, ShadowMode.decode(0x02)); + + assertNull(ShadowMode.decode(-1)); + assertNull(ShadowMode.decode(0x03)); + + return; + } + +} diff --git a/src/test/java/jp/sfjp/mikutoga/vmd/model/ShadowMotionTest.java b/src/test/java/jp/sfjp/mikutoga/vmd/model/ShadowMotionTest.java new file mode 100644 index 0000000..bf09e2b --- /dev/null +++ b/src/test/java/jp/sfjp/mikutoga/vmd/model/ShadowMotionTest.java @@ -0,0 +1,138 @@ +/* + */ + +package jp.sfjp.mikutoga.vmd.model; + +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import static org.junit.Assert.*; + +/** + * + */ +public strictfp class ShadowMotionTest { + + public ShadowMotionTest() { + } + + @BeforeClass + public static void setUpClass() { + } + + @AfterClass + public static void tearDownClass() { + } + + @Before + public void setUp() { + } + + @After + public void tearDown() { + } + + /** + * Test of rawParamToScope method, of class ShadowMotion. + */ + @Test + public void testRawParamToScope() { + System.out.println("rawParamToScope"); + + assertEquals(10000.0, ShadowMotion.rawParamToScope(0.0), 0.0); + assertEquals(8875.0, ShadowMotion.rawParamToScope(0.01125), 1e-11); + + return; + } + + /** + * Test of scopeToRawParam method, of class ShadowMotion. + */ + @Test + public void testScopeToRawParam() { + System.out.println("scopeToRawParam"); + + assertEquals(0.1, ShadowMotion.scopeToRawParam(0.0), 0.0); + assertEquals(0.01125, ShadowMotion.scopeToRawParam(8875.0), 1e-16); + + return; + } + + /** + * Test of set/getRawScopeParam method, of class ShadowMotion. + */ + @Test + public void testSetGetRawScopeParam() { + System.out.println("set/getRawScopeParam"); + + ShadowMotion motion; + + motion = new ShadowMotion(); + assertEquals(0.01125, motion.getRawScopeParam(), 0.0); + + motion.setRawScopeParam(0.1); + assertEquals(0.1, motion.getRawScopeParam(), 0.0); + + return; + } + + /** + * Test of set/getScope method, of class ShadowMotion. + */ + @Test + public void testSetGetScope() { + System.out.println("set/getScope"); + + ShadowMotion motion; + + motion = new ShadowMotion(); + + assertEquals(8875.0, motion.getScope(), 1e-11); + + motion.setScope(10000.0); + assertEquals(10000.0, motion.getScope(), 0.0); + + return; + } + + /** + * Test of set/getShadowMode method, of class ShadowMotion. + */ + @Test + public void testSetGetShadowMode() { + System.out.println("set/getShadowMode"); + + ShadowMotion motion; + + motion = new ShadowMotion(); + + assertSame(ShadowMode.MODE_1, motion.getShadowMode()); + + motion.setShadowMode(ShadowMode.MODE_2); + assertSame(ShadowMode.MODE_2, motion.getShadowMode()); + + motion.setShadowMode(ShadowMode.NONE); + assertSame(ShadowMode.NONE, motion.getShadowMode()); + + return; + } + + /** + * Test of toString method, of class ShadowMotion. + */ + @Test + public void testToString() { + System.out.println("toString"); + + ShadowMotion motion; + + motion = new ShadowMotion(); + + assertEquals("#0 shadow mode : MODE_1 rawparam=0.01125", motion.toString()); + + return; + } + +} diff --git a/src/test/java/jp/sfjp/mikutoga/vmd/model/VmdMotionTest.java b/src/test/java/jp/sfjp/mikutoga/vmd/model/VmdMotionTest.java new file mode 100644 index 0000000..796bf90 --- /dev/null +++ b/src/test/java/jp/sfjp/mikutoga/vmd/model/VmdMotionTest.java @@ -0,0 +1,426 @@ +/* + */ + +package jp.sfjp.mikutoga.vmd.model; + +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import static org.junit.Assert.*; + +/** + * + */ +public class VmdMotionTest { + + public VmdMotionTest() { + } + + @BeforeClass + public static void setUpClass() { + } + + @AfterClass + public static void tearDownClass() { + } + + @Before + public void setUp() { + } + + @After + public void tearDown() { + } + + /** + * Test of getせtModelName method, of class VmdMotion. + */ + @Test + public void testGetSetModelName() { + System.out.println("get/setModelName"); + + VmdMotion motion; + + motion = new VmdMotion(); + + assertEquals("カメラ・照明", motion.getModelName()); + + motion.setModelName(""); + assertEquals("", motion.getModelName()); + + motion.setModelName("model"); + assertEquals("model", motion.getModelName()); + + try{ + motion.setModelName(null); + fail(); + }catch(NullPointerException e){ + // GOOD + } + + return; + } + + /** + * Test of isModelMotion method, of class VmdMotion. + */ + @Test + public void testIsModelMotion() { + System.out.println("isModelMotion"); + + VmdMotion motion; + + motion = new VmdMotion(); + + assertFalse(motion.isModelMotion()); + + motion.setModelName("model"); + assertTrue(motion.isModelMotion()); + + motion.setModelName("カメラ・照明"); + assertFalse(motion.isModelMotion()); + + return; + } + + /** + * Test of getBonePartMap method, of class VmdMotion. + */ + @Test + public void testGetBonePartMap() { + System.out.println("getBonePartMap"); + + VmdMotion motion; + Map> map; + + motion = new VmdMotion(); + + map = motion.getBonePartMap(); + assertNotNull(map); + assertTrue(map.isEmpty()); + + return; + } + + /** + * Test of getMorphPartMap method, of class VmdMotion. + */ + @Test + public void testGetMorphPartMap() { + System.out.println("getMorphPartMap"); + + VmdMotion motion; + Map> map; + + motion = new VmdMotion(); + + map = motion.getMorphPartMap(); + assertNotNull(map); + assertTrue(map.isEmpty()); + + return; + } + + /** + * Test of getCameraMotionList method, of class VmdMotion. + */ + @Test + public void testGetCameraMotionList() { + System.out.println("getCameraMotionList"); + + VmdMotion motion; + List list; + + motion = new VmdMotion(); + + list = motion.getCameraMotionList(); + assertNotNull(list); + assertTrue(list.isEmpty()); + + return; + } + + /** + * Test of getLuminousMotionList method, of class VmdMotion. + */ + @Test + public void testGetLuminousMotionList() { + System.out.println("getLuminousMotionList"); + + VmdMotion motion; + List list; + + motion = new VmdMotion(); + + list = motion.getLuminousMotionList(); + assertNotNull(list); + assertTrue(list.isEmpty()); + + return; + } + + /** + * Test of getShadowMotionList method, of class VmdMotion. + */ + @Test + public void testGetShadowMotionList() { + System.out.println("getShadowMotionList"); + + VmdMotion motion; + List list; + + motion = new VmdMotion(); + + list = motion.getShadowMotionList(); + assertNotNull(list); + assertTrue(list.isEmpty()); + + return; + } + + /** + * Test of addBoneMotion method, of class VmdMotion. + */ + @Test + public void testAddBoneMotion() { + System.out.println("addBoneMotion"); + + VmdMotion motion; + BoneMotion bone; + + motion = new VmdMotion(); + + bone = new BoneMotion(); + bone.setBoneName("X"); + bone.setFrameNumber(99); + motion.addBoneMotion(bone); + + bone = new BoneMotion(); + bone.setBoneName("Y"); + bone.setFrameNumber(9); + motion.addBoneMotion(bone); + + bone = new BoneMotion(); + bone.setBoneName("A"); + bone.setFrameNumber(10); + motion.addBoneMotion(bone); + + bone = new BoneMotion(); + bone.setBoneName("Y"); + bone.setFrameNumber(1); + motion.addBoneMotion(bone); + + Map> map = motion.getBonePartMap(); + + Set keySet = map.keySet(); + assertEquals(3, keySet.size()); + Iterator it; + it = keySet.iterator(); + assertEquals("X", it.next()); + assertEquals("Y", it.next()); + assertEquals("A", it.next()); + + assertEquals(1, map.get("X").size()); + assertEquals(2, map.get("Y").size()); + assertEquals(1, map.get("A").size()); + + assertEquals(99, map.get("X").get(0).getFrameNumber()); + assertEquals(9, map.get("Y").get(0).getFrameNumber()); + assertEquals(1, map.get("Y").get(1).getFrameNumber()); + assertEquals(10, map.get("A").get(0).getFrameNumber()); + + return; + } + + /** + * Test of addMorphMotion method, of class VmdMotion. + */ + @Test + public void testAddMorphMotion() { + System.out.println("addMorphMotion"); + + VmdMotion motion; + MorphMotion morph; + + motion = new VmdMotion(); + + morph = new MorphMotion(); + morph.setMorphName("X"); + morph.setFrameNumber(99); + motion.addMorphMotion(morph); + + morph = new MorphMotion(); + morph.setMorphName("Y"); + morph.setFrameNumber(9); + motion.addMorphMotion(morph); + + morph = new MorphMotion(); + morph.setMorphName("A"); + morph.setFrameNumber(10); + motion.addMorphMotion(morph); + + morph = new MorphMotion(); + morph.setMorphName("Y"); + morph.setFrameNumber(1); + motion.addMorphMotion(morph); + + Map> map = motion.getMorphPartMap(); + + Set keySet = map.keySet(); + assertEquals(3, keySet.size()); + Iterator it; + it = keySet.iterator(); + assertEquals("X", it.next()); + assertEquals("Y", it.next()); + assertEquals("A", it.next()); + + assertEquals(1, map.get("X").size()); + assertEquals(2, map.get("Y").size()); + assertEquals(1, map.get("A").size()); + + assertEquals(99, map.get("X").get(0).getFrameNumber()); + assertEquals(9, map.get("Y").get(0).getFrameNumber()); + assertEquals(1, map.get("Y").get(1).getFrameNumber()); + assertEquals(10, map.get("A").get(0).getFrameNumber()); + + return; + } + + /** + * Test of frameSort method, of class VmdMotion. + */ + @Test + public void testFrameSort() { + System.out.println("frameSort"); + + VmdMotion motion; + + motion = new VmdMotion(); + + BoneMotion bmotion; + + bmotion = new BoneMotion(); + bmotion.setBoneName("bone"); + bmotion.setFrameNumber(2); + motion.addBoneMotion(bmotion); + + bmotion = new BoneMotion(); + bmotion.setBoneName("bone"); + bmotion.setFrameNumber(1); + motion.addBoneMotion(bmotion); + + MorphMotion mmotion; + + mmotion = new MorphMotion(); + mmotion.setMorphName("morph"); + mmotion.setFrameNumber(20); + motion.addMorphMotion(mmotion); + + mmotion = new MorphMotion(); + mmotion.setMorphName("morph"); + mmotion.setFrameNumber(10); + motion.addMorphMotion(mmotion); + + CameraMotion cmotion; + + cmotion = new CameraMotion(); + cmotion.setFrameNumber(200); + motion.getCameraMotionList().add(cmotion); + + cmotion = new CameraMotion(); + cmotion.setFrameNumber(100); + motion.getCameraMotionList().add(cmotion); + + LuminousMotion lmotion; + + lmotion = new LuminousMotion(); + lmotion.setFrameNumber(2000); + motion.getLuminousMotionList().add(lmotion); + + lmotion = new LuminousMotion(); + lmotion.setFrameNumber(1000); + motion.getLuminousMotionList().add(lmotion); + + ShadowMotion smotion; + + smotion = new ShadowMotion(); + smotion.setFrameNumber(20000); + motion.getShadowMotionList().add(smotion); + + smotion = new ShadowMotion(); + smotion.setFrameNumber(10000); + motion.getShadowMotionList().add(smotion); + + motion.frameSort(); + + assertEquals(2, motion.getBonePartMap().get("bone").size()); + assertEquals(1, motion.getBonePartMap().get("bone").get(0).getFrameNumber()); + assertEquals(2, motion.getBonePartMap().get("bone").get(1).getFrameNumber()); + + assertEquals(2, motion.getMorphPartMap().get("morph").size()); + assertEquals(10, motion.getMorphPartMap().get("morph").get(0).getFrameNumber()); + assertEquals(20, motion.getMorphPartMap().get("morph").get(1).getFrameNumber()); + + assertEquals(2, motion.getCameraMotionList().size()); + assertEquals(100, motion.getCameraMotionList().get(0).getFrameNumber()); + assertEquals(200, motion.getCameraMotionList().get(1).getFrameNumber()); + + assertEquals(2, motion.getLuminousMotionList().size()); + assertEquals(1000, motion.getLuminousMotionList().get(0).getFrameNumber()); + assertEquals(2000, motion.getLuminousMotionList().get(1).getFrameNumber()); + + assertEquals(2, motion.getShadowMotionList().size()); + assertEquals(10000, motion.getShadowMotionList().get(0).getFrameNumber()); + assertEquals(20000, motion.getShadowMotionList().get(1).getFrameNumber()); + + return; + } + + /** + * Test of toString method, of class VmdMotion. + */ + @Test + public void testToString() { + System.out.println("toString"); + + VmdMotion motion; + + motion = new VmdMotion(); + + assertEquals( + "model name : カメラ・照明\n" + +"bone#0 morph#0 camera#0 luminous#0 shadow#0", + motion.toString()); + + motion.setModelName("model"); + motion.addBoneMotion(new BoneMotion()); + motion.addMorphMotion(new MorphMotion()); + motion.addMorphMotion(new MorphMotion()); + motion.getCameraMotionList().add(new CameraMotion()); + motion.getCameraMotionList().add(new CameraMotion()); + motion.getCameraMotionList().add(new CameraMotion()); + motion.getLuminousMotionList().add(new LuminousMotion()); + motion.getLuminousMotionList().add(new LuminousMotion()); + motion.getLuminousMotionList().add(new LuminousMotion()); + motion.getLuminousMotionList().add(new LuminousMotion()); + motion.getShadowMotionList().add(new ShadowMotion()); + motion.getShadowMotionList().add(new ShadowMotion()); + motion.getShadowMotionList().add(new ShadowMotion()); + motion.getShadowMotionList().add(new ShadowMotion()); + motion.getShadowMotionList().add(new ShadowMotion()); + + assertEquals( + "model name : model\n" + +"bone#1 morph#2 camera#3 luminous#4 shadow#5", + motion.toString()); + + return; + } + +} diff --git a/src/test/java/testdata/CnvAssert.java b/src/test/java/testdata/CnvAssert.java index b215bbc..7d39f1a 100644 --- a/src/test/java/testdata/CnvAssert.java +++ b/src/test/java/testdata/CnvAssert.java @@ -11,8 +11,8 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import jp.sourceforge.mikutoga.vmd2xml.MotionFileType; -import jp.sourceforge.mikutoga.vmd2xml.Vmd2XmlConv; +import jp.sfjp.mikutoga.vmd2xml.MotionFileType; +import jp.sfjp.mikutoga.vmd2xml.Vmd2XmlConv; import static org.junit.Assert.*; diff --git a/src/test/java/testdata/vmd110820/morph/MorphTest.java b/src/test/java/testdata/vmd110820/morph/MorphTest.java new file mode 100644 index 0000000..3ced6b7 --- /dev/null +++ b/src/test/java/testdata/vmd110820/morph/MorphTest.java @@ -0,0 +1,56 @@ +/* + */ + +package testdata.vmd110820.morph; + +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +import static testdata.CnvAssert.*; + +/** + * + */ +public class MorphTest { + + static Class THISCLASS = MorphTest.class; + + public MorphTest() { + assert this.getClass() == THISCLASS; + return; + } + + @BeforeClass + public static void setUpClass() { + } + + @AfterClass + public static void tearDownClass() { + } + + @Before + public void setUp() { + } + + @After + public void tearDown() { + } + + @Test + public void vmd2xml() throws Exception{ + System.out.println("vmd2xml"); + assertVmd2Xml(THISCLASS, "morph.vmd", "morph.xml"); + return; + } + + @Test + public void xml2vmd() throws Exception{ + System.out.println("xml2vmd"); + assertXml2Vmd(THISCLASS, "morph.xml", "morph.vmd"); + return; + } + +} diff --git a/src/test/java/testdata/vmd110820/motion/MotionTest.java b/src/test/java/testdata/vmd110820/motion/MotionTest.java new file mode 100644 index 0000000..5c5ed9b --- /dev/null +++ b/src/test/java/testdata/vmd110820/motion/MotionTest.java @@ -0,0 +1,56 @@ +/* + */ + +package testdata.vmd110820.motion; + +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +import static testdata.CnvAssert.*; + +/** + * + */ +public class MotionTest { + + static Class THISCLASS = MotionTest.class; + + public MotionTest() { + assert this.getClass() == THISCLASS; + return; + } + + @BeforeClass + public static void setUpClass() { + } + + @AfterClass + public static void tearDownClass() { + } + + @Before + public void setUp() { + } + + @After + public void tearDown() { + } + + @Test + public void vmd2xml() throws Exception{ + System.out.println("vmd2xml"); + assertVmd2Xml(THISCLASS, "motion.vmd", "motion.xml"); + return; + } + + @Test + public void xml2vmd() throws Exception{ + System.out.println("xml2vmd"); + assertXml2Vmd(THISCLASS, "motion.xml", "motion.vmd"); + return; + } + +} diff --git a/src/test/resources/testdata/vmd110820/camera/camera.xml b/src/test/resources/testdata/vmd110820/camera/camera.xml index 55a445b..79f309e 100644 --- a/src/test/resources/testdata/vmd110820/camera/camera.xml +++ b/src/test/resources/testdata/vmd110820/camera/camera.xml @@ -15,18 +15,18 @@ > - + @@ -71,14 +71,6 @@ - diff --git a/src/test/resources/testdata/vmd110820/luminous/luminous.xml b/src/test/resources/testdata/vmd110820/luminous/luminous.xml index 80caa93..f6a795a 100644 --- a/src/test/resources/testdata/vmd110820/luminous/luminous.xml +++ b/src/test/resources/testdata/vmd110820/luminous/luminous.xml @@ -14,19 +14,6 @@ version="110820" > - - @@ -54,14 +41,6 @@ - diff --git a/src/test/resources/testdata/vmd110820/minimum/mincam.xml b/src/test/resources/testdata/vmd110820/minimum/mincam.xml index 96d2842..749c55d 100644 --- a/src/test/resources/testdata/vmd110820/minimum/mincam.xml +++ b/src/test/resources/testdata/vmd110820/minimum/mincam.xml @@ -14,33 +14,12 @@ version="110820" > - - - diff --git a/src/test/resources/testdata/vmd110820/minimum/minmotion.xml b/src/test/resources/testdata/vmd110820/minimum/minmotion.xml index d5d1979..40cc5a1 100644 --- a/src/test/resources/testdata/vmd110820/minimum/minmotion.xml +++ b/src/test/resources/testdata/vmd110820/minimum/minmotion.xml @@ -14,20 +14,9 @@ version="110820" > - + - - diff --git a/src/test/resources/testdata/vmd110820/morph/morph.vmd b/src/test/resources/testdata/vmd110820/morph/morph.vmd new file mode 100644 index 0000000000000000000000000000000000000000..9d67fb057b1de3b8a3f30ed66c2822d79d69ce4e GIT binary patch literal 208 zcmWH`PfpCq&rDJ9%`eH!&r@(oEJ;)_FfcG;@bdQY&CO3q&0+Y90vLdR4Tzf-ph$p( tK>$sd6(VYnCd>sEZm@4!h+#-tS{k}A$Pi;=V{~DVA!pB=v4vOxApu_rZCwBW literal 0 HcmV?d00001 diff --git a/src/test/resources/testdata/vmd110820/morph/morph.xml b/src/test/resources/testdata/vmd110820/morph/morph.xml new file mode 100644 index 0000000..0ae0d55 --- /dev/null +++ b/src/test/resources/testdata/vmd110820/morph/morph.xml @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/resources/testdata/vmd110820/motion/motion.vmd b/src/test/resources/testdata/vmd110820/motion/motion.vmd new file mode 100644 index 0000000000000000000000000000000000000000..4ca6a1561c25f105e214d40d32774db9870792b1 GIT binary patch literal 403 zcmWH`PfpCq&rDJ9%`eH!&r@(oEJ;)_FfcG;@bdQY&CO3q&0+Y90+<;X7@DJ+CpX76 zMnk25B6vW9y$BR!Ljf9>5yFSbGBSYq2rjyHtYFI;?17X65CJhVXt3uJagY-cVGzmA ob^sbupN+<4M3rS^KvB%dz|gsC%AN`7aBm|Uj>)Fncj#sU05wc%0ssI2 literal 0 HcmV?d00001 diff --git a/src/test/resources/testdata/vmd110820/motion/motion.xml b/src/test/resources/testdata/vmd110820/motion/motion.xml new file mode 100644 index 0000000..d0ecacf --- /dev/null +++ b/src/test/resources/testdata/vmd110820/motion/motion.xml @@ -0,0 +1,85 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/resources/testdata/vmd110820/shadow/allShadow.xml b/src/test/resources/testdata/vmd110820/shadow/allShadow.xml index bccbd2a..87c4205 100644 --- a/src/test/resources/testdata/vmd110820/shadow/allShadow.xml +++ b/src/test/resources/testdata/vmd110820/shadow/allShadow.xml @@ -14,19 +14,6 @@ version="110820" > - - diff --git a/src/test/resources/testdata/vmd110820/small/onlyBone.xml b/src/test/resources/testdata/vmd110820/small/onlyBone.xml index ce6e385..3eed8be 100644 --- a/src/test/resources/testdata/vmd110820/small/onlyBone.xml +++ b/src/test/resources/testdata/vmd110820/small/onlyBone.xml @@ -20,10 +20,10 @@ - + @@ -41,14 +41,6 @@ - diff --git a/src/test/resources/testdata/vmd110820/small/onlyLuminous.xml b/src/test/resources/testdata/vmd110820/small/onlyLuminous.xml index 284d3dd..38f62ee 100644 --- a/src/test/resources/testdata/vmd110820/small/onlyLuminous.xml +++ b/src/test/resources/testdata/vmd110820/small/onlyLuminous.xml @@ -14,19 +14,6 @@ version="110820" > - - @@ -39,14 +26,6 @@ - diff --git a/src/test/resources/testdata/vmd110820/small/onlyMorph.xml b/src/test/resources/testdata/vmd110820/small/onlyMorph.xml index c03f6a6..c521656 100644 --- a/src/test/resources/testdata/vmd110820/small/onlyMorph.xml +++ b/src/test/resources/testdata/vmd110820/small/onlyMorph.xml @@ -17,17 +17,6 @@ - - diff --git a/src/test/resources/testdata/vmd110820/small/onlyShadow.xml b/src/test/resources/testdata/vmd110820/small/onlyShadow.xml index 0afe844..b3b57f2 100644 --- a/src/test/resources/testdata/vmd110820/small/onlyShadow.xml +++ b/src/test/resources/testdata/vmd110820/small/onlyShadow.xml @@ -14,19 +14,6 @@ version="110820" > - - -- 2.11.0