2016-11-22 10:55:13 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import ctypes
|
2016-11-22 15:49:36 +00:00
|
|
|
import argparse
|
|
|
|
import os
|
2016-11-22 16:17:37 +00:00
|
|
|
import math
|
2016-11-22 10:55:13 +00:00
|
|
|
|
2016-11-25 14:03:03 +00:00
|
|
|
import pygame as pg
|
|
|
|
import pygame.locals as pgl
|
|
|
|
import OpenGL.GL as gl
|
|
|
|
import OpenGL.GLU as glu
|
2016-11-22 10:55:13 +00:00
|
|
|
|
2016-11-25 13:56:37 +00:00
|
|
|
from d3.model.tools import load_model
|
|
|
|
from d3.geometry import Vector
|
2016-11-25 14:41:52 +00:00
|
|
|
from d3.controls import TrackBallControls, OrbitControls
|
2016-11-25 13:28:39 +00:00
|
|
|
from d3.camera import Camera
|
2016-11-25 13:56:37 +00:00
|
|
|
from d3.shader import DefaultShader
|
2016-11-22 15:49:36 +00:00
|
|
|
|
2016-11-22 10:55:13 +00:00
|
|
|
WINDOW_WIDTH = 1024
|
|
|
|
WINDOW_HEIGHT = 768
|
|
|
|
|
2016-11-22 15:49:36 +00:00
|
|
|
def main(args):
|
2016-11-22 10:55:13 +00:00
|
|
|
|
2016-11-25 13:56:37 +00:00
|
|
|
camera = Camera(Vector(0,0,5), Vector(0,0,0))
|
2016-11-25 14:41:52 +00:00
|
|
|
controls = OrbitControls()
|
2016-11-22 16:17:37 +00:00
|
|
|
|
2016-11-25 14:03:03 +00:00
|
|
|
pg.init()
|
2016-11-22 10:55:13 +00:00
|
|
|
display = (WINDOW_WIDTH, WINDOW_HEIGHT)
|
2016-11-25 14:03:03 +00:00
|
|
|
pg.display.set_mode(display, pgl.DOUBLEBUF | pgl.OPENGL)
|
2016-11-29 14:42:21 +00:00
|
|
|
pg.display.set_caption('Model-Converter')
|
2016-11-22 10:55:13 +00:00
|
|
|
|
|
|
|
# OpenGL init
|
2016-11-25 14:03:03 +00:00
|
|
|
gl.glMatrixMode(gl.GL_PROJECTION)
|
|
|
|
gl.glLoadIdentity()
|
|
|
|
glu.gluPerspective(45, (WINDOW_WIDTH / WINDOW_HEIGHT), 0.1, 50.0)
|
2016-11-22 10:55:13 +00:00
|
|
|
|
2016-11-25 14:03:03 +00:00
|
|
|
gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
|
|
|
|
gl.glEnable(gl.GL_DEPTH_TEST)
|
|
|
|
gl.glEnable(gl.GL_CULL_FACE)
|
|
|
|
gl.glEnable(gl.GL_BLEND)
|
|
|
|
gl.glClearColor(0, 0, 0, 0)
|
2016-11-22 10:55:13 +00:00
|
|
|
|
|
|
|
running = True
|
|
|
|
|
2016-11-22 15:49:36 +00:00
|
|
|
model = load_model(args.input)
|
2016-11-29 14:40:30 +00:00
|
|
|
model.init_textures()
|
2016-11-23 14:38:50 +00:00
|
|
|
model.generate_vbos()
|
2016-11-22 10:55:13 +00:00
|
|
|
|
2016-11-29 14:40:30 +00:00
|
|
|
# shader = DefaultShader()
|
2016-11-25 10:27:05 +00:00
|
|
|
|
2016-11-22 10:55:13 +00:00
|
|
|
while running:
|
2016-11-25 14:03:03 +00:00
|
|
|
for event in pg.event.get():
|
|
|
|
if event.type == pg.QUIT:
|
|
|
|
pg.quit()
|
2016-11-22 10:55:13 +00:00
|
|
|
quit()
|
2016-11-25 14:03:03 +00:00
|
|
|
elif event.type == pg.KEYUP:
|
|
|
|
if event.key == pg.K_ESCAPE:
|
|
|
|
pg.quit()
|
2016-11-22 10:55:13 +00:00
|
|
|
quit()
|
2016-11-25 14:03:03 +00:00
|
|
|
elif event.type == pg.MOUSEBUTTONDOWN:
|
2016-11-22 16:29:25 +00:00
|
|
|
if event.button == 1:
|
2016-11-25 14:03:03 +00:00
|
|
|
pg.mouse.get_rel()
|
2016-11-22 10:55:13 +00:00
|
|
|
|
2016-11-23 11:07:47 +00:00
|
|
|
# Update physics
|
|
|
|
controls.update()
|
|
|
|
|
2016-11-25 10:53:35 +00:00
|
|
|
|
2016-11-25 14:03:03 +00:00
|
|
|
gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
|
|
|
|
gl.glMatrixMode(gl.GL_MODELVIEW)
|
|
|
|
gl.glLoadIdentity()
|
2016-11-25 10:53:35 +00:00
|
|
|
|
|
|
|
camera.look()
|
2016-11-22 16:17:37 +00:00
|
|
|
|
2016-11-25 14:03:03 +00:00
|
|
|
gl.glPushMatrix()
|
2016-11-22 16:17:37 +00:00
|
|
|
controls.apply()
|
2016-11-29 14:40:30 +00:00
|
|
|
# shader.bind()
|
2016-11-25 16:08:57 +00:00
|
|
|
model.draw()
|
2016-11-29 14:40:30 +00:00
|
|
|
# shader.unbind()
|
2016-11-25 14:03:03 +00:00
|
|
|
gl.glPopMatrix()
|
2016-11-22 16:17:37 +00:00
|
|
|
|
2016-11-25 14:03:03 +00:00
|
|
|
gl.glFlush()
|
|
|
|
pg.display.flip()
|
2016-11-22 16:17:37 +00:00
|
|
|
|
2016-11-23 11:07:47 +00:00
|
|
|
# Sleep
|
2016-11-25 14:03:03 +00:00
|
|
|
pg.time.wait(10)
|
2016-11-22 10:55:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2016-11-22 15:49:36 +00:00
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
parser.set_defaults(func=main)
|
|
|
|
parser.add_argument('-v', '--version', action='version', version='1.0')
|
|
|
|
parser.add_argument('-i', '--input', metavar='input', default=None, help='Input model')
|
|
|
|
args = parser.parse_args()
|
|
|
|
args.func(args)
|