OSDN Git Service

cde99ece58e9f910ae08f10659b834705a9d5cdc
[mikutoga/TogaGem.git] / src / main / java / jp / sourceforge / mikutoga / pmd / Vertex.java
1 /*
2  * vertex 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.SerialNumbered;
11
12 /**
13  * 頂点情報。
14  */
15 public class Vertex implements SerialNumbered {
16
17     private static final int MIN_WEIGHT = 0;
18     private static final int MAX_WEIGHT = 100;
19
20     private final Pos3d position = new Pos3d();
21     private final Vec3d normal = new Vec3d();
22
23     private final Pos2d uvPosition = new Pos2d();
24
25     private BoneInfo boneA = null;
26     private BoneInfo boneB = null;
27
28     private int boneWeight = 50;
29
30     private boolean edgeAppearance = true;
31
32     private int serialNo = -1;
33
34     /**
35      * コンストラクタ。
36      */
37     public Vertex(){
38         super();
39         return;
40     }
41
42     /**
43      * 頂点位置座標を返す。
44      * @return 頂点の位置座標
45      */
46     public Pos3d getPosition(){
47         return this.position;
48     }
49
50     /**
51      * 法線ベクトルを返す。
52      * @return 法線ベクトル
53      */
54     public Vec3d getNormal(){
55         return this.normal;
56     }
57
58     /**
59      * UVマップ座標を返す。
60      * @return UVマップ情報
61      */
62     public Pos2d getUVPosition(){
63         return this.uvPosition;
64     }
65
66     /**
67      * 頂点の属するボーンを設定する。
68      * @param boneA ボーンA
69      * @param boneB ボーンB
70      * @throws NullPointerException 引数がnull
71      */
72     public void setBonePair(BoneInfo boneA, BoneInfo boneB)
73             throws NullPointerException{
74         if(boneA == null || boneB == null) throw new NullPointerException();
75         this.boneA = boneA;
76         this.boneB = boneB;
77         return;
78     }
79
80     /**
81      * ボーンAを返す。
82      * @return ボーンA
83      */
84     public BoneInfo getBoneA(){
85         return this.boneA;
86     }
87
88     /**
89      * ボーンBを返す。
90      * @return ボーンB
91      */
92     public BoneInfo getBoneB(){
93         return this.boneB;
94     }
95
96     /**
97      * ボーンAのウェイト値を設定する。
98      * @param weight ウェイト値。0(影響小)-100(影響大)
99      * @throws IllegalArgumentException ウェイト値が範囲外
100      */
101     public void setWeightA(int weight) throws IllegalArgumentException{
102         if(   weight < MIN_WEIGHT
103            || MAX_WEIGHT < weight ){
104             throw new IllegalArgumentException();
105         }
106         this.boneWeight = weight;
107         return;
108     }
109
110     /**
111      * ボーンBのウェイト値を設定する。
112      * @param weight ウェイト値。0(影響小)-100(影響大)
113      * @throws IllegalArgumentException ウェイト値が範囲外
114      */
115     public void setWeightB(int weight) throws IllegalArgumentException{
116         setWeightA(MAX_WEIGHT - weight);
117         return;
118     }
119
120     /**
121      * ボーンAのウェイト値を返す。
122      * @return ウェイト値
123      */
124     public int getWeightA(){
125         return this.boneWeight;
126     }
127
128     /**
129      * ボーンBのウェイト値を返す。
130      * @return ウェイト値
131      */
132     public int getWeightB(){
133         int result = MAX_WEIGHT - this.boneWeight;
134         return result;
135     }
136
137     /**
138      * ボーンAのウェイト率を返す。
139      * @return ウェイト率。0.0(影響小)-1.0(影響大)
140      */
141     public float getWeightRatioA(){
142         return ((float)this.boneWeight) / (float)MAX_WEIGHT;
143     }
144
145     /**
146      * ボーンBのウェイト率を返す。
147      * @return ウェイト率。0.0(影響小)-1.0(影響大)
148      */
149     public float getWeightRatioB(){
150         return ((float)MAX_WEIGHT - (float)this.boneWeight)
151                 / (float)MAX_WEIGHT;
152     }
153
154     /**
155      * エッジを表示するか設定する。
156      * マテリアル材質単位の設定より優先度は高い。
157      * @param show 表示するならtrue
158      */
159     public void setEdgeAppearance(boolean show){
160         this.edgeAppearance = show;
161         return;
162     }
163
164     /**
165      * エッジを表示するか判定する。
166      * マテリアル材質単位の設定より優先度は高い。
167      * @return 表示するならtrue
168      */
169     public boolean getEdgeAppearance(){
170         return this.edgeAppearance;
171     }
172
173     /**
174      * {@inheritDoc}
175      * @param num {@inheritDoc}
176      */
177     @Override
178     public void setSerialNumber(int num){
179         this.serialNo = num;
180         return;
181     }
182
183     /**
184      * {@inheritDoc}
185      * @return {@inheritDoc}
186      */
187     @Override
188     public int getSerialNumber(){
189         return this.serialNo;
190     }
191
192     /**
193      * {@inheritDoc}
194      * @return {@inheritDoc}
195      */
196     @Override
197     public String toString(){
198         StringBuilder result = new StringBuilder();
199
200         result.append("Vertex(").append(this.serialNo).append(") ");
201         result.append(this.position).append(' ');
202         result.append(this.normal).append(' ');
203         result.append("UV").append(this.uvPosition).append(' ');
204
205         result.append("[")
206               .append(this.boneA.getBoneName())
207               .append("<>")
208               .append(this.boneB.getBoneName())
209               .append("] ");
210
211         result.append("weight=").append(this.boneWeight).append(' ');
212
213         if(this.edgeAppearance) result.append("showEdge");
214         else                    result.append("hideEdge");
215
216         return result.toString();
217     }
218
219 }