def update_recording(scn): global records, timer if records is None: records = {} timer = 0 record = {} record['cam'] = serialize_matrix( scn.GetCurrentCamera().GetTransform().GetWorld()) head_controller = gs.GetInputSystem().GetDevice("openvr_hmd") if head_controller is not None: record['head_controller'] = serialize_matrix( head_controller.GetMatrix(gs.InputDevice.MatrixHead)) controller0 = gs.GetInputSystem().GetDevice("openvr_controller_0") if controller0 is not None: record['controller_0'] = serialize_matrix( controller0.GetMatrix(gs.InputDevice.MatrixHead)) controller1 = gs.GetInputSystem().GetDevice("openvr_controller_1") if controller1 is not None: record['controller_1'] = serialize_matrix( controller1.GetMatrix(gs.InputDevice.MatrixHead)) if gs.GetPlus().KeyDown(gs.InputDevice.KeyN): record['clap'] = True records[str(timer)] = record timer += gs.GetPlus().GetClockDt().to_sec()
def change_groupe(scn, gui, openvr_frame_renderer): global current_stages, current_node_groupe, current_audio_group, counter_wait counter_wait -= plus.GetClockDt().to_sec() # switch highlighted group if (counter_wait < 0.0 and current_audio_group is None and current_node_groupe is None) or plus.KeyPress( gs.InputDevice.KeySpace): counter_wait = 1.0 for node in scn_glow.GetNodes(): node.SetEnabled(False) node = scn_glow.GetNode(app_stages[current_stages]["name_group"]) if node is not None: node.SetEnabled(True) current_node_groupe = node else: current_node_groupe = None current_stages += 1 if current_stages >= len(app_stages): current_stages = 0 # launch audio after 1 sec, and if the user find it if counter_wait < 0.0 and current_audio_group is None and not gui.WantCaptureMouse( ): controller0 = gs.GetInputSystem().GetDevice("openvr_controller_0") # if slighlty press gachette if openvr_frame_renderer is not None and controller0 is not None and controller0.GetValue( gs.InputDevice.InputButton2) > 0.2: mat_controller = controller0.GetMatrix(gs.InputDevice.MatrixHead) pos_cam = scn.GetCurrentCamera().GetTransform().GetPosition() pos_laser = mat_controller.GetTranslation() + pos_cam dir_laser = mat_controller.GetZ() hit, trace = scn.GetPhysicSystem().Raycast(pos_laser, dir_laser, 4) if hit: scene_simple_graphic = scn.GetComponent("SceneOverlay") helper_2d.draw_line(scene_simple_graphic, pos_laser, trace.GetPosition(), gs.Color(238 / 255, 235 / 255, 92 / 255)) name = trace.GetNode().GetName() if name == app_stages[current_stages][ "name_group"] and controller0.GetValue( gs.InputDevice.InputButton2) == 1.0: current_audio_group = plus.GetMixer().Stream( app_stages[current_stages]["sound"]) elif openvr_frame_renderer is None: current_audio_group = plus.GetMixer().Stream( app_stages[current_stages]["sound"]) # if the audio finish, enable the switch group if current_audio_group is not None and plus.GetMixer().GetPlayState( current_audio_group) != gs.MixerPlaying: current_audio_group = None current_node_groupe = None counter_wait = 1.0
def pre_update(scn, openvr_frame_renderer): global saved_cam_matrix if show_live_cam: saved_cam_matrix = scn.GetCurrentCamera().GetTransform().GetWorld() cam = scn.GetCurrentCamera() if cam is not None: controller1 = gs.GetInputSystem().GetDevice("openvr_controller_1") if controller1 is not None: cam.GetTransform().SetWorld( saved_cam_matrix * controller1.GetMatrix(gs.InputDevice.MatrixHead) * calibration_matrix)
def draw_fps(scn, gui, scene_simple_graphic, use_vr, dt_sec): fps_text = "FPS:{0}".format(int(1 / dt_sec.to_sec())) if use_vr: head_controller = gs.GetInputSystem().GetDevice("openvr_hmd") if head_controller is not None and scn.GetCurrentCamera() is not None: text_mat = head_controller.GetMatrix( gs.InputDevice.MatrixHead) * gs.Matrix4.TranslationMatrix( gs.Vector3(-0.1, -0.1, 0.5)) text_pos = text_mat.GetTranslation() + scn.GetCurrentCamera( ).GetTransform().GetPosition() scene_simple_graphic.SetDepthTest(False) scene_simple_graphic.SetBlendMode(gs.BlendAlpha) scene_simple_graphic.Text(text_pos.x, text_pos.y, text_pos.z, fps_text, gs.Color.Green, font, 0.001) gui.Text(fps_text)
def update_controller(scn): global controller_nodes, helmet_node if scn.GetCurrentCamera() is None or not create_nodes_controller: return # if helmet_node is None: # helmet_node = create_helmet(scn) # draw the 2 controllers for i in range(2): if i >= len(controller_nodes): controller_nodes.append(create_controller(scn)) controller = gs.GetInputSystem().GetDevice( "openvr_controller_{0}".format(i)) if controller is not None and controller_nodes[i].GetTransform( ) is not None: controller_nodes[i].GetTransform().SetWorld( gs.Matrix4.TranslationMatrix( scn.GetCurrentCamera().GetTransform().GetPosition()) * controller.GetMatrix(gs.InputDevice.MatrixHead))
def update_camera_move(dt_sec, camera_handler, gui, cam, use_vr): controller0 = gs.GetInputSystem().GetDevice("openvr_controller_0") if not gui.WantCaptureMouse(): if use_vr is None or controller0 is None: camera_handler.update(cam, dt_sec.to_sec())
def update_camera_teleporter(scn, scene_simple_graphic, cam, use_vr, authorise_ground_node): controller0 = gs.GetInputSystem().GetDevice("openvr_controller_0") pos_start = None dir_teleporter = None teleporter_activate = False if use_vr is not None and controller0 is not None: if controller0.GetValue(gs.InputDevice.InputButton0) != 0 or controller0.GetValue(gs.InputDevice.InputButton1) != 0: pos_cam = cam.GetTransform().GetPosition() mat_controller = controller0.GetMatrix(gs.InputDevice.MatrixHead) dir_teleporter = mat_controller.GetZ() pos_start = mat_controller.GetTranslation() + pos_cam teleporter_activate = controller0.WasButtonPressed(gs.InputDevice.Button0) else: if plus.KeyDown(gs.InputDevice.KeyX) or plus.KeyDown(gs.InputDevice.KeyC): pos_start = cam.GetTransform().GetPosition() dir_teleporter = cam.GetTransform().GetWorld().GetZ() if pos_start is not None: if pos_start.y < 0: return # teleporter # project point on the ground cos_angle = dir_teleporter.Dot(gs.Vector3(dir_teleporter.x, 0, dir_teleporter.z).Normalized()) cos_angle = min(1.0, max(cos_angle, -1)) angle = math.acos(cos_angle) if dir_teleporter.y < 0: angle = -angle velocity = 5 d = ((velocity * cos_angle) / 9.81) * (velocity * math.sin(angle) + math.sqrt((velocity * math.sin(angle)) ** 2 + 2 * 9.81 * pos_start.y)) else: velocity = 5 min_d = ((velocity * 1) / 9.81) * (velocity * math.sin(0) + math.sqrt((velocity * math.sin(0)) ** 2 + 2 * 9.81 * pos_start.y)) max_d = 10 d = min_d + (1.0 - abs(cos_angle)) * max_d ground_pos = gs.Vector3(pos_start.x, 0, pos_start.z) + gs.Vector3(dir_teleporter.x, 0, dir_teleporter.z).Normalized() *d authorise_movement = True if authorise_ground_node is not None: authorise_ground_node.GetObject().GetGeometry().GetMaterial(0).SetFloat3("pos_touched", ground_pos.x, ground_pos.y, ground_pos.z) hit, trace = scn.GetPhysicSystem().Raycast(ground_pos + gs.Vector3(0, 0.5, 0), gs.Vector3(0, -1, 0), 4, 3) if not hit or trace.GetNode() != authorise_ground_node: authorise_movement = False strength_force = math.pow((math.sin(angle) + 1) / 2, 2) * 2 color = gs.Color(0, 1, 198/255) if authorise_movement else gs.Color(1, 18/255, 0) helper_2d.draw_spline(scene_simple_graphic, pos_start, pos_start + dir_teleporter * strength_force, ground_pos + gs.Vector3(0, strength_force, 0), ground_pos, color) if authorise_ground_node is None: helper_2d.draw_circle(scene_simple_graphic, gs.Matrix4.TranslationMatrix(ground_pos), 1, color) if authorise_movement and teleporter_activate: if use_vr: head_controller = gs.GetInputSystem().GetDevice("openvr_hmd") head_pos = head_controller.GetMatrix(gs.InputDevice.MatrixHead).GetTranslation() head_pos.y = 0 ground_pos = ground_pos - head_pos cam.GetTransform().SetWorld(gs.Matrix4.TranslationMatrix(ground_pos)) else: if authorise_ground_node is not None: authorise_ground_node.GetObject().GetGeometry().GetMaterial(0).SetFloat3("pos_touched", 99999, 99999, 99999)
def calibration(scn, openvr_frame_renderer, gui): global calibration_matrix, do_calibration, timer, calibration_fov, show_live_cam, draw_calibration_picture show_live_cam = gui.Checkbox("Show live cam", show_live_cam) temp_calibration = gui.Checkbox("Calibration", do_calibration) if temp_calibration: if not show_live_cam and temp_calibration != do_calibration: load_record(scn, openvr_frame_renderer) # draw alpha picture draw_calibration_picture = gui.Checkbox("Draw calibration picture", draw_calibration_picture) if draw_calibration_picture: gs.GetPlus().Image2D(0, 0, 1.0, "calibration.png", gs.Color(1, 1, 1, 0.5)) if gui.Button("Calibrate live from ground"): controller1 = gs.GetInputSystem().GetDevice("openvr_controller_1") if controller1 is not None: calibration_matrix = controller1.GetMatrix( gs.InputDevice.MatrixHead).InversedFast() delta = 0.01 pos_calibration = calibration_matrix.GetTranslation() if gui.Button("PosX -"): pos_calibration.x -= delta gui.SameLine() if gui.Button("PosX +"): pos_calibration.x += delta gui.SameLine() pos_calibration.x = gui.InputFloat("px", pos_calibration.x)[1] if gui.Button("PosY -"): pos_calibration.y -= delta gui.SameLine() if gui.Button("PosY +"): pos_calibration.y += delta gui.SameLine() pos_calibration.y = gui.InputFloat("py", pos_calibration.y)[1] if gui.Button("PosZ -"): pos_calibration.z -= delta gui.SameLine() if gui.Button("PosZ +"): pos_calibration.z += delta gui.SameLine() pos_calibration.z = gui.InputFloat("pz", pos_calibration.z)[1] # pos_calibration = gui.InputVector3("Pos", pos_calibration)[1] rot_calibration = calibration_matrix.GetRotation() if gui.Button("RotX -"): rot_calibration.x -= delta gui.SameLine() if gui.Button("RotX +"): rot_calibration.x += delta gui.SameLine() rot_calibration.x = gui.InputFloat( "rx", rot_calibration.x * 180.0 / 3.1415)[1] * 3.1415 / 180.0 if gui.Button("RotY -"): rot_calibration.y -= delta gui.SameLine() if gui.Button("RotY +"): rot_calibration.y += delta gui.SameLine() rot_calibration.y = gui.InputFloat( "ry", rot_calibration.y * 180.0 / 3.1415)[1] * 3.1415 / 180.0 if gui.Button("RotZ -"): rot_calibration.z -= delta gui.SameLine() if gui.Button("RotZ +"): rot_calibration.z += delta gui.SameLine() rot_calibration.z = gui.InputFloat( "rz", rot_calibration.z * 180.0 / 3.1415)[1] * 3.1415 / 180.0 calibration_matrix = gs.Matrix4.TransformationMatrix( pos_calibration, rot_calibration) changed, calibration_fov = gui.SliderFloat("FOV (deg)", calibration_fov, 1, 180) if changed: scn.GetCurrentCamera().GetCamera().SetZoomFactor( gs.FovToZoomFactor(calibration_fov * 3.1415 / 180.0)) if records is not None: timer = gui.SliderFloat("Timeline", timer, 0, max([float(i) for i in records.keys()]))[1] else: if temp_calibration != do_calibration: save_calibration() stop_play(scn, openvr_frame_renderer) do_calibration = temp_calibration
SCR_DISP_WIDTH = 320 * 2 SCR_DISP_HEIGHT = 200 * 2 SCR_SCALE_FACTOR = min(SCR_DISP_WIDTH / SCR_PHYSIC_WIDTH, SCR_DISP_HEIGHT / SCR_PHYSIC_HEIGHT) SCR_MARGIN_X = (SCR_DISP_WIDTH - (SCR_PHYSIC_WIDTH * SCR_SCALE_FACTOR)) / 2.0 gs.LoadPlugins(gs.get_default_plugins_path()) render.init(SCR_DISP_WIDTH, SCR_DISP_HEIGHT, "pkg.core") # provide access to the data folder gs.MountFileDriver(gs.StdFileDriver("assets/"), "@assets/") gameReset() player.initial_pox_z = (board.board_length * 0.45) player.reset() while not input.key_press(gs.InputDevice.KeyEscape): dt = clock.update() # 1.0 / 60.0 # update mouse gs.GetInputSystem().Update() # get the mouse device mouse_device = gs.GetInputSystem().GetDevice("mouse") gameMainLoop(mouse_device) render.flip()
def update(scn, openvr_frame_renderer): global button_pressed, selected_material if switch_object_textures is None or len(switch_object_textures) <= 0: return if selected_material is None: # load the selected material selected_material = plus.LoadMaterial("assets/selected.mat") controller0 = gs.GetInputSystem().GetDevice("openvr_controller_0") # restore material if selected["n"] is not None: geo = selected["n"].GetObject().GetGeometry() for m in range(geo.GetMaterialCount()): geo.SetMaterial(m, selected["m"][m]) selected["n"] = None selected["m"] = None pos_laser = None dir_laser = None click_on_switch = False if openvr_frame_renderer is not None and controller0 is not None: if controller0.GetValue(gs.InputDevice.InputButton2) > 0.2: mat_controller = controller0.GetMatrix(gs.InputDevice.MatrixHead) pos_cam = scn.GetCurrentCamera().GetTransform().GetPosition() pos_laser = mat_controller.GetTranslation() + pos_cam dir_laser = mat_controller.GetZ() if controller0.GetValue(gs.InputDevice.InputButton2) == 1.0: click_on_switch = True else: if plus.KeyDown(gs.InputDevice.KeySpace) or plus.KeyDown( gs.InputDevice.KeyW): pos_laser = scn.GetCurrentCamera().GetTransform().GetPosition() dir_laser = scn.GetCurrentCamera().GetTransform().GetWorld().GetZ() if plus.KeyDown(gs.InputDevice.KeyW): click_on_switch = True if pos_laser is not None: hit, trace = scn.GetPhysicSystem().Raycast(pos_laser, dir_laser, 1) if hit: # helper_2d.draw_line(scene_simple_graphic, pos_laser, trace.GetPosition(), # gs.Color(238 / 255, 235 / 255, 92 / 255)) # if not use_vr: # helper_2d.draw_cross(scene_simple_graphic, trace.GetPosition(), # gs.Color(238 / 255, 235 / 255, 92 / 255)) name = trace.GetNode().GetName() if name in switch_object_textures: selected_node = switch_object_textures[name]["node"] # if need to switch to selected material current_material = selected_node.GetObject().GetGeometry( ).GetMaterial(0) if current_material != selected_material: selected["n"] = selected_node selected["m"] = [] geo = selected_node.GetObject().GetGeometry() for m in range(geo.GetMaterialCount()): selected["m"].append(geo.GetMaterial(m)) geo.SetMaterial(m, selected_material) selected_material.SetTexture( "diffuse_map", current_material.GetTexture("diffuse_map")) # switch if the trigger is triggered if click_on_switch and not button_pressed: if len(selected["m"]) > 0: new_diffuse_tex = plus.GetRendererAsync().LoadTexture( switch_object_textures[name]["diffuse_map"][ switch_object_textures[name]["index"]]) switch_object_textures[name]["index"] += 1 if switch_object_textures[name]["index"] >= len( switch_object_textures[name]["diffuse_map"]): switch_object_textures[name]["index"] = 0 selected_material.SetTexture("diffuse_map", new_diffuse_tex) selected["m"][0].SetTexture("diffuse_map", new_diffuse_tex) # else: # helper_2d.draw_line(scene_simple_graphic, pos_laser, pos_laser + dir_laser * 10, # gs.Color(238 / 255, 235 / 255, 92 / 255)) # if not use_vr: # helper_2d.draw_cross(scene_simple_graphic, pos_laser + dir_laser * 0.2, # gs.Color(238 / 255, 235 / 255, 92 / 255), 0.01) if click_on_switch: if not button_pressed: button_pressed = True else: button_pressed = False
def check_switch_objects(scn, scene_simple_graphic, cam, use_vr): global button_pressed, selected_material if selected_material is None: # load the selected material selected_material = plus.LoadMaterial("assets/selected.mat") controller0 = gs.GetInputSystem().GetDevice("openvr_controller_0") # restore material if selected["n"] is not None: geo = selected["n"].GetObject().GetGeometry() for m in range(geo.GetMaterialCount()): geo.SetMaterial(m, selected["m"][m]) selected["n"] = None selected["m"] = None pos_laser = None dir_laser = None click_on_switch = False if use_vr is not None and controller0 is not None: if controller0.GetValue(gs.InputDevice.InputButton2) > 0.2: mat_controller = controller0.GetMatrix(gs.InputDevice.MatrixHead) pos_cam = cam.GetTransform().GetPosition() pos_laser = mat_controller.GetTranslation() + pos_cam dir_laser = mat_controller.GetZ() if controller0.GetValue(gs.InputDevice.InputButton2) == 1.0: click_on_switch = True else: if plus.KeyDown(gs.InputDevice.KeySpace) or plus.KeyDown( gs.InputDevice.KeyW): pos_laser = cam.GetTransform().GetPosition() dir_laser = cam.GetTransform().GetWorld().GetZ() if plus.KeyPress(gs.InputDevice.KeyW): click_on_switch = True if pos_laser is not None: hit, trace = scn.GetPhysicSystem().Raycast(pos_laser, dir_laser, 1) if hit: helper_2d.draw_line(scene_simple_graphic, pos_laser, trace.GetPosition(), gs.Color(238 / 255, 235 / 255, 92 / 255)) if not use_vr: helper_2d.draw_cross(scene_simple_graphic, trace.GetPosition(), gs.Color(238 / 255, 235 / 255, 92 / 255)) name = trace.GetNode().GetName() if "_switch_" in name: name = name[:-2] if name in switch_objects: selected_node = switch_objects[name]["nodes"][ switch_objects[name]["current_display"]] # if need to switch to selected material current_material = selected_node.GetObject().GetGeometry( ).GetMaterial(0) if current_material != selected_material: selected["n"] = selected_node selected["m"] = [] geo = selected_node.GetObject().GetGeometry() for m in range(geo.GetMaterialCount()): selected["m"].append(geo.GetMaterial(m)) geo.SetMaterial(m, selected_material) selected_material.SetTexture( "diffuse_map", current_material.GetTexture("diffuse_map")) # switch if the trigger is triggered if click_on_switch: if not button_pressed: button_pressed = True switch_objects[name]["nodes"][switch_objects[name][ "current_display"]].SetEnabled(False) switch_objects[name]["current_display"] += 1 if switch_objects[name]["current_display"] >= len( switch_objects[name]["nodes"]): switch_objects[name]["current_display"] = 0 switch_objects[name]["nodes"][switch_objects[name][ "current_display"]].SetEnabled(True) else: button_pressed = False else: helper_2d.draw_line(scene_simple_graphic, pos_laser, pos_laser + dir_laser * 10, gs.Color(238 / 255, 235 / 255, 92 / 255)) if not use_vr: helper_2d.draw_cross(scene_simple_graphic, pos_laser + dir_laser * 0.2, gs.Color(238 / 255, 235 / 255, 92 / 255), 0.01) return True return False
def update(scn, openvr_frame_renderer): global button_pressed if catalogue is None or len(catalogue) <= 0: return controller0 = gs.GetInputSystem().GetDevice("openvr_controller_0") pos_laser = None dir_laser = None click_on_switch = False if openvr_frame_renderer is not None and controller0 is not None: # if controller0.GetValue(gs.InputDevice.InputButton2) > 0.2: mat_controller = controller0.GetMatrix(gs.InputDevice.MatrixHead) pos_cam = scn.GetCurrentCamera().GetTransform().GetPosition() pos_laser = mat_controller.GetTranslation() + pos_cam dir_laser = mat_controller.GetZ() if controller0.GetValue(gs.InputDevice.InputButton2) == 1.0: click_on_switch = True else: # if plus.KeyDown(gs.InputDevice.KeySpace) or plus.KeyDown(gs.InputDevice.KeyW): pos_laser = scn.GetCurrentCamera().GetTransform().GetPosition() dir_laser = scn.GetCurrentCamera().GetTransform().GetWorld().GetZ() if plus.KeyDown(gs.InputDevice.KeyW): click_on_switch = True # draw card controller1 = gs.GetInputSystem().GetDevice("openvr_controller_1") if openvr_frame_renderer is not None and controller1 is not None: # draw the current cards mat_controller = gs.Matrix4.TranslationMatrix(scn.GetCurrentCamera( ).GetTransform().GetPosition()) * controller1.GetMatrix( gs.InputDevice.MatrixHead) mat_controller = mat_controller * gs.Matrix4.TranslationMatrix( (0, 0.0053, -0.049)) * gs.Matrix4.RotationMatrix( (-6.0 * 3.1415 / 180.0, 0, 0)) else: mat_controller = gs.Matrix4.TranslationMatrix( scn.GetCurrentCamera().GetTransform().GetWorld().GetZ() * 5) * scn.GetCurrentCamera().GetTransform().GetWorld() min_angle, max_angle = 0, 3.1415 for name_object, data_object in catalogue[current_room]["object"].items(): if "diffuse_gpu" in data_object: for id_diffuse, diffuse_gpu in enumerate( data_object["diffuse_gpu"]): angle = min_angle + (max_angle - min_angle) * ( id_diffuse / catalogue[current_room]["nb_texture"]) mat = mat_controller * gs.Matrix4.RotationMatrix( (-math.pi, 0, 0)) * gs.Matrix4.RotationMatrix( (0, angle, 0)) * gs.Matrix4.TranslationMatrix( (0, 0, radius_button)) helper_2d.draw_quad( scn.GetComponents("SceneOverlay")[0], mat, width_car, height_card, diffuse_gpu) # test collision p0 = scn.GetCurrentCamera().GetTransform().GetPosition() p1 = mat.GetTranslation() p0 = pos_laser p1 = pos_laser + dir_laser p_co = mat.GetTranslation() p_no = mat.GetZ() point_on_plane = helper_2d.intersect_line_plane( p0, p1, p_co, p_no) if point_on_plane is not None: inv_mat = mat.InversedFast() pos = mat.GetTranslation() axis = [ mat.GetX() * width_car / 2, mat.GetY(), mat.GetZ() * height_card / 2 ] poly_card = [(pos - axis[0] - axis[2]) * inv_mat, (pos + axis[0] - axis[2]) * inv_mat, (pos + axis[0] + axis[2]) * inv_mat, (pos - axis[0] + axis[2]) * inv_mat] point_on_plane = point_on_plane * inv_mat if helper_2d.point_in_poly_2d(point_on_plane, poly_card): print("collide on {}".format( data_object["diffuse_map"][id_diffuse])) # # controller0 = gs.GetInputSystem().GetDevice("openvr_controller_0") # # pos_laser = None # dir_laser = None # click_on_switch = False # # if openvr_frame_renderer is not None and controller0 is not None: # if controller0.GetValue(gs.InputDevice.InputButton2) > 0.2: # mat_controller = controller0.GetMatrix(gs.InputDevice.MatrixHead) # # pos_cam = scn.GetCurrentCamera().GetTransform().GetPosition() # pos_laser = mat_controller.GetTranslation() + pos_cam # dir_laser = mat_controller.GetZ() # # if controller0.GetValue(gs.InputDevice.InputButton2) == 1.0: # click_on_switch = True # else: # if plus.KeyDown(gs.InputDevice.KeySpace) or plus.KeyDown(gs.InputDevice.KeyW): # pos_laser = scn.GetCurrentCamera().GetTransform().GetPosition() # dir_laser = scn.GetCurrentCamera().GetTransform().GetWorld().GetZ() # # if plus.KeyDown(gs.InputDevice.KeyW): # click_on_switch = True # # if pos_laser is not None: # hit, trace = scn.GetPhysicSystem().Raycast(pos_laser, dir_laser, 1) # if hit: # # if need to switch to selected material # current_material = selected_node.GetObject().GetGeometry().GetMaterial(0) # if current_material != selected_material: # geo = selected_node.GetObject().GetGeometry() # for m in range(geo.GetMaterialCount()): # geo.SetMaterial(m, selected_material) # selected_material.SetTexture("diffuse_map", current_material.GetTexture("diffuse_map")) # # new_diffuse_tex = plus.GetRendererAsync().LoadTexture(catalogue[name]["diffuse_map"][catalogue[name]["index"]]) # # selected_material.SetTexture("diffuse_map", new_diffuse_tex) # selected["m"][0].SetTexture("diffuse_map", new_diffuse_tex)
# Basic initialisations and use of main devices # =========================================================== import gs # ------------ Display object and Output screen: renderer = gs.EglRenderer() renderer.Open(640, 480) # ------------ Check devices: print("Installed devices:") devices = gs.GetInputSystem().GetDevices() for device in devices: print("Id: " + str(device.GetId()) + " - Name : " + device.GetName()) # ------------ Get devices: keyboard_device = gs.GetInputSystem().GetDevice("keyboard") mouse_device = gs.GetInputSystem().GetDevice("mouse") # ------------ Main loop: while renderer.GetDefaultOutputWindow(): gs.GetInputSystem().Update() # --- Keyboard controls: