Exemplo n.º 1
0
        public static void GetPreview(GH_Document definition, CompoundDrawable compoundDrawable,
                                      Action <IGH_ActiveObject> onNotDrawble = null, Action <IGH_ActiveObject> onSuccessfulExtract = null)
        {
            var meshParameters = definition.PreviewCurrentMeshParameters() ?? Rhino.Geometry.MeshingParameters.Default;
            var isRenderMode   = definition.PreviewMode == GH_PreviewMode.Shaded;

            foreach (var obj in definition.Objects.OfType <IGH_ActiveObject>())
            {
                if (obj.Locked)
                {
                    continue;
                }

                bool isSelected = obj.Attributes.Selected;
                if (definition.PreviewFilter == GH_PreviewFilter.Selected && !isSelected)
                {
                    continue;
                }

                if (obj is IGH_PreviewObject previewObject)
                {
                    if (previewObject.IsPreviewCapable && !previewObject.Hidden)
                    {
                        var geometries = new List <Rhino.Geometry.GeometryBase>();
                        if (obj is IGH_Component component)
                        {
                            foreach (var param in component.Params.Output)
                            {
                                ExtractGeometry(param.VolatileData, ref geometries, isRenderMode, meshParameters);
                            }
                        }
                        else if (obj is IGH_Param param)
                        {
                            ExtractGeometry(param.VolatileData, ref geometries, isRenderMode, meshParameters);
                        }

                        if (geometries.Count != 0)
                        {
                            geometries.ForEach(geom => compoundDrawable.AddDrawable(new PreviewDrawable(geom), isSelected));
                            onSuccessfulExtract?.Invoke(obj);
                        }
                    }
                }
                else
                {
                    onNotDrawble?.Invoke(obj);
                }
            }
        }
Exemplo n.º 2
0
        void DrawData(Grasshopper.Kernel.Data.IGH_Structure volatileData, IGH_DocumentObject docObject)
        {
            if (!volatileData.IsEmpty)
            {
                foreach (var value in volatileData.AllData(true))
                {
                    // First check for IGH_PreviewData to discard no graphic elements like strings, doubles, vectors...
                    if (value is IGH_PreviewData)
                    {
                        switch (value.ScriptVariable())
                        {
                        case Rhino.Geometry.Point3d point:    primitives.Add(new ParamPrimitive(docObject, new Rhino.Geometry.Point(point))); break;

                        case Rhino.Geometry.Line line:        primitives.Add(new ParamPrimitive(docObject, new Rhino.Geometry.LineCurve(line))); break;

                        case Rhino.Geometry.Rectangle3d rect: primitives.Add(new ParamPrimitive(docObject, rect.ToNurbsCurve())); break;

                        case Rhino.Geometry.Arc arc:          primitives.Add(new ParamPrimitive(docObject, new Rhino.Geometry.ArcCurve(arc))); break;

                        case Rhino.Geometry.Circle circle:    primitives.Add(new ParamPrimitive(docObject, new Rhino.Geometry.ArcCurve(circle))); break;

                        case Rhino.Geometry.Ellipse ellipse:  primitives.Add(new ParamPrimitive(docObject, ellipse.ToNurbsCurve())); break;

                        case Rhino.Geometry.Curve curve:      primitives.Add(new ParamPrimitive(docObject, curve)); break;

                        case Rhino.Geometry.Mesh mesh:        primitives.Add(new ParamPrimitive(docObject, mesh)); break;

                        case Rhino.Geometry.Box box:          primitives.Add(new ParamPrimitive(docObject, Rhino.Geometry.Mesh.CreateFromBox(box, 1, 1, 1))); break;

                        case Rhino.Geometry.Brep brep:
                        {
                            var previewMesh = new Rhino.Geometry.Mesh();
                            previewMesh.Append(Rhino.Geometry.Mesh.CreateFromBrep(brep, activeDefinition.PreviewCurrentMeshParameters()));
                            //previewMesh.Weld(Rhino.RhinoMath.ToRadians(10.0));

                            primitives.Add(new ParamPrimitive(docObject, previewMesh));
                        }
                        break;
                        }
                    }
                }
            }
        }