Posts

Showing posts with the label arkit

ARKit Calculate distance from a wall to the camera

ARKit Calculate distance from a wall to the camera I’m developing a project with ARKit. I want to calculate the measure from a wall to the camera and it updates when I move away or I move closer. Now, i have activated that it detects horizontal and vertical surfaces. When I get a surface, I calculate the distance from the camera position and the center of the surface. After I apply the calculus that it gets the distance between 2 points in a 3D space (Euclidean). https://math.stackexchange.com/questions/42640/calculate-distance-in-3d-space Is it correct? Can you help me? class ViewController: UIViewController, ARSCNViewDelegate, ARSessionDelegate { let configuration = ARWorldTrackingConfiguration() override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) configuration.planeDetection = [.horizontal, .vertical] sceneView.session.run(configuration) ...... } func renderer(_ renderer: SCNSceneRenderer, didAdd node: SCNNode, for a...

Using texture in GL shader in ARKit

Using texture in GL shader in ARKit I am trying to use GLKTextureLoader to load a texture into a custom shader written in GLSL. It loads all the vertex and fragment shader bits just fine, but when I try to load a texture it quits. This is how I'm trying to accomplish it: do { guard let CGImage = #imageLiteral(resourceName: "image01").cgImage else { print("no CGImage"); return nil} let texture = try GLKTextureLoader.texture(with: CGImage, options: nil) } catch { print("Texture not loaded", (error)) } it seems to get the CGImage, but fails on the GLKTextureLoader.texture bit. Here is the error: GLKTextureLoader.texture Error Domain=GLKTextureLoaderErrorDomain Code=17 "(null)" UserInfo={GLKTextureLoaderErrorKey=Invalid EAGL context} I've tried logging the GL errors with NSLog("GL Error = %u", glGetError()); but that just gives me GL Error = 0 NSLog("GL Error = %u", glGetError()); GL Error = 0 This is the f...

Changed positions of SCNNodes after unwinding

Changed positions of SCNNodes after unwinding I have an ARKit view (1st view) in which I set nodes to certain positions. Then, I would like to allow the user to go to the 2nd view but also be able to return to the ARKit view by clicking on the return button. The button makes an unwind to the ARKit view but when it does, the positions of the nodes are changed depending on the position of the phone. Can I somehow omit that? I want the nodes in the same places as they were the first time, regardless of the new position of the phone 1 Answer 1 I think your challenge is pretty hard to sort out, indeed when moving to 2nd view the session of the 1rs one is "paused" so a solution should be coded in part in the "viewWillDisappear" function, but due to the strong relation between the device’s motion sensing hardware and the camera there is input from those elements while the session is pau...