expandByObject method

Box3 expandByObject(
  1. Object3D object, [
  2. bool precise = false
])

Implementation

Box3 expandByObject(Object3D object, [bool precise = false]) {
  // Computes the world-axis-aligned bounding box of an object (including its children),
  // accounting for both the object's, and children's, world transforms

  object.updateWorldMatrix(false, false);

  var geometry = object.geometry;

  if (geometry != null) {
    if (precise && geometry.attributes.isNotEmpty && geometry.attributes['position'] != null) {
      var position = geometry.attributes['position'];
      for (var i = 0, l = position.count; i < l; i++) {
        _vectorBox3.fromBufferAttribute(position, i).applyMatrix4(object.matrixWorld);
        expandByPoint(_vectorBox3);
      }
    } else {
      if (geometry.boundingBox == null) {
        geometry.computeBoundingBox();
      }

      _box3box.copy(geometry.boundingBox!);
      _box3box.applyMatrix4(object.matrixWorld);

      union(_box3box);
    }
  }

  var children = object.children;

  for (var i = 0, l = children.length; i < l; i++) {
    expandByObject(children[i], precise);
  }

  return this;
}