Skip to content

Commit 81f8d00

Browse files
committed
Fix toggleSpin
1 parent 2a49cb2 commit 81f8d00

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

src/app/viewer.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ import { PDBeViewport_NoFullscreen } from './ui/pdbe-viewport';
7171
import { PDBeViewportControls } from './ui/pdbe-viewport-controls';
7272
import { UIComponents } from './ui/split-ui/components';
7373
import { LayoutSpec, createPluginSplitUI, resolveHTMLElement } from './ui/split-ui/split-ui';
74+
import { TrackballControlsProps } from 'molstar/lib/mol-canvas3d/controls/trackball';
7475

7576

7677
export class PDBeMolstarPlugin {
@@ -693,17 +694,17 @@ export class PDBeMolstarPlugin {
693694
},
694695

695696
/** With `isSpinning` parameter, switch visual rotation on or off. Without `isSpinning` parameter, toggle rotation. If `resetCamera`, also reset the camera zoom. */
696-
toggleSpin: async (isSpinning?: boolean, resetCamera?: boolean) => {
697+
toggleSpin: async (spin?: boolean, resetCamera?: boolean) => {
697698
if (!this.plugin.canvas3d) return;
698699
const trackball = this.plugin.canvas3d.props.trackball;
699-
700-
let toggleSpinParam: any = trackball.animate.name === 'spin' ? { name: 'off', params: {} } : { name: 'spin', params: { speed: 1 } };
701-
702-
if (typeof isSpinning !== 'undefined') {
703-
toggleSpinParam = { name: 'off', params: {} };
704-
if (isSpinning) toggleSpinParam = { name: 'spin', params: { speed: 1 } };
700+
if (spin === undefined) {
701+
spin = (trackball.animate.name !== 'spin'); // toggle current spin state
705702
}
706-
await PluginCommands.Canvas3D.SetSettings(this.plugin, { settings: { trackball: { ...trackball, animate: toggleSpinParam } } });
703+
const animationParams: TrackballControlsProps['animate'] =
704+
spin ?
705+
{ name: 'spin', params: { speed: 0.1, axis: Vec3.create(0, 1, 0) } }
706+
: { name: 'off', params: {} };
707+
await PluginCommands.Canvas3D.SetSettings(this.plugin, { settings: { trackball: { ...trackball, animate: animationParams } } });
707708
if (resetCamera) await PluginCommands.Camera.Reset(this.plugin, {});
708709
},
709710

0 commit comments

Comments
 (0)