| | 1 | | using DCL; |
| | 2 | | using DCL.Helpers; |
| | 3 | | using System.Collections; |
| | 4 | | using DCL.Controllers; |
| | 5 | | using UnityEngine; |
| | 6 | |
|
| | 7 | | public class VisualTestController : MonoBehaviour |
| | 8 | | { |
| 12 | 9 | | public static VisualTestController i { get; private set; } |
| | 10 | | public new Camera camera; |
| | 11 | | public bool takeSnapshots = false; |
| | 12 | | public bool snapshotsAreBaseline = false; |
| 6 | 13 | | public bool instantiateSceneObjects = true; |
| | 14 | |
|
| 12 | 15 | | private void Awake() { i = this; } |
| | 16 | |
|
| | 17 | | IEnumerator Start() |
| | 18 | | { |
| 6 | 19 | | if (instantiateSceneObjects) |
| | 20 | | { |
| 0 | 21 | | yield return InstantiateTestedObjects(); |
| | 22 | | } |
| | 23 | |
|
| 6 | 24 | | if (takeSnapshots) |
| | 25 | | { |
| 0 | 26 | | if (snapshotsAreBaseline) |
| | 27 | | { |
| 0 | 28 | | yield return VisualTestHelpers.GenerateBaselineForTest(TakeSnapshots()); |
| 0 | 29 | | } |
| | 30 | | else |
| | 31 | | { |
| 0 | 32 | | yield return TakeSnapshots(); |
| | 33 | | } |
| | 34 | | } |
| 6 | 35 | | } |
| | 36 | |
|
| | 37 | | IEnumerator InstantiateTestedObjects() |
| | 38 | | { |
| 0 | 39 | | var sceneController = Environment.i.world.sceneController; |
| 0 | 40 | | var scenesToLoad = (Resources.Load("TestJSON/SceneLoadingTest") as TextAsset).text; |
| | 41 | |
|
| 0 | 42 | | sceneController.UnloadAllScenes(); |
| 0 | 43 | | sceneController.LoadParcelScenes(scenesToLoad); |
| | 44 | |
|
| 0 | 45 | | yield return null; |
| | 46 | |
|
| 0 | 47 | | var scene = Environment.i.world.state.loadedScenes["0,0"] as ParcelScene; |
| 0 | 48 | | string textureUrl = TestAssetsUtils.GetPath() + "/Images/atlas.png"; |
| | 49 | |
|
| 0 | 50 | | TestHelpers.InstantiateEntityWithMaterial(scene, "1", new Vector3(-3, 1, 3), |
| | 51 | | new DCL.Components.BasicMaterial.Model |
| | 52 | | { |
| | 53 | | texture = textureUrl, |
| | 54 | | }, "testBasicMaterial"); |
| | 55 | |
|
| 0 | 56 | | TestHelpers.InstantiateEntityWithMaterial(scene, "2", new Vector3(0, 1, 3), new DCL.Components.PBRMaterial.Model |
| | 57 | | { |
| | 58 | | albedoTexture = textureUrl, |
| | 59 | | metallic = 0, |
| | 60 | | roughness = 1, |
| | 61 | | }, "testMaterial1"); |
| | 62 | |
|
| 0 | 63 | | string materialID = "testMaterial2"; |
| 0 | 64 | | TestHelpers.InstantiateEntityWithMaterial(scene, "3", new Vector3(3, 1, 3), new DCL.Components.PBRMaterial.Model |
| | 65 | | { |
| | 66 | | albedoTexture = textureUrl, |
| | 67 | | metallic = 1, |
| | 68 | | roughness = 1, |
| | 69 | | alphaTexture = textureUrl, |
| | 70 | | }, materialID); |
| | 71 | |
|
| | 72 | | // Re-assign last PBR material to new entity |
| 0 | 73 | | TestHelpers.InstantiateEntityWithShape(scene, "4", DCL.Models.CLASS_ID.BOX_SHAPE, new Vector3(6, 1, 3)); |
| | 74 | |
|
| 0 | 75 | | string entityId = "4"; |
| | 76 | |
|
| 0 | 77 | | scene.SharedComponentAttach( |
| | 78 | | entityId, |
| | 79 | | materialID |
| | 80 | | ); |
| | 81 | |
|
| 0 | 82 | | Color color = new Color(1, 0.7f, 0.7f); |
| | 83 | |
|
| | 84 | | // Update material attached to 2 entities, adding albedoColor |
| 0 | 85 | | scene.SharedComponentUpdate(materialID, JsonUtility.ToJson(new DCL.Components.PBRMaterial.Model |
| | 86 | | { |
| | 87 | | albedoTexture = textureUrl, |
| | 88 | | metallic = 1, |
| | 89 | | roughness = 1, |
| | 90 | | alphaTexture = textureUrl, |
| | 91 | | albedoColor = color |
| | 92 | | })); |
| | 93 | |
|
| 0 | 94 | | TestHelpers.InstantiateEntityWithShape(scene, "5", DCL.Models.CLASS_ID.BOX_SHAPE, new Vector3(-6, 1, 6)); |
| 0 | 95 | | TestHelpers.InstantiateEntityWithShape(scene, "6", DCL.Models.CLASS_ID.SPHERE_SHAPE, new Vector3(-3, 1, 6)); |
| 0 | 96 | | TestHelpers.InstantiateEntityWithShape(scene, "7", DCL.Models.CLASS_ID.PLANE_SHAPE, new Vector3(0, 1, 6)); |
| 0 | 97 | | TestHelpers.InstantiateEntityWithShape(scene, "8", DCL.Models.CLASS_ID.CONE_SHAPE, new Vector3(3, 1, 6)); |
| 0 | 98 | | TestHelpers.InstantiateEntityWithShape(scene, "9", DCL.Models.CLASS_ID.CYLINDER_SHAPE, new Vector3(6, 1, 6)); |
| 0 | 99 | | } |
| | 100 | |
|
| | 101 | | IEnumerator TakeSnapshots() |
| | 102 | | { |
| 0 | 103 | | yield return VisualTestHelpers.TakeSnapshotOrTest("snapshot_1.png", new Vector3(10f, 10f, 0f), Vector3.zero); |
| 0 | 104 | | yield return VisualTestHelpers.TakeSnapshotOrTest("snapshot_2.png", new Vector3(0f, 10f, 0f), Vector3.zero); |
| 0 | 105 | | yield return VisualTestHelpers.TakeSnapshotOrTest("snapshot_3.png", new Vector3(-10f, 10f, 0f), Vector3.zero); |
| 0 | 106 | | yield return VisualTestHelpers.TakeSnapshotOrTest("snapshot_4.png", new Vector3(0f, 10f, -10f), Vector3.zero); |
| 0 | 107 | | } |
| | 108 | | } |