import java.util.List;
import java.util.Map;
import java.util.Set;
+import jp.sourceforge.mikutoga.binio.BinaryExporter;
+import jp.sourceforge.mikutoga.binio.IllegalTextExportException;
import jp.sourceforge.mikutoga.math.MkPos2D;
import jp.sourceforge.mikutoga.math.MkPos3D;
import jp.sourceforge.mikutoga.math.MkVec3D;
* 英名対応以降のPMDファイルフォーマットを
* 使いたくない場合はこのエクスポーターを用いて出力せよ。
*/
-public class PmdExporterBase extends AbstractExporter{
+public class PmdExporterBase extends BinaryExporter{
/** 前(親)ボーンが無い場合の便宜的なボーンID。 */
public static final int NOPREVBONE_ID = 0xffff;
* 指定バイト長をはみ出した。
*/
protected void dumpText(String text, int maxByteLength)
- throws IOException, IllegalPmdTextException{
- dumpText(text, maxByteLength, FDFILLER);
- return;
- }
-
- /**
- * 文字列を指定されたバイト長で出力する。
- * 文字列の改行記号はLF(0x0a)に正規化される。
- * エンコード結果がバイト長に満たない場合は
- * fillerがパディングされる。
- * @param text 文字列
- * @param maxByteLength バイト超指定
- * @param filler 出力結果が足りない場合の詰め物。
- * それでも足りない場合は最後のbyte要素が繰り返し出力される。
- * @throws IOException 出力エラー
- * @throws IllegalPmdTextException エンコード結果が
- * 指定バイト長をはみ出した
- */
- protected void dumpText(String text, int maxByteLength, byte[] filler)
- throws IOException, IllegalPmdTextException{
- String normalized = normalizeBreak(text);
- int blen = dumpCharSequence(normalized);
- int remain = maxByteLength - blen;
-
- if(remain < 0) throw new IllegalPmdTextException("too long text");
-
- int fillerIdx = 0;
- while(remain > 0){
- if(fillerIdx >= filler.length){
- fillerIdx = filler.length - 1;
- }
- dumpByte(filler[fillerIdx]);
- fillerIdx++;
- remain--;
- }
-
+ throws IOException, IllegalTextExportException{
+ dumpFixedW31j(text, maxByteLength, FDFILLER);
return;
}
*/
public void dumpPmdModel(PmdModel model)
throws IOException, IllegalPmdException{
- dumpBasic(model);
- dumpVertexList(model);
- dumpSurfaceList(model);
- dumpMaterialList(model);
- dumpBoneList(model);
- dumpIKChainList(model);
- dumpMorphList(model);
- dumpMorphGroup(model);
- dumpBoneGroupList(model);
+ try{
+ dumpBasic(model);
+ dumpVertexList(model);
+ dumpSurfaceList(model);
+ dumpMaterialList(model);
+ dumpBoneList(model);
+ dumpIKChainList(model);
+ dumpMorphList(model);
+ dumpMorphGroup(model);
+ dumpBoneGroupList(model);
+ }catch(IllegalTextExportException e){
+ throw new IllegalPmdException(e);
+ }
return;
}
* @throws IllegalPmdTextException モデル名もしくは説明が長すぎる
*/
private void dumpBasic(PmdModel model)
- throws IOException, IllegalPmdTextException{
+ throws IOException, IllegalTextExportException{
for(int idx=0; idx < MAGIC_BYTES.length; idx++){
dumpByte(MAGIC_BYTES[idx]);
}
* @throws IllegalPmdTextException シェーディングファイル情報が長すぎる
*/
private void dumpMaterialList(PmdModel model)
- throws IOException, IllegalPmdTextException{
+ throws IOException, IllegalTextExportException{
List<Material> materialList = model.getMaterialList();
int materialNum = materialList.size();
* シェーディングファイル情報を出力する。
* @param shade シェーディング情報
* @throws IOException 出力エラー
- * @throws IllegalPmdTextException ファイル名が長すぎる
+ * @throws IllegalTextExportException ファイル名が長すぎる
*/
private void dumpShadeFileInfo(ShadeInfo shade)
- throws IOException, IllegalPmdTextException{
+ throws IOException, IllegalTextExportException{
String textureFile = shade.getTextureFileName();
String spheremapFile = shade.getSpheremapFileName();
if(text.length() <= 0) filler = NULLFILLER;
else filler = FDFILLER;
- dumpText(text.toString(),
- PmdLimits.MAXBYTES_TEXTUREFILENAME,
- filler );
+ dumpFixedW31j(text.toString(),
+ PmdLimits.MAXBYTES_TEXTUREFILENAME,
+ filler );
return;
}
* @throws IllegalPmdTextException ボーン名が長すぎる
*/
private void dumpBoneList(PmdModel model)
- throws IOException, IllegalPmdTextException{
+ throws IOException, IllegalTextExportException{
List<BoneInfo> boneList = model.getBoneList();
int boneNum = boneList.size();
* @throws IllegalPmdTextException ボーン名が長すぎる
*/
private void dumpBone(BoneInfo bone)
- throws IOException, IllegalPmdTextException{
+ throws IOException, IllegalTextExportException{
String boneName = bone.getBoneName().getPrimaryText();
dumpText(boneName, PmdLimits.MAXBYTES_BONENAME);
* @throws IllegalPmdTextException モーフ名が長すぎる
*/
private void dumpMorphList(PmdModel model)
- throws IOException, IllegalPmdTextException{
+ throws IOException, IllegalTextExportException{
Map<MorphType, List<MorphPart>> morphMap = model.getMorphMap();
Set<MorphType> typeSet = morphMap.keySet();
List<MorphVertex> mergedMorphVertexList = model.mergeMorphVertex();
* デフォルトボーングループ内訳は出力されない。
* @param model モデルデータ
* @throws IOException 出力エラー
- * @throws IllegalPmdTextException ボーングループ名が長すぎる
+ * @throws IllegalTextExportException ボーングループ名が長すぎる
*/
private void dumpBoneGroupList(PmdModel model)
- throws IOException, IllegalPmdTextException{
+ throws IOException, IllegalTextExportException{
List<BoneGroup> groupList = model.getBoneGroupList();
int groupNum = groupList.size();
dumpByte(groupNum - 1);
int dispBoneNum = 0;
for(BoneGroup group : groupList){
if(group.isDefaultBoneGroup()) continue;
- dumpText(group.getGroupName().getPrimaryText(),
- PmdLimits.MAXBYTES_BONEGROUPNAME, LFFILLER );
+ dumpFixedW31j(group.getGroupName().getPrimaryText(),
+ PmdLimits.MAXBYTES_BONEGROUPNAME, LFFILLER );
dispBoneNum += group.getBoneList().size();
}
dumpInt(dispBoneNum);