我有一个带有 SceneKit 的 3d 世界,效果很好,可以平移、放大/缩小,但我想在更大的 3d 世界之上创建 3d 世界的迷你 View 。因此,如果用户放大到非常精细的分辨率,他们仍然知道他们在空间中的位置。
大多数示例似乎在 SceneKit VC 之上覆盖了一个不同的 VC,如 SpriteKit,并带有类似 overlaySKScene 的内容。迷你版不会放大/缩小,但会平移、改变照明等,但它不接受手势。这更像是如何将 self 的迷你版本放在 self 之上的递归。
最佳答案
这是我的做法:
您可以简单地在场景中添加另一个相机,然后渲染到 SCNLayer。然后,您可以在场景中使用该层作为 Material ,或将其作为自定义 View 添加到场景之上。
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;
我很确定这不是一个很好的方法,但它对我有用。
关于ios - Recursion::How to create a mini-view of 3d scenekit of self on top of self?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28766697/