Hi there - we’re trying to understand how to set up our drag interactions properly. We’ve looked extensively through the documentation and the comments in the interaction code but are still stuck.
We have a model with a node that needs to snap to one of many drag anchors. The drag anchor coordinates are defined by a grasshopper data output, which we translate into drag anchors for a geometry output in the model.
I’ve put together a sandbox that shows a simplified version of what we are trying to accomplish: MultiDrag Points - CodeSandbox
The first issue is that the node snaps back to the original anchor when dragging it. For example, if we drag the node from anchor 1 to anchor 2, clicking it again to drag it to anchor 3 snaps it back to anchor 1 first. What are we doing wrong here?
The second issue is that the node doesn’t easily snap to the anchors provided relative to the camera perspective. The best experience is when the camera looks directly down at the plane. Is there a way we can make the dragging more responsive to snapping to anchors regardless of the camera perspective?
Appreciate your help here!
thank you for that detailed issue description. I can definitely confirm that some things here are not working as expected. I will have a look and get back to you!
I’m currently working on a fix for this issue. The offset is definitely an error on our side. I should have a new version for this in the next days (hopefully tomorrow). Then we can evaluate the issue with the anchors and how that behavior can be improved.
so there were two issues. First, the resetting of the object when dragging for a second time has been resolved with the newest viewer version
The second issue was a misunderstanding of the dragging functionality. For the use case of defining points to drag to, there are
PointConstraints. I adapted your example to create the intended behavior: MultiDrag Points (forked) - CodeSandbox
I added comments with
NOTE TIM to where I changed something.
Michael - this is great! Thank you so much for the fix and the detailed response. I can confirm that this has improved our experience in the right direction.
An additional question: Is there a way to know if the interactive object is not placed on a snap anchor? I realized that in this approach, users could place the object anywhere. Is there a way we can only let the user place the object on the snap points?
glad this example works for you! So there are currently two types of contraints in this example, plane and point constraints. You could remove the plane constraint so that you can only drag the object onto the points, but I think this might not be what you are looking for.
In this extended example I used a different approach. I reset the transformation matrix of the dragged object if it is not on a point constraint. Is this what you were looking for?
Hey @MajorMeerkatThe3rd - sorry for the late reply. Just wanted to thank you for helping solve this issue. It’s working great!
I have a few follow up questions that would help finish our implementation around this type of interactivity.
Is it possible to group multiple shapediver outputs into a single drag object? For example, several distinct meshes that are assigned different materials to move as one object as the user drags.
Is it possible to access the coordinates or snap anchor coordinate the user has dragged geometry to? For example, if there is an array of snap anchors and the user drags the object to anchor #5, can we access that index from the API?
I’m happy to hear that everything works for you now!
Regarding your issues:
- This is theoretically already possible. You can take the nodes of the outputs, add them to a shared parent and apply the interaction to this node. Here is an example.
I completely understand that this is probably not as easy as is could be as you have to do some scene tree management. I will look into improving that. I understand that use case and will get back to you.
- Currently this is not possible, but it is fairly easy to expose that in the drag event. I’ll get back to you.
In general, thank you for your feedback, this is very valuable to us!
regarding your second point, the drag anchor that was used is already exposed in the
DRAG_MOVE event. Does this already solve your problem here?
in our latest release (
2.9.2, release notes) we exposed more properties in the drag events, have a look here.
We also now make it possible to group nodes together. An example of this is here.