diff --git a/src/mol-io/reader/ply/parser.ts b/src/mol-io/reader/ply/parser.ts index 27e33c2b9dc326d428c3513a54c5cf281fe7839b..bd9ce4f2d044a9e0cf62efe7c5f06c87d4258658 100644 --- a/src/mol-io/reader/ply/parser.ts +++ b/src/mol-io/reader/ply/parser.ts @@ -154,6 +154,7 @@ function parseTableElement(state: State, spec: TableElementSpec) { const { count, properties } = spec const propertyCount = properties.length const propertyNames: string[] = [] + const propertyTypes: PlyType[] = [] const propertyTokens: Tokens[] = [] const propertyColumns = new Map<string, Column<number>>() @@ -175,6 +176,7 @@ function parseTableElement(state: State, spec: TableElementSpec) { const { type, name } = properties[i] const column = TokenColumn(propertyTokens[i], getColumnSchema(type)) propertyNames.push(name) + propertyTypes.push(type) propertyColumns.set(name, column) } @@ -182,6 +184,7 @@ function parseTableElement(state: State, spec: TableElementSpec) { kind: 'table', rowCount: count, propertyNames, + propertyTypes, getProperty: (name: string) => propertyColumns.get(name) }) } @@ -225,6 +228,7 @@ function parseListElement(state: State, spec: ListElementSpec) { kind: 'list', rowCount: count, name: property.name, + type: property.dataType, value: (row: number) => { const start = offsets[row] const end = offsets[row + 1] diff --git a/src/mol-io/reader/ply/schema.ts b/src/mol-io/reader/ply/schema.ts index bf23fbb703a9cf64a1249ea4085f79a0c424ff90..c5fbcb995ae825d0ea7f829ffd3ea96bca73f715 100644 --- a/src/mol-io/reader/ply/schema.ts +++ b/src/mol-io/reader/ply/schema.ts @@ -61,6 +61,7 @@ export interface PlyTable { readonly kind: 'table' readonly rowCount: number readonly propertyNames: ReadonlyArray<string> + readonly propertyTypes: ReadonlyArray<PlyType> getProperty(name: string): Column<number> | undefined } @@ -73,5 +74,6 @@ export interface PlyList { readonly kind: 'list' readonly rowCount: number, readonly name: string, + readonly type: PlyType, value: (row: number) => PlyListValue } \ No newline at end of file diff --git a/src/mol-model-formats/shape/ply.ts b/src/mol-model-formats/shape/ply.ts index c8c2d9420a2904031582911be3e0e5c290211368..77de7d07da12d0889df69f7b5703832e0e534a83 100644 --- a/src/mol-model-formats/shape/ply.ts +++ b/src/mol-model-formats/shape/ply.ts @@ -22,12 +22,19 @@ import { deepClone } from 'mol-util/object'; // TODO support 'edge' and 'material' elements, see https://www.mathworks.com/help/vision/ug/the-ply-format.html function createPlyShapeParams(vertex?: PlyTable) { - const options: [string, string][] = [['', '']] + const groupOptions: [string, string][] = [['', '']] + const colorOptions: [string, string][] = [['', '']] const defaultValues = { group: '', red: '', green: '', blue: '' } if (vertex) { for (let i = 0, il = vertex.propertyNames.length; i < il; ++i) { const name = vertex.propertyNames[i] - options.push([ name, name ]) + const type = vertex.propertyTypes[i] + if ( + type === 'uchar' || type === 'uint8' || + type === 'ushort' || type === 'uint16' || + type === 'uint' || type === 'uint32' + ) groupOptions.push([ name, name ]) + if (type === 'uchar' || type === 'uint8') colorOptions.push([ name, name ]) } // TODO hardcoded as convenience for data provided by MegaMol @@ -43,9 +50,9 @@ function createPlyShapeParams(vertex?: PlyTable) { coloring: PD.MappedStatic(defaultValues.red && defaultValues.green && defaultValues.blue ? 'vertex' : 'uniform', { vertex: PD.Group({ - red: PD.Select(defaultValues.red, options, { label: 'Red Property' }), - green: PD.Select(defaultValues.green, options, { label: 'Green Property' }), - blue: PD.Select(defaultValues.blue, options, { label: 'Blue Property' }), + red: PD.Select(defaultValues.red, colorOptions, { label: 'Red Property' }), + green: PD.Select(defaultValues.green, colorOptions, { label: 'Green Property' }), + blue: PD.Select(defaultValues.blue, colorOptions, { label: 'Blue Property' }), }, { isFlat: true }), uniform: PD.Group({ color: PD.Color(ColorNames.grey) @@ -53,7 +60,7 @@ function createPlyShapeParams(vertex?: PlyTable) { }), grouping: PD.MappedStatic(defaultValues.group ? 'vertex' : 'none', { vertex: PD.Group({ - group: PD.Select(defaultValues.group, options, { label: 'Group Property' }), + group: PD.Select(defaultValues.group, groupOptions, { label: 'Group Property' }), }, { isFlat: true }), none: PD.Group({ }) }),