startMultiRoomScanning method

Future<MultiRoomScanResult> startMultiRoomScanning()

Scans connected rooms and exports them as one USDZ structure.

The user scans a room, chooses whether to scan another room or finish the structure, and repeats. Apple merges the rooms only when they share a compatible world coordinate space. This method requires iOS 17 or later.

Implementation

Future<MultiRoomScanResult> startMultiRoomScanning() async {
  _ensureOpen();
  final payload = await _channel.startMultiRoomCapture();
  if (payload is! Map) {
    throw const FormatException(
      'RoomPlan returned an invalid structure result.',
    );
  }
  final value = Map<String, dynamic>.from(payload);
  final roomValues = value['rooms'];
  if (roomValues is! List) {
    throw const FormatException('RoomPlan returned no room list.');
  }
  final rooms = roomValues
      .whereType<Map>()
      .map((room) => ScanResult.fromJson(Map<String, dynamic>.from(room)))
      .toList(growable: false);
  final path = value['modelPath']?.toString() ?? '';
  if (rooms.isEmpty || path.trim().isEmpty) {
    throw const FormatException('RoomPlan returned an incomplete structure.');
  }
  final model = File(path);
  if (!await model.exists() || await model.length() == 0) {
    throw FileSystemException(
      'The merged 3D structure was not created.',
      path,
    );
  }
  return MultiRoomScanResult(rooms: rooms, modelFile: model);
}