element-sphere.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435
  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 '../representation';
  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. export const ElementSphereParams = {
  13. ...UnitsMeshParams,
  14. sizeFactor: PD.Numeric(1, { min: 0, max: 10, step: 0.1 }),
  15. detail: PD.Numeric(0, { min: 0, max: 3, step: 1 }),
  16. }
  17. export type ElementSphereParams = typeof ElementSphereParams
  18. export function ElementSphereVisual(): UnitsVisual<ElementSphereParams> {
  19. return UnitsMeshVisual<ElementSphereParams>({
  20. defaultProps: PD.getDefaultValues(ElementSphereParams),
  21. createGeometry: createElementSphereMesh,
  22. createLocationIterator: StructureElementIterator.fromGroup,
  23. getLoci: getElementLoci,
  24. mark: markElement,
  25. setUpdateState: (state: VisualUpdateState, newProps: PD.Values<ElementSphereParams>, currentProps: PD.Values<ElementSphereParams>) => {
  26. state.createGeometry = (
  27. newProps.sizeFactor !== currentProps.sizeFactor ||
  28. newProps.detail !== currentProps.detail
  29. )
  30. }
  31. })
  32. }