Update DragControls array of objects

Hi all! I’m currently trying to use DragControls on my project.
I see that you need to pass in an array with the desired to be draggable meshes when you first instance the controls.

My issue is that in my app, the meshes are being added dinamically, so how would I go about adding new draggable objects as the app goes?

Thanks a lot in advance.

Just add the new object to the array. Something like this:

var controls = new DragControls( objects, ...);

// 5 minutes later ... add a new object to the list of draggable objects

objects.push( new_object ); 

Here is a live demo. Click the button to add a new draggable cube:

https://codepen.io/boytchev/full/zYJMgde

image

Off-topic advice

2 Likes