Browse Source

registered point repr

Alexander Rose 6 years ago
parent
commit
1aaa6fcbd2

+ 3 - 3
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

+ 2 - 0
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

+ 38 - 25
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)
-//     ])
-// }
+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'
+}

+ 3 - 0
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)