Last active
November 24, 2022 11:45
-
-
Save takana-v/ab0ef6cf1509db1dbd1df8d962c049e2 to your computer and use it in GitHub Desktop.
VRChatでQuest単体でフルトラするやつ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# quest_fbt.py | |
# Copyright (c) 2022 takana-v | |
# | |
# This software is released under the MIT License. | |
# http://opensource.org/licenses/mit-license.php | |
import math | |
from pythonosc import udp_client | |
import openvr | |
client = udp_client.SimpleUDPClient("192.168.XXX.XXX", 9000) | |
openvr.init(openvr.VRApplication_Overlay) | |
def get_device_index(serial): | |
i = 0 | |
while True: | |
serial_num = openvr.IVRSystem().getStringTrackedDeviceProperty(i, openvr.Prop_SerialNumber_String) | |
if serial_num == serial: | |
return i | |
if serial_num == "": | |
raise RuntimeError("指定されたデバイスが見つかりませんでした。") | |
i += 1 | |
def run_tracker_server(tracker_indexes, reg_tracker): | |
poses = [] | |
poses, _ = openvr.VRCompositor().getLastPoses(poses, None) | |
pose = poses[reg_tracker] | |
y_delta = -1 * [list(l) for l in list(pose.mDeviceToAbsoluteTracking)][1][3] + 0.04 | |
while True: | |
poses, _ = openvr.VRCompositor().getLastPoses(poses, None) | |
for i,j in enumerate(tracker_indexes): | |
pose = poses[j] | |
col = [list(l) for l in list(pose.mDeviceToAbsoluteTracking)] | |
pos_x = col[0][3] | |
pos_y = col[1][3] | |
pos_z = col[2][3] | |
rot_y = math.asin(col[0][2]) | |
if rot_y != 0: | |
rot_x = math.atan(-col[1][2]/col[2][2]) | |
rot_z = math.atan(-col[0][1]/col[0][0]) | |
else: | |
rot_x = math.atan(col[2][1]/col[1][1]) | |
rot_z = 0 | |
client.send_message( | |
f"/tracking/trackers/{i+1}/position", | |
[ | |
-pos_x, | |
pos_y + y_delta, | |
pos_z, | |
] | |
) | |
client.send_message( | |
f"/tracking/trackers/{i+1}/rotation", | |
[ | |
rot_x, | |
rot_y, | |
rot_z, | |
] | |
) | |
if __name__ == "__main__": | |
device_serials = ["LHR-XXXXXXXX", "LHR-YYYYYYYY", "LHR-ZZZZZZZZ"] | |
tracker_indexes = [get_device_index(s) for s in device_serials] | |
run_tracker_server(tracker_indexes, get_device_index("LHR-XXXXXXXX")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment