diff --git a/src/apps/viewer/index.ts b/src/apps/viewer/index.ts index f64698cf11d0e1f44a0ecb55780df8f7e81bf891..a476588db89e170020d270d79c1649c97c65a2e4 100644 --- a/src/apps/viewer/index.ts +++ b/src/apps/viewer/index.ts @@ -92,7 +92,7 @@ export class Viewer { }, components: { ...DefaultPluginSpec.components, - remoteState: o.layoutShowRemoteState ? 'default' : 'none', + remoteState: o.layoutShowRemoteState ? 'default' : 'none' }, config: [ [PluginConfig.Viewport.ShowExpand, o.viewportShowExpand], diff --git a/src/mol-canvas3d/canvas3d.ts b/src/mol-canvas3d/canvas3d.ts index 8cb502e3616404709ba9b16fc93a1805026de819..3c4b587af398b0c6a1136b53e40f635b7ee01958 100644 --- a/src/mol-canvas3d/canvas3d.ts +++ b/src/mol-canvas3d/canvas3d.ts @@ -66,6 +66,7 @@ export const Canvas3DParams = { }; export const DefaultCanvas3DParams = PD.getDefaultValues(Canvas3DParams); export type Canvas3DProps = PD.Values<typeof Canvas3DParams> +export type PartialCanvas3DProps = { [K in keyof Canvas3DProps]?: Partial<Canvas3DProps[K]> } export { Canvas3D }; @@ -97,7 +98,7 @@ interface Canvas3D { readonly camera: Camera readonly boundingSphere: Readonly<Sphere3D> getPixelData(variant: GraphicsRenderVariant): PixelData - setProps(props: Partial<Canvas3DProps> | ((old: Canvas3DProps) => Partial<Canvas3DProps> | void)): void + setProps(props: PartialCanvas3DProps | ((old: Canvas3DProps) => Partial<Canvas3DProps> | void)): void getImagePass(props: Partial<ImageProps>): ImagePass /** Returns a copy of the current Canvas3D instance props */ @@ -530,7 +531,7 @@ namespace Canvas3D { didDraw, reprCount, setProps: (properties) => { - const props: Partial<Canvas3DProps> = typeof properties === 'function' + const props: PartialCanvas3DProps = typeof properties === 'function' ? produce(getProps(), properties) : properties; @@ -538,7 +539,7 @@ namespace Canvas3D { if (props.camera && props.camera.mode !== undefined && props.camera.mode !== camera.state.mode) { cameraState.mode = props.camera.mode; } - if (props.cameraFog !== undefined) { + if (props.cameraFog !== undefined && props.cameraFog.params) { const newFog = props.cameraFog.name === 'on' ? props.cameraFog.params.intensity : 0; if (newFog !== camera.state.fog) cameraState.fog = newFog; } diff --git a/src/mol-plugin-state/manager/loci-label.ts b/src/mol-plugin-state/manager/loci-label.ts index 5193912b4bf3ce11ed652f0da69791b1298ba1e3..a5ee1eba6cd8184ea6b7495bd58e06e036e6c938 100644 --- a/src/mol-plugin-state/manager/loci-label.ts +++ b/src/mol-plugin-state/manager/loci-label.ts @@ -22,6 +22,12 @@ export type LociLabelProvider = { export class LociLabelManager { providers: LociLabelProvider[] = []; + clearProviders() { + this.providers = []; + this.isDirty = true; + this.showLabels(); + } + addProvider(provider: LociLabelProvider) { this.providers.push(provider); this.providers.sort((a, b) => (b.priority || 0) - (a.priority || 0)); diff --git a/src/mol-plugin/context.ts b/src/mol-plugin/context.ts index 9450a2469678aa9339982aa020a7cfb33a6a84e5..eb7fc71008d9c2f481997477a52e9ed2ce0e0d0e 100644 --- a/src/mol-plugin/context.ts +++ b/src/mol-plugin/context.ts @@ -182,8 +182,7 @@ export class PluginContext { (this.canvas3d as Canvas3D) = Canvas3D.fromCanvas(canvas); this.canvas3dInit.next(true); - const renderer = this.canvas3d!.props.renderer; - PluginCommands.Canvas3D.SetSettings(this, { settings: { renderer: { ...renderer, backgroundColor: Color(0xFCFBF9) } } }); + this.canvas3d?.setProps(this.spec.components?.viewport?.canvas3d || { renderer: { backgroundColor: Color(0xFCFBF9) } }); this.canvas3d!.animate(); (this.helpers.viewportScreenshot as ViewportScreenshotHelper) = new ViewportScreenshotHelper(this); return true; @@ -346,29 +345,31 @@ export class PluginContext { } } - constructor(public spec: PluginSpec) { - // the reason for this is that sometimes, transform params get modified inline (i.e. palette.valueLabel) - // and freezing the params object causes "read-only exception" - // TODO: is this the best place to do it? - setAutoFreeze(false); - + async init() { this.events.log.subscribe(e => this.log.entries = this.log.entries.push(e)); this.initBehaviorEvents(); this.initBuiltInBehavior(); - this.initBehaviors(); + (this.managers.interactivity as InteractivityManager) = new InteractivityManager(this); + (this.managers.lociLabels as LociLabelManager) = new LociLabelManager(this); + (this.builders.structure as StructureBuilder) = new StructureBuilder(this); + this.initDataActions(); this.initAnimations(); this.initCustomParamEditors(); - (this.managers.interactivity as InteractivityManager) = new InteractivityManager(this); - (this.managers.lociLabels as LociLabelManager) = new LociLabelManager(this); - - (this.builders.structure as StructureBuilder) = new StructureBuilder(this); + await this.initBehaviors(); this.log.message(`Mol* Plugin ${PLUGIN_VERSION} [${PLUGIN_VERSION_DATE.toLocaleString()}]`); if (!isProductionMode) this.log.message(`Development mode enabled`); if (isDebugMode) this.log.message(`Debug mode enabled`); } + + constructor(public spec: PluginSpec) { + // the reason for this is that sometimes, transform params get modified inline (i.e. palette.valueLabel) + // and freezing the params object causes "read-only exception" + // TODO: is this the best place to do it? + setAutoFreeze(false); + } } \ No newline at end of file diff --git a/src/mol-plugin/index.ts b/src/mol-plugin/index.ts index c1b568029e0dcbe7676fbffd70d54cac011a6475..288db73b74ac69038d1b8f4ebad103cb5730abd1 100644 --- a/src/mol-plugin/index.ts +++ b/src/mol-plugin/index.ts @@ -94,6 +94,16 @@ export const DefaultPluginSpec: PluginSpec = { export function createPlugin(target: HTMLElement, spec?: PluginSpec): PluginContext { const ctx = new PluginContext(spec || DefaultPluginSpec); + ctx.init(); ReactDOM.render(React.createElement(Plugin, { plugin: ctx }), target); return ctx; +} + +/** Returns the instance of the plugin after all behaviors have been initialized */ +export async function createPluginAsync(target: HTMLElement, spec?: PluginSpec) { + const ctx = new PluginContext(spec || DefaultPluginSpec); + const init = ctx.init(); + ReactDOM.render(React.createElement(Plugin, { plugin: ctx }), target); + await init; + return ctx; } \ No newline at end of file diff --git a/src/mol-plugin/spec.ts b/src/mol-plugin/spec.ts index 0b6e08d118e8255b23ea425bf2884482f18f4fd5..437dca7679402518ba175a58d33ed3e7b737c3a3 100644 --- a/src/mol-plugin/spec.ts +++ b/src/mol-plugin/spec.ts @@ -10,6 +10,7 @@ import { StateTransformParameters } from '../mol-plugin-ui/state/common'; import { PluginLayoutStateProps } from './layout'; import { PluginStateAnimation } from '../mol-plugin-state/animation/model'; import { PluginConfigItem } from './config'; +import { PartialCanvas3DProps } from '../mol-canvas3d/canvas3d'; export { PluginSpec }; @@ -27,7 +28,8 @@ interface PluginSpec { structureTools?: React.ComponentClass, viewport?: { view?: React.ComponentClass, - controls?: React.ComponentClass + controls?: React.ComponentClass, + canvas3d?: PartialCanvas3DProps } }, config?: [PluginConfigItem, unknown][]