OSDN Git Service

08a548169b4ac835e8733c55f2cfc6af419680c7
[mikutoga/Pmd2XML.git] / src / main / java / jp / sfjp / mikutoga / pmd / model / RigidInfo.java
1 /*
2  * rigid information
3  *
4  * License : The MIT License
5  * Copyright(c) 2010 MikuToga Partners
6  */
7
8 package jp.sfjp.mikutoga.pmd.model;
9
10 import java.util.ArrayList;
11 import java.util.Collection;
12 import jp.sfjp.mikutoga.corelib.I18nText;
13 import jp.sfjp.mikutoga.math.MkPos3D;
14 import jp.sfjp.mikutoga.pmd.Rad3d;
15 import jp.sfjp.mikutoga.pmd.RigidBehaviorType;
16
17 /**
18  * 個別の剛体の情報。
19  */
20 public class RigidInfo implements SerialNumbered {
21
22     private final I18nText rigidName = new I18nText();
23
24     private RigidBehaviorType behaviorType = RigidBehaviorType.FOLLOWBONE;
25
26     private final RigidShape rigidShape = new RigidShape();
27     private final MkPos3D position = new MkPos3D();
28     private final Rad3d rotation = new Rad3d();
29
30     private BoneInfo linkedBone;
31
32     private final DynamicsInfo dynamicsInfo = new DynamicsInfo();
33
34     private final Collection<RigidGroup> throughGroupColl =
35             new ArrayList<RigidGroup>();
36
37     private RigidGroup rigidGroup;
38
39     private int serialNo = -1;
40
41     /**
42      * コンストラクタ。
43      */
44     public RigidInfo(){
45         super();
46         return;
47     }
48
49     /**
50      * 剛体名を返す。
51      * @return 剛体名
52      */
53     public I18nText getRigidName(){
54         return this.rigidName;
55     }
56
57     /**
58      * 剛体の振る舞い種別を返す。
59      * @return 剛体の振る舞い種別
60      */
61     public RigidBehaviorType getBehaviorType(){
62         return this.behaviorType;
63     }
64
65     /**
66      * 剛体の振る舞い種別を設定する。
67      * @param type 剛体の振る舞い種別。
68      * @throws NullPointerException 引数がnull
69      */
70     public void setBehaviorType(RigidBehaviorType type)
71             throws NullPointerException{
72         if(type == null) throw new NullPointerException();
73         this.behaviorType = type;
74         return;
75     }
76
77     /**
78      * 剛体形状を返す。
79      * @return 剛体形状
80      */
81     public RigidShape getRigidShape(){
82         return this.rigidShape;
83     }
84
85     /**
86      * 剛体位置を返す。
87      * @return 剛体位置
88      */
89     public MkPos3D getPosition(){
90         return this.position;
91     }
92
93     /**
94      * 剛体姿勢を返す。
95      * @return 剛体姿勢
96      */
97     public Rad3d getRotation(){
98         return this.rotation;
99     }
100
101     /**
102      * 接続ボーンを返す。
103      * @return 接続ボーン
104      */
105     public BoneInfo getLinkedBone(){
106         return this.linkedBone;
107     }
108
109     /**
110      * 接続ボーンを設定する。
111      * @param bone 接続ボーン
112      */
113     public void setLinkedBone(BoneInfo bone){
114         this.linkedBone = bone;
115         return;
116     }
117
118     /**
119      * 剛体の力学パラメータを返す。
120      * @return 力学パラメータ
121      */
122     public DynamicsInfo getDynamicsInfo(){
123         return this.dynamicsInfo;
124     }
125
126     /**
127      * 非衝突グループ集合を返す。
128      * @return 非衝突グループ集合
129      */
130     public Collection<RigidGroup> getThroughGroupColl(){
131         return this.throughGroupColl;
132     }
133
134     /**
135      * 所属する剛体グループを返す。
136      * @return 所属する剛体グループ
137      */
138     public RigidGroup getRigidGroup(){
139         return this.rigidGroup;
140     }
141
142     /**
143      * 所属する剛体グループを設定する。
144      * @param group 所属する剛体グループ
145      */
146     public void setRigidGroup(RigidGroup group){
147         this.rigidGroup = group;
148         return;
149     }
150
151     /**
152      * {@inheritDoc}
153      * @param num {@inheritDoc}
154      */
155     @Override
156     public void setSerialNumber(int num){
157         this.serialNo = num;
158         return;
159     }
160
161     /**
162      * {@inheritDoc}
163      * @return {@inheritDoc}
164      */
165     @Override
166     public int getSerialNumber(){
167         return this.serialNo;
168     }
169
170     /**
171      * {@inheritDoc}
172      * @return {@inheritDoc}
173      */
174     @Override
175     public String toString(){
176         StringBuilder result = new StringBuilder();
177
178         String boneName;
179         if(this.linkedBone == null){
180             boneName = "NOBONE";
181         }else{
182             boneName = this.linkedBone.getBoneName().toString();
183         }
184
185         result.append("Rigid(").append(this.rigidName).append(") ");
186         result.append("[=>")
187               .append(boneName)
188               .append("bone]");
189         result.append(" [").append(this.rigidShape).append("]");
190         result.append(" ").append(this.position);
191         result.append(" ").append(this.rotation);
192         result.append(" [").append(this.dynamicsInfo).append("]");
193         result.append("  [").append(this.behaviorType).append("]");
194
195         result.append(" through[");
196         boolean dumped = false;
197         for(RigidGroup group : this.throughGroupColl){
198             if(dumped) result.append(" ");
199             result.append(group.getGroupNumber());
200             dumped = true;
201         }
202         result.append("]");
203
204         return result.toString();
205     }
206
207 }