Swift Scenekit - 居中SCNText - getBoundingBoxMin:Max问题 [英] Swift Scenekit - Centering SCNText - the getBoundingBoxMin:Max issue
问题描述
享受SCNText上的alignmentMode选项。谷歌搜索周围看起来像alignmentMode和containerFrame有问题。我发现的替代方案建议使用获取边界框功能来查找文本大小,然后相应地手动调整。很棒,除了我不能让功能工作。当我试图得到这两个向量时,我得到一个错误:
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'不能转换为'UnsafeMutablePointer< SCNVector3>'
'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)
}
任何建议都非常感谢。
推荐答案
好的,所以我的最终代码解决方案如下:
OK so my final code solution looks like:
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've left in my couple of global variables, but should make sense.
感谢您的帮助。
这篇关于Swift Scenekit - 居中SCNText - getBoundingBoxMin:Max问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!