我有一个SCNView,它呈现我的场景.但是,我希望在保存时在不同的时间点获取几个屏幕截图.我最好的猜测是创建一个SCNRenderer并渲染场景指定不同的时间.我试过了,但是我的图像只是空白,这是我的代码,任何想法?:
-(void)test
{
//First create a new OpenGL context to render to.
NSOpenGLPixelFormatAttribute pixelFormatAttributes[] = {
NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersionLegacy,
NSOpenGLPFADoubleBuffer,
NSOpenGLPFANoRecovery,
NSOpenGLPFAAccelerated,
NSOpenGLPFADepthSize, 24,
0
};
NSOpenGLPixelFormat *pixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:pixelFormatAttributes];
if (pixelFormat == nil)
{
NSLog(@"Error: No appropriate pixel format found");
}
NSOpenGLContext *context = [[NSOpenGLContext alloc] initWithFormat:pixelFormat shareContext:nil];
//set the renderer to render to that context
SCNRenderer *lRenderer = [SCNRenderer rendererWithContext:context.CGLContextObj options: nil];
lRenderer.scene = myscnview.scene;
lRenderer.pointOfView = [myscnview.pointOfView clone];
//render the scene
[lRenderer render];
//I think I …Run Code Online (Sandbox Code Playgroud) 一直在寻找Scenekit上的灯光,虽然我现在可以应用一个灯光节点来点亮我正在寻找一种从物体内发光的方法.
举一个例子,想象一下霓虹灯发光,或者在其他物体上投射光线的灯泡.
任何想法如何实现这一目标?
非常感谢.
我是SceneKit的新手.我正在尝试设置一个纹理,该视图由a上的代码绘制SCNSphere.自定义视图如下所示:
class CustomView : UIView {
override func drawRect(rect: CGRect) {
let ctx = UIGraphicsGetCurrentContext()
let centerX = self.bounds.width / 2
let centerY = self.bounds.height / 2
// fill background
CGContextSetFillColorWithColor(ctx, UIColor.whiteColor().CGColor)
CGContextFillRect(ctx, self.layer.frame)
// draw axises
CGContextSetLineWidth(ctx, 1)
CGContextSetStrokeColorWithColor(ctx, UIColor.blackColor().CGColor)
CGContextMoveToPoint(ctx, 0, centerY)
CGContextAddLineToPoint(ctx, self.bounds.width, centerY)
CGContextStrokePath(ctx)
CGContextMoveToPoint(ctx, centerX, 0)
CGContextAddLineToPoint(ctx, centerX, self.bounds.height)
CGContextStrokePath(ctx)
}
}
Run Code Online (Sandbox Code Playgroud)
该视图如下所示:

要将此视图设置为a的纹理SCNSphere,我将其取出并将layer其设置contents为firstMaterial.
class MyViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let sceneView …Run Code Online (Sandbox Code Playgroud) 
这是showStatistics设置为true 时打开的窗口.我很好奇所有这些符号的含义?到目前为止,我发现每秒帧数需要尽可能高,并且也要保持不变.别人的意思是什么,它们对什么有用?
如何使用场景工具包中的SCNCamera获得鱼眼镜头对视图的失真?
像这种图像的"鞠躬":

//正如里克斯特所指出的那样,这种失真被称为"桶形失真".
从文档中,这是让我对使用相机进行这种失真的可能性感兴趣的部分:
如果您计算自己的投影变换矩阵,则可以使用此方法直接设置它,覆盖从相机的几何属性合成的变换.
不幸的是,我对计算自己的投影变换矩阵的能力和可能性一无所知.我希望通过它可以做到这种失真......但是不知道,因此这个问题.
通过相机的任何其他方式是理想的.太.想要避免后期处理技巧,并在相机旋转并在场景中移动时获得更加"有机"的这种失真外观.
查看任何滑板视频,了解它在现实生活中的表现.
下面的代码捕获了SCNView1的屏幕截图,但它并没有完全正常工作.
SCNView1包含Node1.目标是在没有Node1的情况下捕获SCNView1.
但是,设置afterScreenUpdates为true(或false)没有帮助:屏幕截图包含Node1,无论如何.
有什么问题?
Node1.hidden = true
let screenshot = turnViewToImage(SCNView1, opaque: false, afterUpdates: true)
// Save screenshot to disk
func turnViewToImage(targetView: UIView, opaque: Bool, afterUpdates: Bool = false) -> UIImage {
UIGraphicsBeginImageContextWithOptions(targetView.bounds.size, opaque, UIScreen.mainScreen().scale)
let context = UIGraphicsGetCurrentContext()
CGContextSetInterpolationQuality(context, CGInterpolationQuality.High)
targetView.drawViewHierarchyInRect(targetView.bounds, afterScreenUpdates: afterUpdates)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return image
}
Run Code Online (Sandbox Code Playgroud) 自从我更新到iOS 10后,在使用openGL进行渲染时,我无法再将Sprite Kit场景渲染到场景节点.Metal的工作正常.错误日志:"Failed to create IOSurface image (texture)"
我曾经能做类似的事情:
class ViewController: UIViewController {
@IBOutlet weak var scnView: SCNView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
scnView.showsStatistics = true
scnView.allowsCameraControl = true
let scnScene = SCNScene()
scnView.scene = scnScene
print("scnView renderingAPI is metal", scnView.renderingAPI == SCNRenderingAPI.metal)
print("scnView renderingAPI is opengl", scnView.renderingAPI == SCNRenderingAPI.openGLES2)
// setup SceneKit scene
let cameraNode = SCNNode()
cameraNode.camera = SCNCamera()
cameraNode.position = SCNVector3(x: 0.0, y: …Run Code Online (Sandbox Code Playgroud) 这个区域很难在线记录,很高兴看到一个有效的Swift 3示例,比如一个带有手动SCNvector3s的自定义绘制多维数据集.在Objective-C中有这个但不是Swift.这可能不是一个常见的问题形式,但我知道这会对很多人有所帮助.如果我错过了某个地方,请提及.
文档不是很有帮助
scngeometrysource等
谢谢
如何绘制边框以突出显示SCNNode并向用户指示该节点已被选中?在我的项目中,用户可以放置多个虚拟对象,用户可以随时选择任何对象.选择后,我应该向用户显示高亮显示的3D对象.有没有办法直接实现这个或在SCNNode上绘制边框?
我正在使用场景工具包进行应用程序.并且eveything工作正常,直到iOS 10.
我可以看到3D模型正确但在我将设备更新到iOS 11后,模型的颜色发生了变化.
-(void)applyColor:(SCNNode*)node{
NSArray *materials = node.geometry.materials;
for (SCNMaterial *material in materials) {
material.diffuse.contents = [UIColor purpalColor];
}
}
Run Code Online (Sandbox Code Playgroud)