From 0a6904bcfae289132e5c86ab4b7c5c5fc065a1f3 Mon Sep 17 00:00:00 2001 From: Alexander Rose <alex.rose@rcsb.org> Date: Mon, 27 Aug 2018 17:10:51 -0700 Subject: [PATCH] wip, representation destroy method --- src/mol-geo/representation/shape/index.ts | 3 ++- .../structure/complex-representation.ts | 19 ++++++++----------- .../structure/complex-visual.ts | 8 +++++--- .../representation/structure/units-visual.ts | 1 + .../structure/visual/element-point.ts | 7 ++++--- 5 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/mol-geo/representation/shape/index.ts b/src/mol-geo/representation/shape/index.ts index 0955145ad..dc6393dee 100644 --- a/src/mol-geo/representation/shape/index.ts +++ b/src/mol-geo/representation/shape/index.ts @@ -64,7 +64,6 @@ export function ShapeRepresentation<P extends ShapeProps>(): ShapeRepresentation const state = createRenderableState(_props) _renderObject = createMeshRenderObject(values, state) - console.log(_renderObject) renderObjects.push(_renderObject) }); } @@ -114,6 +113,8 @@ export function ShapeRepresentation<P extends ShapeProps>(): ShapeRepresentation }, destroy() { // TODO + renderObjects.length = 0 + _renderObject = undefined } } } diff --git a/src/mol-geo/representation/structure/complex-representation.ts b/src/mol-geo/representation/structure/complex-representation.ts index 096d770f4..f10ddbdf2 100644 --- a/src/mol-geo/representation/structure/complex-representation.ts +++ b/src/mol-geo/representation/structure/complex-representation.ts @@ -8,14 +8,14 @@ import { Structure } from 'mol-model/structure'; import { Task } from 'mol-task' import { PickingId } from '../../util/picking'; -import { Loci, EmptyLoci, isEmptyLoci } from 'mol-model/loci'; +import { Loci, EmptyLoci } from 'mol-model/loci'; import { MarkerAction } from '../../util/marker-data'; import { getQualityProps } from '../util'; import { StructureProps, DefaultStructureProps, StructureRepresentation } from '.'; import { ComplexVisual } from './complex-visual'; export function ComplexRepresentation<P extends StructureProps>(visualCtor: () => ComplexVisual<P>): StructureRepresentation<P> { - let visual: ComplexVisual<P> + let visual: ComplexVisual<P> | undefined let _props: P let _structure: Structure @@ -32,7 +32,7 @@ export function ComplexRepresentation<P extends StructureProps>(visualCtor: () = if (_structure.hashCode === structure.hashCode) { await update(_props) } else { - if (!await visual.update(ctx, _props)) { + if (visual && !await visual.update(ctx, _props)) { await visual.create(ctx, structure, _props) } } @@ -46,30 +46,27 @@ export function ComplexRepresentation<P extends StructureProps>(visualCtor: () = _props = Object.assign({}, DefaultStructureProps, _props, props, getQualityProps(props, _structure)) _props.colorTheme.structure = _structure - if (!await visual.update(ctx, _props)) { + if (visual && !await visual.update(ctx, _props)) { await visual.create(ctx, _structure, _props) } }) } function getLoci(pickingId: PickingId) { - let loci: Loci = EmptyLoci - const _loci = visual.getLoci(pickingId) - if (!isEmptyLoci(_loci)) loci = _loci - return loci + return visual ? visual.getLoci(pickingId) : EmptyLoci } function mark(loci: Loci, action: MarkerAction) { - visual.mark(loci, action) + if (visual) visual.mark(loci, action) } function destroy() { - visual.destroy() + if (visual) visual.destroy() } return { get renderObjects() { - return visual.renderObject ? [ visual.renderObject ] : [] + return visual && visual.renderObject ? [ visual.renderObject ] : [] }, get props() { return _props }, create, diff --git a/src/mol-geo/representation/structure/complex-visual.ts b/src/mol-geo/representation/structure/complex-visual.ts index 063ecf36d..514e8adae 100644 --- a/src/mol-geo/representation/structure/complex-visual.ts +++ b/src/mol-geo/representation/structure/complex-visual.ts @@ -15,7 +15,7 @@ import { StructureProps, DefaultStructureMeshProps, MeshUpdateState } from '.'; import { deepEqual, ValueCell } from 'mol-util'; import { updateMeshValues, updateRenderableState } from '../util'; import { PickingId } from '../../util/picking'; -import { Loci, isEveryLoci } from 'mol-model/loci'; +import { Loci, isEveryLoci, EmptyLoci } from 'mol-model/loci'; import { MarkerAction, applyMarkerAction } from '../../util/marker-data'; import { Interval } from 'mol-data/int'; @@ -39,7 +39,7 @@ export function ComplexMeshVisual<P extends ComplexMeshProps>(builder: ComplexMe const { defaultProps, createMesh, createLocationIterator, getLoci, mark, setUpdateState } = builder const updateState = MeshUpdateState.create() - let renderObject: MeshRenderObject + let renderObject: MeshRenderObject | undefined let currentProps: P let mesh: Mesh let currentStructure: Structure @@ -92,9 +92,10 @@ export function ComplexMeshVisual<P extends ComplexMeshProps>(builder: ComplexMe return true }, getLoci(pickingId: PickingId) { - return getLoci(pickingId, currentStructure, renderObject.id) + return renderObject ? getLoci(pickingId, currentStructure, renderObject.id) : EmptyLoci }, mark(loci: Loci, action: MarkerAction) { + if (!renderObject) return const { tMarker } = renderObject.values const { groupCount, instanceCount } = locationIt @@ -117,6 +118,7 @@ export function ComplexMeshVisual<P extends ComplexMeshProps>(builder: ComplexMe }, destroy() { // TODO + renderObject = undefined } } } \ No newline at end of file diff --git a/src/mol-geo/representation/structure/units-visual.ts b/src/mol-geo/representation/structure/units-visual.ts index 51d80f236..ff390f123 100644 --- a/src/mol-geo/representation/structure/units-visual.ts +++ b/src/mol-geo/representation/structure/units-visual.ts @@ -123,6 +123,7 @@ export function UnitsMeshVisual<P extends UnitsMeshProps>(builder: UnitsMeshVisu }, destroy() { // TODO + renderObject = undefined } } } \ No newline at end of file diff --git a/src/mol-geo/representation/structure/visual/element-point.ts b/src/mol-geo/representation/structure/visual/element-point.ts index e58f1bee1..1cfca7104 100644 --- a/src/mol-geo/representation/structure/visual/element-point.ts +++ b/src/mol-geo/representation/structure/visual/element-point.ts @@ -17,7 +17,7 @@ import { deepEqual, defaults } from 'mol-util'; import { SortedArray } from 'mol-data/int'; import { RenderableState, PointValues } from 'mol-gl/renderable'; import { PickingId } from '../../../util/picking'; -import { Loci } from 'mol-model/loci'; +import { Loci, EmptyLoci } from 'mol-model/loci'; import { MarkerAction, createMarkers } from '../../../util/marker-data'; import { Vec3 } from 'mol-math/linear-algebra'; import { fillSerial } from 'mol-util/array'; @@ -48,7 +48,7 @@ export function createPointVertices(unit: Unit) { } export default function PointVisual(): UnitsVisual<PointProps> { - let renderObject: PointRenderObject + let renderObject: PointRenderObject | undefined let currentProps = DefaultPointProps let currentGroup: Unit.SymmetryGroup @@ -123,7 +123,7 @@ export default function PointVisual(): UnitsVisual<PointProps> { return false }, getLoci(pickingId: PickingId) { - return getElementLoci(pickingId, currentGroup, renderObject.id) + return renderObject ? getElementLoci(pickingId, currentGroup, renderObject.id) : EmptyLoci }, mark(loci: Loci, action: MarkerAction) { // TODO @@ -131,6 +131,7 @@ export default function PointVisual(): UnitsVisual<PointProps> { }, destroy() { // TODO + renderObject = undefined } } } -- GitLab