#Problem loading a gltf model

27 messages · Page 1 of 1 (latest)

prime ether
#

I am trying to load a glb model, the example one actually the fox. I tried this again and again and someone asked me to post a help topic so here we go.

If i load it with asset_server.load("models/fox.glb#Scene0"); then it works great .

if i load it with asset_server.load("models/fox.glb"); then it does not work!! it will not show up. There is no error and there is no visible model. I was reassured that it SHOULD load in this discord. However it doesnt. why ?

wraith orchid
#

It looks like it does work if you don't specify a scene but it gives you a handle to a Gltf object instead of a handle to a scene and you would have to use that handle to get the Gltf object from Res<Assets<Gltf>> after the asset is loaded and then get the scene from that object. See https://bevy-cheatbook.github.io/3d/gltf.html#gltf-master-asset for an example. Specifying the scene is definitely a lot simpler as you don't have to wait for the asset loaded event.

Specifying the type of the handle might help make sure you aren't trying to load it as a scene or something which would fail:

let handle: Handle<Gltf> = asset_server.load("models/fox.glb")
prime ether
#

Wait.. well why cant we make it easier than this? It shouldnt be this difficult or confusing

#

In ue4 i just plop a gltf in and say load it and render it and it just works

#

Im still confused even w your explanation 🤣

#

A gltf is one scene !

prime ether
#

also that is annoying because typically I can use a handle in my code even if it isnt loaded yet . But with gltf i have to manually poll for it to be loaded ? ...

prime ether
fringe arch
#

I believe the polling thing will get better with Bevy Assets v2, which is coming in 0.12 I think.

FWIR, in Bevy Assets v2 you can queue up actions in response to assets loading (like spawning the gltf)

#

I also think gltf supports multiple scenes, and I'm betting ue4 does support it, you just don't realize it because they load them in as seperate assets (I think). If you always have one scene, then it always looks like one asset

#

Also from one user to another, Bevy is still very in development! Some things are just bad right now (the renderer is basically completely undocumented as far as I can tell, and for non-trivial things, you have to just start calling raw wgpu which is not convenient). but there are projects working on them!

#

If you have a good idea for how to make this process better (without sacrificing critical features, like being able to access the Gltf object), we'd love to hear it!

prime ether
#

Well for example it would be cool to just assume that a gltf only has one scene. To make it flow really easily in that case. And then allow for advanced coding if needing to use one with multiple scenes

#

We shouldnt need to write tons of boilerplate and polling loops just to support a gltf with a single scene. Make the people using multi scene gltfs write the extra cruft only.

#

My plan is to write my game code with all the cruft and polling loops and then present it and figure out a way to make it better w bevy

wraith orchid
#

Why not just add #Scene0 since you want it to assume one scene anyway? Scenes is an array in gltf so if there is only one then it should always be scene 0. I'm not sure why you are avoiding that?

wraith orchid
fringe arch
#

TBH I low-key agree @prime ether. Perhaps the default should be to just load the first scene, and then with something like #gltf or something it could return the actual gltf object? Regardless it seems like it would be very annoying either way if loading the default didn't load ALL scenes - imagine making a gltf with 5 scenes and only one showing up 😅

wraith orchid
#

It does seem like it could be really nice if trying to load it into a Handle<Scene> would just use the first scene and trying to load it into a Handle<Gltf> would give you the full Gltf. I haven't looked at the assets v2 that got merged in main recently, so idk if that might be more possible in the future?

prime ether
#

Hmm yeah thanks ill look into it

chilly raft
#

Any development on this front will probably be irrelevant in the face of Assets V2 arriving soon, but the most ergonomic solution is to keep all the loaders as they are, and just have the bevy ScenePlugin render scenes as normal when a Handle<Scene> is on an entity, and render the first scene in the gltf when a Handle<Gltf> is on an entity. This would probably also warrant a warning when it first renders, to indicate that this is sub-optimal usage

prime ether
#

yes that is what im thinking ! something like that. im going to wait until v0.12 bevy is out and experiment

#

maybe ill fork the sceneplugin and play around with how the handle for gltf is ... handled

#

while i understand it is -possible- for a gltf file to have multiple scenes, i feel like that is a super weird extreme edge case and so it would be cool if the scene plugin by default loaded a gltf in the way 'that it is going to be 99% of the time' while also still allowing devs to load a multi-scene gltf albeit in a more complex and convoluted way [ like how complex it is now to load a single scene gltf with animations lol ]

#

but basically loading a single scene gltf with animations should be super easy and svelte

#

without weird complex configs it should assume that a gltf is a single scene with 0 or many animations.

#

and then after that, im going to work on animations in general -- seems like bevy has a pretty sparse animations system atm . but im going to need additive animations and stuff for this game