-
-
Notifications
You must be signed in to change notification settings - Fork 485
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
Multiple cameras #2608
Multiple cameras #2608
Conversation
Hi @fabian0702, thanks for the pull request! |
@falkoschindler The issue you encountered, seems to be from the asyncronous creation of elements in nicegui, which sometimes leads to the creation of the child scene, before the parent is even created. A possible solution would be to initialize the scene and then later replace it when the parent is fully initialized. |
@fabian0702 Have you tried running the demo in isolation? with ui.scene().classes('w-2/3 h-64') as scene:
teapot = 'https://upload.wikimedia.org/wikipedia/commons/9/93/Utah_teapot_(solid).stl'
scene.stl(teapot).scale(0.3)
with ui.row().classes('w-full'):
with ui.scene(parent_scene=scene).classes('w-1/3 h-32') as child_scene_1:
child_scene_1.move_camera(x=1, y=-3, z=5)
with ui.scene(parent_scene=scene).classes('w-1/3 h-32') as child_scene_2:
child_scene_2.move_camera(x=0, y=3, z=3) It still doesn't render the child scenes. 😕 |
@falkoschindler The problem you encountered seems to be from an incompletely initialised app, where calls getElement failed and should now be handled by an additional condition in the wait function. |
Thanks @fabian0702, now it's working. 🙂 I just experimented with the following demo: with ui.scene() as main_scene:
main_scene.sphere()
child_scene = ui.scene(parent_scene=main_scene)
ui.button('Add sphere to main scene', on_click=lambda: main_scene.sphere().move(x=1))
ui.button('Add sphere to child scene', on_click=lambda: child_scene.sphere().move(y=1))
ui.button('Clear main scene', on_click=main_scene.clear)
ui.button('Clear child scene', on_click=child_scene.clear) Caused by the way child and parent scene are connected, the behavior might be a bit unexpected: Even though all spheres are shown in all scenes, in Python they are only added to one of the UI elements. When clearing a scene, only its "own" objects disappear, while the mirrored objects from the other scene remain visible. This is only one quirk I could find, but there might be more. I wonder if there could be a better architecture for implementing different views on the very same 3D scene. What would it take to create a new |
@falkoschindler I see two ways to achieve the desired behaviour, either to couple the objects of all scenes, effectively linking all ui.scenes together, or to implement a new ui.scene_view as you mentioned, an attempt at this can be found here. |
@fabian0702 Sorry for keeping you waiting for two weeks now. Since this is a rather tricky feature which takes some focus to get right, I procrastinated quite a bit. Now I finally found the time to look into the new Would you like to go on and update the PR? Or create a new one from scratch? I would really appreciate either of it! 🙂 |
@falkoschindler Thanks for the feedback, I think creating a new PR would be better considering how many commits are behind this branch. It would also improve readability and overall structure. |
Alright. I'll close this PR and add a link to the new one later. 👍🏻 |
This Pull Request introduces the ability to use multiple cameras in one scene, as discussed in this discord Thread. This would allow to have multiple ui.scene elements which are showing the same scene, but from multiple perspectives at the same time.