private void TrafficLight(object sender, RoutedEventArgs e) { if (_prevStyler == null) { _prevStyler = _xpWindow.DrawingControl.DefaultLayerStyler; } var ls2 = new TrafficLightStyler((IfcStore)Model, this) { UseAmber = _useAmber, UseBlue = _useBlue }; ls2.SetColors( XbimColour.FromString(Settings.Default.ColorPass), XbimColour.FromString(Settings.Default.ColorFail), XbimColour.FromString(Settings.Default.ColorWarning), XbimColour.FromString(Settings.Default.ColorNonApplicable) ); ls2.SetFilters( SelectedConcepts(), SelectedExchangeRequirements(), SelectedIfcClasses() ); _xpWindow.DrawingControl.DefaultLayerStyler = ls2; // then reload _xpWindow.DrawingControl.ReloadModel(DrawingControl3D.ModelRefreshOptions.ViewPreserveAll); }
private static Material GetWpfMaterial(Xbim.Common.IModel model, int styleId) { var sStyle = model.Instances[styleId] as IIfcSurfaceStyle; var wpfMaterial = new WpfMaterial(); if (sStyle != null) { XbimTexture texture = XbimTexture.Create(sStyle); texture.DefinedObjectId = styleId; wpfMaterial.CreateMaterial(texture); return(wpfMaterial); } MaterialDictionary defaultMaterial = ModelDataProvider.DefaultMaterials; Material material; if (defaultMaterial.TryGetValue(model.GetType().Name, out material)) { return(material); } var color = new XbimColour("black", 1, 1, 1); wpfMaterial.CreateMaterial(color); return(wpfMaterial); }
public void SetFederationEnvironment(XbimReferencedModel refModel) { var federationColours = new XbimColourMap(StandardColourMaps.Federation); var key = refModel.DocumentInformation.DocumentOwner.RoleName(); _colour = federationColours[key]; }
/// <summary> /// Get the Material of a given element /// </summary> /// <param name="model"></param> /// <param name="styleId"></param> /// <returns></returns> private static Material GetWpfMaterial(IModel model, int styleId) { var sStyle = model.Instances[styleId] as Xbim.Ifc4.Interfaces.IIfcSurfaceStyle; var wpfMaterial = new WpfMaterial(); if (sStyle != null) { var texture = XbimTexture.Create(sStyle); texture.DefinedObjectId = styleId; wpfMaterial.CreateMaterial(texture); return(wpfMaterial); } else { var defautMaterial = Xbim.Presentation.ModelDataProvider.DefaultMaterials; Material material; if (defautMaterial.TryGetValue(model.GetType().Name, out material)) { //((System.Windows.Media.Media3D.DiffuseMaterial)material).Brush.Opacity = opacity; return(material); } else { XbimColour color = new XbimColour("red", 1, 1, 1); wpfMaterial.CreateMaterial(color); return(wpfMaterial); // return defautMaterial["IfcProduct"]; //((System.Windows.Media.Media3D.DiffuseMaterial)mat).Brush.Opacity = opacity; } } }
public void SetColors(XbimColour pass, XbimColour fail, XbimColour warning, XbimColour nonApplicable) { _colourPass = pass; _colourFail = fail; _colourWarning = warning; _colourNa = nonApplicable; }
private void SaveColors(object sender, RoutedEventArgs e) { var tmpCol = new XbimColour( "", SliderR.Value / 255, SliderG.Value / 255, SliderB.Value / 255, SliderA.Value / 255 ); var tag = ((ComboBoxItem)CmbColorGroup.SelectedItem).Tag.ToString(); switch (tag) { case "F": Settings.Default.ColorFail = tmpCol.ToString(); break; case "P": Settings.Default.ColorPass = tmpCol.ToString(); break; case "W": Settings.Default.ColorWarning = tmpCol.ToString(); break; case "N/A": Settings.Default.ColorNonApplicable = tmpCol.ToString(); break; } Settings.Default.Save(); }
public void CreateMaterial(XbimTexture texture) { if (texture.ColourMap.Count > 1) { _material = new MaterialGroup(); _description = "Texture"; bool transparent = true; foreach (var colour in texture.ColourMap) { if (!colour.IsTransparent) { transparent = false; //only transparent if everything is transparent } _description += " " + colour; ((MaterialGroup)_material).Children.Add(MaterialFromColour(colour)); } IsTransparent = transparent; } else if (texture.ColourMap.Count == 1) { XbimColour colour = texture.ColourMap[0]; _material = MaterialFromColour(colour); _description = "Texture " + colour; IsTransparent = colour.IsTransparent; } }
private static Material MaterialFromColour(XbimColour colour) { var col = Color.FromScRgb(colour.Alpha, colour.Red, colour.Green, colour.Blue); Brush brush = new SolidColorBrush(col); // build material Material mat; if (colour.SpecularFactor > 0) { mat = new SpecularMaterial(brush, colour.SpecularFactor * 100); } else if (colour.ReflectionFactor > 0) { mat = new EmissiveMaterial(brush); } else { mat = new DiffuseMaterial(brush); } // freeze and return mat.Freeze(); return(mat); }
/// <summary> /// Generate a Scene /// </summary> /// <param name="model"></param> /// <returns></returns> public XbimScene <XbimMeshGeometry3D, WpfMaterial> GetModelScene(XbimModel model) { //we need a class which implements IXbimRenderMaterial for the material, you might also want to implement a class for Material depending on your needs, //using the WpfMaterial class that then used the Media3D material class as implemented by the XBimXplorer for convenience. XbimScene <XbimMeshGeometry3D, WpfMaterial> scene = new XbimScene <XbimMeshGeometry3D, WpfMaterial>(model); XbimGeometryHandleCollection handles = new XbimGeometryHandleCollection(model.GetGeometryHandles() .Exclude(IfcEntityNameEnum.IFCFEATUREELEMENT)); foreach (var layerContent in handles.GroupByBuildingElementTypes()) { string elementTypeName = layerContent.Key; XbimGeometryHandleCollection layerHandles = layerContent.Value; IEnumerable <XbimGeometryData> geomColl = model.GetGeometryData(layerHandles); XbimColour colour = scene.LayerColourMap[elementTypeName]; XbimMeshLayer <XbimMeshGeometry3D, WpfMaterial> layer = new XbimMeshLayer <XbimMeshGeometry3D, WpfMaterial>(model, colour) { Name = elementTypeName }; //add all content initially into the hidden field foreach (var geomData in geomColl) { layer.AddToHidden(geomData, model); } scene.Add(layer); } return(scene); }
public void Issue52() { // https://github.com/xBimTeam/XbimWindowsUI/issues/52 // var c = new XbimColour("testTransparency", 1f, 1f, 1f, 0.5f); var m = new WpfMaterial(c); Assert.IsTrue(m.IsTransparent); }
private WpfMeshGeometry3D PrepareMesh(XbimColour col) { var matRed = new WpfMaterial(); matRed.CreateMaterial(col); var mg = new WpfMeshGeometry3D(matRed, matRed); return(mg); }
public static Color ToColor(this XbimColour c) { return(new Color() { R = c?.Red ?? 0.75f, G = c?.Green ?? 0.75f, B = c?.Blue ?? 0.75f, A = c?.Alpha ?? 1.0f, }); }
public BimStyle(int styleLabel, float r, float g, float b, float a) { this.styleLabel = styleLabel; this.r = r; this.g = g; this.b = b; this.a = a; color = new Color(r, g, b, a); xbimColour = new XbimColour(r, g, b, a); }
private WpfMaterial GetRandomColorRetainTransparency(WpfMaterial selectedMaterial) { var col = new XbimColour("Some random color", r.NextDouble(), r.NextDouble(), r.NextDouble(), selectedMaterial.IsTransparent ? 0.5 : 1.0 ); return(new WpfMaterial(col)); }
public MyBimColor(int label, float r, float g, float b, float a = 1) { styleLabel = label; this.r = r; this.g = g; this.b = b; this.a = a; color = new Color(r, g, b, a); xbimColour = new XbimColour(label, r, g, b, a); mat = new Material(Shader.Find("Standard")) { color = color }; }
private void GetGeometryData(XbimModel model, IfcProduct product) { var context = new Xbim3DModelContext(model); //TODO: WCS var metre = model.ModelFactors.OneMetre; var units = model.IfcProject.UnitsInContext.Units .Where <IfcSIUnit>(u => u.UnitType == IfcUnitEnum.LENGTHUNIT) .ToList(); string defaultLengthUnit = ""; if (units.Count > 0) { defaultLengthUnit = units.First().GetSymbol(); } var styles = context.SurfaceStyles().ToList(); var productShape = context.ShapeInstancesOf(product) .Where(p => p.RepresentationType != XbimGeometryRepresentationType.OpeningsAndAdditionsExcluded) .Distinct(); if (productShape.Any()) { foreach (var shapeInstance in productShape) { var shapeGeometry = context.ShapeGeometry(shapeInstance.ShapeGeometryLabel); XbimColour style = XbimColour.Default; if (shapeInstance.HasStyle) { style = styles.First(s => s.DefinedObjectId == shapeInstance.StyleLabel).ColourMap.FirstOrDefault(); } Console.WriteLine("--Style: {0}", style); Console.WriteLine("-- x:{0:0.0000} \n-- y:{1:0.0000} \n-- z:{2:0.0000} \n", shapeGeometry.BoundingBox.Location.X, shapeGeometry.BoundingBox.Location.Y, shapeGeometry.BoundingBox.Location.Z); Console.WriteLine("-- sx:{0:0.0000} {3} \n-- sy:{1:0.0000} {3} \n-- sz:{2:0.0000} {3} \n", shapeGeometry.BoundingBox.SizeX, shapeGeometry.BoundingBox.SizeY, shapeGeometry.BoundingBox.SizeZ, defaultLengthUnit); } } }
public XbimMeshLayer <WpfMeshGeometry3D, WpfMaterial> GetLayer( string layerKey, XbimModel model, XbimScene <WpfMeshGeometry3D, WpfMaterial> scene ) { XbimColour colour = _colours[layerKey]; return(new XbimMeshLayer <WpfMeshGeometry3D, WpfMaterial>(model, colour) { Name = layerKey }); }
private Material MaterialFromColour(XbimColour colour) { _description = "Colour " + colour; Color col = Color.FromScRgb(colour.Alpha, colour.Red, colour.Green, colour.Blue); Brush brush = new SolidColorBrush(col); if (colour.SpecularFactor > 0) { return(new SpecularMaterial(brush, colour.SpecularFactor * 100)); } if (colour.ReflectionFactor > 0) { return(new EmissiveMaterial(brush)); } return(new DiffuseMaterial(brush)); }
private void ColorGroupChanged(object sender, SelectionChangedEventArgs e) { XbimColour col = null; var sel = CmbColorGroup.SelectedItem as ComboBoxItem; if (sel?.Tag == null) { return; } var tag = sel.Tag.ToString(); switch (tag) { case "F": col = XbimColour.FromString(Settings.Default.ColorFail); break; case "P": col = XbimColour.FromString(Settings.Default.ColorPass); break; case "W": col = XbimColour.FromString(Settings.Default.ColorWarning); break; case "N/A": col = XbimColour.FromString(Settings.Default.ColorNonApplicable); break; } if (col == null) { return; } try { SliderR.Value = col.Red * 255; SliderG.Value = col.Green * 255; SliderB.Value = col.Blue * 255; SliderA.Value = col.Alpha * 255; } catch (Exception ex) { Debug.Write(ex.Message); } }
public XbimMeshLayer <WpfMeshGeometry3D, WpfMaterial> GetLayer(string layerKey, XbimModel model, XbimScene <WpfMeshGeometry3D, WpfMaterial> scene) { if (layerKey == "Even") { XbimColour colour = new XbimColour("Red", 1.0, 0.0, 0.0, 1); return(new XbimMeshLayer <WpfMeshGeometry3D, WpfMaterial>(model, colour) { Name = layerKey }); } else { XbimColour colour = new XbimColour("Green", 0.0, 1.0, 0.0, 1); return(new XbimMeshLayer <WpfMeshGeometry3D, WpfMaterial>(model, colour) { Name = layerKey }); } }
public void CanPersistColour() { var c = new XbimColour(0.3f, 0.4f, 0.5f, 0.6f); var asString = c.ToString(); var c2 = XbimColour.FromString(asString); var isEqual = c2.Equals(c); Assert.IsTrue(isEqual, "XbimColour ToString Persistency failed."); var custom = "R:0.3 G:0.4 B:0.5 A:0.6"; c2 = XbimColour.FromString(custom); isEqual = c2.Equals(c); Assert.IsTrue(isEqual, "XbimColour ToString Persistency failed."); custom = "R:0,3 G:0,4 B:0,5 A:0,6"; c2 = XbimColour.FromString(custom); isEqual = c2.Equals(c); Assert.IsTrue(isEqual, "XbimColour ToString Persistency failed."); }
public ModelGeometry.Scene.XbimMeshLayer <WpfMeshGeometry3D, WpfMaterial> GetLayer( string layerKey, XbimModel model, XbimScene <WpfMeshGeometry3D, WpfMaterial> scene ) { int iLab; string LayerName = layerKey; bool conversionok = Int32.TryParse(layerKey, out iLab); if (conversionok) { layerKey = model.Instances[iLab].GetType().Name; } XbimColour colour = scene.LayerColourMap[layerKey]; return(new XbimMeshLayer <WpfMeshGeometry3D, WpfMaterial>(model, colour) { Name = LayerName }); }
public void CreateMaterial(XbimColour colour) { _material = MaterialFromColour(colour); _description = "Colour " + colour; IsTransparent = colour.IsTransparent; }
public void CreateMaterial(XbimColour colour) { _material = MaterialFromColour(colour); }
/// <summary> /// Extract Geometries from IFC file. /// </summary> /// <param name="model">IfcStore model.</param> /// <param name="geometries">Geometries data.</param> /// <param name="modelBoundingBox">Bounding box of the ifc model.</param> public static void ExtractGeometries(IfcStore model, ref Dictionary <string, GeometryStore> geometries, ref XbimRect3D modelBoundingBox) { // context is used to extract geometry data var context = new Xbim3DModelContext(model); var meter = context.Model.ModelFactors.OneMeter; context.CreateContext(); // start to extract geometry data var instances = context.ShapeInstances(); XbimColourMap colorMap = new XbimColourMap(); foreach (var instance in instances) // each instance is a mesh { MeshStore meshStore = new MeshStore(); // get the color of this mesh var ss = model.Instances[instance.StyleLabel] as IIfcSurfaceStyle; XbimColour color = XbimColour.DefaultColour; if (ss != null) { var texture = XbimTexture.Create(ss); color = texture.ColourMap.FirstOrDefault(); } else { var styleId = instance.StyleLabel > 0 ? instance.StyleLabel : instance.IfcTypeId; var theType = model.Metadata.GetType((short)styleId); color = colorMap[theType.Name]; } meshStore.Color = string.Format("{0},{1},{2},{3}", (int)(color.Red * 255), (int)(color.Green * 255), (int)(color.Blue * 255), color.Alpha * 255); var geometry = context.ShapeGeometry(instance); var data = (geometry as IXbimShapeGeometryData).ShapeData; // multiple geometry may belong to one product, like frame and glass belong to a ifcwindow var product = model.Instances[instance.IfcProductLabel] as IIfcProduct; if (!geometries.ContainsKey(product.GlobalId)) { geometries.Add(product.GlobalId, new GeometryStore(product.GlobalId, product.Name)); } var geometryStore = geometries[product.GlobalId]; // reading the real geometry data using (var stream = new MemoryStream(data)) { using (var reader = new BinaryReader(stream)) { // triangle the instance and transform it to the correct position var mesh = reader.ReadShapeTriangulation(); mesh = mesh.Transform(instance.Transformation); // geometry data var verticesData = new List <double>(); var normalsData = new List <double>(); var indexesData = new List <int>(); // bouding box for instance. double minX = double.MaxValue, minY = double.MaxValue, minZ = double.MaxValue, maxX = double.MinValue, maxY = double.MinValue, maxZ = double.MinValue; var faces = mesh.Faces as List <XbimFaceTriangulation>; foreach (var face in faces) { foreach (var indice in face.Indices) { indexesData.Add(indice); } foreach (var normal in face.Normals) { normalsData.Add(normal.Normal.X); normalsData.Add(normal.Normal.Y); normalsData.Add(normal.Normal.Z); } } var vertices = mesh.Vertices as List <XbimPoint3D>; foreach (var point in vertices) { double x = point.X / meter, y = point.Y / meter, z = point.Z / meter; verticesData.Add(x); // convert to meter verticesData.Add(y); verticesData.Add(z); // update bounding box minX = Math.Min(minX, x); minY = Math.Min(minY, y); minZ = Math.Min(minZ, z); maxX = Math.Max(maxX, x); maxY = Math.Max(maxY, y); maxZ = Math.Max(maxZ, z); } if (minX == double.MaxValue || minY == double.MaxValue || minZ == double.MaxValue || maxX == double.MinValue || maxY == double.MinValue || maxZ == double.MinValue) { throw new Exception("Invalid Boundingbox"); } // do not trust instance.BoundingBox, it seems to be wrong. XbimRect3D bbox = new XbimRect3D(minX, minY, minZ, maxX - minX, maxY - minY, maxZ - minZ); // update boundingbox of current geometryStore geometryStore.BoundBox = GeometryStore.Union(geometryStore.BoundBox, bbox); // update boundingbox of ifc model modelBoundingBox = GeometryStore.Union(modelBoundingBox, bbox); meshStore.Vertexes = verticesData; meshStore.Normals = normalsData; meshStore.Indexes = indexesData; } } geometryStore.Meshes.Add(meshStore); } }
private static WpfMeshGeometry3D PrepareMesh(XbimColour col) { var wpfMaterial = new WpfMaterial(col); return(new WpfMeshGeometry3D(wpfMaterial, wpfMaterial)); }