Ver Fonte

mol-repr: partially fixed a bug that caused unnecessary volume surface recalc

David Sehnal há 6 anos atrás
pai
commit
f0b242bd7d
2 ficheiros alterados com 10 adições e 2 exclusões
  1. 6 0
      src/mol-model/volume/data.ts
  2. 4 2
      src/mol-repr/volume/isosurface.ts

+ 6 - 0
src/mol-model/volume/data.ts

@@ -6,6 +6,7 @@
 
 import { SpacegroupCell, Box3D } from 'mol-math/geometry'
 import { Tensor, Mat4, Vec3 } from 'mol-math/linear-algebra'
+import { shallowEqual } from 'mol-util/object';
 
 /** The basic unit cell that contains the data. */
 interface VolumeData {
@@ -47,6 +48,11 @@ namespace VolumeIsoValue {
     export type Relative = Readonly<{ kind: 'relative', relativeValue: number }>
     export type Absolute = Readonly<{ kind: 'absolute', absoluteValue: number }>
 
+    export function areSame(a: VolumeIsoValue, b: VolumeIsoValue) {
+        // TODO: this should compare values converted to absolute value
+        return shallowEqual(a, b);
+    }
+
     export function absolute(value: number): Absolute { return { kind: 'absolute', absoluteValue: value }; }
     export function relative(value: number): Relative { return { kind: 'relative', relativeValue: value }; }
 

+ 4 - 2
src/mol-repr/volume/isosurface.ts

@@ -97,7 +97,8 @@ export function IsosurfaceMeshVisual(): VolumeVisual<IsosurfaceMeshParams> {
         getLoci: () => EmptyLoci,
         eachLocation: () => false,
         setUpdateState: (state: VisualUpdateState, newProps: PD.Values<IsosurfaceMeshParams>, currentProps: PD.Values<IsosurfaceMeshParams>) => {
-            if (newProps.isoValue !== currentProps.isoValue) state.createGeometry = true
+            // TODO: should convert to same type of isoValue 1st
+            if (!VolumeIsoValue.areSame(newProps.isoValue, currentProps.isoValue)) state.createGeometry = true
         },
         geometryUtils: Mesh.Utils
     })
@@ -133,7 +134,8 @@ export function IsosurfaceWireframeVisual(): VolumeVisual<IsosurfaceWireframePar
         getLoci: () => EmptyLoci,
         eachLocation: () => false,
         setUpdateState: (state: VisualUpdateState, newProps: PD.Values<IsosurfaceWireframeParams>, currentProps: PD.Values<IsosurfaceWireframeParams>) => {
-            if (newProps.isoValue !== currentProps.isoValue) state.createGeometry = true
+            // TODO: should convert to same type of isoValue 1st
+            if (!VolumeIsoValue.areSame(newProps.isoValue, currentProps.isoValue)) state.createGeometry = true
         },
         geometryUtils: Lines.Utils
     })