2019-11-09 17:36:52 -05:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Xml;
|
2019-11-10 08:41:17 -05:00
|
|
|
|
using System.IO;
|
2019-11-09 17:36:52 -05:00
|
|
|
|
|
2019-11-12 16:29:00 -05:00
|
|
|
|
namespace Toolbox.Library.Collada
|
2019-11-09 17:36:52 -05:00
|
|
|
|
{
|
|
|
|
|
public class ColladaWriter : IDisposable
|
|
|
|
|
{
|
|
|
|
|
private XmlTextWriter Writer;
|
|
|
|
|
private DAE.ExportSettings Settings;
|
|
|
|
|
private DAE.Version Version;
|
|
|
|
|
|
2019-11-10 08:41:17 -05:00
|
|
|
|
private Dictionary<string, int> AttriubteIdList = new Dictionary<string, int>();
|
|
|
|
|
|
2019-11-09 17:36:52 -05:00
|
|
|
|
public ColladaWriter(string fileName, DAE.ExportSettings settings)
|
|
|
|
|
{
|
|
|
|
|
Settings = settings;
|
|
|
|
|
Version = settings.FileVersion;
|
|
|
|
|
Writer = new XmlTextWriter(fileName, Encoding.UTF8)
|
|
|
|
|
{
|
|
|
|
|
Formatting = Formatting.Indented,
|
|
|
|
|
Indentation = 2,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-10 08:41:17 -05:00
|
|
|
|
public void WriteDAEHeader()
|
2019-11-09 17:36:52 -05:00
|
|
|
|
{
|
|
|
|
|
Writer.WriteStartDocument();
|
|
|
|
|
Writer.WriteStartElement("COLLADA");
|
|
|
|
|
Writer.WriteAttributeString("xmlns", "http://www.collada.org/2005/11/COLLADASchema");
|
|
|
|
|
Writer.WriteAttributeString("version", $"{Version.Major}.{Version.Minor}.{Version.Micro}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void WriteAsset()
|
|
|
|
|
{
|
|
|
|
|
Writer.WriteStartElement("asset");
|
|
|
|
|
Writer.WriteEndElement();
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-10 08:41:17 -05:00
|
|
|
|
public void WriteFileSettings()
|
2019-11-09 17:36:52 -05:00
|
|
|
|
{
|
2019-11-10 08:41:17 -05:00
|
|
|
|
Writer.WriteStartElement("asset");
|
|
|
|
|
{
|
|
|
|
|
Writer.WriteStartElement("contributor");
|
|
|
|
|
Writer.WriteElementString("authoring_tool", System.Windows.Forms.Application.ProductName);
|
|
|
|
|
Writer.WriteEndElement();
|
|
|
|
|
|
|
|
|
|
Writer.WriteStartElement("created");
|
|
|
|
|
Writer.WriteString(DateTime.UtcNow.ToString("s", System.Globalization.CultureInfo.InvariantCulture) + "Z");
|
|
|
|
|
Writer.WriteEndElement();
|
|
|
|
|
|
|
|
|
|
Writer.WriteStartElement("modified");
|
|
|
|
|
Writer.WriteString(DateTime.UtcNow.ToString("s", System.Globalization.CultureInfo.InvariantCulture) + "Z");
|
|
|
|
|
Writer.WriteEndElement();
|
|
|
|
|
|
|
|
|
|
Writer.WriteStartElement("unit");
|
|
|
|
|
Writer.WriteAttributeString("meter", "0.01");
|
|
|
|
|
Writer.WriteAttributeString("name", "centimeter");
|
|
|
|
|
Writer.WriteEndElement();
|
2019-11-09 17:36:52 -05:00
|
|
|
|
|
2019-11-10 08:41:17 -05:00
|
|
|
|
Writer.WriteStartElement("up_axis");
|
|
|
|
|
Writer.WriteString("Y_UP");
|
|
|
|
|
Writer.WriteEndElement();
|
|
|
|
|
}
|
|
|
|
|
Writer.WriteEndElement();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void WriteLibraryImages(string[] textureNames)
|
|
|
|
|
{
|
|
|
|
|
Writer.WriteStartElement("library_images");
|
|
|
|
|
for (int i = 0; i < textureNames?.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
Writer.WriteStartElement("image");
|
|
|
|
|
Writer.WriteAttributeString("id", textureNames[i]);
|
|
|
|
|
Writer.WriteStartElement("init_from");
|
|
|
|
|
Writer.WriteString($"{Settings.ImageFolder}{textureNames[i]}.{Settings.ImageExtension}");
|
|
|
|
|
Writer.WriteEndElement();
|
|
|
|
|
Writer.WriteEndElement();
|
|
|
|
|
}
|
|
|
|
|
Writer.WriteEndElement();
|
2019-11-09 17:36:52 -05:00
|
|
|
|
}
|
|
|
|
|
|
2019-11-12 16:29:00 -05:00
|
|
|
|
public void WriteLibraryMaterials(List<Material> materials)
|
|
|
|
|
{
|
|
|
|
|
Writer.WriteStartElement("library_materials");
|
|
|
|
|
for (int i = 0; i < materials?.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
Writer.WriteStartElement("library_effects");
|
|
|
|
|
Writer.WriteEndElement();
|
|
|
|
|
}
|
|
|
|
|
Writer.WriteEndElement();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void WriteLibraryEffects(List<Material> materials)
|
|
|
|
|
{
|
|
|
|
|
Writer.WriteStartElement("library_effects");
|
|
|
|
|
for (int i = 0; i < materials?.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
Writer.WriteStartElement("library_effects");
|
|
|
|
|
Writer.WriteEndElement();
|
|
|
|
|
}
|
|
|
|
|
Writer.WriteEndElement();
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-09 17:36:52 -05:00
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
Writer.Close();
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-11-12 16:29:00 -05:00
|
|
|
|
|
|
|
|
|
public class Material
|
|
|
|
|
{
|
|
|
|
|
public string Name { get; set; }
|
|
|
|
|
}
|
2019-11-09 17:36:52 -05:00
|
|
|
|
}
|