Skip to content
Snippets Groups Projects
Commit 8b274c10 authored by David Sehnal's avatar David Sehnal
Browse files

mol-plugin: targetted unwind, ability to auto start animation

parent ca4a6337
No related branches found
No related tags found
No related merge requests found
...@@ -44,12 +44,12 @@ class PluginState { ...@@ -44,12 +44,12 @@ class PluginState {
getSnapshot(params?: PluginState.GetSnapshotParams): PluginState.Snapshot { getSnapshot(params?: PluginState.GetSnapshotParams): PluginState.Snapshot {
const p = { ...PluginState.DefaultGetSnapshotParams, ...params }; const p = { ...PluginState.DefaultGetSnapshotParams, ...params };
console.log(p.animation, this.animation.getSnapshot());
return { return {
id: UUID.create22(), id: UUID.create22(),
data: p.data ? this.dataState.getSnapshot() : void 0, data: p.data ? this.dataState.getSnapshot() : void 0,
behaviour: p.behavior ? this.behaviorState.getSnapshot() : void 0, behaviour: p.behavior ? this.behaviorState.getSnapshot() : void 0,
animation: p.animation ? this.animation.getSnapshot() : void 0, animation: p.animation ? this.animation.getSnapshot() : void 0,
startAnimation: p.startAnimation ? !!p.startAnimation : void 0,
camera: p.camera ? { camera: p.camera ? {
current: this.plugin.canvas3d.camera.getSnapshot(), current: this.plugin.canvas3d.camera.getSnapshot(),
transitionStyle: p.cameraTranstion.name, transitionStyle: p.cameraTranstion.name,
...@@ -76,13 +76,16 @@ class PluginState { ...@@ -76,13 +76,16 @@ class PluginState {
this.animation.setSnapshot(snapshot.animation); this.animation.setSnapshot(snapshot.animation);
} }
if (snapshot.camera) { if (snapshot.camera) {
await PluginCommands.Camera.SetSnapshot.dispatch(this.plugin, { PluginCommands.Camera.SetSnapshot.dispatch(this.plugin, {
snapshot: snapshot.camera.current, snapshot: snapshot.camera.current,
durationMs: snapshot.camera.transitionStyle === 'animate' durationMs: snapshot.camera.transitionStyle === 'animate'
? snapshot.camera.transitionDurationInMs ? snapshot.camera.transitionDurationInMs
: void 0 : void 0
}); });
} }
if (snapshot.startAnimation) {
this.animation.start();
}
} }
dispose() { dispose() {
...@@ -120,6 +123,7 @@ namespace PluginState { ...@@ -120,6 +123,7 @@ namespace PluginState {
data: PD.Boolean(true), data: PD.Boolean(true),
behavior: PD.Boolean(false), behavior: PD.Boolean(false),
animation: PD.Boolean(true), animation: PD.Boolean(true),
startAnimation: PD.Boolean(false),
canvas3d: PD.Boolean(true), canvas3d: PD.Boolean(true),
camera: PD.Boolean(true), camera: PD.Boolean(true),
// TODO: make camera snapshots same as the StateSnapshots with "child states?" // TODO: make camera snapshots same as the StateSnapshots with "child states?"
...@@ -139,6 +143,7 @@ namespace PluginState { ...@@ -139,6 +143,7 @@ namespace PluginState {
data?: State.Snapshot, data?: State.Snapshot,
behaviour?: State.Snapshot, behaviour?: State.Snapshot,
animation?: PluginAnimationManager.Snapshot, animation?: PluginAnimationManager.Snapshot,
startAnimation?: boolean,
camera?: { camera?: {
current: Camera.Snapshot, current: Camera.Snapshot,
transitionStyle: CameraTransitionStyle, transitionStyle: CameraTransitionStyle,
......
...@@ -7,9 +7,10 @@ ...@@ -7,9 +7,10 @@
import { PluginStateAnimation } from './model'; import { PluginStateAnimation } from './model';
import { PluginStateObject } from '../objects'; import { PluginStateObject } from '../objects';
import { StateTransforms } from '../transforms'; import { StateTransforms } from '../transforms';
import { StateSelection } from 'mol-state'; import { StateSelection, StateTransform } from 'mol-state';
import { PluginCommands } from 'mol-plugin/command'; import { PluginCommands } from 'mol-plugin/command';
import { ParamDefinition as PD } from 'mol-util/param-definition'; import { ParamDefinition as PD } from 'mol-util/param-definition';
import { PluginContext } from 'mol-plugin/context';
export const AnimateModelIndex = PluginStateAnimation.create({ export const AnimateModelIndex = PluginStateAnimation.create({
name: 'built-in.animate-model-index', name: 'built-in.animate-model-index',
...@@ -89,14 +90,25 @@ export const AnimateModelIndex = PluginStateAnimation.create({ ...@@ -89,14 +90,25 @@ export const AnimateModelIndex = PluginStateAnimation.create({
export const AnimateAssemblyUnwind = PluginStateAnimation.create({ export const AnimateAssemblyUnwind = PluginStateAnimation.create({
name: 'built-in.animate-assembly-unwind', name: 'built-in.animate-assembly-unwind',
display: { name: 'Unwind Assembly' }, display: { name: 'Unwind Assembly' },
params: () => ({ params: (plugin: PluginContext) => {
durationInMs: PD.Numeric(3000, { min: 100, max: 10000, step: 100}), const targets: [string, string][] = [['all', 'All']];
playOnce: PD.Boolean(false) const structures = plugin.state.dataState.select(StateSelection.Generators.rootsOfType(PluginStateObject.Molecule.Structure));
}),
for (const s of structures) {
targets.push([s.transform.ref, s.obj!.data.models[0].label]);
}
return {
durationInMs: PD.Numeric(3000, { min: 100, max: 10000, step: 100}),
playOnce: PD.Boolean(false),
target: PD.Select(targets[0][0], targets)
};
},
initialState: () => ({ t: 0 }), initialState: () => ({ t: 0 }),
async setup(_, plugin) { async setup(params, plugin) {
const state = plugin.state.dataState; const state = plugin.state.dataState;
const reprs = state.select(StateSelection.Generators.ofType(PluginStateObject.Molecule.Structure.Representation3D)); const root = !params.target || params.target === 'all' ? StateTransform.RootRef : params.target;
const reprs = state.select(StateSelection.Generators.ofType(PluginStateObject.Molecule.Structure.Representation3D, root));
const update = state.build(); const update = state.build();
let changed = false; let changed = false;
...@@ -125,7 +137,8 @@ export const AnimateAssemblyUnwind = PluginStateAnimation.create({ ...@@ -125,7 +137,8 @@ export const AnimateAssemblyUnwind = PluginStateAnimation.create({
}, },
async apply(animState, t, ctx) { async apply(animState, t, ctx) {
const state = ctx.plugin.state.dataState; const state = ctx.plugin.state.dataState;
const anims = state.select(StateSelection.Generators.ofTransformer(StateTransforms.Representation.UnwindStructureAssemblyRepresentation3D)); const root = !ctx.params.target || ctx.params.target === 'all' ? StateTransform.RootRef : ctx.params.target;
const anims = state.select(StateSelection.Generators.ofTransformer(StateTransforms.Representation.UnwindStructureAssemblyRepresentation3D, root));
if (anims.length === 0) { if (anims.length === 0) {
return { kind: 'finished' }; return { kind: 'finished' };
......
...@@ -15,7 +15,7 @@ export { PluginStateAnimation } ...@@ -15,7 +15,7 @@ export { PluginStateAnimation }
interface PluginStateAnimation<P = any, S = any> { interface PluginStateAnimation<P = any, S = any> {
name: string, name: string,
readonly display: { readonly name: string, readonly description?: string }, readonly display: { readonly name: string, readonly description?: string },
params: (ctx: PluginContext) => PD.For<P>, params(ctx: PluginContext): PD.For<P>,
initialState(params: P, ctx: PluginContext): S, initialState(params: P, ctx: PluginContext): S,
// TODO: support state in setup/teardown? // TODO: support state in setup/teardown?
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment