コード例 #1
0
 static bool UnityARKit_refPoints_tryAttach(
     TrackableId trackableToAffix,
     Pose pose,
     out XRAnchor anchor)
 {
     throw new System.NotImplementedException(k_ExceptionMsg);
 }
コード例 #2
0
 public override bool TryAttachAnchor(
     TrackableId trackableToAffix,
     Pose pose,
     out XRAnchor anchor)
 {
     return(UnityARCore_refPoints_tryAttach(trackableToAffix, pose, out anchor));
 }
コード例 #3
0
            public override unsafe TrackableChanges <XRAnchor> GetChanges(
                XRAnchor defaultAnchor,
                Allocator allocator)
            {
                int   addedCount, updatedCount, removedCount, elementSize;
                void *addedPtr, updatedPtr, removedPtr;
                var   context = UnityARCore_refPoints_acquireChanges(
                    out addedPtr, out addedCount,
                    out updatedPtr, out updatedCount,
                    out removedPtr, out removedCount,
                    out elementSize);

                try
                {
                    return(new TrackableChanges <XRAnchor>(
                               addedPtr, addedCount,
                               updatedPtr, updatedCount,
                               removedPtr, removedCount,
                               defaultAnchor, elementSize,
                               allocator));
                }
                finally
                {
                    UnityARCore_refPoints_releaseChanges(context);
                }
            }
コード例 #4
0
 public override bool TryAttachAnchor(
     TrackableId trackableToAffix,
     Pose pose,
     out XRAnchor anchor)
 {
     return(this.TryAddAnchor(pose, out anchor));
 }
        private static void DebugOutExtra(string label, XRAnchor xrAnchor, SpongyAnchorXR tracker)
        {
            Debug.Assert(xrAnchor.trackableId == tracker.TrackableId);
            Vector3 tP = tracker.transform.position;
            Vector3 tR = tracker.transform.rotation.eulerAngles;
            Vector3 rP = xrAnchor.pose.position;
            Vector3 rR = xrAnchor.pose.rotation.eulerAngles;

            rR = new Vector3(1.0f, 2.0f, 3.0f);
            Debug.Log($"{label}{tracker.name}-{tracker.TrackableId}/{xrAnchor.trackingState}: {DebugVector3("tP=", tP)}|{DebugEuler("tR=", tR)} <=> {DebugVector3("rP=", rP)}|{DebugEuler("rR=", rR)}");
        }
コード例 #6
0
            public override bool TryAddAnchor(
                Pose pose,
                out XRAnchor anchor)
            {
                var trackableId = NativeApi.UnityXRMock_attachAnchor(TrackableId.invalidId, pose);

                if (NativeApi.anchors.TryGetValue(trackableId, out NativeApi.AnchorInfo anchorInfo))
                {
                    anchor = anchorInfo.ToXRAnchor(XRAnchor.defaultValue);
                    return(true);
                }

                anchor = default;
                return(false);
            }
コード例 #7
0
            public override unsafe bool TryAddAnchor(Pose pose, out XRAnchor anchor)
            {
                if (m_TrackerHandle == Native.InvalidHandle)
                {
                    anchor = default;
                    return(false);
                }

                // Get the pose position in right-handed coordinates
                var mlTarget = FlipHandedness(pose.position);

                // Get the ID of the closest PCF to our target position
                var getClosestResult = Native.GetClosest(m_TrackerHandle, ref mlTarget, out MLCoordinateFrameUID cfuid);

                if (getClosestResult != MLApiResult.Ok)
                {
                    LogWarning($"Could not create anchor because MLPersistentCoordinateFrameGetClosest returned {getClosestResult}.");
                    anchor = default;
                    return(false);
                }

                // Get the pose of the PCF
                if (!Native.TryGetPose(cfuid, out Pose closetCoordinateFrame))
                {
                    LogWarning($"Could not create anchor because no pose could be determined for coordinate frame {cfuid}.");
                    anchor = default;
                    return(false);
                }

                var referenceFrame = new ReferenceFrame(new ReferenceFrame.Cinfo
                {
                    closetCoordinateFrame = closetCoordinateFrame,
                    cfuid             = cfuid,
                    trackingState     = TrackingState.Tracking,
                    initialAnchorPose = pose
                });

                m_PendingAdds.Add(referenceFrame);
                anchor = referenceFrame.anchor;

                return(true);
            }
コード例 #8
0
            public override unsafe TrackableChanges <XRAnchor> GetChanges(
                XRAnchor defaultAnchor,
                Allocator allocator)
            {
                using (var updated = GetUpdated(Allocator.Temp, out int updatedCount))
                {
                    var changes = new TrackableChanges <XRAnchor>(
                        m_PendingAdds.Count,
                        updatedCount,
                        m_PendingRemoves.Count,
                        allocator);

                    GetAdded(changes.added);
                    NativeArray <XRAnchor> .Copy(updated, changes.updated, updatedCount);

                    GetRemoved(changes.removed);

                    return(changes);
                }
            }
コード例 #9
0
 public override unsafe TrackableChanges <XRAnchor> GetChanges(
     XRAnchor defaultAnchor,
     Allocator allocator)
 {
     try
     {
         return(TrackableChanges <XRAnchor> .CopyFrom(
                    new NativeArray <XRAnchor>(
                        NativeApi.addedAnchors.Select(m => m.ToXRAnchor(defaultAnchor)).ToArray(), allocator),
                    new NativeArray <XRAnchor>(
                        NativeApi.updatedAnchors.Select(m => m.ToXRAnchor(defaultAnchor)).ToArray(), allocator),
                    new NativeArray <TrackableId>(
                        NativeApi.removedAnchors.Select(m => m.id).ToArray(), allocator),
                    allocator));
     }
     finally
     {
         NativeApi.UnityXRMock_consumedAnchorChanges();
     }
 }
        private static void UpdateTracker(string label, XRAnchor xrAnchor, Dictionary <TrackableId, SpongyAnchorXR> anchors)
        {
            SpongyAnchorXR tracker;

            if (anchors.TryGetValue(xrAnchor.trackableId, out tracker))
            {
                DebugOutExtra(label, xrAnchor, tracker);

                tracker.IsReliablyLocated = xrAnchor.trackingState != TrackingState.None;

                Pose    repose = ExtractPose(xrAnchor);
                Vector3 delta  = repose.position - tracker.transform.position;
                tracker.Delta = delta;
                tracker.transform.position = repose.position;
                tracker.transform.rotation = repose.rotation;
            }
            else
            {
                Debug.LogError($"Missing trackableId {xrAnchor.trackableId} from DB, adding now.");
            }
        }
コード例 #11
0
            public override unsafe TrackableChanges <XRAnchor> GetChanges(
                XRAnchor defaultAnchor,
                Allocator allocator)
            {
                int   addedCount, updatedCount, removedCount, elementSize;
                void *addedPtr, updatedPtr, removedPtr;
                var   context = NativeApi.UnityWindowsMR_refPoints_acquireChanges(
                    out addedPtr, out addedCount,
                    out updatedPtr, out updatedCount,
                    out removedPtr, out removedCount,
                    out elementSize);

                try
                {
                    // Yes, this is an extra copy, but the hit is small compared with the code needed to get rid of it.
                    // If this becomes a problem we can eliminate the extra copy by doing something similar to
                    // NativeCopyUtility.PtrToNativeArrayWithDefault only with a pre-allocated array properties
                    // from using the TrackableChanges(int, int, int allocator) constructor.
                    var added   = NativeCopyUtility.PtrToNativeArrayWithDefault <XRAnchor>(defaultAnchor, addedPtr, elementSize, addedCount, allocator);
                    var updated = NativeCopyUtility.PtrToNativeArrayWithDefault <XRAnchor>(defaultAnchor, updatedPtr, elementSize, updatedCount, allocator);
                    var removed = NativeCopyUtility.PtrToNativeArrayWithDefault <TrackableId>(default(TrackableId), removedPtr, elementSize, removedCount, allocator);


                    var ret = TrackableChanges <XRAnchor> .CopyFrom(
                        added,
                        updated,
                        removed,
                        allocator);

                    added.Dispose();
                    updated.Dispose();
                    removed.Dispose();
                    return(ret);
                }
                finally
                {
                    NativeApi.UnityWindowsMR_refPoints_releaseChanges(context);
                }
            }
コード例 #12
0
        public static TrackableChanges <XRAnchor> ConsumeChanges(XRAnchor defaultAnchor, Allocator allocator)
        {
            lock (stateLock)
            {
                try
                {
                    if (allocator != Allocator.None)
                    {
                        T[] EfficientArray <T>(IEnumerable <AnchorApi.AnchorInfo> collection, Func <AnchorApi.AnchorInfo, T> converter)
                        => collection.Any(m => true) ? collection.Select(converter).ToArray() : Array.Empty <T>();

                        return(TrackableChanges <XRAnchor> .CopyFrom(
                                   new NativeArray <XRAnchor>(
                                       EfficientArray(AnchorApi.added.Values, m => m.ToXRAnchor(defaultAnchor)), allocator),
                                   new NativeArray <XRAnchor>(
                                       EfficientArray(AnchorApi.updated.Values, m => m.ToXRAnchor(defaultAnchor)), allocator),
                                   new NativeArray <TrackableId>(
                                       EfficientArray(AnchorApi.removed.Values, m => m.id), allocator),
                                   allocator));
                    }
                    else
                    {
                        return(default);
コード例 #13
0
 public override bool TryAddAnchor(Pose pose, out XRAnchor anchor)
 {
     anchor = AnchorApi.Attach(pose, TrackingState.Tracking, Guid.Empty);
     return(anchor != null);
 }
コード例 #14
0
 public override unsafe TrackableChanges <XRAnchor> GetChanges(XRAnchor defaultAnchor, Allocator allocator)
 => AnchorApi.ConsumeChanges(defaultAnchor, allocator);
コード例 #15
0
 static extern bool UnityARCore_refPoints_tryAttach(
     TrackableId trackableToAffix,
     Pose pose,
     out XRAnchor anchor);
コード例 #16
0
 static extern bool UnityARCore_refPoints_tryAdd(
     Pose pose,
     out XRAnchor anchor);
コード例 #17
0
 public XRAnchor ToXRAnchor(XRAnchor defaultAnchor)
 {
     return(new XRAnchor(this.id, this.pose, this.trackingState, defaultAnchor.nativePtr));
 }
コード例 #18
0
 public override bool TryAddAnchor(
     Pose pose,
     out XRAnchor anchor)
 {
     return(UnityARCore_refPoints_tryAdd(pose, out anchor));
 }
コード例 #19
0
 static bool UnityARKit_refPoints_tryAdd(
     Pose pose,
     out XRAnchor anchor)
 {
     throw new System.NotImplementedException(k_ExceptionMsg);
 }
 private static bool CheckTracking(XRAnchor xrAnchor)
 {
     return(xrAnchor.trackingState != TrackingState.None);
 }
コード例 #21
0
 public override TrackableChanges <XRAnchor> GetChanges(XRAnchor defaultAnchor, Allocator allocator) => default;
コード例 #22
0
 public override bool TryAddAnchor(
     Pose pose,
     out XRAnchor anchor)
 {
     return(NativeApi.UnityWindowsMR_refPoints_tryAdd(pose, out anchor));
 }
コード例 #23
0
 public static extern bool UnityWindowsMR_refPoints_tryAdd(Pose pose, out XRAnchor anchor);
 private static Pose ExtractPose(XRAnchor xrAnchor)
 {
     return(xrAnchor.pose);
 }