Search code examples
iosswiftscenekitarkitscnnode

How to scale and position a SCNNode that has a SCNSkinner attached?


Using SceneKit, I'm loading a very simple .dae file consisting of a large cylinder with three associated bones. I want to scale the cylinder down and position it on the ground. Here's the code

public class MyNode: SCNNode {

    public convenience init() {
        self.init()

        let scene = SCNScene(named: "test.dae")

        let cylinder = (scene?.rootNode.childNode(withName: "Cylinder", recursively: true))!

        let scale: Float = 0.1
        cylinder.scale = SCNVector3Make(scale, scale, scale)
        cylinder.position = SCNVector3(0, scale, 0)

        self.addChildNode(cylinder)
    }
}

This doesn't work; the cylinder is still huge when I view it. The only way I can get the code to work is to remove associated SCNSKinner.

cylinder.skinner = nil

Why does this happen and how can I properly scale and position the model, bones and all?


Solution

  • when a geometry is skinned it is driven by its skeleton. Which means that the transform of the skinned node is no longer used, it's the transforms of the bones that are important.

    For this file Armature is the root of the skeleton. If you translate/scale this node instead of Cylinder you'll get what you want.