Example #1
0
    // Use this for initialization
    void Start()
    {
        m_session = UnityARSessionNativeInterface.GetARSessionNativeInterface();

        Application.targetFrameRate = 60;
        ARKitWorldTrackingSessionConfiguration config = new ARKitWorldTrackingSessionConfiguration();

        config.planeDetection        = planeDetection;
        config.alignment             = startAlignment;
        config.getPointCloudData     = getPointCloud;
        config.enableLightEstimation = enableLightEstimation;

        if (config.IsSupported)
        {
            m_session.RunWithConfig(config);
            UnityARSessionNativeInterface.ARFrameUpdatedEvent += FirstFrameUpdate;
        }

        if (m_camera == null)
        {
            m_camera = Camera.main;
        }

        UnityARSessionRunOption options = UnityARSessionRunOption.ARSessionRunOptionRemoveExistingAnchors | UnityARSessionRunOption.ARSessionRunOptionResetTracking;

        m_session.RunWithConfigAndOptions(config, options);
    }
    // Use this for initialization
    void Start()
    {
        m_session = UnityARSessionNativeInterface.GetARSessionNativeInterface();

#if !UNITY_EDITOR
        Application.targetFrameRate = 60;
        ARKitWorldTrackingSessionConfiguration config = new ARKitWorldTrackingSessionConfiguration();
        config.planeDetection        = planeDetection;
        config.alignment             = startAlignment;
        config.getPointCloudData     = getPointCloud;
        config.enableLightEstimation = enableLightEstimation;
        m_session.RunWithConfig(config);

        UnityARSessionRunOption options = new UnityARSessionRunOption();
        options = UnityARSessionRunOption.ARSessionRunOptionRemoveExistingAnchors | UnityARSessionRunOption.ARSessionRunOptionResetTracking;
        m_session.RunWithConfigAndOptions(config, options);

        if (m_camera == null)
        {
            m_camera = Camera.main;
        }
#else
        //put some defaults so that it doesnt complain
        UnityARCamera scamera = new UnityARCamera();
        scamera.worldTransform = new UnityARMatrix4x4(new Vector4(1, 0, 0, 0), new Vector4(0, 1, 0, 0), new Vector4(0, 0, 1, 0), new Vector4(0, 0, 0, 1));
        Matrix4x4 projMat = Matrix4x4.Perspective(60.0f, 1.33f, 0.1f, 30.0f);
        scamera.projectionMatrix = new UnityARMatrix4x4(projMat.GetColumn(0), projMat.GetColumn(1), projMat.GetColumn(2), projMat.GetColumn(3));

        UnityARSessionNativeInterface.SetStaticCamera(scamera);
#endif
    }
        private void ConfigureSession(bool togglePlaneDetection, bool clearOldPlanes)
        {
            ARKitWorldTrackingSessionConfiguration config = new ARKitWorldTrackingSessionConfiguration();

            if (togglePlaneDetection)
            {
                if (UnityARSessionNativeInterface.IsARKit_1_5_Supported())
                {
                    config.planeDetection = UnityARPlaneDetection.HorizontalAndVertical;
                }
                else
                {
                    config.planeDetection = UnityARPlaneDetection.Horizontal;
                }
            }
            else
            {
                config.planeDetection = UnityARPlaneDetection.None;
            }

            if (clearOldPlanes)
            {
                mPlaneGenerator.ClearPlanes();
            }

            config.alignment             = UnityARAlignment.UnityARAlignmentGravity;
            config.getPointCloudData     = true;
            config.enableLightEstimation = true;

            UnityARSessionRunOption options = new UnityARSessionRunOption();

            //options = UnityARSessionRunOption.ARSessionRunOptionRemoveExistingAnchors | UnityARSessionRunOption.ARSessionRunOptionResetTracking;
            options = UnityARSessionRunOption.ARSessionRunOptionRemoveExistingAnchors;
            mSession.RunWithConfigAndOptions(config, options);
        }
    public void ResetScence()
    {
        ClearPoints();
        ARKitWorldTrackingSessionConfiguration config = new ARKitWorldTrackingSessionConfiguration(
            UnityARAlignment.UnityARAlignmentGravity,
            UnityARPlaneDetection.Vertical,
            true, true
            );

        m_session.RunWithConfigAndOptions(config, UnityARSessionRunOption.ARSessionRunOptionRemoveExistingAnchors);
    }
Example #5
0
    public void ResetAr()
    {
        sessionStarted = false;
        UnityARSessionRunOption options = new UnityARSessionRunOption();
        ARKitWorldTrackingSessionConfiguration config = new ARKitWorldTrackingSessionConfiguration(UnityARAlignment.UnityARAlignmentGravity, UnityARPlaneDetection.Horizontal);

        config  = setConfig(config);
        options = UnityARSessionRunOption.ARSessionRunOptionRemoveExistingAnchors | UnityARSessionRunOption.ARSessionRunOptionResetTracking;
        if (config.IsSupported)
        {
            m_session.RunWithConfigAndOptions(config, options);
            UnityARSessionNativeInterface.ARFrameUpdatedEvent += FirstFrameUpdate;
        }
    }
    void OnGUI()
    {
        if (GUI.Button(new Rect(100, 100, 200, 50), "session pause"))
        {
            m_session.Pause();
        }

        if (GUI.Button(new Rect(300, 100, 200, 50), "session run"))
        {
            m_session.Run();
        }

        if (GUI.Button(new Rect(100, 200, 200, 50), "renew & run"))
        {
            ARKitWorldTrackingSessionConfiguration config = new ARKitWorldTrackingSessionConfiguration();
            config.alignment             = UnityARAlignment.UnityARAlignmentGravityAndHeading;
            config.planeDetection        = UnityARPlaneDetection.Horizontal;
            config.enableLightEstimation = true;
            config.getPointCloudData     = true;

            //m_session.RunWithConfig (config);
            m_session.RunWithConfigAndOptions(config, UnityARSessionRunOption.ARSessionRunOptionResetTracking);
        }

        if (GUI.Button(new Rect(300, 200, 200, 50), "renew & close"))
        {
            ARKitWorldTrackingSessionConfiguration config = new ARKitWorldTrackingSessionConfiguration();
            config.alignment             = UnityARAlignment.UnityARAlignmentGravity;
            config.planeDetection        = UnityARPlaneDetection.Horizontal;
            config.enableLightEstimation = true;
            config.getPointCloudData     = true;

            //m_session.RunWithConfig (config);
            m_session.RunWithConfigAndOptions(config, UnityARSessionRunOption.ARSessionRunOptionRemoveExistingAnchors);
        }
    }
Example #7
0
    public void ExampletButtonPressed(UnityARVideoFormat videoFormat)
    {
        UnityARSessionNativeInterface session = UnityARSessionNativeInterface.GetARSessionNativeInterface();

        var config = new ARKitFaceTrackingConfiguration();

        if (config.IsSupported)
        {
            config.alignment             = UnityARAlignment.UnityARAlignmentGravity;
            config.enableLightEstimation = true;
            config.videoFormat           = videoFormat.videoFormatPtr;
            Application.targetFrameRate  = videoFormat.framesPerSecond;

            UnityARSessionRunOption runOption = UnityARSessionRunOption.ARSessionRunOptionRemoveExistingAnchors | UnityARSessionRunOption.ARSessionRunOptionResetTracking;
            session.RunWithConfigAndOptions(config, runOption);
        }
    }
Example #8
0
        private void Start()
        {
#if UNITY_IOS
            // Ensure that ARkit reset the tracking when the scene gets restarted
            UnityARCameraManager    arkitCameraManager = FindObjectOfType <UnityARCameraManager>();
            UnityARSessionRunOption options            = new UnityARSessionRunOption();
            options = UnityARSessionRunOption.ARSessionRunOptionRemoveExistingAnchors | UnityARSessionRunOption.ARSessionRunOptionResetTracking;
            UnityARSessionNativeInterface nativeInterface = UnityARSessionNativeInterface.GetARSessionNativeInterface();

            ARKitWorldTrackingSessionConfiguration config = new ARKitWorldTrackingSessionConfiguration();
            config.planeDetection        = arkitCameraManager.planeDetection;
            config.alignment             = arkitCameraManager.startAlignment;
            config.getPointCloudData     = arkitCameraManager.getPointCloud;
            config.enableLightEstimation = arkitCameraManager.enableLightEstimation;
            nativeInterface.RunWithConfigAndOptions(config, options);
#endif
        }
Example #9
0
    public void ResetScence()
    {
        int c_count = linesGenerator.transform.childCount;

        for (int i = 0; i < c_count; i++)
        {
            Destroy(linesGenerator.transform.GetChild(i).gameObject);
        }
        cd.ClearCurrentMeasure();
        ARKitWorldTrackingSessionConfiguration config = new ARKitWorldTrackingSessionConfiguration(
            UnityARAlignment.UnityARAlignmentGravity,
            UnityARPlaneDetection.Horizontal,
            true, true
            );

        m_session.RunWithConfigAndOptions(config, UnityARSessionRunOption.ARSessionRunOptionRemoveExistingAnchors);
        MStatus = MeasureStatus.Initializing;
    }
Example #10
0
    // Use this for initialization
    public void Start()
    {
        //ARKitRemoteConnection existingSessions=
        if (GameObject.Find("ARKitWorldTrackingRemoteConnection") != null)
        {
            Debug.Log("tracking reset: ");
            GameObject trackingSesh = GameObject.Find("ARKitWorldTrackingRemoteConnection");
            //Destroy(trackingSesh);
            trackingSesh.SetActive(false);

            //Destroy(FindObjectOfType<ARKitRemoteConnection>());
        }
        else
        {
        }

        //Debug.Log(existingSessions);

        m_session = UnityARSessionNativeInterface.GetARSessionNativeInterface();

        Application.targetFrameRate = 60;
        ARKitWorldTrackingSessionConfiguration config = new ARKitWorldTrackingSessionConfiguration();

        config.planeDetection        = planeDetection;
        config.alignment             = startAlignment;
        config.getPointCloudData     = getPointCloud;
        config.enableLightEstimation = enableLightEstimation;
        config.enableAutoFocus       = enableAutoFocus;
        if (detectionImages != null)
        {
            config.arResourceGroupName = detectionImages.resourceGroupName;
        }

        if (config.IsSupported)
        {
            m_session.RunWithConfigAndOptions(config, UnityARSessionRunOption.ARSessionRunOptionRemoveExistingAnchors | UnityARSessionRunOption.ARSessionRunOptionResetTracking);
            UnityARSessionNativeInterface.ARFrameUpdatedEvent += FirstFrameUpdate;
        }

        if (m_camera == null)
        {
            m_camera = Camera.main;
        }
    }
Example #11
0
    private void Awake()
    {
        _providerStatus = ProviderStatus.Initializing;

        //Configure ArKit
        UnityARSessionNativeInterface arKitSession = UnityARSessionNativeInterface.GetARSessionNativeInterface();

#if !UNITY_EDITOR
        // config
        //Application.targetFrameRate = 60;

        ARKitWorldTrackingSessionConfiguration config = new ARKitWorldTrackingSessionConfiguration
        {
            planeDetection        = UnityARPlaneDetection.Horizontal,
            alignment             = UnityARAlignment.UnityARAlignmentGravity,
            getPointCloudData     = true,
            enableLightEstimation = true,
            enableAutoFocus       = false
        };

        if (!config.IsSupported)
        {
            Debug.LogError("Tracking is not supported on this device");
            ToastManager.Instance.ShowToast(" Session Error : ArKit is not supported on this device.");
            _providerStatus = ProviderStatus.NotSupported;
        }
        else
        {
            _providerStatus = ProviderStatus.Ready;
            arKitSession.RunWithConfigAndOptions(config, UnityARSessionRunOption.ARSessionRunOptionResetTracking);
        }
#else
        UnityARCamera scamera = new UnityARCamera();
        scamera.worldTransform = new UnityARMatrix4x4(new Vector4(1, 0, 0, 0), new Vector4(0, 1, 0, 0), new Vector4(0, 0, 1, 0), new Vector4(0, 0, 0, 1));
        Matrix4x4 projMat = Matrix4x4.Perspective(60.0f, 1.33f, 0.1f, 30.0f);
        scamera.projectionMatrix = new UnityARMatrix4x4(projMat.GetColumn(0), projMat.GetColumn(1), projMat.GetColumn(2), projMat.GetColumn(3));

        UnityARSessionNativeInterface.SetStaticCamera(scamera);
        _providerStatus = ProviderStatus.Ready;
        #endif
    }
Example #12
0
    void OnGUI()
    {
        // 创建暂停按钮
        if (GUI.Button(new Rect(50, 50, 100, 50), "会话暂停"))
        {
            // 会话暂停
            m_session.Pause();
        }

        // 创建开始按钮
        if (GUI.Button(new Rect(100, 200, 100, 50), "会话开始"))
        {
            // 新建世界跟踪配置类
            ARKitWorldTrackingSessionConfiguration config = new ARKitWorldTrackingSessionConfiguration();
            config.alignment             = UnityARAlignment.UnityARAlignmentGravity;
            config.planeDetection        = UnityARPlaneDetection.Horizontal;
            config.enableLightEstimation = true;
            config.getPointCloudData     = true;
            // 重置会话
            m_session.RunWithConfigAndOptions(config, UnityARSessionRunOption.ARSessionRunOptionRemoveExistingAnchors);
        }
    }
    private void Awake()
    {
        //Configure ArKit
        _arKitSession = UnityARSessionNativeInterface.GetARSessionNativeInterface();


        #if !UNITY_EDITOR
        // config
        Application.targetFrameRate = 60;

        _config = new ARKitWorldTrackingSessionConfiguration();

        _config.planeDetection        = UnityARPlaneDetection.Horizontal;
        _config.alignment             = UnityARAlignment.UnityARAlignmentGravity;
        _config.getPointCloudData     = true;
        _config.enableLightEstimation = true;
        _config.enableAutoFocus       = true;
        UnityARSessionRunOption tracking = UnityARSessionRunOption.ARSessionRunOptionResetTracking;
        _arKitSession.RunWithConfigAndOptions(_config, tracking);

        if (!_config.IsSupported)
        {
            Debug.LogError("Tracking is not supported on this device");
            //Delete the VideoCamera. Default providers will create its own video camera
            Destroy(GetComponent <Camera>());
        }
        else
        {
            ProviderHelper.ArKitSupported = true;
        }
        #else
        UnityARCamera scamera = new UnityARCamera();
        scamera.worldTransform = new UnityARMatrix4x4(new Vector4(1, 0, 0, 0), new Vector4(0, 1, 0, 0), new Vector4(0, 0, 1, 0), new Vector4(0, 0, 0, 1));
        Matrix4x4 projMat = Matrix4x4.Perspective(60.0f, 1.33f, 0.1f, 30.0f);
        scamera.projectionMatrix = new UnityARMatrix4x4(projMat.GetColumn(0), projMat.GetColumn(1), projMat.GetColumn(2), projMat.GetColumn(3));

        UnityARSessionNativeInterface.SetStaticCamera(scamera);
        #endif
    }
Example #14
0
    public void RunSession(bool isPlaneDetectionEnabled, bool isReset)
    {
                #if !UNITY_EDITOR
        ARKitWorldTrackingSessionConfiguration config = new ARKitWorldTrackingSessionConfiguration();
        config.planeDetection        = isPlaneDetectionEnabled ? UnityARPlaneDetection.Horizontal : UnityARPlaneDetection.None;
        config.alignment             = UnityARAlignment.UnityARAlignmentGravityAndHeading;
        config.getPointCloudData     = false;
        config.enableLightEstimation = true;

        if (isReset)
        {
            UnityARSessionRunOption options = UnityARSessionRunOption.ARSessionRunOptionRemoveExistingAnchors |
                                              UnityARSessionRunOption.ARSessionRunOptionResetTracking;

            m_session.RunWithConfigAndOptions(config, options);
        }
        else
        {
            m_session.RunWithConfig(config);
        }
                #endif
    }
Example #15
0
    public void ExampletButtonPressed(UnityARVideoFormat videoFormat)
    {
        //Restart session with new video format in config

        UnityARSessionNativeInterface session = UnityARSessionNativeInterface.GetARSessionNativeInterface();

        ARKitWorldTrackingSessionConfiguration config = new ARKitWorldTrackingSessionConfiguration();

        if (config.IsSupported)
        {
            config.planeDetection        = UnityARPlaneDetection.HorizontalAndVertical;
            config.alignment             = UnityARAlignment.UnityARAlignmentGravity;
            config.getPointCloudData     = true;
            config.enableLightEstimation = true;
            config.enableAutoFocus       = true;
            config.videoFormat           = videoFormat.videoFormatPtr;
            Application.targetFrameRate  = videoFormat.framesPerSecond;

            UnityARSessionRunOption runOption = UnityARSessionRunOption.ARSessionRunOptionRemoveExistingAnchors | UnityARSessionRunOption.ARSessionRunOptionResetTracking;
            session.RunWithConfigAndOptions(config, runOption);
        }
    }
Example #16
0
    void InitializeARSession()
    {
        Session = UnityARSessionNativeInterface.GetARSessionNativeInterface();
        ARKitFaceTrackingConfiguration configuration = new ARKitFaceTrackingConfiguration();

        configuration.alignment             = UnityARAlignment.UnityARAlignmentGravity;
        configuration.enableLightEstimation = true;
        //オプションを追加
        var options = UnityARSessionRunOption.ARSessionRunOptionRemoveExistingAnchors | UnityARSessionRunOption.ARSessionRunOptionResetTracking;

        if (configuration.IsSupported)
        {
            UnityARSessionNativeInterface.ARFaceAnchorAddedEvent   += FaceAdd;
            UnityARSessionNativeInterface.ARFaceAnchorUpdatedEvent += FaceUpdate;
            UnityARSessionNativeInterface.ARFaceAnchorRemovedEvent += FaceRemoved;
        }
        else
        {
            // 利用できない場合の処理
        }

        //オプションをセット
        Session.RunWithConfigAndOptions(configuration, options);
    }
Example #17
0
 public override void ResetARSession()
 {
     m_session.RunWithConfigAndOptions(m_arconfig, UnityARSessionRunOption.ARSessionRunOptionRemoveExistingAnchors);
 }