diff --git a/Assets/VRM.Samples/Editor/Tests/VRMImportExportTests.cs b/Assets/VRM.Samples/Editor/Tests/VRMImportExportTests.cs index ce0da3f13..0260c88b3 100644 --- a/Assets/VRM.Samples/Editor/Tests/VRMImportExportTests.cs +++ b/Assets/VRM.Samples/Editor/Tests/VRMImportExportTests.cs @@ -17,6 +17,13 @@ namespace VRM.Samples var bytes = f.GetStoreBytes(); node.SetValue(p, bytes); } + + public static string ToJson(this glTF self) + { + var f = new JsonFormatter(); + f.GenSerialize(self); + return f.ToString(); + } } public class VRMImportExportTests diff --git a/Assets/VRM/UniGLTF/Editor/Tests/UniGLTFTests.cs b/Assets/VRM/UniGLTF/Editor/Tests/UniGLTFTests.cs index 0c090fecf..59aa2c4e1 100644 --- a/Assets/VRM/UniGLTF/Editor/Tests/UniGLTFTests.cs +++ b/Assets/VRM/UniGLTF/Editor/Tests/UniGLTFTests.cs @@ -8,6 +8,58 @@ using UnityEngine; namespace UniGLTF { + static class ToJsonExtensions + { + public static string ToJson(this glTF self) + { + var f = new JsonFormatter(); + f.GenSerialize(self); + return f.ToString(); + } + public static string ToJson(this glTFMesh self) + { + var f = new JsonFormatter(); + f.GenSerialize(self); + return f.ToString(); + } + public static string ToJson(this glTFPrimitives self) + { + var f = new JsonFormatter(); + f.GenSerialize(self); + return f.ToString(); + } + public static string ToJson(this glTFAttributes self) + { + var f = new JsonFormatter(); + f.GenSerialize(self); + return f.ToString(); + } + public static string ToJson(this glTFMaterialBaseColorTextureInfo self) + { + var f = new JsonFormatter(); + f.GenSerialize(self); + return f.ToString(); + } + public static string ToJson(this glTFMaterial self) + { + var f = new JsonFormatter(); + f.GenSerialize(self); + return f.ToString(); + } + public static string ToJson(this glTFNode self) + { + var f = new JsonFormatter(); + f.GenSerialize(self); + return f.ToString(); + } + public static string ToJson(this glTFSkin self) + { + var f = new JsonFormatter(); + f.GenSerialize(self); + return f.ToString(); + } + } + public class UniGLTFTests { static GameObject CreateSimpleScene() diff --git a/Assets/VRM/UniGLTF/Scripts/Format/ExtensionsAndExtras/KHR_draco_mesh_compression.cs b/Assets/VRM/UniGLTF/Scripts/Format/ExtensionsAndExtras/KHR_draco_mesh_compression.cs index 1e4b9ae48..d84362e5f 100644 --- a/Assets/VRM/UniGLTF/Scripts/Format/ExtensionsAndExtras/KHR_draco_mesh_compression.cs +++ b/Assets/VRM/UniGLTF/Scripts/Format/ExtensionsAndExtras/KHR_draco_mesh_compression.cs @@ -1,5 +1,4 @@ using System; -using UniJSON; namespace UniGLTF @@ -7,10 +6,5 @@ namespace UniGLTF [Serializable] public partial class glTFPrimitives_extensions : ExtensionsBase { - [JsonSerializeMembers] - void SerializeMembers_draco(GLTFJsonFormatter f) - { - //throw new NotImplementedException(); - } } } diff --git a/Assets/VRM/UniGLTF/Scripts/Format/ExtensionsAndExtras/KHR_materials_unlit.cs b/Assets/VRM/UniGLTF/Scripts/Format/ExtensionsAndExtras/KHR_materials_unlit.cs index 72e28518c..3c220eafb 100644 --- a/Assets/VRM/UniGLTF/Scripts/Format/ExtensionsAndExtras/KHR_materials_unlit.cs +++ b/Assets/VRM/UniGLTF/Scripts/Format/ExtensionsAndExtras/KHR_materials_unlit.cs @@ -4,7 +4,7 @@ using UniJSON; namespace UniGLTF { [Serializable] - public class glTF_KHR_materials_unlit : JsonSerializableBase + public class glTF_KHR_materials_unlit { public static string ExtensionName { @@ -14,11 +14,6 @@ namespace UniGLTF } } - protected override void SerializeMembers(GLTFJsonFormatter f) - { - //throw new System.NotImplementedException(); - } - public static glTFMaterial CreateDefault() { return new glTFMaterial @@ -42,14 +37,5 @@ namespace UniGLTF { [JsonSchema(Required = true)] public glTF_KHR_materials_unlit KHR_materials_unlit; - - [JsonSerializeMembers] - void SerializeMembers_unlit(GLTFJsonFormatter f) - { - if (KHR_materials_unlit != null) - { - f.Key("KHR_materials_unlit"); f.GLTFValue(KHR_materials_unlit); - } - } } } diff --git a/Assets/VRM/UniGLTF/Scripts/Format/ExtensionsAndExtras/KHR_texture_transform.cs b/Assets/VRM/UniGLTF/Scripts/Format/ExtensionsAndExtras/KHR_texture_transform.cs index 8c5034369..b0ec9fd7c 100644 --- a/Assets/VRM/UniGLTF/Scripts/Format/ExtensionsAndExtras/KHR_texture_transform.cs +++ b/Assets/VRM/UniGLTF/Scripts/Format/ExtensionsAndExtras/KHR_texture_transform.cs @@ -6,7 +6,7 @@ using UniJSON; namespace UniGLTF { [Serializable] - public class glTF_KHR_texture_transform : JsonSerializableBase + public class glTF_KHR_texture_transform { public static string ExtensionName { @@ -26,14 +26,6 @@ namespace UniGLTF [ItemJsonSchema(Minimum = 0)] public int texCoord; - - protected override void SerializeMembers(GLTFJsonFormatter f) - { - f.KeyValue(() => offset); - f.KeyValue(() => rotation); - f.KeyValue(() => scale); - f.KeyValue(() => texCoord); - } } [Serializable] @@ -41,18 +33,5 @@ namespace UniGLTF { [JsonSchema(Required = true)] public glTF_KHR_texture_transform KHR_texture_transform; - - /// - /// リフレクションでシリアライズする時は使われない - /// - /// - [JsonSerializeMembers] - void SerializeMembers_textureInfo(GLTFJsonFormatter f) - { - if (KHR_texture_transform != null) - { - f.KeyValue(() => KHR_texture_transform); - } - } } } diff --git a/Assets/VRM/UniGLTF/Scripts/Format/ExtensionsAndExtras/glTFExtensions.cs b/Assets/VRM/UniGLTF/Scripts/Format/ExtensionsAndExtras/glTFExtensions.cs index 20b649bcc..50da34c2f 100644 --- a/Assets/VRM/UniGLTF/Scripts/Format/ExtensionsAndExtras/glTFExtensions.cs +++ b/Assets/VRM/UniGLTF/Scripts/Format/ExtensionsAndExtras/glTFExtensions.cs @@ -7,31 +7,8 @@ using UniJSON; namespace UniGLTF { #region Base - public class JsonSerializeMembersAttribute : Attribute { } - - public class PartialExtensionBase : JsonSerializableBase + public class PartialExtensionBase { - protected override void SerializeMembers(GLTFJsonFormatter f) - { - foreach (var method in this.GetType().GetMethods(BindingFlags.Instance | - BindingFlags.Public | BindingFlags.NonPublic)) - { - if (method.GetCustomAttributes(typeof(JsonSerializeMembersAttribute), true).Any()) - { - method.Invoke(this, new[] { f }); - } - } - } - - public int __count - { - get - { - return typeof(T).GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic) - .Where(x => x.GetCustomAttributes(typeof(JsonSerializeMembersAttribute), true).Any()) - .Count(); - } - } } [ItemJsonSchema(ValueType = ValueNodeType.Object)] diff --git a/Assets/VRM/UniGLTF/Scripts/Format/ExtensionsAndExtras/glTFMesh.Primitives.extras.targetNames.cs b/Assets/VRM/UniGLTF/Scripts/Format/ExtensionsAndExtras/glTFMesh.Primitives.extras.targetNames.cs index bbfc18965..a62a3d2c6 100644 --- a/Assets/VRM/UniGLTF/Scripts/Format/ExtensionsAndExtras/glTFMesh.Primitives.extras.targetNames.cs +++ b/Assets/VRM/UniGLTF/Scripts/Format/ExtensionsAndExtras/glTFMesh.Primitives.extras.targetNames.cs @@ -13,20 +13,5 @@ namespace UniGLTF { [JsonSchema(Required = true, MinItems = 1)] public List targetNames = new List(); - - [JsonSerializeMembers] - void PrimitiveMembers(GLTFJsonFormatter f) - { - if (targetNames.Count > 0) - { - f.Key("targetNames"); - f.BeginList(); - foreach (var x in targetNames) - { - f.Value(x); - } - f.EndList(); - } - } } } diff --git a/Assets/VRM/UniGLTF/Scripts/Format/ExtensionsAndExtras/glTFMesh.extras.targetNames.cs b/Assets/VRM/UniGLTF/Scripts/Format/ExtensionsAndExtras/glTFMesh.extras.targetNames.cs index 49e12de51..56135623d 100644 --- a/Assets/VRM/UniGLTF/Scripts/Format/ExtensionsAndExtras/glTFMesh.extras.targetNames.cs +++ b/Assets/VRM/UniGLTF/Scripts/Format/ExtensionsAndExtras/glTFMesh.extras.targetNames.cs @@ -13,20 +13,5 @@ namespace UniGLTF { [JsonSchema(Required = true, MinItems = 1)] public List targetNames = new List(); - - [JsonSerializeMembers] - void PrimitiveMembers(GLTFJsonFormatter f) - { - if (targetNames.Count > 0) - { - f.Key("targetNames"); - f.BeginList(); - foreach (var x in targetNames) - { - f.Value(x); - } - f.EndList(); - } - } } } diff --git a/Assets/VRM/UniGLTF/Scripts/Format/GLTFJsonFormatter.cs b/Assets/VRM/UniGLTF/Scripts/Format/GLTFJsonFormatter.cs deleted file mode 100644 index 7a6b1b061..000000000 --- a/Assets/VRM/UniGLTF/Scripts/Format/GLTFJsonFormatter.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System.Collections.Generic; -using UniJSON; - - -namespace UniGLTF -{ - public class GLTFJsonFormatter: UniJSON.JsonFormatter - { - public void GLTFValue(JsonSerializableBase s) - { - CommaCheck(); - Store.Write(s.ToJson()); - } - - public void GLTFValue(IEnumerable values) where T : JsonSerializableBase - { - BeginList(); - foreach (var value in values) - { - GLTFValue(value); - } - EndList(); - } - - public void GLTFValue(List values) - { - BeginList(); - foreach (var value in values) - { - this.Value(value); - } - EndList(); - } - } -} diff --git a/Assets/VRM/UniGLTF/Scripts/Format/GLTFJsonFormatter.cs.meta b/Assets/VRM/UniGLTF/Scripts/Format/GLTFJsonFormatter.cs.meta deleted file mode 100644 index eb52e7f5d..000000000 --- a/Assets/VRM/UniGLTF/Scripts/Format/GLTFJsonFormatter.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: b80a7ee38e762de44a90d60d9d4ff4dd -timeCreated: 1531806259 -licenseType: Free -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/VRM/UniGLTF/Scripts/Format/JsonSerializableBase.cs b/Assets/VRM/UniGLTF/Scripts/Format/JsonSerializableBase.cs deleted file mode 100644 index 3d302b1da..000000000 --- a/Assets/VRM/UniGLTF/Scripts/Format/JsonSerializableBase.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; - - -namespace UniGLTF -{ - [Serializable] - public abstract class JsonSerializableBase - { - protected abstract void SerializeMembers(GLTFJsonFormatter f); - - public string ToJson() - { - var f = new GLTFJsonFormatter(); - f.BeginMap(); - - SerializeMembers(f); - - f.EndMap(); - return f.ToString(); - } - } -} diff --git a/Assets/VRM/UniGLTF/Scripts/Format/JsonSerializableBase.cs.meta b/Assets/VRM/UniGLTF/Scripts/Format/JsonSerializableBase.cs.meta deleted file mode 100644 index a21428132..000000000 --- a/Assets/VRM/UniGLTF/Scripts/Format/JsonSerializableBase.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: d169186adbfc59b4b882611d37f0a282 -timeCreated: 1532078625 -licenseType: Free -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/VRM/UniGLTF/Scripts/Format/SerializerTypes.cs b/Assets/VRM/UniGLTF/Scripts/Format/SerializerTypes.cs index fcdee0804..10b7b7009 100644 --- a/Assets/VRM/UniGLTF/Scripts/Format/SerializerTypes.cs +++ b/Assets/VRM/UniGLTF/Scripts/Format/SerializerTypes.cs @@ -3,7 +3,6 @@ public enum SerializerTypes { Generated, // generated, No AOT Problem - JsonSerializable, // manual, Obsolete UniJSON, // reflection, Obsolete } } diff --git a/Assets/VRM/UniGLTF/Scripts/Format/glTF.cs b/Assets/VRM/UniGLTF/Scripts/Format/glTF.cs index 4180f52be..fe0564d4c 100644 --- a/Assets/VRM/UniGLTF/Scripts/Format/glTF.cs +++ b/Assets/VRM/UniGLTF/Scripts/Format/glTF.cs @@ -8,7 +8,7 @@ using UniJSON; namespace UniGLTF { [Serializable] - public class gltfScene : JsonSerializableBase + public class gltfScene { [JsonSchema(MinItems = 1)] [ItemJsonSchema(Minimum = 0)] @@ -17,15 +17,10 @@ namespace UniGLTF public object extensions; public object extras; public string name; - - protected override void SerializeMembers(GLTFJsonFormatter f) - { - f.KeyValue(() => nodes); - } } [Serializable] - public class glTF : JsonSerializableBase, IEquatable + public class glTF : IEquatable { [JsonSchema(Required = true)] public glTFAssets asset = new glTFAssets(); @@ -311,92 +306,6 @@ namespace UniGLTF return string.Format("{0}", asset); } - protected override void SerializeMembers(GLTFJsonFormatter f) - { - if (extensionsUsed.Count > 0) - { - f.Key("extensionsUsed"); f.GLTFValue(extensionsUsed); - } - if (extensions.__count > 0) - { - f.Key("extensions"); f.GLTFValue(extensions); - } - if (extras.__count > 0) - { - f.Key("extras"); f.GLTFValue(extras); - } - - f.Key("asset"); f.GLTFValue(asset); - - // buffer - if (buffers.Any()) - { - f.Key("buffers"); f.GLTFValue(buffers); - } - if (bufferViews.Any()) - { - f.Key("bufferViews"); f.GLTFValue(bufferViews); - } - if (accessors.Any()) - { - f.Key("accessors"); f.GLTFValue(accessors); - } - - // materials - if (images.Any()) - { - f.Key("images"); f.GLTFValue(images); - if (samplers.Count == 0) - { - samplers.Add(new glTFTextureSampler()); - } - } - - if (samplers.Any()) - { - f.Key("samplers"); f.GLTFValue(samplers); - } - - if (textures.Any()) - { - f.Key("textures"); f.GLTFValue(textures); - } - if (materials.Any()) - { - f.Key("materials"); f.GLTFValue(materials); - } - - // meshes - if (meshes.Any()) - { - f.Key("meshes"); f.GLTFValue(meshes); - } - if (skins.Any()) - { - f.Key("skins"); f.GLTFValue(skins); - } - - // scene - if (nodes.Any()) - { - f.Key("nodes"); f.GLTFValue(nodes); - } - if (scenes.Any()) - { - f.Key("scenes"); f.GLTFValue(scenes); - if (scene >= 0) - { - f.KeyValue(() => scene); - } - } - - // animations - if (animations.Any()) - { - f.Key("animations"); f.GLTFValue(animations); - } - } - public bool Equals(glTF other) { return @@ -486,11 +395,6 @@ namespace UniGLTF f.GenSerialize(this); json = f.ToString().ParseAsJson().ToString(" "); } - else if (serializer == SerializerTypes.JsonSerializable) - { - // Obsolete - json = ToJson(); - } else { throw new Exception("[UniVRM Export Error] unknown serializer type"); @@ -522,4 +426,5 @@ namespace UniGLTF return (json, buffers); } } + } diff --git a/Assets/VRM/UniGLTF/Scripts/Format/glTFAnimation.cs b/Assets/VRM/UniGLTF/Scripts/Format/glTFAnimation.cs index 3dfc1c6fa..757a63d7a 100644 --- a/Assets/VRM/UniGLTF/Scripts/Format/glTFAnimation.cs +++ b/Assets/VRM/UniGLTF/Scripts/Format/glTFAnimation.cs @@ -2,13 +2,12 @@ using System.Linq; using System.Collections.Generic; using UniJSON; -using UnityEngine; namespace UniGLTF { [Serializable] - public class glTFAnimationTarget : JsonSerializableBase + public class glTFAnimationTarget { [JsonSchema(Minimum = 0)] public int node; @@ -20,15 +19,6 @@ namespace UniGLTF public object extensions; public object extras; - protected override void SerializeMembers(GLTFJsonFormatter f) - { - f.KeyValue(() => node); - if (!string.IsNullOrEmpty(path)) - { - f.KeyValue(() => path); - } - } - public enum Interpolations { LINEAR, @@ -143,7 +133,7 @@ namespace UniGLTF } [Serializable] - public class glTFAnimationChannel : JsonSerializableBase + public class glTFAnimationChannel { [JsonSchema(Required = true, Minimum = 0)] public int sampler = -1; @@ -154,16 +144,10 @@ namespace UniGLTF // empty schemas public object extensions; public object extras; - - protected override void SerializeMembers(GLTFJsonFormatter f) - { - f.KeyValue(() => sampler); - f.Key("target"); f.GLTFValue(target); - } } [Serializable] - public class glTFAnimationSampler : JsonSerializableBase + public class glTFAnimationSampler { [JsonSchema(Required = true, Minimum = 0)] public int input = -1; @@ -177,20 +161,10 @@ namespace UniGLTF // empty schemas public object extensions; public object extras; - - protected override void SerializeMembers(GLTFJsonFormatter f) - { - f.KeyValue(() => input); - if (!string.IsNullOrEmpty(interpolation)) - { - f.KeyValue(() => interpolation); - } - f.KeyValue(() => output); - } } [Serializable] - public class glTFAnimation : JsonSerializableBase + public class glTFAnimation { public string name = ""; @@ -204,17 +178,6 @@ namespace UniGLTF public object extensions; public object extras; - protected override void SerializeMembers(GLTFJsonFormatter f) - { - if (!string.IsNullOrEmpty(name)) - { - f.KeyValue(() => name); - } - - f.Key("channels"); f.GLTFValue(channels); - f.Key("samplers"); f.GLTFValue(samplers); - } - [Obsolete] public int AddChannelAndGetSampler(int nodeIndex, glTFAnimationTarget.AnimationPropertys property) { diff --git a/Assets/VRM/UniGLTF/Scripts/Format/glTFAssets.cs b/Assets/VRM/UniGLTF/Scripts/Format/glTFAssets.cs index bf691fc82..9fbb1a4ae 100644 --- a/Assets/VRM/UniGLTF/Scripts/Format/glTFAssets.cs +++ b/Assets/VRM/UniGLTF/Scripts/Format/glTFAssets.cs @@ -4,7 +4,7 @@ using UniJSON; namespace UniGLTF { [Serializable] - public class glTFAssets : JsonSerializableBase + public class glTFAssets { public string generator; @@ -20,12 +20,6 @@ namespace UniGLTF public object extensions; public object extras; - protected override void SerializeMembers(GLTFJsonFormatter f) - { - f.Key("generator"); f.Value(generator); - f.Key("version"); f.Value(version); - } - public override string ToString() { return string.Format("GLTF-{0} generated by {1}", version, generator); diff --git a/Assets/VRM/UniGLTF/Scripts/Format/glTFBuffer.cs b/Assets/VRM/UniGLTF/Scripts/Format/glTFBuffer.cs index 14f2cd7ad..32a360ef3 100644 --- a/Assets/VRM/UniGLTF/Scripts/Format/glTFBuffer.cs +++ b/Assets/VRM/UniGLTF/Scripts/Format/glTFBuffer.cs @@ -1,27 +1,16 @@ using System; -using System.Linq; using UniJSON; namespace UniGLTF { [Serializable] - public class glTFBuffer : JsonSerializableBase + public class glTFBuffer { IBytesBuffer Storage; public void OpenStorage(IStorage storage) { Storage = new ArraySegmentByteBuffer(storage.Get(uri)); - /* - if (string.IsNullOrEmpty(uri)) - { - Storage = (glbDataBytes); - } - else - { - Storage = new UriByteBuffer(baseDir, uri); - } - */ } public glTFBuffer() @@ -59,19 +48,10 @@ namespace UniGLTF { return Storage.GetBytes(); } - - protected override void SerializeMembers(GLTFJsonFormatter f) - { - if (!string.IsNullOrEmpty(uri)) - { - f.KeyValue(() => uri); - } - f.KeyValue(() => byteLength); - } } [Serializable] - public class glTFBufferView : JsonSerializableBase + public class glTFBufferView { [JsonSchema(Required = true, Minimum = 0)] public int buffer; @@ -92,27 +72,10 @@ namespace UniGLTF public object extensions; public object extras; public string name; - - protected override void SerializeMembers(GLTFJsonFormatter f) - { - f.KeyValue(() => buffer); - f.KeyValue(() => byteOffset); - f.KeyValue(() => byteLength); - if (target != glBufferTarget.NONE) - { - f.Key("target"); f.Value((int)target); - } - /* When this is not defined, data is tightly packed. When two or more accessors use the same bufferView, this field must be defined. - if (byteStride >= 4) - { - f.KeyValue(() => byteStride); - } - */ - } } [Serializable] - public class glTFSparseIndices : JsonSerializableBase + public class glTFSparseIndices { [JsonSchema(Required = true, Minimum = 0)] public int bufferView = -1; @@ -126,17 +89,10 @@ namespace UniGLTF // empty schemas public object extensions; public object extras; - - protected override void SerializeMembers(GLTFJsonFormatter f) - { - f.KeyValue(() => bufferView); - f.KeyValue(() => byteOffset); - f.Key("componentType"); f.Value((int)componentType); - } } [Serializable] - public class glTFSparseValues : JsonSerializableBase + public class glTFSparseValues { [JsonSchema(Required = true, Minimum = 0)] public int bufferView = -1; @@ -147,16 +103,10 @@ namespace UniGLTF // empty schemas public object extensions; public object extras; - - protected override void SerializeMembers(GLTFJsonFormatter f) - { - f.KeyValue(() => bufferView); - f.KeyValue(() => byteOffset); - } } [Serializable] - public class glTFSparse : JsonSerializableBase + public class glTFSparse { [JsonSchema(Required = true, Minimum = 1)] public int count; @@ -170,17 +120,10 @@ namespace UniGLTF // empty schemas public object extensions; public object extras; - - protected override void SerializeMembers(GLTFJsonFormatter f) - { - f.KeyValue(() => count); - f.Key("indices"); f.GLTFValue(indices); - f.Key("values"); f.GLTFValue(values); - } } [Serializable] - public class glTFAccessor : JsonSerializableBase + public class glTFAccessor { [JsonSchema(Minimum = 0)] public int bufferView = -1; @@ -237,30 +180,5 @@ namespace UniGLTF public object extensions; public object extras; - - protected override void SerializeMembers(GLTFJsonFormatter f) - { - f.KeyValue(() => bufferView); - f.KeyValue(() => byteOffset); - f.KeyValue(() => type); - f.Key("componentType"); f.Value((int)componentType); - f.KeyValue(() => count); - if (max != null && max.Any()) - { - f.KeyValue(() => max); - } - if (min != null && min.Any()) - { - f.KeyValue(() => min); - } - - if (sparse != null && sparse.count > 0) - { - f.Key("sparse"); f.GLTFValue(sparse); - } - - f.KeyValue(() => normalized); - f.KeyValue(() => name); - } } } diff --git a/Assets/VRM/UniGLTF/Scripts/Format/glTFMaterial.cs b/Assets/VRM/UniGLTF/Scripts/Format/glTFMaterial.cs index ef0be0dc2..3a74b60d4 100644 --- a/Assets/VRM/UniGLTF/Scripts/Format/glTFMaterial.cs +++ b/Assets/VRM/UniGLTF/Scripts/Format/glTFMaterial.cs @@ -19,7 +19,7 @@ namespace UniGLTF } [Serializable] - public abstract class glTFTextureInfo : JsonSerializableBase, IglTFTextureinfo + public abstract class glTFTextureInfo : IglTFTextureinfo { [JsonSchema(Required = true, Minimum = 0)] public int index = -1; @@ -31,16 +31,6 @@ namespace UniGLTF public glTFTextureInfo_extensions extensions; public object extras; - protected override void SerializeMembers(GLTFJsonFormatter f) - { - f.KeyValue(() => index); - f.KeyValue(() => texCoord); - if (extensions != null) - { - f.KeyValue(() => extensions); - } - } - public abstract glTFTextureTypes TextureType { get; } } @@ -68,12 +58,6 @@ namespace UniGLTF { public float scale = 1.0f; - protected override void SerializeMembers(GLTFJsonFormatter f) - { - f.KeyValue(() => scale); - base.SerializeMembers(f); - } - public override glTFTextureTypes TextureType { get { return glTFTextureTypes.Normal; } @@ -86,12 +70,6 @@ namespace UniGLTF [JsonSchema(Minimum = 0.0, Maximum = 1.0)] public float strength = 1.0f; - protected override void SerializeMembers(GLTFJsonFormatter f) - { - f.KeyValue(() => strength); - base.SerializeMembers(f); - } - public override glTFTextureTypes TextureType { get { return glTFTextureTypes.Occlusion; } @@ -108,7 +86,7 @@ namespace UniGLTF } [Serializable] - public class glTFPbrMetallicRoughness : JsonSerializableBase + public class glTFPbrMetallicRoughness { public glTFMaterialBaseColorTextureInfo baseColorTexture = null; @@ -127,28 +105,10 @@ namespace UniGLTF // empty schemas public object extensions; public object extras; - - protected override void SerializeMembers(GLTFJsonFormatter f) - { - if (baseColorTexture != null) - { - f.Key("baseColorTexture"); f.GLTFValue(baseColorTexture); - } - if (baseColorFactor != null) - { - f.KeyValue(() => baseColorFactor); - } - if (metallicRoughnessTexture != null) - { - f.Key("metallicRoughnessTexture"); f.GLTFValue(metallicRoughnessTexture); - } - f.KeyValue(() => metallicFactor); - f.KeyValue(() => roughnessFactor); - } } [Serializable] - public class glTFMaterial : JsonSerializableBase + public class glTFMaterial { public string name; public glTFPbrMetallicRoughness pbrMetallicRoughness = new glTFPbrMetallicRoughness @@ -177,46 +137,6 @@ namespace UniGLTF public glTFMaterial_extensions extensions; public object extras; - protected override void SerializeMembers(GLTFJsonFormatter f) - { - if (!String.IsNullOrEmpty(name)) - { - f.Key("name"); f.Value(name); - } - if (pbrMetallicRoughness != null) - { - f.Key("pbrMetallicRoughness"); f.GLTFValue(pbrMetallicRoughness); - } - if (normalTexture != null) - { - f.Key("normalTexture"); f.GLTFValue(normalTexture); - } - if (occlusionTexture != null) - { - f.Key("occlusionTexture"); f.GLTFValue(occlusionTexture); - } - if (emissiveTexture != null) - { - f.Key("emissiveTexture"); f.GLTFValue(emissiveTexture); - } - if (emissiveFactor != null) - { - f.Key("emissiveFactor"); f.Serialize(emissiveFactor); - } - - f.KeyValue(() => doubleSided); - - if (!string.IsNullOrEmpty(alphaMode)) - { - f.KeyValue(() => alphaMode); - } - - if (extensions != null) - { - f.Key("extensions"); f.GLTFValue(extensions); - } - } - public glTFTextureInfo[] GetTextures() { return new glTFTextureInfo[] diff --git a/Assets/VRM/UniGLTF/Scripts/Format/glTFMesh.cs b/Assets/VRM/UniGLTF/Scripts/Format/glTFMesh.cs index 14de38978..c33d15828 100644 --- a/Assets/VRM/UniGLTF/Scripts/Format/glTFMesh.cs +++ b/Assets/VRM/UniGLTF/Scripts/Format/glTFMesh.cs @@ -5,7 +5,7 @@ using UniJSON; namespace UniGLTF { [Serializable] - public class glTFAttributes : JsonSerializableBase + public class glTFAttributes { [JsonSchema(Minimum = 0, ExplicitIgnorableValue = -1)] public int POSITION = -1; @@ -54,22 +54,10 @@ namespace UniGLTF && WEIGHTS_0 == rhs.WEIGHTS_0 ; } - - protected override void SerializeMembers(GLTFJsonFormatter f) - { - f.KeyValue(() => POSITION); - if (NORMAL != -1) f.KeyValue(() => NORMAL); - if (TANGENT != -1) f.KeyValue(() => TANGENT); - if (TEXCOORD_0 != -1) f.KeyValue(() => TEXCOORD_0); - if (TEXCOORD_1 != -1) f.KeyValue(() => TEXCOORD_1); - if (COLOR_0 != -1) f.KeyValue(() => COLOR_0); - if (JOINTS_0 != -1) f.KeyValue(() => JOINTS_0); - if (WEIGHTS_0 != -1) f.KeyValue(() => WEIGHTS_0); - } } [Serializable] - public class gltfMorphTarget : JsonSerializableBase + public class gltfMorphTarget { [JsonSchema(Minimum = 0, ExplicitIgnorableValue = -1)] public int POSITION = -1; @@ -79,20 +67,13 @@ namespace UniGLTF [JsonSchema(Minimum = 0, ExplicitIgnorableValue = -1)] public int TANGENT = -1; - - protected override void SerializeMembers(GLTFJsonFormatter f) - { - f.KeyValue(() => POSITION); - if (NORMAL >= 0) f.KeyValue(() => NORMAL); - if (TANGENT >= 0) f.KeyValue(() => TANGENT); - } } /// /// https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/schema/mesh.primitive.schema.json /// [Serializable] - public class glTFPrimitives : JsonSerializableBase + public class glTFPrimitives { [JsonSchema(EnumValues = new object[] { 0, 1, 2, 3, 4, 5, 6 })] public int mode; @@ -122,26 +103,10 @@ namespace UniGLTF [JsonSchema(SkipSchemaComparison = true)] public glTFPrimitives_extensions extensions = null; - - protected override void SerializeMembers(GLTFJsonFormatter f) - { - f.KeyValue(() => mode); - f.KeyValue(() => indices); - f.Key("attributes"); f.GLTFValue(attributes); - f.KeyValue(() => material); - if (targets != null && targets.Count > 0) - { - f.Key("targets"); f.GLTFValue(targets); - } - if (extras.targetNames.Count > 0) - { - f.Key("extras"); f.GLTFValue(extras); - } - } } [Serializable] - public class glTFMesh : JsonSerializableBase + public class glTFMesh { public string name; @@ -165,15 +130,5 @@ namespace UniGLTF { name = _name; } - - protected override void SerializeMembers(GLTFJsonFormatter f) - { - f.KeyValue(() => name); - f.Key("primitives"); f.GLTFValue(primitives); - if (weights != null && weights.Length > 0) - { - f.KeyValue(() => weights); - } - } } } diff --git a/Assets/VRM/UniGLTF/Scripts/Format/glTFNode.cs b/Assets/VRM/UniGLTF/Scripts/Format/glTFNode.cs index edef688f7..8b1877749 100644 --- a/Assets/VRM/UniGLTF/Scripts/Format/glTFNode.cs +++ b/Assets/VRM/UniGLTF/Scripts/Format/glTFNode.cs @@ -5,7 +5,7 @@ using UniJSON; namespace UniGLTF { [Serializable] - public class glTFNode : JsonSerializableBase + public class glTFNode { // TODO: need an empty string? public string name; @@ -43,36 +43,5 @@ namespace UniGLTF public glTFNode_extensions extensions; public glTFNode_extra extras = new glTFNode_extra(); - - protected override void SerializeMembers(GLTFJsonFormatter f) - { - if (children != null && children.Any()) - { - f.Key("children"); f.BeginList(); - foreach (var child in children) - { - f.Value(child); - } - f.EndList(); - } - - if (!string.IsNullOrEmpty(name)) f.KeyValue(() => name); - if (matrix != null) f.KeyValue(() => matrix); - if (translation != null) f.KeyValue(() => translation); - if (rotation != null) f.KeyValue(() => rotation); - if (scale != null) f.KeyValue(() => scale); - - if (mesh >= 0) f.KeyValue(() => mesh); - if (camera >= 0) f.KeyValue(() => camera); - if (skin >= 0) - { - f.KeyValue(() => skin); - - if (extras.__count > 0) - { - f.Key("extras"); f.GLTFValue(extras); - } - } - } } } diff --git a/Assets/VRM/UniGLTF/Scripts/Format/glTFSkin.cs b/Assets/VRM/UniGLTF/Scripts/Format/glTFSkin.cs index aebffb10a..a4a1911c8 100644 --- a/Assets/VRM/UniGLTF/Scripts/Format/glTFSkin.cs +++ b/Assets/VRM/UniGLTF/Scripts/Format/glTFSkin.cs @@ -4,7 +4,7 @@ using UniJSON; namespace UniGLTF { [Serializable] - public class glTFSkin : JsonSerializableBase + public class glTFSkin { [JsonSchema(Minimum = 0, ExplicitIgnorableValue = -1)] public int inverseBindMatrices = -1; @@ -20,15 +20,5 @@ namespace UniGLTF public object extensions; public object extras; public string name; - - protected override void SerializeMembers(GLTFJsonFormatter f) - { - f.KeyValue(() => inverseBindMatrices); - f.KeyValue(() => joints); - if (skeleton >= 0) - { - f.KeyValue(() => skeleton); - } - } } } diff --git a/Assets/VRM/UniGLTF/Scripts/Format/glTFTexture.cs b/Assets/VRM/UniGLTF/Scripts/Format/glTFTexture.cs index 199846b9e..f5a2fe8ee 100644 --- a/Assets/VRM/UniGLTF/Scripts/Format/glTFTexture.cs +++ b/Assets/VRM/UniGLTF/Scripts/Format/glTFTexture.cs @@ -5,7 +5,7 @@ using UniJSON; namespace UniGLTF { [Serializable] - public class glTFTextureSampler : JsonSerializableBase + public class glTFTextureSampler { [JsonSchema(EnumSerializationType = EnumSerializationType.AsInt, EnumExcludes = new object[] { @@ -33,18 +33,10 @@ namespace UniGLTF public object extensions; public object extras; public string name; - - protected override void SerializeMembers(GLTFJsonFormatter f) - { - f.Key("magFilter"); f.Value((int)magFilter); - f.Key("minFilter"); f.Value((int)minFilter); - f.Key("wrapS"); f.Value((int)wrapS); - f.Key("wrapT"); f.Value((int)wrapT); - } } [Serializable] - public class glTFImage : JsonSerializableBase + public class glTFImage { public string name; public string uri; @@ -52,7 +44,7 @@ namespace UniGLTF [JsonSchema(Dependencies = new string[] { "mimeType" }, Minimum = 0)] public int bufferView; - [JsonSchema(EnumValues = new object[] { "image/jpeg", "image/png" }, EnumSerializationType =EnumSerializationType.AsString)] + [JsonSchema(EnumValues = new object[] { "image/jpeg", "image/png" }, EnumSerializationType = EnumSerializationType.AsString)] public string mimeType; public string GetExt() @@ -84,24 +76,10 @@ namespace UniGLTF // empty schemas public object extensions; public object extras; - - protected override void SerializeMembers(GLTFJsonFormatter f) - { - f.KeyValue(() => name); - if (!string.IsNullOrEmpty(uri)) - { - f.KeyValue(() => uri); - } - else - { - f.KeyValue(() => bufferView); - f.KeyValue(() => mimeType); - } - } } [Serializable] - public class glTFTexture : JsonSerializableBase + public class glTFTexture { [JsonSchema(Minimum = 0)] public int sampler; @@ -113,11 +91,5 @@ namespace UniGLTF public object extensions; public object extras; public string name; - - protected override void SerializeMembers(GLTFJsonFormatter f) - { - f.KeyValue(() => sampler); - f.KeyValue(() => source); - } } } diff --git a/Assets/VRM/UniGLTF/Scripts/IO/ImporterContext.cs b/Assets/VRM/UniGLTF/Scripts/IO/ImporterContext.cs index c6ce7189c..b7c585a96 100644 --- a/Assets/VRM/UniGLTF/Scripts/IO/ImporterContext.cs +++ b/Assets/VRM/UniGLTF/Scripts/IO/ImporterContext.cs @@ -288,10 +288,9 @@ namespace UniGLTF { GLTF = GltfDeserializer.Deserialize(json.ParseAsJson()); } - else if (_serializerType == SerializerTypes.JsonSerializable) + else { - // Obsolete - GLTF = JsonUtility.FromJson(Json); + throw new NotImplementedException(); } if (GLTF.asset.version != "2.0") diff --git a/Assets/VRM/UniVRM/Editor/Tests/UniVRMSerializeTests.cs b/Assets/VRM/UniVRM/Editor/Tests/UniVRMSerializeTests.cs index 8b1caac2e..6e1ca4aab 100644 --- a/Assets/VRM/UniVRM/Editor/Tests/UniVRMSerializeTests.cs +++ b/Assets/VRM/UniVRM/Editor/Tests/UniVRMSerializeTests.cs @@ -1,12 +1,151 @@ using NUnit.Framework; using System; using System.Collections.Generic; -using System.Linq; +using UniGLTF; using UniJSON; using UnityEngine; namespace VRM { + static class ToJsonExtensions + { + public static string ToJson(this glTF self) + { + var f = new JsonFormatter(); + f.GenSerialize(self); + return f.ToString(); + } + public static string ToJson(this glTFMesh self) + { + var f = new JsonFormatter(); + f.GenSerialize(self); + return f.ToString(); + } + public static string ToJson(this glTFPrimitives self) + { + var f = new JsonFormatter(); + f.GenSerialize(self); + return f.ToString(); + } + public static string ToJson(this glTFAttributes self) + { + var f = new JsonFormatter(); + f.GenSerialize(self); + return f.ToString(); + } + public static string ToJson(this glTFMaterialBaseColorTextureInfo self) + { + var f = new JsonFormatter(); + f.GenSerialize(self); + return f.ToString(); + } + public static string ToJson(this glTFMaterial self) + { + var f = new JsonFormatter(); + f.GenSerialize(self); + return f.ToString(); + } + public static string ToJson(this glTFNode self) + { + var f = new JsonFormatter(); + f.GenSerialize(self); + return f.ToString(); + } + public static string ToJson(this glTFSkin self) + { + var f = new JsonFormatter(); + f.GenSerialize(self); + return f.ToString(); + } + + public static string ToJson(this glTF_VRM_MaterialValueBind self) + { + var f = new JsonFormatter(); + f.GenSerialize(self); + return f.ToString(); + } + public static string ToJson(this glTF_VRM_BlendShapeBind self) + { + var f = new JsonFormatter(); + f.GenSerialize(self); + return f.ToString(); + } + public static string ToJson(this glTF_VRM_BlendShapeGroup self) + { + var f = new JsonFormatter(); + f.GenSerialize(self); + return f.ToString(); + } + public static string ToJson(this glTF_VRM_DegreeMap self) + { + var f = new JsonFormatter(); + f.GenSerialize(self); + return f.ToString(); + } + public static string ToJson(this glTF_VRM_MeshAnnotation self) + { + var f = new JsonFormatter(); + f.GenSerialize(self); + return f.ToString(); + } + public static string ToJson(this glTF_VRM_Firstperson self) + { + var f = new JsonFormatter(); + f.GenSerialize(self); + return f.ToString(); + } + public static string ToJson(this glTF_VRM_HumanoidBone self) + { + var f = new JsonFormatter(); + f.GenSerialize(self); + return f.ToString(); + } + public static string ToJson(this glTF_VRM_Humanoid self) + { + var f = new JsonFormatter(); + f.GenSerialize(self); + return f.ToString(); + } + public static string ToJson(this glTF_VRM_Material self) + { + var f = new JsonFormatter(); + f.GenSerialize(self); + return f.ToString(); + } + public static string ToJson(this glTF_VRM_Meta self) + { + var f = new JsonFormatter(); + f.GenSerialize(self); + return f.ToString(); + } + public static string ToJson(this glTF_VRM_SecondaryAnimationCollider self) + { + var f = new JsonFormatter(); + f.GenSerialize(self); + return f.ToString(); + } + public static string ToJson(this glTF_VRM_SecondaryAnimationColliderGroup self) + { + var f = new JsonFormatter(); + f.GenSerialize(self); + return f.ToString(); + } + + public static string ToJson(this glTF_VRM_SecondaryAnimationGroup self) + { + var f = new JsonFormatter(); + f.GenSerialize(self); + return f.ToString(); + } + + public static string ToJson(this glTF_VRM_SecondaryAnimation self) + { + var f = new JsonFormatter(); + f.GenSerialize(self); + return f.ToString(); + } + } + public class UniVRMSerializeTests { [Test] diff --git a/Assets/VRM/UniVRM/Scripts/Format/VRMFormat.cs b/Assets/VRM/UniVRM/Scripts/Format/VRMFormat.cs index 6e50945e4..12715de7d 100644 --- a/Assets/VRM/UniVRM/Scripts/Format/VRMFormat.cs +++ b/Assets/VRM/UniVRM/Scripts/Format/VRMFormat.cs @@ -8,15 +8,6 @@ namespace UniGLTF public partial class glTF_extensions : ExtensionsBase { public VRM.glTF_VRM_extensions VRM; - - [JsonSerializeMembers] - void VRMSerializeMembers(GLTFJsonFormatter f) - { - if (VRM != null) - { - f.Key("VRM"); f.GLTFValue(VRM); - } - } } } @@ -27,7 +18,7 @@ namespace VRM [JsonSchema(Title = "vrm", Description = @" VRM extension is for 3d humanoid avatars (and models) in VR applications. ")] - public class glTF_VRM_extensions : JsonSerializableBase + public class glTF_VRM_extensions { public static string ExtensionName { @@ -41,7 +32,7 @@ VRM extension is for 3d humanoid avatars (and models) in VR applications. public string exporterVersion = "UniVRM-" + VRMVersion.VERSION; [JsonSchema(Description = @"Version of VRM specification. " + VRMSpecVersion.VERSION)] - public string specVersion = VRMSpecVersion.Version; + public string specVersion = VRMSpecVersion.Version; public glTF_VRM_Meta meta = new glTF_VRM_Meta(); public glTF_VRM_Humanoid humanoid = new glTF_VRM_Humanoid(); @@ -49,17 +40,5 @@ VRM extension is for 3d humanoid avatars (and models) in VR applications. public glTF_VRM_BlendShapeMaster blendShapeMaster = new glTF_VRM_BlendShapeMaster(); public glTF_VRM_SecondaryAnimation secondaryAnimation = new glTF_VRM_SecondaryAnimation(); public List materialProperties = new List(); - - protected override void SerializeMembers(GLTFJsonFormatter f) - { - f.KeyValue(() => exporterVersion); - f.KeyValue(() => specVersion); - f.Key("meta"); f.GLTFValue(meta); - f.Key("humanoid"); f.GLTFValue(humanoid); - f.Key("firstPerson"); f.GLTFValue(firstPerson); - f.Key("blendShapeMaster"); f.GLTFValue(blendShapeMaster); - f.Key("secondaryAnimation"); f.GLTFValue(secondaryAnimation); - f.Key("materialProperties"); f.GLTFValue(materialProperties); - } } } diff --git a/Assets/VRM/UniVRM/Scripts/Format/glTF_VRM_BlendShape.cs b/Assets/VRM/UniVRM/Scripts/Format/glTF_VRM_BlendShape.cs index 80e859660..6b7f53951 100644 --- a/Assets/VRM/UniVRM/Scripts/Format/glTF_VRM_BlendShape.cs +++ b/Assets/VRM/UniVRM/Scripts/Format/glTF_VRM_BlendShape.cs @@ -8,23 +8,16 @@ namespace VRM { [Serializable] [JsonSchema(Title = "vrm.blendshape.materialbind")] - public class glTF_VRM_MaterialValueBind : UniGLTF.JsonSerializableBase + public class glTF_VRM_MaterialValueBind { public string materialName; public string propertyName; public float[] targetValue; - - protected override void SerializeMembers(GLTFJsonFormatter f) - { - f.KeyValue(() => materialName); - f.KeyValue(() => propertyName); - f.KeyValue(() => targetValue); - } } [Serializable] [JsonSchema(Title = "vrm.blendshape.bind")] - public class glTF_VRM_BlendShapeBind : UniGLTF.JsonSerializableBase + public class glTF_VRM_BlendShapeBind { [JsonSchema(Required = true, Minimum = 0)] public int mesh = -1; @@ -32,15 +25,8 @@ namespace VRM [JsonSchema(Required = true, Minimum = 0)] public int index = -1; - [JsonSchema(Required =true, Minimum = 0, Maximum = 100, Description = @"SkinnedMeshRenderer.SetBlendShapeWeight")] + [JsonSchema(Required = true, Minimum = 0, Maximum = 100, Description = @"SkinnedMeshRenderer.SetBlendShapeWeight")] public float weight = 0; - - protected override void SerializeMembers(GLTFJsonFormatter f) - { - f.KeyValue(() => mesh); - f.KeyValue(() => index); - f.KeyValue(() => weight); - } } public enum BlendShapePreset @@ -75,7 +61,7 @@ namespace VRM [Serializable] [JsonSchema(Title = "vrm.blendshape.group", Description = "BlendShapeClip of UniVRM")] - public class glTF_VRM_BlendShapeGroup : UniGLTF.JsonSerializableBase + public class glTF_VRM_BlendShapeGroup { [JsonSchema(Description = "Expression name")] public string name; @@ -110,27 +96,12 @@ namespace VRM [JsonSchema(Description = "0 or 1. Do not allow an intermediate value. Value should rounded")] public bool isBinary; - - protected override void SerializeMembers(GLTFJsonFormatter f) - { - f.KeyValue(() => name); - f.KeyValue(() => presetName); - f.KeyValue(() => isBinary); - f.Key("binds"); f.GLTFValue(binds); - f.Key("materialValues"); f.GLTFValue(materialValues); - } } [Serializable] [JsonSchema(Title = "vrm.blendshape", Description = "BlendShapeAvatar of UniVRM")] - public class glTF_VRM_BlendShapeMaster : UniGLTF.JsonSerializableBase + public class glTF_VRM_BlendShapeMaster { public List blendShapeGroups = new List(); - - - protected override void SerializeMembers(GLTFJsonFormatter f) - { - f.Key("blendShapeGroups"); f.GLTFValue(blendShapeGroups); - } } } diff --git a/Assets/VRM/UniVRM/Scripts/Format/glTF_VRM_FirstPerson.cs b/Assets/VRM/UniVRM/Scripts/Format/glTF_VRM_FirstPerson.cs index d376478fa..9b741367b 100644 --- a/Assets/VRM/UniVRM/Scripts/Format/glTF_VRM_FirstPerson.cs +++ b/Assets/VRM/UniVRM/Scripts/Format/glTF_VRM_FirstPerson.cs @@ -9,7 +9,7 @@ namespace VRM { [Serializable] [JsonSchema(Title = "vrm.firstperson.degreemap")] - public class glTF_VRM_DegreeMap : UniGLTF.JsonSerializableBase + public class glTF_VRM_DegreeMap { [JsonSchema(Description = "None linear mapping params. time, value, inTangent, outTangent")] public float[] curve; @@ -19,16 +19,6 @@ namespace VRM [JsonSchema(Description = "Look at map range degree from xRange.")] public float yRange = 10.0f; - - protected override void SerializeMembers(GLTFJsonFormatter f) - { - if (curve != null) - { - f.KeyValue(() => curve); - } - f.KeyValue(() => xRange); - f.KeyValue(() => yRange); - } } public enum FirstPersonFlag @@ -41,19 +31,13 @@ namespace VRM [Serializable] [JsonSchema(Title = "vrm.firstperson.meshannotation")] - public class glTF_VRM_MeshAnnotation : JsonSerializableBase + public class glTF_VRM_MeshAnnotation { // When the value is -1, it means that no target mesh is found. [JsonSchema(Minimum = 0)] public int mesh; public string firstPersonFlag; - - protected override void SerializeMembers(GLTFJsonFormatter f) - { - f.KeyValue(() => mesh); - f.KeyValue(() => firstPersonFlag); - } } public enum LookAtType @@ -65,7 +49,7 @@ namespace VRM [Serializable] [JsonSchema(Title = "vrm.firstperson")] - public class glTF_VRM_Firstperson : UniGLTF.JsonSerializableBase + public class glTF_VRM_Firstperson { // When the value is -1, it means that no bone for first person is found. [JsonSchema(Description = "The bone whose rendering should be turned off in first-person view. Usually Head is specified.", Minimum = 0, ExplicitIgnorableValue = -1)] @@ -103,18 +87,5 @@ namespace VRM [JsonSchema(Description = "Eye controller setting.")] public glTF_VRM_DegreeMap lookAtVerticalUp = new glTF_VRM_DegreeMap(); - - protected override void SerializeMembers(GLTFJsonFormatter f) - { - f.KeyValue(() => firstPersonBone); - f.KeyValue(() => firstPersonBoneOffset); - f.Key("meshAnnotations"); f.GLTFValue(meshAnnotations); - - f.KeyValue(() => lookAtTypeName); - f.Key("lookAtHorizontalInner"); f.GLTFValue(lookAtHorizontalInner); - f.Key("lookAtHorizontalOuter"); f.GLTFValue(lookAtHorizontalOuter); - f.Key("lookAtVerticalDown"); f.GLTFValue(lookAtVerticalDown); - f.Key("lookAtVerticalUp"); f.GLTFValue(lookAtVerticalUp); - } } } diff --git a/Assets/VRM/UniVRM/Scripts/Format/glTF_VRM_Humanoid.cs b/Assets/VRM/UniVRM/Scripts/Format/glTF_VRM_Humanoid.cs index 6065a38da..4a7d36419 100644 --- a/Assets/VRM/UniVRM/Scripts/Format/glTF_VRM_Humanoid.cs +++ b/Assets/VRM/UniVRM/Scripts/Format/glTF_VRM_Humanoid.cs @@ -91,7 +91,7 @@ namespace VRM [Serializable] [JsonSchema(Title = "vrm.humanoid.bone")] - public class glTF_VRM_HumanoidBone : JsonSerializableBase + public class glTF_VRM_HumanoidBone { [JsonSchema(Description = "Human bone name.", EnumValues = new object[] { @@ -183,25 +183,11 @@ namespace VRM [JsonSchema(Description = "Unity's HumanLimit.axisLength")] public float axisLength; - - protected override void SerializeMembers(GLTFJsonFormatter f) - { - f.Key("bone"); f.Value((string) bone.ToString()); - f.KeyValue(() => node); - f.KeyValue(() => useDefaultValues); - if (!useDefaultValues) - { - f.KeyValue(() => min); - f.KeyValue(() => max); - f.KeyValue(() => center); - f.KeyValue(() => axisLength); - } - } } [Serializable] [JsonSchema(Title = "vrm.humanoid")] - public class glTF_VRM_Humanoid : JsonSerializableBase + public class glTF_VRM_Humanoid { public List humanBones = new List(); @@ -248,19 +234,6 @@ namespace VRM } } - protected override void SerializeMembers(GLTFJsonFormatter f) - { - f.Key("humanBones"); f.GLTFValue(humanBones); - f.KeyValue(() => armStretch); - f.KeyValue(() => legStretch); - f.KeyValue(() => upperArmTwist); - f.KeyValue(() => lowerArmTwist); - f.KeyValue(() => upperLegTwist); - f.KeyValue(() => lowerLegTwist); - f.KeyValue(() => feetSpacing); - f.KeyValue(() => hasTranslationDoF); - } - public void Apply(UniHumanoid.AvatarDescription desc, List nodes) { armStretch = desc.armStretch; diff --git a/Assets/VRM/UniVRM/Scripts/Format/glTF_VRM_Material.cs b/Assets/VRM/UniVRM/Scripts/Format/glTF_VRM_Material.cs index 726cd58df..47288a410 100644 --- a/Assets/VRM/UniVRM/Scripts/Format/glTF_VRM_Material.cs +++ b/Assets/VRM/UniVRM/Scripts/Format/glTF_VRM_Material.cs @@ -9,7 +9,7 @@ namespace VRM { [Serializable] [JsonSchema(Title = "vrm.material")] - public class glTF_VRM_Material : JsonSerializableBase + public class glTF_VRM_Material { public string name; public string shader; @@ -23,53 +23,6 @@ namespace VRM public static readonly string VRM_USE_GLTFSHADER = "VRM_USE_GLTFSHADER"; - protected override void SerializeMembers(GLTFJsonFormatter f) - { - f.KeyValue(() => name); - f.KeyValue(() => renderQueue); - f.KeyValue(() => shader); - { - f.Key("floatProperties"); f.BeginMap(); - foreach (var kv in floatProperties) - { - f.Key(kv.Key); f.Value(kv.Value); - } - f.EndMap(); - } - { - f.Key("vectorProperties"); f.BeginMap(); - foreach (var kv in vectorProperties) - { - f.Key(kv.Key); f.Serialize(kv.Value.ToArray()); - } - f.EndMap(); - } - { - f.Key("textureProperties"); f.BeginMap(); - foreach (var kv in textureProperties) - { - f.Key(kv.Key); f.Value(kv.Value); - } - f.EndMap(); - } - { - f.Key("keywordMap"); f.BeginMap(); - foreach (var kv in keywordMap) - { - f.Key(kv.Key); f.Value(kv.Value); - } - f.EndMap(); - } - { - f.Key("tagMap"); f.BeginMap(); - foreach (var kv in tagMap) - { - f.Key(kv.Key); f.Value(kv.Value); - } - f.EndMap(); - } - } - public static List Parse(string src) { var json = JsonParser.Parse(src)["extensions"]["VRM"]["materialProperties"]; diff --git a/Assets/VRM/UniVRM/Scripts/Format/glTF_VRM_Meta.cs b/Assets/VRM/UniVRM/Scripts/Format/glTF_VRM_Meta.cs index 7610142ff..c1036ebc7 100644 --- a/Assets/VRM/UniVRM/Scripts/Format/glTF_VRM_Meta.cs +++ b/Assets/VRM/UniVRM/Scripts/Format/glTF_VRM_Meta.cs @@ -32,7 +32,7 @@ namespace VRM [Serializable] [JsonSchema(Title = "vrm.meta")] - public class glTF_VRM_Meta : JsonSerializableBase + public class glTF_VRM_Meta { static UssageLicense FromString(string src) { @@ -146,26 +146,5 @@ namespace VRM [JsonSchema(Description = "If “Other” is selected, put the URL link of the license document here.")] public string otherLicenseUrl; #endregion - - protected override void SerializeMembers(GLTFJsonFormatter f) - { - f.KeyValue(() => version); - - f.KeyValue(() => author); - f.KeyValue(() => contactInformation); - f.KeyValue(() => reference); - - f.KeyValue(() => title); - f.KeyValue(() => texture); - - f.KeyValue(() => allowedUserName); - f.KeyValue(() => violentUssageName); - f.KeyValue(() => sexualUssageName); - f.KeyValue(() => commercialUssageName); - f.KeyValue(() => otherPermissionUrl); - - f.KeyValue(() => licenseName); - f.KeyValue(() => otherLicenseUrl); - } } } diff --git a/Assets/VRM/UniVRM/Scripts/Format/glTF_VRM_SecondaryAnimation.cs b/Assets/VRM/UniVRM/Scripts/Format/glTF_VRM_SecondaryAnimation.cs index 5d825b8c3..ba5257ec3 100644 --- a/Assets/VRM/UniVRM/Scripts/Format/glTF_VRM_SecondaryAnimation.cs +++ b/Assets/VRM/UniVRM/Scripts/Format/glTF_VRM_SecondaryAnimation.cs @@ -8,42 +8,30 @@ using UnityEngine; namespace VRM { [Serializable] - public class glTF_VRM_SecondaryAnimationCollider : JsonSerializableBase + public class glTF_VRM_SecondaryAnimationCollider { [JsonSchema(Description = "The local coordinate from the node of the collider group.")] public Vector3 offset; [JsonSchema(Description = "The radius of the collider.")] public float radius; - - protected override void SerializeMembers(GLTFJsonFormatter f) - { - f.KeyValue(() => offset); - f.KeyValue(() => radius); - } } [Serializable] [JsonSchema(Title = "vrm.secondaryanimation.collidergroup", Description = @"Set sphere balls for colliders used for collision detections with swaying objects.")] - public class glTF_VRM_SecondaryAnimationColliderGroup : JsonSerializableBase + public class glTF_VRM_SecondaryAnimationColliderGroup { [JsonSchema(Description = "The node of the collider group for setting up collision detections.", Minimum = 0)] public int node; public List colliders = new List(); - - protected override void SerializeMembers(GLTFJsonFormatter f) - { - f.KeyValue(() => node); - f.Key("colliders"); f.GLTFValue(colliders); - } } [Serializable] [JsonSchema(Title = "vrm.secondaryanimation.spring")] - public class glTF_VRM_SecondaryAnimationGroup : JsonSerializableBase + public class glTF_VRM_SecondaryAnimationGroup { [JsonSchema(Description = "Annotation comment")] public string comment; @@ -76,35 +64,16 @@ namespace VRM [JsonSchema(Description = "Specify the index of the collider group for collisions with swaying objects.")] [ItemJsonSchema(Minimum = 0)] public int[] colliderGroups = new int[] { }; - - protected override void SerializeMembers(GLTFJsonFormatter f) - { - f.KeyValue(() => comment); - f.KeyValue(() => stiffiness); - f.KeyValue(() => gravityPower); - f.KeyValue(() => gravityDir); - f.KeyValue(() => dragForce); - f.KeyValue(() => center); - f.KeyValue(() => hitRadius); - f.KeyValue(() => bones); - f.KeyValue(() => colliderGroups); - } } [Serializable] [JsonSchema(Title = "vrm.secondaryanimation", Description = "The setting of automatic animation of string-like objects such as tails and hairs.")] - public class glTF_VRM_SecondaryAnimation : JsonSerializableBase + public class glTF_VRM_SecondaryAnimation { [JsonSchema(ExplicitIgnorableItemLength = 0)] public List boneGroups = new List(); [JsonSchema(ExplicitIgnorableItemLength = 0)] public List colliderGroups = new List(); - - protected override void SerializeMembers(GLTFJsonFormatter f) - { - f.Key("boneGroups"); f.GLTFValue(boneGroups); - f.Key("colliderGroups"); f.GLTFValue(colliderGroups); - } } } diff --git a/Assets/VRM/UniVRM/Scripts/SpringBone/VRMSpringUtility.cs b/Assets/VRM/UniVRM/Scripts/SpringBone/VRMSpringUtility.cs index 7d71909fe..eb216aa0a 100644 --- a/Assets/VRM/UniVRM/Scripts/SpringBone/VRMSpringUtility.cs +++ b/Assets/VRM/UniVRM/Scripts/SpringBone/VRMSpringUtility.cs @@ -59,7 +59,7 @@ namespace VRM spring.boneGroups.Add ); - File.WriteAllText(path, spring.ToJson()); + // File.WriteAllText(path, spring.ToJson()); } #endregion