-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGui_Main.py
More file actions
174 lines (136 loc) · 3.87 KB
/
Gui_Main.py
File metadata and controls
174 lines (136 loc) · 3.87 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
import pygame
from pygame.locals import *
import numpy as np
from OpenGL.GL import *
from OpenGL.GLU import *
import Loader
import subprocess
import ctypes
buildSizeX = 200
buildSizeY = 200
vertices = (
(1, -1, -1),
(1, 1, -1),
(-1, 1, -1),
(-1, -1, -1),
(1, -1, 1),
(1, 1, 1),
(-1, -1, 1),
(-1, 1, 1),
)
edges = (
(0, 1),
(0, 3),
(0, 4),
(2, 1),
(2, 3),
(2, 7),
(6, 3),
(6, 4),
(6, 7),
(5, 1),
(5, 4),
(5, 7),
)
surfaces = (
(0, 1, 2, 3),
(3, 2, 7, 6),
(6, 7, 5, 4),
(4, 5, 1, 0),
(1, 5, 7, 2),
(4, 0, 3, 6),
)
colours = (
(1, 0, 0),
(0, 1, 0),
(0, 0, 1),
(0, 0, 0),
(1, 1, 1),
(0, 1, 1),
(1, 0, 0),
(0, 1, 0),
(0, 0, 1),
(0, 0, 0),
(1, 1, 1),
(0, 1, 1),
)
mesh = Loader.Load()
#mesh.load("C:/Users/aidan/Downloads/Cube.stl")
mesh.load("C:/Users/aidan/Downloads/NoFace_body.stl")
vertices = mesh.vertices
surfaces = mesh.triangle
print(vertices)
def Cube():
glBegin(GL_TRIANGLES)
for surface in surfaces:
x = 0
for vertex in surface:
x += 1
glColor3fv(colours[x])
glVertex3fv(vertices[vertex])
glEnd()
#glBegin(GL_LINES)
#for edge in edges:
# for vertex in edge:
# glVertex3fv(vertices[vertex])
#glEnd()
def createBuffer(attributes):
bufferdata = (ctypes.c_float*len(attributes))(*attributes) # float buffer
buffersize = len(attributes)*4 # buffer size in bytes
vbo = glGenBuffers(1)
glBindBuffer(GL_ARRAY_BUFFER, vbo)
glBufferData(GL_ARRAY_BUFFER, buffersize, bufferdata, GL_STATIC_DRAW)
glBindBuffer(GL_ARRAY_BUFFER, 0)
return vbo
def drawBuffer(vbo, noOfVertices):
glBindBuffer(GL_ARRAY_BUFFER, vbo)
stride = 6*4 # (24 bytes) : [x,y,z,r,g,b] * sizeof(float) -> (4bytes)
glEnableClientState(GL_VERTEX_ARRAY)
glVertexPointer(3, GL_FLOAT, stride, None)
glEnableClientState(GL_COLOR_ARRAY)
offset = 3*4 # (12 bytes) : the rgb starts afer the 3 coords x,y,z * sizeof(float) -> (4bytes) representing the size of the x,y,z
glColorPointer(3, GL_FLOAT, stride, ctypes.c_void_p(offset))
glDrawArrays(GL_TRIANGLES, 0, noOfVertices)
glDisableClientState(GL_VERTEX_ARRAY)
glDisableClientState(GL_COLOR_ARRAY)
glBindBuffer(GL_ARRAY_BUFFER, 0)
def main():
pygame.init()
display = (1400, 1300)
pygame.display.set_mode(display, DOUBLEBUF|OPENGL|RESIZABLE)
gluPerspective(90, float((display[0]/display[1])), 0.1, 1000.0)
glEnable(GL_CULL_FACE)
glCullFace(GL_BACK)
#glEnable(GL_DEPTH_TEST)
#glDepthFunc(GL_LESS)
glTranslatef(0, 10, -70)
glRotatef(90, 10, 0, 0)
numberOfPoints = len(vertices) // 6 # 12 components per attrribute tuple
bufferObj = createBuffer(vertices)
mousePosition = pygame.mouse.get_rel()
while True:
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
#Cube()
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
glTranslatef(-0.5, 0, 0)
if event.key == pygame.K_RIGHT:
glTranslatef(0.5, 0, 0)
if event.key == pygame.K_UP:
glTranslatef(0, 0.5, 0)
if event.key == pygame.K_DOWN:
glTranslatef(0, -0.5, 0)
if pygame.mouse.get_pressed() == (1, 0, 0):
mousePosition = pygame.mouse.get_rel()
glRotatef(mousePosition[0]/3*-1, 0, 0, 1)
#glRotatef(mousePosition[1]/3, 0, 0, 0)
else:
mousePosition = pygame.mouse.get_rel()
drawBuffer(bufferObj, numberOfPoints)
pygame.display.flip()
#pygame.time.wait(1)
main()