ARKit學習-4

轉(zhuǎn)載請注明出處
Apple原文地址: https://developer.apple.com/documentation/arkit/building_a_basic_ar_experience

Building a Basic AR Experience 構(gòu)建基本的 AR 場景

Configure an AR session and use SceneKit or SpriteKit to display AR content.
配置 AR Session,然后使用 SceneKit 或者 SpriteKit 來展示 AR 內(nèi)容。


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 就可自行滿足創(chuàng)建 AR 場景的基本要求:即每個視圖的背景用實時的相機圖像來展示,然后還可以渲染您提供的 2D 或者 3D 覆蓋物 (overlay),從而構(gòu)建出「這些覆蓋物實際上是位于現(xiàn)實世界中」這樣一種錯覺。要使用這些視圖類的話,您可以根據(jù)您所想要創(chuàng)建的 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” 模板來創(chuàng)建一個新的 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.
  • ARSCNViewARSKView類都是包含在 ARSession當中的,而 ARSession對象則用來管理設(shè)備動作追蹤和進行圖像處理的,也就是創(chuàng)建 AR 場景的必需品。但是,要運行 Session,您首先必須選擇一種 Session 配置。
image.png

The type of configuration object you choose determines the style and quality of AR experiences you can create:
您所選擇的配置對象的類型,決定了您所創(chuàng)建的 AR 場景的風格和質(zhì)量:

  • 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 設(shè)備當中,ARWorldTrackingSessionConfiguration子類提供了高精度的設(shè)備動作追蹤功能,可以幫助您將虛擬內(nèi)容「放置」在現(xiàn)實世界中的某個表面上。

  • On other devices supported by ARKit, the ARSessionConfiguration
    base class provides basic motion tracking that permits slightly less immersive AR experiences.
  • 在 ARKit 所支持的其他設(shè)備當中,ARSessionConfiguration這個基礎(chǔ)類則提供了基本的動作追蹤功能,可以提供略弱的沉浸式 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,那么首先要使用您所需要的配置,來創(chuàng)建 Session 配置對象,然后對 ARSCNView或者 ARSKView實例中的 session對象調(diào)用 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 ,來將虛擬內(nèi)容放置到視圖當中了。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容