diff --git a/src/mol-plugin/state.ts b/src/mol-plugin/state.ts index 07127dbf56ca0ea5e03f1781016e64157b99cf3a..0e2a82007cb13fd299de8f7e56cf8fdd302ee28d 100644 --- a/src/mol-plugin/state.ts +++ b/src/mol-plugin/state.ts @@ -44,12 +44,12 @@ class PluginState { getSnapshot(params?: PluginState.GetSnapshotParams): PluginState.Snapshot { const p = { ...PluginState.DefaultGetSnapshotParams, ...params }; - console.log(p.animation, this.animation.getSnapshot()); return { id: UUID.create22(), data: p.data ? this.dataState.getSnapshot() : void 0, behaviour: p.behavior ? this.behaviorState.getSnapshot() : void 0, animation: p.animation ? this.animation.getSnapshot() : void 0, + startAnimation: p.startAnimation ? !!p.startAnimation : void 0, camera: p.camera ? { current: this.plugin.canvas3d.camera.getSnapshot(), transitionStyle: p.cameraTranstion.name, @@ -76,13 +76,16 @@ class PluginState { this.animation.setSnapshot(snapshot.animation); } if (snapshot.camera) { - await PluginCommands.Camera.SetSnapshot.dispatch(this.plugin, { + PluginCommands.Camera.SetSnapshot.dispatch(this.plugin, { snapshot: snapshot.camera.current, durationMs: snapshot.camera.transitionStyle === 'animate' ? snapshot.camera.transitionDurationInMs : void 0 }); } + if (snapshot.startAnimation) { + this.animation.start(); + } } dispose() { @@ -120,6 +123,7 @@ namespace PluginState { data: PD.Boolean(true), behavior: PD.Boolean(false), animation: PD.Boolean(true), + startAnimation: PD.Boolean(false), canvas3d: PD.Boolean(true), camera: PD.Boolean(true), // TODO: make camera snapshots same as the StateSnapshots with "child states?" @@ -139,6 +143,7 @@ namespace PluginState { data?: State.Snapshot, behaviour?: State.Snapshot, animation?: PluginAnimationManager.Snapshot, + startAnimation?: boolean, camera?: { current: Camera.Snapshot, transitionStyle: CameraTransitionStyle, diff --git a/src/mol-plugin/state/animation/built-in.ts b/src/mol-plugin/state/animation/built-in.ts index 0e75c918b2ade162140cc336413c63de733fe20f..0c58a509ede0eee55be6d84fcd966070b612350c 100644 --- a/src/mol-plugin/state/animation/built-in.ts +++ b/src/mol-plugin/state/animation/built-in.ts @@ -7,9 +7,10 @@ import { PluginStateAnimation } from './model'; import { PluginStateObject } from '../objects'; import { StateTransforms } from '../transforms'; -import { StateSelection } from 'mol-state'; +import { StateSelection, StateTransform } from 'mol-state'; import { PluginCommands } from 'mol-plugin/command'; import { ParamDefinition as PD } from 'mol-util/param-definition'; +import { PluginContext } from 'mol-plugin/context'; export const AnimateModelIndex = PluginStateAnimation.create({ name: 'built-in.animate-model-index', @@ -89,14 +90,25 @@ export const AnimateModelIndex = PluginStateAnimation.create({ export const AnimateAssemblyUnwind = PluginStateAnimation.create({ name: 'built-in.animate-assembly-unwind', display: { name: 'Unwind Assembly' }, - params: () => ({ - durationInMs: PD.Numeric(3000, { min: 100, max: 10000, step: 100}), - playOnce: PD.Boolean(false) - }), + params: (plugin: PluginContext) => { + const targets: [string, string][] = [['all', 'All']]; + 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 }), - async setup(_, plugin) { + async setup(params, plugin) { 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(); let changed = false; @@ -125,7 +137,8 @@ export const AnimateAssemblyUnwind = PluginStateAnimation.create({ }, async apply(animState, t, ctx) { 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) { return { kind: 'finished' }; diff --git a/src/mol-plugin/state/animation/model.ts b/src/mol-plugin/state/animation/model.ts index 21aa69100290a36ef7a8c745177fccf8689e4954..5759feca7b0ced9e1975f6e9d4dc1c1620475f9d 100644 --- a/src/mol-plugin/state/animation/model.ts +++ b/src/mol-plugin/state/animation/model.ts @@ -15,7 +15,7 @@ export { PluginStateAnimation } interface PluginStateAnimation<P = any, S = any> { name: 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, // TODO: support state in setup/teardown?