OSDN Git Service

Merge release/v1.203.2
[mikutoga/Pmd2XML.git] / src / main / java / jp / sfjp / mikutoga / pmd / model / BoneInfo.java
1 /*
2  * bone 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 jp.sfjp.mikutoga.corelib.I18nText;
11 import jp.sfjp.mikutoga.math.MkPos3D;
12 import jp.sfjp.mikutoga.pmd.BoneType;
13
14 /**
15  * ボーン情報。
16  */
17 public class BoneInfo implements SerialNumbered {
18
19     private static final String NO_BONE = "NONE";
20
21     private final I18nText boneName = new I18nText();
22     private BoneType boneType;
23
24     private BoneInfo prevBone;
25     private BoneInfo nextBone;
26     private BoneInfo srcBone;
27
28     private final MkPos3D position = new MkPos3D();
29
30     private int rotationRatio;
31
32     private int boneSerialNo = -1;
33
34
35     /**
36      * コンストラクタ。
37      */
38     public BoneInfo(){
39         super();
40         return;
41     }
42
43
44     /**
45      * ボーン名を返す。
46      * @return ボーン名
47      */
48     public I18nText getBoneName(){
49         return this.boneName;
50     }
51
52     /**
53      * ボーン種別を設定する。
54      * @param type ボーン種別
55      * @throws NullPointerException 引数がnull
56      */
57     public void setBoneType(BoneType type) throws NullPointerException{
58         if(type == null) throw new NullPointerException();
59         this.boneType = type;
60         return;
61     }
62
63     /**
64      * ボーン種別を返す。
65      * @return ボーン種別
66      */
67     public BoneType getBoneType(){
68         return this.boneType;
69     }
70
71     /**
72      * 親(前)ボーンを設定する。
73      * @param prevBone 前ボーン。ない場合はnullを指定。
74      */
75     public void setPrevBone(BoneInfo prevBone){
76         this.prevBone = prevBone;
77         return;
78     }
79
80     /**
81      * 親(前)ボーンを返す。
82      * @return 前ボーン。ない場合はnullを返す。
83      */
84     public BoneInfo getPrevBone(){
85         return this.prevBone;
86     }
87
88     /**
89      * 子(次)ボーンを設定する。
90      * 捩りボーンでは軸方向に位置するボーン、
91      * 回転連動ボーンでは影響元ボーン。
92      * @param nextBone 次ボーン。ない場合はnullを指定。
93      */
94     public void setNextBone(BoneInfo nextBone){
95         this.nextBone = nextBone;
96         return;
97     }
98
99     /**
100      * 子(次)ボーンを返す。
101      * 捩りボーンでは軸方向に位置するボーン、
102      * 回転連動ボーンでは影響元ボーン。
103      * @return 次ボーン。ない場合はnullを返す。
104      */
105     public BoneInfo getNextBone(){
106         return this.nextBone;
107     }
108
109     /**
110      * このボーンが影響を受けるIK元、回転元のソースボーンを設定する。
111      * @param ikBoneArg ソースボーン。ない場合はnullを指定。
112      */
113     public void setSrcBone(BoneInfo ikBoneArg){
114         this.srcBone = ikBoneArg;
115         return;
116     }
117
118     /**
119      * このボーンが影響を受けるIK元、回転元のソースボーンを返す。
120      * @return ソースボーン。ない場合はnull
121      */
122     public BoneInfo getSrcBone(){
123         return this.srcBone;
124     }
125
126     /**
127      * ボーン位置を返す。
128      * @return ボーン位置
129      */
130     public MkPos3D getPosition(){
131         return this.position;
132     }
133
134     /**
135      * 回転連動の影響度を返す。
136      * 回転連動ボーンの場合のみ有効。
137      * @return 回転連動の影響度
138      */
139     public int getRotationRatio(){
140         return this.rotationRatio;
141     }
142
143     /**
144      * 回転連動の影響度を設定する。
145      * 回転連動ボーンの場合のみ有効。
146      * @param ratio 回転連動の影響度
147      */
148     public void setRotationRatio(int ratio){
149         this.rotationRatio = ratio;
150     }
151
152     /**
153      * {@inheritDoc}
154      * @param num {@inheritDoc}
155      */
156     @Override
157     public void setSerialNumber(int num){
158         this.boneSerialNo = num;
159         return;
160     }
161
162     /**
163      * {@inheritDoc}
164      * @return {@inheritDoc}
165      */
166     @Override
167     public int getSerialNumber(){
168         return this.boneSerialNo;
169     }
170
171     /**
172      * {@inheritDoc}
173      * @return {@inheritDoc}
174      */
175     @Override
176     public String toString(){
177         StringBuilder result = new StringBuilder();
178
179         result.append("Bone")
180               .append(this.boneSerialNo)
181               .append("(")
182               .append(this.boneName.getPrimaryText())
183               .append(")");
184
185         result.append(" type=")
186               .append(this.boneType);
187
188         result.append(" prev=");
189         if(this.prevBone != null) result.append(this.prevBone.getBoneName());
190         else                      result.append(NO_BONE);
191
192         result.append(" next=");
193         if(this.nextBone != null) result.append(this.nextBone.getBoneName());
194         else                      result.append(NO_BONE);
195
196         if(this.boneType == BoneType.LINKEDROT){
197             result.append(" rotraio=").append(this.rotationRatio);
198         }else{
199             result.append(" ik=");
200             if(this.srcBone != null){
201                 result.append(this.srcBone.getBoneName());
202             }else{
203                 result.append(NO_BONE);
204             }
205         }
206
207         result.append(" ").append(this.position);
208
209         return result.toString();
210     }
211
212 }