molstar
Version:
A comprehensive macromolecular library.
60 lines • 3.56 kB
JavaScript
"use strict";
/**
* Copyright (c) 2020 mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author David Sehnal <david.sehnal@gmail.com>
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.AnimateCameraSpin = void 0;
var tslib_1 = require("tslib");
var interpolate_1 = require("../../../mol-math/interpolate");
var quat_1 = require("../../../mol-math/linear-algebra/3d/quat");
var vec3_1 = require("../../../mol-math/linear-algebra/3d/vec3");
var param_definition_1 = require("../../../mol-util/param-definition");
var model_1 = require("../model");
var _dir = (0, vec3_1.Vec3)(), _axis = (0, vec3_1.Vec3)(), _rot = (0, quat_1.Quat)();
exports.AnimateCameraSpin = model_1.PluginStateAnimation.create({
name: 'built-in.animate-camera-spin',
display: { name: 'Camera Spin' },
isExportable: true,
params: function () { return ({
durationInMs: param_definition_1.ParamDefinition.Numeric(4000, { min: 100, max: 20000, step: 100 }),
speed: param_definition_1.ParamDefinition.Numeric(1, { min: 1, max: 10, step: 1 }, { description: 'How many times to spin in the specified dutation.' }),
direction: param_definition_1.ParamDefinition.Select('cw', [['cw', 'Clockwise'], ['ccw', 'Counter Clockwise']], { cycle: true })
}); },
initialState: function (_, ctx) { var _a; return ({ snapshot: (_a = ctx.canvas3d) === null || _a === void 0 ? void 0 : _a.camera.getSnapshot() }); },
getDuration: function (p) { return ({ kind: 'fixed', durationMs: p.durationInMs }); },
teardown: function (_, state, ctx) {
var _a;
(_a = ctx.canvas3d) === null || _a === void 0 ? void 0 : _a.requestCameraReset({ snapshot: state.snapshot, durationMs: 0 });
},
apply: function (animState, t, ctx) {
var _a, _b;
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
var snapshot, phase, angle, position;
return (0, tslib_1.__generator)(this, function (_c) {
if (t.current === 0) {
return [2 /*return*/, { kind: 'next', state: animState }];
}
snapshot = animState.snapshot;
if (snapshot.radiusMax < 0.0001) {
return [2 /*return*/, { kind: 'finished' }];
}
phase = (0, interpolate_1.clamp)(t.current / ctx.params.durationInMs, 0, 1);
if (phase >= 0.99999) {
(_a = ctx.plugin.canvas3d) === null || _a === void 0 ? void 0 : _a.requestCameraReset({ snapshot: snapshot, durationMs: 0 });
return [2 /*return*/, { kind: 'finished' }];
}
angle = 2 * Math.PI * phase * ctx.params.speed * (ctx.params.direction === 'ccw' ? -1 : 1);
vec3_1.Vec3.sub(_dir, snapshot.position, snapshot.target);
vec3_1.Vec3.normalize(_axis, snapshot.up);
quat_1.Quat.setAxisAngle(_rot, _axis, angle);
vec3_1.Vec3.transformQuat(_dir, _dir, _rot);
position = vec3_1.Vec3.add((0, vec3_1.Vec3)(), snapshot.target, _dir);
(_b = ctx.plugin.canvas3d) === null || _b === void 0 ? void 0 : _b.requestCameraReset({ snapshot: (0, tslib_1.__assign)((0, tslib_1.__assign)({}, snapshot), { position: position }), durationMs: 0 });
return [2 /*return*/, { kind: 'next', state: animState }];
});
});
}
});
//# sourceMappingURL=camera-spin.js.map