ARKit
ARKit copied to clipboard
Pick Multiple object, drag and drop them.
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.
Hi @ignacio-chiazzo, any idea how we can achieve this?
I need this too.
That's something that I plan to tackle soon, but feel free to open a PR if you want to :)
Give a hint please? What functions handles all this?
@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.
Can we not make it without arrays? Can we use hitTest?
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
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.
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.
}
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.
Can we assign current tapped node to current virtualObject variable?
No that I can think of, but I didn't try it.
Can you help me with arrays please? Can you add arrays to the source code? I cannot figure it out.
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.
@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)