Esempio n. 1
0
            public override unsafe TrackableChanges <XRReferencePoint> GetChanges(
                XRReferencePoint defaultReferencePoint,
                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 <XRReferencePoint>(
                               addedPtr, addedCount,
                               updatedPtr, updatedCount,
                               removedPtr, removedCount,
                               defaultReferencePoint, elementSize,
                               allocator));
                }
                finally
                {
                    UnityARCore_refPoints_releaseChanges(context);
                }
            }
Esempio n. 2
0
 public override bool TryAttachReferencePoint(
     TrackableId trackableToAffix,
     Pose pose,
     out XRReferencePoint referencePoint)
 {
     return(UnityARCore_refPoints_tryAttach(trackableToAffix, pose, out referencePoint));
 }
Esempio n. 3
0
 public override bool TryAttachReferencePoint(
     TrackableId trackableToAffix,
     Pose pose,
     out XRReferencePoint referencePoint)
 {
     return(this.TryAddReferencePoint(pose, out referencePoint));
 }
Esempio n. 4
0
 static bool UnityARCore_refPoints_tryAdd(
     Pose pose,
     out XRReferencePoint referencePoint)
 {
     referencePoint = default(XRReferencePoint);
     return(false);
 }
Esempio n. 5
0
 static bool UnityARKit_refPoints_tryAttach(
     TrackableId trackableToAffix,
     Pose pose,
     out XRReferencePoint referencePoint)
 {
     referencePoint = default(XRReferencePoint);
     return(false);
 }
        private static void DebugOutExtra(string label, XRReferencePoint referencePoint, SpongyAnchorXR tracker)
        {
            Debug.Assert(referencePoint.trackableId == tracker.TrackableId);
            Vector3 tP = tracker.transform.position;
            Vector3 tR = tracker.transform.rotation.eulerAngles;
            Vector3 rP = referencePoint.pose.position;
            Vector3 rR = referencePoint.pose.rotation.eulerAngles;

            rR = new Vector3(1.0f, 2.0f, 3.0f);
            DebugLogSetup($"{label}{tracker.name}-{tracker.TrackableId}/{referencePoint.trackingState}: {DebugVector3("tP=", tP)}|{DebugEuler("tR=", tR)} <=> {DebugVector3("rP=", rP)}|{DebugEuler("rR=", rR)}");
        }
        private static Pose ExtractPose(XRReferencePoint referencePoint)
        {
            Pose repose = referencePoint.pose;

            if (referencePoint.trackingState == TrackingState.None)
            {
                repose.position.z = -repose.position.z;
                repose.rotation.x = -repose.rotation.x;
                repose.rotation.y = -repose.rotation.y;
            }
            return(repose);
        }
Esempio n. 8
0
            public override bool TryAddReferencePoint(
                Pose pose,
                out XRReferencePoint referencePoint)
            {
                var trackableId = NativeApi.UnityXRMock_attachReferencePoint(TrackableId.invalidId, pose);

                if (NativeApi.refPoints.TryGetValue(trackableId, out NativeApi.RefPointInfo refPointInfo))
                {
                    referencePoint = refPointInfo.ToXRReferencePoint(XRReferencePoint.GetDefault());
                    return(true);
                }

                referencePoint = default;
                return(false);
            }
            public override unsafe bool TryAddReferencePoint(Pose pose, out XRReferencePoint referencePoint)
            {
                if (m_TrackerHandle == Native.InvalidHandle)
                {
                    referencePoint = 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 reference point because MLPersistentCoordinateFrameGetClosest returned {getClosestResult}.");
                    referencePoint = default;
                    return(false);
                }

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

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

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

                return(true);
            }
            public override unsafe TrackableChanges <XRReferencePoint> GetChanges(
                XRReferencePoint defaultReferencePoint,
                Allocator allocator)
            {
                using (var updated = GetUpdated(Allocator.Temp, out int updatedCount))
                {
                    var changes = new TrackableChanges <XRReferencePoint>(
                        m_PendingAdds.Count,
                        updatedCount,
                        m_PendingRemoves.Count,
                        allocator);

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

                    GetRemoved(changes.removed);

                    return(changes);
                }
            }
Esempio n. 11
0
 public override unsafe TrackableChanges <XRReferencePoint> GetChanges(
     XRReferencePoint defaultReferencePoint,
     Allocator allocator)
 {
     try
     {
         return(TrackableChanges <XRReferencePoint> .CopyFrom(
                    new NativeArray <XRReferencePoint>(
                        NativeApi.addedRefPoints.Select(m => m.ToXRReferencePoint(defaultReferencePoint)).ToArray(), allocator),
                    new NativeArray <XRReferencePoint>(
                        NativeApi.updatedRefPoints.Select(m => m.ToXRReferencePoint(defaultReferencePoint)).ToArray(), allocator),
                    new NativeArray <TrackableId>(
                        NativeApi.removedRefPoints.Select(m => m.id).ToArray(), allocator),
                    allocator));
     }
     finally
     {
         NativeApi.UnityXRMock_consumedReferencePointChanges();
     }
 }
        private static void UpdateTracker(string label, XRReferencePoint referencePoint, Dictionary <TrackableId, SpongyAnchorXR> anchors)
        {
            SpongyAnchorXR tracker;

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

                /// mafinc - Would rather base this on the current TrackingState of the referencePoint,
                /// but that is not currently reliable.
                tracker.IsReliablyLocated = true;

                Pose repose = ExtractPose(referencePoint);
                tracker.transform.position = repose.position;
                tracker.transform.rotation = repose.rotation;
            }
            else
            {
                Debug.LogError($"Missing trackableId {referencePoint.trackableId} from DB.");
            }
        }
        private static void UpdateTracker(string label, XRReferencePoint referencePoint, Dictionary <TrackableId, SpongyAnchorXR> anchors)
        {
            SpongyAnchorXR tracker;

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

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

                Pose    repose = ExtractPose(referencePoint);
                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 {referencePoint.trackableId} from DB.");
            }
        }
            /// <summary>
            /// Get changes to the passed XRReferencePoint
            /// </summary>
            /// <param name="defaultReferencePoint">The XRReferencePoint to get changes for.</param>
            /// <param name="allocator">Reference to the allocator for the XRReferencePoint.</param>
            /// <returns></returns>
            public override unsafe TrackableChanges <XRReferencePoint> GetChanges(
                XRReferencePoint defaultReferencePoint,
                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 <XRReferencePoint>(defaultReferencePoint, addedPtr, elementSize, addedCount, allocator);
                    var updated = NativeCopyUtility.PtrToNativeArrayWithDefault <XRReferencePoint>(defaultReferencePoint, updatedPtr, elementSize, updatedCount, allocator);
                    var removed = NativeCopyUtility.PtrToNativeArrayWithDefault <TrackableId>(default(TrackableId), removedPtr, elementSize, removedCount, allocator);


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

                    added.Dispose();
                    updated.Dispose();
                    removed.Dispose();
                    return(ret);
                }
                finally
                {
                    NativeApi.UnityWindowsMR_refPoints_releaseChanges(context);
                }
            }
Esempio n. 15
0
 static extern bool UnityARCore_refPoints_tryAdd(
     Pose pose,
     out XRReferencePoint referencePoint);
 public static extern bool UnityWindowsMR_refPoints_tryAdd(
     Pose pose,
     out XRReferencePoint referencePoint);
 /// <summary>
 /// Try to add a new XRReferencePoint.
 /// </summary>
 /// <param name="pose">The position for the XRReferencePoint.</param>
 /// <param name="referencePoint">The XRReferencePoint reference returned.</param>
 /// <returns>True if the XRReferencePoint was created.</returns>
 public override bool TryAddReferencePoint(
     Pose pose,
     out XRReferencePoint referencePoint)
 {
     return(NativeApi.UnityWindowsMR_refPoints_tryAdd(pose, out referencePoint));
 }
Esempio n. 18
0
 public override bool TryAddReferencePoint(
     Pose pose,
     out XRReferencePoint referencePoint)
 {
     return(UnityARCore_refPoints_tryAdd(pose, out referencePoint));
 }
 public override TrackableChanges <XRReferencePoint> GetChanges(XRReferencePoint defaultReferencePoint, Allocator allocator) => default;
 private static Pose ExtractPose(XRReferencePoint referencePoint)
 {
     return(referencePoint.pose);
 }
 private static bool CheckTracking(XRReferencePoint referencePoint)
 {
     return(referencePoint.trackingState != TrackingState.None);
 }
Esempio n. 22
0
 static extern bool UnityARCore_refPoints_tryAttach(
     TrackableId trackableToAffix,
     Pose pose,
     out XRReferencePoint referencePoint);
Esempio n. 23
0
 public XRReferencePoint ToXRReferencePoint(XRReferencePoint defaultReferencePoint)
 {
     return(new XRReferencePoint(this.id, this.pose, this.trackingState, defaultReferencePoint.nativePtr));
 }