How do I change location of pivot point in SceneKit

风格不统一 提交于 2019-12-02 12:59:59

问题


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

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.


回答1:


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.



来源:https://stackoverflow.com/questions/35673305/how-do-i-change-location-of-pivot-point-in-scenekit

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!