diff --git a/src/mol-geo/geometry/transform-data.ts b/src/mol-geo/geometry/transform-data.ts index 993c279c564fc208b1c798e16c48c5bb0f7b2ff1..486400aa21a6a1f6f62e820df05d7855c87b667a 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 a57aa5775690444e4543b37c0638d17ca490e8d0..a949d4dfc2c6b72672ea3941226e07b13ed73b91 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 3c7b2e95d862c9446b4b70b7dc6b18191191cddc..0caccdd9f3d1f874e9b8213d621bb28dd69a59be 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 d8aed56d5a857a4c5e35c6cef4eec14b9699de08..52569ad324fb9df486f33dee17775b4bd5be3f73 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 f5217b91a9d6024fff8b66267c1d1d0dd1ac9a69..d5ce56381d82bd2f4598311be0878be4a2aa6d46 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 5a0b0484b44bbebf3c786d1a4f2a397ea230f6dd..5f20f76625fb085080ed2da6ca005c83fc75b725 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 0aafc91dd1275e7715236ee6210f4b4c3a608c30..8b3427321ec7cb4bc3dbb49c7a48e50a0163254a 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 0eebe27e7ab971acfaef6f51d9c893ab22bf21d4..e9c9cfb4aecff654415755b60b5240fe371c39d1 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 1039efdfb35fc8691478ee051647a86026f2c737..e0df24ab33d18aed5bf4c6ae9f823ff656618be8 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 44231be6d242ae2f27e8a6b5d4f4f6b6d298969d..69368d4ca87dc326cf110bb2a7e7ec7fc9bceaa9 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 9412dd09c22fbb136853b441a2ea6c857450e4f8..5c5c8d388a3417dcb0d09687c6f3481d24325664 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 ae3a8abd1963f1fd73cacb8354f3e3f23937d87c..73c77715bc4a31d5039ea78476d1d42aa5b57f22 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 6a7e20353a18696efe6af7086f72e30416e35992..0be7361e871d576a0ba60281b6afd55178834149 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 ee17543a6b71de9124b0e9c2b5c80493ca531e91..e5a8a9683e593169e342375e4cd66090c5360119 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 75e5550bef38ece716431eba23d39c589096180e..0c01c3c0f6a0aa65bfefc1cca37f8b17edd1565c 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 dea76bc8d6a35c9cac5a3a30d258b106b83da614..e17ebb6e265aea176828c3fadc037889595e73c7 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 5f298b7d991aeb9e476252f510272a9aa436a4bc..b16a312d3ef7f29ccd74a2a61242ac4cac050307 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 1dcfc59d48d5007f00646684856a5ce0e2b5031b..fad35df529db12baacb5b1ac74b2c5b74788e6ff 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 c60a434881f7547188072fc471f29b53e462de4f..6e638cf3ed2f6a5ead2fe6dbf404408a013c73a3 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 c4860d4d744859c9e802c96acdb7facfc8c9af1f..60e8ba403f1fa0433a258b7f53724a1221ce09e6 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 17b11795c6f08bafdb6183821a4fd56c13f3ca11..d94e90efbc3714750b118292adc7c27b7cc5921a 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 3f5856a550ba3cf9522849ae4e20d4eb28c0c9e7..d2ebb496edcf15f62469ec34e66c00696b02f8b2 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 09a38619fa31efab45fdde6d23772b3a60fa4b86..deb5042742b2b45d282c1fedbbca8d1285f26f95 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 8d513a24e3bda1b520a9433cecd7d30852f733cb..ca721b769066e6c8b819c3e15de8521473ded340 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 98c02ed68eadadb4b24858a085da165008234dfb..956f617281fabe76a138e3f77acd0a5aa18689fa 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 0000000000000000000000000000000000000000..51805957d731001be2fcdffd9e2e58b224fabec1 --- /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 024329777aa21c30495ff23e6d40152c8ab8def8..5853a5870da55d5f4c586cc9ed1ab9f21f5c8fef 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 d338223827793bad74d0cba8298b17aeebc7d50e..7dce42eb7828b1920448cca7ed056b504b3ae719 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 a361ad32d738a75c4908f4216db70dc54066d613..94c01ff1105be2478db804f3b062c8fc11c52c2b 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