From 15e1f1a3f111a773ac2274997912607cc2152245 Mon Sep 17 00:00:00 2001 From: Riccardo Bovo Date: Wed, 13 Nov 2024 11:19:47 +0000 Subject: [PATCH] Headset scale added to player rig --- .../Multiplayer/Photon/PhotonPlayerRig.prefab | 1 + .../Multiplayer/MultiplayerDataStructs.cs | 8 +++- .../Multiplayer/MultiplayerInterfaces.cs | 1 - .../Scripts/Multiplayer/MultiplayerManager.cs | 28 ++++++++++- .../Multiplayer/Photon/PhotonPlayerRig.cs | 46 ++++++++++++++++--- 5 files changed, 73 insertions(+), 11 deletions(-) diff --git a/Assets/Resources/Multiplayer/Photon/PhotonPlayerRig.prefab b/Assets/Resources/Multiplayer/Photon/PhotonPlayerRig.prefab index 35a6e9432e..ad58259adc 100644 --- a/Assets/Resources/Multiplayer/Photon/PhotonPlayerRig.prefab +++ b/Assets/Resources/Multiplayer/Photon/PhotonPlayerRig.prefab @@ -56,6 +56,7 @@ MonoBehaviour: m_Right: {fileID: 1621605232836574636} m_Tool: {fileID: 4282572128721117942} _oculusPlayerId: 0 + _IsRoomOwner: 0 headTransform: {fileID: 5041384770245166357} m_PlayerId: 0 --- !u!114 &2967658244113361874 diff --git a/Assets/Scripts/Multiplayer/MultiplayerDataStructs.cs b/Assets/Scripts/Multiplayer/MultiplayerDataStructs.cs index 359e9241f7..68922d0186 100644 --- a/Assets/Scripts/Multiplayer/MultiplayerDataStructs.cs +++ b/Assets/Scripts/Multiplayer/MultiplayerDataStructs.cs @@ -23,14 +23,20 @@ public struct PlayerRigData { public Vector3 HeadPosition; public Quaternion HeadRotation; - public Vector3 HeadScale; public Vector3 ToolPosition; public Quaternion ToolRotation; + public Vector3 LeftHandPosition; + public Quaternion LeftHandRotation; + + public Vector3 RightHandPosition; + public Quaternion RightHandRotation; + public BrushData BrushData; public ExtraData ExtraData; public bool IsRoomOwner; + public float SceneScale; } diff --git a/Assets/Scripts/Multiplayer/MultiplayerInterfaces.cs b/Assets/Scripts/Multiplayer/MultiplayerInterfaces.cs index 4c9e758748..f95b1693aa 100644 --- a/Assets/Scripts/Multiplayer/MultiplayerInterfaces.cs +++ b/Assets/Scripts/Multiplayer/MultiplayerInterfaces.cs @@ -33,7 +33,6 @@ public interface IDataConnectionHandler : IConnectionHandler { void Update(); - int GetPlayerCount(); bool GetPlayerRoomOwnershipStatus(int playerId); Task PerformCommand(BaseCommand command); diff --git a/Assets/Scripts/Multiplayer/MultiplayerManager.cs b/Assets/Scripts/Multiplayer/MultiplayerManager.cs index 86d548dc55..a98d47399b 100644 --- a/Assets/Scripts/Multiplayer/MultiplayerManager.cs +++ b/Assets/Scripts/Multiplayer/MultiplayerManager.cs @@ -292,6 +292,25 @@ void Update() // Transmit local player data relative to scene origin var headRelativeToScene = App.Scene.AsScene[App.VrSdk.GetVrCamera().transform]; var pointerRelativeToScene = App.Scene.AsScene[PointerManager.m_Instance.MainPointer.transform]; + var headScale = App.VrSdk.GetVrCamera().transform.localScale; + var leftController = InputManager.m_Instance.GetController(InputManager.ControllerName.Brush).transform; + var rightController = InputManager.m_Instance.GetController(InputManager.ControllerName.Wand).transform; + + //if (leftController == null || rightController == null) + //{ + // Debug.LogWarning("Left or right controller is null."); + // return; + //} + + //InputDevice headDevice = InputDevices.GetDeviceAtXRNode(XRNode.Head); + //if (headDevice.isValid) + //{ + // deviceModel = headDevice.name; + // Debug.Log("Headset model: " + deviceModel); + //} + + var leftHandRelativeToScene = App.Scene.AsScene[leftController]; + var rightHandRelativeToScene = App.Scene.AsScene[rightController]; var data = new PlayerRigData { @@ -299,6 +318,11 @@ void Update() HeadRotation = headRelativeToScene.rotation, ToolPosition = pointerRelativeToScene.translation, ToolRotation = pointerRelativeToScene.rotation, + LeftHandPosition = leftHandRelativeToScene.translation, + LeftHandRotation = leftHandRelativeToScene.rotation, + RightHandPosition = rightHandRelativeToScene.translation, + RightHandRotation = rightHandRelativeToScene.rotation, + BrushData = new BrushData { Color = PointerManager.m_Instance.MainPointer.GetCurrentColor(), @@ -309,7 +333,8 @@ void Update() { OculusPlayerId = myOculusUserId, }, - IsRoomOwner = isUserRoomOwner + IsRoomOwner = isUserRoomOwner, + SceneScale = App.Scene.Pose.scale }; if (m_LocalPlayer != null) @@ -485,7 +510,6 @@ private IEnumerator SendCommandHistory() } } - public void StartSpeaking() { m_VoiceManager?.StartSpeaking(); diff --git a/Assets/Scripts/Multiplayer/Photon/PhotonPlayerRig.cs b/Assets/Scripts/Multiplayer/Photon/PhotonPlayerRig.cs index 76e1d8eaee..6217c7afa2 100644 --- a/Assets/Scripts/Multiplayer/Photon/PhotonPlayerRig.cs +++ b/Assets/Scripts/Multiplayer/Photon/PhotonPlayerRig.cs @@ -17,7 +17,6 @@ using UnityEngine; using Fusion; using TiltBrush; -using System; namespace OpenBrush.Multiplayer { @@ -35,6 +34,7 @@ public class PhotonPlayerRig : NetworkBehaviour, ITransientData [Networked] private NetworkString<_64> brushGuid { get; set; } [Networked] public ulong oculusPlayerId { get; set; } [Networked] public bool IsRoomOwner { get; set; } + [Networked] public float SceneScale { get; set; } PointerScript transientPointer; // The offset transforms. @@ -53,11 +53,11 @@ public void TransmitData(PlayerRigData data) { transmitData = data; oculusPlayerId = data.ExtraData.OculusPlayerId; - brushColor = data.BrushData.Color; brushSize = data.BrushData.Size; brushGuid = data.BrushData.Guid; IsRoomOwner = data.IsRoomOwner; + SceneScale = data.SceneScale; } public PlayerRigData RecieveData() @@ -66,11 +66,22 @@ public PlayerRigData RecieveData() { HeadPosition = m_PlayerHead.InterpolationTarget.position, HeadRotation = m_PlayerHead.InterpolationTarget.rotation, + + ToolPosition = m_Tool.InterpolationTarget.position, + ToolRotation = m_Tool.InterpolationTarget.rotation, + + LeftHandPosition = m_Left.InterpolationTarget.position, + LeftHandRotation = m_Left.InterpolationTarget.rotation, + + RightHandPosition = m_Right.InterpolationTarget.position, + RightHandRotation = m_Right.InterpolationTarget.rotation, + IsRoomOwner = this.IsRoomOwner, ExtraData = new ExtraData { OculusPlayerId = this.oculusPlayerId - } + }, + SceneScale = this.SceneScale }; return data; } @@ -100,6 +111,12 @@ public override void FixedUpdateNetwork() m_Tool.transform.position = transmitData.ToolPosition; m_Tool.transform.rotation = transmitData.ToolRotation; + + m_Left.transform.position = transmitData.LeftHandPosition; + m_Left.transform.rotation = transmitData.LeftHandRotation; + + m_Right.transform.position = transmitData.RightHandPosition; + m_Right.transform.rotation = transmitData.RightHandRotation; } } @@ -109,12 +126,21 @@ public override void Render() if (Object.HasStateAuthority) { + var remoteTR = TrTransform.TR( + m_PlayerHead.InterpolationTarget.position, + m_PlayerHead.InterpolationTarget.rotation + ); + App.Scene.AsScene[headTransform] = remoteTR; } else { - var toolTR = TrTransform.TR(m_Tool.InterpolationTarget.position, m_Tool.InterpolationTarget.rotation); + // Remote pointer + var toolTR = TrTransform.TR( + m_Tool.InterpolationTarget.position, + m_Tool.InterpolationTarget.rotation + ); App.Scene.AsScene[transientPointer.transform] = toolTR; transientPointer.SetColor(brushColor); @@ -123,10 +149,16 @@ public override void Render() transientPointer.SetBrush(BrushCatalog.m_Instance.GetBrush(new System.Guid(brushGuid.ToString()))); } transientPointer.BrushSize01 = brushSize; - } - var remoteTR = TrTransform.TR(m_PlayerHead.InterpolationTarget.position, m_PlayerHead.InterpolationTarget.rotation); - App.Scene.AsScene[headTransform] = remoteTR; + // Remote head + var remoteTR = TrTransform.TRS( + m_PlayerHead.InterpolationTarget.position, + m_PlayerHead.InterpolationTarget.rotation, + 1/SceneScale + ); + App.Scene.AsScene[headTransform] = remoteTR; + + } } void OnDestroy()