Skip to content

Commit

Permalink
add the option to choose the max number of detection and rename ZEDSk…
Browse files Browse the repository at this point in the history
…eletonTrackingManager to ZEDBodyTrackingManager
  • Loading branch information
Bvallon-sl committed Apr 17, 2023
1 parent 26e9243 commit 3279dbb
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 18 deletions.
6 changes: 3 additions & 3 deletions ZEDUnityLivelink/Assets/ZEDFusion/Scripts/SkeletonHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1121,16 +1121,16 @@ public void SetControlWithJointPosition(Vector3[] jointsPosition, Quaternion[] j
currentJoints = jointsPosition;

humanoid.SetActive(useAvatar);
skeleton.SetActive(!useAvatar || ZEDSkeletonTrackingManager.EnableSDKSkeleton);
skeleton.SetActive(!useAvatar || ZEDBodyTrackingManager.EnableSDKSkeleton);
usingAvatar = useAvatar;

if (useAvatar)
{
SetHumanPoseControl(jointsPosition[0], rootRotation, jointsRotation, _mirrorOnYAxis);

if (ZEDSkeletonTrackingManager.EnableSDKSkeleton)
if (ZEDBodyTrackingManager.EnableSDKSkeleton)
{
UpdateSkeleton(ZEDSkeletonTrackingManager.OffsetSDKSkeleton);
UpdateSkeleton(ZEDBodyTrackingManager.OffsetSDKSkeleton);
}
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
///
/// </summary>
[DisallowMultipleComponent]
public class ZEDSkeletonTrackingManager : MonoBehaviour
public class ZEDBodyTrackingManager : MonoBehaviour
{
#region vars
/// <summary>
Expand All @@ -19,6 +19,13 @@ public class ZEDSkeletonTrackingManager : MonoBehaviour
/// </summary>
[Tooltip("Display 3D avatar. If set to false, only display bones and joint")]
public bool enableAvatar = true;

/// <summary>
/// Maximum number of detection displayed in the scene.
/// </summary>
[Tooltip("Maximum number of detections spawnable in the scene")]
public int maximumNumberOfDetections = 75;

/// <summary>
/// Avatar game objects
/// </summary>
Expand Down Expand Up @@ -105,12 +112,15 @@ private void UpdateSkeletonData(sl.Bodies bodies)
}
else
{
SkeletonHandler handler = ScriptableObject.CreateInstance<SkeletonHandler>();
Vector3 spawnPosition = bodyData.position;
handler.Create(avatars[Random.Range(0,avatars.Length)], bodies.body_format);
handler.InitSkeleton(person_id, new Material(skeletonBaseMaterial));
avatarControlList.Add(person_id, handler);
UpdateAvatarControl(handler, bodyData);
if (avatarControlList.Count < maximumNumberOfDetections)
{
SkeletonHandler handler = ScriptableObject.CreateInstance<SkeletonHandler>();
Vector3 spawnPosition = bodyData.position;
handler.Create(avatars[Random.Range(0, avatars.Length)], bodies.body_format);
handler.InitSkeleton(person_id, new Material(skeletonBaseMaterial));
avatarControlList.Add(person_id, handler);
UpdateAvatarControl(handler, bodyData);
}
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions ZEDUnityLivelink/Assets/ZEDFusion/Scripts/ZEDSkeletonAnimator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class ZEDSkeletonAnimator : MonoBehaviour
public Transform LeftFootTransform = null;
public Transform RightFootTransform = null;
public Vector3 ankleHeightOffset = new Vector3(0, 0.102f, 0);
public ZEDSkeletonTrackingManager bodyTrackingManager;
public ZEDBodyTrackingManager bodyTrackingManager;

[Header("Keyboard controls")]
public KeyCode toggleFootIK = KeyCode.I;
Expand Down Expand Up @@ -112,7 +112,7 @@ public class ZEDSkeletonAnimator : MonoBehaviour

private void Awake()
{
bodyTrackingManager = (ZEDSkeletonTrackingManager)FindObjectOfType(typeof(ZEDSkeletonTrackingManager));
bodyTrackingManager = (ZEDBodyTrackingManager)FindObjectOfType(typeof(ZEDBodyTrackingManager));
if (bodyTrackingManager == null)
{
Debug.LogError("ZEDManagerIK: No body tracking manager loaded!");
Expand All @@ -125,8 +125,8 @@ void Start()
animator = GetComponent<Animator>();
currentGroundedPosL = LeftFootTransform.position;
currentGroundedPosR = RightFootTransform.position;
bodyTrackingFrequency = ZEDSkeletonTrackingManager.BodyTrackingFrequency;
smoothingFactor = ZEDSkeletonTrackingManager.SmoothingFactor;
bodyTrackingFrequency = ZEDBodyTrackingManager.BodyTrackingFrequency;
smoothingFactor = ZEDBodyTrackingManager.SmoothingFactor;
}

/// <summary>
Expand Down Expand Up @@ -406,8 +406,8 @@ private void ManageHeightOffset()

private void Update()
{
bodyTrackingFrequency = ZEDSkeletonTrackingManager.BodyTrackingFrequency;
smoothingFactor = ZEDSkeletonTrackingManager.SmoothingFactor;
bodyTrackingFrequency = ZEDBodyTrackingManager.BodyTrackingFrequency;
smoothingFactor = ZEDBodyTrackingManager.SmoothingFactor;

/// KEY INPUTS
if (Input.GetKeyDown(toggleFootIK))
Expand Down
4 changes: 2 additions & 2 deletions ZEDUnityLivelink/ProjectSettings/ProjectVersion.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
m_EditorVersion: 2021.3.21f1
m_EditorVersionWithRevision: 2021.3.21f1 (1b156197d683)
m_EditorVersion: 2021.3.22f1
m_EditorVersionWithRevision: 2021.3.22f1 (b6c551784ba3)

0 comments on commit 3279dbb

Please sign in to comment.