Exemple #1
0
 def run(self):
     context = pg.Context(Program())
     font = pg.Font(self, 2, FONT, 24, (0, 0, 0, 1))
     self.message = 'loading triangle mesh'
     mesh = pg.STL('examples/%s.stl' % NAME).center()
     self.triangles = '%d triangles' % (len(mesh.positions) / 3)
     self.message = 'computing bounding box'
     (x0, y0, z0), (x1, y1, z1) = pg.bounding_box(mesh.positions)
     context.uv0 = (x0, z0)
     context.uv1 = (x1, z1)
     self.message = 'generating vertex buffer'
     context.position = pg.VertexBuffer(mesh.positions)
     self.message = 'generating height map'
     p = mesh.positions
     lookup = defaultdict(list)
     for v1, v2, v3 in zip(p[::3], p[1::3], p[2::3]):
         x, y, z = v1
         x, z = int(round(x / STEP)), int(round(z / STEP))
         lookup[(x, z)].append((v1, v2, v3))
     self.message = 'loading brightness texture'
     context.sampler = pg.Texture(0, 'examples/%s.jpg' % NAME)
     self.message = 'loading normal texture'
     context.normal_sampler = pg.Texture(1, 'examples/%s.png' % NAME)
     self.result = {
         'font': font,
         'context': context,
         'lookup': lookup,
     }
Exemple #2
0
 def setup(self):
     self.font = pg.Font(self, 0, '/Library/Fonts/Arial.ttf', 24)
     self.wasd = pg.WASD(self, speed=5)
     self.wasd.look_at((14, 0, 0), (0, 0, 0))
     self.context = pg.Context(pg.DirectionalLightProgram())
     self.sphere = pg.Sphere(5, 0.4, (0, 0, 0))
     self.context.ambient_color = (0.4, 0.4, 0.4)
     self.context.light_color = (0.6, 0.6, 0.6)
Exemple #3
0
 def setup(self):
     self.font = pg.Font(self, 1, '/Library/Fonts/Arial.ttf', 24)
     self.wasd = pg.WASD(self)
     self.wasd.look_at(pg.normalize((1, 0, 1)), (0, 0, 0))
     self.context = pg.Context(pg.DirectionalLightProgram())
     self.context.sampler = pg.Texture(0, 'examples/earth.png')
     self.context.use_texture = True
     sphere = pg.Sphere(4, 0.5, (0, 0, 0))
     self.context.position = pg.VertexBuffer(sphere.positions)
     self.context.normal = pg.VertexBuffer(sphere.normals)
     self.context.uv = pg.VertexBuffer(sphere.uvs)
Exemple #4
0
 def setup(self):
     self.device = gps.Device()
     pg. async (self.device.run)
     self.fix = False
     self.font = pg.Font(self, 3, FONT, 18, bg=(0, 0, 0))
     self.wasd = pg.WASD(self, speed=SPEED)
     self.wasd.look_at((0, 0, EARTH_RADIUS + ALTITUDE * 2), (0, 0, 0))
     # stars
     self.stars = pg.Context(StarsProgram())
     self.stars.sampler = pg.Texture(2, 'resources/stars.png')
     self.stars_sphere = pg.Sphere(4).reverse_winding()
     # earth
     self.earth = pg.Context(EarthProgram())
     self.earth.day = pg.Texture(0, 'resources/earth_day.jpg')
     self.earth.night = pg.Texture(1, 'resources/earth_night.jpg')
     self.earth.ambient_color = (0.4, 0.4, 0.4)
     self.earth.light_color = (1.25, 1.25, 1.25)
     self.earth.specular_power = 20.0
     self.earth.specular_multiplier = 0.3
     self.earth_sphere = pg.Sphere(5, EARTH_RADIUS)
     # moon
     self.moon = pg.Context(pg.DirectionalLightProgram())
     self.moon.use_texture = True
     self.moon.sampler = pg.Texture(4, 'resources/moon.jpg')
     self.moon.ambient_color = (0.1, 0.1, 0.1)
     self.moon.light_color = (1.3, 1.3, 1.3)
     self.moon.specular_power = 20.0
     self.moon.specular_multiplier = 0.3
     self.moon_sphere = pg.Sphere(4, MOON_RADIUS)
     # satellites
     self.context = pg.Context(pg.DirectionalLightProgram())
     self.context.object_color = (1, 1, 1)
     m = SATELLITE_SCALE
     self.satellite = pg.STL('resources/dawn.stl').center()
     self.satellite = pg.Matrix().scale((m, m, m)) * self.satellite
     # lines
     self.lines = pg.Context(pg.SolidColorProgram())
     self.lines.color = (1, 1, 1, 0.25)
Exemple #5
0
 def setup(self):
     self.font = pg.Font(self, 0, '/Library/Fonts/Arial.ttf', 72)
Exemple #6
0
 def setup(self):
     self.title_font = pg.Font(self, 3, FONT, 72, (0, 0, 0, 1))
     self.font = pg.Font(self, 4, FONT, 36, (0, 0, 0, 1))