* Copyright(c) 2010 MikuToga Partners
*/
-package jp.sfjp.mikutoga.pmd.xml101009;
+package jp.sfjp.mikutoga.pmd.xml;
import java.awt.Color;
import java.io.IOException;
import java.io.OutputStream;
import java.util.List;
import java.util.Map;
+import jp.sfjp.mikutoga.pmd.model.BoneGroup;
+import jp.sfjp.mikutoga.pmd.model.BoneInfo;
+import jp.sfjp.mikutoga.pmd.model.DynamicsInfo;
+import jp.sfjp.mikutoga.pmd.model.IKChain;
+import jp.sfjp.mikutoga.pmd.model.JointInfo;
+import jp.sfjp.mikutoga.pmd.model.Material;
+import jp.sfjp.mikutoga.pmd.model.MorphPart;
+import jp.sfjp.mikutoga.pmd.model.MorphVertex;
+import jp.sfjp.mikutoga.pmd.model.PmdModel;
+import jp.sfjp.mikutoga.pmd.model.RigidGroup;
+import jp.sfjp.mikutoga.pmd.model.RigidInfo;
+import jp.sfjp.mikutoga.pmd.model.RigidShape;
+import jp.sfjp.mikutoga.pmd.model.SerialNumbered;
+import jp.sfjp.mikutoga.pmd.model.ShadeInfo;
+import jp.sfjp.mikutoga.pmd.model.Surface;
+import jp.sfjp.mikutoga.pmd.model.ToonMap;
+import jp.sfjp.mikutoga.pmd.model.Vertex;
import jp.sourceforge.mikutoga.corelib.I18nText;
import jp.sourceforge.mikutoga.math.MkPos2D;
import jp.sourceforge.mikutoga.math.MkPos3D;
import jp.sourceforge.mikutoga.pmd.Rad3d;
import jp.sourceforge.mikutoga.pmd.RigidShapeType;
import jp.sourceforge.mikutoga.pmd.TripletRange;
-import jp.sourceforge.mikutoga.pmd.model.BoneGroup;
-import jp.sourceforge.mikutoga.pmd.model.BoneInfo;
-import jp.sourceforge.mikutoga.pmd.model.DynamicsInfo;
-import jp.sourceforge.mikutoga.pmd.model.IKChain;
-import jp.sourceforge.mikutoga.pmd.model.JointInfo;
-import jp.sourceforge.mikutoga.pmd.model.Material;
-import jp.sourceforge.mikutoga.pmd.model.MorphPart;
-import jp.sourceforge.mikutoga.pmd.model.MorphVertex;
-import jp.sourceforge.mikutoga.pmd.model.PmdModel;
-import jp.sourceforge.mikutoga.pmd.model.RigidGroup;
-import jp.sourceforge.mikutoga.pmd.model.RigidInfo;
-import jp.sourceforge.mikutoga.pmd.model.RigidShape;
-import jp.sourceforge.mikutoga.pmd.model.SerialNumbered;
-import jp.sourceforge.mikutoga.pmd.model.ShadeInfo;
-import jp.sourceforge.mikutoga.pmd.model.Surface;
-import jp.sourceforge.mikutoga.pmd.model.ToonMap;
-import jp.sourceforge.mikutoga.pmd.model.Vertex;
import jp.sourceforge.mikutoga.xml.BasicXmlExporter;
import jp.sourceforge.mikutoga.xml.XmlResourceResolver;
/**
* 101009形式XMLでPMDモデルデータを出力する。
*/
-public class Xml101009Exporter extends BasicXmlExporter{
+public class XmlExporter extends BasicXmlExporter{
private static final String TOP_COMMENT =
" MikuMikuDance\n"
private String generator = null;
+ private XmlModelFileType xmlType = XmlModelFileType.XML_101009;
+
+
/**
* コンストラクタ。
* 文字エンコーディングはUTF-8が用いられる。
* @param stream 出力ストリーム
*/
- public Xml101009Exporter(OutputStream stream){
+ public XmlExporter(OutputStream stream){
super(stream);
return;
}
/**
+ * 出力XMLファイル種別を返す。
+ * @return ファイル種別
+ */
+ public XmlModelFileType getXmlFileType(){
+ return this.xmlType;
+ }
+
+ /**
+ * 出力XMLファイル種別を設定する。
+ * @param type ファイル種別
+ */
+ public void setXmlFileType(XmlModelFileType type){
+ switch(type){
+ case XML_101009:
+ case XML_130128:
+ this.xmlType = type;
+ break;
+ case XML_AUTO:
+ this.xmlType = XmlModelFileType.XML_130128;
+ break;
+ default:
+ throw new IllegalArgumentException();
+ }
+
+ assert this.xmlType == XmlModelFileType.XML_101009
+ || this.xmlType == XmlModelFileType.XML_130128;
+
+ return;
+ }
+
+ /**
* Generatorメタ情報を設定する。
* @param generatorArg Generatorメタ情報。表示したくないときはnull
*/
* @throws IOException {@inheritDoc}
*/
@Override
- public Xml101009Exporter ind() throws IOException{
+ public XmlExporter ind() throws IOException{
super.ind();
return this;
}
* @return this本体
* @throws IOException 出力エラー
*/
- protected Xml101009Exporter putUnescapedComment(CharSequence seq)
+ protected XmlExporter putUnescapedComment(CharSequence seq)
throws IOException{
if( ! isBasicLatinOnlyOut() ) return this;
if(hasOnlyBasicLatin(seq)) return this;
* @return this本体
* @throws IOException 出力エラー
*/
- protected Xml101009Exporter putI18nName(I18nText text) throws IOException{
+ protected XmlExporter putI18nName(I18nText text) throws IOException{
for(String lang639 : text.lang639CodeList()){
if(lang639.equals(I18nText.CODE639_PRIMARY)) continue;
String name = text.getI18nText(lang639);
* @return this本体
* @throws IOException 出力エラー
*/
- protected Xml101009Exporter putNumberedIdAttr(CharSequence attrName,
+ protected XmlExporter putNumberedIdAttr(CharSequence attrName,
CharSequence prefix,
int num )
throws IOException{
* @return this本体
* @throws IOException 出力エラー
*/
- protected Xml101009Exporter putNumberedIdAttr(CharSequence attrName,
+ protected XmlExporter putNumberedIdAttr(CharSequence attrName,
CharSequence prefix,
SerialNumbered numbered )
throws IOException{
* @return this本体
* @throws IOException 出力エラー
*/
- protected Xml101009Exporter putPosition(MkPos3D position)
+ protected XmlExporter putPosition(MkPos3D position)
throws IOException{
putRawText("<position ");
putFloatAttr("x", (float) position.getXpos()).sp();
* @return this本体
* @throws IOException 出力エラー
*/
- protected Xml101009Exporter putRadRotation(Rad3d rotation)
+ protected XmlExporter putRadRotation(Rad3d rotation)
throws IOException{
putRawText("<radRotation ");
putFloatAttr("xRad", rotation.getXRad()).sp();
* @return this本体
* @throws IOException 出力エラー
*/
- protected Xml101009Exporter putLocalNameComment(I18nText name)
+ protected XmlExporter putLocalNameComment(I18nText name)
throws IOException{
String localName = name.getText();
if(localName.isEmpty()){
* @return this本体
* @throws IOException 出力エラー
*/
- protected Xml101009Exporter putPrimaryNameAttr(CharSequence attrName,
+ protected XmlExporter putPrimaryNameAttr(CharSequence attrName,
I18nText name)
throws IOException{
String primaryName = name.getPrimaryText();
ind().putRawText("<pmdModel").ln();
pushNest();
- ind().putAttr("xmlns", Xml101009Resources.NS_PMDXML).ln();
+ String defns;
+ String xsduri;
+ String version;
+ if(this.xmlType == XmlModelFileType.XML_101009){
+ defns = Schema101009.NS_PMDXML;
+ xsduri = Schema101009.SCHEMA_PMDXML;
+ version = Schema101009.VER_PMDXML;
+ }else if(this.xmlType == XmlModelFileType.XML_130128){
+ defns = Schema130128.NS_PMDXML;
+ xsduri = Schema130128.SCHEMA_PMDXML;
+ version = Schema130128.VER_PMDXML;
+ }else{
+ assert false;
+ throw new AssertionError();
+ }
+
+ ind().putAttr("xmlns", defns).ln();
+
ind().putAttr("xmlns:xsi", XmlResourceResolver.NS_XSD).ln();
ind().putRawText("xsi:schemaLocation").putRawText("=\"");
- putRawText(Xml101009Resources.NS_PMDXML).ln();
+ putRawText(defns).ln();
pushNest();
- ind().putRawText(Xml101009Resources.SCHEMA_PMDXML).putRawCh('"').ln();
+ ind().putRawText(xsduri).putRawCh('"').ln();
popNest();
- ind().putAttr("schemaVersion", Xml101009Resources.VER_PMDXML).ln(2);
+ ind().putAttr("schemaVersion", version).ln(2);
ind().putPrimaryNameAttr("name", modelName).ln();
popNest();
* @return this本体
* @throws IOException 出力エラー
*/
- private Xml101009Exporter putModelInfo(PmdModel model)
+ private XmlExporter putModelInfo(PmdModel model)
throws IOException{
I18nText modelName = model.getModelName();
putI18nName(modelName);
* @return this本体
* @throws IOException 出力エラー
*/
- private Xml101009Exporter putDescription(CharSequence lang639,
+ private XmlExporter putDescription(CharSequence lang639,
CharSequence content)
throws IOException{
String text = content.toString();
* @return this本体
* @throws IOException 出力エラー
*/
- private Xml101009Exporter putMetaInfo(PmdModel model) throws IOException{
+ private XmlExporter putMetaInfo(PmdModel model) throws IOException{
ind().putRawText("<license>").ln();
ind().putRawText("</license>").ln(2);
* @return this本体
* @throws IOException 出力エラー
*/
- private Xml101009Exporter putMaterialList(PmdModel model)
+ private XmlExporter putMaterialList(PmdModel model)
throws IOException{
ind().putRawText("<materialList>").ln();
* @return this本体
* @throws IOException 出力エラー
*/
- private Xml101009Exporter putMaterial(Material material, int no)
+ private XmlExporter putMaterial(Material material, int no)
throws IOException{
String bool;
if(material.getEdgeAppearance()) bool = "true";
* @return this本体
* @throws IOException 出力エラー
*/
- private Xml101009Exporter putToonMap(PmdModel model)
+ private XmlExporter putToonMap(PmdModel model)
throws IOException{
ind().putRawText("<toonMap>").ln();
pushNest();
* @return this本体
* @throws IOException 出力エラー
*/
- private Xml101009Exporter putToon(ToonMap map, int index)
+ private XmlExporter putToon(ToonMap map, int index)
throws IOException{
putRawText("<toonDef ");
putNumberedIdAttr("toonFileId", PFX_TOONFILE, index).sp();
* @return this本体
* @throws IOException 出力エラー
*/
- private Xml101009Exporter putSurfaceGroupList(PmdModel model)
+ private XmlExporter putSurfaceGroupList(PmdModel model)
throws IOException{
ind().putRawText("<surfaceGroupList>").ln();
* @return this本体
* @throws IOException 出力エラー
*/
- private Xml101009Exporter putSurfaceList(List<Surface> surfaceList,
+ private XmlExporter putSurfaceList(List<Surface> surfaceList,
int index)
throws IOException{
ind().putRawText("<surfaceGroup ");
* @return this本体
* @throws IOException 出力エラー
*/
- private Xml101009Exporter putSurface(Surface surface)
+ private XmlExporter putSurface(Surface surface)
throws IOException{
ind().putRawText("<surface ");
* @return this本体
* @throws IOException 出力エラー
*/
- private Xml101009Exporter putVertexList(PmdModel model)
+ private XmlExporter putVertexList(PmdModel model)
throws IOException{
ind().putRawText("<vertexList>").ln();
* @return this本体
* @throws IOException 出力エラー
*/
- private Xml101009Exporter putVertex(Vertex vertex)
+ private XmlExporter putVertex(Vertex vertex)
throws IOException{
String bool;
if(vertex.getEdgeAppearance()) bool = "true";
* @return this本体
* @throws IOException 出力エラー
*/
- private Xml101009Exporter putBoneList(PmdModel model)
+ private XmlExporter putBoneList(PmdModel model)
throws IOException{
ind().putRawText("<boneList>").ln();
pushNest();
* @return this本体
* @throws IOException 出力エラー
*/
- private Xml101009Exporter putBone(BoneInfo bone)
+ private XmlExporter putBone(BoneInfo bone)
throws IOException{
I18nText i18nName = bone.getBoneName();
BoneType type = bone.getBoneType();
MkPos3D position = bone.getPosition();
ind().putPosition(position).ln();
- BoneInfo ikBone = bone.getIKBone();
+ BoneInfo srcBone = bone.getSrcBone();
if(bone.getBoneType() == BoneType.LINKEDROT){
ind().putRawText("<rotationRatio ");
putIntAttr("ratio", bone.getRotationRatio());
putRawText(" />").ln();
- }else if(ikBone != null){
- ind().putRawText("<ikBone ");
- putNumberedIdAttr("boneIdRef", PFX_BONE, ikBone);
+ }else if(srcBone != null){
+ String iktag;
+ switch(getXmlFileType()){
+ case XML_101009:
+ iktag = "<ikBone ";
+ break;
+ case XML_130128:
+ iktag = "<sourceBone ";
+ break;
+ default:
+ assert false;
+ throw new AssertionError();
+ }
+ ind().putRawText(iktag);
+ putNumberedIdAttr("boneIdRef", PFX_BONE, srcBone);
putRawText(" /> ");
- String ikBoneName = "Ref:" + ikBone.getBoneName().getText();
+ String ikBoneName = "Ref:" + srcBone.getBoneName().getText();
putLineComment(ikBoneName);
ln();
}
* @return this本体
* @throws IOException 出力エラー
*/
- private Xml101009Exporter putBoneGroupList(PmdModel model)
+ private XmlExporter putBoneGroupList(PmdModel model)
throws IOException{
ind().putRawText("<boneGroupList>").ln();
* @return this本体
* @throws IOException 出力エラー
*/
- private Xml101009Exporter putBoneGroup(BoneGroup group)
+ private XmlExporter putBoneGroup(BoneGroup group)
throws IOException{
I18nText i18nName = group.getGroupName();
* @return this本体
* @throws IOException 出力エラー
*/
- private Xml101009Exporter putIKChainList(PmdModel model)
+ private XmlExporter putIKChainList(PmdModel model)
throws IOException{
ind().putRawText("<ikChainList>").ln();
* @return this本体
* @throws IOException 出力エラー
*/
- private Xml101009Exporter putIKChain(IKChain chain)
+ private XmlExporter putIKChain(IKChain chain)
throws IOException{
int depth = chain.getIKDepth();
float weight = chain.getIKWeight();
* @return this本体
* @throws IOException 出力エラー
*/
- private Xml101009Exporter putMorphList(PmdModel model)
+ private XmlExporter putMorphList(PmdModel model)
throws IOException{
ind().putRawText("<morphList>").ln();
pushNest();
* @return this本体
* @throws IOException 出力エラー
*/
- private Xml101009Exporter putMorphPart(MorphPart part)
+ private XmlExporter putMorphPart(MorphPart part)
throws IOException{
I18nText i18nName = part.getMorphName();
String primary = i18nName.getPrimaryText();
* @return this本体
* @throws IOException 出力エラー
*/
- private Xml101009Exporter putRigidList(PmdModel model)
+ private XmlExporter putRigidList(PmdModel model)
throws IOException{
ind().putRawText("<rigidList>").ln();
pushNest();
* @return this本体
* @throws IOException 出力エラー
*/
- private Xml101009Exporter putRigid(RigidInfo rigid)
+ private XmlExporter putRigid(RigidInfo rigid)
throws IOException{
BoneInfo linkedBone = rigid.getLinkedBone();
I18nText i18nName = rigid.getRigidName();
* @return this本体
* @throws IOException 出力エラー
*/
- private Xml101009Exporter putRigidShape(RigidShape shape)
+ private XmlExporter putRigidShape(RigidShape shape)
throws IOException{
RigidShapeType type = shape.getShapeType();
* @return this本体
* @throws IOException 出力エラー
*/
- private Xml101009Exporter putDynamics(DynamicsInfo dynamics)
+ private XmlExporter putDynamics(DynamicsInfo dynamics)
throws IOException{
ind().putRawText("<dynamics").ln();
pushNest();
* @return this本体
* @throws IOException 出力エラー
*/
- private Xml101009Exporter putRigidGroupList(PmdModel model)
+ private XmlExporter putRigidGroupList(PmdModel model)
throws IOException{
ind().putRawText("<rigidGroupList>").ln(2);
pushNest();
* @return this本体
* @throws IOException 出力エラー
*/
- private Xml101009Exporter putJointList(PmdModel model)
+ private XmlExporter putJointList(PmdModel model)
throws IOException{
ind().putRawText("<jointList>").ln();
* @return this本体
* @throws IOException 出力エラー
*/
- private Xml101009Exporter putJoint(JointInfo joint)
+ private XmlExporter putJoint(JointInfo joint)
throws IOException{
I18nText i18nName = joint.getJointName();