public static void BuildPreview
        (
            DB.Element element, MeshingParameters meshingParameters, DB.ViewDetailLevel DetailLevel,
            out Rhino.Display.DisplayMaterial[] materials, out Mesh[] meshes, out Curve[] wires
        )
        {
            DB.Options options = null;
            using (var geometry = element?.GetGeometry(DetailLevel == DB.ViewDetailLevel.Undefined ? DB.ViewDetailLevel.Medium : DetailLevel, out options)) using (options)
                {
                    if (geometry is null)
                    {
                        materials = null;
                        meshes    = null;
                        wires     = null;
                    }
                    else
                    {
                        var categoryMaterial = element.Category?.Material.ToRhino(null);
                        var elementMaterial  = geometry.MaterialElement.ToRhino(categoryMaterial);

                        meshes    = geometry.GetPreviewMeshes(meshingParameters).Where(x => x is object).ToArray();
                        wires     = geometry.GetPreviewWires().Where(x => x is object).ToArray();
                        materials = geometry.GetPreviewMaterials(element.Document, elementMaterial).Where(x => x is object).ToArray();

                        foreach (var mesh in meshes)
                        {
                            mesh.Normals.ComputeNormals();
                        }
                    }
                }
        }
Beispiel #2
0
        protected override void TrySolveInstance(IGH_DataAccess DA)
        {
            DB.Element element = null;
            if (!DA.GetData("Element", ref element))
            {
                return;
            }

            var detailLevel = DB.ViewDetailLevel.Undefined;

            DA.GetData(1, ref detailLevel);
            if (detailLevel == DB.ViewDetailLevel.Undefined)
            {
                detailLevel = DB.ViewDetailLevel.Coarse;
            }

            DB.Options options = null;
            using (var geometry = element?.GetGeometry(detailLevel, out options)) using (options)
                {
                    var list = geometry?.ToRhino().Where(x => x is object).ToList();

                    DA.SetDataList("Geometry", list);
                }
        }
        public static void BuildPreview
        (
            DB.Element element, MeshingParameters meshingParameters, DB.ViewDetailLevel DetailLevel,
            out Rhino.Display.DisplayMaterial[] materials, out Mesh[] meshes, out Curve[] wires
        )
        {
            DB.Options options = null;
            using (var geometry = element?.GetGeometry(DetailLevel == DB.ViewDetailLevel.Undefined ? DB.ViewDetailLevel.Medium : DetailLevel, out options)) using (options)
                {
                    if (geometry is null)
                    {
                        materials = null;
                        meshes    = null;
                        wires     = null;
                    }
                    else
                    {
                        var categoryMaterial = element.Category?.Material.ToDisplayMaterial(null);
                        var elementMaterial  = geometry.MaterialElement.ToDisplayMaterial(categoryMaterial);

                        meshes    = geometry.GetPreviewMeshes(meshingParameters).Where(x => x is object).ToArray();
                        wires     = geometry.GetPreviewWires().Where(x => x is object).ToArray();
                        materials = geometry.GetPreviewMaterials(element.Document, elementMaterial).Where(x => x is object).ToArray();

                        if (meshes.Length == 0 && wires.Length == 0 && element.get_BoundingBox(null) is DB.BoundingBoxXYZ)
                        {
                            var subMeshes    = new List <Mesh>();
                            var subWires     = new List <Curve>();
                            var subMaterials = new List <Rhino.Display.DisplayMaterial>();

                            foreach (var dependent in element.GetDependentElements(null).Select(x => element.Document.GetElement(x)))
                            {
                                if (dependent.get_BoundingBox(null) is null)
                                {
                                    continue;
                                }

                                DB.Options dependentOptions = null;
                                using (var dependentGeometry = dependent?.GetGeometry(DetailLevel == DB.ViewDetailLevel.Undefined ? DB.ViewDetailLevel.Medium : DetailLevel, out dependentOptions)) using (dependentOptions)
                                    {
                                        if (dependentGeometry is object)
                                        {
                                            subMeshes.AddRange(dependentGeometry.GetPreviewMeshes(meshingParameters).Where(x => x is object));
                                            subWires.AddRange(dependentGeometry.GetPreviewWires().Where(x => x is object));
                                            subMaterials.AddRange(dependentGeometry.GetPreviewMaterials(element.Document, elementMaterial).Where(x => x is object));
                                        }
                                    }
                            }

                            meshes    = subMeshes.ToArray();
                            wires     = subWires.ToArray();
                            materials = subMaterials.ToArray();
                        }

                        foreach (var mesh in meshes)
                        {
                            mesh.Normals.ComputeNormals();
                        }
                    }
                }
        }