1

I am creating an AR app using ARKit in which I have to place a TV on a wall. As vertical plane detection is not supported in ARKit as of now, I have created a wall using the technique like https://github.com/bjarnel/arkit-occlusion did. Now I have to place a TV on this wall. But when I am placing the TV model on this wall, it's not oriented correctly. I am using the same Euler angles for TV model as of wall. But I am not able to place it correctly.

Code for creating the wall -

class func node(from:SCNVector3,
                to:SCNVector3) -> SCNNode {
    let distance = from.distance(vector: to)


    let wall = SCNPlane(width: CGFloat(distance),
                        height: HEIGHT)

    wall.firstMaterial = wallMaterial()
    let node = SCNNode(geometry: wall)

    // always render before the beachballs
    node.renderingOrder = 10

    // get center point
    node.position = SCNVector3(from.x + (to.x - from.x) * 0.5,
                               from.y + Float(HEIGHT) * 0.5,
                               from.z + (to.z - from.z) * 0.5)

    node.eulerAngles = SCNVector3(0, -atan2(to.x - node.position.x, from.z - node.position.z) - Float.pi * 0.5, 0)
    return node
}

Code for loading the TV model on wall -

let tvScene = SCNScene(named: "art.scnassets/\(name)")
let tvNode = tvScene?.rootNode.childNode(withName: "TV", 
recursively: true)
tvNode?.position = SCNVector3(hitResult.worldTransform.columns.3.x, hitResult.worldTransform.columns.3.y, wall.position.z)
tvNode?.eulerAngles = SCNVector3(-90, wall.eulerAngles.y, 180)
           self.sceneView.scene.rootNode.addChildNode(tvNode!)

Please help me out.

Luca Torella
  • 7,974
  • 4
  • 38
  • 48
Jagveer Singh
  • 584
  • 7
  • 28

1 Answers1

0

I don't know about your angle are correctly calculated or not. But SCNNode requires angles in Radians not in degree

SCNVector3(-90, wall.eulerAngles.y, 180)

Should be

SCNVector3(-.pi / 2, wall.eulerAngles.y, pi)

Hope it is helpful

Prashant Tukadiya
  • 15,838
  • 4
  • 62
  • 98