简体   繁体   中英

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.

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

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
)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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