</includes>
</resource>
+ <resource>
+ <directory>src/main/resources</directory>
+ <includes>
+ <include>**/*.properties</include>
+ <include>**/*.xsd</include>
+ <include>**/*.dtd</include>
+ </includes>
+ <excludes>
+ <exclude>**/version.properties</exclude>
+ </excludes>
+ </resource>
+
</resources>
</build>
--- /dev/null
+/*\r
+ * international text\r
+ *\r
+ * License : The MIT License\r
+ * Copyright(c) 2010 MikuToga Partners\r
+ */\r
+\r
+package jp.sourceforge.mikutoga.corelib;\r
+\r
+import java.util.ArrayList;\r
+import java.util.HashMap;\r
+import java.util.Iterator;\r
+import java.util.List;\r
+import java.util.Locale;\r
+import java.util.Map;\r
+import java.util.Set;\r
+\r
+/**\r
+ * 多言語のバリアントを持つ文字列情報。\r
+ * <ul>\r
+ * <li>プライマリ:識別子にはこちらを使う。基本は日本語。\r
+ * <li>グローバル:基本は英語。UCS Basic-Latinオンリーの貧弱な言語環境でも\r
+ * 読める文字列が望ましい。\r
+ * <li>その他:必要に応じて好きな言語を。\r
+ * </ul>\r
+ */\r
+public class I18nText implements CharSequence {\r
+\r
+ /** プライマリ言語のロケール。 */\r
+ public static final Locale LOCALE_PRIMARY = Locale.JAPANESE;\r
+ /** プライマリ言語の言語コード。 */\r
+ public static final String CODE639_PRIMARY = LOCALE_PRIMARY.getLanguage();\r
+\r
+ /** グローバル言語のロケール。 */\r
+ public static final Locale LOCALE_GLOBAL = Locale.ENGLISH;\r
+ /** グローバル言語の言語コード。 */\r
+ public static final String CODE639_GLOBAL = LOCALE_GLOBAL.getLanguage();\r
+\r
+ static{\r
+ assert CODE639_PRIMARY.equals("ja");\r
+ assert CODE639_GLOBAL .equals("en");\r
+ }\r
+\r
+ private final Map<String, String> nameMap = new HashMap<String, String>();\r
+\r
+ /**\r
+ * コンストラクタ。\r
+ */\r
+ public I18nText(){\r
+ super();\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * プライマリ文字列の登録。\r
+ * @param seq プライマリ文字列。nullの場合は削除動作\r
+ */\r
+ public void setPrimaryText(CharSequence seq){\r
+ setText(CODE639_PRIMARY, seq);\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * グローバル文字列の登録。\r
+ * @param seq グローバル文字列。nullの場合は削除動作\r
+ */\r
+ public void setGlobalText(CharSequence seq){\r
+ setText(CODE639_GLOBAL, seq);\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * 任意のロケールに関連付けられた文字列の登録。\r
+ * @param locale ロケール\r
+ * @param seq 文字列。nullの場合は削除動作\r
+ * @throws NullPointerException ロケール引数がnull\r
+ */\r
+ public void setText(Locale locale, CharSequence seq)\r
+ throws NullPointerException{\r
+ String code639 = locale.getLanguage();\r
+ setText(code639, seq);\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * 任意の言語コードに関連付けられた文字列の登録。\r
+ * @param code639 ISO639言語コード\r
+ * @param seq 文字列。nullの場合は削除動作\r
+ * @throws NullPointerException 言語コードがnull\r
+ */\r
+ public void setText(String code639, CharSequence seq)\r
+ throws NullPointerException{\r
+ if(code639 == null) throw new NullPointerException();\r
+\r
+ if(seq != null){\r
+ String text = seq.toString();\r
+ this.nameMap.put(code639, text);\r
+ }else{\r
+ this.nameMap.remove(code639);\r
+ }\r
+\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * 言語コードに応じた文字列を返す。\r
+ * @param code639 ISO639言語コード\r
+ * @return 文字列。見つからなければnullを返す。\r
+ * @throws NullPointerException 引数がnull\r
+ */\r
+ public String getText(String code639) throws NullPointerException{\r
+ if(code639 == null) throw new NullPointerException();\r
+ String result = this.nameMap.get(code639);\r
+ return result;\r
+ }\r
+\r
+ /**\r
+ * ロケールに応じた文字列を返す。\r
+ * @param locale ロケール\r
+ * @return 文字列。見つからなければnullを返す。\r
+ * @throws NullPointerException 引数がnull\r
+ */\r
+ public String getText(Locale locale) throws NullPointerException{\r
+ String code639 = locale.getLanguage();\r
+ String result = getText(code639);\r
+ return result;\r
+ }\r
+\r
+ /**\r
+ * プライマリ文字列を返す。\r
+ * @return 文字列。見つからなければnullを返す。\r
+ */\r
+ public String getPrimaryText(){\r
+ String result = getText(CODE639_PRIMARY);\r
+ return result;\r
+ }\r
+\r
+ /**\r
+ * グローバル文字列を返す。\r
+ * @return 文字列。見つからなければnullを返す。\r
+ */\r
+ public String getGlobalText(){\r
+ String result = getText(CODE639_GLOBAL);\r
+ return result;\r
+ }\r
+\r
+ /**\r
+ * プライマリ文字列を返す。\r
+ * 見つからなければグローバル文字列を返す。\r
+ * それでも見つからなければ空文字列を返す。\r
+ * @return 文字列\r
+ */\r
+ public String getText(){\r
+ String result;\r
+\r
+ result = getPrimaryText();\r
+\r
+ if(result == null){\r
+ result = getGlobalText();\r
+ }\r
+\r
+ if(result == null){\r
+ result = "";\r
+ }\r
+\r
+ return result;\r
+ }\r
+\r
+ /**\r
+ * 実行環境のデフォルトロケールに応じた文字列を返す。\r
+ * 見つからなければグローバル文字列、プライマリ文字列の順に返す。\r
+ * それでも見つからなければ適当な言語コードの文字列を返す。\r
+ * それでも見つからなければ空文字列を返す。\r
+ * デフォルトロケールの確認はその都度行われる。\r
+ * @return 文字列\r
+ */\r
+ public String getLocalizedText(){\r
+ Locale locale = Locale.getDefault();\r
+ String langCode = locale.getLanguage();\r
+\r
+ String result;\r
+\r
+ result = this.nameMap.get(langCode);\r
+\r
+ if(result == null){\r
+ result = this.nameMap.get(CODE639_GLOBAL);\r
+ }\r
+\r
+ if(result == null){\r
+ result = this.nameMap.get(CODE639_PRIMARY);\r
+ }\r
+\r
+ if(result == null){\r
+ Set<String> langSet = this.nameMap.keySet();\r
+ Iterator<String> it = langSet.iterator();\r
+ while(it.hasNext()){\r
+ String lang = it.next();\r
+ result = this.nameMap.get(lang);\r
+ if(result != null) break;\r
+ }\r
+ }\r
+\r
+ if(result == null){\r
+ result = "";\r
+ }\r
+\r
+ return result;\r
+ }\r
+\r
+ /**\r
+ * 全言語の文字列を削除する。\r
+ */\r
+ public void removeAllText(){\r
+ this.nameMap.clear();\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * 登録済みの全ISO639言語コードリストを返す。\r
+ * 優先度はプライマリ、グローバル、その他の順。\r
+ * @return 全ISO639言語コード\r
+ */\r
+ public List<String> lang639CodeList(){\r
+ Set<String> set = this.nameMap.keySet();\r
+ List<String> result = new ArrayList<String>(set.size());\r
+\r
+ for(String lang : set){\r
+ if(lang.equals(CODE639_PRIMARY)) result.add(lang);\r
+ }\r
+\r
+ for(String lang : set){\r
+ if(lang.equals(CODE639_GLOBAL)) result.add(lang);\r
+ }\r
+\r
+ for(String lang : set){\r
+ if(lang.equals(CODE639_PRIMARY)) continue;\r
+ if(lang.equals(CODE639_GLOBAL)) continue;\r
+ result.add(lang);\r
+ }\r
+\r
+ return result;\r
+ }\r
+\r
+ /**\r
+ * プライマリ文字列が登録されているか判定する。\r
+ * @return 登録されていればtrue\r
+ */\r
+ public boolean hasPrimaryText(){\r
+ boolean result = this.nameMap.containsKey(CODE639_PRIMARY);\r
+ return result;\r
+ }\r
+\r
+ /**\r
+ * グローバル文字列が登録されているか判定する。\r
+ * @return 登録されていればtrue\r
+ */\r
+ public boolean hasGlobalText(){\r
+ boolean result = this.nameMap.containsKey(CODE639_GLOBAL);\r
+ return result;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * {@link #getText()}に準ずる。\r
+ * @param index {@inheritDoc}\r
+ * @return {@inheritDoc}\r
+ */\r
+ public char charAt(int index){\r
+ String text = getText();\r
+ char result = text.charAt(index);\r
+ return result;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * {@link #getText()}に準ずる。\r
+ * @return {@inheritDoc}\r
+ */\r
+ public int length(){\r
+ String text = getText();\r
+ int result = text.length();\r
+ return result;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * {@link #getText()}に準ずる。\r
+ * @param start {@inheritDoc}\r
+ * @param end {@inheritDoc}\r
+ * @return {@inheritDoc}\r
+ */\r
+ public CharSequence subSequence(int start, int end){\r
+ String text = getText();\r
+ CharSequence result = text.subSequence(start, end);\r
+ return result;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * {@link #getText()}に準ずる。\r
+ * @return {@inheritDoc}\r
+ */\r
+ @Override\r
+ public String toString(){\r
+ return getText();\r
+ }\r
+\r
+}\r
--- /dev/null
+/*\r
+ * List utilities\r
+ *\r
+ * License : The MIT License\r
+ * Copyright(c) 2010 MikuToga Partners\r
+ */\r
+\r
+package jp.sourceforge.mikutoga.corelib;\r
+\r
+import java.lang.reflect.Constructor;\r
+import java.lang.reflect.InvocationTargetException;\r
+import java.util.Collection;\r
+import java.util.List;\r
+\r
+/**\r
+ * リスト構造の各種ユーティリティ。\r
+ */\r
+public final class ListUtil {\r
+\r
+ /**\r
+ * 隠しコンストラクタ。\r
+ */\r
+ private ListUtil(){\r
+ assert false;\r
+ throw new AssertionError();\r
+ }\r
+\r
+ /**\r
+ * リストの出現順にシリアルナンバーを割り振る。\r
+ * シリアルナンバー先頭は0。\r
+ * @param list リスト。なるべく{@link java.util.RandomAccess}型が望ましい。\r
+ */\r
+ public static void assignIndexedSerial(\r
+ List<? extends SerialNumbered> list){\r
+ int size = list.size();\r
+ for(int idx = 0; idx < size; idx++){\r
+ SerialNumbered numbered = list.get(idx);\r
+ numbered.setSerialNumber(idx);\r
+ }\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * コレクションの要素数を拡張する。\r
+ * 追加された要素にはnullが収められる。\r
+ * コレクションがすでに指定サイズ以上の要素数を持つ場合、何もしない。\r
+ * @param <E> 型\r
+ * @param coll コレクション\r
+ * @param newSize 新サイズ\r
+ */\r
+ public static <E> void extendCollection(Collection<E> coll, int newSize){\r
+ int remain = newSize - coll.size();\r
+ if(remain <= 0) return;\r
+\r
+ for(int ct = 1; ct <= remain; ct++){\r
+ coll.add(null);\r
+ }\r
+\r
+ assert coll.size() == newSize;\r
+\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * リストのnull要素をデフォルトコンストラクタによるインスタンスで埋める。\r
+ * null要素がなければなにもしない。\r
+ * @param <E> 型\r
+ * @param list リスト\r
+ * @param cons コンストラクタ\r
+ * @return 埋めた数\r
+ */\r
+ public static <E> int fillDefCons(List<E> list,\r
+ Constructor<? extends E> cons){\r
+ int result = 0;\r
+\r
+ int size = list.size();\r
+ for(int pt = 0; pt < size; pt++){\r
+ E elem = list.get(pt);\r
+ if(elem != null) continue;\r
+\r
+ try{\r
+ elem = cons.newInstance();\r
+ }catch(InstantiationException e){\r
+ assert false;\r
+ throw new AssertionError(e);\r
+ }catch(IllegalAccessException e){\r
+ assert false;\r
+ throw new AssertionError(e);\r
+ }catch(InvocationTargetException e){\r
+ Throwable cause = e.getTargetException();\r
+ if(cause instanceof RuntimeException){\r
+ throw (RuntimeException) cause;\r
+ }\r
+ if(cause instanceof Error){\r
+ throw (Error) cause;\r
+ }\r
+ assert false;\r
+ throw new AssertionError(e);\r
+ }\r
+\r
+ list.set(pt, elem);\r
+ result++;\r
+ }\r
+\r
+ return result;\r
+ }\r
+\r
+ /**\r
+ * リストのnull要素をデフォルトコンストラクタによるインスタンスで埋める。\r
+ * @param <E> 型\r
+ * @param list リスト\r
+ * @param klass デフォルトコンストラクタの属するクラス\r
+ * @return 埋めた数\r
+ */\r
+ public static <E> int fillDefCons(List<E> list, Class<? extends E> klass){\r
+ Constructor<? extends E> cons;\r
+ try{\r
+ cons = klass.getConstructor();\r
+ }catch(NoSuchMethodException e){\r
+ assert false;\r
+ throw new AssertionError(e);\r
+ }\r
+\r
+ return fillDefCons(list, cons);\r
+ }\r
+\r
+ /**\r
+ * リスト要素数の拡張とデフォルトコンストラクタによる要素埋めを行う。\r
+ * 追加された要素および既存のnull要素には\r
+ * デフォルトコンストラクタによるインスタンスが収められる。\r
+ * @param <E> 型\r
+ * @param list リスト\r
+ * @param klass デフォルトコンストラクタの属するクラス\r
+ * @param newSize 新サイズ\r
+ * @return 埋めた数。\r
+ */\r
+ public static <E> int prepareDefConsList(List<E> list,\r
+ Class<? extends E> klass,\r
+ int newSize ){\r
+ extendCollection(list, newSize);\r
+ int result = fillDefCons(list, klass);\r
+ return result;\r
+ }\r
+\r
+}\r
--- /dev/null
+/*\r
+ * serial-numbered interface\r
+ *\r
+ * License : The MIT License\r
+ * Copyright(c) 2010 MikuToga Partners\r
+ */\r
+\r
+package jp.sourceforge.mikutoga.corelib;\r
+\r
+import java.util.Comparator;\r
+\r
+/**\r
+ * 通し番号を持つオブジェクトの抽象化インタフェース。\r
+ */\r
+public interface SerialNumbered {\r
+\r
+ /** 昇順での比較子。 */\r
+ public Comparator<SerialNumbered> COMPARATOR = new SerialComparator();\r
+\r
+ /**\r
+ * 通し番号を設定する。\r
+ * @param num 通し番号\r
+ */\r
+ void setSerialNumber(int num);\r
+\r
+ /**\r
+ * 通し番号を返す。\r
+ * @return 通し番号\r
+ */\r
+ int getSerialNumber();\r
+\r
+ /**\r
+ * 通し番号による比較子Comparator。\r
+ * 通し番号の昇順を定義づける。\r
+ */\r
+ public static class SerialComparator\r
+ implements Comparator<SerialNumbered> {\r
+\r
+ /**\r
+ * コンストラクタ。\r
+ */\r
+ public SerialComparator(){\r
+ super();\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param o1 {@inheritDoc}\r
+ * @param o2 {@inheritDoc}\r
+ * @return {@inheritDoc}\r
+ */\r
+ public int compare(SerialNumbered o1, SerialNumbered o2){\r
+ if(o1 == o2) return 0;\r
+ if(o1 == null) return -1;\r
+ if(o2 == null) return +1;\r
+\r
+ int ser1 = o1.getSerialNumber();\r
+ int ser2 = o2.getSerialNumber();\r
+\r
+ return ser1 - ser2;\r
+ }\r
+\r
+ }\r
+\r
+}\r
--- /dev/null
+/*\r
+ * Windows File utils\r
+ *\r
+ * License : The MIT License\r
+ * Copyright(c) 2010 MikuToga Partners\r
+ */\r
+\r
+package jp.sourceforge.mikutoga.corelib;\r
+\r
+/**\r
+ * Windowsに特化したFileユーティリティ。\r
+ */\r
+public final class WinFile {\r
+\r
+ public static final char SEPARATOR_CHAR = '\\'; // \\r
+ public static final String SEPARATOR =\r
+ Character.toString(SEPARATOR_CHAR);\r
+ public static final String PFX_UNC =\r
+ SEPARATOR + SEPARATOR; // \\\r
+\r
+ static{\r
+ assert '\\' == 0x005c;\r
+ }\r
+\r
+ /**\r
+ * 隠しコンストラクタ。\r
+ */\r
+ private WinFile(){\r
+ assert false;\r
+ throw new AssertionError();\r
+ }\r
+\r
+ /**\r
+ * Windowsファイル名の正規化を行う。\r
+ * UNCも考慮される。\r
+ * 相対パスは相対パスのまま。\r
+ * <ul>\r
+ * <li>頭の3回以上連続する\記号は2個の\記号に置き換えられる。\r
+ * <li>末尾の1回以上連続する\記号は削除。\r
+ * ただし頭から連続している場合は削除しない。\r
+ * <li>2回以上連続する\記号は1個の\記号にまとめられる。\r
+ * ただし頭から連続している場合はまとめない。\r
+ * </ul>\r
+ * @param seq 対象ファイル名\r
+ * @return 正規化されたファイル名\r
+ */\r
+ public static String normalizeWinFileName(CharSequence seq){\r
+ String text = seq.toString();\r
+ text = text.replaceAll("^\\\\{3,}", "\\\\\\\\");\r
+ text = text.replaceAll("(.*[^\\\\])\\\\+$", "$1");\r
+ text = text.replaceAll("([^\\\\])\\\\{2,}", "$1\\\\");\r
+ return text;\r
+ }\r
+\r
+}\r
--- /dev/null
+/*\r
+ * package information for Javadoc\r
+ *\r
+ * License : The MIT License\r
+ * Copyright(c) 2010 MikuToga Partners\r
+ */\r
+\r
+/**\r
+ * MikuToga共通基盤ライブラリ。\r
+ */\r
+\r
+package jp.sourceforge.mikutoga.corelib;\r
+\r
+/* EOF */\r
--- /dev/null
+/*\r
+ * bone group\r
+ *\r
+ * License : The MIT License\r
+ * Copyright(c) 2010 MikuToga Partners\r
+ */\r
+\r
+package jp.sourceforge.mikutoga.pmd;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Iterator;\r
+import java.util.List;\r
+import jp.sourceforge.mikutoga.corelib.I18nText;\r
+import jp.sourceforge.mikutoga.corelib.SerialNumbered;\r
+\r
+/**\r
+ * ボーングループ。\r
+ * ボーングループ名と0個以上のボーンを配下に持つ。\r
+ * 通し番号0のボーングループは、暗黙に用意される「デフォルトボーングループ」とする。\r
+ */\r
+public class BoneGroup implements SerialNumbered , Iterable<BoneInfo> {\r
+\r
+ private final I18nText groupName = new I18nText();\r
+\r
+ private final List<BoneInfo> boneList = new ArrayList<BoneInfo>();\r
+\r
+ private int serialNo = -1;\r
+\r
+ /**\r
+ * コンストラクタ。\r
+ */\r
+ public BoneGroup(){\r
+ super();\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * ボーングループ名を返す。\r
+ * @return ボーングループ名\r
+ */\r
+ public I18nText getGroupName(){\r
+ return this.groupName;\r
+ }\r
+\r
+ /**\r
+ * ボーンリストを取得する。\r
+ * @return ボーンリスト\r
+ */\r
+ public List<BoneInfo> getBoneList(){\r
+ return this.boneList;\r
+ }\r
+\r
+ /**\r
+ * デフォルトボーングループか否か判定する。\r
+ * 通し番号が0ならデフォルトボーングループ。\r
+ * @return デフォルトボーングループならtrue\r
+ */\r
+ public boolean isDefaultBoneGroup(){\r
+ if(this.serialNo == 0) return true;\r
+ return false;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @return {@inheritDoc}\r
+ */\r
+ public Iterator<BoneInfo> iterator(){\r
+ return this.boneList.iterator();\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param num {@inheritDoc}\r
+ */\r
+ public void setSerialNumber(int num){\r
+ this.serialNo = num;\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @return {@inheritDoc}\r
+ */\r
+ public int getSerialNumber(){\r
+ return this.serialNo;\r
+ }\r
+\r
+ /**\r
+ * ボーングループ番号(ボーン枠番号)を返す。\r
+ * 常に通し番号より1少ない値となる。\r
+ * デフォルトボーングループは-1となる。\r
+ * @return ボーングループ番号\r
+ */\r
+ public int getBoneGroupNumber(){\r
+ return this.serialNo - 1;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @return {@inheritDoc}\r
+ */\r
+ @Override\r
+ public String toString(){\r
+ StringBuilder result = new StringBuilder();\r
+\r
+ result.append("BoneGroup(")\r
+ .append(this.groupName)\r
+ .append(") [");\r
+\r
+ boolean dumped = false;\r
+ for(BoneInfo bone : this){\r
+ if(dumped) result.append(", ");\r
+ result.append(bone.getBoneName());\r
+ dumped = true;\r
+ }\r
+\r
+ result.append(']');\r
+\r
+ return result.toString();\r
+ }\r
+\r
+}\r
--- /dev/null
+/*\r
+ * bone information\r
+ *\r
+ * License : The MIT License\r
+ * Copyright(c) 2010 MikuToga Partners\r
+ */\r
+\r
+package jp.sourceforge.mikutoga.pmd;\r
+\r
+import jp.sourceforge.mikutoga.corelib.I18nText;\r
+import jp.sourceforge.mikutoga.corelib.SerialNumbered;\r
+\r
+/**\r
+ * ボーン情報。\r
+ */\r
+public class BoneInfo implements SerialNumbered {\r
+\r
+ private final I18nText boneName = new I18nText();\r
+ private BoneType boneType;\r
+\r
+ private BoneInfo prevBone;\r
+ private BoneInfo nextBone;\r
+ private BoneInfo ikBone;\r
+\r
+ private final Pos3d position = new Pos3d();\r
+\r
+ private int rotationRatio;\r
+\r
+ private int serialNo = -1;\r
+\r
+ /**\r
+ * コンストラクタ。\r
+ */\r
+ public BoneInfo(){\r
+ super();\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * ボーン名を返す。\r
+ * @return ボーン名\r
+ */\r
+ public I18nText getBoneName(){\r
+ return this.boneName;\r
+ }\r
+\r
+ /**\r
+ * ボーン種別を設定する。\r
+ * @param type ボーン種別\r
+ * @throws NullPointerException 引数がnull\r
+ */\r
+ public void setBoneType(BoneType type) throws NullPointerException{\r
+ if(type == null) throw new NullPointerException();\r
+ this.boneType = type;\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * ボーン種別を返す。\r
+ * @return ボーン種別\r
+ */\r
+ public BoneType getBoneType(){\r
+ return this.boneType;\r
+ }\r
+\r
+ /**\r
+ * 親(前)ボーンを設定する。\r
+ * @param prevBone 前ボーン。ない場合はnullを指定。\r
+ */\r
+ public void setPrevBone(BoneInfo prevBone){\r
+ this.prevBone = prevBone;\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * 親(前)ボーンを返す。\r
+ * @return 前ボーン。ない場合はnullを返す。\r
+ */\r
+ public BoneInfo getPrevBone(){\r
+ return this.prevBone;\r
+ }\r
+\r
+ /**\r
+ * 子(次)ボーンを設定する。\r
+ * 捩りボーンでは軸方向に位置するボーン、\r
+ * 回転連動ボーンでは影響元ボーン。\r
+ * @param nextBone 次ボーン。ない場合はnullを指定。\r
+ */\r
+ public void setNextBone(BoneInfo nextBone){\r
+ this.nextBone = nextBone;\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * 子(次)ボーンを返す。\r
+ * 捩りボーンでは軸方向に位置するボーン、\r
+ * 回転連動ボーンでは影響元ボーン。\r
+ * @return 次ボーン。ない場合はnullを返す。\r
+ */\r
+ public BoneInfo getNextBone(){\r
+ return this.nextBone;\r
+ }\r
+\r
+ /**\r
+ * このボーンが影響を受けるIKボーンを設定する。\r
+ * @param ikBoneArg IKボーン。ない場合はnullを指定。\r
+ */\r
+ public void setIKBone(BoneInfo ikBoneArg){\r
+ this.ikBone = ikBoneArg;\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * このボーンが影響を受けるIKボーンを返す。\r
+ * @return IKボーン。ない場合はnull\r
+ */\r
+ public BoneInfo getIKBone(){\r
+ return this.ikBone;\r
+ }\r
+\r
+ /**\r
+ * ボーン位置を返す。\r
+ * @return ボーン位置\r
+ */\r
+ public Pos3d getPosition(){\r
+ return this.position;\r
+ }\r
+\r
+ /**\r
+ * 回転連動の影響度を返す。\r
+ * 回転連動ボーンの場合のみ有効。\r
+ * @return 回転連動の影響度\r
+ */\r
+ public int getRotationRatio(){\r
+ return this.rotationRatio;\r
+ }\r
+\r
+ /**\r
+ * 回転連動の影響度を設定する。\r
+ * 回転連動ボーンの場合のみ有効。\r
+ * @param ratio 回転連動の影響度\r
+ */\r
+ public void setRotationRatio(int ratio){\r
+ this.rotationRatio = ratio;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param num {@inheritDoc}\r
+ */\r
+ public void setSerialNumber(int num){\r
+ this.serialNo = num;\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @return {@inheritDoc}\r
+ */\r
+ public int getSerialNumber(){\r
+ return this.serialNo;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @return {@inheritDoc}\r
+ */\r
+ @Override\r
+ public String toString(){\r
+ StringBuilder result = new StringBuilder();\r
+\r
+ result.append("Bone")\r
+ .append(this.serialNo)\r
+ .append("(")\r
+ .append(this.boneName.getPrimaryText())\r
+ .append(")");\r
+\r
+ result.append(" type=")\r
+ .append(this.boneType);\r
+\r
+ result.append(" prev=");\r
+ if(this.prevBone != null) result.append(this.prevBone.getBoneName());\r
+ else result.append("NONE");\r
+\r
+ result.append(" next=");\r
+ if(this.nextBone != null) result.append(this.nextBone.getBoneName());\r
+ else result.append("NONE");\r
+\r
+ if(this.boneType == BoneType.LINKEDROT){\r
+ result.append(" rotraio=").append(this.rotationRatio);\r
+ }else{\r
+ result.append(" ik=");\r
+ if(this.ikBone != null) result.append(this.ikBone.getBoneName());\r
+ else result.append("NONE");\r
+ }\r
+\r
+ result.append(" ").append(this.position);\r
+\r
+ return result.toString();\r
+ }\r
+\r
+}\r
--- /dev/null
+/*\r
+ * bone type\r
+ *\r
+ * License : The MIT License\r
+ * Copyright(c) 2010 MikuToga Partners\r
+ */\r
+\r
+package jp.sourceforge.mikutoga.pmd;\r
+\r
+import java.util.Locale;\r
+import java.util.ResourceBundle;\r
+\r
+/**\r
+ * ボーン種別。\r
+ * <ul>\r
+ * <li>0x00:回転\r
+ * <li>0x01:回転/移動\r
+ * <li>0x02:IK\r
+ * <li>0x03:不明\r
+ * <li>0x04:IK影響下(回転)\r
+ * <li>0x05:回転影響下\r
+ * <li>0x06:IK接続先\r
+ * <li>0x07:非表示\r
+ * <li>0x08:捩り\r
+ * <li>0x09:回転連動\r
+ * </ul>\r
+ */\r
+public enum BoneType {\r
+\r
+ /** 回転。 */\r
+ ROTATE(0x00),\r
+ /** 回転/移動。 */\r
+ ROTMOV(0x01),\r
+ /** IK。 */\r
+ IK(0x02),\r
+ /** 不明。 */\r
+ UNKNOWN(0x03),\r
+ /** IK影響下(回転)。 */\r
+ UNDERIK(0x04),\r
+ /** 回転影響下。 */\r
+ UNDERROT(0x05),\r
+ /** IK接続先。 */\r
+ IKCONNECTED(0x06),\r
+ /** 非表示。 */\r
+ HIDDEN(0x07),\r
+ /** 捩り。 */\r
+ TWIST(0x08),\r
+ /** 回転連動。 */\r
+ LINKEDROT(0x09),\r
+ ;\r
+\r
+ private static final String FAMILY_NAME =\r
+ "jp.sourceforge.mikutoga.pmd.resources.BoneTypeName";\r
+\r
+ private final byte encoded;\r
+\r
+ /**\r
+ * コンストラクタ。\r
+ * @param code 符号化int値\r
+ */\r
+ private BoneType(int code){\r
+ this((byte)code);\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * コンストラクタ。\r
+ * @param code 符号化byte値\r
+ */\r
+ private BoneType(byte code){\r
+ this.encoded = code;\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * byte値からデコードする。\r
+ * @param code byte値\r
+ * @return デコードされた列挙子。該当するものがなければnull\r
+ */\r
+ public static BoneType decode(byte code){\r
+ BoneType result = null;\r
+\r
+ for(BoneType type : values()){\r
+ if(type.encode() == code){\r
+ result = type;\r
+ break;\r
+ }\r
+ }\r
+\r
+ return result;\r
+ }\r
+\r
+ /**\r
+ * byte値にエンコードする。\r
+ * @return byte値\r
+ */\r
+ public byte encode(){\r
+ return this.encoded;\r
+ }\r
+\r
+ /**\r
+ * デフォルトロケールでの表示名を返す。\r
+ * @return 表示名\r
+ */\r
+ public String getGuiName(){\r
+ Locale locale = Locale.getDefault();\r
+ return getGuiName(locale);\r
+ }\r
+\r
+ /**\r
+ * ロケールに準じた表示名を返す。\r
+ * @param locale ロケール。nullならデフォルトロケールと解釈される。\r
+ * @return 表示名\r
+ */\r
+ public String getGuiName(Locale locale){\r
+ if(locale == null) return getGuiName();\r
+ ResourceBundle rb = ResourceBundle.getBundle(FAMILY_NAME, locale);\r
+ String key = name();\r
+ String result = rb.getString(key);\r
+ return result;\r
+ }\r
+\r
+}\r
--- /dev/null
+/*\r
+ * 3d rotation (degree)\r
+ *\r
+ * License : The MIT License\r
+ * Copyright(c) 2010 MikuToga Partners\r
+ */\r
+\r
+package jp.sourceforge.mikutoga.pmd;\r
+\r
+/**\r
+ * XYZ3軸による回転量(degree)。\r
+ * radianではなくdegree。(直角は90.0)\r
+ */\r
+public class Deg3d {\r
+\r
+ private float xDeg;\r
+ private float yDeg;\r
+ private float zDeg;\r
+\r
+ /**\r
+ * コンストラクタ。\r
+ */\r
+ public Deg3d(){\r
+ super();\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * X軸回転量を設定する。\r
+ * @param xDeg X軸回転量(degree)\r
+ */\r
+ public void setXDeg(float xDeg){\r
+ this.xDeg = xDeg;\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * X軸回転量を返す。\r
+ * @return X軸回転量(degree)\r
+ */\r
+ public float getXDeg(){\r
+ return this.xDeg;\r
+ }\r
+\r
+ /**\r
+ * Y軸回転量を設定する。\r
+ * @param yDeg Y軸回転量(degree)\r
+ */\r
+ public void setYDeg(float yDeg){\r
+ this.yDeg = yDeg;\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * Y軸回転量を返す。\r
+ * @return Y軸回転量(degree)\r
+ */\r
+ public float getYDeg(){\r
+ return this.yDeg;\r
+ }\r
+\r
+ /**\r
+ * Z軸回転量を設定する。\r
+ * @param zDeg Z軸回転量(degree)\r
+ */\r
+ public void setZDeg(float zDeg){\r
+ this.zDeg = zDeg;\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * Z軸回転量を返す。\r
+ * @return Z軸回転量(degree)\r
+ */\r
+ public float getZDeg(){\r
+ return this.zDeg;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @return {@inheritDoc}\r
+ */\r
+ @Override\r
+ public String toString(){\r
+ StringBuilder result = new StringBuilder();\r
+\r
+ result.append("deg=[")\r
+ .append(this.xDeg).append(", ")\r
+ .append(this.yDeg).append(", ")\r
+ .append(this.zDeg).append(']');\r
+\r
+ return result.toString();\r
+ }\r
+\r
+}\r
--- /dev/null
+/*\r
+ * dynamics parameter\r
+ *\r
+ * License : The MIT License\r
+ * Copyright(c) 2010 MikuToga Partners\r
+ */\r
+\r
+package jp.sourceforge.mikutoga.pmd;\r
+\r
+/**\r
+ * 剛体間力学演算の各種パラメータ。\r
+ * 各剛体に設定可能なパラメータは\r
+ * 「質量」、「移動減衰率」、「回転減衰率」、「反発力」、「摩擦力」の5種類。\r
+ */\r
+public class DynamicsInfo {\r
+\r
+ /** 質量。 */\r
+ private float mass;\r
+ /** 移動減衰率。 */\r
+ private float dampingPos;\r
+ /** 回転減衰率。 */\r
+ private float dampingRot;\r
+ /** 反発力。 */\r
+ private float restitution;\r
+ /** 摩擦力。 */\r
+ private float friction;\r
+\r
+ /**\r
+ * コンストラクタ。\r
+ */\r
+ public DynamicsInfo(){\r
+ super();\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * 質量を返す。\r
+ * @return 質量\r
+ */\r
+ public float getMass(){\r
+ return this.mass;\r
+ }\r
+\r
+ /**\r
+ * 質量を設定する。\r
+ * @param mass 質量\r
+ */\r
+ public void setMass(float mass){\r
+ this.mass = mass;\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * 移動減衰率を返す。\r
+ * @return 移動減衰率\r
+ */\r
+ public float getDampingPosition(){\r
+ return this.dampingPos;\r
+ }\r
+\r
+ /**\r
+ * 移動減衰率を設定する。\r
+ * @param damping 移動減衰率\r
+ */\r
+ public void setDampingPosition(float damping){\r
+ this.dampingPos = damping;\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * 回転減衰率を返す。\r
+ * @return 回転減衰率\r
+ */\r
+ public float getDampingRotation(){\r
+ return this.dampingRot;\r
+ }\r
+\r
+ /**\r
+ * 回転減衰率を設定する。\r
+ * @param damping 回転減衰率\r
+ */\r
+ public void setDampingRotation(float damping){\r
+ this.dampingRot = damping;\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * 反発力を返す。\r
+ * @return 反発力\r
+ */\r
+ public float getRestitution(){\r
+ return this.restitution;\r
+ }\r
+\r
+ /**\r
+ * 反発力を設定する。\r
+ * @param restitution 反発力\r
+ */\r
+ public void setRestitution(float restitution){\r
+ this.restitution = restitution;\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * 摩擦力を返す。\r
+ * @return 摩擦力\r
+ */\r
+ public float getFriction(){\r
+ return this.friction;\r
+ }\r
+\r
+ /**\r
+ * 摩擦力を設定する。\r
+ * @param friction 摩擦力\r
+ */\r
+ public void setFriction(float friction){\r
+ this.friction = friction;\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @return {@inheritDoc}\r
+ */\r
+ @Override\r
+ public String toString(){\r
+ StringBuilder result = new StringBuilder();\r
+\r
+ result.append("mass=").append(this.mass).append(", ");\r
+ result.append("damping(Pos)=").append(this.dampingPos).append(", ");\r
+ result.append("damping(Rot)=").append(this.dampingRot).append(", ");\r
+ result.append("restitution=").append(this.restitution).append(", ");\r
+ result.append("friction=").append(this.friction);\r
+\r
+ return result.toString();\r
+ }\r
+\r
+}\r
--- /dev/null
+/*\r
+ * IK chained bone\r
+ *\r
+ * License : The MIT License\r
+ * Copyright(c) 2010 MikuToga Partners\r
+ */\r
+\r
+package jp.sourceforge.mikutoga.pmd;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Iterator;\r
+import java.util.List;\r
+\r
+/**\r
+ * IK連鎖ボーン群。\r
+ */\r
+public class IKChain implements Iterable<BoneInfo> {\r
+\r
+ private BoneInfo ikBone;\r
+\r
+ private int ikDepth;\r
+ private float ikWeight;\r
+\r
+ private final List<BoneInfo> chainList = new ArrayList<BoneInfo>();\r
+\r
+ /**\r
+ * コンストラクタ。\r
+ */\r
+ public IKChain(){\r
+ super();\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * IKボーンを設定する。\r
+ * @param bone IKボーン\r
+ */\r
+ public void setIkBone(BoneInfo bone){\r
+ this.ikBone = bone;\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * IKボーンを返す。\r
+ * @return IKボーン\r
+ */\r
+ public BoneInfo getIkBone(){\r
+ return this.ikBone;\r
+ }\r
+\r
+ /**\r
+ * IK演算再帰深度を設定する。\r
+ * @param depth IK演算再帰深度\r
+ */\r
+ public void setIKDepth(int depth){\r
+ this.ikDepth = depth;\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * IK演算再帰深度を返す。\r
+ * @return IK演算再帰深度\r
+ */\r
+ public int getIKDepth(){\r
+ return this.ikDepth;\r
+ }\r
+\r
+ /**\r
+ * IKウェイトを設定する。\r
+ * @param weight IKウェイト\r
+ */\r
+ public void setIKWeight(float weight){\r
+ this.ikWeight = weight;\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * IKウェイトを返す。\r
+ * @return IKウェイト\r
+ */\r
+ public float getIKWeight(){\r
+ return this.ikWeight;\r
+ }\r
+\r
+ /**\r
+ * IK連鎖ボーンリストを返す。\r
+ * 最初の要素は必ずIK接続先ボーン。それ以降はIK影響下ボーン。\r
+ * @return IK連鎖ボーンリスト\r
+ */\r
+ public List<BoneInfo> getChainedBoneList(){\r
+ return this.chainList;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @return {@inheritDoc}\r
+ */\r
+ public Iterator<BoneInfo> iterator(){\r
+ return this.chainList.iterator();\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @return {@inheritDoc}\r
+ */\r
+ @Override\r
+ public String toString(){\r
+ StringBuilder result = new StringBuilder();\r
+\r
+ result.append("IKChain");\r
+\r
+ result.append(" depth:").append(this.ikDepth);\r
+ result.append(" weight:").append(this.ikWeight);\r
+\r
+ result.append(" IKbone:").append(this.ikBone.getBoneName());\r
+\r
+ result.append(" [");\r
+\r
+ boolean chaindumped = false;\r
+ for(BoneInfo chain : this.chainList){\r
+ if(chaindumped) result.append(" => ");\r
+ result.append(chain.getBoneName());\r
+ chaindumped = true;\r
+ }\r
+\r
+ result.append("]");\r
+\r
+ return result.toString();\r
+ }\r
+\r
+}\r
--- /dev/null
+/*\r
+ * joint information\r
+ *\r
+ * License : The MIT License\r
+ * Copyright(c) 2010 MikuToga Partners\r
+ */\r
+\r
+package jp.sourceforge.mikutoga.pmd;\r
+\r
+import jp.sourceforge.mikutoga.corelib.I18nText;\r
+\r
+/**\r
+ * 剛体間ジョイント情報。\r
+ */\r
+public class JointInfo {\r
+\r
+ private final I18nText jointName = new I18nText();\r
+\r
+ private RigidInfo rigidA;\r
+ private RigidInfo rigidB;\r
+\r
+ private final Pos3d position = new Pos3d();\r
+ private final Rad3d rotation = new Rad3d();\r
+\r
+ private final Pos3d elaPosition = new Pos3d();\r
+ private final Deg3d elaRotation = new Deg3d();\r
+\r
+ private final TripletRange posRange = new TripletRange();\r
+ private final TripletRange rotRange = new TripletRange();\r
+\r
+ /**\r
+ * コンストラクタ。\r
+ */\r
+ public JointInfo(){\r
+ super();\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * ジョイント名を返す。\r
+ * @return ジョイント名\r
+ */\r
+ public I18nText getJointName(){\r
+ return this.jointName;\r
+ }\r
+\r
+ /**\r
+ * 連結剛体Aを返す。\r
+ * @return 連結剛体A\r
+ */\r
+ public RigidInfo getRigidA(){\r
+ return this.rigidA;\r
+ }\r
+\r
+ /**\r
+ * 連結剛体Bを返す。\r
+ * @return 連結剛体B\r
+ */\r
+ public RigidInfo getRigidB(){\r
+ return this.rigidB;\r
+ }\r
+\r
+ /**\r
+ * 連結する剛体を設定する。\r
+ * @param rigidA 連結剛体A\r
+ * @param rigidB 連結剛体B\r
+ */\r
+ public void setRigidPair(RigidInfo rigidA, RigidInfo rigidB){\r
+ this.rigidA = rigidA;\r
+ this.rigidB = rigidB;\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * ジョイントの位置を返す。\r
+ * @return ジョイントの位置\r
+ */\r
+ public Pos3d getPosition(){\r
+ return this.position;\r
+ }\r
+\r
+ /**\r
+ * ジョイントの姿勢を返す。\r
+ * @return ジョイントの姿勢\r
+ */\r
+ public Rad3d getRotation(){\r
+ return this.rotation;\r
+ }\r
+\r
+ /**\r
+ * ジョイントのバネ位置を返す。\r
+ * @return ジョイントのバネ位置\r
+ */\r
+ public Pos3d getElasticPosition(){\r
+ return this.elaPosition;\r
+ }\r
+\r
+ /**\r
+ * ジョイントのバネ姿勢を返す。\r
+ * @return ジョイントのバネ姿勢\r
+ */\r
+ public Deg3d getElasticRotation(){\r
+ return this.elaRotation;\r
+ }\r
+\r
+ /**\r
+ * ジョイントの位置制約を返す。\r
+ * @return ジョイントの位置制約\r
+ */\r
+ public TripletRange getPositionRange(){\r
+ return this.posRange;\r
+ }\r
+\r
+ /**\r
+ * ジョイントの姿勢制約を返す。\r
+ * @return ジョイントの姿勢制約\r
+ */\r
+ public TripletRange getRotationRange(){\r
+ return this.rotRange;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @return {@inheritDoc}\r
+ */\r
+ @Override\r
+ public String toString(){\r
+ StringBuilder result = new StringBuilder();\r
+\r
+ result.append("Joint ");\r
+ result.append(this.jointName);\r
+ result.append("[")\r
+ .append(this.rigidA.getRigidName())\r
+ .append("<=>")\r
+ .append(this.rigidB.getRigidName())\r
+ .append("] ");\r
+ result.append(this.position).append(' ');\r
+ result.append(this.rotation).append(' ');\r
+\r
+ result.append("poslim{").append(this.posRange).append("} ");\r
+ result.append("rotlim{").append(this.rotRange).append("} ");\r
+\r
+ result.append("ela:").append(this.elaPosition).append(' ');\r
+ result.append("ela:").append(this.elaRotation);\r
+\r
+ return result.toString();\r
+ }\r
+\r
+}\r
--- /dev/null
+/*\r
+ * material information\r
+ *\r
+ * License : The MIT License\r
+ * Copyright(c) 2010 MikuToga Partners\r
+ */\r
+\r
+package jp.sourceforge.mikutoga.pmd;\r
+\r
+import java.awt.Color;\r
+import java.awt.Transparency;\r
+import java.util.ArrayList;\r
+import java.util.Iterator;\r
+import java.util.List;\r
+import jp.sourceforge.mikutoga.corelib.I18nText;\r
+\r
+/**\r
+ * マテリアル素材情報。\r
+ */\r
+public class Material implements Iterable<Surface> {\r
+\r
+ private final I18nText materialName = new I18nText();\r
+\r
+ private Color diffuseColor;\r
+\r
+ private Color specularColor;\r
+ private float shininess;\r
+\r
+ private Color ambientColor;\r
+\r
+ private final ShadeInfo shadeInfo = new ShadeInfo();\r
+\r
+ private boolean edgeAppearance = true;\r
+\r
+ private final List<Surface> surfaceList = new ArrayList<Surface>();\r
+\r
+ /**\r
+ * コンストラクタ。\r
+ */\r
+ public Material(){\r
+ super();\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * 色を不透明化する。\r
+ * @param color 色\r
+ * @return 不透明化した色。引数と同じ場合もありうる。\r
+ */\r
+ private static Color forceOpaque(Color color){\r
+ if(color.getTransparency() == Transparency.OPAQUE){\r
+ return color;\r
+ }\r
+\r
+ float[] rgba = new float[4];\r
+ color.getRGBColorComponents(rgba);\r
+\r
+ Color result = new Color(rgba[0], rgba[1], rgba[2], 1.0f);\r
+\r
+ return result;\r
+ }\r
+\r
+ /**\r
+ * マテリアル名を返す。\r
+ * PMDEditorのみでのサポート?\r
+ * @return マテリアル名\r
+ */\r
+ public I18nText getMaterialName(){\r
+ return this.materialName;\r
+ }\r
+\r
+ /**\r
+ * 拡散光を設定する。\r
+ * アルファ成分も反映される。\r
+ * @param color 拡散光\r
+ * @throws NullPointerException 引数がnull\r
+ */\r
+ public void setDiffuseColor(Color color) throws NullPointerException{\r
+ if(color == null) throw new NullPointerException();\r
+ this.diffuseColor = color;\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * 拡散光を返す。\r
+ * @return 拡散光\r
+ */\r
+ public Color getDiffuseColor(){\r
+ return this.diffuseColor;\r
+ }\r
+\r
+ /**\r
+ * 反射光を設定する。\r
+ * 透過成分があれば不透明化される。\r
+ * @param color 反射光\r
+ * @throws NullPointerException 引数がnull\r
+ */\r
+ public void setSpecularColor(Color color)\r
+ throws NullPointerException{\r
+ if(color == null) throw new NullPointerException();\r
+ this.specularColor = forceOpaque(color);\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * 反射光を返す。\r
+ * @return 反射光\r
+ */\r
+ public Color getSpecularColor(){\r
+ return this.specularColor;\r
+ }\r
+\r
+ /**\r
+ * 環境光を設定する。\r
+ * 透過成分があれば不透明化される。\r
+ * @param color 環境光\r
+ * @throws NullPointerException 引数がnull\r
+ */\r
+ public void setAmbientColor(Color color)\r
+ throws NullPointerException{\r
+ if(color == null) throw new NullPointerException();\r
+ this.ambientColor = forceOpaque(color);\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * 環境光を返す。\r
+ * @return 環境光\r
+ */\r
+ public Color getAmbientColor(){\r
+ return this.ambientColor;\r
+ }\r
+\r
+ /**\r
+ * 光沢強度を設定する。\r
+ * MMDで用いられるのは1.0〜15.0あたり。\r
+ * @param shininess 光沢強度\r
+ */\r
+ public void setShininess(float shininess){\r
+ this.shininess = shininess;\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * 光沢強度を返す。\r
+ * @return 光沢強度\r
+ */\r
+ public float getShininess(){\r
+ return this.shininess;\r
+ }\r
+\r
+ /**\r
+ * シェーディング設定を返す。\r
+ * @return シェーディング設定\r
+ */\r
+ public ShadeInfo getShadeInfo(){\r
+ return this.shadeInfo;\r
+ }\r
+\r
+ /**\r
+ * エッジを表示するか設定する。\r
+ * 頂点単位の設定より優先度は低い。\r
+ * @param show 表示するならtrue\r
+ */\r
+ public void setEdgeAppearance(boolean show){\r
+ this.edgeAppearance = show;\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * エッジを表示するか判定する。\r
+ * 頂点単位の設定より優先度は低い。\r
+ * @return 表示するならtrue\r
+ */\r
+ public boolean getEdgeAppearance(){\r
+ return this.edgeAppearance;\r
+ }\r
+\r
+ /**\r
+ * 面リストを返す。\r
+ * @return 面リスト\r
+ */\r
+ public List<Surface> getSurfaceList(){\r
+ return this.surfaceList;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @return {@inheritDoc}\r
+ */\r
+ public Iterator<Surface> iterator(){\r
+ return this.surfaceList.iterator();\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @return {@inheritDoc}\r
+ */\r
+ @Override\r
+ public String toString(){\r
+ StringBuilder result = new StringBuilder();\r
+\r
+ result.append("Material ");\r
+\r
+ float[] rgba = new float[4];\r
+\r
+ this.diffuseColor.getRGBComponents(rgba);\r
+ result.append("diffuse=[")\r
+ .append(rgba[0]).append(", ")\r
+ .append(rgba[1]).append(", ")\r
+ .append(rgba[2]).append(", ")\r
+ .append(rgba[3]).append(']')\r
+ .append(' ');\r
+\r
+ this.specularColor.getRGBComponents(rgba);\r
+ result.append("specular=[")\r
+ .append(rgba[0]).append(", ")\r
+ .append(rgba[1]).append(", ")\r
+ .append(rgba[2]).append(", ")\r
+ .append(rgba[3]).append(']')\r
+ .append(' ');\r
+\r
+ this.ambientColor.getRGBComponents(rgba);\r
+ result.append("ambient=[")\r
+ .append(rgba[0]).append(", ")\r
+ .append(rgba[1]).append(", ")\r
+ .append(rgba[2]).append(", ")\r
+ .append(rgba[3]).append(']')\r
+ .append(' ');\r
+\r
+ result.append("shininess=")\r
+ .append(this.shininess)\r
+ .append(' ');\r
+ result.append("edge=")\r
+ .append(this.edgeAppearance)\r
+ .append(' ');\r
+ result.append("surfaces=")\r
+ .append(this.surfaceList.size())\r
+ .append(' ');\r
+ result.append(this.shadeInfo);\r
+\r
+ return result.toString();\r
+ }\r
+\r
+}\r
--- /dev/null
+/*\r
+ * morph information\r
+ *\r
+ * License : The MIT License\r
+ * Copyright(c) 2010 MikuToga Partners\r
+ */\r
+\r
+package jp.sourceforge.mikutoga.pmd;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Iterator;\r
+import java.util.List;\r
+import jp.sourceforge.mikutoga.corelib.I18nText;\r
+import jp.sourceforge.mikutoga.corelib.SerialNumbered;\r
+\r
+/**\r
+ * 個別モーフ情報。\r
+ */\r
+public class MorphPart implements SerialNumbered, Iterable<MorphVertex> {\r
+\r
+ private final I18nText morphName = new I18nText();\r
+\r
+ private MorphType type;\r
+\r
+ private final List<MorphVertex> morphVertexList =\r
+ new ArrayList<MorphVertex>();\r
+\r
+ private int serialNo = -1;\r
+\r
+ /**\r
+ * コンストラクタ。\r
+ */\r
+ public MorphPart(){\r
+ super();\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * モーフ名を返す。\r
+ * @return モーフ名\r
+ */\r
+ public I18nText getMorphName(){\r
+ return this.morphName;\r
+ }\r
+\r
+ /**\r
+ * モーフ種別を設定する。\r
+ * @param typeArg モーフ種別\r
+ * @throws NullPointerException 引数がnull\r
+ */\r
+ public void setMorphType(MorphType typeArg) throws NullPointerException{\r
+ if(typeArg == null) throw new NullPointerException();\r
+ this.type = typeArg;\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * モーフ種別を返す。\r
+ * @return モーフ種別。\r
+ */\r
+ public MorphType getMorphType(){\r
+ return this.type;\r
+ }\r
+\r
+ /**\r
+ * モーフ頂点情報リストを返す。\r
+ * @return モーフ頂点情報リスト\r
+ */\r
+ public List<MorphVertex> getMorphVertexList(){\r
+ return this.morphVertexList;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @return {@inheritDoc}\r
+ */\r
+ public Iterator<MorphVertex> iterator(){\r
+ return this.morphVertexList.iterator();\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param num {@inheritDoc}\r
+ */\r
+ public void setSerialNumber(int num){\r
+ this.serialNo = num;\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @return {@inheritDoc}\r
+ */\r
+ public int getSerialNumber(){\r
+ return this.serialNo;\r
+ }\r
+\r
+ @Override\r
+ public String toString(){\r
+ StringBuilder result = new StringBuilder();\r
+\r
+ result.append("Morph(").append(this.morphName).append(") ");\r
+ result.append("type=").append(this.type);\r
+ result.append(" vertexNum=").append(this.morphVertexList.size());\r
+\r
+ return result.toString();\r
+ }\r
+\r
+}\r
--- /dev/null
+/*\r
+ * morph type\r
+ *\r
+ * License : The MIT License\r
+ * Copyright(c) 2010 MikuToga Partners\r
+ */\r
+\r
+package jp.sourceforge.mikutoga.pmd;\r
+\r
+import java.util.Locale;\r
+import java.util.ResourceBundle;\r
+\r
+/**\r
+ * モーフ種別。\r
+ * <ul>\r
+ * <li>0:base\r
+ * <li>1:まゆ\r
+ * <li>2:目\r
+ * <li>3:リップ\r
+ * <li>4:その他\r
+ * </ul>\r
+ */\r
+public enum MorphType {\r
+\r
+ /** base。 */\r
+ BASE(0x00),\r
+ /** まゆ。 */\r
+ EYEBROW(0x01),\r
+ /** 目。 */\r
+ EYE(0x02),\r
+ /** リップ。 */\r
+ LIP(0x03),\r
+ /** その他。 */\r
+ EXTRA(0x04),\r
+ ;\r
+\r
+ private static final String FAMILY_NAME =\r
+ "jp.sourceforge.mikutoga.pmd.resources.MorphTypeName";\r
+\r
+ private final byte encoded;\r
+\r
+ /**\r
+ * コンストラクタ。\r
+ * @param code 符号化int値\r
+ */\r
+ private MorphType(int code){\r
+ this((byte)code);\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * コンストラクタ。\r
+ * @param code 符号化byte値\r
+ */\r
+ private MorphType(byte code){\r
+ this.encoded = code;\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * byte値からデコードする。\r
+ * @param code byte値\r
+ * @return デコードされた列挙子。該当するものがなければnull\r
+ */\r
+ public static MorphType decode(byte code){\r
+ MorphType result = null;\r
+\r
+ for(MorphType type : values()){\r
+ if(type.encode() == code){\r
+ result = type;\r
+ break;\r
+ }\r
+ }\r
+\r
+ return result;\r
+ }\r
+\r
+ /**\r
+ * byte値にエンコードする。\r
+ * @return byte値\r
+ */\r
+ public byte encode(){\r
+ return this.encoded;\r
+ }\r
+\r
+ /**\r
+ * デフォルトロケールでの表示名を返す。\r
+ * @return 表示名\r
+ */\r
+ public String getGuiName(){\r
+ Locale locale = Locale.getDefault();\r
+ return getGuiName(locale);\r
+ }\r
+\r
+ /**\r
+ * ロケールに準じた表示名を返す。\r
+ * @param locale ロケール。nullならデフォルトロケールと解釈される。\r
+ * @return 表示名\r
+ */\r
+ public String getGuiName(Locale locale){\r
+ if(locale == null) return getGuiName();\r
+ ResourceBundle rb = ResourceBundle.getBundle(FAMILY_NAME, locale);\r
+ String key = name();\r
+ String result = rb.getString(key);\r
+ return result;\r
+ }\r
+\r
+ /**\r
+ * モーフ種別がbaseか否か判定する。\r
+ * @return baseならtrue\r
+ */\r
+ public boolean isBase(){\r
+ if(this == BASE) return true;\r
+ return false;\r
+ }\r
+\r
+}\r
--- /dev/null
+/*\r
+ * morph vertex information\r
+ *\r
+ * License : The MIT License\r
+ * Copyright(c) 2010 MikuToga Partners\r
+ */\r
+\r
+package jp.sourceforge.mikutoga.pmd;\r
+\r
+import java.util.Comparator;\r
+import jp.sourceforge.mikutoga.corelib.SerialNumbered;\r
+\r
+/**\r
+ * モーフアニメーションを構成する個別の頂点移動の情報。\r
+ */\r
+public class MorphVertex implements SerialNumbered{\r
+\r
+ /** 頂点IDを昇順に順序づけるComaparator。 */\r
+ public static final Comparator<MorphVertex> VIDCOMPARATOR =\r
+ new VertexIdComparator();\r
+\r
+ private Vertex baseVertex;\r
+ private final Pos3d offset = new Pos3d();\r
+\r
+ private int serialNo = -1;\r
+\r
+ /**\r
+ * コンストラクタ。\r
+ */\r
+ public MorphVertex(){\r
+ super();\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * 移動元頂点情報を返す。\r
+ * @return 移動元頂点\r
+ */\r
+ public Vertex getBaseVertex(){\r
+ return this.baseVertex;\r
+ }\r
+\r
+ /**\r
+ * 移動元頂点情報を設定する。\r
+ * @param vertex 移動元頂点\r
+ * @throws NullPointerException 引数がnull\r
+ */\r
+ public void setBaseVertex(Vertex vertex) throws NullPointerException{\r
+ if(vertex == null) throw new NullPointerException();\r
+ this.baseVertex = vertex;\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * 頂点移動量を返す。\r
+ * @return 頂点移動量\r
+ */\r
+ public Pos3d getOffset(){\r
+ return this.offset;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param num {@inheritDoc}\r
+ */\r
+ public void setSerialNumber(int num){\r
+ this.serialNo = num;\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @return {@inheritDoc}\r
+ */\r
+ public int getSerialNumber(){\r
+ return this.serialNo;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @return {@inheritDoc}\r
+ */\r
+ @Override\r
+ public String toString(){\r
+ StringBuilder result = new StringBuilder();\r
+\r
+ result.append("vid(")\r
+ .append(this.baseVertex.getSerialNumber())\r
+ .append(") ");\r
+ result.append(this.baseVertex.getPosition());\r
+ result.append(" >> ");\r
+ result.append(this.offset);\r
+\r
+ return result.toString();\r
+ }\r
+\r
+ /**\r
+ * 頂点IDによる比較子Comparator。\r
+ */\r
+ private static final class VertexIdComparator\r
+ implements Comparator<MorphVertex> {\r
+\r
+ /**\r
+ * コンストラクタ。\r
+ */\r
+ private VertexIdComparator(){\r
+ super();\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param o1 {@inheritDoc}\r
+ * @param o2 {@inheritDoc}\r
+ * @return {@inheritDoc}\r
+ */\r
+ public int compare(MorphVertex o1, MorphVertex o2){\r
+ if(o1 == o2) return 0;\r
+ if(o1 == null) return -1;\r
+ if(o2 == null) return +1;\r
+\r
+ int ser1 = o1.getBaseVertex().getSerialNumber();\r
+ int ser2 = o2.getBaseVertex().getSerialNumber();\r
+\r
+ return ser1 - ser2;\r
+ }\r
+\r
+ }\r
+\r
+}\r
--- /dev/null
+/*\r
+ * PMD model\r
+ *\r
+ * License : The MIT License\r
+ * Copyright(c) 2010 MikuToga Partners\r
+ */\r
+\r
+package jp.sourceforge.mikutoga.pmd;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Collections;\r
+import java.util.EnumMap;\r
+import java.util.HashMap;\r
+import java.util.HashSet;\r
+import java.util.LinkedList;\r
+import java.util.List;\r
+import java.util.Map;\r
+import java.util.RandomAccess;\r
+import java.util.Set;\r
+import jp.sourceforge.mikutoga.corelib.I18nText;\r
+\r
+/**\r
+ * PMDモデルファイル一式に相当するもの。\r
+ * 様々な基本構造のリストの集合から構成される。\r
+ */\r
+public class PmdModel {\r
+\r
+ /** デフォルトのヘッダバージョン。 */\r
+ public static final float DEF_HEADERVER = 1.0f;\r
+\r
+ private float headerVersion = DEF_HEADERVER;\r
+\r
+ private final I18nText modelName = new I18nText();\r
+ private final I18nText description = new I18nText();\r
+\r
+ private final List<Vertex> vertexList = new ArrayList<Vertex>();\r
+ private final List<Surface> surfaceList = new ArrayList<Surface>();\r
+ private final List<Material> materialList = new LinkedList<Material>();\r
+\r
+ private final List<BoneInfo> boneList = new ArrayList<BoneInfo>();\r
+ private final List<BoneGroup> boneGroupList = new ArrayList<BoneGroup>();\r
+\r
+ private final List<IKChain> ikChainList = new ArrayList<IKChain>();\r
+\r
+ private final Map<MorphType, List<MorphPart>> morphMap =\r
+ new EnumMap<MorphType, List<MorphPart>>(MorphType.class);\r
+\r
+ private final List<RigidInfo> rigidList = new ArrayList<RigidInfo>();\r
+ private final List<RigidGroup> rigidGroupList =\r
+ new ArrayList<RigidGroup>();\r
+\r
+ private final List<JointInfo> jointList = new ArrayList<JointInfo>();\r
+\r
+ private ToonMap toonMap = new ToonMap();\r
+\r
+ /**\r
+ * コンストラクタ。\r
+ */\r
+ public PmdModel(){\r
+ super();\r
+\r
+ assert this.vertexList instanceof RandomAccess;\r
+ assert this.surfaceList instanceof RandomAccess;\r
+\r
+ this.morphMap.put(MorphType.EYEBROW, new ArrayList<MorphPart>());\r
+ this.morphMap.put(MorphType.EYE, new ArrayList<MorphPart>());\r
+ this.morphMap.put(MorphType.LIP, new ArrayList<MorphPart>());\r
+ this.morphMap.put(MorphType.EXTRA, new ArrayList<MorphPart>());\r
+\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * PMDファイルのヘッダバージョンを返す。\r
+ * @return PMDファイルのヘッダバージョン\r
+ */\r
+ public float getHeaderVersion(){\r
+ return this.headerVersion;\r
+ }\r
+\r
+ /**\r
+ * PMDファイルのヘッダバージョンを設定する。\r
+ * @param ver PMDファイルのヘッダバージョン\r
+ */\r
+ public void setHeaderVersion(float ver){\r
+ this.headerVersion = ver;\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * モデル名を返す。\r
+ * @return モデル名\r
+ */\r
+ public I18nText getModelName(){\r
+ return this.modelName;\r
+ }\r
+\r
+ /**\r
+ * モデル説明文を返す。\r
+ * 改行表現には{@literal \n}が用いられる\r
+ * @return モデル説明文\r
+ */\r
+ public I18nText getDescription(){\r
+ return this.description;\r
+ }\r
+\r
+ /**\r
+ * 頂点リストを返す。\r
+ * @return 頂点リスト。\r
+ */\r
+ public List<Vertex> getVertexList(){\r
+ return this.vertexList;\r
+ }\r
+\r
+ /**\r
+ * 面リストを返す。\r
+ * @return 面リスト\r
+ */\r
+ public List<Surface> getSurfaceList(){\r
+ return this.surfaceList;\r
+ }\r
+\r
+ /**\r
+ * 素材リストを返す。\r
+ * @return 素材リスト\r
+ */\r
+ public List<Material> getMaterialList(){\r
+ return this.materialList;\r
+ }\r
+\r
+ /**\r
+ * ボーンリストを返す。\r
+ * @return ボーンリスト\r
+ */\r
+ public List<BoneInfo> getBoneList(){\r
+ return this.boneList;\r
+ }\r
+\r
+ /**\r
+ * ボーングループリストを返す。\r
+ * @return ボーングループリスト\r
+ */\r
+ public List<BoneGroup> getBoneGroupList(){\r
+ return this.boneGroupList;\r
+ }\r
+\r
+ /**\r
+ * IKチェーンリストを返す。\r
+ * @return IKチェーンリスト\r
+ */\r
+ public List<IKChain> getIKChainList(){\r
+ return this.ikChainList;\r
+ }\r
+\r
+ /**\r
+ * 種類別モーフリストのマップを返す。\r
+ * @return 種類別モーフリストのマップ\r
+ */\r
+ public Map<MorphType, List<MorphPart>> getMorphMap(){\r
+ return this.morphMap;\r
+ }\r
+\r
+ /**\r
+ * 剛体リストを返す。\r
+ * @return 剛体リスト\r
+ */\r
+ public List<RigidInfo> getRigidList(){\r
+ return this.rigidList;\r
+ }\r
+\r
+ /**\r
+ * 剛体グループリストを返す。\r
+ * @return 剛体グループリスト。\r
+ */\r
+ public List<RigidGroup> getRigidGroupList(){\r
+ return this.rigidGroupList;\r
+ }\r
+\r
+ /**\r
+ * 剛体間ジョイントリストを返す。\r
+ * @return 剛体間ジョイントリスト\r
+ */\r
+ public List<JointInfo> getJointList(){\r
+ return this.jointList;\r
+ }\r
+\r
+ /**\r
+ * トゥーンファイルマップを返す。\r
+ * @return トゥーンファイルマップ\r
+ */\r
+ public ToonMap getToonMap(){\r
+ return this.toonMap;\r
+ }\r
+\r
+ /**\r
+ * トゥーンファイルマップを設定する。\r
+ * 各素材のシェーディングで参照するトゥーンファイルマップも更新される。\r
+ * @param map トゥーンファイルマップ\r
+ */\r
+ public void setToonMap(ToonMap map){\r
+ this.toonMap = map;\r
+ for(Material material : this.materialList){\r
+ ShadeInfo info = material.getShadeInfo();\r
+ info.setToonMap(this.toonMap);\r
+ }\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * このモデルがグローバル名を含むか判定する。\r
+ * ボーン名、ボーングループ名、モーフ名、モデル説明文が判定対象。\r
+ * @return グローバル名を持つならtrue\r
+ */\r
+ public boolean hasGlobalText(){\r
+ if(this.modelName.hasGlobalText()) return true;\r
+ if(this.description.hasGlobalText()) return true;\r
+\r
+ for(BoneInfo bone : this.boneList){\r
+ if(bone.getBoneName().hasGlobalText()) return true;\r
+ }\r
+\r
+ List<MorphType> typeList = new ArrayList<MorphType>();\r
+ typeList.addAll(this.morphMap.keySet());\r
+ for(MorphType type : typeList){\r
+ List<MorphPart> partList = this.morphMap.get(type);\r
+ for(MorphPart part : partList){\r
+ if(part.getMorphName().hasGlobalText()) return true;\r
+ }\r
+ }\r
+\r
+ for(BoneGroup group : this.boneGroupList){\r
+ if(group.getGroupName().hasGlobalText()) return true;\r
+ }\r
+\r
+ return false;\r
+ }\r
+\r
+ /**\r
+ * モーフで使われる全てのモーフ頂点のリストを返す。\r
+ * モーフ間で重複する頂点はマージされる。\r
+ * 頂点IDでソートされる。\r
+ * <p>\r
+ * 0から始まる通し番号がリナンバリングされる。\r
+ * 通し番号は返されるモーフ頂点リストの添え字番号と一致する。\r
+ * @return モーフに使われるモーフ頂点のリスト\r
+ */\r
+ public List<MorphVertex> mergeMorphVertex(){\r
+ List<MorphVertex> result = new ArrayList<MorphVertex>();\r
+\r
+ Set<Vertex> mergedVertexSet = new HashSet<Vertex>();\r
+ for(MorphType type : this.morphMap.keySet()){\r
+ if(type.isBase()) continue;\r
+ List<MorphPart> partList = this.morphMap.get(type);\r
+ if(partList == null) continue;\r
+ for(MorphPart part : partList){\r
+ for(MorphVertex morphVertex : part){\r
+ Vertex vertex = morphVertex.getBaseVertex();\r
+ if(mergedVertexSet.contains(vertex)) continue;\r
+ mergedVertexSet.add(vertex);\r
+ result.add(morphVertex);\r
+ }\r
+ }\r
+ }\r
+\r
+ Collections.sort(result, MorphVertex.VIDCOMPARATOR);\r
+ for(int idx = 0; idx < result.size(); idx++){\r
+ MorphVertex morphVertex = result.get(idx);\r
+ morphVertex.setSerialNumber(idx);\r
+ }\r
+\r
+ Map<Vertex, MorphVertex> numberedMap =\r
+ new HashMap<Vertex, MorphVertex>();\r
+ for(MorphVertex morphVertex : result){\r
+ numberedMap.put(morphVertex.getBaseVertex(), morphVertex);\r
+ }\r
+\r
+ for(MorphType type : this.morphMap.keySet()){\r
+ if(type.isBase()) continue;\r
+ List<MorphPart> partList = this.morphMap.get(type);\r
+ if(partList == null) continue;\r
+ for(MorphPart part : partList){\r
+ for(MorphVertex morphVertex : part){\r
+ Vertex vertex = morphVertex.getBaseVertex();\r
+ MorphVertex numbered = numberedMap.get(vertex);\r
+ assert numbered != null;\r
+ morphVertex.setSerialNumber(numbered.getSerialNumber());\r
+ }\r
+ }\r
+ }\r
+\r
+ return result;\r
+ }\r
+\r
+ /**\r
+ * 永続化可能な状態へトリミングする。\r
+ * 各種オブジェクトの通し番号が変化する可能性がある。\r
+ */\r
+ public void trimming(){\r
+ List<Surface> trimmedSurfaceList = trimmingSurfaceList();\r
+ this.surfaceList.clear();\r
+ this.surfaceList.addAll(trimmedSurfaceList);\r
+\r
+ List<Vertex> trimmedVertexList = trimmingVertexList();\r
+ this.vertexList.clear();\r
+ this.vertexList.addAll(trimmedVertexList);\r
+\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * 面リストをトリミングする。\r
+ * 所属マテリアル順に再配置し、通し番号を割り振り直す。\r
+ * 所属マテリアルの無い面はリストの末端に配置される。\r
+ * 面リスト中のnullは削除され詰められる。\r
+ * @return トリミングされた面リスト\r
+ */\r
+ private List<Surface> trimmingSurfaceList(){\r
+ Set<Surface> materialedSurfaceSet = new HashSet<Surface>();\r
+ for(Material material : this.materialList){\r
+ if(material == null) continue;\r
+ for(Surface surface : material){\r
+ if(surface == null) continue;\r
+ materialedSurfaceSet.add(surface);\r
+ }\r
+ }\r
+\r
+ materialedSurfaceSet.removeAll(this.surfaceList);\r
+\r
+ List<Surface> result = new ArrayList<Surface>();\r
+ for(Surface surface : this.surfaceList){\r
+ if(surface == null) continue;\r
+ result.add(surface);\r
+ }\r
+\r
+ result.addAll(materialedSurfaceSet);\r
+\r
+ int serialNum = 0;\r
+ for(Surface surface : result){\r
+ surface.setSerialNumber(serialNum);\r
+ serialNum++;\r
+ }\r
+\r
+ return result;\r
+ }\r
+\r
+ /**\r
+ * 頂点リストをトリミングする。\r
+ * 通し番号を振り直す。\r
+ * 所属面の無い頂点はリストの末端に配置される。\r
+ * 頂点リスト中のnullは削除され詰められる。\r
+ * @return トリミングされた頂点リスト\r
+ */\r
+ private List<Vertex> trimmingVertexList(){\r
+ Set<Vertex> surfacedVertexSet = new HashSet<Vertex>();\r
+ for(Surface surface : this.surfaceList){\r
+ if(surface == null) continue;\r
+ for(Vertex vertex : surface){\r
+ surfacedVertexSet.add(vertex);\r
+ }\r
+ }\r
+\r
+ surfacedVertexSet.removeAll(this.vertexList);\r
+\r
+ List<Vertex> result = new ArrayList<Vertex>();\r
+ for(Vertex vertex : this.vertexList){\r
+ if(vertex == null) continue;\r
+ result.add(vertex);\r
+ }\r
+\r
+ result.addAll(surfacedVertexSet);\r
+\r
+ int serialNum = 0;\r
+ for(Vertex vertex : result){\r
+ vertex.setSerialNumber(serialNum);\r
+ serialNum++;\r
+ }\r
+\r
+ return result;\r
+ }\r
+\r
+}\r
--- /dev/null
+/*\r
+ * 2D position\r
+ *\r
+ * License : The MIT License\r
+ * Copyright(c) 2010 MikuToga Partners\r
+ */\r
+\r
+package jp.sourceforge.mikutoga.pmd;\r
+\r
+/**\r
+ * 二次元空間座標及び変量を表す。\r
+ */\r
+public class Pos2d {\r
+\r
+ private float xPos;\r
+ private float yPos;\r
+\r
+ /**\r
+ * コンストラクタ。\r
+ * [0,0]が設定される\r
+ */\r
+ public Pos2d(){\r
+ this(0.0f, 0.0f);\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * コンストラクタ。\r
+ * @param xPos X座標\r
+ * @param yPos Y座標\r
+ */\r
+ public Pos2d(float xPos, float yPos){\r
+ super();\r
+ this.xPos = xPos;\r
+ this.yPos = yPos;\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * X座標を設定する。\r
+ * @param xPos X座標\r
+ */\r
+ public void setXPos(float xPos){\r
+ this.xPos = xPos;\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * X座標を返す。\r
+ * @return X座標\r
+ */\r
+ public float getXPos(){\r
+ return this.xPos;\r
+ }\r
+\r
+ /**\r
+ * Y座標を設定する。\r
+ * @param yPos Y座標\r
+ */\r
+ public void setYPos(float yPos){\r
+ this.yPos = yPos;\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * Y座標を返す。\r
+ * @return Y座標\r
+ */\r
+ public float getYPos(){\r
+ return this.yPos;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @return {@inheritDoc}\r
+ */\r
+ @Override\r
+ public String toString(){\r
+ StringBuilder result = new StringBuilder();\r
+\r
+ result.append("pos=[")\r
+ .append(this.xPos).append(", ")\r
+ .append(this.yPos).append(']');\r
+\r
+ return result.toString();\r
+ }\r
+\r
+}\r
--- /dev/null
+/*\r
+ * 3D position\r
+ *\r
+ * License : The MIT License\r
+ * Copyright(c) 2010 MikuToga Partners\r
+ */\r
+\r
+package jp.sourceforge.mikutoga.pmd;\r
+\r
+/**\r
+ * 三次元空間座標及び変量を表す。\r
+ */\r
+public class Pos3d {\r
+\r
+ private float xPos;\r
+ private float yPos;\r
+ private float zPos;\r
+\r
+ /**\r
+ * コンストラクタ。\r
+ * [0,0,0]が設定される。\r
+ */\r
+ public Pos3d(){\r
+ this(0.0f, 0.0f, 0.0f);\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * コンストラクタ。\r
+ * @param xPos X座標\r
+ * @param yPos Y座標\r
+ * @param zPos Z座標\r
+ */\r
+ public Pos3d(float xPos, float yPos, float zPos){\r
+ super();\r
+ this.xPos = xPos;\r
+ this.yPos = yPos;\r
+ this.zPos = zPos;\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * X座標を設定する。\r
+ * @param xPos X座標\r
+ */\r
+ public void setXPos(float xPos){\r
+ this.xPos = xPos;\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * X座標を返す。\r
+ * @return X座標\r
+ */\r
+ public float getXPos(){\r
+ return this.xPos;\r
+ }\r
+\r
+ /**\r
+ * Y座標を設定する。\r
+ * @param yPos Y座標\r
+ */\r
+ public void setYPos(float yPos){\r
+ this.yPos = yPos;\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * Y座標を返す。\r
+ * @return Y座標\r
+ */\r
+ public float getYPos(){\r
+ return this.yPos;\r
+ }\r
+\r
+ /**\r
+ * Z座標を設定する。\r
+ * @param zPos Z座標\r
+ */\r
+ public void setZPos(float zPos){\r
+ this.zPos = zPos;\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * Z座標を返す。\r
+ * @return Z座標\r
+ */\r
+ public float getZPos(){\r
+ return this.zPos;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @return {@inheritDoc}\r
+ */\r
+ @Override\r
+ public String toString(){\r
+ StringBuilder result = new StringBuilder();\r
+\r
+ result.append("pos=[")\r
+ .append(this.xPos).append(", ")\r
+ .append(this.yPos).append(", ")\r
+ .append(this.zPos).append(']');\r
+\r
+ return result.toString();\r
+ }\r
+\r
+}\r
--- /dev/null
+/*\r
+ * 3d rotation (radian)\r
+ *\r
+ * License : The MIT License\r
+ * Copyright(c) 2010 MikuToga Partners\r
+ */\r
+\r
+package jp.sourceforge.mikutoga.pmd;\r
+\r
+/**\r
+ * XYZ3軸による回転量(radian)。\r
+ * degereeではなくradian。(直角はΠ/2)\r
+ */\r
+public class Rad3d {\r
+\r
+ private float xRad;\r
+ private float yRad;\r
+ private float zRad;\r
+\r
+ /**\r
+ * コンストラクタ。\r
+ */\r
+ public Rad3d(){\r
+ super();\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * X軸回転量を設定する。\r
+ * @param xRad X軸回転量(radian)\r
+ */\r
+ public void setXRad(float xRad){\r
+ this.xRad = xRad;\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * X軸回転量を返す。\r
+ * @return X軸回転量(radian)\r
+ */\r
+ public float getXRad(){\r
+ return this.xRad;\r
+ }\r
+\r
+ /**\r
+ * Y軸回転量を設定する。\r
+ * @param yRad Y軸回転量(radian)\r
+ */\r
+ public void setYRad(float yRad){\r
+ this.yRad = yRad;\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * Y軸回転量を返す。\r
+ * @return Y軸回転量(radian)\r
+ */\r
+ public float getYRad(){\r
+ return this.yRad;\r
+ }\r
+\r
+ /**\r
+ * Z軸回転量を設定する。\r
+ * @param zRad Z軸回転量(radian)\r
+ */\r
+ public void setZRad(float zRad){\r
+ this.zRad = zRad;\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * Z軸回転量を返す。\r
+ * @return Z軸回転量(radian)\r
+ */\r
+ public float getZRad(){\r
+ return this.zRad;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @return {@inheritDoc}\r
+ */\r
+ @Override\r
+ public String toString(){\r
+ StringBuilder result = new StringBuilder();\r
+\r
+ result.append("rad=[")\r
+ .append(this.xRad).append(", ")\r
+ .append(this.yRad).append(", ")\r
+ .append(this.zRad).append(']');\r
+\r
+ return result.toString();\r
+ }\r
+\r
+}\r
--- /dev/null
+/*\r
+ * rigid behavior type\r
+ *\r
+ * License : The MIT License\r
+ * Copyright(c) 2010 MikuToga Partners\r
+ */\r
+\r
+package jp.sourceforge.mikutoga.pmd;\r
+\r
+import java.util.Locale;\r
+import java.util.ResourceBundle;\r
+\r
+/**\r
+ * 剛体の振る舞い種別。\r
+ * <ul>\r
+ * <li>0x00:ボーン追従\r
+ * <li>0x01:物理演算\r
+ * <li>0x02:物理演算+ボーン位置合わせ\r
+ * </ul>\r
+ */\r
+public enum RigidBehaviorType {\r
+\r
+ /** ボーン追従。 */\r
+ FOLLOWBONE(0x00),\r
+ /** 物理演算。 */\r
+ ONLYDYNAMICS(0x01),\r
+ /** 物理演算+ボーン位置合わせ。 */\r
+ BONEDDYNAMICS(0x02),\r
+ ;\r
+\r
+ private static final String FAMILY_NAME =\r
+ "jp.sourceforge.mikutoga.pmd.resources.RigidBehaviorTypeName";\r
+\r
+ private final byte encoded;\r
+\r
+ /**\r
+ * コンストラクタ。\r
+ * @param code 符号化int値\r
+ */\r
+ private RigidBehaviorType(int code){\r
+ this((byte)code);\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * コンストラクタ。\r
+ * @param code 符号化byte値\r
+ */\r
+ private RigidBehaviorType(byte code){\r
+ this.encoded = code;\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * byte値からデコードする。\r
+ * @param code byte値\r
+ * @return デコードされた列挙子。該当するものがなければnull\r
+ */\r
+ public static RigidBehaviorType decode(byte code){\r
+ RigidBehaviorType result = null;\r
+\r
+ for(RigidBehaviorType type : values()){\r
+ if(type.encode() == code){\r
+ result = type;\r
+ break;\r
+ }\r
+ }\r
+\r
+ return result;\r
+ }\r
+\r
+ /**\r
+ * byte値にエンコードする。\r
+ * @return byte値\r
+ */\r
+ public byte encode(){\r
+ return this.encoded;\r
+ }\r
+\r
+ /**\r
+ * デフォルトロケールでの表示名を返す。\r
+ * @return 表示名\r
+ */\r
+ public String getGuiName(){\r
+ Locale locale = Locale.getDefault();\r
+ return getGuiName(locale);\r
+ }\r
+\r
+ /**\r
+ * ロケールに準じた表示名を返す。\r
+ * @param locale ロケール。nullならデフォルトロケールと解釈される。\r
+ * @return 表示名\r
+ */\r
+ public String getGuiName(Locale locale){\r
+ if(locale == null) return getGuiName();\r
+ ResourceBundle rb = ResourceBundle.getBundle(FAMILY_NAME, locale);\r
+ String key = name();\r
+ String result = rb.getString(key);\r
+ return result;\r
+ }\r
+\r
+}\r
--- /dev/null
+/*\r
+ * rigid group\r
+ *\r
+ * License : The MIT License\r
+ * Copyright(c) 2010 MikuToga Partners\r
+ */\r
+\r
+package jp.sourceforge.mikutoga.pmd;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Iterator;\r
+import java.util.List;\r
+import jp.sourceforge.mikutoga.corelib.SerialNumbered;\r
+\r
+/**\r
+ * 剛体グループ情報。\r
+ * 剛体間の衝突設定の対象となる。\r
+ */\r
+public class RigidGroup implements SerialNumbered, Iterable<RigidInfo> {\r
+\r
+ private final List<RigidInfo> rigidList = new ArrayList<RigidInfo>();\r
+\r
+ private int serialNo = -1;\r
+\r
+ /**\r
+ * コンストラクタ。\r
+ */\r
+ public RigidGroup(){\r
+ super();\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * 所属する剛体のリストを返す。\r
+ * @return 剛体リスト\r
+ */\r
+ public List<RigidInfo> getRigidList(){\r
+ return this.rigidList;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @return {@inheritDoc}\r
+ */\r
+ public Iterator<RigidInfo> iterator(){\r
+ return this.rigidList.iterator();\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param num {@inheritDoc}\r
+ */\r
+ public void setSerialNumber(int num){\r
+ this.serialNo = num;\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @return {@inheritDoc}\r
+ */\r
+ public int getSerialNumber(){\r
+ return this.serialNo;\r
+ }\r
+\r
+ /**\r
+ * グループ番号を返す。\r
+ * MMDでは1〜16までが使われる。\r
+ * 通し番号に1を加えた値と等しい。\r
+ * @return グループ番号\r
+ */\r
+ public int getGroupNumber(){\r
+ return this.serialNo + 1;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @return {@inheritDoc}\r
+ */\r
+ @Override\r
+ public String toString(){\r
+ StringBuilder result = new StringBuilder();\r
+\r
+ result.append("RigidGroup(").append(getGroupNumber()).append(") [");\r
+\r
+ boolean dumped;\r
+\r
+ dumped = false;\r
+ for(RigidInfo rigid : this.rigidList){\r
+ if(dumped) result.append(", ");\r
+ result.append(rigid.getRigidName());\r
+ dumped = true;\r
+ }\r
+ result.append(']');\r
+\r
+ return result.toString();\r
+ }\r
+\r
+}\r
--- /dev/null
+/*\r
+ * rigid information\r
+ *\r
+ * License : The MIT License\r
+ * Copyright(c) 2010 MikuToga Partners\r
+ */\r
+\r
+package jp.sourceforge.mikutoga.pmd;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Collection;\r
+import jp.sourceforge.mikutoga.corelib.I18nText;\r
+import jp.sourceforge.mikutoga.corelib.SerialNumbered;\r
+\r
+/**\r
+ * 個別の剛体の情報。\r
+ */\r
+public class RigidInfo implements SerialNumbered {\r
+\r
+ private final I18nText rigidName = new I18nText();\r
+\r
+ private RigidBehaviorType behaviorType = RigidBehaviorType.FOLLOWBONE;\r
+\r
+ private final RigidShape rigidShape = new RigidShape();\r
+ private final Pos3d position = new Pos3d();\r
+ private final Rad3d rotation = new Rad3d();\r
+\r
+ private BoneInfo linkedBone;\r
+\r
+ private final DynamicsInfo dynamicsInfo = new DynamicsInfo();\r
+\r
+ private final Collection<RigidGroup> throughGroupColl =\r
+ new ArrayList<RigidGroup>();\r
+\r
+ private RigidGroup rigidGroup;\r
+\r
+ private int serialNo = -1;\r
+\r
+ /**\r
+ * コンストラクタ。\r
+ */\r
+ public RigidInfo(){\r
+ super();\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * 剛体名を返す。\r
+ * @return 剛体名\r
+ */\r
+ public I18nText getRigidName(){\r
+ return this.rigidName;\r
+ }\r
+\r
+ /**\r
+ * 剛体の振る舞い種別を返す。\r
+ * @return 剛体の振る舞い種別\r
+ */\r
+ public RigidBehaviorType getBehaviorType(){\r
+ return this.behaviorType;\r
+ }\r
+\r
+ /**\r
+ * 剛体の振る舞い種別を設定する。\r
+ * @param type 剛体の振る舞い種別。\r
+ * @throws NullPointerException 引数がnull\r
+ */\r
+ public void setBehaviorType(RigidBehaviorType type)\r
+ throws NullPointerException{\r
+ if(type == null) throw new NullPointerException();\r
+ this.behaviorType = type;\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * 剛体形状を返す。\r
+ * @return 剛体形状\r
+ */\r
+ public RigidShape getRigidShape(){\r
+ return this.rigidShape;\r
+ }\r
+\r
+ /**\r
+ * 剛体位置を返す。\r
+ * @return 剛体位置\r
+ */\r
+ public Pos3d getPosition(){\r
+ return this.position;\r
+ }\r
+\r
+ /**\r
+ * 剛体姿勢を返す。\r
+ * @return 剛体姿勢\r
+ */\r
+ public Rad3d getRotation(){\r
+ return this.rotation;\r
+ }\r
+\r
+ /**\r
+ * 接続ボーンを返す。\r
+ * @return 接続ボーン\r
+ */\r
+ public BoneInfo getLinkedBone(){\r
+ return this.linkedBone;\r
+ }\r
+\r
+ /**\r
+ * 接続ボーンを設定する。\r
+ * @param bone 接続ボーン\r
+ */\r
+ public void setLinkedBone(BoneInfo bone){\r
+ this.linkedBone = bone;\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * 剛体の力学パラメータを返す。\r
+ * @return 力学パラメータ\r
+ */\r
+ public DynamicsInfo getDynamicsInfo(){\r
+ return this.dynamicsInfo;\r
+ }\r
+\r
+ /**\r
+ * 非衝突グループ集合を返す。\r
+ * @return 非衝突グループ集合\r
+ */\r
+ public Collection<RigidGroup> getThroughGroupColl(){\r
+ return this.throughGroupColl;\r
+ }\r
+\r
+ /**\r
+ * 所属する剛体グループを返す。\r
+ * @return 所属する剛体グループ\r
+ */\r
+ public RigidGroup getRigidGroup(){\r
+ return this.rigidGroup;\r
+ }\r
+\r
+ /**\r
+ * 所属する剛体グループを設定する。\r
+ * @param group 所属する剛体グループ\r
+ */\r
+ public void setRigidGroup(RigidGroup group){\r
+ this.rigidGroup = group;\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param num {@inheritDoc}\r
+ */\r
+ public void setSerialNumber(int num){\r
+ this.serialNo = num;\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @return {@inheritDoc}\r
+ */\r
+ public int getSerialNumber(){\r
+ return this.serialNo;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @return {@inheritDoc}\r
+ */\r
+ @Override\r
+ public String toString(){\r
+ StringBuilder result = new StringBuilder();\r
+\r
+ result.append("Rigid(").append(this.rigidName).append(") ");\r
+ result.append("[=>")\r
+ .append(this.linkedBone.getBoneName())\r
+ .append("bone]");\r
+ result.append(" [").append(this.rigidShape).append("]");\r
+ result.append(" ").append(this.position);\r
+ result.append(" ").append(this.rotation);\r
+ result.append(" [").append(this.dynamicsInfo).append("]");\r
+ result.append(" [").append(this.behaviorType).append("]");\r
+\r
+ result.append(" through[");\r
+ boolean dumped = false;\r
+ for(RigidGroup group : this.throughGroupColl){\r
+ if(dumped) result.append(" ");\r
+ result.append(group.getGroupNumber());\r
+ dumped = true;\r
+ }\r
+ result.append("]");\r
+\r
+ return result.toString();\r
+ }\r
+\r
+}\r
--- /dev/null
+/*\r
+ * rigid shape information\r
+ *\r
+ * License : The MIT License\r
+ * Copyright(c) 2010 MikuToga Partners\r
+ */\r
+\r
+package jp.sourceforge.mikutoga.pmd;\r
+\r
+/**\r
+ * 剛体形状に関する情報。\r
+ * 球及びカプセルの半径と箱の幅は同じ値が用いられる。\r
+ */\r
+public class RigidShape {\r
+\r
+ private RigidShapeType type = RigidShapeType.BOX;\r
+ private float width = 0.1f;\r
+ private float height = 0.1f;\r
+ private float depth = 0.1f;\r
+\r
+ /**\r
+ * コンストラクタ。\r
+ */\r
+ public RigidShape(){\r
+ super();\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * 剛体形状種別を返す。\r
+ * @return 剛体形状種別\r
+ */\r
+ public RigidShapeType getShapeType(){\r
+ return this.type;\r
+ }\r
+\r
+ /**\r
+ * 剛体形状種別を設定する。\r
+ * @param typeArg 剛体形状種別\r
+ * @throws NullPointerException 引数がnull\r
+ */\r
+ public void setShapeType(RigidShapeType typeArg)\r
+ throws NullPointerException{\r
+ if(typeArg == null) throw new NullPointerException();\r
+ this.type = typeArg;\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * 箱の幅を返す。\r
+ * @return 箱の幅\r
+ */\r
+ public float getWidth(){\r
+ return this.width;\r
+ }\r
+\r
+ /**\r
+ * 箱の幅を設定する。\r
+ * @param width 箱の幅\r
+ */\r
+ public void setWidth(float width){\r
+ this.width = width;\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * 箱及びカプセルの高さを返す。\r
+ * @return 箱及びカプセルの高さ\r
+ */\r
+ public float getHeight(){\r
+ return this.height;\r
+ }\r
+\r
+ /**\r
+ * 箱及びカプセルの高さを設定する。\r
+ * @param height 箱及びカプセルの高さ\r
+ */\r
+ public void setHeight(float height){\r
+ this.height = height;\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * 箱の奥行きを返す。\r
+ * @return 箱の奥行き\r
+ */\r
+ public float getDepth(){\r
+ return this.depth;\r
+ }\r
+\r
+ /**\r
+ * 箱の奥行きを設定する。\r
+ * @param depth 箱の奥行き\r
+ */\r
+ public void setDepth(float depth){\r
+ this.depth = depth;\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * 球及びカプセルの半径を返す。\r
+ * @return 球及びカプセルの半径\r
+ */\r
+ public float getRadius(){\r
+ return this.width;\r
+ }\r
+\r
+ /**\r
+ * 球及びカプセルの半径を設定する。\r
+ * @param radius 球及びカプセルの半径\r
+ */\r
+ public void setRadius(float radius){\r
+ this.width = radius;\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @return {@inheritDoc}\r
+ */\r
+ @Override\r
+ public String toString(){\r
+ StringBuilder result = new StringBuilder();\r
+\r
+ result.append(this.type).append(' ');\r
+\r
+ switch(this.type){\r
+ case SPHERE:\r
+ result.append("r=").append(this.width);\r
+ break;\r
+ case BOX:\r
+ result.append("w=").append(this.width).append(", ");\r
+ result.append("h=").append(this.height).append(", ");\r
+ result.append("d=").append(this.depth);\r
+ break;\r
+ case CAPSULE:\r
+ result.append("r=").append(this.width).append(", ");\r
+ result.append("h=").append(this.height);\r
+ break;\r
+ default:\r
+ assert false;\r
+ throw new AssertionError();\r
+ }\r
+\r
+ return result.toString();\r
+ }\r
+\r
+}\r
--- /dev/null
+/*\r
+ * rigid shape type\r
+ *\r
+ * License : The MIT License\r
+ * Copyright(c) 2010 MikuToga Partners\r
+ */\r
+\r
+package jp.sourceforge.mikutoga.pmd;\r
+\r
+import java.util.Locale;\r
+import java.util.ResourceBundle;\r
+\r
+/**\r
+ * 剛体の形状種別。\r
+ * <ul>\r
+ * <li>0x00:球\r
+ * <li>0x01:箱\r
+ * <li>0x02:カプセル\r
+ * </ul>\r
+ */\r
+public enum RigidShapeType {\r
+\r
+ /** 球。 */\r
+ SPHERE(0x00),\r
+ /** 箱。 */\r
+ BOX(0x01),\r
+ /** カプセル。 */\r
+ CAPSULE(0x02),\r
+ ;\r
+\r
+ private static final String FAMILY_NAME =\r
+ "jp.sourceforge.mikutoga.pmd.resources.RigidShapeTypeName";\r
+\r
+ private final byte encoded;\r
+\r
+ /**\r
+ * コンストラクタ。\r
+ * @param code 符号化int値\r
+ */\r
+ private RigidShapeType(int code){\r
+ this((byte)code);\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * コンストラクタ。\r
+ * @param code 符号化byte値\r
+ */\r
+ private RigidShapeType(byte code){\r
+ this.encoded = code;\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * byte値からデコードする。\r
+ * @param code byte値\r
+ * @return デコードされた列挙子。該当するものがなければnull\r
+ */\r
+ public static RigidShapeType decode(byte code){\r
+ RigidShapeType result = null;\r
+\r
+ for(RigidShapeType type : values()){\r
+ if(type.encode() == code){\r
+ result = type;\r
+ break;\r
+ }\r
+ }\r
+\r
+ return result;\r
+ }\r
+\r
+ /**\r
+ * byte値にエンコードする。\r
+ * @return byte値\r
+ */\r
+ public byte encode(){\r
+ return this.encoded;\r
+ }\r
+\r
+ /**\r
+ * デフォルトロケールでの表示名を返す。\r
+ * @return 表示名\r
+ */\r
+ public String getGuiName(){\r
+ Locale locale = Locale.getDefault();\r
+ return getGuiName(locale);\r
+ }\r
+\r
+ /**\r
+ * ロケールに準じた表示名を返す。\r
+ * @param locale ロケール。nullならデフォルトロケールと解釈される。\r
+ * @return 表示名\r
+ */\r
+ public String getGuiName(Locale locale){\r
+ if(locale == null) return getGuiName();\r
+ ResourceBundle rb = ResourceBundle.getBundle(FAMILY_NAME, locale);\r
+ String key = name();\r
+ String result = rb.getString(key);\r
+ return result;\r
+ }\r
+\r
+}\r
--- /dev/null
+/*\r
+ * shading information\r
+ *\r
+ * License : The MIT License\r
+ * Copyright(c) 2010 MikuToga Partners\r
+ */\r
+\r
+package jp.sourceforge.mikutoga.pmd;\r
+\r
+/**\r
+ * シェーディング情報。\r
+ */\r
+public class ShadeInfo {\r
+\r
+ private ToonMap toonMap = new ToonMap();\r
+ private int toonIdx;\r
+\r
+ private String textureFileName = null;\r
+ private String spheremapFileName = null;\r
+\r
+ /**\r
+ * コンストラクタ。\r
+ */\r
+ public ShadeInfo(){\r
+ super();\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * トゥーンマップを設定する。\r
+ * @param map トゥーンマップ\r
+ */\r
+ public void setToonMap(ToonMap map){\r
+ this.toonMap = map;\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * トゥーンマップを返す。\r
+ * @return トゥーンマップ\r
+ */\r
+ public ToonMap getToonMap(){\r
+ return this.toonMap;\r
+ }\r
+\r
+ /**\r
+ * トゥーンインデックスを設定する。\r
+ * @param idx トゥーンインデックス\r
+ */\r
+ public void setToonIndex(int idx){\r
+ this.toonIdx = idx;\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * トゥーンインデックス値を返す。\r
+ * @return トゥーンインデックス値\r
+ */\r
+ public int getToonIndex(){\r
+ return this.toonIdx;\r
+ }\r
+\r
+ /**\r
+ * トゥーンインデックス値が有効か判定する。\r
+ * 現時点では0から9までの値を有効とする。\r
+ * @return 有効ならtrue\r
+ */\r
+ public boolean isValidToonIndex(){\r
+ if(0 <= this.toonIdx && this.toonIdx <= 9) return true;\r
+ return false;\r
+ }\r
+\r
+ /**\r
+ * トゥーンファイル名を返す。\r
+ * @return トゥーンファイル名\r
+ * @throws IllegalStateException トゥーンマップが設定されていない。\r
+ */\r
+ public String getToonFileName() throws IllegalStateException{\r
+ if(this.toonMap == null) throw new IllegalStateException();\r
+ String result = this.toonMap.getIndexedToon(this.toonIdx);\r
+ return result;\r
+ }\r
+\r
+ /**\r
+ * テクスチャファイル名を設定する。\r
+ * @param fileName テクスチャファイル名\r
+ */\r
+ public void setTextureFileName(String fileName){\r
+ this.textureFileName = fileName;\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * テクスチャファイル名を返す。\r
+ * @return テクスチャファイル名\r
+ */\r
+ public String getTextureFileName(){\r
+ return this.textureFileName;\r
+ }\r
+\r
+ /**\r
+ * スフィアマップファイル名を設定する。\r
+ * @param fileName スフィアマップファイル名\r
+ */\r
+ public void setSpheremapFileName(String fileName){\r
+ this.spheremapFileName = fileName;\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * スフィアマップファイル名を返す。\r
+ * @return スフィアマップファイル名\r
+ */\r
+ public String getSpheremapFileName(){\r
+ return this.spheremapFileName;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @return {@inheritDoc}\r
+ */\r
+ @Override\r
+ public String toString(){\r
+ StringBuilder result = new StringBuilder();\r
+\r
+ result.append("toon(")\r
+ .append(this.toonIdx)\r
+ .append(")=")\r
+ .append(getToonFileName())\r
+ .append(' ');\r
+ result.append("texture=")\r
+ .append(this.textureFileName)\r
+ .append(' ');\r
+ result.append("sphere=")\r
+ .append(this.spheremapFileName);\r
+\r
+ return result.toString();\r
+ }\r
+\r
+}\r
--- /dev/null
+/*\r
+ * triangle surface\r
+ *\r
+ * License : The MIT License\r
+ * Copyright(c) 2010 MikuToga Partners\r
+ */\r
+\r
+package jp.sourceforge.mikutoga.pmd;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Iterator;\r
+import java.util.List;\r
+import jp.sourceforge.mikutoga.corelib.SerialNumbered;\r
+\r
+/**\r
+ * 3頂点の三角形からなる面情報。\r
+ */\r
+public class Surface implements SerialNumbered, Iterable<Vertex> {\r
+\r
+ private Vertex vertex1;\r
+ private Vertex vertex2;\r
+ private Vertex vertex3;\r
+\r
+ private int serialNo = -1;\r
+\r
+ /**\r
+ * コンストラクタ。\r
+ * 3頂点がnullの状態で生成される。\r
+ */\r
+ public Surface(){\r
+ super();\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * 3頂点を設定する。\r
+ * @param vertex1 頂点1\r
+ * @param vertex2 頂点2\r
+ * @param vertex3 頂点3\r
+ * @throws IllegalArgumentException 重複する頂点が引数に含まれた\r
+ */\r
+ public void setTriangle(Vertex vertex1, Vertex vertex2, Vertex vertex3)\r
+ throws IllegalArgumentException{\r
+ if(vertex1 != null && (vertex1 == vertex2 || vertex1 == vertex3)){\r
+ throw new IllegalArgumentException();\r
+ }\r
+ if(vertex2 != null && vertex2 == vertex3){\r
+ throw new IllegalArgumentException();\r
+ }\r
+\r
+ this.vertex1 = vertex1;\r
+ this.vertex2 = vertex2;\r
+ this.vertex3 = vertex3;\r
+\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * 3頂点を返す。\r
+ * @param store 頂点格納用配列。nullもしくは3要素に満たない場合は無視され、\r
+ * 新規に格納用配列が生成される。\r
+ * @return 先頭3要素に3頂点が収められた配列。未設定要素にはnullが入る。\r
+ * 引数が長さ3以上の配列であれば引数と同じ配列が返る。\r
+ */\r
+ public Vertex[] getTriangle(Vertex[] store){\r
+ Vertex[] result;\r
+ if(store == null || store.length < 3){\r
+ result = new Vertex[3];\r
+ }else{\r
+ result = store;\r
+ }\r
+\r
+ result[0] = this.vertex1;\r
+ result[1] = this.vertex2;\r
+ result[2] = this.vertex3;\r
+\r
+ return result;\r
+ }\r
+\r
+ /**\r
+ * 頂点その1を返す。\r
+ * @return 頂点その1\r
+ */\r
+ public Vertex getVertex1(){\r
+ return this.vertex1;\r
+ }\r
+\r
+ /**\r
+ * 頂点その2を返す。\r
+ * @return 頂点その2\r
+ */\r
+ public Vertex getVertex2(){\r
+ return this.vertex2;\r
+ }\r
+\r
+ /**\r
+ * 頂点その3を返す。\r
+ * @return 頂点その3\r
+ */\r
+ public Vertex getVertex3(){\r
+ return this.vertex3;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * 頂点を返す反復子を生成する。\r
+ * 反復子がnullを返す可能性もありうる。\r
+ * @return {@inheritDoc}\r
+ */\r
+ public Iterator<Vertex> iterator(){\r
+ List<Vertex> list = new ArrayList<Vertex>(3);\r
+\r
+ list.add(this.vertex1);\r
+ list.add(this.vertex2);\r
+ list.add(this.vertex3);\r
+\r
+ return list.iterator();\r
+ }\r
+\r
+ /**\r
+ * 3頂点全てが設定されているか判定する。\r
+ * @return 3頂点とも非nullが設定されていればtrue\r
+ */\r
+ public boolean isCompleted(){\r
+ if( this.vertex1 != null\r
+ && this.vertex2 != null\r
+ && this.vertex3 != null ){\r
+ return true;\r
+ }\r
+ return false;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param num {@inheritDoc}\r
+ */\r
+ public void setSerialNumber(int num){\r
+ this.serialNo = num;\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @return {@inheritDoc}\r
+ */\r
+ public int getSerialNumber(){\r
+ return this.serialNo;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @return {@inheritDoc}\r
+ */\r
+ @Override\r
+ public String toString(){\r
+ StringBuilder result = new StringBuilder();\r
+\r
+ result.append("Surface(")\r
+ .append(getSerialNumber())\r
+ .append(")");\r
+\r
+ if(isCompleted()){\r
+ result.append(" VID=[")\r
+ .append(this.vertex1.getSerialNumber())\r
+ .append(',')\r
+ .append(this.vertex2.getSerialNumber())\r
+ .append(',')\r
+ .append(this.vertex3.getSerialNumber())\r
+ .append(']');\r
+ }\r
+\r
+ return result.toString();\r
+ }\r
+\r
+}\r
--- /dev/null
+/*\r
+ * toon file mapping\r
+ *\r
+ * License : The MIT License\r
+ * Copyright(c) 2010 MikuToga Partners\r
+ */\r
+\r
+package jp.sourceforge.mikutoga.pmd;\r
+\r
+import java.util.Collections;\r
+import java.util.Map;\r
+import java.util.TreeMap;\r
+\r
+/**\r
+ * インデックス化されたトゥーンファイル構成。\r
+ * 既存のトゥーンファイル構成と異なるトゥーンファイル名を用いることが可能。\r
+ * <h1>デフォルトのトゥーンファイル構成。</h1>\r
+ * <ul>\r
+ * <li>0x00:toon01.bmp\r
+ * <li>0x01:toon02.bmp\r
+ * <li>.....\r
+ * <li>0x09:toon10.bmp\r
+ * <li>0xff:toon0.bmp\r
+ * </ul>\r
+ */\r
+public class ToonMap {\r
+\r
+ private static final Map<Integer, String> DEF_TOONMAP;\r
+\r
+ static{\r
+ Map<Integer, String> map = new TreeMap<Integer, String>();\r
+\r
+ map.put(0x00, "toon01.bmp");\r
+ map.put(0x01, "toon02.bmp");\r
+ map.put(0x02, "toon03.bmp");\r
+ map.put(0x03, "toon04.bmp");\r
+ map.put(0x04, "toon05.bmp");\r
+ map.put(0x05, "toon06.bmp");\r
+ map.put(0x06, "toon07.bmp");\r
+ map.put(0x07, "toon08.bmp");\r
+ map.put(0x08, "toon09.bmp");\r
+ map.put(0x09, "toon10.bmp");\r
+ map.put(0xff, "toon0.bmp");\r
+\r
+ DEF_TOONMAP = Collections.unmodifiableMap(map);\r
+ }\r
+\r
+ private final Map<Integer, String> toonMap =\r
+ new TreeMap<Integer, String>(DEF_TOONMAP);\r
+\r
+ /**\r
+ * コンストラクタ。\r
+ */\r
+ public ToonMap(){\r
+ super();\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * 指定したインデックス値に対応したトゥーンファイル名を返す。\r
+ * @param idx インデックス値\r
+ * @return トゥーンファイル名。該当するものがなければnull\r
+ */\r
+ public String getIndexedToon(int idx){\r
+ String result = this.toonMap.get(idx);\r
+ return result;\r
+ }\r
+\r
+ /**\r
+ * 指定したインデックス値にトゥーンファイル名を設定する。\r
+ * @param idx インデックス値\r
+ * @param toonFileName トゥーンフィル名\r
+ * @throws NullPointerException トゥーンファイル名がnull\r
+ */\r
+ public void setIndexedToon(int idx, String toonFileName)\r
+ throws NullPointerException{\r
+ if(toonFileName == null) throw new NullPointerException();\r
+ this.toonMap.put(idx, toonFileName);\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * このトゥーンファイル構成がデフォルトのトゥーンファイル構成と等しいか判定する。\r
+ * @return 等しければtrue\r
+ */\r
+ public boolean isDefaultMap(){\r
+ if(this.toonMap.equals(DEF_TOONMAP)) return true;\r
+ return false;\r
+ }\r
+\r
+ /**\r
+ * 指定インデックスのトゥーンファイル名がデフォルトと等しいか判定する。\r
+ * @param idx インデックス\r
+ * @return デフォルトと等しければtrue。\r
+ */\r
+ public boolean isDefaultToon(int idx){\r
+ String thisToon = this.toonMap.get(idx);\r
+ if(thisToon == null) return false;\r
+\r
+ String defToon = DEF_TOONMAP.get(idx);\r
+ if(thisToon.equals(defToon)) return true;\r
+\r
+ return false;\r
+ }\r
+\r
+ /**\r
+ * このトゥーンファイル構成をデフォルト構成内容でリセットする。\r
+ */\r
+ public void resetDefaultMap(){\r
+ this.toonMap.clear();\r
+ this.toonMap.putAll(DEF_TOONMAP);\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * 指定インデックスのトゥーンファイル名をデフォルトのトゥーンファイル名にリセットする。\r
+ * @param idx インデックス値\r
+ */\r
+ public void resetIndexedToon(int idx){\r
+ String toonFile = DEF_TOONMAP.get(idx);\r
+ this.toonMap.put(idx, toonFile);\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @return {@inheritDoc}\r
+ */\r
+ @Override\r
+ public String toString(){\r
+ StringBuilder result = new StringBuilder();\r
+\r
+ boolean dumped = false;\r
+ for(Map.Entry<Integer, String> entry : this.toonMap.entrySet()){\r
+ Integer idx = entry.getKey();\r
+ String toonFile = entry.getValue();\r
+\r
+ if(dumped) result.append(", ");\r
+ result.append('(').append(idx).append(')');\r
+ result.append(toonFile);\r
+ dumped = true;\r
+ }\r
+\r
+ return result.toString();\r
+ }\r
+\r
+}\r
--- /dev/null
+/*\r
+ * triplet-value range limitation\r
+ *\r
+ * License : The MIT License\r
+ * Copyright(c) 2010 MikuToga Partners\r
+ */\r
+\r
+package jp.sourceforge.mikutoga.pmd;\r
+\r
+/**\r
+ * XYZ三組float値の範囲制約。\r
+ */\r
+public class TripletRange {\r
+\r
+ private float xFrom;\r
+ private float xTo;\r
+ private float yFrom;\r
+ private float yTo;\r
+ private float zFrom;\r
+ private float zTo;\r
+\r
+ /**\r
+ * コンストラクタ。\r
+ */\r
+ public TripletRange(){\r
+ super();\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * X値有効範囲を設定する。\r
+ * 下限値が上限値より大きければ入れ替える。\r
+ * @param xFrom X値下限\r
+ * @param xTo X値上限\r
+ */\r
+ public void setXRange(float xFrom, float xTo){\r
+ if(xFrom <= xTo){\r
+ this.xFrom = xFrom;\r
+ this.xTo = xTo;\r
+ }else{\r
+ this.xFrom = xTo;\r
+ this.xTo = xFrom;\r
+ }\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * Y値有効範囲を設定する。\r
+ * 下限値が上限値より大きければ入れ替える。\r
+ * @param yFrom Y値下限\r
+ * @param yTo Y値上限\r
+ */\r
+ public void setYRange(float yFrom, float yTo){\r
+ if(yFrom <= yTo){\r
+ this.yFrom = yFrom;\r
+ this.yTo = yTo;\r
+ }else{\r
+ this.yFrom = yTo;\r
+ this.yTo = yFrom;\r
+ }\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * Z値有効範囲を設定する。\r
+ * 下限値が上限値より大きければ入れ替える。\r
+ * @param zFrom Z値下限\r
+ * @param zTo Z値上限\r
+ */\r
+ public void setZRange(float zFrom, float zTo){\r
+ if(zFrom <= zTo){\r
+ this.zFrom = zFrom;\r
+ this.zTo = zTo;\r
+ }else{\r
+ this.zFrom = zTo;\r
+ this.zTo = zFrom;\r
+ }\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * X値下限を返す。\r
+ * @return X値下限\r
+ */\r
+ public float getXFrom(){\r
+ return this.xFrom;\r
+ }\r
+\r
+ /**\r
+ * X値上限を返す。\r
+ * @return X値上限\r
+ */\r
+ public float getXTo(){\r
+ return this.xTo;\r
+ }\r
+\r
+ /**\r
+ * Y値下限を返す。\r
+ * @return Y値下限\r
+ */\r
+ public float getYFrom(){\r
+ return this.yFrom;\r
+ }\r
+\r
+ /**\r
+ * Y値上限を返す。\r
+ * @return Y値上限\r
+ */\r
+ public float getYTo(){\r
+ return this.yTo;\r
+ }\r
+\r
+ /**\r
+ * Z値下限を返す。\r
+ * @return Z値下限\r
+ */\r
+ public float getZFrom(){\r
+ return this.zFrom;\r
+ }\r
+\r
+ /**\r
+ * Z値上限を返す。\r
+ * @return Z値上限\r
+ */\r
+ public float getZTo(){\r
+ return this.zTo;\r
+ }\r
+\r
+ /**\r
+ * X値が範囲制約を満たすか判定する。\r
+ * @param xVal X値\r
+ * @return 制約を満たすならtrue\r
+ */\r
+ public boolean isValidX(float xVal){\r
+ if(this.xFrom <= xVal && xVal <= this.xTo) return true;\r
+ return false;\r
+ }\r
+\r
+ /**\r
+ * Y値が範囲制約を満たすか判定する。\r
+ * @param yVal Y値\r
+ * @return 制約を満たすならtrue\r
+ */\r
+ public boolean isValidY(float yVal){\r
+ if(this.yFrom <= yVal && yVal <= this.yTo) return true;\r
+ return false;\r
+ }\r
+\r
+ /**\r
+ * Z値が範囲制約を満たすか判定する。\r
+ * @param zVal Z値\r
+ * @return 制約を満たすならtrue\r
+ */\r
+ public boolean isValidZ(float zVal){\r
+ if(this.zFrom <= zVal && zVal <= this.zTo) return true;\r
+ return false;\r
+ }\r
+\r
+ @Override\r
+ public String toString(){\r
+ StringBuilder result = new StringBuilder();\r
+\r
+ result.append("x=[")\r
+ .append(xFrom)\r
+ .append(" - ")\r
+ .append(xTo)\r
+ .append("] ");\r
+ result.append("y=[")\r
+ .append(yFrom)\r
+ .append(" - ")\r
+ .append(yTo)\r
+ .append("] ");\r
+ result.append("z=[")\r
+ .append(zFrom)\r
+ .append(" - ")\r
+ .append(zTo)\r
+ .append("]");\r
+\r
+ return result.toString();\r
+ }\r
+\r
+}\r
--- /dev/null
+/*\r
+ * 3D vector\r
+ *\r
+ * License : The MIT License\r
+ * Copyright(c) 2010 MikuToga Partners\r
+ */\r
+\r
+package jp.sourceforge.mikutoga.pmd;\r
+\r
+/**\r
+ * XYZ三次元ベクトル。\r
+ */\r
+public class Vec3d {\r
+\r
+ private float xVal;\r
+ private float yVal;\r
+ private float zVal;\r
+\r
+ /**\r
+ * コンストラクタ。\r
+ */\r
+ public Vec3d(){\r
+ super();\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * X値を設定する。\r
+ * @param xVal X値\r
+ */\r
+ public void setXVal(float xVal){\r
+ this.xVal = xVal;\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * X値を返す。\r
+ * @return X値\r
+ */\r
+ public float getXVal(){\r
+ return this.xVal;\r
+ }\r
+\r
+ /**\r
+ * Y値を設定する。\r
+ * @param yVal Y値\r
+ */\r
+ public void setYVal(float yVal){\r
+ this.yVal = yVal;\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * Y値を返す。\r
+ * @return Y値\r
+ */\r
+ public float getYVal(){\r
+ return this.yVal;\r
+ }\r
+\r
+ /**\r
+ * Z値を設定する。\r
+ * @param zVal Z値\r
+ */\r
+ public void setZVal(float zVal){\r
+ this.zVal = zVal;\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * Z値を返す。\r
+ * @return Z値\r
+ */\r
+ public float getZVal(){\r
+ return this.zVal;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @return {@inheritDoc}\r
+ */\r
+ @Override\r
+ public String toString(){\r
+ StringBuilder result = new StringBuilder();\r
+\r
+ result.append("vec=[")\r
+ .append(this.xVal).append(", ")\r
+ .append(this.yVal).append(", ")\r
+ .append(this.zVal).append(']');\r
+\r
+ return result.toString();\r
+ }\r
+\r
+}\r
--- /dev/null
+/*\r
+ * vertex information\r
+ *\r
+ * License : The MIT License\r
+ * Copyright(c) 2010 MikuToga Partners\r
+ */\r
+\r
+package jp.sourceforge.mikutoga.pmd;\r
+\r
+import jp.sourceforge.mikutoga.corelib.SerialNumbered;\r
+\r
+/**\r
+ * 頂点情報。\r
+ */\r
+public class Vertex implements SerialNumbered {\r
+\r
+ private static final int MIN_WEIGHT = 0;\r
+ private static final int MAX_WEIGHT = 100;\r
+\r
+ private final Pos3d position = new Pos3d();\r
+ private final Vec3d normal = new Vec3d();\r
+\r
+ private final Pos2d uvPosition = new Pos2d();\r
+\r
+ private BoneInfo boneA = null;\r
+ private BoneInfo boneB = null;\r
+\r
+ private int boneWeight = 50;\r
+\r
+ private boolean edgeAppearance = true;\r
+\r
+ private int serialNo = -1;\r
+\r
+ /**\r
+ * コンストラクタ。\r
+ */\r
+ public Vertex(){\r
+ super();\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * 頂点位置座標を返す。\r
+ * @return 頂点の位置座標\r
+ */\r
+ public Pos3d getPosition(){\r
+ return this.position;\r
+ }\r
+\r
+ /**\r
+ * 法線ベクトルを返す。\r
+ * @return 法線ベクトル\r
+ */\r
+ public Vec3d getNormal(){\r
+ return this.normal;\r
+ }\r
+\r
+ /**\r
+ * UVマップ座標を返す。\r
+ * @return UVマップ情報\r
+ */\r
+ public Pos2d getUVPosition(){\r
+ return this.uvPosition;\r
+ }\r
+\r
+ /**\r
+ * 頂点の属するボーンを設定する。\r
+ * @param boneA ボーンA\r
+ * @param boneB ボーンB\r
+ * @throws NullPointerException 引数がnull\r
+ */\r
+ public void setBonePair(BoneInfo boneA, BoneInfo boneB)\r
+ throws NullPointerException{\r
+ if(boneA == null || boneB == null) throw new NullPointerException();\r
+ this.boneA = boneA;\r
+ this.boneB = boneB;\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * ボーンAを返す。\r
+ * @return ボーンA\r
+ */\r
+ public BoneInfo getBoneA(){\r
+ return this.boneA;\r
+ }\r
+\r
+ /**\r
+ * ボーンBを返す。\r
+ * @return ボーンB\r
+ */\r
+ public BoneInfo getBoneB(){\r
+ return this.boneB;\r
+ }\r
+\r
+ /**\r
+ * ボーンAのウェイト値を設定する。\r
+ * @param weight ウェイト値。0(影響小)-100(影響大)\r
+ * @throws IllegalArgumentException ウェイト値が範囲外\r
+ */\r
+ public void setWeightA(int weight) throws IllegalArgumentException{\r
+ if( weight < MIN_WEIGHT\r
+ || MAX_WEIGHT < weight ){\r
+ throw new IllegalArgumentException();\r
+ }\r
+ this.boneWeight = weight;\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * ボーンBのウェイト値を設定する。\r
+ * @param weight ウェイト値。0(影響小)-100(影響大)\r
+ * @throws IllegalArgumentException ウェイト値が範囲外\r
+ */\r
+ public void setWeightB(int weight) throws IllegalArgumentException{\r
+ setWeightA(MAX_WEIGHT - weight);\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * ボーンAのウェイト値を返す。\r
+ * @return ウェイト値\r
+ */\r
+ public int getWeightA(){\r
+ return this.boneWeight;\r
+ }\r
+\r
+ /**\r
+ * ボーンBのウェイト値を返す。\r
+ * @return ウェイト値\r
+ */\r
+ public int getWeightB(){\r
+ int result = MAX_WEIGHT - this.boneWeight;\r
+ return result;\r
+ }\r
+\r
+ /**\r
+ * ボーンAのウェイト率を返す。\r
+ * @return ウェイト率。0.0(影響小)-1.0(影響大)\r
+ */\r
+ public float getWeightRatioA(){\r
+ return ((float)this.boneWeight) / (float)MAX_WEIGHT;\r
+ }\r
+\r
+ /**\r
+ * ボーンBのウェイト率を返す。\r
+ * @return ウェイト率。0.0(影響小)-1.0(影響大)\r
+ */\r
+ public float getWeightRatioB(){\r
+ return ((float)MAX_WEIGHT - (float)this.boneWeight)\r
+ / (float)MAX_WEIGHT;\r
+ }\r
+\r
+ /**\r
+ * エッジを表示するか設定する。\r
+ * マテリアル材質単位の設定より優先度は高い。\r
+ * @param show 表示するならtrue\r
+ */\r
+ public void setEdgeAppearance(boolean show){\r
+ this.edgeAppearance = show;\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * エッジを表示するか判定する。\r
+ * マテリアル材質単位の設定より優先度は高い。\r
+ * @return 表示するならtrue\r
+ */\r
+ public boolean getEdgeAppearance(){\r
+ return this.edgeAppearance;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param num {@inheritDoc}\r
+ */\r
+ public void setSerialNumber(int num){\r
+ this.serialNo = num;\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @return {@inheritDoc}\r
+ */\r
+ public int getSerialNumber(){\r
+ return this.serialNo;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @return {@inheritDoc}\r
+ */\r
+ @Override\r
+ public String toString(){\r
+ StringBuilder result = new StringBuilder();\r
+\r
+ result.append("Vertex(").append(this.serialNo).append(") ");\r
+ result.append(this.position).append(' ');\r
+ result.append(this.normal).append(' ');\r
+ result.append("UV").append(this.uvPosition).append(' ');\r
+\r
+ result.append("[")\r
+ .append(this.boneA.getBoneName())\r
+ .append("<>")\r
+ .append(this.boneB.getBoneName())\r
+ .append("] ");\r
+\r
+ result.append("weight=").append(this.boneWeight).append(' ');\r
+\r
+ if(this.edgeAppearance) result.append("showEdge");\r
+ else result.append("hideEdge");\r
+\r
+ return result.toString();\r
+ }\r
+\r
+}\r
--- /dev/null
+/*\r
+ * package information for Javadoc\r
+ *\r
+ * License : The MIT License\r
+ * Copyright(c) 2010 MikuToga Partners\r
+ */\r
+\r
+/**\r
+ * PMDモデルファイルに相当するオブジェクト各種。\r
+ */\r
+\r
+package jp.sourceforge.mikutoga.pmd;\r
+\r
+/* EOF */\r
--- /dev/null
+/*\r
+ * abstract exporter\r
+ *\r
+ * License : The MIT License\r
+ * Copyright(c) 2010 MikuToga Partners\r
+ */\r
+\r
+package jp.sourceforge.mikutoga.pmd.pmdexporter;\r
+\r
+import java.io.IOException;\r
+import java.io.OutputStream;\r
+import java.nio.BufferOverflowException;\r
+import java.nio.ByteBuffer;\r
+import java.nio.ByteOrder;\r
+import java.nio.CharBuffer;\r
+import java.nio.charset.Charset;\r
+import java.nio.charset.CharsetEncoder;\r
+import java.nio.charset.CoderResult;\r
+import java.nio.charset.CodingErrorAction;\r
+\r
+/**\r
+ * 抽象化されたエクスポーター共通部。\r
+ */\r
+public abstract class AbstractExporter {\r
+\r
+ private static final Charset CS_WIN31J = Charset.forName("windows-31j");\r
+\r
+ private static final String ERRMSG_TOOLONGTEXT = "too long text";\r
+ private static final String ERRMSG_INVUCSSEQ = "invalid unicode sequence";\r
+ private static final String ERRMSG_NONWIN31J = "no character in win31j";\r
+\r
+ private static final int BYTES_SHORT = Short .SIZE / Byte.SIZE;\r
+ private static final int BYTES_INT = Integer.SIZE / Byte.SIZE;\r
+ private static final int BYTES_FLOAT = Float .SIZE / Byte.SIZE;\r
+\r
+ private static final int BUFSZ_BYTE = 512;\r
+ private static final int BUFSZ_CHAR = 512;\r
+\r
+ private final OutputStream ostream;\r
+\r
+ private final byte[] barray;\r
+ private final ByteBuffer bbuf;\r
+\r
+ private final CharBuffer cbuf;\r
+ private final CharsetEncoder encoder;\r
+\r
+\r
+ /**\r
+ * コンストラクタ。\r
+ * @param stream 出力ストリーム\r
+ * @throws NullPointerException 引数がnull\r
+ */\r
+ protected AbstractExporter(OutputStream stream)\r
+ throws NullPointerException{\r
+ super();\r
+\r
+ if(stream == null) throw new NullPointerException();\r
+ this.ostream = stream;\r
+\r
+ this.barray = new byte[BUFSZ_BYTE];\r
+ this.bbuf = ByteBuffer.wrap(this.barray);\r
+ this.bbuf.order(ByteOrder.LITTLE_ENDIAN);\r
+\r
+ this.cbuf = CharBuffer.allocate(BUFSZ_CHAR);\r
+ this.encoder = CS_WIN31J.newEncoder();\r
+ this.encoder.onMalformedInput(CodingErrorAction.REPORT);\r
+ this.encoder.onUnmappableCharacter(CodingErrorAction.REPORT);\r
+ this.encoder.reset();\r
+\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * 出力をフラッシュする。\r
+ * I/O効率とデバッグ効率のバランスを考え、ご利用は計画的に。\r
+ * @throws IOException 出力エラー\r
+ */\r
+ protected void flush() throws IOException{\r
+ this.ostream.flush();\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * byte値を出力する。\r
+ * @param bVal byte値\r
+ * @throws IOException 出力エラー\r
+ */\r
+ protected void dumpByte(byte bVal) throws IOException{\r
+ this.ostream.write((int)bVal);\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * int値をbyte値で出力する。\r
+ * byte値に収まらない上位ビットはそのまま捨てられる。\r
+ * @param iVal int値\r
+ * @throws IOException 出力エラー\r
+ */\r
+ protected void dumpByte(int iVal) throws IOException{\r
+ dumpByte((byte)iVal);\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * short値を出力する。\r
+ * @param sVal short値\r
+ * @throws IOException 出力エラー\r
+ */\r
+ protected void dumpShort(short sVal) throws IOException{\r
+ this.bbuf.clear();\r
+ this.bbuf.putShort(sVal);\r
+ this.ostream.write(this.barray, 0, BYTES_SHORT);\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * int値をshort値で出力する。\r
+ * short値に収まらない上位ビットはそのまま捨てられる。\r
+ * @param iVal int値\r
+ * @throws IOException 出力エラー\r
+ */\r
+ protected void dumpShort(int iVal) throws IOException{\r
+ dumpShort((short)iVal);\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * int値を出力する。\r
+ * @param iVal int値\r
+ * @throws IOException 出力エラー\r
+ */\r
+ protected void dumpInt(int iVal) throws IOException{\r
+ this.bbuf.clear();\r
+ this.bbuf.putInt(iVal);\r
+ this.ostream.write(this.barray, 0, BYTES_INT);\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * float値を出力する。\r
+ * @param fVal float値\r
+ * @throws IOException 出力エラー\r
+ */\r
+ protected void dumpFloat(float fVal) throws IOException{\r
+ this.bbuf.clear();\r
+ this.bbuf.putFloat(fVal);\r
+ this.ostream.write(this.barray, 0, BYTES_FLOAT);\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * 文字列をwindows-31jエンコーディングで出力する。\r
+ * @param seq 文字列\r
+ * @return 出力されたbyte総数。\r
+ * @throws IOException 出力エラー\r
+ * @throws IllegalPmdTextException 文字エンコーディングに関するエラー\r
+ */\r
+ protected int dumpCharSequence(CharSequence seq)\r
+ throws IOException, IllegalPmdTextException{\r
+ encodeToByteBuffer(seq);\r
+ this.bbuf.flip();\r
+ int length = dumpByteBuffer();\r
+ return length;\r
+ }\r
+\r
+ /**\r
+ * windows-31jにエンコーディングした文字列を内部バッファに蓄積する。\r
+ * @param seq 文字列\r
+ * @throws IllegalPmdTextException 文字エンコーディングに関するエラー。\r
+ * 考えられる状況としては、\r
+ * <ul>\r
+ * <li>入力文字列がUnicodeとしてすでにおかしい。\r
+ * (サロゲートペアがペアになってないなど)\r
+ * <li>windows-31jにない文字をエンコーディングしようとした\r
+ * <li>エンコーディング結果が内部バッファに収まらなかった。\r
+ * </ul>\r
+ * など。\r
+ */\r
+ private void encodeToByteBuffer(CharSequence seq)\r
+ throws IllegalPmdTextException{\r
+ this.cbuf.clear();\r
+ try{\r
+ this.cbuf.append(seq);\r
+ }catch(BufferOverflowException e){\r
+ throw new IllegalPmdTextException(ERRMSG_TOOLONGTEXT);\r
+ }\r
+ this.cbuf.flip();\r
+\r
+ this.bbuf.clear();\r
+\r
+ CoderResult result = this.encoder.encode(this.cbuf, this.bbuf, true);\r
+ if( ! result.isUnderflow()){\r
+ if(result.isOverflow()){\r
+ throw new IllegalPmdTextException(ERRMSG_TOOLONGTEXT);\r
+ }else if(result.isMalformed()){\r
+ throw new IllegalPmdTextException(ERRMSG_INVUCSSEQ);\r
+ }else if(result.isUnmappable()){\r
+ throw new IllegalPmdTextException(ERRMSG_NONWIN31J);\r
+ }else{\r
+ assert false;\r
+ throw new AssertionError();\r
+ }\r
+ }\r
+\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * 内部バッファに蓄積されたbyte値並びを出力する。\r
+ * @return 出力されたbyte数\r
+ * @throws IOException 出力エラー\r
+ */\r
+ private int dumpByteBuffer() throws IOException{\r
+ int offset = this.bbuf.position();\r
+ int limit = this.bbuf.limit();\r
+ int length = limit - offset;\r
+ this.ostream.write(this.barray, offset, length);\r
+\r
+ this.bbuf.position(limit);\r
+\r
+ return length;\r
+ }\r
+\r
+}\r
--- /dev/null
+/*\r
+ * illegal model exception\r
+ *\r
+ * License : The MIT License\r
+ * Copyright(c) 2010 MikuToga Partners\r
+ */\r
+\r
+package jp.sourceforge.mikutoga.pmd.pmdexporter;\r
+\r
+/**\r
+ * モデルデータの不備を発見した場合の例外。\r
+ */\r
+@SuppressWarnings("serial")\r
+public class IllegalPmdException extends Exception{\r
+\r
+ /**\r
+ * コンストラクタ。\r
+ */\r
+ public IllegalPmdException(){\r
+ super();\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * コンストラクタ。\r
+ * @param message メッセージ\r
+ */\r
+ public IllegalPmdException(String message){\r
+ super(message);\r
+ return;\r
+ }\r
+\r
+}\r
--- /dev/null
+/*\r
+ * illegal text in model exception\r
+ *\r
+ * License : The MIT License\r
+ * Copyright(c) 2010 MikuToga Partners\r
+ */\r
+\r
+package jp.sourceforge.mikutoga.pmd.pmdexporter;\r
+\r
+/**\r
+ * 不正なテキスト情報をモデルデータ中に発見した場合の例外。\r
+ * <p>\r
+ * 考えられる理由としては\r
+ * <ul>\r
+ * <li>用意されたフォーマットに対し文字列が長すぎる。\r
+ * <li>文字エンコーディングできない文字が含まれている\r
+ * <li>ユニコード文字列として既に変。\r
+ * </ul>\r
+ * など。\r
+ */\r
+@SuppressWarnings("serial")\r
+public class IllegalPmdTextException extends IllegalPmdException{\r
+\r
+ /**\r
+ * コンストラクタ。\r
+ */\r
+ public IllegalPmdTextException(){\r
+ super();\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * コンストラクタ。\r
+ * @param message メッセージ\r
+ */\r
+ public IllegalPmdTextException(String message){\r
+ super(message);\r
+ return;\r
+ }\r
+\r
+}\r
--- /dev/null
+/*\r
+ * model exporter for pmd-file(up to date)\r
+ *\r
+ * License : The MIT License\r
+ * Copyright(c) 2010 MikuToga Partners\r
+ */\r
+\r
+package jp.sourceforge.mikutoga.pmd.pmdexporter;\r
+\r
+import java.io.OutputStream;\r
+\r
+/**\r
+ * 最新仕様のPMDファイルエクスポーター。\r
+ * 将来のリリースにおいて、\r
+ * 常に最新のPMDモデルファイルフォーマットに対応したエクスポーターの\r
+ * 別名であることが保証される。つもり。\r
+ */\r
+public class PmdExporter extends PmdExporterExt3{\r
+\r
+ /**\r
+ * コンストラクタ。\r
+ * @param stream 出力ストリーム\r
+ * @throws NullPointerException 引数がnull\r
+ */\r
+ public PmdExporter(OutputStream stream) throws NullPointerException{\r
+ super(stream);\r
+ return;\r
+ }\r
+\r
+}\r
--- /dev/null
+/*\r
+ * model exporter for pmd-file\r
+ *\r
+ * License : The MIT License\r
+ * Copyright(c) 2010 MikuToga Partners\r
+ */\r
+\r
+package jp.sourceforge.mikutoga.pmd.pmdexporter;\r
+\r
+import java.awt.Color;\r
+import java.io.IOException;\r
+import java.io.OutputStream;\r
+import java.util.Collections;\r
+import java.util.LinkedList;\r
+import java.util.List;\r
+import java.util.Map;\r
+import java.util.Set;\r
+import jp.sourceforge.mikutoga.corelib.SerialNumbered;\r
+import jp.sourceforge.mikutoga.parser.pmd.PmdLimits;\r
+import jp.sourceforge.mikutoga.pmd.BoneGroup;\r
+import jp.sourceforge.mikutoga.pmd.BoneInfo;\r
+import jp.sourceforge.mikutoga.pmd.BoneType;\r
+import jp.sourceforge.mikutoga.pmd.IKChain;\r
+import jp.sourceforge.mikutoga.pmd.Material;\r
+import jp.sourceforge.mikutoga.pmd.MorphPart;\r
+import jp.sourceforge.mikutoga.pmd.MorphType;\r
+import jp.sourceforge.mikutoga.pmd.MorphVertex;\r
+import jp.sourceforge.mikutoga.pmd.PmdModel;\r
+import jp.sourceforge.mikutoga.pmd.Pos2d;\r
+import jp.sourceforge.mikutoga.pmd.Pos3d;\r
+import jp.sourceforge.mikutoga.pmd.ShadeInfo;\r
+import jp.sourceforge.mikutoga.pmd.Surface;\r
+import jp.sourceforge.mikutoga.pmd.Vec3d;\r
+import jp.sourceforge.mikutoga.pmd.Vertex;\r
+\r
+/**\r
+ * PMDファイルのエクスポーター(拡張無し基本フォーマット)。\r
+ * <p>\r
+ * 英名対応以降のPMDファイルフォーマットを\r
+ * 使いたくない場合はこのエクスポーターを用いて出力せよ。\r
+ */\r
+public class PmdExporterBase extends AbstractExporter{\r
+\r
+ /** 前(親)ボーンが無い場合の便宜的なボーンID。 */\r
+ public static final int NOPREVBONE_ID = 0xffff;\r
+ /** 次(子)ボーンが無い場合の便宜的なボーンID。 */\r
+ public static final int NONEXTBONE_ID = 0x0000;\r
+ /** 影響元IKボーンが無い場合の便宜的なボーンID。 */\r
+ public static final int NOIKBONE_ID = 0x0000;\r
+\r
+ private static final String MAGIC = "Pmd";\r
+\r
+ private static final byte[] NULLFILLER =\r
+ { (byte)0x00 };\r
+ private static final byte[] FDFILLER =\r
+ { (byte)0x00, (byte)0xfd };\r
+ private static final byte[] LFFILLER =\r
+ { (byte)0x0a, (byte)0x00, (byte)0xfd };\r
+\r
+ /** 改行文字列 CR。 */\r
+ private static final String CR = "\r"; // 0x0d\r
+ /** 改行文字列 LF。 */\r
+ private static final String LF = "\n"; // 0x0a\r
+ /** 改行文字列 CRLF。 */\r
+ private static final String CRLF = CR + LF; // 0x0d, 0x0a\r
+\r
+ static{\r
+ assert NOPREVBONE_ID > PmdLimits.MAX_BONE - 1;\r
+ }\r
+\r
+ /**\r
+ * コンストラクタ。\r
+ * @param stream 出力ストリーム\r
+ * @throws NullPointerException 引数がnull\r
+ */\r
+ public PmdExporterBase(OutputStream stream)\r
+ throws NullPointerException{\r
+ super(stream);\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * 改行文字の正規化を行う。\r
+ * CR(0x0d)およびCRLF(0x0d0a)がLF(0x0a)へと正規化される。\r
+ * @param text 文字列\r
+ * @return 正規化の行われた文字列。\r
+ */\r
+ protected static String normalizeBreak(String text){\r
+ String result = text;\r
+\r
+ result = result.replace(CRLF, LF);\r
+ result = result.replace(CR, LF);\r
+\r
+ return result;\r
+ }\r
+\r
+ /**\r
+ * 文字列を指定されたバイト長で出力する。\r
+ * 文字列の改行記号はLF(0x0a)に正規化される。\r
+ * エンコード結果がバイト長に満たない場合は\r
+ * 1つの0x00及びそれに続く複数の0xfdがパディングされる。\r
+ * @param text 文字列\r
+ * @param maxByteLength バイト長指定\r
+ * @throws IOException 出力エラー\r
+ * @throws IllegalPmdTextException エンコード結果が\r
+ * 指定バイト長をはみ出した。\r
+ */\r
+ protected void dumpText(String text, int maxByteLength)\r
+ throws IOException, IllegalPmdTextException{\r
+ dumpText(text, maxByteLength, FDFILLER);\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * 文字列を指定されたバイト長で出力する。\r
+ * 文字列の改行記号はLF(0x0a)に正規化される。\r
+ * エンコード結果がバイト長に満たない場合は\r
+ * fillerがパディングされる。\r
+ * @param text 文字列\r
+ * @param maxByteLength バイト超指定\r
+ * @param filler 出力結果が足りない場合の詰め物。\r
+ * それでも足りない場合は最後のbyte要素が繰り返し出力される。\r
+ * @throws IOException 出力エラー\r
+ * @throws IllegalPmdTextException エンコード結果が\r
+ * 指定バイト長をはみ出した\r
+ */\r
+ protected void dumpText(String text, int maxByteLength, byte[] filler)\r
+ throws IOException, IllegalPmdTextException{\r
+ String normalized = normalizeBreak(text);\r
+ int blen = dumpCharSequence(normalized);\r
+ int remain = maxByteLength - blen;\r
+\r
+ if(remain < 0) throw new IllegalPmdTextException("too long text");\r
+\r
+ int fillerIdx = 0;\r
+ while(remain > 0){\r
+ if(fillerIdx >= filler.length){\r
+ fillerIdx = filler.length - 1;\r
+ }\r
+ dumpByte(filler[fillerIdx]);\r
+ fillerIdx++;\r
+ remain--;\r
+ }\r
+\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * モデルデータをPMDファイル形式で出力する。\r
+ * @param model モデルデータ\r
+ * @throws IOException 出力エラー\r
+ * @throws IllegalPmdException モデルデータに不備が発見された\r
+ */\r
+ public void dumpPmdModel(PmdModel model)\r
+ throws IOException, IllegalPmdException{\r
+ dumpBasic(model);\r
+ dumpVertexList(model);\r
+ dumpSurfaceList(model);\r
+ dumpMaterialList(model);\r
+ dumpBoneList(model);\r
+ dumpIKChainList(model);\r
+ dumpMorphList(model);\r
+ dumpMorphGroup(model);\r
+ dumpBoneGroupList(model);\r
+\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * モデル基本情報を出力する。\r
+ * @param model モデルデータ\r
+ * @throws IOException 出力エラー\r
+ * @throws IllegalPmdTextException モデル名もしくは説明が長すぎる\r
+ */\r
+ private void dumpBasic(PmdModel model)\r
+ throws IOException, IllegalPmdTextException{\r
+ dumpCharSequence(MAGIC);\r
+ float ver = model.getHeaderVersion();\r
+ dumpFloat(ver);\r
+\r
+ String modelName = model.getModelName() .getPrimaryText();\r
+ String description = model.getDescription().getPrimaryText();\r
+\r
+ dumpText(modelName, PmdLimits.MAXBYTES_MODELNAME);\r
+ dumpText(description, PmdLimits.MAXBYTES_MODELDESC);\r
+\r
+ flush();\r
+\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * 頂点リストを出力する。\r
+ * @param model モデルデータ\r
+ * @throws IOException 出力エラー\r
+ */\r
+ private void dumpVertexList(PmdModel model)\r
+ throws IOException{\r
+ List<Vertex> vList = model.getVertexList();\r
+\r
+ int vertexNum = vList.size();\r
+ dumpInt(vertexNum);\r
+\r
+ for(Vertex vertex : vList){\r
+ dumpVertex(vertex);\r
+ }\r
+\r
+ flush();\r
+\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * 個別の頂点データを出力する。\r
+ * @param vertex 頂点\r
+ * @throws IOException 出力エラー\r
+ */\r
+ private void dumpVertex(Vertex vertex)\r
+ throws IOException{\r
+ Pos3d position = vertex.getPosition();\r
+ dumpPos3d(position);\r
+\r
+ Vec3d normal = vertex.getNormal();\r
+ dumpVec3d(normal);\r
+\r
+ Pos2d uv = vertex.getUVPosition();\r
+ dumpPos2d(uv);\r
+\r
+ BoneInfo boneA = vertex.getBoneA();\r
+ BoneInfo boneB = vertex.getBoneB();\r
+ dumpSerialIdAsShort(boneA);\r
+ dumpSerialIdAsShort(boneB);\r
+\r
+ int weight = vertex.getWeightA();\r
+ dumpByte((byte)weight);\r
+\r
+ byte edgeFlag;\r
+ boolean hasEdge = vertex.getEdgeAppearance();\r
+ if(hasEdge) edgeFlag = 0x00;\r
+ else edgeFlag = 0x01;\r
+ dumpByte(edgeFlag);\r
+\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * 面リストを出力する。\r
+ * @param model モデルデータ\r
+ * @throws IOException 出力エラー\r
+ */\r
+ private void dumpSurfaceList(PmdModel model)\r
+ throws IOException{\r
+ int surfaceNum = 0;\r
+ List<Material> materialList = model.getMaterialList();\r
+ for(Material material : materialList){\r
+ surfaceNum += material.getSurfaceList().size();\r
+ }\r
+ dumpInt(surfaceNum * 3);\r
+\r
+ Vertex[] triangle = new Vertex[3];\r
+ for(Material material : materialList){\r
+ for(Surface surface : material){\r
+ surface.getTriangle(triangle);\r
+ dumpShort(triangle[0].getSerialNumber());\r
+ dumpShort(triangle[1].getSerialNumber());\r
+ dumpShort(triangle[2].getSerialNumber());\r
+ }\r
+ }\r
+\r
+ flush();\r
+\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * マテリアル素材リストを出力する。\r
+ * @param model モデルデータ\r
+ * @throws IOException 出力エラー\r
+ * @throws IllegalPmdTextException シェーディングファイル情報が長すぎる\r
+ */\r
+ private void dumpMaterialList(PmdModel model)\r
+ throws IOException, IllegalPmdTextException{\r
+ List<Material> materialList = model.getMaterialList();\r
+\r
+ int materialNum = materialList.size();\r
+ dumpInt(materialNum);\r
+\r
+ float[] rgba = new float[4];\r
+\r
+ for(Material material : materialList){\r
+ Color diffuse = material.getDiffuseColor();\r
+ diffuse.getRGBComponents(rgba);\r
+ dumpFloat(rgba[0]);\r
+ dumpFloat(rgba[1]);\r
+ dumpFloat(rgba[2]);\r
+ dumpFloat(rgba[3]);\r
+\r
+ float shininess = material.getShininess();\r
+ dumpFloat(shininess);\r
+\r
+ Color specular = material.getSpecularColor();\r
+ specular.getRGBComponents(rgba);\r
+ dumpFloat(rgba[0]);\r
+ dumpFloat(rgba[1]);\r
+ dumpFloat(rgba[2]);\r
+\r
+ Color ambient = material.getAmbientColor();\r
+ ambient.getRGBComponents(rgba);\r
+ dumpFloat(rgba[0]);\r
+ dumpFloat(rgba[1]);\r
+ dumpFloat(rgba[2]);\r
+\r
+ ShadeInfo shade = material.getShadeInfo();\r
+ int toonIdx = shade.getToonIndex();\r
+ dumpByte(toonIdx);\r
+\r
+ byte edgeFlag;\r
+ boolean showEdge = material.getEdgeAppearance();\r
+ if(showEdge) edgeFlag = 0x01;\r
+ else edgeFlag = 0x00;\r
+ dumpByte(edgeFlag);\r
+\r
+ int surfaceNum = material.getSurfaceList().size();\r
+ dumpInt(surfaceNum * 3);\r
+\r
+ dumpShadeFileInfo(shade);\r
+ }\r
+\r
+ flush();\r
+\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * シェーディングファイル情報を出力する。\r
+ * @param shade シェーディング情報\r
+ * @throws IOException 出力エラー\r
+ * @throws IllegalPmdTextException ファイル名が長すぎる\r
+ */\r
+ private void dumpShadeFileInfo(ShadeInfo shade)\r
+ throws IOException, IllegalPmdTextException{\r
+ String textureFile = shade.getTextureFileName();\r
+ String spheremapFile = shade.getSpheremapFileName();\r
+\r
+ StringBuilder text = new StringBuilder();\r
+ if(textureFile != null) text.append(textureFile);\r
+ if(spheremapFile != null && spheremapFile.length() > 0){\r
+ text.append('*')\r
+ .append(spheremapFile);\r
+ }\r
+\r
+ byte[] filler;\r
+ if(text.length() <= 0) filler = NULLFILLER;\r
+ else filler = FDFILLER;\r
+\r
+ dumpText(text.toString(),\r
+ PmdLimits.MAXBYTES_TEXTUREFILENAME,\r
+ filler );\r
+\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * ボーンリストを出力する。\r
+ * @param model モデルデータ\r
+ * @throws IOException 出力エラー\r
+ * @throws IllegalPmdTextException ボーン名が長すぎる\r
+ */\r
+ private void dumpBoneList(PmdModel model)\r
+ throws IOException, IllegalPmdTextException{\r
+ List<BoneInfo> boneList = model.getBoneList();\r
+\r
+ int boneNum = boneList.size();\r
+ dumpShort(boneNum);\r
+\r
+ for(BoneInfo bone : boneList){\r
+ dumpBone(bone);\r
+ }\r
+\r
+ flush();\r
+\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * 個別のボーン情報を出力する。\r
+ * @param bone ボーン情報\r
+ * @throws IOException 出力エラー\r
+ * @throws IllegalPmdTextException ボーン名が長すぎる\r
+ */\r
+ private void dumpBone(BoneInfo bone)\r
+ throws IOException, IllegalPmdTextException{\r
+ String boneName = bone.getBoneName().getPrimaryText();\r
+ dumpText(boneName, PmdLimits.MAXBYTES_BONENAME);\r
+\r
+ BoneInfo prev = bone.getPrevBone();\r
+ if(prev != null) dumpSerialIdAsShort(prev);\r
+ else dumpShort(NOPREVBONE_ID);\r
+\r
+ BoneInfo next = bone.getNextBone();\r
+ if(next != null) dumpSerialIdAsShort(next);\r
+ else dumpShort(NONEXTBONE_ID);\r
+\r
+ BoneType type = bone.getBoneType();\r
+ dumpByte(type.encode());\r
+\r
+ if(type == BoneType.LINKEDROT){\r
+ int ratio = bone.getRotationRatio();\r
+ dumpShort(ratio);\r
+ }else{\r
+ BoneInfo ik = bone.getIKBone();\r
+ if(ik != null) dumpSerialIdAsShort(ik);\r
+ else dumpShort(NOIKBONE_ID);\r
+ }\r
+\r
+ Pos3d position = bone.getPosition();\r
+ dumpPos3d(position);\r
+\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * IKチェーンリストを出力する。\r
+ * @param model モデルデータ\r
+ * @throws IOException 出力エラー\r
+ */\r
+ private void dumpIKChainList(PmdModel model)\r
+ throws IOException{\r
+ List<IKChain> ikChainList = model.getIKChainList();\r
+\r
+ int ikNum = ikChainList.size();\r
+ dumpShort(ikNum);\r
+\r
+ for(IKChain chain : ikChainList){\r
+ dumpIKChain(chain);\r
+ }\r
+\r
+ flush();\r
+\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * IKチェーンを出力する。\r
+ * @param chain IKチェーン\r
+ * @throws IOException 出力エラー\r
+ */\r
+ // TODO ボーンリストから自動抽出できる情報ではないのか?\r
+ private void dumpIKChain(IKChain chain)\r
+ throws IOException{\r
+ BoneInfo ikBone = chain.getIkBone();\r
+ dumpSerialIdAsShort(ikBone);\r
+\r
+ List<BoneInfo> boneList = chain.getChainedBoneList();\r
+\r
+ BoneInfo bone1st = boneList.get(0);\r
+ dumpSerialIdAsShort(bone1st);\r
+\r
+ int boneNum = boneList.size();\r
+ dumpByte(boneNum - 1);\r
+\r
+ int depth = chain.getIKDepth();\r
+ float weight = chain.getIKWeight();\r
+\r
+ dumpShort(depth);\r
+ dumpFloat(weight);\r
+\r
+ for(int idx = 1; idx < boneNum; idx++){ // リストの2番目以降全て\r
+ BoneInfo bone = boneList.get(idx);\r
+ dumpSerialIdAsShort(bone);\r
+ }\r
+\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * モーフリストを出力する。\r
+ * @param model モデルデータ\r
+ * @throws IOException 出力エラー\r
+ * @throws IllegalPmdTextException モーフ名が長すぎる\r
+ */\r
+ private void dumpMorphList(PmdModel model)\r
+ throws IOException, IllegalPmdTextException{\r
+ Map<MorphType, List<MorphPart>> morphMap = model.getMorphMap();\r
+ Set<MorphType> typeSet = morphMap.keySet();\r
+ List<MorphVertex> mergedMorphVertexList = model.mergeMorphVertex();\r
+\r
+ int totalMorphPart = 0;\r
+ for(MorphType type : typeSet){\r
+ List<MorphPart> partList = morphMap.get(type);\r
+ if(partList == null) continue;\r
+ totalMorphPart += partList.size();\r
+ }\r
+\r
+ if(totalMorphPart <= 0){\r
+ dumpShort(0);\r
+ return;\r
+ }else{\r
+ totalMorphPart++; // baseの分\r
+ dumpShort(totalMorphPart);\r
+ }\r
+\r
+ dumpText("base", PmdLimits.MAXBYTES_MORPHNAME);\r
+ int totalVertex = mergedMorphVertexList.size();\r
+ dumpInt(totalVertex);\r
+ dumpByte(MorphType.BASE.encode());\r
+ for(MorphVertex morphVertex : mergedMorphVertexList){\r
+ Vertex baseVertex = morphVertex.getBaseVertex();\r
+ dumpInt(baseVertex.getSerialNumber());\r
+ dumpPos3d(baseVertex.getPosition());\r
+ }\r
+\r
+ for(MorphType type : typeSet){\r
+ List<MorphPart> partList = morphMap.get(type);\r
+ if(partList == null) continue;\r
+ for(MorphPart part : partList){\r
+ dumpText(part.getMorphName().getPrimaryText(),\r
+ PmdLimits.MAXBYTES_MORPHNAME );\r
+ List<MorphVertex> morphVertexList = part.getMorphVertexList();\r
+ dumpInt(morphVertexList.size());\r
+ dumpByte(part.getMorphType().encode());\r
+\r
+ for(MorphVertex morphVertex : morphVertexList){\r
+ dumpInt(morphVertex.getSerialNumber());\r
+ dumpPos3d(morphVertex.getOffset());\r
+ }\r
+ }\r
+ }\r
+\r
+ flush();\r
+\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * モーフグループを出力する。\r
+ * @param model モデルデータ\r
+ * @throws IOException 出力エラー\r
+ */\r
+ private void dumpMorphGroup(PmdModel model)\r
+ throws IOException{\r
+ Map<MorphType, List<MorphPart>> morphMap = model.getMorphMap();\r
+ Set<MorphType> typeSet = morphMap.keySet();\r
+\r
+ int totalMorph = 0;\r
+ for(MorphType type : typeSet){\r
+ List<MorphPart> partList = morphMap.get(type);\r
+ if(partList == null) continue;\r
+ totalMorph += partList.size();\r
+ }\r
+ dumpByte(totalMorph);\r
+\r
+ List<MorphType> typeList = new LinkedList<MorphType>();\r
+ for(MorphType type : typeSet){\r
+ assert ! type.isBase();\r
+ typeList.add(type);\r
+ }\r
+ Collections.reverse(typeList); // 一応本家と互換性を\r
+\r
+ for(MorphType type : typeList){\r
+ List<MorphPart> partList = morphMap.get(type);\r
+ if(partList == null) continue;\r
+ for(MorphPart part : partList){\r
+ dumpSerialIdAsShort(part);\r
+ }\r
+ }\r
+\r
+ flush();\r
+\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * ボーングループリストを出力する。\r
+ * デフォルトボーングループ内訳は出力されない。\r
+ * @param model モデルデータ\r
+ * @throws IOException 出力エラー\r
+ * @throws IllegalPmdTextException ボーングループ名が長すぎる\r
+ */\r
+ private void dumpBoneGroupList(PmdModel model)\r
+ throws IOException, IllegalPmdTextException{\r
+ List<BoneGroup> groupList = model.getBoneGroupList();\r
+ int groupNum = groupList.size();\r
+ dumpByte(groupNum - 1);\r
+\r
+ int dispBoneNum = 0;\r
+ for(BoneGroup group : groupList){\r
+ if(group.isDefaultBoneGroup()) continue;\r
+ dumpText(group.getGroupName().getPrimaryText(),\r
+ PmdLimits.MAXBYTES_BONEGROUPNAME, LFFILLER );\r
+ dispBoneNum += group.getBoneList().size();\r
+ }\r
+ dumpInt(dispBoneNum);\r
+\r
+ for(BoneGroup group : groupList){\r
+ if(group.isDefaultBoneGroup()) continue;\r
+ for(BoneInfo bone : group){\r
+ dumpSerialIdAsShort(bone);\r
+ int groupId = group.getSerialNumber();\r
+ dumpByte(groupId);\r
+ }\r
+ }\r
+\r
+ flush();\r
+\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * 各種通し番号をshort値で出力する。\r
+ * short値に収まらない上位ビットは捨てられる。\r
+ * @param obj 番号づけられたオブジェクト\r
+ * @throws IOException 出力エラー\r
+ */\r
+ protected void dumpSerialIdAsShort(SerialNumbered obj)\r
+ throws IOException{\r
+ int serialId = obj.getSerialNumber();\r
+ dumpShort(serialId);\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * 2次元位置情報を出力する。\r
+ * @param position 2次元位置情報\r
+ * @throws IOException 出力エラー\r
+ */\r
+ protected void dumpPos2d(Pos2d position) throws IOException{\r
+ float xPos = position.getXPos();\r
+ float yPos = position.getYPos();\r
+\r
+ dumpFloat(xPos);\r
+ dumpFloat(yPos);\r
+\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * 3次元位置情報を出力する。\r
+ * @param position 3次元位置情報\r
+ * @throws IOException 出力エラー\r
+ */\r
+ protected void dumpPos3d(Pos3d position) throws IOException{\r
+ float xPos = position.getXPos();\r
+ float yPos = position.getYPos();\r
+ float zPos = position.getZPos();\r
+\r
+ dumpFloat(xPos);\r
+ dumpFloat(yPos);\r
+ dumpFloat(zPos);\r
+\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * 3次元ベクトル情報を出力する。\r
+ * @param vector 3次元ベクトル\r
+ * @throws IOException 出力エラー\r
+ */\r
+ protected void dumpVec3d(Vec3d vector) throws IOException{\r
+ float xVal = vector.getXVal();\r
+ float yVal = vector.getYVal();\r
+ float zVal = vector.getZVal();\r
+\r
+ dumpFloat(xVal);\r
+ dumpFloat(yVal);\r
+ dumpFloat(zVal);\r
+\r
+ return;\r
+ }\r
+\r
+}\r
--- /dev/null
+/*\r
+ * model exporter for pmd-file(Ext1)\r
+ *\r
+ * License : The MIT License\r
+ * Copyright(c) 2010 MikuToga Partners\r
+ */\r
+\r
+package jp.sourceforge.mikutoga.pmd.pmdexporter;\r
+\r
+import java.io.IOException;\r
+import java.io.OutputStream;\r
+import java.util.List;\r
+import java.util.Map;\r
+import jp.sourceforge.mikutoga.parser.pmd.PmdLimits;\r
+import jp.sourceforge.mikutoga.pmd.BoneGroup;\r
+import jp.sourceforge.mikutoga.pmd.BoneInfo;\r
+import jp.sourceforge.mikutoga.pmd.MorphPart;\r
+import jp.sourceforge.mikutoga.pmd.MorphType;\r
+import jp.sourceforge.mikutoga.pmd.PmdModel;\r
+\r
+/**\r
+ * PMDファイルのエクスポーター(拡張1:英名対応)。\r
+ * <p>\r
+ * 任意のトゥーンファイル名対応以降のPMDファイルフォーマットを\r
+ * 使いたくない場合はこのエクスポーターを用いて出力せよ。\r
+ */\r
+public class PmdExporterExt1 extends PmdExporterBase{\r
+\r
+ /**\r
+ * コンストラクタ。\r
+ * @param stream 出力ストリーム\r
+ * @throws NullPointerException 引数がnull\r
+ */\r
+ public PmdExporterExt1(OutputStream stream)\r
+ throws NullPointerException{\r
+ super(stream);\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param model {@inheritDoc}\r
+ * @throws IOException {@inheritDoc}\r
+ * @throws IllegalPmdException {@inheritDoc}\r
+ */\r
+ @Override\r
+ public void dumpPmdModel(PmdModel model)\r
+ throws IOException, IllegalPmdException{\r
+ super.dumpPmdModel(model);\r
+\r
+ dumpGlobalInfo(model);\r
+\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * 英語名情報を出力する。\r
+ * @param model モデルデータ\r
+ * @throws IOException 出力エラー\r
+ * @throws IllegalPmdTextException 文字列が長すぎる。\r
+ */\r
+ private void dumpGlobalInfo(PmdModel model)\r
+ throws IOException, IllegalPmdTextException{\r
+ boolean hasGlobal = model.hasGlobalText();\r
+ byte globalFlag;\r
+ if(hasGlobal) globalFlag = 0x01;\r
+ else globalFlag = 0x00;\r
+ dumpByte(globalFlag);\r
+\r
+ if(hasGlobal){\r
+ dumpBasicGlobal(model);\r
+ dumpBoneGlobal(model);\r
+ dumpMorphGlobal(model);\r
+ dumpBoneGroupGlobal(model);\r
+ }\r
+\r
+ flush();\r
+\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * モデル基本情報を英語で出力する。\r
+ * @param model モデルデータ\r
+ * @throws IOException 出力エラー\r
+ * @throws IllegalPmdTextException 文字列が長すぎる。\r
+ */\r
+ private void dumpBasicGlobal(PmdModel model)\r
+ throws IOException, IllegalPmdTextException{\r
+ String modelName = model.getModelName().getGlobalText();\r
+ if(modelName == null) modelName = "";\r
+ dumpText(modelName, PmdLimits.MAXBYTES_MODELNAME);\r
+\r
+ String description = model.getDescription().getGlobalText();\r
+ if(description == null) description = "";\r
+ dumpText(description, PmdLimits.MAXBYTES_MODELDESC);\r
+\r
+ flush();\r
+ }\r
+\r
+ /**\r
+ * ボーン英語名情報を出力する。\r
+ * @param model モデルデータ\r
+ * @throws IOException 出力エラー\r
+ * @throws IllegalPmdTextException 文字列が長すぎる。\r
+ */\r
+ private void dumpBoneGlobal(PmdModel model)\r
+ throws IOException, IllegalPmdTextException{\r
+ for(BoneInfo bone : model.getBoneList()){\r
+ String boneName = bone.getBoneName().getGlobalText();\r
+ if(boneName == null) boneName = "";\r
+ dumpText(boneName, PmdLimits.MAXBYTES_BONENAME);\r
+ }\r
+\r
+ flush();\r
+ }\r
+\r
+ /**\r
+ * モーフ英語名情報を出力する。\r
+ * @param model モデルデータ\r
+ * @throws IOException 出力エラー\r
+ * @throws IllegalPmdTextException 文字列が長すぎる。\r
+ */\r
+ private void dumpMorphGlobal(PmdModel model)\r
+ throws IOException, IllegalPmdTextException{\r
+ Map<MorphType, List<MorphPart>> morphMap = model.getMorphMap();\r
+\r
+ for(MorphType type : MorphType.values()){\r
+ if(type.isBase()) continue;\r
+ List<MorphPart> partList = morphMap.get(type);\r
+ if(partList == null) continue;\r
+ for(MorphPart part : partList){\r
+ String morphName = part.getMorphName().getGlobalText();\r
+ if(morphName == null) morphName = "";\r
+ dumpText(morphName, PmdLimits.MAXBYTES_MORPHNAME);\r
+ }\r
+ }\r
+\r
+ flush();\r
+ }\r
+\r
+ /**\r
+ * ボーングループ英語名情報を出力する。\r
+ * @param model モデルデータ\r
+ * @throws IOException 出力エラー\r
+ * @throws IllegalPmdTextException 文字列が長すぎる\r
+ */\r
+ private void dumpBoneGroupGlobal(PmdModel model)\r
+ throws IOException, IllegalPmdTextException{\r
+ for(BoneGroup group : model.getBoneGroupList()){\r
+ if(group.isDefaultBoneGroup()) continue;\r
+ String groupName = group.getGroupName().getGlobalText();\r
+ if(groupName == null) groupName = "";\r
+ dumpText(groupName, PmdLimits.MAXBYTES_BONEGROUPNAME);\r
+ }\r
+\r
+ flush();\r
+ }\r
+\r
+}\r
--- /dev/null
+/*\r
+ * model exporter for pmd-file(Ext2)\r
+ *\r
+ * License : The MIT License\r
+ * Copyright(c) 2010 MikuToga Partners\r
+ */\r
+\r
+package jp.sourceforge.mikutoga.pmd.pmdexporter;\r
+\r
+import java.io.IOException;\r
+import java.io.OutputStream;\r
+import jp.sourceforge.mikutoga.parser.pmd.PmdLimits;\r
+import jp.sourceforge.mikutoga.pmd.PmdModel;\r
+import jp.sourceforge.mikutoga.pmd.ToonMap;\r
+\r
+/**\r
+ * PMDファイルのエクスポーター(拡張2:任意のトゥーンファイル名対応)。\r
+ * <p>\r
+ * 物理演算対応以降のPMDファイルフォーマットを\r
+ * 使いたくない場合はこのエクスポーターを用いて出力せよ。\r
+ */\r
+public class PmdExporterExt2 extends PmdExporterExt1{\r
+\r
+ /**\r
+ * コンストラクタ。\r
+ * @param stream 出力ストリーム\r
+ * @throws NullPointerException 引数がnull\r
+ */\r
+ public PmdExporterExt2(OutputStream stream)\r
+ throws NullPointerException{\r
+ super(stream);\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param model {@inheritDoc}\r
+ * @throws IOException {@inheritDoc}\r
+ * @throws IllegalPmdException {@inheritDoc}\r
+ */\r
+ @Override\r
+ public void dumpPmdModel(PmdModel model)\r
+ throws IOException, IllegalPmdException{\r
+ super.dumpPmdModel(model);\r
+\r
+ dumpToonMap(model);\r
+\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * 独自トゥーンファイルテーブルを出力する。\r
+ * @param model モデルデータ\r
+ * @throws IOException 出力エラー\r
+ * @throws IllegalPmdTextException トゥーンファイル名が長すぎる\r
+ */\r
+ private void dumpToonMap(PmdModel model)\r
+ throws IOException, IllegalPmdTextException{\r
+ ToonMap map = model.getToonMap();\r
+\r
+ for(int idx = 0; idx < PmdLimits.TOON_FIXEDNUM; idx++){\r
+ String toonName = map.getIndexedToon(idx);\r
+ if(toonName == null) toonName = "";\r
+ dumpText(toonName, PmdLimits.MAXBYTES_TOONFILENAME);\r
+ }\r
+\r
+ flush();\r
+\r
+ return;\r
+ }\r
+\r
+}\r
--- /dev/null
+/*\r
+ * model exporter for pmd-file(Ext3)\r
+ *\r
+ * License : The MIT License\r
+ * Copyright(c) 2010 MikuToga Partners\r
+ */\r
+\r
+package jp.sourceforge.mikutoga.pmd.pmdexporter;\r
+\r
+import java.io.IOException;\r
+import java.io.OutputStream;\r
+import java.util.List;\r
+import jp.sourceforge.mikutoga.parser.pmd.PmdLimits;\r
+import jp.sourceforge.mikutoga.pmd.BoneInfo;\r
+import jp.sourceforge.mikutoga.pmd.Deg3d;\r
+import jp.sourceforge.mikutoga.pmd.DynamicsInfo;\r
+import jp.sourceforge.mikutoga.pmd.JointInfo;\r
+import jp.sourceforge.mikutoga.pmd.PmdModel;\r
+import jp.sourceforge.mikutoga.pmd.Rad3d;\r
+import jp.sourceforge.mikutoga.pmd.RigidGroup;\r
+import jp.sourceforge.mikutoga.pmd.RigidInfo;\r
+import jp.sourceforge.mikutoga.pmd.RigidShape;\r
+import jp.sourceforge.mikutoga.pmd.RigidShapeType;\r
+import jp.sourceforge.mikutoga.pmd.TripletRange;\r
+\r
+/**\r
+ * PMDファイルのエクスポーター(拡張3:物理演算対応)。\r
+ * <p>\r
+ * 物理演算対応のPMDファイルフォーマットを\r
+ * 使いたい場合はこのエクスポーターを用いて出力せよ。\r
+ */\r
+public class PmdExporterExt3 extends PmdExporterExt2{\r
+\r
+ private static final short MASK_FULLCOLLISION = (short) 0xffff;\r
+\r
+ /**\r
+ * コンストラクタ。\r
+ * @param stream 出力ストリーム\r
+ * @throws NullPointerException 引数がnull\r
+ */\r
+ public PmdExporterExt3(OutputStream stream)\r
+ throws NullPointerException{\r
+ super(stream);\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param model {@inheritDoc}\r
+ * @throws IOException {@inheritDoc}\r
+ * @throws IllegalPmdException {@inheritDoc}\r
+ */\r
+ @Override\r
+ public void dumpPmdModel(PmdModel model)\r
+ throws IOException, IllegalPmdException{\r
+ super.dumpPmdModel(model);\r
+\r
+ dumpRigidList(model);\r
+ dumpJointList(model);\r
+\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * 剛体リストを出力する。\r
+ * @param model モデルデータ\r
+ * @throws IOException 出力エラー\r
+ * @throws IllegalPmdTextException 長すぎる剛体名\r
+ */\r
+ private void dumpRigidList(PmdModel model)\r
+ throws IOException, IllegalPmdTextException{\r
+ List<RigidInfo> rigidList = model.getRigidList();\r
+ int rigidNum = rigidList.size();\r
+ dumpInt(rigidNum);\r
+\r
+ for(RigidInfo rigid : rigidList){\r
+ dumpRigid(rigid);\r
+ }\r
+\r
+ flush();\r
+\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * 個別の剛体情報を出力する。\r
+ * @param rigid 剛体\r
+ * @throws IOException 出力エラー\r
+ * @throws IllegalPmdTextException 長すぎる剛体名\r
+ */\r
+ private void dumpRigid(RigidInfo rigid)\r
+ throws IOException, IllegalPmdTextException{\r
+ String rigidName = rigid.getRigidName().getPrimaryText();\r
+ dumpText(rigidName, PmdLimits.MAXBYTES_RIGIDNAME);\r
+\r
+ BoneInfo linkedBone = rigid.getLinkedBone();\r
+ dumpShort(linkedBone.getSerialNumber());\r
+\r
+ RigidGroup group = rigid.getRigidGroup();\r
+ dumpByte(group.getSerialNumber());\r
+\r
+ short mask = MASK_FULLCOLLISION;\r
+ for(RigidGroup throughGroup : rigid.getThroughGroupColl()){\r
+ int serialId = throughGroup.getSerialNumber();\r
+ mask &= ~(0x0001 << serialId);\r
+ }\r
+ dumpShort(mask);\r
+\r
+ dumpRigidShape(rigid.getRigidShape());\r
+\r
+ dumpPos3d(rigid.getPosition());\r
+ dumpRad3d(rigid.getRotation());\r
+\r
+ dumpDynamics(rigid.getDynamicsInfo());\r
+\r
+ dumpByte(rigid.getBehaviorType().encode());\r
+\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * 剛体形状を出力する。\r
+ * @param shape 剛体形状\r
+ * @throws IOException 出力エラー\r
+ */\r
+ private void dumpRigidShape(RigidShape shape)\r
+ throws IOException{\r
+ RigidShapeType type = shape.getShapeType();\r
+ dumpByte(type.encode());\r
+\r
+ float width = shape.getWidth();\r
+ float height = shape.getHeight();\r
+ float depth = shape.getDepth();\r
+\r
+ dumpFloat(width);\r
+ dumpFloat(height);\r
+ dumpFloat(depth);\r
+\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * 力学設定を出力する。\r
+ * @param dynamics 力学設定\r
+ * @throws IOException 出力エラー\r
+ */\r
+ private void dumpDynamics(DynamicsInfo dynamics)\r
+ throws IOException{\r
+ float mass = dynamics.getMass();\r
+ float dampPos = dynamics.getDampingPosition();\r
+ float dampRot = dynamics.getDampingRotation();\r
+ float restitution = dynamics.getRestitution();\r
+ float friction = dynamics.getFriction();\r
+\r
+ dumpFloat(mass);\r
+ dumpFloat(dampPos);\r
+ dumpFloat(dampRot);\r
+ dumpFloat(restitution);\r
+ dumpFloat(friction);\r
+\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * ジョイントリストを出力する。\r
+ * @param model モデルデータ\r
+ * @throws IOException 出力エラー\r
+ * @throws IllegalPmdTextException 長すぎるジョイント名\r
+ */\r
+ private void dumpJointList(PmdModel model)\r
+ throws IOException, IllegalPmdTextException{\r
+ List<JointInfo> jointList = model.getJointList();\r
+ int jointNum = jointList.size();\r
+ dumpInt(jointNum);\r
+\r
+ for(JointInfo joint : jointList){\r
+ dumpJoint(joint);\r
+ }\r
+\r
+ flush();\r
+\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * 個別のジョイント情報を出力する。\r
+ * @param joint ジョイント\r
+ * @throws IOException 出力エラー\r
+ * @throws IllegalPmdTextException 長すぎるジョイント名\r
+ */\r
+ private void dumpJoint(JointInfo joint)\r
+ throws IOException, IllegalPmdTextException{\r
+ String jointName = joint.getJointName().getPrimaryText();\r
+ dumpText(jointName, PmdLimits.MAXBYTES_JOINTNAME);\r
+\r
+ RigidInfo rigidA = joint.getRigidA();\r
+ RigidInfo rigidB = joint.getRigidB();\r
+\r
+ dumpInt(rigidA.getSerialNumber());\r
+ dumpInt(rigidB.getSerialNumber());\r
+\r
+ dumpPos3d(joint.getPosition());\r
+ dumpRad3d(joint.getRotation());\r
+\r
+ dumpTripletRange(joint.getPositionRange());\r
+ dumpTripletRange(joint.getRotationRange());\r
+\r
+ dumpPos3d(joint.getElasticPosition());\r
+ dumpDeg3d(joint.getElasticRotation());\r
+\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * 3次元範囲制約を出力する。\r
+ * @param range 3次元範囲制約\r
+ * @throws IOException 出力エラー\r
+ */\r
+ protected void dumpTripletRange(TripletRange range) throws IOException{\r
+ float xFrom = range.getXFrom();\r
+ float yFrom = range.getYFrom();\r
+ float zFrom = range.getZFrom();\r
+\r
+ dumpFloat(xFrom);\r
+ dumpFloat(yFrom);\r
+ dumpFloat(zFrom);\r
+\r
+ float xTo = range.getXTo();\r
+ float yTo = range.getYTo();\r
+ float zTo = range.getZTo();\r
+\r
+ dumpFloat(xTo);\r
+ dumpFloat(yTo);\r
+ dumpFloat(zTo);\r
+\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * ラジアンによる3次元姿勢情報を出力する。\r
+ * @param rad 3次元姿勢情報\r
+ * @throws IOException 出力エラー\r
+ */\r
+ protected void dumpRad3d(Rad3d rad) throws IOException{\r
+ float xVal = rad.getXRad();\r
+ float yVal = rad.getYRad();\r
+ float zVal = rad.getZRad();\r
+\r
+ dumpFloat(xVal);\r
+ dumpFloat(yVal);\r
+ dumpFloat(zVal);\r
+\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * 度数法による3次元姿勢情報を出力する。\r
+ * @param deg 3次元姿勢情報\r
+ * @throws IOException 出力エラー\r
+ */\r
+ protected void dumpDeg3d(Deg3d deg) throws IOException{\r
+ float xVal = deg.getXDeg();\r
+ float yVal = deg.getYDeg();\r
+ float zVal = deg.getZDeg();\r
+\r
+ dumpFloat(xVal);\r
+ dumpFloat(yVal);\r
+ dumpFloat(zVal);\r
+\r
+ return;\r
+ }\r
+\r
+}\r
--- /dev/null
+/*\r
+ * package information for Javadoc\r
+ *\r
+ * License : The MIT License\r
+ * Copyright(c) 2010 MikuToga Partners\r
+ */\r
+\r
+/**\r
+ * PMDモデルファイル(*.pmd)用エクスポーター。\r
+ */\r
+\r
+package jp.sourceforge.mikutoga.pmd.pmdexporter;\r
+\r
+/* EOF */\r
--- /dev/null
+/*\r
+ * building bone information\r
+ *\r
+ * License : The MIT License\r
+ * Copyright(c) 2010 MikuToga Partners\r
+ */\r
+\r
+package jp.sourceforge.mikutoga.pmd.pmdloader;\r
+\r
+import jp.sourceforge.mikutoga.corelib.ListUtil;\r
+import java.util.Iterator;\r
+import java.util.LinkedList;\r
+import java.util.List;\r
+import jp.sourceforge.mikutoga.parser.ParseStage;\r
+import jp.sourceforge.mikutoga.parser.pmd.PmdBoneHandler;\r
+import jp.sourceforge.mikutoga.parser.pmd.PmdLimits;\r
+import jp.sourceforge.mikutoga.pmd.BoneGroup;\r
+import jp.sourceforge.mikutoga.pmd.BoneInfo;\r
+import jp.sourceforge.mikutoga.pmd.BoneType;\r
+import jp.sourceforge.mikutoga.pmd.IKChain;\r
+import jp.sourceforge.mikutoga.pmd.PmdModel;\r
+import jp.sourceforge.mikutoga.pmd.Pos3d;\r
+\r
+/**\r
+ * ボーン関係の通知をパーサから受け取る。\r
+ */\r
+class BoneBuilder implements PmdBoneHandler {\r
+\r
+ private final List<BoneInfo> boneList;\r
+ private Iterator<BoneInfo> boneIt;\r
+ private BoneInfo currentBone = null;\r
+\r
+ private final List<IKChain> ikChainList;\r
+ private Iterator<IKChain> ikChainIt;\r
+ private IKChain currentIkChain = null;\r
+\r
+ private final List<BoneGroup> boneGroupList;\r
+ private Iterator<BoneGroup> boneGroupIt;\r
+ private BoneGroup currentBoneGroup = null;\r
+\r
+ /**\r
+ * コンストラクタ。\r
+ * @param model モデル\r
+ */\r
+ BoneBuilder(PmdModel model){\r
+ super();\r
+\r
+ this.boneList = model.getBoneList();\r
+ this.ikChainList = model.getIKChainList();\r
+ this.boneGroupList = model.getBoneGroupList();\r
+\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param stage {@inheritDoc}\r
+ * @param loops {@inheritDoc}\r
+ */\r
+ public void loopStart(ParseStage stage, int loops){\r
+ assert stage instanceof PmdBoneStage;\r
+\r
+ if(stage == PmdBoneHandler.BONE_LIST){\r
+ ListUtil.prepareDefConsList(this.boneList, BoneInfo.class, loops);\r
+ ListUtil.assignIndexedSerial(this.boneList);\r
+\r
+ this.boneIt = this.boneList.iterator();\r
+ if(this.boneIt.hasNext()){\r
+ this.currentBone = this.boneIt.next();\r
+ }\r
+ }else if(stage == PmdBoneHandler.IK_LIST){\r
+ ListUtil.prepareDefConsList(this.ikChainList,\r
+ IKChain.class,\r
+ loops );\r
+\r
+ this.ikChainIt = this.ikChainList.iterator();\r
+ if(this.ikChainIt.hasNext()){\r
+ this.currentIkChain = this.ikChainIt.next();\r
+ }\r
+ }else if(stage == PmdBoneHandler.IKCHAIN_LIST){\r
+ //NOTHING\r
+ }else if(stage == PmdBoneHandler.BONEGROUP_LIST){\r
+ ListUtil.prepareDefConsList(this.boneGroupList,\r
+ BoneGroup.class,\r
+ loops + 1 );\r
+ ListUtil.assignIndexedSerial(this.boneGroupList);\r
+\r
+ this.boneGroupIt = this.boneGroupList.iterator();\r
+\r
+ assert this.boneGroupIt.hasNext();\r
+ this.boneGroupIt.next(); // デフォルトボーングループを読み飛ばす\r
+\r
+ if(this.boneGroupIt.hasNext()){\r
+ this.currentBoneGroup = this.boneGroupIt.next();\r
+ }\r
+ }else if(stage == PmdBoneHandler.GROUPEDBONE_LIST){\r
+ //NOTHING\r
+ }else{\r
+ assert false;\r
+ throw new AssertionError();\r
+ }\r
+\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param stage {@inheritDoc}\r
+ */\r
+ public void loopNext(ParseStage stage){\r
+ assert stage instanceof PmdBoneStage;\r
+\r
+ if(stage == PmdBoneHandler.BONE_LIST){\r
+ if(this.boneIt.hasNext()){\r
+ this.currentBone = this.boneIt.next();\r
+ }\r
+ }else if(stage == PmdBoneHandler.IK_LIST){\r
+ if(this.ikChainIt.hasNext()){\r
+ this.currentIkChain = this.ikChainIt.next();\r
+ }\r
+ }else if(stage == PmdBoneHandler.IKCHAIN_LIST){\r
+ //NOTHING\r
+ }else if(stage == PmdBoneHandler.BONEGROUP_LIST){\r
+ if(this.boneGroupIt.hasNext()){\r
+ this.currentBoneGroup = this.boneGroupIt.next();\r
+ }\r
+ }else if(stage == PmdBoneHandler.GROUPEDBONE_LIST){\r
+ //NOTHING\r
+ }else{\r
+ assert false;\r
+ throw new AssertionError();\r
+ }\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param stage {@inheritDoc}\r
+ */\r
+ public void loopEnd(ParseStage stage){\r
+ assert stage instanceof PmdBoneStage;\r
+\r
+ if(stage == PmdBoneHandler.BONE_LIST){\r
+ //NOTHING\r
+ }else if(stage == PmdBoneHandler.IK_LIST){\r
+ //NOTHING\r
+ }else if(stage == PmdBoneHandler.IKCHAIN_LIST){\r
+ //NOTHING\r
+ }else if(stage == PmdBoneHandler.BONEGROUP_LIST){\r
+ //NOTHING\r
+ }else if(stage == PmdBoneHandler.GROUPEDBONE_LIST){\r
+ pickOrphanBone();\r
+ }else{\r
+ assert false;\r
+ throw new AssertionError();\r
+ }\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * 所属グループの無いボーンをデフォルトボーングループへ登録する。\r
+ */\r
+ private void pickOrphanBone(){\r
+ List<BoneInfo> orpahnList = new LinkedList<BoneInfo>();\r
+ orpahnList.addAll(this.boneList);\r
+ for(BoneGroup group : this.boneGroupList){\r
+ orpahnList.removeAll(group.getBoneList());\r
+ }\r
+\r
+ BoneGroup defaultGroup = this.boneGroupList.get(0);\r
+ defaultGroup.getBoneList().addAll(orpahnList);\r
+\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param boneName {@inheritDoc}\r
+ * @param boneKind {@inheritDoc}\r
+ */\r
+ public void pmdBoneInfo(String boneName, byte boneKind){\r
+ this.currentBone.getBoneName().setPrimaryText(boneName);\r
+ BoneType type = BoneType.decode(boneKind);\r
+ this.currentBone.setBoneType(type);\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param parentId {@inheritDoc}\r
+ * @param tailId {@inheritDoc}\r
+ * @param ikId {@inheritDoc}\r
+ */\r
+ public void pmdBoneLink(int parentId, int tailId, int ikId){\r
+ BoneInfo prevBone = null;\r
+ if(0 <= parentId && parentId < PmdLimits.MAX_BONE){\r
+ prevBone = this.boneList.get(parentId);\r
+ }\r
+\r
+ BoneInfo nextBone = null;\r
+ if(tailId != 0){\r
+ nextBone = this.boneList.get(tailId);\r
+ }\r
+\r
+ BoneInfo ikBone = null;\r
+ if(this.currentBone.getBoneType() == BoneType.LINKEDROT){\r
+ ikBone = null;\r
+ int ratio = ikId;\r
+ this.currentBone.setRotationRatio(ratio);\r
+ }else if(0 < ikId && ikId < PmdLimits.MAX_BONE){\r
+ ikBone = this.boneList.get(ikId);\r
+ }\r
+\r
+ this.currentBone.setPrevBone(prevBone);\r
+ this.currentBone.setNextBone(nextBone);\r
+ this.currentBone.setIKBone(ikBone);\r
+\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param xPos {@inheritDoc}\r
+ * @param yPos {@inheritDoc}\r
+ * @param zPos {@inheritDoc}\r
+ */\r
+ public void pmdBonePosition(float xPos, float yPos, float zPos){\r
+ Pos3d position = this.currentBone.getPosition();\r
+ position.setXPos(xPos);\r
+ position.setYPos(yPos);\r
+ position.setZPos(zPos);\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param boneId {@inheritDoc}\r
+ * @param targetId {@inheritDoc}\r
+ * @param depth {@inheritDoc}\r
+ * @param weight {@inheritDoc}\r
+ */\r
+ public void pmdIKInfo(int boneId, int targetId, int depth, float weight){\r
+ BoneInfo bone = this.boneList.get(boneId);\r
+ this.currentIkChain.setIkBone(bone);\r
+\r
+ BoneInfo target = this.boneList.get(targetId);\r
+ this.currentIkChain.getChainedBoneList().add(0, target);\r
+\r
+ this.currentIkChain.setIKDepth(depth);\r
+ this.currentIkChain.setIKWeight(weight);\r
+\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param childId {@inheritDoc}\r
+ */\r
+ public void pmdIKChainInfo(int childId){\r
+ BoneInfo chain = this.boneList.get(childId);\r
+ this.currentIkChain.getChainedBoneList().add(chain);\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param groupName {@inheritDoc}\r
+ */\r
+ public void pmdBoneGroupInfo(String groupName){\r
+ this.currentBoneGroup.getGroupName().setPrimaryText(groupName);\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param boneId {@inheritDoc}\r
+ * @param groupId {@inheritDoc}\r
+ */\r
+ public void pmdGroupedBoneInfo(int boneId, int groupId){\r
+ BoneInfo bone = this.boneList.get(boneId);\r
+ BoneGroup group = this.boneGroupList.get(groupId);\r
+ group.getBoneList().add(bone);\r
+ return;\r
+ }\r
+\r
+}\r
--- /dev/null
+/*\r
+ * building joint information\r
+ *\r
+ * License : The MIT License\r
+ * Copyright(c) 2010 MikuToga Partners\r
+ */\r
+\r
+package jp.sourceforge.mikutoga.pmd.pmdloader;\r
+\r
+import jp.sourceforge.mikutoga.corelib.ListUtil;\r
+import java.util.Iterator;\r
+import java.util.List;\r
+import jp.sourceforge.mikutoga.parser.ParseStage;\r
+import jp.sourceforge.mikutoga.parser.pmd.PmdJointHandler;\r
+import jp.sourceforge.mikutoga.pmd.Deg3d;\r
+import jp.sourceforge.mikutoga.pmd.JointInfo;\r
+import jp.sourceforge.mikutoga.pmd.PmdModel;\r
+import jp.sourceforge.mikutoga.pmd.Pos3d;\r
+import jp.sourceforge.mikutoga.pmd.Rad3d;\r
+import jp.sourceforge.mikutoga.pmd.RigidInfo;\r
+import jp.sourceforge.mikutoga.pmd.TripletRange;\r
+\r
+/**\r
+ * ジョイント関係の通知をパーサから受け取る。\r
+ */\r
+class JointBuilder implements PmdJointHandler {\r
+\r
+ private final List<RigidInfo> rigidList;\r
+\r
+ private final List<JointInfo> jointList;\r
+ private Iterator<JointInfo> jointIt;\r
+ private JointInfo currentJoint = null;\r
+\r
+ /**\r
+ * コンストラクタ。\r
+ * @param model モデル\r
+ */\r
+ JointBuilder(PmdModel model){\r
+ super();\r
+ this.rigidList = model.getRigidList();\r
+ this.jointList = model.getJointList();\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param stage {@inheritDoc}\r
+ * @param loops {@inheritDoc}\r
+ */\r
+ public void loopStart(ParseStage stage, int loops){\r
+ assert stage == PmdJointHandler.JOINT_LIST;\r
+\r
+ ListUtil.prepareDefConsList(this.jointList, JointInfo.class, loops);\r
+\r
+ this.jointIt = this.jointList.iterator();\r
+ if(this.jointIt.hasNext()){\r
+ this.currentJoint = this.jointIt.next();\r
+ }\r
+\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param stage {@inheritDoc}\r
+ */\r
+ public void loopNext(ParseStage stage){\r
+ assert stage == PmdJointHandler.JOINT_LIST;\r
+\r
+ if(this.jointIt.hasNext()){\r
+ this.currentJoint = this.jointIt.next();\r
+ }\r
+\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param stage {@inheritDoc}\r
+ */\r
+ public void loopEnd(ParseStage stage){\r
+ assert stage == PmdJointHandler.JOINT_LIST;\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param jointName {@inheritDoc}\r
+ */\r
+ public void pmdJointName(String jointName){\r
+ this.currentJoint.getJointName().setPrimaryText(jointName);\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param rigidIdA {@inheritDoc}\r
+ * @param rigidIdB {@inheritDoc}\r
+ */\r
+ public void pmdJointLink(int rigidIdA, int rigidIdB){\r
+ RigidInfo rigidA = this.rigidList.get(rigidIdA);\r
+ RigidInfo rigidB = this.rigidList.get(rigidIdB);\r
+ this.currentJoint.setRigidPair(rigidA, rigidB);\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param posX {@inheritDoc}\r
+ * @param posY {@inheritDoc}\r
+ * @param posZ {@inheritDoc}\r
+ */\r
+ public void pmdJointPosition(float posX, float posY, float posZ){\r
+ Pos3d position = this.currentJoint.getPosition();\r
+ position.setXPos(posX);\r
+ position.setYPos(posY);\r
+ position.setZPos(posZ);\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param rotX {@inheritDoc}\r
+ * @param rotY {@inheritDoc}\r
+ * @param rotZ {@inheritDoc}\r
+ */\r
+ public void pmdJointRotation(float rotX, float rotY, float rotZ){\r
+ Rad3d rotation = this.currentJoint.getRotation();\r
+ rotation.setXRad(rotX);\r
+ rotation.setYRad(rotY);\r
+ rotation.setZRad(rotZ);\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param posXlim1 {@inheritDoc}\r
+ * @param posXlim2 {@inheritDoc}\r
+ * @param posYlim1 {@inheritDoc}\r
+ * @param posYlim2 {@inheritDoc}\r
+ * @param posZlim1 {@inheritDoc}\r
+ * @param posZlim2 {@inheritDoc}\r
+ */\r
+ public void pmdPositionLimit(float posXlim1, float posXlim2,\r
+ float posYlim1, float posYlim2,\r
+ float posZlim1, float posZlim2){\r
+ TripletRange range = this.currentJoint.getPositionRange();\r
+ range.setXRange(posXlim1, posXlim2);\r
+ range.setYRange(posYlim1, posYlim2);\r
+ range.setZRange(posZlim1, posZlim2);\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param rotXlim1 {@inheritDoc}\r
+ * @param rotXlim2 {@inheritDoc}\r
+ * @param rotYlim1 {@inheritDoc}\r
+ * @param rotYlim2 {@inheritDoc}\r
+ * @param rotZlim1 {@inheritDoc}\r
+ * @param rotZlim2 {@inheritDoc}\r
+ */\r
+ public void pmdRotationLimit(float rotXlim1, float rotXlim2,\r
+ float rotYlim1, float rotYlim2,\r
+ float rotZlim1, float rotZlim2){\r
+ TripletRange range = this.currentJoint.getRotationRange();\r
+ range.setXRange(rotXlim1, rotXlim2);\r
+ range.setYRange(rotYlim1, rotYlim2);\r
+ range.setZRange(rotZlim1, rotZlim2);\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param elasticPosX {@inheritDoc}\r
+ * @param elasticPosY {@inheritDoc}\r
+ * @param elasticPosZ {@inheritDoc}\r
+ */\r
+ public void pmdElasticPosition(float elasticPosX,\r
+ float elasticPosY,\r
+ float elasticPosZ){\r
+ Pos3d position = this.currentJoint.getElasticPosition();\r
+ position.setXPos(elasticPosX);\r
+ position.setYPos(elasticPosY);\r
+ position.setZPos(elasticPosZ);\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param elasticRotX {@inheritDoc}\r
+ * @param elasticRotY {@inheritDoc}\r
+ * @param elasticRotZ {@inheritDoc}\r
+ */\r
+ public void pmdElasticRotation(float elasticRotX,\r
+ float elasticRotY,\r
+ float elasticRotZ){\r
+ Deg3d rotation = this.currentJoint.getElasticRotation();\r
+ rotation.setXDeg(elasticRotX);\r
+ rotation.setYDeg(elasticRotY);\r
+ rotation.setZDeg(elasticRotZ);\r
+ return;\r
+ }\r
+\r
+}\r
--- /dev/null
+/*\r
+ * building material information\r
+ *\r
+ * License : The MIT License\r
+ * Copyright(c) 2010 MikuToga Partners\r
+ */\r
+\r
+package jp.sourceforge.mikutoga.pmd.pmdloader;\r
+\r
+import jp.sourceforge.mikutoga.corelib.ListUtil;\r
+import java.awt.Color;\r
+import java.util.Iterator;\r
+import java.util.List;\r
+import jp.sourceforge.mikutoga.parser.ParseStage;\r
+import jp.sourceforge.mikutoga.parser.pmd.PmdMaterialHandler;\r
+import jp.sourceforge.mikutoga.pmd.Material;\r
+import jp.sourceforge.mikutoga.pmd.PmdModel;\r
+import jp.sourceforge.mikutoga.pmd.ShadeInfo;\r
+import jp.sourceforge.mikutoga.pmd.Surface;\r
+import jp.sourceforge.mikutoga.pmd.ToonMap;\r
+\r
+/**\r
+ * マテリアル素材関連の通知をパーサから受け取る。\r
+ */\r
+class MaterialBuilder implements PmdMaterialHandler {\r
+\r
+ private final List<Material> materialList;\r
+ private Iterator<Material> materialIt;\r
+ private Material currentMaterial = null;\r
+\r
+ private final List<Surface> surfacelList;\r
+ private Iterator<Surface> surfaceIt;\r
+\r
+ private final ToonMap toonMap;\r
+\r
+ /**\r
+ * コンストラクタ。\r
+ * @param model モデル\r
+ */\r
+ MaterialBuilder(PmdModel model){\r
+ super();\r
+\r
+ this.materialList = model.getMaterialList();\r
+ this.surfacelList = model.getSurfaceList();\r
+ this.toonMap = model.getToonMap();\r
+\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param stage {@inheritDoc}\r
+ * @param loops {@inheritDoc}\r
+ */\r
+ public void loopStart(ParseStage stage, int loops){\r
+ assert stage == PmdMaterialHandler.MATERIAL_LIST;\r
+\r
+ ListUtil.prepareDefConsList(this.materialList, Material.class, loops);\r
+\r
+ this.materialIt = this.materialList.iterator();\r
+ if(this.materialIt.hasNext()){\r
+ this.currentMaterial = this.materialIt.next();\r
+ }\r
+\r
+ this.surfaceIt = this.surfacelList.iterator();\r
+\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param stage {@inheritDoc}\r
+ */\r
+ public void loopNext(ParseStage stage){\r
+ assert stage == PmdMaterialHandler.MATERIAL_LIST;\r
+\r
+ if(this.materialIt.hasNext()){\r
+ this.currentMaterial = this.materialIt.next();\r
+ }\r
+\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param stage {@inheritDoc}\r
+ */\r
+ public void loopEnd(ParseStage stage){\r
+ assert stage == PmdMaterialHandler.MATERIAL_LIST;\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param red {@inheritDoc}\r
+ * @param green {@inheritDoc}\r
+ * @param blue {@inheritDoc}\r
+ * @param alpha {@inheritDoc}\r
+ */\r
+ public void pmdMaterialDiffuse(float red,\r
+ float green,\r
+ float blue,\r
+ float alpha ){\r
+ Color diffuse = new Color(red, green, blue, alpha);\r
+ this.currentMaterial.setDiffuseColor(diffuse);\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param red {@inheritDoc}\r
+ * @param green {@inheritDoc}\r
+ * @param blue {@inheritDoc}\r
+ */\r
+ public void pmdMaterialAmbient(float red,\r
+ float green,\r
+ float blue ){\r
+ Color ambient = new Color(red, green, blue);\r
+ this.currentMaterial.setAmbientColor(ambient);\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param red {@inheritDoc}\r
+ * @param green {@inheritDoc}\r
+ * @param blue {@inheritDoc}\r
+ * @param shininess {@inheritDoc}\r
+ */\r
+ public void pmdMaterialSpecular(float red,\r
+ float green,\r
+ float blue,\r
+ float shininess ){\r
+ Color specular = new Color(red, green, blue);\r
+ this.currentMaterial.setSpecularColor(specular);\r
+ this.currentMaterial.setShininess(shininess);\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param hasEdge {@inheritDoc}\r
+ * @param vertexNum {@inheritDoc}\r
+ */\r
+ public void pmdMaterialInfo(boolean hasEdge, int vertexNum){\r
+ this.currentMaterial.setEdgeAppearance(hasEdge);\r
+\r
+ List<Surface> list = this.currentMaterial.getSurfaceList();\r
+\r
+ int surfaceNum = vertexNum / 3;\r
+ for(int ct = 1; ct <= surfaceNum; ct++){\r
+ Surface surface = this.surfaceIt.next();\r
+ list.add(surface);\r
+ }\r
+\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param toonIdx {@inheritDoc}\r
+ * @param textureFile {@inheritDoc}\r
+ * @param sphereFile {@inheritDoc}\r
+ */\r
+ public void pmdMaterialShading(int toonIdx,\r
+ String textureFile,\r
+ String sphereFile ){\r
+ ShadeInfo info = this.currentMaterial.getShadeInfo();\r
+\r
+ ToonMap map = this.toonMap;\r
+\r
+ info.setToonMap(map);\r
+ info.setToonIndex(toonIdx);\r
+ info.setTextureFileName(textureFile);\r
+ info.setSpheremapFileName(sphereFile);\r
+\r
+ return;\r
+ }\r
+\r
+}\r
--- /dev/null
+/*\r
+ * building morph information\r
+ *\r
+ * License : The MIT License\r
+ * Copyright(c) 2010 MikuToga Partners\r
+ */\r
+\r
+package jp.sourceforge.mikutoga.pmd.pmdloader;\r
+\r
+import jp.sourceforge.mikutoga.corelib.ListUtil;\r
+import java.util.ArrayList;\r
+import java.util.Iterator;\r
+import java.util.LinkedList;\r
+import java.util.List;\r
+import java.util.Map;\r
+import jp.sourceforge.mikutoga.parser.ParseStage;\r
+import jp.sourceforge.mikutoga.parser.pmd.PmdMorphHandler;\r
+import jp.sourceforge.mikutoga.pmd.MorphPart;\r
+import jp.sourceforge.mikutoga.pmd.MorphType;\r
+import jp.sourceforge.mikutoga.pmd.MorphVertex;\r
+import jp.sourceforge.mikutoga.pmd.PmdModel;\r
+import jp.sourceforge.mikutoga.pmd.Pos3d;\r
+import jp.sourceforge.mikutoga.pmd.Vertex;\r
+\r
+/**\r
+ * モーフ関係の通知をパーサから受け取る。\r
+ */\r
+class MorphBuilder implements PmdMorphHandler {\r
+\r
+ private final Map<MorphType, List<MorphPart>> morphMap;\r
+\r
+ private List<MorphPart> morphPartList;\r
+ private Iterator<MorphPart> morphPartIt;\r
+ private MorphPart currentMorphPart;\r
+ private final List<Vertex> vertexList;\r
+\r
+ private final List<Vertex> morphVertexList = new ArrayList<Vertex>();\r
+\r
+ /**\r
+ * コンストラクタ。\r
+ * @param model モデル\r
+ */\r
+ MorphBuilder(PmdModel model){\r
+ super();\r
+ this.vertexList = model.getVertexList();\r
+ this.morphMap = model.getMorphMap();\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * PMDファイル中の出現順で各モーフを格納するためのリストを設定する。\r
+ * 主な用途はモーフ英名との突き合わせ作業。\r
+ * @param list モーフ格納リスト\r
+ */\r
+ void setMorphPartList(List<MorphPart> list){\r
+ this.morphPartList = list;\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param stage {@inheritDoc}\r
+ * @param loops {@inheritDoc}\r
+ */\r
+ public void loopStart(ParseStage stage, int loops){\r
+ assert stage instanceof PmdMorphStage;\r
+\r
+ if(stage == PmdMorphHandler.MORPH_LIST){\r
+ ListUtil.prepareDefConsList(this.morphPartList,\r
+ MorphPart.class,\r
+ loops );\r
+ ListUtil.assignIndexedSerial(this.morphPartList);\r
+\r
+ this.morphPartIt = this.morphPartList.iterator();\r
+ if(this.morphPartIt.hasNext()){\r
+ this.currentMorphPart = this.morphPartIt.next();\r
+ }\r
+ }else if(stage == PmdMorphHandler.MORPHVERTEX_LIST){\r
+ // NOTHING\r
+ }else if(stage == PmdMorphHandler.MORPHORDER_LIST){\r
+ // NOTHING\r
+ }\r
+\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param stage {@inheritDoc}\r
+ */\r
+ public void loopNext(ParseStage stage){\r
+ assert stage instanceof PmdMorphStage;\r
+\r
+ if(stage == PmdMorphHandler.MORPH_LIST){\r
+ if(this.morphPartIt.hasNext()){\r
+ this.currentMorphPart = this.morphPartIt.next();\r
+ }\r
+ }else if(stage == PmdMorphHandler.MORPHVERTEX_LIST){\r
+ // NOTHING\r
+ }else if(stage == PmdMorphHandler.MORPHORDER_LIST){\r
+ // NOTHING\r
+ }\r
+\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param stage {@inheritDoc}\r
+ */\r
+ public void loopEnd(ParseStage stage){\r
+ assert stage instanceof PmdMorphStage;\r
+ if(stage == PmdMorphHandler.MORPH_LIST){\r
+ // NOTHING\r
+ }else if(stage == PmdMorphHandler.MORPHVERTEX_LIST){\r
+ // NOTHING\r
+ }else if(stage == PmdMorphHandler.MORPHORDER_LIST){\r
+ // NOTHING\r
+ }\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param morphName {@inheritDoc}\r
+ * @param morphType {@inheritDoc}\r
+ */\r
+ public void pmdMorphInfo(String morphName, byte morphType){\r
+ this.currentMorphPart.getMorphName().setPrimaryText(morphName);\r
+ MorphType type = MorphType.decode(morphType);\r
+ this.currentMorphPart.setMorphType(type);\r
+\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param serialId {@inheritDoc}\r
+ * @param xPos {@inheritDoc}\r
+ * @param yPos {@inheritDoc}\r
+ * @param zPos {@inheritDoc}\r
+ */\r
+ public void pmdMorphVertexInfo(int serialId,\r
+ float xPos, float yPos, float zPos){\r
+ MorphVertex morphVertex;\r
+ morphVertex = new MorphVertex();\r
+ Pos3d position = morphVertex.getOffset();\r
+ position.setXPos(xPos);\r
+ position.setYPos(yPos);\r
+ position.setZPos(zPos);\r
+\r
+ Vertex vertex;\r
+ if(this.currentMorphPart.getMorphType().isBase()){\r
+ vertex = this.vertexList.get(serialId);\r
+ this.morphVertexList.add(vertex);\r
+ }else{\r
+ vertex = this.morphVertexList.get(serialId);\r
+ }\r
+ morphVertex.setBaseVertex(vertex);\r
+\r
+ this.currentMorphPart.getMorphVertexList().add(morphVertex);\r
+\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param morphId {@inheritDoc}\r
+ */\r
+ public void pmdMorphOrderInfo(int morphId){\r
+ MorphPart part = this.morphPartList.get(morphId);\r
+ MorphType type = part.getMorphType();\r
+\r
+ List<MorphPart> partList = this.morphMap.get(type);\r
+ if(partList == null){\r
+ partList = new LinkedList<MorphPart>();\r
+ this.morphMap.put(type, partList);\r
+ }\r
+ partList.add(part);\r
+\r
+ return;\r
+ }\r
+\r
+}\r
--- /dev/null
+/*\r
+ * PMD file loader\r
+ *\r
+ * License : The MIT License\r
+ * Copyright(c) 2010 MikuToga Partners\r
+ */\r
+\r
+package jp.sourceforge.mikutoga.pmd.pmdloader;\r
+\r
+import java.io.IOException;\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+import jp.sourceforge.mikutoga.parser.MmdFormatException;\r
+import jp.sourceforge.mikutoga.parser.MmdSource;\r
+import jp.sourceforge.mikutoga.parser.pmd.PmdParser;\r
+import jp.sourceforge.mikutoga.pmd.MorphPart;\r
+import jp.sourceforge.mikutoga.pmd.PmdModel;\r
+\r
+/**\r
+ * PMDモデルファイルを読み込むためのローダ。\r
+ */\r
+public class PmdLoader {\r
+\r
+ private PmdModel model;\r
+ private PmdParser parser;\r
+ private TextBuilder textBuilder;\r
+\r
+ private boolean loaded = false;\r
+ private boolean hasMoreData = false;\r
+\r
+ /**\r
+ * コンストラクタ。\r
+ * @param source PMDファイル入力ソース\r
+ */\r
+ public PmdLoader(MmdSource source){\r
+ super();\r
+\r
+ this.model = new PmdModel();\r
+ this.parser = new PmdParser(source);\r
+ this.textBuilder = new TextBuilder(this.model);\r
+\r
+ setHandler();\r
+\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * パーサに各種ハンドラの設定を行う。\r
+ */\r
+ private void setHandler(){\r
+ ShapeBuilder shapeBuilder = new ShapeBuilder(this.model);\r
+ MaterialBuilder materialBuilder = new MaterialBuilder(this.model);\r
+ BoneBuilder boneBuilder = new BoneBuilder(this.model);\r
+ MorphBuilder morphBuilder = new MorphBuilder(this.model);\r
+ ToonBuilder toonBuilder = new ToonBuilder(this.model);\r
+ RigidBuilder rigidBuilder = new RigidBuilder(this.model);\r
+ JointBuilder jointBuilder = new JointBuilder(this.model);\r
+\r
+ this.parser.setBasicHandler(this.textBuilder);\r
+ this.parser.setShapeHandler(shapeBuilder);\r
+ this.parser.setMaterialHandler(materialBuilder);\r
+ this.parser.setBoneHandler(boneBuilder);\r
+ this.parser.setMorphHandler(morphBuilder);\r
+ this.parser.setEngHandler(this.textBuilder);\r
+ this.parser.setToonHandler(toonBuilder);\r
+ this.parser.setRigidHandler(rigidBuilder);\r
+ this.parser.setJointHandler(jointBuilder);\r
+\r
+ List<MorphPart> morphPartList = new ArrayList<MorphPart>();\r
+ morphBuilder.setMorphPartList(morphPartList);\r
+ this.textBuilder.setMorphPartList(morphPartList);\r
+ morphPartList.clear();\r
+\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * PMDファイルの読み込みを行いモデル情報を返す。\r
+ * 1インスタンスにつき一度しかロードできない。\r
+ * @return モデル情報\r
+ * @throws IOException 入力エラー\r
+ * @throws MmdFormatException PMDファイルフォーマットの異常を検出\r
+ * @throws IllegalStateException このインスタンスで再度のロードを試みた。\r
+ */\r
+ public PmdModel load()\r
+ throws IOException,\r
+ MmdFormatException,\r
+ IllegalStateException {\r
+ if(this.loaded) throw new IllegalStateException();\r
+\r
+ PmdModel result;\r
+ try{\r
+ this.parser.parsePmd();\r
+ }finally{\r
+ this.loaded = true;\r
+\r
+ result = this.model;\r
+ this.hasMoreData = this.textBuilder.hasMoreData();\r
+\r
+ this.model = null;\r
+ this.parser = null;\r
+ this.textBuilder = null;\r
+ }\r
+\r
+ return result;\r
+ }\r
+\r
+ /**\r
+ * ロード処理が正常終了したのにまだ読み込んでいない部分が放置されているか判定する。\r
+ * MMDでの仕様拡張によるPMDファイルフォーマットの拡張が行われた場合を想定。\r
+ * @return 読み込んでいない部分があればtrue\r
+ */\r
+ public boolean hasMoreData(){\r
+ return this.hasMoreData;\r
+ }\r
+\r
+}\r
--- /dev/null
+/*\r
+ * building rigid information\r
+ *\r
+ * License : The MIT License\r
+ * Copyright(c) 2010 MikuToga Partners\r
+ */\r
+\r
+package jp.sourceforge.mikutoga.pmd.pmdloader;\r
+\r
+import jp.sourceforge.mikutoga.corelib.ListUtil;\r
+import java.util.Iterator;\r
+import java.util.List;\r
+import jp.sourceforge.mikutoga.parser.ParseStage;\r
+import jp.sourceforge.mikutoga.parser.pmd.PmdLimits;\r
+import jp.sourceforge.mikutoga.parser.pmd.PmdRigidHandler;\r
+import jp.sourceforge.mikutoga.pmd.BoneInfo;\r
+import jp.sourceforge.mikutoga.pmd.DynamicsInfo;\r
+import jp.sourceforge.mikutoga.pmd.PmdModel;\r
+import jp.sourceforge.mikutoga.pmd.Pos3d;\r
+import jp.sourceforge.mikutoga.pmd.Rad3d;\r
+import jp.sourceforge.mikutoga.pmd.RigidBehaviorType;\r
+import jp.sourceforge.mikutoga.pmd.RigidGroup;\r
+import jp.sourceforge.mikutoga.pmd.RigidInfo;\r
+import jp.sourceforge.mikutoga.pmd.RigidShape;\r
+import jp.sourceforge.mikutoga.pmd.RigidShapeType;\r
+\r
+/**\r
+ * 剛体関係の通知をパーサから受け取る。\r
+ */\r
+class RigidBuilder implements PmdRigidHandler {\r
+\r
+ private final List<BoneInfo> boneList;\r
+\r
+ private final List<RigidInfo> rigidList;\r
+ private Iterator<RigidInfo> rigidIt;\r
+ private RigidInfo currentRigid = null;\r
+\r
+ private final List<RigidGroup> rigidGroupList;\r
+\r
+ /**\r
+ * コンストラクタ。\r
+ * @param model モデル\r
+ */\r
+ RigidBuilder(PmdModel model){\r
+ super();\r
+ this.boneList = model.getBoneList();\r
+ this.rigidList = model.getRigidList();\r
+ this.rigidGroupList = model.getRigidGroupList();\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param stage {@inheritDoc}\r
+ * @param loops {@inheritDoc}\r
+ */\r
+ public void loopStart(ParseStage stage, int loops){\r
+ ListUtil.prepareDefConsList(this.rigidList, RigidInfo.class, loops);\r
+ ListUtil.assignIndexedSerial(this.rigidList);\r
+\r
+ this.rigidIt = this.rigidList.iterator();\r
+ if(this.rigidIt.hasNext()){\r
+ this.currentRigid = this.rigidIt.next();\r
+ }\r
+\r
+ ListUtil.prepareDefConsList(this.rigidGroupList,\r
+ RigidGroup.class,\r
+ PmdLimits.RIGIDGROUP_FIXEDNUM );\r
+ ListUtil.assignIndexedSerial(this.rigidGroupList);\r
+\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param stage {@inheritDoc}\r
+ */\r
+ public void loopNext(ParseStage stage){\r
+ if(this.rigidIt.hasNext()){\r
+ this.currentRigid = this.rigidIt.next();\r
+ }\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param stage {@inheritDoc}\r
+ */\r
+ public void loopEnd(ParseStage stage){\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param rigidName {@inheritDoc}\r
+ */\r
+ public void pmdRigidName(String rigidName){\r
+ this.currentRigid.getRigidName().setPrimaryText(rigidName);\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param rigidGroupId {@inheritDoc}\r
+ * @param linkedBoneId {@inheritDoc}\r
+ */\r
+ public void pmdRigidInfo(int rigidGroupId, int linkedBoneId){\r
+ BoneInfo bone = this.boneList.get(linkedBoneId);\r
+ RigidGroup group = this.rigidGroupList.get(rigidGroupId);\r
+\r
+ this.currentRigid.setLinkedBone(bone);\r
+ this.currentRigid.setRigidGroup(group);\r
+ group.getRigidList().add(this.currentRigid);\r
+\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param shapeType {@inheritDoc}\r
+ * @param width {@inheritDoc}\r
+ * @param height {@inheritDoc}\r
+ * @param depth {@inheritDoc}\r
+ */\r
+ public void pmdRigidShape(byte shapeType,\r
+ float width, float height, float depth){\r
+ RigidShape shape = this.currentRigid.getRigidShape();\r
+\r
+ shape.setWidth(width);\r
+ shape.setHeight(height);\r
+ shape.setDepth(depth);\r
+\r
+ RigidShapeType type = RigidShapeType.decode(shapeType);\r
+ shape.setShapeType(type);\r
+\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param posX {@inheritDoc}\r
+ * @param posY {@inheritDoc}\r
+ * @param posZ {@inheritDoc}\r
+ */\r
+ public void pmdRigidPosition(float posX, float posY, float posZ){\r
+ Pos3d position = this.currentRigid.getPosition();\r
+ position.setXPos(posX);\r
+ position.setYPos(posY);\r
+ position.setZPos(posZ);\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param radX {@inheritDoc}\r
+ * @param radY {@inheritDoc}\r
+ * @param radZ {@inheritDoc}\r
+ */\r
+ public void pmdRigidRotation(float radX, float radY, float radZ){\r
+ Rad3d rotation = this.currentRigid.getRotation();\r
+ rotation.setXRad(radX);\r
+ rotation.setYRad(radY);\r
+ rotation.setZRad(radZ);\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param mass {@inheritDoc}\r
+ * @param dampingPos {@inheritDoc}\r
+ * @param dampingRot {@inheritDoc}\r
+ * @param restitution {@inheritDoc}\r
+ * @param friction {@inheritDoc}\r
+ */\r
+ public void pmdRigidPhysics(float mass,\r
+ float dampingPos,\r
+ float dampingRot,\r
+ float restitution,\r
+ float friction ){\r
+ DynamicsInfo info = this.currentRigid.getDynamicsInfo();\r
+\r
+ info.setMass(mass);\r
+ info.setDampingPosition(dampingPos);\r
+ info.setDampingRotation(dampingRot);\r
+ info.setRestitution(restitution);\r
+ info.setFriction(friction);\r
+\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param behaveType {@inheritDoc}\r
+ * @param collisionMap {@inheritDoc}\r
+ */\r
+ public void pmdRigidBehavior(byte behaveType, short collisionMap){\r
+ RigidBehaviorType type = RigidBehaviorType.decode(behaveType);\r
+ this.currentRigid.setBehaviorType(type);\r
+\r
+ for(int bitPos = 0; bitPos < PmdLimits.RIGIDGROUP_FIXEDNUM; bitPos++){\r
+ short mask = 0x0001;\r
+ mask <<= bitPos;\r
+ if((collisionMap & mask) == 0){\r
+ RigidGroup group = this.rigidGroupList.get(bitPos);\r
+ this.currentRigid.getThroughGroupColl().add(group);\r
+ }\r
+ }\r
+\r
+ return;\r
+ }\r
+\r
+}\r
--- /dev/null
+/*\r
+ * building shape information\r
+ *\r
+ * License : The MIT License\r
+ * Copyright(c) 2010 MikuToga Partners\r
+ */\r
+\r
+package jp.sourceforge.mikutoga.pmd.pmdloader;\r
+\r
+import jp.sourceforge.mikutoga.corelib.ListUtil;\r
+import java.util.Iterator;\r
+import java.util.List;\r
+import java.util.RandomAccess;\r
+import jp.sourceforge.mikutoga.parser.ParseStage;\r
+import jp.sourceforge.mikutoga.parser.pmd.PmdShapeHandler;\r
+import jp.sourceforge.mikutoga.pmd.BoneInfo;\r
+import jp.sourceforge.mikutoga.pmd.PmdModel;\r
+import jp.sourceforge.mikutoga.pmd.Pos2d;\r
+import jp.sourceforge.mikutoga.pmd.Pos3d;\r
+import jp.sourceforge.mikutoga.pmd.Surface;\r
+import jp.sourceforge.mikutoga.pmd.Vec3d;\r
+import jp.sourceforge.mikutoga.pmd.Vertex;\r
+\r
+/**\r
+ * モデル形状に関する通知をパーサから受け取る。\r
+ */\r
+class ShapeBuilder implements PmdShapeHandler {\r
+\r
+ private final List<Vertex> vertexList;\r
+ private final List<BoneInfo> boneList;\r
+ private final List<Surface> surfaceList;\r
+\r
+ private Iterator<Vertex> vertexIt;\r
+ private Vertex currentVertex = null;\r
+\r
+ private Iterator<Surface> surfaceIt;\r
+ private Surface currentSurface = null;\r
+\r
+ /**\r
+ * コンストラクタ。\r
+ * @param model モデル\r
+ */\r
+ ShapeBuilder(PmdModel model){\r
+ super();\r
+\r
+ this.vertexList = model.getVertexList();\r
+ this.boneList = model.getBoneList();\r
+ this.surfaceList = model.getSurfaceList();\r
+\r
+ assert this.vertexList instanceof RandomAccess;\r
+ assert this.surfaceList instanceof RandomAccess;\r
+ assert this.boneList instanceof RandomAccess;\r
+\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * ボーンリスト上にボーンを用意する。\r
+ * すでに指定位置にボーンがあればなにもしない。\r
+ * @param id 0から始まるボーン番号\r
+ * @return 用意されたボーン\r
+ */\r
+ private BoneInfo prepareBone(int id){\r
+ ListUtil.extendCollection(this.boneList, id + 1);\r
+ BoneInfo bone = this.boneList.get(id);\r
+ if(bone == null){\r
+ bone = new BoneInfo();\r
+ bone.setSerialNumber(id);\r
+ this.boneList.set(id, bone);\r
+ }\r
+ return bone;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param stage {@inheritDoc}\r
+ * @param loops {@inheritDoc}\r
+ */\r
+ public void loopStart(ParseStage stage, int loops){\r
+ if(stage == PmdShapeHandler.VERTEX_LIST){\r
+ ListUtil.prepareDefConsList(this.vertexList, Vertex.class, loops);\r
+ ListUtil.assignIndexedSerial(this.vertexList);\r
+\r
+ this.vertexIt = this.vertexList.iterator();\r
+ if(this.vertexIt.hasNext()){\r
+ this.currentVertex = this.vertexIt.next();\r
+ }\r
+ }else if(stage == PmdShapeHandler.SURFACE_LIST){\r
+ ListUtil.prepareDefConsList(this.surfaceList,\r
+ Surface.class, loops );\r
+ ListUtil.assignIndexedSerial(this.surfaceList);\r
+\r
+ this.surfaceIt = this.surfaceList.iterator();\r
+ if(this.surfaceIt.hasNext()){\r
+ this.currentSurface = this.surfaceIt.next();\r
+ }\r
+ }else{\r
+ assert false;\r
+ throw new AssertionError();\r
+ }\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param stage {@inheritDoc}\r
+ */\r
+ public void loopNext(ParseStage stage){\r
+ if(stage == PmdShapeHandler.VERTEX_LIST){\r
+ if(this.vertexIt.hasNext()){\r
+ this.currentVertex = this.vertexIt.next();\r
+ }\r
+ }else if(stage == PmdShapeHandler.SURFACE_LIST){\r
+ if(this.surfaceIt.hasNext()){\r
+ this.currentSurface = this.surfaceIt.next();\r
+ }\r
+ }else{\r
+ assert false;\r
+ throw new AssertionError();\r
+ }\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param stage {@inheritDoc}\r
+ */\r
+ public void loopEnd(ParseStage stage){\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param xPos {@inheritDoc}\r
+ * @param yPos {@inheritDoc}\r
+ * @param zPos {@inheritDoc}\r
+ */\r
+ public void pmdVertexPosition(float xPos, float yPos, float zPos){\r
+ Pos3d position = this.currentVertex.getPosition();\r
+ position.setXPos(xPos);\r
+ position.setYPos(yPos);\r
+ position.setZPos(zPos);\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param xVec {@inheritDoc}\r
+ * @param yVec {@inheritDoc}\r
+ * @param zVec {@inheritDoc}\r
+ */\r
+ public void pmdVertexNormal(float xVec, float yVec, float zVec){\r
+ Vec3d normal = this.currentVertex.getNormal();\r
+ normal.setXVal(xVec);\r
+ normal.setYVal(yVec);\r
+ normal.setZVal(zVec);\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param uVal {@inheritDoc}\r
+ * @param vVal {@inheritDoc}\r
+ */\r
+ public void pmdVertexUV(float uVal, float vVal){\r
+ Pos2d uv = this.currentVertex.getUVPosition();\r
+ uv.setXPos(uVal);\r
+ uv.setYPos(vVal);\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param boneId1 {@inheritDoc}\r
+ * @param boneId2 {@inheritDoc}\r
+ * @param weightForB1 {@inheritDoc}\r
+ */\r
+ public void pmdVertexWeight(int boneId1, int boneId2, int weightForB1){\r
+ BoneInfo bone1 = prepareBone(boneId1);\r
+ BoneInfo bone2 = prepareBone(boneId2);\r
+\r
+ this.currentVertex.setBonePair(bone1, bone2);\r
+ this.currentVertex.setWeightA(weightForB1);\r
+\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param hideEdge {@inheritDoc}\r
+ */\r
+ public void pmdVertexEdge(boolean hideEdge){\r
+ this.currentVertex.setEdgeAppearance( ! hideEdge );\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param vertexId1 {@inheritDoc}\r
+ * @param vertexId2 {@inheritDoc}\r
+ * @param vertexId3 {@inheritDoc}\r
+ */\r
+ public void pmdSurfaceTriangle(int vertexId1,\r
+ int vertexId2,\r
+ int vertexId3 ){\r
+ Vertex vtx1 = this.vertexList.get(vertexId1);\r
+ Vertex vtx2 = this.vertexList.get(vertexId2);\r
+ Vertex vtx3 = this.vertexList.get(vertexId3);\r
+\r
+ this.currentSurface.setTriangle(vtx1, vtx2, vtx3);\r
+\r
+ return;\r
+ }\r
+\r
+}\r
--- /dev/null
+/*\r
+ * building text info\r
+ *\r
+ * License : The MIT License\r
+ * Copyright(c) 2010 MikuToga Partners\r
+ */\r
+\r
+package jp.sourceforge.mikutoga.pmd.pmdloader;\r
+\r
+import java.util.Iterator;\r
+import java.util.List;\r
+import jp.sourceforge.mikutoga.corelib.I18nText;\r
+import jp.sourceforge.mikutoga.parser.ParseStage;\r
+import jp.sourceforge.mikutoga.parser.pmd.PmdBasicHandler;\r
+import jp.sourceforge.mikutoga.parser.pmd.PmdEngHandler;\r
+import jp.sourceforge.mikutoga.pmd.BoneGroup;\r
+import jp.sourceforge.mikutoga.pmd.BoneInfo;\r
+import jp.sourceforge.mikutoga.pmd.MorphPart;\r
+import jp.sourceforge.mikutoga.pmd.PmdModel;\r
+\r
+/**\r
+ * テキスト関係の通知をパーサから受け取る。\r
+ */\r
+class TextBuilder implements PmdBasicHandler, PmdEngHandler {\r
+\r
+ private final PmdModel model;\r
+\r
+ private final I18nText modelName;\r
+ private final I18nText description;\r
+\r
+ private final List<BoneInfo> boneList;\r
+ private Iterator<BoneInfo> boneIt;\r
+ private BoneInfo currentBone = null;\r
+\r
+ private List<MorphPart> morphPartList;\r
+ private Iterator<MorphPart> morphPartIt;\r
+ private MorphPart currentMorphPart = null;\r
+\r
+ private final List<BoneGroup> boneGroupList;\r
+ private Iterator<BoneGroup> boneGroupIt;\r
+ private BoneGroup currentBoneGroup = null;\r
+\r
+ private boolean hasMoreData = false;\r
+\r
+ /**\r
+ * コンストラクタ。\r
+ * @param model モデル\r
+ */\r
+ TextBuilder(PmdModel model){\r
+ super();\r
+\r
+ this.model = model;\r
+\r
+ this.modelName = model.getModelName();\r
+ this.description = model.getDescription();\r
+\r
+ this.boneList = model.getBoneList();\r
+ this.boneGroupList = model.getBoneGroupList();\r
+\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * PMDファイル中の出現順で各モーフを格納するためのリストを設定する。\r
+ * 主な用途はモーフ和英名の突き合わせ作業。\r
+ * @param list モーフ格納リスト\r
+ */\r
+ void setMorphPartList(List<MorphPart> list){\r
+ this.morphPartList = list;\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ */\r
+ public void pmdParseStart(){\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param hasMoreData {@inheritDoc}\r
+ */\r
+ public void pmdParseEnd(boolean hasMoreData){\r
+ this.hasMoreData = hasMoreData;\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param stage {@inheritDoc}\r
+ * @param loops {@inheritDoc}\r
+ */\r
+ public void loopStart(ParseStage stage, int loops){\r
+ assert stage instanceof PmdEngStage;\r
+\r
+ if(stage == PmdEngHandler.ENGBONE_LIST){\r
+ this.boneIt = this.boneList.iterator();\r
+ if(this.boneIt.hasNext()){\r
+ this.currentBone = this.boneIt.next();\r
+ }\r
+ }else if(stage == PmdEngHandler.ENGMORPH_LIST){\r
+ this.morphPartIt = this.morphPartList.iterator();\r
+\r
+ // 「base」モーフを読み飛ばす\r
+ assert this.morphPartIt.hasNext();\r
+ MorphPart part = this.morphPartIt.next();\r
+ assert part != null;\r
+\r
+ if(this.morphPartIt.hasNext()){\r
+ this.currentMorphPart = this.morphPartIt.next();\r
+ }\r
+ }else if(stage == PmdEngHandler.ENGBONEGROUP_LIST){\r
+ this.boneGroupIt = this.boneGroupList.iterator();\r
+\r
+ // デフォルトボーングループを読み飛ばす\r
+ assert this.boneGroupIt.hasNext();\r
+ BoneGroup group = this.boneGroupIt.next();\r
+ assert group != null;\r
+\r
+ if(this.boneGroupIt.hasNext()){\r
+ this.currentBoneGroup = this.boneGroupIt.next();\r
+ }\r
+ }else{\r
+ assert false;\r
+ throw new AssertionError();\r
+ }\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param stage {@inheritDoc}\r
+ */\r
+ public void loopNext(ParseStage stage){\r
+ assert stage instanceof PmdEngStage;\r
+\r
+ if(stage == PmdEngHandler.ENGBONE_LIST){\r
+ if(this.boneIt.hasNext()){\r
+ this.currentBone = this.boneIt.next();\r
+ }\r
+ }else if(stage == PmdEngHandler.ENGMORPH_LIST){\r
+ if(this.morphPartIt.hasNext()){\r
+ this.currentMorphPart = this.morphPartIt.next();\r
+ }\r
+ }else if(stage == PmdEngHandler.ENGBONEGROUP_LIST){\r
+ if(this.boneGroupIt.hasNext()){\r
+ this.currentBoneGroup = this.boneGroupIt.next();\r
+ }\r
+ }else{\r
+ assert false;\r
+ throw new AssertionError();\r
+ }\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param stage {@inheritDoc}\r
+ */\r
+ public void loopEnd(ParseStage stage){\r
+ assert stage instanceof PmdEngStage;\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param ver {@inheritDoc}\r
+ */\r
+ public void pmdHeaderInfo(float ver){\r
+ this.model.setHeaderVersion(ver);\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param modelName {@inheritDoc}\r
+ * @param description {@inheritDoc}\r
+ */\r
+ public void pmdModelInfo(String modelName, String description){\r
+ this.modelName .setPrimaryText(modelName);\r
+ this.description.setPrimaryText(description);\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param hasEnglishInfo {@inheritDoc}\r
+ */\r
+ public void pmdEngEnabled(boolean hasEnglishInfo){\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param modelName {@inheritDoc}\r
+ * @param description {@inheritDoc}\r
+ */\r
+ public void pmdEngModelInfo(String modelName, String description){\r
+ this.modelName .setGlobalText(modelName);\r
+ this.description.setGlobalText(description);\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param boneName {@inheritDoc}\r
+ */\r
+ public void pmdEngBoneInfo(String boneName){\r
+ this.currentBone.getBoneName().setGlobalText(boneName);\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param morphName {@inheritDoc}\r
+ */\r
+ public void pmdEngMorphInfo(String morphName){\r
+ this.currentMorphPart.getMorphName().setGlobalText(morphName);\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param groupName {@inheritDoc}\r
+ */\r
+ public void pmdEngBoneGroupInfo(String groupName){\r
+ this.currentBoneGroup.getGroupName().setGlobalText(groupName);\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * 読み残したデータがあるか判定する。\r
+ * @return 読み残したデータがあればtrue\r
+ */\r
+ public boolean hasMoreData(){\r
+ return this.hasMoreData;\r
+ }\r
+\r
+}\r
--- /dev/null
+/*\r
+ * building toon information\r
+ *\r
+ * License : The MIT License\r
+ * Copyright(c) 2010 MikuToga Partners\r
+ */\r
+\r
+package jp.sourceforge.mikutoga.pmd.pmdloader;\r
+\r
+import jp.sourceforge.mikutoga.parser.ParseStage;\r
+import jp.sourceforge.mikutoga.parser.pmd.PmdLimits;\r
+import jp.sourceforge.mikutoga.parser.pmd.PmdToonHandler;\r
+import jp.sourceforge.mikutoga.pmd.PmdModel;\r
+import jp.sourceforge.mikutoga.pmd.ToonMap;\r
+\r
+/**\r
+ * トゥーン関係の通知をパーサから受け取る。\r
+ */\r
+class ToonBuilder implements PmdToonHandler {\r
+\r
+ private final PmdModel model;\r
+\r
+ private ToonMap toonMap;\r
+ private int index;\r
+\r
+ /**\r
+ * コンストラクタ。\r
+ * @param model モデル\r
+ */\r
+ ToonBuilder(PmdModel model){\r
+ this.model = model;\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param stage {@inheritDoc}\r
+ * @param loops {@inheritDoc}\r
+ */\r
+ public void loopStart(ParseStage stage, int loops){\r
+ assert stage == PmdToonHandler.TOON_LIST;\r
+ assert loops == PmdLimits.TOON_FIXEDNUM;\r
+\r
+ this.toonMap = new ToonMap();\r
+ this.index = 0;\r
+\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param stage {@inheritDoc}\r
+ */\r
+ public void loopNext(ParseStage stage){\r
+ assert stage == PmdToonHandler.TOON_LIST;\r
+ this.index++;\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param stage {@inheritDoc}\r
+ */\r
+ public void loopEnd(ParseStage stage){\r
+ assert stage == PmdToonHandler.TOON_LIST;\r
+ this.model.setToonMap(this.toonMap);\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param toonFileName {@inheritDoc}\r
+ */\r
+ public void pmdToonFileInfo(String toonFileName){\r
+ this.toonMap.setIndexedToon(this.index, toonFileName);\r
+ return;\r
+ }\r
+\r
+}\r
--- /dev/null
+/*\r
+ * package information for Javadoc\r
+ *\r
+ * License : The MIT License\r
+ * Copyright(c) 2010 MikuToga Partners\r
+ */\r
+\r
+/**\r
+ * PMDモデルファイルをパースし、\r
+ * 内容を反映したオブジェクト群を構築するためのライブラリ。\r
+ */\r
+\r
+package jp.sourceforge.mikutoga.pmd.pmdloader;\r
+\r
+/* EOF */\r
--- /dev/null
+/*\r
+ * pmd-xml exporter\r
+ *\r
+ * License : The MIT License\r
+ * Copyright(c) 2010 MikuToga Partners\r
+ */\r
+\r
+package jp.sourceforge.mikutoga.pmd.xml;\r
+\r
+import java.awt.Color;\r
+import java.io.IOException;\r
+import java.io.OutputStream;\r
+import java.util.List;\r
+import java.util.Map;\r
+import jp.sourceforge.mikutoga.corelib.I18nText;\r
+import jp.sourceforge.mikutoga.corelib.SerialNumbered;\r
+import jp.sourceforge.mikutoga.pmd.BoneGroup;\r
+import jp.sourceforge.mikutoga.pmd.BoneInfo;\r
+import jp.sourceforge.mikutoga.pmd.BoneType;\r
+import jp.sourceforge.mikutoga.pmd.Deg3d;\r
+import jp.sourceforge.mikutoga.pmd.DynamicsInfo;\r
+import jp.sourceforge.mikutoga.pmd.IKChain;\r
+import jp.sourceforge.mikutoga.pmd.JointInfo;\r
+import jp.sourceforge.mikutoga.pmd.Material;\r
+import jp.sourceforge.mikutoga.pmd.MorphPart;\r
+import jp.sourceforge.mikutoga.pmd.MorphType;\r
+import jp.sourceforge.mikutoga.pmd.MorphVertex;\r
+import jp.sourceforge.mikutoga.pmd.PmdModel;\r
+import jp.sourceforge.mikutoga.pmd.Pos2d;\r
+import jp.sourceforge.mikutoga.pmd.Pos3d;\r
+import jp.sourceforge.mikutoga.pmd.Rad3d;\r
+import jp.sourceforge.mikutoga.pmd.RigidGroup;\r
+import jp.sourceforge.mikutoga.pmd.RigidInfo;\r
+import jp.sourceforge.mikutoga.pmd.RigidShape;\r
+import jp.sourceforge.mikutoga.pmd.RigidShapeType;\r
+import jp.sourceforge.mikutoga.pmd.ShadeInfo;\r
+import jp.sourceforge.mikutoga.pmd.Surface;\r
+import jp.sourceforge.mikutoga.pmd.ToonMap;\r
+import jp.sourceforge.mikutoga.pmd.TripletRange;\r
+import jp.sourceforge.mikutoga.pmd.Vec3d;\r
+import jp.sourceforge.mikutoga.pmd.Vertex;\r
+import jp.sourceforge.mikutoga.xml.BasicXmlExporter;\r
+import jp.sourceforge.mikutoga.xml.XmlResourceResolver;\r
+\r
+/**\r
+ * XML形式でPMDモデルデータを出力する。\r
+ */\r
+public class PmdXmlExporter extends BasicXmlExporter{\r
+\r
+ private static final String GENERATOR = "Mikutoga" + " Ver 0.0.1";\r
+ private static final String TOP_COMMENT =\r
+ " MikuMikuDance\n model-data(*.pmd) on XML";\r
+ private static final String SCHEMA_LOCATION =\r
+ PmdXmlResources.NS_PMDXML + " " + PmdXmlResources.SCHEMA_PMDXML;\r
+\r
+ /** 改行文字列 CR。 */\r
+ private static final String CR = "\r"; // 0x0d\r
+ /** 改行文字列 LF。 */\r
+ private static final String LF = "\n"; // 0x0a\r
+ /** 改行文字列 CRLF。 */\r
+ private static final String CRLF = CR + LF; // 0x0d, 0x0a\r
+\r
+ private static final String PFX_SURFACEGROUP = "sg";\r
+ private static final String PFX_TOONFILE = "tf";\r
+ private static final String PFX_VERTEX = "vtx";\r
+ private static final String PFX_BONE = "bn";\r
+ private static final String PFX_RIGID = "rd";\r
+ private static final String PFX_RIGIDGROUP = "rg";\r
+\r
+ private static final String BONETYPE_COMMENT =\r
+ "Bone types:\n"\r
+ + "[0 : ROTATE : Rotate : 回転 :]\n"\r
+ + "[1 : ROTMOV : Rotate/Move : 回転/移動 :]\n"\r
+ + "[2 : IK : IK : IK :]\n"\r
+ + "[3 : UNKNOWN : Unknown : 不明 :]\n"\r
+ + "[4 : UNDERIK : Under IK : IK影響下(回転) :]\n"\r
+ + "[5 : UNDERROT : Under rotate : 回転影響下 :]\n"\r
+ + "[6 : IKCONNECTED : IK connected : IK接続先 :]\n"\r
+ + "[7 : HIDDEN : Hidden : 非表示 :]\n"\r
+ + "[8 : TWIST : Twist : 捩り :]\n"\r
+ + "[9 : LINKEDROT : Linked Rotate: 回転連動 :]\n";\r
+\r
+ private static final String MORPHTYPE_COMMENT =\r
+ "Morph types:\n"\r
+ + "[1 : EYEBROW : まゆ ]\n"\r
+ + "[2 : EYE : 目 ]\n"\r
+ + "[3 : LIP : リップ ]\n"\r
+ + "[4 : EXTRA : その他 ]\n";\r
+\r
+ private static final String RIGIDBEHAVIOR_COMMENT =\r
+ "Rigid behavior types:\n"\r
+ + "[0 : FOLLOWBONE : ボーン追従 ]\n"\r
+ + "[1 : ONLYDYNAMICS : 物理演算 ]\n"\r
+ + "[2 : BONEDDYNAMICS : ボーン位置合わせ ]\n";\r
+\r
+ /**\r
+ * コンストラクタ。\r
+ * 文字エンコーディングはUTF-8が用いられる。\r
+ * @param stream 出力ストリーム\r
+ */\r
+ public PmdXmlExporter(OutputStream stream){\r
+ super(stream);\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * 任意の文字列がBasicLatin文字のみから構成されるか判定する。\r
+ * @param seq 文字列\r
+ * @return null、長さ0もしくはBasicLatin文字のみから構成されるならtrue\r
+ */\r
+ public static boolean hasOnlyBasicLatin(CharSequence seq){\r
+ if(seq == null) return true;\r
+ int length = seq.length();\r
+ for(int pos = 0; pos < length; pos++){\r
+ char ch = seq.charAt(pos);\r
+ if(ch > 0x007f) return false;\r
+ }\r
+ return true;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @return {@inheritDoc}\r
+ * @throws IOException {@inheritDoc}\r
+ */\r
+ @Override\r
+ public PmdXmlExporter ind() throws IOException{\r
+ super.ind();\r
+ return this;\r
+ }\r
+\r
+ /**\r
+ * 文字参照によるエスケープを補佐するためのコメントを出力する。\r
+ * @param seq 文字列\r
+ * @return this本体\r
+ * @throws IOException 出力エラー\r
+ */\r
+ protected PmdXmlExporter putUnescapedComment(CharSequence seq)\r
+ throws IOException{\r
+ if( ! isBasicLatinOnlyOut() ) return this;\r
+ if(hasOnlyBasicLatin(seq)) return this;\r
+ put(' ').putLineComment(seq);\r
+ return this;\r
+ }\r
+\r
+ /**\r
+ * 多言語化された各種識別名を出力する。\r
+ * プライマリ名は出力対象外。\r
+ * @param text 多言語文字列\r
+ * @return this本体\r
+ * @throws IOException 出力エラー\r
+ */\r
+ protected PmdXmlExporter putI18nName(I18nText text) throws IOException{\r
+ for(String lang639 : text.lang639CodeList()){\r
+ if(lang639.equals(I18nText.CODE639_PRIMARY)) continue;\r
+ String name = text.getText(lang639);\r
+ ind().put("<i18nName ");\r
+ putAttr("lang", lang639).put(' ');\r
+ putAttr("name", name);\r
+ put(" />");\r
+ putUnescapedComment(name);\r
+ ln();\r
+ }\r
+ return this;\r
+ }\r
+\r
+ /**\r
+ * 番号付けされたID(IDREF)属性を出力する。\r
+ * @param attrName 属性名\r
+ * @param prefix IDプレフィクス\r
+ * @param num 番号\r
+ * @return this本体\r
+ * @throws IOException 出力エラー\r
+ */\r
+ protected PmdXmlExporter putNumberedIdAttr(CharSequence attrName,\r
+ CharSequence prefix,\r
+ int num )\r
+ throws IOException{\r
+ put(attrName).put("=\"");\r
+ put(prefix).put(num);\r
+ put('"');\r
+ return this;\r
+ }\r
+\r
+ /**\r
+ * 番号付けされたID(IDREF)属性を出力する。\r
+ * @param attrName 属性名\r
+ * @param prefix IDプレフィクス\r
+ * @param numbered 番号付けされたオブジェクト\r
+ * @return this本体\r
+ * @throws IOException 出力エラー\r
+ */\r
+ protected PmdXmlExporter putNumberedIdAttr(CharSequence attrName,\r
+ CharSequence prefix,\r
+ SerialNumbered numbered )\r
+ throws IOException{\r
+ putNumberedIdAttr(attrName, prefix, numbered.getSerialNumber());\r
+ return this;\r
+ }\r
+\r
+ /**\r
+ * 位置情報を出力する。\r
+ * @param position 位置情報\r
+ * @return this本体\r
+ * @throws IOException 出力エラー\r
+ */\r
+ protected PmdXmlExporter putPosition(Pos3d position) throws IOException{\r
+ put("<position ");\r
+ putFloatAttr("x", position.getXPos()).put(' ');\r
+ putFloatAttr("y", position.getYPos()).put(' ');\r
+ putFloatAttr("z", position.getZPos()).put(' ');\r
+ put("/>");\r
+ return this;\r
+ }\r
+\r
+ /**\r
+ * 姿勢情報(ラジアン)を出力する。\r
+ * @param rotation 姿勢情報\r
+ * @return this本体\r
+ * @throws IOException 出力エラー\r
+ */\r
+ protected PmdXmlExporter putRadRotation(Rad3d rotation)\r
+ throws IOException{\r
+ put("<radRotation ");\r
+ putFloatAttr("xRad", rotation.getXRad()).put(' ');\r
+ putFloatAttr("yRad", rotation.getYRad()).put(' ');\r
+ putFloatAttr("zRad", rotation.getZRad()).put(' ');\r
+ put("/>");\r
+ return this;\r
+ }\r
+\r
+ /**\r
+ * 多言語識別名属性のローカルな名前をコメント出力する。\r
+ * @param name 多言語識別名\r
+ * @return this本体\r
+ * @throws IOException 出力エラー\r
+ */\r
+ protected PmdXmlExporter putLocalNameComment(I18nText name)\r
+ throws IOException{\r
+ String localName = name.getText();\r
+ ind().putLineComment(localName);\r
+ return this;\r
+ }\r
+\r
+ /**\r
+ * 多言語識別名属性のプライマリな名前を出力する。\r
+ * @param attrName 属性名\r
+ * @param name 多言語識別名\r
+ * @return this本体\r
+ * @throws IOException 出力エラー\r
+ */\r
+ protected PmdXmlExporter putPrimaryNameAttr(CharSequence attrName,\r
+ I18nText name)\r
+ throws IOException{\r
+ String primaryName = name.getPrimaryText();\r
+ putAttr(attrName, primaryName);\r
+ return this;\r
+ }\r
+\r
+ /**\r
+ * PMDモデルデータをXML形式で出力する。\r
+ * @param model PMDモデルデータ\r
+ * @throws IOException 出力エラー\r
+ */\r
+ public void putPmdModel(PmdModel model) throws IOException{\r
+ ind().put("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>").ln(2);\r
+\r
+ ind().putBlockComment(TOP_COMMENT).ln(2);\r
+\r
+ ind().put("<!DOCTYPE pmdModel").ln();\r
+ ind().put(" SYSTEM \"")\r
+ .put(PmdXmlResources.DTD_PMDXML)\r
+ .put("\" >")\r
+ .ln(3);\r
+\r
+ I18nText modelName = model.getModelName();\r
+ ind().putLocalNameComment(modelName).ln();\r
+ ind().put("<pmdModel").ln();\r
+ pushNest();\r
+ ind().putAttr("xmlns", PmdXmlResources.NS_PMDXML).ln();\r
+ ind().putAttr("xmlns:xsi", XmlResourceResolver.NS_XSD).ln();\r
+ ind().putAttr("xsi:schemaLocation", SCHEMA_LOCATION).ln();\r
+ ind().putAttr("schemaVersion", PmdXmlResources.VER_PMDXML).ln(2);\r
+ ind().putPrimaryNameAttr("name", modelName).ln();\r
+ popNest();\r
+ put(">").ln(2);\r
+\r
+ putModelInfo(model).flush();\r
+ putMetaInfo(model).flush();\r
+ putMaterialList(model).flush();\r
+ putToonMap(model).flush();\r
+ putBoneList(model).flush();\r
+ putBoneGroupList(model).flush();\r
+ putIKChainList(model).flush();\r
+ putMorphList(model).flush();\r
+ putRigidList(model).flush();\r
+ putRigidGroupList(model).flush();\r
+ putJointList(model).flush();\r
+ putSurfaceGroupList(model).flush();\r
+ putVertexList(model).flush();\r
+\r
+ ind().put("</pmdModel>").ln(2);\r
+ ind().put("<!-- EOF -->").ln();\r
+\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * モデル基本情報を出力する。\r
+ * @param model モデル情報\r
+ * @return this本体\r
+ * @throws IOException 出力エラー\r
+ */\r
+ private PmdXmlExporter putModelInfo(PmdModel model)\r
+ throws IOException{\r
+ I18nText modelName = model.getModelName();\r
+ putI18nName(modelName);\r
+ ln();\r
+\r
+ I18nText description = model.getDescription();\r
+ for(String lang639 : description.lang639CodeList()){\r
+ String descText = description.getText(lang639);\r
+ putDescription(lang639, descText);\r
+ ln();\r
+ }\r
+\r
+ return this;\r
+ }\r
+\r
+ /**\r
+ * モデル詳細テキストを出力する。\r
+ * @param lang639 言語コード\r
+ * @param content 詳細内容\r
+ * @return this本体\r
+ * @throws IOException 出力エラー\r
+ */\r
+ private PmdXmlExporter putDescription(CharSequence lang639,\r
+ CharSequence content)\r
+ throws IOException{\r
+ String text = content.toString();\r
+ text = text.replace(CRLF, LF);\r
+ text = text.replace(CR, LF);\r
+\r
+ ind().put("<description");\r
+ if( ! I18nText.CODE639_PRIMARY.equals(lang639) ){\r
+ put(" ");\r
+ putAttr("lang", lang639);\r
+ }\r
+ put(">").ln();\r
+\r
+ putBRedContent(text);\r
+\r
+ ln();\r
+ ind().put("</description>").ln();\r
+\r
+ if( ! hasOnlyBasicLatin(text) && isBasicLatinOnlyOut() ){\r
+ putBlockComment(text);\r
+ }\r
+\r
+ return this;\r
+ }\r
+\r
+ /**\r
+ * break要素を含む要素内容を出力する。\r
+ * 必要に応じてXML定義済み実体文字が割り振られた文字、\r
+ * コントロールコード、および非BasicLatin文字がエスケープされる。\r
+ * \nはbrタグに変換される。\r
+ * @param content 内容\r
+ * @return this本体\r
+ * @throws IOException 出力エラー\r
+ */\r
+ protected BasicXmlExporter putBRedContent(CharSequence content)\r
+ throws IOException{\r
+ int length = content.length();\r
+\r
+ for(int pos = 0; pos < length; pos++){\r
+ char ch = content.charAt(pos);\r
+ if(ch == '\n'){\r
+ put("<br/>").ln();\r
+ }else if(Character.isISOControl(ch)){\r
+ putCharRef2Hex(ch);\r
+ }else if( ! isBasicLatin(ch) && isBasicLatinOnlyOut()){\r
+ putCharRef4Hex(ch);\r
+ }else{\r
+ switch(ch){\r
+ case '&': put("&"); break;\r
+ case '<': put("<"); break;\r
+ case '>': put(">"); break;\r
+ case '"': put("""); break;\r
+ case '\'': put("'"); break;\r
+ default: put(ch); break;\r
+ }\r
+ }\r
+ }\r
+\r
+ return this;\r
+ }\r
+\r
+ /**\r
+ * 各種メタ情報を出力する。\r
+ * @param model モデルデータ\r
+ * @return this本体\r
+ * @throws IOException 出力エラー\r
+ */\r
+ private PmdXmlExporter putMetaInfo(PmdModel model) throws IOException{\r
+ ind().put("<license>").ln();\r
+ ind().put("</license>").ln(2);\r
+\r
+ ind().put("<credits>").ln();\r
+ ind().put("</credits>").ln(2);\r
+\r
+ ind().put("<meta ");\r
+ putAttr("name", "generator").put(' ').putAttr("content", GENERATOR);\r
+ put(" />").ln();\r
+ ind().put("<meta ");\r
+ putAttr("name", "siteURL").put(' ').putAttr("content", "");\r
+ put(" />").ln();\r
+ ind().put("<meta ");\r
+ putAttr("name", "imageURL").put(' ').putAttr("content", "");\r
+ put(" />").ln(2);\r
+\r
+ return this;\r
+ }\r
+\r
+ /**\r
+ * マテリアル素材一覧を出力する。\r
+ * @param model モデルデータ\r
+ * @return this本体\r
+ * @throws IOException 出力エラー\r
+ */\r
+ private PmdXmlExporter putMaterialList(PmdModel model)\r
+ throws IOException{\r
+ ind().put("<materialList>").ln(2);\r
+ pushNest();\r
+\r
+ int ct = 0;\r
+ for(Material material : model.getMaterialList()){\r
+ putMaterial(material, ct++);\r
+ }\r
+\r
+ popNest();\r
+ ind().put("</materialList>").ln(2);\r
+\r
+ return this;\r
+ }\r
+\r
+ /**\r
+ * マテリアル素材情報を出力する。\r
+ * @param material マテリアル素材\r
+ * @param no マテリアル通し番号\r
+ * @return this本体\r
+ * @throws IOException 出力エラー\r
+ */\r
+ private PmdXmlExporter putMaterial(Material material, int no)\r
+ throws IOException{\r
+ String bool;\r
+ if(material.getEdgeAppearance()) bool = "true";\r
+ else bool = "false";\r
+ I18nText name = material.getMaterialName();\r
+ String primary = name.getPrimaryText();\r
+ String local = name.getText();\r
+\r
+ if(local != null && local.length() > 0){\r
+ ind().putLineComment(local).ln();\r
+ }\r
+ ind().put("<material ");\r
+ if(primary != null && primary.length() > 0){\r
+ putAttr("name", primary).put(' ');\r
+ }\r
+\r
+ putAttr("showEdge", bool);\r
+ put(" ");\r
+ putNumberedIdAttr("surfaceGroupIdRef", PFX_SURFACEGROUP, no);\r
+ put('>').ln();\r
+ pushNest();\r
+\r
+ putI18nName(name);\r
+\r
+ float[] rgba = new float[4];\r
+\r
+ Color diffuse = material.getDiffuseColor();\r
+ diffuse.getRGBComponents(rgba);\r
+ ind().put("<diffuse ");\r
+ putFloatAttr("r", rgba[0]).put(' ');\r
+ putFloatAttr("g", rgba[1]).put(' ');\r
+ putFloatAttr("b", rgba[2]).put(' ');\r
+ putFloatAttr("alpha", rgba[3]).put(' ');\r
+ put("/>").ln();\r
+\r
+ Color specular = material.getSpecularColor();\r
+ specular.getRGBComponents(rgba);\r
+ float shininess = material.getShininess();\r
+ ind().put("<specular ");\r
+ putFloatAttr("r", rgba[0]).put(' ');\r
+ putFloatAttr("g", rgba[1]).put(' ');\r
+ putFloatAttr("b", rgba[2]).put(' ');\r
+ putFloatAttr("shininess", shininess).put(' ');\r
+ put("/>").ln();\r
+\r
+ Color ambient = material.getAmbientColor();\r
+ ambient.getRGBComponents(rgba);\r
+ ind().put("<ambient ");\r
+ putFloatAttr("r", rgba[0]).put(' ');\r
+ putFloatAttr("g", rgba[1]).put(' ');\r
+ putFloatAttr("b", rgba[2]).put(' ');\r
+ put("/>").ln();\r
+\r
+ ShadeInfo shade = material.getShadeInfo();\r
+ String textureFileName = shade.getTextureFileName();\r
+ String spheremapFileName = shade.getSpheremapFileName();\r
+\r
+ if(shade.isValidToonIndex()){\r
+ ind().put("<toon ");\r
+ int toonIdx = shade.getToonIndex();\r
+ putNumberedIdAttr("toonFileIdRef", PFX_TOONFILE, toonIdx);\r
+ put(" />");\r
+ String toonFileName = shade.getToonFileName();\r
+ if(toonFileName != null && toonFileName.length() > 0){\r
+ put(' ').putLineComment(toonFileName);\r
+ }\r
+ ln();\r
+ }\r
+\r
+ if(textureFileName != null && textureFileName.length() > 0){\r
+ ind().put("<textureFile ");\r
+ putAttr("winFileName", textureFileName);\r
+ put(" />").ln();\r
+ }\r
+\r
+ if(spheremapFileName != null && spheremapFileName.length() > 0){\r
+ ind().put("<spheremapFile ");\r
+ putAttr("winFileName", spheremapFileName);\r
+ put(" />").ln();\r
+ }\r
+\r
+ popNest();\r
+ ind().put("</material>").ln(2);\r
+\r
+ return this;\r
+ }\r
+\r
+ /**\r
+ * トゥーンファイルマッピング情報を出力する。\r
+ * @param model モデルデータ\r
+ * @return this本体\r
+ * @throws IOException 出力エラー\r
+ */\r
+ private PmdXmlExporter putToonMap(PmdModel model)\r
+ throws IOException{\r
+ ind().put("<toonMap>").ln();\r
+ pushNest();\r
+\r
+ ToonMap map = model.getToonMap();\r
+ for(int index = 0; index <= 9; index++){\r
+ ind().putToon(map, index).ln();\r
+ }\r
+\r
+ popNest();\r
+ ind().put("</toonMap>").ln(2);\r
+ return this;\r
+ }\r
+\r
+ /**\r
+ * 個別のトゥーンファイル情報を出力する。\r
+ * @param map トゥーンマップ\r
+ * @param index インデックス値\r
+ * @return this本体\r
+ * @throws IOException 出力エラー\r
+ */\r
+ private PmdXmlExporter putToon(ToonMap map, int index)\r
+ throws IOException{\r
+ put("<toonDef ");\r
+ putNumberedIdAttr("toonFileId", PFX_TOONFILE, index).put(' ');\r
+ putIntAttr("index", index).put(' ');\r
+ String toonFile = map.getIndexedToon(index);\r
+ putAttr("winFileName", toonFile);\r
+ put(" />");\r
+ putUnescapedComment(toonFile);\r
+ return this;\r
+ }\r
+\r
+ /**\r
+ * サーフェイスグループリストを出力する。\r
+ * @param model モデルデータ\r
+ * @return this本体\r
+ * @throws IOException 出力エラー\r
+ */\r
+ private PmdXmlExporter putSurfaceGroupList(PmdModel model)\r
+ throws IOException{\r
+ ind().put("<surfaceGroupList>").ln(2);\r
+ pushNest();\r
+\r
+ int ct = 0;\r
+ for(Material material : model.getMaterialList()){\r
+ List<Surface> surfaceList = material.getSurfaceList();\r
+ putSurfaceList(surfaceList, ct++);\r
+ }\r
+\r
+ popNest();\r
+ ind().put("</surfaceGroupList>").ln(2);\r
+\r
+ return this;\r
+ }\r
+\r
+ /**\r
+ * 個別のサーフェイスグループを出力する。\r
+ * @param surfaceList サーフェイスのリスト\r
+ * @param index グループインデックス\r
+ * @return this本体\r
+ * @throws IOException 出力エラー\r
+ */\r
+ private PmdXmlExporter putSurfaceList(List<Surface> surfaceList,\r
+ int index)\r
+ throws IOException{\r
+ ind().put("<surfaceGroup ");\r
+ putNumberedIdAttr("surfaceGroupId", PFX_SURFACEGROUP, index);\r
+ put(">").ln();\r
+ pushNest();\r
+\r
+ for(Surface surface : surfaceList){\r
+ putSurface(surface);\r
+ }\r
+\r
+ popNest();\r
+ ind().put("</surfaceGroup>").ln(2);\r
+\r
+ return this;\r
+ }\r
+\r
+ /**\r
+ * 個別のサーフェイスを出力する。\r
+ * @param surface サーフェイス\r
+ * @return this本体\r
+ * @throws IOException 出力エラー\r
+ */\r
+ private PmdXmlExporter putSurface(Surface surface)\r
+ throws IOException{\r
+ ind().put("<surface ");\r
+\r
+ Vertex vertex1 = surface.getVertex1();\r
+ Vertex vertex2 = surface.getVertex2();\r
+ Vertex vertex3 = surface.getVertex3();\r
+\r
+ putNumberedIdAttr("vtxIdRef1", PFX_VERTEX, vertex1).put(' ');\r
+ putNumberedIdAttr("vtxIdRef2", PFX_VERTEX, vertex2).put(' ');\r
+ putNumberedIdAttr("vtxIdRef3", PFX_VERTEX, vertex3).put(' ');\r
+\r
+ put("/>").ln();\r
+ return this;\r
+ }\r
+\r
+ /**\r
+ * 頂点リストを出力する。\r
+ * @param model モデルデータ\r
+ * @return this本体\r
+ * @throws IOException 出力エラー\r
+ */\r
+ private PmdXmlExporter putVertexList(PmdModel model)\r
+ throws IOException{\r
+ ind().put("<vertexList>").ln(2);\r
+ pushNest();\r
+\r
+ for(Vertex vertex : model.getVertexList()){\r
+ putVertex(vertex);\r
+ }\r
+\r
+ popNest();\r
+ ind().put("</vertexList>").ln(2);\r
+\r
+ return this;\r
+ }\r
+\r
+ /**\r
+ * 個別の頂点情報を出力する。\r
+ * @param vertex 頂点\r
+ * @return this本体\r
+ * @throws IOException 出力エラー\r
+ */\r
+ private PmdXmlExporter putVertex(Vertex vertex)\r
+ throws IOException{\r
+ String bool;\r
+ if(vertex.getEdgeAppearance()) bool = "true";\r
+ else bool = "false";\r
+\r
+ ind().put("<vertex ");\r
+ putNumberedIdAttr("vtxId", PFX_VERTEX, vertex).put(' ');\r
+ putAttr("showEdge", bool);\r
+ put(">").ln();\r
+ pushNest();\r
+\r
+ Pos3d position = vertex.getPosition();\r
+ ind().putPosition(position).ln();\r
+\r
+ Vec3d normal = vertex.getNormal();\r
+ ind().put("<normal ");\r
+ putFloatAttr("x", normal.getXVal()).put(' ');\r
+ putFloatAttr("y", normal.getYVal()).put(' ');\r
+ putFloatAttr("z", normal.getZVal()).put(' ');\r
+ put("/>").ln();\r
+\r
+ Pos2d uvPos = vertex.getUVPosition();\r
+ ind().put("<uvMap ");\r
+ putFloatAttr("u", uvPos.getXPos()).put(' ');\r
+ putFloatAttr("v", uvPos.getYPos()).put(' ');\r
+ put("/>").ln();\r
+\r
+ BoneInfo boneA = vertex.getBoneA();\r
+ BoneInfo boneB = vertex.getBoneB();\r
+ int weight = vertex.getWeightA();\r
+ ind().put("<skinning ");\r
+ putNumberedIdAttr("boneIdRef1", PFX_BONE, boneA).put(' ');\r
+ putNumberedIdAttr("boneIdRef2", PFX_BONE, boneB).put(' ');\r
+ putIntAttr("weightBalance", weight).put(' ');\r
+ put("/>").ln();\r
+\r
+ popNest();\r
+ ind().put("</vertex>").ln(2);\r
+\r
+ return this;\r
+ }\r
+\r
+ /**\r
+ * ボーンリストを出力する。\r
+ * @param model モデルデータ\r
+ * @return this本体\r
+ * @throws IOException 出力エラー\r
+ */\r
+ private PmdXmlExporter putBoneList(PmdModel model)\r
+ throws IOException{\r
+ ind().put("<boneList>").ln(2);\r
+ pushNest();\r
+\r
+ putBlockComment(BONETYPE_COMMENT).ln();\r
+\r
+ for(BoneInfo bone : model.getBoneList()){\r
+ putBone(bone);\r
+ }\r
+\r
+ popNest();\r
+ ind().put("</boneList>").ln(2);\r
+\r
+ return this;\r
+ }\r
+\r
+ /**\r
+ * 個別のボーン情報を出力する。\r
+ * @param bone ボーン情報\r
+ * @return this本体\r
+ * @throws IOException 出力エラー\r
+ */\r
+ private PmdXmlExporter putBone(BoneInfo bone)\r
+ throws IOException{\r
+ I18nText i18nName = bone.getBoneName();\r
+ BoneType type = bone.getBoneType();\r
+\r
+ putLocalNameComment(i18nName).putLineComment(type.getGuiName()).ln();\r
+ ind().put("<bone ");\r
+ putPrimaryNameAttr("name", i18nName).put(' ');\r
+ putNumberedIdAttr("boneId", PFX_BONE, bone).put(' ');\r
+ putAttr("type", type.name());\r
+ put(">").ln();\r
+ pushNest();\r
+\r
+ putI18nName(i18nName);\r
+\r
+ Pos3d position = bone.getPosition();\r
+ ind().putPosition(position).ln();\r
+\r
+ BoneInfo ikBone = bone.getIKBone();\r
+ if(bone.getBoneType() == BoneType.LINKEDROT){\r
+ ind().put("<rotationRatio ");\r
+ putIntAttr("ratio", bone.getRotationRatio());\r
+ put(" />").ln();\r
+ }else if(ikBone != null){\r
+ ind().put("<ikBone ");\r
+ putNumberedIdAttr("boneIdRef", PFX_BONE, ikBone);\r
+ put(" /> ");\r
+ String ikBoneName = "Ref:" + ikBone.getBoneName().getText();\r
+ putLineComment(ikBoneName);\r
+ ln();\r
+ }\r
+\r
+ StringBuilder chainComment = new StringBuilder();\r
+ ind().put("<boneChain");\r
+ BoneInfo prev = bone.getPrevBone();\r
+ BoneInfo next = bone.getNextBone();\r
+ if(prev != null){\r
+ put(' ');\r
+ putNumberedIdAttr("prevBoneIdRef", PFX_BONE, prev);\r
+ chainComment.append('[')\r
+ .append(prev.getBoneName().getPrimaryText())\r
+ .append(']')\r
+ .append("=> #");\r
+ }\r
+ if(next != null){\r
+ put(' ');\r
+ putNumberedIdAttr("nextBoneIdRef", PFX_BONE, next);\r
+ if(chainComment.length() <= 0) chainComment.append("#");\r
+ chainComment.append(" =>")\r
+ .append('[')\r
+ .append(next.getBoneName().getPrimaryText())\r
+ .append(']');\r
+ }\r
+ put(" />").ln();\r
+ ind().putLineComment(chainComment).ln();\r
+\r
+ popNest();\r
+ ind().put("</bone>").ln(2);\r
+\r
+ return this;\r
+ }\r
+\r
+ /**\r
+ * ボーングループリストを出力する。\r
+ * @param model モデルデータ\r
+ * @return this本体\r
+ * @throws IOException 出力エラー\r
+ */\r
+ private PmdXmlExporter putBoneGroupList(PmdModel model)\r
+ throws IOException{\r
+ ind().put("<boneGroupList>").ln(2);\r
+ pushNest();\r
+\r
+ for(BoneGroup group : model.getBoneGroupList()){\r
+ if(group.isDefaultBoneGroup()) continue;\r
+ putBoneGroup(group);\r
+ }\r
+\r
+ popNest();\r
+ ind().put("</boneGroupList>").ln(2);\r
+\r
+ return this;\r
+ }\r
+\r
+ /**\r
+ * 個別のボーングループ情報を出力する。\r
+ * @param group ボーングループ情報\r
+ * @return this本体\r
+ * @throws IOException 出力エラー\r
+ */\r
+ private PmdXmlExporter putBoneGroup(BoneGroup group)\r
+ throws IOException{\r
+ I18nText i18nName = group.getGroupName();\r
+\r
+ putLocalNameComment(i18nName).ln();\r
+ ind().put("<boneGroup ");\r
+ putPrimaryNameAttr("name", i18nName);\r
+ put(">").ln();\r
+ pushNest();\r
+\r
+ putI18nName(i18nName);\r
+\r
+ for(BoneInfo bone : group){\r
+ ind().put("<boneGroupMember ");\r
+ putNumberedIdAttr("boneIdRef", PFX_BONE, bone);\r
+ put(" /> ");\r
+ String boneName = "Ref:" + bone.getBoneName().getText();\r
+ putLineComment(boneName).ln();\r
+ }\r
+\r
+ popNest();\r
+ ind().put("</boneGroup>").ln(2);\r
+\r
+ return this;\r
+ }\r
+\r
+ /**\r
+ * IKチェーンリストを出力する。\r
+ * @param model モデルデータ\r
+ * @return this本体\r
+ * @throws IOException 出力エラー\r
+ */\r
+ private PmdXmlExporter putIKChainList(PmdModel model)\r
+ throws IOException{\r
+ ind().put("<ikChainList>").ln(2);\r
+ pushNest();\r
+\r
+ for(IKChain chain : model.getIKChainList()){\r
+ putIKChain(chain);\r
+ }\r
+\r
+ popNest();\r
+ ind().put("</ikChainList>").ln(2);\r
+\r
+ return this;\r
+ }\r
+\r
+ /**\r
+ * 個別のIKチェーン情報を出力する。\r
+ * @param chain チェーン情報\r
+ * @return this本体\r
+ * @throws IOException 出力エラー\r
+ */\r
+ private PmdXmlExporter putIKChain(IKChain chain)\r
+ throws IOException{\r
+ int depth = chain.getIKDepth();\r
+ float weight = chain.getIKWeight();\r
+ BoneInfo ikBone = chain.getIkBone();\r
+\r
+ ind().putLineComment("Ref:" + ikBone.getBoneName().getText()).ln();\r
+ ind().put("<ikChain ");\r
+ putNumberedIdAttr("ikBoneIdRef", PFX_BONE, ikBone).put(' ');\r
+ putIntAttr("recursiveDepth", depth).put(' ');\r
+ putFloatAttr("weight", weight);\r
+ put("> ").ln();\r
+ pushNest();\r
+\r
+ for(BoneInfo bone : chain){\r
+ ind().put("<chainOrder ");\r
+ putNumberedIdAttr("boneIdRef", PFX_BONE, bone);\r
+ put(" /> ");\r
+ putLineComment("Ref:" + bone.getBoneName().getText());\r
+ ln();\r
+ }\r
+\r
+ popNest();\r
+ ind().put("</ikChain>").ln(2);\r
+\r
+ return this;\r
+ }\r
+\r
+ /**\r
+ * モーフリストを出力する。\r
+ * @param model モデルデータ\r
+ * @return this本体\r
+ * @throws IOException 出力エラー\r
+ */\r
+ private PmdXmlExporter putMorphList(PmdModel model)\r
+ throws IOException{\r
+ ind().put("<morphList>").ln(2);\r
+ pushNest();\r
+\r
+ putBlockComment(MORPHTYPE_COMMENT).ln();\r
+\r
+ Map<MorphType, List<MorphPart>> morphMap = model.getMorphMap();\r
+ for(MorphType type : MorphType.values()){\r
+ if(type == MorphType.BASE) continue;\r
+ List<MorphPart> partList = morphMap.get(type);\r
+ if(partList == null) continue;\r
+ for(MorphPart part : partList){\r
+ putMorphPart(part);\r
+ }\r
+ }\r
+\r
+ popNest();\r
+ ind().put("</morphList>").ln(2);\r
+\r
+ return this;\r
+ }\r
+\r
+ /**\r
+ * 個別のモーフ情報を出力する。\r
+ * @param part モーフ情報\r
+ * @return this本体\r
+ * @throws IOException 出力エラー\r
+ */\r
+ private PmdXmlExporter putMorphPart(MorphPart part)\r
+ throws IOException{\r
+ I18nText i18nName = part.getMorphName();\r
+ String primary = i18nName.getPrimaryText();\r
+\r
+ ind().put("<morph ");\r
+ putAttr("name", primary).put(' ');\r
+ putAttr("type", part.getMorphType().name());\r
+ put(">");\r
+ putUnescapedComment(primary);\r
+ ln();\r
+ pushNest();\r
+\r
+ putI18nName(i18nName);\r
+\r
+ for(MorphVertex mvertex : part){\r
+ Pos3d offset = mvertex.getOffset();\r
+ Vertex base = mvertex.getBaseVertex();\r
+\r
+ ind().put("<morphVertex ");\r
+ putNumberedIdAttr("vtxIdRef", PFX_VERTEX, base).put(' ');\r
+ putFloatAttr("xOff", offset.getXPos()).put(' ');\r
+ putFloatAttr("yOff", offset.getYPos()).put(' ');\r
+ putFloatAttr("zOff", offset.getZPos()).put(' ');\r
+ put("/>");\r
+ ln();\r
+ }\r
+\r
+ popNest();\r
+ ind().put("</morph>").ln(2);\r
+\r
+ return this;\r
+ }\r
+\r
+ /**\r
+ * 剛体リストを出力する。\r
+ * @param model モデルデータ\r
+ * @return this本体\r
+ * @throws IOException 出力エラー\r
+ */\r
+ private PmdXmlExporter putRigidList(PmdModel model)\r
+ throws IOException{\r
+ ind().put("<rigidList>").ln(2);\r
+ pushNest();\r
+\r
+ putBlockComment(RIGIDBEHAVIOR_COMMENT).ln();\r
+\r
+ for(RigidInfo rigid : model.getRigidList()){\r
+ putRigid(rigid);\r
+ }\r
+\r
+ popNest();\r
+ ind().put("</rigidList>").ln(2);\r
+\r
+ return this;\r
+ }\r
+\r
+ /**\r
+ * 個別の剛体情報を出力する。\r
+ * @param rigid 剛体情報\r
+ * @return this本体\r
+ * @throws IOException 出力エラー\r
+ */\r
+ private PmdXmlExporter putRigid(RigidInfo rigid)\r
+ throws IOException{\r
+ BoneInfo linkedBone = rigid.getLinkedBone();\r
+ I18nText i18nName = rigid.getRigidName();\r
+ String primary = i18nName.getPrimaryText();\r
+\r
+ putLocalNameComment(i18nName).ln();\r
+ ind().put("<rigid ");\r
+ putAttr("name", primary).put(' ');\r
+ putNumberedIdAttr("rigidId", PFX_RIGID, rigid).put(' ');\r
+ putAttr("behavior", rigid.getBehaviorType().name());\r
+ put(">").ln();\r
+ pushNest();\r
+\r
+ putI18nName(i18nName);\r
+\r
+ ind().put("<linkedBone ");\r
+ putNumberedIdAttr("boneIdRef", PFX_BONE, linkedBone);\r
+ put(" /> ");\r
+ putLineComment("Ref:" + linkedBone.getBoneName().getText());\r
+ ln(2);\r
+\r
+ RigidShape shape = rigid.getRigidShape();\r
+ putRigidShape(shape);\r
+\r
+ Pos3d position = rigid.getPosition();\r
+ ind().putPosition(position).ln();\r
+\r
+ Rad3d rotation = rigid.getRotation();\r
+ ind().putRadRotation(rotation).ln();\r
+\r
+ DynamicsInfo dynamics = rigid.getDynamicsInfo();\r
+ putDynamics(dynamics).ln();\r
+\r
+ for(RigidGroup group : rigid.getThroughGroupColl()){\r
+ ind().put("<throughRigidGroup ");\r
+ putNumberedIdAttr("rigidGroupIdRef",\r
+ PFX_RIGIDGROUP,\r
+ group.getSerialNumber() + 1).put(' ');\r
+ put(" />").ln();\r
+ }\r
+\r
+ popNest();\r
+ ind().put("</rigid>").ln(2);\r
+\r
+ return this;\r
+ }\r
+\r
+ /**\r
+ * 剛体形状を出力する。\r
+ * @param shape 剛体形状\r
+ * @return this本体\r
+ * @throws IOException 出力エラー\r
+ */\r
+ private PmdXmlExporter putRigidShape(RigidShape shape)\r
+ throws IOException{\r
+ RigidShapeType type = shape.getShapeType();\r
+\r
+ switch(type){\r
+ case BOX:\r
+ ind().put("<rigidShapeBox ");\r
+ putFloatAttr("width", shape.getWidth()).put(' ');\r
+ putFloatAttr("height", shape.getHeight()).put(' ');\r
+ putFloatAttr("depth", shape.getDepth()).put(' ');\r
+ break;\r
+ case SPHERE:\r
+ ind().put("<rigidShapeSphere ");\r
+ putFloatAttr("radius", shape.getRadius()).put(' ');\r
+ break;\r
+ case CAPSULE:\r
+ ind().put("<rigidShapeCapsule ");\r
+ putFloatAttr("height", shape.getHeight()).put(' ');\r
+ putFloatAttr("radius", shape.getRadius()).put(' ');\r
+ break;\r
+ default:\r
+ assert false;\r
+ throw new AssertionError();\r
+ }\r
+\r
+ put("/>").ln();\r
+\r
+ return this;\r
+ }\r
+\r
+ /**\r
+ * 力学設定を出力する。\r
+ * @param dynamics 力学設定\r
+ * @return this本体\r
+ * @throws IOException 出力エラー\r
+ */\r
+ private PmdXmlExporter putDynamics(DynamicsInfo dynamics)\r
+ throws IOException{\r
+ ind().put("<dynamics").ln();\r
+ pushNest();\r
+ ind().putFloatAttr("mass", dynamics.getMass()).ln();\r
+ ind().putFloatAttr("dampingPosition",\r
+ dynamics.getDampingPosition()).ln();\r
+ ind().putFloatAttr("dampingRotation",\r
+ dynamics.getDampingRotation()).ln();\r
+ ind().putFloatAttr("restitution", dynamics.getRestitution()).ln();\r
+ ind().putFloatAttr("friction", dynamics.getFriction()).ln();\r
+ popNest();\r
+ ind().put("/>").ln();\r
+\r
+ return this;\r
+ }\r
+\r
+ /**\r
+ * 剛体グループリストを出力する。\r
+ * @param model モデルデータ\r
+ * @return this本体\r
+ * @throws IOException 出力エラー\r
+ */\r
+ private PmdXmlExporter putRigidGroupList(PmdModel model)\r
+ throws IOException{\r
+ ind().put("<rigidGroupList>").ln(2);\r
+ pushNest();\r
+\r
+ for(RigidGroup group : model.getRigidGroupList()){\r
+ ind().put("<rigidGroup ");\r
+ putNumberedIdAttr("rigidGroupId",\r
+ PFX_RIGIDGROUP,\r
+ group.getSerialNumber() + 1);\r
+ List<RigidInfo> rigidList = group.getRigidList();\r
+ if(rigidList.size() <= 0){\r
+ put(" />").ln(2);\r
+ continue;\r
+ }\r
+ put(">").ln();\r
+ pushNest();\r
+\r
+ for(RigidInfo rigid : rigidList){\r
+ ind().put("<rigidGroupMember ");\r
+ putNumberedIdAttr("rigidIdRef", PFX_RIGID, rigid).put(' ');\r
+ put("/>");\r
+ put(' ');\r
+ putLineComment("Ref:" + rigid.getRigidName().getText());\r
+ ln();\r
+ }\r
+\r
+ popNest();\r
+ ind().put("</rigidGroup>").ln(2);\r
+ }\r
+\r
+ popNest();\r
+ ind().put("</rigidGroupList>").ln(2);\r
+\r
+ return this;\r
+ }\r
+\r
+ /**\r
+ * ジョイントリストを出力する。\r
+ * @param model モデルデータ\r
+ * @return this本体\r
+ * @throws IOException 出力エラー\r
+ */\r
+ private PmdXmlExporter putJointList(PmdModel model)\r
+ throws IOException{\r
+ ind().put("<jointList>").ln(2);\r
+ pushNest();\r
+\r
+ for(JointInfo joint : model.getJointList()){\r
+ putJoint(joint);\r
+ }\r
+\r
+ popNest();\r
+ ind().put("</jointList>").ln(2);\r
+\r
+ return this;\r
+ }\r
+\r
+ /**\r
+ * 個別のジョイント情報を出力する。\r
+ * @param joint ジョイント情報\r
+ * @return this本体\r
+ * @throws IOException 出力エラー\r
+ */\r
+ private PmdXmlExporter putJoint(JointInfo joint)\r
+ throws IOException{\r
+ I18nText i18nName = joint.getJointName();\r
+\r
+ putLocalNameComment(i18nName).ln();\r
+ ind().put("<joint ");\r
+ putPrimaryNameAttr("name", i18nName);\r
+ put(">").ln();\r
+ pushNest();\r
+\r
+ putI18nName(i18nName);\r
+\r
+ RigidInfo rigidA = joint.getRigidA();\r
+ RigidInfo rigidB = joint.getRigidB();\r
+ ind().put("<jointedRigidPair ");\r
+ putNumberedIdAttr("rigidIdRef1", PFX_RIGID, rigidA).put(' ');\r
+ putNumberedIdAttr("rigidIdRef2", PFX_RIGID, rigidB).put(' ');\r
+ put("/>").ln();\r
+ ind();\r
+ putLineComment("[" + rigidA.getRigidName().getText() + "]"\r
+ + " <=> [" + rigidB.getRigidName().getText() + "]");\r
+ ln(2);\r
+\r
+ Pos3d position = joint.getPosition();\r
+ ind().putPosition(position).ln();\r
+\r
+ TripletRange posRange = joint.getPositionRange();\r
+ ind().put("<limitPosition").ln();\r
+ pushNest();\r
+ ind();\r
+ putFloatAttr("xFrom", posRange.getXFrom()).put(' ');\r
+ putFloatAttr("xTo", posRange.getXTo()).ln();\r
+ ind();\r
+ putFloatAttr("yFrom", posRange.getYFrom()).put(' ');\r
+ putFloatAttr("yTo", posRange.getYTo()).ln();\r
+ ind();\r
+ putFloatAttr("zFrom", posRange.getZFrom()).put(' ');\r
+ putFloatAttr("zTo", posRange.getZTo()).ln();\r
+ popNest();\r
+ ind().put("/>").ln(2);\r
+\r
+ Rad3d rotation = joint.getRotation();\r
+ ind().putRadRotation(rotation).ln();\r
+ TripletRange rotRange = joint.getRotationRange();\r
+ ind().put("<limitRotation").ln();\r
+ pushNest();\r
+ ind();\r
+ putFloatAttr("xFrom", rotRange.getXFrom()).put(' ');\r
+ putFloatAttr("xTo", rotRange.getXTo()).ln();\r
+ ind();\r
+ putFloatAttr("yFrom", rotRange.getYFrom()).put(' ');\r
+ putFloatAttr("yTo", rotRange.getYTo()).ln();\r
+ ind();\r
+ putFloatAttr("zFrom", rotRange.getZFrom()).put(' ');\r
+ putFloatAttr("zTo", rotRange.getZTo()).ln();\r
+ popNest();\r
+ ind().put("/>").ln(2);\r
+\r
+ Pos3d elaPosition = joint.getElasticPosition();\r
+ ind().put("<elasticPosition ");\r
+ putFloatAttr("x", elaPosition.getXPos()).put(' ');\r
+ putFloatAttr("y", elaPosition.getYPos()).put(' ');\r
+ putFloatAttr("z", elaPosition.getZPos()).put(' ');\r
+ put("/>").ln();\r
+\r
+ Deg3d elaRotation = joint.getElasticRotation();\r
+ ind().put("<elasticRotation ");\r
+ putFloatAttr("xDeg", elaRotation.getXDeg()).put(' ');\r
+ putFloatAttr("yDeg", elaRotation.getYDeg()).put(' ');\r
+ putFloatAttr("zDeg", elaRotation.getZDeg()).put(' ');\r
+ put("/>").ln(2);\r
+\r
+ popNest();\r
+ ind().put("</joint>").ln(2);\r
+\r
+ return this;\r
+ }\r
+\r
+}\r
--- /dev/null
+/*\r
+ * xml resources for PMD-XML\r
+ *\r
+ * License : The MIT License\r
+ * Copyright(c) 2010 MikuToga Partners\r
+ */\r
+\r
+package jp.sourceforge.mikutoga.pmd.xml;\r
+\r
+import java.net.URI;\r
+import java.net.URISyntaxException;\r
+import javax.xml.XMLConstants;\r
+import javax.xml.parsers.DocumentBuilder;\r
+import javax.xml.parsers.DocumentBuilderFactory;\r
+import javax.xml.parsers.ParserConfigurationException;\r
+import javax.xml.validation.Schema;\r
+import javax.xml.validation.SchemaFactory;\r
+import jp.sourceforge.mikutoga.xml.XmlResourceResolver;\r
+import org.xml.sax.SAXException;\r
+\r
+/**\r
+ *\r
+ */\r
+public final class PmdXmlResources {\r
+\r
+ public static final String NS_PMDXML =\r
+ "http://mikutoga.sourceforge.jp/xml/ns/pmdxml/100923";\r
+ public static final String SCHEMA_PMDXML =\r
+ "http://mikutoga.sourceforge.jp/xml/xsd/pmdxml-100923.xsd";\r
+ public static final String DTD_PMDXML =\r
+ "http://mikutoga.sourceforge.jp/xml/dtd/pmdxml-100923.dtd";\r
+ public static final String VER_PMDXML =\r
+ "100923";\r
+ public static final String LOCAL_SCHEMA_PMDXML =\r
+ "./resources/pmdxml-100923.xsd";\r
+ public static final String LOCAL_DTD_PMDXML =\r
+ "./resources/pmdxml-100923.dtd";\r
+\r
+ public static final URI URI_SCHEMA_PMDXML = URI.create(SCHEMA_PMDXML);\r
+ public static final URI URI_DTD_PMDXML = URI.create(DTD_PMDXML);\r
+ public static final URI RES_SCHEMA_PMDXML;\r
+ public static final URI RES_DTD_PMDXML;\r
+\r
+ private static final Class THISCLASS = PmdXmlResources.class;\r
+\r
+ static{\r
+ Object dummy = new PmdXmlResources();\r
+\r
+ try{\r
+ RES_SCHEMA_PMDXML =\r
+ THISCLASS.getResource(LOCAL_SCHEMA_PMDXML).toURI();\r
+ RES_DTD_PMDXML =\r
+ THISCLASS.getResource(LOCAL_DTD_PMDXML).toURI();\r
+ }catch(URISyntaxException e){\r
+ throw new ExceptionInInitializerError(e);\r
+ }\r
+ }\r
+\r
+ /**\r
+ * 隠しコンストラクタ。\r
+ */\r
+ private PmdXmlResources(){\r
+ super();\r
+ assert this.getClass().equals(THISCLASS);\r
+ return;\r
+ }\r
+\r
+ public static DocumentBuilder newBuilder()\r
+ throws SAXException, ParserConfigurationException {\r
+ XmlResourceResolver resolver = new XmlResourceResolver();\r
+ resolver.putURIMap(URI_SCHEMA_PMDXML, RES_SCHEMA_PMDXML);\r
+ resolver.putURIMap(URI_DTD_PMDXML, RES_DTD_PMDXML);\r
+\r
+ SchemaFactory schemaFactory =\r
+ SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);\r
+ schemaFactory.setResourceResolver(resolver);\r
+ Schema schema = schemaFactory.newSchema();\r
+\r
+ DocumentBuilderFactory builderFactory =\r
+ DocumentBuilderFactory.newInstance();\r
+ builderFactory.setCoalescing(true);\r
+ builderFactory.setExpandEntityReferences(true);\r
+ builderFactory.setIgnoringComments(true);\r
+ builderFactory.setIgnoringElementContentWhitespace(false);\r
+ builderFactory.setNamespaceAware(true);\r
+ builderFactory.setValidating(false);\r
+ builderFactory.setSchema(schema);\r
+\r
+ DocumentBuilder builder = builderFactory.newDocumentBuilder();\r
+ builder.setEntityResolver(resolver);\r
+\r
+ return builder;\r
+ }\r
+\r
+}\r
--- /dev/null
+/*\r
+ * xml loader\r
+ *\r
+ * License : The MIT License\r
+ * Copyright(c) 2010 MikuToga Partners\r
+ */\r
+\r
+package jp.sourceforge.mikutoga.pmd.xml;\r
+\r
+import java.awt.Color;\r
+import java.io.IOException;\r
+import java.util.ArrayList;\r
+import java.util.HashMap;\r
+import java.util.LinkedList;\r
+import java.util.List;\r
+import java.util.Map;\r
+import javax.xml.parsers.DocumentBuilder;\r
+import jp.sourceforge.mikutoga.corelib.I18nText;\r
+import jp.sourceforge.mikutoga.corelib.ListUtil;\r
+import jp.sourceforge.mikutoga.pmd.BoneGroup;\r
+import jp.sourceforge.mikutoga.pmd.BoneInfo;\r
+import jp.sourceforge.mikutoga.pmd.BoneType;\r
+import jp.sourceforge.mikutoga.pmd.Deg3d;\r
+import jp.sourceforge.mikutoga.pmd.DynamicsInfo;\r
+import jp.sourceforge.mikutoga.pmd.IKChain;\r
+import jp.sourceforge.mikutoga.pmd.JointInfo;\r
+import jp.sourceforge.mikutoga.pmd.Material;\r
+import jp.sourceforge.mikutoga.pmd.MorphPart;\r
+import jp.sourceforge.mikutoga.pmd.MorphType;\r
+import jp.sourceforge.mikutoga.pmd.MorphVertex;\r
+import jp.sourceforge.mikutoga.pmd.PmdModel;\r
+import jp.sourceforge.mikutoga.pmd.Pos2d;\r
+import jp.sourceforge.mikutoga.pmd.Pos3d;\r
+import jp.sourceforge.mikutoga.pmd.Rad3d;\r
+import jp.sourceforge.mikutoga.pmd.RigidBehaviorType;\r
+import jp.sourceforge.mikutoga.pmd.RigidGroup;\r
+import jp.sourceforge.mikutoga.pmd.RigidInfo;\r
+import jp.sourceforge.mikutoga.pmd.RigidShape;\r
+import jp.sourceforge.mikutoga.pmd.RigidShapeType;\r
+import jp.sourceforge.mikutoga.pmd.ShadeInfo;\r
+import jp.sourceforge.mikutoga.pmd.Surface;\r
+import jp.sourceforge.mikutoga.pmd.ToonMap;\r
+import jp.sourceforge.mikutoga.pmd.TripletRange;\r
+import jp.sourceforge.mikutoga.pmd.Vec3d;\r
+import jp.sourceforge.mikutoga.pmd.Vertex;\r
+import jp.sourceforge.mikutoga.xml.DomUtils;\r
+import jp.sourceforge.mikutoga.xml.TogaXmlException;\r
+import org.w3c.dom.Document;\r
+import org.w3c.dom.Element;\r
+import org.w3c.dom.Node;\r
+import org.w3c.dom.NodeList;\r
+import org.xml.sax.InputSource;\r
+import org.xml.sax.SAXException;\r
+\r
+/**\r
+ * XML形式でのモデルファイルを読み込む。\r
+ */\r
+public class Xml2PmdLoader {\r
+\r
+ private final DocumentBuilder builder;\r
+\r
+ private PmdModel model;\r
+\r
+ private final Map<String, Integer> toonIdxMap =\r
+ new HashMap<String, Integer>();\r
+ private final Map<String, BoneInfo> boneMap =\r
+ new HashMap<String, BoneInfo>();\r
+ private final Map<String, Vertex> vertexMap =\r
+ new HashMap<String, Vertex>();\r
+ private final Map<String, List<Surface>> surfaceGroupMap =\r
+ new HashMap<String, List<Surface>>();\r
+ private final Map<String, RigidInfo> rigidMap =\r
+ new HashMap<String, RigidInfo>();\r
+ private final Map<String, RigidGroup> rigidGroupMap =\r
+ new HashMap<String, RigidGroup>();\r
+\r
+\r
+ /**\r
+ * コンストラクタ。\r
+ * @param builder ビルダ\r
+ */\r
+ public Xml2PmdLoader(DocumentBuilder builder){\r
+ super();\r
+ this.builder = builder;\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * 要素からxsd:string型属性値を読み取る。\r
+ * @param elem 要素\r
+ * @param attrName 属性名\r
+ * @return 文字列\r
+ * @throw TogaXmlException 属性値が見つからなかった。\r
+ */\r
+ private static String getStringAttr(Element elem, String attrName)\r
+ throws TogaXmlException{\r
+ return DomUtils.getStringAttr(elem, attrName);\r
+ }\r
+\r
+ /**\r
+ * 要素からxsd:boolean型属性値を読み取る。\r
+ * @param elem 要素\r
+ * @param attrName 属性名\r
+ * @return 真ならtrue\r
+ * @throw TogaXmlException 属性値が見つからなかった。\r
+ */\r
+ private static boolean getBooleanAttr(Element elem, String attrName)\r
+ throws TogaXmlException{\r
+ return DomUtils.getBooleanAttr(elem, attrName);\r
+ }\r
+\r
+ /**\r
+ * 要素からxsd:integer型属性値を読み取る。\r
+ * @param elem 要素\r
+ * @param attrName 属性名\r
+ * @return int値\r
+ * @throw TogaXmlException 属性値が見つからなかった。\r
+ */\r
+ private static int getIntegerAttr(Element elem, String attrName)\r
+ throws TogaXmlException{\r
+ return DomUtils.getIntegerAttr(elem, attrName);\r
+ }\r
+\r
+ /**\r
+ * 要素からxsd:float型属性値を読み取る。\r
+ * @param elem 要素\r
+ * @param attrName 属性名\r
+ * @return float値\r
+ * @throw TogaXmlException 属性値が見つからなかった。\r
+ */\r
+ private static float getFloatAttr(Element elem, String attrName)\r
+ throws TogaXmlException{\r
+ return DomUtils.getFloatAttr(elem, attrName);\r
+ }\r
+\r
+ /**\r
+ * 要素から日本語Windows用ファイル名を属性値として読み取る。\r
+ * 念のため文字U+00A5は文字U-005Cに変換される。\r
+ * @param elem 要素\r
+ * @param attrName 属性名\r
+ * @return ファイル名\r
+ * @throw TogaXmlException 属性値が見つからなかった。\r
+ */\r
+ private static String getSjisFileNameAttr(Element elem, String attrName)\r
+ throws TogaXmlException{\r
+ return DomUtils.getSjisFileNameAttr(elem, attrName);\r
+ }\r
+\r
+ /**\r
+ * 指定された名前の子要素を1つだけ返す。\r
+ * @param parent 親要素\r
+ * @param tagName 子要素名\r
+ * @return 子要素\r
+ * @throw TogaXmlException 1つも見つからなかった\r
+ */\r
+ private static Element getChild(Element parent, String tagName)\r
+ throws TogaXmlException{\r
+ return DomUtils.getChild(parent, tagName);\r
+ }\r
+\r
+ /**\r
+ * 親要素が指定された名前の子要素を持つか判定する。\r
+ * @param parent 親要素\r
+ * @param tagName 子要素名\r
+ * @return 指定名の子要素が存在すればtrue\r
+ */\r
+ private static boolean hasChild(Element parent, String tagName){\r
+ return DomUtils.hasChild(parent, tagName);\r
+ }\r
+\r
+ /**\r
+ * 指定された名前の子要素のforeachを返す。\r
+ * @param parent 親要素\r
+ * @param childTag 子要素名\r
+ * @return 子要素のforeach\r
+ */\r
+ private static Iterable<Element> eachChild(Element parent,\r
+ String childTag){\r
+ return DomUtils.getEachChild(parent, childTag);\r
+ }\r
+\r
+ private static String getGlobalName(Element parent){\r
+ NodeList nodeList = parent.getElementsByTagName("i18nName");\r
+ int length = nodeList.getLength();\r
+ for(int idx = 0; idx < length; idx++){\r
+ Node i18nNameNode = nodeList.item(idx);\r
+ Element i18nNameElem = (Element)i18nNameNode;\r
+ String lang = i18nNameElem.getAttribute("lang");\r
+ if(lang == null || lang.length() <= 0) continue;\r
+ if(lang.equals("en")){\r
+ String name = i18nNameElem.getAttribute("name");\r
+ return name;\r
+ }\r
+ }\r
+ return null;\r
+ }\r
+\r
+ /**\r
+ * brタグで区切られた文字列内容(Mixed content)を改行付き文字列に変換する。\r
+ * brタグはその出現回数だけ\nに変換される。\r
+ * 生文字列コンテンツ中の\n,\rは削除される。\r
+ * 改行文字以外のホワイトスペースは保持される。\r
+ * @param parent br要素及び文字列コンテンツを含む要素\r
+ * @return 変換された文字列\r
+ */\r
+ private static String getBRedContent(Element parent){\r
+ StringBuilder result = new StringBuilder();\r
+\r
+ for(Node node = parent.getFirstChild();\r
+ node != null;\r
+ node = node.getNextSibling() ){\r
+\r
+ switch(node.getNodeType()){\r
+ case Node.ELEMENT_NODE:\r
+ Element elem = (Element) node;\r
+ if("br".equals(elem.getTagName())){\r
+ result.append('\n');\r
+ }\r
+ break;\r
+ case Node.TEXT_NODE:\r
+ case Node.CDATA_SECTION_NODE:\r
+ String content = node.getTextContent();\r
+ content = content.replace("\r", "");\r
+ content = content.replace("\n", "");\r
+ result.append(content);\r
+ break;\r
+ default:\r
+ break;\r
+ }\r
+ }\r
+\r
+ return result.toString();\r
+ }\r
+\r
+ private static void buildI18nName(Element baseElement, I18nText text)\r
+ throws TogaXmlException{\r
+ String primaryText;\r
+ primaryText = getStringAttr(baseElement, "name");\r
+ text.setPrimaryText(primaryText);\r
+\r
+ for(Element i18nNameElem : eachChild(baseElement, "i18nName")){\r
+ String lang = getStringAttr(i18nNameElem, "lang");\r
+ String name = getStringAttr(i18nNameElem, "name");\r
+ if("en".equals(lang)){\r
+ text.setGlobalText(name);\r
+ }else{\r
+ text.setText(lang, text);\r
+ }\r
+ }\r
+\r
+ return;\r
+ }\r
+\r
+ public PmdModel parse(InputSource source)\r
+ throws SAXException, IOException, TogaXmlException{\r
+ Document document = this.builder.parse(source);\r
+\r
+ this.model = new PmdModel();\r
+\r
+ Element pmdModelElem = document.getDocumentElement();\r
+\r
+ buildBasicInfo(pmdModelElem);\r
+\r
+ buildBoneList(pmdModelElem);\r
+ buildVertexList(pmdModelElem);\r
+ buildSurfaceList(pmdModelElem);\r
+\r
+ buildToonMap(pmdModelElem);\r
+ buildMaterialList(pmdModelElem);\r
+ buildIkChainList(pmdModelElem);\r
+ buildMorphList(pmdModelElem);\r
+ buildBoneGroupList(pmdModelElem);\r
+\r
+ buildRigidList(pmdModelElem);\r
+ buildRigidGroupList(pmdModelElem);\r
+ resolveThroughRigidGroup(pmdModelElem);\r
+\r
+ buildJointList(pmdModelElem);\r
+\r
+ return this.model;\r
+ }\r
+\r
+ private void buildBasicInfo(Element pmdModelElem)\r
+ throws TogaXmlException{\r
+ String primaryName = getStringAttr(pmdModelElem, "name");\r
+ String globalName = getGlobalName(pmdModelElem);\r
+\r
+ I18nText modelName = this.model.getModelName();\r
+ modelName.setPrimaryText(primaryName);\r
+ modelName.setGlobalText(globalName);\r
+\r
+ String primaryDescription = null;\r
+ String globalDescription = null;\r
+ for(Element descriptionElem :\r
+ eachChild(pmdModelElem, "description")){\r
+ String descriptionText = getBRedContent(descriptionElem);\r
+ if( ! descriptionElem.hasAttribute("lang") ){\r
+ primaryDescription = descriptionText;\r
+ }else{\r
+ String lang = getStringAttr(descriptionElem, "lang");\r
+ if(lang.equals("ja")){\r
+ primaryDescription = descriptionText;\r
+ }else if(lang.equals("en")){\r
+ globalDescription = descriptionText;\r
+ }\r
+ }\r
+ }\r
+\r
+ I18nText description = this.model.getDescription();\r
+ description.setPrimaryText(primaryDescription);\r
+ description.setGlobalText(globalDescription);\r
+\r
+ return;\r
+ }\r
+\r
+ private void buildToonMap(Element pmdModelElem)\r
+ throws TogaXmlException{\r
+ ToonMap toonMap = this.model.getToonMap();\r
+\r
+ Element toonMapElem = getChild(pmdModelElem, "toonMap");\r
+\r
+ for(Element toonDefElem : eachChild(toonMapElem, "toonDef")){\r
+ String toonFileId = getStringAttr(toonDefElem, "toonFileId");\r
+ int toonIndex = getIntegerAttr(toonDefElem, "index");\r
+ String toonFile = getSjisFileNameAttr(toonDefElem, "winFileName");\r
+\r
+ toonMap.setIndexedToon(toonIndex, toonFile);\r
+ this.toonIdxMap.put(toonFileId, toonIndex);\r
+ }\r
+\r
+ return;\r
+ }\r
+\r
+ private void buildBoneList(Element pmdModelElem)\r
+ throws TogaXmlException{\r
+ Element boneListElem = getChild(pmdModelElem, "boneList");\r
+\r
+ List<BoneInfo> boneList = this.model.getBoneList();\r
+\r
+ for(Element boneElem : eachChild(boneListElem, "bone")){\r
+ BoneInfo boneInfo = new BoneInfo();\r
+ boneList.add(boneInfo);\r
+\r
+ I18nText boneName = boneInfo.getBoneName();\r
+ buildI18nName(boneElem, boneName);\r
+\r
+ String boneType = getStringAttr(boneElem, "type");\r
+ BoneType type = BoneType.valueOf(boneType);\r
+ boneInfo.setBoneType(type);\r
+\r
+ String boneId = getStringAttr(boneElem, "boneId");\r
+ this.boneMap.put(boneId, boneInfo);\r
+\r
+ Element positionElem = getChild(boneElem, "position");\r
+ float xPos = getFloatAttr(positionElem, "x");\r
+ float yPos = getFloatAttr(positionElem, "y");\r
+ float zPos = getFloatAttr(positionElem, "z");\r
+ Pos3d position = boneInfo.getPosition();\r
+ position.setXPos(xPos);\r
+ position.setYPos(yPos);\r
+ position.setZPos(zPos);\r
+ }\r
+\r
+ ListUtil.assignIndexedSerial(boneList);\r
+\r
+ int serial = 0;\r
+ for(Element boneElem : eachChild(boneListElem, "bone")){\r
+ BoneInfo boneInfo = boneList.get(serial++);\r
+\r
+ if(hasChild(boneElem, "ikBone")){\r
+ Element ikBoneElem = getChild(boneElem, "ikBone");\r
+ String ikBoneId = getStringAttr(ikBoneElem, "boneIdRef");\r
+ BoneInfo ikBone = this.boneMap.get(ikBoneId);\r
+ boneInfo.setIKBone(ikBone);\r
+ }else if(hasChild(boneElem, "rotationRatio")){\r
+ Element ikBoneElem = getChild(boneElem, "rotationRatio");\r
+ int ratio = getIntegerAttr(ikBoneElem, "ratio");\r
+ boneInfo.setRotationRatio(ratio);\r
+ }\r
+\r
+ Element boneChainElem = getChild(boneElem, "boneChain");\r
+ if(boneChainElem.hasAttribute("prevBoneIdRef")){\r
+ String prevId = getStringAttr(boneChainElem, "prevBoneIdRef");\r
+ BoneInfo prevBone = this.boneMap.get(prevId);\r
+ boneInfo.setPrevBone(prevBone);\r
+ }\r
+ if(boneChainElem.hasAttribute("nextBoneIdRef")){\r
+ String nextId = getStringAttr(boneChainElem, "nextBoneIdRef");\r
+ BoneInfo nextBone = this.boneMap.get(nextId);\r
+ boneInfo.setNextBone(nextBone);\r
+ }\r
+ }\r
+\r
+ return;\r
+ }\r
+\r
+ private void buildVertexList(Element pmdModelElem)\r
+ throws TogaXmlException{\r
+ Element vertexListElem = getChild(pmdModelElem, "vertexList");\r
+\r
+ List<Vertex> vertexList = this.model.getVertexList();\r
+\r
+ for(Element vertexElem : eachChild(vertexListElem, "vertex")){\r
+ Vertex vertex = new Vertex();\r
+ vertexList.add(vertex);\r
+\r
+ String vertexId = getStringAttr(vertexElem, "vtxId");\r
+ this.vertexMap.put(vertexId, vertex);\r
+\r
+ boolean showEdge = getBooleanAttr(vertexElem, "showEdge");\r
+ vertex.setEdgeAppearance(showEdge);\r
+\r
+ float xVal;\r
+ float yVal;\r
+ float zVal;\r
+\r
+ Element positionElem = getChild(vertexElem, "position");\r
+ xVal = getFloatAttr(positionElem, "x");\r
+ yVal = getFloatAttr(positionElem, "y");\r
+ zVal = getFloatAttr(positionElem, "z");\r
+ Pos3d position = vertex.getPosition();\r
+ position.setXPos(xVal);\r
+ position.setYPos(yVal);\r
+ position.setZPos(zVal);\r
+\r
+ Element normalElem = getChild(vertexElem, "normal");\r
+ xVal = getFloatAttr(normalElem, "x");\r
+ yVal = getFloatAttr(normalElem, "y");\r
+ zVal = getFloatAttr(normalElem, "z");\r
+ Vec3d normal = vertex.getNormal();\r
+ normal.setXVal(xVal);\r
+ normal.setYVal(yVal);\r
+ normal.setZVal(zVal);\r
+\r
+ Element uvElem = getChild(vertexElem, "uvMap");\r
+ float uVal = getFloatAttr(uvElem, "u");\r
+ float vVal = getFloatAttr(uvElem, "v");\r
+ Pos2d uv = vertex.getUVPosition();\r
+ uv.setXPos(uVal);\r
+ uv.setYPos(vVal);\r
+\r
+ Element skinningElem = getChild(vertexElem, "skinning");\r
+ String boneId1 = getStringAttr(skinningElem, "boneIdRef1");\r
+ String boneId2 = getStringAttr(skinningElem, "boneIdRef2");\r
+ int weight = getIntegerAttr(skinningElem, "weightBalance");\r
+ BoneInfo boneA = this.boneMap.get(boneId1);\r
+ BoneInfo boneB = this.boneMap.get(boneId2);\r
+ vertex.setBonePair(boneA, boneB);\r
+ vertex.setWeightA(weight);\r
+ }\r
+\r
+ ListUtil.assignIndexedSerial(vertexList);\r
+\r
+ return;\r
+ }\r
+\r
+ private void buildSurfaceList(Element pmdModelElem)\r
+ throws TogaXmlException{\r
+ Element surfaceGroupListElem =\r
+ getChild(pmdModelElem, "surfaceGroupList");\r
+\r
+ for(Element surfaceGroupElem :\r
+ eachChild(surfaceGroupListElem, "surfaceGroup") ){\r
+\r
+ String groupId = getStringAttr(surfaceGroupElem, "surfaceGroupId");\r
+ List<Surface> surfaceList = buildSurface(surfaceGroupElem);\r
+\r
+ this.surfaceGroupMap.put(groupId, surfaceList);\r
+ }\r
+ }\r
+\r
+ private List<Surface> buildSurface(Element surfaceGroupElem)\r
+ throws TogaXmlException{\r
+ List<Surface> result = new ArrayList<Surface>();\r
+\r
+ for(Element surfaceElem : eachChild(surfaceGroupElem, "surface")){\r
+ Surface surface = new Surface();\r
+ result.add(surface);\r
+\r
+ String id1 = getStringAttr(surfaceElem, "vtxIdRef1");\r
+ String id2 = getStringAttr(surfaceElem, "vtxIdRef2");\r
+ String id3 = getStringAttr(surfaceElem, "vtxIdRef3");\r
+\r
+ Vertex vertex1 = this.vertexMap.get(id1);\r
+ Vertex vertex2 = this.vertexMap.get(id2);\r
+ Vertex vertex3 = this.vertexMap.get(id3);\r
+\r
+ surface.setTriangle(vertex1, vertex2, vertex3);\r
+ }\r
+\r
+ return result;\r
+ }\r
+\r
+ private void buildMaterialList(Element pmdModelElem)\r
+ throws TogaXmlException{\r
+ Element materialListElem =\r
+ getChild(pmdModelElem, "materialList");\r
+\r
+ List<Surface> surfaceList = this.model.getSurfaceList();\r
+ List<Material> materialList = this.model.getMaterialList();\r
+\r
+ for(Element materialElem : eachChild(materialListElem, "material")){\r
+ Material material = new Material();\r
+ materialList.add(material);\r
+\r
+ material.getShadeInfo().setToonMap(this.model.getToonMap());\r
+\r
+ String surfaceGroupId =\r
+ getStringAttr(materialElem, "surfaceGroupIdRef");\r
+ List<Surface> surfaceGroup =\r
+ this.surfaceGroupMap.get(surfaceGroupId);\r
+ surfaceList.addAll(surfaceGroup);\r
+ material.getSurfaceList().addAll(surfaceGroup);\r
+\r
+ boolean hasEdge = getBooleanAttr(materialElem, "showEdge");\r
+ material.setEdgeAppearance(hasEdge);\r
+\r
+ ShadeInfo shadeInfo = material.getShadeInfo();\r
+\r
+ int toonIdx;\r
+ if(hasChild(materialElem, "toon")){\r
+ Element toonElem = getChild(materialElem, "toon");\r
+ String toonId = getStringAttr(toonElem, "toonFileIdRef");\r
+ toonIdx = this.toonIdxMap.get(toonId);\r
+ }else{\r
+ toonIdx = 255;\r
+ }\r
+ shadeInfo.setToonIndex(toonIdx);\r
+\r
+ if(hasChild(materialElem, "textureFile")){\r
+ Element textureFileElem =\r
+ getChild(materialElem, "textureFile");\r
+ String textureFile =\r
+ getSjisFileNameAttr(textureFileElem, "winFileName");\r
+ shadeInfo.setTextureFileName(textureFile);\r
+ }\r
+\r
+ if(hasChild(materialElem, "spheremapFile")){\r
+ Element spheremapFileElem =\r
+ getChild(materialElem, "spheremapFile");\r
+ String spheremapFile =\r
+ getSjisFileNameAttr(spheremapFileElem, "winFileName");\r
+ shadeInfo.setSpheremapFileName(spheremapFile);\r
+ }\r
+\r
+ float red;\r
+ float green;\r
+ float blue;\r
+\r
+ Element diffuseElem = getChild(materialElem, "diffuse");\r
+ red = getFloatAttr(diffuseElem, "r");\r
+ green = getFloatAttr(diffuseElem, "g");\r
+ blue = getFloatAttr(diffuseElem, "b");\r
+ float alpha = getFloatAttr(diffuseElem, "alpha");\r
+ Color diffuse = new Color(red, green, blue, alpha);\r
+ material.setDiffuseColor(diffuse);\r
+\r
+ Element specularElem = getChild(materialElem, "specular");\r
+ red = getFloatAttr(specularElem, "r");\r
+ green = getFloatAttr(specularElem, "g");\r
+ blue = getFloatAttr(specularElem, "b");\r
+ float shininess = getFloatAttr(specularElem, "shininess");\r
+ Color specular = new Color(red, green, blue);\r
+ material.setSpecularColor(specular);\r
+ material.setShininess(shininess);\r
+\r
+ Element ambientElem = getChild(materialElem, "ambient");\r
+ red = getFloatAttr(ambientElem, "r");\r
+ green = getFloatAttr(ambientElem, "g");\r
+ blue = getFloatAttr(ambientElem, "b");\r
+ Color ambient = new Color(red, green, blue);\r
+ material.setAmbientColor(ambient);\r
+ }\r
+\r
+ return;\r
+ }\r
+\r
+ private void buildIkChainList(Element pmdModelElem)\r
+ throws TogaXmlException{\r
+ Element ikChainListElem =\r
+ getChild(pmdModelElem, "ikChainList");\r
+\r
+ List<IKChain> ikChainList = this.model.getIKChainList();\r
+\r
+ for(Element ikChainElem : eachChild(ikChainListElem, "ikChain")){\r
+ IKChain ikChain = new IKChain();\r
+ ikChainList.add(ikChain);\r
+\r
+ String ikBoneIdRef = getStringAttr(ikChainElem, "ikBoneIdRef");\r
+ int rucursiveDepth = getIntegerAttr(ikChainElem, "recursiveDepth");\r
+ float weight = getFloatAttr(ikChainElem, "weight");\r
+\r
+ BoneInfo ikBone = this.boneMap.get(ikBoneIdRef);\r
+ ikChain.setIkBone(ikBone);\r
+ ikChain.setIKDepth(rucursiveDepth);\r
+ ikChain.setIKWeight(weight);\r
+\r
+ List<BoneInfo> chainList = ikChain.getChainedBoneList();\r
+\r
+ for(Element orderElem : eachChild(ikChainElem, "chainOrder")){\r
+ String boneIdRef = getStringAttr(orderElem, "boneIdRef");\r
+ BoneInfo chaindBone = this.boneMap.get(boneIdRef);\r
+ chainList.add(chaindBone);\r
+ }\r
+ }\r
+\r
+ return;\r
+ }\r
+\r
+ private void buildMorphList(Element pmdModelElem)\r
+ throws TogaXmlException{\r
+ Element morphListElem =\r
+ getChild(pmdModelElem, "morphList");\r
+\r
+ Map<MorphType, List<MorphPart>> morphMap = this.model.getMorphMap();\r
+\r
+ for(Element morphElem : eachChild(morphListElem, "morph")){\r
+ MorphPart morphPart = new MorphPart();\r
+\r
+ I18nText name = morphPart.getMorphName();\r
+ buildI18nName(morphElem, name);\r
+\r
+ String type = getStringAttr(morphElem, "type");\r
+ MorphType morphType = MorphType.valueOf(type);\r
+ morphPart.setMorphType(morphType);\r
+\r
+ List<MorphVertex> morphVertexList = morphPart.getMorphVertexList();\r
+\r
+ for(Element morphVertexElem : eachChild(morphElem, "morphVertex")){\r
+ String vtxIdRef = getStringAttr(morphVertexElem, "vtxIdRef");\r
+ Vertex baseVertex = this.vertexMap.get(vtxIdRef);\r
+ float xOff = getFloatAttr(morphVertexElem, "xOff");\r
+ float yOff = getFloatAttr(morphVertexElem, "yOff");\r
+ float zOff = getFloatAttr(morphVertexElem, "zOff");\r
+\r
+ MorphVertex morphVertex = new MorphVertex();\r
+ morphVertex.setBaseVertex(baseVertex);\r
+ Pos3d position = morphVertex.getOffset();\r
+ position.setXPos(xOff);\r
+ position.setYPos(yOff);\r
+ position.setZPos(zOff);\r
+\r
+ morphVertexList.add(morphVertex);\r
+ }\r
+\r
+ morphMap.get(morphType).add(morphPart);\r
+ }\r
+\r
+ List<MorphPart> serialList = new LinkedList<MorphPart>();\r
+ MorphPart baseDummy = new MorphPart();\r
+ serialList.add(baseDummy);\r
+ for(MorphPart part : morphMap.get(MorphType.EYEBROW)){\r
+ serialList.add(part);\r
+ }\r
+ for(MorphPart part : morphMap.get(MorphType.EYE)){\r
+ serialList.add(part);\r
+ }\r
+ for(MorphPart part : morphMap.get(MorphType.LIP)){\r
+ serialList.add(part);\r
+ }\r
+ for(MorphPart part : morphMap.get(MorphType.EXTRA)){\r
+ serialList.add(part);\r
+ }\r
+ ListUtil.assignIndexedSerial(serialList);\r
+\r
+ return;\r
+ }\r
+\r
+ private void buildBoneGroupList(Element pmdModelElem)\r
+ throws TogaXmlException{\r
+ Element boneGroupListElem =\r
+ getChild(pmdModelElem, "boneGroupList");\r
+\r
+ List<BoneGroup> boneGroupList = this.model.getBoneGroupList();\r
+ BoneGroup defaultGroup = new BoneGroup();\r
+ boneGroupList.add(defaultGroup);\r
+\r
+ for(Element boneGroupElem : eachChild(boneGroupListElem, "boneGroup")){\r
+ BoneGroup group = new BoneGroup();\r
+ boneGroupList.add(group);\r
+\r
+ I18nText name = group.getGroupName();\r
+ buildI18nName(boneGroupElem, name);\r
+\r
+ for(Element boneGroupMemberElem : eachChild(boneGroupElem, "boneGroupMember")){\r
+ String boneIdRef = getStringAttr(boneGroupMemberElem, "boneIdRef");\r
+ BoneInfo bone = this.boneMap.get(boneIdRef);\r
+ group.getBoneList().add(bone);\r
+ }\r
+ }\r
+\r
+ ListUtil.assignIndexedSerial(boneGroupList);\r
+\r
+ return;\r
+ }\r
+\r
+ private void buildRigidList(Element pmdModelElem)\r
+ throws TogaXmlException{\r
+ Element rigidListElem =\r
+ getChild(pmdModelElem, "rigidList");\r
+\r
+ List<RigidInfo> rigidList = this.model.getRigidList();\r
+\r
+ for(Element rigidElem : eachChild(rigidListElem, "rigid")){\r
+ RigidInfo rigid = new RigidInfo();\r
+ rigidList.add(rigid);\r
+\r
+ I18nText name = rigid.getRigidName();\r
+ buildI18nName(rigidElem, name);\r
+\r
+ String behavior = getStringAttr(rigidElem, "behavior");\r
+ RigidBehaviorType type = RigidBehaviorType.valueOf(behavior);\r
+ rigid.setBehaviorType(type);\r
+\r
+ String rigidId = getStringAttr(rigidElem, "rigidId");\r
+ this.rigidMap.put(rigidId, rigid);\r
+\r
+ Element linkedBoneElem = getChild(rigidElem, "linkedBone");\r
+ String boneIdRef = getStringAttr(linkedBoneElem, "boneIdRef");\r
+ BoneInfo linkedBone = this.boneMap.get(boneIdRef);\r
+ rigid.setLinkedBone(linkedBone);\r
+\r
+ RigidShape rigidShape = rigid.getRigidShape();\r
+ if(hasChild(rigidElem, "rigidShapeSphere")){\r
+ Element shapeElem =\r
+ getChild(rigidElem, "rigidShapeSphere");\r
+ float radius = getFloatAttr(shapeElem, "radius");\r
+ rigidShape.setShapeType(RigidShapeType.SPHERE);\r
+ rigidShape.setRadius(radius);\r
+ }\r
+ if(hasChild(rigidElem, "rigidShapeBox")){\r
+ Element shapeElem =\r
+ getChild(rigidElem, "rigidShapeBox");\r
+ float width = getFloatAttr(shapeElem, "width");\r
+ float height = getFloatAttr(shapeElem, "height");\r
+ float depth = getFloatAttr(shapeElem, "depth");\r
+ rigidShape.setShapeType(RigidShapeType.BOX);\r
+ rigidShape.setWidth(width);\r
+ rigidShape.setHeight(height);\r
+ rigidShape.setDepth(depth);\r
+ }\r
+ if(hasChild(rigidElem, "rigidShapeCapsule")){\r
+ Element shapeElem =\r
+ getChild(rigidElem, "rigidShapeCapsule");\r
+ float height = getFloatAttr(shapeElem, "height");\r
+ float radius = getFloatAttr(shapeElem, "radius");\r
+ rigidShape.setShapeType(RigidShapeType.CAPSULE);\r
+ rigidShape.setHeight(height);\r
+ rigidShape.setRadius(radius);\r
+ }\r
+\r
+ float xVal;\r
+ float yVal;\r
+ float zVal;\r
+\r
+ Element positionElem = getChild(rigidElem, "position");\r
+ xVal = getFloatAttr(positionElem, "x");\r
+ yVal = getFloatAttr(positionElem, "y");\r
+ zVal = getFloatAttr(positionElem, "z");\r
+ Pos3d position = rigid.getPosition();\r
+ position.setXPos(xVal);\r
+ position.setYPos(yVal);\r
+ position.setZPos(zVal);\r
+\r
+ Element radRotationElem = getChild(rigidElem, "radRotation");\r
+ xVal = getFloatAttr(radRotationElem, "xRad");\r
+ yVal = getFloatAttr(radRotationElem, "yRad");\r
+ zVal = getFloatAttr(radRotationElem, "zRad");\r
+ Rad3d rotation = rigid.getRotation();\r
+ rotation.setXRad(xVal);\r
+ rotation.setYRad(yVal);\r
+ rotation.setZRad(zVal);\r
+\r
+ Element dynamicsElem = getChild(rigidElem, "dynamics");\r
+ float mass = getFloatAttr(dynamicsElem, "mass");\r
+ float dampingPosition = getFloatAttr(dynamicsElem, "dampingPosition");\r
+ float dampingRotation = getFloatAttr(dynamicsElem, "dampingRotation");\r
+ float restitution = getFloatAttr(dynamicsElem, "restitution");\r
+ float friction = getFloatAttr(dynamicsElem, "friction");\r
+ DynamicsInfo dynamics = rigid.getDynamicsInfo();\r
+ dynamics.setMass(mass);\r
+ dynamics.setDampingPosition(dampingPosition);\r
+ dynamics.setDampingRotation(dampingRotation);\r
+ dynamics.setRestitution(restitution);\r
+ dynamics.setFriction(friction);\r
+ }\r
+\r
+ ListUtil.assignIndexedSerial(rigidList);\r
+\r
+ return;\r
+ }\r
+\r
+ private void buildRigidGroupList(Element pmdModelElem)\r
+ throws TogaXmlException{\r
+ Element rigidGroupListElem =\r
+ getChild(pmdModelElem, "rigidGroupList");\r
+\r
+ List<RigidGroup> groupList = this.model.getRigidGroupList();\r
+\r
+ for(Element rigidGroupElem : eachChild(rigidGroupListElem, "rigidGroup")){\r
+ RigidGroup rigidGroup = new RigidGroup();\r
+ groupList.add(rigidGroup);\r
+\r
+ String rigidGroupId = getStringAttr(rigidGroupElem, "rigidGroupId");\r
+ this.rigidGroupMap.put(rigidGroupId, rigidGroup);\r
+\r
+ for(Element memberElem : eachChild(rigidGroupElem, "rigidGroupMember")){\r
+ String rigidIdRef = getStringAttr(memberElem, "rigidIdRef");\r
+ RigidInfo rigid = this.rigidMap.get(rigidIdRef);\r
+ rigidGroup.getRigidList().add(rigid);\r
+ rigid.setRigidGroup(rigidGroup);\r
+ }\r
+ }\r
+\r
+ while(groupList.size() < 16){\r
+ RigidGroup rigidGroup = new RigidGroup();\r
+ groupList.add(rigidGroup);\r
+ }\r
+\r
+ ListUtil.assignIndexedSerial(groupList);\r
+\r
+ return;\r
+ }\r
+\r
+ private void resolveThroughRigidGroup(Element pmdModelElem)\r
+ throws TogaXmlException{\r
+ Element rigidListElem =\r
+ getChild(pmdModelElem, "rigidList");\r
+\r
+ List<RigidInfo> rigidList = this.model.getRigidList();\r
+\r
+ int serialNum = 0;\r
+ for(Element rigidElem : eachChild(rigidListElem, "rigid")){\r
+ RigidInfo rigid = rigidList.get(serialNum++);\r
+ for(Element groupElem : eachChild(rigidElem, "throughRigidGroup")){\r
+ String groupId = getStringAttr(groupElem, "rigidGroupIdRef");\r
+ RigidGroup group = this.rigidGroupMap.get(groupId);\r
+ rigid.getThroughGroupColl().add(group);\r
+ }\r
+ }\r
+\r
+ return;\r
+ }\r
+\r
+ private void buildJointList(Element pmdModelElem)\r
+ throws TogaXmlException{\r
+ Element jointListElem =\r
+ getChild(pmdModelElem, "jointList");\r
+\r
+ List<JointInfo> jointList = this.model.getJointList();\r
+\r
+ for(Element jointElem : eachChild(jointListElem, "joint")){\r
+ JointInfo joint = new JointInfo();\r
+ jointList.add(joint);\r
+\r
+ I18nText name = joint.getJointName();\r
+ buildI18nName(jointElem, name);\r
+\r
+ Element rigidPairElem = getChild(jointElem, "jointedRigidPair");\r
+ String rigidIdRef1 = getStringAttr(rigidPairElem, "rigidIdRef1");\r
+ String rigidIdRef2 = getStringAttr(rigidPairElem, "rigidIdRef2");\r
+ RigidInfo rigid1 = this.rigidMap.get(rigidIdRef1);\r
+ RigidInfo rigid2 = this.rigidMap.get(rigidIdRef2);\r
+ joint.setRigidPair(rigid1, rigid2);\r
+\r
+ float xVal;\r
+ float yVal;\r
+ float zVal;\r
+ float xFrom;\r
+ float xTo;\r
+ float yFrom;\r
+ float yTo;\r
+ float zFrom;\r
+ float zTo;\r
+\r
+ Pos3d position = joint.getPosition();\r
+ Element positionElem = getChild(jointElem, "position");\r
+ xVal = getFloatAttr(positionElem, "x");\r
+ yVal = getFloatAttr(positionElem, "y");\r
+ zVal = getFloatAttr(positionElem, "z");\r
+ position.setXPos(xVal);\r
+ position.setYPos(yVal);\r
+ position.setZPos(zVal);\r
+\r
+ TripletRange limitPosition = joint.getPositionRange();\r
+ Element limitPositionElem = getChild(jointElem, "limitPosition");\r
+ xFrom = getFloatAttr(limitPositionElem, "xFrom");\r
+ xTo = getFloatAttr(limitPositionElem, "xTo");\r
+ yFrom = getFloatAttr(limitPositionElem, "yFrom");\r
+ yTo = getFloatAttr(limitPositionElem, "yTo");\r
+ zFrom = getFloatAttr(limitPositionElem, "zFrom");\r
+ zTo = getFloatAttr(limitPositionElem, "zTo");\r
+ limitPosition.setXRange(xFrom, xTo);\r
+ limitPosition.setYRange(yFrom, yTo);\r
+ limitPosition.setZRange(zFrom, zTo);\r
+\r
+ Rad3d rotation = joint.getRotation();\r
+ Element rotationElem = getChild(jointElem, "radRotation");\r
+ xVal = getFloatAttr(rotationElem, "xRad");\r
+ yVal = getFloatAttr(rotationElem, "yRad");\r
+ zVal = getFloatAttr(rotationElem, "zRad");\r
+ rotation.setXRad(xVal);\r
+ rotation.setYRad(yVal);\r
+ rotation.setZRad(zVal);\r
+\r
+ TripletRange limitRotation = joint.getRotationRange();\r
+ Element limitRotationElem = getChild(jointElem, "limitRotation");\r
+ xFrom = getFloatAttr(limitRotationElem, "xFrom");\r
+ xTo = getFloatAttr(limitRotationElem, "xTo");\r
+ yFrom = getFloatAttr(limitRotationElem, "yFrom");\r
+ yTo = getFloatAttr(limitRotationElem, "yTo");\r
+ zFrom = getFloatAttr(limitRotationElem, "zFrom");\r
+ zTo = getFloatAttr(limitRotationElem, "zTo");\r
+ limitRotation.setXRange(xFrom, xTo);\r
+ limitRotation.setYRange(yFrom, yTo);\r
+ limitRotation.setZRange(zFrom, zTo);\r
+\r
+ Pos3d elasticPosition = joint.getElasticPosition();\r
+ Element elasticPositionElem = getChild(jointElem, "elasticPosition");\r
+ xVal = getFloatAttr(elasticPositionElem, "x");\r
+ yVal = getFloatAttr(elasticPositionElem, "y");\r
+ zVal = getFloatAttr(elasticPositionElem, "z");\r
+ elasticPosition.setXPos(xVal);\r
+ elasticPosition.setYPos(yVal);\r
+ elasticPosition.setZPos(zVal);\r
+\r
+ Deg3d elasticRotation = joint.getElasticRotation();\r
+ Element elasticRotationElem = getChild(jointElem, "elasticRotation");\r
+ xVal = getFloatAttr(elasticRotationElem, "xDeg");\r
+ yVal = getFloatAttr(elasticRotationElem, "yDeg");\r
+ zVal = getFloatAttr(elasticRotationElem, "zDeg");\r
+ elasticRotation.setXDeg(xVal);\r
+ elasticRotation.setYDeg(yVal);\r
+ elasticRotation.setZDeg(zVal);\r
+ }\r
+\r
+ return;\r
+ }\r
+\r
+}\r
--- /dev/null
+/*\r
+ * package information for Javadoc\r
+ *\r
+ * License : The MIT License\r
+ * Copyright(c) 2010 MikuToga Partners\r
+ */\r
+\r
+/**\r
+ * PMDモデル内容をXMLで出力するためのライブラリ。\r
+ */\r
+\r
+package jp.sourceforge.mikutoga.pmd.xml;\r
+\r
+/* EOF */\r
--- /dev/null
+/*\r
+ * basic xml exporter\r
+ *\r
+ * License : The MIT License\r
+ * Copyright(c) 2010 MikuToga Partners\r
+ */\r
+\r
+package jp.sourceforge.mikutoga.xml;\r
+\r
+import java.io.BufferedWriter;\r
+import java.io.Closeable;\r
+import java.io.Flushable;\r
+import java.io.IOException;\r
+import java.io.OutputStream;\r
+import java.io.OutputStreamWriter;\r
+import java.nio.charset.Charset;\r
+import javax.xml.bind.DatatypeConverter;\r
+\r
+/**\r
+ * 各種XMLエクスポータの基本機能。\r
+ * UCS4は未サポート。\r
+ */\r
+public class BasicXmlExporter {\r
+\r
+ /** デフォルトエンコーディング。 */\r
+ private static final Charset CS_UTF8 = Charset.forName("UTF-8");\r
+\r
+ /** デフォルトの改行文字列。 */\r
+ private static final String LF = "\n"; // 0x0a\r
+ /** デフォルトのインデント単位。 */\r
+ private static final String DEFAULT_INDENT_UNIT = "\u0020\u0020";\r
+\r
+ private static final char[] HEXCHAR_TABLE = {\r
+ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',\r
+ 'A', 'B', 'C', 'D', 'E', 'F',\r
+ };\r
+\r
+ static{\r
+ assert HEXCHAR_TABLE.length == 16;\r
+ }\r
+\r
+\r
+ private final Appendable appendable;\r
+\r
+ private String newline = LF;\r
+ private String indentUnit = DEFAULT_INDENT_UNIT;\r
+\r
+ private int indentNest = 0;\r
+ private boolean basicLatinOnlyOut = true;\r
+\r
+\r
+ /**\r
+ * コンストラクタ。\r
+ * 文字エンコーディングはUTF-8が用いられる。\r
+ * @param stream 出力ストリーム\r
+ */\r
+ public BasicXmlExporter(OutputStream stream){\r
+ this(stream, CS_UTF8);\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * コンストラクタ。\r
+ * @param stream 出力ストリーム\r
+ * @param charSet 文字エンコーディング指定\r
+ */\r
+ public BasicXmlExporter(OutputStream stream, Charset charSet){\r
+ this(\r
+ new BufferedWriter(\r
+ new OutputStreamWriter(stream, charSet)\r
+ )\r
+ );\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * コンストラクタ。\r
+ * @param appendable 文字列出力\r
+ */\r
+ public BasicXmlExporter(Appendable appendable){\r
+ super();\r
+ this.appendable = appendable;\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * ASCIIコード相当(UCS:Basic-Latin)の文字か否か判定する。\r
+ * @param ch 判定対象文字\r
+ * @return Basic-Latin文字ならtrue\r
+ */\r
+ public static boolean isBasicLatin(char ch){\r
+ if(ch <= 0x7f) return true;\r
+ return false;\r
+ }\r
+\r
+ /**\r
+ * 改行文字列を設定する。\r
+ * @param newLine 改行文字列\r
+ * @throws NullPointerException 引数がnull\r
+ */\r
+ public void setNewLine(String newLine) throws NullPointerException{\r
+ if(newLine == null) throw new NullPointerException();\r
+ this.newline = newLine;\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * BasicLatin文字だけで出力するか設定する。\r
+ * BasicLatin以外の文字(≒日本語)をそのまま出力するか\r
+ * 文字参照で出力するかの設定が可能。\r
+ * コメント部中身は対象外。\r
+ * @param bool BasicLatin文字だけで出力するならtrue\r
+ */\r
+ public void setBasicLatinOnlyOut(boolean bool){\r
+ this.basicLatinOnlyOut = bool;\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * BasicLatin文字だけを出力する状態か判定する。\r
+ * コメント部中身は対象外。\r
+ * @return BasicLatin文字だけで出力するならtrue\r
+ */\r
+ public boolean isBasicLatinOnlyOut(){\r
+ return this.basicLatinOnlyOut;\r
+ }\r
+\r
+ /**\r
+ * 改行文字列を設定する。\r
+ * デフォルトではLF(0x0a)\nが用いられる。\r
+ * @param seq 改行文字列。nullは空文字列""と解釈される。\r
+ */\r
+ public void setNewLine(CharSequence seq){\r
+ if(seq == null) this.newline = "";\r
+ else this.newline = seq.toString();\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * インデント単位文字列を設定する。\r
+ * デフォルトでは空白2個。\r
+ * @param seq インデント単位文字列。nullは空文字列""と解釈される。\r
+ */\r
+ public void setIndentUnit(CharSequence seq){\r
+ if(seq == null) this.indentUnit = "";\r
+ else this.indentUnit = seq.toString();\r
+ }\r
+\r
+ /**\r
+ * 可能であれば出力をフラッシュする。\r
+ * @throws IOException 出力エラー\r
+ */\r
+ public void flush() throws IOException{\r
+ if(this.appendable instanceof Flushable){\r
+ ((Flushable)this.appendable).flush();\r
+ }\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * 可能であれば出力をクローズする。\r
+ * @throws IOException 出力エラー\r
+ */\r
+ public void close() throws IOException{\r
+ if(this.appendable instanceof Closeable){\r
+ ((Closeable)this.appendable).close();\r
+ }\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * 1文字出力する。\r
+ * @param ch 文字\r
+ * @return this本体\r
+ * @throws IOException 出力エラー\r
+ */\r
+ public BasicXmlExporter put(char ch) throws IOException{\r
+ this.appendable.append(ch);\r
+ return this;\r
+ }\r
+\r
+ /**\r
+ * 文字列を出力する。\r
+ * @param seq 文字列\r
+ * @return this本体\r
+ * @throws IOException 出力エラー\r
+ */\r
+ public BasicXmlExporter put(CharSequence seq) throws IOException{\r
+ this.appendable.append(seq);\r
+ return this;\r
+ }\r
+\r
+ /**\r
+ * int値を出力する。\r
+ * @param iVal int値\r
+ * @return this本体\r
+ * @throws IOException 出力エラー\r
+ * @see java.lang.Integer#toString(int)\r
+ */\r
+ public BasicXmlExporter put(int iVal) throws IOException{\r
+ String value = DatatypeConverter.printInt(iVal);\r
+ this.appendable.append(value);\r
+ return this;\r
+ }\r
+\r
+ /**\r
+ * float値を出力する。\r
+ * @param fVal float値\r
+ * @return this本体\r
+ * @throws IOException 出力エラー\r
+ * @see java.lang.Float#toString(float)\r
+ */\r
+ public BasicXmlExporter put(float fVal) throws IOException{\r
+ String value = DatatypeConverter.printFloat(fVal);\r
+ this.appendable.append(value);\r
+ return this;\r
+ }\r
+\r
+ /**\r
+ * 改行を出力する。\r
+ * @return this本体\r
+ * @throws IOException 出力エラー\r
+ */\r
+ public BasicXmlExporter ln() throws IOException{\r
+ this.appendable.append(this.newline);\r
+ return this;\r
+ }\r
+\r
+ /**\r
+ * 改行を指定回数出力する。\r
+ * @param count 改行回数。0以下の場合は何も出力しない。\r
+ * @return this本体\r
+ * @throws IOException 出力エラー\r
+ */\r
+ public BasicXmlExporter ln(int count) throws IOException{\r
+ for(int ct = 1; ct <= count; ct++){\r
+ this.appendable.append(this.newline);\r
+ }\r
+ return this;\r
+ }\r
+\r
+ /**\r
+ * インデントを出力する。\r
+ * インデント単位文字列をネストレベル回数分出力する。\r
+ * @return this本体\r
+ * @throws IOException 出力エラー\r
+ */\r
+ public BasicXmlExporter ind() throws IOException{\r
+ for(int ct = 1; ct <= this.indentNest; ct++){\r
+ put(this.indentUnit);\r
+ }\r
+ return this;\r
+ }\r
+\r
+ /**\r
+ * インデントレベルを一段下げる。\r
+ */\r
+ public void pushNest(){\r
+ this.indentNest++;\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * インデントレベルを一段上げる。\r
+ * インデントレベル0の状態をさらに上げようとした場合、何も起こらない。\r
+ */\r
+ public void popNest(){\r
+ this.indentNest--;\r
+ if(this.indentNest < 0) this.indentNest = 0;\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * 指定された文字を16進2桁の文字参照形式で出力する。\r
+ * 2桁で出力できない場合は4桁で出力する。\r
+ * @param ch 文字\r
+ * @return this本体\r
+ * @throws IOException 出力エラー\r
+ */\r
+ public BasicXmlExporter putCharRef2Hex(char ch) throws IOException{\r
+ if(ch > 0xff) return putCharRef4Hex(ch);\r
+\r
+ char hex3 = HEXCHAR_TABLE[(ch >> 4) & 0x000f];\r
+ char hex4 = HEXCHAR_TABLE[(ch ) & 0x000f];\r
+\r
+ this.appendable.append("&#x");\r
+ this.appendable.append(hex3);\r
+ this.appendable.append(hex4);\r
+ this.appendable.append(';');\r
+\r
+ return this;\r
+ }\r
+\r
+ /**\r
+ * 指定された文字を16進4桁の文字参照形式で出力する。\r
+ * UCS4に伴うサロゲートペアは未サポート\r
+ * @param ch 文字\r
+ * @return this本体\r
+ * @throws IOException 出力エラー\r
+ */\r
+ public BasicXmlExporter putCharRef4Hex(char ch) throws IOException{\r
+ char hex1 = HEXCHAR_TABLE[(ch >> 12) & 0x000f];\r
+ char hex2 = HEXCHAR_TABLE[(ch >> 8) & 0x000f];\r
+ char hex3 = HEXCHAR_TABLE[(ch >> 4) & 0x000f];\r
+ char hex4 = HEXCHAR_TABLE[(ch ) & 0x000f];\r
+\r
+ this.appendable.append("&#x");\r
+ this.appendable.append(hex1);\r
+ this.appendable.append(hex2);\r
+ this.appendable.append(hex3);\r
+ this.appendable.append(hex4);\r
+ this.appendable.append(';');\r
+\r
+ return this;\r
+ }\r
+\r
+ /**\r
+ * 要素の中身および属性値中身を出力する。\r
+ * 必要に応じてXML定義済み実体文字が割り振られた文字、\r
+ * コントロールコード、および非BasicLatin文字がエスケープされる。\r
+ * @param content 内容\r
+ * @return this本体\r
+ * @throws IOException 出力エラー\r
+ */\r
+ public BasicXmlExporter putContent(CharSequence content)\r
+ throws IOException{\r
+ int length = content.length();\r
+\r
+ for(int pos = 0; pos < length; pos++){\r
+ char ch = content.charAt(pos);\r
+ if(Character.isISOControl(ch)){\r
+ putCharRef2Hex(ch);\r
+ }else if( ! isBasicLatin(ch) && isBasicLatinOnlyOut()){\r
+ putCharRef4Hex(ch);\r
+ }else{\r
+ switch(ch){\r
+ case '&': this.appendable.append("&"); break;\r
+ case '<': this.appendable.append("<"); break;\r
+ case '>': this.appendable.append(">"); break;\r
+ case '"': this.appendable.append("""); break;\r
+ case '\'': this.appendable.append("'"); break;\r
+ case '\u00a5': this.appendable.append('\u005c\u005c'); break;\r
+ default: this.appendable.append(ch); break;\r
+ }\r
+ }\r
+ }\r
+\r
+ return this;\r
+ }\r
+\r
+ /**\r
+ * 属性値を出力する。\r
+ * @param attrName 属性名\r
+ * @param content 属性内容\r
+ * @return this本体\r
+ * @throws IOException 出力エラー\r
+ */\r
+ public BasicXmlExporter putAttr(CharSequence attrName,\r
+ CharSequence content)\r
+ throws IOException{\r
+ put(attrName).put('=').put('"').putContent(content).put('"');\r
+ return this;\r
+ }\r
+\r
+ /**\r
+ * int型属性値を出力する。\r
+ * @param attrName 属性名\r
+ * @param iVal int値\r
+ * @return this本体\r
+ * @throws IOException 出力エラー\r
+ */\r
+ public BasicXmlExporter putIntAttr(CharSequence attrName,\r
+ int iVal)\r
+ throws IOException{\r
+ put(attrName).put('=').put('"').put(iVal).put('"');\r
+ return this;\r
+ }\r
+\r
+ /**\r
+ * float型属性値を出力する。\r
+ * @param attrName 属性名\r
+ * @param fVal float値\r
+ * @return this本体\r
+ * @throws IOException 出力エラー\r
+ */\r
+ public BasicXmlExporter putFloatAttr(CharSequence attrName,\r
+ float fVal)\r
+ throws IOException{\r
+ put(attrName).put('=').put('"').put(fVal).put('"');\r
+ return this;\r
+ }\r
+\r
+ /**\r
+ * コメントの内容を出力する。\r
+ * コメント中の\n記号出現に伴い、\r
+ * あらかじめ指定された改行文字が出力される。\r
+ * \n以外のコントロールコード各種、\r
+ * 及び非BasicLatin文字はそのまま出力される。\r
+ * 連続するハイフン(-)記号間には強制的にスペースが挿入される。\r
+ * @param comment コメント内容\r
+ * @return this本体\r
+ * @throws IOException 出力エラー\r
+ */\r
+ public BasicXmlExporter putCommentContent(CharSequence comment)\r
+ throws IOException{\r
+ int length = comment.length();\r
+\r
+ char prev = '\0';\r
+ for(int pos = 0; pos < length; pos++){\r
+ char ch = comment.charAt(pos);\r
+ if(ch == '\n'){\r
+ ln();\r
+ prev = ch;\r
+ continue;\r
+ }\r
+ if(prev == '-' && ch == '-') put(' ');\r
+ put(ch);\r
+ prev = ch;\r
+ }\r
+\r
+ return this;\r
+ }\r
+\r
+ /**\r
+ * 1行コメントを出力する。\r
+ * コメント中の\n記号出現に伴い、\r
+ * あらかじめ指定された改行文字が出力される。\r
+ * \n以外のコントロールコード各種、\r
+ * 及び非BasicLatin文字はそのまま出力される。\r
+ * 連続するハイフン(-)記号間には強制的にスペースが挿入される。\r
+ * @param comment コメント内容\r
+ * @return this本体\r
+ * @throws IOException 出力エラー\r
+ */\r
+ public BasicXmlExporter putLineComment(CharSequence comment)\r
+ throws IOException{\r
+ put("<!--").put(' ');\r
+ putCommentContent(comment);\r
+ put(' ').put("-->");\r
+ return this;\r
+ }\r
+\r
+ /**\r
+ * ブロックコメントを出力する。\r
+ * コメント中の\n記号出現に伴い、\r
+ * あらかじめ指定された改行文字が出力される。\r
+ * \n以外のコントロールコード各種、\r
+ * 及び非BasicLatin文字はそのまま出力される。\r
+ * 連続するハイフン(-)記号間には強制的にスペースが挿入される。\r
+ * @param comment コメント内容\r
+ * @return this本体\r
+ * @throws IOException 出力エラー\r
+ */\r
+ public BasicXmlExporter putBlockComment(CharSequence comment)\r
+ throws IOException{\r
+ put("<!--").ln();\r
+\r
+ putCommentContent(comment);\r
+\r
+ int commentLength = comment.length();\r
+ if(commentLength > 0){\r
+ char lastCh = comment.charAt(commentLength - 1);\r
+ if(lastCh != '\n') ln();\r
+ }\r
+\r
+ put("-->").ln();\r
+\r
+ return this;\r
+ }\r
+\r
+}\r
--- /dev/null
+/*\r
+ * XML DOM utilities\r
+ *\r
+ * License : The MIT License\r
+ * Copyright(c) 2010 MikuToga Partners\r
+ */\r
+\r
+package jp.sourceforge.mikutoga.xml;\r
+\r
+import java.util.Iterator;\r
+import java.util.LinkedList;\r
+import java.util.List;\r
+import java.util.NoSuchElementException;\r
+import javax.xml.bind.DatatypeConverter;\r
+import org.w3c.dom.Element;\r
+import org.w3c.dom.Node;\r
+\r
+/**\r
+ * DOMユーティリティ。\r
+ */\r
+public final class DomUtils {\r
+\r
+ /**\r
+ * 隠しコンストラクタ。\r
+ */\r
+ private DomUtils(){\r
+ super();\r
+ assert false;\r
+ throw new AssertionError();\r
+ }\r
+\r
+ /**\r
+ * 要素からxsd:string型属性値を読み取る。\r
+ * @param elem 要素\r
+ * @param attrName 属性名\r
+ * @return 文字列\r
+ * @throw TogaXmlException 属性値が見つからなかった。\r
+ */\r
+ public static String getStringAttr(Element elem, String attrName)\r
+ throws TogaXmlException{\r
+ if( ! elem.hasAttribute(attrName) ){\r
+ String message = "Attr:[" + attrName + "] "\r
+ + "was not found in "\r
+ + "Elem:[" + elem.getTagName()+"]";\r
+ throw new TogaXmlException(message);\r
+ }\r
+\r
+ String result;\r
+ try{\r
+ result = elem.getAttribute(attrName);\r
+ }catch(IllegalArgumentException e){\r
+ String message = "Invalid attribute form [" + attrName + "]";\r
+ throw new TogaXmlException(message, e);\r
+ }\r
+\r
+ return result;\r
+ }\r
+\r
+ /**\r
+ * 要素からxsd:boolean型属性値を読み取る。\r
+ * @param elem 要素\r
+ * @param attrName 属性名\r
+ * @return 真ならtrue\r
+ * @throw TogaXmlException 属性値が見つからなかった。\r
+ */\r
+ public static boolean getBooleanAttr(Element elem, String attrName)\r
+ throws TogaXmlException{\r
+ String value = getStringAttr(elem, attrName);\r
+\r
+ boolean result;\r
+ try{\r
+ result = DatatypeConverter.parseBoolean(value);\r
+ }catch(IllegalArgumentException e){\r
+ String message =\r
+ "Invalid boolean attribute form "\r
+ + "[" + attrName + "][" + value + "]";\r
+ throw new TogaXmlException(message, e);\r
+ }\r
+\r
+ return result;\r
+ }\r
+\r
+ /**\r
+ * 要素からxsd:integer型属性値を読み取る。\r
+ * @param elem 要素\r
+ * @param attrName 属性名\r
+ * @return int値\r
+ * @throw TogaXmlException 属性値が見つからなかった。\r
+ */\r
+ public static int getIntegerAttr(Element elem, String attrName)\r
+ throws TogaXmlException{\r
+ String value = getStringAttr(elem, attrName);\r
+\r
+ int result;\r
+ try{\r
+ result = DatatypeConverter.parseInt(value);\r
+ }catch(IllegalArgumentException e){\r
+ String message =\r
+ "Invalid integer attribute form "\r
+ + "[" + attrName + "][" + value + "]";\r
+ throw new TogaXmlException(message, e);\r
+ }\r
+\r
+ return result;\r
+ }\r
+\r
+ /**\r
+ * 要素からxsd:float型属性値を読み取る。\r
+ * @param elem 要素\r
+ * @param attrName 属性名\r
+ * @return float値\r
+ * @throw TogaXmlException 属性値が見つからなかった。\r
+ */\r
+ public static float getFloatAttr(Element elem, String attrName)\r
+ throws TogaXmlException{\r
+ String value = getStringAttr(elem, attrName);\r
+\r
+ float result;\r
+ try{\r
+ result = DatatypeConverter.parseFloat(value);\r
+ }catch(IllegalArgumentException e){\r
+ String message =\r
+ "Invalid float attribute form "\r
+ + "[" + attrName + "][" + value + "]";\r
+ throw new TogaXmlException(message, e);\r
+ }\r
+\r
+ return result;\r
+ }\r
+\r
+ /**\r
+ * 要素から日本語Windows用ファイル名を属性値として読み取る。\r
+ * 念のため文字U+00A5は文字U-005Cに変換される。\r
+ * @param elem 要素\r
+ * @param attrName 属性名\r
+ * @return ファイル名\r
+ * @throw TogaXmlException 属性値が見つからなかった。\r
+ */\r
+ public static String getSjisFileNameAttr(Element elem, String attrName)\r
+ throws TogaXmlException{\r
+ String result;\r
+ try{\r
+ result = getStringAttr(elem, attrName);\r
+ }catch(IllegalArgumentException e){\r
+ String message =\r
+ "Invalid winfile attribute form "\r
+ + "[" + attrName + "]";\r
+ throw new TogaXmlException(message, e);\r
+ }\r
+\r
+ result.replace("" + '\u00a5', "" + '\u005c\u005c');\r
+\r
+ return result;\r
+ }\r
+\r
+ /**\r
+ * 指定された名前の子要素を1つだけ返す。\r
+ * @param parent 親要素\r
+ * @param tagName 子要素名\r
+ * @return 子要素\r
+ * @throw TogaXmlException 1つも見つからなかった\r
+ */\r
+ public static Element getChild(Element parent, String tagName)\r
+ throws TogaXmlException{\r
+ Element result = null;\r
+\r
+ for(Node node = parent.getFirstChild();\r
+ node != null;\r
+ node = node.getNextSibling() ){\r
+\r
+ if(node.getNodeType() != Node.ELEMENT_NODE) continue;\r
+ Element elem = (Element) node;\r
+\r
+ String elemTagName = elem.getTagName();\r
+ if( tagName.equals(elemTagName) ){\r
+ result = elem;\r
+ break;\r
+ }\r
+ }\r
+\r
+ if(result == null){\r
+ String message =\r
+ "Elem:[" + tagName + "] was not found in "\r
+ +"Elem:[" + parent.getTagName() + "]";\r
+ throw new TogaXmlException(message);\r
+ }\r
+\r
+ return result;\r
+ }\r
+\r
+ /**\r
+ * 親要素が指定された名前の子要素を持つか判定する。\r
+ * @param parent 親要素\r
+ * @param tagName 子要素名\r
+ * @return 指定名の子要素が存在すればtrue\r
+ */\r
+ public static boolean hasChild(Element parent, String tagName){\r
+ for(Node node = parent.getFirstChild();\r
+ node != null;\r
+ node = node.getNextSibling() ){\r
+\r
+ if(node.getNodeType() != Node.ELEMENT_NODE) continue;\r
+ Element elem = (Element) node;\r
+\r
+ String elemTagName = elem.getTagName();\r
+ if( tagName.equals(elemTagName) ) return true;\r
+ }\r
+\r
+ return false;\r
+ }\r
+\r
+ /**\r
+ * 指定された名前の子要素のリストを返す。\r
+ * @param parent 親要素\r
+ * @param childTag 子要素名\r
+ * @return 子要素のリスト\r
+ */\r
+ public static List<Element> getChildList(Element parent,\r
+ String childTag){\r
+ List<Element> result = new LinkedList<Element>();\r
+\r
+ for(Node node = parent.getFirstChild();\r
+ node != null;\r
+ node = node.getNextSibling() ){\r
+\r
+ if(node.getNodeType() != Node.ELEMENT_NODE) continue;\r
+ Element elem = (Element) node;\r
+\r
+ String tagName = elem.getTagName();\r
+ if( ! childTag.equals(tagName) ) continue;\r
+\r
+ result.add(elem);\r
+ }\r
+\r
+ return result;\r
+ }\r
+\r
+ /**\r
+ * 指定された名前の子要素の列挙子を返す。\r
+ * @param parent 親要素\r
+ * @param childTag 子要素名\r
+ * @return 子要素の列挙子\r
+ */\r
+ public static Iterator<Element> getChildIterator(Element parent,\r
+ String childTag){\r
+ Element firstElem;\r
+ try{\r
+ firstElem = getChild(parent, childTag);\r
+ }catch(TogaXmlException e){\r
+ firstElem = null;\r
+ }\r
+\r
+ Iterator<Element> result = new ElemIterator(firstElem);\r
+\r
+ return result;\r
+ }\r
+\r
+ /**\r
+ * 指定された名前の子要素のforeachを返す。\r
+ * @param parent 親要素\r
+ * @param childTag 子要素名\r
+ * @return 子要素のforeach\r
+ */\r
+ public static Iterable<Element> getEachChild(Element parent,\r
+ String childTag){\r
+ final Iterator<Element> iterator = getChildIterator(parent, childTag);\r
+ Iterable<Element> result = new Iterable<Element>(){\r
+ public Iterator<Element> iterator(){\r
+ return iterator;\r
+ }\r
+ };\r
+ return result;\r
+ }\r
+\r
+ /**\r
+ * 要素の次の要素を返す。\r
+ * @param elem 要素\r
+ * @return 次の要素。なければnull\r
+ */\r
+ public static Element nextElement(Element elem){\r
+ Node nextNode = elem;\r
+ for(;;){\r
+ nextNode = nextNode.getNextSibling();\r
+ if(nextNode == null) break;\r
+ if(nextNode.getNodeType() == Node.ELEMENT_NODE){\r
+ break;\r
+ }\r
+ }\r
+\r
+ return (Element) nextNode;\r
+ }\r
+\r
+ /**\r
+ * 同じ要素名を持つ次の要素を返す。\r
+ * @param elem 要素\r
+ * @return 次の要素。なければnull\r
+ */\r
+ public static Element nextNamedElement(Element elem){\r
+ String tagName = elem.getTagName();\r
+ Element nextElem = elem;\r
+ for(;;){\r
+ nextElem = nextElement(nextElem);\r
+ if(nextElem == null) break;\r
+ if(tagName.equals(nextElem.getTagName())) break;\r
+ }\r
+\r
+ return nextElem;\r
+ }\r
+\r
+ /**\r
+ * 同じ親要素と同じ要素名を持つ兄弟要素を列挙する列挙子。\r
+ */\r
+ private static class ElemIterator implements Iterator<Element>{\r
+ private Element next;\r
+\r
+ /**\r
+ * コンストラクタ。\r
+ * @param elem 最初の要素。nullを指定すれば空列挙子となる。\r
+ */\r
+ private ElemIterator(Element elem){\r
+ super();\r
+ this.next = elem;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @return {@inheritDoc}\r
+ */\r
+ public boolean hasNext(){\r
+ if(this.next == null) return false;\r
+ return true;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @return {@inheritDoc}\r
+ * @throws NoSuchElementException {@inheritDoc}\r
+ */\r
+ public Element next() throws NoSuchElementException{\r
+ if(this.next == null) throw new NoSuchElementException();\r
+ Element result = this.next;\r
+ this.next = nextNamedElement(this.next);\r
+ return result;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * ※ 未サポート。\r
+ */\r
+ public void remove(){\r
+ throw new UnsupportedOperationException();\r
+ }\r
+\r
+ }\r
+\r
+}\r
--- /dev/null
+/*\r
+ * exception about xml\r
+ *\r
+ * License : The MIT License\r
+ * Copyright(c) 2010 MikuToga Partners\r
+ */\r
+\r
+package jp.sourceforge.mikutoga.xml;\r
+\r
+/**\r
+ * 意図しないXML文書を検出した際の例外。\r
+ */\r
+@SuppressWarnings("serial")\r
+public class TogaXmlException extends Exception{\r
+\r
+ /**\r
+ * コンストラクタ。\r
+ */\r
+ public TogaXmlException(){\r
+ super();\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * コンストラクタ。\r
+ * @param message メッセージ\r
+ */\r
+ public TogaXmlException(String message){\r
+ super(message);\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * コンストラクタ。\r
+ * @param message メッセージ\r
+ * @param cause 原因の例外\r
+ */\r
+ public TogaXmlException(String message, Throwable cause){\r
+ super(message, cause);\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * コンストラクタ。\r
+ * @param cause 原因の例外\r
+ */\r
+ public TogaXmlException(Throwable cause){\r
+ super(cause);\r
+ return;\r
+ }\r
+\r
+}\r
--- /dev/null
+/*\r
+ * xml resource resolver\r
+ *\r
+ * License : The MIT License\r
+ * Copyright(c) 2009 olyutorskii\r
+ */\r
+\r
+package jp.sourceforge.mikutoga.xml;\r
+\r
+import java.io.IOException;\r
+import java.io.InputStream;\r
+import java.io.Reader;\r
+import java.net.URI;\r
+import java.net.URISyntaxException;\r
+import java.net.URL;\r
+import java.util.HashMap;\r
+import java.util.Map;\r
+import org.w3c.dom.ls.LSInput;\r
+import org.w3c.dom.ls.LSResourceResolver;\r
+import org.xml.sax.EntityResolver;\r
+import org.xml.sax.InputSource;\r
+import org.xml.sax.SAXException;\r
+\r
+/**\r
+ * URL変換マップに従い、XML文書からの外部参照をリダイレクトする。\r
+ * 相対URIはこのクラスをベースに解決される。\r
+ * 主な用途は外部スキーマのリソース化など。\r
+ */\r
+public class XmlResourceResolver\r
+ implements LSResourceResolver, EntityResolver {\r
+\r
+ public static final String SCHEMA_XML =\r
+ "http://www.w3.org/2001/xml.xsd";\r
+ public static final String NS_XSD =\r
+ "http://www.w3.org/2001/XMLSchema-instance";\r
+\r
+ private static final String LOCAL_SCHEMA_XML =\r
+ "./resources/xml-2009-01.xsd";\r
+ private static final URI EMPTY_URI = URI.create("");\r
+ private static final Class THISCLASS = XmlResourceResolver.class;\r
+\r
+\r
+ /**\r
+ * 絶対URIと相対URIを合成したURIを返す。\r
+ * 正規化も行われる。\r
+ * @param base 絶対URIでなければならない。nullでもよい。\r
+ * @param relative 絶対URIでもよいがその場合baseは無視される。null可。\r
+ * @return 合成結果のURLオブジェクト。必ず絶対URIになる。\r
+ * @throws java.net.URISyntaxException URIとして変。\r
+ * @throws java.lang.IllegalArgumentException 絶対URIが生成できない。\r
+ */\r
+ protected static URI buildBaseRelativeURI(String base, String relative)\r
+ throws URISyntaxException,\r
+ IllegalArgumentException {\r
+ URI baseURI = null;\r
+ if(base != null){\r
+ baseURI = new URI(base);\r
+ if( ! baseURI.isAbsolute() ) throw new IllegalArgumentException();\r
+ }\r
+\r
+ URI relativeURI = EMPTY_URI;\r
+ if(relative != null){\r
+ relativeURI = new URI(relative);\r
+ }\r
+\r
+ URI resultURI;\r
+ if(baseURI == null || relativeURI.isAbsolute()){\r
+ resultURI = relativeURI;\r
+ }else{\r
+ resultURI = baseURI.resolve(relativeURI);\r
+ }\r
+\r
+ if( ! resultURI.isAbsolute() ) throw new IllegalArgumentException();\r
+\r
+ resultURI = resultURI.normalize();\r
+\r
+ return resultURI;\r
+ }\r
+\r
+ /**\r
+ * LSInput実装を生成する。\r
+ * @return LSInput実装\r
+ */\r
+ public static LSInput createLSInput(){\r
+ LSInput input = new LSInputImpl();\r
+ return input;\r
+ }\r
+\r
+ private final Map<URI, URI> uriMap = new HashMap<URI, URI>();\r
+\r
+ /**\r
+ * コンストラクタ。\r
+ */\r
+ public XmlResourceResolver(){\r
+ super();\r
+\r
+ assert this.getClass().equals(THISCLASS);\r
+\r
+ URI originalURI = URI.create(SCHEMA_XML);\r
+ URL redirectURL = THISCLASS.getResource(LOCAL_SCHEMA_XML);\r
+ URI redirectURI;\r
+ try{\r
+ redirectURI = redirectURL.toURI();\r
+ }catch(URISyntaxException e){\r
+ assert false;\r
+ throw new AssertionError(e);\r
+ }\r
+\r
+ this.uriMap.put(originalURI, redirectURI);\r
+\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * オリジナルURIとリダイレクト先のURIを登録する。\r
+ * オリジナルURIへのアクセスはリダイレクトされる。\r
+ * @param original オリジナルURI\r
+ * @param redirect リダイレクトURI\r
+ */\r
+ public void putURIMap(URI original, URI redirect){\r
+ this.uriMap.put(original.normalize(), redirect.normalize());\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * 変換後のリソースの入力ストリームを得る。\r
+ * @param originalURI オリジナルURI\r
+ * @return 入力ストリーム\r
+ * @throws java.io.IOException 入出力エラー\r
+ */\r
+ public InputStream getXMLResourceAsStream(URI originalURI)\r
+ throws IOException{\r
+ URI resourceURI = this.uriMap.get(originalURI.normalize());\r
+ URL resourceURL = resourceURI.toURL();\r
+ InputStream is = resourceURL.openStream();\r
+\r
+ return is;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * URL変換したあとの入力ソースを返す。\r
+ * @param type {@inheritDoc}\r
+ * @param namespaceURI {@inheritDoc}\r
+ * @param publicId {@inheritDoc}\r
+ * @param systemId {@inheritDoc}\r
+ * @param baseURI {@inheritDoc}\r
+ * @return {@inheritDoc}\r
+ */\r
+ public LSInput resolveResource(String type,\r
+ String namespaceURI,\r
+ String publicId,\r
+ String systemId,\r
+ String baseURI ){\r
+ if(systemId == null) return null;\r
+\r
+ URI originalURI;\r
+ try{\r
+ originalURI = buildBaseRelativeURI(baseURI, systemId);\r
+ }catch(URISyntaxException e){\r
+ return null;\r
+ }\r
+\r
+ InputStream is;\r
+ try{\r
+ is = getXMLResourceAsStream(originalURI);\r
+ }catch(IOException e){\r
+ return null;\r
+ }\r
+\r
+ LSInput input = createLSInput();\r
+ input.setBaseURI(baseURI);\r
+ input.setPublicId(publicId);\r
+ input.setSystemId(systemId);\r
+ input.setByteStream(is);\r
+\r
+ return input;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * URL変換したあとの入力ソースを返す。\r
+ * @param publicId {@inheritDoc}\r
+ * @param systemId {@inheritDoc}\r
+ * @return {@inheritDoc}\r
+ * @throws org.xml.sax.SAXException {@inheritDoc}\r
+ * @throws java.io.IOException {@inheritDoc}\r
+ */\r
+ public InputSource resolveEntity(String publicId, String systemId)\r
+ throws SAXException, IOException{\r
+ if(systemId == null) return null;\r
+\r
+ URI originalUri;\r
+ try{\r
+ originalUri = new URI(systemId);\r
+ }catch(URISyntaxException e){\r
+ return null;\r
+ }\r
+\r
+ InputStream is = getXMLResourceAsStream(originalUri);\r
+\r
+ InputSource source = new InputSource(is);\r
+ source.setPublicId(publicId);\r
+ source.setSystemId(systemId);\r
+\r
+ return source;\r
+ }\r
+\r
+ /**\r
+ * JRE1.5用LSInput実装。\r
+ * JRE1.6なら\r
+ * org.w3c.dom.ls.DOMImplementationLS#createLSInput()\r
+ * で生成可能かも。\r
+ */\r
+ private static class LSInputImpl implements LSInput {\r
+\r
+ private String baseURI = null;\r
+ private InputStream byteStream = null;\r
+ private boolean certifiedText = false;\r
+ private Reader characterStream = null;\r
+ private String encoding = null;\r
+ private String publicId = null;\r
+ private String stringData = null;\r
+ private String systemId = null;\r
+\r
+ /**\r
+ * コンストラクタ。\r
+ */\r
+ private LSInputImpl(){\r
+ super();\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @return {@inheritDoc}\r
+ */\r
+ public String getBaseURI(){\r
+ return this.baseURI;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param baseURI {@inheritDoc}\r
+ */\r
+ public void setBaseURI(String baseURI){\r
+ this.baseURI = baseURI;\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @return {@inheritDoc}\r
+ */\r
+ public InputStream getByteStream(){\r
+ return this.byteStream;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param byteStream {@inheritDoc}\r
+ */\r
+ public void setByteStream(InputStream byteStream){\r
+ this.byteStream = byteStream;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @return {@inheritDoc}\r
+ */\r
+ public boolean getCertifiedText(){\r
+ return this.certifiedText;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param certifiedText {@inheritDoc}\r
+ */\r
+ public void setCertifiedText(boolean certifiedText){\r
+ this.certifiedText = certifiedText;\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @return {@inheritDoc}\r
+ */\r
+ public Reader getCharacterStream(){\r
+ return this.characterStream;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param characterStream {@inheritDoc}\r
+ */\r
+ public void setCharacterStream(Reader characterStream){\r
+ this.characterStream = characterStream;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @return {@inheritDoc}\r
+ */\r
+ public String getEncoding(){\r
+ return this.encoding;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param encoding {@inheritDoc}\r
+ */\r
+ public void setEncoding(String encoding){\r
+ this.encoding = encoding;\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @return {@inheritDoc}\r
+ */\r
+ public String getPublicId(){\r
+ return this.publicId;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param publicId {@inheritDoc}\r
+ */\r
+ public void setPublicId(String publicId){\r
+ this.publicId = publicId;\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @return {@inheritDoc}\r
+ */\r
+ public String getStringData(){\r
+ return this.stringData;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param stringData {@inheritDoc}\r
+ */\r
+ public void setStringData(String stringData){\r
+ this.stringData = stringData;\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @return {@inheritDoc}\r
+ */\r
+ public String getSystemId(){\r
+ return this.systemId;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ * @param systemId {@inheritDoc}\r
+ */\r
+ public void setSystemId(String systemId){\r
+ this.systemId = systemId;\r
+ return;\r
+ }\r
+\r
+ }\r
+\r
+ // TODO OASIS XML Catalog などと調和したい。\r
+}\r
--- /dev/null
+/*\r
+ * package information for Javadoc\r
+ *\r
+ * License : The MIT License\r
+ * Copyright(c) 2010 MikuToga Partners\r
+ */\r
+\r
+/**\r
+ * MikuToga XML共通ライブラリ。\r
+ */\r
+\r
+package jp.sourceforge.mikutoga.xml;\r
+\r
+/* EOF */\r
--- /dev/null
+#
+
+ROTATE = Rotate
+ROTMOV = Rotate/Move
+IK = IK
+UNKNOWN = Unknown
+UNDERIK = Under IK
+UNDERROT = Under rotate
+IKCONNECTED = IK connected
+HIDDEN = Hidden
+TWIST = Twist
+LINKEDROT = Linked Rotate
+
+### EOF ###
--- /dev/null
+#
+
+ROTATE = \u56de\u8ee2
+ROTMOV = \u56de\u8ee2/\u79fb\u52d5
+IK = IK
+UNKNOWN = \u4e0d\u660e
+UNDERIK = IK\u5f71\u97ff\u4e0b(\u56de\u8ee2)
+UNDERROT = \u56de\u8ee2\u5f71\u97ff\u4e0b
+IKCONNECTED = IK\u63a5\u7d9a\u5148
+HIDDEN = \u975e\u8868\u793a
+TWIST = \u6369\u308a
+LINKEDROT = \u56de\u8ee2\u9023\u52d5
+
+### EOF ###
--- /dev/null
+#
+
+BASE = base
+EYEBROW = brow
+EYE = eyes
+LIP = mouse
+EXTRA = other
+
+### EOF ###
--- /dev/null
+#
+
+BASE = base
+EYEBROW = \u307e\u3086
+EYE = \u76ee
+LIP = \u30ea\u30c3\u30d7
+EXTRA = \u305d\u306e\u4ed6
+
+### EOF ###
--- /dev/null
+#
+
+FOLLOWBONE = static(to bone)
+ONLYDYNAMICS = dynamic
+BONEDDYNAMICS = bone matching
+
+### EOF ###
--- /dev/null
+#
+
+FOLLOWBONE = \u30dc\u30fc\u30f3\u8ffd\u5f93
+ONLYDYNAMICS = \u7269\u7406\u6f14\u7b97
+BONEDDYNAMICS = \u30dc\u30fc\u30f3\u4f4d\u7f6e\u5408\u308f\u305b
+
+### EOF ###
--- /dev/null
+#
+
+SPHERE = sphere
+BOX = box
+CAPSULE = capsule
+
+### EOF ###
--- /dev/null
+#
+
+SPHERE = \u7403
+BOX = \u7bb1
+CAPSULE = \u30ab\u30d7\u30bb\u30eb
+
+### EOF ###
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<!--
+ MikuMikuDance
+ model-data(*.pmd) on XML
+ DTD definition
+
+ License : The MIT License
+ Copyright(c) 2010 MikuToga Partners
+
+ SYSTEM ID: http://mikutoga.sourceforge.jp/xml/dtd/pmdxml-100923.dtd
+-->
+
+
+<!-- ROOT -->
+<!ELEMENT pmdModel (
+ i18nName*, description+, license*, credits*, meta*,
+ materialList,
+ toonMap,
+ boneList,
+ boneGroupList,
+ ikChainList,
+ morphList,
+ rigidList,
+ rigidGroupList,
+ jointList,
+ surfaceGroupList,
+ vertexList
+) >
+<!ATTLIST pmdModel
+ xmlns CDATA #IMPLIED
+ xmlns:xsi CDATA #IMPLIED
+ xsi:schemaLocation CDATA #IMPLIED
+ schemaVersion CDATA #FIXED "100923"
+ name CDATA #REQUIRED
+>
+
+
+<!-- Multilingual name. -->
+<!ELEMENT i18nName EMPTY>
+<!ATTLIST i18nName
+ lang CDATA #REQUIRED
+ name CDATA #REQUIRED
+>
+
+
+<!-- Break line. -->
+<!ELEMENT br EMPTY>
+
+
+<!-- Description note about model. -->
+<!ELEMENT description (#PCDATA | br)* >
+<!ATTLIST description
+ lang CDATA "ja"
+ xml:space CDATA #FIXED "preserve"
+>
+
+
+<!-- License term of usage. -->
+<!ELEMENT license (#PCDATA | br)* >
+<!ATTLIST license
+ lang CDATA "ja"
+ xml:space CDATA #FIXED "preserve"
+>
+
+
+<!-- Credits for someone. -->
+<!ELEMENT credits (#PCDATA | br)* >
+<!ATTLIST credits
+ lang CDATA "ja"
+ xml:space CDATA #FIXED "preserve"
+>
+
+
+<!--
+Meta-information of model.
+Use free.
+but, some meta-name has recommended usage.
++ "generator" (Generator application name)
++ "siteURL" (Website URL)
++ "imageURL" (Thumbnail image URL)
+-->
+<!ELEMENT meta EMPTY>
+<!ATTLIST meta
+ name CDATA #REQUIRED
+ content CDATA #REQUIRED
+>
+
+
+<!--
+Material list.
+All visual things can be tracked from here.
+-->
+<!ELEMENT materialList (material)* >
+
+
+<!--
+Material definition.
+Colors, shading, any other definitions.
+-->
+<!ELEMENT material (
+ i18nName*,
+ diffuse,
+ specular,
+ ambient,
+ toon?,
+ textureFile?,
+ spheremapFile?
+)*>
+<!ATTLIST material
+ name CDATA #IMPLIED
+ showEdge CDATA #REQUIRED
+ surfaceGroupIdRef CDATA #REQUIRED
+>
+
+
+<!-- Diffuse color definition. -->
+<!ELEMENT diffuse EMPTY>
+<!ATTLIST diffuse
+ r CDATA #REQUIRED
+ g CDATA #REQUIRED
+ b CDATA #REQUIRED
+ alpha CDATA #REQUIRED
+>
+
+
+<!-- Specular color definition. -->
+<!ELEMENT specular EMPTY>
+<!ATTLIST specular
+ r CDATA #REQUIRED
+ g CDATA #REQUIRED
+ b CDATA #REQUIRED
+ shininess CDATA #REQUIRED
+>
+
+
+<!-- Ambient color definition. -->
+<!ELEMENT ambient EMPTY>
+<!ATTLIST ambient
+ r CDATA #REQUIRED
+ g CDATA #REQUIRED
+ b CDATA #REQUIRED
+>
+
+
+<!-- Reference for Toon-image. -->
+<!ELEMENT toon EMPTY>
+<!ATTLIST toon
+ toonFileIdRef CDATA #REQUIRED
+>
+
+
+<!-- Texture file information. -->
+<!ELEMENT textureFile EMPTY>
+<!ATTLIST textureFile
+ winFileName CDATA #REQUIRED
+>
+
+
+<!-- Sphere-map file information. -->
+<!ELEMENT spheremapFile EMPTY>
+<!ATTLIST spheremapFile
+ winFileName CDATA #REQUIRED
+>
+
+
+<!-- Toon-file mappings. -->
+<!ELEMENT toonMap (toonDef)* >
+
+
+<!-- Toon-file information. -->
+<!ELEMENT toonDef EMPTY>
+<!ATTLIST toonDef
+ toonFileId CDATA #REQUIRED
+ index CDATA #REQUIRED
+ winFileName CDATA #REQUIRED
+>
+
+
+<!-- List of bone information. -->
+<!ELEMENT boneList (bone)* >
+
+
+<!-- Bone definition. -->
+<!ELEMENT bone (
+ i18nName*,
+ position,
+ (rotationRatio | ikBone)?,
+ boneChain
+) >
+<!ATTLIST bone
+ name CDATA #REQUIRED
+ boneId CDATA #REQUIRED
+ type (
+ ROTATE
+ | ROTMOV
+ | IK
+ | UNKNOWN
+ | UNDERIK
+ | UNDERROT
+ | IKCONNECTED
+ | HIDDEN
+ | TWIST
+ | LINKEDROT
+ ) #REQUIRED
+>
+
+
+<!-- position information. -->
+<!ELEMENT position EMPTY>
+<!ATTLIST position
+ x CDATA #REQUIRED
+ y CDATA #REQUIRED
+ z CDATA #REQUIRED
+>
+
+
+<!-- Relationship-info between bones. -->
+<!ELEMENT boneChain EMPTY>
+<!ATTLIST boneChain
+ prevBoneIdRef CDATA #IMPLIED
+ nextBoneIdRef CDATA #IMPLIED
+>
+
+
+<!-- Rotation ratio between Linked-rotationed bones. -->
+<!ELEMENT rotationRatio EMPTY>
+<!ATTLIST rotationRatio
+ ratio CDATA #REQUIRED
+>
+
+
+<!-- Reference to IK-Bone. -->
+<!ELEMENT ikBone EMPTY>
+<!ATTLIST ikBone
+ boneIdRef CDATA #REQUIRED
+>
+
+
+<!-- List of Bone-group. -->
+<!ELEMENT boneGroupList (boneGroup)* >
+
+
+<!-- Bone-group. -->
+<!ELEMENT boneGroup (i18nName*, boneGroupMember*) >
+<!ATTLIST boneGroup
+ name CDATA #REQUIRED
+>
+
+
+<!-- Member of Bone-group. -->
+<!ELEMENT boneGroupMember EMPTY>
+<!ATTLIST boneGroupMember
+ boneIdRef CDATA #REQUIRED
+>
+
+
+<!-- List of IK chain. -->
+<!ELEMENT ikChainList (ikChain)* >
+
+
+<!-- IK chained bones definition. -->
+<!ELEMENT ikChain (chainOrder)+ >
+<!ATTLIST ikChain
+ ikBoneIdRef CDATA #REQUIRED
+ recursiveDepth CDATA #REQUIRED
+ weight CDATA #REQUIRED
+>
+
+
+<!-- Part of IK chained bones. -->
+<!ELEMENT chainOrder EMPTY>
+<!ATTLIST chainOrder
+ boneIdRef CDATA #REQUIRED
+>
+
+
+<!-- List of morphing definition. -->
+<!ELEMENT morphList (morph)* >
+
+
+<!-- Morphing definition. -->
+<!ELEMENT morph (i18nName*, morphVertex*) >
+<!ATTLIST morph
+ name CDATA #REQUIRED
+ type (
+ EYEBROW
+ | EYE
+ | LIP
+ | EXTRA
+ ) #REQUIRED
+>
+
+
+<!-- Morphing vertex information. -->
+<!ELEMENT morphVertex EMPTY>
+<!ATTLIST morphVertex
+ vtxIdRef CDATA #REQUIRED
+ xOff CDATA #REQUIRED
+ yOff CDATA #REQUIRED
+ zOff CDATA #REQUIRED
+>
+
+
+<!-- list of Rigid-body definition. -->
+<!ELEMENT rigidList (rigid)* >
+
+
+<!-- Rigid-body definition. -->
+<!ELEMENT rigid (
+ i18nName*,
+ linkedBone,
+ (rigidShapeSphere | rigidShapeBox | rigidShapeCapsule),
+ position,
+ radRotation,
+ dynamics,
+ throughRigidGroup*
+) >
+<!ATTLIST rigid
+ name CDATA #REQUIRED
+ rigidId CDATA #REQUIRED
+ behavior (
+ FOLLOWBONE
+ | ONLYDYNAMICS
+ | BONEDDYNAMICS
+ ) #REQUIRED
+>
+
+
+<!-- Referenced Bone from Rigid-body. -->
+<!ELEMENT linkedBone EMPTY>
+<!ATTLIST linkedBone
+ boneIdRef CDATA #REQUIRED
+>
+
+
+<!-- Sphere shape of Rigid-body. -->
+<!ELEMENT rigidShapeSphere EMPTY>
+<!ATTLIST rigidShapeSphere
+ radius CDATA #REQUIRED
+>
+
+
+<!-- Box shape of Rigid-body. -->
+<!ELEMENT rigidShapeBox EMPTY>
+<!ATTLIST rigidShapeBox
+ width CDATA #REQUIRED
+ height CDATA #REQUIRED
+ depth CDATA #REQUIRED
+>
+
+
+<!-- Capsule shape of Rigid-body. -->
+<!ELEMENT rigidShapeCapsule EMPTY>
+<!ATTLIST rigidShapeCapsule
+ height CDATA #REQUIRED
+ radius CDATA #REQUIRED
+>
+
+
+<!-- Rotaion information by radian. -->
+<!ELEMENT radRotation EMPTY>
+<!ATTLIST radRotation
+ xRad CDATA #REQUIRED
+ yRad CDATA #REQUIRED
+ zRad CDATA #REQUIRED
+>
+
+
+<!-- Dynamics parameters. -->
+<!ELEMENT dynamics EMPTY>
+<!ATTLIST dynamics
+ mass CDATA #REQUIRED
+ dampingPosition CDATA #REQUIRED
+ dampingRotation CDATA #REQUIRED
+ restitution CDATA #REQUIRED
+ friction CDATA #REQUIRED
+>
+
+
+<!-- Reference for non-collision rigid-group. -->
+<!ELEMENT throughRigidGroup EMPTY>
+<!ATTLIST throughRigidGroup
+ rigidGroupIdRef CDATA #REQUIRED
+>
+
+
+<!-- List of Rigid-body group. -->
+<!ELEMENT rigidGroupList (rigidGroup)* >
+
+
+<!-- Rigid-body group. -->
+<!ELEMENT rigidGroup (rigidGroupMember)* >
+<!ATTLIST rigidGroup
+ rigidGroupId CDATA #REQUIRED
+>
+
+
+<!-- Member of Rigid-body group. -->
+<!ELEMENT rigidGroupMember EMPTY>
+<!ATTLIST rigidGroupMember
+ rigidIdRef CDATA #REQUIRED
+>
+
+
+<!-- List of joint definition. -->
+<!ELEMENT jointList (joint)* >
+
+
+<!-- Joint definition. -->
+<!ELEMENT joint (
+ i18nName*,
+ jointedRigidPair,
+ position, limitPosition,
+ radRotation, limitRotation,
+ elasticPosition,
+ elasticRotation
+) >
+<!ATTLIST joint
+ name CDATA #REQUIRED
+>
+
+
+<!-- Jointed-bones information. -->
+<!ELEMENT jointedRigidPair EMPTY>
+<!ATTLIST jointedRigidPair
+ rigidIdRef2 CDATA #REQUIRED
+ rigidIdRef1 CDATA #REQUIRED
+>
+
+
+<!-- Limit of Position. -->
+<!ELEMENT limitPosition EMPTY>
+<!ATTLIST limitPosition
+ xFrom CDATA #REQUIRED
+ xTo CDATA #REQUIRED
+ yFrom CDATA #REQUIRED
+ yTo CDATA #REQUIRED
+ zFrom CDATA #REQUIRED
+ zTo CDATA #REQUIRED
+>
+
+
+<!-- Limit of Rotation. -->
+<!ELEMENT limitRotation EMPTY>
+<!ATTLIST limitRotation
+ xFrom CDATA #REQUIRED
+ xTo CDATA #REQUIRED
+ yFrom CDATA #REQUIRED
+ yTo CDATA #REQUIRED
+ zFrom CDATA #REQUIRED
+ zTo CDATA #REQUIRED
+>
+
+
+<!-- Elastic position of joint. -->
+<!ELEMENT elasticPosition EMPTY>
+<!ATTLIST elasticPosition
+ x CDATA #REQUIRED
+ y CDATA #REQUIRED
+ z CDATA #REQUIRED
+>
+
+
+<!-- Elastic rotation of joint by degree. -->
+<!ELEMENT elasticRotation EMPTY>
+<!ATTLIST elasticRotation
+ xDeg CDATA #REQUIRED
+ yDeg CDATA #REQUIRED
+ zDeg CDATA #REQUIRED
+>
+
+
+<!-- List of surface group. -->
+<!ELEMENT surfaceGroupList (surfaceGroup)* >
+
+
+<!-- Surface group. -->
+<!ELEMENT surfaceGroup (surface)* >
+<!ATTLIST surfaceGroup
+ surfaceGroupId CDATA #REQUIRED
+>
+
+
+<!-- Each surface with Triangle. -->
+<!ELEMENT surface EMPTY>
+<!ATTLIST surface
+ vtxIdRef1 CDATA #REQUIRED
+ vtxIdRef2 CDATA #REQUIRED
+ vtxIdRef3 CDATA #REQUIRED
+>
+
+
+<!-- List of vertex. -->
+<!ELEMENT vertexList (vertex)* >
+
+
+<!-- Vertex definition. -->
+<!ELEMENT vertex (position, normal, uvMap, skinning) >
+<!ATTLIST vertex
+ vtxId CDATA #REQUIRED
+ showEdge CDATA #REQUIRED
+>
+
+
+<!-- Normal vector definition. -->
+<!ELEMENT normal EMPTY>
+<!ATTLIST normal
+ x CDATA #REQUIRED
+ y CDATA #REQUIRED
+ z CDATA #REQUIRED
+>
+
+
+<!-- UV-mapping information. -->
+<!ELEMENT uvMap EMPTY>
+<!ATTLIST uvMap
+ u CDATA #REQUIRED
+ v CDATA #REQUIRED
+>
+
+
+<!-- Skinning definition from vertex to bone. -->
+<!ELEMENT skinning EMPTY>
+<!ATTLIST skinning
+ boneIdRef1 CDATA #REQUIRED
+ boneIdRef2 CDATA #REQUIRED
+ weightBalance CDATA #REQUIRED
+>
+
+
+<!-- EOF -->
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<!--
+ MikuMikuDance
+ model-data(*.pmd) on XML
+ schema definition
+
+ License : The MIT License
+ Copyright(c) 2010 MikuToga Partners
+-->
+
+
+<xsd:schema
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+
+ targetNamespace="http://mikutoga.sourceforge.jp/xml/ns/pmdxml/100923"
+ xmlns:tns ="http://mikutoga.sourceforge.jp/xml/ns/pmdxml/100923"
+
+ elementFormDefault="qualified"
+ version="100923"
+>
+
+ <xsd:annotation>
+ <xsd:documentation>
+ MikuMikuDance model-data(*.pmd) on XML.
+ License : The MIT License
+ Copyright(c) 2010 MikuToga Partners
+ </xsd:documentation>
+ </xsd:annotation>
+
+
+ <xsd:import
+ namespace="http://www.w3.org/XML/1998/namespace"
+ schemaLocation="http://www.w3.org/2001/xml.xsd" />
+
+
+ <!-- ROOT -->
+ <xsd:element name="pmdModel">
+ <xsd:annotation>
+ <xsd:documentation>
+ Root element.
+ </xsd:documentation>
+ </xsd:annotation>
+
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element ref="tns:i18nName"
+ minOccurs="0" maxOccurs="unbounded" />
+ <xsd:element ref="tns:description"
+ minOccurs="1" maxOccurs="unbounded" />
+ <xsd:element ref="tns:license"
+ minOccurs="0" maxOccurs="unbounded" />
+ <xsd:element ref="tns:credits"
+ minOccurs="0" maxOccurs="unbounded" />
+ <xsd:element ref="tns:meta"
+ minOccurs="0" maxOccurs="unbounded" />
+ <xsd:element ref="tns:materialList" />
+ <xsd:element ref="tns:toonMap" />
+ <xsd:element ref="tns:boneList" />
+ <xsd:element ref="tns:boneGroupList" />
+ <xsd:element ref="tns:ikChainList" />
+ <xsd:element ref="tns:morphList" />
+ <xsd:element ref="tns:rigidList" />
+ <xsd:element ref="tns:rigidGroupList" />
+ <xsd:element ref="tns:jointList" />
+ <xsd:element ref="tns:surfaceGroupList" />
+ <xsd:element ref="tns:vertexList" />
+ </xsd:sequence>
+ <xsd:attribute name="name" type="xsd:string" use="required" />
+ <xsd:attribute
+ name="schemaVersion"
+ type="xsd:string"
+ use="required"
+ fixed="100923" />
+ </xsd:complexType>
+
+ <xsd:unique name="ModelLang">
+ <xsd:selector xpath="./tns:i18nName" />
+ <xsd:field xpath="@lang" />
+ </xsd:unique>
+
+ <xsd:unique name="DescriptionLang">
+ <xsd:selector xpath="./tns:description" />
+ <xsd:field xpath="@lang" />
+ </xsd:unique>
+
+ <xsd:unique name="LicenseLang">
+ <xsd:selector xpath="./tns:license" />
+ <xsd:field xpath="@lang" />
+ </xsd:unique>
+
+ <xsd:unique name="CreditsLang">
+ <xsd:selector xpath="./tns:credits" />
+ <xsd:field xpath="@lang" />
+ </xsd:unique>
+
+ <xsd:keyref name="Material-SurfaceGroup" refer="tns:SurfaceGroup-Id">
+ <xsd:selector xpath="./tns:materialList/tns:material" />
+ <xsd:field xpath="@surfaceGroupIdRef" />
+ </xsd:keyref>
+
+ <xsd:keyref name="Material-Toon" refer="tns:Toon-Id">
+ <xsd:selector xpath="./tns:materialList/tns:material/tns:toon" />
+ <xsd:field xpath="@toonFileIdRef" />
+ </xsd:keyref>
+
+ <xsd:keyref name="Bone-prev" refer="tns:Bone-Id">
+ <xsd:selector xpath="./tns:boneList/tns:bone/tns:boneChain" />
+ <xsd:field xpath="@prevBoneIdRef" />
+ </xsd:keyref>
+
+ <xsd:keyref name="Bone-next" refer="tns:Bone-Id">
+ <xsd:selector xpath="./tns:boneList/tns:bone/tns:boneChain" />
+ <xsd:field xpath="@nextBoneIdRef" />
+ </xsd:keyref>
+
+ <xsd:keyref name="Bone-ik" refer="tns:Bone-Id">
+ <xsd:selector xpath="./tns:boneList/tns:bone/tns:ikBone" />
+ <xsd:field xpath="@boneIdRef" />
+ </xsd:keyref>
+
+ <xsd:keyref name="BoneGroup-Bone" refer="tns:Bone-Id">
+ <xsd:selector xpath="./tns:boneGroupList/tns:boneGroup/tns:boneGroupMember" />
+ <xsd:field xpath="@boneIdRef" />
+ </xsd:keyref>
+
+ <xsd:keyref name="IkChain-Bone" refer="tns:Bone-Id">
+ <xsd:selector xpath="./tns:ikChainList/tns:ikChain" />
+ <xsd:field xpath="@ikBoneIdRef" />
+ </xsd:keyref>
+
+ <xsd:keyref name="IkChainPart-Bone" refer="tns:Bone-Id">
+ <xsd:selector xpath="./tns:ikChainList/tns:ikChain/tns:chainOrder" />
+ <xsd:field xpath="@boneIdRef" />
+ </xsd:keyref>
+
+ <xsd:keyref name="Morph-Vertex" refer="tns:Vertex-Id">
+ <xsd:selector xpath="./tns:morphList/tns:morph/tns:morphVertex" />
+ <xsd:field xpath="@vtxIdRef" />
+ </xsd:keyref>
+
+ <xsd:keyref name="Rigid-Bone" refer="tns:Bone-Id">
+ <xsd:selector xpath="./tns:rigidList/tns:rigid/tns:linkedBone" />
+ <xsd:field xpath="@boneIdRef" />
+ </xsd:keyref>
+
+ <xsd:keyref name="Rigid-RigidGroup" refer="tns:RigidGroup-Id">
+ <xsd:selector xpath="./tns:rigidList/tns:rigid/tns:throughRigidGroup" />
+ <xsd:field xpath="@rigidGroupIdRef" />
+ </xsd:keyref>
+
+ <xsd:keyref name="RigidGroup-Rigid" refer="tns:Rigid-Id">
+ <xsd:selector xpath="./tns:rigidGroupList/tns:rigidGroup/tns:rigidGroupMember" />
+ <xsd:field xpath="@rigidIdRef" />
+ </xsd:keyref>
+
+ <xsd:keyref name="Joint-Rigid1" refer="tns:Rigid-Id">
+ <xsd:selector xpath="./tns:jointList/tns:joint/tns:jointedRigidPair" />
+ <xsd:field xpath="@rigidIdRef1" />
+ </xsd:keyref>
+
+ <xsd:keyref name="Joint-Rigid2" refer="tns:Rigid-Id">
+ <xsd:selector xpath="./tns:jointList/tns:joint/tns:jointedRigidPair" />
+ <xsd:field xpath="@rigidIdRef2" />
+ </xsd:keyref>
+
+ <xsd:keyref name="Surface-Vertex1" refer="tns:Vertex-Id">
+ <xsd:selector xpath="./tns:surfaceGroupList/tns:surfaceGroup/tns:surface" />
+ <xsd:field xpath="@vtxIdRef1" />
+ </xsd:keyref>
+
+ <xsd:keyref name="Surface-Vertex2" refer="tns:Vertex-Id">
+ <xsd:selector xpath="./tns:surfaceGroupList/tns:surfaceGroup/tns:surface" />
+ <xsd:field xpath="@vtxIdRef2" />
+ </xsd:keyref>
+
+ <xsd:keyref name="Surface-Vertex3" refer="tns:Vertex-Id">
+ <xsd:selector xpath="./tns:surfaceGroupList/tns:surfaceGroup/tns:surface" />
+ <xsd:field xpath="@vtxIdRef3" />
+ </xsd:keyref>
+
+ <xsd:keyref name="Vertex-Bone1" refer="tns:Bone-Id">
+ <xsd:selector xpath="./tns:vertexList/tns:vertex/tns:skinning" />
+ <xsd:field xpath="@boneIdRef1" />
+ </xsd:keyref>
+
+ <xsd:keyref name="Vertex-Bone2" refer="tns:Bone-Id">
+ <xsd:selector xpath="./tns:vertexList/tns:vertex/tns:skinning" />
+ <xsd:field xpath="@boneIdRef2" />
+ </xsd:keyref>
+
+ </xsd:element>
+
+
+ <xsd:simpleType name="NonJaLanguage">
+ <xsd:annotation>
+ <xsd:documentation>
+ xsd:language except "ja" (Primary-language in MMD)
+ </xsd:documentation>
+ </xsd:annotation>
+
+ <xsd:restriction base="xsd:language">
+ <xsd:pattern value="([^jJ].*)|([jJ][^aA].*)|([jJ][aA].+)" />
+ </xsd:restriction>
+
+ </xsd:simpleType>
+
+
+ <xsd:element name="i18nName">
+ <xsd:annotation>
+ <xsd:documentation>
+ Multilingual name.
+ </xsd:documentation>
+ </xsd:annotation>
+
+ <xsd:complexType>
+ <xsd:attribute
+ name="lang"
+ type="tns:NonJaLanguage"
+ use="required" />
+ <xsd:attribute
+ name="name"
+ type="xsd:string"
+ use="required" />
+ </xsd:complexType>
+
+ </xsd:element>
+
+
+ <xsd:element name="br">
+ <xsd:annotation>
+ <xsd:documentation>
+ Break line.
+ </xsd:documentation>
+ </xsd:annotation>
+ </xsd:element>
+
+
+ <xsd:complexType name="bredContent" mixed="true">
+ <xsd:annotation>
+ <xsd:documentation>
+ Free paragraph with break-line.
+ Any raw-newline(CR,CRLF) will be ignored later.
+ But, other white-spaces will be preserved.
+ </xsd:documentation>
+ </xsd:annotation>
+
+ <xsd:sequence>
+ <xsd:element ref="tns:br" minOccurs="0" maxOccurs="unbounded" />
+ </xsd:sequence>
+
+ <xsd:attribute
+ name="lang"
+ type="xsd:language"
+ use="optional"
+ default="ja" />
+ <xsd:attribute ref="xml:space" use="optional" fixed="preserve" />
+
+ </xsd:complexType>
+
+
+ <xsd:element name="description" type="tns:bredContent">
+ <xsd:annotation>
+ <xsd:documentation>
+ Description note about model.
+ </xsd:documentation>
+ </xsd:annotation>
+ </xsd:element>
+
+
+ <xsd:element name="license" type="tns:bredContent">
+ <xsd:annotation>
+ <xsd:documentation>
+ License term of usage.
+ </xsd:documentation>
+ </xsd:annotation>
+ </xsd:element>
+
+
+ <xsd:element name="credits" type="tns:bredContent">
+ <xsd:annotation>
+ <xsd:documentation>
+ Credits for someone.
+ </xsd:documentation>
+ </xsd:annotation>
+ </xsd:element>
+
+
+ <xsd:element name="meta">
+ <xsd:annotation>
+ <xsd:documentation>
+ Meta-information of model.
+ Use free.
+ but, some meta-name has recommended usage.
+ + "generator" (Generator application name)
+ + "siteURL" (Website URL)
+ + "imageURL" (Thumbnail image URL)
+ </xsd:documentation>
+ </xsd:annotation>
+
+ <xsd:complexType>
+ <xsd:attribute
+ name="name"
+ type="xsd:NCName"
+ use="required" />
+ <xsd:attribute
+ name="content"
+ type="xsd:string"
+ use="required" />
+ </xsd:complexType>
+
+ </xsd:element>
+
+
+ <xsd:element name="materialList">
+ <xsd:annotation>
+ <xsd:documentation>
+ Material list.
+ All visual things can be tracked from here.
+ </xsd:documentation>
+ </xsd:annotation>
+
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element
+ ref="tns:material"
+ minOccurs="0" maxOccurs="unbounded" />
+ </xsd:sequence>
+ </xsd:complexType>
+
+ <xsd:unique name="SurfaceGroupRef">
+ <xsd:selector xpath="./tns:material" />
+ <xsd:field xpath="@surfaceGroupIdRef" />
+ </xsd:unique>
+
+ </xsd:element>
+
+
+ <xsd:element name="material">
+ <xsd:annotation>
+ <xsd:documentation>
+ Material definition.
+ Colors, shading, any other definitions.
+ </xsd:documentation>
+ </xsd:annotation>
+
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element ref="tns:i18nName" minOccurs="0" maxOccurs="unbounded"/>
+ <xsd:element ref="tns:diffuse" />
+ <xsd:element ref="tns:specular" />
+ <xsd:element ref="tns:ambient" />
+ <xsd:element ref="tns:toon" minOccurs="0" />
+ <xsd:element ref="tns:textureFile" minOccurs="0" />
+ <xsd:element ref="tns:spheremapFile" minOccurs="0" />
+ </xsd:sequence>
+
+ <xsd:attribute
+ name="name"
+ type="xsd:string"
+ use="optional" />
+ <xsd:attribute
+ name="showEdge"
+ type="xsd:boolean"
+ use="required" />
+ <xsd:attribute
+ name="surfaceGroupIdRef"
+ type="xsd:NCName"
+ use="required" />
+ </xsd:complexType>
+
+ </xsd:element>
+
+
+ <xsd:simpleType name="SrgbCompo">
+ <xsd:annotation>
+ <xsd:documentation>
+ sRGB component value. (0.0 - 1.0)
+ </xsd:documentation>
+ </xsd:annotation>
+
+ <xsd:restriction base="xsd:float">
+ <xsd:minInclusive value="0.0" />
+ <xsd:maxInclusive value="1.0" />
+ </xsd:restriction>
+
+ </xsd:simpleType>
+
+
+ <xsd:element name="diffuse">
+ <xsd:annotation>
+ <xsd:documentation>
+ Diffuse color definition.
+ </xsd:documentation>
+ </xsd:annotation>
+
+ <xsd:complexType>
+ <xsd:attribute name="r" type="tns:SrgbCompo" use="required" />
+ <xsd:attribute name="g" type="tns:SrgbCompo" use="required" />
+ <xsd:attribute name="b" type="tns:SrgbCompo" use="required" />
+ <xsd:attribute name="alpha" type="tns:SrgbCompo" use="required" />
+ </xsd:complexType>
+
+ </xsd:element>
+
+
+ <xsd:element name="specular">
+ <xsd:annotation>
+ <xsd:documentation>
+ Specular color definition.
+ </xsd:documentation>
+ </xsd:annotation>
+
+ <xsd:complexType>
+ <xsd:attribute name="r" type="tns:SrgbCompo" use="required" />
+ <xsd:attribute name="g" type="tns:SrgbCompo" use="required" />
+ <xsd:attribute name="b" type="tns:SrgbCompo" use="required" />
+ <xsd:attribute name="shininess" type="xsd:float" use="required" />
+ </xsd:complexType>
+
+ </xsd:element>
+
+
+ <xsd:element name="ambient">
+ <xsd:annotation>
+ <xsd:documentation>
+ Ambient color definition.
+ </xsd:documentation>
+ </xsd:annotation>
+
+ <xsd:complexType>
+ <xsd:attribute name="r" type="tns:SrgbCompo" use="required" />
+ <xsd:attribute name="g" type="tns:SrgbCompo" use="required" />
+ <xsd:attribute name="b" type="tns:SrgbCompo" use="required" />
+ </xsd:complexType>
+
+ </xsd:element>
+
+
+ <xsd:element name="toon">
+ <xsd:annotation>
+ <xsd:documentation>
+ Reference for Toon-image.
+ </xsd:documentation>
+ </xsd:annotation>
+
+ <xsd:complexType>
+ <xsd:attribute
+ name="toonFileIdRef"
+ type="xsd:NCName"
+ use="required" />
+ </xsd:complexType>
+
+ </xsd:element>
+
+
+ <xsd:element name="textureFile">
+ <xsd:annotation>
+ <xsd:documentation>
+ Texture file information.
+ </xsd:documentation>
+ </xsd:annotation>
+
+ <xsd:complexType>
+ <xsd:attribute
+ name="winFileName"
+ type="xsd:string"
+ use="required" />
+ </xsd:complexType>
+
+ </xsd:element>
+
+
+ <xsd:element name="spheremapFile">
+ <xsd:annotation>
+ <xsd:documentation>
+ Sphere-map file information.
+ </xsd:documentation>
+ </xsd:annotation>
+
+ <xsd:complexType>
+ <xsd:attribute
+ name="winFileName"
+ type="xsd:string"
+ use="required" />
+ </xsd:complexType>
+
+ </xsd:element>
+
+
+ <xsd:element name="toonMap">
+ <xsd:annotation>
+ <xsd:documentation>
+ Toon-file mappings.
+ </xsd:documentation>
+ </xsd:annotation>
+
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element
+ ref="tns:toonDef"
+ minOccurs="0" maxOccurs="unbounded" />
+ </xsd:sequence>
+ </xsd:complexType>
+
+ <xsd:unique name="ToonIndex">
+ <xsd:selector xpath="./tns:toonDef" />
+ <xsd:field xpath="@index" />
+ </xsd:unique>
+
+ <xsd:key name="Toon-Id">
+ <xsd:selector xpath="./tns:toonDef" />
+ <xsd:field xpath="@toonFileId" />
+ </xsd:key>
+
+ </xsd:element>
+
+
+ <xsd:element name="toonDef">
+ <xsd:annotation>
+ <xsd:documentation>
+ Toon-file information.
+ </xsd:documentation>
+ </xsd:annotation>
+
+ <xsd:complexType>
+ <xsd:attribute
+ name="toonFileId"
+ type="xsd:NCName"
+ use="required" />
+ <xsd:attribute
+ name="index"
+ type="xsd:nonNegativeInteger"
+ use="required" />
+ <xsd:attribute
+ name="winFileName"
+ type="xsd:string"
+ use="required" />
+ </xsd:complexType>
+
+ </xsd:element>
+
+
+ <xsd:element name="boneList">
+ <xsd:annotation>
+ <xsd:documentation>
+ List of bone information.
+ </xsd:documentation>
+ </xsd:annotation>
+
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element ref="tns:bone" minOccurs="0" maxOccurs="unbounded" />
+ </xsd:sequence>
+ </xsd:complexType>
+
+ <xsd:key name="Bone-Id">
+ <xsd:selector xpath="./tns:bone" />
+ <xsd:field xpath="@boneId" />
+ </xsd:key>
+<!--
+ <xsd:unique name="BoneName">
+ <xsd:selector xpath="./tns:bone" />
+ <xsd:field xpath="@name" />
+ </xsd:unique>
+-->
+ </xsd:element>
+
+
+ <xsd:simpleType name="BoneType">
+ <xsd:annotation>
+ <xsd:documentation>
+ bone types.
+ </xsd:documentation>
+ </xsd:annotation>
+
+ <xsd:restriction base="xsd:string">
+ <xsd:enumeration value="ROTATE" /> <!-- 回転 -->
+ <xsd:enumeration value="ROTMOV" /> <!-- 回転/移動 -->
+ <xsd:enumeration value="IK" /> <!-- IK -->
+ <xsd:enumeration value="UNKNOWN" /> <!-- 不明 -->
+ <xsd:enumeration value="UNDERIK" /> <!-- IK影響下(回転) -->
+ <xsd:enumeration value="UNDERROT" /> <!-- 回転影響下 -->
+ <xsd:enumeration value="IKCONNECTED" /> <!-- IK接続先 -->
+ <xsd:enumeration value="HIDDEN" /> <!-- 非表示 -->
+ <xsd:enumeration value="TWIST" /> <!-- 捩り -->
+ <xsd:enumeration value="LINKEDROT" /> <!-- 回転連動 -->
+ </xsd:restriction>
+
+ </xsd:simpleType>
+
+
+ <xsd:element name="bone">
+ <xsd:annotation>
+ <xsd:documentation>
+ Bone definition.
+ </xsd:documentation>
+ </xsd:annotation>
+
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element ref="tns:i18nName" minOccurs="0" maxOccurs="unbounded" />
+ <xsd:element ref="tns:position" />
+ <xsd:choice minOccurs="0">
+ <xsd:element ref="tns:rotationRatio" />
+ <xsd:element ref="tns:ikBone" />
+ </xsd:choice>
+ <xsd:element ref="tns:boneChain" />
+ </xsd:sequence>
+
+ <xsd:attribute name="name" type="xsd:string" use="required" />
+ <xsd:attribute name="boneId" type="xsd:NCName" use="required" />
+ <xsd:attribute name="type" type="tns:BoneType" use="required" />
+ </xsd:complexType>
+
+ </xsd:element>
+
+
+ <xsd:element name="boneChain">
+ <xsd:annotation>
+ <xsd:documentation>
+ Relationship-info between bones.
+ </xsd:documentation>
+ </xsd:annotation>
+
+ <xsd:complexType>
+ <xsd:attribute
+ name="prevBoneIdRef"
+ type="xsd:NCName"
+ use="optional" />
+ <xsd:attribute
+ name="nextBoneIdRef"
+ type="xsd:NCName"
+ use="optional" />
+ </xsd:complexType>
+
+ </xsd:element>
+
+
+ <xsd:element name="rotationRatio">
+ <xsd:annotation>
+ <xsd:documentation>
+ Rotation ratio between Linked-rotationed bones.
+ </xsd:documentation>
+ </xsd:annotation>
+
+ <xsd:complexType>
+ <xsd:attribute
+ name="ratio"
+ type="xsd:integer"
+ use="required" />
+ </xsd:complexType>
+
+ </xsd:element>
+
+
+ <xsd:element name="ikBone">
+ <xsd:annotation>
+ <xsd:documentation>
+ Reference to IK-Bone.
+ </xsd:documentation>
+ </xsd:annotation>
+
+ <xsd:complexType>
+ <xsd:attribute
+ name="boneIdRef"
+ type="xsd:NCName"
+ use="required" />
+ </xsd:complexType>
+
+ </xsd:element>
+
+
+ <xsd:element name="boneGroupList">
+ <xsd:annotation>
+ <xsd:documentation>
+ List of Bone-group.
+ </xsd:documentation>
+ </xsd:annotation>
+
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element
+ ref="tns:boneGroup"
+ minOccurs="0" maxOccurs="unbounded" />
+ </xsd:sequence>
+ </xsd:complexType>
+
+<!--
+ <xsd:unique name="BoneGroupName">
+ <xsd:selector xpath="./tns:boneGroup" />
+ <xsd:field xpath="@name" />
+ </xsd:unique>
+-->
+ </xsd:element>
+
+
+ <xsd:element name="boneGroup">
+ <xsd:annotation>
+ <xsd:documentation>
+ Bone-group.
+ </xsd:documentation>
+ </xsd:annotation>
+
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element
+ ref="tns:i18nName"
+ minOccurs="0" maxOccurs="unbounded" />
+ <xsd:element
+ ref="tns:boneGroupMember"
+ minOccurs="0" maxOccurs="unbounded" />
+ </xsd:sequence>
+ <xsd:attribute
+ name="name"
+ type="xsd:string"
+ use="required" />
+ </xsd:complexType>
+
+ </xsd:element>
+
+
+ <xsd:element name="boneGroupMember">
+ <xsd:annotation>
+ <xsd:documentation>
+ Member of Bone-group.
+ </xsd:documentation>
+ </xsd:annotation>
+
+ <xsd:complexType>
+ <xsd:attribute
+ name="boneIdRef"
+ type="xsd:NCName"
+ use="required" />
+ </xsd:complexType>
+
+ </xsd:element>
+
+
+ <xsd:element name="ikChainList">
+ <xsd:annotation>
+ <xsd:documentation>
+ List of IK chain.
+ </xsd:documentation>
+ </xsd:annotation>
+
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element
+ ref="tns:ikChain"
+ minOccurs="0" maxOccurs="unbounded" />
+ </xsd:sequence>
+ </xsd:complexType>
+
+ <xsd:unique name="IkChainBone">
+ <xsd:selector xpath="./tns:ikChain" />
+ <xsd:field xpath="@ikBoneIdRef" />
+ </xsd:unique>
+
+ </xsd:element>
+
+
+ <xsd:element name="ikChain">
+ <xsd:annotation>
+ <xsd:documentation>
+ IK chained bones definition.
+ </xsd:documentation>
+ </xsd:annotation>
+
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element
+ ref="tns:chainOrder"
+ minOccurs="1" maxOccurs="unbounded" />
+ </xsd:sequence>
+
+ <xsd:attribute
+ name="ikBoneIdRef"
+ type="xsd:NCName"
+ use="required" />
+ <xsd:attribute
+ name="recursiveDepth"
+ type="xsd:integer"
+ use="required" />
+ <xsd:attribute
+ name="weight"
+ type="xsd:float"
+ use="required" />
+ </xsd:complexType>
+
+ </xsd:element>
+
+
+ <xsd:element name="chainOrder">
+ <xsd:annotation>
+ <xsd:documentation>
+ Part of IK chained bones.
+ </xsd:documentation>
+ </xsd:annotation>
+
+ <xsd:complexType>
+ <xsd:attribute
+ name="boneIdRef"
+ type="xsd:NCName"
+ use="required" />
+ </xsd:complexType>
+
+ </xsd:element>
+
+
+ <xsd:element name="morphList">
+ <xsd:annotation>
+ <xsd:documentation>
+ List of morphing definition.
+ </xsd:documentation>
+ </xsd:annotation>
+
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element
+ ref="tns:morph"
+ minOccurs="0" maxOccurs="unbounded" />
+ </xsd:sequence>
+ </xsd:complexType>
+
+<!--
+ <xsd:unique name="MorphName">
+ <xsd:selector xpath="./tns:morph" />
+ <xsd:field xpath="@name" />
+ </xsd:unique>
+-->
+ </xsd:element>
+
+
+ <xsd:simpleType name="MorphType">
+ <xsd:annotation>
+ <xsd:documentation>
+ Morph types.
+ </xsd:documentation>
+ </xsd:annotation>
+
+ <xsd:restriction base="xsd:string">
+ <xsd:enumeration value="EYEBROW" /> <!-- まゆ -->
+ <xsd:enumeration value="EYE" /> <!-- 目 -->
+ <xsd:enumeration value="LIP" /> <!-- リップ -->
+ <xsd:enumeration value="EXTRA" /> <!-- その他 -->
+ </xsd:restriction>
+
+ </xsd:simpleType>
+
+
+ <xsd:element name="morph">
+ <xsd:annotation>
+ <xsd:documentation>
+ Morphing definition.
+ </xsd:documentation>
+ </xsd:annotation>
+
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element
+ ref="tns:i18nName"
+ minOccurs="0" maxOccurs="unbounded" />
+ <xsd:element
+ ref="tns:morphVertex"
+ minOccurs="0" maxOccurs="unbounded" />
+ </xsd:sequence>
+ <xsd:attribute
+ name="name"
+ type="xsd:string"
+ use="required" />
+ <xsd:attribute name="type" type="tns:MorphType" use="required" />
+ </xsd:complexType>
+
+ </xsd:element>
+
+
+ <xsd:element name="morphVertex">
+ <xsd:annotation>
+ <xsd:documentation>
+ Morphing vertex information.
+ </xsd:documentation>
+ </xsd:annotation>
+
+ <xsd:complexType>
+ <xsd:attribute name="vtxIdRef" type="xsd:NCName" use="required" />
+ <xsd:attribute name="xOff" type="xsd:float" use="required" />
+ <xsd:attribute name="yOff" type="xsd:float" use="required" />
+ <xsd:attribute name="zOff" type="xsd:float" use="required" />
+ </xsd:complexType>
+
+ </xsd:element>
+
+
+ <xsd:element name="rigidList">
+ <xsd:annotation>
+ <xsd:documentation>
+ list of Rigid-body definition.
+ </xsd:documentation>
+ </xsd:annotation>
+
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element
+ ref="tns:rigid"
+ minOccurs="0" maxOccurs="unbounded" />
+ </xsd:sequence>
+ </xsd:complexType>
+
+ <xsd:key name="Rigid-Id">
+ <xsd:selector xpath="./tns:rigid" />
+ <xsd:field xpath="@rigidId" />
+ </xsd:key>
+<!--
+ <xsd:unique name="RigidName">
+ <xsd:selector xpath="./tns:rigid" />
+ <xsd:field xpath="@name" />
+ </xsd:unique>
+-->
+ </xsd:element>
+
+
+ <xsd:simpleType name="RigidBehaviorType">
+ <xsd:annotation>
+ <xsd:documentation>
+ Rigid bahavior types.
+ </xsd:documentation>
+ </xsd:annotation>
+
+ <xsd:restriction base="xsd:string">
+ <xsd:enumeration value="FOLLOWBONE" /> <!-- ボーン追従 -->
+ <xsd:enumeration value="ONLYDYNAMICS" /> <!-- 物理 -->
+ <xsd:enumeration value="BONEDDYNAMICS" /> <!-- 物理+ボーン -->
+ </xsd:restriction>
+
+ </xsd:simpleType>
+
+
+ <xsd:element name="rigid">
+ <xsd:annotation>
+ <xsd:documentation>
+ Rigid-body definition.
+ </xsd:documentation>
+ </xsd:annotation>
+
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element
+ ref="tns:i18nName"
+ minOccurs="0" maxOccurs="unbounded" />
+ <xsd:element ref="tns:linkedBone" />
+
+ <xsd:choice>
+ <xsd:element ref="tns:rigidShapeSphere" />
+ <xsd:element ref="tns:rigidShapeBox" />
+ <xsd:element ref="tns:rigidShapeCapsule" />
+ </xsd:choice>
+
+ <xsd:element ref="tns:position" />
+ <xsd:element ref="tns:radRotation" />
+ <xsd:element ref="tns:dynamics" />
+ <xsd:element
+ ref="tns:throughRigidGroup"
+ minOccurs="0" maxOccurs="unbounded" />
+ </xsd:sequence>
+
+ <xsd:attribute name="name" type="xsd:string" use="required" />
+ <xsd:attribute name="rigidId" type="xsd:NCName" use="required" />
+ <xsd:attribute
+ name="behavior"
+ type="tns:RigidBehaviorType"
+ use="required" />
+ </xsd:complexType>
+
+ <xsd:unique name="ThroughRigidGroup">
+ <xsd:selector xpath="./tns:throughRigidGroup" />
+ <xsd:field xpath="@rigidGroupIdRef" />
+ </xsd:unique>
+
+ </xsd:element>
+
+
+ <xsd:element name="linkedBone">
+ <xsd:annotation>
+ <xsd:documentation>
+ Referenced Bone from Rigid-body.
+ </xsd:documentation>
+ </xsd:annotation>
+
+ <xsd:complexType>
+ <xsd:attribute
+ name="boneIdRef"
+ type="xsd:NCName"
+ use="required" />
+ </xsd:complexType>
+
+ </xsd:element>
+
+
+ <xsd:element name="rigidShapeSphere">
+ <xsd:annotation>
+ <xsd:documentation>
+ Sphere shape of Rigid-body.
+ </xsd:documentation>
+ </xsd:annotation>
+
+ <xsd:complexType>
+ <xsd:attribute name="radius" type="xsd:float" use="required" />
+ </xsd:complexType>
+
+ </xsd:element>
+
+
+ <xsd:element name="rigidShapeBox">
+ <xsd:annotation>
+ <xsd:documentation>
+ Box shape of Rigid-body.
+ </xsd:documentation>
+ </xsd:annotation>
+
+ <xsd:complexType>
+ <xsd:attribute name="width" type="xsd:float" use="required" />
+ <xsd:attribute name="height" type="xsd:float" use="required" />
+ <xsd:attribute name="depth" type="xsd:float" use="required" />
+ </xsd:complexType>
+
+ </xsd:element>
+
+
+ <xsd:element name="rigidShapeCapsule">
+ <xsd:annotation>
+ <xsd:documentation>
+ Capsule shape of Rigid-body.
+ </xsd:documentation>
+ </xsd:annotation>
+
+ <xsd:complexType>
+ <xsd:attribute name="height" type="xsd:float" use="required" />
+ <xsd:attribute name="radius" type="xsd:float" use="required" />
+ </xsd:complexType>
+
+ </xsd:element>
+
+
+ <xsd:element name="radRotation">
+ <xsd:annotation>
+ <xsd:documentation>
+ Rotaion information by radian.
+ </xsd:documentation>
+ </xsd:annotation>
+
+ <xsd:complexType>
+ <xsd:attribute name="xRad" type="xsd:float" use="required" />
+ <xsd:attribute name="yRad" type="xsd:float" use="required" />
+ <xsd:attribute name="zRad" type="xsd:float" use="required" />
+ </xsd:complexType>
+
+ </xsd:element>
+
+
+ <xsd:element name="dynamics">
+ <xsd:annotation>
+ <xsd:documentation>
+ Dynamics parameters.
+ </xsd:documentation>
+ </xsd:annotation>
+
+ <xsd:complexType>
+ <xsd:attribute
+ name="mass"
+ type="xsd:float"
+ use="required" />
+ <xsd:attribute
+ name="dampingPosition"
+ type="xsd:float"
+ use="required" />
+ <xsd:attribute
+ name="dampingRotation"
+ type="xsd:float"
+ use="required" />
+ <xsd:attribute
+ name="restitution"
+ type="xsd:float"
+ use="required" />
+ <xsd:attribute
+ name="friction"
+ type="xsd:float"
+ use="required" />
+ </xsd:complexType>
+
+ </xsd:element>
+
+
+ <xsd:element name="throughRigidGroup">
+ <xsd:annotation>
+ <xsd:documentation>
+ Reference for non-collision rigid-group.
+ </xsd:documentation>
+ </xsd:annotation>
+
+ <xsd:complexType>
+ <xsd:attribute
+ name="rigidGroupIdRef"
+ type="xsd:NCName"
+ use="required" />
+ </xsd:complexType>
+
+ </xsd:element>
+
+
+ <xsd:element name="rigidGroupList">
+ <xsd:annotation>
+ <xsd:documentation>
+ List of Rigid-body group.
+ </xsd:documentation>
+ </xsd:annotation>
+
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element
+ ref="tns:rigidGroup"
+ minOccurs="0" maxOccurs="unbounded" />
+ </xsd:sequence>
+ </xsd:complexType>
+
+ <xsd:key name="RigidGroup-Id">
+ <xsd:selector xpath="./tns:rigidGroup" />
+ <xsd:field xpath="@rigidGroupId" />
+ </xsd:key>
+
+ </xsd:element>
+
+
+ <xsd:element name="rigidGroup">
+ <xsd:annotation>
+ <xsd:documentation>
+ Rigid-body group.
+ </xsd:documentation>
+ </xsd:annotation>
+
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element
+ ref="tns:rigidGroupMember"
+ minOccurs="0" maxOccurs="unbounded" />
+ </xsd:sequence>
+
+ <xsd:attribute
+ name="rigidGroupId"
+ type="xsd:NCName"
+ use="required" />
+ </xsd:complexType>
+
+ <xsd:unique name="RigidGroupMember">
+ <xsd:selector xpath="./tns:rigidGroupMember" />
+ <xsd:field xpath="@rigidIdRef" />
+ </xsd:unique>
+
+ </xsd:element>
+
+
+ <xsd:element name="rigidGroupMember">
+ <xsd:annotation>
+ <xsd:documentation>
+ Member of Rigid-body group.
+ </xsd:documentation>
+ </xsd:annotation>
+
+ <xsd:complexType>
+ <xsd:attribute
+ name="rigidIdRef"
+ type="xsd:NCName"
+ use="required" />
+ </xsd:complexType>
+
+ </xsd:element>
+
+
+ <xsd:element name="jointList">
+ <xsd:annotation>
+ <xsd:documentation>
+ List of joint definition.
+ </xsd:documentation>
+ </xsd:annotation>
+
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element
+ ref="tns:joint"
+ minOccurs="0" maxOccurs="unbounded" />
+ </xsd:sequence>
+ </xsd:complexType>
+
+ </xsd:element>
+
+
+ <xsd:element name="joint">
+ <xsd:annotation>
+ <xsd:documentation>
+ Joint definition.
+ </xsd:documentation>
+ </xsd:annotation>
+
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element
+ ref="tns:i18nName"
+ minOccurs="0" maxOccurs="unbounded" />
+ <xsd:element ref="tns:jointedRigidPair" />
+ <xsd:element ref="tns:position" />
+ <xsd:element ref="tns:limitPosition" />
+ <xsd:element ref="tns:radRotation" />
+ <xsd:element ref="tns:limitRotation" />
+ <xsd:element ref="tns:elasticPosition" />
+ <xsd:element ref="tns:elasticRotation" />
+ </xsd:sequence>
+
+ <xsd:attribute
+ name="name"
+ type="xsd:string"
+ use="required" />
+ </xsd:complexType>
+
+<!--
+ <xsd:unique name="JointName">
+ <xsd:selector xpath="./tns:joint" />
+ <xsd:field xpath="@name" />
+ </xsd:unique>
+-->
+ </xsd:element>
+
+
+ <xsd:element name="jointedRigidPair">
+ <xsd:annotation>
+ <xsd:documentation>
+ Jointed-bones information.
+ </xsd:documentation>
+ </xsd:annotation>
+
+ <xsd:complexType>
+ <xsd:attribute
+ name="rigidIdRef1"
+ type="xsd:NCName"
+ use="required" />
+ <xsd:attribute
+ name="rigidIdRef2"
+ type="xsd:NCName"
+ use="required" />
+ </xsd:complexType>
+
+ </xsd:element>
+
+
+ <xsd:element name="limitPosition">
+ <xsd:annotation>
+ <xsd:documentation>
+ Limit of Position.
+ </xsd:documentation>
+ </xsd:annotation>
+
+ <xsd:complexType>
+ <xsd:attribute name="xFrom" type="xsd:float" use="required" />
+ <xsd:attribute name="xTo" type="xsd:float" use="required" />
+ <xsd:attribute name="yFrom" type="xsd:float" use="required" />
+ <xsd:attribute name="yTo" type="xsd:float" use="required" />
+ <xsd:attribute name="zFrom" type="xsd:float" use="required" />
+ <xsd:attribute name="zTo" type="xsd:float" use="required" />
+ </xsd:complexType>
+
+ </xsd:element>
+
+
+ <xsd:element name="limitRotation">
+ <xsd:annotation>
+ <xsd:documentation>
+ Limit of Rotation.
+ </xsd:documentation>
+ </xsd:annotation>
+
+ <xsd:complexType>
+ <xsd:attribute name="xFrom" type="xsd:float" use="required" />
+ <xsd:attribute name="xTo" type="xsd:float" use="required" />
+ <xsd:attribute name="yFrom" type="xsd:float" use="required" />
+ <xsd:attribute name="yTo" type="xsd:float" use="required" />
+ <xsd:attribute name="zFrom" type="xsd:float" use="required" />
+ <xsd:attribute name="zTo" type="xsd:float" use="required" />
+ </xsd:complexType>
+
+ </xsd:element>
+
+
+ <xsd:element name="elasticPosition">
+ <xsd:annotation>
+ <xsd:documentation>
+ Elastic position of joint.
+ </xsd:documentation>
+ </xsd:annotation>
+
+ <xsd:complexType>
+ <xsd:attribute name="x" type="xsd:float" use="required" />
+ <xsd:attribute name="y" type="xsd:float" use="required" />
+ <xsd:attribute name="z" type="xsd:float" use="required" />
+ </xsd:complexType>
+
+ </xsd:element>
+
+
+ <xsd:element name="elasticRotation">
+ <xsd:annotation>
+ <xsd:documentation>
+ Elastic rotation of joint by degree.
+ </xsd:documentation>
+ </xsd:annotation>
+
+ <xsd:complexType>
+ <xsd:attribute name="xDeg" type="xsd:float" use="required" />
+ <xsd:attribute name="yDeg" type="xsd:float" use="required" />
+ <xsd:attribute name="zDeg" type="xsd:float" use="required" />
+ </xsd:complexType>
+
+ </xsd:element>
+
+
+ <xsd:element name="surfaceGroupList">
+ <xsd:annotation>
+ <xsd:documentation>
+ List of surface group.
+ </xsd:documentation>
+ </xsd:annotation>
+
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element
+ ref="tns:surfaceGroup"
+ minOccurs="0" maxOccurs="unbounded" />
+ </xsd:sequence>
+ </xsd:complexType>
+
+ <xsd:key name="SurfaceGroup-Id">
+ <xsd:selector xpath="./tns:surfaceGroup" />
+ <xsd:field xpath="@surfaceGroupId" />
+ </xsd:key>
+
+ </xsd:element>
+
+
+ <xsd:element name="surfaceGroup">
+ <xsd:annotation>
+ <xsd:documentation>
+ Surface group.
+ </xsd:documentation>
+ </xsd:annotation>
+
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element ref="tns:surface" minOccurs="0" maxOccurs="unbounded" />
+ </xsd:sequence>
+
+ <xsd:attribute
+ name="surfaceGroupId"
+ type="xsd:NCName"
+ use="required" />
+ </xsd:complexType>
+
+ </xsd:element>
+
+
+ <xsd:element name="surface">
+ <xsd:annotation>
+ <xsd:documentation>
+ Each surface with Triangle.
+ </xsd:documentation>
+ </xsd:annotation>
+
+ <xsd:complexType>
+ <xsd:attribute
+ name="vtxIdRef1"
+ type="xsd:NCName"
+ use="required" />
+ <xsd:attribute
+ name="vtxIdRef2"
+ type="xsd:NCName"
+ use="required" />
+ <xsd:attribute
+ name="vtxIdRef3"
+ type="xsd:NCName"
+ use="required" />
+ </xsd:complexType>
+
+ </xsd:element>
+
+
+ <xsd:element name="vertexList">
+ <xsd:annotation>
+ <xsd:documentation>
+ List of vertex.
+ </xsd:documentation>
+ </xsd:annotation>
+
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element ref="tns:vertex" minOccurs="0" maxOccurs="unbounded" />
+ </xsd:sequence>
+ </xsd:complexType>
+
+ <xsd:key name="Vertex-Id">
+ <xsd:selector xpath="./tns:vertex" />
+ <xsd:field xpath="@vtxId" />
+ </xsd:key>
+
+ </xsd:element>
+
+
+ <xsd:element name="vertex">
+ <xsd:annotation>
+ <xsd:documentation>
+ Vertex definition.
+ </xsd:documentation>
+ </xsd:annotation>
+
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element ref="tns:position" />
+ <xsd:element ref="tns:normal" />
+ <xsd:element ref="tns:uvMap" />
+ <xsd:element ref="tns:skinning" />
+ </xsd:sequence>
+
+ <xsd:attribute
+ name="vtxId"
+ type="xsd:NCName"
+ use="required" />
+ <xsd:attribute
+ name="showEdge"
+ type="xsd:boolean"
+ use="required" />
+ </xsd:complexType>
+
+ </xsd:element>
+
+
+ <xsd:element name="position">
+ <xsd:annotation>
+ <xsd:documentation>
+ Position definition.
+ </xsd:documentation>
+ </xsd:annotation>
+
+ <xsd:complexType>
+ <xsd:attribute name="x" type="xsd:float" use="required" />
+ <xsd:attribute name="y" type="xsd:float" use="required" />
+ <xsd:attribute name="z" type="xsd:float" use="required" />
+ </xsd:complexType>
+
+ </xsd:element>
+
+
+ <xsd:element name="normal">
+ <xsd:annotation>
+ <xsd:documentation>
+ Normal vector definition.
+ </xsd:documentation>
+ </xsd:annotation>
+
+ <xsd:complexType>
+ <xsd:attribute name="x" type="xsd:float" use="required" />
+ <xsd:attribute name="y" type="xsd:float" use="required" />
+ <xsd:attribute name="z" type="xsd:float" use="required" />
+ </xsd:complexType>
+
+ </xsd:element>
+
+
+ <xsd:element name="uvMap">
+ <xsd:annotation>
+ <xsd:documentation>
+ UV-mapping information.
+ </xsd:documentation>
+ </xsd:annotation>
+
+ <xsd:complexType>
+ <xsd:attribute name="u" type="xsd:float" use="required" />
+ <xsd:attribute name="v" type="xsd:float" use="required" />
+ </xsd:complexType>
+
+ </xsd:element>
+
+
+ <xsd:element name="skinning">
+ <xsd:annotation>
+ <xsd:documentation>
+ Skinning definition from vertex to bone.
+ </xsd:documentation>
+ </xsd:annotation>
+
+ <xsd:complexType>
+ <xsd:attribute name="boneIdRef1" type="xsd:NCName" use="required" />
+ <xsd:attribute name="boneIdRef2" type="xsd:NCName" use="required" />
+ <xsd:attribute
+ name="weightBalance"
+ type="xsd:nonNegativeInteger"
+ use="required" />
+ </xsd:complexType>
+
+ </xsd:element>
+
+
+</xsd:schema>
+
+
+<!-- EOF -->
--- /dev/null
+<?xml version='1.0'?>
+<?xml-stylesheet href="../2008/09/xsd.xsl" type="text/xsl"?>
+<xs:schema targetNamespace="http://www.w3.org/XML/1998/namespace"
+ xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns ="http://www.w3.org/1999/xhtml"
+ xml:lang="en">
+
+ <xs:annotation>
+ <xs:documentation>
+ <div>
+ <h1>About the XML namespace</h1>
+
+ <div class="bodytext">
+ <p>
+ This schema document describes the XML namespace, in a form
+ suitable for import by other schema documents.
+ </p>
+ <p>
+ See <a href="http://www.w3.org/XML/1998/namespace.html">
+ http://www.w3.org/XML/1998/namespace.html</a> and
+ <a href="http://www.w3.org/TR/REC-xml">
+ http://www.w3.org/TR/REC-xml</a> for information
+ about this namespace.
+ </p>
+ <p>
+ Note that local names in this namespace are intended to be
+ defined only by the World Wide Web Consortium or its subgroups.
+ The names currently defined in this namespace are listed below.
+ They should not be used with conflicting semantics by any Working
+ Group, specification, or document instance.
+ </p>
+ <p>
+ See further below in this document for more information about <a
+ href="#usage">how to refer to this schema document from your own
+ XSD schema documents</a> and about <a href="#nsversioning">the
+ namespace-versioning policy governing this schema document</a>.
+ </p>
+ </div>
+ </div>
+ </xs:documentation>
+ </xs:annotation>
+
+ <xs:attribute name="lang">
+ <xs:annotation>
+ <xs:documentation>
+ <div>
+
+ <h3>lang (as an attribute name)</h3>
+ <p>
+ denotes an attribute whose value
+ is a language code for the natural language of the content of
+ any element; its value is inherited. This name is reserved
+ by virtue of its definition in the XML specification.</p>
+
+ </div>
+ <div>
+ <h4>Notes</h4>
+ <p>
+ Attempting to install the relevant ISO 2- and 3-letter
+ codes as the enumerated possible values is probably never
+ going to be a realistic possibility.
+ </p>
+ <p>
+ See BCP 47 at <a href="http://www.rfc-editor.org/rfc/bcp/bcp47.txt">
+ http://www.rfc-editor.org/rfc/bcp/bcp47.txt</a>
+ and the IANA language subtag registry at
+ <a href="http://www.iana.org/assignments/language-subtag-registry">
+ http://www.iana.org/assignments/language-subtag-registry</a>
+ for further information.
+ </p>
+ <p>
+ The union allows for the 'un-declaration' of xml:lang with
+ the empty string.
+ </p>
+ </div>
+ </xs:documentation>
+ </xs:annotation>
+ <xs:simpleType>
+ <xs:union memberTypes="xs:language">
+ <xs:simpleType>
+ <xs:restriction base="xs:string">
+ <xs:enumeration value=""/>
+ </xs:restriction>
+ </xs:simpleType>
+ </xs:union>
+ </xs:simpleType>
+ </xs:attribute>
+
+ <xs:attribute name="space">
+ <xs:annotation>
+ <xs:documentation>
+ <div>
+
+ <h3>space (as an attribute name)</h3>
+ <p>
+ denotes an attribute whose
+ value is a keyword indicating what whitespace processing
+ discipline is intended for the content of the element; its
+ value is inherited. This name is reserved by virtue of its
+ definition in the XML specification.</p>
+
+ </div>
+ </xs:documentation>
+ </xs:annotation>
+ <xs:simpleType>
+ <xs:restriction base="xs:NCName">
+ <xs:enumeration value="default"/>
+ <xs:enumeration value="preserve"/>
+ </xs:restriction>
+ </xs:simpleType>
+ </xs:attribute>
+
+ <xs:attribute name="base" type="xs:anyURI"> <xs:annotation>
+ <xs:documentation>
+ <div>
+
+ <h3>base (as an attribute name)</h3>
+ <p>
+ denotes an attribute whose value
+ provides a URI to be used as the base for interpreting any
+ relative URIs in the scope of the element on which it
+ appears; its value is inherited. This name is reserved
+ by virtue of its definition in the XML Base specification.</p>
+
+ <p>
+ See <a
+ href="http://www.w3.org/TR/xmlbase/">http://www.w3.org/TR/xmlbase/</a>
+ for information about this attribute.
+ </p>
+ </div>
+ </xs:documentation>
+ </xs:annotation>
+ </xs:attribute>
+
+ <xs:attribute name="id" type="xs:ID">
+ <xs:annotation>
+ <xs:documentation>
+ <div>
+
+ <h3>id (as an attribute name)</h3>
+ <p>
+ denotes an attribute whose value
+ should be interpreted as if declared to be of type ID.
+ This name is reserved by virtue of its definition in the
+ xml:id specification.</p>
+
+ <p>
+ See <a
+ href="http://www.w3.org/TR/xml-id/">http://www.w3.org/TR/xml-id/</a>
+ for information about this attribute.
+ </p>
+ </div>
+ </xs:documentation>
+ </xs:annotation>
+ </xs:attribute>
+
+ <xs:attributeGroup name="specialAttrs">
+ <xs:attribute ref="xml:base"/>
+ <xs:attribute ref="xml:lang"/>
+ <xs:attribute ref="xml:space"/>
+ <xs:attribute ref="xml:id"/>
+ </xs:attributeGroup>
+
+ <xs:annotation>
+ <xs:documentation>
+ <div>
+
+ <h3>Father (in any context at all)</h3>
+
+ <div class="bodytext">
+ <p>
+ denotes Jon Bosak, the chair of
+ the original XML Working Group. This name is reserved by
+ the following decision of the W3C XML Plenary and
+ XML Coordination groups:
+ </p>
+ <blockquote>
+ <p>
+ In appreciation for his vision, leadership and
+ dedication the W3C XML Plenary on this 10th day of
+ February, 2000, reserves for Jon Bosak in perpetuity
+ the XML name "xml:Father".
+ </p>
+ </blockquote>
+ </div>
+ </div>
+ </xs:documentation>
+ </xs:annotation>
+
+ <xs:annotation>
+ <xs:documentation>
+ <div xml:id="usage" id="usage">
+ <h2><a name="usage">About this schema document</a></h2>
+
+ <div class="bodytext">
+ <p>
+ This schema defines attributes and an attribute group suitable
+ for use by schemas wishing to allow <code>xml:base</code>,
+ <code>xml:lang</code>, <code>xml:space</code> or
+ <code>xml:id</code> attributes on elements they define.
+ </p>
+ <p>
+ To enable this, such a schema must import this schema for
+ the XML namespace, e.g. as follows:
+ </p>
+ <pre>
+ <schema . . .>
+ . . .
+ <import namespace="http://www.w3.org/XML/1998/namespace"
+ schemaLocation="http://www.w3.org/2001/xml.xsd"/>
+ </pre>
+ <p>
+ or
+ </p>
+ <pre>
+ <import namespace="http://www.w3.org/XML/1998/namespace"
+ schemaLocation="http://www.w3.org/2009/01/xml.xsd"/>
+ </pre>
+ <p>
+ Subsequently, qualified reference to any of the attributes or the
+ group defined below will have the desired effect, e.g.
+ </p>
+ <pre>
+ <type . . .>
+ . . .
+ <attributeGroup ref="xml:specialAttrs"/>
+ </pre>
+ <p>
+ will define a type which will schema-validate an instance element
+ with any of those attributes.
+ </p>
+ </div>
+ </div>
+ </xs:documentation>
+ </xs:annotation>
+
+ <xs:annotation>
+ <xs:documentation>
+ <div id="nsversioning" xml:id="nsversioning">
+ <h2><a name="nsversioning">Versioning policy for this schema document</a></h2>
+ <div class="bodytext">
+ <p>
+ In keeping with the XML Schema WG's standard versioning
+ policy, this schema document will persist at
+ <a href="http://www.w3.org/2009/01/xml.xsd">
+ http://www.w3.org/2009/01/xml.xsd</a>.
+ </p>
+ <p>
+ At the date of issue it can also be found at
+ <a href="http://www.w3.org/2001/xml.xsd">
+ http://www.w3.org/2001/xml.xsd</a>.
+ </p>
+ <p>
+ The schema document at that URI may however change in the future,
+ in order to remain compatible with the latest version of XML
+ Schema itself, or with the XML namespace itself. In other words,
+ if the XML Schema or XML namespaces change, the version of this
+ document at <a href="http://www.w3.org/2001/xml.xsd">
+ http://www.w3.org/2001/xml.xsd
+ </a>
+ will change accordingly; the version at
+ <a href="http://www.w3.org/2009/01/xml.xsd">
+ http://www.w3.org/2009/01/xml.xsd
+ </a>
+ will not change.
+ </p>
+ <p>
+ Previous dated (and unchanging) versions of this schema
+ document are at:
+ </p>
+ <ul>
+ <li><a href="http://www.w3.org/2009/01/xml.xsd">
+ http://www.w3.org/2009/01/xml.xsd</a></li>
+ <li><a href="http://www.w3.org/2007/08/xml.xsd">
+ http://www.w3.org/2007/08/xml.xsd</a></li>
+ <li><a href="http://www.w3.org/2004/10/xml.xsd">
+ http://www.w3.org/2004/10/xml.xsd</a></li>
+ <li><a href="http://www.w3.org/2001/03/xml.xsd">
+ http://www.w3.org/2001/03/xml.xsd</a></li>
+ </ul>
+ </div>
+ </div>
+ </xs:documentation>
+ </xs:annotation>
+
+</xs:schema>
--- /dev/null
+/*\r
+ *\r
+ */\r
+\r
+package jp.sourceforge.mikutoga.pmd;\r
+\r
+import java.util.Locale;\r
+import org.junit.After;\r
+import org.junit.AfterClass;\r
+import org.junit.Before;\r
+import org.junit.BeforeClass;\r
+import org.junit.Test;\r
+import static org.junit.Assert.*;\r
+\r
+/**\r
+ * \r
+ */\r
+public class MorphTypeTest {\r
+\r
+ public MorphTypeTest() {\r
+ }\r
+\r
+ @BeforeClass\r
+ public static void setUpClass() throws Exception{\r
+ }\r
+\r
+ @AfterClass\r
+ public static void tearDownClass() throws Exception{\r
+ }\r
+\r
+ @Before\r
+ public void setUp() {\r
+ }\r
+\r
+ @After\r
+ public void tearDown() {\r
+ }\r
+\r
+ /**\r
+ * Test of values method, of class MorphType.\r
+ */\r
+ @Test\r
+ public void testValues(){\r
+ System.out.println("values");\r
+\r
+ MorphType[] array = MorphType.values();\r
+\r
+ assertEquals(5, array.length);\r
+\r
+ assertEquals(MorphType.BASE, array[0]);\r
+ assertEquals(MorphType.EYEBROW, array[1]);\r
+ assertEquals(MorphType.EYE, array[2]);\r
+ assertEquals(MorphType.LIP, array[3]);\r
+ assertEquals(MorphType.EXTRA, array[4]);\r
+\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * Test of decode method, of class MorphType.\r
+ */\r
+ @Test\r
+ public void testDecode(){\r
+ System.out.println("decode");\r
+\r
+ assertEquals(MorphType.BASE, MorphType.decode((byte)0x00));\r
+ assertEquals(MorphType.EYEBROW, MorphType.decode((byte)0x01));\r
+ assertEquals(MorphType.EYE, MorphType.decode((byte)0x02));\r
+ assertEquals(MorphType.LIP, MorphType.decode((byte)0x03));\r
+ assertEquals(MorphType.EXTRA, MorphType.decode((byte)0x04));\r
+ assertNull(MorphType.decode((byte)0x05));\r
+\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * Test of encode method, of class MorphType.\r
+ */\r
+ @Test\r
+ public void testEncode(){\r
+ System.out.println("encode");\r
+\r
+ assertEquals(0x00, MorphType.BASE.encode());\r
+ assertEquals(0x01, MorphType.EYEBROW.encode());\r
+ assertEquals(0x02, MorphType.EYE.encode());\r
+ assertEquals(0x03, MorphType.LIP.encode());\r
+ assertEquals(0x04, MorphType.EXTRA.encode());\r
+\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * Test of getGuiName method, of class MorphType.\r
+ */\r
+ @Test\r
+ public void testGetGuiName_0args(){\r
+ System.out.println("getGuiName");\r
+\r
+ Locale locale = Locale.getDefault();\r
+\r
+ for(MorphType type : MorphType.values()){\r
+ assertEquals(type.getGuiName(locale), type.getGuiName());\r
+ }\r
+\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * Test of getGuiName method, of class MorphType.\r
+ */\r
+ @Test\r
+ public void testGetGuiName_Locale(){\r
+ System.out.println("getGuiName");\r
+\r
+ Locale locale = Locale.JAPANESE;\r
+\r
+ assertEquals("base", MorphType.BASE.getGuiName(locale));\r
+ assertEquals("まゆ", MorphType.EYEBROW.getGuiName(locale));\r
+ assertEquals("目", MorphType.EYE.getGuiName(locale));\r
+ assertEquals("リップ", MorphType.LIP.getGuiName(locale));\r
+ assertEquals("その他", MorphType.EXTRA.getGuiName(locale));\r
+ \r
+ return;\r
+ }\r
+\r
+}\r