Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to synchronize mouse actions between two NGL stages? #996

Open
jong3 opened this issue Oct 13, 2023 · 1 comment
Open

How to synchronize mouse actions between two NGL stages? #996

jong3 opened this issue Oct 13, 2023 · 1 comment

Comments

@jong3
Copy link

jong3 commented Oct 13, 2023

I created two NGL stage objects :

var stage1 = new NGL.Stage( "viewport1", {backgroundColor: "white"});
var stage2 = new NGL.Stage( "viewport2", {backgroundColor: "white"});

I want the mouse operations of the two stages to be synchronized, that is, when rotating or moving the molecule of one stage, the other stage performs the same action. At present, I have implemented the scrolled action.

stage1.mouseObserver.signals.scrolled.add(function (delta) {
    console.log('scrolled', delta);
    stage2.mouseBehavior._onScroll(delta);
});

But other mouse actions are invalid. i.e. dragged.

stage1.mouseObserver.signals.dragged.add(function (deltaX, deltaY) {
    console.log('dragged', deltaX, deltaY);
    stage2.mouseBehavior._onDrag(deltaX, deltaY);
});

How can I solve this problem? Thank you very much.

@jong3
Copy link
Author

jong3 commented Oct 13, 2023

I've already solved the problem.
For scrolled action:

stage1.mouseObserver.signals.scrolled.add(function (delta) {
    stage2.mouseBehavior._onScroll(delta);
});

For click:

stage1.signals.clicked.add(function (pickingProxy) {
    stage2.animationControls.move(pickingProxy.position.clone());
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant