ios - 错误 : removing the root node of a scene from its scene is not allowed

标签 ios swift runtime-error scenekit

我在代码的最后一行遇到错误。

- (SCNScene *)getWorkingScene {
    SCNScene *workingSceneView  = self.scene;

    if (workingSceneView == nil){
        workingSceneView = [[SCNScene alloc] init];
        workingSceneView.background.contents = self.skyColor;
        self.scene = workingSceneView;
        self.allowsCameraControl = TRUE;
        self.autoenablesDefaultLighting = TRUE;
        self.showsStatistics = TRUE;
        self.backgroundColor = self.skyColor;
        self.delegate = self;
    }

    return workingSceneView;
}

DPoint *point = [coodinate convertCooridnateTo3DPoint];
NSURL *pathToResource = [NSURL urlWithObjectName:objectName ofType:@"dae"];
NSError *error;
SCNScene *scene = [SCNScene sceneWithURL:pathToResource options:nil error:&error];
SCNNode *node = scene.rootNode;
node.position = SCNVector3Make(point.x, point.y, point.z);
node.rotation = SCNVector4Make(0, 1, 0, ((M_PI*point.y)/180.0));
SCNScene *workingScene = self.getWorkingScene;
[workingScene.rootNode addChildNode:node];

最佳答案

一个节点只能属于一个场景,就像一个 View 只能有一个父 View 一样。

当您调用 [workingScene.rootNode addChildNode:node]; 时,您正在将 node 从其当前场景 (scene) 移动到另一个场景场景(workingScene)。但是nodescene的根节点。不允许删除场景的根节点,因此会出现错误。

一种解决方案是将 node 的所有子节点移动到 workingScene.rootNode

关于ios - 错误 : removing the root node of a scene from its scene is not allowed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45682267/

相关文章:

ios - SwiftUI 文本字段 : Keyboard does not show up on tapped

ios - 获取谷歌地图的经纬度中心

ios - 是否可以单击一个 imageView 并打开一个新的 View Controller?

javascript - window.onerror 没有在 Cordova 被解雇

c++ - QSqlDatabasePrivate::addDatabase: 重复的连接名称 'MyConnection' 错误

ios - 我想记住一个 (NSIndexPath *)indexPath 以便以后删除,但是崩溃了

ios - 如何让一组标签在 iOS 中对齐?

ios - 相对于 iOS 中帧的初始引用的电话加速

c++ - 两个几乎相同的 C++ 程序,一个运行良好但另一个出现运行时错误

ios - UIImageView 使用自动布局垂直拉伸(stretch)