Move Box with line end

Hey everybody,

i am fairly new to babylonjs and currently working on my first project, trying to bring the ngrx store and babylonjs together. As you can prolly imagine there are a lot of questions to be asked … but for now i will stick to this one :wink: :

Lets say i have 2 Boxes. The boxes are connected by a line, that can have numerous points. At the moment the boxes as well as the line are independant meshes. Now if i move one box, i want the corresponding line end to move with my box. What i am roughly thinking about is something like:

  • Click on the box
  • Have something like a MeshManager to find all Meshes that have to move with my box
  • Move the box*
  • update the points array of the line while dragging the box around
  • when drag ends, dispatch an action to my store to update the domain model
  • What would i ideally use to move my Box? The PositionGizmo or a mesh behavior? Are there more behaviors to come in future releases?

But: this feels rather complicated for something that i would consider a fairly common use case. I ve read about the TransformNode but that doesnt seem to help me with my problem since i dont want to move the complete line mesh.

A small and simple Playground using the gizmo to move the box around: https://www.babylonjs-playground.com/#4TMPFR#1

Best regards and thanks in advance!

Your approach is correct and you will need to update the line. This is a pretty common use case in 2d with node editors but a bit less in 3d. There would be a lot of ways to update the line depending on the underlying use case.

You could also have a look at the dragbehavior to move the box: Use Mesh Behaviors (eg. dragging) - Babylon.js Documentation