Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get width/height of SCNText Geometry

I'm looking for a possibility to calculate the size of an SCNText Geometry. I want to make a row of individual text nodes that have a frame around the text.

Let's say the text has 5pt width. I want a SCNPlane as background with a width of 7pt and the text centred inside. How can I calculate the text size dynamically? I tried different things.. Monospace Fonts, counting bigger and smaller chars etc. But it didn't work out.

Like this:

----------  ----------
|  Text  |  |  Text  |
----------  ----------

Here some sample code:

let textGeometry = SCNText(string: name, extrusionDepth: 0.1)
textGeometry.font = UIFont(name: "Helvetica Neue", size: 1)
let textNode = SCNNode(geometry: textGeometry);

Thanks

like image 472
Nico S. Avatar asked Sep 15 '25 13:09

Nico S.


1 Answers

SCNNode and SCNGeometry (and thus SCNText) conform to the SCNBoundingVolume protocol. The method your are looking for is -getBoundingBoxMin:max:

like image 118
mnuages Avatar answered Sep 18 '25 10:09

mnuages