Swift Scenekit - SCNText Centering - getBoundingBoxMin: Max Method

Have fun with the alignmentMode parameter in SCNText. There was googling around, and there seems to be a problem with alignmentMode and containerFrame. The alternatives that I found suggest using the border limit function to find the size of the text, and then manually adjust accordingly. Great if I can't get the function to work. When I try to get two vectors, I get an error message:

'SCNVector3' does not convert to 'UnsafeMutablePointer <SCNVector3>

I get this both in geometry and in node. code example 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 that were highly appreciated.

+5
source share
2 answers

OK, so my final code solution is as follows:

 func setCounterValue(counterValue:Int) { var v1 = SCNVector3(x: 0,y: 0,z: 0) var v2 = SCNVector3(x: 0,y: 0,z: 0) _textNode.removeFromParentNode() _counterValue = counterValue let newText = SCNText(string: String(format: "%08d", counterValue), extrusionDepth:sDepth) newText.font = UIFont (name: "Arial", size: 3) newText.firstMaterial!.diffuse.contents = UIColor.whiteColor() newText.firstMaterial!.specular.contents = UIColor.whiteColor() _textNode = SCNNode(geometry: newText) _textNode.getBoundingBoxMin(&v1, max: &v2) let dx:Float = Float(v1.x - v2.x)/2.0 let dy:Float = Float(v1.y - v2.y) _textNode.position = SCNVector3Make(dx, dy, Float(sDepth/2)) node.addChildNode(_textNode) } 

I left global variables in my pairs, but should make sense.

Thanks for the help.

+10
source

EDIT: Functions with external pointer arguments are pulled into Swift, so in Swift 3, Apple replaced this method (and the corresponding setter method) with a property

+10
source

Source: https://habr.com/ru/post/1209658/


All Articles