mirror of
https://github.com/Faraphel/Atlas-Install.git
synced 2025-07-04 03:38:26 +02:00
try to get minimap image from its brres file
This commit is contained in:
parent
9673a63e4c
commit
af54745ec9
1 changed files with 71 additions and 0 deletions
71
scripts/obj_to_png (minimap).py
Normal file
71
scripts/obj_to_png (minimap).py
Normal file
|
@ -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()
|
Loading…
Reference in a new issue