Replacement for Arkit in iOS10

Replacement for ARKit in iOS10

Depending on how you've set your expectations, it is possible to use SceneKit as a "fallback" from ARKit -- specifically, from ARSCNView.

What you can easily do is create a 3D content experience that appears "in the real world" via AR when running on an ARKit capable device, and in an entirely virtual setting (that is, rendered in 3D without a camera feed as background) when running without ARKit.

Note: ARKit support isn't just an iOS 11 thing -- you also need an A9 device. So you might think about a fallback experience for older hardware on iOS 11, not just for older iOS versions.

To do that, you'll need to be able to swap out your view class at runtime. That means not creating ARSCNView in a storyboard, but initializing one and adding it to your view controller's root view in code.

override func viewDidLoad() {
super.viewDidLoad()
let sceneView = ARSCNView(frame: view.bounds)
sceneView.scene = // ... set up your SceneKit scene ...
view.addSubview(sceneView)
}

Once you're doing something like that, you can wrap the critical part in a conditional that uses ARSCNView when available and SCNView otherwise. Actually, you might want to set up a handy function for that...

var canUseARKit: Bool {
if #available(iOS 11.0,*) {
return ARWorldTrackingSessionConfiguration.isSupported
} else {
return false
}
}

Then you can conditionalize your view setup:

override func viewDidLoad() {
super.viewDidLoad()
let sceneView: SCNView
if canUseARKit {
sceneView = ARSCNView(frame: view.bounds)
} else {
sceneView = SCNView(frame: view.bounds)
}
sceneView.scene = // ... set up your SceneKit scene ...
view.addSubview(sceneView)
}

Of course, there's still more to do after that:

  • When you're using ARKit, you get camera control "for free"; when you're using SceneKit on its own you'll have to think about where to place the camera and how to let the user control it. (Check the WWDC17 SceneKit session for some tips on new iOS 11 camera controls.)
  • When you're using SceneKit on its own, your 3D content defines "the world" that the user interacts with -- that is, you place cameras and such in relation to your content. When using ARKit, you have to think about where and how to place your content relative to the real world.

But aside from such concerns, working with SceneKit content within ARSCNView is no different from working with SceneKit content inSCNView, so for the rest of your app/game you can share a lot of code and assets between AR and non-AR user experiences.

SCNGeometry / SCNCylinder render edges / border only (Store color, clear content)

The WWDC 2014 presentation showed orbiting cubes that had only wireframes. The technique was to use an image with green edges but transparent interior as the material. From AAPLSlideScenegraphSummary.m:

        // A node that will help visualize the position of the stars
_wireframeBoxNode = [SCNNode node];
_wireframeBoxNode.rotation = SCNVector4Make(0, 1, 0, M_PI_4);
_wireframeBoxNode.geometry = [SCNBox boxWithWidth:1 height:1 length:1 chamferRadius:0];
_wireframeBoxNode.geometry.firstMaterial.diffuse.contents = [NSImage imageNamed:@"box_wireframe"];
_wireframeBoxNode.geometry.firstMaterial.lightingModelName = SCNLightingModelConstant; // no lighting
_wireframeBoxNode.geometry.firstMaterial.doubleSided = YES; // double sided

Sample Image

For a similar effect with SCNCylinder, you might need to pass an array of materials, some with border and some without.

Edit

For High Sierra/iOS 11 and higher, the answer by @mnuages is a simpler/better approach.

Privacy Camera Description issue in info.plist

Try below things,

  1. Delete app from Simulator or Device
  2. Press Cmd + Shift + K to clean the project and Cmd + Alt + Shift + K to clean the build directory
  3. Remove Derived Data folder
  4. Quit and restart Xcode

FYI. Just give it a try.



Related Topics



Leave a reply



Submit