2017-08-14 45 views
0

我在代碼的最後一行出現錯誤。錯誤:不允許從場景中移除場景的根節點

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

回答

2

節點只能屬於一個場景,很像一個視圖只能有一個父視圖。

當您撥打[workingScene.rootNode addChildNode:node];時,您正在將node從當前場景(scene)移動到另一場景(workingScene)。但nodescene的根節點。您不允許刪除場景的根節點,因此錯誤。

一種解決方案是將node的所有子節點移動到workingScene.rootNode