glTFast icon indicating copy to clipboard operation
glTFast copied to clipboard

Freeze frame during runtime loading in Android

Open ChocolateRacoon opened this issue 3 months ago • 0 comments

Hello,

Could you please tell me if there is any way to get rid of freeze frames?

As far as I understand, the use of IDeferAgent is intended specifically for loading multiple models and increases the frame rate by queuing. Freeze frames occur even when loading one model.

Files

Model (glb): https://sketchfab.com/3d-models/warcraft-3-alliance-footmanfanmade-201452e568064aedadccfafb668ef6a5

Script

using System.IO;
using System.Threading.Tasks;
using GLTFast;
using UnityEngine;

namespace GLTFLoading
{
    public class GltfLoader : MonoBehaviour
    {
        [SerializeField] private string fileName = "Footman_RIG.glb";
        [SerializeField] [Range(.01f, 5f)] private float frameBudget = 0.1f;
        private GltfImport _gltf;

        async void Start()
        {
            fileName = Path.Combine(Application.persistentDataPath, fileName);
            Debug.Log($"Path for file = {fileName}");
            await LoadGltfBinaryFromMemory(transform);
        }
        
        private async Task<bool> LoadGltfBinaryFromMemory(Transform parent)
        {
            TimeBudgetPerFrameDeferAgent deferAgent = parent.gameObject.AddComponent<TimeBudgetPerFrameDeferAgent>();
            deferAgent.SetFrameBudget(frameBudget);
            GltfImport.SetDefaultDeferAgent(deferAgent);
            ImportSettings importSettings = new()
            {
                AnimationMethod = AnimationMethod.Mecanim,
                AnisotropicFilterLevel = 3,
                GenerateMipMaps = true
            };
            var success = await _gltf.Load(fileName, importSettings); // Frame freeze is here
            if (success)
                return await _gltf.InstantiateMainSceneAsync(parent);
            
            return success;
        }

    }
}

To Reproduce

Steps to reproduce the behavior:

  1. Create URP unity project
  2. Create scene
  3. Add the script (you can see it above) to scene
  4. Build the application
  5. Install the app on the device, download the model and place the model in the Persistence Data Path
  6. Open the app
  7. See frame freeze

Expected behavior

We get a frame freeze

Video

https://github.com/atteneder/glTFast/assets/108283613/d4f69fd1-83c9-4d52-a441-f48767b895af

Additional data

  • glTFast version 6.0.1
  • Unity version 2022.3.16f1
  • URP 14.0.9
  • Platform: Android

Device

  • Meta Quest 3 (OS version SQ3A220605.009.A1), Oculus Quest 2

Optional

As I understand, parameter GenerateMipMaps = true

is very hard for the app.

Setting this parameter to False reduced the peaks (according to the profiler data), but it still doesn't look good. Below I present the profiler data when loading GLTF via gltf fast

GenerateMipMaps = true

image

GenerateMipMaps = false

image

ChocolateRacoon avatar Mar 27 '24 09:03 ChocolateRacoon