Skip to content
Snippets Groups Projects
Commit 78fdc0d8 authored by Alexander Rose's avatar Alexander Rose
Browse files

renamed representation building blocks to Visuals

parent 762048b7
No related branches found
No related tags found
No related merge requests found
......@@ -11,7 +11,7 @@ import { ValueCell } from 'mol-util/value-cell'
import { RenderObject, createMeshRenderObject, MeshRenderObject } from 'mol-gl/render-object'
import { Unit, Link } from 'mol-model/structure';
import { UnitsRepresentation, DefaultStructureProps } from './index';
import { UnitsVisual, DefaultStructureProps } from './index';
import { RuntimeContext } from 'mol-task'
import { createTransforms } from './utils';
import { fillSerial } from 'mol-gl/renderable/util';
......@@ -78,7 +78,7 @@ export const DefaultBondProps = {
}
export type BondProps = Partial<typeof DefaultBondProps>
export default function IntraUnitBonds(): UnitsRepresentation<BondProps> {
export default function IntraUnitBonds(): UnitsVisual<BondProps> {
const renderObjects: RenderObject[] = []
let cylinders: MeshRenderObject
let currentProps: typeof DefaultBondProps
......
......@@ -14,8 +14,8 @@ import { PickingId } from '../../util/picking';
import { Loci, EmptyLoci, isEmptyLoci } from 'mol-model/loci';
import { MarkerAction } from '../../util/marker-data';
export interface UnitsRepresentation<P> {
renderObjects: ReadonlyArray<RenderObject>
export interface UnitsVisual<P> {
readonly renderObjects: ReadonlyArray<RenderObject>
create: (ctx: RuntimeContext, group: Unit.SymmetryGroup, props: P) => Promise<void>
update: (ctx: RuntimeContext, props: P) => Promise<boolean>
getLoci: (pickingId: PickingId) => Loci
......@@ -24,9 +24,9 @@ export interface UnitsRepresentation<P> {
export interface StructureRepresentation<P extends RepresentationProps = {}> extends Representation<Structure, P> { }
interface GroupRepresentation<T> {
repr: UnitsRepresentation<T>
group: Unit.SymmetryGroup
interface GroupVisual<T> {
readonly visual: UnitsVisual<T>
readonly group: Unit.SymmetryGroup
}
export const DefaultStructureProps = {
......@@ -39,19 +39,11 @@ export const DefaultStructureProps = {
}
export type StructureProps = Partial<typeof DefaultStructureProps>
export function StructureRepresentation<P extends StructureProps>(reprCtor: () => UnitsRepresentation<P>): StructureRepresentation<P> {
export function StructureRepresentation<P extends StructureProps>(visualCtor: () => UnitsVisual<P>): StructureRepresentation<P> {
const renderObjects: RenderObject[] = []
const groupReprs: GroupRepresentation<P>[] = []
const groupVisuals: GroupVisual<P>[] = []
// let currentProps: typeof DefaultStructureProps
function getLoci(pickingId: PickingId) {
for (let i = 0, il = groupReprs.length; i < il; ++i) {
const loc = groupReprs[i].repr.getLoci(pickingId)
if (!isEmptyLoci(loc)) return loc
}
return EmptyLoci
}
return {
renderObjects,
create(structure: Structure, props: P = {} as P) {
......@@ -65,15 +57,15 @@ export function StructureRepresentation<P extends StructureProps>(reprCtor: () =
const groups = StructureSymmetry.getTransformGroups(structure);
for (let i = 0; i < groups.length; i++) {
if(ctx.shouldUpdate) await ctx.update({
message: 'Building structure unit representations...',
message: 'Building structure unit visuals...',
current: i,
max: groups.length
})
const group = groups[i];
const repr = reprCtor()
groupReprs.push({ repr, group })
await repr.create(ctx, group, props)
renderObjects.push(...repr.renderObjects)
const visual = visualCtor()
groupVisuals.push({ visual, group })
await visual.create(ctx, group, props)
renderObjects.push(...visual.renderObjects)
}
});
},
......@@ -81,27 +73,33 @@ export function StructureRepresentation<P extends StructureProps>(reprCtor: () =
return Task.create('StructureRepresentation.update', async ctx => {
renderObjects.length = 0 // clear
for (let i = 0, il = groupReprs.length; i < il; ++i) {
for (let i = 0, il = groupVisuals.length; i < il; ++i) {
if(ctx.shouldUpdate) await ctx.update({
message: 'Updating structure unit representations...',
message: 'Updating structure unit visuals...',
current: i,
max: il
})
const groupRepr = groupReprs[i]
const { repr, group } = groupRepr
const groupVisual = groupVisuals[i]
const { visual, group } = groupVisual
if (!await repr.update(ctx, props)) {
if (!await visual.update(ctx, props)) {
console.log('update failed, need to rebuild')
repr.create(ctx, group, props)
visual.create(ctx, group, props)
}
renderObjects.push(...repr.renderObjects)
renderObjects.push(...visual.renderObjects)
}
})
},
getLoci,
getLoci(pickingId: PickingId) {
for (let i = 0, il = groupVisuals.length; i < il; ++i) {
const loc = groupVisuals[i].visual.getLoci(pickingId)
if (!isEmptyLoci(loc)) return loc
}
return EmptyLoci
},
mark(loci: Loci, action: MarkerAction) {
for (let i = 0, il = groupReprs.length; i < il; ++i) {
groupReprs[i].repr.mark(loci, action)
for (let i = 0, il = groupVisuals.length; i < il; ++i) {
groupVisuals[i].visual.mark(loci, action)
}
}
}
......
......@@ -11,7 +11,7 @@ import { Unit, Element } from 'mol-model/structure';
import { RuntimeContext } from 'mol-task'
import { fillSerial } from 'mol-gl/renderable/util';
import { UnitsRepresentation, DefaultStructureProps } from './index';
import { UnitsVisual, DefaultStructureProps } from './index';
import VertexMap from '../../shape/vertex-map';
import { SizeTheme } from '../../theme';
import { createTransforms, createColors, createSizes, markElement } from './utils';
......@@ -47,7 +47,7 @@ export function createPointVertices(unit: Unit) {
return vertices
}
export default function PointUnitsRepresentation(): UnitsRepresentation<PointProps> {
export default function PointUnitsRepresentation(): UnitsVisual<PointProps> {
const renderObjects: RenderObject[] = []
let points: PointRenderObject
let currentProps = DefaultPointProps
......
......@@ -9,7 +9,7 @@ import { ValueCell } from 'mol-util/value-cell'
import { RenderObject, createMeshRenderObject, MeshRenderObject } from 'mol-gl/render-object'
import { Unit, Element, Queries } from 'mol-model/structure';
import { UnitsRepresentation, DefaultStructureProps } from './index';
import { UnitsVisual, DefaultStructureProps } from './index';
import { RuntimeContext } from 'mol-task'
import { createTransforms, createColors, createSphereMesh, markElement } from './utils';
import VertexMap from '../../shape/vertex-map';
......@@ -44,7 +44,7 @@ export const DefaultSpacefillProps = {
}
export type SpacefillProps = Partial<typeof DefaultSpacefillProps>
export default function SpacefillUnitsRepresentation(): UnitsRepresentation<SpacefillProps> {
export default function SpacefillUnitsRepresentation(): UnitsVisual<SpacefillProps> {
const renderObjects: RenderObject[] = []
let spheres: MeshRenderObject
let currentProps: typeof DefaultSpacefillProps
......
......@@ -12,8 +12,8 @@ import { PickingId } from '../../util/picking';
import { Loci, EmptyLoci } from 'mol-model/loci';
import { MarkerAction } from '../../util/marker-data';
export interface VolumeElementRepresentation<P> {
renderObjects: ReadonlyArray<RenderObject>
export interface VolumeVisual<P> {
readonly renderObjects: ReadonlyArray<RenderObject>
create: (ctx: RuntimeContext, volumeData: VolumeData, props: P) => Promise<void>
update: (ctx: RuntimeContext, props: P) => Promise<boolean>
getLoci: (pickingId: PickingId) => Loci
......@@ -22,16 +22,16 @@ export interface VolumeElementRepresentation<P> {
export interface VolumeRepresentation<P extends RepresentationProps = {}> extends Representation<VolumeData, P> { }
export function VolumeRepresentation<P>(reprCtor: () => VolumeElementRepresentation<P>): VolumeRepresentation<P> {
export function VolumeRepresentation<P>(visualCtor: () => VolumeVisual<P>): VolumeRepresentation<P> {
const renderObjects: RenderObject[] = []
return {
renderObjects,
create(volumeData: VolumeData, props: P = {} as P) {
return Task.create('VolumeRepresentation.create', async ctx => {
const repr = reprCtor()
await repr.create(ctx, volumeData, props)
renderObjects.push(...repr.renderObjects)
const visual = visualCtor()
await visual.create(ctx, volumeData, props)
renderObjects.push(...visual.renderObjects)
});
},
update(props: P) {
......
......@@ -9,7 +9,7 @@ import { VolumeData, VolumeIsoValue } from 'mol-model/volume'
import { Task, RuntimeContext } from 'mol-task'
import { computeMarchingCubes } from '../../util/marching-cubes/algorithm';
import { Mesh } from '../../shape/mesh';
import { VolumeElementRepresentation } from '.';
import { VolumeVisual } from '.';
import { RenderObject, createMeshRenderObject, MeshRenderObject } from 'mol-gl/render-object';
import { fillSerial } from 'mol-gl/renderable/util';
import { ValueCell, defaults } from 'mol-util';
......@@ -50,7 +50,7 @@ export const DefaultSurfaceProps = {
}
export type SurfaceProps = Partial<typeof DefaultSurfaceProps>
export default function Surface(): VolumeElementRepresentation<SurfaceProps> {
export default function Surface(): VolumeVisual<SurfaceProps> {
const renderObjects: RenderObject[] = []
let surface: MeshRenderObject
let curProps = DefaultSurfaceProps
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment