diff --git a/doc/gh_DFBrepToCloud.rst b/doc/gh_DFBrepToCloud.rst new file mode 100644 index 00000000..3f4e7db7 --- /dev/null +++ b/doc/gh_DFBrepToCloud.rst @@ -0,0 +1,8 @@ +.. image:: ../src/gh/components/DF_brep_to_cloud/icon.png + :align: left + :width: 40px + +``DFBrepToCloud`` component +=========================== + +.. ghcomponent_to_rst:: ../src/gh/components/DF_brep_to_cloud \ No newline at end of file diff --git a/doc/gh_components.rst b/doc/gh_components.rst index 202fa923..02ae96b3 100644 --- a/doc/gh_components.rst +++ b/doc/gh_components.rst @@ -76,6 +76,11 @@ DF has a Grasshopper_ plugin with a set of components that allows the user to in - .. image:: ../src/gh/components/DF_colorize_cloud/icon.png - `gh_DFColorizeCloud `_ + * - .. image:: ../src/gh/components/DF_brep_to_cloud/icon.png + - `gh_DFBrepToCloud `_ + - + - + .. toctree:: @@ -107,4 +112,5 @@ DF has a Grasshopper_ plugin with a set of components that allows the user to in gh_DFXMLExporter gh_DFPreviewAssembly gh_DFRemoveBeam - gh_DFColorizeCloud \ No newline at end of file + gh_DFColorizeCloud + gh_DFBrepToCloud \ No newline at end of file diff --git a/src/gh/components/DF_brep_to_cloud/code.py b/src/gh/components/DF_brep_to_cloud/code.py new file mode 100644 index 00000000..6d68bb4d --- /dev/null +++ b/src/gh/components/DF_brep_to_cloud/code.py @@ -0,0 +1,38 @@ +#! python3 + +import Rhino +from ghpythonlib.componentbase import executingcomponent as component +from Grasshopper.Kernel import GH_RuntimeMessageLevel as RML + +from diffCheck import df_cvt_bindings +import System + + +class DFBrepToCloud(component): + def RunScript(self, + i_breps: System.Collections.Generic.IList[Rhino.Geometry.Brep], + i_num_points: int): + self.meshing_parameters = Rhino.Geometry.MeshingParameters.DefaultAnalysisMesh + + mesh_versions = [] + + if i_breps is None or i_num_points is None: + return None + + for i_brep in i_breps: + if not isinstance(i_brep, Rhino.Geometry.Brep): + self.AddRuntimeMessage(RML.Warning, "Please provide a brep to convert to a cloud") + return None + meshes = Rhino.Geometry.Mesh.CreateFromBrep(i_brep, self.meshing_parameters) + for mesh in meshes: + mesh_versions.append(mesh) + + unified_mesh = mesh_versions[0] + unified_mesh.Append(mesh_versions) + unified_mesh.Faces.ConvertQuadsToTriangles() + df_mesh = df_cvt_bindings.cvt_rhmesh_2_dfmesh(unified_mesh) + df_cloud = df_mesh.sample_points_uniformly(i_num_points) + rgpoints = [Rhino.Geometry.Point3d(pt[0], pt[1], pt[2]) for pt in df_cloud.points] + rh_cloud = Rhino.Geometry.PointCloud(rgpoints) + print(rh_cloud) + return [rh_cloud] diff --git a/src/gh/components/DF_brep_to_cloud/icon.png b/src/gh/components/DF_brep_to_cloud/icon.png new file mode 100644 index 00000000..ee9921a4 Binary files /dev/null and b/src/gh/components/DF_brep_to_cloud/icon.png differ diff --git a/src/gh/components/DF_brep_to_cloud/metadata.json b/src/gh/components/DF_brep_to_cloud/metadata.json new file mode 100644 index 00000000..3ff32491 --- /dev/null +++ b/src/gh/components/DF_brep_to_cloud/metadata.json @@ -0,0 +1,52 @@ +{ + "name": "DFBrepToMesh", + "nickname": "DFBrepToMesh", + "category": "diffCheck", + "subcategory": "Cloud", + "description": "Create unique point cloud from list of breps.", + "exposure": 4, + "instanceGuid": "0194cbfc-1a6d-44a7-ae5d-7495db20edbe", + "ghpython": { + "hideOutput": true, + "hideInput": true, + "isAdvancedMode": true, + "marshalOutGuids": true, + "iconDisplay": 2, + "inputParameters": [ + { + "name": "i_breps", + "nickname": "i_breps", + "description": "The breps to convert to point cloud.", + "optional": false, + "allowTreeAccess": false, + "showTypeHints": true, + "scriptParamAccess": "list", + "wireDisplay": "default", + "sourceCount": 0, + "typeHintID": "brep" + }, + { + "name": "i_num_points", + "nickname": "i_num_points", + "description": "The number of points in the new point cloud.", + "optional": false, + "allowTreeAccess": false, + "showTypeHints": true, + "scriptParamAccess": "item", + "wireDisplay": "default", + "sourceCount": 0, + "typeHintID": "int" + } + ], + "outputParameters": [ + { + "name": "o_pointcloud", + "nickname": "o_pointcloud", + "description": "The generated point cloud.", + "optional": false, + "sourceCount": 0, + "graft": false + } + ] + } +} \ No newline at end of file diff --git a/src/gh/components/DF_mesh_to_cloud/code.py b/src/gh/components/DF_mesh_to_cloud/code.py index ca8112da..1aa2cf47 100644 --- a/src/gh/components/DF_mesh_to_cloud/code.py +++ b/src/gh/components/DF_mesh_to_cloud/code.py @@ -1,7 +1,8 @@ #! python3 +import System -import Rhino.Geometry as rg +import Rhino from ghpythonlib.componentbase import executingcomponent as component @@ -12,13 +13,26 @@ class DFMeshToCloud(component): def RunScript(self, - i_mesh: rg.Mesh, - i_points: int) -> rg.PointCloud: - df_mesh = diffCheck.df_cvt_bindings.cvt_rhmesh_2_dfmesh(i_mesh) - df_cloud = df_mesh.sample_points_uniformly(i_points) + i_meshes:System.Collections.Generic.IList[Rhino.Geometry.Mesh], + i_points: int) -> Rhino.Geometry.PointCloud: + + if i_meshes is None: + return None + + if i_points is None: + i_points = 1000 + rh_mesh = i_meshes[0] + for i in range(1, len(i_meshes)): + if i_meshes[i] is None: + return None + rh_mesh.Append(i_meshes[i]) + rh_mesh.Faces.ConvertQuadsToTriangles() + + df_mesh = diffCheck.df_cvt_bindings.cvt_rhmesh_2_dfmesh(rh_mesh) + df_cloud = df_mesh.sample_points_uniformly(i_points) + rgpoints = [Rhino.Geometry.Point3d(p[0], p[1], p[2]) for p in df_cloud.points] # convert the df_cloud to a rhino cloud - rgpoints = [rg.Point3d(pt[0], pt[1], pt[2]) for pt in df_cloud.points] - rh_cloud = rg.PointCloud(rgpoints) + rh_cloud = Rhino.Geometry.PointCloud(rgpoints) return [rh_cloud] diff --git a/src/gh/components/DF_mesh_to_cloud/metadata.json b/src/gh/components/DF_mesh_to_cloud/metadata.json index 8f8f8e14..a8161561 100644 --- a/src/gh/components/DF_mesh_to_cloud/metadata.json +++ b/src/gh/components/DF_mesh_to_cloud/metadata.json @@ -14,13 +14,13 @@ "iconDisplay": 2, "inputParameters": [ { - "name": "i_mesh", - "nickname": "i_mesh", - "description": "Mesh to sample into a point cloud.", + "name": "i_meshes", + "nickname": "i_meshes", + "description": "Meshes to sample into a point cloud.", "optional": true, "allowTreeAccess": true, "showTypeHints": true, - "scriptParamAccess": "item", + "scriptParamAccess": "list", "wireDisplay": "default", "sourceCount": 0, "typeHintID": "mesh"