view = canvas.central_widget.add_view() view.camera = 'arcball' # Adapt the depth to the scale of the mesh to avoid rendering artefacts. view.camera.depth_value = 10 * (vertices.max() - vertices.min()) shading = None if args.shading == 'none' else args.shading mesh = Mesh(vertices, faces, shading=shading, color='white') mesh.transform = transforms.MatrixTransform() mesh.transform.rotate(90, (1, 0, 0)) mesh.transform.rotate(135, (0, 0, 1)) mesh.shading_filter.shininess = 1e+1 view.add(mesh) texture_filter = TextureFilter(texture, texcoords) mesh.attach(texture_filter) @canvas.events.key_press.connect def on_key_press(event): if event.key == "t": texture_filter.enabled = not texture_filter.enabled mesh.update() def attach_headlight(mesh, view, canvas): light_dir = (0, 1, 0, 0) mesh.shading_filter.light_dir = light_dir[:3] initial_light_dir = view.camera.transform.imap(light_dir) @view.scene.transform.changed.connect
# Create a colored `MeshVisual`. mesh = Mesh(vertices, faces, color=(.5, .7, .5, 1)) mesh.transform = transforms.MatrixTransform() mesh.transform.rotate(90, (1, 0, 0)) mesh.transform.rotate(-45, (0, 0, 1)) view.add(mesh) # Use filters to affect the rendering of the mesh. wireframe_filter = WireframeFilter(width=args.wireframe_width) # Note: For convenience, this `ShadingFilter` would be created automatically by # the `MeshVisual with, e.g. `mesh = MeshVisual(..., shading='smooth')`. It is # created manually here for demonstration purposes. shading_filter = ShadingFilter(shininess=args.shininess) # The wireframe filter is attached before the shading filter otherwise the # wireframe is not shaded. mesh.attach(wireframe_filter) mesh.attach(shading_filter) def attach_headlight(view): light_dir = (0, 1, 0, 0) shading_filter.light_dir = light_dir[:3] initial_light_dir = view.camera.transform.imap(light_dir) @view.scene.transform.changed.connect def on_transform_change(event): transform = view.camera.transform shading_filter.light_dir = transform.map(initial_light_dir)[:3] attach_headlight(view)
"""Show how to display mesh normals on a mesh.""" from vispy import app, scene from vispy.io import read_mesh, load_data_file from vispy.scene.visuals import Mesh, MeshNormals from vispy.visuals.filters import WireframeFilter mesh_file = load_data_file('orig/triceratops.obj.gz') vertices, faces, _, _ = read_mesh(mesh_file) mesh = Mesh(vertices, faces, shading='flat') meshdata = mesh.mesh_data wireframe_filter = WireframeFilter(color='lightblue') mesh.attach(wireframe_filter) face_normals = MeshNormals(meshdata, primitive='face', color='yellow') vertex_normals = MeshNormals(meshdata, primitive='vertex', color='orange', width=2) canvas = scene.SceneCanvas(keys='interactive', bgcolor='white') view = canvas.central_widget.add_view() view.camera = 'arcball' view.add(mesh) face_normals.parent = mesh vertex_normals.parent = mesh @canvas.events.key_press.connect def on_key_press(event):