我在代码的最后一行收到错误。
- (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];
答案 0 :(得分:2)
一个节点只能属于一个场景,就像一个视图只能有一个父视图一样。
当您致电[workingScene.rootNode addChildNode:node];
时,您正在将node
从当前场景(scene
)移动到另一个场景(workingScene
)。但node
是scene
的根节点。您不能删除场景的根节点,因此会出错。
一种解决方案是将node
的所有子节点移动到workingScene.rootNode
。