Skip to content

Add optional WebP support and GLB loader - #828

Closed
mostafa1310 wants to merge 1 commit into
atteneder:openupmfrom
mostafa1310:feature/webp-support
Closed

mostafa1310 wants to merge 1 commit into
atteneder:openupmfrom
mostafa1310:feature/webp-support

Conversation

@mostafa1310

Copy link
Copy Markdown

Overview

Adds optional, high-performance native support for WebP textures and the EXT_texture_webp glTF 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, ImageImport correctly logs a LogCode.PackageMissing error directing them to install it.

  • Non-blocking Decoder: WebpImageLoader.cs handles decompression on a background thread using Task.Run before creating the texture on the main thread, ensuring heavy WebP assets don't cause frame drops.
  • Addon Architecture: WebpTextureImportAddon is auto-registered by ImportAddonRegistry when the WebP dependency is detected via the WEBP_IS_INSTALLED assembly define.
  • Mipmap Generation: Safely bypasses the unity.webp mipmap allocation bug by explicitly allocating the base level and leveraging Texture2D.Apply(true) for native GPU mipmap generation.
  • Example Code: Added DocExamples/LoadGltfWithWebp.cs demonstrating memory-safe, leak-free runtime loading.

Testing

Tested with local and remote .glb files containing WebP textures. Unmanaged NativeArray memory leaks handled via proper Dispose() patterns in the example code.

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.
@github-actions

Copy link
Copy Markdown
Contributor

👋 Thanks for opening a pull request!

Unfortunately contributions are only accepted on Unity's fork.

Please resubmit your changes here instead:
👉 https://github.com/Unity-Technologies/com.unity.cloud.gltfast

Note

Unity's fork is structured as a monorepo, so you need to move your changes into the appropriate subfolder (Packages/com.unity.cloud.gltfast).

Thank you! 🙏

@CLAassistant

CLAassistant commented Aug 10, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@github-actions github-actions Bot closed this Aug 10, 2026
@atteneder

Copy link
Copy Markdown
Owner

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. GltfImport) has to get modified. If you run into limitations, let's discuss solutions.

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

@mostafa1310

Copy link
Copy Markdown
Author

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?

@atteneder

Copy link
Copy Markdown
Owner

Sounds good. Please continue on Unity's fork.

@mostafa1310

Copy link
Copy Markdown
Author

the problem that it's behind and is on version of the package 6.18 and not 6.19

@atteneder

Copy link
Copy Markdown
Owner

It's one commit right before the 6.19 release/branch-off. Even if it says 6.18.1-pre.1, it's effectively 6.19 without the version bump and release tagged in the changelog.md.

That's the current workflow with arguable pros/cons.

I hope that works for you, let me know otherwise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants