pushTriangle method

void pushTriangle(
  1. num a,
  2. num b,
  3. num c,
  4. Material material,
)

Implementation

void pushTriangle(num a, num b, num c, Material material) {
  RenderableVertex v1 = _vertexPool[a.toInt()];
  RenderableVertex v2 = _vertexPool[b.toInt()];
  RenderableVertex v3 = _vertexPool[c.toInt()];
  if (!checkTriangleVisibility(v1, v2, v3)) return;

  if (material.side == DoubleSide || checkBackfaceCulling(v1, v2, v3)) {
    _face = getNextFaceInPool();
    _face.id = object.id;

    _face.v1.copy(v1);
    _face.v2.copy(v2);
    _face.v3.copy(v3);

    _face.z = (v1.positionScreen.z + v2.positionScreen.z + v3.positionScreen.z) / 3;
    _face.renderOrder = object.renderOrder; // face normal

    _vector3.subVectors(v3.position, v2.position);
    _vector4.subVectors(v1.position.toVector4(), v2.position.toVector4());
    _vector3.crossFromVector4(_vector4);

    _face.normalModel.copy(_vector3);
    _face.normalModel.applyMatrix3(normalMatrix).normalize();

    for (int i = 0; i < 3; i++) {
      Vector3 normal = _face.vertexNormalsModel[i];
      normal.fromArray(normals); //arguments[i] * 3
      normal.applyMatrix3(normalMatrix).normalize();
      Vector2 uv = _face.uvs[i];
      if (uvs.isNotEmpty) {
        uv.fromArray(uvs); //arguments[i] * 2
      }
    }

    _face.vertexNormalsLength = 3;
    _face.material = material;

    if (material.vertexColors) {
      _face.color.fromArray(colors, (a * 3).toInt());
    }
    _renderData.elements.add(_face);
  }
}