Skip to content
Snippets Groups Projects
Select Git revision
  • 9f2053e68d0619f2ed92a9112d7d685fb360e8d8
  • master default protected
  • rednatco-v2
  • rednatco
  • test
  • ntc-tube-uniform-color
  • ntc-tube-missing-atoms
  • restore-vertex-array-per-program
  • watlas2
  • dnatco_new
  • cleanup-old-nodejs
  • webmmb
  • fix_auth_seq_id
  • update_deps
  • ext_dev
  • ntc_balls
  • nci-2
  • plugin
  • bugfix-0.4.5
  • nci
  • servers
  • v0.5.0-dev.1
  • v0.4.5
  • v0.4.4
  • v0.4.3
  • v0.4.2
  • v0.4.1
  • v0.4.0
  • v0.3.12
  • v0.3.11
  • v0.3.10
  • v0.3.9
  • v0.3.8
  • v0.3.7
  • v0.3.6
  • v0.3.5
  • v0.3.4
  • v0.3.3
  • v0.3.2
  • v0.3.1
  • v0.3.0
41 results

generic.ts

Blame
  • camera.ts 1.94 KiB
    /**
     * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
     *
     * @author David Sehnal <david.sehnal@gmail.com>
     */
    
    import { PluginContext } from 'mol-plugin/context';
    import { PluginCommands } from 'mol-plugin/command';
    import { PluginStateObject as SO } from '../../state/objects';
    import { CameraSnapshotManager } from 'mol-plugin/state/camera';
    
    export function registerDefault(ctx: PluginContext) {
        Reset(ctx);
        SetSnapshot(ctx);
        Snapshots(ctx);
    }
    
    export function Reset(ctx: PluginContext) {
        PluginCommands.Camera.Reset.subscribe(ctx, () => {
            const sel = ctx.state.dataState.select(q => q.root.subtree().ofType(SO.Molecule.Structure));
            if (!sel.length) return;
    
            const center = (sel[0].obj! as SO.Molecule.Structure).data.boundary.sphere.center;
            ctx.canvas3d.camera.setState({ target: center });
            ctx.canvas3d.requestDraw(true);
    
            // TODO
            // ctx.canvas3d.resetCamera();
        })
    }
    
    export function SetSnapshot(ctx: PluginContext) {
        PluginCommands.Camera.SetSnapshot.subscribe(ctx, ({ snapshot, durationMs }) => {
            ctx.canvas3d.camera.transition.apply(snapshot, durationMs);
        })
    }
    
    export function Snapshots(ctx: PluginContext) {
        PluginCommands.Camera.Snapshots.Clear.subscribe(ctx, () => {
            ctx.state.cameraSnapshots.clear();
        });
    
        PluginCommands.Camera.Snapshots.Remove.subscribe(ctx, ({ id }) => {
            ctx.state.cameraSnapshots.remove(id);
        });
    
        PluginCommands.Camera.Snapshots.Add.subscribe(ctx, ({ name, description }) => {
            const entry = CameraSnapshotManager.Entry(ctx.canvas3d.camera.getSnapshot(), name, description);
            ctx.state.cameraSnapshots.add(entry);
        });
    
        PluginCommands.Camera.Snapshots.Apply.subscribe(ctx, ({ id }) => {
            const e = ctx.state.cameraSnapshots.getEntry(id);
            return PluginCommands.Camera.SetSnapshot.dispatch(ctx, { snapshot: e.snapshot, durationMs: 200 });
        });
    }