geometry.ts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. */
  6. import { Mesh } from './mesh/mesh';
  7. import { Point } from './point/point';
  8. import { RenderableState } from 'mol-gl/renderable';
  9. import { ValueCell } from 'mol-util';
  10. import { BaseValues } from 'mol-gl/renderable/schema';
  11. import { Color } from 'mol-util/color';
  12. import { ColorThemeProps } from 'mol-view/theme/color';
  13. import { LocationIterator } from '../util/location-iterator';
  14. import { ColorType } from './color-data';
  15. import { SizeType } from './size-data';
  16. export type GeometryKindType = { 'mesh': Mesh, 'point': Point }
  17. export type GeometryKind = keyof GeometryKindType
  18. export type Geometry = Helpers.ValueOf<GeometryKindType>
  19. export namespace Geometry {
  20. export function getDrawCount(geometry: Geometry) {
  21. switch (geometry.kind) {
  22. case 'mesh': return geometry.triangleCount * 3
  23. case 'point': return geometry.vertexCount
  24. }
  25. }
  26. //
  27. export const DefaultProps = {
  28. alpha: 1,
  29. visible: true,
  30. depthMask: true,
  31. useFog: false,
  32. quality: 'auto' as VisualQuality,
  33. colorTheme: { name: 'uniform', value: Color(0x22EE11) } as ColorThemeProps,
  34. }
  35. export type Props = typeof DefaultProps
  36. export type Counts = { drawCount: number, groupCount: number, instanceCount: number }
  37. export function createValues(props: Props, counts: Counts) {
  38. return {
  39. uAlpha: ValueCell.create(props.alpha),
  40. uGroupCount: ValueCell.create(counts.groupCount),
  41. drawCount: ValueCell.create(counts.drawCount),
  42. dUseFog: ValueCell.create(props.useFog),
  43. }
  44. }
  45. export function updateValues(values: BaseValues, props: Props) {
  46. ValueCell.updateIfChanged(values.uAlpha, props.alpha)
  47. ValueCell.updateIfChanged(values.dUseFog, props.useFog)
  48. }
  49. }
  50. //
  51. export function createRenderableState(props: Geometry.Props): RenderableState {
  52. return {
  53. visible: props.visible,
  54. depthMask: props.depthMask
  55. }
  56. }
  57. export function updateRenderableState(state: RenderableState, props: Geometry.Props) {
  58. state.visible = props.visible
  59. state.depthMask = props.depthMask
  60. }
  61. //
  62. export function getGranularity(locationIt: LocationIterator, granularity: ColorType | SizeType) {
  63. // Always use 'group' granularity for 'complex' location iterators,
  64. // i.e. for which an instance may include multiple units
  65. return granularity === 'instance' && locationIt.isComplex ? 'group' : granularity
  66. }
  67. //
  68. export const VisualQualityInfo = {
  69. 'custom': {},
  70. 'auto': {},
  71. 'highest': {},
  72. 'high': {},
  73. 'medium': {},
  74. 'low': {},
  75. 'lowest': {},
  76. }
  77. export type VisualQuality = keyof typeof VisualQualityInfo
  78. export const VisualQualityNames = Object.keys(VisualQualityInfo)