ARKit學(xué)習(xí)-6

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


Providing 2D Virtual Content with SpriteKit(使用 SpriteKit 來提供 2D 虛擬元素)

Use SpriteKit to place two-dimensional images in 3D space in your AR experience.
使用 SpriteKit 在您的 3D AR 場景中放置二維圖像。


Overview

  • 要將 SpriteKit 元素放進增強現(xiàn)實當(dāng)中,您首先需要運行 AR Session(請參閱構(gòu)建基本的 AR 場景一節(jié))。

  • SpriteKit is inherently for 2D visual content, but augmented reality involves real-world 3D spaces. Use the ARSKView
    class to create AR experiences by providing 2D sprites (SKNode
    objects) that correspond to real-world 3D positions (ARAnchor
    objects). When the user moves the device, the view automatically rotates and scales the SpriteKit nodes corresponding to anchors so that they appear to track the real world seen by the camera.

  • SpriteKit 只包含有 2D 元素,但是增強現(xiàn)實則涉及到現(xiàn)實世界的 3D 空間。因此,使用ARSKView類來創(chuàng)建 AR 場景,這樣就可以在真實世界對應(yīng)的 3D 位置 ( ARAnchor對象) 中放置 2D 精靈元素 ( SKNode) 對象)。當(dāng)用戶移動設(shè)備的時候,視圖會自動旋轉(zhuǎn)并縮放與錨點相對應(yīng)的 SpriteKit 結(jié)點,看起來這些元素能夠追蹤相機所看到的真實世界。
    For example, you can place 2D images that appear to float in 3D space:
    舉個例子,您可以將 2D 圖像以漂浮的方式,放置在 3D 空間當(dāng)中:

// Create a transform with a translation of 0.2 meters in front of the camera.
var translation = matrix_identity_float4x4
translation.columns.3.z = -0.2
let transform = simd_mul(view.session.currentFrame.camera.transform, translation)

// Add a new anchor to the session.
let anchor = ARAnchor(transform: transform)
view.session.add(anchor: anchor)

// (Elsewhere...) Provide a label node to represent the anchor.
func view(_ view: ARSKView, nodeFor anchor: ARAnchor) -> SKNode? {
    return SKLabelNode(text: "??")
}
  • The view(_:nodeFor:)
    method above returns an SKLabelNode
    object, which displays a text label. Like most SpriteKit nodes, this class creates a 2D visual representation, so the ARSKView
    class presents the node in a billboard style: The sprite scales and rotates (around its z-axis) so that it appears to follow the 3D position of its anchor, but always faces toward the camera.
  • 上面的這個 view(_:nodeFor:)方法將會返回一個 SKLabelNode對象,用以展示文本標(biāo)簽。與大多數(shù) SpriteKit 結(jié)點一樣,這個類將會創(chuàng)建一個 2D 的可視化表示,因此ARSKView類將會以廣告牌的樣式來展示這個結(jié)點:精靈可以通過(圍繞 z 軸)縮放以及旋轉(zhuǎn),讓其看起來能夠跟隨錨點的 3D 位置,但是卻始終面向相機。
最后編輯于
?著作權(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)容

  • Introducing ARKit iOS 11 引入 ARKit,這是 個全新的框架,允許開發(fā)者輕松地為 iP...
    沒八阿哥的程序閱讀 2,683評論 1 9
  • ARkit Introducing ARKit iOS 11引入ARKit,這是 個全新的框架,允許開發(fā)者輕松地為...
    坤哥愛卿閱讀 1,490評論 0 1
  • 引言ARKit 為開發(fā) iPhone 和 iPad 增強現(xiàn)實(AR)app 提供了一個前沿平臺。本文為你介紹 AR...
    螞蟻安然閱讀 9,646評論 0 14
  • 轉(zhuǎn)載請注明出處Apple原文地址:https://developer.apple.com/documentatio...
    小羊快跑閱讀 387評論 0 2
  • A view for displaying AR experiences that augment the cam...
    loveFBI閱讀 1,039評論 0 0

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