OSDN Git Service

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