| | 1 | | using DCL.Helpers; |
| | 2 | | using System.Collections; |
| | 3 | | using UnityEngine; |
| | 4 | | using UnityGLTF; |
| | 5 | |
|
| | 6 | | public class GLTFBenchmark : MonoBehaviour |
| | 7 | | { |
| 0 | 8 | | public string url = "/GLB/TrunkSeparatedTextures/Trunk.glb"; |
| | 9 | |
|
| | 10 | | int count = 0; |
| 0 | 11 | | public int sampleCount = 100; |
| 0 | 12 | | float minTime = float.MaxValue; |
| 0 | 13 | | float maxTime = float.MinValue; |
| | 14 | |
|
| | 15 | | private IEnumerator Start() |
| | 16 | | { |
| 0 | 17 | | GLTFSceneImporter.PROFILING_ENABLED = true; |
| 0 | 18 | | GLTFSceneImporter.budgetPerFrameInMilliseconds = float.MaxValue; |
| 0 | 19 | | GLTFSceneImporter.OnPerformanceFinish += OnPerformanceFinish; |
| 0 | 20 | | yield return new WaitForSeconds(1.0f); |
| 0 | 21 | | RunTest(); |
| 0 | 22 | | } |
| | 23 | |
|
| | 24 | | private void OnPerformanceFinish(float obj) |
| | 25 | | { |
| 0 | 26 | | if (count > 1) |
| | 27 | | { |
| 0 | 28 | | minTime = Mathf.Min(obj, minTime); |
| 0 | 29 | | maxTime = Mathf.Max(obj, maxTime); |
| | 30 | | } |
| 0 | 31 | | } |
| | 32 | |
|
| | 33 | | GameObject lastGameObjectCreated; |
| | 34 | |
|
| | 35 | | void RunTest() |
| | 36 | | { |
| 0 | 37 | | if (count > sampleCount) |
| | 38 | | { |
| 0 | 39 | | Debug.Log($"Url = {url} ... Min time = {minTime * 1000}... Max time = {maxTime * 1000}"); |
| 0 | 40 | | return; |
| | 41 | | } |
| | 42 | |
|
| 0 | 43 | | count++; |
| 0 | 44 | | GameObject gameObject = new GameObject("Test"); |
| 0 | 45 | | lastGameObjectCreated = gameObject; |
| 0 | 46 | | GLTFComponent gltfComponent = gameObject.AddComponent<GLTFComponent>(); |
| 0 | 47 | | gltfComponent.Initialize(DCL.Environment.i.platform.webRequest); |
| 0 | 48 | | GLTFComponent.Settings tmpSettings = new GLTFComponent.Settings() |
| | 49 | | { |
| | 50 | | useVisualFeedback = false, |
| | 51 | | initialVisibility = true, |
| | 52 | | }; |
| | 53 | |
|
| 0 | 54 | | gltfComponent.OnFinishedLoadingAsset += RunTest; |
| 0 | 55 | | gltfComponent.LoadAsset(TestAssetsUtils.GetPath() + url, TestAssetsUtils.GetPath() + url, false, tmpSettings); |
| 0 | 56 | | } |
| | 57 | | } |