示例#1
0
def keyPressed(key,x,y,scene):
    delta = 0.05
    cam = scene.cam
    if key == '\033':
        sys.exit(1)
    if key == 'w':
        delta_pos = - cam.rot() * vec3(0,0,1)
        for i in range(0,3):
            cam.pos[i] += delta * delta_pos[i]
    if key == 's':
        delta_pos = cam.rot() * vec3(0,0,1)
        for i in range(0,3):
            cam.pos[i] += delta * delta_pos[i]
    if key == 'a':
        delta_pos = - cam.rot() * vec3(1,0,0)
        for i in range(0,3):
            cam.pos[i] += delta * delta_pos[i]
    if key == 'd':
        delta_pos = cam.rot() * vec3(1,0,0)
        for i in range(0,3):
            cam.pos[i] += delta * delta_pos[i]

    if key == 'z':
        model = scene.models[0]
        for m in model.models:
            m.material.bump_height += 0.005
    if key == 'x':
        model = scene.models[0]
        for m in model.models:
            m.material.bump_height -= 0.005
示例#2
0
def calculateTangents(positions, normals, texcoords, elements):

    #We want our tangent space to be aligned such that
    #the x axis corresponds to the u direction in the bump map and
    # the y axis corresponds to the v direction in the bump map.
    #That is, if Q represents a point inside the triangle,
    # we would like to be able to write
    #Q - P0 = (u - u0)T + (v - v0)B

    vcount = len(positions)
    tan1 = numpy.zeros((vcount, 3), dtype='float32')
    tan2 = numpy.zeros((vcount, 3), dtype='float32')
    tangents = numpy.zeros((vcount, 4), dtype='float32')

    for (i1, i2, i3) in elements:
        v1, v2, v3 = positions[i1], positions[i2], positions[i3]
        w1, w2, w3 = texcoords[i1], texcoords[i2], texcoords[i3]

        x1, y1, z1 = v2 - v1
        x2, y2, z2 = v3 - v1

        s1, t1 = w2 - w1
        s2, t2 = w3 - w1

        r = 1.0 / (s1 * t2 - s2 * t1)

        sdir = [(t2 * x1 - t1 * x2) * r, (t2 * y1 - t1 * y2) * r,
                (t2 * z1 - t1 * z2) * r]
        tdir = [(s1 * x2 - s2 * x1) * r, (s1 * y2 - s2 * y1) * r,
                (s1 * z2 - s2 * z1) * r]

        tan1[i1] += sdir
        tan1[i2] += sdir
        tan1[i3] += sdir

        tan2[i1] += tdir
        tan2[i2] += tdir
        tan2[i3] += tdir

    for i in range(0, vcount):
        vn = normals[i]
        vt = tan1[i]
        n = vec3(float(vn[0]), float(vn[1]), float(vn[2]))
        t = vec3(float(vt[0]), float(vt[1]), float(vt[2]))

        #Gram-Scmidt orthogonalize
        tan = (t - n * (n * t)).normalize()
        tangents[i] = tan[0], tan[1], tan[2], 0

        #Handedness
        vt2 = tan2[i]
        t2 = vec3(float(vt2[0]), float(vt2[1]), float(vt2[2]))
        h = (n.cross(t)) * t2
        if h < 0:
            tangents[i][3] = -1.0
        else:
            tangents[i][3] = 1.0

    #In the end, B = (NxT)*T_w
    return tangents
示例#3
0
def keyPressed(key, x, y, scene):
    delta = 0.05
    cam = scene.cam
    if key == '\033':
        sys.exit(1)
    if key == 'w':
        delta_pos = -cam.rot() * vec3(0, 0, 1)
        for i in range(0, 3):
            cam.pos[i] += delta * delta_pos[i]
    if key == 's':
        delta_pos = cam.rot() * vec3(0, 0, 1)
        for i in range(0, 3):
            cam.pos[i] += delta * delta_pos[i]
    if key == 'a':
        delta_pos = -cam.rot() * vec3(1, 0, 0)
        for i in range(0, 3):
            cam.pos[i] += delta * delta_pos[i]
    if key == 'd':
        delta_pos = cam.rot() * vec3(1, 0, 0)
        for i in range(0, 3):
            cam.pos[i] += delta * delta_pos[i]

    if key == 'z':
        model = scene.models[0]
        for m in model.models:
            m.material.bump_height += 0.005
    if key == 'x':
        model = scene.models[0]
        for m in model.models:
            m.material.bump_height -= 0.005
示例#4
0
 def __init__(self,uniform,sm_uniform):
     self.uniform = uniform
     self.sm_uniform = sm_uniform
     self.intensity = 1.
     self.color = vec3(1.,1.,1.)
     self.pos = vec3(0.,0.,0.)
     self.dir = vec3(0.,0.,1.)
     self.aperture = 1. #half angle of aperture
     self.reach   = 1. #maximum reach
     self.ang_dimming = 2. #dimming factor as it faces away from a normal
     self.dist_dimming = 0.5 #linear dimming factor as the object is further
     self.specular_exponent = 32
     self.generates_shadow_map = True
示例#5
0
 def __init__(self, uniform, sm_uniform):
     self.uniform = uniform
     self.sm_uniform = sm_uniform
     self.intensity = 1.
     self.color = vec3(1., 1., 1.)
     self.pos = vec3(0., 0., 0.)
     self.dir = vec3(0., 0., 1.)
     self.aperture = 1.  #half angle of aperture
     self.reach = 1.  #maximum reach
     self.ang_dimming = 2.  #dimming factor as it faces away from a normal
     self.dist_dimming = 0.5  #linear dimming factor as the object is further
     self.specular_exponent = 32
     self.generates_shadow_map = True
示例#6
0
    def cam(self):
        cam = Cam()
        cam.pos = self.pos
        aperture_deg = 2 * 180 * self.aperture / pi
        cam.projTransf = mat4.perspective(aperture_deg,1.,0.1,self.reach)    
        self.dir = self.dir.normalize()

        if self.dir == vec3(0.,0.,1.):
            rot_axis = vec3(1.,0.,0.)
            cos_alpha = vec3(0.,self.dir[1],self.dir[2]).normalize() * vec3(1.,0.,0.)
            angle = acos(-cos_alpha)
        else:
            rot_axis = self.dir.cross(vec3(0.,0.,1.)).normalize()
            cos_alpha = vec3(self.dir[0],self.dir[1],0.).normalize()*self.dir.normalize()
            angle = acos(-cos_alpha)

        cam.ori.fromAngleAxis(angle,rot_axis)
        return cam
示例#7
0
    def cam(self):
        cam = Cam()
        cam.pos = self.pos
        aperture_deg = 2 * 180 * self.aperture / pi
        cam.projTransf = mat4.perspective(aperture_deg, 1., 0.1, self.reach)
        self.dir = self.dir.normalize()

        if self.dir == vec3(0., 0., 1.):
            rot_axis = vec3(1., 0., 0.)
            cos_alpha = vec3(0., self.dir[1], self.dir[2]).normalize() * vec3(
                1., 0., 0.)
            angle = acos(-cos_alpha)
        else:
            rot_axis = self.dir.cross(vec3(0., 0., 1.)).normalize()
            cos_alpha = vec3(self.dir[0], self.dir[1],
                             0.).normalize() * self.dir.normalize()
            angle = acos(-cos_alpha)

        cam.ori.fromAngleAxis(angle, rot_axis)
        return cam
示例#8
0
 def __init__(self):
     self.intensity = 0.5
     self.color = vec3(1.0,1.0,1.0)
     self.uniform = 'ambient_light'
示例#9
0
def keyPressed(key,x,y,scene):
    global main_program
    global sec_program
    delta = 0.05
    cam = scene.cam
    if key == '\033' or key == 'q':
        sys.exit(1)
    if key == '1':
        scene.active_program = main_program
    if key == '2':
        scene.active_program = sec_program
    if key == 'w':
        delta_pos = - cam.rot() * vec3(0,0,1)
        for i in range(0,3):
            cam.pos[i] += delta * delta_pos[i]
    if key == 's':
        delta_pos = cam.rot() * vec3(0,0,1)
        for i in range(0,3):
            cam.pos[i] += delta * delta_pos[i]
    if key == 'a':
        delta_pos = - cam.rot() * vec3(1,0,0)
        for i in range(0,3):
            cam.pos[i] += delta * delta_pos[i]
    if key == 'd':
        delta_pos = cam.rot() * vec3(1,0,0)
        for i in range(0,3):
            cam.pos[i] += delta * delta_pos[i]

    if key == 'z':
        model = scene.models[0]
        for m in model.models:
            m.material.bump_height += 0.005
    if key == 'x':
        model = scene.models[0]
        for m in model.models:
            m.material.bump_height -= 0.005

            
    light = scene.lights.spots[0]
    model = scene.models[0]

    if key == 't':
        model.props.pos.x += 0.1
    if key == 'r':
        model.props.pos.x -= 0.1
    if key == 'g':
        model.props.pos.z += 0.1
    if key == 'f':
        model.props.pos.z -= 0.1
    if key == 'b':
        model.props.pos.y += 0.1
    if key == 'v':
        model.props.pos.y -= 0.1

    if key == 'h':
        light.pos.x += 0.1
    if key == 'k':
        light.pos.x -= 0.1
    if key == 'u':
        light.pos.z += 0.1
    if key == 'j':
        light.pos.z -= 0.1
    if key == 'o':
        light.intensity += 0.1
    if key == 'l':
        light.intensity -= 0.1
    if key == 'y':
        light.pos.y += 0.1
    if key == 'i':
        light.pos.y -= 0.1
示例#10
0
def main():

    scene = Scene()
    scene.screen.size = (800,600)
    startOpengl(scene.screen.size[0],scene.screen.size[1])

    global main_program

    print 'Initializing main shaders'
    main_program = initShaders("shaders/3ds.vert", 
                                      "shaders/3ds.frag",
                                      "shaders/detail-3ds.geom")
    
    global sec_program
    print 'Initializing secondary shaders'
    sec_program = initShaders("shaders/parallaxOcclusionSelfShadow.vert", 
                              "shaders/parallaxOcclusionSelfShadow.frag")


    scene.active_program = main_program

    # scene.active_program = initShaders("shaders/3ds.vert", "shaders/3ds.frag")
    # scene.active_program = initShaders("shaders/parallax.vert", "shaders/parallax.frag")
    # scene.active_program = initShaders("shaders/relief.vert", "shaders/relief.frag")

    scene.initShadowFB()

    # teapot_index = scene.loadObjModel('models/teapot.obj')
    # if teapot_index == None:
    #     print 'Error loading model'
    #     exit(-1)
    # teapot = scene.models[teapot_index]
    # for m in teapot.models:
    #     m.material.ambient = vec4(1,0.2,0.2,1)
    #     tm = m.material.texture1_map
    #     nm = m.material.normal_map
    #     hm = m.material.height_map
    #     tm.name = 'textures/masonry_wall-texture.jpg'
    #     hm.name = 'textures/masonry_wall-height_map.jpg'
    #     nm.name = 'textures/masonry_wall-normal_map.jpg'
    #     sc = 4
    #     tm.scale = (sc,sc)
    #     hm.scale = (sc,sc)
    #     nm.scale = (sc,sc)
    #     tm.set = True
    #     hm.set = True
    #     nm.set = True

    # floor_index = scene.loadObjModel('models/floor.obj')
    floor_index = scene.loadObjModel('models/grid.obj')
    if floor_index == None:
        print 'Error loading model'
        exit(-1)
    floor = scene.models[floor_index]
    floor.props.pos = vec3(0,-0.5,3)
    floor.props.scale = vec3(1)

    for m in floor.models:
        m.material.bump_height = 0.015
        m.material.ambient = vec4(0.8,0.8,1,1)
        m.material.shininess = 0

        tm = m.material.texture1_map
        nm = m.material.normal_map
        hm = m.material.height_map

        # tm.name = 'textures/grass-texture.jpg'
        tm.name = 'textures/masonry_wall-texture.jpg'
        hm.name = 'textures/masonry_wall-height_map.jpg'
        # hm.name = 'textures/heightmap1-1024.jpg'
        # nm.name = 'textures/masonry_wall-normal_map.jpg'
        # tm.name = 'textures/brickwork-texture.jpg'
        # hm.name = 'textures/brickwork-height_map.jpg'
        # nm.name = 'textures/brickwork-normal_map.jpg'

        sc = 0.5
        tm.scale = (sc,sc)
        hm.scale = (sc,sc)
        nm.scale = (sc,sc)
        tm.set = True
        hm.set = True
        nm.set = False

        # sm = m.material.shininess_map
        # sm.name = 'textures/brickwork-bump_map.jpg'
        # sm.scale = (sc,sc)
        # sm.set = True

        # rm = m.material.reflection_map
        # rm.set_textures('textures/cubemap/sky_x_pos.jpg',
        #                 'textures/cubemap/sky_x_neg.jpg',
        #                 'textures/cubemap/sky_y_pos.jpg',
        #                 'textures/cubemap/sky_y_neg.jpg',
        #                 'textures/cubemap/sky_z_pos.jpg',
        #                 'textures/cubemap/sky_z_neg.jpg')
        # rm.set = True

    scene.initCubemap('textures/cubemap/sky_x_pos.jpg',
                      'textures/cubemap/sky_x_neg.jpg',
                      'textures/cubemap/sky_y_pos.jpg',
                      'textures/cubemap/sky_y_neg.jpg',
                      'textures/cubemap/sky_z_pos.jpg',
                      'textures/cubemap/sky_z_neg.jpg')

    scene.loadModelTextures()
    scene.cam.pos = vec3(0.,1,3.)

    scene.lights.ambient.intensity = 0.6

    # spot_light = scene.lights.new_spot_light()
    # spot_light.pos = vec3(0,5,0)
    # spot_light.dir = vec3(0,-1,0).normalize()
    # spot_light.reach = 10
    # spot_light.dist_dimming = 0.5
    # spot_light.ang_dimming = 0.5
    # spot_light.color = vec3(1,1,1)

    spot_light = scene.new_spot_light()
    spot_light.pos = vec3(0,10,10)
    spot_light.dir = vec3(0,-1,-1).normalize()
    spot_light.reach = 40
    spot_light.dist_dimming = 0.2
    spot_light.ang_dimming = 0.2
    spot_light.color = vec3(1,1,1)

    glutDisplayFunc(lambda : scene.drawScene())
    glutIdleFunc(lambda : scene.drawScene())
    glutReshapeFunc(lambda w,h: reshape(w,h,scene))

    glutKeyboardFunc(lambda key,x,y : keyPressed(key,x,y,scene))
    glutMotionFunc(lambda x,y : mouseFunc(x,y,scene))
    # glutPassiveMotionFunc(lambda x,y : mouseFunc(x,y,scene,screen_size))

    glutWarpPointer(250,250)

    glutMouseFunc
    glutMainLoop()
示例#11
0
 def __init__(self):
     self.intensity = 0.5
     self.color = vec3(1.0, 1.0, 1.0)
     self.uniform = 'ambient_light'
示例#12
0
def main():
    screen_size = startOpengl()
    program = initShaders("shaders/grass.vert", "shaders/grass.frag")

    scene = Scene()
    scene.active_program = program

    model_index = scene.loadObjModel('models/floor.obj')

    if model_index == None:
        print 'Error loading model'
        exit(-1)

    model = scene.models[model_index]

    model.props.pos = vec3(0,-0.5,3)
    model.props.scale = vec3(1)

    for m in model.models:
        m.material.bump_height = 0.05

        tm = m.material.texture1_map
        nm = m.material.normal_map
        hm = m.material.height_map

        # tm.name = 'textures/uvmap.png'


        tm.mag_filter = GL_NEAREST
        tm.min_filter = GL_NEAREST_MIPMAP_NEAREST
        nm.mag_filter = GL_NEAREST
        nm.min_filter = GL_NEAREST_MIPMAP_NEAREST
        hm.mag_filter = GL_NEAREST
        hm.min_filter = GL_NEAREST_MIPMAP_NEAREST

        tm.name = 'textures/grass-texture.jpg'

        hm.name = 'textures/grass-height_map.jpg'
        nm.name = 'textures/grass-height_map.jpg'

        # hm.name = 'textures/height_example.jpg'
        # nm.name = 'textures/height_example.jpg'

        # tm.name = 'textures/brickwork-texture.jpg'
        # hm.name = 'textures/brickwork-height_map.jpg'
        # nm.name = 'textures/brickwork-normal_map.jpg'

        # tm.name = 'textures/masonry_wall-texture.jpg'
        # hm.name = 'textures/masonry_wall-height_map.jpg'
        # nm.name = 'textures/masonry_wall-normal_map.jpg'

        sc = 20
        tm.scale = (sc,sc)
        hm.scale = (sc,sc)
        nm.scale = (sc,sc)
        tm.set = True
        hm.set = True
        nm.set = True

        # sm = m.material.shininess_map
        # sm.name = 'textures/brickwork-bump_map.jpg'
        # sm.scale = (sc,sc)
        # sm.set = True

        # rm = m.material.reflection_map
        # rm.set_textures('textures/cubemap/sky_x_pos.jpg',
        #                 'textures/cubemap/sky_x_neg.jpg',
        #                 'textures/cubemap/sky_y_pos.jpg',
        #                 'textures/cubemap/sky_y_neg.jpg',
        #                 'textures/cubemap/sky_z_pos.jpg',
        #                 'textures/cubemap/sky_z_neg.jpg')
        # rm.set = True

    scene.initCubemap('textures/cubemap/sky_x_pos.jpg',
                      'textures/cubemap/sky_x_neg.jpg',
                      'textures/cubemap/sky_y_pos.jpg',
                      'textures/cubemap/sky_y_neg.jpg',
                      'textures/cubemap/sky_z_pos.jpg',
                      'textures/cubemap/sky_z_neg.jpg')

    scene.loadModelTextures()
    scene.cam.pos = vec3(0.,0.,3)
    
    screen = Screen()
    screen.size = screen_size

    glutDisplayFunc(lambda : drawScene(scene))
    glutIdleFunc(lambda : drawScene(scene))
    glutReshapeFunc(lambda w,h: reshape(w,h,screen))

    glutKeyboardFunc(lambda key,x,y : keyPressed(key,x,y,scene))
    glutMotionFunc(lambda x,y : mouseFunc(x,y,scene,screen))
    # glutPassiveMotionFunc(lambda x,y : mouseFunc(x,y,scene,screen_size))

    glutWarpPointer(250,250)

    glutMouseFunc
    glutMainLoop()
示例#13
0
def keyPressed(key, x, y, scene):
    global main_program
    global sec_program
    delta = 0.05
    cam = scene.cam
    if key == '\033' or key == 'q':
        sys.exit(1)
    if key == '1':
        scene.active_program = main_program
    if key == '2':
        scene.active_program = sec_program
    if key == 'w':
        delta_pos = -cam.rot() * vec3(0, 0, 1)
        for i in range(0, 3):
            cam.pos[i] += delta * delta_pos[i]
    if key == 's':
        delta_pos = cam.rot() * vec3(0, 0, 1)
        for i in range(0, 3):
            cam.pos[i] += delta * delta_pos[i]
    if key == 'a':
        delta_pos = -cam.rot() * vec3(1, 0, 0)
        for i in range(0, 3):
            cam.pos[i] += delta * delta_pos[i]
    if key == 'd':
        delta_pos = cam.rot() * vec3(1, 0, 0)
        for i in range(0, 3):
            cam.pos[i] += delta * delta_pos[i]

    if key == 'z':
        model = scene.models[0]
        for m in model.models:
            m.material.bump_height += 0.005
    if key == 'x':
        model = scene.models[0]
        for m in model.models:
            m.material.bump_height -= 0.005

    light = scene.lights.spots[0]
    model = scene.models[0]

    if key == 't':
        model.props.pos.x += 0.1
    if key == 'r':
        model.props.pos.x -= 0.1
    if key == 'g':
        model.props.pos.z += 0.1
    if key == 'f':
        model.props.pos.z -= 0.1
    if key == 'b':
        model.props.pos.y += 0.1
    if key == 'v':
        model.props.pos.y -= 0.1

    if key == 'h':
        light.pos.x += 0.1
    if key == 'k':
        light.pos.x -= 0.1
    if key == 'u':
        light.pos.z += 0.1
    if key == 'j':
        light.pos.z -= 0.1
    if key == 'o':
        light.intensity += 0.1
    if key == 'l':
        light.intensity -= 0.1
    if key == 'y':
        light.pos.y += 0.1
    if key == 'i':
        light.pos.y -= 0.1
示例#14
0
def main():

    scene = Scene()
    scene.screen.size = (800, 600)
    startOpengl(scene.screen.size[0], scene.screen.size[1])

    global main_program

    print 'Initializing main shaders'
    main_program = initShaders("shaders/3ds.vert", "shaders/3ds.frag",
                               "shaders/detail-3ds.geom")

    global sec_program
    print 'Initializing secondary shaders'
    sec_program = initShaders("shaders/parallaxOcclusionSelfShadow.vert",
                              "shaders/parallaxOcclusionSelfShadow.frag")

    scene.active_program = main_program

    # scene.active_program = initShaders("shaders/3ds.vert", "shaders/3ds.frag")
    # scene.active_program = initShaders("shaders/parallax.vert", "shaders/parallax.frag")
    # scene.active_program = initShaders("shaders/relief.vert", "shaders/relief.frag")

    scene.initShadowFB()

    # teapot_index = scene.loadObjModel('models/teapot.obj')
    # if teapot_index == None:
    #     print 'Error loading model'
    #     exit(-1)
    # teapot = scene.models[teapot_index]
    # for m in teapot.models:
    #     m.material.ambient = vec4(1,0.2,0.2,1)
    #     tm = m.material.texture1_map
    #     nm = m.material.normal_map
    #     hm = m.material.height_map
    #     tm.name = 'textures/masonry_wall-texture.jpg'
    #     hm.name = 'textures/masonry_wall-height_map.jpg'
    #     nm.name = 'textures/masonry_wall-normal_map.jpg'
    #     sc = 4
    #     tm.scale = (sc,sc)
    #     hm.scale = (sc,sc)
    #     nm.scale = (sc,sc)
    #     tm.set = True
    #     hm.set = True
    #     nm.set = True

    # floor_index = scene.loadObjModel('models/floor.obj')
    floor_index = scene.loadObjModel('models/grid.obj')
    if floor_index == None:
        print 'Error loading model'
        exit(-1)
    floor = scene.models[floor_index]
    floor.props.pos = vec3(0, -0.5, 3)
    floor.props.scale = vec3(1)

    for m in floor.models:
        m.material.bump_height = 0.015
        m.material.ambient = vec4(0.8, 0.8, 1, 1)
        m.material.shininess = 0

        tm = m.material.texture1_map
        nm = m.material.normal_map
        hm = m.material.height_map

        # tm.name = 'textures/grass-texture.jpg'
        tm.name = 'textures/masonry_wall-texture.jpg'
        hm.name = 'textures/masonry_wall-height_map.jpg'
        # hm.name = 'textures/heightmap1-1024.jpg'
        # nm.name = 'textures/masonry_wall-normal_map.jpg'
        # tm.name = 'textures/brickwork-texture.jpg'
        # hm.name = 'textures/brickwork-height_map.jpg'
        # nm.name = 'textures/brickwork-normal_map.jpg'

        sc = 0.5
        tm.scale = (sc, sc)
        hm.scale = (sc, sc)
        nm.scale = (sc, sc)
        tm.set = True
        hm.set = True
        nm.set = False

        # sm = m.material.shininess_map
        # sm.name = 'textures/brickwork-bump_map.jpg'
        # sm.scale = (sc,sc)
        # sm.set = True

        # rm = m.material.reflection_map
        # rm.set_textures('textures/cubemap/sky_x_pos.jpg',
        #                 'textures/cubemap/sky_x_neg.jpg',
        #                 'textures/cubemap/sky_y_pos.jpg',
        #                 'textures/cubemap/sky_y_neg.jpg',
        #                 'textures/cubemap/sky_z_pos.jpg',
        #                 'textures/cubemap/sky_z_neg.jpg')
        # rm.set = True

    scene.initCubemap('textures/cubemap/sky_x_pos.jpg',
                      'textures/cubemap/sky_x_neg.jpg',
                      'textures/cubemap/sky_y_pos.jpg',
                      'textures/cubemap/sky_y_neg.jpg',
                      'textures/cubemap/sky_z_pos.jpg',
                      'textures/cubemap/sky_z_neg.jpg')

    scene.loadModelTextures()
    scene.cam.pos = vec3(0., 1, 3.)

    scene.lights.ambient.intensity = 0.6

    # spot_light = scene.lights.new_spot_light()
    # spot_light.pos = vec3(0,5,0)
    # spot_light.dir = vec3(0,-1,0).normalize()
    # spot_light.reach = 10
    # spot_light.dist_dimming = 0.5
    # spot_light.ang_dimming = 0.5
    # spot_light.color = vec3(1,1,1)

    spot_light = scene.new_spot_light()
    spot_light.pos = vec3(0, 10, 10)
    spot_light.dir = vec3(0, -1, -1).normalize()
    spot_light.reach = 40
    spot_light.dist_dimming = 0.2
    spot_light.ang_dimming = 0.2
    spot_light.color = vec3(1, 1, 1)

    glutDisplayFunc(lambda: scene.drawScene())
    glutIdleFunc(lambda: scene.drawScene())
    glutReshapeFunc(lambda w, h: reshape(w, h, scene))

    glutKeyboardFunc(lambda key, x, y: keyPressed(key, x, y, scene))
    glutMotionFunc(lambda x, y: mouseFunc(x, y, scene))
    # glutPassiveMotionFunc(lambda x,y : mouseFunc(x,y,scene,screen_size))

    glutWarpPointer(250, 250)

    glutMouseFunc
    glutMainLoop()
示例#15
0
def main():
    screen_size = startOpengl()
    program = initShaders("shaders/grass.vert", "shaders/grass.frag")

    scene = Scene()
    scene.active_program = program

    model_index = scene.loadObjModel('models/floor.obj')

    if model_index == None:
        print 'Error loading model'
        exit(-1)

    model = scene.models[model_index]

    model.props.pos = vec3(0, -0.5, 3)
    model.props.scale = vec3(1)

    for m in model.models:
        m.material.bump_height = 0.05

        tm = m.material.texture1_map
        nm = m.material.normal_map
        hm = m.material.height_map

        # tm.name = 'textures/uvmap.png'

        tm.mag_filter = GL_NEAREST
        tm.min_filter = GL_NEAREST_MIPMAP_NEAREST
        nm.mag_filter = GL_NEAREST
        nm.min_filter = GL_NEAREST_MIPMAP_NEAREST
        hm.mag_filter = GL_NEAREST
        hm.min_filter = GL_NEAREST_MIPMAP_NEAREST

        tm.name = 'textures/grass-texture.jpg'

        hm.name = 'textures/grass-height_map.jpg'
        nm.name = 'textures/grass-height_map.jpg'

        # hm.name = 'textures/height_example.jpg'
        # nm.name = 'textures/height_example.jpg'

        # tm.name = 'textures/brickwork-texture.jpg'
        # hm.name = 'textures/brickwork-height_map.jpg'
        # nm.name = 'textures/brickwork-normal_map.jpg'

        # tm.name = 'textures/masonry_wall-texture.jpg'
        # hm.name = 'textures/masonry_wall-height_map.jpg'
        # nm.name = 'textures/masonry_wall-normal_map.jpg'

        sc = 20
        tm.scale = (sc, sc)
        hm.scale = (sc, sc)
        nm.scale = (sc, sc)
        tm.set = True
        hm.set = True
        nm.set = True

        # sm = m.material.shininess_map
        # sm.name = 'textures/brickwork-bump_map.jpg'
        # sm.scale = (sc,sc)
        # sm.set = True

        # rm = m.material.reflection_map
        # rm.set_textures('textures/cubemap/sky_x_pos.jpg',
        #                 'textures/cubemap/sky_x_neg.jpg',
        #                 'textures/cubemap/sky_y_pos.jpg',
        #                 'textures/cubemap/sky_y_neg.jpg',
        #                 'textures/cubemap/sky_z_pos.jpg',
        #                 'textures/cubemap/sky_z_neg.jpg')
        # rm.set = True

    scene.initCubemap('textures/cubemap/sky_x_pos.jpg',
                      'textures/cubemap/sky_x_neg.jpg',
                      'textures/cubemap/sky_y_pos.jpg',
                      'textures/cubemap/sky_y_neg.jpg',
                      'textures/cubemap/sky_z_pos.jpg',
                      'textures/cubemap/sky_z_neg.jpg')

    scene.loadModelTextures()
    scene.cam.pos = vec3(0., 0., 3)

    screen = Screen()
    screen.size = screen_size

    glutDisplayFunc(lambda: drawScene(scene))
    glutIdleFunc(lambda: drawScene(scene))
    glutReshapeFunc(lambda w, h: reshape(w, h, screen))

    glutKeyboardFunc(lambda key, x, y: keyPressed(key, x, y, scene))
    glutMotionFunc(lambda x, y: mouseFunc(x, y, scene, screen))
    # glutPassiveMotionFunc(lambda x,y : mouseFunc(x,y,scene,screen_size))

    glutWarpPointer(250, 250)

    glutMouseFunc
    glutMainLoop()