diff --git a/CHANGELOG.md b/CHANGELOG.md index f805a3ed102..49a5f2734dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Added `compas.geometry.Torus.to_brep()`. * Added `compas.brep.Brep.from_iges()`. * Added `compas.brep.Brep.to_iges()`. +* Added `compas.scene.Scene`. ### Changed @@ -24,7 +25,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Changed `compas.geometry.NurbsSurface.u_isocurve` to `isocurve_u`. * Changed `compas.geometry.NurbsSurface.v_isocurve` to `isocurve_v`. * Changed `compas.brep.Brep.from_step_file` to `from_step`. -* * Moved `compas.brep` to `compas.geometry.brep`. +* Moved `compas.brep` to `compas.geometry.brep`. +* `Artists` classes are renamed to `SceneObject` classes and now under `compas.scene`, `compas_rhino.scene`, `compas_ghpython.scene`, `compas_blender.scene`. ### Removed @@ -37,6 +39,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Added `Frame.axes` * Added `compas.datastructures.TreeNode` and `compas.datastructures.Tree` classes. * Added `EllipseArtist` to `compas_rhino` and `compas_ghpython`. +* Added `compas.scene.Scene`. ### Changed diff --git a/docs/reference/compas.artists.rst b/docs/reference/compas.artists.rst deleted file mode 100644 index 8ac5391bc40..00000000000 --- a/docs/reference/compas.artists.rst +++ /dev/null @@ -1,46 +0,0 @@ - -******************************************************************************** -compas.artists -******************************************************************************** - -.. currentmodule:: compas.artists - -.. rst-class:: lead - - -This package defines artists for visualising COMPAS objects. -Every object type is paired with a corresponding artist type that is capable of visualizing the data of the object. -The artists are implemented as pluggables, and automatically switch between plugins depending on the contexct in which they are used. - - -Classes -======= - -.. autosummary:: - :toctree: generated/ - :nosignatures: - - Artist - DataArtistNotRegisteredError - GeometryArtist - MeshArtist - NetworkArtist - NoArtistContextError - VolMeshArtist - - -Pluggables -========== - -Pluggables are functions that don't have an actual implementation, but receive an implementation from a plugin. - -.. autosummary:: - :toctree: generated/ - :nosignatures: - - clear - redraw - register_artists - - - diff --git a/docs/reference/compas.rst b/docs/reference/compas.rst index d7627740b8a..f1f3e04812e 100644 --- a/docs/reference/compas.rst +++ b/docs/reference/compas.rst @@ -11,7 +11,6 @@ and can be used independently of CAD systems in any environment that supports Py :titlesonly: :caption: compas - compas.artists compas.colors compas.data compas.datastructures @@ -20,4 +19,5 @@ and can be used independently of CAD systems in any environment that supports Py compas.numerical compas.plugins compas.rpc + compas.scene compas.topology diff --git a/docs/reference/compas.scene.rst b/docs/reference/compas.scene.rst new file mode 100644 index 00000000000..56e69a48208 --- /dev/null +++ b/docs/reference/compas.scene.rst @@ -0,0 +1,46 @@ + +******************************************************************************** +compas.scene +******************************************************************************** + +.. currentmodule:: compas.scene + +.. rst-class:: lead + + +This package defines scene objects for visualising COMPAS objects. +Every object type is paired with a corresponding scene object type that is capable of visualizing the data of the object. +The scene objects are implemented as pluggables, and automatically switch between plugins depending on the contexct in which they are used. + + +Classes +======= + +.. autosummary:: + :toctree: generated/ + :nosignatures: + + SceneObject + DataSceneObjectNotRegisteredError + GeometryObject + MeshObject + NetworkObject + NoSceneObjectContextError + VolMeshObject + + +Pluggables +========== + +Pluggables are functions that don't have an actual implementation, but receive an implementation from a plugin. + +.. autosummary:: + :toctree: generated/ + :nosignatures: + + clear + redraw + register_scene_objects + + + diff --git a/docs/reference/compas_blender.artists.rst b/docs/reference/compas_blender.artists.rst deleted file mode 100644 index 55ad8128aab..00000000000 --- a/docs/reference/compas_blender.artists.rst +++ /dev/null @@ -1,47 +0,0 @@ - -******************************************************************************** -compas_blender.artists -******************************************************************************** - -.. currentmodule:: compas_blender.artists - -.. rst-class:: lead - - -This package provides artist plugins for visualising COMPAS objects in Blender. -When working in Blender, :class:`compas.artists.Artist` will automatically use the corresponding Blender artist for each COMPAS object type. - - -Classes -======= - - - -.. autosummary:: - :toctree: generated/ - :nosignatures: - - BlenderArtist - BoxArtist - CapsuleArtist - CircleArtist - ConeArtist - CurveArtist - CylinderArtist - FrameArtist - LineArtist - MeshArtist - NetworkArtist - PointArtist - PointcloudArtist - PolygonArtist - PolyhedronArtist - PolylineArtist - SphereArtist - SurfaceArtist - TorusArtist - VectorArtist - VolMeshArtist - - - diff --git a/docs/reference/compas_blender.rst b/docs/reference/compas_blender.rst index 35356b1a74c..9d1fc39bca8 100644 --- a/docs/reference/compas_blender.rst +++ b/docs/reference/compas_blender.rst @@ -9,6 +9,7 @@ COMPAS geometry and data structures in Blender, and for basic user inter interac :titlesonly: :caption: compas_blender - compas_blender.artists compas_blender.conversions compas_blender.geometry + compas_blender.scene + diff --git a/docs/reference/compas_blender.scene.rst b/docs/reference/compas_blender.scene.rst new file mode 100644 index 00000000000..4c48c6efa5e --- /dev/null +++ b/docs/reference/compas_blender.scene.rst @@ -0,0 +1,47 @@ + +******************************************************************************** +compas_blender.scene +******************************************************************************** + +.. currentmodule:: compas_blender.scene + +.. rst-class:: lead + + +This package provides scene object plugins for visualising COMPAS objects in Blender. +When working in Blender, :class:`compas.scene.SceneObject` will automatically use the corresponding Blender scene object for each COMPAS object type. + + +Classes +======= +BoxObject + + +.. autosummary:: + :toctree: generated/ + :nosignatures: + + BlenderSceneObject + BoxObject + CapsuleObject + CircleObject + ConeObject + CurveObject + CylinderObject + FrameObject + LineObject + MeshObject + NetworkObject + PointObject + PointcloudObject + PolygonObject + PolyhedronObject + PolylineObject + SphereObject + SurfaceObject + TorusObject + VectorObject + VolMeshObject + + + diff --git a/docs/reference/compas_ghpython.artists.rst b/docs/reference/compas_ghpython.artists.rst deleted file mode 100644 index 53279e953c2..00000000000 --- a/docs/reference/compas_ghpython.artists.rst +++ /dev/null @@ -1,47 +0,0 @@ - -******************************************************************************** -compas_ghpython.artists -******************************************************************************** - -.. currentmodule:: compas_ghpython.artists - -.. rst-class:: lead - - -This package provides artist plugins for visualising COMPAS objects in Grasshopper. -When working in GH Python components, :class:`compas.artists.Artist` will automatically use the corresponding GHPython artist for each COMPAS object type. - - -Classes -======= - - - -.. autosummary:: - :toctree: generated/ - :nosignatures: - - BoxArtist - CapsuleArtist - CircleArtist - ConeArtist - CurveArtist - CylinderArtist - EllipseArtist - FrameArtist - GHArtist - LineArtist - MeshArtist - NetworkArtist - PointArtist - PolygonArtist - PolyhedronArtist - PolylineArtist - SphereArtist - SurfaceArtist - TorusArtist - VectorArtist - VolMeshArtist - - - diff --git a/docs/reference/compas_ghpython.rst b/docs/reference/compas_ghpython.rst index c0fbfd91da5..8156b23c5ee 100644 --- a/docs/reference/compas_ghpython.rst +++ b/docs/reference/compas_ghpython.rst @@ -9,5 +9,6 @@ COMPAS geometry and data structures in Rhino, through GHPython. :titlesonly: :caption: compas_ghpython - compas_ghpython.artists compas_ghpython.components + compas_ghpython.scene + diff --git a/docs/reference/compas_ghpython.scene.rst b/docs/reference/compas_ghpython.scene.rst new file mode 100644 index 00000000000..9ef2c524832 --- /dev/null +++ b/docs/reference/compas_ghpython.scene.rst @@ -0,0 +1,47 @@ + +******************************************************************************** +compas_ghpython.scene +******************************************************************************** + +.. currentmodule:: compas_ghpython.scene + +.. rst-class:: lead + + +This package provides scene object plugins for visualising COMPAS objects in Grasshopper. +When working in GH Python components, :class:`compas.scene.SceneObject` will automatically use the corresponding GHPython scene object for each COMPAS object type. + + +Classes +======= + + + +.. autosummary:: + :toctree: generated/ + :nosignatures: + + BoxObject + CapsuleObject + CircleObject + ConeObject + CurveObject + CylinderObject + EllipseObject + FrameObject + GHObject + LineObject + MeshObject + NetworkObject + PointObject + PolygonObject + PolyhedronObject + PolylineObject + SphereObject + SurfaceObject + TorusObject + VectorObject + VolMeshObject + + + diff --git a/docs/reference/compas_rhino.artists.rst b/docs/reference/compas_rhino.artists.rst deleted file mode 100644 index 85601324fc4..00000000000 --- a/docs/reference/compas_rhino.artists.rst +++ /dev/null @@ -1,49 +0,0 @@ - -******************************************************************************** -compas_rhino.artists -******************************************************************************** - -.. currentmodule:: compas_rhino.artists - -.. rst-class:: lead - - -This package provides artist plugins for visualising COMPAS objects in Rhino. -When working in Rhino, :class:`compas.artists.Artist` will automatically use the corresponding Rhino artist for each COMPAS object type. - - -Classes -======= - - - -.. autosummary:: - :toctree: generated/ - :nosignatures: - - BoxArtist - BrepArtist - CapsuleArtist - CircleArtist - ConeArtist - CurveArtist - CylinderArtist - EllipseArtist - FrameArtist - LineArtist - MeshArtist - NetworkArtist - PlaneArtist - PointArtist - PolygonArtist - PolyhedronArtist - PolylineArtist - RhinoArtist - SphereArtist - SurfaceArtist - TorusArtist - VectorArtist - VolMeshArtist - - - diff --git a/docs/reference/compas_rhino.rst b/docs/reference/compas_rhino.rst index f5e54e16391..27bd6a60edd 100644 --- a/docs/reference/compas_rhino.rst +++ b/docs/reference/compas_rhino.rst @@ -9,7 +9,8 @@ COMPAS geometry and data structures in Rhino, and for basic user inter interacti :titlesonly: :caption: compas_rhino - compas_rhino.artists compas_rhino.conversions compas_rhino.forms compas_rhino.geometry + compas_rhino.scene + diff --git a/docs/reference/compas_rhino.scene.rst b/docs/reference/compas_rhino.scene.rst new file mode 100644 index 00000000000..417fabd5589 --- /dev/null +++ b/docs/reference/compas_rhino.scene.rst @@ -0,0 +1,49 @@ + +******************************************************************************** +compas_rhino.scene +******************************************************************************** + +.. currentmodule:: compas_rhino.scene + +.. rst-class:: lead + + +This package provides scene object plugins for visualising COMPAS objects in Rhino. +When working in Rhino, :class:`compas.scene.SceneObject` will automatically use the corresponding Rhino scene object for each COMPAS object type. + + +Classes +======= + + + +.. autosummary:: + :toctree: generated/ + :nosignatures: + + BoxObject + BrepObject + CapsuleObject + CircleObject + ConeObject + CurveObject + CylinderObject + EllipseObject + FrameObject + LineObject + MeshObject + NetworkObject + PlaneObject + PointObject + PolygonObject + PolyhedronObject + PolylineObject + RhinoObject + SphereObject + SurfaceObject + TorusObject + VectorObject + VolMeshObject + + + diff --git a/docs/reference/index.rst b/docs/reference/index.rst index 310dc03865d..836a10f211f 100644 --- a/docs/reference/index.rst +++ b/docs/reference/index.rst @@ -14,7 +14,7 @@ and can be used independently of CAD systems in any environment that supports Py :titlesonly: :caption: compas - compas.artists + compas.scene compas.colors compas.data compas.datastructures @@ -37,7 +37,7 @@ COMPAS geometry and data structures in Blender, and for basic user inter interac :titlesonly: :caption: compas_blender - compas_blender.artists + compas_blender.scene compas_blender.conversions compas_blender.geometry @@ -53,7 +53,7 @@ COMPAS geometry and data structures in Rhino, through GHPython. :titlesonly: :caption: compas_ghpython - compas_ghpython.artists + compas_ghpython.scene compas_ghpython.components compas_ghpython.conversions @@ -69,7 +69,7 @@ COMPAS geometry and data structures in Rhino, and for basic user inter interacti :titlesonly: :caption: compas_rhino - compas_rhino.artists + compas_rhino.scene compas_rhino.conversions compas_rhino.forms compas_rhino.geometry diff --git a/docs/userguide/configuration/grasshopper.rst b/docs/userguide/configuration/grasshopper.rst index be65939a5e7..141c64baed4 100644 --- a/docs/userguide/configuration/grasshopper.rst +++ b/docs/userguide/configuration/grasshopper.rst @@ -20,11 +20,13 @@ component on your Grasshopper canvas, paste the following script and hit `OK`. import compas from compas.datastructures import Mesh - from compas_ghpython.artists import MeshArtist + from compas.scene import Scene mesh = Mesh.from_obj(compas.get('faces.obj')) - a = MeshArtist(mesh).draw() + scene = Scene() + scene.add(mesh) + a = scene.redraw() .. figure:: /_images/gh_verify.jpg @@ -64,6 +66,6 @@ recognizes the changes. To avoid restarting Rhino, you can use the function Prefer using `unload_modules` as early as possible in your grasshopper workflow. Re-loading modules later might result, for example, - in COMPAS not being able to find an `Artist` as well as other issues + in COMPAS not being able to find an `SceneObject` as well as other issues related to a mid-workflow re-definition of Python types. diff --git a/docs/userguide/tutorials.rst b/docs/userguide/tutorials.rst index d80ae99c14f..dfbed7a14c7 100644 --- a/docs/userguide/tutorials.rst +++ b/docs/userguide/tutorials.rst @@ -10,4 +10,4 @@ Tutorials tutorials/datastructures/index tutorials/rpc tutorials/colors - turorials/artists/index + turorials/scene/index diff --git a/docs/userguide/tutorials/artists/boxartist.py b/docs/userguide/tutorials/artists/boxartist.py deleted file mode 100644 index 915214f9008..00000000000 --- a/docs/userguide/tutorials/artists/boxartist.py +++ /dev/null @@ -1,11 +0,0 @@ -from compas.geometry import Box -from compas.artists import Artist - -Artist.clear() - -box = Box.from_corner_corner_height([0, 0, 0], [1, 1, 0], 3) - -artist = Artist(box, layer='Test::Child') -artist.draw(color=(0.0, 1.0, 0.0)) - -Artist.redraw() diff --git a/docs/userguide/tutorials/artists/capsuleartist.py b/docs/userguide/tutorials/artists/capsuleartist.py deleted file mode 100644 index da3b1933f98..00000000000 --- a/docs/userguide/tutorials/artists/capsuleartist.py +++ /dev/null @@ -1,11 +0,0 @@ -from compas.geometry import Capsule -from compas.artists import Artist - -Artist.clear() - -capsule = Capsule(radius=1.0, height=7.0) - -artist = Artist(capsule) -artist.draw(color=(1.0, 0.0, 0.0)) - -Artist.redraw() diff --git a/docs/userguide/tutorials/artists/circleartist.py b/docs/userguide/tutorials/artists/circleartist.py deleted file mode 100644 index 66c33f8ee6d..00000000000 --- a/docs/userguide/tutorials/artists/circleartist.py +++ /dev/null @@ -1,11 +0,0 @@ -from compas.geometry import Circle -from compas.artists import Artist - -Artist.clear() - -circle = Circle(radius=3.0) - -artist = Artist(circle) -artist.draw(color=(0.0, 0.0, 1.0), show_point=True, show_normal=True) - -Artist.redraw() diff --git a/docs/userguide/tutorials/artists/coneartist.py b/docs/userguide/tutorials/artists/coneartist.py deleted file mode 100644 index 12113ec9d91..00000000000 --- a/docs/userguide/tutorials/artists/coneartist.py +++ /dev/null @@ -1,11 +0,0 @@ -from compas.geometry import Cone -from compas.artists import Artist - -Artist.clear() - -cone = Cone(radius=1.0, height=7.0) - -artist = Artist(cone) -artist.draw(color=(1.0, 0.0, 0.0)) - -Artist.redraw() diff --git a/docs/userguide/tutorials/artists/curveartist.py b/docs/userguide/tutorials/artists/curveartist.py deleted file mode 100644 index 0ce569c4e5a..00000000000 --- a/docs/userguide/tutorials/artists/curveartist.py +++ /dev/null @@ -1,12 +0,0 @@ -from compas.geometry import NurbsCurve -from compas.artists import Artist - -Artist.clear() - -curve = NurbsCurve.from_points([[0, 0, 0], [3, 3, 6], [6, -3, -3], [9, 0, 0]]) - -artist = Artist(curve) -artist.color = (0.0, 1.0, 0.0) -artist.draw() - -Artist.redraw() diff --git a/docs/userguide/tutorials/artists/cylinderartist.py b/docs/userguide/tutorials/artists/cylinderartist.py deleted file mode 100644 index 9628b035a34..00000000000 --- a/docs/userguide/tutorials/artists/cylinderartist.py +++ /dev/null @@ -1,11 +0,0 @@ -from compas.geometry import Cylinder -from compas.artists import Artist - -Artist.clear() - -cylinder = Cylinder(radius=1.0, height=7.0) - -artist = Artist(cylinder) -artist.draw(color=(1.0, 0.0, 0.0)) - -Artist.redraw() diff --git a/docs/userguide/tutorials/artists/frameartist.py b/docs/userguide/tutorials/artists/frameartist.py deleted file mode 100644 index 7a2d41582f2..00000000000 --- a/docs/userguide/tutorials/artists/frameartist.py +++ /dev/null @@ -1,10 +0,0 @@ -from compas.geometry import Frame -from compas.artists import Artist - -Artist.clear() - -frame = Frame.worldXY() -artist = Artist(frame) -artist.draw() - -Artist.redraw() diff --git a/docs/userguide/tutorials/artists/lineartist.py b/docs/userguide/tutorials/artists/lineartist.py deleted file mode 100644 index 47dc60be132..00000000000 --- a/docs/userguide/tutorials/artists/lineartist.py +++ /dev/null @@ -1,20 +0,0 @@ -from math import pi -from compas.geometry import Rotation, Scale -from compas.geometry import Line -from compas.artists import Artist -from compas.colors import Color - -Artist.clear() - -line = Line([0, 0, 0], [3, 0, 0]) -artist = Artist(line) -# artist.color = (1.0, 0.0, 0.0) - -step = pi / 10.0 -rotation = Rotation.from_axis_and_angle([0, 0, 1], angle=step) - -for i in range(11): - artist.draw(color=Color.from_i(i / 10)) - line.transform(rotation) - -Artist.redraw() \ No newline at end of file diff --git a/docs/userguide/tutorials/artists/meshartist.py b/docs/userguide/tutorials/artists/meshartist.py deleted file mode 100644 index 83a3fc8508e..00000000000 --- a/docs/userguide/tutorials/artists/meshartist.py +++ /dev/null @@ -1,16 +0,0 @@ -from compas.datastructures import Mesh -from compas.artists import Artist -from compas.colors import Color - -mesh = Mesh.from_meshgrid(10, 10) - -Artist.clear() - -artist = Artist(mesh) -artist.draw_vertices() -artist.draw_edges() -artist.draw_faces(color={face: Color.pink() for face in mesh.face_sample(size=17)}) -#artist.draw_vertexnormals() -artist.draw_facenormals() - -Artist.redraw() diff --git a/docs/userguide/tutorials/artists/networkartist.py b/docs/userguide/tutorials/artists/networkartist.py deleted file mode 100644 index a53e3429e47..00000000000 --- a/docs/userguide/tutorials/artists/networkartist.py +++ /dev/null @@ -1,21 +0,0 @@ -from compas.geometry import Pointcloud -from compas.datastructures import Network -from compas.artists import Artist -from compas.colors import Color - -network = Network.from_pointcloud(Pointcloud.from_bounds(8, 5, 3, 53)) - -node = network.node_sample(size=1)[0] -nbrs = network.neighbors(node) -edges = network.connected_edges(node) - -Artist.clear() - -artist = Artist(network) -artist.draw( - nodecolor={n: Color.pink() for n in [node] + nbrs}, - edgecolor={e: Color.pink() for e in edges}, - nodetext='index' -) - -Artist.redraw() diff --git a/docs/userguide/tutorials/artists/pointartist.py b/docs/userguide/tutorials/artists/pointartist.py deleted file mode 100644 index 28be7d90886..00000000000 --- a/docs/userguide/tutorials/artists/pointartist.py +++ /dev/null @@ -1,17 +0,0 @@ -import compas_rhino - -from compas.geometry import Point -from compas.artists import Artist -from compas.colors import Color - -compas_rhino.clear() - -point = Point(0, 0, 0) -artist = Artist(point) -# artist.color = (0.0, 1.0, 0.0) - -for i in range(11): - point.x = i - artist.draw(color=Color.from_i(i / 10)) - -compas_rhino.redraw() diff --git a/docs/userguide/tutorials/artists/polygonartist.py b/docs/userguide/tutorials/artists/polygonartist.py deleted file mode 100644 index 81960502493..00000000000 --- a/docs/userguide/tutorials/artists/polygonartist.py +++ /dev/null @@ -1,13 +0,0 @@ -from compas.geometry import Polygon -from compas.artists import Artist - -Artist.clear() - -polygon = Polygon.from_sides_and_radius_xy(8, 7.0) - -artist = Artist(polygon) -artist.color = (0.0, 1.0, 0.0) - -artist.draw(show_points=True, show_edges=True) - -Artist.redraw() diff --git a/docs/userguide/tutorials/artists/polyhedronartist.py b/docs/userguide/tutorials/artists/polyhedronartist.py deleted file mode 100644 index 00fab26f62e..00000000000 --- a/docs/userguide/tutorials/artists/polyhedronartist.py +++ /dev/null @@ -1,10 +0,0 @@ -from compas.geometry import Polyhedron -from compas.artists import Artist - -Artist.clear() - -polyhedron = Polyhedron.from_platonicsolid(f=8) -artist = Artist(polyhedron) -artist.draw() - -Artist.redraw() diff --git a/docs/userguide/tutorials/artists/polylineartist.py b/docs/userguide/tutorials/artists/polylineartist.py deleted file mode 100644 index 37584c501bf..00000000000 --- a/docs/userguide/tutorials/artists/polylineartist.py +++ /dev/null @@ -1,20 +0,0 @@ -from random import randrange -from compas.geometry import Polyline -from compas.artists import Artist -from compas.colors import Color - -Artist.clear() - -polyline = Polyline([[0, 0, 0]]) - -for i, r in enumerate([randrange(1, 20) for _ in range(10)]): - if i % 2 == 0: - polyline.append([r, polyline.points[-1].y, 0]) - else: - polyline.append([polyline.points[-1].x, r, 0]) - -artist = Artist(polyline) -artist.color = (0.0, 0.0, 1.0) -artist.draw() - -Artist.redraw() diff --git a/docs/userguide/tutorials/artists/sphereartist.py b/docs/userguide/tutorials/artists/sphereartist.py deleted file mode 100644 index 551f12051f9..00000000000 --- a/docs/userguide/tutorials/artists/sphereartist.py +++ /dev/null @@ -1,11 +0,0 @@ -from compas.geometry import Sphere -from compas.artists import Artist - -Artist.clear() - -sphere = Sphere(radius=1.0) - -artist = Artist(sphere) -artist.draw(color=(1.0, 0.0, 0.0)) - -Artist.redraw() diff --git a/docs/userguide/tutorials/artists/torusartist.py b/docs/userguide/tutorials/artists/torusartist.py deleted file mode 100644 index 2e64114b432..00000000000 --- a/docs/userguide/tutorials/artists/torusartist.py +++ /dev/null @@ -1,11 +0,0 @@ -from compas.geometry import Torus -from compas.artists import Artist - -Artist.clear() - -torus = Torus(radius_axis=7.0, radius_pipe=2.0) - -artist = Artist(torus) -artist.draw(color=(1.0, 0.0, 0.0)) - -Artist.redraw() diff --git a/docs/userguide/tutorials/artists/try_artists_mesh.py b/docs/userguide/tutorials/artists/try_artists_mesh.py deleted file mode 100644 index 45808d6ad22..00000000000 --- a/docs/userguide/tutorials/artists/try_artists_mesh.py +++ /dev/null @@ -1,12 +0,0 @@ -from compas.datastructures import Mesh -from compas.artists import Artist -from compas.colors import Color - -mesh = Mesh.from_meshgrid(10, 10) - -Artist.clear() - -artist = Artist(mesh) -artist.draw_faces(color={face: Color.pink() for face in mesh.face_sample(size=17)}) - -Artist.redraw() diff --git a/docs/userguide/tutorials/artists/try_artists_network.py b/docs/userguide/tutorials/artists/try_artists_network.py deleted file mode 100644 index 38e2f2bde74..00000000000 --- a/docs/userguide/tutorials/artists/try_artists_network.py +++ /dev/null @@ -1,20 +0,0 @@ -from compas.geometry import Pointcloud -from compas.datastructures import Network -from compas.artists import Artist -from compas.colors import Color - -network = Network.from_pointcloud(Pointcloud.from_bounds(8, 5, 3, 53)) - -node = network.node_sample(size=1)[0] -nbrs = network.neighbors(node) -edges = network.connected_edges(node) - -Artist.clear() - -artist = Artist(network) -artist.draw( - nodecolor={n: Color.pink() for n in [node] + nbrs}, - edgecolor={e: Color.pink() for e in edges}, -) - -Artist.redraw() diff --git a/docs/userguide/tutorials/artists/try_artists_shapes.py b/docs/userguide/tutorials/artists/try_artists_shapes.py deleted file mode 100644 index 803304606c1..00000000000 --- a/docs/userguide/tutorials/artists/try_artists_shapes.py +++ /dev/null @@ -1,27 +0,0 @@ -import random -from compas.geometry import Box, Sphere, Cylinder, Cone, Capsule, Torus, Polyhedron -from compas.geometry import Plane, Circle, Pointcloud -from compas.geometry import Translation -from compas.artists import Artist -from compas.colors import Color - -shapes = [ - Box.from_width_height_depth(1, 1, 1), - Sphere([0, 0, 0], 0.3), - Cylinder(Circle(Plane([0, 0, 0], [0, 0, 1]), 0.3), 1.0), - Cone(Circle(Plane([0, 0, 0], [0, 0, 1]), 0.3), 1.0), - Capsule([[0, 0, 0], [1, 0, 0]], 0.2), - Torus(Plane([0, 0, 0], [0, 0, 1]), 1.0, 0.3), - Polyhedron.from_platonicsolid(12), -] - -cloud = Pointcloud.from_bounds(8, 5, 3, len(shapes)) - -Artist.clear() - -for point, shape in zip(cloud, shapes): - shape.transform(Translation.from_vector(point)) - artist = Artist(shape) - artist.draw(color=Color.from_i(random.random())) - -Artist.redraw() diff --git a/docs/userguide/tutorials/artists/try_artists_volmesh.py b/docs/userguide/tutorials/artists/try_artists_volmesh.py deleted file mode 100644 index ed42ab05053..00000000000 --- a/docs/userguide/tutorials/artists/try_artists_volmesh.py +++ /dev/null @@ -1,12 +0,0 @@ -from compas.datastructures import VolMesh -from compas.artists import Artist -from compas.colors import Color - -mesh = VolMesh.from_meshgrid(dx=10, nx=10) - -Artist.clear() - -artist = Artist(mesh) -artist.draw_cells(color={cell: Color.pink() for cell in mesh.cell_sample(size=83)}) - -Artist.redraw() diff --git a/docs/userguide/tutorials/artists/vectorartist.py b/docs/userguide/tutorials/artists/vectorartist.py deleted file mode 100644 index f1f86d78d2f..00000000000 --- a/docs/userguide/tutorials/artists/vectorartist.py +++ /dev/null @@ -1,28 +0,0 @@ -from math import pi -from compas.geometry import Vector -from compas.geometry import Rotation -from compas.artists import Artist -from compas.colors import Color - -Artist.clear() - -vector = Vector(1, 0, 0) -artist = Artist(vector) -# artist.color = (0.0, 1.0, 0.0) - -# for i in range(11): -# artist.draw( -# color=Color.from_i(i / 10), -# point=[i, 0, 0], -# show_point=True -# ) - -step = pi / 10.0 - -for i in range(11): - artist.draw(color=Color.from_i(i / 10)) - - rotation = Rotation.from_axis_and_angle([0, 0, 1], angle=step) - vector.transform(rotation) - -Artist.redraw() diff --git a/docs/userguide/tutorials/artists/volmeshartist.py b/docs/userguide/tutorials/artists/volmeshartist.py deleted file mode 100644 index ed42ab05053..00000000000 --- a/docs/userguide/tutorials/artists/volmeshartist.py +++ /dev/null @@ -1,12 +0,0 @@ -from compas.datastructures import VolMesh -from compas.artists import Artist -from compas.colors import Color - -mesh = VolMesh.from_meshgrid(dx=10, nx=10) - -Artist.clear() - -artist = Artist(mesh) -artist.draw_cells(color={cell: Color.pink() for cell in mesh.cell_sample(size=83)}) - -Artist.redraw() diff --git a/docs/userguide/tutorials/files/drinking_bird.py b/docs/userguide/tutorials/files/drinking_bird.py index 1e839b3324b..615b4c4a48e 100644 --- a/docs/userguide/tutorials/files/drinking_bird.py +++ b/docs/userguide/tutorials/files/drinking_bird.py @@ -1,4 +1,4 @@ -from compas.artists import Artist +from compas.scene import Scene from compas.robots import Joint from compas.robots import RobotModel from compas.geometry import Box @@ -49,6 +49,6 @@ hat_joint_origin = Frame([0, 0, 1 - 0.3 + 1.5 / 2], [1, 0, 0], [0, 1, 0]) model.add_joint("hat_joint", Joint.FIXED, head_link, hat_link, origin=hat_joint_origin) -artist = Artist(model, layer="COMPAS::Example Robot") -artist.clear_layer() -artist.draw_visual() +scene = Scene() +scene.add(model, layer="COMPAS::Example Robot") +scene.redraw() \ No newline at end of file diff --git a/docs/userguide/tutorials/geometry/curves_and_surfaces/curve_closest_point.py b/docs/userguide/tutorials/geometry/curves_and_surfaces/curve_closest_point.py deleted file mode 100644 index 893c8cb1c8b..00000000000 --- a/docs/userguide/tutorials/geometry/curves_and_surfaces/curve_closest_point.py +++ /dev/null @@ -1,27 +0,0 @@ -from compas.geometry import Point -from compas.geometry import NurbsCurve -from compas.artists import Artist -from compas.colors import Color - - -points = [Point(0, 0, 0), Point(3, 0, 2), Point(6, 0, -3), Point(8, 0, 0)] -curve = NurbsCurve.from_interpolation(points) - -projection_point = Point(2, -1, 0) - -closest_point, t = curve.closest_point(projection_point, return_parameter=True) - -print(curve.point_at(t) == closest_point) - -# ============================================================================== -# Visualisation -# ============================================================================== - -Artist.clear() - -Artist(curve, color=Color.from_hex("#0092D2")).draw() - -Artist(projection_point).draw() -Artist(closest_point).draw() - -Artist.redraw() diff --git a/docs/userguide/tutorials/geometry/curves_and_surfaces/curve_comparison1.py b/docs/userguide/tutorials/geometry/curves_and_surfaces/curve_comparison1.py deleted file mode 100644 index 3607a9c1f26..00000000000 --- a/docs/userguide/tutorials/geometry/curves_and_surfaces/curve_comparison1.py +++ /dev/null @@ -1,52 +0,0 @@ -from compas.geometry import Point -from compas.geometry import Polyline, Bezier -from compas.geometry import NurbsCurve -from compas.artists import Artist -from compas.colors import Color - - -points = [Point(0, 0, 0), Point(1, 3, 0), Point(2, 0, 0)] -bezier = Bezier(points) - -points = [Point(3, 0, 0), Point(4, 3, 0), Point(5, 0, 0)] - -curve1 = NurbsCurve.from_parameters( - points=points, - weights=[1.0, 1.0, 1.0], - knots=[0.0, 1.0], - multiplicities=[3, 3], - degree=2, -) - -curve2 = NurbsCurve.from_parameters( - points=points, - weights=[1.0, 2.0, 1.0], - knots=[0.0, 1.0], - multiplicities=[3, 3], - degree=2, -) - -curve3 = NurbsCurve.from_parameters( - points=points, - weights=[1.0, 1.0, 1.0], - knots=[0.0, 1.0, 2.0, 3.0, 4.0, 5.0], - multiplicities=[1, 1, 1, 1, 1, 1], - degree=2, -) - -# ============================================================================== -# Visualisation -# ============================================================================== - -Artist.clear() - -Artist(Polyline(bezier.points)).draw() -Artist(Polyline(bezier.locus())).draw(show_points=True) - -Artist(Polyline(curve1.points)).draw(show_points=True) - -Artist(curve1).draw(color=Color.black()) -Artist(curve2).draw(color=Color.pink()) -Artist(curve3).draw(color=Color.azure()) - -Artist.redraw() diff --git a/docs/userguide/tutorials/geometry/curves_and_surfaces/curve_comparison2.py b/docs/userguide/tutorials/geometry/curves_and_surfaces/curve_comparison2.py deleted file mode 100644 index 0d2b532c751..00000000000 --- a/docs/userguide/tutorials/geometry/curves_and_surfaces/curve_comparison2.py +++ /dev/null @@ -1,81 +0,0 @@ -from compas.geometry import Point -from compas.geometry import Polyline, Bezier -from compas.geometry import NurbsCurve -from compas.artists import Artist -from compas.colors import Color - - -points = [Point(0, 0, 0), Point(1, 2, 0), Point(2, -2, 0), Point(3, 0, 0)] -bezier = Bezier(points) - -points = [Point(4, 0, 0), Point(5, 2, 0), Point(6, -2, 0), Point(7, 0, 0)] - -curve1 = NurbsCurve.from_parameters( - points=points, - weights=[1.0, 1.0, 1.0, 1.0], - knots=[0.0, 1.0], - multiplicities=[4, 4], - degree=3, -) - -curve2 = NurbsCurve.from_parameters( - points=points, - weights=[1.0, 2.0, 2.0, 1.0], - knots=[0.0, 1.0], - multiplicities=[4, 4], - degree=3, -) - -curve3 = NurbsCurve.from_parameters( - points=points, - weights=[1.0, 1.0, 1.0, 1.0], - knots=[0.0, 1 / 3, 2 / 3, 1.0], - multiplicities=[3, 1, 1, 3], - degree=3, -) - -curve4 = NurbsCurve.from_parameters( - points=points, - weights=[1.0, 1.0, 1.0, 1.0], - knots=[0.0, 1 / 5, 2 / 5, 3 / 5, 4 / 5, 1.0], - multiplicities=[2, 1, 1, 1, 1, 2], - degree=3, -) - -curve5 = NurbsCurve.from_parameters( - points=points, - weights=[1.0, 1.0, 1.0, 1.0], - knots=[0.0, 1 / 7, 2 / 7, 3 / 7, 4 / 7, 5 / 7, 6 / 7, 1.0], - multiplicities=[1, 1, 1, 1, 1, 1, 1, 1], - degree=3, -) - -# curve6 = NurbsCurve.from_parameters( -# points=points, -# weights=[1.0, 1.0, 1.0, 1.0], -# knots=[0.0, 0.5, 1.0], -# multiplicities=[3, 1, 3], -# degree=2 -# ) - -# ============================================================================== -# Visualisation -# ============================================================================== - -Artist.clear() - -Artist(Polyline(bezier.points)).draw() -Artist(Polyline(bezier.locus())).draw() - -Artist(Polyline(curve1.points)).draw(show_points=True) - -color = Color.red() - -Artist(curve1).draw(color=color) -Artist(curve2).draw(color=color.lightened(factor=20)) -Artist(curve3).draw(color=color.lightened(factor=40)) -Artist(curve4).draw(color=color.lightened(factor=60)) -Artist(curve5).draw(color=color.lightened(factor=80)) -# Artist(curve6).draw(color=color.lightened(factor=50)) - -Artist.redraw() diff --git a/docs/userguide/tutorials/geometry/curves_and_surfaces/curve_from_circle.py b/docs/userguide/tutorials/geometry/curves_and_surfaces/curve_from_circle.py deleted file mode 100644 index 8ecff71057d..00000000000 --- a/docs/userguide/tutorials/geometry/curves_and_surfaces/curve_from_circle.py +++ /dev/null @@ -1,21 +0,0 @@ -from compas.geometry import Vector, Point, Plane -from compas.geometry import Polyline -from compas.geometry import Circle -from compas.geometry import NurbsCurve -from compas.artists import Artist -from compas.colors import Color - - -circle = Circle(Plane(Point(0, 0, 0), Vector(0, 0, 1)), 1.0) -curve = NurbsCurve.from_circle(circle) - -# ============================================================================== -# Visualisation -# ============================================================================== - -Artist.clear() - -Artist(curve).draw(color=Color.green()) -Artist(Polyline(curve.points)).draw(show_points=True) - -Artist.redraw() diff --git a/docs/userguide/tutorials/geometry/curves_and_surfaces/curve_from_ellipse.py b/docs/userguide/tutorials/geometry/curves_and_surfaces/curve_from_ellipse.py deleted file mode 100644 index 0ee6da9a32c..00000000000 --- a/docs/userguide/tutorials/geometry/curves_and_surfaces/curve_from_ellipse.py +++ /dev/null @@ -1,21 +0,0 @@ -from compas.geometry import Vector, Point, Plane -from compas.geometry import Polyline -from compas.geometry import Ellipse -from compas.geometry import NurbsCurve -from compas.artists import Artist -from compas.colors import Color - - -ellipse = Ellipse(Plane(Point(0, 0, 0), Vector(0, 0, 1)), 2.0, 1.0) -curve = NurbsCurve.from_ellipse(ellipse) - -# ============================================================================== -# Visualisation -# ============================================================================== - -Artist.clear() - -Artist(curve).draw(color=Color.green()) -Artist(Polyline(curve.points)).draw(show_points=True) - -Artist.redraw() diff --git a/docs/userguide/tutorials/geometry/curves_and_surfaces/curve_from_interpolation.py b/docs/userguide/tutorials/geometry/curves_and_surfaces/curve_from_interpolation.py deleted file mode 100644 index c449ffea17e..00000000000 --- a/docs/userguide/tutorials/geometry/curves_and_surfaces/curve_from_interpolation.py +++ /dev/null @@ -1,26 +0,0 @@ -from compas.geometry import Point -from compas.geometry import Polyline, Bezier -from compas.geometry import NurbsCurve -from compas.artists import Artist -from compas.colors import Color - - -points = [Point(0, 0, 0), Point(3, 6, 0), Point(6, -3, 3), Point(10, 0, 0)] -bezier = Bezier(points) -points = bezier.locus(10) - -curve = NurbsCurve.from_interpolation(points) - -# ============================================================================== -# Visualisation -# ============================================================================== - -Artist.clear() - -Artist(curve).draw(color=Color.green()) -Artist(Polyline(curve.points)).draw(show_points=True) - -for point in points: - Artist(point).draw() - -Artist.redraw() diff --git a/docs/userguide/tutorials/geometry/curves_and_surfaces/curve_from_line.py b/docs/userguide/tutorials/geometry/curves_and_surfaces/curve_from_line.py deleted file mode 100644 index 60eb4c2205f..00000000000 --- a/docs/userguide/tutorials/geometry/curves_and_surfaces/curve_from_line.py +++ /dev/null @@ -1,22 +0,0 @@ -from compas.geometry import Point -from compas.geometry import Line -from compas.geometry import NurbsCurve -from compas.artists import Artist -from compas.colors import Color - - -line = Line(Point(0, 0, 0), Point(3, 3, 0)) -curve = NurbsCurve.from_line(line) - -# ============================================================================== -# Visualisation -# ============================================================================== - -Artist.clear() - -Artist(curve).draw(color=Color.green()) - -for point in curve.points: - Artist(point).draw() - -Artist.redraw() diff --git a/docs/userguide/tutorials/geometry/curves_and_surfaces/curve_from_parameters.py b/docs/userguide/tutorials/geometry/curves_and_surfaces/curve_from_parameters.py deleted file mode 100644 index 1362bd83833..00000000000 --- a/docs/userguide/tutorials/geometry/curves_and_surfaces/curve_from_parameters.py +++ /dev/null @@ -1,27 +0,0 @@ -from compas.geometry import Point -from compas.geometry import Polyline -from compas.geometry import NurbsCurve -from compas.artists import Artist -from compas.colors import Color - - -points = [Point(0, 0, 0), Point(3, 6, 0), Point(6, -3, 3), Point(10, 0, 0)] - -curve = NurbsCurve.from_parameters( - points=points, - weights=[1.0, 1.0, 1.0, 1.0], - knots=[0.0, 1.0], - multiplicities=[4, 4], - degree=3, -) - -# ============================================================================== -# Visualisation -# ============================================================================== - -Artist.clear() - -Artist(curve).draw(color=Color.green()) -Artist(Polyline(curve.points)).draw(show_points=True) - -Artist.redraw() diff --git a/docs/userguide/tutorials/geometry/curves_and_surfaces/curve_from_points.py b/docs/userguide/tutorials/geometry/curves_and_surfaces/curve_from_points.py deleted file mode 100644 index 59dad83714e..00000000000 --- a/docs/userguide/tutorials/geometry/curves_and_surfaces/curve_from_points.py +++ /dev/null @@ -1,21 +0,0 @@ -from compas.geometry import Point -from compas.geometry import Polyline -from compas.geometry import NurbsCurve -from compas.artists import Artist -from compas.colors import Color - - -points = [Point(0, 0, 0), Point(3, 6, 0), Point(6, -3, 3), Point(10, 0, 0)] - -curve = NurbsCurve.from_points(points) - -# ============================================================================== -# Visualisation -# ============================================================================== - -Artist.clear() - -Artist(curve).draw(color=Color.green()) -Artist(Polyline(curve.points)).draw(show_points=True) - -Artist.redraw() diff --git a/docs/userguide/tutorials/geometry/curves_and_surfaces/surface_aabb.py b/docs/userguide/tutorials/geometry/curves_and_surfaces/surface_aabb.py deleted file mode 100644 index 4821d031adb..00000000000 --- a/docs/userguide/tutorials/geometry/curves_and_surfaces/surface_aabb.py +++ /dev/null @@ -1,43 +0,0 @@ -from math import radians -from compas.geometry import Point, Translation, Rotation -from compas.geometry import Polyline -from compas.geometry import NurbsSurface -from compas.artists import Artist - - -points = [ - [Point(0, 0, 0), Point(1, 0, 0), Point(2, 0, 0), Point(3, 0, 0), Point(4, 0, 0)], - [Point(0, 1, 0), Point(1, 1, 2), Point(2, 1, 2), Point(3, 1, 0), Point(4, 1, 0)], - [Point(0, 2, 0), Point(1, 2, 2), Point(2, 2, 2), Point(3, 2, 0), Point(4, 2, 0)], - [Point(0, 3, 0), Point(1, 3, 0), Point(2, 3, 0), Point(3, 3, 0), Point(4, 3, 0)], -] - -surface = NurbsSurface.from_points(points=points) - -T = Translation.from_vector([0, -1.5, 0]) -R = Rotation.from_axis_and_angle([0, 0, 1], radians(45)) - -surface.transform(R * T) - -# ============================================================================== -# AABB -# ============================================================================== - -box = surface.aabb(optimal=True) - -# ============================================================================== -# Visualisation -# ============================================================================== - -Artist.clear() - -for row in surface.points: - Artist(Polyline(row)).draw() - -for col in zip(*list(surface.points)): - Artist(Polyline(col)).draw() - -Artist(surface).draw() -Artist(box).draw() - -Artist.redraw() diff --git a/docs/userguide/tutorials/geometry/curves_and_surfaces/surface_frames.py b/docs/userguide/tutorials/geometry/curves_and_surfaces/surface_frames.py deleted file mode 100644 index 804c02af11c..00000000000 --- a/docs/userguide/tutorials/geometry/curves_and_surfaces/surface_frames.py +++ /dev/null @@ -1,34 +0,0 @@ -from compas.geometry import Point -from compas.utilities import meshgrid, flatten -from compas.geometry import NurbsSurface -from compas.artists import Artist - - -points = [ - [Point(0, 0, 0), Point(1, 0, 0), Point(2, 0, 0), Point(3, 0, 0)], - [Point(0, 1, 0), Point(1, 1, 2), Point(2, 1, 2), Point(3, 1, 0)], - [Point(0, 2, 0), Point(1, 2, 2), Point(2, 2, 2), Point(3, 2, 0)], - [Point(0, 3, 0), Point(1, 3, 0), Point(2, 3, 0), Point(3, 3, 0)], -] - -surface = NurbsSurface.from_points(points=points) - -# ============================================================================== -# Frames -# ============================================================================== - -U, V = meshgrid(surface.u_space(), surface.v_space(), "ij") -frames = [surface.frame_at(u, v) for u, v in zip(flatten(U), flatten(V))] - -# ============================================================================== -# Visualisation -# ============================================================================== - -Artist.clear() - -Artist(surface).draw() - -for frame in frames: - Artist(frame).draw() - -Artist.redraw() diff --git a/docs/userguide/tutorials/geometry/curves_and_surfaces/surface_from_meshgrid.py b/docs/userguide/tutorials/geometry/curves_and_surfaces/surface_from_meshgrid.py deleted file mode 100644 index 267b293c934..00000000000 --- a/docs/userguide/tutorials/geometry/curves_and_surfaces/surface_from_meshgrid.py +++ /dev/null @@ -1,44 +0,0 @@ -from compas.geometry import Point -from compas.geometry import Polyline -from compas.utilities import meshgrid, linspace -from compas.geometry import NurbsSurface -from compas.artists import Artist - - -UU, VV = meshgrid(linspace(0, 8, 9), linspace(0, 5, 6)) - -Z = 0.5 - -points = [] -for i, (U, V) in enumerate(zip(UU, VV)): - row = [] - for j, (u, v) in enumerate(zip(U, V)): - if i == 0 or i == 5 or j == 0 or j == 8: - z = 0.0 - elif i < 2 or i > 3: - z = -1.0 - else: - if j < 2 or j > 6: - z = -1.0 - else: - z = Z - row.append(Point(u, v, z)) - points.append(row) - -surface = NurbsSurface.from_points(points=points) - -# ============================================================================== -# Visualisation -# ============================================================================== - -Artist.clear() - -for row in surface.points: - Artist(Polyline(row)).draw() - -for col in zip(*list(surface.points)): - Artist(Polyline(col)).draw() - -Artist(surface).draw() - -Artist.redraw() diff --git a/docs/userguide/tutorials/geometry/curves_and_surfaces/surface_from_parameters.py b/docs/userguide/tutorials/geometry/curves_and_surfaces/surface_from_parameters.py deleted file mode 100644 index d73814b3128..00000000000 --- a/docs/userguide/tutorials/geometry/curves_and_surfaces/surface_from_parameters.py +++ /dev/null @@ -1,103 +0,0 @@ -from compas.geometry import Point -from compas.geometry import Polyline -from compas.geometry import NurbsSurface -from compas.artists import Artist - - -points = [ - [ - Point(0, 0, 0), - Point(1, 0, +0), - Point(2, 0, +0), - Point(3, 0, +0), - Point(4, 0, +0), - Point(5, 0, 0), - ], - [ - Point(0, 1, 0), - Point(1, 1, -1), - Point(2, 1, -1), - Point(3, 1, -1), - Point(4, 1, -1), - Point(5, 1, 0), - ], - [ - Point(0, 2, 0), - Point(1, 2, -1), - Point(2, 2, +2), - Point(3, 2, +2), - Point(4, 2, -1), - Point(5, 2, 0), - ], - [ - Point(0, 3, 0), - Point(1, 3, -1), - Point(2, 3, +2), - Point(3, 3, +2), - Point(4, 3, -1), - Point(5, 3, 0), - ], - [ - Point(0, 4, 0), - Point(1, 4, -1), - Point(2, 4, -1), - Point(3, 4, -1), - Point(4, 4, -1), - Point(5, 4, 0), - ], - [ - Point(0, 5, 0), - Point(1, 5, +0), - Point(2, 5, +0), - Point(3, 5, +0), - Point(4, 5, +0), - Point(5, 5, 0), - ], -] - -weights = [ - [1.0, 1.0, 1.0, 1.0, 1.0, 1.0], - [1.0, 1.0, 1.0, 1.0, 1.0, 1.0], - [1.0, 1.0, 1.0, 1.0, 1.0, 1.0], - [1.0, 1.0, 1.0, 1.0, 1.0, 1.0], - [1.0, 1.0, 1.0, 1.0, 1.0, 1.0], - [1.0, 1.0, 1.0, 1.0, 1.0, 1.0], -] - -surface = NurbsSurface.from_parameters( - points=points, - weights=weights, - u_knots=[ - 1.0, - 1 + 1 / 9, - 1 + 2 / 9, - 1 + 3 / 9, - 1 + 4 / 9, - 1 + 5 / 9, - 1 + 6 / 9, - 1 + 7 / 9, - 1 + 8 / 9, - 2.0, - ], - v_knots=[0.0, 1 / 9, 2 / 9, 3 / 9, 4 / 9, 5 / 9, 6 / 9, 7 / 9, 8 / 9, 1.0], - u_mults=[1, 1, 1, 1, 1, 1, 1, 1, 1, 1], - v_mults=[1, 1, 1, 1, 1, 1, 1, 1, 1, 1], - u_degree=3, - v_degree=3, -) - -# ============================================================================== -# Visualisation -# ============================================================================== - -Artist.clear() - -for row in surface.points: - Artist(Polyline(row)).draw() - -for col in zip(*list(surface.points)): - Artist(Polyline(col)).draw() - -Artist(surface).draw() - -Artist.redraw() diff --git a/docs/userguide/tutorials/geometry/curves_and_surfaces/surface_from_points.py b/docs/userguide/tutorials/geometry/curves_and_surfaces/surface_from_points.py deleted file mode 100644 index b1086dbb1f7..00000000000 --- a/docs/userguide/tutorials/geometry/curves_and_surfaces/surface_from_points.py +++ /dev/null @@ -1,30 +0,0 @@ -from compas.geometry import Point -from compas.geometry import Polyline -from compas.geometry import NurbsSurface -from compas.artists import Artist - - -points = [ - [Point(0, 0, 0), Point(1, 0, 0), Point(2, 0, 0), Point(3, 0, 0)], - [Point(0, 1, 0), Point(1, 1, 2), Point(2, 1, 2), Point(3, 1, 0)], - [Point(0, 2, 0), Point(1, 2, 2), Point(2, 2, 2), Point(3, 2, 0)], - [Point(0, 3, 0), Point(1, 3, 0), Point(2, 3, 0), Point(3, 3, 0)], -] - -surface = NurbsSurface.from_points(points=points) - -# ============================================================================== -# Visualisation -# ============================================================================== - -Artist.clear() - -for row in surface.points: - Artist(Polyline(row)).draw() - -for col in zip(*list(surface.points)): - Artist(Polyline(col)).draw() - -Artist(surface).draw() - -Artist.redraw() diff --git a/docs/userguide/tutorials/geometry/curves_and_surfaces/surface_isocurves.py b/docs/userguide/tutorials/geometry/curves_and_surfaces/surface_isocurves.py deleted file mode 100644 index d32c44836fb..00000000000 --- a/docs/userguide/tutorials/geometry/curves_and_surfaces/surface_isocurves.py +++ /dev/null @@ -1,40 +0,0 @@ -from compas.geometry import Point -from compas.geometry import Polyline -from compas.geometry import NurbsSurface -from compas.artists import Artist - - -points = [ - [Point(0, 0, 0), Point(1, 0, 0), Point(2, 0, 0), Point(3, 0, 0), Point(4, 0, 0)], - [Point(0, 1, 0), Point(1, 1, 2), Point(2, 1, 2), Point(3, 1, 0), Point(4, 1, 0)], - [Point(0, 2, 0), Point(1, 2, 2), Point(2, 2, 2), Point(3, 2, 0), Point(4, 2, 0)], - [Point(0, 3, 0), Point(1, 3, 0), Point(2, 3, 0), Point(3, 3, 0), Point(4, 3, 0)], -] - -surface = NurbsSurface.from_points(points=points) - -# ============================================================================== -# Isocurves -# ============================================================================== - -u_curves = [] -for u in surface.u_space(): - u_curves.append(surface.u_isocurve(u)) - -v_curves = [] -for v in surface.v_space(): - v_curves.append(surface.v_isocurve(v)) - -# ============================================================================== -# Visualisation -# ============================================================================== - -Artist.clear() - -for curve in u_curves: - Artist(Polyline(curve.locus())).draw() - -for curve in v_curves: - Artist(Polyline(curve.locus())).draw() - -Artist.redraw() diff --git a/docs/userguide/tutorials/geometry/curves_and_surfaces/surface_jsondata.py b/docs/userguide/tutorials/geometry/curves_and_surfaces/surface_jsondata.py deleted file mode 100644 index fbb53bff069..00000000000 --- a/docs/userguide/tutorials/geometry/curves_and_surfaces/surface_jsondata.py +++ /dev/null @@ -1,45 +0,0 @@ -from compas.geometry import Point -from compas.geometry import Polyline -from compas.geometry import NurbsSurface -from compas.artists import Artist - - -points = [ - [Point(0, 0, 0), Point(1, 0, 0), Point(2, 0, 0), Point(3, 0, 0)], - [Point(0, 1, 0), Point(1, 1, 2), Point(2, 1, 2), Point(3, 1, 0)], - [Point(0, 2, 0), Point(1, 2, 2), Point(2, 2, 2), Point(3, 2, 0)], - [Point(0, 3, 0), Point(1, 3, 0), Point(2, 3, 0), Point(3, 3, 0)], -] - -surface = NurbsSurface.from_points(points=points) - -# ============================================================================== -# JSON Data -# ============================================================================== - -string = surface.to_jsonstring(pretty=True) - -print(string) - -other = NurbsSurface.from_jsonstring(string) - -# print(surface == other) - -# ============================================================================== -# Visualisation -# ============================================================================== - -Artist.clear() - -u = surface.u_isocurve(0.5 * sum(surface.u_domain)) -v = surface.v_isocurve(0.5 * sum(surface.v_domain)) - -Artist(Polyline(u.locus())).draw() -Artist(Polyline(v.locus())).draw() - -# for curve in surface.boundary(): -# Artist(Polyline(curve.locus())).draw() - -Artist(other).draw() - -Artist.redraw() diff --git a/docs/userguide/tutorials/geometry/curves_and_surfaces/surface_random.py b/docs/userguide/tutorials/geometry/curves_and_surfaces/surface_random.py deleted file mode 100644 index b044928815a..00000000000 --- a/docs/userguide/tutorials/geometry/curves_and_surfaces/surface_random.py +++ /dev/null @@ -1,36 +0,0 @@ -import random -from compas.geometry import Polyline -from compas.geometry import NurbsSurface -from compas.artists import Artist - - -U = 10 -V = 20 - -surface = NurbsSurface.from_meshgrid(nu=U, nv=V) - -# ============================================================================== -# Update -# ============================================================================== - -for u in range(1, U): - for v in range(1, V): - point = surface.points[u, v] - point.z = random.choice([+1, -1]) * random.random() - surface.points[u, v] = point - -# ============================================================================== -# Visualisation -# ============================================================================== - -Artist.clear() - -for row in surface.points: - Artist(Polyline(row)).draw() - -for col in zip(*list(surface.points)): - Artist(Polyline(col)).draw() - -Artist(surface).draw() - -Artist.redraw() diff --git a/docs/userguide/tutorials/geometry/curves_and_surfaces/surface_spacepoints.py b/docs/userguide/tutorials/geometry/curves_and_surfaces/surface_spacepoints.py deleted file mode 100644 index a6ba872bce7..00000000000 --- a/docs/userguide/tutorials/geometry/curves_and_surfaces/surface_spacepoints.py +++ /dev/null @@ -1,39 +0,0 @@ -from compas.geometry import Point -from compas.geometry import Polyline -from compas.geometry import NurbsSurface -from compas.artists import Artist - - -points = [ - [Point(0, 0, 0), Point(1, 0, 0), Point(2, 0, 0), Point(3, 0, 0), Point(4, 0, 0)], - [Point(0, 1, 0), Point(1, 1, 2), Point(2, 1, 2), Point(3, 1, 0), Point(4, 1, 0)], - [Point(0, 2, 0), Point(1, 2, 2), Point(2, 2, 2), Point(3, 2, 0), Point(4, 2, 0)], - [Point(0, 3, 0), Point(1, 3, 0), Point(2, 3, 0), Point(3, 3, 0), Point(4, 3, 0)], -] - -surface = NurbsSurface.from_points(points=points) - -# ============================================================================== -# Points over UV space -# ============================================================================== - -spacepoints = surface.xyz(nu=50, nv=10) - -# ============================================================================== -# Visualisation -# ============================================================================== - -Artist.clear() - -for row in surface.points: - Artist(Polyline(row)).draw() - -for col in zip(*list(surface.points)): - Artist(Polyline(col)).draw() - -Artist(surface).draw() - -for point in spacepoints: - Artist(point).draw() - -Artist.redraw() diff --git a/docs/userguide/tutorials/artists/index.rst b/docs/userguide/tutorials/scene/index.rst similarity index 75% rename from docs/userguide/tutorials/artists/index.rst rename to docs/userguide/tutorials/scene/index.rst index bb252a59273..22da4589e62 100644 --- a/docs/userguide/tutorials/artists/index.rst +++ b/docs/userguide/tutorials/scene/index.rst @@ -1,5 +1,5 @@ *********************** -Introduction to Artists +Introduction to Scene *********************** More info coming soon... diff --git a/docs/userguide/tutorials/scene/scene.py b/docs/userguide/tutorials/scene/scene.py new file mode 100644 index 00000000000..cd2522ff4c0 --- /dev/null +++ b/docs/userguide/tutorials/scene/scene.py @@ -0,0 +1,86 @@ +from compas.scene import Scene +from compas.geometry import Box +from compas.geometry import Capsule +from compas.geometry import Circle +from compas.geometry import Cone +from compas.geometry import Cylinder +from compas.geometry import Ellipse +from compas.geometry import Frame +from compas.geometry import Line +from compas.geometry import Point +from compas.geometry import Polygon +from compas.geometry import Polyhedron +from compas.geometry import Polyline +from compas.geometry import Sphere +from compas.geometry import Torus +from compas.geometry import Vector +# from compas.geometry import Plane + +from compas.datastructures import Mesh +from compas.datastructures import Network +from compas.datastructures import VolMesh + +from compas.geometry import Translation + + +box = Box.from_width_height_depth(1, 1, 1) +capsule = Capsule(0.5, 1, Frame.worldXY()) +circle = Circle(1, Frame.worldXY()) +cone = Cone(1, 1, Frame.worldXY()) +cylinder = Cylinder(1, 1, Frame.worldXY()) +line = Line(Point(0, 0, 0), Point(1, 1, 1)) +point = Point(0, 0, 0) +polygon = Polygon.from_sides_and_radius_xy(5, 1) +polyhedron = Polyhedron.from_platonicsolid(4) +polyline = Polyline([[0, 0, 0], [1, 0, 0], [1, 0, 1]]) +sphere = Sphere(1) +torus = Torus(1, 0.3, Frame.worldXY()) +vector = Vector(0, 0, 1) + +# TODO: Make these work everywhere +# ellipse = Ellipse(1, 0.5, Frame.worldXY()) +# frame = Frame.worldXY() +# plane = Plane(Point(0, 0, 0), Vector(0, 0, 1)) + + +mesh = Mesh.from_polyhedron(8) +network = Network.from_nodes_and_edges([(0, 0, 0), (0, -1.5, 0), (-1, 1, 0), (1, 1, 0)], [(0, 1), (0, 2), (0, 3)]) +volmesh = VolMesh.from_meshgrid(1, 1, 1, 2, 2, 2) + + +scene = Scene() +scene.add(box) +scene.add(capsule) +scene.add(circle) +scene.add(cone) +scene.add(cylinder) +scene.add(line) +scene.add(point) +scene.add(polygon) +scene.add(polyhedron) +scene.add(polyline) +scene.add(sphere) +scene.add(torus) +scene.add(vector) + +# scene.add(ellipse) +# scene.add(frame) +# scene.add(plane) + +scene.add(mesh) +scene.add(network) +scene.add(volmesh) + + +x = 0 +y = 0 +for obj in scene.sceneobjects: + obj.transformation = Translation.from_vector([x, y, 0]) + x += 5 + if x > 20: + x = 0 + y += 5 + + +scene.print_hierarchy() +scene.redraw() diff --git a/src/compas/artists/__init__.py b/src/compas/artists/__init__.py deleted file mode 100644 index bc456709517..00000000000 --- a/src/compas/artists/__init__.py +++ /dev/null @@ -1,35 +0,0 @@ -""" -This package defines artists for visualising COMPAS objects. -Every object type is paired with a corresponding artist type that is capable of visualizing the data of the object. -The artists are implemented as pluggables, and automatically switch between plugins depending on the contexct in which they are used. -""" - -from __future__ import print_function -from __future__ import absolute_import -from __future__ import division - -from .exceptions import DataArtistNotRegisteredError -from .exceptions import NoArtistContextError -from .artist import Artist -from .meshartist import MeshArtist -from .networkartist import NetworkArtist -from .geometryartist import GeometryArtist -from .volmeshartist import VolMeshArtist - -from .artist import clear -from .artist import redraw -from .artist import register_artists - - -__all__ = [ - "DataArtistNotRegisteredError", - "NoArtistContextError", - "Artist", - "MeshArtist", - "NetworkArtist", - "GeometryArtist", - "VolMeshArtist", - "clear", - "redraw", - "register_artists", -] diff --git a/src/compas/colors/colordict.py b/src/compas/colors/colordict.py index 4b6b038f363..5e8d6462476 100644 --- a/src/compas/colors/colordict.py +++ b/src/compas/colors/colordict.py @@ -83,7 +83,7 @@ def update(self, other): Parameters ---------- - other : dict or :class:`compas.artists.ColorDict` + other : dict or :class:`compas.scene.ColorDict` The other dictionary. Returns diff --git a/src/compas/datastructures/assembly/part.py b/src/compas/datastructures/assembly/part.py index 390b9d605f9..9524e528d2b 100644 --- a/src/compas/datastructures/assembly/part.py +++ b/src/compas/datastructures/assembly/part.py @@ -193,7 +193,7 @@ def get_geometry(self, with_features=False): """ Returns a transformed copy of the part's geometry. - The returned type can be drawn with an Artist. + The returned type can be drawn with a scene object. Parameters ---------- diff --git a/src/compas/datastructures/tree/tree.py b/src/compas/datastructures/tree/tree.py index bcc587283c0..63a36b84926 100644 --- a/src/compas/datastructures/tree/tree.py +++ b/src/compas/datastructures/tree/tree.py @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- + from __future__ import print_function from __future__ import absolute_import from __future__ import division @@ -438,12 +440,14 @@ def get_nodes_by_name(self, name): def __repr__(self): return "".format(len(list(self.nodes))) - def print(self): + def print_hierarchy(self): """Print the spatial hierarchy of the tree.""" - def _print(node, depth=0): - print(" " * depth + str(node)) - for child in node.children: - _print(child, depth + 1) + def _print(node, prefix="", last=True): + connector = "└── " if last else "├── " + print("{}{}{}".format(prefix, connector, node)) + prefix += " " if last else "│ " + for i, child in enumerate(node.children): + _print(child, prefix, i == len(node.children) - 1) _print(self.root) diff --git a/src/compas/rpc/xfunc.py b/src/compas/rpc/xfunc.py index 338d61e689a..4db80d60169 100644 --- a/src/compas/rpc/xfunc.py +++ b/src/compas/rpc/xfunc.py @@ -182,9 +182,8 @@ class XFunc(object): .. code-block:: python import compas - import compas_rhino - from compas_rhino.artists import MeshArtist + from compas.scene import Scene from compas.datastructures import Mesh from compas.utilities import XFunc @@ -213,9 +212,9 @@ class XFunc(object): attr['y'] = xyz[vertex][1] attr['z'] = xyz[vertex][2] - artist = MeshArtist(mesh) - artist.draw_vertices() - artist.draw_edges() + scene = Scene() + scene.add(mesh) + scene.redraw() """ diff --git a/src/compas/scene/__init__.py b/src/compas/scene/__init__.py new file mode 100644 index 00000000000..d19d7d63eae --- /dev/null +++ b/src/compas/scene/__init__.py @@ -0,0 +1,37 @@ +""" +This package defines sceneobjects for visualising COMPAS items (geometry & datastructures). +Every item type is paired with a corresponding scene object type that is capable of visualizing the data of the object. +The scene objects are implemented as pluggables, and automatically switch between plugins depending on the contexct in which they are used. +""" + +from __future__ import print_function +from __future__ import absolute_import +from __future__ import division + +from .exceptions import SceneObjectNotRegisteredError +from .exceptions import NoSceneObjectContextError +from .sceneobject import SceneObject +from .meshobject import MeshObject +from .networkobject import NetworkObject +from .geometryobject import GeometryObject +from .volmeshobject import VolMeshObject + +from .sceneobject import clear +from .sceneobject import redraw +from .sceneobject import register_scene_objects + +from .scene import Scene + +__all__ = [ + "SceneObjectNotRegisteredError", + "NoSceneObjectContextError", + "SceneObject", + "MeshObject", + "NetworkObject", + "GeometryObject", + "VolMeshObject", + "Scene", + "clear", + "redraw", + "register_scene_objects", +] diff --git a/src/compas/artists/assemblyartist.py b/src/compas/scene/assemblyobject.py similarity index 100% rename from src/compas/artists/assemblyartist.py rename to src/compas/scene/assemblyobject.py diff --git a/src/compas/artists/descriptors/__init__.py b/src/compas/scene/descriptors/__init__.py similarity index 100% rename from src/compas/artists/descriptors/__init__.py rename to src/compas/scene/descriptors/__init__.py diff --git a/src/compas/artists/descriptors/attribute.py b/src/compas/scene/descriptors/attribute.py similarity index 100% rename from src/compas/artists/descriptors/attribute.py rename to src/compas/scene/descriptors/attribute.py diff --git a/src/compas/artists/descriptors/color.py b/src/compas/scene/descriptors/color.py similarity index 100% rename from src/compas/artists/descriptors/color.py rename to src/compas/scene/descriptors/color.py diff --git a/src/compas/artists/descriptors/colordict.py b/src/compas/scene/descriptors/colordict.py similarity index 100% rename from src/compas/artists/descriptors/colordict.py rename to src/compas/scene/descriptors/colordict.py diff --git a/src/compas/artists/descriptors/protocol.py b/src/compas/scene/descriptors/protocol.py similarity index 100% rename from src/compas/artists/descriptors/protocol.py rename to src/compas/scene/descriptors/protocol.py diff --git a/src/compas/artists/exceptions.py b/src/compas/scene/exceptions.py similarity index 54% rename from src/compas/artists/exceptions.py rename to src/compas/scene/exceptions.py index 105fe5a2bc7..c628888c210 100644 --- a/src/compas/artists/exceptions.py +++ b/src/compas/scene/exceptions.py @@ -3,16 +3,16 @@ from __future__ import division -class DataArtistNotRegisteredError(Exception): - """Exception that is raised when no artist is registered for a given data type.""" +class SceneObjectNotRegisteredError(Exception): + """Exception that is raised when no scene object is registered for a given data type.""" -class NoArtistContextError(Exception): - """Exception that is raised when no artist context is assigned is registered for a given data type.""" +class NoSceneObjectContextError(Exception): + """Exception that is raised when no scene object context is assigned is registered for a given data type.""" def __init__(self): error_message = "No context defined." error_message += "\n\nThis usually means that the script that you are running requires" error_message += "\na CAD environment but it is being ran as a standalone script" error_message += "\n(ie. from the command line or code editor)." - super(NoArtistContextError, self).__init__(error_message) + super(NoSceneObjectContextError, self).__init__(error_message) diff --git a/src/compas/artists/geometryartist.py b/src/compas/scene/geometryobject.py similarity index 68% rename from src/compas/artists/geometryartist.py rename to src/compas/scene/geometryobject.py index 7da5e2d66e8..7fe3a57fa73 100644 --- a/src/compas/artists/geometryartist.py +++ b/src/compas/scene/geometryobject.py @@ -2,12 +2,12 @@ from __future__ import absolute_import from __future__ import division -from .artist import Artist +from .sceneobject import SceneObject from .descriptors.color import ColorAttribute -class GeometryArtist(Artist): - """Base class for artists for geometry objects. +class GeometryObject(SceneObject): + """Base class for scene objects for geometry objects. Parameters ---------- @@ -17,7 +17,7 @@ class GeometryArtist(Artist): Attributes ---------- geometry : :class:`compas.geometry.Geometry` - The geometry object associated with the artist. + The geometry object associated with the scene object. color : :class:`compas.colors.Color` The color of the object. @@ -26,5 +26,5 @@ class GeometryArtist(Artist): color = ColorAttribute(default=None) def __init__(self, geometry, **kwargs): - super(GeometryArtist, self).__init__(item=geometry, **kwargs) + super(GeometryObject, self).__init__(item=geometry, **kwargs) self.geometry = geometry diff --git a/src/compas/artists/meshartist.py b/src/compas/scene/meshobject.py similarity index 95% rename from src/compas/artists/meshartist.py rename to src/compas/scene/meshobject.py index 7f6d91500fe..bd13561d6b8 100644 --- a/src/compas/artists/meshartist.py +++ b/src/compas/scene/meshobject.py @@ -5,13 +5,13 @@ from abc import abstractmethod from compas.geometry import transform_points -from .artist import Artist +from .sceneobject import SceneObject from .descriptors.color import ColorAttribute from .descriptors.colordict import ColorDictAttribute -class MeshArtist(Artist): - """Base class for all mesh artists. +class MeshObject(SceneObject): + """Base class for all mesh scene objects. Parameters ---------- @@ -36,8 +36,8 @@ class MeshArtist(Artist): See Also -------- - :class:`compas.artists.NetworkArtist` - :class:`compas.artists.VolMeshArtist` + :class:`compas.scene.NetworkObject` + :class:`compas.scene.VolMeshObject` """ @@ -48,7 +48,7 @@ class MeshArtist(Artist): face_color = ColorDictAttribute(default=None) def __init__(self, mesh, **kwargs): - super(MeshArtist, self).__init__(item=mesh, **kwargs) + super(MeshObject, self).__init__(item=mesh, **kwargs) self._mesh = None self._vertex_xyz = None self.mesh = mesh @@ -164,7 +164,7 @@ def draw_mesh(self, *args, **kwargs): """Draw the mesh of the mesh. .. deprecated:: 1.14.1 - Use :meth:`~MeshArtist.draw` instead. + Use :meth:`~MeshObject.draw` instead. Returns ------- diff --git a/src/compas/artists/networkartist.py b/src/compas/scene/networkobject.py similarity index 93% rename from src/compas/artists/networkartist.py rename to src/compas/scene/networkobject.py index 9b4ef87f97a..a41797e070d 100644 --- a/src/compas/artists/networkartist.py +++ b/src/compas/scene/networkobject.py @@ -6,12 +6,12 @@ from compas.colors import Color from compas.geometry import transform_points -from .artist import Artist +from .sceneobject import SceneObject from .descriptors.colordict import ColorDictAttribute -class NetworkArtist(Artist): - """Artist for drawing network data structures. +class NetworkObject(SceneObject): + """Scene object for drawing network data structures. Parameters ---------- @@ -21,7 +21,7 @@ class NetworkArtist(Artist): Attributes ---------- network : :class:`compas.datastructures.Network` - The COMPAS network associated with the artist. + The COMPAS network associated with the scene object. node_xyz : dict[hashable, list[float]] Mapping between nodes and their view coordinates. The default view coordinates are the actual coordinates of the nodes of the network. @@ -32,8 +32,8 @@ class NetworkArtist(Artist): See Also -------- - :class:`compas.artists.MeshArtist` - :class:`compas.artists.VolMeshArtist` + :class:`compas.scene.MeshObject` + :class:`compas.scene.VolMeshObject` """ @@ -41,7 +41,7 @@ class NetworkArtist(Artist): edge_color = ColorDictAttribute(default=Color.black()) def __init__(self, network, **kwargs): - super(NetworkArtist, self).__init__(**kwargs) + super(NetworkObject, self).__init__(item=network, **kwargs) self._network = None self._node_xyz = None self.network = network diff --git a/src/compas/scene/scene.py b/src/compas/scene/scene.py new file mode 100644 index 00000000000..49605177208 --- /dev/null +++ b/src/compas/scene/scene.py @@ -0,0 +1,69 @@ +from compas.data import Data +from compas.datastructures import Tree +from compas.datastructures import TreeNode +from compas.scene import SceneObject + + +class Scene(Data): + def __init__(self, name=None): + super(Scene, self).__init__(name) + self._tree = Tree("Scene") + root = TreeNode(name="root") + self.tree.add(root) + + @property + def tree(self): + return self._tree + + @property + def sceneobjects(self): + return [node.attributes["sceneobject"] for node in self.tree.nodes if "sceneobject" in node.attributes] + + def add(self, item, parent=None, **kwargs): + sceneobject = SceneObject(item, **kwargs) + name = item.name or item.__class__.__name__ + node = TreeNode(name, attributes={"sceneobject": sceneobject}) + + if parent is None: + self.tree.add(node, parent=self.tree.root) + else: + parent_node = self._get_node(parent) + self.tree.add(node, parent=parent_node) + + return sceneobject + + def remove(self, sceneobject): + node = self._get_node(sceneobject) + self.tree.remove_node(node) + + def _get_node(self, sceneobject): + for node in self.tree.nodes: + if "sceneobject" in node.attributes: + if node.attributes["sceneobject"] == sceneobject: + return node + raise Exception("Scene object not in scene") + + def redraw(self): + sceneobject = None + + drawn_objects = [] + for sceneobject in self.sceneobjects: + drawn_object = sceneobject.draw() + + # TODO: unify output of draw(), so we don't have to do this + if isinstance(drawn_object, (list, tuple)): + for item in drawn_object: + if isinstance(item, (list, tuple)): + drawn_objects.extend(item) + else: + drawn_objects.append(item) + else: + drawn_objects.append(drawn_object) + + if drawn_objects: + sceneobject.redraw() + + return drawn_objects + + def print_hierarchy(self): + self.tree.print_hierarchy() diff --git a/src/compas/artists/artist.py b/src/compas/scene/sceneobject.py similarity index 55% rename from src/compas/artists/artist.py rename to src/compas/scene/sceneobject.py index 08f8b93aa54..c35dea7b1ee 100644 --- a/src/compas/artists/artist.py +++ b/src/compas/scene/sceneobject.py @@ -7,8 +7,8 @@ from collections import defaultdict import compas -from compas.artists.exceptions import DataArtistNotRegisteredError -from compas.artists.exceptions import NoArtistContextError +from compas.scene.exceptions import SceneObjectNotRegisteredError +from compas.scene.exceptions import NoSceneObjectContextError from compas.plugins import PluginValidator from compas.plugins import pluggable @@ -32,12 +32,12 @@ def redraw(): @pluggable(category="factories", selector="collect_all") -def register_artists(): - """Registers artists available in the current context.""" +def register_scene_objects(): + """Registers scene objects available in the current context.""" raise NotImplementedError -register_artists.__pluggable__ = True +register_scene_objects.__pluggable__ = True def is_viewer_open(): @@ -54,7 +54,7 @@ def is_viewer_open(): # if the instance exists, return True # in this case, the viewer is the current context # to do this without introducing compas_view2 as a dependency, - # creating the singleton instance should modify a class attribute of the Artist + # creating the singleton instance should modify a class attribute of the SceneObject # (or potentially a module level attribute of compas itself) return False @@ -63,13 +63,13 @@ def _detect_current_context(): """Chooses an appropriate context depending on available contexts and open instances. with the following priority: 1. Viewer 2. Plotter - 3. Rhino / GH - checked explicitly since Artists for both get registered when code is run from either. + 3. Rhino / GH - checked explicitly since SceneObjects for both get registered when code is run from either. 4. Other Returns ------- str - Name of an available context, used as key in :attr:`Artist.ITEM_ARTIST` + Name of an available context, used as key in :attr:`SceneObject.ITEM_SCENEOBJECT` """ if is_viewer_open(): @@ -80,23 +80,23 @@ def _detect_current_context(): return "Rhino" if compas.is_blender(): return "Blender" - other_contexts = [v for v in Artist.ITEM_ARTIST.keys()] + other_contexts = [v for v in SceneObject.ITEM_SCENEOBJECT.keys()] if other_contexts: return other_contexts[0] - raise NoArtistContextError() + raise NoSceneObjectContextError() -def _get_artist_cls(data, **kwargs): +def _get_sceneobject_cls(data, **kwargs): # in any case user gets to override the choice context_name = kwargs.get("context") or _detect_current_context() dtype = type(data) cls = None - if "artist_type" in kwargs: - cls = kwargs["artist_type"] + if "sceneobject_type" in kwargs: + cls = kwargs["sceneobject_type"] else: - context = Artist.ITEM_ARTIST[context_name] + context = SceneObject.ITEM_SCENEOBJECT[context_name] for type_ in inspect.getmro(dtype): cls = context.get(type_, None) @@ -104,79 +104,51 @@ def _get_artist_cls(data, **kwargs): break if cls is None: - raise DataArtistNotRegisteredError( - "No artist is registered for this data type: {} in this context: {}".format(dtype, context_name) + raise SceneObjectNotRegisteredError( + "No scene object is registered for this data type: {} in this context: {}".format(dtype, context_name) ) return cls -class Artist(object): - """Base class for all artists. +class SceneObject(object): + """Base class for all scene objects. Parameters ---------- item : Any - The item which should be visualized using the created Artist. + The item which should be visualized using the created SceneObject. context : str, optional - Explicit context to pick the Artist from. + Explicit context to pick the SceneObject from. If not specified, an attempt will be made to automatically detect the appropriate context. Attributes ---------- - ITEM_ARTIST : dict[str, dict[Type[:class:`compas.data.Data`], Type[:class:`compas.artists.Artist`]]] - Dictionary mapping data types to the corresponding artists types per visualization context. - - See Also - -------- - :class:`compas.artists.GeometryArtist` - :class:`compas.artists.MeshArtist` - :class:`compas.artists.NetworkArtist` - :class:`compas.artists.VolMeshArtist` - - Examples - -------- - >>> from compas.artists import Artist - >>> from compas.geometry import Point - >>> point = Point(1, 2, 3) - >>> artist = Artist(point) - >>> artist.draw() - - >>> from compas.artists import Artist - >>> from compas.geometry import Box - >>> box = Box(1) - >>> artist = Artist(box) - >>> artist.draw() - - >>> from compas.artists import Artist - >>> from compas.datastructures import Mesh - >>> mesh = Mesh.from_obj(compas.get('tubemesh.obj')) - >>> artist = Artist(mesh) - >>> artist.draw() - + ITEM_SCENEOBJECT : dict[str, dict[Type[:class:`~compas.data.Data`], Type[:class:`~compas.scene.SceneObject`]]] + Dictionary mapping data types to the corresponding scene objects types per visualization context. """ # add this to support the descriptor protocol vor Python versions below 3.6 __metaclass__ = DescriptorProtocol - __ARTISTS_REGISTERED = False + __SCENEOBJECTS_REGISTERED = False - ITEM_ARTIST = defaultdict(dict) + ITEM_SCENEOBJECT = defaultdict(dict) def __new__(cls, item, **kwargs): - if not Artist.__ARTISTS_REGISTERED: - cls.register_artists() - Artist.__ARTISTS_REGISTERED = True + if not SceneObject.__SCENEOBJECTS_REGISTERED: + cls.register_scene_objects() + SceneObject.__SCENEOBJECTS_REGISTERED = True if item is None: raise ValueError( - "Cannot create an artist for None. Please ensure you pass a instance of a supported class." + "Cannot create a scene object for None. Please ensure you pass a instance of a supported class." ) - cls = _get_artist_cls(item, **kwargs) + cls = _get_sceneobject_cls(item, **kwargs) PluginValidator.ensure_implementations(cls) - return super(Artist, cls).__new__(cls) + return super(SceneObject, cls).__new__(cls) def __init__(self, item, **kwargs): self._item = item @@ -184,7 +156,7 @@ def __init__(self, item, **kwargs): @property def transformation(self): - """The transformation matrix of the artist. + """The transformation matrix of the scene object. Returns ------- @@ -200,44 +172,44 @@ def transformation(self, transformation): @staticmethod def build(item, **kwargs): - """Build an artist corresponding to the item type. + """Build a scene object corresponding to the item type. Parameters ---------- **kwargs : dict[str, Any], optional The keyword arguments (kwargs) collected in a dict. - For relevant options, see the parameter lists of the matching artist type. + For relevant options, see the parameter lists of the matching scene object type. Returns ------- - :class:`compas.artists.Artist` - An artist of the type matching the provided item according to the item-artist map :attr:`~Artist.ITEM_ARTIST`. - The map is created by registering item-artist type pairs using :meth:`~Artist.register`. + :class:`~compas.scene.SceneObject` + A scene object of the type matching the provided item according to the item-sceneobject map :attr:`~SceneObject.ITEM_SCENEOBJECT`. + The map is created by registering item-sceneobject type pairs using :meth:`~SceneObject.register`. """ - artist_type = _get_artist_cls(item, **kwargs) - artist = artist_type(item, **kwargs) - return artist + sceneobject_type = _get_sceneobject_cls(item, **kwargs) + sceneobject = sceneobject_type(item, **kwargs) + return sceneobject @staticmethod - def build_as(item, artist_type, **kwargs): - """Build an artist with the given type. + def build_as(item, sceneobject_type, **kwargs): + """Build a scene object with the given type. Parameters ---------- - artist_type : :class:`compas.artists.Artist` + sceneobject_type : :class:`~compas.scene.SceneObject` **kwargs : dict[str, Any], optional The keyword arguments (kwargs) collected in a dict. - For relevant options, see the parameter lists of the matching artist type. + For relevant options, see the parameter lists of the matching sceneobject type. Returns ------- - :class:`compas.artists.Artist` - An artist of the given type. + :class:`~compas.scene.SceneObject` + A scene object of the given type. """ - artist = artist_type(item, **kwargs) - return artist + sceneobject = sceneobject_type(item, **kwargs) + return sceneobject @staticmethod def clear(): @@ -262,27 +234,27 @@ def redraw(): return redraw() @staticmethod - def register_artists(): - """Register Artists using available plugins. + def register_scene_objects(): + """Register SceneObjects using available plugins. Returns ------- List[str] - List containing names of discovered Artist plugins. + List containing names of discovered SceneObject plugins. """ - return register_artists() + return register_scene_objects() @staticmethod - def register(item_type, artist_type, context=None): - """Register an artist type to a data type. + def register(item_type, sceneobject_type, context=None): + """Register a scene object type to a data type. Parameters ---------- - item_type : :class:`compas.data.Data` + item_type : :class:`~compas.data.Data` The type of data item. - artist_type : :class:`compas.artists.Artist` - The type of the corresponding/compatible artist. + sceneobject_type : :class:`~compas.scene.SceneObject` + The type of the corresponding/compatible scene object. context : Literal['Viewer', 'Rhino', 'Grasshopper', 'Blender'], optional The visualization context in which the pair should be registered. @@ -291,7 +263,7 @@ def register(item_type, artist_type, context=None): None """ - Artist.ITEM_ARTIST[context][item_type] = artist_type + SceneObject.ITEM_SCENEOBJECT[context][item_type] = sceneobject_type @abstractmethod def draw(self): diff --git a/src/compas/artists/volmeshartist.py b/src/compas/scene/volmeshobject.py similarity index 95% rename from src/compas/artists/volmeshartist.py rename to src/compas/scene/volmeshobject.py index 9762e04ad7d..82f4114c866 100644 --- a/src/compas/artists/volmeshartist.py +++ b/src/compas/scene/volmeshobject.py @@ -6,13 +6,13 @@ from compas.colors import Color from compas.geometry import transform_points -from .artist import Artist +from .sceneobject import SceneObject from .descriptors.color import ColorAttribute from .descriptors.colordict import ColorDictAttribute -class VolMeshArtist(Artist): - """Artist for drawing volmesh data structures. +class VolMeshObject(SceneObject): + """Scene object for drawing volmesh data structures. Parameters ---------- @@ -22,7 +22,7 @@ class VolMeshArtist(Artist): Attributes ---------- volmesh : :class:`compas.datastructures.VolMesh` - The COMPAS volmesh associated with the artist. + The COMPAS volmesh associated with the scene object. vertex_xyz : dict[int, list[float]] The view coordinates of the vertices. By default, the actual vertex coordinates are used. @@ -41,8 +41,8 @@ class VolMeshArtist(Artist): See Also -------- - :class:`compas.artists.NetworkArtist` - :class:`compas.artists.MeshArtist` + :class:`compas.scene.NetworkObject` + :class:`compas.scene.MeshObject` """ @@ -54,7 +54,7 @@ class VolMeshArtist(Artist): cell_color = ColorDictAttribute(default=Color.grey()) def __init__(self, volmesh, **kwargs): - super(VolMeshArtist, self).__init__(item=volmesh, **kwargs) + super(VolMeshObject, self).__init__(item=volmesh, **kwargs) self._volmesh = None self._vertex_xyz = None self.volmesh = volmesh diff --git a/src/compas_blender/__init__.py b/src/compas_blender/__init__.py index c427ee0159d..6a6e8dd71ea 100644 --- a/src/compas_blender/__init__.py +++ b/src/compas_blender/__init__.py @@ -78,5 +78,5 @@ def _get_default_blender_installation_path_windows(version): __all_plugins__ = [ "compas_blender.geometry.booleans", - "compas_blender.artists", + "compas_blender.scene", ] diff --git a/src/compas_blender/artists/__init__.py b/src/compas_blender/artists/__init__.py deleted file mode 100644 index 9d511cea9e9..00000000000 --- a/src/compas_blender/artists/__init__.py +++ /dev/null @@ -1,112 +0,0 @@ -""" -This package provides artist plugins for visualising COMPAS objects in Blender. -When working in Blender, :class:`compas.artists.Artist` will automatically use the corresponding Blender artist for each COMPAS object type. -""" - -import compas_blender - -from compas.plugins import plugin -from compas.artists import Artist - -from compas.geometry import Box -from compas.geometry import Capsule -from compas.geometry import Circle -from compas.geometry import Cone -from compas.geometry import Curve -from compas.geometry import Cylinder -from compas.geometry import Frame -from compas.geometry import Line -from compas.geometry import Point -from compas.geometry import Pointcloud -from compas.geometry import Polygon -from compas.geometry import Polyhedron -from compas.geometry import Polyline -from compas.geometry import Sphere -from compas.geometry import Surface -from compas.geometry import Torus -from compas.geometry import Vector -from compas.datastructures import Mesh -from compas.datastructures import Network -from compas.datastructures import VolMesh - -from .artist import BlenderArtist -from .boxartist import BoxArtist -from .capsuleartist import CapsuleArtist -from .circleartist import CircleArtist -from .coneartist import ConeArtist -from .curveartist import CurveArtist -from .cylinderartist import CylinderArtist -from .frameartist import FrameArtist -from .lineartist import LineArtist -from .meshartist import MeshArtist -from .networkartist import NetworkArtist -from .pointartist import PointArtist -from .pointcloudartist import PointcloudArtist -from .polygonartist import PolygonArtist -from .polyhedronartist import PolyhedronArtist -from .polylineartist import PolylineArtist -from .sphereartist import SphereArtist -from .surfaceartist import SurfaceArtist -from .torusartist import TorusArtist -from .vectorartist import VectorArtist -from .volmeshartist import VolMeshArtist - - -@plugin(category="drawing-utils", pluggable_name="clear", requires=["bpy"]) -def clear_blender(): - compas_blender.clear() - - -@plugin(category="drawing-utils", pluggable_name="redraw", requires=["bpy"]) -def redraw_blender(): - compas_blender.redraw() - - -@plugin(category="factories", requires=["bpy"]) -def register_artists(): - Artist.register(Box, BoxArtist, context="Blender") - Artist.register(Capsule, CapsuleArtist, context="Blender") - Artist.register(Circle, CircleArtist, context="Blender") - Artist.register(Cone, ConeArtist, context="Blender") - Artist.register(Curve, CurveArtist, context="Blender") - Artist.register(Cylinder, CylinderArtist, context="Blender") - Artist.register(Frame, FrameArtist, context="Blender") - Artist.register(Line, LineArtist, context="Blender") - Artist.register(Mesh, MeshArtist, context="Blender") - Artist.register(Network, NetworkArtist, context="Blender") - Artist.register(Point, PointArtist, context="Blender") - Artist.register(Pointcloud, PointcloudArtist, context="Blender") - Artist.register(Polygon, PolygonArtist, context="Blender") - Artist.register(Polyhedron, PolyhedronArtist, context="Blender") - Artist.register(Polyline, PolylineArtist, context="Blender") - Artist.register(Sphere, SphereArtist, context="Blender") - Artist.register(Surface, SurfaceArtist, context="Blender") - Artist.register(Torus, TorusArtist, context="Blender") - Artist.register(Vector, VectorArtist, context="Blender") - Artist.register(VolMesh, VolMeshArtist, context="Blender") - print("Blender Artists registered.") - - -__all__ = [ - "BlenderArtist", - "BoxArtist", - "CapsuleArtist", - "CircleArtist", - "ConeArtist", - "CurveArtist", - "CylinderArtist", - "FrameArtist", - "LineArtist", - "MeshArtist", - "NetworkArtist", - "PointArtist", - "PointcloudArtist", - "PolygonArtist", - "PolyhedronArtist", - "PolylineArtist", - "SphereArtist", - "SurfaceArtist", - "TorusArtist", - "VectorArtist", - "VolMeshArtist", -] diff --git a/src/compas_blender/scene/__init__.py b/src/compas_blender/scene/__init__.py new file mode 100644 index 00000000000..9e59b81cedf --- /dev/null +++ b/src/compas_blender/scene/__init__.py @@ -0,0 +1,112 @@ +""" +This package provides scene object plugins for visualising COMPAS objects in Blender. +When working in Blender, :class:`compas.scene.SceneObject` will automatically use the corresponding Blender object for each COMPAS object type. +""" + +import compas_blender + +from compas.plugins import plugin +from compas.scene import SceneObject + +from compas.geometry import Box +from compas.geometry import Capsule +from compas.geometry import Circle +from compas.geometry import Cone +from compas.geometry import Curve +from compas.geometry import Cylinder +from compas.geometry import Frame +from compas.geometry import Line +from compas.geometry import Point +from compas.geometry import Pointcloud +from compas.geometry import Polygon +from compas.geometry import Polyhedron +from compas.geometry import Polyline +from compas.geometry import Sphere +from compas.geometry import Surface +from compas.geometry import Torus +from compas.geometry import Vector +from compas.datastructures import Mesh +from compas.datastructures import Network +from compas.datastructures import VolMesh + +from .sceneobject import BlenderSceneObject +from .boxobject import BoxObject +from .capsuleobject import CapsuleObject +from .circleobject import CircleObject +from .coneobject import ConeObject +from .curveobject import CurveObject +from .cylinderobject import CylinderObject +from .frameobject import FrameObject +from .lineobject import LineObject +from .meshobject import MeshObject +from .networkobject import NetworkObject +from .pointobject import PointObject +from .pointcloudobject import PointcloudObject +from .polygonobject import PolygonObject +from .polyhedronobject import PolyhedronObject +from .polylineobject import PolylineObject +from .sphereobject import SphereObject +from .surfaceobject import SurfaceObject +from .torusobject import TorusObject +from .vectorobject import VectorObject +from .volmeshobject import VolMeshObject + + +@plugin(category="drawing-utils", pluggable_name="clear", requires=["bpy"]) +def clear_blender(): + compas_blender.clear() + + +@plugin(category="drawing-utils", pluggable_name="redraw", requires=["bpy"]) +def redraw_blender(): + compas_blender.redraw() + + +@plugin(category="factories", requires=["bpy"]) +def register_scene_objects(): + SceneObject.register(Box, BoxObject, context="Blender") + SceneObject.register(Capsule, CapsuleObject, context="Blender") + SceneObject.register(Circle, CircleObject, context="Blender") + SceneObject.register(Cone, ConeObject, context="Blender") + SceneObject.register(Curve, CurveObject, context="Blender") + SceneObject.register(Cylinder, CylinderObject, context="Blender") + SceneObject.register(Frame, FrameObject, context="Blender") + SceneObject.register(Line, LineObject, context="Blender") + SceneObject.register(Mesh, MeshObject, context="Blender") + SceneObject.register(Network, NetworkObject, context="Blender") + SceneObject.register(Point, PointObject, context="Blender") + SceneObject.register(Pointcloud, PointcloudObject, context="Blender") + SceneObject.register(Polygon, PolygonObject, context="Blender") + SceneObject.register(Polyhedron, PolyhedronObject, context="Blender") + SceneObject.register(Polyline, PolylineObject, context="Blender") + SceneObject.register(Sphere, SphereObject, context="Blender") + SceneObject.register(Surface, SurfaceObject, context="Blender") + SceneObject.register(Torus, TorusObject, context="Blender") + SceneObject.register(Vector, VectorObject, context="Blender") + SceneObject.register(VolMesh, VolMeshObject, context="Blender") + print("Blender Objects registered.") + + +__all__ = [ + "BlenderSceneObject", + "BoxObject", + "CapsuleObject", + "CircleObject", + "ConeObject", + "CurveObject", + "CylinderObject", + "FrameObject", + "LineObject", + "MeshObject", + "NetworkObject", + "PointObject", + "PointcloudObject", + "PolygonObject", + "PolyhedronObject", + "PolylineObject", + "SphereObject", + "SurfaceObject", + "TorusObject", + "VectorObject", + "VolMeshObject", +] diff --git a/src/compas_blender/artists/boxartist.py b/src/compas_blender/scene/boxobject.py similarity index 87% rename from src/compas_blender/artists/boxartist.py rename to src/compas_blender/scene/boxobject.py index 495d7409fb8..1ca0fe23897 100644 --- a/src/compas_blender/artists/boxartist.py +++ b/src/compas_blender/scene/boxobject.py @@ -9,12 +9,12 @@ from compas_blender import conversions -from compas.artists import GeometryArtist -from .artist import BlenderArtist +from compas.scene import GeometryObject +from .sceneobject import BlenderSceneObject -class BoxArtist(BlenderArtist, GeometryArtist): - """Artist for drawing box shapes in Blender. +class BoxObject(BlenderSceneObject, GeometryObject): + """Scene object for drawing box shapes in Blender. Parameters ---------- @@ -34,7 +34,7 @@ def draw( collection: Optional[Union[str, bpy.types.Collection]] = None, show_wire: bool = True, ) -> bpy.types.Object: - """Draw the box associated with the artist. + """Draw the box associated with the scene object. Parameters ---------- diff --git a/src/compas_blender/artists/capsuleartist.py b/src/compas_blender/scene/capsuleobject.py similarity index 87% rename from src/compas_blender/artists/capsuleartist.py rename to src/compas_blender/scene/capsuleobject.py index 2b24e1903c7..48bfc5f0425 100644 --- a/src/compas_blender/artists/capsuleartist.py +++ b/src/compas_blender/scene/capsuleobject.py @@ -8,12 +8,12 @@ from compas_blender import conversions -from compas.artists import GeometryArtist -from .artist import BlenderArtist +from compas.scene import GeometryObject +from .sceneobject import BlenderSceneObject -class CapsuleArtist(BlenderArtist, GeometryArtist): - """Artist for drawing capsule shapes in Blender. +class CapsuleObject(BlenderSceneObject, GeometryObject): + """Scene object for drawing capsule shapes in Blender. Parameters ---------- @@ -36,7 +36,7 @@ def draw( show_wire: bool = False, shade_smooth: bool = True, ) -> bpy.types.Object: - """Draw the capsule associated with the artist. + """Draw the capsule associated with the scene object. Parameters ---------- @@ -65,6 +65,7 @@ def draw( vertices, faces = self.geometry.to_vertices_and_faces(u=u, v=v) mesh = conversions.vertices_and_faces_to_blender_mesh(vertices, faces, name=self.geometry.name) if shade_smooth: + print(dir(mesh)) mesh.shade_smooth() obj = self.create_object(mesh, name=name) diff --git a/src/compas_blender/artists/circleartist.py b/src/compas_blender/scene/circleobject.py similarity index 87% rename from src/compas_blender/artists/circleartist.py rename to src/compas_blender/scene/circleobject.py index fecc9d0370e..e363876a141 100644 --- a/src/compas_blender/artists/circleartist.py +++ b/src/compas_blender/scene/circleobject.py @@ -6,12 +6,12 @@ from compas.geometry import Circle from compas.colors import Color -from compas.artists import GeometryArtist -from .artist import BlenderArtist +from compas.scene import GeometryObject +from .sceneobject import BlenderSceneObject -class CircleArtist(BlenderArtist, GeometryArtist): - """Artist for drawing circles in Blender. +class CircleObject(BlenderSceneObject, GeometryObject): + """Scene object for drawing circles in Blender. Parameters ---------- diff --git a/src/compas_blender/artists/coneartist.py b/src/compas_blender/scene/coneobject.py similarity index 87% rename from src/compas_blender/artists/coneartist.py rename to src/compas_blender/scene/coneobject.py index 99f60abb034..ef290df7b76 100644 --- a/src/compas_blender/artists/coneartist.py +++ b/src/compas_blender/scene/coneobject.py @@ -8,12 +8,12 @@ from compas_blender import conversions -from compas.artists import GeometryArtist -from .artist import BlenderArtist +from compas.scene import GeometryObject +from .sceneobject import BlenderSceneObject -class ConeArtist(BlenderArtist, GeometryArtist): - """Artist for drawing cone shapes in Blender. +class ConeObject(BlenderSceneObject, GeometryObject): + """Scene object for drawing cone shapes in Blender. Parameters ---------- @@ -35,7 +35,7 @@ def draw( show_wire: bool = False, shade_smooth: bool = True, ) -> bpy.types.Object: - """Draw the cone associated with the artist. + """Draw the cone associated with the scene object. Parameters ---------- diff --git a/src/compas_blender/artists/curveartist.py b/src/compas_blender/scene/curveobject.py similarity index 87% rename from src/compas_blender/artists/curveartist.py rename to src/compas_blender/scene/curveobject.py index 446ef95671d..5af65965546 100644 --- a/src/compas_blender/artists/curveartist.py +++ b/src/compas_blender/scene/curveobject.py @@ -7,12 +7,12 @@ from compas.colors import Color from compas_blender import conversions -from compas.artists import GeometryArtist -from .artist import BlenderArtist +from compas.scene import GeometryObject +from .sceneobject import BlenderSceneObject -class CurveArtist(BlenderArtist, GeometryArtist): - """Artist for drawing curves in Blender. +class CurveObject(BlenderSceneObject, GeometryObject): + """Scene object for drawing curves in Blender. Parameters ---------- diff --git a/src/compas_blender/artists/cylinderartist.py b/src/compas_blender/scene/cylinderobject.py similarity index 87% rename from src/compas_blender/artists/cylinderartist.py rename to src/compas_blender/scene/cylinderobject.py index 22089c20952..2ebe33bf1df 100644 --- a/src/compas_blender/artists/cylinderartist.py +++ b/src/compas_blender/scene/cylinderobject.py @@ -8,12 +8,12 @@ from compas_blender import conversions -from compas.artists import GeometryArtist -from .artist import BlenderArtist +from compas.scene import GeometryObject +from .sceneobject import BlenderSceneObject -class CylinderArtist(BlenderArtist, GeometryArtist): - """Artist for drawing cylinder shapes in Blender. +class CylinderObject(BlenderSceneObject, GeometryObject): + """Scene object for drawing cylinder shapes in Blender. Parameters ---------- @@ -35,7 +35,7 @@ def draw( show_wire: bool = False, shade_smooth: bool = True, ) -> bpy.types.Object: - """Draw the cylinder associated with the artist. + """Draw the cylinder associated with the scene object. Parameters ---------- diff --git a/src/compas_blender/artists/frameartist.py b/src/compas_blender/scene/frameobject.py similarity index 90% rename from src/compas_blender/artists/frameartist.py rename to src/compas_blender/scene/frameobject.py index c29641b2492..3cc4d802848 100644 --- a/src/compas_blender/artists/frameartist.py +++ b/src/compas_blender/scene/frameobject.py @@ -7,12 +7,12 @@ from compas.geometry import Frame from compas.colors import Color -from compas.artists import GeometryArtist -from .artist import BlenderArtist +from compas.scene import GeometryObject +from .sceneobject import BlenderSceneObject -class FrameArtist(BlenderArtist, GeometryArtist): - """Artist for drawing frames in Blender. +class FrameObject(BlenderSceneObject, GeometryObject): + """Scene object for drawing frames in Blender. Parameters ---------- @@ -21,7 +21,7 @@ class FrameArtist(BlenderArtist, GeometryArtist): **kwargs : dict, optional Additional keyword arguments. For more info, - see :class:`compas_blender.artists.BlenderArtist` and :class:`compas.artists.GeometryArtist`. + see :class:`compas_blender.scene.BlenderSceneObject` and :class:`compas.scene.GeometryObject`. Attributes ---------- diff --git a/src/compas_blender/artists/lineartist.py b/src/compas_blender/scene/lineobject.py similarity index 82% rename from src/compas_blender/artists/lineartist.py rename to src/compas_blender/scene/lineobject.py index cc12603e5ba..c2428dea93f 100644 --- a/src/compas_blender/artists/lineartist.py +++ b/src/compas_blender/scene/lineobject.py @@ -9,12 +9,12 @@ from compas_blender import conversions -from compas.artists import GeometryArtist -from compas_blender.artists import BlenderArtist +from compas.scene import GeometryObject +from .sceneobject import BlenderSceneObject -class LineArtist(BlenderArtist, GeometryArtist): - """Artist for drawing lines in Blender. +class LineObject(BlenderSceneObject, GeometryObject): + """Scene object for drawing lines in Blender. Parameters ---------- @@ -23,7 +23,7 @@ class LineArtist(BlenderArtist, GeometryArtist): **kwargs : dict, optional Additional keyword arguments. For more info, - see :class:`compas_blender.artists.BlenderArtist` and :class:`compas.artists.GeometryArtist`. + see :class:`compas_blender.scene.BlenderSceneObject` and :class:`compas.scene.GeometryObject`. """ diff --git a/src/compas_blender/artists/meshartist.py b/src/compas_blender/scene/meshobject.py similarity index 98% rename from src/compas_blender/artists/meshartist.py rename to src/compas_blender/scene/meshobject.py index 1d96c57d0c5..84e5b8c93f0 100644 --- a/src/compas_blender/artists/meshartist.py +++ b/src/compas_blender/scene/meshobject.py @@ -17,14 +17,14 @@ from compas.geometry import scale_vector from compas.colors import Color -from compas.artists import MeshArtist as BaseArtist -from .artist import BlenderArtist +from compas.scene import MeshObject as BaseMeshObject +from .sceneobject import BlenderSceneObject from compas_blender import conversions -class MeshArtist(BlenderArtist, BaseArtist): - """Artist for drawing mesh data structures in Blender. +class MeshObject(BlenderSceneObject, BaseMeshObject): + """Scene object for drawing mesh data structures in Blender. Parameters ---------- diff --git a/src/compas_blender/artists/networkartist.py b/src/compas_blender/scene/networkobject.py similarity index 92% rename from src/compas_blender/artists/networkartist.py rename to src/compas_blender/scene/networkobject.py index fa48ef321a9..47d705a10f2 100644 --- a/src/compas_blender/artists/networkartist.py +++ b/src/compas_blender/scene/networkobject.py @@ -12,14 +12,14 @@ from compas.colors import Color from compas.geometry import Line -from compas.artists import NetworkArtist as BaseArtist -from .artist import BlenderArtist +from compas.scene import NetworkObject as BaseSceneObject +from .sceneobject import BlenderSceneObject from compas_blender import conversions -class NetworkArtist(BlenderArtist, BaseArtist): - """Artist for drawing network data structures in Blender. +class NetworkObject(BlenderSceneObject, BaseSceneObject): + """Scene object for drawing network data structures in Blender. Parameters ---------- @@ -145,7 +145,7 @@ def draw_nodes( for node in nodes or self.network.nodes(): # type: ignore name = f"{self.network.name}.node.{node}" # type: ignore color = self.node_color[node] # type: ignore - point = self.node_xyz[node] # type: ignore + point = self.network.nodes_attributes("xyz")[node] # type: ignore # there is no such thing as a sphere data block bpy.ops.mesh.primitive_uv_sphere_add(location=point, radius=radius, segments=u, ring_count=v) @@ -186,7 +186,9 @@ def draw_edges( for u, v in edges or self.network.edges(): # type: ignore name = f"{self.network.name}.edge.{u}-{v}" # type: ignore color = self.edge_color[u, v] # type: ignore - curve = conversions.line_to_blender_curve(Line(self.node_xyz[u], self.node_xyz[v])) + curve = conversions.line_to_blender_curve( + Line(self.network.nodes_attributes("xyz")[u], self.network.nodes_attributes("xyz")[v]) + ) obj = self.create_object(curve, name=name) self.update_object(obj, color=color, collection=collection) @@ -217,7 +219,7 @@ def draw_edges( # for node in self.node_text: # labels.append( # { - # "pos": self.node_xyz[node], + # "pos": self.network.nodes_attributes("xyz")[node], # "name": f"{self.network.name}.nodelabel.{node}", # "text": self.node_text[node], # "color": self.node_color[node], @@ -245,7 +247,7 @@ def draw_edges( # u, v = edge # labels.append( # { - # "pos": centroid_points([self.node_xyz[u], self.node_xyz[v]]), + # "pos": centroid_points([self.network.nodes_attributes("xyz")[u], self.network.nodes_attributes("xyz")[v]]), # "name": f"{self.network.name}.edgelabel.{u}-{v}", # "text": self.edge_text[edge], # "color": self.edge_color[edge], diff --git a/src/compas_blender/artists/pointcloudartist.py b/src/compas_blender/scene/pointcloudobject.py similarity index 89% rename from src/compas_blender/artists/pointcloudartist.py rename to src/compas_blender/scene/pointcloudobject.py index de7f497ee8f..f5d98daa31a 100644 --- a/src/compas_blender/artists/pointcloudartist.py +++ b/src/compas_blender/scene/pointcloudobject.py @@ -6,14 +6,14 @@ from compas.geometry import Point from compas.colors import Color -from compas.artists import GeometryArtist -from .artist import BlenderArtist +from compas.scene import GeometryObject +from .sceneobject import BlenderSceneObject from compas_blender import conversions -class PointcloudArtist(BlenderArtist, GeometryArtist): - """Artist for drawing pointclouds in Blender. +class PointcloudObject(BlenderSceneObject, GeometryObject): + """Scene object for drawing pointclouds in Blender. Parameters ---------- diff --git a/src/compas_blender/artists/pointartist.py b/src/compas_blender/scene/pointobject.py similarity index 89% rename from src/compas_blender/artists/pointartist.py rename to src/compas_blender/scene/pointobject.py index 19889f4b84b..641d204355d 100644 --- a/src/compas_blender/artists/pointartist.py +++ b/src/compas_blender/scene/pointobject.py @@ -6,12 +6,12 @@ from compas.geometry import Point from compas.colors import Color -from compas.artists import GeometryArtist -from .artist import BlenderArtist +from compas.scene import GeometryObject +from .sceneobject import BlenderSceneObject -class PointArtist(BlenderArtist, GeometryArtist): - """Artist for drawing points in Blender. +class PointObject(BlenderSceneObject, GeometryObject): + """Scene object for drawing points in Blender. Parameters ---------- diff --git a/src/compas_blender/artists/polygonartist.py b/src/compas_blender/scene/polygonobject.py similarity index 88% rename from src/compas_blender/artists/polygonartist.py rename to src/compas_blender/scene/polygonobject.py index 44f6f184b9a..54a93e600fb 100644 --- a/src/compas_blender/artists/polygonartist.py +++ b/src/compas_blender/scene/polygonobject.py @@ -9,12 +9,12 @@ from compas_blender import conversions -from compas.artists import GeometryArtist -from .artist import BlenderArtist +from compas.scene import GeometryObject +from .sceneobject import BlenderSceneObject -class PolygonArtist(BlenderArtist, GeometryArtist): - """Artist for drawing polygons in Blender. +class PolygonObject(BlenderSceneObject, GeometryObject): + """Scene object for drawing polygons in Blender. Parameters ---------- diff --git a/src/compas_blender/artists/polyhedronartist.py b/src/compas_blender/scene/polyhedronobject.py similarity index 85% rename from src/compas_blender/artists/polyhedronartist.py rename to src/compas_blender/scene/polyhedronobject.py index 3cba884f2c6..303c4da34b1 100644 --- a/src/compas_blender/artists/polyhedronartist.py +++ b/src/compas_blender/scene/polyhedronobject.py @@ -6,14 +6,14 @@ from compas.geometry import Polyhedron from compas.colors import Color -from compas.artists import GeometryArtist -from .artist import BlenderArtist +from compas.scene import GeometryObject +from .sceneobject import BlenderSceneObject from compas_blender import conversions -class PolyhedronArtist(BlenderArtist, GeometryArtist): - """Artist for drawing polyhedron shapes in Blender. +class PolyhedronObject(BlenderSceneObject, GeometryObject): + """Scene object for drawing polyhedron shapes in Blender. Parameters ---------- @@ -30,7 +30,7 @@ def __init__(self, polyhedron: Polyhedron, **kwargs: Any): def draw( self, color: Optional[Color] = None, collection: Optional[str] = None, show_wire: bool = True ) -> List[bpy.types.Object]: - """Draw the polyhedron associated with the artist. + """Draw the polyhedron associated with the scene object. Parameters ---------- diff --git a/src/compas_blender/artists/polylineartist.py b/src/compas_blender/scene/polylineobject.py similarity index 87% rename from src/compas_blender/artists/polylineartist.py rename to src/compas_blender/scene/polylineobject.py index 3daedb95e33..0366904173e 100644 --- a/src/compas_blender/artists/polylineartist.py +++ b/src/compas_blender/scene/polylineobject.py @@ -6,14 +6,14 @@ from compas.geometry import Polyline from compas.colors import Color -from compas.artists import GeometryArtist -from .artist import BlenderArtist +from compas.scene import GeometryObject +from .sceneobject import BlenderSceneObject from compas_blender import conversions -class PolylineArtist(BlenderArtist, GeometryArtist): - """Artist for drawing polylines in Blender. +class PolylineObject(BlenderSceneObject, GeometryObject): + """Scene object for drawing polylines in Blender. Parameters ---------- diff --git a/src/compas_blender/artists/artist.py b/src/compas_blender/scene/sceneobject.py similarity index 97% rename from src/compas_blender/artists/artist.py rename to src/compas_blender/scene/sceneobject.py index 917abe2bfda..1307eafafa3 100644 --- a/src/compas_blender/artists/artist.py +++ b/src/compas_blender/scene/sceneobject.py @@ -6,26 +6,26 @@ import compas_blender from compas.colors import Color -from compas.artists import Artist +from compas.scene import SceneObject from compas.geometry import Transformation from compas_blender import conversions -class BlenderArtist(Artist): - """Base class for all Blender artists. +class BlenderSceneObject(SceneObject): + """Base class for all Blender scene objects. Parameters ---------- collection : str | :blender:`bpy.types.Collection`, optional - The Blender scene collection the object(s) created by the artist belong to. + The Blender scene collection the object(s) created by the scene object belong to. **kwargs : dict, optional Additional keyword arguments. Attributes ---------- objects : list[:blender:`bpy.types.Object`] - The Blender objects created by the artist. + The Blender objects created by the scene object. """ diff --git a/src/compas_blender/artists/sphereartist.py b/src/compas_blender/scene/sphereobject.py similarity index 88% rename from src/compas_blender/artists/sphereartist.py rename to src/compas_blender/scene/sphereobject.py index bb0e5863420..c35bc5968f9 100644 --- a/src/compas_blender/artists/sphereartist.py +++ b/src/compas_blender/scene/sphereobject.py @@ -7,14 +7,14 @@ from compas.geometry import Sphere from compas.colors import Color -from compas.artists import GeometryArtist -from .artist import BlenderArtist +from compas.scene import GeometryObject +from .sceneobject import BlenderSceneObject from compas_blender import conversions -class SphereArtist(BlenderArtist, GeometryArtist): - """Artist for drawing sphere shapes in Blender. +class SphereObject(BlenderSceneObject, GeometryObject): + """Scene object for drawing sphere shapes in Blender. Parameters ---------- @@ -37,7 +37,7 @@ def draw( show_wire: bool = False, shade_smooth: bool = True, ) -> List[bpy.types.Object]: - """Draw the sphere associated with the artist. + """Draw the sphere associated with the scene object. Parameters ---------- diff --git a/src/compas_blender/artists/surfaceartist.py b/src/compas_blender/scene/surfaceobject.py similarity index 87% rename from src/compas_blender/artists/surfaceartist.py rename to src/compas_blender/scene/surfaceobject.py index f81ac7d8e8e..6562ecd095b 100644 --- a/src/compas_blender/artists/surfaceartist.py +++ b/src/compas_blender/scene/surfaceobject.py @@ -6,14 +6,14 @@ from compas.geometry import Surface from compas.colors import Color -from compas.artists import GeometryArtist -from compas_blender.artists import BlenderArtist +from compas.scene import GeometryObject +from .sceneobject import BlenderSceneObject from compas_blender import conversions -class SurfaceArtist(BlenderArtist, GeometryArtist): - """Artist for drawing surfaces in Blender. +class SurfaceObject(BlenderSceneObject, GeometryObject): + """Scene object for drawing surfaces in Blender. Parameters ---------- diff --git a/src/compas_blender/artists/torusartist.py b/src/compas_blender/scene/torusobject.py similarity index 88% rename from src/compas_blender/artists/torusartist.py rename to src/compas_blender/scene/torusobject.py index ca883c3b659..808f2fdabce 100644 --- a/src/compas_blender/artists/torusartist.py +++ b/src/compas_blender/scene/torusobject.py @@ -6,14 +6,14 @@ from compas.geometry import Torus from compas.colors import Color -from compas.artists import GeometryArtist -from .artist import BlenderArtist +from compas.scene import GeometryObject +from .sceneobject import BlenderSceneObject from compas_blender import conversions -class TorusArtist(BlenderArtist, GeometryArtist): - """Artist for drawing torus shapes in Blender. +class TorusObject(BlenderSceneObject, GeometryObject): + """Scene object for drawing torus shapes in Blender. Parameters ---------- @@ -36,7 +36,7 @@ def draw( show_wire: bool = False, shade_smooth: bool = True, ) -> bpy.types.Object: - """Draw the torus associated with the artist. + """Draw the torus associated with the scene object. Parameters ---------- diff --git a/src/compas_blender/artists/vectorartist.py b/src/compas_blender/scene/vectorobject.py similarity index 90% rename from src/compas_blender/artists/vectorartist.py rename to src/compas_blender/scene/vectorobject.py index 201f08ad9c6..99a66f7a8bf 100644 --- a/src/compas_blender/artists/vectorartist.py +++ b/src/compas_blender/scene/vectorobject.py @@ -8,14 +8,14 @@ from compas.geometry import Line from compas.colors import Color -from compas.artists import GeometryArtist -from .artist import BlenderArtist +from compas.scene import GeometryObject +from .sceneobject import BlenderSceneObject from compas_blender import conversions -class VectorArtist(BlenderArtist, GeometryArtist): - """Artist for drawing vectors in Blender. +class VectorObject(BlenderSceneObject, GeometryObject): + """Scene object for drawing vectors in Blender. Parameters ---------- diff --git a/src/compas_blender/artists/volmeshartist.py b/src/compas_blender/scene/volmeshobject.py similarity index 92% rename from src/compas_blender/artists/volmeshartist.py rename to src/compas_blender/scene/volmeshobject.py index 4b3f1b18861..f0eff14c54f 100644 --- a/src/compas_blender/artists/volmeshartist.py +++ b/src/compas_blender/scene/volmeshobject.py @@ -15,14 +15,14 @@ from compas.geometry import Line from compas.colors import Color -from compas.artists import VolMeshArtist as BaseArtist -from .artist import BlenderArtist +from compas.scene import VolMeshObject as BaseVolMeshObject +from .sceneobject import BlenderSceneObject from compas_blender import conversions -class VolMeshArtist(BlenderArtist, BaseArtist): - """An artist for drawing volumetric mesh data structures in Blender. +class VolMeshObject(BlenderSceneObject, BaseVolMeshObject): + """A scene object for drawing volumetric mesh data structures in Blender. Parameters ---------- @@ -103,7 +103,7 @@ def draw( The default is None, in which case all cells are drawn. color : :class:`compas.colors.Color` | dict[int, :class:`compas.colors.Color`], optional The color of the cells. - The default color is :attr:`VolMeshArtist.default_cellcolor`. + The default color is :attr:`VolMeshObject.default_cellcolor`. collection : str, optional The name of the Blender scene collection containing the created object(s). @@ -153,7 +153,7 @@ def draw_vertices( for vertex in vertices or self.volmesh.vertices(): # type: ignore name = f"{self.volmesh.name}.vertex.{vertex}" # type: ignore color = self.vertex_color[vertex] # type: ignore - point = self.vertex_xyz[vertex] + point = self.volmesh.vertices_attributes("xyz")[vertex] # there is no such thing as a sphere data block bpy.ops.mesh.primitive_uv_sphere_add(location=point, radius=radius, segments=u, ring_count=v) @@ -194,7 +194,9 @@ def draw_edges( for u, v in edges or self.volmesh.edges(): # type: ignore name = f"{self.volmesh.name}.edge.{u}-{v}" # type: ignore color = self.edge_color[u, v] # type: ignore - curve = conversions.line_to_blender_curve(Line(self.vertex_xyz[u], self.vertex_xyz[v])) + curve = conversions.line_to_blender_curve( + Line(self.volmesh.vertices_attributes("xyz")[u], self.volmesh.vertices_attributes("xyz")[v]) + ) obj = self.create_object(curve, name=name) self.update_object(obj, color=color, collection=collection) # type: ignore @@ -235,7 +237,7 @@ def draw_faces( for face in faces or self.volmesh.faces(): # type: ignore name = f"{self.volmesh.name}.face.{face}" # type: ignore color = self.face_color[face] # type: ignore - points = [self.vertex_xyz[vertex] for vertex in self.volmesh.face_vertices(face)] # type: ignore + points = [self.volmesh.vertices_attributes("xyz")[vertex] for vertex in self.volmesh.face_vertices(face)] # type: ignore mesh = conversions.polygon_to_blender_mesh(points, name=name) # type: ignore obj = self.create_object(mesh, name=name) @@ -282,7 +284,7 @@ def draw_cells( faces = self.volmesh.cell_faces(cell) # type: ignore vertex_index = dict((vertex, index) for index, vertex in enumerate(vertices)) - vertices = [self.vertex_xyz[vertex] for vertex in vertices] + vertices = [self.volmesh.vertices_attributes("xyz")[vertex] for vertex in vertices] faces = [[vertex_index[vertex] for vertex in self.volmesh.halfface_vertices(face)] for face in faces] # type: ignore mesh = conversions.vertices_and_faces_to_blender_mesh(vertices, faces, name=name) # type: ignore @@ -331,7 +333,7 @@ def draw_vertexnormals( for vertex in vertices or self.volmesh.vertices(): # type: ignore name = f"{self.volmesh.name}.vertex.{vertex}.normal" # type: ignore - a = self.vertex_xyz[vertex] + a = self.volmesh.vertices_attributes("xyz")[vertex] n = self.volmesh.vertex_normal(vertex) # type: ignore b = add_vectors(a, scale_vector(n, scale)) @@ -377,7 +379,7 @@ def draw_facenormals( for face in faces or self.volmesh.faces(): # type: ignore name = f"{self.volmesh.name}.face.{face}.normal" # type: ignore - a = centroid_points([self.vertex_xyz[vertex] for vertex in self.volmesh.face_vertices(face)]) # type: ignore + a = centroid_points([self.volmesh.vertices_attributes("xyz")[vertex] for vertex in self.volmesh.face_vertices(face)]) # type: ignore n = self.volmesh.face_normal(face) # type: ignore b = add_vectors(a, scale_vector(n, scale)) @@ -413,7 +415,7 @@ def draw_facenormals( # for vertex in self.vertex_text: # labels.append( # { - # "pos": self.vertex_xyz[vertex], + # "pos": self.volmesh.vertices_attributes("xyz")[vertex], # "name": f"{self.volmesh.name}.vertexlabel.{vertex}", # "text": self.vertex_text[vertex], # "color": self.vertex_color[vertex], @@ -441,7 +443,7 @@ def draw_facenormals( # u, v = edge # labels.append( # { - # "pos": centroid_points([self.vertex_xyz[u], self.vertex_xyz[v]]), + # "pos": centroid_points([self.volmesh.vertices_attributes("xyz")[u], self.volmesh.vertices_attributes("xyz")[v]]), # "name": f"{self.volmesh.name}.edgelabel.{u}-{v}", # "text": self.edge_text[edge], # "color": self.edge_color[edge], @@ -468,7 +470,7 @@ def draw_facenormals( # for face in self.face_text: # labels.append( # { - # "pos": centroid_points([self.vertex_xyz[vertex] for vertex in self.volmesh.face_vertices(face)]), + # "pos": centroid_points([self.volmesh.vertices_attributes("xyz")[vertex] for vertex in self.volmesh.face_vertices(face)]), # "name": "{}.facelabel.{}".format(self.volmesh.name, face), # "text": self.face_text[face], # "color": self.face_color[face], diff --git a/src/compas_ghpython/__init__.py b/src/compas_ghpython/__init__.py index 6b4bf2a4949..1f7ce54c592 100644 --- a/src/compas_ghpython/__init__.py +++ b/src/compas_ghpython/__init__.py @@ -20,7 +20,7 @@ __all_plugins__ = [ "compas_ghpython.install", "compas_ghpython.uninstall", - "compas_ghpython.artists", + "compas_ghpython.scene", ] diff --git a/src/compas_ghpython/artists/__init__.py b/src/compas_ghpython/artists/__init__.py deleted file mode 100644 index 975fc0080a7..00000000000 --- a/src/compas_ghpython/artists/__init__.py +++ /dev/null @@ -1,105 +0,0 @@ -""" -This package provides artist plugins for visualising COMPAS objects in Grasshopper. -When working in GH Python components, :class:`compas.artists.Artist` will automatically use the corresponding GHPython artist for each COMPAS object type. -""" -from __future__ import absolute_import - -from compas.plugins import plugin -from compas.artists import Artist - -from compas.geometry import Box -from compas.geometry import Capsule -from compas.geometry import Circle -from compas.geometry import Cone -from compas.geometry import Curve -from compas.geometry import Cylinder -from compas.geometry import Ellipse -from compas.geometry import Frame -from compas.geometry import Line -from compas.geometry import Point -from compas.geometry import Polygon -from compas.geometry import Polyhedron -from compas.geometry import Polyline -from compas.geometry import Sphere -from compas.geometry import Surface -from compas.geometry import Torus -from compas.geometry import Vector -from compas.geometry import Brep - -from compas.datastructures import Mesh -from compas.datastructures import Network -from compas.datastructures import VolMesh - -from .artist import GHArtist -from .boxartist import BoxArtist -from .capsuleartist import CapsuleArtist -from .circleartist import CircleArtist -from .coneartist import ConeArtist -from .curveartist import CurveArtist -from .cylinderartist import CylinderArtist -from .ellipseartist import EllipseArtist -from .frameartist import FrameArtist -from .lineartist import LineArtist -from .meshartist import MeshArtist -from .networkartist import NetworkArtist -from .pointartist import PointArtist -from .polygonartist import PolygonArtist -from .polyhedronartist import PolyhedronArtist -from .polylineartist import PolylineArtist -from .sphereartist import SphereArtist -from .surfaceartist import SurfaceArtist -from .torusartist import TorusArtist -from .vectorartist import VectorArtist -from .volmeshartist import VolMeshArtist -from .brepartist import BrepArtist - - -@plugin(category="factories", requires=["Rhino"]) -def register_artists(): - Artist.register(Box, BoxArtist, context="Grasshopper") - Artist.register(Capsule, CapsuleArtist, context="Grasshopper") - Artist.register(Circle, CircleArtist, context="Grasshopper") - Artist.register(Cone, ConeArtist, context="Grasshopper") - Artist.register(Curve, CurveArtist, context="Grasshopper") - Artist.register(Cylinder, CylinderArtist, context="Grasshopper") - Artist.register(Ellipse, EllipseArtist, context="Grasshopper") - Artist.register(Frame, FrameArtist, context="Grasshopper") - Artist.register(Line, LineArtist, context="Grasshopper") - Artist.register(Mesh, MeshArtist, context="Grasshopper") - Artist.register(Network, NetworkArtist, context="Grasshopper") - Artist.register(Point, PointArtist, context="Grasshopper") - Artist.register(Polygon, PolygonArtist, context="Grasshopper") - Artist.register(Polyhedron, PolyhedronArtist, context="Grasshopper") - Artist.register(Polyline, PolylineArtist, context="Grasshopper") - Artist.register(Sphere, SphereArtist, context="Grasshopper") - Artist.register(Surface, SurfaceArtist, context="Grasshopper") - Artist.register(Torus, TorusArtist, context="Grasshopper") - Artist.register(Vector, VectorArtist, context="Grasshopper") - Artist.register(VolMesh, VolMeshArtist, context="Grasshopper") - Artist.register(Brep, BrepArtist, context="Grasshopper") - print("GH Artists registered.") - - -__all__ = [ - "GHArtist", - "BoxArtist", - "CapsuleArtist", - "CircleArtist", - "ConeArtist", - "CurveArtist", - "CylinderArtist", - "EllipseArtist", - "FrameArtist", - "LineArtist", - "MeshArtist", - "NetworkArtist", - "PointArtist", - "PolygonArtist", - "PolyhedronArtist", - "PolylineArtist", - "SphereArtist", - "SurfaceArtist", - "TorusArtist", - "VectorArtist", - "VolMeshArtist", -] diff --git a/src/compas_ghpython/components/Compas_ToRhinoGeometry/code.py b/src/compas_ghpython/components/Compas_ToRhinoGeometry/code.py index f152ef89648..1d5ede76f5c 100644 --- a/src/compas_ghpython/components/Compas_ToRhinoGeometry/code.py +++ b/src/compas_ghpython/components/Compas_ToRhinoGeometry/code.py @@ -3,7 +3,7 @@ """ from ghpythonlib.componentbase import executingcomponent as component -from compas.artists import Artist +from compas.scene import SceneObject class CompasToRhinoGeometry(component): @@ -11,4 +11,4 @@ def RunScript(self, cg): if not cg: return None - return Artist(cg).draw() + return SceneObject(cg).draw() diff --git a/src/compas_ghpython/scene/__init__.py b/src/compas_ghpython/scene/__init__.py new file mode 100644 index 00000000000..39849ce363a --- /dev/null +++ b/src/compas_ghpython/scene/__init__.py @@ -0,0 +1,105 @@ +""" +This package provides scene object plugins for visualising COMPAS objects in Grasshopper. +When working in GH Python components, :class:`compas.scene.SceneObject` will automatically use the corresponding GHPython scene object for each COMPAS object type. +""" +from __future__ import absolute_import + +from compas.plugins import plugin +from compas.scene import SceneObject + +from compas.geometry import Box +from compas.geometry import Capsule +from compas.geometry import Circle +from compas.geometry import Cone +from compas.geometry import Curve +from compas.geometry import Cylinder +from compas.geometry import Ellipse +from compas.geometry import Frame +from compas.geometry import Line +from compas.geometry import Point +from compas.geometry import Polygon +from compas.geometry import Polyhedron +from compas.geometry import Polyline +from compas.geometry import Sphere +from compas.geometry import Surface +from compas.geometry import Torus +from compas.geometry import Vector +from compas.geometry import Brep + +from compas.datastructures import Mesh +from compas.datastructures import Network +from compas.datastructures import VolMesh + +from .sceneobject import GHSceneObject +from .boxobject import BoxObject +from .capsuleobject import CapsuleObject +from .circleobject import CircleObject +from .coneobject import ConeObject +from .curveobject import CurveObject +from .cylinderobject import CylinderObject +from .ellipseobject import EllipseObject +from .frameobject import FrameObject +from .lineobject import LineObject +from .meshobject import MeshObject +from .networkobject import NetworkObject +from .pointobject import PointObject +from .polygonobject import PolygonObject +from .polyhedronobject import PolyhedronObject +from .polylineobject import PolylineObject +from .sphereobject import SphereObject +from .surfaceobject import SurfaceObject +from .torusobject import TorusObject +from .vectorobject import VectorObject +from .volmeshobject import VolMeshObject +from .brepobject import BrepObject + + +@plugin(category="factories", requires=["Rhino"]) +def register_scene_objects(): + SceneObject.register(Box, BoxObject, context="Grasshopper") + SceneObject.register(Capsule, CapsuleObject, context="Grasshopper") + SceneObject.register(Circle, CircleObject, context="Grasshopper") + SceneObject.register(Cone, ConeObject, context="Grasshopper") + SceneObject.register(Curve, CurveObject, context="Grasshopper") + SceneObject.register(Cylinder, CylinderObject, context="Grasshopper") + SceneObject.register(Ellipse, EllipseObject, context="Grasshopper") + SceneObject.register(Frame, FrameObject, context="Grasshopper") + SceneObject.register(Line, LineObject, context="Grasshopper") + SceneObject.register(Mesh, MeshObject, context="Grasshopper") + SceneObject.register(Network, NetworkObject, context="Grasshopper") + SceneObject.register(Point, PointObject, context="Grasshopper") + SceneObject.register(Polygon, PolygonObject, context="Grasshopper") + SceneObject.register(Polyhedron, PolyhedronObject, context="Grasshopper") + SceneObject.register(Polyline, PolylineObject, context="Grasshopper") + SceneObject.register(Sphere, SphereObject, context="Grasshopper") + SceneObject.register(Surface, SurfaceObject, context="Grasshopper") + SceneObject.register(Torus, TorusObject, context="Grasshopper") + SceneObject.register(Vector, VectorObject, context="Grasshopper") + SceneObject.register(VolMesh, VolMeshObject, context="Grasshopper") + SceneObject.register(Brep, BrepObject, context="Grasshopper") + print("GH SceneObjects registered.") + + +__all__ = [ + "GHSceneObject", + "BoxObject", + "CapsuleObject", + "CircleObject", + "ConeObject", + "CurveObject", + "CylinderObject", + "EllipseObject", + "FrameObject", + "LineObject", + "MeshObject", + "NetworkObject", + "PointObject", + "PolygonObject", + "PolyhedronObject", + "PolylineObject", + "SphereObject", + "SurfaceObject", + "TorusObject", + "VectorObject", + "VolMeshObject", +] diff --git a/src/compas_ghpython/artists/boxartist.py b/src/compas_ghpython/scene/boxobject.py similarity index 70% rename from src/compas_ghpython/artists/boxartist.py rename to src/compas_ghpython/scene/boxobject.py index fd2fb0b279b..39412115f14 100644 --- a/src/compas_ghpython/artists/boxartist.py +++ b/src/compas_ghpython/scene/boxobject.py @@ -4,12 +4,12 @@ from compas_rhino import conversions -from compas.artists import GeometryArtist -from .artist import GHArtist +from compas.scene import GeometryObject +from .sceneobject import GHSceneObject -class BoxArtist(GHArtist, GeometryArtist): - """Artist for drawing box shapes. +class BoxObject(GHSceneObject, GeometryObject): + """Scene object for drawing box shapes. Parameters ---------- @@ -21,10 +21,10 @@ class BoxArtist(GHArtist, GeometryArtist): """ def __init__(self, box, **kwargs): - super(BoxArtist, self).__init__(geometry=box, **kwargs) + super(BoxObject, self).__init__(geometry=box, **kwargs) def draw(self): - """Draw the box associated with the artist. + """Draw the box associated with the scene object. Returns ------- diff --git a/src/compas_ghpython/artists/brepartist.py b/src/compas_ghpython/scene/brepobject.py similarity index 76% rename from src/compas_ghpython/artists/brepartist.py rename to src/compas_ghpython/scene/brepobject.py index 13698200214..ed2cbf7a5b9 100644 --- a/src/compas_ghpython/artists/brepartist.py +++ b/src/compas_ghpython/scene/brepobject.py @@ -4,12 +4,12 @@ from compas_rhino import conversions -from compas.artists import GeometryArtist -from .artist import GHArtist +from compas.scene import GeometryObject +from .sceneobject import GHSceneObject -class BrepArtist(GHArtist, GeometryArtist): - """An artist for drawing a brep in Grasshopper. +class BrepObject(GHSceneObject, GeometryObject): + """A Scene object for drawing a brep in Grasshopper. Parameters ---------- @@ -21,7 +21,7 @@ class BrepArtist(GHArtist, GeometryArtist): """ def __init__(self, brep, **kwargs): - super(BrepArtist, self).__init__(geometry=brep, **kwargs) + super(BrepObject, self).__init__(geometry=brep, **kwargs) def draw(self): """Draw the brep as a Grasshopper geometry. diff --git a/src/compas_ghpython/artists/capsuleartist.py b/src/compas_ghpython/scene/capsuleobject.py similarity index 72% rename from src/compas_ghpython/artists/capsuleartist.py rename to src/compas_ghpython/scene/capsuleobject.py index d028d333db5..068e847b604 100644 --- a/src/compas_ghpython/artists/capsuleartist.py +++ b/src/compas_ghpython/scene/capsuleobject.py @@ -4,12 +4,12 @@ from compas_rhino import conversions -from compas.artists import GeometryArtist -from .artist import GHArtist +from compas.scene import GeometryObject +from .sceneobject import GHSceneObject -class CapsuleArtist(GHArtist, GeometryArtist): - """Artist for drawing capsule shapes. +class CapsuleObject(GHSceneObject, GeometryObject): + """Scene object for drawing capsule shapes. Parameters ---------- @@ -21,10 +21,10 @@ class CapsuleArtist(GHArtist, GeometryArtist): """ def __init__(self, capsule, **kwargs): - super(CapsuleArtist, self).__init__(geometry=capsule, **kwargs) + super(CapsuleObject, self).__init__(geometry=capsule, **kwargs) def draw(self): - """Draw the capsule associated with the artist. + """Draw the capsule associated with the scene object. Returns ------- diff --git a/src/compas_ghpython/artists/circleartist.py b/src/compas_ghpython/scene/circleobject.py similarity index 76% rename from src/compas_ghpython/artists/circleartist.py rename to src/compas_ghpython/scene/circleobject.py index d61b2bb53eb..b6141693464 100644 --- a/src/compas_ghpython/artists/circleartist.py +++ b/src/compas_ghpython/scene/circleobject.py @@ -4,12 +4,12 @@ from compas_rhino import conversions -from compas.artists import GeometryArtist -from .artist import GHArtist +from compas.scene import GeometryObject +from .sceneobject import GHSceneObject -class CircleArtist(GHArtist, GeometryArtist): - """Artist for drawing circles. +class CircleObject(GHSceneObject, GeometryObject): + """Scene object for drawing circles. Parameters ---------- @@ -21,7 +21,7 @@ class CircleArtist(GHArtist, GeometryArtist): """ def __init__(self, circle, **kwargs): - super(CircleArtist, self).__init__(geometry=circle, **kwargs) + super(CircleObject, self).__init__(geometry=circle, **kwargs) def draw(self): """Draw the circle. diff --git a/src/compas_ghpython/artists/coneartist.py b/src/compas_ghpython/scene/coneobject.py similarity index 57% rename from src/compas_ghpython/artists/coneartist.py rename to src/compas_ghpython/scene/coneobject.py index 3711992b047..6d358d3155b 100644 --- a/src/compas_ghpython/artists/coneartist.py +++ b/src/compas_ghpython/scene/coneobject.py @@ -4,12 +4,12 @@ from compas_rhino import conversions -from compas.artists import GeometryArtist -from .artist import GHArtist +from compas.scene import GeometryObject +from .sceneobject import GHSceneObject -class ConeArtist(GHArtist, GeometryArtist): - """Artist for drawing cone shapes. +class ConeObject(GHSceneObject, GeometryObject): + """Scene object for drawing cone shapes. Parameters ---------- @@ -21,21 +21,20 @@ class ConeArtist(GHArtist, GeometryArtist): """ def __init__(self, cone, **kwargs): - super(ConeArtist, self).__init__(geometry=cone, **kwargs) + super(ConeObject, self).__init__(geometry=cone, **kwargs) def draw(self): - """Draw the cone associated with the artist. + """Draw the cone associated with the scene object. Returns ------- list[:rhino:`Rhino.Geometry.Brep`] """ - breps = conversions.cone_to_rhino_brep(self.geometry) + brep = conversions.cone_to_rhino_brep(self.geometry) if self.transformation: transformation = conversions.transformation_to_rhino(self.transformation) - for geometry in breps: - geometry.Transform(transformation) + brep.Transform(transformation) - return breps + return brep diff --git a/src/compas_ghpython/artists/curveartist.py b/src/compas_ghpython/scene/curveobject.py similarity index 77% rename from src/compas_ghpython/artists/curveartist.py rename to src/compas_ghpython/scene/curveobject.py index 1916854b808..00047597a7d 100644 --- a/src/compas_ghpython/artists/curveartist.py +++ b/src/compas_ghpython/scene/curveobject.py @@ -4,12 +4,12 @@ from compas_rhino import conversions -from compas.artists import GeometryArtist -from .artist import GHArtist +from compas.scene import GeometryObject +from .sceneobject import GHSceneObject -class CurveArtist(GHArtist, GeometryArtist): - """Artist for drawing curves. +class CurveObject(GHSceneObject, GeometryObject): + """Scene object for drawing curves. Parameters ---------- @@ -24,7 +24,7 @@ class CurveArtist(GHArtist, GeometryArtist): """ def __init__(self, curve, **kwargs): - super(CurveArtist, self).__init__(geometry=curve, **kwargs) + super(CurveObject, self).__init__(geometry=curve, **kwargs) def draw(self): """Draw the curve. diff --git a/src/compas_ghpython/artists/cylinderartist.py b/src/compas_ghpython/scene/cylinderobject.py similarity index 76% rename from src/compas_ghpython/artists/cylinderartist.py rename to src/compas_ghpython/scene/cylinderobject.py index b144983e698..a85432b2967 100644 --- a/src/compas_ghpython/artists/cylinderartist.py +++ b/src/compas_ghpython/scene/cylinderobject.py @@ -4,12 +4,12 @@ from compas_rhino import conversions -from compas.artists import GeometryArtist -from .artist import GHArtist +from compas.scene import GeometryObject +from .sceneobject import GHSceneObject -class CylinderArtist(GHArtist, GeometryArtist): - """Artist for drawing cylinder shapes. +class CylinderObject(GHSceneObject, GeometryObject): + """Scene object for drawing cylinder shapes. Parameters ---------- @@ -21,10 +21,10 @@ class CylinderArtist(GHArtist, GeometryArtist): """ def __init__(self, cylinder, **kwargs): - super(CylinderArtist, self).__init__(geometry=cylinder, **kwargs) + super(CylinderObject, self).__init__(geometry=cylinder, **kwargs) def draw(self, color=None, u=16): - """Draw the cylinder associated with the artist. + """Draw the cylinder associated with the scene object. Parameters ---------- diff --git a/src/compas_ghpython/artists/ellipseartist.py b/src/compas_ghpython/scene/ellipseobject.py similarity index 63% rename from src/compas_ghpython/artists/ellipseartist.py rename to src/compas_ghpython/scene/ellipseobject.py index 4557c654874..cfac19b18e1 100644 --- a/src/compas_ghpython/artists/ellipseartist.py +++ b/src/compas_ghpython/scene/ellipseobject.py @@ -4,12 +4,12 @@ from compas_rhino import conversions -from compas.artists import GeometryArtist -from .artist import GHArtist +from compas.scene import GeometryObject +from .sceneobject import GHSceneObject -class EllipseArtist(GHArtist, GeometryArtist): - """Artist for drawing ellipses. +class EllipseObject(GHSceneObject, GeometryObject): + """Scene object for drawing ellipses. Parameters ---------- @@ -21,7 +21,7 @@ class EllipseArtist(GHArtist, GeometryArtist): """ def __init__(self, ellipse, **kwargs): - super(EllipseArtist, self).__init__(geometry=ellipse, **kwargs) + super(EllipseObject, self).__init__(geometry=ellipse, **kwargs) def draw(self): """Draw the ellipse. @@ -32,9 +32,9 @@ def draw(self): """ ellipse = conversions.ellipse_to_rhino(self.geometry) + ellipse = ellipse.ToNurbsCurve() if self.transformation: - transformation = conversions.transformation_to_rhino(self.transformation) - ellipse.Transform(transformation) + ellipse.Transform(conversions.transformation_to_rhino(self.transformation)) return ellipse diff --git a/src/compas_ghpython/artists/frameartist.py b/src/compas_ghpython/scene/frameobject.py similarity index 88% rename from src/compas_ghpython/artists/frameartist.py rename to src/compas_ghpython/scene/frameobject.py index 8a511924c96..b36dc0e6914 100644 --- a/src/compas_ghpython/artists/frameartist.py +++ b/src/compas_ghpython/scene/frameobject.py @@ -4,12 +4,12 @@ from compas_rhino import conversions -from compas.artists import GeometryArtist -from .artist import GHArtist +from compas.scene import GeometryObject +from .sceneobject import GHSceneObject -class FrameArtist(GHArtist, GeometryArtist): - """Artist for drawing frames. +class FrameObject(GHSceneObject, GeometryObject): + """Scene object for drawing frames. Parameters ---------- @@ -36,7 +36,7 @@ class FrameArtist(GHArtist, GeometryArtist): """ def __init__(self, frame, scale=1.0, **kwargs): - super(FrameArtist, self).__init__(geometry=frame, **kwargs) + super(FrameObject, self).__init__(geometry=frame, **kwargs) self.scale = scale def draw(self): diff --git a/src/compas_ghpython/artists/lineartist.py b/src/compas_ghpython/scene/lineobject.py similarity index 75% rename from src/compas_ghpython/artists/lineartist.py rename to src/compas_ghpython/scene/lineobject.py index adda79ebe51..89ef533974f 100644 --- a/src/compas_ghpython/artists/lineartist.py +++ b/src/compas_ghpython/scene/lineobject.py @@ -4,12 +4,12 @@ from compas_rhino import conversions -from compas.artists import GeometryArtist -from .artist import GHArtist +from compas.scene import GeometryObject +from .sceneobject import GHSceneObject -class LineArtist(GHArtist, GeometryArtist): - """Artist for drawing lines. +class LineObject(GHSceneObject, GeometryObject): + """Scene object for drawing lines. Parameters ---------- @@ -21,7 +21,7 @@ class LineArtist(GHArtist, GeometryArtist): """ def __init__(self, line, **kwargs): - super(LineArtist, self).__init__(geometry=line, **kwargs) + super(LineObject, self).__init__(geometry=line, **kwargs) def draw(self): """Draw the line. diff --git a/src/compas_ghpython/artists/meshartist.py b/src/compas_ghpython/scene/meshobject.py similarity index 90% rename from src/compas_ghpython/artists/meshartist.py rename to src/compas_ghpython/scene/meshobject.py index acc1ba123a4..a044f327f2e 100644 --- a/src/compas_ghpython/artists/meshartist.py +++ b/src/compas_ghpython/scene/meshobject.py @@ -2,15 +2,15 @@ from __future__ import division from __future__ import print_function -from compas.artists import MeshArtist as BaseArtist +from compas.scene import MeshObject as BaseMeshObject from compas.colors import Color from compas_rhino import conversions -from compas_rhino.artists._helpers import ngon -from .artist import GHArtist +from compas_rhino.scene._helpers import ngon +from .sceneobject import GHSceneObject -class MeshArtist(GHArtist, BaseArtist): - """Artist for drawing mesh data structures. +class MeshObject(GHSceneObject, BaseMeshObject): + """Scene object for drawing mesh data structures. Parameters ---------- @@ -22,7 +22,7 @@ class MeshArtist(GHArtist, BaseArtist): """ def __init__(self, mesh, **kwargs): - super(MeshArtist, self).__init__(mesh=mesh, **kwargs) + super(MeshObject, self).__init__(mesh=mesh, **kwargs) def draw(self, color=None, vertexcolors=None, facecolors=None, disjoint=False): """Draw the mesh. @@ -37,7 +37,7 @@ def draw(self, color=None, vertexcolors=None, facecolors=None, disjoint=False): :rhino:`Rhino.Geometry.Mesh` """ - # the rhino artist can set an overal color and component colors simultaneously + # the rhino scene object can set an overal color and component colors simultaneously # because it can set an overall color on the mesh object attributes # this is not possible in GH (since there is no such object) # either we set an overall color or we set component colors diff --git a/src/compas_ghpython/artists/networkartist.py b/src/compas_ghpython/scene/networkobject.py similarity index 87% rename from src/compas_ghpython/artists/networkartist.py rename to src/compas_ghpython/scene/networkobject.py index 6a6af153296..599eb841715 100644 --- a/src/compas_ghpython/artists/networkartist.py +++ b/src/compas_ghpython/scene/networkobject.py @@ -4,12 +4,12 @@ from compas_rhino import conversions -from compas.artists import NetworkArtist as BaseArtist -from .artist import GHArtist +from compas.scene import NetworkObject as BaseNetworkObject +from .sceneobject import GHSceneObject -class NetworkArtist(GHArtist, BaseArtist): - """Artist for drawing network data structures. +class NetworkObject(GHSceneObject, BaseNetworkObject): + """Scene object for drawing network data structures. Parameters ---------- @@ -21,7 +21,7 @@ class NetworkArtist(GHArtist, BaseArtist): """ def __init__(self, network, **kwargs): - super(NetworkArtist, self).__init__(network=network, **kwargs) + super(NetworkObject, self).__init__(network=network, **kwargs) def draw(self): """Draw the entire network with default color settings. diff --git a/src/compas_ghpython/artists/pointartist.py b/src/compas_ghpython/scene/pointobject.py similarity index 75% rename from src/compas_ghpython/artists/pointartist.py rename to src/compas_ghpython/scene/pointobject.py index 600f9684561..68e4bd0169e 100644 --- a/src/compas_ghpython/artists/pointartist.py +++ b/src/compas_ghpython/scene/pointobject.py @@ -4,12 +4,12 @@ from compas_rhino import conversions -from compas.artists import GeometryArtist -from .artist import GHArtist +from compas.scene import GeometryObject +from .sceneobject import GHSceneObject -class PointArtist(GHArtist, GeometryArtist): - """Artist for drawing points. +class PointObject(GHSceneObject, GeometryObject): + """Scene object for drawing points. Parameters ---------- @@ -21,7 +21,7 @@ class PointArtist(GHArtist, GeometryArtist): """ def __init__(self, point, **kwargs): - super(PointArtist, self).__init__(geometry=point, **kwargs) + super(PointObject, self).__init__(geometry=point, **kwargs) def draw(self): """Draw the point. diff --git a/src/compas_ghpython/artists/polygonartist.py b/src/compas_ghpython/scene/polygonobject.py similarity index 82% rename from src/compas_ghpython/artists/polygonartist.py rename to src/compas_ghpython/scene/polygonobject.py index bee1ef73be3..bb976e55d0c 100644 --- a/src/compas_ghpython/artists/polygonartist.py +++ b/src/compas_ghpython/scene/polygonobject.py @@ -6,12 +6,12 @@ from compas_rhino import conversions -from compas.artists import GeometryArtist -from .artist import GHArtist +from compas.scene import GeometryObject +from .sceneobject import GHSceneObject -class PolygonArtist(GHArtist, GeometryArtist): - """Artist for drawing polygons. +class PolygonObject(GHSceneObject, GeometryObject): + """Scene object for drawing polygons. Parameters ---------- @@ -23,7 +23,7 @@ class PolygonArtist(GHArtist, GeometryArtist): """ def __init__(self, polygon, **kwargs): - super(PolygonArtist, self).__init__(geometry=polygon, **kwargs) + super(PolygonObject, self).__init__(geometry=polygon, **kwargs) def draw(self, color=None, show_vertices=False, show_edges=False): """Draw the polygon. diff --git a/src/compas_ghpython/artists/polyhedronartist.py b/src/compas_ghpython/scene/polyhedronobject.py similarity index 77% rename from src/compas_ghpython/artists/polyhedronartist.py rename to src/compas_ghpython/scene/polyhedronobject.py index 9a1c2d411d7..c2d3d28a44f 100644 --- a/src/compas_ghpython/artists/polyhedronartist.py +++ b/src/compas_ghpython/scene/polyhedronobject.py @@ -6,12 +6,12 @@ from compas_rhino import conversions -from compas.artists import GeometryArtist -from .artist import GHArtist +from compas.scene import GeometryObject +from .sceneobject import GHSceneObject -class PolyhedronArtist(GHArtist, GeometryArtist): - """Artist for drawing polyhedron shapes. +class PolyhedronObject(GHSceneObject, GeometryObject): + """Scene object for drawing polyhedron shapes. Parameters ---------- @@ -23,10 +23,10 @@ class PolyhedronArtist(GHArtist, GeometryArtist): """ def __init__(self, polyhedron, **kwargs): - super(PolyhedronArtist, self).__init__(geometry=polyhedron, **kwargs) + super(PolyhedronObject, self).__init__(geometry=polyhedron, **kwargs) def draw(self, color=None): - """Draw the polyhedron associated with the artist. + """Draw the polyhedron associated with the scene object. Parameters ---------- diff --git a/src/compas_ghpython/artists/polylineartist.py b/src/compas_ghpython/scene/polylineobject.py similarity index 75% rename from src/compas_ghpython/artists/polylineartist.py rename to src/compas_ghpython/scene/polylineobject.py index aa95784a527..2d871eed75b 100644 --- a/src/compas_ghpython/artists/polylineartist.py +++ b/src/compas_ghpython/scene/polylineobject.py @@ -4,12 +4,12 @@ from compas_rhino import conversions -from compas.artists import GeometryArtist -from .artist import GHArtist +from compas.scene import GeometryObject +from .sceneobject import GHSceneObject -class PolylineArtist(GHArtist, GeometryArtist): - """Artist for drawing polylines. +class PolylineObject(GHSceneObject, GeometryObject): + """Scene object for drawing polylines. Parameters ---------- @@ -21,7 +21,7 @@ class PolylineArtist(GHArtist, GeometryArtist): """ def __init__(self, polyline, **kwargs): - super(PolylineArtist, self).__init__(geometry=polyline, **kwargs) + super(PolylineObject, self).__init__(geometry=polyline, **kwargs) def draw(self): """Draw the polyline. diff --git a/src/compas_ghpython/artists/artist.py b/src/compas_ghpython/scene/sceneobject.py similarity index 54% rename from src/compas_ghpython/artists/artist.py rename to src/compas_ghpython/scene/sceneobject.py index 306e5f1101d..29e5777fb97 100644 --- a/src/compas_ghpython/artists/artist.py +++ b/src/compas_ghpython/scene/sceneobject.py @@ -2,14 +2,14 @@ from __future__ import absolute_import from __future__ import division -from compas.artists import Artist +from compas.scene import SceneObject -class GHArtist(Artist): - """Base class for all GH artists.""" +class GHSceneObject(SceneObject): + """Base class for all GH scene objects.""" def __init__(self, **kwargs): - super(GHArtist, self).__init__(**kwargs) + super(GHSceneObject, self).__init__(**kwargs) def clear(self): raise NotImplementedError diff --git a/src/compas_ghpython/artists/sphereartist.py b/src/compas_ghpython/scene/sphereobject.py similarity index 69% rename from src/compas_ghpython/artists/sphereartist.py rename to src/compas_ghpython/scene/sphereobject.py index 63ca84eceff..22db157e2ee 100644 --- a/src/compas_ghpython/artists/sphereartist.py +++ b/src/compas_ghpython/scene/sphereobject.py @@ -4,12 +4,12 @@ from compas_rhino import conversions -from compas.artists import GeometryArtist -from .artist import GHArtist +from compas.scene import GeometryObject +from .sceneobject import GHSceneObject -class SphereArtist(GHArtist, GeometryArtist): - """Artist for drawing sphere shapes. +class SphereObject(GHSceneObject, GeometryObject): + """Scene object for drawing sphere shapes. Parameters ---------- @@ -21,10 +21,10 @@ class SphereArtist(GHArtist, GeometryArtist): """ def __init__(self, sphere, **kwargs): - super(SphereArtist, self).__init__(geometry=sphere, **kwargs) + super(SphereObject, self).__init__(geometry=sphere, **kwargs) def draw(self): - """Draw the sphere associated with the artist. + """Draw the sphere associated with the scene object. Returns ------- diff --git a/src/compas_ghpython/artists/surfaceartist.py b/src/compas_ghpython/scene/surfaceobject.py similarity index 76% rename from src/compas_ghpython/artists/surfaceartist.py rename to src/compas_ghpython/scene/surfaceobject.py index 3aebff6f80b..9d7dec02f16 100644 --- a/src/compas_ghpython/artists/surfaceartist.py +++ b/src/compas_ghpython/scene/surfaceobject.py @@ -4,12 +4,12 @@ from compas_rhino import conversions -from compas.artists import GeometryArtist -from .artist import GHArtist +from compas.scene import GeometryObject +from .sceneobject import GHSceneObject -class SurfaceArtist(GHArtist, GeometryArtist): - """Artist for drawing surfaces. +class SurfaceObject(GHSceneObject, GeometryObject): + """Scene object for drawing surfaces. Parameters ---------- @@ -24,7 +24,7 @@ class SurfaceArtist(GHArtist, GeometryArtist): """ def __init__(self, surface, **kwargs): - super(SurfaceArtist, self).__init__(geometry=surface, **kwargs) + super(SurfaceObject, self).__init__(geometry=surface, **kwargs) def draw(self): """Draw the surface. diff --git a/src/compas_ghpython/artists/torusartist.py b/src/compas_ghpython/scene/torusobject.py similarity index 52% rename from src/compas_ghpython/artists/torusartist.py rename to src/compas_ghpython/scene/torusobject.py index c0d5817e666..8eabf3b1ba6 100644 --- a/src/compas_ghpython/artists/torusartist.py +++ b/src/compas_ghpython/scene/torusobject.py @@ -4,12 +4,12 @@ from compas_rhino import conversions -from compas.artists import GeometryArtist -from .artist import GHArtist +from compas.scene import GeometryObject +from .sceneobject import GHSceneObject -class TorusArtist(GHArtist, GeometryArtist): - """Artist for drawing torus shapes. +class TorusObject(GHSceneObject, GeometryObject): + """Scene object for drawing torus shapes. Parameters ---------- @@ -21,19 +21,18 @@ class TorusArtist(GHArtist, GeometryArtist): """ def __init__(self, torus, **kwargs): - super(TorusArtist, self).__init__(geometry=torus, **kwargs) + super(TorusObject, self).__init__(geometry=torus, **kwargs) def draw(self): - """Draw the torus associated with the artist. + """Draw the torus associated with the scene object. Returns ------- :rhino:`Rhino.Geometry.Torus` """ - geometry = conversions.torus_to_rhino(self.geometry) - + brep = conversions.torus_to_rhino_brep(self.geometry) if self.transformation: - geometry.Transform(conversions.transformation_to_rhino(self.transformation)) + brep.Transform(conversions.transformation_to_rhino(self.transformation)) - return geometry + return brep diff --git a/src/compas_ghpython/artists/vectorartist.py b/src/compas_ghpython/scene/vectorobject.py similarity index 82% rename from src/compas_ghpython/artists/vectorartist.py rename to src/compas_ghpython/scene/vectorobject.py index 1d29eb8c8a7..fcd1a3eeadc 100644 --- a/src/compas_ghpython/artists/vectorartist.py +++ b/src/compas_ghpython/scene/vectorobject.py @@ -5,12 +5,12 @@ from compas_rhino import conversions from compas.geometry import Point -from compas.artists import GeometryArtist -from .artist import GHArtist +from compas.scene import GeometryObject +from .sceneobject import GHSceneObject -class VectorArtist(GHArtist, GeometryArtist): - """Artist for drawing vectors. +class VectorObject(GHSceneObject, GeometryObject): + """Scene object for drawing vectors. Parameters ---------- @@ -22,7 +22,7 @@ class VectorArtist(GHArtist, GeometryArtist): """ def __init__(self, vector, **kwargs): - super(VectorArtist, self).__init__(geometry=vector, **kwargs) + super(VectorObject, self).__init__(geometry=vector, **kwargs) def draw(self, point=None, show_point=False): """Draw the vector. diff --git a/src/compas_ghpython/artists/volmeshartist.py b/src/compas_ghpython/scene/volmeshobject.py similarity index 90% rename from src/compas_ghpython/artists/volmeshartist.py rename to src/compas_ghpython/scene/volmeshobject.py index ce6cf13b261..c915ddae202 100644 --- a/src/compas_ghpython/artists/volmeshartist.py +++ b/src/compas_ghpython/scene/volmeshobject.py @@ -3,14 +3,14 @@ from __future__ import division from compas_rhino import conversions -from compas_rhino.artists._helpers import ngon +from compas_rhino.scene._helpers import ngon -from compas.artists import VolMeshArtist as BaseArtist -from .artist import GHArtist +from compas.scene import VolMeshObject as BaseVolMeshObject +from .sceneobject import GHSceneObject -class VolMeshArtist(GHArtist, BaseArtist): - """Artist for drawing volmesh data structures. +class VolMeshObject(GHSceneObject, BaseVolMeshObject): + """Scene object for drawing volmesh data structures. Parameters ---------- @@ -22,7 +22,7 @@ class VolMeshArtist(GHArtist, BaseArtist): """ def __init__(self, volmesh, **kwargs): - super(VolMeshArtist, self).__init__(volmesh=volmesh, **kwargs) + super(VolMeshObject, self).__init__(volmesh=volmesh, **kwargs) def draw(self, cells=None, color=None): """Draw a selection of cells. @@ -34,7 +34,7 @@ def draw(self, cells=None, color=None): The default is None, in which case all cells are drawn. color : :class:`compas.colors.Color` | dict[int, :class:`compas.colors.Color`], optional The color of the cells. - The default color is :attr:`VolMeshArtist.default_cellcolor`. + The default color is :attr:`VolMeshObject.default_cellcolor`. Returns ------- @@ -97,7 +97,7 @@ def draw_faces(self, faces=None, color=None): The default is None, in which case all faces are drawn. color : :class:`compas.colors.Color` | dict[int, :class:`compas.colors.Color`], optional The color specification for the faces. - The default color is :attr:`VolMeshArtist.default_facecolor`. + The default color is :attr:`VolMeshObject.default_facecolor`. Returns ------- diff --git a/src/compas_rhino/__init__.py b/src/compas_rhino/__init__.py index 9c678c5749e..1ed0fefd802 100644 --- a/src/compas_rhino/__init__.py +++ b/src/compas_rhino/__init__.py @@ -45,7 +45,7 @@ "compas_rhino.geometry.trimesh_slicing", "compas_rhino.install", "compas_rhino.uninstall", - "compas_rhino.artists", + "compas_rhino.scene", "compas_rhino.geometry.curves", "compas_rhino.geometry.surfaces", "compas_rhino.geometry.brep", diff --git a/src/compas_rhino/artists/__init__.py b/src/compas_rhino/artists/__init__.py deleted file mode 100644 index eab3628a900..00000000000 --- a/src/compas_rhino/artists/__init__.py +++ /dev/null @@ -1,127 +0,0 @@ -""" -This package provides artist plugins for visualising COMPAS objects in Rhino. -When working in Rhino, :class:`compas.artists.Artist` will automatically use the corresponding Rhino artist for each COMPAS object type. -""" -from __future__ import absolute_import - -from compas.plugins import plugin -from compas.artists import Artist - -from compas.geometry import Circle -from compas.geometry import Ellipse -from compas.geometry import Frame -from compas.geometry import Line -from compas.geometry import Plane -from compas.geometry import Point -from compas.geometry import Polygon -from compas.geometry import Polyline -from compas.geometry import Vector - -from compas.geometry import Box -from compas.geometry import Capsule -from compas.geometry import Cone -from compas.geometry import Cylinder -from compas.geometry import Polyhedron -from compas.geometry import Sphere -from compas.geometry import Torus - -from compas.geometry import Curve -from compas.geometry import Surface -from compas.geometry import Brep - -from compas.datastructures import Mesh -from compas.datastructures import Network -from compas.datastructures import VolMesh - -import compas_rhino - -from .artist import RhinoArtist -from .circleartist import CircleArtist -from .ellipseartist import EllipseArtist -from .frameartist import FrameArtist -from .lineartist import LineArtist -from .planeartist import PlaneArtist -from .pointartist import PointArtist -from .polygonartist import PolygonArtist -from .polylineartist import PolylineArtist -from .vectorartist import VectorArtist - -from .boxartist import BoxArtist -from .capsuleartist import CapsuleArtist -from .coneartist import ConeArtist -from .cylinderartist import CylinderArtist -from .polyhedronartist import PolyhedronArtist -from .sphereartist import SphereArtist -from .torusartist import TorusArtist - -from .meshartist import MeshArtist -from .networkartist import NetworkArtist -from .volmeshartist import VolMeshArtist - -from .curveartist import CurveArtist -from .surfaceartist import SurfaceArtist -from .brepartist import BrepArtist - - -@plugin(category="drawing-utils", pluggable_name="clear", requires=["Rhino"]) -def clear_rhino(): - compas_rhino.clear() - - -@plugin(category="drawing-utils", pluggable_name="redraw", requires=["Rhino"]) -def redraw_rhino(): - compas_rhino.redraw() - - -@plugin(category="factories", requires=["Rhino"]) -def register_artists(): - Artist.register(Circle, CircleArtist, context="Rhino") - Artist.register(Ellipse, EllipseArtist, context="Rhino") - Artist.register(Frame, FrameArtist, context="Rhino") - Artist.register(Line, LineArtist, context="Rhino") - Artist.register(Plane, PlaneArtist, context="Rhino") - Artist.register(Point, PointArtist, context="Rhino") - Artist.register(Polygon, PolygonArtist, context="Rhino") - Artist.register(Polyline, PolylineArtist, context="Rhino") - Artist.register(Vector, VectorArtist, context="Rhino") - Artist.register(Box, BoxArtist, context="Rhino") - Artist.register(Capsule, CapsuleArtist, context="Rhino") - Artist.register(Cone, ConeArtist, context="Rhino") - Artist.register(Cylinder, CylinderArtist, context="Rhino") - Artist.register(Polyhedron, PolyhedronArtist, context="Rhino") - Artist.register(Sphere, SphereArtist, context="Rhino") - Artist.register(Torus, TorusArtist, context="Rhino") - Artist.register(Mesh, MeshArtist, context="Rhino") - Artist.register(Network, NetworkArtist, context="Rhino") - Artist.register(VolMesh, VolMeshArtist, context="Rhino") - Artist.register(Curve, CurveArtist, context="Rhino") - Artist.register(Surface, SurfaceArtist, context="Rhino") - Artist.register(Brep, BrepArtist, context="Rhino") - print("Rhino Artists registered.") - - -__all__ = [ - "RhinoArtist", - "CircleArtist", - "EllipseArtist", - "FrameArtist", - "LineArtist", - "PlaneArtist", - "PointArtist", - "PolygonArtist", - "PolylineArtist", - "VectorArtist", - "BoxArtist", - "CapsuleArtist", - "ConeArtist", - "CylinderArtist", - "PolyhedronArtist", - "SphereArtist", - "TorusArtist", - "MeshArtist", - "NetworkArtist", - "VolMeshArtist", - "CurveArtist", - "SurfaceArtist", - "BrepArtist", -] diff --git a/src/compas_rhino/conversions/shapes.py b/src/compas_rhino/conversions/shapes.py index 6112dbde5dc..1401382f196 100644 --- a/src/compas_rhino/conversions/shapes.py +++ b/src/compas_rhino/conversions/shapes.py @@ -71,7 +71,7 @@ def sphere_to_rhino(sphere): :rhino:`Rhino.Geometry.Sphere` """ - return RhinoSphere(point_to_rhino(sphere.point), sphere.radius) + return RhinoSphere(point_to_rhino(sphere.frame.point), sphere.radius) def cone_to_rhino(cone): diff --git a/src/compas_rhino/conversions/surfaces.py b/src/compas_rhino/conversions/surfaces.py index ccd2caddd4a..37b9c177760 100644 --- a/src/compas_rhino/conversions/surfaces.py +++ b/src/compas_rhino/conversions/surfaces.py @@ -191,7 +191,7 @@ def surface_to_compas_mesh(surface, cls=None, facefilter=None, cleanup=False): -------- >>> import compas_rhino >>> from compas_rhino.geometry import RhinoSurface - >>> from compas_rhino.artists import MeshArtist + >>> from compas.scene import Scene >>> def facefilter(face): ... success, w, h = face.GetSurfaceSize() @@ -205,9 +205,9 @@ def surface_to_compas_mesh(surface, cls=None, facefilter=None, cleanup=False): >>> surf = RhinoSurface.from_guid(guid) >>> mesh = surf.to_compas(facefilter=facefilter) - >>> artist = MeshArtist(mesh, layer="Blocks") - >>> artist.clear_layer() - >>> artist.draw() + >>> scene = Scene() + >>> scene.add(mesh, layer="Blocks") + >>> scene.redraw() """ if not surface.HasBrepForm: diff --git a/src/compas_rhino/scene/__init__.py b/src/compas_rhino/scene/__init__.py new file mode 100644 index 00000000000..ac6ad00e3b0 --- /dev/null +++ b/src/compas_rhino/scene/__init__.py @@ -0,0 +1,127 @@ +""" +This package provides scene object plugins for visualising COMPAS objects in Rhino. +When working in Rhino, :class:`compas.scene.SceneObject` will automatically use the corresponding Rhino scene object for each COMPAS object type. +""" +from __future__ import absolute_import + +from compas.plugins import plugin +from compas.scene import SceneObject + +from compas.geometry import Circle +from compas.geometry import Ellipse +from compas.geometry import Frame +from compas.geometry import Line +from compas.geometry import Plane +from compas.geometry import Point +from compas.geometry import Polygon +from compas.geometry import Polyline +from compas.geometry import Vector + +from compas.geometry import Box +from compas.geometry import Capsule +from compas.geometry import Cone +from compas.geometry import Cylinder +from compas.geometry import Polyhedron +from compas.geometry import Sphere +from compas.geometry import Torus + +from compas.geometry import Curve +from compas.geometry import Surface +from compas.geometry import Brep + +from compas.datastructures import Mesh +from compas.datastructures import Network +from compas.datastructures import VolMesh + +import compas_rhino + +from .sceneobject import RhinoSceneObject +from .circleobject import CircleObject +from .ellipseobject import EllipseObject +from .frameobject import FrameObject +from .lineobject import LineObject +from .planeobject import PlaneObject +from .pointobject import PointObject +from .polygonobject import PolygonObject +from .polylineobject import PolylineObject +from .vectorobject import VectorObject + +from .boxobject import BoxObject +from .capsuleobject import CapsuleObject +from .coneobject import ConeObject +from .cylinderobject import CylinderObject +from .polyhedronobject import PolyhedronObject +from .sphereobject import SphereObject +from .torusobject import TorusObject + +from .meshobject import MeshObject +from .networkobject import NetworkObject +from .volmeshobject import VolMeshObject + +from .curveobject import CurveObject +from .surfaceobject import SurfaceObject +from .brepobject import BrepObject + + +@plugin(category="drawing-utils", pluggable_name="clear", requires=["Rhino"]) +def clear_rhino(): + compas_rhino.clear() + + +@plugin(category="drawing-utils", pluggable_name="redraw", requires=["Rhino"]) +def redraw_rhino(): + compas_rhino.redraw() + + +@plugin(category="factories", requires=["Rhino"]) +def register_scene_objects(): + SceneObject.register(Circle, CircleObject, context="Rhino") + SceneObject.register(Ellipse, EllipseObject, context="Rhino") + SceneObject.register(Frame, FrameObject, context="Rhino") + SceneObject.register(Line, LineObject, context="Rhino") + SceneObject.register(Plane, PlaneObject, context="Rhino") + SceneObject.register(Point, PointObject, context="Rhino") + SceneObject.register(Polygon, PolygonObject, context="Rhino") + SceneObject.register(Polyline, PolylineObject, context="Rhino") + SceneObject.register(Vector, VectorObject, context="Rhino") + SceneObject.register(Box, BoxObject, context="Rhino") + SceneObject.register(Capsule, CapsuleObject, context="Rhino") + SceneObject.register(Cone, ConeObject, context="Rhino") + SceneObject.register(Cylinder, CylinderObject, context="Rhino") + SceneObject.register(Polyhedron, PolyhedronObject, context="Rhino") + SceneObject.register(Sphere, SphereObject, context="Rhino") + SceneObject.register(Torus, TorusObject, context="Rhino") + SceneObject.register(Mesh, MeshObject, context="Rhino") + SceneObject.register(Network, NetworkObject, context="Rhino") + SceneObject.register(VolMesh, VolMeshObject, context="Rhino") + SceneObject.register(Curve, CurveObject, context="Rhino") + SceneObject.register(Surface, SurfaceObject, context="Rhino") + SceneObject.register(Brep, BrepObject, context="Rhino") + print("Rhino SceneObjects registered.") + + +__all__ = [ + "RhinoSceneObject", + "CircleObject", + "EllipseObject", + "FrameObject", + "LineObject", + "PlaneObject", + "PointObject", + "PolygonObject", + "PolylineObject", + "VectorObject", + "BoxObject", + "CapsuleObject", + "ConeObject", + "CylinderObject", + "PolyhedronObject", + "SphereObject", + "TorusObject", + "MeshObject", + "NetworkObject", + "VolMeshObject", + "CurveObject", + "SurfaceObject", + "BrepObject", +] diff --git a/src/compas_rhino/artists/_helpers.py b/src/compas_rhino/scene/_helpers.py similarity index 100% rename from src/compas_rhino/artists/_helpers.py rename to src/compas_rhino/scene/_helpers.py diff --git a/src/compas_rhino/artists/boxartist.py b/src/compas_rhino/scene/boxobject.py similarity index 80% rename from src/compas_rhino/artists/boxartist.py rename to src/compas_rhino/scene/boxobject.py index e63e03abc12..54d5f0c3811 100644 --- a/src/compas_rhino/artists/boxartist.py +++ b/src/compas_rhino/scene/boxobject.py @@ -4,16 +4,16 @@ import scriptcontext as sc # type: ignore -from compas.artists import GeometryArtist +from compas.scene import GeometryObject from compas.colors import Color from compas_rhino.conversions import box_to_rhino from compas_rhino.conversions import transformation_to_rhino -from .artist import RhinoArtist +from .sceneobject import RhinoSceneObject from ._helpers import attributes -class BoxArtist(RhinoArtist, GeometryArtist): - """Artist for drawing box shapes. +class BoxObject(RhinoSceneObject, GeometryObject): + """Scene object for drawing box shapes. Parameters ---------- @@ -25,10 +25,10 @@ class BoxArtist(RhinoArtist, GeometryArtist): """ def __init__(self, box, **kwargs): - super(BoxArtist, self).__init__(geometry=box, **kwargs) + super(BoxObject, self).__init__(geometry=box, **kwargs) def draw(self, color=None): - """Draw the box associated with the artist. + """Draw the box associated with the scene object. Parameters ---------- diff --git a/src/compas_rhino/artists/brepartist.py b/src/compas_rhino/scene/brepobject.py similarity index 82% rename from src/compas_rhino/artists/brepartist.py rename to src/compas_rhino/scene/brepobject.py index 8eb01633819..29b8d4f5ba6 100644 --- a/src/compas_rhino/artists/brepartist.py +++ b/src/compas_rhino/scene/brepobject.py @@ -7,13 +7,13 @@ from compas.colors import Color from compas_rhino.conversions import brep_to_rhino from compas_rhino.conversions import transformation_to_rhino -from compas.artists import GeometryArtist -from .artist import RhinoArtist +from compas.scene import GeometryObject +from .sceneobject import RhinoSceneObject from ._helpers import attributes -class BrepArtist(RhinoArtist, GeometryArtist): - """An artist for drawing a RhinoBrep. +class BrepObject(RhinoSceneObject, GeometryObject): + """A scene object for drawing a RhinoBrep. Parameters ---------- @@ -23,7 +23,7 @@ class BrepArtist(RhinoArtist, GeometryArtist): """ def __init__(self, brep, **kwargs): - super(BrepArtist, self).__init__(geometry=brep, **kwargs) + super(BrepObject, self).__init__(geometry=brep, **kwargs) def draw(self, color=None): """Bakes the Brep into the current document diff --git a/src/compas_rhino/artists/capsuleartist.py b/src/compas_rhino/scene/capsuleobject.py similarity index 81% rename from src/compas_rhino/artists/capsuleartist.py rename to src/compas_rhino/scene/capsuleobject.py index e85e2159459..3e55cf49cba 100644 --- a/src/compas_rhino/artists/capsuleartist.py +++ b/src/compas_rhino/scene/capsuleobject.py @@ -4,16 +4,16 @@ import scriptcontext as sc # type: ignore -from compas.artists import GeometryArtist +from compas.scene import GeometryObject from compas.colors import Color from compas_rhino.conversions import capsule_to_rhino_brep from compas_rhino.conversions import transformation_to_rhino -from .artist import RhinoArtist +from .sceneobject import RhinoSceneObject from ._helpers import attributes -class CapsuleArtist(RhinoArtist, GeometryArtist): - """Artist for drawing capsule shapes. +class CapsuleObject(RhinoSceneObject, GeometryObject): + """Scene object for drawing capsule shapes. Parameters ---------- @@ -25,10 +25,10 @@ class CapsuleArtist(RhinoArtist, GeometryArtist): """ def __init__(self, capsule, **kwargs): - super(CapsuleArtist, self).__init__(geometry=capsule, **kwargs) + super(CapsuleObject, self).__init__(geometry=capsule, **kwargs) def draw(self, color=None): - """Draw the capsule associated with the artist. + """Draw the capsule associated with the scene object. Parameters ---------- diff --git a/src/compas_rhino/artists/circleartist.py b/src/compas_rhino/scene/circleobject.py similarity index 84% rename from src/compas_rhino/artists/circleartist.py rename to src/compas_rhino/scene/circleobject.py index f438e4dc4c7..a8a8ad7c6db 100644 --- a/src/compas_rhino/artists/circleartist.py +++ b/src/compas_rhino/scene/circleobject.py @@ -4,18 +4,18 @@ import scriptcontext as sc # type: ignore -from compas.artists import GeometryArtist +from compas.scene import GeometryObject from compas.colors import Color from compas_rhino.conversions import circle_to_rhino # from compas_rhino.conversions import point_to_rhino from compas_rhino.conversions import transformation_to_rhino -from .artist import RhinoArtist +from .sceneobject import RhinoSceneObject from ._helpers import attributes -class CircleArtist(RhinoArtist, GeometryArtist): - """Artist for drawing circles. +class CircleObject(RhinoSceneObject, GeometryObject): + """Scene object for drawing circles. Parameters ---------- @@ -27,7 +27,7 @@ class CircleArtist(RhinoArtist, GeometryArtist): """ def __init__(self, circle, **kwargs): - super(CircleArtist, self).__init__(geometry=circle, **kwargs) + super(CircleObject, self).__init__(geometry=circle, **kwargs) def draw(self, color=None): """Draw the circle. diff --git a/src/compas_rhino/artists/coneartist.py b/src/compas_rhino/scene/coneobject.py similarity index 79% rename from src/compas_rhino/artists/coneartist.py rename to src/compas_rhino/scene/coneobject.py index 786a3c65299..9123305130c 100644 --- a/src/compas_rhino/artists/coneartist.py +++ b/src/compas_rhino/scene/coneobject.py @@ -4,16 +4,16 @@ import scriptcontext as sc # type: ignore -from compas.artists import GeometryArtist +from compas.scene import GeometryObject from compas.colors import Color from compas_rhino.conversions import cone_to_rhino_brep from compas_rhino.conversions import transformation_to_rhino -from .artist import RhinoArtist +from .sceneobject import RhinoSceneObject from ._helpers import attributes -class ConeArtist(RhinoArtist, GeometryArtist): - """Artist for drawing cone shapes. +class ConeObject(RhinoSceneObject, GeometryObject): + """Scene object for drawing cone shapes. Parameters ---------- @@ -25,10 +25,10 @@ class ConeArtist(RhinoArtist, GeometryArtist): """ def __init__(self, cone, **kwargs): - super(ConeArtist, self).__init__(geometry=cone, **kwargs) + super(ConeObject, self).__init__(geometry=cone, **kwargs) def draw(self, color=None): - """Draw the cone associated with the artist. + """Draw the cone associated with the scene object. Parameters ---------- diff --git a/src/compas_rhino/artists/curveartist.py b/src/compas_rhino/scene/curveobject.py similarity index 83% rename from src/compas_rhino/artists/curveartist.py rename to src/compas_rhino/scene/curveobject.py index e07d65586b2..30fcce1c4bb 100644 --- a/src/compas_rhino/artists/curveartist.py +++ b/src/compas_rhino/scene/curveobject.py @@ -4,16 +4,16 @@ import scriptcontext as sc # type: ignore -from compas.artists import GeometryArtist +from compas.scene import GeometryObject from compas.colors import Color from compas_rhino.conversions import curve_to_rhino from compas_rhino.conversions import transformation_to_rhino -from .artist import RhinoArtist +from .sceneobject import RhinoSceneObject from ._helpers import attributes -class CurveArtist(RhinoArtist, GeometryArtist): - """Artist for drawing curves. +class CurveObject(RhinoSceneObject, GeometryObject): + """Scene object for drawing curves. Parameters ---------- @@ -25,7 +25,7 @@ class CurveArtist(RhinoArtist, GeometryArtist): """ def __init__(self, curve, **kwargs): - super(CurveArtist, self).__init__(geometry=curve, **kwargs) + super(CurveObject, self).__init__(geometry=curve, **kwargs) def draw(self, color=None): """Draw the curve. diff --git a/src/compas_rhino/artists/cylinderartist.py b/src/compas_rhino/scene/cylinderobject.py similarity index 79% rename from src/compas_rhino/artists/cylinderartist.py rename to src/compas_rhino/scene/cylinderobject.py index 80345b70916..f9e726af3fa 100644 --- a/src/compas_rhino/artists/cylinderartist.py +++ b/src/compas_rhino/scene/cylinderobject.py @@ -4,16 +4,16 @@ import scriptcontext as sc # type: ignore -from compas.artists import GeometryArtist +from compas.scene import GeometryObject from compas.colors import Color from compas_rhino.conversions import cylinder_to_rhino_brep from compas_rhino.conversions import transformation_to_rhino -from .artist import RhinoArtist +from .sceneobject import RhinoSceneObject from ._helpers import attributes -class CylinderArtist(RhinoArtist, GeometryArtist): - """Artist for drawing cylinder shapes. +class CylinderObject(RhinoSceneObject, GeometryObject): + """Scene object for drawing cylinder shapes. Parameters ---------- @@ -25,10 +25,10 @@ class CylinderArtist(RhinoArtist, GeometryArtist): """ def __init__(self, cylinder, **kwargs): - super(CylinderArtist, self).__init__(geometry=cylinder, **kwargs) + super(CylinderObject, self).__init__(geometry=cylinder, **kwargs) def draw(self, color=None): - """Draw the cylinder associated with the artist. + """Draw the cylinder associated with the scene object. Parameters ---------- diff --git a/src/compas_rhino/artists/ellipseartist.py b/src/compas_rhino/scene/ellipseobject.py similarity index 69% rename from src/compas_rhino/artists/ellipseartist.py rename to src/compas_rhino/scene/ellipseobject.py index ab6cebaa999..4a7d9ce678c 100644 --- a/src/compas_rhino/artists/ellipseartist.py +++ b/src/compas_rhino/scene/ellipseobject.py @@ -4,17 +4,17 @@ import scriptcontext as sc # type: ignore -from compas.artists import GeometryArtist +from compas.scene import GeometryObject from compas.colors import Color from compas_rhino.conversions import ellipse_to_rhino from compas_rhino.conversions import transformation_to_rhino -from .artist import RhinoArtist +from .sceneobject import RhinoSceneObject from ._helpers import attributes -class EllipseArtist(RhinoArtist, GeometryArtist): - """Artist for drawing ellipses. +class EllipseObject(RhinoSceneObject, GeometryObject): + """Scene object for drawing ellipses. Parameters ---------- @@ -26,7 +26,7 @@ class EllipseArtist(RhinoArtist, GeometryArtist): """ def __init__(self, ellipse, **kwargs): - super(EllipseArtist, self).__init__(geometry=ellipse, **kwargs) + super(EllipseObject, self).__init__(geometry=ellipse, **kwargs) def draw(self, color=None): """Draw the ellipse. @@ -45,9 +45,10 @@ def draw(self, color=None): color = Color.coerce(color) or self.color attr = attributes(name=self.geometry.name, color=color, layer=self.layer) - geometry = ellipse_to_rhino(self.geometry) + ellipse = ellipse_to_rhino(self.geometry) + ellipse = ellipse.ToNurbsCurve() if self.transformation: - geometry.Transform(transformation_to_rhino(self.transformation)) + ellipse.Transform(transformation_to_rhino(self.transformation)) - return sc.doc.Objects.AddEllipse(geometry, attr) + return sc.doc.Objects.AddCurve(ellipse, attr) diff --git a/src/compas_rhino/artists/frameartist.py b/src/compas_rhino/scene/frameobject.py similarity index 81% rename from src/compas_rhino/artists/frameartist.py rename to src/compas_rhino/scene/frameobject.py index e0277e0896b..7e5f4fcac47 100644 --- a/src/compas_rhino/artists/frameartist.py +++ b/src/compas_rhino/scene/frameobject.py @@ -4,15 +4,16 @@ import scriptcontext as sc # type: ignore -from compas.artists import GeometryArtist +from compas.scene import GeometryObject from compas.colors import Color from compas_rhino.conversions import point_to_rhino -from .artist import RhinoArtist +from compas_rhino.conversions import transformation_to_rhino +from .sceneobject import RhinoSceneObject from ._helpers import attributes -class FrameArtist(RhinoArtist, GeometryArtist): - """Artist for drawing frames. +class FrameObject(RhinoSceneObject, GeometryObject): + """Scene object for drawing frames. Parameters ---------- @@ -40,7 +41,7 @@ class FrameArtist(RhinoArtist, GeometryArtist): """ def __init__(self, frame, scale=1.0, **kwargs): - super(FrameArtist, self).__init__(geometry=frame, **kwargs) + super(FrameObject, self).__init__(geometry=frame, **kwargs) self.scale = scale or 1.0 self.color_origin = Color.black() self.color_xaxis = Color.red() @@ -88,4 +89,12 @@ def draw(self): self.add_to_group("Frame.{}".format(self.geometry.name), guids) + if self.transformation: + transformation = transformation_to_rhino(self.transformation) + for guid in guids: + obj = sc.doc.Objects.Find(guid) + if obj: + obj.Geometry.Transform(transformation) + obj.CommitChanges() + return guids diff --git a/src/compas_rhino/artists/lineartist.py b/src/compas_rhino/scene/lineobject.py similarity index 72% rename from src/compas_rhino/artists/lineartist.py rename to src/compas_rhino/scene/lineobject.py index 2e23039a84e..f5805147dc0 100644 --- a/src/compas_rhino/artists/lineartist.py +++ b/src/compas_rhino/scene/lineobject.py @@ -4,15 +4,16 @@ import scriptcontext as sc # type: ignore -from compas.artists import GeometryArtist +from compas.scene import GeometryObject from compas.colors import Color from compas_rhino.conversions import line_to_rhino -from .artist import RhinoArtist +from compas_rhino.conversions import transformation_to_rhino +from .sceneobject import RhinoSceneObject from ._helpers import attributes -class LineArtist(RhinoArtist, GeometryArtist): - """Artist for drawing lines. +class LineObject(RhinoSceneObject, GeometryObject): + """Scene object for drawing lines. Parameters ---------- @@ -24,7 +25,7 @@ class LineArtist(RhinoArtist, GeometryArtist): """ def __init__(self, line, **kwargs): - super(LineArtist, self).__init__(geometry=line, **kwargs) + super(LineObject, self).__init__(geometry=line, **kwargs) def draw(self, color=None): """Draw the line. @@ -44,5 +45,7 @@ def draw(self, color=None): attr = attributes(name=self.geometry.name, color=color, layer=self.layer) geometry = line_to_rhino(self.geometry) + if self.transformation: + geometry.Transform(transformation_to_rhino(self.transformation)) return sc.doc.Objects.AddLine(geometry, attr) diff --git a/src/compas_rhino/artists/meshartist.py b/src/compas_rhino/scene/meshobject.py similarity index 95% rename from src/compas_rhino/artists/meshartist.py rename to src/compas_rhino/scene/meshobject.py index 73c4c8b4b09..31a4c7aa6cd 100644 --- a/src/compas_rhino/artists/meshartist.py +++ b/src/compas_rhino/scene/meshobject.py @@ -12,7 +12,7 @@ from compas.geometry import Sphere import compas_rhino -from compas.artists import MeshArtist as BaseArtist +from compas.scene import MeshObject as BaseMeshObject from compas.colors import Color from compas_rhino.conversions import vertices_and_faces_to_rhino from compas_rhino.conversions import mesh_to_rhino @@ -21,13 +21,13 @@ from compas_rhino.conversions import cylinder_to_rhino_brep from compas_rhino.conversions import sphere_to_rhino from compas_rhino.conversions import transformation_to_rhino -from .artist import RhinoArtist +from .sceneobject import RhinoSceneObject from ._helpers import attributes from ._helpers import ngon -class MeshArtist(RhinoArtist, BaseArtist): - """Artists for drawing mesh data structures. +class MeshObject(RhinoSceneObject, BaseMeshObject): + """Scene object for drawing mesh data structures. Parameters ---------- @@ -39,14 +39,14 @@ class MeshArtist(RhinoArtist, BaseArtist): """ def __init__(self, mesh, **kwargs): - super(MeshArtist, self).__init__(mesh=mesh, **kwargs) + super(MeshObject, self).__init__(mesh=mesh, **kwargs) # ========================================================================== # clear # ========================================================================== def clear(self): - """Delete all objects drawn by this artist. + """Delete all objects drawn by this scene object. Returns ------- @@ -57,7 +57,7 @@ def clear(self): compas_rhino.delete_objects(guids, purge=True) def clear_vertices(self): - """Delete all vertices drawn by this artist. + """Delete all vertices drawn by this scene object. Returns ------- @@ -68,7 +68,7 @@ def clear_vertices(self): compas_rhino.delete_objects(guids, purge=True) def clear_edges(self): - """Delete all edges drawn by this artist. + """Delete all edges drawn by this scene object. Returns ------- @@ -79,7 +79,7 @@ def clear_edges(self): compas_rhino.delete_objects(guids, purge=True) def clear_faces(self): - """Delete all faces drawn by this artist. + """Delete all faces drawn by this scene object. Returns ------- @@ -90,7 +90,7 @@ def clear_faces(self): compas_rhino.delete_objects(guids, purge=True) def clear_vertexnormals(self): - """Delete all vertex normals drawn by this artist. + """Delete all vertex normals drawn by this scene object. Returns ------- @@ -101,7 +101,7 @@ def clear_vertexnormals(self): compas_rhino.delete_objects(guids, purge=True) def clear_facenormals(self): - """Delete all face normals drawn by this artist. + """Delete all face normals drawn by this scene object. Returns ------- @@ -112,7 +112,7 @@ def clear_facenormals(self): compas_rhino.delete_objects(guids, purge=True) def clear_vertexlabels(self): - """Delete all vertex labels drawn by this artist. + """Delete all vertex labels drawn by this scene object. Returns ------- @@ -123,7 +123,7 @@ def clear_vertexlabels(self): compas_rhino.delete_objects(guids, purge=True) def clear_edgelabels(self): - """Delete all edge labels drawn by this artist. + """Delete all edge labels drawn by this scene object. Returns ------- @@ -134,7 +134,7 @@ def clear_edgelabels(self): compas_rhino.delete_objects(guids, purge=True) def clear_facelabels(self): - """Delete all face labels drawn by this artist. + """Delete all face labels drawn by this scene object. Returns ------- @@ -155,7 +155,7 @@ def draw(self, color=None, vertexcolors=None, facecolors=None, disjoint=False): ---------- color : tuple[int, int, int], optional The color of the mesh. - Default is the value of :attr:`MeshArtist.default_color`. + Default is the value of :attr:`MeshObject.default_color`. disjoint : bool, optional If True, draw the faces of the mesh with disjoint vertices. diff --git a/src/compas_rhino/artists/networkartist.py b/src/compas_rhino/scene/networkobject.py similarity index 96% rename from src/compas_rhino/artists/networkartist.py rename to src/compas_rhino/scene/networkobject.py index ef7b604b5ac..1bad68c82ba 100644 --- a/src/compas_rhino/artists/networkartist.py +++ b/src/compas_rhino/scene/networkobject.py @@ -9,17 +9,17 @@ from compas.geometry import Line from compas.geometry import Cylinder from compas.geometry import Sphere -from compas.artists import NetworkArtist as BaseArtist +from compas.scene import NetworkObject as BaseNetworkObject from compas_rhino.conversions import point_to_rhino from compas_rhino.conversions import line_to_rhino from compas_rhino.conversions import sphere_to_rhino from compas_rhino.conversions import cylinder_to_rhino_brep -from .artist import RhinoArtist +from .sceneobject import RhinoSceneObject from ._helpers import attributes -class NetworkArtist(RhinoArtist, BaseArtist): - """Artist for drawing network data structures. +class NetworkObject(RhinoSceneObject, BaseNetworkObject): + """Scene object for drawing network data structures. Parameters ---------- @@ -31,14 +31,14 @@ class NetworkArtist(RhinoArtist, BaseArtist): """ def __init__(self, network, **kwargs): - super(NetworkArtist, self).__init__(network=network, **kwargs) + super(NetworkObject, self).__init__(network=network, **kwargs) # ========================================================================== # clear # ========================================================================== def clear(self): - """Delete all objects drawn by this artist. + """Delete all objects drawn by this scene object. Returns ------- @@ -49,7 +49,7 @@ def clear(self): compas_rhino.delete_objects(guids, purge=True) def clear_nodes(self): - """Delete all nodes drawn by this artist. + """Delete all nodes drawn by this scene object. Returns ------- @@ -60,7 +60,7 @@ def clear_nodes(self): compas_rhino.delete_objects(guids, purge=True) def clear_edges(self): - """Delete all edges drawn by this artist. + """Delete all edges drawn by this scene object. Returns ------- diff --git a/src/compas_rhino/artists/planeartist.py b/src/compas_rhino/scene/planeobject.py similarity index 69% rename from src/compas_rhino/artists/planeartist.py rename to src/compas_rhino/scene/planeobject.py index fea059e7d83..fa4e8967dd7 100644 --- a/src/compas_rhino/artists/planeartist.py +++ b/src/compas_rhino/scene/planeobject.py @@ -2,12 +2,12 @@ from __future__ import absolute_import from __future__ import division -from compas.artists import GeometryArtist -from .artist import RhinoArtist +from compas.scene import GeometryObject +from .sceneobject import RhinoSceneObject -class PlaneArtist(RhinoArtist, GeometryArtist): - """Artist for drawing planes. +class PlaneObject(RhinoSceneObject, GeometryObject): + """Scene object for drawing planes. Parameters ---------- @@ -19,7 +19,7 @@ class PlaneArtist(RhinoArtist, GeometryArtist): """ def __init__(self, plane, **kwargs): - super(PlaneArtist, self).__init__(geometry=plane, **kwargs) + super(PlaneObject, self).__init__(geometry=plane, **kwargs) def draw(self): """Draw the plane. diff --git a/src/compas_rhino/artists/pointartist.py b/src/compas_rhino/scene/pointobject.py similarity index 64% rename from src/compas_rhino/artists/pointartist.py rename to src/compas_rhino/scene/pointobject.py index b551f13f42c..5a7655aa755 100644 --- a/src/compas_rhino/artists/pointartist.py +++ b/src/compas_rhino/scene/pointobject.py @@ -4,15 +4,16 @@ import scriptcontext as sc # type: ignore -from compas.artists import GeometryArtist +from compas.scene import GeometryObject from compas.colors import Color from compas_rhino.conversions import point_to_rhino -from .artist import RhinoArtist +from compas_rhino.conversions import transformation_to_rhino +from .sceneobject import RhinoSceneObject from ._helpers import attributes -class PointArtist(RhinoArtist, GeometryArtist): - """Artist for drawing points. +class PointObject(RhinoSceneObject, GeometryObject): + """Scene object for drawing points. Parameters ---------- @@ -24,7 +25,7 @@ class PointArtist(RhinoArtist, GeometryArtist): """ def __init__(self, point, **kwargs): - super(PointArtist, self).__init__(geometry=point, **kwargs) + super(PointObject, self).__init__(geometry=point, **kwargs) def draw(self, color=None): """Draw the point. @@ -42,4 +43,7 @@ def draw(self, color=None): """ color = Color.coerce(color) or self.color attr = attributes(name=self.geometry.name, color=color, layer=self.layer) - return sc.doc.Objects.AddPoint(point_to_rhino(self.geometry), attr) + geometry = point_to_rhino(self.geometry) + if self.transformation: + geometry.Transform(transformation_to_rhino(self.transformation)) + return sc.doc.Objects.AddPoint(geometry, attr) diff --git a/src/compas_rhino/artists/polygonartist.py b/src/compas_rhino/scene/polygonobject.py similarity index 86% rename from src/compas_rhino/artists/polygonartist.py rename to src/compas_rhino/scene/polygonobject.py index 89d3a72a1cd..68520e648b3 100644 --- a/src/compas_rhino/artists/polygonartist.py +++ b/src/compas_rhino/scene/polygonobject.py @@ -4,17 +4,18 @@ import scriptcontext as sc # type: ignore -from compas.artists import GeometryArtist +from compas.scene import GeometryObject from compas.colors import Color from compas_rhino.conversions import point_to_rhino from compas_rhino.conversions import line_to_rhino from compas_rhino.conversions import vertices_and_faces_to_rhino -from .artist import RhinoArtist +from compas_rhino.conversions import transformation_to_rhino +from .sceneobject import RhinoSceneObject from ._helpers import attributes -class PolygonArtist(RhinoArtist, GeometryArtist): - """Artist for drawing polygons. +class PolygonObject(RhinoSceneObject, GeometryObject): + """Scene object for drawing polygons. Parameters ---------- @@ -26,7 +27,7 @@ class PolygonArtist(RhinoArtist, GeometryArtist): """ def __init__(self, polygon, **kwargs): - super(PolygonArtist, self).__init__(geometry=polygon, **kwargs) + super(PolygonObject, self).__init__(geometry=polygon, **kwargs) def draw(self, color=None): """Draw the polygon. @@ -48,6 +49,8 @@ def draw(self, color=None): vertices = self.geometry.points faces = self.geometry.faces mesh = vertices_and_faces_to_rhino(vertices, faces) + if self.transformation: + mesh.Transform(transformation_to_rhino(self.transformation)) return sc.doc.Objects.AddMesh(mesh, attr) diff --git a/src/compas_rhino/artists/polyhedronartist.py b/src/compas_rhino/scene/polyhedronobject.py similarity index 64% rename from src/compas_rhino/artists/polyhedronartist.py rename to src/compas_rhino/scene/polyhedronobject.py index cc70ee21ab6..fa10f2dbd48 100644 --- a/src/compas_rhino/artists/polyhedronartist.py +++ b/src/compas_rhino/scene/polyhedronobject.py @@ -4,15 +4,16 @@ import scriptcontext as sc # type: ignore -from compas.artists import GeometryArtist +from compas.scene import GeometryObject from compas.colors import Color from compas_rhino.conversions import vertices_and_faces_to_rhino -from .artist import RhinoArtist +from compas_rhino.conversions import transformation_to_rhino +from .sceneobject import RhinoSceneObject from ._helpers import attributes -class PolyhedronArtist(RhinoArtist, GeometryArtist): - """Artist for drawing polyhedron shapes. +class PolyhedronObject(RhinoSceneObject, GeometryObject): + """Scene object for drawing polyhedron shapes. Parameters ---------- @@ -24,10 +25,10 @@ class PolyhedronArtist(RhinoArtist, GeometryArtist): """ def __init__(self, polyhedron, **kwargs): - super(PolyhedronArtist, self).__init__(geometry=polyhedron, **kwargs) + super(PolyhedronObject, self).__init__(geometry=polyhedron, **kwargs) def draw(self, color=None): - """Draw the polyhedron associated with the artist. + """Draw the polyhedron associated with the scene object. Parameters ---------- @@ -45,5 +46,8 @@ def draw(self, color=None): vertices = [list(vertex) for vertex in self.geometry.vertices] faces = self.geometry.faces + geometry = vertices_and_faces_to_rhino(vertices, faces) + if self.transformation: + geometry.Transform(transformation_to_rhino(self.transformation)) - return sc.doc.Objects.AddMesh(vertices_and_faces_to_rhino(vertices, faces), attr) + return sc.doc.Objects.AddMesh(geometry, attr) diff --git a/src/compas_rhino/artists/polylineartist.py b/src/compas_rhino/scene/polylineobject.py similarity index 76% rename from src/compas_rhino/artists/polylineartist.py rename to src/compas_rhino/scene/polylineobject.py index 00468c3ed3f..b783d4543e8 100644 --- a/src/compas_rhino/artists/polylineartist.py +++ b/src/compas_rhino/scene/polylineobject.py @@ -4,16 +4,17 @@ import scriptcontext as sc # type: ignore -from compas.artists import GeometryArtist +from compas.scene import GeometryObject from compas.colors import Color from compas_rhino.conversions import point_to_rhino from compas_rhino.conversions import polyline_to_rhino -from .artist import RhinoArtist +from compas_rhino.conversions import transformation_to_rhino +from .sceneobject import RhinoSceneObject from ._helpers import attributes -class PolylineArtist(RhinoArtist, GeometryArtist): - """Artist for drawing polylines. +class PolylineObject(RhinoSceneObject, GeometryObject): + """Scene object for drawing polylines. Parameters ---------- @@ -25,7 +26,7 @@ class PolylineArtist(RhinoArtist, GeometryArtist): """ def __init__(self, polyline, **kwargs): - super(PolylineArtist, self).__init__(geometry=polyline, **kwargs) + super(PolylineObject, self).__init__(geometry=polyline, **kwargs) def draw(self, color=None): """Draw the polyline. @@ -43,8 +44,11 @@ def draw(self, color=None): """ color = Color.coerce(color) or self.color attr = attributes(name=self.geometry.name, color=color, layer=self.layer) + geometry = polyline_to_rhino(self.geometry) + if self.transformation: + geometry.Transform(transformation_to_rhino(self.transformation)) - return sc.doc.Objects.AddPolyline(polyline_to_rhino(self.geometry), attr) + return sc.doc.Objects.AddPolyline(geometry, attr) def draw_points(self, color=None): """Draw the polyline points. diff --git a/src/compas_rhino/artists/artist.py b/src/compas_rhino/scene/sceneobject.py similarity index 86% rename from src/compas_rhino/artists/artist.py rename to src/compas_rhino/scene/sceneobject.py index 8ce1a31937e..5afb195b79e 100644 --- a/src/compas_rhino/artists/artist.py +++ b/src/compas_rhino/scene/sceneobject.py @@ -5,11 +5,11 @@ import scriptcontext as sc # type: ignore import compas_rhino -from compas.artists import Artist +from compas.scene import SceneObject -class RhinoArtist(Artist): - """Base class for all Rhino artists. +class RhinoSceneObject(SceneObject): + """Base class for all Rhino scene objects. Parameters ---------- @@ -21,7 +21,7 @@ class RhinoArtist(Artist): """ def __init__(self, layer=None, **kwargs): - super(RhinoArtist, self).__init__(**kwargs) + super(RhinoSceneObject, self).__init__(**kwargs) self.layer = layer def get_group(self, name): @@ -64,7 +64,7 @@ def add_to_group(self, name, guids): sc.doc.Groups.AddToGroup(group.Index, guids) def clear_layer(self): - """Clear the layer of the artist. + """Clear the layer of the scene object. Returns ------- diff --git a/src/compas_rhino/artists/sphereartist.py b/src/compas_rhino/scene/sphereobject.py similarity index 61% rename from src/compas_rhino/artists/sphereartist.py rename to src/compas_rhino/scene/sphereobject.py index e5a7bdc8718..d5e5cb27412 100644 --- a/src/compas_rhino/artists/sphereartist.py +++ b/src/compas_rhino/scene/sphereobject.py @@ -4,15 +4,16 @@ import scriptcontext as sc # type: ignore -from compas.artists import GeometryArtist +from compas.scene import GeometryObject from compas.colors import Color from compas_rhino.conversions import sphere_to_rhino -from .artist import RhinoArtist +from compas_rhino.conversions import transformation_to_rhino +from .sceneobject import RhinoSceneObject from ._helpers import attributes -class SphereArtist(RhinoArtist, GeometryArtist): - """Artist for drawing sphere shapes. +class SphereObject(RhinoSceneObject, GeometryObject): + """Scene object for drawing sphere shapes. Parameters ---------- @@ -24,10 +25,10 @@ class SphereArtist(RhinoArtist, GeometryArtist): """ def __init__(self, sphere, **kwargs): - super(SphereArtist, self).__init__(geometry=sphere, **kwargs) + super(SphereObject, self).__init__(geometry=sphere, **kwargs) def draw(self, color=None): - """Draw the sphere associated with the artist. + """Draw the sphere associated with the scene object. Parameters ---------- @@ -42,4 +43,8 @@ def draw(self, color=None): """ color = Color.coerce(color) or self.color attr = attributes(name=self.geometry.name, color=color, layer=self.layer) - return sc.doc.Objects.AddSphere(sphere_to_rhino(self.geometry), attr) + geometry = sphere_to_rhino(self.geometry) + if self.transformation: + geometry.Transform(transformation_to_rhino(self.transformation)) + + return sc.doc.Objects.AddSphere(geometry, attr) diff --git a/src/compas_rhino/artists/surfaceartist.py b/src/compas_rhino/scene/surfaceobject.py similarity index 72% rename from src/compas_rhino/artists/surfaceartist.py rename to src/compas_rhino/scene/surfaceobject.py index a03c542d5c5..a49bf2dccf6 100644 --- a/src/compas_rhino/artists/surfaceartist.py +++ b/src/compas_rhino/scene/surfaceobject.py @@ -4,15 +4,16 @@ import scriptcontext as sc # type: ignore -from compas.artists import GeometryArtist +from compas.scene import GeometryObject from compas.colors import Color from compas_rhino.conversions import surface_to_rhino -from .artist import RhinoArtist +from compas_rhino.conversions import transformation_to_rhino +from .sceneobject import RhinoSceneObject from ._helpers import attributes -class SurfaceArtist(RhinoArtist, GeometryArtist): - """Artist for drawing surfaces. +class SurfaceObject(RhinoSceneObject, GeometryObject): + """Scene object for drawing surfaces. Parameters ---------- @@ -24,7 +25,7 @@ class SurfaceArtist(RhinoArtist, GeometryArtist): """ def __init__(self, surface, **kwargs): - super(SurfaceArtist, self).__init__(geometry=surface, **kwargs) + super(SurfaceObject, self).__init__(geometry=surface, **kwargs) def draw(self, color=None): """Draw the surface. @@ -43,4 +44,6 @@ def draw(self, color=None): color = Color.coerce(color) or self.color attr = attributes(name=self.geometry.name, color=color, layer=self.layer) surface = surface_to_rhino(self.geometry) + if self.transformation: + surface.Transform(transformation_to_rhino(self.transformation)) return sc.doc.Objects.AddSurface(surface, attr) diff --git a/src/compas_rhino/artists/torusartist.py b/src/compas_rhino/scene/torusobject.py similarity index 68% rename from src/compas_rhino/artists/torusartist.py rename to src/compas_rhino/scene/torusobject.py index a532f5b34c1..662fb802040 100644 --- a/src/compas_rhino/artists/torusartist.py +++ b/src/compas_rhino/scene/torusobject.py @@ -4,15 +4,16 @@ import scriptcontext as sc # type: ignore -from compas.artists import GeometryArtist +from compas.scene import GeometryObject from compas.colors import Color from compas_rhino.conversions import torus_to_rhino_brep -from .artist import RhinoArtist +from compas_rhino.conversions import transformation_to_rhino +from .sceneobject import RhinoSceneObject from ._helpers import attributes -class TorusArtist(RhinoArtist, GeometryArtist): - """Artist for drawing torus shapes. +class TorusObject(RhinoSceneObject, GeometryObject): + """Scene object for drawing torus shapes. Parameters ---------- @@ -24,10 +25,10 @@ class TorusArtist(RhinoArtist, GeometryArtist): """ def __init__(self, torus, **kwargs): - super(TorusArtist, self).__init__(geometry=torus, **kwargs) + super(TorusObject, self).__init__(geometry=torus, **kwargs) def draw(self, color=None): - """Draw the torus associated with the artist. + """Draw the torus associated with the scene object. Parameters ---------- @@ -43,4 +44,7 @@ def draw(self, color=None): color = Color.coerce(color) or self.color attr = attributes(name=self.geometry.name, color=color, layer=self.layer) brep = torus_to_rhino_brep(self.geometry) + if self.transformation: + brep.Transform(transformation_to_rhino(self.transformation)) + return sc.doc.Objects.AddBrep(brep, attr) diff --git a/src/compas_rhino/artists/vectorartist.py b/src/compas_rhino/scene/vectorobject.py similarity index 65% rename from src/compas_rhino/artists/vectorartist.py rename to src/compas_rhino/scene/vectorobject.py index fd33ce79a87..9f68a13c362 100644 --- a/src/compas_rhino/artists/vectorartist.py +++ b/src/compas_rhino/scene/vectorobject.py @@ -5,15 +5,16 @@ import scriptcontext as sc # type: ignore from compas.geometry import Point -from compas.artists import GeometryArtist +from compas.scene import GeometryObject from compas.colors import Color from compas_rhino.conversions import point_to_rhino -from .artist import RhinoArtist +from compas_rhino.conversions import transformation_to_rhino +from .sceneobject import RhinoSceneObject from ._helpers import attributes -class VectorArtist(RhinoArtist, GeometryArtist): - """Artist for drawing vectors. +class VectorObject(RhinoSceneObject, GeometryObject): + """Scene object for drawing vectors. Parameters ---------- @@ -25,7 +26,7 @@ class VectorArtist(RhinoArtist, GeometryArtist): """ def __init__(self, vector, **kwargs): - super(VectorArtist, self).__init__(geometry=vector, **kwargs) + super(VectorObject, self).__init__(geometry=vector, **kwargs) def draw(self, color=None, point=None): """Draw the vector. @@ -50,5 +51,11 @@ def draw(self, color=None, point=None): point = point or [0, 0, 0] start = Point(*point) end = start + self.geometry - - return sc.doc.Objects.AddLine(point_to_rhino(start), point_to_rhino(end), attr) + start_geometry = point_to_rhino(start) + end_geometry = point_to_rhino(end) + if self.transformation: + transformation = transformation_to_rhino(self.transformation) + start_geometry.Transform(transformation) + end_geometry.Transform(transformation) + + return sc.doc.Objects.AddLine(start_geometry, end_geometry, attr) diff --git a/src/compas_rhino/artists/volmeshartist.py b/src/compas_rhino/scene/volmeshobject.py similarity index 95% rename from src/compas_rhino/artists/volmeshartist.py rename to src/compas_rhino/scene/volmeshobject.py index 360ac89f943..40c5bfdce3b 100644 --- a/src/compas_rhino/artists/volmeshartist.py +++ b/src/compas_rhino/scene/volmeshobject.py @@ -8,17 +8,17 @@ import compas_rhino from compas.geometry import centroid_points from compas.geometry import Line -from compas.artists import VolMeshArtist as BaseArtist +from compas.scene import VolMeshObject as BaseVolMeshObject from compas_rhino.conversions import point_to_rhino from compas_rhino.conversions import line_to_rhino from compas_rhino.conversions import vertices_and_faces_to_rhino -from .artist import RhinoArtist +from .sceneobject import RhinoSceneObject from ._helpers import attributes from ._helpers import ngon -class VolMeshArtist(RhinoArtist, BaseArtist): - """Artist for drawing volmesh data structures. +class VolMeshObject(RhinoSceneObject, BaseVolMeshObject): + """Scene object for drawing volmesh data structures. Parameters ---------- @@ -30,14 +30,14 @@ class VolMeshArtist(RhinoArtist, BaseArtist): """ def __init__(self, volmesh, **kwargs): - super(VolMeshArtist, self).__init__(volmesh=volmesh, **kwargs) + super(VolMeshObject, self).__init__(volmesh=volmesh, **kwargs) # ========================================================================== # clear # ========================================================================== def clear(self): - """Delete all objects drawn by this artist. + """Delete all objects drawn by this scene object. Returns ------- @@ -48,7 +48,7 @@ def clear(self): compas_rhino.delete_objects(guids, purge=True) def clear_vertices(self): - """Delete all vertices drawn by this artist. + """Delete all vertices drawn by this scene object. Returns ------- @@ -59,7 +59,7 @@ def clear_vertices(self): compas_rhino.delete_objects(guids, purge=True) def clear_edges(self): - """Delete all edges drawn by this artist. + """Delete all edges drawn by this scene object. Returns ------- @@ -70,7 +70,7 @@ def clear_edges(self): compas_rhino.delete_objects(guids, purge=True) def clear_faces(self): - """Delete all faces drawn by this artist. + """Delete all faces drawn by this scene object. Returns ------- @@ -81,7 +81,7 @@ def clear_faces(self): compas_rhino.delete_objects(guids, purge=True) def clear_cells(self): - """Delete all cells drawn by this artist. + """Delete all cells drawn by this scene object. Returns ------- @@ -92,7 +92,7 @@ def clear_cells(self): compas_rhino.delete_objects(guids, purge=True) def clear_vertexlabels(self): - """Delete all vertex labels drawn by this artist. + """Delete all vertex labels drawn by this scene object. Returns ------- @@ -103,7 +103,7 @@ def clear_vertexlabels(self): compas_rhino.delete_objects(guids, purge=True) def clear_edgelabels(self): - """Delete all edge labels drawn by this artist. + """Delete all edge labels drawn by this scene object. Returns ------- @@ -114,7 +114,7 @@ def clear_edgelabels(self): compas_rhino.delete_objects(guids, purge=True) def clear_facelabels(self): - """Delete all face labels drawn by this artist. + """Delete all face labels drawn by this scene object. Returns ------- @@ -138,7 +138,7 @@ def draw(self, cells=None, color=None): The default is None, in which case all cells are drawn. color : :class:`compas.colors.Color` | dict[int, :class:`compas.colors.Color`], optional The color of the cells. - The default color is :attr:`VolMeshArtist.default_cellcolor`. + The default color is :attr:`VolMeshObject.default_cellcolor`. Returns ------- diff --git a/tests/compas/artists/test_artists.py b/tests/compas/artists/test_artists.py deleted file mode 100644 index b6f693978bc..00000000000 --- a/tests/compas/artists/test_artists.py +++ /dev/null @@ -1,110 +0,0 @@ -import pytest # noqa: F401 - -import compas -from compas.artists import Artist -from compas.artists.artist import NoArtistContextError - - -if not compas.IPY: - - @pytest.fixture(autouse=True) - def reset_artists(): - # before each test - yield - # after each test, reset artists - Artist.ITEM_ARTIST.clear() - Artist._Artist__ARTISTS_REGISTERED = False # type: ignore - - -def register_fake_context(): - Artist.register(FakeItem, FakeArtist, context="fake") - - -class FakeArtist(Artist): - def draw(self): - pass - - -class FakeSubArtist(Artist): - def draw(self): - pass - - -class FakeItem(object): - pass - - -class FakeSubItem(FakeItem): - pass - - -def test_get_artist_cls_with_orderly_registration(): - Artist.register(FakeItem, FakeArtist, context="fake") - Artist.register(FakeSubItem, FakeSubArtist, context="fake") - item = FakeItem() - artist = Artist(item, context="fake") - assert isinstance(artist, FakeArtist) - - item = FakeSubItem() - artist = Artist(item, context="fake") - assert isinstance(artist, FakeSubArtist) - - -def test_get_artist_cls_with_out_of_order_registration(): - Artist.register(FakeSubItem, FakeSubArtist, context="fake") - Artist.register(FakeItem, FakeArtist, context="fake") - item = FakeItem() - artist = Artist(item, context="fake") - assert isinstance(artist, FakeArtist) - - item = FakeSubItem() - artist = Artist(item, context="fake") - assert isinstance(artist, FakeSubArtist) - - -if not compas.IPY: - - def test_artist_auto_context_discovery(mocker): - mocker.patch("compas.artists.Artist.register_artists") - Artist.register_artists.side_effect = register_fake_context - Artist._Artist__ARTISTS_REGISTERED = False # type: ignore - - item = FakeItem() - artist = Artist(item) - - assert isinstance(artist, FakeArtist) - - def test_artist_auto_context_discovery_viewer(mocker): - mocker.patch("compas.artists.artist.is_viewer_open", return_value=True) - Artist.ITEM_ARTIST["Viewer"] = {FakeItem: FakeArtist} - - item = FakeSubItem() - artist = Artist(item) - - assert isinstance(artist, FakeArtist) - - def test_artist_auto_context_discovery_viewer_priority(mocker): - mocker.patch("compas.artists.artist.is_viewer_open", return_value=True) - - class FakeViewerArtist(FakeArtist): - pass - - class FakePlotterArtist(FakeArtist): - pass - - Artist.ITEM_ARTIST["Viewer"] = {FakeItem: FakeViewerArtist} - Artist.ITEM_ARTIST["Plotter"] = {FakeItem: FakePlotterArtist} - - item = FakeSubItem() - artist = Artist(item) - - assert isinstance(artist, FakeViewerArtist) - - def test_artist_auto_context_discovery_no_context(mocker): - mocker.patch("compas.artists.artist.is_viewer_open", return_value=False) - mocker.patch("compas.artists.artist.compas.is_grasshopper", return_value=False) - mocker.patch("compas.artists.artist.compas.is_rhino", return_value=False) - - with pytest.raises(NoArtistContextError): - item = FakeSubItem() - _ = Artist(item) diff --git a/tests/compas/scene/test_scene.py b/tests/compas/scene/test_scene.py new file mode 100644 index 00000000000..18ab4252086 --- /dev/null +++ b/tests/compas/scene/test_scene.py @@ -0,0 +1,110 @@ +import pytest # noqa: F401 + +import compas +from compas.scene import SceneObject +from compas.scene import NoSceneObjectContextError + + +if not compas.IPY: + + @pytest.fixture(autouse=True) + def reset_sceneobjects(): + # before each test + yield + # after each test, reset scene objects + SceneObject.ITEM_SCENEOBJECT.clear() + SceneObject._SceneObject__SCENEOBJECTS_REGISTERED = False # type: ignore + + +def register_fake_context(): + SceneObject.register(FakeItem, FakeSceneObject, context="fake") + + +class FakeSceneObject(SceneObject): + def draw(self): + pass + + +class FakeSubSceneObject(SceneObject): + def draw(self): + pass + + +class FakeItem(object): + pass + + +class FakeSubItem(FakeItem): + pass + + +def test_get_sceneobject_cls_with_orderly_registration(): + SceneObject.register(FakeItem, FakeSceneObject, context="fake") + SceneObject.register(FakeSubItem, FakeSubSceneObject, context="fake") + item = FakeItem() + sceneobject = SceneObject(item, context="fake") + assert isinstance(sceneobject, FakeSceneObject) + + item = FakeSubItem() + sceneobject = SceneObject(item, context="fake") + assert isinstance(sceneobject, FakeSubSceneObject) + + +def test_get_sceneobject_cls_with_out_of_order_registration(): + SceneObject.register(FakeSubItem, FakeSubSceneObject, context="fake") + SceneObject.register(FakeItem, FakeSceneObject, context="fake") + item = FakeItem() + sceneobject = SceneObject(item, context="fake") + assert isinstance(sceneobject, FakeSceneObject) + + item = FakeSubItem() + sceneobject = SceneObject(item, context="fake") + assert isinstance(sceneobject, FakeSubSceneObject) + + +if not compas.IPY: + + def test_sceneobject_auto_context_discovery(mocker): + mocker.patch("compas.scene.SceneObject.register_scene_objects") + SceneObject.register_scene_objects.side_effect = register_fake_context + SceneObject._SceneObject__SCENEOBJECTS_REGISTERED = False # type: ignore + + item = FakeItem() + sceneobject = SceneObject(item) + + assert isinstance(sceneobject, FakeSceneObject) + + def test_sceneobject_auto_context_discovery_viewer(mocker): + mocker.patch("compas.scene.sceneobject.is_viewer_open", return_value=True) + SceneObject.ITEM_SCENEOBJECT["Viewer"] = {FakeItem: FakeSceneObject} + + item = FakeSubItem() + sceneobject = SceneObject(item) + + assert isinstance(sceneobject, FakeSceneObject) + + def test_sceneobject_auto_context_discovery_viewer_priority(mocker): + mocker.patch("compas.scene.sceneobject.is_viewer_open", return_value=True) + + class FakeViewerSceneObject(FakeSceneObject): + pass + + class FakePlotterSceneObject(FakeSceneObject): + pass + + SceneObject.ITEM_SCENEOBJECT["Viewer"] = {FakeItem: FakeViewerSceneObject} + SceneObject.ITEM_SCENEOBJECT["Plotter"] = {FakeItem: FakePlotterSceneObject} + + item = FakeSubItem() + sceneobject = SceneObject(item) + + assert isinstance(sceneobject, FakeViewerSceneObject) + + def test_sceneobject_auto_context_discovery_no_context(mocker): + mocker.patch("compas.scene.sceneobject.is_viewer_open", return_value=False) + mocker.patch("compas.scene.sceneobject.compas.is_grasshopper", return_value=False) + mocker.patch("compas.scene.sceneobject.compas.is_rhino", return_value=False) + + with pytest.raises(NoSceneObjectContextError): + item = FakeSubItem() + _ = SceneObject(item) diff --git a/tests/compas/stubs.py b/tests/compas/stubs.py index 796725f30d6..bcd330aa34b 100644 --- a/tests/compas/stubs.py +++ b/tests/compas/stubs.py @@ -8,7 +8,7 @@ def compas_api(): modules = [ - "compas.artists", + "compas.scene", "compas.data", "compas.datastructures", "compas.files",