quick-styles.tsx 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /**
  2. * Copyright (c) 2022 mol* contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * @author Alexander Rose <alexander.rose@weirdbyte.de>
  5. */
  6. import { PresetStructureRepresentations } from '../../mol-plugin-state/builder/structure/representation-preset';
  7. import { Color } from '../../mol-util/color';
  8. import { CollapsableControls, PurePluginUIComponent } from '../base';
  9. import { Button } from '../controls/common';
  10. import { MagicWandSvg } from '../controls/icons';
  11. import { ParamDefinition as PD } from '../../mol-util/param-definition';
  12. import { PostprocessingParams } from '../../mol-canvas3d/passes/postprocessing';
  13. import { PluginConfig } from '../../mol-plugin/config';
  14. import { StructureComponentManager } from '../../mol-plugin-state/manager/structure/component';
  15. export class StructureQuickStylesControls extends CollapsableControls {
  16. defaultState() {
  17. return {
  18. isCollapsed: false,
  19. header: 'Quick Styles',
  20. brand: { accent: 'gray' as const, svg: MagicWandSvg }
  21. };
  22. }
  23. renderControls() {
  24. return <>
  25. <QuickStyles />
  26. </>;
  27. }
  28. }
  29. export class QuickStyles extends PurePluginUIComponent {
  30. async default() {
  31. const { structures } = this.plugin.managers.structure.hierarchy.selection;
  32. const preset = this.plugin.config.get(PluginConfig.Structure.DefaultRepresentationPreset) || PresetStructureRepresentations.auto.id;
  33. const provider = this.plugin.builders.structure.representation.resolveProvider(preset);
  34. await this.plugin.managers.structure.component.applyPreset(structures, provider);
  35. this.plugin.managers.structure.component.setOptions(PD.getDefaultValues(StructureComponentManager.OptionsParams));
  36. if (this.plugin.canvas3d) {
  37. const p = PD.getDefaultValues(PostprocessingParams);
  38. this.plugin.canvas3d.setProps({
  39. postprocessing: { outline: p.outline, occlusion: p.occlusion }
  40. });
  41. }
  42. }
  43. async illustrative() {
  44. const { structures } = this.plugin.managers.structure.hierarchy.selection;
  45. await this.plugin.managers.structure.component.applyPreset(structures, PresetStructureRepresentations.illustrative);
  46. if (this.plugin.canvas3d) {
  47. this.plugin.canvas3d.setProps({
  48. postprocessing: {
  49. outline: {
  50. name: 'on',
  51. params: { scale: 1, color: Color(0x000000), threshold: 0.25 }
  52. },
  53. occlusion: {
  54. name: 'on',
  55. params: { bias: 0.8, blurKernelSize: 15, radius: 5, samples: 32, scaleFactor: 1 }
  56. },
  57. }
  58. });
  59. }
  60. }
  61. async stylized() {
  62. this.plugin.managers.structure.component.setOptions({ ...this.plugin.managers.structure.component.state.options, ignoreLight: true });
  63. if (this.plugin.canvas3d) {
  64. const pp = this.plugin.canvas3d.props.postprocessing;
  65. this.plugin.canvas3d.setProps({
  66. postprocessing: {
  67. outline: {
  68. name: 'on',
  69. params: pp.outline.name === 'on'
  70. ? pp.outline.params
  71. : { scale: 1, color: Color(0x000000), threshold: 0.33 }
  72. },
  73. occlusion: {
  74. name: 'on',
  75. params: pp.occlusion.name === 'on'
  76. ? pp.occlusion.params
  77. : { bias: 0.8, blurKernelSize: 15, radius: 5, samples: 32, scaleFactor: 1 }
  78. },
  79. }
  80. });
  81. }
  82. }
  83. render() {
  84. return <div className='msp-flex-row'>
  85. <Button noOverflow title='Applies default representation preset. Set outline and occlusion effects to defaults.' onClick={() => this.default()} style={{ width: 'auto' }}>
  86. Default
  87. </Button>
  88. <Button noOverflow title='Applies no representation preset. Enables outline and occlusion effects. Enables ignore-light representation parameter.' onClick={() => this.stylized()} style={{ width: 'auto' }}>
  89. Stylized
  90. </Button>
  91. <Button noOverflow title='Applies illustrative representation preset. Enables outline and occlusion effects. Enables ignore-light parameter.' onClick={() => this.illustrative()} style={{ width: 'auto' }}>
  92. Illustrative
  93. </Button>
  94. </div>;
  95. }
  96. }