Reputation: 4089
I am getting an error at the last line of the code.
- (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];
Upvotes: 0
Views: 856
Reputation: 318774
A node can only belong to one scene, much like a view can only have one parent view.
When you call [workingScene.rootNode addChildNode:node];
you are moving node
from its current scene (scene
) to a different scene (workingScene
). But node
is the root node of scene
. You are not allowed to remove the root node of a scene, hence the error.
One solution is to move all of the child nodes of node
to workingScene.rootNode
.
Upvotes: 2