예제 #1
0
        void InitializeARKit(serializableARKitInit sai)
        {
                        #if !UNITY_EDITOR
            //get the config and runoption from editor and use them to initialize arkit on device
            //added Sascha Gehlich's modifications to this method bc this seemed to help with the framerate issues
            Application.targetFrameRate = 60;
            m_session = UnityARSessionNativeInterface.GetARSessionNativeInterface();
            ARKitWorldTrackingSessionConfiguration config = sai.config;
            UnityARSessionRunOption runOptions            = sai.runOption;

            UnityARSessionNativeInterface session = UnityARSessionNativeInterface.GetARSessionNativeInterface();

            config.planeDetection = UnityARPlaneDetection.Horizontal;
            var videoFormat = UnityARVideoFormat.SupportedVideoFormats()[UnityARVideoFormat.SupportedVideoFormats().Count - 1];
            config.videoFormat          = videoFormat.videoFormatPtr;
            Application.targetFrameRate = videoFormat.framesPerSecond;

            m_session.RunWithConfigAndOptions(config, runOptions);

            UnityARSessionNativeInterface.ARFrameUpdatedEvent  += ARFrameUpdated;
            UnityARSessionNativeInterface.ARAnchorAddedEvent   += ARAnchorAdded;
            UnityARSessionNativeInterface.ARAnchorUpdatedEvent += ARAnchorUpdated;
            UnityARSessionNativeInterface.ARAnchorRemovedEvent += ARAnchorRemoved;
                        #endif
        }
예제 #2
0
        void InitializeARKit(serializableARKitInit sai)
        {
            //#if !UNITY_EDITOR

            //get the config and runoption from editor and use them to initialize arkit on device
            Application.targetFrameRate = 60;
            m_session = UnityARSessionNativeInterface.GetARSessionNativeInterface();
            ARKitWorldTrackingSessionConfiguration config = sai.config;

            if (detectionImages != null)
            {
                config.arResourceGroupName = detectionImages.resourceGroupName;
            }

            UnityARSessionRunOption runOptions = sai.runOption;

            m_session.RunWithConfigAndOptions(config, runOptions);

            UnityARSessionNativeInterface.ARFrameUpdatedEvent += ARFrameUpdated;
            //UnityARSessionNativeInterface.ARAnchorAddedEvent += ARAnchorAdded;
            //UnityARSessionNativeInterface.ARAnchorUpdatedEvent += ARAnchorUpdated;
            //UnityARSessionNativeInterface.ARAnchorRemovedEvent += ARAnchorRemoved;

            //#endif
        }
예제 #3
0
        void OnGUI()
        {
            if (GUI.Button(new Rect(100, 100, 200, 50), "Stop"))
            {
                UnityARSessionNativeInterface.GetARSessionNativeInterface().Pause();
            }
            if (GUI.Button(new Rect(300, 100, 200, 50), "Start"))
            {
                ARKitWorldTrackingSessionConfiguration sessionConfig = new ARKitWorldTrackingSessionConfiguration(alignmentOptions [currentAlignmentIndex], planeOptions[currentPlaneIndex]);
                UnityARSessionNativeInterface.GetARSessionNativeInterface().RunWithConfigAndOptions(sessionConfig, runOptions[currentOptionIndex]);
            }
            if (GUI.Button(new Rect(100, 300, 200, 100), "Start Non-WT Session"))
            {
                ARKitSessionConfiguration sessionConfig = new ARKitSessionConfiguration(alignmentOptions [currentAlignmentIndex], true, true);
                UnityARSessionNativeInterface.GetARSessionNativeInterface().RunWithConfig(sessionConfig);
            }
            string runOptionStr = (currentOptionIndex == 0 ? "Full" : (currentOptionIndex == 1 ? "Tracking" : (currentOptionIndex == 2 ? "Anchors" : "None")));

            if (GUI.Button(new Rect(100, 200, 150, 50), "RunOption:" + runOptionStr))
            {
                currentOptionIndex = (currentOptionIndex + 1) % 4;
            }
            string alignmentOptionStr = (currentAlignmentIndex == 0 ? "Camera" : (currentAlignmentIndex == 1 ? "Gravity" :  "GravityAndHeading"));

            if (GUI.Button(new Rect(300, 200, 150, 50), "AlignOption:" + alignmentOptionStr))
            {
                currentAlignmentIndex = (currentAlignmentIndex + 1) % 3;
            }
            string planeOptionStr = currentPlaneIndex == 0 ? "Horizontal" :  "None";

            if (GUI.Button(new Rect(500, 200, 150, 50), "PlaneOption:" + planeOptionStr))
            {
                currentPlaneIndex = (currentPlaneIndex + 1) % 2;
            }
        }
예제 #4
0
        /// <summary>
        /// 开启ARKit功能
        /// </summary>
        /// <param name="_notif"></param>
        private void TurnOnARKit(Anywhere.Notification _notif)
        {
            ARKitWorldTrackingSessionConfiguration sessionConfig = new ARKitWorldTrackingSessionConfiguration(alignmentOptions[currentAlignmentIndex], planeOptions[currentPlaneIndex], true, false);

            UnityARSessionNativeInterface.GetARSessionNativeInterface().RunWithConfigAndOptions(sessionConfig, runOptions[currentOptionIndex]);
            Anywhere.NotifCenter.GetNotice.PostDispatchEvent(Anywhere.NotifEventKey.ARKIT_FOCUS_ON);
            Anywhere.NotifCenter.GetNotice.PostDispatchEvent(Anywhere.NotifEventKey.ARKIT_CREATEARANCHOR);
        }
        public void RunWithConfigAndOptions(ARKitWorldTrackingSessionConfiguration config, UnityARSessionRunOption runOptions)
        {
#if !UNITY_EDITOR && UNITY_IOS
            StartWorldTrackingSessionWithOptions(m_NativeARSession, config, runOptions);
#elif UNITY_EDITOR
            CreateRemoteWorldTrackingConnection(config, runOptions);
#endif
        }
 public void RunWithConfigAndOptions(ARKitWorldTrackingSessionConfiguration config, UnityARSessionRunOption runOptions)
 {
     config.alignment = UnityARAlignment.UnityARAlignmentGravityAndHeading;
                 #if !UNITY_EDITOR
     StartWorldTrackingSessionWithOptions(m_NativeARSession, config, runOptions);
                 #else
     CreateRemoteWorldTrackingConnection(config, runOptions);
                 #endif
 }
        public void RunWithConfigAndImage(ARKitWorldTrackingSessionConfiguration config, int a_BufferLength, byte[] a_ImageBuffer, float width)
        {
#if !UNITY_EDITOR
            StartWorldTrackingSessionWithImage(m_NativeARSession, config, a_BufferLength, a_ImageBuffer, width);
#else
            UnityARSessionRunOption runOptions = UnityARSessionRunOption.ARSessionRunOptionRemoveExistingAnchors | UnityARSessionRunOption.ARSessionRunOptionResetTracking;
            CreateRemoteWorldTrackingConnection(config, runOptions);
#endif
        }
        public void RunWithConfig(ARKitWorldTrackingSessionConfiguration config)
        {
#if !UNITY_EDITOR && UNITY_IOS
            StartWorldTrackingSession(m_NativeARSession, config);
#elif UNITY_EDITOR
            UnityARSessionRunOption runOptions = UnityARSessionRunOption.ARSessionRunOptionRemoveExistingAnchors | UnityARSessionRunOption.ARSessionRunOptionResetTracking;
            CreateRemoteWorldTrackingConnection(config, runOptions);
#endif
        }
 public void RunWithConfig(ARKitWorldTrackingSessionConfiguration config)
 {
     config.alignment = UnityARAlignment.UnityARAlignmentGravityAndHeading;
                 #if !UNITY_EDITOR
     StartWorldTrackingSession(m_NativeARSession, config);
                 #else
     UnityARSessionRunOption runOptions = UnityARSessionRunOption.ARSessionRunOptionRemoveExistingAnchors | UnityARSessionRunOption.ARSessionRunOptionResetTracking;
     CreateRemoteWorldTrackingConnection(config, runOptions);
                 #endif
 }
예제 #10
0
        public void PlaneDetectionOFF()
        {
            planeDetection = UnityARPlaneDetection.None;
            ARKitWorldTrackingSessionConfiguration config = new ARKitWorldTrackingSessionConfiguration();

            config.planeDetection        = planeDetection;
            config.alignment             = startAlignment;
            config.getPointCloudData     = false;
            config.enableLightEstimation = false;
            UnityARSessionNativeInterface.GetARSessionNativeInterface().RunWithConfig(config);
        }
        private static void CreateRemoteWorldTrackingConnection(ARKitWorldTrackingSessionConfiguration config, UnityARSessionRunOption runOptions)
        {
            GameObject            go      = new GameObject("ARKitWorldTrackingRemoteConnection");
            ARKitRemoteConnection addComp = go.AddComponent <ARKitRemoteConnection>();

            addComp.planeDetection        = config.planeDetection;
            addComp.startAlignment        = config.alignment;
            addComp.getPointCloud         = config.getPointCloudData;
            addComp.enableLightEstimation = config.enableLightEstimation;
            addComp.resetTracking         = (runOptions & UnityARSessionRunOption.ARSessionRunOptionResetTracking) != 0;
            addComp.removeExistingAnchors = (runOptions & UnityARSessionRunOption.ARSessionRunOptionRemoveExistingAnchors) != 0;
        }
예제 #12
0
        private void InitializeARKit(serializableARKitInit sai)
        {
            Application.targetFrameRate = 60;
            m_session = UnityARSessionNativeInterface.GetARSessionNativeInterface();
            ARKitWorldTrackingSessionConfiguration config = sai.config;
            UnityARSessionRunOption runOption             = sai.runOption;

            m_session.RunWithConfigAndOptions(config, runOption);
            UnityARSessionNativeInterface.ARFrameUpdatedEvent  += ARFrameUpdated;
            UnityARSessionNativeInterface.ARAnchorAddedEvent   += ARAnchorAdded;
            UnityARSessionNativeInterface.ARAnchorUpdatedEvent += ARAnchorUpdated;
            UnityARSessionNativeInterface.ARAnchorRemovedEvent += ARAnchorRemoved;
        }
예제 #13
0
 private void LockDectingPlane(string command)
 {
     if (command == "lock")
     {
         UnityARSessionNativeInterface          m_session      = UnityARSessionNativeInterface.GetARSessionNativeInterface();
         UnityARPlaneDetection                  planeDetection = UnityARPlaneDetection.None;
         ARKitWorldTrackingSessionConfiguration config         = new ARKitWorldTrackingSessionConfiguration();
         config.planeDetection        = planeDetection;
         config.alignment             = UnityARAlignment.UnityARAlignmentGravity;
         config.getPointCloudData     = false;
         config.enableLightEstimation = false;
         m_session.RunWithConfig(config);
     }
 }
예제 #14
0
        void InitializeARKit(serializableARKitInit sai)
        {
                        #if !UNITY_EDITOR
            //get the config and runoption from editor and use them to initialize arkit on device
            Application.targetFrameRate = 120;
            m_session = UnityARSessionNativeInterface.GetARSessionNativeInterface();
            ARKitWorldTrackingSessionConfiguration config = sai.config;
            UnityARSessionRunOption runOptions            = sai.runOption;
            m_session.RunWithConfigAndOptions(config, runOptions);

            UnityARSessionNativeInterface.ARFrameUpdatedEvent  += ARFrameUpdated;
            UnityARSessionNativeInterface.ARAnchorAddedEvent   += ARAnchorAdded;
            UnityARSessionNativeInterface.ARAnchorUpdatedEvent += ARAnchorUpdated;
            UnityARSessionNativeInterface.ARAnchorRemovedEvent += ARAnchorRemoved;
                        #endif
        }
        // The main camera is surrounded by a SphereCollider with IsTrigger set to On
        void OnTriggerEnter(Collider portal)
        {
            Portal logic = portal.GetComponentInParent <Portal> ();

            transform.position = logic.PortalCameras[1].transform.position - GetComponentInChildren <Camera>().transform.localPosition;


            if (logic.name == "VRDoor")
            {
                doorToReality.transform.position = new Vector3(-0.97f, 200.968f, 0.33f);
                doorToReality.transform.rotation = Quaternion.LookRotation(Vector3.ProjectOnPlane(doorToReality.transform.position - mainCamera.transform.position, Vector3.up));
                doorToReality.GetComponentInParent <Portal> ().Source.transform.localPosition = doorToReality.transform.position;
                hittest.SetActive(false);
                logic.gameObject.SetActive(false);
            }

            if (logic.name == "VRDoor2")
            {
                doorToReality.transform.position = new Vector3(8.83f, 904.77f, 4.0f);
                doorToReality.transform.rotation = Quaternion.LookRotation(Vector3.ProjectOnPlane(doorToReality.transform.position - mainCamera.transform.position, Vector3.up));
                doorToReality.GetComponentInParent <Portal> ().Source.transform.localPosition = doorToReality.transform.position;

                portalcamera2.SetActive(false);
                hittest.SetActive(false);

                logic.gameObject.SetActive(false);
            }

            if (logic.name == "RealWorldDoor")
            {
                hittest.SetActive(true);
                ARKitWorldTrackingSessionConfiguration sessionConfig = new ARKitWorldTrackingSessionConfiguration(UnityARAlignment.UnityARAlignmentGravity, UnityARPlaneDetection.Horizontal);
                UnityARSessionNativeInterface.GetARSessionNativeInterface().RunWithConfigAndOptions(sessionConfig, UnityARSessionRunOption.ARSessionRunOptionRemoveExistingAnchors | UnityARSessionRunOption.ARSessionRunOptionResetTracking);
            }


            if (OnPortalTransition != null)
            {
                // Emit a static OnPortalTransition event every time the camera enters a portal. The DoorManager listens for this event.
                OnPortalTransition();
            }
        }
예제 #16
0
        void InitializeARKit(serializableARKitInit sai)
        {
                        #if !UNITY_EDITOR
            //get the config and runoption from editor and use them to initialize arkit on device
            Application.targetFrameRate = 60;
            m_session = UnityARSessionNativeInterface.GetARSessionNativeInterface();
            ARKitWorldTrackingSessionConfiguration config = sai.config;
            UnityARSessionRunOption runOptions            = sai.runOption;

            //potentially improves framerate?
            //https://bitbucket.org/Unity-Technologies/unity-arkit-plugin/issues/78/remote-very-low-fps-and-repeated

            UnityARSessionNativeInterface session = UnityARSessionNativeInterface.GetARSessionNativeInterface();
            config.planeDetection = UnityARPlaneDetection.Horizontal;
            var videoFormat = UnityARVideoFormat.SupportedVideoFormats()[UnityARVideoFormat.SupportedVideoFormats().Count - 1];
            config.videoFormat          = videoFormat.videoFormatPtr;
            Application.targetFrameRate = videoFormat.framesPerSecond;

            m_session.RunWithConfigAndOptions(config, runOptions);

            UnityARSessionNativeInterface.ARFrameUpdatedEvent  += ARFrameUpdated;
            UnityARSessionNativeInterface.ARAnchorAddedEvent   += ARAnchorAdded;
            UnityARSessionNativeInterface.ARAnchorUpdatedEvent += ARAnchorUpdated;
            UnityARSessionNativeInterface.ARAnchorRemovedEvent += ARAnchorRemoved;
                        #endif
            // #if !UNITY_EDITOR
            // //get the config and runoption from editor and use them to initialize arkit on device
            // Application.targetFrameRate = 60;
            // m_session = UnityARSessionNativeInterface.GetARSessionNativeInterface();
            // ARKitWorldTrackingSessionConfiguration config = sai.config;
            // UnityARSessionRunOption runOptions = sai.runOption;
            // m_session.RunWithConfigAndOptions(config, runOptions);

            // UnityARSessionNativeInterface.ARFrameUpdatedEvent += ARFrameUpdated;
            // UnityARSessionNativeInterface.ARAnchorAddedEvent += ARAnchorAdded;
            // UnityARSessionNativeInterface.ARAnchorUpdatedEvent += ARAnchorUpdated;
            // UnityARSessionNativeInterface.ARAnchorRemovedEvent += ARAnchorRemoved;
            // #endif
        }
예제 #17
0
 public void RunWithConfigAndOptions(ARKitWorldTrackingSessionConfiguration config, UnityARSessionRunOption runOptions)
 {
     StartWorldTrackingSessionWithOptions(m_NativeARSession, config, runOptions);
 }
 private static extern void StartWorldTrackingSessionWithOptions(IntPtr nativeSession, ARKitWorldTrackingSessionConfiguration configuration, UnityARSessionRunOption runOptions);
 private static extern void StartWorldTrackingSession(IntPtr nativeSession, ARKitWorldTrackingSessionConfiguration configuration);
 private static extern void StartWorldTrackingSessionWithImage(IntPtr nativeSession, ARKitWorldTrackingSessionConfiguration configuration, int a_BufferLength, [MarshalAs(UnmanagedType.LPArray)] byte[] a_ImageBuffer, float a_width);
        public void RunWithConfig(ARKitWorldTrackingSessionConfiguration config)
        {
#if !UNITY_EDITOR
            StartWorldTrackingSession(m_NativeARSession, config);
#endif
        }
        public void RunWithConfigAndOptions(ARKitWorldTrackingSessionConfiguration config, UnityARSessionRunOption runOptions)
        {
#if !UNITY_EDITOR
            StartWorldTrackingSessionWithOptions(m_NativeARSession, config, runOptions);
#endif
        }
예제 #23
0
        public void ResetAR()
        {
            ARKitWorldTrackingSessionConfiguration sessionConfig = new ARKitWorldTrackingSessionConfiguration(alignmentOptions [currentAlignmentIndex], planeOptions[currentPlaneIndex]);

            UnityARSessionNativeInterface.GetARSessionNativeInterface().RunWithConfigAndOptions(sessionConfig, runOptions[currentOptionIndex]);
        }
예제 #24
0
 public void RunWithConfig(ARKitWorldTrackingSessionConfiguration config)
 {
     StartWorldTrackingSession(m_NativeARSession, config);
 }