Пример #1
0
        public void CreateSession(ARCoreSession sessionComponent)
        {
#if ARCORE_IOS_SUPPORT
            if (SessionComponent != null)
            {
                Debug.LogError("Multiple ARCore session components cannot exist in the scene. " +
                               "Destroying the newest.");
                GameObject.Destroy(sessionComponent);
                return;
            }

            m_RealArKitSessionHandle = _GetSessionHandleFromArkitPlugin();
            SessionComponent         = sessionComponent;

            var status = ExternApi.ArSession_create(m_CloudServicesApiKey, null, ref m_SessionHandle);
            if (status != ApiArStatus.Success)
            {
                Debug.LogErrorFormat("Could not create a cross platform ARCore session ({0}).", status);
                return;
            }

            NativeSession = new NativeSession(m_SessionHandle, IntPtr.Zero);
#else
            Debug.Log("ARCore iOS Support is not enabled. ARCore will be disabled on iOS device.");
            return;
#endif
        }
Пример #2
0
        public override void Install(bool reset)
        {
            base.Install(reset);

#if UNITY_EDITOR
            if (ARBackgroundMaterial == null || reset)
            {
                ARBackgroundMaterial = ResourceExt.EditorLoadAsset <Material>("Assets/GoogleARCore/SDK/Materials/ARBackground.mat");
            }
#endif

            if (arCoreSession == null)
            {
                arCoreSession = this.Ensure <ARCoreSession>().Value;
                arCoreSession.SessionConfig = ScriptableObject.CreateInstance <ARCoreSessionConfig>();
                arCoreSession.SessionConfig.MatchCameraFramerate = true;
            }

            if (bgRenderer == null)
            {
                bgRenderer = this.Ensure <ARCoreBackgroundRenderer>().Value;
                bgRenderer.BackgroundMaterial = ARBackgroundMaterial;
            }

            if (poseDriver == null)
            {
                poseDriver = this.Ensure <TrackedPoseDriver>().Value;
                poseDriver.SetPoseSource(TrackedPoseDriver.DeviceType.GenericXRDevice, TrackedPoseDriver.TrackedPose.ColorCamera);
                poseDriver.trackingType         = TrackedPoseDriver.TrackingType.RotationAndPosition;
                poseDriver.updateType           = TrackedPoseDriver.UpdateType.BeforeRender;
                poseDriver.UseRelativeTransform = true;
            }
        }
Пример #3
0
    /// <summary>
    /// Unity Start function.
    /// </summary>
    private void Start()
    {
        //Get the current ARCore session
        m_Session = ARSessionManager.Instance.GetSession();
        // Multiply it by scaleFactor
        m_Session.transform.localScale *= m_scaleFactor;

        //Initialize lists
        m_OldImages       = new List <AugmentedImage>();
        m_CurrFrameImages = new List <AugmentedImage>();
        m_Visualizers     = new List <ImageVisualizer>();

        //Set the device screen to never timeout
        //Screen.sleepTimeout = SleepTimeout.NeverSleep;

        //Initialize object pool of ImageVisualizers
        for (int i = 0; i < m_PoolStartingSize; i++)
        {
            //Create new instance of ImageVisualizer
            ImageVisualizer visualizer = Instantiate(m_ImageVisualizerPrefab);
            //Deactivate visualizer's gameobjec
            visualizer.gameObject.SetActive(false);

            //Add instance to object pool
            ObjectPool.Add(visualizer);
        }

        // Set Overlay Screen active
        m_FitToScanOverlay.SetActive(true);
    }
Пример #4
0
 private void Start()
 {
     _sessionA  = SessionDemoA.GetComponent <ARCoreSession>();
     _sessionB  = SessionDemoB.GetComponent <ARCoreSession>();
     _myConfigA = _sessionA.SessionConfig;
     _myConfigB = _sessionB.SessionConfig;
 }
Пример #5
0
        public void CreateSession(ARCoreSession sessionComponent)
        {
#if ARCORE_IOS_SUPPORT
            if (SessionComponent != null)
            {
                Debug.LogError("Multiple ARCore session components cannot exist in the scene. " +
                               "Destroying the newest.");
                GameObject.Destroy(sessionComponent);
                return;
            }

            SessionComponent        = sessionComponent;
            _realArKitSessionHandle = _arCoreiOSHelper.GetARKitSessionPtr();
            string apiKey = _arCoreiOSHelper.GetCloudServicesApiKey();
            var    status =
                ExternApi.ArSession_create(apiKey, null, ref _sessionHandle);
            if (status != ApiArStatus.Success)
            {
                Debug.LogErrorFormat(
                    "Could not create a cross platform ARCore session ({0}).", status);
                return;
            }

            NativeSession = new NativeSession(_sessionHandle, IntPtr.Zero);
            _arCoreiOSHelper.RegisterFrameUpdateEvent(_instance._OnARKitFrameUpdated);
#else
            Debug.Log("ARCore iOS Support is not enabled. ARCore will be disabled on iOS device.");
            return;
#endif
        }
Пример #6
0
 void DestroyARCore()
 {
     ARCoreSession.Destroy(anchor);
     ARCoreSession.DestroyImmediate(anchor);
     Soldier.SetActive(false);
     text.text += "anchor destroy";
 }
        /// <summary>
        /// Handles Instant Preview logic when ARCore's EarlyUpdate method is called.
        /// </summary>
        /// <param name="session">Relevant ARCoreSession object being updated.</param>
        public static void OnEarlyUpdate(ARCoreSession session)
        {
            if (Application.isEditor || session == null)
            {
                return;
            }

            if (!s_PauseWarned && !session.enabled)
            {
                Debug.LogWarning("Disabling ARCore session is not available in editor.");
                s_PauseWarned = true;
            }

            var config = session.SessionConfig;

            if (config == null)
            {
                return;
            }

            if (!s_DisabledLightEstimationWarned && !config.EnableLightEstimation)
            {
                Debug.LogWarning("ARCore light estimation cannot be disabled in editor.");
                s_DisabledLightEstimationWarned = true;
            }

            if (!s_DisabledPlaneFindingWarned && !config.EnablePlaneFinding)
            {
                Debug.LogWarning("ARCore plane finding cannot be disabled in editor.");
                s_DisabledPlaneFindingWarned = true;
            }
        }
    public void CreateSenseAR()
    {
        if (type == ReferenceImageType.Database && bCompleteReadingImageDatabase == false)
        {
            Debug.Log("CreateSenseAR Failed");
            return;
        }

        if (type == ReferenceImageType.Patt && bCompleteReadingConfig == false)
        {
            Debug.Log("CreateSenseAR Failed");
            return;
        }

        if (shotButton)
        {
            shotButton.gameObject.SetActive(true);
        }

        if (SenseARInstance == null)
        {
            SenseARInstance = (GameObject)Instantiate(SenseARBasePrefab, transform.position, transform.rotation);
            slamController  = GameObject.Find("SlamController").GetComponent <SenseARSLAMController>();
            updateTexture   = GameObject.Find("ARCamera").GetComponent <SenseARUpdateTexture>();
            session         = SenseARInstance.GetComponent <ARCoreSession>();
            database        = new ReferenceImageDatabase(Session.GetNativeSession());
            if (type == ReferenceImageType.SingleImage)
            {
                for (int i = 0; i < textures.Length; ++i)
                {
                    database.AddImage(textures[i].name, textures[i]);
                }
            }
            else if (type == ReferenceImageType.Patt)
            {
                database.LoadConfig(ConfigBuffer, ConfigBufferLength);
                for (int i = 0; i < patts.Length; ++i)
                {
                    database.AddPatt(PattsBuffer[i], PattsBufferLength[i]);
                }
            }
            else
            {
                database.Deserialize(ImageDatabaseBuffer, ImageDatabaseBufferLength);
            }
            session.SetReferenceImageDatabase(database);

            session.Connect();

            // display size return screen size when portrait mode
            //int ScreenWidth = 0, ScreenHeight = 0;
            //Session.GetNativeSession().SessionApi.GetDisplaySize(ref ScreenWidth, ref ScreenHeight);
        }

        if (AxisPrefab)
        {
            axisInstance = (GameObject)Instantiate(AxisPrefab, new Vector3(0, 0, 0), transform.rotation);
        }
    }
    /// <summary>
    /// Establish the initial configuration
    /// </summary>
    private void Awake()
    {
        ARCoreSession arCoreSession = GameObject.FindObjectOfType <ARCoreSession>();

        arCoreSession.SessionConfig = ARCoreSessionConfig;
        SpatialStoriesEventController.Instance.SpatialStoriesEvent += new SpatialStoriesEventHandler(OnSpatialStoriesEvent);
        if (FitToScanOverlay != null)
        {
            FitToScanOverlay.SetActive(true);
        }
    }
Пример #10
0
    IEnumerator AddNewArCoreSession()
    {
        ARCoreSession arCoreSession = GameObject.Find("ARCore Device").AddComponent <ARCoreSession>();

        arCoreSession.SessionConfig = Resources.Load <ARCoreSessionConfig>("DefaultSessionConfig");
        arCoreSession.enabled       = true;

        Session.GetTrackables(m_AllDetectedPlanes);
        Debug.LogWarning("trackable count after destroy is: " + m_AllDetectedPlanes.Count);
        yield break;
    }
Пример #11
0
 public void CreateSession(ARCoreSession sessionComponent)
 {
     sessionComponent.StartCoroutine(InstantPreviewManager.InitializeIfNeeded());
     if (SessionComponent != null)
     {
         Debug.LogError("Multiple ARCore session components cannot exist in the scene. " +
                        "Destroying the newest.");
         GameObject.Destroy(sessionComponent);
         return;
     }
     SessionComponent = sessionComponent;
 }
Пример #12
0
    /// <summary>
    /// Resumes the AR session, if paused.
    /// </summary>
    public override void ResumeSession()
    {
        if (arCoreDeviceObj)
        {
            ARCoreSession arCoreSession = arCoreDeviceObj.GetComponent <ARCoreSession>();

            if (arCoreSession)
            {
                arCoreSession.enabled = true;
            }
        }
    }
Пример #13
0
    public void ResetTracking()
    {
        ARCoreSession            session            = device.GetComponent <ARCoreSession>();
        ARCoreSessionConfig      sessionConfig      = session.SessionConfig;
        ARCoreCameraConfigFilter cameraConfigFilter = session.CameraConfigFilter;

        DestroyImmediate(session);
        session = device.AddComponent <ARCoreSession>();
        session.SessionConfig      = sessionConfig;
        session.CameraConfigFilter = cameraConfigFilter;
        session.enabled            = true;
    }
Пример #14
0
    public void LoadDemoB()
    {
        UIMainMenu.SetActive(false);
        DemoB.SetActive(true);
        UIDemoB.SetActive(true);

        if (_sessionB == null)
        {
            _sessionB = SessionDemoB.AddComponent <ARCoreSession>();
            _sessionB.SessionConfig = _myConfigB;
            _sessionB.enabled       = true;
        }
    }
Пример #15
0
        public void CreateSession(ARCoreSession sessionComponent)
        {
            if (SessionComponent != null)
            {
                Debug.LogError("Multiple ARCore session components cannot exist in the scene. " +
                               "Destroying the newest.");
                GameObject.Destroy(sessionComponent);
                return;
            }

            m_RealArKitSessionHandle = _GetSessionHandleFromArkitPlugin();
            SessionComponent         = sessionComponent;
            EnableSession();
        }
Пример #16
0
        public void CreateSession(ARCoreSession session)
        {
            session.StartCoroutine(InstantPreviewManager.InitializeIfNeeded());

            if (m_SessionComponent != null)
            {
                //Debug.LogError("Multiple session components cannot exist in the scene. " +
                //"Destroying the newest.");
                //GameObject.Destroy(session);
                //return;
            }

            m_SessionComponent = session;
            EnableSession();
        }
Пример #17
0
    IEnumerator DeleteArCoreSession()
    {
        ARCoreSession arCoreSession = GameObject.Find("ARCore Device").GetComponent <ARCoreSession>();

        Debug.Log(arCoreSession);

        Session.GetTrackables(m_AllDetectedPlanes);

        Debug.LogWarning("trackable count is: " + m_AllDetectedPlanes.Count);

        m_AllDetectedPlanes.Clear();
        DestroyImmediate(arCoreSession);

        yield break;
    }
Пример #18
0
        private void PerformArCoreRaycast()
        {
            m_arCoreSession = GameObject.FindObjectOfType <ARCoreSession>();

            if (m_arCoreSession != null)
            {
                if (m_arCoreSession.SessionConfig.PlaneFindingMode != DetectedPlaneFindingMode.Disabled)
                {
                    PerformArCoreRaycastPlane();
                }
                if (m_arCoreSession.SessionConfig.AugmentedImageDatabase != null)
                {
                    PerformArCoreImageRecognition();
                }
            }
        }
Пример #19
0
    /// <summary>
    /// Destroys the current session and re-instantiates a new instance of the session.
    /// </summary>
    IEnumerator CreateNewSession()
    {
        //Disable session and destroy the holding gameobject
        m_arSession.enabled = false;
        if (m_sessionObject != null)
        {
            Destroy(m_sessionObject);
        }

        yield return(new WaitForEndOfFrame());

        //Create new session
        m_sessionObject     = Instantiate(m_arCoreSessionPrefab);
        m_arSession         = m_sessionObject.GetComponent <ARCoreSession>();
        m_arSession.enabled = true;
    }
Пример #20
0
    /// <summary>
    /// Pauses the AR session.
    /// </summary>
    /// <returns><c>true</c>, if session was paused, <c>false</c> if pausing AR session is not supported.</returns>
    public override bool PauseSession()
    {
        if (arCoreDeviceObj)
        {
            ARCoreSession arCoreSession = arCoreDeviceObj.GetComponent <ARCoreSession>();

            if (arCoreSession)
            {
                arCoreSession.enabled = false;
            }

            return(true);
        }

        return(false);
    }
Пример #21
0
    IEnumerator _RestartSession()
    {
        console4.text = "세션 재시작";
        ARCoreSession       session  = ARCoreDevice.GetComponent <ARCoreSession>();
        ARCoreSessionConfig myConfig = session.SessionConfig;

        //DestroyImmediate(session);
        Destroy(session);

        yield return(null);

        session = ARCoreDevice.AddComponent <ARCoreSession>();
        session.SessionConfig = myConfig;
        session.enabled       = true;
        dataBaseIndex.Clear();
        callCount = 0;
    }
Пример #22
0
    void DisableTracking()
    {
        TrackedPoseDriver tpd                 = GetComponent <TrackedPoseDriver>();
        ARCoreSession     session             = GetComponent <ARCoreSession>();
        InstantPreviewTrackedPoseDriver iptpd = GetComponent <InstantPreviewTrackedPoseDriver>();

        if (tpd)
        {
            tpd.enabled = false;
        }
        if (session)
        {
            session.enabled = false;
        }
        if (iptpd)
        {
            iptpd.enabled = false;
        }
        tracking = false;
        Debug.Log("Tracking Disabled");
    }
Пример #23
0
        private static Dictionary <ARCoreSessionConfig, string> GetAllSessionConfigs()
        {
            Dictionary <ARCoreSessionConfig, string> sessionToPathMap =
                new Dictionary <ARCoreSessionConfig, string>();

            EditorBuildSettingsScene[] scenes = EditorBuildSettings.scenes;
            foreach (EditorBuildSettingsScene editorScene in EditorBuildSettings.scenes)
            {
                if (editorScene.enabled)
                {
                    Scene scene = SceneManager.GetSceneByPath(editorScene.path);
                    if (!scene.isLoaded)
                    {
                        scene = EditorSceneManager.OpenScene(
                            editorScene.path, OpenSceneMode.Additive);
                    }

                    foreach (GameObject gameObject in scene.GetRootGameObjects())
                    {
                        ARCoreSession sessionComponent =
                            (ARCoreSession)gameObject.GetComponentInChildren(
                                typeof(ARCoreSession));
                        if (sessionComponent != null)
                        {
                            if (!sessionToPathMap.ContainsKey(sessionComponent.SessionConfig))
                            {
                                sessionToPathMap.Add(
                                    sessionComponent.SessionConfig, editorScene.path);
                            }

                            break;
                        }
                    }
                }
            }

            return(sessionToPathMap);
        }
Пример #24
0
    private void Start()
    {
        //Get current session from session manager
        m_arSession = ARSessionManager.Instance.GetSession();
        //Initialise lists
        m_trackedImages           = new List <AugmentedImage>();
        m_listOfVisualizedObjects = new List <ARImageVisualiser>();
        //Set screen to never timeout
        Screen.sleepTimeout = SleepTimeout.NeverSleep;

        //Create Object Pool for ARImageVisualiser
        for (int i = 0; i < m_objectPoolStartSize; i++)
        {
            //Create instance of visualizer
            GameObject visualizerObject = Instantiate(m_arVisualizerPrefab);
            visualizerObject.SetActive(false);
            //Get component
            ARImageVisualiser visualizer = visualizerObject.GetComponent <ARImageVisualiser>();

            //Add to object pool
            ObjectPool.Add(visualizer);
        }
    }
Пример #25
0
        public override IEnumerator StartService(Settings settings)
        {
            if (m_ARCoreSessionConfig == null)
            {
                m_ARCoreSessionConfig = ScriptableObject.CreateInstance <ARCoreSessionConfig>();
            }

            m_ARCoreSessionConfig.EnableLightEstimation = settings.enableLightEstimation;
            m_ARCoreSessionConfig.PlaneFindingMode      = DetectedPlaneFindingMode.HorizontalAndVertical;
            //Do we want to match framerate to the camera?
            m_ARCoreSessionConfig.MatchCameraFramerate = true;

            // Create a GameObject on which the session component will live.
            if (m_ARCoreSession == null)
            {
                var go = new GameObject("ARCore Session");
                go.SetActive(false);
                m_ARCoreSession = go.AddComponent <ARCoreSession>();
                m_ARCoreSession.SessionConfig = m_ARCoreSessionConfig;
                go.SetActive(true);
            }

            // Enabling the session triggers the connection
            m_ARCoreSession.SessionConfig = m_ARCoreSessionConfig;
            m_ARCoreSession.enabled       = true;

            if (!IsSupported)
            {
                switch (Session.Status)
                {
                case SessionStatus.ErrorApkNotAvailable:
                    Debug.LogError("ARCore APK is not installed");
                    yield break;

                case SessionStatus.ErrorPermissionNotGranted:
                    Debug.LogError("A needed permission (likely the camera) has not been granted");
                    yield break;

                case SessionStatus.ErrorSessionConfigurationNotSupported:
                    Debug.LogError("The given ARCore session configuration is not supported on this device");
                    yield break;

                case SessionStatus.FatalError:
                    Debug.LogError("A fatal error was encountered trying to start the ARCore session");
                    yield break;
                }
            }

            while (!Session.Status.IsValid())
            {
                IsRunning = false;

                if (Session.Status.IsError())
                {
                    switch (Session.Status)
                    {
                    case SessionStatus.ErrorPermissionNotGranted:
                        Debug.LogError("A needed permission (likely the camera) has not been granted");
                        yield break;

                    case SessionStatus.FatalError:
                        Debug.LogError("A fatal error was encountered trying to start the ARCore session");
                        yield break;
                    }
                }

                yield return(null);
            }

            // If we make it out of the while loop, then the session is initialized and valid
            IsRunning = true;

            if (IsRunning)
            {
                TextureReader_create((int)k_ImageFormatType, k_ARCoreTextureWidth, k_ARCoreTextureHeight, true);
            }
        }
Пример #26
0
    //void Start()
    //{
    //    this.StartSession();
    //}

    //[Tooltip("A scriptable object specifying the ARCore session configuration.")]
    // public ARCoreSessionConfig SessionConfig;

    //public void StartSession()
    //{
    //    ARCoreSession session = this.goARCoreDevice.AddComponent<ARCoreSession>();
    //    session.SessionConfig = this.SessionConfig;
    //    LifecycleManager.Instance.CreateSession(this.goARCoreDevice.GetComponent<ARCoreSession>());
    //    LifecycleManager.Instance.EnableSession();

    //    LifecycleManager.Instance.
    //}

    public void Dest()
    {
        ARCoreSession session = this.goARCoreDevice.GetComponent <ARCoreSession>();

        DestroyImmediate(session);
    }
Пример #27
0
 void Start()
 {
     _sesion = ArCoreDevice.GetComponent <ARCoreSession>();
 }
Пример #28
0
 public void DestroySession()
 {
     m_SessionComponent = null;
 }
Пример #29
0
    // initializes the AR-Core components
    private void InitArCore()
    {
        //Debug.Log("InitArCore started.");

        // disable the main camera, if any
        Camera currentCamera = MultiARInterop.GetMainCamera();

        if (currentCamera)
        {
            currentCamera.gameObject.SetActive(false);
        }

        // create ARCore-Device in the scene
        arCoreDeviceObj      = Instantiate(arCoreDevicePrefab, Vector3.zero, Quaternion.identity);
        arCoreDeviceObj.name = "ARCore Device";
        DontDestroyOnLoad(arCoreDeviceObj);

        // get background material
        arCodeRenderer = FindObjectOfType <ARCoreBackgroundRenderer>();
        if (arCodeRenderer)
        {
            backgroundMat = arCodeRenderer.BackgroundMaterial;
        }

        // update the session config, if needed
        ARCoreSession arSession = arCoreDeviceObj.GetComponent <ARCoreSession>();

        if (arSession != null && arSession.SessionConfig != null && arImageDatabase != null)
        {
            arSession.SessionConfig.AugmentedImageDatabase = arImageDatabase;
        }

        // reference to the AR main camera
        mainCamera = arCoreDeviceObj.GetComponentInChildren <Camera>();

//		// disable directional light, if any
//		Light currentLight = MultiARInterop.GetDirectionalLight();
//		if(currentLight)
//		{
//			currentLight.gameObject.SetActive(false);
//		}
//
//		// create AR environmental light
//		GameObject envLight = new GameObject("Evironmental Light");
//		//envLight.transform.position = Vector3.zero;
//		//envLight.transform.rotation = Quaternion.identity;
//		envLight.AddComponent<EnvironmentalLight>();
//
//		// reference to the AR directional light
//		//directionalLight = envLight.GetComponent<Light>();

        // modify the directional light
        Light currentLight = MultiARInterop.GetDirectionalLight();

        if (!currentLight)
        {
            GameObject currentLightObj = new GameObject("Directional light");

            currentLight      = currentLightObj.AddComponent <Light>();
            currentLight.type = LightType.Directional;
        }

        // reset light position & rotation
        currentLight.transform.position = Vector3.zero;
        currentLight.transform.rotation = Quaternion.Euler(40f, 40f, 0f);
        DontDestroyOnLoad(currentLight.gameObject);

        // set light parameters
        //currentLight.lightmapBakeType = LightmapBakeType.Mixed;
        currentLight.color = new Color32(255, 254, 244, 255);

        // add the ar-light component
        currentLight.gameObject.AddComponent <MultiARDirectionalLight>();

        // get ar-data
        MultiARInterop.MultiARData arData = arManager ? arManager.GetARData() : null;

        if (arManager && arManager.usePointCloudData)
        {
            arData.pointCloudData      = new Vector3[MultiARInterop.MAX_POINT_COUNT];
            arData.pointCloudLength    = 0;
            arData.pointCloudTimestamp = 0.0;
        }

        // create surface renderer
        if (arManager && arData != null)
        {
            arData.surfaceRendererRoot      = new GameObject();
            arData.surfaceRendererRoot.name = "SurfaceRenderer";
            DontDestroyOnLoad(arData.surfaceRendererRoot);
        }

        // interface is initialized
        isInitialized = true;

        //Debug.Log("InitArCore finished.");
    }
Пример #30
0
 public void DestroySession()
 {
     m_SessionComponent = null;
     m_NativeSession    = null;
     ExternApi.ArPresto_reset();
 }