Basic ARKit example that detects planes and makes them lava.

Overview

FloorIsLava

Basic ARKit example that detects planes and makes them lava.

Requirements

  • Xcode 9 (you can view the code in Xcode 8 but will not be able to build the project)
  • Device running iOS 11, with an A9 chip or higher (iPhone 6S or newer, iPad Pro)

Project Walkthrough

Welcome to ARKit! This basic project setup shows how to start an AR session and watch for planes that are detected. We are using an ARSCNView, a specially designed SceneKit view that contains an ARSession.

1. Configuring and starting the session

The ARSession gathers data from the world and processes it. Because we want to place objects on horizontal planes, we need to configure the session to detect them:

let configuration = ARWorldTrackingConfiguration()
configuration.planeDetection = .horizontal

We can then start the session with this configuration by running:

sceneView.session.run(configuration)

2. Add a SceneKit node to detected planes

Next, we override the ARSCNViewDelegate renderer methods. The SceneView will call these methods when AR "anchors" are detected in the world. Since we've configured the session to detect horizontal planes, these methods will be called for those as well.

In the didAdd method, we check that the discovered node is a plane, then use a helper function to create a simple SceneKit plane. Finally, we add the SceneKit plane as a child of the automatically-generated node for the anchor.

func renderer(_ renderer: SCNSceneRenderer, didAdd node: SCNNode, for anchor: ARAnchor) {

  guard let planeAnchor = anchor as? ARPlaneAnchor else { return }
  
  let planeNode = createPlaneNode(anchor: planeAnchor)
  
  // ARKit owns the node corresponding to the anchor, so make the plane a child node.
  node.addChildNode(planeNode) 
}

3. Update the SceneKit plane when the AR plane is updated

As the user moves the device camera around the world, the session gets more information about anchors. We implement the didUpdate method, which is called when the session updates an existing anchor, so we can update our SceneKit node to match the AR plane.

func renderer(_ renderer: SCNSceneRenderer, didUpdate node: SCNNode, for anchor: ARAnchor) {

    guard let planeAnchor = anchor as? ARPlaneAnchor else { return }

    // Remove existing plane nodes
    node.enumerateChildNodes {
        (childNode, _) in
        childNode.removeFromParentNode()
    }

    let planeNode = createPlaneNode(anchor: planeAnchor)

    node.addChildNode(planeNode)
}

4. Remove the SceneKit plane when the AR plane is removed

Finally, we implement the didRemove delegate method to remove any SceneKit planes we've created if a plane is removed from the world.

func renderer(_ renderer: SCNSceneRenderer, didRemove node: SCNNode, for anchor: ARAnchor) {

    guard anchor is ARPlaneAnchor else { return }

    // Remove existing plane nodes
    node.enumerateChildNodes {
        (childNode, _) in
        childNode.removeFromParentNode()
    }
}
You might also like...
ARKit Demo Application
ARKit Demo Application

ARKitNavigationDemo Work in progress. In Progress Region β€” For one, we could render far fewer nodes. In fact, it’s a bit distracting that the entire t

This library uses ARKit Face Tracking in order to catch user's smile.
This library uses ARKit Face Tracking in order to catch user's smile.

SmileToUnlock Make your users smile before opening the app :) Gif with the demonstration Installation Cocoapods The most preferable way to use this li

PlacenoteSDK Sample app in native iOS using ARKit, written primarily in Swift

Placenote SDK for iOS Placenote SDK lets you easily build cloud-based Augmented Reality (AR) apps that pin digital content to locations in the real wo

Power! Unlimited power for ARKit 2.0!
Power! Unlimited power for ARKit 2.0!

A long time ago in a galaxy, far, far away... It is a period when iPhone SE and iPhone X were destroyed from the apple store, the AR market was under

A simple application created for educational purposes for mastering ARKit
A simple application created for educational purposes for mastering ARKit

ARDrawing AR Drawing is a simple application created for educational purposes for mastering ARKit. The basis of the project is copied from the project

Trying TDD with ARKit
Trying TDD with ARKit

ARPlacer BDD Spec As a user I want to place a random object in real world. I also want to see the distance between AR object and my phone. Use Cases

Draw VR content over live camera feed with ARKit

funny-ar Exercise with ARKit: draw VR content over live camera feed: work is in

ARKit: Projecting 3D mesh to 2D coordinate
ARKit: Projecting 3D mesh to 2D coordinate

ARKitDemo ARKit: Projecting 3D mesh to 2D coordinate A simple utility to project 3D face mesh in 2D coordinate on device screen. Sources: https://deve

Furniture E-Commerce Augmented Reality(AR) app in iOS powered by ARKit
Furniture E-Commerce Augmented Reality(AR) app in iOS powered by ARKit

HomeMax-iOS Furniture E-Commerce Augmented Reality(AR) app in iOS powered by ARKit and SceneKit. Inspired by IKEA place app. Description Experience on

Comments
  • ARSCNViewDelegate not called

    ARSCNViewDelegate not called

    Hi I cloned your project and ran it without change on my iPhone but the ARSCNViewDelegate renderer methods are not called. Do you know any issue with plane detections?

    opened by gdelafosse 3
  • Changed deprecated ARWorldTrackingSessionConfiguration

    Changed deprecated ARWorldTrackingSessionConfiguration

    "ARWorldTrackingSessionConfiguration" is deprecated since iOS 11 came out of beta. This commit changes all occurrences in this project to the now appropriate "ARWorldTrackingConfiguration".

    https://developer.apple.com/documentation/arkit/arworldtrackingconfiguration

    opened by antonrohr 1
Owner
Ari V
PM @ Kry/Livi I like CSS and hedgehogs.
Ari V
ARKit Base Project. Place virtual objects based on WWDC example project

ARKit - Placing Virtual Objects in Augmented Reality Learn best practices for visual feedback, gesture interactions, and realistic rendering in AR exp

Ignacio Chiazzo Cardarello 338 Jan 5, 2023
A library that allows you to generate and update environment maps in real-time using the camera feed and ARKit's tracking capabilities.

ARKitEnvironmentMapper Example To run the example project, clone the repo, and run pod install from the Example directory first. Installation ARKitEnv

SV Hawks 91 Dec 4, 2022
A library that allows you to generate and update environment maps in real-time using the camera feed and ARKit's tracking capabilities.

ARKitEnvironmentMapper Example To run the example project, clone the repo, and run pod install from the Example directory first. Installation ARKitEnv

SV Hawks 91 Dec 4, 2022
Using ARKit and LiDAR to save depth data and export point cloud, based on WWDC20-10611 sample code

Save iOS ARFrame and Point Cloud This project improves the usability of the sample code from WWDC20 session 10611: Explore ARKit 4. Note that the samp

null 4 Dec 22, 2022
A sample collection of basic functions of Apple's AR framework for iOS.

RealityKit-Sampler RealityKitSampler is a sample collection of basic functions of RealityKit, Apple's AR framework for iOS. How to build 1, Download o

MLBoy 74 Dec 21, 2022
An iOS Framework Capture & record ARKit videos πŸ“Ή, photos πŸŒ„, Live Photos πŸŽ‡, and GIFs πŸŽ†.

An iOS Framework that enables developers to capture videos ?? , photos ?? , Live Photos ?? , and GIFs ?? with ARKit content.

Ahmed Bekhit 1.5k Dec 24, 2022
Augmented Reality image tracking with SwiftUI, RealityKit and ARKit 4.

ARImageTracking This is an Augmented Reality Xcode project that uses Apple's newest RealityKit framework and ARKit 4 features, to dynamically track a

Richard Qi 198 Dec 7, 2022
ARDicee - Simple augmented reality app using SceneKit and ARKit

ARDicee Simple augmented reality app using SceneKit and ARKit Requirements Xcode

donggyu 3 Feb 4, 2022
AR Ruler - A simple iOS app made using ARKit and SceneKit

A simple iOS app made using ARKit and SceneKit.Which can try to simplify little things in your life such as measuring stuff.

Dishant Nagpal 5 Aug 31, 2022
ARKit + CoreLocation: Combines the high accuracy of AR with the scale of GPS data.

ARKit: Uses camera and motion data to map out the local world as you move around. CoreLocation: Uses wifi and GPS data to determine your global locati

Andrew Hart 5.3k Dec 27, 2022