From 00f5ff24ea4099fa5325b370eefe0be2335e996e Mon Sep 17 00:00:00 2001 From: Alexander Rose <alex.rose@rcsb.org> Date: Mon, 27 Aug 2018 10:34:06 -0700 Subject: [PATCH] handle undefined renderObject --- src/mol-geo/representation/index.ts | 2 +- src/mol-geo/representation/shape/index.ts | 5 +++-- .../representation/structure/complex-representation.ts | 4 +++- .../representation/structure/units-representation.ts | 4 +++- src/mol-geo/representation/structure/units-visual.ts | 7 ++++--- src/mol-geo/representation/volume/index.ts | 2 +- 6 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/mol-geo/representation/index.ts b/src/mol-geo/representation/index.ts index a444545fe..d7cac572d 100644 --- a/src/mol-geo/representation/index.ts +++ b/src/mol-geo/representation/index.ts @@ -23,7 +23,7 @@ export interface Representation<D, P extends RepresentationProps = {}> { } export interface Visual<D, P extends RepresentationProps = {}> { - readonly renderObject: RenderObject + readonly renderObject: RenderObject | undefined create: (ctx: RuntimeContext, data: D, props?: Partial<P>) => Promise<void> update: (ctx: RuntimeContext, props: Partial<P>) => Promise<boolean> getLoci: (pickingId: PickingId) => Loci diff --git a/src/mol-geo/representation/shape/index.ts b/src/mol-geo/representation/shape/index.ts index 14fcd8e32..0955145ad 100644 --- a/src/mol-geo/representation/shape/index.ts +++ b/src/mol-geo/representation/shape/index.ts @@ -33,7 +33,7 @@ export type ShapeProps = typeof DefaultShapeProps export function ShapeRepresentation<P extends ShapeProps>(): ShapeRepresentation<P> { const renderObjects: RenderObject[] = [] - let _renderObject: MeshRenderObject + let _renderObject: MeshRenderObject | undefined let _shape: Shape let _props: P @@ -83,12 +83,13 @@ export function ShapeRepresentation<P extends ShapeProps>(): ShapeRepresentation update, getLoci(pickingId: PickingId) { const { objectId, groupId } = pickingId - if (_renderObject.id === objectId) { + if (_renderObject && _renderObject.id === objectId) { return Shape.Loci([ { shape: _shape, ids: OrderedSet.ofSingleton(groupId) } ]) } return EmptyLoci }, mark(loci: Loci, action: MarkerAction) { + if (!_renderObject) return const { tMarker } = _renderObject.values let changed = false if (isEveryLoci(loci)) { diff --git a/src/mol-geo/representation/structure/complex-representation.ts b/src/mol-geo/representation/structure/complex-representation.ts index 6a258b24c..096d770f4 100644 --- a/src/mol-geo/representation/structure/complex-representation.ts +++ b/src/mol-geo/representation/structure/complex-representation.ts @@ -68,7 +68,9 @@ export function ComplexRepresentation<P extends StructureProps>(visualCtor: () = } return { - get renderObjects() { return [ visual.renderObject ] }, + get renderObjects() { + return visual.renderObject ? [ visual.renderObject ] : [] + }, get props() { return _props }, create, update, diff --git a/src/mol-geo/representation/structure/units-representation.ts b/src/mol-geo/representation/structure/units-representation.ts index f2ed113e7..03f2945b1 100644 --- a/src/mol-geo/representation/structure/units-representation.ts +++ b/src/mol-geo/representation/structure/units-representation.ts @@ -114,7 +114,9 @@ export function UnitsRepresentation<P extends StructureProps>(visualCtor: () => return { get renderObjects() { const renderObjects: RenderObject[] = [] - visuals.forEach(({ visual }) => renderObjects.push(visual.renderObject)) + visuals.forEach(({ visual }) => { + if (visual.renderObject) renderObjects.push(visual.renderObject) + }) return renderObjects }, get props() { diff --git a/src/mol-geo/representation/structure/units-visual.ts b/src/mol-geo/representation/structure/units-visual.ts index d7ebb4b9b..51d80f236 100644 --- a/src/mol-geo/representation/structure/units-visual.ts +++ b/src/mol-geo/representation/structure/units-visual.ts @@ -12,7 +12,7 @@ import { PickingId } from '../../util/picking'; import { LocationIterator } from '../../util/location-iterator'; import { Mesh } from '../../mesh/mesh'; import { MarkerAction, applyMarkerAction } from '../../util/marker-data'; -import { Loci, isEveryLoci } from 'mol-model/loci'; +import { Loci, isEveryLoci, EmptyLoci } from 'mol-model/loci'; import { MeshRenderObject } from 'mol-gl/render-object'; import { createUnitsMeshRenderObject, createColors } from './visual/util/common'; import { deepEqual, ValueCell } from 'mol-util'; @@ -40,7 +40,7 @@ export function UnitsMeshVisual<P extends UnitsMeshProps>(builder: UnitsMeshVisu 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 currentGroup: Unit.SymmetryGroup @@ -97,9 +97,10 @@ export function UnitsMeshVisual<P extends UnitsMeshProps>(builder: UnitsMeshVisu return true }, getLoci(pickingId: PickingId) { - return getLoci(pickingId, currentGroup, renderObject.id) + return renderObject ? getLoci(pickingId, currentGroup, renderObject.id) : EmptyLoci }, mark(loci: Loci, action: MarkerAction) { + if (!renderObject) return const { tMarker } = renderObject.values const { groupCount, instanceCount } = locationIt diff --git a/src/mol-geo/representation/volume/index.ts b/src/mol-geo/representation/volume/index.ts index 75555e2ca..b2a6afeda 100644 --- a/src/mol-geo/representation/volume/index.ts +++ b/src/mol-geo/representation/volume/index.ts @@ -33,7 +33,7 @@ export function VolumeRepresentation<P extends VolumeProps>(visualCtor: (volumeD _volumeData = volumeData const visual = visualCtor(_volumeData) await visual.create(ctx, _volumeData, props) - renderObjects.push(visual.renderObject) + if (visual.renderObject) renderObjects.push(visual.renderObject) }); } -- GitLab