OSDN Git Service

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