From 043e23a137c9324dea49679e8bdb13de11c3add0 Mon Sep 17 00:00:00 2001 From: Alexander Rose <alex.rose@rcsb.org> Date: Wed, 20 Mar 2019 17:06:37 -0700 Subject: [PATCH] added shape.sourceData --- src/mol-model-formats/shape/ply.ts | 2 +- src/mol-model/shape/shape.ts | 5 ++++- src/mol-plugin/behavior/dynamic/labels.ts | 2 +- src/mol-plugin/util/structure-labels.ts | 2 +- src/tests/browser/render-shape.ts | 7 ++----- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/mol-model-formats/shape/ply.ts b/src/mol-model-formats/shape/ply.ts index 2b80c8230..61add2ae6 100644 --- a/src/mol-model-formats/shape/ply.ts +++ b/src/mol-model-formats/shape/ply.ts @@ -67,7 +67,7 @@ async function getShape(ctx: RuntimeContext, plyFile: PlyFile, props: {}, shape? const mesh = await getPlyMesh(ctx, vertex, face, shape && shape.geometry) return shape || Shape.create( - 'test', mesh, + 'test', plyFile, mesh, (groupId: number) => { return Color.fromRgb(red.value(groupId), green.value(groupId), blue.value(groupId)) }, diff --git a/src/mol-model/shape/shape.ts b/src/mol-model/shape/shape.ts index 98188c58e..0d740ef14 100644 --- a/src/mol-model/shape/shape.ts +++ b/src/mol-model/shape/shape.ts @@ -15,6 +15,8 @@ export interface Shape<G extends Geometry = Geometry> { readonly id: UUID /** A name to describe the shape */ readonly name: string + /** The data used to create the shape */ + readonly sourceData: unknown /** The geometry of the shape, e.g. `Mesh` or `Lines` */ readonly geometry: G /** An array of transformation matrices to describe multiple instances of the geometry */ @@ -30,10 +32,11 @@ export interface Shape<G extends Geometry = Geometry> { } export namespace Shape { - export function create<G extends Geometry>(name: string, geometry: G, getColor: Shape['getColor'], getSize: Shape['getSize'], getLabel: Shape['getLabel'], transforms?: Mat4[]): Shape<G> { + export function create<G extends Geometry>(name: string, sourceData: unknown, geometry: G, getColor: Shape['getColor'], getSize: Shape['getSize'], getLabel: Shape['getLabel'], transforms?: Mat4[]): Shape<G> { return { id: UUID.create22(), name, + sourceData, geometry, transforms: transforms || [Mat4.identity()], get groupCount() { return Geometry.getGroupCount(geometry) }, diff --git a/src/mol-plugin/behavior/dynamic/labels.ts b/src/mol-plugin/behavior/dynamic/labels.ts index be5465150..16b43e187 100644 --- a/src/mol-plugin/behavior/dynamic/labels.ts +++ b/src/mol-plugin/behavior/dynamic/labels.ts @@ -107,7 +107,7 @@ export const SceneLabels = PluginBehavior.create<SceneLabelsProps>({ private getLabelsShape = (ctx: RuntimeContext, data: LabelsData, props: SceneLabelsProps, shape?: Shape<Text>) => { this.geo = getLabelsText(data, props, this.geo) - return Shape.create('Scene Labels', this.geo, this.getColor, this.getSize, this.getLabel, data.transforms) + return Shape.create('Scene Labels', data, this.geo, this.getColor, this.getSize, this.getLabel, data.transforms) } /** Update structures to be labeled, returns true if changed */ diff --git a/src/mol-plugin/util/structure-labels.ts b/src/mol-plugin/util/structure-labels.ts index c6e944b29..932569da9 100644 --- a/src/mol-plugin/util/structure-labels.ts +++ b/src/mol-plugin/util/structure-labels.ts @@ -44,7 +44,7 @@ export async function getLabelRepresentation(ctx: RuntimeContext, structure: Str function getLabelsShape(ctx: RuntimeContext, data: LabelsData, props: PD.Values<Text.Params>, shape?: Shape<Text>) { const geo = getLabelsText(data, props, shape && shape.geometry); - return Shape.create('Scene Labels', geo, () => ColorNames.dimgrey, g => data.sizes[g], () => '') + return Shape.create('Scene Labels', data, geo, () => ColorNames.dimgrey, g => data.sizes[g], () => '') } const boundaryHelper = new BoundaryHelper(); diff --git a/src/tests/browser/render-shape.ts b/src/tests/browser/render-shape.ts index 6b234dd81..1f5f39ec7 100644 --- a/src/tests/browser/render-shape.ts +++ b/src/tests/browser/render-shape.ts @@ -19,9 +19,6 @@ import { Representation } from 'mol-repr/representation'; import { MarkerAction } from 'mol-geo/geometry/marker-data'; import { EveryLoci } from 'mol-model/loci'; - - - const parent = document.getElementById('app')! parent.style.width = '100%' parent.style.height = '100%' @@ -85,7 +82,7 @@ async function getSphereMesh(ctx: RuntimeContext, centers: number[], mesh?: Mesh const myData = { centers: [0, 0, 0, 0, 3, 0, 1, 0 , 4], - colors: [ColorNames.tomato, ColorNames.springgreen,ColorNames.springgreen], + colors: [ColorNames.tomato, ColorNames.springgreen, ColorNames.springgreen], labels: ['Sphere 0, Instance A', 'Sphere 1, Instance A', 'Sphere 0, Instance B', 'Sphere 1, Instance B'], transforms: [Mat4.identity(), Mat4.fromTranslation(Mat4.zero(), Vec3.create(3, 0, 0))] } @@ -100,7 +97,7 @@ async function getShape(ctx: RuntimeContext, data: MyData, props: {}, shape?: Sh const mesh = await getSphereMesh(ctx, centers, shape && shape.geometry) const groupCount = centers.length / 3 return shape || Shape.create( - 'test', mesh, + 'test', data, mesh, (groupId: number) => colors[groupId], // color: per group, same for instances () => 1, // size: constant (groupId: number, instanceId: number) => labels[instanceId * groupCount + groupId], // label: per group and instance -- GitLab