2 * building joint information
4 * License : The MIT License
5 * Copyright(c) 2010 MikuToga Partners
8 package jp.sfjp.mikutoga.pmd.model.binio;
10 import java.util.Iterator;
11 import java.util.List;
12 import jp.sfjp.mikutoga.bin.parser.ParseStage;
13 import jp.sfjp.mikutoga.math.MkPos3D;
14 import jp.sfjp.mikutoga.pmd.Deg3d;
15 import jp.sfjp.mikutoga.pmd.Rad3d;
16 import jp.sfjp.mikutoga.pmd.TripletRange;
17 import jp.sfjp.mikutoga.pmd.model.JointInfo;
18 import jp.sfjp.mikutoga.pmd.model.ListUtil;
19 import jp.sfjp.mikutoga.pmd.model.PmdModel;
20 import jp.sfjp.mikutoga.pmd.model.RigidInfo;
21 import jp.sfjp.mikutoga.pmd.parser.PmdJointHandler;
24 * ジョイント関係の通知をパーサから受け取る。
26 class JointBuilder implements PmdJointHandler {
28 private final List<RigidInfo> rigidList;
30 private final List<JointInfo> jointList;
31 private Iterator<JointInfo> jointIt;
32 private JointInfo currentJoint = null;
38 JointBuilder(PmdModel model){
40 this.rigidList = model.getRigidList();
41 this.jointList = model.getJointList();
47 * @param stage {@inheritDoc}
48 * @param loops {@inheritDoc}
51 public void loopStart(ParseStage stage, int loops){
52 assert stage == PmdJointHandler.JOINT_LIST;
54 ListUtil.prepareDefConsList(this.jointList, JointInfo.class, loops);
56 this.jointIt = this.jointList.iterator();
57 if(this.jointIt.hasNext()){
58 this.currentJoint = this.jointIt.next();
66 * @param stage {@inheritDoc}
69 public void loopNext(ParseStage stage){
70 assert stage == PmdJointHandler.JOINT_LIST;
72 if(this.jointIt.hasNext()){
73 this.currentJoint = this.jointIt.next();
81 * @param stage {@inheritDoc}
84 public void loopEnd(ParseStage stage){
85 assert stage == PmdJointHandler.JOINT_LIST;
91 * @param jointName {@inheritDoc}
94 public void pmdJointName(String jointName){
95 this.currentJoint.getJointName().setPrimaryText(jointName);
101 * @param rigidIdA {@inheritDoc}
102 * @param rigidIdB {@inheritDoc}
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);
114 * @param posX {@inheritDoc}
115 * @param posY {@inheritDoc}
116 * @param posZ {@inheritDoc}
119 public void pmdJointPosition(float posX, float posY, float posZ){
120 MkPos3D position = this.currentJoint.getPosition();
121 position.setXpos(posX);
122 position.setYpos(posY);
123 position.setZpos(posZ);
129 * @param rotX {@inheritDoc}
130 * @param rotY {@inheritDoc}
131 * @param rotZ {@inheritDoc}
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);
144 * @param posXlim1 {@inheritDoc}
145 * @param posXlim2 {@inheritDoc}
146 * @param posYlim1 {@inheritDoc}
147 * @param posYlim2 {@inheritDoc}
148 * @param posZlim1 {@inheritDoc}
149 * @param posZlim2 {@inheritDoc}
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);
164 * @param rotXlim1 {@inheritDoc}
165 * @param rotXlim2 {@inheritDoc}
166 * @param rotYlim1 {@inheritDoc}
167 * @param rotYlim2 {@inheritDoc}
168 * @param rotZlim1 {@inheritDoc}
169 * @param rotZlim2 {@inheritDoc}
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);
184 * @param elasticPosX {@inheritDoc}
185 * @param elasticPosY {@inheritDoc}
186 * @param elasticPosZ {@inheritDoc}
189 public void pmdElasticPosition(float elasticPosX,
192 MkPos3D position = this.currentJoint.getElasticPosition();
193 position.setXpos(elasticPosX);
194 position.setYpos(elasticPosY);
195 position.setZpos(elasticPosZ);
201 * @param elasticRotX {@inheritDoc}
202 * @param elasticRotY {@inheritDoc}
203 * @param elasticRotZ {@inheritDoc}
206 public void pmdElasticRotation(float elasticRotX,
209 Deg3d rotation = this.currentJoint.getElasticRotation();
210 rotation.setXDeg(elasticRotX);
211 rotation.setYDeg(elasticRotY);
212 rotation.setZDeg(elasticRotZ);