4 * License : The MIT License
5 * Copyright(c) 2011 MikuToga Partners
8 package jp.sfjp.mikutoga.vmd.model;
10 import java.text.MessageFormat;
11 import java.util.Collections;
12 import java.util.LinkedHashMap;
13 import java.util.LinkedList;
14 import java.util.List;
16 import jp.sfjp.mikutoga.vmd.FrameNumbered;
17 import jp.sfjp.mikutoga.vmd.VmdUniq;
22 public class VmdMotion {
24 private static final String MSG_TXT =
26 + "bone#{1} morph#{2} camera#{3} luminous#{4} shadow#{5} flag#{6}";
29 private String modelName = VmdUniq.MODELNAME_STAGEACT;
31 private final Map<String, List<BoneMotion>> bonePartMap;
32 private final Map<String, List<MorphMotion>> morphPartMap;
34 private final List<CameraMotion> cameraMotionList;
35 private final List<LuminousMotion> luminousMotionList;
36 private final List<ShadowMotion> shadowMotionList;
37 private final List<NumberedVmdFlag> flagList;
46 this.bonePartMap = new LinkedHashMap<String, List<BoneMotion>>();
47 this.morphPartMap = new LinkedHashMap<String, List<MorphMotion>>();
49 this.cameraMotionList = new LinkedList<CameraMotion>();
50 this.luminousMotionList = new LinkedList<LuminousMotion>();
51 this.shadowMotionList = new LinkedList<ShadowMotion>();
52 this.flagList = new LinkedList<NumberedVmdFlag>();
62 public String getModelName(){
63 return this.modelName;
68 * <p>このモーションがモデルモーションかステージ演出情報かは、
70 * @param modelName モデル名
71 * @throws NullPointerException 引数がnull
72 * @see jp.sfjp.mikutoga.vmd.VmdUniq#MODELNAME_STAGEACT
74 public void setModelName(String modelName) throws NullPointerException{
75 if(modelName == null) throw new NullPointerException();
76 this.modelName = modelName;
82 * <p>判別は特殊なモデル名を持つか否かで決定される。
83 * @return モデルモーションならtrue
84 * @see jp.sfjp.mikutoga.vmd.VmdUniq#MODELNAME_STAGEACT
86 public boolean isModelMotion(){
87 if(VmdUniq.isStageActName(this.modelName)){
95 * フラグモーションが存在するか否か判定する。
97 * MMD Ver7.40以降のVMDフォーマットでなければ記録できない。
100 public boolean hasFlagMotion(){
101 if(this.flagList.isEmpty()) return false;
106 * 順序保証されたボーンモーションマップを返す。
107 * @return ボーンモーションマップ
108 * @see java.util.LinkedHashMap
110 public Map<String, List<BoneMotion>> getBonePartMap(){
111 return this.bonePartMap;
115 * 順序保証されたモーフモーションマップを返す。
116 * @return モーフモーションマップ
117 * @see java.util.LinkedHashMap
119 public Map<String, List<MorphMotion>> getMorphPartMap(){
120 return this.morphPartMap;
125 * @return カメラモーションのリスト
127 public List<CameraMotion> getCameraMotionList(){
128 return this.cameraMotionList;
133 * @return 照明モーションのリスト
135 public List<LuminousMotion> getLuminousMotionList(){
136 return this.luminousMotionList;
141 * @return シャドウモーションのリスト
143 public List<ShadowMotion> getShadowMotionList(){
144 return this.shadowMotionList;
148 * 各種フレーム番号付きフラグのリストを返す。
149 * @return フレーム番号付きフラグのリスト
151 public List<NumberedVmdFlag> getNumberedFlagList(){
152 return this.flagList;
158 * @param motion ボーンモーション
159 * @see java.util.LinkedHashMap
161 public void addBoneMotion(BoneMotion motion){
162 String name = motion.getBoneName();
164 List<BoneMotion> list = this.bonePartMap.get(name);
166 list = new LinkedList<BoneMotion>();
167 this.bonePartMap.put(name, list);
178 * @param motion モーフモーション
179 * @see java.util.LinkedHashMap
181 public void addMorphMotion(MorphMotion motion){
182 String name = motion.getMorphName();
184 List<MorphMotion> list = this.morphPartMap.get(name);
186 list = new LinkedList<MorphMotion>();
187 this.morphPartMap.put(name, list);
196 * 各データをフレーム番号順に昇順ソートする。
198 public void frameSort(){
199 for(List<BoneMotion> list : this.bonePartMap.values()){
200 Collections.sort(list, FrameNumbered.COMPARATOR);
203 for(List<MorphMotion> list : this.morphPartMap.values()){
204 Collections.sort(list, FrameNumbered.COMPARATOR);
207 Collections.sort(this.cameraMotionList, FrameNumbered.COMPARATOR);
208 Collections.sort(this.luminousMotionList, FrameNumbered.COMPARATOR);
209 Collections.sort(this.shadowMotionList, FrameNumbered.COMPARATOR);
210 Collections.sort(this.flagList, FrameNumbered.COMPARATOR);
217 * @return {@inheritDoc}
220 public String toString(){
222 for(List<BoneMotion> motionList : this.bonePartMap.values()){
223 boneNo += motionList.size();
227 for(List<MorphMotion> motionList : this.morphPartMap.values()){
228 morphNo += motionList.size();
231 int cameraNo = this.cameraMotionList .size();
232 int luminousNo = this.luminousMotionList.size();
233 int shadowNo = this.shadowMotionList .size();
234 int flagNo = this.flagList .size();
237 msg = MessageFormat.format(MSG_TXT,
239 boneNo, morphNo, cameraNo, luminousNo, shadowNo, flagNo );