Select Git revision
index.ts 5.07 KiB
/**
* Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author Alexander Rose <alexander.rose@weirdbyte.de>
*/
import { Task } from 'mol-task'
import { RenderObject, createMeshRenderObject, MeshRenderObject } from 'mol-gl/render-object';
import { RepresentationProps, Representation } from '..';
import { PickingId } from '../../util/picking';
import { Loci, EmptyLoci, isEveryLoci } from 'mol-model/loci';
import { MarkerAction, applyMarkerAction, createMarkers } from '../../util/marker-data';
import { createRenderableState, createMeshValues, createIdentityTransform, DefaultMeshProps } from '../util';
import { getMeshData } from '../../util/mesh-data';
import { MeshValues } from 'mol-gl/renderable';
import { ValueCell } from 'mol-util';
import { ColorThemeProps } from 'mol-view/theme/color';
import { Shape } from 'mol-model/shape';
import { LocationIterator } from '../../util/location-iterator';
import { createColors } from '../structure/visual/util/common';
import { OrderedSet, Interval } from 'mol-data/int';
export interface ShapeRepresentation<P extends RepresentationProps = {}> extends Representation<Shape, P> { }
export const DefaultShapeProps = {
...DefaultMeshProps,
colorTheme: { name: 'shape-group' } as ColorThemeProps
}
export type ShapeProps = typeof DefaultShapeProps
// TODO
// export type ShapeRepresentation = ShapeRepresentation<ShapeProps>
export function ShapeRepresentation<P extends ShapeProps>(): ShapeRepresentation<P> {
const renderObjects: RenderObject[] = []
let _renderObject: MeshRenderObject | undefined
let _shape: Shape
let _props: P
function create(shape: Shape, props: Partial<P> = {}) {
_props = Object.assign({}, DefaultShapeProps, _props, props)
_shape = shape
return Task.create('ShapeRepresentation.create', async ctx => {
renderObjects.length = 0
const mesh = shape.mesh
const locationIt = ShapeGroupIterator.fromShape(shape)
const { groupCount, instanceCount } = locationIt
const color = createColors(locationIt, _props.colorTheme)
const marker = createMarkers(instanceCount * groupCount)
const counts = { drawCount: mesh.triangleCount * 3, groupCount, instanceCount }
const values: MeshValues = {
...getMeshData(mesh),
...createMeshValues(_props, counts),
aTransform: createIdentityTransform(),
...color,
...marker,
elements: mesh.indexBuffer,
}
const state = createRenderableState(_props)
_renderObject = createMeshRenderObject(values, state)
renderObjects.push(_renderObject)
});
}