2.12.8 • Published 1 month ago

@shapediver/viewer.features.interaction v2.12.8

Weekly downloads
-
License
polyform-noncomme...
Repository
github
Last release
1 month ago

@shapediver/viewer.features.interaction

This is the npm package for the ShapeDiver Viewer interaction features. 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.interaction

Usage

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

InteractionEngine

After creating a Viewport and possibly a Session, you can create an InteractionEngine, which is the central hub for all interaction related behavior. This can easily done with the code below.

const interactionEngine = new InteractionEngine(viewport);

Once an InteractionEngine has been created, Selection, Hovering or Dragging can be enabled. Please see the following sections for the description of these features.

Selection

To be able to select objects in the scene, a SelectionManager has to be created. Additionally, the nodes that should be selectable have to be marked as such. This can be seen in the code below.

import { addListener, EVENTTYPE, ISelectEvent, MaterialStandardData } from "@shapediver/viewer";
import { InteractionData, InteractionEngine, SelectManager } from "@shapediver/viewer.features.interaction";

// Create the selection manager and add it
const selectManger = new SelectManager();
// Define a material that should be applied on selection. If no material is defined, the material will not change
selectManger.effectMaterial = new MaterialStandardData({ color: "#ffff00" });
// Add the selection manager to the interaction engine
interactionEngine.addInteractionManager(selectManger);

// In this example, we just make the whole session selectable as one. This can be further expanded to the lowest geometry levels
session.node.data.push(new InteractionData({ select: true }));

// event listener for SELECT_ON
addListener(EVENTTYPE.INTERACTION.SELECT_ON, (e) => {
    const selectEvent = <ISelectEvent>e;
});

// event listener for SELECT_OFF
addListener(EVENTTYPE.INTERACTION.SELECT_OFF, (e) => {
    const selectEvent = <ISelectEvent>e;
});

Via the shown event listeners in the code example actions can be triggered. Additional examples can be viewed on our help desk.

Hovering

To be able to hover objects in the scene, a HoverManager has to be created. Additionally, the nodes that should be hoverable have to be marked as such. This can be seen in the code below.

import { addListener, EVENTTYPE, IHoverEvent, MaterialStandardData } from "@shapediver/viewer";
import { InteractionData, InteractionEngine, HoverManager } from "@shapediver/viewer.features.interaction";

// Create the hover manager and add it
const hoverManger = new HoverManager();
// Define a material that should be applied on hover. If no material is defined, the material will not change
hoverManger.effectMaterial = new MaterialStandardData({ color: "#ffff00" });
// Add the hover manager to the interaction engine
interactionEngine.addInteractionManager(hoverManger);

// In this example, we mark the various outputs of a session as hoverable
for (let  o in session.outputs)
  session.outputs[o].node!.data.push(new InteractionData({ hover: true }));

// event listener for HOVER_ON
addListener(EVENTTYPE.INTERACTION.HOVER_ON, (e) => {
    const hoverEvent = <IHoverEvent>e;
});

// event listener for HOVER_OFF
addListener(EVENTTYPE.INTERACTION.HOVER_OFF, (e) => {
    const hoverEvent = <IHoverEvent>e;
});

Via the shown event listeners in the code example actions can be triggered. A note of caution, if a lot of objects are hoverable make sure that you do not trigger any actions that take a long time in the events. This might affect the performance of your application. Additional examples can be viewed on our help desk.

Dragging

To be able to drag objects in the scene, a DragManager has to be created. Additionally, the nodes that should be draggable have to be marked as such.

For dragging, you also have to define how you want things to be dragged through the scene. There are various options for this which are all explained in our help desk section. In this example, we only add a camera plane constraint.

import { addListener, EVENTTYPE, IDragEvent, MaterialStandardData } from "@shapediver/viewer";
import { InteractionData, InteractionEngine, DragManager } from "@shapediver/viewer.features.interaction";

// Create the drag manager and add it
const dragManger = new DragManager();
// Define a material that should be applied on drag. If no material is defined, the material will not change
dragManger.effectMaterial = new MaterialStandardData({ color: "#ffff00" });
// Add the drag manager to the interaction engine
interactionEngine.addInteractionManager(dragManger);

// add a camera plane constraint
const cameraPlaneConstraint = new CameraPlaneConstraint();
// use the token to remove the constraint again (removeDragConstraint)
const token = dragManager.addDragConstraint(cameraPlaneConstraint);

// In this example, we mark the various outputs of a session as draggable
for (let  o in session.outputs)
  session.outputs[o].node!.data.push(new InteractionData({ drag: true }));

// event listener for DRAG_START 
addListener(EVENTTYPE.INTERACTION.DRAG_START, (e) => {
    const dragEvent = <IDragEvent>e;
});

// event listener for DRAG_MOVE
addListener(EVENTTYPE.INTERACTION.DRAG_MOVE, (e) => {
    const dragEvent = <IDragEvent>e;
});

// event listener for DRAG_END
addListener(EVENTTYPE.INTERACTION.DRAG_END, (e) => {
    const dragEvent = <IDragEvent>e;
});

Via the shown event listeners in the code example actions can be triggered. A note of caution, make sure that you do not trigger any actions that take a long time in the DRAG_MOVE events. These events are fired all the time and might affect the performance of your application. Additional examples can be viewed on our help desk.

2.12.8

1 month ago

2.12.7

2 months ago

2.12.6

2 months ago

2.12.5

3 months ago

2.12.4

3 months ago

2.12.3

3 months ago

2.12.2

3 months ago

2.11.0

7 months ago

2.9.9

8 months ago

2.9.5

10 months ago

2.9.12

5 months ago

2.9.13

5 months ago

2.9.10

8 months ago

2.9.11

8 months ago

2.10.0

8 months ago

2.12.0

5 months ago

2.10.1-rc.0

7 months ago

2.12.1

5 months ago

2.9.2

11 months ago

2.9.1

11 months ago

2.9.4

10 months ago

2.9.3

11 months ago

2.8.5

12 months ago

2.9.0

11 months ago

2.8.1

1 year ago

2.8.0

1 year ago

2.8.3

1 year ago

2.8.2

1 year ago

2.8.4

1 year ago

2.7.10

1 year ago

2.7.4

1 year ago

2.7.6

1 year ago

2.7.5

1 year ago

2.7.8

1 year ago

2.7.7

1 year ago

2.7.9

1 year ago

2.7.0

1 year ago

2.7.2

1 year ago

2.7.1

1 year ago

2.6.1

1 year ago

2.6.3

1 year ago

2.6.2

1 year ago

2.7.3

1 year ago

2.6.5

1 year ago

2.6.4

1 year ago

2.4.1

1 year ago

2.4.0

2 years ago

2.4.2

1 year ago

2.3.4

2 years ago

2.3.3

2 years ago

2.3.5

2 years ago

2.6.0

1 year ago

2.5.0

1 year ago

2.5.1

1 year ago

2.3.0

2 years ago

2.3.2

2 years ago

2.3.1

2 years ago

2.2.5

2 years ago

2.2.4

2 years ago

2.0.3

2 years ago

2.0.2

2 years ago

2.0.5

2 years ago

2.0.4

2 years ago

2.0.7

2 years ago

2.0.6

2 years ago

2.0.9

2 years ago

2.0.8

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.15.7

2 years ago

1.15.6

2 years ago

1.15.5

2 years ago

2.2.1

2 years ago

2.2.0

2 years ago

2.2.2

2 years ago

2.1.2

2 years ago

2.1.1

2 years ago

2.1.3

2 years ago

2.1.6

2 years ago

2.0.11

2 years ago

2.1.5

2 years ago

2.0.12

2 years ago

2.0.10

2 years ago

2.1.0

2 years ago

1.15.0

2 years ago

1.15.4

2 years ago

1.15.3

2 years ago

1.15.2

2 years ago

1.15.1

2 years ago

1.14.10

2 years ago

1.14.11

2 years ago

1.14.12

2 years ago

1.14.13

2 years ago

1.14.14

2 years ago

1.14.15

2 years ago

1.14.16

2 years ago

1.14.1

2 years ago

1.14.0

2 years ago

1.14.5

2 years ago

1.14.4

2 years ago

1.14.3

2 years ago

1.14.2

2 years ago

1.14.9

2 years ago

1.14.8

2 years ago

1.14.7

2 years ago

1.14.6

2 years ago

1.13.10

2 years ago

1.13.9

2 years ago

1.13.8

2 years ago

1.13.7

2 years ago

1.13.2

2 years ago

1.13.1

2 years ago

1.13.6

2 years ago

1.13.5

2 years ago

1.13.4

2 years ago

1.13.3

2 years ago

1.12.6

2 years ago

1.12.5

2 years ago

1.13.0

2 years ago

1.12.3

2 years ago

1.12.2

2 years ago

1.12.1

2 years ago

1.12.0

2 years ago

1.10.9

2 years ago

1.10.8

2 years ago

1.12.4

2 years ago

1.11.12

2 years ago

1.11.10

2 years ago

1.11.11

2 years ago

1.11.4

2 years ago

1.11.3

2 years ago

1.11.2

2 years ago

1.11.8

2 years ago

1.11.7

2 years ago

1.11.6

2 years ago

1.11.5

2 years ago

1.11.9

2 years ago

1.11.0-alpha.0

2 years ago

1.10.15

2 years ago

1.10.13

2 years ago

1.10.14

2 years ago

1.10.11

2 years ago

1.10.12

2 years ago

1.10.10

2 years ago

1.10.7

2 years ago

1.10.6

2 years ago

1.10.5

2 years ago

1.10.4

2 years ago

1.10.1

2 years ago

1.9.0

2 years ago

1.8.14

2 years ago

1.8.13

2 years ago

1.8.12

2 years ago

1.8.11

2 years ago

1.8.10

2 years ago

1.8.9

2 years ago

1.8.8

2 years ago

1.8.7

2 years ago

1.8.6

2 years ago

1.8.5

2 years ago

1.8.4

2 years ago

1.8.3

2 years ago

1.8.2

2 years ago

1.8.1

2 years ago

1.8.0

2 years ago

1.7.1

2 years ago

1.7.0

2 years ago