zauberzeug / nicegui

Create web-based user interfaces with Python. The nice way.
https://nicegui.io
MIT License
10.16k stars 605 forks source link

Allow ungrouping 3D objects #4018

Closed falkoschindler closed 9 hours ago

falkoschindler commented 1 day ago

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:

falkoschindler commented 1 day ago

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

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.