【问题标题】:Error: removing the root node of a scene from its scene is not allowed错误:不允许从场景中移除场景的根节点
【发布时间】:2017-08-15 10:48:37
【问题描述】:

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

- (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];

【问题讨论】:

    标签: ios swift runtime-error scenekit


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 2014-09-02
      • 2016-04-22
      • 2015-04-28
      • 2023-03-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-10
      • 1970-01-01
      相关资源
      最近更新 更多