Skip to content

Commit

Permalink
update to compas 2.4
Browse files Browse the repository at this point in the history
  • Loading branch information
tomvanmele committed Aug 23, 2024
1 parent 91a1856 commit 3595b5b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 21 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

* Changed `compas_notebook.scene.ThreeBrepObject` to be compatible with `compas>=2.4`.
* Changed `compas_notebook.scene.ThreeMeshObject` to be compatible with `compas>=2.4`.

### Removed


Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
compas >= 2.1
compas >= 2.4
jupyter
pythreejs
6 changes: 2 additions & 4 deletions src/compas_notebook/scene/brepobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
class ThreeBrepObject(ThreeSceneObject, GeometryObject):
"""Scene object for drawing a Brep."""

def __init__(self, item: Brep, *args: Any, **kwargs: Any):
super().__init__(geometry=item, *args, **kwargs)
self.brep = item
geometry: Brep

def draw(self):
"""Draw the Brep associated with the scene object.
Expand All @@ -25,7 +23,7 @@ def draw(self):
List of pythreejs objects created.
"""
mesh, polylines = self.brep.to_viewmesh()
mesh, polylines = self.geometry.to_viewmesh()
vertices, faces = mesh.to_vertices_and_faces()

geometry = vertices_and_faces_to_threejs(vertices, faces)
Expand Down
32 changes: 16 additions & 16 deletions src/compas_notebook/scene/meshobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def draw(self):
return self.guids

def draw_vertices(self, vertices, color):
positions = [self.vertex_xyz[vertex] for vertex in vertices]
positions = [self.mesh.vertex_coordinates(vertex) for vertex in vertices]
positions = numpy.array(positions, dtype=numpy.float32)
colors = [color[i] for i in range(len(vertices))]
colors = numpy.array(colors, dtype=numpy.float32)
Expand All @@ -65,8 +65,8 @@ def draw_edges(self, edges, color):
colors = []

for u, v in edges:
positions.append(self.vertex_xyz[u])
positions.append(self.vertex_xyz[v])
positions.append(self.mesh.vertex_coordinates(u))
positions.append(self.mesh.vertex_coordinates(v))
colors.append(color[u, v])
colors.append(color[u, v])

Expand All @@ -91,32 +91,32 @@ def draw_faces(self, faces, color):
c = color[face]

if len(vertices) == 3:
positions.append(self.vertex_xyz[vertices[0]])
positions.append(self.vertex_xyz[vertices[1]])
positions.append(self.vertex_xyz[vertices[2]])
positions.append(self.mesh.vertex_coordinates(vertices[0]))
positions.append(self.mesh.vertex_coordinates(vertices[1]))
positions.append(self.mesh.vertex_coordinates(vertices[2]))
colors.append(c)
colors.append(c)
colors.append(c)
elif len(vertices) == 4:
positions.append(self.vertex_xyz[vertices[0]])
positions.append(self.vertex_xyz[vertices[1]])
positions.append(self.vertex_xyz[vertices[2]])
positions.append(self.mesh.vertex_coordinates(vertices[0]))
positions.append(self.mesh.vertex_coordinates(vertices[1]))
positions.append(self.mesh.vertex_coordinates(vertices[2]))
colors.append(c)
colors.append(c)
colors.append(c)
positions.append(self.vertex_xyz[vertices[0]])
positions.append(self.vertex_xyz[vertices[2]])
positions.append(self.vertex_xyz[vertices[3]])
positions.append(self.mesh.vertex_coordinates(vertices[0]))
positions.append(self.mesh.vertex_coordinates(vertices[2]))
positions.append(self.mesh.vertex_coordinates(vertices[3]))
colors.append(c)
colors.append(c)
colors.append(c)
else:
polygon = Polygon([self.vertex_xyz[v] for v in vertices])
polygon = Polygon([self.mesh.vertex_coordinates(v) for v in vertices])
ears = earclip_polygon(polygon)
for ear in ears:
positions.append(self.vertex_xyz[vertices[ear[0]]])
positions.append(self.vertex_xyz[vertices[ear[1]]])
positions.append(self.vertex_xyz[vertices[ear[2]]])
positions.append(self.mesh.vertex_coordinates(vertices[ear[0]]))
positions.append(self.mesh.vertex_coordinates(vertices[ear[1]]))
positions.append(self.mesh.vertex_coordinates(vertices[ear[2]]))
colors.append(c)
colors.append(c)
colors.append(c)
Expand Down

0 comments on commit 3595b5b

Please sign in to comment.