Skip to content

Commit fe9e997

Browse files
committed
rhino shapes on par with blender implementation
1 parent b0588db commit fe9e997

File tree

5 files changed

+56
-154
lines changed

5 files changed

+56
-154
lines changed

src/compas_rhino/artists/coneartist.py

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from __future__ import absolute_import
33
from __future__ import division
44

5-
from compas.utilities import pairwise
65
import compas_rhino
76
from compas.artists import ShapeArtist
87
from .artist import RhinoArtist
@@ -23,50 +22,30 @@ class ConeArtist(RhinoArtist, ShapeArtist):
2322
def __init__(self, cone, layer=None, **kwargs):
2423
super(ConeArtist, self).__init__(shape=cone, layer=layer, **kwargs)
2524

26-
def draw(self, u=None, show_vertices=False, show_edges=False, show_faces=True, join_faces=True):
25+
def draw(self, color=None, u=None):
2726
"""Draw the cone associated with the artist.
2827
2928
Parameters
3029
----------
30+
color : tuple of float, optional
31+
The RGB color of the cone.
3132
u : int, optional
3233
Number of faces in the "u" direction.
3334
Default is ``~ConeArtist.u``.
34-
show_vertices : bool, optional
35-
Default is ``False``.
36-
show_edges : bool, optional
37-
Default is ``False``.
38-
show_faces : bool, optional
39-
Default is ``True``.
40-
join_faces : bool, optional
41-
Default is ``True``.
4235
4336
Returns
4437
-------
4538
list
4639
The GUIDs of the objects created in Rhino.
4740
"""
41+
color = color or self.color
4842
u = u or self.u
4943
vertices, faces = self.shape.to_vertices_and_faces(u=u)
5044
vertices = [list(vertex) for vertex in vertices]
51-
guids = []
52-
if show_vertices:
53-
points = [{'pos': point, 'color': self.color} for point in vertices]
54-
guids += compas_rhino.draw_points(points, layer=self.layer, clear=False, redraw=False)
55-
if show_edges:
56-
lines = []
57-
seen = set()
58-
for face in faces:
59-
for u, v in pairwise(face + face[:1]):
60-
if (u, v) not in seen:
61-
seen.add((u, v))
62-
seen.add((v, u))
63-
lines.append({'start': vertices[u], 'end': vertices[v], 'color': self.color})
64-
guids += compas_rhino.draw_lines(lines, layer=self.layer, clear=False, redraw=False)
65-
if show_faces:
66-
if join_faces:
67-
guid = compas_rhino.draw_mesh(vertices, faces, layer=self.layer, name=self.shape.name, color=self.color, disjoint=True)
68-
guids.append(guid)
69-
else:
70-
polygons = [{'points': [vertices[index] for index in face], 'color': self.color} for face in faces]
71-
guids += compas_rhino.draw_faces(polygons, layer=self.layer, clear=False, redraw=False)
72-
return guids
45+
guid = compas_rhino.draw_mesh(vertices,
46+
faces,
47+
layer=self.layer,
48+
name=self.shape.name,
49+
color=color,
50+
disjoint=True)
51+
return [guid]

src/compas_rhino/artists/cylinderartist.py

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from __future__ import absolute_import
33
from __future__ import division
44

5-
from compas.utilities import pairwise
65
import compas_rhino
76
from compas.artists import ShapeArtist
87
from .artist import RhinoArtist
@@ -22,50 +21,30 @@ class CylinderArtist(RhinoArtist, ShapeArtist):
2221
def __init__(self, cylinder, layer=None, **kwargs):
2322
super(CylinderArtist, self).__init__(shape=cylinder, layer=layer, **kwargs)
2423

25-
def draw(self, u=None, show_vertices=False, show_edges=False, show_faces=True, join_faces=True):
24+
def draw(self, color=None, u=None):
2625
"""Draw the cylinder associated with the artist.
2726
2827
Parameters
2928
----------
29+
color : tuple of float, optional
30+
The RGB color of the cylinder.
3031
u : int, optional
3132
Number of faces in the "u" direction.
3233
Default is ``~CylinderArtist.u``.
33-
show_vertices : bool, optional
34-
Default is ``False``.
35-
show_edges : bool, optional
36-
Default is ``False``.
37-
show_faces : bool, optional
38-
Default is ``True``.
39-
join_faces : bool, optional
40-
Default is ``True``.
4134
4235
Returns
4336
-------
4437
list
4538
The GUIDs of the objects created in Rhino.
4639
"""
40+
color = color or self.color
4741
u = u or self.u
4842
vertices, faces = self.shape.to_vertices_and_faces(u=u)
4943
vertices = [list(vertex) for vertex in vertices]
50-
guids = []
51-
if show_vertices:
52-
points = [{'pos': point, 'color': self.color} for point in vertices]
53-
guids += compas_rhino.draw_points(points, layer=self.layer, clear=False, redraw=False)
54-
if show_edges:
55-
lines = []
56-
seen = set()
57-
for face in faces:
58-
for u, v in pairwise(face + face[:1]):
59-
if (u, v) not in seen:
60-
seen.add((u, v))
61-
seen.add((v, u))
62-
lines.append({'start': vertices[u], 'end': vertices[v], 'color': self.color})
63-
guids += compas_rhino.draw_lines(lines, layer=self.layer, clear=False, redraw=False)
64-
if show_faces:
65-
if join_faces:
66-
guid = compas_rhino.draw_mesh(vertices, faces, layer=self.layer, name=self.shape.name, color=self.color, disjoint=True)
67-
guids.append(guid)
68-
else:
69-
polygons = [{'points': [vertices[index] for index in face], 'color': self.color} for face in faces]
70-
guids += compas_rhino.draw_faces(polygons, layer=self.layer, clear=False, redraw=False)
71-
return guids
44+
guid = compas_rhino.draw_mesh(vertices,
45+
faces,
46+
layer=self.layer,
47+
name=self.shape.name,
48+
color=color,
49+
disjoint=True)
50+
return [guid]

src/compas_rhino/artists/polyhedronartist.py

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -21,40 +21,26 @@ class PolyhedronArtist(RhinoArtist, ShapeArtist):
2121
def __init__(self, polyhedron, layer=None, **kwargs):
2222
super(PolyhedronArtist, self).__init__(shape=polyhedron, layer=layer, **kwargs)
2323

24-
def draw(self, show_vertices=False, show_edges=False, show_faces=True, join_faces=True):
24+
def draw(self, color=None):
2525
"""Draw the polyhedron associated with the artist.
2626
2727
Parameters
2828
----------
29-
show_vertices : bool, optional
30-
Default is ``False``.
31-
show_edges : bool, optional
32-
Default is ``False``.
33-
show_faces : bool, optional
34-
Default is ``True``.
35-
join_faces : bool, optional
36-
Default is ``True``.
29+
color : tuple of float, optional
30+
The RGB color of the polyhedron.
3731
3832
Returns
3933
-------
4034
list
4135
The GUIDs of the objects created in Rhino.
4236
"""
37+
color = color or self.color
4338
vertices = [list(vertex) for vertex in self.shape.vertices]
44-
guids = []
45-
if show_vertices:
46-
points = [{'pos': point, 'color': self.color, 'name': str(index)} for index, point in enumerate(vertices)]
47-
guids += compas_rhino.draw_points(points, layer=self.layer, clear=False, redraw=False)
48-
if show_edges:
49-
edges = self.shape.edges
50-
lines = [{'start': vertices[i], 'end': vertices[j], 'color': self.color} for i, j in edges]
51-
guids += compas_rhino.draw_lines(lines, layer=self.layer, clear=False, redraw=False)
52-
if show_faces:
53-
faces = self.shape.faces
54-
if join_faces:
55-
guid = compas_rhino.draw_mesh(vertices, faces, layer=self.layer, name=self.shape.name, color=self.color, disjoint=True)
56-
guids.append(guid)
57-
else:
58-
polygons = [{'points': [vertices[index] for index in face], 'color': self.color} for face in faces]
59-
guids += compas_rhino.draw_faces(polygons, layer=self.layer, clear=False, redraw=False)
60-
return guids
39+
faces = self.shape.faces
40+
guid = compas_rhino.draw_mesh(vertices,
41+
faces,
42+
layer=self.layer,
43+
name=self.shape.name,
44+
color=color,
45+
disjoint=True)
46+
return [guid]

src/compas_rhino/artists/sphereartist.py

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from __future__ import absolute_import
33
from __future__ import division
44

5-
from compas.utilities import pairwise
65
import compas_rhino
76
from compas.artists import ShapeArtist
87
from .artist import RhinoArtist
@@ -22,54 +21,34 @@ class SphereArtist(RhinoArtist, ShapeArtist):
2221
def __init__(self, sphere, layer=None, **kwargs):
2322
super(SphereArtist, self).__init__(shape=sphere, layer=layer, **kwargs)
2423

25-
def draw(self, u=None, v=None, show_vertices=False, show_edges=False, show_faces=True, join_faces=True):
24+
def draw(self, color=None, u=None, v=None):
2625
"""Draw the sphere associated with the artist.
2726
2827
Parameters
2928
----------
29+
color : tuple of float, optional
30+
The RGB color of the sphere.
3031
u : int, optional
3132
Number of faces in the "u" direction.
3233
Default is ``~SphereArtist.u``.
3334
v : int, optional
3435
Number of faces in the "v" direction.
3536
Default is ``~SphereArtist.v``.
36-
show_vertices : bool, optional
37-
Default is ``False``.
38-
show_edges : bool, optional
39-
Default is ``False``.
40-
show_faces : bool, optional
41-
Default is ``True``.
42-
join_faces : bool, optional
43-
Default is ``True``.
4437
4538
Returns
4639
-------
4740
list
4841
The GUIDs of the objects created in Rhino.
4942
"""
43+
color = color or self.color
5044
u = u or self.u
5145
v = v or self.v
5246
vertices, faces = self.shape.to_vertices_and_faces(u=u, v=v)
5347
vertices = [list(vertex) for vertex in vertices]
54-
guids = []
55-
if show_vertices:
56-
points = [{'pos': point, 'color': self.color} for point in vertices]
57-
guids += compas_rhino.draw_points(points, layer=self.layer, clear=False, redraw=False)
58-
if show_edges:
59-
lines = []
60-
seen = set()
61-
for face in faces:
62-
for u, v in pairwise(face + face[:1]):
63-
if (u, v) not in seen:
64-
seen.add((u, v))
65-
seen.add((v, u))
66-
lines.append({'start': vertices[u], 'end': vertices[v], 'color': self.color})
67-
guids += compas_rhino.draw_lines(lines, layer=self.layer, clear=False, redraw=False)
68-
if show_faces:
69-
if join_faces:
70-
guid = compas_rhino.draw_mesh(vertices, faces, layer=self.layer, name=self.shape.name, color=self.color, disjoint=True)
71-
guids.append(guid)
72-
else:
73-
polygons = [{'points': [vertices[index] for index in face], 'color': self.color} for face in faces]
74-
guids += compas_rhino.draw_faces(polygons, layer=self.layer, clear=False, redraw=False)
75-
return guids
48+
guid = compas_rhino.draw_mesh(vertices,
49+
faces,
50+
layer=self.layer,
51+
name=self.shape.name,
52+
color=color,
53+
disjoint=True)
54+
return [guid]

src/compas_rhino/artists/torusartist.py

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from __future__ import absolute_import
33
from __future__ import division
44

5-
from compas.utilities import pairwise
65
import compas_rhino
76
from compas.artists import ShapeArtist
87
from .artist import RhinoArtist
@@ -22,54 +21,34 @@ class TorusArtist(RhinoArtist, ShapeArtist):
2221
def __init__(self, torus, layer=None, **kwargs):
2322
super(TorusArtist, self).__init__(shape=torus, layer=layer, **kwargs)
2423

25-
def draw(self, u=None, v=None, show_vertices=False, show_edges=False, show_faces=True, join_faces=True):
24+
def draw(self, color=None, u=None, v=None):
2625
"""Draw the torus associated with the artist.
2726
2827
Parameters
2928
----------
29+
color : tuple of float, optional
30+
The RGB color of the torus.
3031
u : int, optional
3132
Number of faces in the "u" direction.
3233
Default is ``~TorusArtist.u``.
3334
v : int, optional
3435
Number of faces in the "v" direction.
3536
Default is ``~TorusArtist.v``.
36-
show_vertices : bool, optional
37-
Default is ``False``.
38-
show_edges : bool, optional
39-
Default is ``False``.
40-
show_faces : bool, optional
41-
Default is ``True``.
42-
join_faces : bool, optional
43-
Default is ``True``.
4437
4538
Returns
4639
-------
4740
list
4841
The GUIDs of the objects created in Rhino.
4942
"""
43+
color = color or self.color
5044
u = u or self.u
5145
v = v or self.v
5246
vertices, faces = self.shape.to_vertices_and_faces(u=u, v=v)
5347
vertices = [list(vertex) for vertex in vertices]
54-
guids = []
55-
if show_vertices:
56-
points = [{'pos': point, 'color': self.color} for point in vertices]
57-
guids += compas_rhino.draw_points(points, layer=self.layer, clear=False, redraw=False)
58-
if show_edges:
59-
lines = []
60-
seen = set()
61-
for face in faces:
62-
for u, v in pairwise(face + face[:1]):
63-
if (u, v) not in seen:
64-
seen.add((u, v))
65-
seen.add((v, u))
66-
lines.append({'start': vertices[u], 'end': vertices[v], 'color': self.color})
67-
guids += compas_rhino.draw_lines(lines, layer=self.layer, clear=False, redraw=False)
68-
if show_faces:
69-
if join_faces:
70-
guid = compas_rhino.draw_mesh(vertices, faces, layer=self.layer, name=self.shape.name, color=self.color, disjoint=True)
71-
guids.append(guid)
72-
else:
73-
polygons = [{'points': [vertices[index] for index in face], 'color': self.color} for face in faces]
74-
guids += compas_rhino.draw_faces(polygons, layer=self.layer, clear=False, redraw=False)
75-
return guids
48+
guid = compas_rhino.draw_mesh(vertices,
49+
faces,
50+
layer=self.layer,
51+
name=self.shape.name,
52+
color=color,
53+
disjoint=True)
54+
return [guid]

0 commit comments

Comments
 (0)