atteneder / glTFast

Efficient glTF 3D import / export package for Unity
Other
1.24k stars 251 forks source link

Unable to import a .glb file on Android #576

Open Creepymulder opened 1 year ago

Creepymulder commented 1 year ago

Describe the bug

Hello there!

I'm trying to import a .glb file using the "Gltf asset" script with all option on default. No custom code.

It's working fine on the editor, but on Android I'm getting the following :

2023/02/27 17:16:43.283 19335 19365 Error Unity NullReferenceException: Object reference not set to an instance of an object. 2023/02/27 17:16:43.283 19335 19365 Error Unity at GLTFast.Materials.BuiltInMaterialGenerator.GenerateDefaultMaterial (System.Boolean pointsSupport) [0x00000] in <00000000000000000000000000000000>:0 2023/02/27 17:16:43.283 19335 19365 Error Unity at GLTFast.Materials.MaterialGenerator.GetDefaultMaterial (System.Boolean pointsSupport) [0x00000] in <00000000000000000000000000000000>:0 2023/02/27 17:16:43.283 19335 19365 Error Unity at GLTFast.GameObjectInstantiator.AddPrimitive (System.UInt32 nodeIndex, System.String meshName, UnityEngine.Mesh mesh, System.Int32[] materialIndices, System.UInt32[] joints, System.Nullable1[T] rootJoint, System.Single[] morphTargetWeights, System.Int32 primitiveNumeration) [0x00000] in <00000000000000000000000000000000>:0 2023/02/27 17:16:43.283 19335 19365 Error Unity at GLTFast.GltfImport+<>cDisplayClass116_0.gPopulateHierarchy|2 (System.UInt32 nodeIndex, System.Nullable`1[T] parentIndex) [0x00000] in <00000000000000000000000000000000>:0 2023/02/27 17:16:43.283 19335 19365 Error Unity at GLTFast.GltfImport+<>cDisplayClass116_0.gIterateNodes|0 (System.UInt32 nodeI `

The .GLB file in question is attached.

Unity 2022.2.2f1 Galaxy Tab S7 with Android 13

haha-63f797eb227eb(2).zip

I've also tried all the manual way to import a .GLB following the documentation, but they all end with the same error message.

Thanks !

amrmohamed25 commented 1 year ago

@Creepymulder Try this #580

ROBYER1 commented 1 year ago

Similar issue here, the normal loading script works on Desktop builds and Editor on Windows 11 and M1 Mac, works fine on device on IOS. On Android if we try to load a file that has a mesh, materials and textures in it, I get

16028 16053 Error CRASH Cause: null pointer dereference

Interestingly, files that contain only animated bones in them with no materials or textures load fine, this includes an animation only file that I am using to retarget an animation to a model already in the scene.

genaray commented 1 year ago

Any update on this? I need to make this work for android for my bachelor thesis... I'm running into the exact same error which throws me back in my timeplan.

ROBYER1 commented 1 year ago

Any update on this? I need to make this work for android for my bachelor thesis... I'm running into the exact same error which throws me back in my timeplan.

I believe this issue is actually this issue I found later on, on Android we could only load glb/gltf that used KTX2 textures. Jpeg/Png don't work. https://github.com/atteneder/glTFast/issues/590

genaray commented 1 year ago

Any update on this? I need to make this work for android for my bachelor thesis... I'm running into the exact same error which throws me back in my timeplan.

I believe this issue is actually this issue I found later on, on Android we could only load glb/gltf that used KTX2 textures. Jpeg/Png don't work. #590

Thanks for the fast answer! Will this be fixed in the near future? Or this even fixable?

Would you recommend Gltfunity for this particular case instead?

amrmohamed25 commented 1 year ago

Any update on this? I need to make this work for android for my bachelor thesis... I'm running into the exact same error which throws me back in my timeplan.

Did you try #580?

genaray commented 1 year ago

Any update on this? I need to make this work for android for my bachelor thesis... I'm running into the exact same error which throws me back in my timeplan.

Did you try #580?

Do you think this could make it work? I can not change the model directly however... Im gonna give it a try, lets see if it works.

amrmohamed25 commented 1 year ago

Any update on this? I need to make this work for android for my bachelor thesis... I'm running into the exact same error which throws me back in my timeplan.

Did you try #580?

Do you think this could make it work? I can not change the model directly however... Im gonna give it a try, lets see if it works.

I guess it will but can tell me what are you expecting? In my case i was expecting to display a glb model that is stored on a server with all textures on it and it worked for all models that i used. Note: i didnt try to use URP

genaray commented 1 year ago

I guess it will but can tell me what are you expecting?

Well, like mentioned in the issue. Theres a glb file stored on a server with textures and materials on it and i wanna load it during runtime on android devices. Its actually a crucial part for my bachelor thesis. Im not using URP either, still on the inbuild renderpipeline. However i receive exact the same issue as described above.

The glb file I'm using (from sketchfab) : https://sketchfab.com/3d-models/coffee-maker-9ccda2fddba846e6ba97eb774b8a09c6

amrmohamed25 commented 1 year ago

I guess it will but can tell me what are you expecting?

Well, like mentioned in the issue. Theres a glb file stored on a server with textures and materials on it and i wanna load it during runtime on android devices. Its actually a crucial part for my bachelor thesis. Im not using URP either, still on the inbuild renderpipeline. However i receive exact the same issue as described above.

The glb file I'm using (from sketchfab) : https://sketchfab.com/3d-models/coffee-maker-9ccda2fddba846e6ba97eb774b8a09c6

I guess it will work with all that mentioned

genaray commented 1 year ago

I guess it will but can tell me what are you expecting?

Well, like mentioned in the issue. Theres a glb file stored on a server with textures and materials on it and i wanna load it during runtime on android devices. Its actually a crucial part for my bachelor thesis. Im not using URP either, still on the inbuild renderpipeline. However i receive exact the same issue as described above. The glb file I'm using (from sketchfab) : https://sketchfab.com/3d-models/coffee-maker-9ccda2fddba846e6ba97eb774b8a09c6

I guess it will work with all that mentioned

It really worked thanks! :) Well it works partially... The model shows up, but its all black for some reason. I downloaded and included the shaders as you said, i put them into Assets/Resources/Shaders (since you haven't mentioned a particular folder). One think i have noticed is that one of the shaders throws errors at me: https://prnt.sc/iVSFuSSR1r28

image

Any clue why its all black? And why that one shader throws those errors?

amrmohamed25 commented 1 year ago

I guess it will but can tell me what are you expecting?

Well, like mentioned in the issue. Theres a glb file stored on a server with textures and materials on it and i wanna load it during runtime on android devices. Its actually a crucial part for my bachelor thesis. Im not using URP either, still on the inbuild renderpipeline. However i receive exact the same issue as described above. The glb file I'm using (from sketchfab) : https://sketchfab.com/3d-models/coffee-maker-9ccda2fddba846e6ba97eb774b8a09c6

I guess it will work with all that mentioned

It really worked thanks! :) Well it works partially... The model shows up, but its all black for some reason. I downloaded and included the shaders as you said, i put them into Assets/Resources/Shaders (since you haven't mentioned a particular folder). One think i have noticed is that one of the shaders throws errors at me: https://prnt.sc/iVSFuSSR1r28

Any clue why its all black? And why that one shader throws those errors?

Did you include the pbrMetallicRoughness in the Always included shaders?

genaray commented 1 year ago

Did you include the pbrMetallicRoughness in the Always included shaders?

Yes i have, like this : (Thats the correct one, right?) image

However that one throws those errors at me: image

Any ideas?

amrmohamed25 commented 1 year ago

Did you include the pbrMetallicRoughness in the Always included shaders?

Yes i have, like this : (Thats the correct one, right?) image

However that one throws those errors at me: image

Any ideas?

It's correct. Can you replace it with the one inside the glTFast itself it is located in glTFast directory / Runtime/shader/Built-in

genaray commented 1 year ago

Can you replace it with the one inside the glTFast itself it is located in glTFast directory / Runtime/shader/Built-in

What exactly do you mean? Like replacing the pbrMetallicRoughness shader? I actually downloaded it from https://github.com/atteneder/glTFast/blob/main/Runtime/Shader/Built-In/glTFPbrMetallicRoughness.shader which should be sufficient. Or do you mean something else?

I think the metallicroughness shader itself is not the problem, its the included that are missing. However i have no idea on how to add them to make that work properly.

amrmohamed25 commented 1 year ago

Can you replace it with the one inside the glTFast itself it is located in glTFast directory / Runtime/shader/Built-in

What exactly do you mean? Like replacing the pbrMetallicRoughness shader? I actually downloaded it from https://github.com/atteneder/glTFast/blob/main/Runtime/Shader/Built-In/glTFPbrMetallicRoughness.shader which should be sufficient. Or do you mean something else?

I think the metallicroughness shader itself is not the problem, its the included that are missing. However i have no idea on how to add them to make that work properly.

It should be sufficient but i dont have any of these errors so you could try to replace the pbrMetallicRoughness.shader that is in the Always Included Shaders with the one that is inside the package directory in your project inside the / Runtime/shader/Built-in If that didnt work you could try including these shaders also but in my case i didnt have to

genaray commented 1 year ago

Can you replace it with the one inside the glTFast itself it is located in glTFast directory / Runtime/shader/Built-in

What exactly do you mean? Like replacing the pbrMetallicRoughness shader? I actually downloaded it from https://github.com/atteneder/glTFast/blob/main/Runtime/Shader/Built-In/glTFPbrMetallicRoughness.shader which should be sufficient. Or do you mean something else? I think the metallicroughness shader itself is not the problem, its the included that are missing. However i have no idea on how to add them to make that work properly.

It should be sufficient but i dont have any of these errors so you could try to replace the pbrMetallicRoughness.shader that is in the Always Included Shaders with the one that is inside the package directory in your project inside the / Runtime/shader/Built-in If that didnt work you could try including these shaders also but in my case i didnt have to

Solved it, now works. I included the whole folder where those missing included were located at and dropped in the shader with meta data again. Thanks!

amrmohamed25 commented 1 year ago

Can you replace it with the one inside the glTFast itself it is located in glTFast directory / Runtime/shader/Built-in

What exactly do you mean? Like replacing the pbrMetallicRoughness shader? I actually downloaded it from https://github.com/atteneder/glTFast/blob/main/Runtime/Shader/Built-In/glTFPbrMetallicRoughness.shader which should be sufficient. Or do you mean something else? I think the metallicroughness shader itself is not the problem, its the included that are missing. However i have no idea on how to add them to make that work properly.

It should be sufficient but i dont have any of these errors so you could try to replace the pbrMetallicRoughness.shader that is in the Always Included Shaders with the one that is inside the package directory in your project inside the / Runtime/shader/Built-in If that didnt work you could try including these shaders also but in my case i didnt have to

Solved it, now works. I included the whole folder where those missing included were located at and dropped in the shader with meta data again. Thanks!

That's great. Happy to hear that. Good luck finishing your bachelor thesis

Creepymulder commented 1 year ago

Sorry I haven't been able to test it out since I created this issue, but I'm glad it's working with this fix, thanks a lot :-).

amrmohamed25 commented 1 year ago

Sorry I haven't been able to test it out since I created this issue, but I'm glad it's working with this fix, thanks a lot :-).

No problem at all. you are welcome :)