Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiplayer FaceCam #624

Merged
merged 105 commits into from
Aug 17, 2023
Merged

Multiplayer FaceCam #624

merged 105 commits into from
Aug 17, 2023

Conversation

Li-ID
Copy link
Collaborator

@Li-ID Li-ID commented Jul 17, 2023

This is a live transmission of the face, in front or above the avatar.
Users with a webcam can enable this feature.

Resolves and closes #560.

Features

  • Only the face is displayed, not the whole webcam video. This works even if the user is moving around.
  • The FaceCam can be displayed in front of the avatars face, or above, facing the viewer.
  • Resolution and FPS as well as network transmission FPS can be set in the FaceCam prefab.

Controls

  • Key: I - Switch on and off.
  • Key: F3 - Switch position above and in front of the avatars face.

Performance

  • Detecting the face is done by the OpenCV plugin.
  • Dealing with face recognition errors and fluid face tracking is done manually. The focus was on using simple and direct mathematical methods.
  • Unity's new "Netcode for GameObjects", which is still under development, was used for the multiplayer implementation.
    The host receives all the videos that contain the cropped face and forwards them only to the clients that have not yet received the video.
    It tries to use the most direct functions of Unity's "Netcode for GameObjects" as well as the functions from the code used in the OpenCV plugin examples.
    • The video is sent as a JPG, which has to be converted to a JPG before and back to a 'texture2d' afterwards. This unfortunately costs some resources which makes the implementation a bit slow.
    • Also, because of the size of these byte packets sent via RPC, it is not possible to use the unreliable RPC which should give a slightly better performance.

Hopefully a more performant implementation of the functions provided by Unity on the OpenCV plugins will also improve the performance of this feature (like the conversion between JPG and 'texture2D' becoming more efficient). Then it may also be possible to switch to unreliable RPCs, as well as possibly choose a different container for network transmission than JPG. It is also possible no conversion from 'texture2D' might be necessary.
Self-adjusting resolution, compression, bitrate and FPS would also be a great addition.

Li-ID added 30 commits May 20, 2023 22:59
But everyone but not the server sends it to themselfs too. This should be fixed.
…d Network-Test-Stuff into the FaceCam folder.
Simplified code.
Fixed error related to y position.
My cat walked over the keyboard this somehow disabled the red square and implemented zoom onto the face instead of jumping right to it.
Co-authored-by: Falko <10247603+falko17@users.noreply.github.com>
Copy link
Collaborator

@falko17 falko17 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me now! Only needs a review from @koschke (and ideally a test in practice, I only looked at the code.)

Improved error message format.
Shortened long lines.
Accepted performance improvement suggested by Visual Studio.
# Conflicts:
#	Assets/SEE/Net/Network.cs
We want to abstract from the kind of interaction (keyboard or
trigger on a VR controller). Moreover, we want to have one single
location in the code where all key bindings are defined so that we
can check whether there are any conflicts.

In fact, a conflict with KeyCode.O existed. Switching the facecam's
position on the player is now bound to KeyCode.F3.
FaceCam will instantiated also for a client (may be a temporary change).
Copy link
Collaborator

@koschke koschke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed a few more issues. In particular, I replaced the reference to Input and KeyCode by a more abstract SEEInput call. Never use Input and KeyCode. There was a keybinding conflict in key O. The facecam's position can now be switched by F3.

Otherwise, the code looks good. However, in my test with two different computers, the face mask worked only on the machine acting as the host. On the client machine, it doesn't. I noticed and marked the responsible source code in file PlayerSpawner.cs, which spawns the FaceCam prefab only on the server. Removing the condition didn't work. There were NetCode errors raised then.
This needs further investigation.

Assets/SEE/Tools/FaceCam/FaceCam.cs Show resolved Hide resolved
Assets/SEE/Tools/FaceCam/FaceCam.cs Outdated Show resolved Hide resolved
Assets/SEE/Tools/FaceCam/FaceCam.cs Outdated Show resolved Hide resolved
Assets/SEE/Game/Worlds/PlayerSpawner.cs Show resolved Hide resolved
Assets/SEE/Tools/FaceCam/FaceCam.cs Show resolved Hide resolved
Assets/SEE/Tools/FaceCam/FaceCam.cs Show resolved Hide resolved
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a few bad patterns I found which you should check.

Assets/SEE/Tools/FaceCam/FaceCam.cs Outdated Show resolved Hide resolved
Assets/SEE/Tools/FaceCam/FaceCam.cs Outdated Show resolved Hide resolved
…-FaceCam

# Conflicts:
#	Assets/SEE/Tools/FaceCam/FaceCam.cs
The check has no type information. In this particular case,
the argument is a Texture, not a GameObject and the use of
Object.Destroy would have been fine.
To deal with similar situations, I generalized Destroyer.Destroy
from Component to Object.
Removed some redundancy.
Fixed bug: Added missing parameter recurseIntoChildren in recursive call.
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a few bad patterns I found which you should check.

Assets/SEE/Utils/Destroyer.cs Show resolved Hide resolved
Assets/SEE/Utils/Destroyer.cs Show resolved Hide resolved
Assets/SEE/Utils/Destroyer.cs Show resolved Hide resolved
@koschke koschke enabled auto-merge August 17, 2023 14:45
Copy link
Collaborator

@koschke koschke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made a few more minor improvements and filed a follow-up issue #633.

Can be merged now.

@koschke koschke merged commit d12cf01 into master Aug 17, 2023
10 checks passed
@koschke koschke deleted the 560-FaceCam branch September 16, 2023 14:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bachelorproject Something applicable to the bachelor project, e.g. its report enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Live transmission of the face, in front of the avatar.
3 participants