How can I remove all nodes from a scenekit scene?

血红的双手。 提交于 2019-12-03 23:19:43
Alan

Try this (assuming you are using Swift):

rootNode.enumerateChildNodes { (node, stop) in
        node.removeFromParentNode()
    }

Works for me.

Alessandro Mattiuzzi

For me worked like below:

sceneView.scene.rootNode.enumerateChildNodes { (node, stop) in
node.removeFromParentNode() }

you can either create a new scene or call -[SCNNode removeFromParentNode] on every child node of the scene's rootNode

Where you need to remove all of your nodes, call this (if your scene isn't self, change it):

for (SCNNode *node in [self children]) {
    [node removeFromParent]
}

Additionally, if you need to remove each node except for some, call this (say, we don't want to remove 3 nodes, and they're named a, b, and c)

for (SCNNode *node in [self children]) {
    if (![node.name isEqualToString:@"a"] && ![node.name isEqualToString:@"b"] && ![node.name isEqualToString:@"c"]) {
        [node removeFromParent]
    }
}

Hope this helps!

the simplest way I found to remove all nodes from a scene is:

  self.removeAllChildren()

This worked well for me in XCode version 7.2

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