Hi @friuns -
Thanks for reporting the crash! Your usage of the ARBackground renderer is not quite correct. You will need to create a Resources directory in Assets and create a material there that has its shader set to AR/TangoARRender. No need to attach a texture to this material as the background texture is created in an optimized way by Unity. Here is an example MonoBehavior you can use for the renderer setup:
public class ARRenderSetup : MonoBehaviour {
private UnityEngine.XR.ARBackgroundRenderer backgroundRenderer = new UnityEngine.XR.ARBackgroundRenderer();
private Material mat;
void Awake()
{
// First parameter is the name of your material in the Resources folder
mat = Resources.Load(āTangoARBackgroundā, typeof(Material)) as Material;
}
// Use this for initialization
void Start ()
{
// Associate this background renderer object with Tango
UnityEngine.XR.Tango.TangoDevice.backgroundRenderer = backgroundRenderer;
// Associate the rendererās background material with the material in your Resources folder
backgroundRenderer.backgroundMaterial = mat;
backgroundRenderer.mode = UnityEngine.XR.ARRenderMode.MaterialAsBackground;
}
}
This MonoBehavior moves the Unity camera in sync with the position of the Tango camera:
public class CameraMovement : MonoBehaviour {
void Update () {
UnityEngine.XR.Tango.PoseData pose;
if (UnityEngine.XR.Tango.TangoInputTracking.TryGetPoseAtTime(out pose, UnityEngine.XR.Tango.CoordinateFrame.StartOfService, UnityEngine.XR.Tango.CoordinateFrame.CameraColor)) {
Camera.main.transform.position = pose.position;
Camera.main.transform.rotation = pose.rotation;
}
}
}
This MonoBehavior properly initializes Tango for a simple AR scene (no depth camera).
public class TangoConnection : MonoBehaviour
{
private TangoConfig tangoAPIConfig = new TangoConfig();
#if UNITY_EDITOR
// A camera field already exists in MonoBehavior for Editor-only,
// so use the new keyword there to silence a warning about it.
public new Camera camera;
#else
// The runtime doesnāt have this problem, so donāt use the
// new keyword here.
public Camera camera;
#endif
private Nullable m_VerticalFov = null;
private Nullable m_HorizontalFov = null;
void Awake()
{
tangoAPIConfig.enableMotionTracking = true;
tangoAPIConfig.enableColorCamera = true;
tangoAPIConfig.enableDepth = false;
if (TangoDevice.Connect(tangoAPIConfig))
TangoDevice.synchronizeFramerateWithColorCamera = false;
else
Debug.LogWarning(āTango failed to connect!ā);
}
protected Nullable GetCameraFov(ScreenOrientation screenOrientation)
{
if ((screenOrientation == ScreenOrientation.Portrait) ||
(screenOrientation == ScreenOrientation.PortraitUpsideDown))
{
if (m_HorizontalFov == null)
{
float fov;
if (TangoDevice.TryGetHorizontalFov(out fov))
m_HorizontalFov = fov;
}
return m_HorizontalFov;
}
else
{
if (m_VerticalFov == null)
{
float fov;
if (TangoDevice.TryGetVerticalFov(out fov))
m_VerticalFov = fov;
}
return m_VerticalFov;
}
}
protected virtual void SetCameraFov()
{
if (camera != null)
{
Nullable cameraFov = GetCameraFov(Screen.orientation);
if (cameraFov != null)
camera.fieldOfView = cameraFov.Value;
}
}
void OnDestroy()
{
TangoDevice.Disconnect();
}
void Update()
{
SetCameraFov();
}
}
Please reply to the thread if you have further questions.
-Best,
Mike Durand