ios - 如何使用 SCNRenderer 将 SceneKit 与现有的 OpenGL 结合起来?

标签 ios opengl-es scenekit glkit

我想使用 SceneKit 的 SCNRenderer 将一些模型绘制到我现有的 GLKit OpenGL ES 3.0 应用程序中,并匹配我现有的 modelViewProjection 转换。当我加载一个 SceneKit 场景并使用 SCNRenderer 渲染它时,SceneKit 相机转换似乎被忽略了,我只得到一个默认的边界框 View 。更一般地说,当然我更愿意提供我自己的矩阵,但我不确定该怎么做。

//
// Called from my glkView(view: GLKView, drawInRect rect: CGRect)
//

// Load the scene
let scene = SCNScene(named: "art.scnassets/model.scn")!

// Create and add regular SceneKit camera to the scene
let cameraNode = SCNNode()
cameraNode.camera = SCNCamera()
cameraNode.position = SCNVector3(x: 0, y: 0, z: 10)
scene.rootNode.addChildNode(cameraNode)

// Render into the current OpenGL context
let renderer = SCNRenderer( context: EAGLContext.currentContext(), options: nil )
renderer.scene = scene
renderer.renderAtTime(0)

我看到 SCN 相机上暴露了一个 projectionTransform,我也尝试过操纵它,但没有结果。我还猜测这只是字面上的投影变换,而不是完整的 modelViewProjection 变换。

// Probably WRONG
cameraNode.camera!.projectionTransform = SCNMatrix4FromGLKMatrix4( modelViewProjectionTransform )

有没有人有以这种方式将 SceneKit 混合到 OpenGL 绘图中的示例?谢谢。

编辑:

Bobelyuk 对示例的引用是正确的,到目前为止已经帮助我解决了一半的问题。事实证明,虽然我添加了摄像头节点,但我未能将摄像头节点设置为“pointOfView”:

scene.pointOfView = cameraNode

该示例似乎展示了如何获取 opengl 矩阵并将其反转以将其设置在相机上,但是到目前为止我还无法将其用于我的代码。我将很快用代码示例再次更新。

最佳答案

http://qiita.com/akira108/items/a743138fca532ee193fe在这里你可以找到如何结合 SCNRendererOpenGLContext

关于ios - 如何使用 SCNRenderer 将 SceneKit 与现有的 OpenGL 结合起来?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41384462/

相关文章:

ios - 构建时没有 module.a 输出

iphone - 防止缩放到一定限度

opengl-es - OpenGL ES 2.x : Bind both `GL_TEXTURE_2D` and `GL_TEXTURE_CUBE_MAP` in the same texture image unit?

ios - ARKIT:使用 PanGesture 移动对象(正确方式)

ios - 设备进入休眠模式时临时部署中的背景 NSURLSession 问题

c# - 如何在 ios xamarin 的文本字段中禁用空格字符

ios - 仅以英文获取 CLGeocoder 值

安卓 OpenGL 截图

ios - 在 3D 中使线条变粗?

ios - 在球体表面 SceneKit 上写文字?