copy method

dynamic copy(
  1. dynamic source
)

Implementation

copy(source) {
  // reset

  this.vertices = [];
  this.colors = [];
  this.faces = [];
  faceVertexUvs = [[]];
  this.morphTargets = [];
  this.morphNormals = [];
  this.skinWeights = [];
  this.skinIndices = [];
  this.lineDistances = [];
  this.boundingBox = null;
  this.boundingSphere = null;

  // name

  name = source.name;

  // vertices

  var vertices = source.vertices;

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

  // colors

  var colors = source.colors;

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

  // faces

  var faces = source.faces;

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

  // face vertex uvs

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

    if (this.faceVertexUvs[i] == null) {
      this.faceVertexUvs[i] = [];
    }

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

      for (var k = 0, kl = uvs.length; k < kl; k++) {
        var uv = uvs[k];

        uvsCopy.add(uv.clone());
      }

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

  // morph targets

  var morphTargets = source.morphTargets;

  for (var i = 0, il = morphTargets.length; i < il; i++) {
    var morphTarget = MorphTarget(null);
    morphTarget.name = morphTargets[i].name;

    // vertices

    if (morphTargets[i].vertices != null) {
      morphTarget.vertices = [];

      for (var j = 0, jl = morphTargets[i].vertices.length; j < jl; j++) {
        morphTarget.vertices.add(morphTargets[i].vertices[j].clone());
      }
    }

    // normals

    if (morphTargets[i].normals != null) {
      morphTarget.normals = [];

      for (var j = 0, jl = morphTargets[i].normals.length; j < jl; j++) {
        morphTarget.normals.add(morphTargets[i].normals[j].clone());
      }
    }

    this.morphTargets.add(morphTarget);
  }

  // morph normals

  var morphNormals = source.morphNormals;

  for (var i = 0, il = morphNormals.length; i < il; i++) {
    var morphNormal = MorphNormals();

    // vertex normals

    if (morphNormals[i].vertexNormals != null) {
      morphNormal.vertexNormals = [];

      for (var j = 0, jl = morphNormals[i].vertexNormals.length; j < jl; j++) {
        var srcVertexNormal = morphNormals[i].vertexNormals[j];

        Face3 destVertexNormal = Face3(0, 0, 0, null, null);

        destVertexNormal.a = srcVertexNormal.a.clone();
        destVertexNormal.b = srcVertexNormal.b.clone();
        destVertexNormal.c = srcVertexNormal.c.clone();

        morphNormal.vertexNormals.add(destVertexNormal);
      }
    }

    // face normals

    if (morphNormals[i].faceNormals != null) {
      morphNormal.faceNormals = [];

      for (var j = 0, jl = morphNormals[i].faceNormals.length; j < jl; j++) {
        morphNormal.faceNormals.add(morphNormals[i].faceNormals[j].clone());
      }
    }

    this.morphNormals.add(morphNormal);
  }

  // skin weights

  var skinWeights = source.skinWeights;

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

  // skin indices

  var skinIndices = source.skinIndices;

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

  // line distances

  var lineDistances = source.lineDistances;

  for (var i = 0, il = lineDistances.length; i < il; i++) {
    this.lineDistances.add(lineDistances[i]);
  }

  // bounding box

  var boundingBox = source.boundingBox;

  if (boundingBox != null) {
    this.boundingBox = boundingBox.clone();
  }

  // bounding sphere

  var boundingSphere = source.boundingSphere;

  if (boundingSphere != null) {
    this.boundingSphere = boundingSphere.clone();
  }

  // update flags

  elementsNeedUpdate = source.elementsNeedUpdate;
  verticesNeedUpdate = source.verticesNeedUpdate;
  uvsNeedUpdate = source.uvsNeedUpdate;
  normalsNeedUpdate = source.normalsNeedUpdate;
  colorsNeedUpdate = source.colorsNeedUpdate;
  lineDistancesNeedUpdate = source.lineDistancesNeedUpdate;
  groupsNeedUpdate = source.groupsNeedUpdate;

  return this;
}