2

I have a 3d world with SceneKit, works great, can pan, zoom in/out but I want to create a mini-view of the 3d world on top of the larger 3d world. So if the user zooms in to a very fine resolution they still know where they are in space.

Most examples seem to overlay a different VC like SpriteKit on top of a SceneKit VC with something like overlaySKScene . The mini-version doesn't zoom in/out but will pan, change lighting etc but it will not accept gestures. This is more like recursion of how to put an mini-version of self on top of self.

2 Answers2

5

Here is how I did it:

You can simply add another camera to the scene, and render to a SCNLayer. Then, you can either use this layer within the scene as a material, or add it as a custom view on top of your scene.

SCNScene *scene2 =[SCNScene scene];

// We duplicate the scene by cloning the root node. 
// I found that you cannot share the scene if you 
// use the layer within it.
[[scene2 rootNode] addChildNode:[root clone]];

// Create a SCNLayer, set the scene and size
SCNLayer *scnlayer = [SCNLayer layer];
scnlayer.scene = scene2;
scnlayer.frame = CGRectMake(0, 0, 600, 800);

// "Layer" should be the name of your second camera
scnlayer.pointOfView = [scene.rootNode childNodeWithName:@"Layer" recursively:YES];

// Make sure it gets updated
scnlayer.playing = YES;



// Make a parent layer with a black background
CALayer *backgroundLayer = [CALayer layer];
backgroundLayer.backgroundColor = CGColorGetConstantColor(kCGColorBlack);
backgroundLayer.frame = CGRectMake(0, 0, 600, 800);

// Add the SCNLayer
[backgroundLayer addSublayer:scnlayer];

// Set the layer as the emissive material of an object
SCNMaterial *material = plane.geometry.firstMaterial;
material.emission.contents = scnlayer;

I'm pretty sure this is not a great way to do it, but it worked for me.

Moustach
  • 2,904
  • 1
  • 13
  • 23
  • Cool! Thanks, I'll give it go. Did you try SCNTechnique? – μολὼν.λαβέ Feb 27 '15 at 16:51
  • I have played a lot with SCNTechnique but haven't dived into multiple point of views yet. I'm pretty sure it has something to do with the `node` property. I'll probably try it out later today! – Moustach Feb 27 '15 at 17:20
2

there are multiple ways to do that.

You can simply add another SCNView on top of the other view. A single SCNScene can be rendered by several views, using different points of view.

You can also use SCNTechnique to create a "mini-view" pass that will re-render your scene with another point of view in a sub-viewport.

In this extract from the SCNTechnique header file you can see that you can provide the name of the wanted pointOfView:

   sequence: ["Pass1", "Pass2", ...],
      passes: {
        "Pass1": {
           outputs: <outputs>
           inputs: <inputs>
           draw: <draw command>
           program: <program name>
           colorStates: <color states>               
           depthStates: <depth states>               
           stencilStates: <stencil states>           
           cullMode: <cull mode>                     
           blendStates: <blend states>               
           viewport: <custom viewport>               
           pointOfView: <node name>                  // Point of view
           samples: <sample count>                   
           excludeCategoryMask: <category bitMask>   
           includeCategoryMask: <category bitMask>   
        },
        "Pass2" : { 
            [...]
        }
      }

So adding a technique to your SCNScene (it conforms to SCNTechniqueSupport) with a DRAW_SCENE pass should work.

mnuages
  • 13,049
  • 2
  • 23
  • 40
  • Apple has zero examples of of this. Do you have any examples using `SCNTechnique `? Would you attach SCNTechnique to the camera node then use viewport? – μολὼν.λαβέ Feb 27 '15 at 15:34
  • I would be interested to know how to change point of view using SCNTechnique as well. I'll post another answer with my workaround. – Moustach Feb 27 '15 at 16:35