I am trying to create an AR app that have a number of SCNText
and SCNPlane
.
And I am trying to place each SCNText
inside the SCNPlane
, but as this figure shows, the text becomes always outside the plane.
My Question is how can I place each SCNText
inside the SCNPlane
?
This is my code section:
func displayMark() {
var str = ["Orange ","Apple ","Banana ","limon", "onion"]
var x : Float = 1
var i = 0
while i<5 {
let text = SCNText(string: str[i], extrusionDepth: 0)
let material = SCNMaterial()
material.diffuse.contents = UIColor.black
text.materials = [material]
let node = SCNNode()
node.position = SCNVector3(0, x/15 , 0)
node.scale = SCNVector3(0.0009, 0.0009, 0.0009)
let planeNode2 = SCNNode(geometry: text)
node.addChildNode(planeNode2)
let minVec = node.boundingBox.min
let maxVec = node.boundingBox.max
let bound = SCNVector3Make(maxVec.x - minVec.x,
maxVec.y - minVec.y,
maxVec.z - minVec.z);
let plane = SCNPlane(width: CGFloat(bound.x),
height: CGFloat(bound.y))
plane.cornerRadius = 5
plane.firstMaterial?.diffuse.contents = UIColor.gray.withAlphaComponent(0.8)
let planeNode = SCNNode(geometry: plane)
node.addChildNode(planeNode)
planeNode.name = "text"
i = i + 1
x = 1 + x
self.sceneView.scene.rootNode.addChildNode(node)
self.sceneView.autoenablesDefaultLighting = true
}
}