docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class MutableRuntimeReferenceImageLibrary

    A reference image library that can be constructed and modified at runtime.

    Inheritance
    object
    RuntimeReferenceImageLibrary
    MutableRuntimeReferenceImageLibrary
    Implements
    IReferenceImageLibrary
    Inherited Members
    RuntimeReferenceImageLibrary.this[int]
    RuntimeReferenceImageLibrary.count
    RuntimeReferenceImageLibrary.GetReferenceImageAt(int)
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: UnityEngine.XR.ARSubsystems
    Assembly: Unity.XR.ARSubsystems.dll
    Syntax
    public abstract class MutableRuntimeReferenceImageLibrary : RuntimeReferenceImageLibrary, IReferenceImageLibrary
    Remarks

    This differs from an XRReferenceImageLibrary, which can only be constructed in the Editor and is immutable at runtime.

    Important

    Implementors: XRImageTrackingSubsystem providers must implement this class for their provider if supportsMutableLibrary is true to provide the functionality to support runtime mutable libraries.

    This is not something consumers of the UnityEngine.XR.ARSubsystems namespace should implement.

    Properties

    supportedTextureFormatCount

    The number of texture formats that are supported for image addition.

    Declaration
    public abstract int supportedTextureFormatCount { get; }
    Property Value
    Type Description
    int
    See Also
    CreateRuntimeLibrary(XRReferenceImageLibrary)

    supportsValidation

    (Read Only) True if this MutableRuntimeReferenceImageLibrary supports the validation of images when added via ScheduleAddImageWithValidationJob(NativeSlice<byte>, Vector2Int, TextureFormat, XRReferenceImage, JobHandle).

    Declaration
    public virtual bool supportsValidation { get; }
    Property Value
    Type Description
    bool
    Remarks
    Important

    Implementors: If this is true, then your implementation must also override:

    • ScheduleAddImageWithValidationJobImpl(NativeSlice<byte>, Vector2Int, TextureFormat, XRReferenceImage, JobHandle)
    • GetAddReferenceImageJobStatus(AddReferenceImageJobState)
    See Also
    CreateRuntimeLibrary(XRReferenceImageLibrary)

    Methods

    CreateAddJobState(IntPtr, JobHandle)

    Derived classes should call this to create an AddReferenceImageJobState to be returned by its implementation of ScheduleAddImageWithValidationJobImpl(NativeSlice<byte>, Vector2Int, TextureFormat, XRReferenceImage, JobHandle).

    Declaration
    protected AddReferenceImageJobState CreateAddJobState(IntPtr handle, JobHandle jobHandle)
    Parameters
    Type Name Description
    IntPtr handle

    A handle to the job state. This should be unique to this job state.

    JobHandle jobHandle

    The JobHandle associated with the add job state.

    Returns
    Type Description
    AddReferenceImageJobState

    Returns a new AddReferenceImageJobState that contains information about the state of an add image job.

    Exceptions
    Type Condition
    ArgumentException

    Thrown if supportsValidation is true and handle is IntPtr.Zero.

    See Also
    CreateRuntimeLibrary(XRReferenceImageLibrary)

    GetAddReferenceImageJobStatus(AddReferenceImageJobState)

    Get the status of an AddReferenceImageJobState.

    Declaration
    protected virtual AddReferenceImageJobStatus GetAddReferenceImageJobStatus(AddReferenceImageJobState state)
    Parameters
    Type Name Description
    AddReferenceImageJobState state

    The state whose status should be retrieved.

    Returns
    Type Description
    AddReferenceImageJobStatus

    Returns the AddReferenceImageJobStatus of an existing AddReferenceImageJobState.

    Remarks
    Important

    Implementors: If supportsValidation is true, then you must also implement this method.

    Exceptions
    Type Condition
    NotImplementedException

    Thrown if the state has a non-zero IntPtr (non-zero means the concrete class should have overriden this method).

    See Also
    CreateRuntimeLibrary(XRReferenceImageLibrary)

    GetEnumerator()

    Gets an enumerator for this collection of reference images. This allows this image library to act as a collection in a foreach statement. The MutableRuntimeReferenceImageLibrary.Enumerator is a struct, so no garbage is generated.

    Declaration
    public MutableRuntimeReferenceImageLibrary.Enumerator GetEnumerator()
    Returns
    Type Description
    MutableRuntimeReferenceImageLibrary.Enumerator

    An enumerator that can be used in a foreach statement.

    See Also
    CreateRuntimeLibrary(XRReferenceImageLibrary)

    GetSupportedTextureFormatAt(int)

    Returns the supported texture format at index. Useful for enumerating the supported texture formats for image addition.

    Declaration
    public TextureFormat GetSupportedTextureFormatAt(int index)
    Parameters
    Type Name Description
    int index

    The index of the format to retrieve.

    Returns
    Type Description
    TextureFormat

    The supported format at index.

    See Also
    CreateRuntimeLibrary(XRReferenceImageLibrary)

    GetSupportedTextureFormatAtImpl(int)

    Derived methods should return the TextureFormat at the given index. index has already been validated to be within [0..supportedTextureFormatCount].

    Declaration
    protected abstract TextureFormat GetSupportedTextureFormatAtImpl(int index)
    Parameters
    Type Name Description
    int index

    The index of the format to retrieve.

    Returns
    Type Description
    TextureFormat

    The supported format at index.

    See Also
    CreateRuntimeLibrary(XRReferenceImageLibrary)

    IsTextureFormatSupported(TextureFormat)

    Determines whether the given format is supported.

    Declaration
    public bool IsTextureFormatSupported(TextureFormat format)
    Parameters
    Type Name Description
    TextureFormat format

    The TextureFormat to test.

    Returns
    Type Description
    bool

    true if format is supported for image addition; otherwise, false.

    See Also
    CreateRuntimeLibrary(XRReferenceImageLibrary)

    ScheduleAddImageJobImpl(NativeSlice<byte>, Vector2Int, TextureFormat, XRReferenceImage, JobHandle)

    This method should schedule a Unity Job which adds an image to this reference image library.

    Declaration
    protected abstract JobHandle ScheduleAddImageJobImpl(NativeSlice<byte> imageBytes, Vector2Int sizeInPixels, TextureFormat format, XRReferenceImage referenceImage, JobHandle inputDeps)
    Parameters
    Type Name Description
    NativeSlice<byte> imageBytes

    The raw image bytes in format. Assume the bytes will be valid until the job completes.

    Vector2Int sizeInPixels

    The width and height of the image, in pixels.

    TextureFormat format

    The format of imageBytes. The format has already been validated with IsTextureFormatSupported(TextureFormat).

    XRReferenceImage referenceImage

    The XRReferenceImage data associated with the image to add to the library. This includes information like physical dimensions, associated Texture2D (optional), and string name.

    JobHandle inputDeps

    Input dependencies for the add image job.

    Returns
    Type Description
    JobHandle

    A JobHandle which can be used to chain together multiple tasks or to query for completion.

    See Also
    ScheduleAddImageWithValidationJobImpl(NativeSlice<byte>, Vector2Int, TextureFormat, XRReferenceImage, JobHandle)

    ScheduleAddImageWithValidationJob(NativeSlice<byte>, Vector2Int, TextureFormat, XRReferenceImage, JobHandle)

    Asynchronously adds an image to this library.

    Declaration
    public AddReferenceImageJobState ScheduleAddImageWithValidationJob(NativeSlice<byte> imageBytes, Vector2Int sizeInPixels, TextureFormat format, XRReferenceImage referenceImage, JobHandle inputDeps = default)
    Parameters
    Type Name Description
    NativeSlice<byte> imageBytes

    The raw image bytes in format.

    Vector2Int sizeInPixels

    The width and height of the image, in pixels.

    TextureFormat format

    The format of imageBytes. Test for and enumerate supported formats with supportedTextureFormatCount, GetSupportedTextureFormatAt(int), and IsTextureFormatSupported(TextureFormat).

    XRReferenceImage referenceImage

    The XRReferenceImage data associated with the image to add to the library. This includes information like physical dimensions, associated Texture2D (optional), and string name. The guid must be set to zero (Empty). A new guid is automatically generated for the new image.

    JobHandle inputDeps

    (Optional) Input dependencies for the add image job.

    Returns
    Type Description
    AddReferenceImageJobState

    Returns an AddReferenceImageJobState that can be used to query the status of the job. The AddReferenceImageJobState can be used to determine whether the image was successfully added. Invalid images will be not be added to the reference image library.

    Remarks

    Image addition can take some time (for example, several frames) due to the processing that must occur to insert the image into the library. This is done using the [Unity Job System] (https://docs.unity3d.com/Manual/JobSystem.html). The returned AddReferenceImageJobState allows your to query for the status of the job, and, if the job completed, whether it was successful. The job state includes the JobHandle which can be used to chain together multiple tasks.

    This job, like all Unity jobs, can have dependencies (using the inputDeps). This can be useful, for example, if imageBytes is the output of another job. If you are adding multiple images to the library, it is not necessary to pass a previous ScheduleAddImageWithValidationJob(NativeSlice<byte>, Vector2Int, TextureFormat, XRReferenceImage, JobHandle)'s JobHandle as the input dependency to the next ScheduleAddImageWithValidationJob(NativeSlice<byte>, Vector2Int, TextureFormat, XRReferenceImage, JobHandle).

    The imageBytes must be valid until this job completes. The caller is responsible for managing its memory. You can use the resulting JobHandle to schedule a job that deallocates the imageBytes.

    Exceptions
    Type Condition
    ArgumentException

    Thrown if imageBytes does not contain any bytes.

    ArgumentException

    Thrown if referenceImage's guid is not Empty.

    ArgumentNullException

    Thrown if referenceImage's name is null.

    ArgumentOutOfRangeException

    Thrown if referenceImage's specifySize is true but referenceImage.size contains values less than or equal to zero.

    InvalidOperationException

    Thrown if the format is not supported. You can query for support using IsTextureFormatSupported(TextureFormat).

    ArgumentOutOfRangeException

    Thrown if sizeInPixels contains values less than or equal to zero.

    See Also
    CreateRuntimeLibrary(XRReferenceImageLibrary)

    ScheduleAddImageWithValidationJobImpl(NativeSlice<byte>, Vector2Int, TextureFormat, XRReferenceImage, JobHandle)

    This method should schedule a Unity Job which adds an image to this reference image library.

    Declaration
    protected virtual AddReferenceImageJobState ScheduleAddImageWithValidationJobImpl(NativeSlice<byte> imageBytes, Vector2Int sizeInPixels, TextureFormat format, XRReferenceImage referenceImage, JobHandle inputDeps)
    Parameters
    Type Name Description
    NativeSlice<byte> imageBytes

    The raw image bytes in format. You can assume the bytes are valid until the job completes.

    Vector2Int sizeInPixels

    The width and height of the image, in pixels.

    TextureFormat format

    The format of imageBytes. The format has already been validated with IsTextureFormatSupported(TextureFormat).

    XRReferenceImage referenceImage

    The XRReferenceImage data associated with the image to add to the library. This includes information like physical dimensions, associated Texture2D (optional), and string name.

    JobHandle inputDeps

    A JobHandle that represents input dependencies for the add image job.

    Returns
    Type Description
    AddReferenceImageJobState

    Returns an AddReferenceImageJobState which contains the state of the asynchronous image addition.

    Exceptions
    Type Condition
    NotImplementedException

    Thrown by this base class implementation. If supportsValidation is true, then this method should be implemented by the derived class.

    See Also
    CreateRuntimeLibrary(XRReferenceImageLibrary)

    Implements

    IReferenceImageLibrary

    See Also

    CreateRuntimeLibrary(XRReferenceImageLibrary)
    In This Article
    Back to top
    Copyright © 2024 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)