A view for displaying AR experiences that augment the camera view with 2D SpriteKit content.
顯示使用2D SpriteKit內容增強相機視圖的AR體驗的視圖。
Overview
Use the?ARSKView?class to create augmented reality experiences that position 2D elements in 3D space within a device camera view of the real world. When you run the view's provided?ARSession?object:
The view automatically renders the live video feed from the device camera as the scene background.
When you implement?ARSKViewDelegate?methods to associate SpriteKit content with real-world positions, the view automatically scales and rotates those SpriteKit nodes so that they appear to track the real world seen by the camera.
概述
使用ARSKView類創建增強現實體驗,將2D元素定位在真實世界的設備相機視圖內的3D空間中。 當你運行視圖提供的ARSession對象時:
1.該視圖自動將設備攝像機的實時視頻饋送呈現為場景背景。
當您使用ARSKViewDelegate方法將SpriteKit內容與實際位置關聯時,視圖會自動縮放和旋轉這些SpriteKit節點,以便它們看起來跟蹤攝像機看到的真實世界。
? ? ? ? ? ? ? ? ? ? ? ? ?First Steps
Providing 2D Virtual Content with SpriteKit
Use SpriteKit to place two-dimensional images in 3D space in your AR experience.
使用SpriteKit在AR體驗中將二維圖像放置在3D空間中。
Overview
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 (SKNodeobjects) 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.?
For example, you can place 2D images that appear to float in 3D space:
概述
SpriteKit固有地用于2D視覺內容,但增強現實涉及真實世界的3D空間。 使用ARSKView類通過提供對應于真實世界3D位置(ARAnchor對象)的2D精靈(SKNode對象)來創建AR體驗。 當用戶移動設備時,視圖會自動旋轉并縮放與錨點相對應的SpriteKit節點,以便它們看起來跟蹤攝像機看到的真實世界。
例如,您可以放置出現在3D空間中的2D圖像:
The?view:nodeForAnchor:?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:nodeForAnchor:方法返回一個SKLabelNode對象,該對象顯示一個文本標簽。 和大多數SpriteKit節點一樣,這個類創建了一個2D視覺表示,所以ARSKView類以一種廣告牌風格呈現節點:sprite縮放并旋轉(圍繞其z軸),使其看起來跟隨其錨點的3D位置, 但始終朝向相機。
session
The AR session that manages motion tracking and camera image processing for the view's contents.
ARSession管理視圖內容的運動跟蹤和攝像頭圖像處理。
Discussion
A view creates its own session object; use this property to access and configure the view's session.
討論
視圖創建自己的Session對象; 使用此屬性來訪問和配置視圖的Session。
? ? ? ? ? ? ? ? ? ? ? ? ? ? Responding to AR Updates
delegate
An object you provide to mediate synchronization of the view's AR scene information with SpriteKit content.
您提供的一個對象,用于調解視圖的AR場景信息與SpriteKit內容的同步。
ARSKViewDelegate
Methods you can implement to mediate the automatic synchronization of SpriteKit content with an AR session.
您可以實現的方法來調解SpriteKit內容與ARSession的自動同步。
Overview
Implement this protocol to provide SpriteKit content corresponding to?ARAnchor?objects tracked by the view's AR session, or to manage the view's automatic updating of such content.
This protocol extends the?ARSessionObserver?protocol, so your session delegate can also implement those methods to respond to changes in session status.
概述
實現此協議以提供與由視圖的ARSession跟蹤的ARAnchor對象相對應的SpriteKit內容,或管理視圖對此類內容的自動更新。
這個協議擴展了ARSessionObserver協議,所以你的會話委托也可以實現這些方法來響應會話狀態的變化。
Handling Content Updates
view:nodeForAnchor:
Asks the delegate to provide a SpriteKit node corresponding to a newly added anchor.
要求代理提供與新添加的錨對應的SpriteKit節點。
Parameters
view
The?ARSKView?object rendering the scene.
渲染場景的ARSKView對象。
anchor
The anchor for which a node is requested.
請求節點的錨點。
Return Value
A new SpriteKit node, which ARKit will add to the scene and update to follow its corresponding AR anchor.
返回值
一個新的SpriteKit節點,ARKit將添加到場景并更新以跟隨其相應的AR錨點。
Discussion
Depending on the session configuration, ARKit may automatically add anchors to a session, such as the origin of the world coordinate system and detected planes. ARKit also calls this method to provide visual content for any?ARAnchor?objects you manually add using the session's?addAnchor:?method.
You can implement this method to provide a new?SKNode?object (or instance of any system or custom?SKNode?subclass) you plan to use as a visual representation of the anchor.?
Note that ARKit controls the node's position, rotation, and scale to simulate a billboarded 3D effect even for 2D sprites. If you provide a?SKTransformLayer?node, ARKit applies a 3D transformation.
Alternatively, if you do not implement this method, ARKit creates an empty node, and you can implement the?view:didAddNode:forAnchor:?method instead to provide visual content by adding children to that node.
討論
根據Session配置的不同,ARKit可能會自動將錨點添加到Session中,例如世界坐標系的原點和檢測到的平面。 ARKit還調用此方法為使用會話的addAnchor:方法手動添加的任何ARAnchor對象提供可視內容。
您可以實現此方法以提供計劃用作錨的可視表示的新SKNode對象(或任何系統或自定義SKNode子類的實例)。
請注意,ARKit控制節點的位置,旋轉和縮放比例,以模擬即使是2D Sprite也使用billboarded 3D效果。 如果您提供SKTransformLayer節點,ARKit將應用3D轉換。
或者,如果您未實現此方法,則ARKit將創建一個空節點,并且您可以實現視圖:didAddNode:forAnchor:方法,以通過將子節點添加到該節點來提供可視內容。
view:didAddNode:forAnchor:
Tells the delegate that a SpriteKit node corresponding to a new AR anchor has been added to the scene.
告訴委托人已將與新的AR錨點對應的SpriteKit節點添加到場景中。
Parameters
view
The?ARSKView?object rendering the scene.
渲染場景的ARSKView對象。
node
The newly added SpriteKit node.
新添加的SpriteKit節點。
anchor
The AR anchor corresponding to the node.
AR節點對應的AR節點。
Discussion
Depending on the session configuration, ARKit may automatically add anchors to a session. The view calls this method once for each new anchor. ARKit also calls this method to provide visual content for any?ARAnchor?objects you manually add using the session's?addAnchor:?method.
You can provide visual content for the anchor by adding child nodes.
Alternatively, you can implement the?view:nodeForAnchor:?method to create your own node (or instance of an?SKNode?subclass) for an anchor.
討論
根據Session配置的不同,ARKit可能會自動將錨點添加到Session中。 該視圖為每個新的錨點調用一次該方法。 ARKit還調用此方法為使用會話的addAnchor:方法手動添加的任何ARAnchor對象提供可視內容。
您可以通過添加子節點來為定位點提供可視內容。
或者,您可以實現view:nodeForAnchor:方法為錨點創建自己的節點(或SKNode子類的實例)。
view:willUpdateNode:forAnchor:
Tells the delegate that a SpriteKit node's properties will be updated to match the current state of its corresponding anchor.
告訴委托人SpriteKit節點的屬性將被更新以匹配其相應錨的當前狀態。
Parameters
view
The ARSKView object rendering the scene.
渲染場景的ARSKView對象。
node
The updated SpriteKit node.
更新的SpriteKit節點
anchor
The AR anchor corresponding to the node.
AR節點對應的AR節點。
Discussion
Depending on the session configuration, ARKit may automatically update anchors in a session. The view calls this method once for each updated anchor.
討論
根據Session配置的不同,ARKit可能會自動更新Session中的錨點。 該視圖為每個更新的錨點調用一次該方法。
view:didUpdateNode:forAnchor:
Tells the delegate that a SpriteKit node's properties have been updated to match the current state of its corresponding anchor.
告訴委托人,SpriteKit節點的屬性已經更新以匹配其相應錨的當前狀態。
Parameters
view
The ARSKView object rendering the scene.
渲染場景的ARSKView對象。
node
The updated SpriteKit node.
更新的SpriteKit節點
anchor
The AR anchor corresponding to the node.
AR節點對應的AR節點。
Discussion
Depending on the session configuration, ARKit may automatically update anchors in a session. The view calls this method once for each updated anchor.
討論
根據Session配置的不同,ARKit可能會自動更新Session中的錨點。 該視圖為每個更新的錨點調用一次該方法。
view:didRemoveNode:forAnchor:
Tells the delegate that the SpriteKit node corresponding to an AR anchor has been removed from the scene.
告訴委托人,與AR錨對應的SpriteKit節點已從場景中移除。
Parameters
view
The ARSKView object rendering the scene.
渲染場景的ARSKView對象。
node
The updated SpriteKit node.
更新的SpriteKit節點
anchor
The AR anchor corresponding to the node.
AR節點對應的AR節點。
Discussion
Depending on the session configuration, ARKit may automatically remove anchors from a session. The view calls this method once for each removed anchor.
討論
根據Session配置的不同,ARKit可能會自動從Session中刪除錨點。 該視圖為每個已移除的錨點調用一次該方法。
Inherits From?ARSessionObserver,?SKViewDelegate