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.PmdConst;
16 * PMDモデルファイルのパーサ拡張その3。
20 public class PmdParserExt3 extends PmdParserExt2 {
22 private PmdRigidHandler rigidHandler = PmdUnifiedHandler.EMPTY;
23 private PmdJointHandler jointHandler = PmdUnifiedHandler.EMPTY;
29 public PmdParserExt3(InputStream source){
36 * @param handler 剛体ハンドラ
38 public void setRigidHandler(PmdRigidHandler handler){
40 this.rigidHandler = PmdUnifiedHandler.EMPTY;
42 this.rigidHandler = handler;
49 * @param handler ジョイントハンドラ
51 public void setJointHandler(PmdJointHandler handler){
53 this.jointHandler = PmdUnifiedHandler.EMPTY;
55 this.jointHandler = handler;
62 * @throws IOException {@inheritDoc}
63 * @throws MmdFormatException {@inheritDoc}
66 protected void parseBody()
67 throws IOException, MmdFormatException {
80 * @throws IOException IOエラー
81 * @throws MmdFormatException フォーマットエラー
83 private void parseRigidList() throws IOException, MmdFormatException{
84 int rigidNum = parseLeInt();
86 this.rigidHandler.loopStart(PmdRigidHandler.RIGID_LIST, rigidNum);
88 for(int ct = 0; ct < rigidNum; ct++){
90 parsePmdText(PmdConst.MAXBYTES_RIGIDNAME);
91 this.rigidHandler.pmdRigidName(rigidName);
93 int linkedBoneId = parseLeUShortAsInt();
94 int rigidGroupId = parseUByteAsInt();
95 short collisionMap = parseLeShort();
96 this.rigidHandler.pmdRigidInfo(rigidGroupId, linkedBoneId);
101 byte behaveType = parseByte();
102 this.rigidHandler.pmdRigidBehavior(behaveType, collisionMap);
104 this.rigidHandler.loopNext(PmdRigidHandler.RIGID_LIST);
107 this.rigidHandler.loopEnd(PmdRigidHandler.RIGID_LIST);
114 * @throws IOException IOエラー
115 * @throws MmdFormatException フォーマットエラー
117 private void parseRigidGeom() throws IOException, MmdFormatException{
118 byte shapeType = parseByte();
119 float width = parseLeFloat();
120 float height = parseLeFloat();
121 float depth = parseLeFloat();
123 this.rigidHandler.pmdRigidShape(shapeType, width, height, depth);
125 float posX = parseLeFloat();
126 float posY = parseLeFloat();
127 float posZ = parseLeFloat();
129 this.rigidHandler.pmdRigidPosition(posX, posY, posZ);
131 float rotX = parseLeFloat();
132 float rotY = parseLeFloat();
133 float rotZ = parseLeFloat();
135 this.rigidHandler.pmdRigidRotation(rotX, rotY, rotZ);
142 * @throws IOException IOエラー
143 * @throws MmdFormatException フォーマットエラー
145 private void parseRigidDynamics()
146 throws IOException, MmdFormatException{
147 float mass = parseLeFloat();
148 float dampingPos = parseLeFloat();
149 float dampingRot = parseLeFloat();
150 float restitution = parseLeFloat();
151 float friction = parseLeFloat();
153 this.rigidHandler.pmdRigidPhysics(
154 mass, dampingPos, dampingRot, restitution, friction
162 * @throws IOException IOエラー
163 * @throws MmdFormatException フォーマットエラー
165 private void parseJointList() throws IOException, MmdFormatException{
166 int jointNum = parseLeInt();
168 this.jointHandler.loopStart(PmdJointHandler.JOINT_LIST, jointNum);
170 for(int ct = 0; ct < jointNum; ct++){
172 parsePmdText(PmdConst.MAXBYTES_JOINTNAME);
173 this.jointHandler.pmdJointName(jointName);
175 int rigidIdA = parseLeInt();
176 int rigidIdB = parseLeInt();
177 this.jointHandler.pmdJointLink(rigidIdA, rigidIdB);
183 this.jointHandler.loopNext(PmdJointHandler.JOINT_LIST);
186 this.jointHandler.loopEnd(PmdJointHandler.JOINT_LIST);
193 * @throws IOException IOエラー
194 * @throws MmdFormatException フォーマットエラー
196 private void parseJointGeom() throws IOException, MmdFormatException{
197 float posX = parseLeFloat();
198 float posY = parseLeFloat();
199 float posZ = parseLeFloat();
201 this.jointHandler.pmdJointPosition(posX, posY, posZ);
203 float rotX = parseLeFloat();
204 float rotY = parseLeFloat();
205 float rotZ = parseLeFloat();
207 this.jointHandler.pmdJointRotation(rotX, rotY, rotZ);
214 * @throws IOException IOエラー
215 * @throws MmdFormatException フォーマットエラー
217 private void parseJointLimit() throws IOException, MmdFormatException{
218 float posXlim1 = parseLeFloat();
219 float posYlim1 = parseLeFloat();
220 float posZlim1 = parseLeFloat();
221 float posXlim2 = parseLeFloat();
222 float posYlim2 = parseLeFloat();
223 float posZlim2 = parseLeFloat();
225 this.jointHandler.pmdPositionLimit(
231 float rotXlim1 = parseLeFloat();
232 float rotYlim1 = parseLeFloat();
233 float rotZlim1 = parseLeFloat();
234 float rotXlim2 = parseLeFloat();
235 float rotYlim2 = parseLeFloat();
236 float rotZlim2 = parseLeFloat();
238 this.jointHandler.pmdRotationLimit(
249 * @throws IOException IOエラー
250 * @throws MmdFormatException フォーマットエラー
252 private void parseJointElastic()
253 throws IOException, MmdFormatException{
254 float elasticPosX = parseLeFloat();
255 float elasticPosY = parseLeFloat();
256 float elasticPosZ = parseLeFloat();
258 this.jointHandler.pmdElasticPosition(
264 float elasticRotX = parseLeFloat();
265 float elasticRotY = parseLeFloat();
266 float elasticRotZ = parseLeFloat();
268 this.jointHandler.pmdElasticRotation(