2 * pmd parser extension 3
4 * License : The MIT License
5 * Copyright(c) 2010 MikuToga Partners
8 package jp.sfjp.mikutoga.pmd.parser;
10 import java.io.IOException;
11 import java.io.InputStream;
12 import jp.sfjp.mikutoga.bin.parser.MmdFormatException;
13 import jp.sfjp.mikutoga.pmd.PmdLimits;
16 * PMDモデルファイルのパーサ拡張その3。
19 public class PmdParserExt3 extends PmdParserExt2 {
21 private PmdRigidHandler rigidHandler = PmdUnifiedHandler.EMPTY;
22 private PmdJointHandler jointHandler = PmdUnifiedHandler.EMPTY;
28 public PmdParserExt3(InputStream source){
35 * @param handler 剛体ハンドラ
37 public void setRigidHandler(PmdRigidHandler handler){
39 this.rigidHandler = PmdUnifiedHandler.EMPTY;
41 this.rigidHandler = handler;
48 * @param handler ジョイントハンドラ
50 public void setJointHandler(PmdJointHandler handler){
52 this.jointHandler = PmdUnifiedHandler.EMPTY;
54 this.jointHandler = handler;
61 * @throws IOException {@inheritDoc}
62 * @throws MmdFormatException {@inheritDoc}
65 protected void parseBody()
66 throws IOException, MmdFormatException {
79 * @throws IOException IOエラー
80 * @throws MmdFormatException フォーマットエラー
82 private void parseRigidList() throws IOException, MmdFormatException{
83 int rigidNum = parseLeInt();
85 this.rigidHandler.loopStart(PmdRigidHandler.RIGID_LIST, rigidNum);
87 for(int ct = 0; ct < rigidNum; ct++){
89 parsePmdText(PmdLimits.MAXBYTES_RIGIDNAME);
90 this.rigidHandler.pmdRigidName(rigidName);
92 int linkedBoneId = parseLeUShortAsInt();
93 int rigidGroupId = parseUByteAsInt();
94 short collisionMap = parseLeShort();
95 this.rigidHandler.pmdRigidInfo(rigidGroupId, linkedBoneId);
100 byte behaveType = parseByte();
101 this.rigidHandler.pmdRigidBehavior(behaveType, collisionMap);
103 this.rigidHandler.loopNext(PmdRigidHandler.RIGID_LIST);
106 this.rigidHandler.loopEnd(PmdRigidHandler.RIGID_LIST);
113 * @throws IOException IOエラー
114 * @throws MmdFormatException フォーマットエラー
116 private void parseRigidGeom() throws IOException, MmdFormatException{
117 byte shapeType = parseByte();
118 float width = parseLeFloat();
119 float height = parseLeFloat();
120 float depth = parseLeFloat();
122 this.rigidHandler.pmdRigidShape(shapeType, width, height, depth);
124 float posX = parseLeFloat();
125 float posY = parseLeFloat();
126 float posZ = parseLeFloat();
128 this.rigidHandler.pmdRigidPosition(posX, posY, posZ);
130 float rotX = parseLeFloat();
131 float rotY = parseLeFloat();
132 float rotZ = parseLeFloat();
134 this.rigidHandler.pmdRigidRotation(rotX, rotY, rotZ);
141 * @throws IOException IOエラー
142 * @throws MmdFormatException フォーマットエラー
144 private void parseRigidDynamics()
145 throws IOException, MmdFormatException{
146 float mass = parseLeFloat();
147 float dampingPos = parseLeFloat();
148 float dampingRot = parseLeFloat();
149 float restitution = parseLeFloat();
150 float friction = parseLeFloat();
152 this.rigidHandler.pmdRigidPhysics(
153 mass, dampingPos, dampingRot, restitution, friction
161 * @throws IOException IOエラー
162 * @throws MmdFormatException フォーマットエラー
164 private void parseJointList() throws IOException, MmdFormatException{
165 int jointNum = parseLeInt();
167 this.jointHandler.loopStart(PmdJointHandler.JOINT_LIST, jointNum);
169 for(int ct = 0; ct < jointNum; ct++){
171 parsePmdText(PmdLimits.MAXBYTES_JOINTNAME);
172 this.jointHandler.pmdJointName(jointName);
174 int rigidIdA = parseLeInt();
175 int rigidIdB = parseLeInt();
176 this.jointHandler.pmdJointLink(rigidIdA, rigidIdB);
182 this.jointHandler.loopNext(PmdJointHandler.JOINT_LIST);
185 this.jointHandler.loopEnd(PmdJointHandler.JOINT_LIST);
192 * @throws IOException IOエラー
193 * @throws MmdFormatException フォーマットエラー
195 private void parseJointGeom() throws IOException, MmdFormatException{
196 float posX = parseLeFloat();
197 float posY = parseLeFloat();
198 float posZ = parseLeFloat();
200 this.jointHandler.pmdJointPosition(posX, posY, posZ);
202 float rotX = parseLeFloat();
203 float rotY = parseLeFloat();
204 float rotZ = parseLeFloat();
206 this.jointHandler.pmdJointRotation(rotX, rotY, rotZ);
213 * @throws IOException IOエラー
214 * @throws MmdFormatException フォーマットエラー
216 private void parseJointLimit() throws IOException, MmdFormatException{
217 float posXlim1 = parseLeFloat();
218 float posYlim1 = parseLeFloat();
219 float posZlim1 = parseLeFloat();
220 float posXlim2 = parseLeFloat();
221 float posYlim2 = parseLeFloat();
222 float posZlim2 = parseLeFloat();
224 this.jointHandler.pmdPositionLimit(
230 float rotXlim1 = parseLeFloat();
231 float rotYlim1 = parseLeFloat();
232 float rotZlim1 = parseLeFloat();
233 float rotXlim2 = parseLeFloat();
234 float rotYlim2 = parseLeFloat();
235 float rotZlim2 = parseLeFloat();
237 this.jointHandler.pmdRotationLimit(
248 * @throws IOException IOエラー
249 * @throws MmdFormatException フォーマットエラー
251 private void parseJointElastic()
252 throws IOException, MmdFormatException{
253 float elasticPosX = parseLeFloat();
254 float elasticPosY = parseLeFloat();
255 float elasticPosZ = parseLeFloat();
257 this.jointHandler.pmdElasticPosition(
263 float elasticRotX = parseLeFloat();
264 float elasticRotY = parseLeFloat();
265 float elasticRotZ = parseLeFloat();
267 this.jointHandler.pmdElasticRotation(