1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
#!/usr/bin/env python
import collada
import sys
import os
import renderer
import pyglet
from pyglet.gl import *
try:
# Try and create a window with multisampling (antialiasing)
config = Config(sample_buffers=1, samples=4,
depth_size=16, double_buffer=True)
window = pyglet.window.Window(resizable=False, config=config, vsync=True)
except pyglet.window.NoSuchConfigException:
# Fall back to no multisampling for old hardware
window = pyglet.window.Window(resizable=False)
window.rotate_x = 0.0
window.rotate_y = 0.0
window.rotate_z = 0.0
@window.event
def on_draw():
daerender.render(window.rotate_x, window.rotate_y, window.rotate_z)
@window.event
def on_mouse_drag(x, y, dx, dy, buttons, modifiers):
if abs(dx) > 2:
if dx > 0:
window.rotate_y += 2
else:
window.rotate_y -= 2
if abs(dy) > 1:
if dy > 0:
window.rotate_x -= 2
else:
window.rotate_x += 2
@window.event
def on_resize(width, height):
if height == 0:
height = 1
# Override the default on_resize handler to create a 3D projection
glViewport(0, 0, width, height)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
gluPerspective(60., width / float(height), .1, 1000.)
glMatrixMode(GL_MODELVIEW)
return pyglet.event.EVENT_HANDLED
if __name__ == '__main__':
filename = sys.argv[1] if len(sys.argv) > 1 else os.path.join(os.path.dirname(__file__), 'data', 'cockpit.zip')
# open COLLADA file ignoring some errors in case they appear
collada_file = collada.Collada(filename, ignore=[
collada.common.DaeUnsupportedError,
collada.common.DaeBrokenRefError])
daerender = renderer.GLSLRenderer(collada_file)
#daerender = renderer.OldStyleRenderer(collada_file, window)
window.width = 1024
window.height = 768
pyglet.app.run()
daerender.cleanup()
|