0

I have a scene with a child node named wc. I want to add dae/model file on that node.

I was able to add the model/dae via following:

  1. Create parent scene with dae asset from bundle
  2. Add parent scene to the scnView and typecast it to self.view
  3. Get the required node where dae is to be added.
  4. Create a sub-Scene with the required node dae.
  5. Add the sub-scene root node as child of required node of parent scene.
  6. Set the position of child node as that of required node of parent scene.

Following is the snippet:

Code Snippet (in viewDidLoad)

//Create Scene
SCNScene *scene = [SCNScene sceneNamed:@"bathScene.scnassets/peace01.dae"];
SCNView *scnView = (SCNView *)self.view;
scnView.scene = scene;
scnView.allowsCameraControl = YES;
scnView.delegate = self;
scnView.autoenablesDefaultLighting = YES;

//Get the required node where dae is to be added
SCNNode * wcNode = [scnView.scene.rootNode childNodeWithName:@"wc" recursively:YES];
SCNVector3 wcNodeScreenPosition = [scnView projectPoint:wcNode.position];
NSLog(@"wcNode position %f, %f, %f",wcNodeScreenPosition.x, wcNodeScreenPosition.y, wcNodeScreenPosition.z);


//Create sub-Scene
SCNScene* wcScene = [SCNScene sceneNamed:@"bathScene.scnassets/closet.dae"];


//Add the sub-scene root node to the required node of parent scene            
[scnView.scene.rootNode addChildNode:[wcScene.rootNode childNodeWithName:@"ceramic" recursively: false]];
SCNNode * wcDAENode = [wcScene.rootNode childNodeWithName:@"ceramic" recursively: false];
wcDAENode.position = [wcNode position];
SCNVector3 wcDAENodeScreenPosition = [scnView projectPoint:wcDAENode.position];
NSLog(@"DAE position %f, %f, %f",wcDAENodeScreenPosition.x, wcDAENodeScreenPosition.y, wcDAENodeScreenPosition.z);

Log Output

wcNode position 275.306549, 157.163620, 0.956176

DAE position 284.000000, 160.000000, 0.959596

As you can see in the aforementioned log output, the position of required node and its child Dae Node is not the same which renders the model shifted in the scene.

Why are the positions different ?

How do I compensate for the shift ?

Community
  • 1
  • 1
madLokesh
  • 1,860
  • 23
  • 49
  • these nodes come from two different scenes, and none of them is an ancestor of the other in the reconstructed scene. Why would you assume they have the same projected coordinates? – mnuages Jul 25 '16 at 13:37
  • You are right. And even when I was make for the error, the node was being displayed at a fixed position. I was able to solve the problem by creating a SCNNode and adding as child of root node of parent scene. The created scnnode position is same as that of the required node. It works. – madLokesh Jul 25 '16 at 13:39

0 Answers0