简体   繁体   English

SceneKit:更改SceneKit文本的枢轴/轴

[英]SceneKit: Changing the pivot/axis of SceneKit text

I have created this SceneKit text by dragging a 3D Text to the scene using Interface Builder. 我通过使用Interface Builder将3D文本拖到场景中来创建此SceneKit文本。

It was created like this: 它是这样创建的:

在此处输入图片说明

The axis is on the lower left. 轴在左下方。 Is there a way to center the axis on that text using interface builder? 有没有一种方法可以使用界面生成器将轴居中放置在该文本上?

Not in the Scene Editor. 不在场景编辑器中。

In code, you can change a node's pivot to match the center point of its geometry by examining the bounding box. 在代码中,可以通过检查边界框来更改节点的枢轴以使其几何形状的中心点匹配。 For example: 例如:

func centerPivot(for node: SCNNode) {
    var min = SCNVector3Zero
    var max = SCNVector3Zero
    node.getBoundingBoxMin(&min, max: &max)
    node.pivot = SCNMatrix4MakeTranslation(
        min.x + (max.x - min.x)/2,
        min.y + (max.y - min.y)/2,
        min.z + (max.z - min.z)/2
    )
}

Update for swift 4 迅速更新4

let min = node.boundingBox.min
let max = node.boundingBox.max

node.pivot = SCNMatrix4MakeTranslation(
    min.x + (max.x - min.x)/2,
    min.y + (max.y - min.y)/2,
    min.z + (max.z - min.z)/2
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM