1
0
mirror of synced 2024-12-11 23:36:01 +01:00
Switch-Toolbox/Switch_Toolbox_Library/FileFormats/DAE/ColladaWriter.cs
KillzXGaming b225c942e5 A few fixes.
Fix viewport not loading base drawables.
Fix animation player having issues with new animation classes.
Fix gfmdl for pkmn lets go.
Disable vertex color loading for gfmdl for now till fixed.
2019-11-12 16:29:00 -05:00

120 lines
3.9 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using System.IO;
namespace Toolbox.Library.Collada
{
public class ColladaWriter : IDisposable
{
private XmlTextWriter Writer;
private DAE.ExportSettings Settings;
private DAE.Version Version;
private Dictionary<string, int> AttriubteIdList = new Dictionary<string, int>();
public ColladaWriter(string fileName, DAE.ExportSettings settings)
{
Settings = settings;
Version = settings.FileVersion;
Writer = new XmlTextWriter(fileName, Encoding.UTF8)
{
Formatting = Formatting.Indented,
Indentation = 2,
};
}
public void WriteDAEHeader()
{
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();
}
public void WriteFileSettings()
{
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();
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();
}
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();
}
public void Dispose()
{
Writer.Close();
}
}
public class Material
{
public string Name { get; set; }
}
}