Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pick Multiple object, drag and drop them. #7

Open
ignacio-chiazzo opened this issue Oct 1, 2017 · 14 comments
Open

Pick Multiple object, drag and drop them. #7

ignacio-chiazzo opened this issue Oct 1, 2017 · 14 comments

Comments

@ignacio-chiazzo
Copy link
Owner

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.

@chuongle
Copy link

chuongle commented Nov 3, 2017

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

@KMamedoff
Copy link

I need this too.

@ignacio-chiazzo
Copy link
Owner Author

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

@KMamedoff
Copy link

Give a hint please? What functions handles all this?

@ignacio-chiazzo
Copy link
Owner Author

ignacio-chiazzo commented Dec 2, 2017

@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.

@KMamedoff
Copy link

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

@ignacio-chiazzo
Copy link
Owner Author

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

var hitTestOptions = [SCNHitTestOption: Any]()
hitTestOptions[SCNHitTestOption.boundingBoxOnly] = true
let results: [SCNHitTestResult] = sceneView.hitTest(initialTouchLocation, options: hitTestOptions)
for result in results {
if VirtualObject.isNodePartOfVirtualObject(result.node) {
firstTouchWasOnObject = true
break
}
}

@KMamedoff
Copy link

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.

@ignacio-chiazzo
Copy link
Owner Author

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.
            }

@KMamedoff
Copy link

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.

@ignacio-chiazzo
Copy link
Owner Author

Can we assign current tapped node to current virtualObject variable?

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

@KMamedoff
Copy link

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

@ignacio-chiazzo
Copy link
Owner Author

ignacio-chiazzo commented Dec 5, 2017

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
Copy link
Owner Author

ignacio-chiazzo commented Dec 10, 2017

@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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants