merge method

dynamic merge(
  1. dynamic geometry,
  2. dynamic matrix, {
  3. int materialIndexOffset = 0,
})

Implementation

merge(geometry, matrix, {int materialIndexOffset = 0}) {
  if (!(geometry && geometry.isGeometry)) {
    print('THREE.Geometry.merge(): geometry not an instance of THREE.Geometry. $geometry');
    return;
  }

  var normalMatrix;
  var vertexOffset = vertices.length,
      vertices1 = vertices,
      vertices2 = geometry.vertices,
      faces1 = faces,
      faces2 = geometry.faces,
      colors1 = colors,
      colors2 = geometry.colors;

  if (matrix != null) {
    normalMatrix = three.Matrix3().getNormalMatrix(matrix);
  }

  // vertices

  for (var i = 0, il = vertices2.length; i < il; i++) {
    var vertex = vertices2[i];

    var vertexCopy = vertex.clone();

    if (matrix != null) vertexCopy.applyMatrix4(matrix);

    vertices1.add(vertexCopy);
  }

  // colors

  for (var i = 0, il = colors2.length; i < il; i++) {
    colors1.add(colors2[i].clone());
  }

  // faces

  for (var i = 0, il = faces2.length; i < il; i++) {
    var face = faces2[i];
    var normal, color;
    var faceVertexNormals = face.vertexNormals, faceVertexColors = face.vertexColors;

    var faceCopy = Face3(face.a + vertexOffset, face.b + vertexOffset, face.c + vertexOffset, null, null);
    faceCopy.normal.copy(face.normal);

    if (normalMatrix != null) {
      faceCopy.normal.applyMatrix3(normalMatrix).normalize();
    }

    for (var j = 0, jl = faceVertexNormals.length; j < jl; j++) {
      normal = faceVertexNormals[j].clone();

      if (normalMatrix != null) {
        normal.applyMatrix3(normalMatrix).normalize();
      }

      faceCopy.vertexNormals.add(normal);
    }

    faceCopy.color.copy(face.color);

    for (var j = 0, jl = faceVertexColors.length; j < jl; j++) {
      color = faceVertexColors[j];
      faceCopy.vertexColors.add(color.clone());
    }

    faceCopy.materialIndex = face.materialIndex + materialIndexOffset;

    faces1.add(faceCopy);
  }

  // uvs

  for (var i = 0, il = geometry.faceVertexUvs.length; i < il; i++) {
    var faceVertexUvs2 = geometry.faceVertexUvs[i];

    if (faceVertexUvs[i] == null) faceVertexUvs[i] = [];

    for (var j = 0, jl = faceVertexUvs2.length; j < jl; j++) {
      var uvs2 = faceVertexUvs2[j];
      List<three.Vector2> uvsCopy = [];

      for (var k = 0, kl = uvs2.length; k < kl; k++) {
        uvsCopy.add(uvs2[k].clone());
      }

      faceVertexUvs[i]?.add(uvsCopy);
    }
  }
}