Esempio n. 1
0
    private void OnAnchorLocated(object sender, AnchorLocatedEventArgs args)
    {
        UnityEngine.WSA.Application.InvokeOnAppThread(
            async() =>
        {
            if (isDeleteProcess)
            {
                await cloudAnchorSession.DeleteAnchorAsync(args.Anchor);
            }
            else
            {
                var cube = GameObject.CreatePrimitive(PrimitiveType.Cube);

                cube.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);

                cube.GetComponent <Renderer>().material = this.relocalizedCubeMaterial;

                var worldAnchor = cube.AddComponent <WorldAnchor>();

                worldAnchor.SetNativeSpatialAnchorPtr(args.Anchor.LocalAnchor);

                cube.name = args.Identifier;

                cubes.Add(cube);
            }
        },
            false
            );
    }
Esempio n. 2
0
        private void SpatialAnchorsSession_AnchorLocated(object sender, AnchorLocatedEventArgs e)
        {
            LocateAnchorStatus status = e.Status;

            switch (status)
            {
            case LocateAnchorStatus.AlreadyTracked:
                break;

            case LocateAnchorStatus.Located:
            {
                CloudSpatialAnchor anchor = e.Anchor;
                Debug.WriteLine("Cloud Anchor found! Identifier : " + anchor.Identifier);
                AnchorVisual visual = new AnchorVisual
                {
                    cloudAnchor = anchor,
                    identifier  = anchor.Identifier,
                    localAnchor = anchor.LocalAnchor
                };
                this.anchorVisuals[visual.identifier] = visual;
                this.sceneView.Session.AddAnchor(anchor.LocalAnchor);
                this.PlaceCube(visual.localAnchor);
                break;
            }

            case LocateAnchorStatus.NotLocated:
            case LocateAnchorStatus.NotLocatedAnchorDoesNotExist:
                break;
            }

            this.OnAnchorLocated?.Invoke(sender, e);
        }
Esempio n. 3
0
 private void CloudManager_AnchorLocated(object sender, AnchorLocatedEventArgs args)
 {
     if (args.Status == LocateAnchorStatus.Located)
     {
         OnCloudAnchorLocated(args);
     }
 }
Esempio n. 4
0
    private void CloudSpatialAnchorSession_AnchorLocated(object sender, AnchorLocatedEventArgs args)
    {
        OnAnchorLocated?.Invoke(sender, args);
        UnityEngine.WSA.Application.InvokeOnAppThread(
            () =>
        {
            GameObject cube = this.gameObject;

            var oldWorldAnchor = cube.GetComponent <WorldAnchor>();
            // remove any world anchor component from the game object so that it can be moved
            if (oldWorldAnchor)
            {
                DestroyImmediate(oldWorldAnchor);
            }

            cube.transform.localScale = new Vector3(0.2f, 0.2f, 0.2f);

            var worldAnchor = cube.AddComponent <WorldAnchor>();


            worldAnchor.SetNativeSpatialAnchorPtr(args.Anchor.LocalAnchor);

            feedback.transform.position = cube.transform.position;

            cube.name = args.Identifier;
        },
            false
            );
    }
Esempio n. 5
0
    /// <summary>
    /// Callback function that is executed when an anchor is located.
    /// </summary>
    private void CloudSpatialAnchorSession_AnchorLocated(object sender, AnchorLocatedEventArgs args)
    {
        switch (args.Status)
        {
        case LocateAnchorStatus.Located:
            Debug.Log("ASA Info: Anchor located! Identifier: " + args.Identifier);
            UnityDispatcher.InvokeOnAppThread(() =>
            {
                // Create a green sphere.
                var worldAnchor = SharedWorldAnchor.Instance.gameObject.AddComponent <WorldAnchor>();

                // Get the WorldAnchor from the CloudSpatialAnchor and use it to position the sphere.
                worldAnchor.SetNativeSpatialAnchorPtr(args.Anchor.LocalAnchor);
            });
            break;

        case LocateAnchorStatus.AlreadyTracked:
            Debug.Log("ASA Info: Anchor already tracked. Identifier: " + args.Identifier);
            break;

        case LocateAnchorStatus.NotLocated:
            Debug.Log("ASA Info: Anchor not located. Identifier: " + args.Identifier);
            break;

        case LocateAnchorStatus.NotLocatedAnchorDoesNotExist:
            Debug.LogError("ASA Error: Anchor not located does not exist. Identifier: " + args.Identifier);
            break;
        }

        // Clear Anchor Watcher
        AnchorWatcher = null;
    }
Esempio n. 6
0
        protected override void OnCloudAnchorLocated(AnchorLocatedEventArgs args)
        {
            base.OnCloudAnchorLocated(args);

            CloudSpatialAnchor nextCsa = args.Anchor;

            this.currentCloudAnchor = args.Anchor;

            this.QueueOnUpdate(new Action(() =>
            {
                this.anchorsLocated++;
                this.currentCloudAnchor = nextCsa;
                Pose anchorPose         = Pose.identity;

#if UNITY_ANDROID || UNITY_IOS
                anchorPose = this.currentCloudAnchor.GetAnchorPose();
#endif
                // HoloLens: The position will be set based on the unityARUserAnchor that was located.

                GameObject nextObject = this.SpawnNewAnchoredObject(anchorPose.position, anchorPose.rotation, this.currentCloudAnchor);
                this.AttachTextMesh(nextObject, _anchorNumberToFind);
                this.otherSpawnedObjects.Add(nextObject);

                if (this.anchorsLocated >= this.anchorsExpected)
                {
                    this.currentAppState = AppState.DemoStepStopSessionForQuery;
                }
            }));
        }
Esempio n. 7
0
        /// <summary>
        /// Called when an anchor is found
        /// </summary>
        private void OnAnchorLocated(object sender, AnchorLocatedEventArgs e)
        {
            if (e.Status == LocateAnchorStatus.AlreadyTracked)
            {
                // Nothing to do since we've already rendered any anchors we've located.
            }
            else if (e.Status == LocateAnchorStatus.Located)
            {
                var anchor = e.Anchor;
                var model  = new AnchorModel
                {
                    CloudAnchor = anchor,
                    LocalAnchor = anchor.LocalAnchor
                };
                this.anchorVisuals[anchor.Identifier] = model;
                this.sceneView.Session.AddAnchor(anchor.LocalAnchor);

                var modelNode = LoadModel();
                if (modelNode != null)
                {
                    modelNode.Position = model.LocalAnchor.Transform.ToPosition();
                    this.sceneView.Scene.RootNode.AddChildNode(modelNode);
                }
            }
        }
        protected override void OnCloudAnchorLocated(AnchorLocatedEventArgs args)
        {
            base.OnCloudAnchorLocated(args);

            if (args.Status == LocateAnchorStatus.Located)
            {
                UnityDispatcher.InvokeOnAppThread(() =>
                {
                    locatedCount++;
                    currentCloudAnchor = args.Anchor;

                    Pose anchorPose = Pose.identity;

                    #if UNITY_ANDROID || UNITY_IOS
                    anchorPose = currentCloudAnchor.GetPose();
                    #endif
                    // HoloLens: The position will be set based on the unityARUserAnchor that was located.

                    SpawnOrMoveCurrentAnchoredObject(anchorPose.position, anchorPose.rotation);

                    spawnedObject.transform.localScale += scaleMods[(int)currentAppState];
                    spawnedObject = null;

                    if (currentAppState == AppState.Searching)
                    {
                        currentAppState = AppState.ReadyToNeighborQuery;
                    }
                });
            }
        }
Esempio n. 9
0
    private void CloudSpatialAnchorSession_AnchorLocated(object sender, AnchorLocatedEventArgs args)
    {
        UnityEngine.WSA.Application.InvokeOnAppThread(() =>
        {
            switch (args.Status)
            {
            case LocateAnchorStatus.Located:
                Debug.Log("ASA Info: アンカーが見つかりました! Identifier: " + args.Identifier);
                // CloudSpatialAnchorからWorldAnchorを取得し、それを使ってモデルを配置
                m_labModel.AddComponent <WorldAnchor>();
                m_labModel.GetComponent <WorldAnchor>().SetNativeSpatialAnchorPtr(args.Anchor.LocalAnchor);
                break;

            case LocateAnchorStatus.AlreadyTracked:
                Debug.Log("ASA Info: アンカーは既に読み取られています。 Identifier: " + args.Identifier);
                break;

            case LocateAnchorStatus.NotLocated:
                Debug.Log("ASA Info: アンカーが見つかりません。 Identifier: " + args.Identifier);
                break;

            case LocateAnchorStatus.NotLocatedAnchorDoesNotExist:
                Debug.LogError("ASA Error: アンカーが見つかりません - 削除されたか、照会された識別子が正しくありません。 Identifier: " + args.Identifier);
                break;
            }
        }, false);
    }
Esempio n. 10
0
        protected override void OnCloudAnchorLocated(AnchorLocatedEventArgs args)
        {
            base.OnCloudAnchorLocated(args);

            if (args.Status == LocateAnchorStatus.Located)
            {
                UnityDispatcher.InvokeOnAppThread(() =>
                {
                    foundId = args.Anchor.Identifier;

                    currentCloudAnchor = args.Anchor;

                    Pose anchorPose = Pose.identity;


                    anchorPose = currentCloudAnchor.GetPose();


                    spawnedObject      = null;
                    currentCloudAnchor = null;



                    feedbackBox.text = "Anchor Found!";


                    SpawnOrMoveCurrentAnchoredObject(anchorPose.position, anchorPose.rotation);
                });
            }
        }
        protected override void OnCloudAnchorLocated(AnchorLocatedEventArgs args)
        {
            base.OnCloudAnchorLocated(args);
            Debug.Log("Located:" + args.Status + " , " + args.Identifier);
            if (args.Status == LocateAnchorStatus.Located)
            {
                CloudSpatialAnchor cloudAnchor = args.Anchor;


                UnityDispatcher.InvokeOnAppThread(() =>
                {
                    currentAppState = AppState.DemoStepStopWatcher;
                    Pose anchorPose = Pose.identity;

#if UNITY_ANDROID || UNITY_IOS
                    // anchorPose = currentCloudAnchor.GetPose();
#endif

                    // HoloLens: The position will be set based on the unityARUserAnchor that was located.
                    GameObject spawnedObject = SpawnNewAnchoredObject(anchorPose.position, anchorPose.rotation, cloudAnchor);
                    allDiscoveredAnchors.Add(spawnedObject);
                    anchorIdsToLocate.Add(args.Identifier);
                });
            }
        }
    private void CloudManager_OnAnchorLocated(object sender, AnchorLocatedEventArgs args)
    {
        Debug.LogFormat("Anchor recognized as a possible anchor {0} {1}", args.Identifier, args.Status);
        if (args.Status == LocateAnchorStatus.Located)
        {
            //this.OnCloudAnchorLocated(args);

            CloudSpatialAnchor nextCsa = args.Anchor;
            this.currentCloudAnchor = args.Anchor;


            this.QueueOnUpdate(new Action(() =>
            {
                this.anchorsLocated++;
                this.currentCloudAnchor = nextCsa;
                Pose anchorPose         = Pose.identity;

#if UNITY_ANDROID || UNITY_IOS
                anchorPose = this.currentCloudAnchor.GetAnchorPose();
#endif
                // HoloLens: The position will be set based on the unityARUserAnchor that was located.

                GameObject nextObject = this.SpawnNewAnchoredObject(anchorPose.position, anchorPose.rotation, this.currentCloudAnchor);
                //this.AttachTextMesh(nextObject, _anchorNumberToFind);
                this.otherSpawnedObjects.Add(nextObject);

                //if (this.anchorsLocated >= this.anchorsExpected)
                //{
                //    //this.currentAppState = AppState.DemoStepStopSessionForQuery;
                //}
            }));
        }
    }
Esempio n. 13
0
        protected override void OnCloudAnchorLocated(AnchorLocatedEventArgs args)
        {
            base.OnCloudAnchorLocated(args);

            if (args.Status == LocateAnchorStatus.Located)
            {
                CloudSpatialAnchor nextCsa = args.Anchor;
                currentCloudAnchor = args.Anchor;

                UnityDispatcher.InvokeOnAppThread(() =>
                {
                    anchorsLocated++;
                    currentCloudAnchor = nextCsa;
                    Pose anchorPose    = Pose.identity;

                    #if UNITY_ANDROID || UNITY_IOS
                    anchorPose = currentCloudAnchor.GetPose();
                    #endif
                    // HoloLens: The position will be set based on the unityARUserAnchor that was located.

                    GameObject nextObject = SpawnNewAnchoredObject(anchorPose.position, anchorPose.rotation, currentCloudAnchor);
                    spawnedObjectMat      = nextObject.GetComponent <MeshRenderer>().material;
                    AttachTextMesh(nextObject, _anchorNumberToFind);
                    otherSpawnedObjects.Add(nextObject);

                    if (anchorsLocated >= anchorsExpected)
                    {
                        currentAppState = AppState.DemoStepStopSessionForQuery;
                    }
                });
            }
        }
        protected override void OnCloudAnchorLocated(AnchorLocatedEventArgs args)
        {
            base.OnCloudAnchorLocated(args);

            this.QueueOnUpdate(() =>
            {
                this.locatedCount++;
                this.currentCloudAnchor = args.Anchor;
                Pose anchorPose         = Pose.identity;

#if UNITY_ANDROID || UNITY_IOS
                anchorPose = this.currentCloudAnchor.GetAnchorPose();
#endif
                // HoloLens: The position will be set based on the unityARUserAnchor that was located.

                this.SpawnOrMoveCurrentAnchoredObject(anchorPose.position, anchorPose.rotation);

                this.spawnedObject.transform.localScale += this.scaleMods[(int)this.currentAppState];
                this.spawnedObject = null;

                if (this.currentAppState == AppState.Graphing)
                {
                    if (this.spawnedObjectsInCurrentAppState.Count == this.anchorIds.Count)
                    {
                        this.currentAppState = AppState.ReadyToSearch;
                    }
                }
                else if (this.currentAppState == AppState.Searching)
                {
                    this.currentAppState = AppState.ReadyToNeighborQuery;
                }
            });
        }
Esempio n. 15
0
        void OnAnchorLocated(object sender, AnchorLocatedEventArgs args)
        {
            Debug.Log($"On Anchor Located, status is {args.Status} anchor is {args.Anchor?.Identifier}, pointer is {args.Anchor?.LocalAnchor}");
            Debug.Assert(this.taskWaitForAnchorLocation != null);

            this.taskWaitForAnchorLocation.SetResult(args.Anchor);
        }
    protected override void OnCloudAnchorLocated(AnchorLocatedEventArgs args)
    {
        base.OnCloudAnchorLocated(args);

        if (args.Status == LocateAnchorStatus.Located)
        {
            currentCloudAnchor = args.Anchor;

            UnityDispatcher.InvokeOnAppThread(() =>
            {
                Pose anchorPose = Pose.identity;

#if UNITY_ANDROID || UNITY_IOS
                anchorPose = currentCloudAnchor.GetPose();
#endif

                NotificationManager.Instance.GenerateSuccess("Anchor found : " + args.Identifier);
                loaderPanel.SetActive(false);
                // localizeButton.SetActive(false);

                // HoloLens: The position will be set based on the unityARUserAnchor that was located.
                SpawnOrMoveCurrentAnchoredObject(anchorPose.position, anchorPose.rotation);
                // currentAppState = AppState.DemoStepDeleteFoundAnchor;
            });
        }
    }
Esempio n. 17
0
    private void CloudSpatialAnchorSession_AnchorLocated(object sender, AnchorLocatedEventArgs args)
    {
        switch (args.Status)
        {
        case LocateAnchorStatus.Located:
            DispatcherQueue.Enqueue(async() =>
            {
                // Instantiate the Prefab
                _prefabInstance = GameObject.Instantiate(Prefab, Vector3.zero, Quaternion.identity) as GameObject;
                var localAnchor = _prefabInstance.AddComponent <WorldAnchor>();

                // Get the WorldAnchor from the CloudSpatialAnchor and assign it to the local anchor
                localAnchor.SetNativeSpatialAnchorPtr(args.Anchor.LocalAnchor);

                // Delete the ASA anchor Clean up state so that we can start over and create a new anchor.
                await _cloudSpatialAnchorSession.DeleteAnchorAsync(args.Anchor);
                _currentCloudAnchorId = String.Empty;
                _wasTapped            = false;
                Log($"Anchor located: {args.Identifier}\r\nGaze and tap to place a new anchor.", Color.green);
            });
            break;

        case LocateAnchorStatus.AlreadyTracked:
            Log($"ASA Anchor already tracked: {args.Identifier}", Color.magenta);
            break;

        case LocateAnchorStatus.NotLocated:
            Log($"ASA Anchor not located : {args.Identifier}", Color.magenta);
            break;

        case LocateAnchorStatus.NotLocatedAnchorDoesNotExist:
            Log($"ASA Anchor not located -> Does not exist: {args.Identifier}", Color.red);
            break;
        }
    }
    private void CloudSpatialAnchorSession_AnchorLocated(object sender, AnchorLocatedEventArgs args)
    {
        switch (args.Status)
        {
        case LocateAnchorStatus.Located:
            Debug.Log("ASA Info: Anchor located! Identifier: " + args.Identifier);
            // Create a green sphere.
            QueueOnUpdate(() =>
            {
                GameObject refObj = GameObject.Find("RefernceSceneBuilder");
                indicator.AddComponent <WorldAnchor>();
                Material indicatorMaterial = indicator.GetComponent <MeshRenderer>().material;
                indicatorMaterial.color    = Color.green;

                // Get the WorldAnchor from the CloudSpatialAnchor and use it to position the sphere.
                refObj.GetComponent <UnityEngine.XR.WSA.WorldAnchor>().SetNativeSpatialAnchorPtr(args.Anchor.LocalAnchor);

                // Clean up state so that we can start over and create a new anchor.
                //cloudSpatialAnchorId = "";
            });
            break;

        case LocateAnchorStatus.AlreadyTracked:
            Debug.Log("ASA Info: Anchor already tracked. Identifier: " + args.Identifier);
            break;

        case LocateAnchorStatus.NotLocated:
            Debug.Log("ASA Info: Anchor not located. Identifier: " + args.Identifier);
            break;

        case LocateAnchorStatus.NotLocatedAnchorDoesNotExist:
            Debug.LogError("ASA Error: Anchor not located does not exist. Identifier: " + args.Identifier);
            break;
        }
    }
Esempio n. 19
0
        private void CloudManager_OnAnchorLocated(object sender, AnchorLocatedEventArgs args)
        {
            Debug.LogFormat("anchor recognized as a possible anchor {0} {1}", args.Identifier, args.Status);
            if (args.Status == LocateAnchorStatus.Located || args.Status == LocateAnchorStatus.AlreadyTracked)
            {
                if (!_cloudAnchors.Contains(args.Anchor))
                {
                    _cloudAnchors.Add(args.Anchor);
                }

                lock (_dispatchQueue)
                {
                    _dispatchQueue.Enqueue(new Action(() =>
                    {
                        var result         = new AnchorLocatedResult();
                        result.CloudAnchor = args.Anchor;
                        result.Anchor      = _anchors.FirstOrDefault(a => a.id == args.Identifier);

                        Pose anchorPose = Pose.identity;

#if UNITY_ANDROID || UNITY_IOS
                        anchorPose = args.Anchor.GetAnchorPose();
#endif
                        result.SpawnData = new SpawnData()
                        {
                            Position = anchorPose.position, Rotation = anchorPose.rotation
                        };

                        BroadcastMessage("OnAnchorLocated", result);
                    }));
                }
            }
        }
        protected override void OnCloudAnchorLocated(AnchorLocatedEventArgs args)
        {
            base.OnCloudAnchorLocated(args);

            Debug.Log("about to check expiration");
            // if ((args != null) && (args.Anchor != null))
            //    Debug.Log("Expiration Date for this anchor is " + args.Anchor.Expiration);


            if (args.Status == LocateAnchorStatus.Located)
            {
                CloudSpatialAnchor nextCsa = args.Anchor;
                currentCloudAnchor = args.Anchor;
                //         Debug.Log("Expiration Date for this anchor is " + nextCsa.Expiration);


                UnityDispatcher.InvokeOnAppThread(() =>
                {
                    anchorsLocated++;
                    currentCloudAnchor = nextCsa;
                    Pose anchorPose    = Pose.identity;

#if UNITY_ANDROID || UNITY_IOS
                    anchorPose = currentCloudAnchor.GetPose();
#endif
                    // HoloLens: The position will be set based on the unityARUserAnchor that was located.

                    GameObject nextObject = SpawnNewAnchoredObject(anchorPose.position, anchorPose.rotation, currentCloudAnchor);
                    //spawnedObjectMat = nextObject.GetComponent<MeshRenderer>().material;
                    Debug.Log("Setting goal in shareddemo");
                    // Will only begin if it hasn't yet started.



                    //GameObject.Find("arrow").GetComponent<moveTo>().setGoal(nextObject.transform, nextObject.name);

#if !UNITY_EDITOR
                    //Instead of setting anchor is up as destination, add the game object to the flag list for later use
                    GameObject.Find("listOfFlagsGameObj_CombinedExperience").GetComponent <ListOps>().addFlag(nextObject);
                    Debug.Log("********************************************added next Object: " + nextObject.transform.position + ". Main camera's location is " + Camera.main.transform.position + ". other position is " + GameObject.Find("CameraParent").transform.position);
                    beginNav();

                    // Only start navigation if there are destination flags

                    //      AttachTextMesh(nextObject, _anchorNumberToFind);
#endif
                    otherSpawnedObjects.Add(nextObject);
                    Debug.Log("Adding " + nextObject);

                    if (anchorsLocated >= this.getNbrDestAnchors())
                    {
                        currentAppState = AppState.DemoStepStopSessionForQuery;
                    }
                    else
                    {
                        Debug.Log("only " + anchorsLocated + " anchors have so far been located");
                    }
                });
            }
        }
Esempio n. 21
0
    public override void OnCloudAnchorLocated(AnchorLocatedEventArgs args)
    {
        CloudSpatialAnchor cloudAnchor = args.Anchor;

        // callback is sometimes called multiple times for the same anchor, so we ensure only one object is instantiated per anchor ID
        if (!instantiatedAnchorIds.Contains(args.Identifier))
        {
            // load recording
            string        recordingId     = anchorStore.GetRecordingId(args.Identifier);
            HoloRecording loadedRecording = LoadHoloRecording(recordingId);

            // Instantiate anchored object - will be the parent object of hands recording and representation
            GameObject  anchoredObject = new GameObject();
            WorldAnchor wa             = anchoredObject.AddComponent <WorldAnchor>();
            wa.SetNativeSpatialAnchorPtr(cloudAnchor.LocalAnchor);

            // instantiate representation and pass the recording to it
            Vector3 newRepLocation = new Vector3(loadedRecording.positionXRep, loadedRecording.positionYRep, loadedRecording.positionZRep);
            InstantiateRecordingRepresentation(ref anchoredObject, atLocation: newRepLocation, atPalm: false);

            HoloPlayerBehaviour playerComponent = recordingRepresentationInstance.GetComponent <HoloPlayerBehaviour>();
            playerComponent.PutHoloRecordingIntoPlayer(recordingId, loadedRecording, anchoredObject, anchorStore, openKeyboard: false);

            // Mark already instantiated Anchor Ids so that nothing is instantiated more than once.
            instantiatedAnchorIds.Add(args.Identifier);
        }
    }
Esempio n. 22
0
    private void MoveObjectUsingAppProperties(Transform obj, AnchorLocatedEventArgs args, int id)
    {
        Vector3 pos = Vector3.zero;

        pos.x = float.Parse(args.Anchor.AppProperties[id.ToString() + "-posX"]);
        pos.y = float.Parse(args.Anchor.AppProperties[id.ToString() + "-posY"]);
        pos.z = float.Parse(args.Anchor.AppProperties[id.ToString() + "-posZ"]);

        Vector3 scale = Vector3.zero;

        scale.x = float.Parse(args.Anchor.AppProperties[id.ToString() + "-scaleX"]);
        scale.y = float.Parse(args.Anchor.AppProperties[id.ToString() + "-scaleY"]);
        scale.z = float.Parse(args.Anchor.AppProperties[id.ToString() + "-scaleZ"]);

        Quaternion rot = Quaternion.identity;

        rot.x = float.Parse(args.Anchor.AppProperties[id.ToString() + "-rotX"]);
        rot.y = float.Parse(args.Anchor.AppProperties[id.ToString() + "-rotY"]);
        rot.z = float.Parse(args.Anchor.AppProperties[id.ToString() + "-rotZ"]);
        rot.w = float.Parse(args.Anchor.AppProperties[id.ToString() + "-rotW"]);

        obj.transform.localPosition = pos;
        obj.transform.localScale    = scale;
        obj.transform.localRotation = rot;
    }
Esempio n. 23
0
 private void CloudManager_AnchorLocated(object sender, AnchorLocatedEventArgs args)
 {
     Debug.LogFormat("Anchor recognized as a possible anchor {0} {1}", args.Identifier, args.Status);
     if (args.Status == LocateAnchorStatus.Located)
     {
         OnCloudAnchorLocated(args);
     }
 }
Esempio n. 24
0
    private void CloudManager_AnchorLocated(object sender, AnchorLocatedEventArgs args)
    {
        QueueOnUpdate(new Action(() => Debug.Log($"Anchor recognized as a possible Azure anchor")));

        if (args.Status == LocateAnchorStatus.Located || args.Status == LocateAnchorStatus.AlreadyTracked)
        {
            currentCloudAnchor = args.Anchor;

            QueueOnUpdate(() =>
            {
                Debug.Log($"Azure anchor located successfully");

                // Notify AnchorFeedbackScript
                OnASAAnchorLocated?.Invoke();

#if UNITY_ANDROID || UNITY_IOS
                Pose anchorPose = Pose.identity;
                anchorPose      = currentCloudAnchor.GetPose();
#endif

#if WINDOWS_UWP || UNITY_WSA
                // HoloLens: The position will be set based on the unityARUserAnchor that was located.

                // Create a local anchor at the location of the object in question
                gameObject.CreateNativeAnchor();

                // Notify AnchorFeedbackScript
                OnCreateLocalAnchor?.Invoke();

                // On HoloLens, if we do not have a cloudAnchor already, we will have already positioned the
                // object based on the passed in worldPos/worldRot and attached a new world anchor,
                // so we are ready to commit the anchor to the cloud if requested.
                // If we do have a cloudAnchor, we will use it's pointer to setup the world anchor,
                // which will position the object automatically.
                if (currentCloudAnchor != null)
                {
                    Debug.Log("Local anchor position successfully set to Azure anchor position");

                    gameObject.GetComponent <UnityEngine.XR.WSA.WorldAnchor>().SetNativeSpatialAnchorPtr(currentCloudAnchor.LocalAnchor);
                }
#else
                Debug.Log($"Setting object to anchor pose with position '{anchorPose.position}' and rotation '{anchorPose.rotation}'");
                transform.position = anchorPose.position;
                transform.rotation = anchorPose.rotation;

                // Create a native anchor at the location of the object in question
                gameObject.CreateNativeAnchor();

                // Notify AnchorFeedbackScript
                OnCreateLocalAnchor?.Invoke();
#endif
            });
        }
        else
        {
            QueueOnUpdate(new Action(() => Debug.Log($"Attempt to locate Anchor with ID '{args.Identifier}' failed, locate anchor status was not 'Located' but '{args.Status}'")));
        }
    }
Esempio n. 25
0
        /// <summary>
        /// Creates a <see cref="GameObject"/> representing the anchor based on provided <see cref="AnchorLocatedEventArgs"/>.
        /// </summary>
        /// <param name="args">Args passed from AnchorLocated event.</param>
        /// <returns>The newly created <see cref="GameObject"/>.</returns>
        protected virtual GameObject CreateGameObjectFrom(AnchorLocatedEventArgs args)
        {
            Pose pose = args.Anchor.GetAnchorPose();

            Debug.Log($"ASA-Android: Creating an anchor at: {pose.position.ToString("G4")}, {pose.rotation.eulerAngles.ToString("G2")}");
            GameObject gameObject = SpawnGameObject(pose.position, pose.rotation);

            gameObject.AddARAnchor();
            return(gameObject);
        }
        private void HandleAnchorLocated(object sender, AnchorLocatedEventArgs args)
        {
            Debug.Log($"Anchor recognized as a possible Azure anchor");

            if (args.Status == LocateAnchorStatus.Located || args.Status == LocateAnchorStatus.AlreadyTracked)
            {
                currentCloudAnchor = args.Anchor;

                AppDispatcher.Instance().Enqueue(() =>
                {
                    Debug.Log($"Azure anchor located successfully");
                    var indicator = Instantiate(anchorPositionPrefab);

#if WINDOWS_UWP || UNITY_WSA
                    indicator.gameObject.CreateNativeAnchor();

                    if (currentCloudAnchor == null)
                    {
                        return;
                    }
                    Debug.Log("Local anchor position successfully set to Azure anchor position");

                    indicator.GetComponent <UnityEngine.XR.WSA.WorldAnchor>().SetNativeSpatialAnchorPtr(currentCloudAnchor.LocalAnchor);
#elif UNITY_ANDROID || UNITY_IOS
                    Pose anchorPose = Pose.identity;
                    anchorPose      = currentCloudAnchor.GetPose();

                    Debug.Log($"Setting object to anchor pose with position '{anchorPose.position}' and rotation '{anchorPose.rotation}'");
                    indicator.transform.position = anchorPose.position;
                    indicator.transform.rotation = anchorPose.rotation;

                    // Create a native anchor at the location of the object in question
                    indicator.gameObject.CreateNativeAnchor();
#endif

                    indicator.Init(currentTrackedObject);
                    anchorArrowGuide.SetTargetObject(indicator.transform);
                    activeAnchors.Add(currentTrackedObject.SpatialAnchorId, indicator);

                    // Notify subscribers
                    OnFindAnchorSucceeded?.Invoke(this, EventArgs.Empty);
                    currentWatcher?.Stop();
                    currentTrackedObject = null;
                });
            }
            else
            {
                Debug.Log($"Attempt to locate Anchor with ID '{args.Identifier}' failed, locate anchor status was not 'Located' but '{args.Status}'");
            }

            StopAzureSession();
        }
        protected override void OnCloudAnchorLocated(AnchorLocatedEventArgs args)
        {
            base.OnCloudAnchorLocated(args);

            if (args.Status == LocateAnchorStatus.Located)
            {
                currentCloudAnchor = args.Anchor;

                UnityDispatcher.InvokeOnAppThread(() =>
                {
                    Pose anchorPose = Pose.identity;

#if UNITY_ANDROID || UNITY_IOS
                    anchorPose = currentCloudAnchor.GetPose();
#endif
                    if (AzureAssetImporter.mapIdToOffset.ContainsKey(args.Identifier))
                    {
                        Vector3 Mapoffsetposition    = AzureAssetImporter.mapIdToOffset[args.Identifier].position;
                        Quaternion Mapoffsetrotation = AzureAssetImporter.mapIdToOffset[args.Identifier].rotation;

                        Matrix4x4 cloudMapOffset = Matrix4x4.TRS(Mapoffsetposition, Mapoffsetrotation, Vector3.one);

                        Matrix4x4 anchorPoseOg = Matrix4x4.TRS(anchorPose.position, anchorPose.rotation, Vector3.one);

                        Matrix4x4 resultpose = anchorPoseOg * cloudMapOffset.inverse;

                        loaderPanel.SetActive(false);
                        // localizeButton.SetActive(false);
                        ARSpace.SetActive(true);
                        destinationDropdown.SetActive(true);

                        NotificationManager.Instance.GenerateSuccess("Offset found , setting global pose" + args.Identifier);

                        ARSpace.transform.rotation = resultpose.rotation;
                        ARSpace.transform.position = new Vector3(resultpose[0, 3], resultpose[1, 3], resultpose[2, 3]);
                    }
                    else
                    {
                        ARSpace.SetActive(true);
                        destinationDropdown.SetActive(true);
                        NotificationManager.Instance.GenerateSuccess("No Offset , setting default pose" + args.Identifier);
                        SpawnOrMoveCurrentAnchoredObject(anchorPose.position, anchorPose.rotation);
                    }
                });

                Debug.Log("Yay, anchor located!");

                SetBypassCache(true);
            }
        }
Esempio n. 28
0
        /// <summary>
        /// Handle a new anchor being located.
        /// </summary>
        private void AnchorLocated(object sender, AnchorLocatedEventArgs args)
        {
            LogVerbose("AnchorLocated() called. (anchor id: {0})", args.Identifier);

            _appContext.Send(contextState =>
            {
                FindEntry appAnchor;
                if (_pendingFinds.TryGetValue(args.Identifier, out appAnchor))
                {
                    LogVerbose("Anchor located, and notifying listeners. (anchor id: {0})", args.Identifier);
                    appAnchor.TaskCompletionSource.TrySetResult(args.Anchor);
                }
            }, null);
        }
Esempio n. 29
0
        public void UpdateStatusTextOnNewAnchorsLocated(object sender, AnchorLocatedEventArgs args)
        {
            if (args.Status == LocateAnchorStatus.Located)
            {
                ignoreMainButtonTaps = false;
                step = DemoStep.StopWatcher;

                BeginInvokeOnMainThread(() =>
                {
                    ++numAnchorsFound;
                    HideStatusLabel(true);
                    UpdateMainStatusTitle($"{numAnchorsFound} anchor(s) found! Tap to stop watcher.");
                });
            }
        }
        private void onAnchorLocated(object sender, AnchorLocatedEventArgs args)
        {
            LocateAnchorStatus status = args.P0.Status;

            RunOnUiThread(() =>
            {
                if (status == LocateAnchorStatus.Located)
                {
                    renderLocatedAnchor(args.P0.Anchor);
                }
                else if (status == LocateAnchorStatus.NotLocatedAnchorDoesNotExist)
                {
                    statusText.Text = "Anchor does not exist";
                }
            });
        }