ARKit SceneKit 金属集成

ARKit SceneKit Metal Integration

我正在尝试将 ARKit 中对象的创建与 SceneKit 和金属。我可以使用 SeneKit 轻松创建一些对象,而使用 Metal 可以轻松创建其他对象,所以我希望能够同时使用这两种对象。

例如,使用 sceneKit 模板创建 ArKit 项目时,会通过 SceneKit 节点放置 space 飞船作为演示。另一方面,使用 Metal 模板在 ARKit 中创建一个立方体,并使用锚点击。

我怎样才能在同一个项目中同时使用这两者?例如,通过 Metal 创建立方体并使用 SceneKit 创建 spaceship。

另一个例子,有一个 MTKView,我想将其包装为一个对象或将其层叠在 SceneKit 中的一个对象之上,我还有其他在 SceneKit 中使用 PBR 创建的对象,我想要这些在 ARKit 中并排显示。如果可以的话。

也许用这个? : https://developer.apple.com/documentation/scenekit/scnprogram

我认为,如果可能的话,这对不断发展的 ARKit 社区非常有用。

谢谢!

How would I be able to use both in the same project?

你必须选择是用 Metal 还是 SceneKit 来构建你的应用程序,两者都有优缺点。 我认为您可以采用两种方法:

  • 使用 SceneKit。由于 SceneKit 使用 Metal,您可以增强和更改着色器或程序。 Maybe start reading the documentation 关于在 SceneKit 中使用 Metal。也许你可以在 Metal 中做你想做的事,同时尽可能地使用 SceneKits 抽象。

  • 使用金属。如果按照 Apple 的预期在 SceneKit 中使用 Metal,您必须在 Metal 中构建所有内容是不够的。 要加载复杂模型,您可以使用 Apples ModelIO 将 3D 内容加载到金属中。

您应该能够同时在您的场景中使用 SceneKit 和 Metal 内容 - 您可以使用 SCNSceneRendererDelegate 通过访问渲染器和它的 currentRenderCommandEncoder 属性 (https://developer.apple.com/documentation/scenekit/scnscenerendererdelegate):

  • renderer(_:willRenderScene:atTime:) - 用于在 SceneKit 的
  • 之前渲染 Metal 内容
  • renderer(_:didRenderScene:atTime:) - 用于在 SceneKit 的
  • 之后渲染 Metal 内容

或者使用SCNNodeRendererDelegate将节点内容替换为Metal内容(https://developer.apple.com/documentation/scenekit/scnnoderendererdelegate):

  • renderNode(_:renderer:arguments:)