Browse Source

wip, representation destroy method

Alexander Rose 6 years ago
parent
commit
0a6904bcfa

+ 2 - 1
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
         }
     }
 }

+ 8 - 11
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,

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

+ 1 - 0
src/mol-geo/representation/structure/units-visual.ts

@@ -123,6 +123,7 @@ export function UnitsMeshVisual<P extends UnitsMeshProps>(builder: UnitsMeshVisu
         },
         destroy() {
             // TODO
+            renderObject = undefined
         }
     }
 }

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