element-sphere.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536
  1. /**
  2. * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * @author Alexander Rose <alexander.rose@weirdbyte.de>
  5. * @author David Sehnal <david.sehnal@gmail.com>
  6. */
  7. import { UnitsVisual } from '../index';
  8. import { VisualUpdateState } from '../../util';
  9. import { createElementSphereMesh, markElement, getElementLoci, StructureElementIterator } from './util/element';
  10. import { UnitsMeshVisual, UnitsMeshParams } from '../units-visual';
  11. import { ParamDefinition as PD } from 'mol-util/param-definition';
  12. import { SizeThemeName, SizeThemeOptions } from 'mol-theme/size';
  13. export const ElementSphereParams = {
  14. ...UnitsMeshParams,
  15. sizeTheme: PD.Select<SizeThemeName>('Size Theme', '', 'physical', SizeThemeOptions),
  16. sizeValue: PD.Numeric('Size Value', '', 0.2, 0, 10, 0.1),
  17. sizeFactor: PD.Numeric('Size Factor', '', 1, 0, 10, 0.1),
  18. detail: PD.Numeric('Sphere Detail', '', 0, 0, 3, 1),
  19. }
  20. export const DefaultElementSphereProps = PD.getDefaultValues(ElementSphereParams)
  21. export type ElementSphereProps = typeof DefaultElementSphereProps
  22. export function ElementSphereVisual(): UnitsVisual<ElementSphereProps> {
  23. return UnitsMeshVisual<ElementSphereProps>({
  24. defaultProps: DefaultElementSphereProps,
  25. createGeometry: createElementSphereMesh,
  26. createLocationIterator: StructureElementIterator.fromGroup,
  27. getLoci: getElementLoci,
  28. mark: markElement,
  29. setUpdateState: (state: VisualUpdateState, newProps: ElementSphereProps, currentProps: ElementSphereProps) => {
  30. state.createGeometry = newProps.detail !== currentProps.detail
  31. }
  32. })
  33. }