EventListener detect if model was orbited

Hi All,

Is there any scene.addEventListener that detects when the ShapeDiver canvas is orbited?

I have a CSS animation inviting users to “orbit” the canvas, as an advise that what they are seeing is a 3D model, so I want to detect when the user rotates the viewer and then hide the container with the CSS animation.

Thanks!

I haven’t tried the API yet but this page looks relevant?

https://viewer.shapediver.com/v2/2.18.0/doc/module-ApiSceneInterface-ApiSceneInterface.html#EVENTTYPE

Specifically, these three event types:

DRAG_START SceneEventType drag.start dragging of an object started
DRAG_MOVE SceneEventType drag.move continuously fired during dragging of an object
DRAG_END SceneEventType drag.end dragging of an object ended

And maybe this page too?

Thank you @Joseph_Oster, I had previously tried with these SceneEventType and I think that they are waiting for an object to move from position (maybe for clickable 3d objects).

I also tried with HOVER_ON SceneEventType and it works when the mouse hovers an object (callback), but I want specifically fire an event when the scene is orbited.

Thanks!

That makes sense. Scrolling the page a little more I see this one:

LIVETRANSFORMATIONTYPE :LiveTransformationType

Enum for supported live transformation types.

Type:
Properties:
Name Type Default Description
ROTATION LiveTransformationType rotation the transformation is a rotation

But again, I could be wrong. I better hold off until I try these things myself.

There are general camera movement events that are triggered when any camera movement starts, is in progress or stops: http://app.shapediver.com/api/module-CameraApi-CameraApi.html#EVENTTYPE

However, you won’t be able to discrimnate between the different types of movement (rotations, zooming and panning).

1 Like

Thank you @mathieu1 It works.

For the viewer I have zooming and panning disabled, so EVENTYPE CAMERA_START will detect rotation.

Thanks!

api.scene.camera.addEventListener(api.scene.camera.EVENTTYPE.CAMERA_END, alert("CAM END");

Is this code correct, if I want to trigger a function/alert after a user is for example zooming in?

I do get an alert when a scene is loaded, but not after manual movements.

@shwdehaan the correct form is:

api.scene.camera.addEventListener(api.scene.camera.EVENTTYPE.CAMERA_END, function(){alert("CAM END")});

Another option is to declare your function first and then use it in the event listener:

var myFunction = function(){alert("CAM END")};

api.scene.camera.addEventListener(api.scene.camera.EVENTTYPE.CAMERA_END, myFunction);
1 Like

Thank you, this indeed works.

I’m now testing with an orthogonal camera (cameraType = 1), but it doesn’t seem to trigger the event listener. Is this expected behavior?

Update: I guess this has to do with the fact that zooming in orthogonal mode doens’t actually make the camera move, it only changes the camera target. Is there any way to trigger an event in this case?

Update 2: Maybe not: panning dóes move the camera, also in ortho mode, and it doesn’t trigger.

Update 3: When setting the camera damping factor to 1.0 camera movements also fail to trigger.

Sorry for the late answer. After some testing, it appears that the event is indeed not triggered with the orthogonal cameras. I have filed a bug and will let you know once it is fixed.

1 Like

Hi Matthieu,

Do you have an update?

The issue should be resolved in the latest version of the viewer (2.20.2). Please update it in your code and let me know if that is the case.

1 Like