Example #1
0
        public SceneData(BimStore3DModel store, IMaterialManager materialManager)
        {
            Meshes             = new List <MeshData>();
            GeometrySources    = new List <GeometrySourceData>();
            ConstructiveMeshes = new List <ConstructiveMeshData>();
            MaterialSources    = new List <MaterialSourceData>();

            //Materials and Textures
            var uniqueTextures = new Dictionary <Guid, TextureSourceData>();

            foreach (var material in materialManager.Materials)
            {
                MaterialSources.Add(new MaterialSourceData(material.Value));

                //Get textures
                var propertyInfos = material.Value.GetType().GetProperties();

                foreach (var propertyInfo in propertyInfos)
                {
                    var attributes = propertyInfo.GetCustomAttributes(typeof(VisualizerTextureMaterialParameter), true);

                    if (attributes.Length > 0)
                    {
                        var texture = (TextureModelEx)propertyInfo.GetValue(material.Value);

                        if (texture != null)
                        {
                            if (!uniqueTextures.ContainsKey(texture.Id))
                            {
                                uniqueTextures.Add(texture.Id, new TextureSourceData(texture));
                            }
                        }
                    }
                }
            }

            TextureSources = uniqueTextures.Values.ToList();

            //Meshes + Geometries + ConstructiveMeshes
            foreach (var item in store.Items)
            {
                foreach (var geometry in item.Geometries)
                {
                    var meshData = new MeshData(geometry);
                    Meshes.Add(meshData);
                    GeometrySources.Add(new GeometrySourceData(meshData, @"GeometrySources"));
                    ConstructiveMeshes.Add(new ConstructiveMeshData(geometry, meshData.Id, geometry.Material.Id));
                }
            }
        }
Example #2
0
 public BimStore3DViewModel(BimStore3DModel model, IMaterialManager materialManager)
 {
     Model = model;
     Items = new ObservableCollection <BimStoreItem3DViewModel>(model.Items.Select(item => new BimStoreItem3DViewModel(item, materialManager)));
 }
Example #3
0
        public BimStore3DModel Load(string fileName)
        {
            var bimStoreItems = new Dictionary <IPersistEntity, List <Tuple <MeshGeometry3D, MaterialModel, XbimMatrix3D> > > (); //ID - ifcProductLabel

            var ifcModel = IfcStore.Open(fileName, null, null,
                                         (progress, state) => { reportProgress?.Invoke(progress, state); },
                                         XbimDBAccess.Exclusive);

            //Prepare
            var modelPosition = new XbimModelPositioning(ifcModel);
            var context       = new Xbim3DModelContext(ifcModel);

            context.CreateContext();

            //Clear materials
            MaterialManager.Clear();

            var materialsByStyleId = new Dictionary <int, MaterialModel>();

            var excludedTypes = GenerateDefaultExclusions(ifcModel, DefaultExcludedTypes);

            using (var geometryStore = ifcModel.ReferencingModel.GeometryStore)
            {
                using (var geometryReader = geometryStore.BeginRead())
                {
                    var shapeInstances = GetShapeInstancesToRender(geometryReader, excludedTypes);

                    foreach (var shapeInstance in shapeInstances)
                    {
                        #region Material

                        var styleId = shapeInstance.StyleLabel > 0
                            ? shapeInstance.StyleLabel
                            : shapeInstance.IfcTypeId * -1;

                        MaterialModel material;
                        if (!materialsByStyleId.ContainsKey(styleId))
                        {
                            material = MaterialModelCreator.Create(ifcModel, shapeInstance.IfcTypeId);
                            materialsByStyleId.Add(styleId, material);
                            MaterialManager.Add(material);
                        }
                        else
                        {
                            material = materialsByStyleId[styleId];
                        }

                        #endregion

                        #region Geometry

                        IXbimShapeGeometryData shapeGeometry =
                            geometryReader.ShapeGeometry(shapeInstance.ShapeGeometryLabel);

                        var geometry3D = new MeshGeometry3D();
                        switch ((XbimGeometryType)shapeGeometry.Format)
                        {
                        case XbimGeometryType.PolyhedronBinary:
                            geometry3D.Read(shapeGeometry.ShapeData);
                            break;

                        case XbimGeometryType.Polyhedron:
                            geometry3D.Read(((XbimShapeGeometry)shapeGeometry).ShapeData);
                            break;
                        }

                        #endregion

                        var ifcProduct = ifcModel.Model.Instances.FirstOrDefault(i => i.EntityLabel == shapeInstance.IfcProductLabel);

                        if (ifcProduct != null)
                        {
                            if (!bimStoreItems.ContainsKey(ifcProduct))
                            {
                                bimStoreItems.Add(ifcProduct, new List <Tuple <MeshGeometry3D, MaterialModel, XbimMatrix3D> >(new []
                                {
                                    new Tuple <MeshGeometry3D, MaterialModel, XbimMatrix3D>(geometry3D, material, XbimMatrix3D.Multiply(modelPosition.Transform, shapeInstance.Transformation)),
                                }));
                            }
                            else
                            {
                                bimStoreItems[ifcProduct].Add(new Tuple <MeshGeometry3D, MaterialModel, XbimMatrix3D>(geometry3D, material, XbimMatrix3D.Multiply(modelPosition.Transform, shapeInstance.Transformation)));
                            }
                        }
                    }
                }
            }

            //Generate model
            var bimStore3D = new BimStore3DModel(context.Model as IfcStore);

            foreach (var bimStoreItem in bimStoreItems)
            {
                bimStore3D.Add(
                    new BimStoreItem3DModel(bimStoreItem.Key,
                                            new List <BimGeometry3DModel>(
                                                bimStoreItem.Value.Select(x =>
                                                                          new BimGeometry3DModel(
                                                                              x.Item1.ToMeshModel(),
                                                                              x.Item2,
                                                                              x.Item3.ToMatrix3D())))));
            }

            return(bimStore3D);
        }