//Preview meshes in Rhino
        public override void DrawViewportMeshes(IGH_PreviewArgs args)
        {
            if (Hidden)
            {
                return;
            }                                   //if the component is hidden
            if (Locked)
            {
                return;
            }                                    //if the component is locked

            base.DrawViewportMeshes(args);
            base.DrawViewportWires(args);

            Rhino.Display.DisplayMaterial mat = new Rhino.Display.DisplayMaterial(color, 0);

            if (meshes != null)
            {
                foreach (Mesh mesh in meshes)
                {
                    if (mesh != null && mesh.IsValid)
                    {
                        args.Display.DrawMeshShaded(mesh, mat);
                        args.Display.DrawMeshWires(mesh, Color.White);
                    }
                }
            }
        }
Beispiel #2
0
 public void CreateMaterial()
 {
     _material          = new Rhino.Display.DisplayMaterial();
     _material.Diffuse  = DrawUtil.DrawColorSupports;
     _material.Specular = DrawUtil.DrawColorSupports;
     _material.Emission = DrawUtil.DrawColorSupports;
 }
Beispiel #3
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            if (DA.Iteration == 0)
            {
                this.m_items   = new List <GH_CustomPreviewItem>();
                this.m_clipbox = BoundingBox.Empty;
            }
            List <IGH_GeometricGoo> destination2 = new List <IGH_GeometricGoo>();
            Color color = new Color();
            int   seed  = 0;

            if ((DA.GetDataList <IGH_GeometricGoo>(0, destination2) && DA.GetData(1, ref color)) && DA.GetData(2, ref seed))
            {
                Random rand = new Random(DA.Iteration + seed);
                if (DA.Iteration == 0)
                {
                }
                else
                {
                    color = Color.FromArgb(rand.Next(255), rand.Next(255), rand.Next(255));
                }
                for (int i = 0; i < destination2.Count; i++)
                {
                    Rhino.Display.DisplayMaterial material = new Rhino.Display.DisplayMaterial(color);
                    GH_CustomPreviewItem          item     = new GH_CustomPreviewItem
                    {
                        m_obj = (IGH_PreviewData)destination2[i],
                        m_mat = material,
                        m_col = material.Diffuse
                    };
                    this.m_items.Add(item);
                    this.m_clipbox.Union(destination2[i].Boundingbox);
                }
            }
        }
Beispiel #4
0
        public override void DrawViewportMeshes(IGH_PreviewArgs args)
        {
            if (model == null)
            {
                return;
            }

            var errorMaterial = new Rhino.Display.DisplayMaterial(System.Drawing.Color.Red, 0.3);
            var rodMaterial   = new Rhino.Display.DisplayMaterial(System.Drawing.Color.BurlyWood, 0.3);
            var jointMaterial = new Rhino.Display.DisplayMaterial(System.Drawing.Color.Black, 0.3);

            foreach (var i in traversedEdges)
            {
                var conn = model.Edges[i];
                args.Display.DrawMeshShaded(model.RodMeshes[conn], model.ClashedRods.Contains(conn) ? errorMaterial : rodMaterial);
            }

            foreach (var i in traversedVertices)
            {
                var jointMeshes = model.JointMeshes[i];
                foreach (var b in jointMeshes)
                {
                    args.Display.DrawMeshShaded(b, model.ClashedJoints.Contains(i) ? errorMaterial : jointMaterial);
                }
            }
        }
Beispiel #5
0
        /***************************************************/

        public virtual void DrawViewportMeshes(GH_PreviewMeshArgs args)
        {
            if (!m_IsMeshPreviewable)   //Flagged as not previewable - return
            {
                return;
            }

            if (m_PreviewMesh == null)  //No preview mesh set yet
            {
                //Create and store mesh. Will return values for surface type objects (surfaces, breps, meshes etc)
                m_PreviewMesh = Render.ICreatePreviewMesh(m_RhinoGeometry, args.MeshingParameters);

                if (m_PreviewMesh == null)
                {
                    m_IsMeshPreviewable = false;    //If no mesh could be extracted, set flag as not required to check again for the same geometry
                    return;
                }
            }

            if (m_PreviewMesh != null)
            {
                if (m_PreviewMesh.VertexColors.Count > 0)   //If colours are set (RenderMeshes) draw these colours
                {
                    args.Pipeline.DrawMeshFalseColors(m_PreviewMesh);
                }
                else
                {
                    Rhino.Display.DisplayMaterial mat = Render.RenderMaterial(args.Material, m_PreviewMaterial);    //If material is default GH material, BHoM default will be used, if not, default GH material is used.
                    args.Pipeline.DrawMeshShaded(m_PreviewMesh, mat);
                }
            }
        }
Beispiel #6
0
        protected override void OnDynamicDraw(GetPointDrawEventArgs e)
        {
            base.OnDynamicDraw(e);

            Point3d  Origin       = new_brep.UserDictionary.GetPoint3d("CurrentPosition");
            Vector3d OriginVector = new_brep.UserDictionary.GetVector3d("CurrentDirection");

            Point3d currentpoint = e.CurrentPoint;

            Vector3d normal_on_mesh = base_mesh.NormalAt(base_mesh.ClosestMeshPoint(currentpoint, 0));

            Brep moved_brep = new_brep.DuplicateBrep();

            if (OriginVector.IsParallelTo(normal_on_mesh) == 0)
            {
                double   RotationAngle = Vector3d.VectorAngle(OriginVector, normal_on_mesh);
                Vector3d RoationAxis   = Vector3d.CrossProduct(OriginVector, normal_on_mesh);
                moved_brep.Rotate(RotationAngle, RoationAxis, Origin);
            }

            moved_brep.Translate(currentpoint - Origin);
            e.Display.DrawBrepWires(moved_brep, System.Drawing.Color.Red);
            Rhino.Display.DisplayMaterial material = new Rhino.Display.DisplayMaterial(System.Drawing.Color.Red);
            e.Display.DrawBrepShaded(moved_brep, material);
            moved_brep.Dispose();
        }
        internal static IEnumerable <Rhino.Display.DisplayMaterial> GetPreviewMaterials
        (
            this IEnumerable <DB.GeometryObject> geometries,
            DB.Document doc,
            Rhino.Display.DisplayMaterial defaultMaterial
        )
        {
            var scaleFactor = Revit.ModelUnits;

            foreach (var geometry in geometries)
            {
                if (geometry.Visibility != DB.Visibility.Visible)
                {
                    continue;
                }

                switch (geometry)
                {
                case DB.GeometryInstance instance:
                    foreach (var g in instance.GetInstanceGeometry().GetPreviewMaterials(doc, instance.GetInstanceGeometry().MaterialElement.ToRhino(defaultMaterial)))
                    {
                        yield return(g);
                    }
                    break;

                case DB.Mesh mesh:
                    if (mesh.NumTriangles <= 0)
                    {
                        continue;
                    }

                    var sm = doc.GetElement(mesh.MaterialElementId) as DB.Material;
                    yield return(sm.ToRhino(defaultMaterial));

                    break;

                case DB.Solid solid:
                    if (solid.Faces.IsEmpty)
                    {
                        continue;
                    }

                    var  solidFaces           = solid.Faces.OfType <DB.Face>();
                    bool useMultipleMaterials = solidFaces.HasMultipleMaterials();

                    foreach (var face in solidFaces)
                    {
                        var fm = doc.GetElement(face.MaterialElementId) as DB.Material;
                        yield return(fm.ToRhino(defaultMaterial));

                        if (!useMultipleMaterials)
                        {
                            break;
                        }
                    }
                    break;
                }
            }
        }
 public Grasshopper.Kernel.Types.GH_Material GetGHMaterial(string Path)
 {
     Rhino.Display.DisplayMaterial mat = new Rhino.Display.DisplayMaterial();
     mat.SetBitmapTexture(Path, true);
     Grasshopper.Kernel.Types.GH_Material mater = new Grasshopper.Kernel.Types.GH_Material();
     mater.Value = mat;
     return mater;
 }
Beispiel #9
0
        /***************************************************/
        /**** Private Method                            ****/
        /***************************************************/

        private bool SetGeometry()
        {
            ResetPreviewMeshes();   //Clears cashed preview meshes and resets preview flag.

            if (Value == null)
            {
                m_IsMeshPreviewable = false;
                return(true);
            }
            else if (Value is IRender)
            {
                m_RhinoGeometry = (Value as IRender).IToRhino();
                m_Color         = (Value as IRender).Colour;
                BH.oM.Graphics.Texture texture = null;

                if (Value is RenderGeometry)
                {
                    RenderGeometry renderGeom = Value as RenderGeometry;
                    m_Geometry  = renderGeom.Geometry;
                    m_thickness = renderGeom.EdgeThickness;
                    texture     = renderGeom.SurfaceColour;
                }
                else if (Value is RenderCurve)
                {
                    m_thickness = (Value as RenderCurve).Thickness;
                    m_Geometry  = (Value as RenderCurve).Curve;
                }

                if (texture != null)
                {
                    m_PreviewMaterial = texture.ToRhino();
                }
                else
                {
                    double transparency = (255 - m_Color.A) / (double)255;
                    m_PreviewMaterial = new Rhino.Display.DisplayMaterial(m_Color, transparency);
                }
                return(true);
            }
            else if (Value is BHoMObject)
            {
                m_Geometry      = (Value as BHoMObject).IGeometry();
                m_RhinoGeometry = m_Geometry.IToRhino();
                return(true);
            }
            else if (Value is IGeometry)
            {
                m_Geometry      = Value as IGeometry;
                m_RhinoGeometry = m_Geometry.IToRhino();
                return(true);
            }
            else
            {
                m_IsMeshPreviewable = false;
                return(false);
            }
        }
Beispiel #10
0
 protected override void PostDrawObjects(Rhino.Display.DrawEventArgs e)
 {
     if (null != Mesh)
     {
         Rhino.Display.DisplayMaterial material = new Rhino.Display.DisplayMaterial();
         material.Diffuse = System.Drawing.Color.Blue;
         e.Display.DrawMeshShaded(Mesh, material);
     }
 }
Beispiel #11
0
 protected override void PostDrawObjects(Rhino.Display.DrawEventArgs e)
 {
     if (null != Mesh)
     {
         Rhino.Display.DisplayMaterial material = new Rhino.Display.DisplayMaterial();
         material.IsTwoSided  = true;
         material.Diffuse     = System.Drawing.Color.Blue;
         material.BackDiffuse = System.Drawing.Color.Red;
         e.Display.EnableLighting(true);
         e.Display.DrawMeshShaded(Mesh, material);
         e.Display.DrawMeshWires(Mesh, System.Drawing.Color.Black);
     }
 }
Beispiel #12
0
        public void DrawViewportMeshes(IGH_PreviewArgs args)
        {
            IGH_StructureEnumerator data = this.VolatileData.AllData(true);

            Rhino.Display.DisplayMaterial mat = args.ShadeMaterial;
            if (Attributes.Selected)
            {
                mat = args.ShadeMaterial_Selected;
            }

            foreach (IMesh m in data)
            {
                args.Display.DrawMeshShaded(m.RenderMesh, mat);
            }
        }
Beispiel #13
0
 public override void DrawViewportMeshes(IGH_PreviewArgs args)
 {
     if (ready)
     {
         //System.Drawing.Color clr = System.Drawing.Color.FromArgb(120, 120, 120);
         //Rhino.Display.DisplayMaterial mat = new Rhino.Display.DisplayMaterial(clr);
         for (int i = 0; i < panelGeo.Count; i++)
         {
             Rhino.Display.DisplayMaterial mat = new Rhino.Display.DisplayMaterial(colors[i]);
             args.Display.DrawBrepShaded(panelGeo[i], mat);
             args.Display.DrawBrepWires(panelGeo[i], System.Drawing.Color.Black);
             mat.Dispose();
         }
         args.Display.DrawBrepWires(robo, System.Drawing.Color.Black);
     }
 }
Beispiel #14
0
        /// <summary>
        /// Each implementation of GH_Component must provide a public
        /// constructor without any arguments.
        /// Category represents the Tab in which the component will appear,
        /// Subcategory the panel. If you use non-existing tab or panel names,
        /// new tabs/panels will automatically be created.
        /// </summary>
        public ClownfishComponent()
            : base("Clownfish", "C",
                   "Object Selection",
                   "Params", "Clownfish")
        {
            indices                  = new List <int>();
            mouseSelector            = new MouseSelector(this);
            selectionGeometries      = new List <SelectionGeometry>();
            selectionGeometriesStack = new Stack <SelectionGeometry>();
            selectionRetrigger       = true;

            selectThroughObjects = false;
            orderSelection       = true;
            selectFaces          = false;

            display_material = new Rhino.Display.DisplayMaterial(System.Drawing.Color.Yellow);
        }
 public override void DrawViewportMeshes(IGH_PreviewArgs args)
 {
     foreach (var m in _meshes)
     {
         try
         {
             var frontFace = new Rhino.Display.DisplayMaterial(m.FrontFaceColor)
             {
                 IsTwoSided  = true,
                 BackDiffuse = m.BackFaceColor
             };
             args.Display.DrawMeshShaded(m.Mesh, frontFace);
         }
         catch
         {
         }
     }
 }
Beispiel #16
0
        public void DrawViewportMeshes(GH_PreviewMeshArgs args)
        {
            if (!(Value is null))
            {
                Rhino.Display.DisplayMaterial areaLoadMaterial = new Rhino.Display.DisplayMaterial(args.Material);

                System.Drawing.Color col = DrawUtil.DrawColorLoads;

                areaLoadMaterial.Diffuse      = col;
                areaLoadMaterial.Specular     = col;
                areaLoadMaterial.Emission     = col;
                areaLoadMaterial.BackDiffuse  = col;
                areaLoadMaterial.BackSpecular = col;
                areaLoadMaterial.BackEmission = col;

                args.Pipeline.DrawBrepShaded(Value, areaLoadMaterial);
            }
        }
Beispiel #17
0
        public override void DrawViewportMeshes(IGH_PreviewArgs args)
        {
            if (model == null)
            {
                return;
            }

            for (int i = 0; i < utilization.Count; i++)
            {
                var errorMaterial = new Rhino.Display.DisplayMaterial(
                    System.Drawing.Color.FromArgb(0,
                                                  255,
                                                  (int)Math.Max(255 * (1 - utilization[i]), 0),
                                                  (int)Math.Max(255 * (1 - utilization[i]), 0)),
                    0.3);
                var mesh = model.RodMeshes[model.Edges[i]];
                args.Display.DrawMeshShaded(mesh, errorMaterial);
            }
        }
Beispiel #18
0
        /// <summary>
        /// Override default preview behaviour (mesh and wire colors)
        /// </summary>
        public override void DrawViewportMeshes(IGH_PreviewArgs args)
        {
            Rhino.Display.DisplayMaterial mat = new Rhino.Display.DisplayMaterial(Color.FromArgb(255, 255, 255), 0);

            base.DrawViewportMeshes(args);
            base.DrawViewportWires(args);

            if (m_mesh != null)
            {
                foreach (Mesh mesh in m_mesh)
                {
                    if (mesh != null && mesh.IsValid)
                    {
                        args.Display.DrawMeshShaded(mesh, mat);
                        args.Display.DrawMeshWires(mesh, Color.Black);
                    }
                }
            }
        }
        protected override void OnDynamicDraw(GetPointDrawEventArgs e)
        {
            base.OnDynamicDraw(e);
            Point3d current_point = e.CurrentPoint;
            Brep    new_new_brep  = RotateBrep(new_brep, base_mesh, current_point, start_point);
            Color   color         = My_object_functions.GetColor(new_new_brep);
            double  radius        = current_point.DistanceTo(center_point);
            Circle  circle        = new Circle(plane, center_point, radius);
            Line    line1         = new Line(current_point, center_point);
            Line    line2         = new Line(center_point, start_point - center_point, radius);

            e.Display.DrawBrepWires(new_new_brep, color);
            Rhino.Display.DisplayMaterial material = new Rhino.Display.DisplayMaterial(color);
            e.Display.DrawBrepShaded(new_new_brep, material);

            e.Display.DrawCircle(circle, System.Drawing.Color.Black);
            e.Display.DrawLine(line1, System.Drawing.Color.Black);
            //e.Display.DrawLine(line2, System.Drawing.Color.Black);
        }
        /// <summary>
        /// Override default preview behaviour (mesh and wire colors)
        /// </summary>
        public override void DrawViewportMeshes(IGH_PreviewArgs args)
        {
            Rhino.Display.DisplayMaterial mat = new Rhino.Display.DisplayMaterial(Color.FromArgb(255, 255, 255), 0);

            base.DrawViewportMeshes(args);
            base.DrawViewportWires(args);

            if (m_mesh != null)
            {
                foreach (Mesh mesh in m_mesh)
                {
                    if (mesh != null && mesh.IsValid)
                    {
                        args.Display.DrawMeshShaded(mesh, mat);
                        args.Display.DrawMeshWires(mesh, Color.Black);
                    }
                }
            }
            
        }
Beispiel #21
0
        public override void DrawViewportMeshes(IGH_PreviewArgs args)
        {
            //base.DrawViewportMeshes(args);

            //could be a global variable, if needed to be changed by some smiulation
            Material material = new Material();

            material.Transparency = 0.3;
            _mat = new Rhino.Display.DisplayMaterial(material);

            if (_viewFactors != null)
            {
                args.Display.DrawMeshShaded(_viewFactors, _mat);
                //foreach (Mesh msh in _colouredMesh)
                //{
                //    args.Display.DrawMeshShaded(msh, _mat);

                //    //args.Display.DrawMeshFalseColors(msh);
                //}
            }
        }
        protected override void OnDynamicDraw(GetPointDrawEventArgs e)
        {
            base.OnDynamicDraw(e);


            Point3d current_point = e.CurrentPoint;

            List <Sphere> pin_ball_list;

            Brep new_new_brep = MoveBrep(new_brep, base_mesh, current_point, out pin_ball_list);

            Color color = My_object_functions.GetColor(new_new_brep);

            for (int i = 0; i < pin_ball_list.Count; i++)
            {
                e.Display.DrawSphere(pin_ball_list[i], System.Drawing.Color.Red);
            }
            e.Display.DrawBrepWires(new_new_brep, color);
            Rhino.Display.DisplayMaterial material = new Rhino.Display.DisplayMaterial(color);
            e.Display.DrawBrepShaded(new_new_brep, material);
        }
Beispiel #23
0
        public void DrawViewportMeshes(GH_PreviewMeshArgs args)
        {
            if (Value != null)
            {
                System.Drawing.Color          col = args.Material.Diffuse;
                Rhino.Display.DisplayMaterial areaStrcMaterial = new Rhino.Display.DisplayMaterial(args.Material);
                if (!DrawUtil.CheckSelection(col))
                {
                    col = DrawUtil.DrawColorStructuralElements;

                    areaStrcMaterial.Diffuse      = col;
                    areaStrcMaterial.Specular     = col;
                    areaStrcMaterial.Emission     = col;
                    areaStrcMaterial.BackDiffuse  = col;
                    areaStrcMaterial.BackSpecular = col;
                    areaStrcMaterial.BackEmission = col;
                }

                args.Pipeline.DrawBrepShaded(Value, areaStrcMaterial);
            }
        }
Beispiel #24
0
 public override void DrawViewportMeshes(IGH_PreviewArgs args)
 {
     if ((this.m_items != null))
     {
         if (this.Attributes.Selected)
         {
             GH_PreviewMeshArgs args2 = new GH_PreviewMeshArgs(args.Viewport, args.Display, args.ShadeMaterial_Selected, args.MeshingParameters);
             foreach (GH_CustomPreviewItem item in this.m_items)
             {
                 item.m_obj.DrawViewportMeshes(args2);
             }
         }
         else
         {
             foreach (GH_CustomPreviewItem item2 in this.m_items)
             {
                 Rhino.Display.DisplayMaterial lastColor = new Rhino.Display.DisplayMaterial(item2.m_col);
                 GH_PreviewMeshArgs            args3     = new GH_PreviewMeshArgs(args.Viewport, args.Display, lastColor, args.MeshingParameters);
                 item2.m_obj.DrawViewportMeshes(args3);
             }
         }
     }
 }
Beispiel #25
0
        public override void DrawViewportMeshes(IGH_PreviewArgs args)
        {
            if (model == null)
            {
                return;
            }

            var errorMaterial = new Rhino.Display.DisplayMaterial(System.Drawing.Color.Red, 0.3);
            var rodMaterial   = new Rhino.Display.DisplayMaterial(System.Drawing.Color.BurlyWood, 0.3);
            var jointMaterial = new Rhino.Display.DisplayMaterial(System.Drawing.Color.Black, 0.3);

            foreach (var kvp in model.RodMeshes)
            {
                args.Display.DrawMeshShaded(kvp.Value, model.ClashedRods.Contains(kvp.Key) ? errorMaterial : rodMaterial);
            }

            foreach (var kvp in model.JointMeshes)
            {
                foreach (var b in kvp.Value)
                {
                    args.Display.DrawMeshShaded(b, model.ClashedJoints.Contains(kvp.Key) ? errorMaterial : jointMaterial);
                }
            }
        }
Beispiel #26
0
        public override void DrawViewportWires(IGH_PreviewArgs args)
        {
            //base.DrawViewportWires(args);
            int defaultPointRadius = 2;

            for (int n = 0; n < m_obj.Count; n++)
            {
                object obj = m_obj[n];
                Rhino.DocObjects.ObjectAttributes att = m_att[n].Value;
                if (obj == null) continue;
                Type objectType = obj.GetType();
                if (objectType == typeof(Grasshopper.Kernel.Types.GH_Vector))
                {
                    Rhino.Geometry.Vector3d rh_vec = ((Grasshopper.Kernel.Types.GH_Vector)obj).Value;
                    args.Display.DrawArrow(new Rhino.Geometry.Line(new Rhino.Geometry.Point3d(0, 0, 0), new Rhino.Geometry.Point3d(rh_vec)), att.ObjectColor);
                    continue;
                }
                if (objectType == typeof(Grasshopper.Kernel.Types.GH_Point))
                {
                    Rhino.Geometry.Point3d rh_point = ((Grasshopper.Kernel.Types.GH_Point)obj).Value;
                    if (att.PlotWeight == 0) args.Display.DrawPoint(rh_point, Rhino.Display.PointStyle.Simple, defaultPointRadius, att.ObjectColor);
                    else args.Display.DrawPoint(rh_point, Rhino.Display.PointStyle.Simple, (int)att.PlotWeight, att.ObjectColor);
                    continue;
                }
                if (objectType == typeof(Grasshopper.Kernel.Types.GH_Line))
                {
                    Rhino.Geometry.Line rh_line = ((Grasshopper.Kernel.Types.GH_Line)obj).Value;
                    if (att.PlotWeight == 0) args.Display.DrawLine(rh_line, att.ObjectColor);
                    else args.Display.DrawLine(rh_line, att.ObjectColor, (int)att.PlotWeight);
                    continue;
                }
                if (objectType == typeof(Grasshopper.Kernel.Types.GH_Mesh))
                {
                    Rhino.Geometry.Mesh rh_mesh = ((Grasshopper.Kernel.Types.GH_Mesh)obj).Value;
                    Rhino.Display.DisplayMaterial mat = new Rhino.Display.DisplayMaterial(att.ObjectColor, 0.5);
                    args.Display.DrawMeshShaded(rh_mesh, mat);
                    continue;
                }
                if (objectType == typeof(Grasshopper.Kernel.Types.GH_Curve))
                {
                    //TODO: deal with open polylines, curves, non-planar polycurves, etc
                    Rhino.Geometry.Curve rh_curve = ((Grasshopper.Kernel.Types.GH_Curve)obj).Value;

                    Rhino.Geometry.Polyline rh_pline = new Rhino.Geometry.Polyline();
                    if ((rh_curve.IsClosed) && (rh_curve.IsPlanar()) && (rh_curve.TryGetPolyline(out rh_pline)))
                    {
                        bool fill = true;
                        Rhino.Geometry.Intersect.CurveIntersections iev = Rhino.Geometry.Intersect.Intersection.CurveSelf(rh_curve, Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance);
                        if (iev.Count > 0)
                        {
                            AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Found a self-intersecting polygon.  Fills will not be applied.");
                            fill = false;
                        }
                        args.Display.DrawPolygon(rh_pline, att.ObjectColor, false);

                        if (fill)
                        {
                            Rhino.Geometry.Mesh m = Rhino.Geometry.Mesh.CreateFromPlanarBoundary(rh_curve, Rhino.Geometry.MeshingParameters.Smooth);
                            args.Display.DrawMeshShaded(m, new Rhino.Display.DisplayMaterial(att.ObjectColor, 0.5));
                        }
                        continue;
                    }
                }

                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "The component does not know how to handle this type of gh_geometry: " + objectType.FullName);
            }
        }
Beispiel #27
0
 static internal Rhino.Display.DisplayMaterial ToRhino(this Autodesk.Revit.DB.Material material, Rhino.Display.DisplayMaterial parentMaterial)
 {
     return((material == null) ? parentMaterial ?? defaultMaterial :
            new Rhino.Display.DisplayMaterial()
     {
         Diffuse = material.Color.ToRhino(),
         Transparency = material.Transparency / 100.0,
         Shine = material.Shininess / 128.0
     });
 }
        public override void DrawViewportWires(IGH_PreviewArgs args)
        {
            base.DrawViewportWires(args);

            if (this.Hidden || this.Locked)
            {
                return;
            }
            System.Drawing.Color solidClr = !this.Attributes.Selected ? args.ShadeMaterial.Diffuse : args.ShadeMaterial_Selected.Diffuse;

            foreach (var obj in ConvertedObjects)
            {
                if (!(obj is GeometryBase))
                {
                    continue;
                }
                switch ((( GeometryBase )obj).ObjectType)
                {
                case Rhino.DocObjects.ObjectType.Point:
                    args.Display.DrawPoint(((Rhino.Geometry.Point)obj).Location, Rhino.Display.PointStyle.X, 2, solidClr);
                    break;

                case Rhino.DocObjects.ObjectType.Curve:
                    args.Display.DrawCurve(( Curve )obj, solidClr);
                    break;

                case Rhino.DocObjects.ObjectType.Extrusion:
                    Rhino.Display.DisplayMaterial eMaterial = new Rhino.Display.DisplayMaterial(solidClr, 0.5);
                    args.Display.DrawBrepShaded((( Extrusion )obj).ToBrep(), eMaterial);
                    break;

                case Rhino.DocObjects.ObjectType.Brep:
                    Rhino.Display.DisplayMaterial bMaterial = new Rhino.Display.DisplayMaterial(solidClr, 0.5);
                    args.Display.DrawBrepShaded(( Brep )obj, bMaterial);
                    //e.Display.DrawBrepWires((Brep)obj, Color.DarkGray, 1);
                    break;

                case Rhino.DocObjects.ObjectType.Mesh:
                    var mesh = obj as Mesh;
                    if (mesh.VertexColors.Count > 0)
                    {
                        for (int i = 0; i < mesh.VertexColors.Count; i++)
                        {
                            mesh.VertexColors[i] = System.Drawing.Color.FromArgb(100, mesh.VertexColors[i]);
                        }

                        args.Display.DrawMeshFalseColors(mesh);
                    }
                    else
                    {
                        Rhino.Display.DisplayMaterial mMaterial = new Rhino.Display.DisplayMaterial(solidClr, 0.5);
                        args.Display.DrawMeshShaded(mesh, mMaterial);
                    }
                    //e.Display.DrawMeshWires((Mesh)obj, Color.DarkGray);
                    break;

                case Rhino.DocObjects.ObjectType.TextDot:
                    //e.Display.Draw3dText( ((TextDot)obj).Text, Colors[count], new Plane(((TextDot)obj).Point));
                    //todo
                    break;

                case Rhino.DocObjects.ObjectType.Annotation:
                    //todo
                    break;
                }
                // TODO
            }
        }
Beispiel #29
0
 internal Texture(int index, Rhino.Display.DisplayMaterial parent, bool front)
 {
     m_index   = index;
     m__parent = parent;
     m_front   = front;
 }
        public override void DrawViewportWires(IGH_PreviewArgs args)
        {
            //base.DrawViewportWires(args);
            int defaultPointRadius = 2;

            for (int n = 0; n < m_obj.Count; n++)
            {
                object obj = m_obj[n];
                Rhino.DocObjects.ObjectAttributes att = m_att[n].Value;
                if (obj == null)
                {
                    continue;
                }
                Type objectType = obj.GetType();
                if (objectType == typeof(Grasshopper.Kernel.Types.GH_Vector))
                {
                    Rhino.Geometry.Vector3d rh_vec = ((Grasshopper.Kernel.Types.GH_Vector)obj).Value;
                    args.Display.DrawArrow(new Rhino.Geometry.Line(new Rhino.Geometry.Point3d(0, 0, 0), new Rhino.Geometry.Point3d(rh_vec)), att.ObjectColor);
                    continue;
                }
                if (objectType == typeof(Grasshopper.Kernel.Types.GH_Point))
                {
                    Rhino.Geometry.Point3d rh_point = ((Grasshopper.Kernel.Types.GH_Point)obj).Value;
                    if (att.PlotWeight == 0)
                    {
                        args.Display.DrawPoint(rh_point, Rhino.Display.PointStyle.Simple, defaultPointRadius, att.ObjectColor);
                    }
                    else
                    {
                        args.Display.DrawPoint(rh_point, Rhino.Display.PointStyle.Simple, (int)att.PlotWeight, att.ObjectColor);
                    }
                    continue;
                }
                if (objectType == typeof(Grasshopper.Kernel.Types.GH_Line))
                {
                    Rhino.Geometry.Line rh_line = ((Grasshopper.Kernel.Types.GH_Line)obj).Value;
                    if (att.PlotWeight == 0)
                    {
                        args.Display.DrawLine(rh_line, att.ObjectColor);
                    }
                    else
                    {
                        args.Display.DrawLine(rh_line, att.ObjectColor, (int)att.PlotWeight);
                    }
                    continue;
                }
                if (objectType == typeof(Grasshopper.Kernel.Types.GH_Mesh))
                {
                    Rhino.Geometry.Mesh           rh_mesh = ((Grasshopper.Kernel.Types.GH_Mesh)obj).Value;
                    Rhino.Display.DisplayMaterial mat     = new Rhino.Display.DisplayMaterial(att.ObjectColor, 0.5);
                    args.Display.DrawMeshShaded(rh_mesh, mat);
                    continue;
                }
                if (objectType == typeof(Grasshopper.Kernel.Types.GH_Curve))
                {
                    //TODO: deal with open polylines, curves, non-planar polycurves, etc
                    Rhino.Geometry.Curve rh_curve = ((Grasshopper.Kernel.Types.GH_Curve)obj).Value;

                    Rhino.Geometry.Polyline rh_pline = new Rhino.Geometry.Polyline();
                    if ((rh_curve.IsClosed) && (rh_curve.IsPlanar()) && (rh_curve.TryGetPolyline(out rh_pline)))
                    {
                        bool fill = true;
                        Rhino.Geometry.Intersect.CurveIntersections iev = Rhino.Geometry.Intersect.Intersection.CurveSelf(rh_curve, Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance);
                        if (iev.Count > 0)
                        {
                            AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Found a self-intersecting polygon.  Fills will not be applied.");
                            fill = false;
                        }
                        args.Display.DrawPolygon(rh_pline, att.ObjectColor, false);

                        if (fill)
                        {
                            Rhino.Geometry.Mesh m = Rhino.Geometry.Mesh.CreateFromPlanarBoundary(rh_curve, Rhino.Geometry.MeshingParameters.Smooth);
                            args.Display.DrawMeshShaded(m, new Rhino.Display.DisplayMaterial(att.ObjectColor, 0.5));
                        }
                        continue;
                    }
                }

                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "The component does not know how to handle this type of gh_geometry: " + objectType.FullName);
            }
        }
Beispiel #31
0
 public static Rhino.Display.DisplayMaterial ToRhino(this DB.Material material, Rhino.Display.DisplayMaterial parentMaterial) => material.ToDisplayMaterial(parentMaterial);
Beispiel #32
0
 public static Rhino.Display.DisplayMaterial ToRhino(this DB.Material material, Rhino.Display.DisplayMaterial parentMaterial)
 {
     return((material is null) ? parentMaterial ?? defaultMaterial :
            new Rhino.Display.DisplayMaterial()
     {
         Diffuse = material.Color.ToRhino(),
         Transparency = material.Transparency / 100.0,
         Shine = material.Shininess / 128.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)
        {
            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);
        }
 public Rhino.Display.DisplayMaterial GetRHMaterial(string Path)
 {
     Rhino.Display.DisplayMaterial mat = new Rhino.Display.DisplayMaterial();
     mat.SetBitmapTexture(Path, true);
     return mat;
 }