Skip to content

Instantly share code, notes, and snippets.

@vpenades
Created November 6, 2017 19:37
Show Gist options
  • Save vpenades/a0a866fdacab4c60786e71f01c4706f7 to your computer and use it in GitHub Desktop.
Save vpenades/a0a866fdacab4c60786e71f01c4706f7 to your computer and use it in GitHub Desktop.
gltf code generation example
using System;
using System.Linq;
using System.Collections.Generic;
using Newtonsoft.Json;
namespace glTFLoader.Schema
{
public class MeshPrimitive : GLTFChildOfRootProperty
{
private Dictionary<string, gltfId> _attributes;
private gltfId _indices;
private gltfId _material;
private modeEnum _mode;
private Dictionary<string, gltfId>[] _targets;
internal static MeshPrimitive Deserialize(GLTFRoot root, JsonReader reader)
{
var instance = new MeshPrimitive();
while (reader.Read() && reader.TokenType == JsonToken.PropertyName)
{
var curProp = reader.Value.ToString();
switch (curProp)
{
case "attributes":
{
instance._attributes = reader.ReadAsDictionary(() => gltfId.Deserialize(root, reader));
break;
}
case "indices":
{
instance._indices = gltfId.Deserialize(root, reader);
break;
}
case "material":
{
instance._material = gltfId.Deserialize(root, reader);
break;
}
case "mode":
{
instance._mode = modeEnum.Deserialize(root, reader);
break;
}
case "targets":
{
instance._targets = reader.ReadList(() => reader.ReadAsDictionary(() => gltfId.Deserialize(root, reader))).ToArray(); ;
break;
}
default:
{
instance.DefaultPropertyDeserializer(root, reader);
break;
}
}
}
return instance;
}
internal override void Serialize(JsonWriter writer)
{
writer.WriteStartObject();
{
writer.WritePropertyName("attributes");
writer.WriteDictionary(_attributes, item0 => item0.Serialize(writer));
}
{
writer.WritePropertyName("indices");
_indices.Serialize(writer);
}
{
writer.WritePropertyName("material");
_material.Serialize(writer);
}
{
writer.WritePropertyName("mode");
_mode.Serialize(writer);
}
{
writer.WritePropertyName("targets");
writer.WriteList(_targets, item0 => writer.WriteDictionary(item0, item1 => item1.Serialize(writer)));
}
base.Serialize(writer);
writer.WriteEndObject();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment