| | 1 | | using DCL.Components; |
| | 2 | | using DCL.Configuration; |
| | 3 | | using DCL.Helpers; |
| | 4 | | using DCL.Models; |
| | 5 | | using NUnit.Framework; |
| | 6 | | using System.Collections; |
| | 7 | | using UnityEngine; |
| | 8 | | using UnityEngine.TestTools; |
| | 9 | |
|
| | 10 | | namespace Tests |
| | 11 | | { |
| | 12 | | public class MaterialTransitionControllerTests : IntegrationTestSuite_Legacy |
| | 13 | | { |
| | 14 | | [UnityTest] |
| | 15 | | [Category("Explicit")] |
| | 16 | | [Explicit("Test is too slow")] |
| | 17 | | public IEnumerator MaterialTransitionWithGLTF() |
| | 18 | | { |
| 0 | 19 | | var entity1 = TestHelpers.CreateSceneEntity(scene); |
| | 20 | |
|
| 0 | 21 | | ParcelSettings.VISUAL_LOADING_ENABLED = true; |
| | 22 | |
|
| 0 | 23 | | var prevLoadingType = RendereableAssetLoadHelper.loadingType; |
| 0 | 24 | | RendereableAssetLoadHelper.loadingType = RendereableAssetLoadHelper.LoadingType.GLTF_ONLY; |
| | 25 | |
|
| 0 | 26 | | Shader hologramShader = Shader.Find("DCL/FX/Hologram"); |
| | 27 | |
|
| 0 | 28 | | Assert.IsTrue(hologramShader != null, "Hologram shader == null??"); |
| | 29 | |
|
| 0 | 30 | | IDCLEntity entity = null; |
| | 31 | |
|
| 0 | 32 | | GLTFShape shape = TestHelpers.InstantiateEntityWithShape<GLTFShape, GLTFShape.Model> |
| | 33 | | (scene, |
| | 34 | | DCL.Models.CLASS_ID.GLTF_SHAPE, |
| | 35 | | Vector3.zero, |
| | 36 | | out entity, |
| | 37 | | new GLTFShape.Model() { src = TestAssetsUtils.GetPath() + "/GLB/Lantern/Lantern.glb" }); |
| | 38 | |
|
| 0 | 39 | | LoadWrapper gltfShape = GLTFShape.GetLoaderForEntity(entity); |
| 0 | 40 | | yield return new WaitUntil(() => gltfShape.alreadyLoaded); |
| | 41 | |
|
| 0 | 42 | | float timeout = 0; |
| | 43 | |
|
| 0 | 44 | | while (timeout < 10) |
| | 45 | | { |
| 0 | 46 | | timeout += Time.deltaTime; |
| | 47 | |
|
| 0 | 48 | | if (entity.meshRootGameObject != null) |
| | 49 | | { |
| 0 | 50 | | var c = entity.meshRootGameObject.GetComponentInChildren<MaterialTransitionController>(); |
| | 51 | |
|
| 0 | 52 | | if (c != null && c.placeholder != null) // NOTE(Brian): Wait for it |
| | 53 | | { |
| 0 | 54 | | Assert.IsTrue(c.useHologram, "useHologram must be true"); |
| 0 | 55 | | Assert.IsTrue(entity.meshRootGameObject != null, "meshGameObject is null"); |
| 0 | 56 | | Assert.AreEqual(c.gameObject.transform, c.placeholder.transform.parent, |
| | 57 | | "MaterialTransitionController is not parented correctly"); |
| 0 | 58 | | Assert.IsTrue(c.placeholder.GetComponent<MeshFilter>() != null, |
| | 59 | | "MeshFilter missing from placeholder object"); |
| 0 | 60 | | Assert.IsTrue(c.placeholder.GetComponent<Renderer>() != null, |
| | 61 | | "Renderer missing from placeholder object"); |
| 0 | 62 | | Assert.IsTrue(c.placeholder.GetComponent<Renderer>().sharedMaterial != null, |
| | 63 | | "SharedMaterial missing from placeholder's renderer"); |
| 0 | 64 | | Assert.AreEqual(hologramShader, c.placeholder.GetComponent<Renderer>().sharedMaterial.shader, |
| | 65 | | "Placeholder is not hologram"); |
| | 66 | |
|
| 0 | 67 | | yield return new WaitForSeconds(2f); |
| | 68 | |
|
| 0 | 69 | | Assert.IsTrue(c == null, "MaterialTransitionController should be destroyed by now!"); |
| | 70 | |
|
| 0 | 71 | | break; |
| | 72 | | } |
| 0 | 73 | | } |
| | 74 | |
|
| 0 | 75 | | yield return null; |
| | 76 | | } |
| | 77 | |
|
| 0 | 78 | | Assert.Less(timeout, 10.1f, "Timeout! MaterialTransitionController never appeared?"); |
| | 79 | |
|
| 0 | 80 | | RendereableAssetLoadHelper.loadingType = prevLoadingType; |
| | 81 | |
|
| 0 | 82 | | yield return null; |
| 0 | 83 | | } |
| | 84 | |
|
| | 85 | | [UnityTest] |
| | 86 | | public IEnumerator MaterialTransitionWithParametrizableMeshes() |
| | 87 | | { |
| 1 | 88 | | DCL.Configuration.EnvironmentSettings.DEBUG = true; |
| | 89 | |
|
| 1 | 90 | | var entity1 = TestHelpers.CreateSceneEntity(scene); |
| | 91 | |
|
| 1 | 92 | | ParcelSettings.VISUAL_LOADING_ENABLED = true; |
| | 93 | |
|
| 1 | 94 | | IDCLEntity entity = null; |
| 1 | 95 | | ConeShape shape = TestHelpers.InstantiateEntityWithShape<ConeShape, ConeShape.Model> |
| | 96 | | ( |
| | 97 | | scene, |
| | 98 | | DCL.Models.CLASS_ID.CONE_SHAPE, |
| | 99 | | new Vector3(2, 1, 3), |
| | 100 | | out entity, |
| | 101 | | new ConeShape.Model()); |
| | 102 | |
|
| 1 | 103 | | yield return null; |
| | 104 | |
|
| 1 | 105 | | float timeout = 0f; |
| 1 | 106 | | float maxTime = 20f; |
| 1 | 107 | | while (timeout < maxTime) |
| | 108 | | { |
| 1 | 109 | | timeout += Time.deltaTime; |
| | 110 | |
|
| 1 | 111 | | if (timeout > maxTime) |
| 0 | 112 | | timeout = maxTime; |
| | 113 | |
|
| 1 | 114 | | if (entity.meshRootGameObject != null) |
| | 115 | | { |
| 1 | 116 | | var c = entity.meshRootGameObject.GetComponentInChildren<MaterialTransitionController>(); |
| | 117 | |
|
| 1 | 118 | | if (c != null) // NOTE(Brian): Wait for it |
| | 119 | | { |
| 1 | 120 | | Assert.IsTrue(!c.useHologram, "useHologram must be false"); |
| 1 | 121 | | Assert.IsTrue(entity.meshRootGameObject != null, "meshGameObject is null"); |
| 1 | 122 | | Assert.IsTrue(c.placeholder == null, |
| | 123 | | "placeholder must be null because we're not using holograms with parametric shapes."); |
| | 124 | |
|
| 1 | 125 | | yield return new WaitForSeconds(0.5f); |
| | 126 | |
|
| 1 | 127 | | Assert.IsTrue(c == null, "MaterialTransitionController should be destroyed by now!"); |
| | 128 | |
|
| 1 | 129 | | break; |
| | 130 | | } |
| 0 | 131 | | } |
| | 132 | |
|
| 0 | 133 | | yield return null; |
| | 134 | | } |
| | 135 | |
|
| 1 | 136 | | Assert.Less(timeout, maxTime + 0.1f, "Timeout! MaterialTransitionController never appeared?"); |
| | 137 | |
|
| 1 | 138 | | yield return null; |
| 1 | 139 | | } |
| | 140 | | } |
| | 141 | | } |