Search code examples
swiftarkitscntext

How to Auto-Size a Background for 3D text in ARKit


I am trying to generate a background that automatically conforms to the size of the 3D that my program generates using ARKit. Is their a way to do that using swift/xCode or is there a way to calculate what size the background would have to be?

For example: text1 = "abc"

would only need a small background, where as: text2 = "abcdefg \n 1234567 \n testing123"

would need a bigger background, and the text and background would also vary with the size of the text.


Solution

  • look into boundingBox

    let text = SCNText(string: "123", extrusionDepth: 0.1)
    let textNode = SCNNode(geometry: text)
    
    let (min, max) = textNode.boundingBox
    print("width :",max.x - min.x,"height :",max.y - min.y,"depth :",max.z - min.z)