Esempio n. 1
0
        public static IFCAnyHandle GetOrCreateMaterialStyle(Document document, ExporterIFC exporterIFC, ElementId materialId)
        {
            IFCAnyHandle styleHnd = ExporterCacheManager.MaterialIdToStyleHandleCache.Find(materialId);

            if (styleHnd == null)
            {
                Material material = document.GetElement(materialId) as Material;
                if (material == null)
                {
                    return(null);
                }

                string matName = material.Name;

                Color  color    = material.Color;
                double blueVal  = color.Blue / 255.0;
                double greenVal = color.Green / 255.0;
                double redVal   = color.Red / 255.0;

                IFCFile      file     = exporterIFC.GetFile();
                IFCAnyHandle colorHnd = IFCInstanceExporter.CreateColourRgb(file, null, redVal, greenVal, blueVal);

                double  transparency = ((double)material.Transparency) / 100.0;
                IFCData smoothness   = IFCDataUtil.CreateAsNormalisedRatioMeasure(((double)material.Smoothness) / 100.0);

                IFCData specularExp = IFCDataUtil.CreateAsSpecularExponent(material.Shininess);

                IFCReflectanceMethod method = IFCReflectanceMethod.NotDefined;

                IFCAnyHandle renderingHnd = IFCInstanceExporter.CreateSurfaceStyleRendering(file, colorHnd, transparency,
                                                                                            null, null, null, null, smoothness, specularExp, method);

                ICollection <IFCAnyHandle> surfStyles = new HashSet <IFCAnyHandle>();
                surfStyles.Add(renderingHnd);

                IFCSurfaceSide surfSide = IFCSurfaceSide.Both;
                styleHnd = IFCInstanceExporter.CreateSurfaceStyle(file, matName, surfSide, surfStyles);
                ExporterCacheManager.MaterialIdToStyleHandleCache.Register(materialId, styleHnd);
            }

            return(styleHnd);
        }
      /// <summary>
      /// Creates a handle representing an IfcSurfaceStyleRendering and assigns it to the file.
      /// </summary>
      /// <param name="file">The file.</param>
      /// <param name="surfaceColour">The optional surface colour.</param>
      /// <param name="transparency">The optional transparency.</param>
      /// <param name="diffuseColour">The optional diffuse colour, as a handle or normalised ratio.</param>
      /// <param name="transmissionColour">The optional transmission colour, as a handle or normalised ratio.</param>
      /// <param name="diffuseTransmissionColour">The optional diffuse transmission colour, as a handle or normalised ratio.</param>
      /// <param name="reflectionColour">The optional reflection colour, as a handle or normalised ratio.</param>
      /// <param name="specularColour">The optional specular colour, as a handle or normalised ratio.</param>
      /// <param name="specularHighlight">The optional specular highlight, as a handle or normalised ratio.</param>
      /// <param name="method">The reflectance method.</param>
      /// <returns>The handle.</returns>
      public static IFCAnyHandle CreateSurfaceStyleRendering(IFCFile file, IFCAnyHandle surfaceColour,
          double? transparency, IFCData diffuseColour,
          IFCData transmissionColour, IFCData diffuseTransmissionColour,
          IFCData reflectionColour, IFCData specularColour, IFCData specularHighlight, IFCReflectanceMethod method)
      {
         ValidSurfaceStyleShading(surfaceColour);

         IFCAnyHandle surfaceStyleRendering = CreateInstance(file, IFCEntityType.IfcSurfaceStyleRendering);
         SetSurfaceStyleShading(surfaceStyleRendering, surfaceColour);
         IFCAnyHandleUtil.SetAttribute(surfaceStyleRendering, "Transparency", transparency);
         IFCAnyHandleUtil.SetAttribute(surfaceStyleRendering, "DiffuseColour", diffuseColour);
         IFCAnyHandleUtil.SetAttribute(surfaceStyleRendering, "TransmissionColour", transmissionColour);
         IFCAnyHandleUtil.SetAttribute(surfaceStyleRendering, "DiffuseTransmissionColour", diffuseTransmissionColour);
         IFCAnyHandleUtil.SetAttribute(surfaceStyleRendering, "ReflectionColour", reflectionColour);
         IFCAnyHandleUtil.SetAttribute(surfaceStyleRendering, "SpecularColour", specularColour);
         IFCAnyHandleUtil.SetAttribute(surfaceStyleRendering, "SpecularHighlight", specularHighlight);
         IFCAnyHandleUtil.SetAttribute(surfaceStyleRendering, "ReflectanceMethod", method);

         return surfaceStyleRendering;
      }