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 draggable groups #3549

Merged
merged 3 commits into from
Sep 2, 2024
Merged

Conversation

voigta
Copy link
Contributor

@voigta voigta commented Aug 20, 2024

This PR allows groups to be draggable. Currently there is no effect when we call group.draggable().

As noted in the documentation of DragControls, this only works if the scene contains a single draggable group. This might lead to some confusion but ignoring the .draggable() call for groups is also confusing...😅 At least setting the transformGroup property to true only affects the behavior for groups and not for other objects.

@falkoschindler falkoschindler self-requested a review August 20, 2024 15:28
Copy link
Contributor

@falkoschindler falkoschindler left a comment

Choose a reason for hiding this comment

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

Thanks for the pull request, @voigta!

The method .draggable() doing nothing on groups is indeed unexpected. So I tested your fix with the following example:

with ui.scene() as scene:
    sphere = scene.sphere().draggable()
    with scene.group().draggable():
        scene.box().move(x=1)
        scene.box().move(x=-1)

But just as mentioned in the documentation, the boxes are only draggable if the sphere isn't draggable. This isn't nice either.

I'll have to think about it. Maybe there's another way to get a more intuitive behavior. The drag handler in JavaScript could try to propagate the movement to the next group in its hierarchy. Otherwise raising a NotImplemented exception in group.draggable might be the better choice.

@falkoschindler
Copy link
Contributor

We see the following options:

  1. Raise a NotImplement exception when calling draggable() on a group as a temporary workaround to avoid confusion.
  2. Raising a RuntimeError when calling draggable() if there are other draggables defined causing a conflict.
  3. Somehow solving the problem, e.g. by dynamically updating the transformGroup on mouse down.

What do you think, @voigta?

@falkoschindler falkoschindler added the question Further information is requested label Sep 2, 2024
@voigta
Copy link
Contributor Author

voigta commented Sep 2, 2024

Thanks for the feedback @falkoschindler.

Solving the problem (i.e. option 3) would definitely be the cleanest solution.

There have been updates of DragControls.js in three.js r162 that allow multiple draggable groups. However, the situation of a draggable group and a draggable object is still not nicely handled in the official repo. Therefore, I've added a small modification that should fix this problem and your example is now working as expected.

@falkoschindler falkoschindler removed the question Further information is requested label Sep 2, 2024
@falkoschindler falkoschindler added this to the 2.0.2 milestone Sep 2, 2024
@falkoschindler falkoschindler added the bug Something isn't working label Sep 2, 2024
Copy link
Contributor

@falkoschindler falkoschindler left a comment

Choose a reason for hiding this comment

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

Thanks for the update, @voigta!

The new solution looks really neat and it behaves just as expected! What a nice incidence that we just upgraded three.js.
I just moved the change into our npm.py script, so that it is automatically applied when updating third-party libraries.

Let's merge! 🚀

@falkoschindler falkoschindler merged commit 79f9d2e into zauberzeug:main Sep 2, 2024
1 check passed
@falkoschindler falkoschindler modified the milestones: 2.0.2, 2.1.0 Sep 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants