@twinfinity/core
    Preparing search index...

    Class 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

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

      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

      // 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).
      ));

    Properties

    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.

    The API is required for accessing current scene.

    id: number = ...

    Unique id of IconHandler.

    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

    • get iconCount(): number

      Number if icons.

      Returns number

    • get renderGroup(): number

      Render group icons are rendered in.

      Returns number

    • set renderGroup(i: number): void

      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

    • This function insert icons to the handler.

      Parameters

      • icons: Icon | Icon[]

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

      Returns void

    • Clears icon handler of all currently attached icons. Attached icons will be detached.

      Returns void

    • 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

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

      Returns 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

    • Get Icon by id.

      Parameters

      • id: string

        Id of icon to get.

      Returns undefined | Icon

      Icon or undefined if no Icon was found.

    • Icons currently attached to IconHandler.

      Returns IterableIterator<Icon>

    • This function adds a texture and metadata about it to the icon handler. Changes are automatically reflected in rendering.

      Parameters

      Returns void