diff --git a/Assets/VRM/UniGLTF/Editor/Tests/UniGLTFTests.cs b/Assets/VRM/UniGLTF/Editor/Tests/UniGLTFTests.cs index d46ed821f..ce5d0ebee 100644 --- a/Assets/VRM/UniGLTF/Editor/Tests/UniGLTFTests.cs +++ b/Assets/VRM/UniGLTF/Editor/Tests/UniGLTFTests.cs @@ -647,20 +647,43 @@ namespace UniGLTF Assert.AreNotEqual(gltf.nodes[0].mesh, gltf.nodes[1].mesh); // import - var context = new ImporterContext(); - context.ParseJson(json, new SimpleStorage(new ArraySegment(new byte[1024 * 1024]))); - //Debug.LogFormat("{0}", context.Json); - context.Load(); + { + var context = new ImporterContext(); + context.ParseJson(json, new SimpleStorage(new ArraySegment(new byte[1024 * 1024]))); + //Debug.LogFormat("{0}", context.Json); + context.Load(); - var importedRed = context.Root.transform.GetChild(0); - var importedRedMaterial = importedRed.GetComponent().sharedMaterial; - Assert.AreEqual("red", importedRedMaterial.name); - Assert.AreEqual(Color.red, importedRedMaterial.color); + var importedRed = context.Root.transform.GetChild(0); + var importedRedMaterial = importedRed.GetComponent().sharedMaterial; + Assert.AreEqual("red", importedRedMaterial.name); + Assert.AreEqual(Color.red, importedRedMaterial.color); - var importedBlue = context.Root.transform.GetChild(1); - var importedBlueMaterial = importedBlue.GetComponent().sharedMaterial; - Assert.AreEqual("blue", importedBlueMaterial.name); - Assert.AreEqual(Color.blue, importedBlueMaterial.color); + var importedBlue = context.Root.transform.GetChild(1); + var importedBlueMaterial = importedBlue.GetComponent().sharedMaterial; + Assert.AreEqual("blue", importedBlueMaterial.name); + Assert.AreEqual(Color.blue, importedBlueMaterial.color); + } + + // import new version + { + var context = new ImporterContext + { + UseUniJSONParser = true + }; + context.ParseJson(json, new SimpleStorage(new ArraySegment(new byte[1024 * 1024]))); + //Debug.LogFormat("{0}", context.Json); + context.Load(); + + var importedRed = context.Root.transform.GetChild(0); + var importedRedMaterial = importedRed.GetComponent().sharedMaterial; + Assert.AreEqual("red", importedRedMaterial.name); + Assert.AreEqual(Color.red, importedRedMaterial.color); + + var importedBlue = context.Root.transform.GetChild(1); + var importedBlueMaterial = importedBlue.GetComponent().sharedMaterial; + Assert.AreEqual("blue", importedBlueMaterial.name); + Assert.AreEqual(Color.blue, importedBlueMaterial.color); + } } finally { @@ -685,7 +708,6 @@ namespace UniGLTF public CantConstruct Value; } - [Test] public void JsonUtilityTest() { @@ -693,5 +715,13 @@ namespace UniGLTF Assert.NotNull(dummy.Value); Assert.False(dummy.Value.Value); } + + [Test] + public void UniJSONTest() + { + var dummy = default(Dummy); + "{}".ParseAsJson().Deserialize(ref dummy); + Assert.Null(dummy.Value); + } } } diff --git a/Assets/VRM/UniGLTF/Scripts/IO/ImporterContext.cs b/Assets/VRM/UniGLTF/Scripts/IO/ImporterContext.cs index 82c78e51e..096699a06 100644 --- a/Assets/VRM/UniGLTF/Scripts/IO/ImporterContext.cs +++ b/Assets/VRM/UniGLTF/Scripts/IO/ImporterContext.cs @@ -6,6 +6,7 @@ using System.IO; using System.Text; using System.Collections; using DepthFirstScheduler; +using UniJSON; #if UNITY_EDITOR using UnityEditor; #endif @@ -259,12 +260,21 @@ namespace UniGLTF new SimpleStorage(chunks[1].Bytes)); } + public bool UseUniJSONParser; public virtual void ParseJson(string json, IStorage storage) { Json = json; Storage = storage; - GLTF = JsonUtility.FromJson(Json); + if (UseUniJSONParser) + { + Json.ParseAsJson().Deserialize(ref GLTF); + } + else + { + GLTF = JsonUtility.FromJson(Json); + } + if (GLTF.asset.version != "2.0") { throw new UniGLTFException("unknown gltf version {0}", GLTF.asset.version); diff --git a/Assets/VRM/UniGLTF/Scripts/IO/MaterialImporter.cs b/Assets/VRM/UniGLTF/Scripts/IO/MaterialImporter.cs index 8e9cd4b03..26311424e 100644 --- a/Assets/VRM/UniGLTF/Scripts/IO/MaterialImporter.cs +++ b/Assets/VRM/UniGLTF/Scripts/IO/MaterialImporter.cs @@ -89,10 +89,13 @@ namespace UniGLTF if (x.extensions != null && x.extensions.KHR_materials_unlit != null) { // texture - var texture = m_context.GetTexture(x.pbrMetallicRoughness.baseColorTexture.index); - if (texture != null) + if (x.pbrMetallicRoughness.baseColorTexture != null) { - material.mainTexture = texture.Texture; + var texture = m_context.GetTexture(x.pbrMetallicRoughness.baseColorTexture.index); + if (texture != null) + { + material.mainTexture = texture.Texture; + } } // color