Repository navigation
Add optional WebP support and GLB loader - #828
mostafa1310 wants to merge 1 commit into
Conversation
Adds optional WebP decoding support via the com.netpyoung.webp package. Introduces WebpImageLoader.cs and WebpTextureImportAddon.cs (both guarded by the WEBP_IS_INSTALLED define), updates ImageImport.cs to use the WebP loader when available (or log a package-missing error), and auto-registers the addon in ImportAddonRegistry. Updates glTFast.asmdef to reference unity.webp and add the WEBP_IS_INSTALLED define for the package. Also adds DocExamples/LoadGltfWithWebp.cs — a small runtime example for loading local .glb files.
|
👋 Thanks for opening a pull request! Unfortunately contributions are only accepted on Unity's fork. Please resubmit your changes here instead: Note Unity's fork is structured as a monorepo, so you need to move your changes into the appropriate subfolder ( Thank you! 🙏 |
|
Hi Mostafa, Thanks for bringing this in. I fiddled with WebP before and wasn't aware of unity.webp. An increasing priority to me is clean separation between add-on logic and core glTFast logic. I see room for improvement, but since your add-on is a precedential case we may have to iron out some rough edges first. I'd prefer a solution where the dependency chain is inverted, so that the glTFast add-on can be part of unity.webp itself. At the very least no core code (e.g. One more: I see it supports a variety of platforms. How does it behave if it's run on a non-supported one (Embedded Linux)? WebP is of increasing priority, so thanks again for the effort |
|
Hi Andreas, Thanks for the great feedback and for looking into this. We completely agree with your point about keeping a clean separation between the add-on and the core logic. I will look into restructuring the WebP support exactly as you described, inverting the dependency chain so that the core glTFast code (like GltfImport) doesn't need to be modified at all. My Top priority is to make sure that it run in runtime and it worked after some tweaks and optimizations in term of loading textures. and after that i added it to support Unity glb import too. Regarding your question about Embedded Linux: The unity.webp package relies on Google's libwebp C binaries, which compile to virtually all targets. However, if it happens to run on an unsupported platform, the native C# binding will simply throw a DllNotFoundException. Because our Addon implementation safely wraps the decoding process inside a try/catch block on a background Task, it will cleanly catch the exception, log a graceful error, and glTFast will simply continue loading the rest of the model uninterrupted! so unfortunately i didn't try it on Embedded Linux but i will see my availability if it's possible to try and i will get back to you with the results Thanks again for the guidance, we’ll work on updating the implementation to match this architecture and get back to you! with another pull request and for knowing i made the same pull request on the (https://github.com/Unity-Technologies/com.unity.cloud.gltfast) with just some changes to match the other repo project structure. so should i in the feature make updates on this repo or the unity package repo? |
|
Sounds good. Please continue on Unity's fork. |
|
the problem that it's behind and is on version of the package 6.18 and not 6.19 |
|
It's one commit right before the 6.19 release/branch-off. Even if it says That's the current workflow with arguable pros/cons. I hope that works for you, let me know otherwise. |
Overview
Adds optional, high-performance native support for WebP textures and the
EXT_texture_webpglTF extension.Implementation Details
WebP support is enabled automatically when the user installs the
unity.webp(com.netpyoung.webp) package. If a user attempts to load a WebP model without the package,ImageImportcorrectly logs aLogCode.PackageMissingerror directing them to install it.WebpImageLoader.cshandles decompression on a background thread usingTask.Runbefore creating the texture on the main thread, ensuring heavy WebP assets don't cause frame drops.WebpTextureImportAddonis auto-registered byImportAddonRegistrywhen the WebP dependency is detected via theWEBP_IS_INSTALLEDassembly define.unity.webpmipmap allocation bug by explicitly allocating the base level and leveragingTexture2D.Apply(true)for native GPU mipmap generation.DocExamples/LoadGltfWithWebp.csdemonstrating memory-safe, leak-free runtime loading.Testing
Tested with local and remote .glb files containing WebP textures. Unmanaged
NativeArraymemory leaks handled via properDispose()patterns in the example code.