コード例 #1
0
        /// <inheritdoc />
        public override void DidAddAnchors(ARSession session, ARAnchor[] anchors)
        {
            var newAnchors = new List <ARMobileAnchor>();

            foreach (var anchor in anchors)
            {
                var id = new Guid(anchor.Identifier.GetBytes());

                Matrix transform;
                anchor.Transform.ToWave(out transform);

                ARMobileAnchor newAnchor;

                var planeAnchor = anchor as ARPlaneAnchor;
                if (planeAnchor != null)
                {
                    var plane = new ARMobilePlaneAnchor();
                    newAnchor = plane;

                    planeAnchor.Transform.ToWave(out plane.Transform);
                    planeAnchor.Center.ToWave(out plane.Center);
                    planeAnchor.Extent.ToWave(out plane.Size);
                    plane.Type = planeAnchor.Alignment.ToWave();

                    if (this.supportARKitOnePointFive &&
                        planeAnchor.Geometry != null)
                    {
                        planeAnchor.Geometry.GetBoundaryVertices().ToWave(ref plane.BoundaryPolygon);
                    }
                }
                else
                {
                    newAnchor = new ARMobileAnchor();
                }

                newAnchor.Id        = id;
                newAnchor.Transform = transform;

                newAnchors.Add(newAnchor);
            }

            this.service.AddAnchors(newAnchors);
        }
コード例 #2
0
        private void RefreshTrackables(Frame frame)
        {
            var newAnchors        = new List <ARMobileAnchor>();
            var updatedAnchors    = new List <ARMobileAnchor>();
            var removedAnchorsIds = new List <Guid>();

            foreach (ARCore.Plane arCorePlane in frame.GetUpdatedTrackables(Java.Lang.Class.FromType(typeof(ARCore.Plane))))
            {
                if (arCorePlane.TrackingState != ARCore.TrackingState.Tracking ||
                    arCorePlane.SubsumedBy != null)
                {
                    removedAnchorsIds.Add(arCorePlane.GetGuid());
                }
                else
                {
                    var planeId     = arCorePlane.GetGuid();
                    var planeAnchor = this.FindAnchor(planeId) as ARMobilePlaneAnchor;

                    if (planeAnchor == null)
                    {
                        planeAnchor = new ARMobilePlaneAnchor()
                        {
                            Id = planeId
                        };
                        newAnchors.Add(planeAnchor);
                    }
                    else
                    {
                        updatedAnchors.Add(planeAnchor);
                    }

                    arCorePlane.Polygon.ToWave(ref planeAnchor.BoundaryPolygon);
                    arCorePlane.CenterPose.ToWave(out planeAnchor.Transform);
                    planeAnchor.Size.X = arCorePlane.ExtentX;
                    planeAnchor.Size.Z = arCorePlane.ExtentZ;
                    planeAnchor.Type   = arCorePlane.GetPlaneAnchorType();
                }
            }

            this.AddAnchors(newAnchors);
            this.UpdatedAnchors(updatedAnchors);
            this.RemoveAnchors(removedAnchorsIds);
        }