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

Allow ungrouping 3D objects #4018

Merged
merged 7 commits into from
Nov 22, 2024
Merged

Allow ungrouping 3D objects #4018

merged 7 commits into from
Nov 22, 2024

Conversation

falkoschindler
Copy link
Contributor

@falkoschindler falkoschindler commented Nov 21, 2024

This PR implements feature request #4015 introducing an ungroup method for 3D objects:

import math
import time
from nicegui import ui

with ui.scene() as scene:
    with scene.group() as group:
        a = scene.sphere().move(-2)
        b = scene.sphere().move(0)
        c = scene.sphere().move(2)

ui.timer(0.1, lambda: group.move(y=math.sin(time.time())))
ui.button('Ungroup', on_click=a.ungroup)

ui.run()

Open tasks:

  • better name: "detach"
  • introduce "attach" for symmetry
  • resolve pose so that the object doesn't move visually

@falkoschindler falkoschindler added the enhancement New feature or request label Nov 21, 2024
@falkoschindler falkoschindler added this to the 2.6 milestone Nov 21, 2024
@falkoschindler falkoschindler requested a review from rodja November 21, 2024 06:43
@falkoschindler falkoschindler self-assigned this Nov 21, 2024
@falkoschindler
Copy link
Contributor Author

@rodja Resolving the object's world pose turns out rather tricky.

  • We could compute it on the server. But currently we don't have NumPy as a dependency. And concatenating and inverting 3D motion matrices by hand is pretty challenging.
  • We could compute it on the client using Three.js. This is relatively easy, but requires the server to await the result to update its internal state. This makes attach and detach async methods that can't be called on the auto-index page.

So I wonder if this requirement is worth the effort.

Update: I couldn't resist and implemented the computation for preserving position and rotation. But when extending the concept to preserve scale as well, I noticed that this isn't possible with our current object model. When scaling a box in x direction, attaching it to a rotating group and detaching it again, the resulting transformation contains shear, which can't be represented.

Either we preserve position, rotation but no scale, or we drop this requirement alrogether.

Copy link
Member

@rodja rodja left a comment

Choose a reason for hiding this comment

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

That's great @falkoschindler. Keeping position and orientation is a handy feature. I suggest we simply place note in the documentation that scaling is not preserved.

@falkoschindler falkoschindler merged commit dd2504a into main Nov 22, 2024
8 checks passed
@falkoschindler falkoschindler deleted the ungroup-scene-objects branch November 22, 2024 13:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants