コード例 #1
0
ファイル: ARHitTest.cs プロジェクト: oi7/ITSOS
    bool HitTestWithResultType(ARPoint point, ARHitTestResultType resultTypes)
    {
        List <ARHitTestResult> hitResults = UnityARSessionNativeInterface.GetARSessionNativeInterface().HitTest(point, resultTypes);

        if (hitResults.Count > 0)
        {
            foreach (var hitResult in hitResults)
            {
                //TODO: get the position and rotations to spawn the hat
                Vector3    pos      = UnityARMatrixOps.GetPosition(hitResult.worldTransform);
                Quaternion rotation = UnityARMatrixOps.GetRotation(hitResult.worldTransform);
                spawnedObjects.Add(Instantiate(hitPrefab, pos, rotation));                    // in order to use for shuffling
                return(true);
            }
        }
        return(false);
    }
コード例 #2
0
    bool HitTestWithResultType(ARPoint point, ARHitTestResultType resultTypes)
    {
        List <ARHitTestResult> hitResults = UnityARSessionNativeInterface.GetARSessionNativeInterface().HitTest(point, resultTypes);

        if (hitResults.Count > 0)
        {
            foreach (var hitResult in hitResults)
            {
                Debug.Log("Got hit!");
                m_HitTransform.position = UnityARMatrixOps.GetPosition(hitResult.worldTransform);
                m_HitTransform.rotation = UnityARMatrixOps.GetRotation(hitResult.worldTransform);
                Debug.Log(string.Format("x:{0:0.######} y:{1:0.######} z:{2:0.######}", m_HitTransform.position.x, m_HitTransform.position.y, m_HitTransform.position.z));
                return(true);
            }
        }
        return(false);
    }
コード例 #3
0
    // Use this for initialization
    void Start()
    {
#if !UNITY_EDITOR
        Application.targetFrameRate = 60;
        m_session = UnityARSessionNativeInterface.GetARSessionNativeInterface();
        ARKitSessionConfiguration config = new ARKitSessionConfiguration();
        config.alignment             = UnityARAlignment.UnityARAlignmentGravity;
        config.getPointCloudData     = true;
        config.enableLightEstimation = true;
        m_session.RunWithConfig(config);

        if (m_camera == null)
        {
            m_camera = Camera.main;
        }
#endif
    }
コード例 #4
0
    bool HitTestWithResultType(ARPoint point, ARHitTestResultType resultTypes)
    {
        List <ARHitTestResult> hitResults = UnityARSessionNativeInterface.GetARSessionNativeInterface().HitTest(point, resultTypes);

        if (hitResults.Count > 0)
        {
            foreach (var hitResult in hitResults)
            {
                Debug.Log("Got hit!");
                GameObject newFood = GameObject.Instantiate(foodTemplate);
                newFood.transform.position = UnityARMatrixOps.GetPosition(hitResult.worldTransform);
                foods.Add(newFood);
                return(true);
            }
        }
        return(false);
    }
コード例 #5
0
ファイル: BallMaker.cs プロジェクト: fiigo0/UnityArKitMaps
    // Update is called once per frame
    void Update()
    {
                #if UNITY_EDITOR   //we will only use this script on the editor side, though there is nothing that would prevent it from working on device
        if (Input.GetMouseButtonDown(0))
        {
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;

            //we'll try to hit one of the plane collider gameobjects that were generated by the plugin
            //effectively similar to calling HitTest with ARHitTestResultType.ARHitTestResultTypeExistingPlaneUsingExtent
            if (Physics.Raycast(ray, out hit, maxRayDistance, collisionLayer))
            {
                CreateBall(new Vector3(hit.point.x, hit.point.y + createHeight, hit.point.z));

                //we're going to get the position from the contact point
                Debug.Log(string.Format("x:{0:0.######} y:{1:0.######} z:{2:0.######}", hit.point.x, hit.point.y, hit.point.z));
            }
        }
                #else
        if (Input.touchCount > 0)
        {
            var touch = Input.GetTouch(0);
            if (touch.phase == TouchPhase.Began)
            {
                var     screenPosition = Camera.main.ScreenToViewportPoint(touch.position);
                ARPoint point          = new ARPoint {
                    x = screenPosition.x,
                    y = screenPosition.y
                };

                List <ARHitTestResult> hitResults = UnityARSessionNativeInterface.GetARSessionNativeInterface().HitTest(point,
                                                                                                                        ARHitTestResultType.ARHitTestResultTypeExistingPlaneUsingExtent);
                if (hitResults.Count > 0)
                {
                    foreach (var hitResult in hitResults)
                    {
                        Vector3 position = UnityARMatrixOps.GetPosition(hitResult.worldTransform);
                        CreateBall(new Vector3(position.x, position.y + createHeight, position.z));
                        break;
                    }
                }
            }
        }
                #endif
    }
コード例 #6
0
        protected override void Update()
        {
            base.Update();

            LinkedList <ARPlaneAnchorGameObject> arpags = unityARAnchorManager.GetCurrentPlaneAnchors();
            Touch touch;

            if (Input.touchCount < 1 || (touch = Input.GetTouch(0)).phase != TouchPhase.Began)
            {
                return;
            }

            Vector3 screenPosition = mainCamera.ScreenToViewportPoint(touch.position);
            ARPoint point          = new ARPoint
            {
                x = screenPosition.x,
                y = screenPosition.y
            };

            // prioritize reults types
            ARHitTestResultType[] resultTypes =
            {
                ARHitTestResultType.ARHitTestResultTypeExistingPlaneUsingExtent,
                // if you want to use infinite planes use this:
                //ARHitTestResultType.ARHitTestResultTypeExistingPlane,
                ARHitTestResultType.ARHitTestResultTypeEstimatedHorizontalPlane,
                ARHitTestResultType.ARHitTestResultTypeEstimatedVerticalPlane,
                ARHitTestResultType.ARHitTestResultTypeFeaturePoint
                //ARHitTestResultType.ARHitTestResultTypeFeaturePoint
            };

            for (int i = 0; i < resultTypes.Length; ++i)
            {
                List <ARHitTestResult> hitResults = UnityARSessionNativeInterface.GetARSessionNativeInterface().HitTest(point, resultTypes[i]);
                if (hitResults.Count > 0)
                {
                    Matrix4x4 matrix        = hitResults[0].worldTransform;
                    var       touchedObject = Instantiate(AppearTouchPrefab, UnityARMatrixOps.GetPosition(matrix), UnityARMatrixOps.GetRotation(matrix));
                    touchedObject.transform.LookAt(mainCamera.transform);
                    touchedObject.transform.rotation = Quaternion.Euler(0.0f, touchedObject.transform.rotation.eulerAngles.y, touchedObject.transform.rotation.z);
                    touchedObject.transform.parent   = fieldObjectAnchorRoot.transform;
                    break;
                }
            }
        }
コード例 #7
0
    void Update()
    {
        List <ARHitTestResult> hitResults;
        ARPoint point;

        //float scale;


        if (Input.touchCount > 0 && anchor != null)
        {
            var touch = Input.GetTouch(0);
            if (touch.phase == TouchPhase.Began)
            {
                Vector2 center         = new Vector2(Screen.width / 2, Screen.height / 2);
                Vector3 screenPosition = Camera.main.ScreenToViewportPoint(center);
                point.x = screenPosition.x;
                point.y = screenPosition.y;
                //Vector2 edge = new Vector2 (Screen.width, Screen.height / 2);
                //Vector3 screenEdge = Camera.main.ScreenToViewportPoint (edge);
                //scale = screenPosition.x - screenEdge.x;

                hitResults = UnityARSessionNativeInterface.GetARSessionNativeInterface().HitTest(point,
                                                                                                 ARHitTestResultType.ARHitTestResultTypeExistingPlaneUsingExtent);
                if (hitResults.Count == 0)
                {
                    hitResults = UnityARSessionNativeInterface.GetARSessionNativeInterface().HitTest(point,
                                                                                                     ARHitTestResultType.ARHitTestResultTypeHorizontalPlane);
                }
                if (hitResults.Count == 0)
                {
                    hitResults = UnityARSessionNativeInterface.GetARSessionNativeInterface().HitTest(point,
                                                                                                     ARHitTestResultType.ARHitTestResultTypeFeaturePoint);
                }

                if (hitResults.Count > 0)
                {
                    anchor.position = UnityARMatrixOps.GetPosition(hitResults [0].worldTransform);
                    anchor.rotation = UnityARMatrixOps.GetRotation(hitResults [0].worldTransform);
                    //Debug.Log("ARHitHandler scale: " + scale);
                    //anchor.localScale = new Vector3(scale, scale, scale);
                    controller.ToggleAnchor();
                }
            }
        }
    }
コード例 #8
0
        // Use this for initialization
        void Start()
        {
            // Initialize some variables
            m_arMode = false;

            m_session = UnityARSessionNativeInterface.GetARSessionNativeInterface();

            UnityARSessionNativeInterface.ARImageAnchorAddedEvent   += AddImageAnchor;
            UnityARSessionNativeInterface.ARImageAnchorUpdatedEvent += UpdateImageAnchor;
            UnityARSessionNativeInterface.ARImageAnchorRemovedEvent += RemoveImageAnchor;
            scene = GameObject.Find("Scene");

#if !UNITY_EDITOR
            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.RunWithConfig(config);
                UnityARSessionNativeInterface.ARFrameUpdatedEvent += FirstFrameUpdate;
            }

            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
        }
コード例 #9
0
        /// <summary>
        /// Performs a Raycast against a plane.
        /// </summary>
        /// <param name="camera">The AR camera being used.</param>
        /// <param name="x">The x screen position.</param>
        /// <param name="y">The y screen position.</param>
        /// <param name="hitPose">The resulting hit pose if the method returns <c>true</c>.</param>
        /// <returns><c>true</c> if a plane was hit. Otherwise <c>false</c>.</returns>
        public bool RaycastPlane(Camera camera, float x, float y, out Pose hitPose)
        {
            hitPose = new Pose();
#if ARCORE_IOS_SUPPORT
            var session = UnityARSessionNativeInterface.GetARSessionNativeInterface();

            var     viewportPoint = camera.ScreenToViewportPoint(new Vector2(x, y));
            ARPoint arPoint       = new ARPoint
            {
                x = viewportPoint.x,
                y = viewportPoint.y
            };

            m_HitResultList = session.HitTest(arPoint, ARHitTestResultType.ARHitTestResultTypeExistingPlaneUsingExtent);
            if (m_HitResultList.Count > 0)
            {
                int minDistanceIndex = 0;
                for (int i = 1; i < m_HitResultList.Count; i++)
                {
                    if (m_HitResultList[i].distance < m_HitResultList[minDistanceIndex].distance)
                    {
                        minDistanceIndex = i;
                    }
                }

                hitPose.position = UnityARMatrixOps.GetPosition(m_HitResultList[minDistanceIndex].worldTransform);

                // Original ARKit hit pose is the plane rotation.
                Quaternion planeRotation = UnityARMatrixOps.GetRotation(
                    m_HitResultList[minDistanceIndex].worldTransform);

                // Try to match the hit rotation to the one ARCore uses.
                Vector3 planeNormal     = planeRotation * Vector3.up;
                Vector3 rayDir          = camera.ViewportPointToRay(viewportPoint).direction;
                Vector3 planeProjection = Vector3.ProjectOnPlane(rayDir, planeNormal);
                Vector3 forwardDir      = -planeProjection.normalized;

                Quaternion hitRotation = Quaternion.LookRotation(forwardDir, planeNormal);
                hitPose.rotation = hitRotation;

                return(true);
            }
#endif
            return(false);
        }
コード例 #10
0
 // Updates the state by updating the time counter, and deleting the first object in our clones list if time is up
 void UpdateState()
 {
     // Just remove anchors after a certain amount of time, for example's sake.
     timeUntilRemove   -= Time.deltaTime;
     textIndicator.text = "Time until oldest anchor removed: " + (int)timeUntilRemove + "s";
     if (timeUntilRemove <= 0.0f && clones.Count > 0)
     {
         GameObject clone = (GameObject)clones[0];
         clones.RemoveAt(0);
         UnityARSessionNativeInterface.GetARSessionNativeInterface().RemoveUserAnchor(clone.GetComponent <UnityARUserAnchorComponent>().AnchorId);
         if (clone != null)
         {
             Debug.Log("still exists, so we delete it ourselves " + clones.Count);
             Destroy(clone);
         }
         timeUntilRemove = originalTimeUntilRemove;
     }
 }
コード例 #11
0
        public override void StopService()
        {
            var anchors = m_Anchors.Values;

            foreach (var anchor in anchors)
            {
                DestroyAnchor(anchor);
            }
            UnityARSessionNativeInterface.ARUserAnchorUpdatedEvent -= UpdateUserAnchor;
            UnityARSessionNativeInterface.GetARSessionNativeInterface().Pause();

            nativeInterface.SetCapturePixelData(false, IntPtr.Zero, IntPtr.Zero);
            m_PinnedYArray.Free();
            m_PinnedUVArray.Free();
            m_TexturesInitialized = false;

            IsRunning = false;
        }
コード例 #12
0
    // Use this for initialization
    private void Start()
    {
        anchorLocateCriteria = new AnchorLocateCriteria();

#if UNITY_IOS
        arkitSession = UnityARSessionNativeInterface.GetARSessionNativeInterface();
        UnityARSessionNativeInterface.ARFrameUpdatedEvent += UnityARSessionNativeInterface_ARFrameUpdatedEvent;
#elif UNITY_ANDROID
        UnityAndroidHelper.Instance.DispatchUiThread(unityActivity =>
        {
            using (AndroidJavaClass cloudServices = new AndroidJavaClass("com.microsoft.CloudServices"))
            {
                cloudServices.CallStatic("initialize", unityActivity);
            }
        });
#endif
        StartCoroutine(CreateNewCloudSession());
    }
コード例 #13
0
    bool GetCursorPosition(ref Vector3 positionToUpdate)
    {
        bool wasCursorFound = false;
        List <ARHitTestResult> hitResults =
            UnityARSessionNativeInterface.GetARSessionNativeInterface().HitTest(m_hitPointToUse, m_resultTypeToUse);

        if (hitResults.Count > 0)
        {
            ARHitTestResult hitResult = Utils.GetFirstValidHit(hitResults);
            if (hitResult.isValid)
            {
                positionToUpdate = UnityARMatrixOps.GetPosition(hitResult.worldTransform);
                wasCursorFound   = true;
            }
        }

        return(wasCursorFound);
    }
コード例 #14
0
        private void Update()
        {
            // We only classify a new image if no other vision requests are in progress
            if (_vision.InProgress)
            {
                return;
            }

            // Instead of using ARKit's capturedImage (CVPixelBuffer), like we did in the first example,
            // this time we use the Y plane of the YCbCr texture Unity uses to render the current camera frame.
            ARTextureHandles handles = UnityARSessionNativeInterface.GetARSessionNativeInterface().GetARVideoTextureHandles();

            if (handles.textureY != System.IntPtr.Zero)
            {
                // This is the call where we pass in the handle to the metal texture to be analysed
                _vision.EvaluateBuffer(handles.textureY, ImageDataType.MetalTexture);
            }
        }
コード例 #15
0
    private void Start()
    {
        // Singleton handling
        if (instance == null)
        {
            instance = this;
        }
        else if (instance != this)
        {
            Destroy(this);
        }

        Input.location.Start();
        arSession = UnityARSessionNativeInterface.GetARSessionNativeInterface();
        StartARKit();
        FeaturesVisualizer.EnablePointcloud();
        LibPlacenote.Instance.RegisterListener(this);
    }
コード例 #16
0
    bool GetGroundPlane(ARPoint point, ARHitTestResultType resultTypes)
    {
        List <ARHitTestResult> hitResults = UnityARSessionNativeInterface.GetARSessionNativeInterface().HitTest(point, resultTypes);

        if (hitResults.Count > 0)
        {
            foreach (var hitResult in hitResults)
            {
                groundPlaneAnchorIdentifier = hitResult.anchorIdentifier;
                groundPlanePosition         = new Vector3(0f, UnityARMatrixOps.GetPosition(hitResult.worldTransform).y, 0f);
                CreateGroundPlane(groundPlanePosition);
                aimTarget.SetActive(true);
                return(true);
            }
        }

        return(false);
    }
コード例 #17
0
    bool HitTestWithResultType(ARPoint point, ARHitTestResultType resultTypes)
    {
        Camera camera = Camera.main;
        List <ARHitTestResult> hitResults = UnityARSessionNativeInterface.GetARSessionNativeInterface().HitTest(point, resultTypes);

        if (hitResults.Count > 0)
        {
            anchor.position = UnityARMatrixOps.GetPosition(hitResults[0].worldTransform);
            //anchor.rotation = UnityARMatrixOps.GetRotation (hitResult.worldTransform);

            anchor.LookAt(anchor.position + camera.transform.rotation * Vector3.forward,
                          camera.transform.rotation * Vector3.up);

            Debug.Log(string.Format("x:{0:0.######} y:{1:0.######} z:{2:0.######}", anchor.position.x, anchor.position.y, anchor.position.z));
            return(true);
        }
        return(false);
    }
コード例 #18
0
    // Use this for initialization
    void Start()
    {
        Input.location.Start();

        mMapListPanel.SetActive(false);

        mSession = UnityARSessionNativeInterface.GetARSessionNativeInterface();

        StartARKit();
        FeaturesVisualizer.EnablePointcloud();
        LibPlacenote.Instance.RegisterListener(this);
        ResetSlider();

        // for simulator
                #if UNITY_EDITOR
        mSimulatorAddShapeButton.SetActive(true);
                #endif
    }
コード例 #19
0
    void Start()
    {
        // LibPlacenote.Instance.Initialized();
        iiii = GameObject.Find("ARKitWorldTrackingRemoteConnection");
        mRadiusSlider.value = 0.5f;

        //ResetSlider();
        StartCoroutine(Start1());
        mSession = UnityARSessionNativeInterface.GetARSessionNativeInterface();
        UnityARSessionNativeInterface.ARFrameUpdatedEvent += ARFrameUpdated;
        Application.targetFrameRate = 60;
        //ARKitWorldTrackingSessionConfiguration config = new ARKitWorldTrackingSessionConfiguration();
        //config.planeDetection = UnityARPlaneDetection.Horizontal;
        //config.alignment = UnityARAlignment.UnityARAlignmentGravity;
        //config.getPointCloudData = true;
        //config.enableLightEstimation = true;
        //mSession.RunWithConfig(config);
    }
コード例 #20
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;
        }
    }
コード例 #21
0
    // Use this for initialization
    void Start()
    {
        m_session = UnityARSessionNativeInterface.GetARSessionNativeInterface();

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

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

        if (config.IsSupported)
        {
            m_session.RunWithConfig(config);

            UnityARSessionNativeInterface.ARFaceAnchorAddedEvent   += FaceAdded;
            UnityARSessionNativeInterface.ARFaceAnchorUpdatedEvent += FaceUpdated;
            UnityARSessionNativeInterface.ARFaceAnchorRemovedEvent += FaceRemoved;
        }
    }
コード例 #22
0
        public override void UpdateCamera(Camera camera)
        {
            camera.projectionMatrix = nativeInterface.GetCameraProjection();

            if (!m_BackgroundRendering)
            {
                return;
            }

            ARTextureHandles handles = UnityARSessionNativeInterface.GetARSessionNativeInterface().GetARVideoTextureHandles();

            if (handles.textureY == System.IntPtr.Zero || handles.textureCbCr == System.IntPtr.Zero)
            {
                return;
            }

            Resolution currentResolution = Screen.currentResolution;

            // Texture Y
            if (_videoTextureY == null)
            {
                _videoTextureY = Texture2D.CreateExternalTexture(currentResolution.width, currentResolution.height,
                                                                 TextureFormat.R8, false, false, (System.IntPtr)handles.textureY);
                _videoTextureY.filterMode = FilterMode.Bilinear;
                _videoTextureY.wrapMode   = TextureWrapMode.Repeat;
                m_ClearMaterial.SetTexture("_textureY", _videoTextureY);
            }

            // Texture CbCr
            if (_videoTextureCbCr == null)
            {
                _videoTextureCbCr = Texture2D.CreateExternalTexture(currentResolution.width, currentResolution.height,
                                                                    TextureFormat.RG16, false, false, (System.IntPtr)handles.textureCbCr);
                _videoTextureCbCr.filterMode = FilterMode.Bilinear;
                _videoTextureCbCr.wrapMode   = TextureWrapMode.Repeat;
                m_ClearMaterial.SetTexture("_textureCbCr", _videoTextureCbCr);
            }

            _videoTextureY.UpdateExternalTexture(handles.textureY);
            _videoTextureCbCr.UpdateExternalTexture(handles.textureCbCr);

            m_ClearMaterial.SetMatrix("_DisplayTransform", m_DisplayTransform);
        }
コード例 #23
0
    // Use this for initialization
    void Start()
    {
        m_session = UnityARSessionNativeInterface.GetARSessionNativeInterface();

        Application.targetFrameRate = 60;

        var config = sessionConfiguration;

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

        if (m_camera == null)
        {
            m_camera = Camera.main;
        }
    }
    private IEnumerator ResetOrientation()
    {
        Matrix4x4 matrix = UnityARSessionNativeInterface.GetARSessionNativeInterface().GetCameraPose();

        var orientation = UnityARMatrixOps.GetRotation(matrix);

        while
        (
            orientation == Quaternion.identity ||
            (
                orientation.x == 0 &&
                orientation.y == 0 &&
                orientation.z == 0 &&
                orientation.w == -1
            )
        )
        {
            yield return(null);
        }

        yield return(new WaitForEndOfFrame());

        _orientation = _resetOffset * orientation;

        var orientationHelper = new GameObject();

        orientationHelper.name = "_OnAppFocusOrientationHelper";

        orientationHelper.transform.rotation = _lastOrientation;
        var oldForward = orientationHelper.transform.forward;

        orientationHelper.transform.rotation = _orientation;
        var newForward = orientationHelper.transform.forward;

        var angle = Quaternion.Angle(_lastOrientation, _orientation);

        //        Debug.Log(" [IOSTrackingProvider] : Angle is : " + angle);

        if (Mathf.Abs(angle) <= 30)
        {
            _resetOffset = Quaternion.FromToRotation(oldForward, newForward);
        }
    }
コード例 #25
0
    private bool HitTestWithResultType(ARPoint point, ARHitTestResultType arHitTestResultTypes)
    {
        List <ARHitTestResult> hitResults = UnityARSessionNativeInterface.GetARSessionNativeInterface().HitTest(point, arHitTestResultTypes);

        if (hitResults.Count > 0)
        {
            anchorSet = true;

            ChildrenSetActive(parentGameObject, true);

            parentGameObject.transform.position = UnityARMatrixOps.GetPosition(hitResults[0].worldTransform);
            parentGameObject.transform.rotation = UnityARMatrixOps.GetRotation(hitResults[0].worldTransform);
            parentGameObject.transform.LookAt(new Vector3(mainCamera.transform.position.x, parentGameObject.transform.position.y, mainCamera.transform.position.z));

            return(true);
        }

        return(false);
    }
コード例 #26
0
    bool HitTestWithResultType(ARPoint point, ARHitTestResultType resultTypes, GameObject target)
    {
        List <ARHitTestResult> hitResults = UnityARSessionNativeInterface.GetARSessionNativeInterface().HitTest(point, resultTypes);

        if (hitResults.Count > 0)
        {
            foreach (var hitResult in hitResults)
            {
                Debug.Log("Got hit!");
                target.transform.position = UnityARMatrixOps.GetPosition(hitResult.worldTransform);
                Vector3 up      = Vector3.up;
                Vector3 right   = Vector3.Cross(up, Camera.main.transform.forward).normalized;
                Vector3 forward = -Vector3.Cross(right, up).normalized;
                target.transform.rotation = Quaternion.LookRotation(forward, up);
                return(true);
            }
        }
        return(false);
    }
コード例 #27
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);
        }
        if (m_camera == null)
        {
            m_camera = Camera.main;
        }
    }
コード例 #28
0
        public override void ApplyAnchor(ARAnchor arAnchor)
        {
            if (!IsRunning)
            {
                return;
            }

            Matrix4x4             matrix     = Matrix4x4.TRS(arAnchor.transform.position, arAnchor.transform.rotation, arAnchor.transform.localScale);
            UnityARUserAnchorData anchorData = new UnityARUserAnchorData();

            anchorData.transform.column0 = matrix.GetColumn(0);
            anchorData.transform.column1 = matrix.GetColumn(1);
            anchorData.transform.column2 = matrix.GetColumn(2);
            anchorData.transform.column3 = matrix.GetColumn(3);

            anchorData                   = UnityARSessionNativeInterface.GetARSessionNativeInterface().AddUserAnchor(anchorData);
            arAnchor.anchorID            = anchorData.identifierStr;
            m_Anchors[arAnchor.anchorID] = arAnchor;
        }
コード例 #29
0
 /// <summary>
 /// checks hits in order of priority
 /// returns true on first valid hit and saves in out variables
 /// </summary>
 /// <param name="viewportPoint"></param>
 /// <param name="resultTypesPrioriy"></param>
 /// <param name="hitPos"></param>
 /// <param name="hitRotaion"></param>
 /// <returns></returns>
 public static bool getHitData(ARPoint viewportPoint, ARHitTestResultType[] resultTypesPrioriy, out Vector3 hitPos, out Quaternion hitRotaion)
 {
     foreach (var resultType in resultTypesPrioriy)
     {
         List <ARHitTestResult> hitResults = UnityARSessionNativeInterface.GetARSessionNativeInterface().HitTest(viewportPoint, resultType);
         if (hitResults.Count > 0)
         {
             foreach (var hitResult in hitResults)
             {
                 hitPos     = UnityARMatrixOps.GetPosition(hitResult.worldTransform);
                 hitRotaion = UnityARMatrixOps.GetRotation(hitResult.worldTransform);
                 return(true);
             }
         }
     }
     hitRotaion = Quaternion.identity;
     hitPos     = Vector3.zero;
     return(false);
 }
コード例 #30
0
    bool HitTestWithResultType(ARPoint point, ARHitTestResultType resultTypes)
    {
        List <ARHitTestResult> hitResults = UnityARSessionNativeInterface.GetARSessionNativeInterface().HitTest(point, resultTypes);

        if (hitResults.Count > 0)
        {
            foreach (var hitResult in hitResults)
            {
                Vector3 pos = UnityARMatrixOps.GetPosition(hitResult.worldTransform);
                placementPrompt.SetHit(pos);
                placementPrompt.gameObject.SetActive(true);
                introText.gameObject.SetActive(false);
                introTextPanel.gameObject.SetActive(false);
                MenuBTN.gameObject.SetActive(true);
                return(true);
            }
        }
        return(false);
    }