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.sourceforge.mikutoga.parser.MmdFormatException;
15 * PMDモデルファイルのパーサ拡張その3。
18 public class PmdParserExt3 extends PmdParserExt2 {
20 private static final int RIGID_DATA_SZ = 83;
21 private static final int JOINT_DATA_SZ = 124;
23 private PmdRigidHandler rigidHandler = null;
24 private PmdJointHandler jointHandler = null;
30 public PmdParserExt3(InputStream source){
37 * @param handler 剛体ハンドラ
39 public void setRigidHandler(PmdRigidHandler handler){
40 this.rigidHandler = handler;
46 * @param handler ジョイントハンドラ
48 public void setJointHandler(PmdJointHandler handler){
49 this.jointHandler = handler;
55 * @throws IOException {@inheritDoc}
56 * @throws MmdFormatException {@inheritDoc}
59 protected void parseBody()
60 throws IOException, MmdFormatException {
73 * @throws IOException IOエラー
74 * @throws MmdFormatException フォーマットエラー
76 private void parseRigidList() throws IOException, MmdFormatException{
77 int rigidNum = parseLeInt();
79 if(this.rigidHandler == null){
80 skip(RIGID_DATA_SZ * rigidNum);
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);
96 byte shapeType = parseByte();
97 float width = parseLeFloat();
98 float height = parseLeFloat();
99 float depth = parseLeFloat();
100 this.rigidHandler.pmdRigidShape(shapeType, width, height, depth);
102 float posX = parseLeFloat();
103 float posY = parseLeFloat();
104 float posZ = parseLeFloat();
105 this.rigidHandler.pmdRigidPosition(posX, posY, posZ);
107 float rotX = parseLeFloat();
108 float rotY = parseLeFloat();
109 float rotZ = parseLeFloat();
110 this.rigidHandler.pmdRigidRotation(rotX, rotY, rotZ);
112 float mass = parseLeFloat();
113 float dampingPos = parseLeFloat();
114 float dampingRot = parseLeFloat();
115 float restitution = parseLeFloat();
116 float friction = parseLeFloat();
117 this.rigidHandler.pmdRigidPhysics(mass,
118 dampingPos, dampingRot,
119 restitution, friction );
121 byte behaveType = parseByte();
122 this.rigidHandler.pmdRigidBehavior(behaveType, collisionMap);
124 this.rigidHandler.loopNext(PmdRigidHandler.RIGID_LIST);
127 this.rigidHandler.loopEnd(PmdRigidHandler.RIGID_LIST);
134 * @throws IOException IOエラー
135 * @throws MmdFormatException フォーマットエラー
137 private void parseJointList() throws IOException, MmdFormatException{
138 int jointNum = parseLeInt();
140 if(this.jointHandler == null){
141 skip(JOINT_DATA_SZ * jointNum);
145 this.jointHandler.loopStart(PmdJointHandler.JOINT_LIST, jointNum);
147 for(int ct = 0; ct < jointNum; ct++){
149 parsePmdText(PmdLimits.MAXBYTES_JOINTNAME);
150 this.jointHandler.pmdJointName(jointName);
152 int rigidIdA = parseLeInt();
153 int rigidIdB = parseLeInt();
154 this.jointHandler.pmdJointLink(rigidIdA, rigidIdB);
156 float posX = parseLeFloat();
157 float posY = parseLeFloat();
158 float posZ = parseLeFloat();
159 this.jointHandler.pmdJointPosition(posX, posY, posZ);
161 float rotX = parseLeFloat();
162 float rotY = parseLeFloat();
163 float rotZ = parseLeFloat();
164 this.jointHandler.pmdJointRotation(rotX, rotY, rotZ);
166 float posXlim1 = parseLeFloat();
167 float posYlim1 = parseLeFloat();
168 float posZlim1 = parseLeFloat();
169 float posXlim2 = parseLeFloat();
170 float posYlim2 = parseLeFloat();
171 float posZlim2 = parseLeFloat();
172 this.jointHandler.pmdPositionLimit(posXlim1, posXlim2,
174 posZlim1, posZlim2 );
176 float rotXlim1 = parseLeFloat();
177 float rotYlim1 = parseLeFloat();
178 float rotZlim1 = parseLeFloat();
179 float rotXlim2 = parseLeFloat();
180 float rotYlim2 = parseLeFloat();
181 float rotZlim2 = parseLeFloat();
182 this.jointHandler.pmdRotationLimit(rotXlim1, rotXlim2,
184 rotZlim1, rotZlim2 );
186 float elasticPosX = parseLeFloat();
187 float elasticPosY = parseLeFloat();
188 float elasticPosZ = parseLeFloat();
189 this.jointHandler.pmdElasticPosition(elasticPosX,
193 float elasticRotX = parseLeFloat();
194 float elasticRotY = parseLeFloat();
195 float elasticRotZ = parseLeFloat();
196 this.jointHandler.pmdElasticRotation(elasticRotX,
200 this.jointHandler.loopNext(PmdJointHandler.JOINT_LIST);
203 this.jointHandler.loopEnd(PmdJointHandler.JOINT_LIST);