示例#1
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            // Declare a variable for the input
            Line            line         = new Line();
            GH_CrossSection crossSection = null;
            GH_Material     material     = null;


            // Use the DA object to retrieve the data inside the first input parameter.
            // If the retieval fails (for example if there is no data) we need to abort.
            if (!DA.GetData(0, ref line))
            {
                return;
            }
            if (!DA.GetData(1, ref crossSection))
            {
                return;
            }
            if (!DA.GetData(2, ref material))
            {
                return;
            }



            GH_Beam beam = new GH_Beam(line.From, line.To, crossSection, material);


            DA.SetData(0, beam);
        }
示例#2
0
        public override bool CastTo <Q>(ref Q target)
        {
            if (typeof(Q).IsAssignableFrom(typeof(GH_Material)))
            {
                object ptr = new GH_Material(Value.Material);
                target = (Q)ptr;
                return(true);
            }

            return(false);
        }
示例#3
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            // Declare a variable for the input

            Point3d p0 = new Point3d();
            Point3d p1 = new Point3d();
            Point3d p2 = new Point3d();


            GH_Material material = null;

            double thickness = 0;


            // Use the DA object to retrieve the data inside the first input parameter.
            // If the retieval fails (for example if there is no data) we need to abort.
            if (!DA.GetData(0, ref p0))
            {
                return;
            }
            if (!DA.GetData(1, ref p1))
            {
                return;
            }
            if (!DA.GetData(2, ref p2))
            {
                return;
            }
            if (!DA.GetData(3, ref material))
            {
                return;
            }
            if (!DA.GetData(4, ref thickness))
            {
                return;
            }



            GH_ConstantStrainTriangle triangle = new GH_ConstantStrainTriangle(p0, p1, p2, material, thickness);



            DA.SetData(0, triangle);
        }
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Mesh        mesh      = new Mesh();
            GH_Material material  = null;
            double      thickness = 0;

            // Use the DA object to retrieve the data inside the first input parameter.
            // If the retieval fails (for example if there is no data) we need to abort.
            if (!DA.GetData(0, ref mesh))
            {
                return;
            }
            if (!DA.GetData(1, ref material))
            {
                return;
            }
            if (!DA.GetData(2, ref thickness))
            {
                return;
            }

            List <GH_ConstantStrainTriangle> triangles = new List <GH_ConstantStrainTriangle>();

            foreach (MeshFace face in mesh.Faces)
            {
                if (!face.IsTriangle)
                {
                    continue; //silently skip
                }

                Point3d p0 = mesh.TopologyVertices[face.A];
                Point3d p1 = mesh.TopologyVertices[face.B];
                Point3d p2 = mesh.TopologyVertices[face.C];
                triangles.Add(new GH_ConstantStrainTriangle(p0, p1, p2, material, thickness));
            }

            DA.SetDataList(0, triangles);
        }
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Color  diff      = Color.Aqua;
            string diffText  = "";
            Color  emiss     = Color.Black;
            double shine     = 0;
            Color  spec      = Color.White;
            double trans     = 0;
            string transText = "";
            string bumpText  = "";
            string enviText  = "";

            DA.GetData("Diffuse", ref diff);
            DA.GetData("DiffuseTexture", ref diffText);
            DA.GetData("Emission", ref emiss);
            DA.GetData("Shine", ref shine);
            DA.GetData("Specular", ref spec);
            DA.GetData("Transparency", ref trans);
            DA.GetData("TransparencyTexture", ref transText);
            DA.GetData("BumpTexture", ref bumpText);
            DA.GetData("EnvironmentTexture", ref enviText);

            Rhino.Display.DisplayMaterial matt = new Rhino.Display.DisplayMaterial();

            matt.BackDiffuse = diff;
            matt.Diffuse     = diff;
            if (diffText != "")
            {
                matt.SetBitmapTexture(diffText, true);
            }

            matt.BackTransparency = trans;
            matt.Transparency     = trans;
            if (transText != "")
            {
                matt.SetTransparencyTexture(transText, true);
            }

            if (bumpText != "")
            {
                matt.SetBumpTexture(bumpText, true);
            }

            if (enviText != "")
            {
                matt.SetEnvironmentTexture(enviText, true);
            }

            matt.BackEmission = emiss;
            matt.Emission     = emiss;

            matt.BackSpecular = spec;
            matt.Specular     = spec;

            matt.BackShine = shine;
            matt.Shine     = shine;


            GH_Material material = new GH_Material(matt);

            DA.SetData("Material", material);
        }
示例#6
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            /*
             * Original Version Written by Giulio Piacentino - 2010 11 21 - for Grasshopper 0.8.002
             * Enhanced by Co-de-iT (Alessio) - now bakes on chosen layer(s) and in groups
             */
            GeometryBase obj = null;

            if (!DA.GetData(0, ref obj))
            {
                return;
            }

            string name = "";

            DA.GetData(1, ref name);
            string layer = "";

            DA.GetData(2, ref layer);

            Color color = new Color();

            DA.GetData(3, ref color);
            Object material = new Object();

            DA.GetData(4, ref material);
            int group_n = 0;

            DA.GetData(5, ref group_n);

            bool group = false;

            DA.GetData(6, ref group);
            bool bake_iT = false;

            DA.GetData(7, ref bake_iT);

            if (!bake_iT)
            {
                return;
            }

            //Make new attribute to set name
            Rhino.DocObjects.ObjectAttributes att = new Rhino.DocObjects.ObjectAttributes();

            //Set object name
            if (!string.IsNullOrEmpty(name))
            {
                att.Name = name;
            }

            //Set color
            if (!color.IsEmpty)
            {
                att.ColorSource = Rhino.DocObjects.ObjectColorSource.ColorFromObject; //Make the color type "by object"
                att.ObjectColor = color;

                att.PlotColorSource = Rhino.DocObjects.ObjectPlotColorSource.PlotColorFromObject; //Make the plot color type "by object"
                att.PlotColor       = color;
            }

            // Set group

            if (group)
            {
                Rhino.RhinoDoc.ActiveDoc.Groups.Add(Convert.ToString(group_n));
                att.AddToGroup(group_n);
            }

            //Set layer
            if (!string.IsNullOrEmpty(layer) && Rhino.DocObjects.Layer.IsValidName(layer))
            {
                //Get the current layer index
                Rhino.DocObjects.Tables.LayerTable layerTable = Rhino.RhinoDoc.ActiveDoc.Layers;
                //int layerIndex = layerTable.Find(layer, true);
                int layerIndex = layerTable.FindByFullPath(layer, -1);

                if (layerIndex < 0)                                                //This layer does not exist, we add it
                {
                    Rhino.DocObjects.Layer onlayer = new Rhino.DocObjects.Layer(); //Make a new layer
                    onlayer.Name  = layer;
                    onlayer.Color = Color.Gainsboro;                               // sets new layer color - future dev: choose new layers color

                    layerIndex = layerTable.Add(onlayer);                          //Add the layer to the layer table
                    if (layerIndex > -1)                                           //We managed to add the layer!
                    {
                        att.LayerIndex = layerIndex;
                        //Print("Added new layer to the document at position " + layerIndex + " named " + layer + ". ");
                    }
                    //else
                    //Print("Layer did not add. Try cleaning up your layers."); //This never happened to me.
                }
                else
                {
                    att.LayerIndex = layerIndex; //We simply add to the existing layer
                }
            }


            //Set plotweight
            //if (pWidth > 0)
            //{
            //    att.PlotWeightSource = Rhino.DocObjects.ObjectPlotWeightSource.PlotWeightFromObject;
            //    att.PlotWeight = pWidth;
            //}


            //Set material

            bool materialByName = !string.IsNullOrEmpty(material as string);

            Rhino.Display.DisplayMaterial inMaterial;
            if (material is GH_Material)
            {
                GH_Material gMat = material as GH_Material;
                inMaterial = gMat.Value as Rhino.Display.DisplayMaterial;
            }
            else
            {
                inMaterial = material as Rhino.Display.DisplayMaterial;
            }
            if (material is Color)
            {
                inMaterial = new Rhino.Display.DisplayMaterial((Color)material);
            }
            if (material != null && inMaterial == null && !materialByName)
            {
                if (!(material is string))
                {
                    try //We also resort to try with IConvertible
                    {
                        inMaterial = (Rhino.Display.DisplayMaterial)Convert.ChangeType(material, typeof(Rhino.Display.DisplayMaterial));
                    }
                    catch (InvalidCastException)
                    {
                    }
                }
            }
            if (inMaterial != null || materialByName)
            {
                string matName;

                if (!materialByName)
                {
                    matName = string.Format("D:{0}-E:{1}-S:{2},{3}-T:{4}",
                                            Format(inMaterial.Diffuse),
                                            Format(inMaterial.Emission),
                                            Format(inMaterial.Specular),
                                            inMaterial.Shine.ToString(),
                                            inMaterial.Transparency.ToString()
                                            );
                }
                else
                {
                    matName = (string)material;
                }

                int materialIndex = Rhino.RhinoDoc.ActiveDoc.Materials.Find(matName, true);
                if (materialIndex < 0 && !materialByName)                     //Material does not exist and we have its specs
                {
                    materialIndex = Rhino.RhinoDoc.ActiveDoc.Materials.Add(); //Let's add it
                    if (materialIndex > -1)
                    {
                        //Print("Added new material at position " + materialIndex + " named \"" + matName + "\". ");
                        Rhino.DocObjects.Material m = Rhino.RhinoDoc.ActiveDoc.Materials[materialIndex];
                        m.Name          = matName;
                        m.DiffuseColor  = inMaterial.Diffuse;
                        m.EmissionColor = inMaterial.Emission;
                        //m.ReflectionColor = inMaterial.Specular;
                        m.SpecularColor = inMaterial.Specular;
                        m.Shine         = inMaterial.Shine;
                        m.Transparency  = inMaterial.Transparency;
                        //m.TransparentColor = no equivalent

                        m.CommitChanges();

                        att.MaterialSource = Rhino.DocObjects.ObjectMaterialSource.MaterialFromObject;
                        att.MaterialIndex  = materialIndex;
                    }
                    else
                    {
                        AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Material did not add. Try cleaning up your materials."); //This never happened to me.
                    }
                }
                else if (materialIndex < 0 && materialByName) //Material does not exist and we do not have its specs. We do nothing
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Warning: material name not found. I cannot set the source to this material name. Add a material with name: " + matName);
                }
                else
                {
                    //If this material exists, we do not replace it!
                    att.MaterialSource = Rhino.DocObjects.ObjectMaterialSource.MaterialFromObject;
                    att.MaterialIndex  = materialIndex;
                }
            }

            //Set wire density
            //if (wires == -1 || wires > 0)
            //{
            //    att.WireDensity = wires;
            //}


            //Bake to the right type of object
            switch (obj.ObjectType)
            {
            case Rhino.DocObjects.ObjectType.Brep:
                Rhino.RhinoDoc.ActiveDoc.Objects.AddBrep(obj as Brep, att);
                break;

            case Rhino.DocObjects.ObjectType.Curve:
                Rhino.RhinoDoc.ActiveDoc.Objects.AddCurve(obj as Curve, att);
                break;

            case Rhino.DocObjects.ObjectType.Point:
                Rhino.RhinoDoc.ActiveDoc.Objects.AddPoint((obj as Rhino.Geometry.Point).Location, att);
                break;

            case Rhino.DocObjects.ObjectType.Surface:
                Rhino.RhinoDoc.ActiveDoc.Objects.AddSurface(obj as Surface, att);
                break;

            case Rhino.DocObjects.ObjectType.Mesh:
                Rhino.RhinoDoc.ActiveDoc.Objects.AddMesh(obj as Mesh, att);
                break;

            case Rhino.DocObjects.ObjectType.Extrusion:
                typeof(Rhino.DocObjects.Tables.ObjectTable).InvokeMember("AddExtrusion", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.InvokeMethod, null, Rhino.RhinoDoc.ActiveDoc.Objects, new object[] { obj, att });
                break;

            case Rhino.DocObjects.ObjectType.PointSet:
                Rhino.RhinoDoc.ActiveDoc.Objects.AddPointCloud(obj as Rhino.Geometry.PointCloud, att);     //This is a speculative entry
                break;

            default:
                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "The script does not know how to handle this type of geometry: " + obj.GetType().FullName);
                break;
            }
        }