I have a SceneKit app with 2
.scn files in the art.scnassets folder. The base
ship.scn that comes with the project, and a new file
orcIdle.scn that I added myself.
When I call this code on this ship, it moves it properly:
self.myScene = SCNScene(named: "art.scnassets/ship.scn")! // Set the scene to the view let ship = (myScene.rootNode.childNode(withName: "ship", recursively: false))! ship.position = SCNVector3(0, 0, -5) self.sceneView.scene = myScene
When I call the same code on my orcIdle file, it places the orc exactly at (0,0,0)
self.myScene = SCNScene(named: "art.scnassets/orcIdle.scn")! // Set the scene to the view let orc = (myScene.rootNode.childNode(withName: "orcIdle", recursively: false))! orc.position = SCNVector3(0, 0, -5) self.sceneView.scene = myScene
here are screenshots of the file node:
This is the default ship file included in the project by Xcode.
This is my orcIdle file.
As you can see, it's the exact same code but 1 moves, and the other doesn't. Also, in the top right corner of the images, i can adjust the Z value there. It works for .ship, but not for .orcIdle.
Is it a scale issue? Any thoughts?
Here's a new screenshot with as much of the scene graph as I can capture.
Usually, you must select a skeleton's top hierarchy (like
root node) to move geometry, since its mesh was bound to skeleton. If model's skeleton is considerably deeper in the hierarchy use
.childNodes[x] subscript syntax to fetch a desired joint.
But a solution based on your
.scn file is the following – create a
topNode object and put
LOD_Group inside it.
So your code should look like this:
let scene = SCNScene(named: "art.scnassets/orcIdle.scn")! orc = scene.rootNode.childNode(withName: "topNode", recursively: true)! orc.position = SCNVector3(0,0,-20)