OSDN Git Service

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