Skip to content

Commit

Permalink
Merge pull request #1016 from compas-dev/tiny-refactor-robot-artists
Browse files Browse the repository at this point in the history
tiny refactoring of robot model artists
  • Loading branch information
gonzalocasas authored Mar 26, 2022
2 parents 0c59a51 + b7ce0b8 commit b85cce7
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 23 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

* Fixed bug in Blender mesh conversion.
* Changed Rhino plugin installer to check for and install required plugin packages.
* Refactor robot model artists to use the same `Mesh.to_vertices_and_faces` everywhere.
* Fix debug print on Blender artist.

### Removed

Expand Down
1 change: 0 additions & 1 deletion src/compas_blender/artists/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@

@plugin(category='drawing-utils', pluggable_name='clear', requires=['bpy'])
def clear_blender():
print('doing it')
compas_blender.clear()


Expand Down
3 changes: 2 additions & 1 deletion src/compas_blender/artists/robotmodelartist.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ def create_geometry(self,
else:
color = (1., 1., 1.)

v, f = geometry.to_vertices_and_faces()
v, f = geometry.to_vertices_and_faces(triangulated=False)

native_mesh = compas_blender.draw_mesh(
vertices=v, faces=f, name=name, color=color, centroid=False, collection=self.collection
)
Expand Down
4 changes: 3 additions & 1 deletion src/compas_ghpython/artists/robotmodelartist.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ def transform(self, native_mesh, transformation):
def create_geometry(self, geometry, name=None, color=None):
if color:
color = rgb_to_rgb(color[0], color[1], color[2])
vertices, faces = geometry.to_vertices_and_faces()

vertices, faces = geometry.to_vertices_and_faces(triangulated=False)

mesh = compas_ghpython.draw_mesh(vertices, faces, color=color)
# Try to fix invalid meshes
if not mesh.IsValid:
Expand Down
22 changes: 2 additions & 20 deletions src/compas_rhino/artists/robotmodelartist.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
from Rhino.DocObjects.ObjectColorSource import ColorFromLayer
from Rhino.DocObjects.ObjectMaterialSource import MaterialFromObject

from compas.geometry import centroid_polygon
from compas.utilities import pairwise
from compas.artists import RobotModelArtist

import compas_rhino
Expand Down Expand Up @@ -63,23 +61,7 @@ def create_geometry(self, geometry, name=None, color=None):
if 'mesh_color.diffuse' in geometry.attributes:
color = geometry.attributes['mesh_color.diffuse']

key_index = geometry.key_index()
vertices = geometry.vertices_attributes('xyz')
faces = [[key_index[key] for key in geometry.face_vertices(fkey)] for fkey in geometry.faces()]
new_faces = []
for face in faces:
f = len(face)
if f == 3:
new_faces.append(face + face[-1:])
elif f == 4:
new_faces.append(face)
elif f > 4:
centroid = len(vertices)
vertices.append(centroid_polygon([vertices[index] for index in face]))
for a, b in pairwise(face + face[0:1]):
new_faces.append([centroid, a, b, b])
else:
continue
vertices, faces = geometry.to_vertices_and_faces(triangulated=False)

mesh = Rhino.Geometry.Mesh()

Expand All @@ -95,7 +77,7 @@ def create_geometry(self, geometry, name=None, color=None):

for v in vertices:
mesh.Vertices.Add(*v)
for face in new_faces:
for face in faces:
mesh.Faces.AddFace(*face)

mesh.Normals.ComputeNormals()
Expand Down

0 comments on commit b85cce7

Please sign in to comment.