Removed cheap texture hacks.

This commit is contained in:
Quantum 2018-08-22 22:35:36 -04:00
parent 50b8d39b71
commit 1b973b0082
2 changed files with 24 additions and 57 deletions

View file

@ -1,6 +1,5 @@
from math import sqrt from math import sqrt
from six.moves import range
from pyglet.gl import * from pyglet.gl import *
from punyverse.orbit import KeplerOrbit from punyverse.orbit import KeplerOrbit

View file

@ -1,7 +1,7 @@
from __future__ import print_function from __future__ import print_function
from collections import OrderedDict
import os import os
from collections import OrderedDict
try: try:
import json import json
@ -28,37 +28,16 @@ from math import pi, sqrt
G = 6.67384e-11 # Gravitation Constant G = 6.67384e-11 # Gravitation Constant
def get_best_texture(info, optional=False, loader=load_texture): def get_best_texture(info, loader=load_texture):
cheap = False
skip = False
texture = None
if isinstance(info, list): if isinstance(info, list):
for item in info: for item in info:
if isinstance(item, list):
if len(item) == 4:
cheap = True
texture = item
break
continue
try: try:
texture = loader(item) return loader(item)
except ValueError: except ValueError:
pass pass
else:
break
else:
cheap = True
texture = [1, 1, 1, 1]
else: else:
try: return loader(info)
texture = loader(info) raise ValueError('No texture found')
except ValueError:
if optional:
skip = True
else:
cheap = True
texture = [1, 1, 1, 1]
return cheap, skip, texture
def load_world(file, callback=lambda message, completion: None): def load_world(file, callback=lambda message, completion: None):
@ -176,18 +155,13 @@ class World(object):
division = info.get('division', max(min(int(radius / 8), 60), 10)) division = info.get('division', max(min(int(radius / 8), 60), 10))
if 'texture' in info: if 'texture' in info:
cheap, skip, texture = get_best_texture(info['texture'], optional=info.get('optional', False)) texture = get_best_texture(info['texture'])
if skip: if self.options.get('normal', False) and 'normal' in info:
return object_id = compile(normal_sphere, radius, division, texture,
if cheap: info['normal'], lighting=lighting, inside=background)
object_id = compile(colourball, radius, division, division, texture)
else: else:
if self.options.get('normal', False) and 'normal' in info: object_id = compile(sphere, radius, division, division, texture,
object_id = compile(normal_sphere, radius, division, texture, lighting=lighting, inside=background)
info['normal'], lighting=lighting, inside=background)
else:
object_id = compile(sphere, radius, division, division, texture,
lighting=lighting, inside=background)
elif 'model' in info: elif 'model' in info:
scale = info.get('scale', 1) scale = info.get('scale', 1)
object_id = model_list(load_model(info['model']), info.get('sx', scale), info.get('sy', scale), object_id = model_list(load_model(info['model']), info.get('sx', scale), info.get('sy', scale),
@ -229,23 +203,19 @@ class World(object):
cloud_texture = atmosphere_data.get('cloud_texture', None) cloud_texture = atmosphere_data.get('cloud_texture', None)
corona_texture = atmosphere_data.get('corona_texture', None) corona_texture = atmosphere_data.get('corona_texture', None)
if cloud_texture is not None: if cloud_texture is not None:
cheap, _, cloud_texture = get_best_texture(cloud_texture, loader=load_clouds) cloud_texture = get_best_texture(cloud_texture, loader=load_clouds)
if not cheap: cloudmap_id = compile(sphere, radius + 2, division, division, cloud_texture, lighting=False)
cloudmap_id = compile(sphere, radius + 2, division, division, cloud_texture,
lighting=False)
if corona_texture is not None: if corona_texture is not None:
cheap, _, corona = get_best_texture(corona_texture) corona = get_best_texture(corona_texture)
if not cheap: corona_size = atmosphere_data.get('corona_size', radius / 2)
corona_size = atmosphere_data.get('corona_size', radius / 2) corona_division = atmosphere_data.get('corona_division', 100)
corona_division = atmosphere_data.get('corona_division', 100) corona_ratio = atmosphere_data.get('corona_ratio', 0.5)
corona_ratio = atmosphere_data.get('corona_ratio', 0.5) corona_id = compile(flare, radius, radius + corona_size, corona_division, corona_ratio, corona)
corona_id = compile(flare, radius, radius + corona_size, corona_division,
corona_ratio, corona)
if atm_texture is not None: if atm_texture is not None:
cheap, _, atm_texture = get_best_texture(atm_texture) atm_texture = get_best_texture(atm_texture)
if not cheap: atmosphere_id = compile(disk, radius, radius + atm_size, 30, atm_texture)
atmosphere_id = compile(disk, radius, radius + atm_size, 30, atm_texture)
theta = 360.0 / rotation if rotation else 0 theta = 360.0 / rotation if rotation else 0
object = type(object_id, (x, y, z), (pitch, yaw, roll), rotation_angle=theta, object = type(object_id, (x, y, z), (pitch, yaw, roll), rotation_angle=theta,
@ -262,11 +232,9 @@ class World(object):
yaw = self._eval(ring_data.get('yaw', yaw)) yaw = self._eval(ring_data.get('yaw', yaw))
roll = self._eval(ring_data.get('roll', roll)) roll = self._eval(ring_data.get('roll', roll))
cheap, _, texture = get_best_texture(texture) texture = get_best_texture(texture)
if not cheap: self.tracker.append(type(compile(disk, distance, distance + size, 30, texture), (x, y, z),
self.tracker.append( (pitch, yaw, roll), **params))
type(compile(disk, distance, distance + size, 30, texture), (x, y, z),
(pitch, yaw, roll), **params))
for satellite, info in six.iteritems(info.get('satellites', {})): for satellite, info in six.iteritems(info.get('satellites', {})):
message = 'Loading %s, satellite of %s.' % (satellite, name) message = 'Loading %s, satellite of %s.' % (satellite, name)