Ejemplo n.º 1
0
    /// <summary>
    /// Immediately creates local anchor after detected marker intersects detected plane beneath it.
    /// Cloud anchor is created afterwards, but it takes some time. When it is finished, scene will be attached to it.
    /// Called if user clicks on the calibration cube displayed over detected marker.
    /// </summary>
    /// <param name="tf"></param>
    public void CreateAnchor(Transform tf)
    {
#if (UNITY_ANDROID || UNITY_IOS) && AR_ON
        ARPlane          plane   = null;
        UnityEngine.Pose hitPose = new UnityEngine.Pose();

        // try to raycast straight down to intersect closest plane
        List <ARRaycastHit> raycastHits = new List <ARRaycastHit>();
        if (ARRaycastManager.Raycast(new Ray(tf.position, Vector3.down), raycastHits, TrackableType.PlaneWithinPolygon))
        {
            hitPose = raycastHits[0].pose;
            TrackableId hitPlaneId = raycastHits[0].trackableId;
            plane = ARPlaneManager.GetPlane(hitPlaneId);
        }

        // remove all old local anchors, if there are some (in case we are recalibrating)
        RemoveLocalWorldAnchor();
        RemoveCloudWorldAnchor();

        // set temporary world anchor
        //WorldAnchorLocal = ARAnchorManager.AttachAnchor(plane,
        //    new Pose(hitPose.position, Quaternion.FromToRotation(tf.up, plane.normal) * tf.rotation));

        //WorldAnchorLocal = ARAnchorManager.AddAnchor(new UnityEngine.Pose(hitPose != new UnityEngine.Pose() ? hitPose.position : tf.position,
        //    plane != null ? Quaternion.FromToRotation(tf.up, plane.normal) * tf.rotation : tf.rotation));

        WorldAnchorLocal = ARAnchorManager.AddAnchor(new UnityEngine.Pose(tf.position,
                                                                          plane != null ? Quaternion.FromToRotation(tf.up, plane.normal) * tf.rotation : tf.rotation));

        // immediately attach scene to local anchor (after cloud anchor is created, scene will be attached to it)
        AttachScene(WorldAnchorLocal.gameObject);

        // Create cloud anchor
        if (Settings.Instance.UseCloudAnchors)
        {
            WorldAnchorCloud = ARAnchorManager.HostCloudAnchor(WorldAnchorLocal);
            StartCoroutine(HostCloudAnchor());
        }
        else
        {
            Calibrated        = true;
            UsingCloudAnchors = false;
            OnARCalibrated?.Invoke(this, new CalibrationEventArgs(true, WorldAnchorLocal.gameObject));
            Notifications.Instance.ShowNotification("Calibration successful", "");
            worldAnchorVis = null;
            ActivateCalibrationElements((bool)MainSettingsMenu.Instance.CalibrationElements.GetValue());
        }

        GameManager.Instance.SceneSetActive(true);
        ActivateTrackableMarkers(false);
#endif
    }
Ejemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        if (m_AppMode == AppMode.TouchToHostCloudReferencePoint)
        {
            OutputText.text = m_AppMode.ToString();

            if (Input.touchCount >= 1 &&
                Input.GetTouch(0).phase == TouchPhase.Began &&
                !EventSystem.current.IsPointerOverGameObject(
                    Input.GetTouch(0).fingerId))
            {
                List <ARRaycastHit> hitResults = new List <ARRaycastHit>();
                RaycastManager.Raycast(Input.GetTouch(0).position, hitResults);
                if (hitResults.Count > 0)
                {
                    Pose pose = hitResults[0].pose;

                    // dokundurulan yerde referans noktası oluşturuyor.
                    ARAnchor referencePoint =
                        AnchorManager.AddAnchor(hitResults[0].pose);

                    // bulut referans noktasını oluşturuyor.
                    m_CloudReferencePoint =
                        AnchorManager.HostCloudAnchor(referencePoint);
                    if (m_CloudReferencePoint == null)
                    {
                        OutputText.text = "Create Failed!";
                        return;
                    }

                    // Wait for the reference point to be ready.
                    m_AppMode = AppMode.WaitingForHostedReferencePoint;
                }
            }
        }
        else if (m_AppMode == AppMode.WaitingForHostedReferencePoint)
        {
            OutputText.text = m_AppMode.ToString();

            CloudAnchorState cloudReferenceState =
                m_CloudReferencePoint.cloudAnchorState;
            OutputText.text += " - " + cloudReferenceState.ToString();

            if (cloudReferenceState == CloudAnchorState.Success)
            {
                GameObject cloudAnchor = Instantiate(
                    HostedPointPrefab,
                    Vector3.zero,
                    Quaternion.identity);
                cloudAnchor.transform.SetParent(
                    m_CloudReferencePoint.transform, false);
                panel.gameObject.SetActive(true);
                m_CloudReferenceId    = m_CloudReferencePoint.cloudAnchorId;
                cloudAnchorId.text    = m_CloudReferenceId;
                m_CloudReferencePoint = null;
                m_AppMode             = AppMode.TouchToHostCloudReferencePoint;
            }
        }
    }
Ejemplo n.º 3
0
    void instantiateCloudAnchorAt(Pose pose)
    {
        // Let localAnchor = new anchor placed at "pose"
        ARAnchor localAnchor = anchorManager.AddAnchor(pose);

        // Log position of new local anchor
        if (verboseLog)
        {
            Debug.Log("Placed local anchor at: " + pose.position.ToString());
        }

        // Instantiate a new cloud anchor based off of localAnchor and push to unregisteredCloudAnchors
        unregisteredCloudAnchors.Add(anchorManager.HostCloudAnchor(localAnchor));
    }
Ejemplo n.º 4
0
    /// <summary>
    /// Immediately creates local anchor after detected marker intersects detected plane beneath it.
    /// Cloud anchor is created afterwards, but it takes some time. When it is finished, scene will be attached to it.
    /// Called if user clicks on the calibration cube displayed over detected marker.
    /// </summary>
    /// <param name="tf"></param>
    public void CreateAnchor(Transform tf)
    {
#if (UNITY_ANDROID || UNITY_IOS) && !UNITY_EDITOR
        // try to raycast straight down to intersect closest plane
        List <ARRaycastHit> raycastHits = new List <ARRaycastHit>();
        if (ARRaycastManager.Raycast(new Ray(tf.position, Vector3.down), raycastHits, TrackableType.PlaneWithinPolygon))
        {
            // remove all old local anchors, if there are some (in case we are recalibrating)
            RemoveLocalWorldAnchor();
            RemoveCloudWorldAnchor();

            Pose        hitPose    = raycastHits[0].pose;
            TrackableId hitPlaneId = raycastHits[0].trackableId;
            ARPlane     plane      = ARPlaneManager.GetPlane(hitPlaneId);

            // set temporary world anchor
            WorldAnchorLocal = ARAnchorManager.AttachAnchor(plane,
                                                            new Pose(hitPose.position, Quaternion.FromToRotation(tf.up, plane.normal) * tf.rotation));
            // immediately attach scene to local anchor (after cloud anchor is created, scene will be attached to it)
            AttachScene(WorldAnchorLocal.gameObject);

            // Create cloud anchor
            if (Settings.Instance.UseCloudAnchors)
            {
                WorldAnchorCloud = ARAnchorManager.HostCloudAnchor(WorldAnchorLocal);

                StartCoroutine(HostCloudAnchor());
            }
            else
            {
                Calibrated     = true;
                worldAnchorVis = null;
                ActivateCalibrationElements(ControlBoxManager.Instance.CalibrationElementsToggle.isOn);
            }

            GameManager.Instance.Scene.SetActive(true);

            ActivateTrackableMarkers(false);
        }
        // if there is no plane beneath detected marker then display notification about unsufficient tracking
        else
        {
            Notifications.Instance.ShowNotification("Calibration error", "Plane beneath calibration marker is not detected");
            //Play animation for moving with the device
            TrackingLostAnimation.PlayVideo(5f);
        }
#endif
    }
Ejemplo n.º 5
0
    public void onPlaceOrigin()
    {
        if (Input.touchCount > 0 && Input.touches[0].phase == TouchPhase.Began)
        {
            List <ARRaycastHit> hitResults = new List <ARRaycastHit>();
            raycastManager.Raycast(Input.touches[0].position, hitResults);

            if (hitResults.Count > 0)
            {
                CmdChangeGameState(GameState.States.WaitingForOriginRegistration);

                ARAnchor localAnchor = anchorManager.AddAnchor(hitResults[0].pose);
                origin = anchorManager.HostCloudAnchor(localAnchor);
            }
        }
    }
    public void HostAnchor()
    {
        debugtext.text = "HostAnchor executing";


        FeatureMapQuality quality = anchormanager.EstimateFeatureMapQualityForHosting(GetCameraPose());

        cloudanchor = anchormanager.HostCloudAnchor(pendingHostAnchor, 1);

        if (cloudanchor == null)
        {
            debugtext.text = "Unable to host cloud anchor";
        }
        else
        {
            anchorHostInProgress = true;
        }
    }
Ejemplo n.º 7
0
    public void HostAnchor()
    {
        //ARDebugManager.Instance.LogInfo($"HostAnchor executing");

        FeatureMapQuality quality =
            arAnchorManager.EstimateFeatureMapQualityForHosting(GetCameraPose());

        cloudAnchor = arAnchorManager.HostCloudAnchor(pendingHostAnchor, 1);

        if (cloudAnchor == null)
        {
            // ARDebugManager.Instance.LogError("Unable to host cloud anchor");
        }
        else
        {
            anchorUpdateInProgress = true;
        }
    }
Ejemplo n.º 8
0
        /// <summary>
        /// Hosts the user placed cloud anchor and associates the resulting Id with this object.
        /// </summary>
        /// <param name="anchor">The last placed anchor.</param>
        public void HostAnchor(ARAnchor anchor)
        {
            _isHost        = true;
            _shouldResolve = false;
            transform.SetParent(anchor.transform);
            _anchorMesh.SetActive(true);

            _cloudAnchor = _anchorManager.HostCloudAnchor(anchor);
            if (_cloudAnchor == null)
            {
                Debug.LogError("Failed to add Cloud Anchor.");
                _cloudAnchorsExampleController.OnAnchorHosted(
                    false, "Failed to add Cloud Anchor.");
                _shouldUpdatePoint = false;
            }
            else
            {
                _shouldUpdatePoint = true;
            }
        }
Ejemplo n.º 9
0
    // 클라우드 앵커 등록
    void HostProcessing()
    {
        // 로컬 앵커가 생성되지 않았을 때 리턴
        if (localAnchor == null)
        {
            return;
        }

        // 피쳐 포인트의 갯수 많을 수록 맵핑 퀄리티가 증가함.

        /*
         *  Insufficient = 0 // 불충분
         *  Sufficient   = 1 // 충분
         *  Good         = 2 // Good
         */
        FeatureMapQuality quality
            = anchorManager.EstimateFeatureMapQualityForHosting(GetCameraPose());

        string mappingText = string.Format("맵핑 품질 = {0}", quality);

        // 맵핑 퀄리티가 1이상일 때 호스팅 요청
        if (quality == FeatureMapQuality.Sufficient || quality == FeatureMapQuality.Good)
        {
            // Google Cloud Anchor API를 사용해 업로드(클라우드 앵커의 생성을 요청)
            cloudAnchor = anchorManager.HostCloudAnchor(localAnchor, 1);

            if (cloudAnchor == null)
            {
                mappingText = "클라우드 앵커 생성 실패";
            }
            else
            {
                mappingText = "클라우드 앵커 생성 시작";
                mode        = Mode.HOST_PENDING;
            }
        }

        messageText.text = mappingText;
    }
Ejemplo n.º 10
0
    public IEnumerator ParasiteCloud()
    {
        check = true;

        yield return(new WaitForSeconds(5));

        cloudanchor = anchorManager.HostCloudAnchor(anchor);


        if (cloudanchor != null)
        {
            Instantiate(anchorprefeb, cloudanchor.transform);
            StartCoroutine(CloudState());
            pendingcloudanchor.Add(cloudanchor);
        }
        else
        {
            checktext.text = "실패 : " + count;
        }



        check = false;
    }
Ejemplo n.º 11
0
 public void HostAnchor(int index)
 {
     _arDebugManager.LogInfo($"HostAnchor executing #" + (index + 1).ToString());
     cloudAnchorList[index] = _arAnchorManager.HostCloudAnchor(pendingHostAnchorList[index], 1);
 }
Ejemplo n.º 12
0
    void Update()
    {
        if (m_AppMode == AppMode.TouchToHostCloudAnchor)
        {
            OutputText.text = m_AppMode.ToString();

            if (Input.touchCount >= 1 &&
                Input.GetTouch(0).phase == TouchPhase.Began &&
                !EventSystem.current.IsPointerOverGameObject(
                    Input.GetTouch(0).fingerId))
            {
                List <ARRaycastHit> hitResults = new List <ARRaycastHit>();
                RaycastManager.Raycast(Input.GetTouch(0).position, hitResults);
                if (hitResults.Count > 0)
                {
                    Pose pose = hitResults[0].pose;

                    // Create a reference point at the touch.
                    ARAnchor anchor =
                        AnchorManager.AddAnchor(
                            hitResults[0].pose);

                    // Create Cloud Reference Point.
                    m_CloudAnchor =
                        AnchorManager.HostCloudAnchor(
                            anchor);
                    if (m_CloudAnchor == null)
                    {
                        OutputText.text = "Create Failed!";
                        return;
                    }

                    // Wait for the reference point to be ready.
                    m_AppMode = AppMode.WaitingForHostedAnchor;
                }
            }
        }
        else if (m_AppMode == AppMode.WaitingForHostedAnchor)
        {
            OutputText.text = m_AppMode.ToString();

            CloudAnchorState cloudAnchorState =
                m_CloudAnchor.cloudAnchorState;
            OutputText.text += " - " + cloudAnchorState.ToString();

            if (cloudAnchorState == CloudAnchorState.Success)
            {
                GameObject cloudAnchor = Instantiate(
                    HostedPointPrefab,
                    Vector3.zero,
                    Quaternion.identity);
                cloudAnchor.transform.SetParent(
                    m_CloudAnchor.transform, false);

                cloudAnchorIdQueue.Enqueue(m_CloudAnchor.cloudAnchorId);
                StartCoroutine(saveAnchor(m_CloudAnchor.cloudAnchorId, GPS.Instance.latitude, GPS.Instance.longitude));
                createMessage(m_CloudAnchor.cloudAnchorId);
                m_CloudAnchor = null;

                m_AppMode = AppMode.ResolveCloudAnchor;
            }
        }
        else if (m_AppMode == AppMode.ResolveCloudAnchor)
        {
            OutputText.text = m_AppMode.ToString();
            //if there is a breadcrumb left to load
            if (cloudAnchorIdQueue.Count >= 1)
            {
                m_CloudAnchorId = cloudAnchorIdQueue.Dequeue();
                OutputText.text = m_CloudAnchorId;
                m_CloudAnchor   = AnchorManager.ResolveCloudAnchorId(m_CloudAnchorId);
                startTime       = DateTime.Now;

                if (m_CloudAnchor == null)
                {
                    OutputText.text = "Resolve Failed!";
                    m_CloudAnchorId = string.Empty;
                    //m_AppMode = AppMode.TouchToHostCloudAnchor;
                    return;
                }

                m_CloudAnchorId = string.Empty;

                // Wait for the reference point to be ready.
                m_AppMode = AppMode.WaitingForResolvedAnchor;
            }
            else
            {
                //if the queue is empty, return to placing anchors
                m_AppMode = AppMode.TouchToHostCloudAnchor;
            }
        }
        else if (m_AppMode == AppMode.WaitingForResolvedAnchor)
        {
            OutputText.text = m_AppMode.ToString();

            CloudAnchorState cloudAnchorState =
                m_CloudAnchor.cloudAnchorState;
            OutputText.text += " - " + cloudAnchorState.ToString();

            if (cloudAnchorState == CloudAnchorState.Success)
            {
                GameObject cloudAnchor = Instantiate(
                    ResolvedPointPrefab,
                    Vector3.zero,
                    Quaternion.identity);
                cloudAnchor.transform.SetParent(
                    m_CloudAnchor.transform, false);

                StartCoroutine(getMessage(m_CloudAnchor.cloudAnchorId, cloudAnchor.GetComponentInChildren <Text>()));

                m_CloudAnchor = null;

                if (cloudAnchorIdQueue.Count <= 0)
                {
                    //if there are no more anchors to process, go back to placing anchors
                    m_AppMode = AppMode.TouchToHostCloudAnchor;
                }
                else
                {
                    //if there are more anchors to resolve, do that.
                    m_AppMode = AppMode.ResolveCloudAnchor;
                }
            }
            else if (cloudAnchorState == CloudAnchorState.TaskInProgress)
            {
                if (startTime.HasValue && (DateTime.Now - startTime.Value).TotalSeconds >= maxWait)
                {
                    m_CloudAnchor = null;

                    if (cloudAnchorIdQueue.Count <= 0)
                    {
                        //if there are no more anchors to process, go back to placing anchors
                        m_AppMode = AppMode.TouchToHostCloudAnchor;
                    }
                    else
                    {
                        //if there are more anchors to resolve, do that.
                        m_AppMode = AppMode.ResolveCloudAnchor;
                    }
                }
            }
            else if (cloudAnchorState == CloudAnchorState.ErrorResolvingCloudIdNotFound)
            {
                m_CloudAnchor = null;

                if (cloudAnchorIdQueue.Count <= 0)
                {
                    //if there are no more anchors to process, go back to placing anchors
                    m_AppMode = AppMode.TouchToHostCloudAnchor;
                }
                else
                {
                    //if there are more anchors to resolve, do that.
                    m_AppMode = AppMode.ResolveCloudAnchor;
                }
            }
        }
        else if (m_AppMode == AppMode.WaitingForQueue)
        {
            if (isQueueReady)
            {
                m_AppMode = AppMode.ResolveCloudAnchor;
                return;
            }
            //check if the gps has initialized and the populate coroutine has not started
            else if (!isQueueStarted && GPS.Instance.latitude != 0)
            {
                StartCoroutine(PopulateAnchorQueue(GPS.Instance.latitude, GPS.Instance.longitude));
                isQueueStarted = true;
            }
        }
    }
Ejemplo n.º 13
0
    // Update is called once per frame
    void Update()
    {
        if (m_AppMode == AppMode.TouchToHostCloudReferencePoint)
        {
            OutputText.text = m_AppMode.ToString();

            // If the user presses a non-ui part of the screen
            if (Input.touchCount >= 1 && Input.GetTouch(0).phase == TouchPhase.Began && !EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId))
            {
                // Raycast where the user touched the screen
                List <ARRaycastHit> hitResults = new List <ARRaycastHit>();
                RaycastManager.Raycast(Input.GetTouch(0).position, hitResults);

                // If the user touched a surface in AR
                if (hitResults.Count > 0)
                {
                    // Create a cloud anchor where the user touches in world space
                    Pose     pose     = hitResults[0].pose;
                    ARAnchor m_anchor = AnchorManager.AddAnchor(pose);
                    m_CloudAnchor = AnchorManager.HostCloudAnchor(m_anchor);

                    if (m_CloudAnchor == null)
                    {
                        Debug.LogError("Create Failed!");
                        return;
                    }

                    // Flag program to wait for the cloud anchor to register
                    m_AppMode = AppMode.WaitingForHostedReferencePoint;
                }
            }
        }
        else if (m_AppMode == AppMode.WaitingForHostedReferencePoint)
        {
            OutputText.text = m_AppMode.ToString();

            CloudAnchorState cloudAnchorState = m_CloudAnchor.cloudAnchorState;

            OutputText.text += " - " + cloudAnchorState.ToString();

            if (cloudAnchorState == CloudAnchorState.Success)
            {
                // Place a HostedPointPrefab where the cloud anchor successfully spawned
                GameObject cloudAnchor = Instantiate(HostedPointPrefab, Vector3.zero, Quaternion.identity);
                cloudAnchor.transform.SetParent(m_CloudAnchor.transform, false);

                m_CloudReferenceId = m_CloudAnchor.cloudAnchorId;

                // Make the user resolve the anchor next
                m_AppMode = AppMode.TouchToResolveCloudReferencePoint;
            }
        }
        else if (m_AppMode == AppMode.TouchToResolveCloudReferencePoint)
        {
            OutputText.text = m_CloudReferenceId;

            // If the user taps the screen
            if (Input.touchCount >= 1 && Input.GetTouch(0).phase == TouchPhase.Began && !EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId))
            {
                // Attempt to resolve the anchor that you just instantiated
                m_CloudAnchor = AnchorManager.ResolveCloudAnchorId(m_CloudReferenceId);

                if (m_CloudAnchor == null)
                {
                    OutputText.text    = "Resolve failed!";
                    m_CloudReferenceId = string.Empty;
                    m_AppMode          = AppMode.TouchToHostCloudReferencePoint;
                    return;
                }

                m_CloudReferenceId = string.Empty;

                m_AppMode = AppMode.WaitingForResolvedReferencePoint;
            }
        }
        else if (m_AppMode == AppMode.WaitingForResolvedReferencePoint)
        {
            OutputText.text = m_AppMode.ToString();

            CloudAnchorState cloudAnchorState = m_CloudAnchor.cloudAnchorState;

            if (cloudAnchorState == CloudAnchorState.Success)
            {
                GameObject cloudAnchor = Instantiate(ResolvedPointPrefab, Vector3.zero, Quaternion.identity);
                cloudAnchor.transform.SetParent(m_CloudAnchor.transform, false);

                m_CloudAnchor = null;
                m_AppMode     = AppMode.TouchToHostCloudReferencePoint;
            }
            else if (cloudAnchorState != CloudAnchorState.TaskInProgress)
            {
                OutputText.text = "Invalid ID";
                m_AppMode       = AppMode.TouchToHostCloudReferencePoint;
            }

            Debug.Log(m_CloudReferenceId);
        }
    }