code not allowing user to change scn file (Swi

2019-08-17 15:27发布

问题:

The code below places a die multiple times. This is exactly what I want the code to do. However when I change diceCollada.scn to another scn file that is in the assets folder, the code doesn't place the other objects. I don't know why if I import another scn file I can not change the arkit scene. All I want to do is to be able to use this exact code with another scn file that's it.

 func addDice(atLocation location: ARHitTestResult) {

    // Create a new scene

////IF I CHANGE diceCollada.scn to hat.scn THE OBJECT DOES NOT SHOW UP
    let diceScene = SCNScene(named: "art.scnassets/diceCollada.scn")!

    // Create Dice Node for Pos.

    if let diceNode = diceScene.rootNode.childNode(withName: "Dice", recursively: true) {

        // Assign found position to dice
        diceNode.position = SCNVector3(
            location.worldTransform.columns.3.x,
            location.worldTransform.columns.3.y + diceNode.boundingSphere.radius,
            location.worldTransform.columns.3.z
        )

        diceArray.append(diceNode)

        // Set the scene to the view
        sceneView.scene.rootNode.addChildNode(diceNode)

        // Roll Dice
        roll(dice: diceNode)
    }
}