expandByObject method

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

Implementation

BoundingBox 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);

  final geometry = object.geometry;

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

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

      union(_box3box);
    }
  }

  final children = object.children;

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

  return this;
}