Skip to content

Commit

Permalink
Add clearing control
Browse files Browse the repository at this point in the history
  • Loading branch information
aganders3 committed Jun 14, 2023
1 parent 29b0f5d commit 20c71e9
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions examples/scene/face_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
Controls:
* s - Cycle shading modes (None, 'flat', 'smooth')
* w - Toggle wireframe
* p - Toggle face picking view
* p - Toggle face picking view - shows the colors encoding face ID
* c - Clear painted faces
"""
import argparse
import itertools
Expand Down Expand Up @@ -48,7 +49,7 @@
mesh = Mesh(
vertices,
faces,
face_colors=face_colors
face_colors=face_colors.copy()
)
mesh.transform = transforms.MatrixTransform()
mesh.transform.rotate(90, (1, 0, 0))
Expand Down Expand Up @@ -102,18 +103,16 @@ def on_mouse_move(event):
row = int(row / rows * id.shape[0])

# color the hovered face on the mesh
meshdata = mesh.mesh_data
if id[row, col] in range(1, len(face_colors)):
face_colors[id[row, col], :] = (0, 1, 0, 1)
# meshdata.set_face_colors(face_colors)
# mesh.set_data(meshdata=meshdata)
# this may be less safe, but it's faster
meshdata._face_colors_indexed_by_faces[id[row, col]] = (0, 1, 0, 1)
mesh.mesh_data._face_colors_indexed_by_faces[id[row, col]] = (0, 1, 0, 1)
mesh.mesh_data_changed()


@canvas.events.key_press.connect
def on_key_press(event):
if event.key == 'c':
mesh.set_data(vertices, faces, face_colors=face_colors)
if event.key == 's':
shading_filter.shading = next(shading)
mesh.update()
Expand Down

0 comments on commit 20c71e9

Please sign in to comment.