OSDN Git Service

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