-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPython3dRenderCode.py
More file actions
85 lines (77 loc) · 2.45 KB
/
Python3dRenderCode.py
File metadata and controls
85 lines (77 loc) · 2.45 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
import pygame
import sys
from pygame.locals import*
from OpenGL.GL import*
from OpenGL.GLU import*
vertextxt = "YOUR VERTEX.TXT FILE PATH HERE" #path to our txt files
facestxt = "YOUR FACES.TXT FILE PATH HERE" #example C:\\Users\\Johno\\Desktop\\txtFiles\\faces.txt
paints = [ #colors for our faces
(0,255,0), #green
(255,0,0), #red
(255,255,0), #yellow
(0,255,255), #cyan
(0,0,255), #blue
(255,255,255) #white
]
def get_list(txtname):
listname = []
with open(txtname) as f:
for line in f:
line = line.rstrip(",\r\n").replace("(",'').replace(")","").replace(" ",'')
row = list(line.split(","))
listname.append(row)
listname = [[float(j) for j in i] for i in listname]
return listname
modelVerts = get_list(vertextxt) #list of vertices
modelFaces = get_list(facestxt) #list of faces
def drawfaces():
glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT) #clears each frame
glBegin(GL_TRIANGLES) #drawing method
for eachface in (modelFaces): #each face in list of faces
color = 0
for eachvert in eachface: #each point in each face
color +=1
if color >5:
color = 0
glColor3fv(paints[color]) #adding one solid color
glVertex3fv(modelVerts[int(eachvert)]) #rendering triangles
glEnd()
def main():
pygame.init()
display = (800,800) #set window
pygame.display.set_caption("RENDERING OBJECT")
FPS = pygame.time.Clock() #fps func
pygame.display.set_mode(display, DOUBLEBUF|OPENGL)
gluPerspective(45,1,.1,50)
glTranslate(0,0,-5) #xyz
glRotate(-90,1,0,0)
Left = False
Right = False
def moveOBJ():
if Left:
glRotate(-1,0,0,1)
if Right:
glRotate(1,0,0,1)
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == KEYDOWN:
if event.key == K_ESCAPE:
pygame.quit()
sys.exit()
if event.key == K_a:
Left = True
if event.key == K_d:
Right = True
if event.type == KEYUP:
if event.key == K_a:
Left = False
if event.key == K_d:
Right = False
pygame.display.flip()
drawfaces()
moveOBJ()
FPS.tick(60)
main()