Setting up the Orientation of 3D Text in Arkit application

I basically have two 3D Points. Let us assume that the coordinates of the two points are:

 

 

`(x: 1, y: 1, z: 1)` and `(x: 2, y: 2, z: 2)`.

 

 

Basically, I have three lines:

 

 

Line1: directly joins point 1 and point 2. So, end points of this line are:

 

`(x: 1, y: 1, z: 1)` and `(x: 2, y: 2, z: 2)`.

 

 

Line2: This is basically horizontal component. So,end points of this line are:

 

 

`(x: 1, y: 1, z: 1)` and `(x: 2, y: 2, z: 1)`.

 

 

 

 

Line3: This is basically vertical component. So,end points of this line are:

 

 

`(x: 1, y: 1, z: 1)` and `(x: 1, y: 1, z: 2)`.

 

 

Now, I am trying to add a 3D Text. I want to display my text exactly above my line. Since, I have three lines, I will display three texts. So, I would like to know the coordinates of the text (for all the three different lines such that they don’t overlap) and also the orientation to be set for the texts (such that they are properly visible always to the user, even if he rotates the mobile etc).

 

 

Creating text is as follows:

 

 

    func AddText(pos1: SCNVector3?, pos2: SCNVector3?) {

 

 

        var txtNode = SCNNode()

        let d = self.distanceBetweenPoints(A: pos1!, B: pos2!)

          

        let distanceString = String(format: “%.2f”, d)

        let txtGeometry = SCNText(string: distanceString, extrusionDepth: 1.0)

          

        txtGeometry.firstMaterial?.diffuse.contents = UIColor.red

          

        txtGeometry.alignmentMode  = kCAAlignmentCenter

        txtGeometry.truncationMode = kCATruncationMiddle

          

        txtNode.removeFromParentNode()

        txtNode = SCNNode(geometry: txtGeometry)

          

        txtNode.position = SCNVector3(((pos1?.x)! + (pos2?.x)!)/2, ((pos1?.y)! + (pos2?.y)!)/2, ((pos1?.z)! + (pos2?.z)!)/2)

          

        txtNode.scale = SCNVector3(0.005, 0.005, 0.005)

        sceneView.scene.rootNode.addChildNode(txtNode)

    }

 

 

I would be really glad, if some can explain the changes to be made in my above function. So that all the three texts are clearly visible(orientation ) to the user and do not overlap on each other.

Powered by WPeMatico

About

You may also like...

Comments are closed.