docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class InstanceIdToColorMapping

    Static class to procedurally generate a unique color for an instance ID. This algorithm is deterministic, and will always return the same color for a ID, and the same ID for a color. ID 0 is reserved to be an invalid ID and is mapped to color black (0,0,0,255). Invalid IDs always map to black, and black always maps to ID 0. In order to try to create visually contrasting colors for IDs, there are a subset of IDs reserved (1-65) to be generated by applying the golden ration to find the next color in the HSL spectrum. All of these colors, and only theses colors, will be in the alpha channel 255. After the first 65 IDs, the color will be determined by iterating through all available RGB values in the alpha channels from 264 - 1. Alpha channel 0 is marked as invalid. This service will support over 4 billion unique IDs => colors [(256^4) - (256*2) + 64]

    Inheritance
    object
    InstanceIdToColorMapping
    Inherited Members
    object.ToString()
    object.Equals(object)
    object.Equals(object, object)
    object.ReferenceEquals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    Namespace: UnityEngine.Perception.GroundTruth
    Assembly: solution.dll
    Syntax
    public static class InstanceIdToColorMapping

    Fields

    Name Description
    maxId

    The max ID supported by this class.

    Methods

    Name Description
    GetColorFromInstanceId(uint)

    Retrieve the color that is mapped to the passed in ID. If the ID is 0 or 255 the returned color will be black.

    GetColorFromPackedColor(uint)

    Converts a packed color (or unsigned 32bit representation of a color) into an RGBA color.

    GetInstanceIdFromColor(Color32)

    Retrieve the ID associated with the passed in color. If the passed in color is black this service will return 0.

    GetPackedColorFromColor(Color32)

    Packs a color32 (RGBA - 1 byte per channel) into a 32bit unsigned integer.

    TryGetColorFromInstanceId(uint, out Color32)

    Retrieve the color that is mapped to the passed in ID. If the ID is 0 or 255 false will be returned, and color will be set to black.

    TryGetInstanceIdFromColor(Color32, out uint)

    Retrieve the ID associated with the passed in color. If the passed in color is black or cannot be mapped to an ID this service will return false, and the out id will be set to 0.

    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)