|
@@ -10,62 +10,56 @@ import { createRenderObject, RenderObject } from 'mol-gl/renderer'
|
|
import { createColorTexture } from 'mol-gl/util';
|
|
import { createColorTexture } from 'mol-gl/util';
|
|
import { Vec3, Mat4 } from 'mol-math/linear-algebra'
|
|
import { Vec3, Mat4 } from 'mol-math/linear-algebra'
|
|
import { OrderedSet } from 'mol-data/int'
|
|
import { OrderedSet } from 'mol-data/int'
|
|
-import { Element, Unit, ElementSet } from 'mol-model/structure';
|
|
|
|
-import P from 'mol-model/structure/query/properties';
|
|
|
|
-import { RepresentationProps, UnitRepresentation } from './index';
|
|
|
|
|
|
+import { Unit, ElementGroup } from 'mol-model/structure';
|
|
|
|
+import { RepresentationProps, UnitsRepresentation } from './index';
|
|
import { Task } from 'mol-task'
|
|
import { Task } from 'mol-task'
|
|
import { MeshBuilder } from '../../shape/mesh-builder';
|
|
import { MeshBuilder } from '../../shape/mesh-builder';
|
|
|
|
+import { VdwRadius } from 'mol-model/structure/model/properties/atomic';
|
|
|
|
|
|
-export default function Spacefill(): UnitRepresentation {
|
|
|
|
- const renderObjects: RenderObject[] = []
|
|
|
|
|
|
+export const DefaultSpacefillProps = {
|
|
|
|
+
|
|
|
|
+}
|
|
|
|
+export type SpacefillProps = Partial<typeof DefaultSpacefillProps>
|
|
|
|
|
|
- // unit: Unit, atomGroup: AtomGroup
|
|
|
|
|
|
+export default function Spacefill(): UnitsRepresentation<SpacefillProps> {
|
|
|
|
+ const renderObjects: RenderObject[] = []
|
|
|
|
|
|
return {
|
|
return {
|
|
- create: (units: ReadonlyArray<Unit>, elements: ElementSet, props: Partial<RepresentationProps> = {}) => Task.create('Spacefill', async ctx => {
|
|
|
|
- const l = Element.Location();
|
|
|
|
|
|
+ renderObjects,
|
|
|
|
+ create: (units: ReadonlyArray<Unit>, elementGroup: ElementGroup, props: SpacefillProps = {}) => Task.create('Spacefill', async ctx => {
|
|
const meshBuilder = MeshBuilder.create()
|
|
const meshBuilder = MeshBuilder.create()
|
|
|
|
|
|
- const unitIds = ElementSet.unitIds(elements);
|
|
|
|
- for (let i = 0, _i = unitIds.length; i < _i; i++) {
|
|
|
|
- const unitId = unitIds[i];
|
|
|
|
- const unit = units[unitId];
|
|
|
|
- const elementGroup = ElementSet.unitGetByIndex(elements, i);
|
|
|
|
-
|
|
|
|
- const elementCount = OrderedSet.size(elementGroup.elements)
|
|
|
|
-
|
|
|
|
- l.unit = unit;
|
|
|
|
|
|
+ const v = Vec3.zero()
|
|
|
|
+ const m = Mat4.identity()
|
|
|
|
|
|
- const v = Vec3.zero()
|
|
|
|
- const m = Mat4.identity()
|
|
|
|
|
|
+ const { x, y, z } = units[0].model.conformation
|
|
|
|
+ const { type_symbol } = units[0].model.hierarchy.atoms
|
|
|
|
+ const elementCount = OrderedSet.size(elementGroup.elements)
|
|
|
|
+ for (let i = 0; i < elementCount; i++) {
|
|
|
|
+ const e = OrderedSet.getAt(elementGroup.elements, i)
|
|
|
|
+ v[0] = x[e]
|
|
|
|
+ v[1] = y[e]
|
|
|
|
+ v[2] = z[e]
|
|
|
|
+ Mat4.setTranslation(m, v)
|
|
|
|
|
|
- for (let i = 0; i < elementCount; i++) {
|
|
|
|
- l.element = OrderedSet.getAt(elementGroup.elements, i)
|
|
|
|
-
|
|
|
|
- v[0] = P.atom.x(l)
|
|
|
|
- v[1] = P.atom.y(l)
|
|
|
|
- v[2] = P.atom.z(l)
|
|
|
|
- Mat4.setTranslation(m, v)
|
|
|
|
-
|
|
|
|
- meshBuilder.addIcosahedron(m, { radius: P.atom.vdw(l), detail: 1 })
|
|
|
|
- }
|
|
|
|
|
|
+ meshBuilder.addIcosahedron(m, { radius: VdwRadius(type_symbol.value(e)), detail: 0 })
|
|
|
|
|
|
if (i % 10 === 0 && ctx.shouldUpdate) {
|
|
if (i % 10 === 0 && ctx.shouldUpdate) {
|
|
- await ctx.update({ message: 'Spacefill', current: i, max: _i });
|
|
|
|
|
|
+ await ctx.update({ message: 'Spacefill', current: i, max: elementCount });
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- const transformArray = new Float32Array(32)
|
|
|
|
- const m4 = Mat4.identity()
|
|
|
|
- Mat4.toArray(m4, transformArray, 0)
|
|
|
|
|
|
+ const unitsCount = units.length
|
|
|
|
+ const transformArray = new Float32Array(unitsCount * 16)
|
|
|
|
+ for (let i = 0; i < unitsCount; i++) {
|
|
|
|
+ Mat4.toArray(units[i].operator.matrix, transformArray, i * 16)
|
|
|
|
+ }
|
|
|
|
|
|
- const color = ValueCell.create(createColorTexture(1))
|
|
|
|
|
|
+ const color = ValueCell.create(createColorTexture(unitsCount))
|
|
color.ref.value.set([ 0, 0, 255 ])
|
|
color.ref.value.set([ 0, 0, 255 ])
|
|
|
|
|
|
const mesh = meshBuilder.getMesh()
|
|
const mesh = meshBuilder.getMesh()
|
|
|
|
|
|
- // console.log(mesh)
|
|
|
|
-
|
|
|
|
const spheres = createRenderObject('mesh', {
|
|
const spheres = createRenderObject('mesh', {
|
|
position: mesh.vertexBuffer,
|
|
position: mesh.vertexBuffer,
|
|
normal: mesh.normalBuffer,
|
|
normal: mesh.normalBuffer,
|
|
@@ -73,13 +67,11 @@ export default function Spacefill(): UnitRepresentation {
|
|
transform: ValueCell.create(transformArray),
|
|
transform: ValueCell.create(transformArray),
|
|
elements: mesh.indexBuffer,
|
|
elements: mesh.indexBuffer,
|
|
|
|
|
|
- instanceCount: transformArray.length / 16,
|
|
|
|
|
|
+ instanceCount: unitsCount,
|
|
elementCount: mesh.triangleCount,
|
|
elementCount: mesh.triangleCount,
|
|
positionCount: mesh.vertexCount
|
|
positionCount: mesh.vertexCount
|
|
}, {})
|
|
}, {})
|
|
renderObjects.push(spheres)
|
|
renderObjects.push(spheres)
|
|
-
|
|
|
|
- return renderObjects
|
|
|
|
}),
|
|
}),
|
|
update: (props: RepresentationProps) => false
|
|
update: (props: RepresentationProps) => false
|
|
}
|
|
}
|