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

Add Transform-preserving hierarchy update method #5475

Closed
nicopap opened this issue Jul 28, 2022 · 0 comments
Closed

Add Transform-preserving hierarchy update method #5475

nicopap opened this issue Jul 28, 2022 · 0 comments
Labels
A-Hierarchy Parent-child entity hierarchies A-Transform Translations, rotations and scales C-Usability A targeted quality-of-life change that makes Bevy easier to use

Comments

@nicopap
Copy link
Contributor

nicopap commented Jul 28, 2022

What problem does this solve or what need does it fill?

It is currently cumbersome and error-prone to update an entity's parent while keeping its GlobalTransform static.

What solution would you like?

I'd like a method on EntityCommands that allows updating both the parent and the transform of an entity so that they keep their GlobalTransform.

What alternative(s) have you considered?

It is possible to reparent keeping the same transform with the following code:

fn transform_relative_to(point: &GlobalTransform, reference: &GlobalTransform) -> Transform {
    let relative_affine = reference.affine().inverse() * point.affine();
    let (scale, rotation, translation) = relative_affine.to_scale_rotation_translation();
    Transform { translation, rotation, scale }
}

Then, the following to set both the parent and the transform in order to preserve the same GlobalTransform through the hierarchy change.

let new_transform = transform_relative_to(entity_transform, parent_transform);
commands.entity(entity).set_parent(new_parent).insert(new_transform);
@nicopap nicopap added C-Feature A new feature, making something new possible D-Trivial Nice and easy! A great choice to get started with Bevy C-Usability A targeted quality-of-life change that makes Bevy easier to use A-Transform Translations, rotations and scales A-Hierarchy Parent-child entity hierarchies labels Jul 28, 2022
@alice-i-cecile alice-i-cecile removed the C-Feature A new feature, making something new possible label Jul 28, 2022
@nicopap nicopap removed the D-Trivial Nice and easy! A great choice to get started with Bevy label Jul 28, 2022
@nicopap nicopap changed the title Add more commands to deal with hierarchy Add Transform-preserving hierarchy update method Nov 4, 2022
bors bot pushed a commit that referenced this issue Dec 25, 2022
# Objective

It is often necessary  to update an entity's parent while keeping its GlobalTransform static. Currently it is cumbersome and error-prone (two questions in the discord `#help` channel in the past week)

- Part 1 of #5475
- Part 2: #7024.

## Solution

- Add a `reparented_to` method to `GlobalTransform`

---

## Changelog

- Add a `reparented_to` method to `GlobalTransform`
bors bot pushed a commit that referenced this issue Dec 25, 2022
# Objective

It is often necessary  to update an entity's parent while keeping its GlobalTransform static. Currently it is cumbersome and error-prone (two questions in the discord `#help` channel in the past week)

- Part 1 of #5475
- Part 2: #7024.

## Solution

- Add a `reparented_to` method to `GlobalTransform`

---

## Changelog

- Add a `reparented_to` method to `GlobalTransform`
bors bot pushed a commit that referenced this issue Jan 12, 2023
…preserving `GlobalTransform` (#7024)

# Objective

It is often necessary  to update an entity's parent
while keeping its GlobalTransform static. Currently
it is cumbersome and error-prone (two questions in
the discord `#help` channel in the past week)

- Part 2, resolves #5475
- Builds on: #7020.

## Solution

- Added the `BuildChildrenTransformExt` trait, it is part
  of `bevy::prelude` and adds the following methods to `EntityCommands`:
  - `set_parent_in_place`: Change the parent of an entity and
    update its `Transform` in order to preserve its `GlobalTransform` after the parent change
  - `remove_parent_in_place`: Remove an entity from a hierarchy,
    while preserving its `GlobalTransform`.

---

## Changelog


- Added the `BuildChildrenTransformExt` trait, it is part
  of `bevy::prelude` and adds the following methods to `EntityCommands`:
  - `set_parent_in_place`: Change the parent of an entity and
    update its `Transform` in order to preserve its `GlobalTransform` after the parent change
  - `remove_parent_in_place`: Remove an entity from a hierarchy,
    while preserving its `GlobalTransform`.

Co-authored-by: Nicola Papale <nicopap@users.noreply.github.com>
@bors bors bot closed this as completed in 689eab6 Jan 12, 2023
alradish pushed a commit to alradish/bevy that referenced this issue Jan 22, 2023
# Objective

It is often necessary  to update an entity's parent while keeping its GlobalTransform static. Currently it is cumbersome and error-prone (two questions in the discord `#help` channel in the past week)

- Part 1 of bevyengine#5475
- Part 2: bevyengine#7024.

## Solution

- Add a `reparented_to` method to `GlobalTransform`

---

## Changelog

- Add a `reparented_to` method to `GlobalTransform`
alradish pushed a commit to alradish/bevy that referenced this issue Jan 22, 2023
…preserving `GlobalTransform` (bevyengine#7024)

# Objective

It is often necessary  to update an entity's parent
while keeping its GlobalTransform static. Currently
it is cumbersome and error-prone (two questions in
the discord `#help` channel in the past week)

- Part 2, resolves bevyengine#5475
- Builds on: bevyengine#7020.

## Solution

- Added the `BuildChildrenTransformExt` trait, it is part
  of `bevy::prelude` and adds the following methods to `EntityCommands`:
  - `set_parent_in_place`: Change the parent of an entity and
    update its `Transform` in order to preserve its `GlobalTransform` after the parent change
  - `remove_parent_in_place`: Remove an entity from a hierarchy,
    while preserving its `GlobalTransform`.

---

## Changelog


- Added the `BuildChildrenTransformExt` trait, it is part
  of `bevy::prelude` and adds the following methods to `EntityCommands`:
  - `set_parent_in_place`: Change the parent of an entity and
    update its `Transform` in order to preserve its `GlobalTransform` after the parent change
  - `remove_parent_in_place`: Remove an entity from a hierarchy,
    while preserving its `GlobalTransform`.

Co-authored-by: Nicola Papale <nicopap@users.noreply.github.com>
ItsDoot pushed a commit to ItsDoot/bevy that referenced this issue Feb 1, 2023
# Objective

It is often necessary  to update an entity's parent while keeping its GlobalTransform static. Currently it is cumbersome and error-prone (two questions in the discord `#help` channel in the past week)

- Part 1 of bevyengine#5475
- Part 2: bevyengine#7024.

## Solution

- Add a `reparented_to` method to `GlobalTransform`

---

## Changelog

- Add a `reparented_to` method to `GlobalTransform`
ItsDoot pushed a commit to ItsDoot/bevy that referenced this issue Feb 1, 2023
…preserving `GlobalTransform` (bevyengine#7024)

# Objective

It is often necessary  to update an entity's parent
while keeping its GlobalTransform static. Currently
it is cumbersome and error-prone (two questions in
the discord `#help` channel in the past week)

- Part 2, resolves bevyengine#5475
- Builds on: bevyengine#7020.

## Solution

- Added the `BuildChildrenTransformExt` trait, it is part
  of `bevy::prelude` and adds the following methods to `EntityCommands`:
  - `set_parent_in_place`: Change the parent of an entity and
    update its `Transform` in order to preserve its `GlobalTransform` after the parent change
  - `remove_parent_in_place`: Remove an entity from a hierarchy,
    while preserving its `GlobalTransform`.

---

## Changelog


- Added the `BuildChildrenTransformExt` trait, it is part
  of `bevy::prelude` and adds the following methods to `EntityCommands`:
  - `set_parent_in_place`: Change the parent of an entity and
    update its `Transform` in order to preserve its `GlobalTransform` after the parent change
  - `remove_parent_in_place`: Remove an entity from a hierarchy,
    while preserving its `GlobalTransform`.

Co-authored-by: Nicola Papale <nicopap@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Hierarchy Parent-child entity hierarchies A-Transform Translations, rotations and scales C-Usability A targeted quality-of-life change that makes Bevy easier to use
Projects
None yet
2 participants