Dragging Scnnode in Arkit Using Scenekit

Cant drag ARKit SCNNode?

I agree with @Rickster that the Apple Code provides a much more robust example, however, I have this and it seems to work smoothly (much more so when you are using PlaneDetection (since feature points are much more sporadic):

I don't make use of touchesBegan but simply do the work in touchesMoved instead:

override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {

//1. Get The Current Touch Point
guard let currentTouchPoint = touches.first?.location(in: self.augmentedRealityView),
//2. Get The Next Feature Point Etc
let hitTest = augmentedRealityView.hitTest(currentTouchPoint, types: .existingPlane).first else { return }

//3. Convert To World Coordinates
let worldTransform = hitTest.worldTransform

//4. Set The New Position
let newPosition = SCNVector3(worldTransform.columns.3.x, worldTransform.columns.3.y, worldTransform.columns.3.z)

//5. Apply To The Node
nodeToDrag.simdPosition = float3(newPosition.x, newPosition.y, newPosition.z)

}

I might be going about this completely the wrong way (and if I am I would love to get feedback).

Anyway, I hope it might help... You can see a quick video of it in action here: Dragging SCNNode

Placing, Dragging and Removing SCNNodes in ARKit

The solution for dragging the object was to set the movedObject to the [[[hitResult node] parentNode] parentNode] parentNode] and the drag became smoother.



Related Topics



Leave a reply



Submit