Ejemplo n.º 1
0
        public void ToggleARMatteMode(bool active)
        {
            ARScreen arkitScreen = Camera.main.gameObject.GetComponent <ARScreen>();

            if (arkitScreen == null)
            {
                return;
            }

            if (arCoverSphere != null)
            {
                arCoverSphere.SetActive(active);
            }

            if (active)
            {
                if (matteMaterial != null)
                {
                    matteMaterial.SetTexture("_textureY", arkitScreen.m_ClearMaterial.GetTexture("_textureY"));
                    matteMaterial.SetTexture("_textureCbCr", arkitScreen.m_ClearMaterial.GetTexture("_textureCbCr"));
                    matteMaterial.SetMatrix("_DisplayTransform", arkitScreen.m_ClearMaterial.GetMatrix("_DisplayTransform"));
                }
            }
            else
            {
                if (matteMaterial != null)
                {
                    matteMaterial.SetTexture("_textureY", null);
                    matteMaterial.SetTexture("_textureCbCr", null);
                    // matteMaterial.SetMatrix("_DisplayTransform", arkitScreen.m_ClearMaterial.GetMatrix("_DisplayTransform"));
                }
            }
        }
Ejemplo n.º 2
0
        public void ToggleARKeyMode(bool active)
        {
            ARScreen arkitScreen = Camera.main.gameObject.GetComponent <ARScreen>();

            if (arkitScreen == null)
            {
                return;
            }

            Shader shader = Shader.Find("VPET/ARCameraShader");

            if (active)
            {
                shader = Shader.Find("VPET/ARCameraShaderChromaKey");
            }

            if (shader)
            {
                arkitScreen.m_ClearMaterial.shader = shader;
            }
        }
Ejemplo n.º 3
0
        public void ToggleArMode(bool active)
        {
            arMode = active;
            ui.setupSecondaryMenu();
#if USE_ARKIT
            GameObject root           = GameObject.Find("Scene");
            GameObject arPlanes       = GameObject.Find("ARPlanes");
            GameObject arKit          = GameObject.Find("ARKit");
            TouchInput input          = inputAdapter.GetComponent <TouchInput>();
            GameObject arConfigWidget = GameObject.Find("GUI/Canvas/ARConfigWidget");
            GameObject rootScene      = SceneLoader.scnRoot;

            if (m_anchorPrefab == null)
            {
                m_anchorPrefab = Resources.Load("VPET/Prefabs/AnchorModifier", typeof(GameObject)) as GameObject;
            }

            if (input)
            {
                input.enabled = !active;
            }
#endif
            if (active)
            {
#if USE_TANGO
                sceneAdapter.HideGeometry();
                tangoApplication.m_enableVideoOverlay           = true;
                tangoApplication.m_videoOverlayUseTextureMethod = true;
                TangoARScreen tangoArScreen = Camera.main.gameObject.GetComponent <TangoARScreen>();
                if (tangoArScreen == null)
                {
                    tangoArScreen = Camera.main.gameObject.AddComponent <TangoARScreen>();
                }
                tangoArScreen.enabled = true;
#elif USE_ARKIT
                //avoids object updates while placing, scaling, rotating scene in AR setup
                lockScene = true;
                // reset camera
                cameraAdapter.globalCameraReset();
                //resetCameraOffset();
                Camera.main.transform.position = Vector3.zero;
                Camera.main.transform.rotation = Quaternion.identity;
                //Camera.main.fieldOfView = 60;
                //Camera.main.nearClipPlane = 0.1f;
                //Camera.main.farClipPlane = 100000;
                // enable video background

                ARScreen arkitScreen = Camera.main.gameObject.GetComponent <ARScreen>();
                if (arkitScreen == null)
                {
                    arkitScreen = Camera.main.gameObject.AddComponent <ARScreen>();
                }

                if (arKit)
                {
                    ARKitController arController = arKit.GetComponent <ARKitController>();
                    if (arController)
                    {
                        arController.setARMode(true);
                    }
                }

                // enable plane alignment
                if (root)
                {
                    ARPlaneAlignment hitTest = root.GetComponent <ARPlaneAlignment>();
                    if (hitTest == null)
                    {
                        hitTest = root.AddComponent <ARPlaneAlignment>();
                        hitTest.m_HitTransform = root.transform;
                    }
                }
                // enable plane visualisation
                if (arPlanes)
                {
                    ARPlane arPlaneComponent = arPlanes.GetComponent <ARPlane>();
                    if (arPlaneComponent == null)
                    {
                        arPlaneComponent = arPlanes.AddComponent <ARPlane>();
                    }
                }
                // create anchor modifier
                if (m_anchorModifier == null)
                {
                    m_anchorModifier = GameObject.Instantiate(m_anchorPrefab);
                    m_anchorModifier.transform.position = Vector3.zero;
                    m_anchorModifier.layer = LayerMask.NameToLayer("RenderInFront");
                    foreach (Transform child in m_anchorModifier.transform)
                    {
                        child.gameObject.layer = 8;
                    }
                    m_anchorModifier.transform.localScale = Vector3.zero;
                    m_anchorModifier.name = "ARModifier";
                    if (root)
                    {
                        m_anchorModifier.transform.SetParent(root.transform, false);
                    }
                }
                ui.hideConfigWidget();
                //hide scene while placing AR anchor
                //rootScene.SetActive(false);
                arConfigWidget.SetActive(true);
                SetSceneScale(VPETSettings.Instance.sceneScale);
                //arConfigWidget.transform.Find("scale_value").GetComponent<Text>().text;

                //initalize ar lock buttons
                ui.changeARLockRotationButtonImage(lockARRotation);
                ui.changeARLockScaleButtonImage(lockARScale);
#endif
            }
            else
            {
#if USE_TANGO
                Camera.main.gameObject.GetComponent <TangoARScreen>().enabled = false;
                GameObject.Destroy(Camera.main.GetComponent <TangoARScreen>());
                tangoApplication.m_enableVideoOverlay = false;
#elif USE_ARKIT
                if (arKit)
                {
                    ARKitController arController = arKit.GetComponent <ARKitController>();
                    if (arController)
                    {
                        arController.setARMode(false);
                    }
                }
                // destroy video background
                GameObject.Destroy(Camera.main.GetComponent <ARScreen>());
                if (root)
                {
                    GameObject.Destroy(root.GetComponent <ARPlaneAlignment>());
                }
                // destroy plane visualisation
                if (arPlanes)
                {
                    GameObject.Destroy(arPlanes.GetComponent <ARPlane>());
                }
                // disable anchor visualisation
                if (m_anchorModifier)
                {
                    m_anchorModifier.SetActive(false);
                    GameObject.Destroy(m_anchorModifier);
                    m_anchorModifier = null;
                }
#endif
                // reset cameras to defaults
                Camera.main.ResetProjectionMatrix();
                SetSceneScale(1f);
                repositionCamera();
                UpdateProjectionMatrixSecondaryCameras();
                sceneAdapter.ShowGeometry();
            }

            hasUpdatedProjectionMatrix = true;
        }