From 1aaa6fcbd2de016cfa41f0b4a0978aa0c45e5116 Mon Sep 17 00:00:00 2001 From: Alexander Rose <alexander.rose@weirdbyte.de> Date: Sun, 2 Dec 2018 20:01:35 +0900 Subject: [PATCH] registered point repr --- src/mol-gl/shader/chunks/apply-fog.glsl | 6 +- src/mol-repr/structure/registry.ts | 2 + .../structure/representation/point.ts | 63 +++++++++++-------- .../structure/visual/element-point.ts | 3 + 4 files changed, 46 insertions(+), 28 deletions(-) diff --git a/src/mol-gl/shader/chunks/apply-fog.glsl b/src/mol-gl/shader/chunks/apply-fog.glsl index a0f273ebc..f7fcadde6 100644 --- a/src/mol-gl/shader/chunks/apply-fog.glsl +++ b/src/mol-gl/shader/chunks/apply-fog.glsl @@ -3,8 +3,8 @@ // float depth = gl_FragCoord.z / gl_FragCoord.w; float fogFactor = smoothstep(uFogNear, uFogFar, depth); gl_FragColor.rgb = mix(gl_FragColor.rgb, uFogColor, fogFactor); - float alpha = (1.0 - fogFactor) * gl_FragColor.a; - if (alpha < 0.01) + float fogAlpha = (1.0 - fogFactor) * gl_FragColor.a; + if (fogAlpha < 0.01) discard; - gl_FragColor = vec4( gl_FragColor.rgb, alpha ); + gl_FragColor = vec4( gl_FragColor.rgb, fogAlpha ); #endif \ No newline at end of file diff --git a/src/mol-repr/structure/registry.ts b/src/mol-repr/structure/registry.ts index ebaa92df4..12802514c 100644 --- a/src/mol-repr/structure/registry.ts +++ b/src/mol-repr/structure/registry.ts @@ -13,6 +13,7 @@ import { MolecularVolumeRepresentationProvider } from './representation/molecula import { CarbohydrateRepresentationProvider } from './representation/carbohydrate'; import { SpacefillRepresentationProvider } from './representation/spacefill'; import { DistanceRestraintRepresentationProvider } from './representation/distance-restraint'; +import { PointRepresentationProvider } from './representation/point'; export class StructureRepresentationRegistry extends RepresentationRegistry<Structure> { constructor() { @@ -31,6 +32,7 @@ export const BuiltInStructureRepresentations = { 'distance-restraint': DistanceRestraintRepresentationProvider, 'molecular-surface': MolecularSurfaceRepresentationProvider, 'molecular-volume': MolecularVolumeRepresentationProvider, + 'point': PointRepresentationProvider, 'spacefill': SpacefillRepresentationProvider, } export type BuiltInStructureRepresentationsName = keyof typeof BuiltInStructureRepresentations diff --git a/src/mol-repr/structure/representation/point.ts b/src/mol-repr/structure/representation/point.ts index efc91f8df..9a1789271 100644 --- a/src/mol-repr/structure/representation/point.ts +++ b/src/mol-repr/structure/representation/point.ts @@ -1,29 +1,42 @@ -// /** -// * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info. -// * -// * @author Alexander Rose <alexander.rose@weirdbyte.de> -// */ +/** + * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info. + * + * @author Alexander Rose <alexander.rose@weirdbyte.de> + */ -// import { ElementPointVisual, ElementPointParams } from '../visual/element-point'; -// import { UnitsRepresentation } from '../units-representation'; -// import { ParamDefinition as PD } from 'mol-util/param-definition'; -// import { StructureRepresentation } from '../representation'; -// import { Representation } from 'mol-repr/representation'; -// import { ThemeRegistryContext } from 'mol-theme/theme'; -// import { Structure } from 'mol-model/structure'; +import { ElementPointVisual, ElementPointParams } from '../visual/element-point'; +import { UnitsRepresentation } from '../units-representation'; +import { ParamDefinition as PD } from 'mol-util/param-definition'; +import { StructureRepresentation, StructureRepresentationProvider } from '../representation'; +import { Representation, RepresentationParamsGetter, RepresentationContext } from 'mol-repr/representation'; +import { ThemeRegistryContext } from 'mol-theme/theme'; +import { Structure } from 'mol-model/structure'; +import { UnitKind, UnitKindOptions } from '../visual/util/common'; -// export const PointParams = { -// ...ElementPointParams, -// } -// export function getPointParams(ctx: ThemeRegistryContext, structure: Structure) { -// return PointParams // TODO return copy -// } -// export type PointProps = PD.DefaultValues<typeof PointParams> +const PointVisuals = { + 'element-point': (ctx: RepresentationContext, getParams: RepresentationParamsGetter<Structure, ElementPointParams>) => UnitsRepresentation('Points', ctx, getParams, ElementPointVisual), +} -// export type PointRepresentation = StructureRepresentation<PointProps> +export const PointParams = { + ...ElementPointParams, + unitKinds: PD.MultiSelect<UnitKind>(['atomic', 'spheres'], UnitKindOptions), +} +export type PointParams = typeof PointParams +export function getPointParams(ctx: ThemeRegistryContext, structure: Structure) { + return PD.clone(PointParams) +} -// export function PointRepresentation(defaultProps: PointProps): PointRepresentation { -// return Representation.createMulti('Point', defaultProps, [ -// UnitsRepresentation('Point', defaultProps, ElementPointVisual) -// ]) -// } \ No newline at end of file +export type PointRepresentation = StructureRepresentation<PointParams> +export function PointRepresentation(ctx: RepresentationContext, getParams: RepresentationParamsGetter<Structure, PointParams>): PointRepresentation { + return Representation.createMulti('Point', ctx, getParams, PointVisuals as unknown as Representation.Def<Structure, PointParams>) +} + +export const PointRepresentationProvider: StructureRepresentationProvider<PointParams> = { + label: 'Point', + description: 'Displays elements (atoms, coarse spheres) as spheres.', + factory: PointRepresentation, + getParams: getPointParams, + defaultValues: PD.getDefaultValues(PointParams), + defaultColorTheme: 'element-symbol', + defaultSizeTheme: 'physical' +} \ No newline at end of file diff --git a/src/mol-repr/structure/visual/element-point.ts b/src/mol-repr/structure/visual/element-point.ts index 71f5d4b1f..ae3a8abd1 100644 --- a/src/mol-repr/structure/visual/element-point.ts +++ b/src/mol-repr/structure/visual/element-point.ts @@ -18,6 +18,7 @@ import { Theme } from 'mol-theme/theme'; export const ElementPointParams = { ...UnitsPointsParams, + // sizeFactor: PD.Numeric(1.0, { min: 0, max: 10, step: 0.01 }), pointSizeAttenuation: PD.Boolean(false), } export type ElementPointParams = typeof ElementPointParams @@ -25,6 +26,8 @@ export type ElementPointParams = typeof ElementPointParams // TODO size export function createElementPoint(ctx: VisualContext, unit: Unit, structure: Structure, theme: Theme, props: PD.Values<ElementPointParams>, points: Points) { + // const { sizeFactor } = props + const elements = unit.elements const n = elements.length const builder = PointsBuilder.create(n, n / 10, points) -- GitLab