This is an example of using Apple SceneKit with iOS Google Virtual Reality SDK for using with Google Cardboard.
Currently ( January 2018 April 2017 June 2016 ) it is the easiest way to develop VR app on the iPhone. Hope this is going to change after WWDC 2016 2017 2018.
The project codename is ’VRBoilerplate’ and initially it was prepared for iOS programming competition UADevChallenge 2016. It supports both Objective-C and Swift.
Install CocoaPods, open VRBoilerplate.xcworkspace, start coding.
To create and manage scene, you need to implement a class based on VRControllerProtocol.
Than specify that class in Info.plist under VRControllerClass key.
If you’re using Swift, you need to specify Obj-C runtime class name
@objc(VRControllerSwift)
class VRControllerSwift : NSObject, VRControllerProtocol {
// ...
Very simple protocol that contains init-constructor and three methods.
Read-only property that should return SCNScene. Can’t be null, the scene should not be changed during VRController object lifetime.
The method is called before each frame (one time for both eyes). Argument is head rotation from GVR SDK.
You can use prepareFrameWithHeadTransform: as a game loop body.
This method is called when magnet on Cardboard is ‘clicked’ (or if there there are tap on Simulator window)
There is VRControllerSwift and VRControllerObjC example VR controllers. Which one is going to be used is specified in Info.plist. By default we use VRControllerSwift.
They contain different implementations. If you want to do some cool stuff, I suggest you to read both.
-
Viewer is at the point (0, 0, 0) looking around. The project does not takes into account SCNCamera objects in Scene. After app start the viewer is looking at the direction (0, 0, -1). The direction which viewer is holding Cardboard in the real word is going to be (0, 0, -1) in VR.
-
There are number of problems with integration of GVR and SceneKit. Since GVR is closed source, they are more like ‘known issues’ like now.
-
reflectivity (.reflectivity > 0) does not work for SCNFloor
-
SpriteKit scenes are not working as a materials
-
There are two warning during build: … direct access in gvr::Singleton gvr::ServerLogger ::GetInstance() to global weak symbol — see issue in GVR project.
-