32 lines
1.1 KiB
Python
32 lines
1.1 KiB
Python
import numpy as np
|
|
from vispy import app, scene
|
|
from vispy.scene.visuals import Mesh
|
|
from vispy.visuals.filters import ShadingFilter, WireframeFilter
|
|
from utils.files.input import ScannedObject
|
|
|
|
|
|
def render3D(obj:ScannedObject):
|
|
vertices = np.asarray(obj.get_vertices())
|
|
faces = np.asarray(obj.get_faces())
|
|
canvas = scene.SceneCanvas(keys='interactive', bgcolor='white')
|
|
view = canvas.central_widget.add_view()
|
|
view.camera = 'arcball'
|
|
view.camera.depth_value = 1e3
|
|
mesh = Mesh(vertices, faces, color=(.5, .7, .5, 1))
|
|
view.add(mesh)
|
|
wireframe_filter = WireframeFilter(width=0)
|
|
shading_filter = ShadingFilter(shininess=0)
|
|
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)
|
|
canvas.show()
|
|
app.run() |