| | 1 | | using DCL; |
| | 2 | | using DCL.Helpers; |
| | 3 | | using System; |
| | 4 | | using System.Collections; |
| | 5 | | using DCL.Controllers; |
| | 6 | | using UnityEngine; |
| | 7 | | using UnityEngine.Networking; |
| | 8 | | using UnityGLTF; |
| | 9 | | using Environment = DCL.Environment; |
| | 10 | |
|
| | 11 | | public class GLTFLoadingTestController : MonoBehaviour |
| | 12 | | { |
| 0 | 13 | | public string dataTrackingURL = "https://tracking.decentraland.org/track"; |
| | 14 | |
|
| | 15 | | GLTFComponent[] gltfRenderers; |
| | 16 | | float loadingStartingTime; |
| | 17 | |
|
| | 18 | | void Start() |
| | 19 | | { |
| | 20 | | // --------- |
| 0 | 21 | | var sceneController = Environment.i.world.sceneController; |
| 0 | 22 | | var scenesToLoad = (Resources.Load("TestJSON/SceneLoadingTest") as TextAsset).text; |
| | 23 | |
|
| 0 | 24 | | sceneController.UnloadAllScenes(); |
| 0 | 25 | | sceneController.LoadParcelScenes(scenesToLoad); |
| | 26 | |
|
| 0 | 27 | | var scene = Environment.i.world.state.loadedScenes["0,0"] as ParcelScene; |
| | 28 | |
|
| | 29 | | // FULL GLB |
| 0 | 30 | | TestHelpers.InstantiateEntityWithShape(scene, "1", DCL.Models.CLASS_ID.GLTF_SHAPE, new Vector3(-2.5f, 1, 0), |
| | 31 | | TestAssetsUtils.GetPath() + "/GLB/Trunk/Trunk.glb"); |
| | 32 | |
|
| | 33 | | // GLB + Separated Textures |
| 0 | 34 | | TestHelpers.InstantiateEntityWithShape(scene, "2", DCL.Models.CLASS_ID.GLTF_SHAPE, new Vector3(0f, 1, 0), |
| | 35 | | TestAssetsUtils.GetPath() + "/GLB/TrunkSeparatedTextures/Trunk.glb"); |
| | 36 | |
|
| | 37 | | // GLTF |
| 0 | 38 | | TestHelpers.InstantiateEntityWithShape(scene, "3", DCL.Models.CLASS_ID.GLTF_SHAPE, new Vector3(2.5f, 1, 0), |
| | 39 | | TestAssetsUtils.GetPath() + "/GLTF/Trunk/Trunk.gltf"); |
| | 40 | | // --------- |
| 0 | 41 | | } |
| | 42 | |
|
| | 43 | | void SendLoadingTimeDataToEndpoint() |
| | 44 | | { |
| 0 | 45 | | GLTFLoadingTestTrackingData data = new GLTFLoadingTestTrackingData(); |
| 0 | 46 | | data.events[0].TestResultInMilliseconds = (Time.time - loadingStartingTime).ToString(); |
| | 47 | |
|
| 0 | 48 | | string parsedJSON = JsonUtility.ToJson(data); |
| | 49 | |
|
| 0 | 50 | | StartCoroutine(PostRequest(dataTrackingURL, parsedJSON)); |
| 0 | 51 | | } |
| | 52 | |
|
| | 53 | | IEnumerator PostRequest(string url, string json) |
| | 54 | | { |
| 0 | 55 | | var uwr = new UnityWebRequest(url, "POST"); |
| 0 | 56 | | byte[] jsonToSend = new System.Text.UTF8Encoding().GetBytes(json); |
| 0 | 57 | | uwr.uploadHandler = (UploadHandler) new UploadHandlerRaw(jsonToSend); |
| 0 | 58 | | uwr.downloadHandler = (DownloadHandler) new DownloadHandlerBuffer(); |
| 0 | 59 | | uwr.SetRequestHeader("Content-Type", "application/json"); |
| | 60 | |
|
| | 61 | | // Send the request then wait here until it returns |
| 0 | 62 | | yield return uwr.SendWebRequest(); |
| | 63 | |
|
| 0 | 64 | | if (uwr.result == UnityWebRequest.Result.ConnectionError) |
| | 65 | | { |
| 0 | 66 | | Debug.Log("Error While Sending: " + uwr.error); |
| 0 | 67 | | } |
| | 68 | | else |
| | 69 | | { |
| 0 | 70 | | Debug.Log("Received: " + uwr.downloadHandler.text); |
| | 71 | | } |
| 0 | 72 | | } |
| | 73 | |
|
| | 74 | | [Serializable] |
| | 75 | | class GLTFLoadingTestTrackingData |
| | 76 | | { |
| 0 | 77 | | public string user = "WorldTeam-Unity"; |
| 0 | 78 | | public TestEvent[] events = new TestEvent[1]; |
| | 79 | |
|
| 0 | 80 | | public GLTFLoadingTestTrackingData() { events[0] = new TestEvent(); } |
| | 81 | |
|
| | 82 | | [Serializable] |
| | 83 | | public class TestEvent |
| | 84 | | { |
| 0 | 85 | | public string TestRun = "GLTF-LoadingTime"; |
| | 86 | | public string TestResultInMilliseconds; |
| 0 | 87 | | public string GLTBFileSize = "9.5MB (Lantern)"; |
| | 88 | | } |
| | 89 | | } |
| | 90 | | } |