How to set text orientation in ARKit?

I am creating a simple application with ARKit, in which I add text to the scene to the knocked position:

@objc func tapped(sender: UITapGestureRecognizer){
    let sceneView = sender.view as! ARSCNView
    let tapLocation = sender.location(in: sceneView)
    let hitTest = sceneView.hitTest(tapLocation, types: .featurePoint)
    if !hitTest.isEmpty{
        self.addTag(tag: "A", hitTestResult: hitTest.first!)
    }
    else{
        print("no match")
    }
}

func addTag(tag: String, hitTestResult: ARHitTestResult){
    let tag = SCNText(string:tag, extrusionDepth: 0.1)
    tag.font = UIFont(name: "Optima", size: 1)
    tag.firstMaterial?.diffuse.contents = UIColor.red

    let tagNode = SCNNode(geometry: tag)

    let transform = hitTestResult.worldTransform
    let thirdColumn = transform.columns.3
    tagNode.position = SCNVector3(thirdColumn.x,thirdColumn.y - tagNode.boundingBox.max.y / 2,thirdColumn.z)
    print("\(thirdColumn.x) \(thirdColumn.y) \(thirdColumn.z)")
    self.sceneView.scene.rootNode.addChildNode(tagNode)
}

This works, but I have a problem with the orientation of the text. When I add it with the original position of the camera, the orientation of the text is in order, I see the text on the front (Example 1). But when I turn the camera left / right and add text by clicking, I see the added text on the side (Example 2).

Example 1:

3-D letter in front

Example 2:

3-D letter from the side

I know that to solve it there must be some simple trick, but as a beginner in this topic I could not find it until now.

+6
source share
2 answers

, , , ( ), ?

node. eulerAngles node , , .

addTag() :

let eulerAngles = self.sceneView.session.currentFrame?.camera.eulerAngles
tagNode.eulerAngles = SCNVector3(eulerAngles.x, eulerAngles.y, eulerAngles.z + .pi / 2)

.pi / 2 , , ARKit , . z.

( , ) .localRotate() node, transform, eulerAngles.

, .

EDIT: Float(1.57) .pi / 2.

+2

, ? SCNBillboardConstraint :

tagNode.constraints = [SCNBillboardConstraint()]
+2

All Articles