OSDN Git Service

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