def batch_coordplane(size=40, step=0.5, color=(1, 1, 1, 1), batch=None, lighting=False): """ This function simplifies steps for building a CoordinatePlane and adding it to a graphics.Batch - if this is the desired behavior. """ parent = None if not lighting: parent = miru.graphics.ColorMaterialGroup(lighting=False) group = miru.graphics.ColorGroup(color, parent=parent) if not batch: batch = pyglet.graphics.Batch() coordplane = CoordinatePlane(size, step) geom.get_vlist(coordplane, batch, group) return batch
window = miru.ui.Window(600,400) context.window = window context.osd.add_object(pyglet.clock.ClockDisplay()) context.control = miru.input.SimpleMouseControl() context.camera.lights = miru.camera.LightGroup([ miru.camera.DirectionalLight()]) context.camera.pos.z = 5 context.camera.angle.x = -15 batch = pyglet.graphics.Batch() group = miru.graphics.ColorGroup(0.2) torus = geom.Torus(divisions=75) #torus.get_vlist(batch, group) vlist = geom.get_vlist(torus, batch, group) torus_obj = miru.core.Object(batch) torus_obj.angle.z = 15 context.add_object(torus_obj) v = 35 def update(dt): dy = dt * v torus_obj.angle.x += dy pyglet.clock.schedule_interval(update, 1/60.) while not window.has_exit: window.clear() pyglet.clock.tick() window.dispatch_events() context.render()
main_light = miru.camera.DirectionalLight(pos=[0.0,0.0,1.0]) #sky_light = miru.camera.DirectionalLight(pos=[0.0,1.0,0.0]) context.camera.lights = miru.camera.LightGroup([ main_light,]) #sky_light,]) #context.camera.pos.z = 5 context.camera.pos= (0,1.25,4) pyglet.gl.glEnable(pyglet.gl.GL_BLEND) pyglet.gl.glBlendFunc(pyglet.gl.GL_SRC_ALPHA, pyglet.gl.GL_ONE_MINUS_SRC_ALPHA) sky_img = pyglet.image.load(os.path.join(resource_base_path, sky_1)) sky_tex = sky_img.get_texture(rectangle=True, force_rectangle=True) sky_batch = pyglet.graphics.Batch() sky_shape = geom.Square(width=192, height=108, depth=0, tex=sky_tex) sky_group = miru.graphics.TextureBindGroup(sky_tex, sky_tex.target, parent=None, gencoords=False) sky_vlist = geom.get_vlist(sky_shape, sky_batch, sky_group) sky_obj = miru.core.Object(sky_batch) sky_obj.angle.x = 90 sky_obj.pos.y = 7 context.add_object(sky_obj) skin_tex = load_image(os.path.join(resource_base_path, img_1)).get_texture()#rectangle=True, force_rectangle=True) geom_batch = Batch() tex_group = miru.graphics.TextureBindGroup(skin_tex, skin_tex.target, parent=None, gencoords=False) geom_mesh = geom.Cube() geom_mesh.texcoord_data = [ 0.245, 0.505, 0.245, 0.745, 0.005, 0.746, 0.005, 0.505, # left 0.495, 0.755, 0.495, 0.995, 0.255, 0.995, 0.255, 0.755, # back 0.745, 0.505, 0.745, 0.745, 0.505, 0.745, 0.505, 0.505, # right 0.255, 0.745, 0.255, 0.505, 0.495, 0.505, 0.495, 0.745, # top 0.255, 0.245, 0.255, 0.005, 0.495, 0.005, 0.495, 0.245, # bottom
context.camera.lights = LightGroup([ DirectionalLight(pos=[1.0,1.0,0.5])]) tex = load_image('docs/demo/cross.png').get_texture() batch = Batch() texture_group = TextureBindGroup(tex) cube_geom = Cube() cube_geom.texcoord_data = [ 0.245, 0.505, 0.245, 0.745, 0.005, 0.746, 0.005, 0.505, # left 0.495, 0.755, 0.495, 0.995, 0.255, 0.995, 0.255, 0.755, # back 0.745, 0.505, 0.745, 0.745, 0.505, 0.745, 0.505, 0.505, # right 0.255, 0.745, 0.255, 0.505, 0.495, 0.505, 0.495, 0.745, # top 0.255, 0.245, 0.255, 0.005, 0.495, 0.005, 0.495, 0.245, # bottom 0.255, 0.495, 0.255, 0.255, 0.495, 0.255, 0.495, 0.495 ] # front vlist = get_vlist(cube_geom, batch, texture_group) slider = deque(vlist.tex_coords) cube = Object(batch) context.add_object(cube) cube.angle.z = 35 v = 35 def update(dt): dy = dt * v cube.angle.x += dy clock.schedule_interval(update, 1/60.) def update_texcoords(dt): slider.rotate(8) vlist.tex_coords[:] = list(slider)
camera.PositionalLight(pos=(-0.54,1.3,2.5), diffuse=(0.9,0,0,1)), camera.PositionalLight(pos=(1.6,1.3,2.7), diffuse=(0,0.9,0,1)), camera.PositionalLight(pos=(-2.7,1.7,0.3), diffuse=(0,0,0.9,1)), ]) for i in range(1,len(context.camera.lights)): context.camera.lights[i].debug = True batch = pyglet.graphics.Batch() color_group = graphics.ColorGroup((0.5,0.5,0.5,1.0)) objs = [] for x in range(-3, 4): for z in range(-3, 4): sphere = geom.Cube(0.7) geom.transform(sphere, (x * 1.23, 0, z * 1.23)) geom.get_vlist(sphere, batch, color_group) context.add_object(core.Object(batch)) print """ You should see a small grid of objects with some colored lights over it. You should be able to click on the bulb of a light to move it around. The white light is a spotlight which remains focussed on the object floating above the grid. """ while not w.has_exit: pyglet.clock.tick() w.clear()
context.osd.add_object(pyglet.clock.ClockDisplay()) context.control = miru.input.SimpleMouseControl() context.camera.lights = miru.camera.LightGroup([ miru.camera.DirectionalLight(pos=[1.0,1.0,0.5])]) context.camera.pos.z = 15 #context.camera.angle.x = -15 img = pyglet.image.load(skin_1) tex = img.get_texture(rectangle=True, force_rectangle=True) batch = pyglet.graphics.Batch() shape = geom.Square(width=16, height=9, depth=0, tex=tex) #shape = geom.Square(width=480, height=270, depth=0, tex=tex) group = miru.graphics.TextureBindGroup(tex, tex.target, parent=None, gencoords=False) vlist = geom.get_vlist(shape, batch, group) shape_obj = miru.core.Object(batch) #shape_obj.angle.z = 15 context.add_object(shape_obj) v = 35 def update(dt): dy = dt * v shape_obj.angle.y += dy pyglet.clock.schedule_interval(update, 1/60.) while not window.has_exit: window.clear() pyglet.clock.tick() window.dispatch_events()
if opts.fshader: for f in opts.fshader.split(','): data = open(f).read() fs = shader.FragmentShader(data) fshaders.append(fs) print 'creating program with:', vshaders + fshaders program = shader.createProgram(*(vshaders + fshaders)) batch = pyglet.graphics.Batch() shader_group = shader.ShaderGroup(program) color_group1 = graphics.ColorGroup((0.0,1.0,1.0), parent=shader_group) sphere1 = geom.Sphere( radius=0.63 ) geom.transform(sphere1, (-0.93,0,0)) geom.get_vlist(sphere1, batch, color_group1) color_group2 = graphics.ColorGroup((0.0,1.0,0.0), parent=shader_group) sphere2 = geom.Sphere( radius=0.63 ) geom.transform(sphere2, (0,-0.93,0)) geom.get_vlist(sphere2, batch, color_group2) color_group3 = graphics.ColorGroup((1.0,0.0,0.0), parent=shader_group) sphere3 = geom.Sphere( radius=0.63 ) geom.transform(sphere3, (0,0.93,0)) geom.get_vlist(sphere3, batch, color_group3) color_group4 = graphics.ColorGroup((1.0,0.0,1.0), parent=shader_group) sphere4 = geom.Sphere( radius=0.63 ) geom.transform(sphere4, (0.93,0,0)) geom.get_vlist(sphere4, batch, color_group4)