Stuff
This commit is contained in:
parent
b6130ca640
commit
befe9c19fe
|
@ -58,11 +58,21 @@ class OrbitControls(Controls):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.phi = 0
|
self.phi = 0
|
||||||
self.theta = 0
|
self.theta = 0
|
||||||
|
self.scale = 1
|
||||||
|
|
||||||
def apply(self):
|
def apply(self):
|
||||||
|
gl.glScalef(self.scale, self.scale, self.scale)
|
||||||
gl.glRotatef(self.theta * 180 / math.pi, 1.0, 0.0, 0.0)
|
gl.glRotatef(self.theta * 180 / math.pi, 1.0, 0.0, 0.0)
|
||||||
gl.glRotatef(self.phi * 180 / math.pi, 0.0, 1.0, 0.0)
|
gl.glRotatef(self.phi * 180 / math.pi, 0.0, 1.0, 0.0)
|
||||||
|
|
||||||
|
def apply_event(self, event):
|
||||||
|
if event.type == pygame.MOUSEBUTTONDOWN:
|
||||||
|
# Wheel up
|
||||||
|
if event.button == 4:
|
||||||
|
self.scale += 0.2
|
||||||
|
elif event.button == 5:
|
||||||
|
self.scale -= 2
|
||||||
|
|
||||||
def update(self, time = 10):
|
def update(self, time = 10):
|
||||||
|
|
||||||
if not pygame.mouse.get_pressed()[0]:
|
if not pygame.mouse.get_pressed()[0]:
|
||||||
|
|
|
@ -74,7 +74,6 @@ class ModelParser:
|
||||||
"""Initializes the model
|
"""Initializes the model
|
||||||
"""
|
"""
|
||||||
self.up_conversion = up_conversion
|
self.up_conversion = up_conversion
|
||||||
print(up_conversion)
|
|
||||||
self.vertices = []
|
self.vertices = []
|
||||||
self.normals = []
|
self.normals = []
|
||||||
self.tex_coords = []
|
self.tex_coords = []
|
||||||
|
|
|
@ -48,7 +48,9 @@ class Material:
|
||||||
gl.glBindTexture(gl.GL_TEXTURE_2D, self.id)
|
gl.glBindTexture(gl.GL_TEXTURE_2D, self.id)
|
||||||
|
|
||||||
def unbind(self):
|
def unbind(self):
|
||||||
pass
|
from OpenGL import GL as gl
|
||||||
|
|
||||||
|
gl.glDisable(gl.GL_TEXTURE_2D)
|
||||||
|
|
||||||
import PIL.Image
|
import PIL.Image
|
||||||
|
|
||||||
|
@ -150,33 +152,11 @@ class MeshPart:
|
||||||
|
|
||||||
gl.glDrawArrays(gl.GL_TRIANGLES, 0, len(self.vertex_vbo.data) * 9)
|
gl.glDrawArrays(gl.GL_TRIANGLES, 0, len(self.vertex_vbo.data) * 9)
|
||||||
|
|
||||||
|
gl.glDisableClientState(gl.GL_VERTEX_ARRAY)
|
||||||
|
gl.glDisableClientState(gl.GL_NORMAL_ARRAY)
|
||||||
|
gl.glDisableClientState(gl.GL_TEXTURE_COORD_ARRAY)
|
||||||
|
|
||||||
|
|
||||||
def draw_from_arrays(self):
|
def draw_from_arrays(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
class Mesh:
|
|
||||||
def __init__(self):
|
|
||||||
self.vertices = []
|
|
||||||
self.tex_coords = []
|
|
||||||
self.normals = []
|
|
||||||
self.parts = []
|
|
||||||
self.current_material = None
|
|
||||||
self.current_part = None
|
|
||||||
|
|
||||||
def draw(self):
|
|
||||||
for part in self.parts:
|
|
||||||
part.draw()
|
|
||||||
|
|
||||||
def add_face(self, face):
|
|
||||||
if self.current_part is None or face.material != self.current_part.material:
|
|
||||||
self.current_part = MeshPart(self)
|
|
||||||
self.current_part.material = face.material
|
|
||||||
self.parts.append(self.current_part)
|
|
||||||
|
|
||||||
self.current_part.add_face(face)
|
|
||||||
|
|
||||||
def generate_vbos(self):
|
|
||||||
for part in self.parts:
|
|
||||||
part.generate_vbos()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
36
viewer.py
36
viewer.py
|
@ -18,7 +18,18 @@ from d3.camera import Camera
|
||||||
from d3.shader import DefaultShader
|
from d3.shader import DefaultShader
|
||||||
|
|
||||||
WINDOW_WIDTH = 1024
|
WINDOW_WIDTH = 1024
|
||||||
WINDOW_HEIGHT = 768
|
WINDOW_HEIGHT = 1024
|
||||||
|
|
||||||
|
def resize(width, height):
|
||||||
|
print((width, height))
|
||||||
|
|
||||||
|
length = min(width, height)
|
||||||
|
offset = int( math.fabs(width - height) / 2)
|
||||||
|
|
||||||
|
if width < height:
|
||||||
|
gl.glViewport(0, offset, length, length)
|
||||||
|
else:
|
||||||
|
gl.glViewport(offset, 0, length, length)
|
||||||
|
|
||||||
def main(args):
|
def main(args):
|
||||||
|
|
||||||
|
@ -35,10 +46,13 @@ def main(args):
|
||||||
|
|
||||||
pg.init()
|
pg.init()
|
||||||
display = (WINDOW_WIDTH, WINDOW_HEIGHT)
|
display = (WINDOW_WIDTH, WINDOW_HEIGHT)
|
||||||
pg.display.set_mode(display, pgl.DOUBLEBUF | pgl.OPENGL)
|
pg.display.set_mode(display, pgl.DOUBLEBUF | pgl.OPENGL | pgl.RESIZABLE)
|
||||||
pg.display.set_caption('Model-Converter')
|
pg.display.set_caption('Model-Converter')
|
||||||
|
|
||||||
# OpenGL init
|
# OpenGL init
|
||||||
|
gl.glMatrixMode(gl.GL_MODELVIEW)
|
||||||
|
gl.glViewport(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT)
|
||||||
|
|
||||||
gl.glMatrixMode(gl.GL_PROJECTION)
|
gl.glMatrixMode(gl.GL_PROJECTION)
|
||||||
gl.glLoadIdentity()
|
gl.glLoadIdentity()
|
||||||
glu.gluPerspective(45, (WINDOW_WIDTH / WINDOW_HEIGHT), 0.1, 50.0)
|
glu.gluPerspective(45, (WINDOW_WIDTH / WINDOW_HEIGHT), 0.1, 50.0)
|
||||||
|
@ -68,6 +82,9 @@ def main(args):
|
||||||
|
|
||||||
while running:
|
while running:
|
||||||
for event in pg.event.get():
|
for event in pg.event.get():
|
||||||
|
|
||||||
|
controls.apply_event(event)
|
||||||
|
|
||||||
if event.type == pg.QUIT:
|
if event.type == pg.QUIT:
|
||||||
pg.quit()
|
pg.quit()
|
||||||
quit()
|
quit()
|
||||||
|
@ -78,6 +95,8 @@ def main(args):
|
||||||
elif event.type == pg.MOUSEBUTTONDOWN:
|
elif event.type == pg.MOUSEBUTTONDOWN:
|
||||||
if event.button == 1:
|
if event.button == 1:
|
||||||
pg.mouse.get_rel()
|
pg.mouse.get_rel()
|
||||||
|
elif event.type == pg.VIDEORESIZE:
|
||||||
|
resize(event.size[0], event.size[1])
|
||||||
|
|
||||||
# Update physics
|
# Update physics
|
||||||
controls.update()
|
controls.update()
|
||||||
|
@ -90,6 +109,19 @@ def main(args):
|
||||||
|
|
||||||
gl.glPushMatrix()
|
gl.glPushMatrix()
|
||||||
controls.apply()
|
controls.apply()
|
||||||
|
|
||||||
|
gl.glBegin(gl.GL_LINES)
|
||||||
|
gl.glColor3f (1.0,0.0,0.0)
|
||||||
|
gl.glVertex3f(0.0,0.0,0.0)
|
||||||
|
gl.glVertex3f(2.0,0.0,0.0)
|
||||||
|
gl.glColor3f (0.0,1.0,0.0)
|
||||||
|
gl.glVertex3f(0.0,0.0,0.0)
|
||||||
|
gl.glVertex3f(0.0,2.0,0.0)
|
||||||
|
gl.glColor3f (0.0,0.0,1.0)
|
||||||
|
gl.glVertex3f(0.0,0.0,0.0)
|
||||||
|
gl.glVertex3f(0.0,0.0,2.0)
|
||||||
|
gl.glEnd()
|
||||||
|
|
||||||
shader.bind()
|
shader.bind()
|
||||||
model.draw()
|
model.draw()
|
||||||
shader.unbind()
|
shader.unbind()
|
||||||
|
|
Loading…
Reference in New Issue