Ejemplo n.º 1
0
        public static Material SolidMaterial(string name = "", double density = 0.0, double conductivity = 0.0, double specificHeat = 0.0, double additionalHeatTransfer = 0.0, double vapourResistivity = 0.0, string description = "", Roughness roughness = Roughness.Undefined, double refraction = 0.0, double solarReflectanceExternal = 0.0, double solarReflectanceInternal = 0.0, double solarTransmittance = 0.0, double lightReflectanceExternal = 0.0, double lightReflectanceInternal = 0.0, double lightTransmittance = 0.0, double emissivityExternal = 0.0, double emissivityInternal = 0.0, double specularity = 0.0, double transmittedDiffusivity = 0.0, double transmittedSpecularity = 0.0, bool ignoreInUValueCalculation = false)
        {
            SolidMaterial solidProperties = new SolidMaterial
            {
                Name                      = name,
                Density                   = density,
                Conductivity              = conductivity,
                SpecificHeat              = specificHeat,
                VapourResistivity         = vapourResistivity,
                Description               = description,
                Roughness                 = roughness,
                Refraction                = refraction,
                SolarReflectanceExternal  = solarReflectanceExternal,
                SolarReflectanceInternal  = solarReflectanceInternal,
                SolarTransmittance        = solarTransmittance,
                LightReflectanceExternal  = lightReflectanceExternal,
                LightReflectanceInternal  = lightReflectanceInternal,
                LightTransmittance        = lightTransmittance,
                EmissivityExternal        = emissivityExternal,
                EmissivityInternal        = emissivityInternal,
                Specularity               = specularity,
                TransmittedDiffusivity    = transmittedDiffusivity,
                TransmittedSpecularity    = transmittedSpecularity,
                IgnoreInUValueCalculation = ignoreInUValueCalculation,
            };

            return(BH.Engine.Physical.Create.Material(name, new List <IMaterialProperties> {
                solidProperties
            }));
        }
Ejemplo n.º 2
0
        public static double Absorptance(this Material material)
        {
            if (material == null)
            {
                BH.Engine.Reflection.Compute.RecordError("Cannot query the absorptance of a null material.");
                return(0);
            }

            SolidMaterial materialProperties = material.Properties.Where(x => x is SolidMaterial).FirstOrDefault() as SolidMaterial;

            if (materialProperties == null)
            {
                return(0.0);
            }

            double maxEmissivity = Math.Max(materialProperties.EmissivityExternal, materialProperties.EmissivityInternal);

            if (maxEmissivity > 1 || maxEmissivity < 0)
            {
                BH.Engine.Reflection.Compute.RecordError("Maximum emissivity was greater than 1 or less than 0 and so absorptance cannot be accurately calculated");
                return(0.0);
            }

            return(1 - maxEmissivity);
        }
Ejemplo n.º 3
0
        public static IPrimitive Convert(IObject3D rootItem)
        {
            var tracePrimitives = new List <IPrimitive>();

            foreach (var item in rootItem.VisibleMeshes())
            {
                SolidMaterial partMaterial;
                var           color = item.WorldColor(rootItem);
                if (color.alpha != 0)
                {
                    partMaterial = new SolidMaterial(new ColorF(color.Red0To1, color.Green0To1, color.Blue0To1), .01, 0.0, 2.0);
                }
                else
                {
                    partMaterial = new SolidMaterial(new ColorF(.9, .2, .1), .01, 0.0, 2.0);
                }

                var worldMatrix = item.WorldMatrix(rootItem);

                item.Mesh.AddTracePrimitives(partMaterial, worldMatrix, tracePrimitives);
            }

            // return an empty collection
            return(BoundingVolumeHierarchy.CreateNewHierachy(tracePrimitives));
        }
Ejemplo n.º 4
0
        public static IPrimitive ConvertUnoptomized(Mesh simpleMesh)
        {
            List <IPrimitive> renderCollection = new List <IPrimitive>();

            //SolidMaterial redStuff = new SolidMaterial(new RGBA_Floats(.9, .2, .1), .01, 0.0, 2.0);
            SolidMaterial mhBlueStuff = new SolidMaterial(new ColorF(0, .32, .58), .01, 0.0, 2.0);
            int           index       = 0;

            Vector3[] triangle = new Vector3[3];
            //Mesh simpleMesh = Processors.StlProcessing.Load("complex.stl");
            //Mesh simpleMesh = Processors.StlProcessing.Load("Spider With Base.stl");
            throw new NotImplementedException();
            //foreach (Face face in simpleMesh.Faces)
            //{
            //	foreach (Vertex vertex in face.Vertices())
            //	{
            //		triangle[index++] = vertex.Position;
            //		if (index == 3)
            //		{
            //			index = 0;
            //			renderCollection.Add(new TriangleShape(triangle[0], triangle[1], triangle[2], mhBlueStuff));
            //		}
            //	}
            //}

            //return new UnboundCollection(renderCollection);
        }
Ejemplo n.º 5
0
        public static ITraceable Convert(IObject3D item, MaterialAbstract partMaterial = null)
        {
            var renderCollection = new List <ITraceable>();

            if (partMaterial == null)
            {
                partMaterial = new SolidMaterial(new ColorF(.9, .2, .1), .01, 0.0, 2.0);
            }

            int index    = 0;
            var triangle = new Vector3[3];

            foreach (Mesh mesh in item.VisibleMeshes().Select(i => i.Mesh))
            {
                throw new NotImplementedException();
                //foreach (Face face in mesh.Faces)
                //{
                //	foreach (Vertex vertex in face.Vertices())
                //	{
                //		triangle[index++] = vertex.Position;
                //		if (index == 3)
                //		{
                //			index = 0;
                //			renderCollection.Add(new TriangleShape(triangle[0], triangle[1], triangle[2], partMaterial));
                //		}
                //	}
                //}
            }

            return(BoundingVolumeHierarchy.CreateNewHierachy(renderCollection));
        }
Ejemplo n.º 6
0
        public static IPrimitive Convert(IObject3D item, MaterialAbstract partMaterial = null)
        {
            List <IPrimitive> renderCollection = new List <IPrimitive>();

            if (partMaterial == null)
            {
                partMaterial = new SolidMaterial(new ColorF(.9, .2, .1), .01, 0.0, 2.0);
            }
            int index = 0;

            Vector3[] triangle = new Vector3[3];
            foreach (Mesh mesh in item.VisibleMeshes().Select(i => i.Mesh))
            {
                foreach (Face face in mesh.Faces)
                {
                    foreach (Vertex vertex in face.Vertices())
                    {
                        triangle[index++] = vertex.Position;
                        if (index == 3)
                        {
                            index = 0;
                            renderCollection.Add(new TriangleShape(triangle[0], triangle[1], triangle[2], partMaterial));
                        }
                    }
                }
            }

            return(BoundingVolumeHierarchy.CreateNewHierachy(renderCollection));
        }
Ejemplo n.º 7
0
        public static IPrimitive Convert(PolygonMesh.Mesh simpleMesh, MaterialAbstract partMaterial = null)
        {
            List <IPrimitive> renderCollection = new List <IPrimitive>();

            if (partMaterial == null)
            {
                partMaterial = new SolidMaterial(new RGBA_Floats(.9, .2, .1), .01, 0.0, 2.0);
            }
            int index = 0;

            Vector3[] triangle = new Vector3[3];
            foreach (PolygonMesh.Face face in simpleMesh.Faces)
            {
                foreach (PolygonMesh.Vertex vertex in face.Vertices())
                {
                    triangle[index++] = vertex.Position;
                    if (index == 3)
                    {
                        index = 0;
                        renderCollection.Add(new TriangleShape(triangle[0], triangle[1], triangle[2], partMaterial));
                    }
                }
            }

            return(BoundingVolumeHierarchy.CreateNewHierachy(renderCollection));
        }
    /*
     * public Vector3 NearestTet(Vector3 pos) {
     *      Vector3[] ns = {
     *              new Vector3(-1, 0, 1),
     *              new Vector3(-1, 0, 0),
     *              new Vector3(-1, 0,-1),
     *              new Vector3( 0, 0, 1),
     *              new Vector3( 1, 0, 0),
     *              new Vector3( 0, 0,-1),
     *      };
     *
     *      Vector3i pi = new Vector3i(Mathf.RoundToInt(pos.x*cellScale), 0, Mathf.RoundToInt(pos.z*cellScale));
     *      Vector3[] closest = new Vector3[ns.Length+1];
     *      closest[0] = SuddenlyTetrahedrons(pi.x, pi.y, pi.z);
     *      for(int i = 0; i < ns.Length; i++) {
     *              closest[i+1] = SuddenlyTetrahedrons(pi.x + (int)ns[i].x, pi.y, pi.z + (int)ns[i].z);
     *      }
     *      float d = 100000000;
     *      int ii = 0;
     *      for(int i = 0; i < closest.Length; i++) {
     *              float sm = new Vector3(pos.x-closest[i].x, 0, pos.z-closest[i].z).sqrMagnitude;
     *              if(sm < d) {
     *                      d = sm;
     *                      ii = i;
     *              }
     *      }
     *      return closest[ii]*cellScaleRecip;
     * }
     */

    public bool CellwallArea(Vector3 pos, SolidMaterial check)
    {
        float r = cellScale * 0.5f - cellMembrane * 1.2f;
        float d = 0;

        if (check != SolidMaterial.Epidermis)
        {
            Vector3 nearPos = NearestTet(pos, false);
            d = new Vector3(pos.x - nearPos.x, 0, pos.z - nearPos.z).magnitude;
        }
        else
        {
            Matrix4x4 mat = Matrix4x4.TRS(Vector3.zero, skinRotation, Vector3.one).inverse;
            pos = mat.MultiplyPoint3x4(pos);
            Vector3 local = mat.MultiplyPoint3x4(pos);
            local = new Vector3(Mathf.Round(pos.x * cellScaleRecip * 0.2f) * cellScale * 5f, pos.y, Mathf.Round(pos.z * cellScaleRecip * 5f) * cellScale * 0.2f);
            d     = new Vector3(pos.x - local.x, 0, pos.z - local.z).magnitude;
        }

        bool res = (d > r - cellMembrane * 1.1f) && (d < r + cellMembrane * 1.1f);

        //Debug.DrawRay(pos, new Vector3(pos.x-nearPos.x, 0, pos.z-nearPos.z), Color.green);
        //Vector3 v = Vector3.Cross(new Vector3(pos.x-nearPos.x, 0, pos.z-nearPos.z), Vector3.up).normalized;
        //Debug.DrawRay((nearPos+v*1), (new Vector3(pos.x-nearPos.x, 0, pos.z-nearPos.z).normalized * r), Color.red);
        //Debug.Log("" + (r-cellMembrane) + " < " + d + " < " + (r+cellMembrane) );
        return(res);
    }
Ejemplo n.º 9
0
        public static BHX.Glaze ToGBXGlazed(this BHC.Layer layer)
        {
            if (layer == null || layer.Material == null)
            {
                return(null);
            }
            SolidMaterial transparentProperties = layer.FindMaterial <SolidMaterial>(typeof(SolidMaterial));

            if (transparentProperties == null)
            {
                return(null);
            }

            BHX.Glaze glaze = new BHX.Glaze();

            glaze.ID                 = "glaze-" + layer.Material.Name.Replace(" ", "-").Replace(",", "") + layer.Material.BHoM_Guid.ToString().Substring(0, 5);
            glaze.Name               = layer.Material.Name;
            glaze.Thickness.Value    = Math.Round(layer.Thickness, 4).ToString();
            glaze.Conductivity.Value = transparentProperties.Conductivity.ToString();

            glaze.SolarTransmittance = new BHX.Transmittance {
                Value = Math.Round(transparentProperties.SolarTransmittance, 3).ToString(), Type = "Solar"
            };

            List <BHX.Reflectance> solarReflectance = new List <BHX.Reflectance>();

            solarReflectance.Add(new BHX.Reflectance {
                Value = Math.Round(transparentProperties.SolarReflectanceExternal, 3).ToString(), Type = "ExtSolar"
            });
            solarReflectance.Add(new BHX.Reflectance {
                Value = Math.Round(transparentProperties.SolarReflectanceInternal, 3).ToString(), Type = "IntSolar"
            });
            glaze.SolarReflectance = solarReflectance.ToArray();

            glaze.LightTransmittance = new BHX.Transmittance {
                Value = Math.Round(transparentProperties.LightTransmittance, 3).ToString(), Type = "Visible"
            };

            List <BHX.Reflectance> lightReflectance = new List <BHX.Reflectance>();

            lightReflectance.Add(new BHX.Reflectance {
                Value = Math.Round(transparentProperties.LightReflectanceExternal, 3).ToString(), Type = "ExtVisible"
            });
            lightReflectance.Add(new BHX.Reflectance {
                Value = Math.Round(transparentProperties.LightReflectanceInternal, 3).ToString(), Type = "IntVisible"
            });
            glaze.LightReflectance = lightReflectance.ToArray();

            List <BHX.Emittance> emittance = new List <BHX.Emittance>();

            emittance.Add(new BHX.Emittance {
                Value = Math.Round(transparentProperties.EmissivityExternal, 3).ToString(), Type = "ExtIR"
            });
            emittance.Add(new BHX.Emittance {
                Value = Math.Round(transparentProperties.EmissivityInternal, 3).ToString(), Type = "IntIR"
            });
            glaze.Emittance = emittance.ToArray();

            return(glaze);
        }
Ejemplo n.º 10
0
        /***************************************************/

        public static oM.Physical.Constructions.Construction Construction(this string constructionName, string materialName)
        {
            if (string.IsNullOrEmpty(constructionName) || string.IsNullOrEmpty(materialName))
            {
                return(null);
            }

            string matName = null;

            if (!string.IsNullOrEmpty(materialName))
            {
                matName = string.Format("Default {0} Material", materialName);
            }
            else
            {
                matName = "Default Material";
            }

            SolidMaterial transparentMaterialProperties = new SolidMaterial();

            transparentMaterialProperties.Name = matName;

            oM.Physical.Materials.Material material = new oM.Physical.Materials.Material();
            material.Properties.Add(transparentMaterialProperties);

            oM.Physical.Constructions.Construction construction = new oM.Physical.Constructions.Construction();
            construction.Name = constructionName;

            oM.Physical.Constructions.Layer layer = new oM.Physical.Constructions.Layer();
            layer.Material = material;

            construction.Layers.Add(layer);

            return(construction);
        }
Ejemplo n.º 11
0
        /***************************************************/
        /****        Public methods - Materials         ****/
        /***************************************************/

        public static void CopyCharacteristics(this SolidMaterial toMaterial, Material fromMaterial)
        {
            if (fromMaterial == null)
            {
                toMaterial.NullRevitElementWarning();
                return;
            }

            ElementId elementID = fromMaterial.ThermalAssetId;

            if (elementID == null || elementID == ElementId.InvalidElementId)
            {
                toMaterial.NullThermalAssetWarning();
                return;
            }

            PropertySetElement propertySetElement = fromMaterial.Document.GetElement(elementID) as PropertySetElement;
            ThermalAsset       thermalAsset       = propertySetElement?.GetThermalAsset();

            if (thermalAsset == null)
            {
                Compute.NullThermalAssetWarning(toMaterial);
                return;
            }

            toMaterial.CopyCharacteristics(thermalAsset);
        }
Ejemplo n.º 12
0
        public static IPrimitive ConvertUnoptomized(PolygonMesh.Mesh simpleMesh)
        {
            List <IPrimitive> renderCollection = new List <IPrimitive>();

            //SolidMaterial redStuff = new SolidMaterial(new RGBA_Floats(.9, .2, .1), .01, 0.0, 2.0);
            SolidMaterial mhBlueStuff = new SolidMaterial(new RGBA_Floats(0, .32, .58), .01, 0.0, 2.0);
            int           index       = 0;

            Vector3[] triangle = new Vector3[3];
            //PolygonMesh.Mesh simpleMesh = PolygonMesh.Processors.StlProcessing.Load("complex.stl");
            //PolygonMesh.Mesh simpleMesh = PolygonMesh.Processors.StlProcessing.Load("Spider With Base.stl");
            foreach (PolygonMesh.Face face in simpleMesh.Faces)
            {
                foreach (PolygonMesh.Vertex vertex in face.Vertices())
                {
                    triangle[index++] = vertex.Position;
                    if (index == 3)
                    {
                        index = 0;
                        renderCollection.Add(new TriangleShape(triangle[0], triangle[1], triangle[2], mhBlueStuff));
                    }
                }
            }

            return(new UnboundCollection(renderCollection));
        }
Ejemplo n.º 13
0
        /***************************************************/
        /****               Public Methods              ****/
        /***************************************************/

        public static SolidMaterial SolidMaterialFromRevit(this Material material, RevitSettings settings = null, Dictionary <string, List <IBHoMObject> > refObjects = null)
        {
            if (material == null)
            {
                return(null);
            }

            settings = settings.DefaultIfNull();

            SolidMaterial result = refObjects.GetValue <SolidMaterial>(material.Id.IntegerValue);

            if (result != null)
            {
                return(result);
            }
            else
            {
                result = new SolidMaterial();
            }

            result.Name = material.Name;
            Parameter parameter = material.get_Parameter(BuiltInParameter.ALL_MODEL_DESCRIPTION);

            if (parameter != null)
            {
                result.Description = parameter.AsString();
            }

            result.CopyCharacteristics(material);
            result.SetProperties(material, settings.ParameterSettings);

            refObjects.AddOrReplace(material.Id, result);
            return(result);
        }
Ejemplo n.º 14
0
        private void CalculateIntersectCostsAndSaveToFile()
        {
            int numInterations = 5000000;
            AxisAlignedBoundingBox referenceCostObject = new AxisAlignedBoundingBox(new Vector3(-.5, -.5, -.5), new Vector3(.5, .5, .5));

            Stopwatch timer        = new Stopwatch();
            Vector3   accumulation = new Vector3();

            timer.Start();
            for (int i = 0; i < numInterations; i++)
            {
                accumulation += GetRandomIntersectingRay().directionNormal;
            }
            long notIntersectStuff = timer.ElapsedMilliseconds;

            timer.Restart();
            for (int i = 0; i < numInterations; i++)
            {
                GetRandomIntersectingRay().Intersection(referenceCostObject);
            }
            long referenceMiliseconds = timer.ElapsedMilliseconds;

            SolidMaterial material            = new SolidMaterial(RGBA_Floats.Black, 0, 0, 1);
            long          sphereMiliseconds   = CalculateIntersectCostsForItem(new SphereShape(new Vector3(), .5, material), numInterations);
            long          cylinderMiliseconds = CalculateIntersectCostsForItem(new CylinderShape(.5, 1, material), numInterations);
            long          boxMiliseconds      = CalculateIntersectCostsForItem(new BoxShape(new Vector3(-.5, -.5, -.5), new Vector3(.5, .5, .5), material), numInterations);
            long          planeMiliseconds    = CalculateIntersectCostsForItem(new PlaneShape(new Vector3(0, 0, 1), 0, material), numInterations);
            BaseShape     triangleTest        = new TriangleShape(new Vector3(-1, 0, 0), new Vector3(0, 1, 0), new Vector3(0, 0, 0), material);
            long          triangleMiliseconds = CalculateIntersectCostsForItem(triangleTest, numInterations);

            System.IO.File.WriteAllText("Cost Of Primitive.txt",
                                        "Cost of Primitives"
                                        + "\r\n" + numInterations.ToString("N0") + " intersections per primitive."
                                        + "\r\nTest Overhead: " + notIntersectStuff.ToString()
                                        + GetStringForFile("AABB", referenceMiliseconds, notIntersectStuff)
                                        + GetStringForFile("Sphere", sphereMiliseconds, notIntersectStuff)
                                        + GetStringForFile("Cylider", cylinderMiliseconds, notIntersectStuff)
                                        + GetStringForFile("Box", boxMiliseconds, notIntersectStuff)
                                        + GetStringForFile("Plane", planeMiliseconds, notIntersectStuff)
                                        + GetStringForFile("Triangle", triangleMiliseconds, notIntersectStuff)
                                        );
        }
Ejemplo n.º 15
0
        private static Dictionary <string, BaseMaterial> LoadMtl(string file)
        {
            Dictionary <string, BaseMaterial> materials = new Dictionary <string, BaseMaterial>();
            string       currentName = "";
            BaseMaterial currentMat  = new SolidMaterial();

            foreach (var s in File.ReadAllLines(file))
            {
                if (String.IsNullOrEmpty(s))
                {
                    continue;
                }
                var    lines = Regex.Split(s, @"\s").Where(l => !String.IsNullOrEmpty(l)).ToList();
                string flag  = lines[0];

                if (flag == "newmtl")
                {
                    materials.Add(currentName, currentMat);
                    currentName = Regex.Replace(s, @"\s*newmtl\s*(.*\S)\s*$", "$1");
                    currentMat  = new SolidMaterial();
                }
                else
                if (flag == "map_Kd")
                {
                    var imageName = Regex.Replace(s, @"\s*map_Kd\s*(.*\S)\s*$", "$1");
                    var img       = new CSharpImageLibrary.ImageEngineImage(imageName);
                    currentMat = new TextureMaterial(img);
                }
                else
                if (flag == "Kd")
                {
                    currentMat = new SolidMaterial(Color.FromArgb(0,
                                                                  (int)(double.Parse(lines[1]) * 255),
                                                                  (int)(double.Parse(lines[2]) * 255),
                                                                  (int)(double.Parse(lines[3]) * 255)));
                }
            }
            materials.Add(currentName, currentMat);
            return(materials);
        }
Ejemplo n.º 16
0
        public static IEnergyPlusClass ToEnergyPlus(this SolidMaterial solidMaterial, double thickness)
        {
            Material bhomMaterial = new Material();

            bhomMaterial.Properties.Add(solidMaterial);

            string materialName = solidMaterial.Name == "" ? solidMaterial.BHoM_Guid.ToString() : solidMaterial.Name;

            if (BH.Engine.Environment.Query.IsTransparent(bhomMaterial))
            {
                EPMaterialWindowGlazing eplusMaterial = new EPMaterialWindowGlazing();
                eplusMaterial.Name            = materialName;
                eplusMaterial.OpticalDataType = OpticalDataType.SpectralAverage;
                eplusMaterial.Thickness       = thickness;
                eplusMaterial.SolarTransmittanceAtNormalIncidence          = solidMaterial.SolarTransmittance;
                eplusMaterial.FrontSideSolarReflectanceAtNormalIncidence   = solidMaterial.SolarReflectanceExternal;
                eplusMaterial.BackSideSolarReflectanceAtNormalIncidence    = solidMaterial.SolarReflectanceInternal;
                eplusMaterial.VisibleTransmittanceAtNormalIncidence        = solidMaterial.LightTransmittance;
                eplusMaterial.FrontSideVisibleReflectanceAtNormalIncidence = solidMaterial.LightReflectanceExternal;
                eplusMaterial.BackSideVisibleReflectanceAtNormalIncidence  = solidMaterial.LightReflectanceInternal;
                eplusMaterial.FrontSideInfraredHemisphericalEmissivity     = solidMaterial.EmissivityExternal;
                eplusMaterial.BackSideInfraredHemisphericalEmissivity      = solidMaterial.EmissivityInternal;
                eplusMaterial.Conductivity = solidMaterial.Conductivity;
                return(eplusMaterial);
            }
            else
            {
                EPMaterial eplusMaterial = new EPMaterial();
                eplusMaterial.Name               = materialName;
                eplusMaterial.Roughness          = solidMaterial.Roughness.ToEnergyPlus();
                eplusMaterial.Thickness          = thickness;
                eplusMaterial.Conductivity       = solidMaterial.Conductivity;
                eplusMaterial.Density            = solidMaterial.Density;
                eplusMaterial.SpecificHeat       = solidMaterial.SpecificHeat;
                eplusMaterial.ThermalAbsorptance = solidMaterial.EmissivityExternal;
                eplusMaterial.SolarAbsorptance   = 1 - solidMaterial.SolarReflectanceExternal;
                eplusMaterial.VisibleAbsorptance = 1 - solidMaterial.LightReflectanceExternal;
                return(eplusMaterial);
            }
        }
Ejemplo n.º 17
0
        public static IPrimitive Convert(IObject3D rootItem)
        {
            List <IPrimitive> renderCollection = new List <IPrimitive>();

            foreach (var item in rootItem.VisibleMeshes())
            {
                SolidMaterial partMaterial;
                var           color = item.WorldColor(rootItem);
                if (color.alpha != 0)
                {
                    partMaterial = new SolidMaterial(new ColorF(color.Red0To1, color.Green0To1, color.Blue0To1), .01, 0.0, 2.0);
                }
                else
                {
                    partMaterial = new SolidMaterial(new ColorF(.9, .2, .1), .01, 0.0, 2.0);
                }

                var worldMatrix = item.WorldMatrix(rootItem);
                foreach (Face face in item.Mesh.Faces)
                {
                    if (false)
                    {
                        renderCollection.Add(new MeshFaceTraceable(face, partMaterial, worldMatrix));
                    }
                    else
                    {
                        foreach (var triangle in face.AsTriangles())
                        {
                            renderCollection.Add(new TriangleShape(
                                                     Vector3.Transform(triangle.p0, worldMatrix),
                                                     Vector3.Transform(triangle.p1, worldMatrix),
                                                     Vector3.Transform(triangle.p2, worldMatrix),
                                                     partMaterial));
                        }
                    }
                }
            }

            return(BoundingVolumeHierarchy.CreateNewHierachy(renderCollection));
        }
Ejemplo n.º 18
0
        public static IPrimitive Convert(PolygonMesh.MeshGroup meshGroup, MaterialAbstract partMaterial = null)
        {
            List <IPrimitive> renderCollection = new List <IPrimitive>();

            SolidMaterial otherMaterial = new SolidMaterial(new RGBA_Floats(.1, .2, .9), .01, 0.0, 2.0);

            if (partMaterial == null)
            {
                partMaterial = new SolidMaterial(new RGBA_Floats(.9, .2, .1), .01, 0.0, 2.0);
            }
            int index = 0;

            Vector3[] triangle = new Vector3[3];
            foreach (PolygonMesh.Mesh mesh in meshGroup.Meshes)
            {
                int materialIntdex = MeshMaterialData.Get(mesh).MaterialIndex;
                foreach (PolygonMesh.Face face in mesh.Faces)
                {
                    foreach (PolygonMesh.Vertex vertex in face.Vertices())
                    {
                        triangle[index++] = vertex.Position;
                        if (index == 3)
                        {
                            index = 0;
                            if (materialIntdex == 1)
                            {
                                renderCollection.Add(new TriangleShape(triangle[0], triangle[1], triangle[2], partMaterial));
                            }
                            else
                            {
                                renderCollection.Add(new TriangleShape(triangle[0], triangle[1], triangle[2], otherMaterial));
                            }
                        }
                    }
                }
            }

            return(BoundingVolumeHierarchy.CreateNewHierachy(renderCollection));
        }
Ejemplo n.º 19
0
        public static BHC.Layer ToBHoM(this BHX.Material gbMaterial)
        {
            BHC.Layer     layer = new BHC.Layer();
            SolidMaterial materialProperties = new SolidMaterial();

            try
            {
                layer.Thickness = System.Convert.ToDouble(gbMaterial.Thickness.Value);
                materialProperties.Conductivity = System.Convert.ToDouble(gbMaterial.Conductivity.Value);
                materialProperties.SpecificHeat = System.Convert.ToDouble(gbMaterial.SpecificHeat.Value);
                materialProperties.Density      = System.Convert.ToDouble(gbMaterial.Density.Value);
            }
            catch { }

            BHM.Material material = new BHM.Material();
            material.Name = gbMaterial.Name;

            material.Properties.Add(materialProperties);
            layer.Material = material;

            return(layer);
        }
 public static SolidMaterial Check(Vector3 input)
 {
     lastCheck = i.Check2(input, false);
     return(lastCheck);
 }
Ejemplo n.º 21
0
        /***************************************************/
        /****          Public methods - Assets          ****/
        /***************************************************/

        public static void CopyCharacteristics(this SolidMaterial toMaterial, ThermalAsset fromAsset)
        {
            toMaterial.Conductivity = fromAsset.ThermalConductivity.ToSI(UnitType.UT_HVAC_ThermalConductivity);
            toMaterial.SpecificHeat = fromAsset.SpecificHeat.ToSI(UnitType.UT_HVAC_SpecificHeat);
            toMaterial.Density      = fromAsset.Density.ToSI(UnitType.UT_MassDensity);
        }
 public static SolidMaterial Check(Vector3 input, bool skinFudge)
 {
     lastCheck = i.Check2(input, skinFudge);
     return(lastCheck);
 }
    //public static string lastStr = "";

    public SolidMaterial Check2(Vector3 input, bool skinFudge)
    {
        List <MediumInfo> currentMedium = new List <MediumInfo>();

        RaycastHit[] hits3 = Physics.RaycastAll(new Vector3(input.x, 18.25958f, input.z), Vector3.down, 100, (1 << 14));
        //RaycastHit[] hits2 = Physics.RaycastAll(point+dir*dist, -dir, dist, (1<<14));
        //string strr = "hit: ";
        for (int i = 0; i < hits3.Length; i++)
        {
            RaycastHit hit    = hits3[i];
            MediumInfo medium = hit.collider.GetComponent <MediumInfo>();
            //strr += hit.collider.gameObject.name +", ";

            float fudge = skinFudge ? skinWidthFudge : skinWidthNorm;
            //Debug.Log(fudge);
            if (skinFudge)
            {
                Debug.Log(hit.textureCoord.y);
            }
            if (medium.name == "Flesh" && hit.textureCoord.y < fudge && hit.textureCoord.y > 0.05f)
            {
                if (skinFudge)
                {
                    Debug.Log(hit.textureCoord.y + " < " + fudge);
                }
                MediumInfo nm = null;
                nm = gameObject.GetComponent <MediumInfo>();
                if (!nm)
                {
                    nm = gameObject.AddComponent <MediumInfo>();
                }
                nm.name    = "Epidermis";
                nm.density = 1.3f;
                currentMedium.Add(nm);

                skinRotation = Quaternion.LookRotation(-Vector3.Scale(hit.normal, new Vector3(1, 0, 1)));
                skinPosition = hit.textureCoord.y;
            }
            else if (hit.textureCoord.y < 0.05f)
            {
                if (skinFudge)
                {
                    Debug.Log(hit.textureCoord.y + " < " + 0.05f);
                }
                //Debug.Log(hit.textureCoord.y);
                currentMedium.Add(medium);
            }
        }

        //if(lastStr != strr) Debug.Log(strr );
        ///lastStr = strr;

        string        s = "Air";
        SolidMaterial m = SolidMaterial.Air;

        for (int i = 0; i < currentMedium.Count; i++)
        {
            s = currentMedium[i].name;
        }
        if (s == "Soda")
        {
            m = SolidMaterial.Soda;
        }
        if (s == "Plastic")
        {
            m = SolidMaterial.Plastic;
        }
        if (s == "Steel")
        {
            m = SolidMaterial.Steel;
        }
        if (s == "Flesh")
        {
            m = SolidMaterial.Flesh;
        }
        if (s == "Epidermis")
        {
            m = SolidMaterial.Epidermis;
        }
        if (s == "Wood")
        {
            m = SolidMaterial.Wood;
        }
        if (s == "Chamber")
        {
            m = SolidMaterial.Chamber;
        }

        return(m);
    }
Ejemplo n.º 24
0
 protected BaseShape()
 {
     Position = new Vector(0, 0, 0);
     Material = new SolidMaterial(new Vector(1, 0, 1), 0, 0, 0);
 }