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

added shape.sourceData

parent f4d019ac
No related branches found
No related tags found
No related merge requests found
...@@ -67,7 +67,7 @@ async function getShape(ctx: RuntimeContext, plyFile: PlyFile, props: {}, shape? ...@@ -67,7 +67,7 @@ async function getShape(ctx: RuntimeContext, plyFile: PlyFile, props: {}, shape?
const mesh = await getPlyMesh(ctx, vertex, face, shape && shape.geometry) const mesh = await getPlyMesh(ctx, vertex, face, shape && shape.geometry)
return shape || Shape.create( return shape || Shape.create(
'test', mesh, 'test', plyFile, mesh,
(groupId: number) => { (groupId: number) => {
return Color.fromRgb(red.value(groupId), green.value(groupId), blue.value(groupId)) return Color.fromRgb(red.value(groupId), green.value(groupId), blue.value(groupId))
}, },
......
...@@ -15,6 +15,8 @@ export interface Shape<G extends Geometry = Geometry> { ...@@ -15,6 +15,8 @@ export interface Shape<G extends Geometry = Geometry> {
readonly id: UUID readonly id: UUID
/** A name to describe the shape */ /** A name to describe the shape */
readonly name: string readonly name: string
/** The data used to create the shape */
readonly sourceData: unknown
/** The geometry of the shape, e.g. `Mesh` or `Lines` */ /** The geometry of the shape, e.g. `Mesh` or `Lines` */
readonly geometry: G readonly geometry: G
/** An array of transformation matrices to describe multiple instances of the geometry */ /** An array of transformation matrices to describe multiple instances of the geometry */
...@@ -30,10 +32,11 @@ export interface Shape<G extends Geometry = Geometry> { ...@@ -30,10 +32,11 @@ export interface Shape<G extends Geometry = Geometry> {
} }
export namespace Shape { 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 { return {
id: UUID.create22(), id: UUID.create22(),
name, name,
sourceData,
geometry, geometry,
transforms: transforms || [Mat4.identity()], transforms: transforms || [Mat4.identity()],
get groupCount() { return Geometry.getGroupCount(geometry) }, get groupCount() { return Geometry.getGroupCount(geometry) },
......
...@@ -107,7 +107,7 @@ export const SceneLabels = PluginBehavior.create<SceneLabelsProps>({ ...@@ -107,7 +107,7 @@ export const SceneLabels = PluginBehavior.create<SceneLabelsProps>({
private getLabelsShape = (ctx: RuntimeContext, data: LabelsData, props: SceneLabelsProps, shape?: Shape<Text>) => { private getLabelsShape = (ctx: RuntimeContext, data: LabelsData, props: SceneLabelsProps, shape?: Shape<Text>) => {
this.geo = getLabelsText(data, props, this.geo) 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 */ /** Update structures to be labeled, returns true if changed */
......
...@@ -44,7 +44,7 @@ export async function getLabelRepresentation(ctx: RuntimeContext, structure: Str ...@@ -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>) { function getLabelsShape(ctx: RuntimeContext, data: LabelsData, props: PD.Values<Text.Params>, shape?: Shape<Text>) {
const geo = getLabelsText(data, props, shape && shape.geometry); 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(); const boundaryHelper = new BoundaryHelper();
......
...@@ -19,9 +19,6 @@ import { Representation } from 'mol-repr/representation'; ...@@ -19,9 +19,6 @@ import { Representation } from 'mol-repr/representation';
import { MarkerAction } from 'mol-geo/geometry/marker-data'; import { MarkerAction } from 'mol-geo/geometry/marker-data';
import { EveryLoci } from 'mol-model/loci'; import { EveryLoci } from 'mol-model/loci';
const parent = document.getElementById('app')! const parent = document.getElementById('app')!
parent.style.width = '100%' parent.style.width = '100%'
parent.style.height = '100%' parent.style.height = '100%'
...@@ -85,7 +82,7 @@ async function getSphereMesh(ctx: RuntimeContext, centers: number[], mesh?: Mesh ...@@ -85,7 +82,7 @@ async function getSphereMesh(ctx: RuntimeContext, centers: number[], mesh?: Mesh
const myData = { const myData = {
centers: [0, 0, 0, 0, 3, 0, 1, 0 , 4], 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'], 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))] 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 ...@@ -100,7 +97,7 @@ async function getShape(ctx: RuntimeContext, data: MyData, props: {}, shape?: Sh
const mesh = await getSphereMesh(ctx, centers, shape && shape.geometry) const mesh = await getSphereMesh(ctx, centers, shape && shape.geometry)
const groupCount = centers.length / 3 const groupCount = centers.length / 3
return shape || Shape.create( return shape || Shape.create(
'test', mesh, 'test', data, mesh,
(groupId: number) => colors[groupId], // color: per group, same for instances (groupId: number) => colors[groupId], // color: per group, same for instances
() => 1, // size: constant () => 1, // size: constant
(groupId: number, instanceId: number) => labels[instanceId * groupCount + groupId], // label: per group and instance (groupId: number, instanceId: number) => labels[instanceId * groupCount + groupId], // label: per group and instance
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment