-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
🧪 Bone attachments #18262
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
base: main
Are you sure you want to change the base?
🧪 Bone attachments #18262
Conversation
…target_ids` to `GltfLoaderSettings`
|
@alice-i-cecile any template on how to make the release note? |
We're kind of in flux right now, but for now, putting a
|
viridia
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good generally. Note to @alice-i-cecile : this PR solves one of the two use cases mentioned in the original issue, so unless we want to split it into two separate tickets, it should not close the issue once merged.
that is why i wrote |
|
@alice-i-cecile given how early this is I think it is best to add |
|
Can someone help me understand why we can't just use BSN overrides for this? BSN should have the ability to say "I want to load scene X, but add my own custom entity as a child of object Y". That's core to the concept of what overrides are. Once we do that, this feature should naturally fall out, no? |
|
@pcwalton for skinned meshes there are other things needed for it to work, not just parenting, I'm preparing another model to actually show that this works for skinned meshes |
|
@alice-i-cecile This PR is important for me as it implements the ability for multiple skins to share a single armature scene. |
|
This needs merge conflict resolution, and reviews by animation experts. I am not one, but I will socialize your PR and try to get opinions :) It also needs an updated release note: we have a nice little folder for them now! |
Well, the solution in this PR is based on GLTF scenes, not BSN. So that feature of BSN isn't going to be applicable, unless we are saying that BSN is going to be the one and only fully-supported scene format going forward. |
|
My two cents as someone who's worked with similar features in Unreal: There's really two parts to this change - adding the option to make the glTF loader calculate The glTF loader changes could be useful for other features. One example is loading a glTF with a skinned mesh but no animations, then binding the mesh to animations loaded from a second glTF. There's even an argument that the loader should do this by default for convenience. I do think the code could be simplified if The second part is binding the joints of one skinned mesh to another mesh's animation player. Note that this is not just a rigid attachment, so as far I can tell it's not doable through simple parent/child relationships or BSN patches - there needs to be logic to find and match up joint entities. There's various other ways to do similar things but with different trade-offs. I think it's fine for this PR to start with one option, even if it might not fit all users. The feature is clunky as it has to wait for one scene to spawn first, and then the other scene has to be spawned and tweaked. I don't think there's a better way to do this within the current Bevy asset/scene pipeline. As the pipeline evolves I'd guess this feature would move into a more robust transform step within the pipeline. So the options as I see them are:
|
|
i'm in favor of doing the |
|
Ok, I'll take a crack at a PR with the |
|
I'd be very happy to see that refactor in 0.18 :) |
## Objective
Add flexibility by refactoring `AnimationTarget` into two separate
components. This will smooth the path for future animation features.
## Background
`bevy_animation` animates entities by assigning them `AnimationTarget`
components:
```rust
struct AnimationTarget {
player: Entity,
id: AnimationTargetId,
}
```
- `player: Entity` links to an entity that contains an `AnimationPlayer`
component. An `AnimationPlayer` plays `AnimationClip` assets.
- `id: AnimationTargetId` identifies which tracks in an `AnimationClip`
apply to the target entity.
When loading a glTF these components are automatically created. They can
also be created manually.
## Problem
The two parts of `AnimationTarget` often go together but sometimes would
be better separated:
1. I might want to calculate the `AnimationTargetId` first, but not link
it up to an `AnimationPlayer` until later (see #18262 for an example).
2. I might want to use `AnimationTargetId` but not use `AnimationPlayer`
- maybe I've got a different component that plays `AnimationClip`s.
In theory `player` could be left as `Entity::PLACEHOLDER`, but that's
messy and will trigger a warning in `animate_targets`.
## Solution
This PR splits `AnimationTarget` into two components:
1. `AnimationTargetId` is just the original struct with a component
derive.
2. `AnimationPlayerTarget` is a new unit struct `(Entity)`.
I'm not convinced `AnimationPlayerTarget` is a good name, but it does
fit the usual source/target naming for entity relationships.
`AnimationPlayerRef` was another candidate.
`AnimationPlayerTarget` could be a relationship target, but there would
be a performance cost from making `AnimationPlayer` a relationship
source. Maybe it's still a good idea, but that's probably best left to
another PR.
### Performance
Profiled on `many_foxes` - difference was negligible.
### Testing
Examples `animated_mesh`, `animated_transform`, `animated_ui`,
`animation_masks`, `eased_motion`, `scene_viewer`.
## Future
If this PR lands then I'll probably file a follow up that adds more
flexibility to the the glTF loader creation of `AnimationTargetId` and
`AnimationPlayer`. This will help #18262 and enable some other features.
|
I've submitted two PRs for the refactor I proposed in my previous comment. |
Objective
Starts work on #17114
Solution
Create a new crate
bevy_bone_attachmentsand implement a extension trait onEntityCommandsto allow attaching a newSceneto anEntity. The command then collects allAnimationTargets of the entity and copies it to the newScene.This is very early and only includes the above method, the new crate can also be included on an existing crate.
Testing
Showcase
Bone attachments allow you to attach a mesh to another, think a character holding a weapon, or customizable clothing.
Experimental: The current state only allows attaching new scenes into models, and requires that the parent entity is already fully loaded (if it is also a scene, after its
SceneInstanceis ready) and have matchingAnimationTargetIds.Screencast_20250312_094221.webm
Use Guide