mirror of
https://github.com/Faraphel/Atlas-Install.git
synced 2025-07-03 03:08:29 +02:00
reformatted the file
This commit is contained in:
parent
7683083deb
commit
cdbb2f6493
1 changed files with 31 additions and 26 deletions
|
@ -1,12 +1,12 @@
|
|||
import pygame
|
||||
import OpenGL
|
||||
from pygame.locals import *
|
||||
from OpenGL.GL import *
|
||||
from OpenGL.GLU import *
|
||||
import pywavefront
|
||||
from PIL import Image
|
||||
|
||||
scene = pywavefront.Wavefront(r"D:\Users\RC606\Desktop\Programme\MKWF-Install\test\Track-WU8\map_model.obj", collect_faces=True)
|
||||
scene = pywavefront.Wavefront(r"D:\Users\RC606\Desktop\Programme\MKWF-Install\test\Track-WU8\map_model.obj",
|
||||
collect_faces=True)
|
||||
|
||||
scene_box = (scene.vertices[0], scene.vertices[0])
|
||||
for vertex in scene.vertices:
|
||||
|
@ -14,58 +14,63 @@ for vertex in scene.vertices:
|
|||
max_v = [max(scene_box[1][i], vertex[i]) for i in range(3)]
|
||||
scene_box = (min_v, max_v)
|
||||
|
||||
scene_size = [scene_box[1][i]-scene_box[0][i] for i in range(3)]
|
||||
scene_size = [scene_box[1][i] - scene_box[0][i] for i in range(3)]
|
||||
max_scene_size = max(scene_size)
|
||||
scaled_size = 5
|
||||
scene_scale = [scaled_size/max_scene_size for i in range(3)]
|
||||
scene_trans = [-(scene_box[1][i]+scene_box[0][i])/2 for i in range(3)]
|
||||
scaled_size = 5
|
||||
scene_scale = [scaled_size / max_scene_size for i in range(3)]
|
||||
scene_trans = [-(scene_box[1][i] + scene_box[0][i]) / 2 for i in range(3)]
|
||||
|
||||
def Model():
|
||||
|
||||
def model():
|
||||
glPushMatrix()
|
||||
glScalef(*scene_scale)
|
||||
glTranslatef(*scene_trans)
|
||||
glPolygonMode(GL_FRONT_AND_BACK,GL_FILL)
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
|
||||
|
||||
color_axe = 1
|
||||
|
||||
|
||||
for mesh in scene.mesh_list:
|
||||
max_height, min_height = float("-inf"), float("inf")
|
||||
for face in mesh.faces:
|
||||
for vertex_i in face:
|
||||
height = scene.vertices[vertex_i][color_axe]
|
||||
if height > max_height: max_height = height
|
||||
elif height < min_height: min_height = height
|
||||
if height > max_height:
|
||||
max_height = height
|
||||
elif height < min_height:
|
||||
min_height = height
|
||||
|
||||
min_height -= (max_height - min_height) // 4
|
||||
|
||||
|
||||
glBegin(GL_TRIANGLES)
|
||||
for face in mesh.faces:
|
||||
for vertex_i in face:
|
||||
height = scene.vertices[vertex_i][color_axe]
|
||||
color = (height - min_height) / max_height
|
||||
|
||||
|
||||
glColor3f(color, color, color)
|
||||
glVertex3f(*scene.vertices[vertex_i])
|
||||
glEnd()
|
||||
|
||||
glPopMatrix()
|
||||
|
||||
|
||||
def main():
|
||||
display = (600, 600)
|
||||
window = pygame.display.set_mode(display, DOUBLEBUF | OPENGL)
|
||||
gluPerspective(45, (display[0] / display[1]), 1, 500.0)
|
||||
glTranslatef(0.0, 0.0, -6.5)
|
||||
glRotatef(90, 1, 0, 0)
|
||||
display = (600, 600)
|
||||
window = pygame.display.set_mode(display, DOUBLEBUF | OPENGL)
|
||||
gluPerspective(45, (display[0] / display[1]), 1, 500.0)
|
||||
glTranslatef(0.0, 0.0, -6.5)
|
||||
glRotatef(90, 1, 0, 0)
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
|
||||
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
|
||||
Model()
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
|
||||
model()
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
|
||||
|
||||
pix = glReadPixels(0, 0, *display, GL_RGB, GL_UNSIGNED_BYTE)
|
||||
image = Image.frombytes(mode="RGB", size=display, data=pix)
|
||||
image.save("test.png")
|
||||
exit()
|
||||
|
||||
pix = glReadPixels(0, 0, *display, GL_RGB, GL_UNSIGNED_BYTE)
|
||||
image = Image.frombytes(mode="RGB", size=display, data=pix)
|
||||
image.save("test.png")
|
||||
exit()
|
||||
|
||||
main()
|
||||
|
|
Loading…
Reference in a new issue