From e0a716c88e0eb2f5e2a72133cde2c86eda81322c Mon Sep 17 00:00:00 2001 From: Alexander Rose <alex.rose@rcsb.org> Date: Thu, 13 Dec 2018 15:46:27 -0800 Subject: [PATCH] refactored mol-repr/visual --- src/mol-geo/geometry/transform-data.ts | 2 +- .../representations/assembly-symmetry-axes.ts | 3 +- src/mol-repr/representation.ts | 23 +------ src/mol-repr/shape/representation.ts | 1 + src/mol-repr/structure/complex-visual.ts | 9 ++- .../structure/units-representation.ts | 3 +- src/mol-repr/structure/units-visual.ts | 11 ++-- .../visual/carbohydrate-link-cylinder.ts | 2 +- .../visual/carbohydrate-symbol-mesh.ts | 2 +- .../carbohydrate-terminal-link-cylinder.ts | 2 +- .../visual/cross-link-restraint-cylinder.ts | 2 +- .../structure/visual/element-point.ts | 2 +- .../visual/gaussian-density-point.ts | 2 +- .../visual/gaussian-density-volume.ts | 2 +- .../structure/visual/gaussian-surface-mesh.ts | 2 +- .../visual/gaussian-surface-wireframe.ts | 2 +- .../visual/inter-unit-link-cylinder.ts | 2 +- .../visual/intra-unit-link-cylinder.ts | 2 +- .../structure/visual/nucleotide-block-mesh.ts | 2 +- .../visual/polymer-backbone-cylinder.ts | 2 +- .../visual/polymer-direction-wedge.ts | 2 +- .../structure/visual/polymer-gap-cylinder.ts | 2 +- .../structure/visual/polymer-trace-mesh.ts | 2 +- src/mol-repr/structure/visual/util/element.ts | 2 +- src/mol-repr/structure/visual/util/link.ts | 2 +- src/mol-repr/visual.ts | 61 +++++++++++++++++++ src/mol-repr/volume/direct-volume.ts | 3 +- src/mol-repr/volume/isosurface-mesh.ts | 3 +- src/mol-repr/volume/representation.ts | 10 +-- 29 files changed, 105 insertions(+), 60 deletions(-) create mode 100644 src/mol-repr/visual.ts diff --git a/src/mol-geo/geometry/transform-data.ts b/src/mol-geo/geometry/transform-data.ts index 993c279c5..486400aa2 100644 --- a/src/mol-geo/geometry/transform-data.ts +++ b/src/mol-geo/geometry/transform-data.ts @@ -43,7 +43,7 @@ export function createIdentityTransform(transformData?: TransformData): Transfor } const tmpTransformMat4 = Mat4.identity() -export function setTransform(matrix: Mat4, transformData: TransformData) { +export function setTransformData(matrix: Mat4, transformData: TransformData) { const instanceCount = transformData.instanceCount.ref.value const transform = transformData.transform.ref.value const aTransform = transformData.aTransform.ref.value diff --git a/src/mol-model-props/rcsb/representations/assembly-symmetry-axes.ts b/src/mol-model-props/rcsb/representations/assembly-symmetry-axes.ts index a57aa5775..a949d4dfc 100644 --- a/src/mol-model-props/rcsb/representations/assembly-symmetry-axes.ts +++ b/src/mol-model-props/rcsb/representations/assembly-symmetry-axes.ts @@ -5,7 +5,8 @@ */ import { ParamDefinition as PD } from 'mol-util/param-definition'; -import { RepresentationParamsGetter, RepresentationContext, VisualContext } from 'mol-repr/representation'; +import { RepresentationParamsGetter, RepresentationContext } from 'mol-repr/representation'; +import { VisualContext } from 'mol-repr/visual'; import { ThemeRegistryContext, Theme } from 'mol-theme/theme'; import { Structure } from 'mol-model/structure'; import { StructureRepresentationProvider, StructureRepresentation, ComplexRepresentation, ComplexVisual } from 'mol-repr/structure/representation'; diff --git a/src/mol-repr/representation.ts b/src/mol-repr/representation.ts index 3c7b2e95d..0caccdd9f 100644 --- a/src/mol-repr/representation.ts +++ b/src/mol-repr/representation.ts @@ -4,7 +4,7 @@ * @author Alexander Rose <alexander.rose@weirdbyte.de> */ -import { Task, RuntimeContext } from 'mol-task' +import { Task } from 'mol-task' import { RenderObject } from 'mol-gl/render-object' import { PickingId } from '../mol-geo/geometry/picking'; import { Loci, isEmptyLoci, EmptyLoci } from 'mol-model/loci'; @@ -240,25 +240,4 @@ namespace Representation { } } } -} - -// - -export interface VisualContext { - readonly runtime: RuntimeContext - readonly webgl?: WebGLContext -} -// export type VisualFactory<D, P extends PD.Params> = (ctx: VisualContext) => Visual<D, P> - -export interface Visual<D, P extends PD.Params> { - /** Number of addressable groups in all instances of the visual */ - readonly groupCount: number - readonly renderObject: RenderObject | undefined - createOrUpdate: (ctx: VisualContext, theme: Theme, props?: Partial<PD.Values<P>>, data?: D) => Promise<void> | void - getLoci: (pickingId: PickingId) => Loci - mark: (loci: Loci, action: MarkerAction) => boolean - setVisibility: (value: boolean) => void - setPickable: (value: boolean) => void - setTransform: (value: Mat4) => void - destroy: () => void } \ No newline at end of file diff --git a/src/mol-repr/shape/representation.ts b/src/mol-repr/shape/representation.ts index d8aed56d5..52569ad32 100644 --- a/src/mol-repr/shape/representation.ts +++ b/src/mol-repr/shape/representation.ts @@ -109,6 +109,7 @@ export function ShapeRepresentation<P extends ShapeParams>(ctx: RepresentationCo setState(state: Partial<Representation.State>) { if (state.visible !== undefined) renderObjects.forEach(ro => ro.state.visible = state.visible!) if (state.pickable !== undefined) renderObjects.forEach(ro => ro.state.pickable = state.pickable!) + // TODO state.transform Representation.updateState(_state, state) }, diff --git a/src/mol-repr/structure/complex-visual.ts b/src/mol-repr/structure/complex-visual.ts index f5217b91a..d5ce56381 100644 --- a/src/mol-repr/structure/complex-visual.ts +++ b/src/mol-repr/structure/complex-visual.ts @@ -5,7 +5,7 @@ */ import { Structure } from 'mol-model/structure'; -import { Visual, VisualContext } from '../representation'; +import { Visual, VisualContext } from '../visual'; import { MeshRenderObject, LinesRenderObject, PointsRenderObject, DirectVolumeRenderObject } from 'mol-gl/render-object'; import { createComplexMeshRenderObject, UnitKind, UnitKindOptions, createComplexDirectVolumeRenderObject } from './visual/util/common'; import { StructureMeshParams, StructureParams, StructureDirectVolumeParams } from './representation'; @@ -29,7 +29,6 @@ import { RenderableState } from 'mol-gl/renderable'; import { UnitsParams } from './units-representation'; import { DirectVolume } from 'mol-geo/geometry/direct-volume/direct-volume'; import { Mat4 } from 'mol-math/linear-algebra'; -import { setTransform } from 'mol-geo/geometry/transform-data'; export interface ComplexVisual<P extends StructureParams> extends Visual<Structure, P> { } @@ -195,13 +194,13 @@ export function ComplexVisual<P extends ComplexParams>(builder: ComplexVisualGeo return changed }, setVisibility(value: boolean) { - if (renderObject) renderObject.state.visible = value + Visual.setVisibility(renderObject, value) }, setPickable(value: boolean) { - if (renderObject) renderObject.state.pickable = value + Visual.setPickable(renderObject, value) }, setTransform(value: Mat4) { - if (renderObject) setTransform(value, renderObject.values) + Visual.setTransform(renderObject, value) }, destroy() { // TODO diff --git a/src/mol-repr/structure/units-representation.ts b/src/mol-repr/structure/units-representation.ts index 5a0b0484b..5f20f7662 100644 --- a/src/mol-repr/structure/units-representation.ts +++ b/src/mol-repr/structure/units-representation.ts @@ -8,7 +8,8 @@ import { Structure, Unit } from 'mol-model/structure'; import { Task } from 'mol-task' import { RenderObject } from 'mol-gl/render-object'; -import { Visual, RepresentationContext, RepresentationParamsGetter, Representation } from '../representation'; +import { RepresentationContext, RepresentationParamsGetter, Representation } from '../representation'; +import { Visual } from '../visual'; import { Loci, EmptyLoci, isEmptyLoci } from 'mol-model/loci'; import { StructureGroup } from './units-visual'; import { StructureRepresentation, StructureParams } from './representation'; diff --git a/src/mol-repr/structure/units-visual.ts b/src/mol-repr/structure/units-visual.ts index 0aafc91dd..8b3427321 100644 --- a/src/mol-repr/structure/units-visual.ts +++ b/src/mol-repr/structure/units-visual.ts @@ -5,7 +5,8 @@ */ import { Unit, Structure } from 'mol-model/structure'; -import { RepresentationProps, Visual, VisualContext } from '../representation'; +import { RepresentationProps } from '../representation'; +import { Visual, VisualContext } from '../visual'; import { StructureMeshParams, StructurePointsParams, StructureLinesParams, StructureDirectVolumeParams } from './representation'; import { Loci, isEveryLoci, EmptyLoci } from 'mol-model/loci'; import { MeshRenderObject, PointsRenderObject, LinesRenderObject, DirectVolumeRenderObject } from 'mol-gl/render-object'; @@ -31,7 +32,6 @@ import { SizeTheme } from 'mol-theme/size'; import { UnitsParams } from './units-representation'; import { RenderableState } from 'mol-gl/renderable'; import { Mat4 } from 'mol-math/linear-algebra'; -import { setTransform } from 'mol-geo/geometry/transform-data'; export type StructureGroup = { structure: Structure, group: Unit.SymmetryGroup } @@ -169,6 +169,7 @@ export function UnitsVisual<P extends UnitsParams>(builder: UnitsVisualGeometryB } if (updateState.updateTransform || updateState.createGeometry) { + console.log('UnitsVisual.updateBoundingSphere') updateBoundingSphere(renderObject.values, newGeometry || geometry) } @@ -239,13 +240,13 @@ export function UnitsVisual<P extends UnitsParams>(builder: UnitsVisualGeometryB return changed }, setVisibility(value: boolean) { - if (renderObject) renderObject.state.visible = value + Visual.setVisibility(renderObject, value) }, setPickable(value: boolean) { - if (renderObject) renderObject.state.pickable = value + Visual.setPickable(renderObject, value) }, setTransform(value: Mat4) { - if (renderObject) setTransform(value, renderObject.values) + Visual.setTransform(renderObject, value) }, destroy() { // TODO diff --git a/src/mol-repr/structure/visual/carbohydrate-link-cylinder.ts b/src/mol-repr/structure/visual/carbohydrate-link-cylinder.ts index 0eebe27e7..e9c9cfb4a 100644 --- a/src/mol-repr/structure/visual/carbohydrate-link-cylinder.ts +++ b/src/mol-repr/structure/visual/carbohydrate-link-cylinder.ts @@ -18,7 +18,7 @@ import { Mesh } from 'mol-geo/geometry/mesh/mesh'; import { LocationIterator } from 'mol-geo/util/location-iterator'; import { PickingId } from 'mol-geo/geometry/picking'; import { VisualUpdateState } from '../../util'; -import { VisualContext } from 'mol-repr/representation'; +import { VisualContext } from 'mol-repr/visual'; import { Theme } from 'mol-theme/theme'; function createCarbohydrateLinkCylinderMesh(ctx: VisualContext, structure: Structure, theme: Theme, props: PD.Values<CarbohydrateLinkParams>, mesh?: Mesh) { diff --git a/src/mol-repr/structure/visual/carbohydrate-symbol-mesh.ts b/src/mol-repr/structure/visual/carbohydrate-symbol-mesh.ts index 1039efdfb..e0df24ab3 100644 --- a/src/mol-repr/structure/visual/carbohydrate-symbol-mesh.ts +++ b/src/mol-repr/structure/visual/carbohydrate-symbol-mesh.ts @@ -23,7 +23,7 @@ import { LocationIterator } from 'mol-geo/util/location-iterator'; import { PickingId } from 'mol-geo/geometry/picking'; import { OrderedSet, Interval } from 'mol-data/int'; import { EmptyLoci, Loci } from 'mol-model/loci'; -import { VisualContext } from 'mol-repr/representation'; +import { VisualContext } from 'mol-repr/visual'; import { Theme } from 'mol-theme/theme'; import { getResidueLoci } from './util/common'; diff --git a/src/mol-repr/structure/visual/carbohydrate-terminal-link-cylinder.ts b/src/mol-repr/structure/visual/carbohydrate-terminal-link-cylinder.ts index 44231be6d..69368d4ca 100644 --- a/src/mol-repr/structure/visual/carbohydrate-terminal-link-cylinder.ts +++ b/src/mol-repr/structure/visual/carbohydrate-terminal-link-cylinder.ts @@ -18,7 +18,7 @@ import { Mesh } from 'mol-geo/geometry/mesh/mesh'; import { LocationIterator } from 'mol-geo/util/location-iterator'; import { PickingId } from 'mol-geo/geometry/picking'; import { VisualUpdateState } from '../../util'; -import { VisualContext } from 'mol-repr/representation'; +import { VisualContext } from 'mol-repr/visual'; import { Theme } from 'mol-theme/theme'; function createCarbohydrateTerminalLinkCylinderMesh(ctx: VisualContext, structure: Structure, theme: Theme, props: PD.Values<CarbohydrateTerminalLinkParams>, mesh?: Mesh) { diff --git a/src/mol-repr/structure/visual/cross-link-restraint-cylinder.ts b/src/mol-repr/structure/visual/cross-link-restraint-cylinder.ts index 9412dd09c..5c5c8d388 100644 --- a/src/mol-repr/structure/visual/cross-link-restraint-cylinder.ts +++ b/src/mol-repr/structure/visual/cross-link-restraint-cylinder.ts @@ -18,7 +18,7 @@ import { ParamDefinition as PD } from 'mol-util/param-definition'; import { Mesh } from 'mol-geo/geometry/mesh/mesh'; import { LocationIterator } from 'mol-geo/util/location-iterator'; import { PickingId } from 'mol-geo/geometry/picking'; -import { VisualContext } from 'mol-repr/representation'; +import { VisualContext } from 'mol-repr/visual'; import { Theme } from 'mol-theme/theme'; function createCrossLinkRestraintCylinderMesh(ctx: VisualContext, structure: Structure, theme: Theme, props: PD.Values<CrossLinkRestraintParams>, mesh?: Mesh) { diff --git a/src/mol-repr/structure/visual/element-point.ts b/src/mol-repr/structure/visual/element-point.ts index ae3a8abd1..73c77715b 100644 --- a/src/mol-repr/structure/visual/element-point.ts +++ b/src/mol-repr/structure/visual/element-point.ts @@ -13,7 +13,7 @@ import { UnitsPointsVisual, UnitsPointsParams } from '../units-visual'; import { ParamDefinition as PD } from 'mol-util/param-definition'; import { Points } from 'mol-geo/geometry/points/points'; import { PointsBuilder } from 'mol-geo/geometry/points/points-builder'; -import { VisualContext } from 'mol-repr/representation'; +import { VisualContext } from 'mol-repr/visual'; import { Theme } from 'mol-theme/theme'; export const ElementPointParams = { diff --git a/src/mol-repr/structure/visual/gaussian-density-point.ts b/src/mol-repr/structure/visual/gaussian-density-point.ts index 6a7e20353..0be7361e8 100644 --- a/src/mol-repr/structure/visual/gaussian-density-point.ts +++ b/src/mol-repr/structure/visual/gaussian-density-point.ts @@ -15,7 +15,7 @@ import { GaussianDensityProps, GaussianDensityParams } from 'mol-model/structure import { ParamDefinition as PD } from 'mol-util/param-definition'; import { Points } from 'mol-geo/geometry/points/points'; import { PointsBuilder } from 'mol-geo/geometry/points/points-builder'; -import { VisualContext } from 'mol-repr/representation'; +import { VisualContext } from 'mol-repr/visual'; import { Theme } from 'mol-theme/theme'; export const GaussianDensityPointParams = { diff --git a/src/mol-repr/structure/visual/gaussian-density-volume.ts b/src/mol-repr/structure/visual/gaussian-density-volume.ts index ee17543a6..e5a8a9683 100644 --- a/src/mol-repr/structure/visual/gaussian-density-volume.ts +++ b/src/mol-repr/structure/visual/gaussian-density-volume.ts @@ -8,7 +8,7 @@ import { Structure, StructureElement } from 'mol-model/structure'; import { VisualUpdateState } from '../../util'; import { ParamDefinition as PD } from 'mol-util/param-definition'; import { DirectVolume } from 'mol-geo/geometry/direct-volume/direct-volume'; -import { VisualContext } from 'mol-repr/representation'; +import { VisualContext } from 'mol-repr/visual'; import { Theme } from 'mol-theme/theme'; import { ComplexVisual, ComplexDirectVolumeVisual, ComplexDirectVolumeParams } from '../complex-visual'; import { EmptyLoci } from 'mol-model/loci'; diff --git a/src/mol-repr/structure/visual/gaussian-surface-mesh.ts b/src/mol-repr/structure/visual/gaussian-surface-mesh.ts index 75e5550be..0c01c3c0f 100644 --- a/src/mol-repr/structure/visual/gaussian-surface-mesh.ts +++ b/src/mol-repr/structure/visual/gaussian-surface-mesh.ts @@ -13,7 +13,7 @@ import { GaussianDensityProps, GaussianDensityParams } from 'mol-model/structure import { ParamDefinition as PD } from 'mol-util/param-definition'; import { Mesh } from 'mol-geo/geometry/mesh/mesh'; import { computeMarchingCubesMesh } from 'mol-geo/util/marching-cubes/algorithm'; -import { VisualContext } from 'mol-repr/representation'; +import { VisualContext } from 'mol-repr/visual'; import { Theme } from 'mol-theme/theme'; async function createGaussianSurfaceMesh(ctx: VisualContext, unit: Unit, structure: Structure, theme: Theme, props: GaussianDensityProps, mesh?: Mesh): Promise<Mesh> { diff --git a/src/mol-repr/structure/visual/gaussian-surface-wireframe.ts b/src/mol-repr/structure/visual/gaussian-surface-wireframe.ts index dea76bc8d..e17ebb6e2 100644 --- a/src/mol-repr/structure/visual/gaussian-surface-wireframe.ts +++ b/src/mol-repr/structure/visual/gaussian-surface-wireframe.ts @@ -13,7 +13,7 @@ import { GaussianDensityProps, GaussianDensityParams } from 'mol-model/structure import { ParamDefinition as PD } from 'mol-util/param-definition'; import { Lines } from 'mol-geo/geometry/lines/lines'; import { computeMarchingCubesLines } from 'mol-geo/util/marching-cubes/algorithm'; -import { VisualContext } from 'mol-repr/representation'; +import { VisualContext } from 'mol-repr/visual'; import { Theme } from 'mol-theme/theme'; async function createGaussianWireframe(ctx: VisualContext, unit: Unit, structure: Structure, theme: Theme, props: GaussianDensityProps, lines?: Lines): Promise<Lines> { diff --git a/src/mol-repr/structure/visual/inter-unit-link-cylinder.ts b/src/mol-repr/structure/visual/inter-unit-link-cylinder.ts index 5f298b7d9..b16a312d3 100644 --- a/src/mol-repr/structure/visual/inter-unit-link-cylinder.ts +++ b/src/mol-repr/structure/visual/inter-unit-link-cylinder.ts @@ -16,7 +16,7 @@ import { BitFlags } from 'mol-util'; import { ParamDefinition as PD } from 'mol-util/param-definition'; import { Mesh } from 'mol-geo/geometry/mesh/mesh'; import { PickingId } from 'mol-geo/geometry/picking'; -import { VisualContext } from 'mol-repr/representation'; +import { VisualContext } from 'mol-repr/visual'; import { Theme } from 'mol-theme/theme'; function createInterUnitLinkCylinderMesh(ctx: VisualContext, structure: Structure, theme: Theme, props: PD.Values<InterUnitLinkParams>, mesh?: Mesh) { diff --git a/src/mol-repr/structure/visual/intra-unit-link-cylinder.ts b/src/mol-repr/structure/visual/intra-unit-link-cylinder.ts index 1dcfc59d4..fad35df52 100644 --- a/src/mol-repr/structure/visual/intra-unit-link-cylinder.ts +++ b/src/mol-repr/structure/visual/intra-unit-link-cylinder.ts @@ -17,7 +17,7 @@ import { BitFlags } from 'mol-util'; import { ParamDefinition as PD } from 'mol-util/param-definition'; import { Mesh } from 'mol-geo/geometry/mesh/mesh'; import { PickingId } from 'mol-geo/geometry/picking'; -import { VisualContext } from 'mol-repr/representation'; +import { VisualContext } from 'mol-repr/visual'; import { Theme } from 'mol-theme/theme'; function createIntraUnitLinkCylinderMesh(ctx: VisualContext, unit: Unit, structure: Structure, theme: Theme, props: PD.Values<IntraUnitLinkParams>, mesh?: Mesh) { diff --git a/src/mol-repr/structure/visual/nucleotide-block-mesh.ts b/src/mol-repr/structure/visual/nucleotide-block-mesh.ts index c60a43488..6e638cf3e 100644 --- a/src/mol-repr/structure/visual/nucleotide-block-mesh.ts +++ b/src/mol-repr/structure/visual/nucleotide-block-mesh.ts @@ -16,7 +16,7 @@ import { Box } from 'mol-geo/primitive/box'; import { Mesh } from 'mol-geo/geometry/mesh/mesh'; import { MeshBuilder } from 'mol-geo/geometry/mesh/mesh-builder'; import { addCylinder } from 'mol-geo/geometry/mesh/builder/cylinder'; -import { VisualContext } from 'mol-repr/representation'; +import { VisualContext } from 'mol-repr/visual'; import { Theme } from 'mol-theme/theme'; import { VisualUpdateState } from 'mol-repr/util'; import { CylinderProps } from 'mol-geo/primitive/cylinder'; diff --git a/src/mol-repr/structure/visual/polymer-backbone-cylinder.ts b/src/mol-repr/structure/visual/polymer-backbone-cylinder.ts index c4860d4d7..60e8ba403 100644 --- a/src/mol-repr/structure/visual/polymer-backbone-cylinder.ts +++ b/src/mol-repr/structure/visual/polymer-backbone-cylinder.ts @@ -17,7 +17,7 @@ import { Mesh } from 'mol-geo/geometry/mesh/mesh'; import { MeshBuilder } from 'mol-geo/geometry/mesh/mesh-builder'; import { CylinderProps } from 'mol-geo/primitive/cylinder'; import { addCylinder } from 'mol-geo/geometry/mesh/builder/cylinder'; -import { VisualContext } from 'mol-repr/representation'; +import { VisualContext } from 'mol-repr/visual'; import { Theme } from 'mol-theme/theme'; export const PolymerBackboneCylinderParams = { diff --git a/src/mol-repr/structure/visual/polymer-direction-wedge.ts b/src/mol-repr/structure/visual/polymer-direction-wedge.ts index 17b11795c..d94e90efb 100644 --- a/src/mol-repr/structure/visual/polymer-direction-wedge.ts +++ b/src/mol-repr/structure/visual/polymer-direction-wedge.ts @@ -14,7 +14,7 @@ import { ParamDefinition as PD } from 'mol-util/param-definition'; import { Wedge } from 'mol-geo/primitive/wedge'; import { Mesh } from 'mol-geo/geometry/mesh/mesh'; import { MeshBuilder } from 'mol-geo/geometry/mesh/mesh-builder'; -import { VisualContext } from 'mol-repr/representation'; +import { VisualContext } from 'mol-repr/visual'; import { Theme } from 'mol-theme/theme'; import { VisualUpdateState } from 'mol-repr/util'; diff --git a/src/mol-repr/structure/visual/polymer-gap-cylinder.ts b/src/mol-repr/structure/visual/polymer-gap-cylinder.ts index 3f5856a55..d2ebb496e 100644 --- a/src/mol-repr/structure/visual/polymer-gap-cylinder.ts +++ b/src/mol-repr/structure/visual/polymer-gap-cylinder.ts @@ -17,7 +17,7 @@ import { MeshBuilder } from 'mol-geo/geometry/mesh/mesh-builder'; import { CylinderProps } from 'mol-geo/primitive/cylinder'; import { addSphere } from 'mol-geo/geometry/mesh/builder/sphere'; import { addFixedCountDashedCylinder } from 'mol-geo/geometry/mesh/builder/cylinder'; -import { VisualContext } from 'mol-repr/representation'; +import { VisualContext } from 'mol-repr/visual'; import { Theme } from 'mol-theme/theme'; const segmentCount = 10 diff --git a/src/mol-repr/structure/visual/polymer-trace-mesh.ts b/src/mol-repr/structure/visual/polymer-trace-mesh.ts index 09a38619f..deb504274 100644 --- a/src/mol-repr/structure/visual/polymer-trace-mesh.ts +++ b/src/mol-repr/structure/visual/polymer-trace-mesh.ts @@ -15,7 +15,7 @@ import { Mesh } from 'mol-geo/geometry/mesh/mesh'; import { MeshBuilder } from 'mol-geo/geometry/mesh/mesh-builder'; import { addSheet } from 'mol-geo/geometry/mesh/builder/sheet'; import { addTube } from 'mol-geo/geometry/mesh/builder/tube'; -import { VisualContext } from 'mol-repr/representation'; +import { VisualContext } from 'mol-repr/visual'; import { Theme } from 'mol-theme/theme'; export const PolymerTraceMeshParams = { diff --git a/src/mol-repr/structure/visual/util/element.ts b/src/mol-repr/structure/visual/util/element.ts index 8d513a24e..ca721b769 100644 --- a/src/mol-repr/structure/visual/util/element.ts +++ b/src/mol-repr/structure/visual/util/element.ts @@ -14,7 +14,7 @@ import { MeshBuilder } from 'mol-geo/geometry/mesh/mesh-builder'; import { addSphere } from 'mol-geo/geometry/mesh/builder/sphere'; import { PickingId } from 'mol-geo/geometry/picking'; import { LocationIterator } from 'mol-geo/util/location-iterator'; -import { VisualContext } from 'mol-repr/representation'; +import { VisualContext } from 'mol-repr/visual'; import { Theme } from 'mol-theme/theme'; import { StructureGroup } from 'mol-repr/structure/units-visual'; diff --git a/src/mol-repr/structure/visual/util/link.ts b/src/mol-repr/structure/visual/util/link.ts index 98c02ed68..956f61728 100644 --- a/src/mol-repr/structure/visual/util/link.ts +++ b/src/mol-repr/structure/visual/util/link.ts @@ -13,7 +13,7 @@ import { MeshBuilder } from 'mol-geo/geometry/mesh/mesh-builder'; import { CylinderProps } from 'mol-geo/primitive/cylinder'; import { addFixedCountDashedCylinder, addCylinder, addDoubleCylinder } from 'mol-geo/geometry/mesh/builder/cylinder'; import { LocationIterator } from 'mol-geo/util/location-iterator'; -import { VisualContext } from 'mol-repr/representation'; +import { VisualContext } from 'mol-repr/visual'; export const LinkCylinderParams = { linkScale: PD.Numeric(0.4, { min: 0, max: 1, step: 0.1 }), diff --git a/src/mol-repr/visual.ts b/src/mol-repr/visual.ts new file mode 100644 index 000000000..51805957d --- /dev/null +++ b/src/mol-repr/visual.ts @@ -0,0 +1,61 @@ +/** + * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info. + * + * @author Alexander Rose <alexander.rose@weirdbyte.de> + */ + +import { RuntimeContext } from 'mol-task' +import { RenderObject, MeshRenderObject, LinesRenderObject, PointsRenderObject, DirectVolumeRenderObject } from 'mol-gl/render-object' +import { PickingId } from '../mol-geo/geometry/picking'; +import { Loci } from 'mol-model/loci'; +import { MarkerAction } from '../mol-geo/geometry/marker-data'; +import { ParamDefinition as PD } from 'mol-util/param-definition'; +import { WebGLContext } from 'mol-gl/webgl/context'; +import { Theme } from 'mol-theme/theme'; +import { Mat4 } from 'mol-math/linear-algebra'; +import { setTransformData } from 'mol-geo/geometry/transform-data'; +import { calculateTransformBoundingSphere } from 'mol-gl/renderable/util'; +import { Sphere3D } from 'mol-math/geometry'; +import { ValueCell } from 'mol-util'; + +export interface VisualContext { + readonly runtime: RuntimeContext + readonly webgl?: WebGLContext +} +// export type VisualFactory<D, P extends PD.Params> = (ctx: VisualContext) => Visual<D, P> + +type VisualRenderObject = MeshRenderObject | LinesRenderObject | PointsRenderObject | DirectVolumeRenderObject + +export { Visual } +interface Visual<D, P extends PD.Params> { + /** Number of addressable groups in all instances of the visual */ + readonly groupCount: number + readonly renderObject: RenderObject | undefined + createOrUpdate: (ctx: VisualContext, theme: Theme, props?: Partial<PD.Values<P>>, data?: D) => Promise<void> | void + getLoci: (pickingId: PickingId) => Loci + mark: (loci: Loci, action: MarkerAction) => boolean + setVisibility: (value: boolean) => void + setPickable: (value: boolean) => void + setTransform: (value: Mat4) => void + destroy: () => void +} +namespace Visual { + export function setVisibility(renderObject: VisualRenderObject | undefined, value: boolean) { + if (renderObject) renderObject.state.visible = value + } + + export function setPickable(renderObject: VisualRenderObject | undefined, value: boolean) { + if (renderObject) renderObject.state.pickable = value + } + + export function setTransform(renderObject: VisualRenderObject | undefined, value: Mat4) { + if (renderObject) { + const { values } = renderObject + setTransformData(value, values) + const boundingSphere = calculateTransformBoundingSphere(values.invariantBoundingSphere.ref.value, values.aTransform.ref.value, values.instanceCount.ref.value) + if (!Sphere3D.equals(boundingSphere, values.boundingSphere.ref.value)) { + ValueCell.update(values.boundingSphere, boundingSphere) + } + } + } +} \ No newline at end of file diff --git a/src/mol-repr/volume/direct-volume.ts b/src/mol-repr/volume/direct-volume.ts index 024329777..5853a5870 100644 --- a/src/mol-repr/volume/direct-volume.ts +++ b/src/mol-repr/volume/direct-volume.ts @@ -19,8 +19,9 @@ import { createIdentityTransform } from 'mol-geo/geometry/transform-data'; import { DirectVolume } from 'mol-geo/geometry/direct-volume/direct-volume'; import { Geometry } from 'mol-geo/geometry/geometry'; import { VisualUpdateState } from 'mol-repr/util'; -import { VisualContext, RepresentationContext, RepresentationParamsGetter } from 'mol-repr/representation'; +import { RepresentationContext, RepresentationParamsGetter } from 'mol-repr/representation'; import { Theme, ThemeRegistryContext } from 'mol-theme/theme'; +import { VisualContext } from 'mol-repr/visual'; function getBoundingBox(gridDimension: Vec3, transform: Mat4) { const bbox = Box3D.empty() diff --git a/src/mol-repr/volume/isosurface-mesh.ts b/src/mol-repr/volume/isosurface-mesh.ts index d33822382..7dce42eb7 100644 --- a/src/mol-repr/volume/isosurface-mesh.ts +++ b/src/mol-repr/volume/isosurface-mesh.ts @@ -16,8 +16,9 @@ import { LocationIterator } from 'mol-geo/util/location-iterator'; import { createIdentityTransform } from 'mol-geo/geometry/transform-data'; import { Geometry } from 'mol-geo/geometry/geometry'; import { VisualUpdateState } from 'mol-repr/util'; -import { VisualContext, RepresentationContext, RepresentationParamsGetter } from 'mol-repr/representation'; +import { RepresentationContext, RepresentationParamsGetter } from 'mol-repr/representation'; import { Theme, ThemeRegistryContext } from 'mol-theme/theme'; +import { VisualContext } from 'mol-repr/visual'; interface VolumeIsosurfaceProps { isoValue: number diff --git a/src/mol-repr/volume/representation.ts b/src/mol-repr/volume/representation.ts index a361ad32d..94c01ff11 100644 --- a/src/mol-repr/volume/representation.ts +++ b/src/mol-repr/volume/representation.ts @@ -5,7 +5,8 @@ */ import { Task } from 'mol-task' -import { Representation, Visual, RepresentationContext, VisualContext, RepresentationProvider, RepresentationParamsGetter } from '../representation'; +import { Representation, RepresentationContext, RepresentationProvider, RepresentationParamsGetter } from '../representation'; +import { Visual, VisualContext } from '../visual'; import { VolumeData } from 'mol-model/volume'; import { Loci, EmptyLoci, isEveryLoci } from 'mol-model/loci'; import { Geometry } from 'mol-geo/geometry/geometry'; @@ -23,7 +24,6 @@ import { Theme, createEmptyTheme } from 'mol-theme/theme'; import { Subject } from 'rxjs'; import { RenderableState } from 'mol-gl/renderable'; import { Mat4 } from 'mol-math/linear-algebra'; -import { setTransform } from 'mol-geo/geometry/transform-data'; export interface VolumeVisual<P extends VolumeParams> extends Visual<VolumeData, P> { } @@ -125,13 +125,13 @@ export function VolumeVisual<P extends VolumeParams>(builder: VolumeVisualGeomet return changed }, setVisibility(value: boolean) { - if (renderObject) renderObject.state.visible = value + Visual.setVisibility(renderObject, value) }, setPickable(value: boolean) { - if (renderObject) renderObject.state.pickable = value + Visual.setPickable(renderObject, value) }, setTransform(value: Mat4) { - if (renderObject) setTransform(value, renderObject.values) + Visual.setTransform(renderObject, value) }, destroy() { // TODO -- GitLab