@masatomakino/threejs-interactive-object
    Preparing search index...

    Interface IClickableObject3D<Value>

    Interface contract for objects that can respond to pointer interactions.

    Defines the required structure for Three.js objects to become interactive within the MouseEventManager system. Objects implementing this interface can receive pointer events (mouse, touch, pen) and respond appropriately through their associated ButtonInteractionHandler.

    Implementation Requirements: Objects must provide an interactionHandler property that implements ButtonInteractionHandler. This handler manages the object's interaction behavior, state transitions, and event emission.

    Detection Mechanism: MouseEventManager uses this interface to identify interactive objects during raycasting. Objects are validated using a type guard that checks for the presence and structure of the interactionHandler property.

    import { ButtonInteractionHandler } from '@masatomakino/threejs-interactive-object';
    import { Mesh, BoxGeometry, MeshBasicMaterial } from 'three';

    // Creating an interactive object by implementing the interface
    class MyInteractiveMesh extends Mesh implements IClickableObject3D<string> {
    public readonly interactionHandler: ButtonInteractionHandler<string>;

    constructor() {
    super(new BoxGeometry(1, 1, 1), new MeshBasicMaterial());
    this.interactionHandler = new ButtonInteractionHandler({ view: this });
    this.interactionHandler.value = 'my-custom-button';
    }
    }

    // Using with existing objects via composition
    const mesh = new Mesh(geometry, material);
    const handler = new ButtonInteractionHandler({ view: mesh });
    (mesh as IClickableObject3D<number>).interactionHandler = handler;
    handler.value = 42;
    • The interface is designed for composition rather than inheritance
    • Most implementations use the provided ClickableMesh, ClickableSprite, or conversion utilities
    • The Value type parameter enables type-safe custom data association
    • MouseEventManager validates objects using implementsIClickableObject3D() type guard
    interface IClickableObject3D<Value> {
        interactionHandler: ButtonInteractionHandler<Value>;
    }

    Type Parameters

    • Value

      Type of custom data associated with the interactive object. Used for identifying specific objects in event handlers.

    Implemented by

    Index

    Properties

    interactionHandler: ButtonInteractionHandler<Value>

    The interaction handler that manages this object's pointer event responses.

    This handler is responsible for processing pointer events, managing interaction states, updating visual materials, and emitting appropriate events. It serves as the bridge between the MouseEventManager's event detection and the object's behavioral responses.