merge method Null safety

Sp3dObj merge(
  1. Sp3dObj other
)

(en)Merge another object into this object. This operation is high cost. id, name, author, physics and option values do not change.

(ja)このオブジェクトに別のオブジェクトをマージします。この操作は高コストです。 このオブジェクト固有のパラメータ(id,name,author,physics)とオプション値は変更されません。

  • other : other obj.

Implementation

Sp3dObj merge(Sp3dObj other) {
  Sp3dObj copyOther = other.deepCopy();
  // 追加する各要素のインデックスを変更。
  final int myVerticesLen = this.vertices.length;
  final int myMaterialLen = this.materials.length;
  final int myImageLen = this.images.length;
  for (Sp3dMaterial i in copyOther.materials) {
    if (i.imageIndex != null) {
      i.imageIndex = i.imageIndex! + myImageLen;
    }
  }
  for (Sp3dFragment i in copyOther.fragments) {
    for (Sp3dFace j in i.faces) {
      if (j.materialIndex != null) {
        j.materialIndex = j.materialIndex! + myMaterialLen;
      }
      for (int k = 0; k < j.vertexIndexList.length; k++) {
        j.vertexIndexList[k] += myVerticesLen;
      }
    }
  }
  // 追加
  for (Uint8List i in copyOther.images) {
    this.images.add(i);
  }
  for (Sp3dMaterial i in copyOther.materials) {
    this.materials.add(i);
  }
  for (Sp3dV3D i in copyOther.vertices) {
    this.vertices.add(i);
  }
  for (Sp3dFragment i in copyOther.fragments) {
    this.fragments.add(i);
  }
  return this;
}