子类化SCNScene和SceneKit编辑器 [英] Subclassing SCNScene and SceneKit Editor
问题描述
我有一个带摄像机设置的SCNScene子类,我想在所有子类中使用。
I have SCNScene subclass with a camera setup, that I want to use in all the subclasses.
let scene01 = TheSubclassScene()
let scene02 = TheSubclassScene(named:"art.scnassets/testScene.scn")!
self.sceneArray.addObject(scene01)
self.sceneArray.addObject(scene02)
我想在运行时更改场景。当我在代码中创建场景但不使用SceneKit编辑器中的场景时,这个工作正常。所以 scene01
正在运作,但是 scene02
不是。在调试器中,我可以看到数组中的两个场景。一个是SCNSceneSubclass类型,但另一个是SCNScene类型。
I want to change the scenes at runtime. This works when I create the scene in code but not with a scene from the SceneKit Editor. So scene01
is working but scene02
isn't. In the debugger I can see the two scenes in the array. One is of type SCNSceneSubclass but the other is of type SCNScene.
有没有办法让这个工作?
Is there any way to get this working?
更新:
这是我的场景子类
Update: This is my scene subclass
class TheSubclassScene: SCNScene
{
let cameraNode = CameraNode()
override init()
{
super.init()
self.rootNode.addChildNode(self.cameraNode)
}
required init?(coder aDecoder: NSCoder)
{
super.init(coder: aDecoder)
}
}
推荐答案
我解决了这个问题。不好但是有效。我实例化一个 SCNScene(名为:art.scnassets / testScene.scn)
然后我实例化一个 TheSubclassScene()
然后克隆场景的rootNode并将其作为子节点添加到子类场景中。
I have a workaround for that problem. Not nice but it works. I instantiate a SCNScene(named: "art.scnassets/testScene.scn")
then I instantiate a TheSubclassScene()
and I clone the rootNode of the scene and add it as a child node to the subclass scene.
let testScene = SCNScene(named:"art.scnassets/testScene.scn")!
let subclassScene = TheSubclassScene()
subclassScene.rootNode.addChildNode(testScene.rootNode.clone())
这篇关于子类化SCNScene和SceneKit编辑器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!