コード例 #1
0
            public MagicLeapProvider()
            {
                // ARFoundation often beats XRManagement to the instantiation so often times the MagicLeapPrivileges
                // class will not be available to get privileges from.  Because of this the class is acquired here.
                MagicLeapPrivileges.Initialize();

                m_PerceptionHandle = PerceptionHandle.Acquire();


                if (s_NativeProviderPtr == IntPtr.Zero)
                {
                    s_NativeProviderPtr = Native.Construct();
                }
                if (RequestPrivilegesIfNecessary())
                {
                    if (s_NativeTrackerCreationJobHandle.Equals(default(JobHandle)))
                    {
                        RcoApi.Retain(s_NativeProviderPtr);
                        s_NativeTrackerCreationJobHandle = new CreateNativeImageTrackerJob {
                            nativeProvider = s_NativeProviderPtr
                        }.Schedule();
                    }
                }
                else
                {
                    LogWarning($"Could not start the image tracking subsystem because privileges were denied.");
                }
            }
コード例 #2
0
        unsafe void DeserializeImageDatabaseFile(XRReferenceImageLibrary serializedLibrary)
        {
            var libraryPath = MagicLeapImageTrackingSubsystem.GetDatabaseFilePathFromLibrary(serializedLibrary);

            if (!File.Exists(libraryPath))
            {
                throw new ArgumentException($"Serialized Image Tracking Library at '{libraryPath}' doesn't exist.");
            }

            var bytes = File.ReadAllBytes(libraryPath);

            if (bytes.Length < sizeof(ulong))
            {
                throw new ArgumentException($"Serialized Image Tracking Library at '{libraryPath}' has no image data within it.");
            }

            var magicBytes = BitConverter.ToUInt64(bytes, 0);
            var byteOffset = sizeof(ulong);

            if (magicBytes != kMagicBytes)
            {
                throw new ArgumentException($"Serialized Image Tracking Library at '{libraryPath}' is not a valid image database file.");
            }

            for (int i = 0; i < serializedLibrary.count; ++i)
            {
                var referenceImage = serializedLibrary[i];
                var imageHandle    = MagicLeapImageTrackingSubsystem.Native.InvalidHandle;

                var widthInPixels = BitConverter.ToInt32(bytes, byteOffset);
                byteOffset += sizeof(int);
                var heightInPixels = BitConverter.ToInt32(bytes, byteOffset);
                byteOffset += sizeof(int);

                // Retain in case we destroy before the images have been processed
                RcoApi.Retain(m_NativePtr);
                RcoApi.Retain(m_NativeProviderPtr);
                fixed(byte *texturePtr = &bytes[byteOffset])
                {
                    var grayscaleImage = new NativeArray <byte>(widthInPixels * heightInPixels, Allocator.Persistent);

                    NativeArray <byte> .Copy(bytes, byteOffset, grayscaleImage, 0, widthInPixels *heightInPixels);

                    new AddImageJob
                    {
                        nativeProvider        = m_NativeProviderPtr,
                        database              = m_NativePtr,
                        managedReferenceImage = new ManagedReferenceImage(referenceImage),
                        grayscaleImage        = grayscaleImage,
                        width  = widthInPixels,
                        height = heightInPixels,
                        name   = new NativeArray <byte>(Encoding.UTF8.GetBytes(referenceImage.name + "\0"), Allocator.Persistent)
                    }.Schedule(m_CreateAssociatedNativeTrackerJobHandle);
                }

                byteOffset += widthInPixels * heightInPixels;
            }
        }
            public MagicLeapProvider()
            {
                m_PerceptionHandle = PerceptionHandle.Acquire();

                if (s_NativeProviderPtr == IntPtr.Zero)
                {
                    s_NativeProviderPtr = Native.Construct();
                }
                if (RequestPrivilegesIfNecessary())
                {
                    if (s_NativeTrackerCreationJobHandle.Equals(default(JobHandle)))
                    {
                        RcoApi.Retain(s_NativeProviderPtr);
                        s_NativeTrackerCreationJobHandle = new CreateNativeImageTrackerJob {
                            nativeProvider = s_NativeProviderPtr
                        }.Schedule();
                    }
                }
                else
                {
                    LogWarning($"Could not start the image tracking subsystem because privileges were denied.");
                }
            }
コード例 #4
0
        protected override JobHandle ScheduleAddImageJobImpl(
            NativeSlice <byte> imageBytes,
            Vector2Int sizeInPixels,
            TextureFormat format,
            XRReferenceImage referenceImage,
            JobHandle inputDeps)
        {
            if (m_NativeProviderPtr != MagicLeapImageTrackingSubsystem.nativeProviderPtr)
            {
                throw new InvalidOperationException($"Attempted to modify dead image library.  The native provider that created this library doesn't exist and the native resource for this library has been released.  Dispose this object.");
            }

            var grayscaleImage = new NativeArray <byte>(
                sizeInPixels.x * sizeInPixels.y,
                Allocator.Persistent,
                NativeArrayOptions.UninitializedMemory);

            var jobDependencies = JobHandle.CombineDependencies(m_CreateAssociatedNativeTrackerJobHandle, inputDeps);

            var conversionHandle = ConversionJob.Schedule(imageBytes, sizeInPixels, format, grayscaleImage, jobDependencies);

            // Retain in case we destroy before the images have been processed
            RcoApi.Retain(m_NativePtr);
            RcoApi.Retain(m_NativeProviderPtr);

            return(new AddImageJob
            {
                nativeProvider = m_NativeProviderPtr,
                database = m_NativePtr,
                managedReferenceImage = new ManagedReferenceImage(referenceImage),
                grayscaleImage = grayscaleImage,
                width = sizeInPixels.x,
                height = sizeInPixels.y,
                name = new NativeArray <byte>(Encoding.UTF8.GetBytes(referenceImage.name + "\0"), Allocator.Persistent),
            }.Schedule(conversionHandle));
        }