Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I change location of pivot point in SceneKit

I'm trying to move pivot point to the center of an object so it rotates around its center. How can I do this?

enter image description here

I see no option in Xcode editor for doing this. I tried changing the pivot point programmatically:

    // create a new scene
    let scene = SCNScene(named: "art.scnassets/Heart.scn")!

    // change pivot point
    scene.rootNode.pivot = SCNMatrix4MakeTranslation(0.5, 0.5, 0.5)

But it doesn't work either, the object still rotates around its old pivot point.

like image 762
Rafa de King Avatar asked Feb 27 '16 17:02

Rafa de King


1 Answers

The heart is (probably) not the root node of your scene. It is a child of the root node (as are the default camera and any lights). So you could try

// (use the Scene Editor to figure out what the node name really is)
if let heart = scene.rootNode.childNodeWithName("HEART", recursively: true) {
    heart.pivot = SCNMatrix4MakeTranslation(0.5, 0.5, 0.5)
}

As for the Scene Editor...are you sure you're manipulating the heart, and not the entire scene? I've also seen some SO and Devforum traffic that suggests (but doesn't prove) that some parameters set in the Scene Editor aren't honored at runtime.

like image 160
Hal Mueller Avatar answered Oct 17 '22 12:10

Hal Mueller