ARKit icon indicating copy to clipboard operation
ARKit copied to clipboard

Pick Multiple object, drag and drop them.

Open ignacio-chiazzo opened this issue 7 years ago • 14 comments

We only can drag and drop the last object selected. We want to allow dragging and dropping to all object placed regardless the time they were added.

ignacio-chiazzo avatar Oct 01 '17 17:10 ignacio-chiazzo

Hi @ignacio-chiazzo, any idea how we can achieve this?

chuongle avatar Nov 03 '17 04:11 chuongle

I need this too.

KMamedoff avatar Nov 29 '17 12:11 KMamedoff

That's something that I plan to tackle soon, but feel free to open a PR if you want to :)

ignacio-chiazzo avatar Nov 29 '17 12:11 ignacio-chiazzo

Give a hint please? What functions handles all this?

KMamedoff avatar Dec 02 '17 02:12 KMamedoff

@KMamedoff We track the last object tapped/selected in the mainViewController. https://github.com/ignacio-chiazzo/ARKit/blob/master/ARKitProject/MainViewController.swift#L76

You need to have the instance of the virtualObjects added in an array that you have to create. Each time you add a virtualObject you have to add it to the array, when you delete one virtualObject you have to delete from the array. Also, when you tap on the screen you should be able to know which object is selected.

ignacio-chiazzo avatar Dec 02 '17 02:12 ignacio-chiazzo

Can we not make it without arrays? Can we use hitTest?

KMamedoff avatar Dec 05 '17 12:12 KMamedoff

You can use hitTest, you would have to compare that the object hit is a VirtualObject like this

https://github.com/ignacio-chiazzo/ARKit/blob/b72301f47c5c7d5a47529f54fcd5def9270366c3/ARKitProject/UI%20Elements/Gesture.swift#L117-L125

ignacio-chiazzo avatar Dec 05 '17 12:12 ignacio-chiazzo

Okay but how can I make that "result" node the selected virtual object? Can you show that to me please? I would really appreciate your help.

KMamedoff avatar Dec 05 '17 12:12 KMamedoff

You have to use an array to track the objects you have placed, like I said above. When the user clicks on the screen you get the result from hitTest and you compare that the result.node is within the array. Like this:

            // virtualObjectPlaced ~ our array of virtual objects
            guard let result = sceneView.hitTest(yourViewTouchLocation, options: hitTestOptions).first 
             else {
                return
            }
            if virtualObjectPlaced.contains(result.node) { 
                # Get the instance and select the object matched as the one that the user selected.
            }

ignacio-chiazzo avatar Dec 05 '17 12:12 ignacio-chiazzo

I get what you saying. I am asking a different approach to the issue. Can we assign current tapped node to current virtualObject variable? That way we would not need arrays.

KMamedoff avatar Dec 05 '17 13:12 KMamedoff

Can we assign current tapped node to current virtualObject variable?

No that I can think of, but I didn't try it.

ignacio-chiazzo avatar Dec 05 '17 13:12 ignacio-chiazzo

Can you help me with arrays please? Can you add arrays to the source code? I cannot figure it out.

KMamedoff avatar Dec 05 '17 13:12 KMamedoff

Thanks for taking a look at this. I'm glad you have the interest to add this feature :). I cannot work on this for at least two weeks, but I can help you as much as I can.

ignacio-chiazzo avatar Dec 05 '17 13:12 ignacio-chiazzo

@KMamedoff I added this PR that will make things easier to tackle this issue. That PR adds a new class Manager which stores the objects that have been placed on the plane. In addition, that PR adds a unique ID to all virtual Objects so as to make easier to detect which object was selected. So now, when the user touched the screen we can detect whether the user selected an object and which object was selected (by comparing the ids)

ignacio-chiazzo avatar Dec 10 '17 20:12 ignacio-chiazzo