Skip to content

Commit

Permalink
Merge pull request #1016 from oocytanb/fix/test_for_exporting_null_mesh
Browse files Browse the repository at this point in the history
Add a test case for exporting nodes contains null mesh
  • Loading branch information
ousttrue authored Jun 9, 2021
2 parents 9f3cbfc + d4cc94e commit 2b8568c
Showing 1 changed file with 73 additions and 0 deletions.
73 changes: 73 additions & 0 deletions Assets/UniGLTF/Tests/UniGLTF/UniGLTFTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,79 @@ public void MeshHasNoRendererTest()
}
}

[Test]
public void ExportingNullMeshTest()
{
var validator = ScriptableObject.CreateInstance<MeshExportValidator>();
var root = new GameObject("root");

try
{
{
var child = GameObject.CreatePrimitive(PrimitiveType.Cube);
child.transform.SetParent(root.transform);
// remove MeshFilter
Component.DestroyImmediate(child.GetComponent<MeshFilter>());
}

{
var child = GameObject.CreatePrimitive(PrimitiveType.Cube);
child.transform.SetParent(root.transform);
// set null
child.GetComponent<MeshFilter>().sharedMesh = null;
}

// validate
validator.SetRoot(root, MeshExportSettings.Default, new DefualtBlendShapeExportFilter());
var vs = validator.Validate(root);
Assert.True(vs.All(x => x.CanExport));

// export
var gltf = new glTF();
string json;
using (var exporter = new gltfExporter(gltf))
{
exporter.Prepare(root);
exporter.Export(UniGLTF.MeshExportSettings.Default, new EditorTextureSerializer());

json = gltf.ToJson();
}

Assert.AreEqual(0, gltf.meshes.Count);
Assert.AreEqual(2, gltf.nodes.Count);
Assert.AreEqual(-1, gltf.nodes[0].mesh);
Assert.AreEqual(-1, gltf.nodes[1].mesh);

// import
{
var parser = new GltfParser();
parser.ParseJson(json, new SimpleStorage(new ArraySegment<byte>(new byte[1024 * 1024])));

using (var context = new ImporterContext(parser))
{
context.Load();

Assert.AreEqual(2, context.Root.transform.GetChildren().Count());

{
var child = context.Root.transform.GetChild(0);
Assert.IsNull(child.GetSharedMesh());
}

{
var child = context.Root.transform.GetChild(1);
Assert.IsNull(child.GetSharedMesh());
}
}
}
}
finally
{
GameObject.DestroyImmediate(root);
ScriptableObject.DestroyImmediate(validator);
}
}

[Serializable]
class CantConstruct
{
Expand Down

0 comments on commit 2b8568c

Please sign in to comment.