OSDN Git Service

[no commit message]
[mikutoga/TogaGem.git] / src / main / java / jp / sourceforge / mikutoga / pmd / pmdloader / JointBuilder.java
1 /*
2  * building joint information
3  *
4  * License : The MIT License
5  * Copyright(c) 2010 MikuToga Partners
6  */
7
8 package jp.sourceforge.mikutoga.pmd.pmdloader;
9
10 import java.util.Iterator;
11 import java.util.List;
12 import jp.sourceforge.mikutoga.corelib.ListUtil;
13 import jp.sourceforge.mikutoga.parser.ParseStage;
14 import jp.sourceforge.mikutoga.pmd.Deg3d;
15 import jp.sourceforge.mikutoga.pmd.Pos3d;
16 import jp.sourceforge.mikutoga.pmd.Rad3d;
17 import jp.sourceforge.mikutoga.pmd.TripletRange;
18 import jp.sourceforge.mikutoga.pmd.model.JointInfo;
19 import jp.sourceforge.mikutoga.pmd.model.PmdModel;
20 import jp.sourceforge.mikutoga.pmd.model.RigidInfo;
21 import jp.sourceforge.mikutoga.pmd.parser.PmdJointHandler;
22
23 /**
24  * ジョイント関係の通知をパーサから受け取る。
25  */
26 class JointBuilder implements PmdJointHandler {
27
28     private final List<RigidInfo> rigidList;
29
30     private final List<JointInfo> jointList;
31     private Iterator<JointInfo> jointIt;
32     private JointInfo currentJoint = null;
33
34     /**
35      * コンストラクタ。
36      * @param model モデル
37      */
38     JointBuilder(PmdModel model){
39         super();
40         this.rigidList = model.getRigidList();
41         this.jointList = model.getJointList();
42         return;
43     }
44
45     /**
46      * {@inheritDoc}
47      * @param stage {@inheritDoc}
48      * @param loops {@inheritDoc}
49      */
50     @Override
51     public void loopStart(ParseStage stage, int loops){
52         assert stage == PmdJointHandler.JOINT_LIST;
53
54         ListUtil.prepareDefConsList(this.jointList, JointInfo.class, loops);
55
56         this.jointIt = this.jointList.iterator();
57         if(this.jointIt.hasNext()){
58             this.currentJoint = this.jointIt.next();
59         }
60
61         return;
62     }
63
64     /**
65      * {@inheritDoc}
66      * @param stage {@inheritDoc}
67      */
68     @Override
69     public void loopNext(ParseStage stage){
70         assert stage == PmdJointHandler.JOINT_LIST;
71
72         if(this.jointIt.hasNext()){
73             this.currentJoint = this.jointIt.next();
74         }
75
76         return;
77     }
78
79     /**
80      * {@inheritDoc}
81      * @param stage {@inheritDoc}
82      */
83     @Override
84     public void loopEnd(ParseStage stage){
85         assert stage == PmdJointHandler.JOINT_LIST;
86         return;
87     }
88
89     /**
90      * {@inheritDoc}
91      * @param jointName {@inheritDoc}
92      */
93     @Override
94     public void pmdJointName(String jointName){
95         this.currentJoint.getJointName().setPrimaryText(jointName);
96         return;
97     }
98
99     /**
100      * {@inheritDoc}
101      * @param rigidIdA {@inheritDoc}
102      * @param rigidIdB {@inheritDoc}
103      */
104     @Override
105     public void pmdJointLink(int rigidIdA, int rigidIdB){
106         RigidInfo rigidA = this.rigidList.get(rigidIdA);
107         RigidInfo rigidB = this.rigidList.get(rigidIdB);
108         this.currentJoint.setRigidPair(rigidA, rigidB);
109         return;
110     }
111
112     /**
113      * {@inheritDoc}
114      * @param posX {@inheritDoc}
115      * @param posY {@inheritDoc}
116      * @param posZ {@inheritDoc}
117      */
118     @Override
119     public void pmdJointPosition(float posX, float posY, float posZ){
120         Pos3d position = this.currentJoint.getPosition();
121         position.setXPos(posX);
122         position.setYPos(posY);
123         position.setZPos(posZ);
124         return;
125     }
126
127     /**
128      * {@inheritDoc}
129      * @param rotX {@inheritDoc}
130      * @param rotY {@inheritDoc}
131      * @param rotZ {@inheritDoc}
132      */
133     @Override
134     public void pmdJointRotation(float rotX, float rotY, float rotZ){
135         Rad3d rotation = this.currentJoint.getRotation();
136         rotation.setXRad(rotX);
137         rotation.setYRad(rotY);
138         rotation.setZRad(rotZ);
139         return;
140     }
141
142     /**
143      * {@inheritDoc}
144      * @param posXlim1 {@inheritDoc}
145      * @param posXlim2 {@inheritDoc}
146      * @param posYlim1 {@inheritDoc}
147      * @param posYlim2 {@inheritDoc}
148      * @param posZlim1 {@inheritDoc}
149      * @param posZlim2 {@inheritDoc}
150      */
151     @Override
152     public void pmdPositionLimit(float posXlim1, float posXlim2,
153                                  float posYlim1, float posYlim2,
154                                  float posZlim1, float posZlim2){
155         TripletRange range = this.currentJoint.getPositionRange();
156         range.setXRange(posXlim1, posXlim2);
157         range.setYRange(posYlim1, posYlim2);
158         range.setZRange(posZlim1, posZlim2);
159         return;
160     }
161
162     /**
163      * {@inheritDoc}
164      * @param rotXlim1 {@inheritDoc}
165      * @param rotXlim2 {@inheritDoc}
166      * @param rotYlim1 {@inheritDoc}
167      * @param rotYlim2 {@inheritDoc}
168      * @param rotZlim1 {@inheritDoc}
169      * @param rotZlim2 {@inheritDoc}
170      */
171     @Override
172     public void pmdRotationLimit(float rotXlim1, float rotXlim2,
173                                  float rotYlim1, float rotYlim2,
174                                  float rotZlim1, float rotZlim2){
175         TripletRange range = this.currentJoint.getRotationRange();
176         range.setXRange(rotXlim1, rotXlim2);
177         range.setYRange(rotYlim1, rotYlim2);
178         range.setZRange(rotZlim1, rotZlim2);
179         return;
180     }
181
182     /**
183      * {@inheritDoc}
184      * @param elasticPosX {@inheritDoc}
185      * @param elasticPosY {@inheritDoc}
186      * @param elasticPosZ {@inheritDoc}
187      */
188     @Override
189     public void pmdElasticPosition(float elasticPosX,
190                                    float elasticPosY,
191                                    float elasticPosZ){
192         Pos3d position = this.currentJoint.getElasticPosition();
193         position.setXPos(elasticPosX);
194         position.setYPos(elasticPosY);
195         position.setZPos(elasticPosZ);
196         return;
197     }
198
199     /**
200      * {@inheritDoc}
201      * @param elasticRotX {@inheritDoc}
202      * @param elasticRotY {@inheritDoc}
203      * @param elasticRotZ {@inheritDoc}
204      */
205     @Override
206     public void pmdElasticRotation(float elasticRotX,
207                                    float elasticRotY,
208                                    float elasticRotZ){
209         Deg3d rotation = this.currentJoint.getElasticRotation();
210         rotation.setXDeg(elasticRotX);
211         rotation.setYDeg(elasticRotY);
212         rotation.setZDeg(elasticRotZ);
213         return;
214     }
215
216 }