diff --git a/src/mol-repr/representation.ts b/src/mol-repr/representation.ts index edba78b11ac0be2af2b9c1b737aa5f9bacb5689b..eb2c3af88ad8c3de56c9ca3a3f9a516488825aeb 100644 --- a/src/mol-repr/representation.ts +++ b/src/mol-repr/representation.ts @@ -32,21 +32,21 @@ export interface RepresentationContext { } export type RepresentationParamsGetter<D, P extends PD.Params> = (ctx: ThemeRegistryContext, data: D) => P -export type RepresentationFactory<D, P extends PD.Params> = (ctx: RepresentationContext, getParams: RepresentationParamsGetter<D, P>) => Representation<D, P> +export type RepresentationFactory<D, P extends PD.Params, S extends Representation.State> = (ctx: RepresentationContext, getParams: RepresentationParamsGetter<D, P>) => Representation<D, P, S> // -export interface RepresentationProvider<D, P extends PD.Params> { +export interface RepresentationProvider<D, P extends PD.Params, S extends Representation.State> { readonly label: string readonly description: string - readonly factory: RepresentationFactory<D, P> + readonly factory: RepresentationFactory<D, P, S> readonly getParams: RepresentationParamsGetter<D, P> readonly defaultValues: PD.Values<P> readonly defaultColorTheme: string readonly defaultSizeTheme: string } -export type AnyRepresentationProvider = RepresentationProvider<any, {}> +export type AnyRepresentationProvider = RepresentationProvider<any, {}, Representation.State> export const EmptyRepresentationProvider = { label: '', @@ -56,9 +56,9 @@ export const EmptyRepresentationProvider = { defaultValues: {} } -export class RepresentationRegistry<D> { - private _list: { name: string, provider: RepresentationProvider<D, any> }[] = [] - private _map = new Map<string, RepresentationProvider<D, any>>() +export class RepresentationRegistry<D, S extends Representation.State> { + private _list: { name: string, provider: RepresentationProvider<D, any, any> }[] = [] + private _map = new Map<string, RepresentationProvider<D, any, any>>() get default() { return this._list[0]; } get types(): [string, string][] { @@ -67,7 +67,7 @@ export class RepresentationRegistry<D> { constructor() {}; - add<P extends PD.Params>(name: string, provider: RepresentationProvider<D, P>) { + add<P extends PD.Params>(name: string, provider: RepresentationProvider<D, P, S>) { this._list.push({ name, provider }) this._map.set(name, provider) } @@ -77,8 +77,8 @@ export class RepresentationRegistry<D> { this._map.delete(name) } - get<P extends PD.Params>(name: string): RepresentationProvider<D, P> { - return this._map.get(name) || EmptyRepresentationProvider as unknown as RepresentationProvider<D, P> + get<P extends PD.Params>(name: string): RepresentationProvider<D, P, S> { + return this._map.get(name) || EmptyRepresentationProvider as unknown as RepresentationProvider<D, P, S> } get list() { @@ -89,7 +89,7 @@ export class RepresentationRegistry<D> { // export { Representation } -interface Representation<D, P extends PD.Params = {}> { +interface Representation<D, P extends PD.Params = {}, S extends Representation.State = Representation.State> { readonly label: string readonly updated: Subject<number> /** Number of addressable groups in all visuals of the representation */ @@ -97,10 +97,10 @@ interface Representation<D, P extends PD.Params = {}> { readonly renderObjects: ReadonlyArray<GraphicsRenderObject> readonly props: Readonly<PD.Values<P>> readonly params: Readonly<P> - readonly state: Readonly<Representation.State> + readonly state: Readonly<S> readonly theme: Readonly<Theme> createOrUpdate: (props?: Partial<PD.Values<P>>, data?: D) => Task<void> - setState: (state: Partial<Representation.State>) => void + setState: (state: Partial<S>) => void setTheme: (theme: Theme) => void getLoci: (pickingId: PickingId) => Loci mark: (loci: Loci, action: MarkerAction) => boolean @@ -116,30 +116,22 @@ namespace Representation { syncManually: boolean /** A transformation applied to the representation's renderobjects */ transform: Mat4 - /** - * A set of transformations applied to the instances within the representation's renderobjects, - * laid out as Mat4's in a Float32Array - */ - instanceTransforms: Float32Array } export function createState(): State { - return { visible: false, pickable: false, syncManually: false, transform: Mat4.identity(), instanceTransforms: new Float32Array(Mat4.identity()) } + return { visible: false, pickable: false, syncManually: false, transform: Mat4.identity(), /* instanceTransforms: new Float32Array(Mat4.identity()) */ } } export function updateState(state: State, update: Partial<State>) { if (update.visible !== undefined) state.visible = update.visible if (update.pickable !== undefined) state.pickable = update.pickable if (update.syncManually !== undefined) state.syncManually = update.syncManually if (update.transform !== undefined) Mat4.copy(state.transform, update.transform) - if (update.instanceTransforms !== undefined) { - if (update.instanceTransforms.length !== state.instanceTransforms.length) { - state.instanceTransforms = new Float32Array(update.instanceTransforms) - } else { - state.instanceTransforms.set(update.instanceTransforms) - } - } + } + export interface StateBuilder<S extends State> { + create(): S + update(state: S, update: Partial<S>): void } - export type Any = Representation<any, any> + export type Any = Representation<any, any, any> export const Empty: Any = { label: '', groupCount: 0, renderObjects: [], props: {}, params: {}, updated: new Subject(), state: createState(), theme: createEmptyTheme(), createOrUpdate: () => Task.constant('', undefined), @@ -150,12 +142,12 @@ namespace Representation { destroy: () => {} } - export type Def<D, P extends PD.Params = {}> = { [k: string]: RepresentationFactory<D, P> } + export type Def<D, P extends PD.Params = {}, S extends State = State> = { [k: string]: RepresentationFactory<D, P, S> } - export function createMulti<D, P extends PD.Params = {}>(label: string, ctx: RepresentationContext, getParams: RepresentationParamsGetter<D, P>, reprDefs: Def<D, P>): Representation<D, P> { + export function createMulti<D, P extends PD.Params = {}, S extends State = State>(label: string, ctx: RepresentationContext, getParams: RepresentationParamsGetter<D, P>, stateBuilder: StateBuilder<S>, reprDefs: Def<D, P>): Representation<D, P, S> { let version = 0 const updated = new Subject<number>() - const currentState = Representation.createState() + const currentState = stateBuilder.create() let currentTheme = createEmptyTheme() let currentParams: P @@ -236,11 +228,11 @@ namespace Representation { } return marked }, - setState: (state: Partial<State>) => { + setState: (state: Partial<S>) => { for (let i = 0, il = reprList.length; i < il; ++i) { reprList[i].setState(state) } - Representation.updateState(currentState, state) + stateBuilder.update(currentState, state) }, setTheme: (theme: Theme) => { for (let i = 0, il = reprList.length; i < il; ++i) { @@ -293,9 +285,7 @@ namespace Representation { setState: (state: Partial<State>) => { if (state.visible !== undefined) Visual.setVisibility(renderObject, state.visible) if (state.pickable !== undefined) Visual.setPickable(renderObject, state.pickable) - if (state.transform !== undefined || state.instanceTransforms !== undefined) { - Visual.setTransform(renderObject, state.transform, state.instanceTransforms) - } + if (state.transform !== undefined) Visual.setTransform(renderObject, state.transform) Representation.updateState(currentState, state) }, diff --git a/src/mol-repr/structure/complex-representation.ts b/src/mol-repr/structure/complex-representation.ts index 187f8608d23642d29bff26e0871a600f7be124e1..ba7be4eecbd7820796c811886e4da252fd412fe4 100644 --- a/src/mol-repr/structure/complex-representation.ts +++ b/src/mol-repr/structure/complex-representation.ts @@ -8,11 +8,11 @@ import { Structure } from 'mol-model/structure'; import { Task } from 'mol-task' import { Loci, EmptyLoci } from 'mol-model/loci'; -import { StructureRepresentation, StructureParams } from './representation'; +import { StructureRepresentation, StructureParams, StructureRepresentationStateBuilder, StructureRepresentationState } from './representation'; import { ComplexVisual } from './complex-visual'; import { PickingId } from 'mol-geo/geometry/picking'; import { MarkerAction } from 'mol-geo/geometry/marker-data'; -import { RepresentationContext, RepresentationParamsGetter, Representation } from 'mol-repr/representation'; +import { RepresentationContext, RepresentationParamsGetter } from 'mol-repr/representation'; import { Theme, createEmptyTheme } from 'mol-theme/theme'; import { ParamDefinition as PD } from 'mol-util/param-definition'; import { Subject } from 'rxjs'; @@ -20,7 +20,7 @@ import { Subject } from 'rxjs'; export function ComplexRepresentation<P extends StructureParams>(label: string, ctx: RepresentationContext, getParams: RepresentationParamsGetter<Structure, P>, visualCtor: () => ComplexVisual<P>): StructureRepresentation<P> { let version = 0 const updated = new Subject<number>() - const _state = Representation.createState() + const _state = StructureRepresentationStateBuilder.create() let visual: ComplexVisual<P> | undefined let _structure: Structure diff --git a/src/mol-repr/structure/registry.ts b/src/mol-repr/structure/registry.ts index 12802514cc0dcf6719dc1a206d04786853f33207..d6d28f25330e7a4a0fd59e02bddc5a10aaa8f022 100644 --- a/src/mol-repr/structure/registry.ts +++ b/src/mol-repr/structure/registry.ts @@ -14,12 +14,13 @@ import { CarbohydrateRepresentationProvider } from './representation/carbohydrat import { SpacefillRepresentationProvider } from './representation/spacefill'; import { DistanceRestraintRepresentationProvider } from './representation/distance-restraint'; import { PointRepresentationProvider } from './representation/point'; +import { StructureRepresentationState } from './representation'; -export class StructureRepresentationRegistry extends RepresentationRegistry<Structure> { +export class StructureRepresentationRegistry extends RepresentationRegistry<Structure, StructureRepresentationState> { constructor() { super() Object.keys(BuiltInStructureRepresentations).forEach(name => { - const p = (BuiltInStructureRepresentations as { [k: string]: RepresentationProvider<Structure, any> })[name] + const p = (BuiltInStructureRepresentations as { [k: string]: RepresentationProvider<Structure, any, StructureRepresentationState> })[name] this.add(name, p) }) } diff --git a/src/mol-repr/structure/representation.ts b/src/mol-repr/structure/representation.ts index d42c7935cc01eb29d6d759d20cac218f78f9a6e2..183cd297c381b744e1abfe7a073d28b9322fefb4 100644 --- a/src/mol-repr/structure/representation.ts +++ b/src/mol-repr/structure/representation.ts @@ -14,13 +14,27 @@ import { Points } from 'mol-geo/geometry/points/points'; import { Lines } from 'mol-geo/geometry/lines/lines'; import { DirectVolume } from 'mol-geo/geometry/direct-volume/direct-volume'; import { Spheres } from 'mol-geo/geometry/spheres/spheres'; -// import { Mat4 } from 'mol-math/linear-algebra'; +import { StructureUnitTransforms } from 'mol-model/structure/structure/util/unit-transforms'; -export interface StructureRepresentation<P extends RepresentationProps = {}> extends Representation<Structure, P> { - // setUnitsTransform(unitTransforms: { [id: number]: Mat4 }): void +export interface StructureRepresentationState extends Representation.State { + unitTransforms: StructureUnitTransforms | null } +export const StructureRepresentationStateBuilder: Representation.StateBuilder<StructureRepresentationState> = { + create: () => { + return { + ...Representation.createState(), + unitTransforms: null + } + }, + update: (state: StructureRepresentationState, update: Partial<StructureRepresentationState>) => { + Representation.updateState(state, update) + if (update.unitTransforms !== undefined) state.unitTransforms = update.unitTransforms + } +} + +export interface StructureRepresentation<P extends RepresentationProps = {}> extends Representation<Structure, P, StructureRepresentationState> { } -export type StructureRepresentationProvider<P extends PD.Params> = RepresentationProvider<Structure, P> +export type StructureRepresentationProvider<P extends PD.Params> = RepresentationProvider<Structure, P, StructureRepresentationState> // diff --git a/src/mol-repr/structure/representation/ball-and-stick.ts b/src/mol-repr/structure/representation/ball-and-stick.ts index 0146c906126da9efed2b514cc62eb0e70f0a0dec..a7b3e9accf7d1a73008a0a5caad0fc46c748eb36 100644 --- a/src/mol-repr/structure/representation/ball-and-stick.ts +++ b/src/mol-repr/structure/representation/ball-and-stick.ts @@ -10,7 +10,7 @@ import { InterUnitLinkVisual, InterUnitLinkParams } from '../visual/inter-unit-l import { ParamDefinition as PD } from 'mol-util/param-definition'; import { UnitsRepresentation } from '../units-representation'; import { ComplexRepresentation } from '../complex-representation'; -import { StructureRepresentation, StructureRepresentationProvider } from '../representation'; +import { StructureRepresentation, StructureRepresentationProvider, StructureRepresentationStateBuilder } from '../representation'; import { Representation, RepresentationParamsGetter, RepresentationContext } from 'mol-repr/representation'; import { ThemeRegistryContext } from 'mol-theme/theme'; import { Structure } from 'mol-model/structure'; @@ -40,7 +40,7 @@ export function getBallAndStickParams(ctx: ThemeRegistryContext, structure: Stru export type BallAndStickRepresentation = StructureRepresentation<BallAndStickParams> export function BallAndStickRepresentation(ctx: RepresentationContext, getParams: RepresentationParamsGetter<Structure, BallAndStickParams>): BallAndStickRepresentation { - return Representation.createMulti('Ball & Stick', ctx, getParams, BallAndStickVisuals as unknown as Representation.Def<Structure, BallAndStickParams>) + return Representation.createMulti('Ball & Stick', ctx, getParams, StructureRepresentationStateBuilder, BallAndStickVisuals as unknown as Representation.Def<Structure, BallAndStickParams>) } export const BallAndStickRepresentationProvider: StructureRepresentationProvider<BallAndStickParams> = { diff --git a/src/mol-repr/structure/representation/carbohydrate.ts b/src/mol-repr/structure/representation/carbohydrate.ts index a71144a064cea93fddf73db62966e0d252821844..a4f4d3079ce4b63ce9356e4e7322d28d354e4ede 100644 --- a/src/mol-repr/structure/representation/carbohydrate.ts +++ b/src/mol-repr/structure/representation/carbohydrate.ts @@ -9,7 +9,7 @@ import { CarbohydrateLinkVisual, CarbohydrateLinkParams } from '../visual/carboh import { CarbohydrateTerminalLinkParams, CarbohydrateTerminalLinkVisual } from '../visual/carbohydrate-terminal-link-cylinder'; import { ParamDefinition as PD } from 'mol-util/param-definition'; import { ComplexRepresentation } from '../complex-representation'; -import { StructureRepresentation, StructureRepresentationProvider } from '../representation'; +import { StructureRepresentation, StructureRepresentationProvider, StructureRepresentationStateBuilder } from '../representation'; import { Representation, RepresentationParamsGetter, RepresentationContext } from 'mol-repr/representation'; import { ThemeRegistryContext } from 'mol-theme/theme'; import { Structure } from 'mol-model/structure'; @@ -35,7 +35,7 @@ export function getCarbohydrateParams(ctx: ThemeRegistryContext, structure: Stru export type CarbohydrateRepresentation = StructureRepresentation<CarbohydrateParams> export function CarbohydrateRepresentation(ctx: RepresentationContext, getParams: RepresentationParamsGetter<Structure, CarbohydrateParams>): CarbohydrateRepresentation { - return Representation.createMulti('Carbohydrate', ctx, getParams, CarbohydrateVisuals as unknown as Representation.Def<Structure, CarbohydrateParams>) + return Representation.createMulti('Carbohydrate', ctx, getParams, StructureRepresentationStateBuilder, CarbohydrateVisuals as unknown as Representation.Def<Structure, CarbohydrateParams>) } export const CarbohydrateRepresentationProvider: StructureRepresentationProvider<CarbohydrateParams> = { diff --git a/src/mol-repr/structure/representation/cartoon.ts b/src/mol-repr/structure/representation/cartoon.ts index 5dfed8882e77416a1582696660bb8c93b5681426..d524d00d6c46b62e7253725c4d59e8aa8417c686 100644 --- a/src/mol-repr/structure/representation/cartoon.ts +++ b/src/mol-repr/structure/representation/cartoon.ts @@ -9,7 +9,7 @@ import { PolymerGapVisual, PolymerGapParams } from '../visual/polymer-gap-cylind import { NucleotideBlockVisual, NucleotideBlockParams } from '../visual/nucleotide-block-mesh'; import { ParamDefinition as PD } from 'mol-util/param-definition'; import { UnitsRepresentation } from '../units-representation'; -import { StructureRepresentation, StructureRepresentationProvider } from '../representation'; +import { StructureRepresentation, StructureRepresentationProvider, StructureRepresentationStateBuilder } from '../representation'; import { Representation, RepresentationParamsGetter, RepresentationContext } from 'mol-repr/representation'; import { PolymerDirectionVisual, PolymerDirectionParams } from '../visual/polymer-direction-wedge'; import { Structure, Unit } from 'mol-model/structure'; @@ -49,7 +49,7 @@ export function getCartoonParams(ctx: ThemeRegistryContext, structure: Structure export type CartoonRepresentation = StructureRepresentation<CartoonParams> export function CartoonRepresentation(ctx: RepresentationContext, getParams: RepresentationParamsGetter<Structure, CartoonParams>): CartoonRepresentation { - return Representation.createMulti('Cartoon', ctx, getParams, CartoonVisuals as unknown as Representation.Def<Structure, CartoonParams>) + return Representation.createMulti('Cartoon', ctx, getParams, StructureRepresentationStateBuilder, CartoonVisuals as unknown as Representation.Def<Structure, CartoonParams>) } export const CartoonRepresentationProvider: StructureRepresentationProvider<CartoonParams> = { diff --git a/src/mol-repr/structure/representation/distance-restraint.ts b/src/mol-repr/structure/representation/distance-restraint.ts index ca1c8a8819531d2fef7b73b8c6073620787a3d6e..096bf268b829982f631008c7f1bde095d4e6a48f 100644 --- a/src/mol-repr/structure/representation/distance-restraint.ts +++ b/src/mol-repr/structure/representation/distance-restraint.ts @@ -7,7 +7,7 @@ import { CrossLinkRestraintVisual, CrossLinkRestraintParams } from '../visual/cross-link-restraint-cylinder'; import { ParamDefinition as PD } from 'mol-util/param-definition'; import { ComplexRepresentation } from '../complex-representation'; -import { StructureRepresentation, StructureRepresentationProvider } from '../representation'; +import { StructureRepresentation, StructureRepresentationProvider, StructureRepresentationStateBuilder } from '../representation'; import { Representation, RepresentationContext, RepresentationParamsGetter } from 'mol-repr/representation'; import { ThemeRegistryContext } from 'mol-theme/theme'; import { Structure } from 'mol-model/structure'; @@ -28,7 +28,7 @@ export function getDistanceRestraintParams(ctx: ThemeRegistryContext, structure: export type DistanceRestraintRepresentation = StructureRepresentation<DistanceRestraintParams> export function DistanceRestraintRepresentation(ctx: RepresentationContext, getParams: RepresentationParamsGetter<Structure, DistanceRestraintParams>): DistanceRestraintRepresentation { - return Representation.createMulti('DistanceRestraint', ctx, getParams, DistanceRestraintVisuals as unknown as Representation.Def<Structure, DistanceRestraintParams>) + return Representation.createMulti('DistanceRestraint', ctx, getParams, StructureRepresentationStateBuilder, DistanceRestraintVisuals as unknown as Representation.Def<Structure, DistanceRestraintParams>) } export const DistanceRestraintRepresentationProvider: StructureRepresentationProvider<DistanceRestraintParams> = { diff --git a/src/mol-repr/structure/representation/molecular-surface.ts b/src/mol-repr/structure/representation/molecular-surface.ts index 48d5b9f48c34d038f18873f547cdbf145d33540b..4cef6716dca74fcef9b2ec284b41b1b41eaee9f3 100644 --- a/src/mol-repr/structure/representation/molecular-surface.ts +++ b/src/mol-repr/structure/representation/molecular-surface.ts @@ -8,7 +8,7 @@ import { GaussianSurfaceVisual, GaussianSurfaceParams } from '../visual/gaussian import { UnitsRepresentation } from '../units-representation'; import { GaussianWireframeVisual, GaussianWireframeParams } from '../visual/gaussian-surface-wireframe'; import { ParamDefinition as PD } from 'mol-util/param-definition'; -import { StructureRepresentation, StructureRepresentationProvider } from '../representation'; +import { StructureRepresentation, StructureRepresentationProvider, StructureRepresentationStateBuilder } from '../representation'; import { Representation, RepresentationParamsGetter, RepresentationContext } from 'mol-repr/representation'; import { ThemeRegistryContext } from 'mol-theme/theme'; import { Structure } from 'mol-model/structure'; @@ -32,7 +32,7 @@ export function getMolecularSurfaceParams(ctx: ThemeRegistryContext, structure: export type MolecularSurfaceRepresentation = StructureRepresentation<MolecularSurfaceParams> export function MolecularSurfaceRepresentation(ctx: RepresentationContext, getParams: RepresentationParamsGetter<Structure, MolecularSurfaceParams>): MolecularSurfaceRepresentation { - return Representation.createMulti('Molecular Surface', ctx, getParams, MolecularSurfaceVisuals as unknown as Representation.Def<Structure, MolecularSurfaceParams>) + return Representation.createMulti('Molecular Surface', ctx, getParams, StructureRepresentationStateBuilder, MolecularSurfaceVisuals as unknown as Representation.Def<Structure, MolecularSurfaceParams>) } export const MolecularSurfaceRepresentationProvider: StructureRepresentationProvider<MolecularSurfaceParams> = { diff --git a/src/mol-repr/structure/representation/molecular-volume.ts b/src/mol-repr/structure/representation/molecular-volume.ts index d437203678c75fb13e21d67130e7d6d6ce153fc9..4bf0a0141629d5912bd6cf5de50e001a4ed3a0da 100644 --- a/src/mol-repr/structure/representation/molecular-volume.ts +++ b/src/mol-repr/structure/representation/molecular-volume.ts @@ -6,7 +6,7 @@ import { ParamDefinition as PD } from 'mol-util/param-definition'; import { GaussianDensityVolumeParams, GaussianDensityVolumeVisual } from '../visual/gaussian-density-volume'; -import { StructureRepresentation, StructureRepresentationProvider, ComplexRepresentation } from '../representation'; +import { StructureRepresentation, StructureRepresentationProvider, ComplexRepresentation, StructureRepresentationStateBuilder } from '../representation'; import { Representation, RepresentationParamsGetter, RepresentationContext } from 'mol-repr/representation'; import { ThemeRegistryContext } from 'mol-theme/theme'; import { Structure } from 'mol-model/structure'; @@ -25,7 +25,7 @@ export function getMolecularVolumeParams(ctx: ThemeRegistryContext, structure: S export type MolecularVolumeRepresentation = StructureRepresentation<MolecularVolumeParams> export function MolecularVolumeRepresentation(ctx: RepresentationContext, getParams: RepresentationParamsGetter<Structure, MolecularVolumeParams>): MolecularVolumeRepresentation { - return Representation.createMulti('Molecular Volume', ctx, getParams, MolecularVolumeVisuals as unknown as Representation.Def<Structure, MolecularVolumeParams>) + return Representation.createMulti('Molecular Volume', ctx, getParams, StructureRepresentationStateBuilder, MolecularVolumeVisuals as unknown as Representation.Def<Structure, MolecularVolumeParams>) } export const MolecularVolumeRepresentationProvider: StructureRepresentationProvider<MolecularVolumeParams> = { diff --git a/src/mol-repr/structure/representation/point.ts b/src/mol-repr/structure/representation/point.ts index 9a1789271d384a46dc9af306591e487ef3562be0..fe54c0e2c1c417e6fbfdc48403bbc7a6a5f3662d 100644 --- a/src/mol-repr/structure/representation/point.ts +++ b/src/mol-repr/structure/representation/point.ts @@ -7,7 +7,7 @@ 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 { StructureRepresentation, StructureRepresentationProvider, StructureRepresentationStateBuilder } from '../representation'; import { Representation, RepresentationParamsGetter, RepresentationContext } from 'mol-repr/representation'; import { ThemeRegistryContext } from 'mol-theme/theme'; import { Structure } from 'mol-model/structure'; @@ -28,7 +28,7 @@ export function getPointParams(ctx: ThemeRegistryContext, structure: Structure) 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>) + return Representation.createMulti('Point', ctx, getParams, StructureRepresentationStateBuilder, PointVisuals as unknown as Representation.Def<Structure, PointParams>) } export const PointRepresentationProvider: StructureRepresentationProvider<PointParams> = { diff --git a/src/mol-repr/structure/representation/spacefill.ts b/src/mol-repr/structure/representation/spacefill.ts index ad310ca55c54e09d6e747ba231115701c83eaf36..74ca4264ac9695dc178f65830c6816532261103e 100644 --- a/src/mol-repr/structure/representation/spacefill.ts +++ b/src/mol-repr/structure/representation/spacefill.ts @@ -7,7 +7,7 @@ import { getElementSphereVisual, ElementSphereParams } from '../visual/element-sphere'; import { UnitsRepresentation } from '../units-representation'; import { ParamDefinition as PD } from 'mol-util/param-definition'; -import { StructureRepresentation, StructureRepresentationProvider } from '../representation'; +import { StructureRepresentation, StructureRepresentationProvider, StructureRepresentationStateBuilder } from '../representation'; import { RepresentationParamsGetter, RepresentationContext, Representation } from 'mol-repr/representation'; import { ThemeRegistryContext } from 'mol-theme/theme'; import { Structure } from 'mol-model/structure'; @@ -28,7 +28,7 @@ export function getSpacefillParams(ctx: ThemeRegistryContext, structure: Structu export type SpacefillRepresentation = StructureRepresentation<SpacefillParams> export function SpacefillRepresentation(ctx: RepresentationContext, getParams: RepresentationParamsGetter<Structure, SpacefillParams>): SpacefillRepresentation { - return Representation.createMulti('Spacefill', ctx, getParams, SpacefillVisuals as unknown as Representation.Def<Structure, SpacefillParams>) + return Representation.createMulti('Spacefill', ctx, getParams, StructureRepresentationStateBuilder, SpacefillVisuals as unknown as Representation.Def<Structure, SpacefillParams>) } export const SpacefillRepresentationProvider: StructureRepresentationProvider<SpacefillParams> = { diff --git a/src/mol-repr/structure/units-representation.ts b/src/mol-repr/structure/units-representation.ts index ffe186030e06f3aa5edd3a175b208d79b58c1933..5f3484040efc14cd1736c93496822aab36e1620c 100644 --- a/src/mol-repr/structure/units-representation.ts +++ b/src/mol-repr/structure/units-representation.ts @@ -8,11 +8,11 @@ import { Structure, Unit } from 'mol-model/structure'; import { Task } from 'mol-task' import { GraphicsRenderObject } from 'mol-gl/render-object'; -import { RepresentationContext, RepresentationParamsGetter, Representation } from '../representation'; +import { RepresentationContext, RepresentationParamsGetter } from '../representation'; import { Visual } from '../visual'; import { Loci, EmptyLoci, isEmptyLoci } from 'mol-model/loci'; import { StructureGroup } from './units-visual'; -import { StructureRepresentation, StructureParams } from './representation'; +import { StructureRepresentation, StructureParams, StructureRepresentationState, StructureRepresentationStateBuilder } from './representation'; import { PickingId } from 'mol-geo/geometry/picking'; import { MarkerAction } from 'mol-geo/geometry/marker-data'; import { Theme, createEmptyTheme } from 'mol-theme/theme'; @@ -31,7 +31,7 @@ export interface UnitsVisual<P extends UnitsParams> extends Visual<StructureGrou export function UnitsRepresentation<P extends UnitsParams>(label: string, ctx: RepresentationContext, getParams: RepresentationParamsGetter<Structure, P>, visualCtor: () => UnitsVisual<P>): StructureRepresentation<P> { let version = 0 const updated = new Subject<number>() - const _state = Representation.createState() + const _state = StructureRepresentationStateBuilder.create() let visuals = new Map<number, { group: Unit.SymmetryGroup, visual: UnitsVisual<P> }>() let _structure: Structure diff --git a/src/mol-repr/volume/registry.ts b/src/mol-repr/volume/registry.ts index 512463432e26bda845a6ec9d6b784634f8cf50f1..7c8631590b2bd0ac39af0675045d7420309e883e 100644 --- a/src/mol-repr/volume/registry.ts +++ b/src/mol-repr/volume/registry.ts @@ -4,16 +4,16 @@ * @author Alexander Rose <alexander.rose@weirdbyte.de> */ -import { RepresentationProvider, RepresentationRegistry } from '../representation'; +import { RepresentationProvider, RepresentationRegistry, Representation } from '../representation'; import { VolumeData } from 'mol-model/volume'; import { IsosurfaceRepresentationProvider } from './isosurface-mesh'; import { DirectVolumeRepresentationProvider } from './direct-volume'; -export class VolumeRepresentationRegistry extends RepresentationRegistry<VolumeData> { +export class VolumeRepresentationRegistry extends RepresentationRegistry<VolumeData, Representation.State> { constructor() { super() Object.keys(BuiltInVolumeRepresentations).forEach(name => { - const p = (BuiltInVolumeRepresentations as { [k: string]: RepresentationProvider<VolumeData, any> })[name] + const p = (BuiltInVolumeRepresentations as { [k: string]: RepresentationProvider<VolumeData, any, Representation.State> })[name] this.add(name, p) }) } diff --git a/src/mol-repr/volume/representation.ts b/src/mol-repr/volume/representation.ts index 84836600bb5fa30b9fd2e1f25b9afe24716afaa1..1822e400ee7579b4c2e30ac980e0d0c39de55db6 100644 --- a/src/mol-repr/volume/representation.ts +++ b/src/mol-repr/volume/representation.ts @@ -129,7 +129,7 @@ export function VolumeVisual<P extends VolumeParams>(builder: VolumeVisualGeomet setPickable(pickable: boolean) { Visual.setPickable(renderObject, pickable) }, - setTransform(matrix?: Mat4, instanceMatrices?: Float32Array) { + setTransform(matrix?: Mat4, instanceMatrices?: Float32Array | null) { Visual.setTransform(renderObject, matrix, instanceMatrices) }, destroy() { @@ -141,7 +141,7 @@ export function VolumeVisual<P extends VolumeParams>(builder: VolumeVisualGeomet export interface VolumeRepresentation<P extends VolumeParams> extends Representation<VolumeData, P> { } -export type VolumeRepresentationProvider<P extends VolumeParams> = RepresentationProvider<VolumeData, P> +export type VolumeRepresentationProvider<P extends VolumeParams> = RepresentationProvider<VolumeData, P, Representation.State> //