PointerDragBehavior with two/second camera/viewport

Hello again!

This:

is a combination of this one:

where @Deltakosh said “…a bug where the ray caster considers meshes on the wrong layer…”

and this one:

where we want to drag objects in the XZ plane.

PROBLEM: while an object is dragged the scene moves too (suspect the problem is that PointerDragBehavior.detachCameraControls does not kick in).

SITUATION: 3 blue objects in the first viewport, and the axis pointers in the second one (lower left corner).

I the case of one camera/viewport - this problem does not occur.

Please advise!

function _pick_down(a) {

CAMERA.detachControl(canvas, true)

if (a.sourceEvent.button == 0) {
	OBJ.itemMove = a.source;
	DRAGXY.attach(OBJ.itemMove);
}

}

function _pick_up(a) {

CAMERA.attachControl(canvas, true)
if (a.source == OBJ.itemMove) {
	DRAG.detach(OBJ.itemMove);
    DRAG.releaseDrag();
	OBJ.itemMove = null;
}

}

The problem is your glitch came back now though o_O… the plot thickens!

1 Like

@Pryme8

Yes, I’m fixing it this way in my project, by detaching and attaching the camera. But when I saw the “detachCameraControls” property, decided to create the simper case (one camera/viewport only).

And seeing it’s not working with 2 cameras - decided to report it.

is this pg working as you expect?
https://www.babylonjs-playground.com/index.html#UTINNB#19

2 Likes

Oooo gotcha! It prolly only works for the activeCamera then for the detachCameraControls, Im not sure though.

@trevordev

Yes, I solved it this way in my project, too. And it works.

But decided to report is as I’m far too new to Babylon and could not decide if this is the correct way for the 2 viewports scenario or this is a bug - as the behavior should be able to detach the camera as in the 1 viewport case.

Hope this helps!

1 Like

Thanks, I think it should still only effect the active camera, for complex cases it is recommended to handle camera attaching/detaching manually like you’ve done.