{"id":21033322,"url":"https://github.com/sameesunkaria/buildingyourfirstarexperience","last_synced_at":"2025-03-13T20:14:43.634Z","repository":{"id":90242705,"uuid":"174561032","full_name":"Sameesunkaria/BuildingYourFirstARExperience","owner":"Sameesunkaria","description":null,"archived":false,"fork":false,"pushed_at":"2019-03-12T14:45:25.000Z","size":180,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-20T15:48:54.369Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Sameesunkaria.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE/LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-03-08T15:25:33.000Z","updated_at":"2019-03-20T11:35:50.000Z","dependencies_parsed_at":null,"dependency_job_id":"20164d4c-d362-41e3-8ab6-41ae19997100","html_url":"https://github.com/Sameesunkaria/BuildingYourFirstARExperience","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sameesunkaria%2FBuildingYourFirstARExperience","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sameesunkaria%2FBuildingYourFirstARExperience/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sameesunkaria%2FBuildingYourFirstARExperience/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sameesunkaria%2FBuildingYourFirstARExperience/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Sameesunkaria","download_url":"https://codeload.github.com/Sameesunkaria/BuildingYourFirstARExperience/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243475358,"owners_count":20296712,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-19T12:54:11.085Z","updated_at":"2025-03-13T20:14:43.608Z","avatar_url":"https://github.com/Sameesunkaria.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Building Your First AR Experience\n\nCreate an app that runs an AR session and uses plane detection to place 3D content using SceneKit.   \n\n## Overview\n\nThis sample app runs an [ARKit][0] world tracking session with content displayed in a SceneKit view. To demonstrate plane detection, the app visualizes both the estimated shape of and a bounding rectangle for each detected [`ARPlaneAnchor`][14] object. On supported devices, ARKit can recognize many types of real-world surfaces, so the app also labels each detected plane with identifying text.\n\n[0]:https://developer.apple.com/documentation/arkit\n[14]:https://developer.apple.com/documentation/arkit/arplaneanchor\n\n## Getting Started\n\nARKit requires iOS 11 and a device with an A9 (or later) processor. ARKit is not available in iOS Simulator. Building the sample code requires Xcode 9 or later.\n\n## Configure and Run the AR Session\n\nThe [`ARSCNView`][1] class is a SceneKit view that includes an [`ARSession`][2] object that manages the motion tracking and image processing required to create an augmented reality (AR) experience. However, to run a session you must provide a session configuration.\n\n[1]:https://developer.apple.com/documentation/arkit/arscnview\n[2]:https://developer.apple.com/documentation/arkit/arsession\n\n![Architecture diagram: an ARKit view owns an ARSession, which requires an ARConfiguration to run.](Documentation/ARViewSessionConfiguration.png)\n\nThe [`ARWorldTrackingConfiguration`][3] class provides high-precision motion tracking and enables features to help you place virtual content in relation to real-world surfaces. To start an AR session, create a session configuration object with the options you want (such as plane detection), then call the [`run(_:options:)`][4] method on the [`session`][5] object of your [`ARSCNView`][1] instance:\n\n``` swift\nlet configuration = ARWorldTrackingConfiguration()\nconfiguration.planeDetection = [.horizontal, .vertical]\nsceneView.session.run(configuration)\n```\n[View in Source](x-source-tag://StartARSession)\n\n[3]:https://developer.apple.com/documentation/arkit/arworldtrackingconfiguration\n[4]:https://developer.apple.com/documentation/arkit/arsession/2875735-run\n[5]:https://developer.apple.com/documentation/arkit/arscnview/2865796-session\n\nRun your session only when the view that will display it is onscreen.\n\n- Important: If your app requires ARKit for its core functionality, use the `arkit` key in the [`UIRequiredDeviceCapabilities`][7] section of your app's `Info.plist` file to make your app available only on devices that support ARKit. If AR is a secondary feature of your app, use the [`isSupported`][8] property to determine whether to offer AR-based features.\n\n[7]:https://developer.apple.com/library/content/documentation/General/Reference/InfoPlistKeyReference/Articles/iPhoneOSKeys.html#//apple_ref/doc/uid/TP40009252-SW3\n[8]:https://developer.apple.com/documentation/arkit/arconfiguration/2923553-issupported\n\n## Place 3D Content for Detected Planes\n\nAfter you’ve set up your AR session, you can use SceneKit to place virtual content in the view.\n\nWhen plane detection is enabled, ARKit adds and updates anchors for each detected plane. By default, the [`ARSCNView`][1] class adds an [`SCNNode`][9] object to the SceneKit scene for each anchor. Your view's delegate can implement the [`renderer(_:didAdd:for:)`][10] method to add content to the scene. When you add content as a child of the node corresponding to the anchor, the `ARSCNView` class automatically moves that content as ARKit refines its estimate of the plane's position.\n\n``` swift\nfunc renderer(_ renderer: SCNSceneRenderer, didAdd node: SCNNode, for anchor: ARAnchor) {\n    // Place content only for anchors found by plane detection.\n    guard let planeAnchor = anchor as? ARPlaneAnchor else { return }\n    \n    // Create a custom object to visualize the plane geometry and extent.\n    let plane = Plane(anchor: planeAnchor, in: sceneView)\n    \n    // Add the visualization to the ARKit-managed node so that it tracks\n    // changes in the plane anchor as plane estimation continues.\n    node.addChildNode(plane)\n}\n```\n[View in Source](x-source-tag://PlaceARContent)\n\n[9]:https://developer.apple.com/documentation/scenekit/scnnode\n[10]:https://developer.apple.com/documentation/arkit/arscnviewdelegate/2865794-renderer\n\nARKit offers two ways to track the area of an estimated plane. A plane anchor's [`geometry`][20] describes a convex polygon tightly enclosing all points that ARKit currently estimates to be part of the same plane (easily visualized using [`ARSCNPlaneGeometry`][21]). ARKit also provides a simpler estimate in a plane anchor's [`extent`][22] and [`center`][23], which together describe a rectangular boundary (easily visualized using [`SCNPlane`][12]).\n\n``` swift\n// Create a mesh to visualize the estimated shape of the plane.\nguard let meshGeometry = ARSCNPlaneGeometry(device: sceneView.device!)\n    else { fatalError(\"Can't create plane geometry\") }\nmeshGeometry.update(from: anchor.geometry)\nmeshNode = SCNNode(geometry: meshGeometry)\n\n// Create a node to visualize the plane's bounding rectangle.\nlet extentPlane: SCNPlane = SCNPlane(width: CGFloat(anchor.extent.x), height: CGFloat(anchor.extent.z))\nextentNode = SCNNode(geometry: extentPlane)\nextentNode.simdPosition = anchor.center\n\n// `SCNPlane` is vertically oriented in its local coordinate space, so\n// rotate it to match the orientation of `ARPlaneAnchor`.\nextentNode.eulerAngles.x = -.pi / 2\n```\n[View in Source](x-source-tag://VisualizePlane)\n\n[20]:https://developer.apple.com/documentation/arkit/arplaneanchor/2941025-geometry\n[21]:https://developer.apple.com/documentation/arkit/arscnplanegeometry\n[22]:https://developer.apple.com/documentation/arkit/arplaneanchor/2882055-extent\n[23]:https://developer.apple.com/documentation/arkit/arplaneanchor/2882056-center\n[12]:https://developer.apple.com/documentation/scenekit/scnplane\n\n\nARKit continually updates its estimates of each detected plane's shape and extent. To show the current estimated shape for each plane, this sample app also implements the [`renderer(_:didUpdate:for:)`][11] method, updating the [`ARSCNPlaneGeometry`][21] and [`SCNPlane`][12] objects to reflect the latest information from ARKit.\n\n``` swift\nfunc renderer(_ renderer: SCNSceneRenderer, didUpdate node: SCNNode, for anchor: ARAnchor) {\n    // Update only anchors and nodes set up by `renderer(_:didAdd:for:)`.\n    guard let planeAnchor = anchor as? ARPlaneAnchor,\n        let plane = node.childNodes.first as? Plane\n        else { return }\n    \n    // Update ARSCNPlaneGeometry to the anchor's new estimated shape.\n    if let planeGeometry = plane.meshNode.geometry as? ARSCNPlaneGeometry {\n        planeGeometry.update(from: planeAnchor.geometry)\n    }\n\n    // Update extent visualization to the anchor's new bounding rectangle.\n    if let extentGeometry = plane.extentNode.geometry as? SCNPlane {\n        extentGeometry.width = CGFloat(planeAnchor.extent.x)\n        extentGeometry.height = CGFloat(planeAnchor.extent.z)\n        plane.extentNode.simdPosition = planeAnchor.center\n    }\n    \n    // Update the plane's classification and the text position\n    if #available(iOS 12.0, *),\n        let classificationNode = plane.classificationNode,\n        let classificationGeometry = classificationNode.geometry as? SCNText {\n        let currentClassification = planeAnchor.classification.description\n        if let oldClassification = classificationGeometry.string as? String, oldClassification != currentClassification {\n            classificationGeometry.string = currentClassification\n            classificationNode.centerAlign()\n        }\n    }\n    \n}\n```\n[View in Source](x-source-tag://UpdateARContent)\n\n[11]:https://developer.apple.com/documentation/arkit/arscnviewdelegate/2865799-renderer\n\nOn iPhone XS, iPhone XS Max, and iPhone XR, ARKit can also classify detected planes, reporting which kind of common real-world surface that plane represents (for example, a table, floor, or wall). In this example, the [`renderer(_:didUpdate:for:)`][11] method also displays and updates a text label to show that information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsameesunkaria%2Fbuildingyourfirstarexperience","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsameesunkaria%2Fbuildingyourfirstarexperience","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsameesunkaria%2Fbuildingyourfirstarexperience/lists"}