Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved glTF extension support #12039

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

MalekiRe
Copy link
Contributor

@MalekiRe MalekiRe commented Feb 22, 2024

by adding the data directly to the nodes.

Objective

Fixes animation support compile bug + extension support

Solution

Adds gltf extension data to the nodes when importing as well as to the scene as a standalone entity.

Also allows you to access a weaker version of the gltf struct from within scenes.

Changelog

Added
GltfExtensions component
WeakGltf component

Migration Guide

Copy link
Contributor

Welcome, new contributor!

Please make sure you've read our contributing guide and we look forward to reviewing your pull request shortly ✨

@alice-i-cecile alice-i-cecile added C-Feature A new feature, making something new possible A-Assets Load files from disk to use for things like images, models, and sounds A-Animation Make things move and change over time labels Feb 22, 2024
Copy link
Member

@alice-i-cecile alice-i-cecile left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this solution much better! Should we revert #11138 as part of this? @CorneliusCornbread: is there anything that would be missing with the simpler design of this PR?

@CorneliusCornbread
Copy link
Contributor

I like this solution much better! Should we revert #11138 as part of this? @CorneliusCornbread: is there anything that would be missing with the simpler design of this PR?

The only thing I could consider 'missing' is that this technically doesn't cover all the extensions a scene can have. But its not really feasible to do that, not without bevy creating its own full representation of gltf internally (or switching to using gltf-rs internally).

To summarize what this PR does, it essentially grabs extension data for just scene information, the catch is you have to deserialize the values again before you can use them but it makes the json data easily accessible via a system. Honestly, having bevy have a full-blown representation of gltf internally for its asset system would solve this problem entirely, but we're avoiding that, at least for now.

@mockersf
Copy link
Member

could you change the PR title to be about gltf, not scenes?

@alice-i-cecile alice-i-cecile changed the title Improved extension support for scenes drastically Improved glTF extension support Feb 22, 2024
@MalekiRe MalekiRe force-pushed the malek/improved_extension_support branch from fcb6092 to c464c17 Compare February 22, 2024 19:31
@MalekiRe MalekiRe requested a review from mockersf February 22, 2024 19:32
world
.spawn(SpatialBundle::INHERITED_IDENTITY)
.with_children(|parent| {
if let Some(extensions) = gltf.extensions() {
parent.spawn(GltfExtensions {
value: serde_json::Value::from(extensions.clone()).to_string(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason why we are putting this into the component as a string and not as the already-parsed serde_json::Value? At least with the Value, you have a structure to work with, instead of needing to deserialize it again.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Value doesn't implement reflect

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Github really needs a 🥲 reaction. Can we reflect ignore it? I think that's more useful on the balance: not having to deserialize it seems better than more functional reflection.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm we could, but I prefer to have it be a string over reflect ignoring the field, if you feel strongly about this I will change it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, for some reason doing reflect ignore causes it to not get stored when you spawn the scene, so we just can't have it

@MalekiRe MalekiRe force-pushed the malek/improved_extension_support branch 2 times, most recently from 36fb22b to c1f65f4 Compare February 22, 2024 23:54
@MalekiRe
Copy link
Contributor Author

Uses a WeakGltf struct now, to store the gltf info other than scenes in the scene.

@tbillington
Copy link
Contributor

tbillington commented Feb 23, 2024

Is this intended to be a temporary solution until there are better ways to author scenes?

It feels really weird to leak details of the original asset format into the ecs world like this.

I don't mean to drive-by after people have already reviewed this, it's just the first time I've seen it.

@MalekiRe
Copy link
Contributor Author

@tbillington there is some very rough plans to make some sort of trait extension based gltf importer extension thing but they are not yet anywhere where they are gonna exist in an upstreamable state for at least the next version, and probably more. At some point having a complete rewrite of the gltf loader to handle this would be better, but that design should be well thought out, given it would be such a breaking change.

@alice-i-cecile
Copy link
Member

alice-i-cecile commented Feb 23, 2024

I don't think this is a clear enough improvement over the existing solution to warrant the additional complexity at this point. I would really like to:

a) have exactly one way of doing this
b) store the parsed JSON rather than just a string

@mockersf
Copy link
Member

very opposed to this: the scene is the wrong level to add everything about the global gltf. if you need informations about the gltf, load the gltf instead of just the scene, then you could add an handle to the parent gltf to the scene however you want, but it's your responsibility to do.

I could understand adding a weak handle to the parent gltf by default, but opposed to anything more than that

@alice-i-cecile alice-i-cecile added the X-Controversial There is active debate or serious implications around merging this PR label Feb 23, 2024
@MalekiRe
Copy link
Contributor Author

MalekiRe commented Feb 23, 2024

I understand the distress here with that. But this means the standard bevy way of doing

commands.spawn(SceneBundle {
   scene: assets.load("my_gltf.gltf#Scene0");
});

Will become a footgun when interacting with any third party gltf extension handling that requires external data.

The above code is fine, until the point that you want to, for example load physics scenes, in which case, with the weak handle you have to do

commands.spawn((SceneBundle {
   scene: assets.load("my_gltf.gltf#Scene0");
}, assets.load("my_gltf.gltf")));

This is a tradeoff I'm willing to make here, and then have a weak handle to the gLTF in the scene, however it def makes spawning scenes have different behavior.

Before with spawning a scene from a gLTF it was assumed that everything you needed for the scene was in the

struct Scene {
    world: World
}

Now this is no longer the case, whenever spawning a scene bundle, if you want extension support, you have to remember to spawn the gltf along side it.

@MalekiRe
Copy link
Contributor Author

If my other PR #12077 get's merged then I will revert this one back to it's simple state of just putting extension data in nodes, and one for top level.

@mockersf
Copy link
Member

mockersf commented Feb 24, 2024

Will become a footgun when interacting with any third party gltf extension handling that requires external data.

This seems to be a badly designed gltf extension then? Why do they put data needed for the scene outside of the scene? gltfs can have multiple scenes, how that would work? It is possible to keep the extension data at the scene level in the gltf spec.

@MalekiRe MalekiRe force-pushed the malek/improved_extension_support branch from a52153f to 130f16b Compare February 28, 2024 08:34
@MalekiRe
Copy link
Contributor Author

The issue here is not the design of the gltf extension, the issue here is that in order to access nodes, materials, or anything else by index ( which is the way you need to access them in gltf, accessing them by name is fraught and not recommended, and extensions thus do not do that ) you need to actually have the data. This is what the original weak gltf solved by re-cloning the vecs of nodes and materials and such into each scene.

Having the functionality to reference the parent gltf is more important than resolving any footguns though, so in order to push this PR forward I have reverted to the old weak handle method, which means you must spawn in a gltf along side the scene, but it works.

@MalekiRe MalekiRe force-pushed the malek/improved_extension_support branch from 90697ea to 3492e81 Compare February 29, 2024 01:06
@alice-i-cecile
Copy link
Member

Before I can approve this, I need:

  1. A clear explanation of how this relates to GLTF extension support #11138: what are the differences, why might users use one vs the other and why should we keep both?
  2. An example demonstrating how end users can take advantage of this, that answers the questions above and can be quickly validated to ensure we didn't break anything.
  3. A better PR description, clearly laying out the key facts and usage patterns.

@janhohenheim janhohenheim added the S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged label Jun 25, 2024
@alice-i-cecile alice-i-cecile added A-glTF Related to the glTF 3D scene/model format and removed A-Assets Load files from disk to use for things like images, models, and sounds labels Sep 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Animation Make things move and change over time A-glTF Related to the glTF 3D scene/model format C-Feature A new feature, making something new possible S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged X-Controversial There is active debate or serious implications around merging this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants