Browse Source

wip, renderer tweaks

Alexander Rose 7 years ago
parent
commit
4d3c769e6c

+ 1 - 1
src/apps/render-test/state.ts

@@ -39,7 +39,7 @@ export default class State {
     initialized = new BehaviorSubject<boolean>(false)
     loading = new BehaviorSubject<boolean>(false)
 
-    colorTheme = new BehaviorSubject<ColorTheme>('chain-id')
+    colorTheme = new BehaviorSubject<ColorTheme>('atom-index')
     detail = new BehaviorSubject<number>(2)
 
     pointVisibility = new BehaviorSubject<boolean>(true)

+ 1 - 1
src/mol-geo/representation/structure/point.ts

@@ -75,7 +75,7 @@ export default function Point(): UnitsRepresentation<PointProps> {
                     objectId: 0,
 
                     position: ValueCell.create(vertices),
-                    id: ValueCell.create(fillSerial(new Float32Array(unitCount))),
+                    id: ValueCell.create(fillSerial(new Float32Array(elementCount))),
                     size,
                     color,
                     transform: ValueCell.create(transforms),

+ 0 - 1
src/mol-gl/renderer.ts

@@ -74,7 +74,6 @@ namespace Renderer {
 
         const draw = () => {
             regl.poll() // updates timers and viewport
-            camera.update()
             baseContext(state => {
                 regl.clear({ color: [0, 0, 0, 1] })
                 // TODO painters sort, filter visible, filter picking, visibility culling?

+ 5 - 2
src/mol-view/controls/trackball.ts

@@ -63,7 +63,7 @@ namespace TrackballControls {
         const wheelSub = input.wheel.subscribe(onWheel)
         const pinchSub = input.pinch.subscribe(onPinch)
 
-        // internals
+        // For internal use
         const target = Vec3.zero()
         const lastPosition = Vec3.zero()
 
@@ -84,7 +84,7 @@ namespace TrackballControls {
         const _panStart = Vec2.zero()
         const _panEnd = Vec2.zero()
 
-        // for reset
+        // Initial values for reseting
         const target0 = Vec3.clone(target)
         const position0 = Vec3.clone(object.position)
         const up0 = Vec3.clone(object.up)
@@ -197,6 +197,7 @@ namespace TrackballControls {
             }
         }
 
+        /** Ensure the distance between object and target is within the min/max distance */
         function checkDistances() {
             if (Vec3.squaredMagnitude(_eye) > maxDistance * maxDistance) {
                 Vec3.setMagnitude(_eye, _eye, maxDistance)
@@ -211,6 +212,7 @@ namespace TrackballControls {
             }
         }
 
+        /** Update the object's position, direction and up vectors */
         function update() {
             Vec3.sub(_eye, object.position, target)
 
@@ -229,6 +231,7 @@ namespace TrackballControls {
             }
         }
 
+        /** Reset object's vectors and the target vector to their initial values */
         function reset() {
             Vec3.copy(target, target0)
             Vec3.copy(object.position, position0)

+ 11 - 6
src/mol-view/viewer.ts

@@ -4,7 +4,7 @@
  * @author Alexander Rose <alexander.rose@weirdbyte.de>
  */
 
-import { Vec3 } from 'mol-math/linear-algebra'
+import { Vec3, Mat4, EPSILON } from 'mol-math/linear-algebra'
 import InputObserver from 'mol-util/input/input-observer'
 import * as SetUtils from 'mol-util/set'
 import Renderer, { RendererStats } from 'mol-gl/renderer'
@@ -24,7 +24,7 @@ interface Viewer {
     remove: (repr: StructureRepresentation) => void
     clear: () => void
 
-    draw: () => void
+    draw: (force?: boolean) => void
     requestDraw: () => void
     animate: () => void
 
@@ -68,22 +68,27 @@ namespace Viewer {
         const renderer = Renderer.create(gl, camera)
 
         let drawPending = false
+        const prevProjectionView = Mat4.zero()
 
-        function draw () {
+        function draw (force?: boolean) {
             controls.update()
             camera.update()
-            renderer.draw()
+            if (force || !Mat4.areEqual(camera.projectionView, prevProjectionView, EPSILON.Value)) {
+                Mat4.copy(prevProjectionView, camera.projectionView)
+                renderer.draw()
+            }
+            drawPending = false
         }
 
         function requestDraw () {
             if (drawPending) return
             drawPending = true
-            window.requestAnimationFrame(draw)
+            window.requestAnimationFrame(() => draw(true))
         }
 
         function animate () {
             draw()
-            window.requestAnimationFrame(animate)
+            window.requestAnimationFrame(() => animate())
         }
 
         handleResize()