def build_scene(): scene_items = [] # Insert filename into WavefrontReader. terrain_file = "terrain.obj" terrain_reader = rc.WavefrontReader(terrain_file) # Get terrain mesh terrain = get_terrain(terrain_reader, terrain_file) # Get tree mesh tree_file = "tree.obj" tree_render = rc.WavefrontReader(tree_file) tree = add_tree_to_terrain(terrain, random.randint(0, len(terrain.vertices)), tree_render, tree_file) scene_items.append(tree) scene_items.append(terrain) return scene_items
def build_scene(): scene_items = [] # Insert filename into WavefrontReader. terrain_file = "terrain.obj" terrain_reader = rc.WavefrontReader(terrain_file) # Get terrain mesh terrain = get_terrain(terrain_reader, terrain_file) # Get tree mesh tree_file = "tree.obj" tree_render = rc.WavefrontReader(tree_file) trees = scatter_randomly(terrain, tree_render, tree_file) scene_items.extend(trees) scene_items.append(terrain) return scene_items
def make_world_from_fw(self, fw_path): f = open(fw_path) self.name = re.match(r'WORLD_NAME:(.*);', f.readline()).groups()[0] self.size = int( re.match(r'WORLD_SIZE:(.*);', f.readline()).groups()[0]) self.objs_num = int( re.match(r'OBJ_NUM:(.*);', f.readline()).groups()[0]) self.objs.append( Obj_Attr( rc.WavefrontReader('models/box.obj').get_mesh( "box", position=(0, -.1, -1.5), scale=.03 * self.size / 20, rotation=(0, -90, 0)), (0, 0), 0, 0, 0)) # add floor; self.objs[0].mesh.textures.append( rc.Texture().from_image('models/wall.jpg')) for i in range(self.objs_num): self.objs.append(self.resolve_obj(f.readline())) if i > 0: OBSTACLES_OBJS.append(self.objs[-1].position) self.rules_num = int( re.match(r'RULE_NUM:(.*);', f.readline()).groups()[0]) for i in range(self.rules_num): self.rules.append(self.resolve_rule(f.readline())) self.objs[1].mesh.textures.append( rc.Texture().from_image('models/roof_1.jpg'))
def resolve_obj(self,line): (ID,model,mesh,pos,temp,move) = re.match(r'OBJ:ID:"(.*)";MODEL:"(.*)";MESH:"(.*)";POS:(.*);TEMP:"(.*)";MOVE:"(.*)";',line).groups(); #print (ID,model,mesh,pos); pos = pos.split(',');pos=[float(i) for i in pos]; entity = rc.WavefrontReader(model).get_mesh(mesh,position=(pos[0], -.1,pos[1]), scale=.1, rotation=(0, 0, 0)); #entity.uniforms['diffuse'] = 1, 1, 0 #give color; return Obj_Attr(entity,pos,move,temp,0);
def _load_scene(self): # ratcave instantly creates gl resources so we can't import earlier import ratcave as rc # Insert filename into WavefrontReader. obj_filename = rc.resources.obj_primitives obj_reader = rc.WavefrontReader(obj_filename) # Create Mesh self._monkey = obj_reader.get_mesh("Monkey", scale=.7) self._monkey.position.xyz = 0, 0, 0 self._monkey.uniforms['diffuse'] = 0., 0., 1. self._monkey.uniforms['spec_weight'] = 300. self._torus = obj_reader.get_mesh("TorusSmooth") self._torus.position.xyz = 0, 0, 0 self._torus.rotation.x = 20 self._torus.uniforms['diffuse'] = 1., 0., 0. self._torus.uniforms['spec_weight'] = 300. # Create Scene self._scene = rc.Scene(meshes=[self._monkey, self._torus]) self._scene.light.position.z = 3 self._scene.light.position.x = 3 # Prebuild shader with rc.default_shader: pass # mutables self._torus_xpos = imgui.Float(0) self._cam_angle = imgui.Float(0) self._cam_dist = imgui.Float(3)
def __init__(self, *args, **kwargs): """ Returns Window with everything needed for doing arena scanning. Will automatically close when all camera movement has completed. """ super(GridScanWindow, self).__init__(*args, **kwargs) wavefront_reader = rc.WavefrontReader(rc.resources.obj_primitives) self.mesh = wavefront_reader.get_mesh('Grid', position=[0., 0., -1.], scale=1.5, point_size=12, drawstyle='point') self.mesh.uniforms['diffuse'] = [1., 1., 1.] # Make white self.mesh.uniforms['flat_shading'] = True self.scene = rc.Scene([self.mesh], bgColor=(0, 0, 0)) self.scene.camera.ortho_mode = True dist = .06 self.cam_positions = ((dist * np.sin(ang), dist * np.cos(ang), -1) for ang in np.linspace(0, 2 * np.pi, 40)[:-1]) self.marker_pos = [] pyglet.clock.schedule(self.detect_projection_point) pyglet.clock.schedule(self.move_camera)
def gen_spheres(scale=.01, color=(1., 1., 1.)): reader = rc.WavefrontReader(rc.resources.obj_primitives) spheres = [] for row, col in product(*[np.linspace(-.5, .5, 20)]*2): sphere = reader.get_mesh('Sphere', position=(row, col, -1), scale=scale,) sphere.uniforms['flat_shading'] = 1 sphere.uniforms['diffuse'] = color spheres.append(sphere) return spheres
def load_object(file): # Insert filename into WavefrontReader. file_reader = rc.WavefrontReader(file) # Create Mesh object = file_reader.get_mesh(get_body_name(file), position=(0, 0, 0), scale=1.0) set_material(object) return object
def build_scene(): scene_items = [] # Insert filename into WavefrontReader. terrain_file = args.terrain_path if args.terrain_path else "terrain.obj" terrain_reader = rc.WavefrontReader(terrain_file) # Get terrain mesh terrain = get_terrain(terrain_reader, terrain_file) # Get tree mesh tree_file = args.tree_path if args.tree_path else "tree.obj" # print tree_file tree_render = rc.WavefrontReader(tree_file) if args.image_path: trees = scatter_based_on_image(terrain, tree_render, tree_file, args.image_path) else: trees = scatter_randomly(terrain, tree_render, tree_file) scene_items.extend(trees) scene_items.append(terrain) return scene_items
def make_world_from_fw(self,fw_path): f = open(fw_path); self.name = re.match(r'WORLD_NAME:(.*);',f.readline()).groups()[0]; self.size = int(re.match(r'WORLD_SIZE:(.*);',f.readline()).groups()[0]); self.objs_num = int(re.match(r'OBJ_NUM:(.*);',f.readline()).groups()[0]); self.objs.append(Obj_Attr( rc.WavefrontReader('obj/box/box.obj').get_mesh("box",position=(0, -.1, -1.5), scale=.03*self.size/20, rotation=(0, -90, 0)), (0,0),0,0,0)); # add floor; for i in range(self.objs_num): self.objs.append(self.resolve_obj( f.readline() )); self.rules_num = int(re.match(r'RULE_NUM:(.*);',f.readline()).groups()[0]); for i in range(self.rules_num): self.rules.append(self.resolve_rule( f.readline() ));
def __init__(self,client_sock,server_sock): #Handling user keyboard inputs self.keys = key.KeyStateHandler() window.push_handlers(self.keys) #Used for reading and handling user inputs self.client_sock = client_sock self.server_sock = server_sock #Default stats label to be displayed self.stats = ['Fall Status: False','Fall Distance: Nan'] # Load Meshes and put into a Scene obj_reader = rc.WavefrontReader(rc.resources.obj_primitives) self.sphere = obj_reader.get_mesh('Sphere', position=(0, 0, -3),scale=0.3) self.torus = obj_reader.get_mesh('Torus', position=(0, 0, -3),scale=0.5) self.torus2 = obj_reader.get_mesh('Torus', position=(0, 0, -3),scale=0.5) #set up diffuse color for meshes self.sphere.uniforms['diffuse'] = [.6, .6, .6] self.torus.uniforms['diffuse'] = [1, 0, 0] self.torus2.uniforms['diffuse'] = [0, 0, 1] #setting up the defaults self.azimuth = 0 self.pitch = 0 self.roll = 0 self.vx = 0 self.vy = 0 self.vz = 0 #add meshes to scene self.scene = rc.Scene(meshes=[self.sphere,self.torus,self.torus2]) #set up scene background color self.scene.bgColor = 138/255, 113/255, 145/255 #schdules the update and user input functions to run pyglet.clock.schedule_interval(self.update, 1.0/40.0) # pyglet.clock.schedule_interval(self.get_recent_valid_data, 1.0/60.0) pyglet.clock.schedule(self.user_inputs) #used to display animation self.begin_animation = False #exit game condition self.end_game=False self.animation_data = [] self.display_data = Queue() self.iter_barrier = threading.Barrier(2)
def get_virtual_arena_mesh(arena_file, arena_mesh, objname='Arena', texture_filename=None): """Returns an arena mesh parented to another arena meesh and with lighting settings applied.""" vr_arena = rc.WavefrontReader(arena_file).get_mesh(objname) vr_arena.uniforms['diffuse'] = 1., 1, 1 vr_arena.parent = arena_mesh vr_arena.uniforms['flat_shading'] = False if texture_filename: vr_arena.texture = rc.Texture.from_image(texture_filename) return vr_arena
def make_scene(self): # Insert filename into WavefrontReader. obj_filename = rc.resources.obj_primitives obj_reader = rc.WavefrontReader(obj_filename) # Create Mesh monkey = obj_reader.get_mesh("Monkey") monkey.position.xyz = 0, 0, -5 # Create Scene self.scene = rc.Scene(meshes=[monkey], bgColor=(0, 1, 0))
def resolve_obj(line): (ID, model, mesh, pos) = re.match(r'OBJ:ID:"(.*)";MODEL:"(.*)";MESH:"(.*)";POS:(.*?);', line).groups() print(ID, model, mesh, pos) pos = pos.split(',') pos = [float(i) for i in pos] return Obj_Attr( rc.WavefrontReader(model).get_mesh(mesh, position=(pos[0], pos[1], -1.5), scale=.03, rotation=(0, 0, 0)), pos, 0, 0, 0)
def __init_entities(self): self.obj_filename = rc.resources.obj_primitives self.obj_reader = rc.WavefrontReader(self.obj_filename) self.quad_pool = EntityPool(self.__make_quadrotor) self.axis_pool = EntityPool(self.__make_axis) self.goal_pool = EntityPool(self.__make_goal) self.grid_pool = EntityPool(self.__make_grid) self.line_pool = EntityPool(self.__make_line) self.entity_pools = [ self.quad_pool, self.axis_pool, self.goal_pool, self.grid_pool, self.line_pool ]
def view_mesh(body, obj_filename): # """Displays mesh in .obj file. Useful for checking that files are rendering properly.""" reader = rc.WavefrontReader(obj_filename) mesh = reader.get_mesh(body, position=(0, 0, -1)) print(mesh.vertices.shape) mesh.scale.x = .2 / np.ptp(mesh.vertices, axis=0).max() camera = rc.Camera(projection=rc.PerspectiveProjection(fov_y=20)) light = rc.Light(position=(camera.position.xyz)) scene = rc.Scene(meshes=[mesh], camera=camera, light=light, bgColor=(.2, .4, .2)) scene.gl_states = scene.gl_states[:-1] display = pyglet.window.get_platform().get_default_display() screen = display.get_screens()[0] window = pyglet.window.Window(fullscreen=True, screen=screen) fbo = rc.FBO(rc.Texture(width=4096, height=4096)) quad = rc.gen_fullscreen_quad() quad.texture = fbo.texture label = pyglet.text.Label() @window.event def on_draw(): with rc.resources.genShader, fbo: scene.draw() with rc.resources.deferredShader: quad.draw() verts_mean = np.ptp(mesh.vertices, axis=0) label.text = 'Name: {}\nRotation: {}\nSize: {} x {} x {}'.format( mesh.name, mesh.rotation, verts_mean[0], verts_mean[1], verts_mean[2]) label.draw() @window.event def on_resize(width, height): camera.projection.aspect = float(width) / height @window.event def on_mouse_motion(x, y, dx, dy): x, y = x / float(window.width) - .5, y / float(window.height) - .5 mesh.rotation.x = -360 * y mesh.rotation.y = 360 * x pyglet.app.run()
def __init__(self, projector, serial_device, *args, **kwargs): super(LatencyDisplayApp, self).__init__(*args, **kwargs) self.device = serial_device pyglet.clock.schedule(lambda dt: None) reader = rc.WavefrontReader(rc.resources.obj_primitives) self.dot = reader.get_mesh('Sphere', scale=.02, position=(0, 0, 0)) self.dot.uniforms['diffuse'] = 1., 0., 0. self.dot.uniforms['flat_shading'] = True self.scene = rc.Scene(meshes=[self.dot], bgColor=(0., 0., 0.)) self.scene.camera = projector self.scene.camera.projection.aspect = 1.7777 self.shader3d = rc.Shader.from_file(*rc.resources.genShader) self.latency_display = pyglet.text.Label(text='Waiting for Stimulus Switch..', x=0, y=0, font_size=36) pyglet.clock.schedule(self.update_latency_display)
def __init__(self, *args, **kwargs): super(RotationWindow, self).__init__(*args, **kwargs) pyglet.clock.schedule(lambda dt: None) reader = rc.WavefrontReader(rc.resources.obj_primitives) self.mesh = reader.get_mesh('Monkey', scale=.05, position=(0, 0, 0)) self.mesh.rotation = self.mesh.rotation.to_quaternion() self.scene = rc.Scene(meshes=[self.mesh], bgColor=(0., 0., 0.)) self.fbo = rc.FBO(rc.Texture(width=4096, height=4096)) self.quad = rc.gen_fullscreen_quad() self.quad.texture = self.fbo.texture self.label = pyglet.text.Label() self.shader3d = rc.Shader.from_file(*rc.resources.genShader) self.shaderAA = rc.Shader.from_file(*rc.resources.deferredShader)
def load_projected_scene(arena_file, projector_file, motive_client): """Scene-building convenience function. Returns (scene, arena, arena_rb) from filenames and motive.""" arena = rc.WavefrontReader(arena_file).get_mesh('Arena') arena.uniforms['diffuse'] = 1., 1, 1 arena.uniforms['flat_shading'] = False arena.rotation = arena.rotation.to_quaternion() arena_rb = motive_client.rigid_bodies['Arena'] arena.position.xyz = arena_rb.position arena.rotation.wxyz = arena_rb.quaternion scene = rc.Scene(meshes=[arena], bgColor=(.6, 0, 0)) scene.gl_states = scene.gl_states[:-1] beamer = rc.Camera.from_pickle(projector_file) scene.camera.position.xyz = beamer.position.xyz scene.camera.rotation.xyz = beamer.rotation.xyz scene.camera.projection.fov_y = 41.5 scene.camera.projection.aspect = 1.7778 scene.light.position.xyz = scene.camera.position.xyz return scene, arena, arena_rb
def main(): FULLSCREEN = True reader = rc.WavefrontReader('resources/maze.obj') arena = reader.get_mesh('Cube') arena.textures.append(rc.Texture.from_image(rc.resources.img_uvgrid)) sphere = reader.get_mesh('Sphere') # , position=(0, 0, -1)) cylinder = reader.get_mesh('Cylinder') # , position=(0, 0, -1)) player = rc.Camera(projection=rc.PerspectiveProjection(z_near=.001, z_far=4.5), position=(0, .3, 0)) player.rotation.axes = 'sxyz' scene = rc.Scene(meshes=[arena, sphere, cylinder], camera=player, bgColor=(1., 0., 0.)) #scene.gl_states = scene.gl_states[:-1] window = FPSGame(player=player, scene=scene, fullscreen=FULLSCREEN) pyglet.app.run()
def __init__(self, max_points=1000, *args, **kwargs): """ Returns Window with everything needed for doing projector calibration. Keyword Args: -max_points (int): total number of data points to collect before exiting. """ super(PointScanWindow, self).__init__(*args, **kwargs) wavefront_reader = rc.WavefrontReader(rc.resources.obj_primitives) self.mesh = wavefront_reader.get_mesh('Sphere', position=[0., 0., -1.], scale=.01) self.mesh.uniforms['diffuse'] = [1., 1., 1.] # Make white self.mesh.uniforms['flat_shading'] = True self.scene = rc.Scene([self.mesh], bgColor=(0, 0, 0)) self.scene.camera.ortho_mode = True self.max_points = max_points self.screen_pos = [] self.marker_pos = [] pyglet.clock.schedule(self.detect_projection_point) pyglet.clock.schedule(self._close_if_max_points_reached)
import pyglet import ratcave as rc import itertools as it import numpy as np try: from contextlib import ExitStack except ImportError: from contextlib2 import ExitStack # Create Window window = pyglet.window.Window(resizable=True, vsync=False) # Create Mesh obj_filename = rc.resources.obj_primitives obj_reader = rc.WavefrontReader(obj_filename) monkey = obj_reader.get_mesh("Monkey") monkey.uniforms['flat_shading'] = False monkey.position.xyz = 0, 0, -4 monkey.scale.xyz = .25 monkey.point_size = .1 plane = obj_reader.get_mesh('Plane') plane.position.xyz = 0, 0, -5 plane.rotation.x = 0 plane.scale.xyz = 8 plane.uniforms['spec_weight'] = 0 fps_display = pyglet.window.FPSDisplay(window) light = rc.Light()
OBJ_NAME = 'Cube' NUM_OBJECTS = 20 USE_CUBEMAP = True CUBEMAP_TEXTURE_SIZE = 2048 HAS_UNIFORMS = True IS_MOVING = True ROLLING_WINDOW_LEN = 30 FULLSCREEN = True ANTIALIAS = True # Create Window window = pyglet.window.Window(resizable=True, vsync=False, fullscreen=FULLSCREEN) # Generate Objects reader = rc.WavefrontReader(rc.resources.obj_primitives) player = rc.mesh.EmptyMesh() screen = reader.get_mesh('Plane') screen.position = 0, 0, -1 screen.scale = .7 screen.uniforms['diffuse'] = .7, 0, 0 def sphere_factory(reader, n=10): for _ in range(n): sphere = reader.get_mesh(OBJ_NAME, scale=.1) sphere.position = np.append(2 * np.random.random(2) - 1, [-2]) if not HAS_UNIFORMS: sphere.uniforms = rc.UniformCollection() else: sphere.uniforms['diffuse']= np.random.random(3)
import ratcave as rc import pyglet window = pyglet.window.Window(resizable=True, width=400, height=800) pyglet.clock.schedule(lambda dt: dt) cube = rc.WavefrontReader(rc.resources.obj_primitives).get_mesh('Cube', scale=.02) cube.position.xyz = .5, .5, -2 cam = rc.Camera() cam.projection = rc.OrthoProjection(coords='relative', origin='corner') @window.event def on_draw(): with rc.default_shader, rc.default_states, cam: cube.draw() @window.event def on_resize(width, height): # cam.projection.match_aspect_to_viewport() cam.projection.aspect = width / height # cam.reset_uniforms() # cam.projection.projection_matrix[0, 0] += .01 print(cam.projection.viewport) print(cam.projection_matrix) print(cam.uniforms['projection_matrix']) pyglet.app.run()
Y = curr_timeseries[1].to_arrays()[1] Z = curr_timeseries[2].to_arrays()[1] Roll = curr_timeseries[3].to_arrays()[1] Pitch = curr_timeseries[4].to_arrays()[1] Yaw = curr_timeseries[5].to_arrays()[1] window = pyglet.window.Window(resizable=True) keys = key.KeyStateHandler() window.push_handlers(keys) global f f = 0 # get an object model_file = rc.resources.obj_primitives monkey = rc.WavefrontReader("M206v4.obj").get_mesh('Cube', scale=.1) monkey.position.xyz = 0, 0, -3.5 monkey.uniforms['diffuse'] = [0.255, 0.191, 0.] # RGB values scene = rc.Scene(meshes=[monkey]) scene.camera.rotation.x = -15 scene.light.rotation.x = -15 def move_camera(dt): camera_speed = 3 if keys[key.LEFT]: scene.camera.position.x -= camera_speed * dt if keys[key.RIGHT]:
float mean = 0.5; float std = .1; uniform float theta; void main() { brightness = sin(texCoord.x / width + theta) / 2.; // Sine wave brightness *= exp(-.5 * pow(texCoord.x - mean, 2) / pow(std, 2)); // x-gaussian brightness *= exp(-.5 * pow(texCoord.y - mean, 2) / pow(std, 2)); // y-gaussian brightness += .5; // Add grey value final_color = vec4(vec3(brightness), 1.) ; } """ shader = rc.Shader(vert=vert_shader, frag=frag_shader) plane = rc.WavefrontReader(rc.resources.obj_primitives).get_mesh( 'Plane') #gen_fullscreen_quad() plane.scale.xyz = .2 plane.position.xyz = 0, 0, -1 plane.uniforms['theta'] = 0. plane.uniforms['width'] = .01 window = pyglet.window.Window(fullscreen=True) scene = rc.Scene(meshes=[plane], bgColor=(.5, .5, .5), camera=rc.Camera(projection=rc.OrthoProjection())) # Draw Function @window.event def on_draw():
def main(): #gettign positions of rigib bodies in real time client = NatClient() arena_rb = client.rigid_bodies['Arena'] rat_rb = client.rigid_bodies['Rat'] window = pyglet.window.Window(resizable=True, fullscreen=True, screen=get_screen(1)) # Opening the basic pyglet window # Load Arena remove_image_lines_from_mtl('assets/3D/grass_scene.mtl') arena_filename = 'assets/3D/grass_scene.obj'# we are taking an arena which has been opened in blender and rendered to 3D after scanning it does not have flipped normals arena_reader = rc.WavefrontReader(arena_filename) # loading the mesh of the arena thought a wavefrontreader arena = arena_reader.get_mesh("Arena", position=arena_rb.position) # making the wafrotn into mesh so we can extrude texture ont top of it. arena.uniforms['diffuse'] = 1., 1., 1. # addign a white diffuse material to the arena arena.rotation = arena.rotation.to_quaternion() # we also need to get arena's rotation not just xyz so it can be tracked and moved if it gets bumped # Load the projector as a Ratcave camera, set light to its position projector = rc.Camera.from_pickle('assets/3D/projector.pkl') # settign the pickle filled of the projector, which gives us the coordinates of where the projector is projector.position.x += .004 projector.projection = rc.PerspectiveProjection(fov_y =40.5, aspect=1.777777778) light = rc.Light(position=projector.position) ## Make Virtual Scene ## fields = [] for x, z in itertools.product([-.8, 0, .8], [-1.6, 0, 1.6]): field = load_textured_mesh(arena_reader, 'grass', 'grass.png') field.position.x += x field.position.z += z fields.append(field) ground = load_textured_mesh(arena_reader, 'Ground', 'dirt.png') sky = load_textured_mesh(arena_reader, 'Sky', 'sky.png') snake = load_textured_mesh(arena_reader, 'Snake', 'snake.png') rat_camera = rc.Camera(projection=rc.PerspectiveProjection(aspect=1, fov_y=90, z_near=.001, z_far=10), position=rat_rb.position) # settign the camera to be on top of the rats head meshes = [ground, sky, snake] + fields for mesh in meshes: mesh.uniforms['diffuse'] = 1., 1., 1. mesh.uniforms['flat_shading'] = False mesh.parent = arena virtual_scene = rc.Scene(meshes=meshes, light=light, camera=rat_camera, bgColor=(0, 0, 255)) # seetign aset virtual scene to be projected as the mesh of the arena virtual_scene.gl_states.states = virtual_scene.gl_states.states[:-1] ## Make Cubemapping work on arena cube_texture = rc.TextureCube(width=4096, height=4096) # usign cube mapping to import eh image on the texture of the arena framebuffer = rc.FBO(texture=cube_texture) ## creating a fr`amebuffer as the texture - in tut 4 it was the blue screen arena.textures.append(cube_texture) # Stereo vr_camgroup = rc.StereoCameraGroup(distance=.05) vr_camgroup.rotation = vr_camgroup.rotation.to_quaternion() # updating the posiotn of the arena in xyz and also in rotational perspective def update(dt): """main update function: put any movement or tracking steps in here, because it will be run constantly!""" vr_camgroup.position, vr_camgroup.rotation.xyzw = rat_rb.position, rat_rb.quaternion # setting the actual osiont of the rat camera to vbe of the rat position arena.uniforms['playerPos'] = rat_rb.position arena.position, arena.rotation.xyzw = arena_rb.position, arena_rb.quaternion arena.position.y -= .02 pyglet.clock.schedule(update) # making it so that the app updates in real time @window.event def on_draw(): ## Render virtual scene onto cube texture with framebuffer: with cube_shader: for mask, camside in zip([(True, False, False, True), (False, True, True, True)], [vr_camgroup.left, vr_camgroup.right]): gl.glColorMask(*mask) virtual_scene.camera.position.xyz = camside.position_global virtual_scene.draw360_to_texture(cube_texture) ## Render real scene onto screen gl.glColorMask(True, True, True, True) window.clear() with cube_shader: # usign cube shader to create the actuall 6 sided virtual cube which gets upated with position and angle of the camera/viewer rc.clear_color(255, 0, 0) # why is it here 39? e with projector, light: arena.draw() # actually run everything. pyglet.app.run()
import pyglet import ratcave as rc from pyglet.gl import gl from pyglet.window import key window = pyglet.window.Window(resizable=True) keys = key.KeyStateHandler() window.push_handlers(keys) # get an object model_file = rc.resources.obj_primitives monkey = rc.WavefrontReader(model_file).get_mesh('Monkey') monkey.position.xyz = 0, 0, -2.5 camera = rc.StereoCameraGroup() @window.event def on_draw(): gl.glColorMask(True, True, True, True) window.clear() with rc.default_shader, rc.default_states: with camera.right: gl.glColorMask(False, True, True, True) monkey.draw() gl.glClear(gl.GL_DEPTH_BUFFER_BIT) with camera.left: gl.glColorMask(True, False, False, True)
bg_mesh = rc.Mesh.from_incomplete_data(bg_data, position=(0, 0, -.5)) bg_mesh.uniforms['diffuse'] = 1., 1, 1 # bg_mesh.scale.xyz = 3. bg_mesh.drawmode = rc.POINTS bg_mesh.dynamic = True bg_mesh.point_size = 4 fg_mesh = rc.Mesh.from_incomplete_data(bg_data, position=(0, 0, -2.5)) fg_mesh.uniforms['diffuse'] = 1., 1, 1 # bg_mesh.scale.xyz = 3. fg_mesh.drawmode = rc.POINTS fg_mesh.dynamic = True fg_mesh.point_size = 4 fg_mesh.scale.xyz = 5, 5, 1. blocker1 = rc.WavefrontReader(rc.resources.obj_primitives).get_mesh('Plane') blocker1.parent = bg_mesh blocker1.uniforms['diffuse'] = (0., ) * 3 blocker1.uniforms['flat_shading'] = True blocker1.position.xyz = -.66, 0, -.001 blocker1.scale.xyz = .6, .9, 1. bg_mesh.update() blocker2 = rc.WavefrontReader(rc.resources.obj_primitives).get_mesh('Plane') blocker2.parent = bg_mesh blocker2.uniforms['diffuse'] = (0., ) * 3 blocker2.uniforms['flat_shading'] = True blocker2.position.xyz = .66, 0, -.001 blocker2.scale.xyz = .6, .9, 1. bg_mesh.update()
def __init__(self, arena_objfile, projector_file, fullscreen=True, screen=1, antialiasing=True, vsync=False, fps_mode=False, *args, **kwargs): """ A Pyglet Window that sets up the arena, beamer, and virtual scenes, along with motive update and draw functions for updating and rendering a virtual reality environment in a ratCAVE setup. """ self.__display = pyglet.window.get_platform().get_default_display() self.__screen = self.__display.get_screens()[screen] super(self.__class__, self).__init__(fullscreen=fullscreen, screen=self.__screen, vsync=vsync, *args, **kwargs) self.cube_fbo = rc.FBO(texture=rc.TextureCube(width=4096, height=4096)) self.arena = rc.WavefrontReader(arena_objfile).get_mesh( cfg.ARENA_MESH_NAME) self.arena.uniforms['diffuse'] = cfg.ARENA_LIGHTING_DIFFUSE self.arena.uniforms['flat_shading'] = cfg.ARENA_LIGHTING_FLAT_SHADING self.arena.rotation = self.arena.rotation.to_quaternion() self.arena_rb = motive.rigid_bodies[cfg.ARENA_MOTIVE_NAME] self.arena.position.xyz = self.arena_rb.position self.arena.rotation.wxyz = self.arena_rb.quaternion beamer = rc.Camera.from_pickle(projector_file) beamer.projection.aspect = 1.77778 beamer.projection.fov_y = 41.5 self.active_scene = rc.Scene(meshes=[self.arena], bgColor=(.6, 0, 0), camera=beamer) self.active_scene.gl_states.states = self.active_scene.gl_states.states[: -1] self.active_scene.light.position.xyz = beamer.position.xyz self.orig_texture = None self.shader = rc.resources.cube_shader self._vr_scenes = set() self.current_vr_scene = None self.rodent_rb = motive.rigid_bodies[cfg.RODENT_MOTIVE_NAME] self.antialiasing = antialiasing # self.fbo_aa = rc.FBO(rc.Texture(width=4096, height=4096, mipmap=True)) # self.aa_quad = rc.gen_fullscreen_quad() # self.aa_quad.texture = self.fbo_aa.texture # self.shader_deferred = rc.Shader.from_file(*rc.resources.deferredShader) if fps_mode: raise NotImplementedError( "Haven't gotten fps_mode to work properly yet.") self.fps_mode = fps_mode pyglet.clock.schedule(self.update)