Skip to content

Instantly share code, notes, and snippets.

@cyberfox
Created April 11, 2020 12:40
Show Gist options
  • Save cyberfox/369480dd45b01829468e5c8a25a4eb1b to your computer and use it in GitHub Desktop.
Save cyberfox/369480dd45b01829468e5c8a25a4eb1b to your computer and use it in GitHub Desktop.
C# set of classes for parsing DSF files
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using Newtonsoft.Json;
namespace DAZ
{
public class DataCollection<T>
{
public int count { get; set; }
public List<List<T>> values { get; set; }
}
public class SimpleCollection<T>
{
public int count { get; set; }
public List<T> values { get; set; }
}
public class Vertices : DataCollection<float> { }
public class PolygonGroups : SimpleCollection<string> { }
public class PolyList : DataCollection<int> { }
public class Region
{
public string id { get; set; }
public string label { get; set; }
public string display_hint { get; set; }
public List<Region> children { get; set; }
public SimpleCollection<int> map { get; set; }
}
public class Geometry
{
public string id { get; set; }
public string name { get; set; }
public string type { get; set; }
public string edge_interpolation_mode { get; set; }
public string subd_mormal_smoothing_mode { get; set; }
public Vertices vertices { get; set; }
public PolygonGroups polygon_groups { get; set; }
public PolygonGroups polygon_material_groups { get; set; }
public PolyList polylist { get; set; }
public string default_uv_set;
public Region root_region { get; set; }
// public {something} graft { get; set; }
// public {something} extra { get; set; }
}
public class Point
{
public string id { get; set; }
public string name { get; set; }
public string type { get; set; }
public string label { get; set; }
public bool visible { get; set; }
public bool auto_follow { get; set; }
public float value { get; set; }
public long min { get; set; }
public long max { get; set; }
public bool display_as_percent { get; set; }
public float step_size { get; set; }
}
public class Node
{
public string id { get; set; }
public string name { get; set; }
public string type { get; set; }
public string label { get; set; }
public string rotation_order { get; set; }
public bool inherits_scale { get; set; }
public List<Point> center_point { get; set; }
public List<Point> end_point { get; set; }
public List<Point> orientation { get; set; }
public List<Point> rotation { get; set; }
public List<Point> translation { get; set; }
public List<Point> scale { get; set; }
public Point general_scale { get; set; }
public Presentation presentation { get; set; }
// public {something} extra { get; set; }
}
public class Presentation
{
public string type { get; set; }
public string label { get; set; }
public string description { get; set; }
public string icon_large { get; set; }
public List<List<float>> colors { get; set; }
public string preferred_base { get; set; }
}
public class Contributor
{
public string author { get; set; }
public string email { get; set; }
public string website { get; set; }
}
public class AssetInfo
{
public string id { get; set; }
public string type { get; set; }
public string revision { get; set; }
public string modified { get; set; }
public Contributor contributor { get; set; }
}
public class DSF
{
public string file_version { get; set; }
public AssetInfo asset_info { get; set; }
public List<Geometry> geometry_library { get; set; }
public List<Node> node_library { get; set; }
// public List<JObject> modifier_library { get; set; }
}
public class Utility
{
public static DSF Load(string filename)
{
FileStream inputStream = new FileStream(filename, FileMode.Open);
GZipStream inStream = new GZipStream(inputStream, CompressionMode.Decompress);
StreamReader sr = new StreamReader(inStream);
var js = JsonSerializer.CreateDefault();
DSF dsf = (DSF)js.Deserialize(sr, typeof(DSF));
return dsf;
}
}
}
@cyberfox
Copy link
Author

Usage is like this:

        DSF dsf = Utility.Load(filepath);

        Debug.Log(dsf.asset_info.contributor.author);
        Debug.Log(dsf.file_version);
        Geometry g = dsf.geometry_library.First();
        Debug.Log(g.vertices.count);
        Debug.Log(g.polylist.count);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment