4 * License : The MIT License
5 * Copyright(c) 2011 MikuToga Partners
8 package jp.sourceforge.mikutoga.vmd.model.binio;
10 import java.io.IOException;
11 import java.io.OutputStream;
12 import jp.sourceforge.mikutoga.binio.BinaryExporter;
13 import jp.sourceforge.mikutoga.binio.IllegalTextExportException;
14 import jp.sourceforge.mikutoga.vmd.IllegalVmdDataException;
15 import jp.sourceforge.mikutoga.vmd.VmdConst;
16 import jp.sourceforge.mikutoga.vmd.model.VmdMotion;
21 public class VmdExporter extends BinaryExporter {
23 private static final byte[] HEADFILLER = {
30 private static final byte[] FDFILLER =
31 { (byte)0x00, (byte)0xfd };
34 private final BasicExporter basicExporter;
35 private final CameraExporter cameraExporter;
36 private final LightingExporter lightingExporter;
41 * @param stream 出力ストリーム
43 public VmdExporter(OutputStream stream){
46 this.basicExporter = new BasicExporter(stream);
47 this.cameraExporter = new CameraExporter(stream);
48 this.lightingExporter = new LightingExporter(stream);
54 * モーションデータをVMDファイル形式で出力する。
55 * <p>異常時には出力データのフラッシュが試みられる。
56 * @param motion モーションデータ
57 * @throws IOException 出力エラー
58 * @throws IllegalVmdDataException モーションデータに不備が発見された
60 public void dumpVmdMotion(VmdMotion motion)
61 throws IOException, IllegalVmdDataException{
63 dumpVmdMotionImpl(motion);
72 * モーションデータをVMDファイル形式で出力する。
73 * @param motion モーションデータ
74 * @throws IOException 出力エラー
75 * @throws IllegalVmdDataException モーションデータに不備が発見された
77 private void dumpVmdMotionImpl(VmdMotion motion)
78 throws IOException, IllegalVmdDataException{
82 dumpModelName(motion);
83 this.basicExporter.dumpBoneMotion(motion);
84 this.basicExporter.dumpMorphMotion(motion);
85 }catch(IllegalTextExportException e){
86 throw new IllegalVmdDataException(e);
89 this.cameraExporter.dumpCameraMotion(motion);
90 this.lightingExporter.dumpLuminousMotion(motion);
91 this.lightingExporter.dumpShadowMotion(motion);
98 * @throws IOException 出力エラー
100 private void dumpHeader() throws IOException{
101 byte[] header = VmdConst.createMagicHeader();
102 dumpByteArray(header);
103 dumpByteArray(HEADFILLER);
105 assert header.length + HEADFILLER.length == VmdConst.HEADER_LENGTH;
113 * 便宜的に{@link VmdConst.MODELNAME_STAGEACT}が使われる。
114 * @param motion モーションデータ
115 * @throws IOException 出力エラー
116 * @throws IllegalTextExportException 不正なモデル名の出現
118 private void dumpModelName(VmdMotion motion)
119 throws IOException, IllegalTextExportException{
120 String modelName = motion.getModelName();
121 if(modelName == null) modelName = VmdConst.MODELNAME_STAGEACT;
123 dumpFixedW31j(modelName, VmdConst.MODELNAME_MAX, FDFILLER);