2 * model exporter for pmd-file(Ext3)
4 * License : The MIT License
5 * Copyright(c) 2010 MikuToga Partners
8 package jp.sourceforge.mikutoga.pmd.pmdexporter;
10 import java.io.IOException;
11 import java.io.OutputStream;
12 import java.util.List;
13 import jp.sourceforge.mikutoga.pmd.Deg3d;
14 import jp.sourceforge.mikutoga.pmd.Rad3d;
15 import jp.sourceforge.mikutoga.pmd.RigidShapeType;
16 import jp.sourceforge.mikutoga.pmd.TripletRange;
17 import jp.sourceforge.mikutoga.pmd.model.BoneInfo;
18 import jp.sourceforge.mikutoga.pmd.model.DynamicsInfo;
19 import jp.sourceforge.mikutoga.pmd.model.JointInfo;
20 import jp.sourceforge.mikutoga.pmd.model.PmdModel;
21 import jp.sourceforge.mikutoga.pmd.model.RigidGroup;
22 import jp.sourceforge.mikutoga.pmd.model.RigidInfo;
23 import jp.sourceforge.mikutoga.pmd.model.RigidShape;
24 import jp.sourceforge.mikutoga.pmd.parser.PmdLimits;
27 * PMDファイルのエクスポーター(拡張3:物理演算対応)。
29 * 物理演算対応のPMDファイルフォーマットを
30 * 使いたい場合はこのエクスポーターを用いて出力せよ。
32 public class PmdExporterExt3 extends PmdExporterExt2{
34 private static final short MASK_FULLCOLLISION = (short) 0xffff;
38 * @param stream 出力ストリーム
39 * @throws NullPointerException 引数がnull
41 public PmdExporterExt3(OutputStream stream)
42 throws NullPointerException{
49 * @param model {@inheritDoc}
50 * @throws IOException {@inheritDoc}
51 * @throws IllegalPmdException {@inheritDoc}
54 public void dumpPmdModel(PmdModel model)
55 throws IOException, IllegalPmdException{
56 super.dumpPmdModel(model);
67 * @throws IOException 出力エラー
68 * @throws IllegalPmdTextException 長すぎる剛体名
70 private void dumpRigidList(PmdModel model)
71 throws IOException, IllegalPmdTextException{
72 List<RigidInfo> rigidList = model.getRigidList();
73 int rigidNum = rigidList.size();
76 for(RigidInfo rigid : rigidList){
88 * @throws IOException 出力エラー
89 * @throws IllegalPmdTextException 長すぎる剛体名
91 private void dumpRigid(RigidInfo rigid)
92 throws IOException, IllegalPmdTextException{
93 String rigidName = rigid.getRigidName().getPrimaryText();
94 dumpText(rigidName, PmdLimits.MAXBYTES_RIGIDNAME);
96 BoneInfo linkedBone = rigid.getLinkedBone();
97 if(linkedBone == null){
100 dumpShort(linkedBone.getSerialNumber());
103 RigidGroup group = rigid.getRigidGroup();
104 dumpByte(group.getSerialNumber());
106 short mask = MASK_FULLCOLLISION;
107 for(RigidGroup throughGroup : rigid.getThroughGroupColl()){
108 int serialId = throughGroup.getSerialNumber();
109 mask &= ~(0x0001 << serialId);
113 dumpRigidShape(rigid.getRigidShape());
115 dumpPos3d(rigid.getPosition());
116 dumpRad3d(rigid.getRotation());
118 dumpDynamics(rigid.getDynamicsInfo());
120 dumpByte(rigid.getBehaviorType().encode());
128 * @throws IOException 出力エラー
130 private void dumpRigidShape(RigidShape shape)
132 RigidShapeType type = shape.getShapeType();
133 dumpByte(type.encode());
135 float width = shape.getWidth();
136 float height = shape.getHeight();
137 float depth = shape.getDepth();
148 * @param dynamics 力学設定
149 * @throws IOException 出力エラー
151 private void dumpDynamics(DynamicsInfo dynamics)
153 float mass = dynamics.getMass();
154 float dampPos = dynamics.getDampingPosition();
155 float dampRot = dynamics.getDampingRotation();
156 float restitution = dynamics.getRestitution();
157 float friction = dynamics.getFriction();
162 dumpFloat(restitution);
170 * @param model モデルデータ
171 * @throws IOException 出力エラー
172 * @throws IllegalPmdTextException 長すぎるジョイント名
174 private void dumpJointList(PmdModel model)
175 throws IOException, IllegalPmdTextException{
176 List<JointInfo> jointList = model.getJointList();
177 int jointNum = jointList.size();
180 for(JointInfo joint : jointList){
192 * @throws IOException 出力エラー
193 * @throws IllegalPmdTextException 長すぎるジョイント名
195 private void dumpJoint(JointInfo joint)
196 throws IOException, IllegalPmdTextException{
197 String jointName = joint.getJointName().getPrimaryText();
198 dumpText(jointName, PmdLimits.MAXBYTES_JOINTNAME);
200 RigidInfo rigidA = joint.getRigidA();
201 RigidInfo rigidB = joint.getRigidB();
203 dumpInt(rigidA.getSerialNumber());
204 dumpInt(rigidB.getSerialNumber());
206 dumpPos3d(joint.getPosition());
207 dumpRad3d(joint.getRotation());
209 dumpTripletRange(joint.getPositionRange());
210 dumpTripletRange(joint.getRotationRange());
212 dumpPos3d(joint.getElasticPosition());
213 dumpDeg3d(joint.getElasticRotation());
220 * @param range 3次元範囲制約
221 * @throws IOException 出力エラー
223 protected void dumpTripletRange(TripletRange range) throws IOException{
224 float xFrom = range.getXFrom();
225 float yFrom = range.getYFrom();
226 float zFrom = range.getZFrom();
232 float xTo = range.getXTo();
233 float yTo = range.getYTo();
234 float zTo = range.getZTo();
244 * ラジアンによる3次元姿勢情報を出力する。
246 * @throws IOException 出力エラー
248 protected void dumpRad3d(Rad3d rad) throws IOException{
249 float xVal = rad.getXRad();
250 float yVal = rad.getYRad();
251 float zVal = rad.getZRad();
261 * 度数法による3次元姿勢情報を出力する。
263 * @throws IOException 出力エラー
265 protected void dumpDeg3d(Deg3d deg) throws IOException{
266 float xVal = deg.getXDeg();
267 float yVal = deg.getYDeg();
268 float zVal = deg.getZDeg();