atteneder / KtxUnity

Load KTX and Basis Universal textures at runtime
Apache License 2.0
218 stars 42 forks source link

Is loading a ktx2 file from a .glb supported? #29

Closed DerrickBarra closed 3 years ago

DerrickBarra commented 3 years ago

@atteneder Hey bud, our team just added KtxUnity plugin integration to the GLTFUtility plugin (we would use GLTFast, but we need animation support).

However in my testing this morning, KtxUnity has been returning a null reference to the texture on the success delegate. If I load a .ktx2 or .basis texture outside of a .glb there aren't any issues.

The weird thing is that the mimeType is confirmed to be image/ktx2 beforehand.

Now the issue could also be with the optimizer we're passing our models through (Rapid Compact from DGG) and the creation of the ktx2. But can you confirm you've seen this test work? And if so, can you share the test model you used so I can try it out here?

Here's the file I'm testing if you're curious.

Horse GLB GLB - KTX2 GLB - Draco GLB - Draco & KTX2

GLTFImage

atteneder commented 3 years ago

Hi @DerrickBarra ,

Transcoding likely failed.

Last time I checked RapidCompact (4.0.x), they seem to still use an outdated KTX 2.0 draft specification. Not sure, but could be the reason.

I successfully tested with gltfpack 0.15 and suggest you try it as well to compare. If this works, it's likely RapidCompact's fault.

Let me know how it goes.

DerrickBarra commented 3 years ago

@atteneder I just reached out with Rapid Compact to double-check that the CLI we are using has the latest KTX specification. I'm pretty sure they updated to the latest a few months ago but maybe our CLI is out of date. I'll investigate that tool you linked me to which will help us diagnose the problem. Thanks!

DerrickBarra commented 3 years ago

@atteneder So I pinpointed the bug in KtxUnity that is causing the issue.

If I use TextureBase.LoadBytesRoutine(), that causes the texture to be returned null. This is a nice convenience function to have around since we're not always working within a monobehaviour, hopefully, the bug in it can get squashed.

Instead, if I use LoadFromBytes() and pass in a Singleton monobehaviour I created as a dummy, then that works just fine.

In talking to another developer (@daverin over at the GLTFUtility plugin git repo). He mentions that he actually squashed this bug with two different solutions. Check out his reply.

atteneder commented 3 years ago

Fyi: Once I was mentioned in the other PR I got notifications, so no need to double-notify in here.

No bug, but rather wrong use of co-routines.