Annotations Plugin for ThreePipe
    Preparing search index...

    Class AnnotationsPlugin

    Annotations Plugin

    3D annotations ("hotspots"), like Sketchfab's: numbered markers on the model. Click one: the camera goes to the view saved with it and a card shows its title and text, with ‹ prev / next › (also ←/→, Esc closes).

    • Saved with the scene: annotations is a serialized property, so the viewer config and viewer.exportScene({viewerConfig: true}) (the .glb) hold it, and loading them restores it.
    • Markers are attached to an object (local point + normal), so they follow the object when it moves or animates.
    • Markers behind geometry or on a surface that faces away are dimmed. The occlusion test casts a few rays per frame, only after the camera, an anchor or the scene changed, and while frames render (an animation) at most every occlusionRecheckInterval ms.
    • editable: startAdding (then click a surface), edit the title and the text in the card, "Update view", "Delete", and drag a marker to another surface point (dragOnlySelected: the open one only). All edits are undoable with UndoManagerPlugin, and so is the selection: opening an annotation or closing the card is one undo step, as the selection of the PickingPlugin.
    • The card stays open until it is closed (its close button, Esc) or a click (no drag) on the canvas. With closeOnCanvasInteraction, any interaction with the canvas closes it: also a drag (orbit) or a wheel zoom.
    • Tour: goTo, next, prev, playTour; events annotationChange and annotationSelect for an outside list.
    • renderCardContent: the app renders the content of the card (not in editable mode), for example from the values in Annotation.data.
    • compactCard: the card shows the title and the text only, and a tour bar at the bottom centre has ‹ the title of the open annotation ›. The bar fades while the user moves the camera (tourBar). showCloseButton hides the ✕ of the card.

    The markers and the card are in a layer over the canvas, in the viewer container (which must be positioned, for example position: relative). The UI folder (Annotations) has Editable, Drag only selected, Close on canvas interaction, Close button, Compact card, Add, Play tour and Remove all.

    Hierarchy

    Index
    _dirty: boolean = false
    _viewer?: ThreeViewer
    _viewerListeners: { postFrame: () => void; postRender: () => void } = ...
    actions: ViewerAction[] = ...

    The keys of the plugin, as actions (registered in viewer.actions, where a UI lists them): → and ← open the next and the previous annotation while a card is open, before the arrow keys of the camera controls on the canvas (capture); a held arrow goes on through them. With more viewers on the page, the viewer with the focus, or the one used last, takes the key. Escape (close the card) stays a key of the card.

    animDuration: number = 900

    Camera animation time in ms for a large move (short moves are faster)

    annotations: Annotation[] = []

    All annotations in tour order. Saved with the scene (in the .glb). Change them through the methods.

    closeOnCanvasInteraction: boolean = false

    Any interaction with the canvas closes the open card: a click, a drag (orbit, pan with a finger, a pinch: as soon as the pointer moves 4px) and a wheel zoom. Primary button and touch only; not while placing or dragging a marker. Default false: only a click (no drag) on the canvas closes it, and the card stays while the camera orbits. Not saved with the scene, like editable.

    constructor: typeof AViewerPluginSync & typeof AViewerPlugin
    dependencies: typeof PopmotionPlugin[] = ...
    enabled: boolean = true
    isViewerPluginSync: true = ...
    occlusionRaysPerFrame: number = 8

    Max rays per frame for the occlusion test (it also stops after ~2 ms)

    occlusionRecheckInterval: number = 200

    After rendered frames, the occlusion test runs again at most this often (ms), for geometry that moves without a scene update (an animation). No frames: no test.

    uiConfig: UiObjectConfig = ...
    InjectStyles: boolean = true

    Adds the stylesheet of the anp- classes to the page when the first plugin is added. Off: the page styles them.

    OldPluginType?: string
    PluginType: "AnnotationsPlugin" = 'AnnotationsPlugin'
    • get compactCard(): boolean

      A compact card, for a viewer with a tour: the card shows the title and the text only (editable: Update view and Delete at its top, before the ✕), and the tour bar at the bottom centre has ‹ the title of the open annotation ›. The bar fades while the user moves the camera, see tourBar. Default false: the card has ‹ 1 / 3 › and the tools in its bottom row. Not saved with the scene, like editable.

      Returns boolean

    • set compactCard(v: boolean): void

      Parameters

      • v: boolean

      Returns void

    • get dragOnlySelected(): boolean

      Editable: only the open (selected) annotation can be dragged to another surface point. A press on another marker opens it with a click, and a drag from it moves the camera, as a drag on the canvas does. Off: a drag on any marker moves it. Default true: in an editor a drag that starts on a marker is often meant to orbit, and the markers are small; with it on, a marker moves only after it was opened, and that move is one undo step. Not saved with the scene, like editable.

      Returns boolean

    • set dragOnlySelected(v: boolean): void

      Parameters

      • v: boolean

      Returns void

    • get renderCardContent(): AnnotationCardRenderer | undefined

      A hook for the app: renders the content of the card (in place of the title and the text) when editable is off. The ✕, the ‹ › of the card and the tour bar of compactCard stay; in editable mode the default editor card shows. It runs when an annotation opens, when the annotations change, and when it is set: set it again to render the open card again (for app state it reads). Returning undefined gives the default content, and so does an error (logged). A string is set as HTML as is, so escape what comes from a file or a user (escapeHtml, renderAnnotationText). Clicks and keys in the content do not reach the viewer, as in the default card.

      Returns AnnotationCardRenderer | undefined

      annotations.renderCardContent = (a, {index}) => a.data?.price === undefined ? undefined :
      `<h3>${escapeHtml(a.title)}</h3><p>${renderAnnotationText(a.text)}</p><b>$${escapeHtml(String(a.data.price))}</b>`
    • set renderCardContent(v: AnnotationCardRenderer | undefined): void

      Parameters

      Returns void

    • get tourBar(): "hidden" | "shown" | "faded"

      The state of the tour bar of compactCard:

      • 'hidden': the option is off, no annotation is open, a new one is being placed, or the plugin is disabled
      • 'shown': an annotation is open (also during playTour)
      • 'faded': shown, but the user moves the camera (a drag past 4px or a wheel on the canvas); it shows again 400 ms after the pointer up or the last wheel event

      Returns "hidden" | "shown" | "faded"

    • Parameters

      • e: IViewerEvent

      Returns IViewerEvent

    • Parameters

      • Optionalprefix: string

      Returns string

    • Add an annotation on object at a point and normal in its local space. view defaults to the current camera view. content.instanceId: an instance of an InstancedMesh, the point and the normal are then in that instance's space. content.data: values of the app (Annotation.data). Undoable. Returns the new annotation.

      Parameters

      • object: IObject3D
      • localPoint: Vector3
      • localNormal: Vector3
      • Optionalview: AnnotationView | null
      • content: {
            data?: Record<string, any>;
            instanceId?: number;
            text?: string;
            title?: string;
        } = {}

      Returns Annotation

    • Parameters

      • key: any
      • setDirty: boolean = true

      Returns void

    • Parameters

      • key: any
      • setDirty: boolean = true

      Returns void

    • Returns ISerializedConfig | Record<string, never>

    • The object an annotation is on, or null when it is not in the scene. Found by uuid, or by the path of names on the first look up (after a load, where the uuids can be new). Once found, the annotation stays on that object: when it leaves the scene, the marker hides (an object with the same path, like an unnamed sibling, does not take it), and it shows again when the object, or one with its uuid, is back.

      Parameters

      Returns
          | IObject3D<
              IObject3DEventMap,
              IGeometry<NormalBufferAttributes, BufferGeometryEventMap>
              | undefined,
              IMaterial<IMaterialEventMap> | IMaterial<IMaterialEventMap>[] | undefined,
          >
          | null

    • Open an annotation: the camera goes to its saved view and the card opens. In editable mode, opening another annotation is one undo step (the undo opens the one before, or closes the card), as a selection.

      Parameters

      • indexOrId: string | number

        place in the tour or id

      • options: { fly?: boolean; focusTitle?: boolean } = {}

        fly: false keeps the camera; focusTitle puts the cursor in the title (editable only)

      Returns void

    • Parameters

      • state: any

      Returns Promise<void>

    • Go through the annotations one after another, like Sketchfab's autopilot. Any click or key stops it. The tour adds no undo steps.

      Parameters

      • intervalMs: number = 5000

      Returns void

    • Parameters

      • ...args: any[]

      Returns any

    • Editable only: the next click on a surface places a new annotation there, with the current camera view. Esc or a right click cancels. Returns false when it did not start (not editable, not added, disabled, or already placing).

      Returns boolean

    • Change the title, text, view or data of an annotation. Undoable.

      Parameters

      • id: string
      • patch: Partial<Pick<Annotation, "title" | "text" | "view" | "data">>

      Returns void