create()

in src/engine/actvolume/tetra.js [41:126]


  create(vRadiusEllipse, numSubdividesOfOrigTetra) {
    // console.log(`vRadiusEllipse = ${vRadiusEllipse}`);
    // console.log(`numSubdividesOfOrigTetra = ${numSubdividesOfOrigTetra}`);
    const X = 0.5257311121;
    const Z = 0.8506508083;
    // { -X, 0.0f, Z },{ X, 0.0f, Z },{ -X, 0.0f, -Z },{ X, 0.0f, -Z },
    // { 0.0f, Z, X },{ 0.0f, Z, -X },{ 0.0f, -Z, X },{ 0.0f, -Z, -X },
    // { Z, X, 0.0f },{ -Z, X, 0.0f },{ Z, -X, 0.0f },{ -Z, -X, 0.0f }
    const vdata = [
      -X,
      0.0,
      +Z,
      +X,
      0.0,
      +Z,
      -X,
      0.0,
      -Z,
      +X,
      0.0,
      -Z,
      0.0,
      +Z,
      +X,
      0.0,
      +Z,
      -X,
      0.0,
      -Z,
      +X,
      0.0,
      -Z,
      -X,
      +Z,
      +X,
      0.0,
      -Z,
      +X,
      0.0,
      +Z,
      -X,
      0.0,
      -Z,
      -X,
      0.0,
    ];
    /*eslint-disable no-magic-numbers*/
    const tindices = [
      0, 4, 1, 0, 9, 4, 9, 5, 4, 4, 5, 8, 4, 8, 1, 8, 10, 1, 8, 3, 10, 5, 3, 8, 5, 2, 3, 2, 7, 3, 7, 10, 3, 7, 6, 10, 7, 11, 6, 11, 0, 6, 0,
      1, 6, 6, 1, 10, 9, 0, 11, 9, 11, 2, 9, 2, 5, 7, 2, 11,
    ];
    this.m_pointSet = new PointSet(NUM_VERTICES_TETRA);
    let i3 = 0;
    for (let i = 0; i < NUM_VERTICES_TETRA; i++, i3 += 3) {
      const x = vdata[i3 + 0];
      const y = vdata[i3 + 1];
      const z = vdata[i3 + 2];
      this.m_pointSet.addPoint(x, y, z);
    } // for (i) all vertices in tetrahedron structure
    // m_triangleSet.create(NUM_TRIANGLES_TETRA);
    this.m_triangleSet = new TriangleSet(NUM_TRIANGLES_TETRA);
    i3 = 0;
    for (let i = 0; i < NUM_TRIANGLES_TETRA; i++, i3 += 3) {
      const ia = tindices[i3 + 0];
      const ib = tindices[i3 + 1];
      const ic = tindices[i3 + 2];
      // use inverse points order to reach correct plane visibility and correct normal directions
      this.m_triangleSet.addTriangle(ia, ic, ib);
    }
    this.subDivideMesh(numSubdividesOfOrigTetra);

    // scale to given input ellipse
    const numPoints = this.m_pointSet.getNumPoints();
    for (let i = 0; i < numPoints; i++) {
      this.m_pointSet.m_points[i].m_point.x *= vRadiusEllipse.x;
      this.m_pointSet.m_points[i].m_point.y *= vRadiusEllipse.y;
      this.m_pointSet.m_points[i].m_point.z *= vRadiusEllipse.z;
      // console.log(`DEEP DEB. x = ${this.m_pointSet.m_points[i].m_point.x}`);
    } // for (i) all points in set

    // test save geo into file
    // const TEST_FILE_NAME = 'tetra.obj';
    // this.saveGeoToObjFile(TEST_FILE_NAME);

    return 1;
  } // create