quick-styles.tsx 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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, includeTransparent: true }
  52. },
  53. occlusion: {
  54. name: 'on',
  55. params: { bias: 0.8, blurKernelSize: 15, radius: 5, samples: 32, resolutionScale: 1 }
  56. },
  57. shadow: { name: 'off', params: {} },
  58. }
  59. });
  60. }
  61. }
  62. async stylized() {
  63. this.plugin.managers.structure.component.setOptions({ ...this.plugin.managers.structure.component.state.options, ignoreLight: true });
  64. if (this.plugin.canvas3d) {
  65. const pp = this.plugin.canvas3d.props.postprocessing;
  66. this.plugin.canvas3d.setProps({
  67. postprocessing: {
  68. outline: {
  69. name: 'on',
  70. params: pp.outline.name === 'on'
  71. ? pp.outline.params
  72. : { scale: 1, color: Color(0x000000), threshold: 0.33, includeTransparent: true }
  73. },
  74. occlusion: {
  75. name: 'on',
  76. params: pp.occlusion.name === 'on'
  77. ? pp.occlusion.params
  78. : { bias: 0.8, blurKernelSize: 15, radius: 5, samples: 32, resolutionScale: 1 }
  79. },
  80. shadow: { name: 'off', params: {} },
  81. }
  82. });
  83. }
  84. }
  85. render() {
  86. return <div className='msp-flex-row'>
  87. <Button noOverflow title='Applies default representation preset. Set outline and occlusion effects to defaults.' onClick={() => this.default()} style={{ width: 'auto' }}>
  88. Default
  89. </Button>
  90. <Button noOverflow title='Applies no representation preset. Enables outline and occlusion effects. Enables ignore-light representation parameter.' onClick={() => this.stylized()} style={{ width: 'auto' }}>
  91. Stylized
  92. </Button>
  93. <Button noOverflow title='Applies illustrative representation preset. Enables outline and occlusion effects. Enables ignore-light parameter.' onClick={() => this.illustrative()} style={{ width: 'auto' }}>
  94. Illustrative
  95. </Button>
  96. </div>;
  97. }
  98. }