Three.js can load a couple of formats, and the easiest to use for me is Collada which has a few great points:
- It's actually an XML format
- It's open and well documented
- And my tool (modo) supports it very well.
If you are still following me, you would have already pointed out a weakness: XML files are usually not small. Actually XML tends to be big instead of binary counterparts. You should also know as web developer that big files are not that smart. So I thought why not try to minify my DAE (collada) file? Well, some stuff are obvious: reduce the spaces, returns etc, and some others are like dropping useless information out of the file.
I choose to write a small C# code for that, and... you shall see it's REALLY SMALL:
Code: Select all
static void Main(string[] args)
{
if(args.Length != 1)
{
Console.WriteLine("collada_minify.exe <file.dae>");
return;
}
XElement doc = XElement.Load(args[0]);
doc.Descendants(doc.GetDefaultNamespace() + "asset").Remove();
doc.Descendants(doc.GetDefaultNamespace() + "extra").Remove();
doc.Descendants(doc.GetDefaultNamespace() + "technique").Where(row => row.Attribute("profile") != null && row.Attribute("profile").Value == "modo401").Remove();
StringWriter writer = new StringWriter();
doc.Save(writer,SaveOptions.DisableFormatting);
Regex replaceLeaderSpaces = new Regex("^(\\s+)", RegexOptions.Multiline);
File.WriteAllText(args[0], replaceLeaderSpaces.Replace(writer.GetStringBuilder().ToString(), ""));
}
If you wonder how that works? It's using LINQ to XML which let you query the XML file nearly like a DB, pretty cool stuff.