OSDN Git Service

MMD Ver7.40 対応 新スキーマ開発開始
[mikutoga/Vmd2XML.git] / src / main / java / jp / sfjp / mikutoga / vmd / model / VmdMotion.java
1 /*
2  * motion & stage act
3  *
4  * License : The MIT License
5  * Copyright(c) 2011 MikuToga Partners
6  */
7
8 package jp.sfjp.mikutoga.vmd.model;
9
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;
15 import java.util.Map;
16 import jp.sfjp.mikutoga.vmd.FrameNumbered;
17 import jp.sfjp.mikutoga.vmd.VmdUniq;
18
19 /**
20  * モーション及び演出情報。
21  */
22 public class VmdMotion {
23
24     private static final String MSG_TXT =
25           "model name : {0}\n"
26         + "bone#{1} morph#{2} camera#{3} luminous#{4} shadow#{5} flag#{6}";
27
28
29     private String modelName = VmdUniq.MODELNAME_STAGEACT;
30
31     private final Map<String, List<BoneMotion>>  bonePartMap;
32     private final Map<String, List<MorphMotion>> morphPartMap;
33
34     private final List<CameraMotion>    cameraMotionList;
35     private final List<LuminousMotion>  luminousMotionList;
36     private final List<ShadowMotion>    shadowMotionList;
37     private final List<NumberedVmdFlag> flagList;
38
39
40     /**
41      * コンストラクタ。
42      */
43     public VmdMotion(){
44         super();
45
46         this.bonePartMap  = new LinkedHashMap<String, List<BoneMotion>>();
47         this.morphPartMap = new LinkedHashMap<String, List<MorphMotion>>();
48
49         this.cameraMotionList   = new LinkedList<CameraMotion>();
50         this.luminousMotionList = new LinkedList<LuminousMotion>();
51         this.shadowMotionList   = new LinkedList<ShadowMotion>();
52         this.flagList           = new LinkedList<NumberedVmdFlag>();
53
54         return;
55     }
56
57
58     /**
59      * モデル名を返す。
60      * @return モデル名
61      */
62     public String getModelName(){
63         return this.modelName;
64     }
65
66     /**
67      * モデル名を設定する。
68      * <p>このモーションがモデルモーションかステージ演出情報かは、
69      * このモデル名で判別される。
70      * @param modelName モデル名
71      * @throws NullPointerException 引数がnull
72      * @see jp.sfjp.mikutoga.vmd.VmdUniq#MODELNAME_STAGEACT
73      */
74     public void setModelName(String modelName) throws NullPointerException{
75         if(modelName == null) throw new NullPointerException();
76         this.modelName = modelName;
77         return;
78     }
79
80     /**
81      * モデルモーションか否か判別する。
82      * <p>判別は特殊なモデル名を持つか否かで決定される。
83      * @return モデルモーションならtrue
84      * @see jp.sfjp.mikutoga.vmd.VmdUniq#MODELNAME_STAGEACT
85      */
86     public boolean isModelMotion(){
87         if(VmdUniq.isStageActName(this.modelName)){
88             return false;
89         }
90
91         return true;
92     }
93
94     /**
95      * 順序保証されたボーンモーションマップを返す。
96      * @return ボーンモーションマップ
97      * @see java.util.LinkedHashMap
98      */
99     public Map<String, List<BoneMotion>> getBonePartMap(){
100         return this.bonePartMap;
101     }
102
103     /**
104      * 順序保証されたモーフモーションマップを返す。
105      * @return モーフモーションマップ
106      * @see java.util.LinkedHashMap
107      */
108     public Map<String, List<MorphMotion>> getMorphPartMap(){
109         return this.morphPartMap;
110     }
111
112     /**
113      * カメラモーションのリストを返す。
114      * @return カメラモーションのリスト
115      */
116     public List<CameraMotion> getCameraMotionList(){
117         return this.cameraMotionList;
118     }
119
120     /**
121      * 照明モーションのリストを返す。
122      * @return 照明モーションのリスト
123      */
124     public List<LuminousMotion> getLuminousMotionList(){
125         return this.luminousMotionList;
126     }
127
128     /**
129      * シャドウモーションのリストを返す。
130      * @return シャドウモーションのリスト
131      */
132     public List<ShadowMotion> getShadowMotionList(){
133         return this.shadowMotionList;
134     }
135
136     /**
137      * 各種フレーム番号付きフラグのリストを返す。
138      * @return フレーム番号付きフラグのリスト
139      */
140     public List<NumberedVmdFlag> getNumberedFlagList(){
141         return this.flagList;
142     }
143
144     /**
145      * ボーンモーションを追加する。
146      * 追加順は保持される。
147      * @param motion ボーンモーション
148      * @see java.util.LinkedHashMap
149      */
150     public void addBoneMotion(BoneMotion motion){
151         String name = motion.getBoneName();
152
153         List<BoneMotion> list = this.bonePartMap.get(name);
154         if(list == null){
155             list = new LinkedList<BoneMotion>();
156             this.bonePartMap.put(name, list);
157         }
158
159         list.add(motion);
160
161         return;
162     }
163
164     /**
165      * モーフモーションを追加する。
166      * 追加順は保持される。
167      * @param motion モーフモーション
168      * @see java.util.LinkedHashMap
169      */
170     public void addMorphMotion(MorphMotion motion){
171         String name = motion.getMorphName();
172
173         List<MorphMotion> list = this.morphPartMap.get(name);
174         if(list == null){
175             list = new LinkedList<MorphMotion>();
176             this.morphPartMap.put(name, list);
177         }
178
179         list.add(motion);
180
181         return;
182     }
183
184     /**
185      * 各データをフレーム番号順に昇順ソートする。
186      */
187     public void frameSort(){
188         for(List<BoneMotion> list : this.bonePartMap.values()){
189             Collections.sort(list, FrameNumbered.COMPARATOR);
190         }
191
192         for(List<MorphMotion> list : this.morphPartMap.values()){
193             Collections.sort(list, FrameNumbered.COMPARATOR);
194         }
195
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);
200
201         return;
202     }
203
204     /**
205      * {@inheritDoc}
206      * @return {@inheritDoc}
207      */
208     @Override
209     public String toString(){
210         int boneNo = 0;
211         for(List<BoneMotion> motionList : this.bonePartMap.values()){
212             boneNo += motionList.size();
213         }
214
215         int morphNo = 0;
216         for(List<MorphMotion> motionList : this.morphPartMap.values()){
217             morphNo += motionList.size();
218         }
219
220         int cameraNo   = this.cameraMotionList  .size();
221         int luminousNo = this.luminousMotionList.size();
222         int shadowNo   = this.shadowMotionList  .size();
223         int flagNo     = this.flagList          .size();
224
225         String msg;
226         msg = MessageFormat.format(MSG_TXT,
227                 this.modelName,
228                 boneNo, morphNo, cameraNo, luminousNo, shadowNo, flagNo );
229
230         return msg;
231     }
232
233 }