mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-09-13 06:20:01 -05:00
Add ImporterContext.UseUniJSONParser. Add Test. Add nullcheck.
This commit is contained in:
@@ -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<byte>(new byte[1024 * 1024])));
|
||||
//Debug.LogFormat("{0}", context.Json);
|
||||
context.Load();
|
||||
{
|
||||
var context = new ImporterContext();
|
||||
context.ParseJson(json, new SimpleStorage(new ArraySegment<byte>(new byte[1024 * 1024])));
|
||||
//Debug.LogFormat("{0}", context.Json);
|
||||
context.Load();
|
||||
|
||||
var importedRed = context.Root.transform.GetChild(0);
|
||||
var importedRedMaterial = importedRed.GetComponent<Renderer>().sharedMaterial;
|
||||
Assert.AreEqual("red", importedRedMaterial.name);
|
||||
Assert.AreEqual(Color.red, importedRedMaterial.color);
|
||||
var importedRed = context.Root.transform.GetChild(0);
|
||||
var importedRedMaterial = importedRed.GetComponent<Renderer>().sharedMaterial;
|
||||
Assert.AreEqual("red", importedRedMaterial.name);
|
||||
Assert.AreEqual(Color.red, importedRedMaterial.color);
|
||||
|
||||
var importedBlue = context.Root.transform.GetChild(1);
|
||||
var importedBlueMaterial = importedBlue.GetComponent<Renderer>().sharedMaterial;
|
||||
Assert.AreEqual("blue", importedBlueMaterial.name);
|
||||
Assert.AreEqual(Color.blue, importedBlueMaterial.color);
|
||||
var importedBlue = context.Root.transform.GetChild(1);
|
||||
var importedBlueMaterial = importedBlue.GetComponent<Renderer>().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<byte>(new byte[1024 * 1024])));
|
||||
//Debug.LogFormat("{0}", context.Json);
|
||||
context.Load();
|
||||
|
||||
var importedRed = context.Root.transform.GetChild(0);
|
||||
var importedRedMaterial = importedRed.GetComponent<Renderer>().sharedMaterial;
|
||||
Assert.AreEqual("red", importedRedMaterial.name);
|
||||
Assert.AreEqual(Color.red, importedRedMaterial.color);
|
||||
|
||||
var importedBlue = context.Root.transform.GetChild(1);
|
||||
var importedBlueMaterial = importedBlue.GetComponent<Renderer>().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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<glTF>(Json);
|
||||
if (UseUniJSONParser)
|
||||
{
|
||||
Json.ParseAsJson().Deserialize(ref GLTF);
|
||||
}
|
||||
else
|
||||
{
|
||||
GLTF = JsonUtility.FromJson<glTF>(Json);
|
||||
}
|
||||
|
||||
if (GLTF.asset.version != "2.0")
|
||||
{
|
||||
throw new UniGLTFException("unknown gltf version {0}", GLTF.asset.version);
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user