Reorganized imports
This commit is contained in:
parent
c6537a8f8c
commit
e953492280
|
@ -3,9 +3,8 @@
|
|||
import argparse
|
||||
import os
|
||||
|
||||
from d3.model.ply import PLYExporter
|
||||
from d3.model.tools import convert
|
||||
from functools import partial
|
||||
import d3.model.tools as mt
|
||||
import functools as fc
|
||||
|
||||
def check_path(path, should_exist):
|
||||
""" 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):
|
||||
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:
|
||||
print(result)
|
||||
|
@ -31,7 +30,7 @@ if __name__ == '__main__':
|
|||
parser.set_defaults(func=main)
|
||||
parser.add_argument('-v', '--version', action='version', version='1.0')
|
||||
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)')
|
||||
parser.add_argument('-o', '--output', metavar='output',
|
||||
help='Output path')
|
||||
|
|
|
@ -3,10 +3,7 @@
|
|||
from .geometry import Vector
|
||||
|
||||
import pygame
|
||||
|
||||
from OpenGL.GL import *
|
||||
from OpenGL.GLU import *
|
||||
|
||||
import OpenGL.GL as gl
|
||||
import math
|
||||
|
||||
class Controls:
|
||||
|
@ -26,7 +23,7 @@ class TrackBallControls(Controls):
|
|||
self.theta = 0
|
||||
|
||||
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):
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
from math import sqrt
|
||||
import math
|
||||
|
||||
class Vector:
|
||||
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
|
||||
|
||||
def norm(self):
|
||||
return sqrt(self.norm2())
|
||||
return math.sqrt(self.norm2())
|
||||
|
||||
def normalize(self):
|
||||
norm = self.norm()
|
||||
|
|
61
viewer.py
61
viewer.py
|
@ -2,15 +2,14 @@
|
|||
|
||||
import sys
|
||||
import ctypes
|
||||
import pygame
|
||||
import argparse
|
||||
import os
|
||||
import math
|
||||
|
||||
from pygame.locals import *
|
||||
from OpenGL.GL import *
|
||||
from OpenGL.GL.shaders import *
|
||||
from OpenGL.GLU import *
|
||||
import pygame as pg
|
||||
import pygame.locals as pgl
|
||||
import OpenGL.GL as gl
|
||||
import OpenGL.GLU as glu
|
||||
|
||||
from d3.model.tools import load_model
|
||||
from d3.geometry import Vector
|
||||
|
@ -26,20 +25,20 @@ def main(args):
|
|||
camera = Camera(Vector(0,0,5), Vector(0,0,0))
|
||||
controls = TrackBallControls()
|
||||
|
||||
pygame.init()
|
||||
pg.init()
|
||||
display = (WINDOW_WIDTH, WINDOW_HEIGHT)
|
||||
pygame.display.set_mode(display, DOUBLEBUF|OPENGL)
|
||||
pg.display.set_mode(display, pgl.DOUBLEBUF | pgl.OPENGL)
|
||||
|
||||
# OpenGL init
|
||||
glMatrixMode(GL_PROJECTION)
|
||||
glLoadIdentity()
|
||||
gluPerspective(45, (WINDOW_WIDTH / WINDOW_HEIGHT), 0.1, 50.0)
|
||||
gl.glMatrixMode(gl.GL_PROJECTION)
|
||||
gl.glLoadIdentity()
|
||||
glu.gluPerspective(45, (WINDOW_WIDTH / WINDOW_HEIGHT), 0.1, 50.0)
|
||||
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
|
||||
glEnable(GL_DEPTH_TEST)
|
||||
glEnable(GL_CULL_FACE)
|
||||
glEnable(GL_BLEND)
|
||||
glClearColor(0, 0, 0, 0)
|
||||
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)
|
||||
|
||||
running = True
|
||||
|
||||
|
@ -49,40 +48,40 @@ def main(args):
|
|||
shader = DefaultShader()
|
||||
|
||||
while running:
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
pygame.quit()
|
||||
for event in pg.event.get():
|
||||
if event.type == pg.QUIT:
|
||||
pg.quit()
|
||||
quit()
|
||||
elif event.type == pygame.KEYUP:
|
||||
if event.key == pygame.K_ESCAPE:
|
||||
pygame.quit()
|
||||
elif event.type == pg.KEYUP:
|
||||
if event.key == pg.K_ESCAPE:
|
||||
pg.quit()
|
||||
quit()
|
||||
elif event.type == pygame.MOUSEBUTTONDOWN:
|
||||
elif event.type == pg.MOUSEBUTTONDOWN:
|
||||
if event.button == 1:
|
||||
pygame.mouse.get_rel()
|
||||
pg.mouse.get_rel()
|
||||
|
||||
# Update physics
|
||||
controls.update()
|
||||
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
|
||||
glMatrixMode(GL_MODELVIEW)
|
||||
glLoadIdentity()
|
||||
gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
|
||||
gl.glMatrixMode(gl.GL_MODELVIEW)
|
||||
gl.glLoadIdentity()
|
||||
|
||||
camera.look()
|
||||
|
||||
glPushMatrix()
|
||||
gl.glPushMatrix()
|
||||
controls.apply()
|
||||
shader.bind()
|
||||
model.gl_draw()
|
||||
shader.unbind()
|
||||
glPopMatrix()
|
||||
gl.glPopMatrix()
|
||||
|
||||
glFlush()
|
||||
pygame.display.flip()
|
||||
gl.glFlush()
|
||||
pg.display.flip()
|
||||
|
||||
# Sleep
|
||||
pygame.time.wait(10)
|
||||
pg.time.wait(10)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
Loading…
Reference in New Issue