Пример #1
0
        public static WpfMeshGeometry3D GetGeometry(IPersistEntity selection, XbimMatrix3D modelTransform, WpfMaterial mat)
        {
            var tgt = new WpfMeshGeometry3D(mat, mat);

            tgt.BeginUpdate();
            using (var geomstore = selection.Model.GeometryStore)
            {
                using (var geomReader = geomstore.BeginRead())
                {
                    foreach (var shapeInstance in geomReader.ShapeInstancesOfEntity(selection).Where(x => x.RepresentationType == XbimGeometryRepresentationType.OpeningsAndAdditionsIncluded))
                    {
                        IXbimShapeGeometryData shapegeom = geomReader.ShapeGeometry(shapeInstance.ShapeGeometryLabel);
                        if (shapegeom.Format != (byte)XbimGeometryType.PolyhedronBinary)
                        {
                            continue;
                        }
                        var transform = shapeInstance.Transformation * modelTransform;
                        tgt.Add(
                            shapegeom.ShapeData,
                            shapeInstance.IfcTypeId,
                            shapeInstance.IfcProductLabel,
                            shapeInstance.InstanceLabel,
                            transform,
                            (short)selection.Model.UserDefinedId
                            );
                    }
                }
            }
            tgt.EndUpdate();
            return(tgt);
        }
Пример #2
0
 // attempting to load the shapeGeometry from the database; 
 // 
 internal static WpfMeshGeometry3D GetRepresentationGeometry(Material mat, IEnumerable<IIfcProduct> productContexts, IEnumerable<int> representationLabels, IModel selModel, XbimMatrix3D modelTransform, bool wcsAdjust)
 {
     var placementTree = new XbimPlacementTree(selModel, wcsAdjust);
     var tgt = new WpfMeshGeometry3D(mat, mat);
     tgt.BeginUpdate();
     using (var geomstore = selModel.GeometryStore)
     using (var geomReader = geomstore.BeginRead())
     {
         var matchingGeometries = geomReader.ShapeGeometries.Where(x => representationLabels.Contains(x.IfcShapeLabel));
         foreach (var contextualProduct in productContexts)
         {
             var trsf = placementTree[contextualProduct.ObjectPlacement.EntityLabel];
             foreach (IXbimShapeGeometryData shapegeom in matchingGeometries)
             {
                 if (shapegeom.Format != (byte)XbimGeometryType.PolyhedronBinary)
                     continue;
                 // Debug.WriteLine($"adding {shapegeom.ShapeLabel} at {DateTime.Now.ToLongTimeString()}");
                 var transform = trsf * modelTransform;
                 tgt.Add(
                     shapegeom.ShapeData,
                     453, // shapeInstance.IfcTypeId,
                     contextualProduct.EntityLabel, // shapeInstance.IfcProductLabel,
                     -1, // shapeInstance.InstanceLabel,
                     transform,
                     (short)contextualProduct.Model.UserDefinedId
                 );
             }
         }
     }
     tgt.EndUpdate();
     return tgt;
 }
Пример #3
0
        // attempting to load the shapeGeometry from the database;
        //
        public static WpfMeshGeometry3D GetGeometry(IIfcShapeRepresentation rep, XbimModelPositioningCollection positions, Material mat)
        {
            var placementTree = new XbimPlacementTree(rep.Model);

            var tgt = new WpfMeshGeometry3D(mat, mat);

            tgt.BeginUpdate();
            var prodShapes = rep.OfProductRepresentation.OfType <IIfcProductDefinitionShape>();

            foreach (var prodShape in prodShapes)
            {
                if (prodShape?.ShapeOfProduct == null)
                {
                    continue;
                }
                foreach (var contextualProduct in prodShape?.ShapeOfProduct)
                {
                    var trsf           = placementTree[contextualProduct.ObjectPlacement.EntityLabel];
                    var modelTransform = positions[rep.Model].Transform;
                    using (var geomstore = rep.Model.GeometryStore)
                        using (var geomReader = geomstore.BeginRead())
                        {
                            var dispitems = rep.Items.Select(x => x.EntityLabel);
                            var r2        = geomReader.ShapeGeometries.Where(x => dispitems.Contains(x.IfcShapeLabel));

                            foreach (IXbimShapeGeometryData shapegeom in r2)
                            {
                                if (shapegeom.Format != (byte)XbimGeometryType.PolyhedronBinary)
                                {
                                    continue;
                                }
                                // Debug.WriteLine($"adding {shapegeom.ShapeLabel} at {DateTime.Now.ToLongTimeString()}");
                                var transform = trsf * modelTransform;
                                tgt.Add(
                                    shapegeom.ShapeData,
                                    453,                           // shapeInstance.IfcTypeId,
                                    contextualProduct.EntityLabel, // shapeInstance.IfcProductLabel,
                                    -1,                            // shapeInstance.InstanceLabel,
                                    transform,
                                    (short)rep.Model.UserDefinedId
                                    );
                            }
                        }
                }
            }
            tgt.EndUpdate();
            return(tgt);
        }
Пример #4
0
        public static WpfMeshGeometry3D GetGeometry(EntitySelection selection, XbimModelPositioningCollection positions, Material mat)
        {
            var tgt = new WpfMeshGeometry3D(mat, mat);

            tgt.BeginUpdate();
            foreach (var modelgroup in selection.GroupBy(i => i.Model))
            {
                var model          = modelgroup.Key;
                var modelTransform = positions[model]?.Transform;
                if (modelTransform != null)
                {
                    using (var geomstore = model.GeometryStore)
                        using (var geomReader = geomstore.BeginRead())
                        {
                            foreach (var item in modelgroup)
                            {
                                foreach (var shapeInstance in geomReader.ShapeInstancesOfEntity(item).Where(x => x.RepresentationType != XbimGeometryRepresentationType.OpeningsAndAdditionsExcluded))
                                {
                                    IXbimShapeGeometryData shapegeom = geomReader.ShapeGeometry(shapeInstance.ShapeGeometryLabel);
                                    if (shapegeom.Format != (byte)XbimGeometryType.PolyhedronBinary)
                                    {
                                        continue;
                                    }
                                    var transform = shapeInstance.Transformation * modelTransform;
                                    tgt.Add(
                                        shapegeom.ShapeData,
                                        shapeInstance.IfcTypeId,
                                        shapeInstance.IfcProductLabel,
                                        shapeInstance.InstanceLabel,
                                        transform,
                                        (short)model.UserDefinedId
                                        );
                                }
                            }
                        }
                }
            }
            tgt.EndUpdate();
            return(tgt);
        }
Пример #5
0
        internal static WpfMeshGeometry3D GetRepresentationGeometry2(Material mat, IEnumerable <int> representationLabels, IModel selModel, XbimMatrix3D modelTransform, bool wcsAdjust, XbimShapeGeometry shapegeom, IIfcProduct contextualProduct)
        {
            var placementTree = new XbimPlacementTree(selModel, wcsAdjust);
            var trsf          = placementTree[contextualProduct.ObjectPlacement.EntityLabel];
            var tgt           = new WpfMeshGeometry3D(mat, mat);

            tgt.BeginUpdate();
            if (shapegeom.Format == XbimGeometryType.PolyhedronBinary)
            {
                // Debug.WriteLine($"adding {shapegeom.ShapeLabel} at {DateTime.Now.ToLongTimeString()}");
                var transform = trsf * modelTransform;
                tgt.Add(
                    ((IXbimShapeGeometryData)shapegeom).ShapeData,
                    contextualProduct.ExpressType.TypeId, // shapeInstance.IfcTypeId,
                    contextualProduct.EntityLabel,        // shapeInstance.IfcProductLabel,
                    -1,                                   // shapeInstance.InstanceLabel,
                    transform,
                    (short)contextualProduct.Model.UserDefinedId
                    );
            }
            tgt.EndUpdate();
            return(tgt);
        }
        /// <summary>
        /// This version uses the new Geometry representation
        /// </summary>
        /// <param name="model"></param>
        /// <param name="context"></param>
        /// <param name="exclude">List of type to exclude, by default excplict openings and spaces are excluded if exclude = null</param>
        /// <returns></returns>
        private void BuildScene(Xbim3DModelContext context)
        {
            //get a list of all the unique styles
            Dictionary <int, WpfMaterial>       styles          = new Dictionary <int, WpfMaterial>();
            Dictionary <int, MeshGeometry3D>    shapeGeometries = new Dictionary <int, MeshGeometry3D>();
            Dictionary <int, WpfMeshGeometry3D> meshSets        = new Dictionary <int, WpfMeshGeometry3D>();
            Model3DGroup opaques      = new Model3DGroup();
            Model3DGroup transparents = new Model3DGroup();

            foreach (var shapeGeom in context.ShapeGeometries())
            {
                MeshGeometry3D wpfMesh = new MeshGeometry3D();
                wpfMesh.SetValue(TagProperty, shapeGeom); //don't read the geometry into the mesh yet as we do not know where the instance is located
                shapeGeometries.Add(shapeGeom.ShapeLabel, wpfMesh);
            }


            foreach (var style in context.SurfaceStyles())
            {
                WpfMaterial wpfMaterial = new WpfMaterial();
                wpfMaterial.CreateMaterial(style);
                styles.Add(style.DefinedObjectId, wpfMaterial);
                WpfMeshGeometry3D mg = new WpfMeshGeometry3D(wpfMaterial, wpfMaterial);
                meshSets.Add(style.DefinedObjectId, mg);
                if (style.IsTransparent)
                {
                    transparents.Children.Add(mg);
                }
                else
                {
                    opaques.Children.Add(mg);
                }
            }

            ////if (!styles.Any()) return ; //this should always have something unless the model is empty
            ////double metre = model.ModelFactors.OneMetre;
            ////XbimMatrix3D wcsTransform = XbimMatrix3D.CreateTranslation(_modelTranslation) * XbimMatrix3D.CreateScale((float)(1 / metre));

            ////foreach (var shapeInstance in context.ShapeInstances()
            ////        .Where(s => s.RepresentationType == XbimGeometryRepresentationType.OpeningsAndAdditionsIncluded &&
            ////            !typeof(IfcFeatureElement).IsAssignableFrom(IfcMetaData.GetType(s.IfcTypeId)) &&
            ////            !typeof(IfcSpace).IsAssignableFrom(IfcMetaData.GetType(s.IfcTypeId))))
            ////{
            ////    int styleId = shapeInstance.StyleLabel > 0 ? shapeInstance.StyleLabel : shapeInstance.IfcTypeId * -1;

            ////    //GET THE ACTUAL GEOMETRY
            ////    MeshGeometry3D wpfMesh;
            ////    //see if we have already read it
            ////    if (shapeGeometries.TryGetValue(shapeInstance.ShapeGeometryLabel, out wpfMesh))
            ////    {
            ////        GeometryModel3D mg = new GeometryModel3D(wpfMesh, styles[styleId]);
            ////        mg.SetValue(TagProperty, new XbimInstanceHandle(model, shapeInstance.IfcProductLabel, shapeInstance.IfcTypeId));
            ////        mg.BackMaterial = mg.Material;
            ////        mg.Transform = XbimMatrix3D.Multiply(shapeInstance.Transformation, wcsTransform).ToMatrixTransform3D();
            ////        if (styles[styleId].IsTransparent)
            ////            transparents.Children.Add(mg);
            ////        else
            ////            opaques.Children.Add(mg);
            ////    }
            ////    else //we need to get the shape geometry
            ////    {
            ////        XbimShapeGeometry shapeGeom = context.ShapeGeometry(shapeInstance.ShapeGeometryLabel);
            ////        if (shapeGeom.ReferenceCount > 1) //only store if we are going to use again
            ////        {
            ////            wpfMesh = new MeshGeometry3D();
            ////            wpfMesh.Read(shapeGeom.ShapeData);
            ////            shapeGeometries.Add(shapeInstance.ShapeGeometryLabel, wpfMesh);
            ////            GeometryModel3D mg = new GeometryModel3D(wpfMesh, styles[styleId]);
            ////            mg.SetValue(TagProperty, new XbimInstanceHandle(model, shapeInstance.IfcProductLabel, shapeInstance.IfcTypeId));
            ////            mg.BackMaterial = mg.Material;
            ////            mg.Transform = XbimMatrix3D.Multiply(shapeInstance.Transformation, wcsTransform).ToMatrixTransform3D();
            ////            if (styles[styleId].IsTransparent)
            ////                transparents.Children.Add(mg);
            ////            else
            ////                opaques.Children.Add(mg);
            ////        }
            ////        else //it is a one off, merge it with shapes of a similar material
            ////        {
            ////            WpfMeshGeometry3D mg = meshSets[styleId];
            ////            mg.Add(shapeGeom.ShapeData,
            ////                shapeInstance.IfcTypeId,
            ////                shapeInstance.IfcProductLabel,
            ////                shapeInstance.InstanceLabel,
            ////                XbimMatrix3D.Multiply(shapeInstance.Transformation, wcsTransform), 0);
            ////        }
            ////    }

            ////}

            if (opaques.Children.Any())
            {
                ModelVisual3D mv = new ModelVisual3D();
                mv.Content = opaques;
                Opaques.Children.Add(mv);
                if (_modelBounds.IsEmpty)
                {
                    _modelBounds = mv.Content.Bounds.ToXbimRect3D();
                }
                else
                {
                    _modelBounds.Union(mv.Content.Bounds.ToXbimRect3D());
                }
            }
            if (transparents.Children.Any())
            {
                ModelVisual3D mv = new ModelVisual3D();
                mv.Content = transparents;
                Transparents.Children.Add(mv);
                if (_modelBounds.IsEmpty)
                {
                    _modelBounds = mv.Content.Bounds.ToXbimRect3D();
                }
                else
                {
                    _modelBounds.Union(mv.Content.Bounds.ToXbimRect3D());
                }
            }
        }