Having fun with the alignmentMode option on SCNText. Been googling around and it looks like there is a problem with alignmentMode and containerFrame. The alternatives I've found suggest using the get bounding box function to find the text size and then manually adjust accordingly. Great except I cant get the function to work. When I try to get the two vectors I get an error:
'SCNVector3' is not convertible to 'UnsafeMutablePointer < SCNVector3>'
I get that both on the geometry and the node. example of the code is below
func setCounterValue(counterValue:Int) {
var v1 = SCNVector3(x: 0,y: 0,z: 0)
var v2 = SCNVector3(x: 0,y: 0,z: 0)
_counterValue = counterValue
let newText = SCNText(string: String(format: "%06d", counterValue), extrusionDepth:sDepth)
newText.font = UIFont (name: "Arial", size: 3)
newText.firstMaterial!.diffuse.contents = UIColor.whiteColor()
newText.firstMaterial!.specular.contents = UIColor.whiteColor()
newText.getBoundingBoxMin(v1, max: v2)
_textNode = SCNNode(geometry: newText)
_textNode.getBoundingBoxMin(v1, max: v2)
}
Any suggestions greatly appreciated.
OK so my final code solution looks like:
I've left in my couple of global variables, but should make sense.
Thanks for the help all.
EDIT: Functions with out-pointer arguments suck in Swift, so in Swift 3 Apple replaced this method (and the corresponding setter method) with a property whose type is a tuple:
So you can just write something like:
More generally...
Functions that take an out-parameter of
UnsafeMutablePointer
type in Swift can be called by passing aninout
reference as the parameter. So for the Swift 2 version of this method, or for similar methods elsewhere: