Browse Source

create full cap for arrows, tube & sheet fixxes

Alexander Rose 6 years ago
parent
commit
fa3e803bc8
2 changed files with 19 additions and 50 deletions
  1. 6 37
      src/mol-geo/primitive/sheet.ts
  2. 13 13
      src/mol-geo/primitive/tube.ts

+ 6 - 37
src/mol-geo/primitive/sheet.ts

@@ -20,15 +20,10 @@ const positionVector = Vec3.zero()
 const normalVector = Vec3.zero()
 const torsionVector = Vec3.zero()
 
-const arrowVerticalVector = Vec3.zero()
 const p1 = Vec3.zero()
 const p2 = Vec3.zero()
 const p3 = Vec3.zero()
 const p4 = Vec3.zero()
-const p5 = Vec3.zero()
-const p6 = Vec3.zero()
-const p7 = Vec3.zero()
-const p8 = Vec3.zero()
 
 export function addSheet(controlPoints: ArrayLike<number>, normalVectors: ArrayLike<number>, binormalVectors: ArrayLike<number>, linearSegments: number, width: number, height: number, arrowHeight: number, startCap: boolean, endCap: boolean, state: MeshBuilderState) {
     const { vertices, normals, indices } = state
@@ -121,7 +116,7 @@ export function addSheet(controlPoints: ArrayLike<number>, normalVectors: ArrayL
         vertexCount = vertices.elementCount
 
         Vec3.fromArray(verticalVector, normalVectors, offset)
-        Vec3.scale(verticalVector, verticalVector, height);
+        Vec3.scale(verticalVector, verticalVector, arrowHeight === 0 ? height : arrowHeight);
 
         Vec3.fromArray(horizontalVector, binormalVectors, offset)
         Vec3.scale(horizontalVector, horizontalVector, width);
@@ -140,36 +135,11 @@ export function addSheet(controlPoints: ArrayLike<number>, normalVectors: ArrayL
 
         Vec3.cross(normalVector, horizontalVector, verticalVector)
 
-        if (arrowHeight === 0) {
-            for (let i = 0; i < 4; ++i) {
-                ChunkedArray.add3(normals, normalVector[0], normalVector[1], normalVector[2])
-            }
-
-            ChunkedArray.add3(indices, vertexCount + 2, vertexCount + 1, vertexCount);
-            ChunkedArray.add3(indices, vertexCount, vertexCount + 3, vertexCount + 2);
-        } else {
-            Vec3.fromArray(arrowVerticalVector, normalVectors, offset)
-            Vec3.scale(arrowVerticalVector, verticalVector, arrowHeight);
-
-            Vec3.add(p5, Vec3.add(p5, positionVector, horizontalVector), arrowVerticalVector)
-            Vec3.sub(p6, Vec3.add(p6, positionVector, horizontalVector), arrowVerticalVector)
-            Vec3.sub(p7, Vec3.sub(p7, positionVector, horizontalVector), arrowVerticalVector)
-            Vec3.add(p8, Vec3.sub(p8, positionVector, horizontalVector), arrowVerticalVector)
-
-            ChunkedArray.add3(vertices, p5[0], p5[1], p5[2])
-            ChunkedArray.add3(vertices, p6[0], p6[1], p6[2])
-            ChunkedArray.add3(vertices, p7[0], p7[1], p7[2])
-            ChunkedArray.add3(vertices, p8[0], p8[1], p8[2])
-
-            for (let i = 0; i < 8; ++i) {
-                ChunkedArray.add3(normals, normalVector[0], normalVector[1], normalVector[2])
-            }
-
-            ChunkedArray.add3(indices, vertexCount + 7, vertexCount, vertexCount + 4);
-            ChunkedArray.add3(indices, vertexCount + 7, vertexCount + 3, vertexCount);
-            ChunkedArray.add3(indices, vertexCount + 5, vertexCount + 1, vertexCount + 6);
-            ChunkedArray.add3(indices, vertexCount + 1, vertexCount + 2, vertexCount + 6);
+        for (let i = 0; i < 4; ++i) {
+            ChunkedArray.add3(normals, normalVector[0], normalVector[1], normalVector[2])
         }
+        ChunkedArray.add3(indices, vertexCount + 2, vertexCount + 1, vertexCount);
+        ChunkedArray.add3(indices, vertexCount, vertexCount + 3, vertexCount + 2);
     }
 
     if (endCap && arrowHeight === 0) {
@@ -199,10 +169,9 @@ export function addSheet(controlPoints: ArrayLike<number>, normalVectors: ArrayL
         for (let i = 0; i < 4; ++i) {
             ChunkedArray.add3(normals, normalVector[0], normalVector[1], normalVector[2])
         }
-
         ChunkedArray.add3(indices, vertexCount + 2, vertexCount + 1, vertexCount);
         ChunkedArray.add3(indices, vertexCount, vertexCount + 3, vertexCount + 2);
     }
 
-    return (linearSegments + 1) * 8 + (startCap ? (arrowHeight === 0 ? 4 : 8) : 0) + (endCap && arrowHeight === 0 ? 4 : 0)
+    return (linearSegments + 1) * 8 + (startCap ? 4 : 0) + (endCap && arrowHeight === 0 ? 4 : 0)
 }

+ 13 - 13
src/mol-geo/primitive/tube.ts

@@ -80,7 +80,7 @@ export function addTube(controlPoints: ArrayLike<number>, normalVectors: ArrayLi
 
     if (startCap) {
         const offset = 0
-        vertexCount = vertices.elementCount
+        const centerVertex = vertices.elementCount
         Vec3.fromArray(u, normalVectors, offset)
         Vec3.fromArray(v, binormalVectors, offset)
         Vec3.fromArray(controlPoint, controlPoints, offset)
@@ -89,6 +89,7 @@ export function addTube(controlPoints: ArrayLike<number>, normalVectors: ArrayLi
         ChunkedArray.add3(vertices, controlPoint[0], controlPoint[1], controlPoint[2]);
         ChunkedArray.add3(normals, normalVector[0], normalVector[1], normalVector[2]);
 
+        vertexCount = vertices.elementCount
         for (let i = 0; i < radialSegments; ++i) {
             const t = 2 * Math.PI * i / radialSegments;
 
@@ -106,16 +107,16 @@ export function addTube(controlPoints: ArrayLike<number>, normalVectors: ArrayLi
 
             ChunkedArray.add3(
                 indices,
-                vertexCount,
-                vertexCount + i + 1,
-                vertexCount + (i + 1) % radialSegments + 1
+                centerVertex,
+                vertexCount + i,
+                vertexCount + (i + 1) % radialSegments
             );
         }
     }
 
     if (endCap) {
         const offset = linearSegments * 3
-        vertexCount = vertices.elementCount
+        const centerVertex = vertices.elementCount
         Vec3.fromArray(u, normalVectors, offset)
         Vec3.fromArray(v, binormalVectors, offset)
         Vec3.fromArray(controlPoint, controlPoints, offset)
@@ -124,6 +125,7 @@ export function addTube(controlPoints: ArrayLike<number>, normalVectors: ArrayLi
         ChunkedArray.add3(vertices, controlPoint[0], controlPoint[1], controlPoint[2]);
         ChunkedArray.add3(normals, normalVector[0], normalVector[1], normalVector[2]);
 
+        vertexCount = vertices.elementCount
         for (let i = 0; i < radialSegments; ++i) {
             const t = 2 * Math.PI * i / radialSegments;
 
@@ -139,14 +141,12 @@ export function addTube(controlPoints: ArrayLike<number>, normalVectors: ArrayLi
             ChunkedArray.add3(vertices, tempPos[0], tempPos[1], tempPos[2]);
             ChunkedArray.add3(normals, normalVector[0], normalVector[1], normalVector[2]);
 
-            if (i < radialSegments - 2) {
-                ChunkedArray.add3(
-                    indices,
-                    vertexCount + i + 1,
-                    vertexCount + (i + 1) % radialSegments + 1,
-                    vertexCount
-                );
-            }
+            ChunkedArray.add3(
+                indices,
+                vertexCount + i,
+                vertexCount + (i + 1) % radialSegments,
+                centerVertex
+            );
         }
     }