buildGeoFromCorners()

in packages/miew/src/gfx/geometries/SSIsosurfaceGeometry.js [264:359]


  buildGeoFromCorners(meshRes, vBoxMin, vBoxMax, corners, vCellStep, cube) {
    const arrSize = 12;
    const cNumVerts = 8;
    const numCells = meshRes - 1;
    const side = meshRes;
    const side2 = meshRes * meshRes;

    const vaEdges = new Array(arrSize);
    for (let i = 0; i < arrSize; i++) {
      vaEdges[i] = new THREE.Vector3();
    }
    const sign = [];
    for (let i = 0; i < cNumVerts; i++) {
      sign[i] = 1.0;
    }
    const vCorner = new THREE.Vector3();
    let indCell = 0;
    let indY = 0;
    for (let y = 0; y < numCells; y++, indY += side2) {
      let indZ = 0;
      for (let z = 0; z < numCells; z++, indZ += side) {
        for (let x = 0; x < numCells; x++) {
          if (!cube.hasIntersection[indCell]) {
            // next cell
            indCell++;
            continue;
          }
          const bitsInside = cube.bitsInside[indCell];

          this.getCornerCoord(vBoxMin, vBoxMax, x, y, z, meshRes, vCorner);

          const indPointValues = indCell * (2 << (2 + 2));
          for (let i = 0, j = 0; i < cNumVerts; i++) {
            cube.pointsValuesLinear[indPointValues + j++] = vCorner.x;
            cube.pointsValuesLinear[indPointValues + j++] = vCorner.y;
            cube.pointsValuesLinear[indPointValues + j++] = vCorner.z;
          }

          cube.pointsValuesLinear[indPointValues + 3] += vCellStep.x;
          cube.pointsValuesLinear[indPointValues + 2 * 3] += vCellStep.x;
          cube.pointsValuesLinear[indPointValues + 5 * 3] += vCellStep.x;
          cube.pointsValuesLinear[indPointValues + 6 * 3] += vCellStep.x;

          cube.pointsValuesLinear[indPointValues + 2 * 3 + 2] += vCellStep.z;
          cube.pointsValuesLinear[indPointValues + 3 * 3 + 2] += vCellStep.z;
          cube.pointsValuesLinear[indPointValues + 6 * 3 + 2] += vCellStep.z;
          cube.pointsValuesLinear[indPointValues + 7 * 3 + 2] += vCellStep.z;

          cube.pointsValuesLinear[indPointValues + 4 * 3 + 1] += vCellStep.y;
          cube.pointsValuesLinear[indPointValues + 5 * 3 + 1] += vCellStep.y;
          cube.pointsValuesLinear[indPointValues + 6 * 3 + 1] += vCellStep.y;
          cube.pointsValuesLinear[indPointValues + 7 * 3 + 1] += vCellStep.y;

          // now current cell has intersections (from -x to +x) on some cube edges
          const indValues = indPointValues + 24;
          for (let i = 0; i < cNumVerts; ++i) {
            sign[i] = (cube.pointsValuesLinear[indValues + i] < 0.0) ? 1 : 0;
          }

          this.buildEdgePoint(0, 1, sign, cube, indPointValues, vaEdges[0]);
          this.buildEdgePoint(1, 2, sign, cube, indPointValues, vaEdges[1]);
          this.buildEdgePoint(2, 3, sign, cube, indPointValues, vaEdges[2]);
          this.buildEdgePoint(3, 0, sign, cube, indPointValues, vaEdges[3]);

          this.buildEdgePoint(4, 5, sign, cube, indPointValues, vaEdges[4]);
          this.buildEdgePoint(5, 6, sign, cube, indPointValues, vaEdges[5]);
          this.buildEdgePoint(6, 7, sign, cube, indPointValues, vaEdges[6]);
          this.buildEdgePoint(7, 4, sign, cube, indPointValues, vaEdges[7]);

          this.buildEdgePoint(0, 4, sign, cube, indPointValues, vaEdges[8]);
          this.buildEdgePoint(1, 5, sign, cube, indPointValues, vaEdges[9]);
          this.buildEdgePoint(2, 6, sign, cube, indPointValues, vaEdges[10]);
          this.buildEdgePoint(3, 7, sign, cube, indPointValues, vaEdges[11]);

          const offs = bitsInside * (2 << (1 + 2));
          for (let numTri = 0, indTri = 0; numTri < (2 + 2 + 2); numTri++, indTri += 3) {
            // s_triIndicesMarchCube is external array, defined in mold_ind.js
            const i0 = cube.striIndicesMarchCube[offs + indTri];
            if (i0 < 0) {
              break;
            }
            const i1 = cube.striIndicesMarchCube[offs + indTri + 1];
            const i2 = cube.striIndicesMarchCube[offs + indTri + 2];

            if (!this.addTriangle(vaEdges[i0], vaEdges[i1], vaEdges[i2])) {
              return 0 - 2;
            }
          } // for numTri

          // next cell (cube)
          indCell++;
        } // for (x)
      } // for (z)
    } // for (y)
    return 0;
  }