Browse Source

wip, point repr

Alexander Rose 7 years ago
parent
commit
eea59e9e75
2 changed files with 84 additions and 16 deletions
  1. 17 16
      src/apps/render-test/state.ts
  2. 67 0
      src/mol-geo/representation/structure/point.ts

+ 17 - 16
src/apps/render-test/state.ts

@@ -12,14 +12,20 @@ import { createColorTexture } from 'mol-gl/util';
 import Icosahedron from 'mol-geo/primitive/icosahedron'
 import Box from 'mol-geo/primitive/box'
 import Spacefill from 'mol-geo/representation/structure/spacefill'
+import Point from 'mol-geo/representation/structure/point'
 
 import CIF from 'mol-io/reader/cif'
 import { Run, Progress } from 'mol-task'
-import { ElementSet, Structure } from 'mol-model/structure'
+import { Structure } from 'mol-model/structure'
+
+function log(progress: Progress) {
+    const p = progress.root.progress
+    console.log(`${p.message} ${(p.current/p.max*100).toFixed(2)}%`)
+}
 
 async function parseCif(data: string|Uint8Array) {
     const comp = CIF.parse(data)
-    const parsed = await Run(comp);
+    const parsed = await Run(comp, log, 100);
     if (parsed.isError) throw parsed;
     return parsed
 }
@@ -117,21 +123,16 @@ export default class State {
         const mesh2 = makeCubesMesh();
         renderer.add(mesh2)
 
-        function log(progress: Progress) {
-            const p = progress.root.progress
-            console.log(`${p.message} ${(p.current/p.max*100).toFixed(2)}%`)
-        }
+        const structures = await getPdb('4v99')
+        const { elements, units } = structures[0];
 
-        async function createSpacefills (structure: Structure) {
-            const spacefills: RenderObject[] = []
-            const { elements, units } = structure;
-            const spacefill = Spacefill()
-            spacefills.push(...await Run(spacefill.create(units, elements), log, 100))
-            return spacefills
-        }
-        const structures = await getPdb('3pqr')
-        const spacefills = await createSpacefills(structures[0])
-        spacefills.forEach(renderer.add)
+        // const spacefill = Spacefill()
+        // const spacefills = await Run(spacefill.create(units, elements), log, 100)
+        // spacefills.forEach(renderer.add)
+
+        const point = Point()
+        const points = await Run(point.create(units, elements), log, 100)
+        points.forEach(renderer.add)
 
         renderer.frame()
     }

+ 67 - 0
src/mol-geo/representation/structure/point.ts

@@ -0,0 +1,67 @@
+/**
+ * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
+ *
+ * @author Alexander Rose <alexander.rose@weirdbyte.de>
+ */
+
+import { ValueCell } from 'mol-util/value-cell'
+
+import { createRenderObject, RenderObject } from 'mol-gl/renderer'
+import { createColorTexture } from 'mol-gl/util';
+import { Mat4 } from 'mol-math/linear-algebra'
+import { OrderedSet } from 'mol-data/int'
+import { ChunkedArray } from 'mol-data/util';
+import { Element, Unit, ElementSet } from 'mol-model/structure';
+import P from 'mol-model/structure/query/properties';
+import { RepresentationProps, UnitRepresentation } from './index';
+import { Task } from 'mol-task'
+
+
+export default function Point(): UnitRepresentation {
+    const renderObjects: RenderObject[] = []
+    const vertices = ChunkedArray.create(Float32Array, 3, 1024, 2048);
+
+    return {
+        create: (units: ReadonlyArray<Unit>, elements: ElementSet, props: Partial<RepresentationProps> = {}) => Task.create('Spacefill', async ctx => {
+            const l = Element.Location();
+
+            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;
+
+                for (let i = 0; i < elementCount; i++) {
+                    l.element = OrderedSet.getAt(elementGroup.elements, i)
+                    ChunkedArray.add3(vertices, P.atom.x(l), P.atom.y(l), P.atom.z(l))
+                }
+
+                if (i % 10 === 0 && ctx.shouldUpdate) {
+                    await ctx.update({ message: 'Point', current: i, max: _i });
+                }
+            }
+
+            const transformArray = new Float32Array(32)
+            const m4 = Mat4.identity()
+            Mat4.toArray(m4, transformArray, 0)
+
+            const color = ValueCell.create(createColorTexture(1))
+            color.ref.value.set([ 0, 0, 255 ])
+
+            const points = createRenderObject('point', {
+                position: ValueCell.create(ChunkedArray.compact(vertices, true) as Float32Array),
+                color,
+                transform: ValueCell.create(transformArray),
+
+                instanceCount: transformArray.length / 16,
+                positionCount: vertices.elementCount
+            }, {})
+            renderObjects.push(points)
+
+            return renderObjects
+        }),
+        update: (props: RepresentationProps) => false
+    }
+}