public override void OnNodeAddedForAnchor(ISCNSceneRenderer renderer, SCNNode node, ARAnchor anchor)
        {
            base.OnNodeAddedForAnchor(renderer, node, anchor);

            if (!(anchor is ARFaceAnchor faceAnchor))
            {
                return;
            }

            foreach (var child in node.ChildNodes)
            {
                child.RemoveFromParentNode();
            }

            node.AddChildNode(FaceNode);

            SoundManager.PlaySound("spooky");
        }
Beispiel #2
0
        public override void OnNodeAddedForAnchor(ISCNSceneRenderer renderer, SCNNode node, ARAnchor anchor)
        {
            base.OnNodeAddedForAnchor(renderer, node, anchor);

            SoundManager.PlaySound("miss");

            var imageAnchor = anchor as ARImageAnchor;
            var refSize     = imageAnchor.ReferenceImage.PhysicalSize;
            var box         = new SCNBox
            {
                Width         = refSize.Width * .9f,
                Length        = refSize.Height * .9f,
                Height        = 0.0001f,
                ChamferRadius = 0
            };

            box.FirstMaterial.Diffuse.Contents = UIColor.White.ColorWithAlpha(.95f);

            var pf = Prefabs[i++];

            node.AddChildNode(new SCNNode {
                Geometry = box
            });
            node.AddChildNode(pf);

            pf.Position = SCNVector3.Zero;
        }
Beispiel #3
0
        /// <summary>
        /// The Unity Update() method.
        /// </summary>
        public void Update()
        {
            _UpdateApplicationLifecycle();

            if (m_CurrentActiveScreen != ActiveScreen.ARScreen)
            {
                return;
            }

            // If we are neither in hosting nor resolving mode then the update is complete.
            if (m_CurrentMode != ApplicationMode.Hosting &&
                m_CurrentMode != ApplicationMode.Resolving)
            {
                return;
            }

            // Give AR session some time to prepare for resolving and update the UI message
            // once the preparation time passed.
            if (m_CurrentMode == ApplicationMode.Resolving && !m_PassedResolvingPreparedTime)
            {
                m_TimeSinceStart += Time.deltaTime;

                if (m_TimeSinceStart > k_ResolvingPrepareTime)
                {
                    m_PassedResolvingPreparedTime = true;
                    NetworkUIController.ShowDebugMessage(
                        "Waiting for Cloud Anchor to be hosted...");
                }
            }

            // If the origin anchor has not been placed yet, then update in resolving mode is
            // complete.
            if (m_CurrentMode == ApplicationMode.Resolving && !IsOriginPlaced)
            {
                return;
            }

            // If the player has not touched the screen then the update is complete.
            Touch touch;

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

            // Ignore the touch if it's pointing on UI objects.
            if (EventSystem.current.IsPointerOverGameObject(touch.fingerId))
            {
                return;
            }

            List <ARRaycastHit> hitResults = new List <ARRaycastHit>();

            RaycastManager.Raycast(Input.GetTouch(0).position, hitResults);

            // If there was an anchor placed, then instantiate the corresponding object.
            if (hitResults.Count > 0)
            {
                // The first touch on the Hosting mode will instantiate the origin anchor. Any
                // subsequent touch will instantiate a star, both in Hosting and Resolving modes.
                if (_CanPlaceStars())
                {
                    _InstantiateStar(_ToWorldOriginPose(hitResults[0].pose));
                }
                else if (!IsOriginPlaced && m_CurrentMode == ApplicationMode.Hosting)
                {
                    ARAnchor anchor = AnchorManager.AddAnchor(hitResults[0].pose);
                    WorldOrigin = anchor.transform;
                    _InstantiateAnchor(anchor);
                    OnAnchorInstantiated(true);
                }
            }
        }
        public override void OnNodeAddedForAnchor(ISCNSceneRenderer renderer, SCNNode node, ARAnchor anchor)
        {
            if (!(anchor is ARPlaneAnchor planeAnchor))
            {
                return;
            }

            var color = planeAnchor.Alignment == ARPlaneAnchorAlignment.Horizontal
                ? UIColor.Blue : UIColor.Red;

            var planeNode = CreateARPlaneNode(planeAnchor, color.ColorWithAlpha(.5f));

            node.AddChildNode(planeNode);

            if (PlaySoundOnNodeDetection())
            {
                SoundManager.PlaySound("buy1");
            }
        }
        public override void OnNodeRemovedForAnchor(ISCNSceneRenderer renderer, SCNNode node, ARAnchor anchor)
        {
            if (!(anchor is ARPlaneAnchor planeAnchor))
            {
                return;
            }

            if (PlaySoundOnNodeDetection())
            {
                SoundManager.PlaySound("miss");
            }
        }
 public void Initialize(ARAnchor anchor)
 {
     m_anchor = anchor;
     Update();
 }
Beispiel #7
0
 public void OnAnchorRemoved(ARAnchor arAnchor, ARNode arNode)
 {
     surfaces.Remove(arAnchor.AnchorId);
 }
Beispiel #8
0
 public void SetAnchor(ARAnchor anchor)
 {
     _anchor = anchor;
 }
Beispiel #9
0
 public void RemoveAnchor(ARAnchor anchor)
 {
     m_anchorDict.Remove(anchor.m_anchorHandle);
 }
Beispiel #10
0
 public override void DidRemoveNode(ISCNSceneRenderer renderer, SCNNode node, ARAnchor anchor)
 {
     if (anchor is ARPlaneAnchor planeAnchor)
     {
         this.planeNodes[anchor.Identifier].RemoveFromParentNode();
         this.planeNodes.Remove(anchor.Identifier);
     }
 }
 public override void DidUpdateNode(ISCNSceneRenderer renderer, SCNNode node, ARAnchor anchor)
 {
 }
Beispiel #12
0
 public override void DidAddNode(ISCNSceneRenderer renderer, SCNNode node, ARAnchor anchor)
 {
     if (anchor is ARPlaneAnchor planeAnchor)
     {
         var planeNode = new PlaneNode(planeAnchor);
         node.AddChildNode(planeNode);
         this.planeNodes.Add(anchor.Identifier, planeNode);
     }
 }
Beispiel #13
0
 public override void DidUpdateNode(ISCNSceneRenderer renderer, SCNNode node, ARAnchor anchor)
 {
     if (anchor is ARPlaneAnchor planeAnchor)
     {
         //this.planeNodes[anchor.Identifier].Update(planeAnchor);
     }
 }
        public override void OnNodeUpdatedForAnchor(ISCNSceneRenderer renderer, SCNNode node, ARAnchor anchor)
        {
            base.OnNodeUpdatedForAnchor(renderer, node, anchor);

            if (!(anchor is ARFaceAnchor faceAnchor))
            {
                return;
            }

            FaceNode.Update(faceAnchor.Geometry);
        }
 /// <summary>
 /// The constructor initializes the pose of the virtual object in a space and the
 /// color of the virtual object with the input anchor point and color parameters.
 /// </summary>
 /// <param name="arAnchor">Data provided by AR Engine, describing the pose.</param>
 /// <param name="color4f">Color data in an array with a length of 4.</param>
 public VirtualObject(ARAnchor arAnchor, float[] color4f)
 {
     mObjectColors = Arrays.CopyOf(color4f, color4f.Length);
     mArAnchor     = arAnchor;
     Init();
 }
Beispiel #16
0
 private static void DebugOutExtra(string label, ARAnchor arAnchor, SpongyAnchorARF tracker)
 {
     Debug.Assert(arAnchor.trackableId == tracker.TrackableId);
     Debug.Log($"{label}{tracker.name}-{tracker.TrackableId}/{arAnchor.trackingState}: T={tracker.transform.GetGlobalPose().ToString("F3")} AR={arAnchor.transform.GetGlobalPose().ToString("F3")}");
 }
Beispiel #17
0
 internal ARSCNViewNodeEventArgs(ISCNSceneRenderer renderer, SCNNode node, ARAnchor anchor)
 {
     Renderer = renderer;
     Node     = node;
     Anchor   = anchor;
 }
Beispiel #18
0
            public override void DidAddNode(ISCNSceneRenderer renderer, SCNNode node, ARAnchor anchor)
            {
                if (anchor is ARImageAnchor imageAnchor)
                {
                    var box = new SCNBox();

                    nfloat width  = imageAnchor.ReferenceImage.PhysicalSize.Width;
                    nfloat height = imageAnchor.ReferenceImage.PhysicalSize.Height;

                    box.Width  = width;
                    box.Height = height;
                    box.Length = (System.nfloat) 0.1;
                    box.FirstMaterial.Diffuse.Contents = UIColor.Orange;

                    SCNText text = SCNText.Create("Enter Here", (System.nfloat) 0.1);
                    text.Font     = UIFont.SystemFontOfSize(1);
                    text.Flatness = (System.nfloat) 0.05;
                    text.FirstMaterial.Diffuse.Contents = UIColor.Red;


                    var textNode = new SCNNode
                    {
                        Geometry = text,
                    };



                    textNode.Scale       = new SCNVector3((float)0.5, (float)0.5, (float)0.5);
                    textNode.EulerAngles = new SCNVector3((float)(-1.57), 0, 0);

                    textNode.Position = new SCNVector3
                    {
                        X = (float)(imageAnchor.Transform.Column3.X + 2),
                        Y = imageAnchor.Transform.Column3.Y - 2,
                        Z = imageAnchor.Transform.Column3.Z
                    };



                    var boxNode = new SCNNode
                    {
                        Geometry = box,

                        Position = new SCNVector3 {
                            X = -imageAnchor.Transform.Column3.X / 2,
                            Y = -imageAnchor.Transform.Column3.Y,
                            Z = imageAnchor.Transform.Column3.Z
                        }
                    };

                    node.AddChildNode(textNode);
                    //node.AddChildNode(boxNode);
                }
            }
Beispiel #19
0
        public void MarshallingTest()
        {
            var faceAnchor = new ARAnchor("My Anchor", MatrixFloat4x4.Identity);

            Assert.AreEqual(MatrixFloat4x4.Identity, faceAnchor.Transform, "Transform");
        }
            public override void DidAddNode(ISCNSceneRenderer renderer, SCNNode node, ARAnchor anchor)
            {
                var planeAnchor = anchor as ARPlaneAnchor ?? throw new Exception();

                AddPlaneNode(planeAnchor, node, UIColor.Blue.ColorWithAlpha(0.3f));
            }
Beispiel #21
0
        /// <summary>
        /// The Unity Update() method.
        /// Modified for project mARble
        /// </summary>
        public void Update()
        {
            _UpdateApplicationLifecycle();

            if (m_CurrentActiveScreen != ActiveScreen.ARScreen)
            {
                return;
            }

            // If we are neither in hosting nor resolving mode then the update is complete.
            if (m_CurrentMode != ApplicationMode.Hosting &&
                m_CurrentMode != ApplicationMode.Resolving)
            {
                return;
            }

            // Give AR session some time to prepare for resolving and update the UI message
            // once the preparation time passed.
            if (m_CurrentMode == ApplicationMode.Resolving && !m_PassedResolvingPreparedTime)
            {
                m_TimeSinceStart += Time.deltaTime;

                if (m_TimeSinceStart > k_ResolvingPrepareTime)
                {
                    m_PassedResolvingPreparedTime = true;
                    NetworkUIController.ShowDebugMessage(
                        "Waiting for Cloud Anchor to be hosted...");
                }
            }

            // If the origin anchor has not been placed yet, then update in resolving mode is
            // complete.
            if (m_CurrentMode == ApplicationMode.Resolving && !IsOriginPlaced)
            {
                return;
            }

            // If the player has not touched the screen then the update is complete.
            Touch touch;

            if (Input.touchCount < 1)
            {
                return;
            }
            touch = Input.GetTouch(0);

            // Ignore the touch if it's pointing on UI objects.
            if (EventSystem.current.IsPointerOverGameObject(touch.fingerId) || IsPointerOverUIObject())
            {
                return;
            }

            List <ARRaycastHit> hitResults = new List <ARRaycastHit>();

            RaycastManager.Raycast(touch.position, hitResults);
            if (touch.phase == TouchPhase.Began)
            {
                // First check if the player is selecting an existing item
                Ray        ray = ARCamera.ScreenPointToRay(touch.position);
                RaycastHit hitObject;

                // Sets item touched as Selected Object
                if (Physics.Raycast(ray, out hitObject))
                {
                    lastSelectedObject = hitObject.transform.GetComponent <PlacementObject>();
                    if (lastSelectedObject != null)
                    {
                        placedObjects = FindObjectsOfType <PlacementObject>();
                        foreach (PlacementObject placementObject in placedObjects)
                        {
                            placementObject.Selected = placementObject == lastSelectedObject;
                        }
                    }
                }
            }

            // Deselect object if the player is no longer touching
            if (touch.phase == TouchPhase.Ended && lastSelectedObject != null)
            {
                lastSelectedObject.Selected = false;
            }


            // If there was an anchor placed, then instantiate the corresponding object.
            if (hitResults.Count > 0)
            {
                // The first touch on the Hosting mode will instantiate the origin anchor. Any
                // subsequent touch will instantiate a star, both in Hosting and Resolving modes.
                if (_CanPlaceStars())
                {
                    Pose hitPose = hitResults[0].pose;
                    // yOffset to prevent object clipping through AR plane

                    // If no existing object is selected, instantiate a new object
                    if (lastSelectedObject == null && ModeManager.Instance.GetCurrMode() == GameMode.PLACEMENT_MODE)
                    {
                        // Vector3 yOffsetPrefab = new Vector3(0f, currSelectedPrefab.GetComponent<Renderer>().bounds.size.y/2.001f, 0f);
                        // hitPose.position += yOffsetPrefab;
                        _InstantiateStar(_ToWorldOriginPose(hitPose));
                    }
                    else
                    {
                        // Move the selected object
                        if (lastSelectedObject.Selected)
                        {
                            //V ector3 yOffsetSelectedObject = new Vector3(0f, lastSelectedObject.GetComponent<Renderer>().bounds.size.y/2.001f, 0f);

                            if (lastSelectedObject.tag == "Marble")
                            {
                                float snapDist = 0.075f; //0.05f;
                                MoveMarble(hitPose, snapDist);
                            }
                            else
                            {
                                lastSelectedObject.transform.position = hitPose.position;
                                //  we don't use the + yOffsetSelectedObject anymore
                            }
                        }
                    }
                }
                else if (!IsOriginPlaced && m_CurrentMode == ApplicationMode.Hosting)
                {
                    ARAnchor anchor = AnchorManager.AddAnchor(hitResults[0].pose);
                    WorldOrigin = anchor.transform;
                    _InstantiateAnchor(anchor);
                    OnAnchorInstantiated(true);
                }
            }
        }
            public override void DidUpdateNode(ISCNSceneRenderer renderer, SCNNode node, ARAnchor anchor)
            {
                var planeAnchor = anchor as ARPlaneAnchor ?? throw new Exception();

                UpdatePlaneNode(planeAnchor, node);
            }
        public override void OnNodeUpdatedForAnchor(ISCNSceneRenderer renderer, SCNNode node, ARAnchor anchor)
        {
            if (!(anchor is ARPlaneAnchor planeAnchor))
            {
                return;
            }

            UpdateARPlaneNode(node.ChildNodes[0], planeAnchor);

            if (PlaySoundOnNodeDetection())
            {
                SoundManager.PlaySound("eat");
            }
        }
Beispiel #24
0
 public override async void DidAddNode(ISCNSceneRenderer renderer, SCNNode node, ARAnchor anchor)
 {
     if (anchor != null && anchor is ARImageAnchor)
     {
         var imageAnchor = (ARImageAnchor)anchor;
         var imageName   = imageAnchor.ReferenceImage.Name;
         imageCapturedAction?.Invoke(imageName);
     }
 }
Beispiel #25
0
 public void QueueAnchor(ARAnchor arAnchor)
 {
     pendingHostAnchor = arAnchor;
 }
 public void PositionRobbie(ARAnchor anchor)
 {
     // TODO
 }
Beispiel #27
0
 //remove previous anchor
 //this makes the camera movable again
 public void removeAnchor()
 {
     m_anchorManager.RemoveAnchor(m_anchor);
     m_anchor = null;
 }
Beispiel #28
0
 public override void DidRemoveNode(ISCNSceneRenderer renderer, SCNNode node, ARAnchor anchor)
 => DispatchQueue.MainQueue.DispatchAsync(() => base.DidRemoveNode(renderer, node, anchor));
Beispiel #29
0
 /// <summary>
 /// Instantiates the anchor object at the pose of the m_WorldOrigin.
 /// This will host the Cloud Anchor.
 /// </summary>
 /// <param name="anchor">The ARAnchor object holding the anchor.</param>
 private void _InstantiateAnchor(ARAnchor anchor)
 {
     // The anchor will be spawned by the host, so no networking Command is needed.
     GameObject.Find("LocalPlayer").GetComponent <LocalPlayerController>()
     .SpawnAnchor(anchor);
 }
        public override void OnNodeUpdatedForAnchor(ISCNSceneRenderer renderer, SCNNode node, ARAnchor anchor)
        {
            base.OnNodeUpdatedForAnchor(renderer, node, anchor);

            if (!(anchor is ARFaceAnchor faceAnchor))
            {
                return;
            }

            Console.WriteLine(node);

            try
            {
                foreach (var thing in Faces.OfType <FaceNode>())
                {
                    thing.Update(faceAnchor.Geometry);

                    thing.EulerAngles = node.EulerAngles;
                    thing.RotateBy(0, 0, (float)Math.PI, 0);
                }
            } catch { }

            var blendShapes = faceAnchor.BlendShapes;

            // get the five strongest indicators to display
            var dominantParts = blendShapes.Dictionary
                                .GroupBy(x => $"{x.Key}".Split('_')[0], x => (NSNumber)x.Value)
                                .Select(x => new { Expression = x.Key, Value = x.Max(y => y.FloatValue) }) // take strongest of left or right when present
                                .OrderByDescending(x => x.Value)
                                .Select(x => $"{x.Expression}: {x.Value:P0}")
                                .Take(5)
                                .ToList();

            NaivelyAndIneffecientlyCheckForChangedExpression(node, blendShapes);
        }