Skip to content

Commit

Permalink
Headset scale added to player rig
Browse files Browse the repository at this point in the history
  • Loading branch information
sbanca committed Nov 13, 2024
1 parent 2ba33c7 commit 15e1f1a
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 11 deletions.
1 change: 1 addition & 0 deletions Assets/Resources/Multiplayer/Photon/PhotonPlayerRig.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion Assets/Scripts/Multiplayer/MultiplayerDataStructs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

}

Expand Down
1 change: 0 additions & 1 deletion Assets/Scripts/Multiplayer/MultiplayerInterfaces.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public interface IDataConnectionHandler : IConnectionHandler
{

void Update();

int GetPlayerCount();
bool GetPlayerRoomOwnershipStatus(int playerId);
Task<bool> PerformCommand(BaseCommand command);
Expand Down
28 changes: 26 additions & 2 deletions Assets/Scripts/Multiplayer/MultiplayerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -292,13 +292,37 @@ 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
{
HeadPosition = headRelativeToScene.translation,
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(),
Expand All @@ -309,7 +333,8 @@ void Update()
{
OculusPlayerId = myOculusUserId,
},
IsRoomOwner = isUserRoomOwner
IsRoomOwner = isUserRoomOwner,
SceneScale = App.Scene.Pose.scale
};

if (m_LocalPlayer != null)
Expand Down Expand Up @@ -485,7 +510,6 @@ private IEnumerator SendCommandHistory()
}
}


public void StartSpeaking()
{
m_VoiceManager?.StartSpeaking();
Expand Down
46 changes: 39 additions & 7 deletions Assets/Scripts/Multiplayer/Photon/PhotonPlayerRig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
using UnityEngine;
using Fusion;
using TiltBrush;
using System;

namespace OpenBrush.Multiplayer
{
Expand All @@ -35,6 +34,7 @@ public class PhotonPlayerRig : NetworkBehaviour, ITransientData<PlayerRigData>
[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.
Expand All @@ -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()
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
}
}

Expand All @@ -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);
Expand All @@ -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()
Expand Down

0 comments on commit 15e1f1a

Please sign in to comment.