addMaterialIfNeeded method

int addMaterialIfNeeded(
  1. Sp3dMaterial m
)

(en) Add Sp3dMaterial to this object and returns the corresponding index. This method returns the index of the specified material if it already exists and does not add a new material. Adds the specified material if it does not already exist and returns its index. Please note that materials are compared on the basis of content equivalence.

(ja) このオブジェクトにSp3dMaterialを追加し、対応するインデックスを返します。 このメソッドは、指定されたマテリアルが既に存在する場合はそのインデックスを返し、 新しいマテリアルは追加しません。 指定されたマテリアルがまだ存在しない場合は追加し、そのインデックスを返します。 マテリアルの比較は内容の等価性を基準に行われることに注意してください。

  • m : The Sp3dMaterial you want to add to this object.

Implementation

int addMaterialIfNeeded(Sp3dMaterial m) {
  final int r = materials.indexOf(m);
  if (r < 0) {
    final int nowLen = materials.length;
    materials.add(m);
    return nowLen;
  } else {
    return r;
  }
}