diff --git a/Runtime/Const/KinetixConstants.cs b/Runtime/Const/KinetixConstants.cs index fa1f17a..7f303f8 100644 --- a/Runtime/Const/KinetixConstants.cs +++ b/Runtime/Const/KinetixConstants.cs @@ -8,7 +8,7 @@ namespace Kinetix.Internal { public static class KinetixConstants { - public const string version = "1.8.1"; + public const string version = "1.9.1"; public static bool C_ShouldUGCBeAvailable = true; #if STAGING_KINETIX diff --git a/Runtime/Operations/OperationRetargetEmote/EmoteRetargeting.cs b/Runtime/Operations/OperationRetargetEmote/EmoteRetargeting.cs index 6e52fc7..f9d889c 100644 --- a/Runtime/Operations/OperationRetargetEmote/EmoteRetargeting.cs +++ b/Runtime/Operations/OperationRetargetEmote/EmoteRetargeting.cs @@ -13,8 +13,6 @@ public EmoteRetargeting(EmoteRetargetingConfig _Config): base(_Config) {} public override async Task Execute() { - KinetixLogger.LogDebug("HELP," + Config.Emote.Ids.UUID, "EmoteRetargeting." + nameof(Execute) + " - 16", false); - if (CancellationTokenSource.IsCancellationRequested || Config.CancellationSequencer.canceled) { CurrentTaskCompletionSource.TrySetCanceled(); diff --git a/Samples~/IK_ContainmentZone/ARaycastObject.cs b/Samples~/IK_ContainmentZone/ARaycastObject.cs index 194ce03..4d7a591 100644 --- a/Samples~/IK_ContainmentZone/ARaycastObject.cs +++ b/Samples~/IK_ContainmentZone/ARaycastObject.cs @@ -2,7 +2,7 @@ using System.Linq; using UnityEngine; -public abstract class ARaycastObject : MonoBehaviour +public abstract class ARaycastObject : MonoBehaviour { /// /// Max default raycast distance @@ -59,6 +59,7 @@ public bool Raycast(Vector3 startPosition, Quaternion rotation, Vector3 directio return true; } + abstract public RaycastHit[] Raycast(Vector3 startPosition, Quaternion rotation, Vector3 direction, int layerMask, float distance = RAYCAST_DISTANCE); /// /// Get the farthest point (in global context) along the requested direction @@ -77,13 +78,20 @@ public bool Raycast(Vector3 startPosition, Quaternion rotation, Vector3 directio /// Global rotation of the transform public abstract void DrawGizmo(Vector3 startPosition, Quaternion rotation); - protected bool WhereColliderFilter(RaycastHit raycastHit) => !ignoreColliders.Contains(raycastHit.collider.gameObject); + + + private bool DistanceSecurity(RaycastHit hit) + { + return hit.distance > Mathf.Epsilon; + } + + protected bool WhereColliderFilter(RaycastHit raycastHit) => DistanceSecurity(raycastHit) && !ignoreColliders.Contains(raycastHit.collider.gameObject); protected bool WhereColliderFilter(Collider collider) => !ignoreColliders.Contains(collider.gameObject); - + protected Func WhereHasSpecificCollider(Collider colliderToFind) { return Where; - bool Where (Collider other) + bool Where(Collider other) { return other == colliderToFind; } @@ -91,9 +99,9 @@ bool Where (Collider other) protected Func WhereHasSpecificColliderRaycast(Collider colliderToFind) { return Where; - bool Where(RaycastHit other) + bool Where(RaycastHit raycastHit) { - return other.collider == colliderToFind; + return DistanceSecurity(raycastHit) && raycastHit.collider == colliderToFind; } } } diff --git a/Samples~/IK_ContainmentZone/IK_ContainmentZone.cs b/Samples~/IK_ContainmentZone/IK_ContainmentZone.cs index 9dfbc56..01ccd32 100644 --- a/Samples~/IK_ContainmentZone/IK_ContainmentZone.cs +++ b/Samples~/IK_ContainmentZone/IK_ContainmentZone.cs @@ -1,5 +1,6 @@ using Kinetix; using System; +using System.Linq; using System.Collections; using TMPro; using UnityEngine; @@ -37,7 +38,7 @@ private void Awake() gizmo = GetComponent() ?? gameObject.AddComponent(); } - public void OnValidateGameApiKey() + public void OnValidateGameApiKey() { // Initialization is an async process, // We use a callback to tell when it's finished @@ -88,9 +89,9 @@ public void OpenUGELink() stepDisplayController.NextStep(); - if (routine != null) + if (routine != null) StopCoroutine(routine); - + routine = StartCoroutine(FetchEmotesAtInterval()); }); } @@ -131,7 +132,7 @@ public void AssignEmoteToButton(AnimationMetadata _Metadata) KinetixCore.Metadata.LoadIconByAnimationId(_Metadata.Ids.UUID, (_Sprite) => { animationIcon.sprite = _Sprite; animationName.text = _Metadata.Name; - animationID = _Metadata.Ids.UUID; + animationID = _Metadata.Ids.UUID; }); } @@ -151,15 +152,15 @@ private void OnBeforeIK(IKInfo currentPose) Debug.DrawLine(currentPose.hips.globalPosition, currentPose.leftUpperLeg.globalPosition, Color.gray); Debug.DrawLine(currentPose.leftUpperLeg.globalPosition, currentPose.leftLowerLeg.globalPosition, Color.gray); Debug.DrawLine(currentPose.leftLowerLeg.globalPosition, currentPose.leftFoot.globalPosition, Color.gray); - + Debug.DrawLine(currentPose.hips.globalPosition, currentPose.leftUpperArm.globalPosition, Color.gray); Debug.DrawLine(currentPose.leftUpperArm.globalPosition, currentPose.leftLowerArm.globalPosition, Color.gray); Debug.DrawLine(currentPose.leftLowerArm.globalPosition, currentPose.leftHand.globalPosition, Color.gray); - + Debug.DrawLine(currentPose.hips.globalPosition, currentPose.rightUpperLeg.globalPosition, Color.gray); Debug.DrawLine(currentPose.rightUpperLeg.globalPosition, currentPose.rightLowerLeg.globalPosition, Color.gray); Debug.DrawLine(currentPose.rightLowerLeg.globalPosition, currentPose.rightFoot.globalPosition, Color.gray); - + Debug.DrawLine(currentPose.hips.globalPosition, currentPose.rightUpperArm.globalPosition, Color.gray); Debug.DrawLine(currentPose.rightUpperArm.globalPosition, currentPose.rightLowerArm.globalPosition, Color.gray); Debug.DrawLine(currentPose.rightLowerArm.globalPosition, currentPose.rightHand.globalPosition, Color.gray); @@ -167,7 +168,7 @@ private void OnBeforeIK(IKInfo currentPose) ApplyIK(currentPose, leftHandCollider, currentPose.leftHand, currentPose.leftLowerArm, AvatarIKGoal.LeftHand, AvatarIKHint.LeftElbow); ApplyIK(currentPose, leftFootCollider, currentPose.leftFoot, currentPose.leftLowerLeg, AvatarIKGoal.LeftFoot, AvatarIKHint.LeftKnee); - + ApplyIK(currentPose, rightHandCollider, currentPose.rightHand, currentPose.rightLowerArm, AvatarIKGoal.RightHand, AvatarIKHint.RightElbow); ApplyIK(currentPose, rightFootCollider, currentPose.rightFoot, currentPose.rightLowerLeg, AvatarIKGoal.RightFoot, AvatarIKHint.RightKnee); } @@ -179,7 +180,7 @@ private void OnBeforeIK(IKInfo currentPose) private void ApplyIK(IKInfo currentPose, ARaycastObject raycast, IKTransformInfo transformGoal, IKTransformInfo transformHint, AvatarIKGoal goal, AvatarIKHint hint) { bool isFoot = goal.ToString().EndsWith("Foot"); - + //Check collision for goals (hands / foot) PhysicCast(currentPose, raycast, transformGoal, transformHint, (v) => { @@ -187,7 +188,7 @@ private void ApplyIK(IKInfo currentPose, ARaycastObject raycast, IKTransformInfo { KinetixCore.Animation.SetIKPositionAndWeightOnLocalPlayer(goal, v.Value, 1); KinetixCore.Animation.SetIKHintPositionOnLocalPlayer(hint, transformGoal.globalPosition + (transformHint.globalPosition - transformGoal.globalPosition) * 2); - + if (isFoot) KinetixCore.Animation.SetIKRotationAndWeightOnLocalPlayer(goal, transformGoal.globalRotation, 1); @@ -234,7 +235,7 @@ Green line (near yellow sphere) : Previous position to corrected position gizmo.Color(GIZMO_COLOR); //Check for colliders - Collider[] colliders = raycast.Overlap(transformGoal.globalPosition, transformGoal.globalRotation, overlapLayerMask); + Collider[] colliders = raycast.Overlap(transformGoal.globalPosition, transformGoal.globalRotation, overlapLayerMask).Distinct().ToArray(); int collidersLenght = colliders.Length; bool defaultQuery = Physics.queriesHitBackfaces; //We need to restore physics after we're done computing the physic @@ -246,39 +247,45 @@ Green line (near yellow sphere) : Previous position to corrected position Vector3 hipsToGoal = transformGoal.globalPosition - currentPose.hips.globalPosition; //Compute hint -> goal (+offset) Vector3 fromHintToGoal = (transformGoal.globalPosition + offset) - transformHint.globalPosition; - + //If an overlap has been detected if (collidersLenght > 0) { - Physics.queriesHitBackfaces = true; //enable back faces + Physics.queriesHitBackfaces = false; //disable back faces Vector3 point, fromTo, hitPosition, hitNormal; Vector3 moveDirection = Vector3.zero;//To be computed for (int i = collidersLenght - 1; i >= 0; i--) { Collider collider = colliders[i]; - point = collider.ClosestPointOnBounds(transformGoal.globalPosition); - fromTo = point - transformGoal.globalPosition; + bool colliderIsSelf = collider.GetComponentInParent() == myAnimator; + + Vector3 rayOrigin = colliderIsSelf ? transformGoal.globalPosition : currentPose.hips.globalPosition; + + point = collider.ClosestPointOnBounds(transformGoal.globalPosition + offset); + fromTo = point - rayOrigin; //If it's not interpenetrating, make the raycast point in the direction of the leg/arm. //This is to fix backface normal that are on the opposite side - bool colliderIsSelf = collider.GetComponentInParent() == myAnimator; if (!colliderIsSelf) fromTo *= Mathf.Sign(Vector3.Dot(hipsToGoal, fromTo)); + if (fromTo == Vector3.zero) //Security + fromTo = offset; + #region GIZMO //Nearest point on collider's bounding box - Debug.DrawLine(transformGoal.globalPosition, point, new Color(1, 0, 0, 0.2f)); + Debug.DrawLine(transformGoal.globalPosition + offset, point, new Color(1, 0, 0, 0.2f)); gizmo.Color(GIZMO_COLOR_HIT); gizmo.DrawSphere(point, 0.005f); //Raycast - Debug.DrawRay(offset + transformGoal.globalPosition - fromTo.normalized * RAY_COLISION_OFFSET, fromTo.normalized * (fromTo.magnitude + RAY_COLISION_OFFSET), Color.white); - Debug.DrawRay(offset + transformGoal.globalPosition - fromTo.normalized * RAY_COLISION_OFFSET, fromTo.normalized * (fromTo.magnitude + RAY_COLISION_OFFSET) * 0.2f, Color.magenta); + Debug.DrawRay(offset + rayOrigin - fromTo.normalized * RAY_COLISION_OFFSET, fromTo.normalized * (fromTo.magnitude + RAY_COLISION_OFFSET), Color.white); + Debug.DrawRay(offset + rayOrigin - fromTo.normalized * RAY_COLISION_OFFSET, fromTo.normalized * (fromTo.magnitude + RAY_COLISION_OFFSET) * 0.2f, Color.magenta); #endregion //Do a raycast to get the actual position of the hit - if (!raycast.Raycast(transformGoal.globalPosition - fromTo.normalized * RAY_COLISION_OFFSET, transformGoal.globalRotation, fromTo, overlapLayerMask, out RaycastHit hit, fromTo.magnitude + RAY_COLISION_OFFSET, collider)) + if (!raycast.Raycast(rayOrigin - fromTo.normalized * RAY_COLISION_OFFSET, transformGoal.globalRotation, fromTo, overlapLayerMask, out RaycastHit hit, fromTo.magnitude + RAY_COLISION_OFFSET, collider)) { --collidersLenght; continue; @@ -297,7 +304,7 @@ Green line (near yellow sphere) : Previous position to corrected position //Add a 'velocity' to correct the position in the direction of the normal Vector3 moveVelocity = Vector3.Dot(hitNormal, hitPosition - pointOnCollider) * hitNormal; moveDirection += moveVelocity; - + #region GIZMO //Normal gizmo.Color(Color.cyan); @@ -316,7 +323,7 @@ Green line (near yellow sphere) : Previous position to corrected position if (collidersLenght > 0) { toReturn = transformGoal.globalPosition + moveDirection; - + //Reset color to "color hit" (for the raycastObject's gizmo) gizmo.Color(GIZMO_COLOR_HIT); } @@ -329,7 +336,7 @@ Green line (near yellow sphere) : Previous position to corrected position { //Draw the raycast Debug.DrawRay(transformHint.globalPosition - fromHintToGoal, fromHintToGoal * 2, Color.blue); - + //Init some variables Vector3 hitPosition = hit.point; Vector3 hitNormal = hit.normal; @@ -347,7 +354,7 @@ Green line (near yellow sphere) : Previous position to corrected position //Point on collider gizmo.Color(Color.green); gizmo.DrawSphere(pointOnCollider, 0.01f); - + //Hit gizmo.Color(GIZMO_COLOR_HIT); gizmo.DrawSphere(hitPosition, 0.01f); diff --git a/Samples~/IK_ContainmentZone/RaycastBox.cs b/Samples~/IK_ContainmentZone/RaycastBox.cs index a0f91ca..33f0dbd 100644 --- a/Samples~/IK_ContainmentZone/RaycastBox.cs +++ b/Samples~/IK_ContainmentZone/RaycastBox.cs @@ -40,7 +40,7 @@ public override void DrawGizmo(Vector3 startPosition, Quaternion rotation) public override Collider[] Overlap(Vector3 startPosition, Quaternion rotation, int layerMask) { - return Physics.OverlapBox(startPosition + rotation * offset, size/2, rotation) + return Physics.OverlapBox(startPosition + rotation * offset, size/2, rotation, layerMask) .Where(WhereColliderFilter).ToArray(); } diff --git a/Samples~/Validation_Retake/Scripts/ValidationDemoImplementation.cs b/Samples~/Validation_Retake/Scripts/ValidationDemoImplementation.cs index fac8dee..f63cd9a 100644 --- a/Samples~/Validation_Retake/Scripts/ValidationDemoImplementation.cs +++ b/Samples~/Validation_Retake/Scripts/ValidationDemoImplementation.cs @@ -67,6 +67,8 @@ private void RefreshProcessList(SdkApiProcess[] _Processes) KinetixCore.Metadata.GetAnimationMetadataByAnimationIds(apiProcess.Emote.ToString(), (_AnimationMetadata) => { StopCoroutine(processCoroutine); + AssignEmoteToButton(_AnimationMetadata); + stepDisplayController.NextStep(); }); } diff --git a/package.json b/package.json index 212a576..a29cd9f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "com.kinetix.coreweb2", - "version": "1.9.0", + "version": "1.9.1", "displayName": "Kinetix Core", "description": "Kinetix Core SDK", "samples": [