Merge branch 'overlay_reversion' into develop
# Conflicts: # model.py
This commit is contained in:
108
controller.py
108
controller.py
@@ -27,10 +27,10 @@ def callbackFilepathConfigFile():
|
|||||||
def callbackQuitVrct():
|
def callbackQuitVrct():
|
||||||
setMainWindowGeometry()
|
setMainWindowGeometry()
|
||||||
|
|
||||||
# def callbackEnableEasterEgg():
|
def callbackEnableEasterEgg():
|
||||||
# config.IS_EASTER_EGG_ENABLED = True
|
config.IS_EASTER_EGG_ENABLED = True
|
||||||
# config.OVERLAY_UI_TYPE = "sakura"
|
config.OVERLAY_UI_TYPE = "sakura"
|
||||||
# view.printToTextbox_enableEasterEgg()
|
view.printToTextbox_enableEasterEgg()
|
||||||
|
|
||||||
def setMainWindowGeometry():
|
def setMainWindowGeometry():
|
||||||
PRE_SCALING_INT = strPctToInt(view.getPreUiScaling())
|
PRE_SCALING_INT = strPctToInt(view.getPreUiScaling())
|
||||||
@@ -161,14 +161,12 @@ def receiveSpeakerMessage(message):
|
|||||||
xsoverlay_message = messageFormatter("RECEIVED", translation, message)
|
xsoverlay_message = messageFormatter("RECEIVED", translation, message)
|
||||||
model.notificationXSOverlay(xsoverlay_message)
|
model.notificationXSOverlay(xsoverlay_message)
|
||||||
|
|
||||||
# if model.overlay.initialized is False:
|
if config.ENABLE_OVERLAY_SMALL_LOG is True:
|
||||||
# model.startOverlay()
|
if model.overlay.initialized is True:
|
||||||
# else:
|
overlay_image = model.createOverlayImageShort(message, translation)
|
||||||
# if config.ENABLE_OVERLAY_SMALL_LOG is True:
|
model.updateOverlay(overlay_image)
|
||||||
# overlay_image = model.createOverlayImageShort(message, translation)
|
# overlay_image = model.createOverlayImageLong("receive", message, translation)
|
||||||
# model.updateOverlay(overlay_image)
|
# model.updateOverlay(overlay_image)
|
||||||
# # overlay_image = model.createOverlayImageLong("receive", message, translation)
|
|
||||||
# # model.updateOverlay(overlay_image)
|
|
||||||
|
|
||||||
# ------------Speaker2Chatbox------------
|
# ------------Speaker2Chatbox------------
|
||||||
if config.ENABLE_SPEAKER2CHATBOX is True:
|
if config.ENABLE_SPEAKER2CHATBOX is True:
|
||||||
@@ -427,6 +425,12 @@ def callbackToggleTranscriptionReceive(is_turned_on):
|
|||||||
stopThreadingTranscriptionReceiveMessage()
|
stopThreadingTranscriptionReceiveMessage()
|
||||||
view.changeTranscriptionDisplayStatus("SPEAKER_OFF")
|
view.changeTranscriptionDisplayStatus("SPEAKER_OFF")
|
||||||
|
|
||||||
|
if config.ENABLE_TRANSCRIPTION_RECEIVE is True and config.ENABLE_OVERLAY_SMALL_LOG is True:
|
||||||
|
if model.overlay.initialized is False and model.overlay.checkSteamvrRunning() is True:
|
||||||
|
model.startOverlay()
|
||||||
|
elif config.ENABLE_TRANSCRIPTION_RECEIVE is False:
|
||||||
|
pass
|
||||||
|
|
||||||
def callbackToggleForeground(is_turned_on):
|
def callbackToggleForeground(is_turned_on):
|
||||||
config.ENABLE_FOREGROUND = is_turned_on
|
config.ENABLE_FOREGROUND = is_turned_on
|
||||||
if config.ENABLE_FOREGROUND is True:
|
if config.ENABLE_FOREGROUND is True:
|
||||||
@@ -858,44 +862,44 @@ def callbackSetWhisperWeightType(value):
|
|||||||
config.SELECTED_TRANSCRIPTION_ENGINE = "Google"
|
config.SELECTED_TRANSCRIPTION_ENGINE = "Google"
|
||||||
view.showRestartButtonIfRequired()
|
view.showRestartButtonIfRequired()
|
||||||
|
|
||||||
# # VR Tab
|
# VR Tab
|
||||||
# def callbackSetOverlaySettings(value, set_type:str):
|
def callbackSetOverlaySettings(value, set_type:str):
|
||||||
# print("callbackSetOverlaySettings", value, set_type)
|
print("callbackSetOverlaySettings", value, set_type)
|
||||||
# pre_settings = config.OVERLAY_SETTINGS
|
pre_settings = config.OVERLAY_SETTINGS
|
||||||
# pre_settings[set_type] = value
|
pre_settings[set_type] = value
|
||||||
# config.OVERLAY_SETTINGS = pre_settings
|
config.OVERLAY_SETTINGS = pre_settings
|
||||||
# match (set_type):
|
match (set_type):
|
||||||
# case "opacity":
|
case "opacity":
|
||||||
# model.updateOverlayImageOpacity()
|
model.updateOverlayImageOpacity()
|
||||||
# case "ui_scaling":
|
case "ui_scaling":
|
||||||
# model.updateOverlayImageUiScaling()
|
model.updateOverlayImageUiScaling()
|
||||||
|
|
||||||
# def callbackSetEnableOverlaySmallLog(value):
|
def callbackSetEnableOverlaySmallLog(value):
|
||||||
# print("callbackSetEnableOverlaySmallLog", value)
|
print("callbackSetEnableOverlaySmallLog", value)
|
||||||
# config.ENABLE_OVERLAY_SMALL_LOG = value
|
config.ENABLE_OVERLAY_SMALL_LOG = value
|
||||||
|
|
||||||
# if config.ENABLE_OVERLAY_SMALL_LOG is True:
|
if config.ENABLE_OVERLAY_SMALL_LOG is True and config.ENABLE_TRANSCRIPTION_RECEIVE is True:
|
||||||
# pass
|
if model.overlay.initialized is False and model.overlay.checkSteamvrRunning() is True:
|
||||||
# else:
|
model.startOverlay()
|
||||||
# if model.overlay.initialized is True:
|
elif config.ENABLE_OVERLAY_SMALL_LOG is False:
|
||||||
# model.clearOverlayImage()
|
pass
|
||||||
|
|
||||||
# def callbackSetOverlaySmallLogSettings(value, set_type:str):
|
def callbackSetOverlaySmallLogSettings(value, set_type:str):
|
||||||
# print("callbackSetOverlaySmallLogSettings", value, set_type)
|
print("callbackSetOverlaySmallLogSettings", value, set_type)
|
||||||
# pre_settings = config.OVERLAY_SMALL_LOG_SETTINGS
|
pre_settings = config.OVERLAY_SMALL_LOG_SETTINGS
|
||||||
# pre_settings[set_type] = value
|
pre_settings[set_type] = value
|
||||||
# config.OVERLAY_SMALL_LOG_SETTINGS = pre_settings
|
config.OVERLAY_SMALL_LOG_SETTINGS = pre_settings
|
||||||
# match (set_type):
|
match (set_type):
|
||||||
# case "x_pos":
|
case "x_pos":
|
||||||
# model.updateOverlayPosition()
|
model.updateOverlayPosition()
|
||||||
# case "y_pos":
|
case "y_pos":
|
||||||
# model.updateOverlayPosition()
|
model.updateOverlayPosition()
|
||||||
# case "depth":
|
case "depth":
|
||||||
# model.updateOverlayPosition()
|
model.updateOverlayPosition()
|
||||||
# case "display_duration":
|
case "display_duration":
|
||||||
# model.updateOverlayTimes()
|
model.updateOverlayTimes()
|
||||||
# case "fadeout_duration":
|
case "fadeout_duration":
|
||||||
# model.updateOverlayTimes()
|
model.updateOverlayTimes()
|
||||||
|
|
||||||
# Others Tab
|
# Others Tab
|
||||||
def callbackSetEnableAutoClearMessageBox(value):
|
def callbackSetEnableAutoClearMessageBox(value):
|
||||||
@@ -1062,7 +1066,7 @@ def createMainWindow(splash):
|
|||||||
# set UI and callback
|
# set UI and callback
|
||||||
view.register(
|
view.register(
|
||||||
common_registers={
|
common_registers={
|
||||||
# "callback_enable_easter_egg": callbackEnableEasterEgg,
|
"callback_enable_easter_egg": callbackEnableEasterEgg,
|
||||||
|
|
||||||
"callback_update_software": callbackUpdateSoftware,
|
"callback_update_software": callbackUpdateSoftware,
|
||||||
"callback_restart_software": callbackRestartSoftware,
|
"callback_restart_software": callbackRestartSoftware,
|
||||||
@@ -1150,10 +1154,10 @@ def createMainWindow(splash):
|
|||||||
"callback_set_use_whisper_feature": callbackSetUserWhisperFeature,
|
"callback_set_use_whisper_feature": callbackSetUserWhisperFeature,
|
||||||
"callback_set_whisper_weight_type": callbackSetWhisperWeightType,
|
"callback_set_whisper_weight_type": callbackSetWhisperWeightType,
|
||||||
|
|
||||||
# # VR Tab
|
# VR Tab
|
||||||
# "callback_set_overlay_settings": callbackSetOverlaySettings,
|
"callback_set_overlay_settings": callbackSetOverlaySettings,
|
||||||
# "callback_set_enable_overlay_small_log": callbackSetEnableOverlaySmallLog,
|
"callback_set_enable_overlay_small_log": callbackSetEnableOverlaySmallLog,
|
||||||
# "callback_set_overlay_small_log_settings": callbackSetOverlaySmallLogSettings,
|
"callback_set_overlay_small_log_settings": callbackSetOverlaySmallLogSettings,
|
||||||
|
|
||||||
# Others Tab
|
# Others Tab
|
||||||
"callback_set_enable_auto_clear_chatbox": callbackSetEnableAutoClearMessageBox,
|
"callback_set_enable_auto_clear_chatbox": callbackSetEnableAutoClearMessageBox,
|
||||||
|
|||||||
110
model.py
110
model.py
@@ -26,8 +26,8 @@ from models.translation.translation_languages import translation_lang
|
|||||||
from models.transcription.transcription_languages import transcription_lang
|
from models.transcription.transcription_languages import transcription_lang
|
||||||
from models.translation.translation_utils import checkCTranslate2Weight
|
from models.translation.translation_utils import checkCTranslate2Weight
|
||||||
from models.transcription.transcription_whisper import checkWhisperWeight
|
from models.transcription.transcription_whisper import checkWhisperWeight
|
||||||
# from models.overlay.overlay import Overlay
|
from models.overlay.overlay import Overlay
|
||||||
# from models.overlay.overlay_image import OverlayImage
|
from models.overlay.overlay_image import OverlayImage
|
||||||
|
|
||||||
from config import config
|
from config import config
|
||||||
|
|
||||||
@@ -81,18 +81,18 @@ class Model:
|
|||||||
self.previous_receive_message = ""
|
self.previous_receive_message = ""
|
||||||
self.translator = Translator()
|
self.translator = Translator()
|
||||||
self.keyword_processor = KeywordProcessor()
|
self.keyword_processor = KeywordProcessor()
|
||||||
# self.overlay = Overlay(
|
self.overlay = Overlay(
|
||||||
# config.OVERLAY_SMALL_LOG_SETTINGS["x_pos"],
|
config.OVERLAY_SMALL_LOG_SETTINGS["x_pos"],
|
||||||
# config.OVERLAY_SMALL_LOG_SETTINGS["y_pos"],
|
config.OVERLAY_SMALL_LOG_SETTINGS["y_pos"],
|
||||||
# config.OVERLAY_SMALL_LOG_SETTINGS["depth"],
|
config.OVERLAY_SMALL_LOG_SETTINGS["depth"],
|
||||||
# config.OVERLAY_SMALL_LOG_SETTINGS["display_duration"],
|
config.OVERLAY_SMALL_LOG_SETTINGS["display_duration"],
|
||||||
# config.OVERLAY_SMALL_LOG_SETTINGS["fadeout_duration"],
|
config.OVERLAY_SMALL_LOG_SETTINGS["fadeout_duration"],
|
||||||
# config.OVERLAY_SETTINGS["opacity"],
|
config.OVERLAY_SETTINGS["opacity"],
|
||||||
# config.OVERLAY_SETTINGS["ui_scaling"],
|
config.OVERLAY_SETTINGS["ui_scaling"],
|
||||||
# )
|
)
|
||||||
# self.overlay_image = OverlayImage()
|
self.overlay_image = OverlayImage()
|
||||||
# self.pre_overlay_message = None
|
self.pre_overlay_message = None
|
||||||
# self.th_overlay = None
|
self.th_overlay = None
|
||||||
self.mic_audio_queue = None
|
self.mic_audio_queue = None
|
||||||
self.mic_mute_status = None
|
self.mic_mute_status = None
|
||||||
self.mic_mute_status_check = None
|
self.mic_mute_status_check = None
|
||||||
@@ -651,65 +651,53 @@ class Model:
|
|||||||
def notificationXSOverlay(self, message):
|
def notificationXSOverlay(self, message):
|
||||||
xsoverlayForVRCT(content=f"{message}")
|
xsoverlayForVRCT(content=f"{message}")
|
||||||
|
|
||||||
# def createOverlayImageShort(self, message, translation):
|
def createOverlayImageShort(self, message, translation):
|
||||||
# your_language = config.TARGET_LANGUAGE
|
your_language = config.TARGET_LANGUAGE
|
||||||
# target_language = config.SOURCE_LANGUAGE
|
target_language = config.SOURCE_LANGUAGE
|
||||||
# ui_type = config.OVERLAY_UI_TYPE
|
ui_type = config.OVERLAY_UI_TYPE
|
||||||
# self.pre_overlay_message = {
|
self.pre_overlay_message = {
|
||||||
# "message" : message,
|
"message" : message,
|
||||||
# "your_language" : your_language,
|
"your_language" : your_language,
|
||||||
# "translation" : translation,
|
"translation" : translation,
|
||||||
# "target_language" : target_language,
|
"target_language" : target_language,
|
||||||
# "ui_type" : ui_type,
|
"ui_type" : ui_type,
|
||||||
# }
|
}
|
||||||
# return self.overlay_image.createOverlayImageShort(message, your_language, translation, target_language, ui_type)
|
return self.overlay_image.createOverlayImageShort(message, your_language, translation, target_language, ui_type)
|
||||||
|
|
||||||
# def createOverlayImageLong(self, message_type, message, translation):
|
# def createOverlayImageLong(self, message_type, message, translation):
|
||||||
# your_language = config.TARGET_LANGUAGE if message_type == "receive" else config.SOURCE_LANGUAGE
|
# your_language = config.TARGET_LANGUAGE if message_type == "receive" else config.SOURCE_LANGUAGE
|
||||||
# target_language = config.SOURCE_LANGUAGE if message_type == "receive" else config.TARGET_LANGUAGE
|
# target_language = config.SOURCE_LANGUAGE if message_type == "receive" else config.TARGET_LANGUAGE
|
||||||
# return self.overlay_image.create_overlay_image_long(message_type, message, your_language, translation, target_language)
|
# return self.overlay_image.create_overlay_image_long(message_type, message, your_language, translation, target_language)
|
||||||
|
|
||||||
# def clearOverlayImage(self):
|
def clearOverlayImage(self):
|
||||||
# if self.overlay.initialized is True:
|
self.overlay.clearImage()
|
||||||
# self.overlay.uiManager.uiClear()
|
|
||||||
|
|
||||||
# def updateOverlay(self, img):
|
def updateOverlay(self, img):
|
||||||
# if self.overlay.initialized is True:
|
self.overlay.updateImage(img)
|
||||||
# self.overlay.uiManager.uiUpdate(img)
|
|
||||||
|
|
||||||
# def startOverlay(self):
|
def startOverlay(self):
|
||||||
# if self.overlay.initialized is False:
|
self.overlay.startOverlay()
|
||||||
# self.overlay.init()
|
|
||||||
|
|
||||||
# if self.overlay.initialized is True and self.th_overlay is None:
|
def updateOverlayPosition(self):
|
||||||
# self.th_overlay = Thread(target=self.overlay.startOverlay)
|
pos = (config.OVERLAY_SMALL_LOG_SETTINGS["x_pos"], config.OVERLAY_SMALL_LOG_SETTINGS["y_pos"])
|
||||||
# self.th_overlay.daemon = True
|
depth = config.OVERLAY_SMALL_LOG_SETTINGS["depth"]
|
||||||
# self.th_overlay.start()
|
self.overlay.updatePosition(pos, depth)
|
||||||
|
|
||||||
# def updateOverlayPosition(self):
|
def updateOverlayTimes(self):
|
||||||
# if self.overlay.initialized is True:
|
display_duration = config.OVERLAY_SMALL_LOG_SETTINGS["display_duration"]
|
||||||
# pos = (config.OVERLAY_SMALL_LOG_SETTINGS["x_pos"], config.OVERLAY_SMALL_LOG_SETTINGS["y_pos"])
|
self.overlay.updateDisplayDuration(display_duration)
|
||||||
# self.overlay.uiManager.setPosition(pos)
|
fadeout_duration = config.OVERLAY_SMALL_LOG_SETTINGS["fadeout_duration"]
|
||||||
# depth = config.OVERLAY_SMALL_LOG_SETTINGS["depth"]
|
self.overlay.updateFadeoutDuration(fadeout_duration)
|
||||||
# self.overlay.uiManager.setDepth(depth)
|
|
||||||
# self.overlay.uiManager.posUpdate()
|
|
||||||
|
|
||||||
# def updateOverlayTimes(self):
|
def updateOverlayImageOpacity(self):
|
||||||
# if self.overlay.initialized is True:
|
opacity = config.OVERLAY_SETTINGS["opacity"]
|
||||||
# display_duration = config.OVERLAY_SMALL_LOG_SETTINGS["display_duration"]
|
self.overlay.updateOpacity(opacity, with_fade=True)
|
||||||
# self.overlay.uiManager.setFadeTime(display_duration)
|
|
||||||
# fadeout_duration = config.OVERLAY_SMALL_LOG_SETTINGS["fadeout_duration"]
|
|
||||||
# self.overlay.uiManager.setFadeInterval(fadeout_duration)
|
|
||||||
# self.overlay.uiManager.update()
|
|
||||||
|
|
||||||
# def updateOverlayImageOpacity(self):
|
def updateOverlayImageUiScaling(self):
|
||||||
# if self.overlay.initialized is True:
|
ui_scaling = config.OVERLAY_SETTINGS["ui_scaling"]
|
||||||
# opacity = config.OVERLAY_SETTINGS["opacity"]
|
self.overlay.updateUiScaling(ui_scaling)
|
||||||
# self.overlay.uiManager.setTransparency(opacity)
|
|
||||||
|
|
||||||
# def updateOverlayImageUiScaling(self):
|
def stopOverlay(self):
|
||||||
# if self.overlay.initialized is True:
|
self.overlay.setStopOverlay()
|
||||||
# ui_scaling = config.OVERLAY_SETTINGS["ui_scaling"]
|
|
||||||
# self.overlay.uiManager.setUiScaling(ui_scaling)
|
|
||||||
|
|
||||||
model = Model()
|
model = Model()
|
||||||
@@ -1,18 +1,14 @@
|
|||||||
import psutil
|
import os
|
||||||
|
import ctypes
|
||||||
|
from psutil import process_iter
|
||||||
|
# from os import path as os_path
|
||||||
import ctypes
|
import ctypes
|
||||||
import time
|
import time
|
||||||
import asyncio
|
|
||||||
import openvr
|
import openvr
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
# from queue import Queue
|
||||||
|
from threading import Thread
|
||||||
|
|
||||||
def checkSteamvrRunning():
|
|
||||||
for proc in psutil.process_iter():
|
|
||||||
if "vrserver.exe" == proc.name().lower():
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
# This code is based on the following source:
|
|
||||||
# [GOpy](https://github.com/MeroFune/GOpy)
|
|
||||||
def mat34Id():
|
def mat34Id():
|
||||||
arr = openvr.HmdMatrix34_t()
|
arr = openvr.HmdMatrix34_t()
|
||||||
arr[0][0] = 1
|
arr[0][0] = 1
|
||||||
@@ -20,51 +16,94 @@ def mat34Id():
|
|||||||
arr[2][2] = 1
|
arr[2][2] = 1
|
||||||
return arr
|
return arr
|
||||||
|
|
||||||
class UIElement:
|
class Overlay:
|
||||||
def __init__(self, overlayRoot, key: str, name: str, settings: dict = None) -> None:
|
def __init__(self, x, y , depth, display_duration, fadeout_duration, opacity, ui_scaling):
|
||||||
"""
|
self.initialized = False
|
||||||
pos is a 2-tuple representing (x, y) normalized position of the overlay on the screen
|
settings = {
|
||||||
"""
|
"color": [1, 1, 1],
|
||||||
self.overlay = overlayRoot
|
"opacity": opacity,
|
||||||
self.overlayKey = key
|
"x_pos": x,
|
||||||
self.overlayName = name
|
"y_pos": y,
|
||||||
|
"depth": depth,
|
||||||
|
"display_duration": display_duration,
|
||||||
|
"fadeout_duration": fadeout_duration,
|
||||||
|
"ui_scaling": ui_scaling,
|
||||||
|
}
|
||||||
self.settings = settings
|
self.settings = settings
|
||||||
self.handle = self.overlay.createOverlay(self.overlayKey, self.overlayName)
|
self.system = None
|
||||||
|
self.overlay = None
|
||||||
|
self.handle = None
|
||||||
|
self.lastUpdate = time.monotonic()
|
||||||
|
self.thread_overlay = None
|
||||||
|
self.fadeRatio = 1
|
||||||
|
self.loop = True
|
||||||
|
|
||||||
self.setImage(Image.new("RGBA", (1, 1), (0, 0, 0, 0))) # blank image for default
|
def init(self):
|
||||||
self.setColor(self.settings['Color'])
|
try:
|
||||||
self.setTransparency(self.settings['Transparency'])
|
self.system = openvr.init(openvr.VRApplication_Background)
|
||||||
self.overlay.setOverlayWidthInMeters(
|
self.overlay = openvr.IVROverlay()
|
||||||
self.handle,
|
self.handle = self.overlay.createOverlay("Overlay_Speaker2log", "SOverlay_Speaker2log_UI")
|
||||||
self.settings['Ui_scaling']
|
|
||||||
)
|
|
||||||
|
|
||||||
self.updatePosition()
|
self.updateImage(Image.new("RGBA", (1, 1), (0, 0, 0, 0)))
|
||||||
self.overlay.showOverlay(self.handle)
|
self.updateColor(self.settings["color"])
|
||||||
|
self.updateOpacity(self.settings["opacity"])
|
||||||
|
self.updateUiScaling(self.settings["ui_scaling"])
|
||||||
|
self.updatePosition(
|
||||||
|
(self.settings["x_pos"], self.settings["y_pos"]),
|
||||||
|
self.settings["depth"]
|
||||||
|
)
|
||||||
|
self.overlay.showOverlay(self.handle)
|
||||||
|
self.initialized = True
|
||||||
|
except Exception as e:
|
||||||
|
print("Could not initialise OpenVR", e)
|
||||||
|
|
||||||
def setImage(self, img):
|
def updateImage(self, img):
|
||||||
# configure overlay appearance
|
|
||||||
width, height = img.size
|
width, height = img.size
|
||||||
img = img.tobytes()
|
img = img.tobytes()
|
||||||
img = (ctypes.c_char * len(img)).from_buffer_copy(img)
|
img = (ctypes.c_char * len(img)).from_buffer_copy(img)
|
||||||
self.overlay.setOverlayRaw(self.handle, img, width, height, 4)
|
self.overlay.setOverlayRaw(self.handle, img, width, height, 4)
|
||||||
|
self.updateOpacity(self.settings["opacity"])
|
||||||
|
self.lastUpdate = time.monotonic()
|
||||||
|
|
||||||
def setColor(self, col):
|
def clearImage(self):
|
||||||
|
self.updateImage(Image.new("RGBA", (1, 1), (0, 0, 0, 0)))
|
||||||
|
|
||||||
|
def updateColor(self, col):
|
||||||
"""
|
"""
|
||||||
col is a 3-tuple representing (r, g, b)
|
col is a 3-tuple representing (r, g, b)
|
||||||
"""
|
"""
|
||||||
self.overlay.setOverlayColor(self.handle, col[0], col[1], col[2])
|
self.settings["color"] = col
|
||||||
|
r, g, b = self.settings["color"]
|
||||||
|
self.overlay.setOverlayColor(self.handle, r, g, b)
|
||||||
|
|
||||||
def setTransparency(self, a):
|
def updateOpacity(self, opacity, with_fade=False):
|
||||||
self.overlay.setOverlayAlpha(self.handle, a)
|
self.settings["opacity"] = opacity
|
||||||
|
|
||||||
|
if with_fade is True:
|
||||||
|
if self.fadeRatio > 0:
|
||||||
|
self.overlay.setOverlayAlpha(self.handle, self.fadeRatio * self.settings["opacity"])
|
||||||
|
else:
|
||||||
|
self.overlay.setOverlayAlpha(self.handle, self.settings["opacity"])
|
||||||
|
|
||||||
|
def updateUiScaling(self, ui_scaling):
|
||||||
|
self.settings['ui_scaling'] = ui_scaling
|
||||||
|
self.overlay.setOverlayWidthInMeters(self.handle, self.settings['ui_scaling'])
|
||||||
|
|
||||||
|
def updatePosition(self, pos, depth):
|
||||||
|
"""
|
||||||
|
pos is a 2-tuple representing normalized (x, y)
|
||||||
|
depth is a float representing the depth of the icon plane
|
||||||
|
"""
|
||||||
|
self.settings["x_pos"] = pos[0]
|
||||||
|
self.settings["y_pos"] = pos[1]
|
||||||
|
self.settings["depth"] = depth
|
||||||
|
|
||||||
def updatePosition(self):
|
|
||||||
self.transform = mat34Id() # no rotation required for HMD attachment
|
self.transform = mat34Id() # no rotation required for HMD attachment
|
||||||
|
|
||||||
# assign position
|
# assign position
|
||||||
self.transform[0][3] = self.settings["Normalized_icon_X_position"] * self.settings['Icon_plane_depth']
|
self.transform[0][3] = self.settings["x_pos"] * self.settings['depth']
|
||||||
self.transform[1][3] = self.settings["Normalized_icon_Y_position"] * self.settings['Icon_plane_depth']
|
self.transform[1][3] = self.settings["y_pos"] * self.settings['depth']
|
||||||
self.transform[2][3] = - self.settings['Icon_plane_depth']
|
self.transform[2][3] = - self.settings['depth']
|
||||||
|
|
||||||
self.overlay.setOverlayTransformTrackedDeviceRelative(
|
self.overlay.setOverlayTransformTrackedDeviceRelative(
|
||||||
self.handle,
|
self.handle,
|
||||||
@@ -72,127 +111,11 @@ class UIElement:
|
|||||||
self.transform
|
self.transform
|
||||||
)
|
)
|
||||||
|
|
||||||
def setPosition(self, pos):
|
def updateDisplayDuration(self, display_duration):
|
||||||
"""
|
self.settings['display_duration'] = display_duration
|
||||||
pos is a 2-tuple representing normalized (x, y)
|
|
||||||
"""
|
|
||||||
self.settings["Normalized_icon_X_position"] = pos[0]
|
|
||||||
self.settings["Normalized_icon_Y_position"] = pos[1]
|
|
||||||
|
|
||||||
def setDepth(self, depth):
|
def updateFadeoutDuration(self, fadeout_duration):
|
||||||
self.settings["Icon_plane_depth"] = depth
|
self.settings['fadeout_duration'] = fadeout_duration
|
||||||
|
|
||||||
def setUiScaling(self, ui_scaling):
|
|
||||||
self.overlay.setOverlayWidthInMeters(
|
|
||||||
self.handle,
|
|
||||||
ui_scaling,
|
|
||||||
)
|
|
||||||
|
|
||||||
class UIManager:
|
|
||||||
def __init__(self, overlay_key, overlay_name, settings):
|
|
||||||
self.overlay = openvr.IVROverlay()
|
|
||||||
self.settings = settings
|
|
||||||
self.overlayUI = UIElement(
|
|
||||||
self.overlay,
|
|
||||||
overlay_key,
|
|
||||||
overlay_name,
|
|
||||||
self.settings,
|
|
||||||
)
|
|
||||||
self.fadeRatio = 1
|
|
||||||
self.lastUpdate = time.monotonic()
|
|
||||||
|
|
||||||
def update(self):
|
|
||||||
currTime = time.monotonic()
|
|
||||||
if self.settings['Fade_interval'] != 0:
|
|
||||||
self.evaluateTransparencyFade(self.lastUpdate, currTime)
|
|
||||||
|
|
||||||
def uiClear(self):
|
|
||||||
self.overlayUI.setImage(Image.new("RGBA", (1, 1), (0, 0, 0, 0)))
|
|
||||||
self.overlayUI.setTransparency(self.settings['Transparency'])
|
|
||||||
self.lastUpdate = time.monotonic()
|
|
||||||
|
|
||||||
def uiUpdate(self, img):
|
|
||||||
self.overlayUI.setImage(img)
|
|
||||||
self.overlayUI.setTransparency(self.settings['Transparency'])
|
|
||||||
self.lastUpdate = time.monotonic()
|
|
||||||
|
|
||||||
def evaluateTransparencyFade(self, lastUpdate, currentTime):
|
|
||||||
if (currentTime - lastUpdate) > self.settings['Fade_time']:
|
|
||||||
timeThroughInterval = currentTime - lastUpdate - self.settings['Fade_time']
|
|
||||||
self.fadeRatio = 1 - timeThroughInterval / self.settings['Fade_interval']
|
|
||||||
if self.fadeRatio < 0:
|
|
||||||
self.fadeRatio = 0
|
|
||||||
|
|
||||||
self.overlayUI.setTransparency(self.fadeRatio * self.settings['Transparency'])
|
|
||||||
|
|
||||||
def posUpdate(self):
|
|
||||||
self.overlayUI.updatePosition()
|
|
||||||
|
|
||||||
def setPosition(self, pos):
|
|
||||||
self.overlayUI.setPosition(pos)
|
|
||||||
|
|
||||||
def setDepth(self, depth):
|
|
||||||
self.overlayUI.setDepth(depth)
|
|
||||||
|
|
||||||
def setFadeTime(self, fade_time):
|
|
||||||
self.settings["Fade_time"] = fade_time
|
|
||||||
|
|
||||||
def setFadeInterval(self, fade_interval):
|
|
||||||
self.settings["Fade_interval"] = fade_interval
|
|
||||||
|
|
||||||
def setUiScaling(self, ui_scaling):
|
|
||||||
self.overlayUI.setUiScaling(ui_scaling)
|
|
||||||
|
|
||||||
def setTransparency(self, transparency):
|
|
||||||
self.settings["Transparency"] = transparency
|
|
||||||
self.overlayUI.setTransparency(self.fadeRatio * self.settings['Transparency'])
|
|
||||||
|
|
||||||
class Overlay:
|
|
||||||
def __init__(self, x, y , depth, fade_time, fade_interval, transparency, ui_scaling):
|
|
||||||
self.initialized = False
|
|
||||||
settings = {
|
|
||||||
"Color": [1, 1, 1],
|
|
||||||
"Transparency": transparency,
|
|
||||||
"Normalized_icon_X_position": x,
|
|
||||||
"Normalized_icon_Y_position": y,
|
|
||||||
"Icon_plane_depth": depth,
|
|
||||||
"Fade_time": fade_time,
|
|
||||||
"Fade_interval": fade_interval,
|
|
||||||
"Ui_scaling": ui_scaling,
|
|
||||||
}
|
|
||||||
self.settings = settings
|
|
||||||
self.system = None
|
|
||||||
|
|
||||||
def init(self):
|
|
||||||
try:
|
|
||||||
if checkSteamvrRunning() is True:
|
|
||||||
self.system = openvr.init(openvr.VRApplication_Background)
|
|
||||||
self.initialized = True
|
|
||||||
except Exception as e:
|
|
||||||
print("Could not initialise OpenVR")
|
|
||||||
print(e)
|
|
||||||
|
|
||||||
async def mainLoop(self):
|
|
||||||
while self.checkActive() is True:
|
|
||||||
startTime = time.monotonic()
|
|
||||||
self.uiManager.update()
|
|
||||||
|
|
||||||
sleepTime = (1 / 60) - (time.monotonic() - startTime)
|
|
||||||
if sleepTime > 0:
|
|
||||||
await asyncio.sleep(sleepTime)
|
|
||||||
|
|
||||||
async def initMain(self):
|
|
||||||
if self.initialized is True:
|
|
||||||
self.uiManager = UIManager("Overlay_Speaker2log", "SOverlay_Speaker2log_UI", self.settings)
|
|
||||||
await self.mainLoop()
|
|
||||||
|
|
||||||
def startOverlay(self):
|
|
||||||
asyncio.run(self.initMain())
|
|
||||||
|
|
||||||
def shutdown(self):
|
|
||||||
self.system = None
|
|
||||||
self.initialized = False
|
|
||||||
openvr.shutdown()
|
|
||||||
|
|
||||||
def checkActive(self):
|
def checkActive(self):
|
||||||
try:
|
try:
|
||||||
@@ -200,7 +123,6 @@ class Overlay:
|
|||||||
new_event = openvr.VREvent_t()
|
new_event = openvr.VREvent_t()
|
||||||
while self.system.pollNextEvent(new_event):
|
while self.system.pollNextEvent(new_event):
|
||||||
if new_event.eventType == openvr.VREvent_Quit:
|
if new_event.eventType == openvr.VREvent_Quit:
|
||||||
self.shutdown()
|
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -208,49 +130,78 @@ class Overlay:
|
|||||||
print(e)
|
print(e)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def evaluateOpacityFade(self, lastUpdate, currentTime):
|
||||||
|
if (currentTime - lastUpdate) > self.settings['display_duration']:
|
||||||
|
timeThroughInterval = currentTime - lastUpdate - self.settings['display_duration']
|
||||||
|
self.fadeRatio = 1 - timeThroughInterval / self.settings['fadeout_duration']
|
||||||
|
if self.fadeRatio < 0:
|
||||||
|
self.fadeRatio = 0
|
||||||
|
self.overlay.setOverlayAlpha(self.handle, self.fadeRatio * self.settings['opacity'])
|
||||||
|
|
||||||
|
def update(self):
|
||||||
|
currTime = time.monotonic()
|
||||||
|
if self.settings['fadeout_duration'] != 0:
|
||||||
|
self.evaluateOpacityFade(self.lastUpdate, currTime)
|
||||||
|
else:
|
||||||
|
self.updateOpacity(self.settings["opacity"])
|
||||||
|
|
||||||
|
def mainloop(self):
|
||||||
|
self.loop = True
|
||||||
|
while self.checkActive() is True and self.loop is True:
|
||||||
|
startTime = time.monotonic()
|
||||||
|
self.update()
|
||||||
|
sleepTime = (1 / 16) - (time.monotonic() - startTime)
|
||||||
|
if sleepTime > 0:
|
||||||
|
time.sleep(sleepTime)
|
||||||
|
self.shutdownOverlay()
|
||||||
|
|
||||||
|
def main(self):
|
||||||
|
self.init()
|
||||||
|
if self.initialized is True:
|
||||||
|
self.mainloop()
|
||||||
|
|
||||||
|
def startOverlay(self):
|
||||||
|
self.thread_overlay = Thread(target=self.main)
|
||||||
|
self.thread_overlay.daemon = True
|
||||||
|
self.thread_overlay.start()
|
||||||
|
|
||||||
|
def setStopOverlay(self):
|
||||||
|
self.loop = False
|
||||||
|
|
||||||
|
def shutdownOverlay(self):
|
||||||
|
if self.thread_overlay is not None:
|
||||||
|
self.thread_overlay.join()
|
||||||
|
self.thread_overlay = None
|
||||||
|
if self.overlay is not None:
|
||||||
|
self.overlay.destroyOverlay(self.handle)
|
||||||
|
self.overlay = None
|
||||||
|
if self.system is not None:
|
||||||
|
openvr.shutdown()
|
||||||
|
self.system = None
|
||||||
|
self.initialized = False
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def checkSteamvrRunning() -> bool:
|
||||||
|
_proc_name = "vrmonitor.exe" if os.name == 'nt' else "vrmonitor"
|
||||||
|
return _proc_name in (p.name() for p in process_iter())
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
from overlay_image import OverlayImage
|
from overlay_image import OverlayImage
|
||||||
from threading import Thread, Event
|
|
||||||
class threadFnc(Thread):
|
|
||||||
def __init__(self, fnc, end_fnc=None, daemon=True, *args, **kwargs):
|
|
||||||
super(threadFnc, self).__init__(daemon=daemon, *args, **kwargs)
|
|
||||||
self.fnc = fnc
|
|
||||||
self.end_fnc = end_fnc
|
|
||||||
self._stop = Event()
|
|
||||||
def stop(self):
|
|
||||||
self._stop.set()
|
|
||||||
def stopped(self):
|
|
||||||
return self._stop.is_set()
|
|
||||||
def run(self):
|
|
||||||
while True:
|
|
||||||
if self.stopped():
|
|
||||||
if callable(self.end_fnc):
|
|
||||||
self.end_fnc()
|
|
||||||
return
|
|
||||||
self.fnc(*self._args, **self._kwargs)
|
|
||||||
|
|
||||||
overlay = Overlay()
|
|
||||||
overlay_image = OverlayImage()
|
overlay_image = OverlayImage()
|
||||||
|
|
||||||
if overlay.initialized is False:
|
for i in range(100):
|
||||||
overlay.init()
|
print(i)
|
||||||
if overlay.initialized is True:
|
overlay = Overlay(0, 0, 1, 1, 1, 1, 1)
|
||||||
t = threadFnc(overlay.startOverlay)
|
overlay.startOverlay()
|
||||||
t.start()
|
time.sleep(1)
|
||||||
|
|
||||||
time.sleep(1)
|
# Example usage
|
||||||
img = overlay_image.createOverlayImageShort("こんにちは、世界!さようなら", "Japanese", "Hello,World!Goodbye", "Japanese", ui_type="sakura")
|
img = overlay_image.createOverlayImageShort("こんにちは、世界!さようなら", "Japanese", "Hello,World!Goodbye", "Japanese", ui_type="sakura")
|
||||||
# img = overlay_image.createOverlayImageShort("こんにちは、世界!さようなら", "Japanese", ui_type="sakura")
|
overlay.updateImage(img)
|
||||||
if overlay.initialized is True:
|
time.sleep(0.5)
|
||||||
overlay.uiManager.uiUpdate(img)
|
|
||||||
time.sleep(10)
|
|
||||||
|
|
||||||
img = overlay_image.createOverlayImageShort("こんにちは、世界!さようなら", "Japanese", "안녕하세요, 세계!안녕", "Korean")
|
img = overlay_image.createOverlayImageShort("こんにちは、世界!さようなら", "Japanese", "Hello,World!Goodbye", "Japanese")
|
||||||
if overlay.initialized is True:
|
overlay.updateImage(img)
|
||||||
overlay.uiManager.uiUpdate(img)
|
time.sleep(0.5)
|
||||||
time.sleep(10)
|
|
||||||
|
|
||||||
img = overlay_image.createOverlayImageShort("こんにちは、世界!さようなら", "Japanese", "你好世界!再见", "Chinese Simplified")
|
overlay.setStopOverlay()
|
||||||
if overlay.initialized is True:
|
|
||||||
overlay.uiManager.uiUpdate(img)
|
|
||||||
time.sleep(10)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user