def __init__(self): shader = pi3d.Shader("uv_reflect") bumpsh = pi3d.Shader("uv_bump") flatsh = pi3d.Shader("uv_flat") #shade2d = pi3d.Shader('2d_flat') ectex = pi3d.loadECfiles("../textures/ecubes/RedPlanet", "redplanet_256", "png", True) self.myecube = pi3d.EnvironmentCube(size=1800.0, maptype="FACES") self.myecube.set_draw_details(flatsh,ectex) # Create elevation map mapwidth=2000.0 mapdepth=2000.0 mapheight=100.0 redplanet = pi3d.Texture("../textures/mars_colour.png") bumpimg = pi3d.Texture("../textures/mudnormal.jpg") self.mymap = pi3d.ElevationMap(mapfile='../textures/mars_height.png', width=mapwidth, depth=mapdepth, height=mapheight, divx=64, divy=64) self.mymap.set_draw_details(bumpsh,[redplanet, bumpimg],128.0, 0.0) self.mymap.set_fog((0.3, 0.15, 0.1, 0.0), 1000.0) #Load Corridors sections sttnbmp = pi3d.Texture("../textures/floor_nm.jpg") sttnshn = pi3d.Texture("../textures/stars.jpg") x,z = 0,0 y = self.mymap.calcHeight(x, z) #corridor with windows self.cor_win = pi3d.Model(file_string="../models/MarsStation/corridor_win_lowpoly.egg", x=x, y=y, z=z, sx=0.1, sy=0.1, sz=0.1) self.cor_win.set_shader(shader) #normal corridor self.corridor = pi3d.Model(file_string="../models/MarsStation/corridor_lowpoly.egg", x=x, y=y, z=z, sx=0.1, sy=0.1, sz=0.1) self.corridor.set_shader(shader) #corridor crossing self.cor_cross = pi3d.Model(file_string="../models/MarsStation/cross_room.egg", x=x, y=y, z=z, sx=0.1, sy=0.1, sz=0.1) self.cor_cross.set_shader(shader) self.cor_cross.set_normal_shine(sttnbmp, 32.0, sttnshn, 0.1) #corridor crossing with doors self.cor_cross_doors = pi3d.Model(file_string="../models/MarsStation/cross_room_doors.egg", x=x, y=y, z=z, sx=0.1, sy=0.1, sz=0.1) self.cor_cross_doors.set_shader(shader) self.cor_cross_doors.set_normal_shine(sttnbmp, 32.0, sttnshn, 0.1) #corridor with 90 degree bend self.cor_bend = pi3d.Model(file_string="../models/MarsStation/bend_lowpoly.egg", x=x, y=y, z=z, sx=0.1, sy=0.1, sz=0.1) self.cor_bend.set_shader(shader) self.cor_bend.set_normal_shine(sttnbmp, 32.0) self.cor_bend.rotateToY(180)
def __init__(self): super().__init__() self.center = pi3d.Model( file_string="../Blender/goomba/goomba_dead/goomba.obj") shader = pi3d.Shader("uv_bump") self.center.set_shader(shader) self.center.scale(0.4, 0.4, 0.4)
def __init__(self): super().__init__() self.center = pi3d.Model(file_string="../Blender/toad/toad.obj") shader = pi3d.Shader("uv_flat") self.center.set_shader(shader) #self.center.scale(0.1,0.1,0.1) self.center.scale(0.03, 0.03, 0.03)
def __init__(self): super().__init__() self.center = pi3d.Model( file_string="../Blender/DBZ/Roshi/Master_Roshi.obj") shader = pi3d.Shader("uv_flat") self.center.set_shader(shader) self.center.scale(0.3, 0.3, 0.3)
class MySelectableObject: home_path = "/home/pi/naropa_installation/" obj = pi3d.Model(file_string=home_path + 'models/gun.obj', name='gun', z=0.0) isSelected = False isValidSelection = True
def __init__(self): super().__init__() #Create human #porl = pi3d.Model(file_string="Blender/Porl.obj", name="monument") #porl.translate(90.0, -mymap.calcHeight(100.0, 235) + 12.0, 235.0) #porl.scale(5.0, 5.0, 5.0) self.body = pi3d.Model(file_string="../Blender/pi_Porl_Body.obj") #body.translate(90.0, -mymap.calcHeight(100.0, 235) + 20.0, 235.0) self.body.scale(1.0, 1.0, 1.0) self.head = pi3d.Model(file_string="../Blender/pi_Porl_Head.obj", y=1.84) self.armR = pi3d.Model(file_string="../Blender/pi_Porl_Arm_Right.obj", x=-0.5, y=1.64, z=0.1) self.handR = pi3d.Model( file_string="../Blender/pi_Porl_Hand_Right.obj", x=-0.75) self.legs = pi3d.Model(file_string="../Blender/pi_Porl_Legs.obj", y=-3.7) self.armL = pi3d.Model(file_string="../Blender/pi_Porl_Arm_Left.obj", x=0.5, y=1.64, z=0.1) self.handL = pi3d.Model(file_string="../Blender/pi_Porl_Hand_Left.obj", x=0.75) self.body.add_child(self.head) self.body.add_child(self.armR) self.armR.add_child(self.handR) self.body.add_child(self.legs) self.body.add_child(self.armL) self.armL.add_child(self.handL)
def __init__(self, x, y, z): self.x = x self.y = y self.z = z print('Spawning a vehicle in {0}, {1}, {2}'.format( self.x, self.y, self.z)) self.model = pi3d.Model(file_string='models/cow2.obj', camera=CAMERA) self.model.set_shader(SHADER)
def __init__(self): super().__init__() self.center = pi3d.Model( file_string="../Blender/Zelda/Custom_Link/Link_full_butt.obj") shader = pi3d.Shader("uv_flat") self.center.set_shader(shader) self.center.scale(0.6, 0.6, 0.6) self.armR = pi3d.Model( file_string="../Blender/Zelda/Custom_Link/Link_armR.obj", cy=-8.6, cx=1, cz=-0.7) self.armR.set_shader(shader) self.forarmR = pi3d.Model( file_string="../Blender/Zelda/Custom_Link/Link_forarmR.obj", cy=-8.8, cx=2.8, cz=-0.7) self.forarmR.set_shader(shader) self.handR = pi3d.Model( file_string="../Blender/Zelda/Custom_Link/Link_handR.obj", cy=-8.8, cx=4.4, cz=-0.7) self.handR.set_shader(shader) self.armL = pi3d.Model( file_string="../Blender/Zelda/Custom_Link/Link_armL.obj", cy=-8.6, cx=-1, cz=-0.7) self.armL.set_shader(shader) self.forarmL = pi3d.Model( file_string="../Blender/Zelda/Custom_Link/Link_forarmL.obj", cy=-8.8, cx=-2.8, cz=-0.7) self.forarmL.set_shader(shader) self.handL = pi3d.Model( file_string="../Blender/Zelda/Custom_Link/Link_handL.obj", cy=-8.8, cx=-4.4, cz=-0.7) self.handL.set_shader(shader) self.center.add_child(self.armR) self.armR.add_child(self.forarmR) self.forarmR.add_child(self.handR) self.center.add_child(self.armL) self.armL.add_child(self.forarmL) self.forarmL.add_child(self.handL)
def __init__(self, model, recalc_time, refid): self.refid = refid self.recalc_time = recalc_time #in theory use different values for enemy self.x, self.y, self.z = 0.0, 0.0, 0.0 self.x_perr, self.y_perr, self.z_perr = 0.0, 0.0, 0.0 self.x_ierr, self.y_ierr, self.z_ierr = 0.0, 0.0, 0.0 self.d_err = 0.0 self.v_speed, self.h_speed = 0.0, 0.0 self.rollrate, self.pitchrate, self.yaw = 0.0, 0.0, 0.0 self.direction, self.roll, self.pitch = 0.0, 0.0, 0.0 self.max_roll, self.max_pitch = 65, 30 #limit rotations self.ailerons, self.elevator = 0.0, 0.0 self.max_ailerons, self.max_elevator = 10.0, 10.0 #limit conrol surface movement self.VNE = 120 #max speed (Velocity Not to be Exceeded) self.mass = 300 self.a_factor, self.e_factor = 10, 10 self.roll_inrta, self.pitch_inrta = 100, 100 self.max_power = 2000 #force units of thrust really self.lift_factor = 20.0 #randomly adjusted to give required performance! self.power_setting = 0.0 self.throttle_step = 20 self.last_time = time.time() self.last_pos_time = self.last_time self.del_time = None #difference in pi time for other aero c.f. main one self.rtime = 60 self.nearest = None self.other_damage = 0.0 #done to nearest others since last json_load self.damage = 0.0 #done to this aeroplane by others #create the actual model self.model = pi3d.Model(file_string=model, camera=CAMERA) self.model.set_shader(SHADER) self.model.set_normal_shine(flatwhite, 16.0, flatwhite, 0.5) #roration by Les self.model.rotateToX(xoffset) self.model.rotateToY(yoffset) self.model.rotateToZ(zoffset) #create the bullets plane = pi3d.Plane(h=25, w=1) self.bullets = pi3d.MergeShape(camera=CAMERA) #the merge method does rotations 1st Z, 2nd X, 3rd Y for some reason #for multi axis rotations you need to figure it out by rotating a #sheet of paper in the air in front of you (angles counter clockwise)! self.bullets.merge([[plane, -2.0, 0.5, 8.0, 90, 0, 0, 1, 1, 1], [plane, -2.0, 0.5, 8.0, 0, 90, 90, 1, 1, 1], [plane, 2.0, 0.5, 8.0, 90, 0, 0, 1, 1, 1], [plane, 2.0, 0.5, 8.0, 0, 90, 90, 1, 1, 1]]) self.num_b = len(BULLET_TEX) self.seq_b = self.num_b self.bullets.set_draw_details(FLATSH, [BULLET_TEX[0]])
def make_model(filename, name, x=0, y=0, z=0, rx=0, ry=0, rz=0): model = pi3d.Model(file_string='models/' + filename, name=name, x=x, y=y, z=z, rx=rx, ry=ry, rz=rz, sx=0.1, sy=0.1, sz=0.1) model.set_shader(shader) set_fog(model) return model
def __init__(self, shinesh, flatsh, reflimg, alpha, font, text, x, y, z, ry): self.achieved = False s = sin(radians(ry)) c = cos(radians(ry)) self.coin = pi3d.Model(file_string="models/coin.obj", x=x + R*s, y=y, z=z + R*c, sx=0.2, sy=0.2, sz=0.2, ry=ry) self.coin.set_draw_details(shinesh, [self.coin.buf[0].textures[0], reflimg], 1.0, 0.7) self.coin.set_alpha(alpha) self.coin.set_material((0.5, 0.4, 0.0)) self.string = pi3d.String(font=font, string=text, size=200.0, x=x + R*0.5*s, y=y, z=z + R*0.5*c, ry=ry) self.string.set_shader(flatsh)
def do_pickle(self, fog=((0.3, 0.3, 0.4, 0.95), 450.0)): '''run once to save pkl files from ElevationMaps and Models combined as MergeShapes as defined in the SceneryItem objects listed in scenery_list ''' for key in self.scenery_list: s_item = self.scenery_list[key] if s_item.put_on is None: #this is a map - do all these first pass LOGGER.debug('pickling %s', key) mymap = pi3d.ElevationMap(mapfile='{}/{}.png'.format( self.path, key), name=key, width=(self.msize + 0.001), depth=(self.msize + 0.001), height=s_item.height, x=s_item.x, y=s_item.y, z=s_item.z, divx=32, divy=32) mymap.set_fog(*fog) mymap.set_alpha(s_item.alpha) with open('{}/{}.pkl'.format(self.path, key), 'wb') as f: pickle.dump(mymap, f) s_item.shape = mymap # temp store all these for the sake of make_pickle for key in self.scenery_list: s_item = self.scenery_list[key] if s_item.put_on is not None: #model so need to put on map LOGGER.debug('pickling %s', key) md = s_item.model_details if not md['model'] in self.models: self.models[md['model']] = pi3d.Model( file_string='{}/{}.obj'.format(self.path, md['model'])) m_item = self.scenery_list[s_item.put_on] xpos = s_item.x - m_item.x # relative to map it's put on zpos = s_item.z - m_item.z mymerge = pi3d.MergeShape(name=key, x=s_item.x, z=s_item.z) mymerge.cluster(self.models[md['model']], m_item.shape, 0.0, 0.0, md['w'], md['d'], md['n'], key, md['maxs'], md['mins']) mymerge.set_fog(*fog) with open('{}/{}.pkl'.format(self.path, key), 'wb') as f: pickle.dump(mymerge, f) for key in self.scenery_list: #tidy up memory usage s_item = self.scenery_list[key] s_item.shape = None
def __init__(self): #Setup shaders flatsh = pi3d.Shader("uv_flat") #shade2d = pi3d.Shader('2d_flat') # create splash screen and draw it #splash = pi3d.ImageSprite("../textures/pi3d_splash.jpg", shade2d, w=10, h=10, z=0.2) #splash.draw() #DISPLAY.swap_buffers() #Setup environment cube ectex = pi3d.loadECfiles("../textures/ecubes/Miramar", "miramar_256", "png", nobottom = True) self.myecube = pi3d.EnvironmentCube(size=1800.0, maptype="FACES", nobottom=True) self.myecube.set_draw_details(flatsh, ectex) #Load Hall model self.mymap = pi3d.Model(file_string="../models/ConferenceHall/conferencehall.egg", name="Hall", sx=0.1, sy=0.1, sz=0.1) self.mymap.set_shader(flatsh) self.mymap.position(0.0,10.0, 0.0)
def main(): #Model textures and shaders shader = pi3d.Shader("uv_reflect") bumptex = pi3d.Texture("textures/floor_nm.jpg") shinetex = pi3d.Texture("textures/stars.jpg") # load model mymodel = pi3d.Model(file_string='models/teapot.obj', z=10) mymodel.set_shader(shader) mymodel.set_normal_shine(bumptex, 4.0, shinetex, 0.5) #Create environment box flatsh = pi3d.Shader("uv_flat") ectex=pi3d.loadECfiles("textures/ecubes","sbox") myecube = pi3d.EnvironmentCube(size=900.0, maptype="FACES", name="cube") myecube.set_draw_details(flatsh, ectex) CAMERA = pi3d.Camera.instance() rot = 0.0 # rotation of camera tilt = 0.0 # tilt of camera while DISPLAY.loop_running() and not \ inputs.key_state("KEY_ESC"): #Rotate camera inputs.do_input_events() # camera steered by mouse #Note:Some mice devices will be located on #get_mouse_movement(1) instead of get_mouse_movement() mx,my,mv,mh,md=inputs.get_mouse_movement() #mx,my,mv,mh,md=inputs.get_mouse_movement(1) rot -= (mx)*0.2 tilt -= (my)*0.2 CAMERA.reset() CAMERA.rotate(tilt, rot, 0) #Rotate object mymodel.rotateIncY(2.0) mymodel.rotateIncZ(0.1) mymodel.rotateIncX(0.3) #Draw objects mymodel.draw() myecube.draw()
def load_asteroids(): # Check if a pre-loaded database exists db_filename = os.path.join(VAR_DIR, AST_DB_FILENAME) start = time.time() if os.path.exists(db_filename): # Load the database ast = pickle.load(file(db_filename, 'rb')) else: # Database does not exist. Load the models then save # the database ast = [] global_scale = 1.0 for mf in asteroids.models[0:5]: model_filename = mf[0] model_scale = mf[1] model_name = model_filename.split('.')[ 0] # Remove the .obj extention m = pi3d.Model(file_string='../media/models/' + model_filename, name=model_name) m.scale(model_scale * global_scale, model_scale * global_scale, model_scale * global_scale) ast.append(m) pickle.dump(ast, file(db_filename, 'wb')) # Set the shader for all models for a in ast: a.set_shader(shader_uv_flat) end = time.time() print("Loading time: %f\n" % (end - start)) return ast
def __init__(self): super().__init__() self.center = pi3d.Model(file_string="../Blender/lego/Emmet_body.obj") shader = pi3d.Shader("uv_light") self.center.set_shader(shader) self.center.scale(6, 6, 6) self.head = pi3d.Model(file_string="../Blender/lego/emmet_head.obj", cy=-0.6, cz=-0) self.head.set_shader(shader) self.armR = pi3d.Model(file_string="../Blender/lego/Emmet_armR.obj", cy=-0.55, cx=0.15, cz=-0) self.armR.set_shader(shader) self.armL = pi3d.Model( file_string="../Blender/lego/emmet_armL_sword.obj", cy=-0.55, cx=-0.15, cz=-0) self.armL.set_shader(shader) self.legL = pi3d.Model(file_string="../Blender/lego/Emmet_legL.obj", cy=-0.3) self.legL.set_shader(shader) self.legR = pi3d.Model(file_string="../Blender/lego/Emmet_legR.obj", cy=-0.3) self.legR.set_shader(shader) self.center.add_child(self.head) self.center.add_child(self.armR) self.center.add_child(self.armL) self.center.add_child(self.legL) self.center.add_child(self.legR)
DISPLAY = pi3d.Display.create(#x=100, y=100, background=(0.2, 0.4, 0.6, 1)) shader = pi3d.Shader("uv_reflect") flatsh = pi3d.Shader('uv_flat') #======================================== # this is a bit of a one off because the texture has transparent parts # comment out and google to see why it's included here. from pi3d import opengles, GL_CULL_FACE opengles.glDisable(GL_CULL_FACE) #======================================== # load bump and reflection textures bumptex = pi3d.Texture("/home/pi/Develop/pi3d/pi3d_demos/textures/floor_nm.jpg") shinetex = pi3d.Texture(npa) # load model_loadmodel mymodel = pi3d.Model(file_string='/home/pi/Develop/pi3d/pi3d_demos/models/teapot.obj', name='teapot') mymodel.set_shader(shader) mymodel.set_normal_shine(bumptex, 0.0, shinetex, 0.7) mysphere = pi3d.Sphere(radius=400.0, rx=180, ry=180, invert=True) mysphere.set_draw_details(flatsh, [shinetex], vmult=3.0, umult=3.0) # Fetch key presses mykeys = pi3d.Keyboard() mymouse = pi3d.Mouse(restrict=False) mymouse.start() omx, omy = mymouse.position() CAMERA = pi3d.Camera.instance()
import sys sys.path.insert(1, '/home/pi/pi3d') # to use local 'develop' branch version import pi3d import numpy as np RANGE = 100.0 MODEL_PATH = '{}' display = pi3d.Display.create(background=(0.0, 0.0, 0.0, 0.0)) shader = pi3d.Shader('uv_light') laser_shader = pi3d.Shader('mat_flat') # pod and laser 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_tip = pi3d.Cylinder(radius=0.05, height=5.0, rx=90.0, y=0.28) laser_tip.set_material((1.0, 0.0, 0.0)) laser_tip.set_alpha(0.0) laser_gun.add_child(laser_tip) laser_base.add_child(laser_gun) pod.add_child(laser_base) pod.set_shader(shader) # all use uv_light shader laser_tip.set_shader(laser_shader) # asteroid asteroid = pi3d.Model(file_string=MODEL_PATH.format('asteroid_large_1.obj'), z=50,
mytrees1.set_draw_details(flatsh, [tree2img], 0.0, 0.0) mytrees1.set_fog(*TFOG) mytrees2 = pi3d.MergeShape(name="trees2") mytrees2.cluster(treemodel2.buf[0], mymap, 0.0, 0.0, 400.0, 400.0, 80, "", 6.0, 3.0) mytrees2.set_draw_details(flatsh, [tree1img], 0.0, 0.0) mytrees2.set_fog(*TFOG) mytrees3 = pi3d.MergeShape(name="trees3") mytrees3.cluster(treemodel2, mymap, 0.0, 0.0, 300.0, 300.0, 20, "", 4.0, 2.0) mytrees3.set_draw_details(flatsh, [hb2img], 0.0, 0.0) mytrees3.set_fog(*TFOG) #Create monument monument = pi3d.Model(file_string="models/pi3d.obj", name="monument") monument.set_shader(shinesh) monument.set_normal_shine(bumpimg, 16.0, reflimg, 0.4) monument.set_fog(*FOG) monument.translate(100.0, -mymap.calcHeight(100.0, 235) + 12.0, 235.0) monument.scale(20.0, 20.0, 20.0) monument.rotateToY(65) #screenshot number scshots = 1 #avatar camera rot = 0.0 tilt = 0.0 avhgt = 3.5 xm = 0.0
# Setup display and initialise pi3d DISPLAY = pi3d.Display.create(x=50, y=50, w=-100, h=-100, background=(0.2, 0.4, 0.6, 1)) shader = pi3d.Shader('uv_light') #======================================== # load model_loadmodel mymodel = pi3d.Model(file_string='models/Triceratops/Triceratops.egg', name='Triceratops', x=0, y=-1, z=40, sx=0.005, sy=0.005, sz=0.005) mymodel.set_shader(shader) # Fetch key presses mykeys = pi3d.Keyboard() while 1: DISPLAY.clear() mymodel.draw() mymodel.rotateIncZ(0.001) mymodel.rotateIncX(-0.00317543) mymodel.rotateIncY(0.11)
height=mapheight, divx=64, divy=64) mymap.set_draw_details(shader, [mountimg1, bumpimg], 128.0, 0.0) FOG = (0.5, 0.5, 0.5, 0.8) def set_fog(shape): shape.set_fog(FOG, 1000.0) #Load tank tank_body = pi3d.Model(file_string='models/Tiger/body.obj', sx=0.1, sy=0.1, sz=0.1) tank_body.set_shader(shader) tank_body.set_normal_shine(tigerbmp) """ NB the shadow texture must be the third texture in Buffer.textures but OffscreenTextures textures don't exists until after they have been drawn to. This isn't a problem where the textures can be passed to the draw() method as with the ElevationMap see line 260. However for Model drawing the diffuse texture is loaded automatically so the botch is to check if there are still only two texttures and add the shadow map as the third one see line 177 """ tank_gun = pi3d.Model(file_string='models/Tiger/gun.obj') tank_gun.set_shader(shader) tank_turret = pi3d.Model(file_string='models/Tiger/turret.obj')
lightamb=(0.75, 0.75, 0.75), is_point=False) flatsh = pi3d.Shader("uv_flat") shadermat = pi3d.Shader("mat_light") #Set up the 3D models xyz = .03 names = ["gun", "bear", "fork", "knife", "cake"] models = [] for objname in names: temp = selectable.MySelectableObject() temp.obj = pi3d.Model(file_string=home_path + 'models/' + objname + '.obj', camera=CAMERA, name=objname, z=0.0) temp.obj.scale(xyz, xyz, xyz) temp.obj.set_shader(shadermat) temp.obj.set_light(light) temp.obj.set_fog(fogshade=(.0, .0, .0, .0), fogdist=32) models.append(temp) validColor = (0.0, 1.0, 1.0) invalidColor = (0.1, 0.1, 0.4) selectedColor = (1.0, .2, .0) screenWidth = 40 positionIncrement = screenWidth / 6 #we need 6 spaces for 5 models screenWidth = screenWidth / 2 #make the width relative to center of the screen, i.e -10 to 10 rewindPos = screenWidth - positionIncrement
def pi3d_model(): from sense_hat import SenseHat import math import pi3d sense = SenseHat() display = pi3d.Display.create() cam = pi3d.Camera.instance() shader = pi3d.Shader("mat_light") model = pi3d.Model( file_string="CS294.obj", name="model", x=0, y=-1, z=40, sx=7.5, sy=7.5, sz=7.5) model.set_shader(shader) cam.position((0, 20, 0)) cam.point_at((0, -1, 40)) keyb = pi3d.Keyboard() compass = gyro = accel = True sense.set_imu_config(compass, gyro, accel) yaw_offset = 133 while display.loop_running(): orientation = sense.get_orientation_radians() if orientation is None: pass pitch = orientation["pitch"] roll = orientation["roll"] yaw = orientation["yaw"] yaw_total = yaw + math.radians(yaw_offset) sin_y = math.sin(yaw_total) cos_y = math.cos(yaw_total) sin_p = math.sin(pitch) cos_p = math.cos(pitch) sin_r = math.sin(roll) cos_r = math.cos(roll) abs_roll = math.degrees(math.asin(sin_p * cos_y + cos_p * sin_r * sin_y)) abs_pitch = math.degrees(math.asin(sin_p * sin_y - cos_p * sin_r * cos_y)) model.rotateToZ(abs_roll) model.rotateToX(abs_pitch) model.rotateToY(math.degrees(yaw_total)) model.draw() keypress = keyb.read() if keypress == 27: keyb.close() display.destroy() break elif keypress == ord('m'): compass = not compass sense.set_imu_config(compass, gyro, accel) elif keypress == ord('g'): gyro = not gyro sense.set_imu_config(compass, gyro, accel) elif keypress == ord('a'): accel = not accel sense.set_imu_config(compass, gyro, accel) elif keypress == ord('='): yaw_offset += 1 elif keypress == ord('-'): yaw_offset -= 1
# ======================================== # this is a bit of a one off because the texture has transparent parts # comment out and google to see why it's included here. pi3d.opengles.glDisable(pi3d.GL_CULL_FACE) # ======================================== # load bump and reflection textures bumptex = pi3d.Texture("textures/floor_nm.jpg") shinetex = pi3d.Texture("textures/stars.jpg") # ======================================== # load model mymodel = pi3d.Model(file_string='models/teapot.obj', name='teapot', y=5.0, z=10.0) mymodel.set_shader(shader) mymodel.set_normal_shine(bumptex, 16.0, shinetex, 0.5) def update(): mymodel.rotateIncY(0.41) mymodel.rotateIncZ(0.12) mymodel.rotateIncX(0.23) def draw(): myecube.draw() mymodel.draw() engine.on_update = update
#Setup shaders flatsh = pi3d.Shader("shaders/uv_flat") shade2d = pi3d.Shader('shaders/2d_flat') # create splash screen and draw it splash = pi3d.ImageSprite("textures/pi3d_splash.jpg", shade2d, w=10, h=10, z=0.2) splash.draw() DISPLAY.swap_buffers() #Setup environment cube ectex = pi3d.loadECfiles("textures/ecubes/Miramar", "miramar_256", "png", nobottom = True) myecube = pi3d.EnvironmentCube(size=1800.0, maptype="FACES", nobottom=True) myecube.set_draw_details(flatsh, ectex) #Load Hall model hall = pi3d.Model(file_string="models/ConferenceHall/conferencehall.egg", name="Hall", sx=0.1, sy=0.1, sz=0.1) hall.set_shader(flatsh) #key presses mymouse = pi3d.Mouse(restrict = False) mymouse.start() omx, omy = mymouse.position() #position vars mouserot = -70.0 tilt = 10.0 avhgt = 4.0 xm = 0.0 zm = 0.0 ym = avhgt
light = pi3d.Light( ) #lightpos=(-1.0, 0.0, 10.0), lightcol=(3.0, 3.0, 2.0), lightamb=(0.02, 0.01, 0.03), is_point=True) #======================================== # this is a bit of a one off because the texture has transparent parts # comment out and google to see why it's included here. from pi3d import opengles, GL_CULL_FACE opengles.glDisable(GL_CULL_FACE) #======================================== # load bump and reflection textures bumptex = pi3d.Texture("textures/floor_nm.jpg") shinetex = pi3d.Texture("textures/stars.jpg") flatwhite = pi3d.Texture("textures/white.png") # load model_loadmodel mymodel = pi3d.Model( file_string='models/Drone/drone.obj', name='teapot', z=4) #pi3d.Model(file_string='models/teapot.obj', name='teapot', z=4) mymodel.set_shader(shader) mymodel.set_light(light) mymodel.set_normal_shine(flatwhite, 16.0, flatwhite, 0.5) #mymodel.set_normal_shine(bumptex, 16.0, shinetex, 0.5) # Fetch key presses mykeys = pi3d.Keyboard() while DISPLAY.loop_running(): mymodel.draw() #mymodel.rotateIncY(0.41) #mymodel.rotateIncZ(0.12) #mymodel.rotateIncX(0.23) #-14.949986457824707 -185.32106018066406 21.600025177001953
######################################################################## DISPLAY = pi3d.Display.create(x=100, y=100, background=(0.2, 0.4, 0.6, 1)) shader = pi3d.Shader("uv_reflect") flatsh = pi3d.Shader('uv_flat') #======================================== # this is a bit of a one off because the texture has transparent parts # comment out and google to see why it's included here. from pi3d import opengles, GL_CULL_FACE opengles.glDisable(GL_CULL_FACE) #======================================== # load bump and reflection textures bumptex = pi3d.Texture("textures/floor_nm.jpg") shinetex = pi3d.Texture(npa) # load model_loadmodel mymodel = pi3d.Model(file_string='models/teapot.obj', name='teapot') mymodel.set_shader(shader) mymodel.set_normal_shine(bumptex, 0.0, shinetex, 0.7) mysphere = pi3d.Sphere(radius=400.0, rx=180, ry=180, invert=True) mysphere.set_draw_details(flatsh, [shinetex], vmult=3.0, umult=3.0) # Fetch key presses mykeys = pi3d.Keyboard() mymouse = pi3d.Mouse(restrict=False) mymouse.start() CAMERA = pi3d.Camera.instance() dist = [-4.0, -4.0, -4.0] rot = 0.0
def pi3d_model(): from sense_hat import SenseHat import math import pi3d sense = SenseHat() display = pi3d.Display.create() cam = pi3d.Camera.instance() shader = pi3d.Shader("mat_light") # .obj file is read in and x,y,z size(s) are determined model = pi3d.Model(file_string="apollo-soyuz.obj", name="model", x=0, y=-1, z=40, sx=1.5, sy=1.5, sz=1.5) model.set_shader(shader) cam.position((0, 20, 0)) cam.point_at((0, -1, 40)) keyb = pi3d.Keyboard() compass = gyro = accel = True sense.set_imu_config(compass, gyro, accel) yaw_offset = 133 # This offset aligns the model with the Pi while display.loop_running(): orientation = sense.get_orientation_radians() if orientation is None: pass pitch = orientation["pitch"] roll = orientation["roll"] yaw = orientation["yaw"] yaw_total = yaw + math.radians(yaw_offset) # Maths! sin_y = math.sin(yaw_total) cos_y = math.cos(yaw_total) sin_p = math.sin(pitch) cos_p = math.cos(pitch) sin_r = math.sin(roll) cos_r = math.cos(roll) abs_roll = math.degrees( math.asin(sin_p * cos_y + cos_p * sin_r * sin_y)) abs_pitch = math.degrees( math.asin(sin_p * sin_y - cos_p * sin_r * cos_y)) model.rotateToZ(abs_roll) model.rotateToX(abs_pitch) model.rotateToY(math.degrees(yaw_total)) model.draw() keypress = keyb.read() if keypress == 27: keyb.close() display.destroy() break elif keypress == ord('m'): # Toggles Magnetometer compass = not compass sense.set_imu_config(compass, gyro, accel) elif keypress == ord('g'): # Toggles Gyroscope gyro = not gyro sense.set_imu_config(compass, gyro, accel) elif keypress == ord('a'): # Toggles Accelerometer accel = not accel sense.set_imu_config(compass, gyro, accel) elif keypress == ord('='): # Increases yaw offset yaw_offset += 1 elif keypress == ord('-'): # Decreases yaw offset yaw_offset -= 1
# Load all models zpos = 5 model_objs = [] dxy = 1.2 global_scale = 0.6 mf = models.asteroids[5] model_filename = mf[0] model_scale = mf[1] model_name = model_filename.split('.')[0] # Remove the .obj extention print("Loading " + model_name) m = pi3d.Model(file_string='../media/models/' + model_filename, name=model_name, x=0, y=0, z=zpos) m.set_shader(shader) m.scale(model_scale * global_scale, model_scale * global_scale, model_scale * global_scale) model_objs.append(m) # Fetch key presses mykeys = pi3d.Keyboard() t = time.time() zpos = 50 blur_amount = 10 t = time.time()
sense = SenseHat() display = pi3d.Display.create() cam = pi3d.Camera.instance() shader = pi3d.Shader("mat_light") original_pos_x = 0 original_pos_y = -1 original_pos_z = 40 model = pi3d.Model(file_string="apollo-soyuz.obj", name="model", x=original_pos_x, y=original_pos_y, z=original_pos_y, sx=1, sy=1, sz=1) model.set_shader(shader) cam.position((0, 20, 0)) cam.point_at((0, -1, 40)) keyb = pi3d.Keyboard() compass = gyro = accel = True sense.set_imu_config(compass, gyro, accel) yaw_offset = 72