diff --git a/Assets/UniGLTF/UniGLTF/Editor/Serialization/ArraySerialization.cs b/Assets/UniGLTF/UniGLTF/Editor/Serialization/ArraySerialization.cs index 3fc8dac12..548351987 100644 --- a/Assets/UniGLTF/UniGLTF/Editor/Serialization/ArraySerialization.cs +++ b/Assets/UniGLTF/UniGLTF/Editor/Serialization/ArraySerialization.cs @@ -3,7 +3,7 @@ using System.IO; namespace UniGLTF { - public class ArraySerialization : FunctionSerializationBase + public class ArraySerialization : SerializationBase { IValueSerialization m_inner; @@ -14,7 +14,7 @@ namespace UniGLTF } public override void GenerateDeserializer(StreamWriter writer, string callName) { - var itemCallName = callName + "_ARRAY"; + var itemCallName = callName + "_ITEM"; writer.Write(@" public static $0 $2(ListTreeNode parsed) @@ -28,7 +28,7 @@ public static $0 $2(ListTreeNode parsed) return value; } " -.Replace("$0", UniJSON.JsonSchemaAttribute.GetTypeName(ValueType)) +.Replace("$0", JsonSchemaAttribute.GetTypeName(ValueType)) .Replace("$1", m_inner.ValueType.Name) .Replace("$2", callName) .Replace("$3", m_inner.GenerateDeserializerCall(itemCallName, "x")) @@ -39,5 +39,32 @@ public static $0 $2(ListTreeNode parsed) m_inner.GenerateDeserializer(writer, itemCallName); } } + + public override void GenerateSerializer(StreamWriter writer, string callName) + { + var itemCallName = callName + "_ITEM"; + writer.Write($@" +public static void {callName}(JsonFormatter f, {m_inner.ValueType.Name}[] value) +{{ + f.BeginList(); + + foreach(var item in value) + {{ + " +); + + writer.Write($"{m_inner.GenerateSerializerCall(itemCallName, "item")};\n"); + + writer.Write(@" + } + f.EndList(); +} +"); + + if (!m_inner.IsInline) + { + m_inner.GenerateSerializer(writer, itemCallName); + } + } } } diff --git a/Assets/UniGLTF/UniGLTF/Editor/Serialization/DeserializerGenerator.cs b/Assets/UniGLTF/UniGLTF/Editor/Serialization/DeserializerGenerator.cs index 7b579ce86..891a3e827 100644 --- a/Assets/UniGLTF/UniGLTF/Editor/Serialization/DeserializerGenerator.cs +++ b/Assets/UniGLTF/UniGLTF/Editor/Serialization/DeserializerGenerator.cs @@ -42,7 +42,7 @@ public static class GltfDeserializer [MenuItem(UniGLTFVersion.MENU + "/GLTF: Generate Deserializer")] static void GenerateSerializer() { - var info = new ObjectSerialization(typeof(glTF), "gltf"); + var info = new ObjectSerialization(typeof(glTF), "gltf", "Deserialize_"); Debug.Log(info); using (var s = File.Open(OutPath, FileMode.Create)) @@ -54,6 +54,7 @@ public static class GltfDeserializer } Debug.LogFormat("write: {0}", OutPath); + UnityPath.FromFullpath(OutPath).ImportAsset(); } } } diff --git a/Assets/UniGLTF/UniGLTF/Editor/Serialization/EnumSerialization.cs b/Assets/UniGLTF/UniGLTF/Editor/Serialization/EnumSerialization.cs new file mode 100644 index 000000000..8ac3c6c82 --- /dev/null +++ b/Assets/UniGLTF/UniGLTF/Editor/Serialization/EnumSerialization.cs @@ -0,0 +1,74 @@ +using System; +using System.IO; + +namespace UniGLTF +{ + public class EnumIntSerialization : IValueSerialization + { + Type m_type; + EnumSerializationType m_serializationType; + + public Type ValueType + { + get { return m_type; } + } + + public bool IsInline + { + get { return true; } + } + + public override string ToString() + { + return ValueType.ToString(); + } + + + public EnumIntSerialization(Type t, EnumSerializationType serializationType) + { + m_type = t; + m_serializationType = serializationType; + } + + public void GenerateDeserializer(StreamWriter writer, string callName) + { + throw new System.NotImplementedException(); + } + + public string GenerateDeserializerCall(string callName, string argName) + { + switch (m_serializationType) + { + case EnumSerializationType.AsInt: + return string.Format("({0}){1}.GetInt32()", m_type.Name, argName); + + case EnumSerializationType.AsLowerString: + // (ProjectionType)Enum.Parse(typeof(ProjectionType), kv.Value.GetString(), true) + return $"({m_type.Name})Enum.Parse(typeof({m_type.Name}), {argName}.GetString(), true)"; + + default: + throw new NotImplementedException(); + } + } + + public void GenerateSerializer(StreamWriter writer, string callName) + { + throw new NotImplementedException(); + } + + public string GenerateSerializerCall(string callName, string argName) + { + switch (m_serializationType) + { + case EnumSerializationType.AsInt: + return $"f.Value((int){argName})"; + + case EnumSerializationType.AsLowerString: + return $"f.Value({argName}.ToString().ToLower())"; + + default: + throw new NotImplementedException(); + } + } + } +} diff --git a/Assets/VRM/UniVRM/Scripts/Format/VRMFormatterExtensionsGltf.g.cs.meta b/Assets/UniGLTF/UniGLTF/Editor/Serialization/EnumSerialization.cs.meta similarity index 83% rename from Assets/VRM/UniVRM/Scripts/Format/VRMFormatterExtensionsGltf.g.cs.meta rename to Assets/UniGLTF/UniGLTF/Editor/Serialization/EnumSerialization.cs.meta index c5f181fe4..546a5bf9c 100644 --- a/Assets/VRM/UniVRM/Scripts/Format/VRMFormatterExtensionsGltf.g.cs.meta +++ b/Assets/UniGLTF/UniGLTF/Editor/Serialization/EnumSerialization.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 280f4d5430b0b04449ef06d6f1b4db36 +guid: 135bb9bd3d924ea4abe8fc6219355a6b MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/UniGLTF/UniGLTF/Editor/Serialization/ExtensionSerialization.cs b/Assets/UniGLTF/UniGLTF/Editor/Serialization/ExtensionSerialization.cs index ac2fe6031..1aafaa477 100644 --- a/Assets/UniGLTF/UniGLTF/Editor/Serialization/ExtensionSerialization.cs +++ b/Assets/UniGLTF/UniGLTF/Editor/Serialization/ExtensionSerialization.cs @@ -18,5 +18,15 @@ namespace UniGLTF { return $"new glTFExtensionImport({argName})"; } + + public void GenerateSerializer(StreamWriter writer, string callName) + { + throw new NotImplementedException(); + } + + public string GenerateSerializerCall(string callName, string argName) + { + return "value.extras.Serialize(f)"; + } } } diff --git a/Assets/UniGLTF/UniGLTF/Editor/Serialization/FieldSerializationInfo.cs b/Assets/UniGLTF/UniGLTF/Editor/Serialization/FieldSerializationInfo.cs index ae62e2c0d..107620924 100644 --- a/Assets/UniGLTF/UniGLTF/Editor/Serialization/FieldSerializationInfo.cs +++ b/Assets/UniGLTF/UniGLTF/Editor/Serialization/FieldSerializationInfo.cs @@ -26,11 +26,13 @@ namespace UniGLTF private set; } + readonly string m_prefix; + public string FunctionName { get { - return "Deserialize_" + Path + return m_prefix + Path .Replace("/", "_") .Replace("[]", "_") ; @@ -45,32 +47,33 @@ namespace UniGLTF private set; } - public FieldSerializationInfo(FieldInfo fi, string path) + public FieldSerializationInfo(FieldInfo fi, string path, string prefix) { + m_prefix = prefix; m_fi = fi; Path = path + "/" + fi.Name; m_attr = fi.GetCustomAttributes(true).FirstOrDefault(x => x.GetType() == typeof(JsonSchemaAttribute)) as JsonSchemaAttribute; - Serialization = GetSerialization(m_fi.FieldType, Path, m_attr); + Serialization = GetSerialization(m_fi.FieldType, Path, m_attr, prefix); } - static IValueSerialization GetSerialization(Type t, string path, JsonSchemaAttribute attr) + static IValueSerialization GetSerialization(Type t, string path, JsonSchemaAttribute attr, string prefix) { if (t.IsArray) { return new ArraySerialization(t, - GetSerialization(t.GetElementType(), path + "[]", attr)); + GetSerialization(t.GetElementType(), path + "[]", attr, prefix)); } else if (t.IsGenericType && t.GetGenericTypeDefinition() == typeof(List<>)) { return new ListSerialization(t, - GetSerialization(t.GetGenericArguments()[0], path + "[]", attr)); + GetSerialization(t.GetGenericArguments()[0], path + "[]", attr, prefix)); } else if (t.IsGenericType && t.GetGenericTypeDefinition() == typeof(Dictionary<,>) && t.GetGenericArguments()[0] == typeof(string)) { return new StringKeyDictionarySerialization(t, - GetSerialization(t.GetGenericArguments()[1], path, attr)); + GetSerialization(t.GetGenericArguments()[1], path, attr, prefix)); } // GetCollectionType(fi.FieldType, out suffix, out t); @@ -131,7 +134,7 @@ namespace UniGLTF return new ExtensionSerialization(); } - return new ObjectSerialization(t, path); + return new ObjectSerialization(t, path, prefix); } public override string ToString() diff --git a/Assets/UniGLTF/UniGLTF/Editor/Serialization/IValueSerialization.cs b/Assets/UniGLTF/UniGLTF/Editor/Serialization/IValueSerialization.cs index 34ebe3ca6..b799d1d2c 100644 --- a/Assets/UniGLTF/UniGLTF/Editor/Serialization/IValueSerialization.cs +++ b/Assets/UniGLTF/UniGLTF/Editor/Serialization/IValueSerialization.cs @@ -13,5 +13,9 @@ namespace UniGLTF string GenerateDeserializerCall(string callName, string argName); void GenerateDeserializer(StreamWriter writer, string callName); + + string GenerateSerializerCall(string callName, string argName); + + void GenerateSerializer(StreamWriter writer, string callName); } } diff --git a/Assets/UniGLTF/UniGLTF/Editor/Serialization/ListSerialization.cs b/Assets/UniGLTF/UniGLTF/Editor/Serialization/ListSerialization.cs index 3c95dfb20..703cb90c5 100644 --- a/Assets/UniGLTF/UniGLTF/Editor/Serialization/ListSerialization.cs +++ b/Assets/UniGLTF/UniGLTF/Editor/Serialization/ListSerialization.cs @@ -1,10 +1,9 @@ using System; using System.IO; -using System.Linq; namespace UniGLTF { - public class ListSerialization : FunctionSerializationBase + public class ListSerialization : SerializationBase { IValueSerialization m_inner; @@ -21,7 +20,7 @@ namespace UniGLTF public override void GenerateDeserializer(StreamWriter writer, string callName) { - var itemCallName = callName + "_LIST"; + var itemCallName = callName + "_ITEM"; writer.Write(@" public static $0 $2(ListTreeNode parsed) { @@ -32,7 +31,7 @@ public static $0 $2(ListTreeNode parsed) } return value; }" -.Replace("$0", UniJSON.JsonSchemaAttribute.GetTypeName(ValueType)) +.Replace("$0", JsonSchemaAttribute.GetTypeName(ValueType)) .Replace("$1", m_inner.ValueType.Name) .Replace("$2", callName) .Replace("$3", m_inner.GenerateDeserializerCall(itemCallName, "x")) @@ -43,5 +42,32 @@ public static $0 $2(ListTreeNode parsed) m_inner.GenerateDeserializer(writer, itemCallName); } } + + public override void GenerateSerializer(StreamWriter writer, string callName) + { + var itemCallName = callName + "_ITEM"; + writer.Write($@" +public static void {callName}(JsonFormatter f, List<{m_inner.ValueType.Name}> value) +{{ + f.BeginList(); + + foreach(var item in value) + {{ + " +); + + writer.Write($"{m_inner.GenerateSerializerCall(itemCallName, "item")};\n"); + + writer.Write(@" + } + f.EndList(); +} +"); + + if (!m_inner.IsInline) + { + m_inner.GenerateSerializer(writer, itemCallName); + } + } } } diff --git a/Assets/UniGLTF/UniGLTF/Editor/Serialization/ObjectSerialization.cs b/Assets/UniGLTF/UniGLTF/Editor/Serialization/ObjectSerialization.cs index 0142ba449..ec4b49333 100644 --- a/Assets/UniGLTF/UniGLTF/Editor/Serialization/ObjectSerialization.cs +++ b/Assets/UniGLTF/UniGLTF/Editor/Serialization/ObjectSerialization.cs @@ -5,7 +5,7 @@ using System.Text; namespace UniGLTF { - public abstract class FunctionSerializationBase : IValueSerialization + public abstract class SerializationBase : IValueSerialization { public Type ValueType { @@ -22,16 +22,23 @@ namespace UniGLTF public string GenerateDeserializerCall(string callName, string argName) { - return string.Format("{0}({1})", callName, argName); + return $"{callName}({argName})"; + } + + public abstract void GenerateSerializer(StreamWriter writer, string callName); + + public string GenerateSerializerCall(string callName, string argName) + { + return $"{callName}(f, {argName})"; } } - public class ObjectSerialization : FunctionSerializationBase + public class ObjectSerialization : SerializationBase { string m_path; FieldSerializationInfo[] m_fsi; - public ObjectSerialization(Type t, string path) + public ObjectSerialization(Type t, string path, string prefix) { ValueType = t; m_path = path; @@ -47,7 +54,7 @@ namespace UniGLTF }) .Select(x => { - return new FieldSerializationInfo(x, path); + return new FieldSerializationInfo(x, path, prefix); }).ToArray(); } @@ -103,5 +110,36 @@ public static $0 $2(ListTreeNode parsed) } } } + + public override void GenerateSerializer(StreamWriter writer, string callName) + { + writer.Write($@" +public static void {callName}(JsonFormatter f, {ValueType.Name} value) +{{ + f.BeginMap(); + +" +); + + foreach (var f in m_fsi) + { + writer.Write($" f.Key(\"{f.Name}\");\n"); + writer.Write($" {f.Serialization.GenerateSerializerCall(f.FunctionName, $"value.{f.Name}")};\n"); + writer.Write("\n"); + } + + writer.Write(@" + f.EndMap(); +} +"); + + foreach (var f in m_fsi) + { + if (!f.Serialization.IsInline) + { + f.Serialization.GenerateSerializer(writer, f.FunctionName); + } + } + } } } diff --git a/Assets/UniGLTF/UniGLTF/Editor/Serialization/PrimitiveSerialization.cs b/Assets/UniGLTF/UniGLTF/Editor/Serialization/PrimitiveSerialization.cs index 4d2ea1316..209f75eb5 100644 --- a/Assets/UniGLTF/UniGLTF/Editor/Serialization/PrimitiveSerialization.cs +++ b/Assets/UniGLTF/UniGLTF/Editor/Serialization/PrimitiveSerialization.cs @@ -19,6 +19,16 @@ namespace UniGLTF public abstract string GenerateDeserializerCall(string callName, string argName); + public void GenerateSerializer(StreamWriter writer, string callName) + { + throw new NotImplementedException(); + } + + public string GenerateSerializerCall(string callName, string argName) + { + return $"f.Value({argName})"; + } + public override string ToString() { return ValueType.ToString(); @@ -180,37 +190,4 @@ namespace UniGLTF return argName + ".GetString()"; } } - - public class EnumIntSerialization : PrimitiveSerializationBase - { - Type m_type; - UniJSON.EnumSerializationType m_serializationType; - - public override Type ValueType - { - get { return m_type; } - } - - public EnumIntSerialization(Type t, UniJSON.EnumSerializationType serializationType) - { - m_type = t; - m_serializationType = serializationType; - } - - public override string GenerateDeserializerCall(string callName, string argName) - { - switch (m_serializationType) - { - case UniJSON.EnumSerializationType.AsInt: - return string.Format("({0}){1}.GetInt32()", m_type.Name, argName); - - case UniJSON.EnumSerializationType.AsLowerString: - // (ProjectionType)Enum.Parse(typeof(ProjectionType), kv.Value.GetString(), true) - return $"({m_type.Name})Enum.Parse(typeof({m_type.Name}), {argName}.GetString(), true)"; - - default: - throw new NotImplementedException(); - } - } - } -} \ No newline at end of file +} diff --git a/Assets/UniGLTF/UniGLTF/Editor/Serialization/SerializerGenerator.cs b/Assets/UniGLTF/UniGLTF/Editor/Serialization/SerializerGenerator.cs index 005c04131..3366b4897 100644 --- a/Assets/UniGLTF/UniGLTF/Editor/Serialization/SerializerGenerator.cs +++ b/Assets/UniGLTF/UniGLTF/Editor/Serialization/SerializerGenerator.cs @@ -1,5 +1,4 @@ using System; -using System.Collections; using System.Collections.Generic; using System.IO; using System.Reflection; @@ -14,341 +13,47 @@ namespace UniGLTF { const BindingFlags FIELD_FLAGS = BindingFlags.Instance | BindingFlags.Public; - static string OutPath - { - get - { - return Path.Combine(UnityEngine.Application.dataPath, - "UniGLTF/UniGLTF/Scripts/IO/FormatterExtensionsGltf.g.cs"); - } - } - - /// - /// AOT向けにシリアライザを生成する - /// - [MenuItem(UniGLTFVersion.MENU + "/GLTF: Generate Serializer")] - static void GenerateSerializer() - { - var path = OutPath; - - using (var g = new Generator(path)) - { - var rootType = typeof(glTF); - g.Generate(rootType, "gltf"); - } - } - - class Generator : IDisposable - { - String m_path; - Stream m_s; - StreamWriter m_w; - - static Dictionary s_snippets = new Dictionary - { - {"gltf/animations", "if(value.animations!=null && value.animations.Count>0)" }, - {"gltf/cameras", "if(value.cameras!=null && value.cameras.Count>0)" }, - {"gltf/buffers", "if(value.buffers!=null && value.buffers.Count>0)" }, - {"gltf/bufferViews", "if(value.bufferViews!=null && value.bufferViews.Count>0)" }, - {"gltf/bufferViews[]/byteStride", "" }, - {"gltf/bufferViews[]/target", "if(value.target!=0)" }, - {"gltf/animations[]/channels", "if(value.channels!=null && value.channels.Count>0)" }, - {"gltf/animations[]/channels[]/target", "if(value!=null)" }, - {"gltf/animations[]/samplers", "if(value.samplers!=null && value.samplers.Count>0)" }, - {"gltf/accessors", "if(value.accessors!=null && value.accessors.Count>0)" }, - {"gltf/accessors[]/max", "if(value.max!=null && value.max.Length>0)"}, - {"gltf/accessors[]/min", "if(value.min!=null && value.min.Length>0)"}, - {"gltf/accessors[]/sparse", "if(value.sparse!=null && value.sparse.count>0)"}, - {"gltf/accessors[]/bufferView", "if(value.bufferView>=0)"}, - {"gltf/accessors[]/byteOffset", "if(value.bufferView>=0)"}, - - {"gltf/images", "if(value.images!=null && value.images.Count>0)" }, - - {"gltf/meshes", "if(value.meshes!=null && value.meshes.Count>0)" }, - {"gltf/meshes[]/primitives", "if(value.primitives!=null && value.primitives.Count>0)" }, - {"gltf/meshes[]/primitives[]/targets", "if(value.targets!=null && value.targets.Count>0)" }, - - {"gltf/meshes[]/primitives[]/targets[]/POSITION", "if(value.POSITION!=-1)" }, - {"gltf/meshes[]/primitives[]/targets[]/NORMAL", "if(value.NORMAL!=-1)" }, - {"gltf/meshes[]/primitives[]/targets[]/TANGENT", "if(value.TANGENT!=-1)" }, - - {"gltf/meshes[]/primitives[]/attributes/POSITION", "if(value.POSITION!=-1)"}, - {"gltf/meshes[]/primitives[]/attributes/NORMAL", "if(value.NORMAL!=-1)"}, - {"gltf/meshes[]/primitives[]/attributes/TANGENT", "if(value.TANGENT!=-1)"}, - {"gltf/meshes[]/primitives[]/attributes/TEXCOORD_0", "if(value.TEXCOORD_0!=-1)"}, - {"gltf/meshes[]/primitives[]/attributes/TEXCOORD_1", "if(value.TEXCOORD_1!=-1)"}, - {"gltf/meshes[]/primitives[]/attributes/COLOR_0", "if(value.COLOR_0!=-1)"}, - {"gltf/meshes[]/primitives[]/attributes/JOINTS_0", "if(value.JOINTS_0!=-1)"}, - {"gltf/meshes[]/primitives[]/attributes/WEIGHTS_0", "if(value.WEIGHTS_0!=-1)"}, - - {"gltf/meshes[]/weights", "if(value.weights!=null && value.weights.Length>0)" }, - {"gltf/materials", "if(value.materials!=null && value.materials.Count>0)" }, - {"gltf/materials[]/alphaCutoff", "if(value.alphaMode == \"MASK\")" }, - {"gltf/nodes", "if(value.nodes!=null && value.nodes.Count>0)" }, - {"gltf/nodes[]/camera", "if(value.camera!=-1)"}, - {"gltf/nodes[]/mesh", "if(value.mesh!=-1)"}, - {"gltf/nodes[]/skin", "if(value.skin!=-1)"}, - {"gltf/nodes[]/children", "if(value.children != null && value.children.Length>0)"}, - {"gltf/samplers", "if(value.samplers!=null && value.samplers.Count>0)" }, - {"gltf/scenes", "if(value.scenes!=null && value.scenes.Count>0)" }, - {"gltf/scenes[]/nodes", "if(value.nodes!=null && value.nodes.Length>0)" }, - {"gltf/skins", "if(value.skins!=null && value.skins.Count>0)" }, - {"gltf/skins[]/skeleton", "if(value.skeleton!=-1)"}, - {"gltf/skins[]/joints", "if(value.joints!=null && value.joints.Length>0)"}, - {"gltf/extensionsUsed", "if(value.extensionsUsed!=null && value.extensionsUsed.Count>0)"}, // dummy - {"gltf/extensionsRequired", "if(false && value.extensionsRequired!=null && value.extensionsRequired.Count>0)"}, - {"gltf/extensions/VRM/humanoid/humanBones[]/axisLength", "if(value.axisLength>0)"}, - {"gltf/extensions/VRM/humanoid/humanBones[]/center", "if(value.center!=Vector3.zero)"}, - {"gltf/extensions/VRM/humanoid/humanBones[]/max", "if(value.max!=Vector3.zero)"}, - {"gltf/extensions/VRM/humanoid/humanBones[]/min", "if(value.min!=Vector3.zero)"}, - {"gltf/textures", "if(value.textures!=null && value.textures.Count>0)" }, - }; - - public Generator(string path) - { - m_path = path; - m_s = File.Open(path, FileMode.Create); - m_w = new StreamWriter(m_s, Encoding.UTF8); - - // begin - m_w.Write(@" -using System; + const string Begin = @"using System; using System.Collections.Generic; using UniJSON; namespace UniGLTF { - static public class IFormatterExtensionsGltf + static public class GltfSerializer { -"); - } +"; - public void Dispose() - { - // end - m_w.Write(@" + const string End = @" } // class } // namespace -"); +"; - m_w.Dispose(); - m_s.Dispose(); - UnityPath.FromFullpath(m_path).ImportAsset(); + static string OutPath + { + get + { + return Path.Combine(UnityEngine.Application.dataPath, + "UniGLTF/UniGLTF/Scripts/IO/GltfSerializer.g.cs"); + } + } + + [MenuItem(UniGLTFVersion.MENU + "/GLTF: Generate Serializer")] + static void GenerateSerializer() + { + var info = new ObjectSerialization(typeof(glTF), "gltf", "Serialize_"); + Debug.Log(info); + + using (var s = File.Open(OutPath, FileMode.Create)) + using (var w = new StreamWriter(s, new UTF8Encoding(false))) + { + w.Write(Begin); + info.GenerateSerializer(w, "Serialize"); + w.Write(End); } - HashSet m_used = new HashSet - { - typeof(object), - }; - - public void Generate(Type t, string path, int level = 0) - { - if (m_used.Contains(t)) - { - // 処理済み - return; - } - m_used.Add(t); - - // - // primitive - // - try - { - var mi = typeof(JsonFormatter).GetMethod("Value", new Type[] { t }); - if (mi != null) - { - m_w.Write(@" - public static void GenSerialize(this JsonFormatter f, $0 value) - { - f.Value(value); - } -".Replace("$0", t.Name)); - - return; - } - } - catch (AmbiguousMatchException) - { - // skip - } - - if (t.IsEnum) - { - // - // enum - // - m_w.Write(@" - public static void GenSerialize(this JsonFormatter f, $0 value) - { - f.Value((int)value); - } -".Replace("$0", t.Name)); - } - else if (t.IsArray) - { - var et = t.GetElementType(); - m_w.Write(@" - /// $1 - public static void GenSerialize(this JsonFormatter f, $0[] value) - { - f.BeginList(value.Length); - foreach (var x in value) - { - f.GenSerialize(x); - } - f.EndList(); - } - " - .Replace("$0", et.Name) - .Replace("$1", path) - ); - Generate(et, path + "[]", level + 1); - } - else if (t.IsGenericType) - { - if (t.GetGenericTypeDefinition() == typeof(List<>)) - { - // - // array - // - var et = t.GetGenericArguments()[0]; - m_w.Write(@" - /// $1 - public static void GenSerialize(this JsonFormatter f, List<$0> value) - { - f.BeginList(value.Count); - foreach (var x in value) - { - f.GenSerialize(x); - } - f.EndList(); - } -" -.Replace("$0", et.Name) -.Replace("$1", path)); - Generate(et, path + "[]", level + 1); - } - else if (t.GetGenericTypeDefinition() == typeof(Dictionary<,>) - && t.GetGenericArguments()[0] == typeof(string)) - { - // - // object - // - var et = t.GetGenericArguments()[1]; - m_w.Write(@" - /// $1 - public static void GenSerialize(this JsonFormatter f, Dictionary value) - { - f.BeginMap(value.Count); - foreach (var kv in value) - { - f.Key(kv.Key); - f.GenSerialize(kv.Value); - } - f.EndMap(); - } - -" -.Replace("$0", et.Name) -.Replace("$1", path)); - Generate(et, path + "{}", level + 1); - } - else - { - Debug.LogWarningFormat("unknown type: {0}", t); - } - } - else if (t == typeof(glTFExtension)) - { - // skip - } - else - { - // - // reflection - // - Debug.LogFormat("{0}({1})", path, t.Name); - - m_w.Write(@" - /// $1 - public static void GenSerialize(this JsonFormatter f, $0 value) - { - f.BeginMap(0); // dummy -" -.Replace("$0", t.Name) -.Replace("$1", path) -); - - foreach (var fi in t.GetFields(FIELD_FLAGS)) - { - if (fi.FieldType == typeof(object)) - { - continue; - } - if (fi.IsLiteral && !fi.IsInitOnly) - { - continue; - } - if (fi.FieldType == typeof(string) || fi.FieldType.IsEnum || fi.FieldType.IsArray || fi.FieldType.IsGenericType) - { - - } - else if (fi.FieldType == typeof(glTFExtension)) - { - - } - else if (fi.FieldType.IsClass && fi.FieldType.GetFields(FIELD_FLAGS).Length == 0) - { - continue; - } - - var snipet = ""; - if (fi.FieldType == typeof(string)) - { - snipet = $"if(!string.IsNullOrEmpty(value.{fi.Name}))"; - } - else if (fi.FieldType.IsClass) - { - snipet = $"if(value.{fi.Name}!=null)"; - } - - var value = default(string); - if (s_snippets.TryGetValue($"{path}/{fi.Name}", out value)) - { - snipet = value; - } - - if (value == "") - { - // found, but empty - } - else - { - m_w.Write(@" - $1 - { - f.Key(""$0""); f.GenSerialize(value.$0); - } -" - .Replace("$0", fi.Name) - .Replace("$1", snipet) - ); - } - } - - m_w.Write(@" - f.EndMap(); - } -"); - - foreach (var fi in t.GetFields(FIELD_FLAGS)) - { - Generate(fi.FieldType, path + "/" + fi.Name, level + 1); - } - } - } + Debug.LogFormat("write: {0}", OutPath); + UnityPath.FromFullpath(OutPath).ImportAsset(); } } } diff --git a/Assets/UniGLTF/UniGLTF/Editor/Serialization/StringKeyDictionarySerialization.cs b/Assets/UniGLTF/UniGLTF/Editor/Serialization/StringKeyDictionarySerialization.cs index 3c74af3b9..62b997167 100644 --- a/Assets/UniGLTF/UniGLTF/Editor/Serialization/StringKeyDictionarySerialization.cs +++ b/Assets/UniGLTF/UniGLTF/Editor/Serialization/StringKeyDictionarySerialization.cs @@ -3,7 +3,7 @@ using System.IO; namespace UniGLTF { - public class StringKeyDictionarySerialization : FunctionSerializationBase + public class StringKeyDictionarySerialization : SerializationBase { IValueSerialization m_inner; @@ -14,7 +14,7 @@ namespace UniGLTF } public override void GenerateDeserializer(StreamWriter writer, string callName) { - var itemCallName = callName + "_DICT"; + var itemCallName = callName + "_ITEM"; writer.Write(@" public static $0 $2(ListTreeNode parsed) @@ -27,7 +27,7 @@ public static $0 $2(ListTreeNode parsed) return value; } " -.Replace("$0", UniJSON.JsonSchemaAttribute.GetTypeName(ValueType)) +.Replace("$0", JsonSchemaAttribute.GetTypeName(ValueType)) .Replace("$1", m_inner.ValueType.Name) .Replace("$2", callName) .Replace("$3", m_inner.GenerateDeserializerCall(itemCallName, "kv.Value")) @@ -38,5 +38,27 @@ public static $0 $2(ListTreeNode parsed) m_inner.GenerateDeserializer(writer, itemCallName); } } + + public override void GenerateSerializer(StreamWriter writer, string callName) + { + var itemCallName = callName + "_ITEM"; + writer.Write($@" +public static void {callName}(JsonFormatter f, Dictionary value) +{{ + f.BeginMap(); + foreach(var kv in value) + {{ + f.Key(kv.Key); + {m_inner.GenerateSerializerCall(itemCallName, "kv.Value")}; + }} + f.EndMap(); +}} +"); + + if (!m_inner.IsInline) + { + m_inner.GenerateSerializer(writer, itemCallName); + } + } } } diff --git a/Assets/UniGLTF/UniGLTF/Editor/Tests/UniGLTFTests.cs b/Assets/UniGLTF/UniGLTF/Editor/Tests/UniGLTFTests.cs index 253d56899..8170d62af 100644 --- a/Assets/UniGLTF/UniGLTF/Editor/Tests/UniGLTFTests.cs +++ b/Assets/UniGLTF/UniGLTF/Editor/Tests/UniGLTFTests.cs @@ -13,49 +13,49 @@ namespace UniGLTF public static string ToJson(this glTF self) { var f = new JsonFormatter(); - f.GenSerialize(self); + GltfSerializer.Serialize(f, self); return f.ToString(); } public static string ToJson(this glTFMesh self) { var f = new JsonFormatter(); - f.GenSerialize(self); + GltfSerializer.Serialize_gltf_meshes_LIST(f, self); return f.ToString(); } public static string ToJson(this glTFPrimitives self) { var f = new JsonFormatter(); - f.GenSerialize(self); + GltfSerializer.Serialize_gltf_meshes__primitives_LIST(f, self); return f.ToString(); } public static string ToJson(this glTFAttributes self) { var f = new JsonFormatter(); - f.GenSerialize(self); + GltfSerializer.Serialize_gltf_meshes__primitives__attributes(f, self); return f.ToString(); } public static string ToJson(this glTFMaterialBaseColorTextureInfo self) { var f = new JsonFormatter(); - f.GenSerialize(self); + GltfSerializer.Serialize_gltf_materials__pbrMetallicRoughness_baseColorTexture(f, self); return f.ToString(); } public static string ToJson(this glTFMaterial self) { var f = new JsonFormatter(); - f.GenSerialize(self); + GltfSerializer.Serialize_gltf_materials_LIST(f, self); return f.ToString(); } public static string ToJson(this glTFNode self) { var f = new JsonFormatter(); - f.GenSerialize(self); + GltfSerializer.Serialize_gltf_nodes_LIST(f, self); return f.ToString(); } public static string ToJson(this glTFSkin self) { var f = new JsonFormatter(); - f.GenSerialize(self); + GltfSerializer.Serialize_gltf_skins_LIST(f, self); return f.ToString(); } } diff --git a/Assets/UniGLTF/UniJSON/Scripts/Json/JsonSchemaAttribute.cs b/Assets/UniGLTF/UniGLTF/Scripts/Format/JsonSchemaAttribute.cs similarity index 98% rename from Assets/UniGLTF/UniJSON/Scripts/Json/JsonSchemaAttribute.cs rename to Assets/UniGLTF/UniGLTF/Scripts/Format/JsonSchemaAttribute.cs index 4a8cfef26..c52e036fe 100644 --- a/Assets/UniGLTF/UniJSON/Scripts/Json/JsonSchemaAttribute.cs +++ b/Assets/UniGLTF/UniGLTF/Scripts/Format/JsonSchemaAttribute.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Reflection; using System.Text; -namespace UniJSON +namespace UniGLTF { public enum EnumSerializationType { @@ -39,7 +39,7 @@ namespace UniJSON #endregion #region object - public ValueNodeType ValueType; + public UniJSON.ValueNodeType ValueType; public int MinProperties; public bool Required; public string[] Dependencies; diff --git a/Assets/UniGLTF/UniJSON/Scripts/Json/JsonSchemaAttribute.cs.meta b/Assets/UniGLTF/UniGLTF/Scripts/Format/JsonSchemaAttribute.cs.meta similarity index 69% rename from Assets/UniGLTF/UniJSON/Scripts/Json/JsonSchemaAttribute.cs.meta rename to Assets/UniGLTF/UniGLTF/Scripts/Format/JsonSchemaAttribute.cs.meta index fa872cf7e..2ee6c9d2d 100644 --- a/Assets/UniGLTF/UniJSON/Scripts/Json/JsonSchemaAttribute.cs.meta +++ b/Assets/UniGLTF/UniGLTF/Scripts/Format/JsonSchemaAttribute.cs.meta @@ -1,8 +1,7 @@ fileFormatVersion: 2 -guid: e79a9be81d4b0fc4ebd9ca47d0f20a04 -timeCreated: 1526058096 -licenseType: Free +guid: 648733606660ecc4d8b8b25e37c1194f MonoImporter: + externalObjects: {} serializedVersion: 2 defaultReferences: [] executionOrder: 0 diff --git a/Assets/UniGLTF/UniGLTF/Scripts/Format/glTF.cs b/Assets/UniGLTF/UniGLTF/Scripts/Format/glTF.cs index bb6a83aab..d85f61f1d 100644 --- a/Assets/UniGLTF/UniGLTF/Scripts/Format/glTF.cs +++ b/Assets/UniGLTF/UniGLTF/Scripts/Format/glTF.cs @@ -380,7 +380,7 @@ namespace UniGLTF public byte[] ToGlbBytes() { var f = new JsonFormatter(); - f.GenSerialize(this); + GltfSerializer.Serialize(f, this); var json = f.ToString().ParseAsJson().ToString(" "); @@ -404,7 +404,7 @@ namespace UniGLTF throw new NotImplementedException(); } - f.GenSerialize(this); + GltfSerializer.Serialize(f, this); var json = f.ToString().ParseAsJson().ToString(" "); RemoveUnusedExtensions(json); return (json, buffers); diff --git a/Assets/UniGLTF/UniGLTF/Scripts/IO/FormatterExtensionsGltf.g.cs b/Assets/UniGLTF/UniGLTF/Scripts/IO/FormatterExtensionsGltf.g.cs deleted file mode 100644 index c38cbc992..000000000 --- a/Assets/UniGLTF/UniGLTF/Scripts/IO/FormatterExtensionsGltf.g.cs +++ /dev/null @@ -1,1544 +0,0 @@ - -using System; -using System.Collections.Generic; -using UniJSON; - -namespace UniGLTF { - - static public class IFormatterExtensionsGltf - { - - - /// gltf - public static void GenSerialize(this JsonFormatter f, glTF value) - { - f.BeginMap(0); // dummy - - if(value.asset!=null) - { - f.Key("asset"); f.GenSerialize(value.asset); - } - - if(value.buffers!=null && value.buffers.Count>0) - { - f.Key("buffers"); f.GenSerialize(value.buffers); - } - - if(value.bufferViews!=null && value.bufferViews.Count>0) - { - f.Key("bufferViews"); f.GenSerialize(value.bufferViews); - } - - if(value.accessors!=null && value.accessors.Count>0) - { - f.Key("accessors"); f.GenSerialize(value.accessors); - } - - if(value.textures!=null && value.textures.Count>0) - { - f.Key("textures"); f.GenSerialize(value.textures); - } - - if(value.samplers!=null && value.samplers.Count>0) - { - f.Key("samplers"); f.GenSerialize(value.samplers); - } - - if(value.images!=null && value.images.Count>0) - { - f.Key("images"); f.GenSerialize(value.images); - } - - if(value.materials!=null && value.materials.Count>0) - { - f.Key("materials"); f.GenSerialize(value.materials); - } - - if(value.meshes!=null && value.meshes.Count>0) - { - f.Key("meshes"); f.GenSerialize(value.meshes); - } - - if(value.nodes!=null && value.nodes.Count>0) - { - f.Key("nodes"); f.GenSerialize(value.nodes); - } - - if(value.skins!=null && value.skins.Count>0) - { - f.Key("skins"); f.GenSerialize(value.skins); - } - - - { - f.Key("scene"); f.GenSerialize(value.scene); - } - - if(value.scenes!=null && value.scenes.Count>0) - { - f.Key("scenes"); f.GenSerialize(value.scenes); - } - - if(value.animations!=null && value.animations.Count>0) - { - f.Key("animations"); f.GenSerialize(value.animations); - } - - if(value.cameras!=null && value.cameras.Count>0) - { - f.Key("cameras"); f.GenSerialize(value.cameras); - } - - if(value.extensionsUsed!=null && value.extensionsUsed.Count>0) - { - f.Key("extensionsUsed"); f.GenSerialize(value.extensionsUsed); - } - - if(false && value.extensionsRequired!=null && value.extensionsRequired.Count>0) - { - f.Key("extensionsRequired"); f.GenSerialize(value.extensionsRequired); - } - - if(value.extensions!=null) - { - f.Key("extensions"); f.GenSerialize(value.extensions); - } - - if(value.extras!=null) - { - f.Key("extras"); f.GenSerialize(value.extras); - } - - f.EndMap(); - } - - /// gltf/asset - public static void GenSerialize(this JsonFormatter f, glTFAssets value) - { - f.BeginMap(0); // dummy - - if(!string.IsNullOrEmpty(value.generator)) - { - f.Key("generator"); f.GenSerialize(value.generator); - } - - if(!string.IsNullOrEmpty(value.version)) - { - f.Key("version"); f.GenSerialize(value.version); - } - - if(!string.IsNullOrEmpty(value.copyright)) - { - f.Key("copyright"); f.GenSerialize(value.copyright); - } - - if(!string.IsNullOrEmpty(value.minVersion)) - { - f.Key("minVersion"); f.GenSerialize(value.minVersion); - } - - if(value.extensions!=null) - { - f.Key("extensions"); f.GenSerialize(value.extensions); - } - - if(value.extras!=null) - { - f.Key("extras"); f.GenSerialize(value.extras); - } - - f.EndMap(); - } - - public static void GenSerialize(this JsonFormatter f, String value) - { - f.Value(value); - } - - /// gltf/buffers - public static void GenSerialize(this JsonFormatter f, List value) - { - f.BeginList(value.Count); - foreach (var x in value) - { - f.GenSerialize(x); - } - f.EndList(); - } - - /// gltf/buffers[] - public static void GenSerialize(this JsonFormatter f, glTFBuffer value) - { - f.BeginMap(0); // dummy - - if(!string.IsNullOrEmpty(value.uri)) - { - f.Key("uri"); f.GenSerialize(value.uri); - } - - - { - f.Key("byteLength"); f.GenSerialize(value.byteLength); - } - - if(value.extensions!=null) - { - f.Key("extensions"); f.GenSerialize(value.extensions); - } - - if(value.extras!=null) - { - f.Key("extras"); f.GenSerialize(value.extras); - } - - if(!string.IsNullOrEmpty(value.name)) - { - f.Key("name"); f.GenSerialize(value.name); - } - - f.EndMap(); - } - - public static void GenSerialize(this JsonFormatter f, Int32 value) - { - f.Value(value); - } - - /// gltf/bufferViews - public static void GenSerialize(this JsonFormatter f, List value) - { - f.BeginList(value.Count); - foreach (var x in value) - { - f.GenSerialize(x); - } - f.EndList(); - } - - /// gltf/bufferViews[] - public static void GenSerialize(this JsonFormatter f, glTFBufferView value) - { - f.BeginMap(0); // dummy - - - { - f.Key("buffer"); f.GenSerialize(value.buffer); - } - - - { - f.Key("byteOffset"); f.GenSerialize(value.byteOffset); - } - - - { - f.Key("byteLength"); f.GenSerialize(value.byteLength); - } - - if(value.target!=0) - { - f.Key("target"); f.GenSerialize(value.target); - } - - if(value.extensions!=null) - { - f.Key("extensions"); f.GenSerialize(value.extensions); - } - - if(value.extras!=null) - { - f.Key("extras"); f.GenSerialize(value.extras); - } - - if(!string.IsNullOrEmpty(value.name)) - { - f.Key("name"); f.GenSerialize(value.name); - } - - f.EndMap(); - } - - public static void GenSerialize(this JsonFormatter f, glBufferTarget value) - { - f.Value((int)value); - } - - /// gltf/accessors - public static void GenSerialize(this JsonFormatter f, List value) - { - f.BeginList(value.Count); - foreach (var x in value) - { - f.GenSerialize(x); - } - f.EndList(); - } - - /// gltf/accessors[] - public static void GenSerialize(this JsonFormatter f, glTFAccessor value) - { - f.BeginMap(0); // dummy - - if(value.bufferView>=0) - { - f.Key("bufferView"); f.GenSerialize(value.bufferView); - } - - if(value.bufferView>=0) - { - f.Key("byteOffset"); f.GenSerialize(value.byteOffset); - } - - if(!string.IsNullOrEmpty(value.type)) - { - f.Key("type"); f.GenSerialize(value.type); - } - - - { - f.Key("componentType"); f.GenSerialize(value.componentType); - } - - - { - f.Key("count"); f.GenSerialize(value.count); - } - - if(value.max!=null && value.max.Length>0) - { - f.Key("max"); f.GenSerialize(value.max); - } - - if(value.min!=null && value.min.Length>0) - { - f.Key("min"); f.GenSerialize(value.min); - } - - - { - f.Key("normalized"); f.GenSerialize(value.normalized); - } - - if(value.sparse!=null && value.sparse.count>0) - { - f.Key("sparse"); f.GenSerialize(value.sparse); - } - - if(!string.IsNullOrEmpty(value.name)) - { - f.Key("name"); f.GenSerialize(value.name); - } - - if(value.extensions!=null) - { - f.Key("extensions"); f.GenSerialize(value.extensions); - } - - if(value.extras!=null) - { - f.Key("extras"); f.GenSerialize(value.extras); - } - - f.EndMap(); - } - - public static void GenSerialize(this JsonFormatter f, glComponentType value) - { - f.Value((int)value); - } - - /// gltf/accessors[]/max - public static void GenSerialize(this JsonFormatter f, Single[] value) - { - f.BeginList(value.Length); - foreach (var x in value) - { - f.GenSerialize(x); - } - f.EndList(); - } - - public static void GenSerialize(this JsonFormatter f, Single value) - { - f.Value(value); - } - - public static void GenSerialize(this JsonFormatter f, Boolean value) - { - f.Value(value); - } - - /// gltf/accessors[]/sparse - public static void GenSerialize(this JsonFormatter f, glTFSparse value) - { - f.BeginMap(0); // dummy - - - { - f.Key("count"); f.GenSerialize(value.count); - } - - if(value.indices!=null) - { - f.Key("indices"); f.GenSerialize(value.indices); - } - - if(value.values!=null) - { - f.Key("values"); f.GenSerialize(value.values); - } - - if(value.extensions!=null) - { - f.Key("extensions"); f.GenSerialize(value.extensions); - } - - if(value.extras!=null) - { - f.Key("extras"); f.GenSerialize(value.extras); - } - - f.EndMap(); - } - - /// gltf/accessors[]/sparse/indices - public static void GenSerialize(this JsonFormatter f, glTFSparseIndices value) - { - f.BeginMap(0); // dummy - - - { - f.Key("bufferView"); f.GenSerialize(value.bufferView); - } - - - { - f.Key("byteOffset"); f.GenSerialize(value.byteOffset); - } - - - { - f.Key("componentType"); f.GenSerialize(value.componentType); - } - - if(value.extensions!=null) - { - f.Key("extensions"); f.GenSerialize(value.extensions); - } - - if(value.extras!=null) - { - f.Key("extras"); f.GenSerialize(value.extras); - } - - f.EndMap(); - } - - /// gltf/accessors[]/sparse/values - public static void GenSerialize(this JsonFormatter f, glTFSparseValues value) - { - f.BeginMap(0); // dummy - - - { - f.Key("bufferView"); f.GenSerialize(value.bufferView); - } - - - { - f.Key("byteOffset"); f.GenSerialize(value.byteOffset); - } - - if(value.extensions!=null) - { - f.Key("extensions"); f.GenSerialize(value.extensions); - } - - if(value.extras!=null) - { - f.Key("extras"); f.GenSerialize(value.extras); - } - - f.EndMap(); - } - - /// gltf/textures - public static void GenSerialize(this JsonFormatter f, List value) - { - f.BeginList(value.Count); - foreach (var x in value) - { - f.GenSerialize(x); - } - f.EndList(); - } - - /// gltf/textures[] - public static void GenSerialize(this JsonFormatter f, glTFTexture value) - { - f.BeginMap(0); // dummy - - - { - f.Key("sampler"); f.GenSerialize(value.sampler); - } - - - { - f.Key("source"); f.GenSerialize(value.source); - } - - if(value.extensions!=null) - { - f.Key("extensions"); f.GenSerialize(value.extensions); - } - - if(value.extras!=null) - { - f.Key("extras"); f.GenSerialize(value.extras); - } - - if(!string.IsNullOrEmpty(value.name)) - { - f.Key("name"); f.GenSerialize(value.name); - } - - f.EndMap(); - } - - /// gltf/samplers - public static void GenSerialize(this JsonFormatter f, List value) - { - f.BeginList(value.Count); - foreach (var x in value) - { - f.GenSerialize(x); - } - f.EndList(); - } - - /// gltf/samplers[] - public static void GenSerialize(this JsonFormatter f, glTFTextureSampler value) - { - f.BeginMap(0); // dummy - - - { - f.Key("magFilter"); f.GenSerialize(value.magFilter); - } - - - { - f.Key("minFilter"); f.GenSerialize(value.minFilter); - } - - - { - f.Key("wrapS"); f.GenSerialize(value.wrapS); - } - - - { - f.Key("wrapT"); f.GenSerialize(value.wrapT); - } - - if(value.extensions!=null) - { - f.Key("extensions"); f.GenSerialize(value.extensions); - } - - if(value.extras!=null) - { - f.Key("extras"); f.GenSerialize(value.extras); - } - - if(!string.IsNullOrEmpty(value.name)) - { - f.Key("name"); f.GenSerialize(value.name); - } - - f.EndMap(); - } - - public static void GenSerialize(this JsonFormatter f, glFilter value) - { - f.Value((int)value); - } - - public static void GenSerialize(this JsonFormatter f, glWrap value) - { - f.Value((int)value); - } - - /// gltf/images - public static void GenSerialize(this JsonFormatter f, List value) - { - f.BeginList(value.Count); - foreach (var x in value) - { - f.GenSerialize(x); - } - f.EndList(); - } - - /// gltf/images[] - public static void GenSerialize(this JsonFormatter f, glTFImage value) - { - f.BeginMap(0); // dummy - - if(!string.IsNullOrEmpty(value.name)) - { - f.Key("name"); f.GenSerialize(value.name); - } - - if(!string.IsNullOrEmpty(value.uri)) - { - f.Key("uri"); f.GenSerialize(value.uri); - } - - - { - f.Key("bufferView"); f.GenSerialize(value.bufferView); - } - - if(!string.IsNullOrEmpty(value.mimeType)) - { - f.Key("mimeType"); f.GenSerialize(value.mimeType); - } - - if(value.extensions!=null) - { - f.Key("extensions"); f.GenSerialize(value.extensions); - } - - if(value.extras!=null) - { - f.Key("extras"); f.GenSerialize(value.extras); - } - - f.EndMap(); - } - - /// gltf/materials - public static void GenSerialize(this JsonFormatter f, List value) - { - f.BeginList(value.Count); - foreach (var x in value) - { - f.GenSerialize(x); - } - f.EndList(); - } - - /// gltf/materials[] - public static void GenSerialize(this JsonFormatter f, glTFMaterial value) - { - f.BeginMap(0); // dummy - - if(!string.IsNullOrEmpty(value.name)) - { - f.Key("name"); f.GenSerialize(value.name); - } - - if(value.pbrMetallicRoughness!=null) - { - f.Key("pbrMetallicRoughness"); f.GenSerialize(value.pbrMetallicRoughness); - } - - if(value.normalTexture!=null) - { - f.Key("normalTexture"); f.GenSerialize(value.normalTexture); - } - - if(value.occlusionTexture!=null) - { - f.Key("occlusionTexture"); f.GenSerialize(value.occlusionTexture); - } - - if(value.emissiveTexture!=null) - { - f.Key("emissiveTexture"); f.GenSerialize(value.emissiveTexture); - } - - if(value.emissiveFactor!=null) - { - f.Key("emissiveFactor"); f.GenSerialize(value.emissiveFactor); - } - - if(!string.IsNullOrEmpty(value.alphaMode)) - { - f.Key("alphaMode"); f.GenSerialize(value.alphaMode); - } - - if(value.alphaMode == "MASK") - { - f.Key("alphaCutoff"); f.GenSerialize(value.alphaCutoff); - } - - - { - f.Key("doubleSided"); f.GenSerialize(value.doubleSided); - } - - if(value.extensions!=null) - { - f.Key("extensions"); f.GenSerialize(value.extensions); - } - - if(value.extras!=null) - { - f.Key("extras"); f.GenSerialize(value.extras); - } - - f.EndMap(); - } - - /// gltf/materials[]/pbrMetallicRoughness - public static void GenSerialize(this JsonFormatter f, glTFPbrMetallicRoughness value) - { - f.BeginMap(0); // dummy - - if(value.baseColorTexture!=null) - { - f.Key("baseColorTexture"); f.GenSerialize(value.baseColorTexture); - } - - if(value.baseColorFactor!=null) - { - f.Key("baseColorFactor"); f.GenSerialize(value.baseColorFactor); - } - - if(value.metallicRoughnessTexture!=null) - { - f.Key("metallicRoughnessTexture"); f.GenSerialize(value.metallicRoughnessTexture); - } - - - { - f.Key("metallicFactor"); f.GenSerialize(value.metallicFactor); - } - - - { - f.Key("roughnessFactor"); f.GenSerialize(value.roughnessFactor); - } - - if(value.extensions!=null) - { - f.Key("extensions"); f.GenSerialize(value.extensions); - } - - if(value.extras!=null) - { - f.Key("extras"); f.GenSerialize(value.extras); - } - - f.EndMap(); - } - - /// gltf/materials[]/pbrMetallicRoughness/baseColorTexture - public static void GenSerialize(this JsonFormatter f, glTFMaterialBaseColorTextureInfo value) - { - f.BeginMap(0); // dummy - - - { - f.Key("index"); f.GenSerialize(value.index); - } - - - { - f.Key("texCoord"); f.GenSerialize(value.texCoord); - } - - if(value.extensions!=null) - { - f.Key("extensions"); f.GenSerialize(value.extensions); - } - - if(value.extras!=null) - { - f.Key("extras"); f.GenSerialize(value.extras); - } - - f.EndMap(); - } - - /// gltf/materials[]/pbrMetallicRoughness/metallicRoughnessTexture - public static void GenSerialize(this JsonFormatter f, glTFMaterialMetallicRoughnessTextureInfo value) - { - f.BeginMap(0); // dummy - - - { - f.Key("index"); f.GenSerialize(value.index); - } - - - { - f.Key("texCoord"); f.GenSerialize(value.texCoord); - } - - if(value.extensions!=null) - { - f.Key("extensions"); f.GenSerialize(value.extensions); - } - - if(value.extras!=null) - { - f.Key("extras"); f.GenSerialize(value.extras); - } - - f.EndMap(); - } - - /// gltf/materials[]/normalTexture - public static void GenSerialize(this JsonFormatter f, glTFMaterialNormalTextureInfo value) - { - f.BeginMap(0); // dummy - - - { - f.Key("scale"); f.GenSerialize(value.scale); - } - - - { - f.Key("index"); f.GenSerialize(value.index); - } - - - { - f.Key("texCoord"); f.GenSerialize(value.texCoord); - } - - if(value.extensions!=null) - { - f.Key("extensions"); f.GenSerialize(value.extensions); - } - - if(value.extras!=null) - { - f.Key("extras"); f.GenSerialize(value.extras); - } - - f.EndMap(); - } - - /// gltf/materials[]/occlusionTexture - public static void GenSerialize(this JsonFormatter f, glTFMaterialOcclusionTextureInfo value) - { - f.BeginMap(0); // dummy - - - { - f.Key("strength"); f.GenSerialize(value.strength); - } - - - { - f.Key("index"); f.GenSerialize(value.index); - } - - - { - f.Key("texCoord"); f.GenSerialize(value.texCoord); - } - - if(value.extensions!=null) - { - f.Key("extensions"); f.GenSerialize(value.extensions); - } - - if(value.extras!=null) - { - f.Key("extras"); f.GenSerialize(value.extras); - } - - f.EndMap(); - } - - /// gltf/materials[]/emissiveTexture - public static void GenSerialize(this JsonFormatter f, glTFMaterialEmissiveTextureInfo value) - { - f.BeginMap(0); // dummy - - - { - f.Key("index"); f.GenSerialize(value.index); - } - - - { - f.Key("texCoord"); f.GenSerialize(value.texCoord); - } - - if(value.extensions!=null) - { - f.Key("extensions"); f.GenSerialize(value.extensions); - } - - if(value.extras!=null) - { - f.Key("extras"); f.GenSerialize(value.extras); - } - - f.EndMap(); - } - - /// gltf/meshes - public static void GenSerialize(this JsonFormatter f, List value) - { - f.BeginList(value.Count); - foreach (var x in value) - { - f.GenSerialize(x); - } - f.EndList(); - } - - /// gltf/meshes[] - public static void GenSerialize(this JsonFormatter f, glTFMesh value) - { - f.BeginMap(0); // dummy - - if(!string.IsNullOrEmpty(value.name)) - { - f.Key("name"); f.GenSerialize(value.name); - } - - if(value.primitives!=null && value.primitives.Count>0) - { - f.Key("primitives"); f.GenSerialize(value.primitives); - } - - if(value.weights!=null && value.weights.Length>0) - { - f.Key("weights"); f.GenSerialize(value.weights); - } - - if(value.extras!=null) - { - f.Key("extras"); f.GenSerialize(value.extras); - } - - if(value.extensions!=null) - { - f.Key("extensions"); f.GenSerialize(value.extensions); - } - - f.EndMap(); - } - - /// gltf/meshes[]/primitives - public static void GenSerialize(this JsonFormatter f, List value) - { - f.BeginList(value.Count); - foreach (var x in value) - { - f.GenSerialize(x); - } - f.EndList(); - } - - /// gltf/meshes[]/primitives[] - public static void GenSerialize(this JsonFormatter f, glTFPrimitives value) - { - f.BeginMap(0); // dummy - - - { - f.Key("mode"); f.GenSerialize(value.mode); - } - - - { - f.Key("indices"); f.GenSerialize(value.indices); - } - - if(value.attributes!=null) - { - f.Key("attributes"); f.GenSerialize(value.attributes); - } - - - { - f.Key("material"); f.GenSerialize(value.material); - } - - if(value.targets!=null && value.targets.Count>0) - { - f.Key("targets"); f.GenSerialize(value.targets); - } - - if(value.extras!=null) - { - f.Key("extras"); f.GenSerialize(value.extras); - } - - if(value.extensions!=null) - { - f.Key("extensions"); f.GenSerialize(value.extensions); - } - - f.EndMap(); - } - - /// gltf/meshes[]/primitives[]/attributes - public static void GenSerialize(this JsonFormatter f, glTFAttributes value) - { - f.BeginMap(0); // dummy - - if(value.POSITION!=-1) - { - f.Key("POSITION"); f.GenSerialize(value.POSITION); - } - - if(value.NORMAL!=-1) - { - f.Key("NORMAL"); f.GenSerialize(value.NORMAL); - } - - if(value.TANGENT!=-1) - { - f.Key("TANGENT"); f.GenSerialize(value.TANGENT); - } - - if(value.TEXCOORD_0!=-1) - { - f.Key("TEXCOORD_0"); f.GenSerialize(value.TEXCOORD_0); - } - - if(value.TEXCOORD_1!=-1) - { - f.Key("TEXCOORD_1"); f.GenSerialize(value.TEXCOORD_1); - } - - if(value.COLOR_0!=-1) - { - f.Key("COLOR_0"); f.GenSerialize(value.COLOR_0); - } - - if(value.JOINTS_0!=-1) - { - f.Key("JOINTS_0"); f.GenSerialize(value.JOINTS_0); - } - - if(value.WEIGHTS_0!=-1) - { - f.Key("WEIGHTS_0"); f.GenSerialize(value.WEIGHTS_0); - } - - f.EndMap(); - } - - /// gltf/meshes[]/primitives[]/targets - public static void GenSerialize(this JsonFormatter f, List value) - { - f.BeginList(value.Count); - foreach (var x in value) - { - f.GenSerialize(x); - } - f.EndList(); - } - - /// gltf/meshes[]/primitives[]/targets[] - public static void GenSerialize(this JsonFormatter f, gltfMorphTarget value) - { - f.BeginMap(0); // dummy - - if(value.POSITION!=-1) - { - f.Key("POSITION"); f.GenSerialize(value.POSITION); - } - - if(value.NORMAL!=-1) - { - f.Key("NORMAL"); f.GenSerialize(value.NORMAL); - } - - if(value.TANGENT!=-1) - { - f.Key("TANGENT"); f.GenSerialize(value.TANGENT); - } - - f.EndMap(); - } - - /// gltf/nodes - public static void GenSerialize(this JsonFormatter f, List value) - { - f.BeginList(value.Count); - foreach (var x in value) - { - f.GenSerialize(x); - } - f.EndList(); - } - - /// gltf/nodes[] - public static void GenSerialize(this JsonFormatter f, glTFNode value) - { - f.BeginMap(0); // dummy - - if(!string.IsNullOrEmpty(value.name)) - { - f.Key("name"); f.GenSerialize(value.name); - } - - if(value.children != null && value.children.Length>0) - { - f.Key("children"); f.GenSerialize(value.children); - } - - if(value.matrix!=null) - { - f.Key("matrix"); f.GenSerialize(value.matrix); - } - - if(value.translation!=null) - { - f.Key("translation"); f.GenSerialize(value.translation); - } - - if(value.rotation!=null) - { - f.Key("rotation"); f.GenSerialize(value.rotation); - } - - if(value.scale!=null) - { - f.Key("scale"); f.GenSerialize(value.scale); - } - - if(value.mesh!=-1) - { - f.Key("mesh"); f.GenSerialize(value.mesh); - } - - if(value.skin!=-1) - { - f.Key("skin"); f.GenSerialize(value.skin); - } - - if(value.weights!=null) - { - f.Key("weights"); f.GenSerialize(value.weights); - } - - if(value.camera!=-1) - { - f.Key("camera"); f.GenSerialize(value.camera); - } - - if(value.extensions!=null) - { - f.Key("extensions"); f.GenSerialize(value.extensions); - } - - if(value.extras!=null) - { - f.Key("extras"); f.GenSerialize(value.extras); - } - - f.EndMap(); - } - - /// gltf/nodes[]/children - public static void GenSerialize(this JsonFormatter f, Int32[] value) - { - f.BeginList(value.Length); - foreach (var x in value) - { - f.GenSerialize(x); - } - f.EndList(); - } - - /// gltf/skins - public static void GenSerialize(this JsonFormatter f, List value) - { - f.BeginList(value.Count); - foreach (var x in value) - { - f.GenSerialize(x); - } - f.EndList(); - } - - /// gltf/skins[] - public static void GenSerialize(this JsonFormatter f, glTFSkin value) - { - f.BeginMap(0); // dummy - - - { - f.Key("inverseBindMatrices"); f.GenSerialize(value.inverseBindMatrices); - } - - if(value.joints!=null && value.joints.Length>0) - { - f.Key("joints"); f.GenSerialize(value.joints); - } - - if(value.skeleton!=-1) - { - f.Key("skeleton"); f.GenSerialize(value.skeleton); - } - - if(value.extensions!=null) - { - f.Key("extensions"); f.GenSerialize(value.extensions); - } - - if(value.extras!=null) - { - f.Key("extras"); f.GenSerialize(value.extras); - } - - if(!string.IsNullOrEmpty(value.name)) - { - f.Key("name"); f.GenSerialize(value.name); - } - - f.EndMap(); - } - - /// gltf/scenes - public static void GenSerialize(this JsonFormatter f, List value) - { - f.BeginList(value.Count); - foreach (var x in value) - { - f.GenSerialize(x); - } - f.EndList(); - } - - /// gltf/scenes[] - public static void GenSerialize(this JsonFormatter f, gltfScene value) - { - f.BeginMap(0); // dummy - - if(value.nodes!=null && value.nodes.Length>0) - { - f.Key("nodes"); f.GenSerialize(value.nodes); - } - - if(value.extensions!=null) - { - f.Key("extensions"); f.GenSerialize(value.extensions); - } - - if(value.extras!=null) - { - f.Key("extras"); f.GenSerialize(value.extras); - } - - if(!string.IsNullOrEmpty(value.name)) - { - f.Key("name"); f.GenSerialize(value.name); - } - - f.EndMap(); - } - - /// gltf/animations - public static void GenSerialize(this JsonFormatter f, List value) - { - f.BeginList(value.Count); - foreach (var x in value) - { - f.GenSerialize(x); - } - f.EndList(); - } - - /// gltf/animations[] - public static void GenSerialize(this JsonFormatter f, glTFAnimation value) - { - f.BeginMap(0); // dummy - - if(!string.IsNullOrEmpty(value.name)) - { - f.Key("name"); f.GenSerialize(value.name); - } - - if(value.channels!=null && value.channels.Count>0) - { - f.Key("channels"); f.GenSerialize(value.channels); - } - - if(value.samplers!=null && value.samplers.Count>0) - { - f.Key("samplers"); f.GenSerialize(value.samplers); - } - - if(value.extensions!=null) - { - f.Key("extensions"); f.GenSerialize(value.extensions); - } - - if(value.extras!=null) - { - f.Key("extras"); f.GenSerialize(value.extras); - } - - f.EndMap(); - } - - /// gltf/animations[]/channels - public static void GenSerialize(this JsonFormatter f, List value) - { - f.BeginList(value.Count); - foreach (var x in value) - { - f.GenSerialize(x); - } - f.EndList(); - } - - /// gltf/animations[]/channels[] - public static void GenSerialize(this JsonFormatter f, glTFAnimationChannel value) - { - f.BeginMap(0); // dummy - - - { - f.Key("sampler"); f.GenSerialize(value.sampler); - } - - if(value!=null) - { - f.Key("target"); f.GenSerialize(value.target); - } - - if(value.extensions!=null) - { - f.Key("extensions"); f.GenSerialize(value.extensions); - } - - if(value.extras!=null) - { - f.Key("extras"); f.GenSerialize(value.extras); - } - - f.EndMap(); - } - - /// gltf/animations[]/channels[]/target - public static void GenSerialize(this JsonFormatter f, glTFAnimationTarget value) - { - f.BeginMap(0); // dummy - - - { - f.Key("node"); f.GenSerialize(value.node); - } - - if(!string.IsNullOrEmpty(value.path)) - { - f.Key("path"); f.GenSerialize(value.path); - } - - if(value.extensions!=null) - { - f.Key("extensions"); f.GenSerialize(value.extensions); - } - - if(value.extras!=null) - { - f.Key("extras"); f.GenSerialize(value.extras); - } - - f.EndMap(); - } - - /// gltf/animations[]/samplers - public static void GenSerialize(this JsonFormatter f, List value) - { - f.BeginList(value.Count); - foreach (var x in value) - { - f.GenSerialize(x); - } - f.EndList(); - } - - /// gltf/animations[]/samplers[] - public static void GenSerialize(this JsonFormatter f, glTFAnimationSampler value) - { - f.BeginMap(0); // dummy - - - { - f.Key("input"); f.GenSerialize(value.input); - } - - if(!string.IsNullOrEmpty(value.interpolation)) - { - f.Key("interpolation"); f.GenSerialize(value.interpolation); - } - - - { - f.Key("output"); f.GenSerialize(value.output); - } - - if(value.extensions!=null) - { - f.Key("extensions"); f.GenSerialize(value.extensions); - } - - if(value.extras!=null) - { - f.Key("extras"); f.GenSerialize(value.extras); - } - - f.EndMap(); - } - - /// gltf/cameras - public static void GenSerialize(this JsonFormatter f, List value) - { - f.BeginList(value.Count); - foreach (var x in value) - { - f.GenSerialize(x); - } - f.EndList(); - } - - /// gltf/cameras[] - public static void GenSerialize(this JsonFormatter f, glTFCamera value) - { - f.BeginMap(0); // dummy - - if(value.orthographic!=null) - { - f.Key("orthographic"); f.GenSerialize(value.orthographic); - } - - if(value.perspective!=null) - { - f.Key("perspective"); f.GenSerialize(value.perspective); - } - - - { - f.Key("type"); f.GenSerialize(value.type); - } - - if(!string.IsNullOrEmpty(value.name)) - { - f.Key("name"); f.GenSerialize(value.name); - } - - if(value.extensions!=null) - { - f.Key("extensions"); f.GenSerialize(value.extensions); - } - - if(value.extras!=null) - { - f.Key("extras"); f.GenSerialize(value.extras); - } - - f.EndMap(); - } - - /// gltf/cameras[]/orthographic - public static void GenSerialize(this JsonFormatter f, glTFOrthographic value) - { - f.BeginMap(0); // dummy - - - { - f.Key("xmag"); f.GenSerialize(value.xmag); - } - - - { - f.Key("ymag"); f.GenSerialize(value.ymag); - } - - - { - f.Key("zfar"); f.GenSerialize(value.zfar); - } - - - { - f.Key("znear"); f.GenSerialize(value.znear); - } - - if(value.extensions!=null) - { - f.Key("extensions"); f.GenSerialize(value.extensions); - } - - if(value.extras!=null) - { - f.Key("extras"); f.GenSerialize(value.extras); - } - - f.EndMap(); - } - - /// gltf/cameras[]/perspective - public static void GenSerialize(this JsonFormatter f, glTFPerspective value) - { - f.BeginMap(0); // dummy - - - { - f.Key("aspectRatio"); f.GenSerialize(value.aspectRatio); - } - - - { - f.Key("yfov"); f.GenSerialize(value.yfov); - } - - - { - f.Key("zfar"); f.GenSerialize(value.zfar); - } - - - { - f.Key("znear"); f.GenSerialize(value.znear); - } - - if(value.extensions!=null) - { - f.Key("extensions"); f.GenSerialize(value.extensions); - } - - if(value.extras!=null) - { - f.Key("extras"); f.GenSerialize(value.extras); - } - - f.EndMap(); - } - - public static void GenSerialize(this JsonFormatter f, ProjectionType value) - { - f.Value((int)value); - } - - /// gltf/extensionsUsed - public static void GenSerialize(this JsonFormatter f, List value) - { - f.BeginList(value.Count); - foreach (var x in value) - { - f.GenSerialize(x); - } - f.EndList(); - } - - } // class -} // namespace diff --git a/Assets/UniGLTF/UniGLTF/Scripts/IO/GltfSerializer.g.cs b/Assets/UniGLTF/UniGLTF/Scripts/IO/GltfSerializer.g.cs new file mode 100644 index 000000000..99f59bc6d --- /dev/null +++ b/Assets/UniGLTF/UniGLTF/Scripts/IO/GltfSerializer.g.cs @@ -0,0 +1,1261 @@ +using System; +using System.Collections.Generic; +using UniJSON; + +namespace UniGLTF { + + static public class GltfSerializer + { + + +public static void Serialize(JsonFormatter f, glTF value) +{ + f.BeginMap(); + + f.Key("asset"); + Serialize_gltf_asset(f, value.asset); + + f.Key("buffers"); + Serialize_gltf_buffers(f, value.buffers); + + f.Key("bufferViews"); + Serialize_gltf_bufferViews(f, value.bufferViews); + + f.Key("accessors"); + Serialize_gltf_accessors(f, value.accessors); + + f.Key("textures"); + Serialize_gltf_textures(f, value.textures); + + f.Key("samplers"); + Serialize_gltf_samplers(f, value.samplers); + + f.Key("images"); + Serialize_gltf_images(f, value.images); + + f.Key("materials"); + Serialize_gltf_materials(f, value.materials); + + f.Key("meshes"); + Serialize_gltf_meshes(f, value.meshes); + + f.Key("nodes"); + Serialize_gltf_nodes(f, value.nodes); + + f.Key("skins"); + Serialize_gltf_skins(f, value.skins); + + f.Key("scene"); + f.Value(value.scene); + + f.Key("scenes"); + Serialize_gltf_scenes(f, value.scenes); + + f.Key("animations"); + Serialize_gltf_animations(f, value.animations); + + f.Key("cameras"); + Serialize_gltf_cameras(f, value.cameras); + + f.Key("extensionsUsed"); + Serialize_gltf_extensionsUsed(f, value.extensionsUsed); + + f.Key("extensionsRequired"); + Serialize_gltf_extensionsRequired(f, value.extensionsRequired); + + f.Key("extensions"); + value.extras.Serialize(f); + + f.Key("extras"); + value.extras.Serialize(f); + + + f.EndMap(); +} + +public static void Serialize_gltf_asset(JsonFormatter f, glTFAssets value) +{ + f.BeginMap(); + + f.Key("generator"); + f.Value(value.generator); + + f.Key("version"); + f.Value(value.version); + + f.Key("copyright"); + f.Value(value.copyright); + + f.Key("minVersion"); + f.Value(value.minVersion); + + f.Key("extensions"); + value.extras.Serialize(f); + + f.Key("extras"); + value.extras.Serialize(f); + + + f.EndMap(); +} + +public static void Serialize_gltf_buffers(JsonFormatter f, List value) +{ + f.BeginList(); + + foreach(var item in value) + { + Serialize_gltf_buffers_LIST(f, item); + + } + f.EndList(); +} + +public static void Serialize_gltf_buffers_LIST(JsonFormatter f, glTFBuffer value) +{ + f.BeginMap(); + + f.Key("uri"); + f.Value(value.uri); + + f.Key("byteLength"); + f.Value(value.byteLength); + + f.Key("extensions"); + value.extras.Serialize(f); + + f.Key("extras"); + value.extras.Serialize(f); + + f.Key("name"); + f.Value(value.name); + + + f.EndMap(); +} + +public static void Serialize_gltf_bufferViews(JsonFormatter f, List value) +{ + f.BeginList(); + + foreach(var item in value) + { + Serialize_gltf_bufferViews_LIST(f, item); + + } + f.EndList(); +} + +public static void Serialize_gltf_bufferViews_LIST(JsonFormatter f, glTFBufferView value) +{ + f.BeginMap(); + + f.Key("buffer"); + f.Value(value.buffer); + + f.Key("byteOffset"); + f.Value(value.byteOffset); + + f.Key("byteLength"); + f.Value(value.byteLength); + + f.Key("byteStride"); + f.Value(value.byteStride); + + f.Key("target"); + f.Value((int)value.target); + + f.Key("extensions"); + value.extras.Serialize(f); + + f.Key("extras"); + value.extras.Serialize(f); + + f.Key("name"); + f.Value(value.name); + + + f.EndMap(); +} + +public static void Serialize_gltf_accessors(JsonFormatter f, List value) +{ + f.BeginList(); + + foreach(var item in value) + { + Serialize_gltf_accessors_LIST(f, item); + + } + f.EndList(); +} + +public static void Serialize_gltf_accessors_LIST(JsonFormatter f, glTFAccessor value) +{ + f.BeginMap(); + + f.Key("bufferView"); + f.Value(value.bufferView); + + f.Key("byteOffset"); + f.Value(value.byteOffset); + + f.Key("type"); + f.Value(value.type); + + f.Key("componentType"); + f.Value((int)value.componentType); + + f.Key("count"); + f.Value(value.count); + + f.Key("max"); + Serialize_gltf_accessors__max(f, value.max); + + f.Key("min"); + Serialize_gltf_accessors__min(f, value.min); + + f.Key("normalized"); + f.Value(value.normalized); + + f.Key("sparse"); + Serialize_gltf_accessors__sparse(f, value.sparse); + + f.Key("name"); + f.Value(value.name); + + f.Key("extensions"); + value.extras.Serialize(f); + + f.Key("extras"); + value.extras.Serialize(f); + + + f.EndMap(); +} + +public static void Serialize_gltf_accessors__max(JsonFormatter f, Single[] value) +{ + f.BeginList(); + + foreach(var item in value) + { + f.Value(item); + + } + f.EndList(); +} + +public static void Serialize_gltf_accessors__min(JsonFormatter f, Single[] value) +{ + f.BeginList(); + + foreach(var item in value) + { + f.Value(item); + + } + f.EndList(); +} + +public static void Serialize_gltf_accessors__sparse(JsonFormatter f, glTFSparse value) +{ + f.BeginMap(); + + f.Key("count"); + f.Value(value.count); + + f.Key("indices"); + Serialize_gltf_accessors__sparse_indices(f, value.indices); + + f.Key("values"); + Serialize_gltf_accessors__sparse_values(f, value.values); + + f.Key("extensions"); + value.extras.Serialize(f); + + f.Key("extras"); + value.extras.Serialize(f); + + + f.EndMap(); +} + +public static void Serialize_gltf_accessors__sparse_indices(JsonFormatter f, glTFSparseIndices value) +{ + f.BeginMap(); + + f.Key("bufferView"); + f.Value(value.bufferView); + + f.Key("byteOffset"); + f.Value(value.byteOffset); + + f.Key("componentType"); + f.Value((int)value.componentType); + + f.Key("extensions"); + value.extras.Serialize(f); + + f.Key("extras"); + value.extras.Serialize(f); + + + f.EndMap(); +} + +public static void Serialize_gltf_accessors__sparse_values(JsonFormatter f, glTFSparseValues value) +{ + f.BeginMap(); + + f.Key("bufferView"); + f.Value(value.bufferView); + + f.Key("byteOffset"); + f.Value(value.byteOffset); + + f.Key("extensions"); + value.extras.Serialize(f); + + f.Key("extras"); + value.extras.Serialize(f); + + + f.EndMap(); +} + +public static void Serialize_gltf_textures(JsonFormatter f, List value) +{ + f.BeginList(); + + foreach(var item in value) + { + Serialize_gltf_textures_LIST(f, item); + + } + f.EndList(); +} + +public static void Serialize_gltf_textures_LIST(JsonFormatter f, glTFTexture value) +{ + f.BeginMap(); + + f.Key("sampler"); + f.Value(value.sampler); + + f.Key("source"); + f.Value(value.source); + + f.Key("extensions"); + value.extras.Serialize(f); + + f.Key("extras"); + value.extras.Serialize(f); + + f.Key("name"); + f.Value(value.name); + + + f.EndMap(); +} + +public static void Serialize_gltf_samplers(JsonFormatter f, List value) +{ + f.BeginList(); + + foreach(var item in value) + { + Serialize_gltf_samplers_LIST(f, item); + + } + f.EndList(); +} + +public static void Serialize_gltf_samplers_LIST(JsonFormatter f, glTFTextureSampler value) +{ + f.BeginMap(); + + f.Key("magFilter"); + f.Value((int)value.magFilter); + + f.Key("minFilter"); + f.Value((int)value.minFilter); + + f.Key("wrapS"); + f.Value((int)value.wrapS); + + f.Key("wrapT"); + f.Value((int)value.wrapT); + + f.Key("extensions"); + value.extras.Serialize(f); + + f.Key("extras"); + value.extras.Serialize(f); + + f.Key("name"); + f.Value(value.name); + + + f.EndMap(); +} + +public static void Serialize_gltf_images(JsonFormatter f, List value) +{ + f.BeginList(); + + foreach(var item in value) + { + Serialize_gltf_images_LIST(f, item); + + } + f.EndList(); +} + +public static void Serialize_gltf_images_LIST(JsonFormatter f, glTFImage value) +{ + f.BeginMap(); + + f.Key("name"); + f.Value(value.name); + + f.Key("uri"); + f.Value(value.uri); + + f.Key("bufferView"); + f.Value(value.bufferView); + + f.Key("mimeType"); + f.Value(value.mimeType); + + f.Key("extensions"); + value.extras.Serialize(f); + + f.Key("extras"); + value.extras.Serialize(f); + + + f.EndMap(); +} + +public static void Serialize_gltf_materials(JsonFormatter f, List value) +{ + f.BeginList(); + + foreach(var item in value) + { + Serialize_gltf_materials_LIST(f, item); + + } + f.EndList(); +} + +public static void Serialize_gltf_materials_LIST(JsonFormatter f, glTFMaterial value) +{ + f.BeginMap(); + + f.Key("name"); + f.Value(value.name); + + f.Key("pbrMetallicRoughness"); + Serialize_gltf_materials__pbrMetallicRoughness(f, value.pbrMetallicRoughness); + + f.Key("normalTexture"); + Serialize_gltf_materials__normalTexture(f, value.normalTexture); + + f.Key("occlusionTexture"); + Serialize_gltf_materials__occlusionTexture(f, value.occlusionTexture); + + f.Key("emissiveTexture"); + Serialize_gltf_materials__emissiveTexture(f, value.emissiveTexture); + + f.Key("emissiveFactor"); + Serialize_gltf_materials__emissiveFactor(f, value.emissiveFactor); + + f.Key("alphaMode"); + f.Value(value.alphaMode); + + f.Key("alphaCutoff"); + f.Value(value.alphaCutoff); + + f.Key("doubleSided"); + f.Value(value.doubleSided); + + f.Key("extensions"); + value.extras.Serialize(f); + + f.Key("extras"); + value.extras.Serialize(f); + + + f.EndMap(); +} + +public static void Serialize_gltf_materials__pbrMetallicRoughness(JsonFormatter f, glTFPbrMetallicRoughness value) +{ + f.BeginMap(); + + f.Key("baseColorTexture"); + Serialize_gltf_materials__pbrMetallicRoughness_baseColorTexture(f, value.baseColorTexture); + + f.Key("baseColorFactor"); + Serialize_gltf_materials__pbrMetallicRoughness_baseColorFactor(f, value.baseColorFactor); + + f.Key("metallicRoughnessTexture"); + Serialize_gltf_materials__pbrMetallicRoughness_metallicRoughnessTexture(f, value.metallicRoughnessTexture); + + f.Key("metallicFactor"); + f.Value(value.metallicFactor); + + f.Key("roughnessFactor"); + f.Value(value.roughnessFactor); + + f.Key("extensions"); + value.extras.Serialize(f); + + f.Key("extras"); + value.extras.Serialize(f); + + + f.EndMap(); +} + +public static void Serialize_gltf_materials__pbrMetallicRoughness_baseColorTexture(JsonFormatter f, glTFMaterialBaseColorTextureInfo value) +{ + f.BeginMap(); + + f.Key("index"); + f.Value(value.index); + + f.Key("texCoord"); + f.Value(value.texCoord); + + f.Key("extensions"); + value.extras.Serialize(f); + + f.Key("extras"); + value.extras.Serialize(f); + + + f.EndMap(); +} + +public static void Serialize_gltf_materials__pbrMetallicRoughness_baseColorFactor(JsonFormatter f, Single[] value) +{ + f.BeginList(); + + foreach(var item in value) + { + f.Value(item); + + } + f.EndList(); +} + +public static void Serialize_gltf_materials__pbrMetallicRoughness_metallicRoughnessTexture(JsonFormatter f, glTFMaterialMetallicRoughnessTextureInfo value) +{ + f.BeginMap(); + + f.Key("index"); + f.Value(value.index); + + f.Key("texCoord"); + f.Value(value.texCoord); + + f.Key("extensions"); + value.extras.Serialize(f); + + f.Key("extras"); + value.extras.Serialize(f); + + + f.EndMap(); +} + +public static void Serialize_gltf_materials__normalTexture(JsonFormatter f, glTFMaterialNormalTextureInfo value) +{ + f.BeginMap(); + + f.Key("scale"); + f.Value(value.scale); + + f.Key("index"); + f.Value(value.index); + + f.Key("texCoord"); + f.Value(value.texCoord); + + f.Key("extensions"); + value.extras.Serialize(f); + + f.Key("extras"); + value.extras.Serialize(f); + + + f.EndMap(); +} + +public static void Serialize_gltf_materials__occlusionTexture(JsonFormatter f, glTFMaterialOcclusionTextureInfo value) +{ + f.BeginMap(); + + f.Key("strength"); + f.Value(value.strength); + + f.Key("index"); + f.Value(value.index); + + f.Key("texCoord"); + f.Value(value.texCoord); + + f.Key("extensions"); + value.extras.Serialize(f); + + f.Key("extras"); + value.extras.Serialize(f); + + + f.EndMap(); +} + +public static void Serialize_gltf_materials__emissiveTexture(JsonFormatter f, glTFMaterialEmissiveTextureInfo value) +{ + f.BeginMap(); + + f.Key("index"); + f.Value(value.index); + + f.Key("texCoord"); + f.Value(value.texCoord); + + f.Key("extensions"); + value.extras.Serialize(f); + + f.Key("extras"); + value.extras.Serialize(f); + + + f.EndMap(); +} + +public static void Serialize_gltf_materials__emissiveFactor(JsonFormatter f, Single[] value) +{ + f.BeginList(); + + foreach(var item in value) + { + f.Value(item); + + } + f.EndList(); +} + +public static void Serialize_gltf_meshes(JsonFormatter f, List value) +{ + f.BeginList(); + + foreach(var item in value) + { + Serialize_gltf_meshes_LIST(f, item); + + } + f.EndList(); +} + +public static void Serialize_gltf_meshes_LIST(JsonFormatter f, glTFMesh value) +{ + f.BeginMap(); + + f.Key("name"); + f.Value(value.name); + + f.Key("primitives"); + Serialize_gltf_meshes__primitives(f, value.primitives); + + f.Key("weights"); + Serialize_gltf_meshes__weights(f, value.weights); + + f.Key("extras"); + value.extras.Serialize(f); + + f.Key("extensions"); + value.extras.Serialize(f); + + + f.EndMap(); +} + +public static void Serialize_gltf_meshes__primitives(JsonFormatter f, List value) +{ + f.BeginList(); + + foreach(var item in value) + { + Serialize_gltf_meshes__primitives_LIST(f, item); + + } + f.EndList(); +} + +public static void Serialize_gltf_meshes__primitives_LIST(JsonFormatter f, glTFPrimitives value) +{ + f.BeginMap(); + + f.Key("mode"); + f.Value(value.mode); + + f.Key("indices"); + f.Value(value.indices); + + f.Key("attributes"); + Serialize_gltf_meshes__primitives__attributes(f, value.attributes); + + f.Key("material"); + f.Value(value.material); + + f.Key("targets"); + Serialize_gltf_meshes__primitives__targets(f, value.targets); + + f.Key("extras"); + value.extras.Serialize(f); + + f.Key("extensions"); + value.extras.Serialize(f); + + + f.EndMap(); +} + +public static void Serialize_gltf_meshes__primitives__attributes(JsonFormatter f, glTFAttributes value) +{ + f.BeginMap(); + + f.Key("POSITION"); + f.Value(value.POSITION); + + f.Key("NORMAL"); + f.Value(value.NORMAL); + + f.Key("TANGENT"); + f.Value(value.TANGENT); + + f.Key("TEXCOORD_0"); + f.Value(value.TEXCOORD_0); + + f.Key("TEXCOORD_1"); + f.Value(value.TEXCOORD_1); + + f.Key("COLOR_0"); + f.Value(value.COLOR_0); + + f.Key("JOINTS_0"); + f.Value(value.JOINTS_0); + + f.Key("WEIGHTS_0"); + f.Value(value.WEIGHTS_0); + + + f.EndMap(); +} + +public static void Serialize_gltf_meshes__primitives__targets(JsonFormatter f, List value) +{ + f.BeginList(); + + foreach(var item in value) + { + Serialize_gltf_meshes__primitives__targets_LIST(f, item); + + } + f.EndList(); +} + +public static void Serialize_gltf_meshes__primitives__targets_LIST(JsonFormatter f, gltfMorphTarget value) +{ + f.BeginMap(); + + f.Key("POSITION"); + f.Value(value.POSITION); + + f.Key("NORMAL"); + f.Value(value.NORMAL); + + f.Key("TANGENT"); + f.Value(value.TANGENT); + + + f.EndMap(); +} + +public static void Serialize_gltf_meshes__weights(JsonFormatter f, Single[] value) +{ + f.BeginList(); + + foreach(var item in value) + { + f.Value(item); + + } + f.EndList(); +} + +public static void Serialize_gltf_nodes(JsonFormatter f, List value) +{ + f.BeginList(); + + foreach(var item in value) + { + Serialize_gltf_nodes_LIST(f, item); + + } + f.EndList(); +} + +public static void Serialize_gltf_nodes_LIST(JsonFormatter f, glTFNode value) +{ + f.BeginMap(); + + f.Key("name"); + f.Value(value.name); + + f.Key("children"); + Serialize_gltf_nodes__children(f, value.children); + + f.Key("matrix"); + Serialize_gltf_nodes__matrix(f, value.matrix); + + f.Key("translation"); + Serialize_gltf_nodes__translation(f, value.translation); + + f.Key("rotation"); + Serialize_gltf_nodes__rotation(f, value.rotation); + + f.Key("scale"); + Serialize_gltf_nodes__scale(f, value.scale); + + f.Key("mesh"); + f.Value(value.mesh); + + f.Key("skin"); + f.Value(value.skin); + + f.Key("weights"); + Serialize_gltf_nodes__weights(f, value.weights); + + f.Key("camera"); + f.Value(value.camera); + + f.Key("extensions"); + value.extras.Serialize(f); + + f.Key("extras"); + value.extras.Serialize(f); + + + f.EndMap(); +} + +public static void Serialize_gltf_nodes__children(JsonFormatter f, Int32[] value) +{ + f.BeginList(); + + foreach(var item in value) + { + f.Value(item); + + } + f.EndList(); +} + +public static void Serialize_gltf_nodes__matrix(JsonFormatter f, Single[] value) +{ + f.BeginList(); + + foreach(var item in value) + { + f.Value(item); + + } + f.EndList(); +} + +public static void Serialize_gltf_nodes__translation(JsonFormatter f, Single[] value) +{ + f.BeginList(); + + foreach(var item in value) + { + f.Value(item); + + } + f.EndList(); +} + +public static void Serialize_gltf_nodes__rotation(JsonFormatter f, Single[] value) +{ + f.BeginList(); + + foreach(var item in value) + { + f.Value(item); + + } + f.EndList(); +} + +public static void Serialize_gltf_nodes__scale(JsonFormatter f, Single[] value) +{ + f.BeginList(); + + foreach(var item in value) + { + f.Value(item); + + } + f.EndList(); +} + +public static void Serialize_gltf_nodes__weights(JsonFormatter f, Single[] value) +{ + f.BeginList(); + + foreach(var item in value) + { + f.Value(item); + + } + f.EndList(); +} + +public static void Serialize_gltf_skins(JsonFormatter f, List value) +{ + f.BeginList(); + + foreach(var item in value) + { + Serialize_gltf_skins_LIST(f, item); + + } + f.EndList(); +} + +public static void Serialize_gltf_skins_LIST(JsonFormatter f, glTFSkin value) +{ + f.BeginMap(); + + f.Key("inverseBindMatrices"); + f.Value(value.inverseBindMatrices); + + f.Key("joints"); + Serialize_gltf_skins__joints(f, value.joints); + + f.Key("skeleton"); + f.Value(value.skeleton); + + f.Key("extensions"); + value.extras.Serialize(f); + + f.Key("extras"); + value.extras.Serialize(f); + + f.Key("name"); + f.Value(value.name); + + + f.EndMap(); +} + +public static void Serialize_gltf_skins__joints(JsonFormatter f, Int32[] value) +{ + f.BeginList(); + + foreach(var item in value) + { + f.Value(item); + + } + f.EndList(); +} + +public static void Serialize_gltf_scenes(JsonFormatter f, List value) +{ + f.BeginList(); + + foreach(var item in value) + { + Serialize_gltf_scenes_LIST(f, item); + + } + f.EndList(); +} + +public static void Serialize_gltf_scenes_LIST(JsonFormatter f, gltfScene value) +{ + f.BeginMap(); + + f.Key("nodes"); + Serialize_gltf_scenes__nodes(f, value.nodes); + + f.Key("extensions"); + value.extras.Serialize(f); + + f.Key("extras"); + value.extras.Serialize(f); + + f.Key("name"); + f.Value(value.name); + + + f.EndMap(); +} + +public static void Serialize_gltf_scenes__nodes(JsonFormatter f, Int32[] value) +{ + f.BeginList(); + + foreach(var item in value) + { + f.Value(item); + + } + f.EndList(); +} + +public static void Serialize_gltf_animations(JsonFormatter f, List value) +{ + f.BeginList(); + + foreach(var item in value) + { + Serialize_gltf_animations_LIST(f, item); + + } + f.EndList(); +} + +public static void Serialize_gltf_animations_LIST(JsonFormatter f, glTFAnimation value) +{ + f.BeginMap(); + + f.Key("name"); + f.Value(value.name); + + f.Key("channels"); + Serialize_gltf_animations__channels(f, value.channels); + + f.Key("samplers"); + Serialize_gltf_animations__samplers(f, value.samplers); + + f.Key("extensions"); + value.extras.Serialize(f); + + f.Key("extras"); + value.extras.Serialize(f); + + + f.EndMap(); +} + +public static void Serialize_gltf_animations__channels(JsonFormatter f, List value) +{ + f.BeginList(); + + foreach(var item in value) + { + Serialize_gltf_animations__channels_LIST(f, item); + + } + f.EndList(); +} + +public static void Serialize_gltf_animations__channels_LIST(JsonFormatter f, glTFAnimationChannel value) +{ + f.BeginMap(); + + f.Key("sampler"); + f.Value(value.sampler); + + f.Key("target"); + Serialize_gltf_animations__channels__target(f, value.target); + + f.Key("extensions"); + value.extras.Serialize(f); + + f.Key("extras"); + value.extras.Serialize(f); + + + f.EndMap(); +} + +public static void Serialize_gltf_animations__channels__target(JsonFormatter f, glTFAnimationTarget value) +{ + f.BeginMap(); + + f.Key("node"); + f.Value(value.node); + + f.Key("path"); + f.Value(value.path); + + f.Key("extensions"); + value.extras.Serialize(f); + + f.Key("extras"); + value.extras.Serialize(f); + + + f.EndMap(); +} + +public static void Serialize_gltf_animations__samplers(JsonFormatter f, List value) +{ + f.BeginList(); + + foreach(var item in value) + { + Serialize_gltf_animations__samplers_LIST(f, item); + + } + f.EndList(); +} + +public static void Serialize_gltf_animations__samplers_LIST(JsonFormatter f, glTFAnimationSampler value) +{ + f.BeginMap(); + + f.Key("input"); + f.Value(value.input); + + f.Key("interpolation"); + f.Value(value.interpolation); + + f.Key("output"); + f.Value(value.output); + + f.Key("extensions"); + value.extras.Serialize(f); + + f.Key("extras"); + value.extras.Serialize(f); + + + f.EndMap(); +} + +public static void Serialize_gltf_cameras(JsonFormatter f, List value) +{ + f.BeginList(); + + foreach(var item in value) + { + Serialize_gltf_cameras_LIST(f, item); + + } + f.EndList(); +} + +public static void Serialize_gltf_cameras_LIST(JsonFormatter f, glTFCamera value) +{ + f.BeginMap(); + + f.Key("orthographic"); + Serialize_gltf_cameras__orthographic(f, value.orthographic); + + f.Key("perspective"); + Serialize_gltf_cameras__perspective(f, value.perspective); + + f.Key("type"); + f.Value(value.type.ToString().ToLower()); + + f.Key("name"); + f.Value(value.name); + + f.Key("extensions"); + value.extras.Serialize(f); + + f.Key("extras"); + value.extras.Serialize(f); + + + f.EndMap(); +} + +public static void Serialize_gltf_cameras__orthographic(JsonFormatter f, glTFOrthographic value) +{ + f.BeginMap(); + + f.Key("xmag"); + f.Value(value.xmag); + + f.Key("ymag"); + f.Value(value.ymag); + + f.Key("zfar"); + f.Value(value.zfar); + + f.Key("znear"); + f.Value(value.znear); + + f.Key("extensions"); + value.extras.Serialize(f); + + f.Key("extras"); + value.extras.Serialize(f); + + + f.EndMap(); +} + +public static void Serialize_gltf_cameras__perspective(JsonFormatter f, glTFPerspective value) +{ + f.BeginMap(); + + f.Key("aspectRatio"); + f.Value(value.aspectRatio); + + f.Key("yfov"); + f.Value(value.yfov); + + f.Key("zfar"); + f.Value(value.zfar); + + f.Key("znear"); + f.Value(value.znear); + + f.Key("extensions"); + value.extras.Serialize(f); + + f.Key("extras"); + value.extras.Serialize(f); + + + f.EndMap(); +} + +public static void Serialize_gltf_extensionsUsed(JsonFormatter f, List value) +{ + f.BeginList(); + + foreach(var item in value) + { + f.Value(item); + + } + f.EndList(); +} + +public static void Serialize_gltf_extensionsRequired(JsonFormatter f, List value) +{ + f.BeginList(); + + foreach(var item in value) + { + f.Value(item); + + } + f.EndList(); +} + + } // class +} // namespace diff --git a/Assets/UniGLTF/UniGLTF/Scripts/IO/FormatterExtensionsGltf.g.cs.meta b/Assets/UniGLTF/UniGLTF/Scripts/IO/GltfSerializer.g.cs.meta similarity index 69% rename from Assets/UniGLTF/UniGLTF/Scripts/IO/FormatterExtensionsGltf.g.cs.meta rename to Assets/UniGLTF/UniGLTF/Scripts/IO/GltfSerializer.g.cs.meta index 71ef3c0ad..ecfe3f10e 100644 --- a/Assets/UniGLTF/UniGLTF/Scripts/IO/FormatterExtensionsGltf.g.cs.meta +++ b/Assets/UniGLTF/UniGLTF/Scripts/IO/GltfSerializer.g.cs.meta @@ -1,8 +1,7 @@ fileFormatVersion: 2 -guid: 972f1c538db788042863a4ac753dbc04 -timeCreated: 1564987956 -licenseType: Free +guid: 0421d021918de864aab65cce94937b61 MonoImporter: + externalObjects: {} serializedVersion: 2 defaultReferences: [] executionOrder: 0 diff --git a/Assets/UniGLTF/UniGLTF/Scripts/IO/UnityPath.cs b/Assets/UniGLTF/UniGLTF/Scripts/IO/UnityPath.cs index bb236a463..9a4cebe0d 100644 --- a/Assets/UniGLTF/UniGLTF/Scripts/IO/UnityPath.cs +++ b/Assets/UniGLTF/UniGLTF/Scripts/IO/UnityPath.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.IO; using UnityEngine; using System.Collections.Generic; diff --git a/Assets/UniGLTF/UniJSON/Editor/Tests/Json/JsonSerializerTests.cs b/Assets/UniGLTF/UniJSON/Editor/Tests/Json/JsonSerializerTests.cs index f22f3c9bb..646247ffd 100644 --- a/Assets/UniGLTF/UniJSON/Editor/Tests/Json/JsonSerializerTests.cs +++ b/Assets/UniGLTF/UniJSON/Editor/Tests/Json/JsonSerializerTests.cs @@ -3,7 +3,7 @@ using System; using System.Linq; using NUnit.Framework; using System.Collections.Generic; - +using UniGLTF; namespace UniJSON { diff --git a/Assets/VRM.Samples/Editor/Tests/VRMImportExportTests.cs b/Assets/VRM.Samples/Editor/Tests/VRMImportExportTests.cs index 77ab7cd6e..9559c09be 100644 --- a/Assets/VRM.Samples/Editor/Tests/VRMImportExportTests.cs +++ b/Assets/VRM.Samples/Editor/Tests/VRMImportExportTests.cs @@ -21,7 +21,7 @@ namespace VRM.Samples public static string ToJson(this glTF self) { var f = new JsonFormatter(); - f.GenSerialize(self); + GltfSerializer.Serialize(f, self); return f.ToString(); } } @@ -138,7 +138,7 @@ namespace VRM.Samples // 生成シリアライザでJSON化する var f = new JsonFormatter(); - f.GenSerialize(context.GLTF); + GltfSerializer.Serialize(f, context.GLTF); var parsed = f.ToString().ParseAsJson(); var newJson = parsed.ToString(" "); @@ -152,7 +152,7 @@ namespace VRM.Samples var ff = new JsonFormatter(); var des = GltfDeserializer.Deserialize(parsed); ff.Clear(); - ff.GenSerialize(des); + GltfSerializer.Serialize(ff, des); var desJson = ff.ToString().ParseAsJson().ToString(" "); Assert.AreEqual(oldJson.ParseAsJson().ToString(), desJson.ParseAsJson().ToString()); } diff --git a/Assets/VRM/UniVRM/Editor/Tests/UniVRMSerializeTests.cs b/Assets/VRM/UniVRM/Editor/Tests/UniVRMSerializeTests.cs index e4e7bbba3..9b5a2dc45 100644 --- a/Assets/VRM/UniVRM/Editor/Tests/UniVRMSerializeTests.cs +++ b/Assets/VRM/UniVRM/Editor/Tests/UniVRMSerializeTests.cs @@ -12,136 +12,136 @@ namespace VRM public static string ToJson(this glTF self) { var f = new JsonFormatter(); - f.GenSerialize(self); + GltfSerializer.Serialize(f, self); return f.ToString(); } public static string ToJson(this glTFMesh self) { var f = new JsonFormatter(); - f.GenSerialize(self); + GltfSerializer.Serialize_gltf_meshes_LIST(f, self); return f.ToString(); } public static string ToJson(this glTFPrimitives self) { var f = new JsonFormatter(); - f.GenSerialize(self); + GltfSerializer.Serialize_gltf_meshes__primitives_LIST(f, self); return f.ToString(); } public static string ToJson(this glTFAttributes self) { var f = new JsonFormatter(); - f.GenSerialize(self); + GltfSerializer.Serialize_gltf_meshes__primitives__attributes(f, self); return f.ToString(); } public static string ToJson(this glTFMaterialBaseColorTextureInfo self) { var f = new JsonFormatter(); - f.GenSerialize(self); + GltfSerializer.Serialize_gltf_materials__pbrMetallicRoughness_baseColorTexture(f, self); return f.ToString(); } public static string ToJson(this glTFMaterial self) { var f = new JsonFormatter(); - f.GenSerialize(self); + GltfSerializer.Serialize_gltf_materials_LIST(f, self); return f.ToString(); } public static string ToJson(this glTFNode self) { var f = new JsonFormatter(); - f.GenSerialize(self); + GltfSerializer.Serialize_gltf_nodes_LIST(f, self); return f.ToString(); } public static string ToJson(this glTFSkin self) { var f = new JsonFormatter(); - f.GenSerialize(self); + GltfSerializer.Serialize_gltf_skins_LIST(f, self); return f.ToString(); } public static string ToJson(this glTF_VRM_MaterialValueBind self) { var f = new JsonFormatter(); - f.GenSerialize(self); + VRMSerializer.Serialize_vrm_blendShapeMaster_blendShapeGroups__materialValues_ITEM(f, self); return f.ToString(); } public static string ToJson(this glTF_VRM_BlendShapeBind self) { var f = new JsonFormatter(); - f.GenSerialize(self); + VRMSerializer.Serialize_vrm_blendShapeMaster_blendShapeGroups__binds_ITEM(f, self); return f.ToString(); } public static string ToJson(this glTF_VRM_BlendShapeGroup self) { var f = new JsonFormatter(); - f.GenSerialize(self); + VRMSerializer.Serialize_vrm_blendShapeMaster_blendShapeGroups_ITEM(f, self); return f.ToString(); } public static string ToJson(this glTF_VRM_DegreeMap self) { var f = new JsonFormatter(); - f.GenSerialize(self); + VRMSerializer.Serialize_vrm_firstPerson_lookAtHorizontalInner(f, self); return f.ToString(); } public static string ToJson(this glTF_VRM_MeshAnnotation self) { var f = new JsonFormatter(); - f.GenSerialize(self); + VRMSerializer.Serialize_vrm_firstPerson_meshAnnotations_ITEM(f, self); return f.ToString(); } public static string ToJson(this glTF_VRM_Firstperson self) { var f = new JsonFormatter(); - f.GenSerialize(self); + VRMSerializer.Serialize_vrm_firstPerson(f, self); return f.ToString(); } public static string ToJson(this glTF_VRM_HumanoidBone self) { var f = new JsonFormatter(); - f.GenSerialize(self); + VRMSerializer.Serialize_vrm_humanoid_humanBones_ITEM(f, self); return f.ToString(); } public static string ToJson(this glTF_VRM_Humanoid self) { var f = new JsonFormatter(); - f.GenSerialize(self); + VRMSerializer.Serialize_vrm_humanoid(f, self); return f.ToString(); } public static string ToJson(this glTF_VRM_Material self) { var f = new JsonFormatter(); - f.GenSerialize(self); + VRMSerializer.Serialize_vrm_materialProperties_ITEM(f, self); return f.ToString(); } public static string ToJson(this glTF_VRM_Meta self) { var f = new JsonFormatter(); - f.GenSerialize(self); + VRMSerializer.Serialize_vrm_meta(f, self); return f.ToString(); } public static string ToJson(this glTF_VRM_SecondaryAnimationCollider self) { var f = new JsonFormatter(); - f.GenSerialize(self); + VRMSerializer.Serialize_vrm_secondaryAnimation_colliderGroups__colliders_ITEM(f, self); return f.ToString(); } public static string ToJson(this glTF_VRM_SecondaryAnimationColliderGroup self) { var f = new JsonFormatter(); - f.GenSerialize(self); + VRMSerializer.Serialize_vrm_secondaryAnimation_colliderGroups_ITEM(f, self); return f.ToString(); } public static string ToJson(this glTF_VRM_SecondaryAnimationGroup self) { var f = new JsonFormatter(); - f.GenSerialize(self); + VRMSerializer.Serialize_vrm_secondaryAnimation_boneGroups_ITEM(f, self); return f.ToString(); } public static string ToJson(this glTF_VRM_SecondaryAnimation self) { var f = new JsonFormatter(); - f.GenSerialize(self); + VRMSerializer.Serialize_vrm_secondaryAnimation(f, self); return f.ToString(); } } diff --git a/Assets/VRM/UniVRM/Editor/VRMDeserializerGenerator.cs b/Assets/VRM/UniVRM/Editor/VRMDeserializerGenerator.cs index cf7e62dd7..4e01875cd 100644 --- a/Assets/VRM/UniVRM/Editor/VRMDeserializerGenerator.cs +++ b/Assets/VRM/UniVRM/Editor/VRMDeserializerGenerator.cs @@ -25,7 +25,7 @@ namespace VRM [MenuItem(VRM.VRMVersion.MENU + "/VRM: Generate Deserializer")] static void GenerateSerializer() { - var info = new UniGLTF.ObjectSerialization(typeof(glTF_VRM_extensions), "vrm"); + var info = new UniGLTF.ObjectSerialization(typeof(glTF_VRM_extensions), "vrm", "_Deserialize"); Debug.Log(info); using (var s = File.Open(OutPath, FileMode.Create)) diff --git a/Assets/VRM/UniVRM/Editor/VRMSerializerGenerator.cs b/Assets/VRM/UniVRM/Editor/VRMSerializerGenerator.cs index f42de27e0..4c1da5fa3 100644 --- a/Assets/VRM/UniVRM/Editor/VRMSerializerGenerator.cs +++ b/Assets/VRM/UniVRM/Editor/VRMSerializerGenerator.cs @@ -1,11 +1,7 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.IO; +using System.IO; using System.Reflection; using System.Text; using UniGLTF; -using UniJSON; using UnityEditor; using UnityEngine; @@ -20,47 +16,11 @@ namespace VRM get { return Path.Combine(UnityEngine.Application.dataPath, - "VRM/UniVRM/Scripts/Format/VRMFormatterExtensionsGltf.g.cs"); + "VRM/UniVRM/Scripts/Format/VRMSerializer.g.cs"); } } - /// - /// AOT向けにシリアライザを生成する - /// - [MenuItem(VRM.VRMVersion.MENU + "/VRM: Generate Serializer")] - static void GenerateSerializer() - { - var path = OutPath; - - using (var g = new Generator(path)) - { - var rootType = typeof(glTF_VRM_extensions); - g.Generate(rootType, "vrm"); - } - } - - class Generator : IDisposable - { - String m_path; - Stream m_s; - StreamWriter m_w; - - static Dictionary s_snippets = new Dictionary - { - {"vrm/humanoid/humanBones[]/axisLength", "if(value.axisLength>0)"}, - {"vrm/humanoid/humanBones[]/center", "if(value.center!=Vector3.zero)"}, - {"vrm/humanoid/humanBones[]/max", "if(value.max!=Vector3.zero)"}, - {"vrm/humanoid/humanBones[]/min", "if(value.min!=Vector3.zero)"}, - }; - - public Generator(string path) - { - m_path = path; - m_s = File.Open(path, FileMode.Create); - m_w = new StreamWriter(m_s, Encoding.UTF8); - - // begin - m_w.Write(@" + const string Begin = @" using System; using System.Collections.Generic; using UniJSON; @@ -69,228 +29,34 @@ using VRM; namespace VRM { - static public class IFormatterExtensionsGltf + static public class VrmSerializer { -"); - } - - public void Dispose() - { - // end - m_w.Write(@" +"; + const string End = @" } // class } // namespace -"); +"; - m_w.Dispose(); - m_s.Dispose(); - UnityPath.FromFullpath(m_path).ImportAsset(); + /// + /// AOT向けにシリアライザを生成する + /// + [MenuItem(VRM.VRMVersion.MENU + "/VRM: Generate Serializer")] + static void GenerateSerializer() + { + var info = new ObjectSerialization(typeof(glTF_VRM_extensions), "vrm", "Serialize_"); + Debug.Log(info); + + using (var s = File.Open(OutPath, FileMode.Create)) + using (var w = new StreamWriter(s, new UTF8Encoding(false))) + { + w.Write(Begin); + info.GenerateSerializer(w, "Serialize"); + w.Write(End); } - HashSet m_used = new HashSet - { - typeof(object), - }; - - public void Generate(Type t, string path, int level = 0) - { - if (m_used.Contains(t)) - { - // 処理済み - return; - } - m_used.Add(t); - - // - // primitive - // - try - { - var mi = typeof(JsonFormatter).GetMethod("Value", new Type[] { t }); - if (mi != null) - { - m_w.Write(@" - public static void GenSerialize(this JsonFormatter f, $0 value) - { - f.Value(value); - } -".Replace("$0", t.Name)); - - return; - } - } - catch (AmbiguousMatchException) - { - // skip - } - - if (t.IsEnum) - { - // - // enum - // - m_w.Write(@" - public static void GenSerialize(this JsonFormatter f, $0 value) - { - f.Value((int)value); - } -".Replace("$0", t.Name)); - } - else if (t.IsArray) - { - var et = t.GetElementType(); - m_w.Write(@" - /// $1 - public static void GenSerialize(this JsonFormatter f, $0[] value) - { - f.BeginList(value.Length); - foreach (var x in value) - { - f.GenSerialize(x); - } - f.EndList(); - } - " - .Replace("$0", et.Name) - .Replace("$1", path) - ); - Generate(et, path + "[]", level + 1); - } - else if (t.IsGenericType) - { - if (t.GetGenericTypeDefinition() == typeof(List<>)) - { - // - // array - // - var et = t.GetGenericArguments()[0]; - m_w.Write(@" - /// $1 - public static void GenSerialize(this JsonFormatter f, List<$0> value) - { - f.BeginList(value.Count); - foreach (var x in value) - { - f.GenSerialize(x); - } - f.EndList(); - } -" -.Replace("$0", et.Name) -.Replace("$1", path)); - Generate(et, path + "[]", level + 1); - } - else if (t.GetGenericTypeDefinition() == typeof(Dictionary<,>) - && t.GetGenericArguments()[0] == typeof(string)) - { - // - // object - // - var et = t.GetGenericArguments()[1]; - m_w.Write(@" - /// $1 - public static void GenSerialize(this JsonFormatter f, Dictionary value) - { - f.BeginMap(value.Count); - foreach (var kv in value) - { - f.Key(kv.Key); - f.GenSerialize(kv.Value); - } - f.EndMap(); - } - -" -.Replace("$0", et.Name) -.Replace("$1", path)); - Generate(et, path + "{}", level + 1); - } - else - { - Debug.LogWarningFormat("unknown type: {0}", t); - } - } - else if (t == typeof(glTFExtension)) - { - // skip - } - else - { - // - // reflection - // - Debug.LogFormat("{0}({1})", path, t.Name); - - m_w.Write(@" - /// $1 - public static void GenSerialize(this JsonFormatter f, $0 value) - { - f.BeginMap(0); // dummy -" -.Replace("$0", t.Name) -.Replace("$1", path) -); - - foreach (var fi in t.GetFields(FIELD_FLAGS)) - { - if (fi.FieldType == typeof(object)) - { - continue; - } - if (fi.IsLiteral && !fi.IsInitOnly) - { - continue; - } - if (fi.FieldType == typeof(string) || fi.FieldType.IsEnum || fi.FieldType.IsArray || fi.FieldType.IsGenericType) - { - - } - else if (fi.FieldType == typeof(glTF_KHR_materials_unlit)) - { - - } - else if (fi.FieldType.IsClass && fi.FieldType.GetFields(FIELD_FLAGS).Length == 0) - { - continue; - } - - var snipet = fi.FieldType.IsClass ? "if(value." + fi.Name + "!=null)" : ""; - var value = default(string); - if (s_snippets.TryGetValue(path + "/" + fi.Name, out value)) - { - snipet = value; - } - - if (value == "") - { - // found, but empty - } - else - { - m_w.Write(@" - $1 - { - f.Key(""$0""); f.GenSerialize(value.$0); - } -" - .Replace("$0", fi.Name) - .Replace("$1", snipet) - ); - } - } - - m_w.Write(@" - f.EndMap(); - } -"); - - foreach (var fi in t.GetFields(FIELD_FLAGS)) - { - Generate(fi.FieldType, path + "/" + fi.Name, level + 1); - } - } - } + Debug.LogFormat("write: {0}", OutPath); + UnityPath.FromFullpath(OutPath).ImportAsset(); } } } diff --git a/Assets/VRM/UniVRM/Scripts/Format/VRMExporter.cs b/Assets/VRM/UniVRM/Scripts/Format/VRMExporter.cs index 9f9df05cf..390cfe73d 100644 --- a/Assets/VRM/UniVRM/Scripts/Format/VRMExporter.cs +++ b/Assets/VRM/UniVRM/Scripts/Format/VRMExporter.cs @@ -206,7 +206,7 @@ namespace VRM // Serialize VRM var f = new JsonFormatter(); - f.GenSerialize(VRM); + VRMSerializer.Serialize(f, VRM); var bytes = f.GetStoreBytes(); glTFExtensionExport.GetOrCreate(ref glTF.extensions).Add("VRM", bytes); } diff --git a/Assets/VRM/UniVRM/Scripts/Format/VRMFormat.cs b/Assets/VRM/UniVRM/Scripts/Format/VRMFormat.cs index e295c6c7d..548ab400c 100644 --- a/Assets/VRM/UniVRM/Scripts/Format/VRMFormat.cs +++ b/Assets/VRM/UniVRM/Scripts/Format/VRMFormat.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using UniJSON; +using UniGLTF; namespace VRM diff --git a/Assets/VRM/UniVRM/Scripts/Format/VRMFormatterExtensionsGltf.g.cs b/Assets/VRM/UniVRM/Scripts/Format/VRMFormatterExtensionsGltf.g.cs deleted file mode 100644 index aa128de95..000000000 --- a/Assets/VRM/UniVRM/Scripts/Format/VRMFormatterExtensionsGltf.g.cs +++ /dev/null @@ -1,797 +0,0 @@ - -using System; -using System.Collections.Generic; -using UniJSON; -using UnityEngine; -using VRM; - -namespace VRM { - - static public class IFormatterExtensionsGltf - { - - - /// vrm - public static void GenSerialize(this JsonFormatter f, glTF_VRM_extensions value) - { - f.BeginMap(0); // dummy - - if(value.exporterVersion!=null) - { - f.Key("exporterVersion"); f.GenSerialize(value.exporterVersion); - } - - if(value.specVersion!=null) - { - f.Key("specVersion"); f.GenSerialize(value.specVersion); - } - - if(value.meta!=null) - { - f.Key("meta"); f.GenSerialize(value.meta); - } - - if(value.humanoid!=null) - { - f.Key("humanoid"); f.GenSerialize(value.humanoid); - } - - if(value.firstPerson!=null) - { - f.Key("firstPerson"); f.GenSerialize(value.firstPerson); - } - - if(value.blendShapeMaster!=null) - { - f.Key("blendShapeMaster"); f.GenSerialize(value.blendShapeMaster); - } - - if(value.secondaryAnimation!=null) - { - f.Key("secondaryAnimation"); f.GenSerialize(value.secondaryAnimation); - } - - if(value.materialProperties!=null) - { - f.Key("materialProperties"); f.GenSerialize(value.materialProperties); - } - - f.EndMap(); - } - - public static void GenSerialize(this JsonFormatter f, String value) - { - f.Value(value); - } - - /// vrm/meta - public static void GenSerialize(this JsonFormatter f, glTF_VRM_Meta value) - { - f.BeginMap(0); // dummy - - if(value.title!=null) - { - f.Key("title"); f.GenSerialize(value.title); - } - - if(value.version!=null) - { - f.Key("version"); f.GenSerialize(value.version); - } - - if(value.author!=null) - { - f.Key("author"); f.GenSerialize(value.author); - } - - if(value.contactInformation!=null) - { - f.Key("contactInformation"); f.GenSerialize(value.contactInformation); - } - - if(value.reference!=null) - { - f.Key("reference"); f.GenSerialize(value.reference); - } - - - { - f.Key("texture"); f.GenSerialize(value.texture); - } - - if(value.allowedUserName!=null) - { - f.Key("allowedUserName"); f.GenSerialize(value.allowedUserName); - } - - if(value.violentUssageName!=null) - { - f.Key("violentUssageName"); f.GenSerialize(value.violentUssageName); - } - - if(value.sexualUssageName!=null) - { - f.Key("sexualUssageName"); f.GenSerialize(value.sexualUssageName); - } - - if(value.commercialUssageName!=null) - { - f.Key("commercialUssageName"); f.GenSerialize(value.commercialUssageName); - } - - if(value.otherPermissionUrl!=null) - { - f.Key("otherPermissionUrl"); f.GenSerialize(value.otherPermissionUrl); - } - - if(value.licenseName!=null) - { - f.Key("licenseName"); f.GenSerialize(value.licenseName); - } - - if(value.otherLicenseUrl!=null) - { - f.Key("otherLicenseUrl"); f.GenSerialize(value.otherLicenseUrl); - } - - f.EndMap(); - } - - public static void GenSerialize(this JsonFormatter f, Int32 value) - { - f.Value(value); - } - - /// vrm/humanoid - public static void GenSerialize(this JsonFormatter f, glTF_VRM_Humanoid value) - { - f.BeginMap(0); // dummy - - if(value.humanBones!=null) - { - f.Key("humanBones"); f.GenSerialize(value.humanBones); - } - - - { - f.Key("armStretch"); f.GenSerialize(value.armStretch); - } - - - { - f.Key("legStretch"); f.GenSerialize(value.legStretch); - } - - - { - f.Key("upperArmTwist"); f.GenSerialize(value.upperArmTwist); - } - - - { - f.Key("lowerArmTwist"); f.GenSerialize(value.lowerArmTwist); - } - - - { - f.Key("upperLegTwist"); f.GenSerialize(value.upperLegTwist); - } - - - { - f.Key("lowerLegTwist"); f.GenSerialize(value.lowerLegTwist); - } - - - { - f.Key("feetSpacing"); f.GenSerialize(value.feetSpacing); - } - - - { - f.Key("hasTranslationDoF"); f.GenSerialize(value.hasTranslationDoF); - } - - f.EndMap(); - } - - /// vrm/humanoid/humanBones - public static void GenSerialize(this JsonFormatter f, List value) - { - f.BeginList(value.Count); - foreach (var x in value) - { - f.GenSerialize(x); - } - f.EndList(); - } - - /// vrm/humanoid/humanBones[] - public static void GenSerialize(this JsonFormatter f, glTF_VRM_HumanoidBone value) - { - f.BeginMap(0); // dummy - - if(value.bone!=null) - { - f.Key("bone"); f.GenSerialize(value.bone); - } - - - { - f.Key("node"); f.GenSerialize(value.node); - } - - - { - f.Key("useDefaultValues"); f.GenSerialize(value.useDefaultValues); - } - - if(value.min!=Vector3.zero) - { - f.Key("min"); f.GenSerialize(value.min); - } - - if(value.max!=Vector3.zero) - { - f.Key("max"); f.GenSerialize(value.max); - } - - if(value.center!=Vector3.zero) - { - f.Key("center"); f.GenSerialize(value.center); - } - - if(value.axisLength>0) - { - f.Key("axisLength"); f.GenSerialize(value.axisLength); - } - - f.EndMap(); - } - - public static void GenSerialize(this JsonFormatter f, Boolean value) - { - f.Value(value); - } - - /// vrm/humanoid/humanBones[]/min - public static void GenSerialize(this JsonFormatter f, Vector3 value) - { - f.BeginMap(0); // dummy - - - { - f.Key("x"); f.GenSerialize(value.x); - } - - - { - f.Key("y"); f.GenSerialize(value.y); - } - - - { - f.Key("z"); f.GenSerialize(value.z); - } - - f.EndMap(); - } - - public static void GenSerialize(this JsonFormatter f, Single value) - { - f.Value(value); - } - - /// vrm/firstPerson - public static void GenSerialize(this JsonFormatter f, glTF_VRM_Firstperson value) - { - f.BeginMap(0); // dummy - - - { - f.Key("firstPersonBone"); f.GenSerialize(value.firstPersonBone); - } - - - { - f.Key("firstPersonBoneOffset"); f.GenSerialize(value.firstPersonBoneOffset); - } - - if(value.meshAnnotations!=null) - { - f.Key("meshAnnotations"); f.GenSerialize(value.meshAnnotations); - } - - if(value.lookAtTypeName!=null) - { - f.Key("lookAtTypeName"); f.GenSerialize(value.lookAtTypeName); - } - - if(value.lookAtHorizontalInner!=null) - { - f.Key("lookAtHorizontalInner"); f.GenSerialize(value.lookAtHorizontalInner); - } - - if(value.lookAtHorizontalOuter!=null) - { - f.Key("lookAtHorizontalOuter"); f.GenSerialize(value.lookAtHorizontalOuter); - } - - if(value.lookAtVerticalDown!=null) - { - f.Key("lookAtVerticalDown"); f.GenSerialize(value.lookAtVerticalDown); - } - - if(value.lookAtVerticalUp!=null) - { - f.Key("lookAtVerticalUp"); f.GenSerialize(value.lookAtVerticalUp); - } - - f.EndMap(); - } - - /// vrm/firstPerson/meshAnnotations - public static void GenSerialize(this JsonFormatter f, List value) - { - f.BeginList(value.Count); - foreach (var x in value) - { - f.GenSerialize(x); - } - f.EndList(); - } - - /// vrm/firstPerson/meshAnnotations[] - public static void GenSerialize(this JsonFormatter f, glTF_VRM_MeshAnnotation value) - { - f.BeginMap(0); // dummy - - - { - f.Key("mesh"); f.GenSerialize(value.mesh); - } - - if(value.firstPersonFlag!=null) - { - f.Key("firstPersonFlag"); f.GenSerialize(value.firstPersonFlag); - } - - f.EndMap(); - } - - /// vrm/firstPerson/lookAtHorizontalInner - public static void GenSerialize(this JsonFormatter f, glTF_VRM_DegreeMap value) - { - f.BeginMap(0); // dummy - - if(value.curve!=null) - { - f.Key("curve"); f.GenSerialize(value.curve); - } - - - { - f.Key("xRange"); f.GenSerialize(value.xRange); - } - - - { - f.Key("yRange"); f.GenSerialize(value.yRange); - } - - f.EndMap(); - } - - /// vrm/firstPerson/lookAtHorizontalInner/curve - public static void GenSerialize(this JsonFormatter f, Single[] value) - { - f.BeginList(value.Length); - foreach (var x in value) - { - f.GenSerialize(x); - } - f.EndList(); - } - - /// vrm/blendShapeMaster - public static void GenSerialize(this JsonFormatter f, glTF_VRM_BlendShapeMaster value) - { - f.BeginMap(0); // dummy - - if(value.blendShapeGroups!=null) - { - f.Key("blendShapeGroups"); f.GenSerialize(value.blendShapeGroups); - } - - f.EndMap(); - } - - /// vrm/blendShapeMaster/blendShapeGroups - public static void GenSerialize(this JsonFormatter f, List value) - { - f.BeginList(value.Count); - foreach (var x in value) - { - f.GenSerialize(x); - } - f.EndList(); - } - - /// vrm/blendShapeMaster/blendShapeGroups[] - public static void GenSerialize(this JsonFormatter f, glTF_VRM_BlendShapeGroup value) - { - f.BeginMap(0); // dummy - - if(value.name!=null) - { - f.Key("name"); f.GenSerialize(value.name); - } - - if(value.presetName!=null) - { - f.Key("presetName"); f.GenSerialize(value.presetName); - } - - if(value.binds!=null) - { - f.Key("binds"); f.GenSerialize(value.binds); - } - - if(value.materialValues!=null) - { - f.Key("materialValues"); f.GenSerialize(value.materialValues); - } - - - { - f.Key("isBinary"); f.GenSerialize(value.isBinary); - } - - f.EndMap(); - } - - /// vrm/blendShapeMaster/blendShapeGroups[]/binds - public static void GenSerialize(this JsonFormatter f, List value) - { - f.BeginList(value.Count); - foreach (var x in value) - { - f.GenSerialize(x); - } - f.EndList(); - } - - /// vrm/blendShapeMaster/blendShapeGroups[]/binds[] - public static void GenSerialize(this JsonFormatter f, glTF_VRM_BlendShapeBind value) - { - f.BeginMap(0); // dummy - - - { - f.Key("mesh"); f.GenSerialize(value.mesh); - } - - - { - f.Key("index"); f.GenSerialize(value.index); - } - - - { - f.Key("weight"); f.GenSerialize(value.weight); - } - - f.EndMap(); - } - - /// vrm/blendShapeMaster/blendShapeGroups[]/materialValues - public static void GenSerialize(this JsonFormatter f, List value) - { - f.BeginList(value.Count); - foreach (var x in value) - { - f.GenSerialize(x); - } - f.EndList(); - } - - /// vrm/blendShapeMaster/blendShapeGroups[]/materialValues[] - public static void GenSerialize(this JsonFormatter f, glTF_VRM_MaterialValueBind value) - { - f.BeginMap(0); // dummy - - if(value.materialName!=null) - { - f.Key("materialName"); f.GenSerialize(value.materialName); - } - - if(value.propertyName!=null) - { - f.Key("propertyName"); f.GenSerialize(value.propertyName); - } - - if(value.targetValue!=null) - { - f.Key("targetValue"); f.GenSerialize(value.targetValue); - } - - f.EndMap(); - } - - /// vrm/secondaryAnimation - public static void GenSerialize(this JsonFormatter f, glTF_VRM_SecondaryAnimation value) - { - f.BeginMap(0); // dummy - - if(value.boneGroups!=null) - { - f.Key("boneGroups"); f.GenSerialize(value.boneGroups); - } - - if(value.colliderGroups!=null) - { - f.Key("colliderGroups"); f.GenSerialize(value.colliderGroups); - } - - f.EndMap(); - } - - /// vrm/secondaryAnimation/boneGroups - public static void GenSerialize(this JsonFormatter f, List value) - { - f.BeginList(value.Count); - foreach (var x in value) - { - f.GenSerialize(x); - } - f.EndList(); - } - - /// vrm/secondaryAnimation/boneGroups[] - public static void GenSerialize(this JsonFormatter f, glTF_VRM_SecondaryAnimationGroup value) - { - f.BeginMap(0); // dummy - - if(value.comment!=null) - { - f.Key("comment"); f.GenSerialize(value.comment); - } - - - { - f.Key("stiffiness"); f.GenSerialize(value.stiffiness); - } - - - { - f.Key("gravityPower"); f.GenSerialize(value.gravityPower); - } - - - { - f.Key("gravityDir"); f.GenSerialize(value.gravityDir); - } - - - { - f.Key("dragForce"); f.GenSerialize(value.dragForce); - } - - - { - f.Key("center"); f.GenSerialize(value.center); - } - - - { - f.Key("hitRadius"); f.GenSerialize(value.hitRadius); - } - - if(value.bones!=null) - { - f.Key("bones"); f.GenSerialize(value.bones); - } - - if(value.colliderGroups!=null) - { - f.Key("colliderGroups"); f.GenSerialize(value.colliderGroups); - } - - f.EndMap(); - } - - /// vrm/secondaryAnimation/boneGroups[]/bones - public static void GenSerialize(this JsonFormatter f, Int32[] value) - { - f.BeginList(value.Length); - foreach (var x in value) - { - f.GenSerialize(x); - } - f.EndList(); - } - - /// vrm/secondaryAnimation/colliderGroups - public static void GenSerialize(this JsonFormatter f, List value) - { - f.BeginList(value.Count); - foreach (var x in value) - { - f.GenSerialize(x); - } - f.EndList(); - } - - /// vrm/secondaryAnimation/colliderGroups[] - public static void GenSerialize(this JsonFormatter f, glTF_VRM_SecondaryAnimationColliderGroup value) - { - f.BeginMap(0); // dummy - - - { - f.Key("node"); f.GenSerialize(value.node); - } - - if(value.colliders!=null) - { - f.Key("colliders"); f.GenSerialize(value.colliders); - } - - f.EndMap(); - } - - /// vrm/secondaryAnimation/colliderGroups[]/colliders - public static void GenSerialize(this JsonFormatter f, List value) - { - f.BeginList(value.Count); - foreach (var x in value) - { - f.GenSerialize(x); - } - f.EndList(); - } - - /// vrm/secondaryAnimation/colliderGroups[]/colliders[] - public static void GenSerialize(this JsonFormatter f, glTF_VRM_SecondaryAnimationCollider value) - { - f.BeginMap(0); // dummy - - - { - f.Key("offset"); f.GenSerialize(value.offset); - } - - - { - f.Key("radius"); f.GenSerialize(value.radius); - } - - f.EndMap(); - } - - /// vrm/materialProperties - public static void GenSerialize(this JsonFormatter f, List value) - { - f.BeginList(value.Count); - foreach (var x in value) - { - f.GenSerialize(x); - } - f.EndList(); - } - - /// vrm/materialProperties[] - public static void GenSerialize(this JsonFormatter f, glTF_VRM_Material value) - { - f.BeginMap(0); // dummy - - if(value.name!=null) - { - f.Key("name"); f.GenSerialize(value.name); - } - - if(value.shader!=null) - { - f.Key("shader"); f.GenSerialize(value.shader); - } - - - { - f.Key("renderQueue"); f.GenSerialize(value.renderQueue); - } - - if(value.floatProperties!=null) - { - f.Key("floatProperties"); f.GenSerialize(value.floatProperties); - } - - if(value.vectorProperties!=null) - { - f.Key("vectorProperties"); f.GenSerialize(value.vectorProperties); - } - - if(value.textureProperties!=null) - { - f.Key("textureProperties"); f.GenSerialize(value.textureProperties); - } - - if(value.keywordMap!=null) - { - f.Key("keywordMap"); f.GenSerialize(value.keywordMap); - } - - if(value.tagMap!=null) - { - f.Key("tagMap"); f.GenSerialize(value.tagMap); - } - - f.EndMap(); - } - - /// vrm/materialProperties[]/floatProperties - public static void GenSerialize(this JsonFormatter f, Dictionary value) - { - f.BeginMap(value.Count); - foreach (var kv in value) - { - f.Key(kv.Key); - f.GenSerialize(kv.Value); - } - f.EndMap(); - } - - - /// vrm/materialProperties[]/vectorProperties - public static void GenSerialize(this JsonFormatter f, Dictionary value) - { - f.BeginMap(value.Count); - foreach (var kv in value) - { - f.Key(kv.Key); - f.GenSerialize(kv.Value); - } - f.EndMap(); - } - - - /// vrm/materialProperties[]/textureProperties - public static void GenSerialize(this JsonFormatter f, Dictionary value) - { - f.BeginMap(value.Count); - foreach (var kv in value) - { - f.Key(kv.Key); - f.GenSerialize(kv.Value); - } - f.EndMap(); - } - - - /// vrm/materialProperties[]/keywordMap - public static void GenSerialize(this JsonFormatter f, Dictionary value) - { - f.BeginMap(value.Count); - foreach (var kv in value) - { - f.Key(kv.Key); - f.GenSerialize(kv.Value); - } - f.EndMap(); - } - - - /// vrm/materialProperties[]/tagMap - public static void GenSerialize(this JsonFormatter f, Dictionary value) - { - f.BeginMap(value.Count); - foreach (var kv in value) - { - f.Key(kv.Key); - f.GenSerialize(kv.Value); - } - f.EndMap(); - } - - - } // class -} // namespace diff --git a/Assets/VRM/UniVRM/Scripts/Format/VRMSerializer.g.cs b/Assets/VRM/UniVRM/Scripts/Format/VRMSerializer.g.cs new file mode 100644 index 000000000..d23c63fcf --- /dev/null +++ b/Assets/VRM/UniVRM/Scripts/Format/VRMSerializer.g.cs @@ -0,0 +1,810 @@ + +using System; +using System.Collections.Generic; +using UniJSON; +using UnityEngine; +using VRM; + +namespace VRM { + + static public class VRMSerializer + { + + +public static void Serialize(JsonFormatter f, glTF_VRM_extensions value) +{ + f.BeginMap(); + + f.Key("exporterVersion"); + f.Value(value.exporterVersion); + + f.Key("specVersion"); + f.Value(value.specVersion); + + f.Key("meta"); + Serialize_vrm_meta(f, value.meta); + + f.Key("humanoid"); + Serialize_vrm_humanoid(f, value.humanoid); + + f.Key("firstPerson"); + Serialize_vrm_firstPerson(f, value.firstPerson); + + f.Key("blendShapeMaster"); + Serialize_vrm_blendShapeMaster(f, value.blendShapeMaster); + + f.Key("secondaryAnimation"); + Serialize_vrm_secondaryAnimation(f, value.secondaryAnimation); + + f.Key("materialProperties"); + Serialize_vrm_materialProperties(f, value.materialProperties); + + + f.EndMap(); +} + +public static void Serialize_vrm_meta(JsonFormatter f, glTF_VRM_Meta value) +{ + f.BeginMap(); + + f.Key("title"); + f.Value(value.title); + + f.Key("version"); + f.Value(value.version); + + f.Key("author"); + f.Value(value.author); + + f.Key("contactInformation"); + f.Value(value.contactInformation); + + f.Key("reference"); + f.Value(value.reference); + + f.Key("texture"); + f.Value(value.texture); + + f.Key("allowedUserName"); + f.Value(value.allowedUserName); + + f.Key("violentUssageName"); + f.Value(value.violentUssageName); + + f.Key("sexualUssageName"); + f.Value(value.sexualUssageName); + + f.Key("commercialUssageName"); + f.Value(value.commercialUssageName); + + f.Key("otherPermissionUrl"); + f.Value(value.otherPermissionUrl); + + f.Key("licenseName"); + f.Value(value.licenseName); + + f.Key("otherLicenseUrl"); + f.Value(value.otherLicenseUrl); + + + f.EndMap(); +} + +public static void Serialize_vrm_humanoid(JsonFormatter f, glTF_VRM_Humanoid value) +{ + f.BeginMap(); + + f.Key("humanBones"); + Serialize_vrm_humanoid_humanBones(f, value.humanBones); + + f.Key("armStretch"); + f.Value(value.armStretch); + + f.Key("legStretch"); + f.Value(value.legStretch); + + f.Key("upperArmTwist"); + f.Value(value.upperArmTwist); + + f.Key("lowerArmTwist"); + f.Value(value.lowerArmTwist); + + f.Key("upperLegTwist"); + f.Value(value.upperLegTwist); + + f.Key("lowerLegTwist"); + f.Value(value.lowerLegTwist); + + f.Key("feetSpacing"); + f.Value(value.feetSpacing); + + f.Key("hasTranslationDoF"); + f.Value(value.hasTranslationDoF); + + + f.EndMap(); +} + +public static void Serialize_vrm_humanoid_humanBones(JsonFormatter f, List value) +{ + f.BeginList(); + + foreach(var item in value) + { + Serialize_vrm_humanoid_humanBones_ITEM(f, item); + + } + f.EndList(); +} + +public static void Serialize_vrm_humanoid_humanBones_ITEM(JsonFormatter f, glTF_VRM_HumanoidBone value) +{ + f.BeginMap(); + + f.Key("bone"); + f.Value(value.bone); + + f.Key("node"); + f.Value(value.node); + + f.Key("useDefaultValues"); + f.Value(value.useDefaultValues); + + f.Key("min"); + Serialize_vrm_humanoid_humanBones__min(f, value.min); + + f.Key("max"); + Serialize_vrm_humanoid_humanBones__max(f, value.max); + + f.Key("center"); + Serialize_vrm_humanoid_humanBones__center(f, value.center); + + f.Key("axisLength"); + f.Value(value.axisLength); + + + f.EndMap(); +} + +public static void Serialize_vrm_humanoid_humanBones__min(JsonFormatter f, Vector3 value) +{ + f.BeginMap(); + + f.Key("x"); + f.Value(value.x); + + f.Key("y"); + f.Value(value.y); + + f.Key("z"); + f.Value(value.z); + + + f.EndMap(); +} + +public static void Serialize_vrm_humanoid_humanBones__max(JsonFormatter f, Vector3 value) +{ + f.BeginMap(); + + f.Key("x"); + f.Value(value.x); + + f.Key("y"); + f.Value(value.y); + + f.Key("z"); + f.Value(value.z); + + + f.EndMap(); +} + +public static void Serialize_vrm_humanoid_humanBones__center(JsonFormatter f, Vector3 value) +{ + f.BeginMap(); + + f.Key("x"); + f.Value(value.x); + + f.Key("y"); + f.Value(value.y); + + f.Key("z"); + f.Value(value.z); + + + f.EndMap(); +} + +public static void Serialize_vrm_firstPerson(JsonFormatter f, glTF_VRM_Firstperson value) +{ + f.BeginMap(); + + f.Key("firstPersonBone"); + f.Value(value.firstPersonBone); + + f.Key("firstPersonBoneOffset"); + Serialize_vrm_firstPerson_firstPersonBoneOffset(f, value.firstPersonBoneOffset); + + f.Key("meshAnnotations"); + Serialize_vrm_firstPerson_meshAnnotations(f, value.meshAnnotations); + + f.Key("lookAtTypeName"); + f.Value(value.lookAtTypeName); + + f.Key("lookAtHorizontalInner"); + Serialize_vrm_firstPerson_lookAtHorizontalInner(f, value.lookAtHorizontalInner); + + f.Key("lookAtHorizontalOuter"); + Serialize_vrm_firstPerson_lookAtHorizontalOuter(f, value.lookAtHorizontalOuter); + + f.Key("lookAtVerticalDown"); + Serialize_vrm_firstPerson_lookAtVerticalDown(f, value.lookAtVerticalDown); + + f.Key("lookAtVerticalUp"); + Serialize_vrm_firstPerson_lookAtVerticalUp(f, value.lookAtVerticalUp); + + + f.EndMap(); +} + +public static void Serialize_vrm_firstPerson_firstPersonBoneOffset(JsonFormatter f, Vector3 value) +{ + f.BeginMap(); + + f.Key("x"); + f.Value(value.x); + + f.Key("y"); + f.Value(value.y); + + f.Key("z"); + f.Value(value.z); + + + f.EndMap(); +} + +public static void Serialize_vrm_firstPerson_meshAnnotations(JsonFormatter f, List value) +{ + f.BeginList(); + + foreach(var item in value) + { + Serialize_vrm_firstPerson_meshAnnotations_ITEM(f, item); + + } + f.EndList(); +} + +public static void Serialize_vrm_firstPerson_meshAnnotations_ITEM(JsonFormatter f, glTF_VRM_MeshAnnotation value) +{ + f.BeginMap(); + + f.Key("mesh"); + f.Value(value.mesh); + + f.Key("firstPersonFlag"); + f.Value(value.firstPersonFlag); + + + f.EndMap(); +} + +public static void Serialize_vrm_firstPerson_lookAtHorizontalInner(JsonFormatter f, glTF_VRM_DegreeMap value) +{ + f.BeginMap(); + + f.Key("curve"); + Serialize_vrm_firstPerson_lookAtHorizontalInner_curve(f, value.curve); + + f.Key("xRange"); + f.Value(value.xRange); + + f.Key("yRange"); + f.Value(value.yRange); + + + f.EndMap(); +} + +public static void Serialize_vrm_firstPerson_lookAtHorizontalInner_curve(JsonFormatter f, Single[] value) +{ + f.BeginList(); + + foreach(var item in value) + { + f.Value(item); + + } + f.EndList(); +} + +public static void Serialize_vrm_firstPerson_lookAtHorizontalOuter(JsonFormatter f, glTF_VRM_DegreeMap value) +{ + f.BeginMap(); + + f.Key("curve"); + Serialize_vrm_firstPerson_lookAtHorizontalOuter_curve(f, value.curve); + + f.Key("xRange"); + f.Value(value.xRange); + + f.Key("yRange"); + f.Value(value.yRange); + + + f.EndMap(); +} + +public static void Serialize_vrm_firstPerson_lookAtHorizontalOuter_curve(JsonFormatter f, Single[] value) +{ + f.BeginList(); + + foreach(var item in value) + { + f.Value(item); + + } + f.EndList(); +} + +public static void Serialize_vrm_firstPerson_lookAtVerticalDown(JsonFormatter f, glTF_VRM_DegreeMap value) +{ + f.BeginMap(); + + f.Key("curve"); + Serialize_vrm_firstPerson_lookAtVerticalDown_curve(f, value.curve); + + f.Key("xRange"); + f.Value(value.xRange); + + f.Key("yRange"); + f.Value(value.yRange); + + + f.EndMap(); +} + +public static void Serialize_vrm_firstPerson_lookAtVerticalDown_curve(JsonFormatter f, Single[] value) +{ + f.BeginList(); + + foreach(var item in value) + { + f.Value(item); + + } + f.EndList(); +} + +public static void Serialize_vrm_firstPerson_lookAtVerticalUp(JsonFormatter f, glTF_VRM_DegreeMap value) +{ + f.BeginMap(); + + f.Key("curve"); + Serialize_vrm_firstPerson_lookAtVerticalUp_curve(f, value.curve); + + f.Key("xRange"); + f.Value(value.xRange); + + f.Key("yRange"); + f.Value(value.yRange); + + + f.EndMap(); +} + +public static void Serialize_vrm_firstPerson_lookAtVerticalUp_curve(JsonFormatter f, Single[] value) +{ + f.BeginList(); + + foreach(var item in value) + { + f.Value(item); + + } + f.EndList(); +} + +public static void Serialize_vrm_blendShapeMaster(JsonFormatter f, glTF_VRM_BlendShapeMaster value) +{ + f.BeginMap(); + + f.Key("blendShapeGroups"); + Serialize_vrm_blendShapeMaster_blendShapeGroups(f, value.blendShapeGroups); + + + f.EndMap(); +} + +public static void Serialize_vrm_blendShapeMaster_blendShapeGroups(JsonFormatter f, List value) +{ + f.BeginList(); + + foreach(var item in value) + { + Serialize_vrm_blendShapeMaster_blendShapeGroups_ITEM(f, item); + + } + f.EndList(); +} + +public static void Serialize_vrm_blendShapeMaster_blendShapeGroups_ITEM(JsonFormatter f, glTF_VRM_BlendShapeGroup value) +{ + f.BeginMap(); + + f.Key("name"); + f.Value(value.name); + + f.Key("presetName"); + f.Value(value.presetName); + + f.Key("binds"); + Serialize_vrm_blendShapeMaster_blendShapeGroups__binds(f, value.binds); + + f.Key("materialValues"); + Serialize_vrm_blendShapeMaster_blendShapeGroups__materialValues(f, value.materialValues); + + f.Key("isBinary"); + f.Value(value.isBinary); + + + f.EndMap(); +} + +public static void Serialize_vrm_blendShapeMaster_blendShapeGroups__binds(JsonFormatter f, List value) +{ + f.BeginList(); + + foreach(var item in value) + { + Serialize_vrm_blendShapeMaster_blendShapeGroups__binds_ITEM(f, item); + + } + f.EndList(); +} + +public static void Serialize_vrm_blendShapeMaster_blendShapeGroups__binds_ITEM(JsonFormatter f, glTF_VRM_BlendShapeBind value) +{ + f.BeginMap(); + + f.Key("mesh"); + f.Value(value.mesh); + + f.Key("index"); + f.Value(value.index); + + f.Key("weight"); + f.Value(value.weight); + + + f.EndMap(); +} + +public static void Serialize_vrm_blendShapeMaster_blendShapeGroups__materialValues(JsonFormatter f, List value) +{ + f.BeginList(); + + foreach(var item in value) + { + Serialize_vrm_blendShapeMaster_blendShapeGroups__materialValues_ITEM(f, item); + + } + f.EndList(); +} + +public static void Serialize_vrm_blendShapeMaster_blendShapeGroups__materialValues_ITEM(JsonFormatter f, glTF_VRM_MaterialValueBind value) +{ + f.BeginMap(); + + f.Key("materialName"); + f.Value(value.materialName); + + f.Key("propertyName"); + f.Value(value.propertyName); + + f.Key("targetValue"); + Serialize_vrm_blendShapeMaster_blendShapeGroups__materialValues__targetValue(f, value.targetValue); + + + f.EndMap(); +} + +public static void Serialize_vrm_blendShapeMaster_blendShapeGroups__materialValues__targetValue(JsonFormatter f, Single[] value) +{ + f.BeginList(); + + foreach(var item in value) + { + f.Value(item); + + } + f.EndList(); +} + +public static void Serialize_vrm_secondaryAnimation(JsonFormatter f, glTF_VRM_SecondaryAnimation value) +{ + f.BeginMap(); + + f.Key("boneGroups"); + Serialize_vrm_secondaryAnimation_boneGroups(f, value.boneGroups); + + f.Key("colliderGroups"); + Serialize_vrm_secondaryAnimation_colliderGroups(f, value.colliderGroups); + + + f.EndMap(); +} + +public static void Serialize_vrm_secondaryAnimation_boneGroups(JsonFormatter f, List value) +{ + f.BeginList(); + + foreach(var item in value) + { + Serialize_vrm_secondaryAnimation_boneGroups_ITEM(f, item); + + } + f.EndList(); +} + +public static void Serialize_vrm_secondaryAnimation_boneGroups_ITEM(JsonFormatter f, glTF_VRM_SecondaryAnimationGroup value) +{ + f.BeginMap(); + + f.Key("comment"); + f.Value(value.comment); + + f.Key("stiffiness"); + f.Value(value.stiffiness); + + f.Key("gravityPower"); + f.Value(value.gravityPower); + + f.Key("gravityDir"); + Serialize_vrm_secondaryAnimation_boneGroups__gravityDir(f, value.gravityDir); + + f.Key("dragForce"); + f.Value(value.dragForce); + + f.Key("center"); + f.Value(value.center); + + f.Key("hitRadius"); + f.Value(value.hitRadius); + + f.Key("bones"); + Serialize_vrm_secondaryAnimation_boneGroups__bones(f, value.bones); + + f.Key("colliderGroups"); + Serialize_vrm_secondaryAnimation_boneGroups__colliderGroups(f, value.colliderGroups); + + + f.EndMap(); +} + +public static void Serialize_vrm_secondaryAnimation_boneGroups__gravityDir(JsonFormatter f, Vector3 value) +{ + f.BeginMap(); + + f.Key("x"); + f.Value(value.x); + + f.Key("y"); + f.Value(value.y); + + f.Key("z"); + f.Value(value.z); + + + f.EndMap(); +} + +public static void Serialize_vrm_secondaryAnimation_boneGroups__bones(JsonFormatter f, Int32[] value) +{ + f.BeginList(); + + foreach(var item in value) + { + f.Value(item); + + } + f.EndList(); +} + +public static void Serialize_vrm_secondaryAnimation_boneGroups__colliderGroups(JsonFormatter f, Int32[] value) +{ + f.BeginList(); + + foreach(var item in value) + { + f.Value(item); + + } + f.EndList(); +} + +public static void Serialize_vrm_secondaryAnimation_colliderGroups(JsonFormatter f, List value) +{ + f.BeginList(); + + foreach(var item in value) + { + Serialize_vrm_secondaryAnimation_colliderGroups_ITEM(f, item); + + } + f.EndList(); +} + +public static void Serialize_vrm_secondaryAnimation_colliderGroups_ITEM(JsonFormatter f, glTF_VRM_SecondaryAnimationColliderGroup value) +{ + f.BeginMap(); + + f.Key("node"); + f.Value(value.node); + + f.Key("colliders"); + Serialize_vrm_secondaryAnimation_colliderGroups__colliders(f, value.colliders); + + + f.EndMap(); +} + +public static void Serialize_vrm_secondaryAnimation_colliderGroups__colliders(JsonFormatter f, List value) +{ + f.BeginList(); + + foreach(var item in value) + { + Serialize_vrm_secondaryAnimation_colliderGroups__colliders_ITEM(f, item); + + } + f.EndList(); +} + +public static void Serialize_vrm_secondaryAnimation_colliderGroups__colliders_ITEM(JsonFormatter f, glTF_VRM_SecondaryAnimationCollider value) +{ + f.BeginMap(); + + f.Key("offset"); + Serialize_vrm_secondaryAnimation_colliderGroups__colliders__offset(f, value.offset); + + f.Key("radius"); + f.Value(value.radius); + + + f.EndMap(); +} + +public static void Serialize_vrm_secondaryAnimation_colliderGroups__colliders__offset(JsonFormatter f, Vector3 value) +{ + f.BeginMap(); + + f.Key("x"); + f.Value(value.x); + + f.Key("y"); + f.Value(value.y); + + f.Key("z"); + f.Value(value.z); + + + f.EndMap(); +} + +public static void Serialize_vrm_materialProperties(JsonFormatter f, List value) +{ + f.BeginList(); + + foreach(var item in value) + { + Serialize_vrm_materialProperties_ITEM(f, item); + + } + f.EndList(); +} + +public static void Serialize_vrm_materialProperties_ITEM(JsonFormatter f, glTF_VRM_Material value) +{ + f.BeginMap(); + + f.Key("name"); + f.Value(value.name); + + f.Key("shader"); + f.Value(value.shader); + + f.Key("renderQueue"); + f.Value(value.renderQueue); + + f.Key("floatProperties"); + Serialize_vrm_materialProperties__floatProperties(f, value.floatProperties); + + f.Key("vectorProperties"); + Serialize_vrm_materialProperties__vectorProperties(f, value.vectorProperties); + + f.Key("textureProperties"); + Serialize_vrm_materialProperties__textureProperties(f, value.textureProperties); + + f.Key("keywordMap"); + Serialize_vrm_materialProperties__keywordMap(f, value.keywordMap); + + f.Key("tagMap"); + Serialize_vrm_materialProperties__tagMap(f, value.tagMap); + + + f.EndMap(); +} + +public static void Serialize_vrm_materialProperties__floatProperties(JsonFormatter f, Dictionary value) +{ + f.BeginMap(); + foreach(var kv in value) + { + f.Key(kv.Key); + f.Value(kv.Value); + } + f.EndMap(); +} + +public static void Serialize_vrm_materialProperties__vectorProperties(JsonFormatter f, Dictionary value) +{ + f.BeginMap(); + foreach(var kv in value) + { + f.Key(kv.Key); + Serialize_vrm_materialProperties__vectorProperties_DICT(f, kv.Value); + } + f.EndMap(); +} + +public static void Serialize_vrm_materialProperties__vectorProperties_DICT(JsonFormatter f, Single[] value) +{ + f.BeginList(); + + foreach(var item in value) + { + f.Value(item); + + } + f.EndList(); +} + +public static void Serialize_vrm_materialProperties__textureProperties(JsonFormatter f, Dictionary value) +{ + f.BeginMap(); + foreach(var kv in value) + { + f.Key(kv.Key); + f.Value(kv.Value); + } + f.EndMap(); +} + +public static void Serialize_vrm_materialProperties__keywordMap(JsonFormatter f, Dictionary value) +{ + f.BeginMap(); + foreach(var kv in value) + { + f.Key(kv.Key); + f.Value(kv.Value); + } + f.EndMap(); +} + +public static void Serialize_vrm_materialProperties__tagMap(JsonFormatter f, Dictionary value) +{ + f.BeginMap(); + foreach(var kv in value) + { + f.Key(kv.Key); + f.Value(kv.Value); + } + f.EndMap(); +} + + } // class +} // namespace diff --git a/Assets/VRM/UniVRM/Scripts/Format/VRMSerializer.g.cs.meta b/Assets/VRM/UniVRM/Scripts/Format/VRMSerializer.g.cs.meta new file mode 100644 index 000000000..c90430fe6 --- /dev/null +++ b/Assets/VRM/UniVRM/Scripts/Format/VRMSerializer.g.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: e6690cb3c5aaeaa4f862b396991bf4a5 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: