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
f11e0b6fc7
commit
9d73059ad0
|
@ -121,14 +121,14 @@ class Belt(Entity):
|
||||||
class Sky(Entity):
|
class Sky(Entity):
|
||||||
background = True
|
background = True
|
||||||
|
|
||||||
def __init__(self, world, info):
|
def __init__(self, world, info, callback=None):
|
||||||
pitch = world.evaluate(info.get('pitch', 0))
|
pitch = world.evaluate(info.get('pitch', 0))
|
||||||
yaw = world.evaluate(info.get('yaw', 0))
|
yaw = world.evaluate(info.get('yaw', 0))
|
||||||
roll = world.evaluate(info.get('roll', 0))
|
roll = world.evaluate(info.get('roll', 0))
|
||||||
|
|
||||||
super(Sky, self).__init__(world, 'Sky', (0, 0, 0), [pitch, yaw, roll])
|
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.constellation = get_cube_map(info['constellation'])
|
||||||
self.cube = Cube()
|
self.cube = Cube()
|
||||||
|
|
||||||
|
|
|
@ -260,8 +260,9 @@ def load_clouds(file):
|
||||||
return id
|
return id
|
||||||
|
|
||||||
|
|
||||||
def get_cube_map(files):
|
def get_cube_map(files, callback=None):
|
||||||
assert len(files) == 6
|
assert len(files) == 6
|
||||||
|
callback = callback or (lambda index, file: None)
|
||||||
|
|
||||||
buffer = GLuint()
|
buffer = GLuint()
|
||||||
glGenTextures(1, byref(buffer))
|
glGenTextures(1, byref(buffer))
|
||||||
|
@ -270,16 +271,17 @@ def get_cube_map(files):
|
||||||
glBindTexture(GL_TEXTURE_CUBE_MAP, id)
|
glBindTexture(GL_TEXTURE_CUBE_MAP, id)
|
||||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_BASE_LEVEL, 0)
|
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_BASE_LEVEL, 0)
|
||||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAX_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_POSITIVE_X,
|
||||||
GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
|
GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
|
||||||
GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
|
GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
|
||||||
GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
|
GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
|
||||||
GL_TEXTURE_CUBE_MAP_POSITIVE_Z,
|
GL_TEXTURE_CUBE_MAP_POSITIVE_Z,
|
||||||
GL_TEXTURE_CUBE_MAP_NEGATIVE_Z,
|
GL_TEXTURE_CUBE_MAP_NEGATIVE_Z,
|
||||||
]):
|
])):
|
||||||
try:
|
try:
|
||||||
path, file = get_file_path(file)
|
path, file = get_file_path(file)
|
||||||
|
callback(index, file)
|
||||||
path, width, height, depth, mode, texture = load_image(file, path)
|
path, width, height, depth, mode, texture = load_image(file, path)
|
||||||
except Exception:
|
except Exception:
|
||||||
glDeleteTextures(1, byref(buffer))
|
glDeleteTextures(1, byref(buffer))
|
||||||
|
|
|
@ -122,8 +122,9 @@ class World(object):
|
||||||
self.tracker.append(Belt(name, self, info))
|
self.tracker.append(Belt(name, self, info))
|
||||||
|
|
||||||
if 'sky' in root:
|
if 'sky' in root:
|
||||||
self.callback('Loading sky...', 'Loading sky.', 0)
|
def callback(index, file):
|
||||||
self.tracker.append(Sky(self, root['sky']))
|
self.callback('Loading sky...', 'Loading %s.' % file, index / 6)
|
||||||
|
self.tracker.append(Sky(self, root['sky'], callback))
|
||||||
|
|
||||||
if 'asteroids' in root:
|
if 'asteroids' in root:
|
||||||
asteroids = root['asteroids']
|
asteroids = root['asteroids']
|
||||||
|
|
Loading…
Reference in a new issue