Browse Source

added shape.sourceData

Alexander Rose 6 years ago
parent
commit
043e23a137

+ 1 - 1
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))
         },

+ 4 - 1
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) },

+ 1 - 1
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 */

+ 1 - 1
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();

+ 2 - 5
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