Here is the "complete" recipe for what you are trying to achieve (we also plan to add a small tutorial in our Library soon):
If you want to have your AR start in mono (non-stereo) full-screen view and then switch to a Cardboard-based stereoscopic visualization at runtime (for instance upon detection of a target or in response to a user interface event), you can follow these steps:
First, check the Cardboard integration guide here how to set up a stereo view in your scene with Cardboard, and execute all the steps (including the necessary script code changes) so to integrate the Cardboard Main prefab and to bind the ARCamera to the Cardboard left and right cameras:
https://developer.vuforia.com/library//articles/Solution/Integrating-Cardboard-SDK-050
Then, with respect to the instructions above, configure your Scene slightly differently, so that it additionally includes:
- a “MonoAnchorPoint” empty game-object
o a “MonoCamera” (a standard Unity camera object) parented under the“MonoAnchorPoint” game-object
Then disable the Cardboard Main game object in the scene, and enable the “Bind Alternate Camera” option of the ARCamera and make sure to bind it to the MonoCamera by:
- dragging the “MonoAnchorPoint” game object onto the “Central Anchor Point” field
- dragging the “MonoCamera” onto the “Left Camera” field in the ARCamera inspector.
Leave the “Right Camera” field set to “None (Camera)”.
When dragging the MonoCamera game object onto the “Left Camera” field, a button “Add Vuforia Components” will appear in the inspector; make sure to click it in order to add the necessary Vuforia components and background plane to the MonoCamera.
Make sure to uncheck (disable) the “Synchronize Pose updates” (as this will be enabled at runtime via script).
The setup above will make your App start with a full screen mono view; you can then enable Cardboard stereo viewing at runtime using these steps:
- set the central anchor point to the Cardboard Head object (Transform):
VuforiaBehaviour.Instance.SetCentralAnchorPoint( cardboardHead );
- set the Primary and Secondary Cameras to the Cardboard left and right cameras:
VuforiaBehaviour.Instance.PrimaryCamera = cardboardCameraLeft;
VuforiaBehaviour.Instance.PrimaryCamera = cardboardCameraRight;
- enable the SynchronizePoseUpdates property, and set the HeadSetPresent property to "Cardboard":
VuforiaBehaviour.Instance.SynchronizePoseUpdates = true;
VuforiaBehaviour.Instance.SetHeadsetPresent("Cardboard");
- disable the MonAnchorPoint game object in the scene:
monoAnchorPoint.SetActive( false );
It is also recommended to stop the Camera before calling the code above, and restarting it right after:
- Stopping the camera:
CameraDevice.Instance.Stop();
CameraDevice.Instance.Deinit();
- Re-starting the camera:
CameraDevice.Instance.Init(CameraDevice.CameraDirection.CAMERA_BACK);
CameraDevice.Instance.SelectVideoMode(CameraDevice.CameraDeviceMode.MODE_OPTIMIZE_SPEED);
CameraDevice.Instance.Start();
In order to switch back to Mono from an AR Stereo view, you can use this code:
// set the new tracking reference
VuforiaBehaviour.Instance.SetCentralAnchorPoint(monoAnchorPoint);
VuforiaBehaviour.Instance.PrimaryCamera = monoCamera;
VuforiaBehaviour.Instance.SecondaryCamera = null;
// disable explicit updating
VuforiaBehaviour.Instance.SynchronizePoseUpdates = false;
// turn off the cardboard UI:
Cardboard.SDK.EnableAlignmentMarker = false;
Cardboard.SDK.EnableSettingsButton = false;
// deactivate the cardboard prefab:
cardboardHead.SetActive(false);
// enable the mono anchor point:
monoAnchorPoint.gameObject.SetActive(true);
// Stop and Deinit the camera:
CameraDevice.Instance.Stop();
CameraDevice.Instance.Deinit();
// now tell Vuforia that it's being removed from the Cardboard headset:
vuforiaBehaviour.SetHeadsetNotPresent();
// initialize the camera again:
CameraDevice.Instance.Init(CameraDevice.CameraDirection.CAMERA_BACK);
CameraDevice.Instance.SelectVideoMode(CameraDevice.CameraDeviceMode.MODE_OPTIMIZE_SPEED);
CameraDevice.Instance.Start();
Additionally, if you want to switch from an AR to a VR visualization (the latter being without video background), you will also need to implement the following:
- Disable the HideExcessAreaBehaviour components on the left and right cameras of the Cardboard Main prefab (otherwise virtual content will be clipped to size of the video background, which is not filling the full field of view of the Cardboard cameras)
o And make sure to re-enable them when switching back to an AR view
- Disable the VideoBackgroundBehaviour components on the left and right cameras of the Cardboard Main prefab (this will save unnecessary operations and will enhance rendering performance)
- Disable the MeshRenderer component of the BackgroundPlane under the left camera of the Cardboard prefab (this will save a little more performance)
Great to hear.