Skip to content

Commit 704e1d5

Browse files
committed
fix handling of mesh colors in rhino
1 parent d70fb45 commit 704e1d5

File tree

4 files changed

+31
-16
lines changed

4 files changed

+31
-16
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1616

1717
### Changed
1818

19-
* Changed `compas.datastructures.TreeNode` to skip serialising `attributes`, `name` and `children` if being empty.
19+
* Changed `compas.datastructures.TreeNode` to skip serialising `attributes`, `name` and `children` if being empty.
2020
* Changed `compas.datastructures.TreeNode.__repr__` to omit `name` if `None`.
21+
* Changed `compas.scene.descriptors.ColorDictAttribute` to accept a `compas.colors.ColorDict` as value.
22+
* Changed `compas_rhino.scene.RhinoMeshObject.draw` to preprocess vertex and face color dicts into lists.
23+
* Changed `compas_rhino.conversions.vertices_and_faces_to_rhino` to handle vertex color information correctly.
2124

2225
### Removed
2326

src/compas/scene/descriptors/colordict.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ def __set__(self, obj, value):
9191
colordict.clear()
9292
colordict.update(value)
9393

94+
elif isinstance(value, ColorDict):
95+
colordict.clear()
96+
colordict.default = value.default
97+
colordict.update(value)
98+
9499
else:
95100
colordict.clear()
96101
colordict.default = value

src/compas_rhino/conversions/meshes.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -204,19 +204,18 @@ def face_callback(face):
204204

205205
face_callback(face)
206206

207-
# if color:
208-
# mesh.VertexColors.CreateMonotoneMesh(SystemColor.FromArgb(*color.rgb255))
209-
# else:
210-
if not color:
211-
if vertexcolors:
212-
if len(mesh.Vertices) != len(vertexcolors):
213-
raise ValueError("The number of vertex colors does not match the number of vertices.")
214-
215-
colors = System.Array.CreateInstance(System.Drawing.Color, len(vertexcolors))
216-
for index, color in enumerate(vertexcolors):
217-
colors[index] = System.Drawing.Color.FromArgb(*color.rgb255)
218-
219-
mesh.VertexColors.SetColors(colors)
207+
if vertexcolors:
208+
if len(mesh.Vertices) != len(vertexcolors):
209+
raise ValueError("The number of vertex colors does not match the number of vertices.")
210+
211+
colors = System.Array.CreateInstance(System.Drawing.Color, len(vertexcolors))
212+
for index, color in enumerate(vertexcolors):
213+
colors[index] = System.Drawing.Color.FromArgb(*color.rgb255)
214+
215+
mesh.VertexColors.SetColors(colors)
216+
else:
217+
if color:
218+
mesh.VertexColors.CreateMonotoneMesh(System.Drawing.Color.FromArgb(*color.rgb255))
220219

221220
# mesh.UnifyNormals()
222221
mesh.Normals.ComputeNormals()

src/compas_rhino/scene/meshobject.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,19 @@ def draw(self):
181181
if self.show_faces is True:
182182
attr = self.compile_attributes()
183183

184+
vertexcolors = []
185+
if len(self.vertexcolor):
186+
vertexcolors = [self.vertexcolor[vertex] for vertex in self.mesh.vertices()]
187+
188+
facecolors = []
189+
if len(self.facecolor):
190+
facecolors = [self.facecolor[face] for face in self.mesh.faces()]
191+
184192
geometry = mesh_to_rhino(
185193
self.mesh,
186194
color=self.color,
187-
vertexcolors=self.vertexcolor,
188-
facecolors=self.facecolor,
195+
vertexcolors=vertexcolors,
196+
facecolors=facecolors,
189197
disjoint=self.disjoint,
190198
)
191199

0 commit comments

Comments
 (0)