🐛[bugfix] Model : マージに合わせてoverlayの処理を修正

- overlay off時にParameterを変更できるように修正
- overlay終了処理時を修正
- Easter Eggのコメントアウトを削除
This commit is contained in:
misyaguziya
2024-05-08 11:45:28 +09:00
parent 457c4a48f9
commit 32ad466d9d
5 changed files with 41 additions and 39 deletions

View File

@@ -787,7 +787,7 @@ class Config:
def OVERLAY_UI_TYPE(self, value): def OVERLAY_UI_TYPE(self, value):
if isinstance(value, str): if isinstance(value, str):
self._OVERLAY_UI_TYPE = value self._OVERLAY_UI_TYPE = value
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) # saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@property @property
@json_serializable('ENABLE_SEND_MESSAGE_TO_VRC') @json_serializable('ENABLE_SEND_MESSAGE_TO_VRC')

View File

@@ -882,7 +882,8 @@ def callbackSetEnableOverlaySmallLog(value):
if model.overlay.initialized is False and model.overlay.checkSteamvrRunning() is True: if model.overlay.initialized is False and model.overlay.checkSteamvrRunning() is True:
model.startOverlay() model.startOverlay()
elif config.ENABLE_OVERLAY_SMALL_LOG is False: elif config.ENABLE_OVERLAY_SMALL_LOG is False:
pass model.clearOverlayImage()
model.shutdownOverlay()
def callbackSetOverlaySmallLogSettings(value, set_type:str): def callbackSetOverlaySmallLogSettings(value, set_type:str):
print("callbackSetOverlaySmallLogSettings", value, set_type) print("callbackSetOverlaySmallLogSettings", value, set_type)

View File

@@ -697,7 +697,7 @@ class Model:
ui_scaling = config.OVERLAY_SETTINGS["ui_scaling"] ui_scaling = config.OVERLAY_SETTINGS["ui_scaling"]
self.overlay.updateUiScaling(ui_scaling) self.overlay.updateUiScaling(ui_scaling)
def stopOverlay(self): def shutdownOverlay(self):
self.overlay.setStopOverlay() self.overlay.shutdownOverlay()
model = Model() model = Model()

View File

@@ -1,12 +1,9 @@
import os import os
import ctypes import ctypes
from psutil import process_iter from psutil import process_iter
# from os import path as os_path
import ctypes
import time import time
import openvr import openvr
from PIL import Image from PIL import Image
# from queue import Queue
from threading import Thread from threading import Thread
def mat34Id(): def mat34Id():
@@ -43,6 +40,8 @@ class Overlay:
self.system = openvr.init(openvr.VRApplication_Background) self.system = openvr.init(openvr.VRApplication_Background)
self.overlay = openvr.IVROverlay() self.overlay = openvr.IVROverlay()
self.handle = self.overlay.createOverlay("Overlay_Speaker2log", "SOverlay_Speaker2log_UI") self.handle = self.overlay.createOverlay("Overlay_Speaker2log", "SOverlay_Speaker2log_UI")
self.overlay.showOverlay(self.handle)
self.initialized = True
self.updateImage(Image.new("RGBA", (1, 1), (0, 0, 0, 0))) self.updateImage(Image.new("RGBA", (1, 1), (0, 0, 0, 0)))
self.updateColor(self.settings["color"]) self.updateColor(self.settings["color"])
@@ -52,42 +51,46 @@ class Overlay:
(self.settings["x_pos"], self.settings["y_pos"]), (self.settings["x_pos"], self.settings["y_pos"]),
self.settings["depth"] self.settings["depth"]
) )
self.overlay.showOverlay(self.handle)
self.initialized = True
except Exception as e: except Exception as e:
print("Could not initialise OpenVR", e) print("Could not initialise OpenVR", e)
def updateImage(self, img): def updateImage(self, img):
width, height = img.size if self.initialized is True:
img = img.tobytes() width, height = img.size
img = (ctypes.c_char * len(img)).from_buffer_copy(img) img = img.tobytes()
self.overlay.setOverlayRaw(self.handle, img, width, height, 4) img = (ctypes.c_char * len(img)).from_buffer_copy(img)
self.updateOpacity(self.settings["opacity"]) self.overlay.setOverlayRaw(self.handle, img, width, height, 4)
self.lastUpdate = time.monotonic() self.updateOpacity(self.settings["opacity"])
self.lastUpdate = time.monotonic()
def clearImage(self): def clearImage(self):
self.updateImage(Image.new("RGBA", (1, 1), (0, 0, 0, 0))) if self.initialized is True:
self.updateImage(Image.new("RGBA", (1, 1), (0, 0, 0, 0)))
def updateColor(self, col): def updateColor(self, col):
""" """
col is a 3-tuple representing (r, g, b) col is a 3-tuple representing (r, g, b)
""" """
self.settings["color"] = col self.settings["color"] = col
r, g, b = self.settings["color"] if self.initialized is True:
self.overlay.setOverlayColor(self.handle, r, g, b) r, g, b = self.settings["color"]
self.overlay.setOverlayColor(self.handle, r, g, b)
def updateOpacity(self, opacity, with_fade=False): def updateOpacity(self, opacity, with_fade=False):
self.settings["opacity"] = opacity self.settings["opacity"] = opacity
if with_fade is True: if self.initialized is True:
if self.fadeRatio > 0: if with_fade is True:
self.overlay.setOverlayAlpha(self.handle, self.fadeRatio * self.settings["opacity"]) if self.fadeRatio > 0:
else: self.overlay.setOverlayAlpha(self.handle, self.fadeRatio * self.settings["opacity"])
self.overlay.setOverlayAlpha(self.handle, self.settings["opacity"]) else:
self.overlay.setOverlayAlpha(self.handle, self.settings["opacity"])
def updateUiScaling(self, ui_scaling): def updateUiScaling(self, ui_scaling):
self.settings['ui_scaling'] = ui_scaling self.settings['ui_scaling'] = ui_scaling
self.overlay.setOverlayWidthInMeters(self.handle, self.settings['ui_scaling']) if self.initialized is True:
self.overlay.setOverlayWidthInMeters(self.handle, self.settings['ui_scaling'])
def updatePosition(self, pos, depth): def updatePosition(self, pos, depth):
""" """
@@ -105,11 +108,12 @@ class Overlay:
self.transform[1][3] = self.settings["y_pos"] * self.settings['depth'] self.transform[1][3] = self.settings["y_pos"] * self.settings['depth']
self.transform[2][3] = - self.settings['depth'] self.transform[2][3] = - self.settings['depth']
self.overlay.setOverlayTransformTrackedDeviceRelative( if self.initialized is True:
self.handle, self.overlay.setOverlayTransformTrackedDeviceRelative(
openvr.k_unTrackedDeviceIndex_Hmd, self.handle,
self.transform openvr.k_unTrackedDeviceIndex_Hmd,
) self.transform
)
def updateDisplayDuration(self, display_duration): def updateDisplayDuration(self, display_duration):
self.settings['display_duration'] = display_duration self.settings['display_duration'] = display_duration
@@ -153,7 +157,6 @@ class Overlay:
sleepTime = (1 / 16) - (time.monotonic() - startTime) sleepTime = (1 / 16) - (time.monotonic() - startTime)
if sleepTime > 0: if sleepTime > 0:
time.sleep(sleepTime) time.sleep(sleepTime)
self.shutdownOverlay()
def main(self): def main(self):
self.init() self.init()
@@ -165,17 +168,15 @@ class Overlay:
self.thread_overlay.daemon = True self.thread_overlay.daemon = True
self.thread_overlay.start() self.thread_overlay.start()
def setStopOverlay(self):
self.loop = False
def shutdownOverlay(self): def shutdownOverlay(self):
if self.thread_overlay is not None: if isinstance(self.thread_overlay, Thread):
self.loop = False
self.thread_overlay.join() self.thread_overlay.join()
self.thread_overlay = None self.thread_overlay = None
if self.overlay is not None: if isinstance(self.overlay, openvr.IVROverlay) and isinstance(self.handle, int):
self.overlay.destroyOverlay(self.handle) self.overlay.destroyOverlay(self.handle)
self.overlay = None self.overlay = None
if self.system is not None: if isinstance(self.system, openvr.IVRSystem):
openvr.shutdown() openvr.shutdown()
self.system = None self.system = None
self.initialized = False self.initialized = False
@@ -204,4 +205,4 @@ if __name__ == '__main__':
overlay.updateImage(img) overlay.updateImage(img)
time.sleep(0.5) time.sleep(0.5)
overlay.setStopOverlay() overlay.shutdownOverlay()

View File

@@ -101,7 +101,7 @@ class View():
self.view_variable = SimpleNamespace( self.view_variable = SimpleNamespace(
# Common # Common
# CALLBACK_ENABLE_EASTER_EGG=None, CALLBACK_ENABLE_EASTER_EGG=None,
CALLBACK_RESTART_SOFTWARE=None, CALLBACK_RESTART_SOFTWARE=None,
CALLBACK_UPDATE_SOFTWARE=None, CALLBACK_UPDATE_SOFTWARE=None,
@@ -637,7 +637,7 @@ class View():
if common_registers is not None: if common_registers is not None:
# self.view_variable.CALLBACK_ENABLE_EASTER_EGG=common_registers.get("callback_enable_easter_egg", None) self.view_variable.CALLBACK_ENABLE_EASTER_EGG=common_registers.get("callback_enable_easter_egg", None)
self.view_variable.CALLBACK_UPDATE_SOFTWARE=common_registers.get("callback_update_software", None) self.view_variable.CALLBACK_UPDATE_SOFTWARE=common_registers.get("callback_update_software", None)
self.view_variable.CALLBACK_RESTART_SOFTWARE=common_registers.get("callback_restart_software", None) self.view_variable.CALLBACK_RESTART_SOFTWARE=common_registers.get("callback_restart_software", None)