def update_cursor(self): source = obs.obs_get_source_by_name(self.source_name) settings = obs.obs_data_create() if source is not None: scene_source = obs.obs_frontend_get_current_scene() scene_width = obs.obs_source_get_width(source) scene_height = obs.obs_source_get_height(source) scene = obs.obs_scene_from_source(scene_source) scene_item = obs.obs_scene_find_source(scene, self.source_name) if scene_item: scale = obs.vec2() obs.obs_sceneitem_get_scale(scene_item, scale) scene_width, scene_height = apply_scale( scale.x, scale.y, scene_width, scene_height ) next_pos = obs.vec2() next_pos.x, next_pos.y = get_position() next_pos.x -= scene_width / 2 next_pos.y -= scene_height / 2 # set position to center of source where cursor is obs.obs_sceneitem_set_pos(scene_item, next_pos) obs.obs_data_release(settings) obs.obs_scene_release(scene) obs.obs_source_release(source)
def startCountClick(props, prop): global itemSource global xCoord global yCoord global Debug_Mode global jsonItemData global imagePath global imageName global widthCount global heightCount if (obs.obs_frontend_preview_program_mode_active()): sceneSource = obs.obs_frontend_get_current_preview_scene() else: sceneSource = obs.obs_frontend_get_current_scene() sceneWidth = obs.obs_source_get_width(sceneSource) sceneHeight = obs.obs_source_get_height(sceneSource) xWidth = math.ceil(sceneWidth / widthCount) yHeight = math.ceil(sceneHeight / heightCount) blankImage = np.zeros(shape=[yHeight, xWidth, 4], dtype=np.uint8) cv2.rectangle(blankImage, (0, 0), (xWidth, yHeight), (169, 169, 169, 255), 2) if (os.path.isfile(imagePath + imageName)): os.remove(imagePath + imageName) cv2.imwrite(imagePath + imageName, blankImage) if Debug_Mode: print("startCount") print(imagePath + imageName) gridWidth = 0 gridHeight = 0 scene = obs.obs_scene_from_source(sceneSource) itemData = obs.obs_data_create_from_json(jsonItemData) itemSource = obs.obs_load_source(itemData) vec2 = obs.vec2() position = 0 if itemSource != None: item = obs.obs_scene_find_source(scene, "OBSWindowGridItem") while item != None: obs.obs_sceneitem_remove(item) item = obs.obs_scene_find_source(scene, "OBSWindowGridItem") vec2.y = 0 while gridHeight < sceneHeight: gridWidth = 0 vec2.x = 0 while gridWidth < sceneWidth: newItem = obs.obs_scene_add(scene, itemSource) obs.obs_sceneitem_set_pos(newItem, vec2) obs.obs_sceneitem_set_locked(newItem, True) obs.obs_sceneitem_set_order_position(newItem, position) position += 1 vec2.x += xWidth gridWidth += xWidth vec2.y += yHeight gridHeight += yHeight
def add_random_text_source(scene): r = " random text # " + str(randint(0, 10)) with data_ar() as settings: S.obs_data_set_string(settings, "text", f"random text value {r}") with source_create_ar("text_ft2_source", f"random text{r}", settings) as source: pos = S.vec2() pos.x = randint(0, 1920) pos.y = randint(0, 1080) scene_item = S.obs_scene_add(scene, source) S.obs_sceneitem_set_pos(scene_item, pos)
def setSourcePosByName(self, sourceName, x=None, y=None): """ Set the position of the given source by name. If either coordinate is None, that coordinate will not be modified. """ if x == y == None: return for item in self.iterSceneItemsByName(sourceName): pos = obs.vec2() obs.obs_sceneitem_get_pos(item, pos) if x is not None: pos.x = x if y is not None: pos.y = y obs.obs_sceneitem_set_pos(item, pos)
def add_text_to_scene(scene, text_element): """Places text source into some location within scene returns width and height to align next scene items later """ with data_ar() as settings: set_text_source_settings(settings, text_element.text) with source_create_ar("text_ft2_source", text_element.name, settings) as source: pos = obs.vec2() pos.x = text_element.x pos.y = text_element.y scene_item = obs.obs_scene_add(scene, source) obs.obs_sceneitem_set_pos(scene_item, pos) height = obs.obs_source_get_height(source) width = obs.obs_source_get_width(source) return width, height
def move_text_source(self): current_scene = obs.obs_frontend_get_current_scene() source = obs.obs_get_source_by_name("test_py") scene = obs.obs_scene_from_source(current_scene) scene_item = obs.obs_scene_find_source(scene, "test_py") if scene_item: dx, dy = 10, 10 print("old values", self.location.x) obs.obs_sceneitem_get_pos( scene_item, self.location ) # update to last position if its changed from OBS self.location.x += dx self.location.y += dy print("new values", self.location.x) obs.obs_sceneitem_set_pos(scene_item, self.location) obs.obs_scene_release(scene) obs.obs_source_release(source)
def update_position(): global source_name global counter source = obs.obs_frontend_get_current_scene() if source is not None: scene_object = obs.obs_scene_from_source(source) scene_item = obs.obs_scene_find_source(scene_object, source_name) pos = obs.vec2() obs.obs_sceneitem_get_pos(scene_item, pos) next_pos = obs.vec2() next_pos.x = pos.x y_adjust = math.sin(math.radians(counter)) next_pos.y = pos.y + y_adjust / 4 counter += 0.5 if counter == 360: counter = 0 obs.obs_sceneitem_set_pos(scene_item, next_pos) obs.obs_source_release(source)
def boost_bar(boost): boost_bar_pos = [446, 90] boost_bar_size = [210, 20] perc_bar = boost[0] sceneItem = get_scene_item('Blue-Boost-0') scale2_vec = obs.vec2() obs.vec2_set(scale2_vec, perc_bar[0], 1) obs.obs_sceneitem_set_scale(sceneItem, scale2_vec) pos_vec = obs.vec2() obs.vec2_set(pos_vec, boost_bar_pos[0] + boost_bar_size[0] * (1-perc_bar[0]), boost_bar_pos[1]) obs.obs_sceneitem_set_pos(sceneItem, pos_vec) # obs.obs_sceneitem_release(sceneItem) sceneItem = get_scene_item('Orange-Boost-0') scale2_vec = obs.vec2() obs.vec2_set(scale2_vec, perc_bar[1], 1) obs.obs_sceneitem_set_scale(sceneItem, scale2_vec) pos_vec = obs.vec2() obs.vec2_set(pos_vec, 1920 - boost_bar_size[0] - boost_bar_pos[0], boost_bar_pos[1]) obs.obs_sceneitem_set_pos(sceneItem, pos_vec)
def set_text_pos(): pos = [119, 14] hardcoded_width = 386 scale = [1.5, 1.5] sceneItem = get_scene_item('Blue-Name') pos_vec = obs.vec2() obs.vec2_set(pos_vec, pos[0], pos[1]) obs.obs_sceneitem_set_pos(sceneItem, pos_vec) obs.obs_sceneitem_get_scale(sceneItem, pos_vec) scale2_vec = obs.vec2() obs.vec2_set(scale2_vec, scale[0], scale[1]) obs.obs_sceneitem_set_scale(sceneItem, scale2_vec) # obs.obs_sceneitem_release(sceneItem) sceneItem = get_scene_item('Orange-Name') pos_vec = obs.vec2() obs.vec2_set(pos_vec, 1920 - pos[0] - hardcoded_width * scale[0], pos[1]) obs.obs_sceneitem_set_pos(sceneItem, pos_vec) scale2_vec = obs.vec2() obs.vec2_set(scale2_vec, scale[0], scale[1]) obs.obs_sceneitem_set_scale(sceneItem, scale2_vec)
def set_text_pos(): pos = [290+100, 14] hardcoded_width = 250 hardcoded_height = 26 scale = [1.5, 1.5] #math should make it mirrored but doesnt, gotta add a bit more so looks mirrored bit_to_right = 5 sceneItem = get_scene_item('Blue-Name') pos_vec = obs.vec2() obs.vec2_set(pos_vec, pos[0], pos[1]) obs.obs_sceneitem_set_pos(sceneItem, pos_vec) obs.obs_sceneitem_get_scale(sceneItem, pos_vec) scale2_vec = obs.vec2() obs.vec2_set(scale2_vec, scale[0], scale[1]) obs.obs_sceneitem_set_scale(sceneItem, scale2_vec) # obs.obs_sceneitem_release(sceneItem) sceneItem = get_scene_item('Orange-Name') pos_vec = obs.vec2() obs.vec2_set(pos_vec, 1920-pos[0]-hardcoded_width*scale[0] + bit_to_right, pos[1]) obs.obs_sceneitem_set_pos(sceneItem, pos_vec) scale2_vec = obs.vec2() obs.vec2_set(scale2_vec, scale[0], scale[1]) obs.obs_sceneitem_set_scale(sceneItem, scale2_vec) # obs.obs_sceneitem_release(sceneItem) sceneItem = get_scene_item('Blue-Dev-Name') pos_vec = obs.vec2() obs.vec2_set(pos_vec, pos[0], pos[1]+hardcoded_height*scale[1]) obs.obs_sceneitem_set_pos(sceneItem, pos_vec) obs.obs_sceneitem_get_scale(sceneItem, pos_vec) scale2_vec = obs.vec2() obs.vec2_set(scale2_vec, scale[0], scale[1]) obs.obs_sceneitem_set_scale(sceneItem, scale2_vec) # obs.obs_sceneitem_release(sceneItem) sceneItem = get_scene_item('Orange-Dev-Name') pos_vec = obs.vec2() obs.vec2_set(pos_vec, 1920-pos[0]-hardcoded_width*scale[0] + bit_to_right, pos[1]+hardcoded_height*scale[1]) obs.obs_sceneitem_set_pos(sceneItem, pos_vec) scale2_vec = obs.vec2() obs.vec2_set(scale2_vec, scale[0], scale[1]) obs.obs_sceneitem_set_scale(sceneItem, scale2_vec)
def auto_setup(props, prop): # Todo: add BO3 and BO5 global game_item global social_item global overlay_item global bar_0_item global blue_cheer_item global orange_cheer_item global bar_1_item global blue_name_item global orange_name_item global blue_dev_name_item global orange_dev_name_item global blue_boost_item global orange_boost_item global boost_0_item global boost_1_item global goal_item global game_source global social_source global overlay_source global bar_0_source global blue_cheer_source global orange_cheer_source global bar_1_source global blue_name_source global orange_name_source global blue_boost_source global orange_boost_source global boost_0_source global boost_1_source global goal_source if not check_for_scene('RLBot - AutoLeague'): main_scene = obs.obs_scene_create('RLBot - AutoLeague') # Game Capture temp_settings = get_settings('Game Capture') game_source = obs.obs_source_create('game_capture', 'Game', temp_settings, None) game_item = obs.obs_scene_add(main_scene, game_source) obs.obs_data_release(temp_settings) obs.obs_source_release(game_source) # obs.obs_sceneitem_release(game_item) # Social temp_settings = get_settings('Social') temp_path = os.path.join(files_path, 'social.png') obs.obs_data_set_string(temp_settings, 'file', temp_path) social_source = obs.obs_source_create('image_source', 'Social', temp_settings, None) social_item = obs.obs_scene_add(main_scene, social_source) obs.obs_data_release(temp_settings) obs.obs_source_release(social_source) # obs.obs_sceneitem_release(social_item) # RLBot Overlay temp_settings = get_settings('RLBot Overlay') temp_path = os.path.join(files_path, 'overlay.png') obs.obs_data_set_string(temp_settings, 'file', temp_path) overlay_source = obs.obs_source_create('image_source', 'Overlay', temp_settings, None) overlay_item = obs.obs_scene_add(main_scene, overlay_source) obs.obs_data_release(temp_settings) obs.obs_source_release(overlay_source) # obs.obs_sceneitem_release(overlay_item) # Blue-Name temp_settings = get_settings('Blue Team Name') blue_name_source = obs.obs_source_create('text_gdiplus', 'Blue-Name', temp_settings, None) blue_name_item = obs.obs_scene_add(main_scene, blue_name_source) obs.obs_data_release(temp_settings) obs.obs_source_release(blue_name_source) # obs.obs_sceneitem_release(blue_name_item) # Orange-Name temp_settings = get_settings('Orange Team Name') orange_name_source = obs.obs_source_create('text_gdiplus', 'Orange-Name', temp_settings, None) orange_name_item = obs.obs_scene_add(main_scene, orange_name_source) obs.obs_data_release(temp_settings) obs.obs_source_release(orange_name_source) # obs.obs_sceneitem_release(orange_name_item) # Blue-Dev-Name temp_settings = get_settings('Blue Dev Name') blue_dev_name_source = obs.obs_source_create('text_gdiplus', 'Blue-Dev-Name', temp_settings, None) blue_dev_name_item = obs.obs_scene_add(main_scene, blue_dev_name_source) obs.obs_data_release(temp_settings) obs.obs_source_release(blue_dev_name_source) # obs.obs_sceneitem_release(blue_name_item) # Orange-Dev-Name temp_settings = get_settings('Orange Dev Name') orange_dev_name_source = obs.obs_source_create('text_gdiplus', 'Orange-Dev-Name', temp_settings, None) orange_dev_name_item = obs.obs_scene_add(main_scene, orange_dev_name_source) obs.obs_data_release(temp_settings) obs.obs_source_release(orange_dev_name_source) # obs.obs_sceneitem_release(orange_name_item) logo_pos = [300, 10] logo_scale = 0.25 # Logo-0 temp_settings = get_settings('Logo') temp_path = os.path.join(files_path, 'logo.png') obs.obs_data_set_string(temp_settings, 'file', temp_path) logo_0_source = obs.obs_source_create('image_source', 'Logo-0', temp_settings, None) logo_0_item = obs.obs_scene_add(main_scene, logo_0_source) obs.obs_data_release(temp_settings) obs.obs_source_release(logo_0_source) vec = obs.vec2() obs.vec2_set(vec, logo_pos[0], logo_pos[1]) obs.obs_sceneitem_set_pos(logo_0_item, vec) obs.vec2_set(vec, logo_scale, logo_scale) obs.obs_sceneitem_set_scale(logo_0_item, vec) # obs.obs_sceneitem_release(social_item) # Logo-1 temp_settings = get_settings('Logo') temp_path = os.path.join(files_path, 'logo.png') obs.obs_data_set_string(temp_settings, 'file', temp_path) logo_0_source = obs.obs_source_create('image_source', 'Logo-1', temp_settings, None) logo_0_item = obs.obs_scene_add(main_scene, logo_0_source) obs.obs_data_release(temp_settings) obs.obs_source_release(logo_0_source) vec = obs.vec2() obs.vec2_set(vec, 1920-100-logo_pos[0], logo_pos[1]) obs.obs_sceneitem_set_pos(logo_0_item, vec) obs.vec2_set(vec, logo_scale, logo_scale) obs.obs_sceneitem_set_scale(logo_0_item, vec) # obs.obs_sceneitem_release(social_item) # Goal temp_settings = get_settings('Goal') temp_path = os.path.join(files_path, 'goal.mov') obs.obs_data_set_string(temp_settings, 'local_file', temp_path) goal_source = obs.obs_source_create('ffmpeg_source', 'Goal', temp_settings, None) goal_item = obs.obs_scene_add(main_scene, goal_source) obs.obs_data_release(temp_settings) obs.obs_source_release(goal_source) # obs.obs_sceneitem_release(goal_item) obs.obs_scene_release(main_scene) set_text_pos() do_reset_bar() else: print('Scene already exists, please delete or rename RLBot scene before continuing')
def adjustCameraTick(): global source_name global source_pos global UpdatesPerSecond global scene_item # Do not control any aspect of the source if no animation is currently playing or if the server is not connected. if (not Source.processingAnimation) or ( not Server.run) or scene_item is None: return #scene_item = findSceneItem(source_name) # Only make adjustments if our server is currently running. #print("adjustCameraTick::scene_item: %s" % (scene_item)) posV = obs.vec2() scaleV = obs.vec2() obs.obs_sceneitem_get_pos(scene_item, posV) obs.obs_sceneitem_get_scale(scene_item, scaleV) width, height = calculateSize(scene_item, Source.scale.x, Source.scale.y) Source.pos = posV Source.size.x = width Source.size.y = height if Source.pos.x != Source.targetPos.x: fractionX = (float(Source.forceX) / float(UpdatesPerSecond)) + Source.posRemainder.x integerX = int(math.floor(fractionX)) Source.posRemainder.x = fractionX - integerX Source.pos.x += integerX if (integerX > 0 and Source.pos.x > Source.targetPos.x) or ( integerX < 0 and Source.pos.x < Source.targetPos.x): Source.pos.x = Source.targetPos.x if Source.pos.y != Source.targetPos.y: fractionY = (Source.forceY / UpdatesPerSecond) + Source.posRemainder.y integerY = int(math.floor(fractionY)) Source.posRemainder.y = fractionY - integerY Source.pos.y += integerY if (integerY > 0 and Source.pos.y > Source.targetPos.y) or ( integerY < 0 and Source.pos.y < Source.targetPos.y): Source.pos.y = Source.targetPos.y if Source.scale.x != Source.targetScale.x: fractionX = (float(Source.forceW) / float(UpdatesPerSecond)) Source.scale.x += fractionX if (fractionX > 0 and Source.scale.x > Source.targetScale.x) or ( fractionX < 0 and Source.scale.x < Source.targetScale.x): Source.scale.x = Source.targetScale.x if Source.scale.y != Source.targetScale.y: fractionY = (float(Source.forceH) / float(UpdatesPerSecond)) Source.scale.y += fractionY if (fractionY > 0 and Source.scale.y > Source.targetScale.y) or ( fractionY < 0 and Source.scale.y < Source.targetScale.y): Source.scale.y = Source.targetScale.y if Source.pos.x == Source.targetPos.x and Source.pos.y == Source.targetPos.y and Source.scale.x == Source.targetScale.x and Source.scale.y == Source.targetScale.y: Source.processingAnimation = False # Update the position and size of the source based on speed/ obs.obs_sceneitem_set_pos(scene_item, Source.pos) obs.obs_sceneitem_set_scale(scene_item, Source.scale)
def process_items(): global setting_offsetX global setting_offsetY global setting_offsetXMod global setting_offsetYMod global cached_items global dimensions if (cached_items == None): return for key, objects in cached_items.items(): item = objects["item"] source = objects["source"] modifiers = objects["modifiers"] myWin = objects["win32gui"] #sourceData = source.get_properties() #print("My id: %s" % sourceData.id) try: rect = win.GetWindowRect(myWin) x = rect[0] + setting_offsetX y = rect[1] + setting_offsetY w = rect[2] - x h = rect[3] - y if ("offset+" in modifiers or "offset" in modifiers): x += setting_offsetXMod y += setting_offsetYMod if ("offset-" in modifiers): x -= setting_offsetXMod y -= setting_offsetYMod if ("offsetx+" in modifiers or "offsetx" in modifiers): x += setting_offsetXMod if ("offsetx-" in modifiers): x -= setting_offsetXMod if ("offsety+" in modifiers or "offsety" in modifiers): y += setting_offsetYMod if ("offsety-" in modifiers): y -= setting_offsetYMod if ("snap" in modifiers): if (x < 0): x = 0 elif (x + w > dimensions.base_width): x = dimensions.base_width - w if (y < 0): y = 0 elif (y + h > dimensions.base_height): y = dimensions.base_height - h if ("snapx" in modifiers): if (x < 0): x = 0 elif (x + w > dimensions.base_width): x = dimensions.base_width - w if ("snapy" in modifiers): if (y < 0): y = 0 elif (y + h > dimensions.base_height): y = dimensions.base_height - h if ("loop" in modifiers): if (x < (0 - w / 2)): x += dimensions.base_width elif (x > (dimensions.base_width - w / 2)): x -= dimensions.base_width if (y < (0 - h / 2)): y += dimensions.base_height elif (y > (dimensions.base_height - h / 2)): y -= dimensions.base_height if ("loopx" in modifiers): if (x < (0 - w / 2)): x += dimensions.base_width elif (x > (dimensions.base_width - w / 2)): x -= dimensions.base_width if ("loopy" in modifiers): if (y < (0 - h / 2)): y += dimensions.base_height elif (y > (dimensions.base_height - h / 2)): y -= dimensions.base_height #print("\tLocation: (%d, %d)" % (x, y)) #print("\t Size: (%d, %d)" % (w, h)) # Move scene? pos_win = obs.vec2() obs.vec2_set(pos_win, x, y) obs.obs_sceneitem_set_pos(item, pos_win) except: print("Failed to track window: %s" % windowTitle) pass
def script_tick(tick): global globSettings global animationInfo global animationRunning global app global currentScene if animationRunning: animationInfo["animTime"] += tick animationInfo["animTime"] = min(animationInfo["animTime"], animationInfo["stopTime"]) scaleFactor = easeInOutQuad( animationInfo["animTime"] / animationInfo["stopTime"], 0, 1, 1) animScene = animationInfo["animScene"] initial = animationInfo["initial"] destination = animationInfo["destination"] result = [] sceneObject = obs.obs_scene_from_source(animScene) if obs.obs_source_get_name( animScene) in obs.obs_frontend_get_scene_names(): items = obs.obs_scene_enum_items(sceneObject) for i in range(len(initial)): pos = obs.vec2() pos.x = scaleFactor * (destination[i]["pos"][0] - initial[i] ["pos"][0]) + initial[i]["pos"][0] pos.y = scaleFactor * (destination[i]["pos"][1] - initial[i] ["pos"][1]) + initial[i]["pos"][1] rot = scaleFactor * (destination[i]["rot"] - initial[i]["rot"]) + initial[i]["rot"] scale = obs.vec2() scale.x = scaleFactor * ( destination[i]["scale"][0] - initial[i]["scale"][0]) + initial[i]["scale"][0] scale.y = scaleFactor * ( destination[i]["scale"][1] - initial[i]["scale"][1]) + initial[i]["scale"][1] alignment = destination[i]["alignment"] bounds = obs.vec2() bounds.x = scaleFactor * ( destination[i]["bounds"][0] - initial[i]["bounds"][0]) + initial[i]["bounds"][0] bounds.y = scaleFactor * ( destination[i]["bounds"][1] - initial[i]["bounds"][1]) + initial[i]["bounds"][1] boundsType = destination[i]["boundsType"] boundsAlignment = destination[i]["boundsAlignment"] crop = obs.obs_sceneitem_crop() crop.left = math.floor( scaleFactor * (destination[i]["crop"][0] - initial[i]["crop"][0]) + initial[i]["crop"][0]) crop.right = math.floor( scaleFactor * (destination[i]["crop"][1] - initial[i]["crop"][1]) + initial[i]["crop"][1]) crop.top = math.floor( scaleFactor * (destination[i]["crop"][2] - initial[i]["crop"][2]) + initial[i]["crop"][2]) crop.bottom = math.floor( scaleFactor * (destination[i]["crop"][3] - initial[i]["crop"][3]) + initial[i]["crop"][3]) obs.obs_sceneitem_set_pos(items[i], pos) obs.obs_sceneitem_set_rot(items[i], rot) obs.obs_sceneitem_set_scale(items[i], scale) obs.obs_sceneitem_set_alignment(items[i], alignment) obs.obs_sceneitem_set_bounds(items[i], bounds) obs.obs_sceneitem_set_bounds_type(items[i], boundsType) obs.obs_sceneitem_set_bounds_alignment(items[i], boundsAlignment) obs.obs_sceneitem_set_crop(items[i], crop) obs.sceneitem_list_release(items) #obs.obs_scene_release(sceneObject) if animationInfo["animTime"] == animationInfo["stopTime"]: obs.obs_source_release(animScene) animationInfo["animScene"] = None animationRunning = False
def tremor_effect(self): flag = next(self.position_swap) if flag: self.update_text(self.scripted_text) current_scene = obs.obs_frontend_get_current_scene() with source_ar(self.source_name) as source, scene_ar( current_scene) as scene: scene_item = obs.obs_scene_find_source(scene, self.source_name) pos = obs.vec2() self.location = pos obs.obs_sceneitem_get_pos( scene_item, self.location ) # update to last position if its changed from OBS if not self.last_jump_x == 0: if self.last_jump_x < 0: # minus minus self.location.x -= self.last_jump_x if self.last_jump_x > 0: self.location.x -= self.last_jump_x if not self.last_jump_y == 0: if self.last_jump_y < 0: self.location.y -= self.last_jump_y if self.last_jump_y > 0: self.location.y -= self.last_jump_y if scene_item: obs.obs_sceneitem_set_pos(scene_item, self.location) else: self.update_text(self.scripted_text) current_scene = obs.obs_frontend_get_current_scene() with source_ar(self.source_name) as source, scene_ar( current_scene) as scene: scene_item = obs.obs_scene_find_source(scene, self.source_name) pos = obs.vec2() self.location = pos obs.obs_sceneitem_get_pos( scene_item, self.location ) # update to last position if its changed from OBS if scene_item: # finish early , and set to default if self.duration // self.refresh_rate <= 3: self.duration = 0 obs.obs_sceneitem_set_pos(scene_item, self.location) else: next_pos = obs.vec2() withoutzero = list(range(-101, 0)) + list(range( 1, 101)) self.last_jump_x = choice(withoutzero) self.last_jump_y = choice(withoutzero) dx, dy = self.last_jump_x, self.last_jump_y next_pos.x, next_pos.y = ( self.location.x + dx, self.location.y + dy, ) obs.obs_sceneitem_set_pos(scene_item, next_pos)
def _obs_sceneitem_set_pos(self, scene_name, source_name, pos): with self._sceneitem_by_name(scene_name, source_name) as si: p = _obs.vec2() p.x, p.y = pos _obs.obs_sceneitem_set_pos(si, p)
def script_tick(tick): if scriptSettings['anim']['animating']: scriptSettings['anim']['time'] += tick scriptSettings['anim']['time'] = min(scriptSettings['anim']['time'], scriptSettings['anim']['length']) initial = scriptSettings['anim']['src'] destination = scriptSettings['anim']['dest'] tScale = easeInOutQuad( scriptSettings['anim']['time'] / scriptSettings['anim']['length'], 0, 1, 1) scene = obs.obs_frontend_get_current_scene() sceneObject = obs.obs_scene_from_source(scene) tweenItems = scriptSettings['anim']['tweener']['tweenItems'] sceneItems = obs.obs_scene_enum_items(sceneObject) for sItem in sceneItems: sceneItem = obs.obs_sceneitem_get_source(sItem) sName = obs.obs_source_get_name(sceneItem) for tItem in tweenItems: if sName == tItem['name']: pos = obs.vec2() pos.x = tScale * ( destination[sName]["pos"][0] - initial[sName]["pos"][0]) + initial[sName]["pos"][0] pos.y = tScale * ( destination[sName]["pos"][1] - initial[sName]["pos"][1]) + initial[sName]["pos"][1] rot = tScale * (destination[sName]["rot"] - initial[sName] ["rot"]) + initial[sName]["rot"] scale = obs.vec2() scale.x = tScale * (destination[sName]["scale"][0] - initial[sName]["scale"][0] ) + initial[sName]["scale"][0] scale.y = tScale * (destination[sName]["scale"][1] - initial[sName]["scale"][1] ) + initial[sName]["scale"][1] alignment = destination[sName]["alignment"] bounds = obs.vec2() bounds.x = tScale * (destination[sName]["bounds"][0] - initial[sName]["bounds"][0] ) + initial[sName]["bounds"][0] bounds.y = tScale * (destination[sName]["bounds"][1] - initial[sName]["bounds"][1] ) + initial[sName]["bounds"][1] boundsType = destination[sName]["boundsType"] boundsAlignment = destination[sName]["boundsAlignment"] crop = obs.obs_sceneitem_crop() crop.left = math.floor(tScale * (destination[sName]["crop"][0] - initial[sName]["crop"][0]) + initial[sName]["crop"][0]) crop.right = math.floor(tScale * (destination[sName]["crop"][1] - initial[sName]["crop"][1]) + initial[sName]["crop"][1]) crop.top = math.floor(tScale * (destination[sName]["crop"][2] - initial[sName]["crop"][2]) + initial[sName]["crop"][2]) crop.bottom = math.floor(tScale * (destination[sName]["crop"][3] - initial[sName]["crop"][3]) + initial[sName]["crop"][3]) obs.obs_sceneitem_set_pos(sItem, pos) obs.obs_sceneitem_set_rot(sItem, rot) obs.obs_sceneitem_set_scale(sItem, scale) obs.obs_sceneitem_set_alignment(sItem, alignment) obs.obs_sceneitem_set_bounds(sItem, bounds) obs.obs_sceneitem_set_bounds_type(sItem, boundsType) obs.obs_sceneitem_set_bounds_alignment( sItem, boundsAlignment) obs.obs_sceneitem_set_crop(sItem, crop) if scriptSettings['anim']['time'] >= scriptSettings['anim']['length']: scriptSettings['anim']['src'] = None scriptSettings['anim']['dest'] = None scriptSettings['anim']['time'] = math.inf scriptSettings['anim']['length'] = 10000 scriptSettings['anim']['tweener'] = None scriptSettings['anim']['animating'] = False