diff --git a/CHANGELOG.md b/CHANGELOG.md index 7cd84c4c64e..fdbeccf631a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added * Added optional `triangulated` flag to `Mesh.to_vertices_and_faces`. +* Added geometry information of active meshes to the serialization/deserialization of robot model's `MeshDescriptor`. +* Added Grasshopper component to draw any COMPAS object. +* Added new icons to Grasshopper components and default to icon style. ### Changed diff --git a/src/compas/robots/model/geometry.py b/src/compas/robots/model/geometry.py index 3622b61a35f..0f3c74a3b1d 100644 --- a/src/compas/robots/model/geometry.py +++ b/src/compas/robots/model/geometry.py @@ -173,6 +173,7 @@ def data(self): 'filename': self.filename, 'scale': self.scale, 'attr': _attr_to_data(self.attr), + 'meshes': [m.data for m in self.meshes], } @data.setter @@ -180,6 +181,7 @@ def data(self, data): self.filename = data['filename'] self.scale = data['scale'] self.attr = _attr_from_data(data['attr']) if 'attr' in data else {} + self.meshes = [Mesh.from_data(md) for md in data['meshes']] if 'meshes' in data else [] @classmethod def from_data(cls, data): @@ -364,6 +366,7 @@ def get_color(self): ('point', 'radius'): compas.geometry.Sphere, ('line', 'radius'): compas.geometry.Capsule, ('attr', 'filename', 'scale'): MeshDescriptor, + ('attr', 'filename', 'meshes', 'scale'): MeshDescriptor, } diff --git a/src/compas_ghpython/components/Compas_Frame/code.py b/src/compas_ghpython/components/Compas_Frame/code.py deleted file mode 100644 index 68eb236c194..00000000000 --- a/src/compas_ghpython/components/Compas_Frame/code.py +++ /dev/null @@ -1,20 +0,0 @@ -""" -Draws a frame or plane. -""" -from ghpythonlib.componentbase import executingcomponent as component - -from compas_ghpython.artists import FrameArtist -from compas_ghpython.components import coerce_frame - - -class CompasFrame(component): - def RunScript(self, frame): - plane = None - - if frame: - frame = coerce_frame(frame) - artist = FrameArtist(frame) - - plane = artist.draw() - - return plane diff --git a/src/compas_ghpython/components/Compas_Frame/icon.png b/src/compas_ghpython/components/Compas_Frame/icon.png deleted file mode 100644 index c8df236e3a3..00000000000 Binary files a/src/compas_ghpython/components/Compas_Frame/icon.png and /dev/null differ diff --git a/src/compas_ghpython/components/Compas_Frame/metadata.json b/src/compas_ghpython/components/Compas_Frame/metadata.json deleted file mode 100644 index 6520be9ccca..00000000000 --- a/src/compas_ghpython/components/Compas_Frame/metadata.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "name": "Frame", - "nickname": "Frame", - "category": "COMPAS", - "subcategory": "Display", - "description": "Draws a frame or plane", - "exposure": 2, - - "ghpython": { - "isAdvancedMode": true, - "inputParameters": [ - { - "name": "frame", - "description": "The frame or plane to be drawn." - } - ], - "outputParameters": [ - { - "name": "plane", - "description": "The drawn plane." - } - ] - } -} \ No newline at end of file diff --git a/src/compas_ghpython/components/Compas_FromJson/code.py b/src/compas_ghpython/components/Compas_FromJson/code.py index 6bcb01f7f3b..808d2290ad0 100644 --- a/src/compas_ghpython/components/Compas_FromJson/code.py +++ b/src/compas_ghpython/components/Compas_FromJson/code.py @@ -8,6 +8,9 @@ class CompasInfo(component): def RunScript(self, json): + if not json: + return None + try: return compas.json_load(json) except: # noqa: E722 diff --git a/src/compas_ghpython/components/Compas_FromJson/icon.png b/src/compas_ghpython/components/Compas_FromJson/icon.png index c8df236e3a3..83db4299842 100644 Binary files a/src/compas_ghpython/components/Compas_FromJson/icon.png and b/src/compas_ghpython/components/Compas_FromJson/icon.png differ diff --git a/src/compas_ghpython/components/Compas_FromJson/metadata.json b/src/compas_ghpython/components/Compas_FromJson/metadata.json index 1932da19c6b..053b84d4710 100644 --- a/src/compas_ghpython/components/Compas_FromJson/metadata.json +++ b/src/compas_ghpython/components/Compas_FromJson/metadata.json @@ -8,6 +8,7 @@ "ghpython": { "isAdvancedMode": true, + "iconDisplay": 2, "inputParameters": [ { "name": "json", diff --git a/src/compas_ghpython/components/Compas_Info/icon.png b/src/compas_ghpython/components/Compas_Info/icon.png index c8df236e3a3..b447b5ee119 100644 Binary files a/src/compas_ghpython/components/Compas_Info/icon.png and b/src/compas_ghpython/components/Compas_Info/icon.png differ diff --git a/src/compas_ghpython/components/Compas_Info/metadata.json b/src/compas_ghpython/components/Compas_Info/metadata.json index 61b0b3ebe89..d5c3a05f196 100644 --- a/src/compas_ghpython/components/Compas_Info/metadata.json +++ b/src/compas_ghpython/components/Compas_Info/metadata.json @@ -8,6 +8,7 @@ "ghpython": { "isAdvancedMode": true, + "iconDisplay": 2, "inputParameters": [ ], "outputParameters": [ diff --git a/src/compas_ghpython/components/Compas_ToJson/icon.png b/src/compas_ghpython/components/Compas_ToJson/icon.png index c8df236e3a3..ae685b73584 100644 Binary files a/src/compas_ghpython/components/Compas_ToJson/icon.png and b/src/compas_ghpython/components/Compas_ToJson/icon.png differ diff --git a/src/compas_ghpython/components/Compas_ToJson/metadata.json b/src/compas_ghpython/components/Compas_ToJson/metadata.json index 423dc4ab33a..a19d5d9ab84 100644 --- a/src/compas_ghpython/components/Compas_ToJson/metadata.json +++ b/src/compas_ghpython/components/Compas_ToJson/metadata.json @@ -8,6 +8,7 @@ "ghpython": { "isAdvancedMode": true, + "iconDisplay": 2, "inputParameters": [ { "name": "data", diff --git a/src/compas_ghpython/components/Compas_ToRhinoGeometry/code.py b/src/compas_ghpython/components/Compas_ToRhinoGeometry/code.py new file mode 100644 index 00000000000..f152ef89648 --- /dev/null +++ b/src/compas_ghpython/components/Compas_ToRhinoGeometry/code.py @@ -0,0 +1,14 @@ +""" +Draws COMPAS geometry in Grasshopper. +""" +from ghpythonlib.componentbase import executingcomponent as component + +from compas.artists import Artist + + +class CompasToRhinoGeometry(component): + def RunScript(self, cg): + if not cg: + return None + + return Artist(cg).draw() diff --git a/src/compas_ghpython/components/Compas_ToRhinoGeometry/icon.png b/src/compas_ghpython/components/Compas_ToRhinoGeometry/icon.png new file mode 100644 index 00000000000..88b3fdd3268 Binary files /dev/null and b/src/compas_ghpython/components/Compas_ToRhinoGeometry/icon.png differ diff --git a/src/compas_ghpython/components/Compas_ToRhinoGeometry/metadata.json b/src/compas_ghpython/components/Compas_ToRhinoGeometry/metadata.json new file mode 100644 index 00000000000..8329fa38ac9 --- /dev/null +++ b/src/compas_ghpython/components/Compas_ToRhinoGeometry/metadata.json @@ -0,0 +1,25 @@ +{ + "name": "Draw", + "nickname": "Draw", + "category": "COMPAS", + "subcategory": "Display", + "description": "Draws COMPAS geometry", + "exposure": 2, + + "ghpython": { + "isAdvancedMode": true, + "iconDisplay": 2, + "inputParameters": [ + { + "name": "cg", + "description": "The COMPAS geometry or datastructure to be drawn." + } + ], + "outputParameters": [ + { + "name": "rg", + "description": "The Rhino geometry object." + } + ] + } +} diff --git a/src/compas_ghpython/components/__init__.py b/src/compas_ghpython/components/__init__.py index a3c499fb19c..c013ea16ec6 100644 --- a/src/compas_ghpython/components/__init__.py +++ b/src/compas_ghpython/components/__init__.py @@ -34,17 +34,6 @@ import compas_rhino -def coerce_frame(plane): - import Rhino - from compas.geometry import Frame - if isinstance(plane, Rhino.Geometry.Plane): - return Frame(plane.Origin, plane.XAxis, plane.YAxis) - elif isinstance(plane, Frame): - return plane - else: - return Frame(*plane) - - def get_version_from_args(): parser = argparse.ArgumentParser() parser.add_argument('-v', '--version', choices=compas_rhino.SUPPORTED_VERSIONS, default=compas_rhino.DEFAULT_VERSION)