3.10.0 • Published 2 months ago

@shapediver/viewer.features.drawing-tools v3.10.0

Weekly downloads
-
License
polyform-noncomme...
Repository
github
Last release
2 months ago

@shapediver/viewer.features.drawing-tools

This is the npm package for the ShapeDiver Viewer Drawing Tools feature. Please have a look at our help desk section for this feature.

For more information on ShapeDiver, please visit our homepage. If you need help, have a look at our help desk.

Installation

npm install --save @shapediver/viewer.features.drawing-tools

Usage

As this is an additional package to the @shapediver/viewer package, we omit the initial setup. Please have a look here.

Initialization

The drawing tools can be initialized with the function createDrawingTools, create a new instance of the drawing tools. The following input can be provided to the function:

  • viewport: the viewport API in which the drawing tools should be created
  • callbacks: the onUpdate and onCancel callbacks are called by the drawing tools whenever the drawing tools are either updated or cancelled
  • settings: the settings with which the Drawing Tools are initialized (see below)

Drawing Tools Settings

The settings that can be provided to the drawing tools are separated into four sections:

geometry

The geometry settings of the drawing tool. Here you can define the points, the mode and specific details of the geometry.

PropertyDescription
pointsThe points that are used when starting the drawing tool. The points are defined as an array of arrays, where each array contains the x, y and z coordinates of the point. If the mode is set to 'lines', the points are connected in the order they are defined. If the mode is set to 'points', the points are not connected.
modeThe mode of the geometry. If the mode is set to 'lines', the points are connected in the order they are defined. If the mode is set to 'points', the points are not connected.
minPointsThe minimum amount of points, if undefined, the geometry is not restricted. This value is checked whenever the user tries to update or finish the drawing tool.
maxPointsThe maximum amount of points, if undefined, the geometry is not restricted. This value is checked whenever the user tries to update or finish the drawing tool.
strictMinMaxPointsIf the number of points is strictly checked during the drawing process. If this setting is set to true, once the minimum or maximum amount of points is reached, the user cannot add or remove points that would violate the restriction. If this setting is set to false, the user can add or remove points even if the minimum or maximum amount of points is exceeded temporarily. Once the user tries to update or finish the drawing tool, the amount of points is checked in either case.
closeIf the mode is set to 'lines', if it is a closed line or not. If the mode is set to 'points', this setting is ignored. A line can be closed by connecting the last point with the first point.
autoCloseIf the mode is set to 'lines', if the line is automatically closed. If the mode is set to 'points', this setting is ignored. The first and last point are always connected if the line is automatically closed.

restrictions

The restrictions of the drawing tool.

Here you can define the restrictions that are used when interacting with the drawing tool. At least one restriction is required, the plane and axis restrictions are added by default if no restrictions are defined.

Each restriction is defined by a type and the corresponding properties of that restriction. For further details on this please see the API documentation.

visualization

The visualization settings of the drawing tool. Here you can define the visualization of the drawing tool.

PropertyDescription
distanceMultiplicationFactorThe multiplication factor of the point size when interactions are performed. If the factor is set to 2, the point size is doubled when interacting.
pointLabelsIf the point labels are shown. The point labels display the position of the points.
distanceLabelsIf the distance labels are shown. The distance labels display the distance between the points.
pointsThe material properties of the points. For more details please have a look at the API documentation.
linesThe material properties of the lines. For more details please have a look at the API documentation.

controls

The control settings of the drawing tool. Here you can define which keys are used for the different actions of the drawing tool.

PropertyDescription
insertThe key that is used to insert a point.
deleteThe key that is used to delete a point.
confirmThe key that is used to confirm actions.
cancelThe key that is used to cancel drawing.
undoThe keys that are used to undo the last action.
redoThe keys that are used to redo the last action.

general

The general settings of the drawing tool. Here you can define general settings of the drawing tool.

PropertyDescription
autoStartIf the drawing tool is started automatically when no points are defined.
autoUpdateIf the drawing tool is updated automatically when the drawing is changed.
closeOnUpdateIf the drawing tool is closed when the drawing is updated.
displayUnitThe unit that will be displayed in the distance and point labels.

Code Example

import {
    addListener,
    createSession,
    createViewport,
    EVENTTYPE_DRAWING_TOOLS,
    IEvent
    } from '@shapediver/viewer';
import {
    createDrawingTools,
    IDrawingToolsApi,
    IDrawingToolsEvent,
    PointsData,
    Settings
    } from '@shapediver/viewer.features.drawing-tools';

(async () => {
    // create a viewport
    const viewport = await createViewport({
        canvas: document.getElementById('canvas') as HTMLCanvasElement
    });
    // create a session
    const session = await createSession({
        ticket: 'YOUR_TICKET',
        modelViewUrl: 'YOUR_MODEL_VIEW_URL'
    });

    /**
     * Define the settings you want to use for the drawing tools
     */
    const customizationProperties: Settings = {

    };

    /**
     * Callback function for the drawing tool
     * executed when the drawing tool is updated
     *
     * @param geometryData
     */
    const onUpdate = async (pointsData: PointsData) => {
        console.log('Drawing tools updated', pointsData);
    };

    /**
     * Callback function for the drawing tool
     * executed when the drawing tool is cancelled
     */
    const onCancel = () => {
        console.log('Drawing tools cancelled');
    };

    /**
     * Add an event when the condition for the minimum number of points is not met.
     */
    addListener(EVENTTYPE_DRAWING_TOOLS.MINIMUM_POINTS, (event: IEvent) => {
        console.log((event as IDrawingToolsEvent).message);
    });

    /**
     * Add an event when the maximum number of points has been exceeded.
     */
    addListener(EVENTTYPE_DRAWING_TOOLS.MAXIMUM_POINTS, (event: IEvent) => {
        console.log((event as IDrawingToolsEvent).message);
    });

    const drawingToolsApi: IDrawingToolsApi | undefined = createDrawingTools(viewport, { onUpdate, onCancel }, customizationProperties);
3.9.9

2 months ago

3.9.8

3 months ago

3.9.3

4 months ago

3.7.5

5 months ago

3.5.7

8 months ago

3.9.10

2 months ago

3.9.2

4 months ago

3.7.4

5 months ago

3.5.6

8 months ago

3.9.1

4 months ago

3.7.3

6 months ago

3.5.5

8 months ago

3.9.0

4 months ago

3.7.2

6 months ago

3.5.4

8 months ago

3.9.7

3 months ago

3.9.6

3 months ago

3.9.5

3 months ago

3.9.4

4 months ago

3.8.14

4 months ago

3.8.15

4 months ago

3.8.12

4 months ago

3.8.0

5 months ago

3.10.0

2 months ago

3.8.13

4 months ago

3.8.10

4 months ago

3.6.0

8 months ago

3.8.11

4 months ago

3.8.9

4 months ago

3.8.4

5 months ago

3.8.3

5 months ago

3.8.2

5 months ago

3.8.1

5 months ago

3.8.8

4 months ago

3.8.7

4 months ago

3.8.6

5 months ago

3.8.5

5 months ago

3.7.1

6 months ago

3.5.3

8 months ago

3.7.0

7 months ago

3.5.2

8 months ago

3.5.1

8 months ago

3.5.0

8 months ago

3.4.3

9 months ago

3.4.2

9 months ago

3.4.1

9 months ago

3.4.0

9 months ago

3.3.10

9 months ago

3.3.4

9 months ago

3.3.3

10 months ago

3.3.2

10 months ago

3.3.9

9 months ago

3.3.8

9 months ago

3.3.7

9 months ago

3.3.6

9 months ago

3.3.1

10 months ago

3.3.0

10 months ago

3.2.8

10 months ago

3.2.7

11 months ago

3.2.6

11 months ago

3.2.5

11 months ago

3.2.4

11 months ago

3.2.3

11 months ago

3.2.2

11 months ago

3.2.1

11 months ago

3.2.0

11 months ago

3.1.2

11 months ago

3.1.1

12 months ago

3.1.0

1 year ago