From 33fee44e63fea76f723b81098375b015c83f8c2c Mon Sep 17 00:00:00 2001 From: Brosef Date: Thu, 4 Jun 2026 03:40:05 +0100 Subject: [PATCH] Started keeping track of masks for #2 --- camera.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/camera.py b/camera.py index 21b98c3..e517af5 100644 --- a/camera.py +++ b/camera.py @@ -12,6 +12,15 @@ from watchdog.observers import Observer from pythonosc import udp_client import watchdog.events +_ADDR_TO_MASK = { + '/usercamera/ShowUIInCamera': 'UI', + '/usercamera/LocalPlayer': 'LOCAL_PLAYER', + '/usercamera/RemotePlayer': 'REMOTE_PLAYER', + '/usercamera/Environment': 'ENVIRONMENT', +} + +_MASK_TO_ADDR = {value: key for key, value in _ADDR_TO_MASK.items()} + class NewPictureHandler(watchdog.events.FileSystemEventHandler): """ Watches for new pictures in the VRChat camera folder. @@ -88,8 +97,15 @@ class Camera: self._newPictureObserver = createNewPictureObserver(self._newPicture) self._multiPictureOngoing = False self._onEnabledCallback = onCameraEnabled + self._masks = {'UI': False} dispatcher.map('/usercamera/Mode', self._onModeChange) + # Map all mask addresses to self._onMaskChange + # and populate any missing mask IDs in self._masks with True. + for address, maskID in _ADDR_TO_MASK.items(): + dispatcher.map(address, self._onMaskChange) + if maskID not in self._masks: + self._masks.update({maskID: True}) def close(self): """ @@ -133,7 +149,20 @@ class Camera: if enabledFlag: self._onCameraEnabled() + def _onMaskChange(self, address: str, value: bool): + """ + Gets called when any mask is changed. + """ + + mask = _ADDR_TO_MASK[address] + self._masks[mask] = value + def _onCameraEnabled(self): + # Ensure the VRChat camera's masks match our own + for maskID, value in self._masks.items(): + address = _MASK_TO_ADDR[maskID] + self.oscClient.send_message(address, value) + if self._onEnabledCallback is not None: self._onEnabledCallback(self)