t = threading.Thread(target=start_capture) t.start() while not new_pic: time.sleep(0.1) ######################################################################## 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)
def end_capture(self, side): """ stop capturing to texture and resume normal rendering to default """ self.textures[side]._end() if self.interlace <= 0: opengles.glDisable(GL_SCISSOR_TEST)
""" val = np.zeros(xy.shape[:2]) # ie same x,y dimensions xy = np.array(xy, dtype=np.float) * self.freq per = int(self.freq * self.size) for o in range(self.octs): val += 0.5**o * self.noise(xy * 2**o, per * 2**o) return val DISPLAY = pi3d.Display.create(x=50, y=50, frames_per_second=20, background=(0.6, 0.5, 0.0, 1.0)) opengles.glDisable( GL_CULL_FACE ) # do this as it will be possible to look under terrain, has to done after Display.create() shader = pi3d.Shader("mat_light") flatsh = pi3d.Shader("mat_flat") perlin = Noise3D(PSIZE, PFREQ, POCT) # size of grid, frequency of noise, # number of octaves, use 5 octaves as reasonable balance #### generate terrain norms = [] tex_coords = [] idx = [] wh = hh = W / 2.0 # half size ws = hs = W / (IX - 1.0) # dist between each vert tx = tz = 1.0 / IX
#return a value for noise in 2D def generate(self, xy): """ xy is 3D array of x,y values """ val = np.zeros(xy.shape[:2]) # ie same x,y dimensions xy = np.array(xy, dtype=np.float) * self.freq per = int(self.freq * self.size) for o in range(self.octs): val += 0.5**o * self.noise(xy * 2**o, per * 2**o) return val DISPLAY = pi3d.Display.create(x=50, y=50, frames_per_second=20, background=(0.6, 0.5, 0.0, 1.0)) opengles.glDisable(GL_CULL_FACE) # do this as it will be possible to look under terrain, has to done after Display.create() shader = pi3d.Shader("mat_light") flatsh = pi3d.Shader("mat_flat") perlin = Noise3D(PSIZE, PFREQ, POCT) # size of grid, frequency of noise, # number of octaves, use 5 octaves as reasonable balance #### generate terrain norms = [] tex_coords = [] idx = [] wh = hh = W / 2.0 # half size ws = hs = W / (IX - 1.0) # dist between each vert tx = tz = 1.0 / IX
This is almost certainly because of the images, so with larger images it may be worth pickling without the Textures and adding these after loading. """ import demo import pi3d # Setup display and initialise pi3d DISPLAY = pi3d.Display.create(x=100, y=100, background=(0.2, 0.4, 0.6, 1)) shader = pi3d.Shader("uv_reflect") #======================================== # 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) from pi3d import opengles, GL_ALPHA_TEST opengles.glDisable(GL_ALPHA_TEST) #======================================== # load model try: with open('models/teapot.pkl', 'rb') as f: #python3 requires binary import pickle mymodel = pickle.load(f) except Exception as e: print("exception was {}".format(e)) """ could be IOError for missing file or various errors from trying to load a file pickled with a different version of python or pickle etc""" mymodel = pi3d.Model(file_string='models/teapot.obj', name='teapot', z=4.0) # load bump and reflection textures bumptex = pi3d.Texture("textures/floor_nm.jpg") shinetex = pi3d.Texture("textures/stars.jpg")