diff --git a/src/mol-model-formats/shape/ply.ts b/src/mol-model-formats/shape/ply.ts index 2b80c8230745a210cde528c5fb4455d22d111e45..61add2ae67fecf902d94435ba2b56405cba34758 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 98188c58e360606021be9fa5ae25eb9e8421eeef..0d740ef14a47a24fab8dbb37f0a5c994c466645e 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 be54651502d57168464b9a568c7a69eb7043cec6..16b43e187b7f1b41e48ea825119088240df1e457 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 c6e944b29219ac96fed56f47556ad3885780ea36..932569da9046774aca3952c380c7174f7d9f31ca 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 6b234dd81375cdc326d3872b3da355361c131ed2..1f5f39ec7da99640c4fd670a8fc6a05c2163a044 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