diff --git a/src/mol-geo/representation/index.ts b/src/mol-geo/representation/index.ts index a444545fe64d4823516e40b01a07e054b43239e9..d7cac572dc59862a36be36f904216a0bf51d12c2 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 14fcd8e32935371921c5269ca9a34415e9dacc94..0955145ad288e91436cdb884f5ae018aa6ce3ebe 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 6a258b24ca99cf9ccc9edc5d1297b306ac483051..096d770f4c09de2311b42b5e68a47dccb0f0b68f 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 f2ed113e7b621b7db6d0ef4827f9f4c9d019a9be..03f2945b142b47b4bbe9344a1ca03ee0d97d81d2 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 d7ebb4b9bc5ccc140c3091671ba836e8fbc87f6a..51d80f236646a267ad8e0eb207a4125c4452287d 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 75555e2ca1ac77678a46c18ca5ffd9f89c9a3d09..b2a6afeda978d13e48bae50c4a83c3f5ca970fd7 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) }); }