From 3279dbbbd3d1aa8f97f9d752ba49ce02f20a91a7 Mon Sep 17 00:00:00 2001 From: Benjamin Vallon Date: Mon, 17 Apr 2023 17:14:14 +0200 Subject: [PATCH] add the option to choose the max number of detection and rename ZEDSkeletonTrackingManager to ZEDBodyTrackingManager --- .../ZEDFusion/Scripts/SkeletonHandler.cs | 6 ++--- ...ngManager.cs => ZEDBodyTrackingManager.cs} | 24 +++++++++++++------ ...cs.meta => ZEDBodyTrackingManager.cs.meta} | 0 .../ZEDFusion/Scripts/ZEDSkeletonAnimator.cs | 12 +++++----- .../ProjectSettings/ProjectVersion.txt | 4 ++-- 5 files changed, 28 insertions(+), 18 deletions(-) rename ZEDUnityLivelink/Assets/ZEDFusion/Scripts/{ZEDSkeletonTrackingManager.cs => ZEDBodyTrackingManager.cs} (85%) rename ZEDUnityLivelink/Assets/ZEDFusion/Scripts/{ZEDSkeletonTrackingManager.cs.meta => ZEDBodyTrackingManager.cs.meta} (100%) diff --git a/ZEDUnityLivelink/Assets/ZEDFusion/Scripts/SkeletonHandler.cs b/ZEDUnityLivelink/Assets/ZEDFusion/Scripts/SkeletonHandler.cs index 1c1ab67..2682967 100644 --- a/ZEDUnityLivelink/Assets/ZEDFusion/Scripts/SkeletonHandler.cs +++ b/ZEDUnityLivelink/Assets/ZEDFusion/Scripts/SkeletonHandler.cs @@ -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 diff --git a/ZEDUnityLivelink/Assets/ZEDFusion/Scripts/ZEDSkeletonTrackingManager.cs b/ZEDUnityLivelink/Assets/ZEDFusion/Scripts/ZEDBodyTrackingManager.cs similarity index 85% rename from ZEDUnityLivelink/Assets/ZEDFusion/Scripts/ZEDSkeletonTrackingManager.cs rename to ZEDUnityLivelink/Assets/ZEDFusion/Scripts/ZEDBodyTrackingManager.cs index d2210a3..56f9d64 100644 --- a/ZEDUnityLivelink/Assets/ZEDFusion/Scripts/ZEDSkeletonTrackingManager.cs +++ b/ZEDUnityLivelink/Assets/ZEDFusion/Scripts/ZEDBodyTrackingManager.cs @@ -7,7 +7,7 @@ /// /// [DisallowMultipleComponent] -public class ZEDSkeletonTrackingManager : MonoBehaviour +public class ZEDBodyTrackingManager : MonoBehaviour { #region vars /// @@ -19,6 +19,13 @@ public class ZEDSkeletonTrackingManager : MonoBehaviour /// [Tooltip("Display 3D avatar. If set to false, only display bones and joint")] public bool enableAvatar = true; + + /// + /// Maximum number of detection displayed in the scene. + /// + [Tooltip("Maximum number of detections spawnable in the scene")] + public int maximumNumberOfDetections = 75; + /// /// Avatar game objects /// @@ -105,12 +112,15 @@ private void UpdateSkeletonData(sl.Bodies bodies) } else { - SkeletonHandler handler = ScriptableObject.CreateInstance(); - 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(); + 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); + } } } } diff --git a/ZEDUnityLivelink/Assets/ZEDFusion/Scripts/ZEDSkeletonTrackingManager.cs.meta b/ZEDUnityLivelink/Assets/ZEDFusion/Scripts/ZEDBodyTrackingManager.cs.meta similarity index 100% rename from ZEDUnityLivelink/Assets/ZEDFusion/Scripts/ZEDSkeletonTrackingManager.cs.meta rename to ZEDUnityLivelink/Assets/ZEDFusion/Scripts/ZEDBodyTrackingManager.cs.meta diff --git a/ZEDUnityLivelink/Assets/ZEDFusion/Scripts/ZEDSkeletonAnimator.cs b/ZEDUnityLivelink/Assets/ZEDFusion/Scripts/ZEDSkeletonAnimator.cs index b078eab..44c9332 100644 --- a/ZEDUnityLivelink/Assets/ZEDFusion/Scripts/ZEDSkeletonAnimator.cs +++ b/ZEDUnityLivelink/Assets/ZEDFusion/Scripts/ZEDSkeletonAnimator.cs @@ -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; @@ -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!"); @@ -125,8 +125,8 @@ void Start() animator = GetComponent(); currentGroundedPosL = LeftFootTransform.position; currentGroundedPosR = RightFootTransform.position; - bodyTrackingFrequency = ZEDSkeletonTrackingManager.BodyTrackingFrequency; - smoothingFactor = ZEDSkeletonTrackingManager.SmoothingFactor; + bodyTrackingFrequency = ZEDBodyTrackingManager.BodyTrackingFrequency; + smoothingFactor = ZEDBodyTrackingManager.SmoothingFactor; } /// @@ -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)) diff --git a/ZEDUnityLivelink/ProjectSettings/ProjectVersion.txt b/ZEDUnityLivelink/ProjectSettings/ProjectVersion.txt index bca3d02..f8251a7 100644 --- a/ZEDUnityLivelink/ProjectSettings/ProjectVersion.txt +++ b/ZEDUnityLivelink/ProjectSettings/ProjectVersion.txt @@ -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)