2 * pmd parser extension 3
4 * License : The MIT License
5 * Copyright(c) 2010 MikuToga Partners
8 package jp.sourceforge.mikutoga.pmd.parser;
10 import java.io.IOException;
11 import java.io.InputStream;
12 import jp.sfjp.mikutoga.bin.parser.MmdFormatException;
15 * PMDモデルファイルのパーサ拡張その3。
18 public class PmdParserExt3 extends PmdParserExt2 {
20 private PmdRigidHandler rigidHandler = NullHandler.HANDLER;
21 private PmdJointHandler jointHandler = NullHandler.HANDLER;
27 public PmdParserExt3(InputStream source){
34 * @param handler 剛体ハンドラ
36 public void setRigidHandler(PmdRigidHandler handler){
38 this.rigidHandler = NullHandler.HANDLER;
40 this.rigidHandler = handler;
47 * @param handler ジョイントハンドラ
49 public void setJointHandler(PmdJointHandler handler){
51 this.jointHandler = NullHandler.HANDLER;
53 this.jointHandler = handler;
60 * @throws IOException {@inheritDoc}
61 * @throws MmdFormatException {@inheritDoc}
64 protected void parseBody()
65 throws IOException, MmdFormatException {
78 * @throws IOException IOエラー
79 * @throws MmdFormatException フォーマットエラー
81 private void parseRigidList() throws IOException, MmdFormatException{
82 int rigidNum = parseLeInt();
84 this.rigidHandler.loopStart(PmdRigidHandler.RIGID_LIST, rigidNum);
86 for(int ct = 0; ct < rigidNum; ct++){
88 parsePmdText(PmdLimits.MAXBYTES_RIGIDNAME);
89 this.rigidHandler.pmdRigidName(rigidName);
91 int linkedBoneId = parseLeUShortAsInt();
92 int rigidGroupId = parseUByteAsInt();
93 short collisionMap = parseLeShort();
94 this.rigidHandler.pmdRigidInfo(rigidGroupId, linkedBoneId);
99 byte behaveType = parseByte();
100 this.rigidHandler.pmdRigidBehavior(behaveType, collisionMap);
102 this.rigidHandler.loopNext(PmdRigidHandler.RIGID_LIST);
105 this.rigidHandler.loopEnd(PmdRigidHandler.RIGID_LIST);
112 * @throws IOException IOエラー
113 * @throws MmdFormatException フォーマットエラー
115 private void parseRigidGeom() throws IOException, MmdFormatException{
116 byte shapeType = parseByte();
117 float width = parseLeFloat();
118 float height = parseLeFloat();
119 float depth = parseLeFloat();
121 this.rigidHandler.pmdRigidShape(shapeType, width, height, depth);
123 float posX = parseLeFloat();
124 float posY = parseLeFloat();
125 float posZ = parseLeFloat();
127 this.rigidHandler.pmdRigidPosition(posX, posY, posZ);
129 float rotX = parseLeFloat();
130 float rotY = parseLeFloat();
131 float rotZ = parseLeFloat();
133 this.rigidHandler.pmdRigidRotation(rotX, rotY, rotZ);
140 * @throws IOException IOエラー
141 * @throws MmdFormatException フォーマットエラー
143 private void parseRigidDynamics()
144 throws IOException, MmdFormatException{
145 float mass = parseLeFloat();
146 float dampingPos = parseLeFloat();
147 float dampingRot = parseLeFloat();
148 float restitution = parseLeFloat();
149 float friction = parseLeFloat();
151 this.rigidHandler.pmdRigidPhysics(
152 mass, dampingPos, dampingRot, restitution, friction
160 * @throws IOException IOエラー
161 * @throws MmdFormatException フォーマットエラー
163 private void parseJointList() throws IOException, MmdFormatException{
164 int jointNum = parseLeInt();
166 this.jointHandler.loopStart(PmdJointHandler.JOINT_LIST, jointNum);
168 for(int ct = 0; ct < jointNum; ct++){
170 parsePmdText(PmdLimits.MAXBYTES_JOINTNAME);
171 this.jointHandler.pmdJointName(jointName);
173 int rigidIdA = parseLeInt();
174 int rigidIdB = parseLeInt();
175 this.jointHandler.pmdJointLink(rigidIdA, rigidIdB);
181 this.jointHandler.loopNext(PmdJointHandler.JOINT_LIST);
184 this.jointHandler.loopEnd(PmdJointHandler.JOINT_LIST);
191 * @throws IOException IOエラー
192 * @throws MmdFormatException フォーマットエラー
194 private void parseJointGeom() throws IOException, MmdFormatException{
195 float posX = parseLeFloat();
196 float posY = parseLeFloat();
197 float posZ = parseLeFloat();
199 this.jointHandler.pmdJointPosition(posX, posY, posZ);
201 float rotX = parseLeFloat();
202 float rotY = parseLeFloat();
203 float rotZ = parseLeFloat();
205 this.jointHandler.pmdJointRotation(rotX, rotY, rotZ);
212 * @throws IOException IOエラー
213 * @throws MmdFormatException フォーマットエラー
215 private void parseJointLimit() throws IOException, MmdFormatException{
216 float posXlim1 = parseLeFloat();
217 float posYlim1 = parseLeFloat();
218 float posZlim1 = parseLeFloat();
219 float posXlim2 = parseLeFloat();
220 float posYlim2 = parseLeFloat();
221 float posZlim2 = parseLeFloat();
223 this.jointHandler.pmdPositionLimit(
229 float rotXlim1 = parseLeFloat();
230 float rotYlim1 = parseLeFloat();
231 float rotZlim1 = parseLeFloat();
232 float rotXlim2 = parseLeFloat();
233 float rotYlim2 = parseLeFloat();
234 float rotZlim2 = parseLeFloat();
236 this.jointHandler.pmdRotationLimit(
247 * @throws IOException IOエラー
248 * @throws MmdFormatException フォーマットエラー
250 private void parseJointElastic()
251 throws IOException, MmdFormatException{
252 float elasticPosX = parseLeFloat();
253 float elasticPosY = parseLeFloat();
254 float elasticPosZ = parseLeFloat();
256 this.jointHandler.pmdElasticPosition(
262 float elasticRotX = parseLeFloat();
263 float elasticRotY = parseLeFloat();
264 float elasticRotZ = parseLeFloat();
266 this.jointHandler.pmdElasticRotation(