From af54745ec931c0b0b6cfffef60d2f417ec75d7eb Mon Sep 17 00:00:00 2001 From: raphael60650 Date: Sun, 1 Aug 2021 19:11:18 +0200 Subject: [PATCH] try to get minimap image from its brres file --- scripts/obj_to_png (minimap).py | 71 +++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 scripts/obj_to_png (minimap).py diff --git a/scripts/obj_to_png (minimap).py b/scripts/obj_to_png (minimap).py new file mode 100644 index 0000000..8928d89 --- /dev/null +++ b/scripts/obj_to_png (minimap).py @@ -0,0 +1,71 @@ +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_box = (scene.vertices[0], scene.vertices[0]) +for vertex in scene.vertices: + min_v = [min(scene_box[0][i], vertex[i]) for i in range(3)] + 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)] +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)] + +def Model(): + glPushMatrix() + glScalef(*scene_scale) + glTranslatef(*scene_trans) + 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 + + 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) + + glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT) + + 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() + +main()