Function drawGizmo

  • Marks the function as a callback for reporting when Gizmos are being drawn for the specified Component type.

    The attributed function must have the following signature

      - (component:Component, camera?:Camera, state?:any)
    

    When the callback is invoked, the component parameter will contain the instance of the component that requests Gizmos to be drawn. The camera parameter contains the Camera that is currently used for drawing the Gizmos.

    If the DrawGizmoFlags.Stateful is specified, a state object will be passed to the method. The state object can be used to store arbitrary data on the state for the current invocation. As long as the component is selected, the same state object will be passed to the method. The state object is guaranteed to be unique for each component, so it can be used to store state or cache data for the current component. However, to avoid colliding with other users of the state, it's best to store your data in a field on the state object uses a Symbol to access. The use of the Symbol guarantees the uniqueness of the field without any potential for collision. The state will automatically be released once the component is deselected. Do not hold on to the state object, or create a reference to the state object in other objects.


    const stateSymbol = Symbol("CustomRenderableGizmoState");

    export class CustomRenderableGizmo
    {
    \@drawGizmo(Renderable, DrawGizmoFlags.Selected | DrawGizmoFlags.Stateful)
    static draw(renderable: Renderable, camera:Camera, state:{
    [stateSymbol]?: {
    selectionTime: number
    }
    })
    {
    if (state[stateSymbol] == null)
    {
    state[stateSymbol] = {
    selectionTime: Date.now()
    };
    }
    }
    }

    Parameters

    Returns AttributeDecorator<Attribute>

    Use the APIs such as Gizmos.drawIcon or Gizmos.drawWireCube to draw gizmos in the scene. Before drawing the gizmos you can setup the color using Gizmos.color or an additional transformaiton using Gizmos.transform.