Skip to main content

IconHandler

Icon Handler is a class for handling a set of Icon:s. Make a instance and setIconAtlas with a texture. Then addIcons to provide a array of Icon[]. Each Icon in the handler can be updated using forEach(). Followed by update().

Index

Constructors

constructor

  • A Icon Handler holds and handle interaction of icons and it´s gpu representation.

    @example
    // Create an IconHandler instance.
    const iconHandler = new IconHandler(api);
    // Add a icon atlas to use for all icons. Provide the babylonTextre, the total icon count, the amount of icons in a group and if the texture use the alpha channel.
    iconHandler.setIconAtlas({
    texture: (await getTexture('./icon.png')),
    totalNumberOfIconsAndStyles: 100,
    numberOfIconsInAStyle: 1,
    hasAlpha: true
    });
    // Add a icon to be renderd.
    iconHandler.attach(new Icon(
    "someId",
    Math.floor(Math.random() * 100), // Use a random icon form the 10X10 icon atlas.
    0, // Use a style index, in this case there is no groups of icons in the texture atlas, so we use the first icon.
    1, // Size
    new Vector3(0, 0, 0), // Add a position for the icon. (at origin in this case).
    new Color4(Math.random(), Math.random(), Math.random(), 1) // Add a random color to the icon, and the max size to the icon. (1).
    ));

    Parameters

    • api: BimCoreApi

      The API is required for accessing current scene.

    • optionaloptions: IconAtlasOptions

      Here you can provide a everything you need to set the icon texture atlas.

    Returns IconHandler

Properties

publicalphaSortInterval

alphaSortInterval: number = IconHandler._defaultAlphaSortInterval

Defines how often the Icons in the IconHandler are alpha sorted (back to front) relative the camera if icons are transparent.

  • If 0 then alpha sort runs every frame. Very expensive. Avoid
  • If > 0 then alpha sort culling runs only when the interval is exceeded.
  • If < 0 alpha sort is disabled.
  • Defaults to 500 ms.

publicreadonlyapi

The API is required for accessing current scene.

publicreadonlyid

id: number = ...

Unique id of IconHandler.

publicocclusionCullingInterval

occlusionCullingInterval: number = -1

Defines how often the Icons in the IconHandler are occlusion culled in milliseconds.

  • If 0 then occlusion culling runs every frame. Very expensive. Avoid
  • If > 0 then occlusion culling runs only when the interval is exceeded.
  • If < 0 occlusion culling is disabled.
  • Defaults to -1

Accessors

publiciconCount

  • get iconCount(): number
  • Number if icons.


    Returns number

publicrenderGroup

  • get renderGroup(): number
  • set renderGroup(i: number): void
  • Render group icons are rendered in.


    Returns number

  • Sets the render group id 0-4 for all icons. Use this with a larger value to render it on top of other geometry in the engine.


    Parameters

    • i: number

    Returns void

Methods

publicattach

  • This function insert icons to the handler.


    Parameters

    • icons: Icon | Icon[]

      A array of icons or a icon to render in scene.

    Returns void

publicclear

  • clear(): void
  • Clears icon handler of all currently attached icons. Attached icons will be detached.


    Returns void

publicdetach

  • This function detach icons from the handler and remove it from picking if it´s clickable.


    Parameters

    • icons: Icon | Icon[]

      A array of icons or a icon to remove from scene.

    Returns void

publicdispose

  • dispose(): void
  • Disposes icon handler. Call when it is no longer in use. After call the icon handler cannot be used again.


    Returns void

publicforEach

  • forEach(action: (i: Icon) => unknown): void
  • Iterate over each icon in the handler. See also icons.


    Parameters

    • action: (i: Icon) => unknown

      This method will run on each icon in the handler. This is a easy way for updating its position or color.

    Returns void

publicgetIconById

  • getIconById(id: string): undefined | Icon
  • Get Icon by id.


    Parameters

    • id: string

      Id of icon to get.

    Returns undefined | Icon

    Icon or undefined if no Icon was found.

publicicons

  • icons(): IterableIterator<Icon>

publicsetIconAtlas

  • setIconAtlas(o: IconAtlasOptions): void
  • This function adds a texture and metadata about it to the icon handler. Changes are not reflected in rendering unless apply is called afterwards.


    Parameters

    • o: IconAtlasOptions

      Option in the form of IconAtlasOptions.

    Returns void