Skip to content

Instantly share code, notes, and snippets.

@fogleman
Created May 5, 2016 22:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fogleman/bcae6f4b47b58c1ed98507c122f35abf to your computer and use it in GitHub Desktop.
Save fogleman/bcae6f4b47b58c1ed98507c122f35abf to your computer and use it in GitHub Desktop.
elevation.py
import pg
class Window(pg.Window):
def setup(self):
self.set_clear_color(0.87, 0.81, 0.70)
self.wasd = pg.WASD(self, speed=0.3)
self.wasd.look_at((0, 0, 0), (30, -5, 30))
self.context = pg.Context(pg.DirectionalLightProgram())
self.context.specular_multiplier = 0.25
self.context.ambient_color = (0.5, 0.5, 0.5)
self.context.light_color = (0.5, 0.5, 0.5)
self.context.use_texture = True
self.context.sampler = pg.Texture(0, '/Users/fogleman/go/src/github.com/fogleman/density/texture.png')
mesh = pg.STL('/Users/fogleman/go/src/github.com/fogleman/pt/mesh.stl').smooth_normals()
mesh = mesh.swap_axes(0, 2, -1)
(x0, y0, z0), (x1, y1, z1) = pg.bounding_box(mesh.positions)
for x, y, z in mesh.positions:
u = (x - x0) / (x1 - x0)
v = (z - z0) / (z1 - z0)
mesh.uvs.append((u, v))
self.mesh = mesh
# sky dome
self.sky = pg.Context(pg.TextureProgram())
self.sky.sampler = pg.Texture(2, '/Users/fogleman/Desktop/sky.jpg')
self.sky_sphere = pg.Sphere(4).reverse_winding()
def draw_sky(self):
matrix = self.wasd.get_matrix(translate=False)
matrix = matrix.perspective(65, self.aspect, 0.1, 1)
self.sky.matrix = matrix
self.sky_sphere.draw(self.sky)
def draw(self):
self.clear()
self.draw_sky()
self.clear_depth_buffer()
matrix = self.wasd.get_matrix()
matrix = matrix.perspective(65, self.aspect, 0.001, 10)
self.context.matrix = matrix
self.context.camera_position = self.wasd.position
self.mesh.draw(self.context)
if __name__ == "__main__":
pg.run(Window)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment