Explorar el Código

add adjustCylinderLength param

- so it can be switched off
Alexander Rose hace 4 años
padre
commit
eca7da2c72

+ 1 - 0
src/mol-repr/structure/representation/ellipsoid.ts

@@ -25,6 +25,7 @@ export const EllipsoidParams = {
     ...EllipsoidMeshParams,
     ...IntraUnitBondCylinderParams,
     ...InterUnitBondCylinderParams,
+    adjustCylinderLength: PD.Boolean(false, { isHidden: true }), // not useful here
     includeParent: PD.Boolean(false, { isHidden: true }), // not yet supported here
     unitKinds: getUnitKindsParam(['atomic']),
     sizeFactor: PD.Numeric(1, { min: 0.01, max: 10, step: 0.01 }),

+ 15 - 12
src/mol-repr/structure/visual/bond-inter-unit-cylinder.ts

@@ -40,7 +40,7 @@ function getInterUnitBondCylinderBuilderProps(structure: Structure, theme: Theme
 
     const bonds = structure.interUnitBonds;
     const { edgeCount, edges } = bonds;
-    const { sizeFactor, sizeAspectRatio } = props;
+    const { sizeFactor, sizeAspectRatio, adjustCylinderLength } = props;
 
     const delta = Vec3();
 
@@ -116,19 +116,20 @@ function getInterUnitBondCylinderBuilderProps(structure: Structure, theme: Theme
             const uA = structure.unitMap.get(b.unitA);
             const uB = structure.unitMap.get(b.unitB);
 
-            const rA = radiusA(edgeIndex), rB = radiusB(edgeIndex);
-            const r = Math.min(rA, rB) * sizeAspectRatio;
-            const oA = Math.sqrt(Math.max(0, rA * rA - r * r)) - 0.05;
-            const oB = Math.sqrt(Math.max(0, rB * rB - r * r)) - 0.05;
-
             uA.conformation.position(uA.elements[b.indexA], posA);
             uB.conformation.position(uB.elements[b.indexB], posB);
 
-            if (oA <= 0.01 && oB <= 0.01) return;
+            if (adjustCylinderLength) {
+                const rA = radiusA(edgeIndex), rB = radiusB(edgeIndex);
+                const r = Math.min(rA, rB) * sizeAspectRatio;
+                const oA = Math.sqrt(Math.max(0, rA * rA - r * r)) - 0.05;
+                const oB = Math.sqrt(Math.max(0, rB * rB - r * r)) - 0.05;
+                if (oA <= 0.01 && oB <= 0.01) return;
 
-            Vec3.normalize(delta, Vec3.sub(delta, posB, posA));
-            Vec3.scaleAndAdd(posA, posA, delta, oA);
-            Vec3.scaleAndAdd(posB, posB, delta, -oB);
+                Vec3.normalize(delta, Vec3.sub(delta, posB, posA));
+                Vec3.scaleAndAdd(posA, posA, delta, oA);
+                Vec3.scaleAndAdd(posB, posB, delta, -oB);
+            }
         },
         style: (edgeIndex: number) => {
             const o = edges[edgeIndex].props.order;
@@ -213,7 +214,8 @@ export function InterUnitBondCylinderImpostorVisual(materialId: number): Complex
                 newProps.dashCap !== currentProps.dashCap ||
                 newProps.stubCap !== currentProps.stubCap ||
                 !arrayEqual(newProps.includeTypes, currentProps.includeTypes) ||
-                !arrayEqual(newProps.excludeTypes, currentProps.excludeTypes)
+                !arrayEqual(newProps.excludeTypes, currentProps.excludeTypes) ||
+                newProps.adjustCylinderLength !== currentProps.adjustCylinderLength
             );
         },
         mustRecreate: (structure: Structure, props: PD.Values<InterUnitBondCylinderParams>, webgl?: WebGLContext) => {
@@ -243,7 +245,8 @@ export function InterUnitBondCylinderMeshVisual(materialId: number): ComplexVisu
                 newProps.dashCap !== currentProps.dashCap ||
                 newProps.stubCap !== currentProps.stubCap ||
                 !arrayEqual(newProps.includeTypes, currentProps.includeTypes) ||
-                !arrayEqual(newProps.excludeTypes, currentProps.excludeTypes)
+                !arrayEqual(newProps.excludeTypes, currentProps.excludeTypes) ||
+                newProps.adjustCylinderLength !== currentProps.adjustCylinderLength
             );
         },
         mustRecreate: (structure: Structure, props: PD.Values<InterUnitBondCylinderParams>, webgl?: WebGLContext) => {

+ 15 - 12
src/mol-repr/structure/visual/bond-intra-unit-cylinder.ts

@@ -31,7 +31,7 @@ function getIntraUnitBondCylinderBuilderProps(unit: Unit.Atomic, structure: Stru
     const bonds = unit.bonds;
     const { edgeCount, a, b, edgeProps, offset } = bonds;
     const { order: _order, flags: _flags } = edgeProps;
-    const { sizeFactor, sizeAspectRatio } = props;
+    const { sizeFactor, sizeAspectRatio, adjustCylinderLength } = props;
 
     const vRef = Vec3(), delta = Vec3();
     const pos = unit.conformation.invariantPosition;
@@ -90,19 +90,20 @@ function getIntraUnitBondCylinderBuilderProps(unit: Unit.Atomic, structure: Stru
             return null;
         },
         position: (posA: Vec3, posB: Vec3, edgeIndex: number) => {
-            const rA = radiusA(edgeIndex), rB = radiusB(edgeIndex);
-            const r = Math.min(rA, rB) * sizeAspectRatio;
-            const oA = Math.sqrt(Math.max(0, rA * rA - r * r)) - 0.05;
-            const oB = Math.sqrt(Math.max(0, rB * rB - r * r)) - 0.05;
-
             pos(elements[a[edgeIndex]], posA);
             pos(elements[b[edgeIndex]], posB);
 
-            if (oA <= 0.01 && oB <= 0.01) return;
+            if (adjustCylinderLength) {
+                const rA = radiusA(edgeIndex), rB = radiusB(edgeIndex);
+                const r = Math.min(rA, rB) * sizeAspectRatio;
+                const oA = Math.sqrt(Math.max(0, rA * rA - r * r)) - 0.05;
+                const oB = Math.sqrt(Math.max(0, rB * rB - r * r)) - 0.05;
+                if (oA <= 0.01 && oB <= 0.01) return;
 
-            Vec3.normalize(delta, Vec3.sub(delta, posB, posA));
-            Vec3.scaleAndAdd(posA, posA, delta, oA);
-            Vec3.scaleAndAdd(posB, posB, delta, -oB);
+                Vec3.normalize(delta, Vec3.sub(delta, posB, posA));
+                Vec3.scaleAndAdd(posA, posA, delta, oA);
+                Vec3.scaleAndAdd(posB, posB, delta, -oB);
+            }
         },
         style: (edgeIndex: number) => {
             const o = _order[edgeIndex];
@@ -195,7 +196,8 @@ export function IntraUnitBondCylinderImpostorVisual(materialId: number): UnitsVi
                 newProps.dashCap !== currentProps.dashCap ||
                 newProps.stubCap !== currentProps.stubCap ||
                 !arrayEqual(newProps.includeTypes, currentProps.includeTypes) ||
-                !arrayEqual(newProps.excludeTypes, currentProps.excludeTypes)
+                !arrayEqual(newProps.excludeTypes, currentProps.excludeTypes) ||
+                newProps.adjustCylinderLength !== currentProps.adjustCylinderLength
             );
 
             const newUnit = newStructureGroup.group.units[0];
@@ -236,7 +238,8 @@ export function IntraUnitBondCylinderMeshVisual(materialId: number): UnitsVisual
                 newProps.dashCap !== currentProps.dashCap ||
                 newProps.stubCap !== currentProps.stubCap ||
                 !arrayEqual(newProps.includeTypes, currentProps.includeTypes) ||
-                !arrayEqual(newProps.excludeTypes, currentProps.excludeTypes)
+                !arrayEqual(newProps.excludeTypes, currentProps.excludeTypes) ||
+                newProps.adjustCylinderLength !== currentProps.adjustCylinderLength
             );
 
             const newUnit = newStructureGroup.group.units[0];

+ 2 - 1
src/mol-repr/structure/visual/util/bond.ts

@@ -26,7 +26,8 @@ export type BondProps = typeof DefaultBondProps
 
 export const BondCylinderParams = {
     ...LinkCylinderParams,
-    ...BondParams
+    ...BondParams,
+    adjustCylinderLength: PD.Boolean(true, { description: 'Shorten cylinders to reduce overlap with spheres.' })
 };
 export const DefaultBondCylinderProps = PD.getDefaultValues(BondCylinderParams);
 export type BondCylinderProps = typeof DefaultBondCylinderProps