Skip to content
Snippets Groups Projects
Select Git revision
  • 3134e1d9f993d6a16b5e76e7a87a7422c268cea3
  • master default protected
  • rednatco-v2
  • base-pairs-ladder
  • 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
  • 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

animation-loop.ts

Blame
  • animation-loop.ts 1.73 KiB
    /**
     * Copyright (c) 2020 mol* contributors, licensed under MIT, See LICENSE file for more info.
     *
     * @author David Sehnal <david.sehnal@gmail.com>
     */
    
    import { PluginContext } from './context';
    import { now } from '../mol-util/now';
    import { PluginAnimationManager } from '../mol-plugin-state/manager/animation';
    
    export class PluginAnimationLoop {
        private currentFrame: any = void 0;
        private _isAnimating = false;
    
        get isAnimating() {
            return this._isAnimating;
        }
    
        async tick(t: number, options?: { isSynchronous?: boolean, manualDraw?: boolean, animation?: PluginAnimationManager.AnimationInfo }) {
            await this.plugin.managers.animation.tick(t, options?.isSynchronous, options?.animation);
            this.plugin.canvas3d?.tick(t as now.Timestamp, options);
        }
    
        private frame = () => {
            this.tick(now());
            if (this._isAnimating) {
                this.currentFrame = requestAnimationFrame(this.frame);
            }
        };
    
        resetTime(t: number = now()) {
            this.plugin.canvas3d?.resetTime(t);
        }
    
        start(options?: { immediate?: boolean }) {
            this.plugin.canvas3d?.resume();
            this._isAnimating = true;
            this.resetTime();
            // TODO: should immediate be the default mode?
            if (options?.immediate) this.frame();
            else this.currentFrame = requestAnimationFrame(this.frame);
        }
    
        stop(options?: { noDraw?: boolean }) {
            this._isAnimating = false;
            if (this.currentFrame !== void 0) {
                cancelAnimationFrame(this.currentFrame);
                this.currentFrame = void 0;
            }
            if (options?.noDraw) {
                this.plugin.canvas3d?.pause(options?.noDraw);
            }
        }
    
        constructor(private plugin: PluginContext) {
    
        }
    }