diff --git a/Assets/VRM.Samples/Editor/Tests/VRMImportExportTests.cs b/Assets/VRM.Samples/Editor/Tests/VRMImportExportTests.cs index c9c721cfe..cf25c4252 100644 --- a/Assets/VRM.Samples/Editor/Tests/VRMImportExportTests.cs +++ b/Assets/VRM.Samples/Editor/Tests/VRMImportExportTests.cs @@ -25,7 +25,7 @@ namespace VRM.Samples { get { - return Path.GetFullPath(Application.dataPath + "/../Tests/Models/Alicia_vrm-0.40/AliciaSolid_vrm-0.40.vrm") + return Path.GetFullPath(Application.dataPath + "/../Tests/Models/Alicia_vrm-0.51/AliciaSolid_vrm-0.51.vrm") .Replace("\\", "/"); } } @@ -139,7 +139,7 @@ namespace VRM.Samples File.WriteAllText("new.json", newJson); // 比較 - Assert.AreEqual(oldJson, newJson); + Assert.AreEqual(oldJson.ParseAsJson().ToString(), newJson.ParseAsJson().ToString()); // 生成デシリアライザでロードする var ff = new JsonFormatter(); @@ -147,7 +147,7 @@ namespace VRM.Samples ff.Clear(); ff.GenSerialize(des); var desJson = ff.ToString().ParseAsJson().ToString(" "); - Assert.AreEqual(oldJson, desJson); + Assert.AreEqual(oldJson.ParseAsJson().ToString(), desJson.ParseAsJson().ToString()); } } } diff --git a/Assets/VRM/UniGLTF/Editor/Tests/UniGLTFTests.cs b/Assets/VRM/UniGLTF/Editor/Tests/UniGLTFTests.cs index b202b072d..a453d0176 100644 --- a/Assets/VRM/UniGLTF/Editor/Tests/UniGLTFTests.cs +++ b/Assets/VRM/UniGLTF/Editor/Tests/UniGLTFTests.cs @@ -668,7 +668,7 @@ namespace UniGLTF { var context = new ImporterContext { - UseUniJSONParser = true + SerializerType = SerializerTypes.UniJSON }; context.ParseJson(json, new SimpleStorage(new ArraySegment(new byte[1024 * 1024]))); //Debug.LogFormat("{0}", context.Json); diff --git a/Assets/VRM/UniGLTF/Scripts/Format/SerializerTypes.cs b/Assets/VRM/UniGLTF/Scripts/Format/SerializerTypes.cs new file mode 100644 index 000000000..9dc459c36 --- /dev/null +++ b/Assets/VRM/UniGLTF/Scripts/Format/SerializerTypes.cs @@ -0,0 +1,9 @@ +namespace UniGLTF +{ + public enum SerializerTypes + { + JsonSerializable, // manual, Obsolete + UniJSON, // reflection + Generated, // generated, experimental for mobile + } +} diff --git a/Assets/VRM/UniGLTF/Scripts/Format/SerializerTypes.cs.meta b/Assets/VRM/UniGLTF/Scripts/Format/SerializerTypes.cs.meta new file mode 100644 index 000000000..6ff72b756 --- /dev/null +++ b/Assets/VRM/UniGLTF/Scripts/Format/SerializerTypes.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 2b17414c7f3ba564083dbcebda778633 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/VRM/UniGLTF/Scripts/Format/glTF.cs b/Assets/VRM/UniGLTF/Scripts/Format/glTF.cs index dad76ad86..f7de69655 100644 --- a/Assets/VRM/UniGLTF/Scripts/Format/glTF.cs +++ b/Assets/VRM/UniGLTF/Scripts/Format/glTF.cs @@ -468,10 +468,10 @@ namespace UniGLTF return f.ToString(); } - public byte[] ToGlbBytes(bool UseUniJSONSerializer = false) + public byte[] ToGlbBytes(SerializerTypes serializer = SerializerTypes.UniJSON) { string json; - if (UseUniJSONSerializer) + if (serializer == SerializerTypes.UniJSON) { var c = new JsonSchemaValidationContext(this) { @@ -479,9 +479,20 @@ namespace UniGLTF }; json = JsonSchema.FromType(GetType()).Serialize(this, c); } + else if (serializer == SerializerTypes.Generated) + { + var f = new JsonFormatter(); + f.GenSerialize(this); + json = f.ToString().ParseAsJson().ToString(" "); + } + else if(serializer == SerializerTypes.JsonSerializable) + { + // Obsolete + json = ToJson(); + } else { - json = ToJson(); + throw new Exception("[UniVRM Export Error] unknown serializer type"); } RemoveUnusedExtensions(json); diff --git a/Assets/VRM/UniGLTF/Scripts/IO/ImporterContext.cs b/Assets/VRM/UniGLTF/Scripts/IO/ImporterContext.cs index 1c2c81201..8f1824bb2 100644 --- a/Assets/VRM/UniGLTF/Scripts/IO/ImporterContext.cs +++ b/Assets/VRM/UniGLTF/Scripts/IO/ImporterContext.cs @@ -271,18 +271,25 @@ namespace UniGLTF } } - public bool UseUniJSONParser; + private SerializerTypes _serializerType = SerializerTypes.UniJSON; + public SerializerTypes SerializerType { get { return _serializerType; } set { _serializerType = value; } } + public virtual void ParseJson(string json, IStorage storage) { Json = json; Storage = storage; - if (UseUniJSONParser) + if (_serializerType == SerializerTypes.UniJSON) { Json.ParseAsJson().Deserialize(ref GLTF); } - else + else if (_serializerType == SerializerTypes.Generated) { + GLTF = GltfDeserializer.Deserialize(json.ParseAsJson()); + } + else if (_serializerType == SerializerTypes.JsonSerializable) + { + // Obsolete GLTF = JsonUtility.FromJson(Json); } diff --git a/Assets/VRM/UniVRM/Scripts/Format/VRMExportSettings.cs b/Assets/VRM/UniVRM/Scripts/Format/VRMExportSettings.cs index 659456f9d..c96f71c7f 100644 --- a/Assets/VRM/UniVRM/Scripts/Format/VRMExportSettings.cs +++ b/Assets/VRM/UniVRM/Scripts/Format/VRMExportSettings.cs @@ -383,7 +383,7 @@ namespace VRM vrm.extensions.VRM.meta.reference = Reference; - var bytes = vrm.ToGlbBytes(UseExperimentalExporter); + var bytes = vrm.ToGlbBytes(UseExperimentalExporter?SerializerTypes.Generated:SerializerTypes.UniJSON); File.WriteAllBytes(path, bytes); Debug.LogFormat("Export elapsed {0}", sw.Elapsed); }