Skip to content

Commit a3edba7

Browse files
authored
Merge pull request #1378 from compas-dev/conversions-api
Explicit methods for geometry and separate methods for doc objects
2 parents 62d3ec4 + 9947037 commit a3edba7

File tree

11 files changed

+1016
-996
lines changed

11 files changed

+1016
-996
lines changed

CHANGELOG.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3232
* Added `compas.geometry.curves.curve.Curve.from_native`.
3333
* Added `compas_rhino.geometry.curves.curve.Curve.from_native`.
3434
* Added `compas_rhino.geometry.curves.nurbs.NurbsCurve.from_native`.
35+
* Added `compas_rhino.conversions.breps.brep_to_compas_mesh`.
36+
* Added `compas_rhino.conversions.docobjects.brepobject_to_compas`.
37+
* Added `compas_rhino.conversions.docobjects.curveobject_to_compas`.
38+
* Added `compas_rhino.conversions.docobjects.meshobject_to_compas`.
39+
* Added `compas_rhino.conversions.docobjects.pointobject_to_compas`.
3540
* Added `compas.datastructures.HashTree` and `compas.datastructures.HashNode`.
3641

3742
### Changed
@@ -47,7 +52,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4752
* Changed `compas.geometry.curves.nurbs.NurbsCurve.__new__` to prevent instantiation of `NurbsCurve` directly.
4853
* Changed `compas_rhino.geometry.curves.new_nurbscurve_from_...` to `nurbscurve_from_...`.
4954
* Fixed `compas_ghpython` Grasshopper components not included in published pakcage.
50-
* Chnaged `compas.colors.Color.coerce` to take color as is, if it is already aninstance of `compas.colors.Color`.
55+
* Changed `compas.colors.Color.coerce` to take color as is, if it is already an instance of `compas.colors.Color`.
56+
* Changed `compas_rhino.conversions.surfaces.surface_to_compas` to work only with surface geometry.
57+
* Changed `compas_rhino.conversions.curves.curve_to_compas_line` to work only with geometry.
58+
* Changed `compas_rhino.conversions.curves.curve_to_compas_circle` to work only with geometry.
59+
* Changed `compas_rhino.conversions.curves.curve_to_compas_ellipse` to work only with geometry.
60+
* Changed `compas_rhino.conversions.curves.curve_to_compas_polyline` to work only with geometry.
61+
* Changed `compas_rhino.objects.get_point_coordinates` to deprecated (removed in v2.3).
62+
* Changed `compas_rhino.objects.get_line_coordinates` to deprecated (removed in v2.3).
63+
* Changed `compas_rhino.objects.get_polyline_coordinates` to deprecated (removed in v2.3).
64+
* Changed `compas_rhino.objects.get_polygon_coordinates` to deprecated (removed in v2.3).
5165
* Fixed a bug in `worldtransformation` of `compas.scene.SceneObject` to include the object's own frame.
5266

5367
### Removed
@@ -77,6 +91,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7791
* Removed `compas.geometry.curves.curve.new_nurbscurve`.
7892
* Removed `compas_rhino.geometry.curves.new_curve`.
7993
* Removed `compas_rhino.geometry.curves.new_nurbscurve`.
94+
* Removed `compas_rhino.conversions.surfaces.data_to_rhino_surface`.
95+
* Removed `compas_rhino.conversions.surfaces.surface_to_compas_data`.
96+
* Removed `compas_rhino.conversions.surfaces.surface_to_compas_quadmesh`.
97+
* Removed `compas_rhino.conversions.curves.curve_to_compas_data`.
8098

8199
## [2.2.1] 2024-06-25
82100

@@ -88,7 +106,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88106

89107
### Removed
90108

91-
92109
## [2.2.0] 2024-06-24
93110

94111
### Added

docs/userguide/cad.rhino.rst

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,183 @@ For more information on visualisation scenes, see :doc:`/userguide/basics.visual
8888
Conversions
8989
===========
9090

91+
For conversion between Rhino objects and COMPAS objects, different scenarios exist.
92+
93+
Rhino Geometry to COMPAS
94+
------------------------
95+
96+
Conversions of geometry is straightforward and explicit.
97+
98+
.. code-block:: python
99+
100+
import Rhino.Geometry
101+
import compas_rhino.conversions
102+
103+
point = Rhino.Geometry.Point3d(...)
104+
point = compas_rhino.conversions.point_to_compas(point)
105+
106+
line = Rhino.Geometry.Line(...)
107+
line = compas_rhino.conversions.line_to_compas(line)
108+
109+
plane = Rhino.Geometry.Plane(...)
110+
plane = compas_rhino.conversions.plane_to_compas(plane)
111+
112+
box = Rhino.Geometry.Box(...)
113+
box = compas_rhino.conversions.box_to_compas(box)
114+
115+
mesh = Rhino.Geometry.Mesh(...)
116+
mesh = compas_rhino.conversions.mesh_to_compas(mesh)
117+
118+
curve = Rhino.Geometry.Curve(...)
119+
curve = compas_rhino.conversions.curve_to_compas(curve)
120+
121+
surface = Rhino.Geometry.Surface(...)
122+
surface = compas_rhino.conversions.surface_to_compas(surface)
123+
124+
brep = Rhino.Geometry.Brep(...)
125+
brep = compas_rhino.conversions.brep_to_compas(brep)
126+
127+
128+
Note that Rhino doen't distinguish between a frame and a plane.
129+
Therefore, to convert `Rhino.Geometry.Plane` to :class:`compas.geometry.Frame`.
130+
131+
.. code-block:: python
132+
133+
plane = Rhino.Geometry.Plane(...)
134+
frame = compas_rhino.conversions.plane_to_compas_frame(plane)
135+
136+
137+
Rhino Object to COMPAS
138+
----------------------
139+
140+
A Rhino Document contains Rhino Object instead of Rhino Geometry.
141+
The geometry of a Rhino Object is stored in the corresponding attribute (`obj.Geometry`).
142+
143+
Converting point, curve, and mesh objects is straightforward.
144+
145+
.. code-block:: python
146+
147+
import compas_rhino.objects
148+
import compas_rhino.conversions
149+
150+
guid = compas_rhino.objects.select_point()
151+
point = compas_rhino.conversions.pointobject_to_compas(guid)
152+
153+
guid = compas_rhino.objects.select_curve()
154+
curve = compas_rhino.conversions.curveobject_to_compas(guid)
155+
156+
guid = compas_rhino.objects.select_mesh()
157+
mesh = compas_rhino.conversions.meshobject_to_compas(guid)
158+
159+
160+
In the case of curve objects, note that the conversion function will return a NurbsCurve in almost all cases.
161+
If the curve has a specific geometry, it can be converted explicitly using the corresponding geomtry conversion function.
162+
For example, if the curve is a circle.
163+
164+
.. code-block:: python
165+
166+
import compas_rhino.objects
167+
import compas_rhino.conversions
168+
169+
guid = compas_rhino.objects.select_curve()
170+
obj = compas_rhino.objects.find_object(guid)
171+
172+
circle = compas_rhino.conversions.curve_to_compas_circle(obj.Geometry)
173+
174+
175+
In the case of all other objects, conversions are a bit trickier.
176+
This is because in a Rhino Document, almost all other geometries are represented by a BrepObject regardless of the actual geometry type.
177+
For example, when you add a sphere to a model, the DocObject is a BrepObject, and the geometry of the object is a Brep.
178+
Therefore, conversions of other objects have to be done more carefully.
179+
180+
.. code-block:: python
181+
182+
import compas_rhino.objects
183+
import compas_rhino.conversions
184+
185+
guid = compas_rhino.objects.select_object()
186+
brep = compas_rhino.conversions.brepobject_to_compas(guid)
187+
188+
189+
Also here, if the object is (supposed to be) a specific type of geometry,
190+
conversion can be done more explicitly using the geometry conversion functions instead.
191+
For example, if the geometry of the object is a Rhino Cylinder.
192+
193+
.. code-block:: python
194+
195+
import compas_rhino.objects
196+
import compas_rhino.conversions
197+
198+
guid = compas_rhino.objects.select_object()
199+
obj = compas_rhino.objects.find_object(guid)
200+
201+
cylinder = compas_rhino.conversions.brep_to_compas_cylinder(obj.Geometry)
202+
203+
204+
COMPAS to Rhino Geometry
205+
------------------------
206+
207+
.. code-block:: python
208+
209+
import compas.geometry
210+
import compas_rhino.conversions
211+
212+
point = compas.geometry.Point(...)
213+
point = compas_rhino.conversions.point_to_rhino(point)
214+
215+
line = compas.geometry.Line(...)
216+
line = compas_rhino.conversions.line_to_rhino(line)
217+
218+
plane = compas.geometry.Plane(...)
219+
plane = compas_rhino.conversions.plane_to_rhino(plane)
220+
221+
box = compas.geometry.Box(...)
222+
box = compas_rhino.conversions.box_to_rhino(box)
223+
224+
curve = compas.geometry.Curve(...)
225+
curve = compas_rhino.conversions.curve_to_rhino(curve)
226+
227+
surface = compas.geometry.Surface(...)
228+
surface = compas_rhino.conversions.surface_to_rhino(surface)
229+
230+
brep = compas.geometry.Brep(...)
231+
brep = compas_rhino.conversions.brep_to_rhino(brep)
232+
233+
234+
To convert a :class:`compas.geometry.Frame`.
235+
236+
.. code-block:: python
237+
238+
frame = compas.geometry.Frame(...)
239+
plane = compas_rhino.conversions.frame_to_rhino_plane(frame)
240+
241+
242+
COMPAS to Rhino Object
243+
----------------------
244+
245+
COMPAS objects are converted to Rhino Objects implicitly, by placing them into a visualisation scene.
246+
However, you can create a Rhino Object in a Rhino Dcocument explicitly from a COMPAS object.
247+
248+
.. code-block:: python
249+
250+
import scriptcontext as sc
251+
import compas.geometry
252+
import compas_rhino_conversions
253+
254+
point = compas.geometry.Point(...)
255+
geometry = compas_rhino.conversions.point_to_rhino(point)
256+
257+
guid = sc.doc.Objects.AddPoint(geometry)
258+
91259
92260
Data Exchange
93261
=============
94262

263+
JSON
264+
----
265+
266+
rhino3dm
267+
--------
95268

96269
Remote Procedure Calls
97270
======================

src/compas_rhino/conversions/__init__.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,8 @@
4343
)
4444
from .surfaces import (
4545
surface_to_rhino,
46-
data_to_rhino_surface,
47-
surface_to_compas_data,
4846
surface_to_compas,
4947
surface_to_compas_mesh,
50-
surface_to_compas_quadmesh,
5148
)
5249
from .shapes import (
5350
box_to_rhino,
@@ -73,10 +70,12 @@
7370
)
7471
from .breps import (
7572
brep_to_rhino,
73+
brep_to_compas,
7674
brep_to_compas_box,
7775
brep_to_compas_cone,
7876
brep_to_compas_cylinder,
7977
brep_to_compas_sphere,
78+
brep_to_compas_mesh,
8079
)
8180
from .extrusions import (
8281
extrusion_to_compas_box,
@@ -89,6 +88,13 @@
8988
transformation_matrix_to_rhino,
9089
)
9190

91+
from .docobjects import (
92+
brepobject_to_compas,
93+
curveobject_to_compas,
94+
meshobject_to_compas,
95+
pointobject_to_compas,
96+
)
97+
9298

9399
__all__ = [
94100
"ConversionError",
@@ -127,11 +133,8 @@
127133
"curve_to_compas",
128134
# surfaces
129135
"surface_to_rhino",
130-
"surface_to_compas_data",
131-
"data_to_rhino_surface",
132136
"surface_to_compas",
133137
"surface_to_compas_mesh",
134-
"surface_to_compas_quadmesh",
135138
# shapes
136139
"box_to_rhino",
137140
"sphere_to_rhino",
@@ -154,15 +157,22 @@
154157
"mesh_to_compas",
155158
# breps
156159
"brep_to_rhino",
160+
"brep_to_compas",
157161
"brep_to_compas_box",
158162
"brep_to_compas_cone",
159163
"brep_to_compas_cylinder",
160164
"brep_to_compas_sphere",
165+
"brep_to_compas_mesh",
161166
# extrusions
162167
"extrusion_to_compas_box",
163168
"extrusion_to_compas_cylinder",
164169
"extrusion_to_compas_torus",
165170
# transformations
166171
"transformation_to_rhino",
167172
"transformation_matrix_to_rhino",
173+
# docobjects
174+
"brepobject_to_compas",
175+
"curveobject_to_compas",
176+
"meshobject_to_compas",
177+
"pointobject_to_compas",
168178
]

0 commit comments

Comments
 (0)