mirror of
https://github.com/quantum5/punyverse.git
synced 2025-04-24 13:11:57 -04:00
Sky cubemap loading progress.
This commit is contained in:
parent
f181ac00f5
commit
e33c90e9bf
|
@ -121,14 +121,14 @@ class Belt(Entity):
|
|||
class Sky(Entity):
|
||||
background = True
|
||||
|
||||
def __init__(self, world, info):
|
||||
def __init__(self, world, info, callback=None):
|
||||
pitch = world.evaluate(info.get('pitch', 0))
|
||||
yaw = world.evaluate(info.get('yaw', 0))
|
||||
roll = world.evaluate(info.get('roll', 0))
|
||||
|
||||
super(Sky, self).__init__(world, 'Sky', (0, 0, 0), [pitch, yaw, roll])
|
||||
|
||||
self.texture = get_best_texture(info['texture'], loader=get_cube_map)
|
||||
self.texture = get_best_texture(info['texture'], loader=get_cube_map, callback=callback)
|
||||
self.constellation = get_cube_map(info['constellation'])
|
||||
self.cube = Cube()
|
||||
|
||||
|
|
|
@ -260,8 +260,9 @@ def load_clouds(file):
|
|||
return id
|
||||
|
||||
|
||||
def get_cube_map(files):
|
||||
def get_cube_map(files, callback=None):
|
||||
assert len(files) == 6
|
||||
callback = callback or (lambda index, file: None)
|
||||
|
||||
buffer = GLuint()
|
||||
glGenTextures(1, byref(buffer))
|
||||
|
@ -270,16 +271,17 @@ def get_cube_map(files):
|
|||
glBindTexture(GL_TEXTURE_CUBE_MAP, id)
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_BASE_LEVEL, 0)
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAX_LEVEL, 0)
|
||||
for file, part in zip(files, [
|
||||
for index, (file, part) in enumerate(zip(files, [
|
||||
GL_TEXTURE_CUBE_MAP_POSITIVE_X,
|
||||
GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
|
||||
GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
|
||||
GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
|
||||
GL_TEXTURE_CUBE_MAP_POSITIVE_Z,
|
||||
GL_TEXTURE_CUBE_MAP_NEGATIVE_Z,
|
||||
]):
|
||||
])):
|
||||
try:
|
||||
path, file = get_file_path(file)
|
||||
callback(index, file)
|
||||
path, width, height, depth, mode, texture = load_image(file, path)
|
||||
except Exception:
|
||||
glDeleteTextures(1, byref(buffer))
|
||||
|
|
|
@ -122,8 +122,9 @@ class World(object):
|
|||
self.tracker.append(Belt(name, self, info))
|
||||
|
||||
if 'sky' in root:
|
||||
self.callback('Loading sky...', 'Loading sky.', 0)
|
||||
self.tracker.append(Sky(self, root['sky']))
|
||||
def callback(index, file):
|
||||
self.callback('Loading sky...', 'Loading %s.' % file, index / 6)
|
||||
self.tracker.append(Sky(self, root['sky'], callback))
|
||||
|
||||
if 'asteroids' in root:
|
||||
asteroids = root['asteroids']
|
||||
|
|
Loading…
Reference in a new issue