Skip to content

Commit 73561e1

Browse files
committed
added spotlight
1 parent ad8ca1f commit 73561e1

File tree

1 file changed

+58
-3
lines changed

1 file changed

+58
-3
lines changed

mouse_skin_obs.py

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import obspython as obs
22
from mouse import get_position # python -m pip install mouse
33

4-
__version__ = "0.2.1"
4+
__version__ = "0.3.0-alpha"
55
REFRESH_RATE = 15
66
FLAG = True
77

@@ -16,8 +16,13 @@ class CursorAsSource:
1616
def __init__(self, source_name=None):
1717
self.source_name = source_name
1818
self.lock = True
19+
self.update_xy = False
20+
self.update_gs = False # green screen
21+
self.update_cr = False
1922

2023
def update_cursor(self):
24+
""" in script settings check update cursor"""
25+
2126
source = obs.obs_get_source_by_name(self.source_name)
2227
settings = obs.obs_data_create()
2328
if source is not None:
@@ -43,14 +48,58 @@ def update_cursor(self):
4348
obs.obs_scene_release(scene)
4449
obs.obs_source_release(source)
4550

51+
def update_green(self):
52+
"""
53+
create new scene with name:__spotlight__
54+
add color source , add opacity(color correction) to that source
55+
add green circle
56+
add that scene as source to ur current scene
57+
apply chromakey filter to that source
58+
in script settings check update green
59+
"""
60+
source = obs.obs_get_source_by_name(self.source_name)
61+
settings = obs.obs_data_create()
62+
if source is not None:
63+
scene_width = obs.obs_source_get_width(source)
64+
scene_height = obs.obs_source_get_height(source)
65+
# get all scenes
66+
scenes = obs.obs_frontend_get_scenes()
67+
for sc in scenes:
68+
# select the one with chromakey cursor(green)
69+
name = obs.obs_source_get_name(sc)
70+
if name == "__spotlight__":
71+
# assign it
72+
_item = sc
73+
else:
74+
obs.obs_source_release(sc)
75+
76+
scene = obs.obs_scene_from_source(_item)
77+
scene_item = obs.obs_scene_find_source(scene, self.source_name)
78+
if scene_item:
79+
scale = obs.vec2()
80+
obs.obs_sceneitem_get_scale(scene_item, scale)
81+
scene_width, scene_height = apply_scale(
82+
scale.x, scale.y, scene_width, scene_height
83+
)
84+
next_pos = obs.vec2()
85+
next_pos.x, next_pos.y = get_position()
86+
next_pos.x -= scene_width / 2
87+
next_pos.y -= scene_height / 2
88+
# set position to center of source where cursor is
89+
obs.obs_sceneitem_set_pos(scene_item, next_pos)
90+
91+
obs.obs_data_release(settings)
92+
obs.obs_scene_release(scene)
93+
obs.obs_source_release(source)
94+
4695
def update_crop(self):
4796
"""
4897
Create 2 display captures.
4998
Create crop filter with this name: cropXY.
5099
Check relative.
51100
Set Width and Height to relatively small numbers e.g : 64x64 .
52101
Image mask blend + color correction might be an option too.
53-
Run script,select this source as cursor source , check Update crop, click start.
102+
Run script,select this source as cursor source , check Update crop and updated cursor, click start.
54103
"""
55104
source = obs.obs_get_source_by_name(self.source_name)
56105
crop = obs.obs_source_get_filter_by_name(source, "cropXY")
@@ -76,7 +125,9 @@ def ticker(self):
76125
if self.update_xy:
77126
self.update_crop()
78127
self.update_cursor()
79-
else:
128+
if self.update_gs:
129+
self.update_green()
130+
if self.update_cr:
80131
self.update_cursor()
81132

82133
if not self.lock:
@@ -112,6 +163,8 @@ def script_defaults(settings):
112163
def script_update(settings):
113164
global REFRESH_RATE
114165
py_cursor.update_xy = obs.obs_data_get_bool(settings, "bool_yn")
166+
py_cursor.update_xy = obs.obs_data_get_bool(settings, "bool_yn_cursor")
167+
py_cursor.update_gs = obs.obs_data_get_bool(settings, "bool_yn_green")
115168
py_cursor.source_name = obs.obs_data_get_string(settings, "source")
116169
REFRESH_RATE = obs.obs_data_get_int(settings, "refresh_rate")
117170

@@ -138,4 +191,6 @@ def script_properties(): # ui
138191
obs.obs_properties_add_button(props, "button", "Stop", stop_pressed)
139192
obs.obs_properties_add_button(props, "button2", "Start", start_pressed)
140193
obs.obs_properties_add_bool(props, "bool_yn", "Update crop")
194+
obs.obs_properties_add_bool(props, "bool_yn_green", "Update green circle")
195+
obs.obs_properties_add_bool(props, "bool_yn_cursor", "Update cursro ")
141196
return props

0 commit comments

Comments
 (0)