Beispiel #1
0
 def _setdebug(self, debug):
     from miru.context import context
     self._debug = debug
     if debug:
         if not self._debug_lines:
             self._debug_lines = core.Object(ViewportOutline(self))
         context.add_object(self._debug_lines)
     else:
         context.remove_object(self._debug_lines)
Beispiel #2
0
Datei: ui.py Projekt: Knio/miru
 def _load_object(self):
     if RANDOM_BENCHMARK:
         fname = "docs/demo/%s.obj" % random.choice(_bmark_choices)
         o = graphics.load_wobj(fname)
         print "loaded [random]", o
     else:
         o = graphics.load_wobj("docs/demo/alien.obj")
         print "loaded", o
     context.add_object(o)
     return o
Beispiel #3
0
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()
    window.flip()

Beispiel #4
0
#])
context.control = miru.input.SimpleMouseControl()

glEnable( GL_CULL_FACE )

batch = pyglet.graphics.Batch()
mesh_id = miru.graphics.load_mesh(
        (sys.argv[1:] and sys.argv[1]
            or os.path.join('docs', 'demo', 'yam.obj')))
miru.graphics.batch_mesh(mesh_id, batch)
#obj = mesh_id
#obj = miru.graphics.Object(batch)
obj = miru.core.Object(batch)
#obj = miru.graphics.load_wobj(batch)
#context.add_object(obj)
context.add_object(batch)
context.osd.add_object(clock.ClockDisplay())

velocity = 20
def update(dt):
    delta = dt * velocity
    obj.angle.y += delta
clock.schedule_interval(update, 1/60.)

while not window.has_exit:
    clock.tick()
    window.clear()
    window.dispatch_events()
    context.render()
    window.flip()
window.close()
Beispiel #5
0
        1.0, 1.0, -1.0,
        1.0, 1.0, 1.0,
        -1.0, -1.0, -1.0,
        -1.0, -1.0, 1.0,
        1.0, -1.0, 1.0,
        1.0, -1.0, -1.0)))

batch2 = pyglet.graphics.Batch()
mesh_id = miru.graphics.load_mesh(
        (sys.argv[1:] and sys.argv[1]
            or os.path.join('docs', 'demo', 'yam.obj')))
miru.graphics.batch_mesh(
        mesh_id, batch2, cubemap.texture_group_b, False)

obj = core.Object(batch1)
context.add_object(obj)
obj = core.Object(batch2)
context.add_object(obj)

velocity = 20
def update(dt):
    delta = dt * velocity
    obj.angle.y += delta
clock.schedule_interval(update, 1/60.)

while not window.has_exit:
    clock.tick()
    window.clear()
    window.dispatch_events()
    context.render()
    window.flip()
Beispiel #6
0
    #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
    0.255, 0.495, 0.255, 0.255, 0.495, 0.255, 0.495, 0.495 ] # front

#cube_geom.texcoord_data = [
    #0.333, 0.500, 0.333, 0.750, 0.000, 0.750, 0.000, 0.500, #left
Beispiel #7
0
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)
clock.schedule_interval(update_texcoords, 0.25)

@window.event
def on_draw():
Beispiel #8
0
o.pos += (-0.5,0.55,0)


pattern = pyglet.image.CheckerImagePattern(
        (90,0,0,255), (0,30,0,255))
tex = pattern.create_image(64, 64).get_texture()
coords = []
for i in range(0, len(tex.tex_coords), 3):
    coords.extend(tex.tex_coords[i:i+3] + (0.125 / 2,))
batch = pyglet.graphics.Batch()
group = graphics.TextureBindGroup(tex.id)
batch.add(4, GL_QUADS, group,
        ('v3f', [-10, 0, -10, 10, 0, -10, 10, 0, 10, -10, 0, 10]),
        ('t4f', coords))
ground = core.Object(batch)
context.add_object(ground)

print """
You should see some objects in fog.
"""

while not w.has_exit:
    pyglet.clock.tick()
    w.clear()
    w.dispatch_events()
    context.render()
    w.flip()

w.close()

Beispiel #9
0
# initialize the window
w = TestWindow(680, 400)
w.set_vsync(False)

utils.addFpsDisplay()

context.window = w
context.control = input.SimpleMouseControl()
context.camera.pos += (0,1,2)
context.camera.angle = (10,0,0)

#context.handle.accessible = True

o = graphics.load_wobj(P('docs','demo','alien.obj'))
o.pos += (0,0.95,-0.6)
context.add_object(o)

# Play around with the spot light
context.camera.lights = camera.LightGroup([
    camera.DirectionalLight(diffuse=(0.1,0.1,0.1,1)),
    camera.PositionalLight(pos=(0,2,0), spot_cutoff=25,
        track_target=o, spot_exponent=10, kq=0.1),
    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()
Beispiel #10
0
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()
    #pyglet.gl.glEnable(pyglet.gl.GL_CULL_FACE)
    #Need blending enabled for cull face to work
    pyglet.gl.glEnable(pyglet.gl.GL_BLEND)
    pyglet.gl.glBlendFunc(pyglet.gl.GL_SRC_ALPHA, pyglet.gl.GL_ONE_MINUS_SRC_ALPHA)