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 * @see java.util.LinkedHashMap
99 public Map<String, List<BoneMotion>> getBonePartMap(){
100 return this.bonePartMap;
104 * 順序保証されたモーフモーションマップを返す。
105 * @return モーフモーションマップ
106 * @see java.util.LinkedHashMap
108 public Map<String, List<MorphMotion>> getMorphPartMap(){
109 return this.morphPartMap;
114 * @return カメラモーションのリスト
116 public List<CameraMotion> getCameraMotionList(){
117 return this.cameraMotionList;
122 * @return 照明モーションのリスト
124 public List<LuminousMotion> getLuminousMotionList(){
125 return this.luminousMotionList;
130 * @return シャドウモーションのリスト
132 public List<ShadowMotion> getShadowMotionList(){
133 return this.shadowMotionList;
137 * 各種フレーム番号付きフラグのリストを返す。
138 * @return フレーム番号付きフラグのリスト
140 public List<NumberedVmdFlag> getNumberedFlagList(){
141 return this.flagList;
147 * @param motion ボーンモーション
148 * @see java.util.LinkedHashMap
150 public void addBoneMotion(BoneMotion motion){
151 String name = motion.getBoneName();
153 List<BoneMotion> list = this.bonePartMap.get(name);
155 list = new LinkedList<BoneMotion>();
156 this.bonePartMap.put(name, list);
167 * @param motion モーフモーション
168 * @see java.util.LinkedHashMap
170 public void addMorphMotion(MorphMotion motion){
171 String name = motion.getMorphName();
173 List<MorphMotion> list = this.morphPartMap.get(name);
175 list = new LinkedList<MorphMotion>();
176 this.morphPartMap.put(name, list);
185 * 各データをフレーム番号順に昇順ソートする。
187 public void frameSort(){
188 for(List<BoneMotion> list : this.bonePartMap.values()){
189 Collections.sort(list, FrameNumbered.COMPARATOR);
192 for(List<MorphMotion> list : this.morphPartMap.values()){
193 Collections.sort(list, FrameNumbered.COMPARATOR);
196 Collections.sort(this.cameraMotionList, FrameNumbered.COMPARATOR);
197 Collections.sort(this.luminousMotionList, FrameNumbered.COMPARATOR);
198 Collections.sort(this.shadowMotionList, FrameNumbered.COMPARATOR);
199 Collections.sort(this.flagList, FrameNumbered.COMPARATOR);
206 * @return {@inheritDoc}
209 public String toString(){
211 for(List<BoneMotion> motionList : this.bonePartMap.values()){
212 boneNo += motionList.size();
216 for(List<MorphMotion> motionList : this.morphPartMap.values()){
217 morphNo += motionList.size();
220 int cameraNo = this.cameraMotionList .size();
221 int luminousNo = this.luminousMotionList.size();
222 int shadowNo = this.shadowMotionList .size();
223 int flagNo = this.flagList .size();
226 msg = MessageFormat.format(MSG_TXT,
228 boneNo, morphNo, cameraNo, luminousNo, shadowNo, flagNo );