public static void ExportToCOLLADA(Scene scene, string fileName) { String strTemplate = Resources.COLLADA_Exporter_Template_Papier; strTemplate = strTemplate.Replace("{DATETIME}", DateTime.Now.ToString()); List<Folding> listFoldings = GetFoldings(scene); int indexStart = strTemplate.IndexOf("{MODEL}"); int indexEnd = strTemplate.IndexOf("{/MODEL}"); string strSubTemplate = strTemplate.Substring(indexStart + 7, indexEnd - indexStart - 7); StringBuilder strFile = new StringBuilder(); strFile.Append(strTemplate.Substring(0, indexStart)); float d = 40f; float dh = d; for (int i = 0; i < listFoldings.Count + 1; i++) { string strFoldingModel = strSubTemplate; if (i < listFoldings.Count) { Folding folding = listFoldings[i]; strFoldingModel = strFoldingModel.Replace("{ARMATURE_NAME}", "Armature_" + i.ToString()); strFoldingModel = strFoldingModel.Replace("{FOLDING_NAME}", "Folding_" + i.ToString()); strFoldingModel = ReplaceValue(strFoldingModel, "{P0.X}", (float)folding.Location.X / d); strFoldingModel = ReplaceValue(strFoldingModel, "{P0.Z}", (float)-folding.Location.Y / d + folding.Height / d); strFoldingModel = ReplaceValue(strFoldingModel, "{P0.Y}", (float)-folding.Height / d); strFoldingModel = ReplaceValue(strFoldingModel, "{P1.X}", (float)folding.Location.X / d + (float)folding.Width / d); strFoldingModel = ReplaceValue(strFoldingModel, "{P1.Z}", (float)-folding.Location.Y / d + folding.Height / d); strFoldingModel = ReplaceValue(strFoldingModel, "{P1.Y}", (float)-folding.Height / dh); strFoldingModel = ReplaceValue(strFoldingModel, "{P2.X}", (float)folding.Location.X / d + (float)folding.Width / d); strFoldingModel = ReplaceValue(strFoldingModel, "{P2.Z}", (0)); strFoldingModel = ReplaceValue(strFoldingModel, "{P2.Y}", (float)-folding.Height / dh); strFoldingModel = ReplaceValue(strFoldingModel, "{P3.X}", (float)folding.Location.X / d); strFoldingModel = ReplaceValue(strFoldingModel, "{P3.Z}", (0)); strFoldingModel = ReplaceValue(strFoldingModel, "{P3.Y}", (float)-folding.Height / dh); strFoldingModel = ReplaceValue(strFoldingModel, "{P4.X}", (float)folding.Location.X / d); strFoldingModel = ReplaceValue(strFoldingModel, "{P4.Z}", (float)-folding.Location.Y / d + folding.Height / d); strFoldingModel = ReplaceValue(strFoldingModel, "{P4.Y}", (0)); strFoldingModel = ReplaceValue(strFoldingModel, "{P5.X}", (float)folding.Location.X / d + (float)folding.Width / d); strFoldingModel = ReplaceValue(strFoldingModel, "{P5.Z}", (float)-folding.Location.Y / d + folding.Height / d); strFoldingModel = ReplaceValue(strFoldingModel, "{P5.Y}", (0)); } else { strFoldingModel = strFoldingModel.Replace("{ARMATURE_NAME}", "Armature_" + i.ToString()); strFoldingModel = strFoldingModel.Replace("{FOLDING_NAME}", "Folding_" + i.ToString()); strFoldingModel = ReplaceValue(strFoldingModel, "{P1.X}", 0); //0 strFoldingModel = ReplaceValue(strFoldingModel, "{P1.Z}", 0f); strFoldingModel = ReplaceValue(strFoldingModel, "{P1.Y}", 0f); strFoldingModel = ReplaceValue(strFoldingModel, "{P0.X}", 20f); //1 strFoldingModel = ReplaceValue(strFoldingModel, "{P0.Z}", 0f); strFoldingModel = ReplaceValue(strFoldingModel, "{P0.Y}", 0f); strFoldingModel = ReplaceValue(strFoldingModel, "{P2.X}", 0f); //2 strFoldingModel = ReplaceValue(strFoldingModel, "{P2.Z}", 20f); strFoldingModel = ReplaceValue(strFoldingModel, "{P2.Y}", 0f); strFoldingModel = ReplaceValue(strFoldingModel, "{P3.X}", 20f); //3 strFoldingModel = ReplaceValue(strFoldingModel, "{P3.Z}", 20f); strFoldingModel = ReplaceValue(strFoldingModel, "{P3.Y}", 0f); strFoldingModel = ReplaceValue(strFoldingModel, "{P4.X}", 20f); strFoldingModel = ReplaceValue(strFoldingModel, "{P4.Z}", 0f); strFoldingModel = ReplaceValue(strFoldingModel, "{P4.Y}", -20f); strFoldingModel = ReplaceValue(strFoldingModel, "{P5.X}", 0f); strFoldingModel = ReplaceValue(strFoldingModel, "{P5.Z}", 0f); strFoldingModel = ReplaceValue(strFoldingModel, "{P5.Y}", -20f); } strFile.AppendLine(); strFile.Append(strFoldingModel); } int indexStart3 = strTemplate.IndexOf("{SCENE}"); int indexEnd3 = strTemplate.IndexOf("{/SCENE}"); strSubTemplate = strTemplate.Substring(indexStart3 + 7, indexEnd3 - indexStart3 - 7); strFile.Append(strTemplate.Substring(indexEnd + 8, indexStart3 - indexEnd - 8)); for (int i = 0; i < listFoldings.Count + 1; i++) { string strFoldingModel = strSubTemplate; //strFoldingModel = strFoldingModel.Replace("{ARMATURE_NAME}", "Armature_" + nbFolding.ToString()); strFoldingModel = strFoldingModel.Replace("{FOLDING_NAME}", "Folding_" + i.ToString()); //strFoldingModel = strFoldingModel.Replace("{BONE1_NAME}", "Bone_" + (nbFolding * 2).ToString()); //strFoldingModel = strFoldingModel.Replace("{BONE2_NAME}", "Bone_" + (nbFolding * 2 + 1).ToString()); strFile.AppendLine(); strFile.Append(strFoldingModel); } strFile.Append(strTemplate.Substring(indexEnd3 + 8)); File.WriteAllText(fileName, strFile.ToString()); }
private static List<Folding> GetFoldings(Scene scene) { List<Folding> listFoldings = new List<Folding>(); foreach (ComponentBase componenent in scene.listComponent) { if (componenent is Folding) { listFoldings.Add((Folding)componenent); } } return listFoldings; }
public static void ExportToCOLLADA2(Scene scene, string fileName) { String strTemplate = Resources.COLLADA_Exporter_Template_Papier2; strTemplate = strTemplate.Replace("{DATETIME}", DateTime.Now.ToString()); List<Folding> listFoldings = GetFoldings(scene); int indexStart = strTemplate.IndexOf("{MODEL}"); int indexEnd = strTemplate.IndexOf("{/MODEL}"); string strSubTemplate = strTemplate.Substring(indexStart + 7, indexEnd - indexStart - 7); StringBuilder strFile = new StringBuilder(); strFile.Append(strTemplate.Substring(0, indexStart)); float d = 40f; float dh = d; for (int i = 0; i < listFoldings.Count + 1; i++) { string strFoldingModel = strSubTemplate; if (i < listFoldings.Count) { Folding folding = listFoldings[i]; strFoldingModel = strFoldingModel.Replace("{ARMATURE_NAME}", "Armature_" + i.ToString()); strFoldingModel = strFoldingModel.Replace("{FOLDING_NAME}", "Folding_" + i.ToString()); //---- List<Vertex> listVertex = new List<Vertex>(); List<int> listVertexIndex = new List<int>(); ComputeVertexCuttingFace(folding.CuttingFace, ref listVertex, ref listVertexIndex); int t = listVertexIndex.Count; ComputeVertexCuttingTop(folding.CuttingTop, ref listVertex, ref listVertexIndex); string FOLDING_FACE_CONFIGURATION = String.Empty; string FOLDING_VERTEX_NORMAL_INDEX = String.Empty; string FOLDING_VERTEX = String.Empty; for (int j = 0; j < listVertex.Count; j++) { Vertex vertex = listVertex[j]; FOLDING_VERTEX += vertex.ToString() + " "; } for (int j = 0; j < listVertexIndex.Count; j++) { if (j % 4 == 0) FOLDING_FACE_CONFIGURATION += "4 "; FOLDING_VERTEX_NORMAL_INDEX += listVertexIndex[j] + (j < t ? " 0 " : " 1 "); } //----- strFoldingModel = strFoldingModel.Replace("{FOLDING_VERTEX_COUNT}", (listVertex.Count * 3).ToString()); strFoldingModel = strFoldingModel.Replace("{FOLDING_VERTEX_COUNT_DIV3}", listVertex.Count.ToString()); strFoldingModel = strFoldingModel.Replace("{FOLDING_FACE_COUNT}", (listVertexIndex.Count / 4).ToString()); strFoldingModel = strFoldingModel.Replace("{FOLDING_VERTEX}", FOLDING_VERTEX); strFoldingModel = strFoldingModel.Replace("{FOLDING_FACE_CONFIGURATION}", FOLDING_FACE_CONFIGURATION); strFoldingModel = strFoldingModel.Replace("{FOLDING_VERTEX_NORMAL_INDEX}", FOLDING_VERTEX_NORMAL_INDEX); } else { strFoldingModel = strFoldingModel.Replace("{ARMATURE_NAME}", "Armature_" + i.ToString()); strFoldingModel = strFoldingModel.Replace("{FOLDING_NAME}", "Folding_" + i.ToString()); //---- List<Vertex> listVertex = new List<Vertex>(); List<int> listVertexIndex = new List<int>(); ComputeVertexCuttingFace(scene.CuttingFront, ref listVertex, ref listVertexIndex); int t = listVertexIndex.Count; ComputeVertexCuttingTop(scene.CuttingTop, ref listVertex, ref listVertexIndex); string FOLDING_FACE_CONFIGURATION = String.Empty; string FOLDING_VERTEX_NORMAL_INDEX = String.Empty; string FOLDING_VERTEX = String.Empty; for (int j = 0; j < listVertex.Count; j++) { Vertex vertex = listVertex[j]; FOLDING_VERTEX += vertex.ToString() + " "; } for (int j = 0; j < listVertexIndex.Count; j++) { if (j % 4 == 0) FOLDING_FACE_CONFIGURATION += "4 "; FOLDING_VERTEX_NORMAL_INDEX += listVertexIndex[j] + (j < t ? " 0 " : " 1 "); } //----- strFoldingModel = strFoldingModel.Replace("{FOLDING_VERTEX_COUNT}", (listVertex.Count * 3).ToString()); strFoldingModel = strFoldingModel.Replace("{FOLDING_VERTEX_COUNT_DIV3}", listVertex.Count.ToString()); strFoldingModel = strFoldingModel.Replace("{FOLDING_FACE_COUNT}", (listVertexIndex.Count / 4).ToString()); strFoldingModel = strFoldingModel.Replace("{FOLDING_VERTEX}", FOLDING_VERTEX); strFoldingModel = strFoldingModel.Replace("{FOLDING_FACE_CONFIGURATION}", FOLDING_FACE_CONFIGURATION); strFoldingModel = strFoldingModel.Replace("{FOLDING_VERTEX_NORMAL_INDEX}", FOLDING_VERTEX_NORMAL_INDEX); } strFile.AppendLine(); strFile.Append(strFoldingModel); } int indexStart3 = strTemplate.IndexOf("{SCENE}"); int indexEnd3 = strTemplate.IndexOf("{/SCENE}"); strSubTemplate = strTemplate.Substring(indexStart3 + 7, indexEnd3 - indexStart3 - 7); strFile.Append(strTemplate.Substring(indexEnd + 8, indexStart3 - indexEnd - 8)); for (int i = 0; i < listFoldings.Count + 1; i++) { string strFoldingModel = strSubTemplate; //strFoldingModel = strFoldingModel.Replace("{ARMATURE_NAME}", "Armature_" + nbFolding.ToString()); strFoldingModel = strFoldingModel.Replace("{FOLDING_NAME}", "Folding_" + i.ToString()); //strFoldingModel = strFoldingModel.Replace("{BONE1_NAME}", "Bone_" + (nbFolding * 2).ToString()); //strFoldingModel = strFoldingModel.Replace("{BONE2_NAME}", "Bone_" + (nbFolding * 2 + 1).ToString()); strFile.AppendLine(); strFile.Append(strFoldingModel); } strFile.Append(strTemplate.Substring(indexEnd3 + 8)); File.WriteAllText(fileName, strFile.ToString()); }
public static void ExportToFBX(Scene scene, string fileName) { String strTemplate = Resources.FBX_Exporter_Template_Papier; strTemplate = strTemplate.Replace("{YEAR}", DateTime.Now.Year.ToString()); strTemplate = strTemplate.Replace("{MONTH}", DateTime.Now.Month.ToString()); strTemplate = strTemplate.Replace("{DAY}", DateTime.Now.Day.ToString()); strTemplate = strTemplate.Replace("{HOUR}", DateTime.Now.Hour.ToString()); strTemplate = strTemplate.Replace("{MINUTE}", DateTime.Now.Minute.ToString()); strTemplate = strTemplate.Replace("{SECOND}", DateTime.Now.Second.ToString()); strTemplate = strTemplate.Replace("{MILLISECOND}", DateTime.Now.Millisecond.ToString()); strTemplate = strTemplate.Replace("{DATETIME}", DateTime.Now.ToString()); List<Folding> listFoldings = GetFoldings(scene); strTemplate = strTemplate.Replace("{OBJECT_COUNT}", (listFoldings.Count * 6 + 2).ToString()); strTemplate = strTemplate.Replace("{MODEL_COUNT}", (listFoldings.Count * 4).ToString()); strTemplate = strTemplate.Replace("{GEOMETRY_COUNT}", (listFoldings.Count).ToString()); strTemplate = strTemplate.Replace("{DEFORMER_COUNT}", (listFoldings.Count * 3).ToString()); int indexStart = strTemplate.IndexOf("{MODEL}"); int indexEnd = strTemplate.IndexOf("{/MODEL}"); string strSubTemplate = strTemplate.Substring(indexStart + 7, indexEnd - indexStart - 7); StringBuilder strFile = new StringBuilder(); strFile.Append(strTemplate.Substring(0, indexStart)); float d = 40f; int nbFolding = 0; foreach (Folding folding in listFoldings) { string strFoldingModel = strSubTemplate; strFoldingModel = strFoldingModel.Replace("{ARMATURE_NAME}", "Armature_" + nbFolding.ToString()); strFoldingModel = strFoldingModel.Replace("{FOLDING_NAME}", "Folding_" + nbFolding.ToString()); strFoldingModel = ReplaceValue(strFoldingModel, "{P0.X}", (float)folding.Location.X / d); strFoldingModel = ReplaceValue(strFoldingModel, "{P0.X}", (float)folding.Location.X / d); strFoldingModel = ReplaceValue(strFoldingModel, "{P0.Y}", (float)folding.Location.Y / d); strFoldingModel = ReplaceValue(strFoldingModel, "{P0.Z}", (float)folding.Height / d); strFoldingModel = ReplaceValue(strFoldingModel, "{P1.X}", (float)folding.Location.X / d + (float)folding.Width / d); strFoldingModel = ReplaceValue(strFoldingModel, "{P1.Y}", (float)folding.Location.Y / d); strFoldingModel = ReplaceValue(strFoldingModel, "{P1.Z}", (float)folding.Height / d); strFoldingModel = ReplaceValue(strFoldingModel, "{P2.X}", (float)folding.Location.X / d + (float)folding.Width / d); strFoldingModel = ReplaceValue(strFoldingModel, "{P2.Y}", (0)); strFoldingModel = ReplaceValue(strFoldingModel, "{P2.Z}", (float)folding.Height / d); strFoldingModel = ReplaceValue(strFoldingModel, "{P3.X}", (float)folding.Location.X / d); strFoldingModel = ReplaceValue(strFoldingModel, "{P3.Y}", (0)); strFoldingModel = ReplaceValue(strFoldingModel, "{P3.Z}", (float)folding.Height / d); strFoldingModel = ReplaceValue(strFoldingModel, "{P4.X}", (float)folding.Location.X / d); strFoldingModel = ReplaceValue(strFoldingModel, "{P4.Y}", (float)folding.Location.Y / d); strFoldingModel = ReplaceValue(strFoldingModel, "{P4.Z}", (0)); strFoldingModel = ReplaceValue(strFoldingModel, "{P5.X}", (float)folding.Location.X / d + (float)folding.Width / d); strFoldingModel = ReplaceValue(strFoldingModel, "{P5.Y}", (float)folding.Location.Y / d); strFoldingModel = ReplaceValue(strFoldingModel, "{P5.Z}", (0)); strFoldingModel = strFoldingModel.Replace("{BONE1_NAME}", "Bone_" + (nbFolding * 2).ToString()); strFoldingModel = ReplaceValue(strFoldingModel, "{FOLDING_DEEP}", (float)folding.Height / d); strFoldingModel = ReplaceValue(strFoldingModel, "{FOLDING_HEIGHT}", (float)folding.Location.Y / d); strFoldingModel = strFoldingModel.Replace("{BONE2_NAME}", "Bone_" + (nbFolding * 2 + 1).ToString()); strFile.AppendLine(); strFile.Append(strFoldingModel); nbFolding++; } int indexStart2 = strTemplate.IndexOf("{POSE}"); int indexEnd2 = strTemplate.IndexOf("{/POSE}"); strSubTemplate = strTemplate.Substring(indexStart2 + 6, indexEnd2 - indexStart2 - 6); strFile.Append(strTemplate.Substring(indexEnd + 8, indexStart2 - indexEnd - 8)); strFile = strFile.Replace("{POSE_COUNT}", (nbFolding * 4).ToString()); nbFolding = 0; foreach (Folding folding in listFoldings) { string strFoldingModel = strSubTemplate; strFoldingModel = strFoldingModel.Replace("{ARMATURE_NAME}", "Armature_" + nbFolding.ToString()); strFoldingModel = strFoldingModel.Replace("{FOLDING_NAME}", "Folding_" + nbFolding.ToString()); strFoldingModel = strFoldingModel.Replace("{BONE1_NAME}", "Bone_" + (nbFolding * 2).ToString()); strFoldingModel = strFoldingModel.Replace("{BONE2_NAME}", "Bone_" + (nbFolding * 2 + 1).ToString()); strFile.AppendLine(); strFile.Append(strFoldingModel); nbFolding++; } int indexStart3 = strTemplate.IndexOf("{MODEL_RELATIONS}"); int indexEnd3 = strTemplate.IndexOf("{/MODEL_RELATIONS}"); strSubTemplate = strTemplate.Substring(indexStart3 + 17, indexEnd3 - indexStart3 - 17); strFile.Append(strTemplate.Substring(indexEnd2 + 7, indexStart3 - indexEnd2 - 7)); nbFolding = 0; foreach (Folding folding in listFoldings) { string strFoldingModel = strSubTemplate; strFoldingModel = strFoldingModel.Replace("{ARMATURE_NAME}", "Armature_" + nbFolding.ToString()); strFoldingModel = strFoldingModel.Replace("{FOLDING_NAME}", "Folding_" + nbFolding.ToString()); strFoldingModel = strFoldingModel.Replace("{BONE1_NAME}", "Bone_" + (nbFolding * 2).ToString()); strFoldingModel = strFoldingModel.Replace("{BONE2_NAME}", "Bone_" + (nbFolding * 2 + 1).ToString()); strFile.AppendLine(); strFile.Append(strFoldingModel); nbFolding++; } int indexStart4 = strTemplate.IndexOf("{MODEL_CONNECTIONS}"); int indexEnd4 = strTemplate.IndexOf("{/MODEL_CONNECTIONS}"); strSubTemplate = strTemplate.Substring(indexStart4 + 19, indexEnd4 - indexStart4 - 19); strFile.Append(strTemplate.Substring(indexEnd3 + 18, indexStart4 - indexEnd3 - 18)); nbFolding = 0; foreach (Folding folding in listFoldings) { string strFoldingModel = strSubTemplate; strFoldingModel = strFoldingModel.Replace("{ARMATURE_NAME}", "Armature_" + nbFolding.ToString()); strFoldingModel = strFoldingModel.Replace("{FOLDING_NAME}", "Folding_" + nbFolding.ToString()); strFoldingModel = strFoldingModel.Replace("{BONE1_NAME}", "Bone_" + (nbFolding * 2).ToString()); strFoldingModel = strFoldingModel.Replace("{BONE2_NAME}", "Bone_" + (nbFolding * 2 + 1).ToString()); strFile.AppendLine(); strFile.Append(strFoldingModel); nbFolding++; } strFile.Append(strTemplate.Substring(indexEnd4 + 20)); File.WriteAllText(fileName, strFile.ToString()); }
private void btnOuvrir_Click(object sender, EventArgs e) { try { OpenFileDialog dlg = new OpenFileDialog(); dlg.Filter = "Papier (*.ppr)|*.ppr"; if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK) { XmlSerializer serializer = new XmlSerializer(typeof(Scene), new Type[] { typeof(ComponentBase), typeof(Folding), typeof(Link), typeof(Platform), typeof(Sensor), typeof(ZoneFoldingH), typeof(ZoneFoldingV), typeof(ZoneMovingH) , typeof(ZoneMovingV), typeof(Hole) }); XmlReader reader = new XmlTextReader(dlg.FileName); scene = (Scene)serializer.Deserialize(reader); reader.Close(); CalcFoldingIntersections(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }