@inweb/viewer-three
Version:
JavaScript library for rendering CAD and BIM files in a browser using Three.js
90 lines (84 loc) • 3.92 kB
text/typescript
///////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2002-2025, Open Design Alliance (the "Alliance").
// All rights reserved.
//
// This software and its documentation and related materials are owned by
// the Alliance. The software may only be incorporated into application
// programs owned by members of the Alliance, subject to a signed
// Membership Agreement and Supplemental Software License Agreement with the
// Alliance. The structure and organization of this software are the valuable
// trade secrets of the Alliance and its suppliers. The software is also
// protected by copyright law and international treaty provisions. Application
// programs incorporating this software must include the following statement
// with their copyright notices:
//
// This application incorporates Open Design Alliance software pursuant to a
// license agreement with Open Design Alliance.
// Open Design Alliance Copyright (C) 2002-2025 by Open Design Alliance.
// All rights reserved.
//
// By use of this software, its documentation or related materials, you
// acknowledge and accept the above terms.
///////////////////////////////////////////////////////////////////////////////
import { IDraggersRegistry, draggersRegistry } from "@inweb/viewer-core";
import { CuttingPlaneXAxisDragger } from "./CuttingPlaneXAxis";
import { CuttingPlaneYAxisDragger } from "./CuttingPlaneYAxis";
import { CuttingPlaneZAxisDragger } from "./CuttingPlaneZAxis";
import { MeasureLineDragger } from "./MeasureLineDragger";
import { OrbitDragger } from "./OrbitDragger";
import { PanDragger } from "./PanDragger";
import { WalkDragger } from "./WalkDragger";
import { ZoomDragger } from "./ZoomDragger";
/**
* Viewer draggers registry. Use this registry to register custom draggers.
*
* To implement custom dragger:
*
* 1. Define a dragger class implements {@link IDragger}.
* 2. Define a constructor with a `viewer` parameter and add mouse event listeners for the specified viewer.
* 3. Define the dragger logic in the event listeners. For example, listen for the `mousemove` event and
* zoom in/out when the left mouse button is pressed.
* 4. Override {@link IDragger.dispose} and remove mouse event listeners from the viewer.
* 5. Register dragger provider in the draggers registry by calling the {@link draggers.registerDragger}.
*
* @example Implementing a custom dragger.
*
* ```javascript
* import { IDragger, draggers, Viewer } from "@inweb/viewer-three";
*
* class MyDragger implements IDragger {
* protected viewer: Viewer;
*
* constructor(viewer: Viewer) {
* this.viewer = viewer;
* this.viewer.addEventListener("pointermove", this.onPointerMove);
* }
*
* override dispose() {
* this.viewer.removeEventListener("pointermove", this.onPointerMove);
* }
*
* onPointerMove = (event: PointerEvent) => {
* // place custom logic here
* };
* }
*
* draggers.registerDragger("MyDragger", (viewer): IDragger => new MyDragger(viewer));
* ```
*
* @example Activating a custom dragger.
*
* ```javascript
* viewer.setActiveDragger("MyDragger");
* ```
*/
export const draggers: IDraggersRegistry = draggersRegistry("threejs");
// build-in draggers
draggers.registerDragger("Pan", (viewer) => new PanDragger(viewer));
draggers.registerDragger("Orbit", (viewer) => new OrbitDragger(viewer));
draggers.registerDragger("Zoom", (viewer) => new ZoomDragger(viewer));
draggers.registerDragger("MeasureLine", (viewer) => new MeasureLineDragger(viewer));
draggers.registerDragger("CuttingPlaneXAxis", (viewer) => new CuttingPlaneXAxisDragger(viewer));
draggers.registerDragger("CuttingPlaneYAxis", (viewer) => new CuttingPlaneYAxisDragger(viewer));
draggers.registerDragger("CuttingPlaneZAxis", (viewer) => new CuttingPlaneZAxisDragger(viewer));
draggers.registerDragger("Walk", (viewer) => new WalkDragger(viewer));