public XbimTexture CreateTexture(IfcSurfaceStyleRendering rendering) { DefinedObjectId = (int)rendering.EntityLabel; ColourMap.Clear(); AddColour(rendering); return(this); }
private static Boolean tryGetColorFromIfcRepresentationItem(IfcRepresentationItem reprItem, out Color color) { color = Color.Black; try { if (reprItem.mStyledByItem != null) { IfcStyledItem ifcStyledItem = reprItem.mStyledByItem; IfcPresentationStyleAssignment sas = (IfcPresentationStyleAssignment)ifcStyledItem.Styles[0]; IfcSurfaceStyle ss = (IfcSurfaceStyle)sas.Styles[0]; IfcSurfaceStyleRendering ssr = (IfcSurfaceStyleRendering)ss.Styles[0]; int alpha = Convert.ToInt32((1 - ssr.Transparency) * 255); color = Color.FromArgb(alpha, ssr.SurfaceColour.Colour); return(true); } } catch (Exception e) { //debug += e.Message + "\n"; } return(false); }
public static Material ToMaterial(this IfcSurfaceStyleRendering r) { MaterialGroup grp = new MaterialGroup(); if (r.DiffuseColour is IfcNormalisedRatioMeasure) { Brush brush = new SolidColorBrush(r.SurfaceColour.ToColor((IfcNormalisedRatioMeasure)r.DiffuseColour)); brush.Opacity = r.Transparency.HasValue ? 1.0 - r.Transparency.Value : 1.0; grp.Children.Add(new DiffuseMaterial(brush)); } else if (r.DiffuseColour is IfcColourRgb) { Brush brush = new SolidColorBrush(((IfcColourRgb)r.DiffuseColour).ToColor()); brush.Opacity = r.Transparency.HasValue ? 1.0 - r.Transparency.Value : 1.0; grp.Children.Add(new DiffuseMaterial(brush)); } else if (r.DiffuseColour == null) { Brush brush = new SolidColorBrush(r.SurfaceColour.ToColor()); brush.Opacity = r.Transparency.HasValue ? 1.0 - r.Transparency.Value : 1.0; grp.Children.Add(new DiffuseMaterial(brush)); } if (r.SpecularColour is IfcNormalisedRatioMeasure) { Brush brush = new SolidColorBrush(r.SurfaceColour.ToColor()); brush.Opacity = r.Transparency.HasValue ? 1.0 - r.Transparency.Value : 1.0; grp.Children.Add(new SpecularMaterial(brush, (IfcNormalisedRatioMeasure)(r.SpecularColour))); } if (r.SpecularColour is IfcColourRgb) { Brush brush = new SolidColorBrush(((IfcColourRgb)r.SpecularColour).ToColor()); brush.Opacity = r.Transparency.HasValue ? 1.0 - r.Transparency.Value : 1.0; grp.Children.Add(new SpecularMaterial(brush, 100.0)); } if (grp.Children.Count == 1) { Material mat = grp.Children[0]; return(mat); } else { return(grp); } }
/// <summary> /// Returns a material corresponding to this surface style, materials are cached in the ModelDataProvider /// </summary> /// <param name = "sStyle"></param> /// <returns></returns> public static Material ToMaterial(this IfcSurfaceStyle sStyle) { //need to change this to return a material group that considers all types of Styles IfcSurfaceStyleRendering rendering = sStyle.Styles.OfType <IfcSurfaceStyleRendering>().FirstOrDefault(); if (rendering != null) { return(rendering.ToMaterial()); } else //try the shading { IfcSurfaceStyleShading shading = sStyle.Styles.OfType <IfcSurfaceStyleShading>().FirstOrDefault(); if (shading != null) { return(shading.ToMaterial()); } } return(null); //no luck }
private void AddColour(IfcSurfaceStyleRendering rendering) { if (rendering.DiffuseColour is IfcNormalisedRatioMeasure) { ColourMap.Add(new XbimColour( rendering.SurfaceColour, rendering.Transparency.HasValue ? 1.0 - rendering.Transparency.Value : 1.0, (IfcNormalisedRatioMeasure)rendering.DiffuseColour )); } else if (rendering.DiffuseColour is IfcColourRgb) { ColourMap.Add(new XbimColour( (IfcColourRgb)rendering.DiffuseColour, rendering.Transparency.HasValue ? 1.0 - rendering.Transparency.Value : 1.0 )); } else if (rendering.DiffuseColour == null) { ColourMap.Add(new XbimColour( rendering.SurfaceColour, rendering.Transparency.HasValue ? 1.0 - rendering.Transparency.Value : 1.0 )); } else if (rendering.SpecularColour is IfcNormalisedRatioMeasure) //getting key duplication on some ifc models so add else if { ColourMap.Add(new XbimColour( rendering.SurfaceColour, rendering.Transparency.HasValue ? 1.0 - rendering.Transparency.Value : 1.0, 1.0, (IfcNormalisedRatioMeasure)(rendering.SpecularColour) )); } else if (rendering.SpecularColour is IfcColourRgb) { ColourMap.Add(new XbimColour( (IfcColourRgb)rendering.SpecularColour, rendering.Transparency.HasValue ? 1.0 - rendering.Transparency.Value : 1.0 )); } }
public static void loadProperties(IfcEntity ifcEntity, IfcProduct ifcProduct) { ifcEntity.ColorMethod = colorMethodType.byEntity; #region Identification ifcEntity.Identification.Add("Model", "nome del file"); ifcEntity.Identification.Add("Name", ifcProduct.Name); ifcEntity.Identification.Add("Type", ifcProduct.ObjectType); ifcEntity.Identification.Add("GUID", ifcProduct.GlobalId); ifcEntity.Identification.Add("KeyWord", ifcProduct.KeyWord); #endregion if (ifcProduct is IfcElement) { IfcElement ifcElement = (IfcElement)ifcProduct; #region Material if (ifcElement.MaterialSelect != null) { if (ifcElement.MaterialSelect is IfcMaterialLayerSetUsage) { IfcMaterialLayerSetUsage mlsu = (IfcMaterialLayerSetUsage)ifcElement.MaterialSelect; //foreach(IfcMaterialLayer ml in mlsu.ForLayerSet.MaterialLayers) IfcMaterialLayerSet mls = mlsu.ForLayerSet; for (int i = 0; i < mls.MaterialLayers.Count; i++) { ifcEntity.Material.Add(i + " " + mls.MaterialLayers[i].Material.Name, mls.MaterialLayers[i].LayerThickness); IfcMaterial ifcMaterial = mls.MaterialLayers[i].Material; if (ifcMaterial.HasRepresentation != null) { IfcMaterialDefinitionRepresentation imdr = ifcMaterial.HasRepresentation; foreach (IfcStyledRepresentation isr in imdr.Representations) { foreach (IfcStyledItem isi in isr.Items) { foreach (IfcPresentationStyleAssignment isas in isi.Styles) // se c'e' presentatio style direttamente { foreach (IfcPresentationStyle ips in isas.Styles) { if (ips is IfcSurfaceStyle) { IfcSurfaceStyle iss = (IfcSurfaceStyle)ips; foreach (var item in iss.Styles) { // vedere IFcSurfaceStyleElementSelect if (item is IfcSurfaceStyleRendering) { IfcSurfaceStyleRendering issr = (IfcSurfaceStyleRendering)item; int alpha = Convert.ToInt32((1 - issr.Transparency) * 255); ifcEntity.Color = Color.FromArgb(alpha, issr.SurfaceColour.Colour); ifcEntity.Identification.Add(i + "C" + mls.MaterialLayers[i].Material.Name, issr.SurfaceColour.Colour.ToString()); } } } else if (ips is IfcCurveStyle) { //ddgfdg } } } //IfcStyledItem ifcStyledItem = reprItem.mStyledByItem; //IfcStyleAssignmentSelect sas = (IfcPresentationStyleAssignment)ifcStyledItem.Styles[0]; //IfcSurfaceStyle ss = (IfcSurfaceStyle)sas.Styles[0]; //IfcSurfaceStyleRendering ssr = (IfcSurfaceStyleRendering)ss.Styles[0]; //color = ssr.SurfaceColour.Colour; } } } } } } } #endregion if (ifcEntity.Color == Color.Black) { Color color; if (defaultColor.TryGetValue(ifcProduct.KeyWord, out color)) { ifcEntity.Color = color; } //else //Debug.Write(ifcElement.KeyWord + " default color not set\n"); } }