Skip to content

Instantly share code, notes, and snippets.

@julienr
Created October 29, 2015 09:13
Show Gist options
  • Save julienr/bd6ad56d963e646515fc to your computer and use it in GitHub Desktop.
Save julienr/bd6ad56d963e646515fc to your computer and use it in GitHub Desktop.
vispy_mesh
##
import sys
import numpy as np
from vispy import scene
from vispy.color import Color
from vispy import gloo
from vispy.scene.cameras import TurntableCamera
import vispy.io
import vispy.geometry
import ply
##
verts, faces, normals, nothin = vispy.io.read_mesh("mesh.obj")
meshdata = vispy.geometry.MeshData(vertices=verts, faces=faces)
#mesh = scene.visuals.Mesh(vertices=verts, shading='smooth', faces=faces)
# sanity check
assert np.allclose(normals, meshdata.get_vertex_normals(), atol=1e-5)
canvas = scene.SceneCanvas(keys='interactive', size=(800, 600), show=True)
# Set up a viewbox to display the cube with interactive arcball
view = canvas.central_widget.add_view()
view.bgcolor = '#efefef'
#view.camera = 'turntable'
view.camera = TurntableCamera(fov=45)
#view.padding = 100
#view.camera.depth_value = 10
#print view.camera.depth_value
color = Color("#3f51b5")
mesh = scene.visuals.Mesh(meshdata=meshdata, shading='smooth', color='w')
mesh.set_gl_state('translucent', depth_test=True, cull_face=True)
view.add(mesh)
# Add a 3D axis to keep us oriented
axis = scene.visuals.XYZAxis(parent=view.scene)
if __name__ == '__main__' and sys.flags.interactive == 0:
canvas.app.run()
##
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment