|
@@ -7,6 +7,7 @@
|
|
|
|
|
|
import { Vec3 } from 'mol-math/linear-algebra';
|
|
|
import { ChunkedArray } from 'mol-data/util';
|
|
|
+import { MeshBuilderState } from '../shape/mesh-builder';
|
|
|
|
|
|
const tA = Vec3.zero()
|
|
|
const tB = Vec3.zero()
|
|
@@ -19,29 +20,39 @@ const positionVector = Vec3.zero()
|
|
|
const normalVector = Vec3.zero()
|
|
|
const torsionVector = Vec3.zero()
|
|
|
|
|
|
-export function addSheet(controlPoints: Helpers.NumberArray, normalVectors: Helpers.NumberArray, binormalVectors: Helpers.NumberArray, linearSegments: number, width: number, height: number, arrowWidth: number, vertices: ChunkedArray<number, 3>, normals: ChunkedArray<number, 3>, indices: ChunkedArray<number, 3>, ids: ChunkedArray<number, 1>, currentId: number) {
|
|
|
+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()
|
|
|
|
|
|
- const vertexCount = vertices.elementCount
|
|
|
+export function addSheet(controlPoints: Helpers.NumberArray, normalVectors: Helpers.NumberArray, binormalVectors: Helpers.NumberArray, linearSegments: number, width: number, height: number, arrowHeight: number, startCap: boolean, endCap: boolean, state: MeshBuilderState) {
|
|
|
+ const { vertices, normals, indices } = state
|
|
|
+
|
|
|
+ let vertexCount = vertices.elementCount
|
|
|
let offsetLength = 0
|
|
|
|
|
|
- if (arrowWidth > 0) {
|
|
|
+ if (arrowHeight > 0) {
|
|
|
Vec3.fromArray(tA, controlPoints, 0)
|
|
|
Vec3.fromArray(tB, controlPoints, linearSegments * 3)
|
|
|
- offsetLength = arrowWidth / Vec3.magnitude(Vec3.sub(tV, tB, tA))
|
|
|
+ offsetLength = arrowHeight / Vec3.magnitude(Vec3.sub(tV, tB, tA))
|
|
|
}
|
|
|
|
|
|
for (let i = 0; i <= linearSegments; ++i) {
|
|
|
- const actualWidth = arrowWidth === 0 ? width : arrowWidth * (1 - i / linearSegments);
|
|
|
-
|
|
|
+ const actualHeight = arrowHeight === 0 ? height : arrowHeight * (1 - i / linearSegments);
|
|
|
const i3 = i * 3
|
|
|
|
|
|
Vec3.fromArray(verticalVector, normalVectors, i3)
|
|
|
- Vec3.scale(verticalVector, verticalVector, actualWidth);
|
|
|
+ Vec3.scale(verticalVector, verticalVector, actualHeight);
|
|
|
|
|
|
Vec3.fromArray(horizontalVector, binormalVectors, i3)
|
|
|
- Vec3.scale(horizontalVector, horizontalVector, height);
|
|
|
+ Vec3.scale(horizontalVector, horizontalVector, width);
|
|
|
|
|
|
- if (arrowWidth > 0) {
|
|
|
+ if (arrowHeight > 0) {
|
|
|
Vec3.fromArray(tA, normalVectors, i3)
|
|
|
Vec3.fromArray(tB, binormalVectors, i3)
|
|
|
Vec3.scale(normalOffset, Vec3.cross(normalOffset, tA, tB), offsetLength)
|
|
@@ -51,49 +62,41 @@ export function addSheet(controlPoints: Helpers.NumberArray, normalVectors: Help
|
|
|
Vec3.fromArray(normalVector, normalVectors, i3)
|
|
|
Vec3.fromArray(torsionVector, binormalVectors, i3)
|
|
|
|
|
|
- Vec3.add(tA, Vec3.add(tA, Vec3.copy(tA, positionVector), horizontalVector), verticalVector)
|
|
|
+ Vec3.add(tA, Vec3.add(tA, positionVector, horizontalVector), verticalVector)
|
|
|
Vec3.copy(tB, normalVector)
|
|
|
ChunkedArray.add3(vertices, tA[0], tA[1], tA[2])
|
|
|
ChunkedArray.add3(normals, tB[0], tB[1], tB[2])
|
|
|
- ChunkedArray.add(ids, currentId);
|
|
|
|
|
|
- Vec3.add(tA, Vec3.sub(tA, Vec3.copy(tA, positionVector), horizontalVector), verticalVector)
|
|
|
+ Vec3.add(tA, Vec3.sub(tA, positionVector, horizontalVector), verticalVector)
|
|
|
ChunkedArray.add3(vertices, tA[0], tA[1], tA[2])
|
|
|
ChunkedArray.add3(normals, tB[0], tB[1], tB[2])
|
|
|
- ChunkedArray.add(ids, currentId);
|
|
|
|
|
|
- Vec3.add(tA, Vec3.sub(tA, Vec3.copy(tA, positionVector), horizontalVector), verticalVector)
|
|
|
- Vec3.add(tB, Vec3.scale(tB, Vec3.copy(tB, torsionVector), -1), normalOffset)
|
|
|
+ // Vec3.add(tA, Vec3.sub(tA, positionVector, horizontalVector), verticalVector) // reuse tA
|
|
|
+ Vec3.add(tB, Vec3.negate(tB, torsionVector), normalOffset)
|
|
|
ChunkedArray.add3(vertices, tA[0], tA[1], tA[2])
|
|
|
ChunkedArray.add3(normals, tB[0], tB[1], tB[2])
|
|
|
- ChunkedArray.add(ids, currentId);
|
|
|
|
|
|
- Vec3.sub(tA, Vec3.sub(tA, Vec3.copy(tA, positionVector), horizontalVector), verticalVector)
|
|
|
+ Vec3.sub(tA, Vec3.sub(tA, positionVector, horizontalVector), verticalVector)
|
|
|
ChunkedArray.add3(vertices, tA[0], tA[1], tA[2])
|
|
|
ChunkedArray.add3(normals, tB[0], tB[1], tB[2])
|
|
|
- ChunkedArray.add(ids, currentId);
|
|
|
|
|
|
- Vec3.sub(tA, Vec3.sub(tA, Vec3.copy(tA, positionVector), horizontalVector), verticalVector)
|
|
|
- Vec3.scale(tB, Vec3.copy(tB, normalVector), -1)
|
|
|
+ // Vec3.sub(tA, Vec3.sub(tA, positionVector, horizontalVector), verticalVector) // reuse tA
|
|
|
+ Vec3.negate(tB, normalVector)
|
|
|
ChunkedArray.add3(vertices, tA[0], tA[1], tA[2])
|
|
|
ChunkedArray.add3(normals, tB[0], tB[1], tB[2])
|
|
|
- ChunkedArray.add(ids, currentId);
|
|
|
|
|
|
- Vec3.sub(tA, Vec3.add(tA, Vec3.copy(tA, positionVector), horizontalVector), verticalVector)
|
|
|
+ Vec3.sub(tA, Vec3.add(tA, positionVector, horizontalVector), verticalVector)
|
|
|
ChunkedArray.add3(vertices, tA[0], tA[1], tA[2])
|
|
|
ChunkedArray.add3(normals, tB[0], tB[1], tB[2])
|
|
|
- ChunkedArray.add(ids, currentId);
|
|
|
|
|
|
- Vec3.sub(tA, Vec3.add(tA, Vec3.copy(tA, positionVector), horizontalVector), verticalVector)
|
|
|
- Vec3.add(tB, Vec3.copy(tB, torsionVector), normalOffset)
|
|
|
+ // Vec3.sub(tA, Vec3.add(tA, positionVector, horizontalVector), verticalVector) // reuse tA
|
|
|
+ Vec3.add(tB, torsionVector, normalOffset)
|
|
|
ChunkedArray.add3(vertices, tA[0], tA[1], tA[2])
|
|
|
ChunkedArray.add3(normals, tB[0], tB[1], tB[2])
|
|
|
- ChunkedArray.add(ids, currentId);
|
|
|
|
|
|
- Vec3.add(tA, Vec3.add(tA, Vec3.copy(tA, positionVector), horizontalVector), verticalVector)
|
|
|
+ Vec3.add(tA, Vec3.add(tA, positionVector, horizontalVector), verticalVector)
|
|
|
ChunkedArray.add3(vertices, tA[0], tA[1], tA[2])
|
|
|
ChunkedArray.add3(normals, tB[0], tB[1], tB[2])
|
|
|
- ChunkedArray.add(ids, currentId);
|
|
|
}
|
|
|
|
|
|
for (let i = 0; i < linearSegments; ++i) {
|
|
@@ -112,4 +115,94 @@ export function addSheet(controlPoints: Helpers.NumberArray, normalVectors: Help
|
|
|
);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ if (startCap) {
|
|
|
+ const offset = 0
|
|
|
+ vertexCount = vertices.elementCount
|
|
|
+
|
|
|
+ Vec3.fromArray(verticalVector, normalVectors, offset)
|
|
|
+ Vec3.scale(verticalVector, verticalVector, height);
|
|
|
+
|
|
|
+ Vec3.fromArray(horizontalVector, binormalVectors, offset)
|
|
|
+ Vec3.scale(horizontalVector, horizontalVector, width);
|
|
|
+
|
|
|
+ Vec3.fromArray(positionVector, controlPoints, offset)
|
|
|
+
|
|
|
+ Vec3.add(p1, Vec3.add(p1, positionVector, horizontalVector), verticalVector)
|
|
|
+ Vec3.sub(p2, Vec3.add(p2, positionVector, horizontalVector), verticalVector)
|
|
|
+ Vec3.sub(p3, Vec3.sub(p3, positionVector, horizontalVector), verticalVector)
|
|
|
+ Vec3.add(p4, Vec3.sub(p4, positionVector, horizontalVector), verticalVector)
|
|
|
+
|
|
|
+ ChunkedArray.add3(vertices, p1[0], p1[1], p1[2])
|
|
|
+ ChunkedArray.add3(vertices, p2[0], p2[1], p2[2])
|
|
|
+ ChunkedArray.add3(vertices, p3[0], p3[1], p3[2])
|
|
|
+ ChunkedArray.add3(vertices, p4[0], p4[1], p4[2])
|
|
|
+
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (endCap && arrowHeight === 0) {
|
|
|
+ const offset = linearSegments * 3
|
|
|
+ vertexCount = vertices.elementCount
|
|
|
+
|
|
|
+ Vec3.fromArray(verticalVector, normalVectors, offset)
|
|
|
+ Vec3.scale(verticalVector, verticalVector, height);
|
|
|
+
|
|
|
+ Vec3.fromArray(horizontalVector, binormalVectors, offset)
|
|
|
+ Vec3.scale(horizontalVector, horizontalVector, width);
|
|
|
+
|
|
|
+ Vec3.fromArray(positionVector, controlPoints, offset)
|
|
|
+
|
|
|
+ Vec3.add(p1, Vec3.add(p1, positionVector, horizontalVector), verticalVector)
|
|
|
+ Vec3.sub(p2, Vec3.add(p2, positionVector, horizontalVector), verticalVector)
|
|
|
+ Vec3.sub(p3, Vec3.sub(p3, positionVector, horizontalVector), verticalVector)
|
|
|
+ Vec3.add(p4, Vec3.sub(p4, positionVector, horizontalVector), verticalVector)
|
|
|
+
|
|
|
+ ChunkedArray.add3(vertices, p1[0], p1[1], p1[2])
|
|
|
+ ChunkedArray.add3(vertices, p2[0], p2[1], p2[2])
|
|
|
+ ChunkedArray.add3(vertices, p3[0], p3[1], p3[2])
|
|
|
+ ChunkedArray.add3(vertices, p4[0], p4[1], p4[2])
|
|
|
+
|
|
|
+ Vec3.cross(normalVector, horizontalVector, verticalVector)
|
|
|
+
|
|
|
+ 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)
|
|
|
}
|