Reorganized imports

This commit is contained in:
Thomas FORGIONE 2016-11-25 15:03:03 +01:00
parent c6537a8f8c
commit e953492280
4 changed files with 38 additions and 43 deletions

View File

@ -3,9 +3,8 @@
import argparse import argparse
import os import os
from d3.model.ply import PLYExporter import d3.model.tools as mt
from d3.model.tools import convert import functools as fc
from functools import partial
def check_path(path, should_exist): def check_path(path, should_exist):
""" Check that a path (file or folder) exists or not and return it. """ Check that a path (file or folder) exists or not and return it.
@ -18,7 +17,7 @@ def check_path(path, should_exist):
def main(args): def main(args):
output = args.output if args.output is not None else '.' + args.type output = args.output if args.output is not None else '.' + args.type
result = convert(args.input, output) result = mt.convert(args.input, output)
if args.output is None: if args.output is None:
print(result) print(result)
@ -31,7 +30,7 @@ if __name__ == '__main__':
parser.set_defaults(func=main) parser.set_defaults(func=main)
parser.add_argument('-v', '--version', action='version', version='1.0') parser.add_argument('-v', '--version', action='version', version='1.0')
parser.add_argument('-i', '--input', metavar='input', parser.add_argument('-i', '--input', metavar='input',
type=partial(check_path, should_exist=True), default=None, type=fc.partial(check_path, should_exist=True), default=None,
help='Input file (.obj)') help='Input file (.obj)')
parser.add_argument('-o', '--output', metavar='output', parser.add_argument('-o', '--output', metavar='output',
help='Output path') help='Output path')

View File

@ -3,10 +3,7 @@
from .geometry import Vector from .geometry import Vector
import pygame import pygame
import OpenGL.GL as gl
from OpenGL.GL import *
from OpenGL.GLU import *
import math import math
class Controls: class Controls:
@ -26,7 +23,7 @@ class TrackBallControls(Controls):
self.theta = 0 self.theta = 0
def apply(self): def apply(self):
glRotatef(self.theta * 180 / math.pi, self.vertex.x, self.vertex.y, self.vertex.z) gl.glRotatef(self.theta * 180 / math.pi, self.vertex.x, self.vertex.y, self.vertex.z)
def update(self, time = 10): def update(self, time = 10):

View File

@ -1,6 +1,6 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
from math import sqrt import math
class Vector: class Vector:
def __init__(self, x = 0.0, y = 0.0, z = 0.0): def __init__(self, x = 0.0, y = 0.0, z = 0.0):
@ -27,7 +27,7 @@ class Vector:
return self.x * self.x + self.y * self.y + self.z * self.z return self.x * self.x + self.y * self.y + self.z * self.z
def norm(self): def norm(self):
return sqrt(self.norm2()) return math.sqrt(self.norm2())
def normalize(self): def normalize(self):
norm = self.norm() norm = self.norm()

View File

@ -2,15 +2,14 @@
import sys import sys
import ctypes import ctypes
import pygame
import argparse import argparse
import os import os
import math import math
from pygame.locals import * import pygame as pg
from OpenGL.GL import * import pygame.locals as pgl
from OpenGL.GL.shaders import * import OpenGL.GL as gl
from OpenGL.GLU import * import OpenGL.GLU as glu
from d3.model.tools import load_model from d3.model.tools import load_model
from d3.geometry import Vector from d3.geometry import Vector
@ -26,20 +25,20 @@ def main(args):
camera = Camera(Vector(0,0,5), Vector(0,0,0)) camera = Camera(Vector(0,0,5), Vector(0,0,0))
controls = TrackBallControls() controls = TrackBallControls()
pygame.init() pg.init()
display = (WINDOW_WIDTH, WINDOW_HEIGHT) display = (WINDOW_WIDTH, WINDOW_HEIGHT)
pygame.display.set_mode(display, DOUBLEBUF|OPENGL) pg.display.set_mode(display, pgl.DOUBLEBUF | pgl.OPENGL)
# OpenGL init # OpenGL init
glMatrixMode(GL_PROJECTION) gl.glMatrixMode(gl.GL_PROJECTION)
glLoadIdentity() gl.glLoadIdentity()
gluPerspective(45, (WINDOW_WIDTH / WINDOW_HEIGHT), 0.1, 50.0) glu.gluPerspective(45, (WINDOW_WIDTH / WINDOW_HEIGHT), 0.1, 50.0)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
glEnable(GL_DEPTH_TEST) gl.glEnable(gl.GL_DEPTH_TEST)
glEnable(GL_CULL_FACE) gl.glEnable(gl.GL_CULL_FACE)
glEnable(GL_BLEND) gl.glEnable(gl.GL_BLEND)
glClearColor(0, 0, 0, 0) gl.glClearColor(0, 0, 0, 0)
running = True running = True
@ -49,40 +48,40 @@ def main(args):
shader = DefaultShader() shader = DefaultShader()
while running: while running:
for event in pygame.event.get(): for event in pg.event.get():
if event.type == pygame.QUIT: if event.type == pg.QUIT:
pygame.quit() pg.quit()
quit() quit()
elif event.type == pygame.KEYUP: elif event.type == pg.KEYUP:
if event.key == pygame.K_ESCAPE: if event.key == pg.K_ESCAPE:
pygame.quit() pg.quit()
quit() quit()
elif event.type == pygame.MOUSEBUTTONDOWN: elif event.type == pg.MOUSEBUTTONDOWN:
if event.button == 1: if event.button == 1:
pygame.mouse.get_rel() pg.mouse.get_rel()
# Update physics # Update physics
controls.update() controls.update()
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
glMatrixMode(GL_MODELVIEW) gl.glMatrixMode(gl.GL_MODELVIEW)
glLoadIdentity() gl.glLoadIdentity()
camera.look() camera.look()
glPushMatrix() gl.glPushMatrix()
controls.apply() controls.apply()
shader.bind() shader.bind()
model.gl_draw() model.gl_draw()
shader.unbind() shader.unbind()
glPopMatrix() gl.glPopMatrix()
glFlush() gl.glFlush()
pygame.display.flip() pg.display.flip()
# Sleep # Sleep
pygame.time.wait(10) pg.time.wait(10)
if __name__ == '__main__': if __name__ == '__main__':