ARKit学习-4

转载请注明出处
Apple原文地址: https://developer.apple.com/documentation/arkit/building_a_basic_ar_experience

Building a Basic AR Experience 构建基本的 AR 场景

Configure an AR session and use SceneKit or SpriteKit to display AR content.
配置 AR Session,然后使用 SceneKit 或者 SpriteKit 来展示 AR 内容。


Overview

  • When you use the ARSCNView
    or ARSKView
    class, ARKit automatically manages the basic requirements for creating an AR experience: Each view displays a live camera image as its backdrop and renders the 2D or 3D overlay content you provide to create the illusion of that content inhabiting the real world. To use one of these view classes, you configure it for the kind of AR experience you want to create, and choose positions and representations for your overlay content.
  • 如果您使用了 ARSCNView或者 ARSKView类的话,那么 ARKit 就可自行满足创建 AR 场景的基本要求:即每个视图的背景用实时的相机图像来展示,然后还可以渲染您提供的 2D 或者 3D 覆盖物 (overlay),从而构建出「这些覆盖物实际上是位于现实世界中」这样一种错觉。要使用这些视图类的话,您可以根据您所想要创建的 AR 场景类型来进行配置,然后为覆盖物选定位置和表示方式。

  • To build your own view for an AR experience instead, see Displaying an AR Experience with Metal.
  • 如果您需要构建自定义的视图来展示 AR 场景的话,请参阅使用 Metal 来展示 AR 场景一节。

Note / 注意

  • This article covers code found in Xcode project templates. For complete example code, create a new iOS application with the Augmented Reality template, and choose SceneKit or SpriteKit from the Content Technology popup menu.
  • 本文所涉及的代码均可以在 Xcode 项目模板当中找到。如果要获取完整的示例代码,请使用 “Augmented Reality” 模板来创建一个新的 iOS 应用,然后在弹出的 Content Technology 菜单当中选择 SceneKit或者SpriteKit

Configure and Run the AR Session / 配置 AR Session 并运行

  • Both the the ARSCNView
    and ARSKView
    classes include an ARSession
    object that manages the motion tracking and image processing required to create an AR experience. However, to run a session you must choose a session configuration.
  • ARSCNView和 ARSKView类都是包含在 ARSession当中的,而 ARSession对象则用来管理设备动作追踪和进行图像处理的,也就是创建 AR 场景的必需品。但是,要运行 Session,您首先必须选择一种 Session 配置。
image.png

The type of configuration object you choose determines the style and quality of AR experiences you can create:
您所选择的配置对象的类型,决定了您所创建的 AR 场景的风格和质量:

  • On iOS devices with an A9 processor or later, the ARWorldTrackingSessionConfiguration
    subclass provides high-precision motion tracking and enables features to help you place virtual content in relation to real-world surfaces.
  • 在具备 A9 或者更高版本处理器的 iOS 设备当中,ARWorldTrackingSessionConfiguration子类提供了高精度的设备动作追踪功能,可以帮助您将虚拟内容「放置」在现实世界中的某个表面上。

  • On other devices supported by ARKit, the ARSessionConfiguration
    base class provides basic motion tracking that permits slightly less immersive AR experiences.
  • 在 ARKit 所支持的其他设备当中,ARSessionConfiguration这个基础类则提供了基本的动作追踪功能,可以提供略弱的沉浸式 AR 体验。

To start an AR session, create a session configuration object with the options you want, then call the run(_:options:)
method on the session
object of your ARSCNView
or ARSKView
instance:
要启动 AR Session,那么首先要使用您所需要的配置,来创建 Session 配置对象,然后对 ARSCNView或者 ARSKView实例中的 session对象调用 run(_:options:)**方法:

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    
    // Create a session configuration
    let configuration = ARWorldTrackingSessionConfiguration()
    configuration.planeDetection = .horizontal
    
    // Run the view's session
    sceneView.session.run(configuration)
}

Important 重要
Run your session only when the view that will display it is onscreen.
只有当视图即将展示在屏幕的时候,才能够运行视图 Session。

After you’ve set up your AR session, use SceneKit or SpriteKit to place virtual content in the view.
当您配置完 AR Session 之后,就可以使用 SceneKit 或者 SpriteKit ,来将虚拟内容放置到视图当中了。

你可能感兴趣的:(ARKit学习-4)