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

    Class StateMaterialSet

    A comprehensive material manager for interactive object states.

    StateMaterialSet manages multiple StateMaterial instances for different interactive states including normal, hover, down, disable, and their selected variants. It provides intelligent state-based material selection with priority logic and unified opacity control across all managed materials for coordinated visual feedback.

    • Only normal material is required; unspecified states automatically use the normal material
    • disable state has priority over interaction states (normal, over, down)
    • Supports both regular and selected variants for each interaction state
    • Provides unified opacity control across all managed materials
    • Handles state transitions with appropriate material switching
    // Minimal setup with only normal material
    const materialSet = new StateMaterialSet({
    normal: new MeshBasicMaterial({ color: 0x888888 })
    });

    // Complete setup with hover, disable, and selected states
    const fullMaterialSet = new StateMaterialSet({
    normal: new MeshBasicMaterial({ color: 0x888888 }),
    over: new MeshBasicMaterial({ color: 0xaaaaaa }),
    disable: new MeshBasicMaterial({ color: 0x444444 }),
    normalSelect: new MeshBasicMaterial({ color: 0x0088ff })
    });
    Index

    Constructors

    Properties

    disable: StateMaterial
    downSelect: StateMaterial
    materials: StateMaterial[] = []
    normalSelect: StateMaterial
    overSelect: StateMaterial

    Methods

    • Gets the appropriate StateMaterial for the given interaction state and conditions.

      Parameters

      • state: ClickableState

        The current interaction state (normal, over, down)

      • mouseEnabled: boolean

        Whether mouse interaction is enabled for the object

      • isSelected: boolean = false

        Whether the object is in selected state (default: false)

      Returns StateMaterial

      The StateMaterial instance for the specified conditions

      State selection priority:

      1. If mouseEnabled is false, always returns disable material
      2. Otherwise, returns the appropriate material based on state and selection:
        • normal + selected = normalSelect
        • over + selected = overSelect
        • down + selected = downSelect
        • normal = normal
        • over = over
        • down = down
      const materialSet = new StateMaterialSet({
      normal: normalMat,
      over: hoverMat,
      disable: disabledMat
      });

      // Get normal material
      const normal = materialSet.getMaterial("normal", true, false);

      // Get hover material for selected object
      const hoverSelected = materialSet.getMaterial("over", true, true);

      // Get disabled material (ignores state and selection)
      const disabled = materialSet.getMaterial("over", false, true);
    • Sets the opacity for all managed materials simultaneously.

      Parameters

      • opacity: number

        The opacity multiplier to apply (0.0 to 1.0)

      Returns void

      Applies the opacity multiplier to all managed StateMaterial instances simultaneously.

      // Set all materials to 50% of their original opacity
      materialSet.setOpacity(0.5);

      // Make invisible or restore original opacity
      materialSet.setOpacity(0.0); // invisible
      materialSet.setOpacity(1.0); // original