| | 1 | | using DCL.Components; |
| | 2 | | using DCL.Helpers; |
| | 3 | | using DCL.Models; |
| | 4 | | using Newtonsoft.Json; |
| | 5 | | using NUnit.Framework; |
| | 6 | | using System.Collections; |
| | 7 | | using UnityEngine; |
| | 8 | | using UnityEngine.TestTools; |
| | 9 | |
|
| | 10 | | public class LoadableShapesMiscTests : IntegrationTestSuite_Legacy |
| | 11 | | { |
| | 12 | | [UnityTest] |
| | 13 | | public IEnumerator OBJShapeUpdate() |
| | 14 | | { |
| 1 | 15 | | string entityId = "1"; |
| 1 | 16 | | TestHelpers.CreateSceneEntity(scene, entityId); |
| | 17 | |
|
| 1 | 18 | | Material placeholderLoadingMaterial = Resources.Load<Material>("Materials/AssetLoading"); |
| | 19 | |
|
| 1 | 20 | | yield return null; |
| | 21 | |
|
| 1 | 22 | | Assert.IsTrue(scene.entities[entityId].meshRootGameObject == null, |
| | 23 | | "Since the shape hasn't been updated yet, the child mesh shouldn't exist"); |
| | 24 | |
|
| 1 | 25 | | TestHelpers.CreateAndSetShape(scene, entityId, DCL.Models.CLASS_ID.OBJ_SHAPE, JsonConvert.SerializeObject( |
| | 26 | | new |
| | 27 | | { |
| | 28 | | src = TestAssetsUtils.GetPath() + "/OBJ/teapot.obj" |
| | 29 | | })); |
| | 30 | |
|
| 1 | 31 | | LoadWrapper objShape = LoadableShape.GetLoaderForEntity(scene.entities[entityId]); |
| 3 | 32 | | yield return new WaitUntil(() => objShape.alreadyLoaded); |
| | 33 | |
|
| 1 | 34 | | Assert.IsTrue(scene.entities[entityId].meshRootGameObject != null, |
| | 35 | | "Every entity with a shape should have the mandatory 'Mesh' object as a child"); |
| | 36 | |
|
| 1 | 37 | | var childRenderer = scene.entities[entityId].meshRootGameObject.GetComponentInChildren<MeshRenderer>(); |
| 1 | 38 | | Assert.IsTrue(childRenderer != null, |
| | 39 | | "Since the shape has already been updated, the child renderer should exist"); |
| 1 | 40 | | Assert.AreNotSame(placeholderLoadingMaterial, childRenderer.sharedMaterial, |
| | 41 | | "Since the shape has already been updated, the child renderer found shouldn't have the 'AssetLoading' placeh |
| 1 | 42 | | } |
| | 43 | |
|
| | 44 | | [UnityTest] |
| | 45 | | public IEnumerator PreExistentShapeUpdate() |
| | 46 | | { |
| 1 | 47 | | string entityId = "1"; |
| 1 | 48 | | TestHelpers.CreateSceneEntity(scene, entityId); |
| 1 | 49 | | var entity = scene.entities[entityId]; |
| | 50 | |
|
| 1 | 51 | | Assert.IsTrue(entity.meshRootGameObject == null, "meshGameObject should be null"); |
| | 52 | |
|
| | 53 | | // Set its shape as a BOX |
| 1 | 54 | | var componentId = TestHelpers.CreateAndSetShape(scene, entityId, CLASS_ID.BOX_SHAPE, "{}"); |
| 1 | 55 | | yield return ((scene.GetSharedComponent(componentId)) as IDelayedComponent).routine; |
| | 56 | |
|
| 1 | 57 | | var meshName = entity.meshRootGameObject.GetComponent<MeshFilter>().mesh.name; |
| 1 | 58 | | Assert.AreEqual("DCL Box Instance", meshName); |
| | 59 | |
|
| | 60 | | // Update its shape to a cylinder |
| 1 | 61 | | TestHelpers.CreateAndSetShape(scene, entityId, CLASS_ID.CYLINDER_SHAPE, "{}"); |
| 1 | 62 | | yield return (scene.GetSharedComponent(componentId) as IDelayedComponent).routine; |
| | 63 | |
|
| 1 | 64 | | Assert.IsTrue(entity.meshRootGameObject != null, "meshGameObject should not be null"); |
| | 65 | |
|
| 1 | 66 | | meshName = entity.meshRootGameObject.GetComponent<MeshFilter>().mesh.name; |
| 1 | 67 | | Assert.AreEqual("DCL Cylinder Instance", meshName); |
| 1 | 68 | | Assert.IsTrue(entity.meshRootGameObject.GetComponent<MeshFilter>() != null, |
| | 69 | | "After updating the entity shape to a basic shape, the mesh filter shouldn't be removed from the object"); |
| | 70 | |
|
| 1 | 71 | | Assert.IsTrue(entity.meshesInfo.currentShape != null, "current shape must exist 1"); |
| 1 | 72 | | Assert.IsTrue(entity.meshesInfo.currentShape is CylinderShape, "current shape is BoxShape"); |
| | 73 | |
|
| | 74 | | // Update its shape to a GLTF |
| 1 | 75 | | TestHelpers.CreateAndSetShape(scene, entityId, DCL.Models.CLASS_ID.GLTF_SHAPE, JsonConvert.SerializeObject( |
| | 76 | | new |
| | 77 | | { |
| | 78 | | src = TestAssetsUtils.GetPath() + "/GLB/Lantern/Lantern.glb" |
| | 79 | | })); |
| | 80 | |
|
| 1 | 81 | | LoadWrapper gltfShape = GLTFShape.GetLoaderForEntity(scene.entities[entityId]); |
| 13 | 82 | | yield return new WaitUntil(() => gltfShape.alreadyLoaded); |
| | 83 | |
|
| 1 | 84 | | Assert.IsTrue(entity.meshesInfo.currentShape != null, "current shape must exist 2"); |
| 1 | 85 | | Assert.IsTrue(entity.meshesInfo.currentShape is GLTFShape, "current shape is GLTFShape"); |
| | 86 | |
|
| 1 | 87 | | Assert.IsTrue(entity.meshRootGameObject != null); |
| | 88 | |
|
| 1 | 89 | | Assert.IsTrue(entity.meshRootGameObject.GetComponent<MeshFilter>() == null, |
| | 90 | | "After updating the entity shape to a GLTF shape, the mesh filter should be removed from the object"); |
| 1 | 91 | | Assert.IsTrue( |
| | 92 | | scene.entities[entityId].gameObject.GetComponentInChildren<UnityGLTF.InstantiatedGLTFObject>() != null, |
| | 93 | | "'GLTFScene' child object with 'InstantiatedGLTF' component should exist if the GLTF was loaded correctly"); |
| | 94 | |
|
| | 95 | | // Update its shape to a sphere |
| 1 | 96 | | TestHelpers.CreateAndSetShape(scene, entityId, CLASS_ID.SPHERE_SHAPE, "{}"); |
| 1 | 97 | | yield return (scene.GetSharedComponent(componentId) as IDelayedComponent).routine; |
| | 98 | |
|
| 1 | 99 | | yield return null; |
| | 100 | |
|
| 1 | 101 | | Assert.IsTrue(entity.meshRootGameObject != null); |
| | 102 | |
|
| 1 | 103 | | meshName = entity.meshRootGameObject.GetComponent<MeshFilter>().mesh.name; |
| | 104 | |
|
| 1 | 105 | | Assert.AreEqual("DCL Sphere Instance", meshName); |
| | 106 | |
|
| 1 | 107 | | Assert.IsTrue( |
| | 108 | | scene.entities[entityId].gameObject.GetComponentInChildren<UnityGLTF.InstantiatedGLTFObject>() == null, |
| | 109 | | "'GLTFScene' child object with 'InstantiatedGLTF' component shouldn't exist after the shape is updated to a |
| 1 | 110 | | } |
| | 111 | | } |