You must follow this steps:
In the menu bar:
Game Object->Create Empty and after rename the created object (this for MonoAnchorPoint)
Game Object->Camera and after rename the created camera (this for MonoCamera)
It is important in the MonoCamera that you change the Near and Far parameters according with the Camera paramenters in ARCamera.
For the switching the script that I have created and function well is:
using UnityEngine;
using System.Collections;
using Vuforia;
public class StereoToMono : MonoBehaviour {
public bool mono = false;
public GameObject cardboardMain = null;
public GameObject cardboardHead = null;
public GameObject monoAnchorPoint = null;
public Camera monoCamera = null;
public Camera cardboardCameraLeft = null;
public Camera cardboardCameraRight = null;
public bool switching = false;
// Use this for initialization
void Start () {
if (mono)
monoMode ();
else
stereoMode ();
}
// Update is called once per frame
void Update () {
if (switching) {
switching = false;
if (mono){
stereoMode ();
ui.showMessage(ui.SWITCHMONO);
Handheld.Vibrate();
}
else if (!mono){
monoMode ();
ui.showMessage(ui.SWITCHSTEREO);
Handheld.Vibrate();
}
}
}
public void monoMode(){
// Stop and Deinit the camera:
CameraDevice.Instance.Stop ();
CameraDevice.Instance.Deinit ();
cardboardMain.SetActive (false);
// enable the mono anchor point:
monoAnchorPoint.SetActive (true);
// set the new tracking reference
VuforiaBehaviour.Instance.SetCentralAnchorPoint (monoAnchorPoint.GetComponent<Transform> ());
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;
// now tell Vuforia that it's being removed from the Cardboard headset:
VuforiaBehaviour.Instance.SetHeadsetNotPresent ();
// initialize the camera again:
CameraDevice.Instance.Init (CameraDevice.CameraDirection.CAMERA_BACK);
CameraDevice.Instance.SelectVideoMode (CameraDevice.CameraDeviceMode.MODE_OPTIMIZE_SPEED);
CameraDevice.Instance.Start ();
mono = true;
}
public void stereoMode(){
CameraDevice.Instance.Stop();
CameraDevice.Instance.Deinit();
// enable the mono anchor point:
monoAnchorPoint.SetActive (false);
cardboardMain.SetActive (true);
VuforiaBehaviour.Instance.SetCentralAnchorPoint( cardboardHead.GetComponent<Transform>());
VuforiaBehaviour.Instance.PrimaryCamera = cardboardCameraLeft;
VuforiaBehaviour.Instance.SecondaryCamera = cardboardCameraRight;
VuforiaBehaviour.Instance.SynchronizePoseUpdates = true;
VuforiaBehaviour.Instance.SetHeadsetPresent("Cardboard");
monoAnchorPoint.SetActive( false );
CameraDevice.Instance.Init(CameraDevice.CameraDirection.CAMERA_BACK);
CameraDevice.Instance.SelectVideoMode(CameraDevice.CameraDeviceMode.MODE_OPTIMIZE_SPEED);
CameraDevice.Instance.Start();
mono = false;
}
}
The variable switching is for switching to mono and stereo and viceversa in play mode.
Remember that the script must be attached to a GameObject in the scene and the variable:
public bool mono = false;
public GameObject cardboardMain = null;
public GameObject cardboardHead = null;
public GameObject monoAnchorPoint = null;
public Camera monoCamera = null;
public Camera cardboardCameraLeft = null;
public Camera cardboardCameraRight = null;
public bool switching = false;
must be set in the inspector menu.
Hi, sorry for my english,
Gino.
In my heiarchy the cardboard game object does not exist.
Then when I create the script where do I attach it to?
Then How do i create the button to toggle between Mono and stereo?