0

I have created this SceneKit text by dragging a 3D Text to the scene using Interface Builder.

It was created like this:

enter image description here

The axis is on the lower left. Is there a way to center the axis on that text using interface builder?

Duck
  • 34,902
  • 47
  • 248
  • 470

2 Answers2

4

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
    )
}
rickster
  • 124,678
  • 26
  • 272
  • 326
1

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
)
meow
  • 46
  • 1