using System.Threading.Tasks;
using Xbim.Ifc4.Interfaces;
using Xbim.Common.Geometry;
using Xbim.ModelGeometry.Scene;
public static class Program
public static async Task Main()
await AABBExample.Show();
public static class AABBExample
public static async Task Show()
var filename = "https://github.com/xBimTeam/XbimWebUI/files/10173051/ModernDiningRoom.zip";
filename = @"https://raw.githubusercontent.com/xBimTeam/XbimSamples/master/BasicCreate/SampleHouse.ifc";
using (var model = await LoadModel(filename))
PrintBoundingBoxes(model);
private static void PrintBoundingBoxes(IModel model)
Xbim3DModelContext context = new Xbim3DModelContext(model);
if (model.GeometriesCount == 0)
var furnitures = model.Instances.OfType<IIfcFurniture>();
foreach(var o in furnitures)
var aabb = GetAxisAlignedBoundingBox(o, context);
Console.WriteLine(string.Format("{0} [{1}] #{2}", o.Name ?? "-", o.GetType().Name, o.EntityLabel));
private static Xbim3DRect GetAxisAlignedBoundingBox(IIfcProduct product, Xbim3DModelContext context)
XbimRect3D prodBox = XbimRect3D.Empty;
foreach (var shp in context.ShapeInstancesOf(product))
var bb = shp.BoundingBox;
bb = XbimRect3D.TransformBy(bb, shp.Transformation);
if (prodBox.IsEmpty) prodBox = bb; else prodBox.Union(bb);
private static async Task<IModel> LoadModel(string source)
if (source.StartsWith("http"))
Stream stream = await GetStream(source);
return IfcStore.Open(stream, StorageType.Ifc, Xbim.Common.Step21.XbimSchemaVersion.Ifc4, XbimModelType.MemoryModel);
return IfcStore.Open(source);
private static async Task<Stream> GetStream(string source)
var client = new HttpClient();
var result = await client.GetAsync(source);
var stream = await result.Content.ReadAsStreamAsync();