UniVRM icon indicating copy to clipboard operation
UniVRM copied to clipboard

WebGL UniTask

Open michaellu88 opened this issue 1 year ago • 6 comments

Will u add UniTask Support for WebGL? since WebGL doesn't support multithreading, loading vrm at runtime will freeze the screen for a couple of seconds. tq

michaellu88 avatar Jul 16 '22 08:07 michaellu88

Convert every function to unitask with async await as much as possible. And testing unitask. Delay for few seconds to find out where it freeze, found out that UniJson parsing and deserialise cause most of the freeze. It is possible to remove json file or using more efficient json parsing for runtime import? I have open another issue on this json parsing.

michaellu88 avatar Jul 23 '22 09:07 michaellu88

UPDATE texture.LoadImage(textureInfo.ImageData);

texture LoadImage freeze 1/2 a seconds as well. trying to replace with LoadRawTextureData, althought it doesn't freeze but no colour loaded.

michaellu88 avatar Jul 24 '22 07:07 michaellu88

Thanks for your reporting. We do not support fully non-blocking loads in single-threaded environments such as WebGL.

If we supported UniTask officially, you won't get the results you want. Because WebGL doesn't support multithreading and the method of parsing JSON is implemented by Task.Run at current version. Also blocking the main thread while loading texture is depend on internal UnityEngine's implementation. new Texture2D() always causes blocking the main thread.

Santarh avatar Jul 24 '22 09:07 Santarh

for texture.loadimage maybe we can solve by using native renderingPlugin as mention in https://stackoverflow.com/questions/54749373/hololens-unity-loadimage-freezes-main-thread

or webglmovietexture as mention in https://stackoverflow.com/questions/56123201/unity-plugin-texture-is-immutable

i will try to implement it and reporting back.

michaellu88 avatar Jul 25 '22 00:07 michaellu88

You can implement ITextureDeserializer with native plugin for your target environments and pass to importer constructor. 😉

Santarh avatar Jul 25 '22 05:07 Santarh

UniTask works in WebGL as long as you're not using Task.Run or switching to the threadPool in general.

breadnone avatar Aug 29 '22 03:08 breadnone

Thank me later: https://github.com/VolodymyrBS/WebGLThreadingPatcher This guy did an amazing job with some pretty hardcore IL generation Worked for me, using it for a few months already in a quite large project, .net standard 2.0 and 2.1

xucian avatar Nov 15 '22 10:11 xucian

This issue has been labeled as "stale" due to no response by the reporter within 1 month (and 7 days after last commented by someone). And it will be closed automatically 14 days later if not responded.

github-actions[bot] avatar Oct 17 '23 05:10 github-actions[bot]

This issue has been closed due to no response within 14 days after labeled as "stale", 7 days after last reopened, and 7 days after last commented.

github-actions[bot] avatar Nov 01 '23 05:11 github-actions[bot]