OSDN Git Service

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