def create_shape(self, x, y, z): if self.shape_type == CUBE: shape = pi3d.Cuboid(x=(x - self.width / 2), y=(y - self.height / 2), z=(z - self.height / 2)) if self.shape_type == SPHERE: shape = pi3d.Sphere(x=(x - self.width / 2), y=(y - self.height / 2), z=(z - self.height / 2), radius=0.5) self.set_material(shape, x, y, z) return shape
def __init__(self): super(QtWindow, self).__init__() ''' layer set to -128 to hide behind X desktop ''' self.DISPLAY = pi3d.Display.create(w=W, h=H, layer=-128) shader = pi3d.Shader('uv_light') tex = pi3d.Texture('textures/PATRN.PNG') self.cube = pi3d.Cuboid(z=2) self.cube.set_draw_details(shader, [tex]) self.cube.show_flag = True # additional attribute stuck onto Cuboid instance self.cube.last_x = None self.cube.last_y = None self.initUI() # not entirely sure why this is done in a different method, just copying others' code!
def draw_cubeMap(cubeMap, heightMap, N=7): z = -N / 2 # starts here to account for offset for i in range(N): # rows cube_row = [] x = -N / 2 # starts here to account for offset for j in range(N): # cols # 2*z, 2*x is for spacing between blocks # h is cut in half to make it look smaller # y is cut in 4 because y grows from cube mid point, so it needs to be h/2 cube = pi3d.Cuboid(x=1.25 * x, y=heightMap[i][j] / 4, z=1.25 * z, h=heightMap[i][j] / 2) cube_row.append(cube) # Add cube to the list x += 1 cubeMap.append(cube_row) # Add a row list to letter_matrix list z += 1
def __init__(self, camera): super(SimpleCube, self).__init__( camera, pi3d.Cuboid(w=40, h=40, d=40, x=0, y=0, z=160.0, name='0'))
#!/usr/bin/python from __future__ import absolute_import, division, print_function, unicode_literals """ Peter Hess' converted shader for pi3d dynamic texturing """ import demo import pi3d DISPLAY = pi3d.Display.create(x=100, y=100, frames_per_second=30) shader = pi3d.Shader("star") tex = pi3d.Texture("textures/PATRN.PNG") #box = pi3d.Cuboid(x=0, y=0, z=2.2) box = pi3d.Cuboid(w=100, h=100, d=100, x=0, y=0, z=100.0) box.set_draw_details(shader, [tex]) tm = 0.0 dt = 0.01 sc = 0.0 ds = 0.001 mykeys = pi3d.Keyboard() ASPECT = DISPLAY.width / DISPLAY.height camera1 = pi3d.Camera((0, 0, 0), (0, 0, -0.1), (1, 1000, 45, ASPECT), is_3d=True) camera2 = pi3d.Camera(is_3d=False) while DISPLAY.loop_running(): box.set_custom_data(48, [tm, sc, -0.5 * sc]) """Three custom unif values used by star shader to animate image """ tm += dt sc = (sc + ds) % 10.0 box.rotateIncX(0.1) box.rotateIncY(0.71) box.position(-50.0, 50.0, 400.0)
self.callback(self.delta) def rotm(self, *args): self.callback(-self.delta) DISPLAY = pi3d.Display.create(w=640, h=480, frames_per_second=30) DISPLAY.set_background(0.8, 0.8, 0.8, 1.0) # r,g,b,alpha shader = pi3d.Shader("uv_reflect") font = pi3d.Font("fonts/FreeSans.ttf", color=(0, 0, 0, 255), font_size=20) gui = pi3d.Gui(font) ww, hh = DISPLAY.width / 2.0, DISPLAY.height / 2.0 img = pi3d.Texture("textures/rock1.jpg") model = pi3d.Cuboid(z=5.0) model.set_draw_details(shader, [img]) radio = pi3d.Radio(gui, ww - 20, hh - 32, label="unhides menu!", label_pos="left", callback=cbx) xi = -ww yi = hh for b in ['tool_estop.gif', 'tool_power.gif', 'tool_open.gif']: # 'tool_reload.gif', 'tool_run.gif', 'tool_step.gif', # 'tool_pause.gif', 'tool_stop.gif', 'tool_blockdelete.gif', # 'tool_optpause.gif', 'tool_zoomin.gif', 'tool_zoomout.gif', # 'tool_axis_z.gif', 'tool_axis_z2.gif', 'tool_axis_x.gif',
#!/usr/bin/python #import demo import pi3d DISPLAY=pi3d.Display.create(x=150,y=150) shader=pi3d.Shader("mat_light") mycube=pi3d.Cuboid(z=6.0) mycube.set_material((1.0,1.0,0.1)) mycube.set_shader(shader) mykeys=pi3d.Keyboard() while DISPLAY.loop_running(): mycube.draw() if mykeys.read()==27: mykeys.close() DISPLAY.destroy() break
ircam.cam_init() # DISPLAY parameters DISP = pi3d.Display.create()#(x = 50, y = 50)# h = 1920, w = 1080) flatsh = pi3d.Shader('uv_flat') ectex = pi3d.loadECfiles('skybox_hall/','skybox_hall') #ectex = pi3d.loadECfiles('stripwood/','stripwood') myecube = pi3d.EnvironmentCube(size = 400.0, maptype = 'FACES') myecube.set_draw_details(flatsh, ectex) # Camera Settings CAM = pi3d.Camera(eye=(0.0,10.0,-80.0)) cube_1 = pi3d.Cuboid(w=10,h=10,d=10) cube_1.set_material((1,0,0)) cube_2 = pi3d.Cuboid(x = 40, y = -50, z =50, w=10, h=10, d=10) cube_2.set_material((0,1,0)) ############generate 15 random cubes################# num_cubes = 5 cub = [0]*num_cubes for i in range(num_cubes): val_x = randint(-10,10) val_y = randint(-10,10) val_z = randint(-10,10) val_s = randint(10,17)
import pi3d from instagram_query import get_instagram_api, InstagramQuery, InstagramMedia api = get_instagram_api() display = pi3d.Display.create(x=50, y=50) shader = pi3d.Shader("uv_light") img_dir = '/home/sam/Dropbox/Photos/friends/' imgs = [img for img in os.listdir(img_dir) if img[0] != '.'] cur_img = 0 images = [] tex = pi3d.Texture(img_dir + imgs[cur_img]) box = pi3d.Cuboid(x=0, y=0, z=2.2) box.set_draw_details(shader, [tex]) ball = pi3d.Sphere(x=-1.5, y=0, z=2.6, radius=0.5) ball.set_draw_details(shader, [tex]) mykeys = pi3d.Keyboard() cur_user = 0 users = [ "meoremy", "samwell3", "omg.rb.md", "moistbuddha", "butterknuckles", "peanutbutterpear" ] cur_tag = 0 tags = ["magic egg", "fractals", "news", "beauty", "time", "reflection"] loaded = []
DISPLAY = pi3d.Display.create() #create mouse obj mymouse = pi3d.Mouse(restrict=False) mymouse.start() #create camera CAM = RotatingCamera(5, mymouse) #create keyboard obj mykeys = pi3d.Keyboard() #create cubes cubeList = [] for i in range(10): cube = pi3d.Cuboid(x=i) cube.set_material((0.0, 1.0, 0.0)) cubeList.append(cube) #display loop while DISPLAY.loop_running(): #listen for keystrokes k = mykeys.read() if k == 27: #ESC key mykeys.close() DISPLAY.destory() break CAM.update(mymouse, mykeys) for cube in cubeList:
Also, when running on ubuntu laptop the pixel copying often has patterns of 'holes' and there are occasional serious error (seg faults) when closing the application. Any further help with this would be appreciated! ''' W, H = 640, 480 ''' This system works by copying the pi3d screen image and 'pasting' it onto a gtk image. NB to get the pi3d layer 'behind' the X windows you need to set its value to < -127 ''' DISPLAY = pi3d.Display.create(w=W, h=H, frames_per_second=20, layer=-128) shader = pi3d.Shader('uv_light') tex = pi3d.Texture('textures/PATRN.PNG') cube = pi3d.Cuboid(z=2) cube.set_draw_details(shader, [tex]) cube.show_flag = True # additional attribute stuck onto Cuboid instance cube.last_x = None cube.last_y = None def rotX(widget, cube): cube.rotateIncX(5.0) cube.show_flag = True def rotY(widget, cube): cube.rotateIncY(15.0) cube.show_flag = True
#bumpimg = pi3d.Texture("textures/black.jpg") checkerboard = pi3d.Texture("textures/glassbuilding.jpg") w = 5.0 h = 10.0 d = 5.0 x = -10.0 z = -10.0 lh = 35 lw = 3 ld = 3 ow = 3 oh = 25 od = 3 cubes = [] cubes.append(pi3d.Cuboid(x=0, y=lh / 2, z=-20, w=ow, h=lh, d=od)) for x, z in [ [0, 0], [-20, 0], [20, 0], [0, 20], ]: cubes.append( pi3d.Cuboid( x=x, # + random.random() * 5, y=h / 2, z=z, # + random.random() * 5, w=ow, # + random.randint(0,3) * 2, h=oh, # + random.randint(0,4) * 10, d=od # + random.randint(0,3) * 2 ))
mytext[:53], font_size=48, color=(70, 70, 180, 255), background_color=None, shadow_radius=1, camera=CAMERA2D, shader=flatsh, f_type='SMOOTH') str1a.sprite.position(50, -150, 1) #NB note Shape methods act on FixedString.sprite str2 = pi3d.FixedString('fonts/NotoSerif-Regular.ttf', mytext, font_size=24, f_type='BUMP') mycuboid = pi3d.Cuboid(camera=CAMERA, z=2, x=0.5) mycuboid.set_draw_details(shader, [tex, str2], 1.0, 0.0) #following is a bit low level but makes it fit nicely look in docs to see #how Buffer.unib[6 and 7] control mapping uv to object mycuboid.buf[0].unib[6] = str2.sprite.buf[0].unib[6] mycuboid.buf[0].unib[7] = str2.sprite.buf[0].unib[7] mykeys = pi3d.Keyboard() while DISPLAY.loop_running(): str1.draw() mycuboid.draw() str1a.draw() mycuboid.rotateIncX(0.091) mycuboid.rotateIncY(0.13) if mykeys.read() == 27: mykeys.close()
G = -0.01 # g -> change in y velocity each frame rot = 0.0 # rotation of camera about vertical axis ballrot = 180.0 # heading of ball about vert axis (y) tilt = 0.0 # rotation of camera about local x axis (left to right horizontal) RADIUS = 1.0 # radius of ball ball = pi3d.Triangle(corners=((-0.01, 0.0), (0.0, 0.01), (0.01, 0.0))) # an 'empty' game object ball_shape = pi3d.Sphere(radius=RADIUS, slices=24, sides=24) # the visible shape ball.add_child(ball_shape) # to get realistic 'rolling' ball_shape.set_draw_details(shader, [plntimg, plnnorm], 1.0) # platforms W = 8.0 H = 1.5 on_plat = False # flag if on a platform (for jumping) platforms = [ # locations of platforms pi3d.Cuboid(x=44, y=5, z=43), pi3d.Cuboid(x=32, y=3, z=28), pi3d.Cuboid(x=30, y=2, z=15), pi3d.Cuboid(x=15, y=1, z=5), pi3d.Cuboid(x=0, y=2, z=0), ] for p in platforms: p.scale(W, H, W) p.set_draw_details(shader, [metlimg, flrnorm], 8.0) p.positionY(p.y() + mymap.calcHeight(p.x(), p.z())) # adjust for terrain dr = 0.0 # rolling speed dy = 0.0 # vertical speed (for jumping) expl = 1.0 # scale value for exploding xb, yb, zb = platforms[0].x(), platforms[0].y() + RADIUS + 5.0, platforms[0].z()
# scene - empty to hold objects scene = pi3d.Triangle(corners=((0, 0), (1, 1), (-1, 1))) # pod, base and gun pod = pi3d.Model(file_string=MODEL_PATH.format('pod_2.obj'), z=20.0) laser_base = pi3d.Model(file_string=MODEL_PATH.format('laser_base_2.obj'), y=3.15) laser_gun = pi3d.Model(file_string=MODEL_PATH.format('laser_gun_2.obj'), y=0.4, z=-0.4) laser_base.add_child(laser_gun) pod.add_child(laser_base) pod.set_shader(shader) # all use uv_light shader # laser beam itself not a child laser_tip = pi3d.Cuboid(w=0.05, h=0.05, d=5.0) laser_tip.set_material((1.0, 0.0, 0.0)) laser_tip.set_alpha(0.0) laser_tip.set_shader(laser_shader) # asteroid asteroid = pi3d.Model(file_string=MODEL_PATH.format('asteroid_large_1.obj'), z=50, y=10, x=20) asteroid.set_shader(shader) # rings ring = pi3d.Model(file_string=MODEL_PATH.format('straight_ring_2.obj')) empty = pi3d.Triangle(corners=((0, 0), (1, 1), (-1, 1)), z=50.0) ring.set_shader(shader)
# DISPLAY parameters DISP = pi3d.Display.create()#(x = 50, y = 50)# h = 1920, w = 1080) flatsh = pi3d.Shader('uv_flat') ectex = pi3d.loadECfiles('skybox_hall/','skybox_hall') #ectex = pi3d.loadECfiles('/home/pi/mycodes/python/zerolens/stripwood/','stripwood') #ectex = pi3d.loadECfiles('/home/pi/mycodes/python/zerolens/blackwall/','blackwall') myecube = pi3d.EnvironmentCube(size = 400.0, maptype = 'FACES') myecube.set_draw_details(flatsh, ectex) # Camera Settings CAM = pi3d.Camera(eye=(0.0,10.0,-80.0)) cube_1 = pi3d.Cuboid(w=10,h=10,d=10) cube_1.set_material((1,0,0)) ############generate 5 random cubes################# num_cubes = 5 cub = [0]*num_cubes lin = [0]*num_cubes for i in range(num_cubes): val_x = 10*randint(-15,15) val_y = 10*randint(-10,10) val_z = 10*randint(-2,10) val_s = randint(10,25) col_r = randint(0,2)
# create a 'pi' symbol statue, 5 cubes across the top with each leg being 3 cubes high. brickAt(-2, 3, 0) brickAt(-1, 3, 0) brickAt(0, 3, 0) brickAt(1, 3, 0) brickAt(2, 3, 0) brickAt(-1, 2, 0) brickAt(1, 2, 0) brickAt(-1, 1, 0) brickAt(1, 1, 0) brickAt(-1, 0, 0) brickAt(1, 0, 0) for position in brick_blocks: brick = pi3d.Cuboid() brick.set_draw_details(light_shader, [brick_texture]) brick.scale(BLOCK_SIZE, BLOCK_SIZE, BLOCK_SIZE) brick.translate(*position) cubes.append(brick) for position in grass_blocks: grass = pi3d.Cuboid() grass.set_draw_details(light_shader, [grass_texture]) grass.scale(BLOCK_SIZE, BLOCK_SIZE, BLOCK_SIZE) grass.translate(*position) cubes.append(grass) def on_action_pressed(): print("FIRE!")
ballrot = 180.0 # heading of ball about vert axis (y) tilt = 0.0 # rotation of camera about local x axis (left to right horizontal) RADIUS = 1.0 # radius of ball ball = pi3d.Triangle(corners=((-0.01, 0.0), (0.0, 0.01), (0.01, 0.0))) # an 'empty' game object ball_shape = pi3d.Sphere(radius=RADIUS, slices=24, sides=24) # the visible shape ball.add_child(ball_shape) # to get realistic 'rolling' ball_shape.set_draw_details(shader, [plntimg, plnnorm], 1.0) # platforms W = 10.0 H = 1.5 on_plat = False # flag if on a platform (for jumping) platforms = [ # locations of platforms pi3d.Cuboid(x=44, y=5, z=43), pi3d.Cuboid(x=32, y=3, z=28), pi3d.Cuboid(x=30, y=2, z=15), pi3d.Cuboid(x=15, y=1, z=5), pi3d.Cuboid(x=0, y=15, z=0), pi3d.Cuboid(x=12, y=3, z=-10), pi3d.Cuboid(x=-5, y=8, z=-21), pi3d.Cuboid(x=4, y=12, z=-23), ] for i in range(10): pl = pi3d.Cuboid(x=random.random() * 50, y=random.random() * 20, z=random.random() * 100) platforms.append(pl) pl.set_material((1, 0.7, 0.2)) for p in platforms:
mountimg1 = pi3d.Texture("textures/mars_colour.png") bumpimg = pi3d.Texture("textures/mudnormal.jpg") mymap = pi3d.ElevationMap(mapfile="textures/mars_height.png", width=mapwidth, depth=mapdepth, height=mapheight, divx=128, divy=128) mymap.set_draw_details(bumpsh, [mountimg1, bumpimg], 128.0, 0.0) mymap.set_fog((0.3, 0.15, 0.1, 0.7), 700.0) #create robot metalimg = pi3d.Texture("textures/metalhull.jpg") robot_head = pi3d.Sphere(radius=1.0) robot_body = pi3d.Cylinder(radius=1.0, height=2.0, sides=12) robot_leg = pi3d.Cuboid(w=0.35, h=2.0) robot = pi3d.MergeShape() robot.add(robot_head.buf[0], 0.0, 1.6) robot.add(robot_body.buf[0], 0.0, 0.5) robot.add(robot_leg.buf[0], -1.04, 0, 0) robot.add(robot_leg.buf[0], 1.05, 0, 0) robot.set_draw_details(shader, [metalimg, metalimg, reflcn], 0.0, 0.5) #create space station ssphere = pi3d.Sphere(radius=10, slices=16, sides=16) scorrid = pi3d.Cylinder(radius=4, height=22) station = pi3d.MergeShape(y=mymap.calcHeight(0, 0), rx=4, ry=4, rz=4) station.add(ssphere.buf[0], -20, 0, 20) station.add(ssphere.buf[0], 20, 0, 20)
w=800, h=480, z=7500) shader = pi3d.Shader("uv_light") shinesh = pi3d.Shader("uv_reflect") flatsh = pi3d.Shader("uv_flat") matsh = pi3d.Shader("mat_reflect") matl = pi3d.Shader("mat_light") test = pi3d.Texture('backgrounds/IMG-20160924-WA0008.jpg') mydoor = pi3d.Cuboid(CAMERA3D, w=0.5, h=1, d=0.08, name="Door", x=0.25, y=0, z=0) #child has z = 0 mydoor.set_alpha(0.9) mydoor.set_material((0.5, 0.1, 0.1)) mydoor.set_draw_details(matl, [], 0.0, 1.0) mydoorhandle = pi3d.Sphere(radius=0.03, x=0.45, z=0.05) mydoorhandle.set_draw_details(shinesh, [], 0.0, 0.5) mydoormerge = pi3d.MergeShape(CAMERA3D, x=0, y=0, z=2) mydoormerge.add_child(mydoor) mydoormerge.add_child(mydoorhandle) angle = 180 mydoormerge.rotateToX(-20)