Beispiel #1
0
        public static void AddElements(this MeshGeometry3D m, IPersistIfcEntity item, XbimMatrix3D wcsTransform)
        {
            var fromModel = item.ModelOf as XbimModel;

            if (fromModel == null || !(item is IfcProduct))
            {
                return;
            }
            switch (fromModel.GeometrySupportLevel)
            {
            case 2:
                var context = new Xbim3DModelContext(fromModel);

                var productShape = context.ShapeInstancesOf((IfcProduct)item)
                                   .Where(s => s.RepresentationType != XbimGeometryRepresentationType.OpeningsAndAdditionsExcluded)
                                   .ToList();
                if (!productShape.Any() && item is IfcFeatureElement)
                {
                    productShape = context.ShapeInstancesOf((IfcProduct)item)
                                   .Where(
                        s => s.RepresentationType == XbimGeometryRepresentationType.OpeningsAndAdditionsExcluded)
                                   .ToList();
                }

                if (!productShape.Any())
                {
                    return;
                }
                foreach (var shapeInstance in productShape)
                {
                    IXbimShapeGeometryData shapeGeom =
                        context.ShapeGeometry(shapeInstance.ShapeGeometryLabel);
                    switch ((XbimGeometryType)shapeGeom.Format)
                    {
                    case XbimGeometryType.PolyhedronBinary:
                        m.Read(shapeGeom.ShapeData,
                               XbimMatrix3D.Multiply(shapeInstance.Transformation, wcsTransform));
                        break;

                    case XbimGeometryType.Polyhedron:
                        m.Read(((XbimShapeGeometry)shapeGeom).ShapeData,
                               XbimMatrix3D.Multiply(shapeInstance.Transformation, wcsTransform));
                        break;
                    }
                }
                break;

            case 1:
                var xm3d        = new XbimMeshGeometry3D();
                var geomDataSet = fromModel.GetGeometryData(item.EntityLabel, XbimGeometryType.TriangulatedMesh);
                foreach (var geomData in geomDataSet)
                {
                    var gd = geomData.TransformBy(wcsTransform);
                    xm3d.Add(gd);
                }
                m.Add(xm3d);
                break;
            }
        }